Moved a large number of 16-bit functions to a separate gdi16.c file.
[wine/hacks.git] / dlls / ddraw / d3dtexture.c
blob9728f97851c68937329d4dfff77c883b262c3eee
1 /* Direct3D Texture
2 * Copyright (c) 1998 Lionel ULMER
4 * This file contains the implementation of interface Direct3DTexture2.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <string.h>
25 #include "windef.h"
26 #include "winerror.h"
27 #include "wine/obj_base.h"
28 #include "ddraw.h"
29 #include "d3d.h"
30 #include "wine/debug.h"
32 #include "mesa_private.h"
34 #define D3DDPRIVATE(x) mesa_d3dd_private*odev=(mesa_d3dd_private*)(x)->private
35 #define D3DTPRIVATE(x) mesa_d3dt_private*dtpriv=(mesa_d3dt_private*)(x)->private
37 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
39 /* Define this if you want to save to a file all the textures used by a game
40 (can be funny to see how they managed to cram all the pictures in
41 texture memory) */
42 #undef TEXTURE_SNOOP
44 #ifdef TEXTURE_SNOOP
45 #include <stdio.h>
47 #define SNOOP_PALETTED() \
48 { \
49 FILE *f; \
50 char buf[32]; \
51 int x, y; \
53 sprintf(buf, "%ld.pnm", dtpriv->tex_name); \
54 f = fopen(buf, "wb"); \
55 fprintf(f, "P6\n%ld %ld\n255\n", src_d->dwWidth, src_d->dwHeight); \
56 for (y = 0; y < src_d->dwHeight; y++) { \
57 for (x = 0; x < src_d->dwWidth; x++) { \
58 unsigned char c = ((unsigned char *) src_d->y.lpSurface)[y * src_d->dwWidth + x]; \
59 fputc(table[c][0], f); \
60 fputc(table[c][1], f); \
61 fputc(table[c][2], f); \
62 } \
63 } \
64 fclose(f); \
67 #define SNOOP_5650() \
68 { \
69 FILE *f; \
70 char buf[32]; \
71 int x, y; \
73 sprintf(buf, "%ld.pnm", dtpriv->tex_name); \
74 f = fopen(buf, "wb"); \
75 fprintf(f, "P6\n%ld %ld\n255\n", src_d->dwWidth, src_d->dwHeight); \
76 for (y = 0; y < src_d->dwHeight; y++) { \
77 for (x = 0; x < src_d->dwWidth; x++) { \
78 unsigned short c = ((unsigned short *) src_d->y.lpSurface)[y * src_d->dwWidth + x]; \
79 fputc((c & 0xF800) >> 8, f); \
80 fputc((c & 0x07E0) >> 3, f); \
81 fputc((c & 0x001F) << 3, f); \
82 } \
83 } \
84 fclose(f); \
87 #define SNOOP_5551() \
88 { \
89 FILE *f; \
90 char buf[32]; \
91 int x, y; \
93 sprintf(buf, "%ld.pnm", dtpriv->tex_name); \
94 f = fopen(buf, "wb"); \
95 fprintf(f, "P6\n%ld %ld\n255\n", src_d->dwWidth, src_d->dwHeight); \
96 for (y = 0; y < src_d->dwHeight; y++) { \
97 for (x = 0; x < src_d->dwWidth; x++) { \
98 unsigned short c = ((unsigned short *) src_d->y.lpSurface)[y * src_d->dwWidth + x]; \
99 fputc((c & 0xF800) >> 8, f); \
100 fputc((c & 0x07C0) >> 3, f); \
101 fputc((c & 0x003E) << 2, f); \
104 fclose(f); \
106 #else
107 #define SNOOP_PALETTED()
108 #define SNOOP_5650()
109 #define SNOOP_5551()
110 #endif
112 extern ICOM_VTABLE(IDirect3DTexture2) mesa_texture2_vtable;
113 extern ICOM_VTABLE(IDirect3DTexture) mesa_texture_vtable;
115 /*******************************************************************************
116 * Texture2 Creation functions
118 LPDIRECT3DTEXTURE2 d3dtexture2_create(IDirectDrawSurfaceImpl* surf)
120 IDirect3DTexture2Impl* tex;
122 tex = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DTexture2Impl));
123 tex->ref = 1;
124 ICOM_VTBL(tex) = &mesa_texture2_vtable;
125 tex->surface = surf;
127 tex->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(mesa_d3dt_private));
129 return (LPDIRECT3DTEXTURE2)tex;
132 /*******************************************************************************
133 * Texture Creation functions
135 LPDIRECT3DTEXTURE d3dtexture_create(IDirectDrawSurfaceImpl* surf)
137 IDirect3DTexture2Impl* tex;
139 tex = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DTexture2Impl));
140 tex->ref = 1;
141 ICOM_VTBL(tex) = (ICOM_VTABLE(IDirect3DTexture2)*)&mesa_texture_vtable;
142 tex->surface = surf;
144 tex->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(mesa_d3dt_private));
146 return (LPDIRECT3DTEXTURE)tex;
149 /*******************************************************************************
150 * IDirectSurface callback methods
152 HRESULT WINAPI SetColorKey_cb(IDirect3DTexture2Impl *texture, DWORD dwFlags, LPDDCOLORKEY ckey )
154 DDSURFACEDESC *tex_d;
155 D3DTPRIVATE(texture);
156 int bpp;
157 GLuint current_texture;
159 TRACE("(%p) : colorkey callback\n", texture);
161 /* Get the texture description */
162 tex_d = (DDSURFACEDESC *)&(texture->surface->surface_desc);
163 bpp = (tex_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8 ?
164 1 /* 8 bit of palette index */:
165 tex_d->ddpfPixelFormat.u1.dwRGBBitCount / 8 /* RGB bits for each colors */ );
167 /* Now, save the current texture */
168 ENTER_GL();
169 glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
171 /* If the GetHandle was not done yet, it's an error */
172 if (dtpriv->tex_name == 0) {
173 ERR("Unloaded texture !\n");
174 LEAVE_GL();
175 return DD_OK;
177 glBindTexture(GL_TEXTURE_2D, dtpriv->tex_name);
179 if (tex_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
180 FIXME("Todo Paletted\n");
181 } else if (tex_d->ddpfPixelFormat.dwFlags & DDPF_RGB) {
182 if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 8) {
183 FIXME("Todo 3_3_2_0\n");
184 } else if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 16) {
185 if (tex_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000000) {
186 /* Now transform the 5_6_5 into a 5_5_5_1 surface to support color keying */
187 unsigned short *dest = (unsigned short *) HeapAlloc(GetProcessHeap(),
188 HEAP_ZERO_MEMORY,
189 tex_d->dwWidth * tex_d->dwHeight * bpp);
190 unsigned short *src = (unsigned short *) tex_d->lpSurface;
191 int x, y;
193 for (y = 0; y < tex_d->dwHeight; y++) {
194 for (x = 0; x < tex_d->dwWidth; x++) {
195 unsigned short cpixel = src[x + y * tex_d->dwWidth];
197 if ((dwFlags & DDCKEY_SRCBLT) &&
198 (cpixel >= ckey->dwColorSpaceLowValue) &&
199 (cpixel <= ckey->dwColorSpaceHighValue)) /* No alpha bit => this pixel is transparent */
200 dest[x + y * tex_d->dwWidth] = (cpixel & ~0x003F) | ((cpixel & 0x001F) << 1) | 0x0000;
201 else /* Alpha bit is set => this pixel will be seen */
202 dest[x + y * tex_d->dwWidth] = (cpixel & ~0x003F) | ((cpixel & 0x001F) << 1) | 0x0001;
206 glTexImage2D(GL_TEXTURE_2D,
208 GL_RGBA,
209 tex_d->dwWidth, tex_d->dwHeight,
211 GL_RGBA,
212 GL_UNSIGNED_SHORT_5_5_5_1,
213 dest);
215 /* Frees the temporary surface */
216 HeapFree(GetProcessHeap(),0,dest);
217 } else if (tex_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000001) {
218 FIXME("Todo 5_5_5_1\n");
219 } else if (tex_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000000F) {
220 FIXME("Todo 4_4_4_4\n");
221 } else {
222 ERR("Unhandled texture format (bad Aplha channel for a 16 bit texture)\n");
224 } else if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 24) {
225 FIXME("Todo 8_8_8_0\n");
226 } else if (tex_d->ddpfPixelFormat.u1.dwRGBBitCount == 32) {
227 FIXME("Todo 8_8_8_8\n");
228 } else {
229 ERR("Unhandled texture format (bad RGB count)\n");
231 } else {
232 ERR("Unhandled texture format (neither RGB nor INDEX)\n");
234 LEAVE_GL();
236 return DD_OK;
239 /*******************************************************************************
240 * IDirect3DTexture2 methods
243 HRESULT WINAPI IDirect3DTexture2Impl_QueryInterface(LPDIRECT3DTEXTURE2 iface,
244 REFIID riid,
245 LPVOID* ppvObj)
247 ICOM_THIS(IDirect3DTexture2Impl,iface);
249 FIXME("(%p)->(%s,%p): stub\n", This, debugstr_guid(riid),ppvObj);
251 return S_OK;
256 ULONG WINAPI IDirect3DTexture2Impl_AddRef(LPDIRECT3DTEXTURE2 iface)
258 ICOM_THIS(IDirect3DTexture2Impl,iface);
259 TRACE("(%p)->()incrementing from %lu.\n", This, This->ref );
261 return ++(This->ref);
266 ULONG WINAPI IDirect3DTexture2Impl_Release(LPDIRECT3DTEXTURE2 iface)
268 ICOM_THIS(IDirect3DTexture2Impl,iface);
269 D3DTPRIVATE(This);
270 FIXME("(%p)->() decrementing from %lu.\n", This, This->ref );
272 if (!--(This->ref)) {
273 /* Delete texture from OpenGL */
274 ENTER_GL();
275 glDeleteTextures(1, &(dtpriv->tex_name));
276 LEAVE_GL();
278 /* Release surface */
279 IDirectDrawSurface4_Release((IDirectDrawSurface4*)This->surface);
281 HeapFree(GetProcessHeap(),0,This);
282 return 0;
285 return This->ref;
288 /*** IDirect3DTexture methods ***/
289 HRESULT WINAPI IDirect3DTextureImpl_GetHandle(LPDIRECT3DTEXTURE iface,
290 LPDIRECT3DDEVICE lpD3DDevice,
291 LPD3DTEXTUREHANDLE lpHandle)
293 ICOM_THIS(IDirect3DTexture2Impl,iface);
294 D3DTPRIVATE(This);
295 IDirect3DDeviceImpl* ilpD3DDevice=(IDirect3DDeviceImpl*)lpD3DDevice;
296 FIXME("(%p)->(%p,%p): stub\n", This, ilpD3DDevice, lpHandle);
298 *lpHandle = (D3DTEXTUREHANDLE) This;
300 /* Now, bind a new texture */
301 ENTER_GL();
302 ilpD3DDevice->set_context(ilpD3DDevice);
303 This->D3Ddevice = (void *) ilpD3DDevice;
304 if (dtpriv->tex_name == 0)
305 glGenTextures(1, &(dtpriv->tex_name));
306 LEAVE_GL();
308 TRACE("OpenGL texture handle is : %d\n", dtpriv->tex_name);
310 return D3D_OK;
313 HRESULT WINAPI IDirect3DTextureImpl_Initialize(LPDIRECT3DTEXTURE iface,
314 LPDIRECT3DDEVICE lpD3DDevice,
315 LPDIRECTDRAWSURFACE lpSurface)
317 ICOM_THIS(IDirect3DTexture2Impl,iface);
318 TRACE("(%p)->(%p,%p)\n", This, lpD3DDevice, lpSurface);
320 return DDERR_ALREADYINITIALIZED;
323 HRESULT WINAPI IDirect3DTextureImpl_Unload(LPDIRECT3DTEXTURE iface)
325 ICOM_THIS(IDirect3DTexture2Impl,iface);
326 FIXME("(%p)->(): stub\n", This);
328 return D3D_OK;
331 /*** IDirect3DTexture2 methods ***/
332 HRESULT WINAPI IDirect3DTexture2Impl_GetHandle(LPDIRECT3DTEXTURE2 iface,
333 LPDIRECT3DDEVICE2 lpD3DDevice2,
334 LPD3DTEXTUREHANDLE lpHandle)
336 ICOM_THIS(IDirect3DTexture2Impl,iface);
337 D3DTPRIVATE(This);
338 IDirect3DDevice2Impl* ilpD3DDevice2=(IDirect3DDevice2Impl*)lpD3DDevice2;
339 TRACE("(%p)->(%p,%p)\n", This, ilpD3DDevice2, lpHandle);
341 /* For 32 bits OSes, handles = pointers */
342 *lpHandle = (D3DTEXTUREHANDLE) This;
344 /* Now, bind a new texture */
345 ENTER_GL();
346 ilpD3DDevice2->set_context(ilpD3DDevice2);
347 This->D3Ddevice = (void *) ilpD3DDevice2;
348 if (dtpriv->tex_name == 0)
349 glGenTextures(1, &(dtpriv->tex_name));
350 LEAVE_GL();
352 TRACE("OpenGL texture handle is : %d\n", dtpriv->tex_name);
354 return D3D_OK;
357 /* Common methods */
358 HRESULT WINAPI IDirect3DTexture2Impl_PaletteChanged(
359 LPDIRECT3DTEXTURE2 iface, DWORD dwStart, DWORD dwCount
361 ICOM_THIS(IDirect3DTexture2Impl,iface);
362 FIXME("(%p)->(%8ld,%8ld): stub\n", This, dwStart, dwCount);
364 return D3D_OK;
367 /* NOTE : if you experience crashes in this function, you must have a buggy
368 version of Mesa. See the file d3dtexture.c for a cure */
369 HRESULT WINAPI IDirect3DTexture2Impl_Load(
370 LPDIRECT3DTEXTURE2 iface, LPDIRECT3DTEXTURE2 lpD3DTexture2
372 ICOM_THIS(IDirect3DTexture2Impl,iface);
373 D3DTPRIVATE(This);
374 IDirect3DTexture2Impl* ilpD3DTexture2=(IDirect3DTexture2Impl*)lpD3DTexture2;
375 DDSURFACEDESC *src_d, *dst_d;
376 static void (*ptr_ColorTableEXT) (GLenum target, GLenum internalformat,
377 GLsizei width, GLenum format, GLenum type, const GLvoid *table) = NULL;
378 #if 0
379 static BOOL color_table_queried = FALSE;
380 #endif
382 TRACE("(%p)->(%p)\n", This, ilpD3DTexture2);
383 TRACE("Copied surface %p to surface %p\n", ilpD3DTexture2->surface, This->surface);
385 /* Suppress the ALLOCONLOAD flag */
386 This->surface->surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_ALLOCONLOAD;
388 /* Copy one surface on the other */
389 dst_d = (DDSURFACEDESC *)&(This->surface->surface_desc);
390 src_d = (DDSURFACEDESC *)&(ilpD3DTexture2->surface->surface_desc);
392 /* Install the callbacks to the destination surface */
393 This->surface->texture = This;
394 This->surface->SetColorKey_cb = SetColorKey_cb;
396 if ((src_d->dwWidth != dst_d->dwWidth) || (src_d->dwHeight != dst_d->dwHeight)) {
397 /* Should also check for same pixel format, lPitch, ... */
398 ERR("Error in surface sizes\n");
399 return D3DERR_TEXTURE_LOAD_FAILED;
400 } else {
401 /* LPDIRECT3DDEVICE2 d3dd = (LPDIRECT3DDEVICE2) This->D3Ddevice; */
402 /* I should put a macro for the calculus of bpp */
403 int bpp = (src_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8 ?
404 1 /* 8 bit of palette index */:
405 src_d->ddpfPixelFormat.u1.dwRGBBitCount / 8 /* RGB bits for each colors */ );
406 GLuint current_texture;
408 /* Copy the main memry texture into the surface that corresponds to the OpenGL
409 texture object. */
410 memcpy(dst_d->lpSurface, src_d->lpSurface, src_d->dwWidth * src_d->dwHeight * bpp);
412 ENTER_GL();
414 /* Now, load the texture */
415 /* d3dd->set_context(d3dd); We need to set the context somehow.... */
416 glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
418 /* If the GetHandle was not done, get the texture name here */
419 if (dtpriv->tex_name == 0)
420 glGenTextures(1, &(dtpriv->tex_name));
421 glBindTexture(GL_TEXTURE_2D, dtpriv->tex_name);
423 if (src_d->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
424 /* ****************
425 Paletted Texture
426 **************** */
427 IDirectDrawPaletteImpl* pal = This->surface->palette;
428 BYTE table[256][4];
429 int i;
431 #if 0
432 if (color_table_queried == FALSE) {
433 ptr_ColorTableEXT =
434 ((Mesa_DeviceCapabilities *) ((x11_dd_private *) This->surface->s.ddraw->d->private)->device_capabilities)->ptr_ColorTableEXT;
436 #endif
438 if (pal == NULL) {
439 ERR("Palettized texture Loading with a NULL palette !\n");
440 LEAVE_GL();
441 return D3DERR_TEXTURE_LOAD_FAILED;
444 /* Get the surface's palette */
445 for (i = 0; i < 256; i++) {
446 table[i][0] = pal->palents[i].peRed;
447 table[i][1] = pal->palents[i].peGreen;
448 table[i][2] = pal->palents[i].peBlue;
449 if ((This->surface->surface_desc.dwFlags & DDSD_CKSRCBLT) &&
450 (i >= This->surface->surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue) &&
451 (i <= This->surface->surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue))
452 table[i][3] = 0x00;
453 else
454 table[i][3] = 0xFF;
457 /* Texture snooping */
458 SNOOP_PALETTED();
460 if (ptr_ColorTableEXT != NULL) {
461 /* use Paletted Texture Extension */
462 ptr_ColorTableEXT(GL_TEXTURE_2D, /* target */
463 GL_RGBA, /* internal format */
464 256, /* table size */
465 GL_RGBA, /* table format */
466 GL_UNSIGNED_BYTE, /* table type */
467 table); /* the color table */
469 glTexImage2D(GL_TEXTURE_2D, /* target */
470 0, /* level */
471 GL_COLOR_INDEX8_EXT, /* internal format */
472 src_d->dwWidth, src_d->dwHeight, /* width, height */
473 0, /* border */
474 GL_COLOR_INDEX, /* texture format */
475 GL_UNSIGNED_BYTE, /* texture type */
476 src_d->lpSurface); /* the texture */
477 } else {
478 DWORD *surface = (DWORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(DWORD));
479 DWORD i;
480 BYTE *src = (BYTE *) src_d->lpSurface, *dst = (BYTE *) surface;
482 for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
483 BYTE color = *src++;
484 *dst++ = table[color][0];
485 *dst++ = table[color][1];
486 *dst++ = table[color][2];
487 *dst++ = table[color][3];
490 glTexImage2D(GL_TEXTURE_2D,
492 GL_RGBA,
493 src_d->dwWidth, src_d->dwHeight,
495 GL_RGBA,
496 GL_UNSIGNED_BYTE,
497 surface);
499 HeapFree(GetProcessHeap(), 0, surface);
501 } else if (src_d->ddpfPixelFormat.dwFlags & DDPF_RGB) {
502 /* ************
503 RGB Textures
504 ************ */
505 if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 8) {
506 /* **********************
507 GL_UNSIGNED_BYTE_3_3_2
508 ********************** */
509 glTexImage2D(GL_TEXTURE_2D,
511 GL_RGB,
512 src_d->dwWidth, src_d->dwHeight,
514 GL_RGB,
515 GL_UNSIGNED_BYTE_3_3_2,
516 src_d->lpSurface);
517 } else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 16) {
518 if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000000) {
520 /* Texture snooping */
521 SNOOP_5650();
523 glTexImage2D(GL_TEXTURE_2D,
525 GL_RGB,
526 src_d->dwWidth, src_d->dwHeight,
528 GL_RGB,
529 GL_UNSIGNED_SHORT_5_6_5,
530 src_d->lpSurface);
531 } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00000001) {
532 /* Texture snooping */
533 SNOOP_5551();
535 glTexImage2D(GL_TEXTURE_2D,
537 GL_RGBA,
538 src_d->dwWidth, src_d->dwHeight,
540 GL_RGBA,
541 GL_UNSIGNED_SHORT_5_5_5_1,
542 src_d->lpSurface);
543 } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x0000000F) {
544 glTexImage2D(GL_TEXTURE_2D,
546 GL_RGBA,
547 src_d->dwWidth, src_d->dwHeight,
549 GL_RGBA,
550 GL_UNSIGNED_SHORT_4_4_4_4,
551 src_d->lpSurface);
552 } else if (src_d->ddpfPixelFormat.u5.dwRGBAlphaBitMask == 0x00008000) {
553 /* Converting the 1555 format in 5551 packed */
554 WORD *surface = (WORD *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, src_d->dwWidth * src_d->dwHeight * sizeof(WORD));
555 DWORD i;
556 WORD *src = (WORD *) src_d->lpSurface, *dst = surface;
558 for (i = 0; i < src_d->dwHeight * src_d->dwWidth; i++) {
559 *dst++ = (((*src & 0x8000) >> 15) |
560 ((*src & 0x7FFF) << 1));
561 src++;
564 glTexImage2D(GL_TEXTURE_2D,
566 GL_RGBA,
567 src_d->dwWidth, src_d->dwHeight,
569 GL_RGBA,
570 GL_UNSIGNED_SHORT_5_5_5_1,
571 surface);
573 HeapFree(GetProcessHeap(), 0, surface);
574 } else {
575 ERR("Unhandled texture format (bad Aplha channel for a 16 bit texture)\n");
577 } else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 24) {
578 glTexImage2D(GL_TEXTURE_2D,
580 GL_RGB,
581 src_d->dwWidth, src_d->dwHeight,
583 GL_RGB,
584 GL_UNSIGNED_BYTE,
585 src_d->lpSurface);
586 } else if (src_d->ddpfPixelFormat.u1.dwRGBBitCount == 32) {
587 glTexImage2D(GL_TEXTURE_2D,
589 GL_RGBA,
590 src_d->dwWidth, src_d->dwHeight,
592 GL_RGBA,
593 GL_UNSIGNED_BYTE,
594 src_d->lpSurface);
595 } else {
596 ERR("Unhandled texture format (bad RGB count)\n");
598 } else {
599 ERR("Unhandled texture format (neither RGB nor INDEX)\n");
602 glBindTexture(GL_TEXTURE_2D, current_texture);
604 LEAVE_GL();
607 return D3D_OK;
611 /*******************************************************************************
612 * IDirect3DTexture2 VTable
614 ICOM_VTABLE(IDirect3DTexture2) mesa_texture2_vtable =
616 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
617 /*** IUnknown methods ***/
618 IDirect3DTexture2Impl_QueryInterface,
619 IDirect3DTexture2Impl_AddRef,
620 IDirect3DTexture2Impl_Release,
621 /*** IDirect3DTexture methods ***/
622 IDirect3DTexture2Impl_GetHandle,
623 IDirect3DTexture2Impl_PaletteChanged,
624 IDirect3DTexture2Impl_Load
627 /*******************************************************************************
628 * IDirect3DTexture VTable
630 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
631 # define XCAST(fun) (typeof(mesa_texture_vtable.fun))
632 #else
633 # define XCAST(fun) (void*)
634 #endif
636 ICOM_VTABLE(IDirect3DTexture) mesa_texture_vtable =
638 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
639 /*** IUnknown methods ***/
640 XCAST(QueryInterface)IDirect3DTexture2Impl_QueryInterface,
641 XCAST(AddRef)IDirect3DTexture2Impl_AddRef,
642 XCAST(Release)IDirect3DTexture2Impl_Release,
643 /*** IDirect3DTexture methods ***/
644 IDirect3DTextureImpl_Initialize,
645 IDirect3DTextureImpl_GetHandle,
646 XCAST(PaletteChanged)IDirect3DTexture2Impl_PaletteChanged,
647 XCAST(Load)IDirect3DTexture2Impl_Load,
648 IDirect3DTextureImpl_Unload
651 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
652 #undef XCAST
653 #endif