Commit 0b5e9d9f authored by Raphael Junqueira's avatar Raphael Junqueira Committed by Alexandre Julliard

- some cleanups

- more cubetextures fixes (now d3d8 sdk cubemap sample work almost perfectly) - add a new debug function "debug_d3dpool" and use it - add a new param (the device) for the conversions functions (because we need to check caps to see how to convert) - some crashes fixed in render to surface code with no stencil-depth surface - a very simple cliplane fix - a stupid palettes fix (stupid language) - begin of anisotropic filter support - begin of compressed textures support - a very useful debug functions: IDirect3DSurface8Impl_SaveSnapshot to dump surfaces as png ;) - many useful surfaces debug code (using SaveSnapshot)
parent 4e310082
......@@ -135,34 +135,34 @@ void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8
int i;
int j;
ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
TRACE("(%p) : About to load texture\n", This);
TRACE("(%p) : About to load texture: dirtified(%d)\n", This, This->Dirty);
for (i = 0; i < This->levels; i++) {
if (i == 0 && This->surfaces[0][i]->textureName != 0 && This->Dirty == FALSE) {
if (i == 0 && This->surfaces[0][0]->textureName != 0 && This->Dirty == FALSE) {
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
#if defined(GL_VERSION_1_3)
glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][i]->textureName);
glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][0]->textureName);
#else
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][i]->textureName);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][0]->textureName);
#endif
checkGLcall("glBindTexture");
TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][i], i, This->surfaces[0][i]->textureName);
TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][0], i, This->surfaces[0][0]->textureName);
/* No need to walk through all mip-map levels, since already all assigned */
i = This->levels;
} else {
if (i == 0) {
if (This->surfaces[0][i]->textureName == 0) {
glGenTextures(1, &This->surfaces[0][i]->textureName);
if (This->surfaces[0][0]->textureName == 0) {
glGenTextures(1, &This->surfaces[0][0]->textureName);
checkGLcall("glGenTextures");
TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][i], i, This->surfaces[0][i]->textureName);
TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][i], i, This->surfaces[0][0]->textureName);
}
#if defined(GL_VERSION_1_3)
glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][i]->textureName);
glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][0]->textureName);
#else
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][i]->textureName);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][0]->textureName);
#endif
checkGLcall("glBindTexture");
TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);
#if defined(GL_VERSION_1_3)
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, This->levels - 1);
......@@ -173,7 +173,7 @@ void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8
}
for (j = 0; j < 6; j++) {
IDirect3DSurface8Impl_CreateGLTexture((LPDIRECT3DSURFACE8) This->surfaces[j][i], cube_targets[j], i);
IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8) This->surfaces[j][i], cube_targets[j], i);
#if 0
TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, glFmt=%x, glType=%x, Mem=%p\n",
cube_targets[j],
......@@ -196,6 +196,12 @@ void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8
This->surfaces[j][i]->allocatedMemory);
checkGLcall("glTexImage2D");
#endif
#if 0
static int gen = 0;
char buffer[4096];
snprintf(buffer, sizeof(buffer), "/tmp/cube%d_face%d_level%d_%d.png", This->surfaces[0][0]->textureName, j, i, ++gen);
IDirect3DSurface8Impl_SaveSnapshot((LPDIRECT3DSURFACE8) This->surfaces[j][i], buffer);
#endif
}
/* Removed glTexParameterf now TextureStageStates are initialized at startup */
This->Dirty = FALSE;
......
......@@ -168,6 +168,7 @@ typedef enum _GL_SupportedExt {
EXT_PALETTED_TEXTURE,
EXT_SECONDARY_COLOR,
EXT_TEXTURE_COMPRESSION_S3TC,
EXT_TEXTURE_FILTER_ANISOTROPIC,
EXT_TEXTURE_LOD,
EXT_TEXTURE_LOD_BIAS,
EXT_VERTEX_WEIGHTING,
......@@ -608,7 +609,8 @@ extern HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D
extern HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface);
/* internal Interfaces */
extern HRESULT WINAPI IDirect3DSurface8Impl_CreateGLTexture(LPDIRECT3DSURFACE8 iface, GLenum gl_target, GLenum gl_level);
extern HRESULT WINAPI IDirect3DSurface8Impl_LoadTexture(LPDIRECT3DSURFACE8 iface, GLenum gl_target, GLenum gl_level);
extern HRESULT WINAPI IDirect3DSurface8Impl_SaveSnapshot(LPDIRECT3DSURFACE8 iface, const char* filename);
/* ------------------ */
......@@ -1228,15 +1230,11 @@ extern DWORD WINAPI IDirect3DPixelShaderImpl_GetVersion(IDirect3DPixelShaderImpl
* to see how not defined it here
*/
void setupTextureStates(LPDIRECT3DDEVICE8 iface, DWORD Stage);
SHORT bytesPerPixel(D3DFORMAT fmt);
GLint fmt2glintFmt(D3DFORMAT fmt);
GLenum fmt2glFmt(D3DFORMAT fmt);
GLenum fmt2glType(D3DFORMAT fmt);
SHORT D3DFmtGetBpp(D3DFORMAT fmt);
GLint D3DFmt2GLIntFmt(D3DFORMAT fmt);
GLenum D3DFmt2GLFmt(D3DFORMAT fmt);
GLenum D3DFmt2GLType(D3DFORMAT fmt);
SHORT D3DFmtGetBpp(IDirect3DDevice8Impl* This, D3DFORMAT fmt);
GLint D3DFmt2GLIntFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt);
GLenum D3DFmt2GLFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt);
GLenum D3DFmt2GLType(IDirect3DDevice8Impl* This, D3DFORMAT fmt);
GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt);
GLenum D3DFmt2GLDepthType(D3DFORMAT fmt);
......@@ -1259,5 +1257,6 @@ const char* debug_d3dusage(DWORD usage);
const char* debug_d3dformat(D3DFORMAT fmt);
const char* debug_d3dressourcetype(D3DRESOURCETYPE res);
const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
const char* debug_d3dpool(D3DPOOL Pool);
#endif /* __WINE_D3DX8_PRIVATE_H */
......@@ -513,7 +513,7 @@ HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps (LPDIRECT3D8 iface,
D3DSTENCILCAPS_REPLACE |
D3DSTENCILCAPS_ZERO;
#if defined(GL_VERSION_1_4) || defined(GL_EXT_stencil_wrap)
pCaps->StencilCaps |= D3DSTENCILCAPS_DECR |
pCaps->StencilCaps |= D3DSTENCILCAPS_DECR |
D3DSTENCILCAPS_INCR;
#endif
......@@ -603,8 +603,13 @@ HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps (LPDIRECT3D8 iface,
pCaps->MaxStreams = 2; /* HACK: Some games want at least 2 */
pCaps->MaxStreamStride = 1024;
#if 1
pCaps->VertexShaderVersion = D3DVS_VERSION(1,1);
pCaps->MaxVertexShaderConst = D3D8_VSHADER_MAX_CONSTANTS;
#else
pCaps->VertexShaderVersion = 0;
pCaps->MaxVertexShaderConst = D3D8_VSHADER_MAX_CONSTANTS;
#endif
#if 0
pCaps->PixelShaderVersion = D3DPS_VERSION(1,1);
......@@ -837,9 +842,9 @@ HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
object->renderTarget = object->frontBuffer;
IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->renderTarget);
object->stencilBufferTarget = object->depthStencilBuffer;
if (NULL != object->stencilBufferTarget)
if (NULL != object->stencilBufferTarget) {
IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->stencilBufferTarget);
}
/* Now override the surface's Flip method (if in double buffering) ?COPIED from DDRAW!?
((x11_ds_private *) surface->private)->opengl_flip = TRUE;
......@@ -875,8 +880,8 @@ HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
checkGLcall("glLightModel (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);");
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
/*
* Initialize openGL extension related variables
......@@ -955,6 +960,9 @@ HRESULT WINAPI IDirect3D8Impl_CreateDevice (LPDIRECT3D8 iface,
} else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
FIXME(" FOUND: EXT Texture S3TC compression support\n");
This->gl_info.supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
} else if (strcmp(ThisExtn, "GL_EXT_texture_filter_anisotropic") == 0) {
FIXME(" FOUND: EXT Texture Anisotropic filter support\n");
This->gl_info.supported[EXT_TEXTURE_FILTER_ANISOTROPIC] = TRUE;
} else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
FIXME(" FOUND: EXT Texture LOD support\n");
This->gl_info.supported[EXT_TEXTURE_LOD] = TRUE;
......
......@@ -25,6 +25,7 @@
#include "winuser.h"
#include "wingdi.h"
#include "wine/debug.h"
#include <stdio.h>
#include "d3d8_private.h"
......@@ -204,8 +205,8 @@ HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKE
This->lockedRect.bottom - j - 1,
This->lockedRect.right - This->lockedRect.left,
1,
D3DFmt2GLFmt(This->myDesc.Format),
D3DFmt2GLType(This->myDesc.Format),
D3DFmt2GLFmt(This->Device, This->myDesc.Format),
D3DFmt2GLType(This->Device, This->myDesc.Format),
pLockedRect->pBits);
vcheckGLcall("glReadPixels");
}
......@@ -398,12 +399,14 @@ ICOM_VTABLE(IDirect3DSurface8) Direct3DSurface8_Vtbl =
IDirect3DSurface8Impl_UnlockRect,
};
HRESULT WINAPI IDirect3DSurface8Impl_CreateGLTexture(LPDIRECT3DSURFACE8 iface, GLenum gl_target, GLenum gl_level) {
HRESULT WINAPI IDirect3DSurface8Impl_LoadTexture(LPDIRECT3DSURFACE8 iface, GLenum gl_target, GLenum gl_level) {
ICOM_THIS(IDirect3DSurface8Impl,iface);
if ((This->myDesc.Format == D3DFMT_P8 || This->myDesc.Format == D3DFMT_A8P8) &&
!GL_SUPPORT_DEV(EXT_PALETTED_TEXTURE, This->Device)) {
if ((This->myDesc.Format == D3DFMT_P8 || This->myDesc.Format == D3DFMT_A8P8)
#if defined(GL_EXT_paletted_texture)
&& !GL_SUPPORT_DEV(EXT_PALETTED_TEXTURE, This->Device)
#endif
) {
/**
* wanted a paletted texture and not really support it in HW
* so software emulation code begin
......@@ -450,27 +453,133 @@ HRESULT WINAPI IDirect3DSurface8Impl_CreateGLTexture(LPDIRECT3DSURFACE8 iface, G
return D3D_OK;
}
TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
gl_target,
gl_level,
D3DFmt2GLIntFmt(This->myDesc.Format),
This->myDesc.Width,
This->myDesc.Height,
0,
D3DFmt2GLFmt(This->myDesc.Format),
D3DFmt2GLType(This->myDesc.Format),
This->allocatedMemory);
glTexImage2D(gl_target,
gl_level,
D3DFmt2GLIntFmt(This->myDesc.Format),
This->myDesc.Width,
This->myDesc.Height,
0,
D3DFmt2GLFmt(This->myDesc.Format),
D3DFmt2GLType(This->myDesc.Format),
This->allocatedMemory);
checkGLcall("glTexImage2D");
if (This->myDesc.Format == D3DFMT_DXT1 ||
This->myDesc.Format == D3DFMT_DXT3 ||
This->myDesc.Format == D3DFMT_DXT5) {
#if defined(GL_EXT_texture_compression_s3tc)
if (GL_SUPPORT_DEV(EXT_TEXTURE_COMPRESSION_S3TC, This->Device)) {
TRACE("Calling glCompressedTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, sz=%d, Mem=%p\n",
gl_target,
gl_level,
D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
This->myDesc.Width,
This->myDesc.Height,
0,
This->myDesc.Size,
This->allocatedMemory);
glCompressedTexImage2DARB(gl_target,
gl_level,
D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
This->myDesc.Width,
This->myDesc.Height,
0,
This->myDesc.Size,
This->allocatedMemory);
checkGLcall("glCommpressedTexTexImage2D");
}
#endif
} else {
TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
gl_target,
gl_level,
D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
This->myDesc.Width,
This->myDesc.Height,
0,
D3DFmt2GLFmt(This->Device, This->myDesc.Format),
D3DFmt2GLType(This->Device, This->myDesc.Format),
This->allocatedMemory);
glTexImage2D(gl_target,
gl_level,
D3DFmt2GLIntFmt(This->Device, This->myDesc.Format),
This->myDesc.Width,
This->myDesc.Height,
0,
D3DFmt2GLFmt(This->Device, This->myDesc.Format),
D3DFmt2GLType(This->Device, This->myDesc.Format),
This->allocatedMemory);
checkGLcall("glTexImage2D");
#if 0
{
static int gen = 0;
char buffer[4096];
++gen;
if ((gen % 10) == 0) {
snprintf(buffer, sizeof(buffer), "/tmp/surface%d_level%d_%d.png", gl_target, gl_level, gen);
IDirect3DSurface8Impl_SaveSnapshot((LPDIRECT3DSURFACE8) This, buffer);
}
}
#endif
}
return D3D_OK;
}
#include <errno.h>
HRESULT WINAPI IDirect3DSurface8Impl_SaveSnapshot(LPDIRECT3DSURFACE8 iface, const char* filename) {
FILE* f = NULL;
int i;
ICOM_THIS(IDirect3DSurface8Impl,iface);
f = fopen(filename, "w+");
if (NULL == f) {
ERR("opening of %s failed with: %s\n", filename, strerror(errno));
return D3DERR_INVALIDCALL;
}
TRACE("opened %s\n", filename);
fprintf(f, "P6\n%u %u\n255\n", This->myDesc.Width, This->myDesc.Height);
switch (This->myDesc.Format) {
case D3DFMT_X8R8G8B8:
case D3DFMT_A8R8G8B8:
{
DWORD color;
for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
color = ((DWORD*) This->allocatedMemory)[i];
fputc((color >> 16) & 0xFF, f);
fputc((color >> 8) & 0xFF, f);
fputc((color >> 0) & 0xFF, f);
}
}
break;
case D3DFMT_R8G8B8:
{
BYTE* color;
for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
color = ((BYTE*) This->allocatedMemory) + (3 * i);
fputc((color[0]) & 0xFF, f);
fputc((color[1]) & 0xFF, f);
fputc((color[2]) & 0xFF, f);
}
}
break;
case D3DFMT_A1R5G5B5:
{
WORD color;
for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
color = ((WORD*) This->allocatedMemory)[i];
fputc((color >> 10) & 0xFF, f);
fputc((color >> 5) & 0xFF, f);
fputc((color >> 0) & 0xFF, f);
}
}
break;
case D3DFMT_R5G6B5:
{
WORD color;
for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
color = ((WORD*) This->allocatedMemory)[i];
fputc((color >> 11) & 0xFF, f);
fputc((color >> 5) & 0xFF, f);
fputc((color >> 0) & 0xFF, f);
}
}
break;
default:
FIXME("Unimplemented dump mode format(%u,%s)\n", This->myDesc.Format, debug_d3dformat(This->myDesc.Format));
}
fclose(f);
return D3D_OK;
}
......@@ -31,10 +31,10 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
/* IDirect3DTexture8 IUnknown parts follow: */
HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface,REFIID riid,LPVOID *ppobj)
HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj)
{
ICOM_THIS(IDirect3DTexture8Impl,iface);
TRACE("(%p) : QueryInterface\n", This);
TRACE("(%p) : QueryInterface for %s\n", This, debugstr_guid(riid));
if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IDirect3DResource8)
|| IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
......@@ -44,7 +44,7 @@ HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface,REF
return D3D_OK;
}
WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
return E_NOINTERFACE;
}
......@@ -134,7 +134,7 @@ void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
}
IDirect3DSurface8Impl_CreateGLTexture((LPDIRECT3DSURFACE8) This->surfaces[i], GL_TEXTURE_2D, i);
IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8) This->surfaces[i], GL_TEXTURE_2D, i);
#if 0
TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
GL_TEXTURE_2D,
......@@ -194,7 +194,8 @@ HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 ifa
TRACE("(%p) Level (%d)\n", This, Level);
return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8) This->surfaces[Level], pDesc);
} else {
FIXME("(%p) Level (%d)\n", This, Level);
FIXME("Levels seems too high?!!\n");
return D3DERR_INVALIDCALL;
}
return D3D_OK;
}
......@@ -218,6 +219,7 @@ HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface,
TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
} else {
FIXME("Levels seems too high?!!\n");
return D3DERR_INVALIDCALL;
}
return hr;
}
......@@ -230,8 +232,9 @@ HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface
TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
} else {
FIXME("Levels seems too high?!!\n");
return D3DERR_INVALIDCALL;
}
return D3D_OK;
return hr;
}
HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT* pDirtyRect) {
ICOM_THIS(IDirect3DTexture8Impl,iface);
......
......@@ -158,10 +158,99 @@ const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType) {
}
}
const char* debug_d3dpool(D3DPOOL Pool) {
switch (Pool) {
#define POOL_TO_STR(p) case p: return #p;
POOL_TO_STR(D3DPOOL_DEFAULT);
POOL_TO_STR(D3DPOOL_MANAGED);
POOL_TO_STR(D3DPOOL_SYSTEMMEM);
POOL_TO_STR(D3DPOOL_SCRATCH);
#undef POOL_TO_STR
default:
FIXME("Unrecognized %u D3DPOOL!\n", Pool);
return "unrecognized";
}
}
/*
* Simple utility routines used for dx -> gl mapping of byte formats
*/
SHORT bytesPerPixel(D3DFORMAT fmt) {
int D3DPrimitiveListGetVertexSize(D3DPRIMITIVETYPE PrimitiveType, int iNumPrim) {
switch (PrimitiveType) {
case D3DPT_POINTLIST: return iNumPrim;
case D3DPT_LINELIST: return iNumPrim * 2;
case D3DPT_LINESTRIP: return iNumPrim + 1;
case D3DPT_TRIANGLELIST: return iNumPrim * 3;
case D3DPT_TRIANGLESTRIP: return iNumPrim + 2;
case D3DPT_TRIANGLEFAN: return iNumPrim + 2;
default:
FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
return 0;
}
}
int D3DPrimitive2GLenum(D3DPRIMITIVETYPE PrimitiveType) {
switch (PrimitiveType) {
case D3DPT_POINTLIST: return GL_POINTS;
case D3DPT_LINELIST: return GL_LINES;
case D3DPT_LINESTRIP: return GL_LINE_STRIP;
case D3DPT_TRIANGLELIST: return GL_TRIANGLES;
case D3DPT_TRIANGLESTRIP: return GL_TRIANGLE_STRIP;
case D3DPT_TRIANGLEFAN: return GL_TRIANGLE_FAN;
default:
FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
return GL_POLYGON;
}
}
int D3DFVFGetSize(D3DFORMAT fvf) {
int ret = 0;
if (fvf & D3DFVF_XYZ) ret += 3 * sizeof(float);
else if (fvf & D3DFVF_XYZRHW) ret += 4 * sizeof(float);
if (fvf & D3DFVF_NORMAL) ret += 3 * sizeof(float);
if (fvf & D3DFVF_PSIZE) ret += sizeof(float);
if (fvf & D3DFVF_DIFFUSE) ret += sizeof(DWORD);
if (fvf & D3DFVF_SPECULAR) ret += sizeof(DWORD);
/*if (fvf & D3DFVF_TEX1) ret += 1;*/
return ret;
}
GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt) {
switch (fmt) {
/* depth/stencil buffer */
case D3DFMT_D16_LOCKABLE:
case D3DFMT_D16:
case D3DFMT_D15S1:
case D3DFMT_D24X4S4:
case D3DFMT_D24S8:
case D3DFMT_D24X8:
case D3DFMT_D32:
return GL_DEPTH_COMPONENT;
default:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
}
return 0;
}
GLenum D3DFmt2GLDepthType(D3DFORMAT fmt) {
switch (fmt) {
/* depth/stencil buffer */
case D3DFMT_D15S1:
case D3DFMT_D16_LOCKABLE:
case D3DFMT_D16:
return GL_UNSIGNED_SHORT;
case D3DFMT_D24X4S4:
case D3DFMT_D24S8:
case D3DFMT_D24X8:
case D3DFMT_D32:
return GL_UNSIGNED_INT;
default:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
}
return 0;
}
SHORT D3DFmtGetBpp(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
SHORT retVal;
switch (fmt) {
......@@ -199,10 +288,13 @@ SHORT bytesPerPixel(D3DFORMAT fmt) {
return retVal;
}
GLint fmt2glintFmt(D3DFORMAT fmt) {
GLint D3DFmt2GLIntFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
GLint retVal;
switch (fmt) {
case D3DFMT_P8: retVal = GL_COLOR_INDEX8_EXT; break;
case D3DFMT_A8P8: retVal = GL_COLOR_INDEX8_EXT; break;
case D3DFMT_A4R4G4B4: retVal = GL_RGBA4; break;
case D3DFMT_A8R8G8B8: retVal = GL_RGBA8; break;
case D3DFMT_X8R8G8B8: retVal = GL_RGB8; break;
......@@ -213,14 +305,29 @@ GLint fmt2glintFmt(D3DFORMAT fmt) {
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
retVal = GL_RGB8;
}
#if defined(GL_EXT_texture_compression_s3tc)
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
switch (fmt) {
case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
default:
/* stupid compiler */
break;
}
}
#endif
TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
return retVal;
}
GLenum fmt2glFmt(D3DFORMAT fmt) {
GLenum D3DFmt2GLFmt(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
GLenum retVal;
switch (fmt) {
case D3DFMT_P8: retVal = GL_COLOR_INDEX; break;
case D3DFMT_A8P8: retVal = GL_COLOR_INDEX; break;
case D3DFMT_A4R4G4B4: retVal = GL_BGRA; break;
case D3DFMT_A8R8G8B8: retVal = GL_BGRA; break;
case D3DFMT_X8R8G8B8: retVal = GL_BGRA; break;
......@@ -231,14 +338,29 @@ GLenum fmt2glFmt(D3DFORMAT fmt) {
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
retVal = GL_BGR;
}
#if defined(GL_EXT_texture_compression_s3tc)
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
switch (fmt) {
case D3DFMT_DXT1: retVal = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case D3DFMT_DXT3: retVal = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
case D3DFMT_DXT5: retVal = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
default:
/* stupid compiler */
break;
}
}
#endif
TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
return retVal;
}
GLenum fmt2glType(D3DFORMAT fmt) {
GLenum D3DFmt2GLType(IDirect3DDevice8Impl* This, D3DFORMAT fmt) {
GLenum retVal;
switch (fmt) {
case D3DFMT_P8: retVal = GL_UNSIGNED_BYTE; break;
case D3DFMT_A8P8: retVal = GL_UNSIGNED_BYTE; break;
case D3DFMT_A4R4G4B4: retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
case D3DFMT_A8R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
case D3DFMT_X8R8G8B8: retVal = GL_UNSIGNED_BYTE; break;
......@@ -249,101 +371,22 @@ GLenum fmt2glType(D3DFORMAT fmt) {
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
retVal = GL_UNSIGNED_BYTE;
}
#if defined(GL_EXT_texture_compression_s3tc)
if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
switch (fmt) {
case D3DFMT_DXT1: retVal = 0; break;
case D3DFMT_DXT3: retVal = 0; break;
case D3DFMT_DXT5: retVal = 0; break;
default:
/* stupid compiler */
break;
}
}
#endif
TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
return retVal;
}
int D3DPrimitiveListGetVertexSize(D3DPRIMITIVETYPE PrimitiveType, int iNumPrim) {
switch (PrimitiveType) {
case D3DPT_POINTLIST: return iNumPrim;
case D3DPT_LINELIST: return iNumPrim * 2;
case D3DPT_LINESTRIP: return iNumPrim + 1;
case D3DPT_TRIANGLELIST: return iNumPrim * 3;
case D3DPT_TRIANGLESTRIP: return iNumPrim + 2;
case D3DPT_TRIANGLEFAN: return iNumPrim + 2;
default:
FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
return 0;
}
}
int D3DPrimitive2GLenum(D3DPRIMITIVETYPE PrimitiveType) {
switch (PrimitiveType) {
case D3DPT_POINTLIST: return GL_POINTS;
case D3DPT_LINELIST: return GL_LINES;
case D3DPT_LINESTRIP: return GL_LINE_STRIP;
case D3DPT_TRIANGLELIST: return GL_TRIANGLES;
case D3DPT_TRIANGLESTRIP: return GL_TRIANGLE_STRIP;
case D3DPT_TRIANGLEFAN: return GL_TRIANGLE_FAN;
default:
FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
return GL_POLYGON;
}
}
int D3DFVFGetSize(D3DFORMAT fvf) {
int ret = 0;
if (fvf & D3DFVF_XYZ) ret += 3 * sizeof(float);
else if (fvf & D3DFVF_XYZRHW) ret += 4 * sizeof(float);
if (fvf & D3DFVF_NORMAL) ret += 3 * sizeof(float);
if (fvf & D3DFVF_PSIZE) ret += sizeof(float);
if (fvf & D3DFVF_DIFFUSE) ret += sizeof(DWORD);
if (fvf & D3DFVF_SPECULAR) ret += sizeof(DWORD);
/*if (fvf & D3DFVF_TEX1) ret += 1;*/
return ret;
}
GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt) {
switch (fmt) {
/* depth/stencil buffer */
case D3DFMT_D16_LOCKABLE:
case D3DFMT_D16:
case D3DFMT_D15S1:
case D3DFMT_D24X4S4:
case D3DFMT_D24S8:
case D3DFMT_D24X8:
case D3DFMT_D32:
return GL_DEPTH_COMPONENT;
default:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
}
return 0;
}
GLenum D3DFmt2GLDepthType(D3DFORMAT fmt) {
switch (fmt) {
/* depth/stencil buffer */
case D3DFMT_D15S1:
case D3DFMT_D16_LOCKABLE:
case D3DFMT_D16:
return GL_UNSIGNED_SHORT;
case D3DFMT_D24X4S4:
case D3DFMT_D24S8:
case D3DFMT_D24X8:
case D3DFMT_D32:
return GL_UNSIGNED_INT;
default:
FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
}
return 0;
}
SHORT D3DFmtGetBpp(D3DFORMAT fmt) {
return bytesPerPixel(fmt);
}
GLint D3DFmt2GLIntFmt(D3DFORMAT fmt) {
return fmt2glintFmt(fmt);
}
GLenum D3DFmt2GLFmt(D3DFORMAT fmt) {
return fmt2glFmt(fmt);
}
GLenum D3DFmt2GLType(D3DFORMAT fmt) {
return fmt2glType(fmt);
}
int SOURCEx_RGB_EXT(DWORD arg) {
switch(arg) {
case D3DTSS_COLORARG0: return GL_SOURCE2_RGB_EXT;
......
......@@ -140,23 +140,23 @@ void WINAPI IDirect3DVolumeTexture8Impl_PreLoad(LPDIRECT3DVOLUMETEXTU
TRACE("Calling glTexImage3D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n",
GL_TEXTURE_3D,
i,
fmt2glintFmt(This->format),
D3DFmt2GLIntFmt(This->Device, This->format),
This->volumes[i]->myDesc.Width,
This->volumes[i]->myDesc.Height,
This->volumes[i]->myDesc.Depth,
0,
fmt2glFmt(This->format),
fmt2glType(This->format),
D3DFmt2GLFmt(This->Device, This->format),
D3DFmt2GLType(This->Device, This->format),
This->volumes[i]->allocatedMemory);
glTexImage3D(GL_TEXTURE_3D,
i,
fmt2glintFmt(This->format),
D3DFmt2GLIntFmt(This->Device, This->format),
This->volumes[i]->myDesc.Width,
This->volumes[i]->myDesc.Height,
This->volumes[i]->myDesc.Depth,
0,
fmt2glFmt(This->format),
fmt2glType(This->format),
D3DFmt2GLFmt(This->Device, This->format),
D3DFmt2GLType(This->Device, This->format),
This->volumes[i]->allocatedMemory);
checkGLcall("glTexImage3D");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment