Webgl Helper / add an API for OESElementIndexUint extension
This commit is contained in:
committed by
Olivier Guyot
parent
7fb113c3dc
commit
06be00bbd5
@@ -2,7 +2,7 @@
|
|||||||
* @module ol/renderer/webgl/PointsLayer
|
* @module ol/renderer/webgl/PointsLayer
|
||||||
*/
|
*/
|
||||||
import WebGLArrayBuffer from '../../webgl/Buffer.js';
|
import WebGLArrayBuffer from '../../webgl/Buffer.js';
|
||||||
import {DYNAMIC_DRAW, ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, FLOAT, EXTENSIONS as WEBGL_EXTENSIONS} from '../../webgl.js';
|
import {DYNAMIC_DRAW, ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, FLOAT} from '../../webgl.js';
|
||||||
import {DefaultAttrib, DefaultUniform} from '../../webgl/Helper.js';
|
import {DefaultAttrib, DefaultUniform} from '../../webgl/Helper.js';
|
||||||
import GeometryType from '../../geom/GeometryType.js';
|
import GeometryType from '../../geom/GeometryType.js';
|
||||||
import WebGLLayerRenderer, {
|
import WebGLLayerRenderer, {
|
||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
apply as applyTransform
|
apply as applyTransform
|
||||||
} from '../../transform.js';
|
} from '../../transform.js';
|
||||||
import {create as createWebGLWorker} from '../../worker/webgl.js';
|
import {create as createWebGLWorker} from '../../worker/webgl.js';
|
||||||
import {includes} from '../../array.js';
|
|
||||||
|
|
||||||
const VERTEX_SHADER = `
|
const VERTEX_SHADER = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
@@ -421,7 +420,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
|
|||||||
const message = {
|
const message = {
|
||||||
type: WebGLWorkerMessageType.GENERATE_BUFFERS,
|
type: WebGLWorkerMessageType.GENERATE_BUFFERS,
|
||||||
renderInstructions: this.renderInstructions_.buffer,
|
renderInstructions: this.renderInstructions_.buffer,
|
||||||
useShortIndices: !includes(WEBGL_EXTENSIONS, 'OES_element_index_uint')
|
useShortIndices: !this.helper.getElementIndexUintEnabled()
|
||||||
};
|
};
|
||||||
// additional properties will be sent back as-is by the worker
|
// additional properties will be sent back as-is by the worker
|
||||||
message['projectionTransform'] = projectionTransform;
|
message['projectionTransform'] = projectionTransform;
|
||||||
|
|||||||
+15
-4
@@ -260,11 +260,12 @@ class WebGLHelper extends Disposable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
this.hasOESElementIndexUint = includes(WEBGL_EXTENSIONS, 'OES_element_index_uint');
|
this.hasOESElementIndexUint_ = includes(WEBGL_EXTENSIONS, 'OES_element_index_uint');
|
||||||
|
|
||||||
// use the OES_element_index_uint extension if available
|
// use the OES_element_index_uint extension if available
|
||||||
if (this.hasOESElementIndexUint) {
|
if (this.hasOESElementIndexUint_) {
|
||||||
gl.getExtension('OES_element_index_uint');
|
gl.getExtension('OES_element_index_uint');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,9 +453,9 @@ class WebGLHelper extends Disposable {
|
|||||||
*/
|
*/
|
||||||
drawElements(start, end) {
|
drawElements(start, end) {
|
||||||
const gl = this.getGL();
|
const gl = this.getGL();
|
||||||
const elementType = this.hasOESElementIndexUint ?
|
const elementType = this.hasOESElementIndexUint_ ?
|
||||||
gl.UNSIGNED_INT : gl.UNSIGNED_SHORT;
|
gl.UNSIGNED_INT : gl.UNSIGNED_SHORT;
|
||||||
const elementSize = this.hasOESElementIndexUint ? 4 : 2;
|
const elementSize = this.hasOESElementIndexUint_ ? 4 : 2;
|
||||||
|
|
||||||
const numItems = end - start;
|
const numItems = end - start;
|
||||||
const offsetInBytes = start * elementSize;
|
const offsetInBytes = start * elementSize;
|
||||||
@@ -746,6 +747,16 @@ class WebGLHelper extends Disposable {
|
|||||||
handleWebGLContextRestored() {
|
handleWebGLContextRestored() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the `OES_element_index_uint` WebGL extension is enabled for this context.
|
||||||
|
* @return {boolean} If true, Uint16Array should be used for element array buffers
|
||||||
|
* instead of Uint8Array.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
getElementIndexUintEnabled() {
|
||||||
|
return this.hasOESElementIndexUint_;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: shutdown program
|
// TODO: shutdown program
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user