void Immediate::end_()
{
array.apply();
- glDrawArrays(type, 0, array.size());
+ glDrawElements(type, indices.size(), UNSIGNED_INT, &indices[0]);
array.clear();
+ indices.clear();
+}
+
+void Immediate::element_(unsigned i)
+{
+ indices.push_back(i);
}
} // namespace GL
{
private:
VertexArray array;
+ std::vector<unsigned> indices;
public:
Immediate(VertexFormat);
private:
virtual void begin_() { }
virtual void end_();
+ virtual void element_(unsigned);
};
} // namespace GL
MeshBuilder::MeshBuilder(Mesh &m):
PrimitiveBuilder(m.vertices),
mesh(m),
- first(0)
+ batch(0)
{ }
void MeshBuilder::begin_()
{
- first=array.size();
+ batch=new Batch(type);
}
void MeshBuilder::end_()
{
- Batch batch(type);
- unsigned last=array.size();
- for(unsigned i=first; i<last; ++i)
- batch.append(i);
- mesh.add_batch(batch);
+ mesh.add_batch(*batch);
+ delete batch;
+ batch=0;
+}
+
+void MeshBuilder::element_(unsigned i)
+{
+ batch->append(i);
}
} // namespace GL
namespace Msp {
namespace GL {
+class Batch;
class Mesh;
class MeshBuilder: public PrimitiveBuilder
{
private:
Mesh &mesh;
- unsigned first;
+ Batch *batch;
public:
MeshBuilder(Mesh &);
private:
virtual void begin_();
virtual void end_();
+ virtual void element_(unsigned);
};
} // namespace GL
textures[i]->bind();
}
}
- else if(main_texture)
+ else if(main_texture && pass.use_textures)
main_texture->bind();
if(material)
coll(c)
{
add("shader", &Loader::shader);
+ add("use_textures", &ObjectPass::use_textures);
}
void ObjectPass::Loader::shader(const string &n)
Program *shprog;
ProgramData *shdata;
+ bool use_textures;
ObjectPass();
~ObjectPass();
end_();
}
+void PrimitiveBuilder::element(unsigned i)
+{
+ if(!in_batch)
+ throw InvalidState("Element specification not between begin() and end()");
+ if(i>=array.size())
+ throw InvalidParameterValue("Element index out of range");
+ element_(i);
+}
+
PrimitiveType PrimitiveBuilder::get_type() const
{
if(!in_batch)
void PrimitiveBuilder::vertex_(float x, float y, float z, float w)
{
- if(!in_batch)
- throw InvalidState("Vertex specification not between begin() and end()");
-
builder->texcoord(ts, tt, tr,tq);
builder->color(cr, cg, cb, ca);
builder->normal(nx, ny, nz);
builder->vertex(x, y, z, w);
+
+ if(in_batch)
+ element_(array.size()-1);
}
} // namespace GL
public:
void begin(PrimitiveType);
void end();
+ void element(unsigned);
PrimitiveType get_type() const;
protected:
virtual void vertex_(float, float, float, float);
virtual void begin_() =0;
virtual void end_() =0;
+ virtual void element_(unsigned) =0;
};
} // namespace GL
pdata(pd),
prog(pr)
{
- add("uniform1", &Loader::uniform1);
- add("uniform2", &Loader::uniform2);
- add("uniform3", &Loader::uniform3);
- add("uniform4", &Loader::uniform4);
+ add("uniform1i", &Loader::uniform1i);
+ add("uniform1f", &Loader::uniform1f);
+ add("uniform2f", &Loader::uniform2f);
+ add("uniform3f", &Loader::uniform3f);
+ add("uniform4f", &Loader::uniform4f);
}
-void ProgramData::Loader::uniform1(const string &n, float v)
+void ProgramData::Loader::uniform1i(const string &n, int v)
{
pdata.uniform(prog.get_uniform_location(n), v);
}
-void ProgramData::Loader::uniform2(const string &n, float v0, float v1)
+void ProgramData::Loader::uniform1f(const string &n, float v)
+{
+ pdata.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);
}
-void ProgramData::Loader::uniform3(const string &n, float v0, float v1, float v2)
+void ProgramData::Loader::uniform3f(const string &n, float v0, float v1, float v2)
{
pdata.uniform(prog.get_uniform_location(n), v0, v1, v2);
}
-void ProgramData::Loader::uniform4(const string &n, float v0, float v1, float v2, float v3)
+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);
}
public:
Loader(ProgramData &, Program &);
private:
- void uniform1(const std::string &, float);
- void uniform2(const std::string &, float, float);
- void uniform3(const std::string &, float, float, float);
- void uniform4(const std::string &, float, float, float, float);
+ void uniform1i(const std::string &, int);
+ void uniform1f(const std::string &, float);
+ void uniform2f(const std::string &, float, float);
+ void uniform3f(const std::string &, float, float, float);
+ void uniform4f(const std::string &, float, float, float, float);
};
private: