Add support for OES_vertex_array_object in chromium
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Sep 2012 23:47:36 +0000 (23:47 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Sep 2012 23:47:36 +0000 (23:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=96578

Patch by Brandon Jones <bajones@google.com> on 2012-09-21
Reviewed by Kenneth Russell.

Source/Platform:

Added code to allow calls to the OES_vertex_array_object extension to interface
properly with the chromium WebGL implementation.

* chromium/public/WebGraphicsContext3D.h:
(WebGraphicsContext3D):
(WebKit::WebGraphicsContext3D::createVertexArrayOES):
(WebKit::WebGraphicsContext3D::deleteVertexArrayOES):
(WebKit::WebGraphicsContext3D::isVertexArrayOES):
(WebKit::WebGraphicsContext3D::bindVertexArrayOES):

Source/WebCore:

Adding basic reference counting to WebGLBuffer objects to satisfy spec requirements
for the OES_vertex_array_object extension. Added code to allow calls to the
OES_vertex_array_object extension to interface properly with the chromium WebGL
implementation.

Test: fast/canvas/webgl/oes-vertex-array-object.html

* html/canvas/WebGLRenderingContext.cpp:
(WebCore):
(WebCore::WebGLRenderingContext::deleteBuffer):
(WebCore::WebGLRenderingContext::vertexAttribPointer):
* html/canvas/WebGLVertexArrayObjectOES.cpp:
(WebCore::WebGLVertexArrayObjectOES::setElementArrayBuffer):
(WebCore):
* html/canvas/WebGLVertexArrayObjectOES.h:
(WebGLVertexArrayObjectOES):
(WebCore::WebGLVertexArrayObjectOES::getVertexAttribStateSize):
* platform/chromium/support/Extensions3DChromium.cpp:
(WebCore::Extensions3DChromium::createVertexArrayOES):
(WebCore::Extensions3DChromium::deleteVertexArrayOES):
(WebCore::Extensions3DChromium::isVertexArrayOES):
(WebCore::Extensions3DChromium::bindVertexArrayOES):

LayoutTests:

Brought over KHRONOS conformance test for OES_vertex_array_object

* fast/canvas/webgl/oes-vertex-array-object-expected.txt: Added.
* fast/canvas/webgl/oes-vertex-array-object.html: Added.
* platform/efl/Skipped:
* platform/gtk-wk2/Skipped:
* platform/mac/Skipped:
* platform/wk2/Skipped:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@129275 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/oes-vertex-array-object-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/oes-vertex-array-object.html [new file with mode: 0644]
LayoutTests/platform/chromium/TestExpectations
LayoutTests/platform/efl/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/wk2/Skipped
Source/Platform/ChangeLog
Source/Platform/chromium/public/WebGraphicsContext3D.h
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Source/WebCore/html/canvas/WebGLRenderingContext.h
Source/WebCore/html/canvas/WebGLVertexArrayObjectOES.cpp
Source/WebCore/html/canvas/WebGLVertexArrayObjectOES.h
Source/WebCore/platform/chromium/support/Extensions3DChromium.cpp

index 3523dae..34db500 100644 (file)
@@ -1,3 +1,19 @@
+2012-09-21  Brandon Jones  <bajones@google.com>
+
+        Add support for OES_vertex_array_object in chromium
+        https://bugs.webkit.org/show_bug.cgi?id=96578
+
+        Reviewed by Kenneth Russell.
+
+        Brought over KHRONOS conformance test for OES_vertex_array_object
+
+        * fast/canvas/webgl/oes-vertex-array-object-expected.txt: Added.
+        * fast/canvas/webgl/oes-vertex-array-object.html: Added.
+        * platform/efl/Skipped:
+        * platform/gtk-wk2/Skipped:
+        * platform/mac/Skipped:
+        * platform/wk2/Skipped:
+
 2012-09-21  Kenichi Ishibashi  <bashi@chromium.org>
 
         [Chromium] Use OpenTypeVerticalData on Linux
diff --git a/LayoutTests/fast/canvas/webgl/oes-vertex-array-object-expected.txt b/LayoutTests/fast/canvas/webgl/oes-vertex-array-object-expected.txt
new file mode 100644 (file)
index 0000000..37abadd
--- /dev/null
@@ -0,0 +1,50 @@
+This test verifies the functionality of the OES_vertex_array_object extension, if it is available.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS WebGL context exists
+Testing binding enum with extension disabled
+PASS getError was expected value: INVALID_ENUM : VERTEX_ARRAY_BINDING_OES should not be queryable if extension is disabled
+PASS Successfully enabled OES_vertex_array_object extension
+PASS OES_vertex_array_object listed as supported and getExtension succeeded
+Testing binding enum with extension enabled
+PASS ext.VERTEX_ARRAY_BINDING_OES is 0x85B5
+PASS getError was expected value: NO_ERROR : VERTEX_ARRAY_BINDING_OES query should succeed if extension is enable
+PASS Default value of VERTEX_ARRAY_BINDING_OES is null
+Testing binding a VAO
+PASS gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is null
+PASS gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO
+PASS gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO
+PASS gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is null
+PASS getError was expected value: INVALID_OPERATION : binding a deleted vertex array object
+PASS gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is null
+Testing object creation
+PASS getError was expected value: NO_ERROR : createVertexArrayOES should not set an error
+PASS vao is non-null.
+PASS ext.isVertexArrayOES(vao) is false
+PASS ext.isVertexArrayOES(vao) is true
+PASS ext.isVertexArrayOES(vao) is true
+PASS ext.isVertexArrayOES() is false
+PASS ext.isVertexArrayOES(null) is false
+Testing attributes work across bindings
+PASS All attributes preserved across bindings
+Testing that attribute values are not attached to bindings
+PASS Vertex attribute values are not attached to bindings
+Testing draws with various VAO bindings
+PASS Draw 0 passed pixel test
+PASS Draw 1 passed pixel test
+PASS Draw 2 passed pixel test
+Testing using deleted buffers referenced by VAOs
+PASS should be 255,0,0,255
+PASS should be 0,255,0,255
+PASS should be 0,0,255,255
+PASS should be 0,255,255,255
+Testing that VAOs don't effect ARRAY_BUFFER binding.
+PASS should be red
+PASS should be green
+PASS getError was expected value: NO_ERROR : there should be no errors
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
\ No newline at end of file
diff --git a/LayoutTests/fast/canvas/webgl/oes-vertex-array-object.html b/LayoutTests/fast/canvas/webgl/oes-vertex-array-object.html
new file mode 100644 (file)
index 0000000..cd07943
--- /dev/null
@@ -0,0 +1,597 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>WebGL OES_vertex_array_object Conformance Tests</title>
+<script src="resources/desktop-gl-constants.js" type="text/javascript"></script>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script src="resources/webgl-test.js"></script>
+<script src="resources/webgl-test-utils.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
+<div id="console"></div>
+<script id="vshader", type="x-shader/x-vertex">
+attribute vec4 a_position;
+attribute vec4 a_color;
+varying vec4 v_color;
+void main(void) {
+    gl_Position = a_position;
+    v_color = a_color;
+}
+</script>
+<script id="fshader", type="x-shader/x-fragment">
+precision mediump float;
+varying vec4 v_color;
+void main(void) {
+    gl_FragColor = v_color;
+}
+</script>
+<script>
+description("This test verifies the functionality of the OES_vertex_array_object extension, if it is available.");
+
+debug("");
+
+var wtu = WebGLTestUtils;
+var canvas = document.getElementById("canvas");
+var gl = create3DContext(canvas);
+var ext = null;
+var vao = null;
+
+if (!gl) {
+    testFailed("WebGL context does not exist");
+} else {
+    testPassed("WebGL context exists");
+
+    // Setup emulated OESVertexArrayObject if it has been included.
+    if (window.setupVertexArrayObject) {
+        debug("using emuated OES_vertex_array_object");
+        setupVertexArrayObject(gl);
+    }
+
+    // Run tests with extension disabled
+    runBindingTestDisabled();
+
+    // Query the extension and store globally so shouldBe can access it
+    ext = gl.getExtension("OES_vertex_array_object");
+    if (!ext) {
+        testPassed("No OES_vertex_array_object support -- this is legal");
+
+        runSupportedTest(false);
+    } else {
+        testPassed("Successfully enabled OES_vertex_array_object extension");
+
+        runSupportedTest(true);
+        runBindingTestEnabled();
+        runObjectTest();
+        runAttributeTests();
+        runAttributeValueTests();
+        runDrawTests();
+        runDeleteTests();
+        runArrayBufferBindTests();
+        glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
+    }
+}
+
+function runSupportedTest(extensionEnabled) {
+    var supported = gl.getSupportedExtensions();
+    if (supported.indexOf("OES_vertex_array_object") >= 0) {
+        if (extensionEnabled) {
+            testPassed("OES_vertex_array_object listed as supported and getExtension succeeded");
+        } else {
+            testFailed("OES_vertex_array_object listed as supported but getExtension failed");
+        }
+    } else {
+        if (extensionEnabled) {
+            testFailed("OES_vertex_array_object not listed as supported but getExtension succeeded");
+        } else {
+            testPassed("OES_vertex_array_object not listed as supported and getExtension failed -- this is legal");
+        }
+    }
+}
+
+function runBindingTestDisabled() {
+    debug("Testing binding enum with extension disabled");
+    
+    // Use the constant directly as we don't have the extension
+    var VERTEX_ARRAY_BINDING_OES = 0x85B5;
+    
+    gl.getParameter(VERTEX_ARRAY_BINDING_OES);
+    glErrorShouldBe(gl, gl.INVALID_ENUM, "VERTEX_ARRAY_BINDING_OES should not be queryable if extension is disabled");
+}
+
+function runBindingTestEnabled() {
+    debug("Testing binding enum with extension enabled");
+    
+    shouldBe("ext.VERTEX_ARRAY_BINDING_OES", "0x85B5");
+    
+    gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES);
+    glErrorShouldBe(gl, gl.NO_ERROR, "VERTEX_ARRAY_BINDING_OES query should succeed if extension is enable");
+    
+    // Default value is null
+    if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) === null) {
+        testPassed("Default value of VERTEX_ARRAY_BINDING_OES is null");
+    } else {
+        testFailed("Default value of VERTEX_ARRAY_BINDING_OES is not null");
+    }
+    
+    debug("Testing binding a VAO");
+    var vao0 = ext.createVertexArrayOES();
+    var vao1 = ext.createVertexArrayOES();
+    shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)");
+    ext.bindVertexArrayOES(vao0);
+    if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao0) {
+        testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO");
+    } else {
+        testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expected VAO")
+    }
+    ext.bindVertexArrayOES(vao1);
+    if (gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) == vao1) {
+        testPassed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is expected VAO");
+    } else {
+        testFailed("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES) is not expected VAO")
+    }
+    ext.deleteVertexArrayOES(vao1);
+    shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)");
+    ext.bindVertexArrayOES(vao1);
+    glErrorShouldBe(gl, gl.INVALID_OPERATION, "binding a deleted vertex array object");
+    ext.bindVertexArrayOES(null);
+    shouldBeNull("gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES)");
+    ext.deleteVertexArrayOES(vao1);
+}
+
+function runObjectTest() {
+    debug("Testing object creation");
+    
+    vao = ext.createVertexArrayOES();
+    glErrorShouldBe(gl, gl.NO_ERROR, "createVertexArrayOES should not set an error");
+    shouldBeNonNull("vao");
+    
+    // Expect false if never bound
+    shouldBeFalse("ext.isVertexArrayOES(vao)");
+    ext.bindVertexArrayOES(vao);
+    shouldBeTrue("ext.isVertexArrayOES(vao)");
+    ext.bindVertexArrayOES(null);
+    shouldBeTrue("ext.isVertexArrayOES(vao)");
+    
+    shouldBeFalse("ext.isVertexArrayOES()");
+    shouldBeFalse("ext.isVertexArrayOES(null)");
+    
+    ext.deleteVertexArrayOES(vao);
+    vao = null;
+}
+
+function runAttributeTests() {
+    debug("Testing attributes work across bindings");
+    
+    var states = [];
+    
+    var attrCount = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
+    for (var n = 0; n < attrCount; n++) {
+        gl.bindBuffer(gl.ARRAY_BUFFER, null);
+        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
+        
+        var state = {};
+        states.push(state);
+        
+        var vao = state.vao = ext.createVertexArrayOES();
+        ext.bindVertexArrayOES(vao);
+        
+        if (n % 2 == 0) {
+            gl.enableVertexAttribArray(n);
+        } else {
+            gl.disableVertexAttribArray(n);
+        }
+        
+        if (n % 2 == 0) {
+            var buffer = state.buffer = gl.createBuffer();
+            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
+            gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
+            
+            gl.vertexAttribPointer(n, 1 + n % 4, gl.FLOAT, true, n * 4, n * 4);
+        }
+        
+        if (n % 2 == 0) {
+            var elbuffer = state.elbuffer = gl.createBuffer();
+            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elbuffer);
+            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
+        }
+        
+        ext.bindVertexArrayOES(null);
+    }
+    
+    var anyMismatch = false;
+    for (var n = 0; n < attrCount; n++) {
+        var state = states[n];
+        
+        ext.bindVertexArrayOES(state.vao);
+        
+        var isEnabled = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_ENABLED);
+        if ((n % 2 == 1) || isEnabled) {
+            // Valid
+        } else {
+            testFailed("VERTEX_ATTRIB_ARRAY_ENABLED not preserved");
+            anyMismatch = true;
+        }
+        
+        var buffer = gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
+        if (n % 2 == 0) {
+            if (buffer == state.buffer) {
+                // Matched
+                if ((gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_SIZE) == 1 + n % 4) &&
+                    (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_TYPE) == gl.FLOAT) &&
+                    (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED) == true) &&
+                    (gl.getVertexAttrib(n, gl.VERTEX_ATTRIB_ARRAY_STRIDE) == n * 4) &&
+                    (gl.getVertexAttribOffset(n, gl.VERTEX_ATTRIB_ARRAY_POINTER) == n * 4)) {
+                    // Matched
+                } else {
+                    testFailed("VERTEX_ATTRIB_ARRAY_* not preserved");
+                    anyMismatch = true;
+                }
+            } else {
+                testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved");
+                anyMismatch = true;
+            }
+        } else {
+            // GL_CURRENT_VERTEX_ATTRIB is not preserved
+            if (buffer) {
+                testFailed("VERTEX_ATTRIB_ARRAY_BUFFER_BINDING not preserved");
+                anyMismatch = true;
+            }
+        }
+        
+        var elbuffer = gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING);
+        if (n % 2 == 0) {
+            if (elbuffer == state.elbuffer) {
+                // Matched
+            } else {
+                testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved");
+                anyMismatch = true;
+            }
+        } else {
+            if (elbuffer == null) {
+                // Matched
+            } else {
+                testFailed("ELEMENT_ARRAY_BUFFER_BINDING not preserved");
+                anyMismatch = true;
+            }
+        }
+    }
+    ext.bindVertexArrayOES(null);
+    if (!anyMismatch) {
+        testPassed("All attributes preserved across bindings");
+    }
+    
+    for (var n = 0; n < attrCount; n++) {
+        var state = states[n];
+        ext.deleteVertexArrayOES(state.vao);
+    }
+}
+
+function runAttributeValueTests() {
+    debug("Testing that attribute values are not attached to bindings");
+    
+    var v;
+    var vao0 = ext.createVertexArrayOES();
+    var anyFailed = false;
+    
+    ext.bindVertexArrayOES(null);
+    gl.vertexAttrib4f(0, 0, 1, 2, 3);
+    
+    v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
+    if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) {
+        testFailed("Vertex attrib value not round-tripped?");
+        anyFailed = true;
+    }
+    
+    ext.bindVertexArrayOES(vao0);
+    
+    v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
+    if (!(v[0] == 0 && v[1] == 1 && v[2] == 2 && v[3] == 3)) {
+        testFailed("Vertex attrib value reset across bindings");
+        anyFailed = true;
+    }
+    
+    gl.vertexAttrib4f(0, 4, 5, 6, 7);
+    ext.bindVertexArrayOES(null);
+    
+    v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
+    if (!(v[0] == 4 && v[1] == 5 && v[2] == 6 && v[3] == 7)) {
+        testFailed("Vertex attrib value bound to buffer");
+        anyFailed = true;
+    }
+    
+    if (!anyFailed) {
+        testPassed("Vertex attribute values are not attached to bindings")
+    }
+    
+    ext.bindVertexArrayOES(null);
+    ext.deleteVertexArrayOES(vao0);
+}
+
+function runDrawTests() {
+    debug("Testing draws with various VAO bindings");
+    
+    canvas.width = 50; canvas.height = 50;
+    gl.viewport(0, 0, canvas.width, canvas.height);
+    
+    var vao0 = ext.createVertexArrayOES();
+    var vao1 = ext.createVertexArrayOES();
+    
+    var program = wtu.setupSimpleTextureProgram(gl, 0, 1);
+    
+    function setupQuad(s) {
+        var opt_positionLocation = 0;
+        var opt_texcoordLocation = 1;
+        var vertexObject = gl.createBuffer();
+        gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
+        gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
+             1.0 * s,  1.0 * s, 0.0,
+            -1.0 * s,  1.0 * s, 0.0,
+            -1.0 * s, -1.0 * s, 0.0,
+             1.0 * s,  1.0 * s, 0.0,
+            -1.0 * s, -1.0 * s, 0.0,
+             1.0 * s, -1.0 * s, 0.0]), gl.STATIC_DRAW);
+        gl.enableVertexAttribArray(opt_positionLocation);
+        gl.vertexAttribPointer(opt_positionLocation, 3, gl.FLOAT, false, 0, 0);
+
+        var vertexObject = gl.createBuffer();
+        gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
+        gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
+            1.0 * s, 1.0 * s,
+            0.0 * s, 1.0 * s,
+            0.0 * s, 0.0 * s,
+            1.0 * s, 1.0 * s,
+            0.0 * s, 0.0 * s,
+            1.0 * s, 0.0 * s]), gl.STATIC_DRAW);
+        gl.enableVertexAttribArray(opt_texcoordLocation);
+        gl.vertexAttribPointer(opt_texcoordLocation, 2, gl.FLOAT, false, 0, 0);
+    };
+    
+    function readLocation(x, y) {
+        var pixels = new Uint8Array(1 * 1 * 4);
+        gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
+        return pixels;
+    };
+    function testPixel(blackList, whiteList) {
+        function testList(list, expected) {
+            for (var n = 0; n < list.length; n++) {
+                var l = list[n];
+                var x = -Math.floor(l * canvas.width / 2) + canvas.width / 2;
+                var y = -Math.floor(l * canvas.height / 2) + canvas.height / 2;
+                var source = readLocation(x, y);
+                if (Math.abs(source[0] - expected) > 2) {
+                    return false;
+                }
+            }
+            return true;
+        }
+        return testList(blackList, 0) && testList(whiteList, 255);
+    };
+    function verifyDraw(drawNumber, s) {
+        wtu.drawQuad(gl);
+        var blackList = [];
+        var whiteList = [];
+        var points = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0];
+        for (var n = 0; n < points.length; n++) {
+            if (points[n] <= s) {
+                blackList.push(points[n]);
+            } else {
+                whiteList.push(points[n]);
+            }
+        }
+        if (testPixel(blackList, whiteList)) {
+            testPassed("Draw " + drawNumber + " passed pixel test");
+        } else {
+            testFailed("Draw " + drawNumber + " failed pixel test");
+        }
+    };
+    
+    // Setup all bindings
+    setupQuad(1);
+    ext.bindVertexArrayOES(vao0);
+    setupQuad(0.5);
+    ext.bindVertexArrayOES(vao1);
+    setupQuad(0.25);
+    
+    // Verify drawing
+    ext.bindVertexArrayOES(null);
+    verifyDraw(0, 1);
+    ext.bindVertexArrayOES(vao0);
+    verifyDraw(1, 0.5);
+    ext.bindVertexArrayOES(vao1);
+    verifyDraw(2, 0.25);
+    
+    ext.bindVertexArrayOES(null);
+    ext.deleteVertexArrayOES(vao0);
+    ext.deleteVertexArrayOES(vao1);
+}
+
+function runDeleteTests() {
+    debug("Testing using deleted buffers referenced by VAOs");
+
+    var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_position", "a_color"]);
+    gl.useProgram(program);
+
+    var positionBuffer = gl.createBuffer();
+    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
+    gl.bufferData(
+        gl.ARRAY_BUFFER,
+        new Float32Array([
+           1.0,  1.0,
+          -1.0,  1.0,
+          -1.0, -1.0,
+           1.0, -1.0]),
+        gl.STATIC_DRAW);
+
+    var colors = [
+      [255,   0,   0, 255],
+      [  0, 255,   0, 255],
+      [  0,   0, 255, 255],
+      [  0, 255, 255, 255]
+    ];
+    var colorBuffers = [];
+    var elementBuffers = [];
+    var vaos = [];
+    for (var ii = 0; ii < colors.length; ++ii) {
+      var vao = ext.createVertexArrayOES();
+      vaos.push(vao);
+      ext.bindVertexArrayOES(vao);
+      // Set the position buffer
+      gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
+      gl.enableVertexAttribArray(0);
+      gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
+
+      var elementBuffer = gl.createBuffer();
+      elementBuffers.push(elementBuffer);
+      gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
+      gl.bufferData(
+          gl.ELEMENT_ARRAY_BUFFER,
+          new Uint8Array([0, 1, 2, 0, 2, 3]),
+          gl.STATIC_DRAW);
+
+      // Setup the color attrib
+      var color = colors[ii];
+      if (ii < 3) {
+        var colorBuffer = gl.createBuffer();
+        colorBuffers.push(colorBuffer);
+        gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
+        gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(
+          [ color[0], color[1], color[2], color[3],
+            color[0], color[1], color[2], color[3],
+            color[0], color[1], color[2], color[3],
+            color[0], color[1], color[2], color[3]
+          ]), gl.STATIC_DRAW);
+        gl.enableVertexAttribArray(1);
+        gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, 0);
+      } else {
+        gl.vertexAttrib4f(1, color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255);
+      }
+    }
+
+    // delete the color buffers AND the position buffer.
+    ext.bindVertexArrayOES(null);
+    for (var ii = 0; ii < colorBuffers.length; ++ii) {
+      gl.deleteBuffer(colorBuffers[ii]);
+      gl.deleteBuffer(elementBuffers[ii]);
+      // The buffers should still be valid at this point, since it was attached to the VAO
+      if(!gl.isBuffer(colorBuffers[ii])) {
+        testFailed("buffer removed too early");
+      }
+    }
+    gl.deleteBuffer(positionBuffer);
+
+    // Render with the deleted buffers. As they are referenced by VAOs they
+    // must still be around.
+    for (var ii = 0; ii < colors.length; ++ii) {
+      var color = colors[ii];
+      ext.bindVertexArrayOES(vaos[ii]);
+      gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);
+      wtu.checkCanvas(gl, color, "should be " + color);
+    }
+
+    // Clean up.
+    for (var ii = 0; ii < colorBuffers.length; ++ii) {
+      ext.deleteVertexArrayOES(vaos[ii]);
+    }
+
+    for (var ii = 0; ii < colorBuffers.length; ++ii) {
+      // The buffers should no longer be valid now that the VAOs are deleted
+      if(gl.isBuffer(colorBuffers[ii])) {
+        testFailed("buffer not properly cleaned up after VAO deletion");
+      }
+    }
+}
+
+function runArrayBufferBindTests() {
+    debug("Testing that VAOs don't effect ARRAY_BUFFER binding.");
+
+    ext.bindVertexArrayOES(null);
+
+    var program = wtu.setupProgram(gl, ["vshader", "fshader"], ["a_color", "a_position"]);
+    gl.useProgram(program);
+
+    // create shared element buuffer
+    var elementBuffer = gl.createBuffer();
+    // bind to default
+    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
+    gl.bufferData(
+        gl.ELEMENT_ARRAY_BUFFER,
+        new Uint8Array([0, 1, 2, 0, 2, 3]),
+        gl.STATIC_DRAW);
+
+    // first create the buffers for no vao draw.
+    var nonVAOColorBuffer = gl.createBuffer();
+    gl.bindBuffer(gl.ARRAY_BUFFER, nonVAOColorBuffer);
+    gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(
+      [ 0, 255, 0, 255,
+        0, 255, 0, 255,
+        0, 255, 0, 255,
+        0, 255, 0, 255,
+      ]), gl.STATIC_DRAW);
+
+    // shared position buffer.
+    var positionBuffer = gl.createBuffer();
+    gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
+    gl.bufferData(
+        gl.ARRAY_BUFFER,
+        new Float32Array([
+           1.0,  1.0,
+          -1.0,  1.0,
+          -1.0, -1.0,
+           1.0, -1.0]),
+        gl.STATIC_DRAW);
+
+    // attach position buffer to default
+    gl.enableVertexAttribArray(1);
+    gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
+
+    // now create vao
+    var vao = ext.createVertexArrayOES();
+    ext.bindVertexArrayOES(vao);
+
+    // attach the position buffer vao
+    gl.enableVertexAttribArray(1);
+    gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
+
+    var vaoColorBuffer = gl.createBuffer();
+    gl.enableVertexAttribArray(0);
+    gl.vertexAttribPointer(0, 4, gl.UNSIGNED_BYTE, true, 0, 0);
+    gl.bindBuffer(gl.ARRAY_BUFFER, vaoColorBuffer);
+    gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(
+      [ 255, 0, 0, 255,
+        255, 0, 0, 255,
+        255, 0, 0, 255,
+        255, 0, 0, 255,
+      ]), gl.STATIC_DRAW);
+    gl.enableVertexAttribArray(0);
+    gl.vertexAttribPointer(0, 4, gl.UNSIGNED_BYTE, true, 0, 0);
+
+    // now set the buffer back to the nonVAOColorBuffer
+    gl.bindBuffer(gl.ARRAY_BUFFER, nonVAOColorBuffer);
+
+    // bind to vao
+    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementBuffer);
+    gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);
+    wtu.checkCanvas(gl, [255, 0, 0, 255], "should be red");
+
+    // unbind vao
+    ext.bindVertexArrayOES(null);
+
+    // At this point the nonVAOColorBuffer should be still be bound.
+    // If the WebGL impl is emulating VAOs it must make sure
+    // it correctly restores this binding.
+    gl.enableVertexAttribArray(0);
+    gl.vertexAttribPointer(0, 4, gl.UNSIGNED_BYTE, true, 0, 0);
+    gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);
+    wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green");
+}
+
+debug("");
+successfullyParsed = true;
+</script>
+<script src="../../resources/js-test-post.js"></script>
+
+</body>
+</html>
index 74b4325..789eb5f 100644 (file)
@@ -3565,3 +3565,6 @@ webkit.org/b/97179 http/tests/css/link-css-disabled-value-with-slow-loading-shee
 # The test should pass after harfbuzz transition.
 webkit.org/b/97296 [ Linux Win ] fast/text/international/hebrew-selection.html [ ImageOnlyFailure ]
 
