Jump to content
  • Advertisement
Sign in to follow this  
mrr

OpenGL making a array of some opengl functions

This topic is 2775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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++ ?

Share this post


Link to post
Share on other sites
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.. :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

When does the class get instantiated?

edit: beat me to the punch :D


I do not know.. I am C programmer dabbling with C++..

Share this post


Link to post
Share on other sites
You've got a potential type mismatch on your function pointer; should be void (GLAPIENTRY *glUniformNfv[4])(GLint location,GLsizei count,const GLfloat * value);

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!