How to use vA method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

VertexArrayFactorySpec.js

Source:VertexArrayFactorySpec.js Github

copy

Full Screen

1/*global defineSuite*/2defineSuite([3 'Core/ComponentDatatype',4 'Core/Geometry',5 'Core/GeometryAttribute',6 'Core/GeometryPipeline',7 'Core/IndexDatatype',8 'Core/PrimitiveType',9 'Renderer/BufferUsage',10 'Renderer/ClearCommand',11 'Renderer/DrawCommand',12 'Renderer/ShaderProgram',13 'Renderer/VertexArray',14 'Specs/createContext'15 ], 'Renderer/VertexArrayFactory', function(16 ComponentDatatype,17 Geometry,18 GeometryAttribute,19 GeometryPipeline,20 IndexDatatype,21 PrimitiveType,22 BufferUsage,23 ClearCommand,24 DrawCommand,25 ShaderProgram,26 VertexArray,27 createContext) {28 'use strict';2930 var context;31 var va;32 var sp;3334 beforeAll(function() {35 context = createContext();36 });3738 afterAll(function() {39 context.destroyForSpecs();40 });4142 afterEach(function() {43 va = va && va.destroy();44 sp = sp && sp.destroy();45 });4647 it('throws when there is no context', function() {48 expect(function() {49 return VertexArray.fromGeometry();50 }).toThrowDeveloperError();51 });5253 it('creates with no optional arguments', function() {54 va = VertexArray.fromGeometry({55 context : context56 });57 expect(va.numberOfAttributes).toEqual(0);58 expect(va.indexBuffer).not.toBeDefined();59 });6061 it('creates with no geometry', function() {62 va = VertexArray.fromGeometry({63 context : context,64 interleave : true65 });66 expect(va.numberOfAttributes).toEqual(0);67 expect(va.indexBuffer).not.toBeDefined();68 });6970 it('creates a single-attribute vertex (non-interleaved)', function() {71 var geometry = new Geometry({72 attributes : {73 position : new GeometryAttribute({74 componentDatatype : ComponentDatatype.FLOAT,75 componentsPerAttribute : 3,76 values : [0.0, 0.0, 0.0, 1.0, 1.0, 1.0]77 })78 },79 primitiveType : PrimitiveType.POINTS80 });8182 var va = VertexArray.fromGeometry({83 context : context,84 geometry : geometry,85 attributeLocations : GeometryPipeline.createAttributeLocations(geometry)86 });8788 expect(va.numberOfAttributes).toEqual(1);89 expect(va.indexBuffer).not.toBeDefined();9091 var position = geometry.attributes.position;92 expect(va.getAttribute(0).index).toEqual(0);93 expect(va.getAttribute(0).componentDatatype).toEqual(position.componentDatatype);94 expect(va.getAttribute(0).componentsPerAttribute).toEqual(position.componentsPerAttribute);95 expect(va.getAttribute(0).offsetInBytes).toEqual(0);96 expect(va.getAttribute(0).strideInBytes).toEqual(0); // Tightly packed9798 expect(va.getAttribute(0).vertexBuffer.usage).toEqual(BufferUsage.DYNAMIC_DRAW); // Default99 });100101 it('creates a single-attribute vertex (interleaved)', function() {102 var geometry = new Geometry({103 attributes : {104 position : new GeometryAttribute({105 componentDatatype : ComponentDatatype.FLOAT,106 componentsPerAttribute : 3,107 values : [0.0, 0.0, 0.0, 1.0, 1.0, 1.0]108 })109 },110 primitiveType : PrimitiveType.POINTS111 });112113 var va = VertexArray.fromGeometry({114 context : context,115 geometry : geometry,116 attributeLocations : GeometryPipeline.createAttributeLocations(geometry),117 interleave : true,118 bufferUsage : BufferUsage.STATIC_DRAW119 });120121 expect(va.numberOfAttributes).toEqual(1);122 expect(va.indexBuffer).not.toBeDefined();123124 var position = geometry.attributes.position;125 expect(va.getAttribute(0).index).toEqual(0);126 expect(va.getAttribute(0).componentDatatype).toEqual(position.componentDatatype);127 expect(va.getAttribute(0).componentsPerAttribute).toEqual(position.componentsPerAttribute);128 expect(va.getAttribute(0).offsetInBytes).toEqual(0);129 expect(va.getAttribute(0).strideInBytes).toEqual(ComponentDatatype.getSizeInBytes(position.componentDatatype) * position.componentsPerAttribute);130131 expect(va.getAttribute(0).vertexBuffer.usage).toEqual(BufferUsage.STATIC_DRAW);132 });133134 it('creates a homogeneous multiple-attribute vertex (non-interleaved)', function() {135 var geometry = new Geometry({136 attributes : {137 customPosition : new GeometryAttribute({138 componentDatatype : ComponentDatatype.FLOAT,139 componentsPerAttribute : 3,140 values : [0.0, 0.0, 0.0, 2.0, 2.0, 2.0]141 }),142 customNormal : new GeometryAttribute({143 componentDatatype : ComponentDatatype.FLOAT,144 componentsPerAttribute : 3,145 values : [1.0, 1.0, 1.0, 3.0, 3.0, 3.0]146 })147 },148 primitiveType : PrimitiveType.POINTS149 });150151 var va = VertexArray.fromGeometry({152 context : context,153 geometry : geometry,154 attributeLocations : GeometryPipeline.createAttributeLocations(geometry)155 });156157 expect(va.numberOfAttributes).toEqual(2);158 expect(va.indexBuffer).not.toBeDefined();159160 var position = geometry.attributes.customPosition;161 expect(va.getAttribute(0).index).toEqual(0);162 expect(va.getAttribute(0).componentDatatype).toEqual(position.componentDatatype);163 expect(va.getAttribute(0).componentsPerAttribute).toEqual(position.componentsPerAttribute);164 expect(va.getAttribute(0).offsetInBytes).toEqual(0);165 expect(va.getAttribute(0).strideInBytes).toEqual(0); // Tightly packed166167 var normal = geometry.attributes.customNormal;168 expect(va.getAttribute(1).index).toEqual(1);169 expect(va.getAttribute(1).componentDatatype).toEqual(normal.componentDatatype);170 expect(va.getAttribute(1).componentsPerAttribute).toEqual(normal.componentsPerAttribute);171 expect(va.getAttribute(1).offsetInBytes).toEqual(0);172 expect(va.getAttribute(1).strideInBytes).toEqual(0); // Tightly packed173174 expect(va.getAttribute(0).vertexBuffer).not.toBe(va.getAttribute(1).vertexBuffer);175 });176177 it('creates a homogeneous multiple-attribute vertex (interleaved)', function() {178 var geometry = new Geometry({179 attributes : {180 customPosition : new GeometryAttribute({181 componentDatatype : ComponentDatatype.FLOAT,182 componentsPerAttribute : 3,183 values : [0.0, 0.0, 0.0, 2.0, 2.0, 2.0]184 }),185 customNormal : new GeometryAttribute({186 componentDatatype : ComponentDatatype.FLOAT,187 componentsPerAttribute : 3,188 values : [1.0, 1.0, 1.0, 3.0, 3.0, 3.0]189 })190 },191 primitiveType : PrimitiveType.POINTS192 });193194 var va = VertexArray.fromGeometry({195 context : context,196 geometry : geometry,197 attributeLocations : GeometryPipeline.createAttributeLocations(geometry),198 interleave : true199 });200201 expect(va.numberOfAttributes).toEqual(2);202 expect(va.indexBuffer).not.toBeDefined();203204 var position = geometry.attributes.customPosition;205 var normal = geometry.attributes.customNormal;206 var expectedStride = ComponentDatatype.getSizeInBytes(position.componentDatatype) * position.componentsPerAttribute + ComponentDatatype.getSizeInBytes(normal.componentDatatype) * normal.componentsPerAttribute;207208 expect(va.getAttribute(0).index).toEqual(0);209 expect(va.getAttribute(0).componentDatatype).toEqual(position.componentDatatype);210 expect(va.getAttribute(0).componentsPerAttribute).toEqual(position.componentsPerAttribute);211 expect(va.getAttribute(0).offsetInBytes).toEqual(0);212 expect(va.getAttribute(0).strideInBytes).toEqual(expectedStride);213214 expect(va.getAttribute(1).index).toEqual(1);215 expect(va.getAttribute(1).componentDatatype).toEqual(normal.componentDatatype);216 expect(va.getAttribute(1).componentsPerAttribute).toEqual(normal.componentsPerAttribute);217 expect(va.getAttribute(1).offsetInBytes).toEqual(ComponentDatatype.getSizeInBytes(position.componentDatatype) * position.componentsPerAttribute);218 expect(va.getAttribute(1).strideInBytes).toEqual(expectedStride);219220 expect(va.getAttribute(0).vertexBuffer).toBe(va.getAttribute(1).vertexBuffer);221 });222223 it('creates a heterogeneous multiple-attribute vertex (interleaved)', function() {224 var geometry = new Geometry({225 attributes : {226 position : new GeometryAttribute({227 componentDatatype : ComponentDatatype.FLOAT,228 componentsPerAttribute : 3,229 values : [0.0, 0.0, 0.0, 2.0, 2.0, 2.0]230 }),231 colors : new GeometryAttribute({232 componentDatatype : ComponentDatatype.UNSIGNED_BYTE,233 componentsPerAttribute : 4,234 values : [1, 1, 1, 1, 2, 2, 2, 2]235 })236 },237 primitiveType : PrimitiveType.POINTS238 });239240 var va = VertexArray.fromGeometry({241 context : context,242 geometry : geometry,243 attributeLocations : GeometryPipeline.createAttributeLocations(geometry),244 interleave : true245 });246247 expect(va.numberOfAttributes).toEqual(2);248 expect(va.indexBuffer).not.toBeDefined();249250 var position = geometry.attributes.position;251 var colors = geometry.attributes.colors;252 var expectedStride = ComponentDatatype.getSizeInBytes(position.componentDatatype) * position.componentsPerAttribute + ComponentDatatype.getSizeInBytes(colors.componentDatatype) * colors.componentsPerAttribute;253254 expect(va.getAttribute(0).index).toEqual(0);255 expect(va.getAttribute(0).componentDatatype).toEqual(position.componentDatatype);256 expect(va.getAttribute(0).componentsPerAttribute).toEqual(position.componentsPerAttribute);257 expect(va.getAttribute(0).offsetInBytes).toEqual(0);258 expect(va.getAttribute(0).strideInBytes).toEqual(expectedStride);259260 expect(va.getAttribute(1).index).toEqual(1);261 expect(va.getAttribute(1).componentDatatype).toEqual(colors.componentDatatype);262 expect(va.getAttribute(1).componentsPerAttribute).toEqual(colors.componentsPerAttribute);263 expect(va.getAttribute(1).offsetInBytes).toEqual(ComponentDatatype.getSizeInBytes(position.componentDatatype) * position.componentsPerAttribute);264 expect(va.getAttribute(1).strideInBytes).toEqual(expectedStride);265266 expect(va.getAttribute(0).vertexBuffer).toBe(va.getAttribute(1).vertexBuffer);267 });268269 it('sorts interleaved attributes from large to small components', function() {270 var geometry = new Geometry({271 attributes : {272 bytes : new GeometryAttribute({273 componentDatatype : ComponentDatatype.BYTE,274 componentsPerAttribute : 1,275 values : [0]276 }),277 shorts : new GeometryAttribute({278 componentDatatype : ComponentDatatype.SHORT,279 componentsPerAttribute : 1,280 values : [1]281 }),282 floats : new GeometryAttribute({283 componentDatatype : ComponentDatatype.FLOAT,284 componentsPerAttribute : 1,285 values : [2]286 })287 },288 primitiveType : PrimitiveType.POINTS289 });290291 var attributeLocations = GeometryPipeline.createAttributeLocations(geometry);292 var va = VertexArray.fromGeometry({293 context : context,294 geometry : geometry,295 attributeLocations : attributeLocations,296 interleave : true297 });298299 expect(va.numberOfAttributes).toEqual(3);300301 var vertexBuffer = va.getAttribute(0).vertexBuffer;302 expect(vertexBuffer).toBe(va.getAttribute(1).vertexBuffer);303 expect(vertexBuffer).toBe(va.getAttribute(2).vertexBuffer);304 expect(vertexBuffer.sizeInBytes).toEqual(8); // Includes 1 byte per-vertex padding305306 // Validate via rendering307 var vs =308 'attribute float bytes; ' +309 'attribute float shorts; ' +310 'attribute float floats; ' +311 'varying vec4 fsColor; ' +312 'void main() { ' +313 ' gl_PointSize = 1.0; ' +314 ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0); ' +315 ' fsColor = vec4((bytes == 0.0) && (shorts == 1.0) && (floats == 2.0)); ' +316 '}';317 var fs =318 'varying vec4 fsColor; ' +319 'void main() { ' +320 ' gl_FragColor = fsColor; ' +321 '}';322323 sp = ShaderProgram.fromCache({324 context : context,325 vertexShaderSource : vs,326 fragmentShaderSource : fs,327 attributeLocations : attributeLocations328 });329330 ClearCommand.ALL.execute(context);331 expect(context).toReadPixels([0, 0, 0, 255]);332333 var command = new DrawCommand({334 primitiveType : PrimitiveType.POINTS,335 shaderProgram : sp,336 vertexArray : va337 });338 command.execute(context);339 expect(context).toReadPixels([255, 255, 255, 255]);340 });341342 it('sorts interleaved attributes from large to small components (2)', function() {343 var geometry = new Geometry({344 attributes : {345 color : new GeometryAttribute({346 componentDatatype : ComponentDatatype.UNSIGNED_BYTE,347 componentsPerAttribute : 4,348 normalize : true,349 values : [255, 0, 0, 255, 0, 255, 0, 255]350 }),351 position : new GeometryAttribute({352 componentDatatype : ComponentDatatype.FLOAT,353 componentsPerAttribute : 3,354 values : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]355 })356 },357 primitiveType : PrimitiveType.POINTS358 });359360 var attributeLocations = GeometryPipeline.createAttributeLocations(geometry);361 var va = VertexArray.fromGeometry({362 context : context,363 geometry : geometry,364 attributeLocations : attributeLocations,365 interleave : true366 });367368 expect(va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(32); // No per-vertex padding needed369370 // Validate via rendering371 var vs =372 'attribute vec3 position; ' +373 'attribute vec4 color; ' +374 'varying vec4 fsColor; ' +375 'void main() { ' +376 ' gl_PointSize = 1.0; ' +377 ' gl_Position = vec4(position, 1.0); ' +378 ' fsColor = color; ' +379 '}';380 var fs =381 'varying vec4 fsColor; ' +382 'void main() { ' +383 ' gl_FragColor = fsColor; ' +384 '}';385 sp = ShaderProgram.fromCache({386 context : context,387 vertexShaderSource : vs,388 fragmentShaderSource : fs,389 attributeLocations : attributeLocations390 });391392 ClearCommand.ALL.execute(context);393 expect(context).toReadPixels([0, 0, 0, 255]);394395 var command = new DrawCommand({396 primitiveType : PrimitiveType.POINTS,397 shaderProgram : sp,398 vertexArray : va,399 offset : 0,400 count : 1401 });402 command.execute(context);403 expect(context).toReadPixels([255, 0, 0, 255]);404405 command = new DrawCommand({406 primitiveType : PrimitiveType.POINTS,407 shaderProgram : sp,408 vertexArray : va,409 offset : 1,410 count : 1411 });412 command.execute(context);413 expect(context).toReadPixels([0, 255, 0, 255]);414 });415416 it('sorts interleaved attributes from large to small components (3)', function() {417 var geometry = new Geometry({418 attributes : {419 unsignedByteAttribute : new GeometryAttribute({420 componentDatatype : ComponentDatatype.UNSIGNED_BYTE,421 componentsPerAttribute : 2,422 values : [1, 2]423 }),424 unsignedShortAttribute : new GeometryAttribute({425 componentDatatype : ComponentDatatype.UNSIGNED_SHORT,426 componentsPerAttribute : 1,427 values : [3]428 }),429 byteAttribute : new GeometryAttribute({430 componentDatatype : ComponentDatatype.BYTE,431 componentsPerAttribute : 1,432 values : [4]433 }),434 shortAttribute : new GeometryAttribute({435 componentDatatype : ComponentDatatype.SHORT,436 componentsPerAttribute : 1,437 values : [5]438 })439 },440 primitiveType : PrimitiveType.POINTS441 });442443 var attributeLocations = GeometryPipeline.createAttributeLocations(geometry);444 var va = VertexArray.fromGeometry({445 context : context,446 geometry : geometry,447 attributeLocations : attributeLocations,448 interleave : true449 });450451 expect(va.numberOfAttributes).toEqual(4);452 expect(va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(8); // Includes 1 byte per-vertex padding453454 // Validate via rendering455 var vs =456 'attribute vec2 unsignedByteAttribute; ' +457 'attribute float unsignedShortAttribute; ' +458 'attribute float byteAttribute; ' +459 'attribute float shortAttribute; ' +460 'varying vec4 fsColor; ' +461 'void main() { ' +462 ' gl_PointSize = 1.0; ' +463 ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0); ' +464 ' fsColor = vec4((unsignedByteAttribute.x == 1.0) && (unsignedByteAttribute.y == 2.0) && (unsignedShortAttribute == 3.0) && (byteAttribute == 4.0) && (shortAttribute == 5.0)); ' +465 '}';466 var fs =467 'varying vec4 fsColor; ' +468 'void main() { ' +469 ' gl_FragColor = fsColor; ' +470 '}';471 sp = ShaderProgram.fromCache({472 context : context,473 vertexShaderSource : vs,474 fragmentShaderSource : fs,475 attributeLocations : attributeLocations476 });477478 ClearCommand.ALL.execute(context);479 expect(context).toReadPixels([0, 0, 0, 255]);480481 var command = new DrawCommand({482 primitiveType : PrimitiveType.POINTS,483 shaderProgram : sp,484 vertexArray : va485 });486 command.execute(context);487 expect(context).toReadPixels([255, 255, 255, 255]);488 });489490 it('creates a custom interleaved vertex', function() {491 var geometry = new Geometry({492 attributes : {493 position : new GeometryAttribute({494 componentDatatype : ComponentDatatype.FLOAT,495 componentsPerAttribute : 3,496 values : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]497 }),498 color : new GeometryAttribute({499 componentDatatype : ComponentDatatype.UNSIGNED_BYTE,500 componentsPerAttribute : 3,501 normalize : true,502 values : [255, 0, 0, 0, 255, 0]503 }),504 normal : new GeometryAttribute({505 componentDatatype : ComponentDatatype.FLOAT,506 componentsPerAttribute : 3,507 values : [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]508 }),509 temperature : new GeometryAttribute({510 componentDatatype : ComponentDatatype.UNSIGNED_SHORT,511 componentsPerAttribute : 1,512 values : [75, 100]513 })514 },515 primitiveType : PrimitiveType.POINTS516 });517518 var attributeLocations = GeometryPipeline.createAttributeLocations(geometry);519 var va = VertexArray.fromGeometry({520 context : context,521 geometry : geometry,522 attributeLocations : attributeLocations,523 interleave : true524 });525526 expect(va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(2 * 32); // Includes 3 byte per-vertex padding527528 // Validate via rendering529 var vs =530 'attribute vec3 position; ' +531 'attribute vec3 color; ' +532 'attribute vec3 normal; ' +533 'attribute float temperature; ' +534 'varying vec4 fsColor; ' +535 'void main() { ' +536 ' gl_PointSize = 1.0; ' +537 ' gl_Position = vec4(position, 1.0); ' +538 ' if ((normal == vec3(1.0, 0.0, 0.0)) && (temperature == 75.0)) { ' +539 ' fsColor = vec4(color, 1.0); ' +540 ' } ' +541 ' else {' +542 ' fsColor = vec4(1.0); ' +543 ' }' +544 '}';545 var fs =546 'varying vec4 fsColor; ' +547 'void main() { ' +548 ' gl_FragColor = fsColor; ' +549 '}';550 sp = ShaderProgram.fromCache({551 context : context,552 vertexShaderSource : vs,553 fragmentShaderSource : fs,554 attributeLocations : attributeLocations555 });556557 ClearCommand.ALL.execute(context);558 expect(context).toReadPixels([0, 0, 0, 255]);559560 var command = new DrawCommand({561 primitiveType : PrimitiveType.POINTS,562 shaderProgram : sp,563 vertexArray : va,564 offset : 0,565 count : 1566 });567 command.execute(context);568 expect(context).toReadPixels([255, 0, 0, 255]);569570 var vs2 =571 'attribute vec3 position; ' +572 'attribute vec3 color; ' +573 'attribute vec3 normal; ' +574 'attribute float temperature; ' +575 'varying vec4 fsColor; ' +576 'void main() { ' +577 ' gl_PointSize = 1.0; ' +578 ' gl_Position = vec4(position, 1.0); ' +579 ' if ((normal == vec3(0.0, 1.0, 0.0)) && (temperature == 100.0)) { ' +580 ' fsColor = vec4(color, 1.0); ' +581 ' } ' +582 ' else {' +583 ' fsColor = vec4(1.0); ' +584 ' }' +585 '}';586 sp = sp.destroy();587 sp = ShaderProgram.fromCache({588 context : context,589 vertexShaderSource : vs2,590 fragmentShaderSource : fs,591 attributeLocations : attributeLocations592 });593594 command = new DrawCommand({595 primitiveType : PrimitiveType.POINTS,596 shaderProgram : sp,597 vertexArray : va,598 offset : 1,599 count : 1600 });601 command.execute(context);602 expect(context).toReadPixels([0, 255, 0, 255]);603 });604605 it('creates an index buffer', function() {606 var geometry = new Geometry({607 attributes : {},608 indices : [0],609 primitiveType : PrimitiveType.POINTS610 });611612 var va = VertexArray.fromGeometry({613 context : context,614 geometry : geometry615 });616617 expect(va.numberOfAttributes).toEqual(0);618 expect(va.indexBuffer).toBeDefined();619 expect(va.indexBuffer.usage).toEqual(BufferUsage.DYNAMIC_DRAW); // Default620 expect(va.indexBuffer.indexDatatype).toEqual(IndexDatatype.UNSIGNED_SHORT);621 expect(va.indexBuffer.numberOfIndices).toEqual(geometry.indices.length);622 });623624 it('throws with different number of interleaved attributes', function() {625 var geometry = new Geometry({626 attributes : {627 position : new GeometryAttribute({628 componentDatatype : ComponentDatatype.FLOAT,629 componentsPerAttribute : 1,630 values : [0.0]631 }),632 normal : new GeometryAttribute({633 componentDatatype : ComponentDatatype.FLOAT,634 componentsPerAttribute : 1,635 values : [1.0, 2.0]636 })637 },638 primitiveType : PrimitiveType.POINTS639 });640641 expect(function() {642 return VertexArray.fromGeometry({643 context : context,644 geometry : geometry,645 interleave : true646 });647 }).toThrowRuntimeError();648 });649650 it('throws with duplicate indices', function() {651 var geometry = new Geometry({652 attributes : {653 position : new GeometryAttribute({654 componentDatatype : ComponentDatatype.FLOAT,655 componentsPerAttribute : 1,656 values : [0.0]657 }),658 normal : new GeometryAttribute({659 componentDatatype : ComponentDatatype.FLOAT,660 componentsPerAttribute : 1,661 values : [1.0]662 })663 },664 primitiveType : PrimitiveType.POINTS665 });666667 expect(function() {668 return VertexArray.fromGeometry({669 context : context,670 geometry : geometry,671 attributeLocations : {672 position : 0,673 normal : 0674 }675 });676 }).toThrowDeveloperError();677 }); ...

Full Screen

Full Screen

VertexArraySpec.js

Source:VertexArraySpec.js Github

copy

Full Screen

1/*global defineSuite*/2defineSuite([3 'Renderer/VertexArray',4 'Core/ComponentDatatype',5 'Core/PrimitiveType',6 'Renderer/Buffer',7 'Renderer/BufferUsage',8 'Renderer/DrawCommand',9 'Renderer/ShaderProgram',10 'Specs/createContext'11 ], function(12 VertexArray,13 ComponentDatatype,14 PrimitiveType,15 Buffer,16 BufferUsage,17 DrawCommand,18 ShaderProgram,19 createContext) {20 'use strict';2122 var context;2324 beforeAll(function() {25 context = createContext();26 });2728 afterAll(function() {29 context.destroyForSpecs();30 });3132 it('binds', function() {33 var positionBuffer = Buffer.createVertexBuffer({34 context : context,35 sizeInBytes : 3,36 usage : BufferUsage.STATIC_DRAW37 });3839 var attributes = [{40 index : 0,41 enabled : true,42 vertexBuffer : positionBuffer,43 componentsPerAttribute : 3,44 componentDatatype : ComponentDatatype.FLOAT,45 normalize : false,46 offsetInBytes : 0,47 strideInBytes : 0,48 instanceDivisor : 049 // tightly packed50 }];5152 var va = new VertexArray({53 context : context,54 attributes : attributes55 });56 va._bind();57 va._unBind();58 va = va.destroy();59 });6061 it('binds with default values', function() {62 var positionBuffer = Buffer.createVertexBuffer({63 context : context,64 sizeInBytes : 3,65 usage : BufferUsage.STATIC_DRAW66 });6768 var attributes = [{69 vertexBuffer : positionBuffer,70 componentsPerAttribute : 371 }];7273 var va = new VertexArray({74 context : context,75 attributes : attributes76 });7778 expect(va.numberOfAttributes).toEqual(1);79 expect(va.getAttribute(0).index).toEqual(0);80 expect(va.getAttribute(0).enabled).toEqual(true);81 expect(va.getAttribute(0).vertexBuffer).toEqual(positionBuffer);82 expect(va.getAttribute(0).componentsPerAttribute).toEqual(3);83 expect(va.getAttribute(0).componentDatatype).toEqual(ComponentDatatype.FLOAT);84 expect(va.getAttribute(0).normalize).toEqual(false);85 expect(va.getAttribute(0).offsetInBytes).toEqual(0);86 expect(va.getAttribute(0).strideInBytes).toEqual(0);87 expect(va.getAttribute(0).instanceDivisor).toEqual(0);8889 va._bind();90 va._unBind();91 va = va.destroy();92 });9394 it('binds with multiple buffers', function() {95 var attributeSize = 3 * Float32Array.BYTES_PER_ELEMENT;96 var positionBuffer = Buffer.createVertexBuffer({97 context : context,98 sizeInBytes : attributeSize,99 usage : BufferUsage.STATIC_DRAW100 });101 var normalBuffer = Buffer.createVertexBuffer({102 context : context,103 sizeInBytes : attributeSize,104 usage : BufferUsage.STATIC_DRAW105 });106107 var attributes = [{108 index : 0,109 vertexBuffer : positionBuffer,110 componentsPerAttribute : 3,111 componentDatatype : ComponentDatatype.FLOAT112 }, {113 index : 1,114 vertexBuffer : normalBuffer,115 componentsPerAttribute : 3,116 componentDatatype : ComponentDatatype.FLOAT117 }];118119 var va = new VertexArray({120 context : context,121 attributes : attributes122 });123124 expect(va.numberOfAttributes).toEqual(2);125 va._bind();126 va._unBind();127 va = va.destroy();128 });129130 it('binds with interleaved buffer', function() {131 var attributeSize = 3 * Float32Array.BYTES_PER_ELEMENT;132 var buffer = Buffer.createVertexBuffer({133 context : context,134 sizeInBytes : attributeSize,135 usage : BufferUsage.STATIC_DRAW136 });137138 var attributes = [{139 vertexBuffer : buffer,140 componentsPerAttribute : 3,141 componentDatatype : ComponentDatatype.FLOAT,142 offsetInBytes : 0,143 strideInBytes : 2 * attributeSize144 }, {145 vertexBuffer : buffer,146 componentsPerAttribute : 3,147 componentDatatype : ComponentDatatype.FLOAT,148 normalize : true,149 offsetInBytes : attributeSize,150 strideInBytes : 2 * attributeSize151 }];152153 var va = new VertexArray({154 context : context,155 attributes : attributes156 });157158 expect(va.numberOfAttributes).toEqual(2);159 va._bind();160 va._unBind();161 va = va.destroy();162 });163164 it('adds attributes', function() {165 var positionBuffer = Buffer.createVertexBuffer({166 context : context,167 sizeInBytes : 3,168 usage : BufferUsage.STATIC_DRAW169 });170171 var va = new VertexArray({172 context : context,173 attributes : [{174 vertexBuffer : positionBuffer,175 componentsPerAttribute : 3176 }]177 });178179 expect(va.numberOfAttributes).toEqual(1);180 expect(va.getAttribute(0).index).toEqual(0);181 expect(va.getAttribute(0).enabled).toEqual(true);182 expect(va.getAttribute(0).vertexBuffer).toEqual(positionBuffer);183 expect(va.getAttribute(0).componentsPerAttribute).toEqual(3);184 expect(va.getAttribute(0).componentDatatype).toEqual(ComponentDatatype.FLOAT);185 expect(va.getAttribute(0).normalize).toEqual(false);186 expect(va.getAttribute(0).offsetInBytes).toEqual(0);187 expect(va.getAttribute(0).strideInBytes).toEqual(0);188 expect(va.getAttribute(0).instanceDivisor).toEqual(0);189190 va = va.destroy();191 });192193 it('modifies attributes', function() {194 var buffer = Buffer.createVertexBuffer({195 context : context,196 sizeInBytes : 6,197 usage : BufferUsage.STATIC_DRAW198 });199200 var attributes = [{201 vertexBuffer : buffer,202 componentsPerAttribute : 3203 }];204205 var va = new VertexArray({206 context : context,207 attributes : attributes208 });209210 expect(va.numberOfAttributes).toEqual(1);211 expect(va.getAttribute(0).enabled).toEqual(true);212213 va.getAttribute(0).enabled = false;214 expect(va.getAttribute(0).enabled).toEqual(false);215216 va._bind();217 va._unBind();218 va = va.destroy();219 });220221 // The following specs test draw calls that pull from a constant attribute.222 // Due to what I believe is a range checking bug in Firefox (Section 6.4 of223 // the WebGL spec), an attribute backed by a buffer must also be bound,224 // otherwise drawArrays unjustly reports an INVALID_OPERATION, hence the225 // firefoxWorkaround attribute below. In practice, we will always have226 // an attribute backed by a buffer anyway.227228 it('renders with a one-component constant value', function() {229 var vs =230 'attribute float firefoxWorkaround;' +231 'attribute float attr;' +232 'varying vec4 v_color;' +233 'void main() { ' +234 ' v_color = vec4(attr == 0.5) + vec4(firefoxWorkaround);' +235 ' gl_PointSize = 1.0;' +236 ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0);' +237 '}';238 var fs =239 'varying vec4 v_color;' +240 'void main() { gl_FragColor = v_color; }';241 var sp = ShaderProgram.fromCache({242 context : context,243 vertexShaderSource : vs,244 fragmentShaderSource : fs,245 attributeLocations : {246 firefoxWorkaround : 0,247 attr : 1248 }249 });250251 var va = new VertexArray({252 context : context,253 attributes : [{254 vertexBuffer : Buffer.createVertexBuffer({255 context : context,256 sizeInBytes : Float32Array.BYTES_PER_ELEMENT,257 usage : BufferUsage.STATIC_DRAW258 }),259 componentsPerAttribute : 1260 }, {261 value : [0.5]262 }]263 });264265 var command = new DrawCommand({266 primitiveType : PrimitiveType.POINTS,267 shaderProgram : sp,268 vertexArray : va,269 count : 1270 });271 command.execute(context);272273 expect(context).toReadPixels([255, 255, 255, 255]);274275 sp = sp.destroy();276 va = va.destroy();277 });278279 it('renders with a two-component constant value', function() {280 var vs =281 'attribute float firefoxWorkaround;' +282 'attribute vec2 attr;' +283 'varying vec4 v_color;' +284 'void main() { ' +285 ' v_color = vec4(attr == vec2(0.25, 0.75)) + vec4(firefoxWorkaround);' +286 ' gl_PointSize = 1.0;' +287 ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0);' +288 '}';289 var fs =290 'varying vec4 v_color;' +291 'void main() { gl_FragColor = v_color; }';292 var sp = ShaderProgram.fromCache({293 context : context,294 vertexShaderSource : vs,295 fragmentShaderSource : fs,296 attributeLocations : {297 firefoxWorkaround : 0,298 attr : 1299 }300 });301302 var va = new VertexArray({303 context : context,304 attributes : [{305 vertexBuffer : Buffer.createVertexBuffer({306 context : context,307 sizeInBytes : Float32Array.BYTES_PER_ELEMENT,308 usage : BufferUsage.STATIC_DRAW309 }),310 componentsPerAttribute : 1311 }, {312 value : [0.25, 0.75]313 }]314 });315316 var command = new DrawCommand({317 primitiveType : PrimitiveType.POINTS,318 shaderProgram : sp,319 vertexArray : va,320 count : 1321 });322 command.execute(context);323324 expect(context).toReadPixels([255, 255, 255, 255]);325326 sp = sp.destroy();327 va = va.destroy();328 });329330 it('renders with a three-component constant value', function() {331 var vs =332 'attribute float firefoxWorkaround;' +333 'attribute vec3 attr;' +334 'varying vec4 v_color;' +335 'void main() { ' +336 ' v_color = vec4(attr == vec3(0.25, 0.5, 0.75)) + vec4(firefoxWorkaround);' +337 ' gl_PointSize = 1.0;' +338 ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0);' +339 '}';340 var fs =341 'varying vec4 v_color;' +342 'void main() { gl_FragColor = v_color; }';343 var sp = ShaderProgram.fromCache({344 context : context,345 vertexShaderSource : vs,346 fragmentShaderSource : fs,347 attributeLocations : {348 firefoxWorkaround : 0,349 attr : 1350 }351 });352353 var va = new VertexArray({354 context : context,355 attributes : [{356 vertexBuffer : Buffer.createVertexBuffer({357 context : context,358 sizeInBytes : Float32Array.BYTES_PER_ELEMENT,359 usage : BufferUsage.STATIC_DRAW360 }),361 componentsPerAttribute : 1362 }, {363 value : [0.25, 0.5, 0.75]364 }]365 });366367 var command = new DrawCommand({368 primitiveType : PrimitiveType.POINTS,369 shaderProgram : sp,370 vertexArray : va,371 count : 1372 });373 command.execute(context);374375 expect(context).toReadPixels([255, 255, 255, 255]);376377 sp = sp.destroy();378 va = va.destroy();379 });380381 it('renders with a four-component constant value', function() {382 var vs =383 'attribute float firefoxWorkaround;' +384 'attribute vec4 attr;' +385 'varying vec4 v_color;' +386 'void main() { ' +387 ' v_color = vec4(attr == vec4(0.2, 0.4, 0.6, 0.8)) + vec4(firefoxWorkaround);' +388 ' gl_PointSize = 1.0;' +389 ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0);' +390 '}';391 var fs =392 'varying vec4 v_color;' +393 'void main() { gl_FragColor = v_color; }';394 var sp = ShaderProgram.fromCache({395 context : context,396 vertexShaderSource : vs,397 fragmentShaderSource : fs,398 attributeLocations : {399 firefoxWorkaround : 0,400 attr : 1401 }402 });403404 var va = new VertexArray({405 context : context,406 attributes : [{407 vertexBuffer : Buffer.createVertexBuffer({408 context : context,409 sizeInBytes : Float32Array.BYTES_PER_ELEMENT,410 usage : BufferUsage.STATIC_DRAW411 }),412 componentsPerAttribute : 1413 }, {414 value : [0.2, 0.4, 0.6, 0.8]415 }]416 });417418 var command = new DrawCommand({419 primitiveType : PrimitiveType.POINTS,420 shaderProgram : sp,421 vertexArray : va,422 count : 1423 });424 command.execute(context);425426 expect(context).toReadPixels([255, 255, 255, 255]);427428 sp = sp.destroy();429 va = va.destroy();430 });431432 it('renders two vertex arrays with constant values', function() {433 var vs =434 'attribute float firefoxWorkaround;' +435 'attribute vec4 attr;' +436 'varying vec4 v_color;' +437 'void main() { ' +438 ' v_color = attr + vec4(firefoxWorkaround);' +439 ' gl_PointSize = 1.0;' +440 ' gl_Position = vec4(0.0, 0.0, 0.0, 1.0);' +441 '}';442443 var fs =444 'varying vec4 v_color;' +445 'void main() { gl_FragColor = v_color; }';446447 var sp = ShaderProgram.fromCache({448 context : context,449 vertexShaderSource : vs,450 fragmentShaderSource : fs,451 attributeLocations : {452 firefoxWorkaround : 0,453 attr : 1454 }455 });456457 var vertexBuffer = Buffer.createVertexBuffer({458 context : context,459 sizeInBytes : Float32Array.BYTES_PER_ELEMENT,460 usage : BufferUsage.STATIC_DRAW461 });462463 var vaRed = new VertexArray({464 context : context,465 attributes : [{466 vertexBuffer : vertexBuffer,467 componentsPerAttribute : 1468 }, {469 value : [1, 0, 0, 1]470 }]471 });472473 var vaGreen = new VertexArray({474 context : context,475 attributes : [{476 vertexBuffer : vertexBuffer,477 componentsPerAttribute : 1478 }, {479 value : [0, 1, 0, 1]480 }]481 });482483 var commandRed = new DrawCommand({484 primitiveType : PrimitiveType.POINTS,485 shaderProgram : sp,486 vertexArray : vaRed,487 count : 1488 });489490 var commandGreen = new DrawCommand({491 primitiveType : PrimitiveType.POINTS,492 shaderProgram : sp,493 vertexArray : vaGreen,494 count : 1495 });496497 commandRed.execute(context);498 expect(context).toReadPixels([255, 0, 0, 255]);499500 commandGreen.execute(context);501 expect(context).toReadPixels([0, 255, 0, 255]);502503 sp = sp.destroy();504 vaRed = vaRed.destroy();505 vaGreen = vaGreen.destroy();506 });507508 it('destroys', function() {509 var va = new VertexArray({510 context : context,511 attributes : [{512 vertexBuffer : Buffer.createVertexBuffer({513 context : context,514 sizeInBytes : new Float32Array([0, 0, 0, 1]),515 usage : BufferUsage.STATIC_DRAW516 }),517 componentsPerAttribute : 4518 }]519 });520521 expect(va.isDestroyed()).toEqual(false);522 va.destroy();523 expect(va.isDestroyed()).toEqual(true);524 });525526 it('fails to create (missing vertexBuffer and value)', function() {527 var attributes = [{528 componentsPerAttribute : 3529 }];530531 expect(function() {532 return new VertexArray({533 context : context,534 attributes : attributes535 });536 }).toThrowDeveloperError();537 });538539 it('fails to create (provides both vertexBuffer and value)', function() {540 var buffer = Buffer.createVertexBuffer({541 context : context,542 sizeInBytes : 3,543 usage : BufferUsage.STATIC_DRAW544 });545546 var attributes = [{547 vertexBuffer : buffer,548 value : [1, 2, 3],549 componentsPerAttribute : 3550 }];551552 expect(function() {553 return new VertexArray({554 context : context,555 attributes : attributes556 });557 }).toThrowDeveloperError();558 });559560 it('fails to create with duplicate indices', function() {561 var buffer = Buffer.createVertexBuffer({562 context : context,563 sizeInBytes : 1,564 usage : BufferUsage.STATIC_DRAW565 });566567 var attributes = [{568 index : 1,569 vertexBuffer : buffer,570 componentsPerAttribute : 1571 }, {572 index : 1,573 vertexBuffer : buffer,574 componentsPerAttribute : 1575 }];576577 expect(function() {578 return new VertexArray({579 context : context,580 attributes : attributes581 });582 }).toThrowDeveloperError();583 });584585 it('fails to create (componentsPerAttribute missing)', function() {586 var buffer = Buffer.createVertexBuffer({587 context : context,588 sizeInBytes : 3,589 usage : BufferUsage.STATIC_DRAW590 });591592 var attributes = [{593 vertexBuffer : buffer594 }];595596 expect(function() {597 return new VertexArray({598 context : context,599 attributes : attributes600 });601 }).toThrowDeveloperError();602 });603604 it('fails to create (componentsPerAttribute < 1)', function() {605 var attributes = [{606 componentsPerAttribute : 0607 }];608609 expect(function() {610 return new VertexArray({611 context : context,612 attributes : attributes613 });614 }).toThrowDeveloperError();615 });616617 it('fails to create (componentsPerAttribute > 4)', function() {618 var attributes = [{619 componentsPerAttribute : 5620 }];621622 expect(function() {623 return new VertexArray({624 context : context,625 attributes : attributes626 });627 }).toThrowDeveloperError();628 });629630 it('fails to create (value.length < 1)', function() {631 var attributes = [{632 value : []633 }];634635 expect(function() {636 return new VertexArray({637 context : context,638 attributes : attributes639 });640 }).toThrowDeveloperError();641 });642643 it('fails to create (value.length > 4)', function() {644 var attributes = [{645 value : [1.0, 2.0, 3.0, 4.0, 5.0]646 }];647648 expect(function() {649 return new VertexArray({650 context : context,651 attributes : attributes652 });653 }).toThrowDeveloperError();654 });655656 it('fails to create (componentDatatype)', function() {657 var buffer = Buffer.createVertexBuffer({658 context : context,659 sizeInBytes : 3,660 usage : BufferUsage.STATIC_DRAW661 });662663 var attributes = [{664 vertexBuffer : buffer,665 componentsPerAttribute : 3,666 componentDatatype : 'invalid component datatype'667 }];668669 expect(function() {670 return new VertexArray({671 context : context,672 attributes : attributes673 });674 }).toThrowDeveloperError();675 });676677 it('fails to create (strideInBytes)', function() {678 var buffer = Buffer.createVertexBuffer({679 context : context,680 sizeInBytes : 3,681 usage : BufferUsage.STATIC_DRAW682 });683684 var attributes = [{685 vertexBuffer : buffer,686 componentsPerAttribute : 3,687 strideInBytes : 256688 }];689690 expect(function() {691 return new VertexArray({692 context : context,693 attributes : attributes694 });695 }).toThrowDeveloperError();696 });697698 it('fails to get attribute', function() {699 var attributes = [{700 value : [0.0, 0.0, 0.0],701 componentsPerAttribute : 3702 }];703704 var va = new VertexArray({705 context : context,706 attributes : attributes707 });708709 expect(function() {710 return va.getAttribute();711 }).toThrowDeveloperError();712 });713714 it('fails to destroy', function() {715 var attributes = [{716 value : [0.0, 0.0, 0.0],717 componentsPerAttribute : 3718 }];719720 var va = new VertexArray({721 context : context,722 attributes : attributes723 });724725 va.destroy();726727 expect(function() {728 va.destroy();729 }).toThrowDeveloperError();730 });731732 it('throws when there is no context', function() {733 expect(function() {734 return new VertexArray();735 }).toThrowDeveloperError();736 });737738 it('throws if instanceDivisor is less than zero', function() {739 var buffer = Buffer.createVertexBuffer({740 context : context,741 sizeInBytes : 3,742 usage : BufferUsage.STATIC_DRAW743 });744745 var attributes = [{746 vertexBuffer : buffer,747 componentsPerAttribute : 3,748 instanceDivisor : -1749 }];750751 expect(function() {752 return new VertexArray({753 context : context,754 attributes : attributes755 });756 }).toThrowDeveloperError();757 });758759 // Direct3D 9 requires vertex attribute zero to not be instanced. While ANGLE can work around this, it is best760 // to follow this convention. This test also guarantees that not all vertex attributes are instanced.761 it('throws if vertex attribute zero is instanced', function() {762 var buffer = Buffer.createVertexBuffer({763 context : context,764 sizeInBytes : 3,765 usage : BufferUsage.STATIC_DRAW766 });767768 var attributes = [{769 index : 0,770 vertexBuffer : buffer,771 componentsPerAttribute : 3,772 instanceDivisor : 1773 }, {774 index : 1,775 vertexBuffer : buffer,776 componentsPerAttribute : 3777 }];778779 expect(function() {780 return new VertexArray({781 context : context,782 attributes : attributes783 });784 }).toThrowDeveloperError();785 });786787 it('throws if an attribute has an instanceDivisor and is not backed by a buffer', function() {788 var buffer = Buffer.createVertexBuffer({789 context : context,790 sizeInBytes : 3,791 usage : BufferUsage.STATIC_DRAW792 });793794 var attributes = [{795 index : 0,796 vertexBuffer : buffer,797 componentsPerAttribute : 3798 }, {799 index : 1,800 value : [0.0, 0.0, 1.0],801 componentsPerAttribute : 3,802 instanceDivisor : 1803 }];804805 expect(function() {806 return new VertexArray({807 context : context,808 attributes : attributes809 });810 }).toThrowDeveloperError();811 });812813 it('throws when instanceDivisor is greater than zero and the instanced arrays extension is not supported.', function() {814 if (!context.instancedArrays) {815 var buffer = Buffer.createVertexBuffer({816 context : context,817 sizeInBytes : 3,818 usage : BufferUsage.STATIC_DRAW819 });820821 var attributes = [{822 index : 0,823 vertexBuffer : buffer,824 componentsPerAttribute : 3825 }, {826 index : 1,827 vertexBuffer : buffer,828 componentsPerAttribute : 3,829 instanceDivisor : 1830 }];831832 expect(function() {833 return new VertexArray({834 context : context,835 attributes : attributes836 });837 }).toThrowDeveloperError();838 }839 }); ...

Full Screen

Full Screen

VertexArrayFacadeSpec.js

Source:VertexArrayFacadeSpec.js Github

copy

Full Screen

1/*global defineSuite*/2defineSuite([3 'Renderer/VertexArrayFacade',4 'Core/ComponentDatatype',5 'Renderer/BufferUsage',6 'Specs/createContext'7 ], function(8 VertexArrayFacade,9 ComponentDatatype,10 BufferUsage,11 createContext) {12 'use strict';1314 var context;1516 beforeAll(function() {17 context = createContext();18 });1920 afterAll(function() {21 context.destroyForSpecs();22 });2324 it('creates a vertex array with static floats', function() {25 var positionIndex = 0;26 var vaf = new VertexArrayFacade(context, [{27 index : positionIndex,28 componentsPerAttribute : 3,29 componentDatatype : ComponentDatatype.FLOAT,30 usage : BufferUsage.STATIC_DRAW31 }], 1);3233 var writer = vaf.writers[positionIndex];34 expect(writer).toBeDefined();3536 writer(0, 1.0, 2.0, 3.0); // Write [1.0, 2.0, 3.0] at index zero.37 vaf.commit(); // Commit writes3839 expect(vaf.va[0].va.getAttribute(0).vertexBuffer).toBeDefined();40 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(1 * 3 * 4);41 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.usage).toEqual(BufferUsage.STATIC_DRAW);42 expect(vaf.va[0].va.getAttribute(0).componentsPerAttribute).toEqual(3);43 expect(vaf.va[0].va.getAttribute(0).componentDatatype).toEqual(ComponentDatatype.FLOAT);44 expect(vaf.va[0].va.getAttribute(0).offsetInBytes).toEqual(0);45 expect(vaf.va[0].va.getAttribute(0).strideInBytes).toEqual(3 * 4);46 });4748 it('resizes a vertex array with static floats', function() {49 var positionIndex = 0;50 var vaf = new VertexArrayFacade(context, [{51 index : positionIndex,52 componentsPerAttribute : 3,53 componentDatatype : ComponentDatatype.FLOAT,54 usage : BufferUsage.STATIC_DRAW55 }], 1);5657 var writer = vaf.writers[positionIndex];58 expect(writer).toBeDefined();5960 writer(0, 1.0, 2.0, 3.0); // Write [1.0, 2.0, 3.0] at index zero.6162 vaf.resize(2); // Two vertices63 writer(1, 1.0, 2.0, 3.0); // Write [4.0, 5.0, 6.0] at index one.64 vaf.commit(); // Commit writes6566 expect(vaf.va[0].va.getAttribute(0).vertexBuffer).toBeDefined();67 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(2 * 3 * 4);68 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.usage).toEqual(BufferUsage.STATIC_DRAW);69 expect(vaf.va[0].va.getAttribute(0).componentsPerAttribute).toEqual(3);70 expect(vaf.va[0].va.getAttribute(0).componentDatatype).toEqual(ComponentDatatype.FLOAT);71 expect(vaf.va[0].va.getAttribute(0).offsetInBytes).toEqual(0);72 expect(vaf.va[0].va.getAttribute(0).strideInBytes).toEqual(3 * 4);73 });7475 it('creates a vertex array with static floats and unsigned bytes', function() {76 var positionIndex = 0;77 var colorIndex = 2;78 var vaf = new VertexArrayFacade(context, [{79 index : positionIndex,80 componentsPerAttribute : 3,81 componentDatatype : ComponentDatatype.FLOAT,82 usage : BufferUsage.STATIC_DRAW83 }, {84 index : colorIndex,85 componentsPerAttribute : 4,86 componentDatatype : ComponentDatatype.UNSIGNED_BYTE,87 usage : BufferUsage.STATIC_DRAW88 }], 1);8990 var positionWriter = vaf.writers[positionIndex];91 var colorWriter = vaf.writers[colorIndex];9293 expect(positionWriter).toBeDefined();94 expect(colorWriter).toBeDefined();9596 positionWriter(0, 1.0, 2.0, 3.0); // Write position [1.0, 2.0, 3.0] at index zero.97 colorWriter(0, 0, 255, 0, 255); // Write color [0, 255, 0, 255] at index zero.98 vaf.commit(); // Commit writes99100 // Position attribute101 expect(vaf.va[0].va.getAttribute(0).vertexBuffer).toBeDefined();102 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(1 * ((3 * 4) + (4 * 1)));103 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.usage).toEqual(BufferUsage.STATIC_DRAW);104 expect(vaf.va[0].va.getAttribute(0).componentsPerAttribute).toEqual(3);105 expect(vaf.va[0].va.getAttribute(0).componentDatatype).toEqual(ComponentDatatype.FLOAT);106 expect(vaf.va[0].va.getAttribute(0).offsetInBytes).toEqual(0);107 expect(vaf.va[0].va.getAttribute(0).strideInBytes).toEqual((3 * 4) + (4 * 1));108109 // Color attribute110 expect(vaf.va[0].va.getAttribute(1).vertexBuffer).toEqual(vaf.va[0].va.getAttribute(0).vertexBuffer);111 expect(vaf.va[0].va.getAttribute(1).componentsPerAttribute).toEqual(4);112 expect(vaf.va[0].va.getAttribute(1).componentDatatype).toEqual(ComponentDatatype.UNSIGNED_BYTE);113 expect(vaf.va[0].va.getAttribute(1).offsetInBytes).toEqual(3 * 4);114 expect(vaf.va[0].va.getAttribute(1).strideInBytes).toEqual(vaf.va[0].va.getAttribute(0).strideInBytes);115 });116117 it('creates a vertex array with static and dynamic attributes', function() {118 var positionIndex = 0;119 var txCoordIndex = 2;120 var vaf = new VertexArrayFacade(context, [{121 index : positionIndex,122 componentsPerAttribute : 3,123 componentDatatype : ComponentDatatype.FLOAT,124 usage : BufferUsage.STATIC_DRAW125 }, {126 index : txCoordIndex,127 componentsPerAttribute : 2,128 componentDatatype : ComponentDatatype.UNSIGNED_SHORT,129 usage : BufferUsage.DYNAMIC_DRAW,130 normalize : true131 }], 1);132133 var positionWriter = vaf.writers[positionIndex];134 var txCoordWriter = vaf.writers[txCoordIndex];135136 expect(positionWriter).toBeDefined();137 expect(txCoordWriter).toBeDefined();138139 positionWriter(0, 1.0, 2.0, 3.0);140 txCoordWriter(0, 32 * 1024, 64 * 1024);141 vaf.commit();142143 // Position attribute144 expect(vaf.va[0].va.getAttribute(0).vertexBuffer).toBeDefined();145 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(1 * (3 * 4));146 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.usage).toEqual(BufferUsage.STATIC_DRAW);147 expect(vaf.va[0].va.getAttribute(0).componentsPerAttribute).toEqual(3);148 expect(vaf.va[0].va.getAttribute(0).componentDatatype).toEqual(ComponentDatatype.FLOAT);149 expect(vaf.va[0].va.getAttribute(0).offsetInBytes).toEqual(0);150 expect(vaf.va[0].va.getAttribute(0).strideInBytes).toEqual(3 * 4);151152 // Texture coordinate attribute153 expect(vaf.va[0].va.getAttribute(1).vertexBuffer).toBeDefined();154 expect(vaf.va[0].va.getAttribute(1).vertexBuffer.sizeInBytes).toEqual(1 * (2 * 2));155 expect(vaf.va[0].va.getAttribute(1).vertexBuffer.usage).toEqual(BufferUsage.DYNAMIC_DRAW);156 expect(vaf.va[0].va.getAttribute(1).componentsPerAttribute).toEqual(2);157 expect(vaf.va[0].va.getAttribute(1).componentDatatype).toEqual(ComponentDatatype.UNSIGNED_SHORT);158 expect(vaf.va[0].va.getAttribute(1).offsetInBytes).toEqual(0);159 expect(vaf.va[0].va.getAttribute(1).strideInBytes).toEqual(2 * 2);160 });161162 it('sub-commits', function() {163 var positionIndex = 0;164 var temperatureIndex = 2;165 var vaf = new VertexArrayFacade(context, [{166 index : positionIndex,167 componentsPerAttribute : 3,168 componentDatatype : ComponentDatatype.FLOAT,169 usage : BufferUsage.STATIC_DRAW170 }, {171 index : temperatureIndex,172 componentsPerAttribute : 1,173 componentDatatype : ComponentDatatype.FLOAT,174 usage : BufferUsage.STREAM_DRAW175 }], 2);176177 var positionWriter = vaf.writers[positionIndex];178 var temperatureWriter = vaf.writers[temperatureIndex];179180 expect(positionWriter).toBeDefined();181 expect(temperatureWriter).toBeDefined();182183 positionWriter(0, 1.0, 2.0, 3.0);184 temperatureWriter(0, 98.6);185 positionWriter(1, 7.0, 8.0, 9.0);186 temperatureWriter(1, 32.0);187 vaf.commit();188189 // Rewrite all vertices190 positionWriter(0, 10.0, 20.0, 30.0);191 temperatureWriter(0, 37.0);192 positionWriter(1, 70.0, 80.0, 90.0);193 temperatureWriter(1, 0.0);194 vaf.commit();195196 // Sub-commit to just one vertex197 temperatureWriter(1, 212.0);198 vaf.subCommit(1, 1);199 vaf.endSubCommits();200201 // Position attribute202 expect(vaf.va[0].va.getAttribute(1).vertexBuffer).toBeDefined();203 expect(vaf.va[0].va.getAttribute(1).vertexBuffer.sizeInBytes).toEqual(2 * (3 * 4));204 expect(vaf.va[0].va.getAttribute(1).vertexBuffer.usage).toEqual(BufferUsage.STATIC_DRAW);205 expect(vaf.va[0].va.getAttribute(1).componentsPerAttribute).toEqual(3);206 expect(vaf.va[0].va.getAttribute(1).componentDatatype).toEqual(ComponentDatatype.FLOAT);207 expect(vaf.va[0].va.getAttribute(1).offsetInBytes).toEqual(0);208 expect(vaf.va[0].va.getAttribute(1).strideInBytes).toEqual(3 * 4);209210 // Temperature attribute211 expect(vaf.va[0].va.getAttribute(0).vertexBuffer).toBeDefined();212 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.sizeInBytes).toEqual(2 * 4);213 expect(vaf.va[0].va.getAttribute(0).vertexBuffer.usage).toEqual(BufferUsage.STREAM_DRAW);214 expect(vaf.va[0].va.getAttribute(0).componentsPerAttribute).toEqual(1);215 expect(vaf.va[0].va.getAttribute(0).componentDatatype).toEqual(ComponentDatatype.FLOAT);216 expect(vaf.va[0].va.getAttribute(0).offsetInBytes).toEqual(0);217 expect(vaf.va[0].va.getAttribute(0).strideInBytes).toEqual(1 * 4);218 });219220 it('destroys previous vertex buffers when number of vertices grows', function() {221 var positionIndex = 0;222 var vaf = new VertexArrayFacade(context, [{223 index : positionIndex,224 componentsPerAttribute : 3,225 componentDatatype : ComponentDatatype.FLOAT,226 usage : BufferUsage.STATIC_DRAW227 }], 1);228229 var writer = vaf.writers[positionIndex];230 expect(writer).toBeDefined();231232 writer(0, 1.0, 2.0, 3.0); // Write [1.0, 2.0, 3.0] at index zero.233 vaf.commit(); // Commit writes234235 // Grab the vertex buffer236 var vbBeforeResize = vaf.va[0].va.getAttribute(0).vertexBuffer;237238 vaf.resize(2); // Two vertices239 writer(1, 1.0, 2.0, 3.0); // Write [4.0, 5.0, 6.0] at index one.240 vaf.commit(); // Commit writes241242 expect(vbBeforeResize.isDestroyed()).toBe(true);243 expect(vaf.va[0].va.getAttribute(0).vertexBuffer).not.toBe(vbBeforeResize);244 });245246 it('is not initially destroyed', function () {247 var positionIndex = 0;248 var vaf = new VertexArrayFacade(context, [{249 index : positionIndex,250 componentsPerAttribute : 3,251 componentDatatype : ComponentDatatype.FLOAT,252 usage : BufferUsage.STATIC_DRAW253 }], 1);254 expect(vaf.isDestroyed()).toBe(false);255 });256257 it('throws when constructed without a context', function() {258 expect(function() {259 return new VertexArrayFacade(undefined, undefined, undefined);260 }).toThrowDeveloperError();261 });262263 it('throws when constructed undefined attributes', function() {264 expect(function() {265 return new VertexArrayFacade(context, undefined, undefined);266 }).toThrowDeveloperError();267 });268269 it('throws when constructed without attributes', function() {270 expect(function() {271 return new VertexArrayFacade(context, []);272 }).toThrowDeveloperError();273 });274275 it('throws when constructed with attributes without componentsPerAttribute', function() {276 expect(function() {277 return new VertexArrayFacade(context, [{}]);278 }).toThrowDeveloperError();279 });280281 it('throws when constructed with attributes with an invalid componentDatatype', function() {282 expect(function() {283 return new VertexArrayFacade(context, [{284 componentsPerAttribute : 1,285 componentDatatype : 'invalid component datatype'286 }]);287 }).toThrowDeveloperError();288 });289290 it('throws when constructed with attributes with an invalid usage', function() {291 expect(function() {292 return new VertexArrayFacade(context, [{293 componentsPerAttribute : 1,294 usage : 'invalid component usage'295 }]);296 }).toThrowDeveloperError();297 });298299 it('throws when constructed with attributes with duplicate indices', function() {300 expect(function() {301 return new VertexArrayFacade(context, [{302 index : 0,303 componentsPerAttribute : 1304 }, {305 index : 0,306 componentsPerAttribute : 1307 }]);308 }).toThrowDeveloperError();309 });310311 it('subCommit throws when passed an invalid offsetInVertices', function() {312 var positionIndex = 0;313 var vaf = new VertexArrayFacade(context, [{314 index : positionIndex,315 componentsPerAttribute : 3,316 componentDatatype : ComponentDatatype.FLOAT,317 usage : BufferUsage.STATIC_DRAW318 }], 10);319320 expect(function() {321 vaf.subCommit(-1, 1);322 }).toThrowDeveloperError();323324 expect(function() {325 vaf.subCommit(10, 1);326 }).toThrowDeveloperError();327328 expect(function() {329 vaf.subCommit(1, 10);330 }).toThrowDeveloperError();331 }); ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { vA } = require('fast-check-monorepo');2console.log(vA());3const { vB } = require('fast-check-monorepo');4console.log(vB());5const { vC } = require('fast-check-monorepo');6console.log(vC());7const { vD } = require('fast-check-monorepo');8console.log(vD());9const { vE } = require('fast-check-monorepo');10console.log(vE());11const { vF } = require('fast-check-monorepo');12console.log(vF());13const { vG } = require('fast-check-monorepo');14console.log(vG());15const { vH } = require('fast-check-monorepo');16console.log(vH());17const { vI } = require('fast-check-monorepo');18console.log(vI());19const { vJ } = require('fast-check-monorepo');20console.log(vJ());21const { vK } = require('fast-check-monorepo');22console.log(vK());23const { vL } = require('fast-check-monorepo');24console.log(vL());25const { vM } = require('fast-check-monorepo');26console.log(vM());27const { vN } = require('fast-check-monorepo');28console.log(vN());29const { vO } = require('fast-check-monorepo');30console.log(vO());31const { v

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { vA } = require('fast-check-monorepo');3console.log(vA);4const { vB } = require('fast-check-monorepo');5console.log(vB);6const { vC } = require('fast-check-monorepo');7console.log(vC);8const { vD } = require('fast-check-monorepo');9console.log(vD);10const { vE } = require('fast-check-monorepo');11console.log(vE);12const { vF } = require('fast-check-monorepo');13console.log(vF);14const { vG } = require('fast-check-monorepo');15console.log(vG);16const { vH } = require('fast-check-monorepo');17console.log(vH);18const { vI } = require('fast-check-monorepo');19console.log(vI);20const { vJ } = require('fast-check-monorepo');21console.log(vJ);22const { vK } = require('fast-check-monorepo');23console.log(vK);24const { vL } = require('fast-check-monorepo');25console.log(vL);26const { vM } = require('fast-check-monorepo');27console.log(vM);28const { vN } = require('fast-check-monorepo');29console.log(vN);30const { vO } = require('fast-check-monorepo');31console.log(vO);

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('@dubzzz/fast-check');2fc.assert(3 fc.property(fc.integer(), fc.integer(), (a, b) => {4 return a + b >= a;5 })6);7const fc = require('@dubzzz/fast-check');8fc.assert(9 fc.property(fc.integer(), fc.integer(), (a, b) => {10 return a + b >= a;11 })12);13const fc = require('@dubzzz/fast-check');14fc.assert(15 fc.property(fc.integer(), fc.integer(), (a, b) => {16 return a + b >= a;17 })18);19const fc = require('@dubzzz/fast-check');20fc.assert(21 fc.property(fc.integer(), fc.integer(), (a, b) => {22 return a + b >= a;23 })24);25const fc = require('@dubzzz/fast-check');26fc.assert(27 fc.property(fc.integer(), fc.integer(), (a, b) => {28 return a + b >= a;29 })30);31const fc = require('@dubzzz/fast-check');32fc.assert(33 fc.property(fc.integer(), fc.integer(), (a, b) => {34 return a + b >= a;35 })36);37const fc = require('@dubzzz/fast-check');38fc.assert(39 fc.property(fc.integer(), fc.integer(), (a, b) => {40 return a + b >= a;41 })42);43const fc = require('@dubzzz/fast-check');44fc.assert(45 fc.property(fc.integer(), fc.integer(), (a, b) => {46 return a + b >= a;47 })48);

Full Screen

Using AI Code Generation

copy

Full Screen

1const {check} = require('fast-check');2const vA = require('fast-check-monorepo/vA');3check(vA, {seed: 1, numRuns: 10000}).then((r) => {4 console.log(r);5});6const {check} = require('fast-check');7const vB = require('fast-check-monorepo/vB');8check(vB, {seed: 1, numRuns: 10000}).then((r) => {9 console.log(r);10});11const {check} = require('fast-check');12const vC = require('fast-check-monorepo/vC');13check(vC, {seed: 1, numRuns: 10000}).then((r) => {14 console.log(r);15});16{ numRuns: 10000,17 counterexample: undefined }18{ numRuns: 10000,19 counterexample: undefined }20{ numRuns: 10000,21 counterexample: undefined }22{ numRuns: 10000,23 counterexample: undefined }24{ numRuns: 10000,25 counterexample: undefined }26{ numRuns: 10000,

Full Screen

Using AI Code Generation

copy

Full Screen

1import * as fc from "fast-check";2test("test", () => {3 fc.assert(4 fc.property(fc.integer(), (n) => {5 return n >= 0;6 })7 );8});9test("test", () => {10 fc.assert(11 fc.property(fc.integer(), (n) => {12 return n >= 1;13 })14 );15});16test("test", () => {17 fc.assert(18 fc.property(fc.integer(), (n) => {19 return n >= 2;20 })21 );22});

Full Screen

Using AI Code Generation

copy

Full Screen

1{2 "compilerOptions": {3 "paths": {4 }5 }6}7{8 "compilerOptions": {9 "paths": {10 }11 },12 { "path": "node_modules/fast-check-vA" }13}14{15 "compilerOptions": {16 "paths": {17 }18 },19 { "path": "node_modules/fast-check-vA" }20}21{22 "compilerOptions": {23 "paths": {24 }25 },26 { "path": "node_modules/fast-check-vA" }27}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful