summaryrefslogtreecommitdiff
path: root/dgl/src/pugl
diff options
context:
space:
mode:
Diffstat (limited to 'dgl/src/pugl')
-rw-r--r--dgl/src/pugl/pugl.h76
-rw-r--r--dgl/src/pugl/pugl_internal.h4
-rw-r--r--dgl/src/pugl/pugl_osx.m22
-rw-r--r--dgl/src/pugl/pugl_win.cpp40
-rw-r--r--dgl/src/pugl/pugl_x11.c46
5 files changed, 91 insertions, 97 deletions
diff --git a/dgl/src/pugl/pugl.h b/dgl/src/pugl/pugl.h
index 898ef056..20a38140 100644
--- a/dgl/src/pugl/pugl.h
+++ b/dgl/src/pugl/pugl.h
@@ -30,19 +30,13 @@
platforms so they are included here to allow for pure portable programs.
*/
#ifdef __APPLE__
-# include "OpenGL/gl.h"
+# include <OpenGL/gl.h>
#else
# ifdef _WIN32
# include <winsock2.h>
# include <windows.h> /* Broken Windows GL headers require this */
# endif
-# include "GL/gl.h"
-#endif
-
-#ifdef _WIN32
-# define PUGL_API
-#else
-# define PUGL_API __attribute__((visibility("hidden")))
+# include <GL/gl.h>
#endif
#ifdef __cplusplus
@@ -238,31 +232,31 @@ typedef void (*PuglFileSelectedFunc)(PuglView* view, const char* filename);
To create a window, call the various puglInit* functions as necessary, then
call puglCreateWindow().
*/
-PUGL_API PuglView*
+PuglView*
puglInit(void);
/**
Set the parent window before creating a window (for embedding).
*/
-PUGL_API void
+void
puglInitWindowParent(PuglView* view, PuglNativeWindow parent);
/**
Set the window size before creating a window.
*/
-PUGL_API void
+void
puglInitWindowSize(PuglView* view, int width, int height);
/**
Set the minimum window size before creating a window.
*/
-PUGL_API void
+void
puglInitWindowMinSize(PuglView* view, int width, int height);
/**
Enable or disable resizing before creating a window.
*/
-PUGL_API void
+void
puglInitUserResizable(PuglView* view, bool resizable);
/**
@@ -271,7 +265,7 @@ puglInitUserResizable(PuglView* view, bool resizable);
On X11, parent_id must be a Window.
On OSX, parent_id must be an NSView*.
*/
-PUGL_API void
+void
puglInitTransientFor(PuglView* view, uintptr_t parent);
/**
@@ -289,7 +283,7 @@ puglInitTransientFor(PuglView* view, uintptr_t parent);
@return 1 (pugl does not currently support multiple windows).
*/
-PUGL_API int
+int
puglCreateWindow(PuglView* view, const char* title);
/**
@@ -300,7 +294,7 @@ puglCreateWindow(PuglView* view, const char* title);
@param height Window height in pixels.
@param resizable Whether window should be user resizable.
*/
-PUGL_API PuglView*
+PuglView*
puglCreate(PuglNativeWindow parent,
const char* title,
int min_width,
@@ -313,19 +307,19 @@ puglCreate(PuglNativeWindow parent,
/**
Show Window (external ui)
*/
-PUGL_API void
+void
puglShowWindow(PuglView* view);
/**
Hide Window (external ui)
*/
-PUGL_API void
+void
puglHideWindow(PuglView* view);
/**
Return the native window handle.
*/
-PUGL_API PuglNativeWindow
+PuglNativeWindow
puglGetNativeWindow(PuglView* view);
/**
@@ -341,13 +335,13 @@ puglGetNativeWindow(PuglView* view);
Note the lack of this facility makes GLUT unsuitable for plugins or
non-trivial programs; this mistake is largely why Pugl exists.
*/
-PUGL_API void
+void
puglSetHandle(PuglView* view, PuglHandle handle);
/**
Get the handle to be passed to all callbacks.
*/
-PUGL_API PuglHandle
+PuglHandle
puglGetHandle(PuglView* view);
/**
@@ -355,13 +349,13 @@ puglGetHandle(PuglView* view);
For Cairo contexts, this returns a pointer to a cairo_t.
For everything else, this is unused and returns NULL.
*/
-PUGL_API void*
+void*
puglGetContext(PuglView* view);
/**
Return the timestamp (if any) of the currently-processing event.
*/
-PUGL_API uint32_t
+uint32_t
puglGetEventTimestamp(PuglView* view);
/**
@@ -369,13 +363,13 @@ puglGetEventTimestamp(PuglView* view);
This should only be called from an event handler.
*/
-PUGL_API int
+int
puglGetModifiers(PuglView* view);
/**
Ignore synthetic repeated key events.
*/
-PUGL_API void
+void
puglIgnoreKeyRepeat(PuglView* view, bool ignore);
/**
@@ -387,61 +381,61 @@ puglIgnoreKeyRepeat(PuglView* view, bool ignore);
/**
Set the function to call when the window is closed.
*/
-PUGL_API void
+void
puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc);
/**
Set the display function which should draw the UI using GL.
*/
-PUGL_API void
+void
puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc);
/**
Set the function to call on keyboard events.
*/
-PUGL_API void
+void
puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc);
/**
Set the function to call on mouse motion.
*/
-PUGL_API void
+void
puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc);
/**
Set the function to call on mouse button events.
*/
-PUGL_API void
+void
puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc);
/**
Set the function to call on scroll events.
*/
-PUGL_API void
+void
puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc);
/**
Set the function to call on special events.
*/
-PUGL_API void
+void
puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc);
/**
Set the function to call when the window size changes.
*/
-PUGL_API void
+void
puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc);
/**
Set callback function to change window size.
*/
-PUGL_API void
+void
puglSetResizeFunc(PuglView* view, PuglResizeFunc resizeFunc);
/**
Set the function to call on file-browser selections.
*/
-PUGL_API void
+void
puglSetFileSelectedFunc(PuglView* view, PuglFileSelectedFunc fileSelectedFunc);
/**
@@ -451,13 +445,13 @@ puglSetFileSelectedFunc(PuglView* view, PuglFileSelectedFunc fileSelectedFunc);
/**
TODO document this.
*/
-PUGL_API int
+int
puglUpdateGeometryConstraints(PuglView* view, int min_width, int min_height, bool aspect);
/**
Grab the input focus.
*/
-PUGL_API void
+void
puglGrabFocus(PuglView* view);
/**
@@ -466,25 +460,25 @@ puglGrabFocus(PuglView* view);
This handles input events as well as rendering, so it should be called
regularly and rapidly enough to keep the UI responsive.
*/
-PUGL_API PuglStatus
+PuglStatus
puglProcessEvents(PuglView* view);
/**
Request a redisplay on the next call to puglProcessEvents().
*/
-PUGL_API void
+void
puglPostRedisplay(PuglView* view);
/**
Request a resize on the next call to puglProcessEvents().
*/
-PUGL_API void
+void
puglPostResize(PuglView* view);
/**
Destroy a GL window.
*/
-PUGL_API void
+void
puglDestroy(PuglView* view);
/**
diff --git a/dgl/src/pugl/pugl_internal.h b/dgl/src/pugl/pugl_internal.h
index 0a353275..609c97b9 100644
--- a/dgl/src/pugl/pugl_internal.h
+++ b/dgl/src/pugl/pugl_internal.h
@@ -240,7 +240,7 @@ puglLeaveContext(PuglView* view, bool flush);
static void
puglDefaultReshape(int width, int height)
{
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
#ifdef ROBTK_HERE
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
@@ -259,5 +259,5 @@ puglDefaultReshape(int width, int height)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
#endif
-#endif
+#endif // PUGL_OPENGL
}
diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m
index 18191628..80b99304 100644
--- a/dgl/src/pugl/pugl_osx.m
+++ b/dgl/src/pugl/pugl_osx.m
@@ -21,11 +21,11 @@
#include <stdlib.h>
-#import <Cocoa/Cocoa.h>
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
#import <cairo.h>
#import <cairo-quartz.h>
#endif
+#import <Cocoa/Cocoa.h>
#include "pugl_internal.h"
@@ -290,7 +290,7 @@ flagsChanged(NSView<PuglGenericView> *self, NSEvent *event)
}
}
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
@interface PuglOpenGLView : NSOpenGLView<PuglGenericView>
{
@public
@@ -530,7 +530,7 @@ flagsChanged(NSView<PuglGenericView> *self, NSEvent *event)
@end
#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
@interface PuglCairoView : NSView<PuglGenericView>
{
PuglView* puglview;
@@ -755,10 +755,10 @@ flagsChanged(NSView<PuglGenericView> *self, NSEvent *event)
struct PuglInternalsImpl {
union {
NSView<PuglGenericView>* view;
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
PuglOpenGLView* glview;
#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
PuglCairoView* cairoview;
#endif
};
@@ -774,7 +774,7 @@ puglInitInternals()
void
puglEnterContext(PuglView* view)
{
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
[[view->impl->glview openGLContext] makeCurrentContext];
#endif
}
@@ -783,7 +783,7 @@ void
puglLeaveContext(PuglView* view, bool flush)
{
if (flush) {
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
if (view->impl->glview->doubleBuffered) {
[[view->impl->glview openGLContext] flushBuffer];
} else {
@@ -802,10 +802,10 @@ puglCreateWindow(PuglView* view, const char* title)
[NSAutoreleasePool new];
[NSApplication sharedApplication];
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
impl->glview = [PuglOpenGLView new];
#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
impl->cairoview = [PuglCairoView new];
#endif
@@ -919,7 +919,7 @@ puglGetNativeWindow(PuglView* view)
void*
puglGetContext(PuglView* view)
{
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
return [view->impl->cairoview cairoContext];
#endif
return NULL;
diff --git a/dgl/src/pugl/pugl_win.cpp b/dgl/src/pugl/pugl_win.cpp
index 445820bd..d8b3866d 100644
--- a/dgl/src/pugl/pugl_win.cpp
+++ b/dgl/src/pugl/pugl_win.cpp
@@ -19,22 +19,22 @@
@file pugl_win.cpp Windows/WGL Pugl Implementation.
*/
+#include <ctime>
+#include <cstdio>
+#include <cstdlib>
+
#include <winsock2.h>
#include <windows.h>
#include <windowsx.h>
-#ifdef PUGL_HAVE_GL
-#include <GL/gl.h>
-#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
#include <cairo/cairo.h>
#include <cairo/cairo-win32.h>
#endif
+#ifdef PUGL_OPENGL
+#include <GL/gl.h>
+#endif
-#include <ctime>
-#include <cstdio>
-#include <cstdlib>
-
-#include "pugl/pugl_internal.h"
+#include "pugl_internal.h"
#ifndef WM_MOUSEWHEEL
# define WM_MOUSEWHEEL 0x020A
@@ -55,11 +55,11 @@ HINSTANCE hInstance = NULL;
struct PuglInternalsImpl {
HWND hwnd;
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
HDC hdc;
HGLRC hglrc;
#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_t* buffer_cr;
cairo_surface_t* buffer_surface;
#endif
@@ -90,7 +90,7 @@ puglInitInternals()
void
puglEnterContext(PuglView* view)
{
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
wglMakeCurrent(view->impl->hdc, view->impl->hglrc);
#endif
}
@@ -98,7 +98,7 @@ puglEnterContext(PuglView* view)
void
puglLeaveContext(PuglView* view, bool flush)
{
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
if (flush) {
glFlush();
SwapBuffers(view->impl->hdc);
@@ -177,7 +177,7 @@ puglCreateWindow(PuglView* view, const char* title)
SetWindowLongPtr(impl->hwnd, GWLP_USERDATA, (LONG_PTR)view);
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
impl->hdc = GetDC(impl->hwnd);
PIXELFORMATDESCRIPTOR pfd;
@@ -228,12 +228,12 @@ puglDestroy(PuglView* view)
PuglInternals* const impl = view->impl;
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
wglMakeCurrent(NULL, NULL);
wglDeleteContext(impl->hglrc);
ReleaseDC(impl->hwnd, impl->hdc);
#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_destroy(impl->buffer_cr);
cairo_surface_destroy(impl->buffer_surface);
#endif
@@ -267,7 +267,7 @@ puglDisplay(PuglView* view)
puglEnterContext(view);
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_t *wc = NULL;
cairo_t *bc = NULL;
cairo_surface_t *ws = NULL;
@@ -298,7 +298,7 @@ puglDisplay(PuglView* view)
if (view->displayFunc) {
view->displayFunc(view);
}
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_set_source_surface(wc, bs, 0, 0);
cairo_paint(wc);
#endif
@@ -306,7 +306,7 @@ puglDisplay(PuglView* view)
puglLeaveContext(view, success);
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_destroy(wc);
cairo_surface_destroy(ws);
#endif
@@ -545,7 +545,7 @@ puglGetNativeWindow(PuglView* view)
void*
puglGetContext(PuglView* view)
{
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
return view->impl->buffer_cr;
#endif
return NULL;
diff --git a/dgl/src/pugl/pugl_x11.c b/dgl/src/pugl/pugl_x11.c
index 44202830..3146cfcc 100644
--- a/dgl/src/pugl/pugl_x11.c
+++ b/dgl/src/pugl/pugl_x11.c
@@ -25,14 +25,14 @@
#include <stdlib.h>
#include <string.h>
-#ifdef PUGL_HAVE_GL
-#include <GL/gl.h>
-#include <GL/glx.h>
-#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
#include <cairo/cairo.h>
#include <cairo/cairo-xlib.h>
#endif
+#ifdef PUGL_OPENGL
+#include <GL/gl.h>
+#include <GL/glx.h>
+#endif
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -60,19 +60,19 @@ struct PuglInternalsImpl {
Display* display;
int screen;
Window win;
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_t* xlib_cr;
cairo_t* buffer_cr;
cairo_surface_t* xlib_surface;
cairo_surface_t* buffer_surface;
#endif
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
GLXContext ctx;
Bool doubleBuffered;
#endif
};
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
/**
Attributes for single-buffered RGBA with at least
4 bits per color and a 16 bit depth buffer.
@@ -129,7 +129,7 @@ puglInitInternals(void)
void
puglEnterContext(PuglView* view)
{
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
glXMakeCurrent(view->impl->display, view->impl->win, view->impl->ctx);
#endif
}
@@ -137,7 +137,7 @@ puglEnterContext(PuglView* view)
void
puglLeaveContext(PuglView* view, bool flush)
{
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
if (flush) {
glFlush();
if (view->impl->doubleBuffered) {
@@ -166,7 +166,7 @@ puglCreateWindow(PuglView* view, const char* title)
XVisualInfo* vi = NULL;
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
impl->doubleBuffered = True;
vi = glXChooseVisual(impl->display, impl->screen, attrListDblMS);
@@ -182,7 +182,7 @@ puglCreateWindow(PuglView* view, const char* title)
impl->doubleBuffered = False;
}
#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
XVisualInfo pat;
int n;
pat.screen = impl->screen;
@@ -196,14 +196,14 @@ puglCreateWindow(PuglView* view, const char* title)
}
#ifdef PUGL_VERBOSE
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
int glxMajor, glxMinor;
glXQueryVersion(impl->display, &glxMajor, &glxMinor);
printf("puGL: GLX-Version : %d.%d\n", glxMajor, glxMinor);
#endif
#endif
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
impl->ctx = glXCreateContext(impl->display, vi, 0, GL_TRUE);
if (!impl->ctx) {
@@ -237,7 +237,7 @@ puglCreateWindow(PuglView* view, const char* title)
CWBorderPixel | CWColormap | CWEventMask, &attr);
if (!impl->win) {
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
glXDestroyContext(impl->display, impl->ctx);
#endif
XFree(vi);
@@ -246,7 +246,7 @@ puglCreateWindow(PuglView* view, const char* title)
return 1;
}
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
impl->xlib_surface = cairo_xlib_surface_create(
impl->display, impl->win, vi->visual, view->width, view->height);
if (impl->xlib_surface == NULL || cairo_surface_status(impl->xlib_surface) != CAIRO_STATUS_SUCCESS) {
@@ -288,7 +288,7 @@ puglCreateWindow(PuglView* view, const char* title)
}
#ifdef PUGL_VERBOSE
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
if (glXIsDirect(impl->display, impl->ctx)) {
printf("puGL: DRI enabled (to disable, set LIBGL_ALWAYS_INDIRECT=1\n");
} else {
@@ -314,10 +314,10 @@ puglDestroy(PuglView* view)
x_fib_close(impl->display);
#endif
-#ifdef PUGL_HAVE_GL
+#ifdef PUGL_OPENGL
glXDestroyContext(impl->display, impl->ctx);
#endif
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_destroy(impl->xlib_cr);
cairo_destroy(impl->buffer_cr);
cairo_surface_destroy(impl->xlib_surface);
@@ -365,7 +365,7 @@ puglDisplay(PuglView* view)
puglEnterContext(view);
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_t* bc = impl->buffer_cr;
cairo_surface_t* xs = impl->xlib_surface;
cairo_surface_t* bs = impl->buffer_surface;
@@ -394,7 +394,7 @@ puglDisplay(PuglView* view)
view->displayFunc(view);
}
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
cairo_t* xc = impl->xlib_cr;
cairo_set_source_surface(xc, impl->buffer_surface, 0, 0);
cairo_paint(xc);
@@ -661,7 +661,7 @@ puglProcessEvents(PuglView* view)
}
if (conf_width != -1) {
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
// Resize surfaces/contexts before dispatching
view->redisplay = true;
cairo_xlib_surface_set_size(view->impl->xlib_surface,
@@ -702,7 +702,7 @@ puglGetNativeWindow(PuglView* view)
void*
puglGetContext(PuglView* view)
{
-#ifdef PUGL_HAVE_CAIRO
+#ifdef PUGL_CAIRO
return view->impl->buffer_cr;
#endif
return NULL;