Batch::Loader::Loader(Batch &b):
- batch(b)
+ DataFile::ObjectLoader<Batch>(b)
{
add("indices", &Loader::indices);
}
void Batch::Loader::indices(const vector<uint> &ind)
{
- batch.append(ind);
+ obj.append(ind);
}
} // namespace GL
#define MSP_GL_BATCH_H_
#include <vector>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
#include "primitivetype.h"
#include "types.h"
class Batch
{
public:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::ObjectLoader<Batch>
{
public:
Loader(Batch &);
private:
- Batch &batch;
-
void indices(const std::vector<uint> &);
};
Distributed under the LGPL
*/
+#include <msp/datafile/collection.h>
#include "gl.h"
#include "font.h"
#include "immediate.h"
Font::Loader::Loader(Font &f):
- font(f),
- coll(0)
+ DataFile::CollectionObjectLoader<Font>(f, 0)
{
init();
}
Font::Loader::Loader(Font &f, Collection &c):
- font(f),
- coll(&c)
+ DataFile::CollectionObjectLoader<Font>(f, &c)
{
init();
}
-DataFile::Collection &Font::Loader::get_collection()
-{
- if(!coll)
- throw InvalidState("No collection");
- return *coll;
-}
-
void Font::Loader::init()
{
add("default_size", &Font::default_size);
Glyph gl;
gl.code=c;
load_sub(gl);
- font.glyphs.insert(GlyphMap::value_type(c, gl));
+ obj.glyphs.insert(GlyphMap::value_type(c, gl));
}
void Font::Loader::texture_inline()
{
RefPtr<Texture2D> tex=new Texture2D;
load_sub(*tex);
- font.tex=tex.release();
- font.own_tex=true;
+ obj.tex=tex.release();
+ obj.own_tex=true;
}
Font::Glyph::Loader::Loader(Glyph &g):
- glyph(g)
+ DataFile::ObjectLoader<Glyph>(g)
{
add("texcoords", &Loader::texcoords);
add("size", &Glyph::w, &Glyph::h);
void Font::Glyph::Loader::texcoords(float x1, float y1, float x2, float y2)
{
- glyph.x1=x1;
- glyph.y1=y1;
- glyph.x2=x2;
- glyph.y2=y2;
+ obj.x1=x1;
+ obj.y1=y1;
+ obj.x2=x2;
+ obj.y2=y2;
}
} // namespace GL
#include <map>
#include <string>
-#include <msp/datafile/collection.h>
+#include <msp/datafile/objectloader.h>
#include <msp/strings/utf8.h>
#include "vertexarray.h"
class Font
{
public:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::CollectionObjectLoader<Font>
{
- private:
- Font &font;
- DataFile::Collection *coll;
-
public:
- typedef DataFile::Collection Collection;
-
Loader(Font &);
- Loader(Font &, DataFile::Collection &);
- Font &get_object() { return font; }
- DataFile::Collection &get_collection();
+ Loader(Font &, Collection &);
private:
void init();
void glyph(unsigned);
private:
struct Glyph
{
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::ObjectLoader<Glyph>
{
public:
Loader(Glyph &);
- Glyph &get_object() { return glyph; }
private:
- Glyph &glyph;
-
void texcoords(float, float, float, float);
};
Material::Loader::Loader(Material &m):
- mat(m)
+ DataFile::ObjectLoader<Material>(m)
{
add("ambient", &Loader::ambient);
add("diffuse", &Loader::diffuse);
void Material::Loader::ambient(float r, float g, float b, float a)
{
- mat.ambient=GL::Color(r, g, b, a);
+ obj.ambient=GL::Color(r, g, b, a);
}
void Material::Loader::diffuse(float r, float g, float b, float a)
{
- mat.diffuse=GL::Color(r, g, b, a);
+ obj.diffuse=GL::Color(r, g, b, a);
}
void Material::Loader::specular(float r, float g, float b, float a)
{
- mat.specular=GL::Color(r, g, b, a);
+ obj.specular=GL::Color(r, g, b, a);
}
void Material::Loader::emission(float r, float g, float b, float a)
{
- mat.emission=GL::Color(r, g, b, a);
+ obj.emission=GL::Color(r, g, b, a);
}
} // namespace GL
#ifndef MSP_GL_MATERIAL_H_
#define MSP_GL_MATERIAL_H_
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
#include "color.h"
namespace Msp {
class Material
{
public:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::ObjectLoader<Material>
{
- private:
- Material &mat;
-
public:
Loader(Material &);
- Material &get_object() const { return mat; }
private:
void ambient(float, float, float, float);
Mesh::Loader::Loader(Mesh &m):
- mesh(m)
+ DataFile::ObjectLoader<Mesh>(m)
{
add("vertices", &Loader::vertices);
add("batch", &Loader::batch);
void Mesh::Loader::vertices(VertexFormat f)
{
- mesh.vertices.reset(f);
- load_sub(mesh.vertices);
+ obj.vertices.reset(f);
+ load_sub(obj.vertices);
}
void Mesh::Loader::batch(PrimitiveType p)
{
- mesh.batches.push_back(Batch(p));
- load_sub(mesh.batches.back());
+ obj.batches.push_back(Batch(p));
+ load_sub(obj.batches.back());
}
} // namespace GL
#ifndef MSP_GL_MESH_H_
#define MSP_GL_MESH_H_
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
#include "batch.h"
#include "vertexarray.h"
friend class MeshBuilder;
public:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::ObjectLoader<Mesh>
{
public:
Loader(Mesh &);
private:
- Mesh &mesh;
-
void vertices(VertexFormat);
void batch(PrimitiveType);
};
Distributed under the LGPL
*/
+#include <msp/datafile/collection.h>
#include <msp/strings/formatter.h>
#include "except.h"
#include "material.h"
Object::Loader::Loader(Object &o, Collection &c):
- obj(o),
- coll(c)
+ DataFile::CollectionObjectLoader<Object>(o, &c)
{
add("lod_mesh", &Loader::lod_mesh);
add("material", &Object::material);
void Object::Loader::lod_mesh(unsigned l, const string &n)
{
obj.meshes.resize(l+1, 0);
- obj.meshes[l]=coll.get<Mesh>(n);
+ obj.meshes[l]=coll->get<Mesh>(n);
}
void Object::Loader::material_inline()
{
RefPtr<Material> mat=new Material;
load_sub(*mat);
- coll.add(format("_%p", mat.get()), mat.get());
+ coll->add(format("_%p", mat.get()), mat.get());
obj.material=mat.release();
}
void Object::Loader::mesh(const string &n)
{
- obj.meshes[0]=coll.get<Mesh>(n);
+ obj.meshes[0]=coll->get<Mesh>(n);
}
void Object::Loader::shader_texture(const string &n)
if(eqsign==string::npos)
throw InvalidParameterValue("Must specify texture slot name");
- obj.textures[obj.technique->get_texture_index(n.substr(0, eqsign))]=coll.get<Texture>(n.substr(eqsign+1));
+ obj.textures[obj.technique->get_texture_index(n.substr(0, eqsign))]=coll->get<Texture>(n.substr(eqsign+1));
}
void Object::Loader::technique(const string &n)
{
- obj.technique=coll.get<Technique>(n);
+ obj.technique=coll->get<Technique>(n);
obj.textures.resize(obj.technique->get_n_textures());
obj.material=obj.technique->get_material();
}
if(obj.main_texture)
throw Exception("Only one main texture may be specified");
- Texture *tex=coll.get<Texture>(n);
+ Texture *tex=coll->get<Texture>(n);
if(obj.technique)
obj.textures[obj.technique->get_texture_index("texture")]=tex;
obj.main_texture=tex;
#define MSP_GL_OBJECT_H_
#include <vector>
-#include <msp/datafile/collection.h>
#include "objectpass.h"
#include "renderable.h"
const Material *material;
public:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::CollectionObjectLoader<Object>
{
- public:
- typedef DataFile::Collection Collection;
-
- protected:
- Object &obj;
- Collection &coll;
-
public:
Loader(Object &, Collection &);
- Object &get_object() const { return obj; }
- Collection &get_collection() const { return coll; }
private:
virtual void finish();
void lod_mesh(unsigned, const std::string &);
Distributed under the LGPL
*/
+#include <msp/datafile/collection.h>
#include "objectpass.h"
#include "program.h"
#include "programdata.h"
ObjectPass::Loader::Loader(ObjectPass &p, Collection &c):
- pass(p),
- coll(c)
+ DataFile::CollectionObjectLoader<ObjectPass>(p, &c)
{
add("shader", &Loader::shader);
add("use_textures", &ObjectPass::use_textures);
void ObjectPass::Loader::shader(const string &n)
{
- Program *shprog=coll.get<Program>(n);
+ Program *shprog=coll->get<Program>(n);
if(shprog) // Allow for unsupported shaders
{
RefPtr<ProgramData> shdata=new ProgramData;
load_sub(*shdata, *shprog);
- pass.shprog=shprog;
- if(pass.shdata)
- delete pass.shdata;
- pass.shdata=shdata.release();
+ obj.shprog=shprog;
+ if(obj.shdata)
+ delete obj.shdata;
+ obj.shdata=shdata.release();
}
}
#ifndef MSP_GL_OBJECTPASS_H_
#define MSP_GL_OBJECTPASS_H_
-#include <msp/datafile/collection.h>
+#include <msp/datafile/objectloader.h>
namespace Msp {
namespace GL {
struct ObjectPass
{
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::CollectionObjectLoader<ObjectPass>
{
- public:
- typedef DataFile::Collection Collection;
-
- private:
- ObjectPass &pass;
- Collection &coll;
-
public:
Loader(ObjectPass &, Collection &);
- ObjectPass &get_object() const { return pass; }
- Collection &get_collection() const { return coll; }
private:
void shader(const std::string &);
};
Program::Loader::Loader(Program &p):
- prog(p)
+ DataFile::ObjectLoader<Program>(p)
{
- prog.set_del_shaders(true);
+ obj.set_del_shaders(true);
add("vertex_shader", &Loader::vertex_shader);
add("fragment_shader", &Loader::fragment_shader);
void Program::Loader::vertex_shader(const string &src)
{
- prog.attach_shader(*new Shader(VERTEX_SHADER, src));
+ obj.attach_shader(*new Shader(VERTEX_SHADER, src));
}
void Program::Loader::fragment_shader(const string &src)
{
- prog.attach_shader(*new Shader(FRAGMENT_SHADER, src));
+ obj.attach_shader(*new Shader(FRAGMENT_SHADER, src));
}
void Program::Loader::attribute(uint i, const string &n)
{
- prog.bind_attribute(i, n);
+ obj.bind_attribute(i, n);
}
void Program::Loader::finish()
{
- prog.link();
+ obj.link();
}
} // namespace GL
#include <list>
#include <string>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
#include "gl.h"
#include "types.h"
static const Program *cur_prog;
public:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::ObjectLoader<Program>
{
- private:
- Program &prog;
-
public:
Loader(Program &);
ProgramData::Loader::Loader(ProgramData &pd, Program &pr):
- pdata(pd),
+ DataFile::ObjectLoader<ProgramData>(pd),
prog(pr)
{
add("uniform1i", &Loader::uniform1i);
void ProgramData::Loader::uniform1i(const string &n, int v)
{
- pdata.uniform(prog.get_uniform_location(n), v);
+ obj.uniform(prog.get_uniform_location(n), v);
}
void ProgramData::Loader::uniform1f(const string &n, float v)
{
- pdata.uniform(prog.get_uniform_location(n), v);
+ obj.uniform(prog.get_uniform_location(n), v);
}
void ProgramData::Loader::uniform2f(const string &n, float v0, float v1)
{
- pdata.uniform(prog.get_uniform_location(n), v0, v1);
+ obj.uniform(prog.get_uniform_location(n), v0, v1);
}
void ProgramData::Loader::uniform3f(const string &n, float v0, float v1, float v2)
{
- pdata.uniform(prog.get_uniform_location(n), v0, v1, v2);
+ obj.uniform(prog.get_uniform_location(n), v0, v1, v2);
}
void ProgramData::Loader::uniform4f(const string &n, float v0, float v1, float v2, float v3)
{
- pdata.uniform(prog.get_uniform_location(n), v0, v1, v2, v3);
+ obj.uniform(prog.get_uniform_location(n), v0, v1, v2, v3);
}
} // namespace GL
#define MSP_GL_PROGRAMDATA_H_
#include <map>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
namespace Msp {
namespace GL {
class ProgramData
{
public:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::ObjectLoader<ProgramData>
{
private:
- ProgramData &pdata;
Program &prog;
public:
Distributed under the LGPL
*/
+#include <msp/core/refptr.h>
+#include <msp/datafile/collection.h>
#include <msp/strings/formatter.h>
#include "material.h"
#include "program.h"
Technique::Loader::Loader(Technique &t, Collection &c):
- tech(t),
- coll(c)
+ DataFile::CollectionObjectLoader<Technique>(t, &c)
{
add("material", &Technique::material);
add("material_inline", &Loader::material_inline);
void Technique::Loader::finish()
{
- for(PassMap::iterator i=tech.passes.begin(); i!=tech.passes.end(); ++i)
+ for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
if(i->second.shdata)
{
- for(unsigned j=0; j<tech.textures.size(); ++j)
+ for(unsigned j=0; j<obj.textures.size(); ++j)
{
- unsigned loc=i->second.shprog->get_uniform_location(tech.textures[j].name);
+ unsigned loc=i->second.shprog->get_uniform_location(obj.textures[j].name);
i->second.shdata->uniform(loc, static_cast<int>(j));
}
}
{
RefPtr<Material> mat=new Material;
load_sub(*mat);
- coll.add(format("_%p", mat.get()), mat.get());
- tech.material=mat.release();
+ coll->add(format("_%p", mat.get()), mat.get());
+ obj.material=mat.release();
}
void Technique::Loader::pass(const string &n)
{
Tag tag(n);
- if(tech.passes.count(tag))
+ if(obj.passes.count(tag))
throw KeyError("Duplicate pass name", n);
ObjectPass p;
- load_sub(p, coll);
- tech.passes[tag]=p;
+ load_sub(p, *coll);
+ obj.passes[tag]=p;
}
void Technique::Loader::shader(const string &n)
{
- Program *shprog=coll.get<Program>(n);
+ Program *shprog=coll->get<Program>(n);
if(shprog) // Allow for unsupported shaders
{
RefPtr<ProgramData> shdata=new ProgramData;
load_sub(*shdata, *shprog);
- tech.normal_pass->shprog=shprog;
- if(tech.normal_pass->shdata)
- delete tech.normal_pass->shdata;
- tech.normal_pass->shdata=shdata.release();
+ obj.normal_pass->shprog=shprog;
+ if(obj.normal_pass->shdata)
+ delete obj.normal_pass->shdata;
+ obj.normal_pass->shdata=shdata.release();
}
}
if(eqsign!=string::npos)
{
tex.name=n.substr(0, eqsign);
- tex.texture=coll.get<Texture>(n.substr(eqsign+1));
+ tex.texture=coll->get<Texture>(n.substr(eqsign+1));
}
else
{
string::size_type dot=n.rfind('.');
tex.name=n.substr(0, dot);
- tex.texture = coll.get<Texture>(n);
+ tex.texture = coll->get<Texture>(n);
}
for(string::iterator i=tex.name.begin(); i!=tex.name.end(); ++i)
if(!isalnum(*i))
*i='_';
- tech.textures.push_back(tex);
+ obj.textures.push_back(tex);
}
void Technique::Loader::texture(const string &n)
{
- if(tech.main_texture)
+ if(obj.main_texture)
throw Exception("Only one main texture may be specified");
- tech.main_texture=coll.get<Texture>(n);
+ obj.main_texture=coll->get<Texture>(n);
TextureSlot tex;
tex.name="texture";
- tex.texture=tech.main_texture;
- tech.textures.push_back(tex);
+ tex.texture=obj.main_texture;
+ obj.textures.push_back(tex);
}
void Technique::Loader::texture_slot(const string &n)
{
TextureSlot tex;
tex.name=n;
- tech.textures.push_back(tex);
+ obj.textures.push_back(tex);
}
} // namespace GL
class Technique
{
public:
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::CollectionObjectLoader<Technique>
{
- public:
- typedef DataFile::Collection Collection;
-
- protected:
- Technique &tech;
- Collection &coll;
-
public:
Loader(Technique &, Collection &);
- Technique &get_object() const { return tech; }
- Collection &get_collection() const { return coll; }
private:
virtual void finish();
void material_inline();
Texture::Loader::Loader(Texture &t):
- tex(t)
+ DataFile::ObjectLoader<Texture>(t)
{
add("min_filter", &Loader::min_filter);
add("mag_filter", &Loader::mag_filter);
void Texture::Loader::min_filter(TextureFilter f)
{
- tex.set_min_filter(f);
+ obj.set_min_filter(f);
}
void Texture::Loader::mag_filter(TextureFilter f)
{
- tex.set_mag_filter(f);
+ obj.set_mag_filter(f);
}
void Texture::Loader::generate_mipmap(bool gm)
{
- tex.parameter(GL_GENERATE_MIPMAP_SGIS, gm);
+ obj.parameter(GL_GENERATE_MIPMAP_SGIS, gm);
}
} // namespace GL
#define MSP_GL_TEXTURE_H_
#include <istream>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
#include "gl.h"
#include "types.h"
class Texture
{
protected:
- class Loader: public DataFile::Loader
+ class Loader: public DataFile::ObjectLoader<Texture>
{
- protected:
- Texture &tex;
-
public:
Loader(Texture &);
void min_filter(TextureFilter);
Graphics::Image img;
img.load_memory(data.data(), data.size());
- static_cast<Texture2D &>(tex).image(img);
+ static_cast<Texture2D &>(obj).image(img);
}
void Texture2D::Loader::raw_data(const string &data)
{
- Texture2D &t2d=static_cast<Texture2D &>(tex);;
+ Texture2D &t2d=static_cast<Texture2D &>(obj);
t2d.image(0, t2d.ifmt, UNSIGNED_BYTE, data.data());
}
void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h, unsigned b)
{
- static_cast<Texture2D &>(tex).storage(fmt, w, h, b);
+ static_cast<Texture2D &>(obj).storage(fmt, w, h, b);
}
} // namespace GL
#define MSP_GL_TEXTURE2D_H_
#include <string>
-#include <msp/datafile/loader.h>
#include <msp/gbase/image.h>
#include "pixelformat.h"
#include "texture.h"