BlocksRenderer light compressing & fix
This commit is contained in:
@@ -17,17 +17,17 @@ using glm::ivec3;
|
||||
using glm::vec3;
|
||||
using glm::vec4;
|
||||
|
||||
#define VERTEX_SIZE 9
|
||||
#define VERTEX_SIZE 6
|
||||
|
||||
BlocksRenderer::BlocksRenderer(size_t capacity,
|
||||
const Content* content,
|
||||
const ContentGfxCache* cache)
|
||||
: content(content),
|
||||
vertexOffset(0),
|
||||
indexOffset(0),
|
||||
indexSize(0),
|
||||
capacity(capacity),
|
||||
cache(cache) {
|
||||
BlocksRenderer::BlocksRenderer(size_t capacity,
|
||||
const Content* content,
|
||||
const ContentGfxCache* cache)
|
||||
: content(content),
|
||||
vertexOffset(0),
|
||||
indexOffset(0),
|
||||
indexSize(0),
|
||||
capacity(capacity),
|
||||
cache(cache) {
|
||||
vertexBuffer = new float[capacity];
|
||||
indexBuffer = new int[capacity];
|
||||
voxelsBuffer = new VoxelsVolume(CHUNK_W + 2, CHUNK_H, CHUNK_D + 2);
|
||||
@@ -50,10 +50,17 @@ void BlocksRenderer::vertex(const vec3& coord,
|
||||
vertexBuffer[vertexOffset++] = u;
|
||||
vertexBuffer[vertexOffset++] = v;
|
||||
|
||||
vertexBuffer[vertexOffset++] = light.r;
|
||||
vertexBuffer[vertexOffset++] = light.g;
|
||||
vertexBuffer[vertexOffset++] = light.b;
|
||||
vertexBuffer[vertexOffset++] = light.a;
|
||||
union {
|
||||
float floating;
|
||||
uint32_t integer;
|
||||
} compressed;
|
||||
|
||||
compressed.integer = (uint32_t(light.r * 255) & 0xff) << 24;
|
||||
compressed.integer |= (uint32_t(light.g * 255) & 0xff) << 16;
|
||||
compressed.integer |= (uint32_t(light.b * 255) & 0xff) << 8;
|
||||
compressed.integer |= (uint32_t(light.a * 255) & 0xff);
|
||||
|
||||
vertexBuffer[vertexOffset++] = compressed.floating;
|
||||
}
|
||||
|
||||
void BlocksRenderer::index(int a, int b, int c, int d, int e, int f) {
|
||||
@@ -72,7 +79,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 * 6 > capacity) {
|
||||
if (vertexOffset + VERTEX_SIZE * 4 > capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
@@ -90,7 +97,7 @@ void BlocksRenderer::face(const vec3& coord, float w, float h,
|
||||
const vec4(&lights)[4],
|
||||
const vec4& tint,
|
||||
bool rotated) {
|
||||
if (vertexOffset + VERTEX_SIZE * 6 > capacity) {
|
||||
if (vertexOffset + VERTEX_SIZE * 4 > capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
@@ -353,7 +360,7 @@ Mesh* BlocksRenderer::render(const Chunk* chunk, int atlas_size, const ChunksSto
|
||||
const voxel* voxels = chunk->voxels;
|
||||
render(voxels, atlas_size);
|
||||
|
||||
const vattr attrs[]{ {3}, {2}, {4}, {0} };
|
||||
const vattr attrs[]{ {3}, {2}, {1}, {0} };
|
||||
Mesh* mesh = new Mesh(vertexBuffer, vertexOffset / VERTEX_SIZE, indexBuffer, indexSize, attrs);
|
||||
return mesh;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user