+# Expected to fail until WebGL extension implementation lands
+webkit.org/b/96961 fast/canvas/webgl/oes-vertex-array-object.html [ Failure Pass ]
+webkit.org/b/96961 platform/chromium/virtual/gpu/fast/canvas/webgl/oes-vertex-array-object.html [ Failure Pass ]
\ No newline at end of file
index 20c9aca..b2fbfe2 100644 (file)
@@ -670,3 +670,6 @@ inspector/extensions/extensions-eval-content-script.html
 
 # ENABLE(WIDGET_REGION) is disabled
 fast/css/widget-region-parser.html
+
+# http://webkit.org/b/96828
+fast/canvas/webgl/oes-vertex-array-object.html
index b04c972..8fbbb63 100644 (file)
@@ -943,6 +943,9 @@ fast/canvas/webgl/tex-image-and-sub-image-2d-with-video.html
 # Sending the mouse down event to the scrollbar starts a nested run loop which causes a hang.
 fast/events/mousedown-in-subframe-scrollbar.html
 
+# http://webkit.org/b/96828
+fast/canvas/webgl/oes-vertex-array-object.html
+
 # --- WebKit1 only ---
 http/tests/misc/willCacheResponse-delegate-callback.html
 http/tests/multipart/load-last-non-html-frame.php
