GLSLShader.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }
00158
00159 }
00160
00161 }
00162
00163 #endif