From: Mikko Rasa Date: Wed, 10 Oct 2007 06:58:39 +0000 (+0000) Subject: Make Material::apply const X-Git-Tag: 0.9~36 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cea3c333797cadd9629aefaa5b82243173a02d16;p=libs%2Fgl.git Make Material::apply const Allow creating meshes runtime Add Program::uniform4 Add arithmetic operators for Color Use glXGetProcAddressARB to hopefully work on olfder glX implementations --- diff --git a/source/batch.cpp b/source/batch.cpp index d650fda8..df4e2fb8 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -19,7 +19,7 @@ Batch::Batch(PrimitiveType t): max_index(0) { } -void Batch::append(uint i) +Batch &Batch::append(uint i) { if(indices.empty()) min_index=max_index=i; @@ -29,6 +29,8 @@ void Batch::append(uint i) max_index=max(max_index, i); } indices.push_back(i); + + return *this; } void Batch::append(const vector &ind) diff --git a/source/batch.h b/source/batch.h index aace6528..237995dc 100644 --- a/source/batch.h +++ b/source/batch.h @@ -31,7 +31,7 @@ public: }; Batch(PrimitiveType t); - void append(uint); + Batch &append(uint); void append(const std::vector &); void draw() const; private: diff --git a/source/color.h b/source/color.h index 0fc303a2..d3710a9d 100644 --- a/source/color.h +++ b/source/color.h @@ -21,6 +21,10 @@ struct Color Color(float v): r(v), g(v), b(v), a(1) { } Color(float r_, float g_, float b_): r(r_), g(g_), b(b_), a(1) { } Color(float r_, float g_, float b_, float a_): r(r_), g(g_), b(b_), a(a_) { } + Color operator*(float f) const { return Color(r*f, g*f, b*f, a); } + Color operator+(const Color &c) const { return Color(r+c.r, g+c.g, b+c.g, 1-(1-a)*(1-c.a)); } + bool operator==(const Color &c) const { return (r==c.r && b==c.b && g==c.g && a==c.a); } + bool operator!=(const Color &c) const { return !operator==(c); } }; } // namespace GL diff --git a/source/extension.cpp b/source/extension.cpp index 1a603def..2d57d1d1 100644 --- a/source/extension.cpp +++ b/source/extension.cpp @@ -56,7 +56,7 @@ void require_extension(const string &ext) ExtFunc *get_proc_address(const string &name) { #ifndef WIN32 - return glXGetProcAddress(reinterpret_cast(name.c_str())); + return glXGetProcAddressARB(reinterpret_cast(name.c_str())); #endif } diff --git a/source/material.cpp b/source/material.cpp index 25c21ff2..58cd15cb 100644 --- a/source/material.cpp +++ b/source/material.cpp @@ -43,7 +43,7 @@ void Material::set_shininess(float s) shininess=s; } -void Material::apply() +void Material::apply() const { glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r); diff --git a/source/material.h b/source/material.h index b2ea995e..babf2676 100644 --- a/source/material.h +++ b/source/material.h @@ -29,7 +29,7 @@ public: void set_specular(const Color &s); void set_emission(const Color &e); void set_shininess(float s); - void apply(); + void apply() const; }; } // namespace GL diff --git a/source/mesh.cpp b/source/mesh.cpp index 4e671e03..8d039977 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -18,6 +18,17 @@ Mesh::Mesh(): vertices.use_vertex_buffer(); } +Mesh::Mesh(VertexFormat f): + vertices(f) +{ + vertices.use_vertex_buffer(); +} + +void Mesh::add_batch(const Batch &b) +{ + batches.push_back(b); +} + void Mesh::draw() const { vertices.apply(); diff --git a/source/mesh.h b/source/mesh.h index 648fb72c..7c80d322 100644 --- a/source/mesh.h +++ b/source/mesh.h @@ -30,6 +30,9 @@ public: }; Mesh(); + Mesh(VertexFormat f); + RefPtr modify_vertices() { return vertices.modify(); } + void add_batch(const Batch &b); void draw() const; private: VertexArray vertices; diff --git a/source/program.cpp b/source/program.cpp index f34133fa..f0fffb1f 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -144,6 +144,11 @@ void Program::uniform(int i, float x, float y, float z, float w) glUniform4fARB(i, x, y, z, w); } +void Program::uniform4(int i, const float *v) +{ + glUniform4fvARB(i, 1, v); +} + void Program::uniform_matrix4(int i, const float *v) { glUniformMatrix4fvARB(i, 1, false, v); diff --git a/source/program.h b/source/program.h index f007fb3a..af249ede 100644 --- a/source/program.h +++ b/source/program.h @@ -64,6 +64,7 @@ public: void uniform(int, float, float); void uniform(int, float, float, float); void uniform(int, float, float, float, float); + void uniform4(int, const float *); void uniform_matrix4(int, const float *); static void unbind();