2017-03-21 05:30:13 +00:00
|
|
|
#include "quakedef.h"
|
|
|
|
#include "winquake.h"
|
|
|
|
#ifdef D3D8QUAKE
|
|
|
|
#if !defined(HMONITOR_DECLARED) && (WINVER < 0x0500)
|
|
|
|
#define HMONITOR_DECLARED
|
|
|
|
DECLARE_HANDLE(HMONITOR);
|
|
|
|
#endif
|
2017-03-27 21:45:45 +00:00
|
|
|
|
|
|
|
#ifdef _XBOX
|
|
|
|
#include <xtl.h>
|
|
|
|
#define D3DLOCK_NOSYSLOCK 0
|
|
|
|
#define D3DLOCK_DISCARD 0
|
|
|
|
#endif
|
|
|
|
|
2017-03-21 05:30:13 +00:00
|
|
|
#include <d3d8.h>
|
|
|
|
extern LPDIRECT3DDEVICE8 pD3DDev8;
|
|
|
|
|
|
|
|
void D3D8_DestroyTexture (texid_t tex)
|
|
|
|
{
|
|
|
|
if (!tex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tex->ptr)
|
|
|
|
IDirect3DTexture8_Release((IDirect3DTexture8*)tex->ptr);
|
|
|
|
tex->ptr = NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-14 16:38:44 +00:00
|
|
|
qboolean D3D8_LoadTextureMips(image_t *tex, const struct pendingtextureinfo *mips)
|
2017-03-21 05:30:13 +00:00
|
|
|
{
|
|
|
|
qbyte *fte_restrict out, *fte_restrict in;
|
|
|
|
int x, y, i;
|
|
|
|
D3DLOCKED_RECT lock;
|
2018-03-04 14:41:16 +00:00
|
|
|
D3DFORMAT fmt = D3DFMT_UNKNOWN;
|
2017-03-21 05:30:13 +00:00
|
|
|
D3DSURFACE_DESC desc;
|
|
|
|
IDirect3DTexture8 *dt;
|
|
|
|
qboolean swap = false;
|
2017-12-28 16:24:50 +00:00
|
|
|
unsigned int blockwidth, blockheight, blockbytes = 1;
|
2017-03-21 05:30:13 +00:00
|
|
|
|
2018-03-04 14:41:16 +00:00
|
|
|
if (mips->type != PTI_2D)
|
|
|
|
return false; //fixme: cube and volumes should work
|
|
|
|
|
2017-03-21 05:30:13 +00:00
|
|
|
switch(mips->encoding)
|
|
|
|
{
|
|
|
|
case PTI_RGB565:
|
|
|
|
fmt = D3DFMT_R5G6B5;
|
|
|
|
break;
|
|
|
|
case PTI_RGBA4444://not supported on d3d9
|
|
|
|
return false;
|
|
|
|
case PTI_ARGB4444:
|
|
|
|
fmt = D3DFMT_A4R4G4B4;
|
|
|
|
break;
|
|
|
|
case PTI_RGBA5551://not supported on d3d9
|
|
|
|
return false;
|
|
|
|
case PTI_ARGB1555:
|
|
|
|
fmt = D3DFMT_A1R5G5B5;
|
|
|
|
break;
|
|
|
|
case PTI_RGBA8:
|
2017-12-28 16:24:50 +00:00
|
|
|
// fmt = D3DFMT_A8B8G8R8; //how do we check
|
2017-03-21 05:30:13 +00:00
|
|
|
fmt = D3DFMT_A8R8G8B8;
|
|
|
|
swap = true;
|
|
|
|
break;
|
|
|
|
case PTI_RGBX8:
|
|
|
|
// fmt = D3DFMT_X8B8G8R8;
|
|
|
|
fmt = D3DFMT_X8R8G8B8;
|
|
|
|
swap = true;
|
|
|
|
break;
|
|
|
|
case PTI_BGRA8:
|
|
|
|
fmt = D3DFMT_A8R8G8B8;
|
|
|
|
break;
|
|
|
|
case PTI_BGRX8:
|
|
|
|
fmt = D3DFMT_X8R8G8B8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
//too lazy to support these for now
|
2017-12-28 16:24:50 +00:00
|
|
|
case PTI_BC1_RGB:
|
|
|
|
case PTI_BC1_RGBA: //d3d doesn't distinguish between these
|
2017-03-21 05:30:13 +00:00
|
|
|
fmt = D3DFMT_DXT1;
|
|
|
|
break;
|
2017-12-28 16:24:50 +00:00
|
|
|
case PTI_BC2_RGBA:
|
2017-03-21 05:30:13 +00:00
|
|
|
fmt = D3DFMT_DXT3;
|
|
|
|
break;
|
2017-12-28 16:24:50 +00:00
|
|
|
case PTI_BC3_RGBA:
|
2017-03-21 05:30:13 +00:00
|
|
|
fmt = D3DFMT_DXT5;
|
|
|
|
break;
|
|
|
|
|
2018-03-04 14:41:16 +00:00
|
|
|
case PTI_EMULATED:
|
2017-03-21 05:30:13 +00:00
|
|
|
default: //no idea
|
2018-03-04 14:41:16 +00:00
|
|
|
break;
|
2017-03-21 05:30:13 +00:00
|
|
|
}
|
2018-03-04 14:41:16 +00:00
|
|
|
if (fmt == D3DFMT_UNKNOWN)
|
|
|
|
return false;
|
2017-03-21 05:30:13 +00:00
|
|
|
|
2017-12-28 16:24:50 +00:00
|
|
|
Image_BlockSizeForEncoding(mips->encoding, &blockbytes, &blockwidth, &blockheight);
|
|
|
|
|
2017-03-21 05:30:13 +00:00
|
|
|
if (!pD3DDev8)
|
|
|
|
return false; //can happen on errors
|
|
|
|
if (FAILED(IDirect3DDevice8_CreateTexture(pD3DDev8, mips->mip[0].width, mips->mip[0].height, mips->mipcount, 0, fmt, D3DPOOL_MANAGED, &dt)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < mips->mipcount; i++)
|
|
|
|
{
|
|
|
|
IDirect3DTexture8_GetLevelDesc(dt, i, &desc);
|
|
|
|
|
|
|
|
if (mips->mip[i].height != desc.Height || mips->mip[i].width != desc.Width)
|
|
|
|
{
|
|
|
|
IDirect3DTexture8_Release(dt);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirect3DTexture8_LockRect(dt, i, &lock, NULL, D3DLOCK_NOSYSLOCK|D3DLOCK_DISCARD);
|
|
|
|
//can't do it in one go. pitch might contain padding or be upside down.
|
|
|
|
if (!mips->mip[i].data)
|
|
|
|
;
|
|
|
|
else if (swap)
|
|
|
|
{
|
2017-12-28 16:24:50 +00:00
|
|
|
size_t rowbytes = ((mips->mip[i].width+blockwidth-1)/blockwidth)*blockbytes;
|
|
|
|
for (y = 0, out = lock.pBits, in = mips->mip[i].data; y < mips->mip[i].height; y++, out += lock.Pitch, in += rowbytes)
|
2017-03-21 05:30:13 +00:00
|
|
|
{
|
2017-12-28 16:24:50 +00:00
|
|
|
for (x = 0; x < rowbytes; x+=4)
|
2017-03-21 05:30:13 +00:00
|
|
|
{
|
|
|
|
out[x+0] = in[x+2];
|
|
|
|
out[x+1] = in[x+1];
|
|
|
|
out[x+2] = in[x+0];
|
|
|
|
out[x+3] = in[x+3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-28 16:24:50 +00:00
|
|
|
size_t rowbytes = ((mips->mip[i].width+blockwidth-1)/blockwidth)*blockbytes;
|
2017-12-28 16:44:53 +00:00
|
|
|
for (y = 0, out = lock.pBits, in = mips->mip[i].data; y < mips->mip[i].height; y+=blockheight, out += lock.Pitch, in += rowbytes)
|
2017-12-28 16:24:50 +00:00
|
|
|
memcpy(out, in, rowbytes);
|
2017-03-21 05:30:13 +00:00
|
|
|
}
|
|
|
|
IDirect3DTexture8_UnlockRect(dt, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D8_DestroyTexture(tex);
|
|
|
|
tex->ptr = dt;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void D3D8_UploadLightmap(lightmapinfo_t *lm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|