Cocoa Design Patterns
Learning OpenGL ES for iOS
Buy at Amazon Now
  • Cocoa Design Patterns
    Cocoa Design Patterns
    by Erik M. Buck, Donald A. Yacktman
  • Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    by Erik M. Buck

Errata > AGLKprepareToDrawWithAttrib

I am puzzled by the your prepareToDrawWithAttrib method defined in AGLKVertexAttribArrayBuffer. This includes the glBindBuffer(GL_ARRAY_BUFFER, method call (step 2). This call is included in your initWithAttribStride method which if I've been following things correctly should precede the call to prepareToDrawWithAttrib. This would result in the call to glBindBuffer being duplicated. Indeed, in example OpenGLES_Ch2_3 commenting out the call to glBindBuffer in prepareToDrawWithAttrib makes no difference. Can you explain why the call to glBindBuffer is needed in your prepareToDrawWithAttrib method.

Thanks - Simon
February 7, 2014 | Unregistered CommenterSimon Moon
Generally speaking, an application may have multiple instances of AGLKVertexAttribArrayBuffer, and the instances may be used out of order with -prepareToDrawWithAttrib messages. If glBindBuffer() is not called, it is possible for AGLKVertexAttribArrayBuffer instances to corrupt each other's buffers.

The "state machine model" of OpenGL with every data structure "global" is the antithesis of object oriented programming unless you consider the entire GL context and associated state as one global object. When accessing global state within instances of objects, it's necessary to assure the correct global state is being used.

It may be that one reason OpenGL is not often successfully wrapped in objects is the prevalence of "unnecessary" state changes. On the other hand, without using objects, you end up with unstructured spaghetti code accessing global state all throughout the program.
February 7, 2014 | Registered CommenterErik Buck