Skip to content

Commit

Permalink
[GL] Deprecated Surface::ResetPixelFormat() by selecting multi-sample…
Browse files Browse the repository at this point in the history
… pixel format via proxy window for Win32 platform.

Surface::ResetPixelFormat() was solely used to re-create the internal window of a Win32 LLGL::Window object when a multi-sample pixel format is selected for an OpenGL context.
In order to load the necessary GL extension procedure wglChoosePixelFormatARB(), a valid GL context must be active. After selecting a format, the multi-sampled GL context can be created.
A Win32 window, however, cannot change its pixel format once its selected, so previously ResetPixelFormat() would re-create the native window on Win32 platform, while all other platforms only had dummy implementations.
This change uses a proxy window that is invisible to select a multi-sample pixel format when a WGL context is created before the format is selected for the actual window provided for the swap-chain.
  • Loading branch information
LukasBanana committed Jul 27, 2024
1 parent 288fa36 commit 044b06a
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 134 deletions.
4 changes: 3 additions & 1 deletion include/LLGL-C/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
LLGL_C_EXPORT bool llglGetSurfaceNativeHandle(LLGLSurface surface, void* nativeHandle, size_t nativeHandleSize);
LLGL_C_EXPORT void llglGetSurfaceContentSize(LLGLSurface surface, LLGLExtent2D* outSize);
LLGL_C_EXPORT bool llglAdaptSurfaceForVideoMode(LLGLSurface surface, LLGLExtent2D* outResolution, bool* outFullscreen);
LLGL_C_EXPORT void llglResetSurfacePixelFormat(LLGLSurface surface);
LLGL_C_EXPORT bool llglProcessSurfaceEvents();
LLGL_C_EXPORT LLGLDisplay llglFindSurfaceResidentDisplay(LLGLSurface surface);

//! \deprecated Since 0.04b; No need to reset pixel format anymore.
LLGL_C_EXPORT void llglResetSurfacePixelFormat(LLGLSurface surface);


#endif

Expand Down
13 changes: 5 additions & 8 deletions include/LLGL/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <LLGL/Types.h>
#include <LLGL/SwapChainFlags.h>
#include <LLGL/Display.h>
#include <LLGL/Deprecated.h>


namespace LLGL
Expand Down Expand Up @@ -76,21 +77,17 @@ class LLGL_EXPORT Surface : public Interface
*/
virtual bool AdaptForVideoMode(Extent2D* resolution, bool* fullscreen) = 0;

/**
\brief Resets the internal pixel format of the surface.
\remarks This function is mainly used by the OpenGL renderer on Win32 when a multi-sampled framebuffer is created.
\note This may invalidate the native handle previously returned by \c GetNativeHandle.
\see GetNativeHandle
*/
virtual void ResetPixelFormat() = 0;

/**
\brief Returns the Display interface where this surface is resident in.
\remarks A surface is considered resident in a display if more than the half of its client area is visible in that display.
\return Pointer to the Display in which this surface is resident or null if this surface is not resident in any display.
*/
virtual Display* FindResidentDisplay() const = 0;

//! \deprecated Since 0.04b; No need to reset pixel format anymore!
LLGL_DEPRECATED("Surface::ResetPixelFormat is deprecated since 0.04b; No need to reset pixel format anymore!")
virtual void ResetPixelFormat();

public:

/**
Expand Down
5 changes: 0 additions & 5 deletions sources/Platform/Android/AndroidCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ UTF8String AndroidCanvas::GetTitle() const
return {}; //todo...
}

void AndroidCanvas::ResetPixelFormat()
{
// dummy
}


} // /namespace LLGL

Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/Android/AndroidCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class AndroidCanvas : public Canvas
void SetTitle(const UTF8String& title) override;
UTF8String GetTitle() const override;

void ResetPixelFormat() override;

private:

CanvasDescriptor desc_;
Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/IOS/IOSCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class IOSCanvas : public Canvas
void SetTitle(const UTF8String& title) override;
UTF8String GetTitle() const override;

void ResetPixelFormat() override;

public:

// Returns the native UIWindow.
Expand Down
10 changes: 0 additions & 10 deletions sources/Platform/IOS/IOSCanvas.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,6 @@ - (void)handlePanGesture:(UIPanGestureRecognizer*)recognizer
}


/*
* ======= Private: =======
*/

