hyporo-cpp/source/hyporo/gpu/device.hpp

149 lines
3.6 KiB
C++
Raw Normal View History

2022-10-03 18:51:34 +05:00
#pragma once
#include "context.hpp"
#include "buffer.hpp"
#include "shader.hpp"
#include "shader_program.hpp"
#include "texture.hpp"
2022-11-18 21:50:49 +05:00
#include "render_target.hpp"
2022-10-03 18:51:34 +05:00
2022-10-27 22:27:50 +05:00
#include "../hyplib/array/array.hpp"
2022-10-03 18:51:34 +05:00
2022-11-29 12:52:33 +05:00
#include "../window_system/window_system.hpp"
2022-10-03 18:51:34 +05:00
namespace hpr::gpu
{
class Device : public Context
{
public:
enum class CullMode
{
Front,
Back,
2022-10-05 21:10:51 +05:00
FrontAndBack,
2022-10-03 18:51:34 +05:00
None
};
protected:
2022-11-18 21:50:49 +05:00
darray<Buffer*> p_buffers;
darray<Shader*> p_shaders;
darray<ShaderProgram*> p_shaderPrograms;
darray<Texture*> p_textures;
2022-10-03 18:51:34 +05:00
2022-10-05 21:10:51 +05:00
Buffer* p_currentVertexBuffer;
Buffer* p_currentIndexBuffer;
2022-11-18 21:50:49 +05:00
Buffer* p_currentUniformBuffer;
2022-10-05 21:10:51 +05:00
ShaderProgram* p_currentShaderProgram;
2022-11-29 12:52:33 +05:00
darray<RenderTarget*> p_renderTargets;
2022-10-03 18:51:34 +05:00
protected:
// Constructors
Device();
2022-11-18 21:50:49 +05:00
explicit
2022-10-03 18:51:34 +05:00
Device(DeviceAPI api);
2022-11-18 21:50:49 +05:00
~Device() override;
2022-10-03 18:51:34 +05:00
public:
// Global functions
2022-11-18 21:50:49 +05:00
static
void create(Device** device, DeviceAPI api);
2022-10-03 18:51:34 +05:00
// Member functions
// Setup
2022-11-18 21:50:49 +05:00
virtual
bool initialize() = 0;
virtual
bool destroy() = 0;
2022-10-03 18:51:34 +05:00
// State
2022-11-18 21:50:49 +05:00
virtual
void faceCulling(bool enableFaceCulling, CullMode faceCullingMode) = 0;
2022-10-03 18:51:34 +05:00
2022-11-29 12:52:33 +05:00
// Render targets
virtual
void createScreenRenderTarget(RenderTarget** target, Window* window) = 0;
virtual
void createFramebufferRenderTarget(RenderTarget** target, int width, int height) = 0;
virtual
void createSubRenderTarget(RenderTarget** target, RenderTarget* parent, int x, int y, int width, int height) = 0;
virtual
void moveRenderTarget(RenderTarget* target, int x, int y);
virtual
void scaleRenderTarget(RenderTarget* target, int width, int height);
virtual
void destroyRenderTarget(RenderTarget*& target);
2022-10-03 18:51:34 +05:00
// Buffers
2022-11-18 21:50:49 +05:00
virtual
void createVertexBuffer(Buffer **buffer, int size, char* data) = 0;
virtual
void createIndexBuffer(Buffer **buffer, int size, char* data) = 0;
virtual
void createUniformBuffer(Buffer **buffer, int size, char* data) = 0;
virtual
void useVertexBuffer(Buffer* buffer, int stride, int offset);
virtual
void useIndexBuffer(Buffer* buffer, int offset);
virtual
void useUniformBuffer(Buffer* buffer, int slot);
virtual
void editBuffer(Buffer* buffer, char* data, int size, int offset) = 0;
virtual
void editBuffer(Buffer* buffer, char* data) = 0;
virtual
void destroyBuffer(Buffer*& buffer);
Buffer* activeBuffer(Buffer::BufferType type);
2022-10-03 18:51:34 +05:00
// Shaders
2022-11-18 21:50:49 +05:00
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
void destroyShader(Shader* shader);
2022-10-03 18:51:34 +05:00
// Shader programs
2022-11-18 21:50:49 +05:00
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);
2022-10-03 18:51:34 +05:00
// Textures
2022-11-18 21:50:49 +05:00
virtual
void createTexture(Texture** texture, const std::string& filename) = 0;
virtual
void useTexture(Texture* texture, int slot) = 0;
virtual
void destroyTexture(Texture*& texture);
2022-10-03 18:51:34 +05:00
};
}