1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-23 02:38:52 -05:00

Removed unused rendering code. Thanks to the awesome power of ImPlot and ImGui, it will likely never need a full custom render pipeline for any practical reason

This commit is contained in:
Gordon McCann 2022-02-24 18:19:32 -05:00
parent d1f58464b4
commit f48a0207a8
14 changed files with 1 additions and 500 deletions

View File

@ -25,6 +25,5 @@
#include "Navigator/SpectrumManager.h" #include "Navigator/SpectrumManager.h"
#include "Navigator/Layer.h" #include "Navigator/Layer.h"
#include "Navigator/Events/Event.h" #include "Navigator/Events/Event.h"
#include "Navigator/Renderer/Renderer.h"
#endif #endif

View File

@ -1,5 +1,4 @@
#include "Application.h" #include "Application.h"
#include "Renderer/Renderer.h"
#include "Renderer/RenderCommand.h" #include "Renderer/RenderCommand.h"
#include "Editor/EditorLayer.h" #include "Editor/EditorLayer.h"
@ -74,11 +73,6 @@ namespace Navigator {
layer->OnImGuiRender(); layer->OnImGuiRender();
m_imgui_layer->End(); m_imgui_layer->End();
m_window->OnUpdate(); m_window->OnUpdate();
/* For debugging
ParameterMap::GetInstance().find("joseph")->second->validFlag = true;
ParameterMap::GetInstance().find("joseph")->second->value = 8.0;
*/
} }
} }
} }

View File

@ -1,40 +0,0 @@
#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;
}
}

View File

@ -1,149 +0,0 @@
#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

View File

@ -1,23 +0,0 @@
#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;
}
}

View File

@ -1,32 +0,0 @@
#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

View File

@ -11,7 +11,7 @@ namespace Navigator {
public: public:
inline static void SetClearColor(const glm::vec4& 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;
}; };

View File

@ -1,16 +0,0 @@
#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);
}
}

View File

@ -1,25 +0,0 @@
#ifndef RENDERER_H
#define RENDERER_H
#include "Navigator/NavCore.h"
#include "RendererAPI.h"
#include "RenderCommand.h"
#include "Shader.h"
#include "VertexArray.h"
namespace Navigator {
class NAV_API Renderer
{
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(); }
};
}
#endif

View File

@ -2,7 +2,6 @@
#define RENDERER_API_H #define RENDERER_API_H
#include "Navigator/NavCore.h" #include "Navigator/NavCore.h"
#include "VertexArray.h"
#include "glm/vec4.hpp" #include "glm/vec4.hpp"
namespace Navigator { namespace Navigator {
@ -18,7 +17,6 @@ namespace Navigator {
virtual void Clear() = 0; virtual void Clear() = 0;
virtual void SetClearColor(const glm::vec4& color) = 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; }

View File

@ -1,133 +0,0 @@
#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));
}
}

View File

@ -1,25 +0,0 @@
#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

View File

@ -1,20 +0,0 @@
#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;
}
}

View File

@ -1,27 +0,0 @@
#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