Changeset 214849 in webkit
- Timestamp:
- Apr 3, 2017 3:47:53 PM (7 years ago)
- Location:
- trunk/Websites/webkit.org
- Files:
-
- 7 added
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Websites/webkit.org/ChangeLog
r214710 r214849 1 2017-04-03 Dean Jackson <dino@apple.com> 2 3 Unreviewed. More WebGPU demos. 4 5 * demos/webgpu/2d.jpg: Added. 6 * demos/webgpu/2d.js: 7 * demos/webgpu/circle.svg: Added. 8 * demos/webgpu/cubes.jpg: Added. 9 * demos/webgpu/hello.html: Added. 10 * demos/webgpu/hello.jpg: Added. 11 * demos/webgpu/hello.js: Copied from Websites/webkit.org/demos/webgpu/2d.js. 12 (init): 13 (render): 14 * demos/webgpu/index.html: Added. 15 * demos/webgpu/simple.jpg: Added. 16 1 17 2017-03-31 Dean Jackson <dino@apple.com> 2 18 -
trunk/Websites/webkit.org/demos/webgpu/2d.js
r214710 r214849 133 133 } 134 134 135 var count = 0;136 137 135 function updateUniformData(index) { 138 136 var now = Date.now() % 100000 / 500; -
trunk/Websites/webkit.org/demos/webgpu/hello.js
r214848 r214849 1 class Uniform {2 constructor(float32Array) {3 if (float32Array && float32Array.length != 64) {4 console.log("Incorrect backing store for Uniform");5 return;6 }7 8 this.array = float32Array || new Float32Array(64);9 }10 // Layout is11 // 0-1 = resolution (float2)12 // 2 = time (float)13 get buffer() {14 return this.array;15 }16 get resolution() {17 return this.array.subarray(0, 2);18 }19 get time() {20 return this.array[2];21 }22 set resolution(value) {23 this.array[0] = value[0];24 this.array[1] = value[1];25 }26 set time(value) {27 this.array[2] = value;28 }29 copyValuesTo(buffer) {30 var bufferData = new Float32Array(buffer.contents);31 for (let i = 0; i < 3; i++) {32 bufferData[i] = this.array[i];33 }34 }35 }36 37 const vertexData = new Float32Array(38 [39 -1, -1, 0, 1,40 1, -1, 0, 1,41 1, 1, 0, 1,42 -1, -1, 0, 1,43 -1, 1, 0, 1,44 1, 1, 0, 1,45 ]);46 47 1 let gpu; 48 2 let commandQueue; 49 3 let renderPassDescriptor; 50 4 let renderPipelineState; 51 52 const NumActiveUniformBuffers = 3;53 let uniforms = new Array(NumActiveUniformBuffers);54 let uniformBuffers = new Array(NumActiveUniformBuffers);55 let currentUniformBufferIndex = 0;56 5 57 6 window.addEventListener("load", init, false); … … 88 37 renderPipelineState = gpu.createRenderPipelineState(pipelineDescriptor); 89 38 90 for (let i = 0; i < NumActiveUniformBuffers; i++) {91 let uniform = new Uniform();92 uniform.resolution = new Float32Array([canvasSize.width, canvasSize.height]);93 uniforms[i] = uniform;94 uniformBuffers[i] = gpu.createBuffer(uniform.buffer);95 }96 97 39 renderPassDescriptor = new WebGPURenderPassDescriptor(); 98 40 // NOTE: Our API proposal has some of these values as enums, not constant numbers. … … 102 44 renderPassDescriptor.colorAttachments[0].clearColor = [0.35, 0.65, 0.85, 1.0]; 103 45 104 vertexBuffer = gpu.createBuffer(vertexData);105 46 render(); 106 47 } … … 108 49 function render() { 109 50 110 updateUniformData(currentUniformBufferIndex);111 112 51 let commandBuffer = commandQueue.createCommandBuffer(); 113 114 52 let drawable = gpu.nextDrawable(); 115 116 53 renderPassDescriptor.colorAttachments[0].texture = drawable.texture; 117 54 118 55 let commandEncoder = commandBuffer.createRenderCommandEncoderWithDescriptor(renderPassDescriptor); 119 56 commandEncoder.setRenderPipelineState(renderPipelineState); 120 commandEncoder.setVertexBuffer(vertexBuffer, 0, 0); 121 commandEncoder.setVertexBuffer(uniformBuffers[currentUniformBufferIndex], 0, 1);122 commandEncoder.setFragmentBuffer(uniformBuffers[currentUniformBufferIndex], 0, 0);57 58 // NOTE: We didn't attach any buffers. We create the geometry in the vertex shader using 59 // the vertex ID. 123 60 124 61 // NOTE: Our API proposal uses the enum value "triangle" here. We haven't got around to implementing the enums yet. 125 commandEncoder.drawPrimitives(gpu.PrimitiveTypeTriangle, 0, 6);62 commandEncoder.drawPrimitives(gpu.PrimitiveTypeTriangle, 0, 3); 126 63 127 64 commandEncoder.endEncoding(); 128 65 commandBuffer.presentDrawable(drawable); 129 66 commandBuffer.commit(); 130 131 currentUniformBufferIndex = (currentUniformBufferIndex + 1) % NumActiveUniformBuffers;132 requestAnimationFrame(render);133 67 } 134 135 var count = 0;136 137 function updateUniformData(index) {138 var now = Date.now() % 100000 / 500;139 let uniform = uniforms[index];140 uniform.time = now;141 142 uniform.copyValuesTo(uniformBuffers[index]);143 144 }
Note: See TracChangeset
for help on using the changeset viewer.