From 2b723ce3314d930ed1956a1942341d5912c165da Mon Sep 17 00:00:00 2001 From: hgn Date: Mon, 27 Oct 2025 22:51:27 +0000 Subject: [PATCH] framebuffer features --- source/engine/model.c | 4 +++- source/engine/model.h | 1 + source/engine/shader_props.h | 2 +- source/engine/vg_framebuffer.c | 26 +++++++++++++++++++++++--- source/engine/vg_framebuffer.h | 6 +++++- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/source/engine/model.c b/source/engine/model.c index 50e6b83..c02999c 100644 --- a/source/engine/model.c +++ b/source/engine/model.c @@ -167,9 +167,11 @@ static void vg_model_stream_materials( struct vg_model_stream_context *ctx, stru if( mat->shader == k_shader_standard || mat->shader == k_shader_standard_cutout || mat->shader == k_shader_foliage || - mat->shader == k_shader_fxglow ) + mat->shader == k_shader_fxglow || + mat->shader == k_shader_pipe ) { keyvalues_read_u32s( &kvs, root, "tex_diffuse", (u32[]){0}, &props->standard.tex_diffuse, 1 ); + keyvalues_read_u32s( &kvs, root, "tex_normal", (u32[]){0}, &props->standard.tex_normal, 1 ); keyvalues_read_u32s( &kvs, root, "render_flags", (u32[]){0}, &props->standard.render_flags, 1 ); } else if( mat->shader == k_shader_standard_vertex_blend ) diff --git a/source/engine/model.h b/source/engine/model.h index 424e198..bea0d12 100644 --- a/source/engine/model.h +++ b/source/engine/model.h @@ -20,6 +20,7 @@ enum mdl_shader k_shader_walking = 9, k_shader_foliage = 10, k_shader_workshop = 11, + k_shader_pipe = 12, k_shader_override = 30000 }; diff --git a/source/engine/shader_props.h b/source/engine/shader_props.h index d383c0d..7c90c7f 100644 --- a/source/engine/shader_props.h +++ b/source/engine/shader_props.h @@ -23,7 +23,7 @@ union shader_props { struct shader_props_standard { - u32 tex_diffuse; + u32 tex_diffuse, tex_normal; u32 render_flags; } standard; diff --git a/source/engine/vg_framebuffer.c b/source/engine/vg_framebuffer.c index aa77caa..d416af3 100644 --- a/source/engine/vg_framebuffer.c +++ b/source/engine/vg_framebuffer.c @@ -40,6 +40,16 @@ void framebuffer_get_res( struct framebuffer *fb, i32 *x, i32 *y ) { *x = _engine.w / fb->resolution_div; *y = _engine.h / fb->resolution_div; + + if( fb->fixed_ratio != 0.0f ) + { + f32 engine_ratio = (f32)_engine.w / (f32)_engine.h; + if( engine_ratio > fb->fixed_ratio ) + *x = (f32)(*y) * fb->fixed_ratio; + + if( engine_ratio < fb->fixed_ratio ) + *y = (f32)(*x) / fb->fixed_ratio; + } } else { @@ -283,11 +293,21 @@ void framebuffer_init( struct framebuffer *fb ) attachment->purpose == k_framebuffer_attachment_type_texture_depth ) { glGenTextures( 1, &attachment->tex.name ); - attachment->tex.flags = VG_TEX_COMPLETE|VG_TEX_FRAMEBUFFER_ATTACHMENT|VG_TEX_LINEAR|VG_TEX_CLAMP|VG_TEX_NOMIP; + attachment->tex.flags = VG_TEX_COMPLETE|VG_TEX_FRAMEBUFFER_ATTACHMENT|VG_TEX_CLAMP|VG_TEX_NOMIP; framebuffer_allocate_texture( fb, attachment ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + if( fb->nearest ) + { + attachment->tex.flags |= VG_TEX_NEAREST; + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + } + else + { + attachment->tex.flags |= VG_TEX_LINEAR; + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + } glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glFramebufferTexture2D( GL_FRAMEBUFFER, attachment->attachment, GL_TEXTURE_2D, attachment->tex.name, 0 ); diff --git a/source/engine/vg_framebuffer.h b/source/engine/vg_framebuffer.h index 866a556..a086efa 100644 --- a/source/engine/vg_framebuffer.h +++ b/source/engine/vg_framebuffer.h @@ -9,7 +9,7 @@ struct framebuffer { const c8 *display_name; - int resolution_div, /* If 0: Use fixed_w, fixed_h. + i32 resolution_div, /* If 0: Use fixed_w, fixed_h. If non-0: Automatically size itself to the window resolution divided by this value */ @@ -18,6 +18,10 @@ struct framebuffer render_w, /* The currently rendering resolution */ render_h; + + f32 fixed_ratio; + b8 nearest; + GLuint id; u32 attachment_count; -- 2.25.1