Use D3D9Ex when available

This hopefully works around crashes in Intel D3D9 support in Windows 8.1.
main
Sam Lantinga 2014-05-31 11:37:12 -07:00
parent 52222db255
commit 49c53fd280
2 changed files with 208 additions and 149 deletions

View File

@ -124,6 +124,7 @@ static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
static void D3D_WindowEvent(SDL_Renderer * renderer, static void D3D_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event); const SDL_WindowEvent *event);
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, const SDL_Rect * rect, const void *pixels,
int pitch); int pitch);
@ -190,12 +191,18 @@ typedef struct
typedef struct typedef struct
{ {
IDirect3DTexture9 *texture; IDirect3DTexture9 *texture;
IDirect3DTexture9 *staging;
} D3D_TextureRep;
typedef struct
{
D3D_TextureRep texture;
D3DTEXTUREFILTERTYPE scaleMode; D3DTEXTUREFILTERTYPE scaleMode;
/* YV12 texture support */ /* YV12 texture support */
SDL_bool yuv; SDL_bool yuv;
IDirect3DTexture9 *utexture; D3D_TextureRep utexture;
IDirect3DTexture9 *vtexture; D3D_TextureRep vtexture;
Uint8 *pixels; Uint8 *pixels;
int pitch; int pitch;
SDL_Rect locked_rect; SDL_Rect locked_rect;
@ -408,6 +415,8 @@ D3D_Reset(SDL_Renderer * renderer)
for (texture = renderer->textures; texture; texture = texture->next) { for (texture = renderer->textures; texture; texture = texture->next) {
if (texture->access == SDL_TEXTUREACCESS_TARGET) { if (texture->access == SDL_TEXTUREACCESS_TARGET) {
D3D_DestroyTexture(renderer, texture); D3D_DestroyTexture(renderer, texture);
} else {
D3D_RecreateTexture(renderer, texture);
} }
} }
@ -805,74 +814,58 @@ GetScaleQuality(void)
} }
static int static int
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, int w, int h)
{ {
D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
D3D_TextureData *data;
D3DPOOL pool;
DWORD usage;
HRESULT result; HRESULT result;
data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data)); result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
if (!data) { PixelFormatToD3DFMT(format),
return SDL_OutOfMemory(); D3DPOOL_DEFAULT, &texture->texture, NULL);
}
data->scaleMode = GetScaleQuality();
texture->driverdata = data;
#ifdef USE_DYNAMIC_TEXTURE
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
pool = D3DPOOL_DEFAULT;
usage = D3DUSAGE_DYNAMIC;
} else
#endif
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
/* D3DPOOL_MANAGED does not work with D3DUSAGE_RENDERTARGET */
pool = D3DPOOL_DEFAULT;
usage = D3DUSAGE_RENDERTARGET;
} else {
pool = D3DPOOL_MANAGED;
usage = 0;
}
result =
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
texture->h, 1, usage,
PixelFormatToD3DFMT(texture->format),
pool, &data->texture, NULL);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("CreateTexture()", result); return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
} }
if (texture->format == SDL_PIXELFORMAT_YV12 || if (usage != D3DUSAGE_RENDERTARGET) {
texture->format == SDL_PIXELFORMAT_IYUV) { result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
data->yuv = SDL_TRUE; PixelFormatToD3DFMT(format),
D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
result =
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w / 2,
texture->h / 2, 1, usage,
PixelFormatToD3DFMT(texture->format),
pool, &data->utexture, NULL);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("CreateTexture()", result); return D3D_SetError("CreateTexture(D3DPOOL_SYSTEMMEM)", result);
}
result =
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w / 2,
texture->h / 2, 1, usage,
PixelFormatToD3DFMT(texture->format),
pool, &data->vtexture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture()", result);
} }
} }
return 0; return 0;
} }
static int static int
D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool full_texture, int x, int y, int w, int h, const void *pixels, int pitch) D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int w, int h)
{
HRESULT result;
if (!texture->texture) {
return 0;
}
IDirect3DTexture9_Release(texture->texture);
result = IDirect3DDevice9_CreateTexture(device, w, h, 1, 0,
PixelFormatToD3DFMT(format),
D3DPOOL_DEFAULT, &texture->texture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
}
result = IDirect3DTexture9_AddDirtyRect(texture->staging, NULL);
if (FAILED(result)) {
return D3D_SetError("AddDirtyRect()", result);
}
result = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture->staging, (IDirect3DBaseTexture9 *)texture->texture);
if (FAILED(result)) {
return D3D_SetError("UpdateTexture()", result);
}
return 0;
}
static int
D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int x, int y, int w, int h, const void *pixels, int pitch)
{ {
RECT d3drect; RECT d3drect;
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
@ -881,16 +874,11 @@ D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool fu
int row, length; int row, length;
HRESULT result; HRESULT result;
if (full_texture) { d3drect.left = x;
result = IDirect3DTexture9_LockRect(texture, 0, &locked, NULL, D3DLOCK_DISCARD); d3drect.right = x + w;
} else { d3drect.top = y;
d3drect.left = x; d3drect.bottom = y + h;
d3drect.right = x + w; result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0);
d3drect.top = y;
d3drect.bottom = y + h;
result = IDirect3DTexture9_LockRect(texture, 0, &locked, &d3drect, 0);
}
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("LockRect()", result); return D3D_SetError("LockRect()", result);
} }
@ -913,46 +901,114 @@ D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool fu
dst += locked.Pitch; dst += locked.Pitch;
} }
} }
IDirect3DTexture9_UnlockRect(texture, 0); IDirect3DTexture9_UnlockRect(texture->staging, 0);
IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture->staging, (IDirect3DBaseTexture9 *)texture->texture);
return 0; return 0;
} }
static void
D3D_DestroyTextureRep(D3D_TextureRep *texture)
{
if (texture->texture) {
IDirect3DTexture9_Release(texture->texture);
texture->texture = NULL;
}
if (texture->staging) {
IDirect3DTexture9_Release(texture->staging);
texture->staging = NULL;
}
}
static int
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_TextureData *texturedata;
DWORD usage;
texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata));
if (!texturedata) {
return SDL_OutOfMemory();
}
texturedata->scaleMode = GetScaleQuality();
texture->driverdata = texturedata;
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
usage = D3DUSAGE_RENDERTARGET;
} else {
usage = 0;
}
if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, texture->w, texture->h) < 0) {
return -1;
}
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
texturedata->yuv = SDL_TRUE;
if (D3D_CreateTextureRep(data->device, &texturedata->utexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
if (D3D_CreateTextureRep(data->device, &texturedata->vtexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
}
return 0;
}
static int
D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
if (D3D_RecreateTextureRep(data->device, &texturedata->texture, texture->format, texture->w, texture->h) < 0) {
return -1;
}
if (texturedata->yuv) {
if (D3D_RecreateTextureRep(data->device, &texturedata->utexture, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
if (D3D_RecreateTextureRep(data->device, &texturedata->vtexture, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
}
return 0;
}
static int static int
D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch) const SDL_Rect * rect, const void *pixels, int pitch)
{ {
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
SDL_bool full_texture = SDL_FALSE; D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
#ifdef USE_DYNAMIC_TEXTURE if (!texturedata) {
if (texture->access == SDL_TEXTUREACCESS_STREAMING &&
rect->x == 0 && rect->y == 0 &&
rect->w == texture->w && rect->h == texture->h) {
full_texture = SDL_TRUE;
}
#endif
if (!data) {
SDL_SetError("Texture is not currently available"); SDL_SetError("Texture is not currently available");
return -1; return -1;
} }
if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) { if (D3D_UpdateTextureRep(data->device, &texturedata->texture, texture->format, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
return -1; return -1;
} }
if (data->yuv) { if (texturedata->yuv) {
/* Skip to the correct offset into the next texture */ /* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
if (D3D_UpdateTextureInternal(texture->format == SDL_PIXELFORMAT_YV12 ? data->vtexture : data->utexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) { if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->vtexture : &texturedata->utexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) {
return -1; return -1;
} }
/* Skip to the correct offset into the next texture */ /* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4); pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4);
if (D3D_UpdateTextureInternal(texture->format == SDL_PIXELFORMAT_YV12 ? data->utexture : data->vtexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) { if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->utexture : &texturedata->vtexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) {
return -1; return -1;
} }
} }
@ -966,29 +1022,21 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const Uint8 *Uplane, int Upitch, const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch) const Uint8 *Vplane, int Vpitch)
{ {
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
SDL_bool full_texture = SDL_FALSE; D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
#ifdef USE_DYNAMIC_TEXTURE if (!texturedata) {
if (texture->access == SDL_TEXTUREACCESS_STREAMING &&
rect->x == 0 && rect->y == 0 &&
rect->w == texture->w && rect->h == texture->h) {
full_texture = SDL_TRUE;
}
#endif
if (!data) {
SDL_SetError("Texture is not currently available"); SDL_SetError("Texture is not currently available");
return -1; return -1;
} }
if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) { if (D3D_UpdateTextureRep(data->device, &texturedata->texture, texture->format, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
return -1; return -1;
} }
if (D3D_UpdateTextureInternal(data->utexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) { if (D3D_UpdateTextureRep(data->device, &texturedata->utexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) {
return -1; return -1;
} }
if (D3D_UpdateTextureInternal(data->vtexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) { if (D3D_UpdateTextureRep(data->device, &texturedata->vtexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) {
return -1; return -1;
} }
return 0; return 0;
@ -998,37 +1046,39 @@ static int
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch) const SDL_Rect * rect, void **pixels, int *pitch)
{ {
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
RECT d3drect;
D3DLOCKED_RECT locked;
HRESULT result;
if (!data) { if (!texturedata) {
SDL_SetError("Texture is not currently available"); SDL_SetError("Texture is not currently available");
return -1; return -1;
} }
if (data->yuv) { texturedata->locked_rect = *rect;
if (texturedata->yuv) {
/* It's more efficient to upload directly... */ /* It's more efficient to upload directly... */
if (!data->pixels) { if (!texturedata->pixels) {
data->pitch = texture->w; texturedata->pitch = texture->w;
data->pixels = (Uint8 *)SDL_malloc((texture->h * data->pitch * 3) / 2); texturedata->pixels = (Uint8 *)SDL_malloc((texture->h * texturedata->pitch * 3) / 2);
if (!data->pixels) { if (!texturedata->pixels) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
} }
data->locked_rect = *rect;
*pixels = *pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch + (void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format)); rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = data->pitch; *pitch = texturedata->pitch;
} else { } else {
RECT d3drect;
D3DLOCKED_RECT locked;
HRESULT result;
d3drect.left = rect->x; d3drect.left = rect->x;
d3drect.right = rect->x + rect->w; d3drect.right = rect->x + rect->w;
d3drect.top = rect->y; d3drect.top = rect->y;
d3drect.bottom = rect->y + rect->h; d3drect.bottom = rect->y + rect->h;
result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0); result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("LockRect()", result); return D3D_SetError("LockRect()", result);
} }
@ -1041,20 +1091,22 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
static void static void
D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
if (!data) { if (!texturedata) {
return; return;
} }
if (data->yuv) { if (texturedata->yuv) {
const SDL_Rect *rect = &data->locked_rect; const SDL_Rect *rect = &texturedata->locked_rect;
void *pixels = void *pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch + (void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format)); rect->x * SDL_BYTESPERPIXEL(texture->format));
D3D_UpdateTexture(renderer, texture, rect, pixels, data->pitch); D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
} else { } else {
IDirect3DTexture9_UnlockRect(data->texture, 0); IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
IDirect3DDevice9_UpdateTexture(data->device, (IDirect3DBaseTexture9 *)texturedata->texture.staging, (IDirect3DBaseTexture9 *)texturedata->texture.texture);
} }
} }
@ -1082,7 +1134,7 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
return -1; return -1;
} }
result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture, 0, &data->currentRenderTarget); result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture.texture, 0, &data->currentRenderTarget);
if(FAILED(result)) { if(FAILED(result)) {
return D3D_SetError("GetSurfaceLevel()", result); return D3D_SetError("GetSurfaceLevel()", result);
} }
@ -1530,7 +1582,7 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
result = result =
IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
texturedata->texture); texturedata->texture.texture);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("SetTexture()", result); return D3D_SetError("SetTexture()", result);
} }
@ -1543,14 +1595,14 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
result = result =
IDirect3DDevice9_SetTexture(data->device, 1, (IDirect3DBaseTexture9 *) IDirect3DDevice9_SetTexture(data->device, 1, (IDirect3DBaseTexture9 *)
texturedata->utexture); texturedata->utexture.texture);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("SetTexture()", result); return D3D_SetError("SetTexture()", result);
} }
result = result =
IDirect3DDevice9_SetTexture(data->device, 2, (IDirect3DBaseTexture9 *) IDirect3DDevice9_SetTexture(data->device, 2, (IDirect3DBaseTexture9 *)
texturedata->vtexture); texturedata->vtexture.texture);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("SetTexture()", result); return D3D_SetError("SetTexture()", result);
} }
@ -1673,7 +1725,7 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
result = result =
IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *) IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
texturedata->texture); texturedata->texture.texture);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("SetTexture()", result); return D3D_SetError("SetTexture()", result);
} }
@ -1686,14 +1738,14 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
result = result =
IDirect3DDevice9_SetTexture(data->device, 1, (IDirect3DBaseTexture9 *) IDirect3DDevice9_SetTexture(data->device, 1, (IDirect3DBaseTexture9 *)
texturedata->utexture); texturedata->utexture.texture);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("SetTexture()", result); return D3D_SetError("SetTexture()", result);
} }
result = result =
IDirect3DDevice9_SetTexture(data->device, 2, (IDirect3DBaseTexture9 *) IDirect3DDevice9_SetTexture(data->device, 2, (IDirect3DBaseTexture9 *)
texturedata->vtexture); texturedata->vtexture.texture);
if (FAILED(result)) { if (FAILED(result)) {
return D3D_SetError("SetTexture()", result); return D3D_SetError("SetTexture()", result);
} }
@ -1816,15 +1868,9 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (!data) { if (!data) {
return; return;
} }
if (data->texture) { D3D_DestroyTextureRep(&data->texture);
IDirect3DTexture9_Release(data->texture); D3D_DestroyTextureRep(&data->utexture);
} D3D_DestroyTextureRep(&data->vtexture);
if (data->utexture) {
IDirect3DTexture9_Release(data->utexture);
}
if (data->vtexture) {
IDirect3DTexture9_Release(data->vtexture);
}
SDL_free(data->pixels); SDL_free(data->pixels);
SDL_free(data); SDL_free(data);
texture->driverdata = NULL; texture->driverdata = NULL;

