17ec681f3Smrg/**************************************************************************
27ec681f3Smrg *
37ec681f3Smrg * Copyright 2008 VMware, Inc.
47ec681f3Smrg * All Rights Reserved.
57ec681f3Smrg *
67ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
77ec681f3Smrg * copy of this software and associated documentation files (the
87ec681f3Smrg * "Software"), to deal in the Software without restriction, including
97ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish,
107ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to
117ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to
127ec681f3Smrg * the following conditions:
137ec681f3Smrg *
147ec681f3Smrg * The above copyright notice and this permission notice (including the
157ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions
167ec681f3Smrg * of the Software.
177ec681f3Smrg *
187ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
197ec681f3Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
207ec681f3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
217ec681f3Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
227ec681f3Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
237ec681f3Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
247ec681f3Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
257ec681f3Smrg *
267ec681f3Smrg **************************************************************************/
277ec681f3Smrg
287ec681f3Smrg#include <windows.h>
297ec681f3Smrg
307ec681f3Smrg#define WGL_WGLEXT_PROTOTYPES
317ec681f3Smrg
327ec681f3Smrg#include <GL/gl.h>
337ec681f3Smrg#include <GL/wglext.h>
347ec681f3Smrg
357ec681f3Smrg#include "glapi/glapi.h"
367ec681f3Smrg#include "stw_device.h"
377ec681f3Smrg#include "gldrv.h"
387ec681f3Smrg#include "stw_nopfuncs.h"
397ec681f3Smrg
407ec681f3Smrg#include "util/u_debug.h"
417ec681f3Smrg
427ec681f3Smrgstruct stw_extension_entry
437ec681f3Smrg{
447ec681f3Smrg   const char *name;
457ec681f3Smrg   PROC proc;
467ec681f3Smrg};
477ec681f3Smrg
487ec681f3Smrg#define STW_EXTENSION_ENTRY(P) { #P, (PROC) P }
497ec681f3Smrg
507ec681f3Smrgstatic const struct stw_extension_entry stw_extension_entries[] = {
517ec681f3Smrg
527ec681f3Smrg   /* WGL_ARB_extensions_string */
537ec681f3Smrg   STW_EXTENSION_ENTRY( wglGetExtensionsStringARB ),
547ec681f3Smrg
557ec681f3Smrg   /* WGL_ARB_pbuffer */
567ec681f3Smrg   STW_EXTENSION_ENTRY( wglCreatePbufferARB ),
577ec681f3Smrg   STW_EXTENSION_ENTRY( wglGetPbufferDCARB ),
587ec681f3Smrg   STW_EXTENSION_ENTRY( wglReleasePbufferDCARB ),
597ec681f3Smrg   STW_EXTENSION_ENTRY( wglDestroyPbufferARB ),
607ec681f3Smrg   STW_EXTENSION_ENTRY( wglQueryPbufferARB ),
617ec681f3Smrg
627ec681f3Smrg   /* WGL_ARB_pixel_format */
637ec681f3Smrg   STW_EXTENSION_ENTRY( wglChoosePixelFormatARB ),
647ec681f3Smrg   STW_EXTENSION_ENTRY( wglGetPixelFormatAttribfvARB ),
657ec681f3Smrg   STW_EXTENSION_ENTRY( wglGetPixelFormatAttribivARB ),
667ec681f3Smrg
677ec681f3Smrg   /* WGL_EXT_extensions_string */
687ec681f3Smrg   STW_EXTENSION_ENTRY( wglGetExtensionsStringEXT ),
697ec681f3Smrg
707ec681f3Smrg   /* WGL_EXT_swap_control */
717ec681f3Smrg   STW_EXTENSION_ENTRY( wglGetSwapIntervalEXT ),
727ec681f3Smrg   STW_EXTENSION_ENTRY( wglSwapIntervalEXT ),
737ec681f3Smrg
747ec681f3Smrg   /* WGL_ARB_create_context */
757ec681f3Smrg   STW_EXTENSION_ENTRY( wglCreateContextAttribsARB ),
767ec681f3Smrg
777ec681f3Smrg   /* WGL_ARB_render_texture */
787ec681f3Smrg   STW_EXTENSION_ENTRY( wglBindTexImageARB ),
797ec681f3Smrg   STW_EXTENSION_ENTRY( wglReleaseTexImageARB ),
807ec681f3Smrg   STW_EXTENSION_ENTRY( wglSetPbufferAttribARB ),
817ec681f3Smrg
827ec681f3Smrg   /*  WGL_ARB_make_current_read */
837ec681f3Smrg   STW_EXTENSION_ENTRY( wglMakeContextCurrentARB ),
847ec681f3Smrg   STW_EXTENSION_ENTRY( wglGetCurrentReadDCARB ),
857ec681f3Smrg   { NULL, NULL }
867ec681f3Smrg};
877ec681f3Smrg
887ec681f3SmrgPROC APIENTRY
897ec681f3SmrgDrvGetProcAddress(
907ec681f3Smrg   LPCSTR lpszProc )
917ec681f3Smrg{
927ec681f3Smrg   const struct stw_extension_entry *entry;
937ec681f3Smrg   PROC p;
947ec681f3Smrg
957ec681f3Smrg   if (!stw_dev)
967ec681f3Smrg      return NULL;
977ec681f3Smrg
987ec681f3Smrg   if (lpszProc[0] == 'w' && lpszProc[1] == 'g' && lpszProc[2] == 'l')
997ec681f3Smrg      for (entry = stw_extension_entries; entry->name; entry++)
1007ec681f3Smrg         if (strcmp( lpszProc, entry->name ) == 0)
1017ec681f3Smrg            return entry->proc;
1027ec681f3Smrg
1037ec681f3Smrg   if (lpszProc[0] == 'g' && lpszProc[1] == 'l') {
1047ec681f3Smrg      p = (PROC) _glapi_get_proc_address(lpszProc);
1057ec681f3Smrg      if (p)
1067ec681f3Smrg         return p;
1077ec681f3Smrg   }
1087ec681f3Smrg
1097ec681f3Smrg   /* If we get here, we'd normally just return NULL, but since some apps
1107ec681f3Smrg    * (like Viewperf12) crash when they try to use the null pointer, try
1117ec681f3Smrg    * returning a pointer to a no-op function instead.
1127ec681f3Smrg    */
1137ec681f3Smrg   p = stw_get_nop_function(lpszProc);
1147ec681f3Smrg   if (p) {
1157ec681f3Smrg      debug_printf("wglGetProcAddress(\"%s\") returning no-op function\n",
1167ec681f3Smrg                   lpszProc);
1177ec681f3Smrg      return p;
1187ec681f3Smrg   }
1197ec681f3Smrg
1207ec681f3Smrg   debug_printf("wglGetProcAddress(\"%s\") returning NULL\n", lpszProc);
1217ec681f3Smrg   return NULL;
1227ec681f3Smrg}
123