Closed TwoPints closed 10 years ago
Could you give me a little more information about what you're trying to achieve? Maybe a sample code of how you want to call that additional method? (And why you can't call 'prepareToDraw' instead.) Just so that I know exactly was this is about, and can make the change in a way that's most useful. Thanks!
prepareToDraw works, it however has the extra overhead of needless gl calls, and the function name itself implies something in this context that you're not doing.
This is code within a classes init: method so not called within a render. The suggestion I'm asking for is just a separation of concerns, so the body within prepareForRender can call to generateProgram (or a more appropriate name), I should have done that as part of the pull request in hindsight to make it more clear. As is, it also has the problem of having to have a valid texture to create a textured program, even though it's not necessarily used for a while, just cached.
The more I think about it, the more the pull request needs changing. :)
for (int i=0; i<NUM_VERTEX_VBO_BUFFERS; ++i) {
baseEffect[i] = [[SPBaseEffect alloc]init];
baseEffect[i].texture = [mTextures lastObject];
[baseEffect[i] prepareToDraw];
//[baseEffect[i] createProgram];
numQuads[i] = activeQuads;
numVertices[i] = activeQuads * 4;
numIndices[i] = activeQuads * 6;
// Generate dynamic vbo so we can change the data later, copy the prefab data to stop any bitching.
glGenBuffers(1, &vertexVBO[i]);
glBindBuffer(GL_ARRAY_BUFFER, vertexVBO[i]);
glBufferData(GL_ARRAY_BUFFER, _numVertices * sizeof(TiledVertexDef), vertexBuffer, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Create vertex array object for speed, not sure if it helps in the scheme of things as presentRenderBuffer takes more time (unless this is idle time?)
glGenVertexArraysOES(1, &vao[i]);
glBindVertexArrayOES(vao[i]);
glBindBuffer(GL_ARRAY_BUFFER, vertexVBO[i]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO);
glVertexAttribPointer(baseEffect[i].attribPosition, 2, GL_SHORT, GL_FALSE, sizeof(TiledVertexDef), (void *)(offsetof(TiledVertexDef, x)));
glEnableVertexAttribArray(baseEffect[i].attribPosition);
glVertexAttribPointer(baseEffect[i].attribColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(TiledVertexDef), (void *)(offsetof(TiledVertexDef, color)));
glEnableVertexAttribArray(baseEffect[i].attribColor);
glVertexAttribPointer(baseEffect[i].attribTexCoords, 2, GL_FLOAT, GL_TRUE, sizeof(TiledVertexDef), (void *)(offsetof(TiledVertexDef, u)));
glEnableVertexAttribArray(baseEffect[i].attribTexCoords);
glBindVertexArrayOES(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
etc
Why did you close the request? Did you find another solution / or do you want to send a new one with the final version?
I've closed it as I realised creating the program requires a texture as its parameter rather than a bool even though it's not used (apart from checking it as if it were a bool) so I need to do more changes than the initial pull request and probably need to think about it more.
...the program before creating a VAO as the attributes need setting before we can call glVertexAttribPointer etc. Probably needs implementing a bit better than this.