2 * IDirect3DSurface8 implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2004 Christian Costa
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
37 #include "wine/debug.h"
39 #include "d3d8_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
43 /* IDirect3DVolume IUnknown parts follow: */
44 HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface,REFIID riid,LPVOID *ppobj)
46 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
48 if (IsEqualGUID(riid, &IID_IUnknown)
49 || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
50 IDirect3DSurface8Impl_AddRef(iface);
55 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
59 ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
60 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
61 ULONG ref = InterlockedIncrement(&This->ref);
63 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
68 ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
69 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
70 ULONG ref = InterlockedDecrement(&This->ref);
72 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
75 HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
76 HeapFree(GetProcessHeap(), 0, This);
81 /* IDirect3DSurface8: */
82 HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8** ppDevice) {
83 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
84 TRACE("(%p) : returning %p\n", This, This->Device);
85 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
87 * Note Calling this method will increase the internal reference count
88 * on the IDirect3DDevice8 interface.
90 IDirect3DDevice8Impl_AddRef(*ppDevice);
94 HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
95 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
96 FIXME("(%p) : stub\n", This);
100 HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
101 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
102 FIXME("(%p) : stub\n", This);
106 HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
107 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
108 FIXME("(%p) : stub\n", This);
112 HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void** ppContainer) {
113 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
115 res = IUnknown_QueryInterface(This->Container, riid, ppContainer);
116 if (E_NOINTERFACE == res) {
118 * If the surface is created using CreateImageSurface, CreateRenderTarget,
119 * or CreateDepthStencilSurface, the surface is considered stand alone. In this case,
120 * GetContainer will return the Direct3D device used to create the surface.
122 res = IUnknown_QueryInterface(This->Container, &IID_IDirect3DDevice8, ppContainer);
124 TRACE("(%p) : returning %p\n", This, *ppContainer);
128 HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
129 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
131 TRACE("(%p) : copying into %p\n", This, pDesc);
132 memcpy(pDesc, &This->myDesc, sizeof(D3DSURFACE_DESC));
136 HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
138 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
140 /* fixme: should we really lock as such? */
141 if (This->inTexture && This->inPBuffer) {
142 FIXME("Warning: Surface is in texture memory or pbuffer\n");
147 if (FALSE == This->lockable) {
148 /* Note: UpdateTextures calls CopyRects which calls this routine to populate the
149 texture regions, and since the destination is an unlockable region we need
151 TRACE("Warning: trying to lock unlockable surf@%p\n", This);
152 /*return D3DERR_INVALIDCALL; */
155 if (This == This->Device->backBuffer || This == This->Device->renderTarget || This == This->Device->frontBuffer || This->Device->depthStencilBuffer) {
156 if (This == This->Device->backBuffer) {
157 TRACE("(%p, backBuffer) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
158 } else if (This == This->Device->frontBuffer) {
159 TRACE("(%p, frontBuffer) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
160 } else if (This == This->Device->renderTarget) {
161 TRACE("(%p, renderTarget) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
162 } else if (This == This->Device->depthStencilBuffer) {
163 TRACE("(%p, stencilBuffer) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
166 TRACE("(%p) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
169 /* DXTn formats don't have exact pitches as they are to the new row of blocks,
170 where each block is 4x4 pixels, 8 bytes (dxt1) and 16 bytes (dxt2/3/4/5)
171 ie pitch = (width/4) * bytes per block */
172 if (This->myDesc.Format == D3DFMT_DXT1) /* DXT1 is 8 bytes per block */
173 pLockedRect->Pitch = (This->myDesc.Width/4) * 8;
174 else if (This->myDesc.Format == D3DFMT_DXT2 || This->myDesc.Format == D3DFMT_DXT3 ||
175 This->myDesc.Format == D3DFMT_DXT4 || This->myDesc.Format == D3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */
176 pLockedRect->Pitch = (This->myDesc.Width/4) * 16;
178 pLockedRect->Pitch = This->bytesPerPixel * This->myDesc.Width; /* Bytes / row */
181 pLockedRect->pBits = This->allocatedMemory;
182 This->lockedRect.left = 0;
183 This->lockedRect.top = 0;
184 This->lockedRect.right = This->myDesc.Width;
185 This->lockedRect.bottom = This->myDesc.Height;
186 TRACE("Locked Rect (%p) = l %ld, t %ld, r %ld, b %ld\n", &This->lockedRect, This->lockedRect.left, This->lockedRect.top, This->lockedRect.right, This->lockedRect.bottom);
188 TRACE("Lock Rect (%p) = l %ld, t %ld, r %ld, b %ld\n", pRect, pRect->left, pRect->top, pRect->right, pRect->bottom);
190 if (This->myDesc.Format == D3DFMT_DXT1) { /* DXT1 is half byte per pixel */
191 pLockedRect->pBits = This->allocatedMemory + (pLockedRect->Pitch * pRect->top) + ((pRect->left * This->bytesPerPixel/2));
193 pLockedRect->pBits = This->allocatedMemory + (pLockedRect->Pitch * pRect->top) + (pRect->left * This->bytesPerPixel);
195 This->lockedRect.left = pRect->left;
196 This->lockedRect.top = pRect->top;
197 This->lockedRect.right = pRect->right;
198 This->lockedRect.bottom = pRect->bottom;
202 if (0 == This->myDesc.Usage) { /* classic surface */
204 /* Nothing to do ;) */
206 } else if (D3DUSAGE_RENDERTARGET & This->myDesc.Usage && !(Flags&D3DLOCK_DISCARD)) { /* render surfaces */
208 if (This == This->Device->backBuffer || This == This->Device->renderTarget || This == This->Device->frontBuffer) {
215 * for render->surface copy begin to begin of allocatedMemory
216 * unlock can be more easy
218 pLockedRect->pBits = This->allocatedMemory;
221 vcheckGLcall("glFlush");
222 glGetIntegerv(GL_READ_BUFFER, &prev_read);
223 vcheckGLcall("glIntegerv");
224 glGetIntegerv(GL_PACK_SWAP_BYTES, &prev_store);
225 vcheckGLcall("glIntegerv");
227 if (This == This->Device->backBuffer) {
228 glReadBuffer(GL_BACK);
229 } else if (This == This->Device->frontBuffer || This == This->Device->renderTarget) {
230 glReadBuffer(GL_FRONT);
231 } else if (This == This->Device->depthStencilBuffer) {
232 ERR("Stencil Buffer lock unsupported for now\n");
234 vcheckGLcall("glReadBuffer");
238 GLenum format = D3DFmt2GLFmt(This->Device, This->myDesc.Format);
239 GLenum type = D3DFmt2GLType(This->Device, This->myDesc.Format);
240 for (j = This->lockedRect.top; j < This->lockedRect.bottom - This->lockedRect.top; ++j) {
241 glReadPixels(This->lockedRect.left,
242 This->lockedRect.bottom - j - 1,
243 This->lockedRect.right - This->lockedRect.left,
247 (char *)pLockedRect->pBits + (pLockedRect->Pitch * (j-This->lockedRect.top)));
248 vcheckGLcall("glReadPixels");
252 glReadBuffer(prev_read);
253 vcheckGLcall("glReadBuffer");
258 FIXME("unsupported locking to Rendering surface surf@%p usage(%lu)\n", This, This->myDesc.Usage);
261 } else if (D3DUSAGE_DEPTHSTENCIL & This->myDesc.Usage) { /* stencil surfaces */
263 FIXME("TODO stencil depth surface locking surf@%p usage(%lu)\n", This, This->myDesc.Usage);
266 FIXME("unsupported locking to surface surf@%p usage(%lu)\n", This, This->myDesc.Usage);
269 if (Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY)) {
274 * as seen in msdn docs
276 IDirect3DSurface8Impl_AddDirtyRect(iface, &This->lockedRect);
278 /** Dirtify Container if needed */
279 if (NULL != This->Container) {
280 IDirect3DBaseTexture8* cont = NULL;
281 hr = IUnknown_QueryInterface(This->Container, &IID_IDirect3DBaseTexture8, (void**) &cont);
283 if (SUCCEEDED(hr) && NULL != cont) {
284 IDirect3DBaseTexture8Impl_SetDirty(cont, TRUE);
285 IDirect3DBaseTexture8_Release(cont);
291 TRACE("returning memory@%p, pitch(%d) dirtyfied(%d)\n", pLockedRect->pBits, pLockedRect->Pitch, This->Dirty);
297 HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
299 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
301 if (FALSE == This->locked) {
302 ERR("trying to Unlock an unlocked surf@%p\n", This);
303 return D3DERR_INVALIDCALL;
306 if (This == This->Device->backBuffer || This == This->Device->frontBuffer || This->Device->depthStencilBuffer || This == This->Device->renderTarget) {
307 if (This == This->Device->backBuffer) {
308 TRACE("(%p, backBuffer) : dirtyfied(%d)\n", This, This->Dirty);
309 } else if (This == This->Device->frontBuffer) {
310 TRACE("(%p, frontBuffer) : dirtyfied(%d)\n", This, This->Dirty);
311 } else if (This == This->Device->depthStencilBuffer) {
312 TRACE("(%p, stencilBuffer) : dirtyfied(%d)\n", This, This->Dirty);
313 } else if (This == This->Device->renderTarget) {
314 TRACE("(%p, renderTarget) : dirtyfied(%d)\n", This, This->Dirty);
317 TRACE("(%p) : dirtyfied(%d)\n", This, This->Dirty);
320 if (FALSE == This->Dirty) {
321 TRACE("(%p) : Not Dirtified so nothing to do, return now\n", This);
325 if (0 == This->myDesc.Usage) { /* classic surface */
328 * waiting to reload the surface via IDirect3DDevice8::UpdateTexture
330 } else if (D3DUSAGE_RENDERTARGET & This->myDesc.Usage) { /* render surfaces */
332 if (This == This->Device->backBuffer || This == This->Device->frontBuffer || This == This->Device->renderTarget) {
335 GLint prev_rasterpos[4];
340 vcheckGLcall("glFlush");
341 glGetIntegerv(GL_DRAW_BUFFER, &prev_draw);
342 vcheckGLcall("glIntegerv");
343 glGetIntegerv(GL_PACK_SWAP_BYTES, &prev_store);
344 vcheckGLcall("glIntegerv");
345 glGetIntegerv(GL_CURRENT_RASTER_POSITION, &prev_rasterpos[0]);
346 vcheckGLcall("glIntegerv");
347 glPixelZoom(1.0, -1.0);
348 vcheckGLcall("glPixelZoom");
350 /* glDrawPixels transforms the raster position as though it was a vertex -
351 we want to draw at screen position 0,0 - Set up ortho (rhw) mode as
352 per drawprim (and leave set - it will sort itself out due to last_was_rhw */
353 if (!This->Device->last_was_rhw) {
355 double X, Y, height, width, minZ, maxZ;
356 This->Device->last_was_rhw = TRUE;
358 /* Transformed already into viewport coordinates, so we do not need transform
359 matrices. Reset all matrices to identity and leave the default matrix in world
361 glMatrixMode(GL_MODELVIEW);
362 checkGLcall("glMatrixMode");
364 checkGLcall("glLoadIdentity");
366 glMatrixMode(GL_PROJECTION);
367 checkGLcall("glMatrixMode");
369 checkGLcall("glLoadIdentity");
371 /* Set up the viewport to be full viewport */
372 X = This->Device->StateBlock->viewport.X;
373 Y = This->Device->StateBlock->viewport.Y;
374 height = This->Device->StateBlock->viewport.Height;
375 width = This->Device->StateBlock->viewport.Width;
376 minZ = This->Device->StateBlock->viewport.MinZ;
377 maxZ = This->Device->StateBlock->viewport.MaxZ;
378 TRACE("Calling glOrtho with %f, %f, %f, %f\n", width, height, -minZ, -maxZ);
379 glOrtho(X, X + width, Y + height, Y, -minZ, -maxZ);
380 checkGLcall("glOrtho");
382 /* Window Coord 0 is the middle of the first pixel, so translate by half
383 a pixel (See comment above glTranslate below) */
384 glTranslatef(0.5, 0.5, 0);
385 checkGLcall("glTranslatef(0.5, 0.5, 0)");
388 if (This == This->Device->backBuffer) {
389 glDrawBuffer(GL_BACK);
390 } else if (This == This->Device->frontBuffer || This == This->Device->renderTarget) {
391 glDrawBuffer(GL_FRONT);
393 vcheckGLcall("glDrawBuffer");
395 /* If not fullscreen, we need to skip a number of bytes to find the next row of data */
396 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &skipBytes);
397 glPixelStorei(GL_UNPACK_ROW_LENGTH, This->myDesc.Width);
399 /* And back buffers are not blended */
402 glRasterPos3i(This->lockedRect.left, This->lockedRect.top, 1);
403 vcheckGLcall("glRasterPos2f");
404 switch (This->myDesc.Format) {
407 glDrawPixels(This->lockedRect.right - This->lockedRect.left, (This->lockedRect.bottom - This->lockedRect.top)-1,
408 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, This->allocatedMemory);
409 vcheckGLcall("glDrawPixels");
414 glDrawPixels(This->lockedRect.right - This->lockedRect.left, (This->lockedRect.bottom - This->lockedRect.top)-1,
415 GL_RGB, GL_UNSIGNED_BYTE, This->allocatedMemory);
416 vcheckGLcall("glDrawPixels");
419 case D3DFMT_A8R8G8B8:
421 glPixelStorei(GL_PACK_SWAP_BYTES, TRUE);
422 vcheckGLcall("glPixelStorei");
423 glDrawPixels(This->lockedRect.right - This->lockedRect.left, (This->lockedRect.bottom - This->lockedRect.top)-1,
424 GL_BGRA, GL_UNSIGNED_BYTE, This->allocatedMemory);
425 vcheckGLcall("glDrawPixels");
426 glPixelStorei(GL_PACK_SWAP_BYTES, prev_store);
427 vcheckGLcall("glPixelStorei");
431 FIXME("Unsupported Format %u in locking func\n", This->myDesc.Format);
434 glPixelZoom(1.0,1.0);
435 vcheckGLcall("glPixelZoom");
436 glDrawBuffer(prev_draw);
437 vcheckGLcall("glDrawBuffer");
438 glRasterPos3iv(&prev_rasterpos[0]);
439 vcheckGLcall("glRasterPos3iv");
441 /* Reset to previous pack row length / blending state */
442 glPixelStorei(GL_UNPACK_ROW_LENGTH, skipBytes);
443 if (This->Device->StateBlock->renderstate[D3DRS_ALPHABLENDENABLE]) glEnable(GL_BLEND);
447 /** restore clean dirty state */
448 IDirect3DSurface8Impl_CleanDirtyRect(iface);
451 FIXME("unsupported unlocking to Rendering surface surf@%p usage(%lu)\n", This, This->myDesc.Usage);
454 } else if (D3DUSAGE_DEPTHSTENCIL & This->myDesc.Usage) { /* stencil surfaces */
456 if (This == This->Device->depthStencilBuffer) {
457 FIXME("TODO stencil depth surface unlocking surf@%p usage(%lu)\n", This, This->myDesc.Usage);
459 FIXME("unsupported unlocking to StencilDepth surface surf@%p usage(%lu)\n", This, This->myDesc.Usage);
463 FIXME("unsupported unlocking to surface surf@%p usage(%lu)\n", This, This->myDesc.Usage);
467 This->locked = FALSE;
468 memset(&This->lockedRect, 0, sizeof(RECT));
473 const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
475 IDirect3DSurface8Impl_QueryInterface,
476 IDirect3DSurface8Impl_AddRef,
477 IDirect3DSurface8Impl_Release,
478 IDirect3DSurface8Impl_GetDevice,
479 IDirect3DSurface8Impl_SetPrivateData,
480 IDirect3DSurface8Impl_GetPrivateData,
481 IDirect3DSurface8Impl_FreePrivateData,
482 IDirect3DSurface8Impl_GetContainer,
483 IDirect3DSurface8Impl_GetDesc,
484 IDirect3DSurface8Impl_LockRect,
485 IDirect3DSurface8Impl_UnlockRect,
489 HRESULT WINAPI IDirect3DSurface8Impl_LoadTexture(LPDIRECT3DSURFACE8 iface, UINT gl_target, UINT gl_level) {
490 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
494 if (This->inPBuffer) {
497 FIXME("Surface in texture is only supported for level 0\n");
498 else if (This->myDesc.Format == D3DFMT_P8 || This->myDesc.Format == D3DFMT_A8P8 ||
499 This->myDesc.Format == D3DFMT_DXT1 || This->myDesc.Format == D3DFMT_DXT2 ||
500 This->myDesc.Format == D3DFMT_DXT3 || This->myDesc.Format == D3DFMT_DXT4 ||
501 This->myDesc.Format == D3DFMT_DXT5)
502 FIXME("Format %d not supported\n", This->myDesc.Format);
504 glCopyTexImage2D(gl_target,
506 D3DFmt2GLIntFmt(This->Device,
507 This->myDesc.Format),
509 0,/*This->surfaces[j][i]->myDesc.Height-1,*/
513 TRACE("Updating target %d\n", gl_target);
514 This->inTexture = TRUE;
520 if ((This->myDesc.Format == D3DFMT_P8 || This->myDesc.Format == D3DFMT_A8P8) &&
521 !GL_SUPPORT_DEV(EXT_PALETTED_TEXTURE, This->Device)) {
523 * wanted a paletted texture and not really support it in HW
524 * so software emulation code begin
527 PALETTEENTRY* pal = This->Device->palettes[This->Device->currentPalette];
528 VOID* surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->myDesc.Width * This->myDesc.Height * sizeof(DWORD));
530 BYTE* src = (BYTE*) This->allocatedMemory;
532 for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
534 *dst++ = pal[color].peRed;
535 *dst++ = pal[color].peGreen;
536 *dst++ = pal[color].peBlue;
537 if (This->myDesc.Format == D3DFMT_A8P8)
538 *dst++ = pal[color].peFlags;
545 TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
555 glTexImage2D(gl_target,
564 checkGLcall("glTexImage2D");
565 HeapFree(GetProcessHeap(), 0, surface);
572 if (This->myDesc.Format == D3DFMT_DXT1 ||
573 This->myDesc.Format == D3DFMT_DXT2 ||
574 This->myDesc.Format == D3DFMT_DXT3 ||
575 This->myDesc.Format == D3DFMT_DXT4 ||
576 This->myDesc.Format == D3DFMT_DXT5) {
577 if (GL_SUPPORT_DEV(EXT_TEXTURE_COMPRESSION_S3TC, This->Device)) {
578 TRACE("Calling glCompressedTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, sz=%d, Mem=%p\n",
581 D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
586 This->allocatedMemory);
590 GL_EXTCALL_DEV(glCompressedTexImage2DARB, This->Device)(gl_target,
592 D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
597 This->allocatedMemory);
598 checkGLcall("glCommpressedTexTexImage2D");
602 FIXME("Using DXT1/3/5 without advertized support\n");
606 TRACE("Calling glTexImage2D %x i=%d, d3dfmt=%s, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
609 debug_d3dformat(This->myDesc.Format),
610 D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
614 D3DFmt2GLFmt(This->Device, This->myDesc.Format),
615 D3DFmt2GLType(This->Device, This->myDesc.Format),
616 This->allocatedMemory);
620 glTexImage2D(gl_target,
622 D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
626 D3DFmt2GLFmt(This->Device, This->myDesc.Format),
627 D3DFmt2GLType(This->Device, This->myDesc.Format),
628 This->allocatedMemory);
629 checkGLcall("glTexImage2D");
635 static unsigned int gen = 0;
638 if ((gen % 10) == 0) {
639 snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm", This, gl_target, gl_level, gen);
640 IDirect3DSurface8Impl_SaveSnapshot((LPDIRECT3DSURFACE8) This, buffer);
643 * debugging crash code
657 HRESULT WINAPI IDirect3DSurface8Impl_SaveSnapshot(LPDIRECT3DSURFACE8 iface, const char* filename) {
660 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
662 f = fopen(filename, "w+");
664 ERR("opening of %s failed with: %s\n", filename, strerror(errno));
665 return D3DERR_INVALIDCALL;
668 TRACE("opened %s with format %s\n", filename, debug_d3dformat(This->myDesc.Format));
670 fprintf(f, "P6\n%u %u\n255\n", This->myDesc.Width, This->myDesc.Height);
671 switch (This->myDesc.Format) {
672 case D3DFMT_X8R8G8B8:
673 case D3DFMT_A8R8G8B8:
676 for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
677 color = ((DWORD*) This->allocatedMemory)[i];
678 fputc((color >> 16) & 0xFF, f);
679 fputc((color >> 8) & 0xFF, f);
680 fputc((color >> 0) & 0xFF, f);
687 for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
688 color = ((BYTE*) This->allocatedMemory) + (3 * i);
689 fputc((color[0]) & 0xFF, f);
690 fputc((color[1]) & 0xFF, f);
691 fputc((color[2]) & 0xFF, f);
695 case D3DFMT_A1R5G5B5:
698 for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
699 color = ((WORD*) This->allocatedMemory)[i];
700 fputc(((color >> 10) & 0x1F) * 255 / 31, f);
701 fputc(((color >> 5) & 0x1F) * 255 / 31, f);
702 fputc(((color >> 0) & 0x1F) * 255 / 31, f);
706 case D3DFMT_A4R4G4B4:
709 for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
710 color = ((WORD*) This->allocatedMemory)[i];
711 fputc(((color >> 8) & 0x0F) * 255 / 15, f);
712 fputc(((color >> 4) & 0x0F) * 255 / 15, f);
713 fputc(((color >> 0) & 0x0F) * 255 / 15, f);
721 for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
722 color = ((WORD*) This->allocatedMemory)[i];
723 fputc(((color >> 11) & 0x1F) * 255 / 31, f);
724 fputc(((color >> 5) & 0x3F) * 255 / 63, f);
725 fputc(((color >> 0) & 0x1F) * 255 / 31, f);
730 FIXME("Unimplemented dump mode format(%u,%s)\n", This->myDesc.Format, debug_d3dformat(This->myDesc.Format));
736 HRESULT WINAPI IDirect3DSurface8Impl_CleanDirtyRect(LPDIRECT3DSURFACE8 iface) {
737 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
739 This->dirtyRect.left = This->myDesc.Width;
740 This->dirtyRect.top = This->myDesc.Height;
741 This->dirtyRect.right = 0;
742 This->dirtyRect.bottom = 0;
748 * very stupid way to handle multiple dirty rects but it works :)
750 extern HRESULT WINAPI IDirect3DSurface8Impl_AddDirtyRect(LPDIRECT3DSURFACE8 iface, CONST RECT* pDirtyRect) {
751 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
753 if (NULL != pDirtyRect) {
754 This->dirtyRect.left = min(This->dirtyRect.left, pDirtyRect->left);
755 This->dirtyRect.top = min(This->dirtyRect.top, pDirtyRect->top);
756 This->dirtyRect.right = max(This->dirtyRect.right, pDirtyRect->right);
757 This->dirtyRect.bottom = max(This->dirtyRect.bottom, pDirtyRect->bottom);
759 This->dirtyRect.left = 0;
760 This->dirtyRect.top = 0;
761 This->dirtyRect.right = This->myDesc.Width;
762 This->dirtyRect.bottom = This->myDesc.Height;