#ifndef __EFFEKSEERRENDERER_LLGI_GRAPHICS_DEVICE_H__ #define __EFFEKSEERRENDERER_LLGI_GRAPHICS_DEVICE_H__ #include #include #include #include #include #include namespace EffekseerRendererLLGI { namespace Backend { class GraphicsDevice; class VertexBuffer; class IndexBuffer; class UniformBuffer; class Shader; class VertexLayout; class FrameBuffer; class Texture; class RenderPass; class PipelineState; class UniformLayout; using GraphicsDeviceRef = Effekseer::RefPtr; using VertexBufferRef = Effekseer::RefPtr; using IndexBufferRef = Effekseer::RefPtr; using UniformBufferRef = Effekseer::RefPtr; using ShaderRef = Effekseer::RefPtr; using VertexLayoutRef = Effekseer::RefPtr; using FrameBufferRef = Effekseer::RefPtr; using TextureRef = Effekseer::RefPtr; using RenderPassRef = Effekseer::RefPtr; using PipelineStateRef = Effekseer::RefPtr; using UniformLayoutRef = Effekseer::RefPtr; class DeviceObject { private: public: virtual void OnLostDevice(); virtual void OnResetDevice(); }; class VertexBuffer : public DeviceObject, public Effekseer::Backend::VertexBuffer { private: std::shared_ptr buffer_; GraphicsDevice* graphicsDevice_ = nullptr; int32_t size_ = 0; bool isDynamic_ = false; public: VertexBuffer(GraphicsDevice* graphicsDevice); ~VertexBuffer() override; bool Allocate(int32_t size, bool isDynamic); void Deallocate(); void OnLostDevice() override; void OnResetDevice() override; bool Init(int32_t size, bool isDynamic); void UpdateData(const void* src, int32_t size, int32_t offset) override; LLGI::Buffer* GetBuffer() { return buffer_.get(); } }; class IndexBuffer : public DeviceObject, public Effekseer::Backend::IndexBuffer { private: std::shared_ptr buffer_; GraphicsDevice* graphicsDevice_ = nullptr; int32_t stride_ = 0; public: IndexBuffer(GraphicsDevice* graphicsDevice); ~IndexBuffer() override; bool Allocate(int32_t elementCount, int32_t stride); void Deallocate(); void OnLostDevice() override; void OnResetDevice() override; bool Init(int32_t elementCount, int32_t stride); void UpdateData(const void* src, int32_t size, int32_t offset) override; LLGI::Buffer* GetBuffer() { return buffer_.get(); } }; class Texture : public DeviceObject, public Effekseer::Backend::Texture { std::shared_ptr texture_; GraphicsDevice* graphicsDevice_ = nullptr; std::function onDisposed_; public: Texture(GraphicsDevice* graphicsDevice); ~Texture() override; bool Init(const Effekseer::Backend::TextureParameter& param, const Effekseer::CustomVector& initialData); bool Init(uint64_t id, std::function onDisposed); bool Init(LLGI::Texture* texture); std::shared_ptr& GetTexture() { return texture_; } }; class Shader : public DeviceObject, public Effekseer::Backend::Shader { private: GraphicsDevice* graphicsDevice_ = nullptr; LLGI::Shader* vertexShader_ = nullptr; LLGI::Shader* pixelShader_ = nullptr; public: Shader(GraphicsDevice* graphicsDevice); ~Shader() override; bool Init(const void* vertexShaderData, int32_t vertexShaderDataSize, const void* pixelShaderData, int32_t pixelShaderDataSize); LLGI::Shader* GetVertexShader() const { return vertexShader_; } LLGI::Shader* GetPixelShader() const { return pixelShader_; } }; class GraphicsDevice : public Effekseer::Backend::GraphicsDevice { private: std::set objects_; LLGI::Graphics* graphics_; public: GraphicsDevice(LLGI::Graphics* graphics); ~GraphicsDevice() override; void LostDevice(); void ResetDevice(); LLGI::Graphics* GetGraphics(); void Register(DeviceObject* deviceObject); void Unregister(DeviceObject* deviceObject); Effekseer::Backend::VertexBufferRef CreateVertexBuffer(int32_t size, const void* initialData, bool isDynamic) override; Effekseer::Backend::IndexBufferRef CreateIndexBuffer(int32_t elementCount, const void* initialData, Effekseer::Backend::IndexBufferStrideType stride) override; Effekseer::Backend::TextureRef CreateTexture(const Effekseer::Backend::TextureParameter& param, const Effekseer::CustomVector& initialData) override; Effekseer::Backend::TextureRef CreateTexture(uint64_t id, const std::function& onDisposed); Effekseer::Backend::TextureRef CreateTexture(LLGI::Texture* texture); Effekseer::Backend::ShaderRef CreateShaderFromBinary(const void* vsData, int32_t vsDataSize, const void* psData, int32_t psDataSize) override; }; } // namespace Backend } // namespace EffekseerRendererLLGI #endif