From f48a0207a8d7fb663de3cf7e88788e02de651548 Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Thu, 24 Feb 2022 18:19:32 -0500 Subject: [PATCH] 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 --- Navigator/src/Navigator.h | 1 - Navigator/src/Navigator/Application.cpp | 6 - Navigator/src/Navigator/Renderer/Buffer.cpp | 40 ----- Navigator/src/Navigator/Renderer/Buffer.h | 149 ------------------ .../Navigator/Renderer/OrthographicCamera.cpp | 23 --- .../Navigator/Renderer/OrthographicCamera.h | 32 ---- .../src/Navigator/Renderer/RenderCommand.h | 2 +- Navigator/src/Navigator/Renderer/Renderer.cpp | 16 -- Navigator/src/Navigator/Renderer/Renderer.h | 25 --- .../src/Navigator/Renderer/RendererAPI.h | 2 - Navigator/src/Navigator/Renderer/Shader.cpp | 133 ---------------- Navigator/src/Navigator/Renderer/Shader.h | 25 --- .../src/Navigator/Renderer/VertexArray.cpp | 20 --- .../src/Navigator/Renderer/VertexArray.h | 27 ---- 14 files changed, 1 insertion(+), 500 deletions(-) delete mode 100644 Navigator/src/Navigator/Renderer/Buffer.cpp delete mode 100644 Navigator/src/Navigator/Renderer/Buffer.h delete mode 100644 Navigator/src/Navigator/Renderer/OrthographicCamera.cpp delete mode 100644 Navigator/src/Navigator/Renderer/OrthographicCamera.h delete mode 100644 Navigator/src/Navigator/Renderer/Renderer.cpp delete mode 100644 Navigator/src/Navigator/Renderer/Renderer.h delete mode 100644 Navigator/src/Navigator/Renderer/Shader.cpp delete mode 100644 Navigator/src/Navigator/Renderer/Shader.h delete mode 100644 Navigator/src/Navigator/Renderer/VertexArray.cpp delete mode 100644 Navigator/src/Navigator/Renderer/VertexArray.h diff --git a/Navigator/src/Navigator.h b/Navigator/src/Navigator.h index 8bf776d..90f413b 100644 --- a/Navigator/src/Navigator.h +++ b/Navigator/src/Navigator.h @@ -25,6 +25,5 @@ #include "Navigator/SpectrumManager.h" #include "Navigator/Layer.h" #include "Navigator/Events/Event.h" -#include "Navigator/Renderer/Renderer.h" #endif diff --git a/Navigator/src/Navigator/Application.cpp b/Navigator/src/Navigator/Application.cpp index d40b762..994a9e2 100644 --- a/Navigator/src/Navigator/Application.cpp +++ b/Navigator/src/Navigator/Application.cpp @@ -1,5 +1,4 @@ #include "Application.h" -#include "Renderer/Renderer.h" #include "Renderer/RenderCommand.h" #include "Editor/EditorLayer.h" @@ -74,11 +73,6 @@ namespace Navigator { layer->OnImGuiRender(); m_imgui_layer->End(); m_window->OnUpdate(); - - /* For debugging - ParameterMap::GetInstance().find("joseph")->second->validFlag = true; - ParameterMap::GetInstance().find("joseph")->second->value = 8.0; - */ } } } diff --git a/Navigator/src/Navigator/Renderer/Buffer.cpp b/Navigator/src/Navigator/Renderer/Buffer.cpp deleted file mode 100644 index 8e75281..0000000 --- a/Navigator/src/Navigator/Renderer/Buffer.cpp +++ /dev/null @@ -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; - } - -} \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/Buffer.h b/Navigator/src/Navigator/Renderer/Buffer.h deleted file mode 100644 index 395a86f..0000000 --- a/Navigator/src/Navigator/Renderer/Buffer.h +++ /dev/null @@ -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& elements) : - m_elements(elements) - { - CalculateOffsetsAndStride(); - } - - inline const std::vector& GetElements() const { return m_elements; } - inline const uint32_t GetStride() const { return m_stride; } - - std::vector::iterator begin() { return m_elements.begin(); }; - std::vector::iterator end() { return m_elements.end(); }; - std::vector::const_iterator begin() const { return m_elements.begin(); }; - std::vector::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 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 diff --git a/Navigator/src/Navigator/Renderer/OrthographicCamera.cpp b/Navigator/src/Navigator/Renderer/OrthographicCamera.cpp deleted file mode 100644 index 54b5b45..0000000 --- a/Navigator/src/Navigator/Renderer/OrthographicCamera.cpp +++ /dev/null @@ -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; - } - -} \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/OrthographicCamera.h b/Navigator/src/Navigator/Renderer/OrthographicCamera.h deleted file mode 100644 index 82b256c..0000000 --- a/Navigator/src/Navigator/Renderer/OrthographicCamera.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/RenderCommand.h b/Navigator/src/Navigator/Renderer/RenderCommand.h index e328519..40b63b3 100644 --- a/Navigator/src/Navigator/Renderer/RenderCommand.h +++ b/Navigator/src/Navigator/Renderer/RenderCommand.h @@ -11,7 +11,7 @@ namespace Navigator { public: inline static void SetClearColor(const glm::vec4& color_array) { s_api->SetClearColor(color_array); } inline static void Clear() { s_api->Clear(); } - inline static void DrawIndexed(const std::shared_ptr& array) { s_api->DrawIndexed(array); } + private: static RendererAPI* s_api; }; diff --git a/Navigator/src/Navigator/Renderer/Renderer.cpp b/Navigator/src/Navigator/Renderer/Renderer.cpp deleted file mode 100644 index 8c3cf72..0000000 --- a/Navigator/src/Navigator/Renderer/Renderer.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "Renderer.h" - -namespace Navigator { - - - void Renderer::BeginScene() {} - - void Renderer::EndScene() {} - - void Renderer::Submit(const std::shared_ptr& shader, const std::shared_ptr& data) - { - shader->Bind(); - data->Bind(); - RenderCommand::DrawIndexed(data); - } -} \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/Renderer.h b/Navigator/src/Navigator/Renderer/Renderer.h deleted file mode 100644 index db09fb2..0000000 --- a/Navigator/src/Navigator/Renderer/Renderer.h +++ /dev/null @@ -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, const std::shared_ptr& data); - - static inline RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); } - - }; -} - -#endif \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/RendererAPI.h b/Navigator/src/Navigator/Renderer/RendererAPI.h index a07614b..6a41d81 100644 --- a/Navigator/src/Navigator/Renderer/RendererAPI.h +++ b/Navigator/src/Navigator/Renderer/RendererAPI.h @@ -2,7 +2,6 @@ #define RENDERER_API_H #include "Navigator/NavCore.h" -#include "VertexArray.h" #include "glm/vec4.hpp" namespace Navigator { @@ -18,7 +17,6 @@ namespace Navigator { virtual void Clear() = 0; virtual void SetClearColor(const glm::vec4& color) = 0; - virtual void DrawIndexed(const std::shared_ptr& array) = 0; inline static API GetAPI() { return s_api; } diff --git a/Navigator/src/Navigator/Renderer/Shader.cpp b/Navigator/src/Navigator/Renderer/Shader.cpp deleted file mode 100644 index 3234b58..0000000 --- a/Navigator/src/Navigator/Renderer/Shader.cpp +++ /dev/null @@ -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 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 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 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)); - } - -} \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/Shader.h b/Navigator/src/Navigator/Renderer/Shader.h deleted file mode 100644 index 8aa6231..0000000 --- a/Navigator/src/Navigator/Renderer/Shader.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/VertexArray.cpp b/Navigator/src/Navigator/Renderer/VertexArray.cpp deleted file mode 100644 index e1a7fee..0000000 --- a/Navigator/src/Navigator/Renderer/VertexArray.cpp +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/Navigator/src/Navigator/Renderer/VertexArray.h b/Navigator/src/Navigator/Renderer/VertexArray.h deleted file mode 100644 index a2c95b4..0000000 --- a/Navigator/src/Navigator/Renderer/VertexArray.h +++ /dev/null @@ -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& buffer) = 0; - virtual void SetIndexBuffer(const std::shared_ptr& buffer) = 0; - virtual const std::vector>& GetVertexBuffers() const = 0; - virtual const std::shared_ptr& GetIndexBuffer() const = 0; - - static VertexArray* Create(); - - }; - -} - -#endif \ No newline at end of file