Use OES_element_index_uint when available
This commit is contained in:
@@ -113,6 +113,15 @@ ol.has.POINTER = 'PointerEvent' in goog.global;
|
|||||||
ol.has.MSPOINTER = !!(goog.global.navigator.msPointerEnabled);
|
ol.has.MSPOINTER = !!(goog.global.navigator.msPointerEnabled);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if browser supports WebGL.
|
||||||
|
* @const
|
||||||
|
* @type {boolean}
|
||||||
|
* @api stable
|
||||||
|
*/
|
||||||
|
ol.has.WEBGL;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum supported WebGL texture size in pixels. If WebGL is not
|
* The maximum supported WebGL texture size in pixels. If WebGL is not
|
||||||
* supported, the value is set to `-1`.
|
* supported, the value is set to `-1`.
|
||||||
@@ -123,17 +132,18 @@ ol.has.WEBGL_MAX_TEXTURE_SIZE;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if browser supports WebGL.
|
* List of supported WebGL extensions.
|
||||||
* @const
|
* @const
|
||||||
* @type {boolean}
|
* @type {Array.<string>}
|
||||||
* @api stable
|
|
||||||
*/
|
*/
|
||||||
ol.has.WEBGL;
|
ol.has.WEBGL_EXTENSIONS;
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
if (ol.ENABLE_WEBGL) {
|
if (ol.ENABLE_WEBGL) {
|
||||||
var hasWebGL = false, textureSize = -1;
|
var hasWebGL = false;
|
||||||
|
var textureSize = -1;
|
||||||
|
var /** @type {Array.<string>} */ extensions = [];
|
||||||
if ('WebGLRenderingContext' in goog.global) {
|
if ('WebGLRenderingContext' in goog.global) {
|
||||||
try {
|
try {
|
||||||
var canvas = /** @type {HTMLCanvasElement} */
|
var canvas = /** @type {HTMLCanvasElement} */
|
||||||
@@ -145,10 +155,12 @@ ol.has.WEBGL;
|
|||||||
hasWebGL = true;
|
hasWebGL = true;
|
||||||
textureSize = /** @type {number} */
|
textureSize = /** @type {number} */
|
||||||
(gl.getParameter(gl.MAX_TEXTURE_SIZE));
|
(gl.getParameter(gl.MAX_TEXTURE_SIZE));
|
||||||
|
extensions = gl.getSupportedExtensions();
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
ol.has.WEBGL = hasWebGL;
|
ol.has.WEBGL = hasWebGL;
|
||||||
ol.has.WEBGL_MAX_TEXTURE_SIZE = textureSize;
|
ol.has.WEBGL_MAX_TEXTURE_SIZE = textureSize;
|
||||||
|
ol.has.WEBGL_EXTENSIONS = extensions;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -434,8 +434,19 @@ ol.render.webgl.ImageReplay.prototype.finish = function(context) {
|
|||||||
|
|
||||||
this.indicesBuffer_ = gl.createBuffer();
|
this.indicesBuffer_ = gl.createBuffer();
|
||||||
gl.bindBuffer(goog.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer_);
|
gl.bindBuffer(goog.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer_);
|
||||||
gl.bufferData(goog.webgl.ELEMENT_ARRAY_BUFFER,
|
var /** @type {ArrayBufferView} */ arrayBuffer, bits;
|
||||||
new Uint16Array(this.indices_), goog.webgl.STATIC_DRAW);
|
if (context.hasOESElementIndexUint) {
|
||||||
|
bits = 32;
|
||||||
|
arrayBuffer = new Uint32Array(this.indices_);
|
||||||
|
} else {
|
||||||
|
bits = 16;
|
||||||
|
arrayBuffer = new Uint16Array(this.indices_);
|
||||||
|
}
|
||||||
|
goog.asserts.assert(this.indices_[this.indices_.length - 1] < (1 << bits),
|
||||||
|
'Too large element index detected, and OES_element_index_uint ' +
|
||||||
|
'extension not available.');
|
||||||
|
gl.bufferData(goog.webgl.ELEMENT_ARRAY_BUFFER, arrayBuffer,
|
||||||
|
goog.webgl.STATIC_DRAW);
|
||||||
|
|
||||||
goog.asserts.assert(this.textures_.length === 0);
|
goog.asserts.assert(this.textures_.length === 0);
|
||||||
|
|
||||||
@@ -611,9 +622,10 @@ ol.render.webgl.ImageReplay.prototype.replay = function(context,
|
|||||||
gl.bindTexture(goog.webgl.TEXTURE_2D, this.textures_[i]);
|
gl.bindTexture(goog.webgl.TEXTURE_2D, this.textures_[i]);
|
||||||
var end = this.groupIndices_[i];
|
var end = this.groupIndices_[i];
|
||||||
var numItems = end - start;
|
var numItems = end - start;
|
||||||
var offsetInBytes = start * 2; // 2 Bytes for UNSIGNED_SHORT
|
var offsetInBytes = start * (context.hasOESElementIndexUint ? 4 : 2);
|
||||||
gl.drawElements(goog.webgl.TRIANGLES, numItems,
|
var elementType = context.hasOESElementIndexUint ?
|
||||||
goog.webgl.UNSIGNED_SHORT, offsetInBytes);
|
goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT;
|
||||||
|
gl.drawElements(goog.webgl.TRIANGLES, numItems, elementType, offsetInBytes);
|
||||||
start = end;
|
start = end;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
goog.provide('ol.webgl.Context');
|
goog.provide('ol.webgl.Context');
|
||||||
|
|
||||||
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.events');
|
goog.require('goog.events');
|
||||||
goog.require('goog.log');
|
goog.require('goog.log');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
|
goog.require('ol.has');
|
||||||
goog.require('ol.structs.Buffer');
|
goog.require('ol.structs.Buffer');
|
||||||
goog.require('ol.structs.IntegerSet');
|
goog.require('ol.structs.IntegerSet');
|
||||||
goog.require('ol.webgl.WebGLContextEventType');
|
goog.require('ol.webgl.WebGLContextEventType');
|
||||||
@@ -66,6 +68,18 @@ ol.webgl.Context = function(canvas, gl) {
|
|||||||
*/
|
*/
|
||||||
this.currentProgram_ = null;
|
this.currentProgram_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.hasOESElementIndexUint = goog.array.contains(
|
||||||
|
ol.has.WEBGL_EXTENSIONS, 'OES_element_index_uint');
|
||||||
|
|
||||||
|
// use the OES_element_index_uint extension if available
|
||||||
|
if (this.hasOESElementIndexUint) {
|
||||||
|
var ext = gl.getExtension('OES_element_index_uint');
|
||||||
|
goog.asserts.assert(!goog.isNull(ext));
|
||||||
|
}
|
||||||
|
|
||||||
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.LOST,
|
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.LOST,
|
||||||
this.handleWebGLContextLost, false, this);
|
this.handleWebGLContextLost, false, this);
|
||||||
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.RESTORED,
|
goog.events.listen(this.canvas_, ol.webgl.WebGLContextEventType.RESTORED,
|
||||||
|
|||||||
Reference in New Issue
Block a user