Full resolution in OpenGL canvas on Retina displays

This commit is contained in:
Maciej Suminski 2015-05-18 13:48:12 +02:00
parent 6788e31a1e
commit 6fc59f9acd
3 changed files with 58 additions and 2 deletions

View File

@ -70,6 +70,10 @@ OPENGL_GAL::OPENGL_GAL( wxWindow* aParent, wxEvtHandler* aMouseListener,
isGrouping = false;
groupCounter = 0;
#ifdef __APPLE__
SetViewWantsBestResolution( true );
#endif
// Connecting the event handlers
Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) );
@ -122,10 +126,16 @@ void OPENGL_GAL::BeginDrawing()
SetCurrent( *glContext );
clientDC = new wxClientDC( this );
#ifdef __APPLE__
const float scaleFactor = GetBackingScaleFactor();
#else
const float scaleFactor = 1.0f;
#endif
// Set up the view port
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glViewport( 0, 0, (GLsizei) screenSize.x, (GLsizei) screenSize.y );
glViewport( 0, 0, (GLsizei) screenSize.x * scaleFactor, (GLsizei) screenSize.y * scaleFactor );
// Create the screen transformation
glOrtho( 0, (GLint) screenSize.x, 0, (GLsizei) screenSize.y,
@ -528,8 +538,14 @@ void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight )
{
screenSize = VECTOR2I( aWidth, aHeight );
#ifdef __APPLE__
const float scaleFactor = GetBackingScaleFactor();
#else
const float scaleFactor = 1.0f;
#endif
// Resize framebuffers
compositor.Resize( aWidth, aHeight );
compositor.Resize( aWidth * scaleFactor, aHeight * scaleFactor );
isFramebufferInitialized = false;
wxGLCanvas::SetSize( aWidth, aHeight );
@ -731,6 +747,7 @@ void OPENGL_GAL::DrawCursor( const VECTOR2D& aCursorPosition )
// Now we should only store the position of the mouse cursor
// The real drawing routines are in blitCursor()
VECTOR2D screenCursor = worldScreenMatrix * aCursorPosition;
cursorPosition = screenWorldMatrix * VECTOR2D( screenCursor.x, screenSize.y - screenCursor.y );
}

View File

@ -0,0 +1,37 @@
--- include/wx/osx/glcanvas.h 2015-05-16 15:40:21.000000000 +0200
+++ include/wx/osx/glcanvas.h 2015-05-16 16:44:53.000000000 +0200
@@ -88,6 +88,9 @@ public:
// update the view port of the current context to match this window
void SetViewport();
+ void SetViewWantsBestResolution( bool aValue );
+ bool GetViewWantsBestResolution();
+ float GetBackingScaleFactor();
// deprecated methods
// ------------------
--- src/osx/cocoa/glcanvas.mm 2015-05-16 15:40:24.000000000 +0200
+++ src/osx/cocoa/glcanvas.mm 2015-05-16 17:10:50.000000000 +0200
@@ -313,6 +313,22 @@ bool wxGLCanvas::SwapBuffers()
return true;
}
+void wxGLCanvas::SetViewWantsBestResolution( bool aValue )
+{
+ [GetHandle() setWantsBestResolutionOpenGLSurface:aValue];
+}
+
+bool wxGLCanvas::GetViewWantsBestResolution()
+{
+ return [GetHandle() wantsBestResolutionOpenGLSurface];
+}
+
+float wxGLCanvas::GetBackingScaleFactor()
+{
+ return [[GetHandle() window] backingScaleFactor];
+}
+
+
bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
{
if ( !m_glContext )

View File

@ -140,6 +140,8 @@ echo "*** Patching wxWidgets..."
doPatch "$1" "$3/patches/wxwidgets-3.0.0_macosx.patch"
doPatch "$1" "$3/patches/wxwidgets-3.0.0_macosx_bug_15908.patch"
doPatch "$1" "$3/patches/wxwidgets-3.0.0_macosx_soname.patch"
# high resolution in OpenGL canvas: http://trac.wxwidgets.org/ticket/15700
doPatch "$1" "$3/patches/wxwidgets-3.0.2_macosx_opengl_retina.patch"
# configure and build wxWidgets
wxWidgets_configure "$1" "$2" "$4"