Changeset 162565 in webkit


Ignore:
Timestamp:
Jan 22, 2014 3:47:24 PM (10 years ago)
Author:
dino@apple.com
Message:

Source/WebCore: [WebGL] Implement ANGLE_instanced_arrays
https://bugs.webkit.org/show_bug.cgi?id=127257

Reviewed by Brent Fulgham.

Implement the instanced drawing WebGL extension,
ANGLE_instanced_arrays. This is currently Mac-only,
but should be portable to other platforms if their
OpenGL exposes the functions. It's also done in a way
that will make exposing it to WebGL2 simple.

Test: fast/canvas/webgl/angle-instanced-arrays.html

  • CMakeLists.txt:
  • DerivedSources.cpp:
  • DerivedSources.make:
  • GNUmakefile.list.am:
  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.vcxproj/WebCore.vcxproj.filters:
  • WebCore.xcodeproj/project.pbxproj:

Add the new files to all the build systems.

  • bindings/js/JSWebGLRenderingContextCustom.cpp:

(WebCore::toJS): Link JS side to C++ side.

  • html/canvas/ANGLEInstancedArrays.cpp: Added.

(WebCore::ANGLEInstancedArrays::ANGLEInstancedArrays):

  • html/canvas/ANGLEInstancedArrays.h: Added.
  • html/canvas/ANGLEInstancedArrays.idl: Added.

New boilerplate files that expose the extension methods.

  • html/canvas/WebGLExtension.h: New extension enum.
  • html/canvas/WebGLRenderingContext.cpp:

(WebCore::WebGLRenderingContext::validateVertexAttributes): Add an optional
parameter representing the number of instance primitives we are asked
to draw. Use that for the draw count if looking at an instanced attribute.
Also make sure we see at least one non-instanced attribute.
(WebCore::WebGLRenderingContext::validateDrawArrays): Update this so it could
be used from either drawArrays or drawArraysInstanced.
(WebCore::WebGLRenderingContext::drawArrays):
(WebCore::WebGLRenderingContext::validateDrawElements): Same here, now can be
used by the instanced and non-instanced versions.
(WebCore::WebGLRenderingContext::drawElements):
(WebCore::WebGLRenderingContext::getExtension): Create and return the new extension.
(WebCore::WebGLRenderingContext::getSupportedExtensions): Add new extension to the list.
(WebCore::WebGLRenderingContext::getVertexAttrib): Intercept a query to the divisor
attribute and return the value we kept in the state.
(WebCore::WebGLRenderingContext::drawArraysInstanced): Call the GC3D method.
(WebCore::WebGLRenderingContext::drawElementsInstanced): Ditto.
(WebCore::WebGLRenderingContext::vertexAttribDivisor): Ditto.

  • html/canvas/WebGLRenderingContext.h: Define the new methods and parameters.
  • html/canvas/WebGLVertexArrayObjectOES.cpp:

(WebCore::WebGLVertexArrayObjectOES::setVertexAttribDivisor): Keep a record of the
divisor if we set it.

  • html/canvas/WebGLVertexArrayObjectOES.h:

(WebCore::WebGLVertexArrayObjectOES::VertexAttribState::VertexAttribState):

  • platform/graphics/GraphicsContext3D.h: New enum.
  • platform/graphics/mac/GraphicsContext3DMac.mm:

(WebCore::GraphicsContext3D::drawArraysInstanced): The actual calls into OpenGL.
(WebCore::GraphicsContext3D::drawElementsInstanced): Ditto.
(WebCore::GraphicsContext3D::vertexAttribDivisor): Ditto.

  • platform/graphics/opengl/GraphicsContext3DOpenGL.cpp: Empty implementations

for non-mac platforms.

  • platform/graphics/ios/GraphicsContext3DIOS.h: Define the iOS names for the

functions.

LayoutTests: Implement ANGLE_instanced_arrays
https://bugs.webkit.org/show_bug.cgi?id=127257

Reviewed by Brent Fulgham.

Copied a slightly modified version of the Khronos instanced
arrays test (mostly modified due to the fact this comes from
an in-progress update to the test suite).

  • fast/canvas/webgl/angle-instanced-arrays-expected.txt: Added.
  • fast/canvas/webgl/angle-instanced-arrays.html: Added.
  • fast/canvas/webgl/resources/webgl-test-utils.js:

(WebGLTestUtils): Added some new functions that were missing, and
some output to a checkColor test.

  • platform/efl/TestExpectations: Skip this for EFL.
  • platform/mac-mountainlion/fast/canvas/webgl/angle-instanced-arrays-expected.txt: Not

supported on Mountain Lion.

