Comparing version 1.7.0 to 2.0.0
@@ -1,2 +0,2 @@ | ||
// Type definitions for regl 1.3.1 | ||
// Type definitions for regl 2.0.0 | ||
// Project: regl | ||
@@ -220,3 +220,3 @@ // Definitions by: Stepan Stolyarov <stepan.stolyarov@gmail.com>, David Schneider <github.com/davschne> | ||
/* Creates a vertex array object */ | ||
vao(attributes: REGL.AttributeState[]) : REGL.VertexArrayObject; | ||
vao(attributes: REGL.AttributeState[] | REGL.VertexArrayOptions) : REGL.VertexArrayObject; | ||
@@ -957,3 +957,3 @@ /* Events and listeners */ | ||
interface VertexArrayObject extends REGL.Resource { | ||
(attributes:REGL.AttributeState[]) : REGL.VertexArrayObject; | ||
(attributes:REGL.AttributeState[] | REGL.VertexArrayOptions) : REGL.VertexArrayObject; | ||
} | ||
@@ -1078,2 +1078,11 @@ | ||
interface VertexArrayOptions { | ||
attributes: AttributeState[]; | ||
elements?: REGL.Elements | REGL.ElementsOptions | REGL.ElementsData | null; | ||
count?:number; | ||
offset?:number; | ||
primitive?:PrimitiveType; | ||
instances?:number; | ||
} | ||
interface Texture extends Resource { | ||
@@ -1080,0 +1089,0 @@ readonly stats: { |
@@ -6,6 +6,17 @@ var check = require('./util/check') | ||
var isNDArrayLike = require('./util/is-ndarray') | ||
var primitives = require('./constants/primitives.json') | ||
var GL_FLOAT = 5126 | ||
var GL_ARRAY_BUFFER = 34962 | ||
var GL_ELEMENT_ARRAY_BUFFER = 34963 | ||
var VAO_OPTIONS = [ | ||
'attributes', | ||
'elements', | ||
'offset', | ||
'count', | ||
'primitive', | ||
'instances' | ||
] | ||
function AttributeRecord () { | ||
@@ -33,3 +44,5 @@ this.state = 0 | ||
stats, | ||
bufferState) { | ||
bufferState, | ||
elementState, | ||
drawState) { | ||
var NUM_ATTRIBUTES = limits.maxAttributes | ||
@@ -107,2 +120,3 @@ var attributeBindings = new Array(NUM_ATTRIBUTES) | ||
gl.enableVertexAttribArray(i) | ||
binding.buffer.bind() | ||
gl.vertexAttribPointer(i, binding.size, binding.type, binding.normalized, binding.stride, binding.offfset) | ||
@@ -117,2 +131,7 @@ if (exti && binding.divisor) { | ||
} | ||
if (drawState.elements) { | ||
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, drawState.elements.buffer.buffer) | ||
} else { | ||
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, null) | ||
} | ||
} | ||
@@ -131,2 +150,8 @@ state.currentVAO = vao | ||
this.attributes = [] | ||
this.elements = null | ||
this.ownsElements = false | ||
this.count = 0 | ||
this.offset = 0 | ||
this.instances = -1 | ||
this.primitive = 4 | ||
var extension = extVAO() | ||
@@ -162,2 +187,8 @@ if (extension) { | ||
} | ||
var elements = elementState.getElements(this.elements) | ||
if (elements) { | ||
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, elements.buffer.buffer) | ||
} else { | ||
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, null) | ||
} | ||
} | ||
@@ -184,2 +215,7 @@ | ||
} | ||
if (this.ownsElements) { | ||
this.elements.destroy() | ||
this.elements = null | ||
this.ownsElements = false | ||
} | ||
if (vaoSet[this.id]) { | ||
@@ -204,4 +240,76 @@ delete vaoSet[this.id] | ||
function updateVAO (attributes) { | ||
check(Array.isArray(attributes), 'arguments to vertex array constructor must be an array') | ||
function updateVAO (options) { | ||
var attributes | ||
if (Array.isArray(options)) { | ||
attributes = options | ||
if (vao.elements && vao.ownsElements) { | ||
vao.elements.destroy() | ||
} | ||
vao.elements = null | ||
vao.ownsElements = false | ||
vao.offset = 0 | ||
vao.count = 0 | ||
vao.instances = -1 | ||
vao.primitive = 4 | ||
} else { | ||
check(typeof options === 'object', 'invalid arguments for create vao') | ||
check('attributes' in options, 'must specify attributes for vao') | ||
if (options.elements) { | ||
var elements = options.elements | ||
if (vao.ownsElements) { | ||
if (typeof elements === 'function' && elements._reglType === 'elements') { | ||
vao.elements.destroy() | ||
vao.ownsElements = false | ||
} else { | ||
vao.elements(elements) | ||
vao.ownsElements = false | ||
} | ||
} else if (elementState.getElements(options.elements)) { | ||
vao.elements = options.elements | ||
vao.ownsElements = false | ||
} else { | ||
vao.elements = elementState.create(options.elements) | ||
vao.ownsElements = true | ||
} | ||
} else { | ||
vao.elements = null | ||
vao.ownsElements = false | ||
} | ||
attributes = options.attributes | ||
// set default vao | ||
vao.offset = 0 | ||
vao.count = -1 | ||
vao.instances = -1 | ||
vao.primitive = 4 | ||
// copy element properties | ||
if (vao.elements) { | ||
vao.count = vao.elements._elements.vertCount | ||
vao.primitive = vao.elements._elements.primType | ||
} | ||
if ('offset' in options) { | ||
vao.offset = options.offset | 0 | ||
} | ||
if ('count' in options) { | ||
vao.count = options.count | 0 | ||
} | ||
if ('instances' in options) { | ||
vao.instances = options.instances | 0 | ||
} | ||
if ('primitive' in options) { | ||
check(options.primitive in primitives, 'bad primitive type: ' + options.primitive) | ||
vao.primitive = primitives[options.primitive] | ||
} | ||
check.optional(() => { | ||
var keys = Object.keys(options) | ||
for (var i = 0; i < keys.length; ++i) { | ||
check(VAO_OPTIONS.indexOf(keys[i]) >= 0, 'invalid option for vao: "' + keys[i] + '" valid options are ' + VAO_OPTIONS) | ||
} | ||
}) | ||
check(Array.isArray(attributes), 'attributes must be an array') | ||
} | ||
check(attributes.length < NUM_ATTRIBUTES, 'too many attributes') | ||
@@ -300,2 +408,9 @@ check(attributes.length > 0, 'must specify at least one attribute') | ||
vao.buffers.length = 0 | ||
if (vao.ownsElements) { | ||
vao.elements.destroy() | ||
vao.elements = null | ||
vao.ownsElements = false | ||
} | ||
vao.destroy() | ||
@@ -302,0 +417,0 @@ } |
@@ -72,3 +72,3 @@ var check = require('./util/check') | ||
} else if (Array.isArray(x)) { | ||
return new DynamicVariable(DYN_ARRAY, x.map((y, i) => unbox(y, path + '[' + i + ']'))) | ||
return new DynamicVariable(DYN_ARRAY, x.map(function (y, i) { return unbox(y, path + '[' + i + ']') })) | ||
} else if (x instanceof DynamicVariable) { | ||
@@ -75,0 +75,0 @@ return x |
{ | ||
"name": "regl", | ||
"version": "1.7.0", | ||
"version": "2.0.0", | ||
"description": "regl is a fast functional WebGL framework.", | ||
@@ -5,0 +5,0 @@ "main": "dist/regl.js", |
@@ -1,2 +0,2 @@ | ||
// Type definitions for regl 1.3.1 | ||
// Type definitions for regl 2.0.0 | ||
// Project: regl | ||
@@ -220,3 +220,3 @@ // Definitions by: Stepan Stolyarov <stepan.stolyarov@gmail.com>, David Schneider <github.com/davschne> | ||
/* Creates a vertex array object */ | ||
vao(attributes: REGL.AttributeState[]) : REGL.VertexArrayObject; | ||
vao(attributes: REGL.AttributeState[] | REGL.VertexArrayOptions) : REGL.VertexArrayObject; | ||
@@ -957,3 +957,3 @@ /* Events and listeners */ | ||
interface VertexArrayObject extends REGL.Resource { | ||
(attributes:REGL.AttributeState[]) : REGL.VertexArrayObject; | ||
(attributes:REGL.AttributeState[] | REGL.VertexArrayOptions) : REGL.VertexArrayObject; | ||
} | ||
@@ -1078,2 +1078,11 @@ | ||
interface VertexArrayOptions { | ||
attributes: AttributeState[]; | ||
elements?: REGL.Elements | REGL.ElementsOptions | REGL.ElementsData | null; | ||
count?:number; | ||
offset?:number; | ||
primitive?:PrimitiveType; | ||
instances?:number; | ||
} | ||
interface Texture extends Resource { | ||
@@ -1080,0 +1089,0 @@ readonly stats: { |
@@ -94,2 +94,3 @@ var check = require('./lib/util/check') | ||
destroyBuffer) | ||
var elementState = wrapElements(gl, extensions, bufferState, stats) | ||
var attributeState = wrapAttributes( | ||
@@ -100,7 +101,8 @@ gl, | ||
stats, | ||
bufferState) | ||
bufferState, | ||
elementState, | ||
drawState) | ||
function destroyBuffer (buffer) { | ||
return attributeState.destroyBuffer(buffer) | ||
} | ||
var elementState = wrapElements(gl, extensions, bufferState, stats) | ||
var shaderState = wrapShaders(gl, stringStore, stats, config) | ||
@@ -263,6 +265,6 @@ var textureState = wrapTextures( | ||
renderbufferState.clear() | ||
attributeState.clear() | ||
textureState.clear() | ||
elementState.clear() | ||
bufferState.clear() | ||
attributeState.clear() | ||
@@ -269,0 +271,0 @@ if (timer) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1210180
29750