aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pugl/detail/implementation.c69
-rw-r--r--pugl/detail/mac.m4
-rw-r--r--pugl/detail/mac_cairo.m2
-rw-r--r--pugl/detail/mac_gl.m22
-rw-r--r--pugl/detail/types.h16
-rw-r--r--pugl/detail/win.c2
-rw-r--r--pugl/detail/win.h23
-rw-r--r--pugl/detail/win_gl.c26
-rw-r--r--pugl/detail/x11.c4
-rw-r--r--pugl/detail/x11_gl.c22
-rw-r--r--pugl/pugl.h2
11 files changed, 78 insertions, 114 deletions
diff --git a/pugl/detail/implementation.c b/pugl/detail/implementation.c
index 7eeba01..04b36d3 100644
--- a/pugl/detail/implementation.c
+++ b/pugl/detail/implementation.c
@@ -25,13 +25,22 @@
#include <stdlib.h>
#include <string.h>
-static PuglHints
-puglDefaultHints(void)
-{
- static const PuglHints hints = {
- 2, 0, 4, 4, 4, 4, 24, 8, 0, true, true, false, false
- };
- return hints;
+static void
+puglSetDefaultHints(PuglHints hints)
+{
+ hints[PUGL_USE_COMPAT_PROFILE] = PUGL_TRUE;
+ hints[PUGL_CONTEXT_VERSION_MAJOR] = 2;
+ hints[PUGL_CONTEXT_VERSION_MINOR] = 0;
+ hints[PUGL_RED_BITS] = 4;
+ hints[PUGL_GREEN_BITS] = 4;
+ hints[PUGL_BLUE_BITS] = 4;
+ hints[PUGL_ALPHA_BITS] = 4;
+ hints[PUGL_DEPTH_BITS] = 24;
+ hints[PUGL_STENCIL_BITS] = 8;
+ hints[PUGL_SAMPLES] = 0;
+ hints[PUGL_DOUBLE_BUFFER] = PUGL_FALSE;
+ hints[PUGL_RESIZABLE] = PUGL_FALSE;
+ hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE;
}
PuglView*
@@ -48,58 +57,20 @@ puglInit(int* PUGL_UNUSED(pargc), char** PUGL_UNUSED(argv))
return NULL;
}
- view->hints = puglDefaultHints();
view->impl = impl;
view->width = 640;
view->height = 480;
view->start_time = puglGetTime(view);
+ puglSetDefaultHints(view->hints);
return view;
}
void
puglInitWindowHint(PuglView* view, PuglWindowHint hint, int value)
{
- switch (hint) {
- case PUGL_USE_COMPAT_PROFILE:
- view->hints.use_compat_profile = value;
- break;
- case PUGL_CONTEXT_VERSION_MAJOR:
- view->hints.context_version_major = value;
- break;
- case PUGL_CONTEXT_VERSION_MINOR:
- view->hints.context_version_minor = value;
- break;
- case PUGL_RED_BITS:
- view->hints.red_bits = value;
- break;
- case PUGL_GREEN_BITS:
- view->hints.green_bits = value;
- break;
- case PUGL_BLUE_BITS:
- view->hints.blue_bits = value;
- break;
- case PUGL_ALPHA_BITS:
- view->hints.alpha_bits = value;
- break;
- case PUGL_DEPTH_BITS:
- view->hints.depth_bits = value;
- break;
- case PUGL_STENCIL_BITS:
- view->hints.stencil_bits = value;
- break;
- case PUGL_SAMPLES:
- view->hints.samples = value;
- break;
- case PUGL_DOUBLE_BUFFER:
- view->hints.double_buffer = value;
- break;
- case PUGL_RESIZABLE:
- view->hints.resizable = value;
- break;
- case PUGL_IGNORE_KEY_REPEAT:
- view->hints.ignoreKeyRepeat = value;
- break;
+ if (hint < PUGL_NUM_WINDOW_HINTS) {
+ view->hints[hint] = value;
}
}
@@ -149,7 +120,7 @@ puglInitWindowParent(PuglView* view, PuglNativeWindow parent)
void
puglInitResizable(PuglView* view, bool resizable)
{
- view->hints.resizable = resizable;
+ view->hints[PUGL_RESIZABLE] = resizable;
}
void
diff --git a/pugl/detail/mac.m b/pugl/detail/mac.m
index 36aff9b..5b332f1 100644
--- a/pugl/detail/mac.m
+++ b/pugl/detail/mac.m
@@ -330,7 +330,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type)
- (void) keyDown:(NSEvent*)event
{
- if (puglview->hints.ignoreKeyRepeat && [event isARepeat]) {
+ if (puglview->hints[PUGL_IGNORE_KEY_REPEAT] && [event isARepeat]) {
return;
}
@@ -700,7 +700,7 @@ puglCreateWindow(PuglView* view, const char* title)
unsigned style = (NSClosableWindowMask |
NSTitledWindowMask |
NSMiniaturizableWindowMask );
- if (view->hints.resizable) {
+ if (view->hints[PUGL_RESIZABLE]) {
style |= NSResizableWindowMask;
}
diff --git a/pugl/detail/mac_cairo.m b/pugl/detail/mac_cairo.m
index 1f4452f..ce03486 100644
--- a/pugl/detail/mac_cairo.m
+++ b/pugl/detail/mac_cairo.m
@@ -75,7 +75,7 @@ puglMacCairoCreate(PuglView* view)
drawView->puglview = view;
[drawView initWithFrame:NSMakeRect(0, 0, view->width, view->height)];
- if (view->hints.resizable) {
+ if (view->hints[PUGL_RESIZABLE]) {
[drawView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
} else {
[drawView setAutoresizingMask:NSViewNotSizable];
diff --git a/pugl/detail/mac_gl.m b/pugl/detail/mac_gl.m
index 6cdf6f6..1392989 100644
--- a/pugl/detail/mac_gl.m
+++ b/pugl/detail/mac_gl.m
@@ -40,12 +40,14 @@ typedef NSUInteger NSWindowStyleMask;
- (id) initWithFrame:(NSRect)frame
{
- const int major = puglview->hints.context_version_major;
- const int profile = ((puglview->hints.use_compat_profile || major < 3)
- ? NSOpenGLProfileVersionLegacy
- : puglview->hints.context_version_major >= 4
- ? NSOpenGLProfileVersion4_1Core
- : NSOpenGLProfileVersion3_2Core);
+ const bool compat = puglview->hints[PUGL_USE_COMPAT_PROFILE];
+ const int samples = puglview->hints[PUGL_SAMPLES];
+ const int major = puglview->hints[PUGL_CONTEXT_VERSION_MAJOR];
+ const int profile = ((compat || major < 3)
+ ? NSOpenGLProfileVersionLegacy
+ : (major >= 4
+ ? NSOpenGLProfileVersion4_1Core
+ : NSOpenGLProfileVersion3_2Core));
NSOpenGLPixelFormatAttribute pixelAttribs[16] = {
NSOpenGLPFADoubleBuffer,
@@ -53,9 +55,9 @@ typedef NSUInteger NSWindowStyleMask;
NSOpenGLPFAOpenGLProfile, profile,
NSOpenGLPFAColorSize, 32,
NSOpenGLPFADepthSize, 32,
- NSOpenGLPFAMultisample, puglview->hints.samples ? 1 : 0,
- NSOpenGLPFASampleBuffers, puglview->hints.samples ? 1 : 0,
- NSOpenGLPFASamples, puglview->hints.samples,
+ NSOpenGLPFAMultisample, samples ? 1 : 0,
+ NSOpenGLPFASampleBuffers, samples ? 1 : 0,
+ NSOpenGLPFASamples, samples,
0};
NSOpenGLPixelFormat* pixelFormat = [
@@ -113,7 +115,7 @@ puglMacGlCreate(PuglView* view)
drawView->puglview = view;
[drawView initWithFrame:NSMakeRect(0, 0, view->width, view->height)];
- if (view->hints.resizable) {
+ if (view->hints[PUGL_RESIZABLE]) {
[drawView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
} else {
[drawView setAutoresizingMask:NSViewNotSizable];
diff --git a/pugl/detail/types.h b/pugl/detail/types.h
index 60f7682..b538091 100644
--- a/pugl/detail/types.h
+++ b/pugl/detail/types.h
@@ -39,21 +39,7 @@
typedef struct PuglInternalsImpl PuglInternals;
/** View hints. */
-typedef struct {
- int context_version_major;
- int context_version_minor;
- int red_bits;
- int green_bits;
- int blue_bits;
- int alpha_bits;
- int depth_bits;
- int stencil_bits;
- int samples;
- int double_buffer;
- bool use_compat_profile;
- bool resizable;
- bool ignoreKeyRepeat;
-} PuglHints;
+typedef int PuglHints[PUGL_NUM_WINDOW_HINTS];
/** Cross-platform view definition. */
struct PuglViewImpl {
diff --git a/pugl/detail/win.c b/pugl/detail/win.c
index 93dce9d..3a30814 100644
--- a/pugl/detail/win.c
+++ b/pugl/detail/win.c
@@ -360,7 +360,7 @@ initCharEvent(PuglEvent* event, PuglView* view, WPARAM wParam, LPARAM lParam)
static bool
ignoreKeyEvent(PuglView* view, LPARAM lParam)
{
- return view->hints.ignoreKeyRepeat && (lParam & (1 << 30));
+ return view->hints[PUGL_IGNORE_KEY_REPEAT] && (lParam & (1 << 30));
}
static RECT
diff --git a/pugl/detail/win.h b/pugl/detail/win.h
index 9af5cbb..88cb1a1 100644
--- a/pugl/detail/win.h
+++ b/pugl/detail/win.h
@@ -40,24 +40,26 @@ struct PuglInternalsImpl {
};
static inline PuglWinPFD
-puglWinGetPixelFormatDescriptor(const PuglHints* const hints)
+puglWinGetPixelFormatDescriptor(const PuglHints hints)
{
- const int rgbBits = hints->red_bits + hints->green_bits + hints->blue_bits;
+ const int rgbBits = (hints[PUGL_RED_BITS] +
+ hints[PUGL_GREEN_BITS] +
+ hints[PUGL_BLUE_BITS]);
PuglWinPFD pfd;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL;
- pfd.dwFlags |= hints->double_buffer ? PFD_DOUBLEBUFFER : 0;
+ pfd.dwFlags |= hints[PUGL_DOUBLE_BUFFER] ? PFD_DOUBLEBUFFER : 0;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = (BYTE)rgbBits;
- pfd.cRedBits = (BYTE)hints->red_bits;
- pfd.cGreenBits = (BYTE)hints->green_bits;
- pfd.cBlueBits = (BYTE)hints->blue_bits;
- pfd.cAlphaBits = (BYTE)hints->alpha_bits;
- pfd.cDepthBits = (BYTE)hints->depth_bits;
- pfd.cStencilBits = (BYTE)hints->stencil_bits;
+ pfd.cRedBits = (BYTE)hints[PUGL_RED_BITS];
+ pfd.cGreenBits = (BYTE)hints[PUGL_GREEN_BITS];
+ pfd.cBlueBits = (BYTE)hints[PUGL_BLUE_BITS];
+ pfd.cAlphaBits = (BYTE)hints[PUGL_ALPHA_BITS];
+ pfd.cDepthBits = (BYTE)hints[PUGL_DEPTH_BITS];
+ pfd.cStencilBits = (BYTE)hints[PUGL_STENCIL_BITS];
pfd.iLayerType = PFD_MAIN_PLANE;
return pfd;
}
@@ -69,13 +71,14 @@ puglWinCreateWindow(const PuglView* const view,
HDC* const hdc)
{
const char* className = view->windowClass ? view->windowClass : "Pugl";
+ const bool resizable = view->hints[PUGL_RESIZABLE];
const unsigned winFlags =
(WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
(view->parent
? WS_CHILD
: (WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX |
- (view->hints.resizable ? (WS_SIZEBOX | WS_MAXIMIZEBOX) : 0))));
+ (resizable ? (WS_SIZEBOX | WS_MAXIMIZEBOX) : 0))));
const unsigned winExFlags =
WS_EX_NOINHERITLAYOUT | (view->parent ? 0u : WS_EX_APPWINDOW);
diff --git a/pugl/detail/win_gl.c b/pugl/detail/win_gl.c
index 17ee68d..0768a4e 100644
--- a/pugl/detail/win_gl.c
+++ b/pugl/detail/win_gl.c
@@ -111,16 +111,16 @@ puglWinGlConfigure(PuglView* view)
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
- WGL_DOUBLE_BUFFER_ARB, view->hints.double_buffer,
+ WGL_DOUBLE_BUFFER_ARB, view->hints[PUGL_DOUBLE_BUFFER],
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
- WGL_SAMPLE_BUFFERS_ARB, view->hints.samples ? 1 : 0,
- WGL_SAMPLES_ARB, view->hints.samples,
- WGL_RED_BITS_ARB, view->hints.red_bits,
- WGL_GREEN_BITS_ARB, view->hints.green_bits,
- WGL_BLUE_BITS_ARB, view->hints.blue_bits,
- WGL_ALPHA_BITS_ARB, view->hints.alpha_bits,
- WGL_DEPTH_BITS_ARB, view->hints.depth_bits,
- WGL_STENCIL_BITS_ARB, view->hints.stencil_bits,
+ WGL_SAMPLE_BUFFERS_ARB, view->hints[PUGL_SAMPLES] ? 1 : 0,
+ WGL_SAMPLES_ARB, view->hints[PUGL_SAMPLES],
+ WGL_RED_BITS_ARB, view->hints[PUGL_RED_BITS],
+ WGL_GREEN_BITS_ARB, view->hints[PUGL_GREEN_BITS],
+ WGL_BLUE_BITS_ARB, view->hints[PUGL_BLUE_BITS],
+ WGL_ALPHA_BITS_ARB, view->hints[PUGL_ALPHA_BITS],
+ WGL_DEPTH_BITS_ARB, view->hints[PUGL_DEPTH_BITS],
+ WGL_STENCIL_BITS_ARB, view->hints[PUGL_STENCIL_BITS],
0,
};
@@ -137,7 +137,7 @@ puglWinGlConfigure(PuglView* view)
}
// Set pixel format for fake window
- const PuglWinPFD fakePfd = puglWinGetPixelFormatDescriptor(&view->hints);
+ const PuglWinPFD fakePfd = puglWinGetPixelFormatDescriptor(view->hints);
const int fakePfId = ChoosePixelFormat(fakeWin.hdc, &fakePfd);
if (!fakePfId) {
return puglWinError(&fakeWin, PUGL_ERR_SET_FORMAT);
@@ -188,10 +188,10 @@ puglWinGlCreate(PuglView* view)
PuglStatus st = PUGL_SUCCESS;
const int contextAttribs[] = {
- WGL_CONTEXT_MAJOR_VERSION_ARB, view->hints.context_version_major,
- WGL_CONTEXT_MINOR_VERSION_ARB, view->hints.context_version_minor,
+ WGL_CONTEXT_MAJOR_VERSION_ARB, view->hints[PUGL_CONTEXT_VERSION_MAJOR],
+ WGL_CONTEXT_MINOR_VERSION_ARB, view->hints[PUGL_CONTEXT_VERSION_MINOR],
WGL_CONTEXT_PROFILE_MASK_ARB,
- (view->hints.use_compat_profile
+ (view->hints[PUGL_USE_COMPAT_PROFILE]
? WGL_CONTEXT_CORE_PROFILE_BIT_ARB
: WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB),
0
diff --git a/pugl/detail/x11.c b/pugl/detail/x11.c
index d6461a2..e6057af 100644
--- a/pugl/detail/x11.c
+++ b/pugl/detail/x11.c
@@ -111,7 +111,7 @@ puglCreateWindow(PuglView* view, const char* title)
}
XSizeHints sizeHints = {0};
- if (!view->hints.resizable) {
+ if (!view->hints[PUGL_RESIZABLE]) {
sizeHints.flags = PMinSize|PMaxSize;
sizeHints.min_width = view->width;
sizeHints.min_height = view->height;
@@ -507,7 +507,7 @@ puglProcessEvents(PuglView* view)
XNextEvent(impl->display, &xevent);
if (xevent.type == KeyRelease) {
// Ignore key repeat if necessary
- if (view->hints.ignoreKeyRepeat &&
+ if (view->hints[PUGL_IGNORE_KEY_REPEAT] &&
XEventsQueued(impl->display, QueuedAfterReading)) {
XEvent next;
XPeekEvent(impl->display, &next);
diff --git a/pugl/detail/x11_gl.c b/pugl/detail/x11_gl.c
index 85c18b4..b6f3c51 100644
--- a/pugl/detail/x11_gl.c
+++ b/pugl/detail/x11_gl.c
@@ -71,14 +71,14 @@ puglX11GlConfigure(PuglView* view)
GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
- GLX_SAMPLES, view->hints.samples,
- GLX_RED_SIZE, puglX11GlHintValue(view->hints.red_bits),
- GLX_GREEN_SIZE, puglX11GlHintValue(view->hints.green_bits),
- GLX_BLUE_SIZE, puglX11GlHintValue(view->hints.blue_bits),
- GLX_ALPHA_SIZE, puglX11GlHintValue(view->hints.alpha_bits),
- GLX_DEPTH_SIZE, puglX11GlHintValue(view->hints.depth_bits),
- GLX_STENCIL_SIZE, puglX11GlHintValue(view->hints.stencil_bits),
- GLX_DOUBLEBUFFER, puglX11GlHintValue(view->hints.double_buffer),
+ GLX_SAMPLES, view->hints[PUGL_SAMPLES],
+ GLX_RED_SIZE, puglX11GlHintValue(view->hints[PUGL_RED_BITS]),
+ GLX_GREEN_SIZE, puglX11GlHintValue(view->hints[PUGL_GREEN_BITS]),
+ GLX_BLUE_SIZE, puglX11GlHintValue(view->hints[PUGL_BLUE_BITS]),
+ GLX_ALPHA_SIZE, puglX11GlHintValue(view->hints[PUGL_ALPHA_BITS]),
+ GLX_DEPTH_SIZE, puglX11GlHintValue(view->hints[PUGL_DEPTH_BITS]),
+ GLX_STENCIL_SIZE, puglX11GlHintValue(view->hints[PUGL_STENCIL_BITS]),
+ GLX_DOUBLEBUFFER, puglX11GlHintValue(view->hints[PUGL_DOUBLE_BUFFER]),
None
};
@@ -117,9 +117,9 @@ puglX11GlCreate(PuglView* view)
const GLXFBConfig fb_config = surface->fb_config;
const int ctx_attrs[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, view->hints.context_version_major,
- GLX_CONTEXT_MINOR_VERSION_ARB, view->hints.context_version_minor,
- GLX_CONTEXT_PROFILE_MASK_ARB, (view->hints.use_compat_profile
+ GLX_CONTEXT_MAJOR_VERSION_ARB, view->hints[PUGL_CONTEXT_VERSION_MAJOR],
+ GLX_CONTEXT_MINOR_VERSION_ARB, view->hints[PUGL_CONTEXT_VERSION_MINOR],
+ GLX_CONTEXT_PROFILE_MASK_ARB, (view->hints[PUGL_USE_COMPAT_PROFILE]
? GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
: GLX_CONTEXT_CORE_PROFILE_BIT_ARB),
0};
diff --git a/pugl/pugl.h b/pugl/pugl.h
index d04f1aa..f352766 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -110,6 +110,8 @@ typedef enum {
PUGL_DOUBLE_BUFFER, /**< True if double buffering should be used */
PUGL_RESIZABLE, /**< True if window should be resizable */
PUGL_IGNORE_KEY_REPEAT, /**< True if key repeat events are ignored */
+
+ PUGL_NUM_WINDOW_HINTS
} PuglWindowHint;
/**