tgShader.h
Go to the documentation of this file.
00001 /* Shader
00002  *
00003  * Copyright (C) 2005, Maurizio Monge <maurizio.monge@gmail.com>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef __SHADER_H__
00021 #define __SHADER_H__
00022 
00023 
00024 
00025 #include <blort/TomGine/headers.h>
00026 #include <blort/TomGine/tgMathlib.h>
00027 
00028 namespace TomGine{
00029 
00033 class tgShader{
00034 private:
00035     GLhandleARB fragment;
00036     GLhandleARB vertex;
00037     GLhandleARB program;
00038 public:
00039     tgShader(   const char *vertex_file = NULL,
00040                 const char *fragment_file = NULL,
00041                 const char *header = NULL);
00042     ~tgShader();
00043 
00044     void bind();
00045     void unbind();
00046     void dumpVars();
00047     void printInfoLog(GLhandleARB obj, const char *msg, ...);
00048     bool getStatus();
00049 
00050     GLuint getAttribLoc(const char*);
00051     GLint  getUniformLoc(const char*);
00052     void setUniform(const char*,int);
00053     void setUniform(const char*,unsigned);
00054     void setUniform(const char*,int,const int*);
00055     void setUniform(const char*,float);
00056     void setUniform(const char*,int,const float*);
00057     void setUniform(const char*,vec2);
00058     void setUniform(const char* var,int n,vec2* f);
00059     void setUniform(const char*,vec3);
00060     void setUniform(const char* var,int n,vec3* f);
00061     void setUniform(const char*,vec4);
00062     void setUniform(const char* var,int n,vec4* f);
00063     void setUniform(const char*,mat3,bool transpose=false);
00064     void setUniform(const char* var,int n,mat3* f,bool transpose);
00065     void setUniform(const char*,mat4,bool transpose=false);
00066     void setUniform(const char* var,int n,mat4* f,bool transpose);
00067 
00068 
00069 };
00070 
00071 
00072 /* allocate (and free) aligned memory, align must be power of 2 */
00073 void *malloc_align(size_t size, int align);
00074 void free_align(void *ptr);
00075 
00076 /* read entierely a file, returning a 0 terminated string */
00077 char *read_text_file(const char* file);
00078 
00079 /* offset of a membet in a structure */
00080 #undef OFFSETOF
00081 #define OFFSETOF(TYPE, MEMBER) (((size_t)&((TYPE *)1)->MEMBER) - 1)
00082 
00083 /* some templates */
00084 template<typename T>
00085 T Max(T a,T b)
00086 {
00087     return a>b?a:b;
00088 }
00089 
00090 template<typename T>
00091 T Min(T a,T b)
00092 {
00093     return a<b?a:b;
00094 }
00095 
00096 template<typename T>
00097 T Abs(T a)
00098 {
00099     return a>0?a:-a;
00100 }
00101 
00102 template<typename T>
00103 T Square(T a)
00104 {
00105     return a*a;
00106 }
00107 
00108 template<typename T>
00109 T Sign(T a)
00110 {
00111     return a==0?0:a>0?1:-1;
00112 }
00113 
00114 } //namespace TomGine
00115 
00116 #endif //__SHADER_H__


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12