Cogs.Core
SwapChainGL20.h
1#pragma once
2
3#include "../ISwapChain.h"
4#include "../BaseGL/GLContext.h"
5#include "../BaseGL/GLFuncPointers.h"
6
7#if defined( __linux__ )
8 #if defined(EGL)
9 #include <EGL/egl.h>
10 #endif
11
12 #undef None
13#elif defined( _WIN32 )
14#include <WinSock2.h>
15#endif
16
17namespace Cogs {
18 class GraphicsDeviceGL20;
19
20 class SwapChainGL20 : public ISwapChain {
21 public:
22 SwapChainGL20(GraphicsDeviceGL20* device, bool isPrimary);
24
25 bool initialize(WindowData* windowData, bool debugLogging);
26 void destroy();
27
28 virtual void beginFrame() override;
29 virtual void endFrame(uint32_t syncInterval = 0, uint32_t presentFlags = PresentFlags::None) override;
30
31 void ReleaseFence();
32 void ReleaseWait();
33
34 virtual void setSize(int newWidth, int newHeight, bool forceIt = false) override;
35 virtual void setFullscreen(bool enabled) override;
36
37 virtual bool isFullscreen() override { return fullscreen; }
38
39 virtual int getWidth() const override { return width; }
40 virtual int getHeight() const override { return height; }
41 virtual int getSamples() const override;
42
43 virtual const RenderTargetHandle& getRenderTarget() const override { return renderTarget; }
44 virtual const DepthStencilHandle& getDepthStencil() const override { return depthStencil; }
45
47
48 private:
49 GLContext glContext;
50 GLsync release = 0;
51
52 GraphicsDeviceGL20* graphicsDevice = nullptr;
53 int width = 1280;
54 int height = 720;
55 TextureHandle textureHandle; // Lives in main context, shared with secondary context.
56 RenderTargetHandle renderTarget; // Lives in main context.
57 DepthStencilHandle depthStencil; // Lives in main context.
58 uint32_t framebuffer = 0; // Lives in secondary swapchain context
59
60 const bool isPrimary = false;
61 bool fullscreen = false;
62 bool needsResize = true;
63 };
64}
bool recreateOffscreenBuffers()
Recreates the textures and render targets used for offscreen rendering.
virtual void endFrame(uint32_t syncInterval=0, uint32_t presentFlags=PresentFlags::None) override
Finalises rendering and swaps the front and back buffers of this swap chain instance.
virtual void setSize(int newWidth, int newHeight, bool forceIt=false) override
Changes the size of this swap chain's viewport.
virtual void setFullscreen(bool enabled) override
Switch this swap chain to fullscreen or windowed depending on the parameter.
virtual void beginFrame() override
Prepares this swap chain for rendering.
virtual bool isFullscreen() override
Test whether the current swap chain is fullscreen.
Definition: SwapChainGL20.h:37
virtual int getSamples() const override
Returns the number of samples this swap chain has.
virtual int getWidth() const override
Returns the pixel width of this swap chain.
Definition: SwapChainGL20.h:39
virtual const RenderTargetHandle & getRenderTarget() const override
Returns the render target managed by this swap chain.
Definition: SwapChainGL20.h:43
virtual int getHeight() const override
Returns the pixel height of this swap chain.
Definition: SwapChainGL20.h:40
virtual const DepthStencilHandle & getDepthStencil() const override
Returns the depth stencil managed by this swap chain.
Definition: SwapChainGL20.h:44
bool initialize(WindowData *windowData, bool debugLogging)
Initialises this swap chain and attaches it to the window provided.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
@ None
No flags.
Definition: Common.h:177