Jump to content
  • Advertisement

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{

	void render();


	GLSL glsl_program;

////// .cpp


void Model::render(){
		//render something

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,




Share this post

Link to post
Share on other sites

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!