OglShader.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 :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 //
00026 // C++ Interface: Shader
00027 //
00028 // Description:
00029 //
00030 //
00031 // Author: The SOFA team </www.sofa-framework.org>, (C) 2007
00032 //
00033 // Copyright: See COPYING file that comes with this distribution
00034 //
00035 //
00036 #ifndef SOFA_COMPONENT_OGLSHADER
00037 #define SOFA_COMPONENT_OGLSHADER
00038 
00039 #include <sofa/core/VisualModel.h>
00040 #include <sofa/core/objectmodel/BaseObject.h>
00041 #include <sofa/core/Shader.h>
00042 #include <sofa/defaulttype/Vec3Types.h>
00043 #include <sofa/helper/gl/template.h>
00044 #include <sofa/helper/gl/GLSLShader.h>
00045 
00046 namespace sofa
00047 {
00048 
00049 namespace component
00050 {
00051 
00052 namespace visualmodel
00053 {
00054 
00065 class OglShader : public core::Shader, public core::VisualModel {
00066 protected:
00068     Data<bool> turnOn;
00069 
00071     Data<std::string> vertFilename;
00073     Data<std::string> fragFilename;
00075     Data<std::string> geoFilename;
00076 
00078     Data<int> geometryInputType;
00080     Data<int> geometryOutputType;
00082     Data<int> geometryVerticesOut;
00083 
00085     sofa::helper::gl::GLSLShader m_shader;
00086 
00087     bool hasGeometryShader;
00088 
00089 public:
00090     OglShader();
00091     virtual ~OglShader();
00092 
00093     void initVisual();
00094     void init();
00095     void reinit();
00096     void drawVisual();
00097     void updateVisual();
00098 
00099     void start();
00100     void stop();
00101 
00102     void addDefineMacro(const std::string &name, const std::string &value);
00103 
00104     void setTexture(const char* name, unsigned short unit);
00105 
00106     void setInt(const char* name, int i);
00107     void setInt2(const char* name, int i1, int i2);
00108     void setInt3(const char* name, int i1, int i2, int i3);
00109     void setInt4(const char* name, int i1, int i2, int i3, int i4);
00110 
00111     void setFloat(const char* name, float f1);
00112     void setFloat2(const char* name, float f1, float f2);
00113     void setFloat3(const char* name, float f1, float f2, float f3);
00114     void setFloat4(const char* name, float f1, float f2, float f3, float f4);
00115 
00116     void setIntVector(const char* name, int count, const GLint* i);
00117     void setIntVector2(const char* name, int count, const GLint* i);
00118     void setIntVector3(const char* name, int count, const GLint* i);
00119     void setIntVector4(const char* name, int count, const GLint* i);
00120 
00121     void setFloatVector(const char* name, int count, const float* f);
00122     void setFloatVector2(const char* name, int count, const float* f);
00123     void setFloatVector3(const char* name, int count, const float* f);
00124     void setFloatVector4(const char* name, int count, const float* f);
00125 
00126     GLint getGeometryInputType() ;
00127     void  setGeometryInputType(GLint v) ;
00128 
00129     GLint getGeometryOutputType() ;
00130     void  setGeometryOutputType(GLint v) ;
00131 
00132     GLint getGeometryVerticesOut() ;
00133     void  setGeometryVerticesOut(GLint v);
00134 };
00135 
00144 class OglShaderElement : public core::ShaderElement {
00145 protected:
00147     Data<std::string> id;
00149     OglShader* shader;
00150 public:
00151     OglShaderElement();
00152     virtual ~OglShaderElement() { };
00153     virtual void init();
00154 
00155     //virtual void setInShader(OglShader& s) = 0;
00156 };
00157 
00158 }//namespace visualmodel
00159 
00160 } //namespace component
00161 
00162 } //namespace sofa
00163 
00164 #endif //SOFA_COMPONENT_OGLSHADER

Generated on Sun Nov 23 03:48:33 2008 for Sofa by  doxygen 1.5.7.1