Hi
I am trying to make an array of some opengl functions so I can call them easier, what I am doing is this.
In a class:
void (*glUniformNfv[4])(GLint location,GLsizei count,const GLfloat * value);
In class constructor I initialize pointers to the functions;
glUniformNfv[0] = glUniform1fv;
glUniformNfv[1] = glUniform2fv;
glUniformNfv[2] = glUniform3fv;
glUniformNfv[3] = glUniform4fv;
And then calling by:
glUniformNfv[nitems ](loc,1,data);
This way no switch case statement on the number of items (nitems) is needed, and this is faster.
However passing the address of the functions glUniform1fv passes null!!!
Note they are initialized already by Glew.. (calling them in the normal way works)
But here somehow they do not behave like ordinary functions? or is this not allowed in C++ ?
making a array of some opengl functions
I solved it.
The initialization of the pointers can not be done in the constructor.
Since at that time glew has not started yet..
The initialization of the pointers can not be done in the constructor.
Since at that time glew has not started yet..
I'm not so sure if this will be fast.
I'm no C expert, but I think that switch cases are similar handled in assembler as array lookups.
And using a function pointer gives extra overhead
I'm no C expert, but I think that switch cases are similar handled in assembler as array lookups.
And using a function pointer gives extra overhead
I'm not so sure if this will be fast.
I'm no C expert, but I think that switch cases are similar handled in assembler as array lookups.
And using a function pointer gives extra overhead
Nah it is probably about the same speed.. I just do not like switch case statements.
When does the class get instantiated?
edit: beat me to the punch
I do not know.. I am C programmer dabbling with C++..
You've got a potential type mismatch on your function pointer; should be void (GLAPIENTRY *glUniformNfv[4])(GLint location,GLsizei count,const GLfloat * value);
You've got a potential type mismatch on your function pointer; should be void (GLAPIENTRY *glUniformNfv[4])(GLint location,GLsizei count,const GLfloat * value);
No according to opengl standard they are all void.
Now If I needed to find the pointer like Glew does then I think you are right..but that is already done by Glew.
GLAPIENTRY actually is defined as something on some platforms. This affects the calling convention used and can cause runtime errors if you get it wrong. So if you want your program to be portable you're going to have to match that definition.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement