Jump to content
  • Advertisement
Sign in to follow this  
ilys4

OpenGL Same codes in shader program

This topic is 4348 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

1. I wanna use shader for changing the only few features of pipeline. (other people may want to) But, in using shader, do I have to implement all the features of those (vertex or pixel of both) shaders? I think it is a wasteful that I make common same code for all shader programs, such like, lighting or texturing which are all implemented by default opengl pipeline that I don't want to change. Is there any other way? Do I have to paste same codes all the shader files? 2. I know '#include' is not permitted in shader code. So, Is there any other way?

Share this post


Link to post
Share on other sites
Advertisement
You can give the GLSL interface multiple source buffers, which is sorta like using #include directive. This way you can declare source with common functions and "link" that with specific shaders.

void ShaderSourceARB(handleARB shaderObj, sizei count, const charARB **string,
const int *length)

You just make a list of sources:


std::vector<charARB*> sources;
for ( files )
sources.push_back ( read_file( file ) );

glShaderSourceARB( handle, sources.size(), &sources[0], 0 );



ch.

Share this post


Link to post
Share on other sites
Quote:

I think it is a wasteful that I make common same code for all shader programs,
such like, lighting or texturing which are all implemented by default opengl pipeline that I don't want to change.


Once you use a shader, you've replaced the entire portion of the pipeline where the shader would go, even if your shader doesn't implement portions of that pipeline. You can't use a vertex shader for, say, transformation but still use the default fixed-function lighting.

You'll have to implement a mimicry of the fixed-function aspects you'd like to keep (I believe GLSL has an ftransform() that will aid in this), and include those into your composite shader program somehow (perhaps in the manner suggested by the above poster).

Share this post


Link to post
Share on other sites
As shaders are just strings before to be uploaded into the card, keep in mind that YOU can manually implement an #include macro. Scan the string, once found "#include", read the next string and subsitute the two by the content of the file... that can sound stupid, but in fact that is not so many work...

Share this post


Link to post
Share on other sites
Quote:
Original post by jfdegbo
As shaders are just strings before to be uploaded into the card, keep in mind that YOU can manually implement an #include macro. Scan the string, once found "#include", read the next string and subsitute the two by the content of the file... that can sound stupid, but in fact that is not so many work...

Wow, It doesn't sounds stupid at all, but It sounds pertectly fitting method in this problem. Thank you :)

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!