GLSLShader.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: 8521 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-10 15:57:35 +0100 (Mi, 10. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 /*******************************************************************************
00044  * GLSLShader.h
00045  *
00046  * Utility classes for GLSL shaders.
00047  *
00048  * (C)2007
00049  * Lehrstuhl I8 RWTH-Aachen, http://www-i8.informatik.rwth-aachen.de
00050  * Author: Markus Tavenrath <speedygoo@speedygoo.de>
00051  *
00052  ******************************************************************************/
00053 
00054 #ifndef GLSLSHADER_H
00055 #define GLSLSHADER_H
00056 
00057 //==============================================================================
00058 
00059 #include "../Config/ACGDefines.hh"
00060 #include <ACG/Math/VectorT.hh>
00061 
00062 #include <list>
00063 #include <string>
00064 
00065 //==============================================================================
00066 
00070 namespace GLSL {
00071 
00072 #define GLSL_MAX_LOGSIZE 16384
00073 
00074     typedef std::list<std::string> StringList;
00075 
00078     class ACGDLLEXPORT Shader
00079     {
00080     public:
00081         Shader(GLenum shaderType);
00082         virtual ~Shader();
00083         void setSource(StringList source);
00084 
00085         // FIXME implement StringList getSource();
00086         bool compile();
00087 
00088     protected:
00089         GLuint m_shaderId;
00090 
00091         friend class Program;
00092     };
00093 
00094     typedef Shader* PtrShader;
00095     typedef const Shader* PtrConstShader;
00096 
00097     //--------------------------------------------------------------------------
00098 
00101     class ACGDLLEXPORT VertexShader
00102         : public Shader
00103     {
00104     public:
00105         VertexShader();
00106         virtual ~VertexShader();
00107     };
00108 
00109     typedef VertexShader* PtrVertexShader;
00110     typedef const VertexShader* PtrVertexConstShader;
00111 
00112     //--------------------------------------------------------------------------
00113 
00116     class ACGDLLEXPORT FragmentShader : public Shader {
00117     public:
00118         FragmentShader();
00119         virtual ~FragmentShader();
00120     };
00121 
00122     typedef FragmentShader* PtrFragmentShader;
00123     typedef const FragmentShader* PtrConstFragmentShader;
00124 
00125     //--------------------------------------------------------------------------
00126 
00131     class ACGDLLEXPORT Program
00132     {
00133     public:
00134         Program();
00135         virtual ~Program();
00136 
00137         void attach(PtrConstShader shader);
00138         void detach(PtrConstShader shader);
00139         void link();
00140 
00141         void setUniform(const char *name, GLint value);
00142         void setUniform(const char *name, GLfloat value);
00143         void setUniform(const char *name, const ACG::Vec3f &value);
00144 
00145         void setUniform(const char *name, GLint *value, int count);
00146 
00147         // set element of array
00148         void setUniform(const char *name, int index, bool value);
00149         void setUniform(const char *name, int index, int value);
00150         void setUniform(const char *name, int index, float value);
00151 
00152         void bindAttributeLocation(unsigned int index, const char *name);
00153         int getAttributeLocation(const char *name);
00154         int getUniformLocation(const char *name);
00155 
00156         void use();
00157 
00158         void disable();
00159 
00160         bool isActive();
00161 
00162     private:
00163 
00164         std::list<PtrConstShader> m_linkedShaders;
00165         GLint m_programId;
00166     };
00167 
00168     typedef Program* PtrProgram;
00169     typedef const Program* PtrConstProgram;
00170 
00171     //--------------------------------------------------------------------------
00172 
00173     GLSL::StringList ACGDLLEXPORT loadShader(const char *filename);
00174 
00175     GLSL::PtrVertexShader ACGDLLEXPORT loadVertexShader(const char *name);
00176     GLSL::PtrFragmentShader ACGDLLEXPORT loadFragmentShader(const char *name);
00177 
00178 }
00179 
00180 
00181 //==============================================================================
00182 
00183 // Local Variables:
00184 // mode: C++
00185 // c-basic-offset: 4
00186 // indent-tabs-mode: nil
00187 // End:
00188 
00189 //==============================================================================
00190 
00191 // GLSLSHADER_H
00192 #endif

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