index 4f64d79..6a7a052 100644 (file)
@@ -199,6 +199,7 @@ fast/canvas/webgl/uniform-location.html
 fast/canvas/webgl/viewport-unchanged-upon-resize.html
 fast/canvas/webgl/webgl-array-invalid-ranges.html
 fast/canvas/webgl/webgl-specific.html
+fast/canvas/webgl/oes-vertex-array-object.html
 fast/harness/override-preferences-2.html
 fast/images/animated-gif-restored-from-bfcache.html
 fast/text/zero-font-size.html
index d85e905..a20603e 100644 (file)
@@ -1,3 +1,20 @@
+2012-09-21  Brandon Jones  <bajones@google.com>
+
+        Add support for OES_vertex_array_object in chromium
+        https://bugs.webkit.org/show_bug.cgi?id=96578
+
+        Reviewed by Kenneth Russell.
+
+        Added code to allow calls to the OES_vertex_array_object extension to interface
+        properly with the chromium WebGL implementation. 
+
+        * chromium/public/WebGraphicsContext3D.h:
+        (WebGraphicsContext3D):
+        (WebKit::WebGraphicsContext3D::createVertexArrayOES):
+        (WebKit::WebGraphicsContext3D::deleteVertexArrayOES):
+        (WebKit::WebGraphicsContext3D::isVertexArrayOES):
+        (WebKit::WebGraphicsContext3D::bindVertexArrayOES):
+
 2012-09-21  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Add setters to WebFilterOperation for IPC pickling
