X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frenderpass.cpp;h=be5bb170280844d88c8b3e8f46fd22cb72e902de;hp=70fa546afcddc0a0f2bcafb04da1313ddbd2b85b;hb=HEAD;hpb=42ace9ac1350d3ae009bdd2fb335ac1e57d1b36b diff --git a/source/renderpass.cpp b/source/renderpass.cpp deleted file mode 100644 index 70fa546a..00000000 --- a/source/renderpass.cpp +++ /dev/null @@ -1,189 +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" - -using namespace std; - -namespace Msp { -namespace GL { - -RenderPass::RenderPass(): - shprog(0), - shdata(0), - own_material(false), - material(0) -{ } - -RenderPass::RenderPass(const RenderPass &other): - shprog(other.shprog), - shdata(other.shdata ? new ProgramData(*other.shdata) : 0), - own_material(other.own_material), - material(own_material ? new Material(*other.material) : other.material), - textures(other.textures) -{ } - -RenderPass::~RenderPass() -{ - delete shdata; - if(own_material) - delete material; -} - -void RenderPass::set_material(const Material *mat) -{ - material = mat; -} - -unsigned RenderPass::get_texture_index(const string &slot) const -{ - for(unsigned i=0; ibind(); - shdata->apply(); - } - else if(old && old->shprog) - GL::Program::unbind(); - - if(material) - material->bind(); - else if(old && old->material) - GL::Material::unbind(); - - for(unsigned i=0; ibind_to(i); - if(old) - { - for(unsigned i=textures.size(); itextures.size(); ++i) - GL::Texture::unbind_from(i); - } -} - -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::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", &Loader::material); - add("material", &RenderPass::material); - add("texture", &Loader::texture); - add("uniforms", &Loader::uniforms); -} - -void RenderPass::Loader::finish() -{ - if(obj.shprog) - { - if(!obj.shdata) - obj.shdata = new ProgramData; - - for(unsigned i=0; iget_uniform_location(obj.textures[i].name); - obj.shdata->uniform(loc, static_cast(i)); - } - } -} - -void RenderPass::Loader::material() -{ - if(obj.material) - throw InvalidState("A material is already loaded"); - - RefPtr mat = new Material; - load_sub(*mat); - obj.material = mat.release(); - obj.own_material = true; -} - -void RenderPass::Loader::texture(const string &n) -{ - const Texture *tex = (n.empty() ? 0 : get_collection().get(n)); - TextureSlot slot(tex); - slot.name = (obj.textures.empty() ? "texture" : format("texture%d", obj.textures.size())); - 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::TextureSlot(const Texture *t): - texture(t) -{ } - - -RenderPass::TextureSlot::Loader::Loader(TextureSlot &s): - DataFile::ObjectLoader(s) -{ - add("name", &TextureSlot::name); -} - -} // namespace GL -} // namespace Msp