I am planing to implement a rendering process, which calculates the distance to a mesh into each voxel of a volume grid. I want to represent this volume grid with a 3d texture, or 2D array, … I am not sure which one to choose and further I tried to implement some variants and they don’t seem to work. Ma questions are:
[ol]
[li]Which texture typ whould be the best for my case
[/li][li]How do I implement it
[/li][li]How to write an read into this volume grid
[/li][li]How can I check for debugin what is written in a texture/frame buffer
[/li][/ol]
I started with an implementation which doesn’t seem to work:
glGenFramebuffers(1, &_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, GRID_SIZE, GRID_SIZE, GRID_SIZE, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_3D, 0);
glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, texture, 0, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) {
std::cout << "FBO successfully loadet" << std::endl;
}else{
std::cout << "FBO had en ERROR" << std::endl;
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
for the rendering process:
glBindFramebuffer(GL_FRAMEBUFFER, fbo->getFBO());
_shader.use();
glBindVertexArray(_vao);
for (int i = 0; i < GRID_SIZE; ++i) {
glFramebufferTexture3D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_3D, fbo->getTextureID(), 0, i);
glDrawArrays(GL_POINTS, 0, _PointSize);
}
glBindVertexArray(0);
Here also a thing I don’t really understand. Do I really load a 3Dtexture for each layer that is been rendered? So does he only render in this layer? Or can’t I attache a 3DTexture to the buffer and render to 2DTextures that are been loaded to the layer of the 3DTexture.
The shaders for the moment are straight forward. They are for the moment only rendering white points. I actually wan’t to test that if I render only white points to the 0 layer, than the rest should be black. But as a result either all pixels are black or alle pixels are white :S I hope someone can show me a nice simple implementation for a 3Dtexture or 2DTexture-Array or something similar which i can use, and where I can read out data to, to see that it is written properly. Because something i am doing wrong the hole time :S