From: Mikko Rasa Date: Sat, 6 Feb 2021 13:28:46 +0000 (+0200) Subject: Allow samplers to be loaded from datafiles X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=14247923eb936d602af43b35cb8ad0fd5d3e25e7;p=libs%2Fgl.git Allow samplers to be loaded from datafiles --- diff --git a/source/renderpass.cpp b/source/renderpass.cpp index 8281b215..835e78a6 100644 --- a/source/renderpass.cpp +++ b/source/renderpass.cpp @@ -128,7 +128,7 @@ void RenderPass::set_texture(unsigned index, const Texture *tex) if(!texturing) texturing = new Texturing; - texturing->attach(index, *tex); + texturing->attach(index, *tex, texturing->get_attached_sampler(index)); } int RenderPass::get_texture_index(const string &n) const @@ -246,14 +246,30 @@ void RenderPass::Loader::uniform_slot2(const string &name, const string &slot) RenderPass::TextureLoader::TextureLoader(Texturing &t, unsigned i, Collection *c): DataFile::CollectionObjectLoader(t, c), - index(i) + index(i), + tex(0), + samp(0) { + add("sampler", &TextureLoader::sampler); add("texture", &TextureLoader::texture); } +void RenderPass::TextureLoader::finish() +{ + if(tex) + obj.attach(index, *tex, samp); + else if(samp) + obj.attach(index, *samp); +} + +void RenderPass::TextureLoader::sampler(const string &name) +{ + samp = &get_collection().get(name); +} + void RenderPass::TextureLoader::texture(const string &name) { - obj.attach(index, get_collection().get(name)); + tex = &get_collection().get(name); } } // namespace GL diff --git a/source/renderpass.h b/source/renderpass.h index 7a2f6568..9e704376 100644 --- a/source/renderpass.h +++ b/source/renderpass.h @@ -11,6 +11,7 @@ class Material; class Program; class ProgramData; class Renderer; +class Sampler; class Texture; class Texturing; @@ -46,10 +47,15 @@ private: { private: unsigned index; + const Texture *tex; + const Sampler *samp; public: TextureLoader(Texturing &, unsigned, Collection *); private: + virtual void finish(); + + void sampler(const std::string &); void texture(const std::string &); }; diff --git a/source/resources.cpp b/source/resources.cpp index c28cdd07..d52dbe34 100644 --- a/source/resources.cpp +++ b/source/resources.cpp @@ -15,6 +15,7 @@ #include "programcompiler.h" #include "resourcemanager.h" #include "resources.h" +#include "sampler.h" #include "technique.h" #include "texture1d.h" #include "texture2d.h" @@ -46,6 +47,7 @@ Resources::Resources(): add_type().suffix(".pipe").keyword("pipeline"); add_type().keyword("pose"); add_type().keyword("shader").suffix(".glsl").creator(&Resources::create_program); + add_type().suffix(".samp").keyword("sampler"); add_type().suffix(".tech").keyword("technique"); add_type().base().suffix(".tex1d").keyword("texture1d"); add_type().base().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d").creator(&Resources::create_texture2d);