index 312d4fa..82d3d36 100644 (file)
@@ -443,6 +443,12 @@ public:
     virtual void pushGroupMarkerEXT(const WGC3Dchar* marker) { }
     virtual void popGroupMarkerEXT(void) { }
 
+    // GL_OES_vertex_array_object
+    virtual WebGLId createVertexArrayOES() { return 0; }
+    virtual void deleteVertexArrayOES(WebGLId array) { }
+    virtual WGC3Dboolean isVertexArrayOES(WebGLId array) { return false; }
+    virtual void bindVertexArrayOES(WebGLId array) { }
+
     GrGLInterface* createGrGLInterface();
 
 protected:
index e9ccf54..125ba8b 100644 (file)
@@ -1,3 +1,33 @@
+2012-09-21  Brandon Jones  <bajones@google.com>
+
+        Add support for OES_vertex_array_object in chromium
+        https://bugs.webkit.org/show_bug.cgi?id=96578
+
+        Reviewed by Kenneth Russell.
+
+        Adding basic reference counting to WebGLBuffer objects to satisfy spec requirements
+        for the OES_vertex_array_object extension. Added code to allow calls to the
+        OES_vertex_array_object extension to interface properly with the chromium WebGL
+        implementation.
+
+        Test: fast/canvas/webgl/oes-vertex-array-object.html
+
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore):
+        (WebCore::WebGLRenderingContext::deleteBuffer):
+        (WebCore::WebGLRenderingContext::vertexAttribPointer):
+        * html/canvas/WebGLVertexArrayObjectOES.cpp:
+        (WebCore::WebGLVertexArrayObjectOES::setElementArrayBuffer):
+        (WebCore):
+        * html/canvas/WebGLVertexArrayObjectOES.h:
+        (WebGLVertexArrayObjectOES):
+        (WebCore::WebGLVertexArrayObjectOES::getVertexAttribStateSize):
+        * platform/chromium/support/Extensions3DChromium.cpp:
+        (WebCore::Extensions3DChromium::createVertexArrayOES):
+        (WebCore::Extensions3DChromium::deleteVertexArrayOES):
+        (WebCore::Extensions3DChromium::isVertexArrayOES):
+        (WebCore::Extensions3DChromium::bindVertexArrayOES):
+
 2012-09-21  Kenichi Ishibashi  <bashi@chromium.org>
 
         [Chromium] Use OpenTypeVerticalData on Linux
