ShaderNode.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8548 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-12 14:40:13 +0100 (Fr, 12. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS ShaderNode
00049 //
00050 //=============================================================================
00051 
00052 #ifndef ACG_SHADER_NODE_HH
00053 #define ACG_SHADER_NODE_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 #include "BaseNode.hh"
00059 #include <string>
00060 
00061 #include "../ShaderUtils/GLSLShader.hh"
00062 #include <ACG/Scenegraph/DrawModes.hh>
00063 
00064 //== NAMESPACES ===============================================================
00065 
00066 namespace ACG {
00067 namespace SceneGraph {
00068 
00069 
00070 //== CLASS DEFINITION =========================================================
00071 
00072 
00080 class ACGDLLEXPORT ShaderNode : public BaseNode
00081 {
00082 public:
00083 
00085   ShaderNode( BaseNode*           _parent = 0,
00086               const std::string&  _name = "<ShaderNode>" );
00087 
00089   virtual ~ShaderNode();
00090 
00091 
00092   ACG_CLASSNAME(ShaderNode);
00093 
00095   void enter(GLState& /*_state*/, DrawModes::DrawMode _drawmode);
00097   void leave(GLState& /*_state*/, DrawModes::DrawMode _drawmode);
00098 
00100   void enterPick(GLState& /*_state*/, PickTarget _target, DrawModes::DrawMode _drawmode);
00102   void leavePick(GLState& /*_state*/, PickTarget _target, DrawModes::DrawMode _drawmode);
00103 
00104 
00106   void setShaderDir( std::string _shaderDir);
00107 
00108   std::string shaderDir() { return shaderDir_; };
00109 
00110   std::string vertexShaderName(DrawModes::DrawMode _drawmode, bool _pick = false);
00111 
00112   std::string fragmentShaderName(DrawModes::DrawMode _drawmode, bool _pick = false);
00113 
00114 
00120   void setShader( DrawModes::DrawMode _drawmode ,
00121                   std::string _vertexShader,
00122                   std::string _fragmentShader,
00123                   std::string _pickVertexShader = "",
00124                   std::string _pickFragmentShader = "");
00125 
00127   GLSL::PtrProgram getShader( DrawModes::DrawMode _drawmode, bool _pick = false);
00128 
00130   bool hasShader( DrawModes::DrawMode _drawmode, bool _pick = false);
00131 
00133   DrawModes::DrawMode availableDrawModes() const;
00134 
00135 private :
00136   // Path to the shaders ( if set ). If empty shaders will not be used.
00137   std::string shaderDir_;
00138 
00139   class ShaderInfo {
00140 
00141     public :
00142       ShaderInfo() :
00143         vertexShader(0),
00144         vertexShaderFile(""),
00145         fragmentShader(0),
00146         fragmentShaderFile(""),
00147         program(0),
00148         initialized(false)
00149       {
00150       };
00151 
00152     GLSL::PtrVertexShader   vertexShader;
00153     std::string             vertexShaderFile;
00154 
00155     GLSL::PtrFragmentShader fragmentShader;
00156     std::string             fragmentShaderFile;
00157 
00158     GLSL::PtrProgram        program;
00159 
00160     bool                    initialized;
00161   };
00162 
00163   std::map< unsigned int, ShaderInfo> shaders;
00164   std::map< unsigned int, ShaderInfo> pickShaders;
00165 };
00166 
00167 
00168 //=============================================================================
00169 } // namespace SceneGraph
00170 } // namespace ACG
00171 //=============================================================================
00172 #endif // ACG_SHADER_NODE_HH defined
00173 //=============================================================================
00174 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .