making a array of some opengl functions

Started by
7 comments, last by 21st Century Moose 13 years ago
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++ ?
Advertisement
I solved it.

The initialization of the pointers can not be done in the constructor.
Since at that time glew has not started yet.. :)
When does the class get instantiated?

edit: beat me to the punch :D
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 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 :D


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);

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement