minimize defines

This commit is contained in:
Ara 2023-12-04 22:50:00 +06:00
parent e0eacb51be
commit e45d85bc5a
17 changed files with 92 additions and 86 deletions

View file

@ -5,7 +5,7 @@
#include <GL/glew.h>
#define VERTEX_SIZE 8
const uint B2D_VERTEX_SIZE = 8;
using glm::vec2;
using glm::vec3;
@ -16,7 +16,7 @@ Batch2D::Batch2D(size_t capacity) : capacity(capacity), offset(0), color(1.0f, 1
{2}, {2}, {4}, {0}
};
buffer = new float[capacity * VERTEX_SIZE];
buffer = new float[capacity * B2D_VERTEX_SIZE];
mesh = new Mesh(buffer, 0, attrs);
index = 0;
@ -75,7 +75,7 @@ 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)
if (index + 6*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES);
vertex(x, y, 0, 0, r,g,b,a);
@ -83,7 +83,7 @@ void Batch2D::point(float x, float y, float r, float g, float b, float a){
}
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)
if (index + 6*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES);
vertex(x1, y1, 0, 0, r,g,b,a);
@ -96,7 +96,7 @@ 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)
if (index + 6*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES);
vertex(x, y, 0, 0, r,g,b,a);
@ -117,7 +117,7 @@ void Batch2D::rect(
bool flippedX,
bool flippedY,
vec4 tint) {
if (index + 6*VERTEX_SIZE >= capacity)
if (index + 6*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES);
float centerX = w*ox;
@ -205,7 +205,7 @@ void Batch2D::rect(
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)
if (index + 6*B2D_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);
@ -222,7 +222,7 @@ 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)
if (index + 30*B2D_VERTEX_SIZE >= capacity)
render(GL_TRIANGLES);
vec2 v0 = vec2(x+h/2,y+h/2);
vec2 v1 = vec2(x+w-sh,y);
@ -317,7 +317,7 @@ void Batch2D::blockSprite(float x, float y, float w, float h, const UVRegion reg
float scalex = regions[3].u2-regions[3].u1;
float scaley = regions[3].v2-regions[3].v1;
if (this->index + 18*VERTEX_SIZE >= capacity)
if (this->index + 18*B2D_VERTEX_SIZE >= capacity)
render();
float d = (w + h) * 0.5f;
@ -376,7 +376,7 @@ void Batch2D::blockSprite(float x, float y, float w, float h, const UVRegion reg
}
void Batch2D::render(unsigned int gl_primitive) {
mesh->reload(buffer, index / VERTEX_SIZE);
mesh->reload(buffer, index / B2D_VERTEX_SIZE);
mesh->draw(gl_primitive);
index = 0;
}