00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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