Skip to content

Commit

Permalink
Fixed compile errors in GLSwapChain on Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBanana committed Sep 4, 2023
1 parent f669b42 commit bffc3da
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
8 changes: 7 additions & 1 deletion include/LLGL/SwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,13 @@ class LLGL_EXPORT SwapChain : public RenderTarget
\see Surface::GetContentSize
\see SwitchFullscreenMode
*/
void SetOrCreateSurface(const std::shared_ptr<Surface>& surface, const Extent2D& size, bool fullscreen, const void* windowContext);
void SetOrCreateSurface(
const std::shared_ptr<Surface>& surface,
const Extent2D& size,
bool fullscreen,
const void* windowContext = nullptr,
std::size_t windowContextSize = 0
);

/**
\brief Shares the surface and resolution with another swap-chain.
Expand Down
10 changes: 7 additions & 3 deletions sources/Renderer/OpenGL/GLSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "../TextureUtils.h"
#include "Platform/GLContextManager.h"

#ifdef __linux__
#include <LLGL/Platform/NativeHandle.h>
#endif


namespace LLGL
{
Expand All @@ -29,17 +33,17 @@ GLSwapChain::GLSwapChain(
pixelFormat.stencilBits = desc.stencilBits;
pixelFormat.samples = static_cast<int>(GetClampedSamples(desc.samples));

#ifdef LLGL_OS_LINUX
#ifdef __linux__

/* Set up surface for the swap-chain and pass native context handle */
NativeHandle windowContext = {};
ChooseGLXVisualAndGetX11WindowContext(pixelFormat, windowContext);
SetOrCreateSurface(surface, desc.resolution, desc.fullscreen, &windowContext);
SetOrCreateSurface(surface, desc.resolution, desc.fullscreen, &windowContext, sizeof(windowContext));

#else

/* Setup surface for the swap-chain */
SetOrCreateSurface(surface, desc.resolution, desc.fullscreen, nullptr);
SetOrCreateSurface(surface, desc.resolution, desc.fullscreen);

#endif

Expand Down
5 changes: 1 addition & 4 deletions sources/Renderer/OpenGL/GLSwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
#include "Platform/GLSwapChainContext.h"
#include <memory>

#ifdef __linux__
#include <LLGL/Platform/NativeHandle.h>
#endif


namespace LLGL
{


struct NativeHandle;
class GLRenderTarget;
class GLContextManager;

Expand Down
6 changes: 3 additions & 3 deletions sources/Renderer/OpenGL/Platform/Linux/LinuxGLSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void GLSwapChain::ChooseGLXVisualAndGetX11WindowContext(GLPixelFormat& pixelForm
if (!windowContext.display)
throw std::runtime_error("failed to open X11 display");

windowContext.parentWindow = DefaultRootWindow(windowContext.display);
windowContext.screen = DefaultScreen(windowContext.display);
windowContext.window = DefaultRootWindow(windowContext.display);
windowContext.screen = DefaultScreen(windowContext.display);

GLXFBConfig framebufferConfig = 0;

Expand Down Expand Up @@ -97,7 +97,7 @@ void GLSwapChain::ChooseGLXVisualAndGetX11WindowContext(GLPixelFormat& pixelForm
}

/* Create Colormap structure */
windowContext.colorMap = XCreateColormap(windowContext.display, windowContext.parentWindow, windowContext.visual->visual, AllocNone);
windowContext.colorMap = XCreateColormap(windowContext.display, windowContext.window, windowContext.visual->visual, AllocNone);

if (!windowContext.visual)
throw std::runtime_error("failed to choose X11 visual for OpenGL");
Expand Down
16 changes: 11 additions & 5 deletions sources/Renderer/SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ Surface& SwapChain::GetSurface() const
* ======= Protected: =======
*/

void SwapChain::SetOrCreateSurface(const std::shared_ptr<Surface>& surface, const Extent2D& size, bool fullscreen, const void* windowContext)
void SwapChain::SetOrCreateSurface(
const std::shared_ptr<Surface>& surface,
const Extent2D& size,
bool fullscreen,
const void* windowContext,
std::size_t windowContextSize)
{
/* Use specified surface size as resolution by default */
Extent2D resolution = size;
Expand Down Expand Up @@ -174,10 +179,11 @@ void SwapChain::SetOrCreateSurface(const std::shared_ptr<Surface>& surface, cons
/* Create new window for this swap-chain */
WindowDescriptor windowDesc;
{
windowDesc.size = size;
windowDesc.borderless = fullscreen;
windowDesc.centered = !fullscreen;
windowDesc.windowContext = windowContext;
windowDesc.size = size;
windowDesc.borderless = fullscreen;
windowDesc.centered = !fullscreen;
windowDesc.windowContext = windowContext;
windowDesc.windowContextSize = windowContextSize;
}
pimpl_->surface = Window::Create(windowDesc);

Expand Down

0 comments on commit bffc3da

Please sign in to comment.