BatchFillOutlineRect
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m19s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m19s
This commit is contained in:
@@ -165,6 +165,8 @@ namespace JGL::J2D {
|
||||
/// @param thickness The width at which to render the lines.
|
||||
void OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness = 1);
|
||||
|
||||
void BatchOutlineRect(const Instance2D* instances, float thickness, const size_t& instance_count);
|
||||
|
||||
/// Draws an outline of a rectangle with rounded corners onto the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
|
@@ -277,23 +277,73 @@ void DrawGradientLine(const Color4& color1, const Color4& color2, float x, float
|
||||
}
|
||||
|
||||
void J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness) {
|
||||
Instance2D rect(color, pos, size);
|
||||
J2D::BatchOutlineRect(&rect, thickness, 1);
|
||||
}
|
||||
|
||||
void J2D::BatchOutlineRect(const Instance2D* instances, float thickness, const size_t& instance_count) {
|
||||
if (!state_stack.Size())
|
||||
Logger::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
Vector2 vertices[] = {{pos.x, pos.y}, {pos.x, pos.y + size.y}, {pos.x + size.x, pos.y + size.y}, {pos.x + size.x, pos.y}};
|
||||
|
||||
glLineWidth(thickness);
|
||||
glColor4ubv(color.ptr());
|
||||
if (instance_count <= 0)
|
||||
return;
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("JGL_RENDERING_ROUTINE", RENDERING_ROUTINE_ID::J2D_OutlineRect);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, ShapeCache::square_origin_topleft_vertex_data->Handle());
|
||||
glLineWidth(thickness);
|
||||
|
||||
if (instance_count == 1 || !supports_instanced || !current_state.current_shader) {
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), nullptr);
|
||||
|
||||
for (size_t i = 0; i < instance_count; i++) {
|
||||
glPushMatrix();
|
||||
glColor4ubv(instances[i].color.ptr());
|
||||
glTranslatef(instances[i].position.x, instances[i].position.y, 0);
|
||||
glScalef(instances[i].size.x, instances[i].size.y, 1);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
glPopMatrix();
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
else {
|
||||
current_state.current_shader->SetBool("JGL_INSTANCED_RENDERING", true);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vector2), nullptr);
|
||||
glVertexAttribDivisorARB(0, 0);
|
||||
|
||||
VRamList instance_buffer((GLfloat*) instances, instance_count * (sizeof(Instance2D) / sizeof(GLfloat)), Stream);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, instance_buffer.Handle());
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Instance2D), (GLvoid*) offsetof(Instance2D, position));
|
||||
glVertexAttribDivisorARB(1, 1);
|
||||
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Instance2D), (GLvoid*) offsetof(Instance2D, size));
|
||||
glVertexAttribDivisorARB(2, 1);
|
||||
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Instance2D), (GLvoid*) offsetof(Instance2D, color));
|
||||
glVertexAttribDivisorARB(3, 1);
|
||||
|
||||
glDrawArraysInstancedARB(GL_LINE_LOOP, 0, 4, instance_count);
|
||||
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glDisableVertexAttribArray(2);
|
||||
glDisableVertexAttribArray(3);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
current_state.current_shader->SetBool("JGL_INSTANCED_RENDERING", false);
|
||||
}
|
||||
|
||||
if (current_state.current_shader)
|
||||
current_state.current_shader->SetInt("JGL_RENDERING_ROUTINE", 0);
|
||||
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
glColor4fv(default_state.draw_color);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user