aboutsummaryrefslogtreecommitdiff
path: root/generic/tkZinc.c
diff options
context:
space:
mode:
authorlecoanet2004-03-23 14:53:46 +0000
committerlecoanet2004-03-23 14:53:46 +0000
commitbfcdb3b51ea88028b63f3f2d9577659e4119d20a (patch)
tree60a2f38988e2719012fbe719cbd19db7d1101f14 /generic/tkZinc.c
parentc15cc9537d6c0d2bf6d5417bd96930cae4381162 (diff)
downloadtkzinc-bfcdb3b51ea88028b63f3f2d9577659e4119d20a.zip
tkzinc-bfcdb3b51ea88028b63f3f2d9577659e4119d20a.tar.gz
tkzinc-bfcdb3b51ea88028b63f3f2d9577659e4119d20a.tar.bz2
tkzinc-bfcdb3b51ea88028b63f3f2d9577659e4119d20a.tar.xz
Changes related to OpenGL context handling (only one context per display) and patches to avoid using widget structure in image cache */
Diffstat (limited to 'generic/tkZinc.c')
-rw-r--r--generic/tkZinc.c138
1 files changed, 88 insertions, 50 deletions
diff --git a/generic/tkZinc.c b/generic/tkZinc.c
index 8cd188d..4801b4d 100644
--- a/generic/tkZinc.c
+++ b/generic/tkZinc.c
@@ -130,17 +130,6 @@ static Tk_Uid dot_uid;
static Tk_Uid star_uid;
#ifdef GL
-typedef struct _ZnGLContextEntry {
- ZnGLContext context;
-#ifdef WIN
- HDC hdc;
-#else
- Display *dpy;
- XVisualInfo *visual; /* Should these two be managed by screen ? */
- Colormap colormap;
-#endif
- struct _ZnGLContextEntry *next;
-} ZnGLContextEntry;
static ZnGLContextEntry *gl_contexts = NULL;
#endif
@@ -624,6 +613,52 @@ ZnNeedRedisplay(ZnWInfo *wi)
}
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * ZnGetGlContext --
+ *
+ *----------------------------------------------------------------------
+ */
+#ifdef GL
+ZnGLContextEntry *
+ZnGetGLContext(Display *dpy)
+{
+ ZnGLContextEntry *context_entry;
+
+ for (context_entry = gl_contexts;
+ context_entry && context_entry->dpy != dpy;
+ context_entry = context_entry->next);
+
+ return context_entry;
+}
+
+void
+ZnGLMakeCurrent(Display *dpy,
+ Tk_Window win)
+{
+ ZnGLContextEntry *context_entry;
+
+ context_entry = ZnGetGLContext(dpy);
+#ifdef WIN
+ wglMakeCurrent(context_entry->hdc, context_entry->context);
+#else
+ glXMakeCurrent(dpy, win==NULL?DefaultRootWindow(dpy):Tk_WindowId(win),
+ context_entry->context);
+#endif
+}
+
+void
+ZnGLSwapBuffers(Display *dpy,
+ Tk_Window win)
+{
+#ifdef WIN
+ SwapBuffers(ZnGetGLContext(dpy)->hdc);
+#else
+ glXSwapBuffers(dpy, Tk_WindowId(win));
+#endif
+}
+#endif
/*
*----------------------------------------------------------------------
@@ -763,7 +798,6 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
#ifdef GL
wi->font_tfi = NULL;
wi->map_font_tfi = NULL;
- wi->max_tex_size = 64; /* Minimum value is always valid */
#endif
wi->map_distance_symbol = ZnUnspecifiedImage;
wi->track_symbol = ZnUnspecifiedImage;
@@ -887,6 +921,7 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
if (wi->render) {
#ifdef GL
ZnGLContextEntry *context_entry;
+ ZnGLContext gl_context;
ASSIGN(wi->flags, ZN_PRINT_CONFIG, (getenv("ZINC_GLX_INFO") != NULL));
@@ -910,25 +945,25 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
0, // reserved
0, 0, 0 // layer masks ignored
};
- int ipixel;
+ int ipixel;
+ HWND hwnd;
+ HDC hdc;
Tk_MakeWindowExist(wi->win);
- wi->hwnd = Tk_GetHWND(Tk_WindowId(wi->win));
- wi->hdc = GetDC(wi->hwnd);
- if (!wi->hdc) {
+ hwnd = Tk_GetHWND(Tk_WindowId(wi->win));
+ hdc = GetDC(hwnd);
+ if (!hdc) {
OutputDebugString("Unable to get the hdc\n");
}
/*
* Look for a matching context already available.
*/
- for (context_entry = gl_contexts;
- context_entry && context_entry->hdc != wi->hdc;
- context_entry = context_entry->next);
+ context_entry = ZnGetGLContext(wi->dpy);
if (context_entry) {
- wi->gl_context = context_entry->context;
+ gl_context = context_entry->context;
}
else {
- ipixel = ChoosePixelFormat(wi->hdc, &pfd);
+ ipixel = ChoosePixelFormat(hdc, &pfd);
/* sprintf(msg, "ipixel=%d dwFlags=0x%x req=0x%x iPixelType=%d\n",
ipixel,
pfd.dwFlags,
@@ -938,16 +973,16 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
if (!ipixel) {
OutputDebugString("ChoosePixelFormat failed\n");
}
- wi->render = (SetPixelFormat(wi->hdc, ipixel, &pfd) == TRUE);
+ wi->render = (SetPixelFormat(hdc, ipixel, &pfd) == TRUE);
if (wi->render) {
- wi->gl_context = wglCreateContext(wi->hdc);
- if (!wi->gl_context) {
+ gl_context = wglCreateContext(hdc);
+ if (!gl_context) {
OutputDebugString("wglCreateContext failed\n");
}
else {
context_entry = ZnMalloc(sizeof(ZnGLContextEntry));
- context_entry->context = wi->gl_context;
- context_entry->hdc = wi->hdc;
+ context_entry->context = gl_context;
+ context_entry->hdc = hdc;
context_entry->next = gl_contexts;
gl_contexts = context_entry;
}
@@ -965,12 +1000,9 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
/*
* Look for a matching context already available.
*/
- for (context_entry = gl_contexts;
- context_entry && context_entry->dpy != wi->dpy;
- context_entry = context_entry->next);
-
+ context_entry = ZnGetGLContext(wi->dpy);
if (context_entry) {
- wi->gl_context = context_entry->context;
+ gl_context = context_entry->context;
gl_visual = context_entry->visual;
colormap = context_entry->colormap;
}
@@ -985,9 +1017,9 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
wi->render = 0;
}
else {
- wi->gl_context = glXCreateContext(wi->dpy, gl_visual,
- NULL, wi->render==1);
- if (!wi->gl_context) {
+ gl_context = glXCreateContext(wi->dpy, gl_visual,
+ NULL, wi->render==1);
+ if (!gl_context) {
fprintf(stderr, "No glx context\n");
wi->render = 0;
}
@@ -995,10 +1027,13 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
colormap = XCreateColormap(wi->dpy, RootWindowOfScreen(wi->screen),
gl_visual->visual, AllocNone);
context_entry = ZnMalloc(sizeof(ZnGLContextEntry));
- context_entry->context = wi->gl_context;
+ context_entry->context = gl_context;
context_entry->visual = gl_visual;
context_entry->colormap = colormap;
context_entry->dpy = wi->dpy;
+ context_entry->max_tex_size = 64; /* Minimum value is always valid */
+ context_entry->max_line_width = 1;
+ context_entry->max_point_width = 1;
context_entry->next = gl_contexts;
gl_contexts = context_entry;
@@ -1022,7 +1057,7 @@ ZincObjCmd(ClientData client_data, /* Main window associated with
glXGetConfig(wi->dpy, gl_visual, GLX_ALPHA_SIZE, &val);
fprintf(stderr, "alpha : %d\n", val);
fprintf(stderr, " Direct Rendering: %d\n",
- glXIsDirect(wi->dpy, wi->gl_context));
+ glXIsDirect(wi->dpy, gl_context));
}
}
}
@@ -6275,18 +6310,21 @@ Event(ClientData client_data, /* Information about widget. */
if (event->type == MapNotify) {
if (!wi->gc) {
SET(wi->flags, ZN_REALIZED);
+
if (wi->render) {
#ifdef GL
- GLfloat r[2]; /* Min, Max */
- GLint i[1];
+ GLfloat r[2]; /* Min, Max */
+ GLint i[1];
+ ZnGLContextEntry *ce;
- ZnGLMakeCurrent(wi);
+ ce = ZnGetGLContext(wi->dpy);
+ ZnGLMakeCurrent(wi->dpy, 0);
glGetFloatv(ZN_GL_LINE_WIDTH_RANGE, r);
- wi->max_line_width = r[1];
+ ce->max_line_width = r[1];
glGetFloatv(ZN_GL_POINT_SIZE_RANGE, r);
- wi->max_point_width = r[1];
+ ce->max_point_width = r[1];
glGetIntegerv(GL_MAX_TEXTURE_SIZE, i);
- wi->max_tex_size = (unsigned int) i[0];
+ ce->max_tex_size = (unsigned int) i[0];
if (!wi->font_tfi) {
wi->font_tfi = ZnGetTexFont(wi, wi->font);
@@ -6305,14 +6343,14 @@ Event(ClientData client_data, /* Information about widget. */
fprintf(stderr, " Available extensions: %s\n",
(char *) glGetString(GL_EXTENSIONS));
fprintf(stderr, "Max antialiased line width: %g\n",
- wi->max_line_width);
+ ce->max_line_width);
fprintf(stderr, "Max antialiased point size: %g\n",
- wi->max_point_width);
+ ce->max_point_width);
fprintf(stderr, "Max texture size: %d\n",
- wi->max_tex_size);
+ ce->max_tex_size);
}
- ZnGLRelease(wi);
+ /*ZnGLRelease(wi);*/
#endif
}
@@ -7476,7 +7514,7 @@ Repair(ZnWInfo *wi)
}
#endif
- ZnGLMakeCurrent(wi);
+ ZnGLMakeCurrent(wi->dpy, wi->win);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
#if 0
@@ -7612,8 +7650,8 @@ Repair(ZnWInfo *wi)
glFlush();
/* Switch the GL buffers. */
- ZnGLSwapBuffers(wi);
- ZnGLRelease(wi);
+ ZnGLSwapBuffers(wi->dpy, wi->win);
+ /*ZnGLRelease(wi);*/
/*
* Wait the end of GL update if we need to synchronize
@@ -7657,7 +7695,7 @@ Repair(ZnWInfo *wi)
}
else {
values.fill_style = FillTiled;
- values.tile = ZnImagePixmap(wi->tile);
+ values.tile = ZnImagePixmap(wi->tile, wi->win);
values.ts_x_origin = values.ts_y_origin = 0;
XChangeGC(wi->dpy, wi->gc,
GCFillStyle|GCTile|GCTileStipXOrigin|GCTileStipYOrigin,