From ce65a22250ed62a63e4b6d74c9a09bd285798258 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 12 Jul 2012 01:59:11 +0000 Subject: [PATCH] Linux fixes. --- linux/dialogs.cpp | 89 +++++++++++---- linux/glwindow.cpp | 275 +++++++++++++++++++++++++-------------------- win/glwindow.cpp | 8 +- 3 files changed, 226 insertions(+), 146 deletions(-) diff --git a/linux/dialogs.cpp b/linux/dialogs.cpp index 2dc402a4..7a4a398c 100644 --- a/linux/dialogs.cpp +++ b/linux/dialogs.cpp @@ -1407,10 +1407,20 @@ bool preferencesdlg_getopts(LC_PREFERENCESDLG_STRUCT* s, LC_PREFERENCESDLG_OPTS* if (GTK_TOGGLE_BUTTON(s->det_edges)->active) opts->nDetail |= LC_DET_BRICKEDGES; if (GTK_TOGGLE_BUTTON(s->det_lighting)->active) opts->nDetail |= LC_DET_LIGHTING; if (GTK_TOGGLE_BUTTON(s->det_smooth)->active) opts->nDetail |= LC_DET_SMOOTH; - if (GTK_TOGGLE_BUTTON(s->det_antialias)->active) opts->nDetail |= LC_DET_ANTIALIAS; if (GTK_TOGGLE_BUTTON(s->det_fast)->active) opts->nDetail |= LC_DET_FAST; if (!read_float(s->det_width, &opts->fLineWidth, 0.5f, 5.0f)) return false; + const gchar* AASamples = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(s->det_antialias)->entry)); + if (!strcmp(AASamples, "Off")) + opts->AASamples = 1; + else if (!strcmp(AASamples, "2x")) + opts->AASamples = 2; + else if (!strcmp(AASamples, "4x")) + opts->AASamples = 4; + else if (!strcmp(AASamples, "8x")) + opts->AASamples = 8; + else + opts->AASamples = 1; opts->nSnap = 0; if (GTK_TOGGLE_BUTTON(s->draw_grid)->active) opts->nSnap |= LC_DRAW_GRID; @@ -1466,6 +1476,7 @@ static void preferencesdlg_default(GtkWidget *widget, gpointer data) Sys_ProfileSaveInt("Default", "Mouse", (int)Opts.nMouse); Sys_ProfileSaveInt("Default", "Detail", Opts.nDetail); Sys_ProfileSaveInt("Default", "Line", (int)(Opts.fLineWidth * 100)); + Sys_ProfileSaveInt("Default", "AASamples", Opts.AASamples); Sys_ProfileSaveInt("Default", "Snap", Opts.nSnap); Sys_ProfileSaveInt("Default", "Angle", Opts.nAngleSnap); Sys_ProfileSaveInt("Default", "Grid", Opts.nGridSize); @@ -1565,25 +1576,9 @@ int preferencesdlg_execute(void* param) gtk_widget_show(s.det_edges); gtk_table_attach_defaults(GTK_TABLE(table), s.det_edges, 0, 1, 0, 1); - s.det_lighting = gtk_check_button_new_with_label("Lighting"); - gtk_widget_show(s.det_lighting); - gtk_table_attach_defaults(GTK_TABLE(table), s.det_lighting, 0, 1, 1, 2); - - s.det_smooth = gtk_check_button_new_with_label("Smooth shading"); - gtk_widget_show(s.det_smooth); - gtk_table_attach_defaults(GTK_TABLE(table), s.det_smooth, 0, 1, 2, 3); - - s.det_antialias = gtk_check_button_new_with_label("Anti-aliasing"); - gtk_widget_show(s.det_antialias); - gtk_table_attach_defaults(GTK_TABLE(table), s.det_antialias, 0, 1, 3, 4); - - s.det_fast = gtk_check_button_new_with_label("Fast rendering"); - gtk_widget_show(s.det_fast); - gtk_table_attach_defaults(GTK_TABLE(table), s.det_fast, 0, 1, 4, 5); - hbox = gtk_hbox_new(FALSE, 5); gtk_widget_show(hbox); - gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 1, 5, 6); + gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 1, 1, 2); label = gtk_label_new("Line width"); gtk_widget_show(label); @@ -1595,6 +1590,40 @@ int preferencesdlg_execute(void* param) gtk_box_pack_start(GTK_BOX(hbox), s.det_width, FALSE, FALSE, 0); gtk_entry_set_width_chars(GTK_ENTRY(s.det_width), 4); + hbox = gtk_hbox_new(FALSE, 5); + gtk_widget_show(hbox); + gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 1, 2, 3); + + label = gtk_label_new("Anti-aliasing"); + gtk_widget_show(label); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0); + gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); + + s.det_antialias = gtk_combo_new(); + gtk_widget_show(s.det_antialias); + gtk_box_pack_start(GTK_BOX(hbox), s.det_antialias, FALSE, FALSE, 0); + gtk_entry_set_width_chars(GTK_ENTRY(GTK_COMBO(s.det_antialias)->entry), 3); + + GList* Samples = NULL; + Samples = g_list_append(Samples, (void*)"Off"); + Samples = g_list_append(Samples, (void*)"2x"); + Samples = g_list_append(Samples, (void*)"4x"); + Samples = g_list_append(Samples, (void*)"8x"); + gtk_combo_set_popdown_strings(GTK_COMBO(s.det_antialias), Samples); + g_list_free(Samples); + + s.det_lighting = gtk_check_button_new_with_label("Lighting"); + gtk_widget_show(s.det_lighting); + gtk_table_attach_defaults(GTK_TABLE(table), s.det_lighting, 0, 1, 3, 4); + + s.det_smooth = gtk_check_button_new_with_label("Smooth shading"); + gtk_widget_show(s.det_smooth); + gtk_table_attach_defaults(GTK_TABLE(table), s.det_smooth, 0, 1, 4, 5); + + s.det_fast = gtk_check_button_new_with_label("Fast rendering"); + gtk_widget_show(s.det_fast); + gtk_table_attach_defaults(GTK_TABLE(table), s.det_fast, 0, 1, 5, 6); + table = gtk_table_new(7, 2, TRUE); gtk_widget_show(table); gtk_container_add(GTK_CONTAINER(notebook), table); @@ -1825,9 +1854,28 @@ int preferencesdlg_execute(void* param) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s.det_edges),(opts->nDetail & LC_DET_BRICKEDGES) ? TRUE : FALSE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s.det_lighting),(opts->nDetail & LC_DET_LIGHTING) ? TRUE : FALSE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s.det_smooth),(opts->nDetail & LC_DET_SMOOTH) ? TRUE : FALSE); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s.det_antialias),(opts->nDetail & LC_DET_ANTIALIAS) ? TRUE : FALSE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s.det_fast),(opts->nDetail & LC_DET_FAST) ? TRUE : FALSE); write_float(s.det_width, opts->fLineWidth); + switch (opts->AASamples) + { + default: + case 1: + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(s.det_antialias)->entry), "Off"); + gtk_list_select_item(GTK_LIST(GTK_COMBO(s.det_antialias)->list), 0); + break; + case 2: + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(s.det_antialias)->entry), "2x"); + gtk_list_select_item(GTK_LIST(GTK_COMBO(s.det_antialias)->list), 1); + break; + case 4: + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(s.det_antialias)->entry), "4x"); + gtk_list_select_item(GTK_LIST(GTK_COMBO(s.det_antialias)->list), 2); + break; + case 8: + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(s.det_antialias)->entry), "8x"); + gtk_list_select_item(GTK_LIST(GTK_COMBO(s.det_antialias)->list), 3); + break; + } gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s.draw_grid), (opts->nSnap & LC_DRAW_GRID) ? TRUE : FALSE); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(s.draw_axis), (opts->nSnap & LC_DRAW_AXIS) ? TRUE : FALSE); @@ -1864,12 +1912,15 @@ int preferencesdlg_execute(void* param) opts->nMouse = TempOpts.nMouse; opts->nDetail = TempOpts.nDetail; opts->fLineWidth = TempOpts.fLineWidth; + opts->AASamples = TempOpts.AASamples; opts->nSnap = TempOpts.nSnap; opts->nAngleSnap = TempOpts.nAngleSnap; opts->nGridSize = TempOpts.nGridSize; opts->nScene = TempOpts.nScene; opts->fDensity = TempOpts.fDensity; strcpy(opts->strBackground, TempOpts.strBackground); + + Sys_ProfileSaveInt("Default", "AASamples", opts->AASamples); } else ret = LC_CANCEL; diff --git a/linux/glwindow.cpp b/linux/glwindow.cpp index 9ad9300b..5c926265 100644 --- a/linux/glwindow.cpp +++ b/linux/glwindow.cpp @@ -5,41 +5,45 @@ #include #include #include +#include "lc_global.h" #include "opengl.h" #include "glwindow.h" +#include "defines.h" +#include "system.h" -typedef struct +struct GLWindowPrivate { - GtkWidget *widget; - Display* xdisplay; - GLXContext context; -} GLWindowPrivate; + GtkWidget *widget; + Display* xdisplay; + GLXContext context; + bool Multisample; +}; // ============================================================================= // static functions -static gint realize_event (GtkWidget *widget, gpointer data) +static gint realize_event(GtkWidget *widget, gpointer data) { - GLWindow *wnd = (GLWindow*)data; + GLWindow *wnd = (GLWindow*)data; - wnd->OnInitialUpdate (); - - return TRUE; + wnd->OnInitialUpdate(); + + return TRUE; } -static gint expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data) +static gint expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { - GLWindow *wnd = (GLWindow*)data; + GLWindow *wnd = (GLWindow*)data; - if (event->count > 0) - return TRUE; + if (event->count > 0) + return TRUE; - wnd->OnDraw (); + wnd->OnDraw(); - return TRUE; + return TRUE; } -static gint button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data) +static gint button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) { GLWindow *wnd = (GLWindow*)data; int x, y; @@ -131,144 +135,166 @@ static void destroy_event (GtkWidget *widget, gpointer data) wnd->DestroyContext (); } */ + +void GL_InitializeExtensions() +{ +} + // ============================================================================= // GLWindow class -GLWindow::GLWindow (GLWindow *share) +GLWindow::GLWindow(GLWindow *share) { - m_pShare = share; - m_pData = g_malloc (sizeof (GLWindowPrivate)); + m_pShare = share; + m_pData = g_malloc(sizeof(GLWindowPrivate)); + memset(m_pData, 0, sizeof(GLWindowPrivate)); } -GLWindow::~GLWindow () +GLWindow::~GLWindow() { - DestroyContext (); - g_free (m_pData); + DestroyContext(); + g_free(m_pData); } bool GLWindow::CreateFromWindow (void *data) { - int attrlist[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, 0 }; - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - Display *dpy = GDK_DISPLAY(); - GdkVisual *visual; - XVisualInfo *vi; + int attrlist[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, 0 }; + GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; + Display *dpy = GDK_DISPLAY(); + GdkVisual *visual; + XVisualInfo *vi = NULL; - // choose visual - visual = gdk_visual_get_system (); - if (visual->depth < 16) - printf ("OpenGL fatal error: LeoCAD needs a display with at least 16 bit colors.\n"); + // choose visual + visual = gdk_visual_get_system(); + if (visual->depth < 16) + printf("OpenGL fatal error: LeoCAD needs a display with at least 16 bit colors.\n"); - if (dpy == NULL) - { - printf ("OpenGL fatal error: Cannot get display.\n"); - return false; - } - prv->xdisplay = dpy; + if (dpy == NULL) + { + printf("OpenGL fatal error: Cannot get display.\n"); + return false; + } + prv->xdisplay = dpy; - vi = pfnglXChooseVisual (dpy, DefaultScreen (dpy), attrlist); - if (vi == NULL) - { - printf ("OpenGL fatal error: glXChooseVisual failed.\n"); - return false; - } + int AASamples = Sys_ProfileLoadInt("Default", "AASamples", 1); - visual = gdkx_visual_get (vi->visualid); - if (visual == NULL) - { - printf ("OpenGL fatal error: Cannot get visual.\n"); - return false; - } + if (AASamples > 1) + { + int attrlistAA[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 16, GLX_SAMPLE_BUFFERS_ARB, 1, GLX_SAMPLES_ARB, AASamples, 0 }; + vi = pfnglXChooseVisual(dpy, DefaultScreen(dpy), attrlistAA); - gtk_widget_push_colormap (gdk_colormap_new (visual, TRUE)); - gtk_widget_push_visual (visual); + if (vi) + prv->Multisample = true; + else + printf("OpenGL error: Could not find multisample visual.\n"); + } - prv->widget = gtk_drawing_area_new (); - gtk_widget_set_double_buffered(GTK_WIDGET(prv->widget), FALSE); + if (!vi) + { + vi = pfnglXChooseVisual(dpy, DefaultScreen(dpy), attrlist); + if (vi == NULL) + { + printf("OpenGL fatal error: glXChooseVisual failed.\n"); + return false; + } + } - if (m_pShare == NULL) - prv->context = pfnglXCreateContext (dpy, vi, NULL, True); - else - { - GLWindowPrivate *share = (GLWindowPrivate*)m_pShare->m_pData; + visual = gdkx_visual_get(vi->visualid); + if (visual == NULL) + { + printf("OpenGL fatal error: Cannot get visual.\n"); + return false; + } - prv->context = pfnglXCreateContext (dpy, vi, share->context, True); - } + gtk_widget_push_colormap(gdk_colormap_new(visual, TRUE)); + gtk_widget_push_visual(visual); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); + prv->widget = gtk_drawing_area_new(); + gtk_widget_set_double_buffered(GTK_WIDGET(prv->widget), FALSE); - XFree (vi); + if (m_pShare == NULL) + prv->context = pfnglXCreateContext(dpy, vi, NULL, True); + else + { + GLWindowPrivate *share = (GLWindowPrivate*)m_pShare->m_pData; - GTK_WIDGET_SET_FLAGS (prv->widget, GTK_CAN_FOCUS); + prv->context = pfnglXCreateContext(dpy, vi, share->context, True); + } - gtk_widget_set_events (GTK_WIDGET (prv->widget), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); + gtk_widget_pop_visual(); + gtk_widget_pop_colormap(); - // Connect signal handlers - gtk_signal_connect (GTK_OBJECT (prv->widget), "expose_event", - GTK_SIGNAL_FUNC (expose_event), this); - // gtk_signal_connect (GTK_OBJECT (prv->widget), "destroy", - // GTK_SIGNAL_FUNC (destroy_event), this); - gtk_signal_connect (GTK_OBJECT (prv->widget), "size_allocate", - GTK_SIGNAL_FUNC (size_allocate_event), this); - gtk_signal_connect (GTK_OBJECT (prv->widget), "motion_notify_event", - GTK_SIGNAL_FUNC (pointer_motion_event), this); - gtk_signal_connect (GTK_OBJECT (prv->widget), "button_press_event", - GTK_SIGNAL_FUNC (button_press_event), this); - gtk_signal_connect (GTK_OBJECT (prv->widget), "button_release_event", - GTK_SIGNAL_FUNC (button_release_event), this); - gtk_signal_connect (GTK_OBJECT (prv->widget), "realize", - GTK_SIGNAL_FUNC (realize_event), this); + XFree(vi); - *((GtkWidget**)data) = prv->widget; + GTK_WIDGET_SET_FLAGS(prv->widget, GTK_CAN_FOCUS); - return true; + gtk_widget_set_events(GTK_WIDGET(prv->widget), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); + + // Connect signal handlers + gtk_signal_connect(GTK_OBJECT(prv->widget), "expose_event", GTK_SIGNAL_FUNC(expose_event), this); +// gtk_signal_connect(GTK_OBJECT(prv->widget), "destroy", GTK_SIGNAL_FUNC(destroy_event), this); + gtk_signal_connect(GTK_OBJECT(prv->widget), "size_allocate", GTK_SIGNAL_FUNC(size_allocate_event), this); + gtk_signal_connect(GTK_OBJECT(prv->widget), "motion_notify_event", GTK_SIGNAL_FUNC(pointer_motion_event), this); + gtk_signal_connect(GTK_OBJECT(prv->widget), "button_press_event", GTK_SIGNAL_FUNC(button_press_event), this); + gtk_signal_connect(GTK_OBJECT(prv->widget), "button_release_event", GTK_SIGNAL_FUNC(button_release_event), this); + gtk_signal_connect(GTK_OBJECT(prv->widget), "realize", GTK_SIGNAL_FUNC(realize_event), this); + + *((GtkWidget**)data) = prv->widget; + + return true; } -void GLWindow::DestroyContext () +void GLWindow::DestroyContext() +{ + GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; + + if (prv->context == pfnglXGetCurrentContext()) + pfnglXMakeCurrent(prv->xdisplay, None, NULL); + + if (prv->context) + pfnglXDestroyContext(prv->xdisplay, prv->context); + + prv->context = NULL; +} + +void GLWindow::OnInitialUpdate() +{ + GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; + + MakeCurrent(); + + GL_InitializeSharedExtensions(); +// GL_InitializeExtensions(); + + if (prv->Multisample) + glEnable(GL_MULTISAMPLE_ARB); +} + +bool GLWindow::MakeCurrent() +{ + GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; + gboolean ret = false; + + if (prv->context) + ret = pfnglXMakeCurrent(prv->xdisplay, GDK_WINDOW_XWINDOW(prv->widget->window), prv->context); + + return ret; +} + +void GLWindow::SwapBuffers() +{ + GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; + + if (prv->context) + pfnglXSwapBuffers(GDK_WINDOW_XDISPLAY(prv->widget->window), GDK_WINDOW_XWINDOW(prv->widget->window)); +} + +void GLWindow::Redraw(bool ForceRedraw) { GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - if (prv->context == pfnglXGetCurrentContext ()) - pfnglXMakeCurrent (prv->xdisplay, None, NULL); - - if (prv->context) - pfnglXDestroyContext (prv->xdisplay, prv->context); - - prv->context = NULL; -} - -void GLWindow::OnInitialUpdate () -{ - MakeCurrent (); - GL_InitializeExtensions (); -} - -bool GLWindow::MakeCurrent () -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - gboolean ret = false; - - if (prv->context) - ret = pfnglXMakeCurrent (prv->xdisplay, GDK_WINDOW_XWINDOW (prv->widget->window), prv->context); - - return ret; -} - -void GLWindow::SwapBuffers () -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - if (prv->context) - pfnglXSwapBuffers (GDK_WINDOW_XDISPLAY (prv->widget->window), GDK_WINDOW_XWINDOW (prv->widget->window)); -} - -void GLWindow::Redraw (bool ForceRedraw) -{ - GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; - - gtk_widget_draw (prv->widget, (GdkRectangle*)NULL); + gtk_widget_draw(prv->widget, (GdkRectangle*)NULL); } void GLWindow::CaptureMouse() @@ -278,3 +304,4 @@ void GLWindow::CaptureMouse() void GLWindow::ReleaseMouse() { } + diff --git a/win/glwindow.cpp b/win/glwindow.cpp index 404edc48..4b7094ff 100644 --- a/win/glwindow.cpp +++ b/win/glwindow.cpp @@ -407,9 +407,6 @@ bool GLWindow::CreateFromWindow(void* data) wglShareLists(share->m_hrc, prv->m_hrc); } - if (prv->Multisample) - glEnable(GL_MULTISAMPLE_ARB); - return true; } @@ -491,7 +488,12 @@ void GLWindow::DestroyContext() void GLWindow::OnInitialUpdate() { + GLWindowPrivate *prv = (GLWindowPrivate*)m_pData; + MakeCurrent(); + + if (prv->Multisample) + glEnable(GL_MULTISAMPLE_ARB); } bool GLWindow::MakeCurrent()