MCPcopy Create free account
hub / github.com/DjDeveloperr/deno_desktop / HelloTriangleApp

Class HelloTriangleApp

examples/hello_triangle.js:3–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import { App } from "./common.js";
2
3export class HelloTriangleApp extends App {
4 constructor() {
5 super("Hello Triangle");
6
7 const vertices = [
8 [ 0, 0.5, 0],
9 [ 0.5, -0.5, 0],
10 [-0.5, -0.5, 0],
11 ];
12
13 const colors = [
14 [1, 0, 0, 1],
15 [0, 1, 0, 1],
16 [0, 0, 1, 1],
17 ];
18
19 const indices = [
20 0, 1, 2,
21 ];
22
23 this.vertices = new Float32Array(vertices.length * 3 + colors.length * 4);
24 for (let i = 0; i < vertices.length; i++) {
25 const vertex = vertices[i], color = colors[i];
26 const offset = i * vertex.length + i * color.length;
27 this.vertices.set(vertex, offset);
28 this.vertices.set(color, offset + vertex.length);
29 }
30
31 this.indices = new Uint16Array(indices);
32 }
33
34 async init() {
35 const shaderModule = await this.loadShader("hello_triangle");
36
37 this.vertexBuffer = this.createBuffer({
38 label: "Vertex Buffer",
39 data: this.vertices,
40 usage: GPUBufferUsage.VERTEX,
41 });
42
43 this.indexBuffer = this.createBuffer({
44 label: "Index Buffer",
45 data: this.indices,
46 usage: GPUBufferUsage.INDEX,
47 });
48
49 this.renderPipeline = this.device.createRenderPipeline({
50 vertex: {
51 module: shaderModule,
52 entryPoint: "vs_main",
53 buffers: [
54 {
55 arrayStride: 4 * 3 + 4 * 4,
56 stepMode: "vertex",
57 attributes: [
58 {
59 offset: 0,
60 shaderLocation: 0,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected