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

View File

@@ -232,3 +232,7 @@ Cannot determine IIIF Image API version from provided image information JSON.
### 62
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.

View File

@@ -23,7 +23,6 @@ export const WebGLWorkerMessageType = {
* @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 {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 {number} elementIndex Index from which render instructions will be read.
* @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 {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

View File

@@ -419,8 +419,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
/** @type import('./Layer').WebGLWorkerGenerateBuffersMessage */
const message = {
type: WebGLWorkerMessageType.GENERATE_BUFFERS,
renderInstructions: this.renderInstructions_.buffer,
useShortIndices: !this.helper.getElementIndexUintEnabled()
renderInstructions: this.renderInstructions_.buffer
};
// additional properties will be sent back as-is by the worker
message['projectionTransform'] = projectionTransform;

View File

@@ -2,8 +2,7 @@
* @module ol/webgl/Buffer
*/
import {STATIC_DRAW, STREAM_DRAW, DYNAMIC_DRAW} from '../webgl.js';
import {includes} from '../array.js';
import {ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, EXTENSIONS as WEBGL_EXTENSIONS} from '../webgl.js';
import {ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER} from '../webgl.js';
import {assert} from '../asserts.js';
/**
@@ -44,7 +43,7 @@ class WebGLArrayBuffer {
/**
* @private
* @type {Float32Array|Uint32Array|Uint16Array}
* @type {Float32Array|Uint32Array}
*/
this.array = null;
@@ -96,7 +95,7 @@ class WebGLArrayBuffer {
}
/**
* @return {Float32Array|Uint32Array|Uint16Array} Array.
* @return {Float32Array|Uint32Array} Array.
*/
getArray() {
return this.array;
@@ -113,15 +112,14 @@ class WebGLArrayBuffer {
/**
* Returns a typed array constructor based on the given buffer type
* @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) {
switch (type) {
case ARRAY_BUFFER:
return Float32Array;
case ELEMENT_ARRAY_BUFFER:
const hasExtension = includes(WEBGL_EXTENSIONS, 'OES_element_index_uint');
return hasExtension ? Uint32Array : Uint16Array;
return Uint32Array;
default:
return Float32Array;
}

View File

@@ -2,12 +2,10 @@
* @module ol/webgl/Helper
*/
import {getUid} from '../util.js';
import {EXTENSIONS as WEBGL_EXTENSIONS} from '../webgl.js';
import Disposable from '../Disposable.js';
import {includes} from '../array.js';
import {listen, unlistenAll} from '../events.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 {
create as createTransform,
@@ -19,6 +17,8 @@ import {
import {create, fromTransform} from '../vec/mat4.js';
import WebGLPostProcessingPass from './PostProcessingPass.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;
/**
* @type {boolean}
* @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');
}
assert(includes(WEBGL_EXTENSIONS, 'OES_element_index_uint'), 63);
gl.getExtension('OES_element_index_uint');
listen(this.canvas_, ContextEventType.LOST,
this.handleWebGLContextLost, this);
@@ -453,9 +445,8 @@ class WebGLHelper extends Disposable {
*/
drawElements(start, end) {
const gl = this.getGL();
const elementType = this.hasOESElementIndexUint_ ?
gl.UNSIGNED_INT : gl.UNSIGNED_SHORT;
const elementSize = this.hasOESElementIndexUint_ ? 4 : 2;
const elementType = gl.UNSIGNED_INT;
const elementSize = 4;
const numItems = end - start;
const offsetInBytes = start * elementSize;
@@ -747,16 +738,6 @@ class WebGLHelper extends Disposable {
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
/**

View File

@@ -16,12 +16,11 @@ onmessage = event => {
const renderInstructions = new Float32Array(received.renderInstructions);
const customAttributesCount = received.customAttributesCount || 0;
const instructionsCount = POINT_INSTRUCTIONS_COUNT + customAttributesCount;
const useShort = received.useShortIndices;
const elementsCount = renderInstructions.length / instructionsCount;
const indicesCount = elementsCount * 6;
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);
let bufferPositions = null;

View File

@@ -89,7 +89,7 @@ describe('ol.renderer.webgl.Layer', function() {
beforeEach(function() {
vertexBuffer = new Float32Array(100);
indexBuffer = new Uint16Array(100);
indexBuffer = new Uint32Array(100);
instructions = new Float32Array(100);
elementIndex = 3;

View File

@@ -2,7 +2,6 @@ import WebGLArrayBuffer, {getArrayClassForType} from '../../../../src/ol/webgl/B
import {
ARRAY_BUFFER,
ELEMENT_ARRAY_BUFFER,
EXTENSIONS as WEBGL_EXTENSIONS,
STATIC_DRAW,
STREAM_DRAW
} from '../../../../src/ol/webgl.js';
@@ -37,11 +36,6 @@ describe('ol.webgl.Buffer', function() {
expect(getArrayClassForType(ARRAY_BUFFER)).to.be(Float32Array);
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() {

View File

@@ -45,25 +45,6 @@ describe('ol/worker/webgl', function() {
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);
});
});
});