]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/glcanvas.cpp
more fixes to radio menu items: fixed Check() for them; allow separators inside the...
[wxWidgets.git] / src / mac / glcanvas.cpp
index b3832d29fa1b822dcd007ccf397f738be2a6983e..62d9c307c44a67542b3859f67957d993cb0f1fbe 100644 (file)
@@ -33,8 +33,6 @@
 #include "wx/glcanvas.h"
 #include "wx/mac/uma.h"
 
-#include <agl.h>
-
 /*
  * GLContext implementation
  */
@@ -47,7 +45,7 @@ wxGLContext::wxGLContext(
 {
     m_window = win;
 
-    m_drawable = (AGLDrawable) UMAGetWindowPort(win->GetMacRootWindow());
+    m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow()));
 
     m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL);
     wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") );
@@ -113,9 +111,9 @@ void wxGLContext::SetColour(const char *colour)
  * wxGLCanvas implementation
  */
 
-IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow)
+IMPLEMENT_CLASS(wxGLCanvas, wxWindow)
 
-BEGIN_EVENT_TABLE(wxGLCanvas, wxScrolledWindow)
+BEGIN_EVENT_TABLE(wxGLCanvas, wxWindow)
     EVT_SIZE(wxGLCanvas::OnSize)
 END_EVENT_TABLE()
 
@@ -147,13 +145,10 @@ wxGLCanvas::~wxGLCanvas()
     delete m_glContext;
 }
 
-bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id,
-                       const wxPoint& pos, const wxSize& size, long style, const wxString& name,
-                       int *attribList, const wxPalette& palette)
+static AGLPixelFormat ChoosePixelFormat(const int *attribList)
 {
-       m_macEraseOnRedraw = false ;
     GLint data[512];
-    GLint defs[] = { AGL_RGBA, 
+    GLint defaultAttribs[] = { AGL_RGBA, 
                     AGL_DOUBLEBUFFER, 
                     AGL_MINIMUM_POLICY, 
                     AGL_DEPTH_SIZE, 1,  // use largest available depth buffer
@@ -165,11 +160,11 @@ bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID
     GLint *attribs;
     if (!attribList)
     {
-       attribs = defs;
+         attribs = defaultAttribs;
     }
     else
     {
-      int data[512], arg=0, p=0;
+      int arg=0, p=0;
 
       data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX
       while( (attribList[arg]!=0) && (p<512) )
@@ -211,11 +206,19 @@ bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID
       }       
       data[p] = 0; 
 
-      attribs = defs;
+      attribs = data;
     }
-    wxScrolledWindow::Create( parent, id, pos, size, style, name );
+    
+    return aglChoosePixelFormat(NULL, 0, attribs);
+}
 
-    AGLPixelFormat fmt = aglChoosePixelFormat(NULL, 0, attribs);
+bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID id,
+                       const wxPoint& pos, const wxSize& size, long style, const wxString& name,
+                       int *attribList, const wxPalette& palette)
+{
+    wxWindow::Create( parent, id, pos, size, style, name );
+
+    AGLPixelFormat fmt = ChoosePixelFormat(attribList);
     wxCHECK_MSG( fmt, false, wxT("Couldn't create OpenGl pixel format") );
 
     m_glContext = new wxGLContext(fmt, this, palette, shared);
@@ -248,7 +251,7 @@ void wxGLCanvas::SetViewport()
     int width, height;
     GetClientSize(& width, & height);
     Rect bounds ;
-    GetWindowPortBounds( GetMacRootWindow() , &bounds ) ;
+    GetWindowPortBounds( MAC_WXHWND(MacGetRootWindow()) , &bounds ) ;
     GLint parms[4] ;
     parms[0] = x ;
     parms[1] = bounds.bottom - bounds.top - ( y + height ) ;
@@ -259,20 +262,32 @@ void wxGLCanvas::SetViewport()
 }
 
 void wxGLCanvas::OnSize(wxSizeEvent& event)
+{
+  MacUpdateView() ;
+}
+
+void wxGLCanvas::MacUpdateView()
 {
   if (m_glContext)
   {
     UpdateContext();
     m_glContext->SetCurrent();
-
     SetViewport();
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-    glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 );
-    glMatrixMode(GL_MODELVIEW);
   }
 }
 
+void wxGLCanvas::MacSuperChangedPosition()
+{
+  MacUpdateView() ;
+  wxWindow::MacSuperChangedPosition() ;
+}
+
+void wxGLCanvas::MacTopLevelWindowChangedPosition()
+{
+  MacUpdateView() ;
+  wxWindow::MacTopLevelWindowChangedPosition() ;
+}
+
 void wxGLCanvas::SetCurrent()
 {
   if (m_glContext)
@@ -287,4 +302,25 @@ void wxGLCanvas::SetColour(const char *colour)
     m_glContext->SetColour(colour);
 }
 
+
+//---------------------------------------------------------------------------
+// wxGLApp
+//---------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxGLApp, wxApp)
+
+bool wxGLApp::InitGLVisual(int *attribList)
+{
+    AGLPixelFormat fmt = ChoosePixelFormat(attribList);
+    if (fmt != NULL) {
+        aglDestroyPixelFormat(fmt);
+        return true;
+    } else
+        return false;
+}
+
+wxGLApp::~wxGLApp(void)
+{
+}
+
 #endif // wxUSE_GLCANVAS