diff --git a/source/hyporo/gpu/buffer.cpp b/source/hyporo/gpu/buffer.cpp new file mode 100644 index 0000000..9c75984 --- /dev/null +++ b/source/hyporo/gpu/buffer.cpp @@ -0,0 +1,30 @@ + +#include "buffer.hpp" + + +namespace hpr::gpu +{ + +Buffer::Buffer() : + Context {DeviceAPI::Unknown}, + p_type {BufferType::Undefined}, + p_size {0}, + p_stride {0} +{} + +Buffer::Buffer(DeviceAPI api) : + Context {api}, + p_type {BufferType::Undefined}, + p_size {0}, + p_stride {0} +{} + +Buffer::~Buffer() +{} + +const BufferType Buffer::type() const +{ + return p_type; +} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/buffer.hpp b/source/hyporo/gpu/buffer.hpp new file mode 100644 index 0000000..bb373ee --- /dev/null +++ b/source/hyporo/gpu/buffer.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include "context.hpp" + +#include + + +namespace hpr::gpu +{ + +class Buffer : public Context +{ + +public: + + enum class BufferType + { + Undefined, + Vertex, + Index, + BufferTypeCount + }; + +protected: + + BufferType p_type; + int p_size; + int p_stride; + +public: + + // Constructors + + Buffer(); + + Buffer(DeviceAPI api); + + virtual ~Buffer(); + + // Member functions + + const int size() const; + + const BufferType type() const; +}; + +} // end namespace hpr::gpu \ No newline at end of file diff --git a/source/hyporo/gpu/device.cpp b/source/hyporo/gpu/device.cpp new file mode 100644 index 0000000..b45b8ef --- /dev/null +++ b/source/hyporo/gpu/device.cpp @@ -0,0 +1,34 @@ + +#include "device.hpp" +#include "opengl/device.hpp" + + +namespace hpr::gpu +{ + + Device::Device() : + Context {DeviceAPI::Unknown} + {} + + Device::Device(DeviceAPI api) : + Context {api} + {} + + Device::~Device() + {} + + void Device::create(Device **device, DeviceAPI api) + { + if (device == nullptr) + throw "Invalid parameter"; + if (api == DeviceAPI::Unknown) + throw "Invalid parameter"; + + *device = nullptr; + + if (api == DeviceAPI::OpenGL) + *device = new opengl::Device; + else + throw "Unsupported device"; + } +} \ No newline at end of file diff --git a/source/hyporo/gpu/device.hpp b/source/hyporo/gpu/device.hpp new file mode 100644 index 0000000..7cf5c44 --- /dev/null +++ b/source/hyporo/gpu/device.hpp @@ -0,0 +1,91 @@ +#pragma once + +#include "context.hpp" +#include "buffer.hpp" +#include "shader.hpp" +#include "shader_program.hpp" +#include "texture.hpp" + +#include + + +namespace hpr::gpu +{ + +class Device : public Context +{ + +public: + + enum class CullMode + { + Front, + Back, + None + }; + +protected: + + std::vector p_buffers; + std::vector p_shaders; + std::vector p_shaderPrograms; + std::vector p_textures; + +protected: + + // Constructors + + Device(); + + Device(DeviceAPI api); + + virtual ~Device(); + +public: + + // Global functions + + static void create(Device** device, DeviceAPI api); + + // Member functions + + // Setup + + virtual bool initialize() = 0; + virtual bool destroy() = 0; + + // State + + virtual void faceCulling(bool enableFaceCulling, CullMode faceCullingMode = CullMode::None) = 0; + + // Buffers + + virtual void createVertexBuffer(Buffer **buffer, int size, char* data) = 0; + virtual void createIndexBuffer(Buffer **buffer, int size, char* data) = 0; + virtual void useVertexBuffer(Buffer* buffer, int stride, int offset); + virtual void useIndexBuffer(Buffer* buffer, int offset); + virtual bool destroyBuffer(Buffer*& buffer); + + // Shaders + + virtual void createVertexShader(Shader** shader, const std::string& filename, const std::string& label) = 0; + virtual void createFragmentShader(Shader** shader, const std::string& filename, const std::string& label) = 0; + virtual void createGeometryShader(Shader** shader, const std::string& filename, const std::string& label) = 0; + virtual bool destroyShader(Shader*& shader); + + // Shader programs + + virtual void createShaderProgram(ShaderProgram** program) = 0; + virtual void attachShader(ShaderProgram* program, Shader* shader); + virtual void linkProgram(ShaderProgram* program); + virtual void useShaderProgram(ShaderProgram* program); + virtual void destroyShaderProgram(ShaderProgram*& program, bool withShaders = false); + + // Textures + + virtual void createTexture(Texture** texture, const std::string& filename) = 0; + virtual void useTexture(Texture* texture, int slot); + virtual void destroyTexture(Texture*& texture); +}; + +} diff --git a/source/hyporo/gpu/opengl/buffer.cpp b/source/hyporo/gpu/opengl/buffer.cpp new file mode 100644 index 0000000..263bb29 --- /dev/null +++ b/source/hyporo/gpu/opengl/buffer.cpp @@ -0,0 +1,28 @@ + +#include "buffer.hpp" + + +namespace hpr::gpu::opengl +{ + +Buffer::Buffer() : + gpu::Buffer(DeviceAPI::OpenGL), + p_bufferIndex {0}, + p_vertexArrayIndex {0} +{} + +Buffer::~Buffer() +{} + +const int Buffer::target() const +{ + switch (p_type) + { + case BufferType::Vertex: + return GL_ARRAY_BUFFER; + case BufferType::Index: + return GL_ELEMENT_INDEX_BUFFER; + } +} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/opengl/buffer.hpp b/source/hyporo/gpu/opengl/buffer.hpp new file mode 100644 index 0000000..28db409 --- /dev/null +++ b/source/hyporo/gpu/opengl/buffer.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "../buffer.hpp" + + +namespace hpr::gpu::opengl +{ + +class Buffer : public gpu::Buffer +{ + friend class Device; + +protected: + unsigned int p_bufferIndex; + unsigned int p_vertexArrayIndex; + +public: + + // Constructors + + Buffer(); + + virtual ~Buffer(); + + // Member functions + + const int target() const; +}; + +} diff --git a/source/hyporo/gpu/opengl/context.cpp b/source/hyporo/gpu/opengl/context.cpp new file mode 100644 index 0000000..e244f32 --- /dev/null +++ b/source/hyporo/gpu/opengl/context.cpp @@ -0,0 +1,5 @@ +// +// Created by L-Nafaryus on 10/3/2022. +// + +#include "context.hpp" diff --git a/source/hyporo/gpu/opengl/context.hpp b/source/hyporo/gpu/opengl/context.hpp new file mode 100644 index 0000000..9ceef65 --- /dev/null +++ b/source/hyporo/gpu/opengl/context.hpp @@ -0,0 +1,8 @@ +// +// Created by L-Nafaryus on 10/3/2022. +// + +#ifndef HYPORO_CONTEXT_HPP +#define HYPORO_CONTEXT_HPP + +#endif //HYPORO_CONTEXT_HPP diff --git a/source/hyporo/gpu/opengl/device.cpp b/source/hyporo/gpu/opengl/device.cpp new file mode 100644 index 0000000..ad11a6b --- /dev/null +++ b/source/hyporo/gpu/opengl/device.cpp @@ -0,0 +1,21 @@ + +#include "device.hpp" +#include "buffer.hpp +#include "shader.hpp" +#include "shader_program.hpp" +#include "texture.hpp" + + +namespace hpr::gpu::opengl +{ + +Device::Device() : + gpu::Device {DeviceAPI::OpenGL}, + p_isInitialized {false} +{} + +Device::~Device() +{} + + +} \ No newline at end of file diff --git a/source/hyporo/gpu/opengl/device.hpp b/source/hyporo/gpu/opengl/device.hpp new file mode 100644 index 0000000..4a059f8 --- /dev/null +++ b/source/hyporo/gpu/opengl/device.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "../device.hpp" + + +namespace hpr::gpu::opengl +{ + +class Device : public gpu::Device +{ + +protected: + + bool p_isInitialized; + +public: + + // Constructors + + Device(); + + ~Device(); + + +}; + +} \ No newline at end of file diff --git a/source/hyporo/gpu/opengl/shader.cpp b/source/hyporo/gpu/opengl/shader.cpp new file mode 100644 index 0000000..1259230 --- /dev/null +++ b/source/hyporo/gpu/opengl/shader.cpp @@ -0,0 +1,19 @@ +// +// Created by L-Nafaryus on 10/3/2022. +// + +#include "shader.hpp" + + +namespace hpr::gpu::opengl +{ + +Shader::Shader() : + gpu::Shader(DeviceAPI::OpenGL), + p_shaderIndex {0} +{} + +Shader::~Shader() +{} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/opengl/shader.hpp b/source/hyporo/gpu/opengl/shader.hpp new file mode 100644 index 0000000..9c393a7 --- /dev/null +++ b/source/hyporo/gpu/opengl/shader.hpp @@ -0,0 +1,26 @@ + +#include "../shader.hpp" + + +namespace hpr::gpu::opengl +{ + +class Shader : public gpu::Shader +{ + friend class Device; + +protected: + + unsigned int p_shaderIndex; + +public: + + // Constructors + + Shader(); + + virtual ~Shader(); + +}; + +} diff --git a/source/hyporo/gpu/opengl/shader_program.cpp b/source/hyporo/gpu/opengl/shader_program.cpp new file mode 100644 index 0000000..455d0aa --- /dev/null +++ b/source/hyporo/gpu/opengl/shader_program.cpp @@ -0,0 +1,22 @@ + +#include "shader_program.hpp" +#include "shader.hpp" + + +namespace hpr::gpu::opengl +{ + +ShaderProgram::ShaderProgram() : + gpu::ShaderProgram {DeviceAPI::OpenGL}, + p_shaderProgramIndex {0} +{} + +ShaderProgram::~ShaderProgram() +{} + +Shader *ShaderProgram::shader(gpu::Shader::ShaderType type) +{ + return static_cast(p_slots[(size_t)type]); +} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/opengl/shader_program.hpp b/source/hyporo/gpu/opengl/shader_program.hpp new file mode 100644 index 0000000..b1c6df5 --- /dev/null +++ b/source/hyporo/gpu/opengl/shader_program.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "../shader_program.hpp" + + +namespace hpr::gpu::opengl +{ + +// Forward declarations + +class Shader; + +// + +class ShaderProgram : public gpu::ShaderProgram +{ + friend class Device; + +protected: + + unsigned int p_shaderProgramIndex; + +public: + + ShaderProgram(); + + ~ShaderProgram(); + +protected: + + Shader* shader(gpu::Shader::ShaderType type); + +}; + +} diff --git a/source/hyporo/gpu/opengl/texture.cpp b/source/hyporo/gpu/opengl/texture.cpp new file mode 100644 index 0000000..592df4b --- /dev/null +++ b/source/hyporo/gpu/opengl/texture.cpp @@ -0,0 +1,16 @@ + +#include "texture.hpp" + + +namespace hpr::gpu::opengl +{ + +Texture::Texture() : + gpu::Texture {DeviceAPI::OpenGL}, + p_textureIndex {0} +{} + +Texture::~Texture() +{} + +} \ No newline at end of file diff --git a/source/hyporo/gpu/opengl/texture.hpp b/source/hyporo/gpu/opengl/texture.hpp new file mode 100644 index 0000000..6687e15 --- /dev/null +++ b/source/hyporo/gpu/opengl/texture.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "../texture.hpp" + + +namespace hpr::gpu::opengl +{ + +class Texture : public gpu::Texture +{ + friend class Device; + +protected: + + unsigned int p_textureIndex; + +public: + + Texture(); + + ~Texture(); + +}; + +} \ No newline at end of file diff --git a/source/hyporo/gpu/shader_program.hpp b/source/hyporo/gpu/shader_program.hpp index bf1dfe6..7072d2d 100644 --- a/source/hyporo/gpu/shader_program.hpp +++ b/source/hyporo/gpu/shader_program.hpp @@ -9,7 +9,7 @@ namespace hpr::gpu { -class ShaderProgram : Context +class ShaderProgram : public Context { protected: diff --git a/source/hyporo/gpu/texture.cpp b/source/hyporo/gpu/texture.cpp new file mode 100644 index 0000000..2f82079 --- /dev/null +++ b/source/hyporo/gpu/texture.cpp @@ -0,0 +1,26 @@ + +#include "texture.hpp" + + +namespace hpr::gpu +{ + +Texture::Texture() : + Context {DeviceAPI::Unknown}, + p_filename {}, + p_width {0}, + p_height {0} +{} + + +Texture::Texture(DeviceAPI api) : + Context {api}, + p_filename {}, + p_width {0}, + p_height {0} +{} + +Texture::~Texture() +{} + +} diff --git a/source/hyporo/gpu/texture.hpp b/source/hyporo/gpu/texture.hpp new file mode 100644 index 0000000..b1f03a9 --- /dev/null +++ b/source/hyporo/gpu/texture.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "context.hpp" + +#include + + +namespace hpr::gpu +{ + +class Texture : public Context +{ +protected: + + std::string p_filename; + int p_width; + int p_height; + +public: + + // Constructors + + Texture(); + + Texture(DeviceAPI api); + + virtual ~Texture(); + + // Member functions + + const std::string filename() const(); + + const int width() const; + + const int height() const; +}; + +} // end namespace hpr::gpu \ No newline at end of file