annotate README.md @ 1351:7b8a6b5e9a46

add: more generic way to index gpu array
author sam <sam@basx.dev>
date Wed, 11 Sep 2024 23:26:08 +0700
parents 4f1c3994009d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
922
9d30ec7fb91e add: some notes
sam <sam@basx.dev>
parents: 337
diff changeset
1 Note: If you are reading this on Github, please not that this is only a mirror
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
2 repository and the newest code is hosted on my mercurial repository at
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
3 https://hg.basx.dev/games/semicongine/.
922
9d30ec7fb91e add: some notes
sam <sam@basx.dev>
parents: 337
diff changeset
4
289
0eef4eba9c17 add: another completed feature
Sam <sam@basx.dev>
parents: 274
diff changeset
5 # Semicongine
41
cc8724250d65 fix: organize notes a bit
Sam <sam@basx.dev>
parents: 8
diff changeset
6
926
f8974736e446 did: smile, just for the sake of testing mercurial hooks :)
sam <sam@basx.dev>
parents: 925
diff changeset
7 Hi there
8
1134f41a49e9 add: a few missing changes
Sam <sam@basx.dev>
parents:
diff changeset
8
213
b5d9410a8184 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 202
diff changeset
9 This is a little game engine, mainly trying to wrap around vulkan and the
b5d9410a8184 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 202
diff changeset
10 operating system's windowing, input and audio system. I am using the last
b5d9410a8184 add: resource packaging and loading for different resource types, simplify build commands, update readme
Sam <sam@basx.dev>
parents: 202
diff changeset
11 programming language you will ever need, [Nim](https://nim-lang.org/)
41
cc8724250d65 fix: organize notes a bit
Sam <sam@basx.dev>
parents: 8
diff changeset
12
1301
bf92a730c83a add: documentation location
sam <sam@basx.dev>
parents: 1275
diff changeset
13 The (incomplete, autogenerated) API documentation is hosted at <https://semicongine.diademgames.com/>.
bf92a730c83a add: documentation location
sam <sam@basx.dev>
parents: 1275
diff changeset
14
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
15 ## Features
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
16
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
17 The engine currently features the following:
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
18
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
19 - No dependencies outside of this repo (except zip/unzip on Linux). All
1275
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
20 dependencies are included (`libs` for library dependencies, `tools` for
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
21 binaries/scripts, `semicongine/thirdparty` for code dependencies)
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
22 - Low-level, Vulkan-base rendering system
1275
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
23 - All vertex/uniform/descriptors/shader-formats can and must be defined
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
24 "freely". The only restriction that we currently have, is that vertex data is
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
25 non-interleaved.
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
26 - A ton of compiletime checks to ensure the defined mesh-data and shaders are
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
27 compatible for rendering
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
28 - Simple audio mixer, should suffice for most things
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
29 - Simple input-system, no controller support at this time
1275
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
30 - Resource packaging of images, audio and 3D files as either folders, zip files or embedded in the executable
1267
4cf9872f7bb6 did: rename back to old name (no v2)
sam <sam@basx.dev>
parents: 1266
diff changeset
31 - Simple font and text rendering
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
32 - A few additional utils like a simple storage API, a few algorithms for
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
33 collision detection, noise generation and texture packing, and a simple
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
34 settings API with hot-reloading
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
35
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
36 ## Hello world example
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
37
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
38 Attention, this project is not optimized for "hello world"-scenarios, so you
1302
4f1c3994009d add: some words to trigger CI docs
sam <sam@basx.dev>
parents: 1301
diff changeset
39 have to write quite a few lines to get something to display:
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
40
1269
81450075ad89 fix: readme markup
sam <sam@basx.dev>
parents: 1267
diff changeset
41 ```nim
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
42
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
43 import semicongine
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
44
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
45 # required
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
46 InitVulkan()
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
47
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
48 # set up a simple render pass to render the displayed frame
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
49 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = false, samples = VK_SAMPLE_COUNT_1_BIT)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
50
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
51 # the swapchain, needs to be attached to the main renderpass
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
52 SetupSwapchain(renderpass = renderpass)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
53
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
54 # render data is used for memory management on the GPU
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
55 var renderdata = InitRenderData()
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
56
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
57 type
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
58 # define a push constant, to have something moving
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
59 PushConstant = object
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
60 scale: float32
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
61 # This is how we define shaders: the interface needs to be "typed"
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
62 # but the shader code itself can freely be written in glsl
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
63 Shader = object
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
64 position {.VertexAttribute.}: Vec3f
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
65 color {.VertexAttribute.}: Vec3f
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
66 pushConstant {.PushConstantAttribute.}: PushConstant
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
67 fragmentColor {.Pass.}: Vec3f
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
68 outColor {.ShaderOutput.}: Vec4f
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
69 # code
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
70 vertexCode: string = """void main() {
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
71 fragmentColor = color;
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
72 gl_Position = vec4(position * pushConstant.scale, 1);}"""
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
73 fragmentCode: string = """void main() {
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
74 outColor = vec4(fragmentColor, 1);}"""
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
75 # And we also need to define our Mesh, which does describe the vertex layout
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
76 TriangleMesh = object
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
77 position: GPUArray[Vec3f, VertexBuffer]
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
78 color: GPUArray[Vec3f, VertexBuffer]
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
79
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
80 # instantiate the mesh and fill with data
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
81 var mesh = TriangleMesh(
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
82 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer),
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
83 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer),
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
84 )
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
85
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
86 # this allocates GPU data, uploads the data to the GPU and flushes any thing that is host-cached
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
87 # this is a shortcut version, more fine-grained control is possible
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
88 AssignBuffers(renderdata, mesh)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
89 renderdata.FlushAllMemory()
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
90
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
91 # Now we need to instantiate the shader as a pipeline object that is attached to a renderpass
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
92 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
93
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
94 # the main render-loop will exit if we get a kill-signal from the OS
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
95 while UpdateInputs():
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
96
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
97 # starts the drawing for the next frame and provides us necesseary framebuffer and commandbuffer objects in this scope
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
98 WithNextFrame(framebuffer, commandbuffer):
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
99
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
100 # start the main (and only) renderpass we have, needs to know the target framebuffer and a commandbuffer
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
101 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)):
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
102
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
103 # now activate our shader-pipeline
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
104 WithPipeline(commandbuffer, pipeline):
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
105
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
106 # and finally, draw the mesh and set a single parameter
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
107 # more complicated setups with descriptors/uniforms are of course possible
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
108 RenderWithPushConstant(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh, pushConstant = PushConstant(scale: 0.3))
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
109
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
110 # cleanup
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
111 checkVkResult vkDeviceWaitIdle(vulkan.device)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
112 DestroyPipeline(pipeline)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
113 DestroyRenderData(renderdata)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
114 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil)
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
115 DestroyVulkan()
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
116
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
117 ```
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
118
1275
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
119 ## Future development
41
cc8724250d65 fix: organize notes a bit
Sam <sam@basx.dev>
parents: 8
diff changeset
120
1266
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
121 For now all features that I need are implemented. I will gradually add more
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
122 stuff that I need, based on the games that I am developing. Here are a few
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
123 things that I consider integrating at a later point, once I have gather some
9e4dc93d4fa9 did: completely rewrite readme
sam <sam@basx.dev>
parents: 926
diff changeset
124 more experience what can/should be used across different projects:
194
93f661a20f74 did: a bit of cleanup with the config, also add some documentation
Sam <sam@basx.dev>
parents: 187
diff changeset
125
1269
81450075ad89 fix: readme markup
sam <sam@basx.dev>
parents: 1267
diff changeset
126 - [ ] More support for glTF format (JPEG textures, animations, morphing)
1275
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
127 - [ ] Some often used utils like camera-controllers, offscreen-rendering, shadow-map rendering, etc.
9d6ce3c34c38 fix: Readme wording
sam <sam@basx.dev>
parents: 1269
diff changeset
128 - [ ] Some UI-stuff
1269
81450075ad89 fix: readme markup
sam <sam@basx.dev>
parents: 1267
diff changeset
129 - [ ] Controller support