annotate examples/hello_cube.nim @ 501:e89fceb5a3a2

did: rename project
author Sam <sam@basx.dev>
date Wed, 18 Jan 2023 13:52:48 +0700
parents 8025ab67d931
children 94d7eed3f118
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1 #
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 # TODO: Needs Depth-Buffer first!
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 #
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
4 #
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 #
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 #
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 #
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
9 #
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
10 #
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
11 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
12 import std/strutils
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
13 import std/enumerate
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
14
501
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
15 import semicongine/engine
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
16 import semicongine/math/vector
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
17 import semicongine/math/matrix
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
18 import semicongine/vertex
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
19 import semicongine/descriptor
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
20 import semicongine/mesh
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
21 import semicongine/thing
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
22 import semicongine/shader
e89fceb5a3a2 did: rename project
Sam <sam@basx.dev>
parents: 500
diff changeset
23 import semicongine/buffer
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
24
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
25 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
26 # 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
27 VertexDataA = object
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 position: PositionAttribute[Vec3[float32]]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
29 color: ColorAttribute[Vec3[float32]]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
30 Uniforms = object
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
31 model: Descriptor[Mat44[float32]]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
32 view: Descriptor[Mat44[float32]]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
33 projection: Descriptor[Mat44[float32]]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
34
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
35 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
36 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
37 uniforms: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
38 t: float32
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
39
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
40
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
41 proc globalUpdate(engine: var Engine, dt: float32) =
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
42 let ratio = float32(engine.vulkan.frameDimension.height) / float32(engine.vulkan.frameDimension.width)
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
43 t += dt
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
44 uniforms.model.value = translate3d(0'f32, 0'f32, 10'f32) * rotate3d(t, Yf32) # * rotate3d(float32(PI), Yf32)
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
45
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
46 uniforms.view.value = Unit44f32
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
47 uniforms.projection.value = Mat44[float32](data:[
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
48 ratio, 0'f32, 0'f32, 0'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
49 0'f32, 1'f32, 0'f32, 0'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
50 0'f32, 0'f32, 1'f32, 0'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
51 0'f32, 0'f32, 0'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
52 ])
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
53 uniforms.projection.value = perspective(float32(PI / 4), float32(engine.vulkan.frameDimension.width) / float32(engine.vulkan.frameDimension.height), 0.1'f32, 100'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
54 for buffer in pipeline.uniformBuffers:
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
55 buffer.updateData(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
56
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 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
58 TopLeftFront = Vec3([ -0.5'f32, -0.5'f32, -0.5'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
59 TopRightFront = Vec3([ 0.5'f32, -0.5'f32, -0.5'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
60 BottomRightFront = Vec3([ 0.5'f32, 0.5'f32, -0.5'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
61 BottomLeftFront = Vec3([ -0.5'f32, 0.5'f32, -0.5'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
62 TopLeftBack = Vec3([ 0.5'f32, -0.5'f32, 0.5'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
63 TopRightBack = Vec3([ -0.5'f32, -0.5'f32, 0.5'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
64 BottomRightBack = Vec3([ -0.5'f32, 0.5'f32, 0.5'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
65 BottomLeftBack = Vec3([ 0.5'f32, 0.5'f32, 0.5'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
66 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
67 cube_pos = @[
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
68 TopLeftFront, TopRightFront, BottomRightFront, BottomLeftFront, # front
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
69 TopLeftBack, TopRightBack, BottomRightBack, BottomLeftBack, # back
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
70 TopLeftBack, TopLeftFront, BottomLeftFront, BottomLeftBack, # left
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
71 TopRightBack, TopRightFront, BottomRightFront, BottomRightBack, # right
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 TopLeftBack, TopRightBack, TopRightFront, TopLeftFront, # top
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 BottomLeftFront, BottomRightFront, BottomRightBack, BottomLeftBack, # bottom
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 ]
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 cube_color = @[
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 Rf32, Rf32, Rf32, Rf32,
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
77 Rf32 * 0.5'f32, Rf32 * 0.5'f32, Rf32 * 0.5'f32, Rf32 * 0.5'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
78 Gf32, Gf32, Gf32, Gf32,
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
79 Gf32 * 0.5'f32, Gf32 * 0.5'f32, Gf32 * 0.5'f32, Gf32 * 0.5'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
80 Bf32, Bf32, Bf32, Bf32,
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
81 Bf32 * 0.5'f32, Bf32 * 0.5'f32, Bf32 * 0.5'f32, Bf32 * 0.5'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
82 ]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
83 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
84 tris: seq[array[3, uint16]]
500
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
85 for i in 0'u16 ..< 6'u16:
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
86 let off = i * 4
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
87 tris.add [off + 0'u16, off + 1'u16, off + 2'u16]
8025ab67d931 fix: hello cube, add: run_all command
Sam <sam@basx.dev>
parents: 499
diff changeset
88 tris.add [off + 2'u16, off + 3'u16, off + 0'u16]
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 var off = 0'u16 * 4
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
90 # tris.add [off + 0'u16, off + 1'u16, off + 2'u16]
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 # tris.add [off + 2'u16, off + 3'u16, off + 0'u16]
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 # off = 1'u16 * 4
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 # tris.add [off + 0'u16, off + 1'u16, off + 2'u16]
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 # tris.add [off + 2'u16, off + 3'u16, off + 0'u16]
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 # off = 4'u16 * 4
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
96 # tris.add [off + 0'u16, off + 1'u16, off + 2'u16]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
97 # tris.add [off + 2'u16, off + 3'u16, off + 0'u16]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
98 # off = 3'u16 * 4
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
99 # tris.add [off + 0'u16, off + 1'u16, off + 2'u16]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
100 # tris.add [off + 2'u16, off + 3'u16, off + 0'u16]
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
101
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
102 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
103 var myengine = igniteEngine("Hello cube")
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
104
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
105 # build a mesh
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
106 var trianglemesh = new IndexedMesh[VertexDataA, 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
107 trianglemesh.vertexData = 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
108 position: PositionAttribute[Vec3[float32]](data: cube_pos),
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
109 color: ColorAttribute[Vec3[float32]](data: cube_color),
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
110 )
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
111 trianglemesh.indices = tris
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
112 # build a single-object scene graph
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
113 var triangle = new Thing
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
114 # add the triangle mesh to the object
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
115 triangle.parts.add trianglemesh
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
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
117 # 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
118 const vertexShader = generateVertexShaderCode[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
119 out_position = (uniforms.projection * uniforms.view * uniforms.model) * vec4(in_position, 1);
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
120 """)
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
121 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
122 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
123 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
124 triangle,
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
125 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
126 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
127 )
3f1111f3b9f8 did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
Sam <sam@basx.dev>
parents:
diff changeset
128 # 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
129 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
130 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
131 myengine.trash()