Batch FillRect & Batch FillCircle.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
@@ -381,6 +381,10 @@ namespace JGL::J2D {
|
||||
void FillPolygon(const Color4& color, const std::vector<Vector2>& points);
|
||||
void OutlineEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, float thickness = 1, int subdivisions = 8);
|
||||
void FillEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, int subdivisions = 8);
|
||||
|
||||
void BatchFillRect(const Color4* colors, const Vector2* positions, const Vector2* sizes, const size_t& rect_count);
|
||||
|
||||
void BatchFillCircle(const Color4 *colors, const Vector2* positions, float* radii, unsigned int subdivisions, const size_t& circle_count);
|
||||
}
|
||||
|
||||
/// Drawing functions for 3D objects.
|
||||
|
@@ -184,19 +184,28 @@ void JGL::J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector
|
||||
}
|
||||
|
||||
void JGL::J2D::FillRect(const Color4& color, const Vector2& pos, const Vector2& size) {
|
||||
BatchFillRect(&color, &pos, &size, 1);
|
||||
}
|
||||
|
||||
void J2D::BatchFillRect(const Color4* colors, const Vector2* positions, const Vector2* sizes, const size_t& rect_count) {
|
||||
if (!state_stack.Size())
|
||||
Logger::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
if (rect_count <= 0)
|
||||
return;
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, ShapeCache::square_origin_topleft_vertex_data->GetHandle());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), nullptr);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(pos.x, pos.y + size.y, 0);
|
||||
glScalef(size.x, size.y, 1);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glPopMatrix();
|
||||
for (size_t i = 0; i < rect_count; i++) {
|
||||
glPushMatrix();
|
||||
glColor4ubv(colors[i].ptr());
|
||||
glTranslatef(positions[i].x, positions[i].y + sizes[i].y, 0);
|
||||
glScalef(sizes[i].x, sizes[i].y, 1);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glPopMatrix();
|
||||
}
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glColor4fv(default_state.draw_color);
|
||||
}
|
||||
|
||||
@@ -234,16 +243,18 @@ void JGL::J2D::FillGradientRect(const Color4& color1, const Color4& color2, cons
|
||||
}
|
||||
|
||||
void JGL::J2D::FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, unsigned int subdivisions) {
|
||||
if (!state_stack.Size())
|
||||
Logger::Error("Drawing J2D element before J2D begin.");
|
||||
std::array<Color4, 4> colors = { color, color, color, color };
|
||||
std::array<Vector2, 2> rect_positions = { Vector2(pos.x + radius, pos.y), {pos.x, pos.y + radius} };
|
||||
std::array<Vector2, 2> rect_sizes = { Vector2(size.x - 2 * radius, size.y), {size.x, size.y - 2 * radius} };
|
||||
std::array<float, 4> circle_radii = { radius, radius, radius, radius };
|
||||
std::array<Vector2, 4> circle_positions
|
||||
{
|
||||
Vector2(pos.x + radius, pos.y + radius), {pos.x + size.x - radius, pos.y + radius},
|
||||
{pos.x + radius, pos.y + size.y - radius}, {pos.x + size.x - radius, pos.y + size.y - radius}
|
||||
};
|
||||
|
||||
JGL::J2D::FillRect(color, {pos.x + radius, pos.y}, {size.x - 2 * radius, size.y});
|
||||
JGL::J2D::FillRect(color, {pos.x, pos.y + radius}, {size.x, size.y - 2 * radius});
|
||||
|
||||
JGL::J2D::FillCircle(color, {pos.x + radius, pos.y + radius}, radius, subdivisions);
|
||||
JGL::J2D::FillCircle(color, {pos.x + size.x - radius, pos.y + radius}, radius, subdivisions);
|
||||
JGL::J2D::FillCircle(color, {pos.x + radius, pos.y + size.y - radius}, radius, subdivisions);
|
||||
JGL::J2D::FillCircle(color, {pos.x + size.x - radius, pos.y + size.y - radius}, radius, subdivisions);
|
||||
J2D::BatchFillRect(colors.data(), rect_positions.data(), rect_sizes.data(), 2);
|
||||
J2D::BatchFillCircle(colors.data(), circle_positions.data(), circle_radii.data(), subdivisions, 4);
|
||||
}
|
||||
|
||||
void JGL::J2D::DrawSprite(const Texture* texture, float positionX, float positionY, float rad_rotation,
|
||||
@@ -733,9 +744,16 @@ void JGL::J2D::OutlineCircle(const Color4& color, const Vector2& center, float r
|
||||
}
|
||||
|
||||
void JGL::J2D::FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions) {
|
||||
BatchFillCircle(&color, ¢er, &radius, subdivisions, 1);
|
||||
}
|
||||
|
||||
void J2D::BatchFillCircle(const Color4* colors, const Vector2* positions, float* radii, unsigned int subdivisions, const size_t& circle_count) {
|
||||
if (!state_stack.Size())
|
||||
Logger::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
if (circle_count <= 0)
|
||||
return;
|
||||
|
||||
GLfloat angle, x, y;
|
||||
float step = (2.f * Math::Pi) / (float) subdivisions;
|
||||
std::vector<Vector2> vertices(subdivisions);
|
||||
@@ -745,8 +763,8 @@ void JGL::J2D::FillCircle(const Color4& color, const Vector2& center, float radi
|
||||
* wait around for the container to resize. This gets rid of it for what we can guarantee. */
|
||||
int i = 0;
|
||||
for (angle = 0.0f; angle < (2.f * Math::Pi); angle += step) {
|
||||
x = radius * std::sin(angle) + center.x;
|
||||
y = radius * std::cos(angle) + center.y;
|
||||
x = std::sin(angle);
|
||||
y = std::cos(angle);
|
||||
if (i < subdivisions)
|
||||
vertices[i] = {x, y};
|
||||
else
|
||||
@@ -754,9 +772,15 @@ void JGL::J2D::FillCircle(const Color4& color, const Vector2& center, float radi
|
||||
i++;
|
||||
}
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, (int) vertices.size());
|
||||
for (size_t j = 0; j < circle_count; j++) {
|
||||
glPushMatrix();
|
||||
glColor4ubv(colors[j].ptr());
|
||||
glTranslatef(positions[j].x, positions[j].y, 0);
|
||||
glScalef(radii[j], radii[j], 0);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, (int) vertices.size());
|
||||
glPopMatrix();
|
||||
}
|
||||
glColor4fv(default_state.draw_color);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user