getting vertices into a grid like structure
I have an array buffer that contains vertex positions. When buffer is used with glDrawArrays, it creates a volumetric object. I want the volumetric object to be on a grid - ie everything on or inside the volumetric object has a particular value and everything outside has a different value. I will need this grid format for some algorithm crunching.
How do i go about converting an array buffer with vertex position to something that looks like a grid? are 3D textures the only way?
Please explain it in a bit more detail as it's not exactly obvious what you want to achieve.
Do you want your vertex positions to be "snapped" to a grid with a predefined granularity? Or you also want to "voxelize" the whole volume?
Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
Technical Blog: http://www.rastergrid.com/blog/
I want both - voxelized object in a 3D grid of some predefined granularity
glDrawArrays uses GL_TRIANGLES to construct the volumetric/3D object using vertices from a vertex buffer object. What i want to do is take the constructed volumetric/3D object and mark all the voxels inside it with a particular value , let's say 1. Everything outside the 3D object has a value 0.
this volumetric/3D object will live in a grid , let's say 128 by 128 by 128.
I was thinking of using a 3D texture but there doesn't seem a way to go from the glDrawArrays to a 3D texture directly. You can go from a FBO to a texture by rendering into the texture target instead of the default window buffer/screen. But not from a VBO to a texture target.
Also, i do not want to use a clamped texture (sampled values between 0 and 1), so how would i create a notion of appropriate grid within a 3D texture?
There is nothing in OpenGL that directly helps with that task (OpenGL is a low level rendering library, it does not do geometry processing). Once you have generated a 3D texture you can again use OpenGL to render it, but generating the texture and determining which cells or inside/outside your mesh is something you have to do yourself.
There should be literature on how to voxelize triangle meshes, for example you may want to look at the work by Cyril Crassin, he does a lot with voxel data structures and computes them on the GPU.