packing and transparency
parent
a071406138
commit
6137773b77
|
@ -78,14 +78,14 @@ namespace blt::gfx
|
||||||
|
|
||||||
inline void drawRectangle(std::string_view texture, const rectangle_t& rectangle)
|
inline void drawRectangle(std::string_view texture, const rectangle_t& rectangle)
|
||||||
{
|
{
|
||||||
const static blt::vec4 empty {0,0,0,0};
|
const static blt::vec4 empty{0, 0, 0, 0};
|
||||||
const static blt::vec4 full {1,1,1,1};
|
const static blt::vec4 full{1, 1, 1, 1};
|
||||||
complex_rectangles[texture][empty][full].push_back(rectangle);
|
complex_rectangles[texture][empty][full].push_back(rectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void drawRectangle(const blt::vec4& color, const rectangle_t& rectangle)
|
inline void drawRectangle(const blt::vec4& color, const rectangle_t& rectangle)
|
||||||
{
|
{
|
||||||
const static blt::vec4 empty {0,0,0,0};
|
const static blt::vec4 empty{0, 0, 0, 0};
|
||||||
complex_rectangles[""][color][empty].push_back(rectangle);
|
complex_rectangles[""][color][empty].push_back(rectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +94,18 @@ namespace blt::gfx
|
||||||
complex_rectangles[draw_info.texture_name][draw_info.color][draw_info.blend].push_back(rectangle);
|
complex_rectangles[draw_info.texture_name][draw_info.color][draw_info.blend].push_back(rectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void render();
|
template<typename T, typename... P>
|
||||||
|
inline void drawRectangle(const T& render_info, P... p)
|
||||||
|
{
|
||||||
|
drawRectangle(render_info, {p...});
|
||||||
|
}
|
||||||
|
|
||||||
|
void render(bool transparency = true);
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
[[nodiscard]] inline size_t draw_count(){
|
[[nodiscard]] inline size_t draw_count()
|
||||||
|
{
|
||||||
return draw_count_;
|
return draw_count_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,8 +61,13 @@ namespace blt::gfx
|
||||||
delete shader;
|
delete shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
void batch_renderer_2d::render()
|
void batch_renderer_2d::render(bool transparency)
|
||||||
{
|
{
|
||||||
|
if (transparency)
|
||||||
|
{
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
draw_count_ = 0;
|
draw_count_ = 0;
|
||||||
shader->bind();
|
shader->bind();
|
||||||
square_vao->bind();
|
square_vao->bind();
|
||||||
|
@ -93,5 +98,7 @@ namespace blt::gfx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (transparency)
|
||||||
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -72,9 +72,8 @@ void update(std::int32_t width, std::int32_t height)
|
||||||
|
|
||||||
const float w = 120, h = 120, cf = 30, rf = 15, crf = 10;
|
const float w = 120, h = 120, cf = 30, rf = 15, crf = 10;
|
||||||
|
|
||||||
renderer_2d.drawRectangle("ibuythat", blt::gfx::rectangle_t(width/2.0, height/2.0, width, height, 90));
|
renderer_2d.drawRectangle("ibuythat", (float)width/2.0f, (float)height/2.0f, (float)width, (float)height, 90.0f);
|
||||||
renderer_2d.drawRectangle("niko", {bx, by, w, h});
|
renderer_2d.drawRectangle("niko", bx, by, w, h);
|
||||||
renderer_2d.drawRectangle({bx / width, ((bx / width) + (bx / height)) / 2.0f, by / height}, {bx + w, by + h, w, h});
|
|
||||||
|
|
||||||
bx += mx * blt::gfx::getFrameDeltaSeconds() * cf;
|
bx += mx * blt::gfx::getFrameDeltaSeconds() * cf;
|
||||||
by += my * blt::gfx::getFrameDeltaSeconds() * cf;
|
by += my * blt::gfx::getFrameDeltaSeconds() * cf;
|
||||||
|
|
Loading…
Reference in New Issue