Automatically generate cubes

Hello

I want to draw a 3D structure made of 16x16x16 cubes. Not all of them must be drawn and each face of each cube may have a different texture (all the different square textures are in the same PNG file so with a number I can calculate the texture coordinates in the big texture).

Now, I have an array with 16x16x16 BOOL to tell if the cube must be drawn or not and an array of 16x16x16x6 int to give the index of the square texture of each face of each cube. Is it possible to pass only these 2 structures (+model/view/projection matrices+light parameters+cube size) via TBO, or whatever you advice, to shaders so that in 1 “glDrawArrays”, the whole structure is drawn without having to fill a big VBO with triangle+texture coordinates?

Thanks for your help
Cathy L.

You can tell glDrawArrays() to draw (161616)*6 quads (or *12 triangles), and have the vertex shader generate all of the data based upon gl_VertexID. You’ll need a geometry shader to discard the faces which aren’t supposed to be drawn based upon the boolean array (ideally, you’d also discard faces which would be obscured by an adjacent cube, i.e. only draw a face if the cube is visible and the adjacent cube isn’t).

In the past, I’ve encountered implementations which don’t like it if attribute array zero doesn’t exist. If you encounter that, you can either use a dummy array with one byte per vertex, or if that’s still too much, draw e.g. 161616 instances and use gl_InstanceID as well as gl_VertexID.

Thanks a lot, I’ll look this way. I’ve never used Geometry Shader before, I have to look into this.
Cathy L.