Files
cocos4/cocos/gfx/shader.ts
T
Yun Hsiao Wu 271a7a0b3a material hash
2019-01-16 14:03:47 +08:00

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; }
}