From cd7c34cb1616b8496acbf69042f0ab92cfbfca83 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 16 Apr 2024 02:28:02 -0400 Subject: [PATCH] multisampling --- CMakeLists.txt | 2 +- include/blt/gfx/renderer/2d_textured_circle.frag | 11 +++++++++-- include/blt/gfx/window.h | 1 + src/blt/gfx/window.cpp | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72f31bc..8e65d7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.9.10) +set(BLT_GRAPHICS_VERSION 0.9.11) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/renderer/2d_textured_circle.frag b/include/blt/gfx/renderer/2d_textured_circle.frag index 14d7031..75a42ef 100644 --- a/include/blt/gfx/renderer/2d_textured_circle.frag +++ b/include/blt/gfx/renderer/2d_textured_circle.frag @@ -12,6 +12,8 @@ uniform sampler2D tex; uniform vec4 color; uniform vec4 use_texture; +const float offset = 1.0 / 32.0; + vec4 linear_iter(vec4 i, vec4 p, float factor){ return (i + p) * factor; } @@ -19,9 +21,14 @@ vec4 linear_iter(vec4 i, vec4 p, float factor){ void main() { float xs = pos.x * pos.x; float ys = pos.y * pos.y; - if (xs + ys > 0.5 * 0.5) + float ts = xs + ys; + const float sq = 0.5 * 0.5; + if (ts > sq) discard; - FragColor = (texture(tex, uv) * use_texture) + color; + if (ts + offset > sq) + FragColor = vec4(1.0, 1.0, 1.0, 1.0); + else + FragColor = (texture(tex, uv) * use_texture) + color; } ")"; diff --git a/include/blt/gfx/window.h b/include/blt/gfx/window.h index e1ac30f..b544c9a 100644 --- a/include/blt/gfx/window.h +++ b/include/blt/gfx/window.h @@ -23,6 +23,7 @@ namespace blt::gfx std::int32_t GL_MINOR = 6; std::int32_t DOUBLE_BUFFER = GLFW_TRUE; std::int32_t GL_PROFILE = GLFW_OPENGL_CORE_PROFILE; + std::int32_t SAMPLES = 8; }; struct window_data diff --git a/src/blt/gfx/window.cpp b/src/blt/gfx/window.cpp index 2a4e360..c1f33a7 100644 --- a/src/blt/gfx/window.cpp +++ b/src/blt/gfx/window.cpp @@ -186,6 +186,7 @@ namespace blt::gfx glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, data.context.GL_MINOR); glfwWindowHint(GLFW_DOUBLEBUFFER, data.context.DOUBLE_BUFFER); glfwWindowHint(GLFW_OPENGL_PROFILE, data.context.GL_PROFILE); + glfwWindowHint(GLFW_SAMPLES, data.context.SAMPLES); /* -- Create the Window -- */ window_state.window = glfwCreateWindow(data.width, data.height, data.title.c_str(), nullptr, nullptr); @@ -204,6 +205,9 @@ namespace blt::gfx /* -- Set up ImGUI -- */ setup_ImGUI(); + if (data.context.SAMPLES > 0) + glEnable(GL_MULTISAMPLE); + /* -- Call User Provided post-window-init function -- */ data.init();