8:00 – 3:30 FP
- Uniform Buffer Objects! Whee!
- Urk: “Any type consuming N bytes in a buffer begins on an N byte boundary within that buffer. That means that standard GLSL types such as int, float, and bool (which are all defined to be 32-bit or four-byte quantities) begin on multiples of four bytes. A vector of these types of length two always begins on a 2N byte boundary. For example, that means a vec2, which is eight bytes long in memory, always starts on an eight-byte boundary. Three- and four-element vectors always start on a 4N byte boundary; so vec3 and vec4 types start on 16-byte boundaries. Each member of an array of scalar or vector types (ints or vec3s, for example) always start boundaries defined by these same rules, but rounded up to the alignment of a vec4. In particular, this means that arrays of anything but vec4 (and Nx4 matrices) won’t be tightly packed, but instead there will be a gap between each of the elements. Matrices are essentially treated like short arrays of vectors, and arrays of matrices are treated like very long arrays of vectors. Finally, structures and arrays of structures have additional packing requirements; the whole structure starts on the boundary required by its largest member, rounded up to the size of a vec4.“
- Need to write up a class that handles shared objects. Should be a variant on the dictionary pattern
- DataElement class includes name, type, size, etc
- UniformBlock class
- Defines the name of the Uniform Block
- Makes sure that there is room for this block, and the binding
glGetIntegerv(GL_MAX_UNIFORM_BUFFERS) glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS)
- allocates the memory
- gets the block index
glGetUniformBlockIndex(GLuint program, const GLchar * uniformBlockName);
- returns pointers to data
- handles the writes into memory
- bind to the shader program (I think)
void glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
- Advanced Geometry Management (Chapter 12)
- Queries (picking, hopefully)
- Questions in OpenGL are represented by query objects, and much like any other object in OpenGL, query objects must be reserved, or generated. To do this, call glGenQueries, passing it the number of queries you want to reserve and the address of a variable (or array) where you would like the names of the query objects to be placed:
void glGenQueries(GLsizei n, GLuint *ids) Gluint myQueries[10]; glGenQueries(10, myQueries); for(int i = 0; i < 10; ++i){ if(myQueries[i] == 0) // throw an error } // run queries glBeginQuery(GL_ANY_SAMPLES_PASSED, myQueries); glEndQuery(GL_ANY_SAMPLES_PASSED); // usually this should be available immediately, but be careful to handle the case if it isn't glGetQueryObjectuiv(myQueries[0], GL_QUERY_RESULT_AVAILABLE, &result); if(result == GL_TRUE) glGetQueryObjectuiv(myQueries[0], GL_QUERY_RESULT, &result); // do something based on the result // then when done... glDeleteQueries(10, myQueries); // free up space for more queries - So the way picking would seem to work would be to set the viewport so that it’s slightly larger than the cursor, then render bounding boxes (using glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE)) inside a loop of questions, then read back (and wait for) the results of the question. If the object is visible in the small FOV, then we can regard it as picked.
- Setting up picking:
GLint viewport[4]; float ratio; glSelectBuffer(BUFSIZE,selectBuf); glGetIntegerv(GL_VIEWPORT,viewport); glRenderMode(GL_SELECT); glInitNames(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPickMatrix(cursorX,viewport[3]-cursorY,5,5,viewport); ratio = (viewport[2]+0.0) / viewport[3]; gluPerspective(45,ratio,0.1,1000); glMatrixMode(GL_MODELVIEW);
- The source for gluPerspective() is here
- Another way of doing picking – http://www.gpucomputing.net/sites/default/files/110606_picking_1.pdf