View File

@ -184,25 +184,38 @@ D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
{ {
*pD3DDLL = SDL_LoadObject("D3D9.DLL"); *pD3DDLL = SDL_LoadObject("D3D9.DLL");
if (*pD3DDLL) { if (*pD3DDLL) {
IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion); typedef IDirect3D9 *(WINAPI *Direct3DCreate9_t) (UINT SDKVersion);
typedef HRESULT *(WINAPI *Direct3DCreate9Ex_t)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
Direct3DCreate9_t Direct3DCreate9Func;
Direct3DCreate9Ex_t Direct3DCreate9ExFunc;
D3DCreate = Direct3DCreate9ExFunc = (Direct3DCreate9Ex_t)SDL_LoadFunction(*pD3DDLL, "Direct3DCreate9Ex");
(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(*pD3DDLL, if (Direct3DCreate9ExFunc) {
"Direct3DCreate9"); IDirect3D9Ex *pDirect3D9ExInterface;
if (D3DCreate) { HRESULT hr = Direct3DCreate9ExFunc(D3D_SDK_VERSION, &pDirect3D9ExInterface);
*pDirect3D9Interface = D3DCreate(D3D_SDK_VERSION); if (SUCCEEDED(hr)) {
} const GUID IDirect3D9_GUID = { 0x81bdcbca, 0x64d4, 0x426d, { 0xae, 0x8d, 0xad, 0x1, 0x47, 0xf4, 0x27, 0x5c } };
if (!*pDirect3D9Interface) { hr = IDirect3D9Ex_QueryInterface(pDirect3D9ExInterface, &IDirect3D9_GUID, (LPVOID)pDirect3D9Interface);
SDL_UnloadObject(*pD3DDLL); IDirect3D9Ex_Release(pDirect3D9ExInterface);
*pD3DDLL = NULL; if (SUCCEEDED(hr)) {
return SDL_FALSE; return SDL_TRUE;
}
}
} }
return SDL_TRUE; Direct3DCreate9Func = (Direct3DCreate9_t)SDL_LoadFunction(*pD3DDLL, "Direct3DCreate9");
} else { if (Direct3DCreate9Func) {
*pDirect3D9Interface = NULL; *pDirect3D9Interface = Direct3DCreate9Func(D3D_SDK_VERSION);
return SDL_FALSE; if (*pDirect3D9Interface) {
return SDL_TRUE;
}
}
SDL_UnloadObject(*pD3DDLL);
*pD3DDLL = NULL;
} }
*pDirect3D9Interface = NULL;
return SDL_FALSE;
} }