Skip to content

Commit

Permalink
Start of WEBGL_debug_shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed Oct 15, 2014
1 parent 8abc4e3 commit 7ed2927
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Source/Renderer/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ define([
this._maximumDrawBuffers = defined(this._drawBuffers) ? gl.getParameter(this._drawBuffers.MAX_DRAW_BUFFERS_WEBGL) : 1;
this._maximumColorAttachments = defined(this._drawBuffers) ? gl.getParameter(this._drawBuffers.MAX_COLOR_ATTACHMENTS_WEBGL) : 1; // min when supported: 4

this._debugShaders = getExtension(gl, ['WEBGL_debug_shaders']);

var cc = gl.getParameter(gl.COLOR_CLEAR_VALUE);
this._clearColor = new Color(cc[0], cc[1], cc[2], cc[3]);
this._clearDepth = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
Expand Down Expand Up @@ -825,6 +827,12 @@ define([
}
},

debugShaders : {
get : function() {
return this._debugShaders;
}
},

throwOnWebGLError : {
get : function() {
return this._throwOnWebGLError;
Expand Down
2 changes: 1 addition & 1 deletion Source/Renderer/ShaderCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ define([
delete this._shadersToRelease[keyword];
} else {
var context = this._context;
var sp = new ShaderProgram(context._gl, context.logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations);
var sp = new ShaderProgram(context._gl, context.logShaderCompilation, context.debugShaders, vertexShaderSource, fragmentShaderSource, attributeLocations);

cachedShader = {
cache : this,
Expand Down
14 changes: 11 additions & 3 deletions Source/Renderer/ShaderProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,10 @@ define([
/**
* @private
*/
var ShaderProgram = function(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations) {
var ShaderProgram = function(gl, logShaderCompilation, debugShaders, vertexShaderSource, fragmentShaderSource, attributeLocations) {
this._gl = gl;
this._logShaderCompilation = logShaderCompilation;
this._debugShaders = debugShaders;
this._attributeLocations = attributeLocations;

this._program = undefined;
Expand Down Expand Up @@ -624,7 +625,7 @@ define([
'#endif \n\n';
}

function createAndLinkProgram(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations) {
function createAndLinkProgram(gl, logShaderCompilation, debugShaders, vertexShaderSource, fragmentShaderSource, attributeLocations) {
var vsSourceVersioned = extractShaderVersion(vertexShaderSource);
var fsSourceVersioned = extractShaderVersion(fragmentShaderSource);

Expand Down Expand Up @@ -672,13 +673,20 @@ define([
log = gl.getShaderInfoLog(fragmentShader);
gl.deleteProgram(program);
console.error('[GL] Fragment shader compile log: ' + log);
if (defined(debugShaders)) {
console.error('[GL] Translated fragment shader source:\n' + debugShaders.getTranslatedShaderSource(fragmentShader));
}

throw new RuntimeError('Fragment shader failed to compile. Compile log: ' + log);
}

if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
log = gl.getShaderInfoLog(vertexShader);
gl.deleteProgram(program);
console.error('[GL] Vertex shader compile log: ' + log);
if (defined(debugShaders)) {
console.error('[GL] Translated vertex shader source:\n' + debugShaders.getTranslatedShaderSource(vertexShader));
}
throw new RuntimeError('Vertex shader failed to compile. Compile log: ' + log);
}

Expand Down Expand Up @@ -858,7 +866,7 @@ define([
}

var gl = shader._gl;
var program = createAndLinkProgram(gl, shader._logShaderCompilation, shader.vertexShaderSource, shader.fragmentShaderSource, shader._attributeLocations);
var program = createAndLinkProgram(gl, shader._logShaderCompilation, shader._debugShaders, shader.vertexShaderSource, shader.fragmentShaderSource, shader._attributeLocations);
var numberOfVertexAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
var uniforms = findUniforms(gl, program);
var partitionedUniforms = partitionUniforms(uniforms.uniformsByName);
Expand Down

0 comments on commit 7ed2927

Please sign in to comment.