From 28b31bfbbbd2c96561d446ad35c1dc25402e49a1 Mon Sep 17 00:00:00 2001 From: MegaMech Date: Mon, 24 Feb 2025 16:39:16 -0700 Subject: [PATCH] more changes --- src/graphic/Fast3D/gfx_opengl.cpp | 8 ++++++-- src/graphic/Fast3D/gfx_pc.cpp | 9 ++++++++- src/graphic/Fast3D/shaders/opengl/default.shader.fs | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/graphic/Fast3D/gfx_opengl.cpp b/src/graphic/Fast3D/gfx_opengl.cpp index 046c692a4..19c49e71f 100644 --- a/src/graphic/Fast3D/gfx_opengl.cpp +++ b/src/graphic/Fast3D/gfx_opengl.cpp @@ -360,7 +360,7 @@ static std::string build_fs_shader(const CCFeatures& cc_features) { { "core_opengl", false }, { "texture", "texture2D" }, { "vOutColor", "gl_FragData[0]" }, - { "vColourId", "gl_FragData[3]" }, + { "vColourId", "gl_FragData[2]" }, #endif }; processor.populate(context); @@ -484,6 +484,7 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad GLuint shader_program = glCreateProgram(); glAttachShader(shader_program, vertex_shader); glAttachShader(shader_program, fragment_shader); + glBindFragDataLocation(shader_program, GL_COLOR_ATTACHMENT2, "vColourId"); glLinkProgram(shader_program); size_t cnt = 0; @@ -816,7 +817,7 @@ static void gfx_opengl_update_framebuffer_parameters(int fb_id, uint32_t width, glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.clrbuf, 0); } else { printf("\nFB ID %d\n\n", fb_id); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, fb.clrbuf, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, fb.clrbuf, 0); } } else { glBindRenderbuffer(GL_RENDERBUFFER, fb.clrbuf_msaa); @@ -825,6 +826,9 @@ static void gfx_opengl_update_framebuffer_parameters(int fb_id, uint32_t width, glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, fb.clrbuf_msaa); } } + + GLenum att[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT2 }; + glDrawBuffers(2, att); if (has_depth_buffer && (fb.width != width || fb.height != height || fb.msaa_level != msaa_level || !fb.has_depth_buffer)) { diff --git a/src/graphic/Fast3D/gfx_pc.cpp b/src/graphic/Fast3D/gfx_pc.cpp index c6587fcf9..06387d88b 100644 --- a/src/graphic/Fast3D/gfx_pc.cpp +++ b/src/graphic/Fast3D/gfx_pc.cpp @@ -4137,6 +4137,7 @@ void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, co colour_id_data.resize(width * height * 4); game_framebuffer_colour_id = gfx_rapi->create_framebuffer(); + gfx_rapi->update_framebuffer_parameters(0, width, height, 1, false, false, false, false, (uint8_t*)colour_id_data.data()); gfx_native_dimensions.width = SCREEN_WIDTH; gfx_native_dimensions.height = SCREEN_HEIGHT; @@ -4267,9 +4268,15 @@ void gfx_run(Gfx* commands, const std::unordered_map& mtx_replacemen gfx_rapi->start_draw_to_framebuffer(game_renders_to_framebuffer ? game_framebuffer : 0, (float)gfx_current_dimensions.height / gfx_native_dimensions.height); -// #define VIEW_COLOUR_ID_FRAMEBUFFER +#define VIEW_COLOUR_ID_FRAMEBUFFER #ifdef VIEW_COLOUR_ID_FRAMEBUFFER + gfx_rapi->start_draw_to_framebuffer(game_framebuffer_colour_id, gfx_current_dimensions.height / gfx_native_dimensions.height); +// test colours to colour id (this worked at one point but not now) +for (size_t i = 0; i < 1000; i++) { + colour_id_data[i] = 0x00FF00FF; +} + #endif gfx_rapi->clear_framebuffer(false, true); g_rdp.viewport_or_scissor_changed = true; diff --git a/src/graphic/Fast3D/shaders/opengl/default.shader.fs b/src/graphic/Fast3D/shaders/opengl/default.shader.fs index f02782cc7..c404c078b 100644 --- a/src/graphic/Fast3D/shaders/opengl/default.shader.fs +++ b/src/graphic/Fast3D/shaders/opengl/default.shader.fs @@ -211,5 +211,5 @@ void main() { @{vOutColor} = fromLinear(@{vOutColor}); @end - @{vColourId} = vec4(0.8, 0.2, 0.3, 1.0); + @{vColourId} = colour_id; }