diff --git a/examples/debug/main.cpp b/examples/debug/main.cpp index 118843a..df4a662 100644 --- a/examples/debug/main.cpp +++ b/examples/debug/main.cpp @@ -66,7 +66,7 @@ int main(int argc, char** argv) return -1; } - oglu::Object square(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology)); + oglu::Object square = oglu::MakeObject(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology)); while (!glfwWindowShouldClose(window)) { @@ -76,7 +76,7 @@ int main(int argc, char** argv) shader->SetUniform("ourColor", &oglu::Color::Transparent); shader->Use(); - square.BindAndDraw(); + square->BindAndDraw(); glfwSwapBuffers(window); glfwPollEvents(); diff --git a/include/color.hpp b/include/color.hpp index a8547a8..c3536ca 100644 --- a/include/color.hpp +++ b/include/color.hpp @@ -1,7 +1,7 @@ #ifndef COLOR_HPP #define COLOR_HPP -#include "core.hpp" +#include #include namespace oglu diff --git a/include/core.hpp b/include/core.hpp index 52a2c06..1a64380 100644 --- a/include/core.hpp +++ b/include/core.hpp @@ -1,6 +1,8 @@ #ifndef CORE_HPP #define CORE_HPP +#include + #ifdef OGLU_WIN32 #ifdef OGLU_BUILD_DLL #define OGLU_API __declspec(dllexport) diff --git a/include/object.hpp b/include/object.hpp index 9b8d437..cc99b58 100644 --- a/include/object.hpp +++ b/include/object.hpp @@ -1,7 +1,7 @@ #ifndef DRAWABLE_HPP #define DRAWABLE_HPP -#include "core.hpp" +#include #include namespace oglu @@ -15,11 +15,12 @@ namespace oglu const GLvoid* pointer; } VertexAttribute; - class OGLU_API Object + class OGLU_API AbstractObject { public: - Object(); - Object(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize); + AbstractObject(const AbstractObject& other); + + friend std::shared_ptr OGLU_API MakeObject(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize); GLuint GetVAO() { return VAO; } void Bind(); @@ -29,11 +30,15 @@ namespace oglu void BindAndDraw(); private: + AbstractObject(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize); + inline void RegisterVertexAttribPointer(GLuint index, const VertexAttribute& topology); GLuint VAO; GLsizei count; }; + + typedef std::shared_ptr Object; } #endif diff --git a/include/shader.hpp b/include/shader.hpp index 9894114..27f343a 100644 --- a/include/shader.hpp +++ b/include/shader.hpp @@ -1,7 +1,6 @@ #ifndef SHADER_HPP #define SHADER_HPP -#include #include #include diff --git a/src/object.cpp b/src/object.cpp index dad6910..59cb075 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -2,15 +2,22 @@ namespace oglu { - Object::Object() : - VAO(0) + AbstractObject::AbstractObject(const AbstractObject& other) : + VAO(other.VAO), count(other.count) { + } - Object::Object(const GLfloat* vertices, size_t verticesSize, + Object MakeObject(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize) + { + AbstractObject* obj = new AbstractObject(vertices, verticesSize, indices, indicesSize, topology, topologySize); + return Object(obj); + } + + AbstractObject::AbstractObject(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize) : - VAO(0) + VAO(0), count(0) { topologySize /= sizeof(VertexAttribute); @@ -39,29 +46,29 @@ namespace oglu count = indicesSize / sizeof(GLuint); } - void Object::Bind() + void AbstractObject::Bind() { glBindVertexArray(VAO); } - void Object::Unbind() + void AbstractObject::Unbind() { } - void Object::Draw() + void AbstractObject::Draw() { glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, (GLvoid*)0); } - void Object::BindAndDraw() + void AbstractObject::BindAndDraw() { glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, (GLvoid*)0); glBindVertexArray(0); } - void Object::RegisterVertexAttribPointer(GLuint index, const VertexAttribute& topology) + void AbstractObject::RegisterVertexAttribPointer(GLuint index, const VertexAttribute& topology) { glVertexAttribPointer(topology.index, topology.size, topology.type, topology.normalized, topology.stride, topology.pointer); glEnableVertexAttribArray(index); diff --git a/src/shader.cpp b/src/shader.cpp index ad77699..44281a6 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -15,10 +15,10 @@ namespace oglu } - std::shared_ptr MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile) + Shader MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile) { AbstractShader* tmp = new AbstractShader(vertexShaderFile, fragmentShaderFile); - return std::shared_ptr(tmp); + return Shader(tmp); } AbstractShader::AbstractShader(const char* vertexShaderFile, const char* fragmentShaderFile) :