[waffle] [PATCH 09/18] wgl: add context hooks
Emil Velikov
emil.l.velikov at gmail.com
Tue Jul 22 20:31:35 PDT 2014
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
src/waffle/wgl/wgl_context.c | 14 ++++++++++++--
src/waffle/wgl/wgl_context.h | 1 +
src/waffle/wgl/wgl_platform.c | 5 ++++-
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/waffle/wgl/wgl_context.c b/src/waffle/wgl/wgl_context.c
index a44176c..ce4ff11 100644
--- a/src/waffle/wgl/wgl_context.c
+++ b/src/waffle/wgl/wgl_context.c
@@ -25,23 +25,28 @@
#include <assert.h>
#include <stdlib.h>
+#include <windows.h>
#include "wcore_error.h"
#include "wgl_config.h"
#include "wgl_context.h"
#include "wgl_error.h"
+#include "wgl_window.h"
bool
wgl_context_destroy(struct wcore_context *wc_self)
{
struct wgl_context *self = wgl_context(wc_self);
- bool ok;
+ bool ok = true;
if (!self)
return true;
- ok = wcore_context_teardown(wc_self);
+ if (self->hglrc)
+ ok &= wglDeleteContext(self->hglrc);
+
+ ok &= wcore_context_teardown(wc_self);
free(self);
return ok;
}
@@ -51,6 +56,7 @@ wgl_context_create(struct wcore_platform *wc_plat,
struct wcore_config *wc_config,
struct wcore_context *wc_share_ctx)
{
+ struct wgl_config *config = wgl_config(wc_config);
struct wgl_context *self;
int error;
@@ -62,6 +68,10 @@ wgl_context_create(struct wcore_platform *wc_plat,
if (error)
goto fail;
+ self->hglrc = wglCreateContext(config->window->hDC);
+ if (!self->hglrc)
+ goto fail;
+
return &self->wcore;
fail:
diff --git a/src/waffle/wgl/wgl_context.h b/src/waffle/wgl/wgl_context.h
index d737a13..5396ff4 100644
--- a/src/waffle/wgl/wgl_context.h
+++ b/src/waffle/wgl/wgl_context.h
@@ -35,6 +35,7 @@ struct wcore_platform;
struct wgl_context {
struct wcore_context wcore;
+ HGLRC hglrc;
};
DEFINE_CONTAINER_CAST_FUNC(wgl_context,
diff --git a/src/waffle/wgl/wgl_platform.c b/src/waffle/wgl/wgl_platform.c
index 3c9c1e6..4318de3 100644
--- a/src/waffle/wgl/wgl_platform.c
+++ b/src/waffle/wgl/wgl_platform.c
@@ -123,7 +123,10 @@ wgl_make_current(struct wcore_platform *wc_self,
struct wcore_window *wc_window,
struct wcore_context *wc_ctx)
{
- return false;
+ HDC hDC = wc_window ? wgl_window(wc_window)->hDC : NULL;
+ HGLRC hglrc = wc_ctx ? wgl_context(wc_ctx)->hglrc : NULL;
+
+ return wglMakeCurrent(hDC, hglrc);
}
static void*
--
2.0.2
More information about the waffle
mailing list