Page principale | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe

C:/Projects/ngn/include/shader.h

00001 /***************************************************************************
00002  *            shader.h
00003  *
00004  *  Sun Sep 12 22:19:14 2004
00005  *  Copyright  2004  thierry schartz
00006  *  thierry.schartz@bluebottle.com
00007  ****************************************************************************/
00008 
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024 
00025 #ifndef SHADER_H
00026 #define SHADER_H
00027 
00028 #ifdef WIN32
00029 #include <windows.h>
00030 #endif
00031 
00032 
00033 
00034 #include "GLee.h"
00035 
00036 namespace ngn {
00037         namespace gl {
00038 
00039 
00040 
00041                         /* base OpenGL shading language wrapper class */
00042                         class Shader
00043                         {
00044                         public:
00045                                 Shader();
00046                                 Shader( const Shader& other );
00047                                 virtual ~Shader();
00048                                 
00049                                 bool load( const char* shader_file );
00050                                 
00051                                 GLubyte* getSource();
00052                                 GLhandleARB getHandler();
00053                                 
00054                                 int compile();
00055 
00056                         protected:
00057                                 GLhandleARB m_handler;
00058 
00059                         private:
00060                                 GLubyte *m_src;
00061                                 const char* m_shader_file;
00062                         };
00063 
00064                         /* fragment shader class */
00065                         class FragmentShader : public Shader
00066                         {
00067                         public:
00068                                 FragmentShader();
00069                         };
00070 
00071                         /* vertex shader class */
00072                         class VertexShader : public Shader
00073                         {
00074                         public:
00075                                 VertexShader();
00076                         };
00077 
00078 
00079 
00080                         /* GLSL shader program class */
00081                         class ShaderProgram
00082                         {
00083                                 public:
00084                                         ShaderProgram();
00085                                         ShaderProgram( const ShaderProgram& other );
00086                                         virtual ~ShaderProgram();
00087                                         // create shader ( load, compile and link )            
00088                                         bool create( const char* fragment_shader_file, const char* vertex_shader_file  );
00089                                         // begin rendering with shader
00090                                         void begin();
00091                                         // post rendering with shader
00092                                         void end();
00093                                         /* send vars to GLSL program */
00094                                         // float
00095                                         bool sendUniform1f(char* varname, GLfloat v0); 
00096                                         bool sendUniform2f(char* varname, GLfloat v0, GLfloat v1); 
00097                                         bool sendUniform3f(char* varname, GLfloat v0, GLfloat v1, GLfloat v2); 
00098                                         bool sendUniform4f(char* varname, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); 
00099                                         // int
00100                                         bool sendUniform1i(char* varname, GLint v0);
00101                                         bool sendUniform2i(char* varname, GLint v0, GLint v1);
00102                                         bool sendUniform3i(char* varname, GLint v0, GLint v1, GLint v2);
00103                                         bool sendUniform4i(char* varname, GLint v0, GLint v1, GLint v2, GLint v3);
00104                                         // float array
00105                                         bool sendUniform1fv(char* varname, GLsizei count, GLfloat *value);
00106                                         bool sendUniform2fv(char* varname, GLsizei count, GLfloat *value);
00107                                         bool sendUniform3fv(char* varname, GLsizei count, GLfloat *value);
00108                                         bool sendUniform4fv(char* varname, GLsizei count, GLfloat *value);
00109                                         // int array
00110                                         bool sendUniform1iv(char* varname, GLsizei count, GLint *value);
00111                                         bool sendUniform2iv(char* varname, GLsizei count, GLint *value);
00112                                         bool sendUniform3iv(char* varname, GLsizei count, GLint *value);
00113                                         bool sendUniform4iv(char* varname, GLsizei count, GLint *value);
00114                                         // matrices 2x2,3x3 & 4x4
00115                                         bool sendUniformMatrix2fv(char* varname, GLsizei count, GLboolean transpose, GLfloat *value);
00116                                         bool sendUniformMatrix3fv(char* varname, GLsizei count, GLboolean transpose, GLfloat *value);
00117                                         bool sendUniformMatrix4fv(char* varname, GLsizei count, GLboolean transpose, GLfloat *value);
00118 
00119                                         // receive vars
00120                                         void getUniformfv(char* name, GLfloat* values);
00121                                         void getUniformiv(char* name, GLint* values); 
00122 
00123                                         // query shader state
00124                                         bool isReady();
00125                                                                                 
00126                 
00127                                 private:
00128                                         bool compile();
00129                                         bool link();
00130                                         GLint getUniformLocation( const GLcharARB *name );
00131 
00132                                         FragmentShader m_fragment;
00133                                         VertexShader m_vertex;
00134                                         GLhandleARB m_program;
00135 
00136                                         bool m_compiled;
00137                                         bool m_loaded;
00138                                         bool m_linked;
00139       
00140                         };
00141 
00142 
00143 
00144 
00145         }//gl
00146 }//ngn
00147 #endif /* SHADER_H */
00148 
00149     
00150             
00151 

Généré le Fri Nov 19 14:20:29 2004 pour NGN par  doxygen 1.3.9.1