Commit 036c4b73 authored by Lionel Ulmer's avatar Lionel Ulmer Committed by Alexandre Julliard

Beginning of infrastructure to support WGL extensions.

parent 3b659d16
...@@ -8,9 +8,10 @@ EXTRAINCL = @X_CFLAGS@ ...@@ -8,9 +8,10 @@ EXTRAINCL = @X_CFLAGS@
EXTRALIBS = @X_LIBS@ @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@ @OPENGL_LIBS@ EXTRALIBS = @X_LIBS@ @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@ @OPENGL_LIBS@
C_SRCS = \ C_SRCS = \
wgl.c \ opengl_ext.c \
opengl_norm.c \ opengl_norm.c \
opengl_ext.c wgl.c \
wgl_ext.c
@MAKE_DLL_RULES@ @MAKE_DLL_RULES@
......
...@@ -544,8 +544,6 @@ print SPEC "@ stdcall wglCreateContext(long) ...@@ -544,8 +544,6 @@ print SPEC "@ stdcall wglCreateContext(long)
@ stdcall wglDescribeLayerPlane(long long long long ptr) @ stdcall wglDescribeLayerPlane(long long long long ptr)
@ stdcall wglGetCurrentContext() @ stdcall wglGetCurrentContext()
@ stdcall wglGetCurrentDC() @ stdcall wglGetCurrentDC()
@ stdcall wglGetExtensionsStringEXT()
@ stdcall wglGetExtensionsStringARB(long)
@ stdcall wglGetLayerPaletteEntries(long long long long ptr) @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
@ stdcall wglGetProcAddress(str) @ stdcall wglGetProcAddress(str)
@ stdcall wglMakeCurrent(long long) @ stdcall wglMakeCurrent(long long)
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
@ stdcall wglDescribeLayerPlane(long long long long ptr) @ stdcall wglDescribeLayerPlane(long long long long ptr)
@ stdcall wglGetCurrentContext() @ stdcall wglGetCurrentContext()
@ stdcall wglGetCurrentDC() @ stdcall wglGetCurrentDC()
@ stdcall wglGetExtensionsStringEXT()
@ stdcall wglGetExtensionsStringARB(long)
@ stdcall wglGetLayerPaletteEntries(long long long long ptr) @ stdcall wglGetLayerPaletteEntries(long long long long ptr)
@ stdcall wglGetProcAddress(str) @ stdcall wglGetProcAddress(str)
@ stdcall wglMakeCurrent(long long) @ stdcall wglMakeCurrent(long long)
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "winerror.h" #include "winerror.h"
#include "wgl.h" #include "wgl.h"
#include "wgl_ext.h"
#include "opengl_ext.h" #include "opengl_ext.h"
#include "wine/library.h" #include "wine/library.h"
#include "wine/debug.h" #include "wine/debug.h"
...@@ -302,6 +303,11 @@ static int compar(const void *elt_a, const void *elt_b) { ...@@ -302,6 +303,11 @@ static int compar(const void *elt_a, const void *elt_b) {
((OpenGL_extension *) elt_b)->name); ((OpenGL_extension *) elt_b)->name);
} }
static int wgl_compar(const void *elt_a, const void *elt_b) {
return strcmp(((WGL_extension *) elt_a)->func_name,
((WGL_extension *) elt_b)->func_name);
}
void* WINAPI wglGetProcAddress(LPCSTR lpszProc) { void* WINAPI wglGetProcAddress(LPCSTR lpszProc) {
void *local_func; void *local_func;
static HMODULE hm = 0; static HMODULE hm = 0;
...@@ -331,6 +337,14 @@ void* WINAPI wglGetProcAddress(LPCSTR lpszProc) { ...@@ -331,6 +337,14 @@ void* WINAPI wglGetProcAddress(LPCSTR lpszProc) {
extension_registry_size, sizeof(OpenGL_extension), compar); extension_registry_size, sizeof(OpenGL_extension), compar);
if (ext_ret == NULL) { if (ext_ret == NULL) {
WGL_extension wgl_ext, *wgl_ext_ret;
/* Try to find the function in the WGL extensions ... */
wgl_ext.func_name = (char *) lpszProc;
wgl_ext_ret = (WGL_extension *) bsearch(&wgl_ext, wgl_extension_registry,
wgl_extension_registry_size, sizeof(WGL_extension), wgl_compar);
if (wgl_ext_ret == NULL) {
/* Some sanity checks :-) */ /* Some sanity checks :-) */
ENTER_GL(); ENTER_GL();
local_func = p_glXGetProcAddressARB(lpszProc); local_func = p_glXGetProcAddressARB(lpszProc);
...@@ -343,6 +357,26 @@ void* WINAPI wglGetProcAddress(LPCSTR lpszProc) { ...@@ -343,6 +357,26 @@ void* WINAPI wglGetProcAddress(LPCSTR lpszProc) {
WARN("Did not find extension %s in either Wine or your OpenGL library.\n", lpszProc); WARN("Did not find extension %s in either Wine or your OpenGL library.\n", lpszProc);
return NULL; return NULL;
} else { } else {
void *ret = NULL;
if (wgl_ext_ret->func_init != NULL) {
const char *err_msg;
if ((err_msg = wgl_ext_ret->func_init(p_glXGetProcAddressARB,
wgl_ext_ret->context)) == NULL) {
ret = wgl_ext_ret->func_address;
} else {
WARN("Error when getting WGL extension '%s' : %s.\n", debugstr_a(lpszProc), err_msg);
return NULL;
}
} else {
ret = wgl_ext_ret->func_address;
}
if (ret)
TRACE(" returning WGL function (%p)\n", ret);
return ret;
}
} else {
ENTER_GL(); ENTER_GL();
local_func = p_glXGetProcAddressARB(ext_ret->glx_name); local_func = p_glXGetProcAddressARB(ext_ret->glx_name);
LEAVE_GL(); LEAVE_GL();
...@@ -713,41 +747,26 @@ static BOOL process_attach(void) ...@@ -713,41 +747,26 @@ static BOOL process_attach(void)
TRACE("could not find glXGetProcAddressARB in libGL.\n"); TRACE("could not find glXGetProcAddressARB in libGL.\n");
} }
/* Initialize also the list of supported WGL extensions. */
wgl_ext_initialize_extensions(default_display, DefaultScreen(default_display));
if (default_cx == NULL) { if (default_cx == NULL) {
ERR("Could not create default context.\n"); ERR("Could not create default context.\n");
} }
return TRUE; return TRUE;
} }
/**********************************************************************/
/* Some WGL extensions... */
static const char *WGL_extensions = "WGL_ARB_extensions_string WGL_EXT_extensions_string";
/**********************************************************************/
const char * WINAPI wglGetExtensionsStringEXT(void) {
TRACE("() returning \"%s\"\n", WGL_extensions);
return WGL_extensions;
}
/**********************************************************************/ /**********************************************************************/
static void process_detach(void) static void process_detach(void)
{ {
glXDestroyContext(default_display, default_cx); glXDestroyContext(default_display, default_cx);
}
/*********************************************************************** /* Do not leak memory... */
* wglGetExtensionsStringARB(OPENGL32.@) wgl_ext_finalize_extensions();
*/
const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
return wglGetExtensionsStringEXT();
} }
/*********************************************************************** /***********************************************************************
* OpenGL initialisation routine * OpenGL initialisation routine
*/ */
......
/* Support for window-specific OpenGL extensions.
*
* Copyright (c) 2004 Lionel Ulmer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winerror.h"
#include "wgl.h"
#include "wgl_ext.h"
#include "opengl_ext.h"
#include "wine/library.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(opengl);
/* Some WGL extensions... */
static const char *WGL_extensions_base = "WGL_ARB_extensions_string WGL_EXT_extensions_string";
static char *WGL_extensions = NULL;
/* Extensions-query functions */
BOOL query_function_pbuffers(const char *gl_version, const char *gl_extensions, const char *glx_extensions,
const char *server_glx_extensions, const char *client_glx_extensions)
{
return FALSE;
}
/***********************************************************************
* wglGetExtensionsStringEXT(OPENGL32.@)
*/
const char * WINAPI wglGetExtensionsStringEXT(void) {
TRACE("() returning \"%s\"\n", WGL_extensions);
return WGL_extensions;
}
/***********************************************************************
* wglGetExtensionsStringARB(OPENGL32.@)
*/
const char * WINAPI wglGetExtensionsStringARB(HDC hdc) {
TRACE("() returning \"%s\"\n", WGL_extensions);
return WGL_extensions;
}
static const struct {
const char *name;
BOOL (*query_function)(const char *gl_version, const char *gl_extensions, const char *glx_extensions,
const char *server_glx_extensions, const char *client_glx_extensions);
} extension_list[] = {
{ "WGL_ARB_pbuffer", query_function_pbuffers }
};
/* Used to initialize the WGL extension string at DLL loading */
void wgl_ext_initialize_extensions(Display *display, int screen)
{
int size = strlen(WGL_extensions_base);
const char *glx_extensions = glXQueryExtensionsString(display, screen);
const char *server_glx_extensions = glXQueryServerString(display, screen, GLX_EXTENSIONS);
const char *client_glx_extensions = glXGetClientString(display, GLX_EXTENSIONS);
const char *gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
const char *gl_version = (const char *) glGetString(GL_VERSION);
int i;
TRACE("GL version : %s.\n", debugstr_a(gl_version));
TRACE("GL exts : %s.\n", debugstr_a(gl_extensions));
TRACE("GLX exts : %s.\n", debugstr_a(glx_extensions));
TRACE("Server GLX exts : %s.\n", debugstr_a(server_glx_extensions));
TRACE("Client GLX exts : %s.\n", debugstr_a(client_glx_extensions));
for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
if (extension_list[i].query_function(gl_version, gl_extensions, glx_extensions,
server_glx_extensions, client_glx_extensions)) {
size += strlen(extension_list[i].name) + 1;
}
}
/* For the moment, only 'base' extensions are supported. */
WGL_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 1);
if (WGL_extensions == NULL) {
WGL_extensions = (char *) WGL_extensions_base;
} else {
strcpy(WGL_extensions, WGL_extensions_base);
for (i = 0; i < (sizeof(extension_list) / sizeof(extension_list[0])); i++) {
if (extension_list[i].query_function(gl_version, gl_extensions, glx_extensions,
server_glx_extensions, client_glx_extensions)) {
strcat(WGL_extensions, " ");
strcat(WGL_extensions, extension_list[i].name);
}
}
}
TRACE("Supporting following WGL extensions : %s.\n", debugstr_a(WGL_extensions));
}
void wgl_ext_finalize_extensions(void)
{
if (WGL_extensions != WGL_extensions_base) {
HeapFree(GetProcessHeap(), 0, WGL_extensions);
}
}
/* Putting this at the end to prevent having to write the prototypes :-) */
WGL_extension wgl_extension_registry[] = {
{ "wglGetExtensionsStringARB", (void *) wglGetExtensionsStringARB, NULL, NULL},
{ "wglGetExtensionsStringEXT", (void *) wglGetExtensionsStringEXT, NULL, NULL}
};
int wgl_extension_registry_size = sizeof(wgl_extension_registry) / sizeof(wgl_extension_registry[0]);
/* Support for window-specific OpenGL extensions.
*
* Copyright (c) 2004 Lionel Ulmer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __DLLS_OPENGL32_WGL_EXT_H
#define __DLLS_OPENGL32_WGL_EXT_H
#include "opengl_ext.h"
/* Used to initialize the WGL extension string at DLL loading */
void wgl_ext_initialize_extensions(Display *display, int screen);
void wgl_ext_finalize_extensions(void);
typedef struct {
const char *func_name;
void *func_address;
const char *(*func_init)(void *(*p_glXGetProcAddressARB)(const GLubyte *), void *context);
void *context;
} WGL_extension;
extern WGL_extension wgl_extension_registry[];
extern int wgl_extension_registry_size;
#endif /* __DLLS_OPENGL32_WGL_EXT_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment