X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/83918cccc9d4930a967c3e7f0547490199ff8889..9f4de6b2cf06f53a98b28f53640f3b9ec8cf4182:/src/gtk/glcanvas.cpp diff --git a/src/gtk/glcanvas.cpp b/src/gtk/glcanvas.cpp index 01f39b67b2..e46cac9e32 100644 --- a/src/gtk/glcanvas.cpp +++ b/src/gtk/glcanvas.cpp @@ -237,9 +237,9 @@ gtk_glcanvas_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, w // wxGlCanvas //--------------------------------------------------------------------------- -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() @@ -283,7 +283,6 @@ bool wxGLCanvas::Create( wxWindow *parent, int *attribList, const wxPalette& palette) { - int data[512]; m_sharedContext = (wxGLContext*)shared; // const_cast m_sharedContextOf = (wxGLCanvas*)shared_context_of; // const_cast m_glContext = (wxGLContext*) NULL; @@ -292,18 +291,79 @@ bool wxGLCanvas::Create( wxWindow *parent, m_noExpose = TRUE; m_nativeSizeEvent = TRUE; + XVisualInfo *vi = NULL; + if (wxTheApp->m_glVisualInfo != NULL) { + vi = (XVisualInfo *) wxTheApp->m_glVisualInfo; + m_canFreeVi = FALSE; // owned by wxTheApp - don't free upon destruction + } else { + vi = (XVisualInfo *) ChooseGLVisual(attribList); + m_canFreeVi = TRUE; + } + m_vi = vi; // save for later use + + wxCHECK_MSG( m_vi, FALSE, "required visual couldn't be found" ); + + GdkVisual *visual = gdkx_visual_get( vi->visualid ); + GdkColormap *colormap = gdk_colormap_new( gdkx_visual_get(vi->visualid), TRUE ); + + gtk_widget_push_colormap( colormap ); + gtk_widget_push_visual( visual ); + + wxWindow::Create( parent, id, pos, size, style, name ); + + m_glWidget = m_wxwindow; + + gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE ); + + gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize", + GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(m_wxwindow), "map", + GTK_SIGNAL_FUNC(gtk_glwindow_map_callback), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", + GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer)this ); + + gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw", + GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this ); + + gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", + GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this ); + + gtk_widget_pop_visual(); + gtk_widget_pop_colormap(); + + if (GTK_WIDGET_REALIZED(m_wxwindow)) + gtk_glwindow_realized_callback( m_wxwindow, this ); + + if (GTK_WIDGET_MAPPED(m_wxwindow)) + gtk_glwindow_map_callback( m_wxwindow, this ); + + return TRUE; +} + +wxGLCanvas::~wxGLCanvas() +{ + XVisualInfo *vi = (XVisualInfo *) m_vi; + + if (vi && m_canFreeVi) XFree( vi ); + if (m_glContext) delete m_glContext; +} + +void* wxGLCanvas::ChooseGLVisual(int *attribList) +{ + int data[512]; if (!attribList) { // default settings if attriblist = 0 data[0] = GLX_RGBA; data[1] = GLX_DOUBLEBUFFER; - data[2] = GLX_DOUBLEBUFFER; - data[3] = GLX_DEPTH_SIZE; data[4] = 1; - data[5] = GLX_RED_SIZE; data[6] = 1; - data[7] = GLX_GREEN_SIZE; data[8] = 1; - data[9] = GLX_BLUE_SIZE; data[10] = 1; - data[11] = GLX_ALPHA_SIZE; data[12] = 0; - data[13] = None; + data[2] = GLX_DEPTH_SIZE; data[3] = 1; + data[4] = GLX_RED_SIZE; data[5] = 1; + data[6] = GLX_GREEN_SIZE; data[7] = 1; + data[8] = GLX_BLUE_SIZE; data[9] = 1; + data[10] = GLX_ALPHA_SIZE; data[11] = 0; + data[12] = None; attribList = (int*) data; } @@ -356,51 +416,7 @@ bool wxGLCanvas::Create( wxWindow *parent, Display *dpy = GDK_DISPLAY(); - XVisualInfo *vi = glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); - - m_vi = vi; // safe for later use - - wxCHECK_MSG( m_vi, FALSE, "required visual couldn't be found" ); - - GdkVisual *visual = gdkx_visual_get( vi->visualid ); - GdkColormap *colormap = gdk_colormap_new( gdkx_visual_get(vi->visualid), TRUE ); - - gtk_widget_push_colormap( colormap ); - gtk_widget_push_visual( visual ); - - wxScrolledWindow::Create( parent, id, pos, size, style, name ); - - m_glWidget = m_wxwindow; - - gtk_pizza_set_clear( GTK_PIZZA(m_wxwindow), FALSE ); - - gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize", - GTK_SIGNAL_FUNC(gtk_glwindow_realized_callback), (gpointer) this ); - - gtk_signal_connect( GTK_OBJECT(m_wxwindow), "map", - GTK_SIGNAL_FUNC(gtk_glwindow_map_callback), (gpointer) this ); - - gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", - GTK_SIGNAL_FUNC(gtk_glwindow_expose_callback), (gpointer)this ); - - gtk_signal_connect( GTK_OBJECT(m_wxwindow), "draw", - GTK_SIGNAL_FUNC(gtk_glwindow_draw_callback), (gpointer)this ); - - gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", - GTK_SIGNAL_FUNC(gtk_glcanvas_size_callback), (gpointer)this ); - - gtk_widget_pop_visual(); - gtk_widget_pop_colormap(); - - return TRUE; -} - -wxGLCanvas::~wxGLCanvas() -{ - XVisualInfo *vi = (XVisualInfo *) m_vi; - - if (vi) XFree( vi ); - if (m_glContext) delete m_glContext; + return glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); } void wxGLCanvas::SwapBuffers() @@ -410,19 +426,6 @@ void wxGLCanvas::SwapBuffers() void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event)) { - int width, height; - GetClientSize( &width, &height ); - - if (m_glContext && GTK_WIDGET_REALIZED(m_glWidget) ) - { - SetCurrent(); - - glViewport(0, 0, (GLint)width, (GLint)height ); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 ); - glMatrixMode(GL_MODELVIEW); - } } void wxGLCanvas::SetCurrent() @@ -450,6 +453,26 @@ void wxGLCanvas::OnInternalIdle() wxWindow::OnInternalIdle(); } + + +//--------------------------------------------------------------------------- +// wxGLApp +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLApp, wxApp) + +wxGLApp::~wxGLApp() +{ + if (m_glVisualInfo) XFree(m_glVisualInfo); +} + +bool wxGLApp::InitGLVisual(int *attribList) +{ + if (m_glVisualInfo) XFree(m_glVisualInfo); + m_glVisualInfo = wxGLCanvas::ChooseGLVisual(attribList); + return (m_glVisualInfo != NULL); +} + #endif // wxUSE_GLCANVAS