Mercurial > games > semicongine
comparison examples/E04_input.nim @ 316:b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 07 Aug 2023 00:23:00 +0700 |
parents | da0bd61abe91 |
children | 887ddc8d45fd |
comparison
equal
deleted
inserted
replaced
315:4921ec86dcb4 | 316:b145a05c2459 |
---|---|
145 scene.root.add newEntity("keyboard-center", [], keyboard) | 145 scene.root.add newEntity("keyboard-center", [], keyboard) |
146 scene.root.add newEntity("cursor", {"mesh": Component(cursormesh)}) | 146 scene.root.add newEntity("cursor", {"mesh": Component(cursormesh)}) |
147 | 147 |
148 # shaders | 148 # shaders |
149 const | 149 const |
150 vertexInput = @[ | 150 inputs = @[ |
151 attr[Vec3f]("position"), | 151 attr[Vec3f]("position"), |
152 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), | 152 attr[Vec4f]("color", memoryPerformanceHint=PreferFastWrite), |
153 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), | 153 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), |
154 ] | 154 ] |
155 vertexOutput = @[attr[Vec4f]("outcolor")] | 155 intermediate = @[attr[Vec4f]("outcolor")] |
156 uniforms = @[attr[Mat4]("projection")] | 156 uniforms = @[attr[Mat4]("projection")] |
157 fragOutput = @[attr[Vec4f]("color")] | 157 outputs = @[attr[Vec4f]("color")] |
158 vertexCode = compileGlslShader( | 158 (vertexCode, fragmentCode) = compileVertexFragmentShaderSet( |
159 stage=VK_SHADER_STAGE_VERTEX_BIT, | 159 inputs=inputs, |
160 inputs=vertexInput, | 160 intermediate=intermediate, |
161 outputs=outputs, | |
161 uniforms=uniforms, | 162 uniforms=uniforms, |
162 outputs=vertexOutput, | 163 vertexCode="""outcolor = color; gl_Position = vec4(position, 1) * (transform * Uniforms.projection);""", |
163 main="""outcolor = color; gl_Position = vec4(position, 1) * (transform * Uniforms.projection);""" | 164 fragmentCode="color = outcolor;", |
164 ) | |
165 fragmentCode = compileGlslShader( | |
166 stage=VK_SHADER_STAGE_FRAGMENT_BIT, | |
167 inputs=vertexOutput, | |
168 uniforms=uniforms, | |
169 outputs=fragOutput, | |
170 main="color = outcolor;" | |
171 ) | 165 ) |
172 | 166 |
173 # set up rendering | 167 # set up rendering |
174 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0.5))) | 168 myengine.setRenderer(myengine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0.5))) |
175 myengine.addScene(scene, vertexInput, @[], transformAttribute="transform") | 169 myengine.addScene(scene, inputs, @[], transformAttribute="transform") |
176 scene.addShaderGlobal("projection", Unit4f32) | 170 scene.addShaderGlobal("projection", Unit4f32) |
177 | 171 |
178 # mainloop | 172 # mainloop |
179 while myengine.updateInputs() == Running: | 173 while myengine.updateInputs() == Running: |
180 if myengine.windowWasResized(): | 174 if myengine.windowWasResized(): |