index 24b9c33..582ed5d 100644 (file)
@@ -1544,22 +1544,8 @@ void WebGLRenderingContext::deleteBuffer(WebGLBuffer* buffer)
         return;
     if (m_boundArrayBuffer == buffer)
         m_boundArrayBuffer = 0;
-    RefPtr<WebGLBuffer> elementArrayBuffer = m_boundVertexArrayObject->getElementArrayBuffer();
-    if (elementArrayBuffer == buffer)
-        m_boundVertexArrayObject->setElementArrayBuffer(0);
-    if (!isGLES2Compliant()) {
-        WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(0);
-        if (buffer == state.bufferBinding) {
-            state.bufferBinding = m_vertexAttrib0Buffer;
-            state.bytesPerElement = 0;
-            state.size = 4;
-            state.type = GraphicsContext3D::FLOAT;
-            state.normalized = false;
-            state.stride = 16;
-            state.originalStride = 0;
-            state.offset = 0;
-        }
-    }
+
+    m_boundVertexArrayObject->unbindBuffer(buffer);
 }
 
 void WebGLRenderingContext::deleteFramebuffer(WebGLFramebuffer* framebuffer)
@@ -4383,17 +4369,7 @@ void WebGLRenderingContext::vertexAttribPointer(GC3Duint index, GC3Dint size, GC
     }
     GC3Dsizei bytesPerElement = size * typeSize;
 
