Index: ps/trunk/binaries/data/config/default.cfg =================================================================== --- ps/trunk/binaries/data/config/default.cfg +++ ps/trunk/binaries/data/config/default.cfg @@ -116,6 +116,7 @@ ; 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. Index: ps/trunk/binaries/data/mods/mod/hwdetect/hwdetect.js =================================================================== --- ps/trunk/binaries/data/mods/mod/hwdetect/hwdetect.js +++ ps/trunk/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 @@ 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 @@ 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); Index: ps/trunk/binaries/data/mods/mod/hwdetect/test.js =================================================================== --- ps/trunk/binaries/data/mods/mod/hwdetect/test.js +++ ps/trunk/binaries/data/mods/mod/hwdetect/test.js @@ -15,9 +15,9 @@ 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 @@ 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")); } Index: ps/trunk/build/premake/premake5.lua =================================================================== --- ps/trunk/build/premake/premake5.lua +++ ps/trunk/build/premake/premake5.lua @@ -786,7 +786,9 @@ "graphics/scripting", "renderer", "renderer/backend", + "renderer/backend/dummy", "renderer/backend/gl", + "renderer/backend/vulkan", "renderer/scripting", "third_party/mikktspace", "third_party/ogre3d_preprocessor" Index: ps/trunk/source/graphics/Canvas2D.h =================================================================== --- ps/trunk/source/graphics/Canvas2D.h +++ ps/trunk/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 @@ class CCanvas2D { public: - CCanvas2D(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + CCanvas2D(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); ~CCanvas2D(); CCanvas2D(const CCanvas2D&) = delete; Index: ps/trunk/source/graphics/Canvas2D.cpp =================================================================== --- ps/trunk/source/graphics/Canvas2D.cpp +++ ps/trunk/source/graphics/Canvas2D.cpp @@ -47,7 +47,7 @@ }; 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 @@ class CCanvas2D::Impl { public: - Impl(Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Impl(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) : DeviceCommandContext(deviceCommandContext) { } @@ -124,7 +124,7 @@ 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 @@ }; CCanvas2D::CCanvas2D( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) : m(std::make_unique(deviceCommandContext)) { Index: ps/trunk/source/graphics/LOSTexture.h =================================================================== --- ps/trunk/source/graphics/LOSTexture.h +++ ps/trunk/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 @@ * 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 @@ 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 @@ bool m_ShaderInitialized = false; - std::unique_ptr + std::unique_ptr m_Texture, m_SmoothTextures[2]; uint32_t m_WhichTexture = 0; @@ -95,7 +95,7 @@ // 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; Index: ps/trunk/source/graphics/LOSTexture.cpp =================================================================== --- ps/trunk/source/graphics/LOSTexture.cpp +++ ps/trunk/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 @@ 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 @@ 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 @@ } -Renderer::Backend::GL::CTexture* CLOSTexture::GetTexture() +Renderer::Backend::ITexture* CLOSTexture::GetTexture() { ENSURE(!m_Dirty); return m_Texture.get(); @@ -227,7 +227,7 @@ 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 @@ 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::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) Index: ps/trunk/source/graphics/MiniMapTexture.h =================================================================== --- ps/trunk/source/graphics/MiniMapTexture.h +++ ps/trunk/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 @@ /** * 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 @@ 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 @@ 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 Index: ps/trunk/source/graphics/MiniMapTexture.cpp =================================================================== --- ps/trunk/source/graphics/MiniMapTexture.cpp +++ ps/trunk/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 @@ } void DrawTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { const float quadUVs[] = { @@ -146,7 +146,7 @@ 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::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::CreateTextures( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) { DestroyTextures(); @@ -238,7 +238,7 @@ 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::RebuildTerrainTexture( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CTerrain* terrain) { const u32 x = 0; @@ -338,7 +338,7 @@ } 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 @@ 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); Index: ps/trunk/source/graphics/ParticleEmitter.h =================================================================== --- ps/trunk/source/graphics/ParticleEmitter.h +++ ps/trunk/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 @@ * 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 Index: ps/trunk/source/graphics/ParticleEmitter.cpp =================================================================== --- ps/trunk/source/graphics/ParticleEmitter.cpp +++ ps/trunk/source/graphics/ParticleEmitter.cpp @@ -33,7 +33,7 @@ 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::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::RenderArray( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m_Particles.empty()) return; Index: ps/trunk/source/graphics/ShaderDefines.h =================================================================== --- ps/trunk/source/graphics/ShaderDefines.h +++ ps/trunk/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 @@ * 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; }; Index: ps/trunk/source/graphics/ShaderDefines.cpp =================================================================== --- ps/trunk/source/graphics/ShaderDefines.cpp +++ ps/trunk/source/graphics/ShaderDefines.cpp @@ -226,7 +226,7 @@ } 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) Index: ps/trunk/source/graphics/ShaderManager.cpp =================================================================== --- ps/trunk/source/graphics/ShaderManager.cpp +++ ps/trunk/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 @@ 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) Index: ps/trunk/source/graphics/ShaderProgram.cpp =================================================================== --- ps/trunk/source/graphics/ShaderProgram.cpp +++ ps/trunk/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) Index: ps/trunk/source/graphics/TerrainTextureManager.h =================================================================== --- ps/trunk/source/graphics/TerrainTextureManager.h +++ ps/trunk/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 @@ 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 @@ 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 Index: ps/trunk/source/graphics/TerrainTextureManager.cpp =================================================================== --- ps/trunk/source/graphics/TerrainTextureManager.cpp +++ ps/trunk/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 @@ } void CTerrainTextureManager::UploadResourcesIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { for (const CTerrainTextureManager::TerrainAlphaMap::iterator& it : m_AlphaMapsToUpload) { @@ -314,7 +314,7 @@ 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()); Index: ps/trunk/source/graphics/TerritoryTexture.h =================================================================== --- ps/trunk/source/graphics/TerritoryTexture.h +++ ps/trunk/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 @@ * 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 @@ * 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 @@ 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 @@ size_t m_DirtyID; - std::unique_ptr m_Texture; + std::unique_ptr m_Texture; ssize_t m_MapSize; // tiles per side Index: ps/trunk/source/graphics/TerritoryTexture.cpp =================================================================== --- ps/trunk/source/graphics/TerritoryTexture.cpp +++ ps/trunk/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 @@ 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 @@ 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::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 @@ 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); Index: ps/trunk/source/graphics/TextRenderer.h =================================================================== --- ps/trunk/source/graphics/TextRenderer.h +++ ps/trunk/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 @@ * 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: Index: ps/trunk/source/graphics/TextRenderer.cpp =================================================================== --- ps/trunk/source/graphics/TextRenderer.cpp +++ ps/trunk/source/graphics/TextRenderer.cpp @@ -202,7 +202,7 @@ }; void CTextRenderer::Render( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, const CMatrix3D& transform) { std::vector indexes; Index: ps/trunk/source/graphics/TextureManager.h =================================================================== --- ps/trunk/source/graphics/TextureManager.h +++ ps/trunk/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 @@ * 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 @@ * 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 @@ * 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 @@ * 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 @@ * 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 @@ // 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; Index: ps/trunk/source/graphics/TextureManager.cpp =================================================================== --- ps/trunk/source/graphics/TextureManager.cpp +++ ps/trunk/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 @@ } 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ { // 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 @@ } 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 @@ */ 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 @@ } } - 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 @@ } bool MakeUploadProgress( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!m_PredefinedTexturesUploaded) { @@ -886,7 +868,7 @@ 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 @@ }; 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() = default; void CTexture::UploadBackendTextureIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (IsUploaded()) return; @@ -960,12 +942,12 @@ 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::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 @@ // 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::WrapBackendTexture( - std::unique_ptr backendTexture) + std::unique_ptr backendTexture) { return m->WrapBackendTexture(std::move(backendTexture)); } @@ -1097,7 +1079,7 @@ } bool CTextureManager::MakeUploadProgress( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { return m->MakeUploadProgress(deviceCommandContext); } Index: ps/trunk/source/graphics/tests/test_TextureManager.h =================================================================== --- ps/trunk/source/graphics/tests/test_TextureManager.h +++ ps/trunk/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 @@ 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 @@ 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 @@ // 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 @@ 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")); Index: ps/trunk/source/gui/CGUIText.cpp =================================================================== --- ps/trunk/source/gui/CGUIText.cpp +++ ps/trunk/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 @@ 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 @@ 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); Index: ps/trunk/source/gui/ObjectTypes/CInput.cpp =================================================================== --- ps/trunk/source/gui/ObjectTypes/CInput.cpp +++ ps/trunk/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::Draw(CCanvas2D& canvas) { - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext = + Renderer::Backend::IDeviceCommandContext* deviceCommandContext = g_Renderer.GetDeviceCommandContext(); if (m_CursorBlinkRate > 0.0) @@ -1244,7 +1244,7 @@ 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; Index: ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp =================================================================== --- ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp +++ ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp @@ -95,7 +95,7 @@ } 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 @@ 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(); Index: ps/trunk/source/main.cpp =================================================================== --- ps/trunk/source/main.cpp +++ ps/trunk/source/main.cpp @@ -74,7 +74,7 @@ #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" Index: ps/trunk/source/ps/ArchiveBuilder.cpp =================================================================== --- ps/trunk/source/ps/ArchiveBuilder.cpp +++ ps/trunk/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 @@ // 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); Index: ps/trunk/source/ps/GameSetup/HWDetect.cpp =================================================================== --- ps/trunk/source/ps/GameSetup/HWDetect.cpp +++ ps/trunk/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 @@ 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 @@ 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( Index: ps/trunk/source/ps/Profiler2GPU.cpp =================================================================== --- ps/trunk/source/ps/Profiler2GPU.cpp +++ ps/trunk/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 @@ public: static bool IsSupported() { + if (g_VideoMode.GetBackend() != CVideoMode::Backend::GL) + return false; return ogl_HaveExtension("GL_ARB_timer_query"); } Index: ps/trunk/source/ps/Util.cpp =================================================================== --- ps/trunk/source/ps/Util.cpp +++ ps/trunk/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" Index: ps/trunk/source/ps/VideoMode.h =================================================================== --- ps/trunk/source/ps/VideoMode.h +++ ps/trunk/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 Backend { -namespace GL -{ -class CDevice; -} +class IDevice; } } @@ -41,7 +38,8 @@ enum class Backend { GL, - GL_ARB + GL_ARB, + DUMMY }; CVideoMode(); @@ -128,7 +126,7 @@ 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 @@ std::unique_ptr m_Cursor; Backend m_Backend = Backend::GL; - std::unique_ptr m_BackendDevice; + std::unique_ptr m_BackendDevice; }; extern CVideoMode g_VideoMode; Index: ps/trunk/source/ps/VideoMode.cpp =================================================================== --- ps/trunk/source/ps/VideoMode.cpp +++ ps/trunk/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 @@ 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 @@ 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) { Index: ps/trunk/source/renderer/DebugRenderer.cpp =================================================================== --- ps/trunk/source/renderer/DebugRenderer.cpp +++ ps/trunk/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 @@ { 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 @@ { 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 @@ { 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 @@ 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 @@ 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::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); Index: ps/trunk/source/renderer/DecalRData.h =================================================================== --- ps/trunk/source/renderer/DecalRData.h +++ ps/trunk/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 @@ 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; } Index: ps/trunk/source/renderer/DecalRData.cpp =================================================================== --- ps/trunk/source/renderer/DecalRData.cpp +++ ps/trunk/source/renderer/DecalRData.cpp @@ -95,7 +95,7 @@ } 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 @@ { 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 @@ { 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()); } Index: ps/trunk/source/renderer/HWLightingModelRenderer.h =================================================================== --- ps/trunk/source/renderer/HWLightingModelRenderer.h +++ ps/trunk/source/renderer/HWLightingModelRenderer.h @@ -41,12 +41,12 @@ 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: Index: ps/trunk/source/renderer/HWLightingModelRenderer.cpp =================================================================== --- ps/trunk/source/renderer/HWLightingModelRenderer.cpp +++ ps/trunk/source/renderer/HWLightingModelRenderer.cpp @@ -49,7 +49,7 @@ 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 @@ 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 @@ // 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 @@ // 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(); Index: ps/trunk/source/renderer/InstancingModelRenderer.h =================================================================== --- ps/trunk/source/renderer/InstancingModelRenderer.h +++ ps/trunk/source/renderer/InstancingModelRenderer.h @@ -44,11 +44,11 @@ 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: Index: ps/trunk/source/renderer/InstancingModelRenderer.cpp =================================================================== --- ps/trunk/source/renderer/InstancingModelRenderer.cpp +++ ps/trunk/source/renderer/InstancingModelRenderer.cpp @@ -55,7 +55,7 @@ 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 @@ // 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 @@ // 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(); Index: ps/trunk/source/renderer/ModelRenderer.h =================================================================== --- ps/trunk/source/renderer/ModelRenderer.h +++ ps/trunk/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 @@ * 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 @@ 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: Index: ps/trunk/source/renderer/ModelRenderer.cpp =================================================================== --- ps/trunk/source/renderer/ModelRenderer.cpp +++ ps/trunk/source/renderer/ModelRenderer.cpp @@ -345,7 +345,7 @@ }; 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()) Index: ps/trunk/source/renderer/ModelVertexRenderer.h =================================================================== --- ps/trunk/source/renderer/ModelVertexRenderer.h +++ ps/trunk/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 @@ * 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 @@ * @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 @@ * succeed. */ virtual void RenderModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader, CModel* model, CModelRData* data) = 0; }; Index: ps/trunk/source/renderer/OverlayRenderer.h =================================================================== --- ps/trunk/source/renderer/OverlayRenderer.h +++ ps/trunk/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 @@ * 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 @@ * 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 @@ * @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 @@ * 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 @@ * 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; Index: ps/trunk/source/renderer/OverlayRenderer.cpp =================================================================== --- ps/trunk/source/renderer/OverlayRenderer.cpp +++ ps/trunk/source/renderer/OverlayRenderer.cpp @@ -154,7 +154,7 @@ 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::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::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 @@ 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::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::RenderQuadOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m->quadBatchMap.empty()) return; @@ -589,7 +589,7 @@ } void OverlayRenderer::RenderForegroundOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CCamera& viewCamera) { PROFILE3_GPU("overlays (fg)"); @@ -739,7 +739,7 @@ } void OverlayRenderer::RenderSphereOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { PROFILE3_GPU("overlays (spheres)"); Index: ps/trunk/source/renderer/ParticleRenderer.h =================================================================== --- ps/trunk/source/renderer/ParticleRenderer.h +++ ps/trunk/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 @@ * Render all the submitted particles. */ void RenderParticles( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup, bool wireframe = false); /** Index: ps/trunk/source/renderer/ParticleRenderer.cpp =================================================================== --- ps/trunk/source/renderer/ParticleRenderer.cpp +++ ps/trunk/source/renderer/ParticleRenderer.cpp @@ -127,7 +127,7 @@ } void ParticleRenderer::RenderParticles( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup, bool wireframe) { CShaderTechnique* lastTech = nullptr; Index: ps/trunk/source/renderer/PatchRData.h =================================================================== --- ps/trunk/source/renderer/PatchRData.h +++ ps/trunk/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 @@ 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); Index: ps/trunk/source/renderer/PatchRData.cpp =================================================================== --- ps/trunk/source/renderer/PatchRData.cpp +++ ps/trunk/source/renderer/PatchRData.cpp @@ -283,7 +283,7 @@ 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 @@ 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 @@ // 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 @@ { 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 @@ { 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 ShaderTechniqueBatches = 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 @@ }; 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 @@ 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 @@ 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::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::RenderSides( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const std::vector& patches) { PROFILE3("render terrain sides"); @@ -1446,13 +1446,13 @@ { 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 @@ { 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::RenderWaterShore( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ASSERT(m_UpdateFlags == 0); Index: ps/trunk/source/renderer/PostprocManager.h =================================================================== --- ps/trunk/source/renderer/PostprocManager.h +++ ps/trunk/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 @@ // 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 @@ { 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 @@ 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 @@ // 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 @@ // 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. Index: ps/trunk/source/renderer/PostprocManager.cpp =================================================================== --- ps/trunk/source/renderer/PostprocManager.cpp +++ ps/trunk/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 @@ { 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::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::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::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::CaptureRenderOutput( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ENSURE(m_IsInitialized); @@ -386,7 +386,7 @@ void CPostprocManager::ReleaseRenderOutput( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ENSURE(m_IsInitialized); @@ -402,7 +402,7 @@ } 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::ApplyPostproc( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { ENSURE(m_IsInitialized); @@ -635,10 +635,10 @@ 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 @@ // 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 @@ } void CPostprocManager::ResolveMultisampleFramebuffer( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (!m_UsingMultisampleBuffer) return; Index: ps/trunk/source/renderer/RenderModifiers.h =================================================================== --- ps/trunk/source/renderer/RenderModifiers.h +++ ps/trunk/source/renderer/RenderModifiers.h @@ -57,7 +57,7 @@ * 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 @@ * @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 @@ // 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: Index: ps/trunk/source/renderer/RenderModifiers.cpp =================================================================== --- ps/trunk/source/renderer/RenderModifiers.cpp +++ ps/trunk/source/renderer/RenderModifiers.cpp @@ -68,7 +68,7 @@ } 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::PrepareModel( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, CModel* model) { if (m_BindingInstancingTransform >= 0) Index: ps/trunk/source/renderer/Renderer.h =================================================================== --- ps/trunk/source/renderer/Renderer.h +++ ps/trunk/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 @@ */ void MakeScreenShotOnNextFrame(ScreenShotType screenShotType); - Renderer::Backend::GL::CDeviceCommandContext* GetDeviceCommandContext(); + Renderer::Backend::IDeviceCommandContext* GetDeviceCommandContext(); protected: friend class CPatchRData; Index: ps/trunk/source/renderer/Renderer.cpp =================================================================== --- ps/trunk/source/renderer/Renderer.cpp +++ ps/trunk/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 @@ { NONCOPYABLE(Internals); public: - std::unique_ptr deviceCommandContext; + std::unique_ptr deviceCommandContext; /// true if CRenderer::Open has been called bool IsOpen; @@ -274,7 +274,7 @@ 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::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 @@ m_ScreenShotType = screenShotType; } -Renderer::Backend::GL::CDeviceCommandContext* CRenderer::GetDeviceCommandContext() +Renderer::Backend::IDeviceCommandContext* CRenderer::GetDeviceCommandContext() { return m->deviceCommandContext.get(); } Index: ps/trunk/source/renderer/SceneRenderer.h =================================================================== --- ps/trunk/source/renderer/SceneRenderer.h +++ ps/trunk/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 @@ * 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 @@ // 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; Index: ps/trunk/source/renderer/SceneRenderer.cpp =================================================================== --- ps/trunk/source/renderer/SceneRenderer.cpp +++ ps/trunk/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 @@ * 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 @@ * 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::RenderShadowMap( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context) { PROFILE3_GPU("shadow map"); @@ -336,7 +336,7 @@ } 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::RenderModels( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context, int cullGroup) { PROFILE3_GPU("models"); @@ -389,7 +389,7 @@ } 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 @@ // 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 @@ 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 @@ // 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 @@ 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::RenderSilhouettes( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CShaderDefines& context) { PROFILE3_GPU("silhouettes"); @@ -726,7 +726,7 @@ } void CSceneRenderer::RenderParticles( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { PROFILE3_GPU("particles"); @@ -745,7 +745,7 @@ // 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 @@ // Render the given scene void CSceneRenderer::RenderScene( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, Scene& scene) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene) { m_CurrentScene = &scene; Index: ps/trunk/source/renderer/ShadowMap.h =================================================================== --- ps/trunk/source/renderer/ShadowMap.h +++ ps/trunk/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 @@ * 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; /** Index: ps/trunk/source/renderer/ShadowMap.cpp =================================================================== --- ps/trunk/source/renderer/ShadowMap.cpp +++ ps/trunk/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 @@ */ 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 @@ // 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 @@ 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 @@ // 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 @@ 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::BindTo( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IShaderProgram* shader) const { const int32_t shadowTexBindingSlot = shader->GetBindingSlot(str_shadowTex); Index: ps/trunk/source/renderer/SilhouetteRenderer.h =================================================================== --- ps/trunk/source/renderer/SilhouetteRenderer.h +++ ps/trunk/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 @@ 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(); Index: ps/trunk/source/renderer/SilhouetteRenderer.cpp =================================================================== --- ps/trunk/source/renderer/SilhouetteRenderer.cpp +++ ps/trunk/source/renderer/SilhouetteRenderer.cpp @@ -444,7 +444,7 @@ } 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::RenderDebugOverlays( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m_DebugRects.empty()) return; Index: ps/trunk/source/renderer/SkyManager.h =================================================================== --- ps/trunk/source/renderer/SkyManager.h +++ ps/trunk/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 @@ * 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 @@ return m_SkySet; } - Renderer::Backend::GL::CTexture* GetSkyCube(); + Renderer::Backend::ITexture* GetSkyCube(); /** * Set the sky set name. @@ -79,7 +79,7 @@ * Load all sky textures from files and upload to GPU. */ void LoadAndUploadSkyTexturesIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext); + Renderer::Backend::IDeviceCommandContext* deviceCommandContext); private: void CreateSkyCube(); Index: ps/trunk/source/renderer/SkyManager.cpp =================================================================== --- ps/trunk/source/renderer/SkyManager.cpp +++ ps/trunk/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 @@ } } - 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 @@ /////////////////////////////////////////////////////////////////////////// } -Renderer::Backend::GL::CTexture* SkyManager::GetSkyCube() +Renderer::Backend::ITexture* SkyManager::GetSkyCube() { return m_SkyTextureCube->GetBackendTexture(); } @@ -203,7 +203,7 @@ } void SkyManager::RenderSky( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { GPU_SCOPED_LABEL(deviceCommandContext, "Render sky"); Index: ps/trunk/source/renderer/TerrainOverlay.h =================================================================== --- ps/trunk/source/renderer/TerrainOverlay.h +++ ps/trunk/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 @@ 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 @@ * @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 @@ * 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 @@ * 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 @@ 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 Index: ps/trunk/source/renderer/TerrainOverlay.cpp =================================================================== --- ps/trunk/source/renderer/TerrainOverlay.cpp +++ ps/trunk/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 @@ void ITerrainOverlay::RenderOverlaysBeforeWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (g_TerrainOverlayList.empty()) return; @@ -77,7 +78,7 @@ } 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::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::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::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() = default; void TerrainTextureOverlay::RenderAfterWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, int cullGroup) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); Index: ps/trunk/source/renderer/TerrainRenderer.h =================================================================== --- ps/trunk/source/renderer/TerrainRenderer.h +++ ps/trunk/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 @@ * @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 @@ * @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 @@ * @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 @@ * 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 @@ * 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 @@ * 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); }; Index: ps/trunk/source/renderer/TerrainRenderer.cpp =================================================================== --- ps/trunk/source/renderer/TerrainRenderer.cpp +++ ps/trunk/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::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 @@ * 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::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 @@ /////////////////////////////////////////////////////////////////// // 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 @@ /////////////////////////////////////////////////////////////////// // 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 @@ // 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 @@ } void TerrainRenderer::RenderSimpleWater( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { PROFILE3_GPU("simple water"); @@ -654,7 +654,7 @@ /////////////////////////////////////////////////////////////////// // 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::RenderWaterFoamOccluders( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, int cullGroup) { CSceneRenderer& sceneRenderer = g_Renderer.GetSceneRenderer(); Index: ps/trunk/source/renderer/TexturedLineRData.h =================================================================== --- ps/trunk/source/renderer/TexturedLineRData.h +++ ps/trunk/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 @@ ~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; Index: ps/trunk/source/renderer/TexturedLineRData.cpp =================================================================== --- ps/trunk/source/renderer/TexturedLineRData.cpp +++ ps/trunk/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 @@ 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 @@ 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]); } Index: ps/trunk/source/renderer/VertexArray.h =================================================================== --- ps/trunk/source/renderer/VertexArray.h +++ ps/trunk/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: 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 @@ // 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 @@ 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; Index: ps/trunk/source/renderer/VertexArray.cpp =================================================================== --- ps/trunk/source/renderer/VertexArray.cpp +++ ps/trunk/source/renderer/VertexArray.cpp @@ -65,7 +65,7 @@ } // 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 @@ 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::UploadIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { m_VB->m_Owner->UploadIfNeeded(deviceCommandContext); } @@ -299,7 +299,7 @@ } 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); Index: ps/trunk/source/renderer/VertexBuffer.h =================================================================== --- ps/trunk/source/renderer/VertexBuffer.h +++ ps/trunk/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 @@ // 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 @@ /// 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 @@ */ 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 @@ /// 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 @@ /// 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; }; Index: ps/trunk/source/renderer/VertexBuffer.cpp =================================================================== --- ps/trunk/source/renderer/VertexBuffer.cpp +++ ps/trunk/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 @@ 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 @@ } 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 @@ // 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::UploadIfNeeded( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext) + Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (UseStreaming(m_Buffer->IsDynamic())) { Index: ps/trunk/source/renderer/VertexBufferManager.h =================================================================== --- ps/trunk/source/renderer/VertexBufferManager.h +++ ps/trunk/source/renderer/VertexBufferManager.h @@ -90,7 +90,7 @@ */ 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 Index: ps/trunk/source/renderer/VertexBufferManager.cpp =================================================================== --- ps/trunk/source/renderer/VertexBufferManager.cpp +++ ps/trunk/source/renderer/VertexBufferManager.cpp @@ -27,15 +27,15 @@ { 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 @@ */ 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); Index: ps/trunk/source/renderer/WaterManager.h =================================================================== --- ps/trunk/source/renderer/WaterManager.h +++ ps/trunk/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 @@ 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 @@ 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 @@ bool WillRenderFancyWater() const; void RenderWaves( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CFrustum& frustrum); /** Index: ps/trunk/source/renderer/WaterManager.cpp =================================================================== --- ps/trunk/source/renderer/WaterManager.cpp +++ ps/trunk/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 @@ 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 @@ // 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 @@ 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::RenderWaves( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const CFrustum& frustrum) { GPU_SCOPED_LABEL(deviceCommandContext, "Render Waves"); Index: ps/trunk/source/renderer/backend/IBuffer.h =================================================================== --- ps/trunk/source/renderer/backend/IBuffer.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/IDevice.h =================================================================== --- ps/trunk/source/renderer/backend/IDevice.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/IDeviceCommandContext.h =================================================================== --- ps/trunk/source/renderer/backend/IDeviceCommandContext.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/IDeviceObject.h =================================================================== --- ps/trunk/source/renderer/backend/IDeviceObject.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/IFramebuffer.h =================================================================== --- ps/trunk/source/renderer/backend/IFramebuffer.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/IShaderProgram.h =================================================================== --- ps/trunk/source/renderer/backend/IShaderProgram.h +++ ps/trunk/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 @@ /** * 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; Index: ps/trunk/source/renderer/backend/ITexture.h =================================================================== --- ps/trunk/source/renderer/backend/ITexture.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Buffer.h =================================================================== --- ps/trunk/source/renderer/backend/dummy/Buffer.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Buffer.cpp =================================================================== --- ps/trunk/source/renderer/backend/dummy/Buffer.cpp +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Device.h =================================================================== --- ps/trunk/source/renderer/backend/dummy/Device.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Device.cpp =================================================================== --- ps/trunk/source/renderer/backend/dummy/Device.cpp +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/DeviceCommandContext.h =================================================================== --- ps/trunk/source/renderer/backend/dummy/DeviceCommandContext.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/DeviceCommandContext.cpp =================================================================== --- ps/trunk/source/renderer/backend/dummy/DeviceCommandContext.cpp +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Framebuffer.h =================================================================== --- ps/trunk/source/renderer/backend/dummy/Framebuffer.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Framebuffer.cpp =================================================================== --- ps/trunk/source/renderer/backend/dummy/Framebuffer.cpp +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/ShaderProgram.h =================================================================== --- ps/trunk/source/renderer/backend/dummy/ShaderProgram.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/ShaderProgram.cpp =================================================================== --- ps/trunk/source/renderer/backend/dummy/ShaderProgram.cpp +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Texture.h =================================================================== --- ps/trunk/source/renderer/backend/dummy/Texture.h +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/dummy/Texture.cpp =================================================================== --- ps/trunk/source/renderer/backend/dummy/Texture.cpp +++ ps/trunk/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 Index: ps/trunk/source/renderer/backend/gl/Buffer.h =================================================================== --- ps/trunk/source/renderer/backend/gl/Buffer.h +++ ps/trunk/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 @@ class CDevice; -class CBuffer +class CBuffer final : public IBuffer { public: - enum class Type - { - VERTEX, - INDEX - }; - - ~CBuffer(); - - Type GetType() const { return m_Type; } - uint32_t GetSize() const { return m_Size; } - bool IsDynamic() const { return m_Dynamic; } + ~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; } GLuint GetHandle() { return m_Handle; } @@ -64,6 +61,7 @@ Type m_Type = Type::VERTEX; uint32_t m_Size = 0; bool m_Dynamic = false; + GLuint m_Handle = 0; }; Index: ps/trunk/source/renderer/backend/gl/Buffer.cpp =================================================================== --- ps/trunk/source/renderer/backend/gl/Buffer.cpp +++ ps/trunk/source/renderer/backend/gl/Buffer.cpp @@ -69,6 +69,11 @@ glDeleteBuffersARB(1, &m_Handle); } +IDevice* CBuffer::GetDevice() +{ + return m_Device; +} + } // namespace GL } // namespace Backend Index: ps/trunk/source/renderer/backend/gl/Device.h =================================================================== --- ps/trunk/source/renderer/backend/gl/Device.h +++ ps/trunk/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 @@ 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, CTexture* colorAttachment, - CTexture* depthStencilAttachment, const CColor& clearColor); + 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 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 @@ 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; Index: ps/trunk/source/renderer/backend/gl/Device.cpp =================================================================== --- ps/trunk/source/renderer/backend/gl/Device.cpp +++ ps/trunk/source/renderer/backend/gl/Device.cpp @@ -218,7 +218,7 @@ } // 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 @@ ); } + device->m_ARB = arb; + device->m_Name = GetNameImpl(); device->m_Version = GetVersionImpl(); device->m_DriverInformation = GetDriverInformationImpl(); @@ -395,6 +397,8 @@ { 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 @@ #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 @@ 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 @@ 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); } Index: ps/trunk/source/renderer/backend/gl/DeviceCommandContext.h =================================================================== --- ps/trunk/source/renderer/backend/gl/DeviceCommandContext.h +++ ps/trunk/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 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 @@ 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 @@ } // 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 Index: ps/trunk/source/renderer/backend/gl/DeviceCommandContext.cpp =================================================================== --- ps/trunk/source/renderer/backend/gl/DeviceCommandContext.cpp +++ ps/trunk/source/renderer/backend/gl/DeviceCommandContext.cpp @@ -147,7 +147,7 @@ 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() = default; +IDevice* CDeviceCommandContext::GetDevice() +{ + return m_Device; +} + void CDeviceCommandContext::SetGraphicsPipelineState( const GraphicsPipelineStateDesc& pipelineStateDesc) { @@ -188,7 +193,7 @@ } 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::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 @@ 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( - 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 @@ 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::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 @@ 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::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::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 @@ 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 @@ 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( Index: ps/trunk/source/renderer/backend/gl/Framebuffer.h =================================================================== --- ps/trunk/source/renderer/backend/gl/Framebuffer.h +++ ps/trunk/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 @@ { 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; } Index: ps/trunk/source/renderer/backend/gl/Framebuffer.cpp =================================================================== --- ps/trunk/source/renderer/backend/gl/Framebuffer.cpp +++ ps/trunk/source/renderer/backend/gl/Framebuffer.cpp @@ -167,6 +167,11 @@ glDeleteFramebuffersEXT(1, &m_Handle); } +IDevice* CFramebuffer::GetDevice() +{ + return m_Device; +} + } // namespace GL } // namespace Backend Index: ps/trunk/source/renderer/backend/gl/ShaderProgram.cpp =================================================================== --- ps/trunk/source/renderer/backend/gl/ShaderProgram.cpp +++ ps/trunk/source/renderer/backend/gl/ShaderProgram.cpp @@ -379,6 +379,8 @@ 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 @@ glDisableVertexAttribArray(index); } + IDevice* GetDevice() override { return m_Device; } + int32_t GetBindingSlot(const CStrIntern name) const override { auto it = m_BindingSlotsMapping.find(name); Index: ps/trunk/source/renderer/backend/gl/Texture.h =================================================================== --- ps/trunk/source/renderer/backend/gl/Texture.h +++ ps/trunk/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,25 +39,21 @@ /** * 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; - GLuint GetHandle() const { return m_Handle; } + 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; } - 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; } + GLuint GetHandle() const { return m_Handle; } private: friend class CDevice; Index: ps/trunk/source/renderer/backend/gl/Texture.cpp =================================================================== --- ps/trunk/source/renderer/backend/gl/Texture.cpp +++ ps/trunk/source/renderer/backend/gl/Texture.cpp @@ -297,6 +297,11 @@ glDeleteTextures(1, &m_Handle); } +IDevice* CTexture::GetDevice() +{ + return m_Device; +} + } // namespace GL } // namespace Backend Index: ps/trunk/source/renderer/backend/vulkan/Device.h =================================================================== --- ps/trunk/source/renderer/backend/vulkan/Device.h +++ ps/trunk/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 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 Index: ps/trunk/source/renderer/backend/vulkan/Device.cpp =================================================================== --- ps/trunk/source/renderer/backend/vulkan/Device.cpp +++ ps/trunk/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 @@ { // 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 @@ 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 @@ 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 Index: ps/trunk/source/tools/atlas/GameInterface/Brushes.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Brushes.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Brushes.cpp @@ -54,7 +54,7 @@ } void ProcessTile( - Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext, + Renderer::Backend::IDeviceCommandContext* deviceCommandContext, ssize_t i, ssize_t j) { ssize_t i0, j0; Index: ps/trunk/source/tools/atlas/GameInterface/View.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/View.cpp +++ ps/trunk/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"