Webgl / remove handling of element_index_uint extension

From now on we will assume this extension is always enabled.

An error message have been added in the unlikely scenario of a lack
of support.
This commit is contained in:
Olivier Guyot
2019-06-05 14:36:02 +02:00
parent 87d5f4c8bc
commit 2412fe0211
9 changed files with 20 additions and 65 deletions
+4
View File
@@ -232,3 +232,7 @@ Cannot determine IIIF Image API version from provided image information JSON.
### 62 ### 62
A `WebGLArrayBuffer` must either be of type `ELEMENT_ARRAY_BUFFER` or `ARRAY_BUFFER`. A `WebGLArrayBuffer` must either be of type `ELEMENT_ARRAY_BUFFER` or `ARRAY_BUFFER`.
### 63
Support for the `OES_element_index_uint` WebGL extension is mandatory for WebGL layers.
+1 -2
View File
@@ -23,7 +23,6 @@ export const WebGLWorkerMessageType = {
* @property {ArrayBuffer} [vertexBuffer] Vertices array raw binary buffer (sent by the worker). * @property {ArrayBuffer} [vertexBuffer] Vertices array raw binary buffer (sent by the worker).
* @property {ArrayBuffer} [indexBuffer] Indices array raw binary buffer (sent by the worker). * @property {ArrayBuffer} [indexBuffer] Indices array raw binary buffer (sent by the worker).
* @property {number} [customAttributesCount] Amount of custom attributes count in the render instructions. * @property {number} [customAttributesCount] Amount of custom attributes count in the render instructions.
* @property {boolean} [useShortIndices] If true, Uint16Array will be used instead of Uint32Array for index buffers.
*/ */
/** /**
@@ -158,7 +157,7 @@ function writeCustomAttrs(buffer, pos, customAttrs) {
* @param {Float32Array} instructions Array of render instructions for points. * @param {Float32Array} instructions Array of render instructions for points.
* @param {number} elementIndex Index from which render instructions will be read. * @param {number} elementIndex Index from which render instructions will be read.
* @param {Float32Array} vertexBuffer Buffer in the form of a typed array. * @param {Float32Array} vertexBuffer Buffer in the form of a typed array.
* @param {Uint16Array|Uint32Array} indexBuffer Buffer in the form of a typed array. * @param {Uint32Array} indexBuffer Buffer in the form of a typed array.
* @param {BufferPositions} [bufferPositions] Buffer write positions; if not specified, positions will be set at 0. * @param {BufferPositions} [bufferPositions] Buffer write positions; if not specified, positions will be set at 0.
* @param {number} [count] Amount of render instructions that will be read. Default value is POINT_INSTRUCTIONS_COUNT * @param {number} [count] Amount of render instructions that will be read. Default value is POINT_INSTRUCTIONS_COUNT
* but a higher value can be provided; all values beyond the default count will be put in the vertices buffer as * but a higher value can be provided; all values beyond the default count will be put in the vertices buffer as
+1 -2
View File
@@ -419,8 +419,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
/** @type import('./Layer').WebGLWorkerGenerateBuffersMessage */ /** @type import('./Layer').WebGLWorkerGenerateBuffersMessage */
const message = { const message = {
type: WebGLWorkerMessageType.GENERATE_BUFFERS, type: WebGLWorkerMessageType.GENERATE_BUFFERS,
renderInstructions: this.renderInstructions_.buffer, renderInstructions: this.renderInstructions_.buffer
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;
+5 -7
View File
@@ -2,8 +2,7 @@
* @module ol/webgl/Buffer * @module ol/webgl/Buffer
*/ */
import {STATIC_DRAW, STREAM_DRAW, DYNAMIC_DRAW} from '../webgl.js'; import {STATIC_DRAW, STREAM_DRAW, DYNAMIC_DRAW} from '../webgl.js';
import {includes} from '../array.js'; import {ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER} from '../webgl.js';
import {ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, EXTENSIONS as WEBGL_EXTENSIONS} from '../webgl.js';
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
/** /**
@@ -44,7 +43,7 @@ class WebGLArrayBuffer {
/** /**
* @private * @private
* @type {Float32Array|Uint32Array|Uint16Array} * @type {Float32Array|Uint32Array}
*/ */
this.array = null; this.array = null;
@@ -96,7 +95,7 @@ class WebGLArrayBuffer {
} }
/** /**
* @return {Float32Array|Uint32Array|Uint16Array} Array. * @return {Float32Array|Uint32Array} Array.
*/ */
getArray() { getArray() {
return this.array; return this.array;
@@ -113,15 +112,14 @@ class WebGLArrayBuffer {
/** /**
* Returns a typed array constructor based on the given buffer type * Returns a typed array constructor based on the given buffer type
* @param {number} type Buffer type, either ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER. * @param {number} type Buffer type, either ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER.
* @returns {Float32ArrayConstructor|Uint16ArrayConstructor|Uint32ArrayConstructor} The typed array class to use for this buffer. * @returns {Float32ArrayConstructor|Uint32ArrayConstructor} The typed array class to use for this buffer.
*/ */
export function getArrayClassForType(type) { export function getArrayClassForType(type) {
switch (type) { switch (type) {
case ARRAY_BUFFER: case ARRAY_BUFFER:
return Float32Array; return Float32Array;
case ELEMENT_ARRAY_BUFFER: case ELEMENT_ARRAY_BUFFER:
const hasExtension = includes(WEBGL_EXTENSIONS, 'OES_element_index_uint'); return Uint32Array;
return hasExtension ? Uint32Array : Uint16Array;
default: default:
return Float32Array; return Float32Array;
} }
+7 -26
View File
@@ -2,12 +2,10 @@
* @module ol/webgl/Helper * @module ol/webgl/Helper
*/ */
import {getUid} from '../util.js'; import {getUid} from '../util.js';
import {EXTENSIONS as WEBGL_EXTENSIONS} from '../webgl.js';
import Disposable from '../Disposable.js'; import Disposable from '../Disposable.js';
import {includes} from '../array.js';
import {listen, unlistenAll} from '../events.js'; import {listen, unlistenAll} from '../events.js';
import {clear} from '../obj.js'; import {clear} from '../obj.js';
import {TEXTURE_2D, TEXTURE_WRAP_S, TEXTURE_WRAP_T} from '../webgl.js'; import {TEXTURE_2D, TEXTURE_WRAP_S, TEXTURE_WRAP_T, EXTENSIONS as WEBGL_EXTENSIONS} from '../webgl.js';
import ContextEventType from '../webgl/ContextEventType.js'; import ContextEventType from '../webgl/ContextEventType.js';
import { import {
create as createTransform, create as createTransform,
@@ -19,6 +17,8 @@ import {
import {create, fromTransform} from '../vec/mat4.js'; import {create, fromTransform} from '../vec/mat4.js';
import WebGLPostProcessingPass from './PostProcessingPass.js'; import WebGLPostProcessingPass from './PostProcessingPass.js';
import {getContext} from '../webgl.js'; import {getContext} from '../webgl.js';
import {includes} from '../array.js';
import {assert} from '../asserts.js';
/** /**
@@ -258,16 +258,8 @@ class WebGLHelper extends Disposable {
*/ */
this.currentProgram_ = null; this.currentProgram_ = null;
/** assert(includes(WEBGL_EXTENSIONS, 'OES_element_index_uint'), 63);
* @type {boolean} gl.getExtension('OES_element_index_uint');
* @private
*/
this.hasOESElementIndexUint_ = includes(WEBGL_EXTENSIONS, 'OES_element_index_uint');
// use the OES_element_index_uint extension if available
if (this.hasOESElementIndexUint_) {
gl.getExtension('OES_element_index_uint');
}
listen(this.canvas_, ContextEventType.LOST, listen(this.canvas_, ContextEventType.LOST,
this.handleWebGLContextLost, this); this.handleWebGLContextLost, this);
@@ -453,9 +445,8 @@ class WebGLHelper extends Disposable {
*/ */
drawElements(start, end) { drawElements(start, end) {
const gl = this.getGL(); const gl = this.getGL();
const elementType = this.hasOESElementIndexUint_ ? const elementType = gl.UNSIGNED_INT;
gl.UNSIGNED_INT : gl.UNSIGNED_SHORT; const elementSize = 4;
const elementSize = this.hasOESElementIndexUint_ ? 4 : 2;
const numItems = end - start; const numItems = end - start;
const offsetInBytes = start * elementSize; const offsetInBytes = start * elementSize;
@@ -747,16 +738,6 @@ 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
/** /**
+1 -2
View File
@@ -16,12 +16,11 @@ onmessage = event => {
const renderInstructions = new Float32Array(received.renderInstructions); const renderInstructions = new Float32Array(received.renderInstructions);
const customAttributesCount = received.customAttributesCount || 0; const customAttributesCount = received.customAttributesCount || 0;
const instructionsCount = POINT_INSTRUCTIONS_COUNT + customAttributesCount; const instructionsCount = POINT_INSTRUCTIONS_COUNT + customAttributesCount;
const useShort = received.useShortIndices;
const elementsCount = renderInstructions.length / instructionsCount; const elementsCount = renderInstructions.length / instructionsCount;
const indicesCount = elementsCount * 6; const indicesCount = elementsCount * 6;
const verticesCount = elementsCount * 4 * (POINT_VERTEX_STRIDE + customAttributesCount); const verticesCount = elementsCount * 4 * (POINT_VERTEX_STRIDE + customAttributesCount);
const indexBuffer = useShort ? new Uint16Array(indicesCount) : new Uint32Array(indicesCount); const indexBuffer = new Uint32Array(indicesCount);
const vertexBuffer = new Float32Array(verticesCount); const vertexBuffer = new Float32Array(verticesCount);
let bufferPositions = null; let bufferPositions = null;
+1 -1
View File
@@ -89,7 +89,7 @@ describe('ol.renderer.webgl.Layer', function() {
beforeEach(function() { beforeEach(function() {
vertexBuffer = new Float32Array(100); vertexBuffer = new Float32Array(100);
indexBuffer = new Uint16Array(100); indexBuffer = new Uint32Array(100);
instructions = new Float32Array(100); instructions = new Float32Array(100);
elementIndex = 3; elementIndex = 3;
-6
View File
@@ -2,7 +2,6 @@ import WebGLArrayBuffer, {getArrayClassForType} from '../../../../src/ol/webgl/B
import { import {
ARRAY_BUFFER, ARRAY_BUFFER,
ELEMENT_ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER,
EXTENSIONS as WEBGL_EXTENSIONS,
STATIC_DRAW, STATIC_DRAW,
STREAM_DRAW STREAM_DRAW
} from '../../../../src/ol/webgl.js'; } from '../../../../src/ol/webgl.js';
@@ -37,11 +36,6 @@ describe('ol.webgl.Buffer', function() {
expect(getArrayClassForType(ARRAY_BUFFER)).to.be(Float32Array); expect(getArrayClassForType(ARRAY_BUFFER)).to.be(Float32Array);
expect(getArrayClassForType(ELEMENT_ARRAY_BUFFER)).to.be(Uint32Array); expect(getArrayClassForType(ELEMENT_ARRAY_BUFFER)).to.be(Uint32Array);
}); });
it('returns the correct typed array constructor (without OES uint extension)', function() {
WEBGL_EXTENSIONS.length = 0;
expect(getArrayClassForType(ELEMENT_ARRAY_BUFFER)).to.be(Uint16Array);
});
}); });
describe('populate methods', function() { describe('populate methods', function() {
-19
View File
@@ -45,25 +45,6 @@ describe('ol/worker/webgl', function() {
worker.postMessage(message); worker.postMessage(message);
}); });
it('responds with buffer data (fallback to Uint16Array)', function(done) {
worker.addEventListener('error', done);
worker.addEventListener('message', function(event) {
expect(event.data.indexBuffer).to.eql(Uint16Array.BYTES_PER_ELEMENT * 6);
done();
});
const instructions = new Float32Array(POINT_INSTRUCTIONS_COUNT);
const message = {
type: WebGLWorkerMessageType.GENERATE_BUFFERS,
renderInstructions: instructions,
useShortIndices: true
};
worker.postMessage(message);
});
}); });
}); });