2005-01-09 17:37:02 +00:00
|
|
|
|
/*
|
|
|
|
|
* IWineD3DSurface Implementation
|
|
|
|
|
*
|
2006-05-22 21:49:09 +00:00
|
|
|
|
* Copyright 1998 Lionel Ulmer
|
2006-05-06 16:08:33 +00:00
|
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2005-01-09 17:37:02 +00:00
|
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
|
|
|
|
* Copyright 2004 Christian Costa
|
2005-07-13 14:15:54 +00:00
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2007-11-01 00:38:50 +00:00
|
|
|
|
* Copyright 2006-2007 Stefan D<EFBFBD>singer for CodeWeavers
|
2007-04-08 23:53:32 +00:00
|
|
|
|
* Copyright 2007 Henri Verbeet
|
2008-02-10 21:20:15 +00:00
|
|
|
|
* Copyright 2006-2008 Roderick Colenbrander
|
2005-01-09 17:37:02 +00:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-01-09 17:37:02 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
2005-08-03 21:17:08 +00:00
|
|
|
|
#include "wine/port.h"
|
2005-01-09 17:37:02 +00:00
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
|
2007-06-09 12:27:41 +00:00
|
|
|
|
#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
2006-11-06 18:45:10 +00:00
|
|
|
|
HRESULT d3dfmt_convert_surface(BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height, UINT outpitch, CONVERT_TYPES convert, IWineD3DSurfaceImpl *surf);
|
2007-10-14 12:34:47 +00:00
|
|
|
|
static void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey);
|
2008-02-10 21:20:15 +00:00
|
|
|
|
static inline void clear_unused_channels(IWineD3DSurfaceImpl *This);
|
2006-07-17 15:27:19 +00:00
|
|
|
|
|
2008-01-02 18:52:22 +00:00
|
|
|
|
static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This) {
|
2008-02-11 00:18:06 +00:00
|
|
|
|
GLint active_texture;
|
|
|
|
|
|
|
|
|
|
/* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
|
|
|
|
|
* Read the unit back instead of switching to 0, this avoids messing around with the state manager's
|
|
|
|
|
* gl states. The current texture unit should always be a valid one.
|
|
|
|
|
*
|
|
|
|
|
* TODO: Track the current active texture per GL context instead of using glGet
|
|
|
|
|
*/
|
2008-01-02 18:52:22 +00:00
|
|
|
|
if (GL_SUPPORT(ARB_MULTITEXTURE)) {
|
2008-02-11 00:18:06 +00:00
|
|
|
|
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
|
|
|
|
|
active_texture -= GL_TEXTURE0_ARB;
|
|
|
|
|
} else {
|
|
|
|
|
active_texture = 0;
|
2008-01-02 18:52:22 +00:00
|
|
|
|
}
|
2008-02-11 00:18:06 +00:00
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(active_texture));
|
2008-01-02 18:52:22 +00:00
|
|
|
|
IWineD3DSurface_BindTexture((IWineD3DSurface *)This);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-02 18:52:56 +00:00
|
|
|
|
/* This call just downloads data, the caller is responsible for activating the
|
|
|
|
|
* right context and binding the correct texture. */
|
2006-09-11 16:51:18 +00:00
|
|
|
|
static void surface_download_data(IWineD3DSurfaceImpl *This) {
|
2007-11-02 20:28:11 +00:00
|
|
|
|
if (0 == This->glDescription.textureName) {
|
|
|
|
|
ERR("Surface does not have a texture, but SFLAG_INTEXTURE is set\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-05 09:15:46 +00:00
|
|
|
|
/* Only support read back of converted P8 surfaces */
|
|
|
|
|
if(This->Flags & SFLAG_CONVERTED && (This->resource.format != WINED3DFMT_P8)) {
|
2007-12-16 22:00:39 +00:00
|
|
|
|
FIXME("Read back converted textures unsupported, format=%s\n", debug_d3dformat(This->resource.format));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-11-02 20:28:11 +00:00
|
|
|
|
|
|
|
|
|
ENTER_GL();
|
2008-01-02 18:52:22 +00:00
|
|
|
|
|
2006-09-11 16:51:18 +00:00
|
|
|
|
if (This->resource.format == WINED3DFMT_DXT1 ||
|
|
|
|
|
This->resource.format == WINED3DFMT_DXT2 || This->resource.format == WINED3DFMT_DXT3 ||
|
|
|
|
|
This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) {
|
|
|
|
|
if (!GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) { /* We can assume this as the texture would not have been created otherwise */
|
|
|
|
|
FIXME("(%p) : Attempting to lock a compressed texture when texture compression isn't supported by opengl\n", This);
|
|
|
|
|
} else {
|
|
|
|
|
TRACE("(%p) : Calling glGetCompressedTexImageARB level %d, format %#x, type %#x, data %p\n", This, This->glDescription.level,
|
|
|
|
|
This->glDescription.glFormat, This->glDescription.glType, This->resource.allocatedMemory);
|
|
|
|
|
|
2007-09-28 12:39:24 +00:00
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
GL_EXTCALL(glGetCompressedTexImageARB(This->glDescription.target, This->glDescription.level, NULL));
|
|
|
|
|
checkGLcall("glGetCompressedTexImageARB()");
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
} else {
|
|
|
|
|
GL_EXTCALL(glGetCompressedTexImageARB(This->glDescription.target, This->glDescription.level, This->resource.allocatedMemory));
|
|
|
|
|
checkGLcall("glGetCompressedTexImageARB()");
|
|
|
|
|
}
|
2006-09-11 16:51:18 +00:00
|
|
|
|
}
|
2007-11-02 20:28:11 +00:00
|
|
|
|
LEAVE_GL();
|
2006-09-11 16:51:18 +00:00
|
|
|
|
} else {
|
2007-02-13 19:21:48 +00:00
|
|
|
|
void *mem;
|
2008-02-05 09:15:46 +00:00
|
|
|
|
GLenum format = This->glDescription.glFormat;
|
|
|
|
|
GLenum type = This->glDescription.glType;
|
2007-02-13 19:21:48 +00:00
|
|
|
|
int src_pitch = 0;
|
|
|
|
|
int dst_pitch = 0;
|
|
|
|
|
|
2008-02-05 09:15:46 +00:00
|
|
|
|
/* In case of P8 the index is stored in the alpha component if the primary render target uses P8 */
|
|
|
|
|
if(This->resource.format == WINED3DFMT_P8) {
|
|
|
|
|
format = GL_ALPHA;
|
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-13 19:21:48 +00:00
|
|
|
|
if (This->Flags & SFLAG_NONPOW2) {
|
2007-06-08 20:28:04 +00:00
|
|
|
|
unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
|
2007-02-13 19:21:48 +00:00
|
|
|
|
src_pitch = This->bytesPerPixel * This->pow2Width;
|
|
|
|
|
dst_pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This);
|
2007-06-08 20:28:04 +00:00
|
|
|
|
src_pitch = (src_pitch + alignment - 1) & ~(alignment - 1);
|
2007-02-13 19:21:48 +00:00
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, src_pitch * This->pow2Height);
|
|
|
|
|
} else {
|
|
|
|
|
mem = This->resource.allocatedMemory;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-11 16:51:18 +00:00
|
|
|
|
TRACE("(%p) : Calling glGetTexImage level %d, format %#x, type %#x, data %p\n", This, This->glDescription.level,
|
2008-02-05 09:15:46 +00:00
|
|
|
|
format, type, mem);
|
2006-09-11 16:51:18 +00:00
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
2008-02-05 09:15:46 +00:00
|
|
|
|
glGetTexImage(This->glDescription.target, This->glDescription.level, format,
|
|
|
|
|
type, NULL);
|
2007-09-11 08:31:54 +00:00
|
|
|
|
checkGLcall("glGetTexImage()");
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
} else {
|
2008-02-05 09:15:46 +00:00
|
|
|
|
glGetTexImage(This->glDescription.target, This->glDescription.level, format,
|
|
|
|
|
type, mem);
|
2007-09-11 08:31:54 +00:00
|
|
|
|
checkGLcall("glGetTexImage()");
|
|
|
|
|
}
|
2007-11-02 20:28:11 +00:00
|
|
|
|
LEAVE_GL();
|
2006-09-11 16:51:18 +00:00
|
|
|
|
|
2007-02-13 19:21:48 +00:00
|
|
|
|
if (This->Flags & SFLAG_NONPOW2) {
|
|
|
|
|
LPBYTE src_data, dst_data;
|
|
|
|
|
int y;
|
2006-09-11 16:51:18 +00:00
|
|
|
|
/*
|
|
|
|
|
* Some games (e.g. warhammer 40k) don't work properly with the odd pitches, preventing
|
|
|
|
|
* the surface pitch from being used to box non-power2 textures. Instead we have to use a hack to
|
|
|
|
|
* repack the texture so that the bpp * width pitch can be used instead of bpp * pow2width.
|
|
|
|
|
*
|
|
|
|
|
* We're doing this...
|
|
|
|
|
*
|
|
|
|
|
* instead of boxing the texture :
|
|
|
|
|
* |<-texture width ->| -->pow2width| /\
|
|
|
|
|
* |111111111111111111| | |
|
|
|
|
|
* |222 Texture 222222| boxed empty | texture height
|
|
|
|
|
* |3333 Data 33333333| | |
|
|
|
|
|
* |444444444444444444| | \/
|
|
|
|
|
* ----------------------------------- |
|
|
|
|
|
* | boxed empty | boxed empty | pow2height
|
|
|
|
|
* | | | \/
|
|
|
|
|
* -----------------------------------
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* we're repacking the data to the expected texture width
|
|
|
|
|
*
|
|
|
|
|
* |<-texture width ->| -->pow2width| /\
|
|
|
|
|
* |111111111111111111222222222222222| |
|
|
|
|
|
* |222333333333333333333444444444444| texture height
|
|
|
|
|
* |444444 | |
|
|
|
|
|
* | | \/
|
|
|
|
|
* | | |
|
|
|
|
|
* | empty | pow2height
|
|
|
|
|
* | | \/
|
|
|
|
|
* -----------------------------------
|
|
|
|
|
*
|
|
|
|
|
* == is the same as
|
|
|
|
|
*
|
|
|
|
|
* |<-texture width ->| /\
|
|
|
|
|
* |111111111111111111|
|
|
|
|
|
* |222222222222222222|texture height
|
|
|
|
|
* |333333333333333333|
|
|
|
|
|
* |444444444444444444| \/
|
|
|
|
|
* --------------------
|
|
|
|
|
*
|
|
|
|
|
* this also means that any references to allocatedMemory should work with the data as if were a
|
|
|
|
|
* standard texture with a non-power2 width instead of texture boxed up to be a power2 texture.
|
|
|
|
|
*
|
|
|
|
|
* internally the texture is still stored in a boxed format so any references to textureName will
|
|
|
|
|
* get a boxed texture with width pow2width and not a texture of width currentDesc.Width.
|
2007-02-13 19:21:48 +00:00
|
|
|
|
*
|
|
|
|
|
* Performance should not be an issue, because applications normally do not lock the surfaces when
|
|
|
|
|
* rendering. If an app does, the SFLAG_DYNLOCK flag will kick in and the memory copy won't be released,
|
|
|
|
|
* and doesn't have to be re-read.
|
2006-09-11 16:51:18 +00:00
|
|
|
|
*/
|
2007-02-13 19:21:48 +00:00
|
|
|
|
src_data = mem;
|
|
|
|
|
dst_data = This->resource.allocatedMemory;
|
|
|
|
|
TRACE("(%p) : Repacking the surface data from pitch %d to pitch %d\n", This, src_pitch, dst_pitch);
|
|
|
|
|
for (y = 1 ; y < This->currentDesc.Height; y++) {
|
|
|
|
|
/* skip the first row */
|
|
|
|
|
src_data += src_pitch;
|
|
|
|
|
dst_data += dst_pitch;
|
|
|
|
|
memcpy(dst_data, src_data, dst_pitch);
|
2006-09-11 16:51:18 +00:00
|
|
|
|
}
|
2007-02-13 19:21:48 +00:00
|
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2006-09-11 16:51:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-02 20:28:11 +00:00
|
|
|
|
|
2007-06-06 23:08:26 +00:00
|
|
|
|
/* Surface has now been downloaded */
|
|
|
|
|
This->Flags |= SFLAG_INSYSMEM;
|
2006-09-11 16:51:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-02 18:52:56 +00:00
|
|
|
|
/* This call just uploads data, the caller is responsible for activating the
|
|
|
|
|
* right context and binding the correct texture. */
|
2007-06-06 23:08:26 +00:00
|
|
|
|
static void surface_upload_data(IWineD3DSurfaceImpl *This, GLenum internal, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data) {
|
2006-09-11 16:51:18 +00:00
|
|
|
|
if (This->resource.format == WINED3DFMT_DXT1 ||
|
|
|
|
|
This->resource.format == WINED3DFMT_DXT2 || This->resource.format == WINED3DFMT_DXT3 ||
|
|
|
|
|
This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) {
|
|
|
|
|
if (!GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
|
|
|
|
|
FIXME("Using DXT1/3/5 without advertized support\n");
|
|
|
|
|
} else {
|
2007-02-13 19:28:25 +00:00
|
|
|
|
/* glCompressedTexSubImage2D for uploading and glTexImage2D for allocating does not work well on some drivers(r200 dri, MacOS ATI driver)
|
|
|
|
|
* glCompressedTexImage2D does not accept NULL pointers. So for compressed textures surface_allocate_surface does nothing, and this
|
|
|
|
|
* function uses glCompressedTexImage2D instead of the SubImage call
|
|
|
|
|
*/
|
2007-09-16 11:36:35 +00:00
|
|
|
|
TRACE("(%p) : Calling glCompressedTexSubImage2D w %d, h %d, data %p\n", This, width, height, data);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
TRACE("(%p) pbo: %#x, data: %p\n", This, This->pbo, data);
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glCompressedTexImage2DARB(This->glDescription.target, This->glDescription.level, internal,
|
|
|
|
|
width, height, 0 /* border */, This->resource.size, NULL));
|
|
|
|
|
checkGLcall("glCompressedTexSubImage2D");
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
} else {
|
|
|
|
|
GL_EXTCALL(glCompressedTexImage2DARB(This->glDescription.target, This->glDescription.level, internal,
|
|
|
|
|
width, height, 0 /* border */, This->resource.size, data));
|
|
|
|
|
checkGLcall("glCompressedTexSubImage2D");
|
|
|
|
|
}
|
2006-09-11 16:51:18 +00:00
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
TRACE("(%p) : Calling glTexSubImage2D w %d, h %d, data, %p\n", This, width, height, data);
|
|
|
|
|
ENTER_GL();
|
2007-09-11 08:31:54 +00:00
|
|
|
|
|
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
TRACE("(%p) pbo: %#x, data: %p\n", This, This->pbo, data);
|
|
|
|
|
|
|
|
|
|
glTexSubImage2D(This->glDescription.target, This->glDescription.level, 0, 0, width, height, format, type, NULL);
|
|
|
|
|
checkGLcall("glTexSubImage2D");
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
glTexSubImage2D(This->glDescription.target, This->glDescription.level, 0, 0, width, height, format, type, data);
|
|
|
|
|
checkGLcall("glTexSubImage2D");
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-11 16:51:18 +00:00
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-02 18:52:56 +00:00
|
|
|
|
/* This call just allocates the texture, the caller is responsible for
|
|
|
|
|
* activating the right context and binding the correct texture. */
|
2006-09-11 16:51:18 +00:00
|
|
|
|
static void surface_allocate_surface(IWineD3DSurfaceImpl *This, GLenum internal, GLsizei width, GLsizei height, GLenum format, GLenum type) {
|
2007-03-31 21:02:37 +00:00
|
|
|
|
BOOL enable_client_storage = FALSE;
|
2007-11-03 15:24:55 +00:00
|
|
|
|
BYTE *mem = NULL;
|
2007-03-31 21:02:37 +00:00
|
|
|
|
|
2006-09-11 16:51:18 +00:00
|
|
|
|
TRACE("(%p) : Creating surface (target %#x) level %d, d3d format %s, internal format %#x, width %d, height %d, gl format %#x, gl type=%#x\n", This,
|
|
|
|
|
This->glDescription.target, This->glDescription.level, debug_d3dformat(This->resource.format), internal, width, height, format, type);
|
|
|
|
|
|
2007-02-13 19:28:25 +00:00
|
|
|
|
if (This->resource.format == WINED3DFMT_DXT1 ||
|
|
|
|
|
This->resource.format == WINED3DFMT_DXT2 || This->resource.format == WINED3DFMT_DXT3 ||
|
|
|
|
|
This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) {
|
|
|
|
|
/* glCompressedTexImage2D does not accept NULL pointers, so we cannot allocate a compressed texture without uploading data */
|
|
|
|
|
TRACE("Not allocating compressed surfaces, surface_upload_data will specify them\n");
|
2007-11-03 15:24:55 +00:00
|
|
|
|
|
|
|
|
|
/* We have to point GL to the client storage memory here, because upload_data might use a PBO. This means a double upload
|
|
|
|
|
* once, unfortunately
|
|
|
|
|
*/
|
|
|
|
|
if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
|
|
|
|
|
/* Neither NONPOW2, DIBSECTION nor OVERSIZE flags can be set on compressed textures */
|
|
|
|
|
This->Flags |= SFLAG_CLIENT;
|
|
|
|
|
mem = (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
|
|
|
|
GL_EXTCALL(glCompressedTexImage2DARB(This->glDescription.target, This->glDescription.level, internal,
|
|
|
|
|
width, height, 0 /* border */, This->resource.size, mem));
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-13 19:28:25 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-11 16:51:18 +00:00
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
2007-03-31 21:02:37 +00:00
|
|
|
|
if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
|
|
|
|
|
if(This->Flags & (SFLAG_NONPOW2 | SFLAG_DIBSECTION | SFLAG_OVERSIZE | SFLAG_CONVERTED) || This->resource.allocatedMemory == NULL) {
|
|
|
|
|
/* In some cases we want to disable client storage.
|
|
|
|
|
* SFLAG_NONPOW2 has a bigger opengl texture than the client memory, and different pitches
|
|
|
|
|
* SFLAG_DIBSECTION: Dibsections may have read / write protections on the memory. Avoid issues...
|
|
|
|
|
* SFLAG_OVERSIZE: The gl texture is smaller than the allocated memory
|
|
|
|
|
* SFLAG_CONVERTED: The conversion destination memory is freed after loading the surface
|
|
|
|
|
* allocatedMemory == NULL: Not defined in the extension. Seems to disable client storage effectively
|
|
|
|
|
*/
|
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
|
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE)");
|
2007-09-18 22:36:39 +00:00
|
|
|
|
This->Flags &= ~SFLAG_CLIENT;
|
2007-03-31 21:02:37 +00:00
|
|
|
|
enable_client_storage = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
This->Flags |= SFLAG_CLIENT;
|
2007-11-03 15:24:55 +00:00
|
|
|
|
|
|
|
|
|
/* Point opengl to our allocated texture memory. Do not use resource.allocatedMemory here because
|
|
|
|
|
* it might point into a pbo. Instead use heapMemory, but get the alignment right.
|
|
|
|
|
*/
|
|
|
|
|
mem = (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
2007-03-31 21:02:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-03 15:24:55 +00:00
|
|
|
|
glTexImage2D(This->glDescription.target, This->glDescription.level, internal, width, height, 0, format, type, mem);
|
2006-09-11 16:51:18 +00:00
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
|
|
2007-03-31 21:02:37 +00:00
|
|
|
|
if(enable_client_storage) {
|
|
|
|
|
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
|
checkGLcall("glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE)");
|
|
|
|
|
}
|
2006-09-11 16:51:18 +00:00
|
|
|
|
LEAVE_GL();
|
2007-04-22 00:02:29 +00:00
|
|
|
|
|
|
|
|
|
This->Flags |= SFLAG_ALLOCATED;
|
2006-09-11 16:51:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-08 23:53:32 +00:00
|
|
|
|
/* In D3D the depth stencil dimensions have to be greater than or equal to the
|
|
|
|
|
* render target dimensions. With FBOs, the dimensions have to be an exact match. */
|
|
|
|
|
/* TODO: We should synchronize the renderbuffer's content with the texture's content. */
|
|
|
|
|
void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
renderbuffer_entry_t *entry;
|
|
|
|
|
GLuint renderbuffer = 0;
|
|
|
|
|
unsigned int src_width, src_height;
|
|
|
|
|
|
|
|
|
|
src_width = This->pow2Width;
|
|
|
|
|
src_height = This->pow2Height;
|
|
|
|
|
|
|
|
|
|
/* A depth stencil smaller than the render target is not valid */
|
|
|
|
|
if (width > src_width || height > src_height) return;
|
|
|
|
|
|
|
|
|
|
/* Remove any renderbuffer set if the sizes match */
|
|
|
|
|
if (width == src_width && height == src_height) {
|
|
|
|
|
This->current_renderbuffer = NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Look if we've already got a renderbuffer of the correct dimensions */
|
|
|
|
|
LIST_FOR_EACH_ENTRY(entry, &This->renderbuffers, renderbuffer_entry_t, entry) {
|
|
|
|
|
if (entry->width == width && entry->height == height) {
|
|
|
|
|
renderbuffer = entry->id;
|
|
|
|
|
This->current_renderbuffer = entry;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!renderbuffer) {
|
2007-07-23 09:13:37 +00:00
|
|
|
|
const GlPixelFormatDesc *glDesc;
|
2007-07-27 11:22:54 +00:00
|
|
|
|
getFormatDescEntry(This->resource.format, &GLINFO_LOCATION, &glDesc);
|
2007-04-08 23:53:32 +00:00
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glGenRenderbuffersEXT(1, &renderbuffer));
|
|
|
|
|
GL_EXTCALL(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbuffer));
|
2007-07-23 09:13:37 +00:00
|
|
|
|
GL_EXTCALL(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, glDesc->glFormat, width, height));
|
2007-04-08 23:53:32 +00:00
|
|
|
|
|
|
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(renderbuffer_entry_t));
|
|
|
|
|
entry->width = width;
|
|
|
|
|
entry->height = height;
|
|
|
|
|
entry->id = renderbuffer;
|
|
|
|
|
list_add_head(&This->renderbuffers, &entry->entry);
|
|
|
|
|
|
|
|
|
|
This->current_renderbuffer = entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkGLcall("set_compatible_renderbuffer");
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-16 19:20:25 +00:00
|
|
|
|
GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
IWineD3DSwapChainImpl *swapchain_impl = (IWineD3DSwapChainImpl *)swapchain;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p) : swapchain %p\n", This, swapchain);
|
|
|
|
|
|
|
|
|
|
if (swapchain_impl->backBuffer && swapchain_impl->backBuffer[0] == iface) {
|
|
|
|
|
TRACE("Returning GL_BACK\n");
|
|
|
|
|
return GL_BACK;
|
|
|
|
|
} else if (swapchain_impl->frontBuffer == iface) {
|
|
|
|
|
TRACE("Returning GL_FRONT\n");
|
|
|
|
|
return GL_FRONT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FIXME("Higher back buffer, returning GL_BACK\n");
|
|
|
|
|
return GL_BACK;
|
|
|
|
|
}
|
2007-04-08 23:53:32 +00:00
|
|
|
|
|
2005-01-09 17:37:02 +00:00
|
|
|
|
ULONG WINAPI IWineD3DSurfaceImpl_Release(IWineD3DSurface *iface) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2005-01-19 16:59:01 +00:00
|
|
|
|
ULONG ref = InterlockedDecrement(&This->resource.ref);
|
2006-10-01 03:20:10 +00:00
|
|
|
|
TRACE("(%p) : Releasing from %d\n", This, ref + 1);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
if (ref == 0) {
|
2008-01-23 21:40:02 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
2007-04-08 23:53:32 +00:00
|
|
|
|
renderbuffer_entry_t *entry, *entry2;
|
2005-07-11 20:38:27 +00:00
|
|
|
|
TRACE("(%p) : cleaning up\n", This);
|
2007-02-17 17:06:30 +00:00
|
|
|
|
|
2005-07-11 20:38:27 +00:00
|
|
|
|
if (This->glDescription.textureName != 0) { /* release the openGL texture.. */
|
2007-03-17 22:00:39 +00:00
|
|
|
|
|
|
|
|
|
/* Need a context to destroy the texture. Use the currently active render target, but only if
|
|
|
|
|
* the primary render target exists. Otherwise lastActiveRenderTarget is garbage, see above.
|
|
|
|
|
* When destroying the primary rt, Uninit3D will activate a context before doing anything
|
|
|
|
|
*/
|
2007-09-10 10:18:15 +00:00
|
|
|
|
if(device->render_targets && device->render_targets[0]) {
|
2007-03-17 22:00:39 +00:00
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 20:38:27 +00:00
|
|
|
|
TRACE("Deleting texture %d\n", This->glDescription.textureName);
|
2007-08-06 14:27:08 +00:00
|
|
|
|
ENTER_GL();
|
2005-07-11 20:38:27 +00:00
|
|
|
|
glDeleteTextures(1, &This->glDescription.textureName);
|
2005-03-14 10:12:52 +00:00
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
2006-05-06 16:08:33 +00:00
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
/* Delete the PBO */
|
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-06 16:08:33 +00:00
|
|
|
|
if(This->Flags & SFLAG_DIBSECTION) {
|
|
|
|
|
/* Release the DC */
|
|
|
|
|
SelectObject(This->hDC, This->dib.holdbitmap);
|
|
|
|
|
DeleteDC(This->hDC);
|
|
|
|
|
/* Release the DIB section */
|
|
|
|
|
DeleteObject(This->dib.DIBsection);
|
|
|
|
|
This->dib.bitmap_data = NULL;
|
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
|
}
|
2006-07-27 15:24:55 +00:00
|
|
|
|
if(This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem(iface, NULL);
|
2006-05-06 16:08:33 +00:00
|
|
|
|
|
2007-02-19 14:23:36 +00:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->palette9);
|
|
|
|
|
|
2005-03-29 19:01:00 +00:00
|
|
|
|
IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
|
2006-05-15 18:49:36 +00:00
|
|
|
|
if(iface == device->ddraw_primary)
|
|
|
|
|
device->ddraw_primary = NULL;
|
2005-07-11 20:38:27 +00:00
|
|
|
|
|
2007-04-08 23:53:32 +00:00
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry) {
|
|
|
|
|
GL_EXTCALL(glDeleteRenderbuffersEXT(1, &entry->id));
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 20:38:27 +00:00
|
|
|
|
TRACE("(%p) Released\n", This);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2005-03-14 10:12:52 +00:00
|
|
|
|
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
return ref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ****************************************************
|
|
|
|
|
IWineD3DSurface IWineD3DResource parts follow
|
|
|
|
|
**************************************************** */
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
void WINAPI IWineD3DSurfaceImpl_PreLoad(IWineD3DSurface *iface) {
|
2005-03-14 10:12:52 +00:00
|
|
|
|
/* TODO: check for locks */
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
IWineD3DBaseTexture *baseTexture = NULL;
|
2007-03-17 22:00:39 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
|
2005-07-11 20:38:27 +00:00
|
|
|
|
TRACE("(%p)Checking to see if the container is a base texture\n", This);
|
2006-04-07 10:51:12 +00:00
|
|
|
|
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture) == WINED3D_OK) {
|
2007-06-05 22:21:08 +00:00
|
|
|
|
TRACE("Passing to container\n");
|
2005-03-14 10:12:52 +00:00
|
|
|
|
IWineD3DBaseTexture_PreLoad(baseTexture);
|
|
|
|
|
IWineD3DBaseTexture_Release(baseTexture);
|
2005-07-13 14:15:54 +00:00
|
|
|
|
} else {
|
2005-03-14 10:12:52 +00:00
|
|
|
|
TRACE("(%p) : About to load surface\n", This);
|
2007-03-17 22:00:39 +00:00
|
|
|
|
|
|
|
|
|
if(!device->isInDraw) {
|
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-06 14:27:08 +00:00
|
|
|
|
ENTER_GL();
|
2005-07-11 20:38:27 +00:00
|
|
|
|
glEnable(This->glDescription.target);/* make sure texture support is enabled in this context */
|
2006-09-11 16:51:18 +00:00
|
|
|
|
if (!This->glDescription.level) {
|
|
|
|
|
if (!This->glDescription.textureName) {
|
|
|
|
|
glGenTextures(1, &This->glDescription.textureName);
|
|
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
|
TRACE("Surface %p given name %d\n", This, This->glDescription.textureName);
|
2005-03-14 10:12:52 +00:00
|
|
|
|
}
|
2006-09-11 16:51:18 +00:00
|
|
|
|
glBindTexture(This->glDescription.target, This->glDescription.textureName);
|
|
|
|
|
checkGLcall("glBindTexture");
|
2007-06-06 23:08:26 +00:00
|
|
|
|
IWineD3DSurface_LoadTexture(iface, FALSE);
|
2006-09-11 16:51:18 +00:00
|
|
|
|
/* This is where we should be reducing the amount of GLMemoryUsed */
|
|
|
|
|
} else if (This->glDescription.textureName) { /* NOTE: the level 0 surface of a mpmapped texture must be loaded first! */
|
|
|
|
|
/* assume this is a coding error not a real error for now */
|
|
|
|
|
FIXME("Mipmap surface has a glTexture bound to it!\n");
|
2005-03-14 10:12:52 +00:00
|
|
|
|
}
|
2006-03-28 12:20:47 +00:00
|
|
|
|
if (This->resource.pool == WINED3DPOOL_DEFAULT) {
|
2005-03-14 10:12:52 +00:00
|
|
|
|
/* Tell opengl to try and keep this texture in video ram (well mostly) */
|
|
|
|
|
GLclampf tmp;
|
|
|
|
|
tmp = 0.9f;
|
2005-07-11 20:38:27 +00:00
|
|
|
|
glPrioritizeTextures(1, &This->glDescription.textureName, &tmp);
|
2005-03-14 10:12:52 +00:00
|
|
|
|
}
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
return;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-12 21:33:04 +00:00
|
|
|
|
static void surface_remove_pbo(IWineD3DSurfaceImpl *This) {
|
|
|
|
|
This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
|
|
|
|
|
This->resource.allocatedMemory =
|
|
|
|
|
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
|
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBuffer(GL_PIXEL_UNPACK_BUFFER, This->pbo)");
|
|
|
|
|
GL_EXTCALL(glGetBufferSubDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0, This->resource.size, This->resource.allocatedMemory));
|
|
|
|
|
checkGLcall("glGetBufferSubData");
|
|
|
|
|
GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
|
|
|
|
|
checkGLcall("glDeleteBuffers");
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
|
|
This->pbo = 0;
|
|
|
|
|
This->Flags &= ~SFLAG_PBO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void WINAPI IWineD3DSurfaceImpl_UnLoad(IWineD3DSurface *iface) {
|
|
|
|
|
IWineD3DBaseTexture *texture = NULL;
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
2008-01-25 17:10:14 +00:00
|
|
|
|
renderbuffer_entry_t *entry, *entry2;
|
2008-01-12 21:33:04 +00:00
|
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
|
|
|
|
|
|
if(This->resource.pool == WINED3DPOOL_DEFAULT) {
|
2008-01-25 17:10:14 +00:00
|
|
|
|
/* Default pool resources are supposed to be destroyed before Reset is called.
|
|
|
|
|
* Implicit resources stay however. So this means we have an implicit render target
|
|
|
|
|
* or depth stencil. The content may be destroyed, but we still have to tear down
|
|
|
|
|
* opengl resources, so we cannot leave early.
|
|
|
|
|
*/
|
|
|
|
|
IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
|
|
|
|
|
} else {
|
|
|
|
|
/* Load the surface into system memory */
|
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL);
|
2008-01-12 21:33:04 +00:00
|
|
|
|
}
|
2008-01-25 17:10:14 +00:00
|
|
|
|
IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
|
|
|
|
|
IWineD3DSurface_ModifyLocation(iface, SFLAG_INDRAWABLE, FALSE);
|
|
|
|
|
This->Flags &= ~SFLAG_ALLOCATED;
|
2008-01-12 21:33:04 +00:00
|
|
|
|
|
|
|
|
|
/* Destroy PBOs, but load them into real sysmem before */
|
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
surface_remove_pbo(This);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-25 17:10:14 +00:00
|
|
|
|
/* Destroy fbo render buffers. This is needed for implicit render targets, for
|
|
|
|
|
* all application-created targets the application has to release the surface
|
|
|
|
|
* before calling _Reset
|
|
|
|
|
*/
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry) {
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
GL_EXTCALL(glDeleteRenderbuffersEXT(1, &entry->id));
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
list_remove(&entry->entry);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
|
}
|
|
|
|
|
list_init(&This->renderbuffers);
|
|
|
|
|
This->current_renderbuffer = NULL;
|
|
|
|
|
|
2008-01-12 21:33:04 +00:00
|
|
|
|
/* If we're in a texture, the texture name belongs to the texture. Otherwise,
|
|
|
|
|
* destroy it
|
|
|
|
|
*/
|
|
|
|
|
IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **) &texture);
|
|
|
|
|
if(!texture) {
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
glDeleteTextures(1, &This->glDescription.textureName);
|
|
|
|
|
This->glDescription.textureName = 0;
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
} else {
|
|
|
|
|
IWineD3DBaseTexture_Release(texture);
|
|
|
|
|
}
|
2008-01-12 21:56:30 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-09 17:37:02 +00:00
|
|
|
|
/* ******************************************************
|
|
|
|
|
IWineD3DSurface IWineD3DSurface parts follow
|
|
|
|
|
****************************************************** */
|
|
|
|
|
|
2005-07-13 14:15:54 +00:00
|
|
|
|
void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target) {
|
2005-07-11 20:38:27 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
TRACE("(%p) : setting textureName %u, target %i\n", This, textureName, target);
|
|
|
|
|
if (This->glDescription.textureName == 0 && textureName != 0) {
|
2007-10-09 20:17:59 +00:00
|
|
|
|
IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
|
2005-07-11 20:38:27 +00:00
|
|
|
|
IWineD3DSurface_AddDirtyRect(iface, NULL);
|
|
|
|
|
}
|
|
|
|
|
This->glDescription.textureName = textureName;
|
|
|
|
|
This->glDescription.target = target;
|
2007-04-22 00:02:29 +00:00
|
|
|
|
This->Flags &= ~SFLAG_ALLOCATED;
|
2005-07-11 20:38:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-13 14:15:54 +00:00
|
|
|
|
void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription) {
|
2005-07-11 20:38:27 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
TRACE("(%p) : returning %p\n", This, &This->glDescription);
|
|
|
|
|
*glDescription = &This->glDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: think about moving this down to resource? */
|
|
|
|
|
const void *WINAPI IWineD3DSurfaceImpl_GetData(IWineD3DSurface *iface) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2007-06-05 22:21:08 +00:00
|
|
|
|
/* This should only be called for sysmem textures, it may be a good idea to extend this to all pools at some point in the future */
|
2006-03-28 12:20:47 +00:00
|
|
|
|
if (This->resource.pool != WINED3DPOOL_SYSTEMMEM) {
|
2005-07-11 20:38:27 +00:00
|
|
|
|
FIXME(" (%p)Attempting to get system memory for a non-system memory texture\n", iface);
|
|
|
|
|
}
|
|
|
|
|
return (CONST void*)(This->resource.allocatedMemory);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-10 21:20:15 +00:00
|
|
|
|
/* Read the framebuffer back into the surface */
|
2007-11-02 21:23:22 +00:00
|
|
|
|
static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, void *dest, UINT pitch) {
|
|
|
|
|
IWineD3DSwapChainImpl *swapchain;
|
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
2007-02-13 19:24:00 +00:00
|
|
|
|
BYTE *mem;
|
2006-07-17 10:39:44 +00:00
|
|
|
|
GLint fmt;
|
|
|
|
|
GLint type;
|
2007-02-13 19:24:00 +00:00
|
|
|
|
BYTE *row, *top, *bottom;
|
|
|
|
|
int i;
|
|
|
|
|
BOOL bpp;
|
2007-11-02 21:23:22 +00:00
|
|
|
|
RECT local_rect;
|
|
|
|
|
BOOL srcIsUpsideDown;
|
|
|
|
|
|
|
|
|
|
if(wined3d_settings.rendertargetlock_mode == RTL_DISABLE) {
|
|
|
|
|
static BOOL warned = FALSE;
|
|
|
|
|
if(!warned) {
|
|
|
|
|
ERR("The application tries to lock the render target, but render target locking is disabled\n");
|
|
|
|
|
warned = TRUE;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain);
|
|
|
|
|
/* Activate the surface. Set it up for blitting now, although not necessarily needed for LockRect.
|
|
|
|
|
* Certain graphics drivers seem to dislike some enabled states when reading from opengl, the blitting usage
|
|
|
|
|
* should help here. Furthermore unlockrect will need the context set up for blitting. The context manager will find
|
|
|
|
|
* context->last_was_blit set on the unlock.
|
|
|
|
|
*/
|
|
|
|
|
ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
|
|
/* Select the correct read buffer, and give some debug output.
|
|
|
|
|
* There is no need to keep track of the current read buffer or reset it, every part of the code
|
|
|
|
|
* that reads sets the read buffer as desired.
|
|
|
|
|
*/
|
|
|
|
|
if(!swapchain) {
|
|
|
|
|
/* Locking the primary render target which is not on a swapchain(=offscreen render target).
|
|
|
|
|
* Read from the back buffer
|
|
|
|
|
*/
|
|
|
|
|
TRACE("Locking offscreen render target\n");
|
|
|
|
|
glReadBuffer(myDevice->offscreenBuffer);
|
|
|
|
|
srcIsUpsideDown = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
|
|
|
|
|
TRACE("Locking %#x buffer\n", buffer);
|
|
|
|
|
glReadBuffer(buffer);
|
|
|
|
|
checkGLcall("glReadBuffer");
|
|
|
|
|
|
|
|
|
|
IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
|
|
|
|
|
srcIsUpsideDown = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: Get rid of the extra rectangle comparison and construction of a full surface rectangle */
|
|
|
|
|
if(!rect) {
|
|
|
|
|
local_rect.left = 0;
|
|
|
|
|
local_rect.top = 0;
|
|
|
|
|
local_rect.right = This->currentDesc.Width;
|
|
|
|
|
local_rect.bottom = This->currentDesc.Height;
|
|
|
|
|
} else {
|
|
|
|
|
local_rect = *rect;
|
|
|
|
|
}
|
|
|
|
|
/* TODO: Get rid of the extra GetPitch call, LockRect does that too. Cache the pitch */
|
2006-07-17 10:39:44 +00:00
|
|
|
|
|
|
|
|
|
switch(This->resource.format)
|
|
|
|
|
{
|
|
|
|
|
case WINED3DFMT_P8:
|
|
|
|
|
{
|
2007-10-11 20:04:48 +00:00
|
|
|
|
if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
|
|
|
|
/* In case of P8 render targets the index is stored in the alpha component */
|
|
|
|
|
fmt = GL_ALPHA;
|
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
mem = dest;
|
|
|
|
|
bpp = This->bytesPerPixel;
|
|
|
|
|
} else {
|
|
|
|
|
/* GL can't return palettized data, so read ARGB pixels into a
|
|
|
|
|
* separate block of memory and convert them into palettized format
|
|
|
|
|
* in software. Slow, but if the app means to use palettized render
|
|
|
|
|
* targets and locks it...
|
|
|
|
|
*
|
|
|
|
|
* Use GL_RGB, GL_UNSIGNED_BYTE to read the surface for performance reasons
|
|
|
|
|
* Don't use GL_BGR as in the WINED3DFMT_R8G8B8 case, instead watch out
|
|
|
|
|
* for the color channels when palettizing the colors.
|
|
|
|
|
*/
|
|
|
|
|
fmt = GL_RGB;
|
|
|
|
|
type = GL_UNSIGNED_BYTE;
|
|
|
|
|
pitch *= 3;
|
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, This->resource.size * 3);
|
|
|
|
|
if(!mem) {
|
|
|
|
|
ERR("Out of memory\n");
|
2007-11-02 21:23:22 +00:00
|
|
|
|
LEAVE_GL();
|
2007-10-11 20:04:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bpp = This->bytesPerPixel * 3;
|
2006-07-17 10:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
mem = dest;
|
|
|
|
|
fmt = This->glDescription.glFormat;
|
|
|
|
|
type = This->glDescription.glType;
|
2007-02-13 19:24:00 +00:00
|
|
|
|
bpp = This->bytesPerPixel;
|
2006-07-17 10:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 21:23:22 +00:00
|
|
|
|
glReadPixels(local_rect.left, local_rect.top,
|
|
|
|
|
local_rect.right - local_rect.left,
|
|
|
|
|
local_rect.bottom - local_rect.top,
|
2007-02-13 19:24:00 +00:00
|
|
|
|
fmt, type, mem);
|
|
|
|
|
vcheckGLcall("glReadPixels");
|
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
|
|
/* Check if we need to flip the image. If we need to flip use glMapBufferARB
|
|
|
|
|
* to get a pointer to it and perform the flipping in software. This is a lot
|
|
|
|
|
* faster than calling glReadPixels for each line. In case we want more speed
|
|
|
|
|
* we should rerender it flipped in a FBO and read the data back from the FBO. */
|
2007-11-02 21:23:22 +00:00
|
|
|
|
if(!srcIsUpsideDown) {
|
2007-09-11 08:31:54 +00:00
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
2007-02-13 19:24:00 +00:00
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
mem = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_READ_WRITE_ARB));
|
|
|
|
|
checkGLcall("glMapBufferARB");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TODO: Merge this with the palettization loop below for P8 targets */
|
2007-11-02 21:23:22 +00:00
|
|
|
|
if(!srcIsUpsideDown) {
|
2007-02-13 19:24:00 +00:00
|
|
|
|
UINT len, off;
|
|
|
|
|
/* glReadPixels returns the image upside down, and there is no way to prevent this.
|
|
|
|
|
Flip the lines in software */
|
2007-11-02 21:23:22 +00:00
|
|
|
|
len = (local_rect.right - local_rect.left) * bpp;
|
|
|
|
|
off = local_rect.left * bpp;
|
2007-02-13 19:24:00 +00:00
|
|
|
|
|
|
|
|
|
row = HeapAlloc(GetProcessHeap(), 0, len);
|
2006-07-17 10:39:44 +00:00
|
|
|
|
if(!row) {
|
|
|
|
|
ERR("Out of memory\n");
|
2007-02-13 19:24:00 +00:00
|
|
|
|
if(This->resource.format == WINED3DFMT_P8) HeapFree(GetProcessHeap(), 0, mem);
|
2007-11-02 21:23:22 +00:00
|
|
|
|
LEAVE_GL();
|
2006-07-17 10:39:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2007-02-13 19:24:00 +00:00
|
|
|
|
|
2007-11-02 21:23:22 +00:00
|
|
|
|
top = mem + pitch * local_rect.top;
|
2008-01-23 21:40:02 +00:00
|
|
|
|
bottom = mem + pitch * ( local_rect.bottom - local_rect.top - 1);
|
2007-11-02 21:23:22 +00:00
|
|
|
|
for(i = 0; i < (local_rect.bottom - local_rect.top) / 2; i++) {
|
2007-02-13 19:24:00 +00:00
|
|
|
|
memcpy(row, top + off, len);
|
|
|
|
|
memcpy(top + off, bottom + off, len);
|
|
|
|
|
memcpy(bottom + off, row, len);
|
2006-07-17 10:39:44 +00:00
|
|
|
|
top += pitch;
|
|
|
|
|
bottom -= pitch;
|
|
|
|
|
}
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, row);
|
2007-09-11 08:31:54 +00:00
|
|
|
|
|
|
|
|
|
/* Unmap the temp PBO buffer */
|
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
|
}
|
2006-07-17 10:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-11 20:04:48 +00:00
|
|
|
|
/* For P8 textures we need to perform an inverse palette lookup. This is done by searching for a palette
|
|
|
|
|
* index which matches the RGB value. Note this isn't guaranteed to work when there are multiple entries for
|
|
|
|
|
* the same color but we have no choice.
|
|
|
|
|
* In case of render targets, the index is stored in the alpha component so no conversion is needed.
|
|
|
|
|
*/
|
|
|
|
|
if((This->resource.format == WINED3DFMT_P8) && !(This->resource.usage & WINED3DUSAGE_RENDERTARGET)) {
|
2006-07-17 10:39:44 +00:00
|
|
|
|
PALETTEENTRY *pal;
|
|
|
|
|
DWORD width = pitch / 3;
|
|
|
|
|
int x, y, c;
|
|
|
|
|
if(This->palette) {
|
|
|
|
|
pal = This->palette->palents;
|
|
|
|
|
} else {
|
|
|
|
|
pal = This->resource.wineD3DDevice->palettes[This->resource.wineD3DDevice->currentPalette];
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-02 21:23:22 +00:00
|
|
|
|
for(y = local_rect.top; y < local_rect.bottom; y++) {
|
|
|
|
|
for(x = local_rect.left; x < local_rect.right; x++) {
|
2006-07-17 10:39:44 +00:00
|
|
|
|
/* start lines pixels */
|
2008-01-23 21:40:02 +00:00
|
|
|
|
BYTE *blue = mem + y * pitch + x * (sizeof(BYTE) * 3);
|
2006-07-17 10:39:44 +00:00
|
|
|
|
BYTE *green = blue + 1;
|
|
|
|
|
BYTE *red = green + 1;
|
|
|
|
|
|
|
|
|
|
for(c = 0; c < 256; c++) {
|
|
|
|
|
if(*red == pal[c].peRed &&
|
|
|
|
|
*green == pal[c].peGreen &&
|
|
|
|
|
*blue == pal[c].peBlue)
|
|
|
|
|
{
|
|
|
|
|
*((BYTE *) dest + y * width + x) = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
|
}
|
2007-11-02 21:23:22 +00:00
|
|
|
|
LEAVE_GL();
|
2006-07-17 10:39:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-10 21:20:15 +00:00
|
|
|
|
/* Read the framebuffer contents into a texture */
|
|
|
|
|
static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This)
|
|
|
|
|
{
|
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
IWineD3DSwapChainImpl *swapchain;
|
|
|
|
|
int bpp;
|
|
|
|
|
GLenum format, internal, type;
|
|
|
|
|
CONVERT_TYPES convert;
|
|
|
|
|
BOOL srcIsUpsideDown;
|
|
|
|
|
GLint prevRead;
|
|
|
|
|
|
|
|
|
|
d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */, &format, &internal, &type, &convert, &bpp, This->srgb);
|
|
|
|
|
|
|
|
|
|
IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain);
|
|
|
|
|
/* Activate the surface. Set it up for blitting now, although not necessarily needed for LockRect.
|
|
|
|
|
* Certain graphics drivers seem to dislike some enabled states when reading from opengl, the blitting usage
|
|
|
|
|
* should help here. Furthermore unlockrect will need the context set up for blitting. The context manager will find
|
|
|
|
|
* context->last_was_blit set on the unlock.
|
|
|
|
|
*/
|
|
|
|
|
ActivateContext(device, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
|
|
|
|
|
surface_bind_and_dirtify(This);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
|
|
glGetIntegerv(GL_READ_BUFFER, &prevRead);
|
|
|
|
|
|
|
|
|
|
/* Select the correct read buffer, and give some debug output.
|
|
|
|
|
* There is no need to keep track of the current read buffer or reset it, every part of the code
|
|
|
|
|
* that reads sets the read buffer as desired.
|
|
|
|
|
*/
|
|
|
|
|
if(!swapchain) {
|
|
|
|
|
/* Locking the primary render target which is not on a swapchain(=offscreen render target).
|
|
|
|
|
* Read from the back buffer
|
|
|
|
|
*/
|
|
|
|
|
TRACE("Locking offscreen render target\n");
|
|
|
|
|
glReadBuffer(device->offscreenBuffer);
|
|
|
|
|
srcIsUpsideDown = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
|
|
|
|
|
TRACE("Locking %#x buffer\n", buffer);
|
|
|
|
|
glReadBuffer(buffer);
|
|
|
|
|
checkGLcall("glReadBuffer");
|
|
|
|
|
|
|
|
|
|
IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
|
|
|
|
|
srcIsUpsideDown = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!(This->Flags & SFLAG_ALLOCATED)) {
|
|
|
|
|
surface_allocate_surface(This, internal, This->pow2Width,
|
|
|
|
|
This->pow2Height, format, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear_unused_channels(This);
|
|
|
|
|
|
|
|
|
|
/* If !SrcIsUpsideDown we should flip the surface.
|
|
|
|
|
* This can be done using glCopyTexSubImage2D but this
|
|
|
|
|
* is VERY slow, so don't do that. We should prevent
|
|
|
|
|
* this code from getting called in such cases or perhaps
|
|
|
|
|
* we can use FBOs */
|
|
|
|
|
|
|
|
|
|
glCopyTexSubImage2D(This->glDescription.target,
|
|
|
|
|
This->glDescription.level,
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
This->currentDesc.Width,
|
|
|
|
|
This->currentDesc.Height);
|
|
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
|
|
|
|
|
glReadBuffer(prevRead);
|
|
|
|
|
vcheckGLcall("glReadBuffer");
|
|
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
TRACE("Updated target %d\n", This->glDescription.target);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-01 00:31:01 +00:00
|
|
|
|
static void surface_prepare_system_memory(IWineD3DSurfaceImpl *This) {
|
|
|
|
|
/* Performance optimization: Count how often a surface is locked, if it is locked regularly do not throw away the system memory copy.
|
|
|
|
|
* This avoids the need to download the surface from opengl all the time. The surface is still downloaded if the opengl texture is
|
|
|
|
|
* changed
|
2007-09-14 15:46:19 +00:00
|
|
|
|
*/
|
2007-11-01 00:31:01 +00:00
|
|
|
|
if(!(This->Flags & SFLAG_DYNLOCK)) {
|
|
|
|
|
This->lockCount++;
|
|
|
|
|
/* MAXLOCKCOUNT is defined in wined3d_private.h */
|
|
|
|
|
if(This->lockCount > MAXLOCKCOUNT) {
|
|
|
|
|
TRACE("Surface is locked regularly, not freeing the system memory copy any more\n");
|
|
|
|
|
This->Flags |= SFLAG_DYNLOCK;
|
2007-10-09 20:17:59 +00:00
|
|
|
|
}
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-27 16:57:51 +00:00
|
|
|
|
/* Create a PBO for dynamically locked surfaces but don't do it for converted or non-pow2 surfaces.
|
2007-11-01 00:31:01 +00:00
|
|
|
|
* Also don't create a PBO for systemmem surfaces.
|
|
|
|
|
*/
|
2007-09-15 19:51:27 +00:00
|
|
|
|
if(GL_SUPPORT(ARB_PIXEL_BUFFER_OBJECT) && (This->Flags & SFLAG_DYNLOCK) && !(This->Flags & (SFLAG_PBO | SFLAG_CONVERTED | SFLAG_NONPOW2)) && (This->resource.pool != WINED3DPOOL_SYSTEMMEM)) {
|
2007-09-11 08:31:54 +00:00
|
|
|
|
GLenum error;
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glGenBuffersARB(1, &This->pbo));
|
|
|
|
|
error = glGetError();
|
|
|
|
|
if(This->pbo == 0 || error != GL_NO_ERROR) {
|
|
|
|
|
ERR("Failed to bind the PBO with error %s (%#x)\n", debug_glerror(error), error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRACE("Attaching pbo=%#x to (%p)\n", This->pbo, This);
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->resource.size + 4, This->resource.allocatedMemory, GL_STREAM_DRAW_ARB));
|
|
|
|
|
checkGLcall("glBufferDataARB");
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
|
|
/* We don't need the system memory anymore and we can't even use it for PBOs */
|
2007-11-03 15:24:55 +00:00
|
|
|
|
if(!(This->Flags & SFLAG_CLIENT)) {
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
|
|
|
|
|
This->resource.heapMemory = NULL;
|
|
|
|
|
}
|
2007-09-11 08:31:54 +00:00
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
|
This->Flags |= SFLAG_PBO;
|
|
|
|
|
LEAVE_GL();
|
2007-11-01 00:31:01 +00:00
|
|
|
|
} else if(!(This->resource.allocatedMemory || This->Flags & SFLAG_PBO)) {
|
|
|
|
|
/* Whatever surface we have, make sure that there is memory allocated for the downloaded copy,
|
|
|
|
|
* or a pbo to map
|
|
|
|
|
*/
|
2007-11-03 15:24:55 +00:00
|
|
|
|
if(!This->resource.heapMemory) {
|
|
|
|
|
This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
|
|
|
|
|
}
|
2007-10-22 11:30:14 +00:00
|
|
|
|
This->resource.allocatedMemory =
|
|
|
|
|
(BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
|
2007-11-01 00:31:01 +00:00
|
|
|
|
if(This->Flags & SFLAG_INSYSMEM) {
|
|
|
|
|
ERR("Surface without memory or pbo has SFLAG_INSYSMEM set!\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
|
|
|
|
IWineD3DSwapChain *swapchain = NULL;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p) : rect@%p flags(%08x), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->resource.allocatedMemory);
|
|
|
|
|
|
2007-10-09 20:19:39 +00:00
|
|
|
|
/* This is also done in the base class, but we have to verify this before loading any data from
|
|
|
|
|
* gl into the sysmem copy. The PBO may be mapped, a different rectangle locked, the discard flag
|
|
|
|
|
* may interfere, and all other bad things may happen
|
|
|
|
|
*/
|
2007-11-01 00:31:01 +00:00
|
|
|
|
if (This->Flags & SFLAG_LOCKED) {
|
|
|
|
|
WARN("Surface is already locked, returning D3DERR_INVALIDCALL\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
2007-11-08 21:44:34 +00:00
|
|
|
|
This->Flags |= SFLAG_LOCKED;
|
|
|
|
|
|
|
|
|
|
if (!(This->Flags & SFLAG_LOCKABLE))
|
|
|
|
|
{
|
|
|
|
|
TRACE("Warning: trying to lock unlockable surf@%p\n", This);
|
|
|
|
|
}
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
2007-08-01 20:48:42 +00:00
|
|
|
|
if (Flags & WINED3DLOCK_DISCARD) {
|
|
|
|
|
/* Set SFLAG_INSYSMEM, so we'll never try to download the data from the texture. */
|
|
|
|
|
TRACE("WINED3DLOCK_DISCARD flag passed, marking local copy as up to date\n");
|
|
|
|
|
This->Flags |= SFLAG_INSYSMEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (This->Flags & SFLAG_INSYSMEM) {
|
|
|
|
|
TRACE("Local copy is up to date, not downloading data\n");
|
2007-11-01 00:31:01 +00:00
|
|
|
|
surface_prepare_system_memory(This); /* Makes sure memory is allocated */
|
2007-02-13 19:21:44 +00:00
|
|
|
|
goto lock_end;
|
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
/* Now download the surface content from opengl
|
|
|
|
|
* Use the render target readback if the surface is on a swapchain(=onscreen render target) or the current primary target
|
|
|
|
|
* Offscreen targets which are not active at the moment or are higher targets(fbos) can be locked with the texture path
|
|
|
|
|
*/
|
|
|
|
|
IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain);
|
|
|
|
|
if(swapchain || iface == myDevice->render_targets[0]) {
|
2007-10-09 20:19:39 +00:00
|
|
|
|
const RECT *pass_rect = pRect;
|
2007-02-13 19:24:00 +00:00
|
|
|
|
|
2007-10-09 20:19:39 +00:00
|
|
|
|
/* IWineD3DSurface_LoadLocation does not check if the rectangle specifies the full surfaces
|
|
|
|
|
* because most caller functions do not need that. So do that here
|
|
|
|
|
*/
|
|
|
|
|
if(pRect &&
|
|
|
|
|
pRect->top == 0 &&
|
|
|
|
|
pRect->left == 0 &&
|
|
|
|
|
pRect->right == This->currentDesc.Width &&
|
|
|
|
|
pRect->bottom == This->currentDesc.Height) {
|
|
|
|
|
pass_rect = NULL;
|
2005-07-13 11:34:55 +00:00
|
|
|
|
}
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
switch(wined3d_settings.rendertargetlock_mode) {
|
2007-09-24 22:21:34 +00:00
|
|
|
|
case RTL_TEXDRAW:
|
|
|
|
|
case RTL_TEXTEX:
|
|
|
|
|
FIXME("Reading from render target with a texture isn't implemented yet, falling back to framebuffer reading\n");
|
|
|
|
|
#if 0
|
|
|
|
|
/* Disabled for now. LoadLocation prefers the texture over the drawable as the source. So if we copy to the
|
|
|
|
|
* texture first, then to sysmem, we'll avoid glReadPixels and use glCopyTexImage and glGetTexImage2D instead.
|
|
|
|
|
* This may be faster on some cards
|
|
|
|
|
*/
|
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL /* No partial texture copy yet */);
|
|
|
|
|
#endif
|
|
|
|
|
/* drop through */
|
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
case RTL_AUTO:
|
|
|
|
|
case RTL_READDRAW:
|
|
|
|
|
case RTL_READTEX:
|
2007-10-09 20:19:39 +00:00
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, pRect);
|
2007-02-13 19:21:44 +00:00
|
|
|
|
break;
|
2006-06-15 10:54:19 +00:00
|
|
|
|
|
2007-09-24 22:21:34 +00:00
|
|
|
|
case RTL_DISABLE:
|
2007-02-13 19:21:44 +00:00
|
|
|
|
break;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
2007-09-24 22:21:34 +00:00
|
|
|
|
if(swapchain) IWineD3DSwapChain_Release(swapchain);
|
2007-09-11 08:31:54 +00:00
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
} else if(iface == myDevice->stencilBufferTarget) {
|
|
|
|
|
/** the depth stencil in openGL has a format of GL_FLOAT
|
|
|
|
|
* which should be good for WINED3DFMT_D16_LOCKABLE
|
|
|
|
|
* and WINED3DFMT_D16
|
|
|
|
|
* it is unclear what format the stencil buffer is in except.
|
|
|
|
|
* 'Each index is converted to fixed point...
|
|
|
|
|
* If GL_MAP_STENCIL is GL_TRUE, indices are replaced by their
|
|
|
|
|
* mappings in the table GL_PIXEL_MAP_S_TO_S.
|
|
|
|
|
* glReadPixels(This->lockedRect.left,
|
|
|
|
|
* This->lockedRect.bottom - j - 1,
|
|
|
|
|
* This->lockedRect.right - This->lockedRect.left,
|
|
|
|
|
* 1,
|
|
|
|
|
* GL_DEPTH_COMPONENT,
|
|
|
|
|
* type,
|
|
|
|
|
* (char *)pLockedRect->pBits + (pLockedRect->Pitch * (j-This->lockedRect.top)));
|
|
|
|
|
*
|
|
|
|
|
* Depth Stencil surfaces which are not the current depth stencil target should have their data in a
|
2007-03-06 20:47:45 +00:00
|
|
|
|
* gl texture(next path), or in local memory(early return because of set SFLAG_INSYSMEM above). If
|
2007-02-13 19:21:44 +00:00
|
|
|
|
* none of that is the case the problem is not in this function :-)
|
|
|
|
|
********************************************/
|
|
|
|
|
FIXME("Depth stencil locking not supported yet\n");
|
|
|
|
|
} else {
|
|
|
|
|
/* This path is for normal surfaces, offscreen render targets and everything else that is in a gl texture */
|
2007-06-05 22:21:08 +00:00
|
|
|
|
TRACE("locking an ordinary surface\n");
|
2007-09-24 22:16:05 +00:00
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
lock_end:
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
ActivateContext(myDevice, myDevice->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
|
|
/* This shouldn't happen but could occur if some other function didn't handle the PBO properly */
|
|
|
|
|
if(This->resource.allocatedMemory) {
|
|
|
|
|
ERR("The surface already has PBO memory allocated!\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
This->resource.allocatedMemory = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_READ_WRITE_ARB));
|
|
|
|
|
checkGLcall("glMapBufferARB");
|
|
|
|
|
|
|
|
|
|
/* Make sure the pbo isn't set anymore in order not to break non-pbo calls */
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-07 23:11:28 +00:00
|
|
|
|
if (Flags & (WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY)) {
|
2005-01-09 17:37:02 +00:00
|
|
|
|
/* Don't dirtify */
|
|
|
|
|
} else {
|
2005-03-14 10:12:52 +00:00
|
|
|
|
IWineD3DBaseTexture *pBaseTexture;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Dirtify on lock
|
|
|
|
|
* as seen in msdn docs
|
|
|
|
|
*/
|
2007-11-03 13:28:06 +00:00
|
|
|
|
IWineD3DSurface_AddDirtyRect(iface, pRect);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
2005-07-07 20:35:05 +00:00
|
|
|
|
/** Dirtify Container if needed */
|
2006-04-07 10:51:12 +00:00
|
|
|
|
if (WINED3D_OK == IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&pBaseTexture) && pBaseTexture != NULL) {
|
2005-03-14 10:12:52 +00:00
|
|
|
|
TRACE("Making container dirty\n");
|
2005-07-07 20:35:05 +00:00
|
|
|
|
IWineD3DBaseTexture_SetDirty(pBaseTexture, TRUE);
|
2005-03-14 10:12:52 +00:00
|
|
|
|
IWineD3DBaseTexture_Release(pBaseTexture);
|
2005-07-13 14:15:54 +00:00
|
|
|
|
} else {
|
2005-03-14 10:12:52 +00:00
|
|
|
|
TRACE("Surface is standalone, no need to dirty the container\n");
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-09 20:19:39 +00:00
|
|
|
|
return IWineD3DBaseSurfaceImpl_LockRect(iface, pLockedRect, pRect, Flags);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-07 20:18:34 +00:00
|
|
|
|
static void flush_to_framebuffer_drawpixels(IWineD3DSurfaceImpl *This, GLenum fmt, GLenum type, UINT bpp, const BYTE *mem) {
|
2006-07-17 15:27:19 +00:00
|
|
|
|
GLint prev_store;
|
|
|
|
|
GLint prev_rasterpos[4];
|
2005-01-09 17:37:02 +00:00
|
|
|
|
GLint skipBytes = 0;
|
2007-02-13 19:24:00 +00:00
|
|
|
|
UINT pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This); /* target is argb, 4 byte */
|
2008-01-23 21:40:02 +00:00
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
2007-11-02 20:08:20 +00:00
|
|
|
|
IWineD3DSwapChainImpl *swapchain;
|
|
|
|
|
|
|
|
|
|
/* Activate the correct context for the render target */
|
|
|
|
|
ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
|
|
|
|
IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain);
|
|
|
|
|
if(!swapchain) {
|
|
|
|
|
/* Primary offscreen render target */
|
|
|
|
|
TRACE("Offscreen render target\n");
|
|
|
|
|
glDrawBuffer(myDevice->offscreenBuffer);
|
|
|
|
|
checkGLcall("glDrawBuffer(myDevice->offscreenBuffer)");
|
|
|
|
|
} else {
|
|
|
|
|
GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
|
|
|
|
|
TRACE("Unlocking %#x buffer\n", buffer);
|
|
|
|
|
glDrawBuffer(buffer);
|
|
|
|
|
checkGLcall("glDrawBuffer");
|
|
|
|
|
|
|
|
|
|
IWineD3DSwapChain_Release((IWineD3DSwapChain *)swapchain);
|
|
|
|
|
}
|
2006-07-17 15:27:19 +00:00
|
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
|
vcheckGLcall("glFlush");
|
|
|
|
|
glGetIntegerv(GL_PACK_SWAP_BYTES, &prev_store);
|
|
|
|
|
vcheckGLcall("glIntegerv");
|
|
|
|
|
glGetIntegerv(GL_CURRENT_RASTER_POSITION, &prev_rasterpos[0]);
|
|
|
|
|
vcheckGLcall("glIntegerv");
|
|
|
|
|
glPixelZoom(1.0, -1.0);
|
|
|
|
|
vcheckGLcall("glPixelZoom");
|
|
|
|
|
|
|
|
|
|
/* If not fullscreen, we need to skip a number of bytes to find the next row of data */
|
|
|
|
|
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &skipBytes);
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, This->currentDesc.Width);
|
|
|
|
|
|
|
|
|
|
glRasterPos3i(This->lockedRect.left, This->lockedRect.top, 1);
|
|
|
|
|
vcheckGLcall("glRasterPos2f");
|
|
|
|
|
|
|
|
|
|
/* Some drivers(radeon dri, others?) don't like exceptions during
|
|
|
|
|
* glDrawPixels. If the surface is a DIB section, it might be in GDIMode
|
|
|
|
|
* after ReleaseDC. Reading it will cause an exception, which x11drv will
|
|
|
|
|
* catch to put the dib section in InSync mode, which leads to a crash
|
|
|
|
|
* and a blocked x server on my radeon card.
|
|
|
|
|
*
|
|
|
|
|
* The following lines read the dib section so it is put in inSync mode
|
|
|
|
|
* before glDrawPixels is called and the crash is prevented. There won't
|
|
|
|
|
* be any interfering gdi accesses, because UnlockRect is called from
|
|
|
|
|
* ReleaseDC, and the app won't use the dc any more afterwards.
|
|
|
|
|
*/
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if((This->Flags & SFLAG_DIBSECTION) && !(This->Flags & SFLAG_PBO)) {
|
2006-07-17 15:27:19 +00:00
|
|
|
|
volatile BYTE read;
|
|
|
|
|
read = This->resource.allocatedMemory[0];
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-17 15:27:19 +00:00
|
|
|
|
glDrawPixels(This->lockedRect.right - This->lockedRect.left,
|
|
|
|
|
(This->lockedRect.bottom - This->lockedRect.top)-1,
|
|
|
|
|
fmt, type,
|
2007-02-13 19:24:00 +00:00
|
|
|
|
mem + bpp * This->lockedRect.left + pitch * This->lockedRect.top);
|
2006-07-17 15:27:19 +00:00
|
|
|
|
checkGLcall("glDrawPixels");
|
2007-09-11 08:31:54 +00:00
|
|
|
|
|
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glBindBufferARB");
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-17 15:27:19 +00:00
|
|
|
|
glPixelZoom(1.0,1.0);
|
|
|
|
|
vcheckGLcall("glPixelZoom");
|
|
|
|
|
|
|
|
|
|
glRasterPos3iv(&prev_rasterpos[0]);
|
|
|
|
|
vcheckGLcall("glRasterPos3iv");
|
|
|
|
|
|
|
|
|
|
/* Reset to previous pack row length */
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, skipBytes);
|
|
|
|
|
vcheckGLcall("glPixelStorei GL_UNPACK_ROW_LENGTH");
|
|
|
|
|
|
2007-11-02 20:08:20 +00:00
|
|
|
|
if(!swapchain) {
|
|
|
|
|
glDrawBuffer(myDevice->offscreenBuffer);
|
|
|
|
|
checkGLcall("glDrawBuffer(myDevice->offscreenBuffer)");
|
|
|
|
|
} else if(swapchain->backBuffer) {
|
|
|
|
|
glDrawBuffer(GL_BACK);
|
|
|
|
|
checkGLcall("glDrawBuffer(GL_BACK)");
|
|
|
|
|
} else {
|
|
|
|
|
glDrawBuffer(GL_FRONT);
|
|
|
|
|
checkGLcall("glDrawBuffer(GL_FRONT)");
|
|
|
|
|
}
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
2006-07-17 15:27:19 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_UnlockRect(IWineD3DSurface *iface) {
|
2005-01-09 17:37:02 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2005-07-07 20:35:05 +00:00
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
|
|
|
|
IWineD3DSwapChainImpl *swapchain = NULL;
|
2007-09-21 17:55:06 +00:00
|
|
|
|
BOOL fullsurface;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
2006-05-06 14:15:37 +00:00
|
|
|
|
if (!(This->Flags & SFLAG_LOCKED)) {
|
2005-07-07 20:35:05 +00:00
|
|
|
|
WARN("trying to Unlock an unlocked surf@%p\n", This);
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if (This->Flags & SFLAG_PBO) {
|
|
|
|
|
TRACE("Freeing PBO memory\n");
|
|
|
|
|
ActivateContext(myDevice, myDevice->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
|
|
|
|
|
GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
|
|
|
|
|
GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
|
|
|
|
|
checkGLcall("glUnmapBufferARB");
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 20:47:45 +00:00
|
|
|
|
TRACE("(%p) : dirtyfied(%d)\n", This, This->Flags & (SFLAG_INDRAWABLE | SFLAG_INTEXTURE) ? 0 : 1);
|
2005-07-07 20:35:05 +00:00
|
|
|
|
|
2007-03-06 20:47:45 +00:00
|
|
|
|
if (This->Flags & (SFLAG_INDRAWABLE | SFLAG_INTEXTURE)) {
|
2005-01-09 17:37:02 +00:00
|
|
|
|
TRACE("(%p) : Not Dirtified so nothing to do, return now\n", This);
|
|
|
|
|
goto unlock_end;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain);
|
2007-08-21 14:52:01 +00:00
|
|
|
|
if(swapchain || (myDevice->render_targets && iface == myDevice->render_targets[0])) {
|
2008-01-21 04:18:12 +00:00
|
|
|
|
if(swapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
|
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
if(wined3d_settings.rendertargetlock_mode == RTL_DISABLE) {
|
|
|
|
|
static BOOL warned = FALSE;
|
|
|
|
|
if(!warned) {
|
|
|
|
|
ERR("The application tries to write to the render target, but render target locking is disabled\n");
|
|
|
|
|
warned = TRUE;
|
2006-12-19 22:26:39 +00:00
|
|
|
|
}
|
2007-02-13 19:21:44 +00:00
|
|
|
|
goto unlock_end;
|
2006-12-19 22:26:39 +00:00
|
|
|
|
}
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
2007-09-21 17:55:06 +00:00
|
|
|
|
if(This->dirtyRect.left == 0 &&
|
|
|
|
|
This->dirtyRect.top == 0 &&
|
|
|
|
|
This->dirtyRect.right == This->currentDesc.Width &&
|
|
|
|
|
This->dirtyRect.bottom == This->currentDesc.Height) {
|
|
|
|
|
fullsurface = TRUE;
|
2007-02-13 19:21:44 +00:00
|
|
|
|
} else {
|
2007-09-21 17:55:06 +00:00
|
|
|
|
/* TODO: Proper partial rectangle tracking */
|
|
|
|
|
fullsurface = FALSE;
|
|
|
|
|
This->Flags |= SFLAG_INSYSMEM;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
switch(wined3d_settings.rendertargetlock_mode) {
|
2007-09-21 17:55:06 +00:00
|
|
|
|
case RTL_READTEX:
|
|
|
|
|
case RTL_TEXTEX:
|
2007-11-04 16:25:44 +00:00
|
|
|
|
ActivateContext(myDevice, iface, CTXUSAGE_BLIT);
|
2007-11-01 00:40:44 +00:00
|
|
|
|
ENTER_GL();
|
|
|
|
|
if (This->glDescription.textureName == 0) {
|
|
|
|
|
glGenTextures(1, &This->glDescription.textureName);
|
|
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
|
}
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glBindTexture(This->glDescription.target, This->glDescription.textureName);
|
|
|
|
|
checkGLcall("glBindTexture(This->glDescription.target, This->glDescription.textureName)");
|
2007-11-01 00:40:44 +00:00
|
|
|
|
LEAVE_GL();
|
2007-09-21 17:55:06 +00:00
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL /* partial texture loading not supported yet */);
|
2007-11-01 00:38:50 +00:00
|
|
|
|
/* drop through */
|
|
|
|
|
|
2007-02-13 19:21:44 +00:00
|
|
|
|
case RTL_AUTO:
|
|
|
|
|
case RTL_READDRAW:
|
|
|
|
|
case RTL_TEXDRAW:
|
2007-09-21 17:55:06 +00:00
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INDRAWABLE, fullsurface ? NULL : &This->dirtyRect);
|
2007-02-13 19:21:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-09-21 17:55:06 +00:00
|
|
|
|
|
|
|
|
|
if(!fullsurface) {
|
|
|
|
|
/* Partial rectangle tracking is not commonly implemented, it is only done for render targets. Overwrite
|
|
|
|
|
* the flags to bring them back into a sane state. INSYSMEM was set before to tell LoadLocation where
|
|
|
|
|
* to read the rectangle from. Indrawable is set because all modifications from the partial sysmem copy
|
|
|
|
|
* are written back to the drawable, thus the surface is merged again in the drawable. The sysmem copy is
|
|
|
|
|
* not fully up to date because only a subrectangle was read in LockRect.
|
|
|
|
|
*/
|
|
|
|
|
This->Flags &= ~SFLAG_INSYSMEM;
|
|
|
|
|
This->Flags |= SFLAG_INDRAWABLE;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-06 20:47:45 +00:00
|
|
|
|
This->dirtyRect.left = This->currentDesc.Width;
|
|
|
|
|
This->dirtyRect.top = This->currentDesc.Height;
|
|
|
|
|
This->dirtyRect.right = 0;
|
|
|
|
|
This->dirtyRect.bottom = 0;
|
2007-02-13 19:21:44 +00:00
|
|
|
|
} else if(iface == myDevice->stencilBufferTarget) {
|
|
|
|
|
FIXME("Depth Stencil buffer locking is not implemented\n");
|
2005-01-09 17:37:02 +00:00
|
|
|
|
} else {
|
2007-02-13 19:21:44 +00:00
|
|
|
|
/* The rest should be a normal texture */
|
|
|
|
|
IWineD3DBaseTextureImpl *impl;
|
|
|
|
|
/* Check if the texture is bound, if yes dirtify the sampler to force a re-upload of the texture
|
|
|
|
|
* Can't load the texture here because PreLoad may destroy and recreate the gl texture, so sampler
|
|
|
|
|
* states need resetting
|
|
|
|
|
*/
|
|
|
|
|
if(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&impl) == WINED3D_OK) {
|
|
|
|
|
if(impl->baseTexture.bindCount) {
|
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(myDevice, STATE_SAMPLER(impl->baseTexture.sampler));
|
|
|
|
|
}
|
|
|
|
|
IWineD3DBaseTexture_Release((IWineD3DBaseTexture *) impl);
|
|
|
|
|
}
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unlock_end:
|
2006-05-06 14:15:37 +00:00
|
|
|
|
This->Flags &= ~SFLAG_LOCKED;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
memset(&This->lockedRect, 0, sizeof(RECT));
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2006-05-06 16:08:33 +00:00
|
|
|
|
WINED3DLOCKED_RECT lock;
|
|
|
|
|
HRESULT hr;
|
2006-05-09 19:04:07 +00:00
|
|
|
|
RGBQUAD col[256];
|
2006-05-06 16:08:33 +00:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n",This,pHDC);
|
|
|
|
|
|
2006-07-25 14:38:02 +00:00
|
|
|
|
if(This->Flags & SFLAG_USERPTR) {
|
|
|
|
|
ERR("Not supported on surfaces with an application-provided surfaces\n");
|
2007-04-14 20:44:55 +00:00
|
|
|
|
return WINEDDERR_NODC;
|
2006-07-25 14:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-05-06 16:08:33 +00:00
|
|
|
|
/* Give more detailed info for ddraw */
|
|
|
|
|
if (This->Flags & SFLAG_DCINUSE)
|
2007-04-14 20:44:55 +00:00
|
|
|
|
return WINEDDERR_DCALREADYCREATED;
|
2006-05-06 16:08:33 +00:00
|
|
|
|
|
|
|
|
|
/* Can't GetDC if the surface is locked */
|
|
|
|
|
if (This->Flags & SFLAG_LOCKED)
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
|
|
memset(&lock, 0, sizeof(lock)); /* To be sure */
|
|
|
|
|
|
|
|
|
|
/* Create a DIB section if there isn't a hdc yet */
|
2006-05-09 19:04:07 +00:00
|
|
|
|
if(!This->hDC) {
|
2007-09-17 11:48:11 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
|
|
|
|
|
if(This->Flags & SFLAG_CLIENT) {
|
|
|
|
|
IWineD3DSurface_PreLoad(iface);
|
2006-05-06 16:08:33 +00:00
|
|
|
|
}
|
2006-08-16 20:35:58 +00:00
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
/* Use the dib section from now on if we are not using a PBO */
|
|
|
|
|
if(!(This->Flags & SFLAG_PBO))
|
|
|
|
|
This->resource.allocatedMemory = This->dib.bitmap_data;
|
2006-05-06 16:08:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Lock the surface */
|
|
|
|
|
hr = IWineD3DSurface_LockRect(iface,
|
|
|
|
|
&lock,
|
|
|
|
|
NULL,
|
|
|
|
|
0);
|
2007-09-11 08:31:54 +00:00
|
|
|
|
|
|
|
|
|
if(This->Flags & SFLAG_PBO) {
|
|
|
|
|
/* Sync the DIB with the PBO. This can't be done earlier because LockRect activates the allocatedMemory */
|
|
|
|
|
memcpy(This->dib.bitmap_data, This->resource.allocatedMemory, This->dib.bitmap_size);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-09 19:04:07 +00:00
|
|
|
|
if(FAILED(hr)) {
|
2006-10-01 03:20:10 +00:00
|
|
|
|
ERR("IWineD3DSurface_LockRect failed with hr = %08x\n", hr);
|
2006-05-06 16:08:33 +00:00
|
|
|
|
/* keep the dib section */
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-09 19:04:07 +00:00
|
|
|
|
if(This->resource.format == WINED3DFMT_P8 ||
|
|
|
|
|
This->resource.format == WINED3DFMT_A8P8) {
|
|
|
|
|
unsigned int n;
|
|
|
|
|
if(This->palette) {
|
|
|
|
|
PALETTEENTRY ent[256];
|
|
|
|
|
|
|
|
|
|
GetPaletteEntries(This->palette->hpal, 0, 256, ent);
|
|
|
|
|
for (n=0; n<256; n++) {
|
|
|
|
|
col[n].rgbRed = ent[n].peRed;
|
|
|
|
|
col[n].rgbGreen = ent[n].peGreen;
|
|
|
|
|
col[n].rgbBlue = ent[n].peBlue;
|
|
|
|
|
col[n].rgbReserved = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
|
|
|
|
|
for (n=0; n<256; n++) {
|
|
|
|
|
col[n].rgbRed = device->palettes[device->currentPalette][n].peRed;
|
|
|
|
|
col[n].rgbGreen = device->palettes[device->currentPalette][n].peGreen;
|
|
|
|
|
col[n].rgbBlue = device->palettes[device->currentPalette][n].peBlue;
|
|
|
|
|
col[n].rgbReserved = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
SetDIBColorTable(This->hDC, 0, 256, col);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-06 16:08:33 +00:00
|
|
|
|
*pHDC = This->hDC;
|
|
|
|
|
TRACE("returning %p\n",*pHDC);
|
|
|
|
|
This->Flags |= SFLAG_DCINUSE;
|
|
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2006-05-06 16:08:33 +00:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n",This,hDC);
|
|
|
|
|
|
|
|
|
|
if (!(This->Flags & SFLAG_DCINUSE))
|
2007-02-15 12:32:25 +00:00
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-05-06 16:08:33 +00:00
|
|
|
|
|
2007-08-14 12:40:33 +00:00
|
|
|
|
if (This->hDC !=hDC) {
|
|
|
|
|
WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC);
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-11 08:31:54 +00:00
|
|
|
|
if((This->Flags & SFLAG_PBO) && This->resource.allocatedMemory) {
|
|
|
|
|
/* Copy the contents of the DIB over to the PBO */
|
|
|
|
|
memcpy(This->resource.allocatedMemory, This->dib.bitmap_data, This->dib.bitmap_size);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-06 16:08:33 +00:00
|
|
|
|
/* we locked first, so unlock now */
|
|
|
|
|
IWineD3DSurface_UnlockRect(iface);
|
|
|
|
|
|
|
|
|
|
This->Flags &= ~SFLAG_DCINUSE;
|
|
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******************************************************
|
|
|
|
|
IWineD3DSurface Internal (No mapping to directx api) parts follow
|
|
|
|
|
****************************************************** */
|
2006-05-22 21:49:09 +00:00
|
|
|
|
|
2007-08-11 18:02:01 +00:00
|
|
|
|
HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode) {
|
2007-04-14 20:44:55 +00:00
|
|
|
|
BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & WINEDDSD_CKSRCBLT);
|
2007-07-23 09:13:37 +00:00
|
|
|
|
const GlPixelFormatDesc *glDesc;
|
2007-11-03 14:14:03 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
BOOL p8_render_target = FALSE;
|
2007-07-27 11:22:54 +00:00
|
|
|
|
getFormatDescEntry(This->resource.format, &GLINFO_LOCATION, &glDesc);
|
2006-05-22 21:49:09 +00:00
|
|
|
|
|
|
|
|
|
/* Default values: From the surface */
|
2007-07-23 09:13:37 +00:00
|
|
|
|
*format = glDesc->glFormat;
|
|
|
|
|
*type = glDesc->glType;
|
2006-05-22 21:49:09 +00:00
|
|
|
|
*convert = NO_CONVERSION;
|
|
|
|
|
*target_bpp = This->bytesPerPixel;
|
|
|
|
|
|
2007-11-23 13:17:21 +00:00
|
|
|
|
if(srgb_mode) {
|
|
|
|
|
*internal = glDesc->glGammaInternal;
|
|
|
|
|
} else if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
|
|
|
|
*internal = glDesc->rtInternal;
|
|
|
|
|
} else {
|
|
|
|
|
*internal = glDesc->glInternal;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-22 21:49:09 +00:00
|
|
|
|
/* Ok, now look if we have to do any conversion */
|
|
|
|
|
switch(This->resource.format) {
|
|
|
|
|
case WINED3DFMT_P8:
|
|
|
|
|
/* ****************
|
|
|
|
|
Paletted Texture
|
|
|
|
|
**************** */
|
2007-11-03 14:14:03 +00:00
|
|
|
|
|
|
|
|
|
if (device->render_targets && device->render_targets[0]) {
|
|
|
|
|
IWineD3DSurfaceImpl* render_target = (IWineD3DSurfaceImpl*)device->render_targets[0];
|
2007-11-05 19:20:34 +00:00
|
|
|
|
if((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET) && (render_target->resource.format == WINED3DFMT_P8))
|
2007-11-03 14:14:03 +00:00
|
|
|
|
p8_render_target = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-07 20:18:34 +00:00
|
|
|
|
/* Use conversion when the paletted texture extension OR fragment shaders are available. When either
|
2008-01-07 12:43:48 +00:00
|
|
|
|
* of the two is available make sure texturing is requested as neither of the two works in
|
|
|
|
|
* conjunction with calls like glDraw-/glReadPixels. Further also use conversion in case of color keying.
|
|
|
|
|
* Paletted textures can be emulated using shaders but only do that for 2D purposes e.g. situations
|
|
|
|
|
* in which the main render target uses p8. Some games like GTA Vice City use P8 for texturing which
|
|
|
|
|
* conflicts with this.
|
2006-08-03 10:39:04 +00:00
|
|
|
|
*/
|
2008-01-07 12:43:48 +00:00
|
|
|
|
if( !(GL_SUPPORT(EXT_PALETTED_TEXTURE) || (GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && p8_render_target)) || colorkey_active || !use_texturing ) {
|
2006-05-22 21:49:09 +00:00
|
|
|
|
*format = GL_RGBA;
|
|
|
|
|
*internal = GL_RGBA;
|
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
|
|
|
|
*target_bpp = 4;
|
|
|
|
|
if(colorkey_active) {
|
|
|
|
|
*convert = CONVERT_PALETTED_CK;
|
2006-07-25 14:41:41 +00:00
|
|
|
|
} else {
|
|
|
|
|
*convert = CONVERT_PALETTED;
|
2006-05-22 21:49:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-12-23 19:47:15 +00:00
|
|
|
|
else if(!GL_SUPPORT(EXT_PALETTED_TEXTURE) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
|
2008-02-08 00:24:24 +00:00
|
|
|
|
*format = GL_ALPHA;
|
2007-10-11 21:11:37 +00:00
|
|
|
|
*internal = GL_RGBA;
|
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
|
|
|
|
*target_bpp = 1;
|
|
|
|
|
}
|
2006-05-22 21:49:09 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WINED3DFMT_R3G3B2:
|
|
|
|
|
/* **********************
|
|
|
|
|
GL_UNSIGNED_BYTE_3_3_2
|
|
|
|
|
********************** */
|
|
|
|
|
if (colorkey_active) {
|
|
|
|
|
/* This texture format will never be used.. So do not care about color keying
|
|
|
|
|
up until the point in time it will be needed :-) */
|
|
|
|
|
FIXME(" ColorKeying not supported in the RGB 332 format !\n");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WINED3DFMT_R5G6B5:
|
|
|
|
|
if (colorkey_active) {
|
|
|
|
|
*convert = CONVERT_CK_565;
|
|
|
|
|
*format = GL_RGBA;
|
|
|
|
|
*internal = GL_RGBA;
|
|
|
|
|
*type = GL_UNSIGNED_SHORT_5_5_5_1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-05-22 01:29:44 +00:00
|
|
|
|
case WINED3DFMT_X1R5G5B5:
|
|
|
|
|
if (colorkey_active) {
|
|
|
|
|
*convert = CONVERT_CK_5551;
|
|
|
|
|
*format = GL_BGRA;
|
|
|
|
|
*internal = GL_RGBA;
|
|
|
|
|
*type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-22 21:49:09 +00:00
|
|
|
|
case WINED3DFMT_R8G8B8:
|
|
|
|
|
if (colorkey_active) {
|
|
|
|
|
*convert = CONVERT_CK_RGB24;
|
|
|
|
|
*format = GL_RGBA;
|
|
|
|
|
*internal = GL_RGBA;
|
|
|
|
|
*type = GL_UNSIGNED_INT_8_8_8_8;
|
|
|
|
|
*target_bpp = 4;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WINED3DFMT_X8R8G8B8:
|
|
|
|
|
if (colorkey_active) {
|
|
|
|
|
*convert = CONVERT_RGB32_888;
|
|
|
|
|
*format = GL_RGBA;
|
|
|
|
|
*internal = GL_RGBA;
|
|
|
|
|
*type = GL_UNSIGNED_INT_8_8_8_8;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-02-15 02:01:44 +00:00
|
|
|
|
case WINED3DFMT_V8U8:
|
2007-03-12 12:11:04 +00:00
|
|
|
|
if(GL_SUPPORT(NV_TEXTURE_SHADER3)) break;
|
2007-03-20 22:42:37 +00:00
|
|
|
|
else if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
|
|
|
|
|
*format = GL_DUDV_ATI;
|
|
|
|
|
*internal = GL_DU8DV8_ATI;
|
|
|
|
|
*type = GL_BYTE;
|
|
|
|
|
/* No conversion - Just change the gl type */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-02-15 02:01:44 +00:00
|
|
|
|
*convert = CONVERT_V8U8;
|
|
|
|
|
*format = GL_BGR;
|
|
|
|
|
*internal = GL_RGB8;
|
2007-03-20 23:06:04 +00:00
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2007-02-15 02:01:44 +00:00
|
|
|
|
*target_bpp = 3;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-08-31 18:41:03 +00:00
|
|
|
|
case WINED3DFMT_L6V5U5:
|
|
|
|
|
*convert = CONVERT_L6V5U5;
|
|
|
|
|
if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
|
|
|
|
|
*target_bpp = 3;
|
|
|
|
|
/* Use format and types from table */
|
|
|
|
|
} else {
|
|
|
|
|
/* Load it into unsigned R5G6B5, swap L and V channels, and revert that in the shader */
|
|
|
|
|
*target_bpp = 2;
|
|
|
|
|
*format = GL_RGB;
|
|
|
|
|
*internal = GL_RGB5;
|
|
|
|
|
*type = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-03-12 12:11:04 +00:00
|
|
|
|
case WINED3DFMT_X8L8V8U8:
|
2007-03-20 23:06:04 +00:00
|
|
|
|
*convert = CONVERT_X8L8V8U8;
|
2007-03-12 12:11:04 +00:00
|
|
|
|
*target_bpp = 4;
|
2007-09-01 18:00:10 +00:00
|
|
|
|
if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
|
|
|
|
|
/* Use formats from gl table. It is a bit unfortunate, but the conversion
|
|
|
|
|
* is needed to set the X format to 255 to get 1.0 for alpha when sampling
|
|
|
|
|
* the texture. OpenGL can't use GL_DSDT8_MAG8_NV as internal format with
|
|
|
|
|
* the needed type and format parameter, so the internal format contains a
|
|
|
|
|
* 4th component, which is returned as alpha
|
|
|
|
|
*/
|
|
|
|
|
} else {
|
|
|
|
|
/* Not supported by GL_ATI_envmap_bumpmap */
|
|
|
|
|
*format = GL_BGRA;
|
2007-09-21 21:34:09 +00:00
|
|
|
|
*internal = GL_RGB8;
|
|
|
|
|
*type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
2007-09-01 18:00:10 +00:00
|
|
|
|
}
|
2007-03-12 12:11:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WINED3DFMT_Q8W8V8U8:
|
|
|
|
|
if(GL_SUPPORT(NV_TEXTURE_SHADER3)) break;
|
2007-03-20 23:06:04 +00:00
|
|
|
|
*convert = CONVERT_Q8W8V8U8;
|
2007-03-12 12:11:04 +00:00
|
|
|
|
*format = GL_BGRA;
|
|
|
|
|
*internal = GL_RGBA8;
|
2007-03-20 23:06:04 +00:00
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2007-03-12 12:11:04 +00:00
|
|
|
|
*target_bpp = 4;
|
2007-03-20 22:42:37 +00:00
|
|
|
|
/* Not supported by GL_ATI_envmap_bumpmap */
|
2007-03-12 12:11:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WINED3DFMT_V16U16:
|
|
|
|
|
if(GL_SUPPORT(NV_TEXTURE_SHADER3)) break;
|
2007-03-20 23:06:04 +00:00
|
|
|
|
*convert = CONVERT_V16U16;
|
|
|
|
|
*format = GL_BGR;
|
2007-09-21 21:34:09 +00:00
|
|
|
|
*internal = GL_RGB16_EXT;
|
|
|
|
|
*type = GL_UNSIGNED_SHORT;
|
2007-03-20 23:06:04 +00:00
|
|
|
|
*target_bpp = 6;
|
2007-03-20 22:42:37 +00:00
|
|
|
|
/* What should I do here about GL_ATI_envmap_bumpmap?
|
|
|
|
|
* Convert it or allow data loss by loading it into a 8 bit / channel texture?
|
|
|
|
|
*/
|
2007-03-12 12:11:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-08-11 18:02:01 +00:00
|
|
|
|
case WINED3DFMT_A4L4:
|
|
|
|
|
/* A4L4 exists as an internal gl format, but for some reason there is not
|
|
|
|
|
* format+type combination to load it. Thus convert it to A8L8, then load it
|
|
|
|
|
* with A4L4 internal, but A8L8 format+type
|
|
|
|
|
*/
|
|
|
|
|
*convert = CONVERT_A4L4;
|
|
|
|
|
*format = GL_LUMINANCE_ALPHA;
|
|
|
|
|
*internal = GL_LUMINANCE4_ALPHA4;
|
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
|
|
|
|
*target_bpp = 2;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-08-12 14:24:29 +00:00
|
|
|
|
case WINED3DFMT_R32F:
|
|
|
|
|
/* Can be loaded in theory with fmt=GL_RED, type=GL_FLOAT, but this fails. The reason
|
|
|
|
|
* is that D3D expects the undefined green, blue and alpha channels to return 1.0
|
|
|
|
|
* when sampling, but OpenGL sets green and blue to 0.0 instead. Thus we have to inject
|
|
|
|
|
* 1.0 instead.
|
|
|
|
|
*
|
|
|
|
|
* The alpha channel defaults to 1.0 in opengl, so nothing has to be done about it.
|
|
|
|
|
*/
|
|
|
|
|
*convert = CONVERT_R32F;
|
|
|
|
|
*format = GL_RGB;
|
|
|
|
|
*internal = GL_RGB32F_ARB;
|
|
|
|
|
*type = GL_FLOAT;
|
|
|
|
|
*target_bpp = 12;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WINED3DFMT_R16F:
|
2007-08-29 19:43:57 +00:00
|
|
|
|
/* Similar to R32F */
|
2007-08-12 14:24:29 +00:00
|
|
|
|
*convert = CONVERT_R16F;
|
|
|
|
|
*format = GL_RGB;
|
|
|
|
|
*internal = GL_RGB16F_ARB;
|
|
|
|
|
*type = GL_HALF_FLOAT_ARB;
|
|
|
|
|
*target_bpp = 6;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-12-15 22:47:10 +00:00
|
|
|
|
case WINED3DFMT_G16R16:
|
|
|
|
|
*convert = CONVERT_G16R16;
|
|
|
|
|
*format = GL_RGB;
|
|
|
|
|
*internal = GL_RGB16_EXT;
|
|
|
|
|
*type = GL_UNSIGNED_SHORT;
|
|
|
|
|
*target_bpp = 6;
|
|
|
|
|
break;
|
|
|
|
|
|
2006-05-22 21:49:09 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-01 18:00:10 +00:00
|
|
|
|
HRESULT d3dfmt_convert_surface(BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height, UINT outpitch, CONVERT_TYPES convert, IWineD3DSurfaceImpl *This) {
|
2006-11-06 18:45:10 +00:00
|
|
|
|
BYTE *source, *dest;
|
2007-09-01 18:00:10 +00:00
|
|
|
|
TRACE("(%p)->(%p),(%d,%d,%d,%d,%p)\n", src, dst, pitch, height, outpitch, convert,This);
|
2006-05-22 21:49:09 +00:00
|
|
|
|
|
|
|
|
|
switch (convert) {
|
|
|
|
|
case NO_CONVERSION:
|
|
|
|
|
{
|
2006-10-05 19:35:10 +00:00
|
|
|
|
memcpy(dst, src, pitch * height);
|
2006-05-22 21:49:09 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CONVERT_PALETTED:
|
|
|
|
|
case CONVERT_PALETTED_CK:
|
|
|
|
|
{
|
2007-09-01 18:00:10 +00:00
|
|
|
|
IWineD3DPaletteImpl* pal = This->palette;
|
2006-05-22 21:49:09 +00:00
|
|
|
|
BYTE table[256][4];
|
2006-10-05 19:35:10 +00:00
|
|
|
|
unsigned int x, y;
|
2006-05-22 21:49:09 +00:00
|
|
|
|
|
|
|
|
|
if( pal == NULL) {
|
|
|
|
|
/* TODO: If we are a sublevel, try to get the palette from level 0 */
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-08 20:11:06 +00:00
|
|
|
|
d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK));
|
2006-05-22 21:49:09 +00:00
|
|
|
|
|
2006-10-05 19:35:10 +00:00
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
|
{
|
2006-11-06 18:45:10 +00:00
|
|
|
|
source = src + pitch * y;
|
2006-10-05 19:35:10 +00:00
|
|
|
|
dest = dst + outpitch * y;
|
2006-11-06 18:45:10 +00:00
|
|
|
|
/* This is an 1 bpp format, using the width here is fine */
|
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
|
BYTE color = *source++;
|
2006-10-05 19:35:10 +00:00
|
|
|
|
*dest++ = table[color][0];
|
|
|
|
|
*dest++ = table[color][1];
|
|
|
|
|
*dest++ = table[color][2];
|
|
|
|
|
*dest++ = table[color][3];
|
|
|
|
|
}
|
2006-05-22 21:49:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CONVERT_CK_565:
|
|
|
|
|
{
|
|
|
|
|
/* Converting the 565 format in 5551 packed to emulate color-keying.
|
|
|
|
|
|
|
|
|
|
Note : in all these conversion, it would be best to average the averaging
|
|
|
|
|
pixels to get the color of the pixel that will be color-keyed to
|
|
|
|
|
prevent 'color bleeding'. This will be done later on if ever it is
|
|
|
|
|
too visible.
|
|
|
|
|
|
2006-10-05 19:31:50 +00:00
|
|
|
|
Note2: Nvidia documents say that their driver does not support alpha + color keying
|
|
|
|
|
on the same surface and disables color keying in such a case
|
2006-05-22 21:49:09 +00:00
|
|
|
|
*/
|
2006-10-05 19:35:10 +00:00
|
|
|
|
unsigned int x, y;
|
|
|
|
|
WORD *Source;
|
|
|
|
|
WORD *Dest;
|
2006-05-22 21:49:09 +00:00
|
|
|
|
|
|
|
|
|
TRACE("Color keyed 565\n");
|
|
|
|
|
|
2006-10-05 19:35:10 +00:00
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
|
Source = (WORD *) (src + y * pitch);
|
|
|
|
|
Dest = (WORD *) (dst + y * outpitch);
|
2006-11-08 01:22:29 +00:00
|
|
|
|
for (x = 0; x < width; x++ ) {
|
2006-10-05 19:35:10 +00:00
|
|
|
|
WORD color = *Source++;
|
|
|
|
|
*Dest = ((color & 0xFFC0) | ((color & 0x1F) << 1));
|
2007-09-01 18:00:10 +00:00
|
|
|
|
if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
|
|
|
|
|
(color > This->SrcBltCKey.dwColorSpaceHighValue)) {
|
2006-10-05 19:35:10 +00:00
|
|
|
|
*Dest |= 0x0001;
|
|
|
|
|
}
|
|
|
|
|
Dest++;
|
2006-05-22 21:49:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-05-22 01:29:44 +00:00
|
|
|
|
case CONVERT_CK_5551:
|
|
|
|
|
{
|
|
|
|
|
/* Converting X1R5G5B5 format to R5G5B5A1 to emulate color-keying. */
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
WORD *Source;
|
|
|
|
|
WORD *Dest;
|
|
|
|
|
TRACE("Color keyed 5551\n");
|
|
|
|
|
for (y = 0; y < height; y++) {
|
|
|
|
|
Source = (WORD *) (src + y * pitch);
|
|
|
|
|
Dest = (WORD *) (dst + y * outpitch);
|
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
WORD color = *Source++;
|
|
|
|
|
*Dest = color;
|
2007-09-01 18:00:10 +00:00
|
|
|
|
if ((color < This->SrcBltCKey.dwColorSpaceLowValue) ||
|
|
|
|
|
(color > This->SrcBltCKey.dwColorSpaceHighValue)) {
|
2007-05-22 01:29:44 +00:00
|
|
|
|
*Dest |= (1 << 15);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*Dest &= ~(1 << 15);
|
|
|
|
|
}
|
|
|
|
|
Dest++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-02-15 02:01:44 +00:00
|
|
|
|
case CONVERT_V8U8:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
short *Source;
|
2007-03-05 20:40:47 +00:00
|
|
|
|
unsigned char *Dest;
|
2007-02-15 02:01:44 +00:00
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (short *) (src + y * pitch);
|
2008-01-23 21:40:02 +00:00
|
|
|
|
Dest = dst + y * outpitch;
|
2007-02-15 02:01:44 +00:00
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
long color = (*Source++);
|
2007-03-05 20:40:47 +00:00
|
|
|
|
/* B */ Dest[0] = 0xff;
|
|
|
|
|
/* G */ Dest[1] = (color >> 8) + 128; /* V */
|
|
|
|
|
/* R */ Dest[2] = (color) + 128; /* U */
|
2007-02-15 02:01:44 +00:00
|
|
|
|
Dest += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-21 21:34:09 +00:00
|
|
|
|
case CONVERT_V16U16:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
DWORD *Source;
|
|
|
|
|
unsigned short *Dest;
|
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (DWORD *) (src + y * pitch);
|
|
|
|
|
Dest = (unsigned short *) (dst + y * outpitch);
|
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
DWORD color = (*Source++);
|
|
|
|
|
/* B */ Dest[0] = 0xffff;
|
|
|
|
|
/* G */ Dest[1] = (color >> 16) + 32768; /* V */
|
|
|
|
|
/* R */ Dest[2] = (color ) + 32768; /* U */
|
|
|
|
|
Dest += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 23:06:04 +00:00
|
|
|
|
case CONVERT_Q8W8V8U8:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
DWORD *Source;
|
|
|
|
|
unsigned char *Dest;
|
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (DWORD *) (src + y * pitch);
|
2008-01-23 21:40:02 +00:00
|
|
|
|
Dest = dst + y * outpitch;
|
2007-03-20 23:06:04 +00:00
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
long color = (*Source++);
|
|
|
|
|
/* B */ Dest[0] = ((color >> 16) & 0xff) + 128; /* W */
|
|
|
|
|
/* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
|
|
|
|
|
/* R */ Dest[2] = (color & 0xff) + 128; /* U */
|
|
|
|
|
/* A */ Dest[3] = ((color >> 24) & 0xff) + 128; /* Q */
|
|
|
|
|
Dest += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-31 18:41:03 +00:00
|
|
|
|
case CONVERT_L6V5U5:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
WORD *Source;
|
|
|
|
|
unsigned char *Dest;
|
|
|
|
|
|
|
|
|
|
if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
|
|
|
|
|
/* This makes the gl surface bigger(24 bit instead of 16), but it works with
|
|
|
|
|
* fixed function and shaders without further conversion once the surface is
|
|
|
|
|
* loaded
|
|
|
|
|
*/
|
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (WORD *) (src + y * pitch);
|
2008-01-23 21:40:02 +00:00
|
|
|
|
Dest = dst + y * outpitch;
|
2007-08-31 18:41:03 +00:00
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
short color = (*Source++);
|
|
|
|
|
unsigned char l = ((color >> 10) & 0xfc);
|
|
|
|
|
char v = ((color >> 5) & 0x3e);
|
|
|
|
|
char u = ((color ) & 0x1f);
|
|
|
|
|
|
|
|
|
|
/* 8 bits destination, 6 bits source, 8th bit is the sign. gl ignores the sign
|
|
|
|
|
* and doubles the positive range. Thus shift left only once, gl does the 2nd
|
|
|
|
|
* shift. GL reads a signed value and converts it into an unsigned value.
|
|
|
|
|
*/
|
|
|
|
|
/* M */ Dest[2] = l << 1;
|
|
|
|
|
|
|
|
|
|
/* Those are read as signed, but kept signed. Just left-shift 3 times to scale
|
|
|
|
|
* from 5 bit values to 8 bit values.
|
|
|
|
|
*/
|
|
|
|
|
/* V */ Dest[1] = v << 3;
|
|
|
|
|
/* U */ Dest[0] = u << 3;
|
|
|
|
|
Dest += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2007-09-21 21:34:09 +00:00
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
unsigned short *Dest_s = (unsigned short *) (dst + y * outpitch);
|
|
|
|
|
Source = (WORD *) (src + y * pitch);
|
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
short color = (*Source++);
|
|
|
|
|
unsigned char l = ((color >> 10) & 0xfc);
|
|
|
|
|
short v = ((color >> 5) & 0x3e);
|
|
|
|
|
short u = ((color ) & 0x1f);
|
|
|
|
|
short v_conv = v + 16;
|
|
|
|
|
short u_conv = u + 16;
|
|
|
|
|
|
|
|
|
|
*Dest_s = ((v_conv << 11) & 0xf800) | ((l << 5) & 0x7e0) | (u_conv & 0x1f);
|
|
|
|
|
Dest_s += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-31 18:41:03 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-01 18:00:10 +00:00
|
|
|
|
case CONVERT_X8L8V8U8:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
DWORD *Source;
|
|
|
|
|
unsigned char *Dest;
|
|
|
|
|
|
|
|
|
|
if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
|
|
|
|
|
/* This implementation works with the fixed function pipeline and shaders
|
|
|
|
|
* without further modification after converting the surface.
|
|
|
|
|
*/
|
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (DWORD *) (src + y * pitch);
|
2008-01-23 21:40:02 +00:00
|
|
|
|
Dest = dst + y * outpitch;
|
2007-09-01 18:00:10 +00:00
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
long color = (*Source++);
|
|
|
|
|
/* L */ Dest[2] = ((color >> 16) & 0xff); /* L */
|
|
|
|
|
/* V */ Dest[1] = ((color >> 8 ) & 0xff); /* V */
|
|
|
|
|
/* U */ Dest[0] = (color & 0xff); /* U */
|
|
|
|
|
/* I */ Dest[3] = 255; /* X */
|
|
|
|
|
Dest += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Doesn't work correctly with the fixed function pipeline, but can work in
|
|
|
|
|
* shaders if the shader is adjusted. (There's no use for this format in gl's
|
|
|
|
|
* standard fixed function pipeline anyway).
|
|
|
|
|
*/
|
2007-09-21 21:34:09 +00:00
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (DWORD *) (src + y * pitch);
|
2008-01-23 21:40:02 +00:00
|
|
|
|
Dest = dst + y * outpitch;
|
2007-09-21 21:34:09 +00:00
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
long color = (*Source++);
|
|
|
|
|
/* B */ Dest[0] = ((color >> 16) & 0xff); /* L */
|
|
|
|
|
/* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
|
|
|
|
|
/* R */ Dest[2] = (color & 0xff) + 128; /* U */
|
|
|
|
|
Dest += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-01 18:00:10 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-11 18:02:01 +00:00
|
|
|
|
case CONVERT_A4L4:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
unsigned char *Source;
|
|
|
|
|
unsigned char *Dest;
|
|
|
|
|
for(y = 0; y < height; y++) {
|
2008-01-23 21:40:02 +00:00
|
|
|
|
Source = src + y * pitch;
|
|
|
|
|
Dest = dst + y * outpitch;
|
2007-08-11 18:02:01 +00:00
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
unsigned char color = (*Source++);
|
|
|
|
|
/* A */ Dest[1] = (color & 0xf0) << 0;
|
|
|
|
|
/* L */ Dest[0] = (color & 0x0f) << 4;
|
|
|
|
|
Dest += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-08-12 14:24:29 +00:00
|
|
|
|
|
|
|
|
|
case CONVERT_R32F:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
float *Source;
|
|
|
|
|
float *Dest;
|
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (float *) (src + y * pitch);
|
|
|
|
|
Dest = (float *) (dst + y * outpitch);
|
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
float color = (*Source++);
|
|
|
|
|
Dest[0] = color;
|
|
|
|
|
Dest[1] = 1.0;
|
|
|
|
|
Dest[2] = 1.0;
|
|
|
|
|
Dest += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CONVERT_R16F:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
WORD *Source;
|
|
|
|
|
WORD *Dest;
|
|
|
|
|
WORD one = 0x3c00;
|
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (WORD *) (src + y * pitch);
|
|
|
|
|
Dest = (WORD *) (dst + y * outpitch);
|
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
WORD color = (*Source++);
|
|
|
|
|
Dest[0] = color;
|
|
|
|
|
Dest[1] = one;
|
|
|
|
|
Dest[2] = one;
|
|
|
|
|
Dest += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-12-15 22:47:10 +00:00
|
|
|
|
|
|
|
|
|
case CONVERT_G16R16:
|
|
|
|
|
{
|
|
|
|
|
unsigned int x, y;
|
|
|
|
|
WORD *Source;
|
|
|
|
|
WORD *Dest;
|
|
|
|
|
|
|
|
|
|
for(y = 0; y < height; y++) {
|
|
|
|
|
Source = (WORD *) (src + y * pitch);
|
|
|
|
|
Dest = (WORD *) (dst + y * outpitch);
|
|
|
|
|
for (x = 0; x < width; x++ ) {
|
|
|
|
|
WORD green = (*Source++);
|
|
|
|
|
WORD red = (*Source++);
|
|
|
|
|
Dest[0] = green;
|
|
|
|
|
Dest[1] = red;
|
|
|
|
|
Dest[2] = 0xffff;
|
|
|
|
|
Dest += 3;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-22 21:49:09 +00:00
|
|
|
|
default:
|
|
|
|
|
ERR("Unsupported conversation type %d\n", convert);
|
|
|
|
|
}
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-14 12:34:47 +00:00
|
|
|
|
static void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4], BOOL colorkey) {
|
2006-08-03 10:39:04 +00:00
|
|
|
|
IWineD3DPaletteImpl* pal = This->palette;
|
2007-10-11 20:04:48 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
BOOL index_in_alpha = FALSE;
|
2006-08-03 10:39:04 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
2007-10-11 20:04:48 +00:00
|
|
|
|
/* Old games like StarCraft, C&C, Red Alert and others use P8 render targets.
|
|
|
|
|
* Reading back the RGB output each lockrect (each frame as they lock the whole screen)
|
|
|
|
|
* is slow. Further RGB->P8 conversion is not possible because palettes can have
|
|
|
|
|
* duplicate entries. Store the color key in the unused alpha component to speed the
|
|
|
|
|
* download up and to make conversion unneeded. */
|
|
|
|
|
if (device->render_targets && device->render_targets[0]) {
|
|
|
|
|
IWineD3DSurfaceImpl* render_target = (IWineD3DSurfaceImpl*)device->render_targets[0];
|
|
|
|
|
|
2007-12-23 19:51:58 +00:00
|
|
|
|
if((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET) && (render_target->resource.format == WINED3DFMT_P8))
|
2007-10-11 20:04:48 +00:00
|
|
|
|
index_in_alpha = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-03 10:39:04 +00:00
|
|
|
|
if (pal == NULL) {
|
|
|
|
|
/* Still no palette? Use the device's palette */
|
|
|
|
|
/* Get the surface's palette */
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
|
table[i][0] = device->palettes[device->currentPalette][i].peRed;
|
|
|
|
|
table[i][1] = device->palettes[device->currentPalette][i].peGreen;
|
|
|
|
|
table[i][2] = device->palettes[device->currentPalette][i].peBlue;
|
2007-10-11 20:04:48 +00:00
|
|
|
|
|
2008-01-29 19:08:25 +00:00
|
|
|
|
/* BltOverride uses a GL_ALPHA_TEST based on GL_NOT_EQUAL 0, so the alpha component
|
|
|
|
|
of pixels that should be masked away should be 0. When inde_in_alpha is set,
|
|
|
|
|
we will store the palette index (the glReadPixels code reads GL_ALPHA back)
|
|
|
|
|
or else we store 0xff. */
|
|
|
|
|
if(colorkey && (i >= This->SrcBltCKey.dwColorSpaceLowValue) && (i <= This->SrcBltCKey.dwColorSpaceHighValue)) {
|
|
|
|
|
table[i][3] = 0;
|
|
|
|
|
} else if(index_in_alpha) {
|
2007-10-11 20:04:48 +00:00
|
|
|
|
table[i][3] = i;
|
2006-08-03 10:39:04 +00:00
|
|
|
|
} else {
|
|
|
|
|
table[i][3] = 0xFF;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
TRACE("Using surface palette %p\n", pal);
|
|
|
|
|
/* Get the surface's palette */
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
|
table[i][0] = pal->palents[i].peRed;
|
|
|
|
|
table[i][1] = pal->palents[i].peGreen;
|
|
|
|
|
table[i][2] = pal->palents[i].peBlue;
|
2007-10-11 20:04:48 +00:00
|
|
|
|
|
2008-01-29 19:08:25 +00:00
|
|
|
|
/* BltOverride uses a GL_ALPHA_TEST based on GL_NOT_EQUAL 0, so the alpha component
|
|
|
|
|
of pixels that should be masked away should be 0. When inde_in_alpha is set,
|
|
|
|
|
we will store the palette index (the glReadPixels code reads GL_ALPHA back)
|
|
|
|
|
or else we store 0xff. */
|
|
|
|
|
if(colorkey && (i >= This->SrcBltCKey.dwColorSpaceLowValue) && (i <= This->SrcBltCKey.dwColorSpaceHighValue)) {
|
2006-08-03 10:39:04 +00:00
|
|
|
|
table[i][3] = 0x00;
|
2008-01-29 19:08:25 +00:00
|
|
|
|
} else if(index_in_alpha) {
|
|
|
|
|
table[i][3] = i;
|
2007-04-29 13:51:47 +00:00
|
|
|
|
} else if(pal->Flags & WINEDDPCAPS_ALPHA) {
|
|
|
|
|
table[i][3] = pal->palents[i].peFlags;
|
2006-08-03 10:39:04 +00:00
|
|
|
|
} else {
|
|
|
|
|
table[i][3] = 0xFF;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-08 20:11:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-11 21:11:37 +00:00
|
|
|
|
const char *fragment_palette_conversion =
|
|
|
|
|
"!!ARBfp1.0\n"
|
|
|
|
|
"TEMP index;\n"
|
|
|
|
|
"PARAM constants = { 0.996, 0.00195, 0, 0 };\n" /* { 255/256, 0.5/255*255/256, 0, 0 } */
|
2008-02-08 00:24:24 +00:00
|
|
|
|
"TEX index, fragment.texcoord[0], texture[0], 2D;\n" /* The alpha-component contains the palette index */
|
|
|
|
|
"MAD index.a, index.a, constants.x, constants.y;\n" /* Scale the index by 255/256 and add a bias of '0.5' in order to sample in the middle */
|
|
|
|
|
"TEX result.color, index.a, texture[1], 1D;\n" /* use the alpha-component as a index in the palette to get the final color */
|
2007-10-11 21:11:37 +00:00
|
|
|
|
"END";
|
|
|
|
|
|
2007-10-08 20:11:06 +00:00
|
|
|
|
/* This function is used in case of 8bit paletted textures to upload the palette.
|
2007-10-11 21:11:37 +00:00
|
|
|
|
It supports GL_EXT_paletted_texture and GL_ARB_fragment_program, support for other
|
|
|
|
|
extensions like ATI_fragment_shaders is possible.
|
2007-10-08 20:11:06 +00:00
|
|
|
|
*/
|
|
|
|
|
static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface, CONVERT_TYPES convert) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
BYTE table[256][4];
|
2007-10-11 21:11:37 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
2007-10-08 20:11:06 +00:00
|
|
|
|
|
|
|
|
|
d3dfmt_p8_init_palette(This, table, (convert == CONVERT_PALETTED_CK));
|
2007-10-11 21:11:37 +00:00
|
|
|
|
|
|
|
|
|
/* Try to use the paletted texture extension */
|
|
|
|
|
if(GL_SUPPORT(EXT_PALETTED_TEXTURE))
|
|
|
|
|
{
|
|
|
|
|
TRACE("Using GL_EXT_PALETTED_TEXTURE for 8-bit paletted texture support\n");
|
2007-11-26 20:28:20 +00:00
|
|
|
|
GL_EXTCALL(glColorTableEXT(This->glDescription.target,GL_RGBA,256,GL_RGBA,GL_UNSIGNED_BYTE, table));
|
2007-10-11 21:11:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Let a fragment shader do the color conversion by uploading the palette to a 1D texture.
|
|
|
|
|
* The 8bit pixel data will be used as an index in this palette texture to retrieve the final color. */
|
|
|
|
|
TRACE("Using fragment shaders for emulating 8-bit paletted texture support\n");
|
|
|
|
|
|
|
|
|
|
/* Create the fragment program if we don't have it */
|
|
|
|
|
if(!device->paletteConversionShader)
|
|
|
|
|
{
|
|
|
|
|
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
|
|
|
|
GL_EXTCALL(glGenProgramsARB(1, &device->paletteConversionShader));
|
|
|
|
|
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, device->paletteConversionShader));
|
|
|
|
|
GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(fragment_palette_conversion), (const GLbyte *)fragment_palette_conversion));
|
|
|
|
|
glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
|
|
|
|
GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, device->paletteConversionShader));
|
|
|
|
|
|
|
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE1));
|
|
|
|
|
glEnable(GL_TEXTURE_1D);
|
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); /* Make sure we have discrete color levels. */
|
|
|
|
|
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, table); /* Upload the palette */
|
|
|
|
|
|
|
|
|
|
/* Switch back to unit 0 in which the 2D texture will be stored. */
|
|
|
|
|
GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0));
|
2007-10-20 18:20:19 +00:00
|
|
|
|
|
|
|
|
|
/* Rebind the texture because it isn't bound anymore */
|
|
|
|
|
glBindTexture(This->glDescription.target, This->glDescription.textureName);
|
2007-10-11 21:11:37 +00:00
|
|
|
|
}
|
2006-08-03 10:39:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-19 14:23:36 +00:00
|
|
|
|
static BOOL palette9_changed(IWineD3DSurfaceImpl *This) {
|
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
|
|
|
|
|
if(This->palette || (This->resource.format != WINED3DFMT_P8 && This->resource.format != WINED3DFMT_A8P8)) {
|
|
|
|
|
/* If a ddraw-style palette is attached assume no d3d9 palette change.
|
|
|
|
|
* Also the palette isn't interesting if the surface format isn't P8 or A8P8
|
|
|
|
|
*/
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(This->palette9) {
|
|
|
|
|
if(memcmp(This->palette9, &device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256) == 0) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2007-06-26 22:13:32 +00:00
|
|
|
|
This->palette9 = HeapAlloc(GetProcessHeap(), 0, sizeof(PALETTEENTRY) * 256);
|
2007-02-19 14:23:36 +00:00
|
|
|
|
}
|
|
|
|
|
memcpy(This->palette9, &device->palettes[device->currentPalette], sizeof(PALETTEENTRY) * 256);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 20:46:52 +00:00
|
|
|
|
static inline void clear_unused_channels(IWineD3DSurfaceImpl *This) {
|
|
|
|
|
GLboolean oldwrite[4];
|
|
|
|
|
|
|
|
|
|
/* Some formats have only some color channels, and the others are 1.0.
|
|
|
|
|
* since our rendering renders to all channels, and those pixel formats
|
|
|
|
|
* are emulated by using a full texture with the other channels set to 1.0
|
|
|
|
|
* manually, clear the unused channels.
|
|
|
|
|
*
|
|
|
|
|
* This could be done with hacking colorwriteenable to mask the colors,
|
|
|
|
|
* but before drawing the buffer would have to be cleared too, so there's
|
|
|
|
|
* no gain in that
|
|
|
|
|
*/
|
|
|
|
|
switch(This->resource.format) {
|
|
|
|
|
case WINED3DFMT_R16F:
|
|
|
|
|
case WINED3DFMT_R32F:
|
|
|
|
|
TRACE("R16F or R32F format, clearing green, blue and alpha to 1.0\n");
|
|
|
|
|
/* Do not activate a context, the correct drawable is active already
|
|
|
|
|
* though just the read buffer is set, make sure to have the correct draw
|
|
|
|
|
* buffer too
|
|
|
|
|
*/
|
|
|
|
|
glDrawBuffer(This->resource.wineD3DDevice->offscreenBuffer);
|
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
glGetBooleanv(GL_COLOR_WRITEMASK, oldwrite);
|
|
|
|
|
glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
|
glClearColor(0.0, 1.0, 1.0, 1.0);
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
glColorMask(oldwrite[0], oldwrite[1], oldwrite[2], oldwrite[3]);
|
|
|
|
|
if(!This->resource.wineD3DDevice->render_offscreen) glDrawBuffer(GL_BACK);
|
|
|
|
|
checkGLcall("Unused channel clear\n");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-06 23:08:26 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BOOL srgb_mode) {
|
2005-01-09 17:37:02 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
|
2007-03-06 20:47:45 +00:00
|
|
|
|
if (!(This->Flags & SFLAG_INTEXTURE)) {
|
2006-07-25 14:41:41 +00:00
|
|
|
|
TRACE("Reloading because surface is dirty\n");
|
|
|
|
|
} else if(/* Reload: gl texture has ck, now no ckey is set OR */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
((This->Flags & SFLAG_GLCKEY) && (!(This->CKeyFlags & WINEDDSD_CKSRCBLT))) ||
|
2006-07-25 14:41:41 +00:00
|
|
|
|
/* Reload: vice versa OR */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
((!(This->Flags & SFLAG_GLCKEY)) && (This->CKeyFlags & WINEDDSD_CKSRCBLT)) ||
|
2006-07-25 14:41:41 +00:00
|
|
|
|
/* Also reload: Color key is active AND the color key has changed */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
((This->CKeyFlags & WINEDDSD_CKSRCBLT) && (
|
2006-07-26 21:19:04 +00:00
|
|
|
|
(This->glCKey.dwColorSpaceLowValue != This->SrcBltCKey.dwColorSpaceLowValue) ||
|
|
|
|
|
(This->glCKey.dwColorSpaceHighValue != This->SrcBltCKey.dwColorSpaceHighValue)))) {
|
2006-07-25 14:41:41 +00:00
|
|
|
|
TRACE("Reloading because of color keying\n");
|
2007-10-13 10:54:10 +00:00
|
|
|
|
/* To perform the color key conversion we need a sysmem copy of
|
|
|
|
|
* the surface. Make sure we have it
|
|
|
|
|
*/
|
2008-01-29 21:42:32 +00:00
|
|
|
|
|
2007-10-13 10:54:10 +00:00
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL);
|
2008-01-29 21:42:32 +00:00
|
|
|
|
/* Make sure the texture is reloaded because of the color key change, this kills performance though :( */
|
|
|
|
|
/* TODO: This is not necessarily needed with hw palettized texture support */
|
|
|
|
|
This->Flags &= ~SFLAG_INTEXTURE;
|
2007-02-19 14:23:36 +00:00
|
|
|
|
} else if(palette9_changed(This)) {
|
|
|
|
|
TRACE("Reloading surface because the d3d8/9 palette was changed\n");
|
2007-10-13 10:54:10 +00:00
|
|
|
|
/* TODO: This is not necessarily needed with hw palettized texture support */
|
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL);
|
2008-01-29 21:42:32 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure the texture is reloaded because of the color key change, this kills performance though :( */
|
|
|
|
|
This->Flags &= ~SFLAG_INTEXTURE;
|
2006-07-25 14:41:41 +00:00
|
|
|
|
} else {
|
2007-03-06 20:47:45 +00:00
|
|
|
|
TRACE("surface is already in texture\n");
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2005-07-11 14:25:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-02-06 19:57:42 +00:00
|
|
|
|
/* Resources are placed in system RAM and do not need to be recreated when a device is lost.
|
2007-10-13 10:54:10 +00:00
|
|
|
|
* These resources are not bound by device size or format restrictions. Because of this,
|
|
|
|
|
* these resources cannot be accessed by the Direct3D device nor set as textures or render targets.
|
|
|
|
|
* However, these resources can always be created, locked, and copied.
|
|
|
|
|
*/
|
2007-03-13 02:44:22 +00:00
|
|
|
|
if (This->resource.pool == WINED3DPOOL_SCRATCH )
|
2005-07-11 14:25:54 +00:00
|
|
|
|
{
|
2006-05-18 20:59:33 +00:00
|
|
|
|
FIXME("(%p) Operation not supported for scratch textures\n",This);
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-07-11 14:25:54 +00:00
|
|
|
|
}
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
2007-10-13 10:54:10 +00:00
|
|
|
|
This->srgb = srgb_mode;
|
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL /* no partial locking for textures yet */);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
|
|
|
|
#if 0
|
2006-09-11 16:51:18 +00:00
|
|
|
|
{
|
|
|
|
|
static unsigned int gen = 0;
|
|
|
|
|
char buffer[4096];
|
|
|
|
|
++gen;
|
|
|
|
|
if ((gen % 10) == 0) {
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm", This, This->glDescription.target, This->glDescription.level, gen);
|
|
|
|
|
IWineD3DSurfaceImpl_SaveSnapshot(iface, buffer);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
2006-09-11 16:51:18 +00:00
|
|
|
|
/*
|
|
|
|
|
* debugging crash code
|
|
|
|
|
if (gen == 250) {
|
|
|
|
|
void** test = NULL;
|
|
|
|
|
*test = 0;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
2005-01-09 17:37:02 +00:00
|
|
|
|
#endif
|
2005-07-13 11:34:55 +00:00
|
|
|
|
|
2006-09-11 16:51:18 +00:00
|
|
|
|
if (!(This->Flags & SFLAG_DONOTFREE)) {
|
2007-10-22 11:02:03 +00:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
|
2006-09-11 16:51:18 +00:00
|
|
|
|
This->resource.allocatedMemory = NULL;
|
2007-10-22 11:02:03 +00:00
|
|
|
|
This->resource.heapMemory = NULL;
|
2007-10-09 20:17:59 +00:00
|
|
|
|
IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, FALSE);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-15 13:38:34 +00:00
|
|
|
|
static void WINAPI IWineD3DSurfaceImpl_BindTexture(IWineD3DSurface *iface) {
|
|
|
|
|
/* TODO: check for locks */
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
IWineD3DBaseTexture *baseTexture = NULL;
|
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)Checking to see if the container is a base texture\n", This);
|
|
|
|
|
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture) == WINED3D_OK) {
|
|
|
|
|
TRACE("Passing to container\n");
|
|
|
|
|
IWineD3DBaseTexture_BindTexture(baseTexture);
|
|
|
|
|
IWineD3DBaseTexture_Release(baseTexture);
|
|
|
|
|
} else {
|
|
|
|
|
TRACE("(%p) : Binding surface\n", This);
|
|
|
|
|
|
|
|
|
|
if(!device->isInDraw) {
|
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
}
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
glBindTexture(This->glDescription.target, This->glDescription.textureName);
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-09 17:37:02 +00:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
HRESULT WINAPI IWineD3DSurfaceImpl_SaveSnapshot(IWineD3DSurface *iface, const char* filename) {
|
|
|
|
|
FILE* f = NULL;
|
2005-09-27 10:49:59 +00:00
|
|
|
|
UINT i, y;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2005-09-27 10:49:59 +00:00
|
|
|
|
char *allocatedMemory;
|
|
|
|
|
char *textureRow;
|
|
|
|
|
IWineD3DSwapChain *swapChain = NULL;
|
|
|
|
|
int width, height;
|
2006-08-26 22:37:56 +00:00
|
|
|
|
GLuint tmpTexture = 0;
|
2005-09-27 10:49:59 +00:00
|
|
|
|
DWORD color;
|
|
|
|
|
/*FIXME:
|
2007-06-07 09:48:55 +00:00
|
|
|
|
Textures may not be stored in ->allocatedgMemory and a GlTexture
|
2005-11-10 11:39:07 +00:00
|
|
|
|
so we should lock the surface before saving a snapshot, or at least check that
|
2005-09-27 10:49:59 +00:00
|
|
|
|
*/
|
|
|
|
|
/* TODO: Compressed texture images can be obtained from the GL in uncompressed form
|
|
|
|
|
by calling GetTexImage and in compressed form by calling
|
|
|
|
|
GetCompressedTexImageARB. Queried compressed images can be saved and
|
|
|
|
|
later reused by calling CompressedTexImage[123]DARB. Pre-compressed
|
|
|
|
|
texture images do not need to be processed by the GL and should
|
|
|
|
|
significantly improve texture loading performance relative to uncompressed
|
|
|
|
|
images. */
|
|
|
|
|
|
|
|
|
|
/* Setup the width and height to be the internal texture width and height. */
|
|
|
|
|
width = This->pow2Width;
|
|
|
|
|
height = This->pow2Height;
|
2007-06-07 09:48:55 +00:00
|
|
|
|
/* check to see if we're a 'virtual' texture, e.g. we're not a pbuffer of texture, we're a back buffer*/
|
2005-09-27 10:49:59 +00:00
|
|
|
|
IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapChain);
|
|
|
|
|
|
2007-03-06 20:47:45 +00:00
|
|
|
|
if (This->Flags & SFLAG_INDRAWABLE && !(This->Flags & SFLAG_INTEXTURE)) {
|
|
|
|
|
/* if were not a real texture then read the back buffer into a real texture */
|
|
|
|
|
/* we don't want to interfere with the back buffer so read the data into a temporary
|
|
|
|
|
* texture and then save the data out of the temporary texture
|
|
|
|
|
*/
|
2005-09-27 10:49:59 +00:00
|
|
|
|
GLint prevRead;
|
|
|
|
|
ENTER_GL();
|
2007-03-06 20:47:45 +00:00
|
|
|
|
TRACE("(%p) Reading render target into texture\n", This);
|
2005-09-27 10:49:59 +00:00
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
|
|
glGenTextures(1, &tmpTexture);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tmpTexture);
|
|
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
|
0,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
0/*border*/,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
glGetIntegerv(GL_READ_BUFFER, &prevRead);
|
|
|
|
|
vcheckGLcall("glGetIntegerv");
|
2007-02-27 20:32:15 +00:00
|
|
|
|
glReadBuffer(swapChain ? GL_BACK : This->resource.wineD3DDevice->offscreenBuffer);
|
2005-09-27 10:49:59 +00:00
|
|
|
|
vcheckGLcall("glReadBuffer");
|
|
|
|
|
glCopyTexImage2D(GL_TEXTURE_2D,
|
|
|
|
|
0,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
checkGLcall("glCopyTexImage2D");
|
|
|
|
|
glReadBuffer(prevRead);
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
2007-03-06 20:47:45 +00:00
|
|
|
|
} else { /* bind the real texture, and make sure it up to date */
|
2005-09-27 10:49:59 +00:00
|
|
|
|
IWineD3DSurface_PreLoad(iface);
|
|
|
|
|
}
|
|
|
|
|
allocatedMemory = HeapAlloc(GetProcessHeap(), 0, width * height * 4);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
FIXME("Saving texture level %d width %d height %d\n", This->glDescription.level, width, height);
|
|
|
|
|
glGetTexImage(GL_TEXTURE_2D,
|
|
|
|
|
This->glDescription.level,
|
|
|
|
|
GL_RGBA,
|
|
|
|
|
GL_UNSIGNED_INT_8_8_8_8_REV,
|
|
|
|
|
allocatedMemory);
|
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
|
if (tmpTexture) {
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
glDeleteTextures(1, &tmpTexture);
|
|
|
|
|
}
|
|
|
|
|
LEAVE_GL();
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
|
|
|
|
f = fopen(filename, "w+");
|
|
|
|
|
if (NULL == f) {
|
|
|
|
|
ERR("opening of %s failed with: %s\n", filename, strerror(errno));
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
2007-06-07 09:48:55 +00:00
|
|
|
|
/* Save the data out to a TGA file because 1: it's an easy raw format, 2: it supports an alpha channel */
|
2005-09-27 10:49:59 +00:00
|
|
|
|
TRACE("(%p) opened %s with format %s\n", This, filename, debug_d3dformat(This->resource.format));
|
|
|
|
|
/* TGA header */
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(2,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
fputc(0,f);
|
|
|
|
|
/* short width*/
|
|
|
|
|
fwrite(&width,2,1,f);
|
|
|
|
|
/* short height */
|
|
|
|
|
fwrite(&height,2,1,f);
|
|
|
|
|
/* format rgba */
|
|
|
|
|
fputc(0x20,f);
|
|
|
|
|
fputc(0x28,f);
|
|
|
|
|
/* raw data */
|
2007-06-07 09:48:55 +00:00
|
|
|
|
/* if the data is upside down if we've fetched it from a back buffer, so it needs flipping again to make it the correct way up */
|
2005-09-27 10:49:59 +00:00
|
|
|
|
if(swapChain)
|
|
|
|
|
textureRow = allocatedMemory + (width * (height - 1) *4);
|
|
|
|
|
else
|
|
|
|
|
textureRow = allocatedMemory;
|
|
|
|
|
for (y = 0 ; y < height; y++) {
|
|
|
|
|
for (i = 0; i < width; i++) {
|
|
|
|
|
color = *((DWORD*)textureRow);
|
|
|
|
|
fputc((color >> 16) & 0xFF, f); /* B */
|
|
|
|
|
fputc((color >> 8) & 0xFF, f); /* G */
|
|
|
|
|
fputc((color >> 0) & 0xFF, f); /* R */
|
|
|
|
|
fputc((color >> 24) & 0xFF, f); /* A */
|
|
|
|
|
textureRow += 4;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
2005-09-27 10:49:59 +00:00
|
|
|
|
/* take two rows of the pointer to the texture memory */
|
|
|
|
|
if(swapChain)
|
|
|
|
|
(textureRow-= width << 3);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
|
|
|
|
|
}
|
2005-09-27 10:49:59 +00:00
|
|
|
|
TRACE("Closing file\n");
|
2005-01-09 17:37:02 +00:00
|
|
|
|
fclose(f);
|
2005-09-27 10:49:59 +00:00
|
|
|
|
|
|
|
|
|
if(swapChain) {
|
|
|
|
|
IWineD3DSwapChain_Release(swapChain);
|
|
|
|
|
}
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, allocatedMemory);
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Slightly inefficient way to handle multiple dirty rects but it works :)
|
|
|
|
|
*/
|
|
|
|
|
extern HRESULT WINAPI IWineD3DSurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2005-07-11 14:25:54 +00:00
|
|
|
|
IWineD3DBaseTexture *baseTexture = NULL;
|
2007-09-24 22:16:05 +00:00
|
|
|
|
|
2007-06-06 23:08:26 +00:00
|
|
|
|
if (!(This->Flags & SFLAG_INSYSMEM) && (This->Flags & SFLAG_INTEXTURE))
|
2007-09-24 22:16:05 +00:00
|
|
|
|
IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
|
2007-06-06 23:08:26 +00:00
|
|
|
|
|
2007-10-09 20:17:59 +00:00
|
|
|
|
IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
|
2005-01-09 17:37:02 +00:00
|
|
|
|
if (NULL != pDirtyRect) {
|
|
|
|
|
This->dirtyRect.left = min(This->dirtyRect.left, pDirtyRect->left);
|
|
|
|
|
This->dirtyRect.top = min(This->dirtyRect.top, pDirtyRect->top);
|
|
|
|
|
This->dirtyRect.right = max(This->dirtyRect.right, pDirtyRect->right);
|
|
|
|
|
This->dirtyRect.bottom = max(This->dirtyRect.bottom, pDirtyRect->bottom);
|
|
|
|
|
} else {
|
|
|
|
|
This->dirtyRect.left = 0;
|
|
|
|
|
This->dirtyRect.top = 0;
|
|
|
|
|
This->dirtyRect.right = This->currentDesc.Width;
|
|
|
|
|
This->dirtyRect.bottom = This->currentDesc.Height;
|
|
|
|
|
}
|
2007-03-06 20:47:45 +00:00
|
|
|
|
TRACE("(%p) : Dirty: yes, Rect:(%d,%d,%d,%d)\n", This, This->dirtyRect.left,
|
2005-01-17 13:44:57 +00:00
|
|
|
|
This->dirtyRect.top, This->dirtyRect.right, This->dirtyRect.bottom);
|
2005-07-11 14:25:54 +00:00
|
|
|
|
/* if the container is a basetexture then mark it dirty. */
|
2006-04-07 10:51:12 +00:00
|
|
|
|
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&baseTexture) == WINED3D_OK) {
|
2007-06-05 22:21:08 +00:00
|
|
|
|
TRACE("Passing to container\n");
|
2005-07-11 14:25:54 +00:00
|
|
|
|
IWineD3DBaseTexture_SetDirty(baseTexture, TRUE);
|
|
|
|
|
IWineD3DBaseTexture_Release(baseTexture);
|
|
|
|
|
}
|
2006-04-07 10:51:12 +00:00
|
|
|
|
return WINED3D_OK;
|
2005-01-09 17:37:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-02 20:01:54 +00:00
|
|
|
|
HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2007-09-16 14:49:02 +00:00
|
|
|
|
HRESULT hr;
|
2007-07-23 09:13:37 +00:00
|
|
|
|
const GlPixelFormatDesc *glDesc;
|
2007-09-16 14:49:02 +00:00
|
|
|
|
getFormatDescEntry(format, &GLINFO_LOCATION, &glDesc);
|
2005-11-02 20:01:54 +00:00
|
|
|
|
|
2007-09-16 14:49:02 +00:00
|
|
|
|
TRACE("(%p) : Calling base function first\n", This);
|
|
|
|
|
hr = IWineD3DBaseSurfaceImpl_SetFormat(iface, format);
|
|
|
|
|
if(SUCCEEDED(hr)) {
|
|
|
|
|
/* Setup some glformat defaults */
|
|
|
|
|
This->glDescription.glFormat = glDesc->glFormat;
|
|
|
|
|
This->glDescription.glFormatInternal = glDesc->glInternal;
|
|
|
|
|
This->glDescription.glType = glDesc->glType;
|
2005-11-02 20:01:54 +00:00
|
|
|
|
|
2007-09-16 14:49:02 +00:00
|
|
|
|
This->Flags &= ~SFLAG_ALLOCATED;
|
|
|
|
|
TRACE("(%p) : glFormat %d, glFotmatInternal %d, glType %d\n", This,
|
|
|
|
|
This->glDescription.glFormat, This->glDescription.glFormatInternal, This->glDescription.glType);
|
2005-11-02 20:01:54 +00:00
|
|
|
|
}
|
2007-09-16 14:49:02 +00:00
|
|
|
|
return hr;
|
2005-11-02 20:01:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-07-25 14:38:02 +00:00
|
|
|
|
HRESULT WINAPI IWineD3DSurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
|
|
|
|
|
|
|
|
|
if(This->Flags & (SFLAG_LOCKED | SFLAG_DCINUSE)) {
|
|
|
|
|
WARN("Surface is locked or the HDC is in use\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(Mem && Mem != This->resource.allocatedMemory) {
|
2007-03-31 21:02:37 +00:00
|
|
|
|
void *release = NULL;
|
2006-07-25 14:38:02 +00:00
|
|
|
|
|
|
|
|
|
/* Do I have to copy the old surface content? */
|
|
|
|
|
if(This->Flags & SFLAG_DIBSECTION) {
|
|
|
|
|
/* Release the DC. No need to hold the critical section for the update
|
|
|
|
|
* Thread because this thread runs only on front buffers, but this method
|
|
|
|
|
* fails for render targets in the check above.
|
|
|
|
|
*/
|
|
|
|
|
SelectObject(This->hDC, This->dib.holdbitmap);
|
|
|
|
|
DeleteDC(This->hDC);
|
|
|
|
|
/* Release the DIB section */
|
|
|
|
|
DeleteObject(This->dib.DIBsection);
|
|
|
|
|
This->dib.bitmap_data = NULL;
|
|
|
|
|
This->resource.allocatedMemory = NULL;
|
|
|
|
|
This->hDC = NULL;
|
|
|
|
|
This->Flags &= ~SFLAG_DIBSECTION;
|
|
|
|
|
} else if(!(This->Flags & SFLAG_USERPTR)) {
|
2007-10-22 11:02:03 +00:00
|
|
|
|
release = This->resource.heapMemory;
|
|
|
|
|
This->resource.heapMemory = NULL;
|
2006-07-25 14:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
This->resource.allocatedMemory = Mem;
|
2007-03-31 21:02:37 +00:00
|
|
|
|
This->Flags |= SFLAG_USERPTR | SFLAG_INSYSMEM;
|
|
|
|
|
|
|
|
|
|
/* Now the surface memory is most up do date. Invalidate drawable and texture */
|
2007-10-09 20:17:59 +00:00
|
|
|
|
IWineD3DSurface_ModifyLocation(iface, SFLAG_INSYSMEM, TRUE);
|
2007-03-31 21:02:37 +00:00
|
|
|
|
|
|
|
|
|
/* For client textures opengl has to be notified */
|
|
|
|
|
if(This->Flags & SFLAG_CLIENT) {
|
2007-04-22 00:02:29 +00:00
|
|
|
|
This->Flags &= ~SFLAG_ALLOCATED;
|
2007-03-31 21:02:37 +00:00
|
|
|
|
IWineD3DSurface_PreLoad(iface);
|
|
|
|
|
/* And hope that the app behaves correctly and did not free the old surface memory before setting a new pointer */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now free the old memory if any */
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, release);
|
2006-07-25 14:38:02 +00:00
|
|
|
|
} else if(This->Flags & SFLAG_USERPTR) {
|
|
|
|
|
/* Lockrect and GetDC will re-create the dib section and allocated memory */
|
|
|
|
|
This->resource.allocatedMemory = NULL;
|
2007-10-22 11:02:03 +00:00
|
|
|
|
/* HeapMemory should be NULL already */
|
|
|
|
|
if(This->resource.heapMemory != NULL) ERR("User pointer surface has heap memory allocated\n");
|
2006-07-25 14:38:02 +00:00
|
|
|
|
This->Flags &= ~SFLAG_USERPTR;
|
2007-03-31 21:02:37 +00:00
|
|
|
|
|
|
|
|
|
if(This->Flags & SFLAG_CLIENT) {
|
2007-04-22 00:02:29 +00:00
|
|
|
|
This->Flags &= ~SFLAG_ALLOCATED;
|
2007-03-31 21:02:37 +00:00
|
|
|
|
/* This respecifies an empty texture and opengl knows that the old memory is gone */
|
|
|
|
|
IWineD3DSurface_PreLoad(iface);
|
|
|
|
|
}
|
2006-07-25 14:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_Flip(IWineD3DSurface *iface, IWineD3DSurface *override, DWORD Flags) {
|
2006-05-09 17:49:24 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
2007-06-03 11:20:27 +00:00
|
|
|
|
IWineD3DSwapChainImpl *swapchain = NULL;
|
|
|
|
|
HRESULT hr;
|
2006-10-01 03:20:10 +00:00
|
|
|
|
TRACE("(%p)->(%p,%x)\n", This, override, Flags);
|
2006-05-09 17:49:24 +00:00
|
|
|
|
|
|
|
|
|
/* Flipping is only supported on RenderTargets */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if( !(This->resource.usage & WINED3DUSAGE_RENDERTARGET) ) return WINEDDERR_NOTFLIPPABLE;
|
2006-05-09 17:49:24 +00:00
|
|
|
|
|
|
|
|
|
if(override) {
|
|
|
|
|
/* DDraw sets this for the X11 surfaces, so don't confuse the user
|
|
|
|
|
* FIXME("(%p) Target override is not supported by now\n", This);
|
|
|
|
|
* Additionally, it isn't really possible to support triple-buffering
|
|
|
|
|
* properly on opengl at all
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-03 11:20:27 +00:00
|
|
|
|
IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **) &swapchain);
|
|
|
|
|
if(!swapchain) {
|
|
|
|
|
ERR("Flipped surface is not on a swapchain\n");
|
|
|
|
|
return WINEDDERR_NOTFLIPPABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Just overwrite the swapchain presentation interval. This is ok because only ddraw apps can call Flip,
|
|
|
|
|
* and only d3d8 and d3d9 apps specify the presentation interval
|
|
|
|
|
*/
|
|
|
|
|
if((Flags & (WINEDDFLIP_NOVSYNC | WINEDDFLIP_INTERVAL2 | WINEDDFLIP_INTERVAL3 | WINEDDFLIP_INTERVAL4)) == 0) {
|
|
|
|
|
/* Most common case first to avoid wasting time on all the other cases */
|
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_ONE;
|
|
|
|
|
} else if(Flags & WINEDDFLIP_NOVSYNC) {
|
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
|
} else if(Flags & WINEDDFLIP_INTERVAL2) {
|
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_TWO;
|
|
|
|
|
} else if(Flags & WINEDDFLIP_INTERVAL3) {
|
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_THREE;
|
|
|
|
|
} else {
|
|
|
|
|
swapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_FOUR;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-09 17:49:24 +00:00
|
|
|
|
/* Flipping a OpenGL surface -> Use WineD3DDevice::Present */
|
2007-06-03 11:20:27 +00:00
|
|
|
|
hr = IWineD3DSwapChain_Present((IWineD3DSwapChain *) swapchain, NULL, NULL, 0, NULL, 0);
|
|
|
|
|
IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
|
|
|
|
|
return hr;
|
2006-04-12 20:32:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-12 18:18:46 +00:00
|
|
|
|
/* Does a direct frame buffer -> texture copy. Stretching is done
|
|
|
|
|
* with single pixel copy calls
|
|
|
|
|
*/
|
2007-04-03 10:00:15 +00:00
|
|
|
|
static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface, IWineD3DSwapChainImpl *swapchain, WINED3DRECT *srect, WINED3DRECT *drect, BOOL upsidedown, WINED3DTEXTUREFILTERTYPE Filter) {
|
2007-02-12 18:18:46 +00:00
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
|
|
|
|
float xrel, yrel;
|
|
|
|
|
UINT row;
|
|
|
|
|
IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
|
2007-08-06 14:27:08 +00:00
|
|
|
|
ENTER_GL();
|
2007-06-09 12:59:15 +00:00
|
|
|
|
IWineD3DSurface_PreLoad((IWineD3DSurface *) This);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
2007-11-26 20:43:08 +00:00
|
|
|
|
/* TODO: Do we need GL_TEXTURE_2D enabled fpr copyteximage? */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glEnable(This->glDescription.target);
|
|
|
|
|
checkGLcall("glEnable(This->glDescription.target)");
|
2007-11-26 20:43:08 +00:00
|
|
|
|
|
2007-02-12 18:18:46 +00:00
|
|
|
|
/* Bind the target texture */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glBindTexture(This->glDescription.target, This->glDescription.textureName);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
checkGLcall("glBindTexture");
|
2007-02-27 20:32:15 +00:00
|
|
|
|
if(!swapchain) {
|
|
|
|
|
glReadBuffer(myDevice->offscreenBuffer);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
} else {
|
2007-04-16 19:20:32 +00:00
|
|
|
|
GLenum buffer = surface_get_gl_buffer(SrcSurface, (IWineD3DSwapChain *)swapchain);
|
|
|
|
|
glReadBuffer(buffer);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
}
|
|
|
|
|
checkGLcall("glReadBuffer");
|
|
|
|
|
|
|
|
|
|
xrel = (float) (srect->x2 - srect->x1) / (float) (drect->x2 - drect->x1);
|
|
|
|
|
yrel = (float) (srect->y2 - srect->y1) / (float) (drect->y2 - drect->y1);
|
|
|
|
|
|
|
|
|
|
if( (xrel - 1.0 < -eps) || (xrel - 1.0 > eps)) {
|
|
|
|
|
FIXME("Doing a pixel by pixel copy from the framebuffer to a texture, expect major performance issues\n");
|
2007-04-03 10:00:15 +00:00
|
|
|
|
|
2007-05-10 15:42:41 +00:00
|
|
|
|
if(Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT) {
|
2007-04-03 10:00:15 +00:00
|
|
|
|
ERR("Texture filtering not supported in direct blit\n");
|
|
|
|
|
}
|
2007-05-10 15:42:41 +00:00
|
|
|
|
} else if((Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT) && ((yrel - 1.0 < -eps) || (yrel - 1.0 > eps))) {
|
2007-04-03 10:00:15 +00:00
|
|
|
|
ERR("Texture filtering not supported in direct blit\n");
|
2007-02-12 18:18:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(upsidedown &&
|
|
|
|
|
!((xrel - 1.0 < -eps) || (xrel - 1.0 > eps)) &&
|
|
|
|
|
!((yrel - 1.0 < -eps) || (yrel - 1.0 > eps))) {
|
|
|
|
|
/* Upside down copy without stretching is nice, one glCopyTexSubImage call will do */
|
|
|
|
|
|
|
|
|
|
glCopyTexSubImage2D(This->glDescription.target,
|
|
|
|
|
This->glDescription.level,
|
|
|
|
|
drect->x1, drect->y1, /* xoffset, yoffset */
|
|
|
|
|
srect->x1, Src->currentDesc.Height - srect->y2,
|
|
|
|
|
drect->x2 - drect->x1, drect->y2 - drect->y1);
|
|
|
|
|
} else {
|
|
|
|
|
UINT yoffset = Src->currentDesc.Height - srect->y1 + drect->y1 - 1;
|
|
|
|
|
/* I have to process this row by row to swap the image,
|
2007-06-05 22:21:08 +00:00
|
|
|
|
* otherwise it would be upside down, so stretching in y direction
|
2007-02-12 18:18:46 +00:00
|
|
|
|
* doesn't cost extra time
|
|
|
|
|
*
|
2007-06-05 22:21:08 +00:00
|
|
|
|
* However, stretching in x direction can be avoided if not necessary
|
2007-02-12 18:18:46 +00:00
|
|
|
|
*/
|
|
|
|
|
for(row = drect->y1; row < drect->y2; row++) {
|
|
|
|
|
if( (xrel - 1.0 < -eps) || (xrel - 1.0 > eps)) {
|
|
|
|
|
/* Well, that stuff works, but it's very slow.
|
|
|
|
|
* find a better way instead
|
|
|
|
|
*/
|
|
|
|
|
UINT col;
|
|
|
|
|
|
|
|
|
|
for(col = drect->x1; col < drect->x2; col++) {
|
|
|
|
|
glCopyTexSubImage2D(This->glDescription.target,
|
|
|
|
|
This->glDescription.level,
|
|
|
|
|
drect->x1 + col, row, /* xoffset, yoffset */
|
|
|
|
|
srect->x1 + col * xrel, yoffset - (int) (row * yrel),
|
|
|
|
|
1, 1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
glCopyTexSubImage2D(This->glDescription.target,
|
|
|
|
|
This->glDescription.level,
|
|
|
|
|
drect->x1, row, /* xoffset, yoffset */
|
|
|
|
|
srect->x1, yoffset - (int) (row * yrel),
|
|
|
|
|
drect->x2-drect->x1, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vcheckGLcall("glCopyTexSubImage2D");
|
2007-11-26 20:43:08 +00:00
|
|
|
|
|
|
|
|
|
/* Leave the opengl state valid for blitting */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glDisable(This->glDescription.target);
|
|
|
|
|
checkGLcall("glDisable(This->glDescription.target)");
|
2007-11-26 20:43:08 +00:00
|
|
|
|
|
2007-02-12 18:18:46 +00:00
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Uses the hardware to stretch and flip the image */
|
2007-04-03 10:00:15 +00:00
|
|
|
|
static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface, IWineD3DSwapChainImpl *swapchain, WINED3DRECT *srect, WINED3DRECT *drect, BOOL upsidedown, WINED3DTEXTUREFILTERTYPE Filter) {
|
2007-03-01 00:42:50 +00:00
|
|
|
|
GLuint src, backup = 0;
|
2007-02-12 18:18:46 +00:00
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
|
|
|
|
IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
|
|
|
|
|
float left, right, top, bottom; /* Texture coordinates */
|
|
|
|
|
UINT fbwidth = Src->currentDesc.Width;
|
|
|
|
|
UINT fbheight = Src->currentDesc.Height;
|
2007-03-04 22:47:57 +00:00
|
|
|
|
GLenum drawBuffer = GL_BACK;
|
2007-11-26 20:28:20 +00:00
|
|
|
|
GLenum texture_target;
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
|
|
|
|
TRACE("Using hwstretch blit\n");
|
|
|
|
|
/* Activate the Proper context for reading from the source surface, set it up for blitting */
|
|
|
|
|
ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
|
2007-08-06 14:27:08 +00:00
|
|
|
|
ENTER_GL();
|
2007-11-26 20:43:08 +00:00
|
|
|
|
|
2007-06-09 12:59:15 +00:00
|
|
|
|
IWineD3DSurface_PreLoad((IWineD3DSurface *) This);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
2007-03-04 22:47:57 +00:00
|
|
|
|
/* Try to use an aux buffer for drawing the rectangle. This way it doesn't need restoring.
|
|
|
|
|
* This way we don't have to wait for the 2nd readback to finish to leave this function.
|
|
|
|
|
*/
|
|
|
|
|
if(GL_LIMITS(aux_buffers) >= 2) {
|
|
|
|
|
/* Got more than one aux buffer? Use the 2nd aux buffer */
|
|
|
|
|
drawBuffer = GL_AUX1;
|
|
|
|
|
} else if((swapchain || myDevice->offscreenBuffer == GL_BACK) && GL_LIMITS(aux_buffers) >= 1) {
|
|
|
|
|
/* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */
|
|
|
|
|
drawBuffer = GL_AUX0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-01 00:42:50 +00:00
|
|
|
|
if(!swapchain && wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
|
|
|
|
|
glGenTextures(1, &backup);
|
|
|
|
|
checkGLcall("glGenTextures\n");
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, backup);
|
|
|
|
|
checkGLcall("glBindTexture(Src->glDescription.target, Src->glDescription.textureName)");
|
2007-11-26 20:28:20 +00:00
|
|
|
|
texture_target = GL_TEXTURE_2D;
|
2007-03-01 00:42:50 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* Backup the back buffer and copy the source buffer into a texture to draw an upside down stretched quad. If
|
|
|
|
|
* we are reading from the back buffer, the backup can be used as source texture
|
|
|
|
|
*/
|
|
|
|
|
if(Src->glDescription.textureName == 0) {
|
|
|
|
|
/* Get it a description */
|
|
|
|
|
IWineD3DSurface_PreLoad(SrcSurface);
|
|
|
|
|
}
|
2007-11-26 20:28:20 +00:00
|
|
|
|
texture_target = Src->glDescription.target;
|
|
|
|
|
glBindTexture(texture_target, Src->glDescription.textureName);
|
|
|
|
|
checkGLcall("glBindTexture(texture_target, Src->glDescription.textureName)");
|
|
|
|
|
glEnable(texture_target);
|
|
|
|
|
checkGLcall("glEnable(texture_target)");
|
2007-03-06 20:47:45 +00:00
|
|
|
|
|
|
|
|
|
/* For now invalidate the texture copy of the back buffer. Drawable and sysmem copy are untouched */
|
|
|
|
|
Src->Flags &= ~SFLAG_INTEXTURE;
|
2007-03-01 00:42:50 +00:00
|
|
|
|
}
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
|
checkGLcall("glReadBuffer(GL_BACK)");
|
|
|
|
|
|
|
|
|
|
/* TODO: Only back up the part that will be overwritten */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glCopyTexSubImage2D(texture_target, 0,
|
2007-02-12 18:18:46 +00:00
|
|
|
|
0, 0 /* read offsets */,
|
|
|
|
|
0, 0,
|
|
|
|
|
fbwidth,
|
|
|
|
|
fbheight);
|
|
|
|
|
|
|
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
|
2007-03-01 00:42:50 +00:00
|
|
|
|
/* No issue with overriding these - the sampler is dirty due to blit usage */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER,
|
2007-04-03 10:00:15 +00:00
|
|
|
|
stateLookup[WINELOOKUP_MAGFILTER][Filter - minLookup[WINELOOKUP_MAGFILTER]]);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
checkGLcall("glTexParameteri");
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER,
|
2007-04-03 10:00:15 +00:00
|
|
|
|
minMipLookup[Filter][WINED3DTEXF_NONE]);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
|
2007-03-01 00:42:50 +00:00
|
|
|
|
if(!swapchain || (IWineD3DSurface *) Src == swapchain->backBuffer[0]) {
|
|
|
|
|
src = backup ? backup : Src->glDescription.textureName;
|
2007-02-12 18:18:46 +00:00
|
|
|
|
} else {
|
|
|
|
|
glReadBuffer(GL_FRONT);
|
|
|
|
|
checkGLcall("glReadBuffer(GL_FRONT)");
|
|
|
|
|
|
|
|
|
|
glGenTextures(1, &src);
|
|
|
|
|
checkGLcall("glGenTextures(1, &src)");
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, src);
|
|
|
|
|
checkGLcall("glBindTexture(GL_TEXTURE_2D, src)");
|
|
|
|
|
|
|
|
|
|
/* TODO: Only copy the part that will be read. Use srect->x1, srect->y2 as origin, but with the width watch
|
|
|
|
|
* out for power of 2 sizes
|
|
|
|
|
*/
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Src->pow2Width, Src->pow2Height, 0,
|
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
|
|
|
|
|
0, 0 /* read offsets */,
|
|
|
|
|
0, 0,
|
|
|
|
|
fbwidth,
|
|
|
|
|
fbheight);
|
|
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
|
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
|
checkGLcall("glReadBuffer(GL_BACK)");
|
2007-11-26 20:28:20 +00:00
|
|
|
|
|
|
|
|
|
if(texture_target != GL_TEXTURE_2D) {
|
|
|
|
|
glDisable(texture_target);
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
texture_target = GL_TEXTURE_2D;
|
|
|
|
|
}
|
2007-02-12 18:18:46 +00:00
|
|
|
|
}
|
|
|
|
|
checkGLcall("glEnd and previous");
|
|
|
|
|
|
|
|
|
|
left = (float) srect->x1 / (float) Src->pow2Width;
|
|
|
|
|
right = (float) srect->x2 / (float) Src->pow2Width;
|
|
|
|
|
|
|
|
|
|
if(upsidedown) {
|
|
|
|
|
top = (float) (Src->currentDesc.Height - srect->y1) / (float) Src->pow2Height;
|
|
|
|
|
bottom = (float) (Src->currentDesc.Height - srect->y2) / (float) Src->pow2Height;
|
|
|
|
|
} else {
|
|
|
|
|
top = (float) (Src->currentDesc.Height - srect->y2) / (float) Src->pow2Height;
|
|
|
|
|
bottom = (float) (Src->currentDesc.Height - srect->y1) / (float) Src->pow2Height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* draw the source texture stretched and upside down. The correct surface is bound already */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
|
glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
2007-03-04 22:47:57 +00:00
|
|
|
|
glDrawBuffer(drawBuffer);
|
|
|
|
|
glReadBuffer(drawBuffer);
|
|
|
|
|
|
2007-02-12 18:18:46 +00:00
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
/* bottom left */
|
|
|
|
|
glTexCoord2f(left, bottom);
|
|
|
|
|
glVertex2i(0, fbheight);
|
|
|
|
|
|
|
|
|
|
/* top left */
|
|
|
|
|
glTexCoord2f(left, top);
|
|
|
|
|
glVertex2i(0, fbheight - drect->y2 - drect->y1);
|
|
|
|
|
|
|
|
|
|
/* top right */
|
|
|
|
|
glTexCoord2f(right, top);
|
|
|
|
|
glVertex2i(drect->x2 - drect->x1, fbheight - drect->y2 - drect->y1);
|
|
|
|
|
|
|
|
|
|
/* bottom right */
|
|
|
|
|
glTexCoord2f(right, bottom);
|
|
|
|
|
glVertex2i(drect->x2 - drect->x1, fbheight);
|
|
|
|
|
glEnd();
|
|
|
|
|
checkGLcall("glEnd and previous");
|
|
|
|
|
|
2007-11-26 20:28:20 +00:00
|
|
|
|
if(texture_target != This->glDescription.target) {
|
|
|
|
|
glDisable(texture_target);
|
|
|
|
|
glEnable(This->glDescription.target);
|
|
|
|
|
texture_target = This->glDescription.target;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-12 18:18:46 +00:00
|
|
|
|
/* Now read the stretched and upside down image into the destination texture */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glBindTexture(texture_target, This->glDescription.textureName);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
checkGLcall("glBindTexture");
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glCopyTexSubImage2D(texture_target,
|
2007-02-12 18:18:46 +00:00
|
|
|
|
0,
|
|
|
|
|
drect->x1, drect->y1, /* xoffset, yoffset */
|
|
|
|
|
0, 0, /* We blitted the image to the origin */
|
|
|
|
|
drect->x2 - drect->x1, drect->y2 - drect->y1);
|
|
|
|
|
checkGLcall("glCopyTexSubImage2D");
|
|
|
|
|
|
2007-03-04 22:47:57 +00:00
|
|
|
|
if(drawBuffer == GL_BACK) {
|
2007-11-26 20:28:20 +00:00
|
|
|
|
/* Write the back buffer backup back */
|
|
|
|
|
if(backup) {
|
|
|
|
|
if(texture_target != GL_TEXTURE_2D) {
|
|
|
|
|
glDisable(texture_target);
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
texture_target = GL_TEXTURE_2D;
|
|
|
|
|
}
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, backup);
|
|
|
|
|
checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
|
|
|
|
|
} else {
|
|
|
|
|
if(texture_target != Src->glDescription.target) {
|
|
|
|
|
glDisable(texture_target);
|
|
|
|
|
glEnable(Src->glDescription.target);
|
|
|
|
|
texture_target = Src->glDescription.target;
|
|
|
|
|
}
|
|
|
|
|
glBindTexture(Src->glDescription.target, Src->glDescription.textureName);
|
|
|
|
|
checkGLcall("glBindTexture(Src->glDescription.target, Src->glDescription.textureName)");
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-04 22:47:57 +00:00
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
/* top left */
|
|
|
|
|
glTexCoord2f(0.0, (float) fbheight / (float) Src->pow2Height);
|
|
|
|
|
glVertex2i(0, 0);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
2007-03-04 22:47:57 +00:00
|
|
|
|
/* bottom left */
|
|
|
|
|
glTexCoord2f(0.0, 0.0);
|
|
|
|
|
glVertex2i(0, fbheight);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
2007-03-04 22:47:57 +00:00
|
|
|
|
/* bottom right */
|
|
|
|
|
glTexCoord2f((float) fbwidth / (float) Src->pow2Width, 0.0);
|
|
|
|
|
glVertex2i(fbwidth, Src->currentDesc.Height);
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
2007-03-04 22:47:57 +00:00
|
|
|
|
/* top right */
|
|
|
|
|
glTexCoord2f((float) fbwidth / (float) Src->pow2Width, (float) fbheight / (float) Src->pow2Height);
|
|
|
|
|
glVertex2i(fbwidth, 0);
|
|
|
|
|
glEnd();
|
|
|
|
|
} else {
|
|
|
|
|
/* Restore the old draw buffer */
|
|
|
|
|
glDrawBuffer(GL_BACK);
|
|
|
|
|
}
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glDisable(texture_target);
|
|
|
|
|
checkGLcall("glDisable(texture_target)");
|
2007-02-12 18:18:46 +00:00
|
|
|
|
|
|
|
|
|
/* Cleanup */
|
2007-03-01 00:42:50 +00:00
|
|
|
|
if(src != Src->glDescription.textureName && src != backup) {
|
2007-02-12 18:18:46 +00:00
|
|
|
|
glDeleteTextures(1, &src);
|
|
|
|
|
checkGLcall("glDeleteTextures(1, &src)");
|
|
|
|
|
}
|
2007-03-01 00:42:50 +00:00
|
|
|
|
if(backup) {
|
|
|
|
|
glDeleteTextures(1, &backup);
|
|
|
|
|
checkGLcall("glDeleteTextures(1, &backup)");
|
|
|
|
|
}
|
2007-11-26 20:43:08 +00:00
|
|
|
|
|
2007-02-12 18:18:46 +00:00
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-22 22:48:54 +00:00
|
|
|
|
/* Not called from the VTable */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter) {
|
2006-10-12 06:22:18 +00:00
|
|
|
|
WINED3DRECT rect;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
2007-02-15 02:02:39 +00:00
|
|
|
|
IWineD3DSwapChainImpl *srcSwapchain = NULL, *dstSwapchain = NULL;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
|
|
|
|
|
|
2006-10-01 03:20:10 +00:00
|
|
|
|
TRACE("(%p)->(%p,%p,%p,%08x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
|
|
|
|
/* Get the swapchain. One of the surfaces has to be a primary surface */
|
2007-08-21 21:24:16 +00:00
|
|
|
|
if(This->resource.pool == WINED3DPOOL_SYSTEMMEM) {
|
|
|
|
|
WARN("Destination is in sysmem, rejecting gl blt\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
2007-02-15 02:02:39 +00:00
|
|
|
|
IWineD3DSurface_GetContainer( (IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&dstSwapchain);
|
|
|
|
|
if(dstSwapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *) dstSwapchain);
|
|
|
|
|
if(Src) {
|
2007-08-21 21:24:16 +00:00
|
|
|
|
if(Src->resource.pool == WINED3DPOOL_SYSTEMMEM) {
|
|
|
|
|
WARN("Src is in sysmem, rejecting gl blt\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
2007-02-15 02:02:39 +00:00
|
|
|
|
IWineD3DSurface_GetContainer( (IWineD3DSurface *) Src, &IID_IWineD3DSwapChain, (void **)&srcSwapchain);
|
|
|
|
|
if(srcSwapchain) IWineD3DSwapChain_Release((IWineD3DSwapChain *) srcSwapchain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Early sort out of cases where no render target is used */
|
|
|
|
|
if(!dstSwapchain && !srcSwapchain &&
|
|
|
|
|
SrcSurface != myDevice->render_targets[0] && This != (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
|
|
|
|
|
TRACE("No surface is render target, not using hardware blit. Src = %p, dst = %p\n", Src, This);
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 02:03:05 +00:00
|
|
|
|
/* No destination color keying supported */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if(Flags & (WINEDDBLT_KEYDEST | WINEDDBLT_KEYDESTOVERRIDE)) {
|
2007-02-15 02:03:05 +00:00
|
|
|
|
/* Can we support that with glBlendFunc if blitting to the frame buffer? */
|
|
|
|
|
TRACE("Destination color key not supported in accelerated Blit, falling back to software\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-22 22:48:54 +00:00
|
|
|
|
if (DestRect) {
|
|
|
|
|
rect.x1 = DestRect->left;
|
|
|
|
|
rect.y1 = DestRect->top;
|
|
|
|
|
rect.x2 = DestRect->right;
|
|
|
|
|
rect.y2 = DestRect->bottom;
|
|
|
|
|
} else {
|
|
|
|
|
rect.x1 = 0;
|
|
|
|
|
rect.y1 = 0;
|
|
|
|
|
rect.x2 = This->currentDesc.Width;
|
|
|
|
|
rect.y2 = This->currentDesc.Height;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* The only case where both surfaces on a swapchain are supported is a back buffer -> front buffer blit on the same swapchain */
|
2007-04-29 10:48:34 +00:00
|
|
|
|
if(dstSwapchain && dstSwapchain == srcSwapchain && dstSwapchain->backBuffer &&
|
|
|
|
|
((IWineD3DSurface *) This == dstSwapchain->frontBuffer) && SrcSurface == dstSwapchain->backBuffer[0]) {
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Half-life does a Blt from the back buffer to the front buffer,
|
|
|
|
|
* Full surface size, no flags... Use present instead
|
2007-04-29 10:48:34 +00:00
|
|
|
|
*
|
|
|
|
|
* This path will only be entered for d3d7 and ddraw apps, because d3d8/9 offer no way to blit TO the front buffer
|
2007-02-15 02:02:39 +00:00
|
|
|
|
*/
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
|
|
|
|
/* Check rects - IWineD3DDevice_Present doesn't handle them */
|
2007-04-29 10:48:34 +00:00
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
RECT mySrcRect;
|
2007-05-10 16:51:00 +00:00
|
|
|
|
TRACE("Looking if a Present can be done...\n");
|
2007-04-29 10:48:34 +00:00
|
|
|
|
/* Source Rectangle must be full surface */
|
|
|
|
|
if( SrcRect ) {
|
|
|
|
|
if(SrcRect->left != 0 || SrcRect->top != 0 ||
|
|
|
|
|
SrcRect->right != Src->currentDesc.Width || SrcRect->bottom != Src->currentDesc.Height) {
|
|
|
|
|
TRACE("No, Source rectangle doesn't match\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mySrcRect.left = 0;
|
|
|
|
|
mySrcRect.top = 0;
|
|
|
|
|
mySrcRect.right = Src->currentDesc.Width;
|
|
|
|
|
mySrcRect.bottom = Src->currentDesc.Height;
|
|
|
|
|
|
|
|
|
|
/* No stretching may occur */
|
|
|
|
|
if(mySrcRect.right != rect.x2 - rect.x1 ||
|
|
|
|
|
mySrcRect.bottom != rect.y2 - rect.y1) {
|
|
|
|
|
TRACE("No, stretching is done\n");
|
|
|
|
|
break;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-29 10:48:34 +00:00
|
|
|
|
/* Destination must be full surface or match the clipping rectangle */
|
|
|
|
|
if(This->clipper && ((IWineD3DClipperImpl *) This->clipper)->hWnd)
|
|
|
|
|
{
|
|
|
|
|
RECT cliprect;
|
|
|
|
|
POINT pos[2];
|
|
|
|
|
GetClientRect(((IWineD3DClipperImpl *) This->clipper)->hWnd, &cliprect);
|
|
|
|
|
pos[0].x = rect.x1;
|
|
|
|
|
pos[0].y = rect.y1;
|
|
|
|
|
pos[1].x = rect.x2;
|
|
|
|
|
pos[1].y = rect.y2;
|
|
|
|
|
MapWindowPoints(GetDesktopWindow(), ((IWineD3DClipperImpl *) This->clipper)->hWnd,
|
|
|
|
|
pos, 2);
|
|
|
|
|
|
|
|
|
|
if(pos[0].x != cliprect.left || pos[0].y != cliprect.top ||
|
|
|
|
|
pos[1].x != cliprect.right || pos[1].y != cliprect.bottom)
|
|
|
|
|
{
|
|
|
|
|
TRACE("No, dest rectangle doesn't match(clipper)\n");
|
|
|
|
|
TRACE("Clip rect at (%d,%d)-(%d,%d)\n", cliprect.left, cliprect.top, cliprect.right, cliprect.bottom);
|
|
|
|
|
TRACE("Blt dest: (%d,%d)-(%d,%d)\n", rect.x1, rect.y1, rect.x2, rect.y2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(rect.x1 != 0 || rect.y1 != 0 ||
|
|
|
|
|
rect.x2 != This->currentDesc.Width || rect.y2 != This->currentDesc.Height) {
|
|
|
|
|
TRACE("No, dest rectangle doesn't match(surface size)\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-04-29 10:48:34 +00:00
|
|
|
|
TRACE("Yes\n");
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-04-29 10:48:34 +00:00
|
|
|
|
/* These flags are unimportant for the flag check, remove them */
|
|
|
|
|
if((Flags & ~(WINEDDBLT_DONOTWAIT | WINEDDBLT_WAIT)) == 0) {
|
|
|
|
|
WINED3DSWAPEFFECT orig_swap = dstSwapchain->presentParms.SwapEffect;
|
|
|
|
|
|
|
|
|
|
/* The idea behind this is that a glReadPixels and a glDrawPixels call
|
|
|
|
|
* take very long, while a flip is fast.
|
|
|
|
|
* This applies to Half-Life, which does such Blts every time it finished
|
|
|
|
|
* a frame, and to Prince of Persia 3D, which uses this to draw at least the main
|
|
|
|
|
* menu. This is also used by all apps when they do windowed rendering
|
|
|
|
|
*
|
|
|
|
|
* The problem is that flipping is not really the same as copying. After a
|
|
|
|
|
* Blt the front buffer is a copy of the back buffer, and the back buffer is
|
|
|
|
|
* untouched. Therefore it's necessary to override the swap effect
|
|
|
|
|
* and to set it back after the flip.
|
|
|
|
|
*
|
2007-06-05 22:21:08 +00:00
|
|
|
|
* Windowed Direct3D < 7 apps do the same. The D3D7 sdk demos are nice
|
2007-04-29 10:48:34 +00:00
|
|
|
|
* testcases.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
dstSwapchain->presentParms.SwapEffect = WINED3DSWAPEFFECT_COPY;
|
2007-06-03 11:20:27 +00:00
|
|
|
|
dstSwapchain->presentParms.PresentationInterval = WINED3DPRESENT_INTERVAL_IMMEDIATE;
|
2007-04-29 10:48:34 +00:00
|
|
|
|
|
|
|
|
|
TRACE("Full screen back buffer -> front buffer blt, performing a flip instead\n");
|
2007-06-03 11:20:27 +00:00
|
|
|
|
IWineD3DSwapChain_Present((IWineD3DSwapChain *) dstSwapchain, NULL, NULL, 0, NULL, 0);
|
2007-04-29 10:48:34 +00:00
|
|
|
|
|
|
|
|
|
dstSwapchain->presentParms.SwapEffect = orig_swap;
|
|
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
2007-04-29 10:48:34 +00:00
|
|
|
|
break;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
TRACE("Unsupported blit between buffers on the same swapchain\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2007-12-15 23:18:20 +00:00
|
|
|
|
} else if(dstSwapchain && dstSwapchain == srcSwapchain) {
|
|
|
|
|
FIXME("Implement hardware blit between two surfaces on the same swapchain\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
} else if(dstSwapchain && srcSwapchain) {
|
|
|
|
|
FIXME("Implement hardware blit between two different swapchains\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
} else if(dstSwapchain) {
|
2007-12-31 02:04:27 +00:00
|
|
|
|
if(SrcSurface == myDevice->render_targets[0]) {
|
|
|
|
|
TRACE("Blit from active render target to a swapchain\n");
|
|
|
|
|
/* Handled with regular texture -> swapchain blit */
|
2007-12-15 23:18:20 +00:00
|
|
|
|
}
|
2007-12-25 21:57:01 +00:00
|
|
|
|
} else if(srcSwapchain && This == (IWineD3DSurfaceImpl *) myDevice->render_targets[0]) {
|
2007-12-15 23:18:20 +00:00
|
|
|
|
FIXME("Implement blit from a swapchain to the active render target\n");
|
2007-02-15 02:02:39 +00:00
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-12-18 12:55:47 +00:00
|
|
|
|
if((srcSwapchain || SrcSurface == myDevice->render_targets[0]) && !dstSwapchain) {
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Blit from render target to texture */
|
|
|
|
|
WINED3DRECT srect;
|
|
|
|
|
BOOL upsideDown, stretchx;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
|
2007-02-15 02:03:05 +00:00
|
|
|
|
TRACE("Color keying not supported by frame buffer to texture blit\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
/* Destination color key is checked above */
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-05 22:21:08 +00:00
|
|
|
|
/* Make sure that the top pixel is always above the bottom pixel, and keep a separate upside down flag
|
2007-06-09 12:59:15 +00:00
|
|
|
|
* glCopyTexSubImage is a bit picky about the parameters we pass to it
|
|
|
|
|
*/
|
2007-02-15 02:02:39 +00:00
|
|
|
|
if(SrcRect) {
|
|
|
|
|
if(SrcRect->top < SrcRect->bottom) {
|
|
|
|
|
srect.y1 = SrcRect->top;
|
|
|
|
|
srect.y2 = SrcRect->bottom;
|
|
|
|
|
upsideDown = FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
srect.y1 = SrcRect->bottom;
|
|
|
|
|
srect.y2 = SrcRect->top;
|
|
|
|
|
upsideDown = TRUE;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
2007-02-15 02:02:39 +00:00
|
|
|
|
srect.x1 = SrcRect->left;
|
|
|
|
|
srect.x2 = SrcRect->right;
|
|
|
|
|
} else {
|
|
|
|
|
srect.x1 = 0;
|
|
|
|
|
srect.y1 = 0;
|
|
|
|
|
srect.x2 = Src->currentDesc.Width;
|
|
|
|
|
srect.y2 = Src->currentDesc.Height;
|
|
|
|
|
upsideDown = FALSE;
|
|
|
|
|
}
|
|
|
|
|
if(rect.x1 > rect.x2) {
|
|
|
|
|
UINT tmp = rect.x2;
|
|
|
|
|
rect.x2 = rect.x1;
|
|
|
|
|
rect.x1 = tmp;
|
|
|
|
|
upsideDown = !upsideDown;
|
|
|
|
|
}
|
2007-02-15 12:51:55 +00:00
|
|
|
|
if(!srcSwapchain) {
|
|
|
|
|
TRACE("Reading from an offscreen target\n");
|
|
|
|
|
upsideDown = !upsideDown;
|
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
if(rect.x2 - rect.x1 != srect.x2 - srect.x1) {
|
|
|
|
|
stretchx = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
stretchx = FALSE;
|
|
|
|
|
}
|
2006-07-26 21:19:04 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Blt is a pretty powerful call, while glCopyTexSubImage2D is not. glCopyTexSubImage cannot
|
2007-04-08 23:54:07 +00:00
|
|
|
|
* flip the image nor scale it.
|
2007-02-15 02:02:39 +00:00
|
|
|
|
*
|
|
|
|
|
* -> If the app asks for a unscaled, upside down copy, just perform one glCopyTexSubImage2D call
|
|
|
|
|
* -> If the app wants a image width an unscaled width, copy it line per line
|
|
|
|
|
* -> If the app wants a image that is scaled on the x axis, and the destination rectangle is smaller
|
|
|
|
|
* than the frame buffer, draw an upside down scaled image onto the fb, read it back and restore the
|
|
|
|
|
* back buffer. This is slower than reading line per line, thus not used for flipping
|
|
|
|
|
* -> If the app wants a scaled image with a dest rect that is bigger than the fb, it has to be copied
|
|
|
|
|
* pixel by pixel
|
2007-04-08 23:54:07 +00:00
|
|
|
|
*
|
|
|
|
|
* If EXT_framebuffer_blit is supported that can be used instead. Note that EXT_framebuffer_blit implies
|
|
|
|
|
* FBO support, so it doesn't really make sense to try and make it work with different offscreen rendering
|
|
|
|
|
* backends.
|
2007-02-15 02:02:39 +00:00
|
|
|
|
*/
|
2007-04-08 23:54:07 +00:00
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && GL_SUPPORT(EXT_FRAMEBUFFER_BLIT)) {
|
|
|
|
|
stretch_rect_fbo((IWineD3DDevice *)myDevice, SrcSurface, &srect,
|
|
|
|
|
(IWineD3DSurface *)This, &rect, Filter, upsideDown);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
} else if((!stretchx) || rect.x2 - rect.x1 > Src->currentDesc.Width ||
|
|
|
|
|
rect.y2 - rect.y1 > Src->currentDesc.Height) {
|
|
|
|
|
TRACE("No stretching in x direction, using direct framebuffer -> texture copy\n");
|
2007-04-03 10:00:15 +00:00
|
|
|
|
fb_copy_to_texture_direct(This, SrcSurface, srcSwapchain, &srect, &rect, upsideDown, Filter);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
} else {
|
|
|
|
|
TRACE("Using hardware stretching to flip / stretch the texture\n");
|
2007-04-03 10:00:15 +00:00
|
|
|
|
fb_copy_to_texture_hwstretch(This, SrcSurface, srcSwapchain, &srect, &rect, upsideDown, Filter);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
if(!(This->Flags & SFLAG_DONOTFREE)) {
|
2007-10-22 11:02:03 +00:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
This->resource.allocatedMemory = NULL;
|
2007-10-22 11:02:03 +00:00
|
|
|
|
This->resource.heapMemory = NULL;
|
2007-02-15 02:02:39 +00:00
|
|
|
|
} else {
|
2007-03-06 20:47:45 +00:00
|
|
|
|
This->Flags &= ~SFLAG_INSYSMEM;
|
2007-02-15 02:02:39 +00:00
|
|
|
|
}
|
2007-03-06 20:47:45 +00:00
|
|
|
|
/* The texture is now most up to date - If the surface is a render target and has a drawable, this
|
|
|
|
|
* path is never entered
|
|
|
|
|
*/
|
2007-10-09 20:17:59 +00:00
|
|
|
|
IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
} else if(Src) {
|
|
|
|
|
/* Blit from offscreen surface to render target */
|
|
|
|
|
float glTexCoord[4];
|
2007-02-15 02:03:05 +00:00
|
|
|
|
DWORD oldCKeyFlags = Src->CKeyFlags;
|
2007-04-14 20:44:55 +00:00
|
|
|
|
WINEDDCOLORKEY oldBltCKey = This->SrcBltCKey;
|
2007-02-15 02:02:39 +00:00
|
|
|
|
RECT SourceRectangle;
|
|
|
|
|
|
|
|
|
|
TRACE("Blt from surface %p to rendertarget %p\n", Src, This);
|
|
|
|
|
|
|
|
|
|
if(SrcRect) {
|
|
|
|
|
SourceRectangle.left = SrcRect->left;
|
|
|
|
|
SourceRectangle.right = SrcRect->right;
|
|
|
|
|
SourceRectangle.top = SrcRect->top;
|
|
|
|
|
SourceRectangle.bottom = SrcRect->bottom;
|
|
|
|
|
} else {
|
|
|
|
|
SourceRectangle.left = 0;
|
|
|
|
|
SourceRectangle.right = Src->currentDesc.Width;
|
|
|
|
|
SourceRectangle.top = 0;
|
|
|
|
|
SourceRectangle.bottom = Src->currentDesc.Height;
|
|
|
|
|
}
|
2007-12-18 12:52:48 +00:00
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && GL_SUPPORT(EXT_FRAMEBUFFER_BLIT) &&
|
|
|
|
|
(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) == 0) {
|
|
|
|
|
TRACE("Using stretch_rect_fbo\n");
|
|
|
|
|
/* The source is always a texture, but never the currently active render target, and the texture
|
|
|
|
|
* contents are never upside down
|
|
|
|
|
*/
|
|
|
|
|
stretch_rect_fbo((IWineD3DDevice *)myDevice, SrcSurface, (WINED3DRECT *) &SourceRectangle,
|
|
|
|
|
(IWineD3DSurface *)This, &rect, Filter, FALSE);
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
if(!CalculateTexRect(Src, &SourceRectangle, glTexCoord)) {
|
|
|
|
|
/* Fall back to software */
|
|
|
|
|
WARN("(%p) Source texture area (%d,%d)-(%d,%d) is too big\n", Src,
|
|
|
|
|
SourceRectangle.left, SourceRectangle.top,
|
|
|
|
|
SourceRectangle.right, SourceRectangle.bottom);
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Color keying: Check if we have to do a color keyed blt,
|
|
|
|
|
* and if not check if a color key is activated.
|
2007-02-15 02:03:05 +00:00
|
|
|
|
*
|
|
|
|
|
* Just modify the color keying parameters in the surface and restore them afterwards
|
|
|
|
|
* The surface keeps track of the color key last used to load the opengl surface.
|
2007-06-05 22:21:08 +00:00
|
|
|
|
* PreLoad will catch the change to the flags and color key and reload if necessary.
|
2007-02-15 02:02:39 +00:00
|
|
|
|
*/
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if(Flags & WINEDDBLT_KEYSRC) {
|
2007-02-15 02:03:05 +00:00
|
|
|
|
/* Use color key from surface */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
} else if(Flags & WINEDDBLT_KEYSRCOVERRIDE) {
|
2007-02-15 02:03:05 +00:00
|
|
|
|
/* Use color key from DDBltFx */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
Src->CKeyFlags |= WINEDDSD_CKSRCBLT;
|
2007-02-15 02:03:05 +00:00
|
|
|
|
This->SrcBltCKey = DDBltFx->ddckSrcColorkey;
|
|
|
|
|
} else {
|
|
|
|
|
/* Do not use color key */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
Src->CKeyFlags &= ~WINEDDSD_CKSRCBLT;
|
2007-02-15 02:02:39 +00:00
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Now load the surface */
|
|
|
|
|
IWineD3DSurface_PreLoad((IWineD3DSurface *) Src);
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2006-07-26 21:19:04 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Activate the destination context, set it up for blitting */
|
|
|
|
|
ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
|
2007-08-06 14:27:08 +00:00
|
|
|
|
ENTER_GL();
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glEnable(Src->glDescription.target);
|
|
|
|
|
checkGLcall("glEnable(Src->glDescription.target)");
|
2007-11-26 20:43:08 +00:00
|
|
|
|
|
2007-03-14 21:00:31 +00:00
|
|
|
|
if(!dstSwapchain) {
|
|
|
|
|
TRACE("Drawing to offscreen buffer\n");
|
|
|
|
|
glDrawBuffer(myDevice->offscreenBuffer);
|
2007-06-05 02:42:04 +00:00
|
|
|
|
checkGLcall("glDrawBuffer");
|
2007-03-14 21:00:31 +00:00
|
|
|
|
} else {
|
2007-04-16 19:20:32 +00:00
|
|
|
|
GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *)This, (IWineD3DSwapChain *)dstSwapchain);
|
|
|
|
|
TRACE("Drawing to %#x buffer\n", buffer);
|
|
|
|
|
glDrawBuffer(buffer);
|
|
|
|
|
checkGLcall("glDrawBuffer");
|
2007-02-15 02:02:39 +00:00
|
|
|
|
}
|
2006-06-04 14:42:57 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Bind the texture */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glBindTexture(Src->glDescription.target, Src->glDescription.textureName);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
|
|
2007-04-03 10:00:15 +00:00
|
|
|
|
/* Filtering for StretchRect */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glTexParameteri(Src->glDescription.target, GL_TEXTURE_MAG_FILTER,
|
2007-04-03 10:00:15 +00:00
|
|
|
|
stateLookup[WINELOOKUP_MAGFILTER][Filter - minLookup[WINELOOKUP_MAGFILTER]]);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
checkGLcall("glTexParameteri");
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glTexParameteri(Src->glDescription.target, GL_TEXTURE_MIN_FILTER,
|
2007-04-03 10:00:15 +00:00
|
|
|
|
minMipLookup[Filter][WINED3DTEXF_NONE]);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
checkGLcall("glTexParameteri");
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glTexParameteri(Src->glDescription.target, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
|
glTexParameteri(Src->glDescription.target, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
|
checkGLcall("glTexEnvi");
|
|
|
|
|
|
|
|
|
|
/* This is for color keying */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
|
2007-02-15 02:02:39 +00:00
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
|
checkGLcall("glEnable GL_ALPHA_TEST");
|
|
|
|
|
glAlphaFunc(GL_NOTEQUAL, 0.0);
|
|
|
|
|
checkGLcall("glAlphaFunc\n");
|
|
|
|
|
} else {
|
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
|
checkGLcall("glDisable GL_ALPHA_TEST");
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* Draw a textured quad
|
2007-03-14 21:00:31 +00:00
|
|
|
|
*/
|
2007-02-15 02:02:39 +00:00
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
|
|
|
|
|
glColor3d(1.0f, 1.0f, 1.0f);
|
|
|
|
|
glTexCoord2f(glTexCoord[0], glTexCoord[2]);
|
|
|
|
|
glVertex3f(rect.x1,
|
|
|
|
|
rect.y1,
|
|
|
|
|
0.0);
|
|
|
|
|
|
|
|
|
|
glTexCoord2f(glTexCoord[0], glTexCoord[3]);
|
|
|
|
|
glVertex3f(rect.x1, rect.y2, 0.0);
|
|
|
|
|
|
|
|
|
|
glTexCoord2f(glTexCoord[1], glTexCoord[3]);
|
|
|
|
|
glVertex3f(rect.x2,
|
|
|
|
|
rect.y2,
|
|
|
|
|
0.0);
|
|
|
|
|
|
|
|
|
|
glTexCoord2f(glTexCoord[1], glTexCoord[2]);
|
|
|
|
|
glVertex3f(rect.x2,
|
|
|
|
|
rect.y1,
|
|
|
|
|
0.0);
|
|
|
|
|
glEnd();
|
|
|
|
|
checkGLcall("glEnd");
|
|
|
|
|
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
|
2007-02-15 02:04:40 +00:00
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
|
checkGLcall("glDisable(GL_ALPHA_TEST)");
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-08 22:08:07 +00:00
|
|
|
|
/* Flush in case the drawable is used by multiple GL contexts */
|
|
|
|
|
if(dstSwapchain && (dstSwapchain->num_contexts >= 2))
|
|
|
|
|
glFlush();
|
|
|
|
|
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glBindTexture(Src->glDescription.target, 0);
|
|
|
|
|
checkGLcall("glBindTexture(Src->glDescription.target, 0)");
|
2007-11-26 20:43:08 +00:00
|
|
|
|
/* Leave the opengl state valid for blitting */
|
2007-11-26 20:28:20 +00:00
|
|
|
|
glDisable(Src->glDescription.target);
|
|
|
|
|
checkGLcall("glDisable(Src->glDescription.target)");
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-03-14 21:00:31 +00:00
|
|
|
|
/* The draw buffer should only need to be restored if we were drawing to the front buffer, and there is a back buffer.
|
|
|
|
|
* otherwise the context manager should choose between GL_BACK / offscreenDrawBuffer
|
|
|
|
|
*/
|
|
|
|
|
if(dstSwapchain && This == (IWineD3DSurfaceImpl *) dstSwapchain->frontBuffer && dstSwapchain->backBuffer) {
|
|
|
|
|
glDrawBuffer(GL_BACK);
|
2007-06-05 02:42:04 +00:00
|
|
|
|
checkGLcall("glDrawBuffer");
|
2007-02-15 02:02:39 +00:00
|
|
|
|
}
|
2007-02-15 02:03:05 +00:00
|
|
|
|
/* Restore the color key parameters */
|
|
|
|
|
Src->CKeyFlags = oldCKeyFlags;
|
|
|
|
|
This->SrcBltCKey = oldBltCKey;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
LEAVE_GL();
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* TODO: If the surface is locked often, perform the Blt in software on the memory instead */
|
2007-03-06 20:47:45 +00:00
|
|
|
|
/* The surface is now in the drawable. On onscreen surfaces or without fbos the texture
|
|
|
|
|
* is outdated now
|
|
|
|
|
*/
|
2007-10-09 20:17:59 +00:00
|
|
|
|
IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INDRAWABLE, TRUE);
|
|
|
|
|
/* TODO: This should be moved to ModifyLocation() */
|
|
|
|
|
if(!(dstSwapchain || wined3d_settings.offscreen_rendering_mode != ORM_FBO)) {
|
2007-03-06 20:47:45 +00:00
|
|
|
|
This->Flags |= SFLAG_INTEXTURE;
|
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
} else {
|
|
|
|
|
/* Source-Less Blit to render target */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if (Flags & WINEDDBLT_COLORFILL) {
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* This is easy to handle for the D3D Device... */
|
|
|
|
|
DWORD color;
|
|
|
|
|
|
|
|
|
|
TRACE("Colorfill\n");
|
|
|
|
|
|
2007-12-20 07:32:11 +00:00
|
|
|
|
/* This == (IWineD3DSurfaceImpl *) myDevice->render_targets[0] || dstSwapchain
|
|
|
|
|
must be true if we are here */
|
|
|
|
|
if (This != (IWineD3DSurfaceImpl *) myDevice->render_targets[0] &&
|
|
|
|
|
!(This == (IWineD3DSurfaceImpl*) dstSwapchain->frontBuffer ||
|
|
|
|
|
(dstSwapchain->backBuffer && This == (IWineD3DSurfaceImpl*) dstSwapchain->backBuffer[0]))) {
|
|
|
|
|
TRACE("Surface is higher back buffer, falling back to software\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-15 02:02:39 +00:00
|
|
|
|
/* The color as given in the Blt function is in the format of the frame-buffer...
|
|
|
|
|
* 'clear' expect it in ARGB format => we need to do some conversion :-)
|
|
|
|
|
*/
|
|
|
|
|
if (This->resource.format == WINED3DFMT_P8) {
|
|
|
|
|
if (This->palette) {
|
|
|
|
|
color = ((0xFF000000) |
|
|
|
|
|
(This->palette->palents[DDBltFx->u5.dwFillColor].peRed << 16) |
|
|
|
|
|
(This->palette->palents[DDBltFx->u5.dwFillColor].peGreen << 8) |
|
|
|
|
|
(This->palette->palents[DDBltFx->u5.dwFillColor].peBlue));
|
2007-02-12 18:18:46 +00:00
|
|
|
|
} else {
|
2007-02-15 02:02:39 +00:00
|
|
|
|
color = 0xFF000000;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
2007-02-15 02:02:39 +00:00
|
|
|
|
}
|
|
|
|
|
else if (This->resource.format == WINED3DFMT_R5G6B5) {
|
|
|
|
|
if (DDBltFx->u5.dwFillColor == 0xFFFF) {
|
|
|
|
|
color = 0xFFFFFFFF;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
} else {
|
2007-02-15 02:02:39 +00:00
|
|
|
|
color = ((0xFF000000) |
|
|
|
|
|
((DDBltFx->u5.dwFillColor & 0xF800) << 8) |
|
|
|
|
|
((DDBltFx->u5.dwFillColor & 0x07E0) << 5) |
|
|
|
|
|
((DDBltFx->u5.dwFillColor & 0x001F) << 3));
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-02-15 02:02:39 +00:00
|
|
|
|
else if ((This->resource.format == WINED3DFMT_R8G8B8) ||
|
|
|
|
|
(This->resource.format == WINED3DFMT_X8R8G8B8) ) {
|
|
|
|
|
color = 0xFF000000 | DDBltFx->u5.dwFillColor;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
2007-02-15 02:02:39 +00:00
|
|
|
|
else if (This->resource.format == WINED3DFMT_A8R8G8B8) {
|
|
|
|
|
color = DDBltFx->u5.dwFillColor;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ERR("Wrong surface type for BLT override(Format doesn't match) !\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRACE("(%p) executing Render Target override, color = %x\n", This, color);
|
2007-12-20 07:32:11 +00:00
|
|
|
|
IWineD3DDeviceImpl_ClearSurface(myDevice, This,
|
|
|
|
|
1, /* Number of rectangles */
|
|
|
|
|
&rect, WINED3DCLEAR_TARGET, color,
|
|
|
|
|
0.0 /* Z */,
|
|
|
|
|
0 /* Stencil */);
|
2007-02-15 02:02:39 +00:00
|
|
|
|
return WINED3D_OK;
|
2006-06-24 10:32:18 +00:00
|
|
|
|
}
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-20 14:57:10 +00:00
|
|
|
|
/* Default: Fall back to the generic blt. Not an error, a TRACE is enough */
|
2007-02-15 02:02:39 +00:00
|
|
|
|
TRACE("Didn't find any usable render target setup for hw blit, falling back to software\n");
|
2006-04-14 17:15:46 +00:00
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-10 19:10:49 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_BltZ(IWineD3DSurfaceImpl *This, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, WINEDDBLTFX *DDBltFx)
|
|
|
|
|
{
|
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
2007-08-27 20:01:06 +00:00
|
|
|
|
float depth;
|
|
|
|
|
|
|
|
|
|
if (Flags & WINEDDBLT_DEPTHFILL) {
|
|
|
|
|
switch(This->resource.format) {
|
|
|
|
|
case WINED3DFMT_D16:
|
|
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x0000ffff;
|
|
|
|
|
break;
|
|
|
|
|
case WINED3DFMT_D15S1:
|
|
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x0000fffe;
|
|
|
|
|
break;
|
|
|
|
|
case WINED3DFMT_D24S8:
|
|
|
|
|
case WINED3DFMT_D24X8:
|
|
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x00ffffff;
|
|
|
|
|
break;
|
|
|
|
|
case WINED3DFMT_D32:
|
|
|
|
|
depth = (float) DDBltFx->u5.dwFillDepth / (float) 0xffffffff;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
depth = 0.0;
|
|
|
|
|
ERR("Unexpected format for depth fill: %s\n", debug_d3dformat(This->resource.format));
|
|
|
|
|
}
|
2007-05-10 19:10:49 +00:00
|
|
|
|
|
|
|
|
|
return IWineD3DDevice_Clear((IWineD3DDevice *) myDevice,
|
|
|
|
|
DestRect == NULL ? 0 : 1,
|
|
|
|
|
(WINED3DRECT *) DestRect,
|
|
|
|
|
WINED3DCLEAR_ZBUFFER,
|
|
|
|
|
0x00000000,
|
2007-08-27 20:01:06 +00:00
|
|
|
|
depth,
|
2007-05-10 19:10:49 +00:00
|
|
|
|
0x00000000);
|
2007-08-27 20:01:06 +00:00
|
|
|
|
}
|
2007-05-10 19:10:49 +00:00
|
|
|
|
|
|
|
|
|
FIXME("(%p): Unsupp depthstencil blit\n", This);
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-14 20:44:55 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_Blt(IWineD3DSurface *iface, RECT *DestRect, IWineD3DSurface *SrcSurface, RECT *SrcRect, DWORD Flags, WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter) {
|
2006-05-22 22:48:54 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
|
|
|
|
IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
|
2007-02-09 15:35:45 +00:00
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
2006-10-01 03:20:10 +00:00
|
|
|
|
TRACE("(%p)->(%p,%p,%p,%x,%p)\n", This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx);
|
2006-07-28 19:33:20 +00:00
|
|
|
|
TRACE("(%p): Usage is %s\n", This, debug_d3dusage(This->resource.usage));
|
2006-05-22 22:48:54 +00:00
|
|
|
|
|
2008-02-15 22:55:36 +00:00
|
|
|
|
if ( (This->Flags & SFLAG_LOCKED) || ((Src != NULL) && (Src->Flags & SFLAG_LOCKED)))
|
|
|
|
|
{
|
|
|
|
|
WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
|
|
|
|
|
return WINEDDERR_SURFACEBUSY;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-08 18:59:57 +00:00
|
|
|
|
/* Accessing the depth stencil is supposed to fail between a BeginScene and EndScene pair,
|
|
|
|
|
* except depth blits, which seem to work
|
|
|
|
|
*/
|
2007-05-10 19:10:49 +00:00
|
|
|
|
if(iface == myDevice->stencilBufferTarget || (SrcSurface && SrcSurface == myDevice->stencilBufferTarget)) {
|
2007-06-08 18:59:57 +00:00
|
|
|
|
if(myDevice->inScene && !(Flags & WINEDDBLT_DEPTHFILL)) {
|
2007-05-10 19:10:49 +00:00
|
|
|
|
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
} else if(IWineD3DSurfaceImpl_BltZ(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx) == WINED3D_OK) {
|
|
|
|
|
TRACE("Z Blit override handled the blit\n");
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
2007-02-09 15:35:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-05-22 22:48:54 +00:00
|
|
|
|
/* Special cases for RenderTargets */
|
|
|
|
|
if( (This->resource.usage & WINED3DUSAGE_RENDERTARGET) ||
|
|
|
|
|
( Src && (Src->resource.usage & WINED3DUSAGE_RENDERTARGET) )) {
|
2007-04-03 10:00:15 +00:00
|
|
|
|
if(IWineD3DSurfaceImpl_BltOverride(This, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter) == WINED3D_OK) return WINED3D_OK;
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For the rest call the X11 surface implementation.
|
|
|
|
|
* For RenderTargets this should be implemented OpenGL accelerated in BltOverride,
|
|
|
|
|
* other Blts are rather rare
|
|
|
|
|
*/
|
2007-09-17 14:03:21 +00:00
|
|
|
|
return IWineD3DBaseSurfaceImpl_Blt(iface, DestRect, SrcSurface, SrcRect, Flags, DDBltFx, Filter);
|
2006-05-22 22:48:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-17 15:25:55 +00:00
|
|
|
|
HRESULT WINAPI IWineD3DSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty, IWineD3DSurface *Source, RECT *rsrc, DWORD trans) {
|
2006-05-26 10:19:28 +00:00
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
|
|
|
|
IWineD3DSurfaceImpl *srcImpl = (IWineD3DSurfaceImpl *) Source;
|
2007-02-09 15:35:45 +00:00
|
|
|
|
IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
|
2006-10-01 03:20:10 +00:00
|
|
|
|
TRACE("(%p)->(%d, %d, %p, %p, %08x\n", iface, dstx, dsty, Source, rsrc, trans);
|
2006-05-26 10:19:28 +00:00
|
|
|
|
|
2008-02-15 22:58:38 +00:00
|
|
|
|
if ( (This->Flags & SFLAG_LOCKED) || ((srcImpl != NULL) && (srcImpl->Flags & SFLAG_LOCKED)))
|
|
|
|
|
{
|
|
|
|
|
WARN(" Surface is busy, returning DDERR_SURFACEBUSY\n");
|
|
|
|
|
return WINEDDERR_SURFACEBUSY;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-09 15:35:45 +00:00
|
|
|
|
if(myDevice->inScene &&
|
|
|
|
|
(iface == myDevice->stencilBufferTarget ||
|
|
|
|
|
(Source && Source == myDevice->stencilBufferTarget))) {
|
|
|
|
|
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-26 10:19:28 +00:00
|
|
|
|
/* Special cases for RenderTargets */
|
|
|
|
|
if( (This->resource.usage & WINED3DUSAGE_RENDERTARGET) ||
|
|
|
|
|
( srcImpl && (srcImpl->resource.usage & WINED3DUSAGE_RENDERTARGET) )) {
|
|
|
|
|
|
|
|
|
|
RECT SrcRect, DstRect;
|
2006-07-26 21:19:04 +00:00
|
|
|
|
DWORD Flags=0;
|
2006-05-26 10:19:28 +00:00
|
|
|
|
|
|
|
|
|
if(rsrc) {
|
|
|
|
|
SrcRect.left = rsrc->left;
|
|
|
|
|
SrcRect.top= rsrc->top;
|
|
|
|
|
SrcRect.bottom = rsrc->bottom;
|
|
|
|
|
SrcRect.right = rsrc->right;
|
|
|
|
|
} else {
|
|
|
|
|
SrcRect.left = 0;
|
|
|
|
|
SrcRect.top = 0;
|
|
|
|
|
SrcRect.right = srcImpl->currentDesc.Width;
|
|
|
|
|
SrcRect.bottom = srcImpl->currentDesc.Height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DstRect.left = dstx;
|
|
|
|
|
DstRect.top=dsty;
|
|
|
|
|
DstRect.right = dstx + SrcRect.right - SrcRect.left;
|
|
|
|
|
DstRect.bottom = dsty + SrcRect.bottom - SrcRect.top;
|
|
|
|
|
|
2006-09-28 19:03:22 +00:00
|
|
|
|
/* Convert BltFast flags into Btl ones because it is called from SurfaceImpl_Blt as well */
|
2007-04-14 20:44:55 +00:00
|
|
|
|
if(trans & WINEDDBLTFAST_SRCCOLORKEY)
|
|
|
|
|
Flags |= WINEDDBLT_KEYSRC;
|
|
|
|
|
if(trans & WINEDDBLTFAST_DESTCOLORKEY)
|
|
|
|
|
Flags |= WINEDDBLT_KEYDEST;
|
|
|
|
|
if(trans & WINEDDBLTFAST_WAIT)
|
|
|
|
|
Flags |= WINEDDBLT_WAIT;
|
|
|
|
|
if(trans & WINEDDBLTFAST_DONOTWAIT)
|
|
|
|
|
Flags |= WINEDDBLT_DONOTWAIT;
|
2006-07-26 21:19:04 +00:00
|
|
|
|
|
2007-05-10 15:42:41 +00:00
|
|
|
|
if(IWineD3DSurfaceImpl_BltOverride(This, &DstRect, Source, &SrcRect, Flags, NULL, WINED3DTEXF_POINT) == WINED3D_OK) return WINED3D_OK;
|
2006-05-26 10:19:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-17 14:03:21 +00:00
|
|
|
|
return IWineD3DBaseSurfaceImpl_BltFast(iface, dstx, dsty, Source, rsrc, trans);
|
2006-04-17 15:25:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 11:15:32 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_PrivateSetup(IWineD3DSurface *iface) {
|
2006-05-18 22:13:29 +00:00
|
|
|
|
/** Check against the maximum texture sizes supported by the video card **/
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
2007-07-16 18:42:16 +00:00
|
|
|
|
unsigned int pow2Width, pow2Height;
|
2007-07-27 11:22:54 +00:00
|
|
|
|
const GlPixelFormatDesc *glDesc;
|
|
|
|
|
|
2007-07-30 12:14:01 +00:00
|
|
|
|
getFormatDescEntry(This->resource.format, &GLINFO_LOCATION, &glDesc);
|
2007-07-27 11:22:54 +00:00
|
|
|
|
/* Setup some glformat defaults */
|
|
|
|
|
This->glDescription.glFormat = glDesc->glFormat;
|
|
|
|
|
This->glDescription.glFormatInternal = glDesc->glInternal;
|
|
|
|
|
This->glDescription.glType = glDesc->glType;
|
|
|
|
|
|
|
|
|
|
This->glDescription.textureName = 0;
|
|
|
|
|
This->glDescription.target = GL_TEXTURE_2D;
|
2007-07-16 18:42:16 +00:00
|
|
|
|
|
|
|
|
|
/* Non-power2 support */
|
|
|
|
|
if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
|
|
|
|
|
pow2Width = This->currentDesc.Width;
|
|
|
|
|
pow2Height = This->currentDesc.Height;
|
|
|
|
|
} else {
|
|
|
|
|
/* Find the nearest pow2 match */
|
|
|
|
|
pow2Width = pow2Height = 1;
|
|
|
|
|
while (pow2Width < This->currentDesc.Width) pow2Width <<= 1;
|
|
|
|
|
while (pow2Height < This->currentDesc.Height) pow2Height <<= 1;
|
|
|
|
|
}
|
|
|
|
|
This->pow2Width = pow2Width;
|
|
|
|
|
This->pow2Height = pow2Height;
|
|
|
|
|
|
|
|
|
|
if (pow2Width > This->currentDesc.Width || pow2Height > This->currentDesc.Height) {
|
|
|
|
|
WINED3DFORMAT Format = This->resource.format;
|
|
|
|
|
/** TODO: add support for non power two compressed textures **/
|
|
|
|
|
if (Format == WINED3DFMT_DXT1 || Format == WINED3DFMT_DXT2 || Format == WINED3DFMT_DXT3
|
|
|
|
|
|| Format == WINED3DFMT_DXT4 || Format == WINED3DFMT_DXT5) {
|
|
|
|
|
FIXME("(%p) Compressed non-power-two textures are not supported w(%d) h(%d)\n",
|
|
|
|
|
This, This->currentDesc.Width, This->currentDesc.Height);
|
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(pow2Width != This->currentDesc.Width ||
|
|
|
|
|
pow2Height != This->currentDesc.Height) {
|
|
|
|
|
This->Flags |= SFLAG_NONPOW2;
|
|
|
|
|
}
|
2006-05-18 22:13:29 +00:00
|
|
|
|
|
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
if ((This->pow2Width > GL_LIMITS(texture_size) || This->pow2Height > GL_LIMITS(texture_size)) && !(This->resource.usage & (WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL))) {
|
|
|
|
|
/* one of three options
|
|
|
|
|
1: Do the same as we do with nonpow 2 and scale the texture, (any texture ops would require the texture to be scaled which is potentially slow)
|
2007-06-05 22:21:08 +00:00
|
|
|
|
2: Set the texture to the maximum size (bad idea)
|
2006-05-18 22:13:29 +00:00
|
|
|
|
3: WARN and return WINED3DERR_NOTAVAILABLE;
|
|
|
|
|
4: Create the surface, but allow it to be used only for DirectDraw Blts. Some apps(e.g. Swat 3) create textures with a Height of 16 and a Width > 3000 and blt 16x16 letter areas from them to the render target.
|
|
|
|
|
*/
|
|
|
|
|
WARN("(%p) Creating an oversized surface\n", This);
|
|
|
|
|
This->Flags |= SFLAG_OVERSIZE;
|
|
|
|
|
|
|
|
|
|
/* This will be initialized on the first blt */
|
|
|
|
|
This->glRect.left = 0;
|
|
|
|
|
This->glRect.top = 0;
|
|
|
|
|
This->glRect.right = 0;
|
|
|
|
|
This->glRect.bottom = 0;
|
|
|
|
|
} else {
|
2008-01-21 21:29:03 +00:00
|
|
|
|
/* Check this after the oversize check - do not make an oversized surface a texture_rectangle one.
|
|
|
|
|
Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
|
|
|
|
|
is used in combination with texture uploads (RTL_READTEX/RTL_TEXTEX). The reason is that EXT_PALETTED_TEXTURE
|
|
|
|
|
doesn't work in combination with ARB_TEXTURE_RECTANGLE.
|
|
|
|
|
*/
|
|
|
|
|
if(This->Flags & SFLAG_NONPOW2 && GL_SUPPORT(ARB_TEXTURE_RECTANGLE) &&
|
|
|
|
|
!((This->resource.format == WINED3DFMT_P8) && GL_SUPPORT(EXT_PALETTED_TEXTURE) && (wined3d_settings.rendertargetlock_mode == RTL_READTEX || wined3d_settings.rendertargetlock_mode == RTL_TEXTEX)))
|
|
|
|
|
{
|
2007-11-28 19:35:04 +00:00
|
|
|
|
This->glDescription.target = GL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
|
This->pow2Width = This->currentDesc.Width;
|
|
|
|
|
This->pow2Height = This->currentDesc.Height;
|
|
|
|
|
This->Flags &= ~SFLAG_NONPOW2;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-18 22:13:29 +00:00
|
|
|
|
/* No oversize, gl rect is the full texture size */
|
|
|
|
|
This->Flags &= ~SFLAG_OVERSIZE;
|
|
|
|
|
This->glRect.left = 0;
|
|
|
|
|
This->glRect.top = 0;
|
|
|
|
|
This->glRect.right = This->pow2Width;
|
|
|
|
|
This->glRect.bottom = This->pow2Height;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-30 19:22:33 +00:00
|
|
|
|
if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
|
|
|
|
switch(wined3d_settings.offscreen_rendering_mode) {
|
|
|
|
|
case ORM_FBO: This->get_drawable_size = get_drawable_size_fbo; break;
|
|
|
|
|
case ORM_PBUFFER: This->get_drawable_size = get_drawable_size_pbuffer; break;
|
|
|
|
|
case ORM_BACKBUFFER: This->get_drawable_size = get_drawable_size_backbuffer; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-08 21:33:48 +00:00
|
|
|
|
This->Flags |= SFLAG_INSYSMEM;
|
|
|
|
|
|
2006-04-17 15:25:55 +00:00
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-09 20:17:59 +00:00
|
|
|
|
static void WINAPI IWineD3DSurfaceImpl_ModifyLocation(IWineD3DSurface *iface, DWORD flag, BOOL persistent) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
2007-11-03 15:41:13 +00:00
|
|
|
|
IWineD3DBaseTexture *texture;
|
2007-10-09 20:17:59 +00:00
|
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s, %s)\n", iface,
|
|
|
|
|
flag == SFLAG_INSYSMEM ? "SFLAG_INSYSMEM" : flag == SFLAG_INDRAWABLE ? "SFLAG_INDRAWABLE" : "SFLAG_INTEXTURE",
|
|
|
|
|
persistent ? "TRUE" : "FALSE");
|
|
|
|
|
|
2008-01-02 18:53:13 +00:00
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
|
|
|
|
|
IWineD3DSwapChain *swapchain = NULL;
|
|
|
|
|
|
|
|
|
|
if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
|
|
|
|
|
TRACE("Surface %p is an onscreen surface\n", iface);
|
|
|
|
|
|
|
|
|
|
IWineD3DSwapChain_Release(swapchain);
|
|
|
|
|
} else {
|
|
|
|
|
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
|
|
|
|
|
if (flag & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE)) flag |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-09 20:17:59 +00:00
|
|
|
|
if(persistent) {
|
2007-11-03 15:41:13 +00:00
|
|
|
|
if((This->Flags & SFLAG_INTEXTURE) && !(flag & SFLAG_INTEXTURE)) {
|
|
|
|
|
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&texture) == WINED3D_OK) {
|
|
|
|
|
TRACE("Passing to container\n");
|
|
|
|
|
IWineD3DBaseTexture_SetDirty(texture, TRUE);
|
|
|
|
|
IWineD3DBaseTexture_Release(texture);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-09 20:17:59 +00:00
|
|
|
|
This->Flags &= ~SFLAG_LOCATIONS;
|
|
|
|
|
This->Flags |= flag;
|
|
|
|
|
} else {
|
2007-11-03 15:41:13 +00:00
|
|
|
|
if((This->Flags & SFLAG_INTEXTURE) && (flag & SFLAG_INTEXTURE)) {
|
|
|
|
|
if (IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&texture) == WINED3D_OK) {
|
|
|
|
|
TRACE("Passing to container\n");
|
|
|
|
|
IWineD3DBaseTexture_SetDirty(texture, TRUE);
|
|
|
|
|
IWineD3DBaseTexture_Release(texture);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-09 20:17:59 +00:00
|
|
|
|
This->Flags &= ~flag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-01 00:38:50 +00:00
|
|
|
|
struct coords {
|
2008-01-12 17:57:08 +00:00
|
|
|
|
GLfloat x, y, z;
|
2007-11-01 00:38:50 +00:00
|
|
|
|
};
|
|
|
|
|
|
2007-11-01 00:40:44 +00:00
|
|
|
|
static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT *rect_in) {
|
2007-11-01 00:38:50 +00:00
|
|
|
|
struct coords coords[4];
|
2007-11-01 00:40:44 +00:00
|
|
|
|
RECT rect;
|
2007-11-08 22:08:07 +00:00
|
|
|
|
IWineD3DSwapChain *swapchain = NULL;
|
2007-11-27 22:43:11 +00:00
|
|
|
|
IWineD3DBaseTexture *texture = NULL;
|
2007-11-08 22:08:07 +00:00
|
|
|
|
HRESULT hr;
|
2007-11-01 00:38:50 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
|
|
|
|
|
2007-11-01 00:40:44 +00:00
|
|
|
|
if(rect_in) {
|
|
|
|
|
rect = *rect_in;
|
|
|
|
|
} else {
|
|
|
|
|
rect.left = 0;
|
|
|
|
|
rect.top = 0;
|
|
|
|
|
rect.right = This->currentDesc.Width;
|
|
|
|
|
rect.bottom = This->currentDesc.Height;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-01 00:38:50 +00:00
|
|
|
|
ActivateContext(device, device->render_targets[0], CTXUSAGE_BLIT);
|
|
|
|
|
ENTER_GL();
|
|
|
|
|
|
2007-11-27 21:25:07 +00:00
|
|
|
|
if(This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB) {
|
|
|
|
|
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
|
checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
|
|
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, This->glDescription.textureName);
|
|
|
|
|
checkGLcall("GL_TEXTURE_RECTANGLE_ARB, This->glDescription.textureName)");
|
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
|
|
|
|
|
coords[0].x = rect.left;
|
|
|
|
|
coords[0].z = 0;
|
|
|
|
|
|
|
|
|
|
coords[1].x = rect.left;
|
|
|
|
|
coords[1].z = 0;
|
|
|
|
|
|
|
|
|
|
coords[2].x = rect.right;
|
|
|
|
|
coords[2].z = 0;
|
|
|
|
|
|
|
|
|
|
coords[3].x = rect.right;
|
|
|
|
|
coords[3].z = 0;
|
|
|
|
|
|
|
|
|
|
coords[0].y = rect.top;
|
|
|
|
|
coords[1].y = rect.bottom;
|
|
|
|
|
coords[2].y = rect.bottom;
|
|
|
|
|
coords[3].y = rect.top;
|
|
|
|
|
} else if(This->glDescription.target == GL_TEXTURE_2D) {
|
2007-11-26 20:43:08 +00:00
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
checkGLcall("glEnable(GL_TEXTURE_2D)");
|
2007-11-01 00:38:50 +00:00
|
|
|
|
glBindTexture(GL_TEXTURE_2D, This->glDescription.textureName);
|
|
|
|
|
checkGLcall("GL_TEXTURE_2D, This->glDescription.textureName)");
|
2007-11-01 00:40:44 +00:00
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
coords[0].x = (float)rect.left / This->pow2Width;
|
2007-11-01 00:40:44 +00:00
|
|
|
|
coords[0].z = 0;
|
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
coords[1].x = (float)rect.left / This->pow2Width;
|
2007-11-01 00:40:44 +00:00
|
|
|
|
coords[1].z = 0;
|
2007-11-01 00:38:50 +00:00
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
coords[2].x = (float)rect.right / This->pow2Width;
|
2007-11-01 00:40:44 +00:00
|
|
|
|
coords[2].z = 0;
|
2007-11-01 00:38:50 +00:00
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
coords[3].x = (float)rect.right / This->pow2Width;
|
2007-11-01 00:40:44 +00:00
|
|
|
|
coords[3].z = 0;
|
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
coords[0].y = (float)rect.top / This->pow2Height;
|
|
|
|
|
coords[1].y = (float)rect.bottom / This->pow2Height;
|
|
|
|
|
coords[2].y = (float)rect.bottom / This->pow2Height;
|
|
|
|
|
coords[3].y = (float)rect.top / This->pow2Height;
|
2007-11-01 00:38:50 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* Must be a cube map */
|
|
|
|
|
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
|
checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->glDescription.textureName);
|
|
|
|
|
checkGLcall("GL_TEXTURE_CUBE_MAP_ARB, This->glDescription.textureName)");
|
2007-11-01 00:40:44 +00:00
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
|
|
|
|
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
checkGLcall("glTexParameteri");
|
2007-11-01 00:38:50 +00:00
|
|
|
|
|
|
|
|
|
switch(This->glDescription.target) {
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
|
coords[0].x = 1; coords[0].y = -1; coords[0].z = 1;
|
|
|
|
|
coords[1].x = 1; coords[1].y = 1; coords[1].z = 1;
|
|
|
|
|
coords[2].x = 1; coords[2].y = 1; coords[2].z = -1;
|
|
|
|
|
coords[3].x = 1; coords[3].y = -1; coords[3].z = -1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
|
coords[0].x = -1; coords[0].y = -1; coords[0].z = 1;
|
|
|
|
|
coords[1].x = -1; coords[1].y = 1; coords[1].z = 1;
|
|
|
|
|
coords[2].x = -1; coords[2].y = 1; coords[2].z = -1;
|
|
|
|
|
coords[3].x = -1; coords[3].y = -1; coords[3].z = -1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
|
coords[0].x = -1; coords[0].y = 1; coords[0].z = 1;
|
|
|
|
|
coords[1].x = 1; coords[1].y = 1; coords[1].z = 1;
|
|
|
|
|
coords[2].x = 1; coords[2].y = 1; coords[2].z = -1;
|
|
|
|
|
coords[3].x = -1; coords[3].y = 1; coords[3].z = -1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
|
coords[0].x = -1; coords[0].y = -1; coords[0].z = 1;
|
|
|
|
|
coords[1].x = 1; coords[1].y = -1; coords[1].z = 1;
|
|
|
|
|
coords[2].x = 1; coords[2].y = -1; coords[2].z = -1;
|
|
|
|
|
coords[3].x = -1; coords[3].y = -1; coords[3].z = -1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
|
coords[0].x = -1; coords[0].y = -1; coords[0].z = 1;
|
|
|
|
|
coords[1].x = 1; coords[1].y = -1; coords[1].z = 1;
|
|
|
|
|
coords[2].x = 1; coords[2].y = -1; coords[2].z = 1;
|
|
|
|
|
coords[3].x = -1; coords[3].y = -1; coords[3].z = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
|
coords[0].x = -1; coords[0].y = -1; coords[0].z = -1;
|
|
|
|
|
coords[1].x = 1; coords[1].y = -1; coords[1].z = -1;
|
|
|
|
|
coords[2].x = 1; coords[2].y = -1; coords[2].z = -1;
|
|
|
|
|
coords[3].x = -1; coords[3].y = -1; coords[3].z = -1;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
ERR("Unexpected texture target\n");
|
|
|
|
|
LEAVE_GL();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
2008-01-12 17:57:08 +00:00
|
|
|
|
glTexCoord3fv(&coords[0].x);
|
2007-11-01 00:40:44 +00:00
|
|
|
|
glVertex2i(rect.left, device->render_offscreen ? rect.bottom : rect.top);
|
2007-11-01 00:38:50 +00:00
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
glTexCoord3fv(&coords[1].x);
|
|
|
|
|
glVertex2i(rect.left, device->render_offscreen ? rect.top : rect.bottom);
|
2007-11-01 00:38:50 +00:00
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
glTexCoord3fv(&coords[2].x);
|
2007-11-01 00:40:44 +00:00
|
|
|
|
glVertex2i(rect.right, device->render_offscreen ? rect.top : rect.bottom);
|
2007-11-01 00:38:50 +00:00
|
|
|
|
|
2008-01-12 17:57:08 +00:00
|
|
|
|
glTexCoord3fv(&coords[3].x);
|
2007-11-01 00:40:44 +00:00
|
|
|
|
glVertex2i(rect.right, device->render_offscreen ? rect.bottom : rect.top);
|
2007-11-01 00:38:50 +00:00
|
|
|
|
glEnd();
|
|
|
|
|
checkGLcall("glEnd");
|
|
|
|
|
|
|
|
|
|
if(This->glDescription.target != GL_TEXTURE_2D) {
|
|
|
|
|
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
|
|
|
|
|
checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
|
2007-11-26 20:43:08 +00:00
|
|
|
|
} else {
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
checkGLcall("glDisable(GL_TEXTURE_2D)");
|
2007-11-01 00:38:50 +00:00
|
|
|
|
}
|
2007-11-08 22:08:07 +00:00
|
|
|
|
|
|
|
|
|
hr = IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DSwapChain, (void **) &swapchain);
|
|
|
|
|
if(hr == WINED3D_OK && swapchain) {
|
|
|
|
|
/* Make sure to flush the buffers. This is needed in apps like Red Alert II and Tiberian SUN that use multiple WGL contexts. */
|
|
|
|
|
if(((IWineD3DSwapChainImpl*)swapchain)->num_contexts >= 2)
|
|
|
|
|
glFlush();
|
|
|
|
|
|
|
|
|
|
IWineD3DSwapChain_Release(swapchain);
|
2007-11-27 22:43:11 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* We changed the filtering settings on the texture. Inform the container about this to get the filters
|
|
|
|
|
* reset properly next draw
|
|
|
|
|
*/
|
|
|
|
|
hr = IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DBaseTexture, (void **) &texture);
|
|
|
|
|
if(hr == WINED3D_OK && texture) {
|
|
|
|
|
((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
|
|
|
|
|
((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
|
|
|
|
|
((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
|
|
|
|
|
IWineD3DBaseTexture_Release(texture);
|
|
|
|
|
}
|
2007-11-08 22:08:07 +00:00
|
|
|
|
}
|
2007-11-01 00:38:50 +00:00
|
|
|
|
LEAVE_GL();
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-24 22:22:53 +00:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* IWineD3DSurface::LoadLocation
|
|
|
|
|
*
|
|
|
|
|
* Copies the current surface data from wherever it is to the requested
|
|
|
|
|
* location. The location is one of the surface flags, SFLAG_INSYSMEM,
|
|
|
|
|
* SFLAG_INTEXTURE and SFLAG_INDRAWABLE. When the surface is current in
|
2007-12-07 00:03:54 +00:00
|
|
|
|
* multiple locations, the gl texture is preferred over the drawable, which is
|
|
|
|
|
* preferred over system memory. The PBO counts as system memory. If rect is
|
|
|
|
|
* not NULL, only the specified rectangle is copied (only supported for
|
2007-09-24 22:22:53 +00:00
|
|
|
|
* sysmem<->drawable copies at the moment). If rect is NULL, the destination
|
|
|
|
|
* location is marked up to date after the copy.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* flag: Surface location flag to be updated
|
|
|
|
|
* rect: rectangle to be copied
|
|
|
|
|
*
|
|
|
|
|
* Returns:
|
|
|
|
|
* WINED3D_OK on success
|
|
|
|
|
* WINED3DERR_DEVICELOST on an internal error
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
2007-09-24 22:02:14 +00:00
|
|
|
|
static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
2007-10-13 10:54:10 +00:00
|
|
|
|
IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
2008-01-02 18:53:13 +00:00
|
|
|
|
IWineD3DSwapChain *swapchain = NULL;
|
2007-10-13 10:54:10 +00:00
|
|
|
|
GLenum format, internal, type;
|
|
|
|
|
CONVERT_TYPES convert;
|
|
|
|
|
int bpp;
|
|
|
|
|
int width, pitch, outpitch;
|
|
|
|
|
BYTE *mem;
|
2007-09-24 22:16:05 +00:00
|
|
|
|
|
2008-01-02 18:53:13 +00:00
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
|
|
|
|
|
if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
|
|
|
|
|
TRACE("Surface %p is an onscreen surface\n", iface);
|
|
|
|
|
|
|
|
|
|
IWineD3DSwapChain_Release(swapchain);
|
|
|
|
|
} else {
|
|
|
|
|
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets.
|
|
|
|
|
* Prefer SFLAG_INTEXTURE. */
|
|
|
|
|
if (flag == SFLAG_INDRAWABLE) flag = SFLAG_INTEXTURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-24 22:02:14 +00:00
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface,
|
|
|
|
|
flag == SFLAG_INSYSMEM ? "SFLAG_INSYSMEM" : flag == SFLAG_INDRAWABLE ? "SFLAG_INDRAWABLE" : "SFLAG_INTEXTURE",
|
|
|
|
|
rect);
|
|
|
|
|
if(rect) {
|
|
|
|
|
TRACE("Rectangle: (%d,%d)-(%d,%d)\n", rect->left, rect->top, rect->right, rect->bottom);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(This->Flags & flag) {
|
|
|
|
|
TRACE("Location already up to date\n");
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!(This->Flags & SFLAG_LOCATIONS)) {
|
|
|
|
|
ERR("Surface does not have any up to date location\n");
|
|
|
|
|
This->Flags |= SFLAG_LOST;
|
|
|
|
|
return WINED3DERR_DEVICELOST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(flag == SFLAG_INSYSMEM) {
|
2007-11-01 00:31:01 +00:00
|
|
|
|
surface_prepare_system_memory(This);
|
|
|
|
|
|
2007-09-24 22:02:14 +00:00
|
|
|
|
/* Download the surface to system memory */
|
|
|
|
|
if(This->Flags & SFLAG_INTEXTURE) {
|
2008-01-02 18:52:56 +00:00
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
surface_bind_and_dirtify(This);
|
|
|
|
|
|
2007-09-24 22:16:05 +00:00
|
|
|
|
surface_download_data(This);
|
2007-09-24 22:02:14 +00:00
|
|
|
|
} else {
|
2007-11-02 21:23:22 +00:00
|
|
|
|
read_from_framebuffer(This, rect,
|
2007-09-24 22:21:34 +00:00
|
|
|
|
This->resource.allocatedMemory,
|
2007-11-02 21:23:22 +00:00
|
|
|
|
IWineD3DSurface_GetPitch(iface));
|
2007-09-24 22:02:14 +00:00
|
|
|
|
}
|
|
|
|
|
} else if(flag == SFLAG_INDRAWABLE) {
|
|
|
|
|
if(This->Flags & SFLAG_INTEXTURE) {
|
2007-11-01 00:40:44 +00:00
|
|
|
|
surface_blt_to_drawable(This, rect);
|
2007-09-24 22:02:14 +00:00
|
|
|
|
} else {
|
2008-01-07 20:18:34 +00:00
|
|
|
|
d3dfmt_get_conv(This, TRUE /* We need color keying */, FALSE /* We won't use textures */, &format, &internal, &type, &convert, &bpp, This->srgb);
|
|
|
|
|
|
|
|
|
|
/* The width is in 'length' not in bytes */
|
|
|
|
|
width = This->currentDesc.Width;
|
|
|
|
|
pitch = IWineD3DSurface_GetPitch(iface);
|
|
|
|
|
|
|
|
|
|
if((convert != NO_CONVERSION) && This->resource.allocatedMemory) {
|
|
|
|
|
int height = This->currentDesc.Height;
|
|
|
|
|
|
|
|
|
|
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
|
|
|
|
|
outpitch = width * bpp;
|
|
|
|
|
outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
|
|
|
|
|
|
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
|
|
|
|
|
if(!mem) {
|
|
|
|
|
ERR("Out of memory %d, %d!\n", outpitch, height);
|
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
|
}
|
|
|
|
|
d3dfmt_convert_surface(This->resource.allocatedMemory, mem, pitch, width, height, outpitch, convert, This);
|
|
|
|
|
|
|
|
|
|
This->Flags |= SFLAG_CONVERTED;
|
|
|
|
|
} else {
|
|
|
|
|
This->Flags &= ~SFLAG_CONVERTED;
|
|
|
|
|
mem = This->resource.allocatedMemory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flush_to_framebuffer_drawpixels(This, format, type, bpp, mem);
|
|
|
|
|
|
|
|
|
|
/* Don't delete PBO memory */
|
|
|
|
|
if((mem != This->resource.allocatedMemory) && !(This->Flags & SFLAG_PBO))
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2007-09-24 22:02:14 +00:00
|
|
|
|
}
|
|
|
|
|
} else /* if(flag == SFLAG_INTEXTURE) */ {
|
2007-10-13 10:54:10 +00:00
|
|
|
|
if (This->Flags & SFLAG_INDRAWABLE) {
|
2008-02-10 21:20:15 +00:00
|
|
|
|
read_from_framebuffer_texture(This);
|
|
|
|
|
} else { /* Upload from system memory */
|
|
|
|
|
d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */, &format, &internal, &type, &convert, &bpp, This->srgb);
|
2007-10-13 10:54:10 +00:00
|
|
|
|
|
2008-02-10 21:20:15 +00:00
|
|
|
|
ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
|
|
|
|
surface_bind_and_dirtify(This);
|
2007-11-02 20:30:50 +00:00
|
|
|
|
ENTER_GL();
|
2007-10-13 10:54:10 +00:00
|
|
|
|
|
|
|
|
|
/* The only place where LoadTexture() might get called when isInDraw=1
|
|
|
|
|
* is ActivateContext where lastActiveRenderTarget is preloaded.
|
|
|
|
|
*/
|
|
|
|
|
if(iface == device->lastActiveRenderTarget && device->isInDraw)
|
|
|
|
|
ERR("Reading back render target but SFLAG_INDRAWABLE not set\n");
|
|
|
|
|
|
|
|
|
|
/* Otherwise: System memory copy must be most up to date */
|
|
|
|
|
|
|
|
|
|
if(This->CKeyFlags & WINEDDSD_CKSRCBLT) {
|
|
|
|
|
This->Flags |= SFLAG_GLCKEY;
|
|
|
|
|
This->glCKey = This->SrcBltCKey;
|
|
|
|
|
}
|
|
|
|
|
else This->Flags &= ~SFLAG_GLCKEY;
|
|
|
|
|
|
|
|
|
|
/* The width is in 'length' not in bytes */
|
|
|
|
|
width = This->currentDesc.Width;
|
|
|
|
|
pitch = IWineD3DSurface_GetPitch(iface);
|
|
|
|
|
|
|
|
|
|
if((convert != NO_CONVERSION) && This->resource.allocatedMemory) {
|
|
|
|
|
int height = This->currentDesc.Height;
|
|
|
|
|
|
|
|
|
|
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */
|
|
|
|
|
outpitch = width * bpp;
|
|
|
|
|
outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
|
|
|
|
|
|
|
|
|
|
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
|
|
|
|
|
if(!mem) {
|
|
|
|
|
ERR("Out of memory %d, %d!\n", outpitch, height);
|
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
|
}
|
|
|
|
|
d3dfmt_convert_surface(This->resource.allocatedMemory, mem, pitch, width, height, outpitch, convert, This);
|
|
|
|
|
|
|
|
|
|
This->Flags |= SFLAG_CONVERTED;
|
|
|
|
|
} else if( (This->resource.format == WINED3DFMT_P8) && (GL_SUPPORT(EXT_PALETTED_TEXTURE) || GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) ) {
|
|
|
|
|
d3dfmt_p8_upload_palette(iface, convert);
|
|
|
|
|
This->Flags &= ~SFLAG_CONVERTED;
|
|
|
|
|
mem = This->resource.allocatedMemory;
|
|
|
|
|
} else {
|
|
|
|
|
This->Flags &= ~SFLAG_CONVERTED;
|
|
|
|
|
mem = This->resource.allocatedMemory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make sure the correct pitch is used */
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
|
|
|
|
|
|
|
|
|
|
if ((This->Flags & SFLAG_NONPOW2) && !(This->Flags & SFLAG_OVERSIZE)) {
|
|
|
|
|
TRACE("non power of two support\n");
|
|
|
|
|
if(!(This->Flags & SFLAG_ALLOCATED)) {
|
|
|
|
|
surface_allocate_surface(This, internal, This->pow2Width, This->pow2Height, format, type);
|
|
|
|
|
}
|
|
|
|
|
if (mem || (This->Flags & SFLAG_PBO)) {
|
|
|
|
|
surface_upload_data(This, internal, This->currentDesc.Width, This->currentDesc.Height, format, type, mem);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* When making the realloc conditional, keep in mind that GL_APPLE_client_storage may be in use, and This->resource.allocatedMemory
|
|
|
|
|
* changed. So also keep track of memory changes. In this case the texture has to be reallocated
|
|
|
|
|
*/
|
|
|
|
|
if(!(This->Flags & SFLAG_ALLOCATED)) {
|
|
|
|
|
surface_allocate_surface(This, internal, This->glRect.right - This->glRect.left, This->glRect.bottom - This->glRect.top, format, type);
|
|
|
|
|
}
|
|
|
|
|
if (mem || (This->Flags & SFLAG_PBO)) {
|
|
|
|
|
surface_upload_data(This, internal, This->glRect.right - This->glRect.left, This->glRect.bottom - This->glRect.top, format, type, mem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Restore the default pitch */
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2008-02-10 21:20:15 +00:00
|
|
|
|
LEAVE_GL();
|
2007-10-13 10:54:10 +00:00
|
|
|
|
|
|
|
|
|
/* Don't delete PBO memory */
|
|
|
|
|
if((mem != This->resource.allocatedMemory) && !(This->Flags & SFLAG_PBO))
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
2007-09-24 22:02:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-24 22:21:34 +00:00
|
|
|
|
if(rect == NULL) {
|
|
|
|
|
This->Flags |= flag;
|
2008-01-02 18:53:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !swapchain
|
|
|
|
|
&& (This->Flags & (SFLAG_INTEXTURE | SFLAG_INDRAWABLE))) {
|
|
|
|
|
/* With ORM_FBO, SFLAG_INTEXTURE and SFLAG_INDRAWABLE are the same for offscreen targets. */
|
|
|
|
|
This->Flags |= (SFLAG_INTEXTURE | SFLAG_INDRAWABLE);
|
2007-09-24 22:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-24 22:02:14 +00:00
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-30 19:22:33 +00:00
|
|
|
|
HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container) {
|
|
|
|
|
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
|
|
|
|
IWineD3DSwapChain *swapchain = NULL;
|
|
|
|
|
|
|
|
|
|
/* Update the drawable size method */
|
|
|
|
|
if(container) {
|
|
|
|
|
IWineD3DBase_QueryInterface(container, &IID_IWineD3DSwapChain, (void **) &swapchain);
|
|
|
|
|
}
|
|
|
|
|
if(swapchain) {
|
|
|
|
|
This->get_drawable_size = get_drawable_size_swapchain;
|
|
|
|
|
IWineD3DSwapChain_Release(swapchain);
|
|
|
|
|
} else if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
|
|
|
|
switch(wined3d_settings.offscreen_rendering_mode) {
|
|
|
|
|
case ORM_FBO: This->get_drawable_size = get_drawable_size_fbo; break;
|
|
|
|
|
case ORM_PBUFFER: This->get_drawable_size = get_drawable_size_pbuffer; break;
|
|
|
|
|
case ORM_BACKBUFFER: This->get_drawable_size = get_drawable_size_backbuffer; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IWineD3DBaseSurfaceImpl_SetContainer(iface, container);
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-06 19:50:35 +00:00
|
|
|
|
const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl =
|
2005-01-09 17:37:02 +00:00
|
|
|
|
{
|
2005-03-14 10:12:52 +00:00
|
|
|
|
/* IUnknown */
|
2007-09-16 11:29:44 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_QueryInterface,
|
2007-09-16 11:42:18 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_AddRef,
|
2005-01-09 17:37:02 +00:00
|
|
|
|
IWineD3DSurfaceImpl_Release,
|
2005-03-29 19:01:00 +00:00
|
|
|
|
/* IWineD3DResource */
|
2007-09-16 11:42:18 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_GetParent,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetDevice,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPrivateData,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPrivateData,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_FreePrivateData,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPriority,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPriority,
|
2005-01-09 17:37:02 +00:00
|
|
|
|
IWineD3DSurfaceImpl_PreLoad,
|
2008-01-12 21:56:30 +00:00
|
|
|
|
IWineD3DSurfaceImpl_UnLoad,
|
2007-09-16 11:42:18 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_GetType,
|
2005-07-13 14:15:54 +00:00
|
|
|
|
/* IWineD3DSurface */
|
2007-09-16 12:03:39 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_GetContainer,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetDesc,
|
2005-01-09 17:37:02 +00:00
|
|
|
|
IWineD3DSurfaceImpl_LockRect,
|
|
|
|
|
IWineD3DSurfaceImpl_UnlockRect,
|
|
|
|
|
IWineD3DSurfaceImpl_GetDC,
|
|
|
|
|
IWineD3DSurfaceImpl_ReleaseDC,
|
2006-04-12 20:32:44 +00:00
|
|
|
|
IWineD3DSurfaceImpl_Flip,
|
2006-04-14 17:15:46 +00:00
|
|
|
|
IWineD3DSurfaceImpl_Blt,
|
2007-09-16 12:03:39 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_GetBltStatus,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetFlipStatus,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_IsLost,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_Restore,
|
2006-04-17 15:25:55 +00:00
|
|
|
|
IWineD3DSurfaceImpl_BltFast,
|
2007-09-16 14:27:58 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPalette,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_SetPalette,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_RealizePalette,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_SetColorKey,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetPitch,
|
2006-07-25 14:38:02 +00:00
|
|
|
|
IWineD3DSurfaceImpl_SetMem,
|
2007-09-16 14:27:58 +00:00
|
|
|
|
IWineD3DBaseSurfaceImpl_SetOverlayPosition,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetOverlayPosition,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_UpdateOverlay,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_SetClipper,
|
|
|
|
|
IWineD3DBaseSurfaceImpl_GetClipper,
|
2005-01-09 17:37:02 +00:00
|
|
|
|
/* Internal use: */
|
|
|
|
|
IWineD3DSurfaceImpl_AddDirtyRect,
|
|
|
|
|
IWineD3DSurfaceImpl_LoadTexture,
|
2007-11-15 13:38:34 +00:00
|
|
|
|
IWineD3DSurfaceImpl_BindTexture,
|
2005-03-14 10:12:52 +00:00
|
|
|
|
IWineD3DSurfaceImpl_SaveSnapshot,
|
2007-11-30 19:22:33 +00:00
|
|
|
|
IWineD3DSurfaceImpl_SetContainer,
|
2005-07-11 20:38:27 +00:00
|
|
|
|
IWineD3DSurfaceImpl_SetGlTextureDesc,
|
|
|
|
|
IWineD3DSurfaceImpl_GetGlDesc,
|
2005-11-02 20:01:54 +00:00
|
|
|
|
IWineD3DSurfaceImpl_GetData,
|
2006-04-17 15:25:55 +00:00
|
|
|
|
IWineD3DSurfaceImpl_SetFormat,
|
2007-10-09 20:17:59 +00:00
|
|
|
|
IWineD3DSurfaceImpl_PrivateSetup,
|
2007-09-24 22:02:14 +00:00
|
|
|
|
IWineD3DSurfaceImpl_ModifyLocation,
|
|
|
|
|
IWineD3DSurfaceImpl_LoadLocation
|
2005-01-09 17:37:02 +00:00
|
|
|
|
};
|