Commit 79ee1296 authored by kbr@google.com's avatar kbr@google.com

2010-07-13 Kenneth Russell <kbr@google.com>

        Reviewed by Darin Fisher.

        Fold most WebGL script-tests into .html files
        https://bugs.webkit.org/show_bug.cgi?id=42204

        For each WebGL script-test layout test which has a corresponding
        copy in the Khronos repository, folded the .js into the .html. This
        will make it easier to synchronize these tests between repositories.

        * fast/canvas/webgl/error-reporting.html:
        * fast/canvas/webgl/get-active-test.html:
        * fast/canvas/webgl/gl-object-get-calls.html:
        * fast/canvas/webgl/incorrect-context-object-behaviour.html:
        * fast/canvas/webgl/index-validation.html:
        * fast/canvas/webgl/null-object-behaviour.html:
        * fast/canvas/webgl/null-uniform-location.html:
        * fast/canvas/webgl/script-tests/error-reporting.js: Removed.
        * fast/canvas/webgl/script-tests/get-active-test.js: Removed.
        * fast/canvas/webgl/script-tests/gl-object-get-calls.js: Removed.
        * fast/canvas/webgl/script-tests/incorrect-context-object-behaviour.js: Removed.
        * fast/canvas/webgl/script-tests/index-validation.js: Removed.
        * fast/canvas/webgl/script-tests/null-object-behaviour.js: Removed.
        * fast/canvas/webgl/script-tests/null-uniform-location.js: Removed.
        * fast/canvas/webgl/script-tests/uniform-location.js: Removed.
        * fast/canvas/webgl/uniform-location.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63250 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4da4ca77
