From: Mikko Rasa Date: Mon, 17 Jan 2011 17:43:10 +0000 (+0000) Subject: Reintroduce named texture slots for Technique inheritance X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=09b835f0ff0ee594fbb555224a85b28398e14116 Reintroduce named texture slots for Technique inheritance --- diff --git a/source/renderpass.cpp b/source/renderpass.cpp index d15a7098..b95bd4bc 100644 --- a/source/renderpass.cpp +++ b/source/renderpass.cpp @@ -33,7 +33,8 @@ RenderPass::RenderPass(const RenderPass &other): shprog(other.shprog), shdata(other.shdata ? new ProgramData(*other.shdata) : 0), material(other.material), - texturing(other.texturing ? new Texturing(*other.texturing) : 0) + texturing(other.texturing ? new Texturing(*other.texturing) : 0), + tex_names(other.tex_names) { } RenderPass::~RenderPass() @@ -56,6 +57,14 @@ void RenderPass::set_texture(unsigned index, const Texture *tex) texturing->attach(index, *tex); } +int RenderPass::get_texture_index(const string &n) const +{ + map::const_iterator i = tex_names.find(n); + if(i==tex_names.end()) + return -1; + return i->second; +} + RenderPass::Loader::Loader(RenderPass &p): DataFile::CollectionObjectLoader(p, 0) @@ -77,6 +86,7 @@ void RenderPass::Loader::init() add("material", &Loader::material_inline); add("material", &Loader::material); add("texunit", &Loader::texunit); + add("texunit", &Loader::texunit_named); add("uniforms", &Loader::uniforms); } @@ -101,6 +111,12 @@ void RenderPass::Loader::texunit(unsigned i) load_sub_with(ldr); } +void RenderPass::Loader::texunit_named(unsigned i, const string &n) +{ + texunit(i); + obj.tex_names[n] = i; +} + void RenderPass::Loader::uniforms() { if(!obj.shprog) diff --git a/source/renderpass.h b/source/renderpass.h index 5c1b8452..c201eb07 100644 --- a/source/renderpass.h +++ b/source/renderpass.h @@ -42,6 +42,7 @@ public: void material_inline(); void material(const std::string &); void texunit(unsigned); + void texunit_named(unsigned, const std::string &); void uniforms(); }; @@ -67,6 +68,7 @@ private: ProgramData *shdata; RefPtr material; Texturing *texturing; + std::map tex_names; RenderPass &operator=(const RenderPass &); public: @@ -80,6 +82,7 @@ public: const Material *get_material() const { return material.get(); } void set_texture(unsigned, const Texture *); const Texturing *get_texturing() const { return texturing; } + int get_texture_index(const std::string &) const; }; } // namespace GL diff --git a/source/technique.cpp b/source/technique.cpp index 9d13a897..49b48798 100644 --- a/source/technique.cpp +++ b/source/technique.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2008-2011 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -88,17 +88,15 @@ Technique::InheritLoader::InheritLoader(Technique &t, Collection &c): add("texture", &InheritLoader::texture); } -void Technique::InheritLoader::texture(unsigned index, const string &name) +void Technique::InheritLoader::texture(const std::string &slot, const string &name) { Texture *tex = get_collection().get(name); for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i) { - try - { - i->second.set_texture(index, tex); - } - catch(const KeyError &) - { } + int index = i->second.get_texture_index(slot); + if(index<0) + continue; + i->second.set_texture(index, tex); } } diff --git a/source/technique.h b/source/technique.h index 608af19d..b06ddcbb 100644 --- a/source/technique.h +++ b/source/technique.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2008-2011 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -41,7 +41,7 @@ private: InheritLoader(Technique &, Collection &); private: - void texture(unsigned, const std::string &); + void texture(const std::string &, const std::string &); }; typedef std::map PassMap;