annotate examples/E01_hello_triangle.nim @ 133:9f2c178beb60

add: correct swapchain destruction, update 1st example to be working
author Sam <sam@basx.dev>
date Thu, 20 Apr 2023 21:59:52 +0700
parents 779607656b12
children fc5db4f1f94e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
9edca5dc4e93 add: working implementation of uniforms
Sam <sam@basx.dev>
parents: 28
diff changeset
1 import std/strutils
9edca5dc4e93 add: working implementation of uniforms
Sam <sam@basx.dev>
parents: 28
diff changeset
2 import std/enumerate
28
b1b05d4efb52 big refactoring, part1
Sam <sam@basx.dev>
parents: 24
diff changeset
3
56
94d7eed3f118 did: cleanup main namespace, add: better coordinate handling in input example
Sam <sam@basx.dev>
parents: 40
diff changeset
4 import semicongine
0
5daf3f236d87 add: initial version
Sam <sam@basx.dev>
parents:
diff changeset
5
5daf3f236d87 add: initial version
Sam <sam@basx.dev>
parents:
diff changeset
6
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
7 const
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
8 vertexInput = @[
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
9 attr[Vec3f]("position", memoryLocation=VRAM),
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
10 attr[Vec3f]("color", memoryLocation=VRAM),
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
11 ]
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
12 vertexOutput = @[attr[Vec3f]("outcolor")]
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
13 fragOutput = @[attr[Vec4f]("color")]
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
14 vertexCode = compileGlslShader(
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
15 stage=VK_SHADER_STAGE_VERTEX_BIT,
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
16 inputs=vertexInput,
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
17 outputs=vertexOutput,
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
18 main="""gl_Position = vec4(position, 1.0); outcolor = color;"""
19
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents: 12
diff changeset
19 )
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
20 fragmentCode = compileGlslShader(
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
21 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
22 inputs=vertexOutput,
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
23 outputs=fragOutput,
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
24 main="color = vec4(outcolor, 1);"
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
25 )
19
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents: 12
diff changeset
26
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
27 var
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
28 triangle = newEntity(
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
29 "triangle",
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
30 newMesh(
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
31 [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)],
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
32 [X, Y, Z],
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
33 )
19
b55d6ecde79d did: introduce scene graph, meshs and generic vertex buffers
Sam <sam@basx.dev>
parents: 12
diff changeset
34 )
133
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
35 myengine = initEngine("Hello triangle")
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
36 renderPass = myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode)
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
37
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
38 myengine.setRenderer(renderPass)
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
39 myengine.addScene(triangle, vertexInput)
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
40
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
41 while myengine.running and not myengine.keyWasPressed(Escape):
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
42 myengine.updateInputs()
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
43 myengine.renderScene(triangle)
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
44
9f2c178beb60 add: correct swapchain destruction, update 1st example to be working
Sam <sam@basx.dev>
parents: 74
diff changeset
45 myengine.destroy()