-    GC3Dsizei validatedStride = stride ? stride : bytesPerElement;
-
-    WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(index);
-    state.bufferBinding = m_boundArrayBuffer;
-    state.bytesPerElement = bytesPerElement;
-    state.size = size;
-    state.type = type;
-    state.normalized = normalized;
-    state.stride = validatedStride;
-    state.originalStride = stride;
-    state.offset = static_cast<GC3Dintptr>(offset);
+    m_boundVertexArrayObject->setVertexAttribState(index, bytesPerElement, size, type, normalized, stride, static_cast<GC3Dintptr>(offset), m_boundArrayBuffer);
     m_context->vertexAttribPointer(index, size, type, normalized, stride, static_cast<GC3Dintptr>(offset));
     cleanupAfterGraphicsCall(false);
 }
index 6023b44..45df6a5 100644 (file)
@@ -322,6 +322,7 @@ public:
     friend class WebGLDebugShaders;
     friend class WebGLCompressedTextureS3TC;
     friend class WebGLRenderingContextErrorMessageCallback;
+    friend class WebGLVertexArrayObjectOES;
 
     WebGLRenderingContext(HTMLCanvasElement*, PassRefPtr<GraphicsContext3D>, GraphicsContext3D::Attributes);
     void initializeNewContext();
index 4aa03b8..a98d092 100644 (file)
@@ -72,6 +72,75 @@ void WebGLVertexArrayObjectOES::deleteObjectImpl(GraphicsContext3D* context3d, P
         extensions->deleteVertexArrayOES(object);
         break;
     }
