+#include <msp/core/maputils.h>
#include <msp/gl/extensions/arb_direct_state_access.h>
#include "buffer.h"
#include "color.h"
}
}
+vector<string> ProgramData::get_uniform_names() const
+{
+ vector<string> names;
+ for(SlotMap::const_iterator i=uniform_slots.begin(); i!=uniform_slots.end(); ++i)
+ names.push_back(i->first);
+ return names;
+}
+
+const Uniform &ProgramData::get_uniform(const string &name) const
+{
+ return *uniforms[get_item(uniform_slots, name)];
+}
+
unsigned ProgramData::compute_slot_mask(const Program::UniformBlockInfo &block) const
{
unsigned mask = 0;
void uniform_matrix4_array(const std::string &, unsigned, const float *);
void remove_uniform(const std::string &);
+ std::vector<std::string> get_uniform_names() const;
+ const Uniform &get_uniform(const std::string &) const;
+
private:
unsigned compute_slot_mask(const Program::UniformBlockInfo &) const;
void update_block(UniformBlock &, const Program::UniformBlockInfo &) const;
RenderPass::RenderPass(const RenderPass &other):
shprog(other.shprog),
shdata(other.shdata ? new ProgramData(*other.shdata) : 0),
+ uniform_slots(other.uniform_slots),
material(other.material),
texturing(other.texturing ? new Texturing(*other.texturing) : 0),
tex_names(other.tex_names),
{
shprog = other.shprog;
shdata = other.shdata ? new ProgramData(*other.shdata) : 0;
+ uniform_slots = other.uniform_slots;
material = other.material;
texturing = other.texturing ? new Texturing(*other.texturing) : 0;
tex_names = other.tex_names;
shdata = new ProgramData(*data);
}
+const string &RenderPass::get_slotted_uniform_name(const string &slot) const
+{
+ map<string, string>::const_iterator i = uniform_slots.find(slot);
+ if(i==uniform_slots.end())
+ {
+ static string empty;
+ return empty;
+ }
+ return i->second;
+}
+
void RenderPass::set_material(const Material *mat)
{
material = mat;
add("texunit", &Loader::texunit);
add("texunit", &Loader::texunit_named);
add("uniforms", &Loader::uniforms);
+ add("uniform_slot", &Loader::uniform_slot);
}
void RenderPass::Loader::material_inline()
obj.shdata = shd.release();
}
+void RenderPass::Loader::uniform_slot(const string &name)
+{
+ uniform_slot2(name, name);
+}
+
+void RenderPass::Loader::uniform_slot2(const string &name, const string &slot)
+{
+ obj.uniform_slots[slot] = name;
+}
+
RenderPass::TextureLoader::TextureLoader(Texturing &t, unsigned i, Collection *c):
DataFile::CollectionObjectLoader<Texturing>(t, c),
void texunit(unsigned);
void texunit_named(unsigned, const std::string &);
void uniforms();
+ void uniform_slot(const std::string &);
+ void uniform_slot2(const std::string &, const std::string &);
};
private:
const Program *shprog;
ProgramData *shdata;
+ std::map<std::string, std::string> uniform_slots;
RefPtr<const Material> material;
std::string material_slot;
Texturing *texturing;
void set_shader_program(const Program *, const ProgramData *);
const Program *get_shader_program() const { return shprog; }
const ProgramData *get_shader_data() const { return shdata; }
+ const std::string &get_slotted_uniform_name(const std::string &) const;
void set_material(const Material *);
const Material *get_material() const { return material.get(); }
const std::string &get_material_slot_name() const { return material_slot; }
return replaced;
}
+bool Technique::replace_uniforms(const ProgramData &shdata)
+{
+ bool replaced = false;
+ const vector<string> &uniform_names = shdata.get_uniform_names();
+ for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
+ {
+ RefPtr<ProgramData> new_shdata;
+ for(vector<string>::const_iterator j=uniform_names.begin(); j!=uniform_names.end(); ++j)
+ {
+ const string &name = i->second.get_slotted_uniform_name(*j);
+ if(name.empty())
+ continue;
+
+ if(!new_shdata)
+ new_shdata = new ProgramData(*i->second.get_shader_data());
+
+ new_shdata->uniform(name, shdata.get_uniform(*j));
+ replaced = true;
+ }
+
+ if(new_shdata)
+ i->second.set_shader_program(i->second.get_shader_program(), new_shdata.get());
+ }
+
+ return replaced;
+}
+
bool Technique::has_shaders() const
{
for(PassMap::const_iterator i=passes.begin(); i!=passes.end(); ++i)
{
add("material", &InheritLoader::material);
add("texture", &InheritLoader::texture);
+ add("uniforms", &InheritLoader::uniforms);
}
void Technique::InheritLoader::material(const string &slot, const string &name)
throw key_error(slot);
}
+void Technique::InheritLoader::uniforms()
+{
+ ProgramData shdata;
+ load_sub(shdata);
+ obj.replace_uniforms(shdata);
+}
+
} // namespace GL
} // namespace Msp
private:
void material(const std::string &, const std::string &);
void texture(const std::string &, const std::string &);
+ void uniforms();
};
public:
const PassMap &get_passes() const { return passes; }
bool replace_texture(const std::string &, const Texture &);
bool replace_material(const std::string &, const Material &);
+ bool replace_uniforms(const ProgramData &);
bool has_shaders() const;
};