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
+10 -10
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;
}
+5 -5
View File
@@ -6,7 +6,7 @@
#include <GL/glew.h>
#include "../typedefs.h"
#define VERTEX_SIZE 9
const uint B3D_VERTEX_SIZE = 9;
using glm::vec2;
using glm::vec3;
@@ -19,7 +19,7 @@ Batch3D::Batch3D(size_t capacity)
{3}, {2}, {4}, {0}
};
buffer = new float[capacity * VERTEX_SIZE];
buffer = new float[capacity * B3D_VERTEX_SIZE];
mesh = new Mesh(buffer, 0, attrs);
index = 0;
@@ -84,7 +84,7 @@ void Batch3D::face(const vec3& coord, float w, float h,
const vec3& axisY,
const UVRegion& region,
const vec4& tint) {
if (index + VERTEX_SIZE * 6 > capacity) {
if (index + B3D_VERTEX_SIZE * 6 > capacity) {
flush();
}
vertex(coord, region.u1, region.v1,
@@ -118,7 +118,7 @@ void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, const UVRe
const float g = color.g;
const float b = color.b;
const float a = color.a;
if (index + 6*VERTEX_SIZE >= capacity) {
if (index + 6*B3D_VERTEX_SIZE >= capacity) {
flush();
}
@@ -179,7 +179,7 @@ void Batch3D::blockCube(const vec3 size, const UVRegion(&texfaces)[6], const vec
}
void Batch3D::flush() {
mesh->reload(buffer, index / VERTEX_SIZE);
mesh->reload(buffer, index / B3D_VERTEX_SIZE);
mesh->draw();
index = 0;
}
+5 -5
View File
@@ -17,7 +17,7 @@ using glm::ivec3;
using glm::vec3;
using glm::vec4;
#define VERTEX_SIZE 6
const uint BlocksRenderer::VERTEX_SIZE = 6;
BlocksRenderer::BlocksRenderer(size_t capacity,
const Content* content,
@@ -81,7 +81,7 @@ void BlocksRenderer::face(const vec3& coord, float w, float h,
const UVRegion& region,
const vec4(&lights)[4],
const vec4& tint) {
if (vertexOffset + VERTEX_SIZE * 4 > capacity) {
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
overflow = true;
return;
}
@@ -116,7 +116,7 @@ void BlocksRenderer::face(const ivec3& coord,
const ivec3& axisZ,
const ivec3& laxisZ,
const UVRegion& region) {
if (vertexOffset + VERTEX_SIZE * 4 > capacity) {
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
overflow = true;
return;
}
@@ -144,7 +144,7 @@ void BlocksRenderer::face(const ivec3& coord_,
float height,
float depth,
const UVRegion& region) {
if (vertexOffset + VERTEX_SIZE * 4 > capacity) {
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
overflow = true;
return;
}
@@ -414,7 +414,7 @@ Mesh* BlocksRenderer::render(const Chunk* chunk, int atlas_size, const ChunksSto
render(voxels, atlas_size);
const vattr attrs[]{ {3}, {2}, {1}, {0} };
Mesh* mesh = new Mesh(vertexBuffer, vertexOffset / VERTEX_SIZE, indexBuffer, indexSize, attrs);
Mesh* mesh = new Mesh(vertexBuffer, vertexOffset / BlocksRenderer::VERTEX_SIZE, indexBuffer, indexSize, attrs);
return mesh;
}
+1
View File
@@ -18,6 +18,7 @@ class ChunksStorage;
class ContentGfxCache;
class BlocksRenderer {
static const uint VERTEX_SIZE;
const Content* const content;
float* vertexBuffer;
int* indexBuffer;
+1 -1
View File
@@ -29,7 +29,7 @@ bool Font::isPrintableChar(int c) {
}
}
#define RES 16
const int RES = 16;
int Font::calcWidth(std::wstring text) {
return text.length() * 8;
+3 -3
View File
@@ -7,9 +7,9 @@
class Texture;
class Batch2D;
#define STYLE_NONE 0
#define STYLE_SHADOW 1
#define STYLE_OUTLINE 2
const uint STYLE_NONE = 0;
const uint STYLE_SHADOW = 1;
const uint STYLE_OUTLINE = 2;
class Font {
int lineHeight_;
+1 -1
View File
@@ -3,7 +3,7 @@
#include <GL/glew.h>
#define LB_VERTEX_SIZE (3+4)
const uint LB_VERTEX_SIZE = (3+4);
LineBatch::LineBatch(size_t capacity) : capacity(capacity) {
const vattr attrs[] = { {3},{4}, {0} };