GLSLShader.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_HELPER_GL_GLSLSHADER_H
00028 #define SOFA_HELPER_GL_GLSLSHADER_H
00029 
00030 #include <sofa/helper/system/gl.h>
00031 #include <sofa/helper/system/glu.h>
00032 
00033 #include <string>
00034 #include <string.h>
00035 
00036 
00037 namespace sofa
00038 {
00039 
00040 namespace helper
00041 {
00042 
00043 namespace gl
00044 {
00045 
00046 #ifndef SOFA_HAVE_GLEW
00047 #error GL Shader support requires GLEW. Please define SOFA_HAVE_GLEW to use shaders.
00048 #endif
00049 
00050 class GLSLShader
00051 {
00052 public:
00053 
00054     GLSLShader();
00055     ~GLSLShader();
00056 
00058     void AddHeader(const std::string& header);
00059     
00060     void AddDefineMacro(const std::string &name, const std::string &value);
00061     
00063     std::string LoadTextFile(const std::string& strFile);
00064 
00066     static bool InitGLSL();
00067 
00069     void InitShaders(const std::string& strVertex, const std::string& stdGeometry, const std::string& strFragment);
00070     
00072     void InitShaders(const std::string& strVertex, const std::string& strFragment)
00073     {
00074     InitShaders(strVertex, std::string(""), strFragment);
00075     }
00076     
00078     GLint GetVariable(std::string strVariable);
00079 
00082     GLhandleARB GetProgram()    {   return m_hProgramObject; }
00083     GLhandleARB GetVertexS()    {   return m_hVertexShader; }
00084     GLhandleARB GetGeometryS()  {   return m_hGeometryShader; }
00085     GLhandleARB GetFragmentS()  {   return m_hFragmentShader; }
00086 
00089     void SetInt(GLint variable, int newValue);
00090     void SetFloat(GLint variable, float newValue);
00092     
00095     void SetInt2(GLint variable, int i1, int i2);
00096     void SetInt3(GLint variable, int i1, int i2, int i3);
00097     void SetInt4(GLint variable, int i1, int i2, int i3, int i4);
00098     void SetFloat2(GLint variable, float v0, float v1);
00099     void SetFloat3(GLint variable, float v0, float v1, float v2);
00100     void SetFloat4(GLint variable, float v0, float v1, float v2, float v3);
00102     
00105     void SetIntVector(GLint variable, GLsizei count, const GLint *value);
00106     void SetIntVector2(GLint variable, GLsizei count, const GLint *value);
00107     void SetIntVector3(GLint variable, GLsizei count, const GLint *value);
00108     void SetIntVector4(GLint variable, GLsizei count, const GLint *value);
00109 
00110     void SetFloatVector(GLint variable, GLsizei count, const float *value);
00111     void SetFloatVector2(GLint variable, GLsizei count, const float *value);
00112     void SetFloatVector3(GLint variable, GLsizei count, const float *value);
00113     void SetFloatVector4(GLint variable, GLsizei count, const float *value);
00115 
00118     void TurnOn();
00119     void TurnOff();
00121 
00123     void Release();
00124 
00125     GLint GetGeometryInputType() { return geometry_input_type; }
00126     void  SetGeometryInputType(GLint v) { geometry_input_type = v; }
00127 
00128     GLint GetGeometryOutputType() { return geometry_output_type; }
00129     void  SetGeometryOutputType(GLint v) { geometry_output_type = v; }
00130 
00131     GLint GetGeometryVerticesOut() { return geometry_vertices_out; }
00132     void  SetGeometryVerticesOut(GLint v) { geometry_vertices_out = v; }
00133     
00134 protected:
00135 
00136     bool CompileShader(GLint target, const std::string& source, GLhandleARB& shader);
00137 
00138     std::string header;
00139 
00141     GLhandleARB m_hVertexShader;
00142 
00144     GLhandleARB m_hGeometryShader;
00145 
00147     GLhandleARB m_hFragmentShader;
00148 
00150     GLhandleARB m_hProgramObject;
00151 
00152     GLint geometry_input_type;
00153     GLint geometry_output_type;
00154     GLint geometry_vertices_out;
00155 };
00156 
00157 } // namespace gl
00158 
00159 } // namespace helper
00160 
00161 } // namespace sofa
00162 
00163 #endif

Generated on Sun Nov 23 02:29:30 2008 for Sofa by  doxygen 1.5.7.1