Object now follows the behaviour of Shader
This commit is contained in:
parent
4fe91a12e2
commit
87b27eae70
|
@ -66,7 +66,7 @@ int main(int argc, char** argv)
|
||||||
return -1;
|
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))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
@ -76,7 +76,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
shader->SetUniform("ourColor", &oglu::Color::Transparent);
|
shader->SetUniform("ourColor", &oglu::Color::Transparent);
|
||||||
shader->Use();
|
shader->Use();
|
||||||
square.BindAndDraw();
|
square->BindAndDraw();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef COLOR_HPP
|
#ifndef COLOR_HPP
|
||||||
#define COLOR_HPP
|
#define COLOR_HPP
|
||||||
|
|
||||||
#include "core.hpp"
|
#include <core.hpp>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef CORE_HPP
|
#ifndef CORE_HPP
|
||||||
#define CORE_HPP
|
#define CORE_HPP
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#ifdef OGLU_WIN32
|
#ifdef OGLU_WIN32
|
||||||
#ifdef OGLU_BUILD_DLL
|
#ifdef OGLU_BUILD_DLL
|
||||||
#define OGLU_API __declspec(dllexport)
|
#define OGLU_API __declspec(dllexport)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef DRAWABLE_HPP
|
#ifndef DRAWABLE_HPP
|
||||||
#define DRAWABLE_HPP
|
#define DRAWABLE_HPP
|
||||||
|
|
||||||
#include "core.hpp"
|
#include <core.hpp>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
|
@ -15,11 +15,12 @@ namespace oglu
|
||||||
const GLvoid* pointer;
|
const GLvoid* pointer;
|
||||||
} VertexAttribute;
|
} VertexAttribute;
|
||||||
|
|
||||||
class OGLU_API Object
|
class OGLU_API AbstractObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Object();
|
AbstractObject(const AbstractObject& other);
|
||||||
Object(const GLfloat* vertices, size_t verticesSize, const GLuint* indices, size_t indicesSize, const VertexAttribute* topology, size_t topologySize);
|
|
||||||
|
friend std::shared_ptr<AbstractObject> 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; }
|
GLuint GetVAO() { return VAO; }
|
||||||
void Bind();
|
void Bind();
|
||||||
|
@ -29,11 +30,15 @@ namespace oglu
|
||||||
void BindAndDraw();
|
void BindAndDraw();
|
||||||
|
|
||||||
private:
|
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);
|
inline void RegisterVertexAttribPointer(GLuint index, const VertexAttribute& topology);
|
||||||
|
|
||||||
GLuint VAO;
|
GLuint VAO;
|
||||||
GLsizei count;
|
GLsizei count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::shared_ptr<AbstractObject> Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef SHADER_HPP
|
#ifndef SHADER_HPP
|
||||||
#define SHADER_HPP
|
#define SHADER_HPP
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <core.hpp>
|
#include <core.hpp>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,22 @@
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
{
|
{
|
||||||
Object::Object() :
|
AbstractObject::AbstractObject(const AbstractObject& other) :
|
||||||
VAO(0)
|
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 GLuint* indices, size_t indicesSize,
|
||||||
const VertexAttribute* topology, size_t topologySize) :
|
const VertexAttribute* topology, size_t topologySize) :
|
||||||
VAO(0)
|
VAO(0), count(0)
|
||||||
{
|
{
|
||||||
topologySize /= sizeof(VertexAttribute);
|
topologySize /= sizeof(VertexAttribute);
|
||||||
|
|
||||||
|
@ -39,29 +46,29 @@ namespace oglu
|
||||||
count = indicesSize / sizeof(GLuint);
|
count = indicesSize / sizeof(GLuint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::Bind()
|
void AbstractObject::Bind()
|
||||||
{
|
{
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::Unbind()
|
void AbstractObject::Unbind()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::Draw()
|
void AbstractObject::Draw()
|
||||||
{
|
{
|
||||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, (GLvoid*)0);
|
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, (GLvoid*)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Object::BindAndDraw()
|
void AbstractObject::BindAndDraw()
|
||||||
{
|
{
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, (GLvoid*)0);
|
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, (GLvoid*)0);
|
||||||
glBindVertexArray(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);
|
glVertexAttribPointer(topology.index, topology.size, topology.type, topology.normalized, topology.stride, topology.pointer);
|
||||||
glEnableVertexAttribArray(index);
|
glEnableVertexAttribArray(index);
|
||||||
|
|
|
@ -15,10 +15,10 @@ namespace oglu
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AbstractShader> MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile)
|
Shader MakeShader(const char* vertexShaderFile, const char* fragmentShaderFile)
|
||||||
{
|
{
|
||||||
AbstractShader* tmp = new AbstractShader(vertexShaderFile, fragmentShaderFile);
|
AbstractShader* tmp = new AbstractShader(vertexShaderFile, fragmentShaderFile);
|
||||||
return std::shared_ptr<AbstractShader>(tmp);
|
return Shader(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractShader::AbstractShader(const char* vertexShaderFile, const char* fragmentShaderFile) :
|
AbstractShader::AbstractShader(const char* vertexShaderFile, const char* fragmentShaderFile) :
|
||||||
|
|
Loading…
Reference in a new issue