Added: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html (0 => 156351)
--- trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html 2013-09-24 19:43:22 UTC (rev 156351)
@@ -0,0 +1,193 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>WebGL BindAttribLocation Mapped Names Conformance Test</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></canvas>
+<script id="vshader" type="text/something-not-_javascript_">
+attribute vec4 vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ;
+attribute vec4 vColor;
+varying vec4 color;
+void main()
+{
+ gl_Position = vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ;
+ color = vColor;
+}
+</script>
+<script id="fshader" type="text/something-not-_javascript_">
+#ifdef GL_ES
+precision highp float;
+#endif
+varying vec4 color;
+void main()
+{
+ gl_FragColor = color;
+}
+</script>
+<script>
+description("This test ensures WebGL implementations don't allow names that start with 'gl_' when calling bindAttribLocation.");
+
+if (window.internals)
+ window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
+
+debug("");
+debug("Canvas.getContext");
+
+var gl = create3DContext(document.getElementById("canvas"));
+shouldBeNonNull(gl);
+
+function fail(x,y, buf, shouldBe)
+{
+ var i = (y*50+x) * 4;
+ var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
+ testFailed(reason);
+}
+
+function pass()
+{
+ testPassed("drawing is correct");
+}
+
+function loadShader(shaderType, shaderId) {
+ // Get the shader source.
+ var shaderSource = document.getElementById(shaderId).text;
+
+ // Create the shader object
+ var shader = gl.createShader(shaderType);
+ if (shader == null) {
+ debug("*** Error: unable to create shader '"+shaderId+"'");
+ return null;
+ }
+
+ // Load the shader source
+ gl.shaderSource(shader, shaderSource);
+
+ // Compile the shader
+ gl.compileShader(shader);
+
+ // Check the compile status
+ var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
+ if (!compiled) {
+ // Something went wrong during compilation; get the error
+ var error = gl.getShaderInfoLog(shader);
+ debug("*** Error compiling shader '"+shader+"':"+error);
+ gl.deleteShader(shader);
+ return null;
+ }
+ return shader;
+}
+
+debug("");
+debug("Checking gl.bindAttribLocation.");
+
+var program = gl.createProgram();
+
+var vs = loadShader(gl.VERTEX_SHADER, "vshader");
+var fs = loadShader(gl.FRAGMENT_SHADER, "fshader");
+gl.attachShader(program, vs);
+gl.attachShader(program, fs);
+
+var positions = gl.createBuffer();
+gl.bindBuffer(gl.ARRAY_BUFFER, positions);
+gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
+
+var colors = gl.createBuffer();
+gl.bindBuffer(gl.ARRAY_BUFFER, colors);
+gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
+ 0,1,0,1,
+ 0,1,0,1,
+ 0,1,0,1]), gl.STATIC_DRAW);
+
+function setBindLocations(colorLocation, positionLocation) {
+ gl.bindAttribLocation(program, positionLocation, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ");
+ gl.bindAttribLocation(program, colorLocation, "vColor");
+ gl.linkProgram(program);
+ gl.useProgram(program);
+ var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
+ assertMsg(linked, "program linked successfully");
+
+ debug("vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ:" + gl.getAttribLocation(program, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ"))
+ debug("vColor :" + gl.getAttribLocation(program, "vColor"))
+ assertMsg(gl.getAttribLocation(program, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ") == positionLocation,
+ "location of vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ should be " + positionLocation);
+ assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
+ "location of vColor should be " + colorLocation);
+
+ var ploc = gl.getAttribLocation(program, "vAVeryLongNameThatWillTriggerTheNameMappingInAllCasesABCDEFGHIJKLMNOPQ");
+ var cloc = gl.getAttribLocation(program, "vColor");
+ gl.bindBuffer(gl.ARRAY_BUFFER, positions);
+ gl.enableVertexAttribArray(positionLocation);
+ gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
+ gl.bindBuffer(gl.ARRAY_BUFFER, colors);
+ gl.enableVertexAttribArray(colorLocation);
+ gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
+}
+
+function checkDraw(colorLocation, positionLocation, r, g, b, a) {
+ gl.clearColor(0, 0, 0, 1);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
+
+ var width = 50;
+ var height = 50;
+ var buf = new Uint8Array(width * height * 4);
+ gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
+
+ function checkPixel(x, y, r, g, b, a) {
+ var offset = (y * width + x) * 4;
+ if (buf[offset + 0] != r ||
+ buf[offset + 1] != g ||
+ buf[offset + 2] != b ||
+ buf[offset + 3] != a) {
+ fail(x, y, buf, "(" + r + "," + g + "," + b + "," + a + ")");
+ return false;
+ }
+ return true;
+ }
+
+ // Test several locations
+ // First line should be all black
+ var success = true;
+ for (var i = 0; i < 50; ++i)
+ success = success && checkPixel(i, 0, 0, 0, 0, 255);
+
+ // Line 15 should be red for at least 10 rgba pixels starting 20 pixels in
+ var offset = (15 * 50 + 20) * 4;
+ for (var i = 0; i < 10; ++i)
+ success = success && checkPixel(20 + i, 15, r, g, b, a);
+
+ // Last line should be all black
+ for (var i = 0; i < 50; ++i)
+ success = success && checkPixel(i, 49, 0, 0, 0, 255);
+
+ if (success)
+ pass();
+
+ gl.disableVertexAttribArray(positionLocation);
+ gl.disableVertexAttribArray(colorLocation);
+}
+
+setBindLocations(2, 3);
+checkDraw(2, 3, 0, 255, 0, 255);
+
+setBindLocations(0, 3);
+gl.disableVertexAttribArray(0);
+gl.vertexAttrib4f(0, 1, 0, 0, 1);
+checkDraw(0, 3, 255, 0, 0, 255);
+
+glErrorShouldBe(gl, gl.NO_ERROR);
+
+debug("");
+
+</script>
+<script src=""
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-mapped-names.html
___________________________________________________________________
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (156350 => 156351)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2013-09-24 19:35:30 UTC (rev 156350)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp 2013-09-24 19:43:22 UTC (rev 156351)
@@ -314,7 +314,10 @@
{
ASSERT(program);
makeContextCurrent();
- ::glBindAttribLocation(program, index, name.utf8().data());
+
+ String mappedName = mappedSymbolName(program, SHADER_SYMBOL_TYPE_ATTRIBUTE, name);
+ LOG(WebGL, "::bindAttribLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
+ ::glBindAttribLocation(program, index, mappedName.utf8().data());
}
void GraphicsContext3D::bindBuffer(GC3Denum target, Platform3DObject buffer)
@@ -724,11 +727,8 @@
makeContextCurrent();
- // The attribute name may have been translated during ANGLE compilation.
- // Look through the corresponding ShaderSourceMap to make sure we
- // reference the mapped name rather than the external name.
String mappedName = mappedSymbolName(program, SHADER_SYMBOL_TYPE_ATTRIBUTE, name);
-
+ LOG(WebGL, "::getAttribLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
return ::glGetAttribLocation(program, mappedName.utf8().data());
}
@@ -1277,11 +1277,8 @@
makeContextCurrent();
- // The uniform name may have been translated during ANGLE compilation.
- // Look through the corresponding ShaderSourceMap to make sure we
- // reference the mapped name rather than the external name.
String mappedName = mappedSymbolName(program, SHADER_SYMBOL_TYPE_UNIFORM, name);
-
+ LOG(WebGL, "::getUniformLocation is mapping %s to %s", name.utf8().data(), mappedName.utf8().data());
return ::glGetUniformLocation(program, mappedName.utf8().data());
}