Jump to content
  • Advertisement
too_many_stars

OpenGL Shader class instancing question

Recommended Posts

Hello Everyone,

I have been going over a number of books and examples that deal with GLSL. It's common after viewing the source code to have something like this...

class Model{

public:
	Model();
	void render();

private:

	GLSL glsl_program;

};
////// .cpp

Model::Model(){
	
	glsl_program.compileAndLinkShaders()

}
void Model::render(){
	
	glsl_program.use()
		//render something
	glsl_program.unUse();
}

Is this how a shader program should be used in real time applications? For example, if I have a particle class, for every particle that's created, do I want to compiling and linking a vertex, frag shader? It seems to a noob such as myself this might not be the best approach to real time applications.

If I am correct, what is the best work around?

Thanks so much for all the help,

 

Mike

 

Share this post


Link to post
Share on other sites
Advertisement

For each effect you use one shader,

Say you draw 1000 particles with the same effect you use one shader only for that, it can be like some type of global variable defined somewhere so you can refer to it, or in this case you could use a pointer to gluint (shader)

Share this post


Link to post
Share on other sites

Thanks for the reply. 

Maybe a singleton registry with std::map< std::string , GLSL > pair? That would give a quick look up table for a particular shader and would make it available in any render method. 

Thanks Mike

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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!