add other filtering option for comparison

This commit is contained in:
Sven Balzer
2025-03-16 21:04:00 +01:00
parent 6a7f54ca5a
commit 5b6d83ed90
5 changed files with 602 additions and 445 deletions
+25 -2
View File
@@ -29,6 +29,7 @@ static SDL_Window *window;
static SDL_GPUGraphicsPipeline *basic_graphics_pipeline;
static SDL_GPUGraphicsPipeline *world_graphics_pipeline;
static SDL_GPUSampler *point_sampler;
static SDL_GPUSampler *bilinear_sampler;
static SDL_GPUBuffer *vertex_buffer;
static SDL_GPUBuffer *index_buffer;
@@ -97,6 +98,8 @@ struct PerFrame {
Uint32 map_width;
};
Uint32 use_other_filtering;
static PerFrame per_frame = {
.aspect_ratio = 16.0f / 9.0f,
.fovy_degrees = 31.0f,
@@ -713,6 +716,7 @@ static bool recreate_graphics_pipelines() {
.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
.num_samplers = 1,
.num_uniform_buffers = 1,
};
SDL_GPUShader *basic_pixel_shader = SDL_CreateGPUShader(device, &basic_pixel_shader_info);
@@ -828,6 +832,7 @@ static bool recreate_graphics_pipelines() {
.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
.num_samplers = 1,
.num_uniform_buffers = 1,
};
SDL_GPUShader *world_pixel_shader = SDL_CreateGPUShader(device, &world_pixel_shader_info);
@@ -1028,6 +1033,21 @@ int main(int argc, char **argv) {
point_sampler = SDL_CreateGPUSampler(device, &point_sampler_info);
SDL_GPUTextureSamplerBinding tile_atlas_texture_binding = { .texture = tile_atlas_texture, .sampler = point_sampler };
SDL_GPUSamplerCreateInfo bilinear_sampler_info = {
.min_filter = SDL_GPU_FILTER_LINEAR,
.mag_filter = SDL_GPU_FILTER_LINEAR,
.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR,
.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE,
.max_anisotropy = 4.0f,
.enable_anisotropy = true,
};
bilinear_sampler = SDL_CreateGPUSampler(device, &bilinear_sampler_info);
vertex_buffer = create_buffer(SDL_GPU_BUFFERUSAGE_VERTEX, sizeof(vertices), vertices, "vertex_buffer");
if (!vertex_buffer) {
log_error("Failed to create buffer. Exiting.");
@@ -1159,6 +1179,8 @@ int main(int argc, char **argv) {
msaa_texture = NULL;
}
}
ImGui::CheckboxFlags("Use other filtering", &use_other_filtering, 0xffffffff);
}
ImGui::End();
@@ -1366,6 +1388,7 @@ int main(int argc, char **argv) {
per_frame.camera_y = player.pos_y;
SDL_PushGPUVertexUniformData(command_buffer, 0, &per_frame, sizeof(per_frame));
SDL_PushGPUFragmentUniformData(command_buffer, 0, &use_other_filtering, sizeof(use_other_filtering));
}
{
@@ -1401,7 +1424,7 @@ int main(int argc, char **argv) {
{ .buffer = world_buffer, .offset = 0 },
};
SDL_GPUTextureSamplerBinding texture_bindings[] = {
{ .texture = tile_atlas_texture, .sampler = point_sampler },
{ .texture = tile_atlas_texture, .sampler = use_other_filtering ? bilinear_sampler : point_sampler },
};
SDL_BindGPUGraphicsPipeline(render_pass, world_graphics_pipeline);
@@ -1419,7 +1442,7 @@ int main(int argc, char **argv) {
{ .buffer = player_instance_buffer, .offset = 0 },
};
SDL_GPUTextureSamplerBinding texture_bindings[] = {
{ .texture = player_texture, .sampler = point_sampler },
{ .texture = player_texture, .sampler = use_other_filtering ? bilinear_sampler : point_sampler },
};
SDL_BindGPUGraphicsPipeline(render_pass, basic_graphics_pipeline);