Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm starting with the programmable pipeline and the shaders in C++ for OpenGL 3.0+, i would love to be able to change some settings on the fly, for example replacing a function with another function, supposing that i have a shader with an operation like

var = A + B

my goal is replacing + with any other operation on the fly with my C++ program, maybe with a GUI, but in general terms with C++, the problem is that until now i'm able to run a shader only after compiling it, so i have something like a static approach.

The same goal applies to the values of the vars that i would also like to change through C++.

It's possible with a programmable pipeline? I'm not interested in performance, just if is possible for the C++ to dynamically communicate and exchange data with the OpenGL pipeline.

share|improve this question
up vote 3 down vote accepted

I'm not sure exactly what you mean.

You can certainly create a new shader string, compile it into a new shader object, and link it into a new program object. But you can't modify an existing shader's source code.

If you just want to change what gets called when, you can use an if statement in your shader based on uniform variables. Though this can get out of hand if you do it a lot.

GLSL 4.00 adds the ability to define multiple subroutines in a shader and dynamically (meaning, post-linking) pick which one to execute. But that's about it.

share|improve this answer
I would like to write my small utility with a GUI a find out what changes when changing a particular operation in a shader, like adding vs subtracting, or change a particular value with the help of a slider for example, everything in real time and dynamically. A very basic shader designer using widget from a GUI. – user827992 Aug 20 '12 at 3:55
@user827992: It doesn't matter whether the changes come from a GUI or what have you. If you want to change your shader, you must compile a new shader. You can change uniform variables with the API, but the shader itself is immutable. – Nicol Bolas Aug 20 '12 at 3:58
to what API are you referring to? – user827992 Aug 20 '12 at 4:07
@user827992: OpenGL. That's what we're talking about, isn't it? – Nicol Bolas Aug 20 '12 at 4:13
yes, but i was thinking about a specific subset only for changing variables. – user827992 Aug 20 '12 at 4:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.