Mercurial > games > semicongine
annotate examples/input.nim @ 521:a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 22 Jan 2023 22:46:53 +0700 |
parents | cd73e429fc99 |
children |
rev | line source |
---|---|
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
1 import std/strutils |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 import std/times |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 |
517
836790efab48
did: cleanup main namespace, add: better coordinate handling in input example
Sam <sam@basx.dev>
parents:
501
diff
changeset
|
4 import semicongine |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 type |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 # define type of vertex |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 VertexDataA = object |
520
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
9 position: PositionAttribute[Vec2] |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
10 color: ColorAttribute[Vec3] |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
11 # transform: ModelTransformAttribute |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
12 # TODO: make this somehow a single vertex attribute |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
13 m1: GenericInstanceAttribute[Vec4] |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
14 m2: GenericInstanceAttribute[Vec4] |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
15 m3: GenericInstanceAttribute[Vec4] |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
16 m4: GenericInstanceAttribute[Vec4] |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
17 Uniforms = object |
520
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
18 projection: Descriptor[Mat44] |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
19 cursor: Descriptor[Vec2] |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
21 var |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 pipeline: RenderPipeline[VertexDataA, Uniforms] |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 uniforms: Uniforms |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
24 scene: Thing |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
25 time: float |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 proc globalUpdate(engine: var Engine, dt: float32) = |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
29 time += dt |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
30 uniforms.cursor.value = engine.input.mousePos |
517
836790efab48
did: cleanup main namespace, add: better coordinate handling in input example
Sam <sam@basx.dev>
parents:
501
diff
changeset
|
31 uniforms.projection.value = ortho[float32]( |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
32 0'f32, float32(engine.vulkan.frameSize.x), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
33 0'f32, float32(engine.vulkan.frameSize.y), |
517
836790efab48
did: cleanup main namespace, add: better coordinate handling in input example
Sam <sam@basx.dev>
parents:
501
diff
changeset
|
34 0'f32, 1'f32, |
836790efab48
did: cleanup main namespace, add: better coordinate handling in input example
Sam <sam@basx.dev>
parents:
501
diff
changeset
|
35 ) |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
36 engine.vulkan.device.updateUniformData(pipeline, uniforms) |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
38 let cursor = firstPartWithName[Mesh[VertexDataA]](scene, "cursor") |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
39 if cursor != nil: |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
40 for c in cursor.vertexData.color.data.mitems: |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
41 c[1] = (sin(time * 8) * 0.5 + 0.5) * 0.2 |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
42 c[2] = (sin(time * 8) * 0.5 + 0.5) * 0.2 |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
43 engine.vulkan.device.updateVertexData(cursor.vertexData.color) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
44 var trans = Unit44 * translate3d(engine.input.mousePos.x, |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
45 engine.input.mousePos.y, 0'f32) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
46 cursor.vertexData.m1.data = @[trans.col(0)] |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
47 cursor.vertexData.m2.data = @[trans.col(1)] |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
48 cursor.vertexData.m3.data = @[trans.col(2)] |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
49 cursor.vertexData.m4.data = @[trans.col(3)] |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
50 engine.vulkan.device.updateVertexData(cursor.vertexData.m1) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
51 engine.vulkan.device.updateVertexData(cursor.vertexData.m2) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
52 engine.vulkan.device.updateVertexData(cursor.vertexData.m3) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
53 engine.vulkan.device.updateVertexData(cursor.vertexData.m4) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
54 |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
55 |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 const |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
57 shape = @[ |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
58 Vec2([ - 1'f32, - 1'f32]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
59 Vec2([1'f32, - 1'f32]), |
520
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
60 Vec2([-0.3'f32, -0.3'f32]), |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
61 Vec2([-0.3'f32, -0.3'f32]), |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
62 Vec2([ - 1'f32, 1'f32]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
63 Vec2([ - 1'f32, - 1'f32]), |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 ] |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
65 colors = @[ |
520
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
66 Vec3([1'f32, 0'f32, 0'f32]), |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
67 Vec3([1'f32, 0'f32, 0'f32]), |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
68 Vec3([1'f32, 0'f32, 0'f32]), |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
69 Vec3([0.8'f32, 0'f32, 0'f32]), |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
70 Vec3([0.8'f32, 0'f32, 0'f32]), |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
71 Vec3([0.8'f32, 0'f32, 0'f32]), |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
72 ] |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 when isMainModule: |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
75 var myengine = igniteEngine("Input") |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 |
518 | 77 var cursormesh = new Mesh[VertexDataA] |
78 cursormesh.vertexData = VertexDataA( | |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
79 position: PositionAttribute[Vec2](data: shape, useOnDeviceMemory: true), |
520
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
80 color: ColorAttribute[Vec3](data: colors), |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
81 # transform: ModelTransformAttribute(data: @[Unit44]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
82 m1: GenericInstanceAttribute[Vec4](data: @[Unit44.row(0)]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
83 m2: GenericInstanceAttribute[Vec4](data: @[Unit44.row(1)]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
84 m3: GenericInstanceAttribute[Vec4](data: @[Unit44.row(2)]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
85 m4: GenericInstanceAttribute[Vec4](data: @[Unit44.row(3)]), |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
86 ) |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
87 # transform the cursor a bit to make it look nice |
518 | 88 for i in 0 ..< cursormesh.vertexData.position.data.len: |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
89 let cursorscale = ( |
517
836790efab48
did: cleanup main namespace, add: better coordinate handling in input example
Sam <sam@basx.dev>
parents:
501
diff
changeset
|
90 scale2d(20'f32, 20'f32) * |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
91 translate2d(1'f32, 1'f32) * |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
92 rotate2d(-float32(PI) / 4'f32) * |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
93 scale2d(0.5'f32, 1'f32) * |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
94 rotate2d(float32(PI) / 4'f32) |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
95 ) |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
96 let pos = Vec3([cursormesh.vertexData.position.data[i][0], |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
97 cursormesh.vertexData.position.data[i][1], 1'f32]) |
518 | 98 cursormesh.vertexData.position.data[i] = (cursorscale * pos).xy |
99 | |
100 var boxmesh = new Mesh[VertexDataA] | |
101 boxmesh.vertexData = VertexDataA( | |
520
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
102 position: PositionAttribute[Vec2](data: shape), |
cd73e429fc99
did: use new vector and matrix names for simpler code
Sam <sam@basx.dev>
parents:
519
diff
changeset
|
103 color: ColorAttribute[Vec3](data: colors), |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
104 # transform: ModelTransformAttribute(data: @[Unit44]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
105 m1: GenericInstanceAttribute[Vec4](data: @[Unit44.row(0)]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
106 m2: GenericInstanceAttribute[Vec4](data: @[Unit44.row(1)]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
107 m3: GenericInstanceAttribute[Vec4](data: @[Unit44.row(2)]), |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
108 m4: GenericInstanceAttribute[Vec4](data: @[Unit44.row(3)]), |
518 | 109 ) |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
110 for i in 0 ..< boxmesh.vertexData.position.data.len: |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
111 let boxscale = translate2d(100'f32, 100'f32) * scale2d(100'f32, 100'f32) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
112 let pos = Vec3([boxmesh.vertexData.position.data[i][0], |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
113 boxmesh.vertexData.position.data[i][1], 1'f32]) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
114 boxmesh.vertexData.position.data[i] = (boxscale * pos).xy |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
115 echo boxmesh.vertexData.position.data |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
116 |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
117 scene = newThing("scene") |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
118 scene.add newThing("cursor", cursormesh) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
119 scene.add newThing("a box", boxmesh, newTransform(Unit44), newTransform( |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
120 translate3d(1'f32, 0'f32, 0'f32))) |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
121 scene.add newTransform(scale3d(1.5'f32, 1.5'f32, 1.5'f32)) |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
122 |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
123 # upload data, prepare shaders, etc |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
124 const vertexShader = generateVertexShaderCode[VertexDataA, Uniforms](""" |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
125 mat4 mat = mat4(m1, m2, m3, m4); |
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
126 out_position = uniforms.projection * mat * vec4(position, 0, 1); |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
127 """) |
521
a25325bec7f2
did: deep refactoring of handling vertrex attribute and buffer updates, don't ask ;(
Sam <sam@basx.dev>
parents:
520
diff
changeset
|
128 echo vertexShader |
499
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
129 const fragmentShader = generateFragmentShaderCode[VertexDataA]() |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
130 pipeline = setupPipeline[VertexDataA, Uniforms, uint16]( |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
131 myengine, |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
132 scene, |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
133 vertexShader, |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
134 fragmentShader |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
135 ) |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
136 # show something |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
137 myengine.run(pipeline, globalUpdate) |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
138 pipeline.trash() |
3f1111f3b9f8
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff
changeset
|
139 myengine.trash() |