Comparing version 0.3.0 to 0.4.0
# Release notes | ||
## Planned | ||
* Add a mechanism for requiring/selectively disabling extensions | ||
* Upgrade vertex pointer format, allow for implicit conversion from arrays | ||
* Improve validation of vertex attributes | ||
* Refactor attributeState, some names are inconsistent and code is too complex | ||
* Change buffer and texture APIs to separate data from rest of options (or maybe not?) | ||
* Add in place update methods to buffers and textures | ||
* Add support for polling buffers and animated GIFs (useful for web audio) | ||
* Cubic framebuffer objects | ||
* More unit tests, improve code coverage | ||
* Benchmark suite | ||
* Optimize generated code | ||
* Optimize bundle size, remove string constants | ||
* Support more DDS texture formats (HDR, PVRTC, etc.) | ||
* Build a website (@freeman-lab is on it!) | ||
* Recipe book/example set | ||
+ Minecraft example | ||
+ Globe | ||
+ Tile based 2D rendering | ||
+ Compound scene | ||
+ Shadow mapping | ||
+ Stencil shadows | ||
+ Turing patterns | ||
+ Spring/cloth physics | ||
+ Asset loading (obj, ply, etc.) | ||
## Next | ||
## 0.4.0 | ||
* Circle CI finally passes! | ||
* Use numeric ids instead of strings for shader sources | ||
* Shader error messages are better | ||
* Browserify transform to remove all runtime checks | ||
* Shader linking is deferred until draw call, enables partial shaders in scope | ||
* Report errors for missing attributes, uniforms and vertex count | ||
## 0.3.0 | ||
* added renderbuffers (via regl.renderbuffer) | ||
@@ -6,0 +44,0 @@ * added framebuffer objects (via regl.framebuffer) |
var glTypes = require('./constants/dtypes.json') | ||
var check = require('./util/check') | ||
var GL_FLOAT = 5126 | ||
function AttributeRecord () { | ||
this.pointer = false | ||
module.exports = function wrapAttributeState ( | ||
gl, | ||
extensions, | ||
limits, | ||
bufferState, | ||
stringStore) { | ||
var attributeState = {} | ||
this.x = 0.0 | ||
this.y = 0.0 | ||
this.z = 0.0 | ||
this.w = 0.0 | ||
function AttributeRecord () { | ||
this.pointer = false | ||
this.buffer = null | ||
this.size = 0 | ||
this.normalized = false | ||
this.type = GL_FLOAT | ||
this.offset = 0 | ||
this.stride = 0 | ||
this.divisor = 0 | ||
} | ||
this.x = 0.0 | ||
this.y = 0.0 | ||
this.z = 0.0 | ||
this.w = 0.0 | ||
Object.assign(AttributeRecord.prototype, { | ||
equals: function (other, size) { | ||
if (!this.pointer) { | ||
return !other.pointer && | ||
this.x === other.x && | ||
this.y === other.y && | ||
this.z === other.z && | ||
this.w === other.w | ||
this.buffer = null | ||
this.size = 0 | ||
this.normalized = false | ||
this.type = GL_FLOAT | ||
this.offset = 0 | ||
this.stride = 0 | ||
this.divisor = 0 | ||
} | ||
function attributeRecordsEqual (left, right, size) { | ||
if (!left.pointer) { | ||
return !right.pointer && | ||
left.x === right.x && | ||
left.y === right.y && | ||
left.z === right.z && | ||
left.w === right.w | ||
} else { | ||
return other.pointer && | ||
this.buffer === other.buffer && | ||
this.size === size && | ||
this.normalized === other.normalized && | ||
this.type === other.type && | ||
this.offset === other.offset && | ||
this.stride === other.stride && | ||
this.divisor === other.divisor | ||
return right.pointer && | ||
left.buffer === right.buffer && | ||
left.size === size && | ||
left.normalized === right.normalized && | ||
left.type === right.type && | ||
left.offset === right.offset && | ||
left.stride === right.stride && | ||
left.divisor === right.divisor | ||
} | ||
}, | ||
} | ||
set: function (other, size) { | ||
var pointer = this.pointer = other.pointer | ||
function setAttributeRecord (left, right, size) { | ||
var pointer = left.pointer = right.pointer | ||
if (pointer) { | ||
this.buffer = other.buffer | ||
this.size = size | ||
this.normalized = other.normalized | ||
this.type = other.type | ||
this.offset = other.offset | ||
this.stride = other.stride | ||
this.divisor = other.divisor | ||
left.buffer = right.buffer | ||
left.size = size | ||
left.normalized = right.normalized | ||
left.type = right.type | ||
left.offset = right.offset | ||
left.stride = right.stride | ||
left.divisor = right.divisor | ||
} else { | ||
this.x = other.x | ||
this.y = other.y | ||
this.z = other.z | ||
this.w = other.w | ||
left.x = right.x | ||
left.y = right.y | ||
left.z = right.z | ||
left.w = right.w | ||
} | ||
} | ||
}) | ||
module.exports = function wrapAttributeState (gl, extensions, limits, bufferState) { | ||
var attributeState = {} | ||
var NUM_ATTRIBUTES = limits.maxAttributes | ||
@@ -70,93 +74,18 @@ var attributeBindings = new Array(NUM_ATTRIBUTES) | ||
function AttributeStack () { | ||
var records = new Array(16) | ||
for (var i = 0; i < 16; ++i) { | ||
records[i] = new AttributeRecord() | ||
} | ||
this.records = records | ||
this.top = 0 | ||
function AttributeStack (name) { | ||
this.records = [] | ||
this.name = name | ||
} | ||
function pushAttributeStack (stack) { | ||
function stackTop (stack) { | ||
var records = stack.records | ||
var top = stack.top | ||
while (records.length - 1 <= top) { | ||
records.push(new AttributeRecord()) | ||
} | ||
return records[++stack.top] | ||
return records[records.length - 1] | ||
} | ||
Object.assign(AttributeStack.prototype, { | ||
pushVec: function (x, y, z, w) { | ||
var head = pushAttributeStack(this) | ||
head.pointer = false | ||
head.x = x | ||
head.y = y | ||
head.z = z | ||
head.w = w | ||
}, | ||
pushPtr: function ( | ||
buffer, | ||
size, | ||
offset, | ||
stride, | ||
divisor, | ||
normalized, | ||
type) { | ||
var head = pushAttributeStack(this) | ||
head.pointer = true | ||
head.buffer = buffer | ||
head.size = size | ||
head.offset = offset | ||
head.stride = stride | ||
head.divisor = divisor | ||
head.normalized = normalized | ||
head.type = type | ||
}, | ||
pushDyn: function (data) { | ||
if (typeof data === 'number') { | ||
this.pushVec(data, 0, 0, 0) | ||
} else if (Array.isArray(data)) { | ||
this.pushVec(data[0], data[1], data[2], data[3]) | ||
} else { | ||
var buffer = bufferState.getBuffer(data) | ||
var size = 0 | ||
var stride = 0 | ||
var offset = 0 | ||
var divisor = 0 | ||
var normalized = false | ||
var type = GL_FLOAT | ||
if (!buffer) { | ||
buffer = bufferState.getBuffer(data.buffer) | ||
size = data.size || 0 | ||
stride = data.stride || 0 | ||
offset = data.offset || 0 | ||
divisor = data.divisor || 0 | ||
normalized = data.normalized || false | ||
type = buffer.dtype | ||
if ('type' in data) { | ||
type = glTypes[data.type] | ||
} | ||
} else { | ||
type = buffer.dtype | ||
} | ||
this.pushPtr(buffer, size, offset, stride, divisor, normalized, type) | ||
} | ||
}, | ||
pop: function () { | ||
this.top -= 1 | ||
} | ||
}) | ||
// =================================================== | ||
// BIND AN ATTRIBUTE | ||
// =================================================== | ||
function bindAttribute (index, current, next, size) { | ||
size = next.size || size | ||
if (current.equals(next, size)) { | ||
function bindAttributeRecord (index, current, next, insize) { | ||
var size = next.size || insize | ||
if (attributeRecordsEqual(current, next, size)) { | ||
return | ||
@@ -188,5 +117,9 @@ } | ||
} | ||
current.set(next, size) | ||
setAttributeRecord(current, next, size) | ||
} | ||
function bindAttribute (index, current, attribStack, size) { | ||
bindAttributeRecord(index, current, stackTop(attribStack), size) | ||
} | ||
// =================================================== | ||
@@ -196,14 +129,87 @@ // DEFINE A NEW ATTRIBUTE | ||
function defAttribute (name) { | ||
if (name in attributeState) { | ||
return | ||
var id = stringStore.id(name) | ||
var result = attributeState[id] | ||
if (!result) { | ||
result = attributeState[id] = new AttributeStack(name) | ||
} | ||
attributeState[name] = new AttributeStack() | ||
return result | ||
} | ||
function createAttributeBox (name) { | ||
var stack = [new AttributeRecord()] | ||
check.saveCommandRef(stack) | ||
function alloc (data) { | ||
var box | ||
if (stack.length <= 0) { | ||
box = new AttributeRecord() | ||
} else { | ||
box = stack.pop() | ||
} | ||
if (typeof data === 'number') { | ||
box.pointer = false | ||
box.x = data | ||
box.y = 0 | ||
box.z = 0 | ||
box.w = 0 | ||
} else if (Array.isArray(data)) { | ||
box.pointer = false | ||
box.x = data[0] | ||
box.y = data[1] | ||
box.z = data[2] | ||
box.w = data[3] | ||
} else { | ||
var buffer = bufferState.getBuffer(data) | ||
var size = 0 | ||
var stride = 0 | ||
var offset = 0 | ||
var divisor = 0 | ||
var normalized = false | ||
var type = GL_FLOAT | ||
if (!buffer) { | ||
buffer = bufferState.getBuffer(data.buffer) | ||
check(buffer, 'missing or invalid buffer for attribute "' + | ||
name + '" called from command ' + box._commandRef) | ||
size = data.size || 0 | ||
stride = data.stride || 0 | ||
offset = data.offset || 0 | ||
divisor = data.divisor || 0 | ||
normalized = data.normalized || false | ||
type = buffer.dtype | ||
if ('type' in data) { | ||
type = glTypes[data.type] | ||
} | ||
} else { | ||
type = buffer.dtype | ||
} | ||
box.pointer = true | ||
box.buffer = buffer | ||
box.size = size | ||
box.offset = offset | ||
box.stride = stride | ||
box.divisor = divisor | ||
box.normalized = normalized | ||
box.type = type | ||
} | ||
return box | ||
} | ||
function free (box) { | ||
stack.push(box) | ||
} | ||
return { | ||
alloc: alloc, | ||
free: free | ||
} | ||
} | ||
return { | ||
bindings: attributeBindings, | ||
attributes: attributeState, | ||
bind: bindAttribute, | ||
def: defAttribute | ||
bindRecord: bindAttributeRecord, | ||
def: defAttribute, | ||
box: createAttributeBox, | ||
state: attributeState | ||
} | ||
} |
// Array and element buffer creation | ||
var check = require('./check') | ||
var isTypedArray = require('./is-typed-array') | ||
var isNDArrayLike = require('./is-ndarray') | ||
var check = require('./util/check') | ||
var isTypedArray = require('./util/is-typed-array') | ||
var isNDArrayLike = require('./util/is-ndarray') | ||
var arrayTypes = require('./constants/arraytypes.json') | ||
var bufferTypes = require('./constants/dtypes.json') | ||
var values = require('./values') | ||
var values = require('./util/values') | ||
@@ -9,0 +9,0 @@ var GL_STATIC_DRAW = 35044 |
@@ -1,9 +0,11 @@ | ||
var check = require('./check') | ||
var createEnvironment = require('./codegen') | ||
var check = require('./util/check') | ||
var createEnvironment = require('./util/codegen') | ||
var primTypes = require('./constants/primitives.json') | ||
var glTypes = require('./constants/dtypes.json') | ||
var GL_ELEMENT_ARRAY_BUFFER = 34963 | ||
var GL_FRAGMENT_SHADER = 35632 | ||
var GL_VERTEX_SHADER = 35633 | ||
var GL_FLOAT = 5126 | ||
@@ -188,2 +190,3 @@ var GL_FLOAT_VEC2 = 35664 | ||
gl, | ||
stringStore, | ||
extensions, | ||
@@ -244,7 +247,7 @@ limits, | ||
program.attributes.forEach(function (attribute) { | ||
var STACK = link(attributeState.attributes[attribute.name]) | ||
var STACK = link(attributeState.def(attribute.name)) | ||
draw(BIND_ATTRIBUTE, '(', | ||
attribute.location, ',', | ||
link(attributeState.bindings[attribute.location]), ',', | ||
STACK, '.records[', STACK, '.top]', ',', | ||
STACK, ',', | ||
typeLength(attribute.info.type), ');') | ||
@@ -256,6 +259,6 @@ }) | ||
var LOCATION = link(uniform.location) | ||
var STACK = link(uniformState.uniforms[uniform.name]) | ||
var STACK = link(uniformState.def(uniform.name)) | ||
var TOP = STACK + '[' + STACK + '.length-1]' | ||
if (uniform.info.type === GL_SAMPLER_2D || | ||
uniform.info.type === GL_SAMPLER_CUBE) { | ||
var type = uniform.info.type | ||
if (type === GL_SAMPLER_2D || type === GL_SAMPLER_CUBE) { | ||
var TEX_VALUE = def(TOP + '._texture') | ||
@@ -265,3 +268,3 @@ TEXTURE_UNIFORMS.push(TEX_VALUE) | ||
} else { | ||
draw(setUniformString(GL, uniform.info.type, LOCATION, TOP)) | ||
draw(setUniformString(GL, type, LOCATION, TOP)) | ||
} | ||
@@ -316,2 +319,3 @@ }) | ||
'if(', CUR_ELEMENTS, '){', | ||
CUR_ELEMENTS, '.bind();', | ||
GL, '.drawElements(', | ||
@@ -321,3 +325,3 @@ CUR_PRIMITIVE, ',', | ||
CUR_ELEMENTS, '.type,', | ||
CUR_OFFSET, ');}', | ||
CUR_OFFSET, ');', | ||
'}else{', | ||
@@ -327,3 +331,3 @@ GL, '.drawArrays(', | ||
CUR_OFFSET, ',', | ||
CUR_COUNT, ');}') | ||
CUR_COUNT, ');}}') | ||
} | ||
@@ -357,2 +361,3 @@ | ||
var BIND_ATTRIBUTE = link(attributeState.bind) | ||
var BIND_ATTRIBUTE_RECORD = link(attributeState.bindRecord) | ||
var FRAME_STATE = link(frameState) | ||
@@ -422,5 +427,8 @@ var FRAMEBUFFER_STATE = link(framebufferState) | ||
function findInfo (list, name) { | ||
return list.find(function (item) { | ||
return item.name === name | ||
}) | ||
for (var i = 0; i < list.length; ++i) { | ||
if (list[i].name === name) { | ||
return list[i] | ||
} | ||
} | ||
return null | ||
} | ||
@@ -441,6 +449,6 @@ | ||
var LOCATION = link(uniform.location) | ||
var STACK = link(uniformState.uniforms[uniform.name]) | ||
var STACK = link(uniformState.def(uniform.name)) | ||
var TOP = STACK + '[' + STACK + '.length-1]' | ||
if (uniform.info.type === GL_SAMPLER_2D || | ||
uniform.info.type === GL_SAMPLER_CUBE) { | ||
var type = uniform.info.type | ||
if (type === GL_SAMPLER_2D || type === GL_SAMPLER_CUBE) { | ||
var TEX_VALUE = def(TOP + '._texture') | ||
@@ -450,3 +458,3 @@ batch(setUniformString(GL, GL_INT, LOCATION, TEX_VALUE + '.bind()')) | ||
} else { | ||
batch(setUniformString(GL, uniform.info.type, LOCATION, TOP)) | ||
batch(setUniformString(GL, type, LOCATION, TOP)) | ||
} | ||
@@ -459,10 +467,10 @@ }) | ||
program.attributes.forEach(function (attribute) { | ||
if (attributes.name in attributes) { | ||
if (attribute.name in attributes) { | ||
return | ||
} | ||
var STACK = link(attributeState.attributes[attribute.name]) | ||
var STACK = link(attributeState.def(attribute.name)) | ||
batch(BIND_ATTRIBUTE, '(', | ||
attribute.location, ',', | ||
link(attributeState.bindings[attribute.location]), ',', | ||
STACK, '.records[', STACK, '.top]', ',', | ||
STACK, ',', | ||
typeLength(attribute.info.type), ');') | ||
@@ -476,7 +484,4 @@ }) | ||
batch( | ||
'if(', CUR_ELEMENTS, '){', | ||
GL, '.bindBuffer(', GL_ELEMENT_ARRAY_BUFFER, ',', CUR_ELEMENTS, '.buffer.buffer);', | ||
'}else{', | ||
GL, '.bindBuffer(', GL_ELEMENT_ARRAY_BUFFER, ',null);', | ||
'}') | ||
'if(', CUR_ELEMENTS, ')', | ||
GL, '.bindBuffer(', GL_ELEMENT_ARRAY_BUFFER, ',', CUR_ELEMENTS, '.buffer.buffer);') | ||
} | ||
@@ -659,6 +664,7 @@ | ||
case 'primitives': | ||
case 'primitive': | ||
case 'offset': | ||
case 'count': | ||
case 'elements': | ||
case 'instances': | ||
break | ||
@@ -717,7 +723,11 @@ | ||
} | ||
batch(BIND_ATTRIBUTE, '(', | ||
var BOX = link(attributeState.box(attribute)) | ||
var ATTRIB_VALUE = dyn(attributes[attribute]) | ||
var RECORD = def(BOX + '.alloc(' + ATTRIB_VALUE + ')') | ||
batch(BIND_ATTRIBUTE_RECORD, '(', | ||
data.location, ',', | ||
link(attribute.bindings[data.location]), ',', | ||
dyn(attributes[attribute]), ',', | ||
link(attributeState.bindings[data.location]), ',', | ||
RECORD, ',', | ||
typeLength(data.info.type), ');') | ||
exit(BOX, '.free(', RECORD, ');') | ||
}) | ||
@@ -731,4 +741,2 @@ | ||
batch(CUR_COUNT, '=', dyn(options.count), ';') | ||
} else if (!useElementOption('count')) { | ||
batch('if(', CUR_COUNT, '){') | ||
} | ||
@@ -739,5 +747,8 @@ if (options.offset) { | ||
if (options.primitive) { | ||
var PRIM_TYPES = link(primTypes) | ||
batch(CUR_PRIMITIVE, '=', PRIM_TYPES, '[', dyn(options.primitive), '];') | ||
batch( | ||
CUR_PRIMITIVE, '=', link(primTypes), '[', dyn(options.primitive), '];') | ||
} | ||
if (instancing && options.instances) { | ||
batch(CUR_INSTANCES, '=', dyn(options.instances), ';') | ||
} | ||
@@ -759,5 +770,5 @@ function useElementOption (x) { | ||
if (useElementOption('count')) { | ||
batch(CUR_COUNT, '=', CUR_ELEMENTS, '.vertCount;', | ||
'if(', CUR_COUNT, '>0){') | ||
batch(CUR_COUNT, '=', CUR_ELEMENTS, '.vertCount;') | ||
} | ||
batch('if(', CUR_COUNT, '>0){') | ||
if (useElementOption('primitive')) { | ||
@@ -774,5 +785,2 @@ batch(CUR_PRIMITIVE, '=', CUR_ELEMENTS, '.primType;') | ||
if (instancing) { | ||
if (options.instances) { | ||
batch(CUR_INSTANCES, '=', dyn(options.instances), ';') | ||
} | ||
batch( | ||
@@ -785,3 +793,3 @@ 'if(', CUR_INSTANCES, '>0){', | ||
CUR_OFFSET, ',', | ||
CUR_INSTANCES, ');}else{') | ||
CUR_INSTANCES, ');}else ') | ||
} | ||
@@ -794,9 +802,3 @@ batch( | ||
CUR_OFFSET, ');') | ||
if (instancing) { | ||
batch('}') | ||
} | ||
if (useElementOption('count')) { | ||
batch('}') | ||
} | ||
batch('}else{') | ||
batch('}}else if(', CUR_COUNT, '>0){') | ||
if (!useElementOption('count')) { | ||
@@ -819,3 +821,3 @@ if (useElementOption('primitive')) { | ||
CUR_OFFSET, ',', | ||
CUR_COUNT, ');}') | ||
CUR_COUNT, ');') | ||
if (instancing) { | ||
@@ -854,5 +856,3 @@ batch('}') | ||
var GL_POLL = link(reglPoll) | ||
var FRAG_SHADER_STATE = link(shaderState.fragShaders) | ||
var VERT_SHADER_STATE = link(shaderState.vertShaders) | ||
var PROGRAM_STATE = link(shaderState.programs) | ||
var SHADER_STATE = link(shaderState) | ||
var FRAMEBUFFER_STATE = link(framebufferState) | ||
@@ -896,3 +896,2 @@ var DRAW_STATE = { | ||
var hasShader = false | ||
Object.keys(staticOptions).sort(optionPriority).forEach(function (param) { | ||
@@ -902,11 +901,9 @@ var value = staticOptions[param] | ||
case 'frag': | ||
hasShader = true | ||
entry(FRAG_SHADER_STATE, '.push(', link(value), ');') | ||
exit(FRAG_SHADER_STATE, '.pop();') | ||
break | ||
case 'vert': | ||
hasShader = true | ||
entry(VERT_SHADER_STATE, '.push(', link(value), ');') | ||
exit(VERT_SHADER_STATE, '.pop();') | ||
var shaderId = stringStore.id(value) | ||
shaderState.shader( | ||
param === 'frag' ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER, | ||
shaderId) | ||
entry(SHADER_STATE, '.', param, '.push(', shaderId, ');') | ||
exit(SHADER_STATE, '.', param, '.pop();') | ||
break | ||
@@ -1212,29 +1209,6 @@ | ||
// ------------------------------- | ||
// update shader program | ||
// ------------------------------- | ||
if (hasShader) { | ||
if (staticOptions.frag && staticOptions.vert) { | ||
var fragSrc = staticOptions.frag | ||
var vertSrc = staticOptions.vert | ||
entry(PROGRAM_STATE, '.push(', | ||
link(shaderState.create(vertSrc, fragSrc)), ');') | ||
} else { | ||
var FRAG_SRC = entry.def( | ||
FRAG_SHADER_STATE, '[', FRAG_SHADER_STATE, '.length-1]') | ||
var VERT_SRC = entry.def( | ||
VERT_SHADER_STATE, '[', VERT_SHADER_STATE, '.length-1]') | ||
var LINK_PROG = link(shaderState.create) | ||
entry( | ||
PROGRAM_STATE, '.push(', | ||
LINK_PROG, '(', VERT_SRC, ',', FRAG_SRC, '));') | ||
} | ||
exit(PROGRAM_STATE, '.pop();') | ||
} | ||
// ------------------------------- | ||
// update static uniforms | ||
// ------------------------------- | ||
Object.keys(staticUniforms).forEach(function (uniform) { | ||
uniformState.def(uniform) | ||
var STACK = link(uniformState.uniforms[uniform]) | ||
var STACK = link(uniformState.def(uniform)) | ||
var VALUE | ||
@@ -1257,61 +1231,7 @@ var value = staticUniforms[uniform] | ||
Object.keys(staticAttributes).forEach(function (attribute) { | ||
attributeState.def(attribute) | ||
var ATTRIBUTE = link(attributeState.attributes[attribute]) | ||
var data = staticAttributes[attribute] | ||
if (typeof data === 'number') { | ||
entry(ATTRIBUTE, '.pushVec(', +data, ',0,0,0);') | ||
} else { | ||
check(!!data, 'invalid attribute: ' + attribute) | ||
if (Array.isArray(data)) { | ||
entry( | ||
ATTRIBUTE, '.pushVec(', | ||
[data[0] || 0, data[1] || 0, data[2] || 0, data[3] || 0], ');') | ||
} else { | ||
var buffer = bufferState.getBuffer(data) | ||
var size = 0 | ||
var stride = 0 | ||
var offset = 0 | ||
var divisor = 0 | ||
var normalized = false | ||
var type = GL_FLOAT | ||
if (!buffer) { | ||
check.type(data, 'object', 'invalid attribute "' + attribute + '"') | ||
buffer = bufferState.getBuffer(data.buffer) | ||
size = data.size || 0 | ||
stride = data.stride || 0 | ||
offset = data.offset || 0 | ||
divisor = data.divisor || 0 | ||
normalized = data.normalized || false | ||
check(!!buffer, 'invalid attribute ' + attribute + '.buffer') | ||
// Check for user defined type overloading | ||
type = buffer.dtype | ||
if ('type' in data) { | ||
check.parameter(data.type, glTypes, 'attribute type') | ||
type = glTypes[data.type] | ||
} | ||
} else { | ||
type = buffer.dtype | ||
} | ||
check(!!buffer, 'invalid attribute ' + attribute + '.buffer') | ||
check.nni(stride, attribute + '.stride') | ||
check.nni(offset, attribute + '.offset') | ||
check.nni(divisor, attribute + '.divisor') | ||
check.type(normalized, 'boolean', attribute + '.normalized') | ||
check.oneOf(size, [0, 1, 2, 3, 4], attribute + '.size') | ||
entry( | ||
ATTRIBUTE, '.pushPtr(', [ | ||
link(buffer), size, offset, stride, | ||
divisor, normalized, type | ||
].join(), ');') | ||
} | ||
} | ||
exit(ATTRIBUTE, '.pop();') | ||
var ATTRIBUTE = link(attributeState.def(attribute)) | ||
var BOX = link(attributeState.box(attribute).alloc(data)) | ||
entry(ATTRIBUTE, '.records.push(', BOX, ');') | ||
exit(ATTRIBUTE, '.records.pop();') | ||
}) | ||
@@ -1571,4 +1491,3 @@ | ||
Object.keys(dynamicUniforms).forEach(function (uniform) { | ||
uniformState.def(uniform) | ||
var STACK = link(uniformState.uniforms[uniform]) | ||
var STACK = link(uniformState.def(uniform)) | ||
var VALUE = dyn(dynamicUniforms[uniform]) | ||
@@ -1583,7 +1502,8 @@ dynamicEntry(STACK, '.push(', VALUE, ');') | ||
Object.keys(dynamicAttributes).forEach(function (attribute) { | ||
attributeState.def(attribute) | ||
var ATTRIBUTE = link(attributeState.attributes[attribute]) | ||
var ATTRIBUTE = link(attributeState.def(attribute)) | ||
var VALUE = dyn(dynamicAttributes[attribute]) | ||
dynamicEntry(ATTRIBUTE, '.pushDyn(', VALUE, ');') | ||
dynamicExit(ATTRIBUTE, '.pop();') | ||
var BOX = link(attributeState.box(attribute)) | ||
dynamicEntry(ATTRIBUTE, '.records.push(', | ||
BOX, '.alloc(', VALUE, '));') | ||
dynamicExit(BOX, '.free(', ATTRIBUTE, '.records.pop());') | ||
}) | ||
@@ -1608,2 +1528,21 @@ | ||
// ------------------------------- | ||
// update shader program only for DRAW and batch | ||
// ------------------------------- | ||
var commonDraw = block() | ||
var CURRENT_PROGRAM = commonDraw.def() | ||
if (staticOptions.frag && staticOptions.vert) { | ||
var fragSrc = staticOptions.frag | ||
var vertSrc = staticOptions.vert | ||
commonDraw(CURRENT_PROGRAM, '=', link( | ||
shaderState.program( | ||
stringStore.id(vertSrc), | ||
stringStore.id(fragSrc))), ';') | ||
} else { | ||
commonDraw(CURRENT_PROGRAM, '=', | ||
SHADER_STATE, '.program', '(', | ||
SHADER_STATE, '.vert[', SHADER_STATE, '.vert.length-1]', ',', | ||
SHADER_STATE, '.frag[', SHADER_STATE, '.frag.length-1]', ');') | ||
} | ||
// ========================================================== | ||
@@ -1613,3 +1552,3 @@ // DRAW PROCEDURE | ||
var draw = proc('draw') | ||
draw(entry) | ||
draw(entry, commonDraw) | ||
if (hasDynamic) { | ||
@@ -1620,7 +1559,6 @@ draw( | ||
} | ||
var CURRENT_SHADER = stackTop(PROGRAM_STATE) | ||
draw( | ||
GL_POLL, '();', | ||
'if(', CURRENT_SHADER, ')', | ||
CURRENT_SHADER, '.draw(', hasDynamic ? DYNARGS : '', ');', | ||
'if(', CURRENT_PROGRAM, ')', | ||
CURRENT_PROGRAM, '.draw(', hasDynamic ? DYNARGS : '', ');', | ||
hasDynamic ? dynamicExit : '', | ||
@@ -1633,4 +1571,3 @@ exit) | ||
var batch = proc('batch') | ||
batch(entry) | ||
var CUR_SHADER = batch.def(stackTop(PROGRAM_STATE)) | ||
batch(entry, commonDraw) | ||
var EXEC_BATCH = link(function (program, count, args) { | ||
@@ -1646,6 +1583,6 @@ var proc = program.batchCache[callId] | ||
batch( | ||
'if(', CUR_SHADER, '){', | ||
'if(', CURRENT_PROGRAM, '){', | ||
GL_POLL, '();', | ||
EXEC_BATCH, '(', | ||
CUR_SHADER, ',', | ||
CURRENT_PROGRAM, ',', | ||
batch.arg(), ',', | ||
@@ -1652,0 +1589,0 @@ batch.arg(), ');') |
// Context and canvas creation helper functions | ||
/*globals HTMLElement,WebGLRenderingContext*/ | ||
var check = require('./check') | ||
var check = require('./util/check') | ||
var extend = require('./util/extend') | ||
@@ -10,3 +11,3 @@ function createCanvas (element, options) { | ||
Object.assign(canvas.style, { | ||
extend(canvas.style, { | ||
border: 0, | ||
@@ -22,3 +23,3 @@ margin: 0, | ||
canvas.style.position = 'absolute' | ||
Object.assign(element.style, { | ||
extend(element.style, { | ||
margin: 0, | ||
@@ -40,3 +41,3 @@ padding: 0 | ||
canvas.height = scale * h | ||
Object.assign(canvas.style, { | ||
extend(canvas.style, { | ||
width: w + 'px', | ||
@@ -50,3 +51,3 @@ height: h + 'px' | ||
var prevDestroy = args.options.onDestroy | ||
args.options = Object.assign({}, args.options, { | ||
args.options = extend(extend({}, args.options), { | ||
onDestroy: function () { | ||
@@ -83,3 +84,3 @@ window.removeEventListener('resize', resize) | ||
gl: gl, | ||
options: Object.assign({ | ||
options: extend({ | ||
pixelRatio: window.devicePixelRatio | ||
@@ -110,3 +111,3 @@ }, options) | ||
gl: args[0], | ||
options: Object.assign({ | ||
options: extend({ | ||
pixelRatio: 1 | ||
@@ -113,0 +114,0 @@ }, options) |
@@ -5,3 +5,3 @@ var GL_TRIANGLES = 4 | ||
var primitive = [ GL_TRIANGLES ] | ||
var count = [ 0 ] | ||
var count = [ -1 ] | ||
var offset = [ 0 ] | ||
@@ -8,0 +8,0 @@ var instances = [ 0 ] |
@@ -1,4 +0,4 @@ | ||
var check = require('./check') | ||
var isTypedArray = require('./is-typed-array') | ||
var isNDArrayLike = require('./is-ndarray') | ||
var check = require('./util/check') | ||
var isTypedArray = require('./util/is-typed-array') | ||
var isNDArrayLike = require('./util/is-ndarray') | ||
var primTypes = require('./constants/primitives.json') | ||
@@ -148,11 +148,9 @@ | ||
Object.assign(reglElements, { | ||
_reglType: 'elements', | ||
_elements: elements, | ||
destroy: function () { | ||
check(elements.buffer !== null, 'must not double destroy elements') | ||
buffer.destroy() | ||
elements.buffer = null | ||
} | ||
}) | ||
reglElements._reglType = 'elements' | ||
reglElements._elements = elements | ||
reglElements.destroy = function () { | ||
check(elements.buffer !== null, 'must not double destroy elements') | ||
buffer.destroy() | ||
elements.buffer = null | ||
} | ||
@@ -159,0 +157,0 @@ return reglElements |
@@ -1,3 +0,4 @@ | ||
var check = require('./check') | ||
var values = require('./values') | ||
var check = require('./util/check') | ||
var values = require('./util/values') | ||
var extend = require('./util/extend') | ||
@@ -22,6 +23,2 @@ // We store these constants so that the minifier can inline them | ||
var GL_ALPHA = 0x1906 | ||
var GL_LUMINANCE = 0x1909 | ||
var GL_LUMINANCE_ALPHA = 0x190A | ||
var GL_RGB = 0x1907 | ||
var GL_RGBA = 0x1908 | ||
@@ -104,4 +101,4 @@ | ||
var colorFormats = Object.assign({}, | ||
colorTextureFormats, | ||
var colorFormats = extend(extend({}, | ||
colorTextureFormats), | ||
colorRenderbufferFormats) | ||
@@ -439,4 +436,4 @@ | ||
framebuffer.width = width || gl.drawingBufferWidth | ||
framebuffer.height = height || gl.drawingBufferHeight | ||
framebuffer.width = width = width || gl.drawingBufferWidth | ||
framebuffer.height = height = height || gl.drawingBufferHeight | ||
@@ -678,9 +675,7 @@ if ('format' in options) { | ||
Object.assign(reglFramebuffer, { | ||
_reglType: 'framebuffer', | ||
_framebuffer: framebuffer, | ||
destroy: function () { | ||
destroy(framebuffer) | ||
} | ||
}) | ||
reglFramebuffer._reglType = 'framebuffer' | ||
reglFramebuffer._framebuffer = framebuffer | ||
reglFramebuffer._destroy = function () { | ||
destroy(framebuffer) | ||
} | ||
@@ -687,0 +682,0 @@ return reglFramebuffer |
@@ -1,3 +0,3 @@ | ||
var check = require('./check') | ||
var isTypedArray = require('./is-typed-array') | ||
var check = require('./util/check') | ||
var isTypedArray = require('./util/is-typed-array') | ||
@@ -4,0 +4,0 @@ var GL_RGBA = 6408 |
@@ -1,3 +0,3 @@ | ||
var check = require('./check') | ||
var values = require('./values') | ||
var check = require('./util/check') | ||
var values = require('./util/values') | ||
@@ -133,9 +133,7 @@ var GL_RENDERBUFFER = 0x8D41 | ||
Object.assign(reglRenderbuffer, { | ||
_reglType: 'renderbuffer', | ||
_renderbuffer: renderbuffer, | ||
destroy: function () { | ||
renderbuffer.decRef() | ||
} | ||
}) | ||
reglRenderbuffer._reglType = 'renderbuffer' | ||
reglRenderbuffer._renderbuffer = renderbuffer | ||
reglRenderbuffer.destroy = function () { | ||
renderbuffer.decRef() | ||
} | ||
@@ -142,0 +140,0 @@ return reglRenderbuffer |
@@ -1,11 +0,13 @@ | ||
var check = require('./check') | ||
var check = require('./util/check') | ||
var values = require('./util/values') | ||
var DEFAULT_FRAG_SHADER = 'void main(){gl_FragColor=vec4(0,0,0,0);}' | ||
var DEFAULT_VERT_SHADER = 'void main(){gl_Position=vec4(0,0,0,0);}' | ||
var GL_FRAGMENT_SHADER = 35632 | ||
var GL_VERTEX_SHADER = 35633 | ||
function ActiveInfo (name, location, info) { | ||
var GL_ACTIVE_UNIFORMS = 0x8B86 | ||
var GL_ACTIVE_ATTRIBUTES = 0x8B89 | ||
function ActiveInfo (name, id, location, info) { | ||
this.name = name | ||
this.id = id | ||
this.location = location | ||
@@ -19,25 +21,21 @@ this.info = info | ||
uniformState, | ||
compileShaderDraw) { | ||
compileShaderDraw, | ||
stringStore) { | ||
// =================================================== | ||
// glsl compilation and linking | ||
// =================================================== | ||
var shaders = {} | ||
var fragShaders = {} | ||
var vertShaders = {} | ||
var fragShaders = [DEFAULT_FRAG_SHADER] | ||
var vertShaders = [DEFAULT_VERT_SHADER] | ||
function getShader (type, id) { | ||
var cache = type === GL_FRAGMENT_SHADER ? fragShaders : vertShaders | ||
var shader = cache[id] | ||
function getShader (type, source) { | ||
var cache = shaders[type] | ||
var shader = cache[source] | ||
if (!shader) { | ||
var source = stringStore.str(id) | ||
shader = gl.createShader(type) | ||
gl.shaderSource(shader, source) | ||
gl.compileShader(shader) | ||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { | ||
var errLog = gl.getShaderInfoLog(shader) | ||
check.raise('Error compiling shader:\n' + errLog) | ||
} | ||
cache[source] = shader | ||
check.shaderError(gl, shader, source, type) | ||
cache[id] = shader | ||
} | ||
@@ -48,17 +46,2 @@ | ||
function refreshShaders () { | ||
shaders[GL_FRAGMENT_SHADER] = {} | ||
shaders[GL_VERTEX_SHADER] = {} | ||
} | ||
function clearShaders () { | ||
Object.keys(shaders).forEach(function (type) { | ||
Object.keys(shaders[type]).forEach(function (shader) { | ||
gl.deleteShader(shaders[type][shader]) | ||
}) | ||
}) | ||
shaders[GL_FRAGMENT_SHADER] = {} | ||
shaders[GL_VERTEX_SHADER] = {} | ||
} | ||
// =================================================== | ||
@@ -70,5 +53,5 @@ // program linking | ||
function REGLProgram (fragSrc, vertSrc) { | ||
this.fragSrc = fragSrc | ||
this.vertSrc = vertSrc | ||
function REGLProgram (fragId, vertId) { | ||
this.fragId = fragId | ||
this.vertId = vertId | ||
this.program = null | ||
@@ -81,134 +64,122 @@ this.uniforms = [] | ||
Object.assign(REGLProgram.prototype, { | ||
link: function () { | ||
var i, info | ||
function linkProgram (desc) { | ||
var i, info | ||
// ------------------------------- | ||
// compile & link | ||
// ------------------------------- | ||
var fragShader = getShader(gl.FRAGMENT_SHADER, this.fragSrc) | ||
var vertShader = getShader(gl.VERTEX_SHADER, this.vertSrc) | ||
// ------------------------------- | ||
// compile & link | ||
// ------------------------------- | ||
var fragShader = getShader(GL_FRAGMENT_SHADER, desc.fragId) | ||
var vertShader = getShader(GL_VERTEX_SHADER, desc.vertId) | ||
var program = this.program = gl.createProgram() | ||
gl.attachShader(program, fragShader) | ||
gl.attachShader(program, vertShader) | ||
gl.linkProgram(program) | ||
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) { | ||
var errLog = gl.getProgramInfoLog(program) | ||
check.raise('Error linking program:\n' + errLog) | ||
} | ||
var program = desc.program = gl.createProgram() | ||
gl.attachShader(program, fragShader) | ||
gl.attachShader(program, vertShader) | ||
gl.linkProgram(program) | ||
check.linkError( | ||
gl, | ||
program, | ||
stringStore.str(desc.fragId), | ||
stringStore.str(desc.vertId)) | ||
// ------------------------------- | ||
// grab uniforms | ||
// ------------------------------- | ||
var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS) | ||
var uniforms = this.uniforms = [] | ||
for (i = 0; i < numUniforms; ++i) { | ||
info = gl.getActiveUniform(program, i) | ||
if (info) { | ||
if (info.size > 1) { | ||
for (var j = 0; j < info.size; ++j) { | ||
var name = info.name.replace('[0]', '[' + j + ']') | ||
uniforms.push(new ActiveInfo( | ||
name, | ||
gl.getUniformLocation(program, name), | ||
info)) | ||
uniformState.def(name) | ||
} | ||
} else { | ||
// ------------------------------- | ||
// grab uniforms | ||
// ------------------------------- | ||
var numUniforms = gl.getProgramParameter(program, GL_ACTIVE_UNIFORMS) | ||
var uniforms = desc.uniforms = [] | ||
for (i = 0; i < numUniforms; ++i) { | ||
info = gl.getActiveUniform(program, i) | ||
if (info) { | ||
if (info.size > 1) { | ||
for (var j = 0; j < info.size; ++j) { | ||
var name = info.name.replace('[0]', '[' + j + ']') | ||
uniformState.def(name) | ||
uniforms.push(new ActiveInfo( | ||
info.name, | ||
gl.getUniformLocation(program, info.name), | ||
name, | ||
stringStore.id(name), | ||
gl.getUniformLocation(program, name), | ||
info)) | ||
uniformState.def(info.name) | ||
} | ||
} | ||
} | ||
// ------------------------------- | ||
// grab attributes | ||
// ------------------------------- | ||
var numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES) | ||
var attributes = this.attributes = [] | ||
for (i = 0; i < numAttributes; ++i) { | ||
info = gl.getActiveAttrib(program, i) | ||
if (info) { | ||
attributes.push(new ActiveInfo( | ||
} else { | ||
uniformState.def(info.name) | ||
uniforms.push(new ActiveInfo( | ||
info.name, | ||
gl.getAttribLocation(program, info.name), | ||
stringStore.id(info.name), | ||
gl.getUniformLocation(program, info.name), | ||
info)) | ||
attributeState.def(info.name) | ||
} | ||
} | ||
// ------------------------------- | ||
// clear cached rendering methods | ||
// ------------------------------- | ||
this.draw = compileShaderDraw(this) | ||
this.batchCache = {} | ||
}, | ||
destroy: function () { | ||
gl.deleteProgram(this.program) | ||
} | ||
}) | ||
function getProgram (vertSource, fragSource) { | ||
var cache = programCache[fragSource] | ||
if (!cache) { | ||
cache = programCache[fragSource] = {} | ||
// ------------------------------- | ||
// grab attributes | ||
// ------------------------------- | ||
var numAttributes = gl.getProgramParameter(program, GL_ACTIVE_ATTRIBUTES) | ||
var attributes = desc.attributes = [] | ||
for (i = 0; i < numAttributes; ++i) { | ||
info = gl.getActiveAttrib(program, i) | ||
if (info) { | ||
attributeState.def(info.name) | ||
attributes.push(new ActiveInfo( | ||
info.name, | ||
stringStore.id(info.name), | ||
gl.getAttribLocation(program, info.name), | ||
info)) | ||
} | ||
} | ||
var program = cache[vertSource] | ||
if (!program) { | ||
program = new REGLProgram(fragSource, vertSource) | ||
program.link() | ||
cache[vertSource] = program | ||
programList.push(program) | ||
} | ||
return program | ||
} | ||
function clearPrograms () { | ||
programList.forEach(function (program) { | ||
program.destroy() | ||
}) | ||
programList.length = 0 | ||
programCache = {} | ||
// ------------------------------- | ||
// clear cached rendering methods | ||
// ------------------------------- | ||
desc.draw = compileShaderDraw(desc) | ||
desc.batchCache = {} | ||
} | ||
function refreshPrograms () { | ||
programList.forEach(function (program) { | ||
program.link() | ||
}) | ||
} | ||
var fragShaderStack = [ -1 ] | ||
var vertShaderStack = [ -1 ] | ||
// =================================================== | ||
// program state | ||
// =================================================== | ||
var programState = [null] | ||
return { | ||
clear: function () { | ||
var deleteShader = gl.deleteShader.bind(gl) | ||
values(fragShaders).forEach(deleteShader) | ||
fragShaders = {} | ||
values(vertShaders).forEach(deleteShader) | ||
vertShaders = {} | ||
// =================================================== | ||
// context management | ||
// =================================================== | ||
function clear () { | ||
clearShaders() | ||
clearPrograms() | ||
} | ||
programList.forEach(function (desc) { | ||
gl.deleteProgram(desc.program) | ||
}) | ||
programList.length = 0 | ||
programCache = {} | ||
}, | ||
function refresh () { | ||
refreshShaders() | ||
refreshPrograms() | ||
} | ||
refresh: function () { | ||
fragShaders = {} | ||
vertShaders = {} | ||
programList.forEach(linkProgram) | ||
}, | ||
// We call clear once to initialize all data structures | ||
clear() | ||
program: function (vertId, fragId) { | ||
check(vertId >= 0, 'missing vertex shader') | ||
check(fragId >= 0, 'missing fragment shader') | ||
return { | ||
create: getProgram, | ||
clear: clear, | ||
refresh: refresh, | ||
programs: programState, | ||
fragShaders: fragShaders, | ||
vertShaders: vertShaders | ||
var cache = programCache[fragId] | ||
if (!cache) { | ||
cache = programCache[fragId] = {} | ||
} | ||
var program = cache[vertId] | ||
if (!program) { | ||
program = new REGLProgram(fragId, vertId) | ||
linkProgram(program) | ||
cache[vertId] = program | ||
programList.push(program) | ||
} | ||
return program | ||
}, | ||
shader: getShader, | ||
frag: fragShaderStack, | ||
vert: vertShaderStack | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
var createStack = require('./stack') | ||
var createEnvironment = require('./codegen') | ||
var createStack = require('./util/stack') | ||
var createEnvironment = require('./util/codegen') | ||
@@ -179,2 +179,3 @@ // WebGL constants | ||
}) | ||
var procs = env.compile() | ||
@@ -181,0 +182,0 @@ |
@@ -1,8 +0,9 @@ | ||
var check = require('./check') | ||
var values = require('./values') | ||
var isTypedArray = require('./is-typed-array') | ||
var isNDArrayLike = require('./is-ndarray') | ||
var loadTexture = require('./load-texture') | ||
var convertToHalfFloat = require('./to-half-float') | ||
var parseDDS = require('./parse-dds') | ||
var check = require('./util/check') | ||
var extend = require('./util/extend') | ||
var values = require('./util/values') | ||
var isTypedArray = require('./util/is-typed-array') | ||
var isNDArrayLike = require('./util/is-ndarray') | ||
var loadTexture = require('./util/load-texture') | ||
var convertToHalfFloat = require('./util/to-half-float') | ||
var parseDDS = require('./util/parse-dds') | ||
@@ -200,3 +201,3 @@ var GL_COMPRESSED_TEXTURE_FORMATS = 0x86A3 | ||
var minFilters = Object.assign({ | ||
var minFilters = extend({ | ||
'nearest mipmap nearest': GL_NEAREST_MIPMAP_NEAREST, | ||
@@ -248,3 +249,3 @@ 'linear mipmap nearest': GL_LINEAR_MIPMAP_NEAREST, | ||
if (extensions.webgl_depth_texture) { | ||
Object.assign(textureFormats, { | ||
extend(textureFormats, { | ||
'depth': GL_DEPTH_COMPONENT, | ||
@@ -254,3 +255,3 @@ 'depth stencil': GL_DEPTH_STENCIL | ||
Object.assign(textureTypes, { | ||
extend(textureTypes, { | ||
'uint16': GL_UNSIGNED_SHORT, | ||
@@ -263,3 +264,3 @@ 'uint32': GL_UNSIGNED_INT, | ||
if (extensions.webgl_compressed_texture_s3tc) { | ||
Object.assign(compressedTextureFormats, { | ||
extend(compressedTextureFormats, { | ||
'rgb s3tc dxt1': GL_COMPRESSED_RGB_S3TC_DXT1_EXT, | ||
@@ -273,3 +274,3 @@ 'rgba s3tc dxt1': GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, | ||
if (extensions.webgl_compressed_texture_atc) { | ||
Object.assign(compressedTextureFormats, { | ||
extend(compressedTextureFormats, { | ||
'rgb arc': GL_COMPRESSED_RGB_ATC_WEBGL, | ||
@@ -282,3 +283,3 @@ 'rgba atc explicit alpha': GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL, | ||
if (extensions.webgl_compressed_texture_pvrtc) { | ||
Object.assign(compressedTextureFormats, { | ||
extend(compressedTextureFormats, { | ||
'rgb pvrtc 4bppv1': GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, | ||
@@ -334,3 +335,3 @@ 'rgb pvrtc 2bppv1': GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, | ||
this.unpackAlignment = 1 | ||
this.colorSpace = GL_BROWSER_DEFAULT_WEBGL | ||
this.colorSpace = 0 | ||
@@ -377,3 +378,3 @@ // shape | ||
Object.assign(PixelInfo.prototype, { | ||
extend(PixelInfo.prototype, { | ||
parseFlags: function (options) { | ||
@@ -588,4 +589,4 @@ if (typeof options !== 'object' || !options) { | ||
} else if (isRectArray(data)) { | ||
var w = data.length | ||
var h = data[0].length | ||
var w = data[0].length | ||
var h = data.length | ||
var c = 1 | ||
@@ -598,6 +599,6 @@ var i, j, k, p | ||
p = 0 | ||
for (i = 0; i < w; ++i) { | ||
for (j = 0; j < h; ++j) { | ||
for (j = 0; j < h; ++j) { | ||
for (i = 0; i < w; ++i) { | ||
for (k = 0; k < c; ++k) { | ||
array[p++] = data[i][j][k] | ||
array[p++] = data[j][i][k] | ||
} | ||
@@ -609,5 +610,5 @@ } | ||
p = 0 | ||
for (i = 0; i < w; ++i) { | ||
for (j = 0; j < h; ++j) { | ||
array[p++] = data[i][j] | ||
for (j = 0; j < h; ++j) { | ||
for (i = 0; i < w; ++i) { | ||
array[p++] = data[j][i] | ||
} | ||
@@ -855,3 +856,3 @@ } | ||
Object.assign(TexParams.prototype, { | ||
extend(TexParams.prototype, { | ||
parse: function (options) { | ||
@@ -1343,3 +1344,3 @@ if (typeof options !== 'object' || !options) { | ||
Object.assign(REGLTexture.prototype, { | ||
extend(REGLTexture.prototype, { | ||
bind: function () { | ||
@@ -1401,9 +1402,7 @@ var texture = this | ||
Object.assign(reglTexture, { | ||
_reglType: 'texture', | ||
_texture: texture, | ||
destroy: function () { | ||
texture.decRef() | ||
} | ||
}) | ||
reglTexture._reglType = 'texture' | ||
reglTexture._texture = texture | ||
reglTexture.destroy = function () { | ||
texture.decRef() | ||
} | ||
@@ -1410,0 +1409,0 @@ return reglTexture |
@@ -1,15 +0,17 @@ | ||
module.exports = function wrapUniformState () { | ||
module.exports = function wrapUniformState (stringStore) { | ||
var uniformState = {} | ||
function defUniform (name) { | ||
if (name in uniformState) { | ||
return | ||
var id = stringStore.id(name) | ||
var result = uniformState[id] | ||
if (!result) { | ||
result = uniformState[id] = [] | ||
} | ||
uniformState[name] = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] | ||
return result | ||
} | ||
return { | ||
uniforms: uniformState, | ||
def: defUniform | ||
def: defUniform, | ||
uniforms: uniformState | ||
} | ||
} |
{ | ||
"name": "regl", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "WebGL", | ||
@@ -13,2 +13,3 @@ "main": "regl.js", | ||
"baboon-image": "^2.0.0", | ||
"bl": "^1.1.2", | ||
"browserify": "^13.0.0", | ||
@@ -20,9 +21,12 @@ "budo": "^8.1.0", | ||
"coverify": "^1.4.1", | ||
"falafel": "^1.2.0", | ||
"faucet": "0.0.1", | ||
"gl": "^3.0.3", | ||
"gl": "^3.0.5", | ||
"gl-mat4": "^1.1.4", | ||
"glob": "^7.0.3", | ||
"google-closure-compiler": "^20160315.2.0", | ||
"hsv2rgb": "^1.1.0", | ||
"indexhtmlify": "^1.2.1", | ||
"mouse-change": "^1.2.1", | ||
"mkdirp": "^0.5.1", | ||
"mouse-change": "^1.3.0", | ||
"ncp": "^2.0.0", | ||
@@ -35,3 +39,4 @@ "runscript": "^1.1.0", | ||
"tape": "^4.4.0", | ||
"uglify-js": "^2.6.2" | ||
"through2": "^2.0.1", | ||
"vectorize-text": "^3.0.2" | ||
}, | ||
@@ -73,5 +78,8 @@ "scripts": { | ||
"standard": { | ||
"ignore": "dist/*" | ||
"ignore": [ | ||
"dist/*", | ||
"www/*" | ||
] | ||
}, | ||
"homepage": "https://mikolalysenko.github.io/regl" | ||
} |
@@ -193,8 +193,9 @@ # regl | ||
Test video (doggie-chromakey.ogv) by [L0ckergn0me](https://archive.org/details/L0ckergn0me-PixieGreenScreen446), used under creative commons license | ||
### Asset licenses | ||
Many examples use creative commons or public domain artwork for illustrative purposes. These assets are not included in any of the redistributable packages of regl. | ||
Cube maps (posx.jpeg, negx.jpeg, posy.jpeg, negy.jpeg, posz.jpeg, negz.jpeg) by [Humus](http://www.humus.name/index.php?page=Textures), used under creative commons 3 license | ||
Environment map of Oregon (ogd-oregon-360.jpg) due to Max Ogden (@ogd on GitHub) | ||
DDS test images (alpine_cliff_a, alpine_cliff_a_norm, alpine_cliff_a_spec) taken from the CC0 license [0-AD texture pack by Wildfire games](http://opengameart.org/content/0-ad-textures) | ||
* Test video (doggie-chromakey.ogv) by [L0ckergn0me](https://archive.org/details/L0ckergn0me-PixieGreenScreen446), used under creative commons license | ||
* Cube maps (posx.jpeg, negx.jpeg, posy.jpeg, negy.jpeg, posz.jpeg, negz.jpeg) by [Humus](http://www.humus.name/index.php?page=Textures), used under creative commons 3 license | ||
* Environment map of Oregon (ogd-oregon-360.jpg) due to Max Ogden (@ogd on GitHub) | ||
* DDS test images (alpine_cliff_a, alpine_cliff_a_norm, alpine_cliff_a_spec) taken from the CC0 license [0-AD texture pack by Wildfire games](http://opengameart.org/content/0-ad-textures) | ||
* Tile set for tile mapping demo (tiles.png) from CC0 licensed [cobblestone paths pack](http://opengameart.org/content/rpg-tiles-cobble-stone-paths-town-objects) |
55
regl.js
@@ -1,3 +0,5 @@ | ||
var check = require('./lib/check') | ||
var check = require('./lib/util/check') | ||
var extend = require('./lib/util/extend') | ||
var getContext = require('./lib/context') | ||
var createStringStore = require('./lib/strings') | ||
var wrapExtensions = require('./lib/extension') | ||
@@ -18,4 +20,4 @@ var wrapLimits = require('./lib/limits') | ||
var dynamic = require('./lib/dynamic') | ||
var raf = require('./lib/raf') | ||
var clock = require('./lib/clock') | ||
var raf = require('./lib/util/raf') | ||
var clock = require('./lib/util/clock') | ||
@@ -38,2 +40,4 @@ var GL_COLOR_BUFFER_BIT = 16384 | ||
var stringStore = createStringStore() | ||
var extensionState = wrapExtensions(gl) | ||
@@ -58,3 +62,3 @@ var extensions = extensionState.extensions | ||
var uniformState = wrapUniforms() | ||
var uniformState = wrapUniforms(stringStore) | ||
@@ -65,3 +69,4 @@ var attributeState = wrapAttributes( | ||
limits, | ||
bufferState) | ||
bufferState, | ||
stringStore) | ||
@@ -74,3 +79,4 @@ var shaderState = wrapShaders( | ||
return compiler.draw(program) | ||
}) | ||
}, | ||
stringStore) | ||
@@ -121,2 +127,3 @@ var drawState = wrapDraw( | ||
gl, | ||
stringStore, | ||
extensions, | ||
@@ -138,3 +145,2 @@ limits, | ||
// raf stuff | ||
var rafCallbacks = [] | ||
@@ -207,3 +213,2 @@ var activeRAF = 0 | ||
// Resource destructuion | ||
function destroy () { | ||
@@ -228,3 +233,2 @@ stopRAF() | ||
// Compiles a set of procedures for an object | ||
function compileProcedure (options) { | ||
@@ -237,3 +241,3 @@ check(!!options, 'invalid args to regl({...})') | ||
function flattenNestedOptions (options) { | ||
var result = Object.assign({}, options) | ||
var result = extend({}, options) | ||
delete result.uniforms | ||
@@ -262,3 +266,2 @@ delete result.attributes | ||
// First we separate the options into static and dynamic components | ||
function separateDynamic (object) { | ||
@@ -303,3 +306,24 @@ var staticItems = {} | ||
check.saveDrawInfo(opts, uniforms, attributes, stringStore) | ||
function REGLCommand (args, body) { | ||
if (typeof args === 'function') { | ||
return scope(null, args) | ||
} else if (typeof body === 'function') { | ||
return scope(args, body) | ||
} | ||
// Runtime shader check. Removed in production builds | ||
check.drawOk( | ||
drawState, | ||
shaderState, | ||
uniformState, | ||
attributeState, | ||
opts._commandRef, | ||
opts._fragId, | ||
opts._vertId, | ||
opts._uniformSet, | ||
opts._attributeSet, | ||
opts._hasCount) | ||
if (typeof args === 'number') { | ||
@@ -309,6 +333,2 @@ return batch(args | 0, reserve(args | 0)) | ||
return batch(args.length, args) | ||
} else if (typeof args === 'function') { | ||
return scope(null, args) | ||
} else if (typeof body === 'function') { | ||
return scope(args, body) | ||
} | ||
@@ -326,7 +346,5 @@ return draw(args) | ||
// Clears the currently bound frame buffer | ||
function clear (options) { | ||
var clearFlags = 0 | ||
// Update context state | ||
poll() | ||
@@ -352,3 +370,2 @@ | ||
// Registers another requestAnimationFrame callback | ||
function frame (cb) { | ||
@@ -377,3 +394,3 @@ rafCallbacks.push(cb) | ||
return Object.assign(compileProcedure, { | ||
return extend(compileProcedure, { | ||
// Clear current FBO | ||
@@ -380,0 +397,0 @@ clear: clear, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
11840
2
201
2
443859
28
42