|
@@ -108,9 +108,11 @@
|
|
public _key: string;
|
|
public _key: string;
|
|
private _indexParameters: any;
|
|
private _indexParameters: any;
|
|
private _fallbacks: EffectFallbacks;
|
|
private _fallbacks: EffectFallbacks;
|
|
|
|
+ private _vertexSourceCode: string;
|
|
|
|
+ private _fragmentSourceCode: string;
|
|
|
|
|
|
private _program: WebGLProgram;
|
|
private _program: WebGLProgram;
|
|
- private _valueCache: { [key: string]: any } = {};
|
|
|
|
|
|
+ private _valueCache: { [key: string]: any };
|
|
private static _baseCache: { [key: number]: WebGLBuffer } = {};
|
|
private static _baseCache: { [key: number]: WebGLBuffer } = {};
|
|
|
|
|
|
constructor(baseName: any, attributesNamesOrOptions: string[] | EffectCreationOptions, uniformsNamesOrEngine: string[] | Engine, samplers?: string[], engine?: Engine, defines?: string, fallbacks?: EffectFallbacks, onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void, indexParameters?: any) {
|
|
constructor(baseName: any, attributesNamesOrOptions: string[] | EffectCreationOptions, uniformsNamesOrEngine: string[] | Engine, samplers?: string[], engine?: Engine, defines?: string, fallbacks?: EffectFallbacks, onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void, indexParameters?: any) {
|
|
@@ -179,7 +181,14 @@
|
|
this._loadFragmentShader(fragmentSource, (fragmentCode) => {
|
|
this._loadFragmentShader(fragmentSource, (fragmentCode) => {
|
|
this._processIncludes(fragmentCode, fragmentCodeWithIncludes => {
|
|
this._processIncludes(fragmentCode, fragmentCodeWithIncludes => {
|
|
this._processShaderConversion(fragmentCodeWithIncludes, true, migratedFragmentCode => {
|
|
this._processShaderConversion(fragmentCodeWithIncludes, true, migratedFragmentCode => {
|
|
- this._prepareEffect(migratedVertexCode, migratedFragmentCode, this._attributesNames, this.defines, this._fallbacks, baseName);
|
|
|
|
|
|
+ if (baseName) {
|
|
|
|
+ this._vertexSourceCode = "#define SHADER_NAME vertex:" + baseName + "\n" + migratedVertexCode;
|
|
|
|
+ this._fragmentSourceCode = "#define SHADER_NAME fragment:" + baseName + "\n" + migratedFragmentCode;
|
|
|
|
+ } else {
|
|
|
|
+ this._vertexSourceCode = migratedVertexCode;
|
|
|
|
+ this._fragmentSourceCode = migratedFragmentCode;
|
|
|
|
+ }
|
|
|
|
+ this._prepareEffect();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -492,15 +501,15 @@
|
|
return source;
|
|
return source;
|
|
}
|
|
}
|
|
|
|
|
|
- private _prepareEffect(vertexSourceCode: string, fragmentSourceCode: string, attributesNames: string[], defines: string, fallbacks?: EffectFallbacks, baseName?: string): void {
|
|
|
|
|
|
+ public _prepareEffect() {
|
|
|
|
+ let attributesNames = this._attributesNames;
|
|
|
|
+ let defines = this.defines;
|
|
|
|
+ let fallbacks = this._fallbacks;
|
|
|
|
+ this._valueCache = {};
|
|
|
|
+
|
|
try {
|
|
try {
|
|
var engine = this._engine;
|
|
var engine = this._engine;
|
|
- if (baseName) {
|
|
|
|
- vertexSourceCode = "#define SHADER_NAME vertex:" + baseName + "\n" + vertexSourceCode;
|
|
|
|
- fragmentSourceCode = "#define SHADER_NAME fragment:" + baseName + "\n" + fragmentSourceCode;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this._program = engine.createShaderProgram(vertexSourceCode, fragmentSourceCode, defines);
|
|
|
|
|
|
+ this._program = engine.createShaderProgram(this._vertexSourceCode, this._fragmentSourceCode, defines);
|
|
|
|
|
|
if (engine.webGLVersion > 1) {
|
|
if (engine.webGLVersion > 1) {
|
|
for (var name in this._uniformBuffersNames) {
|
|
for (var name in this._uniformBuffersNames) {
|
|
@@ -541,28 +550,29 @@
|
|
BABYLON.Tools.Error("Attributes: " + attributesNames.map(function(attribute) {
|
|
BABYLON.Tools.Error("Attributes: " + attributesNames.map(function(attribute) {
|
|
return " " + attribute;
|
|
return " " + attribute;
|
|
}));
|
|
}));
|
|
- this._dumpShadersSource(vertexSourceCode, fragmentSourceCode, defines);
|
|
|
|
|
|
+ this._dumpShadersSource(this._vertexSourceCode, this._fragmentSourceCode, defines);
|
|
Tools.Error("Error: " + this._compilationError);
|
|
Tools.Error("Error: " + this._compilationError);
|
|
|
|
|
|
if (fallbacks && fallbacks.isMoreFallbacks) {
|
|
if (fallbacks && fallbacks.isMoreFallbacks) {
|
|
Tools.Error("Trying next fallback.");
|
|
Tools.Error("Trying next fallback.");
|
|
- defines = fallbacks.reduce(defines);
|
|
|
|
- this._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines, fallbacks);
|
|
|
|
|
|
+ this.defines = fallbacks.reduce(this.defines);
|
|
|
|
+ this._prepareEffect();
|
|
} else { // Sorry we did everything we can
|
|
} else { // Sorry we did everything we can
|
|
|
|
|
|
if (this.onError) {
|
|
if (this.onError) {
|
|
this.onError(this, this._compilationError);
|
|
this.onError(this, this._compilationError);
|
|
}
|
|
}
|
|
this.onErrorObservable.notifyObservers(this);
|
|
this.onErrorObservable.notifyObservers(this);
|
|
|
|
+ this.onErrorObservable.clear();
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public get isSupported(): boolean {
|
|
public get isSupported(): boolean {
|
|
return this._compilationError === "";
|
|
return this._compilationError === "";
|
|
}
|
|
}
|
|
|
|
|
|
- public _bindTexture(channel: string, texture: WebGLTexture): void {
|
|
|
|
|
|
+ public _bindTexture(channel: string, texture: InternalTexture): void {
|
|
this._engine._bindTexture(this._samplers.indexOf(channel), texture);
|
|
this._engine._bindTexture(this._samplers.indexOf(channel), texture);
|
|
}
|
|
}
|
|
|
|
|