From 1d51b3bed9cc5e11f384a7d34f99b39c04d9e22b Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Sat, 24 Sep 2022 16:07:46 +0500 Subject: [PATCH] gpu base started --- source/hyporo/gpu/context.cpp | 24 +++++++++++++++ source/hyporo/gpu/context.hpp | 38 +++++++++++++++++++++++ source/hyporo/gpu/shader.cpp | 23 ++++++++++++++ source/hyporo/gpu/shader.hpp | 45 ++++++++++++++++++++++++++++ source/hyporo/gpu/shader_program.cpp | 21 +++++++++++++ source/hyporo/gpu/shader_program.hpp | 35 ++++++++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 source/hyporo/gpu/context.cpp create mode 100644 source/hyporo/gpu/context.hpp create mode 100644 source/hyporo/gpu/shader.cpp create mode 100644 source/hyporo/gpu/shader.hpp create mode 100644 source/hyporo/gpu/shader_program.cpp create mode 100644 source/hyporo/gpu/shader_program.hpp diff --git a/source/hyporo/gpu/context.cpp b/source/hyporo/gpu/context.cpp new file mode 100644 index 0000000..d831153 --- /dev/null +++ b/source/hyporo/gpu/context.cpp @@ -0,0 +1,24 @@ + +#include "context.hpp" + + +namespace hpr::gpu +{ + +Context::Context() : + p_api {DeviceAPI::Unknown} +{} + +Context::Context(DeviceAPI api) : + p_api {api} +{} + +Context::~Context() +{} + +bool Context::checkCompability(const Context* ctx) const +{ + return (ctx != nullptr) ? ctx->p_api == p_api : true; +} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/context.hpp b/source/hyporo/gpu/context.hpp new file mode 100644 index 0000000..821ed64 --- /dev/null +++ b/source/hyporo/gpu/context.hpp @@ -0,0 +1,38 @@ +#pragma once + + +namespace hpr::gpu +{ + +class Context +{ + +public: + + enum class DeviceAPI + { + Unknown, + OpenGL, + DeviceAPICount + }; + +private: + + DeviceAPI p_api; + +public: + + // Constructors + + Context(); + + Context(DeviceAPI api); + + virtual ~Context(); + + // Member functions + + bool checkCompability(const Context* ctx) const; +}; + +} \ No newline at end of file diff --git a/source/hyporo/gpu/shader.cpp b/source/hyporo/gpu/shader.cpp new file mode 100644 index 0000000..9bcf7ad --- /dev/null +++ b/source/hyporo/gpu/shader.cpp @@ -0,0 +1,23 @@ + +#include "shader.hpp" + + +namespace hpr::gpu +{ + +Shader::Shader() : + Context {DeviceAPI::Unknown}, + p_filename {}, + p_label {} +{} + +Shader::Shader(DeviceAPI api) : + Context {api}, + p_filename {}, + p_label {} +{} + +Shader::~Shader() +{} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/shader.hpp b/source/hyporo/gpu/shader.hpp new file mode 100644 index 0000000..8b4e314 --- /dev/null +++ b/source/hyporo/gpu/shader.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "context.hpp" + +#include + + +namespace hpr::gpu +{ + +class Shader : public Context +{ +protected: + + std::string p_filename; + std::string p_label; + +public: + + enum class ShaderType + { + Vertex, + Geometry, + Fragment, + ShaderTypeCount + }; + + // Constructors + + Shader(); + + Shader(DeviceAPI api); + + virtual ~Shader(); + + // Member functions + + const std::string filename() const; + + const std::string label() const; + + const ShaderType shaderType() const; +}; + +} // end namespace hpr::gpu \ No newline at end of file diff --git a/source/hyporo/gpu/shader_program.cpp b/source/hyporo/gpu/shader_program.cpp new file mode 100644 index 0000000..a3da829 --- /dev/null +++ b/source/hyporo/gpu/shader_program.cpp @@ -0,0 +1,21 @@ + +#include "shader_program.hpp" + + +namespace hpr::gpu +{ + +ShaderProgram::ShaderProgram() : + Context {DeviceAPI::Unknown}, + p_isLinked {false} +{} + +ShaderProgram::ShaderProgram(DeviceAPI api) : + Context {api}, + p_isLinked {false} +{} + +ShaderProgram::~ShaderProgram() +{} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/shader_program.hpp b/source/hyporo/gpu/shader_program.hpp new file mode 100644 index 0000000..bf1dfe6 --- /dev/null +++ b/source/hyporo/gpu/shader_program.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "context.hpp" +#include "shader.hpp" + +#include + + +namespace hpr::gpu +{ + +class ShaderProgram : Context +{ + +protected: + + std::array p_slots; + bool p_isLinked; + +public: + + // Constructors + + ShaderProgram(); + + ShaderProgram(DeviceAPI api); + + virtual ~ShaderProgram(); + + // Member functions + + const Shader* getShader(Shader::ShaderType type) const; +}; + +} \ No newline at end of file