wined3d: Fix a few small bugs in WineD3D_ChoosePixelFormat.
[wine/wine-kai.git] / dlls / wined3d / context.c
blobd80ef0660f19a5caaa542cb764442be819afc400
1 /*
2 * Context and render target management in wined3d
4 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdio.h>
23 #ifdef HAVE_FLOAT_H
24 # include <float.h>
25 #endif
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30 #define GLINFO_LOCATION This->adapter->gl_info
32 /*****************************************************************************
33 * Context_MarkStateDirty
35 * Marks a state in a context dirty. Only one context, opposed to
36 * IWineD3DDeviceImpl_MarkStateDirty, which marks the state dirty in all
37 * contexts
39 * Params:
40 * context: Context to mark the state dirty in
41 * state: State to mark dirty
42 * StateTable: Pointer to the state table in use(for state grouping)
44 *****************************************************************************/
45 static void Context_MarkStateDirty(WineD3DContext *context, DWORD state, const struct StateEntry *StateTable) {
46 DWORD rep = StateTable[state].representative;
47 DWORD idx;
48 BYTE shift;
50 if(!rep || isStateDirty(context, rep)) return;
52 context->dirtyArray[context->numDirtyEntries++] = rep;
53 idx = rep >> 5;
54 shift = rep & 0x1f;
55 context->isStateDirty[idx] |= (1 << shift);
58 /*****************************************************************************
59 * AddContextToArray
61 * Adds a context to the context array. Helper function for CreateContext
63 * This method is not called in performance-critical code paths, only when a
64 * new render target or swapchain is created. Thus performance is not an issue
65 * here.
67 * Params:
68 * This: Device to add the context for
69 * hdc: device context
70 * glCtx: WGL context to add
71 * pbuffer: optional pbuffer used with this context
73 *****************************************************************************/
74 static WineD3DContext *AddContextToArray(IWineD3DDeviceImpl *This, HWND win_handle, HDC hdc, HGLRC glCtx, HPBUFFERARB pbuffer) {
75 WineD3DContext **oldArray = This->contexts;
76 DWORD state;
78 This->contexts = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->contexts) * (This->numContexts + 1));
79 if(This->contexts == NULL) {
80 ERR("Unable to grow the context array\n");
81 This->contexts = oldArray;
82 return NULL;
84 if(oldArray) {
85 memcpy(This->contexts, oldArray, sizeof(*This->contexts) * This->numContexts);
88 This->contexts[This->numContexts] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineD3DContext));
89 if(This->contexts[This->numContexts] == NULL) {
90 ERR("Unable to allocate a new context\n");
91 HeapFree(GetProcessHeap(), 0, This->contexts);
92 This->contexts = oldArray;
93 return NULL;
96 This->contexts[This->numContexts]->hdc = hdc;
97 This->contexts[This->numContexts]->glCtx = glCtx;
98 This->contexts[This->numContexts]->pbuffer = pbuffer;
99 This->contexts[This->numContexts]->win_handle = win_handle;
100 HeapFree(GetProcessHeap(), 0, oldArray);
102 /* Mark all states dirty to force a proper initialization of the states on the first use of the context
104 for(state = 0; state <= STATE_HIGHEST; state++) {
105 Context_MarkStateDirty(This->contexts[This->numContexts], state, This->shader_backend->StateTable);
108 This->numContexts++;
109 TRACE("Created context %p\n", This->contexts[This->numContexts - 1]);
110 return This->contexts[This->numContexts - 1];
113 /* This function takes care of WineD3D pixel format selection. */
114 static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DFORMAT ColorFormat, WINED3DFORMAT DepthStencilFormat, BOOL auxBuffers, BOOL pbuffer, BOOL findCompatible)
116 int iPixelFormat=0;
117 short redBits, greenBits, blueBits, alphaBits, colorBits;
118 short depthBits=0, stencilBits=0;
120 int i = 0;
121 int nCfgs = This->adapter->nCfgs;
122 WineD3D_PixelFormat *cfgs = This->adapter->cfgs;
124 if(!getColorBits(ColorFormat, &redBits, &greenBits, &blueBits, &alphaBits, &colorBits)) {
125 ERR("Unable to get color bits for format %s (%#x)!\n", debug_d3dformat(ColorFormat), ColorFormat);
126 return 0;
129 if(DepthStencilFormat) {
130 getDepthStencilBits(DepthStencilFormat, &depthBits, &stencilBits);
133 /* Find a pixel format which EXACTLY matches our requirements (except for depth) */
134 for(i=0; i<nCfgs; i++) {
135 BOOL exactDepthMatch = TRUE;
136 cfgs = &This->adapter->cfgs[i];
138 /* For now only accept RGBA formats. Perhaps some day we will
139 * allow floating point formats for pbuffers. */
140 if(cfgs->iPixelType != WGL_TYPE_RGBA_ARB)
141 continue;
143 /* In all cases except when we are in pbuffer-mode we need a window drawable format with double buffering. */
144 if(!pbuffer && !cfgs->windowDrawable && !cfgs->doubleBuffer)
145 continue;
147 /* We like to have aux buffers in backbuffer mode */
148 if(auxBuffers && !cfgs->auxBuffers)
149 continue;
151 /* In pbuffer-mode we need a pbuffer-capable format */
152 if(pbuffer && !cfgs->pbufferDrawable)
153 continue;
155 if(cfgs->redSize != redBits)
156 continue;
157 if(cfgs->greenSize != greenBits)
158 continue;
159 if(cfgs->blueSize != blueBits)
160 continue;
161 if(cfgs->alphaSize != alphaBits)
162 continue;
164 /* We try to locate a format which matches our requirements exactly. In case of
165 * depth it is no problem to emulate 16-bit using e.g. 24-bit, so accept that. */
166 if(cfgs->depthSize < depthBits)
167 continue;
168 else if(cfgs->depthSize > depthBits)
169 exactDepthMatch = FALSE;
171 /* In all cases make sure the number of stencil bits matches our requirements
172 * even when we don't need stencil because it could affect performance */
173 if(!(cfgs->stencilSize == stencilBits))
174 continue;
176 /* When we have passed all the checks then we have found a format which matches our
177 * requirements. Note that we only check for a limit number of capabilities right now,
178 * so there can easily be a dozen of pixel formats which appear to be the 'same' but
179 * can still differ in things like multisampling, stereo, SRGB and other flags.
182 /* Exit the loop as we have found a format :) */
183 if(exactDepthMatch) {
184 iPixelFormat = cfgs->iPixelFormat;
185 break;
186 } else if(!iPixelFormat) {
187 /* In the end we might end up with a format which doesn't exactly match our depth
188 * requirements. Accept the first format we found because formats with higher iPixelFormat
189 * values tend to have more extended capabilities (e.g. multisampling) which we don't need. */
190 iPixelFormat = cfgs->iPixelFormat;
194 /* When findCompatible is set and no suitable format was found, let ChoosePixelFormat choose a pixel format in order not to crash. */
195 if(!iPixelFormat && !findCompatible) {
196 ERR("Can't find a suitable iPixelFormat\n");
197 return FALSE;
198 } else if(!iPixelFormat) {
199 PIXELFORMATDESCRIPTOR pfd;
201 TRACE("Falling back to ChoosePixelFormat as we weren't able to find an exactly matching pixel format\n");
202 /* PixelFormat selection */
203 ZeroMemory(&pfd, sizeof(pfd));
204 pfd.nSize = sizeof(pfd);
205 pfd.nVersion = 1;
206 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
207 pfd.iPixelType = PFD_TYPE_RGBA;
208 pfd.cAlphaBits = alphaBits;
209 pfd.cColorBits = colorBits;
210 pfd.cDepthBits = depthBits;
211 pfd.cStencilBits = stencilBits;
212 pfd.iLayerType = PFD_MAIN_PLANE;
214 iPixelFormat = ChoosePixelFormat(hdc, &pfd);
215 if(!iPixelFormat) {
216 /* If this happens something is very wrong as ChoosePixelFormat barely fails */
217 ERR("Can't find a suitable iPixelFormat\n");
218 return FALSE;
222 TRACE("Found iPixelFormat=%d for ColorFormat=%s, DepthStencilFormat=%s\n", iPixelFormat, debug_d3dformat(ColorFormat), debug_d3dformat(DepthStencilFormat));
223 return iPixelFormat;
226 /*****************************************************************************
227 * CreateContext
229 * Creates a new context for a window, or a pbuffer context.
231 * * Params:
232 * This: Device to activate the context for
233 * target: Surface this context will render to
234 * win_handle: handle to the window which we are drawing to
235 * create_pbuffer: tells whether to create a pbuffer or not
236 * pPresentParameters: contains the pixelformats to use for onscreen rendering
238 *****************************************************************************/
239 WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win_handle, BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms) {
240 HDC oldDrawable, hdc;
241 HPBUFFERARB pbuffer = NULL;
242 HGLRC ctx = NULL, oldCtx;
243 WineD3DContext *ret = NULL;
244 int s;
246 TRACE("(%p): Creating a %s context for render target %p\n", This, create_pbuffer ? "offscreen" : "onscreen", target);
248 #define PUSH1(att) attribs[nAttribs++] = (att);
249 #define PUSH2(att,value) attribs[nAttribs++] = (att); attribs[nAttribs++] = (value);
250 if(create_pbuffer) {
251 HDC hdc_parent = GetDC(win_handle);
252 int iPixelFormat = 0;
254 IWineD3DSurface *StencilSurface = This->stencilBufferTarget;
255 WINED3DFORMAT StencilBufferFormat = (NULL != StencilSurface) ? ((IWineD3DSurfaceImpl *) StencilSurface)->resource.format : 0;
257 /* Try to find a pixel format with pbuffer support. */
258 iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format, StencilBufferFormat, FALSE /* auxBuffers */, TRUE /* PBUFFER */, FALSE /* findCompatible */);
259 if(!iPixelFormat) {
260 TRACE("Trying to locate a compatible pixel format because an exact match failed.\n");
262 /* For some reason we weren't able to find a format, try to find something instead of crashing.
263 * A reason for failure could have been wglChoosePixelFormatARB strictness. */
264 iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format, StencilBufferFormat, FALSE /* auxBuffer */, TRUE /* PBUFFER */, TRUE /* findCompatible */);
267 /* This shouldn't happen as ChoosePixelFormat always returns something */
268 if(!iPixelFormat) {
269 ERR("Unable to locate a pixel format for a pbuffer\n");
270 ReleaseDC(win_handle, hdc_parent);
271 goto out;
274 TRACE("Creating a pBuffer drawable for the new context\n");
275 pbuffer = GL_EXTCALL(wglCreatePbufferARB(hdc_parent, iPixelFormat, target->currentDesc.Width, target->currentDesc.Height, 0));
276 if(!pbuffer) {
277 ERR("Cannot create a pbuffer\n");
278 ReleaseDC(win_handle, hdc_parent);
279 goto out;
282 /* In WGL a pbuffer is 'wrapped' inside a HDC to 'fool' wglMakeCurrent */
283 hdc = GL_EXTCALL(wglGetPbufferDCARB(pbuffer));
284 if(!hdc) {
285 ERR("Cannot get a HDC for pbuffer (%p)\n", pbuffer);
286 GL_EXTCALL(wglDestroyPbufferARB(pbuffer));
287 ReleaseDC(win_handle, hdc_parent);
288 goto out;
290 ReleaseDC(win_handle, hdc_parent);
291 } else {
292 PIXELFORMATDESCRIPTOR pfd;
293 int iPixelFormat;
294 int res;
295 WINED3DFORMAT ColorFormat = target->resource.format;
296 WINED3DFORMAT DepthStencilFormat = 0;
297 BOOL auxBuffers = FALSE;
299 hdc = GetDC(win_handle);
300 if(hdc == NULL) {
301 ERR("Cannot retrieve a device context!\n");
302 goto out;
305 /* In case of ORM_BACKBUFFER, make sure to request an alpha component for X4R4G4B4/X8R8G8B8 as we might need it for the backbuffer. */
306 if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
307 auxBuffers = TRUE;
309 if(target->resource.format == WINED3DFMT_X4R4G4B4)
310 ColorFormat = WINED3DFMT_A4R4G4B4;
311 else if(target->resource.format == WINED3DFMT_X8R8G8B8)
312 ColorFormat = WINED3DFMT_A8R8G8B8;
315 /* DirectDraw supports 8bit paletted render targets and these are used by old games like Starcraft and C&C.
316 * Most modern hardware doesn't support 8bit natively so we perform some form of 8bit -> 32bit conversion.
317 * The conversion (ab)uses the alpha component for storing the palette index. For this reason we require
318 * a format with 8bit alpha, so request A8R8G8B8. */
319 if(ColorFormat == WINED3DFMT_P8)
320 ColorFormat = WINED3DFMT_A8R8G8B8;
322 /* Retrieve the depth stencil format from the present parameters.
323 * The choice of the proper format can give a nice performance boost
324 * in case of GPU limited programs. */
325 if(pPresentParms->EnableAutoDepthStencil) {
326 TRACE("pPresentParms->EnableAutoDepthStencil=enabled; using AutoDepthStencilFormat=%s\n", debug_d3dformat(pPresentParms->AutoDepthStencilFormat));
327 DepthStencilFormat = pPresentParms->AutoDepthStencilFormat;
330 /* Try to find a pixel format which matches our requirements */
331 iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc, ColorFormat, DepthStencilFormat, auxBuffers, FALSE /* PBUFFER */, FALSE /* findCompatible */);
333 /* Try to locate a compatible format if we weren't able to find anything */
334 if(!iPixelFormat) {
335 TRACE("Trying to locate a compatible pixel format because an exact match failed.\n");
336 iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc, ColorFormat, DepthStencilFormat, auxBuffers, FALSE /* PBUFFER */, TRUE /* findCompatible */ );
339 /* If we still don't have a pixel format, something is very wrong as ChoosePixelFormat barely fails */
340 if(!iPixelFormat) {
341 ERR("Can't find a suitable iPixelFormat\n");
342 return FALSE;
345 DescribePixelFormat(hdc, iPixelFormat, sizeof(pfd), &pfd);
346 res = SetPixelFormat(hdc, iPixelFormat, NULL);
347 if(!res) {
348 int oldPixelFormat = GetPixelFormat(hdc);
350 /* By default WGL doesn't allow pixel format adjustments but we need it here.
351 * For this reason there is a WINE-specific wglSetPixelFormat which allows you to
352 * set the pixel format multiple times. Only use it when it is really needed. */
354 if(oldPixelFormat == iPixelFormat) {
355 /* We don't have to do anything as the formats are the same :) */
356 } else if(oldPixelFormat && GL_SUPPORT(WGL_WINE_PIXEL_FORMAT_PASSTHROUGH)) {
357 res = GL_EXTCALL(wglSetPixelFormatWINE(hdc, iPixelFormat, NULL));
359 if(!res) {
360 ERR("wglSetPixelFormatWINE failed on HDC=%p for iPixelFormat=%d\n", hdc, iPixelFormat);
361 return FALSE;
363 } else if(oldPixelFormat) {
364 /* OpenGL doesn't allow pixel format adjustments. Print an error and continue using the old format.
365 * There's a big chance that the old format works although with a performance hit and perhaps rendering errors. */
366 ERR("HDC=%p is already set to iPixelFormat=%d and OpenGL doesn't allow changes!\n", hdc, oldPixelFormat);
367 } else {
368 ERR("SetPixelFormat failed on HDC=%p for iPixelFormat=%d\n", hdc, iPixelFormat);
369 return FALSE;
373 #undef PUSH1
374 #undef PUSH2
376 ctx = pwglCreateContext(hdc);
377 if(This->numContexts) pwglShareLists(This->contexts[0]->glCtx, ctx);
379 if(!ctx) {
380 ERR("Failed to create a WGL context\n");
381 if(create_pbuffer) {
382 GL_EXTCALL(wglReleasePbufferDCARB(pbuffer, hdc));
383 GL_EXTCALL(wglDestroyPbufferARB(pbuffer));
385 goto out;
387 ret = AddContextToArray(This, win_handle, hdc, ctx, pbuffer);
388 if(!ret) {
389 ERR("Failed to add the newly created context to the context list\n");
390 pwglDeleteContext(ctx);
391 if(create_pbuffer) {
392 GL_EXTCALL(wglReleasePbufferDCARB(pbuffer, hdc));
393 GL_EXTCALL(wglDestroyPbufferARB(pbuffer));
395 goto out;
397 ret->surface = (IWineD3DSurface *) target;
398 ret->isPBuffer = create_pbuffer;
399 ret->tid = GetCurrentThreadId();
400 if(This->shader_backend->shader_dirtifyable_constants((IWineD3DDevice *) This)) {
401 /* Create the dirty constants array and initialize them to dirty */
402 ret->vshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
403 sizeof(*ret->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
404 ret->pshader_const_dirty = HeapAlloc(GetProcessHeap(), 0,
405 sizeof(*ret->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
406 memset(ret->vshader_const_dirty, 1,
407 sizeof(*ret->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
408 memset(ret->pshader_const_dirty, 1,
409 sizeof(*ret->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
412 TRACE("Successfully created new context %p\n", ret);
414 /* Set up the context defaults */
415 oldCtx = pwglGetCurrentContext();
416 oldDrawable = pwglGetCurrentDC();
417 if(oldCtx && oldDrawable) {
418 /* See comment in ActivateContext context switching */
419 This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, FALSE);
421 if(pwglMakeCurrent(hdc, ctx) == FALSE) {
422 ERR("Cannot activate context to set up defaults\n");
423 goto out;
426 ENTER_GL();
428 glGetIntegerv(GL_AUX_BUFFERS, &ret->aux_buffers);
430 TRACE("Setting up the screen\n");
431 /* Clear the screen */
432 glClearColor(1.0, 0.0, 0.0, 0.0);
433 checkGLcall("glClearColor");
434 glClearIndex(0);
435 glClearDepth(1);
436 glClearStencil(0xffff);
438 checkGLcall("glClear");
440 glColor3f(1.0, 1.0, 1.0);
441 checkGLcall("glColor3f");
443 glEnable(GL_LIGHTING);
444 checkGLcall("glEnable");
446 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
447 checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
449 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
450 checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
452 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
453 checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
455 glPixelStorei(GL_PACK_ALIGNMENT, This->surface_alignment);
456 checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, This->surface_alignment);");
457 glPixelStorei(GL_UNPACK_ALIGNMENT, This->surface_alignment);
458 checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, This->surface_alignment);");
460 if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
461 /* Most textures will use client storage if supported. Exceptions are non-native power of 2 textures
462 * and textures in DIB sections(due to the memory protection).
464 glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
465 checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
467 if(GL_SUPPORT(ARB_VERTEX_BLEND)) {
468 /* Direct3D always uses n-1 weights for n world matrices and uses 1 - sum for the last one
469 * this is equal to GL_WEIGHT_SUM_UNITY_ARB. Enabling it doesn't do anything unless
470 * GL_VERTEX_BLEND_ARB isn't enabled too
472 glEnable(GL_WEIGHT_SUM_UNITY_ARB);
473 checkGLcall("glEnable(GL_WEIGHT_SUM_UNITY_ARB)");
475 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
476 glEnable(GL_TEXTURE_SHADER_NV);
477 checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
479 /* Set up the previous texture input for all shader units. This applies to bump mapping, and in d3d
480 * the previous texture where to source the offset from is always unit - 1.
482 for(s = 1; s < GL_LIMITS(textures); s++) {
483 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
484 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1);
485 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...\n");
489 if(GL_SUPPORT(ARB_POINT_SPRITE)) {
490 for(s = 0; s < GL_LIMITS(textures); s++) {
491 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
492 glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
493 checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)\n");
496 LEAVE_GL();
498 /* Never keep GL_FRAGMENT_SHADER_ATI enabled on a context that we switch away from,
499 * but enable it for the first context we create, and reenable it on the old context
501 if(oldDrawable && oldCtx) {
502 pwglMakeCurrent(oldDrawable, oldCtx);
504 This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
506 out:
507 return ret;
510 /*****************************************************************************
511 * RemoveContextFromArray
513 * Removes a context from the context manager. The opengl context is not
514 * destroyed or unset. context is not a valid pointer after that call.
516 * Similar to the former call this isn't a performance critical function. A
517 * helper function for DestroyContext.
519 * Params:
520 * This: Device to activate the context for
521 * context: Context to remove
523 *****************************************************************************/
524 static void RemoveContextFromArray(IWineD3DDeviceImpl *This, WineD3DContext *context) {
525 UINT t, s;
526 WineD3DContext **oldArray = This->contexts;
528 TRACE("Removing ctx %p\n", context);
530 This->numContexts--;
532 if(This->numContexts) {
533 This->contexts = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->contexts) * This->numContexts);
534 if(!This->contexts) {
535 ERR("Cannot allocate a new context array, PANIC!!!\n");
537 t = 0;
538 for(s = 0; s < This->numContexts; s++) {
539 if(oldArray[s] == context) continue;
540 This->contexts[t] = oldArray[s];
541 t++;
543 } else {
544 This->contexts = NULL;
547 HeapFree(GetProcessHeap(), 0, context);
548 HeapFree(GetProcessHeap(), 0, oldArray);
551 /*****************************************************************************
552 * DestroyContext
554 * Destroys a wineD3DContext
556 * Params:
557 * This: Device to activate the context for
558 * context: Context to destroy
560 *****************************************************************************/
561 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context) {
563 /* check that we are the current context first */
564 TRACE("Destroying ctx %p\n", context);
565 if(pwglGetCurrentContext() == context->glCtx){
566 pwglMakeCurrent(NULL, NULL);
569 if(context->isPBuffer) {
570 GL_EXTCALL(wglReleasePbufferDCARB(context->pbuffer, context->hdc));
571 GL_EXTCALL(wglDestroyPbufferARB(context->pbuffer));
572 } else ReleaseDC(context->win_handle, context->hdc);
573 pwglDeleteContext(context->glCtx);
575 HeapFree(GetProcessHeap(), 0, context->vshader_const_dirty);
576 HeapFree(GetProcessHeap(), 0, context->pshader_const_dirty);
577 RemoveContextFromArray(This, context);
580 /*****************************************************************************
581 * SetupForBlit
583 * Sets up a context for DirectDraw blitting.
584 * All texture units are disabled, texture unit 0 is set as current unit
585 * fog, lighting, blending, alpha test, z test, scissor test, culling disabled
586 * color writing enabled for all channels
587 * register combiners disabled, shaders disabled
588 * world matrix is set to identity, texture matrix 0 too
589 * projection matrix is setup for drawing screen coordinates
591 * Params:
592 * This: Device to activate the context for
593 * context: Context to setup
594 * width: render target width
595 * height: render target height
597 *****************************************************************************/
598 static inline void SetupForBlit(IWineD3DDeviceImpl *This, WineD3DContext *context, UINT width, UINT height) {
599 int i;
600 const struct StateEntry *StateTable = This->shader_backend->StateTable;
602 TRACE("Setting up context %p for blitting\n", context);
603 if(context->last_was_blit) {
604 TRACE("Context is already set up for blitting, nothing to do\n");
605 return;
607 context->last_was_blit = TRUE;
609 /* TODO: Use a display list */
611 /* Disable shaders */
612 This->shader_backend->shader_cleanup((IWineD3DDevice *) This);
613 Context_MarkStateDirty(context, STATE_VSHADER, StateTable);
614 Context_MarkStateDirty(context, STATE_PIXELSHADER, StateTable);
616 /* Disable all textures. The caller can then bind a texture it wants to blit
617 * from
619 if(GL_SUPPORT(NV_REGISTER_COMBINERS)) {
620 glDisable(GL_REGISTER_COMBINERS_NV);
621 checkGLcall("glDisable(GL_REGISTER_COMBINERS_NV)");
623 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
624 /* The blitting code uses (for now) the fixed function pipeline, so make sure to reset all fixed
625 * function texture unit. No need to care for higher samplers
627 for(i = GL_LIMITS(textures) - 1; i > 0 ; i--) {
628 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
629 checkGLcall("glActiveTextureARB");
631 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
632 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
633 checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
635 glDisable(GL_TEXTURE_3D);
636 checkGLcall("glDisable GL_TEXTURE_3D");
637 glDisable(GL_TEXTURE_2D);
638 checkGLcall("glDisable GL_TEXTURE_2D");
640 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
641 checkGLcall("glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);");
643 Context_MarkStateDirty(context, STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP), StateTable);
644 Context_MarkStateDirty(context, STATE_SAMPLER(i), StateTable);
646 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
647 checkGLcall("glActiveTextureARB");
649 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
650 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
651 checkGLcall("glDisable GL_TEXTURE_CUBE_MAP_ARB");
653 glDisable(GL_TEXTURE_3D);
654 checkGLcall("glDisable GL_TEXTURE_3D");
655 glDisable(GL_TEXTURE_2D);
656 checkGLcall("glDisable GL_TEXTURE_2D");
658 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
660 glMatrixMode(GL_TEXTURE);
661 checkGLcall("glMatrixMode(GL_TEXTURE)");
662 glLoadIdentity();
663 checkGLcall("glLoadIdentity()");
664 Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0), StateTable);
666 if (GL_SUPPORT(EXT_TEXTURE_LOD_BIAS)) {
667 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
668 GL_TEXTURE_LOD_BIAS_EXT,
669 0.0);
670 checkGLcall("glTexEnvi GL_TEXTURE_LOD_BIAS_EXT ...");
672 Context_MarkStateDirty(context, STATE_SAMPLER(0), StateTable);
673 Context_MarkStateDirty(context, STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), StateTable);
675 /* Other misc states */
676 glDisable(GL_ALPHA_TEST);
677 checkGLcall("glDisable(GL_ALPHA_TEST)");
678 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHATESTENABLE), StateTable);
679 glDisable(GL_LIGHTING);
680 checkGLcall("glDisable GL_LIGHTING");
681 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_LIGHTING), StateTable);
682 glDisable(GL_DEPTH_TEST);
683 checkGLcall("glDisable GL_DEPTH_TEST");
684 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ZENABLE), StateTable);
685 glDisable(GL_FOG);
686 checkGLcall("glDisable GL_FOG");
687 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_FOGENABLE), StateTable);
688 glDisable(GL_BLEND);
689 checkGLcall("glDisable GL_BLEND");
690 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
691 glDisable(GL_CULL_FACE);
692 checkGLcall("glDisable GL_CULL_FACE");
693 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CULLMODE), StateTable);
694 glDisable(GL_STENCIL_TEST);
695 checkGLcall("glDisable GL_STENCIL_TEST");
696 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_STENCILENABLE), StateTable);
697 glDisable(GL_SCISSOR_TEST);
698 checkGLcall("glDisable GL_SCISSOR_TEST");
699 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), StateTable);
700 if(GL_SUPPORT(ARB_POINT_SPRITE)) {
701 glDisable(GL_POINT_SPRITE_ARB);
702 checkGLcall("glDisable GL_POINT_SPRITE_ARB");
703 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_POINTSPRITEENABLE), StateTable);
705 glColorMask(GL_TRUE, GL_TRUE,GL_TRUE,GL_TRUE);
706 checkGLcall("glColorMask");
707 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPING), StateTable);
708 if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
709 glDisable(GL_COLOR_SUM_EXT);
710 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SPECULARENABLE), StateTable);
711 checkGLcall("glDisable(GL_COLOR_SUM_EXT)");
713 if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
714 GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
715 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SPECULARENABLE), StateTable);
716 checkGLcall("glFinalCombinerInputNV");
719 /* Setup transforms */
720 glMatrixMode(GL_MODELVIEW);
721 checkGLcall("glMatrixMode(GL_MODELVIEW)");
722 glLoadIdentity();
723 checkGLcall("glLoadIdentity()");
724 Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), StateTable);
726 glMatrixMode(GL_PROJECTION);
727 checkGLcall("glMatrixMode(GL_PROJECTION)");
728 glLoadIdentity();
729 checkGLcall("glLoadIdentity()");
730 glOrtho(0, width, height, 0, 0.0, -1.0);
731 checkGLcall("glOrtho");
732 Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable);
734 context->last_was_rhw = TRUE;
735 Context_MarkStateDirty(context, STATE_VDECL, StateTable); /* because of last_was_rhw = TRUE */
737 glDisable(GL_CLIP_PLANE0); checkGLcall("glDisable(clip plane 0)");
738 glDisable(GL_CLIP_PLANE1); checkGLcall("glDisable(clip plane 1)");
739 glDisable(GL_CLIP_PLANE2); checkGLcall("glDisable(clip plane 2)");
740 glDisable(GL_CLIP_PLANE3); checkGLcall("glDisable(clip plane 3)");
741 glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)");
742 glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)");
743 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPING), StateTable);
745 glViewport(0, 0, width, height);
746 checkGLcall("glViewport");
747 Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
749 This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, FALSE);
752 /*****************************************************************************
753 * findThreadContextForSwapChain
755 * Searches a swapchain for all contexts and picks one for the thread tid.
756 * If none can be found the swapchain is requested to create a new context
758 *****************************************************************************/
759 static WineD3DContext *findThreadContextForSwapChain(IWineD3DSwapChain *swapchain, DWORD tid) {
760 int i;
762 for(i = 0; i < ((IWineD3DSwapChainImpl *) swapchain)->num_contexts; i++) {
763 if(((IWineD3DSwapChainImpl *) swapchain)->context[i]->tid == tid) {
764 return ((IWineD3DSwapChainImpl *) swapchain)->context[i];
769 /* Create a new context for the thread */
770 return IWineD3DSwapChainImpl_CreateContextForThread(swapchain);
773 /*****************************************************************************
774 * FindContext
776 * Finds a context for the current render target and thread
778 * Parameters:
779 * target: Render target to find the context for
780 * tid: Thread to activate the context for
782 * Returns: The needed context
784 *****************************************************************************/
785 static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid, GLint *buffer) {
786 IWineD3DSwapChain *swapchain = NULL;
787 HRESULT hr;
788 BOOL readTexture = wined3d_settings.offscreen_rendering_mode != ORM_FBO && This->render_offscreen;
789 WineD3DContext *context = This->activeContext;
790 BOOL oldRenderOffscreen = This->render_offscreen;
791 const WINED3DFORMAT oldFmt = ((IWineD3DSurfaceImpl *) This->lastActiveRenderTarget)->resource.format;
792 const WINED3DFORMAT newFmt = ((IWineD3DSurfaceImpl *) target)->resource.format;
793 const struct StateEntry *StateTable = This->shader_backend->StateTable;
795 /* To compensate the lack of format switching with some offscreen rendering methods and on onscreen buffers
796 * the alpha blend state changes with different render target formats
798 if(oldFmt != newFmt) {
799 const GlPixelFormatDesc *glDesc;
800 const StaticPixelFormatDesc *old = getFormatDescEntry(oldFmt, NULL, NULL);
801 const StaticPixelFormatDesc *new = getFormatDescEntry(newFmt, &GLINFO_LOCATION, &glDesc);
803 /* Disable blending when the alphaMask has changed and when a format doesn't support blending */
804 if((old->alphaMask && !new->alphaMask) || (!old->alphaMask && new->alphaMask) || !(glDesc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)) {
805 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
809 hr = IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **) &swapchain);
810 if(hr == WINED3D_OK && swapchain) {
811 TRACE("Rendering onscreen\n");
813 context = findThreadContextForSwapChain(swapchain, tid);
815 This->render_offscreen = FALSE;
816 /* The context != This->activeContext will catch a NOP context change. This can occur
817 * if we are switching back to swapchain rendering in case of FBO or Back Buffer offscreen
818 * rendering. No context change is needed in that case
821 if(((IWineD3DSwapChainImpl *) swapchain)->frontBuffer == target) {
822 *buffer = GL_FRONT;
823 } else {
824 *buffer = GL_BACK;
826 if(wined3d_settings.offscreen_rendering_mode == ORM_PBUFFER) {
827 if(This->pbufferContext && tid == This->pbufferContext->tid) {
828 This->pbufferContext->tid = 0;
831 IWineD3DSwapChain_Release(swapchain);
833 if(oldRenderOffscreen) {
834 Context_MarkStateDirty(context, WINED3DTS_PROJECTION, StateTable);
835 Context_MarkStateDirty(context, STATE_VDECL, StateTable);
836 Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
837 Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
838 Context_MarkStateDirty(context, STATE_FRONTFACE, StateTable);
841 } else {
842 TRACE("Rendering offscreen\n");
843 This->render_offscreen = TRUE;
844 *buffer = This->offscreenBuffer;
846 switch(wined3d_settings.offscreen_rendering_mode) {
847 case ORM_FBO:
848 /* FBOs do not need a different context. Stay with whatever context is active at the moment */
849 if(This->activeContext && tid == This->lastThread) {
850 context = This->activeContext;
851 } else {
852 /* This may happen if the app jumps straight into offscreen rendering
853 * Start using the context of the primary swapchain. tid == 0 is no problem
854 * for findThreadContextForSwapChain.
856 * Can also happen on thread switches - in that case findThreadContextForSwapChain
857 * is perfect to call.
859 context = findThreadContextForSwapChain(This->swapchains[0], tid);
861 break;
863 case ORM_PBUFFER:
865 IWineD3DSurfaceImpl *targetimpl = (IWineD3DSurfaceImpl *) target;
866 if(This->pbufferContext == NULL ||
867 This->pbufferWidth < targetimpl->currentDesc.Width ||
868 This->pbufferHeight < targetimpl->currentDesc.Height) {
869 if(This->pbufferContext) {
870 DestroyContext(This, This->pbufferContext);
873 /* The display is irrelevant here, the window is 0. But CreateContext needs a valid X connection.
874 * Create the context on the same server as the primary swapchain. The primary swapchain is exists at this point.
876 This->pbufferContext = CreateContext(This, targetimpl,
877 ((IWineD3DSwapChainImpl *) This->swapchains[0])->context[0]->win_handle,
878 TRUE /* pbuffer */, &((IWineD3DSwapChainImpl *)This->swapchains[0])->presentParms);
879 This->pbufferWidth = targetimpl->currentDesc.Width;
880 This->pbufferHeight = targetimpl->currentDesc.Height;
883 if(This->pbufferContext) {
884 if(This->pbufferContext->tid != 0 && This->pbufferContext->tid != tid) {
885 FIXME("The PBuffr context is only supported for one thread for now!\n");
887 This->pbufferContext->tid = tid;
888 context = This->pbufferContext;
889 break;
890 } else {
891 ERR("Failed to create a buffer context and drawable, falling back to back buffer offscreen rendering\n");
892 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
896 case ORM_BACKBUFFER:
897 /* Stay with the currently active context for back buffer rendering */
898 if(This->activeContext && tid == This->lastThread) {
899 context = This->activeContext;
900 } else {
901 /* This may happen if the app jumps straight into offscreen rendering
902 * Start using the context of the primary swapchain. tid == 0 is no problem
903 * for findThreadContextForSwapChain.
905 * Can also happen on thread switches - in that case findThreadContextForSwapChain
906 * is perfect to call.
908 context = findThreadContextForSwapChain(This->swapchains[0], tid);
910 break;
913 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) {
914 /* Make sure we have a OpenGL texture name so the PreLoad() used to read the buffer
915 * back when we are done won't mark us dirty.
917 IWineD3DSurface_PreLoad(target);
920 if(!oldRenderOffscreen) {
921 Context_MarkStateDirty(context, WINED3DTS_PROJECTION, StateTable);
922 Context_MarkStateDirty(context, STATE_VDECL, StateTable);
923 Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
924 Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
925 Context_MarkStateDirty(context, STATE_FRONTFACE, StateTable);
928 if (readTexture) {
929 BOOL oldInDraw = This->isInDraw;
931 /* PreLoad requires a context to load the texture, thus it will call ActivateContext.
932 * Set the isInDraw to true to signal PreLoad that it has a context. Will be tricky
933 * when using offscreen rendering with multithreading
935 This->isInDraw = TRUE;
937 /* Do that before switching the context:
938 * Read the back buffer of the old drawable into the destination texture
940 IWineD3DSurface_PreLoad(This->lastActiveRenderTarget);
942 /* Assume that the drawable will be modified by some other things now */
943 IWineD3DSurface_ModifyLocation(This->lastActiveRenderTarget, SFLAG_INDRAWABLE, FALSE);
945 This->isInDraw = oldInDraw;
948 if(oldRenderOffscreen != This->render_offscreen && This->depth_copy_state != WINED3D_DCS_NO_COPY) {
949 This->depth_copy_state = WINED3D_DCS_COPY;
951 return context;
954 /*****************************************************************************
955 * ActivateContext
957 * Finds a rendering context and drawable matching the device and render
958 * target for the current thread, activates them and puts them into the
959 * requested state.
961 * Params:
962 * This: Device to activate the context for
963 * target: Requested render target
964 * usage: Prepares the context for blitting, drawing or other actions
966 *****************************************************************************/
967 void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextUsage usage) {
968 DWORD tid = GetCurrentThreadId();
969 int i;
970 DWORD dirtyState, idx;
971 BYTE shift;
972 WineD3DContext *context;
973 GLint drawBuffer=0;
974 const struct StateEntry *StateTable = This->shader_backend->StateTable;
976 TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
977 if(This->lastActiveRenderTarget != target || tid != This->lastThread) {
978 context = FindContext(This, target, tid, &drawBuffer);
979 This->lastActiveRenderTarget = target;
980 This->lastThread = tid;
981 } else {
982 /* Stick to the old context */
983 context = This->activeContext;
986 /* Activate the opengl context */
987 if(context != This->activeContext) {
988 BOOL ret;
990 /* Prevent an unneeded context switch as those are expensive */
991 if(context->glCtx && (context->glCtx == pwglGetCurrentContext())) {
992 TRACE("Already using gl context %p\n", context->glCtx);
994 else {
995 TRACE("Switching gl ctx to %p, hdc=%p ctx=%p\n", context, context->hdc, context->glCtx);
997 This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, FALSE);
998 ret = pwglMakeCurrent(context->hdc, context->glCtx);
999 if(ret == FALSE) {
1000 ERR("Failed to activate the new context\n");
1001 } else if(!context->last_was_blit) {
1002 This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
1005 if(This->activeContext->vshader_const_dirty) {
1006 memset(This->activeContext->vshader_const_dirty, 1,
1007 sizeof(*This->activeContext->vshader_const_dirty) * GL_LIMITS(vshader_constantsF));
1009 if(This->activeContext->pshader_const_dirty) {
1010 memset(This->activeContext->pshader_const_dirty, 1,
1011 sizeof(*This->activeContext->pshader_const_dirty) * GL_LIMITS(pshader_constantsF));
1013 This->activeContext = context;
1016 /* We only need ENTER_GL for the gl calls made below and for the helper functions which make GL calls */
1017 ENTER_GL();
1018 /* Select the right draw buffer. It is selected in FindContext. */
1019 if(drawBuffer && context->last_draw_buffer != drawBuffer) {
1020 TRACE("Drawing to buffer: %#x\n", drawBuffer);
1021 context->last_draw_buffer = drawBuffer;
1023 glDrawBuffer(drawBuffer);
1024 checkGLcall("glDrawBuffer");
1027 switch(usage) {
1028 case CTXUSAGE_RESOURCELOAD:
1029 /* This does not require any special states to be set up */
1030 break;
1032 case CTXUSAGE_CLEAR:
1033 if(context->last_was_blit) {
1034 This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
1037 /* Blending and clearing should be orthogonal, but tests on the nvidia driver show that disabling
1038 * blending when clearing improves the clearing performance incredibly.
1040 glDisable(GL_BLEND);
1041 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
1043 glEnable(GL_SCISSOR_TEST);
1044 checkGLcall("glEnable GL_SCISSOR_TEST");
1045 context->last_was_blit = FALSE;
1046 Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), StateTable);
1047 Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
1048 break;
1050 case CTXUSAGE_DRAWPRIM:
1051 /* This needs all dirty states applied */
1052 if(context->last_was_blit) {
1053 This->shader_backend->shader_fragment_enable((IWineD3DDevice *) This, TRUE);
1056 IWineD3DDeviceImpl_FindTexUnitMap(This);
1058 for(i=0; i < context->numDirtyEntries; i++) {
1059 dirtyState = context->dirtyArray[i];
1060 idx = dirtyState >> 5;
1061 shift = dirtyState & 0x1f;
1062 context->isStateDirty[idx] &= ~(1 << shift);
1063 StateTable[dirtyState].apply(dirtyState, This->stateBlock, context);
1065 context->numDirtyEntries = 0; /* This makes the whole list clean */
1066 context->last_was_blit = FALSE;
1067 break;
1069 case CTXUSAGE_BLIT:
1070 SetupForBlit(This, context,
1071 ((IWineD3DSurfaceImpl *)target)->currentDesc.Width,
1072 ((IWineD3DSurfaceImpl *)target)->currentDesc.Height);
1073 break;
1075 default:
1076 FIXME("Unexpected context usage requested\n");
1078 LEAVE_GL();