diff --git a/CMakeLists.txt b/CMakeLists.txt index 623b192..38a7094 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.13.11) +set(BLT_GRAPHICS_VERSION 0.13.12) 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 39d055e..dd2990b 100644 --- a/include/blt/gfx/renderer/batch_2d_renderer.h +++ b/include/blt/gfx/renderer/batch_2d_renderer.h @@ -213,10 +213,11 @@ namespace blt::gfx explicit batch_renderer_2d(resource_manager& resources, matrix_state_manager& state): resources(resources), state(state) { engine = pp_engine_t::make_multi_pp(std::make_unique(), - std::make_unique(state, frame_buffer_t::attachment_t::COLOR1), - std::make_unique(frame_buffer_t::attachment_t::COLOR1, - vec4{4, 4, 4, 1}), - std::make_unique(frame_buffer_t::attachment_t::COLOR1, 2, 2), + std::make_unique(frame_buffer_t::attachment_t::COLOR1), + //std::make_unique(state, frame_buffer_t::attachment_t::COLOR1), + //std::make_unique(frame_buffer_t::attachment_t::COLOR1, + // vec4{4, 4, 4, 1}), + //std::make_unique(frame_buffer_t::attachment_t::COLOR1, 2, 2), std::make_unique(state) ); } diff --git a/include/blt/gfx/renderer/postprocess.h b/include/blt/gfx/renderer/postprocess.h index ffb3a12..5dba75f 100644 --- a/include/blt/gfx/renderer/postprocess.h +++ b/include/blt/gfx/renderer/postprocess.h @@ -165,7 +165,7 @@ namespace blt::gfx void create() override; - void draw(frame_buffer_t& previous); + void draw(frame_buffer_t& previous) override; private: matrix_state_manager& manager; @@ -187,33 +187,43 @@ namespace blt::gfx void create() override; - void draw(frame_buffer_t& previous); + void draw(frame_buffer_t& previous) override; private: i32 x_blur; i32 y_blur; }; - class pp_expansion_step_inplace_t : public pp_in_place_t + class pp_multiplier_step_inplace_t : public pp_in_place_t { public: - pp_expansion_step_inplace_t(frame_buffer_t::attachment_t from, const vec4& multiplier = vec4{2, 2, 2, 2}): + pp_multiplier_step_inplace_t(frame_buffer_t::attachment_t from, const vec4& multiplier = vec4{2, 2, 2, 2}): pp_in_place_t(from), multiplier(multiplier) {} - pp_expansion_step_inplace_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to, - const vec4& multiplier = vec4{2, 2, 2, 2}): + pp_multiplier_step_inplace_t(frame_buffer_t::attachment_t from, frame_buffer_t::attachment_t to, + const vec4& multiplier = vec4{2, 2, 2, 2}): pp_in_place_t(from, to), multiplier(multiplier) {} void create() override; - void draw(frame_buffer_t& previous); + void draw(frame_buffer_t& previous) override; private: vec4 multiplier; }; + class pp_mouse_highlight_step_t : public pp_in_place_t + { + public: + using pp_in_place_t::pp_in_place_t; + + void create() override; + + void draw(frame_buffer_t& previous) override; + }; + class pp_engine_t { public: @@ -230,7 +240,8 @@ namespace blt::gfx steps.emplace_back(std::move(step)); } - static std::unique_ptr createShader(std::string_view fragment, std::optional> engine = {}); + static std::unique_ptr createShader(std::string_view fragment, + std::optional> engine = {}); static std::unique_ptr make_basic_pp() { diff --git a/include/blt/gfx/renderer/shaders/pp_highlight.frag b/include/blt/gfx/renderer/shaders/pp_highlight.frag new file mode 100644 index 0000000..ca3977f --- /dev/null +++ b/include/blt/gfx/renderer/shaders/pp_highlight.frag @@ -0,0 +1,42 @@ +#ifdef __cplusplus +#include +const std::string shader_highlight_frag = R"(" +#version 300 es +precision mediump float; + +out vec4 FragColor; +in vec2 uv; +in vec2 pos; + +uniform sampler2D tex; +uniform ivec4 size; +uniform vec4 mousePos; + +void main() { + vec2 texelSize = 1.0 / vec2(float(size.x), float(size.y)); + vec4 result = vec4(0.0, 0.0, 0.0, 0.0); + for (int x = -size.z; x <= size.z; ++x) { + for (int y = -size.w; y <= size.w; ++y) { + vec2 offset = (vec2(float(x), float(y)) * texelSize); + result += texture(tex, uv + offset); + } + } + + float px = mousePos.x / float(size.x); + float py = mousePos.y / float(size.y); + + float dx = (gl_FragCoord.x - mousePos.x) / float(size.x); + float dy = (gl_FragCoord.y - mousePos.y) / float(size.y); + + float distx = sqrt(dx * dx); + float disty = sqrt(dy * dy); + + vec4 n_color = result / vec4((float(size.z) * 2.0 + 1.0) * (float(size.w) * 2.0 + 1.0)); + + FragColor = vec4(distx, disty, 0.0, 1.0); + + //FragColor = ; +} + +")"; +#endif \ No newline at end of file diff --git a/libraries/BLT b/libraries/BLT index f228cfb..9c0fc81 160000 --- a/libraries/BLT +++ b/libraries/BLT @@ -1 +1 @@ -Subproject commit f228cfbbe31538731a2ef1bd990d41c99562c4d3 +Subproject commit 9c0fc819690a99cbf8cdf923f1aeda22ff57ae9b diff --git a/libraries/imgui b/libraries/imgui index 231cbee..a1b0682 160000 --- a/libraries/imgui +++ b/libraries/imgui @@ -1 +1 @@ -Subproject commit 231cbee0fc4f59dbe5b8b853a11b08dc84e57c65 +Subproject commit a1b06823fe2d964a62fda99385499b218cf5cea5 diff --git a/libraries/openal-soft b/libraries/openal-soft index 111397c..6675317 160000 --- a/libraries/openal-soft +++ b/libraries/openal-soft @@ -1 +1 @@ -Subproject commit 111397c71a5f1c2c88e05da9c84edfdba2e472a4 +Subproject commit 6675317107257c2cc16c947b359d557821d85bf2 diff --git a/src/blt/gfx/renderer/batch_2d_renderer.cpp b/src/blt/gfx/renderer/batch_2d_renderer.cpp index e11effa..3b64853 100644 --- a/src/blt/gfx/renderer/batch_2d_renderer.cpp +++ b/src/blt/gfx/renderer/batch_2d_renderer.cpp @@ -72,8 +72,8 @@ namespace blt::gfx vertices_vbo.create(); indices_vbo.create(); - vertices_vbo.allocate(sizeof(line_vertices), line_vertices); - indices_vbo.allocate(sizeof(square_indices), square_indices); + vertices_vbo.allocate(sizeof(line_vertices), line_vertices, GL_DYNAMIC_DRAW); + indices_vbo.allocate(sizeof(square_indices), square_indices, GL_DYNAMIC_DRAW); line_vao = new vertex_array_t(); auto tb = line_vao->bindVBO(vertices_vbo, 0, 3, GL_FLOAT, 5 * sizeof(float), 0); diff --git a/src/blt/gfx/renderer/postprocess.cpp b/src/blt/gfx/renderer/postprocess.cpp index 8095f58..7253f47 100644 --- a/src/blt/gfx/renderer/postprocess.cpp +++ b/src/blt/gfx/renderer/postprocess.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -275,13 +276,13 @@ namespace blt::gfx shader->setVec4i("size", {static_cast(v.x()), static_cast(v.y()), x_blur, y_blur}); } - void pp_expansion_step_inplace_t::create() + void pp_multiplier_step_inplace_t::create() { pp_in_place_t::create(); shader = pp_engine_t::createShader(shader_multiplier_frag); } - void pp_expansion_step_inplace_t::draw(frame_buffer_t& previous) + void pp_multiplier_step_inplace_t::draw(frame_buffer_t& previous) { pp_in_place_t::draw(previous); shader->bind(); @@ -301,4 +302,19 @@ namespace blt::gfx auto v = vec2(getWindowWidth(), getWindowHeight()); shader->setVec4i("size", {static_cast(v.x()), static_cast(v.y()), x_blur, y_blur}); } + + void pp_mouse_highlight_step_t::create() + { + pp_in_place_t::create(); + shader = pp_engine_t::createShader(shader_highlight_frag); + } + + void pp_mouse_highlight_step_t::draw(frame_buffer_t& previous) + { + pp_in_place_t::draw(previous); + shader->bind(); + auto v = vec2(getWindowWidth(), getWindowHeight()); + shader->setVec4("mousePos", blt::make_vec4(blt::vec2{getMouseX(), v.y() - getMouseY()})); + shader->setVec4i("size", {static_cast(v.x()), static_cast(v.y()), 2, 2}); + } } \ No newline at end of file diff --git a/src/blt/gfx/window.cpp b/src/blt/gfx/window.cpp index a9e9ecb..7eadff9 100644 --- a/src/blt/gfx/window.cpp +++ b/src/blt/gfx/window.cpp @@ -30,7 +30,7 @@ void error_callback(int error, const char* description) void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei, const GLchar* message, const void*) { // do not log performance concerns - if (type == GL_DEBUG_TYPE_PERFORMANCE || type == GL_DEBUG_TYPE_OTHER) + if (type == GL_DEBUG_TYPE_OTHER) return; if (type == GL_DEBUG_TYPE_ERROR) {