X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frenderpass.cpp;h=be5bb170280844d88c8b3e8f46fd22cb72e902de;hp=5b5f72984b3bbfdbfe293d594ba68b3c17b4bd43;hb=HEAD;hpb=d51a234320449909eb34c802faa1f0c516ef70a0 diff --git a/source/renderpass.cpp b/source/renderpass.cpp deleted file mode 100644 index 5b5f7298..00000000 --- a/source/renderpass.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include -#include -#include -#include "material.h" -#include "renderpass.h" -#include "program.h" -#include "programdata.h" -#include "texenv.h" -#include "texture.h" -#include "texture2d.h" -#include "texturing.h" - -using namespace std; - -namespace Msp { -namespace GL { - -RenderPass::RenderPass(): - shprog(0), - shdata(0), - material(0), - texturing(0) -{ } - -RenderPass::RenderPass(const RenderPass &other): - Bindable(other), - shprog(other.shprog), - shdata(other.shdata ? new ProgramData(*other.shdata) : 0), - material(other.material), - texturing(other.texturing ? new Texturing(*other.texturing) : 0) -{ } - -RenderPass::~RenderPass() -{ - delete shdata; - delete texturing; -} - -void RenderPass::set_material(const Material *mat) -{ - material = mat; - material.keep(); -} - -void RenderPass::set_texture(unsigned index, const Texture *tex) -{ - if(!texturing) - texturing = new Texturing; - - texturing->attach(index, *tex); -} - -void RenderPass::bind() const -{ - const RenderPass *old = current(); - if(!set_current(this)) - return; - - if(shprog) - { - shprog->bind(); - shdata->apply(); - } - else if(old && old->shprog) - Program::unbind(); - - if(material) - material->bind(); - else if(old && old->material) - Material::unbind(); - - if(texturing) - texturing->bind(); - else if(old && old->texturing) - Texturing::unbind(); -} - -void RenderPass::unbind() -{ - const RenderPass *old = current(); - if(!set_current(0)) - return; - - if(old->shprog) - Program::unbind(); - - if(old->material) - Material::unbind(); - - if(old->texturing) - Texturing::unbind(); -} - - -RenderPass::Loader::Loader(RenderPass &p): - DataFile::CollectionObjectLoader(p, 0) -{ - init(); -} - -RenderPass::Loader::Loader(RenderPass &p, Collection &c): - DataFile::CollectionObjectLoader(p, &c) -{ - init(); -} - -void RenderPass::Loader::init() -{ - allow_pointer_reload = false; - - add("shader", &RenderPass::shprog); - add("material", static_cast(&Loader::material)); - add("material", static_cast(&Loader::material)); - add("texunit", &Loader::texunit); - add("uniforms", &Loader::uniforms); -} - -void RenderPass::Loader::finish() -{ - // XXX Make shdata optional - if(obj.shprog && !obj.shdata) - obj.shdata = new ProgramData; -} - -void RenderPass::Loader::material() -{ - RefPtr mat = new Material; - load_sub(*mat); - obj.material = mat; -} - -void RenderPass::Loader::material(const string &name) -{ - obj.material = get_collection().get(name); - obj.material.keep(); -} - -void RenderPass::Loader::texunit(unsigned i) -{ - if(!obj.texturing) - obj.texturing = new Texturing; - TextureLoader ldr(*obj.texturing, i, coll); - load_sub_with(ldr); -} - -void RenderPass::Loader::uniforms() -{ - if(!obj.shprog) - throw InvalidState("Can't load uniforms without a shader program"); - if(!obj.shdata) - obj.shdata = new ProgramData; - load_sub(*obj.shdata, *obj.shprog); -} - - -RenderPass::TextureLoader::TextureLoader(Texturing &t, unsigned i, Collection *c): - DataFile::CollectionObjectLoader(t, c), - index(i) -{ - add("texture", &TextureLoader::texture); - add("texture2d", &TextureLoader::texture2d); -} - -void RenderPass::TextureLoader::finish() -{ - if(tex) - { - if(env) - obj.attach(index, *tex, *env); - else - obj.attach(index, *tex); - tex.release(); - env.release(); - } -} - -void RenderPass::TextureLoader::texenv() -{ - throw Exception("TexEnvs can't be loaded yet"); - /*env = new TexEnv; - load_sub(*env);*/ -} - -void RenderPass::TextureLoader::texture(const string &name) -{ - tex = get_collection().get(name); - tex.keep(); -} - -void RenderPass::TextureLoader::texture2d() -{ - tex = new Texture2D; - load_sub(static_cast(*tex)); -} - -} // namespace GL -} // namespace Msp