1999-01-03 17:00:19 +00:00
|
|
|
/* Direct3D Texture
|
2002-03-09 23:29:33 +00:00
|
|
|
* Copyright (c) 1998 Lionel ULMER
|
|
|
|
*
|
|
|
|
* This file contains the implementation of interface Direct3DTexture2.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
1999-01-03 17:00:19 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2001-10-14 16:18:52 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
1999-03-14 16:35:05 +00:00
|
|
|
#include "windef.h"
|
1999-01-03 17:00:19 +00:00
|
|
|
#include "winerror.h"
|
2002-12-05 20:33:07 +00:00
|
|
|
#include "objbase.h"
|
1999-01-03 17:00:19 +00:00
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2000-04-09 14:30:50 +00:00
|
|
|
#include "mesa_private.h"
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
1999-01-03 17:00:19 +00:00
|
|
|
|
1999-01-23 12:32:46 +00:00
|
|
|
/* Define this if you want to save to a file all the textures used by a game
|
|
|
|
(can be funny to see how they managed to cram all the pictures in
|
|
|
|
texture memory) */
|
|
|
|
#undef TEXTURE_SNOOP
|
|
|
|
|
1999-04-06 07:10:48 +00:00
|
|
|
#ifdef TEXTURE_SNOOP
|
2000-02-12 13:20:20 +00:00
|
|
|
#include <stdio.h>
|
2002-05-31 23:06:46 +00:00
|
|
|
|
1999-04-06 07:10:48 +00:00
|
|
|
#define SNOOP_PALETTED() \
|
|
|
|
{ \
|
|
|
|
FILE *f; \
|
|
|
|
char buf[32]; \
|
|
|
|
int x, y; \
|
|
|
|
\
|
2002-11-27 21:38:28 +00:00
|
|
|
sprintf(buf, "%ld.pnm", glThis->tex_name); \
|
1999-04-06 07:10:48 +00:00
|
|
|
f = fopen(buf, "wb"); \
|
|
|
|
fprintf(f, "P6\n%ld %ld\n255\n", src_d->dwWidth, src_d->dwHeight); \
|
|
|
|
for (y = 0; y < src_d->dwHeight; y++) { \
|
|
|
|
for (x = 0; x < src_d->dwWidth; x++) { \
|
2002-11-27 21:38:28 +00:00
|
|
|
unsigned char c = ((unsigned char *) src_d->lpSurface)[y * src_d->dwWidth + x]; \
|
1999-04-06 07:10:48 +00:00
|
|
|
fputc(table[c][0], f); \
|
|
|
|
fputc(table[c][1], f); \
|
|
|
|
fputc(table[c][2], f); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
fclose(f); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SNOOP_5650() \
|
|
|
|
{ \
|
|
|
|
FILE *f; \
|
|
|
|
char buf[32]; \
|
|
|
|
int x, y; \
|
|
|
|
\
|
2002-11-27 21:38:28 +00:00
|
|
|
sprintf(buf, "%ld.pnm", glThis->tex_name); \
|
1999-04-06 07:10:48 +00:00
|
|
|
f = fopen(buf, "wb"); \
|
|
|
|
fprintf(f, "P6\n%ld %ld\n255\n", src_d->dwWidth, src_d->dwHeight); \
|
|
|
|
for (y = 0; y < src_d->dwHeight; y++) { \
|
|
|
|
for (x = 0; x < src_d->dwWidth; x++) { \
|
2002-11-27 21:38:28 +00:00
|
|
|
unsigned short c = ((unsigned short *) src_d->lpSurface)[y * src_d->dwWidth + x]; \
|
1999-04-06 07:10:48 +00:00
|
|
|
fputc((c & 0xF800) >> 8, f); \
|
|
|
|
fputc((c & 0x07E0) >> 3, f); \
|
|
|
|
fputc((c & 0x001F) << 3, f); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
fclose(f); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SNOOP_5551() \
|
|
|
|
{ \
|
|
|
|
FILE *f; \
|
|
|
|
char buf[32]; \
|
|
|
|
int x, y; \
|
|
|
|
\
|
2002-11-27 21:38:28 +00:00
|
|
|
sprintf(buf, "%ld.pnm", glThis->tex_name); \
|
1999-04-06 07:10:48 +00:00
|
|
|
f = fopen(buf, "wb"); \
|
|
|
|
fprintf(f, "P6\n%ld %ld\n255\n", src_d->dwWidth, src_d->dwHeight); \
|
|
|
|
for (y = 0; y < src_d->dwHeight; y++) { \
|
|
|
|
for (x = 0; x < src_d->dwWidth; x++) { \
|
2002-11-27 21:38:28 +00:00
|
|
|
unsigned short c = ((unsigned short *) src_d->lpSurface)[y * src_d->dwWidth + x]; \
|
1999-04-06 07:10:48 +00:00
|
|
|
fputc((c & 0xF800) >> 8, f); \
|
|
|
|
fputc((c & 0x07C0) >> 3, f); \
|
|
|
|
fputc((c & 0x003E) << 2, f); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
fclose(f); \
|
|
|
|
}
|
2002-11-27 21:38:28 +00:00
|
|
|
|
|
|
|
#define SNOOP_1555() \
|
|
|
|
{ \
|
|
|
|
FILE *f; \
|
|
|
|
char buf[32]; \
|
|
|
|
int x, y; \
|
|
|
|
\
|
|
|
|
sprintf(buf, "%ld.pnm", glThis->tex_name); \
|
|
|
|
f = fopen(buf, "wb"); \
|
|
|
|
fprintf(f, "P6\n%ld %ld\n255\n", src_d->dwWidth, src_d->dwHeight); \
|
|
|
|
for (y = 0; y < src_d->dwHeight; y++) { \
|
|
|
|
for (x = 0; x < src_d->dwWidth; x++) { \
|
|
|
|
unsigned short c = ((unsigned short *) src_d->lpSurface)[y * src_d->dwWidth + x]; \
|
|
|
|
fputc((c & 0x7C00) >> 7, f); \
|
|
|
|
fputc((c & 0x03E0) >> 2, f); \
|
|
|
|
fputc((c & 0x001F) << 3, f); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
fclose(f); \
|
|
|
|
}
|
1999-04-06 07:10:48 +00:00
|
|
|
#else
|
|
|
|
#define SNOOP_PALETTED()
|
|
|
|
#define SNOOP_5650()
|
|
|
|
#define SNOOP_5551()
|
2002-11-27 21:38:28 +00:00
|
|
|
#define SNOOP_1555()
|
1999-04-06 07:10:48 +00:00
|
|
|
#endif
|
|
|
|
|
1999-01-03 17:00:19 +00:00
|
|
|
/*******************************************************************************
|
2002-11-21 21:04:16 +00:00
|
|
|
* IDirectSurface callback methods
|
1999-01-03 17:00:19 +00:00
|
|
|
*/
|
2002-12-15 01:17:59 +00:00
|
|
|
HRESULT WINAPI gltex_setcolorkey_cb(IDirectDrawSurfaceImpl *texture, DWORD dwFlags, LPDDCOLORKEY ckey )
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
DDSURFACEDESC *tex_d;
|
|
|
|
GLuint current_texture;
|
2002-12-15 01:17:59 +00:00
|
|
|
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) texture->tex_private;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
TRACE("(%p) : colorkey callback\n", texture);
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
/* Get the texture description */
|
2002-12-15 01:17:59 +00:00
|
|
|
tex_d = (DDSURFACEDESC *)&(texture->surface_desc);
|
2000-07-16 14:40:35 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
/* Now, save the current texture */
|
|
|
|
ENTER_GL();
|
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
2002-12-15 01:17:59 +00:00
|
|
|
if (glThis->tex_name == 0) ERR("Unbound GL texture !!!\n");
|
2002-11-21 21:04:16 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, glThis->tex_name);
|
|
|
|
|
|
|
|
if (tex_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
|
|
|
|
FIXME("Todo Paletted\n");
|
|
|
|
} else if (tex_d->ddpfPixelFormat.dwFlags & DDPF_RGB) {
|
|
|
|
if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 8) {
|
|
|
|
FIXME("Todo 3_3_2_0\n");
|
|
|
|
} else if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 16) {
|
|
|
|
if (tex_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000000) {
|
|
|
|
/* Now transform the 5_6_5 into a 5_5_5_1 surface to support color keying */
|
|
|
|
unsigned short *dest = (unsigned short *) HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
tex_d->u1.lPitch * tex_d->dwHeight);
|
|
|
|
unsigned short *src = (unsigned short *) tex_d->lpSurface;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
for (y = 0; y < tex_d->dwHeight; y++) {
|
|
|
|
for (x = 0; x < tex_d->dwWidth; x++) {
|
|
|
|
unsigned short cpixel = src[x + y * tex_d->dwWidth];
|
|
|
|
|
|
|
|
if ((dwFlags & DDCKEY_SRCBLT) &&
|
|
|
|
(cpixel >= ckey->dwColorSpaceLowValue) &&
|
|
|
|
(cpixel <= ckey->dwColorSpaceHighValue)) /* No alpha bit => this pixel is transparent */
|
|
|
|
dest[x + y * tex_d->dwWidth] = (cpixel & ~0x003F) | ((cpixel & 0x001F) << 1) | 0x0000;
|
|
|
|
else /* Alpha bit is set => this pixel will be seen */
|
|
|
|
dest[x + y * tex_d->dwWidth] = (cpixel & ~0x003F) | ((cpixel & 0x001F) << 1) | 0x0001;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
tex_d->dwWidth, tex_d->dwHeight,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_5_5_5_1,
|
|
|
|
dest);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
/* Frees the temporary surface */
|
|
|
|
HeapFree(GetProcessHeap(),0,dest);
|
|
|
|
} else if (tex_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000001) {
|
|
|
|
FIXME("Todo 5_5_5_1\n");
|
|
|
|
} else if (tex_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000000F) {
|
|
|
|
FIXME("Todo 4_4_4_4\n");
|
|
|
|
} else {
|
|
|
|
ERR("Unhandled texture format (bad Aplha channel for a 16 bit texture)\n");
|
|
|
|
}
|
|
|
|
} else if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 24) {
|
|
|
|
FIXME("Todo 8_8_8_0\n");
|
|
|
|
} else if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 32) {
|
|
|
|
FIXME("Todo 8_8_8_8\n");
|
|
|
|
} else {
|
|
|
|
ERR("Unhandled texture format (bad RGB count)\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("Unhandled texture format (neither RGB nor INDEX)\n");
|
|
|
|
}
|
2002-12-15 01:17:59 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, current_texture);
|
2002-11-21 21:04:16 +00:00
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
return DD_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
static void
|
|
|
|
gltex_upload_texture(IDirectDrawSurfaceImpl *This, BOOLEAN init_upload) {
|
|
|
|
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
|
|
|
|
GLuint current_texture;
|
|
|
|
#if 0
|
|
|
|
static BOOL color_table_queried = FALSE;
|
|
|
|
#endif
|
|
|
|
void (*ptr_ColorTableEXT) (GLenum target, GLenum internalformat,
|
|
|
|
GLsizei width, GLenum format, GLenum type, const GLvoid *table) = NULL;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
DDSURFACEDESC *src_d = (DDSURFACEDESC *)&(This->surface_desc);
|
2000-07-16 14:40:35 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
TRACE(" uploading texture to GL id %d (initial = %d).\n", glThis->tex_name, init_upload);
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, glThis->tex_name);
|
1999-04-06 07:10:48 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
if (src_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
|
|
|
|
/* ****************
|
|
|
|
Paletted Texture
|
|
|
|
**************** */
|
|
|
|
IDirectDrawPaletteImpl* pal = This->palette;
|
|
|
|
BYTE table[256][4];
|
|
|
|
int i;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
#if 0
|
|
|
|
if (color_table_queried == FALSE) {
|
|
|
|
ptr_ColorTableEXT =
|
|
|
|
((Mesa_DeviceCapabilities *) ((x11_dd_private *) This->surface->s.ddraw->d->private)->device_capabilities)->ptr_ColorTableEXT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pal == NULL) {
|
|
|
|
ERR("Palettized texture Loading with a NULL palette !\n");
|
|
|
|
LEAVE_GL();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* 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;
|
|
|
|
if ((src_d->dwFlags & DDSD_CKSRCBLT) &&
|
|
|
|
(i >= src_d->ddckCKSrcBlt.dwColorSpaceLowValue) &&
|
|
|
|
(i <= src_d->ddckCKSrcBlt.dwColorSpaceHighValue))
|
|
|
|
table[i][3] = 0x00;
|
|
|
|
else
|
|
|
|
table[i][3] = 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Texture snooping */
|
|
|
|
SNOOP_PALETTED();
|
|
|
|
|
|
|
|
if (ptr_ColorTableEXT != NULL) {
|
|
|
|
/* use Paletted Texture Extension */
|
|
|
|
ptr_ColorTableEXT(GL_TEXTURE_2D, /* target */
|
|
|
|
GL_RGBA, /* internal format */
|
|
|
|
256, /* table size */
|
|
|
|
GL_RGBA, /* table format */
|
|
|
|
GL_UNSIGNED_BYTE, /* table type */
|
|
|
|
table); /* the color table */
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, /* target */
|
|
|
|
glThis->mipmap_level, /* level */
|
|
|
|
GL_COLOR_INDEX8_EXT, /* internal format */
|
|
|
|
src_d->dwWidth, src_d->dwHeight, /* width, height */
|
|
|
|
0, /* border */
|
|
|
|
GL_COLOR_INDEX, /* texture format */
|
|
|
|
GL_UNSIGNED_BYTE, /* texture type */
|
|
|
|
src_d->lpSurface); /* the texture */
|
|
|
|
} else {
|
|
|
|
DWORD *surface = (DWORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));
|
|
|
|
DWORD i;
|
|
|
|
BYTE *src = (BYTE *) src_d->lpSurface, *dst = (BYTE *) surface;
|
|
|
|
|
|
|
|
for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
|
|
|
|
BYTE color = *src++;
|
|
|
|
*dst++ = table[color][0];
|
|
|
|
*dst++ = table[color][1];
|
|
|
|
*dst++ = table[color][2];
|
|
|
|
*dst++ = table[color][3];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGBA,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
surface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
surface);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, surface);
|
|
|
|
}
|
|
|
|
} else if (src_d->ddpfPixelFormat.dwFlags & DDPF_RGB) {
|
|
|
|
/* ************
|
|
|
|
RGB Textures
|
|
|
|
************ */
|
|
|
|
if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 8) {
|
|
|
|
/* **********************
|
|
|
|
GL_UNSIGNED_BYTE_3_3_2
|
|
|
|
********************** */
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGB,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGB,
|
|
|
|
GL_UNSIGNED_BYTE_3_3_2,
|
|
|
|
src_d->lpSurface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGB,
|
|
|
|
GL_UNSIGNED_BYTE_3_3_2,
|
|
|
|
src_d->lpSurface);
|
|
|
|
} else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 16) {
|
|
|
|
if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000000) {
|
|
|
|
/* Texture snooping */
|
|
|
|
SNOOP_5650();
|
|
|
|
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGB,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGB,
|
|
|
|
GL_UNSIGNED_SHORT_5_6_5,
|
|
|
|
src_d->lpSurface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGB,
|
|
|
|
GL_UNSIGNED_SHORT_5_6_5,
|
|
|
|
src_d->lpSurface);
|
|
|
|
|
|
|
|
} else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000001) {
|
|
|
|
/* Texture snooping */
|
|
|
|
SNOOP_5551();
|
|
|
|
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGBA,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_5_5_5_1,
|
|
|
|
src_d->lpSurface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_5_5_5_1,
|
|
|
|
src_d->lpSurface);
|
|
|
|
} else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000000F) {
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGBA,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_4_4_4_4,
|
|
|
|
src_d->lpSurface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_4_4_4_4,
|
|
|
|
src_d->lpSurface);
|
|
|
|
} else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00008000) {
|
|
|
|
/* Converting the 1555 format in 5551 packed */
|
|
|
|
WORD *surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
|
|
|
|
DWORD i;
|
|
|
|
WORD *src = (WORD *) src_d->lpSurface, *dst = surface;
|
|
|
|
|
|
|
|
for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
|
|
|
|
*dst++ = (((*src & 0x8000) >> 15) |
|
|
|
|
((*src & 0x7FFF) << 1));
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
SNOOP_1555();
|
|
|
|
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGBA,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_5_5_5_1,
|
|
|
|
surface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_SHORT_5_5_5_1,
|
|
|
|
surface);
|
1999-04-06 07:10:48 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, surface);
|
|
|
|
} else {
|
|
|
|
ERR("Unhandled texture format (bad Aplha channel for a 16 bit texture)\n");
|
|
|
|
}
|
|
|
|
} else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 24) {
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGB,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGB,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
src_d->lpSurface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGB,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
src_d->lpSurface);
|
|
|
|
} else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 32) {
|
|
|
|
if (init_upload)
|
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
GL_RGBA,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
0,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
src_d->lpSurface);
|
|
|
|
else
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
glThis->mipmap_level,
|
|
|
|
0, 0,
|
|
|
|
src_d->dwWidth, src_d->dwHeight,
|
|
|
|
GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
src_d->lpSurface);
|
|
|
|
} else {
|
|
|
|
ERR("Unhandled texture format (bad RGB count)\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR("Unhandled texture format (neither RGB nor INDEX)\n");
|
|
|
|
}
|
|
|
|
glBindTexture(GL_TEXTURE_2D, current_texture);
|
1999-04-06 07:10:48 +00:00
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DTextureImpl_1_Initialize(LPDIRECT3DTEXTURE iface,
|
|
|
|
LPDIRECT3DDEVICE lpDirect3DDevice,
|
|
|
|
LPDIRECTDRAWSURFACE lpDDSurface)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture, iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
FIXME("(%p/%p)->(%p,%p) no-op...\n", This, iface, lpDirect3DDevice, lpDDSurface);
|
|
|
|
return DD_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DTextureImpl_2_1T_PaletteChanged(LPDIRECT3DTEXTURE2 iface,
|
|
|
|
DWORD dwStart,
|
|
|
|
DWORD dwCount)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
FIXME("(%p/%p)->(%08lx,%08lx): stub!\n", This, iface, dwStart, dwCount);
|
|
|
|
return DD_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DTextureImpl_1_Unload(LPDIRECT3DTEXTURE iface)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture, iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
FIXME("(%p/%p)->(): stub!\n", This, iface);
|
|
|
|
return DD_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DTextureImpl_2_1T_GetHandle(LPDIRECT3DTEXTURE2 iface,
|
|
|
|
LPDIRECT3DDEVICE2 lpDirect3DDevice2,
|
|
|
|
LPD3DTEXTUREHANDLE lpHandle)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpDirect3DDevice2, lpHandle);
|
|
|
|
return DD_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Main_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
|
|
|
|
LPDIRECT3DTEXTURE2 lpD3DTexture2)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
|
2002-11-21 21:04:16 +00:00
|
|
|
FIXME("(%p/%p)->(%p): stub!\n", This, iface, lpD3DTexture2);
|
|
|
|
return DD_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
static void
|
|
|
|
gltex_final_release(IDirectDrawSurfaceImpl *This)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
|
|
|
|
DWORD mem_used;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
TRACE(" deleting texture with GL id %d.\n", glThis->tex_name);
|
|
|
|
|
|
|
|
/* And delete texture handle */
|
|
|
|
ENTER_GL();
|
|
|
|
if (glThis->tex_name != 0)
|
|
|
|
glDeleteTextures(1, &(glThis->tex_name));
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
/* And if this texture was the current one, remove it at the device level */
|
|
|
|
if (This->d3ddevice != NULL)
|
|
|
|
if (This->d3ddevice->current_texture[0] == This)
|
|
|
|
This->d3ddevice->current_texture[0] = NULL;
|
|
|
|
|
|
|
|
/* All this should be part of main surface management not just a hack for texture.. */
|
|
|
|
if (glThis->loaded) {
|
|
|
|
mem_used = This->surface_desc.dwHeight *
|
|
|
|
This->surface_desc.dwHeight *
|
|
|
|
This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount;
|
|
|
|
This->ddraw_owner->free_memory(This->ddraw_owner, mem_used);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
glThis->final_release(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gltex_lock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
|
|
|
|
|
|
|
|
glThis->lock_update(This, pRect, dwFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gltex_unlock_update(IDirectDrawSurfaceImpl* This, LPCRECT pRect)
|
|
|
|
{
|
|
|
|
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
gltex_upload_texture(This, glThis->first_unlock);
|
|
|
|
LEAVE_GL();
|
|
|
|
glThis->first_unlock = FALSE;
|
|
|
|
|
|
|
|
glThis->unlock_update(This, pRect);
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
GL_IDirect3DTextureImpl_2_1T_GetHandle(LPDIRECT3DTEXTURE2 iface,
|
|
|
|
LPDIRECT3DDEVICE2 lpDirect3DDevice2,
|
|
|
|
LPD3DTEXTUREHANDLE lpHandle)
|
1999-01-03 17:00:19 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
|
|
|
|
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
|
2002-11-21 21:04:16 +00:00
|
|
|
IDirect3DDeviceImpl *lpDeviceImpl = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice2, lpDirect3DDevice2);
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice2, lpHandle);
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
/* The handle is simply the pointer to the implementation structure */
|
2000-04-09 14:30:50 +00:00
|
|
|
*lpHandle = (D3DTEXTUREHANDLE) This;
|
1999-01-17 16:32:32 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
TRACE(" returning handle %08lx.\n", *lpHandle);
|
|
|
|
|
2000-04-09 14:30:50 +00:00
|
|
|
/* Now, bind a new texture */
|
2002-11-21 21:04:16 +00:00
|
|
|
This->d3ddevice = lpDeviceImpl;
|
2000-04-09 14:30:50 +00:00
|
|
|
|
2002-10-16 18:57:52 +00:00
|
|
|
/* Associate the texture with the device and perform the appropriate AddRef/Release */
|
|
|
|
/* FIXME: Is there only one or several textures associated with the device ? */
|
2002-12-02 18:59:11 +00:00
|
|
|
if (lpDeviceImpl->current_texture[0] != NULL)
|
2002-12-15 01:17:59 +00:00
|
|
|
IDirectDrawSurface7_Release(ICOM_INTERFACE(lpDeviceImpl->current_texture[0], IDirectDrawSurface7));
|
|
|
|
IDirectDrawSurface7_AddRef(ICOM_INTERFACE(This, IDirectDrawSurface7));
|
2002-12-02 18:59:11 +00:00
|
|
|
lpDeviceImpl->current_texture[0] = This;
|
2002-10-16 18:57:52 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
TRACE("OpenGL texture handle is : %d\n", glThis->tex_name);
|
2000-04-09 14:30:50 +00:00
|
|
|
|
|
|
|
return D3D_OK;
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
GL_IDirect3DTextureImpl_2_1T_Load(LPDIRECT3DTEXTURE2 iface,
|
|
|
|
LPDIRECT3DTEXTURE2 lpD3DTexture2)
|
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
ICOM_THIS_FROM(IDirectDrawSurfaceImpl, IDirect3DTexture2, iface);
|
|
|
|
IDirect3DTextureGLImpl *glThis = (IDirect3DTextureGLImpl *) This->tex_private;
|
|
|
|
IDirectDrawSurfaceImpl *lpD3DTextureImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirect3DTexture2, lpD3DTexture2);
|
2002-11-27 21:38:28 +00:00
|
|
|
DWORD mem_used;
|
2002-12-15 01:17:59 +00:00
|
|
|
DDSURFACEDESC *src_d, *dst_d;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-11-24 22:33:41 +00:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, lpD3DTexture2);
|
2002-11-27 21:38:28 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
if (glThis->loaded == FALSE) {
|
2002-12-02 21:39:34 +00:00
|
|
|
/* Only check memory for not already loaded texture... */
|
2002-12-15 01:17:59 +00:00
|
|
|
mem_used = This->surface_desc.dwHeight *
|
|
|
|
This->surface_desc.dwHeight *
|
|
|
|
This->surface_desc.u4.ddpfPixelFormat.u1.dwRGBBitCount;
|
|
|
|
if (This->ddraw_owner->allocate_memory(This->ddraw_owner, mem_used) < 0) {
|
2002-12-02 21:39:34 +00:00
|
|
|
TRACE(" out of virtual memory... Warning application.\n");
|
|
|
|
return D3DERR_TEXTURE_LOAD_FAILED;
|
|
|
|
}
|
2002-11-27 21:38:28 +00:00
|
|
|
}
|
2002-12-15 01:17:59 +00:00
|
|
|
glThis->loaded = TRUE;
|
2002-11-27 21:38:28 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
TRACE("Copied surface %p to surface %p\n", lpD3DTextureImpl, This);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
if ( This->surface_desc.ddsCaps.dwCaps & DDSCAPS_ALLOCONLOAD )
|
2002-11-21 21:04:16 +00:00
|
|
|
/* If the surface is not allocated and its location is not yet specified,
|
|
|
|
force it to video memory */
|
2002-12-16 22:48:20 +00:00
|
|
|
if ( !(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_SYSTEMMEMORY|DDSCAPS_VIDEOMEMORY)) )
|
2002-12-15 01:17:59 +00:00
|
|
|
This->surface_desc.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
/* Suppress the ALLOCONLOAD flag */
|
2002-12-15 01:17:59 +00:00
|
|
|
This->surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_ALLOCONLOAD;
|
|
|
|
This->palette = lpD3DTextureImpl->palette;
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
/* Copy one surface on the other */
|
2002-12-15 01:17:59 +00:00
|
|
|
dst_d = (DDSURFACEDESC *)&(This->surface_desc);
|
|
|
|
src_d = (DDSURFACEDESC *)&(lpD3DTextureImpl->surface_desc);
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
if ((src_d->dwWidth != dst_d->dwWidth) || (src_d->dwHeight != dst_d->dwHeight)) {
|
|
|
|
/* Should also check for same pixel format, u1.lPitch, ... */
|
|
|
|
ERR("Error in surface sizes\n");
|
|
|
|
return D3DERR_TEXTURE_LOAD_FAILED;
|
|
|
|
} else {
|
|
|
|
/* LPDIRECT3DDEVICE2 d3dd = (LPDIRECT3DDEVICE2) This->D3Ddevice; */
|
|
|
|
/* I should put a macro for the calculus of bpp */
|
2002-12-15 01:17:59 +00:00
|
|
|
|
|
|
|
/* Copy also the ColorKeying stuff */
|
|
|
|
if (src_d->dwFlags & DDSD_CKSRCBLT) {
|
|
|
|
dst_d->ddckCKSrcBlt.dwColorSpaceLowValue = src_d->ddckCKSrcBlt.dwColorSpaceLowValue;
|
|
|
|
dst_d->ddckCKSrcBlt.dwColorSpaceHighValue = src_d->ddckCKSrcBlt.dwColorSpaceHighValue;
|
|
|
|
}
|
2001-03-21 20:31:26 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
/* Copy the main memry texture into the surface that corresponds to the OpenGL
|
|
|
|
texture object. */
|
|
|
|
memcpy(dst_d->lpSurface, src_d->lpSurface, src_d->u1.lPitch * src_d->dwHeight);
|
1999-01-17 16:32:32 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
/* If the GetHandle was not done, it is an error... */
|
|
|
|
if (glThis->tex_name == 0) ERR("Unbound GL texture !!!\n");
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
ENTER_GL();
|
1999-01-17 16:32:32 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
/* Now, load the texture */
|
|
|
|
/* d3dd->set_context(d3dd); We need to set the context somehow.... */
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
gltex_upload_texture(This, glThis->first_unlock);
|
|
|
|
glThis->first_unlock = FALSE;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
LEAVE_GL();
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_2_QueryInterface(LPDIRECT3DTEXTURE2 iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID* obp)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s,%p) thunking to IDirectDrawSurface7 interface.\n", iface, debugstr_guid(riid), obp);
|
|
|
|
return IDirectDrawSurface7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture2, IDirectDrawSurface7, iface),
|
|
|
|
riid,
|
|
|
|
obp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_2_AddRef(LPDIRECT3DTEXTURE2 iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", iface);
|
|
|
|
return IDirectDrawSurface7_AddRef(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture2, IDirectDrawSurface7, iface));
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_2_Release(LPDIRECT3DTEXTURE2 iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", iface);
|
|
|
|
return IDirectDrawSurface7_AddRef(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture2, IDirectDrawSurface7, iface));
|
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_1_QueryInterface(LPDIRECT3DTEXTURE iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID* obp)
|
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
TRACE("(%p)->(%s,%p) thunking to IDirectDrawSurface7 interface.\n", iface, debugstr_guid(riid), obp);
|
|
|
|
return IDirectDrawSurface7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirectDrawSurface7, iface),
|
|
|
|
riid,
|
|
|
|
obp);
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
ULONG WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_1_AddRef(LPDIRECT3DTEXTURE iface)
|
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", iface);
|
|
|
|
return IDirectDrawSurface7_AddRef(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirectDrawSurface7, iface));
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
ULONG WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_1_Release(LPDIRECT3DTEXTURE iface)
|
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
TRACE("(%p)->() thunking to IDirectDrawSurface7 interface.\n", iface);
|
|
|
|
return IDirectDrawSurface7_AddRef(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirectDrawSurface7, iface));
|
2002-11-21 21:04:16 +00:00
|
|
|
}
|
1999-01-17 16:55:11 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_1_PaletteChanged(LPDIRECT3DTEXTURE iface,
|
|
|
|
DWORD dwStart,
|
|
|
|
DWORD dwCount)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%08lx,%08lx) thunking to IDirect3DTexture2 interface.\n", iface, dwStart, dwCount);
|
2002-12-15 01:17:59 +00:00
|
|
|
return IDirect3DTexture2_PaletteChanged(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirect3DTexture2, iface),
|
2002-11-21 21:04:16 +00:00
|
|
|
dwStart,
|
|
|
|
dwCount);
|
|
|
|
}
|
1999-05-13 18:53:05 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_1_GetHandle(LPDIRECT3DTEXTURE iface,
|
|
|
|
LPDIRECT3DDEVICE lpDirect3DDevice,
|
|
|
|
LPD3DTEXTUREHANDLE lpHandle)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%p,%p) thunking to IDirect3DTexture2 interface.\n", iface, lpDirect3DDevice, lpHandle);
|
2002-12-15 01:17:59 +00:00
|
|
|
return IDirect3DTexture2_GetHandle(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirect3DTexture2, iface),
|
2002-11-21 21:04:16 +00:00
|
|
|
COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice2, lpDirect3DDevice),
|
|
|
|
lpHandle);
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
HRESULT WINAPI
|
|
|
|
Thunk_IDirect3DTextureImpl_1_Load(LPDIRECT3DTEXTURE iface,
|
|
|
|
LPDIRECT3DTEXTURE lpD3DTexture)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%p) thunking to IDirect3DTexture2 interface.\n", iface, lpD3DTexture);
|
2002-12-15 01:17:59 +00:00
|
|
|
return IDirect3DTexture2_Load(COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirect3DTexture2, iface),
|
|
|
|
COM_INTERFACE_CAST(IDirectDrawSurfaceImpl, IDirect3DTexture, IDirect3DTexture2, lpD3DTexture));
|
1999-01-03 17:00:19 +00:00
|
|
|
}
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
# define XCAST(fun) (typeof(VTABLE_IDirect3DTexture2.fun))
|
|
|
|
#else
|
|
|
|
# define XCAST(fun) (void*)
|
|
|
|
#endif
|
1999-01-03 17:00:19 +00:00
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
ICOM_VTABLE(IDirect3DTexture2) VTABLE_IDirect3DTexture2 =
|
1999-05-22 11:41:38 +00:00
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
2002-12-15 01:17:59 +00:00
|
|
|
XCAST(QueryInterface) Thunk_IDirect3DTextureImpl_2_QueryInterface,
|
|
|
|
XCAST(AddRef) Thunk_IDirect3DTextureImpl_2_AddRef,
|
|
|
|
XCAST(Release) Thunk_IDirect3DTextureImpl_2_Release,
|
2002-11-21 21:04:16 +00:00
|
|
|
XCAST(GetHandle) GL_IDirect3DTextureImpl_2_1T_GetHandle,
|
|
|
|
XCAST(PaletteChanged) Main_IDirect3DTextureImpl_2_1T_PaletteChanged,
|
|
|
|
XCAST(Load) GL_IDirect3DTextureImpl_2_1T_Load,
|
1999-01-03 17:00:19 +00:00
|
|
|
};
|
|
|
|
|
2002-12-16 22:48:20 +00:00
|
|
|
ICOM_VTABLE(IDirect3DTexture2) STUB_VTABLE_IDirect3DTexture2 =
|
|
|
|
{
|
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
XCAST(QueryInterface) Thunk_IDirect3DTextureImpl_2_QueryInterface,
|
|
|
|
XCAST(AddRef) Thunk_IDirect3DTextureImpl_2_AddRef,
|
|
|
|
XCAST(Release) Thunk_IDirect3DTextureImpl_2_Release,
|
|
|
|
XCAST(GetHandle) Main_IDirect3DTextureImpl_2_1T_GetHandle,
|
|
|
|
XCAST(PaletteChanged) Main_IDirect3DTextureImpl_2_1T_PaletteChanged,
|
|
|
|
XCAST(Load) Main_IDirect3DTextureImpl_2_1T_Load,
|
|
|
|
};
|
|
|
|
|
2000-07-16 14:40:35 +00:00
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
2002-11-21 21:04:16 +00:00
|
|
|
#undef XCAST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
# define XCAST(fun) (typeof(VTABLE_IDirect3DTexture.fun))
|
2000-07-16 14:40:35 +00:00
|
|
|
#else
|
2002-11-21 21:04:16 +00:00
|
|
|
# define XCAST(fun) (void*)
|
2000-07-16 14:40:35 +00:00
|
|
|
#endif
|
|
|
|
|
2002-11-21 21:04:16 +00:00
|
|
|
ICOM_VTABLE(IDirect3DTexture) VTABLE_IDirect3DTexture =
|
1999-05-22 11:41:38 +00:00
|
|
|
{
|
2002-11-21 21:04:16 +00:00
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
XCAST(QueryInterface) Thunk_IDirect3DTextureImpl_1_QueryInterface,
|
|
|
|
XCAST(AddRef) Thunk_IDirect3DTextureImpl_1_AddRef,
|
|
|
|
XCAST(Release) Thunk_IDirect3DTextureImpl_1_Release,
|
|
|
|
XCAST(Initialize) Main_IDirect3DTextureImpl_1_Initialize,
|
|
|
|
XCAST(GetHandle) Thunk_IDirect3DTextureImpl_1_GetHandle,
|
|
|
|
XCAST(PaletteChanged) Thunk_IDirect3DTextureImpl_1_PaletteChanged,
|
|
|
|
XCAST(Load) Thunk_IDirect3DTextureImpl_1_Load,
|
|
|
|
XCAST(Unload) Main_IDirect3DTextureImpl_1_Unload,
|
1999-01-03 17:00:19 +00:00
|
|
|
};
|
2000-07-16 14:40:35 +00:00
|
|
|
|
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
|
|
|
|
#undef XCAST
|
|
|
|
#endif
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
HRESULT d3dtexture_create(IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation,
|
|
|
|
IDirectDrawSurfaceImpl *main, DWORD mipmap_level)
|
2002-11-21 21:04:16 +00:00
|
|
|
{
|
2002-12-15 01:17:59 +00:00
|
|
|
IDirect3DTextureGLImpl *private;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-16 22:48:20 +00:00
|
|
|
if ((surf->surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_SYSTEMMEMORY)) != 0) {
|
|
|
|
/* If it is an offscreen texture, only create stub implementations.
|
|
|
|
Only the IUnknown interfaces should be used anyway. */
|
|
|
|
ICOM_INIT_INTERFACE(surf, IDirect3DTexture, VTABLE_IDirect3DTexture); /* No special STUB one here as all functions are stubs */
|
|
|
|
ICOM_INIT_INTERFACE(surf, IDirect3DTexture2, STUB_VTABLE_IDirect3DTexture2);
|
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTextureGLImpl));
|
|
|
|
if (private == NULL) return DDERR_OUTOFMEMORY;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
private->final_release = surf->final_release;
|
|
|
|
private->lock_update = surf->lock_update;
|
|
|
|
private->unlock_update = surf->unlock_update;
|
|
|
|
private->mipmap_level = mipmap_level;
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
/* If at creation, we can optimize stuff and wait the first 'unlock' to upload a valid stuff to OpenGL.
|
|
|
|
Otherwise, it will be uploaded here (and may be invalid). */
|
|
|
|
if (at_creation == TRUE)
|
|
|
|
private->first_unlock = TRUE;
|
|
|
|
else
|
|
|
|
private->first_unlock = FALSE;
|
|
|
|
surf->final_release = gltex_final_release;
|
|
|
|
surf->lock_update = gltex_lock_update;
|
|
|
|
surf->unlock_update = gltex_unlock_update;
|
|
|
|
surf->tex_private = private;
|
|
|
|
surf->SetColorKey_cb = gltex_setcolorkey_cb;
|
|
|
|
|
|
|
|
ICOM_INIT_INTERFACE(surf, IDirect3DTexture, VTABLE_IDirect3DTexture);
|
|
|
|
ICOM_INIT_INTERFACE(surf, IDirect3DTexture2, VTABLE_IDirect3DTexture2);
|
|
|
|
|
2002-12-16 22:50:30 +00:00
|
|
|
ENTER_GL();
|
2002-12-15 01:17:59 +00:00
|
|
|
if (mipmap_level == 0) {
|
|
|
|
glGenTextures(1, &(private->tex_name));
|
|
|
|
if (private->tex_name == 0) ERR("Error at creation of OpenGL texture ID !\n");
|
|
|
|
TRACE(" GL texture created (private data at %p and GL id %d).\n", private, private->tex_name);
|
|
|
|
} else {
|
|
|
|
private->tex_name = ((IDirect3DTextureGLImpl *) main->tex_private)->tex_name;
|
|
|
|
TRACE(" GL texture created (private data at %p and GL id reusing id %d).\n", private, private->tex_name);
|
|
|
|
}
|
2002-11-21 21:04:16 +00:00
|
|
|
|
2002-12-15 01:17:59 +00:00
|
|
|
if ((at_creation == FALSE) &&
|
|
|
|
((surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_ALLOCONLOAD) == 0))
|
|
|
|
{
|
|
|
|
gltex_upload_texture(surf, TRUE);
|
|
|
|
}
|
|
|
|
LEAVE_GL();
|
2002-11-21 21:04:16 +00:00
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|