]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/renderpass.cpp
Add a collection parameter to RenderPass::set_material
[libs/gl.git] / source / materials / renderpass.cpp
index 835e78a672cd6203649cdd9cbba4345421fa41b8..810b3673e584671423c95795a0eaab5cdd9c5e93 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/datafile/collection.h>
+#include <msp/io/print.h>
 #include <msp/strings/format.h>
 #include "error.h"
 #include "material.h"
@@ -76,7 +77,7 @@ void RenderPass::maybe_create_material_shader(DataFile::Collection *coll)
                shprog.keep();
        }
        else
-               shprog = material->create_compatible_shader();
+               throw invalid_operation("no collection");
 
        if(shdata)
                shdata = new ProgramData(*shdata, shprog.get());
@@ -116,19 +117,19 @@ const string &RenderPass::get_slotted_uniform_name(const string &slot) const
        return i->second;
 }
 
-void RenderPass::set_material(const Material *mat)
+void RenderPass::set_material(const Material *mat, DataFile::Collection *coll)
 {
        material = mat;
        material.keep();
-       finalize_material(0);
+       finalize_material(coll);
 }
 
-void RenderPass::set_texture(unsigned index, const Texture *tex)
+void RenderPass::set_texture(unsigned index, const Texture *tex, const Sampler *samp)
 {
        if(!texturing)
                texturing = new Texturing;
 
-       texturing->attach(index, *tex, texturing->get_attached_sampler(index));
+       texturing->attach(index, *tex, (samp ? samp : texturing->get_attached_sampler(index)));
 }
 
 int RenderPass::get_texture_index(const string &n) const
@@ -175,6 +176,17 @@ void RenderPass::Loader::init()
        add("uniform_slot", &Loader::uniform_slot2);
 }
 
+// Temporary compatibility feature
+string RenderPass::Loader::get_shader_name(const string &n)
+{
+       if(n.size()>=5 && !n.compare(n.size()-5, 5, ".glsl"))
+       {
+               IO::print(IO::cerr, "Warning: Loading module '%s' as shader is deprecated\n", n);
+               return n+".shader";
+       }
+       return n;
+}
+
 void RenderPass::Loader::material_inline()
 {
        Material::GenericLoader ldr(coll);
@@ -192,7 +204,7 @@ void RenderPass::Loader::material(const string &name)
 
 void RenderPass::Loader::shader(const string &n)
 {
-       obj.shprog = &get_collection().get<Program>(n);
+       obj.shprog = &get_collection().get<Program>(get_shader_name(n));
        obj.shprog.keep();
        obj.shprog_from_material = false;
        if(obj.shdata)