Skip to content

Commit

Permalink
Merge pull request #18 from strawberry-vis/fix-compiler
Browse files Browse the repository at this point in the history
Export methods in compiler such as getUniforms
  • Loading branch information
xiaoiver authored Sep 19, 2023
2 parents eb91300 + 6891a60 commit c8157bf
Show file tree
Hide file tree
Showing 15 changed files with 611 additions and 151 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-months-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strawberry-vis/g-device-api': patch
---

Export compiler utils.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ setPipeline(pipeline: RenderPipeline)
Bindings defines the interface between a set of resources bound and their accessibility in shader stages.

```ts
setBindings: (bindings: Bindings, dynamicByteOffsets?: number[]) => void;
setBindings: (bindings: Bindings) => void;
```

### <a id="setVertexInput" />setVertexInput
Expand Down
40 changes: 7 additions & 33 deletions examples/demos/cubemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import {
} from '../../src';
import { initExample, loadImage } from './utils';
import { vec3, mat4 } from 'gl-matrix';
import {
cubeVertexArray,
cubeVertexSize,
cubeVertexCount,
cubePositionOffset,
cubeUVOffset,
} from '../meshes/cube';

/**
* @see https://webgpu.github.io/webgpu-samples/samples/texturedCube
Expand Down Expand Up @@ -71,39 +78,6 @@ void main() {
},
});

const cubeVertexSize = 4 * 10; // Byte size of one cube vertex.
const cubePositionOffset = 0;
const cubeColorOffset = 4 * 4; // Byte offset of cube vertex color attribute.
const cubeUVOffset = 4 * 8;
const cubeVertexCount = 36;

const cubeVertexArray = new Float32Array([
// float4 position, float4 color, float2 uv,
1, -1, 1, 1, 1, 0, 1, 1, 0, 1, -1, -1, 1, 1, 0, 0, 1, 1, 1, 1, -1, -1, -1,
1, 0, 0, 0, 1, 1, 0, 1, -1, -1, 1, 1, 0, 0, 1, 0, 0, 1, -1, 1, 1, 1, 0, 1,
1, 0, 1, -1, -1, -1, 1, 0, 0, 0, 1, 1, 0,

1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, -1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -1, -1, 1,
1, 0, 0, 1, 1, 0, 1, 1, -1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, -1, -1, 1, 1, 0, 0, 1, 1, 0,

-1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1,
1, 0, 1, 1, 0, -1, 1, -1, 1, 0, 1, 0, 1, 0, 0, -1, 1, 1, 1, 0, 1, 1, 1, 0,
1, 1, 1, -1, 1, 1, 1, 0, 1, 1, 0,

-1, -1, 1, 1, 0, 0, 1, 1, 0, 1, -1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -1, 1, -1, 1,
0, 1, 0, 1, 1, 0, -1, -1, -1, 1, 0, 0, 0, 1, 0, 0, -1, -1, 1, 1, 0, 0, 1, 1,
0, 1, -1, 1, -1, 1, 0, 1, 0, 1, 1, 0,

1, 1, 1, 1, 1, 1, 1, 1, 0, 1, -1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -1, -1, 1, 1,
0, 0, 1, 1, 1, 0, -1, -1, 1, 1, 0, 0, 1, 1, 1, 0, 1, -1, 1, 1, 1, 0, 1, 1,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,

1, -1, -1, 1, 1, 0, 0, 1, 0, 1, -1, -1, -1, 1, 0, 0, 0, 1, 1, 1, -1, 1, -1,
1, 0, 1, 0, 1, 1, 0, 1, 1, -1, 1, 1, 1, 0, 1, 0, 0, 1, -1, -1, 1, 1, 0, 0,
1, 0, 1, -1, 1, -1, 1, 0, 1, 0, 1, 1, 0,
]);

const vertexBuffer = device.createBuffer({
viewOrSize: cubeVertexArray,
usage: BufferUsage.VERTEX,
Expand Down
2 changes: 2 additions & 0 deletions examples/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ export { PrimitiveTopologyPoints } from './primitive-topology-points';
export { PrimitiveTopologyTriangles } from './primitive-topology-triangles';
export { MSAA } from './msaa';
export { RotatingCube } from './rotating-cube';
export { TwoCubes } from './two-cubes';
export { TexturedCube } from './textured-cube';
export { Sampler } from './sampler';
export { InstancedCubes } from './instanced-cubes';
export { Cubemap } from './cubemap';
export { ComputeBoids } from './compute-boids';
38 changes: 5 additions & 33 deletions examples/demos/instanced-cubes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {
} from '../../src';
import { initExample } from './utils';
import { vec3, mat4 } from 'gl-matrix';
import {
cubeVertexArray,
cubeVertexSize,
cubeVertexCount,
} from '../meshes/cube';

/**
* @see https://webgpu.github.io/webgpu-samples/samples/instancedCube#main.ts
Expand Down Expand Up @@ -60,39 +65,6 @@ void main() {
},
});

const cubeVertexSize = 4 * 10; // Byte size of one cube vertex.
const cubePositionOffset = 0;
const cubeColorOffset = 4 * 4; // Byte offset of cube vertex color attribute.
const cubeUVOffset = 4 * 8;
const cubeVertexCount = 36;

const cubeVertexArray = new Float32Array([
// float4 position, float4 color, float2 uv,
1, -1, 1, 1, 1, 0, 1, 1, 0, 1, -1, -1, 1, 1, 0, 0, 1, 1, 1, 1, -1, -1, -1,
1, 0, 0, 0, 1, 1, 0, 1, -1, -1, 1, 1, 0, 0, 1, 0, 0, 1, -1, 1, 1, 1, 0, 1,
1, 0, 1, -1, -1, -1, 1, 0, 0, 0, 1, 1, 0,

1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, -1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -1, -1, 1,
1, 0, 0, 1, 1, 0, 1, 1, -1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, -1, -1, 1, 1, 0, 0, 1, 1, 0,

-1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1,
1, 0, 1, 1, 0, -1, 1, -1, 1, 0, 1, 0, 1, 0, 0, -1, 1, 1, 1, 0, 1, 1, 1, 0,
1, 1, 1, -1, 1, 1, 1, 0, 1, 1, 0,

-1, -1, 1, 1, 0, 0, 1, 1, 0, 1, -1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -1, 1, -1, 1,
0, 1, 0, 1, 1, 0, -1, -1, -1, 1, 0, 0, 0, 1, 0, 0, -1, -1, 1, 1, 0, 0, 1, 1,
0, 1, -1, 1, -1, 1, 0, 1, 0, 1, 1, 0,

1, 1, 1, 1, 1, 1, 1, 1, 0, 1, -1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -1, -1, 1, 1,
0, 0, 1, 1, 1, 0, -1, -1, 1, 1, 0, 0, 1, 1, 1, 0, 1, -1, 1, 1, 1, 0, 1, 1,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,

1, -1, -1, 1, 1, 0, 0, 1, 0, 1, -1, -1, -1, 1, 0, 0, 0, 1, 1, 1, -1, 1, -1,
1, 0, 1, 0, 1, 1, 0, 1, 1, -1, 1, 1, 1, 0, 1, 0, 0, 1, -1, -1, 1, 1, 0, 0,
1, 0, 1, -1, 1, -1, 1, 0, 1, 0, 1, 1, 0,
]);

const xCount = 4;
const yCount = 4;
const numInstances = xCount * yCount;
Expand Down
38 changes: 5 additions & 33 deletions examples/demos/rotating-cube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {
} from '../../src';
import { initExample } from './utils';
import { vec3, mat4 } from 'gl-matrix';
import {
cubeVertexArray,
cubeVertexSize,
cubeVertexCount,
} from '../meshes/cube';

export async function render(
deviceContribution: DeviceContribution,
Expand Down Expand Up @@ -57,39 +62,6 @@ void main() {
},
});

const cubeVertexSize = 4 * 10; // Byte size of one cube vertex.
const cubePositionOffset = 0;
const cubeColorOffset = 4 * 4; // Byte offset of cube vertex color attribute.
const cubeUVOffset = 4 * 8;
const cubeVertexCount = 36;

const cub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 1, 1, -1, 1, 1, 1, 0, 1, 0, 0, 1, -1, -1, 1, 1, 0, 0,
1, 0, 1, -1, 1, -1, 1, 0, 1, 0, 1, 1, 0,
]);

const vertexBuffer = device.createBuffer({
viewOrSize: cubeVertexArray,
usage: BufferUsage.VERTEX,
Expand Down
Loading

0 comments on commit c8157bf

Please sign in to comment.