]> git.tdb.fi Git - libs/gl.git/commitdiff
Allow samplers to be loaded from datafiles
authorMikko Rasa <tdb@tdb.fi>
Sat, 6 Feb 2021 13:28:46 +0000 (15:28 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 6 Feb 2021 17:46:18 +0000 (19:46 +0200)
source/renderpass.cpp
source/renderpass.h
source/resources.cpp

index 8281b2151f3c6c9b54d7ba2c83cc6bbbfad05880..835e78a672cd6203649cdd9cbba4345421fa41b8 100644 (file)
@@ -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<Texturing>(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<Sampler>(name);
+}
+
 void RenderPass::TextureLoader::texture(const string &name)
 {
-       obj.attach(index, get_collection().get<Texture>(name));
+       tex = &get_collection().get<Texture>(name);
 }
 
 } // namespace GL
index 7a2f65688104015afe9650b4b5b6e5814a84a95f..9e704376a446b56abb056edf0d1aab803a269f7d 100644 (file)
@@ -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 &);
        };
 
index c28cdd07cf2d5f6a86814c44aa053ca674005e9f..d52dbe34fb61c745e74c4cad108cdd0a604990e7 100644 (file)
@@ -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<PipelineTemplate>().suffix(".pipe").keyword("pipeline");
        add_type<Pose>().keyword("pose");
        add_type<Program>().keyword("shader").suffix(".glsl").creator(&Resources::create_program);
+       add_type<Sampler>().suffix(".samp").keyword("sampler");
        add_type<Technique>().suffix(".tech").keyword("technique");
        add_type<Texture1D>().base<Texture>().suffix(".tex1d").keyword("texture1d");
        add_type<Texture2D>().base<Texture>().suffix(".tex2d").suffix(".png").suffix(".jpg").keyword("texture2d").creator(&Resources::create_texture2d);