I am working on a voxel engine in OpenGL and want a way to send my chunks to my shader
I know there are some really efficient methods and data structures out there to send voxels such as Sparse Voxel Octrees but I want to start simple, with only one chunk. In c++ chunk is defined as:
struct Chunk {
alignas(4) int voxelNum;
alignas(4) float voxelSize;
alignas(4) float chunkSize;
alignas(16) glm::vec4 position;
bool grid[16 * 16];
};
The SSBO is like this in glsl:
struct Chunk {
int voxelNum;
float voxelSize;
float chunkSize;
vec4 position;
bool grid[16 * 16];
};
layout (std140) uniform ChunkData {
Chunk chunk;
};
And the data is sent like this:
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_UNIFORM_BUFFER, buffer);
glBufferData(GL_UNIFORM_BUFFER, sizeof(Chunk), &chunk, GL_STATIC_DRAW);
I tested the code and this works great for all the variables up to the grid[] array. There, only the first element is correct.
How should I tackle this? More specifically, how can I send a single struct like this from my c++ code to the shader?
boolanint. I assumeboolis 8 bit on your CPU side, while it's 32 on the GPU side.