mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-26 12:18:51 -05:00
Updated rendering pipeline so that, eventually, there will be full functionality. Not actively used
This commit is contained in:
parent
fe775ceb77
commit
1f7e1a49ae
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -11,3 +11,6 @@
|
||||||
[submodule "Navigator/vendor/glfw"]
|
[submodule "Navigator/vendor/glfw"]
|
||||||
path = Navigator/vendor/glfw
|
path = Navigator/vendor/glfw
|
||||||
url = https://github.com/gwm17/glfw.git
|
url = https://github.com/gwm17/glfw.git
|
||||||
|
[submodule "Navigator/vendor/glm"]
|
||||||
|
path = Navigator/vendor/glm
|
||||||
|
url = https://github.com/g-truc/glm.git
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "Navigator/ImGui/ImGuiLayer.h"
|
#include "Navigator/ImGui/ImGuiLayer.h"
|
||||||
#include "Navigator/Physics/PhysicsLayer.h"
|
#include "Navigator/Physics/PhysicsLayer.h"
|
||||||
#include "Navigator/HistogramMap.h"
|
#include "Navigator/HistogramMap.h"
|
||||||
|
#include "glm/vec4.hpp"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ namespace Navigator {
|
||||||
PhysicsLayer* m_physicsLayer;
|
PhysicsLayer* m_physicsLayer;
|
||||||
bool m_runFlag;
|
bool m_runFlag;
|
||||||
|
|
||||||
float m_bckgnd_color[4] = {0.1, 0.1, 0.1, 1.0};
|
glm::vec4 m_bckgnd_color = {0.1f, 0.1f, 0.1f, 1.0f};
|
||||||
|
|
||||||
static Application* s_instance;
|
static Application* s_instance;
|
||||||
};
|
};
|
||||||
|
|
40
Navigator/src/Navigator/Renderer/Buffer.cpp
Normal file
40
Navigator/src/Navigator/Renderer/Buffer.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include "Buffer.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include "RendererAPI.h"
|
||||||
|
#include "Platform/OpenGL/OpenGLBuffer.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
VertexBuffer* VertexBuffer::Create(size_t size, float* arr)
|
||||||
|
{
|
||||||
|
switch (Renderer::GetAPI())
|
||||||
|
{
|
||||||
|
case RendererAPI::API::OpenGL:
|
||||||
|
return new OpenGLVertexBuffer(size, arr);
|
||||||
|
return nullptr;
|
||||||
|
case RendererAPI::API::None:
|
||||||
|
NAV_ERROR("RendererAPI::None is not currently supported for VertexBuffer. Returning nullptr.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
NAV_ERROR("Invalid RendererAPI at VertexBuffer::Create(). Returning nullptr.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexBuffer* IndexBuffer::Create(uint32_t count, uint32_t* arr)
|
||||||
|
{
|
||||||
|
switch (Renderer::GetAPI())
|
||||||
|
{
|
||||||
|
case RendererAPI::API::OpenGL:
|
||||||
|
return new OpenGLIndexBuffer(count, arr);
|
||||||
|
return nullptr;
|
||||||
|
case RendererAPI::API::None:
|
||||||
|
NAV_ERROR("RendererAPI::None is not currently supported for IndexBuffer. Returning nullptr.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
NAV_ERROR("Invalid RendererAPI at IndexBuffer::Create(). Returning nullptr.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
149
Navigator/src/Navigator/Renderer/Buffer.h
Normal file
149
Navigator/src/Navigator/Renderer/Buffer.h
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
#ifndef BUFFER_H
|
||||||
|
#define BUFFER_H
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
NAV_API enum class ShaderDataType {
|
||||||
|
None,
|
||||||
|
Float, Float2, Float3, Float4,
|
||||||
|
Int, Int2, Int3, Int4,
|
||||||
|
Mat3, Mat4,
|
||||||
|
Bool
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint32_t GetShaderDataTypeSize(ShaderDataType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ShaderDataType::None:
|
||||||
|
{
|
||||||
|
NAV_ERROR("ShaderDataType::None is not supported for GetShaderDataTypeSizes");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case ShaderDataType::Float:
|
||||||
|
return 4;
|
||||||
|
case ShaderDataType::Float2:
|
||||||
|
return 4 * 2;
|
||||||
|
case ShaderDataType::Float3:
|
||||||
|
return 4 * 3;
|
||||||
|
case ShaderDataType::Float4:
|
||||||
|
return 4 * 4;
|
||||||
|
case ShaderDataType::Int:
|
||||||
|
return 4;
|
||||||
|
case ShaderDataType::Int2:
|
||||||
|
return 4 * 2;
|
||||||
|
case ShaderDataType::Int3:
|
||||||
|
return 4 * 3;
|
||||||
|
case ShaderDataType::Int4:
|
||||||
|
return 4 * 4;
|
||||||
|
case ShaderDataType::Mat3:
|
||||||
|
return 4 * 3 * 3;
|
||||||
|
case ShaderDataType::Mat4:
|
||||||
|
return 4 * 4 * 4;
|
||||||
|
case ShaderDataType::Bool:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
NAV_ERROR("Unrecognized ShaderDataType at GetShaderDataTypeSize!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct NAV_API BufferElement
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
ShaderDataType type;
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t offset;
|
||||||
|
bool normalized;
|
||||||
|
|
||||||
|
BufferElement() {}
|
||||||
|
BufferElement(ShaderDataType itype, const std::string& iname, bool norm = false) :
|
||||||
|
name(iname), type(itype), size(GetShaderDataTypeSize(itype)), offset(0), normalized(norm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t GetComponentCount() const
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ShaderDataType::Float: return 1;
|
||||||
|
case ShaderDataType::Float2: return 2;
|
||||||
|
case ShaderDataType::Float3: return 3;
|
||||||
|
case ShaderDataType::Float4: return 4;
|
||||||
|
case ShaderDataType::Int: return 1;
|
||||||
|
case ShaderDataType::Int2: return 2;
|
||||||
|
case ShaderDataType::Int3: return 3;
|
||||||
|
case ShaderDataType::Int4: return 4;
|
||||||
|
case ShaderDataType::Mat3: return 9;
|
||||||
|
case ShaderDataType::Mat4: return 16;
|
||||||
|
case ShaderDataType::Bool: return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
NAV_ERROR("Unrecognized ShaderDataType at BufferElement::GetComponentCount!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class NAV_API BufferLayout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
BufferLayout() {}
|
||||||
|
BufferLayout(const std::initializer_list<BufferElement>& elements) :
|
||||||
|
m_elements(elements)
|
||||||
|
{
|
||||||
|
CalculateOffsetsAndStride();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const std::vector<BufferElement>& GetElements() const { return m_elements; }
|
||||||
|
inline const uint32_t GetStride() const { return m_stride; }
|
||||||
|
|
||||||
|
std::vector<BufferElement>::iterator begin() { return m_elements.begin(); };
|
||||||
|
std::vector<BufferElement>::iterator end() { return m_elements.end(); };
|
||||||
|
std::vector<BufferElement>::const_iterator begin() const { return m_elements.begin(); };
|
||||||
|
std::vector<BufferElement>::const_iterator end() const { return m_elements.end(); };
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CalculateOffsetsAndStride()
|
||||||
|
{
|
||||||
|
uint32_t offset = 0;
|
||||||
|
for (auto& element : m_elements)
|
||||||
|
{
|
||||||
|
element.offset = offset;
|
||||||
|
offset += element.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_stride = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<BufferElement> m_elements;
|
||||||
|
uint32_t m_stride;
|
||||||
|
};
|
||||||
|
|
||||||
|
class NAV_API VertexBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~VertexBuffer() {};
|
||||||
|
virtual void Bind() const = 0;
|
||||||
|
virtual void Unbind() const = 0;
|
||||||
|
|
||||||
|
virtual void SetLayout(const BufferLayout& layout) = 0;
|
||||||
|
virtual const BufferLayout& GetLayout() const = 0;
|
||||||
|
|
||||||
|
static VertexBuffer* Create(size_t size, float* arr);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class NAV_API IndexBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IndexBuffer() {};
|
||||||
|
virtual void Bind() const = 0;
|
||||||
|
virtual void Unbind() const = 0;
|
||||||
|
virtual uint32_t GetCount() const = 0;
|
||||||
|
|
||||||
|
static IndexBuffer* Create(uint32_t count, uint32_t* arr);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
23
Navigator/src/Navigator/Renderer/OrthographicCamera.cpp
Normal file
23
Navigator/src/Navigator/Renderer/OrthographicCamera.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "OrthographicCamera.h"
|
||||||
|
|
||||||
|
#include "glm/gtc/matrix_transform.hpp"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
OrthographicCamera::OrthographicCamera(float left, float right, float bottom, float top) :
|
||||||
|
m_projectionMatrix(glm::ortho(left, right, bottom, top, -1.0f, 1.0f)), m_viewMatrix(1.0f), m_viewProjectionMatrix(1.0f), m_position(0.0f, 0.0f, 0.0f), m_polarRot(0.0f)
|
||||||
|
{
|
||||||
|
m_viewProjectionMatrix = m_projectionMatrix * m_viewMatrix; //OpenGL orderer is proj*view, dx is view*proj
|
||||||
|
}
|
||||||
|
|
||||||
|
void OrthographicCamera::RecalculateViewMatrix()
|
||||||
|
{
|
||||||
|
glm::mat4 transform_matrix = glm::translate(glm::mat4(1.0f), m_position); //translate
|
||||||
|
transform_matrix = glm::rotate(transform_matrix, glm::radians(m_polarRot), glm::vec3(0.0f, 0.0f, 1.0f)); //then rotate
|
||||||
|
|
||||||
|
m_viewMatrix = glm::inverse(transform_matrix); //view is the inverse of the transform to the camera
|
||||||
|
|
||||||
|
m_viewProjectionMatrix = m_projectionMatrix * m_viewMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
Navigator/src/Navigator/Renderer/OrthographicCamera.h
Normal file
32
Navigator/src/Navigator/Renderer/OrthographicCamera.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef ORTHOGRAPHIC_CAMERA_H
|
||||||
|
#define ORTHOGRAPHIC_CAMERA_H
|
||||||
|
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class OrthographicCamera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OrthographicCamera(float left, float right, float bottom, float top);
|
||||||
|
inline void SetPosition(const glm::vec3& coords) { m_position = coords; RecalculateViewMatrix(); }
|
||||||
|
inline const glm::vec3& GetPosition() const { return m_position; }
|
||||||
|
inline void SetPolarRotation(float degrees) { m_polarRot = degrees; RecalculateViewMatrix(); }
|
||||||
|
inline float GetRotation() const { return m_polarRot; }
|
||||||
|
inline const glm::mat4& GetProjectionMatrix() const { return m_projectionMatrix; }
|
||||||
|
inline const glm::mat4& GetViewMatrix() const { return m_viewMatrix; }
|
||||||
|
inline const glm::mat4& GetViewProjectionMatrix() const { return m_viewProjectionMatrix; }
|
||||||
|
private:
|
||||||
|
void RecalculateViewMatrix();
|
||||||
|
|
||||||
|
glm::mat4 m_projectionMatrix;
|
||||||
|
glm::mat4 m_viewMatrix;
|
||||||
|
glm::mat4 m_viewProjectionMatrix;
|
||||||
|
|
||||||
|
glm::vec3 m_position;
|
||||||
|
float m_polarRot;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,8 +9,9 @@ namespace Navigator {
|
||||||
class NAV_API RenderCommand
|
class NAV_API RenderCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline static void SetClearColor(const float* color_array) { s_api->SetClearColor(color_array); }
|
inline static void SetClearColor(const glm::vec4& color_array) { s_api->SetClearColor(color_array); }
|
||||||
inline static void Clear() { s_api->Clear(); }
|
inline static void Clear() { s_api->Clear(); }
|
||||||
|
inline static void DrawIndexed(const std::shared_ptr<VertexArray>& array) { s_api->DrawIndexed(array); }
|
||||||
private:
|
private:
|
||||||
static RendererAPI* s_api;
|
static RendererAPI* s_api;
|
||||||
};
|
};
|
||||||
|
|
16
Navigator/src/Navigator/Renderer/Renderer.cpp
Normal file
16
Navigator/src/Navigator/Renderer/Renderer.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "Renderer.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
|
||||||
|
void Renderer::BeginScene() {}
|
||||||
|
|
||||||
|
void Renderer::EndScene() {}
|
||||||
|
|
||||||
|
void Renderer::Submit(const std::shared_ptr<Shader>& shader, const std::shared_ptr<VertexArray>& data)
|
||||||
|
{
|
||||||
|
shader->Bind();
|
||||||
|
data->Bind();
|
||||||
|
RenderCommand::DrawIndexed(data);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@
|
||||||
#include "Navigator/NavCore.h"
|
#include "Navigator/NavCore.h"
|
||||||
#include "RendererAPI.h"
|
#include "RendererAPI.h"
|
||||||
#include "RenderCommand.h"
|
#include "RenderCommand.h"
|
||||||
|
#include "Shader.h"
|
||||||
|
#include "VertexArray.h"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
@ -11,6 +13,10 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static void BeginScene();
|
||||||
|
static void EndScene();
|
||||||
|
static void Submit(const std::shared_ptr<Shader>& shader, const std::shared_ptr<VertexArray>& data);
|
||||||
|
|
||||||
static inline RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); }
|
static inline RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#define RENDERER_API_H
|
#define RENDERER_API_H
|
||||||
|
|
||||||
#include "Navigator/NavCore.h"
|
#include "Navigator/NavCore.h"
|
||||||
|
#include "VertexArray.h"
|
||||||
|
#include "glm/vec4.hpp"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
@ -15,7 +17,8 @@ namespace Navigator {
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void Clear() = 0;
|
virtual void Clear() = 0;
|
||||||
virtual void SetClearColor(const float* color_array) = 0;
|
virtual void SetClearColor(const glm::vec4& color) = 0;
|
||||||
|
virtual void DrawIndexed(const std::shared_ptr<VertexArray>& array) = 0;
|
||||||
|
|
||||||
inline static API GetAPI() { return s_api; }
|
inline static API GetAPI() { return s_api; }
|
||||||
|
|
||||||
|
|
133
Navigator/src/Navigator/Renderer/Shader.cpp
Normal file
133
Navigator/src/Navigator/Renderer/Shader.cpp
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
#include "Shader.h"
|
||||||
|
#include "glad/glad.h"
|
||||||
|
#include "glm/gtc/type_ptr.hpp"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
Shader::Shader(const std::string& vertexSource, const std::string& fragmentSource)
|
||||||
|
{
|
||||||
|
// Create an empty vertex shader handle
|
||||||
|
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
|
||||||
|
// Send the vertex shader source code to GL
|
||||||
|
// Note that std::string's .c_str is NULL character terminated.
|
||||||
|
const GLchar* source = (const GLchar*)vertexSource.c_str();
|
||||||
|
glShaderSource(vertexShader, 1, &source, 0);
|
||||||
|
|
||||||
|
// Compile the vertex shader
|
||||||
|
glCompileShader(vertexShader);
|
||||||
|
|
||||||
|
GLint isCompiled = 0;
|
||||||
|
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &isCompiled);
|
||||||
|
if (isCompiled == GL_FALSE)
|
||||||
|
{
|
||||||
|
GLint maxLength = 0;
|
||||||
|
glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &maxLength);
|
||||||
|
|
||||||
|
// The maxLength includes the NULL character
|
||||||
|
std::vector<GLchar> infoLog(maxLength);
|
||||||
|
glGetShaderInfoLog(vertexShader, maxLength, &maxLength, &infoLog[0]);
|
||||||
|
|
||||||
|
// We don't need the shader anymore.
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
|
||||||
|
// Use the infoLog as you see fit.
|
||||||
|
NAV_ERROR("Shader InfoLog: {0}", infoLog.data());
|
||||||
|
NAV_ERROR("OpenGL Vertex Shader compilation error!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an empty fragment shader handle
|
||||||
|
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
// Send the fragment shader source code to GL
|
||||||
|
// Note that std::string's .c_str is NULL character terminated.
|
||||||
|
source = (const GLchar*)fragmentSource.c_str();
|
||||||
|
glShaderSource(fragmentShader, 1, &source, 0);
|
||||||
|
|
||||||
|
// Compile the fragment shader
|
||||||
|
glCompileShader(fragmentShader);
|
||||||
|
|
||||||
|
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &isCompiled);
|
||||||
|
if (isCompiled == GL_FALSE)
|
||||||
|
{
|
||||||
|
GLint maxLength = 0;
|
||||||
|
glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &maxLength);
|
||||||
|
|
||||||
|
// The maxLength includes the NULL character
|
||||||
|
std::vector<GLchar> infoLog(maxLength);
|
||||||
|
glGetShaderInfoLog(fragmentShader, maxLength, &maxLength, &infoLog[0]);
|
||||||
|
|
||||||
|
// We don't need the shader anymore.
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
|
// Either of them. Don't leak shaders.
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
|
||||||
|
// Use the infoLog as you see fit.
|
||||||
|
NAV_ERROR("Shader InfoLog: {0}", infoLog.data());
|
||||||
|
NAV_ERROR("OpenGL Fragment Shader compilation error!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vertex and fragment shaders are successfully compiled.
|
||||||
|
// Now time to link them together into a program.
|
||||||
|
// Get a program object.
|
||||||
|
m_renderID = glCreateProgram();
|
||||||
|
|
||||||
|
// Attach our shaders to our program
|
||||||
|
glAttachShader(m_renderID, vertexShader);
|
||||||
|
glAttachShader(m_renderID, fragmentShader);
|
||||||
|
|
||||||
|
// Link our program
|
||||||
|
glLinkProgram(m_renderID);
|
||||||
|
|
||||||
|
// Note the different functions here: glGetProgram* instead of glGetShader*.
|
||||||
|
GLint isLinked = 0;
|
||||||
|
glGetProgramiv(m_renderID, GL_LINK_STATUS, (int*)&isLinked);
|
||||||
|
if (isLinked == GL_FALSE)
|
||||||
|
{
|
||||||
|
GLint maxLength = 0;
|
||||||
|
glGetProgramiv(m_renderID, GL_INFO_LOG_LENGTH, &maxLength);
|
||||||
|
|
||||||
|
// The maxLength includes the NULL character
|
||||||
|
std::vector<GLchar> infoLog(maxLength);
|
||||||
|
glGetProgramInfoLog(m_renderID, maxLength, &maxLength, &infoLog[0]);
|
||||||
|
|
||||||
|
// We don't need the program anymore.
|
||||||
|
glDeleteProgram(m_renderID);
|
||||||
|
// Don't leak shaders either.
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
|
|
||||||
|
// Use the infoLog as you see fit.
|
||||||
|
NAV_ERROR("Program InfoLog: {0}", infoLog.data());
|
||||||
|
NAV_ERROR("OpenGL Shader link error!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always detach shaders after a successful link.
|
||||||
|
glDetachShader(m_renderID, vertexShader);
|
||||||
|
glDetachShader(m_renderID, fragmentShader);
|
||||||
|
}
|
||||||
|
|
||||||
|
Shader::~Shader()
|
||||||
|
{
|
||||||
|
glDeleteProgram(m_renderID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::Bind() const
|
||||||
|
{
|
||||||
|
glUseProgram(m_renderID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::Unbind() const
|
||||||
|
{
|
||||||
|
glUseProgram(0);
|
||||||
|
}
|
||||||
|
void Shader::UploadUniformMat4(const std::string& name, const glm::mat4& matrix)
|
||||||
|
{
|
||||||
|
auto loc = glGetUniformLocation(m_renderID, name.c_str());
|
||||||
|
glUniformMatrix4fv(loc, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
Navigator/src/Navigator/Renderer/Shader.h
Normal file
25
Navigator/src/Navigator/Renderer/Shader.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef SHADER_H
|
||||||
|
#define SHADER_H
|
||||||
|
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class NAV_API Shader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Shader(const std::string& vertexSource, const std::string& fragmentSource);
|
||||||
|
~Shader();
|
||||||
|
|
||||||
|
void Bind() const;
|
||||||
|
void Unbind() const;
|
||||||
|
|
||||||
|
void UploadUniformMat4(const std::string& name, const glm::mat4& matrix);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t m_renderID;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
20
Navigator/src/Navigator/Renderer/VertexArray.cpp
Normal file
20
Navigator/src/Navigator/Renderer/VertexArray.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "VertexArray.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include "Platform/OpenGL/OpenGLVertexArray.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
VertexArray* VertexArray::Create()
|
||||||
|
{
|
||||||
|
switch (Renderer::GetAPI())
|
||||||
|
{
|
||||||
|
case RendererAPI::API::OpenGL:
|
||||||
|
return new OpenGLVertexArray();
|
||||||
|
case RendererAPI::API::None:
|
||||||
|
NAV_ERROR("RendererAPI::None is not currently supported for IndexBuffer. Returning nullptr.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
NAV_ERROR("Invalid RendererAPI at VertexArray::Create!");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
27
Navigator/src/Navigator/Renderer/VertexArray.h
Normal file
27
Navigator/src/Navigator/Renderer/VertexArray.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef VERTEX_ARRAY_H
|
||||||
|
#define VERTEX_ARRAY_H
|
||||||
|
|
||||||
|
#include "Buffer.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class NAV_API VertexArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~VertexArray() {};
|
||||||
|
|
||||||
|
virtual void Bind() const = 0;
|
||||||
|
virtual void Unbind() const = 0;
|
||||||
|
|
||||||
|
virtual void AddVertexBuffer(const std::shared_ptr<VertexBuffer>& buffer) = 0;
|
||||||
|
virtual void SetIndexBuffer(const std::shared_ptr<IndexBuffer>& buffer) = 0;
|
||||||
|
virtual const std::vector<std::shared_ptr<VertexBuffer>>& GetVertexBuffers() const = 0;
|
||||||
|
virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const = 0;
|
||||||
|
|
||||||
|
static VertexArray* Create();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
52
Navigator/src/Platform/OpenGL/OpenGLBuffer.cpp
Normal file
52
Navigator/src/Platform/OpenGL/OpenGLBuffer.cpp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
Navigator/src/Platform/OpenGL/OpenGLBuffer.h
Normal file
40
Navigator/src/Platform/OpenGL/OpenGLBuffer.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#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
|
|
@ -2,7 +2,7 @@
|
||||||
#define OPEGL_CONTEXT_H
|
#define OPEGL_CONTEXT_H
|
||||||
|
|
||||||
#include "Navigator/NavCore.h"
|
#include "Navigator/NavCore.h"
|
||||||
#include "Navigator/GraphicsContext.h"
|
#include "Navigator/Renderer/GraphicsContext.h"
|
||||||
|
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,13 @@ namespace Navigator {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLRendererAPI::SetClearColor(const float* color_array)
|
void OpenGLRendererAPI::SetClearColor(const glm::vec4& color_array)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -10,7 +10,8 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void Clear() override;
|
virtual void Clear() override;
|
||||||
virtual void SetClearColor(const float* color_array) override;
|
virtual void SetClearColor(const glm::vec4& color_array) override;
|
||||||
|
virtual void DrawIndexed(const std::shared_ptr<VertexArray>& array) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
76
Navigator/src/Platform/OpenGL/OpenGLVertexArray.cpp
Normal file
76
Navigator/src/Platform/OpenGL/OpenGLVertexArray.cpp
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
Navigator/src/Platform/OpenGL/OpenGLVertexArray.h
Normal file
31
Navigator/src/Platform/OpenGL/OpenGLVertexArray.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#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
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "Navigator/NavCore.h"
|
#include "Navigator/NavCore.h"
|
||||||
#include "Navigator/Window.h"
|
#include "Navigator/Window.h"
|
||||||
#include "Navigator/GraphicsContext.h"
|
#include "Navigator/Renderer/GraphicsContext.h"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
1
Navigator/vendor/glm
vendored
Submodule
1
Navigator/vendor/glm
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 6ad79aae3eb5bf809c30bf1168171e9e55857e45
|
14
premake5.lua
14
premake5.lua
|
@ -15,6 +15,7 @@ IncludeDirs["glfw"] = "Navigator/vendor/glfw/include"
|
||||||
IncludeDirs["ImGui"] = "Navigator/vendor/imgui"
|
IncludeDirs["ImGui"] = "Navigator/vendor/imgui"
|
||||||
IncludeDirs["glad"] = "Navigator/vendor/glad/include"
|
IncludeDirs["glad"] = "Navigator/vendor/glad/include"
|
||||||
IncludeDirs["ImPlot"] = "Navigator/vendor/implot"
|
IncludeDirs["ImPlot"] = "Navigator/vendor/implot"
|
||||||
|
IncludeDirs["glm"] = "Navigator/vendor/glm"
|
||||||
|
|
||||||
include "Navigator/vendor/glfw"
|
include "Navigator/vendor/glfw"
|
||||||
include "Navigator/vendor/imgui"
|
include "Navigator/vendor/imgui"
|
||||||
|
@ -42,7 +43,8 @@ project "Navigator"
|
||||||
"%{IncludeDirs.glfw}",
|
"%{IncludeDirs.glfw}",
|
||||||
"%{IncludeDirs.ImGui}",
|
"%{IncludeDirs.ImGui}",
|
||||||
"%{IncludeDirs.glad}",
|
"%{IncludeDirs.glad}",
|
||||||
"%{IncludeDirs.ImPlot}"
|
"%{IncludeDirs.ImPlot}",
|
||||||
|
"%{IncludeDirs.glm}"
|
||||||
}
|
}
|
||||||
filter {}
|
filter {}
|
||||||
|
|
||||||
|
@ -52,7 +54,8 @@ project "Navigator"
|
||||||
"%{IncludeDirs.glfw}",
|
"%{IncludeDirs.glfw}",
|
||||||
"%{IncludeDirs.ImGui}",
|
"%{IncludeDirs.ImGui}",
|
||||||
"%{IncludeDirs.glad}",
|
"%{IncludeDirs.glad}",
|
||||||
"%{IncludeDirs.ImPlot}"
|
"%{IncludeDirs.ImPlot}",
|
||||||
|
"%{IncludeDirs.glm}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,7 +144,9 @@ project "NavProject"
|
||||||
"Navigator/src/Navigator",
|
"Navigator/src/Navigator",
|
||||||
"Navigator/vendor/spdlog/include/",
|
"Navigator/vendor/spdlog/include/",
|
||||||
"Navigator/vendor/implot/",
|
"Navigator/vendor/implot/",
|
||||||
"Navigator/vendor"
|
"Navigator/vendor",
|
||||||
|
"%{IncludeDirs.glm}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
links {
|
links {
|
||||||
|
@ -158,7 +163,8 @@ project "NavProject"
|
||||||
"%{IncludeDirs.glfw}",
|
"%{IncludeDirs.glfw}",
|
||||||
"%{IncludeDirs.ImGui}",
|
"%{IncludeDirs.ImGui}",
|
||||||
"%{IncludeDirs.glad}",
|
"%{IncludeDirs.glad}",
|
||||||
"%{IncludeDirs.ImPlot}"
|
"%{IncludeDirs.ImPlot}",
|
||||||
|
"%{IncludeDirs.glm}"
|
||||||
}
|
}
|
||||||
filter "system:windows"
|
filter "system:windows"
|
||||||
defines "NAV_WINDOWS"
|
defines "NAV_WINDOWS"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user