mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { GFXObject, GFXObjectType, GFXShaderType, GFXType } from './define';
|
|
import { GFXDevice } from './device';
|
|
|
|
export interface IGFXShaderMacro {
|
|
macro: string;
|
|
value: string;
|
|
}
|
|
|
|
export interface IGFXShaderStage {
|
|
type: GFXShaderType;
|
|
source: string;
|
|
macros?: IGFXShaderMacro[];
|
|
}
|
|
|
|
export class GFXUniform {
|
|
public name: string = '';
|
|
public type: GFXType = GFXType.UNKNOWN;
|
|
public count: number = 1;
|
|
}
|
|
|
|
export class GFXUniformBlock {
|
|
public binding: number = -1;
|
|
public name: string = '';
|
|
// instance : string;
|
|
public members: GFXUniform[] = [];
|
|
}
|
|
|
|
export class GFXUniformSampler {
|
|
public binding: number = -1;
|
|
public name: string = '';
|
|
public type: GFXType = GFXType.UNKNOWN;
|
|
public count: number = 1;
|
|
}
|
|
|
|
export interface IGFXShaderInfo {
|
|
name: string;
|
|
stages: IGFXShaderStage[];
|
|
// bindings: GFXBinding[];
|
|
|
|
blocks?: GFXUniformBlock[];
|
|
samplers?: GFXUniformSampler[];
|
|
}
|
|
|
|
export abstract class GFXShader extends GFXObject {
|
|
|
|
public get id (): number {
|
|
return this._id;
|
|
}
|
|
|
|
protected _device: GFXDevice;
|
|
protected _id: number;
|
|
protected _name: string = '';
|
|
protected _stages: IGFXShaderStage[] = [];
|
|
// protected _bindings: GFXBinding[] = [];
|
|
protected _blocks: GFXUniformBlock[] = []; // blocks are used for being compatible with single uniforms
|
|
protected _samplers: GFXUniformSampler[] = [];
|
|
|
|
constructor (device: GFXDevice) {
|
|
super(GFXObjectType.SHADER);
|
|
this._device = device;
|
|
this._id = device.genShaderId();
|
|
}
|
|
|
|
public abstract initialize (info: IGFXShaderInfo): boolean;
|
|
public abstract destroy ();
|
|
public get name () { return this._name; }
|
|
}
|