From 39e09f9b8c937786340b49303c821918e1fae479 Mon Sep 17 00:00:00 2001 From: Adam Kewley Date: Tue, 7 Jan 2025 10:34:33 +0100 Subject: [PATCH] Merge PerVertexColor shader into oscimgui --- resources/oscar/shaders/PerVertexColor.frag | 9 ---- resources/oscar/shaders/PerVertexColor.vert | 16 ------- src/oscar/UI/oscimgui.cpp | 46 ++++++++++++++++++++- 3 files changed, 44 insertions(+), 27 deletions(-) delete mode 100644 resources/oscar/shaders/PerVertexColor.frag delete mode 100644 resources/oscar/shaders/PerVertexColor.vert diff --git a/resources/oscar/shaders/PerVertexColor.frag b/resources/oscar/shaders/PerVertexColor.frag deleted file mode 100644 index 238ad4a461..0000000000 --- a/resources/oscar/shaders/PerVertexColor.frag +++ /dev/null @@ -1,9 +0,0 @@ -#version 330 core - -in vec4 aVertColor; -out vec4 FragColor; - -void main() -{ - FragColor = aVertColor; -} diff --git a/resources/oscar/shaders/PerVertexColor.vert b/resources/oscar/shaders/PerVertexColor.vert deleted file mode 100644 index 1ef6a127c1..0000000000 --- a/resources/oscar/shaders/PerVertexColor.vert +++ /dev/null @@ -1,16 +0,0 @@ -#version 330 core - -uniform mat4 uProjMat; -uniform mat4 uViewMat; -uniform mat4 uModelMat; - -layout (location = 0) in vec3 aPos; -layout (location = 3) in vec4 aColor; - -out vec4 aVertColor; - -void main() -{ - gl_Position = uProjMat * uViewMat * uModelMat * vec4(aPos, 1.0); - aVertColor = aColor; -} diff --git a/src/oscar/UI/oscimgui.cpp b/src/oscar/UI/oscimgui.cpp index 720b999094..b3aa79b16f 100644 --- a/src/oscar/UI/oscimgui.cpp +++ b/src/oscar/UI/oscimgui.cpp @@ -169,6 +169,48 @@ namespace } )"; + // HACK: this shouldn't be necessary, but is, because the legacy draw list + // rendering code was dependent on it. + constexpr CStringView c_custom_ui_renderer_vertex_shader_src = R"( + #version 330 core + + uniform mat4 uProjMat; + uniform mat4 uViewMat; + uniform mat4 uModelMat; + + layout (location = 0) in vec3 aPos; + layout (location = 3) in vec4 aColor; + + out vec4 aVertColor; + + void main() + { + gl_Position = uProjMat * uViewMat * uModelMat * vec4(aPos, 1.0); + aVertColor = aColor; + } + )"; + + // HACK: this shouldn't be necessary, but is, because the legacy draw list + // rendering code was dependent on it. + constexpr CStringView c_custom_ui_renderer_fragment_shader_src = R"( + #version 330 core + + uniform mat4 uProjMat; + uniform mat4 uViewMat; + uniform mat4 uModelMat; + + layout (location = 0) in vec3 aPos; + layout (location = 3) in vec4 aColor; + + out vec4 aVertColor; + + void main() + { + gl_Position = uProjMat * uViewMat * uModelMat * vec4(aPos, 1.0); + aVertColor = aColor; + } + )"; + ImTextureID to_imgui_texture_id(UID id) { static_assert(std::is_same_v); @@ -2449,8 +2491,8 @@ void osc::ui::DrawList::render_to(RenderTexture& target) // solid color material const Material material{Shader{ - App::slurp("oscar/shaders/PerVertexColor.vert"), - App::slurp("oscar/shaders/PerVertexColor.frag"), + c_custom_ui_renderer_vertex_shader_src, + c_custom_ui_renderer_fragment_shader_src, }}; Camera c;