X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frenderpass.cpp;h=be5bb170280844d88c8b3e8f46fd22cb72e902de;hp=b9a2cb83a05a09cbaab1ec3f6ea674a1fec707ac;hb=HEAD;hpb=2f09d68a0844d2838d116d93d3ecc69723b52f16 diff --git a/source/renderpass.cpp b/source/renderpass.cpp deleted file mode 100644 index b9a2cb83..00000000 --- a/source/renderpass.cpp +++ /dev/null @@ -1,211 +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 "texture.h" -#include "texture2d.h" - -using namespace std; - -namespace Msp { -namespace GL { - -RenderPass::RenderPass(): - shprog(0), - shdata(0), - material(0) -{ } - -RenderPass::RenderPass(const RenderPass &other): - Bindable(other), - shprog(other.shprog), - shdata(other.shdata ? new ProgramData(*other.shdata) : 0), - material(other.material), - textures(other.textures) -{ } - -RenderPass::~RenderPass() -{ - delete shdata; -} - -void RenderPass::set_material(const Material *mat) -{ - material = mat; - material.keep(); -} - -void RenderPass::set_texture(unsigned index, const Texture *tex) -{ - for(vector::iterator i=textures.begin(); i!=textures.end(); ++i) - if(i->index==index) - { - i->texture = tex; - i->texture.keep(); - return; - } - - textures.push_back(TextureSlot(index)); - textures.back().texture = tex; - textures.back().texture.keep(); -} - -void RenderPass::bind() const -{ - const RenderPass *old = current(); - if(!set_current(this)) - return; - - if(shprog) - { - shprog->bind(); - shdata->apply(); - } - else if(old && old->shprog) - GL::Program::unbind(); - - if(material) - material->bind(); - else if(old && old->material) - GL::Material::unbind(); - - unsigned used_tex_units = 0; - for(vector::const_iterator i=textures.begin(); i!=textures.end(); ++i) - { - i->texture->bind_to(i->index); - used_tex_units |= 1<index; - } - if(old) - { - for(vector::const_iterator i=old->textures.begin(); i!=old->textures.end(); ++i) - if(!used_tex_units&(1<index)) - Texture::unbind_from(i->index); - } -} - -void RenderPass::unbind() -{ - const RenderPass *old = current(); - if(!set_current(0)) - return; - - if(old->shprog) - GL::Program::unbind(); - - if(old->material) - GL::Material::unbind(); - - for(unsigned i=old->textures.size(); i--; ) - GL::Texture::unbind_from(i); -} - - -RenderPass::TextureSlot::TextureSlot(unsigned i): - index(i), - texture(0) -{ } - - -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) -{ - TextureSlot slot(i); - load_sub(slot); - obj.textures.push_back(slot); -} - -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::TextureSlot::Loader::Loader(TextureSlot &s): - DataFile::CollectionObjectLoader(s, 0) -{ - init(); -} - -RenderPass::TextureSlot::Loader::Loader(TextureSlot &s, Collection &c): - DataFile::CollectionObjectLoader(s, &c) -{ - init(); -} - -void RenderPass::TextureSlot::Loader::init() -{ - add("texture", &Loader::texture); - add("texture2d", &Loader::texture2d); -} - -void RenderPass::TextureSlot::Loader::texture(const string &name) -{ - obj.texture = get_collection().get(name); - obj.texture.keep(); -} - -void RenderPass::TextureSlot::Loader::texture2d() -{ - RefPtr tex = new Texture2D; - load_sub(*tex); - obj.texture = tex; -} - -} // namespace GL -} // namespace Msp