outlining

main
Brett 2024-05-13 22:12:06 -04:00
parent b239984fd1
commit af143549cb
2 changed files with 39 additions and 13 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
set(BLT_GRAPHICS_VERSION 0.13.15) set(BLT_GRAPHICS_VERSION 0.13.16)
set(BLT_GRAPHICS_TEST_VERSION 0.0.1) set(BLT_GRAPHICS_TEST_VERSION 0.0.1)
project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION})

View File

@ -188,23 +188,36 @@ namespace blt::gfx
const f32 denominator = 1.0f / (draw.z_max - draw.z_min); const f32 denominator = 1.0f / (draw.z_max - draw.z_min);
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilMask(0xFF);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilMask(0xFF);
glStencilFunc(GL_ALWAYS, 1, 0xFF); glStencilFunc(GL_ALWAYS, 1, 0xFF);
draw_points(false, denominator); draw_points(false, denominator);
glStencilFunc(GL_NOTEQUAL, 1, 0xFF); glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
glStencilMask(0x00); glStencilMask(0x00);
glDisable(GL_DEPTH_TEST);
draw_points(true, denominator); draw_points(true, denominator);
glEnable(GL_DEPTH_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilMask(0xFF);
glStencilFunc(GL_ALWAYS, 2, 0xFF);
draw_rectangles(false, denominator); draw_rectangles(false, denominator);
glStencilFunc(GL_NOTEQUAL, 2, 0xFF);
glStencilMask(0x00);
draw_rectangles(true, denominator);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilMask(0xFF);
glStencilFunc(GL_ALWAYS, 4, 0xFF);
draw_lines(false, denominator); draw_lines(false, denominator);
glDisable(GL_STENCIL_TEST); glStencilFunc(GL_NOTEQUAL, 4, 0xFF);
glStencilMask(0x00);
draw_lines(true, denominator);
glDisable(GL_STENCIL_TEST);
post_reset(); post_reset();
} }
@ -241,7 +254,8 @@ namespace blt::gfx
model.translate(point.pos.x(), point.pos.y(), 0.0f); model.translate(point.pos.x(), point.pos.y(), 0.0f);
if (outlined) if (outlined)
{ {
BLT_TRACE(render_info.outline_thickness); if (!render_info.outline)
continue;
model.scale(point.scale * render_info.outline_thickness, point.scale * render_info.outline_thickness, 1.0); model.scale(point.scale * render_info.outline_thickness, point.scale * render_info.outline_thickness, 1.0);
point_shader->setVec4("color", render_info.outline_color); point_shader->setVec4("color", render_info.outline_color);
point_shader->setVec4("use_texture", blt::vec4{0,0,0,0}); point_shader->setVec4("use_texture", blt::vec4{0,0,0,0});
@ -252,7 +266,6 @@ namespace blt::gfx
point_shader->setVec4("use_texture", render_info.blend); point_shader->setVec4("use_texture", render_info.blend);
} }
point_shader->setVec4("outline_color", render_info.outline_color); point_shader->setVec4("outline_color", render_info.outline_color);
point_shader->setFloat("z_index", (z_index - draw.z_min) * denominator); point_shader->setFloat("z_index", (z_index - draw.z_min) * denominator);
point_shader->setMatrix("model", model); point_shader->setMatrix("model", model);
@ -260,7 +273,8 @@ namespace blt::gfx
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
draw.draw_count++; draw.draw_count++;
} }
objects.clear(); if (outlined)
objects.clear();
} }
} }
@ -280,8 +294,16 @@ namespace blt::gfx
{ {
auto& [z_index, line] = object; auto& [z_index, line] = object;
square_shader->setVec4("color", render_info.color); if (outlined){
square_shader->setVec4("use_texture", render_info.blend); if (!render_info.outline)
continue;
square_shader->setVec4("color", render_info.outline_color);
square_shader->setVec4("use_texture", {0,0,0,0});
} else {
square_shader->setVec4("color", render_info.color);
square_shader->setVec4("use_texture", render_info.blend);
}
square_shader->setVec4("outline_color", render_info.outline_color); square_shader->setVec4("outline_color", render_info.outline_color);
square_shader->setFloat("z_index", (z_index - draw.z_min) * denominator); square_shader->setFloat("z_index", (z_index - draw.z_min) * denominator);
@ -316,7 +338,8 @@ namespace blt::gfx
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
draw.draw_count++; draw.draw_count++;
} }
objects.clear(); if (outlined)
objects.clear();
} }
} }
@ -335,6 +358,8 @@ namespace blt::gfx
mat4x4 model; mat4x4 model;
if (outlined) { if (outlined) {
if (!render_info.outline)
continue;
auto nsx = rect.size.x() * render_info.outline_thickness; auto nsx = rect.size.x() * render_info.outline_thickness;
auto nsy = rect.size.y() * render_info.outline_thickness; auto nsy = rect.size.y() * render_info.outline_thickness;
auto ns = blt::vec2(nsx, nsy); auto ns = blt::vec2(nsx, nsy);
@ -358,7 +383,8 @@ namespace blt::gfx
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
draw.draw_count++; draw.draw_count++;
} }
objects.clear(); if (outlined)
objects.clear();
} }
} }
} }