X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramdata.cpp;h=cd12c2ca47fbff99cdbfe2578d30ebbd0468d997;hp=50cefd4f9f9e5bed427c7610e56a48df7b339553;hb=HEAD;hpb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8 diff --git a/source/programdata.cpp b/source/programdata.cpp deleted file mode 100644 index 50cefd4f..00000000 --- a/source/programdata.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#include "color.h" -#include "extension.h" -#include "matrix.h" -#include "program.h" -#include "programdata.h" -#include "uniform.h" -#include "vector.h" - -using namespace std; - -namespace Msp { -namespace GL { - -ProgramData::ProgramData(const Program &p): - program(p) -{ - static RequireExtension _ext("GL_ARB_shader_objects"); -} - -ProgramData::ProgramData(const ProgramData &other): - program(other.program), - data(other.data) -{ - for(map::iterator i=data.begin(); i!=data.end(); ++i) - i->second = i->second->clone(); -} - -ProgramData::~ProgramData() -{ - for(map::iterator i=data.begin(); i!=data.end(); ++i) - delete i->second; -} - -void ProgramData::uniform(int index, Uniform *uni) -{ - map::iterator i = data.find(index); - if(i!=data.end()) - { - delete i->second; - i->second = uni; - } - else - data[index] = uni; -} - -void ProgramData::uniform(int index, int v) -{ - if(index>=0) - uniform(index, new Uniform1i(v)); -} - -void ProgramData::uniform(int index, float v) -{ - if(index>=0) - uniform(index, new Uniform1f(v)); -} - -void ProgramData::uniform(int index, float v0, float v1) -{ - if(index>=0) - uniform(index, new Uniform2f(v0, v1)); -} - -void ProgramData::uniform2(int index, const float *v) -{ - uniform(index, v[0], v[1]); -} - -void ProgramData::uniform(int index, float v0, float v1, float v2) -{ - if(index>=0) - uniform(index, new Uniform3f(v0, v1, v2)); -} - -void ProgramData::uniform(int index, const Vector3 &v) -{ - uniform(index, v.x, v.y, v.z); -} - -void ProgramData::uniform3(int index, const float *v) -{ - uniform(index, v[0], v[1], v[2]); -} - -void ProgramData::uniform(int index, float v0, float v1, float v2, float v3) -{ - if(index>=0) - uniform(index, new Uniform4f(v0, v1, v2, v3)); -} - -void ProgramData::uniform(int index, const Vector4 &v) -{ - uniform(index, v.x, v.y, v.z, v.w); -} - -void ProgramData::uniform(int index, const Color &c) -{ - uniform(index, c.r, c.g, c.b, c.a); -} - -void ProgramData::uniform4(int index, const float *v) -{ - uniform(index, v[0], v[1], v[2], v[3]); -} - -void ProgramData::uniform_matrix4(int index, const float *v) -{ - if(index>=0) - uniform(index, new UniformMatrix4x4f(v)); -} - -void ProgramData::uniform_matrix4(int index, const Matrix &m) -{ - if(index>=0) - { - float v[16]; - copy(m.data(), m.data()+16, v); - uniform_matrix4(index, v); - } -} - -void ProgramData::uniform(const string &name, int v) -{ - uniform(program.get_uniform_location(name), v); -} - -void ProgramData::uniform(const string &name, float v) -{ - uniform(program.get_uniform_location(name), v); -} - -void ProgramData::uniform(const string &name, float v0, float v1) -{ - uniform(program.get_uniform_location(name), v0, v1); -} - -void ProgramData::uniform2(const string &name, const float *v) -{ - uniform2(program.get_uniform_location(name), v); -} - -void ProgramData::uniform(const string &name, float v0, float v1, float v2) -{ - uniform(program.get_uniform_location(name), v0, v1, v2); -} - -void ProgramData::uniform(const string &name, const Vector3 &v) -{ - uniform(program.get_uniform_location(name), v); -} - -void ProgramData::uniform3(const string &name, const float *v) -{ - uniform3(program.get_uniform_location(name), v); -} - -void ProgramData::uniform(const string &name, float v0, float v1, float v2, float v3) -{ - uniform(program.get_uniform_location(name), v0, v1, v2, v3); -} - -void ProgramData::uniform(const string &name, const Vector4 &v) -{ - uniform(program.get_uniform_location(name), v); -} - -void ProgramData::uniform4(const string &name, const float *v) -{ - uniform4(program.get_uniform_location(name), v); -} - -void ProgramData::uniform_matrix4(const string &name, const float *v) -{ - uniform_matrix4(program.get_uniform_location(name), v); -} - -void ProgramData::uniform_matrix4(const string &name, const Matrix &m) -{ - uniform_matrix4(program.get_uniform_location(name), m); -} - -void ProgramData::apply() const -{ - for(map::const_iterator i=data.begin(); i!=data.end(); ++i) - i->second->apply(i->first); -} - - -ProgramData::Loader::Loader(ProgramData &pd): - DataFile::ObjectLoader(pd) -{ - add("uniform1i", &Loader::uniform1i); - add("uniform1f", &Loader::uniform1f); - add("uniform2f", &Loader::uniform2f); - add("uniform3f", &Loader::uniform3f); - add("uniform4f", &Loader::uniform4f); -} - -void ProgramData::Loader::uniform1i(const string &n, int v) -{ - obj.uniform(n, v); -} - -void ProgramData::Loader::uniform1f(const string &n, float v) -{ - obj.uniform(n, v); -} - -void ProgramData::Loader::uniform2f(const string &n, float v0, float v1) -{ - obj.uniform(n, v0, v1); -} - -void ProgramData::Loader::uniform3f(const string &n, float v0, float v1, float v2) -{ - obj.uniform(n, v0, v1, v2); -} - -void ProgramData::Loader::uniform4f(const string &n, float v0, float v1, float v2, float v3) -{ - obj.uniform(n, v0, v1, v2, v3); -} - -} // namespace GL -} // namespace Msp