1 #include <msp/datafile/collection.h>
2 #include <msp/strings/format.h>
5 #include "renderpass.h"
7 #include "programdata.h"
10 #include "texture2d.h"
11 #include "texturing.h"
18 RenderPass::RenderPass():
25 RenderPass::RenderPass(const RenderPass &other):
27 shdata(other.shdata ? new ProgramData(*other.shdata) : 0),
28 material(other.material),
29 texturing(other.texturing ? new Texturing(*other.texturing) : 0),
30 tex_names(other.tex_names)
33 RenderPass::~RenderPass()
38 void RenderPass::set_shader_program(const Program *prog, const ProgramData *data)
45 void RenderPass::set_material(const Material *mat)
51 void RenderPass::set_texture(unsigned index, const Texture *tex)
54 texturing = new Texturing;
56 texturing->attach(index, *tex);
59 int RenderPass::get_texture_index(const string &n) const
61 map<string, unsigned>::const_iterator i = tex_names.find(n);
62 if(i==tex_names.end())
68 RenderPass::Loader::Loader(RenderPass &p):
69 DataFile::CollectionObjectLoader<RenderPass>(p, 0)
74 RenderPass::Loader::Loader(RenderPass &p, Collection &c):
75 DataFile::CollectionObjectLoader<RenderPass>(p, &c)
80 void RenderPass::Loader::init()
82 add("shader", &RenderPass::shprog);
83 add("material", &Loader::material_inline);
84 add("material", &Loader::material);
85 add("texunit", &Loader::texunit);
86 add("texunit", &Loader::texunit_named);
87 add("uniforms", &Loader::uniforms);
90 void RenderPass::Loader::material_inline()
92 RefPtr<Material> mat = new Material;
97 void RenderPass::Loader::material(const string &name)
99 obj.material = &get_collection().get<Material>(name);
103 void RenderPass::Loader::texunit(unsigned i)
106 obj.texturing = new Texturing;
107 TextureLoader ldr(*obj.texturing, i, coll);
111 void RenderPass::Loader::texunit_named(unsigned i, const string &n)
114 obj.tex_names[n] = i;
117 void RenderPass::Loader::uniforms()
120 throw invalid_operation("RenderPass::Loader::uniforms");
121 RefPtr<ProgramData> shd = new ProgramData;
127 RenderPass::TextureLoader::TextureLoader(Texturing &t, unsigned i, Collection *c):
128 DataFile::CollectionObjectLoader<Texturing>(t, c),
131 add("texture", &TextureLoader::texture);
132 add("texture2d", &TextureLoader::texture2d);
135 void RenderPass::TextureLoader::finish()
140 obj.attach(index, *tex, *env);
142 obj.attach(index, *tex);
148 void RenderPass::TextureLoader::texenv()
150 throw runtime_error("TexEnvs can't be loaded yet");
155 void RenderPass::TextureLoader::texture(const string &name)
157 tex = &get_collection().get<Texture>(name);
161 void RenderPass::TextureLoader::texture2d()
164 load_sub(static_cast<Texture2D &>(*tex));