Advertisement

Shader class instancing question

Started by February 23, 2018 01:46 AM
2 comments, last by too_many_stars 6 years, 11 months ago

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

 

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)

Advertisement

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

This topic is closed to new replies.

Advertisement