KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
UPDATE: Because I needed something right away, I've created a simple shader wrapper that does the sort of thing I need. You can find it here: ShaderManager on GitHub . Note that it's designed for Objective-C / iOS, so may not be useful to everyone. If you have any suggestions for design improvements, please let me know! Original Problem: I'm new to using GLSL shaders. I'm familiar enough with the GLSL language and the OpenGL interface, but I'm having trouble designing a simple API through which to use shaders. OpenGL's C interface to interact with shaders seems cumbersome. I can't seem to find any tutorials on the net that cover the API design of such things. My question is this: does any one have a good, simple, API design or pattern to wrap the OpenGL shader program API? Take the following simple example. Say I have one vertex shader that just emulates fixed functionality, and two fragment shaders - one for drawing smooth rectangles and one for drawing smooth circles. I have the following files: Shader.vsh : Simple vertex shader, with the following inputs/outputs: -- Uniforms: mat4 Model, mat4 View, mat4 Projection -- Attributes: vec4 Vertex, vec2 TexCoord, vec4 Color -- Varying: vec4 vColor, vec2 vTexCoord Square.fsh : Fragment shader for drawing squares based on tex coord / color Circle.fsh : Fragment shader for drawing circles based on tex coord / color Basic Linking Now what is the standard way to use these? Do I link the above shaders into two OpenGL shader programs? That is: Shader.vsh + Square.fsh = SquareProgram Shader.vsh + Circle.fsh = CircleProgram Or do I instead create one big program where the fragment shaders check some conditional uniform variables and call out to a shader function to generate their result. E.g: <c
Tags (comma-separated)
Save Edits
Cancel