MeVisLabToolboxReference
|
00001 // **InsertLicense** code 00002 00006 00007 00008 #ifndef _SO_GL_SHADER_PROGRAM_ 00009 #define _SO_GL_SHADER_PROGRAM_ 00010 00011 #include "SoShaderSystem.h" 00012 #include "Inventor/misc/SoGLShader.h" 00013 #include "Inventor/misc/SoUniformParameterBase.h" 00014 #include <Inventor/SbString.h> 00015 #ifdef MEVISLAB 00016 #include <mlGLResources.h> 00017 #else 00018 #include <Inventor/system/SbOpenGL.h> 00019 #endif 00020 #include <list> 00021 #include <map> 00022 #include <string> 00023 00024 class SoGLShaderObject; 00025 00027 class INVENTOR_SHADER_API SoGLShaderProgram : public SoGLShader, public SoUniformParameterBase 00028 { 00029 typedef SoGLShader inherited; 00030 00031 protected: 00032 00033 #ifdef MEVISLAB 00034 ml::GLSLProgram _programRes; 00035 #define PROGRAMHANDLE (_programRes.getHandle()) 00036 #endif 00037 00038 GLint _geometryInputType; 00039 GLint _geometryOutputType; 00040 GLint _geometryVerticesOut; 00041 00042 public: 00043 00045 SoGLShaderProgram(); 00046 00048 virtual ~SoGLShaderProgram(); 00049 00051 virtual void reset(); 00052 00053 void addShaderObject(SoGLShaderObject *shaderObject); 00054 void removeShaderObject(SoGLShaderObject *shaderObject); 00055 void removeAllShaderObjects(); 00056 00057 void enable(int context); 00058 void disable(); 00059 00060 void scheduleLinking(); 00061 00062 void setGeometryInputType(GLint type) { 00063 if (_geometryInputType != type) { _geometryInputType = type; scheduleLinking(); } 00064 } 00065 void setGeometryOutputType(GLint type) { 00066 if (_geometryOutputType != type) { _geometryOutputType = type; scheduleLinking(); } 00067 } 00068 void setGeometryVerticesOut(GLint number) { 00069 if (_geometryVerticesOut != number) { _geometryVerticesOut = number; scheduleLinking(); } 00070 } 00071 00072 virtual SbBool isActiveUniform(const SbString &name); 00073 00075 virtual void clearAssignedTextureUnits() { _assignedTextureUnits = 0; } 00076 00078 virtual int addTextureSampler(const SbString &name); 00079 00080 virtual void set1f(const SbString &name, const float value); 00081 virtual void set2f(const SbString &name, const float *value); 00082 virtual void set3f(const SbString &name, const float *value); 00083 virtual void set4f(const SbString &name, const float *value); 00084 virtual void set2f(const SbString &name, const float value0, const float value1); 00085 virtual void set3f(const SbString &name, const float value0, const float value1, const float value2); 00086 virtual void set4f(const SbString &name, const float value0, const float value1, const float value2, const float value3); 00087 00088 virtual void set1fv(const SbString &name, const int num, const float *value); 00089 virtual void set2fv(const SbString &name, const int num, const float *value); 00090 virtual void set3fv(const SbString &name, const int num, const float *value); 00091 virtual void set4fv(const SbString &name, const int num, const float *value); 00092 00093 virtual void set1i(const SbString &name, const int32_t value); 00094 virtual void set2i(const SbString &name, const int32_t *value); 00095 virtual void set2i(const SbString &name, const SbVec2s &value); 00096 virtual void set3i(const SbString &name, const int32_t *value); 00097 virtual void set3i(const SbString &name, const SbVec3s &value); 00098 virtual void set4i(const SbString &name, const int32_t *value); 00099 00100 virtual void setMatrix3f(const SbString &name, const float *value, SbBool transpose = FALSE); 00101 virtual void setMatrix4f(const SbString &name, const float *value, SbBool transpose = FALSE); 00102 00104 SbBool areAllContextsStillValid(int context); 00105 00106 void setName(const SbString& name) { _name = name; } 00107 00108 const SbString& getName() const { return _name; } 00109 00110 SoINTERNAL public: 00111 00112 enum LinkageResult { 00113 LR_FAILURE = 0, 00114 LR_SUCCESS = 1, 00115 LR_SKIPPED = 2 00116 }; 00117 00118 #ifdef MEVISLAB 00119 ml::GLSLProgram &getProgramResource() { 00120 return _programRes; 00121 } 00122 #endif 00123 00124 GLuint getProgramHandle() const { 00125 return PROGRAMHANDLE; 00126 } 00127 00128 SbBool isExecutable() const { 00129 return _isExecutable; 00130 } 00131 00132 SbBool shouldLink() const { 00133 return _shouldLink; 00134 } 00135 00136 LinkageResult link(int context); 00137 00138 protected: 00139 00140 std::list<SoGLShaderObject *> _shaderObjects; 00141 SbBool _shouldLink; 00142 SbBool _isExecutable; 00143 00144 SbString _name; 00145 00146 int _assignedTextureUnits; 00147 00149 struct UniformInfo { 00150 GLint location; 00151 GLenum type; 00152 GLint size; 00153 UniformInfo() : location(-1), type(GL_INT), size(0) {} 00154 UniformInfo(GLint _location, GLenum _type, GLint _size) : location(_location), type(_type), size(_size) {} 00155 }; 00156 std::map<std::string, UniformInfo> _uniformInfo; 00157 00158 GLint getUniform(const SbString &name, GLenum type, int *num = NULL); 00159 }; 00160 00161 #endif // _SO_GL_SHADER_PROGRAM_