void IOSCanvas::ResetPixelFormat()
{
// dummy
}


} // /namespace LLGL


Expand Down
5 changes: 0 additions & 5 deletions sources/Platform/Linux/LinuxWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ bool LinuxWindow::GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSi
return false;
}

void LinuxWindow::ResetPixelFormat()
{
// dummy
}

Extent2D LinuxWindow::GetContentSize() const
{
/* Return the size of the client area */
Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/Linux/LinuxWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class LinuxWindow : public Window

bool GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSize) override;

void ResetPixelFormat() override;

Extent2D GetContentSize() const override;

void SetPosition(const Offset2D& position) override;
Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/MacOS/MacOSSubviewWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class MacOSSubviewWindow : public Window

bool GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSize) override;

void ResetPixelFormat() override;

Extent2D GetContentSize() const override;

void SetPosition(const Offset2D& position) override;
Expand Down
5 changes: 0 additions & 5 deletions sources/Platform/MacOS/MacOSSubviewWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
return false;
}

void MacOSSubviewWindow::ResetPixelFormat()
{
// dummy
}

Extent2D MacOSSubviewWindow::GetContentSize() const
{
NSSize size = [view_ frame].size;
Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/MacOS/MacOSWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class MacOSWindow : public Window

bool GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSize) override;

void ResetPixelFormat() override;

Extent2D GetContentSize() const override;

void SetPosition(const Offset2D& position) override;
Expand Down
5 changes: 0 additions & 5 deletions sources/Platform/MacOS/MacOSWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ static NSUInteger GetNSWindowStyleMask(const WindowDescriptor& desc)
return false;
}

void MacOSWindow::ResetPixelFormat()
{
// dummy
}

Extent2D MacOSWindow::GetContentSize() const
{
NSSize size = [[wnd_ contentView] frame].size;
Expand Down
5 changes: 0 additions & 5 deletions sources/Platform/UWP/UWPWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ bool UWPWindow::GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSize
return false;
}

void UWPWindow::ResetPixelFormat()
{
//todo
}

Extent2D UWPWindow::GetContentSize() const
{
return Extent2D
Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/UWP/UWPWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class UWPWindow final : public Window

bool GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSize) override;

void ResetPixelFormat() override;

Extent2D GetContentSize() const override;

void SetPosition(const Offset2D& position) override;
Expand Down
15 changes: 6 additions & 9 deletions sources/Platform/Win32/Win32Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace LLGL
* Surface class
*/

void Surface::ResetPixelFormat()
{
// dummy
}

bool Surface::ProcessEvents()
{
/* Peek all queued messages */
Expand Down Expand Up @@ -68,7 +73,7 @@ static RECT GetClientArea(LONG width, LONG height, DWORD style)
// Determines the Win32 window style for the specified descriptor.
static DWORD GetWindowStyle(const WindowDescriptor& desc)
{
DWORD style = (WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
DWORD style = (WS_CLIPCHILDREN | WS_CLIPSIBLINGS); // Both required for OpenGL

const bool hasWindowContext =
(
Expand Down Expand Up @@ -168,14 +173,6 @@ bool Win32Window::GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSi
return false;
}

void Win32Window::ResetPixelFormat()
{
/* Destroy previous window handle and create a new one with current descriptor settings */
auto desc = GetDesc();
DestroyWindow(wnd_);
wnd_ = CreateWindowHandle(desc);
}

Extent2D Win32Window::GetContentSize() const
{
/* Return the size of the client area */
Expand Down
2 changes: 0 additions & 2 deletions sources/Platform/Win32/Win32Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class Win32Window final : public Window

bool GetNativeHandle(void* nativeHandle, std::size_t nativeHandleSize) override;

void ResetPixelFormat() override;

Extent2D GetContentSize() const override;

void SetPosition(const Offset2D& position) override;
Expand Down
Loading

0 comments on commit 044b06a

Please sign in to comment.