Skip to content

Commit

Permalink
Implement OES_element_index_uint support (#121)
Browse files Browse the repository at this point in the history
* Implement OES_element_index_uint support

* Better version of getSupportedExtensions

* Formatting
  • Loading branch information
dhritzkiv authored and mourner committed Oct 18, 2017
1 parent 13d3b32 commit 99efeb3
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ function STACKGL_resize_drawingbuffer () {

function STACKGL_destroy_context () {
}

function OESElementIndexUint () {
}
/* eslint-enable camelcase */

function unpackTypedArray (array) {
Expand Down Expand Up @@ -666,12 +669,21 @@ gl.getContextAttributes = function () {
return this._contextattributes
}

var _getSupportedExtensions = gl.getSupportedExtensions
gl.getSupportedExtensions = function getSupportedExtensions () {
return [
var exts = [
'ANGLE_instanced_arrays',
'STACKGL_resize_drawingbuffer',
'STACKGL_destroy_context'
]

var supportedExts = _getSupportedExtensions.call(this)

if (supportedExts.indexOf('GL_OES_element_index_uint') >= 0) {
exts.push('OES_element_index_uint')
}

return exts
}

function createANGLEInstancedArrays (context) {
Expand Down Expand Up @@ -787,6 +799,13 @@ function createANGLEInstancedArrays (context) {
}
offset >>= 1
elementData = new Uint16Array(elementBuffer._elements.buffer)
} else if (context._extensions.oes_element_index_uint && type === gl.UNSIGNED_INT) {
if (offset % 4) {
setError(context, gl.INVALID_OPERATION)
return
}
offset >>= 2
elementData = new Uint32Array(elementBuffer._elements.buffer)
} else if (type === gl.UNSIGNED_BYTE) {
elementData = elementBuffer._elements
} else {
Expand Down Expand Up @@ -874,6 +893,17 @@ function createANGLEInstancedArrays (context) {
return result
}

function getOESElementIndexUint (context) {
var result = null
var exts = context.getSupportedExtensions()

if (exts && exts.indexOf('OES_element_index_uint') >= 0) {
result = new OESElementIndexUint()
}

return result
}

gl.getExtension = function getExtension (name) {
var str = name.toLowerCase()
if (str in this._extensions) {
Expand All @@ -892,6 +922,9 @@ gl.getExtension = function getExtension (name) {
ext = new STACKGL_resize_drawingbuffer()
ext.resize = this.resize.bind(this)
break
case 'oes_element_index_uint':
ext = getOESElementIndexUint(this)
break
}
if (ext) {
this._extensions[str] = ext
Expand Down Expand Up @@ -1380,7 +1413,7 @@ gl.bufferSubData = function bufferSubData (target, offset, data) {
}

if (offset + u8Data.length > active._size) {
setError(this, gl.INVALID_OPERATION)
setError(this, gl.INVALID_VALUE)
return
}

Expand Down Expand Up @@ -2082,6 +2115,13 @@ gl.drawElements = function drawElements (mode, count, type, ioffset) {
}
offset >>= 1
elementData = new Uint16Array(elementBuffer._elements.buffer)
} else if (this._extensions.oes_element_index_uint && type === gl.UNSIGNED_INT) {
if (offset % 4) {
setError(this, gl.INVALID_OPERATION)
return
}
offset >>= 2
elementData = new Uint32Array(elementBuffer._elements.buffer)
} else if (type === gl.UNSIGNED_BYTE) {
elementData = elementBuffer._elements
} else {
Expand Down

0 comments on commit 99efeb3

Please sign in to comment.