2006-07-10 21:04:37 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2013-02-15 08:47:44 -08:00
|
|
|
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
2011-04-08 13:03:26 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
2006-07-10 21:04:37 +00:00
|
|
|
*/
|
|
|
|
#include "SDL_config.h"
|
|
|
|
|
2011-02-08 10:04:09 -08:00
|
|
|
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-02 14:34:54 -08:00
|
|
|
#include "../../core/windows/SDL_windows.h"
|
|
|
|
|
2011-03-13 11:18:35 -07:00
|
|
|
#include "SDL_hints.h"
|
2011-02-02 14:34:54 -08:00
|
|
|
#include "SDL_loadso.h"
|
|
|
|
#include "SDL_syswm.h"
|
|
|
|
#include "../SDL_sysrender.h"
|
2013-07-07 16:13:17 +02:00
|
|
|
#include <stdio.h>
|
2011-02-02 14:34:54 -08:00
|
|
|
|
|
|
|
#if SDL_VIDEO_RENDER_D3D
|
|
|
|
#define D3D_DEBUG_INFO
|
|
|
|
#include <d3d9.h>
|
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2012-06-01 19:51:08 -03:00
|
|
|
|
|
|
|
typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
|
|
|
|
typedef struct _D3DMATRIX D3DXMATRIX, *LPD3DXMATRIX;
|
|
|
|
typedef struct _D3DVECTOR D3DXVECTOR3, *LPD3DXVECTOR3;
|
|
|
|
|
|
|
|
DEFINE_GUID(IID_ID3DXMatrixStack,
|
|
|
|
0xc7885ba7, 0xf990, 0x4fe7, 0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85);
|
|
|
|
|
|
|
|
#undef INTERFACE
|
|
|
|
#define INTERFACE ID3DXMatrixStack
|
|
|
|
|
|
|
|
DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
|
|
|
|
{
|
|
|
|
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
|
|
|
|
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
|
|
|
|
STDMETHOD_(ULONG,Release)(THIS) PURE;
|
|
|
|
STDMETHOD(Pop)(THIS) PURE;
|
|
|
|
STDMETHOD(Push)(THIS) PURE;
|
|
|
|
STDMETHOD(LoadIdentity)(THIS) PURE;
|
|
|
|
STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
|
|
|
|
STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
|
|
|
|
STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
|
|
|
|
STDMETHOD(RotateAxis)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
|
|
|
|
STDMETHOD(RotateAxisLocal)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
|
|
|
|
STDMETHOD(RotateYawPitchRoll)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
|
|
|
|
STDMETHOD(RotateYawPitchRollLocal)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
|
|
|
|
STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
|
|
|
|
STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
|
|
|
|
STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
|
|
|
|
STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
|
|
|
|
STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef INTERFACE
|
|
|
|
|
|
|
|
#if !defined(__cplusplus) || defined(CINTERFACE)
|
|
|
|
#define ID3DXMatrixStack_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
|
|
|
|
#define ID3DXMatrixStack_AddRef(p) (p)->lpVtbl->AddRef(p)
|
|
|
|
#define ID3DXMatrixStack_Release(p) (p)->lpVtbl->Release(p)
|
|
|
|
#define ID3DXMatrixStack_Pop(p) (p)->lpVtbl->Pop(p)
|
|
|
|
#define ID3DXMatrixStack_Push(p) (p)->lpVtbl->Push(p)
|
|
|
|
#define ID3DXMatrixStack_LoadIdentity(p) (p)->lpVtbl->LoadIdentity(p)
|
|
|
|
#define ID3DXMatrixStack_LoadMatrix(p,a) (p)->lpVtbl->LoadMatrix(p,a)
|
|
|
|
#define ID3DXMatrixStack_MultMatrix(p,a) (p)->lpVtbl->MultMatrix(p,a)
|
|
|
|
#define ID3DXMatrixStack_MultMatrixLocal(p,a) (p)->lpVtbl->MultMatrixLocal(p,a)
|
|
|
|
#define ID3DXMatrixStack_RotateAxis(p,a,b) (p)->lpVtbl->RotateAxis(p,a,b)
|
|
|
|
#define ID3DXMatrixStack_RotateAxisLocal(p,a,b) (p)->lpVtbl->RotateAxisLocal(p,a,b)
|
|
|
|
#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c) (p)->lpVtbl->RotateYawPitchRoll(p,a,b,c)
|
|
|
|
#define ID3DXMatrixStack_RotateYawPitchRollLocal(p,a,b,c) (p)->lpVtbl->RotateYawPitchRollLocal(p,a,b,c)
|
|
|
|
#define ID3DXMatrixStack_Scale(p,a,b,c) (p)->lpVtbl->Scale(p,a,b,c)
|
|
|
|
#define ID3DXMatrixStack_ScaleLocal(p,a,b,c) (p)->lpVtbl->ScaleLocal(p,a,b,c)
|
|
|
|
#define ID3DXMatrixStack_Translate(p,a,b,c) (p)->lpVtbl->Translate(p,a,b,c)
|
|
|
|
#define ID3DXMatrixStack_TranslateLocal(p,a,b,c) (p)->lpVtbl->TranslateLocal(p,a,b,c)
|
|
|
|
#define ID3DXMatrixStack_GetTop(p) (p)->lpVtbl->GetTop(p)
|
|
|
|
#else
|
|
|
|
#define ID3DXMatrixStack_QueryInterface(p,a,b) (p)->QueryInterface(a,b)
|
|
|
|
#define ID3DXMatrixStack_AddRef(p) (p)->AddRef()
|
|
|
|
#define ID3DXMatrixStack_Release(p) (p)->Release()
|
|
|
|
#define ID3DXMatrixStack_Pop(p) (p)->Pop()
|
|
|
|
#define ID3DXMatrixStack_Push(p) (p)->Push()
|
|
|
|
#define ID3DXMatrixStack_LoadIdentity(p) (p)->LoadIdentity()
|
|
|
|
#define ID3DXMatrixStack_LoadMatrix(p,a) (p)->LoadMatrix(a)
|
|
|
|
#define ID3DXMatrixStack_MultMatrix(p,a) (p)->MultMatrix(a)
|
|
|
|
#define ID3DXMatrixStack_MultMatrixLocal(p,a) (p)->MultMatrixLocal(a)
|
|
|
|
#define ID3DXMatrixStack_RotateAxis(p,a,b) (p)->RotateAxis(a,b)
|
|
|
|
#define ID3DXMatrixStack_RotateAxisLocal(p,a,b) (p)->RotateAxisLocal(a,b)
|
|
|
|
#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c) (p)->RotateYawPitchRollLocal(a,b,c)
|
|
|
|
#define ID3DXMatrixStack_Scale(p,a,b,c) (p)->Scale(a,b,c)
|
|
|
|
#define ID3DXMatrixStack_ScaleLocal(p,a,b,c) (p)->ScaleLocal(a,b,c)
|
|
|
|
#define ID3DXMatrixStack_Translate(p,a,b,c) (p)->Translate(a,b,c)
|
|
|
|
#define ID3DXMatrixStack_TranslateLocal(p,a,b,c) (p)->TranslateLocal(a,b,c)
|
|
|
|
#define ID3DXMatrixStack_GetTop(p) (p)->GetTop()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXCreateMatrixStack(DWORD flags, LPD3DXMATRIXSTACK* ppstack);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-14 04:19:00 +00:00
|
|
|
#ifdef ASSEMBLE_SHADER
|
2013-05-18 14:17:52 -07:00
|
|
|
/**************************************************************************
|
|
|
|
* ID3DXBuffer:
|
|
|
|
* ------------
|
|
|
|
* The buffer object is used by D3DX to return arbitrary size data.
|
|
|
|
*
|
|
|
|
* GetBufferPointer -
|
|
|
|
* Returns a pointer to the beginning of the buffer.
|
|
|
|
*
|
|
|
|
* GetBufferSize -
|
|
|
|
* Returns the size of the buffer, in bytes.
|
|
|
|
**************************************************************************/
|
2009-12-14 04:19:00 +00:00
|
|
|
|
|
|
|
typedef interface ID3DXBuffer ID3DXBuffer;
|
|
|
|
typedef interface ID3DXBuffer *LPD3DXBUFFER;
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* {8BA5FB08-5195-40e2-AC58-0D989C3A0102} */
|
|
|
|
DEFINE_GUID(IID_ID3DXBuffer,
|
2009-12-14 04:19:00 +00:00
|
|
|
0x8ba5fb08, 0x5195, 0x40e2, 0xac, 0x58, 0xd, 0x98, 0x9c, 0x3a, 0x1, 0x2);
|
|
|
|
|
|
|
|
#undef INTERFACE
|
|
|
|
#define INTERFACE ID3DXBuffer
|
|
|
|
|
|
|
|
typedef interface ID3DXBuffer {
|
|
|
|
const struct ID3DXBufferVtbl FAR* lpVtbl;
|
|
|
|
} ID3DXBuffer;
|
|
|
|
typedef const struct ID3DXBufferVtbl ID3DXBufferVtbl;
|
|
|
|
const struct ID3DXBufferVtbl
|
|
|
|
{
|
2013-05-18 14:17:52 -07:00
|
|
|
/* IUnknown */
|
2009-12-14 04:19:00 +00:00
|
|
|
STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
|
|
|
|
STDMETHOD_(ULONG, AddRef)(THIS) PURE;
|
|
|
|
STDMETHOD_(ULONG, Release)(THIS) PURE;
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* ID3DXBuffer */
|
2009-12-14 04:19:00 +00:00
|
|
|
STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE;
|
|
|
|
STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE;
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
D3DXAssembleShader(
|
|
|
|
LPCSTR pSrcData,
|
|
|
|
UINT SrcDataLen,
|
|
|
|
CONST LPVOID* pDefines,
|
|
|
|
LPVOID pInclude,
|
|
|
|
DWORD Flags,
|
|
|
|
LPD3DXBUFFER* ppShader,
|
|
|
|
LPD3DXBUFFER* ppErrorMsgs);
|
|
|
|
|
|
|
|
#endif /* ASSEMBLE_SHADER */
|
|
|
|
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Direct3D renderer implementation */
|
|
|
|
|
2006-07-17 06:47:33 +00:00
|
|
|
static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
|
2011-02-15 13:59:59 -08:00
|
|
|
static void D3D_WindowEvent(SDL_Renderer * renderer,
|
|
|
|
const SDL_WindowEvent *event);
|
2006-07-17 06:47:33 +00:00
|
|
|
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
|
|
|
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|
|
|
const SDL_Rect * rect, const void *pixels,
|
|
|
|
int pitch);
|
|
|
|
static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
2011-02-03 00:19:40 -08:00
|
|
|
const SDL_Rect * rect, void **pixels, int *pitch);
|
2006-07-17 06:47:33 +00:00
|
|
|
static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
2012-01-22 01:26:28 -05:00
|
|
|
static int D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
|
2011-02-15 13:59:59 -08:00
|
|
|
static int D3D_UpdateViewport(SDL_Renderer * renderer);
|
2013-05-04 04:46:00 -07:00
|
|
|
static int D3D_UpdateClipRect(SDL_Renderer * renderer);
|
2011-02-15 13:59:59 -08:00
|
|
|
static int D3D_RenderClear(SDL_Renderer * renderer);
|
2009-12-24 19:18:05 +00:00
|
|
|
static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_FPoint * points, int count);
|
2009-12-24 19:18:05 +00:00
|
|
|
static int D3D_RenderDrawLines(SDL_Renderer * renderer,
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_FPoint * points, int count);
|
2009-12-24 19:18:05 +00:00
|
|
|
static int D3D_RenderFillRects(SDL_Renderer * renderer,
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_FRect * rects, int count);
|
2006-07-17 06:47:33 +00:00
|
|
|
static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_Rect * srcrect, const SDL_FRect * dstrect);
|
2012-06-01 19:51:08 -03:00
|
|
|
static int D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
|
|
|
|
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
|
2009-11-09 05:20:11 +00:00
|
|
|
static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
2009-11-22 06:37:43 +00:00
|
|
|
Uint32 format, void * pixels, int pitch);
|
2006-07-17 06:47:33 +00:00
|
|
|
static void D3D_RenderPresent(SDL_Renderer * renderer);
|
|
|
|
static void D3D_DestroyTexture(SDL_Renderer * renderer,
|
|
|
|
SDL_Texture * texture);
|
|
|
|
static void D3D_DestroyRenderer(SDL_Renderer * renderer);
|
|
|
|
|
|
|
|
|
|
|
|
SDL_RenderDriver D3D_RenderDriver = {
|
|
|
|
D3D_CreateRenderer,
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-05 00:34:34 -08:00
|
|
|
"direct3d",
|
2012-01-19 21:06:47 -05:00
|
|
|
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
|
2011-02-03 00:19:40 -08:00
|
|
|
1,
|
|
|
|
{SDL_PIXELFORMAT_ARGB8888},
|
2006-07-10 21:04:37 +00:00
|
|
|
0,
|
|
|
|
0}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2011-02-02 14:34:54 -08:00
|
|
|
void* d3dDLL;
|
2009-01-03 05:42:18 +00:00
|
|
|
IDirect3D9 *d3d;
|
2006-07-10 21:04:37 +00:00
|
|
|
IDirect3DDevice9 *device;
|
2009-12-06 06:21:39 +00:00
|
|
|
UINT adapter;
|
2006-08-07 05:24:13 +00:00
|
|
|
D3DPRESENT_PARAMETERS pparams;
|
2011-02-15 13:59:59 -08:00
|
|
|
SDL_bool updateSize;
|
2006-07-12 09:25:17 +00:00
|
|
|
SDL_bool beginScene;
|
2013-07-23 08:06:49 -07:00
|
|
|
SDL_bool enableSeparateAlphaBlend;
|
2011-03-13 11:18:35 -07:00
|
|
|
D3DTEXTUREFILTERTYPE scaleMode;
|
2012-01-18 22:45:49 -05:00
|
|
|
IDirect3DSurface9 *defaultRenderTarget;
|
|
|
|
IDirect3DSurface9 *currentRenderTarget;
|
2012-06-01 19:51:08 -03:00
|
|
|
void* d3dxDLL;
|
|
|
|
ID3DXMatrixStack *matrixStack;
|
2006-07-17 06:47:33 +00:00
|
|
|
} D3D_RenderData;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2006-07-14 06:40:53 +00:00
|
|
|
IDirect3DTexture9 *texture;
|
2011-03-13 11:18:35 -07:00
|
|
|
D3DTEXTUREFILTERTYPE scaleMode;
|
2006-07-17 06:47:33 +00:00
|
|
|
} D3D_TextureData;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
float x, y, z;
|
2006-08-28 04:03:32 +00:00
|
|
|
DWORD color;
|
2006-07-14 07:41:16 +00:00
|
|
|
float u, v;
|
2006-07-14 06:40:53 +00:00
|
|
|
} Vertex;
|
|
|
|
|
2013-03-31 12:48:50 -04:00
|
|
|
static int
|
2006-07-12 09:25:17 +00:00
|
|
|
D3D_SetError(const char *prefix, HRESULT result)
|
|
|
|
{
|
|
|
|
const char *error;
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case D3DERR_WRONGTEXTUREFORMAT:
|
|
|
|
error = "WRONGTEXTUREFORMAT";
|
|
|
|
break;
|
|
|
|
case D3DERR_UNSUPPORTEDCOLOROPERATION:
|
|
|
|
error = "UNSUPPORTEDCOLOROPERATION";
|
|
|
|
break;
|
|
|
|
case D3DERR_UNSUPPORTEDCOLORARG:
|
|
|
|
error = "UNSUPPORTEDCOLORARG";
|
|
|
|
break;
|
|
|
|
case D3DERR_UNSUPPORTEDALPHAOPERATION:
|
|
|
|
error = "UNSUPPORTEDALPHAOPERATION";
|
|
|
|
break;
|
|
|
|
case D3DERR_UNSUPPORTEDALPHAARG:
|
|
|
|
error = "UNSUPPORTEDALPHAARG";
|
|
|
|
break;
|
|
|
|
case D3DERR_TOOMANYOPERATIONS:
|
|
|
|
error = "TOOMANYOPERATIONS";
|
|
|
|
break;
|
|
|
|
case D3DERR_CONFLICTINGTEXTUREFILTER:
|
|
|
|
error = "CONFLICTINGTEXTUREFILTER";
|
|
|
|
break;
|
|
|
|
case D3DERR_UNSUPPORTEDFACTORVALUE:
|
|
|
|
error = "UNSUPPORTEDFACTORVALUE";
|
|
|
|
break;
|
|
|
|
case D3DERR_CONFLICTINGRENDERSTATE:
|
|
|
|
error = "CONFLICTINGRENDERSTATE";
|
|
|
|
break;
|
|
|
|
case D3DERR_UNSUPPORTEDTEXTUREFILTER:
|
|
|
|
error = "UNSUPPORTEDTEXTUREFILTER";
|
|
|
|
break;
|
|
|
|
case D3DERR_CONFLICTINGTEXTUREPALETTE:
|
|
|
|
error = "CONFLICTINGTEXTUREPALETTE";
|
|
|
|
break;
|
|
|
|
case D3DERR_DRIVERINTERNALERROR:
|
|
|
|
error = "DRIVERINTERNALERROR";
|
|
|
|
break;
|
|
|
|
case D3DERR_NOTFOUND:
|
|
|
|
error = "NOTFOUND";
|
|
|
|
break;
|
|
|
|
case D3DERR_MOREDATA:
|
|
|
|
error = "MOREDATA";
|
|
|
|
break;
|
|
|
|
case D3DERR_DEVICELOST:
|
|
|
|
error = "DEVICELOST";
|
|
|
|
break;
|
|
|
|
case D3DERR_DEVICENOTRESET:
|
|
|
|
error = "DEVICENOTRESET";
|
|
|
|
break;
|
|
|
|
case D3DERR_NOTAVAILABLE:
|
|
|
|
error = "NOTAVAILABLE";
|
|
|
|
break;
|
|
|
|
case D3DERR_OUTOFVIDEOMEMORY:
|
|
|
|
error = "OUTOFVIDEOMEMORY";
|
|
|
|
break;
|
|
|
|
case D3DERR_INVALIDDEVICE:
|
|
|
|
error = "INVALIDDEVICE";
|
|
|
|
break;
|
|
|
|
case D3DERR_INVALIDCALL:
|
|
|
|
error = "INVALIDCALL";
|
|
|
|
break;
|
|
|
|
case D3DERR_DRIVERINVALIDCALL:
|
|
|
|
error = "DRIVERINVALIDCALL";
|
|
|
|
break;
|
|
|
|
case D3DERR_WASSTILLDRAWING:
|
|
|
|
error = "WASSTILLDRAWING";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_SetError("%s: %s", prefix, error);
|
2006-07-12 09:25:17 +00:00
|
|
|
}
|
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
static D3DFORMAT
|
|
|
|
PixelFormatToD3DFMT(Uint32 format)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-14 06:40:53 +00:00
|
|
|
switch (format) {
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB565:
|
2006-07-14 06:40:53 +00:00
|
|
|
return D3DFMT_R5G6B5;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB888:
|
2006-07-14 06:40:53 +00:00
|
|
|
return D3DFMT_X8R8G8B8;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_ARGB8888:
|
2006-07-14 06:40:53 +00:00
|
|
|
return D3DFMT_A8R8G8B8;
|
|
|
|
default:
|
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
static Uint32
|
|
|
|
D3DFMTToPixelFormat(D3DFORMAT format)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2011-02-03 00:19:40 -08:00
|
|
|
switch (format) {
|
|
|
|
case D3DFMT_R5G6B5:
|
|
|
|
return SDL_PIXELFORMAT_RGB565;
|
|
|
|
case D3DFMT_X8R8G8B8:
|
|
|
|
return SDL_PIXELFORMAT_RGB888;
|
|
|
|
case D3DFMT_A8R8G8B8:
|
|
|
|
return SDL_PIXELFORMAT_ARGB8888;
|
|
|
|
default:
|
|
|
|
return SDL_PIXELFORMAT_UNKNOWN;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
static int
|
|
|
|
D3D_Reset(SDL_Renderer * renderer)
|
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
HRESULT result;
|
|
|
|
|
2013-02-11 21:12:14 -08:00
|
|
|
/* Release the default render target before reset */
|
2013-02-17 23:30:47 -08:00
|
|
|
if (data->defaultRenderTarget) {
|
|
|
|
IDirect3DSurface9_Release(data->defaultRenderTarget);
|
|
|
|
data->defaultRenderTarget = NULL;
|
|
|
|
}
|
2013-02-11 21:12:14 -08:00
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
result = IDirect3DDevice9_Reset(data->device, &data->pparams);
|
|
|
|
if (FAILED(result)) {
|
|
|
|
if (result == D3DERR_DEVICELOST) {
|
|
|
|
/* Don't worry about it, we'll reset later... */
|
|
|
|
return 0;
|
|
|
|
} else {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("Reset()", result);
|
2011-02-15 13:59:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
IDirect3DDevice9_SetVertexShader(data->device, NULL);
|
|
|
|
IDirect3DDevice9_SetFVF(data->device,
|
|
|
|
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
|
|
|
|
D3DCULL_NONE);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
|
2013-02-11 21:12:14 -08:00
|
|
|
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
|
2013-05-29 06:31:48 -05:00
|
|
|
data->scaleMode = D3DTEXF_FORCE_DWORD;
|
2011-02-15 13:59:59 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
D3D_ActivateRenderer(SDL_Renderer * renderer)
|
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
if (data->updateSize) {
|
|
|
|
SDL_Window *window = renderer->window;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
|
|
data->pparams.BackBufferWidth = w;
|
|
|
|
data->pparams.BackBufferHeight = h;
|
|
|
|
if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
|
|
|
|
data->pparams.BackBufferFormat =
|
|
|
|
PixelFormatToD3DFMT(SDL_GetWindowPixelFormat(window));
|
|
|
|
} else {
|
|
|
|
data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (D3D_Reset(renderer) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
D3D_UpdateViewport(renderer);
|
|
|
|
|
|
|
|
data->updateSize = SDL_FALSE;
|
|
|
|
}
|
|
|
|
if (data->beginScene) {
|
|
|
|
result = IDirect3DDevice9_BeginScene(data->device);
|
|
|
|
if (result == D3DERR_DEVICELOST) {
|
|
|
|
if (D3D_Reset(renderer) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
result = IDirect3DDevice9_BeginScene(data->device);
|
|
|
|
}
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("BeginScene()", result);
|
2011-02-15 13:59:59 -08:00
|
|
|
}
|
|
|
|
data->beginScene = SDL_FALSE;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_Renderer *
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
|
|
|
SDL_Renderer *renderer;
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_RenderData *data;
|
2011-02-02 14:34:54 -08:00
|
|
|
SDL_SysWMinfo windowinfo;
|
2006-07-12 09:25:17 +00:00
|
|
|
HRESULT result;
|
|
|
|
D3DPRESENT_PARAMETERS pparams;
|
2006-07-15 09:46:36 +00:00
|
|
|
IDirect3DSwapChain9 *chain;
|
2006-07-22 21:17:37 +00:00
|
|
|
D3DCAPS9 caps;
|
2011-02-03 00:19:40 -08:00
|
|
|
Uint32 window_flags;
|
|
|
|
int w, h;
|
|
|
|
SDL_DisplayMode fullscreen_mode;
|
2011-02-15 13:59:59 -08:00
|
|
|
D3DMATRIX matrix;
|
2012-06-01 19:51:08 -03:00
|
|
|
int d3dxVersion;
|
2013-05-18 14:17:52 -07:00
|
|
|
char d3dxDLLFile[50];
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!renderer) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data));
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!data) {
|
2011-02-02 14:34:54 -08:00
|
|
|
SDL_free(renderer);
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-02 14:34:54 -08:00
|
|
|
data->d3dDLL = SDL_LoadObject("D3D9.DLL");
|
|
|
|
if (data->d3dDLL) {
|
|
|
|
IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
|
|
|
|
|
|
|
|
D3DCreate =
|
|
|
|
(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL,
|
|
|
|
"Direct3DCreate9");
|
|
|
|
if (D3DCreate) {
|
|
|
|
data->d3d = D3DCreate(D3D_SDK_VERSION);
|
|
|
|
}
|
|
|
|
if (!data->d3d) {
|
|
|
|
SDL_UnloadObject(data->d3dDLL);
|
|
|
|
data->d3dDLL = NULL;
|
|
|
|
}
|
2012-06-01 19:51:08 -03:00
|
|
|
|
|
|
|
for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) {
|
2013-03-06 09:45:53 -08:00
|
|
|
LPTSTR dllName;
|
|
|
|
SDL_snprintf(d3dxDLLFile, sizeof(d3dxDLLFile), "D3DX9_%02d.dll", d3dxVersion);
|
|
|
|
dllName = WIN_UTF8ToString(d3dxDLLFile);
|
|
|
|
data->d3dxDLL = (void *)LoadLibrary(dllName); /* not using SDL_LoadObject() as we want silently fail - no error message */
|
|
|
|
SDL_free(dllName);
|
2012-06-01 19:51:08 -03:00
|
|
|
if (data->d3dxDLL) {
|
|
|
|
HRESULT (WINAPI *D3DXCreateMatrixStack) (DWORD Flags, LPD3DXMATRIXSTACK* ppStack);
|
|
|
|
D3DXCreateMatrixStack = (HRESULT (WINAPI *) (DWORD, LPD3DXMATRIXSTACK*)) SDL_LoadFunction(data->d3dxDLL, "D3DXCreateMatrixStack");
|
|
|
|
if (D3DXCreateMatrixStack) {
|
|
|
|
D3DXCreateMatrixStack(0, &data->matrixStack);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data->matrixStack) {
|
|
|
|
if (data->d3dxDLL) SDL_UnloadObject(data->d3dxDLL);
|
|
|
|
}
|
2011-02-02 14:34:54 -08:00
|
|
|
}
|
2012-06-01 19:51:08 -03:00
|
|
|
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2012-06-01 19:51:08 -03:00
|
|
|
if (!data->d3d || !data->matrixStack) {
|
2011-02-02 14:34:54 -08:00
|
|
|
SDL_free(renderer);
|
|
|
|
SDL_free(data);
|
|
|
|
SDL_SetError("Unable to create Direct3D interface");
|
|
|
|
return NULL;
|
|
|
|
}
|
Andrey A.
I made a video driver GAPI/RAW for WinCE (SDL-1.3).
RAW mode has a priority, and also, GAPI mode works with environment
"SDL_VIDEO_RENDERER=gapi" and for RAW mode "SDL_VIDEO_RENDERER=raw".
I checked the work on the screens of VGA, WVGA, QVGA, WQVGA, HVGA,
+ tested all modes with WindowsMobile Emulator.
Also, correctly draws the pointer position and the scale of the pointer
for VGA/WVGA modes,
correctly draws top left position for DM orientation screen, and
portrait/landscape/square geometry the screen also correct.
Also, I added a small fix for GDI fullscreen mode.
Patch for latest revision SDL-1.3 in an attachment.
Also added small path for mingw32ce build.
2010-07-27 21:31:28 -07:00
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
renderer->WindowEvent = D3D_WindowEvent;
|
2006-07-17 06:47:33 +00:00
|
|
|
renderer->CreateTexture = D3D_CreateTexture;
|
|
|
|
renderer->UpdateTexture = D3D_UpdateTexture;
|
|
|
|
renderer->LockTexture = D3D_LockTexture;
|
|
|
|
renderer->UnlockTexture = D3D_UnlockTexture;
|
2012-01-22 01:26:28 -05:00
|
|
|
renderer->SetRenderTarget = D3D_SetRenderTarget;
|
2011-02-15 13:59:59 -08:00
|
|
|
renderer->UpdateViewport = D3D_UpdateViewport;
|
2013-05-04 04:46:00 -07:00
|
|
|
renderer->UpdateClipRect = D3D_UpdateClipRect;
|
2011-02-15 13:59:59 -08:00
|
|
|
renderer->RenderClear = D3D_RenderClear;
|
2009-12-24 19:18:05 +00:00
|
|
|
renderer->RenderDrawPoints = D3D_RenderDrawPoints;
|
|
|
|
renderer->RenderDrawLines = D3D_RenderDrawLines;
|
2010-01-18 06:34:04 +00:00
|
|
|
renderer->RenderFillRects = D3D_RenderFillRects;
|
2006-07-17 06:47:33 +00:00
|
|
|
renderer->RenderCopy = D3D_RenderCopy;
|
2012-06-01 19:51:08 -03:00
|
|
|
renderer->RenderCopyEx = D3D_RenderCopyEx;
|
2009-11-09 05:20:11 +00:00
|
|
|
renderer->RenderReadPixels = D3D_RenderReadPixels;
|
2006-07-17 06:47:33 +00:00
|
|
|
renderer->RenderPresent = D3D_RenderPresent;
|
|
|
|
renderer->DestroyTexture = D3D_DestroyTexture;
|
|
|
|
renderer->DestroyRenderer = D3D_DestroyRenderer;
|
|
|
|
renderer->info = D3D_RenderDriver.info;
|
2006-07-10 21:04:37 +00:00
|
|
|
renderer->driverdata = data;
|
|
|
|
|
2012-01-21 22:22:30 -05:00
|
|
|
renderer->info.flags = SDL_RENDERER_ACCELERATED;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-02 14:34:54 -08:00
|
|
|
SDL_VERSION(&windowinfo.version);
|
|
|
|
SDL_GetWindowWMInfo(window, &windowinfo);
|
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
window_flags = SDL_GetWindowFlags(window);
|
|
|
|
SDL_GetWindowSize(window, &w, &h);
|
|
|
|
SDL_GetWindowDisplayMode(window, &fullscreen_mode);
|
|
|
|
|
2006-07-12 09:25:17 +00:00
|
|
|
SDL_zero(pparams);
|
2011-02-02 14:34:54 -08:00
|
|
|
pparams.hDeviceWindow = windowinfo.info.win.window;
|
2011-02-03 00:19:40 -08:00
|
|
|
pparams.BackBufferWidth = w;
|
|
|
|
pparams.BackBufferHeight = h;
|
|
|
|
if (window_flags & SDL_WINDOW_FULLSCREEN) {
|
2006-07-14 06:40:53 +00:00
|
|
|
pparams.BackBufferFormat =
|
2011-02-03 00:19:40 -08:00
|
|
|
PixelFormatToD3DFMT(fullscreen_mode.format);
|
2006-07-14 06:40:53 +00:00
|
|
|
} else {
|
|
|
|
pparams.BackBufferFormat = D3DFMT_UNKNOWN;
|
|
|
|
}
|
2011-02-01 12:19:46 -08:00
|
|
|
pparams.BackBufferCount = 1;
|
|
|
|
pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
if (window_flags & SDL_WINDOW_FULLSCREEN) {
|
2013-05-18 14:17:52 -07:00
|
|
|
if ( ( window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) == SDL_WINDOW_FULLSCREEN_DESKTOP ) {
|
|
|
|
pparams.Windowed = TRUE;
|
|
|
|
pparams.FullScreen_RefreshRateInHz = 0;
|
|
|
|
} else {
|
2006-07-12 09:25:17 +00:00
|
|
|
pparams.Windowed = FALSE;
|
2006-07-14 06:40:53 +00:00
|
|
|
pparams.FullScreen_RefreshRateInHz =
|
2011-02-03 00:19:40 -08:00
|
|
|
fullscreen_mode.refresh_rate;
|
2013-05-18 14:17:52 -07:00
|
|
|
}
|
2006-07-12 09:25:17 +00:00
|
|
|
} else {
|
|
|
|
pparams.Windowed = TRUE;
|
2006-07-14 06:40:53 +00:00
|
|
|
pparams.FullScreen_RefreshRateInHz = 0;
|
2006-07-12 09:25:17 +00:00
|
|
|
}
|
2006-08-05 17:09:42 +00:00
|
|
|
if (flags & SDL_RENDERER_PRESENTVSYNC) {
|
2006-07-15 09:46:36 +00:00
|
|
|
pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
|
|
|
} else {
|
|
|
|
pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
|
|
|
}
|
2006-07-12 09:25:17 +00:00
|
|
|
|
2011-02-02 14:34:54 -08:00
|
|
|
/* FIXME: Which adapter? */
|
|
|
|
data->adapter = D3DADAPTER_DEFAULT;
|
|
|
|
IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
|
2009-06-16 14:34:15 +00:00
|
|
|
|
2011-02-02 14:34:54 -08:00
|
|
|
result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
|
2006-07-12 09:25:17 +00:00
|
|
|
D3DDEVTYPE_HAL,
|
2011-02-02 14:34:54 -08:00
|
|
|
pparams.hDeviceWindow,
|
2011-12-29 05:18:16 -05:00
|
|
|
D3DCREATE_FPU_PRESERVE | ((caps.
|
2009-06-16 14:34:15 +00:00
|
|
|
DevCaps &
|
|
|
|
D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
|
|
|
|
D3DCREATE_HARDWARE_VERTEXPROCESSING :
|
2011-12-29 05:18:16 -05:00
|
|
|
D3DCREATE_SOFTWARE_VERTEXPROCESSING),
|
2006-07-12 09:25:17 +00:00
|
|
|
&pparams, &data->device);
|
|
|
|
if (FAILED(result)) {
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_DestroyRenderer(renderer);
|
2006-07-12 09:25:17 +00:00
|
|
|
D3D_SetError("CreateDevice()", result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
data->beginScene = SDL_TRUE;
|
2011-03-13 11:18:35 -07:00
|
|
|
data->scaleMode = D3DTEXF_FORCE_DWORD;
|
2006-07-12 09:25:17 +00:00
|
|
|
|
2006-07-15 09:46:36 +00:00
|
|
|
/* Get presentation parameters to fill info */
|
|
|
|
result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
|
|
|
|
if (FAILED(result)) {
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_DestroyRenderer(renderer);
|
2006-07-15 09:46:36 +00:00
|
|
|
D3D_SetError("GetSwapChain()", result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
|
|
|
|
if (FAILED(result)) {
|
|
|
|
IDirect3DSwapChain9_Release(chain);
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_DestroyRenderer(renderer);
|
2006-07-15 09:46:36 +00:00
|
|
|
D3D_SetError("GetPresentParameters()", result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
IDirect3DSwapChain9_Release(chain);
|
|
|
|
if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
|
2006-08-05 17:09:42 +00:00
|
|
|
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
2006-07-15 09:46:36 +00:00
|
|
|
}
|
2006-08-07 05:24:13 +00:00
|
|
|
data->pparams = pparams;
|
2006-07-15 09:46:36 +00:00
|
|
|
|
2006-07-22 21:17:37 +00:00
|
|
|
IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
|
|
|
|
renderer->info.max_texture_width = caps.MaxTextureWidth;
|
|
|
|
renderer->info.max_texture_height = caps.MaxTextureHeight;
|
2012-01-21 22:22:30 -05:00
|
|
|
if (caps.NumSimultaneousRTs >= 2) {
|
|
|
|
renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
|
|
|
|
}
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2013-07-23 08:06:49 -07:00
|
|
|
if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
|
|
|
|
data->enableSeparateAlphaBlend = SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
/* Set up parameters for rendering */
|
2006-07-14 07:41:16 +00:00
|
|
|
IDirect3DDevice9_SetVertexShader(data->device, NULL);
|
2006-08-28 04:03:32 +00:00
|
|
|
IDirect3DDevice9_SetFVF(data->device,
|
2011-02-15 13:59:59 -08:00
|
|
|
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
|
2006-08-28 04:39:37 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
|
2006-07-14 06:40:53 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
|
|
|
|
D3DCULL_NONE);
|
2006-07-14 07:41:16 +00:00
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
|
2006-08-28 04:39:37 +00:00
|
|
|
/* Enable color modulation by diffuse color */
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP,
|
|
|
|
D3DTOP_MODULATE);
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1,
|
|
|
|
D3DTA_TEXTURE);
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2,
|
|
|
|
D3DTA_DIFFUSE);
|
|
|
|
/* Enable alpha modulation by diffuse alpha */
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP,
|
|
|
|
D3DTOP_MODULATE);
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1,
|
|
|
|
D3DTA_TEXTURE);
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
|
|
|
|
D3DTA_DIFFUSE);
|
2013-07-23 08:06:49 -07:00
|
|
|
/* Enable separate alpha blend function, if possible */
|
|
|
|
if (data->enableSeparateAlphaBlend) {
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
|
|
|
|
}
|
2006-08-28 17:35:15 +00:00
|
|
|
/* Disable second texture stage, since we're done */
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
|
|
|
|
D3DTOP_DISABLE);
|
|
|
|
IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
|
|
|
|
D3DTOP_DISABLE);
|
2006-07-14 06:40:53 +00:00
|
|
|
|
2012-01-18 22:45:49 -05:00
|
|
|
/* Store the default render target */
|
|
|
|
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget );
|
|
|
|
data->currentRenderTarget = NULL;
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
/* Set an identity world and view matrix */
|
|
|
|
matrix.m[0][0] = 1.0f;
|
|
|
|
matrix.m[0][1] = 0.0f;
|
|
|
|
matrix.m[0][2] = 0.0f;
|
|
|
|
matrix.m[0][3] = 0.0f;
|
|
|
|
matrix.m[1][0] = 0.0f;
|
|
|
|
matrix.m[1][1] = 1.0f;
|
|
|
|
matrix.m[1][2] = 0.0f;
|
|
|
|
matrix.m[1][3] = 0.0f;
|
|
|
|
matrix.m[2][0] = 0.0f;
|
|
|
|
matrix.m[2][1] = 0.0f;
|
|
|
|
matrix.m[2][2] = 1.0f;
|
|
|
|
matrix.m[2][3] = 0.0f;
|
|
|
|
matrix.m[3][0] = 0.0f;
|
|
|
|
matrix.m[3][1] = 0.0f;
|
|
|
|
matrix.m[3][2] = 0.0f;
|
|
|
|
matrix.m[3][3] = 1.0f;
|
|
|
|
IDirect3DDevice9_SetTransform(data->device, D3DTS_WORLD, &matrix);
|
|
|
|
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, &matrix);
|
2006-08-07 05:24:13 +00:00
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
return renderer;
|
2006-08-07 05:24:13 +00:00
|
|
|
}
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
static void
|
|
|
|
D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
|
2006-08-07 05:24:13 +00:00
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
|
|
|
data->updateSize = SDL_TRUE;
|
2006-08-07 05:24:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-13 11:18:35 -07:00
|
|
|
static D3DTEXTUREFILTERTYPE
|
|
|
|
GetScaleQuality(void)
|
|
|
|
{
|
|
|
|
const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
|
|
|
|
|
|
|
|
if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
|
|
|
|
return D3DTEXF_POINT;
|
|
|
|
} else if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) {
|
|
|
|
return D3DTEXF_LINEAR;
|
|
|
|
} else {
|
|
|
|
return D3DTEXF_ANISOTROPIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static int
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2012-08-24 19:39:51 -04:00
|
|
|
D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_TextureData *data;
|
2011-02-04 12:25:26 -08:00
|
|
|
D3DPOOL pool;
|
|
|
|
DWORD usage;
|
2006-07-14 06:40:53 +00:00
|
|
|
HRESULT result;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
|
2006-07-10 21:04:37 +00:00
|
|
|
if (!data) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return SDL_OutOfMemory();
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2011-03-13 11:18:35 -07:00
|
|
|
data->scaleMode = GetScaleQuality();
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
texture->driverdata = data;
|
|
|
|
|
2011-02-04 12:25:26 -08:00
|
|
|
#ifdef USE_DYNAMIC_TEXTURE
|
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
|
|
|
pool = D3DPOOL_DEFAULT;
|
|
|
|
usage = D3DUSAGE_DYNAMIC;
|
|
|
|
} else
|
|
|
|
#endif
|
2012-01-18 22:45:49 -05:00
|
|
|
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
|
2012-01-21 22:22:30 -05:00
|
|
|
/* D3DPOOL_MANAGED does not work with D3DUSAGE_RENDERTARGET */
|
|
|
|
pool = D3DPOOL_DEFAULT;
|
2012-01-18 22:45:49 -05:00
|
|
|
usage = D3DUSAGE_RENDERTARGET;
|
2012-01-21 22:22:30 -05:00
|
|
|
} else {
|
2011-02-04 12:25:26 -08:00
|
|
|
pool = D3DPOOL_MANAGED;
|
|
|
|
usage = 0;
|
|
|
|
}
|
2009-01-03 05:42:18 +00:00
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
result =
|
|
|
|
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
|
2011-02-04 12:25:26 -08:00
|
|
|
texture->h, 1, usage,
|
|
|
|
PixelFormatToD3DFMT(texture->format),
|
|
|
|
pool, &data->texture, NULL);
|
2006-07-14 06:40:53 +00:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("CreateTexture()", result);
|
2006-07-14 06:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|
|
|
const SDL_Rect * rect, const void *pixels, int pitch)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
|
2011-02-03 00:19:40 -08:00
|
|
|
RECT d3drect;
|
|
|
|
D3DLOCKED_RECT locked;
|
|
|
|
const Uint8 *src;
|
|
|
|
Uint8 *dst;
|
|
|
|
int row, length;
|
|
|
|
HRESULT result;
|
2006-07-14 06:40:53 +00:00
|
|
|
|
2011-02-04 12:25:26 -08:00
|
|
|
#ifdef USE_DYNAMIC_TEXTURE
|
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING &&
|
|
|
|
rect->x == 0 && rect->y == 0 &&
|
|
|
|
rect->w == texture->w && rect->h == texture->h) {
|
2011-02-05 11:54:46 -08:00
|
|
|
result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, NULL, D3DLOCK_DISCARD);
|
2011-02-04 12:25:26 -08:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
d3drect.left = rect->x;
|
|
|
|
d3drect.right = rect->x + rect->w;
|
|
|
|
d3drect.top = rect->y;
|
|
|
|
d3drect.bottom = rect->y + rect->h;
|
2011-02-05 11:54:46 -08:00
|
|
|
result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0);
|
2011-02-03 00:19:40 -08:00
|
|
|
}
|
2009-01-03 05:42:18 +00:00
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("LockRect()", result);
|
2011-02-03 00:19:40 -08:00
|
|
|
}
|
2008-11-25 00:29:44 +00:00
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
src = pixels;
|
|
|
|
dst = locked.pBits;
|
|
|
|
length = rect->w * SDL_BYTESPERPIXEL(texture->format);
|
2011-02-04 12:25:26 -08:00
|
|
|
if (length == pitch && length == locked.Pitch) {
|
|
|
|
SDL_memcpy(dst, src, length*rect->h);
|
|
|
|
} else {
|
|
|
|
for (row = 0; row < rect->h; ++row) {
|
|
|
|
SDL_memcpy(dst, src, length);
|
|
|
|
src += pitch;
|
|
|
|
dst += locked.Pitch;
|
|
|
|
}
|
2008-11-25 00:29:44 +00:00
|
|
|
}
|
2011-02-03 00:19:40 -08:00
|
|
|
IDirect3DTexture9_UnlockRect(data->texture, 0);
|
|
|
|
|
|
|
|
return 0;
|
2008-11-25 00:29:44 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
static int
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
2011-02-03 00:19:40 -08:00
|
|
|
const SDL_Rect * rect, void **pixels, int *pitch)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
|
2011-02-03 00:19:40 -08:00
|
|
|
RECT d3drect;
|
|
|
|
D3DLOCKED_RECT locked;
|
|
|
|
HRESULT result;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
d3drect.left = rect->x;
|
|
|
|
d3drect.right = rect->x + rect->w;
|
|
|
|
d3drect.top = rect->y;
|
|
|
|
d3drect.bottom = rect->y + rect->h;
|
2009-01-03 05:42:18 +00:00
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0);
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("LockRect()", result);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
2011-02-03 00:19:40 -08:00
|
|
|
*pixels = locked.pBits;
|
|
|
|
*pitch = locked.Pitch;
|
|
|
|
return 0;
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-03 00:19:40 -08:00
|
|
|
IDirect3DTexture9_UnlockRect(data->texture, 0);
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 04:46:00 -07:00
|
|
|
static int
|
|
|
|
D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
D3D_TextureData *texturedata;
|
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
D3D_ActivateRenderer(renderer);
|
|
|
|
|
|
|
|
/* Release the previous render target if it wasn't the default one */
|
|
|
|
if (data->currentRenderTarget != NULL) {
|
|
|
|
IDirect3DSurface9_Release(data->currentRenderTarget);
|
|
|
|
data->currentRenderTarget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture == NULL) {
|
|
|
|
IDirect3DDevice9_SetRenderTarget(data->device, 0, data->defaultRenderTarget);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
texturedata = (D3D_TextureData *) texture->driverdata;
|
|
|
|
result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture, 0, &data->currentRenderTarget);
|
|
|
|
if(FAILED(result)) {
|
|
|
|
return D3D_SetError("GetSurfaceLevel()", result);
|
|
|
|
}
|
|
|
|
result = IDirect3DDevice9_SetRenderTarget(data->device, 0, data->currentRenderTarget);
|
|
|
|
if(FAILED(result)) {
|
|
|
|
return D3D_SetError("SetRenderTarget()", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
static int
|
|
|
|
D3D_UpdateViewport(SDL_Renderer * renderer)
|
2011-02-07 20:06:26 -08:00
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
2011-02-15 13:59:59 -08:00
|
|
|
D3DVIEWPORT9 viewport;
|
|
|
|
D3DMATRIX matrix;
|
|
|
|
|
|
|
|
/* Set the viewport */
|
|
|
|
viewport.X = renderer->viewport.x;
|
|
|
|
viewport.Y = renderer->viewport.y;
|
|
|
|
viewport.Width = renderer->viewport.w;
|
|
|
|
viewport.Height = renderer->viewport.h;
|
|
|
|
viewport.MinZ = 0.0f;
|
|
|
|
viewport.MaxZ = 1.0f;
|
|
|
|
IDirect3DDevice9_SetViewport(data->device, &viewport);
|
|
|
|
|
|
|
|
/* Set an orthographic projection matrix */
|
2013-05-29 03:07:55 -07:00
|
|
|
if (renderer->viewport.w && renderer->viewport.h) {
|
|
|
|
matrix.m[0][0] = 2.0f / renderer->viewport.w;
|
|
|
|
matrix.m[0][1] = 0.0f;
|
|
|
|
matrix.m[0][2] = 0.0f;
|
|
|
|
matrix.m[0][3] = 0.0f;
|
|
|
|
matrix.m[1][0] = 0.0f;
|
|
|
|
matrix.m[1][1] = -2.0f / renderer->viewport.h;
|
|
|
|
matrix.m[1][2] = 0.0f;
|
|
|
|
matrix.m[1][3] = 0.0f;
|
|
|
|
matrix.m[2][0] = 0.0f;
|
|
|
|
matrix.m[2][1] = 0.0f;
|
|
|
|
matrix.m[2][2] = 1.0f;
|
|
|
|
matrix.m[2][3] = 0.0f;
|
|
|
|
matrix.m[3][0] = -1.0f;
|
|
|
|
matrix.m[3][1] = 1.0f;
|
|
|
|
matrix.m[3][2] = 0.0f;
|
|
|
|
matrix.m[3][3] = 1.0f;
|
|
|
|
IDirect3DDevice9_SetTransform(data->device, D3DTS_PROJECTION, &matrix);
|
|
|
|
}
|
2011-02-07 20:06:26 -08:00
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-07 20:06:26 -08:00
|
|
|
|
2012-01-21 22:22:30 -05:00
|
|
|
static int
|
2013-05-04 04:46:00 -07:00
|
|
|
D3D_UpdateClipRect(SDL_Renderer * renderer)
|
2012-01-21 22:22:30 -05:00
|
|
|
{
|
2013-05-04 04:46:00 -07:00
|
|
|
const SDL_Rect *rect = &renderer->clip_rect;
|
2012-01-21 22:22:30 -05:00
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
2013-05-04 04:46:00 -07:00
|
|
|
RECT r;
|
2012-01-21 22:22:30 -05:00
|
|
|
HRESULT result;
|
|
|
|
|
2013-05-04 04:46:00 -07:00
|
|
|
if (!SDL_RectEmpty(rect)) {
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE);
|
|
|
|
r.left = rect->x;
|
|
|
|
r.top = rect->y;
|
2013-07-19 22:43:14 -07:00
|
|
|
r.right = rect->x + rect->w;
|
2013-05-04 04:46:00 -07:00
|
|
|
r.bottom = rect->y + rect->h;
|
2012-01-21 22:22:30 -05:00
|
|
|
|
2013-05-04 04:46:00 -07:00
|
|
|
result = IDirect3DDevice9_SetScissorRect(data->device, &r);
|
|
|
|
if (result != D3D_OK) {
|
|
|
|
D3D_SetError("SetScissor()", result);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE);
|
2012-01-21 22:22:30 -05:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
static int
|
|
|
|
D3D_RenderClear(SDL_Renderer * renderer)
|
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
DWORD color;
|
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
if (D3D_ActivateRenderer(renderer) < 0) {
|
|
|
|
return -1;
|
2011-02-07 20:06:26 -08:00
|
|
|
}
|
2011-02-15 13:59:59 -08:00
|
|
|
|
|
|
|
color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
|
|
|
|
|
2011-02-15 14:17:42 -08:00
|
|
|
/* Don't reset the viewport if we don't have to! */
|
|
|
|
if (!renderer->viewport.x && !renderer->viewport.y &&
|
|
|
|
renderer->viewport.w == data->pparams.BackBufferWidth &&
|
|
|
|
renderer->viewport.h == data->pparams.BackBufferHeight) {
|
|
|
|
result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
|
|
|
|
} else {
|
|
|
|
D3DVIEWPORT9 viewport;
|
|
|
|
|
|
|
|
/* Clear is defined to clear the entire render target */
|
|
|
|
viewport.X = 0;
|
|
|
|
viewport.Y = 0;
|
|
|
|
viewport.Width = data->pparams.BackBufferWidth;
|
|
|
|
viewport.Height = data->pparams.BackBufferHeight;
|
|
|
|
viewport.MinZ = 0.0f;
|
|
|
|
viewport.MaxZ = 1.0f;
|
|
|
|
IDirect3DDevice9_SetViewport(data->device, &viewport);
|
|
|
|
|
|
|
|
result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
|
|
|
|
|
|
|
|
/* Reset the viewport */
|
|
|
|
viewport.X = renderer->viewport.x;
|
|
|
|
viewport.Y = renderer->viewport.y;
|
|
|
|
viewport.Width = renderer->viewport.w;
|
|
|
|
viewport.Height = renderer->viewport.h;
|
|
|
|
viewport.MinZ = 0.0f;
|
|
|
|
viewport.MaxZ = 1.0f;
|
|
|
|
IDirect3DDevice9_SetViewport(data->device, &viewport);
|
|
|
|
}
|
2011-02-15 13:59:59 -08:00
|
|
|
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("Clear()", result);
|
2011-02-15 13:59:59 -08:00
|
|
|
}
|
|
|
|
return 0;
|
2011-02-07 20:06:26 -08:00
|
|
|
}
|
|
|
|
|
2008-12-31 06:17:24 +00:00
|
|
|
static void
|
2008-12-31 06:18:33 +00:00
|
|
|
D3D_SetBlendMode(D3D_RenderData * data, int blendMode)
|
2008-12-31 06:17:24 +00:00
|
|
|
{
|
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_NONE:
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
|
|
|
FALSE);
|
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
|
|
|
TRUE);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
|
|
|
|
D3DBLEND_SRCALPHA);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
|
|
|
|
D3DBLEND_INVSRCALPHA);
|
2013-07-23 08:06:49 -07:00
|
|
|
if (data->enableSeparateAlphaBlend) {
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
|
|
|
|
D3DBLEND_ONE);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
|
|
|
|
D3DBLEND_INVSRCALPHA);
|
|
|
|
}
|
2008-12-31 06:17:24 +00:00
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
|
|
|
TRUE);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
|
|
|
|
D3DBLEND_SRCALPHA);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
|
|
|
|
D3DBLEND_ONE);
|
2013-07-23 08:06:49 -07:00
|
|
|
if (data->enableSeparateAlphaBlend) {
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
|
|
|
|
D3DBLEND_ZERO);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
|
|
|
|
D3DBLEND_ONE);
|
|
|
|
}
|
2008-12-31 06:17:24 +00:00
|
|
|
break;
|
2011-02-04 19:50:56 -08:00
|
|
|
case SDL_BLENDMODE_MOD:
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
|
|
|
|
TRUE);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
|
|
|
|
D3DBLEND_ZERO);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
|
|
|
|
D3DBLEND_SRCCOLOR);
|
2013-07-23 08:06:49 -07:00
|
|
|
if (data->enableSeparateAlphaBlend) {
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
|
|
|
|
D3DBLEND_ZERO);
|
|
|
|
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
|
|
|
|
D3DBLEND_ONE);
|
|
|
|
}
|
2011-02-04 19:50:56 -08:00
|
|
|
break;
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-10-01 20:59:33 -07:00
|
|
|
D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
|
2009-12-24 19:18:05 +00:00
|
|
|
int count)
|
2008-12-31 06:17:24 +00:00
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
DWORD color;
|
2009-12-09 15:56:56 +00:00
|
|
|
Vertex *vertices;
|
|
|
|
int i;
|
2008-12-31 06:17:24 +00:00
|
|
|
HRESULT result;
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
if (D3D_ActivateRenderer(renderer) < 0) {
|
|
|
|
return -1;
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D3D_SetBlendMode(data, renderer->blendMode);
|
|
|
|
|
2008-12-31 06:18:33 +00:00
|
|
|
result =
|
|
|
|
IDirect3DDevice9_SetTexture(data->device, 0,
|
|
|
|
(IDirect3DBaseTexture9 *) 0);
|
2008-12-31 06:17:24 +00:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetTexture()", result);
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
2009-12-09 15:56:56 +00:00
|
|
|
|
|
|
|
color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
|
|
|
|
|
|
|
|
vertices = SDL_stack_alloc(Vertex, count);
|
|
|
|
for (i = 0; i < count; ++i) {
|
2012-10-01 20:59:33 -07:00
|
|
|
vertices[i].x = points[i].x;
|
|
|
|
vertices[i].y = points[i].y;
|
2009-12-09 15:56:56 +00:00
|
|
|
vertices[i].z = 0.0f;
|
|
|
|
vertices[i].color = color;
|
|
|
|
vertices[i].u = 0.0f;
|
|
|
|
vertices[i].v = 0.0f;
|
|
|
|
}
|
2008-12-31 06:17:24 +00:00
|
|
|
result =
|
2009-12-09 15:56:56 +00:00
|
|
|
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, count,
|
2008-12-31 06:17:24 +00:00
|
|
|
vertices, sizeof(*vertices));
|
2009-12-09 15:56:56 +00:00
|
|
|
SDL_stack_free(vertices);
|
2008-12-31 06:17:24 +00:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("DrawPrimitiveUP()", result);
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-10-01 20:59:33 -07:00
|
|
|
D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
|
2009-12-24 19:18:05 +00:00
|
|
|
int count)
|
2008-12-31 06:17:24 +00:00
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
DWORD color;
|
2009-12-09 15:56:56 +00:00
|
|
|
Vertex *vertices;
|
|
|
|
int i;
|
2008-12-31 06:17:24 +00:00
|
|
|
HRESULT result;
|
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
if (D3D_ActivateRenderer(renderer) < 0) {
|
|
|
|
return -1;
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D3D_SetBlendMode(data, renderer->blendMode);
|
|
|
|
|
2008-12-31 06:18:33 +00:00
|
|
|
result =
|
|
|
|
IDirect3DDevice9_SetTexture(data->device, 0,
|
|
|
|
(IDirect3DBaseTexture9 *) 0);
|
2008-12-31 06:17:24 +00:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetTexture()", result);
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
2009-12-09 15:56:56 +00:00
|
|
|
|
|
|
|
color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
|
|
|
|
|
|
|
|
vertices = SDL_stack_alloc(Vertex, count);
|
|
|
|
for (i = 0; i < count; ++i) {
|
2012-10-01 20:59:33 -07:00
|
|
|
vertices[i].x = points[i].x;
|
|
|
|
vertices[i].y = points[i].y;
|
2009-12-09 15:56:56 +00:00
|
|
|
vertices[i].z = 0.0f;
|
|
|
|
vertices[i].color = color;
|
|
|
|
vertices[i].u = 0.0f;
|
|
|
|
vertices[i].v = 0.0f;
|
|
|
|
}
|
2008-12-31 06:17:24 +00:00
|
|
|
result =
|
2009-12-12 20:31:28 +00:00
|
|
|
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count-1,
|
2008-12-31 06:17:24 +00:00
|
|
|
vertices, sizeof(*vertices));
|
2009-12-12 20:31:28 +00:00
|
|
|
|
|
|
|
/* DirectX 9 has the same line rasterization semantics as GDI,
|
|
|
|
so we need to close the endpoint of the line */
|
2011-11-10 00:22:44 -05:00
|
|
|
if (count == 2 ||
|
|
|
|
points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
|
2012-10-01 20:59:33 -07:00
|
|
|
vertices[0].x = points[count-1].x;
|
|
|
|
vertices[0].y = points[count-1].y;
|
2009-12-12 20:31:28 +00:00
|
|
|
result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, vertices, sizeof(*vertices));
|
|
|
|
}
|
|
|
|
|
2009-12-09 15:56:56 +00:00
|
|
|
SDL_stack_free(vertices);
|
2008-12-31 06:17:24 +00:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("DrawPrimitiveUP()", result);
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-24 19:18:05 +00:00
|
|
|
static int
|
2012-10-01 20:59:33 -07:00
|
|
|
D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
|
2009-12-24 19:18:05 +00:00
|
|
|
int count)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
2008-12-31 06:17:24 +00:00
|
|
|
DWORD color;
|
2009-12-09 15:56:56 +00:00
|
|
|
int i;
|
|
|
|
float minx, miny, maxx, maxy;
|
2008-12-31 06:17:24 +00:00
|
|
|
Vertex vertices[4];
|
2006-07-12 09:25:17 +00:00
|
|
|
HRESULT result;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
if (D3D_ActivateRenderer(renderer) < 0) {
|
|
|
|
return -1;
|
2006-07-12 09:25:17 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2008-12-31 06:17:24 +00:00
|
|
|
D3D_SetBlendMode(data, renderer->blendMode);
|
|
|
|
|
2008-12-31 06:18:33 +00:00
|
|
|
result =
|
|
|
|
IDirect3DDevice9_SetTexture(data->device, 0,
|
|
|
|
(IDirect3DBaseTexture9 *) 0);
|
2008-12-31 06:17:24 +00:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetTexture()", result);
|
2008-12-31 06:17:24 +00:00
|
|
|
}
|
2009-12-09 15:56:56 +00:00
|
|
|
|
|
|
|
color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_FRect *rect = &rects[i];
|
2009-12-09 15:56:56 +00:00
|
|
|
|
2012-10-01 20:59:33 -07:00
|
|
|
minx = rect->x;
|
|
|
|
miny = rect->y;
|
|
|
|
maxx = rect->x + rect->w;
|
|
|
|
maxy = rect->y + rect->h;
|
2009-12-09 15:56:56 +00:00
|
|
|
|
|
|
|
vertices[0].x = minx;
|
|
|
|
vertices[0].y = miny;
|
|
|
|
vertices[0].z = 0.0f;
|
|
|
|
vertices[0].color = color;
|
|
|
|
vertices[0].u = 0.0f;
|
|
|
|
vertices[0].v = 0.0f;
|
|
|
|
|
|
|
|
vertices[1].x = maxx;
|
|
|
|
vertices[1].y = miny;
|
|
|
|
vertices[1].z = 0.0f;
|
|
|
|
vertices[1].color = color;
|
|
|
|
vertices[1].u = 0.0f;
|
|
|
|
vertices[1].v = 0.0f;
|
|
|
|
|
|
|
|
vertices[2].x = maxx;
|
|
|
|
vertices[2].y = maxy;
|
|
|
|
vertices[2].z = 0.0f;
|
|
|
|
vertices[2].color = color;
|
|
|
|
vertices[2].u = 0.0f;
|
|
|
|
vertices[2].v = 0.0f;
|
|
|
|
|
|
|
|
vertices[3].x = minx;
|
|
|
|
vertices[3].y = maxy;
|
|
|
|
vertices[3].z = 0.0f;
|
|
|
|
vertices[3].color = color;
|
|
|
|
vertices[3].u = 0.0f;
|
|
|
|
vertices[3].v = 0.0f;
|
|
|
|
|
|
|
|
result =
|
|
|
|
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN,
|
|
|
|
2, vertices, sizeof(*vertices));
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("DrawPrimitiveUP()", result);
|
2009-12-09 15:56:56 +00:00
|
|
|
}
|
2006-07-12 09:25:17 +00:00
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
|
2009-12-14 04:19:00 +00:00
|
|
|
LPDIRECT3DPIXELSHADER9 shader = NULL;
|
2006-07-14 06:40:53 +00:00
|
|
|
float minx, miny, maxx, maxy;
|
2006-07-14 07:41:16 +00:00
|
|
|
float minu, maxu, minv, maxv;
|
2006-08-28 04:03:32 +00:00
|
|
|
DWORD color;
|
2006-07-14 06:40:53 +00:00
|
|
|
Vertex vertices[4];
|
|
|
|
HRESULT result;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
2011-02-15 13:59:59 -08:00
|
|
|
if (D3D_ActivateRenderer(renderer) < 0) {
|
|
|
|
return -1;
|
2006-07-12 09:25:17 +00:00
|
|
|
}
|
2006-07-14 06:40:53 +00:00
|
|
|
|
2012-10-01 20:59:33 -07:00
|
|
|
minx = dstrect->x - 0.5f;
|
|
|
|
miny = dstrect->y - 0.5f;
|
|
|
|
maxx = dstrect->x + dstrect->w - 0.5f;
|
|
|
|
maxy = dstrect->y + dstrect->h - 0.5f;
|
2006-07-14 06:40:53 +00:00
|
|
|
|
2006-07-14 07:41:16 +00:00
|
|
|
minu = (float) srcrect->x / texture->w;
|
|
|
|
maxu = (float) (srcrect->x + srcrect->w) / texture->w;
|
|
|
|
minv = (float) srcrect->y / texture->h;
|
|
|
|
maxv = (float) (srcrect->y + srcrect->h) / texture->h;
|
2006-07-14 06:40:53 +00:00
|
|
|
|
2006-08-28 04:03:32 +00:00
|
|
|
color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
|
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
vertices[0].x = minx;
|
|
|
|
vertices[0].y = miny;
|
|
|
|
vertices[0].z = 0.0f;
|
2006-08-28 04:03:32 +00:00
|
|
|
vertices[0].color = color;
|
2006-07-14 07:41:16 +00:00
|
|
|
vertices[0].u = minu;
|
|
|
|
vertices[0].v = minv;
|
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
vertices[1].x = maxx;
|
|
|
|
vertices[1].y = miny;
|
|
|
|
vertices[1].z = 0.0f;
|
2006-08-28 04:03:32 +00:00
|
|
|
vertices[1].color = color;
|
2006-07-14 07:41:16 +00:00
|
|
|
vertices[1].u = maxu;
|
|
|
|
vertices[1].v = minv;
|
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
vertices[2].x = maxx;
|
|
|
|
vertices[2].y = maxy;
|
|
|
|
vertices[2].z = 0.0f;
|
2006-08-28 04:03:32 +00:00
|
|
|
vertices[2].color = color;
|
2006-07-14 07:41:16 +00:00
|
|
|
vertices[2].u = maxu;
|
|
|
|
vertices[2].v = maxv;
|
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
vertices[3].x = minx;
|
|
|
|
vertices[3].y = maxy;
|
|
|
|
vertices[3].z = 0.0f;
|
2006-08-28 04:03:32 +00:00
|
|
|
vertices[3].color = color;
|
2006-07-14 07:41:16 +00:00
|
|
|
vertices[3].u = minu;
|
|
|
|
vertices[3].v = maxv;
|
2006-07-14 06:40:53 +00:00
|
|
|
|
2008-12-31 06:17:24 +00:00
|
|
|
D3D_SetBlendMode(data, texture->blendMode);
|
2006-07-19 05:03:21 +00:00
|
|
|
|
2011-03-13 11:18:35 -07:00
|
|
|
if (texturedata->scaleMode != data->scaleMode) {
|
|
|
|
IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
|
|
|
|
texturedata->scaleMode);
|
|
|
|
IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
|
|
|
|
texturedata->scaleMode);
|
|
|
|
data->scaleMode = texturedata->scaleMode;
|
|
|
|
}
|
2006-07-19 05:45:42 +00:00
|
|
|
|
2006-07-14 06:40:53 +00:00
|
|
|
result =
|
2008-08-27 15:10:03 +00:00
|
|
|
IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
|
|
|
|
texturedata->texture);
|
2006-07-14 06:40:53 +00:00
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetTexture()", result);
|
2006-07-14 06:40:53 +00:00
|
|
|
}
|
2009-12-14 04:19:00 +00:00
|
|
|
if (shader) {
|
|
|
|
result = IDirect3DDevice9_SetPixelShader(data->device, shader);
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetShader()", result);
|
2009-12-14 04:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-14 06:40:53 +00:00
|
|
|
result =
|
|
|
|
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
|
|
|
|
vertices, sizeof(*vertices));
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("DrawPrimitiveUP()", result);
|
2006-07-14 06:40:53 +00:00
|
|
|
}
|
2009-12-14 04:19:00 +00:00
|
|
|
if (shader) {
|
|
|
|
result = IDirect3DDevice9_SetPixelShader(data->device, NULL);
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetShader()", result);
|
2009-12-14 04:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-01 19:51:08 -03:00
|
|
|
|
|
|
|
static int
|
|
|
|
D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
|
2012-10-01 20:59:33 -07:00
|
|
|
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
|
|
|
|
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip)
|
2012-06-01 19:51:08 -03:00
|
|
|
{
|
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
|
|
|
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
|
|
|
|
LPDIRECT3DPIXELSHADER9 shader = NULL;
|
|
|
|
float minx, miny, maxx, maxy;
|
|
|
|
float minu, maxu, minv, maxv;
|
|
|
|
float centerx, centery;
|
|
|
|
DWORD color;
|
|
|
|
Vertex vertices[4];
|
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
if (D3D_ActivateRenderer(renderer) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-01 20:59:33 -07:00
|
|
|
centerx = center->x;
|
|
|
|
centery = center->y;
|
2012-06-01 19:51:08 -03:00
|
|
|
|
|
|
|
if (flip & SDL_FLIP_HORIZONTAL) {
|
2012-10-01 20:59:33 -07:00
|
|
|
minx = dstrect->w - centerx - 0.5f;
|
|
|
|
maxx = -centerx - 0.5f;
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
else {
|
2012-10-01 20:59:33 -07:00
|
|
|
minx = -centerx - 0.5f;
|
|
|
|
maxx = dstrect->w - centerx - 0.5f;
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flip & SDL_FLIP_VERTICAL) {
|
2012-10-01 20:59:33 -07:00
|
|
|
miny = dstrect->h - centery - 0.5f;
|
|
|
|
maxy = -centery - 0.5f;
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
else {
|
2012-10-01 20:59:33 -07:00
|
|
|
miny = -centery - 0.5f;
|
|
|
|
maxy = dstrect->h - centery - 0.5f;
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
minu = (float) srcrect->x / texture->w;
|
|
|
|
maxu = (float) (srcrect->x + srcrect->w) / texture->w;
|
|
|
|
minv = (float) srcrect->y / texture->h;
|
|
|
|
maxv = (float) (srcrect->y + srcrect->h) / texture->h;
|
|
|
|
|
|
|
|
color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
|
|
|
|
|
|
|
|
vertices[0].x = minx;
|
|
|
|
vertices[0].y = miny;
|
|
|
|
vertices[0].z = 0.0f;
|
|
|
|
vertices[0].color = color;
|
|
|
|
vertices[0].u = minu;
|
|
|
|
vertices[0].v = minv;
|
|
|
|
|
|
|
|
vertices[1].x = maxx;
|
|
|
|
vertices[1].y = miny;
|
|
|
|
vertices[1].z = 0.0f;
|
|
|
|
vertices[1].color = color;
|
|
|
|
vertices[1].u = maxu;
|
|
|
|
vertices[1].v = minv;
|
|
|
|
|
|
|
|
vertices[2].x = maxx;
|
|
|
|
vertices[2].y = maxy;
|
|
|
|
vertices[2].z = 0.0f;
|
|
|
|
vertices[2].color = color;
|
|
|
|
vertices[2].u = maxu;
|
|
|
|
vertices[2].v = maxv;
|
|
|
|
|
|
|
|
vertices[3].x = minx;
|
|
|
|
vertices[3].y = maxy;
|
|
|
|
vertices[3].z = 0.0f;
|
|
|
|
vertices[3].color = color;
|
|
|
|
vertices[3].u = minu;
|
|
|
|
vertices[3].v = maxv;
|
|
|
|
|
|
|
|
D3D_SetBlendMode(data, texture->blendMode);
|
|
|
|
|
2013-05-18 14:17:52 -07:00
|
|
|
/* Rotate and translate */
|
2012-06-01 19:51:08 -03:00
|
|
|
ID3DXMatrixStack_Push(data->matrixStack);
|
|
|
|
ID3DXMatrixStack_LoadIdentity(data->matrixStack);
|
2012-06-19 13:50:14 -04:00
|
|
|
ID3DXMatrixStack_RotateYawPitchRoll(data->matrixStack, 0.0, 0.0, (float)(M_PI * (float) angle / 180.0f));
|
2012-06-01 19:51:08 -03:00
|
|
|
ID3DXMatrixStack_Translate(data->matrixStack, (float)dstrect->x + centerx, (float)dstrect->y + centery, (float)0.0);
|
|
|
|
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)ID3DXMatrixStack_GetTop(data->matrixStack));
|
|
|
|
|
|
|
|
if (texturedata->scaleMode != data->scaleMode) {
|
|
|
|
IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
|
|
|
|
texturedata->scaleMode);
|
|
|
|
IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
|
|
|
|
texturedata->scaleMode);
|
|
|
|
data->scaleMode = texturedata->scaleMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
result =
|
|
|
|
IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
|
|
|
|
texturedata->texture);
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetTexture()", result);
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
if (shader) {
|
|
|
|
result = IDirect3DDevice9_SetPixelShader(data->device, shader);
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetShader()", result);
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
result =
|
|
|
|
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
|
|
|
|
vertices, sizeof(*vertices));
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("DrawPrimitiveUP()", result);
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
if (shader) {
|
|
|
|
result = IDirect3DDevice9_SetPixelShader(data->device, NULL);
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("SetShader()", result);
|
2012-06-01 19:51:08 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ID3DXMatrixStack_Pop(data->matrixStack);
|
|
|
|
ID3DXMatrixStack_Push(data->matrixStack);
|
|
|
|
ID3DXMatrixStack_LoadIdentity(data->matrixStack);
|
|
|
|
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)ID3DXMatrixStack_GetTop(data->matrixStack));
|
|
|
|
ID3DXMatrixStack_Pop(data->matrixStack);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-09 05:20:11 +00:00
|
|
|
static int
|
|
|
|
D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
2009-11-22 06:37:43 +00:00
|
|
|
Uint32 format, void * pixels, int pitch)
|
2009-11-09 05:20:11 +00:00
|
|
|
{
|
2009-12-12 04:01:40 +00:00
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
2009-11-09 05:20:11 +00:00
|
|
|
D3DSURFACE_DESC desc;
|
2009-12-12 04:01:40 +00:00
|
|
|
LPDIRECT3DSURFACE9 backBuffer;
|
|
|
|
LPDIRECT3DSURFACE9 surface;
|
|
|
|
RECT d3drect;
|
|
|
|
D3DLOCKED_RECT locked;
|
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
result = IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
|
|
|
|
if (FAILED(result)) {
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("GetBackBuffer()", result);
|
2009-12-12 04:01:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = IDirect3DSurface9_GetDesc(backBuffer, &desc);
|
|
|
|
if (FAILED(result)) {
|
|
|
|
IDirect3DSurface9_Release(backBuffer);
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("GetDesc()", result);
|
2009-12-12 04:01:40 +00:00
|
|
|
}
|
2009-11-09 05:20:11 +00:00
|
|
|
|
2009-12-12 04:01:40 +00:00
|
|
|
result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL);
|
|
|
|
if (FAILED(result)) {
|
|
|
|
IDirect3DSurface9_Release(backBuffer);
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("CreateOffscreenPlainSurface()", result);
|
2009-12-12 04:01:40 +00:00
|
|
|
}
|
2009-11-09 05:20:11 +00:00
|
|
|
|
2009-12-12 04:01:40 +00:00
|
|
|
result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface);
|
|
|
|
if (FAILED(result)) {
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
IDirect3DSurface9_Release(backBuffer);
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("GetRenderTargetData()", result);
|
2009-12-12 04:01:40 +00:00
|
|
|
}
|
2009-11-09 05:20:11 +00:00
|
|
|
|
2009-12-12 04:01:40 +00:00
|
|
|
d3drect.left = rect->x;
|
|
|
|
d3drect.right = rect->x + rect->w;
|
|
|
|
d3drect.top = rect->y;
|
|
|
|
d3drect.bottom = rect->y + rect->h;
|
2009-11-09 05:20:11 +00:00
|
|
|
|
2009-12-12 04:01:40 +00:00
|
|
|
result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY);
|
|
|
|
if (FAILED(result)) {
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
IDirect3DSurface9_Release(backBuffer);
|
2013-03-31 12:48:50 -04:00
|
|
|
return D3D_SetError("LockRect()", result);
|
2009-12-12 04:01:40 +00:00
|
|
|
}
|
2009-11-09 05:20:11 +00:00
|
|
|
|
2009-12-12 04:01:40 +00:00
|
|
|
SDL_ConvertPixels(rect->w, rect->h,
|
2011-02-03 00:19:40 -08:00
|
|
|
D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch,
|
2009-12-12 04:01:40 +00:00
|
|
|
format, pixels, pitch);
|
2009-11-09 05:20:11 +00:00
|
|
|
|
2009-12-12 04:01:40 +00:00
|
|
|
IDirect3DSurface9_UnlockRect(surface);
|
|
|
|
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
IDirect3DSurface9_Release(backBuffer);
|
|
|
|
|
|
|
|
return 0;
|
2009-11-09 05:20:11 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_RenderPresent(SDL_Renderer * renderer)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
2006-07-12 09:25:17 +00:00
|
|
|
HRESULT result;
|
|
|
|
|
|
|
|
if (!data->beginScene) {
|
|
|
|
IDirect3DDevice9_EndScene(data->device);
|
|
|
|
data->beginScene = SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-08-07 05:24:13 +00:00
|
|
|
result = IDirect3DDevice9_TestCooperativeLevel(data->device);
|
|
|
|
if (result == D3DERR_DEVICELOST) {
|
|
|
|
/* We'll reset later */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (result == D3DERR_DEVICENOTRESET) {
|
|
|
|
D3D_Reset(renderer);
|
|
|
|
}
|
2006-07-12 09:25:17 +00:00
|
|
|
result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
|
|
|
|
if (FAILED(result)) {
|
|
|
|
D3D_SetError("Present()", result);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
2006-07-14 06:40:53 +00:00
|
|
|
if (data->texture) {
|
|
|
|
IDirect3DTexture9_Release(data->texture);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_free(data);
|
|
|
|
texture->driverdata = NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-07 05:24:13 +00:00
|
|
|
static void
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_DestroyRenderer(SDL_Renderer * renderer)
|
2006-07-10 21:04:37 +00:00
|
|
|
{
|
2006-07-17 06:47:33 +00:00
|
|
|
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
if (data) {
|
2013-05-18 14:17:52 -07:00
|
|
|
/* Release the render target */
|
2013-02-17 23:30:47 -08:00
|
|
|
if (data->defaultRenderTarget) {
|
|
|
|
IDirect3DSurface9_Release(data->defaultRenderTarget);
|
|
|
|
data->defaultRenderTarget = NULL;
|
|
|
|
}
|
2012-01-18 22:45:49 -05:00
|
|
|
if (data->currentRenderTarget != NULL) {
|
|
|
|
IDirect3DSurface9_Release(data->currentRenderTarget);
|
|
|
|
data->currentRenderTarget = NULL;
|
|
|
|
}
|
2013-05-18 14:17:52 -07:00
|
|
|
|
2006-07-12 09:25:17 +00:00
|
|
|
if (data->device) {
|
|
|
|
IDirect3DDevice9_Release(data->device);
|
|
|
|
}
|
2011-02-02 14:34:54 -08:00
|
|
|
if (data->d3d) {
|
|
|
|
IDirect3D9_Release(data->d3d);
|
2013-05-16 00:56:19 -07:00
|
|
|
ID3DXMatrixStack_Release(data->matrixStack);
|
2011-02-02 14:34:54 -08:00
|
|
|
SDL_UnloadObject(data->d3dDLL);
|
|
|
|
}
|
2006-07-10 21:04:37 +00:00
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
SDL_free(renderer);
|
|
|
|
}
|
|
|
|
|
2011-02-08 10:04:09 -08:00
|
|
|
#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
|
2006-07-10 21:04:37 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|