MeVisLabToolboxReference
MeVisLab/Standard/Sources/Inventor/SoShader/Inventor/nodes/SoShaderObject.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 
00006 
00007 
00008 #ifndef  _SO_SHADER_OBJECT_
00009 #define  _SO_SHADER_OBJECT_
00010 
00011 #include "SoShaderSystem.h"
00012 #include "Inventor/misc/SoShaderTypes.h"
00013 #include <Inventor/nodes/SoSubNode.h>
00014 #include <Inventor/fields/SoSFBool.h>
00015 #include <Inventor/fields/SoSFEnum.h>
00016 #include <Inventor/fields/SoSFString.h>
00017 #include <Inventor/sensors/SoFieldSensor.h>
00018 #include <Inventor/SbList.h>
00019 
00020 class SoGLShaderObject;
00021 
00023 SoEXTENDER class INVENTOR_SHADER_API SoShaderObject : public SoNode
00024 {
00025    typedef SoNode inherited;
00026 
00027    SO_NODE_ABSTRACT_HEADER(SoShaderObject);
00028   
00029    public:
00030 
00032       enum SourceType {
00033          GLSL_PROGRAM,  
00034          FILENAME       
00035       };
00036       enum SnippetInsertionLocation {
00037          AT_BEGIN,
00038          AT_END
00039       };
00040 
00042       SoSFBool isActive;
00043       
00045       SoSFEnum sourceType;
00046       
00048       SoSFString sourceProgram;
00049 
00050    SoEXTENDER public:
00051 
00053       virtual void GLRender(SoGLRenderAction *action);
00054  
00055    SoINTERNAL public:
00056 
00058       static void initClass();
00059 
00061       SoGLShaderObject *getGLShaderObject() {
00062          return _glShaderObject;
00063       }
00064 
00066       virtual SoShader::ShaderType shaderType() const = 0;
00067 
00069       SourceType getSourceType() const {
00070          return _sourceType;
00071       }
00072 
00074       const SbString &getSourceProgram() const {
00075          return _sourceProgram;
00076       }
00077 
00079       void     scheduleRebuild();
00080 
00081       SbBool   containsMainFunction() const {
00082          return _containsMainFunction;
00083       }
00084    
00085       SbBool   isSnippet() const {
00086          return _isSnippet;
00087       }
00088       
00089       SbString getSnippetFunctionName() const {
00090          return _snippetFunctionName;
00091       }
00092       
00093       SnippetInsertionLocation getSnippetInsertionLocation() const {
00094          return _snippetInsertionLocation;
00095       }
00096       
00097       const SbList<SbString> &getSnippetUniformList() const {
00098          return _snippetUniformList;
00099       }
00100    
00101       SbBool   hasSourceModifications() const;
00102    
00103    protected:
00104 
00105       void checkType();
00106 
00107       void readSource();
00108 
00109       SoGLShaderObject *_glShaderObject;
00110 
00111       SourceType        _sourceType;
00112       SbString          _sourceProgram;
00113    
00115       SoShaderObject();  
00116 
00118       virtual ~SoShaderObject();
00119 
00120    private:
00121 
00122       static void isActiveSensorCB(void *data, SoSensor *sensor);
00123       static void sourceSensorCB(void *data, SoSensor *sensor);
00124 
00125       SoFieldSensor *_isActiveSensor;
00126       SoFieldSensor *_srcProgSensor;
00127 
00128       void parseSource(const SbString &srcCode);
00129    
00130       // TRUE, if shader contains main function
00131       SbBool _containsMainFunction;
00132       // TRUE, if shader contains activated and valid snippet function
00133       SbBool _isSnippet;
00134       SbString _snippetFunctionName;
00135       SnippetInsertionLocation _snippetInsertionLocation;
00136       SbList<SbString> _snippetUniformList;
00137 };
00138 
00139 #endif  // _SO_SHADER_OBJECT_