Ticket #17391: opengl_scale.patch

File opengl_scale.patch, 7.1 KB (added by tm, 12 months ago)

Implemtation of GetOpenGLScaleFactor()

  • docs/changes.txt

    diff --git a/docs/changes.txt b/docs/changes.txt
    index d2f2fe1..b9c289e 100644
    a b Changes in behaviour not resulting in compilation errors 
    8080
    8181- wxGLCanvas now uses physical pixels on high DPI displays under platforms
    8282  where they're different from logical ones (wxGTK3, wxOSX). Multiply logical
    83   coordinates, e.g. returned by wxWindow::GetSize() by GetContentScaleFactor()
     83  coordinates, e.g. returned by wxWindow::GetSize() by GetOpenGLScaleFactor()
    8484  before using them with OpenGL functions.
    8585
    8686
  • include/wx/glcanvas.h

    diff --git a/include/wx/glcanvas.h b/include/wx/glcanvas.h
    index d21f0d4..0670ea3 100644
    a b public: 
    258258    // as a parameter
    259259    wxGLContextAttrs& GetGLCTXAttrs() { return m_GLCTXAttrs; }
    260260
     261    // wxGLCanvas uses physical pixels on high DPI displays under platforms
     262    // where they're different from logical ones (wxGTK3, wxOSX)
     263    // so provide here a scale factor to hide these 2 different
     264    // implementation details
     265    virtual double GetOpenGLScaleFactor() const;
    261266    // deprecated methods using the implicit wxGLContext
    262267#if WXWIN_COMPATIBILITY_2_8
    263268    wxDEPRECATED( wxGLContext* GetContext() const );
  • include/wx/osx/glcanvas.h

    diff --git a/include/wx/osx/glcanvas.h b/include/wx/osx/glcanvas.h
    index 7f12f24..cf660ac 100644
    a b public: 
    9797
    9898    // implement wxGLCanvasBase methods
    9999    virtual bool SwapBuffers() wxOVERRIDE;
    100 
     100    virtual double GetOpenGLScaleFactor() const wxOVERRIDE;
    101101
    102102    // Mac-specific functions
    103103    // ----------------------
  • include/wx/unix/glx11.h

    diff --git a/include/wx/unix/glx11.h b/include/wx/unix/glx11.h
    index e7b49bb..d8032ef 100644
    a b public: 
    5959    // --------------------------------
    6060
    6161    virtual bool SwapBuffers() wxOVERRIDE;
    62 
     62    virtual double GetOpenGLScaleFactor() const wxOVERRIDE;
    6363
    6464    // X11-specific methods
    6565    // --------------------
  • interface/wx/glcanvas.h

    diff --git a/interface/wx/glcanvas.h b/interface/wx/glcanvas.h
    index ee6007f..2c3c4b0 100644
    a b enum 
    752752    platforms where wxWindow uses logical pixels, affected by the coordinate
    753753    scaling, on high DPI displays. Thus, if you want to set the OpenGL view
    754754    port to the size of entire window, you must multiply the result returned by
    755     wxWindow::GetClientSize() by wxWindow::GetContentScaleFactor() before
     755    wxWindow::GetClientSize() by wxGLCanvas::GetOpenGLScaleFactor() before
    756756    passing it to @c glViewport(). Same considerations apply to other OpenGL
    757757    functions and other coordinates, notably those retrieved from wxMouseEvent
    758758    in the event handlers.
    public: 
    936936    */
    937937    bool SetCurrent(const wxGLContext& context) const;
    938938
     939    /** returns the scale factor for transformation between logical and
     940        physical coordinates
     941        @since 3.1.4
     942    */
     943    double GetOpenGLScaleFactor() const;
    939944    /**
    940945        Swaps the double-buffer of this window, making the back-buffer the
    941946        front-buffer and vice versa, so that the output of the previous OpenGL
  • samples/opengl/cube/cube.cpp

    diff --git a/samples/opengl/cube/cube.cpp b/samples/opengl/cube/cube.cpp
    index 254812e..9410fb4 100644
    a b void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) 
    349349    // multiple canvases: If we updated the viewport in the wxSizeEvent
    350350    // handler, changing the size of one canvas causes a viewport setting that
    351351    // is wrong when next another canvas is repainted.
    352     const wxSize ClientSize = GetClientSize() * GetContentScaleFactor();
     352    const wxSize ClientSize = GetClientSize() * GetOpenGLScaleFactor();
    353353
    354354    TestGLContext& canvas = wxGetApp().GetContext(this, m_useStereo);
    355355    glViewport(0, 0, ClientSize.x, ClientSize.y);
  • samples/opengl/isosurf/isosurf.cpp

    diff --git a/samples/opengl/isosurf/isosurf.cpp b/samples/opengl/isosurf/isosurf.cpp
    index 9dd47a1..19306d3 100644
    a b void TestGLCanvas::OnSize(wxSizeEvent& event) 
    280280    // This is OK here only because there is only one canvas that uses the
    281281    // context. See the cube sample for that case that multiple canvases are
    282282    // made current with one context.
    283     const wxSize size = event.GetSize() * GetContentScaleFactor();
     283    const wxSize size = event.GetSize() * GetOpenGLScaleFactor();
    284284    glViewport(0, 0, size.x, size.y);
    285285}
    286286
  • samples/opengl/penguin/penguin.cpp

    diff --git a/samples/opengl/penguin/penguin.cpp b/samples/opengl/penguin/penguin.cpp
    index b5992a6..e7fcc76 100644
    a b void TestGLCanvas::ResetProjectionMode() 
    306306    // or more than one wxGLContext in the application.
    307307    SetCurrent(*m_glRC);
    308308
    309     const wxSize ClientSize = GetClientSize() * GetContentScaleFactor();
     309    const wxSize ClientSize = GetClientSize() * GetOpenGLScaleFactor();
    310310
    311311    // It's up to the application code to update the OpenGL viewport settings.
    312312    // In order to avoid extensive context switching, consider doing this in
  • samples/opengl/pyramid/pyramid.cpp

    diff --git a/samples/opengl/pyramid/pyramid.cpp b/samples/opengl/pyramid/pyramid.cpp
    index 5123a91..92a0cde 100644
    a b void MyGLCanvas::OnSize(wxSizeEvent& event) 
    565565    SetCurrent(*m_oglContext);
    566566
    567567    // It's up to the application code to update the OpenGL viewport settings.
    568     const wxSize size = event.GetSize() * GetContentScaleFactor();
     568    const wxSize size = event.GetSize() * GetOpenGLScaleFactor();
    569569    m_winHeight = size.y;
    570570    m_oglManager->SetViewport(0, 0, size.x, m_winHeight);
    571571
  • src/common/glcmn.cpp

    diff --git a/src/common/glcmn.cpp b/src/common/glcmn.cpp
    index e0c056a..206fd9a 100644
    a b bool wxGLCanvasBase::ParseAttribList(const int *attribList, 
    376376    return true;
    377377}
    378378
     379double wxGLCanvasBase::GetOpenGLScaleFactor() const
     380{
     381    return 1.0;
     382}
     383
    379384// ============================================================================
    380385// compatibility layer for OpenGL 3 and OpenGL ES
    381386// ============================================================================
  • src/osx/glcanvas_osx.cpp

    diff --git a/src/osx/glcanvas_osx.cpp b/src/osx/glcanvas_osx.cpp
    index 71d7dd0..90b0677 100644
    a b bool wxGLCanvas::IsAGLMultiSampleAvailable() 
    562562    return s_isMultiSampleAvailable != 0;
    563563}
    564564
     565double wxGLCanvas::GetOpenGLScaleFactor() const
     566{
     567    return GetContentScaleFactor();
     568}
     569
    565570/* static */
    566571bool wxGLCanvasBase::IsDisplaySupported(const wxGLAttributes& dispAttrs)
    567572{
  • src/x11/glcanvas.cpp

    diff --git a/src/x11/glcanvas.cpp b/src/x11/glcanvas.cpp
    index 7a4c5fb..cfffba44 100644
    a b int wxGLCanvas::GetColourIndex(const wxColour& col_) 
    124124    return col.GetPixel();
    125125}
    126126
     127double wxGLCanvas::GetOpenGLScaleFactor() const
     128{
     129#ifdef __WXGTK3__
     130    return GetContentScaleFactor();
     131#else
     132    return 1.0;
     133#endif
     134}
     135
    127136#endif // wxUSE_GLCANVAS