[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/libs/kgllib/core/kgllib
From:       Rivo Laks <rivolaks () hot ! ee>
Date:       2008-08-31 11:04:10
Message-ID: 1220180650.984290.7040.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 855239 by rivol:

Add an example on creating a Program with more than 2 shaders

 M  +32 -1     program.h  


--- trunk/playground/libs/kgllib/core/kgllib/program.h #855238:855239
@@ -46,12 +46,43 @@
  *  vertex- and fragment shader to the Program constructor. This automatically
  *  creates temporary Shader objects and then combines them into a Program:
  * @code
- * Program* prog = new Program(vertexShaderFile, fragmentShaderFile);
+ * Program* prog = new Program("myshader.vert", "myshader.frag");
  * if (!prog->isValid()) {
  *     // Error: program failed to load
  * }
  * @endcode
  *
+ * It is also possible to add more than one fragment or vertex shader (e.g. you
+ *  can have some common functions in one shader and the main() function in
+ *  other) or specify only vertex or only fragment shader. In this case you
+ *  will have to first create the Shader objects yourself and then add them to
+ *  a program:
+ * @code
+ * // Create Shader objects
+ * VertexShader vertexShader("myshader.vert");
+ * FragmentShader fragmentShader("myshader.frag");
+ * // common.frag could contain common functions shared by different shaders
+ * FragmentShader commonShader("common.frag");
+ * // Make sure all shaders were successfully loaded
+ * if (!vertexShader.isValid() || !fragmentShader.isValid() || !commonShader.isValid()) {
+ *     // handle the error here
+ *     return;
+ * }
+ *
+ * // Create Program object
+ * Program* prog = new Program();
+ * // Add shader objects to program
+ * prog->addShader(&vertexShader);
+ * prog->addShader(&fragmentShader);
+ * prog->addShader(&commonShader);
+ * // Finally link them together
+ * prog->link();
+ * // And make sure everything succeeded
+ * if (!prog->isValid()) {
+ *     // handle the error
+ * }
+ * @endcode
+ *
  * @section binding Binding
  * To use the program, you need to first bind() it, then render your geometry
  *  and finally unbind() it. Note that it's more convenient to use the Mesh
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic