Mercurial > games > semicongine
annotate README.md @ 1266:9e4dc93d4fa9
did: completely rewrite readme
| author | sam <sam@basx.dev> |
|---|---|
| date | Sun, 28 Jul 2024 22:50:22 +0700 |
| parents | f8974736e446 |
| children | 4cf9872f7bb6 |
| rev | line source |
|---|---|
| 922 | 1 Note: If you are reading this on Github, please not that this is only a mirror |
| 1266 | 2 repository and the newest code is hosted on my mercurial repository at |
| 3 https://hg.basx.dev/games/semicongine/. | |
| 922 | 4 |
| 289 | 5 # Semicongine |
| 41 | 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 | 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 | 12 |
| 1266 | 13 ## Features |
| 14 | |
| 15 The engine currently features the following: | |
| 16 | |
| 17 - No dependencies outside of this repo (except zip/unzip on Linux). All | |
| 18 dependencies are included. | |
| 19 - Low-level, Vulkan-base rendering system | |
| 20 - All vertex/uniform/descriptors/shader-formats, shaders can and must be | |
| 21 defined "freely". The only restriction that we currently have, is that vertex | |
| 22 data is non-interleaved. | |
| 23 - A ton of compiletime checks to ensure the defined mesh-data and shaders are | |
| 24 compatible for rendering | |
| 25 - Simple audio mixer, should suffice for most things | |
| 26 - Simple input-system, no controller support at this time | |
| 27 - Resource packaging of images, audio and 3D files. | |
| 28 - A few additional utils like a simple storage API, a few algorithms for | |
| 29 collision detection, noise generation and texture packing, and a simple | |
| 30 settings API with hot-reloading | |
| 31 | |
| 32 ## Hello world example | |
| 33 | |
| 34 Attention, this project is not optimized for "hello world"-scenarios, so you | |
| 35 have quite a few lines to get something to display: | |
| 36 | |
| 37 ``` | |
| 38 | |
| 39 import semicongine | |
| 40 | |
| 41 # required | |
| 42 InitVulkan() | |
| 43 | |
| 44 # set up a simple render pass to render the displayed frame | |
| 45 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = false, samples = VK_SAMPLE_COUNT_1_BIT) | |
| 46 | |
| 47 # the swapchain, needs to be attached to the main renderpass | |
| 48 SetupSwapchain(renderpass = renderpass) | |
| 49 | |
| 50 # render data is used for memory management on the GPU | |
| 51 var renderdata = InitRenderData() | |
| 52 | |
| 53 type | |
| 54 # define a push constant, to have something moving | |
| 55 PushConstant = object | |
| 56 scale: float32 | |
| 57 # This is how we define shaders: the interface needs to be "typed" | |
| 58 # but the shader code itself can freely be written in glsl | |
| 59 Shader = object | |
| 60 position {.VertexAttribute.}: Vec3f | |
| 61 color {.VertexAttribute.}: Vec3f | |
| 62 pushConstant {.PushConstantAttribute.}: PushConstant | |
| 63 fragmentColor {.Pass.}: Vec3f | |
| 64 outColor {.ShaderOutput.}: Vec4f | |
| 65 # code | |
| 66 vertexCode: string = """void main() { | |
| 67 fragmentColor = color; | |
| 68 gl_Position = vec4(position * pushConstant.scale, 1);}""" | |
| 69 fragmentCode: string = """void main() { | |
| 70 outColor = vec4(fragmentColor, 1);}""" | |
| 71 # And we also need to define our Mesh, which does describe the vertex layout | |
| 72 TriangleMesh = object | |
| 73 position: GPUArray[Vec3f, VertexBuffer] | |
| 74 color: GPUArray[Vec3f, VertexBuffer] | |
| 75 | |
| 76 # instantiate the mesh and fill with data | |
| 77 var mesh = TriangleMesh( | |
| 78 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | |
| 79 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), | |
| 80 ) | |
| 81 | |
| 82 # this allocates GPU data, uploads the data to the GPU and flushes any thing that is host-cached | |
| 83 # this is a shortcut version, more fine-grained control is possible | |
| 84 AssignBuffers(renderdata, mesh) | |
| 85 renderdata.FlushAllMemory() | |
| 86 | |
| 87 # Now we need to instantiate the shader as a pipeline object that is attached to a renderpass | |
| 88 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) | |
| 89 | |
| 90 # the main render-loop will exit if we get a kill-signal from the OS | |
| 91 while UpdateInputs(): | |
| 92 | |
| 93 # starts the drawing for the next frame and provides us necesseary framebuffer and commandbuffer objects in this scope | |
| 94 WithNextFrame(framebuffer, commandbuffer): | |
| 95 | |
| 96 # start the main (and only) renderpass we have, needs to know the target framebuffer and a commandbuffer | |
| 97 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | |
| 98 | |
| 99 # now activate our shader-pipeline | |
| 100 WithPipeline(commandbuffer, pipeline): | |
| 101 | |
| 102 # and finally, draw the mesh and set a single parameter | |
| 103 # more complicated setups with descriptors/uniforms are of course possible | |
| 104 RenderWithPushConstant(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh, pushConstant = PushConstant(scale: 0.3)) | |
| 105 | |
| 106 # cleanup | |
| 107 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
| 108 DestroyPipeline(pipeline) | |
| 109 DestroyRenderData(renderdata) | |
| 110 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | |
| 111 DestroyVulkan() | |
| 112 | |
| 113 ``` | |
| 114 | |
| 289 | 115 ## Roadmap |
| 41 | 116 |
| 1266 | 117 For now all features that I need are implemented. I will gradually add more |
| 118 stuff that I need, based on the games that I am developing. Here are a few | |
| 119 things that I consider integrating at a later point, once I have gather some | |
| 120 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
|
121 |
| 1266 | 122 [ ] More support for glTF format (JPEG textures, animations, morphing) |
| 123 [ ] Maybe some often used utils like camera-controllers, offscreen-rendering, shadow-map rendering, etc. | |
| 124 [ ] Maybe some UI-stuff | |
| 125 [ ] Controller support |