+
+    if (m_boundElementArrayBuffer)
+        m_boundElementArrayBuffer->onDetached(context3d);
+
+    for (size_t i = 0; i < m_vertexAttribState.size(); ++i) {
+        VertexAttribState& state = m_vertexAttribState[i];
+        if (state.bufferBinding)
+            state.bufferBinding->onDetached(context3d);
+    }
+}
+
+void WebGLVertexArrayObjectOES::setElementArrayBuffer(PassRefPtr<WebGLBuffer> buffer)
+{
+    if (buffer)
+        buffer->onAttached();
+    if (m_boundElementArrayBuffer)
+        m_boundElementArrayBuffer->onDetached(context()->graphicsContext3D());
+    m_boundElementArrayBuffer = buffer;
+    
+}
+
+void WebGLVertexArrayObjectOES::setVertexAttribState(
+    GC3Duint index, GC3Dsizei bytesPerElement, GC3Dint size, GC3Denum type, GC3Dboolean normalized, GC3Dsizei stride, GC3Dintptr offset, PassRefPtr<WebGLBuffer> buffer)
+{
+    GC3Dsizei validatedStride = stride ? stride : bytesPerElement;
+
+    VertexAttribState& state = m_vertexAttribState[index];
+
+    if (buffer)
+        buffer->onAttached();
+    if (state.bufferBinding)
+        state.bufferBinding->onDetached(context()->graphicsContext3D());
+
+    state.bufferBinding = buffer;
+    state.bytesPerElement = bytesPerElement;
+    state.size = size;
+    state.type = type;
+    state.normalized = normalized;
+    state.stride = validatedStride;
+    state.originalStride = stride;
+    state.offset = offset;
+}
+
+void WebGLVertexArrayObjectOES::unbindBuffer(PassRefPtr<WebGLBuffer> buffer)
+{
+    if (m_boundElementArrayBuffer == buffer) {
+        m_boundElementArrayBuffer->onDetached(context()->graphicsContext3D());
+        m_boundElementArrayBuffer = 0;
+    }
+
+    for (size_t i = 0; i < m_vertexAttribState.size(); ++i) {
+        VertexAttribState& state = m_vertexAttribState[i];
+        if (state.bufferBinding == buffer) {
+            buffer->onDetached(context()->graphicsContext3D());
+
+            if (!i && !context()->isGLES2Compliant()) {
+                state.bufferBinding = context()->m_vertexAttrib0Buffer;
+                state.bufferBinding->onAttached();
+                state.bytesPerElement = 0;
+                state.size = 4;
+                state.type = GraphicsContext3D::FLOAT;
+                state.normalized = false;
+                state.stride = 16;
+                state.originalStride = 0;
+                state.offset = 0;
+            } else
+                state.bufferBinding = 0;
+        }
+    }
 }
 
 }
