Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/renderer/backend/gl/Device.h
Show All 23 Lines | |||||
#include "renderer/backend/gl/Framebuffer.h" | #include "renderer/backend/gl/Framebuffer.h" | ||||
#include "renderer/backend/gl/ShaderProgram.h" | #include "renderer/backend/gl/ShaderProgram.h" | ||||
#include "renderer/backend/gl/Texture.h" | #include "renderer/backend/gl/Texture.h" | ||||
#include "renderer/backend/IDevice.h" | #include "renderer/backend/IDevice.h" | ||||
#include "scriptinterface/ScriptForward.h" | #include "scriptinterface/ScriptForward.h" | ||||
#include <memory> | #include <memory> | ||||
#include <string> | #include <string> | ||||
#include <tuple> | |||||
#include <unordered_map> | |||||
#include <vector> | #include <vector> | ||||
typedef struct SDL_Window SDL_Window; | typedef struct SDL_Window SDL_Window; | ||||
typedef void* SDL_GLContext; | typedef void* SDL_GLContext; | ||||
namespace Renderer | namespace Renderer | ||||
{ | { | ||||
Show All 19 Lines | public: | ||||
const std::string& GetName() const override { return m_Name; } | const std::string& GetName() const override { return m_Name; } | ||||
const std::string& GetVersion() const override { return m_Version; } | const std::string& GetVersion() const override { return m_Version; } | ||||
const std::string& GetDriverInformation() const override { return m_DriverInformation; } | const std::string& GetDriverInformation() const override { return m_DriverInformation; } | ||||
const std::vector<std::string>& GetExtensions() const override { return m_Extensions; } | const std::vector<std::string>& GetExtensions() const override { return m_Extensions; } | ||||
void Report(const ScriptRequest& rq, JS::HandleValue settings) override; | void Report(const ScriptRequest& rq, JS::HandleValue settings) override; | ||||
IFramebuffer* GetCurrentBackbuffer() override { return m_Backbuffer.get(); } | |||||
std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override; | std::unique_ptr<IDeviceCommandContext> CreateCommandContext() override; | ||||
CDeviceCommandContext* GetActiveCommandContext() { return m_ActiveCommandContext; } | CDeviceCommandContext* GetActiveCommandContext() { return m_ActiveCommandContext; } | ||||
std::unique_ptr<ITexture> CreateTexture( | std::unique_ptr<ITexture> CreateTexture( | ||||
const char* name, const ITexture::Type type, const uint32_t usage, | const char* name, const ITexture::Type type, const uint32_t usage, | ||||
const Format format, const uint32_t width, const uint32_t height, | const Format format, const uint32_t width, const uint32_t height, | ||||
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; | const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; | ||||
std::unique_ptr<ITexture> CreateTexture2D( | std::unique_ptr<ITexture> CreateTexture2D( | ||||
const char* name, const uint32_t usage, | const char* name, const uint32_t usage, | ||||
const Format format, const uint32_t width, const uint32_t height, | const Format format, const uint32_t width, const uint32_t height, | ||||
const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; | const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; | ||||
std::unique_ptr<IFramebuffer> CreateFramebuffer( | std::unique_ptr<IFramebuffer> CreateFramebuffer( | ||||
const char* name, ITexture* colorAttachment, | const char* name, SColorAttachment* colorAttachment, | ||||
ITexture* depthStencilAttachment) override; | SDepthStencilAttachment* depthStencilAttachment) override; | ||||
std::unique_ptr<IFramebuffer> CreateFramebuffer( | |||||
const char* name, ITexture* colorAttachment, | |||||
ITexture* depthStencilAttachment, const CColor& clearColor) override; | |||||
std::unique_ptr<IBuffer> CreateBuffer( | std::unique_ptr<IBuffer> CreateBuffer( | ||||
const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) override; | const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) override; | ||||
std::unique_ptr<IShaderProgram> CreateShaderProgram( | std::unique_ptr<IShaderProgram> CreateShaderProgram( | ||||
const CStr& name, const CShaderDefines& defines) override; | const CStr& name, const CShaderDefines& defines) override; | ||||
bool AcquireNextBackbuffer() override; | bool AcquireNextBackbuffer() override; | ||||
IFramebuffer* GetCurrentBackbuffer( | |||||
const AttachmentLoadOp colorAttachmentLoadOp, | |||||
const AttachmentStoreOp colorAttachmentStoreOp, | |||||
const AttachmentLoadOp depthStencilAttachmentLoadOp, | |||||
const AttachmentStoreOp depthStencilAttachmentStoreOp) override; | |||||
void Present() override; | void Present() override; | ||||
bool UseFramebufferInvalidating() const { return m_UseFramebufferInvalidating; } | |||||
bool IsTextureFormatSupported(const Format format) const override; | bool IsTextureFormatSupported(const Format format) const override; | ||||
bool IsFramebufferFormatSupported(const Format format) const override; | bool IsFramebufferFormatSupported(const Format format) const override; | ||||
const Capabilities& GetCapabilities() const override { return m_Capabilities; } | const Capabilities& GetCapabilities() const override { return m_Capabilities; } | ||||
private: | private: | ||||
CDevice(); | CDevice(); | ||||
SDL_Window* m_Window = nullptr; | SDL_Window* m_Window = nullptr; | ||||
SDL_GLContext m_Context = nullptr; | SDL_GLContext m_Context = nullptr; | ||||
bool m_ARB = false; | bool m_ARB = false; | ||||
std::string m_Name; | std::string m_Name; | ||||
std::string m_Version; | std::string m_Version; | ||||
std::string m_DriverInformation; | std::string m_DriverInformation; | ||||
std::vector<std::string> m_Extensions; | std::vector<std::string> m_Extensions; | ||||
// GL can have the only one command context at once. | // GL can have the only one command context at once. | ||||
// TODO: remove as soon as we have no GL code outside backend, currently | // TODO: remove as soon as we have no GL code outside backend, currently | ||||
// it's used only as a helper for transition. | // it's used only as a helper for transition. | ||||
CDeviceCommandContext* m_ActiveCommandContext = nullptr; | CDeviceCommandContext* m_ActiveCommandContext = nullptr; | ||||
std::unique_ptr<CFramebuffer> m_Backbuffer; | using BackbufferKey = std::tuple< | ||||
AttachmentLoadOp, AttachmentStoreOp, | |||||
AttachmentLoadOp, AttachmentStoreOp>; | |||||
struct BackbufferKeyHash | |||||
{ | |||||
size_t operator()(const BackbufferKey& key) const; | |||||
}; | |||||
// We use std::unordered_map to avoid storing sizes of Attachment*Op | |||||
// enumerations. If it becomes a performance issue we'll replace it | |||||
// by an array. | |||||
std::unordered_map< | |||||
BackbufferKey, std::unique_ptr<CFramebuffer>, BackbufferKeyHash> m_Backbuffers; | |||||
bool m_BackbufferAcquired = false; | bool m_BackbufferAcquired = false; | ||||
bool m_UseFramebufferInvalidating = false; | |||||
Capabilities m_Capabilities{}; | Capabilities m_Capabilities{}; | ||||
}; | }; | ||||
} // namespace GL | } // namespace GL | ||||
} // namespace Backend | } // namespace Backend | ||||
} // namespace Renderer | } // namespace Renderer | ||||
#endif // INCLUDED_RENDERER_BACKEND_GL_DEVICE | #endif // INCLUDED_RENDERER_BACKEND_GL_DEVICE |
Wildfire Games · Phabricator