1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Also remove all OpenGL specific custom rendering stuff.

This commit is contained in:
Gordon McCann 2022-02-24 18:20:29 -05:00
parent f48a0207a8
commit eb19c8a603
7 changed files with 1 additions and 206 deletions

View File

@ -1,52 +0,0 @@
#include "OpenGLBuffer.h"
#include "glad/glad.h"
namespace Navigator {
OpenGLVertexBuffer::OpenGLVertexBuffer(size_t size, float* arr)
{
glCreateBuffers(1, &m_renderID);
glBindBuffer(GL_ARRAY_BUFFER, m_renderID);
glBufferData(GL_ARRAY_BUFFER, size, arr, GL_STATIC_DRAW);
}
OpenGLVertexBuffer::~OpenGLVertexBuffer()
{
glDeleteBuffers(1, &m_renderID);
}
void OpenGLVertexBuffer::Bind() const
{
glBindBuffer(GL_ARRAY_BUFFER, m_renderID);
}
void OpenGLVertexBuffer::Unbind() const
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t count, uint32_t* arr) :
m_count(count)
{
glCreateBuffers(1, &m_renderID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_renderID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_count * sizeof(uint32_t), arr, GL_STATIC_DRAW);
}
OpenGLIndexBuffer::~OpenGLIndexBuffer()
{
glDeleteBuffers(1, &m_renderID);
}
void OpenGLIndexBuffer::Bind() const
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_renderID);
}
void OpenGLIndexBuffer::Unbind() const
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
}

View File

@ -1,40 +0,0 @@
#ifndef OPENGL_BUFFER_H
#define OPENGL_BUFFER_H
#include "Navigator/Renderer/Buffer.h"
namespace Navigator {
class NAV_API OpenGLVertexBuffer : public VertexBuffer
{
public:
OpenGLVertexBuffer(size_t size, float* arr);
~OpenGLVertexBuffer();
virtual void Bind() const override;
virtual void Unbind() const override;
virtual void SetLayout(const BufferLayout& layout) override { m_layout = layout; }
virtual const BufferLayout& GetLayout() const override { return m_layout; }
private:
uint32_t m_renderID;
BufferLayout m_layout;
};
class NAV_API OpenGLIndexBuffer : public IndexBuffer
{
public:
OpenGLIndexBuffer(uint32_t count, uint32_t* arr);
~OpenGLIndexBuffer();
virtual void Bind() const override;
virtual void Unbind() const override;
virtual uint32_t GetCount() const override { return m_count; }
private:
uint32_t m_renderID;
uint32_t m_count;
};
}
#endif

View File

@ -13,9 +13,4 @@ namespace Navigator {
{ {
glClearColor(color_array[0], color_array[1], color_array[2], color_array[3]); glClearColor(color_array[0], color_array[1], color_array[2], color_array[3]);
} }
void OpenGLRendererAPI::DrawIndexed(const std::shared_ptr<VertexArray>& array)
{
glDrawElements(GL_TRIANGLES, array->GetIndexBuffer()->GetCount(), GL_UNSIGNED_INT, nullptr);
}
} }

View File

@ -11,7 +11,6 @@ namespace Navigator {
public: public:
virtual void Clear() override; virtual void Clear() override;
virtual void SetClearColor(const glm::vec4& color_array) override; virtual void SetClearColor(const glm::vec4& color_array) override;
virtual void DrawIndexed(const std::shared_ptr<VertexArray>& array) override;
}; };
} }

View File

@ -1,76 +0,0 @@
#include "OpenGLVertexArray.h"
#include "glad/glad.h"
namespace Navigator {
static GLenum ConvertShaderDataTypeToGLenum(ShaderDataType type)
{
switch (type)
{
case Navigator::ShaderDataType::Float: return GL_FLOAT;
case Navigator::ShaderDataType::Float2: return GL_FLOAT;
case Navigator::ShaderDataType::Float3: return GL_FLOAT;
case Navigator::ShaderDataType::Float4: return GL_FLOAT;
case Navigator::ShaderDataType::Int: return GL_INT;
case Navigator::ShaderDataType::Int2: return GL_INT;
case Navigator::ShaderDataType::Int3: return GL_INT;
case Navigator::ShaderDataType::Int4: return GL_INT;
case Navigator::ShaderDataType::Mat3: return GL_FLOAT;
case Navigator::ShaderDataType::Mat4: return GL_FLOAT;
case Navigator::ShaderDataType::Bool: return GL_BOOL;
}
NAV_ERROR("Unrecognized ShaderDataType at ConvertShaderDataTypeToGLenum!");
return 0;
}
OpenGLVertexArray::OpenGLVertexArray()
{
glCreateVertexArrays(1, &m_rendererID);
}
OpenGLVertexArray::~OpenGLVertexArray()
{
glDeleteVertexArrays(1, &m_rendererID);
}
void OpenGLVertexArray::Bind() const
{
glBindVertexArray(m_rendererID);
}
void OpenGLVertexArray::Unbind() const
{
glBindVertexArray(0);
}
void OpenGLVertexArray::AddVertexBuffer(const std::shared_ptr<VertexBuffer>& buffer)
{
if(buffer->GetLayout().GetElements().size() == 0)
NAV_ERROR("VertexBuffer with no layout passed to VertexArray::AddVertexBuffer!");
glBindVertexArray(m_rendererID);
buffer->Bind();
uint32_t index = 0;
const auto& layout = buffer->GetLayout();
for (const auto& element : layout)
{
glEnableVertexAttribArray(index);
glVertexAttribPointer(index, element.GetComponentCount(), ConvertShaderDataTypeToGLenum(element.type), element.normalized ? GL_TRUE : GL_FALSE, layout.GetStride(), (const void*)element.offset);
index++;
}
m_vertexBuffers.push_back(buffer);
}
void OpenGLVertexArray::SetIndexBuffer(const std::shared_ptr<IndexBuffer>& buffer)
{
glBindVertexArray(m_rendererID);
buffer->Bind();
m_indexBuffer = buffer;
}
}

View File

@ -1,31 +0,0 @@
#ifndef OPENGL_VERTEX_ARRAY
#define OPENGL_VERTEX_ARRAY
#include "Navigator/Renderer/VertexArray.h"
namespace Navigator {
class NAV_API OpenGLVertexArray : public VertexArray
{
public:
OpenGLVertexArray();
virtual ~OpenGLVertexArray();
virtual void Bind() const override;
virtual void Unbind() const override;
virtual void AddVertexBuffer(const std::shared_ptr<VertexBuffer>& buffer) override;
virtual void SetIndexBuffer(const std::shared_ptr<IndexBuffer>& buffer) override;
inline virtual const std::vector<std::shared_ptr<VertexBuffer>>& GetVertexBuffers() const override { return m_vertexBuffers; }
inline virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const { return m_indexBuffer; }
private:
std::vector<std::shared_ptr<VertexBuffer>> m_vertexBuffers;
std::shared_ptr<IndexBuffer> m_indexBuffer;
uint32_t m_rendererID;
};
}
#endif

View File

@ -126,7 +126,7 @@ namespace Navigator {
glfwSetScrollCallback(m_window, [](GLFWwindow* window, double xoffset, double yoffset) glfwSetScrollCallback(m_window, [](GLFWwindow* window, double xoffset, double yoffset)
{ {
Data& data = *(Data*) glfwGetWindowUserPointer(window); Data& data = *(Data*) glfwGetWindowUserPointer(window);
MouseScrolledEvent event(xoffset, yoffset); MouseScrolledEvent event((float)xoffset, (float)yoffset);
data.event_callback_func(event); data.event_callback_func(event);
}); });