Skip to content

Commit

Permalink
[SwapChain] Fixed issue with initially visible swap-chain surface in …
Browse files Browse the repository at this point in the history
…GL backend.

GL context must recreate the window for multi-sampled contexts,
so make the renderer backends call the new ShowSurface() function after their context is fully initialized.
  • Loading branch information
LukasBanana committed Jul 3, 2024
1 parent bc6d978 commit 205ea7c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 2 deletions.
1 change: 0 additions & 1 deletion examples/C99/HelloTriangle/HelloTriangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ int main(int argc, char* argv[])
LLGLWindow window = LLGL_GET_AS(LLGLWindow, surface);

llglSetWindowTitle(window, L"LLGL C99 Example: Hello Triangle");
llglShowWindow(window, true);

// Vertex data structure
typedef struct Vertex
Expand Down
3 changes: 3 additions & 0 deletions include/LLGL/SwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class LLGL_EXPORT SwapChain : public RenderTarget
std::size_t windowContextSize = 0
);

//! Shows the swap-chain surface if it's not the same as the input surface.
void ShowSurface();

/**
\brief Shares the surface and resolution with another swap-chain.
\note This is only used by the renderer debug layer.
Expand Down
4 changes: 4 additions & 0 deletions sources/Renderer/Direct3D11/D3D11SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ D3D11SwapChain::D3D11SwapChain(

if (desc.debugName != nullptr)
SetDebugName(desc.debugName);

/* Show default surface */
if (!surface)
ShowSurface();
}

void D3D11SwapChain::SetDebugName(const char* name)
Expand Down
4 changes: 4 additions & 0 deletions sources/Renderer/Direct3D12/D3D12SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ D3D12SwapChain::D3D12SwapChain(

if (desc.debugName != nullptr)
SetDebugName(desc.debugName);

/* Show default surface */
if (!surface)
ShowSurface();
}

D3D12SwapChain::~D3D12SwapChain()
Expand Down
4 changes: 4 additions & 0 deletions sources/Renderer/Metal/MTSwapChain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ - (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size
view_.colorPixelFormat = renderPass_.GetColorAttachments()[0].pixelFormat;
view_.depthStencilPixelFormat = renderPass_.GetDepthStencilFormat();
view_.sampleCount = renderPass_.GetSampleCount();

/* Show default surface */
if (!surface)
ShowSurface();
}

void MTSwapChain::Present()
Expand Down
5 changes: 5 additions & 0 deletions sources/Renderer/Null/NullSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ NullSwapChain::NullSwapChain(
depthStencilFormat_ { ChooseDepthStencilFormat(desc.depthBits, desc.stencilBits) }
{
SetOrCreateSurface(surface, SwapChain::BuildDefaultSurfaceTitle(rendererInfo), desc.resolution, desc.fullscreen);

if (desc.debugName != nullptr)
SetDebugName(desc.debugName);

/* Show default surface */
if (!surface)
ShowSurface();
}

void NullSwapChain::SetDebugName(const char* name)
Expand Down
4 changes: 4 additions & 0 deletions sources/Renderer/OpenGL/GLSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ GLSwapChain::GLSwapChain(

/* Get state manager and reset current framebuffer height */
GetStateManager().ResetFramebufferHeight(framebufferHeight_);

/* Show default surface */
if (!surface)
ShowSurface();
}

void GLSwapChain::Present()
Expand Down
9 changes: 8 additions & 1 deletion sources/Renderer/SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void SwapChain::SetOrCreateSurface(
{
windowDesc.title = title;
windowDesc.size = size;
windowDesc.flags = WindowFlags::Visible | WindowFlags::DisableSizeScaling | (fullscreen ? WindowFlags::Borderless : WindowFlags::Centered);
windowDesc.flags = WindowFlags::DisableSizeScaling | (fullscreen ? WindowFlags::Borderless : WindowFlags::Centered);
windowDesc.windowContext = windowContext;
windowDesc.windowContextSize = windowContextSize;
}
Expand All @@ -193,6 +193,13 @@ void SwapChain::SetOrCreateSurface(
SetDisplayFullscreenMode(pimpl_->resolution);
}

void SwapChain::ShowSurface()
{
#ifndef LLGL_MOBILE_PLATFORM
static_cast<Window&>(GetSurface()).Show();
#endif
}

void SwapChain::ShareSurfaceAndConfig(SwapChain& other)
{
pimpl_->surface = other.pimpl_->surface;
Expand Down
4 changes: 4 additions & 0 deletions sources/Renderer/Vulkan/VKSwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ VKSwapChain::VKSwapChain(
/* Create Vulkan render passes, swap-chain, depth-stencil buffer, and multisampling color buffers */
CreateDefaultAndSecondaryRenderPass();
CreateResolutionDependentResources(GetResolution());

/* Show default surface */
if (!surface)
ShowSurface();
}

void VKSwapChain::Present()
Expand Down

0 comments on commit 205ea7c

Please sign in to comment.