X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frenderpass.cpp;h=70fa546afcddc0a0f2bcafb04da1313ddbd2b85b;hb=42ace9ac1350d3ae009bdd2fb335ac1e57d1b36b;hp=9e5b71d91f6a7a778902400d58fb0f5316dc40b7;hpb=a93d6abc8a4a3e70fa8f6781d9804583e18ef636;p=libs%2Fgl.git diff --git a/source/renderpass.cpp b/source/renderpass.cpp index 9e5b71d9..70fa546a 100644 --- a/source/renderpass.cpp +++ b/source/renderpass.cpp @@ -19,8 +19,6 @@ using namespace std; namespace Msp { namespace GL { -const RenderPass *RenderPass::current=0; - RenderPass::RenderPass(): shprog(0), shdata(0), @@ -45,7 +43,7 @@ RenderPass::~RenderPass() void RenderPass::set_material(const Material *mat) { - material=mat; + material = mat; } unsigned RenderPass::get_texture_index(const string &slot) const @@ -59,28 +57,26 @@ unsigned RenderPass::get_texture_index(const string &slot) const void RenderPass::set_texture(const string &slot, const Texture *tex) { - textures[get_texture_index(slot)]=tex; + textures[get_texture_index(slot)] = tex; } void RenderPass::bind() const { - if(this==current) + const RenderPass *old = current(); + if(!set_current(this)) return; - const RenderPass *old=current; - current=this; - if(shprog) { shprog->bind(); shdata->apply(); } - else if(old && !old->shprog) + else if(old && old->shprog) GL::Program::unbind(); if(material) material->bind(); - else if(old && !old->material) + else if(old && old->material) GL::Material::unbind(); for(unsigned i=0; ishprog) - GL::Program::unbind(); + const RenderPass *old = current(); + if(!set_current(0)) + return; - if(current->material) - GL::Material::unbind(); + if(old->shprog) + GL::Program::unbind(); - for(unsigned i=current->textures.size(); i--; ) - GL::Texture::unbind_from(i); + if(old->material) + GL::Material::unbind(); - current=0; - } + 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) { - allow_pointer_reload=false; + init(); +} + +void RenderPass::Loader::init() +{ + allow_pointer_reload = false; add("shader", &RenderPass::shprog); add("material", &Loader::material); @@ -128,11 +134,11 @@ void RenderPass::Loader::finish() if(obj.shprog) { if(!obj.shdata) - obj.shdata=new ProgramData; + obj.shdata = new ProgramData; for(unsigned i=0; iget_uniform_location(obj.textures[i].name); + unsigned loc = obj.shprog->get_uniform_location(obj.textures[i].name); obj.shdata->uniform(loc, static_cast(i)); } } @@ -143,17 +149,17 @@ void RenderPass::Loader::material() if(obj.material) throw InvalidState("A material is already loaded"); - RefPtr mat=new Material; + RefPtr mat = new Material; load_sub(*mat); - obj.material=mat.release(); - obj.own_material=true; + 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)); + 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())); + slot.name = (obj.textures.empty() ? "texture" : format("texture%d", obj.textures.size())); load_sub(slot); obj.textures.push_back(slot); } @@ -163,7 +169,7 @@ void RenderPass::Loader::uniforms() if(!obj.shprog) throw InvalidState("Can't load uniforms without a shader program"); if(!obj.shdata) - obj.shdata=new ProgramData; + obj.shdata = new ProgramData; load_sub(*obj.shdata, *obj.shprog); }