aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
Diffstat (limited to 'pugl')
-rw-r--r--pugl/pugl.h25
-rw-r--r--pugl/pugl.hpp4
-rw-r--r--pugl/pugl_cairo_backend.h11
-rw-r--r--pugl/pugl_gl_backend.h11
-rw-r--r--pugl/pugl_internal.h20
-rw-r--r--pugl/pugl_internal_types.h1
-rw-r--r--pugl/pugl_osx.m7
-rw-r--r--pugl/pugl_win.c18
-rw-r--r--pugl/pugl_x11.c18
-rw-r--r--pugl/pugl_x11_cairo.c3
10 files changed, 43 insertions, 75 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h
index b88392b..7e6036f 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -94,14 +94,6 @@ typedef enum {
} PuglStatus;
/**
- Drawing context type.
-*/
-typedef enum {
- PUGL_GL = 1 << 0, /**< OpenGL (3D) */
- PUGL_CAIRO = 1 << 1 /**< Cairo (2D) */
-} PuglContextType;
-
-/**
Window hint.
*/
typedef enum {
@@ -503,10 +495,15 @@ PUGL_API void
puglInitTransientFor(PuglView* view, uintptr_t parent);
/**
- Set the context type before creating a window.
+ Set the graphics backend to use.
+
+ This needs to be called once before creating the window to set the graphics
+ backend. There are two backend accessors included with pugl:
+ puglGlBackend() and puglCairoBackend(), declared in pugl_gl_backend.h and
+ pugl_cairo_backend.h, respectively.
*/
-PUGL_API void
-puglInitContextType(PuglView* view, PuglContextType type);
+PUGL_API int
+puglInitBackend(PuglView* view, const PuglBackend* backend);
/**
@}
@@ -581,8 +578,10 @@ puglGetSize(PuglView* view, int* width, int* height);
/**
Get the drawing context.
- For PUGL_GL contexts, this is unused and returns NULL.
- For PUGL_CAIRO contexts, this returns a pointer to a cairo_t.
+ The context is only guaranteed to be available during an expose.
+
+ For OpenGL backends, this is unused and returns NULL.
+ For Cairo backends, this returns a pointer to a `cairo_t`.
*/
PUGL_API void*
puglGetContext(PuglView* view);
diff --git a/pugl/pugl.hpp b/pugl/pugl.hpp
index 0646d28..d2702ab 100644
--- a/pugl/pugl.hpp
+++ b/pugl/pugl.hpp
@@ -66,8 +66,8 @@ public:
puglInitTransientFor(_view, parent);
}
- virtual void initContextType(PuglContextType type) {
- puglInitContextType(_view, type);
+ virtual void initBackend(const PuglBackend* backend) {
+ puglInitBackend(_view, backend);
}
virtual void createWindow(const char* title) {
diff --git a/pugl/pugl_cairo_backend.h b/pugl/pugl_cairo_backend.h
index b48915e..3330c08 100644
--- a/pugl/pugl_cairo_backend.h
+++ b/pugl/pugl_cairo_backend.h
@@ -14,15 +14,24 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/**
+ @file pugl_cairo_backend.h Declaration of Cairo backend accessor.
+*/
+
#ifndef PUGL_CAIRO_BACKEND_H
#define PUGL_CAIRO_BACKEND_H
-#include "pugl/pugl_internal_types.h"
+#include "pugl/pugl.h"
#ifdef __cplusplus
extern "C" {
#endif
+/**
+ Cairo graphics backend accessor.
+
+ Pass the return value to puglInitBackend() to draw to a view with Cairo.
+*/
PUGL_API const PuglBackend*
puglCairoBackend(void);
diff --git a/pugl/pugl_gl_backend.h b/pugl/pugl_gl_backend.h
index 11f4e4b..5913b95 100644
--- a/pugl/pugl_gl_backend.h
+++ b/pugl/pugl_gl_backend.h
@@ -14,15 +14,24 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/**
+ @file pugl_gl_backend.h Declaration of OpenGL backend accessor.
+*/
+
#ifndef PUGL_GL_BACKEND_H
#define PUGL_GL_BACKEND_H
-#include "pugl/pugl_internal_types.h"
+#include "pugl/pugl.h"
#ifdef __cplusplus
extern "C" {
#endif
+/**
+ OpenGL graphics backend.
+
+ Pass the return value to puglInitBackend() to draw to a view with OpenGL.
+*/
PUGL_API const PuglBackend*
puglGlBackend(void);
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h
index 312329d..1f4cd4d 100644
--- a/pugl/pugl_internal.h
+++ b/pugl/pugl_internal.h
@@ -17,15 +17,9 @@
/**
@file pugl_internal.h Private platform-independent definitions.
- Note this file contains function definitions, so it must be compiled into
- the final binary exactly once. Each platform specific implementation file
- including it once should achieve this.
-
- If you are copying the pugl code into your source tree, the following
- symbols can be defined to tweak pugl behaviour:
-
- PUGL_HAVE_CAIRO: Include Cairo support code.
- PUGL_HAVE_GL: Include OpenGL support code.
+ Note that this file contains function definitions, so it must be compiled
+ into the final binary exactly once. Each platform specific implementation
+ file including it once should achieve this.
*/
#include "pugl/pugl.h"
@@ -59,7 +53,6 @@ puglInit(int* PUGL_UNUSED(pargc), char** PUGL_UNUSED(argv))
}
view->hints = puglDefaultHints();
- view->ctx_type = PUGL_GL;
view->impl = impl;
view->width = 640;
view->height = 480;
@@ -166,10 +159,11 @@ puglInitTransientFor(PuglView* view, uintptr_t parent)
view->transient_parent = parent;
}
-void
-puglInitContextType(PuglView* view, PuglContextType type)
+int
+puglInitBackend(PuglView* view, const PuglBackend* backend)
{
- view->ctx_type = type;
+ view->backend = backend;
+ return 0;
}
void
diff --git a/pugl/pugl_internal_types.h b/pugl/pugl_internal_types.h
index 5f81f97..9a0bedc 100644
--- a/pugl/pugl_internal_types.h
+++ b/pugl/pugl_internal_types.h
@@ -63,7 +63,6 @@ struct PuglViewImpl {
PuglNativeWindow parent;
double start_time;
uintptr_t transient_parent;
- PuglContextType ctx_type;
PuglHints hints;
int width;
int height;
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m
index 30eb84d..6ddb24d 100644
--- a/pugl/pugl_osx.m
+++ b/pugl/pugl_osx.m
@@ -745,13 +745,6 @@ puglCreateWindow(PuglView* view, const char* title)
[NSAutoreleasePool new];
impl->app = [NSApplication sharedApplication];
- view->backend = puglGlBackend();
- if (view->ctx_type == PUGL_CAIRO) {
-#ifdef PUGL_HAVE_CAIRO
- view->backend = puglCairoBackend();
-#endif
- }
-
impl->glview = [PuglOpenGLView alloc];
impl->glview->trackingArea = nil;
impl->glview->markedText = [[NSMutableAttributedString alloc] init];
diff --git a/pugl/pugl_win.c b/pugl/pugl_win.c
index 799850e..b34ca43 100644
--- a/pugl/pugl_win.c
+++ b/pugl/pugl_win.c
@@ -21,13 +21,6 @@
#include "pugl/pugl_internal.h"
#include "pugl/pugl_win.h"
-#ifdef PUGL_HAVE_GL
-#include "pugl/pugl_gl_backend.h"
-#endif
-#ifdef PUGL_HAVE_CAIRO
-#include "pugl/pugl_cairo_backend.h"
-#endif
-
#include <windows.h>
#include <windowsx.h>
@@ -91,17 +84,6 @@ puglCreateWindow(PuglView* view, const char* title)
title = title ? title : "Window";
- if (view->ctx_type == PUGL_GL) {
-#ifdef PUGL_HAVE_GL
- view->backend = puglGlBackend();
-#endif
- }
- if (view->ctx_type == PUGL_CAIRO) {
-#ifdef PUGL_HAVE_CAIRO
- view->backend = puglCairoBackend();
-#endif
- }
-
// Get refresh rate for resize draw timer
DEVMODEA devMode = {0};
EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &devMode);
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index d9620e1..ad9acc8 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -25,13 +25,6 @@
#include "pugl/pugl_internal.h"
#include "pugl/pugl_x11.h"
-#ifdef PUGL_HAVE_GL
-#include "pugl/pugl_gl_backend.h"
-#endif
-#ifdef PUGL_HAVE_CAIRO
-#include "pugl/pugl_cairo_backend.h"
-#endif
-
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -83,17 +76,6 @@ puglCreateWindow(PuglView* view, const char* title)
impl->atoms.NET_WM_STATE_DEMANDS_ATTENTION =
XInternAtom(display, "_NET_WM_STATE_DEMANDS_ATTENTION", 0);
- if (view->ctx_type == PUGL_GL) {
-#ifdef PUGL_HAVE_GL
- view->backend = puglGlBackend();
-#endif
- }
- if (view->ctx_type == PUGL_CAIRO) {
-#ifdef PUGL_HAVE_CAIRO
- view->backend = puglCairoBackend();
-#endif
- }
-
if (!view->backend || !view->backend->configure) {
return 1;
} else if (view->backend->configure(view) || !impl->vi) {
diff --git a/pugl/pugl_x11_cairo.c b/pugl/pugl_x11_cairo.c
index c52b875..1a75b1c 100644
--- a/pugl/pugl_x11_cairo.c
+++ b/pugl/pugl_x11_cairo.c
@@ -118,7 +118,8 @@ puglX11CairoGetContext(PuglView* view)
return surface->cr;
}
-const PuglBackend* puglCairoBackend(void)
+const PuglBackend*
+puglCairoBackend(void)
{
static const PuglBackend backend = {
puglX11CairoConfigure,