Skip to content

Commit

Permalink
fix typo, linter bugs. refresh correctly resets vao state
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolalysenko committed Mar 8, 2020
1 parent 7a79dad commit 1a62276
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module.exports = function wrapAttributeState (
rec.buffer = bufferState.getBuffer(spec)
rec.size = rec.buffer.dimension | 0
rec.normalized = false
rec.types = rec.buffer.dtype
rec.type = rec.buffer.dtype
rec.offfset = 0
rec.stride = 0
rec.divisor = 0
Expand All @@ -235,9 +235,9 @@ module.exports = function wrapAttributeState (
rec.normalized = !!spec.normalized || false
if ('type' in spec) {
check.parameter(spec.type, bufferTypes, 'invalid buffer type')
rec.types = bufferTypes[spec.type]
rec.type = bufferTypes[spec.type]
} else {
rec.types = rec.buffer.dtype
rec.type = rec.buffer.dtype
}
rec.offfset = (spec.offset || 0) | 0
rec.stride = (spec.stride || 0) | 0
Expand Down
8 changes: 8 additions & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3389,6 +3389,11 @@ module.exports = function reglCore (
if (extInstancing) {
INSTANCING = env.link(extInstancing)
}

// update vertex array bindings
if (extensions.oes_vertex_array_object) {
refresh(env.link(extensions.oes_vertex_array_object), '.bindVertexArrayOES(null);')
}
for (var i = 0; i < limits.maxAttributes; ++i) {
var BINDING = refresh.def(shared.attributes, '[', i, ']')
var ifte = env.cond(BINDING, '.buffer')
Expand Down Expand Up @@ -3421,6 +3426,9 @@ module.exports = function reglCore (
BINDING, '.divisor);')
}
}
refresh(
env.shared.vao, '.currentVAO=null;',
env.shared.vao, '.setVAO(', env.shared.vao, '.targetVAO);')

Object.keys(GL_FLAGS).forEach(function (flag) {
var cap = GL_FLAGS[flag]
Expand Down
25 changes: 15 additions & 10 deletions regl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ declare namespace REGL {
framebufferCube(options: REGL.FramebufferCubeOptions): REGL.FramebufferCube;

/* Creates a vertex array object */
vao(attributes: REGL.AttributeConfig[]) : REGL.VertexArrayObject;
vao(attributes: REGL.AttributeState[]) : REGL.VertexArrayObject;

/* Events and listeners */

Expand Down Expand Up @@ -487,7 +487,7 @@ declare namespace REGL {
/**
* Configuration of vertex array object
*/
vao?: REGL.MaybeDynamic<REGL.VertexArrayObject | AttributeConfig[], ParentContext & OwnContext, Props>,
vao?: REGL.MaybeDynamic<REGL.VertexArrayObject | AttributeState[], ParentContext & OwnContext, Props>,

/* Drawing */

Expand Down Expand Up @@ -662,13 +662,16 @@ declare namespace REGL {
[Key in keyof Uniforms]: MaybeDynamic<Uniforms[Key], Context, Props>;
}

type Attribute =
number |
type AttributeState =
ConstantAttribute |
AttributeConfig |
REGL.Buffer |
REGL.BufferData;

type Attribute =
number |
AttributeState;

interface Attributes {
[name: string]: Attribute;
}
Expand All @@ -687,17 +690,19 @@ declare namespace REGL {

interface AttributeConfig {
/** A REGLBuffer wrapping the buffer object. (Default: null) */
buffer?: REGL.Buffer;
buffer?: REGL.Buffer|undefined|null|false;
/** The offset of the vertexAttribPointer in bytes. (Default: 0) */
offset?: number;
offset?: number|undefined;
/** The stride of the vertexAttribPointer in bytes. (Default: 0) */
stride?: number;
stride?: number|undefined;
/** Whether the pointer is normalized. (Default: false) */
normalized?: boolean;
/** The size of the vertex attribute. (Default: Inferred from shader) */
size?: number;
size?: number|undefined;
/** Sets gl.vertexAttribDivisorANGLE. Only supported if the ANGLE_instanced_arrays extension is available. (Default: 0) */
divisor?: number;
divisor?: number|undefined;
/** Data type for attribute */
type?: 'uint8'|'uint16'|'uint32'|'float'|'int8'|'int16'|'int32';
}

interface DepthTestOptions {
Expand Down Expand Up @@ -948,7 +953,7 @@ declare namespace REGL {
}

interface VertexArrayObject extends REGL.Resource {
(attributes: REGL.AttributeConfig[]): REGL.VertexArrayObject;
(attributes:REGL.AttributeState[]) : REGL.VertexArrayObject;
}

interface Buffer extends REGL.Resource {
Expand Down
2 changes: 1 addition & 1 deletion rollup/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ module.exports = {
json()
],
sourceMap: true
};
}
2 changes: 1 addition & 1 deletion rollup/config.unchecked.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ var removeCheck = require('./plugins/remove-check')

config.dest = 'dist/regl.unchecked.js'
config.sourceMap = false
config.plugins.push(removeCheck());
config.plugins.push(removeCheck())

module.exports = config

0 comments on commit 1a62276

Please sign in to comment.