GLSLShader.h

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #ifdef GLSL
00018 #include "GL/glew.h"
00019 #endif
00020 #ifndef __APPLE__
00021 #include "GL/gl.h"
00022 #include "GL/glu.h"
00023 #include "GL/glut.h"
00024 #else
00025 #include "OpenGL/gl.h"
00026 #include "OpenGL/glu.h"
00027 #include "GLUT/glut.h"
00028 #endif
00029 #include <string>
00030 #include <vector>
00031 #include "dada.h"
00032 
00033 #ifndef FLUXUS_GLSL_SHADER
00034 #define FLUXUS_GLSL_SHADER
00035 
00036 using namespace std;
00037 
00038 namespace Fluxus
00039 {
00040 
00044 class GLSLShaderPair
00045 {
00046 public:
00048     GLSLShaderPair(const string &vertexfilename, const string &fragmentfilename);
00049     ~GLSLShaderPair();
00050     
00051     unsigned int GetVertexShader() const { return m_VertexShader; }
00052     unsigned int GetFragmentShader() const { return m_FragmentShader; }
00053     
00054 private:
00056     bool Load(const string &vertexfilename, const string &fragmentfilename);
00057     unsigned int LoadShader(string filename, unsigned int type);
00058 
00059     unsigned int m_VertexShader;
00060     unsigned int m_FragmentShader;
00061 };
00062 
00065 class GLSLShader
00066 {
00067 public:
00069     GLSLShader() : m_RefCount(1), m_IsValid(false) {}
00070     GLSLShader(const GLSLShaderPair &pair);
00071     ~GLSLShader();
00072 
00073     // Temp fix, maybe
00074     void IncRef() { m_RefCount++; }
00075     bool DecRef() { m_RefCount--; return (m_RefCount==0); }
00076 
00080     static void Init();
00081     void Apply();
00082     static void Unapply();
00083     bool IsValid() { return m_IsValid; }
00085     
00089     void SetInt(const string &name, int s);
00090     void SetFloat(const string &name, float s);
00091     void SetVector(const string &name, dVector s);
00092     void SetColour(const string &name, dColour s);
00094     
00098     void SetFloatArray(const string &name, const vector<float> &s);
00099     void SetVectorArray(const string &name, const vector<dVector> &s);
00100     void SetColourArray(const string &name, const vector<dColour> &s);
00102     
00103     static bool m_Enabled;
00104     
00105 private:
00106     unsigned int m_Program;
00107     unsigned int m_RefCount;
00108     bool m_IsValid;
00109 };
00110 
00111 }
00112 
00113 #endif

Generated on Wed Sep 17 21:16:30 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1