2D graphics performance fix
This commit is contained in:
+16
-20
@@ -71,16 +71,16 @@ void Batch2D::texture(Texture* new_texture){
|
||||
}
|
||||
|
||||
void Batch2D::point(float x, float y, float r, float g, float b, float a){
|
||||
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||
// render(GL_TRIANGLES);
|
||||
if (index + 6*VERTEX_SIZE >= capacity)
|
||||
render(GL_TRIANGLES);
|
||||
|
||||
vertex(x, y, 0, 0, r,g,b,a);
|
||||
render(GL_POINTS);
|
||||
}
|
||||
|
||||
void Batch2D::line(float x1, float y1, float x2, float y2, float r, float g, float b, float a){
|
||||
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||
// render(GL_TRIANGLES);
|
||||
if (index + 6*VERTEX_SIZE >= capacity)
|
||||
render(GL_TRIANGLES);
|
||||
|
||||
vertex(x1, y1, 0, 0, r,g,b,a);
|
||||
vertex(x2, y2, 1, 1, r,g,b,a);
|
||||
@@ -92,8 +92,8 @@ void Batch2D::rect(float x, float y, float w, float h){
|
||||
const float g = color.g;
|
||||
const float b = color.b;
|
||||
const float a = color.a;
|
||||
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||
// render(GL_TRIANGLES);
|
||||
if (index + 6*VERTEX_SIZE >= capacity)
|
||||
render(GL_TRIANGLES);
|
||||
|
||||
vertex(x, y, 0, 0, r,g,b,a);
|
||||
vertex(x, y+h, 0, 1, r,g,b,a);
|
||||
@@ -102,7 +102,6 @@ void Batch2D::rect(float x, float y, float w, float h){
|
||||
vertex(x, y, 0, 0, r,g,b,a);
|
||||
vertex(x+w, y+h, 1, 1, r,g,b,a);
|
||||
vertex(x+w, y, 1, 0, r,g,b,a);
|
||||
render(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
void Batch2D::rect(
|
||||
@@ -114,8 +113,8 @@ void Batch2D::rect(
|
||||
bool flippedX,
|
||||
bool flippedY,
|
||||
vec4 tint) {
|
||||
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||
// render(GL_TRIANGLES);
|
||||
if (index + 6*VERTEX_SIZE >= capacity)
|
||||
render(GL_TRIANGLES);
|
||||
|
||||
float centerX = w*ox;
|
||||
float centerY = h*oy;
|
||||
@@ -197,14 +196,13 @@ void Batch2D::rect(
|
||||
vertex(x1, y1, u1, v1, tint.r, tint.g, tint.b, tint.a);
|
||||
vertex(x3, y3, u3, v3, tint.r, tint.g, tint.b, tint.a);
|
||||
vertex(x4, y4, u4, v4, tint.r, tint.g, tint.b, tint.a);
|
||||
render(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
void Batch2D::rect(float x, float y, float w, float h,
|
||||
float u, float v, float tx, float ty,
|
||||
float r, float g, float b, float a){
|
||||
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||
// render(GL_TRIANGLES);
|
||||
if (index + 6*VERTEX_SIZE >= capacity)
|
||||
render(GL_TRIANGLES);
|
||||
vertex(x, y, u, v+ty, r,g,b,a);
|
||||
vertex(x+w, y+h, u+tx, v, r,g,b,a);
|
||||
vertex(x, y+h, u, v, r,g,b,a);
|
||||
@@ -212,7 +210,6 @@ void Batch2D::rect(float x, float y, float w, float h,
|
||||
vertex(x, y, u, v+ty, r,g,b,a);
|
||||
vertex(x+w, y, u+tx, v+ty, r,g,b,a);
|
||||
vertex(x+w, y+h, u+tx, v, r,g,b,a);
|
||||
render(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
void Batch2D::rect(float x, float y, float w, float h,
|
||||
@@ -221,8 +218,8 @@ void Batch2D::rect(float x, float y, float w, float h,
|
||||
float r2, float g2, float b2,
|
||||
float r3, float g3, float b3,
|
||||
float r4, float g4, float b4, int sh){
|
||||
// if (index + 30*VERTEX_SIZE >= capacity)
|
||||
// render(GL_TRIANGLES);
|
||||
if (index + 30*VERTEX_SIZE >= capacity)
|
||||
render(GL_TRIANGLES);
|
||||
vec2 v0 = vec2(x+h/2,y+h/2);
|
||||
vec2 v1 = vec2(x+w-sh,y);
|
||||
vec2 v2 = vec2(x+sh,y);
|
||||
@@ -273,7 +270,6 @@ void Batch2D::rect(float x, float y, float w, float h,
|
||||
vertex(v6, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
vertex(v9, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
vertex(v1, vec2(0, 0), r2,g2,b2,1.0f);
|
||||
render(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
void Batch2D::sprite(Sprite* sprite) {
|
||||
@@ -353,10 +349,6 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int
|
||||
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
|
||||
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
|
||||
vertex(points[1], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
|
||||
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
render(GL_TRIANGLES);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
}
|
||||
|
||||
void Batch2D::render(unsigned int gl_primitive) {
|
||||
@@ -364,3 +356,7 @@ void Batch2D::render(unsigned int gl_primitive) {
|
||||
mesh->draw(gl_primitive);
|
||||
index = 0;
|
||||
}
|
||||
|
||||
void Batch2D::render() {
|
||||
render(GL_TRIANGLES);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
float r3, float g3, float b3,
|
||||
float r4, float g4, float b4, int sh);
|
||||
void render(unsigned int gl_primitive);
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif /* SRC_GRAPHICS_BATCH2D_H_ */
|
||||
|
||||
Reference in New Issue
Block a user