From 62e589ab76770d77748e13ea4f926938e40ed39d Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Sun, 8 May 2022 22:02:46 +0000 Subject: [PATCH] Adds renderer backend interface and dummy backend. Comments By: phosit, Stan Tested By: Langbart, phosit Differential Revision: https://code.wildfiregames.com/D4636 This was SVN commit r26858. --- binaries/data/config/default.cfg | 1 + binaries/data/mods/mod/hwdetect/hwdetect.js | 14 +- binaries/data/mods/mod/hwdetect/test.js | 6 +- build/premake/premake5.lua | 2 + source/graphics/Canvas2D.cpp | 8 +- source/graphics/Canvas2D.h | 4 +- source/graphics/LOSTexture.cpp | 14 +- source/graphics/LOSTexture.h | 20 +- source/graphics/MiniMapTexture.cpp | 18 +- source/graphics/MiniMapTexture.h | 18 +- source/graphics/ParticleEmitter.cpp | 6 +- source/graphics/ParticleEmitter.h | 6 +- source/graphics/ShaderDefines.cpp | 2 +- source/graphics/ShaderDefines.h | 4 +- source/graphics/ShaderManager.cpp | 11 +- source/graphics/ShaderProgram.cpp | 2 +- source/graphics/TerrainTextureManager.cpp | 6 +- source/graphics/TerrainTextureManager.h | 8 +- source/graphics/TerritoryTexture.cpp | 12 +- source/graphics/TerritoryTexture.h | 14 +- source/graphics/TextRenderer.cpp | 2 +- source/graphics/TextRenderer.h | 4 +- source/graphics/TextureManager.cpp | 110 ++++------ source/graphics/TextureManager.h | 32 +-- source/graphics/tests/test_TextureManager.h | 15 +- source/gui/CGUIText.cpp | 6 +- source/gui/ObjectTypes/CInput.cpp | 6 +- source/gui/ObjectTypes/CMiniMap.cpp | 4 +- source/main.cpp | 2 +- source/ps/ArchiveBuilder.cpp | 6 +- source/ps/GameSetup/HWDetect.cpp | 10 +- source/ps/Profiler2GPU.cpp | 3 + source/ps/Util.cpp | 2 +- source/ps/VideoMode.cpp | 8 + source/ps/VideoMode.h | 14 +- source/renderer/DebugRenderer.cpp | 14 +- source/renderer/DecalRData.cpp | 6 +- source/renderer/DecalRData.h | 4 +- source/renderer/HWLightingModelRenderer.cpp | 10 +- source/renderer/HWLightingModelRenderer.h | 6 +- source/renderer/InstancingModelRenderer.cpp | 8 +- source/renderer/InstancingModelRenderer.h | 6 +- source/renderer/ModelRenderer.cpp | 2 +- source/renderer/ModelRenderer.h | 6 +- source/renderer/ModelVertexRenderer.h | 8 +- source/renderer/OverlayRenderer.cpp | 16 +- source/renderer/OverlayRenderer.h | 16 +- source/renderer/ParticleRenderer.cpp | 2 +- source/renderer/ParticleRenderer.h | 4 +- source/renderer/PatchRData.cpp | 34 +-- source/renderer/PatchRData.h | 14 +- source/renderer/PostprocManager.cpp | 40 ++-- source/renderer/PostprocManager.h | 48 ++--- source/renderer/RenderModifiers.cpp | 4 +- source/renderer/RenderModifiers.h | 8 +- source/renderer/Renderer.cpp | 10 +- source/renderer/Renderer.h | 4 +- source/renderer/SceneRenderer.cpp | 30 +-- source/renderer/SceneRenderer.h | 22 +- source/renderer/ShadowMap.cpp | 18 +- source/renderer/ShadowMap.h | 4 +- source/renderer/SilhouetteRenderer.cpp | 4 +- source/renderer/SilhouetteRenderer.h | 6 +- source/renderer/SkyManager.cpp | 14 +- source/renderer/SkyManager.h | 10 +- source/renderer/TerrainOverlay.cpp | 19 +- source/renderer/TerrainOverlay.h | 28 +-- source/renderer/TerrainRenderer.cpp | 22 +- source/renderer/TerrainRenderer.h | 24 +-- source/renderer/TexturedLineRData.cpp | 6 +- source/renderer/TexturedLineRData.h | 4 +- source/renderer/VertexArray.cpp | 10 +- source/renderer/VertexArray.h | 12 +- source/renderer/VertexBuffer.cpp | 16 +- source/renderer/VertexBuffer.h | 18 +- source/renderer/VertexBufferManager.cpp | 8 +- source/renderer/VertexBufferManager.h | 2 +- source/renderer/WaterManager.cpp | 10 +- source/renderer/WaterManager.h | 26 +-- source/renderer/backend/IBuffer.h | 49 +++++ source/renderer/backend/IDevice.h | 108 ++++++++++ .../renderer/backend/IDeviceCommandContext.h | 157 ++++++++++++++ source/renderer/backend/IDeviceObject.h | 51 +++++ source/renderer/backend/IFramebuffer.h | 40 ++++ source/renderer/backend/IShaderProgram.h | 5 +- source/renderer/backend/ITexture.h | 55 +++++ source/renderer/backend/dummy/Buffer.cpp | 58 +++++ source/renderer/backend/dummy/Buffer.h | 68 ++++++ source/renderer/backend/dummy/Device.cpp | 128 +++++++++++ source/renderer/backend/dummy/Device.h | 99 +++++++++ .../backend/dummy/DeviceCommandContext.cpp | 204 ++++++++++++++++++ .../backend/dummy/DeviceCommandContext.h | 143 ++++++++++++ source/renderer/backend/dummy/Framebuffer.cpp | 54 +++++ source/renderer/backend/dummy/Framebuffer.h | 63 ++++++ .../renderer/backend/dummy/ShaderProgram.cpp | 64 ++++++ source/renderer/backend/dummy/ShaderProgram.h | 63 ++++++ source/renderer/backend/dummy/Texture.cpp | 64 ++++++ source/renderer/backend/dummy/Texture.h | 74 +++++++ source/renderer/backend/gl/Buffer.cpp | 5 + source/renderer/backend/gl/Buffer.h | 18 +- source/renderer/backend/gl/Device.cpp | 31 +-- source/renderer/backend/gl/Device.h | 70 +++--- .../backend/gl/DeviceCommandContext.cpp | 62 +++--- .../backend/gl/DeviceCommandContext.h | 111 ++++------ source/renderer/backend/gl/Framebuffer.cpp | 5 + source/renderer/backend/gl/Framebuffer.h | 12 +- source/renderer/backend/gl/ShaderProgram.cpp | 4 + source/renderer/backend/gl/Texture.cpp | 5 + source/renderer/backend/gl/Texture.h | 26 +-- source/renderer/backend/vulkan/Device.cpp | 95 +++++++- source/renderer/backend/vulkan/Device.h | 53 ++++- source/tools/atlas/GameInterface/Brushes.cpp | 2 +- source/tools/atlas/GameInterface/View.cpp | 2 +- 113 files changed, 2359 insertions(+), 672 deletions(-) create mode 100644 source/renderer/backend/IBuffer.h create mode 100644 source/renderer/backend/IDevice.h create mode 100644 source/renderer/backend/IDeviceCommandContext.h create mode 100644 source/renderer/backend/IDeviceObject.h create mode 100644 source/renderer/backend/IFramebuffer.h create mode 100644 source/renderer/backend/ITexture.h create mode 100644 source/renderer/backend/dummy/Buffer.cpp create mode 100644 source/renderer/backend/dummy/Buffer.h create mode 100644 source/renderer/backend/dummy/Device.cpp create mode 100644 source/renderer/backend/dummy/Device.h create mode 100644 source/renderer/backend/dummy/DeviceCommandContext.cpp create mode 100644 source/renderer/backend/dummy/DeviceCommandContext.h create mode 100644 source/renderer/backend/dummy/Framebuffer.cpp create mode 100644 source/renderer/backend/dummy/Framebuffer.h create mode 100644 source/renderer/backend/dummy/ShaderProgram.cpp create mode 100644 source/renderer/backend/dummy/ShaderProgram.h create mode 100644 source/renderer/backend/dummy/Texture.cpp create mode 100644 source/renderer/backend/dummy/Texture.h diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 85ea6872f6..b5411399f9 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -116,6 +116,7 @@ cursorbackend = "sdl" ; Backends for all graphics rendering: ; glarb - GL with legacy assembler-like shaders, might used only for buggy drivers. ; gl - GL with GLSL shaders, should be used by default. +; dummy - backend that does nothing, allows to check performance without backend drivers. rendererbackend = "gl" ; Enables additional debug information in renderer backend. diff --git a/binaries/data/mods/mod/hwdetect/hwdetect.js b/binaries/data/mods/mod/hwdetect/hwdetect.js index 5bb16c755e..86a9d8fd1e 100644 --- a/binaries/data/mods/mod/hwdetect/hwdetect.js +++ b/binaries/data/mods/mod/hwdetect/hwdetect.js @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -209,10 +209,10 @@ function RunDetection(settings) var gfx_mem = settings.gfx_mem; // Values from glGetString - var GL_VENDOR = settings.GL_VENDOR; - var GL_RENDERER = settings.GL_RENDERER; - var GL_VERSION = settings.GL_VERSION; - var GL_EXTENSIONS = settings.GL_EXTENSIONS.split(" "); + var GL_VENDOR = settings.renderer_backend.GL_VENDOR; + var GL_RENDERER = settings.renderer_backend.GL_RENDERER; + var GL_VERSION = settings.renderer_backend.GL_VERSION; + var GL_EXTENSIONS = settings.renderer_backend.GL_EXTENSIONS.split(" "); // Enable GLSL on OpenGL 3+, which should be able to properly // manage GLSL shaders, needed for effects like windy trees @@ -340,6 +340,10 @@ function RunDetection(settings) global.RunHardwareDetection = function(settings) { + // Currently we don't have limitations for other backends than GL and GL ARB. + if (settings.renderer_backend.name != 'gl' && settings.renderer_backend.name != 'glarb') + return; + //print(JSON.stringify(settings, null, 1)+"\n"); var output = RunDetection(settings); diff --git a/binaries/data/mods/mod/hwdetect/test.js b/binaries/data/mods/mod/hwdetect/test.js index 07c165d0fe..92e5796769 100644 --- a/binaries/data/mods/mod/hwdetect/test.js +++ b/binaries/data/mods/mod/hwdetect/test.js @@ -15,9 +15,9 @@ print("Output"); print("Warnings"); hwdetectTestData.sort(function(a, b) { - if (a.GL_RENDERER < b.GL_RENDERER) + if (a.renderer_backend.GL_RENDERER < b.renderer_backend.GL_RENDERER) return -1; - if (b.GL_RENDERER < a.GL_RENDERER) + if (b.renderer_backend.GL_RENDERER < a.renderer_backend.GL_RENDERER) return +1; return 0; }); @@ -35,7 +35,7 @@ for (var settings of hwdetectTestData) print(""); print("" + os); - print("" + settings.GL_RENDERER); + print("" + settings.renderer_backend.GL_RENDERER); print("" + disabled.join(" ")); print("" + output.warnings.concat(output.dialog_warnings).join("\n")); } diff --git a/build/premake/premake5.lua b/build/premake/premake5.lua index 555122797c..519bf9ec99 100644 --- a/build/premake/premake5.lua +++ b/build/premake/premake5.lua @@ -786,7 +786,9 @@ function setup_all_libs () "graphics/scripting", "renderer", "renderer/backend", + "renderer/backend/dummy", "renderer/backend/gl", + "renderer/backend/vulkan", "renderer/scripting", "third_party/mikktspace", "third_party/ogre3d_preprocessor" diff --git a/source/graphics/Canvas2D.cpp b/source/graphics/Canvas2D.cpp index 0fe1d12baa..016cadf256 100644 --- a/source/graphics/Canvas2D.cpp +++ b/source/graphics/Canvas2D.cpp @@ -47,7 +47,7 @@ struct SBindingSlots }; inline void DrawTextureImpl( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTexturePtr& texture, const PlaneArray2D& vertices, PlaneArray2D uvs, const CColor& multiply, const CColor& add, const float grayscaleFactor, const SBindingSlots& bindingSlots) @@ -85,7 +85,7 @@ inline void DrawTextureImpl( class CCanvas2D::Impl { public: - Impl(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Impl(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) : DeviceCommandContext(deviceCommandContext) { } @@ -124,7 +124,7 @@ public: Tech.reset(); } - Renderer::Backend::GL::CDeviceCommandContext* DeviceCommandContext; + Renderer::Backend::IDeviceCommandContext* DeviceCommandContext = nullptr; CShaderTechniquePtr Tech; // We assume that the shader can't be destroyed while it's bound. So these @@ -133,7 +133,7 @@ public: }; CCanvas2D::CCanvas2D( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) : m(std::make_unique(deviceCommandContext)) { diff --git a/source/graphics/Canvas2D.h b/source/graphics/Canvas2D.h index a62c61ab4a..857b28d003 100644 --- a/source/graphics/Canvas2D.h +++ b/source/graphics/Canvas2D.h @@ -20,7 +20,7 @@ #include "graphics/Texture.h" #include "maths/Vector2D.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include #include @@ -35,7 +35,7 @@ struct CColor; class CCanvas2D { public: - CCanvas2D(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + CCanvas2D(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); ~CCanvas2D(); CCanvas2D(const CCanvas2D&) = delete; diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp index df922ffd71..7778e634fe 100644 --- a/source/graphics/LOSTexture.cpp +++ b/source/graphics/LOSTexture.cpp @@ -26,7 +26,7 @@ #include "ps/CStrInternStatic.h" #include "ps/Game.h" #include "ps/Profile.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" #include "renderer/TimeManager.h" @@ -106,7 +106,7 @@ void CLOSTexture::MakeDirty() m_Dirty = true; } -Renderer::Backend::GL::CTexture* CLOSTexture::GetTextureSmooth() +Renderer::Backend::ITexture* CLOSTexture::GetTextureSmooth() { if (CRenderer::IsInitialised() && !g_RenderingOptions.GetSmoothLOS()) return GetTexture(); @@ -114,7 +114,7 @@ Renderer::Backend::GL::CTexture* CLOSTexture::GetTextureSmooth() return m_SmoothTextures[m_WhichTexture].get(); } -void CLOSTexture::InterpolateLOS(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { const bool skipSmoothLOS = CRenderer::IsInitialised() && !g_RenderingOptions.GetSmoothLOS(); if (!skipSmoothLOS && !m_ShaderInitialized) @@ -209,7 +209,7 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::GL::CDeviceCommandContext* d } -Renderer::Backend::GL::CTexture* CLOSTexture::GetTexture() +Renderer::Backend::ITexture* CLOSTexture::GetTexture() { ENSURE(!m_Dirty); return m_Texture.get(); @@ -227,7 +227,7 @@ const CMatrix3D& CLOSTexture::GetMinimapTextureMatrix() return m_MinimapTextureMatrix; } -void CLOSTexture::ConstructTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void CLOSTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { CmpPtr cmpRangeManager(m_Simulation, SYSTEM_ENTITY); if (!cmpRangeManager) @@ -237,7 +237,7 @@ void CLOSTexture::ConstructTexture(Renderer::Backend::GL::CDeviceCommandContext* const size_t textureSize = round_up_to_pow2(round_up((size_t)m_MapSize + g_BlurSize - 1, g_SubTextureAlignment)); - Renderer::Backend::GL::CDevice* backendDevice = deviceCommandContext->GetDevice(); + Renderer::Backend::IDevice* backendDevice = deviceCommandContext->GetDevice(); const Renderer::Backend::Sampler::Desc defaultSamplerDesc = Renderer::Backend::Sampler::MakeDefaultSampler( @@ -311,7 +311,7 @@ void CLOSTexture::ConstructTexture(Renderer::Backend::GL::CDeviceCommandContext* } } -void CLOSTexture::RecomputeTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void CLOSTexture::RecomputeTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { // If the map was resized, delete and regenerate the texture if (m_Texture) diff --git a/source/graphics/LOSTexture.h b/source/graphics/LOSTexture.h index 6911c007f7..30ea4253a4 100644 --- a/source/graphics/LOSTexture.h +++ b/source/graphics/LOSTexture.h @@ -20,9 +20,9 @@ #include "graphics/ShaderTechniquePtr.h" #include "maths/Matrix3D.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Framebuffer.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/IFramebuffer.h" +#include "renderer/backend/ITexture.h" #include @@ -53,10 +53,10 @@ public: * Also potentially switches the current active texture unit, and enables texturing on it. * The texture is in 8-bit ALPHA format. */ - Renderer::Backend::GL::CTexture* GetTexture(); - Renderer::Backend::GL::CTexture* GetTextureSmooth(); + Renderer::Backend::ITexture* GetTexture(); + Renderer::Backend::ITexture* GetTextureSmooth(); - void InterpolateLOS(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void InterpolateLOS(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Returns a matrix to map (x,y,z) world coordinates onto (u,v) LOS texture @@ -75,8 +75,8 @@ public: private: void DeleteTexture(); bool CreateShader(); - void ConstructTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); - void RecomputeTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void ConstructTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); + void RecomputeTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); size_t GetBitmapSize(size_t w, size_t h, size_t* pitch); void GenerateBitmap(const CLosQuerier& los, u8* losData, size_t w, size_t h, size_t pitch); @@ -87,7 +87,7 @@ private: bool m_ShaderInitialized = false; - std::unique_ptr + std::unique_ptr m_Texture, m_SmoothTextures[2]; uint32_t m_WhichTexture = 0; @@ -95,7 +95,7 @@ private: // We update textures once a frame, so we change a Framebuffer once a frame. // That allows us to use two ping-pong FBOs instead of checking completeness // of Framebuffer each frame. - std::unique_ptr + std::unique_ptr m_SmoothFramebuffers[2]; CShaderTechniquePtr m_SmoothTech; diff --git a/source/graphics/MiniMapTexture.cpp b/source/graphics/MiniMapTexture.cpp index ba82db7d57..6d59e56557 100644 --- a/source/graphics/MiniMapTexture.cpp +++ b/source/graphics/MiniMapTexture.cpp @@ -38,7 +38,7 @@ #include "ps/Game.h" #include "ps/World.h" #include "ps/XML/Xeromyces.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" #include "renderer/SceneRenderer.h" @@ -71,7 +71,7 @@ unsigned int ScaleColor(unsigned int color, float x) } void DrawTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { const float quadUVs[] = { @@ -146,7 +146,7 @@ inline void AddEntity(const MinimapUnitVertex& v, CMiniMapTexture::CMiniMapTexture(CSimulation2& simulation) : m_Simulation(simulation), m_IndexArray(false), - m_VertexArray(Renderer::Backend::GL::CBuffer::Type::VERTEX, true) + m_VertexArray(Renderer::Backend::IBuffer::Type::VERTEX, true) { // Register Relax NG validator. CXeromyces::AddValidator(g_VFS, "pathfinder", "simulation/data/pathfinder.rng"); @@ -210,7 +210,7 @@ void CMiniMapTexture::Update(const float UNUSED(deltaRealTime)) } } -void CMiniMapTexture::Render(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void CMiniMapTexture::Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); if (!terrain) @@ -226,7 +226,7 @@ void CMiniMapTexture::Render(Renderer::Backend::GL::CDeviceCommandContext* devic } void CMiniMapTexture::CreateTextures( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) { DestroyTextures(); @@ -238,7 +238,7 @@ void CMiniMapTexture::CreateTextures( Renderer::Backend::Sampler::Filter::LINEAR, Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE); - Renderer::Backend::GL::CDevice* backendDevice = deviceCommandContext->GetDevice(); + Renderer::Backend::IDevice* backendDevice = deviceCommandContext->GetDevice(); // Create terrain texture m_TerrainTexture = backendDevice->CreateTexture2D("MiniMapTerrainTexture", @@ -272,7 +272,7 @@ void CMiniMapTexture::DestroyTextures() } void CMiniMapTexture::RebuildTerrainTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) { const u32 x = 0; @@ -338,7 +338,7 @@ void CMiniMapTexture::RebuildTerrainTexture( } void CMiniMapTexture::RenderFinalTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { // only update 2x / second // (note: since units only move a few pixels per second on the minimap, @@ -579,7 +579,7 @@ void CMiniMapTexture::RenderFinalTexture( if (m_EntitiesDrawn > 0) { - Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; + Renderer::Backend::IDeviceCommandContext::Rect scissorRect; scissorRect.x = scissorRect.y = 1; scissorRect.width = scissorRect.height = FINAL_TEXTURE_SIZE - 2; deviceCommandContext->SetScissors(1, &scissorRect); diff --git a/source/graphics/MiniMapTexture.h b/source/graphics/MiniMapTexture.h index 9c4b31e1c8..6cf0425964 100644 --- a/source/graphics/MiniMapTexture.h +++ b/source/graphics/MiniMapTexture.h @@ -21,8 +21,8 @@ #include "graphics/Color.h" #include "graphics/Texture.h" #include "maths/Vector2D.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/ITexture.h" #include "renderer/VertexArray.h" #include @@ -46,9 +46,9 @@ public: /** * Redraws the texture if it's dirty. */ - void Render(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); - Renderer::Backend::GL::CTexture* GetTexture() const { return m_FinalTexture.get(); } + Renderer::Backend::ITexture* GetTexture() const { return m_FinalTexture.get(); } /** * @return The maximum height for unit passage in water. @@ -67,14 +67,14 @@ public: private: void CreateTextures( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain); void DestroyTextures(); void RebuildTerrainTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain); void RenderFinalTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); CSimulation2& m_Simulation; @@ -83,10 +83,10 @@ private: double m_LastFinalTextureUpdate = 0.0; // minimap texture handles - std::unique_ptr + std::unique_ptr m_TerrainTexture, m_FinalTexture; - std::unique_ptr + std::unique_ptr m_FinalTextureFramebuffer; // texture data diff --git a/source/graphics/ParticleEmitter.cpp b/source/graphics/ParticleEmitter.cpp index cda3362a07..b5eb50b8ae 100644 --- a/source/graphics/ParticleEmitter.cpp +++ b/source/graphics/ParticleEmitter.cpp @@ -33,7 +33,7 @@ CParticleEmitter::CParticleEmitter(const CParticleEmitterTypePtr& type) : m_Type(type), m_Active(true), m_NextParticleIdx(0), m_EmissionRoundingError(0.f), m_LastUpdateTime(type->m_Manager.GetCurrentTime()), m_IndexArray(false), - m_VertexArray(Renderer::Backend::GL::CBuffer::Type::VERTEX, true), + m_VertexArray(Renderer::Backend::IBuffer::Type::VERTEX, true), m_LastFrameNumber(-1) { // If we should start with particles fully emitted, pretend that we @@ -175,7 +175,7 @@ void CParticleEmitter::PrepareForRendering() } void CParticleEmitter::Bind( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) { m_Type->m_Texture->UploadBackendTextureIfNeeded(deviceCommandContext); @@ -201,7 +201,7 @@ void CParticleEmitter::Bind( } void CParticleEmitter::RenderArray( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m_Particles.empty()) return; diff --git a/source/graphics/ParticleEmitter.h b/source/graphics/ParticleEmitter.h index 981cfc98bd..aa62033f5f 100644 --- a/source/graphics/ParticleEmitter.h +++ b/source/graphics/ParticleEmitter.h @@ -21,7 +21,7 @@ #include "graphics/ModelAbstract.h" #include "graphics/ParticleEmitterType.h" #include "maths/Quaternion.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/backend/IShaderProgram.h" #include "renderer/VertexArray.h" @@ -123,14 +123,14 @@ public: * Bind rendering state (textures and blend modes). */ void Bind( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader); /** * Draw the vertex array. */ void RenderArray( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Stop this emitter emitting new particles, and pass responsibility for rendering diff --git a/source/graphics/ShaderDefines.cpp b/source/graphics/ShaderDefines.cpp index c708b63d40..1ad3313e5e 100644 --- a/source/graphics/ShaderDefines.cpp +++ b/source/graphics/ShaderDefines.cpp @@ -226,7 +226,7 @@ CVector4D CShaderUniforms::GetVector(const char* name) const } void CShaderUniforms::BindUniforms( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) const { for (const SItems::Item& item : m_Items->items) diff --git a/source/graphics/ShaderDefines.h b/source/graphics/ShaderDefines.h index a29f8f369e..fb7e495d66 100644 --- a/source/graphics/ShaderDefines.h +++ b/source/graphics/ShaderDefines.h @@ -20,7 +20,7 @@ #include "ps/CStr.h" #include "ps/CStrIntern.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/backend/IShaderProgram.h" #include @@ -180,7 +180,7 @@ public: * Bind the collection of uniforms onto the given shader. */ void BindUniforms( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) const; }; diff --git a/source/graphics/ShaderManager.cpp b/source/graphics/ShaderManager.cpp index a241188d9b..e862589a9f 100644 --- a/source/graphics/ShaderManager.cpp +++ b/source/graphics/ShaderManager.cpp @@ -31,7 +31,7 @@ #include "ps/Profile.h" #include "ps/XML/Xeromyces.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" @@ -141,6 +141,15 @@ bool CShaderManager::NewEffect(const CStr& name, const CShaderDefines& baseDefin if (ret != PSRETURN_OK) return false; + // By default we assume that we have techinques for every dummy shader. + if (g_VideoMode.GetBackend() == CVideoMode::Backend::DUMMY) + { + const Renderer::Backend::GraphicsPipelineStateDesc passPipelineStateDesc = + Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc(); + tech->SetPasses({{passPipelineStateDesc, LoadProgram("dummy", baseDefines)}}); + return true; + } + // Define all the elements and attributes used in the XML file #define EL(x) int el_##x = XeroFile.GetElementID(#x) #define AT(x) int at_##x = XeroFile.GetAttributeID(#x) diff --git a/source/graphics/ShaderProgram.cpp b/source/graphics/ShaderProgram.cpp index 8b006917d8..d2a6b519ba 100644 --- a/source/graphics/ShaderProgram.cpp +++ b/source/graphics/ShaderProgram.cpp @@ -20,7 +20,7 @@ #include "ShaderProgram.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" CShaderProgram::CShaderProgram(const CStr& name, const CShaderDefines& defines) : m_Name(name), m_Defines(defines) diff --git a/source/graphics/TerrainTextureManager.cpp b/source/graphics/TerrainTextureManager.cpp index 04c17c8c6d..86296defc0 100644 --- a/source/graphics/TerrainTextureManager.cpp +++ b/source/graphics/TerrainTextureManager.cpp @@ -30,7 +30,7 @@ #include "ps/Filesystem.h" #include "ps/VideoMode.h" #include "ps/XML/Xeromyces.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include @@ -306,7 +306,7 @@ CTerrainTextureManager::LoadAlphaMap(const VfsPath& alphaMapType) } void CTerrainTextureManager::UploadResourcesIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { for (const CTerrainTextureManager::TerrainAlphaMap::iterator& it : m_AlphaMapsToUpload) { @@ -314,7 +314,7 @@ void CTerrainTextureManager::UploadResourcesIfNeeded( if (!alphaMap.m_CompositeDataToUpload) continue; // Upload the composite texture. - Renderer::Backend::GL::CTexture* texture = alphaMap.m_CompositeAlphaMap.get(); + Renderer::Backend::ITexture* texture = alphaMap.m_CompositeAlphaMap.get(); deviceCommandContext->UploadTexture( texture, Renderer::Backend::Format::A8_UNORM, alphaMap.m_CompositeDataToUpload.get(), texture->GetWidth() * texture->GetHeight()); diff --git a/source/graphics/TerrainTextureManager.h b/source/graphics/TerrainTextureManager.h index 93231ef9e2..29ebc71639 100644 --- a/source/graphics/TerrainTextureManager.h +++ b/source/graphics/TerrainTextureManager.h @@ -21,8 +21,8 @@ #include "lib/file/vfs/vfs_path.h" #include "ps/CStr.h" #include "ps/Singleton.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/ITexture.h" #include #include @@ -72,7 +72,7 @@ public: struct TerrainAlpha { // Composite alpha map (all the alpha maps packed into one texture). - std::unique_ptr m_CompositeAlphaMap; + std::unique_ptr m_CompositeAlphaMap; // Data is used to separate file loading and uploading to GPU. std::shared_ptr m_CompositeDataToUpload; // Coordinates of each (untransformed) alpha map within the packed texture. @@ -121,7 +121,7 @@ public: CTerrainTextureManager::TerrainAlphaMap::iterator LoadAlphaMap(const VfsPath& alphaMapType); - void UploadResourcesIfNeeded(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void UploadResourcesIfNeeded(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); private: // All texture entries created by this class, for easy freeing now that diff --git a/source/graphics/TerritoryTexture.cpp b/source/graphics/TerritoryTexture.cpp index b84db8cd6c..e4218d5f1c 100644 --- a/source/graphics/TerritoryTexture.cpp +++ b/source/graphics/TerritoryTexture.cpp @@ -23,8 +23,8 @@ #include "graphics/Terrain.h" #include "lib/bits.h" #include "ps/Profile.h" -#include "renderer/backend/gl/Device.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDevice.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/Renderer.h" #include "simulation2/Simulation2.h" #include "simulation2/helpers/Grid.h" @@ -57,7 +57,7 @@ bool CTerritoryTexture::UpdateDirty() return cmpTerritoryManager && cmpTerritoryManager->NeedUpdateTexture(&m_DirtyID); } -Renderer::Backend::GL::CTexture* CTerritoryTexture::GetTexture() +Renderer::Backend::ITexture* CTerritoryTexture::GetTexture() { ENSURE(!UpdateDirty()); return m_Texture.get(); @@ -75,7 +75,7 @@ const CMatrix3D& CTerritoryTexture::GetMinimapTextureMatrix() return m_MinimapTextureMatrix; } -void CTerritoryTexture::ConstructTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void CTerritoryTexture::ConstructTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { CmpPtr cmpTerrain(m_Simulation, SYSTEM_ENTITY); if (!cmpTerrain) @@ -129,7 +129,7 @@ void CTerritoryTexture::ConstructTexture(Renderer::Backend::GL::CDeviceCommandCo } } -void CTerritoryTexture::RecomputeTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void CTerritoryTexture::RecomputeTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { // If the map was resized, delete and regenerate the texture if (m_Texture) @@ -246,7 +246,7 @@ void CTerritoryTexture::GenerateBitmap(const Grid& territories, u8* bitmap, bitmap[(j*w+i)*4 + 3] = 0; } -void CTerritoryTexture::UpdateIfNeeded(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void CTerritoryTexture::UpdateIfNeeded(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (UpdateDirty()) RecomputeTexture(deviceCommandContext); diff --git a/source/graphics/TerritoryTexture.h b/source/graphics/TerritoryTexture.h index a61ab48cef..1e84d0f2f9 100644 --- a/source/graphics/TerritoryTexture.h +++ b/source/graphics/TerritoryTexture.h @@ -16,8 +16,8 @@ */ #include "maths/Matrix3D.h" -#include "renderer/backend/gl/Texture.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/ITexture.h" +#include "renderer/backend/IDeviceCommandContext.h" class CSimulation2; template @@ -40,7 +40,7 @@ public: * Also potentially switches the current active texture unit, and enables texturing on it. * The texture is in 32-bit BGRA format. */ - Renderer::Backend::GL::CTexture* GetTexture(); + Renderer::Backend::ITexture* GetTexture(); /** * Returns a matrix to map (x,y,z) world coordinates onto (u,v) texture @@ -60,7 +60,7 @@ public: * Updates the texture if needed (territory was changed or the texture * wasn't created). */ - void UpdateIfNeeded(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void UpdateIfNeeded(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); private: /** @@ -69,8 +69,8 @@ private: bool UpdateDirty(); void DeleteTexture(); - void ConstructTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); - void RecomputeTexture(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void ConstructTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); + void RecomputeTexture(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); void GenerateBitmap(const Grid& territories, u8* bitmap, ssize_t w, ssize_t h); @@ -78,7 +78,7 @@ private: size_t m_DirtyID; - std::unique_ptr m_Texture; + std::unique_ptr m_Texture; ssize_t m_MapSize; // tiles per side diff --git a/source/graphics/TextRenderer.cpp b/source/graphics/TextRenderer.cpp index 7a1f423a79..86385d0c05 100644 --- a/source/graphics/TextRenderer.cpp +++ b/source/graphics/TextRenderer.cpp @@ -202,7 +202,7 @@ struct SBatchCompare }; void CTextRenderer::Render( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, const CMatrix3D& transform) { std::vector indexes; diff --git a/source/graphics/TextRenderer.h b/source/graphics/TextRenderer.h index 716ec49580..bd3803d450 100644 --- a/source/graphics/TextRenderer.h +++ b/source/graphics/TextRenderer.h @@ -23,7 +23,7 @@ #include "maths/Rect.h" #include "maths/Vector2D.h" #include "ps/CStrIntern.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include @@ -104,7 +104,7 @@ public: * Render all of the previously printed text calls. */ void Render( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, const CMatrix3D& transform); private: diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index cb0d433a03..0d5640b770 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -34,8 +34,7 @@ #include "ps/Filesystem.h" #include "ps/Profile.h" #include "ps/Util.h" -#include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include @@ -115,10 +114,10 @@ public: } void CreateTexture( - std::unique_ptr backendTexture, + std::unique_ptr backendTexture, CTextureManagerImpl* textureManager) { - Renderer::Backend::GL::CTexture* fallback = backendTexture.get(); + Renderer::Backend::ITexture* fallback = backendTexture.get(); CTextureProperties props(VfsPath{}); m_Texture = CTexturePtr(new CTexture( std::move(backendTexture), fallback, props, textureManager)); @@ -133,13 +132,10 @@ private: class CSingleColorTexture final : public CPredefinedTexture { public: - CSingleColorTexture(const CColor& color, const bool disableGL, + CSingleColorTexture(const CColor& color, Renderer::Backend::IDevice* device, CTextureManagerImpl* textureManager) : m_Color(color) { - if (disableGL) - return; - std::stringstream textureName; textureName << "SingleColorTexture ("; textureName << "R:" << m_Color.r << ", "; @@ -147,8 +143,8 @@ public: textureName << "B:" << m_Color.b << ", "; textureName << "A:" << m_Color.a << ")"; - std::unique_ptr backendTexture = - g_VideoMode.GetBackendDevice()->CreateTexture2D( + std::unique_ptr backendTexture = + device->CreateTexture2D( textureName.str().c_str(), Renderer::Backend::Format::R8G8B8A8_UNORM, 1, 1, Renderer::Backend::Sampler::MakeDefaultSampler( @@ -157,7 +153,7 @@ public: CreateTexture(std::move(backendTexture), textureManager); } - void Upload(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + void Upload(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!GetTexture() || !GetTexture()->GetBackendTexture()) return; @@ -182,13 +178,10 @@ private: class CSingleColorTextureCube final : public CPredefinedTexture { public: - CSingleColorTextureCube(const CColor& color, const bool disableGL, + CSingleColorTextureCube(const CColor& color, Renderer::Backend::IDevice* device, CTextureManagerImpl* textureManager) : m_Color(color) { - if (disableGL) - return; - std::stringstream textureName; textureName << "SingleColorTextureCube ("; textureName << "R:" << m_Color.r << ", "; @@ -196,9 +189,9 @@ public: textureName << "B:" << m_Color.b << ", "; textureName << "A:" << m_Color.a << ")"; - std::unique_ptr backendTexture = - g_VideoMode.GetBackendDevice()->CreateTexture( - textureName.str().c_str(), Renderer::Backend::GL::CTexture::Type::TEXTURE_CUBE, + std::unique_ptr backendTexture = + device->CreateTexture( + textureName.str().c_str(), Renderer::Backend::ITexture::Type::TEXTURE_CUBE, Renderer::Backend::Format::R8G8B8A8_UNORM, 1, 1, Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::Filter::LINEAR, @@ -206,7 +199,7 @@ public: CreateTexture(std::move(backendTexture), textureManager); } - void Upload(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + void Upload(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!GetTexture() || !GetTexture()->GetBackendTexture()) return; @@ -240,12 +233,9 @@ public: static const uint32_t NUMBER_OF_LEVELS = 9; CGradientTexture(const CColor& colorFrom, const CColor& colorTo, - const bool disableGL, CTextureManagerImpl* textureManager) + Renderer::Backend::IDevice* device, CTextureManagerImpl* textureManager) : m_ColorFrom(colorFrom), m_ColorTo(colorTo) { - if (disableGL) - return; - std::stringstream textureName; textureName << "GradientTexture"; textureName << " From ("; @@ -259,8 +249,8 @@ public: textureName << "B:" << m_ColorTo.b << ","; textureName << "A:" << m_ColorTo.a << ")"; - std::unique_ptr backendTexture = - g_VideoMode.GetBackendDevice()->CreateTexture2D( + std::unique_ptr backendTexture = + device->CreateTexture2D( textureName.str().c_str(), Renderer::Backend::Format::R8G8B8A8_UNORM, WIDTH, 1, Renderer::Backend::Sampler::MakeDefaultSampler( @@ -270,7 +260,7 @@ public: CreateTexture(std::move(backendTexture), textureManager); } - void Upload(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + void Upload(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!GetTexture() || !GetTexture()->GetBackendTexture()) return; @@ -356,29 +346,25 @@ class CTextureManagerImpl { friend class CTexture; public: - CTextureManagerImpl(PIVFS vfs, bool highQuality, bool disableGL) : - m_VFS(vfs), m_CacheLoader(vfs, L".dds"), m_DisableGL(disableGL), + CTextureManagerImpl(PIVFS vfs, bool highQuality, Renderer::Backend::IDevice* device) : + m_VFS(vfs), m_CacheLoader(vfs, L".dds"), m_Device(device), m_TextureConverter(vfs, highQuality), - m_DefaultTexture(CColor(0.25f, 0.25f, 0.25f, 1.0f), disableGL, this), - m_ErrorTexture(CColor(1.0f, 0.0f, 1.0f, 1.0f), disableGL, this), - m_WhiteTexture(CColor(1.0f, 1.0f, 1.0f, 1.0f), disableGL, this), - m_TransparentTexture(CColor(0.0f, 0.0f, 0.0f, 0.0f), disableGL, this), + m_DefaultTexture(CColor(0.25f, 0.25f, 0.25f, 1.0f), device, this), + m_ErrorTexture(CColor(1.0f, 0.0f, 1.0f, 1.0f), device, this), + m_WhiteTexture(CColor(1.0f, 1.0f, 1.0f, 1.0f), device, this), + m_TransparentTexture(CColor(0.0f, 0.0f, 0.0f, 0.0f), device, this), m_AlphaGradientTexture( - CColor(1.0f, 1.0f, 1.0f, 0.0f), CColor(1.0f, 1.0f, 1.0f, 1.0f), disableGL, this), - m_BlackTextureCube(CColor(0.0f, 0.0f, 0.0f, 1.0f), disableGL, this) + CColor(1.0f, 1.0f, 1.0f, 0.0f), CColor(1.0f, 1.0f, 1.0f, 1.0f), device, this), + m_BlackTextureCube(CColor(0.0f, 0.0f, 0.0f, 1.0f), device, this) { // Allow hotloading of textures RegisterFileReloadFunc(ReloadChangedFileCB, this); - if (disableGL) - return; - - Renderer::Backend::GL::CDevice* backendDevice = g_VideoMode.GetBackendDevice(); m_HasS3TC = - backendDevice->IsTextureFormatSupported(Renderer::Backend::Format::BC1_RGB_UNORM) && - backendDevice->IsTextureFormatSupported(Renderer::Backend::Format::BC1_RGBA_UNORM) && - backendDevice->IsTextureFormatSupported(Renderer::Backend::Format::BC2_UNORM) && - backendDevice->IsTextureFormatSupported(Renderer::Backend::Format::BC3_UNORM); + m_Device->IsTextureFormatSupported(Renderer::Backend::Format::BC1_RGB_UNORM) && + m_Device->IsTextureFormatSupported(Renderer::Backend::Format::BC1_RGBA_UNORM) && + m_Device->IsTextureFormatSupported(Renderer::Backend::Format::BC2_UNORM) && + m_Device->IsTextureFormatSupported(Renderer::Backend::Format::BC3_UNORM); } ~CTextureManagerImpl() @@ -418,8 +404,7 @@ public: { // Construct a new default texture with the given properties to use as the search key CTexturePtr texture(new CTexture( - nullptr, m_DisableGL ? nullptr : m_DefaultTexture.GetTexture()->GetBackendTexture(), - props, this)); + nullptr, m_DefaultTexture.GetTexture()->GetBackendTexture(), props, this)); // Try to find an existing texture with the given properties TextureCache::iterator it = m_TextureCache.find(texture); @@ -435,10 +420,10 @@ public: } CTexturePtr WrapBackendTexture( - std::unique_ptr backendTexture) + std::unique_ptr backendTexture) { ENSURE(backendTexture); - Renderer::Backend::GL::CTexture* fallback = backendTexture.get(); + Renderer::Backend::ITexture* fallback = backendTexture.get(); CTextureProperties props(VfsPath{}); CTexturePtr texture(new CTexture( @@ -454,15 +439,12 @@ public: */ void LoadTexture(const CTexturePtr& texture, const VfsPath& path) { - if (m_DisableGL) - return; - PROFILE2("load texture"); PROFILE2_ATTR("name: %ls", path.string().c_str()); std::shared_ptr fileData; size_t fileSize; - const Status loadStatus = g_VFS->LoadFile(path, fileData, fileSize); + const Status loadStatus = m_VFS->LoadFile(path, fileData, fileSize); if (loadStatus != INFO::OK) { LOGERROR("Texture failed to load; \"%s\" %s", @@ -578,7 +560,7 @@ public: } } - texture->m_BackendTexture = g_VideoMode.GetBackendDevice()->CreateTexture2D( + texture->m_BackendTexture = m_Device->CreateTexture2D( texture->m_Properties.m_Path.string8().c_str(), format, (width >> texture->m_BaseLevelOffset), (height >> texture->m_BaseLevelOffset), defaultSamplerDesc, MIPLevelCount - texture->m_BaseLevelOffset); @@ -767,7 +749,7 @@ public: } bool MakeUploadProgress( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!m_PredefinedTexturesUploaded) { @@ -886,7 +868,7 @@ public: private: PIVFS m_VFS; CCacheLoader m_CacheLoader; - bool m_DisableGL; + Renderer::Backend::IDevice* m_Device = nullptr; CTextureConverter m_TextureConverter; CSingleColorTexture m_DefaultTexture; @@ -918,8 +900,8 @@ private: }; CTexture::CTexture( - std::unique_ptr texture, - Renderer::Backend::GL::CTexture* fallback, + std::unique_ptr texture, + Renderer::Backend::ITexture* fallback, const CTextureProperties& props, CTextureManagerImpl* textureManager) : m_BackendTexture(std::move(texture)), m_FallbackBackendTexture(fallback), m_BaseColor(0), m_State(UNLOADED), m_Properties(props), @@ -930,7 +912,7 @@ CTexture::CTexture( CTexture::~CTexture() = default; void CTexture::UploadBackendTextureIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (IsUploaded()) return; @@ -960,12 +942,12 @@ void CTexture::UploadBackendTextureIfNeeded( m_State = UPLOADED; } -Renderer::Backend::GL::CTexture* CTexture::GetBackendTexture() +Renderer::Backend::ITexture* CTexture::GetBackendTexture() { return m_BackendTexture && IsUploaded() ? m_BackendTexture.get() : m_FallbackBackendTexture; } -const Renderer::Backend::GL::CTexture* CTexture::GetBackendTexture() const +const Renderer::Backend::ITexture* CTexture::GetBackendTexture() const { return m_BackendTexture && IsUploaded() ? m_BackendTexture.get() : m_FallbackBackendTexture; } @@ -1000,8 +982,8 @@ void CTexture::Prefetch() } void CTexture::ResetBackendTexture( - std::unique_ptr backendTexture, - Renderer::Backend::GL::CTexture* fallbackBackendTexture) + std::unique_ptr backendTexture, + Renderer::Backend::ITexture* fallbackBackendTexture) { m_BackendTexture = std::move(backendTexture); m_FallbackBackendTexture = fallbackBackendTexture; @@ -1040,8 +1022,8 @@ size_t CTexture::GetUploadedSize() const // CTextureManager: forward all calls to impl: -CTextureManager::CTextureManager(PIVFS vfs, bool highQuality, bool disableGL) : - m(new CTextureManagerImpl(vfs, highQuality, disableGL)) +CTextureManager::CTextureManager(PIVFS vfs, bool highQuality, Renderer::Backend::IDevice* device) : + m(new CTextureManagerImpl(vfs, highQuality, device)) { } @@ -1056,7 +1038,7 @@ CTexturePtr CTextureManager::CreateTexture(const CTextureProperties& props) } CTexturePtr CTextureManager::WrapBackendTexture( - std::unique_ptr backendTexture) + std::unique_ptr backendTexture) { return m->WrapBackendTexture(std::move(backendTexture)); } @@ -1097,7 +1079,7 @@ bool CTextureManager::MakeProgress() } bool CTextureManager::MakeUploadProgress( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { return m->MakeUploadProgress(deviceCommandContext); } diff --git a/source/graphics/TextureManager.h b/source/graphics/TextureManager.h index 58a8666fb7..7580a56ac7 100644 --- a/source/graphics/TextureManager.h +++ b/source/graphics/TextureManager.h @@ -21,8 +21,9 @@ #include "graphics/Texture.h" #include "lib/file/vfs/vfs.h" #include "lib/tex/tex.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDevice.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/ITexture.h" #include @@ -58,7 +59,7 @@ class CTextureManagerImpl; * These will be loaded in the background, when there are no higher-priority textures * to load. * - * The same texture file can be safely loaded multiple times with different GL parameters + * The same texture file can be safely loaded multiple times with different backend parameters * (but this should be avoided whenever possible, as it wastes VRAM). * * For release packages, DDS files can be precached by appending ".dds" to their name, @@ -77,9 +78,8 @@ public: * Construct texture manager. vfs must be the VFS instance used for all textures * loaded from this object. * highQuality is slower and intended for batch-conversion modes. - * disableGL is intended for tests, and will disable all GL uploads. */ - CTextureManager(PIVFS vfs, bool highQuality, bool disableGL); + CTextureManager(PIVFS vfs, bool highQuality, Renderer::Backend::IDevice* device); ~CTextureManager(); @@ -93,7 +93,7 @@ public: * Wraps a backend texture. */ CTexturePtr WrapBackendTexture( - std::unique_ptr backendTexture); + std::unique_ptr backendTexture); /** * Returns a magenta texture. Use this for highlighting errors @@ -133,7 +133,7 @@ public: * Work on asynchronous texture uploading operations, if any. * Returns true if it did any work. Mostly the same as MakeProgress. */ - bool MakeUploadProgress(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + bool MakeUploadProgress(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Synchronously converts and compresses and saves the texture, @@ -294,13 +294,13 @@ public: * will be uploaded. */ void UploadBackendTextureIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Returns a backend texture if successfully uploaded, else fallback. */ - Renderer::Backend::GL::CTexture* GetBackendTexture(); - const Renderer::Backend::GL::CTexture* GetBackendTexture() const; + Renderer::Backend::ITexture* GetBackendTexture(); + const Renderer::Backend::ITexture* GetBackendTexture() const; /** * Attempt to load the texture data quickly, as with @@ -336,19 +336,19 @@ private: // Only the texture manager can create these explicit CTexture( - std::unique_ptr texture, - Renderer::Backend::GL::CTexture* fallback, + std::unique_ptr texture, + Renderer::Backend::ITexture* fallback, const CTextureProperties& props, CTextureManagerImpl* textureManager); void ResetBackendTexture( - std::unique_ptr backendTexture, - Renderer::Backend::GL::CTexture* fallbackBackendTexture); + std::unique_ptr backendTexture, + Renderer::Backend::ITexture* fallbackBackendTexture); const CTextureProperties m_Properties; - std::unique_ptr m_BackendTexture; + std::unique_ptr m_BackendTexture; // It's possible to m_FallbackBackendTexture references m_BackendTexture. - Renderer::Backend::GL::CTexture* m_FallbackBackendTexture = nullptr; + Renderer::Backend::ITexture* m_FallbackBackendTexture = nullptr; u32 m_BaseColor; std::unique_ptr m_TextureData; size_t m_UploadedSize = 0; diff --git a/source/graphics/tests/test_TextureManager.h b/source/graphics/tests/test_TextureManager.h index ae5ee330e5..c4461bd9b2 100644 --- a/source/graphics/tests/test_TextureManager.h +++ b/source/graphics/tests/test_TextureManager.h @@ -21,16 +21,21 @@ #include "lib/external_libraries/libsdl.h" #include "lib/file/vfs/vfs.h" #include "lib/tex/tex.h" +#include "ps/ConfigDB.h" #include "ps/XML/Xeromyces.h" +#include "renderer/backend/dummy/Device.h" class TestTextureManager : public CxxTest::TestSuite { PIVFS m_VFS; + std::unique_ptr m_Device; public: void setUp() { + CConfigDB::Initialise(); + DeleteDirectory(DataDir()/"_testcache"); // clean up in case the last test run failed m_VFS = CreateVfs(); @@ -38,6 +43,8 @@ public: TS_ASSERT_OK(m_VFS->Mount(L"cache/", DataDir() / "_testcache" / "", 0, VFS_MAX_PRIORITY)); CXeromyces::Startup(); + + m_Device = std::make_unique(); } void tearDown() @@ -46,12 +53,14 @@ public: m_VFS.reset(); DeleteDirectory(DataDir()/"_testcache"); + + CConfigDB::Shutdown(); } void test_load_basic() { { - CTextureManager texman(m_VFS, false, true); + CTextureManager texman(m_VFS, false, m_Device.get()); CTexturePtr t1 = texman.CreateTexture(CTextureProperties(L"art/textures/a/demo.png")); @@ -82,7 +91,7 @@ public: // New texture manager - should use the cached file { - CTextureManager texman(m_VFS, false, true); + CTextureManager texman(m_VFS, false, m_Device.get()); CTexturePtr t1 = texman.CreateTexture(CTextureProperties(L"art/textures/a/demo.png")); @@ -94,7 +103,7 @@ public: void test_load_formats() { - CTextureManager texman(m_VFS, false, true); + CTextureManager texman(m_VFS, false, m_Device.get()); CTexturePtr t1 = texman.CreateTexture(CTextureProperties(L"art/textures/a/demo.tga")); CTexturePtr t2 = texman.CreateTexture(CTextureProperties(L"art/textures/a/demo-abgr.dds")); CTexturePtr t3 = texman.CreateTexture(CTextureProperties(L"art/textures/a/demo-dxt1.dds")); diff --git a/source/gui/CGUIText.cpp b/source/gui/CGUIText.cpp index ea25f89224..7c94d5dc40 100644 --- a/source/gui/CGUIText.cpp +++ b/source/gui/CGUIText.cpp @@ -27,7 +27,7 @@ #include "gui/SettingTypes/CGUIString.h" #include "ps/CStrInternStatic.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/Renderer.h" #include @@ -418,7 +418,7 @@ bool CGUIText::AssembleCalls( void CGUIText::Draw(CGUI& pGUI, CCanvas2D& canvas, const CGUIColor& DefaultColor, const CVector2D& pos, CRect clipping) const { - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); bool isClipped = clipping != CRect(); @@ -431,7 +431,7 @@ void CGUIText::Draw(CGUI& pGUI, CCanvas2D& canvas, const CGUIColor& DefaultColor clipping.right = std::floor(clipping.right); const float scale = g_VideoMode.GetScale(); - Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; + Renderer::Backend::IDeviceCommandContext::Rect scissorRect; scissorRect.x = std::ceil(clipping.left * scale); scissorRect.y = std::ceil(g_yres - clipping.bottom * scale); scissorRect.width = std::floor(clipping.GetWidth() * scale); diff --git a/source/gui/ObjectTypes/CInput.cpp b/source/gui/ObjectTypes/CInput.cpp index cb8b548449..8dc9bf3c2b 100644 --- a/source/gui/ObjectTypes/CInput.cpp +++ b/source/gui/ObjectTypes/CInput.cpp @@ -32,7 +32,7 @@ #include "ps/Globals.h" #include "ps/Hotkey.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/Renderer.h" #include @@ -1191,7 +1191,7 @@ void CInput::UpdateCachedSize() void CInput::Draw(CCanvas2D& canvas) { - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); if (m_CursorBlinkRate > 0.0) @@ -1244,7 +1244,7 @@ void CInput::Draw(CCanvas2D& canvas) if (cliparea != CRect()) { const float scale = g_VideoMode.GetScale(); - Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; + Renderer::Backend::IDeviceCommandContext::Rect scissorRect; scissorRect.x = cliparea.left * scale; scissorRect.y = g_yres - cliparea.bottom * scale; scissorRect.width = cliparea.GetWidth() * scale; diff --git a/source/gui/ObjectTypes/CMiniMap.cpp b/source/gui/ObjectTypes/CMiniMap.cpp index a5d58cd010..bda3572d39 100644 --- a/source/gui/ObjectTypes/CMiniMap.cpp +++ b/source/gui/ObjectTypes/CMiniMap.cpp @@ -95,7 +95,7 @@ void CropPointsByCircle(const std::array& points, const CVector3D& } void DrawTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, float angle, float x, float y, float x2, float y2, float mapScale) { // Rotate the texture coordinates (0,0)-(coordMax,coordMax) around their center point (m,m) @@ -427,7 +427,7 @@ void CMiniMap::Draw(CCanvas2D& canvas) Renderer::Backend::BlendFactor::ONE_MINUS_SRC_ALPHA; pipelineStateDesc.blendState.colorBlendOp = pipelineStateDesc.blendState.alphaBlendOp = Renderer::Backend::BlendOp::ADD; - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); deviceCommandContext->SetGraphicsPipelineState(pipelineStateDesc); deviceCommandContext->BeginPass(); diff --git a/source/main.cpp b/source/main.cpp index 68e9b7b669..837180edd2 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -74,7 +74,7 @@ that of Atlas depending on commandline parameters. #include "graphics/GameView.h" #include "graphics/TextureManager.h" #include "gui/GUIManager.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include "rlinterface/RLInterface.h" #include "scriptinterface/ScriptContext.h" diff --git a/source/ps/ArchiveBuilder.cpp b/source/ps/ArchiveBuilder.cpp index 4b954c5695..6acb75e31b 100644 --- a/source/ps/ArchiveBuilder.cpp +++ b/source/ps/ArchiveBuilder.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -25,6 +25,7 @@ #include "lib/file/archive/archive_zip.h" #include "lib/file/vfs/vfs_util.h" #include "ps/XML/Xeromyces.h" +#include "renderer/backend/dummy/Device.h" #include @@ -76,7 +77,8 @@ void CArchiveBuilder::Build(const OsPath& archive, bool compress) // Use CTextureManager instead of CTextureConverter directly, // so it can deal with all the loading of settings.xml files - CTextureManager textureManager(m_VFS, true, true); + Renderer::Backend::Dummy::CDevice device; + CTextureManager textureManager(m_VFS, true, &device); CColladaManager colladaManager(m_VFS); diff --git a/source/ps/GameSetup/HWDetect.cpp b/source/ps/GameSetup/HWDetect.cpp index 64d11b08b6..ad4de82697 100644 --- a/source/ps/GameSetup/HWDetect.cpp +++ b/source/ps/GameSetup/HWDetect.cpp @@ -37,7 +37,7 @@ #include "ps/scripting/JSInterface_Debug.h" #include "ps/UserReport.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "scriptinterface/FunctionWrapper.h" #include "scriptinterface/JSON.h" #include "scriptinterface/Object.h" @@ -137,7 +137,11 @@ void RunHardwareDetection() ReportFreeType(rq, settings); - g_VideoMode.GetBackendDevice()->Report(rq, settings); + JS::RootedValue backendDeviceSettings(rq.cx); + Script::CreateObject(rq, &backendDeviceSettings); + + g_VideoMode.GetBackendDevice()->Report(rq, backendDeviceSettings); + Script::SetProperty(rq, settings, "renderer_backend", backendDeviceSettings); Script::SetProperty(rq, settings, "video_desktop_xres", g_VideoMode.GetDesktopXRes()); Script::SetProperty(rq, settings, "video_desktop_yres", g_VideoMode.GetDesktopYRes()); @@ -191,7 +195,7 @@ void RunHardwareDetection() Script::SetProperty(rq, settings, "timer_resolution", timer_Resolution()); // The version should be increased for every meaningful change. - const int reportVersion = 18; + const int reportVersion = 19; // Send the same data to the reporting system g_UserReporter.SubmitReport( diff --git a/source/ps/Profiler2GPU.cpp b/source/ps/Profiler2GPU.cpp index abc8b70672..64d0d89906 100644 --- a/source/ps/Profiler2GPU.cpp +++ b/source/ps/Profiler2GPU.cpp @@ -27,6 +27,7 @@ #include "lib/ogl.h" #include "ps/ConfigDB.h" #include "ps/Profiler2.h" +#include "ps/VideoMode.h" #include #include @@ -69,6 +70,8 @@ class CProfiler2GPUARB public: static bool IsSupported() { + if (g_VideoMode.GetBackend() != CVideoMode::Backend::GL) + return false; return ogl_HaveExtension("GL_ARB_timer_query"); } diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index 5c9e87590d..02bdf0c0fd 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -34,7 +34,7 @@ #include "ps/GameSetup/GameSetup.h" #include "ps/Pyrogenesis.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #if CONFIG2_AUDIO #include "soundmanager/SoundManager.h" diff --git a/source/ps/VideoMode.cpp b/source/ps/VideoMode.cpp index f137983282..335f7ee576 100644 --- a/source/ps/VideoMode.cpp +++ b/source/ps/VideoMode.cpp @@ -32,6 +32,7 @@ #include "ps/Game.h" #include "ps/GameSetup/Config.h" #include "ps/Pyrogenesis.h" +#include "renderer/backend/dummy/Device.h" #include "renderer/backend/gl/Device.h" #include "renderer/Renderer.h" @@ -235,6 +236,8 @@ void CVideoMode::ReadConfig() CFG_GET_VAL("rendererbackend", rendererBackend); if (rendererBackend == "glarb") m_Backend = Backend::GL_ARB; + else if (rendererBackend == "dummy") + m_Backend = Backend::DUMMY; else m_Backend = Backend::GL; } @@ -526,6 +529,11 @@ void CVideoMode::Shutdown() bool CVideoMode::CreateBackendDevice(const bool createSDLContext) { + if (m_Backend == Backend::DUMMY) + { + m_BackendDevice = std::make_unique(); + return true; + } m_BackendDevice = Renderer::Backend::GL::CDevice::Create(createSDLContext ? m_Window : nullptr, m_Backend == Backend::GL_ARB); if (!m_BackendDevice && m_Backend == Backend::GL) { diff --git a/source/ps/VideoMode.h b/source/ps/VideoMode.h index ee617a9d44..b89c6ea8a5 100644 --- a/source/ps/VideoMode.h +++ b/source/ps/VideoMode.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -28,10 +28,7 @@ namespace Renderer { namespace Backend { -namespace GL -{ -class CDevice; -} +class IDevice; } } @@ -41,7 +38,8 @@ public: enum class Backend { GL, - GL_ARB + GL_ARB, + DUMMY }; CVideoMode(); @@ -128,7 +126,7 @@ public: Backend GetBackend() const { return m_Backend; } - Renderer::Backend::GL::CDevice* GetBackendDevice() { return m_BackendDevice.get(); } + Renderer::Backend::IDevice* GetBackendDevice() { return m_BackendDevice.get(); } private: void ReadConfig(); @@ -184,7 +182,7 @@ private: std::unique_ptr m_Cursor; Backend m_Backend = Backend::GL; - std::unique_ptr m_BackendDevice; + std::unique_ptr m_BackendDevice; }; extern CVideoMode g_VideoMode; diff --git a/source/renderer/DebugRenderer.cpp b/source/renderer/DebugRenderer.cpp index e592802066..5b3857489a 100644 --- a/source/renderer/DebugRenderer.cpp +++ b/source/renderer/DebugRenderer.cpp @@ -28,7 +28,7 @@ #include "maths/Matrix3D.h" #include "maths/Vector3D.h" #include "ps/CStrInternStatic.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/Renderer.h" #include "renderer/SceneRenderer.h" @@ -38,7 +38,7 @@ namespace { void SetGraphicsPipelineStateFromTechAndColor( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderTechniquePtr& tech, const CColor& color, const bool depthTestEnabled = true, const bool wireframe = false) { @@ -80,7 +80,7 @@ void CDebugRenderer::DrawLine( { CShaderTechniquePtr debugLineTech = g_Renderer.GetShaderManager().LoadEffect(str_debug_line); - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); SetGraphicsPipelineStateFromTechAndColor( deviceCommandContext, debugLineTech, color, depthTestEnabled); @@ -138,7 +138,7 @@ void CDebugRenderer::DrawCircle(const CVector3D& origin, const float radius, con { CShaderTechniquePtr debugCircleTech = g_Renderer.GetShaderManager().LoadEffect(str_debug_line); - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); SetGraphicsPipelineStateFromTechAndColor( deviceCommandContext, debugCircleTech, color); @@ -202,7 +202,7 @@ void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& colo CShaderTechniquePtr overlayTech = g_Renderer.GetShaderManager().LoadEffect(str_debug_line); - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); SetGraphicsPipelineStateFromTechAndColor( deviceCommandContext, overlayTech, color, true, wireframe); @@ -301,7 +301,7 @@ void CDebugRenderer::DrawBoundingBox( const CMatrix3D& transform, bool wireframe) { CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_solid); - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); SetGraphicsPipelineStateFromTechAndColor( deviceCommandContext, shaderTech, color, true, wireframe); @@ -348,7 +348,7 @@ void CDebugRenderer::DrawBoundingBox( void CDebugRenderer::DrawBrush(const CBrush& brush, const CColor& color, bool wireframe) { CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_solid); - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); SetGraphicsPipelineStateFromTechAndColor( deviceCommandContext, shaderTech, color, true, wireframe); diff --git a/source/renderer/DecalRData.cpp b/source/renderer/DecalRData.cpp index 590fe13b2d..02d3fcaf44 100644 --- a/source/renderer/DecalRData.cpp +++ b/source/renderer/DecalRData.cpp @@ -95,7 +95,7 @@ void CDecalRData::Update(CSimulation2* simulation) } void CDecalRData::RenderDecals( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& decals, const CShaderDefines& context, ShadowMap* shadow) { PROFILE3("render terrain decals"); @@ -324,7 +324,7 @@ void CDecalRData::BuildVertexData() { m_VBDecals = g_VBMan.AllocateChunk( sizeof(SDecalVertex), vertices.size(), - Renderer::Backend::GL::CBuffer::Type::VERTEX, false); + Renderer::Backend::IBuffer::Type::VERTEX, false); } m_VBDecals->m_Owner->UpdateChunkVertices(m_VBDecals.Get(), vertices.data()); @@ -366,7 +366,7 @@ void CDecalRData::BuildVertexData() { m_VBDecalsIndices = g_VBMan.AllocateChunk( sizeof(u16), indices.size(), - Renderer::Backend::GL::CBuffer::Type::INDEX, false); + Renderer::Backend::IBuffer::Type::INDEX, false); } m_VBDecalsIndices->m_Owner->UpdateChunkVertices(m_VBDecalsIndices.Get(), indices.data()); } diff --git a/source/renderer/DecalRData.h b/source/renderer/DecalRData.h index 9a3af9582d..2c195b32d8 100644 --- a/source/renderer/DecalRData.h +++ b/source/renderer/DecalRData.h @@ -21,7 +21,7 @@ #include "graphics/RenderableObject.h" #include "maths/Vector2D.h" #include "maths/Vector3D.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/VertexBufferManager.h" #include @@ -40,7 +40,7 @@ public: void Update(CSimulation2* simulation); static void RenderDecals( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& decals, const CShaderDefines& context, ShadowMap* shadow); CModelDecal* GetDecal() { return m_Decal; } diff --git a/source/renderer/HWLightingModelRenderer.cpp b/source/renderer/HWLightingModelRenderer.cpp index f900d262e0..7d5452d41e 100644 --- a/source/renderer/HWLightingModelRenderer.cpp +++ b/source/renderer/HWLightingModelRenderer.cpp @@ -49,7 +49,7 @@ struct ShaderModelDef : public CModelDefRPrivate ShaderModelDef::ShaderModelDef(const CModelDefPtr& mdef) : m_IndexArray(false), - m_Array(Renderer::Backend::GL::CBuffer::Type::VERTEX, false) + m_Array(Renderer::Backend::IBuffer::Type::VERTEX, false) { size_t numVertices = mdef->GetNumVertices(); @@ -91,7 +91,7 @@ struct ShaderModel : public CModelRData ShaderModel(const void* key) : CModelRData(key), - m_Array(Renderer::Backend::GL::CBuffer::Type::VERTEX, true) + m_Array(Renderer::Backend::IBuffer::Type::VERTEX, true) {} }; @@ -179,13 +179,13 @@ void ShaderModelVertexRenderer::BeginPass() // Cleanup one rendering pass void ShaderModelVertexRenderer::EndPass( - Renderer::Backend::GL::CDeviceCommandContext* UNUSED(deviceCommandContext)) + Renderer::Backend::IDeviceCommandContext* UNUSED(deviceCommandContext)) { } // Prepare UV coordinates for this modeldef void ShaderModelVertexRenderer::PrepareModelDef( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CModelDef& def) { m->shadermodeldef = (ShaderModelDef*)def.GetRenderData(m); @@ -214,7 +214,7 @@ void ShaderModelVertexRenderer::PrepareModelDef( // Render one model void ShaderModelVertexRenderer::RenderModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* UNUSED(shader), CModel* model, CModelRData* data) { const CModelDefPtr& mdldef = model->GetModelDef(); diff --git a/source/renderer/HWLightingModelRenderer.h b/source/renderer/HWLightingModelRenderer.h index 440fa4c500..664f9a4c4a 100644 --- a/source/renderer/HWLightingModelRenderer.h +++ b/source/renderer/HWLightingModelRenderer.h @@ -41,12 +41,12 @@ public: void BeginPass() override; void EndPass( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) override; + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) override; void PrepareModelDef( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CModelDef& def) override; void RenderModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, CModel* model, CModelRData* data) override; protected: diff --git a/source/renderer/InstancingModelRenderer.cpp b/source/renderer/InstancingModelRenderer.cpp index bdbe17527d..40d7b15e9e 100644 --- a/source/renderer/InstancingModelRenderer.cpp +++ b/source/renderer/InstancingModelRenderer.cpp @@ -55,7 +55,7 @@ struct IModelDef : public CModelDefRPrivate IModelDef::IModelDef(const CModelDefPtr& mdef, bool gpuSkinning, bool calculateTangents) - : m_IndexArray(false), m_Array(Renderer::Backend::GL::CBuffer::Type::VERTEX, false) + : m_IndexArray(false), m_Array(Renderer::Backend::IBuffer::Type::VERTEX, false) { size_t numVertices = mdef->GetNumVertices(); @@ -300,13 +300,13 @@ void InstancingModelRenderer::BeginPass() // Cleanup rendering pass. void InstancingModelRenderer::EndPass( - Renderer::Backend::GL::CDeviceCommandContext* UNUSED(deviceCommandContext)) + Renderer::Backend::IDeviceCommandContext* UNUSED(deviceCommandContext)) { } // Prepare UV coordinates for this modeldef void InstancingModelRenderer::PrepareModelDef( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CModelDef& def) { m->imodeldef = (IModelDef*)def.GetRenderData(m); @@ -367,7 +367,7 @@ void InstancingModelRenderer::PrepareModelDef( // Render one model void InstancingModelRenderer::RenderModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, CModel* model, CModelRData* UNUSED(data)) { const CModelDefPtr& mdldef = model->GetModelDef(); diff --git a/source/renderer/InstancingModelRenderer.h b/source/renderer/InstancingModelRenderer.h index 0f7aa57c38..f8b570d6db 100644 --- a/source/renderer/InstancingModelRenderer.h +++ b/source/renderer/InstancingModelRenderer.h @@ -44,11 +44,11 @@ public: void BeginPass() override; void EndPass( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) override; + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) override; void PrepareModelDef( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CModelDef& def) override; - void RenderModel(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + void RenderModel(Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, CModel* model, CModelRData* data) override; protected: diff --git a/source/renderer/ModelRenderer.cpp b/source/renderer/ModelRenderer.cpp index 3c3ffbe893..88cb51fbcd 100644 --- a/source/renderer/ModelRenderer.cpp +++ b/source/renderer/ModelRenderer.cpp @@ -345,7 +345,7 @@ struct SMRCompareTechBucket }; void ShaderModelRenderer::Render( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const RenderModifierPtr& modifier, const CShaderDefines& context, int cullGroup, int flags) { if (m->submissions[cullGroup].empty()) diff --git a/source/renderer/ModelRenderer.h b/source/renderer/ModelRenderer.h index e1bbe43407..bb2f0fd487 100644 --- a/source/renderer/ModelRenderer.h +++ b/source/renderer/ModelRenderer.h @@ -29,7 +29,7 @@ #include "graphics/MeshManager.h" #include "graphics/RenderableObject.h" #include "graphics/SColor.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/VertexArray.h" class RenderModifier; @@ -159,7 +159,7 @@ public: * CModel::GetFlags() are rendered. */ virtual void Render( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const RenderModifierPtr& modifier, const CShaderDefines& context, int cullGroup, int flags) = 0; /** @@ -268,7 +268,7 @@ public: virtual void PrepareModels(); virtual void EndFrame(); virtual void Render( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const RenderModifierPtr& modifier, const CShaderDefines& context, int cullGroup, int flags); private: diff --git a/source/renderer/ModelVertexRenderer.h b/source/renderer/ModelVertexRenderer.h index a82abf1e51..b6180ddd62 100644 --- a/source/renderer/ModelVertexRenderer.h +++ b/source/renderer/ModelVertexRenderer.h @@ -25,7 +25,7 @@ #include "graphics/MeshManager.h" #include "graphics/ShaderProgramPtr.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/backend/IShaderProgram.h" class CModel; @@ -110,7 +110,7 @@ public: * ModelRenderer implementations must call this function after * rendering related functions for one pass have been called. */ - virtual void EndPass(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) = 0; + virtual void EndPass(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) = 0; /** @@ -125,7 +125,7 @@ public: * @param def The model definition. */ virtual void PrepareModelDef( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CModelDef& def) = 0; @@ -146,7 +146,7 @@ public: * succeed. */ virtual void RenderModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, CModel* model, CModelRData* data) = 0; }; diff --git a/source/renderer/OverlayRenderer.cpp b/source/renderer/OverlayRenderer.cpp index d723baa1c7..6295ca6fe3 100644 --- a/source/renderer/OverlayRenderer.cpp +++ b/source/renderer/OverlayRenderer.cpp @@ -154,7 +154,7 @@ struct OverlayRendererInternals const float OverlayRenderer::OVERLAY_VOFFSET = 0.2f; OverlayRendererInternals::OverlayRendererInternals() - : quadVertices(Renderer::Backend::GL::CBuffer::Type::VERTEX, true), + : quadVertices(Renderer::Backend::IBuffer::Type::VERTEX, true), quadIndices(false) { quadAttributePos.format = Renderer::Backend::Format::R32G32B32_SFLOAT; @@ -368,7 +368,7 @@ void OverlayRenderer::PrepareForRendering() } void OverlayRenderer::RenderOverlaysBeforeWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { PROFILE3_GPU("overlays (before)"); GPU_SCOPED_LABEL(deviceCommandContext, "Render overlays before water"); @@ -383,7 +383,7 @@ void OverlayRenderer::RenderOverlaysBeforeWater( } void OverlayRenderer::RenderOverlaysAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { PROFILE3_GPU("overlays (after)"); GPU_SCOPED_LABEL(deviceCommandContext, "Render overlays after water"); @@ -393,7 +393,7 @@ void OverlayRenderer::RenderOverlaysAfterWater( RenderSphereOverlays(deviceCommandContext); } -void OverlayRenderer::RenderTexturedOverlayLines(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) +void OverlayRenderer::RenderTexturedOverlayLines(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m->texlines.empty()) return; @@ -477,7 +477,7 @@ void OverlayRenderer::RenderTexturedOverlayLines(Renderer::Backend::GL::CDeviceC } void OverlayRenderer::RenderTexturedOverlayLines( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, bool alwaysVisible) { for (size_t i = 0; i < m->texlines.size(); ++i) @@ -494,7 +494,7 @@ void OverlayRenderer::RenderTexturedOverlayLines( } void OverlayRenderer::RenderQuadOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m->quadBatchMap.empty()) return; @@ -589,7 +589,7 @@ void OverlayRenderer::RenderQuadOverlays( } void OverlayRenderer::RenderForegroundOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CCamera& viewCamera) { PROFILE3_GPU("overlays (fg)"); @@ -739,7 +739,7 @@ void OverlayRendererInternals::GenerateSphere() } void OverlayRenderer::RenderSphereOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { PROFILE3_GPU("overlays (spheres)"); diff --git a/source/renderer/OverlayRenderer.h b/source/renderer/OverlayRenderer.h index 66d9b2fa79..5ed7c48575 100644 --- a/source/renderer/OverlayRenderer.h +++ b/source/renderer/OverlayRenderer.h @@ -19,7 +19,7 @@ #define INCLUDED_OVERLAYRENDERER #include "graphics/ShaderProgram.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" struct SOverlayLine; struct SOverlayTexturedLine; @@ -101,7 +101,7 @@ public: * and should be drawn before water (i.e. may be visible under the water) */ void RenderOverlaysBeforeWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Render all the submitted overlays that are embedded in the world @@ -109,7 +109,7 @@ public: * and should be drawn after water (i.e. may be visible on top of the water) */ void RenderOverlaysAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Render all the submitted overlays that should appear on top of everything @@ -117,7 +117,7 @@ public: * @param viewCamera camera to be used for billboard computations */ void RenderForegroundOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CCamera& viewCamera); /// Small vertical offset of overlays from terrain to prevent visual glitches @@ -130,7 +130,7 @@ private: * renders textured overlay lines batched according to their visibility status by delegating * to RenderTexturedOverlayLines(CShaderProgramPtr, bool). */ - void RenderTexturedOverlayLines(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void RenderTexturedOverlayLines(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Helper method; renders those overlay lines currently registered in the internals (i.e. @@ -139,18 +139,18 @@ private: * requires a separate shader to be used. */ void RenderTexturedOverlayLines( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, bool alwaysVisible); /** * Helper method; batch-renders all registered quad overlays, batched by their texture for effiency. */ - void RenderQuadOverlays(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void RenderQuadOverlays(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Helper method; batch-renders all sphere quad overlays. */ - void RenderSphereOverlays(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void RenderSphereOverlays(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); private: OverlayRendererInternals* m; diff --git a/source/renderer/ParticleRenderer.cpp b/source/renderer/ParticleRenderer.cpp index 7d64f67271..4208ccb0a4 100644 --- a/source/renderer/ParticleRenderer.cpp +++ b/source/renderer/ParticleRenderer.cpp @@ -127,7 +127,7 @@ void ParticleRenderer::PrepareForRendering(const CShaderDefines& context) } void ParticleRenderer::RenderParticles( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup, bool wireframe) { CShaderTechnique* lastTech = nullptr; diff --git a/source/renderer/ParticleRenderer.h b/source/renderer/ParticleRenderer.h index 7910807dad..c080dc5ef1 100644 --- a/source/renderer/ParticleRenderer.h +++ b/source/renderer/ParticleRenderer.h @@ -18,7 +18,7 @@ #ifndef INCLUDED_PARTICLERENDERER #define INCLUDED_PARTICLERENDERER -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" class CParticleEmitter; class CShaderDefines; @@ -56,7 +56,7 @@ public: * Render all the submitted particles. */ void RenderParticles( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup, bool wireframe = false); /** diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 9fe1787610..ec61001620 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -283,7 +283,7 @@ void CPatchRData::BuildBlends() m_VBBlends = g_VBMan.AllocateChunk( sizeof(SBlendVertex), blendVertices.size(), - Renderer::Backend::GL::CBuffer::Type::VERTEX, false, + Renderer::Backend::IBuffer::Type::VERTEX, false, nullptr, CVertexBufferManager::Group::TERRAIN); m_VBBlends->m_Owner->UpdateChunkVertices(m_VBBlends.Get(), &blendVertices[0]); @@ -293,7 +293,7 @@ void CPatchRData::BuildBlends() m_VBBlendIndices = g_VBMan.AllocateChunk( sizeof(u16), blendIndices.size(), - Renderer::Backend::GL::CBuffer::Type::INDEX, false, + Renderer::Backend::IBuffer::Type::INDEX, false, nullptr, CVertexBufferManager::Group::TERRAIN); m_VBBlendIndices->m_Owner->UpdateChunkVertices(m_VBBlendIndices.Get(), &blendIndices[0]); } @@ -497,7 +497,7 @@ void CPatchRData::BuildIndices() // Construct vertex buffer m_VBBaseIndices = g_VBMan.AllocateChunk( sizeof(u16), indices.size(), - Renderer::Backend::GL::CBuffer::Type::INDEX, false, nullptr, CVertexBufferManager::Group::TERRAIN); + Renderer::Backend::IBuffer::Type::INDEX, false, nullptr, CVertexBufferManager::Group::TERRAIN); m_VBBaseIndices->m_Owner->UpdateChunkVertices(m_VBBaseIndices.Get(), &indices[0]); } @@ -543,7 +543,7 @@ void CPatchRData::BuildVertices() { m_VBBase = g_VBMan.AllocateChunk( sizeof(SBaseVertex), vsize * vsize, - Renderer::Backend::GL::CBuffer::Type::VERTEX, false, + Renderer::Backend::IBuffer::Type::VERTEX, false, nullptr, CVertexBufferManager::Group::TERRAIN); } @@ -637,7 +637,7 @@ void CPatchRData::BuildSides() { m_VBSides = g_VBMan.AllocateChunk( sizeof(SSideVertex), sideVertices.size(), - Renderer::Backend::GL::CBuffer::Type::VERTEX, false, + Renderer::Backend::IBuffer::Type::VERTEX, false, nullptr, CVertexBufferManager::Group::DEFAULT); } m_VBSides->m_Owner->UpdateChunkVertices(m_VBSides.Get(), &sideVertices[0]); @@ -715,7 +715,7 @@ using TextureBatches = PooledBatchMap, TextureBatches>; void CPatchRData::RenderBases( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches, const CShaderDefines& context, ShadowMap* shadow) { PROFILE3("render terrain bases"); @@ -887,7 +887,7 @@ struct SBlendStackItem }; void CPatchRData::RenderBlends( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches, const CShaderDefines& context, ShadowMap* shadow) { PROFILE3("render terrain blends"); @@ -1009,7 +1009,7 @@ void CPatchRData::RenderBlends( Renderer::Backend::IShaderProgram* shader = techBase->GetShader(pass); TerrainRenderer::PrepareShader(deviceCommandContext, shader, shadow); - Renderer::Backend::GL::CTexture* lastBlendTex = nullptr; + Renderer::Backend::ITexture* lastBlendTex = nullptr; const int32_t baseTexBindingSlot = shader->GetBindingSlot(str_baseTex); @@ -1035,7 +1035,7 @@ void CPatchRData::RenderBlends( samp.Sampler->GetBackendTexture()); } - Renderer::Backend::GL::CTexture* currentBlendTex = itt->m_Texture->m_TerrainAlpha->second.m_CompositeAlphaMap.get(); + Renderer::Backend::ITexture* currentBlendTex = itt->m_Texture->m_TerrainAlpha->second.m_CompositeAlphaMap.get(); if (currentBlendTex != lastBlendTex) { deviceCommandContext->SetTexture( @@ -1110,7 +1110,7 @@ void CPatchRData::RenderBlends( } void CPatchRData::RenderStreams( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches, const bool bindPositionAsTexCoord) { PROFILE3("render terrain streams"); @@ -1210,7 +1210,7 @@ void CPatchRData::RenderOutline() } void CPatchRData::RenderSides( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches) { PROFILE3("render terrain sides"); @@ -1446,13 +1446,13 @@ void CPatchRData::BuildWater() { m_VBWater = g_VBMan.AllocateChunk( sizeof(SWaterVertex), water_vertex_data.size(), - Renderer::Backend::GL::CBuffer::Type::VERTEX, false, + Renderer::Backend::IBuffer::Type::VERTEX, false, nullptr, CVertexBufferManager::Group::WATER); m_VBWater->m_Owner->UpdateChunkVertices(m_VBWater.Get(), &water_vertex_data[0]); m_VBWaterIndices = g_VBMan.AllocateChunk( sizeof(GLushort), water_indices.size(), - Renderer::Backend::GL::CBuffer::Type::INDEX, false, + Renderer::Backend::IBuffer::Type::INDEX, false, nullptr, CVertexBufferManager::Group::WATER); m_VBWaterIndices->m_Owner->UpdateChunkVertices(m_VBWaterIndices.Get(), &water_indices[0]); } @@ -1461,21 +1461,21 @@ void CPatchRData::BuildWater() { m_VBWaterShore = g_VBMan.AllocateChunk( sizeof(SWaterVertex), water_vertex_data_shore.size(), - Renderer::Backend::GL::CBuffer::Type::VERTEX, false, + Renderer::Backend::IBuffer::Type::VERTEX, false, nullptr, CVertexBufferManager::Group::WATER); m_VBWaterShore->m_Owner->UpdateChunkVertices(m_VBWaterShore.Get(), &water_vertex_data_shore[0]); // Construct indices buffer m_VBWaterIndicesShore = g_VBMan.AllocateChunk( sizeof(GLushort), water_indices_shore.size(), - Renderer::Backend::GL::CBuffer::Type::INDEX, false, + Renderer::Backend::IBuffer::Type::INDEX, false, nullptr, CVertexBufferManager::Group::WATER); m_VBWaterIndicesShore->m_Owner->UpdateChunkVertices(m_VBWaterIndicesShore.Get(), &water_indices_shore[0]); } } void CPatchRData::RenderWaterSurface( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const bool bindWaterData) { ASSERT(m_UpdateFlags == 0); @@ -1511,7 +1511,7 @@ void CPatchRData::RenderWaterSurface( } void CPatchRData::RenderWaterShore( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ASSERT(m_UpdateFlags == 0); diff --git a/source/renderer/PatchRData.h b/source/renderer/PatchRData.h index 51859eb334..b50bad966b 100644 --- a/source/renderer/PatchRData.h +++ b/source/renderer/PatchRData.h @@ -22,7 +22,7 @@ #include "graphics/RenderableObject.h" #include "maths/Vector2D.h" #include "maths/Vector3D.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/backend/IShaderProgram.h" #include "renderer/VertexBufferManager.h" @@ -49,26 +49,26 @@ public: void RenderPriorities(CTextRenderer& textRenderer); void RenderWaterSurface( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const bool bindWaterData); void RenderWaterShore( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); CPatch* GetPatch() { return m_Patch; } const CBoundingBoxAligned& GetWaterBounds() const { return m_WaterBounds; } static void RenderBases( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches, const CShaderDefines& context, ShadowMap* shadow); static void RenderBlends( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches, const CShaderDefines& context, ShadowMap* shadow); static void RenderStreams( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches, const bool bindPositionAsTexCoord); static void RenderSides( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches); static void PrepareShader(ShadowMap* shadow); diff --git a/source/renderer/PostprocManager.cpp b/source/renderer/PostprocManager.cpp index 935b1d49b2..27d6527491 100644 --- a/source/renderer/PostprocManager.cpp +++ b/source/renderer/PostprocManager.cpp @@ -31,7 +31,7 @@ #include "ps/Game.h" #include "ps/VideoMode.h" #include "ps/World.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" #include "tools/atlas/GameInterface/GameLoop.h" @@ -122,7 +122,7 @@ void CPostprocManager::RecreateBuffers() { Cleanup(); - Renderer::Backend::GL::CDevice* backendDevice = g_VideoMode.GetBackendDevice(); + Renderer::Backend::IDevice* backendDevice = g_VideoMode.GetBackendDevice(); #define GEN_BUFFER_RGBA(name, w, h) \ name = backendDevice->CreateTexture2D( \ @@ -186,9 +186,9 @@ void CPostprocManager::RecreateBuffers() void CPostprocManager::ApplyBlurDownscale2x( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, - Renderer::Backend::GL::CFramebuffer* framebuffer, - Renderer::Backend::GL::CTexture* inTex, int inWidth, int inHeight) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IFramebuffer* framebuffer, + Renderer::Backend::ITexture* inTex, int inWidth, int inHeight) { deviceCommandContext->SetFramebuffer(framebuffer); @@ -249,11 +249,11 @@ void CPostprocManager::ApplyBlurDownscale2x( } void CPostprocManager::ApplyBlurGauss( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, - Renderer::Backend::GL::CTexture* inTex, - Renderer::Backend::GL::CTexture* tempTex, - Renderer::Backend::GL::CFramebuffer* tempFramebuffer, - Renderer::Backend::GL::CFramebuffer* outFramebuffer, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + Renderer::Backend::ITexture* inTex, + Renderer::Backend::ITexture* tempTex, + Renderer::Backend::IFramebuffer* tempFramebuffer, + Renderer::Backend::IFramebuffer* outFramebuffer, int inWidth, int inHeight) { deviceCommandContext->SetFramebuffer(tempFramebuffer); @@ -351,10 +351,10 @@ void CPostprocManager::ApplyBlurGauss( } void CPostprocManager::ApplyBlur( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { uint32_t width = m_Width, height = m_Height; - Renderer::Backend::GL::CTexture* previousTexture = + Renderer::Backend::ITexture* previousTexture = (m_WhichBuffer ? m_ColorTex1 : m_ColorTex2).get(); for (BlurScale& scale : m_BlurScales) @@ -370,7 +370,7 @@ void CPostprocManager::ApplyBlur( void CPostprocManager::CaptureRenderOutput( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ENSURE(m_IsInitialized); @@ -386,7 +386,7 @@ void CPostprocManager::CaptureRenderOutput( void CPostprocManager::ReleaseRenderOutput( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ENSURE(m_IsInitialized); @@ -402,7 +402,7 @@ void CPostprocManager::ReleaseRenderOutput( } void CPostprocManager::ApplyEffect( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderTechniquePtr& shaderTech, int pass) { // select the other FBO for rendering @@ -481,7 +481,7 @@ void CPostprocManager::ApplyEffect( } void CPostprocManager::ApplyPostproc( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ENSURE(m_IsInitialized); @@ -635,10 +635,10 @@ void CPostprocManager::SetDepthBufferClipPlanes(float nearPlane, float farPlane) void CPostprocManager::CreateMultisampleBuffer() { - Renderer::Backend::GL::CDevice* backendDevice = g_VideoMode.GetBackendDevice(); + Renderer::Backend::IDevice* backendDevice = g_VideoMode.GetBackendDevice(); m_MultisampleColorTex = backendDevice->CreateTexture("PostProcColorMS", - Renderer::Backend::GL::CTexture::Type::TEXTURE_2D_MULTISAMPLE, + Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE, Renderer::Backend::Format::R8G8B8A8_UNORM, m_Width, m_Height, Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::Filter::LINEAR, @@ -646,7 +646,7 @@ void CPostprocManager::CreateMultisampleBuffer() // Allocate the Depth/Stencil texture. m_MultisampleDepthTex = backendDevice->CreateTexture("PostProcDepthMS", - Renderer::Backend::GL::CTexture::Type::TEXTURE_2D_MULTISAMPLE, + Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE, Renderer::Backend::Format::D24_S8, m_Width, m_Height, Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::Filter::LINEAR, @@ -680,7 +680,7 @@ bool CPostprocManager::IsMultisampleEnabled() const } void CPostprocManager::ResolveMultisampleFramebuffer( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!m_UsingMultisampleBuffer) return; diff --git a/source/renderer/PostprocManager.h b/source/renderer/PostprocManager.h index a3c021f423..a76fe668c2 100644 --- a/source/renderer/PostprocManager.h +++ b/source/renderer/PostprocManager.h @@ -20,9 +20,9 @@ #include "graphics/ShaderTechniquePtr.h" #include "ps/CStr.h" -#include "renderer/backend/gl/Framebuffer.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IFramebuffer.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/ITexture.h" #include #include @@ -66,39 +66,39 @@ public: // to our textures instead of directly to the system framebuffer. // @note CPostprocManager must be initialized first void CaptureRenderOutput( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); // First renders blur textures, then calls ApplyEffect for each effect pass, // ping-ponging the buffers at each step. // @note CPostprocManager must be initialized first void ApplyPostproc( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); // Blits the final postprocessed texture to the system framebuffer. The system framebuffer // is selected as the output buffer. Should be called before silhouette rendering. // @note CPostprocManager must be initialized first - void ReleaseRenderOutput(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void ReleaseRenderOutput(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); // Returns true if we render main scene in the MSAA framebuffer. bool IsMultisampleEnabled() const; // Resolves the MSAA framebuffer into the regular one. void ResolveMultisampleFramebuffer( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); private: void CreateMultisampleBuffer(); void DestroyMultisampleBuffer(); // Two framebuffers, that we flip between at each shader pass. - std::unique_ptr + std::unique_ptr m_CaptureFramebuffer, m_PingFramebuffer, m_PongFramebuffer; // Unique color textures for the framebuffers. - std::unique_ptr m_ColorTex1, m_ColorTex2; + std::unique_ptr m_ColorTex1, m_ColorTex2; // The framebuffers share a depth/stencil texture. - std::unique_ptr m_DepthTex; + std::unique_ptr m_DepthTex; float m_NearPlane, m_FarPlane; // A framebuffer and textures x2 for each blur level we render. @@ -106,8 +106,8 @@ private: { struct Step { - std::unique_ptr framebuffer; - std::unique_ptr texture; + std::unique_ptr framebuffer; + std::unique_ptr texture; }; std::array steps; }; @@ -128,8 +128,8 @@ private: CStr m_AAName; CShaderTechniquePtr m_AATech; bool m_UsingMultisampleBuffer; - std::unique_ptr m_MultisampleFramebuffer; - std::unique_ptr + std::unique_ptr m_MultisampleFramebuffer; + std::unique_ptr m_MultisampleColorTex, m_MultisampleDepthTex; uint32_t m_MultisampleCount; std::vector m_AllowedSampleCounts; @@ -142,25 +142,25 @@ private: // Creates blur textures at various scales, for bloom, DOF, etc. void ApplyBlur( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); // High quality GPU image scaling to half size. outTex must have exactly half the size // of inTex. inWidth and inHeight are the dimensions of inTex in texels. void ApplyBlurDownscale2x( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, - Renderer::Backend::GL::CFramebuffer* framebuffer, - Renderer::Backend::GL::CTexture* inTex, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IFramebuffer* framebuffer, + Renderer::Backend::ITexture* inTex, int inWidth, int inHeight); // GPU-based Gaussian blur in two passes. inOutTex contains the input image and will be filled // with the blurred image. tempTex must have the same size as inOutTex. // inWidth and inHeight are the dimensions of the images in texels. void ApplyBlurGauss( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, - Renderer::Backend::GL::CTexture* inTex, - Renderer::Backend::GL::CTexture* tempTex, - Renderer::Backend::GL::CFramebuffer* tempFramebuffer, - Renderer::Backend::GL::CFramebuffer* outFramebuffer, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + Renderer::Backend::ITexture* inTex, + Renderer::Backend::ITexture* tempTex, + Renderer::Backend::IFramebuffer* tempFramebuffer, + Renderer::Backend::IFramebuffer* outFramebuffer, int inWidth, int inHeight); // Applies a pass of a given effect to the entire current framebuffer. The shader is @@ -168,7 +168,7 @@ private: // the depth buffer, a number of blur textures, the screen size, the zNear/zFar planes and // some other parameters used by the optional bloom/HDR pass. void ApplyEffect( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderTechniquePtr& shaderTech, int pass); // Delete all allocated buffers/textures from GPU memory. diff --git a/source/renderer/RenderModifiers.cpp b/source/renderer/RenderModifiers.cpp index f01e2bb7d2..49f224694f 100644 --- a/source/renderer/RenderModifiers.cpp +++ b/source/renderer/RenderModifiers.cpp @@ -68,7 +68,7 @@ ShaderRenderModifier::ShaderRenderModifier() } void ShaderRenderModifier::BeginPass( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) { const CMatrix3D transform = @@ -133,7 +133,7 @@ void ShaderRenderModifier::BeginPass( } void ShaderRenderModifier::PrepareModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, CModel* model) { if (m_BindingInstancingTransform >= 0) diff --git a/source/renderer/RenderModifiers.h b/source/renderer/RenderModifiers.h index 41776b8d70..02cca7c36d 100644 --- a/source/renderer/RenderModifiers.h +++ b/source/renderer/RenderModifiers.h @@ -57,7 +57,7 @@ public: * Must be implemented by derived classes. */ virtual void BeginPass( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) = 0; /** @@ -68,7 +68,7 @@ public: * @param model The model that is about to be rendered. */ virtual void PrepareModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, CModel* model) = 0; }; @@ -121,10 +121,10 @@ public: // Implementation void BeginPass( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) override; void PrepareModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, CModel* model) override; private: diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index 245fadebed..e0e1431313 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -50,7 +50,7 @@ #include "graphics/TextureManager.h" #include "ps/Util.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/DebugRenderer.h" #include "renderer/PostprocManager.h" #include "renderer/RenderingOptions.h" @@ -242,7 +242,7 @@ class CRenderer::Internals { NONCOPYABLE(Internals); public: - std::unique_ptr deviceCommandContext; + std::unique_ptr deviceCommandContext; /// true if CRenderer::Open has been called bool IsOpen; @@ -274,7 +274,7 @@ public: Internals() : IsOpen(false), ShadersDirty(true), profileTable(g_Renderer.m_Stats), deviceCommandContext(g_VideoMode.GetBackendDevice()->CreateCommandContext()), - textureManager(g_VFS, false, false) + textureManager(g_VFS, false, g_VideoMode.GetBackendDevice()) { } }; @@ -712,7 +712,7 @@ void CRenderer::EndFrame() void CRenderer::SetViewport(const SViewPort &vp) { m_Viewport = vp; - Renderer::Backend::GL::CDeviceCommandContext::Rect viewportRect; + Renderer::Backend::IDeviceCommandContext::Rect viewportRect; viewportRect.x = vp.m_X; viewportRect.y = vp.m_Y; viewportRect.width = vp.m_Width; @@ -776,7 +776,7 @@ void CRenderer::MakeScreenShotOnNextFrame(ScreenShotType screenShotType) m_ScreenShotType = screenShotType; } -Renderer::Backend::GL::CDeviceCommandContext* CRenderer::GetDeviceCommandContext() +Renderer::Backend::IDeviceCommandContext* CRenderer::GetDeviceCommandContext() { return m->deviceCommandContext.get(); } diff --git a/source/renderer/Renderer.h b/source/renderer/Renderer.h index d1aa616430..be8c1f55eb 100644 --- a/source/renderer/Renderer.h +++ b/source/renderer/Renderer.h @@ -22,7 +22,7 @@ #include "graphics/ShaderDefines.h" #include "graphics/ShaderProgramPtr.h" #include "ps/Singleton.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/RenderingOptions.h" #include "renderer/Scene.h" @@ -136,7 +136,7 @@ public: */ void MakeScreenShotOnNextFrame(ScreenShotType screenShotType); - Renderer::Backend::GL::CDeviceCommandContext* GetDeviceCommandContext(); + Renderer::Backend::IDeviceCommandContext* GetDeviceCommandContext(); protected: friend class CPatchRData; diff --git a/source/renderer/SceneRenderer.cpp b/source/renderer/SceneRenderer.cpp index ad8a62f581..378a00770a 100644 --- a/source/renderer/SceneRenderer.cpp +++ b/source/renderer/SceneRenderer.cpp @@ -44,7 +44,7 @@ #include "ps/Profile.h" #include "ps/VideoMode.h" #include "ps/World.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/DebugRenderer.h" #include "renderer/HWLightingModelRenderer.h" #include "renderer/InstancingModelRenderer.h" @@ -144,7 +144,7 @@ public: * Renders all non-alpha-blended models with the given context. */ void CallModelRenderers( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, int flags) { CShaderDefines contextSkinned = context; @@ -167,7 +167,7 @@ public: * Renders all alpha-blended models with the given context. */ void CallTranspModelRenderers( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, int flags) { CShaderDefines contextSkinned = context; @@ -293,7 +293,7 @@ void CSceneRenderer::SetSimulation(CSimulation2* simulation) } void CSceneRenderer::RenderShadowMap( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context) { PROFILE3_GPU("shadow map"); @@ -336,7 +336,7 @@ void CSceneRenderer::RenderShadowMap( } void CSceneRenderer::RenderPatches( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup) { PROFILE3_GPU("patches"); @@ -366,7 +366,7 @@ void CSceneRenderer::RenderPatches( } void CSceneRenderer::RenderModels( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup) { PROFILE3_GPU("models"); @@ -389,7 +389,7 @@ void CSceneRenderer::RenderModels( } void CSceneRenderer::RenderTransparentModels( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ETransparentMode transparentMode) { PROFILE3_GPU("transparent models"); @@ -544,7 +544,7 @@ void CSceneRenderer::ComputeRefractionCamera(CCamera& camera, const CBoundingBox // RenderReflections: render the water reflections to the reflection texture void CSceneRenderer::RenderReflections( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, const CBoundingBoxAligned& scissor) { PROFILE3_GPU("water reflections"); @@ -573,7 +573,7 @@ void CSceneRenderer::RenderReflections( screenScissor.x2 = (GLint)ceil((reflectionScissor[1].X*0.5f+0.5f)*vpWidth); screenScissor.y2 = (GLint)ceil((reflectionScissor[1].Y*0.5f+0.5f)*vpHeight); - Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; + Renderer::Backend::IDeviceCommandContext::Rect scissorRect; scissorRect.x = screenScissor.x1; scissorRect.y = screenScissor.y1; scissorRect.width = screenScissor.x2 - screenScissor.x1; @@ -609,7 +609,7 @@ void CSceneRenderer::RenderReflections( // RenderRefractions: render the water refractions to the refraction texture void CSceneRenderer::RenderRefractions( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, const CBoundingBoxAligned &scissor) { PROFILE3_GPU("water refractions"); @@ -643,7 +643,7 @@ void CSceneRenderer::RenderRefractions( screenScissor.x2 = (GLint)ceil((refractionScissor[1].X*0.5f+0.5f)*vpWidth); screenScissor.y2 = (GLint)ceil((refractionScissor[1].Y*0.5f+0.5f)*vpHeight); - Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; + Renderer::Backend::IDeviceCommandContext::Rect scissorRect; scissorRect.x = screenScissor.x1; scissorRect.y = screenScissor.y1; scissorRect.width = screenScissor.x2 - screenScissor.x1; @@ -672,7 +672,7 @@ void CSceneRenderer::RenderRefractions( } void CSceneRenderer::RenderSilhouettes( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context) { PROFILE3_GPU("silhouettes"); @@ -726,7 +726,7 @@ void CSceneRenderer::RenderSilhouettes( } void CSceneRenderer::RenderParticles( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { PROFILE3_GPU("particles"); @@ -745,7 +745,7 @@ void CSceneRenderer::RenderParticles( // RenderSubmissions: force rendering of any batched objects void CSceneRenderer::RenderSubmissions( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CBoundingBoxAligned& waterScissor) { PROFILE3("render submissions"); @@ -1060,7 +1060,7 @@ void CSceneRenderer::SubmitNonRecursive(CModel* model) // Render the given scene void CSceneRenderer::RenderScene( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, Scene& scene) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene) { m_CurrentScene = &scene; diff --git a/source/renderer/SceneRenderer.h b/source/renderer/SceneRenderer.h index dc3df31010..961b5ca01e 100644 --- a/source/renderer/SceneRenderer.h +++ b/source/renderer/SceneRenderer.h @@ -22,7 +22,7 @@ #include "graphics/ShaderDefines.h" #include "graphics/ShaderProgramPtr.h" #include "ps/Singleton.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/RenderingOptions.h" #include "renderer/Scene.h" @@ -97,7 +97,7 @@ public: * Render the given scene immediately. * @param scene a Scene object describing what should be rendered. */ - void RenderScene(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, Scene& scene); + void RenderScene(Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene); /** * Return the scene that is currently being rendered. @@ -195,41 +195,41 @@ protected: // render any batched objects void RenderSubmissions( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CBoundingBoxAligned& waterScissor); // patch rendering stuff void RenderPatches( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup); // model rendering stuff void RenderModels( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup); void RenderTransparentModels( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ETransparentMode transparentMode); void RenderSilhouettes( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context); void RenderParticles( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup); // shadow rendering stuff void RenderShadowMap( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context); // render water reflection and refraction textures void RenderReflections( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, const CBoundingBoxAligned& scissor); void RenderRefractions( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, const CBoundingBoxAligned& scissor); void ComputeReflectionCamera(CCamera& camera, const CBoundingBoxAligned& scissor) const; diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index 830f787e5b..90e77740bb 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -34,8 +34,8 @@ #include "ps/CStrInternStatic.h" #include "ps/Profile.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDevice.h" +#include "renderer/backend/ITexture.h" #include "renderer/DebugRenderer.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" @@ -58,8 +58,8 @@ constexpr float DEFAULT_CASCADE_DISTANCE_RATIO = 1.7f; */ struct ShadowMapInternals { - std::unique_ptr Framebuffer; - std::unique_ptr Texture; + std::unique_ptr Framebuffer; + std::unique_ptr Texture; // bit depth for the depth texture int DepthTextureBits; @@ -109,7 +109,7 @@ struct ShadowMapInternals // incorrectly when the FBO has only a depth attachment. // When m_ShadowAlphaFix is true, we use DummyTexture to store a useless // alpha texture which is attached to the FBO as a workaround. - std::unique_ptr DummyTexture; + std::unique_ptr DummyTexture; // Copy of renderer's standard view camera, saved between // BeginRender and EndRender while we replace it with the shadow camera @@ -472,7 +472,7 @@ void ShadowMapInternals::CreateTexture() Texture.reset(); DummyTexture.reset(); - Renderer::Backend::GL::CDevice* backendDevice = g_VideoMode.GetBackendDevice(); + Renderer::Backend::IDevice* backendDevice = g_VideoMode.GetBackendDevice(); CFG_GET_VAL("shadowquality", QualityLevel); @@ -569,7 +569,7 @@ void ShadowMapInternals::CreateTexture() // Set up to render into shadow map texture void ShadowMap::BeginRender() { - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); deviceCommandContext->SetGraphicsPipelineState( Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc()); @@ -605,7 +605,7 @@ void ShadowMap::PrepareCamera(const int cascade) g_Renderer.GetSceneRenderer().SetViewCamera(camera); const SViewPort& cascadeViewPort = m->Cascades[cascade].ViewPort; - Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; + Renderer::Backend::IDeviceCommandContext::Rect scissorRect; scissorRect.x = cascadeViewPort.m_X; scissorRect.y = cascadeViewPort.m_Y; scissorRect.width = cascadeViewPort.m_Width; @@ -631,7 +631,7 @@ void ShadowMap::EndRender() } void ShadowMap::BindTo( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) const { const int32_t shadowTexBindingSlot = shader->GetBindingSlot(str_shadowTex); diff --git a/source/renderer/ShadowMap.h b/source/renderer/ShadowMap.h index 65f8425eea..480d553121 100644 --- a/source/renderer/ShadowMap.h +++ b/source/renderer/ShadowMap.h @@ -18,7 +18,7 @@ #ifndef INCLUDED_SHADOWMAP #define INCLUDED_SHADOWMAP -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/backend/IShaderProgram.h" class CBoundingBoxAligned; @@ -127,7 +127,7 @@ public: * Binds all needed resources and uniforms to draw shadows using the shader. */ void BindTo( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) const; /** diff --git a/source/renderer/SilhouetteRenderer.cpp b/source/renderer/SilhouetteRenderer.cpp index 41940278bf..cf47788628 100644 --- a/source/renderer/SilhouetteRenderer.cpp +++ b/source/renderer/SilhouetteRenderer.cpp @@ -444,7 +444,7 @@ void SilhouetteRenderer::RenderSubmitCasters(SceneCollector& collector) } void SilhouetteRenderer::RenderDebugBounds( - Renderer::Backend::GL::CDeviceCommandContext* UNUSED(deviceCommandContext)) + Renderer::Backend::IDeviceCommandContext* UNUSED(deviceCommandContext)) { if (m_DebugBounds.empty()) return; @@ -454,7 +454,7 @@ void SilhouetteRenderer::RenderDebugBounds( } void SilhouetteRenderer::RenderDebugOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m_DebugRects.empty()) return; diff --git a/source/renderer/SilhouetteRenderer.h b/source/renderer/SilhouetteRenderer.h index 99073ac3ae..c0509795a2 100644 --- a/source/renderer/SilhouetteRenderer.h +++ b/source/renderer/SilhouetteRenderer.h @@ -20,7 +20,7 @@ #include "graphics/Overlay.h" #include "maths/BoundingBoxAligned.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" class CCamera; class CModel; @@ -42,9 +42,9 @@ public: void RenderSubmitCasters(SceneCollector& collector); void RenderDebugBounds( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); void RenderDebugOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); void EndFrame(); diff --git a/source/renderer/SkyManager.cpp b/source/renderer/SkyManager.cpp index 74235e0379..a57ecc317e 100644 --- a/source/renderer/SkyManager.cpp +++ b/source/renderer/SkyManager.cpp @@ -33,7 +33,7 @@ #include "ps/Filesystem.h" #include "ps/Game.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include "renderer/SceneRenderer.h" #include "renderer/RenderingOptions.h" @@ -41,13 +41,13 @@ #include SkyManager::SkyManager() - : m_VertexArray(Renderer::Backend::GL::CBuffer::Type::VERTEX, false) + : m_VertexArray(Renderer::Backend::IBuffer::Type::VERTEX, false) { CFG_GET_VAL("showsky", m_SkyVisible); } void SkyManager::LoadAndUploadSkyTexturesIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m_SkyTextureCube) return; @@ -117,9 +117,9 @@ void SkyManager::LoadAndUploadSkyTexturesIfNeeded( } } - std::unique_ptr skyCubeMap = + std::unique_ptr skyCubeMap = g_VideoMode.GetBackendDevice()->CreateTexture("SkyCubeMap", - Renderer::Backend::GL::CTexture::Type::TEXTURE_CUBE, + Renderer::Backend::ITexture::Type::TEXTURE_CUBE, Renderer::Backend::Format::R8G8B8A8_UNORM, textures[0].m_Width, textures[0].m_Height, Renderer::Backend::Sampler::MakeDefaultSampler( Renderer::Backend::Sampler::Filter::LINEAR, @@ -166,7 +166,7 @@ void SkyManager::LoadAndUploadSkyTexturesIfNeeded( /////////////////////////////////////////////////////////////////////////// } -Renderer::Backend::GL::CTexture* SkyManager::GetSkyCube() +Renderer::Backend::ITexture* SkyManager::GetSkyCube() { return m_SkyTextureCube->GetBackendTexture(); } @@ -203,7 +203,7 @@ std::vector SkyManager::GetSkySets() const } void SkyManager::RenderSky( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { GPU_SCOPED_LABEL(deviceCommandContext, "Render sky"); diff --git a/source/renderer/SkyManager.h b/source/renderer/SkyManager.h index 5e6423f9dd..316d555eb2 100644 --- a/source/renderer/SkyManager.h +++ b/source/renderer/SkyManager.h @@ -23,8 +23,8 @@ #define INCLUDED_SKYMANAGER #include "graphics/Texture.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/ITexture.h" #include "renderer/VertexArray.h" #include @@ -42,7 +42,7 @@ public: * Render the sky. */ void RenderSky( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Return the currently selected sky set name. @@ -52,7 +52,7 @@ public: return m_SkySet; } - Renderer::Backend::GL::CTexture* GetSkyCube(); + Renderer::Backend::ITexture* GetSkyCube(); /** * Set the sky set name. @@ -79,7 +79,7 @@ public: * Load all sky textures from files and upload to GPU. */ void LoadAndUploadSkyTexturesIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); private: void CreateSkyCube(); diff --git a/source/renderer/TerrainOverlay.cpp b/source/renderer/TerrainOverlay.cpp index d2c1937660..ea6dca7a59 100644 --- a/source/renderer/TerrainOverlay.cpp +++ b/source/renderer/TerrainOverlay.cpp @@ -29,7 +29,8 @@ #include "ps/Game.h" #include "ps/Profile.h" #include "ps/World.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/Renderer.h" #include "renderer/SceneRenderer.h" #include "renderer/TerrainRenderer.h" @@ -64,7 +65,7 @@ ITerrainOverlay::~ITerrainOverlay() void ITerrainOverlay::RenderOverlaysBeforeWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (g_TerrainOverlayList.empty()) return; @@ -77,7 +78,7 @@ void ITerrainOverlay::RenderOverlaysBeforeWater( } void ITerrainOverlay::RenderOverlaysAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, int cullGroup) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { if (g_TerrainOverlayList.empty()) return; @@ -114,7 +115,7 @@ void TerrainOverlay::GetTileExtents( } void TerrainOverlay::RenderBeforeWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!m_Terrain) return; // should never happen, but let's play it safe @@ -139,14 +140,14 @@ void TerrainOverlay::RenderBeforeWater( } void TerrainOverlay::RenderTile( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden) { RenderTile(deviceCommandContext, color, drawHidden, m_i, m_j); } void TerrainOverlay::RenderTile( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden, ssize_t i, ssize_t j) { // TODO: unnecessary computation calls has been removed but we should use @@ -230,14 +231,14 @@ void TerrainOverlay::RenderTile( } void TerrainOverlay::RenderTileOutline( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden) { RenderTileOutline(deviceCommandContext, color, drawHidden, m_i, m_j); } void TerrainOverlay::RenderTileOutline( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden, ssize_t i, ssize_t j) { std::vector vertices; @@ -304,7 +305,7 @@ TerrainTextureOverlay::TerrainTextureOverlay(float texelsPerTile, int priority) TerrainTextureOverlay::~TerrainTextureOverlay() = default; void TerrainTextureOverlay::RenderAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, int cullGroup) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); diff --git a/source/renderer/TerrainOverlay.h b/source/renderer/TerrainOverlay.h index 1e4ed3f784..cd23830c8f 100644 --- a/source/renderer/TerrainOverlay.h +++ b/source/renderer/TerrainOverlay.h @@ -23,8 +23,8 @@ #ifndef INCLUDED_TERRAINOVERLAY #define INCLUDED_TERRAINOVERLAY -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/ITexture.h" +#include "renderer/backend/IDeviceCommandContext.h" struct CColor; struct SColor4ub; @@ -44,24 +44,24 @@ class ITerrainOverlay public: virtual ~ITerrainOverlay(); - virtual void RenderBeforeWater(Renderer::Backend::GL::CDeviceCommandContext* UNUSED(deviceCommandContext)) { } + virtual void RenderBeforeWater(Renderer::Backend::IDeviceCommandContext* UNUSED(deviceCommandContext)) { } virtual void RenderAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* UNUSED(deviceCommandContext), int UNUSED(cullGroup)) { } + Renderer::Backend::IDeviceCommandContext* UNUSED(deviceCommandContext), int UNUSED(cullGroup)) { } /** * Draw all ITerrainOverlay objects that exist * and that should be drawn before water. */ static void RenderOverlaysBeforeWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /** * Draw all ITerrainOverlay objects that exist * and that should be drawn after water. */ static void RenderOverlaysAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, int cullGroup); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup); protected: ITerrainOverlay(int priority); @@ -129,7 +129,7 @@ protected: * @param j j coordinate of tile being processed */ virtual void ProcessTile( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, ssize_t i, ssize_t j) = 0; /** @@ -140,14 +140,14 @@ protected: * should be drawn */ void RenderTile( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden); /** * Draw a filled quad on top of the given tile. */ void RenderTile( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden, ssize_t i, ssize_t j); /** @@ -159,20 +159,20 @@ protected: * should be drawn */ void RenderTileOutline( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden); /** * Draw an outlined quad on top of the given tile. */ void RenderTileOutline( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CColor& color, bool drawHidden, ssize_t i, ssize_t j); private: // Process all tiles void RenderBeforeWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) override; + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) override; // Temporary storage of tile coordinates, so ProcessTile doesn't need to // pass it to RenderTile/etc (and doesn't have a chance to get it wrong) @@ -210,10 +210,10 @@ protected: private: void RenderAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, int cullGroup) override; + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) override; float m_TexelsPerTile; - std::unique_ptr m_Texture; + std::unique_ptr m_Texture; }; #endif // INCLUDED_TERRAINOVERLAY diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 0872a186f1..6566ed27e8 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -38,7 +38,7 @@ #include "ps/Game.h" #include "ps/Profile.h" #include "ps/World.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/DecalRData.h" #include "renderer/PatchRData.h" #include "renderer/Renderer.h" @@ -161,9 +161,9 @@ void TerrainRenderer::EndFrame() } void TerrainRenderer::RenderTerrainOverlayTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup, CMatrix3D& textureMatrix, - Renderer::Backend::GL::CTexture* texture) + Renderer::Backend::ITexture* texture) { ENSURE(m->phase == Phase_Render); @@ -227,7 +227,7 @@ void TerrainRenderer::RenderTerrainOverlayTexture( * Set up all the uniforms for a shader pass. */ void TerrainRenderer::PrepareShader( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, ShadowMap* shadow) { CSceneRenderer& sceneRenderer = g_Renderer.GetSceneRenderer(); @@ -270,7 +270,7 @@ void TerrainRenderer::PrepareShader( } void TerrainRenderer::RenderTerrainShader( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ShadowMap* shadow) { ENSURE(m->phase == Phase_Render); @@ -311,7 +311,7 @@ void TerrainRenderer::RenderTerrainShader( /////////////////////////////////////////////////////////////////// // Render un-textured patches as polygons void TerrainRenderer::RenderPatches( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup, const CShaderDefines& defines, const CColor& color) { ENSURE(m->phase == Phase_Render); @@ -344,7 +344,7 @@ void TerrainRenderer::RenderPatches( /////////////////////////////////////////////////////////////////// // Render outlines of submitted patches as lines void TerrainRenderer::RenderOutlines( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { ENSURE(m->phase == Phase_Render); @@ -383,7 +383,7 @@ CBoundingBoxAligned TerrainRenderer::ScissorWater(int cullGroup, const CCamera& // Render fancy water bool TerrainRenderer::RenderFancyWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ShadowMap* shadow) { PROFILE3_GPU("fancy water"); @@ -598,7 +598,7 @@ bool TerrainRenderer::RenderFancyWater( } void TerrainRenderer::RenderSimpleWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { PROFILE3_GPU("simple water"); @@ -654,7 +654,7 @@ void TerrainRenderer::RenderSimpleWater( /////////////////////////////////////////////////////////////////// // Render water that is part of the terrain void TerrainRenderer::RenderWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ShadowMap* shadow) { const WaterManager& waterManager = g_Renderer.GetSceneRenderer().GetWaterManager(); @@ -666,7 +666,7 @@ void TerrainRenderer::RenderWater( } void TerrainRenderer::RenderWaterFoamOccluders( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { CSceneRenderer& sceneRenderer = g_Renderer.GetSceneRenderer(); diff --git a/source/renderer/TerrainRenderer.h b/source/renderer/TerrainRenderer.h index 95724c8716..efe29834e2 100644 --- a/source/renderer/TerrainRenderer.h +++ b/source/renderer/TerrainRenderer.h @@ -25,8 +25,8 @@ #include "graphics/Color.h" #include "maths/BoundingBoxAligned.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/ITexture.h" #include "renderer/backend/IShaderProgram.h" class CCamera; @@ -103,7 +103,7 @@ public: * @param shadow A prepared shadow map, in case rendering with shadows is enabled. */ void RenderTerrainShader( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ShadowMap* shadow); /** @@ -116,7 +116,7 @@ public: * @param color Fill color of the patches. */ void RenderPatches( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup, const CShaderDefines& defines, const CColor& color = CColor(0.0f, 0.0f, 0.0f, 1.0f)); @@ -129,7 +129,7 @@ public: * @param filtered If true then only render objects that passed CullPatches. */ void RenderOutlines( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup); /** @@ -140,14 +140,14 @@ public: * frame before calling RenderWater. */ void RenderWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ShadowMap* shadow); /** * Renders terrain to a framebuffer to occlude shore foams. */ void RenderWaterFoamOccluders( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup); /** @@ -166,8 +166,8 @@ public: * Intended for use by TerrainTextureOverlay. */ void RenderTerrainOverlayTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, - int cullGroup, CMatrix3D& textureMatrix, Renderer::Backend::GL::CTexture* texture); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + int cullGroup, CMatrix3D& textureMatrix, Renderer::Backend::ITexture* texture); private: TerrainRendererInternals* m; @@ -177,18 +177,18 @@ private: * Returns false if unable to render with fancy water. */ bool RenderFancyWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup, ShadowMap* shadow); /** * RenderSimpleWater: internal rendering method for water */ void RenderSimpleWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup); static void PrepareShader( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, ShadowMap* shadow); }; diff --git a/source/renderer/TexturedLineRData.cpp b/source/renderer/TexturedLineRData.cpp index 9f7a827f98..09101de603 100644 --- a/source/renderer/TexturedLineRData.cpp +++ b/source/renderer/TexturedLineRData.cpp @@ -36,7 +36,7 @@ * to use VertexArray where possible, though. */ void CTexturedLineRData::Render( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const SOverlayTexturedLine& line, Renderer::Backend::IShaderProgram* shader) { if (!m_VB || !m_VBIndices) @@ -322,7 +322,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) m_BoundingBox += vertex.m_Position; m_VB = g_VBMan.AllocateChunk( - sizeof(SVertex), vertices.size(), Renderer::Backend::GL::CBuffer::Type::VERTEX, false); + sizeof(SVertex), vertices.size(), Renderer::Backend::IBuffer::Type::VERTEX, false); // Allocation might fail (e.g. due to too many vertices). if (m_VB) { @@ -333,7 +333,7 @@ void CTexturedLineRData::Update(const SOverlayTexturedLine& line) indices[k] += static_cast(m_VB->m_Index); m_VBIndices = g_VBMan.AllocateChunk( - sizeof(u16), indices.size(), Renderer::Backend::GL::CBuffer::Type::INDEX, false); + sizeof(u16), indices.size(), Renderer::Backend::IBuffer::Type::INDEX, false); if (m_VBIndices) m_VBIndices->m_Owner->UpdateChunkVertices(m_VBIndices.Get(), &indices[0]); } diff --git a/source/renderer/TexturedLineRData.h b/source/renderer/TexturedLineRData.h index 25c675abbb..c3ef374632 100644 --- a/source/renderer/TexturedLineRData.h +++ b/source/renderer/TexturedLineRData.h @@ -23,7 +23,7 @@ #include "graphics/ShaderProgram.h" #include "graphics/TextureManager.h" #include "maths/BoundingBoxAligned.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/VertexBufferManager.h" class CFrustum; @@ -52,7 +52,7 @@ public: ~CTexturedLineRData() = default; void Update(const SOverlayTexturedLine& line); - void Render(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + void Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const SOverlayTexturedLine& line, Renderer::Backend::IShaderProgram* shader); bool IsVisibleInFrustum(const CFrustum& frustum) const; diff --git a/source/renderer/VertexArray.cpp b/source/renderer/VertexArray.cpp index 97fc96c683..1095fab1b4 100644 --- a/source/renderer/VertexArray.cpp +++ b/source/renderer/VertexArray.cpp @@ -65,7 +65,7 @@ size_t GetAttributeSize(const Renderer::Backend::Format format) } // anonymous namespace VertexArray::VertexArray( - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic) + const Renderer::Backend::IBuffer::Type type, const bool dynamic) : m_Type(type), m_Dynamic(dynamic) { m_NumberOfVertices = 0; @@ -245,11 +245,11 @@ void VertexArray::Layout() m_Stride += attrSize; - if (m_Type == Renderer::Backend::GL::CBuffer::Type::VERTEX) + if (m_Type == Renderer::Backend::IBuffer::Type::VERTEX) m_Stride = Align<4>(m_Stride); } - if (m_Type == Renderer::Backend::GL::CBuffer::Type::VERTEX) + if (m_Type == Renderer::Backend::IBuffer::Type::VERTEX) m_Stride = RoundStride(m_Stride); if (m_Stride) @@ -283,7 +283,7 @@ void VertexArray::Upload() } void VertexArray::UploadIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { m_VB->m_Owner->UploadIfNeeded(deviceCommandContext); } @@ -299,7 +299,7 @@ void VertexArray::FreeBackingStore() } VertexIndexArray::VertexIndexArray(const bool dynamic) : - VertexArray(Renderer::Backend::GL::CBuffer::Type::INDEX, dynamic) + VertexArray(Renderer::Backend::IBuffer::Type::INDEX, dynamic) { m_Attr.format = Renderer::Backend::Format::R16_UINT; AddAttribute(&m_Attr); diff --git a/source/renderer/VertexArray.h b/source/renderer/VertexArray.h index e9505a3638..595be3f86d 100644 --- a/source/renderer/VertexArray.h +++ b/source/renderer/VertexArray.h @@ -19,8 +19,8 @@ #define INCLUDED_VERTEXARRAY #include "renderer/backend/Format.h" -#include "renderer/backend/gl/Buffer.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IBuffer.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/VertexBufferManager.h" #include @@ -160,7 +160,7 @@ public: public: VertexArray( - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic); + const Renderer::Backend::IBuffer::Type type, const bool dynamic); ~VertexArray(); // Set the number of vertices stored in the array @@ -182,13 +182,13 @@ public: // Make this vertex array's data available for the next series of calls to Bind void PrepareForRendering(); - void UploadIfNeeded(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void UploadIfNeeded(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); // If you know for certain that you'll never have to change the data again, // call this to free some memory. void FreeBackingStore(); - Renderer::Backend::GL::CBuffer* GetBuffer() { return m_VB ? m_VB->m_Owner->GetBuffer() : nullptr; } + Renderer::Backend::IBuffer* GetBuffer() { return m_VB ? m_VB->m_Owner->GetBuffer() : nullptr; } uint32_t GetOffset() const { return m_VB ? m_VB->m_Index : 0; } @@ -202,7 +202,7 @@ private: return VertexArrayIterator(m_BackingStore + attr->offset, m_Stride); } - Renderer::Backend::GL::CBuffer::Type m_Type; + Renderer::Backend::IBuffer::Type m_Type; bool m_Dynamic; size_t m_NumberOfVertices; std::vector m_Attributes; diff --git a/source/renderer/VertexBuffer.cpp b/source/renderer/VertexBuffer.cpp index 5ddf0061b0..b724c36b7e 100644 --- a/source/renderer/VertexBuffer.cpp +++ b/source/renderer/VertexBuffer.cpp @@ -23,7 +23,7 @@ #include "ps/CLogger.h" #include "ps/Errors.h" #include "ps/VideoMode.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include @@ -38,27 +38,27 @@ constexpr std::size_t MAX_VB_SIZE_BYTES = 4 * 1024 * 1024; CVertexBuffer::CVertexBuffer( const char* name, const size_t vertexSize, - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic) + const Renderer::Backend::IBuffer::Type type, const bool dynamic) : CVertexBuffer(name, vertexSize, type, dynamic, MAX_VB_SIZE_BYTES) { } CVertexBuffer::CVertexBuffer( const char* name, const size_t vertexSize, - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic, + const Renderer::Backend::IBuffer::Type type, const bool dynamic, const size_t maximumBufferSize) : m_VertexSize(vertexSize), m_HasNeededChunks(false) { size_t size = maximumBufferSize; - if (type == Renderer::Backend::GL::CBuffer::Type::VERTEX) + if (type == Renderer::Backend::IBuffer::Type::VERTEX) { // We want to store 16-bit indices to any vertex in a buffer, so the // buffer must never be bigger than vertexSize*64K bytes since we can // address at most 64K of them with 16-bit indices size = std::min(size, vertexSize * 65536); } - else if (type == Renderer::Backend::GL::CBuffer::Type::INDEX) + else if (type == Renderer::Backend::IBuffer::Type::INDEX) { ENSURE(vertexSize == sizeof(u16)); } @@ -89,7 +89,7 @@ CVertexBuffer::~CVertexBuffer() } bool CVertexBuffer::CompatibleVertexType( - const size_t vertexSize, const Renderer::Backend::GL::CBuffer::Type type, + const size_t vertexSize, const Renderer::Backend::IBuffer::Type type, const bool dynamic) const { ENSURE(m_Buffer); @@ -102,7 +102,7 @@ bool CVertexBuffer::CompatibleVertexType( // if no free chunks available CVertexBuffer::VBChunk* CVertexBuffer::Allocate( const size_t vertexSize, const size_t numberOfVertices, - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic, + const Renderer::Backend::IBuffer::Type type, const bool dynamic, void* backingStore) { // check this is the right kind of buffer @@ -226,7 +226,7 @@ void CVertexBuffer::UpdateChunkVertices(VBChunk* chunk, void* data) } void CVertexBuffer::UploadIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (UseStreaming(m_Buffer->IsDynamic())) { diff --git a/source/renderer/VertexBuffer.h b/source/renderer/VertexBuffer.h index 46fc09a64b..b20c19396e 100644 --- a/source/renderer/VertexBuffer.h +++ b/source/renderer/VertexBuffer.h @@ -22,8 +22,8 @@ #ifndef INCLUDED_VERTEXBUFFER #define INCLUDED_VERTEXBUFFER -#include "renderer/backend/gl/Buffer.h" -#include "renderer/backend/gl/DeviceCommandContext.h" +#include "renderer/backend/IBuffer.h" +#include "renderer/backend/IDeviceCommandContext.h" #include #include @@ -92,14 +92,14 @@ public: // constructor, destructor CVertexBuffer( const char* name, const size_t vertexSize, - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic); + const Renderer::Backend::IBuffer::Type type, const bool dynamic); CVertexBuffer( const char* name, const size_t vertexSize, - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic, + const Renderer::Backend::IBuffer::Type type, const bool dynamic, const size_t maximumBufferSize); ~CVertexBuffer(); - void UploadIfNeeded(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + void UploadIfNeeded(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); /// Make the vertex data available for the next usage. void PrepareForRendering(VBChunk* chunk); @@ -113,7 +113,7 @@ public: /// Returns true if this vertex buffer is compatible with the specified vertex type and intended usage. bool CompatibleVertexType( - const size_t vertexSize, const Renderer::Backend::GL::CBuffer::Type type, + const size_t vertexSize, const Renderer::Backend::IBuffer::Type type, const bool dynamic) const; void DumpStatus() const; @@ -130,7 +130,7 @@ public: */ static bool UseStreaming(const bool dynamic); - Renderer::Backend::GL::CBuffer* GetBuffer() { return m_Buffer.get(); } + Renderer::Backend::IBuffer* GetBuffer() { return m_Buffer.get(); } private: friend class CVertexBufferManager; // allow allocate only via CVertexBufferManager @@ -139,7 +139,7 @@ private: /// and with the given type - return null if no free chunks available VBChunk* Allocate( const size_t vertexSize, const size_t numberOfVertices, - const Renderer::Backend::GL::CBuffer::Type type, const bool dynamic, + const Renderer::Backend::IBuffer::Type type, const bool dynamic, void* backingStore); /// Return given chunk to this buffer void Release(VBChunk* chunk); @@ -155,7 +155,7 @@ private: /// Available free vertices - total of all free vertices in the free list size_t m_FreeVertices; - std::unique_ptr m_Buffer; + std::unique_ptr m_Buffer; bool m_HasNeededChunks; }; diff --git a/source/renderer/VertexBufferManager.cpp b/source/renderer/VertexBufferManager.cpp index 0c9b5dd491..92263956ce 100644 --- a/source/renderer/VertexBufferManager.cpp +++ b/source/renderer/VertexBufferManager.cpp @@ -27,15 +27,15 @@ namespace { const char* GetBufferTypeName( - const Renderer::Backend::GL::CBuffer::Type type) + const Renderer::Backend::IBuffer::Type type) { const char* name = "UnknownBuffer"; switch (type) { - case Renderer::Backend::GL::CBuffer::Type::VERTEX: + case Renderer::Backend::IBuffer::Type::VERTEX: name = "VertexBuffer"; break; - case Renderer::Backend::GL::CBuffer::Type::INDEX: + case Renderer::Backend::IBuffer::Type::INDEX: name = "IndexBuffer"; break; default: @@ -121,7 +121,7 @@ void CVertexBufferManager::Shutdown() */ CVertexBufferManager::Handle CVertexBufferManager::AllocateChunk( const size_t vertexSize, const size_t numberOfVertices, - const Renderer::Backend::GL::CBuffer::Type type, + const Renderer::Backend::IBuffer::Type type, const bool dynamic, void* backingStore, Group group) { ENSURE(vertexSize > 0); diff --git a/source/renderer/VertexBufferManager.h b/source/renderer/VertexBufferManager.h index e6e188f898..46362b32a2 100644 --- a/source/renderer/VertexBufferManager.h +++ b/source/renderer/VertexBufferManager.h @@ -90,7 +90,7 @@ public: */ Handle AllocateChunk( const size_t vertexSize, const size_t numberOfVertices, - const Renderer::Backend::GL::CBuffer::Type type, + const Renderer::Backend::IBuffer::Type type, const bool dynamic, void* backingStore = nullptr, Group group = Group::DEFAULT); /// Returns the given @p chunk to its owning buffer diff --git a/source/renderer/WaterManager.cpp b/source/renderer/WaterManager.cpp index f19f88bd7a..5c72497774 100644 --- a/source/renderer/WaterManager.cpp +++ b/source/renderer/WaterManager.cpp @@ -30,7 +30,7 @@ #include "ps/Game.h" #include "ps/VideoMode.h" #include "ps/World.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" #include "renderer/SceneRenderer.h" @@ -183,7 +183,7 @@ int WaterManager::LoadWaterTextures() void WaterManager::RecreateOrLoadTexturesIfNeeded() { - Renderer::Backend::GL::CDevice* backendDevice = g_VideoMode.GetBackendDevice(); + Renderer::Backend::IDevice* backendDevice = g_VideoMode.GetBackendDevice(); // Use screen-sized textures for minimum artifacts. const size_t newRefTextureSize = round_up_to_pow2(g_Renderer.GetHeight()); @@ -554,7 +554,7 @@ void WaterManager::CreateWaveMeshes() // Generic indexes, max-length m_ShoreWavesVBIndices = g_VBMan.AllocateChunk( sizeof(GLushort), water_indices.size(), - Renderer::Backend::GL::CBuffer::Type::INDEX, false, + Renderer::Backend::IBuffer::Type::INDEX, false, nullptr, CVertexBufferManager::Group::WATER); m_ShoreWavesVBIndices->m_Owner->UpdateChunkVertices(m_ShoreWavesVBIndices.Get(), &water_indices[0]); @@ -775,7 +775,7 @@ void WaterManager::CreateWaveMeshes() shoreWave->m_VBVertices = g_VBMan.AllocateChunk( sizeof(SWavesVertex), vertices.size(), - Renderer::Backend::GL::CBuffer::Type::VERTEX, false, + Renderer::Backend::IBuffer::Type::VERTEX, false, nullptr, CVertexBufferManager::Group::WATER); shoreWave->m_VBVertices->m_Owner->UpdateChunkVertices(shoreWave->m_VBVertices.Get(), &vertices[0]); @@ -785,7 +785,7 @@ void WaterManager::CreateWaveMeshes() } void WaterManager::RenderWaves( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CFrustum& frustrum) { GPU_SCOPED_LABEL(deviceCommandContext, "Render Waves"); diff --git a/source/renderer/WaterManager.h b/source/renderer/WaterManager.h index e4b01d8d2a..43997aebf5 100644 --- a/source/renderer/WaterManager.h +++ b/source/renderer/WaterManager.h @@ -26,9 +26,9 @@ #include "graphics/Texture.h" #include "maths/Matrix3D.h" #include "maths/Vector2D.h" -#include "renderer/backend/gl/DeviceCommandContext.h" -#include "renderer/backend/gl/Framebuffer.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/IFramebuffer.h" +#include "renderer/backend/ITexture.h" #include "renderer/VertexBufferManager.h" #include @@ -66,10 +66,10 @@ public: CTexturePtr m_WaveTex; CTexturePtr m_FoamTex; - std::unique_ptr m_FancyTexture; - std::unique_ptr m_FancyTextureDepth; - std::unique_ptr m_ReflFboDepthTexture; - std::unique_ptr m_RefrFboDepthTexture; + std::unique_ptr m_FancyTexture; + std::unique_ptr m_FancyTextureDepth; + std::unique_ptr m_ReflFboDepthTexture; + std::unique_ptr m_RefrFboDepthTexture; // used to know what to update when updating parts of the terrain only. u32 m_updatei0; @@ -101,14 +101,14 @@ public: float m_RepeatPeriod; // Reflection and refraction textures for fancy water - std::unique_ptr m_ReflectionTexture; - std::unique_ptr m_RefractionTexture; + std::unique_ptr m_ReflectionTexture; + std::unique_ptr m_RefractionTexture; size_t m_RefTextureSize; // framebuffer objects - std::unique_ptr m_RefractionFramebuffer; - std::unique_ptr m_ReflectionFramebuffer; - std::unique_ptr m_FancyEffectsFramebuffer; + std::unique_ptr m_RefractionFramebuffer; + std::unique_ptr m_ReflectionFramebuffer; + std::unique_ptr m_FancyEffectsFramebuffer; // Model-view-projection matrices for reflected & refracted cameras // (used to let the vertex shader do projective texturing) @@ -192,7 +192,7 @@ public: bool WillRenderFancyWater() const; void RenderWaves( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CFrustum& frustrum); /** diff --git a/source/renderer/backend/IBuffer.h b/source/renderer/backend/IBuffer.h new file mode 100644 index 0000000000..4b86b5b0a6 --- /dev/null +++ b/source/renderer/backend/IBuffer.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_IBUFFER +#define INCLUDED_RENDERER_BACKEND_IBUFFER + +#include "renderer/backend/IDeviceObject.h" + +#include + +namespace Renderer +{ + +namespace Backend +{ + +class IBuffer : public IDeviceObject +{ +public: + enum class Type + { + VERTEX, + INDEX + }; + + virtual Type GetType() const = 0; + virtual uint32_t GetSize() const = 0; + virtual bool IsDynamic() const = 0; +}; + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_IBUFFER diff --git a/source/renderer/backend/IDevice.h b/source/renderer/backend/IDevice.h new file mode 100644 index 0000000000..cc49d35632 --- /dev/null +++ b/source/renderer/backend/IDevice.h @@ -0,0 +1,108 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_IDEVICE +#define INCLUDED_RENDERER_BACKEND_IDEVICE + +#include "graphics/Color.h" +#include "renderer/backend/Format.h" +#include "renderer/backend/IBuffer.h" +#include "renderer/backend/IDevice.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/IFramebuffer.h" +#include "renderer/backend/IShaderProgram.h" +#include "renderer/backend/ITexture.h" +#include "scriptinterface/ScriptForward.h" + +#include +#include +#include + +class CShaderDefines; +class CStr; + +namespace Renderer +{ + +namespace Backend +{ + +class IDevice +{ +public: + struct Capabilities + { + bool S3TC; + bool ARBShaders; + bool ARBShadersShadow; + bool computeShaders; + bool debugLabels; + bool debugScopedLabels; + bool multisampling; + bool anisotropicFiltering; + uint32_t maxSampleCount; + float maxAnisotropy; + uint32_t maxTextureSize; + }; + + virtual ~IDevice() {} + + virtual const std::string& GetName() const = 0; + virtual const std::string& GetVersion() const = 0; + virtual const std::string& GetDriverInformation() const = 0; + virtual const std::vector& GetExtensions() const = 0; + + virtual void Report(const ScriptRequest& rq, JS::HandleValue settings) = 0; + + virtual IFramebuffer* GetCurrentBackbuffer() = 0; + + virtual std::unique_ptr CreateCommandContext() = 0; + + virtual std::unique_ptr CreateTexture(const char* name, const ITexture::Type type, + const Format format, const uint32_t width, const uint32_t height, + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) = 0; + + virtual std::unique_ptr CreateTexture2D(const char* name, + 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) = 0; + + virtual std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment) = 0; + + virtual std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment, const CColor& clearColor) = 0; + + virtual std::unique_ptr CreateBuffer( + const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) = 0; + + virtual std::unique_ptr CreateShaderProgram( + const CStr& name, const CShaderDefines& defines) = 0; + + virtual void Present() = 0; + + virtual bool IsTextureFormatSupported(const Format format) const = 0; + + virtual const Capabilities& GetCapabilities() const = 0; +}; + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_IDEVICE diff --git a/source/renderer/backend/IDeviceCommandContext.h b/source/renderer/backend/IDeviceCommandContext.h new file mode 100644 index 0000000000..22162c650b --- /dev/null +++ b/source/renderer/backend/IDeviceCommandContext.h @@ -0,0 +1,157 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_IDEVICECOMMANDCONTEXT +#define INCLUDED_RENDERER_BACKEND_IDEVICECOMMANDCONTEXT + +#include "ps/containers/Span.h" +#include "renderer/backend/Format.h" +#include "renderer/backend/IDeviceObject.h" +#include "renderer/backend/PipelineState.h" + +#include +#include + +namespace Renderer +{ + +namespace Backend +{ + +class IBuffer; +class IDevice; +class IFramebuffer; +class ITexture; + +class IDeviceCommandContext : public IDeviceObject +{ +public: + virtual void SetGraphicsPipelineState(const GraphicsPipelineStateDesc& pipelineStateDesc) = 0; + + virtual void BlitFramebuffer( + IFramebuffer* destinationFramebuffer, IFramebuffer* sourceFramebuffer) = 0; + + virtual void ClearFramebuffer() = 0; + virtual void ClearFramebuffer(const bool color, const bool depth, const bool stencil) = 0; + virtual void SetFramebuffer(IFramebuffer* framebuffer) = 0; + virtual void ReadbackFramebufferSync( + const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height, + void* data) = 0; + + virtual void UploadTexture(ITexture* texture, const Format dataFormat, + const void* data, const size_t dataSize, + const uint32_t level = 0, const uint32_t layer = 0) = 0; + virtual void UploadTextureRegion(ITexture* texture, const Format dataFormat, + const void* data, const size_t dataSize, + const uint32_t xOffset, const uint32_t yOffset, + const uint32_t width, const uint32_t height, + const uint32_t level = 0, const uint32_t layer = 0) = 0; + + using UploadBufferFunction = std::function; + virtual void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) = 0; + virtual void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) = 0; + virtual void UploadBufferRegion( + IBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize) = 0; + virtual void UploadBufferRegion( + IBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize, + const UploadBufferFunction& uploadFunction) = 0; + + // TODO: maybe we should add a more common type, like CRectI. + struct Rect + { + int32_t x, y; + int32_t width, height; + }; + virtual void SetScissors(const uint32_t scissorCount, const Rect* scissors) = 0; + virtual void SetViewports(const uint32_t viewportCount, const Rect* viewports) = 0; + + virtual void SetVertexAttributeFormat( + const VertexAttributeStream stream, + const Format format, + const uint32_t offset, + const uint32_t stride, + const uint32_t bindingSlot) = 0; + virtual void SetVertexBuffer(const uint32_t bindingSlot, IBuffer* buffer) = 0; + virtual void SetVertexBufferData(const uint32_t bindingSlot, const void* data) = 0; + + virtual void SetIndexBuffer(IBuffer* buffer) = 0; + virtual void SetIndexBufferData(const void* data) = 0; + + virtual void BeginPass() = 0; + virtual void EndPass() = 0; + + virtual void Draw(const uint32_t firstVertex, const uint32_t vertexCount) = 0; + virtual void DrawIndexed( + const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset) = 0; + // TODO: should be removed when performance impact is minimal on slow hardware. + virtual void DrawIndexedInRange( + const uint32_t firstIndex, const uint32_t indexCount, + const uint32_t start, const uint32_t end) = 0; + + virtual void SetTexture(const int32_t bindingSlot, ITexture* texture) = 0; + + virtual void SetUniform( + const int32_t bindingSlot, + const float value) = 0; + virtual void SetUniform( + const int32_t bindingSlot, + const float valueX, const float valueY) = 0; + virtual void SetUniform( + const int32_t bindingSlot, + const float valueX, const float valueY, + const float valueZ) = 0; + virtual void SetUniform( + const int32_t bindingSlot, + const float valueX, const float valueY, + const float valueZ, const float valueW) = 0; + virtual void SetUniform( + const int32_t bindingSlot, PS::span values) = 0; + + virtual void BeginScopedLabel(const char* name) = 0; + virtual void EndScopedLabel() = 0; + + virtual void Flush() = 0; +}; + +} // namespace Backend + +} // namespace Renderer + +#define GPU_SCOPED_LABEL(deviceCommandContext, name) \ + GPUScopedLabel scopedLabel((deviceCommandContext), (name)); + +class GPUScopedLabel +{ +public: + GPUScopedLabel( + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, + const char* name) + : m_DeviceCommandContext(deviceCommandContext) + { + m_DeviceCommandContext->BeginScopedLabel(name); + } + + ~GPUScopedLabel() + { + m_DeviceCommandContext->EndScopedLabel(); + } + +private: + Renderer::Backend::IDeviceCommandContext* m_DeviceCommandContext = nullptr; +}; + +#endif // INCLUDED_RENDERER_BACKEND_IDEVICECOMMANDCONTEXT diff --git a/source/renderer/backend/IDeviceObject.h b/source/renderer/backend/IDeviceObject.h new file mode 100644 index 0000000000..cb33be775d --- /dev/null +++ b/source/renderer/backend/IDeviceObject.h @@ -0,0 +1,51 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_IDEVICEOBJECT +#define INCLUDED_RENDERER_BACKEND_IDEVICEOBJECT + +#include + +namespace Renderer +{ + +namespace Backend +{ + +class IDevice; + +template +class IDeviceObject +{ +public: + virtual ~IDeviceObject() {} + + virtual IDevice* GetDevice() = 0; + + template + T* As() + { + static_assert(std::is_base_of_v); + return static_cast(this); + } +}; + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_IDEVICEOBJECT diff --git a/source/renderer/backend/IFramebuffer.h b/source/renderer/backend/IFramebuffer.h new file mode 100644 index 0000000000..d9a58e1ea9 --- /dev/null +++ b/source/renderer/backend/IFramebuffer.h @@ -0,0 +1,40 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_IFRAMEBUFFER +#define INCLUDED_RENDERER_BACKEND_IFRAMEBUFFER + +#include "graphics/Color.h" +#include "renderer/backend/IDeviceObject.h" + +namespace Renderer +{ + +namespace Backend +{ + +class IFramebuffer : public IDeviceObject +{ +public: + virtual const CColor& GetClearColor() const = 0; +}; + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_IFRAMEBUFFER diff --git a/source/renderer/backend/IShaderProgram.h b/source/renderer/backend/IShaderProgram.h index 0460cf1644..12fcf6a5b0 100644 --- a/source/renderer/backend/IShaderProgram.h +++ b/source/renderer/backend/IShaderProgram.h @@ -20,6 +20,7 @@ #include "lib/file/vfs/vfs_path.h" #include "ps/CStrIntern.h" +#include "renderer/backend/IDeviceObject.h" namespace Renderer { @@ -45,11 +46,9 @@ enum class VertexAttributeStream : uint32_t /** * IShaderProgram is a container for multiple shaders of different types. */ -class IShaderProgram +class IShaderProgram : public IDeviceObject { public: - virtual ~IShaderProgram() {} - virtual int32_t GetBindingSlot(const CStrIntern name) const = 0; virtual std::vector GetFileDependencies() const = 0; diff --git a/source/renderer/backend/ITexture.h b/source/renderer/backend/ITexture.h new file mode 100644 index 0000000000..dbf3b8cdb8 --- /dev/null +++ b/source/renderer/backend/ITexture.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_ITEXTURE +#define INCLUDED_RENDERER_BACKEND_ITEXTURE + +#include "renderer/backend/Format.h" +#include "renderer/backend/IDeviceObject.h" +#include "renderer/backend/Sampler.h" + +#include + +namespace Renderer +{ + +namespace Backend +{ + +class ITexture : public IDeviceObject +{ +public: + enum class Type + { + TEXTURE_2D, + TEXTURE_2D_MULTISAMPLE, + TEXTURE_CUBE + }; + + virtual Type GetType() const = 0; + virtual Format GetFormat() const = 0; + + virtual uint32_t GetWidth() const = 0; + virtual uint32_t GetHeight() const = 0; + virtual uint32_t GetMIPLevelCount() const = 0; +}; + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_ITEXTURE diff --git a/source/renderer/backend/dummy/Buffer.cpp b/source/renderer/backend/dummy/Buffer.cpp new file mode 100644 index 0000000000..d3f8f774b6 --- /dev/null +++ b/source/renderer/backend/dummy/Buffer.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "Buffer.h" + +#include "renderer/backend/dummy/Device.h" + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +// static +std::unique_ptr CBuffer::Create( + CDevice* device, const Type type, const uint32_t size, const bool dynamic) +{ + std::unique_ptr buffer(new CBuffer()); + buffer->m_Device = device; + buffer->m_Type = type; + buffer->m_Size = size; + buffer->m_Dynamic = dynamic; + return buffer; +} + +CBuffer::CBuffer() = default; + +CBuffer::~CBuffer() = default; + +IDevice* CBuffer::GetDevice() +{ + return m_Device; +} + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer diff --git a/source/renderer/backend/dummy/Buffer.h b/source/renderer/backend/dummy/Buffer.h new file mode 100644 index 0000000000..f8ba678de5 --- /dev/null +++ b/source/renderer/backend/dummy/Buffer.h @@ -0,0 +1,68 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_DUMMY_BUFFER +#define INCLUDED_RENDERER_BACKEND_DUMMY_BUFFER + +#include "renderer/backend/IBuffer.h" + +#include + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +class CDevice; + +class CBuffer : public IBuffer +{ +public: + ~CBuffer() override; + + IDevice* GetDevice() override; + + Type GetType() const override { return m_Type; } + uint32_t GetSize() const override { return m_Size; } + bool IsDynamic() const override { return m_Dynamic; } + +private: + friend class CDevice; + + static std::unique_ptr Create( + CDevice* device, const Type type, const uint32_t size, const bool dynamic); + + CBuffer(); + + CDevice* m_Device = nullptr; + + Type m_Type = Type::VERTEX; + uint32_t m_Size = 0; + bool m_Dynamic = false; +}; + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_DUMMY_BUFFER diff --git a/source/renderer/backend/dummy/Device.cpp b/source/renderer/backend/dummy/Device.cpp new file mode 100644 index 0000000000..939607f9cb --- /dev/null +++ b/source/renderer/backend/dummy/Device.cpp @@ -0,0 +1,128 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "Device.h" + +#include "renderer/backend/dummy/Buffer.h" +#include "renderer/backend/dummy/DeviceCommandContext.h" +#include "renderer/backend/dummy/Framebuffer.h" +#include "renderer/backend/dummy/ShaderProgram.h" +#include "renderer/backend/dummy/Texture.h" +#include "scriptinterface/JSON.h" +#include "scriptinterface/Object.h" +#include "scriptinterface/ScriptInterface.h" +#include "scriptinterface/ScriptRequest.h" + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +CDevice::CDevice() +{ + m_Name = "Dummy"; + m_Version = "Unknown"; + m_DriverInformation = "Unknown"; + m_Extensions = {}; + + m_Backbuffer = CFramebuffer::Create(this); + + m_Capabilities.S3TC = true; + m_Capabilities.ARBShaders = false; + m_Capabilities.ARBShadersShadow = false; + m_Capabilities.computeShaders = true; + m_Capabilities.debugLabels = true; + m_Capabilities.debugScopedLabels = true; + m_Capabilities.multisampling = true; + m_Capabilities.anisotropicFiltering = true; + m_Capabilities.maxSampleCount = 4u; + m_Capabilities.maxAnisotropy = 16.0f; + m_Capabilities.maxTextureSize = 8192u; +} + +CDevice::~CDevice() = default; + +void CDevice::Report(const ScriptRequest& rq, JS::HandleValue settings) +{ + Script::SetProperty(rq, settings, "name", "dummy"); +} + +std::unique_ptr CDevice::CreateCommandContext() +{ + return CDeviceCommandContext::Create(this); +} + +std::unique_ptr CDevice::CreateTexture(const char* UNUSED(name), const CTexture::Type type, + const Format format, const uint32_t width, const uint32_t height, + const Sampler::Desc& UNUSED(defaultSamplerDesc), const uint32_t MIPLevelCount, const uint32_t UNUSED(sampleCount)) +{ + return CTexture::Create(this, type, format, width, height, MIPLevelCount); +} + +std::unique_ptr CDevice::CreateTexture2D(const char* name, + const Format format, const uint32_t width, const uint32_t height, + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) +{ + return CreateTexture(name, ITexture::Type::TEXTURE_2D, + format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); +} + +std::unique_ptr CDevice::CreateFramebuffer( + const char*, ITexture*, ITexture*) +{ + return CFramebuffer::Create(this); +} + +std::unique_ptr CDevice::CreateFramebuffer( + const char*, ITexture*, ITexture*, const CColor&) +{ + return CFramebuffer::Create(this); +} + +std::unique_ptr CDevice::CreateBuffer( + const char*, const CBuffer::Type type, const uint32_t size, const bool dynamic) +{ + return CBuffer::Create(this, type, size, dynamic); +} + +std::unique_ptr CDevice::CreateShaderProgram( + const CStr&, const CShaderDefines&) +{ + return CShaderProgram::Create(this); +} + +void CDevice::Present() +{ + // We have nothing to present. +} + +bool CDevice::IsTextureFormatSupported(const Format UNUSED(format)) const +{ + return true; +} + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer diff --git a/source/renderer/backend/dummy/Device.h b/source/renderer/backend/dummy/Device.h new file mode 100644 index 0000000000..9fc3a6ad48 --- /dev/null +++ b/source/renderer/backend/dummy/Device.h @@ -0,0 +1,99 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_DUMMY_DEVICE +#define INCLUDED_RENDERER_BACKEND_DUMMY_DEVICE + +#include "renderer/backend/IDevice.h" + +class CShaderDefines; + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +class CDeviceCommandContext; + +class CDevice : public IDevice +{ +public: + CDevice(); + ~CDevice() override; + + const std::string& GetName() const override { return m_Name; } + const std::string& GetVersion() const override { return m_Version; } + const std::string& GetDriverInformation() const override { return m_DriverInformation; } + const std::vector& GetExtensions() const override { return m_Extensions; } + + void Report(const ScriptRequest& rq, JS::HandleValue settings) override; + + IFramebuffer* GetCurrentBackbuffer() override { return m_Backbuffer.get(); } + + std::unique_ptr CreateCommandContext() override; + + std::unique_ptr CreateTexture(const char* name, const ITexture::Type type, + const Format format, const uint32_t width, const uint32_t height, + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; + + std::unique_ptr CreateTexture2D(const char* name, + 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; + + std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment) override; + + std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment, const CColor& clearColor) override; + + std::unique_ptr CreateBuffer( + const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) override; + + std::unique_ptr CreateShaderProgram( + const CStr& name, const CShaderDefines& defines) override; + + void Present() override; + + bool IsTextureFormatSupported(const Format format) const override; + + const Capabilities& GetCapabilities() const override { return m_Capabilities; } + +private: + + std::string m_Name; + std::string m_Version; + std::string m_DriverInformation; + std::vector m_Extensions; + + std::unique_ptr m_Backbuffer; + + Capabilities m_Capabilities{}; +}; + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_DUMMY_DEVICE diff --git a/source/renderer/backend/dummy/DeviceCommandContext.cpp b/source/renderer/backend/dummy/DeviceCommandContext.cpp new file mode 100644 index 0000000000..76c601d35b --- /dev/null +++ b/source/renderer/backend/dummy/DeviceCommandContext.cpp @@ -0,0 +1,204 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "DeviceCommandContext.h" + +#include "renderer/backend/dummy/Buffer.h" +#include "renderer/backend/dummy/Device.h" +#include "renderer/backend/dummy/Framebuffer.h" +#include "renderer/backend/dummy/ShaderProgram.h" +#include "renderer/backend/dummy/Texture.h" + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +// static +std::unique_ptr CDeviceCommandContext::Create(CDevice* device) +{ + std::unique_ptr deviceCommandContext(new CDeviceCommandContext()); + deviceCommandContext->m_Device = device; + return deviceCommandContext; +} + +CDeviceCommandContext::CDeviceCommandContext() = default; + +CDeviceCommandContext::~CDeviceCommandContext() = default; + +IDevice* CDeviceCommandContext::GetDevice() +{ + return m_Device; +} + +void CDeviceCommandContext::SetGraphicsPipelineState( + const GraphicsPipelineStateDesc&) +{ +} + +void CDeviceCommandContext::UploadTexture( + ITexture*, const Format, const void*, const size_t, + const uint32_t, const uint32_t) +{ +} + +void CDeviceCommandContext::UploadTextureRegion( + ITexture*, const Format, const void*, const size_t, + const uint32_t, const uint32_t, const uint32_t, const uint32_t, + const uint32_t, const uint32_t) +{ +} + +void CDeviceCommandContext::UploadBuffer(IBuffer*, const void*, const uint32_t) +{ +} + +void CDeviceCommandContext::UploadBuffer(IBuffer*, const UploadBufferFunction&) +{ +} + +void CDeviceCommandContext::UploadBufferRegion( + IBuffer*, const void*, const uint32_t, const uint32_t) +{ +} + +void CDeviceCommandContext::UploadBufferRegion( + IBuffer*, const uint32_t, const uint32_t, const UploadBufferFunction&) +{ +} + +void CDeviceCommandContext::BeginScopedLabel(const char*) +{ +} + +void CDeviceCommandContext::EndScopedLabel() +{ +} + +void CDeviceCommandContext::Flush() +{ +} + +void CDeviceCommandContext::BlitFramebuffer(IFramebuffer*, IFramebuffer*) +{ +} + +void CDeviceCommandContext::ClearFramebuffer() +{ +} + +void CDeviceCommandContext::ClearFramebuffer(const bool, const bool, const bool) +{ +} + +void CDeviceCommandContext::SetFramebuffer(IFramebuffer*) +{ +} + +void CDeviceCommandContext::ReadbackFramebufferSync( + const uint32_t, const uint32_t, const uint32_t, const uint32_t, void*) +{ +} + +void CDeviceCommandContext::SetScissors(const uint32_t, const Rect*) +{ +} + +void CDeviceCommandContext::SetViewports(const uint32_t, const Rect*) +{ +} + +void CDeviceCommandContext::SetVertexAttributeFormat( + const VertexAttributeStream, const Format, + const uint32_t, const uint32_t, const uint32_t) +{ +} + +void CDeviceCommandContext::SetVertexBuffer(const uint32_t, IBuffer*) +{ +} + +void CDeviceCommandContext::SetVertexBufferData(const uint32_t, const void*) +{ +} + +void CDeviceCommandContext::SetIndexBuffer(IBuffer*) +{ +} + +void CDeviceCommandContext::SetIndexBufferData(const void*) +{ +} + +void CDeviceCommandContext::BeginPass() +{ +} + +void CDeviceCommandContext::EndPass() +{ +} + +void CDeviceCommandContext::Draw(const uint32_t, const uint32_t) +{ +} + +void CDeviceCommandContext::DrawIndexed(const uint32_t, const uint32_t, const int32_t) +{ +} + +void CDeviceCommandContext::DrawIndexedInRange( + const uint32_t, const uint32_t, const uint32_t, const uint32_t) +{ +} + +void CDeviceCommandContext::SetTexture(const int32_t, ITexture*) +{ +} + +void CDeviceCommandContext::SetUniform(const int32_t, const float) +{ +} + +void CDeviceCommandContext::SetUniform(const int32_t, const float, const float) +{ +} + +void CDeviceCommandContext::SetUniform( + const int32_t, const float, const float, const float) +{ +} + +void CDeviceCommandContext::SetUniform( + const int32_t, const float, const float, const float, const float) +{ +} + +void CDeviceCommandContext::SetUniform(const int32_t, PS::span) +{ +} + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer diff --git a/source/renderer/backend/dummy/DeviceCommandContext.h b/source/renderer/backend/dummy/DeviceCommandContext.h new file mode 100644 index 0000000000..bcb63b32ca --- /dev/null +++ b/source/renderer/backend/dummy/DeviceCommandContext.h @@ -0,0 +1,143 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_DUMMY_DEVICECOMMANDCONTEXT +#define INCLUDED_RENDERER_DUMMY_DEVICECOMMANDCONTEXT + +#include "renderer/backend/Format.h" +#include "renderer/backend/IDeviceCommandContext.h" +#include "renderer/backend/PipelineState.h" + +#include + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +class CDevice; +class CBuffer; +class CFramebuffer; +class CShaderProgram; +class CTexture; + +class CDeviceCommandContext : public IDeviceCommandContext +{ +public: + ~CDeviceCommandContext(); + + IDevice* GetDevice() override; + + void SetGraphicsPipelineState(const GraphicsPipelineStateDesc& pipelineStateDesc) override; + + void BlitFramebuffer(IFramebuffer* destinationFramebuffer, IFramebuffer* sourceFramebuffer) override; + + void ClearFramebuffer() override; + void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override; + void SetFramebuffer(IFramebuffer* framebuffer) override; + void ReadbackFramebufferSync( + const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height, + void* data) override; + + void UploadTexture(ITexture* texture, const Format dataFormat, + const void* data, const size_t dataSize, + const uint32_t level = 0, const uint32_t layer = 0) override; + void UploadTextureRegion(ITexture* texture, const Format dataFormat, + const void* data, const size_t dataSize, + const uint32_t xOffset, const uint32_t yOffset, + const uint32_t width, const uint32_t height, + const uint32_t level = 0, const uint32_t layer = 0) override; + + using UploadBufferFunction = std::function; + void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) override; + void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) override; + void UploadBufferRegion( + IBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize) override; + void UploadBufferRegion( + IBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize, + const UploadBufferFunction& uploadFunction) override; + + void SetScissors(const uint32_t scissorCount, const Rect* scissors) override; + void SetViewports(const uint32_t viewportCount, const Rect* viewports) override; + + void SetVertexAttributeFormat( + const VertexAttributeStream stream, + const Format format, + const uint32_t offset, + const uint32_t stride, + const uint32_t bindingSlot) override; + void SetVertexBuffer(const uint32_t bindingSlot, IBuffer* buffer) override; + void SetVertexBufferData(const uint32_t bindingSlot, const void* data) override; + + void SetIndexBuffer(IBuffer* buffer) override; + void SetIndexBufferData(const void* data) override; + + void BeginPass() override; + void EndPass() override; + + void Draw(const uint32_t firstVertex, const uint32_t vertexCount) override; + void DrawIndexed( + const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset) override; + void DrawIndexedInRange( + const uint32_t firstIndex, const uint32_t indexCount, + const uint32_t start, const uint32_t end) override; + + void SetTexture(const int32_t bindingSlot, ITexture* texture) override; + + void SetUniform( + const int32_t bindingSlot, + const float value) override; + void SetUniform( + const int32_t bindingSlot, + const float valueX, const float valueY) override; + void SetUniform( + const int32_t bindingSlot, + const float valueX, const float valueY, + const float valueZ) override; + void SetUniform( + const int32_t bindingSlot, + const float valueX, const float valueY, + const float valueZ, const float valueW) override; + void SetUniform( + const int32_t bindingSlot, PS::span values) override; + + void BeginScopedLabel(const char* name) override; + void EndScopedLabel() override; + + void Flush() override; + +private: + friend class CDevice; + + static std::unique_ptr Create(CDevice* device); + + CDeviceCommandContext(); + + CDevice* m_Device = nullptr; +}; + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_DUMMY_DEVICECOMMANDCONTEXT diff --git a/source/renderer/backend/dummy/Framebuffer.cpp b/source/renderer/backend/dummy/Framebuffer.cpp new file mode 100644 index 0000000000..795a543e11 --- /dev/null +++ b/source/renderer/backend/dummy/Framebuffer.cpp @@ -0,0 +1,54 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "Framebuffer.h" + +#include "renderer/backend/dummy/Device.h" + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +CFramebuffer::CFramebuffer() = default; + +CFramebuffer::~CFramebuffer() = default; + +// static +std::unique_ptr CFramebuffer::Create(CDevice* device) +{ + std::unique_ptr framebuffer(new CFramebuffer()); + framebuffer->m_Device = device; + return framebuffer; +} + +IDevice* CFramebuffer::GetDevice() +{ + return m_Device; +} + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer diff --git a/source/renderer/backend/dummy/Framebuffer.h b/source/renderer/backend/dummy/Framebuffer.h new file mode 100644 index 0000000000..7a71cd7900 --- /dev/null +++ b/source/renderer/backend/dummy/Framebuffer.h @@ -0,0 +1,63 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_DUMMY_FRAMEBUFFER +#define INCLUDED_RENDERER_BACKEND_DUMMY_FRAMEBUFFER + +#include "renderer/backend/IFramebuffer.h" + +#include + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +class CDevice; + +class CFramebuffer : public IFramebuffer +{ +public: + ~CFramebuffer() override; + + IDevice* GetDevice() override; + + const CColor& GetClearColor() const override { return m_ClearColor; } + +private: + friend class CDevice; + + static std::unique_ptr Create(CDevice* device); + + CFramebuffer(); + + CDevice* m_Device = nullptr; + + CColor m_ClearColor; +}; + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_DUMMY_FRAMEBUFFER diff --git a/source/renderer/backend/dummy/ShaderProgram.cpp b/source/renderer/backend/dummy/ShaderProgram.cpp new file mode 100644 index 0000000000..2a26543b60 --- /dev/null +++ b/source/renderer/backend/dummy/ShaderProgram.cpp @@ -0,0 +1,64 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "ShaderProgram.h" + +#include "renderer/backend/dummy/Device.h" + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +CShaderProgram::CShaderProgram() = default; + +CShaderProgram::~CShaderProgram() = default; + +// static +std::unique_ptr CShaderProgram::Create(CDevice* device) +{ + std::unique_ptr shaderProgram(new CShaderProgram()); + shaderProgram->m_Device = device; + return shaderProgram; +} + +IDevice* CShaderProgram::GetDevice() +{ + return m_Device; +} + +int32_t CShaderProgram::GetBindingSlot(const CStrIntern UNUSED(name)) const +{ + return -1; +} + +std::vector CShaderProgram::GetFileDependencies() const +{ + return {}; +} + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer diff --git a/source/renderer/backend/dummy/ShaderProgram.h b/source/renderer/backend/dummy/ShaderProgram.h new file mode 100644 index 0000000000..b345b508eb --- /dev/null +++ b/source/renderer/backend/dummy/ShaderProgram.h @@ -0,0 +1,63 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_DUMMY_SHADERPROGRAM +#define INCLUDED_RENDERER_BACKEND_DUMMY_SHADERPROGRAM + +#include "renderer/backend/IShaderProgram.h" + +#include + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +class CDevice; + +class CShaderProgram : public IShaderProgram +{ +public: + ~CShaderProgram() override; + + IDevice* GetDevice() override; + + int32_t GetBindingSlot(const CStrIntern name) const override; + + std::vector GetFileDependencies() const override; + +protected: + friend class CDevice; + + CShaderProgram(); + + static std::unique_ptr Create(CDevice* device); + + CDevice* m_Device = nullptr; +}; + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_DUMMY_SHADERPROGRAM diff --git a/source/renderer/backend/dummy/Texture.cpp b/source/renderer/backend/dummy/Texture.cpp new file mode 100644 index 0000000000..76e2c7de9b --- /dev/null +++ b/source/renderer/backend/dummy/Texture.cpp @@ -0,0 +1,64 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "Texture.h" + +#include "renderer/backend/dummy/Device.h" + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +// static +std::unique_ptr CTexture::Create( + CDevice* device, const Type type, const Format format, + const uint32_t width, const uint32_t height, + const uint32_t MIPLevelCount) +{ + std::unique_ptr texture(new CTexture()); + + texture->m_Device = device; + texture->m_Format = format; + texture->m_Type = type; + texture->m_Width = width; + texture->m_Height = height; + texture->m_MIPLevelCount = MIPLevelCount; + + return texture; +} + +CTexture::CTexture() = default; + +CTexture::~CTexture() = default; + +IDevice* CTexture::GetDevice() +{ + return m_Device; +} + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer diff --git a/source/renderer/backend/dummy/Texture.h b/source/renderer/backend/dummy/Texture.h new file mode 100644 index 0000000000..00e915bc4f --- /dev/null +++ b/source/renderer/backend/dummy/Texture.h @@ -0,0 +1,74 @@ +/* Copyright (C) 2022 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_RENDERER_BACKEND_DUMMY_TEXTURE +#define INCLUDED_RENDERER_BACKEND_DUMMY_TEXTURE + +#include "renderer/backend/ITexture.h" + +#include + +namespace Renderer +{ + +namespace Backend +{ + +namespace Dummy +{ + +class CDevice; + +class CTexture : public ITexture +{ +public: + ~CTexture() override; + + IDevice* GetDevice() override; + + Type GetType() const override { return m_Type; } + Format GetFormat() const override { return m_Format; } + + uint32_t GetWidth() const override { return m_Width; } + uint32_t GetHeight() const override { return m_Height; } + uint32_t GetMIPLevelCount() const override { return m_MIPLevelCount; } + +private: + friend class CDevice; + + CTexture(); + + static std::unique_ptr Create( + CDevice* device, const Type type, const Format format, + const uint32_t width, const uint32_t height, + const uint32_t MIPLevelCount); + + CDevice* m_Device = nullptr; + Type m_Type = Type::TEXTURE_2D; + Format m_Format = Format::UNDEFINED; + uint32_t m_Width = 0; + uint32_t m_Height = 0; + uint32_t m_MIPLevelCount = 0; +}; + +} // namespace Dummy + +} // namespace Backend + +} // namespace Renderer + +#endif // INCLUDED_RENDERER_BACKEND_DUMMY_TEXTURE diff --git a/source/renderer/backend/gl/Buffer.cpp b/source/renderer/backend/gl/Buffer.cpp index 55bde24f2b..462ca6f7d8 100644 --- a/source/renderer/backend/gl/Buffer.cpp +++ b/source/renderer/backend/gl/Buffer.cpp @@ -69,6 +69,11 @@ CBuffer::~CBuffer() glDeleteBuffersARB(1, &m_Handle); } +IDevice* CBuffer::GetDevice() +{ + return m_Device; +} + } // namespace GL } // namespace Backend diff --git a/source/renderer/backend/gl/Buffer.h b/source/renderer/backend/gl/Buffer.h index 11703e1969..5e587bb398 100644 --- a/source/renderer/backend/gl/Buffer.h +++ b/source/renderer/backend/gl/Buffer.h @@ -19,6 +19,7 @@ #define INCLUDED_RENDERER_BACKEND_GL_BUFFER #include "lib/ogl.h" +#include "renderer/backend/IBuffer.h" #include #include @@ -34,20 +35,16 @@ namespace GL class CDevice; -class CBuffer +class CBuffer final : public IBuffer { public: - enum class Type - { - VERTEX, - INDEX - }; + ~CBuffer() override; - ~CBuffer(); + IDevice* GetDevice() override; - Type GetType() const { return m_Type; } - uint32_t GetSize() const { return m_Size; } - bool IsDynamic() const { return m_Dynamic; } + Type GetType() const override { return m_Type; } + uint32_t GetSize() const override { return m_Size; } + bool IsDynamic() const override { return m_Dynamic; } GLuint GetHandle() { return m_Handle; } @@ -64,6 +61,7 @@ private: Type m_Type = Type::VERTEX; uint32_t m_Size = 0; bool m_Dynamic = false; + GLuint m_Handle = 0; }; diff --git a/source/renderer/backend/gl/Device.cpp b/source/renderer/backend/gl/Device.cpp index 7fbce75d55..e1d307f16b 100644 --- a/source/renderer/backend/gl/Device.cpp +++ b/source/renderer/backend/gl/Device.cpp @@ -218,7 +218,7 @@ void GLAD_API_PTR OnDebugMessage( } // anonymous namespace // static -std::unique_ptr CDevice::Create(SDL_Window* window, const bool arb) +std::unique_ptr CDevice::Create(SDL_Window* window, const bool arb) { std::unique_ptr device(new CDevice()); @@ -278,6 +278,8 @@ std::unique_ptr CDevice::Create(SDL_Window* window, const bool arb) ); } + device->m_ARB = arb; + device->m_Name = GetNameImpl(); device->m_Version = GetVersionImpl(); device->m_DriverInformation = GetDriverInformationImpl(); @@ -395,6 +397,8 @@ void CDevice::Report(const ScriptRequest& rq, JS::HandleValue settings) { const char* errstr = "(error)"; + Script::SetProperty(rq, settings, "name", m_ARB ? "glarb" : "gl"); + #define INTEGER(id) do { \ GLint i = -1; \ glGetIntegerv(GL_##id, &i); \ @@ -778,14 +782,14 @@ void CDevice::Report(const ScriptRequest& rq, JS::HandleValue settings) #endif // SDL_VIDEO_DRIVER_X11 } -std::unique_ptr CDevice::CreateCommandContext() +std::unique_ptr CDevice::CreateCommandContext() { std::unique_ptr commandContet = CDeviceCommandContext::Create(this); m_ActiveCommandContext = commandContet.get(); return commandContet; } -std::unique_ptr CDevice::CreateTexture(const char* name, const CTexture::Type type, +std::unique_ptr CDevice::CreateTexture(const char* name, const ITexture::Type type, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) { @@ -793,7 +797,7 @@ std::unique_ptr CDevice::CreateTexture(const char* name, const CTextur format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); } -std::unique_ptr CDevice::CreateTexture2D(const char* name, +std::unique_ptr CDevice::CreateTexture2D(const char* name, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) { @@ -801,22 +805,23 @@ std::unique_ptr CDevice::CreateTexture2D(const char* name, format, width, height, defaultSamplerDesc, MIPLevelCount, sampleCount); } -std::unique_ptr CDevice::CreateFramebuffer( - const char* name, CTexture* colorAttachment, - CTexture* depthStencilAttachment) +std::unique_ptr CDevice::CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment) { return CreateFramebuffer(name, colorAttachment, depthStencilAttachment, CColor(0.0f, 0.0f, 0.0f, 0.0f)); } -std::unique_ptr CDevice::CreateFramebuffer( - const char* name, CTexture* colorAttachment, - CTexture* depthStencilAttachment, const CColor& clearColor) +std::unique_ptr CDevice::CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment, const CColor& clearColor) { - return CFramebuffer::Create(this, name, colorAttachment, depthStencilAttachment, clearColor); + return CFramebuffer::Create( + this, name, colorAttachment->As(), depthStencilAttachment->As(), clearColor); } -std::unique_ptr CDevice::CreateBuffer( - const char* name, const CBuffer::Type type, const uint32_t size, const bool dynamic) +std::unique_ptr CDevice::CreateBuffer( + const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) { return CBuffer::Create(this, name, type, size, dynamic); } diff --git a/source/renderer/backend/gl/Device.h b/source/renderer/backend/gl/Device.h index bbf1e755c2..74965c2dfa 100644 --- a/source/renderer/backend/gl/Device.h +++ b/source/renderer/backend/gl/Device.h @@ -23,6 +23,7 @@ #include "renderer/backend/gl/Framebuffer.h" #include "renderer/backend/gl/ShaderProgram.h" #include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IDevice.h" #include "scriptinterface/ScriptForward.h" #include @@ -43,71 +44,56 @@ namespace GL class CDeviceCommandContext; -class CDevice +class CDevice final : public IDevice { public: - struct Capabilities - { - bool S3TC; - bool ARBShaders; - bool ARBShadersShadow; - bool computeShaders; - bool debugLabels; - bool debugScopedLabels; - bool multisampling; - bool anisotropicFiltering; - uint32_t maxSampleCount; - float maxAnisotropy; - uint32_t maxTextureSize; - }; - - ~CDevice(); + ~CDevice() override; /** * Creates the GL device and the GL context for the window if it presents. */ - static std::unique_ptr Create(SDL_Window* window, const bool arb); + static std::unique_ptr Create(SDL_Window* window, const bool arb); - const std::string& GetName() const { return m_Name; } - const std::string& GetVersion() const { return m_Version; } - const std::string& GetDriverInformation() const { return m_DriverInformation; } - const std::vector& GetExtensions() const { return m_Extensions; } + const std::string& GetName() const override { return m_Name; } + const std::string& GetVersion() const override { return m_Version; } + const std::string& GetDriverInformation() const override { return m_DriverInformation; } + const std::vector& GetExtensions() const override { return m_Extensions; } - void Report(const ScriptRequest& rq, JS::HandleValue settings); + void Report(const ScriptRequest& rq, JS::HandleValue settings) override; - CFramebuffer* GetCurrentBackbuffer() { return m_Backbuffer.get(); } + IFramebuffer* GetCurrentBackbuffer() override { return m_Backbuffer.get(); } - std::unique_ptr CreateCommandContext(); + std::unique_ptr CreateCommandContext() override; CDeviceCommandContext* GetActiveCommandContext() { return m_ActiveCommandContext; } - std::unique_ptr CreateTexture(const char* name, const CTexture::Type type, + std::unique_ptr CreateTexture(const char* name, const ITexture::Type type, const Format format, const uint32_t width, const uint32_t height, - const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount); + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; - std::unique_ptr CreateTexture2D(const char* name, + std::unique_ptr CreateTexture2D(const char* name, 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); + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount = 1, const uint32_t sampleCount = 1) override; - std::unique_ptr CreateFramebuffer( - const char* name, CTexture* colorAttachment, - CTexture* depthStencilAttachment); + std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment) override; - std::unique_ptr CreateFramebuffer( - const char* name, CTexture* colorAttachment, - CTexture* depthStencilAttachment, const CColor& clearColor); + std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment, const CColor& clearColor) override; - std::unique_ptr CreateBuffer( - const char* name, const CBuffer::Type type, const uint32_t size, const bool dynamic); + std::unique_ptr CreateBuffer( + const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) override; std::unique_ptr CreateShaderProgram( - const CStr& name, const CShaderDefines& defines); + const CStr& name, const CShaderDefines& defines) override; - void Present(); + void Present() override; - bool IsTextureFormatSupported(const Format format) const; + bool IsTextureFormatSupported(const Format format) const override; - const Capabilities& GetCapabilities() const { return m_Capabilities; } + const Capabilities& GetCapabilities() const override { return m_Capabilities; } private: CDevice(); @@ -115,6 +101,8 @@ private: SDL_Window* m_Window = nullptr; SDL_GLContext m_Context = nullptr; + bool m_ARB = false; + std::string m_Name; std::string m_Version; std::string m_DriverInformation; diff --git a/source/renderer/backend/gl/DeviceCommandContext.cpp b/source/renderer/backend/gl/DeviceCommandContext.cpp index 0b413228ae..cc1810e190 100644 --- a/source/renderer/backend/gl/DeviceCommandContext.cpp +++ b/source/renderer/backend/gl/DeviceCommandContext.cpp @@ -147,7 +147,7 @@ void UploadBufferRegionImpl( std::unique_ptr CDeviceCommandContext::Create(CDevice* device) { std::unique_ptr deviceCommandContext(new CDeviceCommandContext(device)); - deviceCommandContext->m_Framebuffer = device->GetCurrentBackbuffer(); + deviceCommandContext->m_Framebuffer = static_cast(device->GetCurrentBackbuffer()); deviceCommandContext->ResetStates(); return deviceCommandContext; } @@ -181,6 +181,11 @@ CDeviceCommandContext::CDeviceCommandContext(CDevice* device) CDeviceCommandContext::~CDeviceCommandContext() = default; +IDevice* CDeviceCommandContext::GetDevice() +{ + return m_Device; +} + void CDeviceCommandContext::SetGraphicsPipelineState( const GraphicsPipelineStateDesc& pipelineStateDesc) { @@ -188,7 +193,7 @@ void CDeviceCommandContext::SetGraphicsPipelineState( } void CDeviceCommandContext::UploadTexture( - CTexture* texture, const Format format, + ITexture* texture, const Format format, const void* data, const size_t dataSize, const uint32_t level, const uint32_t layer) { @@ -200,13 +205,14 @@ void CDeviceCommandContext::UploadTexture( } void CDeviceCommandContext::UploadTextureRegion( - CTexture* texture, const Format dataFormat, + ITexture* destinationTexture, const Format dataFormat, const void* data, const size_t dataSize, const uint32_t xOffset, const uint32_t yOffset, const uint32_t width, const uint32_t height, const uint32_t level, const uint32_t layer) { - ENSURE(texture); + ENSURE(destinationTexture); + CTexture* texture = destinationTexture->As(); ENSURE(width > 0 && height > 0); if (texture->GetType() == CTexture::Type::TEXTURE_2D) { @@ -312,24 +318,24 @@ void CDeviceCommandContext::UploadTextureRegion( debug_warn("Unsupported type"); } -void CDeviceCommandContext::UploadBuffer(CBuffer* buffer, const void* data, const uint32_t dataSize) +void CDeviceCommandContext::UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) { UploadBufferRegion(buffer, data, dataSize, 0); } void CDeviceCommandContext::UploadBuffer( - CBuffer* buffer, const UploadBufferFunction& uploadFunction) + IBuffer* buffer, const UploadBufferFunction& uploadFunction) { UploadBufferRegion(buffer, 0, buffer->GetSize(), uploadFunction); } void CDeviceCommandContext::UploadBufferRegion( - CBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize) + IBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize) { ENSURE(data); ENSURE(dataOffset + dataSize <= buffer->GetSize()); const GLenum target = BufferTypeToGLTarget(buffer->GetType()); - ScopedBufferBind scopedBufferBind(this, buffer); + ScopedBufferBind scopedBufferBind(this, buffer->As()); if (buffer->IsDynamic()) { // Tell the driver that it can reallocate the whole VBO @@ -354,12 +360,12 @@ void CDeviceCommandContext::UploadBufferRegion( } void CDeviceCommandContext::UploadBufferRegion( - CBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize, + IBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize, const UploadBufferFunction& uploadFunction) { ENSURE(dataOffset + dataSize <= buffer->GetSize()); const GLenum target = BufferTypeToGLTarget(buffer->GetType()); - ScopedBufferBind scopedBufferBind(this, buffer); + ScopedBufferBind scopedBufferBind(this, buffer->As()); ENSURE(buffer->IsDynamic()); UploadBufferRegionImpl(target, dataOffset, dataSize, uploadFunction); } @@ -407,16 +413,16 @@ void CDeviceCommandContext::BindTexture( m_BoundTextures[unit] = {target, handle}; } -void CDeviceCommandContext::BindBuffer(const CBuffer::Type type, CBuffer* buffer) +void CDeviceCommandContext::BindBuffer(const IBuffer::Type type, CBuffer* buffer) { ENSURE(!buffer || buffer->GetType() == type); - if (type == CBuffer::Type::VERTEX) + if (type == IBuffer::Type::VERTEX) { if (m_VertexBuffer == buffer) return; m_VertexBuffer = buffer; } - else if (type == CBuffer::Type::INDEX) + else if (type == IBuffer::Type::INDEX) { if (!buffer) m_IndexBuffer = nullptr; @@ -713,16 +719,18 @@ void CDeviceCommandContext::SetGraphicsPipelineStateImpl( } void CDeviceCommandContext::BlitFramebuffer( - CFramebuffer* destinationFramebuffer, CFramebuffer* sourceFramebuffer) + IFramebuffer* dstFramebuffer, IFramebuffer* srcFramebuffer) { + CFramebuffer* destinationFramebuffer = dstFramebuffer->As(); + CFramebuffer* sourceFramebuffer = srcFramebuffer->As(); #if CONFIG2_GLES UNUSED2(destinationFramebuffer); UNUSED2(sourceFramebuffer); debug_warn("CDeviceCommandContext::BlitFramebuffer is not implemented for GLES"); #else // Source framebuffer should not be backbuffer. - ENSURE( sourceFramebuffer->GetHandle() != 0); - ENSURE( destinationFramebuffer != sourceFramebuffer ); + ENSURE(sourceFramebuffer->GetHandle() != 0); + ENSURE(destinationFramebuffer != sourceFramebuffer); glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, sourceFramebuffer->GetHandle()); glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, destinationFramebuffer->GetHandle()); // TODO: add more check for internal formats. And currently we don't support @@ -777,12 +785,12 @@ void CDeviceCommandContext::ClearFramebuffer(const bool color, const bool depth, ApplyStencilMask(m_GraphicsPipelineStateDesc.depthStencilState.stencilWriteMask); } -void CDeviceCommandContext::SetFramebuffer(CFramebuffer* framebuffer) +void CDeviceCommandContext::SetFramebuffer(IFramebuffer* framebuffer) { ENSURE(framebuffer); - ENSURE(framebuffer->GetHandle() == 0 || (framebuffer->GetWidth() > 0 && framebuffer->GetHeight() > 0)); - m_Framebuffer = framebuffer; - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->GetHandle()); + m_Framebuffer = framebuffer->As(); + ENSURE(m_Framebuffer->GetHandle() == 0 || (m_Framebuffer->GetWidth() > 0 && m_Framebuffer->GetHeight() > 0)); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_Framebuffer->GetHandle()); ogl_WarnIfError(); } @@ -846,12 +854,12 @@ void CDeviceCommandContext::SetVertexAttributeFormat( } void CDeviceCommandContext::SetVertexBuffer( - const uint32_t bindingSlot, CBuffer* buffer) + const uint32_t bindingSlot, IBuffer* buffer) { ENSURE(buffer); - ENSURE(buffer->GetType() == CBuffer::Type::VERTEX); + ENSURE(buffer->GetType() == IBuffer::Type::VERTEX); ENSURE(m_ShaderProgram); - BindBuffer(buffer->GetType(), buffer); + BindBuffer(buffer->GetType(), buffer->As()); for (size_t index = 0; index < m_VertexAttributeFormat.size(); ++index) { if (!m_VertexAttributeFormat[index].active || m_VertexAttributeFormat[index].bindingSlot != bindingSlot) @@ -886,10 +894,10 @@ void CDeviceCommandContext::SetVertexBufferData( } } -void CDeviceCommandContext::SetIndexBuffer(CBuffer* buffer) +void CDeviceCommandContext::SetIndexBuffer(IBuffer* buffer) { ENSURE(buffer->GetType() == CBuffer::Type::INDEX); - m_IndexBuffer = buffer; + m_IndexBuffer = buffer->As(); m_IndexBufferData = nullptr; BindBuffer(CBuffer::Type::INDEX, m_IndexBuffer); } @@ -976,7 +984,7 @@ void CDeviceCommandContext::DrawIndexedInRange( ogl_WarnIfError(); } -void CDeviceCommandContext::SetTexture(const int32_t bindingSlot, CTexture* texture) +void CDeviceCommandContext::SetTexture(const int32_t bindingSlot, ITexture* texture) { ENSURE(m_ShaderProgram); ENSURE(texture); @@ -1013,7 +1021,7 @@ void CDeviceCommandContext::SetTexture(const int32_t bindingSlot, CTexture* text LOGERROR("CDeviceCommandContext::SetTexture: Invalid texture unit (too big)"); return; } - BindTexture(unit, textureUnit.target, texture->GetHandle()); + BindTexture(unit, textureUnit.target, texture->As()->GetHandle()); } void CDeviceCommandContext::SetUniform( diff --git a/source/renderer/backend/gl/DeviceCommandContext.h b/source/renderer/backend/gl/DeviceCommandContext.h index b2cc0eb7fc..7ba5c80abd 100644 --- a/source/renderer/backend/gl/DeviceCommandContext.h +++ b/source/renderer/backend/gl/DeviceCommandContext.h @@ -22,6 +22,7 @@ #include "ps/containers/Span.h" #include "renderer/backend/Format.h" #include "renderer/backend/gl/Buffer.h" +#include "renderer/backend/IDeviceCommandContext.h" #include "renderer/backend/PipelineState.h" #include @@ -45,101 +46,94 @@ class CFramebuffer; class CShaderProgram; class CTexture; -class CDeviceCommandContext +class CDeviceCommandContext final : public IDeviceCommandContext { public: ~CDeviceCommandContext(); - CDevice* GetDevice() { return m_Device; } + IDevice* GetDevice() override; - void SetGraphicsPipelineState(const GraphicsPipelineStateDesc& pipelineStateDesc); + void SetGraphicsPipelineState(const GraphicsPipelineStateDesc& pipelineStateDesc) override; - void BlitFramebuffer(CFramebuffer* destinationFramebuffer, CFramebuffer* sourceFramebuffer); + void BlitFramebuffer(IFramebuffer* destinationFramebuffer, IFramebuffer* sourceFramebuffer) override; - void ClearFramebuffer(); - void ClearFramebuffer(const bool color, const bool depth, const bool stencil); - void SetFramebuffer(CFramebuffer* framebuffer); + void ClearFramebuffer() override; + void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override; + void SetFramebuffer(IFramebuffer* framebuffer) override; void ReadbackFramebufferSync( const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height, - void* data); + void* data) override; - void UploadTexture(CTexture* texture, const Format dataFormat, + void UploadTexture(ITexture* texture, const Format dataFormat, const void* data, const size_t dataSize, - const uint32_t level = 0, const uint32_t layer = 0); - void UploadTextureRegion(CTexture* texture, const Format dataFormat, + const uint32_t level = 0, const uint32_t layer = 0) override; + void UploadTextureRegion(ITexture* texture, const Format dataFormat, const void* data, const size_t dataSize, const uint32_t xOffset, const uint32_t yOffset, const uint32_t width, const uint32_t height, - const uint32_t level = 0, const uint32_t layer = 0); + const uint32_t level = 0, const uint32_t layer = 0) override; using UploadBufferFunction = std::function; - void UploadBuffer(CBuffer* buffer, const void* data, const uint32_t dataSize); - void UploadBuffer(CBuffer* buffer, const UploadBufferFunction& uploadFunction); + void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) override; + void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) override; void UploadBufferRegion( - CBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize); + IBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize) override; void UploadBufferRegion( - CBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize, - const UploadBufferFunction& uploadFunction); + IBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize, + const UploadBufferFunction& uploadFunction) override; - // TODO: maybe we should add a more common type, like CRectI. - struct Rect - { - int32_t x, y; - int32_t width, height; - }; - void SetScissors(const uint32_t scissorCount, const Rect* scissors); - void SetViewports(const uint32_t viewportCount, const Rect* viewports); + void SetScissors(const uint32_t scissorCount, const Rect* scissors) override; + void SetViewports(const uint32_t viewportCount, const Rect* viewports) override; void SetVertexAttributeFormat( const VertexAttributeStream stream, const Format format, const uint32_t offset, const uint32_t stride, - const uint32_t bindingSlot); - void SetVertexBuffer(const uint32_t bindingSlot, CBuffer* buffer); - void SetVertexBufferData(const uint32_t bindingSlot, const void* data); + const uint32_t bindingSlot) override; + void SetVertexBuffer(const uint32_t bindingSlot, IBuffer* buffer) override; + void SetVertexBufferData(const uint32_t bindingSlot, const void* data) override; - void SetIndexBuffer(CBuffer* buffer); - void SetIndexBufferData(const void* data); + void SetIndexBuffer(IBuffer* buffer) override; + void SetIndexBufferData(const void* data) override; - void BeginPass(); - void EndPass(); + void BeginPass() override; + void EndPass() override; - void Draw(const uint32_t firstVertex, const uint32_t vertexCount); + void Draw(const uint32_t firstVertex, const uint32_t vertexCount) override; void DrawIndexed( - const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset); - // TODO: should be removed when performance impact is minimal on slow hardware. + const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset) override; void DrawIndexedInRange( const uint32_t firstIndex, const uint32_t indexCount, - const uint32_t start, const uint32_t end); + const uint32_t start, const uint32_t end) override; - void SetTexture(const int32_t bindingSlot, CTexture* texture); + void SetTexture(const int32_t bindingSlot, ITexture* texture) override; void SetUniform( const int32_t bindingSlot, - const float value); + const float value) override; void SetUniform( const int32_t bindingSlot, - const float valueX, const float valueY); + const float valueX, const float valueY) override; void SetUniform( const int32_t bindingSlot, const float valueX, const float valueY, - const float valueZ); + const float valueZ) override; void SetUniform( const int32_t bindingSlot, const float valueX, const float valueY, - const float valueZ, const float valueW); + const float valueZ, const float valueW) override; void SetUniform( - const int32_t bindingSlot, PS::span values); + const int32_t bindingSlot, PS::span values) override; - void BeginScopedLabel(const char* name); - void EndScopedLabel(); + void BeginScopedLabel(const char* name) override; + void EndScopedLabel() override; + + void Flush() override; // We need to know when to invalidate our texture bind cache. void OnTextureDestroy(CTexture* texture); - void Flush(); - private: friend class CDevice; friend class CTexture; @@ -154,7 +148,7 @@ private: const GraphicsPipelineStateDesc& pipelineStateDesc, const bool force); void BindTexture(const uint32_t unit, const GLenum target, const GLuint handle); - void BindBuffer(const CBuffer::Type type, CBuffer* buffer); + void BindBuffer(const IBuffer::Type type, CBuffer* buffer); CDevice* m_Device = nullptr; @@ -228,27 +222,4 @@ private: } // namespace Renderer -#define GPU_SCOPED_LABEL(deviceCommandContext, name) \ - GPUScopedLabel scopedLabel((deviceCommandContext), (name)); - -class GPUScopedLabel -{ -public: - GPUScopedLabel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, - const char* name) - : m_DeviceCommandContext(deviceCommandContext) - { - m_DeviceCommandContext->BeginScopedLabel(name); - } - - ~GPUScopedLabel() - { - m_DeviceCommandContext->EndScopedLabel(); - } - -private: - Renderer::Backend::GL::CDeviceCommandContext* m_DeviceCommandContext = nullptr; -}; - #endif // INCLUDED_RENDERER_GL_DEVICECOMMANDCONTEXT diff --git a/source/renderer/backend/gl/Framebuffer.cpp b/source/renderer/backend/gl/Framebuffer.cpp index 03e8cf65c3..96fd785637 100644 --- a/source/renderer/backend/gl/Framebuffer.cpp +++ b/source/renderer/backend/gl/Framebuffer.cpp @@ -167,6 +167,11 @@ CFramebuffer::~CFramebuffer() glDeleteFramebuffersEXT(1, &m_Handle); } +IDevice* CFramebuffer::GetDevice() +{ + return m_Device; +} + } // namespace GL } // namespace Backend diff --git a/source/renderer/backend/gl/Framebuffer.h b/source/renderer/backend/gl/Framebuffer.h index 76faab58ef..7c69789654 100644 --- a/source/renderer/backend/gl/Framebuffer.h +++ b/source/renderer/backend/gl/Framebuffer.h @@ -20,7 +20,7 @@ #include "graphics/Color.h" #include "lib/ogl.h" -#include "renderer/backend/gl/Texture.h" +#include "renderer/backend/IFramebuffer.h" #include #include @@ -35,15 +35,19 @@ namespace GL { class CDevice; +class CTexture; -class CFramebuffer +class CFramebuffer final : public IFramebuffer { public: - ~CFramebuffer(); + ~CFramebuffer() override; + + IDevice* GetDevice() override; + + const CColor& GetClearColor() const override { return m_ClearColor; } GLuint GetHandle() const { return m_Handle; } GLbitfield GetAttachmentMask() const { return m_AttachmentMask; } - const CColor& GetClearColor() const { return m_ClearColor; } uint32_t GetWidth() const { return m_Width; } uint32_t GetHeight() const { return m_Height; } diff --git a/source/renderer/backend/gl/ShaderProgram.cpp b/source/renderer/backend/gl/ShaderProgram.cpp index 1a04f5ca39..2aaaed3f23 100644 --- a/source/renderer/backend/gl/ShaderProgram.cpp +++ b/source/renderer/backend/gl/ShaderProgram.cpp @@ -379,6 +379,8 @@ public: UnbindClientStates(); } + IDevice* GetDevice() override { return m_Device; } + int32_t GetBindingSlot(const CStrIntern name) const override { auto it = m_BindingSlotsMapping.find(name); @@ -960,6 +962,8 @@ public: glDisableVertexAttribArray(index); } + IDevice* GetDevice() override { return m_Device; } + int32_t GetBindingSlot(const CStrIntern name) const override { auto it = m_BindingSlotsMapping.find(name); diff --git a/source/renderer/backend/gl/Texture.cpp b/source/renderer/backend/gl/Texture.cpp index bbb69407a6..23e48fc8b5 100644 --- a/source/renderer/backend/gl/Texture.cpp +++ b/source/renderer/backend/gl/Texture.cpp @@ -297,6 +297,11 @@ CTexture::~CTexture() glDeleteTextures(1, &m_Handle); } +IDevice* CTexture::GetDevice() +{ + return m_Device; +} + } // namespace GL } // namespace Backend diff --git a/source/renderer/backend/gl/Texture.h b/source/renderer/backend/gl/Texture.h index c6651304e2..68234ec8bc 100644 --- a/source/renderer/backend/gl/Texture.h +++ b/source/renderer/backend/gl/Texture.h @@ -19,7 +19,7 @@ #define INCLUDED_RENDERER_BACKEND_GL_TEXTURE #include "lib/ogl.h" -#include "renderer/backend/Format.h" +#include "renderer/backend/ITexture.h" #include "renderer/backend/Sampler.h" #include @@ -39,26 +39,22 @@ class CDevice; /** * Represents a low-level GL texture, encapsulates all properties initialization. */ -class CTexture +class CTexture final : public ITexture { public: - enum class Type - { - TEXTURE_2D, - TEXTURE_2D_MULTISAMPLE, - TEXTURE_CUBE - }; + ~CTexture() override; - ~CTexture(); + IDevice* GetDevice() override; + + Type GetType() const override { return m_Type; } + Format GetFormat() const override { return m_Format; } + + uint32_t GetWidth() const override { return m_Width; } + uint32_t GetHeight() const override { return m_Height; } + uint32_t GetMIPLevelCount() const override { return m_MIPLevelCount; } GLuint GetHandle() const { return m_Handle; } - Type GetType() const { return m_Type; } - Format GetFormat() const { return m_Format; } - uint32_t GetWidth() const { return m_Width; } - uint32_t GetHeight() const { return m_Height; } - uint32_t GetMIPLevelCount() const { return m_MIPLevelCount; } - private: friend class CDevice; diff --git a/source/renderer/backend/vulkan/Device.cpp b/source/renderer/backend/vulkan/Device.cpp index f0491ae4cd..e52f9d75d1 100644 --- a/source/renderer/backend/vulkan/Device.cpp +++ b/source/renderer/backend/vulkan/Device.cpp @@ -19,6 +19,7 @@ #include "Device.h" +#include "lib/external_libraries/libsdl.h" #include "scriptinterface/JSON.h" #include "scriptinterface/Object.h" #include "scriptinterface/ScriptInterface.h" @@ -38,7 +39,7 @@ namespace Vulkan { // static -std::unique_ptr CDevice::Create(SDL_Window* window) +std::unique_ptr CDevice::Create(SDL_Window* UNUSED(window)) { std::unique_ptr device(new CDevice()); return device; @@ -50,6 +51,8 @@ CDevice::~CDevice() = default; void CDevice::Report(const ScriptRequest& rq, JS::HandleValue settings) { + Script::SetProperty(rq, settings, "name", "vulkan"); + std::string vulkanSupport = "unsupported"; // According to http://wiki.libsdl.org/SDL_Vulkan_LoadLibrary the following // functionality is supported since SDL 2.0.8. @@ -68,7 +71,95 @@ void CDevice::Report(const ScriptRequest& rq, JS::HandleValue settings) vulkanSupport = "cantload"; } #endif - Script::SetProperty(rq, settings, "vulkan", vulkanSupport); + Script::SetProperty(rq, settings, "status", vulkanSupport); +} + +IFramebuffer* CDevice::GetCurrentBackbuffer() +{ + return nullptr; +} + +std::unique_ptr CDevice::CreateCommandContext() +{ + return nullptr; +} + +std::unique_ptr CDevice::CreateTexture(const char* name, const ITexture::Type type, + const Format format, const uint32_t width, const uint32_t height, + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) +{ + UNUSED2(name); + UNUSED2(type); + UNUSED2(format); + UNUSED2(width); + UNUSED2(height); + UNUSED2(defaultSamplerDesc); + UNUSED2(MIPLevelCount); + UNUSED2(sampleCount); + return nullptr; +} + +std::unique_ptr CDevice::CreateTexture2D(const char* name, + const Format format, const uint32_t width, const uint32_t height, + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) +{ + UNUSED2(name); + UNUSED2(format); + UNUSED2(width); + UNUSED2(height); + UNUSED2(defaultSamplerDesc); + UNUSED2(MIPLevelCount); + UNUSED2(sampleCount); + return nullptr; +} + +std::unique_ptr CDevice::CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment) +{ + UNUSED2(name); + UNUSED2(colorAttachment); + UNUSED2(depthStencilAttachment); + return nullptr; +} + +std::unique_ptr CDevice::CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment, const CColor& clearColor) +{ + UNUSED2(name); + UNUSED2(colorAttachment); + UNUSED2(depthStencilAttachment); + UNUSED2(clearColor); + return nullptr; +} + +std::unique_ptr CDevice::CreateBuffer( + const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) +{ + UNUSED2(name); + UNUSED2(type); + UNUSED2(size); + UNUSED2(dynamic); + return nullptr; +} + +std::unique_ptr CDevice::CreateShaderProgram( + const CStr& name, const CShaderDefines& defines) +{ + UNUSED2(name); + UNUSED2(defines); + return nullptr; +} + +void CDevice::Present() +{ +} + +bool CDevice::IsTextureFormatSupported(const Format format) const +{ + UNUSED2(format); + return false; } } // namespace Vulkan diff --git a/source/renderer/backend/vulkan/Device.h b/source/renderer/backend/vulkan/Device.h index b06498f572..d89d3af778 100644 --- a/source/renderer/backend/vulkan/Device.h +++ b/source/renderer/backend/vulkan/Device.h @@ -18,6 +18,7 @@ #ifndef INCLUDED_RENDERER_BACKEND_VULKAN_DEVICE #define INCLUDED_RENDERER_BACKEND_VULKAN_DEVICE +#include "renderer/backend/IDevice.h" #include "scriptinterface/ScriptForward.h" #include @@ -33,22 +34,64 @@ namespace Backend namespace Vulkan { -class CDevice +class CDevice : public IDevice { public: - ~CDevice(); - /** * Creates the Vulkan device. */ static std::unique_ptr Create(SDL_Window* window); - void Report(const ScriptRequest& rq, JS::HandleValue settings); + ~CDevice() override; + + const std::string& GetName() const override { return m_Name; } + const std::string& GetVersion() const override { return m_Version; } + const std::string& GetDriverInformation() const override { return m_DriverInformation; } + const std::vector& GetExtensions() const override { return m_Extensions; } + + void Report(const ScriptRequest& rq, JS::HandleValue settings) override; + + IFramebuffer* GetCurrentBackbuffer() override; + + std::unique_ptr CreateCommandContext() override; + + std::unique_ptr CreateTexture(const char* name, const ITexture::Type type, + const Format format, const uint32_t width, const uint32_t height, + const Sampler::Desc& defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override; + + std::unique_ptr CreateTexture2D(const char* name, + 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; + + std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment) override; + + std::unique_ptr CreateFramebuffer( + const char* name, ITexture* colorAttachment, + ITexture* depthStencilAttachment, const CColor& clearColor) override; + + std::unique_ptr CreateBuffer( + const char* name, const IBuffer::Type type, const uint32_t size, const bool dynamic) override; + + std::unique_ptr CreateShaderProgram( + const CStr& name, const CShaderDefines& defines) override; + + void Present() override; + + bool IsTextureFormatSupported(const Format format) const override; + + const Capabilities& GetCapabilities() const override { return m_Capabilities; } private: CDevice(); - SDL_Window* m_Window = nullptr; + std::string m_Name; + std::string m_Version; + std::string m_DriverInformation; + std::vector m_Extensions; + + Capabilities m_Capabilities{}; }; } // namespace Vulkan diff --git a/source/tools/atlas/GameInterface/Brushes.cpp b/source/tools/atlas/GameInterface/Brushes.cpp index 97b47ccc11..b93bcc3795 100644 --- a/source/tools/atlas/GameInterface/Brushes.cpp +++ b/source/tools/atlas/GameInterface/Brushes.cpp @@ -54,7 +54,7 @@ public: } void ProcessTile( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, ssize_t i, ssize_t j) { ssize_t i0, j0; diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index dadeefc0d9..06c8262c6d 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -36,7 +36,7 @@ #include "ps/GameSetup/GameSetup.h" #include "ps/VideoMode.h" #include "ps/World.h" -#include "renderer/backend/gl/Device.h" +#include "renderer/backend/IDevice.h" #include "renderer/DebugRenderer.h" #include "renderer/Renderer.h" #include "renderer/SceneRenderer.h"