diff --git a/03_colored_cube/Shaders/shader.kong b/03_colored_cube/Shaders/shader.kong index 4f7b028..774d66a 100644 --- a/03_colored_cube/Shaders/shader.kong +++ b/03_colored_cube/Shaders/shader.kong @@ -38,6 +38,7 @@ fun pix(input: vertex_out): float4 { struct pipeline { vertex = pos; fragment = pix; + depth_stencil_format = TEXTURE_FORMAT_DEPTH32FLOAT; depth_write = true; depth_compare = COMPARE_LESS; } diff --git a/03_colored_cube/Sources/main.c b/03_colored_cube/Sources/main.c index 9b601ec..276c356 100644 --- a/03_colored_cube/Sources/main.c +++ b/03_colored_cube/Sources/main.c @@ -20,6 +20,7 @@ static vertex_in_buffer vertices; static kope_g5_buffer indices; static kope_g5_buffer constants; static everything_set everything; +static kope_g5_texture depth; static uint32_t vertex_count; @@ -208,6 +209,9 @@ static void update(void *data) { clear_color.a = 1.0f; parameters.color_attachments[0].clear_value = clear_color; parameters.color_attachments[0].texture = framebuffer; + parameters.depth_stencil_attachment.texture = &depth; + parameters.depth_stencil_attachment.depth_clear_value = 1.0f; + parameters.depth_stencil_attachment.depth_load_op = KOPE_G5_LOAD_OP_CLEAR; kope_g5_command_list_begin_render_pass(&list, ¶meters); kong_set_render_pipeline(&list, &pipeline); @@ -242,7 +246,19 @@ int kickstart(int argc, char **argv) { kope_g5_device_create_command_list(&device, &list); + kope_g5_texture_parameters texture_params = {0}; + texture_params.format = KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT; + texture_params.width = width; + texture_params.height = height; + texture_params.depth_or_array_layers = 1; + texture_params.dimension = KOPE_G5_TEXTURE_DIMENSION_2D; + texture_params.mip_level_count = 1; + texture_params.sample_count = 1; + texture_params.usage = KONG_G5_TEXTURE_USAGE_RENDER_ATTACHMENT; + kope_g5_device_create_texture(&device, &texture_params, &depth); + vertex_count = sizeof(vertices_data) / 3 / 4; + kong_create_buffer_vertex_in(&device, vertex_count, &vertices); { vertex_in *v = kong_vertex_in_buffer_lock(&vertices); diff --git a/04_textured_cube/Shaders/shader.kong b/04_textured_cube/Shaders/shader.kong index 8b5166a..ca074dc 100644 --- a/04_textured_cube/Shaders/shader.kong +++ b/04_textured_cube/Shaders/shader.kong @@ -41,4 +41,7 @@ fun pix(input: vertex_out): float4 { struct pipeline { vertex = pos; fragment = pix; + depth_stencil_format = TEXTURE_FORMAT_DEPTH32FLOAT; + depth_write = true; + depth_compare = COMPARE_LESS; } diff --git a/04_textured_cube/Sources/main.c b/04_textured_cube/Sources/main.c index dc3d099..9776340 100644 --- a/04_textured_cube/Sources/main.c +++ b/04_textured_cube/Sources/main.c @@ -24,6 +24,7 @@ static kope_g5_texture texture; static kope_g5_sampler sampler; static everything_set everything; static kope_g5_buffer image_buffer; +static kope_g5_texture depth; static uint32_t vertex_count; @@ -227,6 +228,9 @@ static void update(void *data) { clear_color.a = 1.0f; parameters.color_attachments[0].clear_value = clear_color; parameters.color_attachments[0].texture = framebuffer; + parameters.depth_stencil_attachment.texture = &depth; + parameters.depth_stencil_attachment.depth_load_op = KOPE_G5_LOAD_OP_CLEAR; + parameters.depth_stencil_attachment.depth_clear_value = 1.0f; kope_g5_command_list_begin_render_pass(&list, ¶meters); kong_set_render_pipeline(&list, &pipeline); @@ -269,16 +273,31 @@ int kickstart(int argc, char **argv) { kinc_image_destroy(&image); kope_g5_buffer_unlock(&image_buffer); - kope_g5_texture_parameters texture_parameters; - texture_parameters.width = 512; - texture_parameters.height = 512; - texture_parameters.depth_or_array_layers = 1; - texture_parameters.mip_level_count = 1; - texture_parameters.sample_count = 1; - texture_parameters.dimension = KOPE_G5_TEXTURE_DIMENSION_2D; - texture_parameters.format = KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM; - texture_parameters.usage = KONG_G5_TEXTURE_USAGE_SAMPLE | KONG_G5_TEXTURE_USAGE_COPY_DST; - kope_g5_device_create_texture(&device, &texture_parameters, &texture); + { + kope_g5_texture_parameters texture_params = {0}; + texture_params.format = KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT; + texture_params.width = width; + texture_params.height = height; + texture_params.depth_or_array_layers = 1; + texture_params.dimension = KOPE_G5_TEXTURE_DIMENSION_2D; + texture_params.mip_level_count = 1; + texture_params.sample_count = 1; + texture_params.usage = KONG_G5_TEXTURE_USAGE_RENDER_ATTACHMENT; + kope_g5_device_create_texture(&device, &texture_params, &depth); + } + + { + kope_g5_texture_parameters texture_parameters; + texture_parameters.width = 512; + texture_parameters.height = 512; + texture_parameters.depth_or_array_layers = 1; + texture_parameters.mip_level_count = 1; + texture_parameters.sample_count = 1; + texture_parameters.dimension = KOPE_G5_TEXTURE_DIMENSION_2D; + texture_parameters.format = KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM; + texture_parameters.usage = KONG_G5_TEXTURE_USAGE_SAMPLE | KONG_G5_TEXTURE_USAGE_COPY_DST; + kope_g5_device_create_texture(&device, &texture_parameters, &texture); + } kope_g5_sampler_parameters sampler_parameters; sampler_parameters.address_mode_u = KOPE_G5_ADDRESS_MODE_REPEAT; diff --git a/05_camera_controls/Shaders/shader.kong b/05_camera_controls/Shaders/shader.kong index 8b5166a..ca074dc 100644 --- a/05_camera_controls/Shaders/shader.kong +++ b/05_camera_controls/Shaders/shader.kong @@ -41,4 +41,7 @@ fun pix(input: vertex_out): float4 { struct pipeline { vertex = pos; fragment = pix; + depth_stencil_format = TEXTURE_FORMAT_DEPTH32FLOAT; + depth_write = true; + depth_compare = COMPARE_LESS; } diff --git a/05_camera_controls/Sources/main.c b/05_camera_controls/Sources/main.c index 0db04a9..44b3825 100644 --- a/05_camera_controls/Sources/main.c +++ b/05_camera_controls/Sources/main.c @@ -26,6 +26,7 @@ static kope_g5_texture texture; static kope_g5_sampler sampler; static everything_set everything; static kope_g5_buffer image_buffer; +static kope_g5_texture depth; static uint32_t vertex_count; @@ -318,6 +319,9 @@ static void update(void *data) { clear_color.a = 1.0f; parameters.color_attachments[0].clear_value = clear_color; parameters.color_attachments[0].texture = framebuffer; + parameters.depth_stencil_attachment.texture = &depth; + parameters.depth_stencil_attachment.depth_load_op = KOPE_G5_LOAD_OP_CLEAR; + parameters.depth_stencil_attachment.depth_clear_value = 1.0f; kope_g5_command_list_begin_render_pass(&list, ¶meters); kong_set_render_pipeline(&list, &pipeline); @@ -365,16 +369,31 @@ int kickstart(int argc, char **argv) { kinc_image_destroy(&image); kope_g5_buffer_unlock(&image_buffer); - kope_g5_texture_parameters texture_parameters; - texture_parameters.width = 512; - texture_parameters.height = 512; - texture_parameters.depth_or_array_layers = 1; - texture_parameters.mip_level_count = 1; - texture_parameters.sample_count = 1; - texture_parameters.dimension = KOPE_G5_TEXTURE_DIMENSION_2D; - texture_parameters.format = KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM; - texture_parameters.usage = KONG_G5_TEXTURE_USAGE_SAMPLE | KONG_G5_TEXTURE_USAGE_COPY_DST; - kope_g5_device_create_texture(&device, &texture_parameters, &texture); + { + kope_g5_texture_parameters texture_params = {0}; + texture_params.format = KOPE_G5_TEXTURE_FORMAT_DEPTH32FLOAT; + texture_params.width = width; + texture_params.height = height; + texture_params.depth_or_array_layers = 1; + texture_params.dimension = KOPE_G5_TEXTURE_DIMENSION_2D; + texture_params.mip_level_count = 1; + texture_params.sample_count = 1; + texture_params.usage = KONG_G5_TEXTURE_USAGE_RENDER_ATTACHMENT; + kope_g5_device_create_texture(&device, &texture_params, &depth); + } + + { + kope_g5_texture_parameters texture_parameters; + texture_parameters.width = 512; + texture_parameters.height = 512; + texture_parameters.depth_or_array_layers = 1; + texture_parameters.mip_level_count = 1; + texture_parameters.sample_count = 1; + texture_parameters.dimension = KOPE_G5_TEXTURE_DIMENSION_2D; + texture_parameters.format = KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM; + texture_parameters.usage = KONG_G5_TEXTURE_USAGE_SAMPLE | KONG_G5_TEXTURE_USAGE_COPY_DST; + kope_g5_device_create_texture(&device, &texture_parameters, &texture); + } kope_g5_sampler_parameters sampler_parameters; sampler_parameters.address_mode_u = KOPE_G5_ADDRESS_MODE_REPEAT;