diff options
-rw-r--r-- | assets/shaders/grid.frag | 2 | ||||
-rw-r--r-- | assets/shaders/grid.vert | 8 | ||||
-rw-r--r-- | examples/game_demo/game_demo.c | 6 | ||||
-rw-r--r-- | src/systems/grid.c | 26 |
4 files changed, 36 insertions, 6 deletions
diff --git a/assets/shaders/grid.frag b/assets/shaders/grid.frag index 5bce13b..06eebc3 100644 --- a/assets/shaders/grid.frag +++ b/assets/shaders/grid.frag @@ -3,5 +3,5 @@ out vec4 FragColor; void main() { - FragColor = vec4(1.0); + FragColor = vec4(1.0, 0.0, 0.0, 1.0); }
\ No newline at end of file diff --git a/assets/shaders/grid.vert b/assets/shaders/grid.vert index a98eabe..bdfa477 100644 --- a/assets/shaders/grid.vert +++ b/assets/shaders/grid.vert @@ -6,6 +6,12 @@ uniform Camera { vec4 viewPos; } cam; +// Grid position are in xy clipped space +vec3 gridPlane[6] = vec3[]( + vec3(1, 1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), + vec3(-1, -1, 0), vec3(1, 1, 0), vec3(1, -1, 0) +); +// normal vertice projection void main() { - gl_Position = vec4(1.0); + gl_Position = cam.proj * cam.view * vec4(gridPlane[gl_VertexID].xyz, 1.0); }
\ No newline at end of file diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c index 2362a2e..dfb70d1 100644 --- a/examples/game_demo/game_demo.c +++ b/examples/game_demo/game_demo.c @@ -6,6 +6,7 @@ #include <assert.h> #include "camera.h" #include "core.h" +#include "grid.h" #include "input.h" #include "keys.h" #include "loaders.h" @@ -105,14 +106,15 @@ int main() { if (draw_debug) { // draw the player model with shadows - Render_RenderEntities(render_entities->data, render_entities->len); + // Render_RenderEntities(render_entities->data, render_entities->len); // Render_DrawTerrain(); Skybox_Draw(&skybox, cam); } else { Shadow_DrawDebugQuad(); } - Terrain_Draw(terrain); + // Terrain_Draw(terrain); + Grid_Draw(); // END Draw calls Frame_Draw(); diff --git a/src/systems/grid.c b/src/systems/grid.c index 256fab4..e095d22 100644 --- a/src/systems/grid.c +++ b/src/systems/grid.c @@ -1,6 +1,7 @@ #include "grid.h" #include "file.h" #include "log.h" +#include "maths.h" #include "maths_types.h" #include "primitives.h" #include "ral_common.h" @@ -8,6 +9,7 @@ #include "ral_types.h" #include "render.h" #include "render_types.h" +#include "render_scene.h" #include "shader_layouts.h" void Grid_Init(Grid_Storage* storage) { @@ -15,7 +17,9 @@ void Grid_Init(Grid_Storage* storage) { Geometry plane_geo = Geo_CreatePlane(f32x2(1.0, 1.0)); Mesh plane_mesh = Mesh_Create(&plane_geo, true); storage->plane_vertices = plane_mesh.vertex_buffer; - storage->plane_indices = plane_mesh.index_buffer; + + u32 indices[6] = { 5,4,3,2,1,0}; + storage->plane_indices = GPU_BufferCreate(6 * sizeof(u32),BUFFER_INDEX, BUFFER_FLAG_GPU, &indices); GPU_RenderpassDesc rpass_desc = { .default_framebuffer = true, @@ -60,5 +64,23 @@ void Grid_Draw() { } void Grid_Execute(Grid_Storage *storage) { - // TODO: draw calls + WARN("Draw Grid"); + RenderScene* scene = Render_GetScene(); + GPU_CmdEncoder* enc = GPU_GetDefaultEncoder(); + GPU_CmdEncoder_BeginRender(enc, storage->renderpass); + GPU_EncodeBindPipeline(enc, storage->pipeline); + Mat4 view, proj; + u32x2 dimensions = GPU_Swapchain_GetDimensions(); + Camera camera = scene->camera; + Camera_ViewProj(&camera, (f32)dimensions.x, (f32)dimensions.y, &view, &proj); + Binding_Camera camera_data = { .view = view, + .projection = proj, + .viewPos = vec4(camera.position.x, camera.position.y, + camera.position.z, 1.0) }; + GPU_EncodeBindShaderData( + enc, 0, (ShaderData){ .data = &camera_data, .get_layout = &Binding_Camera_GetLayout }); + GPU_EncodeSetVertexBuffer(enc, storage->plane_vertices); + GPU_EncodeSetIndexBuffer(enc, storage->plane_indices); + GPU_EncodeDrawIndexed(enc, 6); + GPU_CmdEncoder_EndRender(enc); }
\ No newline at end of file |