Add GetOpenGLScaleFactor() to abstract OpenGL coordinates scaling

The fix for OpenGL coordinates when using high DPI in b134589cbb (Fix
OpenGL samples when using HiDPI displays, 2019-08-06) did fix it for GTK
3 and macOS, but broke it for MSW and other platforms not using pixel
scaling, as window coordinates are the same as OpenGL ones there, while
GetContentScaleFactor() can still return values > 1 even on these
platforms.

Provide new GetOpenGLScaleFactor() function abstracting this platform
difference and use it in all OpenGL samples to make them work correctly
in high DPI under all platforms.

Closes https://github.com/wxWidgets/wxWidgets/pull/1944

Closes #17391.
This commit is contained in:
tm
2020-07-10 18:37:47 +02:00
committed by Vadim Zeitlin
parent 01d7fa8116
commit f6cc8ff52c
12 changed files with 50 additions and 7 deletions

View File

@@ -752,7 +752,7 @@ enum
platforms where wxWindow uses logical pixels, affected by the coordinate
scaling, on high DPI displays. Thus, if you want to set the OpenGL view
port to the size of entire window, you must multiply the result returned by
wxWindow::GetClientSize() by wxWindow::GetContentScaleFactor() before
wxWindow::GetClientSize() by wxGLCanvas::GetOpenGLScaleFactor() before
passing it to @c glViewport(). Same considerations apply to other OpenGL
functions and other coordinates, notably those retrieved from wxMouseEvent
in the event handlers.
@@ -936,6 +936,23 @@ public:
*/
bool SetCurrent(const wxGLContext& context) const;
/**
Returns the scale factor for transformation between logical and
physical OpenGL coordinates.
This factor is always 1 on the platforms where logical pixels are the
same as physical ones, in any DPI (such as MSW), but can be different
from it on the platforms where logical and physical pixels may differ
due to DPI scaling (such as GTK 3 or macOS).
To handle the differences between the platforms, always multiply the
values expressed in window coordinates (window sizes, mouse position
etc) by this factor before passing them to OpenGL functions.
@since 3.1.4
*/
double GetOpenGLScaleFactor() const;
/**
Swaps the double-buffer of this window, making the back-buffer the
front-buffer and vice versa, so that the output of the previous OpenGL