aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/unix/area.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libui_sdl/libui/unix/area.c')
-rw-r--r--src/libui_sdl/libui/unix/area.c116
1 files changed, 103 insertions, 13 deletions
diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c
index 2da9bab..5734b4b 100644
--- a/src/libui_sdl/libui/unix/area.c
+++ b/src/libui_sdl/libui/unix/area.c
@@ -28,6 +28,8 @@ struct areaWidgetClass {
GtkDrawingAreaClass parent_class;
};
+typedef struct uiGLContext uiGLContext;
+
struct uiArea {
uiUnixControl c;
GtkWidget *widget; // either swidget or areaWidget depending on whether it is scrolling
@@ -39,6 +41,10 @@ struct uiArea {
GtkWidget *areaWidget;
GtkDrawingArea *drawingArea;
areaWidget *area;
+
+ gboolean opengl;
+ uiGLContext *glContext;
+ unsigned int* req_versions;
int bgR, bgG, bgB;
@@ -57,6 +63,21 @@ struct uiArea {
G_DEFINE_TYPE(areaWidget, areaWidget, GTK_TYPE_DRAWING_AREA)
+int boub(GtkWidget* w) { return isAreaWidget(w); }
+void baba(GtkWidget* w)
+{
+ if (!isAreaWidget(w)) return;
+
+ areaWidget *aw = areaWidget(w);
+ uiArea *a = aw->a;
+ if (!a->opengl) return;
+
+ GdkGLContext* oldctx = gdk_gl_context_get_current();
+ uiGLMakeContextCurrent(a->glContext);
+ glFinish();
+ gdk_gl_context_make_current(oldctx);
+}
+
static void areaWidget_init(areaWidget *aw)
{
// for events
@@ -133,21 +154,28 @@ static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr)
loadAreaSize(a, &(dp.AreaWidth), &(dp.AreaHeight));
- cairo_clip_extents(cr, &clipX0, &clipY0, &clipX1, &clipY1);
- dp.ClipX = clipX0;
- dp.ClipY = clipY0;
- dp.ClipWidth = clipX1 - clipX0;
- dp.ClipHeight = clipY1 - clipY0;
-
- if (a->bgR != -1)
+ if (!a->opengl)
+ {
+ cairo_clip_extents(cr, &clipX0, &clipY0, &clipX1, &clipY1);
+ dp.ClipX = clipX0;
+ dp.ClipY = clipY0;
+ dp.ClipWidth = clipX1 - clipX0;
+ dp.ClipHeight = clipY1 - clipY0;
+
+ if (a->bgR != -1)
+ {
+ cairo_set_source_rgb(cr, a->bgR/255.0, a->bgG/255.0, a->bgB/255.0);
+ cairo_paint(cr);
+ }
+
+ // no need to save or restore the graphics state to reset transformations; GTK+ does that for us
+ (*(a->ah->Draw))(a->ah, a, &dp);
+ }
+ else
{
- cairo_set_source_rgb(cr, a->bgR/255.0, a->bgG/255.0, a->bgB/255.0);
- cairo_paint(cr);
+ areaDrawGL(w, &dp, cr, a->glContext);
}
- // no need to save or restore the graphics state to reset transformations; GTK+ does that for us
- (*(a->ah->Draw))(a->ah, a, &dp);
-
freeContext(dp.Context);
return FALSE;
}
@@ -598,7 +626,15 @@ static void areaWidget_class_init(areaWidgetClass *class)
// control implementation
-uiUnixControlAllDefaults(uiArea)
+uiUnixControlAllDefaultsExceptDestroy(uiArea)
+
+static void uiAreaDestroy(uiControl *c)
+{
+ uiArea* a = uiArea(c);
+ if (a->opengl && a->glContext) freeGLContext(a->glContext);
+ g_object_unref(uiArea(c)->widget);
+ uiFreeControl(c);
+}
void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b)
{
@@ -716,6 +752,7 @@ uiArea *uiNewArea(uiAreaHandler *ah)
a->ah = ah;
a->scrolling = FALSE;
+ a->opengl = FALSE;
a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType,
"libui-area", a,
@@ -730,6 +767,58 @@ uiArea *uiNewArea(uiAreaHandler *ah)
return a;
}
+void _areaCreateGLContext(GtkWidget* widget, gpointer data)
+{
+ uiArea* a = (uiArea*)data;
+
+ uiGLContext* ctx = NULL;
+ for (int i = 0; a->req_versions[i] && !ctx; i++)
+ {
+ int major = uiGLVerMajor(a->req_versions[i]);
+ int minor = uiGLVerMinor(a->req_versions[i]);
+
+ // we cannot support any version older than 3.2 via GDK
+ if ((major < 3) || (major == 3 && minor < 2))
+ break;
+
+ ctx = createGLContext(widget, major, minor);
+ }
+
+ a->glContext = ctx;
+}
+
+uiArea *uiNewGLArea(uiAreaHandler *ah, const unsigned int* req_versions)
+{
+ uiArea *a;
+
+ uiUnixNewControl(uiArea, a);
+
+ a->ah = ah;
+ a->scrolling = FALSE;
+ a->opengl = TRUE;
+
+ a->glContext = NULL;
+ a->req_versions = req_versions;
+ a->areaWidget = GTK_WIDGET(g_object_new(areaWidgetType,
+ "libui-area", a,
+ NULL));
+ a->area = areaWidget(a->areaWidget);
+
+ a->widget = a->areaWidget;
+
+ g_signal_connect(a->widget, "realize", G_CALLBACK(_areaCreateGLContext), a);
+
+ uiAreaSetBackgroundColor(a, -1, -1, -1);
+
+ return a;
+}
+
+uiGLContext *uiAreaGetGLContext(uiArea* a)
+{
+ if (!a) return NULL;
+ return a->glContext;
+}
+
uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
{
uiArea *a;
@@ -740,6 +829,7 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
a->scrolling = TRUE;
a->scrollWidth = width;
a->scrollHeight = height;
+ a->opengl = FALSE;
a->swidget = gtk_scrolled_window_new(NULL, NULL);
a->scontainer = GTK_CONTAINER(a->swidget);