1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include <windows.h>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#define WGL_WGLEXT_PROTOTYPES
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include <GL/gl.h>
33bf215546Sopenharmony_ci#include <GL/wglext.h>
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include "pipe/p_compiler.h"
36bf215546Sopenharmony_ci#include "pipe/p_context.h"
37bf215546Sopenharmony_ci#include "pipe/p_state.h"
38bf215546Sopenharmony_ci#include "util/compiler.h"
39bf215546Sopenharmony_ci#include "util/u_memory.h"
40bf215546Sopenharmony_ci#include "util/u_atomic.h"
41bf215546Sopenharmony_ci#include "hud/hud_context.h"
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci#include "gldrv.h"
44bf215546Sopenharmony_ci#include "stw_device.h"
45bf215546Sopenharmony_ci#include "stw_winsys.h"
46bf215546Sopenharmony_ci#include "stw_framebuffer.h"
47bf215546Sopenharmony_ci#include "stw_pixelformat.h"
48bf215546Sopenharmony_ci#include "stw_context.h"
49bf215546Sopenharmony_ci#include "stw_tls.h"
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_cistruct stw_context *
53bf215546Sopenharmony_cistw_current_context(void)
54bf215546Sopenharmony_ci{
55bf215546Sopenharmony_ci   struct st_context_iface *st;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci   st = (stw_dev) ? stw_dev->stapi->get_current(stw_dev->stapi) : NULL;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci   return (struct stw_context *) ((st) ? st->st_manager_private : NULL);
60bf215546Sopenharmony_ci}
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ciBOOL APIENTRY
64bf215546Sopenharmony_ciDrvCopyContext(DHGLRC dhrcSource, DHGLRC dhrcDest, UINT fuMask)
65bf215546Sopenharmony_ci{
66bf215546Sopenharmony_ci   struct stw_context *src;
67bf215546Sopenharmony_ci   struct stw_context *dst;
68bf215546Sopenharmony_ci   BOOL ret = FALSE;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   if (!stw_dev)
71bf215546Sopenharmony_ci      return FALSE;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci   stw_lock_contexts(stw_dev);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   src = stw_lookup_context_locked( dhrcSource );
76bf215546Sopenharmony_ci   dst = stw_lookup_context_locked( dhrcDest );
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   if (src && dst) {
79bf215546Sopenharmony_ci      /* FIXME */
80bf215546Sopenharmony_ci      assert(0);
81bf215546Sopenharmony_ci      (void) src;
82bf215546Sopenharmony_ci      (void) dst;
83bf215546Sopenharmony_ci      (void) fuMask;
84bf215546Sopenharmony_ci   }
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   stw_unlock_contexts(stw_dev);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   return ret;
89bf215546Sopenharmony_ci}
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ciBOOL APIENTRY
93bf215546Sopenharmony_ciDrvShareLists(DHGLRC dhglrc1, DHGLRC dhglrc2)
94bf215546Sopenharmony_ci{
95bf215546Sopenharmony_ci   struct stw_context *ctx1;
96bf215546Sopenharmony_ci   struct stw_context *ctx2;
97bf215546Sopenharmony_ci   BOOL ret = FALSE;
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci   if (!stw_dev)
100bf215546Sopenharmony_ci      return FALSE;
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   stw_lock_contexts(stw_dev);
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci   ctx1 = stw_lookup_context_locked( dhglrc1 );
105bf215546Sopenharmony_ci   ctx2 = stw_lookup_context_locked( dhglrc2 );
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci   if (ctx1 && ctx2 && ctx2->st->share) {
108bf215546Sopenharmony_ci      ret = ctx2->st->share(ctx2->st, ctx1->st);
109bf215546Sopenharmony_ci      ctx1->shared = TRUE;
110bf215546Sopenharmony_ci      ctx2->shared = TRUE;
111bf215546Sopenharmony_ci   }
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci   stw_unlock_contexts(stw_dev);
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   return ret;
116bf215546Sopenharmony_ci}
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ciDHGLRC APIENTRY
120bf215546Sopenharmony_ciDrvCreateContext(HDC hdc)
121bf215546Sopenharmony_ci{
122bf215546Sopenharmony_ci   return DrvCreateLayerContext( hdc, 0 );
123bf215546Sopenharmony_ci}
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ciDHGLRC APIENTRY
127bf215546Sopenharmony_ciDrvCreateLayerContext(HDC hdc, INT iLayerPlane)
128bf215546Sopenharmony_ci{
129bf215546Sopenharmony_ci   struct stw_context *ctx = stw_create_context_attribs(hdc, iLayerPlane, 0, 1, 0, 0,
130bf215546Sopenharmony_ci                                                        WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
131bf215546Sopenharmony_ci                                                        0, WGL_NO_RESET_NOTIFICATION_ARB);
132bf215546Sopenharmony_ci   if (!ctx)
133bf215546Sopenharmony_ci      return 0;
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci   DHGLRC ret = stw_create_context_handle(ctx, 0);
136bf215546Sopenharmony_ci   if (!ret)
137bf215546Sopenharmony_ci      stw_destroy_context(ctx);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   return ret;
140bf215546Sopenharmony_ci}
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci/**
144bf215546Sopenharmony_ci * Return the stw pixel format that most closely matches the pixel format
145bf215546Sopenharmony_ci * on HDC.
146bf215546Sopenharmony_ci * Used to get a pixel format when SetPixelFormat() hasn't been called before.
147bf215546Sopenharmony_ci */
148bf215546Sopenharmony_cistatic int
149bf215546Sopenharmony_ciget_matching_pixel_format(HDC hdc)
150bf215546Sopenharmony_ci{
151bf215546Sopenharmony_ci   int iPixelFormat = GetPixelFormat(hdc);
152bf215546Sopenharmony_ci   PIXELFORMATDESCRIPTOR pfd;
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci   if (!iPixelFormat)
155bf215546Sopenharmony_ci      return 0;
156bf215546Sopenharmony_ci   if (!DescribePixelFormat(hdc, iPixelFormat, sizeof(pfd), &pfd))
157bf215546Sopenharmony_ci      return 0;
158bf215546Sopenharmony_ci   return stw_pixelformat_choose(hdc, &pfd);
159bf215546Sopenharmony_ci}
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci/**
163bf215546Sopenharmony_ci * Called via DrvCreateContext(), DrvCreateLayerContext() and
164bf215546Sopenharmony_ci * wglCreateContextAttribsARB() to actually create a rendering context.
165bf215546Sopenharmony_ci */
166bf215546Sopenharmony_cistruct stw_context *
167bf215546Sopenharmony_cistw_create_context_attribs(HDC hdc, INT iLayerPlane, struct stw_context *shareCtx,
168bf215546Sopenharmony_ci                           int majorVersion, int minorVersion,
169bf215546Sopenharmony_ci                           int contextFlags, int profileMask,
170bf215546Sopenharmony_ci                           int iPixelFormat, int resetStrategy)
171bf215546Sopenharmony_ci{
172bf215546Sopenharmony_ci   const struct stw_pixelformat_info *pfi;
173bf215546Sopenharmony_ci   struct st_context_attribs attribs;
174bf215546Sopenharmony_ci   struct stw_context *ctx = NULL;
175bf215546Sopenharmony_ci   enum st_context_error ctx_err = 0;
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci   if (!stw_dev)
178bf215546Sopenharmony_ci      return 0;
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci   if (iLayerPlane != 0)
181bf215546Sopenharmony_ci      return 0;
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci   if (!iPixelFormat) {
184bf215546Sopenharmony_ci      /*
185bf215546Sopenharmony_ci       * GDI only knows about displayable pixel formats, so determine the pixel
186bf215546Sopenharmony_ci       * format from the framebuffer.
187bf215546Sopenharmony_ci       *
188bf215546Sopenharmony_ci       * This also allows to use a OpenGL DLL / ICD without installing.
189bf215546Sopenharmony_ci       */
190bf215546Sopenharmony_ci      struct stw_framebuffer *fb;
191bf215546Sopenharmony_ci      fb = stw_framebuffer_from_hdc(hdc);
192bf215546Sopenharmony_ci      if (fb) {
193bf215546Sopenharmony_ci         iPixelFormat = fb->iPixelFormat;
194bf215546Sopenharmony_ci         stw_framebuffer_unlock(fb);
195bf215546Sopenharmony_ci      }
196bf215546Sopenharmony_ci      else {
197bf215546Sopenharmony_ci         /* Applications should call SetPixelFormat before creating a context,
198bf215546Sopenharmony_ci          * but not all do, and the opengl32 runtime seems to use a default
199bf215546Sopenharmony_ci          * pixel format in some cases, so use that.
200bf215546Sopenharmony_ci          */
201bf215546Sopenharmony_ci         iPixelFormat = get_matching_pixel_format(hdc);
202bf215546Sopenharmony_ci         if (!iPixelFormat)
203bf215546Sopenharmony_ci            return 0;
204bf215546Sopenharmony_ci      }
205bf215546Sopenharmony_ci   }
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_ci   pfi = stw_pixelformat_get_info( iPixelFormat );
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci   if (shareCtx != NULL)
210bf215546Sopenharmony_ci      shareCtx->shared = TRUE;
211bf215546Sopenharmony_ci
212bf215546Sopenharmony_ci   ctx = CALLOC_STRUCT( stw_context );
213bf215546Sopenharmony_ci   if (ctx == NULL)
214bf215546Sopenharmony_ci      goto no_ctx;
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_ci   ctx->hDrawDC = hdc;
217bf215546Sopenharmony_ci   ctx->hReadDC = hdc;
218bf215546Sopenharmony_ci   ctx->iPixelFormat = iPixelFormat;
219bf215546Sopenharmony_ci   ctx->shared = shareCtx != NULL;
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ci   memset(&attribs, 0, sizeof(attribs));
222bf215546Sopenharmony_ci   attribs.visual = pfi->stvis;
223bf215546Sopenharmony_ci   attribs.major = majorVersion;
224bf215546Sopenharmony_ci   attribs.minor = minorVersion;
225bf215546Sopenharmony_ci   if (contextFlags & WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB)
226bf215546Sopenharmony_ci      attribs.flags |= ST_CONTEXT_FLAG_FORWARD_COMPATIBLE;
227bf215546Sopenharmony_ci   if (contextFlags & WGL_CONTEXT_DEBUG_BIT_ARB)
228bf215546Sopenharmony_ci      attribs.flags |= ST_CONTEXT_FLAG_DEBUG;
229bf215546Sopenharmony_ci   if (contextFlags & WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB)
230bf215546Sopenharmony_ci      attribs.flags |= ST_CONTEXT_FLAG_ROBUST_ACCESS;
231bf215546Sopenharmony_ci   if (resetStrategy != WGL_NO_RESET_NOTIFICATION_ARB)
232bf215546Sopenharmony_ci      attribs.flags |= ST_CONTEXT_FLAG_RESET_NOTIFICATION_ENABLED;
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_ci   switch (profileMask) {
235bf215546Sopenharmony_ci   case WGL_CONTEXT_CORE_PROFILE_BIT_ARB:
236bf215546Sopenharmony_ci      /* There are no profiles before OpenGL 3.2.  The
237bf215546Sopenharmony_ci       * WGL_ARB_create_context_profile spec says:
238bf215546Sopenharmony_ci       *
239bf215546Sopenharmony_ci       *     "If the requested OpenGL version is less than 3.2,
240bf215546Sopenharmony_ci       *     WGL_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality
241bf215546Sopenharmony_ci       *     of the context is determined solely by the requested version."
242bf215546Sopenharmony_ci       */
243bf215546Sopenharmony_ci      if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 2)) {
244bf215546Sopenharmony_ci         attribs.profile = ST_PROFILE_OPENGL_CORE;
245bf215546Sopenharmony_ci         break;
246bf215546Sopenharmony_ci      }
247bf215546Sopenharmony_ci      FALLTHROUGH;
248bf215546Sopenharmony_ci   case WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
249bf215546Sopenharmony_ci      /*
250bf215546Sopenharmony_ci       * The spec also says:
251bf215546Sopenharmony_ci       *
252bf215546Sopenharmony_ci       *     "If version 3.1 is requested, the context returned may implement
253bf215546Sopenharmony_ci       *     any of the following versions:
254bf215546Sopenharmony_ci       *
255bf215546Sopenharmony_ci       *       * Version 3.1. The GL_ARB_compatibility extension may or may not
256bf215546Sopenharmony_ci       *         be implemented, as determined by the implementation.
257bf215546Sopenharmony_ci       *       * The core profile of version 3.2 or greater."
258bf215546Sopenharmony_ci       *
259bf215546Sopenharmony_ci       * But Mesa doesn't support GL_ARB_compatibility, while most prevalent
260bf215546Sopenharmony_ci       * Windows OpenGL implementations do, and unfortunately many Windows
261bf215546Sopenharmony_ci       * applications don't check whether they receive or not a context with
262bf215546Sopenharmony_ci       * GL_ARB_compatibility, so returning a core profile here does more harm
263bf215546Sopenharmony_ci       * than good.
264bf215546Sopenharmony_ci       */
265bf215546Sopenharmony_ci      attribs.profile = ST_PROFILE_DEFAULT;
266bf215546Sopenharmony_ci      break;
267bf215546Sopenharmony_ci   case WGL_CONTEXT_ES_PROFILE_BIT_EXT:
268bf215546Sopenharmony_ci      if (majorVersion >= 2) {
269bf215546Sopenharmony_ci         attribs.profile = ST_PROFILE_OPENGL_ES2;
270bf215546Sopenharmony_ci      } else {
271bf215546Sopenharmony_ci         attribs.profile = ST_PROFILE_OPENGL_ES1;
272bf215546Sopenharmony_ci      }
273bf215546Sopenharmony_ci      break;
274bf215546Sopenharmony_ci   default:
275bf215546Sopenharmony_ci      assert(0);
276bf215546Sopenharmony_ci      goto no_st_ctx;
277bf215546Sopenharmony_ci   }
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci   attribs.options = stw_dev->st_options;
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ci   ctx->st = stw_dev->stapi->create_context(stw_dev->stapi,
282bf215546Sopenharmony_ci         stw_dev->smapi, &attribs, &ctx_err, shareCtx ? shareCtx->st : NULL);
283bf215546Sopenharmony_ci   if (ctx->st == NULL)
284bf215546Sopenharmony_ci      goto no_st_ctx;
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_ci   ctx->st->st_manager_private = (void *) ctx;
287bf215546Sopenharmony_ci
288bf215546Sopenharmony_ci   if (ctx->st->cso_context) {
289bf215546Sopenharmony_ci      ctx->hud = hud_create(ctx->st->cso_context, ctx->st, NULL);
290bf215546Sopenharmony_ci   }
291bf215546Sopenharmony_ci
292bf215546Sopenharmony_ci   return ctx;
293bf215546Sopenharmony_ci
294bf215546Sopenharmony_cino_st_ctx:
295bf215546Sopenharmony_ci   FREE(ctx);
296bf215546Sopenharmony_cino_ctx:
297bf215546Sopenharmony_ci   return NULL;
298bf215546Sopenharmony_ci}
299bf215546Sopenharmony_ci
300bf215546Sopenharmony_ciDHGLRC
301bf215546Sopenharmony_cistw_create_context_handle(struct stw_context *ctx, DHGLRC handle)
302bf215546Sopenharmony_ci{
303bf215546Sopenharmony_ci   assert(ctx->dhglrc == 0);
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci   stw_lock_contexts(stw_dev);
306bf215546Sopenharmony_ci   if (handle) {
307bf215546Sopenharmony_ci      /* We're replacing the context data for this handle. See the
308bf215546Sopenharmony_ci       * wglCreateContextAttribsARB() function.
309bf215546Sopenharmony_ci       */
310bf215546Sopenharmony_ci      struct stw_context *old_ctx =
311bf215546Sopenharmony_ci         stw_lookup_context_locked((unsigned) handle);
312bf215546Sopenharmony_ci      if (old_ctx) {
313bf215546Sopenharmony_ci         stw_destroy_context(old_ctx);
314bf215546Sopenharmony_ci      }
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci      /* replace table entry */
317bf215546Sopenharmony_ci      handle_table_set(stw_dev->ctx_table, (unsigned) handle, ctx);
318bf215546Sopenharmony_ci   }
319bf215546Sopenharmony_ci   else {
320bf215546Sopenharmony_ci      /* create new table entry */
321bf215546Sopenharmony_ci      handle = (DHGLRC) handle_table_add(stw_dev->ctx_table, ctx);
322bf215546Sopenharmony_ci   }
323bf215546Sopenharmony_ci
324bf215546Sopenharmony_ci   ctx->dhglrc = handle;
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci   stw_unlock_contexts(stw_dev);
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci   return ctx->dhglrc;
329bf215546Sopenharmony_ci}
330bf215546Sopenharmony_ci
331bf215546Sopenharmony_civoid
332bf215546Sopenharmony_cistw_destroy_context(struct stw_context *ctx)
333bf215546Sopenharmony_ci{
334bf215546Sopenharmony_ci   if (ctx->hud) {
335bf215546Sopenharmony_ci      hud_destroy(ctx->hud, NULL);
336bf215546Sopenharmony_ci   }
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_ci   ctx->st->destroy(ctx->st);
339bf215546Sopenharmony_ci   FREE(ctx);
340bf215546Sopenharmony_ci}
341bf215546Sopenharmony_ci
342bf215546Sopenharmony_ci
343bf215546Sopenharmony_ciBOOL APIENTRY
344bf215546Sopenharmony_ciDrvDeleteContext(DHGLRC dhglrc)
345bf215546Sopenharmony_ci{
346bf215546Sopenharmony_ci   struct stw_context *ctx ;
347bf215546Sopenharmony_ci   BOOL ret = FALSE;
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci   if (!stw_dev)
350bf215546Sopenharmony_ci      return FALSE;
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_ci   stw_lock_contexts(stw_dev);
353bf215546Sopenharmony_ci   ctx = stw_lookup_context_locked(dhglrc);
354bf215546Sopenharmony_ci   handle_table_remove(stw_dev->ctx_table, dhglrc);
355bf215546Sopenharmony_ci   stw_unlock_contexts(stw_dev);
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci   if (ctx) {
358bf215546Sopenharmony_ci      struct stw_context *curctx = stw_current_context();
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_ci      /* Unbind current if deleting current context. */
361bf215546Sopenharmony_ci      if (curctx == ctx)
362bf215546Sopenharmony_ci         stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL);
363bf215546Sopenharmony_ci
364bf215546Sopenharmony_ci      stw_destroy_context(ctx);
365bf215546Sopenharmony_ci      ret = TRUE;
366bf215546Sopenharmony_ci   }
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_ci   return ret;
369bf215546Sopenharmony_ci}
370bf215546Sopenharmony_ci
371bf215546Sopenharmony_ciBOOL
372bf215546Sopenharmony_cistw_unbind_context(struct stw_context *ctx)
373bf215546Sopenharmony_ci{
374bf215546Sopenharmony_ci   if (!ctx)
375bf215546Sopenharmony_ci      return FALSE;
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_ci   /* The expectation is that ctx is the same context which is
378bf215546Sopenharmony_ci    * current for this thread.  We should check that and return False
379bf215546Sopenharmony_ci    * if not the case.
380bf215546Sopenharmony_ci    */
381bf215546Sopenharmony_ci   if (ctx != stw_current_context())
382bf215546Sopenharmony_ci      return FALSE;
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci   if (stw_make_current( NULL, NULL, NULL ) == FALSE)
385bf215546Sopenharmony_ci      return FALSE;
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci   return TRUE;
388bf215546Sopenharmony_ci}
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ciBOOL APIENTRY
391bf215546Sopenharmony_ciDrvReleaseContext(DHGLRC dhglrc)
392bf215546Sopenharmony_ci{
393bf215546Sopenharmony_ci   struct stw_context *ctx;
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_ci   if (!stw_dev)
396bf215546Sopenharmony_ci      return FALSE;
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_ci   stw_lock_contexts(stw_dev);
399bf215546Sopenharmony_ci   ctx = stw_lookup_context_locked( dhglrc );
400bf215546Sopenharmony_ci   stw_unlock_contexts(stw_dev);
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ci   return stw_unbind_context(ctx);
403bf215546Sopenharmony_ci}
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci
406bf215546Sopenharmony_ciDHGLRC
407bf215546Sopenharmony_cistw_get_current_context( void )
408bf215546Sopenharmony_ci{
409bf215546Sopenharmony_ci   struct stw_context *ctx;
410bf215546Sopenharmony_ci
411bf215546Sopenharmony_ci   ctx = stw_current_context();
412bf215546Sopenharmony_ci   if (!ctx)
413bf215546Sopenharmony_ci      return 0;
414bf215546Sopenharmony_ci
415bf215546Sopenharmony_ci   return ctx->dhglrc;
416bf215546Sopenharmony_ci}
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci
419bf215546Sopenharmony_ciHDC
420bf215546Sopenharmony_cistw_get_current_dc( void )
421bf215546Sopenharmony_ci{
422bf215546Sopenharmony_ci   struct stw_context *ctx;
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci   ctx = stw_current_context();
425bf215546Sopenharmony_ci   if (!ctx)
426bf215546Sopenharmony_ci      return NULL;
427bf215546Sopenharmony_ci
428bf215546Sopenharmony_ci   return ctx->hDrawDC;
429bf215546Sopenharmony_ci}
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ciHDC
432bf215546Sopenharmony_cistw_get_current_read_dc( void )
433bf215546Sopenharmony_ci{
434bf215546Sopenharmony_ci   struct stw_context *ctx;
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_ci   ctx = stw_current_context();
437bf215546Sopenharmony_ci   if (!ctx)
438bf215546Sopenharmony_ci      return NULL;
439bf215546Sopenharmony_ci
440bf215546Sopenharmony_ci   return ctx->hReadDC;
441bf215546Sopenharmony_ci}
442bf215546Sopenharmony_ci
443bf215546Sopenharmony_cistatic void
444bf215546Sopenharmony_cirelease_old_framebuffers(struct stw_framebuffer *old_fb, struct stw_framebuffer *old_fbRead,
445bf215546Sopenharmony_ci                         struct stw_context *old_ctx)
446bf215546Sopenharmony_ci{
447bf215546Sopenharmony_ci   if (old_fb || old_fbRead) {
448bf215546Sopenharmony_ci      stw_lock_framebuffers(stw_dev);
449bf215546Sopenharmony_ci      if (old_fb) {
450bf215546Sopenharmony_ci         stw_framebuffer_lock(old_fb);
451bf215546Sopenharmony_ci         stw_framebuffer_release_locked(old_fb, old_ctx->st);
452bf215546Sopenharmony_ci      }
453bf215546Sopenharmony_ci      if (old_fbRead) {
454bf215546Sopenharmony_ci         stw_framebuffer_lock(old_fbRead);
455bf215546Sopenharmony_ci         stw_framebuffer_release_locked(old_fbRead, old_ctx->st);
456bf215546Sopenharmony_ci      }
457bf215546Sopenharmony_ci      stw_unlock_framebuffers(stw_dev);
458bf215546Sopenharmony_ci   }
459bf215546Sopenharmony_ci}
460bf215546Sopenharmony_ci
461bf215546Sopenharmony_ciBOOL
462bf215546Sopenharmony_cistw_make_current(struct stw_framebuffer *fb, struct stw_framebuffer *fbRead, struct stw_context *ctx)
463bf215546Sopenharmony_ci{
464bf215546Sopenharmony_ci   struct stw_context *old_ctx = NULL;
465bf215546Sopenharmony_ci   BOOL ret = FALSE;
466bf215546Sopenharmony_ci
467bf215546Sopenharmony_ci   if (!stw_dev)
468bf215546Sopenharmony_ci      return FALSE;
469bf215546Sopenharmony_ci
470bf215546Sopenharmony_ci   old_ctx = stw_current_context();
471bf215546Sopenharmony_ci   if (old_ctx != NULL) {
472bf215546Sopenharmony_ci      if (old_ctx == ctx) {
473bf215546Sopenharmony_ci         if (old_ctx->current_framebuffer == fb && old_ctx->current_read_framebuffer == fbRead) {
474bf215546Sopenharmony_ci            /* Return if already current. */
475bf215546Sopenharmony_ci            return TRUE;
476bf215546Sopenharmony_ci         }
477bf215546Sopenharmony_ci      } else {
478bf215546Sopenharmony_ci         if (old_ctx->shared) {
479bf215546Sopenharmony_ci            if (old_ctx->current_framebuffer) {
480bf215546Sopenharmony_ci               stw_st_flush(old_ctx->st, old_ctx->current_framebuffer->stfb,
481bf215546Sopenharmony_ci                            ST_FLUSH_FRONT | ST_FLUSH_WAIT);
482bf215546Sopenharmony_ci            } else {
483bf215546Sopenharmony_ci               struct pipe_fence_handle *fence = NULL;
484bf215546Sopenharmony_ci               old_ctx->st->flush(old_ctx->st,
485bf215546Sopenharmony_ci                                  ST_FLUSH_FRONT | ST_FLUSH_WAIT, &fence,
486bf215546Sopenharmony_ci                                  NULL, NULL);
487bf215546Sopenharmony_ci            }
488bf215546Sopenharmony_ci         } else {
489bf215546Sopenharmony_ci            if (old_ctx->current_framebuffer)
490bf215546Sopenharmony_ci               stw_st_flush(old_ctx->st, old_ctx->current_framebuffer->stfb,
491bf215546Sopenharmony_ci                            ST_FLUSH_FRONT);
492bf215546Sopenharmony_ci            else
493bf215546Sopenharmony_ci               old_ctx->st->flush(old_ctx->st, ST_FLUSH_FRONT, NULL, NULL, NULL);
494bf215546Sopenharmony_ci         }
495bf215546Sopenharmony_ci      }
496bf215546Sopenharmony_ci   }
497bf215546Sopenharmony_ci
498bf215546Sopenharmony_ci   if (ctx) {
499bf215546Sopenharmony_ci      if (!fb || !fbRead)
500bf215546Sopenharmony_ci         goto fail;
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_ci      if (fb->iPixelFormat != ctx->iPixelFormat) {
503bf215546Sopenharmony_ci         SetLastError(ERROR_INVALID_PIXEL_FORMAT);
504bf215546Sopenharmony_ci         goto fail;
505bf215546Sopenharmony_ci      }
506bf215546Sopenharmony_ci      if (fbRead->iPixelFormat != ctx->iPixelFormat) {
507bf215546Sopenharmony_ci         SetLastError(ERROR_INVALID_PIXEL_FORMAT);
508bf215546Sopenharmony_ci         goto fail;
509bf215546Sopenharmony_ci      }
510bf215546Sopenharmony_ci
511bf215546Sopenharmony_ci      stw_framebuffer_lock(fb);
512bf215546Sopenharmony_ci      stw_framebuffer_update(fb);
513bf215546Sopenharmony_ci      stw_framebuffer_reference_locked(fb);
514bf215546Sopenharmony_ci      stw_framebuffer_unlock(fb);
515bf215546Sopenharmony_ci
516bf215546Sopenharmony_ci      stw_framebuffer_lock(fbRead);
517bf215546Sopenharmony_ci      if (fbRead != fb)
518bf215546Sopenharmony_ci         stw_framebuffer_update(fbRead);
519bf215546Sopenharmony_ci      stw_framebuffer_reference_locked(fbRead);
520bf215546Sopenharmony_ci      stw_framebuffer_unlock(fbRead);
521bf215546Sopenharmony_ci
522bf215546Sopenharmony_ci      struct stw_framebuffer *old_fb = ctx->current_framebuffer;
523bf215546Sopenharmony_ci      struct stw_framebuffer *old_fbRead = ctx->current_read_framebuffer;
524bf215546Sopenharmony_ci      ctx->current_framebuffer = fb;
525bf215546Sopenharmony_ci      ctx->current_read_framebuffer = fbRead;
526bf215546Sopenharmony_ci
527bf215546Sopenharmony_ci      ret = stw_dev->stapi->make_current(stw_dev->stapi, ctx->st,
528bf215546Sopenharmony_ci                                          fb->stfb, fbRead->stfb);
529bf215546Sopenharmony_ci
530bf215546Sopenharmony_ci      /* Release the old framebuffers from this context. */
531bf215546Sopenharmony_ci      release_old_framebuffers(old_fb, old_fbRead, ctx);
532bf215546Sopenharmony_ci
533bf215546Sopenharmony_cifail:
534bf215546Sopenharmony_ci      /* fb and fbRead must be unlocked at this point. */
535bf215546Sopenharmony_ci      if (fb)
536bf215546Sopenharmony_ci         assert(!stw_own_mutex(&fb->mutex));
537bf215546Sopenharmony_ci      if (fbRead)
538bf215546Sopenharmony_ci         assert(!stw_own_mutex(&fbRead->mutex));
539bf215546Sopenharmony_ci
540bf215546Sopenharmony_ci      /* On failure, make the thread's current rendering context not current
541bf215546Sopenharmony_ci       * before returning.
542bf215546Sopenharmony_ci       */
543bf215546Sopenharmony_ci      if (!ret) {
544bf215546Sopenharmony_ci         stw_make_current(NULL, NULL, NULL);
545bf215546Sopenharmony_ci      }
546bf215546Sopenharmony_ci   } else {
547bf215546Sopenharmony_ci      ret = stw_dev->stapi->make_current(stw_dev->stapi, NULL, NULL, NULL);
548bf215546Sopenharmony_ci   }
549bf215546Sopenharmony_ci
550bf215546Sopenharmony_ci   /* Unreference the previous framebuffer if any. It must be done after
551bf215546Sopenharmony_ci    * make_current, as it can be referenced inside.
552bf215546Sopenharmony_ci    */
553bf215546Sopenharmony_ci   if (old_ctx && old_ctx != ctx) {
554bf215546Sopenharmony_ci      release_old_framebuffers(old_ctx->current_framebuffer, old_ctx->current_read_framebuffer, old_ctx);
555bf215546Sopenharmony_ci      old_ctx->current_framebuffer = NULL;
556bf215546Sopenharmony_ci      old_ctx->current_read_framebuffer = NULL;
557bf215546Sopenharmony_ci   }
558bf215546Sopenharmony_ci
559bf215546Sopenharmony_ci   return ret;
560bf215546Sopenharmony_ci}
561bf215546Sopenharmony_ci
562bf215546Sopenharmony_cistatic struct stw_framebuffer *
563bf215546Sopenharmony_ciget_unlocked_refd_framebuffer_from_dc(HDC hDC)
564bf215546Sopenharmony_ci{
565bf215546Sopenharmony_ci   if (!hDC)
566bf215546Sopenharmony_ci      return NULL;
567bf215546Sopenharmony_ci
568bf215546Sopenharmony_ci   /* This call locks fb's mutex */
569bf215546Sopenharmony_ci   struct stw_framebuffer *fb = stw_framebuffer_from_hdc(hDC);
570bf215546Sopenharmony_ci   if (!fb) {
571bf215546Sopenharmony_ci      /* Applications should call SetPixelFormat before creating a context,
572bf215546Sopenharmony_ci       * but not all do, and the opengl32 runtime seems to use a default
573bf215546Sopenharmony_ci       * pixel format in some cases, so we must create a framebuffer for
574bf215546Sopenharmony_ci       * those here.
575bf215546Sopenharmony_ci       */
576bf215546Sopenharmony_ci      int iPixelFormat = get_matching_pixel_format(hDC);
577bf215546Sopenharmony_ci      if (iPixelFormat)
578bf215546Sopenharmony_ci         fb = stw_framebuffer_create(WindowFromDC(hDC), iPixelFormat, STW_FRAMEBUFFER_WGL_WINDOW);
579bf215546Sopenharmony_ci      if (!fb)
580bf215546Sopenharmony_ci         return NULL;
581bf215546Sopenharmony_ci   }
582bf215546Sopenharmony_ci   stw_framebuffer_reference_locked(fb);
583bf215546Sopenharmony_ci   stw_framebuffer_unlock(fb);
584bf215546Sopenharmony_ci   return fb;
585bf215546Sopenharmony_ci}
586bf215546Sopenharmony_ci
587bf215546Sopenharmony_ciBOOL
588bf215546Sopenharmony_cistw_make_current_by_handles(HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc)
589bf215546Sopenharmony_ci{
590bf215546Sopenharmony_ci   struct stw_context *ctx = stw_lookup_context(dhglrc);
591bf215546Sopenharmony_ci   if (dhglrc && !ctx) {
592bf215546Sopenharmony_ci      stw_make_current_by_handles(NULL, NULL, 0);
593bf215546Sopenharmony_ci      return FALSE;
594bf215546Sopenharmony_ci   }
595bf215546Sopenharmony_ci
596bf215546Sopenharmony_ci   struct stw_framebuffer *fb = get_unlocked_refd_framebuffer_from_dc(hDrawDC);
597bf215546Sopenharmony_ci   if (ctx && !fb) {
598bf215546Sopenharmony_ci      stw_make_current_by_handles(NULL, NULL, 0);
599bf215546Sopenharmony_ci      return FALSE;
600bf215546Sopenharmony_ci   }
601bf215546Sopenharmony_ci
602bf215546Sopenharmony_ci   struct stw_framebuffer *fbRead = (hDrawDC == hReadDC || hReadDC == NULL) ?
603bf215546Sopenharmony_ci      fb : get_unlocked_refd_framebuffer_from_dc(hReadDC);
604bf215546Sopenharmony_ci   if (ctx && !fbRead) {
605bf215546Sopenharmony_ci      release_old_framebuffers(fb, NULL, ctx);
606bf215546Sopenharmony_ci      stw_make_current_by_handles(NULL, NULL, 0);
607bf215546Sopenharmony_ci      return FALSE;
608bf215546Sopenharmony_ci   }
609bf215546Sopenharmony_ci
610bf215546Sopenharmony_ci   BOOL success = stw_make_current(fb, fbRead, ctx);
611bf215546Sopenharmony_ci
612bf215546Sopenharmony_ci   if (ctx) {
613bf215546Sopenharmony_ci      if (success) {
614bf215546Sopenharmony_ci         ctx->hDrawDC = hDrawDC;
615bf215546Sopenharmony_ci         ctx->hReadDC = hReadDC;
616bf215546Sopenharmony_ci      } else {
617bf215546Sopenharmony_ci         ctx->hDrawDC = NULL;
618bf215546Sopenharmony_ci         ctx->hReadDC = NULL;
619bf215546Sopenharmony_ci      }
620bf215546Sopenharmony_ci
621bf215546Sopenharmony_ci      assert(fb && fbRead);
622bf215546Sopenharmony_ci      /* In the success case, the context took extra references on these framebuffers,
623bf215546Sopenharmony_ci       * so release our local references.
624bf215546Sopenharmony_ci       */
625bf215546Sopenharmony_ci      stw_lock_framebuffers(stw_dev);
626bf215546Sopenharmony_ci      stw_framebuffer_lock(fb);
627bf215546Sopenharmony_ci      stw_framebuffer_release_locked(fb, ctx->st);
628bf215546Sopenharmony_ci      if (fb != fbRead) {
629bf215546Sopenharmony_ci         stw_framebuffer_lock(fbRead);
630bf215546Sopenharmony_ci         stw_framebuffer_release_locked(fbRead, ctx->st);
631bf215546Sopenharmony_ci      }
632bf215546Sopenharmony_ci      stw_unlock_framebuffers(stw_dev);
633bf215546Sopenharmony_ci   }
634bf215546Sopenharmony_ci   return success;
635bf215546Sopenharmony_ci}
636bf215546Sopenharmony_ci
637bf215546Sopenharmony_ci
638bf215546Sopenharmony_ci/**
639bf215546Sopenharmony_ci * Notify the current context that the framebuffer has become invalid.
640bf215546Sopenharmony_ci */
641bf215546Sopenharmony_civoid
642bf215546Sopenharmony_cistw_notify_current_locked( struct stw_framebuffer *fb )
643bf215546Sopenharmony_ci{
644bf215546Sopenharmony_ci   p_atomic_inc(&fb->stfb->stamp);
645bf215546Sopenharmony_ci}
646bf215546Sopenharmony_ci
647bf215546Sopenharmony_ci
648bf215546Sopenharmony_ci/**
649bf215546Sopenharmony_ci * Although WGL allows different dispatch entrypoints per context
650bf215546Sopenharmony_ci */
651bf215546Sopenharmony_cistatic const GLCLTPROCTABLE cpt =
652bf215546Sopenharmony_ci{
653bf215546Sopenharmony_ci   OPENGL_VERSION_110_ENTRIES,
654bf215546Sopenharmony_ci   {
655bf215546Sopenharmony_ci      &glNewList,
656bf215546Sopenharmony_ci      &glEndList,
657bf215546Sopenharmony_ci      &glCallList,
658bf215546Sopenharmony_ci      &glCallLists,
659bf215546Sopenharmony_ci      &glDeleteLists,
660bf215546Sopenharmony_ci      &glGenLists,
661bf215546Sopenharmony_ci      &glListBase,
662bf215546Sopenharmony_ci      &glBegin,
663bf215546Sopenharmony_ci      &glBitmap,
664bf215546Sopenharmony_ci      &glColor3b,
665bf215546Sopenharmony_ci      &glColor3bv,
666bf215546Sopenharmony_ci      &glColor3d,
667bf215546Sopenharmony_ci      &glColor3dv,
668bf215546Sopenharmony_ci      &glColor3f,
669bf215546Sopenharmony_ci      &glColor3fv,
670bf215546Sopenharmony_ci      &glColor3i,
671bf215546Sopenharmony_ci      &glColor3iv,
672bf215546Sopenharmony_ci      &glColor3s,
673bf215546Sopenharmony_ci      &glColor3sv,
674bf215546Sopenharmony_ci      &glColor3ub,
675bf215546Sopenharmony_ci      &glColor3ubv,
676bf215546Sopenharmony_ci      &glColor3ui,
677bf215546Sopenharmony_ci      &glColor3uiv,
678bf215546Sopenharmony_ci      &glColor3us,
679bf215546Sopenharmony_ci      &glColor3usv,
680bf215546Sopenharmony_ci      &glColor4b,
681bf215546Sopenharmony_ci      &glColor4bv,
682bf215546Sopenharmony_ci      &glColor4d,
683bf215546Sopenharmony_ci      &glColor4dv,
684bf215546Sopenharmony_ci      &glColor4f,
685bf215546Sopenharmony_ci      &glColor4fv,
686bf215546Sopenharmony_ci      &glColor4i,
687bf215546Sopenharmony_ci      &glColor4iv,
688bf215546Sopenharmony_ci      &glColor4s,
689bf215546Sopenharmony_ci      &glColor4sv,
690bf215546Sopenharmony_ci      &glColor4ub,
691bf215546Sopenharmony_ci      &glColor4ubv,
692bf215546Sopenharmony_ci      &glColor4ui,
693bf215546Sopenharmony_ci      &glColor4uiv,
694bf215546Sopenharmony_ci      &glColor4us,
695bf215546Sopenharmony_ci      &glColor4usv,
696bf215546Sopenharmony_ci      &glEdgeFlag,
697bf215546Sopenharmony_ci      &glEdgeFlagv,
698bf215546Sopenharmony_ci      &glEnd,
699bf215546Sopenharmony_ci      &glIndexd,
700bf215546Sopenharmony_ci      &glIndexdv,
701bf215546Sopenharmony_ci      &glIndexf,
702bf215546Sopenharmony_ci      &glIndexfv,
703bf215546Sopenharmony_ci      &glIndexi,
704bf215546Sopenharmony_ci      &glIndexiv,
705bf215546Sopenharmony_ci      &glIndexs,
706bf215546Sopenharmony_ci      &glIndexsv,
707bf215546Sopenharmony_ci      &glNormal3b,
708bf215546Sopenharmony_ci      &glNormal3bv,
709bf215546Sopenharmony_ci      &glNormal3d,
710bf215546Sopenharmony_ci      &glNormal3dv,
711bf215546Sopenharmony_ci      &glNormal3f,
712bf215546Sopenharmony_ci      &glNormal3fv,
713bf215546Sopenharmony_ci      &glNormal3i,
714bf215546Sopenharmony_ci      &glNormal3iv,
715bf215546Sopenharmony_ci      &glNormal3s,
716bf215546Sopenharmony_ci      &glNormal3sv,
717bf215546Sopenharmony_ci      &glRasterPos2d,
718bf215546Sopenharmony_ci      &glRasterPos2dv,
719bf215546Sopenharmony_ci      &glRasterPos2f,
720bf215546Sopenharmony_ci      &glRasterPos2fv,
721bf215546Sopenharmony_ci      &glRasterPos2i,
722bf215546Sopenharmony_ci      &glRasterPos2iv,
723bf215546Sopenharmony_ci      &glRasterPos2s,
724bf215546Sopenharmony_ci      &glRasterPos2sv,
725bf215546Sopenharmony_ci      &glRasterPos3d,
726bf215546Sopenharmony_ci      &glRasterPos3dv,
727bf215546Sopenharmony_ci      &glRasterPos3f,
728bf215546Sopenharmony_ci      &glRasterPos3fv,
729bf215546Sopenharmony_ci      &glRasterPos3i,
730bf215546Sopenharmony_ci      &glRasterPos3iv,
731bf215546Sopenharmony_ci      &glRasterPos3s,
732bf215546Sopenharmony_ci      &glRasterPos3sv,
733bf215546Sopenharmony_ci      &glRasterPos4d,
734bf215546Sopenharmony_ci      &glRasterPos4dv,
735bf215546Sopenharmony_ci      &glRasterPos4f,
736bf215546Sopenharmony_ci      &glRasterPos4fv,
737bf215546Sopenharmony_ci      &glRasterPos4i,
738bf215546Sopenharmony_ci      &glRasterPos4iv,
739bf215546Sopenharmony_ci      &glRasterPos4s,
740bf215546Sopenharmony_ci      &glRasterPos4sv,
741bf215546Sopenharmony_ci      &glRectd,
742bf215546Sopenharmony_ci      &glRectdv,
743bf215546Sopenharmony_ci      &glRectf,
744bf215546Sopenharmony_ci      &glRectfv,
745bf215546Sopenharmony_ci      &glRecti,
746bf215546Sopenharmony_ci      &glRectiv,
747bf215546Sopenharmony_ci      &glRects,
748bf215546Sopenharmony_ci      &glRectsv,
749bf215546Sopenharmony_ci      &glTexCoord1d,
750bf215546Sopenharmony_ci      &glTexCoord1dv,
751bf215546Sopenharmony_ci      &glTexCoord1f,
752bf215546Sopenharmony_ci      &glTexCoord1fv,
753bf215546Sopenharmony_ci      &glTexCoord1i,
754bf215546Sopenharmony_ci      &glTexCoord1iv,
755bf215546Sopenharmony_ci      &glTexCoord1s,
756bf215546Sopenharmony_ci      &glTexCoord1sv,
757bf215546Sopenharmony_ci      &glTexCoord2d,
758bf215546Sopenharmony_ci      &glTexCoord2dv,
759bf215546Sopenharmony_ci      &glTexCoord2f,
760bf215546Sopenharmony_ci      &glTexCoord2fv,
761bf215546Sopenharmony_ci      &glTexCoord2i,
762bf215546Sopenharmony_ci      &glTexCoord2iv,
763bf215546Sopenharmony_ci      &glTexCoord2s,
764bf215546Sopenharmony_ci      &glTexCoord2sv,
765bf215546Sopenharmony_ci      &glTexCoord3d,
766bf215546Sopenharmony_ci      &glTexCoord3dv,
767bf215546Sopenharmony_ci      &glTexCoord3f,
768bf215546Sopenharmony_ci      &glTexCoord3fv,
769bf215546Sopenharmony_ci      &glTexCoord3i,
770bf215546Sopenharmony_ci      &glTexCoord3iv,
771bf215546Sopenharmony_ci      &glTexCoord3s,
772bf215546Sopenharmony_ci      &glTexCoord3sv,
773bf215546Sopenharmony_ci      &glTexCoord4d,
774bf215546Sopenharmony_ci      &glTexCoord4dv,
775bf215546Sopenharmony_ci      &glTexCoord4f,
776bf215546Sopenharmony_ci      &glTexCoord4fv,
777bf215546Sopenharmony_ci      &glTexCoord4i,
778bf215546Sopenharmony_ci      &glTexCoord4iv,
779bf215546Sopenharmony_ci      &glTexCoord4s,
780bf215546Sopenharmony_ci      &glTexCoord4sv,
781bf215546Sopenharmony_ci      &glVertex2d,
782bf215546Sopenharmony_ci      &glVertex2dv,
783bf215546Sopenharmony_ci      &glVertex2f,
784bf215546Sopenharmony_ci      &glVertex2fv,
785bf215546Sopenharmony_ci      &glVertex2i,
786bf215546Sopenharmony_ci      &glVertex2iv,
787bf215546Sopenharmony_ci      &glVertex2s,
788bf215546Sopenharmony_ci      &glVertex2sv,
789bf215546Sopenharmony_ci      &glVertex3d,
790bf215546Sopenharmony_ci      &glVertex3dv,
791bf215546Sopenharmony_ci      &glVertex3f,
792bf215546Sopenharmony_ci      &glVertex3fv,
793bf215546Sopenharmony_ci      &glVertex3i,
794bf215546Sopenharmony_ci      &glVertex3iv,
795bf215546Sopenharmony_ci      &glVertex3s,
796bf215546Sopenharmony_ci      &glVertex3sv,
797bf215546Sopenharmony_ci      &glVertex4d,
798bf215546Sopenharmony_ci      &glVertex4dv,
799bf215546Sopenharmony_ci      &glVertex4f,
800bf215546Sopenharmony_ci      &glVertex4fv,
801bf215546Sopenharmony_ci      &glVertex4i,
802bf215546Sopenharmony_ci      &glVertex4iv,
803bf215546Sopenharmony_ci      &glVertex4s,
804bf215546Sopenharmony_ci      &glVertex4sv,
805bf215546Sopenharmony_ci      &glClipPlane,
806bf215546Sopenharmony_ci      &glColorMaterial,
807bf215546Sopenharmony_ci      &glCullFace,
808bf215546Sopenharmony_ci      &glFogf,
809bf215546Sopenharmony_ci      &glFogfv,
810bf215546Sopenharmony_ci      &glFogi,
811bf215546Sopenharmony_ci      &glFogiv,
812bf215546Sopenharmony_ci      &glFrontFace,
813bf215546Sopenharmony_ci      &glHint,
814bf215546Sopenharmony_ci      &glLightf,
815bf215546Sopenharmony_ci      &glLightfv,
816bf215546Sopenharmony_ci      &glLighti,
817bf215546Sopenharmony_ci      &glLightiv,
818bf215546Sopenharmony_ci      &glLightModelf,
819bf215546Sopenharmony_ci      &glLightModelfv,
820bf215546Sopenharmony_ci      &glLightModeli,
821bf215546Sopenharmony_ci      &glLightModeliv,
822bf215546Sopenharmony_ci      &glLineStipple,
823bf215546Sopenharmony_ci      &glLineWidth,
824bf215546Sopenharmony_ci      &glMaterialf,
825bf215546Sopenharmony_ci      &glMaterialfv,
826bf215546Sopenharmony_ci      &glMateriali,
827bf215546Sopenharmony_ci      &glMaterialiv,
828bf215546Sopenharmony_ci      &glPointSize,
829bf215546Sopenharmony_ci      &glPolygonMode,
830bf215546Sopenharmony_ci      &glPolygonStipple,
831bf215546Sopenharmony_ci      &glScissor,
832bf215546Sopenharmony_ci      &glShadeModel,
833bf215546Sopenharmony_ci      &glTexParameterf,
834bf215546Sopenharmony_ci      &glTexParameterfv,
835bf215546Sopenharmony_ci      &glTexParameteri,
836bf215546Sopenharmony_ci      &glTexParameteriv,
837bf215546Sopenharmony_ci      &glTexImage1D,
838bf215546Sopenharmony_ci      &glTexImage2D,
839bf215546Sopenharmony_ci      &glTexEnvf,
840bf215546Sopenharmony_ci      &glTexEnvfv,
841bf215546Sopenharmony_ci      &glTexEnvi,
842bf215546Sopenharmony_ci      &glTexEnviv,
843bf215546Sopenharmony_ci      &glTexGend,
844bf215546Sopenharmony_ci      &glTexGendv,
845bf215546Sopenharmony_ci      &glTexGenf,
846bf215546Sopenharmony_ci      &glTexGenfv,
847bf215546Sopenharmony_ci      &glTexGeni,
848bf215546Sopenharmony_ci      &glTexGeniv,
849bf215546Sopenharmony_ci      &glFeedbackBuffer,
850bf215546Sopenharmony_ci      &glSelectBuffer,
851bf215546Sopenharmony_ci      &glRenderMode,
852bf215546Sopenharmony_ci      &glInitNames,
853bf215546Sopenharmony_ci      &glLoadName,
854bf215546Sopenharmony_ci      &glPassThrough,
855bf215546Sopenharmony_ci      &glPopName,
856bf215546Sopenharmony_ci      &glPushName,
857bf215546Sopenharmony_ci      &glDrawBuffer,
858bf215546Sopenharmony_ci      &glClear,
859bf215546Sopenharmony_ci      &glClearAccum,
860bf215546Sopenharmony_ci      &glClearIndex,
861bf215546Sopenharmony_ci      &glClearColor,
862bf215546Sopenharmony_ci      &glClearStencil,
863bf215546Sopenharmony_ci      &glClearDepth,
864bf215546Sopenharmony_ci      &glStencilMask,
865bf215546Sopenharmony_ci      &glColorMask,
866bf215546Sopenharmony_ci      &glDepthMask,
867bf215546Sopenharmony_ci      &glIndexMask,
868bf215546Sopenharmony_ci      &glAccum,
869bf215546Sopenharmony_ci      &glDisable,
870bf215546Sopenharmony_ci      &glEnable,
871bf215546Sopenharmony_ci      &glFinish,
872bf215546Sopenharmony_ci      &glFlush,
873bf215546Sopenharmony_ci      &glPopAttrib,
874bf215546Sopenharmony_ci      &glPushAttrib,
875bf215546Sopenharmony_ci      &glMap1d,
876bf215546Sopenharmony_ci      &glMap1f,
877bf215546Sopenharmony_ci      &glMap2d,
878bf215546Sopenharmony_ci      &glMap2f,
879bf215546Sopenharmony_ci      &glMapGrid1d,
880bf215546Sopenharmony_ci      &glMapGrid1f,
881bf215546Sopenharmony_ci      &glMapGrid2d,
882bf215546Sopenharmony_ci      &glMapGrid2f,
883bf215546Sopenharmony_ci      &glEvalCoord1d,
884bf215546Sopenharmony_ci      &glEvalCoord1dv,
885bf215546Sopenharmony_ci      &glEvalCoord1f,
886bf215546Sopenharmony_ci      &glEvalCoord1fv,
887bf215546Sopenharmony_ci      &glEvalCoord2d,
888bf215546Sopenharmony_ci      &glEvalCoord2dv,
889bf215546Sopenharmony_ci      &glEvalCoord2f,
890bf215546Sopenharmony_ci      &glEvalCoord2fv,
891bf215546Sopenharmony_ci      &glEvalMesh1,
892bf215546Sopenharmony_ci      &glEvalPoint1,
893bf215546Sopenharmony_ci      &glEvalMesh2,
894bf215546Sopenharmony_ci      &glEvalPoint2,
895bf215546Sopenharmony_ci      &glAlphaFunc,
896bf215546Sopenharmony_ci      &glBlendFunc,
897bf215546Sopenharmony_ci      &glLogicOp,
898bf215546Sopenharmony_ci      &glStencilFunc,
899bf215546Sopenharmony_ci      &glStencilOp,
900bf215546Sopenharmony_ci      &glDepthFunc,
901bf215546Sopenharmony_ci      &glPixelZoom,
902bf215546Sopenharmony_ci      &glPixelTransferf,
903bf215546Sopenharmony_ci      &glPixelTransferi,
904bf215546Sopenharmony_ci      &glPixelStoref,
905bf215546Sopenharmony_ci      &glPixelStorei,
906bf215546Sopenharmony_ci      &glPixelMapfv,
907bf215546Sopenharmony_ci      &glPixelMapuiv,
908bf215546Sopenharmony_ci      &glPixelMapusv,
909bf215546Sopenharmony_ci      &glReadBuffer,
910bf215546Sopenharmony_ci      &glCopyPixels,
911bf215546Sopenharmony_ci      &glReadPixels,
912bf215546Sopenharmony_ci      &glDrawPixels,
913bf215546Sopenharmony_ci      &glGetBooleanv,
914bf215546Sopenharmony_ci      &glGetClipPlane,
915bf215546Sopenharmony_ci      &glGetDoublev,
916bf215546Sopenharmony_ci      &glGetError,
917bf215546Sopenharmony_ci      &glGetFloatv,
918bf215546Sopenharmony_ci      &glGetIntegerv,
919bf215546Sopenharmony_ci      &glGetLightfv,
920bf215546Sopenharmony_ci      &glGetLightiv,
921bf215546Sopenharmony_ci      &glGetMapdv,
922bf215546Sopenharmony_ci      &glGetMapfv,
923bf215546Sopenharmony_ci      &glGetMapiv,
924bf215546Sopenharmony_ci      &glGetMaterialfv,
925bf215546Sopenharmony_ci      &glGetMaterialiv,
926bf215546Sopenharmony_ci      &glGetPixelMapfv,
927bf215546Sopenharmony_ci      &glGetPixelMapuiv,
928bf215546Sopenharmony_ci      &glGetPixelMapusv,
929bf215546Sopenharmony_ci      &glGetPolygonStipple,
930bf215546Sopenharmony_ci      &glGetString,
931bf215546Sopenharmony_ci      &glGetTexEnvfv,
932bf215546Sopenharmony_ci      &glGetTexEnviv,
933bf215546Sopenharmony_ci      &glGetTexGendv,
934bf215546Sopenharmony_ci      &glGetTexGenfv,
935bf215546Sopenharmony_ci      &glGetTexGeniv,
936bf215546Sopenharmony_ci      &glGetTexImage,
937bf215546Sopenharmony_ci      &glGetTexParameterfv,
938bf215546Sopenharmony_ci      &glGetTexParameteriv,
939bf215546Sopenharmony_ci      &glGetTexLevelParameterfv,
940bf215546Sopenharmony_ci      &glGetTexLevelParameteriv,
941bf215546Sopenharmony_ci      &glIsEnabled,
942bf215546Sopenharmony_ci      &glIsList,
943bf215546Sopenharmony_ci      &glDepthRange,
944bf215546Sopenharmony_ci      &glFrustum,
945bf215546Sopenharmony_ci      &glLoadIdentity,
946bf215546Sopenharmony_ci      &glLoadMatrixf,
947bf215546Sopenharmony_ci      &glLoadMatrixd,
948bf215546Sopenharmony_ci      &glMatrixMode,
949bf215546Sopenharmony_ci      &glMultMatrixf,
950bf215546Sopenharmony_ci      &glMultMatrixd,
951bf215546Sopenharmony_ci      &glOrtho,
952bf215546Sopenharmony_ci      &glPopMatrix,
953bf215546Sopenharmony_ci      &glPushMatrix,
954bf215546Sopenharmony_ci      &glRotated,
955bf215546Sopenharmony_ci      &glRotatef,
956bf215546Sopenharmony_ci      &glScaled,
957bf215546Sopenharmony_ci      &glScalef,
958bf215546Sopenharmony_ci      &glTranslated,
959bf215546Sopenharmony_ci      &glTranslatef,
960bf215546Sopenharmony_ci      &glViewport,
961bf215546Sopenharmony_ci      &glArrayElement,
962bf215546Sopenharmony_ci      &glBindTexture,
963bf215546Sopenharmony_ci      &glColorPointer,
964bf215546Sopenharmony_ci      &glDisableClientState,
965bf215546Sopenharmony_ci      &glDrawArrays,
966bf215546Sopenharmony_ci      &glDrawElements,
967bf215546Sopenharmony_ci      &glEdgeFlagPointer,
968bf215546Sopenharmony_ci      &glEnableClientState,
969bf215546Sopenharmony_ci      &glIndexPointer,
970bf215546Sopenharmony_ci      &glIndexub,
971bf215546Sopenharmony_ci      &glIndexubv,
972bf215546Sopenharmony_ci      &glInterleavedArrays,
973bf215546Sopenharmony_ci      &glNormalPointer,
974bf215546Sopenharmony_ci      &glPolygonOffset,
975bf215546Sopenharmony_ci      &glTexCoordPointer,
976bf215546Sopenharmony_ci      &glVertexPointer,
977bf215546Sopenharmony_ci      &glAreTexturesResident,
978bf215546Sopenharmony_ci      &glCopyTexImage1D,
979bf215546Sopenharmony_ci      &glCopyTexImage2D,
980bf215546Sopenharmony_ci      &glCopyTexSubImage1D,
981bf215546Sopenharmony_ci      &glCopyTexSubImage2D,
982bf215546Sopenharmony_ci      &glDeleteTextures,
983bf215546Sopenharmony_ci      &glGenTextures,
984bf215546Sopenharmony_ci      &glGetPointerv,
985bf215546Sopenharmony_ci      &glIsTexture,
986bf215546Sopenharmony_ci      &glPrioritizeTextures,
987bf215546Sopenharmony_ci      &glTexSubImage1D,
988bf215546Sopenharmony_ci      &glTexSubImage2D,
989bf215546Sopenharmony_ci      &glPopClientAttrib,
990bf215546Sopenharmony_ci      &glPushClientAttrib
991bf215546Sopenharmony_ci   }
992bf215546Sopenharmony_ci};
993bf215546Sopenharmony_ci
994bf215546Sopenharmony_ci
995bf215546Sopenharmony_ciPGLCLTPROCTABLE APIENTRY
996bf215546Sopenharmony_ciDrvSetContext(HDC hdc, DHGLRC dhglrc, PFN_SETPROCTABLE pfnSetProcTable)
997bf215546Sopenharmony_ci{
998bf215546Sopenharmony_ci   PGLCLTPROCTABLE r = (PGLCLTPROCTABLE)&cpt;
999bf215546Sopenharmony_ci
1000bf215546Sopenharmony_ci   if (!stw_make_current_by_handles(hdc, hdc, dhglrc))
1001bf215546Sopenharmony_ci      r = NULL;
1002bf215546Sopenharmony_ci
1003bf215546Sopenharmony_ci   return r;
1004bf215546Sopenharmony_ci}
1005