index 75ae42f..b660de5 100644 (file)
@@ -76,9 +76,11 @@ public:
     void setHasEverBeenBound() { m_hasEverBeenBound = true; }
     
     PassRefPtr<WebGLBuffer> getElementArrayBuffer() const { return m_boundElementArrayBuffer; }
-    void setElementArrayBuffer(PassRefPtr<WebGLBuffer> buffer) { m_boundElementArrayBuffer = buffer; }
+    void setElementArrayBuffer(PassRefPtr<WebGLBuffer>);
     
     VertexAttribState& getVertexAttribState(int index) { return m_vertexAttribState[index]; }
+    void setVertexAttribState(GC3Duint, GC3Dsizei, GC3Dint, GC3Denum, GC3Dboolean, GC3Dsizei, GC3Dintptr, PassRefPtr<WebGLBuffer>);
+    void unbindBuffer(PassRefPtr<WebGLBuffer>);
 
 private:
     WebGLVertexArrayObjectOES(WebGLRenderingContext*, VaoType);
index 9412274..17c3021 100644 (file)
@@ -97,20 +97,22 @@ void Extensions3DChromium::unmapTexSubImage2DCHROMIUM(const void* data)
 
 Platform3DObject Extensions3DChromium::createVertexArrayOES()
 {
-    return 0;
+    return m_private->webContext()->createVertexArrayOES();
 }
 
-void Extensions3DChromium::deleteVertexArrayOES(Platform3DObject)
+void Extensions3DChromium::deleteVertexArrayOES(Platform3DObject array)
 {
+    m_private->webContext()->deleteVertexArrayOES(array);
 }
 
-GC3Dboolean Extensions3DChromium::isVertexArrayOES(Platform3DObject)
+GC3Dboolean Extensions3DChromium::isVertexArrayOES(Platform3DObject array)
 {
-    return 0;
+    return m_private->webContext()->isVertexArrayOES(array);
 }
 
-void Extensions3DChromium::bindVertexArrayOES(Platform3DObject)
+void Extensions3DChromium::bindVertexArrayOES(Platform3DObject array)
 {
+    m_private->webContext()->bindVertexArrayOES(array);
 }
 
 String Extensions3DChromium::getTranslatedShaderSourceANGLE(Platform3DObject shader)