Extra2D/Extra2D/include/extra2d/gfx/opengl/GLDevice.h

76 lines
2.3 KiB
C++

#pragma once
#include <extra2d/gfx/GFXDevice.h>
namespace extra2d {
namespace gfx {
/**
* @brief OpenGL 设备实现
*/
class GLDevice : public Device {
public:
/**
* @brief 构造函数
*/
GLDevice();
/**
* @brief 析构函数
*/
~GLDevice() override;
// ==================== 设备生命周期 ====================
void frameSync() override;
void present() override;
// ==================== 资源创建 ====================
Buffer* createBuffer(const BufferInfo& info) override;
Texture* createTexture(const TextureInfo& info) override;
Shader* createShader(const std::string& name,
const std::string& vertexSource,
const std::string& fragmentSource) override;
PipelineState* createPipelineState(const PipelineStateInfo& info) override;
InputAssembler* createInputAssembler(const InputAssemblerInfo& info) override;
// ==================== 数据传输 ====================
void copyBuffersToTexture(const u8* const* buffers, Texture* dst,
const BufferTextureCopy* regions, u32 count) override;
// ==================== 状态管理 ====================
void setViewport(float x, float y, float width, float height) override;
void setScissor(i32 x, i32 y, u32 width, u32 height) override;
void clearColor(float r, float g, float b, float a) override;
void clearDepthStencil(float depth, u8 stencil) override;
void beginRenderPass() override;
void endRenderPass() override;
void bindPipelineState(PipelineState* pipeline) override;
void bindInputAssembler(InputAssembler* ia) override;
void draw(u32 firstVertex, u32 vertexCount) override;
void drawIndexed(u32 firstIndex, u32 indexCount, i32 vertexOffset) override;
void drawInstanced(u32 firstVertex, u32 vertexCount, u32 instanceCount) override;
void drawIndexedInstanced(u32 firstIndex, u32 indexCount,
u32 instanceCount, i32 vertexOffset) override;
protected:
bool doInit(const DeviceInfo& info) override;
void doDestroy() override;
private:
void initCapabilities();
class GLPipelineState* currentPipeline_{nullptr};
class GLInputAssembler* currentIA_{nullptr};
class GLShader* currentShader_{nullptr};
};
} // namespace gfx
} // namespace extra2d