Fixed a case where resizing the render target was no good
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m16s

This commit is contained in:
2025-02-07 01:56:34 -05:00
parent cb9fe4e5c9
commit 61c1c3245c
3 changed files with 84 additions and 106 deletions

View File

@@ -95,7 +95,7 @@ public:
/// @note The CPU thread this is called from & the GPU cannot do anything while this takes place. It's very slow.
[[nodiscard]] std::vector<GLfloat> GetPixels() const;
[[nodiscard]] static Vector2i MaximimSize();
[[nodiscard]] static Vector2i MaximumSize();
public:
/// Create a Render Target from a Render Target that already exists.
/** @note Render Targets that are copies of another will copy the Texture.

View File

@@ -4,7 +4,7 @@
#include "internals/internals.h"
void JGL::J2D::Begin(RenderTarget* render_target, bool clear_buffers) {
void J2D::Begin(RenderTarget* render_target, bool clear_buffers) {
State current_state = default_state;
state_stack.Push(State::SaveState());
@@ -43,7 +43,7 @@ void JGL::J2D::Begin(RenderTarget* render_target, bool clear_buffers) {
glLoadIdentity();
}
void JGL::J2D::End() {
void J2D::End() {
//Change back to the previous projection.
glPopMatrix();
glMatrixMode(GL_PROJECTION);
@@ -58,7 +58,7 @@ void JGL::J2D::End() {
state_stack.Pop();
}
void JGL::J2D::DrawPoint(const Color4& color, const Vector2& coordinates, float radius) {
void J2D::DrawPoint(const Color4& color, const Vector2& coordinates, float radius) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -69,11 +69,11 @@ void JGL::J2D::DrawPoint(const Color4& color, const Vector2& coordinates, float
glColor4fv(default_state.draw_color);
}
void JGL::J2D::DrawPoint(const Color4& color, float x, float y, float radius) {
void J2D::DrawPoint(const Color4& color, float x, float y, float radius) {
DrawPoint(color, {x, y}, radius);
}
void JGL::J2D::DrawLine(const Color4& color, const Vector2& A, const Vector2& B, float thickness) {
void J2D::DrawLine(const Color4& color, const Vector2& A, const Vector2& B, float thickness) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
Vector2 vertices[] = {A, B};
@@ -85,8 +85,8 @@ void JGL::J2D::DrawLine(const Color4& color, const Vector2& A, const Vector2& B,
glColor4fv(default_state.draw_color);
}
void JGL::J2D::DrawLine(const Color4& color, float x, float y, float w, float h, float thickness) {
JGL::J2D::DrawLine(color, {x, y}, {w, h}, thickness);
void J2D::DrawLine(const Color4& color, float x, float y, float w, float h, float thickness) {
J2D::DrawLine(color, {x, y}, {w, h}, thickness);
}
void J2D::DrawLines(const Color4& color, const Vector2* points, const size_t& point_count, float thickness) {
@@ -100,7 +100,7 @@ void J2D::DrawLines(const Color4& color, const Vector2* points, const size_t& po
glColor4fv(default_state.draw_color);
}
void JGL::J2D::DrawDottedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float thickness) {
void J2D::DrawDottedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float thickness) {
float distance = Vector2::Distance(A, B);
Vector2 direction = (B - A).Normalized();
@@ -113,14 +113,14 @@ void JGL::J2D::DrawDottedLine(const Color4& color, const Vector2& A, const Vecto
for (unsigned int i = 0; i < point_count; ++i)
points[i] = A + direction * (i * spacing);
return JGL::J2D::DrawPoints(color, points.data(), points.size(), thickness);
return J2D::DrawPoints(color, points.data(), points.size(), thickness);
}
void JGL::J2D::DrawDottedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float thickness) {
return JGL::J2D::DrawDottedLine(color, {x1, y1}, {x2, y2}, spacing, thickness);
void J2D::DrawDottedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float thickness) {
return J2D::DrawDottedLine(color, {x1, y1}, {x2, y2}, spacing, thickness);
}
void JGL::J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float dash_length, float thickness) {
void J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float dash_length, float thickness) {
float distance = Vector2::Distance(A, B);
Vector2 direction = (B - A).Normalized();
float length_of_dash_and_gap = dash_length + spacing;
@@ -133,7 +133,7 @@ void JGL::J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vecto
for (unsigned int i = 0; i < dash_count; i++) {
A_current = A + direction * (i * length_of_dash_and_gap);
B_current = A_current + (direction * dash_length);
JGL::J2D::DrawLine(color, A_current, B_current, thickness);
J2D::DrawLine(color, A_current, B_current, thickness);
}
// For the little piece at the end.
@@ -141,15 +141,15 @@ void JGL::J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vecto
if (distance_left > 0) {
A_current = A + direction * (dash_count * length_of_dash_and_gap);
B_current = A_current + direction * std::min(dash_length, distance_left);
JGL::J2D::DrawLine(color, A_current, B_current, thickness);
J2D::DrawLine(color, A_current, B_current, thickness);
}
}
void JGL::J2D::DrawDashedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float dash_length, float thickness) {
return JGL::J2D::DrawDashedLine(color, {x1, y1}, {x2, y2}, spacing, dash_length, thickness);
void J2D::DrawDashedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float dash_length, float thickness) {
return J2D::DrawDashedLine(color, {x1, y1}, {x2, y2}, spacing, dash_length, thickness);
}
void JGL::J2D::DrawGradientLine(const Color4& color1, const Color4& color2, const Vector2& A, const Vector2& B, float thickness) {
void J2D::DrawGradientLine(const Color4& color1, const Color4& color2, const Vector2& A, const Vector2& B, float thickness) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -167,10 +167,10 @@ void JGL::J2D::DrawGradientLine(const Color4& color1, const Color4& color2, cons
}
void DrawGradientLine(const Color4& color1, const Color4& color2, float x, float y, float w, float h, float thickness) {
JGL::J2D::DrawGradientLine(color1, color2, {x, y}, {w, h}, thickness);
J2D::DrawGradientLine(color1, color2, {x, y}, {w, h}, thickness);
}
void JGL::J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness) {
void J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -183,7 +183,7 @@ void JGL::J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FillRect(const Color4& color, const Vector2& pos, const Vector2& size) {
void J2D::FillRect(const Color4& color, const Vector2& pos, const Vector2& size) {
BatchFillRect(&color, &pos, &size, 1);
}
@@ -209,7 +209,7 @@ void J2D::BatchFillRect(const Color4* colors, const Vector2* positions, const Ve
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FillGradientRect(const Color4& color1, const Color4& color2, const Direction& gradient, const Vector2& pos, const Vector2& size) {
void J2D::FillGradientRect(const Color4& color1, const Color4& color2, const Direction& gradient, const Vector2& pos, const Vector2& size) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -242,7 +242,7 @@ void JGL::J2D::FillGradientRect(const Color4& color1, const Color4& color2, cons
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, unsigned int subdivisions) {
void J2D::FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, unsigned int subdivisions) {
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} };
@@ -257,25 +257,25 @@ void JGL::J2D::FillRoundedRect(const Color4& color, const Vector2& pos, const Ve
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,
void J2D::DrawSprite(const Texture* texture, float positionX, float positionY, float rad_rotation,
float originX, float originY,float scaleX, float scaleY,
const Color4& color, Direction inversion) {
DrawSprite(*texture, {positionX, positionY}, rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
}
void JGL::J2D::DrawSprite(const Texture* texture, const Vector2& position, float rad_rotation, const Vector2& origin,
void J2D::DrawSprite(const Texture* texture, const Vector2& position, float rad_rotation, const Vector2& origin,
const Vector2& scale, const Color4& color, Direction inversion) {
DrawSprite(*texture, position, rad_rotation, origin, scale, color, inversion);
}
void JGL::J2D::DrawPartialSprite(const Texture* texture, const Vector2& position, const Vector2& sub_texture_position,
void J2D::DrawPartialSprite(const Texture* texture, const Vector2& position, const Vector2& sub_texture_position,
const Vector2& sub_texture_size, float rad_rotation, const Vector2& origin,
const Vector2& scale, const Color4& color, Direction inversion) {
DrawPartialSprite(*texture, position, sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, inversion);
}
void JGL::J2D::DrawPartialSprite(const Texture* texture, float positionX, float positionY, float sub_texture_positionX,
void J2D::DrawPartialSprite(const Texture* texture, float positionX, float positionY, float sub_texture_positionX,
float sub_texture_positionY, unsigned int sub_texture_sizeX,
unsigned int sub_texture_sizeY, float rad_rotation, float originX, float originY,
float scaleX, float scaleY, const Color4& color, Direction inversion) {
@@ -283,27 +283,27 @@ void JGL::J2D::DrawPartialSprite(const Texture* texture, float positionX, float
rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
}
void JGL::J2D::DrawMirrorSprite(const Texture* texture, const Vector2& position, Direction mirror_axis, float rad_rotation,
void J2D::DrawMirrorSprite(const Texture* texture, const Vector2& position, Direction mirror_axis, float rad_rotation,
const Vector2& origin, const Vector2& scale, const Color4& color) {
DrawMirrorSprite(*texture, position, mirror_axis, rad_rotation, origin, scale, color);
}
void JGL::J2D::DrawSprite(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
void J2D::DrawSprite(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
DrawSprite(*render_target, position, rad_rotation, origin, scale, color, inversion);
}
void JGL::J2D::DrawRenderTarget(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
void J2D::DrawRenderTarget(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
DrawSprite(*render_target, position, rad_rotation, origin, scale, color, inversion);
}
void JGL::J2D::DrawRenderTarget(const RenderTarget& render_target, const Vector2& position, float rad_rotation,
void J2D::DrawRenderTarget(const RenderTarget& render_target, const Vector2& position, float rad_rotation,
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
DrawSprite(render_target, position, rad_rotation, origin, scale, color, inversion);
}
void JGL::J2D::DrawSprite(const JGL::RenderTarget& rt, const Vector2& position, float rad_rotation, const Vector2& origin,
void J2D::DrawSprite(const RenderTarget& rt, const Vector2& position, float rad_rotation, const Vector2& origin,
const Vector2& scale, const Color4& color, Direction inversion) {
//Correct for the render-target being upside-down.
@@ -326,14 +326,14 @@ void JGL::J2D::DrawSprite(const JGL::RenderTarget& rt, const Vector2& position,
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
auto r_position = Vector2(Math::Floor(position.x), Math::Floor(position.y));
JGL::J2D::DrawPartialSprite(*rt.GetTexture(), r_position, {0, 0}, Vector2(rt.GetDimensions()), rad_rotation, origin, scale, color, d);
J2D::DrawPartialSprite(*rt.GetTexture(), r_position, {0, 0}, Vector2(rt.GetDimensions()), rad_rotation, origin, scale, color, d);
if (rt.OwnsTexture())
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void JGL::J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, const Vector2& position, float rad_rotation,
const Vector2& origin, const Vector2& scale,const Color4& color, JGL::Direction inversion) {
void J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, const Vector2& position, float rad_rotation,
const Vector2& origin, const Vector2& scale,const Color4& color, Direction inversion) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -420,23 +420,23 @@ void JGL::J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, con
glColor4fv(default_state.draw_color);
}
void JGL::J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, const Vector2& position, float rad_rotation,
void J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, const Vector2& position, float rad_rotation,
const Vector2& origin, const Vector2& scale,const Color4& color, Direction inversion) {
DrawSprite(*texture, *alpha_mask, position, rad_rotation, origin, scale, color, inversion);
}
void JGL::J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, float positionX, float positionY, float rad_rotation,
void J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, float positionX, float positionY, float rad_rotation,
float originX, float originY,float scaleX, float scaleY,const Color4& color, Direction inversion) {
DrawSprite(texture, alpha_mask, {positionX, positionY}, rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
}
void JGL::J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, float positionX, float positionY, float rad_rotation,
void J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, float positionX, float positionY, float rad_rotation,
float originX, float originY,float scaleX, float scaleY,const Color4& color, Direction inversion) {
DrawSprite(*texture, *alpha_mask, {positionX, positionY}, rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
}
void JGL::J2D::DrawPartialRenderTarget(const JGL::RenderTarget& rt, const Vector2& position, const Vector2& sub_texture_position, const Vector2& sub_texture_size,
float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color, JGL::Direction inversion) {
void J2D::DrawPartialRenderTarget(const RenderTarget& rt, const Vector2& position, const Vector2& sub_texture_position, const Vector2& sub_texture_size,
float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
//Correct for the render-target being upside-down.
Direction d{};
@@ -461,18 +461,18 @@ void JGL::J2D::DrawPartialRenderTarget(const JGL::RenderTarget& rt, const Vector
auto r_position = Vector2(Math::Floor(position.x), Math::Floor(position.y));
auto r_sub_texture_position = Vector2(Math::Floor(sub_texture_position.x), Math::Floor(sub_texture_position.y));
JGL::J2D::DrawPartialSprite(*rt.GetTexture(), r_position, r_sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, d);
J2D::DrawPartialSprite(*rt.GetTexture(), r_position, r_sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, d);
if (rt.OwnsTexture())
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void JGL::J2D::DrawPartialRenderTarget(const JGL::RenderTarget* rt, const Vector2& position,const Vector2& sub_texture_position,const Vector2& sub_texture_size, float rad_rotation,
void J2D::DrawPartialRenderTarget(const RenderTarget* rt, const Vector2& position,const Vector2& sub_texture_position,const Vector2& sub_texture_size, float rad_rotation,
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
DrawPartialRenderTarget(*rt, position, sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, inversion);
}
void JGL::J2D::DrawSprite(const Texture& texture, const Vector2& pos, float rad_rotation, const Vector2& origin,
void J2D::DrawSprite(const Texture& texture, const Vector2& pos, float rad_rotation, const Vector2& origin,
const Vector2& scale, const Color4& color, Direction inversion) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -534,7 +534,7 @@ void JGL::J2D::DrawSprite(const Texture& texture, const Vector2& pos, float rad_
}
void JGL::J2D::DrawSprite(const Texture& texture, float positionX, float positionY, float rad_rotation, float originX,
void J2D::DrawSprite(const Texture& texture, float positionX, float positionY, float rad_rotation, float originX,
float originY, float scaleX, float scaleY, const Color4& color, Direction inversion) {
DrawSprite(texture,
{positionX, positionY},
@@ -544,7 +544,7 @@ void JGL::J2D::DrawSprite(const Texture& texture, float positionX, float positio
color, inversion);
}
void JGL::J2D::DrawPartialSprite(const Texture& texture, const Vector2& position, const Vector2& sub_texture_position,
void J2D::DrawPartialSprite(const Texture& texture, const Vector2& position, const Vector2& sub_texture_position,
const Vector2& sub_texture_size, float rad_rotation, const Vector2& origin,
const Vector2& scale, const Color4& color, Direction inversion) {
if (!state_stack.Size())
@@ -622,22 +622,22 @@ void JGL::J2D::DrawPartialSprite(const Texture& texture, const Vector2& position
glDisable(GL_TEXTURE_2D);
}
void JGL::J2D::DrawPartialSprite(const JGL::Texture& texture, float positionX, float positionY, float sub_texture_positionX,
void J2D::DrawPartialSprite(const Texture& texture, float positionX, float positionY, float sub_texture_positionX,
float sub_texture_positionY, unsigned int sub_texture_sizeX,
unsigned int sub_texture_sizeY, float originX, float originY, float rad_rotation,
float scaleX, float scaleY, const Color4& color, JGL::Direction inversion) {
float scaleX, float scaleY, const Color4& color, Direction inversion) {
JGL::J2D::DrawPartialSprite(texture, {positionX, positionY}, {sub_texture_positionX, sub_texture_positionY},
J2D::DrawPartialSprite(texture, {positionX, positionY}, {sub_texture_positionX, sub_texture_positionY},
{(float) sub_texture_sizeX, (float) sub_texture_sizeY}, rad_rotation, {originX, originY},
{scaleX, scaleY}, color, inversion);
}
void JGL::J2D::DrawMirrorSprite(const Texture& texture, const Vector2& position, Direction mirror_axis, float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color) {
void J2D::DrawMirrorSprite(const Texture& texture, const Vector2& position, Direction mirror_axis, float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
if (mirror_axis == Direction::None)
Logger::Warning("Drawing non-mirrored sprite with JGL::J2D::DrawMirrorSprite?");
Logger::Warning("Drawing non-mirrored sprite with J2D::DrawMirrorSprite?");
glBindTexture(GL_TEXTURE_2D, texture.GetHandle());
Vector2 size = Vector2(texture.GetDimensions());
@@ -716,7 +716,7 @@ void JGL::J2D::DrawMirrorSprite(const Texture& texture, const Vector2& position,
glDisable(GL_TEXTURE_2D);
}
void JGL::J2D::OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions, float thickness) {
void J2D::OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions, float thickness) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -743,7 +743,7 @@ void JGL::J2D::OutlineCircle(const Color4& color, const Vector2& center, float r
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions) {
void J2D::FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions) {
BatchFillCircle(&color, &center, &radius, subdivisions, 1);
}
@@ -784,7 +784,7 @@ void J2D::BatchFillCircle(const Color4* colors, const Vector2* positions, float*
glColor4fv(default_state.draw_color);
}
void JGL::J2D::OutlineTriangle(const Color4& color, const Triangle2D& tri, float thickness) {
void J2D::OutlineTriangle(const Color4& color, const Triangle2D& tri, float thickness) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -797,7 +797,7 @@ void JGL::J2D::OutlineTriangle(const Color4& color, const Triangle2D& tri, float
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FillTriangle(const Color4& color, const Triangle2D& tri) {
void J2D::FillTriangle(const Color4& color, const Triangle2D& tri) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -809,7 +809,7 @@ void JGL::J2D::FillTriangle(const Color4& color, const Triangle2D& tri) {
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Triangle2D& tri) {
void J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Triangle2D& tri) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -826,7 +826,7 @@ void JGL::J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color
glColor4fv(default_state.draw_color);
}
void JGL::J2D::DrawCubicBezierCurve(const Color4& color, const Vector2& controlA, const Vector2& pointA, const Vector2& pointB, const Vector2& controlB,
void J2D::DrawCubicBezierCurve(const Color4& color, const Vector2& controlA, const Vector2& pointA, const Vector2& pointB, const Vector2& controlB,
int subdivisions, float thickness) {
@@ -846,12 +846,12 @@ void JGL::J2D::DrawCubicBezierCurve(const Color4& color, const Vector2& controlA
DrawLines(color, vertices.data(), vertices.size(), thickness);
}
void JGL::J2D::OutlinePolygon(const Color4& color, const Vector2* points, int points_size, float thickness) {
void J2D::OutlinePolygon(const Color4& color, const Vector2* points, int points_size, float thickness) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
if (points[0] != points[points_size -1])
throw std::runtime_error("JGL::J2D::OutlinePolygon: The first point and the last point must connect.");
throw std::runtime_error("J2D::OutlinePolygon: The first point and the last point must connect.");
glLineWidth(thickness);
glColor4ubv(color.ptr());
@@ -860,12 +860,12 @@ void JGL::J2D::OutlinePolygon(const Color4& color, const Vector2* points, int po
glColor4fv(default_state.draw_color);
}
void JGL::J2D::DrawGradientLine(const Color4& color_a, const Color4& color_b, float x, float y, float w, float h,
void J2D::DrawGradientLine(const Color4& color_a, const Color4& color_b, float x, float y, float w, float h,
float thickness) {
DrawGradientLine(color_a, color_b, {x, y}, {w, h}, thickness);
}
void JGL::J2D::DrawArc(const Color4& color, const Vector2& center, float radius, float arc_begin, float arc_end, unsigned int subdivisions, float thickness)
void J2D::DrawArc(const Color4& color, const Vector2& center, float radius, float arc_begin, float arc_end, unsigned int subdivisions, float thickness)
{
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -898,7 +898,7 @@ void JGL::J2D::DrawArc(const Color4& color, const Vector2& center, float radius,
glColor4fv(default_state.draw_color);
}
void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, float thickness)
void J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, float thickness)
{
// A rounded rectangle of size 2a x 2b with rounding radius r is given by
// f(x; a, r) + f(y; b, r) = 1
@@ -913,7 +913,6 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
// TODO: Calculate vertices for top-left quarter-circle.
Vector2 tl = pos;
Vector2 tr = pos + Vector2(size.x, 0);
Vector2 br = pos + size;
Vector2 bl = pos + Vector2(0, size.y);
@@ -924,10 +923,10 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
Vector2 anchor_br = pos + size - Vector2(radius, radius);
Vector2 anchor_bl = pos + Vector2(radius, size.y - radius);
//JGL::J2D::Begin();
//JGL::J2D::DrawPoints(Colors::Red, {tl, tr, br, bl}, 2);
//JGL::J2D::DrawPoints(Colors::Blue, {anchor_tl, anchor_tr, anchor_br, anchor_bl}, 2);
//JGL::J2D::End();
//J2D::Begin();
//J2D::DrawPoints(Colors::Red, {tl, tr, br, bl}, 2);
//J2D::DrawPoints(Colors::Blue, {anchor_tl, anchor_tr, anchor_br, anchor_bl}, 2);
//J2D::End();
Vector2 anchor_topleft_top = pos + Vector2(radius, 0);
Vector2 anchor_topright_top = pos + Vector2(size.x - radius, 0);
@@ -941,7 +940,7 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
Vector2 anchor_bottomleft_left = pos + Vector2(0, size.y - radius);
Vector2 anchor_topleft_left = pos + Vector2(0, radius);
//JGL::J2D::Begin();
//J2D::Begin();
// The 3.01f, etc is a tiny-bit of overshoot to compensate for the fact that
// this is not being plotted as a continuous line-loop.
@@ -949,25 +948,24 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
unsigned int subdivisions = 9;
JGL::J2D::DrawArc(color, anchor_tl, radius, Math::Pi, 3.01f*Math::Pi/2.f, subdivisions, thickness);
JGL::J2D::DrawLine(color, anchor_topleft_top, anchor_topright_top, thickness);
JGL::J2D::DrawArc(color, anchor_tr, radius, 3.f*Math::Pi/2.f, 2.02*Math::Pi, subdivisions, thickness);
JGL::J2D::DrawLine(color, anchor_topright_right, anchor_bottomright_right, thickness);
JGL::J2D::DrawArc(color, anchor_br, radius, 0.0f, 1.01f*Math::Pi/2, subdivisions, thickness);
JGL::J2D::DrawLine(color, anchor_bottomright_bottom, anchor_bottomleft_bottom, thickness);
JGL::J2D::DrawArc(color, anchor_bl, radius, Math::Pi/2, Math::Pi*1.01f, subdivisions, thickness);
JGL::J2D::DrawLine(color, anchor_bottomleft_left, anchor_topleft_left, thickness);
//JGL::J2D::End();
J2D::DrawArc(color, anchor_tl, radius, Math::Pi, 3.01f*Math::Pi/2.f, subdivisions, thickness);
J2D::DrawLine(color, anchor_topleft_top, anchor_topright_top, thickness);
J2D::DrawArc(color, anchor_tr, radius, 3.f*Math::Pi/2.f, 2.02*Math::Pi, subdivisions, thickness);
J2D::DrawLine(color, anchor_topright_right, anchor_bottomright_right, thickness);
J2D::DrawArc(color, anchor_br, radius, 0.0f, 1.01f*Math::Pi/2, subdivisions, thickness);
J2D::DrawLine(color, anchor_bottomright_bottom, anchor_bottomleft_bottom, thickness);
J2D::DrawArc(color, anchor_bl, radius, Math::Pi/2, Math::Pi*1.01f, subdivisions, thickness);
J2D::DrawLine(color, anchor_bottomleft_left, anchor_topleft_left, thickness);
//J2D::End();
}
void JGL::J2D::FillChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius) {
void J2D::FillChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius) {
FillRoundedRect(color, pos, size, radius, 4);
}
void JGL::J2D::OutlineChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius,
float thickness) {
void J2D::OutlineChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, float thickness) {
Vector2 anchor_topleft_top = pos + Vector2(radius, 0);
Vector2 anchor_topright_top = pos + Vector2(size.x - radius, 0);
Vector2 anchor_topright_right = pos + Vector2(size.x, radius);
@@ -985,7 +983,7 @@ void JGL::J2D::OutlineChamferRect(const Color4& color, const Vector2& pos, const
glColor4fv(default_state.draw_color);
}
void JGL::J2D::DrawPoints(const Color4& color, const Vector2* points, int num_points, float radius) {
void J2D::DrawPoints(const Color4& color, const Vector2* points, int num_points, float radius) {
glPointSize(radius);
glColor4ubv(color.ptr());
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), points);
@@ -993,16 +991,16 @@ void JGL::J2D::DrawPoints(const Color4& color, const Vector2* points, int num_po
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FIllTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC) {
void J2D::FIllTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC) {
FillTriangle(color, {triA, triB, triC});
}
void JGL::J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Vector2& tri_a,
void J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Vector2& tri_a,
const Vector2& tri_b, const Vector2& tri_c) {
FillGradientTriangle(a_color, b_color, c_color, {tri_a, tri_b, tri_c});
}
void JGL::J2D::OutlineEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, float thickness,
void J2D::OutlineEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, float thickness,
int subdivisions) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");
@@ -1029,7 +1027,7 @@ void JGL::J2D::OutlineEllipse(const Color4& color, const Vector2& position, floa
glColor4fv(default_state.draw_color);
}
void JGL::J2D::FillEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, int subdivisions) {
void J2D::FillEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, int subdivisions) {
if (!state_stack.Size())
Logger::Error("Drawing J2D element before J2D begin.");

View File

@@ -140,30 +140,10 @@ void JGL::RenderTarget::Resize(const Vector2i& new_size) {
glGetIntegerv(GL_VIEWPORT, old_viewport);
glGetFloatv(GL_COLOR_CLEAR_VALUE, old_clear_color);
/* If what was previously not part of the renderable area is big enough
* to just set the new size. */
if (new_size.x <= texture->GetDimensions().x && new_size.y <= texture->GetDimensions().y) {
size = new_size;
// Clear.
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_object);
auto cc = GetClearColor();
glClearColor(cc.RedChannelNormalized(), cc.GreenChannelNormalized(), cc.BlueChannelNormalized(), cc.AlphaChannelNormalized());
glViewport(0,0, size.x, size.y);
glClear(GL_COLOR_BUFFER_BIT);
if (using_depth)
glClear(GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
glClearColor(old_clear_color[0], old_clear_color[1], old_clear_color[2], old_clear_color[3]);
glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);
return;
}
//If we have to remake the texture.
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_object);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
// Erase it.
delete texture;
@@ -382,6 +362,6 @@ JGL::RenderTarget::RenderTarget(const JGL::RenderTarget& rhs) {
operator delete(this_render_target);
}
Vector2i JGL::RenderTarget::MaximimSize() {
Vector2i JGL::RenderTarget::MaximumSize() {
return Texture::MaximumSize();
}