Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OES_element_index_uint support #121

Merged
merged 3 commits into from
Oct 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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