2010-07-13 Kenneth Russell <kbr@google.com>
Reviewed by Darin Fisher.
Fold most WebGL script-tests into .html files
https://bugs.webkit.org/show_bug.cgi?id=42204
For each WebGL script-test layout test which has a corresponding
copy in the Khronos repository, folded the .js into the .html. This
will make it easier to synchronize these tests between repositories.
* fast/canvas/webgl/error-reporting.html:
* fast/canvas/webgl/get-active-test.html:
* fast/canvas/webgl/gl-object-get-calls.html:
* fast/canvas/webgl/incorrect-context-object-behaviour.html:
* fast/canvas/webgl/index-validation.html:
* fast/canvas/webgl/null-object-behaviour.html:
* fast/canvas/webgl/null-uniform-location.html:
* fast/canvas/webgl/script-tests/error-reporting.js: Removed.
* fast/canvas/webgl/script-tests/get-active-test.js: Removed.
* fast/canvas/webgl/script-tests/gl-object-get-calls.js: Removed.
* fast/canvas/webgl/script-tests/incorrect-context-object-behaviour.js: Removed.
* fast/canvas/webgl/script-tests/index-validation.js: Removed.
* fast/canvas/webgl/script-tests/null-object-behaviour.js: Removed.
* fast/canvas/webgl/script-tests/null-uniform-location.js: Removed.
* fast/canvas/webgl/script-tests/uniform-location.js: Removed.
* fast/canvas/webgl/uniform-location.html:
2010-07-13 Kenneth Russell <kbr@google.com>
Reviewed by Darin Fisher.
......@@ -8,7 +8,61 @@
<div id="description"></div>
<div id="console"></div>
<script src="script-tests/error-reporting.js"></script>
<script>
description("Tests generation of synthetic and real GL errors");
var context = create3DContext();
var program = loadStandardProgram(context);
// Other tests in this directory like getActiveTest and
// incorrect-context-object-behaviour already test the raising of many
// synthetic GL errors. This test verifies the raising of certain
// known real GL errors, and contains a few regression tests for bugs
// discovered in the synthetic error generation and in the WebGL
// implementation itself.
shouldBe("context.getError()", "0");
debug("Testing getActiveAttrib");
// Synthetic OpenGL error
shouldBeNull("context.getActiveAttrib(null, 2)");
shouldBe("context.getError()", "context.INVALID_VALUE");
// Error state should be clear by this point
shouldBe("context.getError()", "context.NO_ERROR");
// Real OpenGL error
shouldBeNull("context.getActiveAttrib(program, 2)");
shouldBe("context.getError()", "context.INVALID_VALUE");
// Error state should be clear by this point
shouldBe("context.getError()", "context.NO_ERROR");
debug("Testing getActiveUniform");
// Synthetic OpenGL error
shouldBeNull("context.getActiveUniform(null, 0)");
shouldBe("context.getError()", "context.INVALID_VALUE");
// Error state should be clear by this point
shouldBe("context.getError()", "context.NO_ERROR");
// Real OpenGL error
shouldBeNull("context.getActiveUniform(program, 50)");
shouldBe("context.getError()", "context.INVALID_VALUE");
// Error state should be clear by this point
shouldBe("context.getError()", "context.NO_ERROR");
debug("Testing attempts to manipulate the default framebuffer");
shouldBeUndefined("context.bindFramebuffer(context.FRAMEBUFFER, 0)");
shouldBe("context.getError()", "context.NO_ERROR");
shouldBeUndefined("context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, 0)");
// Synthetic OpenGL error
shouldBe("context.getError()", "context.INVALID_OPERATION");
// Error state should be clear by this point
shouldBe("context.getError()", "context.NO_ERROR");
shouldBeUndefined("context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, 0, 0)");
// Synthetic OpenGL error
shouldBe("context.getError()", "context.INVALID_OPERATION");
// Error state should be clear by this point
shouldBe("context.getError()", "context.NO_ERROR");
successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
......
......@@ -8,7 +8,103 @@
<div id="description"></div>
<div id="console"></div>
<script src="script-tests/get-active-test.js"></script>
<script>
description("Test of getActiveAttrib and getActiveUniform");
var context = create3DContext();
shouldBeNonNull("context");
var context2 = create3DContext();
shouldBeNonNull("context2");
var program = loadStandardProgram(context);
shouldBeNonNull("program");
var program2 = loadProgram(context2,
"resources/intArrayUniformShader.vert",
"resources/noopUniformShader.frag");
shouldBeNonNull("program2");
shouldBe("context.getError()", "context.NO_ERROR");
shouldBe("context2.getError()", "context2.NO_ERROR");
shouldBe("context.getActiveUniform(program, 0).name", "'u_modelViewProjMatrix'");
shouldBe("context.getActiveUniform(program, 0).type", "context.FLOAT_MAT4");
shouldBe("context.getActiveUniform(program, 0).size", "1");
shouldBeNull("context.getActiveUniform(program, 1)");
shouldBe("context.getError()", "context.INVALID_VALUE");
shouldBeNull("context.getActiveUniform(program, -1)");
shouldBe("context.getError()", "context.INVALID_VALUE");
shouldBeNull("context.getActiveUniform(null, 0)");
shouldBe("context.getError()", "context.INVALID_VALUE");
// we don't know the order the attribs will appear.
var info = [
context.getActiveAttrib(program, 0),
context.getActiveAttrib(program, 1)
];
for (var ii = 0; ii < info.length; ++ii)
shouldBeNonNull("info[ii]");
var expected = [
{ name: 'a_normal', type: context.FLOAT_VEC3, size: 1 },
{ name: 'a_vertex', type: context.FLOAT_VEC4, size: 1 }
];
if (info[0].name != expected[0].name) {
t = info[0];
info[0] = info[1];
info[1] = t;
}
for (var ii = 0; ii < info.length; ++ii) {
shouldBe("info[ii].name", "expected[ii].name");
shouldBe("info[ii].type", "expected[ii].type");
shouldBe("info[ii].size", "expected[ii].size");
}
// we don't know the order the uniforms will appear.
var info2 = [
context2.getActiveUniform(program2, 0),
context2.getActiveUniform(program2, 1)
];
for (var ii = 0; ii < info2.length; ++ii)
shouldBeNonNull("info2[ii]");
var expected2 = [
{ name: 'ival', type: context2.INT, size: 1 },
{ name: 'ival2[0]', type: context2.INT, size: 2 }
];
if (info2[0].name != expected2[0].name) {
t = info2[0];
info2[0] = info2[1];
info2[1] = t;
}
for (var ii = 0; ii < info2.length; ++ii) {
shouldBe("info2[ii].name", "expected2[ii].name");
shouldBe("info2[ii].type", "expected2[ii].type");
shouldBe("info2[ii].size", "expected2[ii].size");
}
shouldBeNull("context.getActiveAttrib(program, 2)");
shouldBe("context.getError()", "context.INVALID_VALUE");
shouldBeNull("context.getActiveAttrib(program, -1)");
shouldBe("context.getError()", "context.INVALID_VALUE");
shouldBeNull("context.getActiveAttrib(null, 0)");
shouldBe("context.getError()", "context.INVALID_VALUE");
shouldBe("context2.getError()", "context.NO_ERROR");
shouldBeNull("context2.getActiveAttrib(program, 0)");
shouldBe("context2.getError()", "context2.INVALID_OPERATION");
shouldBeNull("context2.getActiveUniform(program, 0)");
shouldBe("context2.getError()", "context2.INVALID_OPERATION");
context.deleteProgram(program);
shouldBeNull("context.getActiveUniform(program, 0)");
shouldBe("context.getError()", "context.INVALID_VALUE");
shouldBeNull("context.getActiveAttrib(program, 0)");
shouldBe("context.getError()", "context.INVALID_VALUE");
successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
......
......@@ -8,7 +8,232 @@
<div id="description"></div>
<div id="console"></div>
<script src="script-tests/gl-object-get-calls.js"></script>
<script>
description("Test of get calls against GL objects like getBufferParameter, etc.");
var gl = create3DContext();
var errorVert = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(errorVert, "I am a bad vertex shader");
gl.compileShader(errorVert);
var errorFrag = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(errorFrag, "I am a bad fragment shader");
gl.compileShader(errorFrag);
var standardVert = loadStandardVertexShader(gl);
var standardFrag = loadStandardFragmentShader(gl);
var standardProgram = gl.createProgram();
gl.attachShader(standardProgram, standardVert);
gl.attachShader(standardProgram, standardFrag);
gl.linkProgram(standardProgram);
// Test program and shader gets
var parseError = "ERROR: 0:1: 'I' : syntax error syntax error\nERROR: Parser found no code to compile in source strings.\n";
var errorVertString = "I am a bad vertex shader\n";
var errorFragString = "I am a bad fragment shader\n";
shouldBe('gl.getProgramInfoLog(standardProgram)', '""');
shouldBe('gl.getShaderInfoLog(errorVert)', 'parseError');
shouldBe('gl.getShaderInfoLog(errorFrag)', 'parseError');
shouldBe('gl.getShaderSource(errorVert)', 'errorVertString');
shouldBe('gl.getShaderSource(errorFrag)', 'errorFragString');
var shaders = gl.getAttachedShaders(standardProgram);
shouldBe('shaders.length', '2');
shouldBeTrue('shaders[0] == standardVert && shaders[1] == standardFrag || shaders[1] == standardVert && shaders[0] == standardFrag');
shouldBe('gl.getError()', 'gl.NO_ERROR');
shouldBeUndefined('gl.getAttachedShaders(null)');
shouldBe('gl.getError()', 'gl.INVALID_VALUE');
shouldBeUndefined('gl.getAttachedShaders(standardVert)');
shouldBe('gl.getError()', 'gl.INVALID_VALUE');
// Test getBufferParameter
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, 16, gl.DYNAMIC_DRAW);
shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)', '16');
shouldBe('gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_USAGE)', 'gl.DYNAMIC_DRAW');
// Test getFramebufferAttachmentParameter
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE,
new WebGLUnsignedByteArray([0, 0, 0, 255,
255, 255, 255, 255,
255, 255, 255, 255,
0, 0, 0, 255]));
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.bindTexture(gl.TEXTURE_2D, null);
var framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
var renderbuffer = gl.createRenderbuffer();
shouldBe('gl.getError()', '0');
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
shouldBe('gl.getError()', '0');
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 2, 2);
shouldBe('gl.getError()', '0');
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, renderbuffer);
// FIXME: on some machines (in particular the WebKit commit bots) the
// framebuffer status is FRAMEBUFFER_UNSUPPORTED; more investigation
// is needed why this is the case, because the FBO allocated
// internally by the WebKit implementation has almost identical
// parameters to this one. See https://bugs.webkit.org/show_bug.cgi?id=31843.
//shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.TEXTURE');
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'texture');
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL)', '0');
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE)', '0');
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)', 'gl.RENDERBUFFER');
shouldBe('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)', 'renderbuffer');
// Test getProgramParameter
shouldBe('gl.getProgramParameter(standardProgram, gl.DELETE_STATUS)', 'false');
shouldBe('gl.getProgramParameter(standardProgram, gl.LINK_STATUS)', 'true');
shouldBe('typeof gl.getProgramParameter(standardProgram, gl.VALIDATE_STATUS)', '"boolean"');
shouldBe('typeof gl.getProgramParameter(standardProgram, gl.INFO_LOG_LENGTH)', '"number"');
shouldBe('gl.getProgramParameter(standardProgram, gl.ATTACHED_SHADERS)', '2');
shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTES)', '2');
shouldBeNonZero('gl.getProgramParameter(standardProgram, gl.ACTIVE_ATTRIBUTE_MAX_LENGTH)');
shouldBe('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORMS)', '1');
shouldBeNonZero('gl.getProgramParameter(standardProgram, gl.ACTIVE_UNIFORM_MAX_LENGTH)');
// Test getRenderbufferParameter
shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)', '2');
shouldBe('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_HEIGHT)', '2');
// Note: we can't test the actual value of the internal format since
// the implementation is allowed to change it.
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_INTERNAL_FORMAT)');
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_DEPTH_SIZE)');
var colorbuffer = gl.createRenderbuffer();
shouldBe('gl.getError()', '0');
gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
shouldBe('gl.getError()', '0');
gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 2, 2);
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_RED_SIZE)');
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_GREEN_SIZE)');
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_BLUE_SIZE)');
shouldBeNonZero('gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_ALPHA_SIZE)');
// Test getShaderParameter
shouldBe('gl.getShaderParameter(standardVert, gl.SHADER_TYPE)', 'gl.VERTEX_SHADER');
shouldBe('gl.getShaderParameter(standardVert, gl.DELETE_STATUS)', 'false');
shouldBe('gl.getShaderParameter(standardVert, gl.COMPILE_STATUS)', 'true');
shouldBe('typeof gl.getShaderParameter(standardVert, gl.INFO_LOG_LENGTH)', '"number"');
shouldBeNonZero('gl.getShaderParameter(standardVert, gl.SHADER_SOURCE_LENGTH)');
// Test getTexParameter
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER)', 'gl.NEAREST');
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)', 'gl.NEAREST');
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)', 'gl.CLAMP_TO_EDGE');
shouldBe('gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T)', 'gl.CLAMP_TO_EDGE');
// Test getUniform with all variants of data types
// Boolean uniform variables
var boolProgram = loadProgram(gl, "resources/boolUniformShader.vert", "resources/noopUniformShader.frag");
shouldBe('gl.getProgramParameter(boolProgram, gl.LINK_STATUS)', 'true');
var bvalLoc = gl.getUniformLocation(boolProgram, "bval");
var bval2Loc = gl.getUniformLocation(boolProgram, "bval2");
var bval3Loc = gl.getUniformLocation(boolProgram, "bval3");
var bval4Loc = gl.getUniformLocation(boolProgram, "bval4");
gl.useProgram(boolProgram);
gl.uniform1i(bvalLoc, 1);
gl.uniform2i(bval2Loc, 1, 0);
gl.uniform3i(bval3Loc, 1, 0, 1);
gl.uniform4i(bval4Loc, 1, 0, 1, 0);
shouldBe('gl.getError()', '0');
shouldBe('gl.getUniform(boolProgram, bvalLoc)', 'true');
shouldBe('gl.getUniform(boolProgram, bval2Loc)', '[1, 0]');
shouldBe('gl.getUniform(boolProgram, bval3Loc)', '[1, 0, 1]');
shouldBe('gl.getUniform(boolProgram, bval4Loc)', '[1, 0, 1, 0]');
// Integer uniform variables
var intProgram = loadProgram(gl, "resources/intUniformShader.vert", "resources/noopUniformShader.frag");
shouldBe('gl.getProgramParameter(intProgram, gl.LINK_STATUS)', 'true');
var ivalLoc = gl.getUniformLocation(intProgram, "ival");
var ival2Loc = gl.getUniformLocation(intProgram, "ival2");
var ival3Loc = gl.getUniformLocation(intProgram, "ival3");
var ival4Loc = gl.getUniformLocation(intProgram, "ival4");
gl.useProgram(intProgram);
gl.uniform1i(ivalLoc, 1);
gl.uniform2i(ival2Loc, 2, 3);
gl.uniform3i(ival3Loc, 4, 5, 6);
gl.uniform4i(ival4Loc, 7, 8, 9, 10);
shouldBe('gl.getError()', '0');
shouldBe('gl.getUniform(intProgram, ivalLoc)', '1');
shouldBe('gl.getUniform(intProgram, ival2Loc)', '[2, 3]');
shouldBe('gl.getUniform(intProgram, ival3Loc)', '[4, 5, 6]');
shouldBe('gl.getUniform(intProgram, ival4Loc)', '[7, 8, 9, 10]');
// Float uniform variables
var floatProgram = loadProgram(gl, "resources/floatUniformShader.vert", "resources/noopUniformShader.frag");
shouldBe('gl.getProgramParameter(floatProgram, gl.LINK_STATUS)', 'true');
var fvalLoc = gl.getUniformLocation(floatProgram, "fval");
var fval2Loc = gl.getUniformLocation(floatProgram, "fval2");
var fval3Loc = gl.getUniformLocation(floatProgram, "fval3");
var fval4Loc = gl.getUniformLocation(floatProgram, "fval4");
gl.useProgram(floatProgram);
gl.uniform1f(fvalLoc, 11);
gl.uniform2f(fval2Loc, 12, 13);
gl.uniform3f(fval3Loc, 14, 15, 16);
gl.uniform4f(fval4Loc, 17, 18, 19, 20);
shouldBe('gl.getError()', '0');
shouldBe('gl.getUniform(floatProgram, fvalLoc)', '11');
shouldBe('gl.getUniform(floatProgram, fval2Loc)', '[12, 13]');
shouldBe('gl.getUniform(floatProgram, fval3Loc)', '[14, 15, 16]');
shouldBe('gl.getUniform(floatProgram, fval4Loc)', '[17, 18, 19, 20]');
// Matrix uniform variables
var matProgram = loadProgram(gl, "resources/matUniformShader.vert", "resources/noopUniformShader.frag");
shouldBe('gl.getProgramParameter(matProgram, gl.LINK_STATUS)', 'true');
var mval2Loc = gl.getUniformLocation(matProgram, "mval2");
var mval3Loc = gl.getUniformLocation(matProgram, "mval3");
var mval4Loc = gl.getUniformLocation(matProgram, "mval4");
gl.useProgram(matProgram);
gl.uniformMatrix2fv(mval2Loc, false, [1, 2, 3, 4]);
gl.uniformMatrix3fv(mval3Loc, false, [5, 6, 7, 8, 9, 10, 11, 12, 13]);
gl.uniformMatrix4fv(mval4Loc, false, [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]);
shouldBe('gl.getError()', '0');
shouldBe('gl.getUniform(matProgram, mval2Loc)', '[1, 2, 3, 4]');
shouldBe('gl.getUniform(matProgram, mval3Loc)', '[5, 6, 7, 8, 9, 10, 11, 12, 13]');
shouldBe('gl.getUniform(matProgram, mval4Loc)', '[14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]');
// Test getVertexAttrib
var array = new WebGLFloatArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
gl.bufferData(gl.ARRAY_BUFFER, array, gl.DYNAMIC_DRAW);
// Vertex attribute 0 is special in that it has no current state, so
// fetching GL_CURRENT_VERTEX_ATTRIB generates an error. Use attribute
// 1 for these tests instead.
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(1, 4, gl.FLOAT, false, 0, 0);
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)', 'buffer');
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'true');
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_SIZE)', '4');
shouldBe('(gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == 0) || (gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == 4 * gl.sizeInBytes(gl.FLOAT))', 'true');
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_TYPE)', 'gl.FLOAT');
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED)', 'false');
gl.disableVertexAttribArray(1);
shouldBe('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_ENABLED)', 'false');
gl.vertexAttrib4f(1, 5, 6, 7, 8);
shouldBe('gl.getVertexAttrib(1, gl.CURRENT_VERTEX_ATTRIB)', '[5, 6, 7, 8]');
shouldBe('gl.getError()', '0');
// Test cases where name == 0
gl.deleteTexture(texture);
shouldBeNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
gl.deleteRenderbuffer(renderbuffer);
shouldBeNull('gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)');
gl.deleteBuffer(buffer);
shouldBeNull('gl.getVertexAttrib(1, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)');
shouldBe('gl.getError()', '0');
successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
......
......@@ -8,7 +8,49 @@
<div id="description"></div>
<div id="console"></div>
<script src="script-tests/incorrect-context-object-behaviour.js"></script>
<script>
description("Tests calling WebGL APIs with objects from other contexts");
var contextA = create3DContext();
var contextB = create3DContext();
var programA = loadStandardProgram(contextA);
var programB = loadStandardProgram(contextB);
var shaderA = loadStandardVertexShader(contextA);
var shaderB = loadStandardVertexShader(contextB);
var textureA = contextA.createTexture();
var textureB = contextB.createTexture();
var frameBufferA = contextA.createFramebuffer();
var frameBufferB = contextB.createFramebuffer();
var renderBufferA = contextA.createRenderbuffer();
var renderBufferB = contextB.createRenderbuffer();
var locationA = contextA.getUniformLocation(programA, 'u_modelViewProjMatrix');
var locationB = contextB.getUniformLocation(programB, 'u_modelViewProjMatrix');
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.compileShader(shaderB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.linkProgram(programB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programA, shaderB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderA)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.attachShader(programB, shaderB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programA, shaderB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderA)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.detachShader(programB, shaderB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.shaderSource(shaderB, 'foo')");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindAttribLocation(programB, 0, 'foo')");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindFramebuffer(contextA.FRAMEBUFFER, frameBufferB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindRenderbuffer(contextA.RENDERBUFFER, renderBufferB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.bindTexture(contextA.TEXTURE_2D, textureB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferRenderbuffer(contextA.FRAMEBUFFER, contextA.DEPTH_ATTACHMENT, contextA.RENDERBUFFER, renderBufferB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.framebufferTexture2D(contextA.FRAMEBUFFER, contextA.COLOR_ATTACHMENT0, contextA.TEXTURE_2D, textureB, 0)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramParameter(programB, 0)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getProgramInfoLog(programB, 0)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderParameter(shaderB, 0)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderInfoLog(shaderB, 0)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getShaderSource(shaderB)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniform(programB, locationA)");
shouldGenerateGLError(contextA, contextA.INVALID_OPERATION, "contextA.getUniformLocation(programB, 'u_modelViewProjMatrix')");
successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
......
......@@ -8,7 +8,82 @@
<div id="description"></div>
<div id="console"></div>
<script src="script-tests/index-validation.js"></script>
<script>
description("Test of validating indices for drawElements().");
var gl = create3DContext();
var program = loadStandardProgram(gl);
// 3 vertices => 1 triangle, interleaved data
var dataComplete = new WebGLFloatArray([0, 0, 0, 1,
0, 0, 1,
1, 0, 0, 1,
0, 0, 1,
1, 1, 1, 1,
0, 0, 1]);
var dataIncomplete = new WebGLFloatArray([0, 0, 0, 1,
0, 0, 1,
1, 0, 0, 1,
0, 0, 1,
1, 1, 1, 1]);
var indices = new WebGLUnsignedShortArray([0, 1, 2]);
debug("Testing with valid indices");
var bufferComplete = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW);
var elements = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
gl.useProgram(program);
var vertexLoc = gl.getAttribLocation(program, "a_vertex");
var normalLoc = gl.getAttribLocation(program, "a_normal");
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0);
gl.enableVertexAttribArray(vertexLoc);
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
gl.enableVertexAttribArray(normalLoc);
shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
shouldBe('gl.getError()', '0');
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
shouldBe('gl.getError()', '0');
debug("Testing with out-of-range indices");
var bufferIncomplete = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW);
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 0);
gl.enableVertexAttribArray(vertexLoc);
gl.disableVertexAttribArray(normalLoc);
debug("Enable vertices, valid");
shouldBe('gl.getError()', '0');
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
shouldBe('gl.getError()', '0');
debug("Enable normals, out-of-range");
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
gl.enableVertexAttribArray(normalLoc);
shouldBe('gl.getError()', '0');
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
shouldBe('gl.getError()', 'gl.INVALID_OPERATION');
debug("Test with enabled attribute that does not belong to current program");
gl.disableVertexAttribArray(normalLoc);
var extraLoc = Math.max(vertexLoc, normalLoc) + 1;
gl.enableVertexAttribArray(extraLoc);
debug("Enable an extra attribute with null");
shouldBe('gl.getError()', '0');
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
shouldBe('gl.getError()', 'gl.INVALID_OPERATION');
debug("Enable an extra attribute with insufficient data buffer");
gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * gl.sizeInBytes(gl.FLOAT), 4 * gl.sizeInBytes(gl.FLOAT));
shouldBe('gl.getError()', '0');
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
shouldBe('gl.getError()', '0');
successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
......
......@@ -8,7 +8,43 @@
<div id="description"></div>
<div id="console"></div>
<script src="script-tests/null-object-behaviour.js"></script>
<script>
description("Tests calling WebGL APIs without providing the necessary objects");
var context = create3DDebugContext();
var program = loadStandardProgram(context