summaryrefslogtreecommitdiff
path: root/progs/wgl
diff options
context:
space:
mode:
Diffstat (limited to 'progs/wgl')
-rw-r--r--progs/wgl/SConscript25
-rw-r--r--progs/wgl/sharedtex_mt/sharedtex_mt.c565
-rw-r--r--progs/wgl/wglinfo.c736
-rw-r--r--progs/wgl/wglthreads/wglthreads.c636
4 files changed, 1962 insertions, 0 deletions
diff --git a/progs/wgl/SConscript b/progs/wgl/SConscript
new file mode 100644
index 0000000000..31f61676de
--- /dev/null
+++ b/progs/wgl/SConscript
@@ -0,0 +1,25 @@
+Import('*')
+
+if env['platform'] != 'windows':
+ Return()
+
+env = env.Clone()
+
+env.Append(LIBS = [
+ 'kernel32',
+ 'user32',
+ 'gdi32',
+])
+
+progs = [
+ 'sharedtex_mt',
+ 'wglthreads',
+]
+
+for prog in progs:
+ env.Program(
+ target = prog,
+ source = prog + '/' + prog + '.c',
+ )
+
+env.Program('wglinfo', ['wglinfo.c'])
diff --git a/progs/wgl/sharedtex_mt/sharedtex_mt.c b/progs/wgl/sharedtex_mt/sharedtex_mt.c
new file mode 100644
index 0000000000..779e15001d
--- /dev/null
+++ b/progs/wgl/sharedtex_mt/sharedtex_mt.c
@@ -0,0 +1,565 @@
+/*
+ * Test sharing of display lists and texture objects between GLX contests.
+ * Brian Paul
+ * Summer 2000
+ *
+ *
+ * Copyright (C) 2000 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Modified 2009 for multithreading by Thomas Hellstrom.
+ *
+ * Port to windows by Michal Krol.
+ */
+
+
+#include <windows.h>
+#include <GL/gl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#pragma comment(lib, "opengl32.lib")
+
+struct thread_init_arg {
+ int id;
+};
+
+struct window {
+ CRITICAL_SECTION drawMutex;
+ HDC hDC;
+ HWND Win;
+ HGLRC Context;
+ float Angle;
+ int Id;
+ HGLRC sharedContext;
+ HANDLE hEventInitialised;
+};
+
+
+#define MAX_WINDOWS 20
+static struct window Windows[MAX_WINDOWS];
+static int NumWindows = 0;
+static HANDLE terminate = NULL;
+static HGLRC gCtx = NULL;
+static HDC gHDC = NULL;
+static GLuint Textures[3];
+
+
+
+static void
+Error(const char *msg)
+{
+ fprintf(stderr, "Error - %s\n", msg);
+ exit(1);
+}
+
+static void
+Resize(struct window *h, unsigned int width, unsigned int height);
+
+static LRESULT CALLBACK
+WndProc(HWND hWnd,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam )
+{
+ switch (uMsg) {
+ case WM_KEYDOWN:
+ SetEvent(terminate);
+ break;
+ case WM_SIZE:
+ {
+ LONG index = GetWindowLong(hWnd, GWL_USERDATA);
+
+ if (index >= 0 && index < MAX_WINDOWS) {
+ RECT r;
+
+ GetClientRect(hWnd, &r);
+ Resize(&Windows[index], r.right, r.bottom);
+ }
+ }
+ break;
+ case WM_CREATE:
+ {
+ CREATESTRUCT *pcs = (CREATESTRUCT *) lParam;
+
+ SetWindowLong(hWnd, GWL_USERDATA, (LONG) pcs->lpCreateParams);
+ }
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ }
+
+ return 0;
+}
+
+static int
+initMainthread(void)
+{
+ WNDCLASS wc = {0};
+ HWND win;
+ PIXELFORMATDESCRIPTOR pfd = {0};
+ int visinfo;
+
+ wc.lpfnWndProc = WndProc;
+ wc.lpszClassName = "sharedtex_mt.hidden";
+ wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
+ RegisterClass(&wc);
+
+ win = CreateWindowEx(0,
+ wc.lpszClassName,
+ "sharedtex_mt.hidden",
+ WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ NULL,
+ NULL,
+ wc.hInstance,
+ (LPVOID) -1);
+ if (!win) {
+ Error("Couldn't create window");
+ }
+
+ gHDC = GetDC(win);
+ if (!gHDC) {
+ Error("Couldn't obtain HDC");
+ }
+
+ pfd.cColorBits = 24;
+ pfd.cDepthBits = 24;
+ pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+
+ visinfo = ChoosePixelFormat(gHDC, &pfd);
+ if (!visinfo) {
+ Error("Unable to find RGB, Z, double-buffered visual");
+ }
+
+ SetPixelFormat(gHDC, visinfo, &pfd);
+ gCtx = wglCreateContext(gHDC);
+ if (!gCtx) {
+ Error("Couldn't create WGL context");
+ }
+
+ return 0;
+}
+
+static struct window *
+AddWindow(int xpos, int ypos, HGLRC sCtx)
+{
+ struct window *win = &Windows[NumWindows];
+ WNDCLASS wc = {0};
+ int width = 300, height = 300;
+
+ if (NumWindows >= MAX_WINDOWS)
+ return NULL;
+
+ memset(win, 0, sizeof(*win));
+ InitializeCriticalSection(&win->drawMutex);
+ win->Angle = 0.0;
+ win->Id = NumWindows++;
+
+ wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wc.lpfnWndProc = WndProc;
+ wc.lpszClassName = "sharedtex_mt";
+ wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
+ RegisterClass(&wc);
+
+ win->Win = CreateWindowEx(0,
+ wc.lpszClassName,
+ "sharedtex_mt",
+ WS_SIZEBOX | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ xpos,
+ ypos,
+ width,
+ height,
+ NULL,
+ NULL,
+ wc.hInstance,
+ (LPVOID) win->Id);
+ if (!win->Win) {
+ Error("Couldn't create window");
+ }
+
+ win->sharedContext = sCtx;
+
+ ShowWindow(win->Win, SW_SHOW);
+
+ return win;
+}
+
+
+static void
+InitGLstuff(void)
+{
+ glGenTextures(3, Textures);
+
+ /* setup first texture object */
+ {
+ GLubyte image[16][16][4];
+ GLint i, j;
+ glBindTexture(GL_TEXTURE_2D, Textures[0]);
+
+ /* red/white checkerboard */
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ if ((i ^ j) & 1) {
+ image[i][j][0] = 255;
+ image[i][j][1] = 255;
+ image[i][j][2] = 255;
+ image[i][j][3] = 255;
+ }
+ else {
+ image[i][j][0] = 255;
+ image[i][j][1] = 0;
+ image[i][j][2] = 0;
+ image[i][j][3] = 255;
+ }
+ }
+ }
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
+
+ /* setup second texture object */
+ {
+ GLubyte image[8][8][3];
+ GLint i, j;
+ glBindTexture(GL_TEXTURE_2D, Textures[1]);
+
+ /* green/yellow checkerboard */
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ if ((i ^ j) & 1) {
+ image[i][j][0] = 0;
+ image[i][j][1] = 255;
+ image[i][j][2] = 0;
+ }
+ else {
+ image[i][j][0] = 255;
+ image[i][j][1] = 255;
+ image[i][j][2] = 0;
+ }
+ }
+ }
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB,
+ GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
+
+ /* setup second texture object */
+ {
+ GLubyte image[4][4][3];
+ GLint i, j;
+ glBindTexture(GL_TEXTURE_2D, Textures[2]);
+
+ /* blue/gray checkerboard */
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ if ((i ^ j) & 1) {
+ image[i][j][0] = 0;
+ image[i][j][1] = 0;
+ image[i][j][2] = 255;
+ }
+ else {
+ image[i][j][0] = 200;
+ image[i][j][1] = 200;
+ image[i][j][2] = 200;
+ }
+ }
+ }
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB,
+ GL_UNSIGNED_BYTE, image);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
+
+ /* Now make the cube object display list */
+
+ printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER));
+ printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION));
+ printf("GL_VENDOR: %s\n", (char *) glGetString(GL_VENDOR));
+}
+
+static void
+Redraw(struct window *h)
+{
+ EnterCriticalSection(&h->drawMutex);
+ if (!wglMakeCurrent(h->hDC, h->Context)) {
+ LeaveCriticalSection(&h->drawMutex);
+ Error("wglMakeCurrent failed in Redraw");
+ return;
+ }
+
+ h->Angle += 1.0;
+
+ glShadeModel(GL_FLAT);
+ glClearColor(0.25, 0.25, 0.25, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_DEPTH_TEST);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+ glColor3f(1, 1, 1);
+
+ glPushMatrix();
+ if (h->Id == 0)
+ glRotatef(h->Angle, 0, 1, -1);
+ else if (h->Id == 1)
+ glRotatef(-(h->Angle), 0, 1, -1);
+ else if (h->Id == 2)
+ glRotatef(h->Angle, 0, 1, 1);
+ else if (h->Id == 3)
+ glRotatef(-(h->Angle), 0, 1, 1);
+ glBindTexture(GL_TEXTURE_2D, Textures[0]);
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f(-1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
+ glEnd();
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0); glVertex3f(1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f(1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(1, -1, 1);
+ glEnd();
+
+ glBindTexture(GL_TEXTURE_2D, Textures[1]);
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, -1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
+ glEnd();
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0); glVertex3f(-1, 1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
+ glEnd();
+
+ glBindTexture(GL_TEXTURE_2D, Textures[2]);
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, -1);
+ glEnd();
+ glBegin(GL_POLYGON);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, 1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, 1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
+ glEnd();
+
+ glPopMatrix();
+
+ SwapBuffers(h->hDC);
+
+ if (!wglMakeCurrent(NULL, NULL)) {
+ Error("wglMakeCurrent failed in Redraw");
+ }
+ LeaveCriticalSection(&h->drawMutex);
+}
+
+static DWORD WINAPI
+threadRunner (void *arg)
+{
+ struct thread_init_arg *tia = (struct thread_init_arg *) arg;
+ struct window *win;
+ PIXELFORMATDESCRIPTOR pfd = {0};
+ int visinfo;
+
+ win = &Windows[tia->id];
+
+ win->hDC = GetDC(win->Win);
+ if (!win->hDC) {
+ Error("Couldn't obtain HDC");
+ }
+
+ /* Wait for the previous thread */
+ if(tia->id > 0)
+ WaitForSingleObject(Windows[tia->id - 1].hEventInitialised, INFINITE);
+
+ pfd.cColorBits = 24;
+ pfd.cDepthBits = 24;
+ pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+
+ visinfo = ChoosePixelFormat(win->hDC, &pfd);
+ if (!visinfo) {
+ Error("Unable to find RGB, Z, double-buffered visual");
+ }
+
+ SetPixelFormat(win->hDC, visinfo, &pfd);
+ win->Context = wglCreateContext(win->hDC);
+ if (!win->Context) {
+ Error("Couldn't create WGL context");
+ }
+
+ if (win->sharedContext) {
+ if(!wglShareLists(win->sharedContext, win->Context))
+ Error("Couldn't share WGL context lists");
+ }
+
+ SetEvent(win->hEventInitialised);
+
+ /* Wait for all threads to initialize otherwise wglShareLists will fail */
+ if(tia->id < NumWindows - 1)
+ WaitForSingleObject(Windows[NumWindows - 1].hEventInitialised, INFINITE);
+
+ SendMessage(win->Win, WM_SIZE, 0, 0);
+
+ while (1) {
+ MSG msg;
+
+ /* wait 1 ms for signal either to exit or process messages */
+ switch (MsgWaitForMultipleObjects(1, &terminate, FALSE, 1, QS_ALLINPUT)) {
+ case WAIT_OBJECT_0:
+ SendMessage(win->Win, WM_CLOSE, 0, 0);
+ break;
+ case WAIT_OBJECT_0 + 1:
+ break;
+ }
+
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT) {
+ return 0;
+ }
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ Redraw(win);
+ }
+
+ return 0;
+}
+
+static void
+Resize(struct window *h, unsigned int width, unsigned int height)
+{
+ if (!h->Context)
+ return;
+
+ EnterCriticalSection(&h->drawMutex);
+
+ if (!wglMakeCurrent(h->hDC, h->Context)) {
+ LeaveCriticalSection(&h->drawMutex);
+ Error("wglMakeCurrent failed in Resize()");
+ return;
+ }
+
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1, 1, -1, 1, 2, 10);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0, 0, -4.5);
+ if (!wglMakeCurrent(NULL, NULL)) {
+ Error("wglMakeCurrent failed in Resize()");
+ }
+ LeaveCriticalSection(&h->drawMutex);
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct thread_init_arg tia[MAX_WINDOWS];
+ struct window *h[MAX_WINDOWS];
+ HANDLE threads[MAX_WINDOWS];
+ int i;
+
+ terminate = CreateEvent(NULL, TRUE, FALSE, NULL);
+
+ if (initMainthread())
+ return -1;
+
+ /* four windows and contexts sharing display lists and texture objects */
+ h[0] = AddWindow( 10, 10, gCtx);
+ h[1] = AddWindow(330, 10, gCtx);
+ h[2] = AddWindow( 10, 350, gCtx);
+ h[3] = AddWindow(330, 350, gCtx);
+
+ for (i = 0; i < NumWindows; i++) {
+ Windows[i].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL);
+ }
+
+ for (i = 0; i < NumWindows; i++) {
+ DWORD id;
+
+ tia[i].id = i;
+ threads[i] = CreateThread(NULL, 0, threadRunner, &tia[i], 0, &id);
+
+ WaitForSingleObject(Windows[i].hEventInitialised, INFINITE);
+ }
+
+ if (!wglMakeCurrent(gHDC, gCtx)) {
+ Error("wglMakeCurrent failed for init thread.");
+ return -1;
+ }
+
+ InitGLstuff();
+
+ while (1) {
+ MSG msg;
+
+ /* wait 1 ms for signal either to exit or process messages */
+ switch (MsgWaitForMultipleObjects(NumWindows, threads, TRUE, 1, QS_ALLINPUT)) {
+ case WAIT_OBJECT_0:
+ return 0;
+ }
+
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT) {
+ return 0;
+ }
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+
+ return 0;
+}
diff --git a/progs/wgl/wglinfo.c b/progs/wgl/wglinfo.c
new file mode 100644
index 0000000000..864372c2f9
--- /dev/null
+++ b/progs/wgl/wglinfo.c
@@ -0,0 +1,736 @@
+/*
+ * Copyright (C) 2009 VMware, Inc.
+ * Copyright (C) 1999-2006 Brian Paul
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+/*
+ * This program is a work-alike of the GLX glxinfo program.
+ * Command line options:
+ * -t print wide table
+ * -v print verbose information
+ * -b only print ID of "best" visual on screen 0
+ * -l print interesting OpenGL limits (added 5 Sep 2002)
+ */
+
+#include <windows.h>
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+#include <GL/wglext.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+typedef enum
+{
+ Normal,
+ Wide,
+ Verbose
+} InfoMode;
+
+
+/*
+ * Print a list of extensions, with word-wrapping.
+ */
+static void
+print_extension_list(const char *ext)
+{
+ const char *indentString = " ";
+ const int indent = 4;
+ const int max = 79;
+ int width, i, j;
+
+ if (!ext || !ext[0])
+ return;
+
+ width = indent;
+ printf(indentString);
+ i = j = 0;
+ while (1) {
+ if (ext[j] == ' ' || ext[j] == 0) {
+ /* found end of an extension name */
+ const int len = j - i;
+ if (width + len > max) {
+ /* start a new line */
+ printf("\n");
+ width = indent;
+ printf(indentString);
+ }
+ /* print the extension name between ext[i] and ext[j] */
+ while (i < j) {
+ printf("%c", ext[i]);
+ i++;
+ }
+ /* either we're all done, or we'll continue with next extension */
+ width += len + 1;
+ if (ext[j] == 0) {
+ break;
+ }
+ else {
+ i++;
+ j++;
+ if (ext[j] == 0)
+ break;
+ printf(", ");
+ width += 2;
+ }
+ }
+ j++;
+ }
+ printf("\n");
+}
+
+
+/**
+ * Print interesting limits for vertex/fragment programs.
+ */
+static void
+print_program_limits(GLenum target)
+{
+#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
+ struct token_name {
+ GLenum token;
+ const char *name;
+ };
+ static const struct token_name limits[] = {
+ { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" },
+ { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" },
+ { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" },
+ { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" },
+ { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" },
+ { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" },
+ { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" },
+ { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" },
+ { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" },
+ { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" },
+ { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" },
+ { (GLenum) 0, NULL }
+ };
+ PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC)
+ wglGetProcAddress("glGetProgramivARB");
+ GLint max[1];
+ int i;
+
+ if (target == GL_VERTEX_PROGRAM_ARB) {
+ printf(" GL_VERTEX_PROGRAM_ARB:\n");
+ }
+ else if (target == GL_FRAGMENT_PROGRAM_ARB) {
+ printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
+ }
+ else {
+ return; /* something's wrong */
+ }
+
+ for (i = 0; limits[i].token; i++) {
+ GetProgramivARB_func(target, limits[i].token, max);
+ if (glGetError() == GL_NO_ERROR) {
+ printf(" %s = %d\n", limits[i].name, max[0]);
+ }
+ }
+#endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
+}
+
+
+/**
+ * Print interesting limits for vertex/fragment shaders.
+ */
+static void
+print_shader_limits(GLenum target)
+{
+ struct token_name {
+ GLenum token;
+ const char *name;
+ };
+#if defined(GL_ARB_vertex_shader)
+ static const struct token_name vertex_limits[] = {
+ { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
+ { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" },
+ { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" },
+ { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
+ { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
+ { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
+ { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
+ { (GLenum) 0, NULL }
+ };
+#endif
+#if defined(GL_ARB_fragment_shader)
+ static const struct token_name fragment_limits[] = {
+ { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
+ { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
+ { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
+ { (GLenum) 0, NULL }
+ };
+#endif
+ GLint max[1];
+ int i;
+
+#if defined(GL_ARB_vertex_shader)
+ if (target == GL_VERTEX_SHADER_ARB) {
+ printf(" GL_VERTEX_SHADER_ARB:\n");
+ for (i = 0; vertex_limits[i].token; i++) {
+ glGetIntegerv(vertex_limits[i].token, max);
+ if (glGetError() == GL_NO_ERROR) {
+ printf(" %s = %d\n", vertex_limits[i].name, max[0]);
+ }
+ }
+ }
+#endif
+#if defined(GL_ARB_fragment_shader)
+ if (target == GL_FRAGMENT_SHADER_ARB) {
+ printf(" GL_FRAGMENT_SHADER_ARB:\n");
+ for (i = 0; fragment_limits[i].token; i++) {
+ glGetIntegerv(fragment_limits[i].token, max);
+ if (glGetError() == GL_NO_ERROR) {
+ printf(" %s = %d\n", fragment_limits[i].name, max[0]);
+ }
+ }
+ }
+#endif
+}
+
+
+/**
+ * Print interesting OpenGL implementation limits.
+ */
+static void
+print_limits(const char *extensions)
+{
+ struct token_name {
+ GLuint count;
+ GLenum token;
+ const char *name;
+ };
+ static const struct token_name limits[] = {
+ { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
+ { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
+ { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
+ { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
+ { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
+ { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
+ { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
+ { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
+ { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
+ { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
+ { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
+ { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
+ { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
+ { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
+ { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
+ { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
+ { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
+ { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
+ { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
+ { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
+ { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
+#if defined(GL_ARB_texture_cube_map)
+ { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
+#endif
+#if defined(GLX_NV_texture_rectangle)
+ { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
+#endif
+#if defined(GL_ARB_texture_compression)
+ { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
+#endif
+#if defined(GL_ARB_multitexture)
+ { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
+#endif
+#if defined(GL_EXT_texture_lod_bias)
+ { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
+#endif
+#if defined(GL_EXT_texture_filter_anisotropic)
+ { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
+#endif
+#if defined(GL_ARB_draw_buffers)
+ { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" },
+#endif
+ { 0, (GLenum) 0, NULL }
+ };
+ GLint i, max[2];
+
+ printf("OpenGL limits:\n");
+ for (i = 0; limits[i].count; i++) {
+ glGetIntegerv(limits[i].token, max);
+ if (glGetError() == GL_NO_ERROR) {
+ if (limits[i].count == 1)
+ printf(" %s = %d\n", limits[i].name, max[0]);
+ else /* XXX fix if we ever query something with more than 2 values */
+ printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
+ }
+ }
+
+#if defined(GL_EXT_convolution)
+ {
+ PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC glGetConvolutionParameterivEXT_func =
+ (PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC)wglGetProcAddress("glGetConvolutionParameterivEXT");
+ if(glGetConvolutionParameterivEXT_func) {
+ /* these don't fit into the above mechanism, unfortunately */
+ glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max);
+ glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1);
+ if (glGetError() == GL_NONE) {
+ printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]);
+ }
+ }
+ }
+#endif
+
+#if defined(GL_ARB_vertex_program)
+ if (strstr(extensions, "GL_ARB_vertex_program")) {
+ print_program_limits(GL_VERTEX_PROGRAM_ARB);
+ }
+#endif
+#if defined(GL_ARB_fragment_program)
+ if (strstr(extensions, "GL_ARB_fragment_program")) {
+ print_program_limits(GL_FRAGMENT_PROGRAM_ARB);
+ }
+#endif
+#if defined(GL_ARB_vertex_shader)
+ if (strstr(extensions, "GL_ARB_vertex_shader")) {
+ print_shader_limits(GL_VERTEX_SHADER_ARB);
+ }
+#endif
+#if defined(GL_ARB_fragment_shader)
+ if (strstr(extensions, "GL_ARB_fragment_shader")) {
+ print_shader_limits(GL_FRAGMENT_SHADER_ARB);
+ }
+#endif
+}
+
+
+static LRESULT CALLBACK
+WndProc(HWND hWnd,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam )
+{
+ switch (uMsg) {
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ }
+
+ return 0;
+}
+
+
+static void
+print_screen_info(HDC _hdc, GLboolean limits)
+{
+ WNDCLASS wc;
+ HWND win;
+ HGLRC ctx;
+ int visinfo;
+ HDC hdc;
+ PIXELFORMATDESCRIPTOR pfd;
+
+ memset(&wc, 0, sizeof wc);
+ wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wc.lpfnWndProc = WndProc;
+ wc.lpszClassName = "wglinfo";
+ wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
+ RegisterClass(&wc);
+
+ win = CreateWindowEx(0,
+ wc.lpszClassName,
+ "wglinfo",
+ WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ NULL,
+ NULL,
+ wc.hInstance,
+ NULL);
+ if (!win) {
+ fprintf(stderr, "Couldn't create window");
+ return;
+ }
+
+ hdc = GetDC(win);
+ if (!hdc) {
+ fprintf(stderr, "Couldn't obtain HDC");
+ return;
+ }
+
+ pfd.cColorBits = 3;
+ pfd.cRedBits = 1;
+ pfd.cGreenBits = 1;
+ pfd.cBlueBits = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+
+ visinfo = ChoosePixelFormat(hdc, &pfd);
+ if (!visinfo) {
+ pfd.dwFlags |= PFD_DOUBLEBUFFER;
+ visinfo = ChoosePixelFormat(hdc, &pfd);
+ }
+
+ if (!visinfo) {
+ fprintf(stderr, "Error: couldn't find RGB WGL visual\n");
+ return;
+ }
+
+ SetPixelFormat(hdc, visinfo, &pfd);
+ ctx = wglCreateContext(hdc);
+ if (!ctx) {
+ fprintf(stderr, "Error: wglCreateContext failed\n");
+ return;
+ }
+
+ if (wglMakeCurrent(hdc, ctx)) {
+#if defined(WGL_ARB_extensions_string)
+ PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB_func =
+ (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
+#endif
+ const char *glVendor = (const char *) glGetString(GL_VENDOR);
+ const char *glRenderer = (const char *) glGetString(GL_RENDERER);
+ const char *glVersion = (const char *) glGetString(GL_VERSION);
+ const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
+
+#if defined(WGL_ARB_extensions_string)
+ if(wglGetExtensionsStringARB_func) {
+ const char *wglExtensions = wglGetExtensionsStringARB_func(hdc);
+ if(wglExtensions) {
+ printf("WGL extensions:\n");
+ print_extension_list(wglExtensions);
+ }
+ }
+#endif
+ printf("OpenGL vendor string: %s\n", glVendor);
+ printf("OpenGL renderer string: %s\n", glRenderer);
+ printf("OpenGL version string: %s\n", glVersion);
+#ifdef GL_VERSION_2_0
+ if (glVersion[0] >= '2' && glVersion[1] == '.') {
+ char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
+ printf("OpenGL shading language version string: %s\n", v);
+ }
+#endif
+
+ printf("OpenGL extensions:\n");
+ print_extension_list(glExtensions);
+ if (limits)
+ print_limits(glExtensions);
+ }
+ else {
+ fprintf(stderr, "Error: wglMakeCurrent failed\n");
+ }
+
+ DestroyWindow(win);
+}
+
+
+static const char *
+visual_render_type_name(BYTE iPixelType)
+{
+ switch (iPixelType) {
+ case PFD_TYPE_RGBA:
+ return "rgba";
+ case PFD_TYPE_COLORINDEX:
+ return "ci";
+ default:
+ return "";
+ }
+}
+
+static void
+print_visual_attribs_verbose(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
+{
+ printf("Visual ID: %x generic=%d native=%d\n",
+ iPixelFormat,
+ ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
+ ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0);
+ printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
+ 0 /* ppfd->bufferSize */, 0 /* ppfd->level */,
+ visual_render_type_name(ppfd->iPixelType),
+ ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
+ ppfd->dwFlags & PFD_STEREO ? 1 : 0);
+ printf(" rgba: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n",
+ ppfd->cRedBits, ppfd->cGreenBits,
+ ppfd->cBlueBits, ppfd->cAlphaBits);
+ printf(" cAuxBuffers=%d cDepthBits=%d cStencilBits=%d\n",
+ ppfd->cAuxBuffers, ppfd->cDepthBits, ppfd->cStencilBits);
+ printf(" accum: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n",
+ ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
+ ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits);
+ printf(" multiSample=%d multiSampleBuffers=%d\n",
+ 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */);
+}
+
+
+static void
+print_visual_attribs_short_header(void)
+{
+ printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
+ printf(" id gen nat sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n");
+ printf("-----------------------------------------------------------------------\n");
+}
+
+
+static void
+print_visual_attribs_short(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
+{
+ char *caveat = "None";
+
+ printf("0x%02x %2d %2d %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
+ iPixelFormat,
+ ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
+ ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
+ 0,
+ 0 /* ppfd->bufferSize */,
+ 0 /* ppfd->level */,
+ ppfd->iPixelType == PFD_TYPE_RGBA ? 'r' : ' ',
+ ppfd->iPixelType == PFD_TYPE_COLORINDEX ? 'c' : ' ',
+ ppfd->dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.',
+ ppfd->dwFlags & PFD_STEREO ? 'y' : '.',
+ ppfd->cRedBits, ppfd->cGreenBits,
+ ppfd->cBlueBits, ppfd->cAlphaBits,
+ ppfd->cAuxBuffers,
+ ppfd->cDepthBits,
+ ppfd->cStencilBits
+ );
+
+ printf(" %2d %2d %2d %2d %2d %1d %s\n",
+ ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
+ ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
+ 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */,
+ caveat
+ );
+}
+
+
+static void
+print_visual_attribs_long_header(void)
+{
+ printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
+ printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
+ printf("----------------------------------------------------------------------------------------------------\n");
+}
+
+
+static void
+print_visual_attribs_long(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
+{
+ printf("0x%2x %2d %11d %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
+ iPixelFormat,
+ ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
+ ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
+ 0,
+ 0 /* ppfd->bufferSize */,
+ 0 /* ppfd->level */,
+ visual_render_type_name(ppfd->iPixelType),
+ ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
+ ppfd->dwFlags & PFD_STEREO ? 1 : 0,
+ ppfd->cRedBits, ppfd->cGreenBits,
+ ppfd->cBlueBits, ppfd->cAlphaBits
+ );
+
+ printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
+ ppfd->cAuxBuffers,
+ ppfd->cDepthBits,
+ ppfd->cStencilBits,
+ ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
+ ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
+ 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */
+ );
+}
+
+
+static void
+print_visual_info(HDC hdc, InfoMode mode)
+{
+ PIXELFORMATDESCRIPTOR pfd;
+ int numVisuals, numWglVisuals;
+ int i;
+
+ numVisuals = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL);
+ if (numVisuals == 0)
+ return;
+
+ numWglVisuals = 0;
+ for (i = 0; i < numVisuals; i++) {
+ if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
+ continue;
+
+ //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
+ // continue;
+
+ ++numWglVisuals;
+ }
+
+ printf("%d WGL Visuals\n", numWglVisuals);
+
+ if (mode == Normal)
+ print_visual_attribs_short_header();
+ else if (mode == Wide)
+ print_visual_attribs_long_header();
+
+ for (i = 0; i < numVisuals; i++) {
+ if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
+ continue;
+
+ //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
+ // continue;
+
+ if (mode == Verbose)
+ print_visual_attribs_verbose(i, &pfd);
+ else if (mode == Normal)
+ print_visual_attribs_short(i, &pfd);
+ else if (mode == Wide)
+ print_visual_attribs_long(i, &pfd);
+ }
+ printf("\n");
+}
+
+
+/*
+ * Examine all visuals to find the so-called best one.
+ * We prefer deepest RGBA buffer with depth, stencil and accum
+ * that has no caveats.
+ */
+static int
+find_best_visual(HDC hdc)
+{
+#if 0
+ XVisualInfo theTemplate;
+ XVisualInfo *visuals;
+ int numVisuals;
+ long mask;
+ int i;
+ struct visual_attribs bestVis;
+
+ /* get list of all visuals on this screen */
+ theTemplate.screen = scrnum;
+ mask = VisualScreenMask;
+ visuals = XGetVisualInfo(hdc, mask, &theTemplate, &numVisuals);
+
+ /* init bestVis with first visual info */
+ get_visual_attribs(hdc, &visuals[0], &bestVis);
+
+ /* try to find a "better" visual */
+ for (i = 1; i < numVisuals; i++) {
+ struct visual_attribs vis;
+
+ get_visual_attribs(hdc, &visuals[i], &vis);
+
+ /* always skip visuals with caveats */
+ if (vis.visualCaveat != GLX_NONE_EXT)
+ continue;
+
+ /* see if this vis is better than bestVis */
+ if ((!bestVis.supportsGL && vis.supportsGL) ||
+ (bestVis.visualCaveat != GLX_NONE_EXT) ||
+ (bestVis.iPixelType != vis.iPixelType) ||
+ (!bestVis.doubleBuffer && vis.doubleBuffer) ||
+ (bestVis.cRedBits < vis.cRedBits) ||
+ (bestVis.cGreenBits < vis.cGreenBits) ||
+ (bestVis.cBlueBits < vis.cBlueBits) ||
+ (bestVis.cAlphaBits < vis.cAlphaBits) ||
+ (bestVis.cDepthBits < vis.cDepthBits) ||
+ (bestVis.cStencilBits < vis.cStencilBits) ||
+ (bestVis.cAccumRedBits < vis.cAccumRedBits)) {
+ /* found a better visual */
+ bestVis = vis;
+ }
+ }
+
+ return bestVis.id;
+#else
+ return 0;
+#endif
+}
+
+
+static void
+usage(void)
+{
+ printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
+ printf("\t-v: Print visuals info in verbose form.\n");
+ printf("\t-t: Print verbose table.\n");
+ printf("\t-h: This information.\n");
+ printf("\t-b: Find the 'best' visual and print it's number.\n");
+ printf("\t-l: Print interesting OpenGL limits.\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ HDC hdc;
+ InfoMode mode = Normal;
+ GLboolean findBest = GL_FALSE;
+ GLboolean limits = GL_FALSE;
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-t") == 0) {
+ mode = Wide;
+ }
+ else if (strcmp(argv[i], "-v") == 0) {
+ mode = Verbose;
+ }
+ else if (strcmp(argv[i], "-b") == 0) {
+ findBest = GL_TRUE;
+ }
+ else if (strcmp(argv[i], "-l") == 0) {
+ limits = GL_TRUE;
+ }
+ else if (strcmp(argv[i], "-h") == 0) {
+ usage();
+ return 0;
+ }
+ else {
+ printf("Unknown option `%s'\n", argv[i]);
+ usage();
+ return 0;
+ }
+ }
+
+ hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
+
+ if (findBest) {
+ int b;
+ b = find_best_visual(hdc);
+ printf("%d\n", b);
+ }
+ else {
+ print_screen_info(hdc, limits);
+ printf("\n");
+ print_visual_info(hdc, mode);
+ }
+
+ return 0;
+}
diff --git a/progs/wgl/wglthreads/wglthreads.c b/progs/wgl/wglthreads/wglthreads.c
new file mode 100644
index 0000000000..27dca10f2a
--- /dev/null
+++ b/progs/wgl/wglthreads/wglthreads.c
@@ -0,0 +1,636 @@
+/*
+ * Copyright (C) 2000 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Port to windows done by Michal Krol.
+ */
+
+
+/*
+ * This program tests WGL thread safety.
+ * Command line options:
+ * -h Print usage
+ * -l Enable application-side locking
+ * -n <num threads> Number of threads to create (default is 2)
+ * -t Use texture mapping
+ * -s Force single-threaded.
+ *
+ * Brian Paul 20 July 2000
+ */
+
+
+/*
+ * Notes:
+ * - Each thread gets its own WGL context.
+ *
+ * - The WGL contexts share texture objects.
+ *
+ * - When 't' is pressed to update the texture image, the window/thread which
+ * has input focus is signalled to change the texture. The other threads
+ * should see the updated texture the next time they call glBindTexture.
+ */
+
+
+#include <assert.h>
+#include <windows.h>
+#include <GL/gl.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#pragma comment(lib, "opengl32.lib")
+
+
+/*
+ * Each window/thread/context:
+ */
+struct winthread {
+ int Index;
+ HANDLE Thread;
+ HWND Win;
+ HDC hDC;
+ HGLRC Context;
+ float Angle;
+ int WinWidth, WinHeight;
+ GLboolean NewSize;
+ HANDLE hEventInitialised;
+ GLboolean Initialized;
+ GLboolean MakeNewTexture;
+ HANDLE hEventRedraw;
+};
+
+
+#define MAX_WINTHREADS 100
+static struct winthread WinThreads[MAX_WINTHREADS];
+static int NumWinThreads = 2;
+static HANDLE ExitEvent = NULL;
+
+static GLboolean Locking = 0;
+static GLboolean Texture = GL_FALSE;
+static GLboolean SingleThreaded = GL_FALSE;
+static GLuint TexObj = 12;
+static GLboolean Animate = GL_TRUE;
+
+static CRITICAL_SECTION Mutex;
+
+
+static void
+Error(const char *msg)
+{
+ fprintf(stderr, "Error: %s\n", msg);
+ exit(1);
+}
+
+
+static void
+signal_redraw(void)
+{
+ int i;
+
+ for (i = 0; i < NumWinThreads; i++) {
+ SetEvent(WinThreads[i].hEventRedraw);
+ }
+}
+
+
+static void
+MakeNewTexture(struct winthread *wt)
+{
+#define TEX_SIZE 128
+ static float step = 0.0f;
+ GLfloat image[TEX_SIZE][TEX_SIZE][4];
+ GLint width;
+ int i, j;
+
+ for (j = 0; j < TEX_SIZE; j++) {
+ for (i = 0; i < TEX_SIZE; i++) {
+ float dt = 5.0f * (j - 0.5f * TEX_SIZE) / TEX_SIZE;
+ float ds = 5.0f * (i - 0.5f * TEX_SIZE) / TEX_SIZE;
+ float r = dt * dt + ds * ds + step;
+ image[j][i][0] =
+ image[j][i][1] =
+ image[j][i][2] = 0.75f + 0.25f * (float) cos(r);
+ image[j][i][3] = 1.0f;
+ }
+ }
+
+ step += 0.5;
+
+ glBindTexture(GL_TEXTURE_2D, TexObj);
+
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
+ if (width) {
+ assert(width == TEX_SIZE);
+ /* sub-tex replace */
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE,
+ GL_RGBA, GL_FLOAT, image);
+ }
+ else {
+ /* create new */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0,
+ GL_RGBA, GL_FLOAT, image);
+ }
+}
+
+
+
+/* draw a colored cube */
+static void
+draw_object(void)
+{
+ glPushMatrix();
+ glScalef(0.75f, 0.75f, 0.75f);
+
+ glColor3f(1, 0, 0);
+
+ if (Texture) {
+ glBindTexture(GL_TEXTURE_2D, TexObj);
+ glEnable(GL_TEXTURE_2D);
+ }
+ else {
+ glDisable(GL_TEXTURE_2D);
+ }
+
+ glBegin(GL_QUADS);
+
+ /* -X */
+ glColor3f(0, 1, 1);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f(-1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
+
+ /* +X */
+ glColor3f(1, 0, 0);
+ glTexCoord2f(0, 0); glVertex3f(1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f(1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(1, -1, 1);
+
+ /* -Y */
+ glColor3f(1, 0, 1);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, -1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
+
+ /* +Y */
+ glColor3f(0, 1, 0);
+ glTexCoord2f(0, 0); glVertex3f(-1, 1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, 1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
+
+ /* -Z */
+ glColor3f(1, 1, 0);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, -1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, -1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, -1);
+
+ /* +Y */
+ glColor3f(0, 0, 1);
+ glTexCoord2f(0, 0); glVertex3f(-1, -1, 1);
+ glTexCoord2f(1, 0); glVertex3f( 1, -1, 1);
+ glTexCoord2f(1, 1); glVertex3f( 1, 1, 1);
+ glTexCoord2f(0, 1); glVertex3f(-1, 1, 1);
+
+ glEnd();
+
+ glPopMatrix();
+}
+
+
+/* signal resize of given window */
+static void
+resize(struct winthread *wt, int w, int h)
+{
+ wt->NewSize = GL_TRUE;
+ wt->WinWidth = w;
+ wt->WinHeight = h;
+ if (!Animate)
+ SetEvent(wt->hEventRedraw);
+}
+
+
+/*
+ * We have an instance of this for each thread.
+ */
+static void
+draw_loop(struct winthread *wt)
+{
+ while (1) {
+ GLboolean draw = Animate;
+ MSG msg;
+
+ if (Animate) {
+ /* wait 5 ms for signal either to exit or process messages */
+ switch (MsgWaitForMultipleObjects(1, &ExitEvent, FALSE, 5, QS_ALLINPUT)) {
+ case WAIT_OBJECT_0:
+ SendMessage(wt->Win, WM_CLOSE, 0, 0);
+ break;
+ case WAIT_OBJECT_0 + 1:
+ break;
+ }
+ }
+ else {
+ HANDLE events[2];
+
+ events[0] = wt->hEventRedraw;
+ events[1] = ExitEvent;
+
+ /* wait for signal either to draw, exit or process messages */
+ switch (MsgWaitForMultipleObjects(2, events, FALSE, INFINITE, QS_ALLINPUT)) {
+ case WAIT_OBJECT_0:
+ draw = GL_TRUE;
+ break;
+ case WAIT_OBJECT_0 + 1:
+ SendMessage(wt->Win, WM_CLOSE, 0, 0);
+ break;
+ case WAIT_OBJECT_0 + 2:
+ break;
+ }
+ }
+
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_QUIT) {
+ return;
+ }
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ if (!draw)
+ continue;
+
+ if (Locking)
+ EnterCriticalSection(&Mutex);
+
+ wglMakeCurrent(wt->hDC, wt->Context);
+
+ if (!wt->Initialized) {
+ printf("wglthreads: %d: GL_RENDERER = %s\n", wt->Index,
+ (char *) glGetString(GL_RENDERER));
+ if (Texture /*&& wt->Index == 0*/) {
+ MakeNewTexture(wt);
+ }
+ wt->Initialized = GL_TRUE;
+ }
+
+ if (Locking)
+ LeaveCriticalSection(&Mutex);
+
+ glEnable(GL_DEPTH_TEST);
+
+ if (wt->NewSize) {
+ GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight;
+ glViewport(0, 0, wt->WinWidth, wt->WinHeight);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-w, w, -1.0, 1.0, 1.5, 10);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0, 0, -2.5);
+ wt->NewSize = GL_FALSE;
+ }
+
+ if (wt->MakeNewTexture) {
+ MakeNewTexture(wt);
+ wt->MakeNewTexture = GL_FALSE;
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotatef(wt->Angle, 0, 1, 0);
+ glRotatef(wt->Angle, 1, 0, 0);
+ glScalef(0.7f, 0.7f, 0.7f);
+ draw_object();
+ glPopMatrix();
+
+ if (Locking)
+ EnterCriticalSection(&Mutex);
+
+ SwapBuffers(wt->hDC);
+
+ if (Locking)
+ LeaveCriticalSection(&Mutex);
+
+ wt->Angle += 1.0;
+ }
+}
+
+
+static void
+keypress(WPARAM keySym, struct winthread *wt)
+{
+ switch (keySym) {
+ case VK_ESCAPE:
+ /* tell all threads to exit */
+ SetEvent(ExitEvent);
+ /*printf("exit draw_loop %d\n", wt->Index);*/
+ return;
+ case 't':
+ case 'T':
+ if (Texture) {
+ wt->MakeNewTexture = GL_TRUE;
+ if (!Animate)
+ signal_redraw();
+ }
+ break;
+ case 'a':
+ case 'A':
+ Animate = !Animate;
+ if (Animate)
+ signal_redraw();
+ break;
+ case 's':
+ case 'S':
+ if (!Animate)
+ signal_redraw();
+ break;
+ default:
+ ; /* nop */
+ }
+}
+
+
+static LRESULT CALLBACK
+WndProc(HWND hWnd,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam )
+{
+ int i;
+
+ switch (uMsg) {
+ case WM_KEYDOWN:
+ for (i = 0; i < NumWinThreads; i++) {
+ struct winthread *wt = &WinThreads[i];
+
+ if (hWnd == wt->Win) {
+ keypress(wParam, wt);
+ break;
+ }
+ }
+ break;
+ case WM_SIZE:
+ for (i = 0; i < NumWinThreads; i++) {
+ struct winthread *wt = &WinThreads[i];
+
+ if (hWnd == wt->Win) {
+ RECT r;
+
+ GetClientRect(hWnd, &r);
+ resize(wt, r.right, r.bottom);
+ break;
+ }
+ }
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ }
+
+ return 0;
+}
+
+/*
+ * we'll call this once for each thread, before the threads are created.
+ */
+static void
+create_window(struct winthread *wt, HGLRC shareCtx)
+{
+ WNDCLASS wc = {0};
+ int width = 160, height = 160;
+ int xpos = (wt->Index % 8) * (width + 10);
+ int ypos = (wt->Index / 8) * (width + 20);
+ HWND win;
+ HDC hdc;
+ PIXELFORMATDESCRIPTOR pfd = {0};
+ int visinfo;
+ HGLRC ctx;
+
+ wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wc.lpfnWndProc = WndProc;
+ wc.lpszClassName = "wglthreads";
+ wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
+ RegisterClass(&wc);
+
+ win = CreateWindowEx(0,
+ wc.lpszClassName,
+ "wglthreads",
+ WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TILEDWINDOW,
+ xpos,
+ ypos,
+ width,
+ height,
+ NULL,
+ NULL,
+ wc.hInstance,
+ (LPVOID) wt);
+ if (!win) {
+ Error("Couldn't create window");
+ }
+
+ hdc = GetDC(win);
+ if (!hdc) {
+ Error("Couldn't obtain HDC");
+ }
+
+ pfd.cColorBits = 24;
+ pfd.cDepthBits = 24;
+ pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+
+ visinfo = ChoosePixelFormat(hdc, &pfd);
+ if (!visinfo) {
+ Error("Unable to find RGB, Z, double-buffered visual");
+ }
+
+ SetPixelFormat(hdc, visinfo, &pfd);
+ ctx = wglCreateContext(hdc);
+ if (!ctx) {
+ Error("Couldn't create WGL context");
+ }
+
+ if (shareCtx) {
+ if(!wglShareLists(shareCtx, ctx))
+ Error("Couldn't share WGL context lists");
+ }
+
+ /* save the info for this window/context */
+ wt->Win = win;
+ wt->hDC = hdc;
+ wt->Context = ctx;
+ wt->Angle = 0.0;
+ wt->WinWidth = width;
+ wt->WinHeight = height;
+ wt->NewSize = GL_TRUE;
+}
+
+
+/*
+ * Called by pthread_create()
+ */
+static DWORD WINAPI
+ThreadProc(void *p)
+{
+ struct winthread *wt = (struct winthread *) p;
+ HGLRC share;
+
+ /* Wait for the previous thread */
+ if(Texture && wt->Index > 0) {
+ WaitForSingleObject(WinThreads[wt->Index - 1].hEventInitialised, INFINITE);
+ share = WinThreads[0].Context;
+ }
+ else
+ share = 0;
+
+ share = (Texture && wt->Index > 0) ? WinThreads[0].Context : 0;
+ create_window(wt, share);
+ SetEvent(wt->hEventInitialised);
+
+ /* Wait for all threads to initialize otherwise wglShareLists will fail */
+ if(wt->Index < NumWinThreads - 1)
+ WaitForSingleObject(WinThreads[NumWinThreads - 1].hEventInitialised, INFINITE);
+
+ draw_loop(wt);
+ return 0;
+}
+
+
+static void
+usage(void)
+{
+ printf("wglthreads: test of GL thread safety (any key = exit)\n");
+ printf("Usage:\n");
+ printf(" wglthreads [options]\n");
+ printf("Options:\n");
+ printf(" -h Show this usage screen\n");
+ printf(" -n NUMTHREADS Number of threads to create\n");
+ printf(" -l Use application-side locking\n");
+ printf(" -t Enable texturing\n");
+ printf(" -s Force single-threaded\n");
+ printf("Keyboard:\n");
+ printf(" Esc Exit\n");
+ printf(" t Change texture image (requires -t option)\n");
+ printf(" a Toggle animation\n");
+ printf(" s Step rotation (when not animating)\n");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-h") == 0) {
+ usage();
+ exit(0);
+ }
+ else if (strcmp(argv[i], "-l") == 0) {
+ Locking = 1;
+ }
+ else if (strcmp(argv[i], "-t") == 0) {
+ Texture = 1;
+ }
+ else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) {
+ NumWinThreads = atoi(argv[i + 1]);
+ if (NumWinThreads < 1)
+ NumWinThreads = 1;
+ else if (NumWinThreads > MAX_WINTHREADS)
+ NumWinThreads = MAX_WINTHREADS;
+ i++;
+ }
+ else if (strcmp(argv[i], "-s") == 0) {
+ SingleThreaded = GL_TRUE;
+ }
+ else {
+ usage();
+ exit(1);
+ }
+ }
+
+ if (SingleThreaded)
+ printf("wglthreads: Forcing single-threaded, no other threads will be created.\n");
+
+ if (Locking)
+ printf("wglthreads: Using explicit locks around WGL calls.\n");
+ else
+ printf("wglthreads: No explict locking.\n");
+
+ InitializeCriticalSection(&Mutex);
+ ExitEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+
+ if (SingleThreaded) {
+ NumWinThreads = 1;
+
+ WinThreads[0].Index = 0;
+ WinThreads[0].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL);
+ WinThreads[0].hEventRedraw = CreateEvent(NULL, FALSE, FALSE, NULL);
+
+ ThreadProc((void*) &WinThreads[0]);
+ }
+ else {
+ HANDLE threads[MAX_WINTHREADS];
+
+ printf("wglthreads: creating threads\n");
+
+ /* Create the events */
+ for (i = 0; i < NumWinThreads; i++) {
+ WinThreads[i].Index = i;
+ WinThreads[i].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL);
+ WinThreads[i].hEventRedraw = CreateEvent(NULL, FALSE, FALSE, NULL);
+ }
+
+ /* Create the threads */
+ for (i = 0; i < NumWinThreads; i++) {
+ DWORD id;
+
+ WinThreads[i].Thread = CreateThread(NULL,
+ 0,
+ ThreadProc,
+ (void*) &WinThreads[i],
+ 0,
+ &id);
+ printf("wglthreads: Created thread %p\n", (void *) WinThreads[i].Thread);
+
+ threads[i] = WinThreads[i].Thread;
+ }
+
+ /* Wait for all threads to finish. */
+ WaitForMultipleObjects(NumWinThreads, threads, TRUE, INFINITE);
+ }
+
+ return 0;
+}