Location:
trunk
Files:
8 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r162563 r162565  
     12014-01-22  Dean Jackson  <dino@apple.com>
     2
     3        Implement ANGLE_instanced_arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=127257
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Copied a slightly modified version of the Khronos instanced
     9        arrays test (mostly modified due to the fact this comes from
     10        an in-progress update to the test suite).
     11
     12        * fast/canvas/webgl/angle-instanced-arrays-expected.txt: Added.
     13        * fast/canvas/webgl/angle-instanced-arrays.html: Added.
     14        * fast/canvas/webgl/resources/webgl-test-utils.js:
     15        (WebGLTestUtils): Added some new functions that were missing, and
     16        some output to a checkColor test.
     17        * platform/efl/TestExpectations: Skip this for EFL.
     18        * platform/mac-mountainlion/fast/canvas/webgl/angle-instanced-arrays-expected.txt: Not
     19        supported on Mountain Lion.
     20
    1212014-01-22  Zalan Bujtas  <zalan@apple.com>
    222
  • trunk/LayoutTests/fast/canvas/webgl/resources/webgl-test-utils.js

    r161996 r162565  
    362362
    363363/**
     364 * Creates a unit quad with only positions of a given resolution.
     365 * @param {!WebGLRenderingContext} gl The WebGLRenderingContext to use.
     366 * @param {number} gridRes The resolution of the mesh grid,
     367 *     expressed in the number of quads across and down.
     368 * @param {number} opt_positionLocation The attrib location for position.
     369 */
     370var setupIndexedQuad = function (
     371    gl, gridRes, opt_positionLocation, opt_flipOddTriangles) {
     372  return setupIndexedQuadWithOptions(gl,
     373    { gridRes: gridRes,
     374      positionLocation: opt_positionLocation,
     375      flipOddTriangles: opt_flipOddTriangles
     376    });
     377};
     378
     379/**
     380 * Creates a quad with various options.
     381 * @param {!WebGLRenderingContext} gl The WebGLRenderingContext to use.
     382 * @param {!Object) options The options. See below.
     383 * @return {!Array.<WebGLBuffer>} The created buffers.
     384 *     [positions, <colors>, indices]
     385 *
     386 * Options:
     387 *   gridRes: number of quads across and down grid.
     388 *   positionLocation: attrib location for position
     389 *   flipOddTriangles: reverse order of vertices of every other
     390 *       triangle
     391 *   positionOffset: offset added to each vertex
     392 *   positionMult: multipier for each vertex
     393 *   colorLocation: attrib location for vertex colors. If
     394 *      undefined no vertex colors will be created.
     395 */
     396var setupIndexedQuadWithOptions = function (gl, options) {
     397  var positionLocation = options.positionLocation || 0;
     398  var objects = [];
     399
     400  var gridRes = options.gridRes || 1;
     401  var positionOffset = options.positionOffset || 0;
     402  var positionMult = options.positionMult || 1;
     403  var vertsAcross = gridRes + 1;
     404  var numVerts = vertsAcross * vertsAcross;
     405  var positions = new Float32Array(numVerts * 3);
     406  var indices = new Uint16Array(6 * gridRes * gridRes);
     407  var poffset = 0;
     408
     409  for (var yy = 0; yy <= gridRes; ++yy) {
     410    for (var xx = 0; xx <= gridRes; ++xx) {
     411      positions[poffset + 0] = (-1 + 2 * xx / gridRes) * positionMult + positionOffset;
     412      positions[poffset + 1] = (-1 + 2 * yy / gridRes) * positionMult + positionOffset;
     413      positions[poffset + 2] = 0;
     414
     415      poffset += 3;
     416    }
     417  }
     418
     419  var buf = gl.createBuffer();
     420  gl.bindBuffer(gl.ARRAY_BUFFER, buf);
     421  gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
     422  gl.enableVertexAttribArray(positionLocation);
     423  gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
     424  objects.push(buf);
     425
     426  if (options.colorLocation !== undefined) {
     427    var colors = new Float32Array(numVerts * 4);
     428    for (var yy = 0; yy <= gridRes; ++yy) {
     429      for (var xx = 0; xx <= gridRes; ++xx) {
     430        if (options.color !== undefined) {
     431          colors[poffset + 0] = options.color[0];
     432          colors[poffset + 1] = options.color[1];
     433          colors[poffset + 2] = options.color[2];
     434          colors[poffset + 3] = options.color[3];
     435        } else {
     436          colors[poffset + 0] = xx / gridRes;
     437          colors[poffset + 1] = yy / gridRes;
     438          colors[poffset + 2] = (xx / gridRes) * (yy / gridRes);
     439          colors[poffset + 3] = (yy % 2) * 0.5 + 0.5;
     440        }
     441        poffset += 4;
     442      }
     443    }
     444
     445    var buf = gl.createBuffer();
     446    gl.bindBuffer(gl.ARRAY_BUFFER, buf);
     447    gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
     448    gl.enableVertexAttribArray(options.colorLocation);
     449    gl.vertexAttribPointer(options.colorLocation, 4, gl.FLOAT, false, 0, 0);
     450    objects.push(buf);
     451  }
     452
     453  var tbase = 0;
     454  for (var yy = 0; yy < gridRes; ++yy) {
     455    var index = yy * vertsAcross;
     456    for (var xx = 0; xx < gridRes; ++xx) {
     457      indices[tbase + 0] = index + 0;
     458      indices[tbase + 1] = index + 1;
     459      indices[tbase + 2] = index + vertsAcross;
     460      indices[tbase + 3] = index + vertsAcross;
     461      indices[tbase + 4] = index + 1;
     462      indices[tbase + 5] = index + vertsAcross + 1;
     463
     464      if (options.flipOddTriangles) {
     465        indices[tbase + 4] = index + vertsAcross + 1;
     466        indices[tbase + 5] = index + 1;
     467      }
     468
     469      index += 1;
     470      tbase += 6;
     471    }
     472  }
     473
     474  var buf = gl.createBuffer();
     475  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buf);
     476  gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
     477  objects.push(buf);
     478
     479  return objects;
     480};
     481
     482/**
    364483 * Fills the given texture with a solid color
    365484 * @param {!WebGLContext} gl The WebGLContext to use.
     
    473592  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    474593  gl.drawElements(gl.TRIANGLES, gridRes * 6, gl.UNSIGNED_SHORT, 0);
     594};
     595
     596/**
     597 * Draws a previously setupIndexedQuad
     598 * @param {!WebGLRenderingContext} gl The WebGLRenderingContext to use.
     599 * @param {number} gridRes Resolution of grid.
     600 * @param {!Array.<number>} opt_color The color to fill clear with before
     601 *        drawing. A 4 element array where each element is in the range 0 to
     602 *        255. Default [255, 255, 255, 255]
     603 */
     604var clearAndDrawIndexedQuad = function(gl, gridRes, opt_color) {
     605  opt_color = opt_color || [255, 255, 255, 255];
     606  gl.clearColor(
     607      opt_color[0] / 255,
     608      opt_color[1] / 255,
     609      opt_color[2] / 255,
     610      opt_color[3] / 255);
     611  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
     612  drawIndexedQuad(gl, gridRes);
     613};
     614
     615/**
     616 * Clips a range to min, max
     617 * (Eg. clipToRange(-5,7,0,20) would return {value:0,extent:2}
     618 * @param {number} value start of range
     619 * @param {number} extent extent of range
     620 * @param {number} min min.
     621 * @param {number} max max.
     622 * @return {!{value:number,extent:number} The clipped value.
     623 */
     624var clipToRange = function(value, extent, min, max) {
     625  if (value < min) {
     626    extent -= min - value;
     627    value = min;
     628  }
     629  var end = value + extent;
     630  if (end > max) {
     631    extent -= end - max;
     632  }
     633  if (extent < 0) {
     634    value = max;
     635    extent = 0;
     636  }
     637  return {value:value, extent: extent};
     638};
     639
     640/**
     641 * Determines if the passed context is an instance of a WebGLRenderingContext
     642 * or later variant (like WebGL2RenderingContext)
     643 * @param {CanvasRenderingContext} ctx The context to check.
     644 */
     645var isWebGLContext = function(ctx) {
     646  if (ctx instanceof WebGLRenderingContext)
     647    return true;
     648
     649  if ('WebGL2RenderingContext' in window && ctx instanceof WebGL2RenderingContext)
     650    return true;
     651
     652  return false;
     653};
     654
     655/**
     656 * Checks that a portion of a canvas is 1 color.
     657 * @param {!WebGLRenderingContext|CanvasRenderingContext2D} gl The
     658 *         WebGLRenderingContext or 2D context to use.
     659 * @param {number} x left corner of region to check.
     660 * @param {number} y bottom corner of region to check in case of checking from
     661 *        a GL context or top corner in case of checking from a 2D context.
     662 * @param {number} width width of region to check.
     663 * @param {number} height width of region to check.
     664 * @param {!Array.<number>} color The color expected. A 4 element array where
     665 *        each element is in the range 0 to 255.
     666 * @param {number} opt_errorRange Optional. Acceptable error in
     667 *        color checking. 0 by default.
     668 * @param {!function()} sameFn Function to call if all pixels
     669 *        are the same as color.
     670 * @param {!function()} differentFn Function to call if a pixel
     671 *        is different than color
     672 * @param {!function()} logFn Function to call for logging.
     673 */
     674var checkCanvasRectColor = function(gl, x, y, width, height, color, opt_errorRange, sameFn, differentFn, logFn) {
     675  if (isWebGLContext(gl) && !gl.getParameter(gl.FRAMEBUFFER_BINDING)) {
     676    // We're reading the backbuffer so clip.
     677    var xr = clipToRange(x, width, 0, gl.canvas.width);
     678    var yr = clipToRange(y, height, 0, gl.canvas.height);
     679    if (!xr.extent || !yr.extent) {
     680      logFn("checking rect: effective width or heigh is zero");
     681      sameFn();
     682      return;
     683    }
     684    x = xr.value;
     685    y = yr.value;
     686    width = xr.extent;
     687    height = yr.extent;
     688  }
     689  var errorRange = opt_errorRange || 0;
     690  if (!errorRange.length) {
     691    errorRange = [errorRange, errorRange, errorRange, errorRange]
     692  }
     693  var buf;
     694  if (isWebGLContext(gl)) {
     695    buf = new Uint8Array(width * height * 4);
     696    gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
     697  } else {
     698    buf = gl.getImageData(x, y, width, height).data;
     699  }
     700  for (var i = 0; i < width * height; ++i) {
     701    var offset = i * 4;
     702    for (var j = 0; j < color.length; ++j) {
     703      if (Math.abs(buf[offset + j] - color[j]) > errorRange[j]) {
     704        differentFn();
     705        var was = buf[offset + 0].toString();
     706        for (j = 1; j < color.length; ++j) {
     707          was += "," + buf[offset + j];
     708        }
     709        logFn('at (' + (x + (i % width)) + ', ' + (y + Math.floor(i / width)) +
     710              ') expected: ' + color + ' was ' + was);
     711        return;
     712      }
     713    }
     714  }
     715  sameFn();
    475716};
    476717
     
    506747      }
    507748    }
     749  }
     750  if (!msg) {
     751      msg = "Color was " + color;
    508752  }
    509753  testPassed(msg);
     
    13321576return {
    13331577  cancelAnimFrame: cancelAnimFrame,
     1578  clipToRange: clipToRange,
    13341579  create3DContext: create3DContext,
    13351580  create3DContextWithWrapperThatThrowsOnGLError:
    1336     create3DContextWithWrapperThatThrowsOnGLError,
     1581  create3DContextWithWrapperThatThrowsOnGLError,
    13371582  checkCanvas: checkCanvas,
    13381583  checkCanvasRect: checkCanvasRect,
     1584  checkCanvasRectColor: checkCanvasRectColor,
    13391585  createColoredTexture: createColoredTexture,
    13401586  drawQuad: drawQuad,
     
    13701616  setupProgram: setupProgram,
    13711617  setupQuad: setupQuad,
     1618  setupIndexedQuad: setupIndexedQuad,
     1619  setupIndexedQuadWithOptions: setupIndexedQuadWithOptions,
    13721620  setupSimpleTextureFragmentShader: setupSimpleTextureFragmentShader,
    13731621  setupSimpleTextureProgram: setupSimpleTextureProgram,
  • trunk/LayoutTests/platform/efl/TestExpectations

    r162532 r162565  
    16821682webgl/conformance/textures/texture-attachment-formats.html [ Failure ]
    16831683
     1684# ANGLE_instanced_arrays not implemented on efl
     1685fast/canvas/webgl/angle-instanced-arrays.html [ Skip ]
     1686
    16841687# Text rendering is overflowing region
    16851688webkit.org/b/122511 fast/regions/selection/selecting-text-ignoring-region-horiz-bt.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/CMakeLists.txt

    r162427 r162565  
    497497    html/VoidCallback.idl
    498498
     499    html/canvas/ANGLEInstancedArrays.idl
    499500    html/canvas/CanvasGradient.idl
    500501    html/canvas/CanvasPattern.idl
     
    14931494    html/WeekInputType.cpp
    14941495
     1496    html/canvas/ANGLEInstancedArrays.cpp
    14951497    html/canvas/CanvasContextAttributes.cpp
    14961498    html/canvas/CanvasGradient.cpp
     
    26652667
    26662668    list(APPEND WebCore_SOURCES
     2669        html/canvas/ANGLEInstancedArrays.cpp
    26672670        html/canvas/EXTDrawBuffers.cpp
    26682671        html/canvas/EXTTextureFilterAnisotropic.cpp
     
    27012704    )
    27022705    list(APPEND WebCore_IDL_FILES
     2706        html/canvas/ANGLEInstancedArrays.idl
    27032707        html/canvas/EXTDrawBuffers.idl
    27042708        html/canvas/EXTTextureFilterAnisotropic.idl
  • trunk/Source/WebCore/ChangeLog

    r162559 r162565  
     12014-01-22  Dean Jackson  <dino@apple.com>
     2
     3        [WebGL] Implement ANGLE_instanced_arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=127257
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Implement the instanced drawing WebGL extension,
     9        ANGLE_instanced_arrays. This is currently Mac-only,
     10        but should be portable to other platforms if their
     11        OpenGL exposes the functions. It's also done in a way
     12        that will make exposing it to WebGL2 simple.
     13
     14        Test: fast/canvas/webgl/angle-instanced-arrays.html
     15
     16        * CMakeLists.txt:
     17        * DerivedSources.cpp:
     18        * DerivedSources.make:
     19        * GNUmakefile.list.am:
     20        * WebCore.vcxproj/WebCore.vcxproj:
     21        * WebCore.vcxproj/WebCore.vcxproj.filters:
     22        * WebCore.xcodeproj/project.pbxproj:
     23        Add the new files to all the build systems.
     24
     25        * bindings/js/JSWebGLRenderingContextCustom.cpp:
     26        (WebCore::toJS): Link JS side to C++ side.
     27
     28        * html/canvas/ANGLEInstancedArrays.cpp: Added.
     29        (WebCore::ANGLEInstancedArrays::ANGLEInstancedArrays):
     30        * html/canvas/ANGLEInstancedArrays.h: Added.
     31        * html/canvas/ANGLEInstancedArrays.idl: Added.
     32        New boilerplate files that expose the extension methods.
     33
     34        * html/canvas/WebGLExtension.h: New extension enum.
     35
     36        * html/canvas/WebGLRenderingContext.cpp:
     37        (WebCore::WebGLRenderingContext::validateVertexAttributes): Add an optional
     38        parameter representing the number of instance primitives we are asked
     39        to draw. Use that for the draw count if looking at an instanced attribute.
     40        Also make sure we see at least one non-instanced attribute.
     41        (WebCore::WebGLRenderingContext::validateDrawArrays): Update this so it could
     42        be used from either drawArrays or drawArraysInstanced.
     43        (WebCore::WebGLRenderingContext::drawArrays):
     44        (WebCore::WebGLRenderingContext::validateDrawElements): Same here, now can be
     45        used by the instanced and non-instanced versions.
     46        (WebCore::WebGLRenderingContext::drawElements):
     47        (WebCore::WebGLRenderingContext::getExtension): Create and return the new extension.
     48        (WebCore::WebGLRenderingContext::getSupportedExtensions): Add new extension to the list.
     49        (WebCore::WebGLRenderingContext::getVertexAttrib): Intercept a query to the divisor
     50        attribute and return the value we kept in the state.
     51        (WebCore::WebGLRenderingContext::drawArraysInstanced): Call the GC3D method.
     52        (WebCore::WebGLRenderingContext::drawElementsInstanced): Ditto.
     53        (WebCore::WebGLRenderingContext::vertexAttribDivisor): Ditto.
     54
     55        * html/canvas/WebGLRenderingContext.h: Define the new methods and parameters.
     56
     57        * html/canvas/WebGLVertexArrayObjectOES.cpp:
     58        (WebCore::WebGLVertexArrayObjectOES::setVertexAttribDivisor): Keep a record of the
     59        divisor if we set it.
     60        * html/canvas/WebGLVertexArrayObjectOES.h:
     61        (WebCore::WebGLVertexArrayObjectOES::VertexAttribState::VertexAttribState):
     62
     63        * platform/graphics/GraphicsContext3D.h: New enum.
     64        * platform/graphics/mac/GraphicsContext3DMac.mm:
     65        (WebCore::GraphicsContext3D::drawArraysInstanced): The actual calls into OpenGL.
     66        (WebCore::GraphicsContext3D::drawElementsInstanced): Ditto.
     67        (WebCore::GraphicsContext3D::vertexAttribDivisor): Ditto.
     68
     69        * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp: Empty implementations
     70        for non-mac platforms.
     71
     72        * platform/graphics/ios/GraphicsContext3DIOS.h: Define the iOS names for the
     73        functions.
     74
    1752014-01-22  Zalan Bujtas  <zalan@apple.com>
    276
  • trunk/Source/WebCore/DerivedSources.cpp

    r161688 r162565  
    2828#include "HTMLElementFactory.cpp"
    2929#include "HTMLEntityTable.cpp"
     30#if ENABLE(WEBGL)
     31#include "JSANGLEInstancedArrays.cpp"
     32#endif
    3033#include "JSAbstractWorker.cpp"
    3134#include "JSAttr.cpp"
  • trunk/Source/WebCore/DerivedSources.make

    r161901 r162565  
    409409    $(WebCore)/html/ValidityState.idl \
    410410    $(WebCore)/html/VoidCallback.idl \
     411    $(WebCore)/html/canvas/ANGLEInstancedArrays.idl \
    411412    $(WebCore)/html/canvas/CanvasGradient.idl \
    412413    $(WebCore)/html/canvas/CanvasPattern.idl \
  • trunk/Source/WebCore/GNUmakefile.list.am

    r162372 r162565  
    2929        DerivedSources/WebCore/InspectorWebTypeBuilders.cpp \
    3030        DerivedSources/WebCore/InspectorWebTypeBuilders.h \
     31        DerivedSources/WebCore/JSANGLEInstancedArrays.cpp \
     32        DerivedSources/WebCore/JSANGLEInstancedArrays.h \
    3133        DerivedSources/WebCore/JSAbstractWorker.cpp \
    3234        DerivedSources/WebCore/JSAbstractWorker.h \
     
    15071509        $(WebCore)/html/ValidityState.idl \
    15081510        $(WebCore)/html/VoidCallback.idl \
     1511        $(WebCore)/html/canvas/ANGLEInstancedArrays.idl \
    15091512        $(WebCore)/html/canvas/CanvasGradient.idl \
    15101513        $(WebCore)/html/canvas/CanvasPattern.idl \
     
    32413244        Source/WebCore/html/ButtonInputType.cpp \
    32423245        Source/WebCore/html/ButtonInputType.h \
     3246        Source/WebCore/html/canvas/ANGLEInstancedArrays.cpp \
     3247        Source/WebCore/html/canvas/ANGLEInstancedArrays.h \
    32433248        Source/WebCore/html/canvas/CanvasContextAttributes.cpp \
    32443249        Source/WebCore/html/canvas/CanvasContextAttributes.h \
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r162372 r162565  
    291291    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\CSSPropertyNames.cpp" />
    292292    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\CSSValueKeywords.cpp" />
     293    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSANGLEInstancedArrays.cpp">
     294      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
     295      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
     296      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
     297      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
     298      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
     299      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
     300      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
     301      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
     302      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
     303      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
     304      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
     305      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
     306    </ClCompile>
    293307    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSEXTDrawBuffers.cpp">
    294308      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
     
    65436557      <ForcedIncludeFiles Condition="'$(Configuration)|$(Platform)'=='Production|x64'">ICUVersion.h</ForcedIncludeFiles>
    65446558    </ClCompile>
     6559    <ClCompile Include="..\html\canvas\ANGLEInstancedArrays.cpp" />
    65456560    <ClCompile Include="..\html\canvas\CanvasContextAttributes.cpp" />
    65466561    <ClCompile Include="..\html\canvas\CanvasPathMethods.cpp" />
     
    1855418569    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\XMLViewerJS.h" />
    1855518570    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\XPathGrammar.h" />
     18571    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSANGLEInstancedArrays.h" />
    1855618572    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSEXTDrawBuffers.h" />
    1855718573    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSEXTTextureFilterAnisotropic.h" />
     
    1865418670    <ClInclude Include="..\ForwardingHeaders\runtime\WriteBarrier.h" />
    1865518671    <ClInclude Include="..\ForwardingHeaders\yarr\YarrJIT.h" />
     18672    <ClInclude Include="..\html\canvas\ANGLEInstancedArrays.h" />
    1865618673    <ClInclude Include="..\html\canvas\CanvasContextAttributes.h" />
    1865718674    <ClInclude Include="..\html\canvas\CanvasPathMethods.h" />
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters

    r162440 r162565  
    65936593      <Filter>DerivedSources</Filter>
    65946594    </ClCompile>
     6595    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSANGLEInstancedArrays.cpp">
     6596      <Filter>DerivedSources</Filter>
     6597    </ClCompile>
    65956598    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSEXTDrawBuffers.cpp">
    65966599      <Filter>DerivedSources</Filter>
     
    66196622    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSOESVertexArrayObject.cpp">
    66206623      <Filter>DerivedSources</Filter>
     6624    </ClCompile>
     6625    <ClCompile Include="..\html\canvas\ANGLEInstancedArrays.cpp">
     6626      <Filter>html\canvas</Filter>
    66216627    </ClCompile>
    66226628    <ClCompile Include="..\html\canvas\WebGLBuffer.cpp">
     
    1446414470    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSOESVertexArrayObject.h">
    1446514471      <Filter>DerivedSources</Filter>
     14472    </ClInclude>
     14473    <ClInclude Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\WebCore\DerivedSources\JSANGLEInstancedArrays.h">
     14474      <Filter>DerivedSources</Filter>
     14475    </ClInclude>
     14476    <ClInclude Include="..\html\canvas\ANGLEInstancedArrays.h">
     14477      <Filter>html\canvas</Filter>
    1446614478    </ClInclude>
    1446714479    <ClInclude Include="..\html\canvas\WebGLActiveInfo.h">
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r162454 r162565  
    11951195                319AE064142D6B24006563A1 /* StyleFilterData.h in Headers */ = {isa = PBXBuildFile; fileRef = 319AE062142D6B24006563A1 /* StyleFilterData.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11961196                319FBD5F15D2F464009640A6 /* CachedImageClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 319FBD5D15D2F444009640A6 /* CachedImageClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1197                31A795C61888BADC00382F90 /* JSANGLEInstancedArrays.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31A795C41888BAD100382F90 /* JSANGLEInstancedArrays.cpp */; };
     1198                31A795C71888BCB200382F90 /* ANGLEInstancedArrays.h in Headers */ = {isa = PBXBuildFile; fileRef = 31A795C21888B72400382F90 /* ANGLEInstancedArrays.h */; };
     1199                31A795C81888BCB500382F90 /* ANGLEInstancedArrays.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31A795C11888B72400382F90 /* ANGLEInstancedArrays.cpp */; };
    11971200                31AB5000122878A2001A7DB0 /* GraphicsContext3DIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 31AB4FFF122878A2001A7DB0 /* GraphicsContext3DIOS.h */; };
    11981201                31C0FF210E4CEB6E007D6FE5 /* WebKitAnimationEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31C0FF1B0E4CEB6E007D6FE5 /* WebKitAnimationEvent.cpp */; };
     
    80698072                319AE062142D6B24006563A1 /* StyleFilterData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleFilterData.h; path = style/StyleFilterData.h; sourceTree = "<group>"; };
    80708073                319FBD5D15D2F444009640A6 /* CachedImageClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedImageClient.h; sourceTree = "<group>"; };
     8074                31A795C11888B72400382F90 /* ANGLEInstancedArrays.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ANGLEInstancedArrays.cpp; path = canvas/ANGLEInstancedArrays.cpp; sourceTree = "<group>"; };
     8075                31A795C21888B72400382F90 /* ANGLEInstancedArrays.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ANGLEInstancedArrays.h; path = canvas/ANGLEInstancedArrays.h; sourceTree = "<group>"; };
     8076                31A795C31888B72400382F90 /* ANGLEInstancedArrays.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ANGLEInstancedArrays.idl; path = canvas/ANGLEInstancedArrays.idl; sourceTree = "<group>"; };
     8077                31A795C41888BAD100382F90 /* JSANGLEInstancedArrays.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSANGLEInstancedArrays.cpp; sourceTree = "<group>"; };
     8078                31A795C51888BAD100382F90 /* JSANGLEInstancedArrays.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSANGLEInstancedArrays.h; sourceTree = "<group>"; };
    80718079                31AB4FFF122878A2001A7DB0 /* GraphicsContext3DIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContext3DIOS.h; sourceTree = "<group>"; };
    80728080                31C0FF1B0E4CEB6E007D6FE5 /* WebKitAnimationEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitAnimationEvent.cpp; sourceTree = "<group>"; };
     
    1543815446                        isa = PBXGroup;
    1543915447                        children = (
     15448                                31A795C11888B72400382F90 /* ANGLEInstancedArrays.cpp */,
     15449                                31A795C21888B72400382F90 /* ANGLEInstancedArrays.h */,
     15450                                31A795C31888B72400382F90 /* ANGLEInstancedArrays.idl */,
    1544015451                                6E4E91A710F7FB3100A2779C /* CanvasContextAttributes.cpp */,
    1544115452                                6E4E91A810F7FB3100A2779C /* CanvasContextAttributes.h */,
     
    1819318204                        isa = PBXGroup;
    1819418205                        children = (
     18206                                31A795C41888BAD100382F90 /* JSANGLEInstancedArrays.cpp */,
     18207                                31A795C51888BAD100382F90 /* JSANGLEInstancedArrays.h */,
    1819518208                                BE8EF03E171C8FF9009B48C3 /* JSAudioTrack.cpp */,
    1819618209                                BE8EF03F171C8FF9009B48C3 /* JSAudioTrack.h */,
     
    2366523678                                8AD0A59614C88358000D83C5 /* DOMWebKitCSSRegionRule.h in Headers */,
    2366623679                                8AD0A59814C88358000D83C5 /* DOMWebKitCSSRegionRuleInternal.h in Headers */,
     23680                                31A795C71888BCB200382F90 /* ANGLEInstancedArrays.h in Headers */,
    2366723681                                31611E610E1C4E1400F6A579 /* DOMWebKitCSSTransformValue.h in Headers */,
    2366823682                                31611E630E1C4E1400F6A579 /* DOMWebKitCSSTransformValueInternal.h in Headers */,
     
    2884528859                                5038BE2F1472AD230095E0D1 /* StyleCachedShader.cpp in Sources */,
    2884628860                                50E18CD816F9285800C65486 /* StyleCustomFilterProgram.cpp in Sources */,
     28861                                31A795C81888BCB500382F90 /* ANGLEInstancedArrays.cpp in Sources */,
    2884728862                                A5840E24187B8AC200843B10 /* PageInjectedScriptHost.cpp in Sources */,
    2884828863                                50E18CD916F9285800C65486 /* StyleCustomFilterProgramCache.cpp in Sources */,
     
    2929029305                                97AABD2614FA09D5007457AE /* WebSocketHandshake.cpp in Sources */,
    2929129306                                0F580FA41496939100FB5BD8 /* WebTiledBackingLayer.mm in Sources */,
     29307                                31A795C61888BADC00382F90 /* JSANGLEInstancedArrays.cpp in Sources */,
    2929229308                                CD82030B1395AB6A00F956C6 /* WebVideoFullscreenController.mm in Sources */,
    2929329309                                CD82030D1395AB6A00F956C6 /* WebVideoFullscreenHUDWindowController.mm in Sources */,
  • trunk/Source/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp

    r161688 r162565  
    3030#include "JSWebGLRenderingContext.h"
    3131
     32#include "ANGLEInstancedArrays.h"
    3233#include "EXTDrawBuffers.h"
    3334#include "EXTTextureFilterAnisotropic.h"
     
    3536#include "HTMLCanvasElement.h"
    3637#include "HTMLImageElement.h"
     38#include "JSANGLEInstancedArrays.h"
    3739#include "JSEXTDrawBuffers.h"
    3840#include "JSEXTTextureFilterAnisotropic.h"
     
    234236    case WebGLExtension::WebGLDepthTextureName:
    235237        return toJS(exec, globalObject, static_cast<WebGLDepthTexture*>(extension));
     238    case WebGLExtension::ANGLEInstancedArraysName:
     239        return toJS(exec, globalObject, static_cast<ANGLEInstancedArrays*>(extension));
    236240    }
    237241    ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/html/canvas/WebGLExtension.h

    r161688 r162565  
    5252        WebGLCompressedTextureATCName,
    5353        WebGLCompressedTexturePVRTCName,
     54        ANGLEInstancedArraysName,
    5455    };
    5556
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp

    r162180 r162565  
    3030#include "WebGLRenderingContext.h"
    3131
     32#include "ANGLEInstancedArrays.h"
    3233#include "CachedImage.h"
    3334#include "DOMWindow.h"
     
    18871888}
    18881889
    1889 bool WebGLRenderingContext::validateVertexAttributes(unsigned numElementsRequired)
     1890bool WebGLRenderingContext::validateVertexAttributes(unsigned elementCount, unsigned primitiveCount)
    18901891{
    18911892    if (!m_currentProgram)
     
    18981899    }
    18991900
    1900     if (numElementsRequired <= 0)
     1901    if (elementCount <= 0)
    19011902        return true;
    19021903
    1903     // Look in each consumed vertex attrib (by the current program) and find the smallest buffer size
    1904     unsigned smallestNumElements = UINT_MAX;
     1904
     1905    // Look in each consumed vertex attrib (by the current program).
     1906    bool sawNonInstancedAttrib = false;
     1907    bool sawEnabledAttrib = false;
    19051908    int numActiveAttribLocations = m_currentProgram->numActiveAttribLocations();
    19061909    for (int i = 0; i < numActiveAttribLocations; ++i) {
     
    19091912            const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(loc);
    19101913            if (state.enabled) {
     1914                sawEnabledAttrib = true;
    19111915                // Avoid off-by-one errors in numElements computation.
    19121916                // For the last element, we will only touch the data for the
     
    19171921                if (bytesRemaining >= state.bytesPerElement)
    19181922                    numElements = 1 + (bytesRemaining - state.bytesPerElement) / state.stride;
    1919                 if (numElements < smallestNumElements)
    1920                     smallestNumElements = numElements;
     1923                if (!state.divisor)
     1924                    sawNonInstancedAttrib = true;
     1925                if ((!state.divisor && elementCount > numElements) || (state.divisor && primitiveCount > numElements))
     1926                    return false;
    19211927            }
    19221928        }
    19231929    }
    19241930
    1925     if (smallestNumElements == INT_MAX)
    1926         smallestNumElements = 0;
    1927 
    1928     return numElementsRequired <= smallestNumElements;
     1931    if (!sawNonInstancedAttrib && sawEnabledAttrib)
     1932        return false;
     1933
     1934    return true;
    19291935}
    19301936
     
    19421948}
    19431949
    1944 void WebGLRenderingContext::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count, ExceptionCode& ec)
    1945 {
    1946     UNUSED_PARAM(ec);
    1947 
    1948     if (isContextLost() || !validateDrawMode("drawArrays", mode))
    1949         return;
    1950 
    1951     if (!validateStencilSettings("drawArrays"))
    1952         return;
     1950bool WebGLRenderingContext::validateDrawArrays(const char* functionName, GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount)
     1951{
     1952    if (isContextLost() || !validateDrawMode(functionName, mode))
     1953        return false;
     1954
     1955    if (!validateStencilSettings(functionName))
     1956        return false;
    19531957
    19541958    if (first < 0 || count < 0) {
    1955         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "drawArrays", "first or count < 0");
    1956         return;
     1959        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "first or count < 0");
     1960        return false;
    19571961    }
    19581962
    19591963    if (!count) {
    19601964        cleanupAfterGraphicsCall(true);
    1961         return;
     1965        return false;
     1966    }
     1967
     1968    if (primcount < 0) {
     1969        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "primcount < 0");
     1970        return false;
    19621971    }
    19631972
     
    19671976        Checked<GC3Dint, RecordOverflow> checkedCount(count);
    19681977        Checked<GC3Dint, RecordOverflow> checkedSum = checkedFirst + checkedCount;
    1969         if (checkedSum.hasOverflowed() || !validateVertexAttributes(checkedSum.unsafeGet())) {
    1970             synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "drawArrays", "attempt to access out of bounds arrays");
    1971             return;
     1978        Checked<GC3Dint, RecordOverflow> checkedPrimCount(primcount);
     1979        if (checkedSum.hasOverflowed() || checkedPrimCount.hasOverflowed() || !validateVertexAttributes(checkedSum.unsafeGet(), checkedPrimCount.unsafeGet())) {
     1980            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "attempt to access out of bounds arrays");
     1981            return false;
    19721982        }
    19731983    } else {
    19741984        if (!validateVertexAttributes(0)) {
    1975             synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "drawArrays", "attribs not setup correctly");
    1976             return;
     1985            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "attribs not setup correctly");
     1986            return false;
    19771987        }
    19781988    }
     
    19801990    const char* reason = "framebuffer incomplete";
    19811991    if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3D(), !isResourceSafe(), &reason)) {
    1982         synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "drawArrays", reason);
    1983         return;
    1984     }
     1992        synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, functionName, reason);
     1993        return false;
     1994    }
     1995
     1996    return true;
     1997}
     1998
     1999void WebGLRenderingContext::drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count, ExceptionCode& ec)
     2000{
     2001    UNUSED_PARAM(ec);
     2002
     2003    if (!validateDrawArrays("drawArrays", mode, first, count, 0))
     2004        return;
    19852005
    19862006    clearIfComposited();
     
    19992019}
    20002020
    2001 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, long long offset, ExceptionCode& ec)
    2002 {
    2003     UNUSED_PARAM(ec);
    2004 
    2005     if (isContextLost() || !validateDrawMode("drawElements", mode))
    2006         return;
    2007 
    2008     if (!validateStencilSettings("drawElements"))
    2009         return;
     2021bool WebGLRenderingContext::validateDrawElements(const char* functionName, GC3Denum mode, GC3Dsizei count, GC3Denum type, long long offset, unsigned& numElements)
     2022{
     2023    if (isContextLost() || !validateDrawMode(functionName, mode))
     2024        return false;
     2025
     2026    if (!validateStencilSettings(functionName))
     2027        return false;
    20102028
    20112029    switch (type) {
     
    20162034        if (m_oesElementIndexUint)
    20172035            break;
    2018         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "drawElements", "invalid type");
    2019         return;
     2036        synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid type");
     2037        return false;
    20202038    default:
    2021         synthesizeGLError(GraphicsContext3D::INVALID_ENUM, "drawElements", "invalid type");
    2022         return;
     2039        synthesizeGLError(GraphicsContext3D::INVALID_ENUM, functionName, "invalid type");
     2040        return false;
    20232041    }
    20242042
    20252043    if (count < 0 || offset < 0) {
    2026         synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "drawElements", "count or offset < 0");
    2027         return;
     2044        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, functionName, "count or offset < 0");
     2045        return false;
    20282046    }
    20292047
    20302048    if (!count) {
    20312049        cleanupAfterGraphicsCall(true);
    2032         return;
     2050        return false;
    20332051    }
    20342052
    20352053    if (!m_boundVertexArrayObject->getElementArrayBuffer()) {
    2036         synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "drawElements", "no ELEMENT_ARRAY_BUFFER bound");
    2037         return;
    2038     }
    2039 
    2040     unsigned numElements = 0;
     2054        synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "no ELEMENT_ARRAY_BUFFER bound");
     2055        return false;
     2056    }
     2057
    20412058    if (!isErrorGeneratedOnOutOfBoundsAccesses()) {
    20422059        // Ensure we have a valid rendering state
    20432060        if (!validateElementArraySize(count, type, static_cast<GC3Dintptr>(offset))) {
    2044             synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "drawElements", "request out of bounds for current ELEMENT_ARRAY_BUFFER");
    2045             return;
     2061            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "request out of bounds for current ELEMENT_ARRAY_BUFFER");
     2062            return false;
    20462063        }
    20472064        if (!count)
    2048             return;
     2065            return false;
    20492066        if (!validateIndexArrayConservative(type, numElements) || !validateVertexAttributes(numElements)) {
    20502067            if (!validateIndexArrayPrecise(count, type, static_cast<GC3Dintptr>(offset), numElements) || !validateVertexAttributes(numElements)) {
    2051                 synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "drawElements", "attempt to access out of bounds arrays");
    2052                 return;
     2068                synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "attempt to access out of bounds arrays");
     2069                return false;
    20532070            }
    20542071        }
    20552072    } else {
    20562073        if (!validateVertexAttributes(0)) {
    2057             synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, "drawElements", "attribs not setup correctly");
    2058             return;
     2074            synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "attribs not setup correctly");
     2075            return false;
    20592076        }
    20602077    }
     
    20622079    const char* reason = "framebuffer incomplete";
    20632080    if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3D(), !isResourceSafe(), &reason)) {
    2064         synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "drawElements", reason);
    2065         return;
    2066     }
     2081        synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, functionName, reason);
     2082        return false;
     2083    }
     2084
     2085    return true;
     2086}
     2087
     2088void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, long long offset, ExceptionCode& ec)
     2089{
     2090    UNUSED_PARAM(ec);
     2091
     2092    unsigned numElements = 0;
     2093    if (!validateDrawElements("drawElements", mode, count, type, offset, numElements))
     2094        return;
     2095
    20672096    clearIfComposited();
    20682097
     
    24772506        }
    24782507        return m_extDrawBuffers.get();
     2508    }
     2509    if (equalIgnoringCase(name, "ANGLE_instanced_arrays") && ANGLEInstancedArrays::supported(this)) {
     2510        if (!m_angleInstancedArrays) {
     2511            m_context->getExtensions()->ensureEnabled("GL_ANGLE_instanced_arrays");
     2512            m_angleInstancedArrays = ANGLEInstancedArrays::create(this);
     2513        }
     2514        return m_angleInstancedArrays.get();
    24792515    }
    24802516    if (allowPrivilegedExtensions()) {
     
    29993035    if (supportsDrawBuffers())
    30003036        result.append("EXT_draw_buffers");
     3037    if (ANGLEInstancedArrays::supported(this))
     3038        result.append("ANGLE_instanced_arrays");
    30013039
    30023040    if (allowPrivilegedExtensions()) {
     
    32113249{
    32123250    UNUSED_PARAM(ec);
     3251
    32133252    if (isContextLost())
    32143253        return WebGLGetInfo();
     3254
    32153255    WebGLStateRestorer(this, false);
     3256
    32163257    if (index >= m_maxVertexAttribs) {
    32173258        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "getVertexAttrib", "index out of range");
    32183259        return WebGLGetInfo();
    32193260    }
     3261
    32203262    const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArrayObject->getVertexAttribState(index);
     3263
     3264    if (m_angleInstancedArrays && pname == GraphicsContext3D::VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE)
     3265        return WebGLGetInfo(state.divisor);
     3266
    32213267    switch (pname) {
    32223268    case GraphicsContext3D::VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
     
    61036149}
    61046150
     6151void WebGLRenderingContext::drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount)
     6152{
     6153    if (!validateDrawArrays("drawArraysInstanced", mode, first, count, primcount))
     6154        return;
     6155
     6156    if (primcount < 0) {
     6157        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "drawArraysInstanced", "primcount < 0");
     6158        return;
     6159    }
     6160
     6161    if (!primcount) {
     6162        cleanupAfterGraphicsCall(true);
     6163        return;
     6164    }
     6165
     6166    clearIfComposited();
     6167
     6168    bool vertexAttrib0Simulated = false;
     6169    if (!isGLES2Compliant())
     6170        vertexAttrib0Simulated = simulateVertexAttrib0(first + count - 1);
     6171    if (!isGLES2NPOTStrict())
     6172        checkTextureCompleteness("drawArraysInstanced", true);
     6173    UNUSED_PARAM(primcount);
     6174    m_context->drawArraysInstanced(mode, first, count, primcount);
     6175    if (!isGLES2Compliant() && vertexAttrib0Simulated)
     6176        restoreStatesAfterVertexAttrib0Simulation();
     6177    if (!isGLES2NPOTStrict())
     6178        checkTextureCompleteness("drawArraysInstanced", false);
     6179    cleanupAfterGraphicsCall(true);
     6180}
     6181
     6182void WebGLRenderingContext::drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount)
     6183{
     6184    unsigned numElements = 0;
     6185    if (!validateDrawElements("drawElementsInstanced", mode, count, type, offset, numElements))
     6186        return;
     6187
     6188    if (primcount < 0) {
     6189        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "drawElementsInstanced", "primcount < 0");
     6190        return;
     6191    }
     6192
     6193    if (!primcount) {
     6194        cleanupAfterGraphicsCall(true);
     6195        return;
     6196    }
     6197
     6198    clearIfComposited();
     6199
     6200    bool vertexAttrib0Simulated = false;
     6201    if (!isGLES2Compliant()) {
     6202        if (!numElements)
     6203            validateIndexArrayPrecise(count, type, static_cast<GC3Dintptr>(offset), numElements);
     6204        vertexAttrib0Simulated = simulateVertexAttrib0(numElements);
     6205    }
     6206    if (!isGLES2NPOTStrict())
     6207        checkTextureCompleteness("drawElementsInstanced", true);
     6208    m_context->drawElementsInstanced(mode, count, type, static_cast<GC3Dintptr>(offset), primcount);
     6209    if (!isGLES2Compliant() && vertexAttrib0Simulated)
     6210        restoreStatesAfterVertexAttrib0Simulation();
     6211    if (!isGLES2NPOTStrict())
     6212        checkTextureCompleteness("drawElementsInstanced", false);
     6213    cleanupAfterGraphicsCall(true);
     6214}
     6215
     6216void WebGLRenderingContext::vertexAttribDivisor(GC3Duint index, GC3Duint divisor)
     6217{
     6218    if (isContextLost())
     6219        return;
     6220
     6221    if (index >= m_maxVertexAttribs) {
     6222        synthesizeGLError(GraphicsContext3D::INVALID_VALUE, "vertexAttribDivisor", "index out of range");
     6223        return;
     6224    }
     6225
     6226    m_boundVertexArrayObject->setVertexAttribDivisor(index, divisor);
     6227    m_context->vertexAttribDivisor(index, divisor);
     6228}
     6229
     6230
    61056231} // namespace WebCore
    61066232
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h

    r162180 r162565  
    4242namespace WebCore {
    4343
     44class ANGLEInstancedArrays;
    4445class EXTDrawBuffers;
    4546class EXTTextureFilterAnisotropic;
     
    324325    unsigned getMaxVertexAttribs() const { return m_maxVertexAttribs; }
    325326
     327    // ANGLE_instanced_arrays extension functions.
     328    void drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
     329    void drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
     330    void vertexAttribDivisor(GC3Duint index, GC3Duint divisor);
     331
    326332private:
    327333    friend class EXTDrawBuffers;
     
    379385    // Precise but slow index validation -- only done if conservative checks fail
    380386    bool validateIndexArrayPrecise(GC3Dsizei count, GC3Denum type, GC3Dintptr offset, unsigned& numElementsRequired);
    381     // If numElements <= 0, we only check if each enabled vertex attribute is bound to a buffer.
    382     bool validateVertexAttributes(unsigned numElements);
     387    bool validateVertexAttributes(unsigned elementCount, unsigned primitiveCount = 0);
    383388
    384389    bool validateWebGLObject(const char*, WebGLObject*);
     390
     391    bool validateDrawArrays(const char* functionName, GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
     392    bool validateDrawElements(const char* functionName, GC3Denum mode, GC3Dsizei count, GC3Denum type, long long offset, unsigned& numElements);
    385393
    386394    // Adds a compressed texture format.
     
    541549    OwnPtr<WebGLCompressedTextureS3TC> m_webglCompressedTextureS3TC;
    542550    OwnPtr<WebGLDepthTexture> m_webglDepthTexture;
     551    OwnPtr<ANGLEInstancedArrays> m_angleInstancedArrays;
    543552
    544553    // Helpers for getParameter and others
  • trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectOES.cpp

    r129275 r162565  
    144144}
    145145
     146void WebGLVertexArrayObjectOES::setVertexAttribDivisor(GC3Duint index, GC3Duint divisor)
     147{
     148    VertexAttribState& state = m_vertexAttribState[index];
     149    state.divisor = divisor;
     150}
     151
    146152}
    147153
  • trunk/Source/WebCore/html/canvas/WebGLVertexArrayObjectOES.h

    r162180 r162565  
    5656            , originalStride(0)
    5757            , offset(0)
     58            , divisor(0)
    5859        {
    5960        }
     
    7172        GC3Dsizei originalStride;
    7273        GC3Dintptr offset;
     74        GC3Duint divisor;
    7375    };
    7476   
     
    8486    void setVertexAttribState(GC3Duint, GC3Dsizei, GC3Dint, GC3Denum, GC3Dboolean, GC3Dsizei, GC3Dintptr, PassRefPtr<WebGLBuffer>);
    8587    void unbindBuffer(PassRefPtr<WebGLBuffer>);
     88
     89    void setVertexAttribDivisor(GC3Duint index, GC3Duint divisor);
    8690
    8791private:
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h

    r162451 r162565  
    426426        CONTEXT_LOST_WEBGL = 0x9242,
    427427        UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243,
    428         BROWSER_DEFAULT_WEBGL = 0x9244
     428        BROWSER_DEFAULT_WEBGL = 0x9244,
     429        VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88FE
    429430    };
    430431
     
    828829    void reshape(int width, int height);
    829830
     831    void drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
     832    void drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
     833    void vertexAttribDivisor(GC3Duint index, GC3Duint divisor);
     834
    830835#if PLATFORM(GTK) || PLATFORM(EFL) || USE(CAIRO)
    831836    void paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight,
  • trunk/Source/WebCore/platform/graphics/ios/GraphicsContext3DIOS.h

    r162160 r162565  
    4444#define glRenderbufferStorageMultisampleEXT glRenderbufferStorageMultisampleAPPLE
    4545
     46#define glDrawArraysInstancedARB glDrawArraysInstancedEXT
     47#define glDrawElementsInstancedARB glDrawElementsInstancedEXT
     48#define glVertexAttribDivisorARB glVertexAttribDivisorEXT
     49
    4650#define GL_COLOR_ATTACHMENT0_EXT GL_COLOR_ATTACHMENT0
    4751#define GL_DEPTH24_STENCIL8_EXT GL_DEPTH24_STENCIL8_OES
  • trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm

    r161759 r162565  
    371371}
    372372
     373void GraphicsContext3D::drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount)
     374{
     375#if PLATFORM(IOS) || PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     376    makeContextCurrent();
     377    ::glDrawArraysInstancedARB(mode, first, count, primcount);
     378#else
     379    UNUSED_PARAM(mode);
     380    UNUSED_PARAM(first);
     381    UNUSED_PARAM(count);
     382    UNUSED_PARAM(primcount);
     383#endif
     384}
     385
     386void GraphicsContext3D::drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount)
     387{
     388#if PLATFORM(IOS) || PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     389    makeContextCurrent();
     390    ::glDrawElementsInstancedARB(mode, count, type, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset)), primcount);
     391#else
     392    UNUSED_PARAM(mode);
     393    UNUSED_PARAM(count);
     394    UNUSED_PARAM(type);
     395    UNUSED_PARAM(offset);
     396    UNUSED_PARAM(primcount);
     397#endif
     398}
     399
     400void GraphicsContext3D::vertexAttribDivisor(GC3Duint index, GC3Duint divisor)
     401{
     402#if PLATFORM(IOS) || PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
     403    makeContextCurrent();
     404    ::glVertexAttribDivisorARB(index, divisor);
     405#else
     406    UNUSED_PARAM(index);
     407    UNUSED_PARAM(divisor);
     408#endif
     409}
     410
    373411}
    374412
  • trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp

    r162451 r162565  
    352352}
    353353
     354#if !PLATFORM(MAC)
     355void GraphicsContext3D::drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount)
     356{
     357    UNUSED_PARAM(mode);
     358    UNUSED_PARAM(first);
     359    UNUSED_PARAM(count);
     360    UNUSED_PARAM(primcount);
     361}
     362
     363void GraphicsContext3D::drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount)
     364{
     365    UNUSED_PARAM(mode);
     366    UNUSED_PARAM(count);
     367    UNUSED_PARAM(type);
     368    UNUSED_PARAM(offset);
     369    UNUSED_PARAM(primcount);
     370}
     371
     372void GraphicsContext3D::vertexAttribDivisor(GC3Duint index, GC3Duint divisor)
     373{
     374    UNUSED_PARAM(index);
     375    UNUSED_PARAM(divisor);
     376}
     377#endif
     378
    354379}
    355380
Note: See TracChangeset for help on using the changeset viewer.