Skip to content

Commit

Permalink
Use a depth buffer for samples 03 to 05
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 27, 2024
1 parent 7d59bfd commit 018a09b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 20 deletions.
1 change: 1 addition & 0 deletions 03_colored_cube/Shaders/shader.kong
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 16 additions & 0 deletions 03_colored_cube/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, &parameters);

kong_set_render_pipeline(&list, &pipeline);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions 04_textured_cube/Shaders/shader.kong
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
39 changes: 29 additions & 10 deletions 04_textured_cube/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, &parameters);

kong_set_render_pipeline(&list, &pipeline);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions 05_camera_controls/Shaders/shader.kong
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
39 changes: 29 additions & 10 deletions 05_camera_controls/Sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, &parameters);

kong_set_render_pipeline(&list, &pipeline);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 018a09b

Please sign in to comment.