diff --git a/CMakeLists.txt b/CMakeLists.txt index 193b9de..c309943 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.13.4) +set(BLT_GRAPHICS_VERSION 0.13.5) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/renderer/batch_2d_renderer.h b/include/blt/gfx/renderer/batch_2d_renderer.h index 3186d56..c97eec3 100644 --- a/include/blt/gfx/renderer/batch_2d_renderer.h +++ b/include/blt/gfx/renderer/batch_2d_renderer.h @@ -149,8 +149,7 @@ namespace blt::gfx class batch_renderer_2d { private: - std::unique_ptr engine = pp_engine_t::make_multi_pp(std::make_unique(), - std::make_unique()); + std::unique_ptr engine; template struct render_object_t @@ -210,8 +209,11 @@ namespace blt::gfx } public: - explicit batch_renderer_2d(resource_manager& resources): resources(resources) - {} + explicit batch_renderer_2d(resource_manager& resources, matrix_state_manager& state): resources(resources) + { + engine = pp_engine_t::make_multi_pp(std::make_unique(), + std::make_unique(state)); + } void create(); diff --git a/include/blt/gfx/renderer/postprocess.h b/include/blt/gfx/renderer/postprocess.h index 7ce6b04..61201b7 100644 --- a/include/blt/gfx/renderer/postprocess.h +++ b/include/blt/gfx/renderer/postprocess.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -95,10 +96,15 @@ namespace blt::gfx class pp_outline_step_t : public pp_step_t { public: + pp_outline_step_t(matrix_state_manager& manager): manager(manager) + {} void create() override; void draw(pp_step_t& previous) override; + + private: + matrix_state_manager& manager; }; class pp_engine_t diff --git a/include/blt/gfx/renderer/shaders/2d_textured.frag b/include/blt/gfx/renderer/shaders/2d_textured.frag index 68c8b0c..61f7cdc 100644 --- a/include/blt/gfx/renderer/shaders/2d_textured.frag +++ b/include/blt/gfx/renderer/shaders/2d_textured.frag @@ -5,7 +5,7 @@ const std::string shader_2d_textured_frag = R"(" precision mediump float; layout (location = 0) out vec4 FragColor; -layout (location = 1) out vec4 Mask; +layout (location = 1) out vec4 OutMask; in vec2 uv; in vec2 pos; @@ -20,8 +20,8 @@ vec4 linear_iter(vec4 i, vec4 p, float factor){ void main() { FragColor = (texture(tex, uv) * use_texture) + color; - Mask = outline_color; - //Mask.a = FragColor.a; + OutMask = outline_color; + OutMask.a = FragColor.a; } ")"; diff --git a/include/blt/gfx/renderer/shaders/2d_textured_circle.frag b/include/blt/gfx/renderer/shaders/2d_textured_circle.frag index dd3676c..3bb7d71 100644 --- a/include/blt/gfx/renderer/shaders/2d_textured_circle.frag +++ b/include/blt/gfx/renderer/shaders/2d_textured_circle.frag @@ -5,7 +5,7 @@ const std::string shader_2d_textured_cirlce_frag = R"(" precision mediump float; layout (location = 0) out vec4 FragColor; -layout (location = 1) out vec4 Mask; +layout (location = 1) out vec4 OutMask; in vec2 uv; in vec2 pos; @@ -28,8 +28,8 @@ void main() { if (ts >= sq) discard; FragColor = (texture(tex, uv) * use_texture) + color; - Mask = outline_color; - //Mask.a = FragColor.a; + OutMask = outline_color; + OutMask.a = FragColor.a; } ")"; diff --git a/include/blt/gfx/renderer/shaders/pp_outline_step.frag b/include/blt/gfx/renderer/shaders/pp_outline_step.frag index 0850140..fb4e2b6 100644 --- a/include/blt/gfx/renderer/shaders/pp_outline_step.frag +++ b/include/blt/gfx/renderer/shaders/pp_outline_step.frag @@ -13,6 +13,12 @@ uniform vec2 viewportSize; uniform sampler2D albedo; uniform sampler2D mask; +vec4 outline_color = vec4(1.0f, 0.0f, 0.0f, 1.0f); + +float longest(vec3 v){ + return max(v.r, max(v.b, v.g)); +} + #define LINE_WEIGHT 3.0 void main() { @@ -24,16 +30,16 @@ void main() { vec2 uvTop = vec2(uvCenter.x, uvCenter.y - dx); vec2 uvTopRight = vec2(uvCenter.x + dx, uvCenter.y - dx); - float mCenter = texture(mask, uvCenter).r; - float mTop = texture(mask, uvTop).r; - float mRight = texture(mask, uvRight).r; - float mTopRight = texture(mask, uvTopRight).r; + float mCenter = longest(texture(mask, uvCenter).rgb); + float mTop = longest(texture(mask, uvTop).rgb); + float mRight = longest(texture(mask, uvRight).rgb); + float mTopRight = longest(texture(mask, uvTopRight).rgb); float dT = abs(mCenter - mTop); float dR = abs(mCenter - mRight); float dTR = abs(mCenter - mTopRight); - float delta = 0.0; + float delta = 0.0f; delta = max(delta, dT); delta = max(delta, dR); delta = max(delta, dTR); @@ -41,7 +47,10 @@ void main() { vec4 outline = vec4(delta, delta, delta, 1.0); vec4 albedo = texture(albedo, uv); - FragColor = albedo - outline; + if (delta <= 0.001) + FragColor = albedo; + else + FragColor = outline_color; } ")"; diff --git a/src/blt/gfx/renderer/batch_2d_renderer.cpp b/src/blt/gfx/renderer/batch_2d_renderer.cpp index a8b43f0..2453f13 100644 --- a/src/blt/gfx/renderer/batch_2d_renderer.cpp +++ b/src/blt/gfx/renderer/batch_2d_renderer.cpp @@ -184,6 +184,8 @@ namespace blt::gfx glActiveTexture(GL_TEXTURE0); engine->bind(); + const GLenum buffers[]{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; + glDrawBuffers(2, buffers); draw_objects(); glDisable(GL_DEPTH_TEST); diff --git a/src/blt/gfx/renderer/postprocess.cpp b/src/blt/gfx/renderer/postprocess.cpp index 764e6b7..8a19cd6 100644 --- a/src/blt/gfx/renderer/postprocess.cpp +++ b/src/blt/gfx/renderer/postprocess.cpp @@ -156,8 +156,6 @@ namespace blt::gfx void pp_outline_target::draw() { draw_buffer.updateBuffersStorage(getWindowWidth(), getWindowHeight()); - glEnable(GL_TEXTURE0); - glEnable(GL_TEXTURE1); } void pp_outline_step_t::create() @@ -176,6 +174,7 @@ namespace blt::gfx glActiveTexture(GL_TEXTURE1); previous.getBuffer().getTexture(frame_buffer_t::attachment_t::COLOR1).bind(); shader->bind(); - shader->setVec2("viewportSize", static_cast(getWindowWidth()), static_cast(getWindowHeight())); + auto v = manager.getScale2D(); + shader->setVec2("viewportSize", static_cast(getWindowWidth()) * (1.0f/v.x()), static_cast(getWindowHeight()) * (1.0f / v.y())); } } \ No newline at end of file diff --git a/src/blt/gfx/shader.cpp b/src/blt/gfx/shader.cpp index 8f56174..e5f0b5a 100644 --- a/src/blt/gfx/shader.cpp +++ b/src/blt/gfx/shader.cpp @@ -168,6 +168,7 @@ namespace blt::gfx BLT_ERROR("I have an log of %d length", log_length); BLT_ERROR(infoLog.data()); BLT_ERROR("--- --- --- --- --- --- --- --- ---"); + std::exit(0); } glValidateProgram(programID);