LCOV - code coverage report
Current view: top level - source/renderer/backend/gl - SwapChain.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 1 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_RENDERER_BACKEND_GL_SWAPCHAIN
      19             : #define INCLUDED_RENDERER_BACKEND_GL_SWAPCHAIN
      20             : 
      21             : #include "lib/config2.h"
      22             : #include "renderer/backend/gl/Framebuffer.h"
      23             : #include "renderer/backend/ISwapChain.h"
      24             : 
      25             : #if CONFIG2_GLES
      26             : #include "external_libraries/opengles2_wrapper.h"
      27             : #else
      28             : #include <glad/gl.h>
      29             : #endif
      30             : 
      31             : #include <cstdint>
      32             : #include <memory>
      33             : #include <unordered_map>
      34             : 
      35             : typedef struct SDL_Window SDL_Window;
      36             : 
      37             : namespace Renderer
      38             : {
      39             : 
      40             : namespace Backend
      41             : {
      42             : 
      43             : namespace GL
      44             : {
      45             : 
      46             : class CDevice;
      47             : 
      48             : class CSwapChain final : public ISwapChain
      49             : {
      50             : public:
      51             :     ~CSwapChain() override;
      52             : 
      53             :     IDevice* GetDevice() override;
      54             : 
      55           0 :     bool IsValid() const override { return true; }
      56             : 
      57             :     bool AcquireNextBackbuffer() override;
      58             : 
      59             :     IFramebuffer* GetCurrentBackbuffer(
      60             :         const AttachmentLoadOp colorAttachmentLoadOp,
      61             :         const AttachmentStoreOp colorAttachmentStoreOp,
      62             :         const AttachmentLoadOp depthStencilAttachmentLoadOp,
      63             :         const AttachmentStoreOp depthStencilAttachmentStoreOp) override;
      64             : 
      65             :     void Present() override;
      66             : 
      67             : private:
      68             :     friend class CDevice;
      69             : 
      70             :     static std::unique_ptr<CSwapChain> Create(
      71             :         CDevice* device, SDL_Window* window,
      72             :         int surfaceDrawableWidth, int surfaceDrawableHeight,
      73             :         const bool vsync);
      74             : 
      75             :     CSwapChain();
      76             : 
      77             :     CDevice* m_Device{nullptr};
      78             :     SDL_Window* m_Window{nullptr};
      79             :     int m_SurfaceDrawableWidth{0};
      80             :     int m_SurfaceDrawableHeight{0};
      81             : 
      82             :     using BackbufferKey = std::tuple<
      83             :         AttachmentLoadOp, AttachmentStoreOp,
      84             :         AttachmentLoadOp, AttachmentStoreOp>;
      85             :     struct BackbufferKeyHash
      86             :     {
      87             :         size_t operator()(const BackbufferKey& key) const;
      88             :     };
      89             :     // We use std::unordered_map to avoid storing sizes of Attachment*Op
      90             :     // enumerations. If it becomes a performance issue we'll replace it
      91             :     // by an array.
      92             :     std::unordered_map<
      93             :         BackbufferKey, std::unique_ptr<CFramebuffer>, BackbufferKeyHash> m_Backbuffers;
      94             :     bool m_BackbufferAcquired{false};
      95             : };
      96             : 
      97             : } // namespace GL
      98             : 
      99             : } // namespace Backend
     100             : 
     101             : } // namespace Renderer
     102             : 
     103             : #endif // INCLUDED_RENDERER_BACKEND_GL_SWAPCHAIN

Generated by: LCOV version 1.16