Update for SDL3 coding style (#6717)

I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
This commit is contained in:
Sam Lantinga 2022-11-30 12:51:59 -08:00 committed by GitHub
parent 14b902faca
commit 5750bcb174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
781 changed files with 51659 additions and 55763 deletions

View file

@ -20,7 +20,6 @@
*/
#include "SDL_internal.h"
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
#include "../../core/windows/SDL_windows.h"
@ -52,12 +51,11 @@ typedef struct
LPDIRECT3DPIXELSHADER9 shader;
} D3D_DrawStateCache;
/* Direct3D renderer implementation */
typedef struct
{
void* d3dDLL;
void *d3dDLL;
IDirect3D9 *d3d;
IDirect3DDevice9 *device;
UINT adapter;
@ -68,7 +66,7 @@ typedef struct
D3DTEXTUREFILTERTYPE scaleMode[8];
IDirect3DSurface9 *defaultRenderTarget;
IDirect3DSurface9 *currentRenderTarget;
void* d3dxDLL;
void *d3dxDLL;
#if SDL_HAVE_YUV
LPDIRECT3DPIXELSHADER9 shaders[NUM_SHADERS];
#endif
@ -113,8 +111,7 @@ typedef struct
float u, v;
} Vertex;
static int
D3D_SetError(const char *prefix, HRESULT result)
static int D3D_SetError(const char *prefix, HRESULT result)
{
const char *error;
@ -192,8 +189,7 @@ D3D_SetError(const char *prefix, HRESULT result)
return SDL_SetError("%s: %s", prefix, error);
}
static D3DFORMAT
PixelFormatToD3DFMT(Uint32 format)
static D3DFORMAT PixelFormatToD3DFMT(Uint32 format)
{
switch (format) {
case SDL_PIXELFORMAT_RGB565:
@ -212,8 +208,7 @@ PixelFormatToD3DFMT(Uint32 format)
}
}
static Uint32
D3DFMTToPixelFormat(D3DFORMAT format)
static Uint32 D3DFMTToPixelFormat(D3DFORMAT format)
{
switch (format) {
case D3DFMT_R5G6B5:
@ -227,8 +222,7 @@ D3DFMTToPixelFormat(D3DFORMAT format)
}
}
static void
D3D_InitRenderState(D3D_RenderData *data)
static void D3D_InitRenderState(D3D_RenderData *data)
{
D3DMATRIX matrix;
@ -286,12 +280,11 @@ D3D_InitRenderState(D3D_RenderData *data)
data->beginScene = SDL_TRUE;
}
static int D3D_Reset(SDL_Renderer * renderer);
static int D3D_Reset(SDL_Renderer *renderer);
static int
D3D_ActivateRenderer(SDL_Renderer * renderer)
static int D3D_ActivateRenderer(SDL_Renderer *renderer)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
HRESULT result;
if (data->updateSize) {
@ -335,25 +328,22 @@ D3D_ActivateRenderer(SDL_Renderer * renderer)
return 0;
}
static void
D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
static void D3D_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
data->updateSize = SDL_TRUE;
}
}
static int
D3D_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
static int D3D_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
{
SDL_GetWindowSizeInPixels(renderer->window, w, h);
return 0;
}
static D3DBLEND
GetBlendFunc(SDL_BlendFactor factor)
static D3DBLEND GetBlendFunc(SDL_BlendFactor factor)
{
switch (factor) {
case SDL_BLENDFACTOR_ZERO:
@ -376,13 +366,13 @@ GetBlendFunc(SDL_BlendFactor factor)
return D3DBLEND_DESTALPHA;
case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
return D3DBLEND_INVDESTALPHA;
default: break;
default:
break;
}
return (D3DBLEND) 0;
return (D3DBLEND)0;
}
static D3DBLENDOP
GetBlendEquation(SDL_BlendOperation operation)
static D3DBLENDOP GetBlendEquation(SDL_BlendOperation operation)
{
switch (operation) {
case SDL_BLENDOPERATION_ADD:
@ -395,15 +385,15 @@ GetBlendEquation(SDL_BlendOperation operation)
return D3DBLENDOP_MIN;
case SDL_BLENDOPERATION_MAXIMUM:
return D3DBLENDOP_MAX;
default: break;
default:
break;
}
return (D3DBLENDOP) 0;
return (D3DBLENDOP)0;
}
static SDL_bool
D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
static SDL_bool D3D_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
@ -426,8 +416,7 @@ D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
return SDL_TRUE;
}
static int
D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, D3DFORMAT d3dfmt, int w, int h)
static int D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, D3DFORMAT d3dfmt, int w, int h)
{
HRESULT result;
@ -439,23 +428,21 @@ D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD us
texture->d3dfmt = d3dfmt;
result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
PixelFormatToD3DFMT(format),
D3DPOOL_DEFAULT, &texture->texture, NULL);
PixelFormatToD3DFMT(format),
D3DPOOL_DEFAULT, &texture->texture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
}
return 0;
}
static int
D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
static int D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
{
HRESULT result;
if (texture->staging == NULL) {
result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, 0,
texture->d3dfmt, D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
texture->d3dfmt, D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture(D3DPOOL_SYSTEMMEM)", result);
}
@ -463,8 +450,7 @@ D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
return 0;
}
static int
D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture)
static int D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture)
{
if (texture->texture) {
IDirect3DTexture9_Release(texture->texture);
@ -477,8 +463,7 @@ D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture)
return 0;
}
static int
D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, int y, int w, int h, const void *pixels, int pitch)
static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, int y, int w, int h, const void *pixels, int pitch)
{
RECT d3drect;
D3DLOCKED_RECT locked;
@ -495,7 +480,7 @@ D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, i
d3drect.right = x + w;
d3drect.top = y;
d3drect.bottom = y + h;
result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0);
if (FAILED(result)) {
return D3D_SetError("LockRect()", result);
@ -505,7 +490,7 @@ D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, i
dst = (Uint8 *)locked.pBits;
length = w * SDL_BYTESPERPIXEL(texture->format);
if (length == pitch && length == locked.Pitch) {
SDL_memcpy(dst, src, length*h);
SDL_memcpy(dst, src, length * h);
} else {
if (length > pitch) {
length = pitch;
@ -528,8 +513,7 @@ D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, i
return 0;
}
static void
D3D_DestroyTextureRep(D3D_TextureRep *texture)
static void D3D_DestroyTextureRep(D3D_TextureRep *texture)
{
if (texture->texture) {
IDirect3DTexture9_Release(texture->texture);
@ -541,14 +525,13 @@ D3D_DestroyTextureRep(D3D_TextureRep *texture)
}
}
static int
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata;
DWORD usage;
texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata));
texturedata = (D3D_TextureData *)SDL_calloc(1, sizeof(*texturedata));
if (texturedata == NULL) {
return SDL_OutOfMemory();
}
@ -582,8 +565,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
static int
D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static int D3D_RecreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
@ -609,12 +591,11 @@ D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
static int
D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
static int D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels, int pitch)
{
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
if (texturedata == NULL) {
return SDL_SetError("Texture is not currently available");
@ -626,14 +607,14 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
#if SDL_HAVE_YUV
if (texturedata->yuv) {
/* 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_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->vtexture : &texturedata->utexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2) < 0) {
return -1;
}
/* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)pixels + ((rect->h + 1) / 2) * ((pitch + 1) / 2));
pixels = (const void *)((const Uint8 *)pixels + ((rect->h + 1) / 2) * ((pitch + 1) / 2));
if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->utexture : &texturedata->vtexture, rect->x / 2, (rect->y + 1) / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2) < 0) {
return -1;
}
@ -643,15 +624,14 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
}
#if SDL_HAVE_YUV
static int
D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
static int D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
if (texturedata == NULL) {
return SDL_SetError("Texture is not currently available");
@ -670,9 +650,8 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
}
#endif
static int
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
{
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
@ -694,8 +673,8 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
}
}
*pixels =
(void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
(void *)((Uint8 *)texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = texturedata->pitch;
} else
#endif
@ -723,8 +702,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}
static void
D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
@ -736,8 +714,8 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (texturedata->yuv) {
const SDL_Rect *rect = &texturedata->locked_rect;
void *pixels =
(void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
(void *)((Uint8 *)texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
} else
#endif
@ -753,8 +731,7 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
}
static void
D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
static void D3D_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
{
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
@ -765,10 +742,9 @@ D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Scal
texturedata->scaleMode = (scaleMode == SDL_ScaleModeNearest) ? D3DTEXF_POINT : D3DTEXF_LINEAR;
}
static int
D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
static int D3D_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *texture)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata;
D3D_TextureRep *texturerep;
HRESULT result;
@ -795,7 +771,7 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
if (texturerep->dirty && texturerep->staging) {
if (!texturerep->texture) {
result = IDirect3DDevice9_CreateTexture(device, texturerep->w, texturerep->h, 1, texturerep->usage,
PixelFormatToD3DFMT(texturerep->format), D3DPOOL_DEFAULT, &texturerep->texture, NULL);
PixelFormatToD3DFMT(texturerep->format), D3DPOOL_DEFAULT, &texturerep->texture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
}
@ -820,8 +796,7 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
static int
D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
static int D3D_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
if (D3D_ActivateRenderer(renderer) < 0) {
return -1;
@ -830,19 +805,16 @@ D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
return D3D_SetRenderTargetInternal(renderer, texture);
}
static int
D3D_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
static int D3D_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{
return 0; /* nothing to do in this backend. */
return 0; /* nothing to do in this backend. */
}
static int
D3D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
static int D3D_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
const size_t vertslen = count * sizeof (Vertex);
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
const size_t vertslen = count * sizeof(Vertex);
Vertex *verts = (Vertex *)SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
int i;
if (verts == NULL) {
@ -861,15 +833,14 @@ D3D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
return 0;
}
static int
D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
static int D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
{
int i;
int count = indices ? num_indices : num_vertices;
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, count * sizeof (Vertex), 0, &cmd->data.draw.first);
Vertex *verts = (Vertex *)SDL_AllocateRenderVertices(renderer, count * sizeof(Vertex), 0, &cmd->data.draw.first);
if (verts == NULL) {
return -1;
@ -892,8 +863,8 @@ D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t
j = i;
}
xy_ = (float *)((char*)xy + j * xy_stride);
col_ = *(SDL_Color *)((char*)color + j * color_stride);
xy_ = (float *)((char *)xy + j * xy_stride);
col_ = *(SDL_Color *)((char *)color + j * color_stride);
verts->x = xy_[0] * scale_x - 0.5f;
verts->y = xy_[1] * scale_y - 0.5f;
@ -901,7 +872,7 @@ D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t
verts->color = D3DCOLOR_ARGB(col_.a, col_.r, col_.g, col_.b);
if (texture) {
float *uv_ = (float *)((char*)uv + j * uv_stride);
float *uv_ = (float *)((char *)uv + j * uv_stride);
verts->u = uv_[0];
verts->v = uv_[1];
} else {
@ -914,14 +885,13 @@ D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t
return 0;
}
static int
UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
static int UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
{
if (texture->dirty && texture->staging) {
HRESULT result;
if (!texture->texture) {
result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, texture->usage,
PixelFormatToD3DFMT(texture->format), D3DPOOL_DEFAULT, &texture->texture, NULL);
PixelFormatToD3DFMT(texture->format), D3DPOOL_DEFAULT, &texture->texture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
}
@ -936,8 +906,7 @@ UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
return 0;
}
static int
BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
static int BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
{
HRESULT result;
UpdateDirtyTexture(device, texture);
@ -948,8 +917,7 @@ BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
return 0;
}
static void
UpdateTextureScaleMode(D3D_RenderData *data, D3D_TextureData *texturedata, unsigned index)
static void UpdateTextureScaleMode(D3D_RenderData *data, D3D_TextureData *texturedata, unsigned index)
{
if (texturedata->scaleMode != data->scaleMode[index]) {
IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MINFILTER,
@ -964,8 +932,7 @@ UpdateTextureScaleMode(D3D_RenderData *data, D3D_TextureData *texturedata, unsig
}
}
static int
SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSHADER9 *shader)
static int SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, LPDIRECT3DPIXELSHADER9 *shader)
{
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
@ -1010,16 +977,15 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
return 0;
}
static int
SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
static int SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
{
SDL_Texture *texture = cmd->data.draw.texture;
const SDL_BlendMode blend = cmd->data.draw.blend;
if (texture != data->drawstate.texture) {
#if SDL_HAVE_YUV
D3D_TextureData *oldtexturedata = data->drawstate.texture ? (D3D_TextureData *) data->drawstate.texture->driverdata : NULL;
D3D_TextureData *newtexturedata = texture ? (D3D_TextureData *) texture->driverdata : NULL;
D3D_TextureData *oldtexturedata = data->drawstate.texture ? (D3D_TextureData *)data->drawstate.texture->driverdata : NULL;
D3D_TextureData *newtexturedata = texture ? (D3D_TextureData *)texture->driverdata : NULL;
#endif
LPDIRECT3DPIXELSHADER9 shader = NULL;
@ -1047,7 +1013,7 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
data->drawstate.texture = texture;
} else if (texture) {
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
UpdateDirtyTexture(data->device, &texturedata->texture);
#if SDL_HAVE_YUV
if (texturedata->yuv) {
@ -1128,10 +1094,9 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
return 0;
}
static int
D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
static int D3D_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
const int vboidx = data->currentVertexBuffer;
IDirect3DVertexBuffer9 *vbo = NULL;
const SDL_bool istarget = renderer->target != NULL;
@ -1150,7 +1115,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
IDirect3DVertexBuffer9_Release(vbo);
}
if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, (UINT) vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, (UINT)vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
vbo = NULL;
}
data->vertexBuffers[vboidx] = vbo;
@ -1159,12 +1124,12 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
if (vbo) {
void *ptr;
if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, (UINT) vertsize, &ptr, D3DLOCK_DISCARD))) {
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, (UINT)vertsize, &ptr, D3DLOCK_DISCARD))) {
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
} else {
SDL_memcpy(ptr, vertices, vertsize);
if (FAILED(IDirect3DVertexBuffer9_Unlock(vbo))) {
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
}
}
}
@ -1184,130 +1149,137 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
}
}
IDirect3DDevice9_SetStreamSource(data->device, 0, vbo, 0, sizeof (Vertex));
IDirect3DDevice9_SetStreamSource(data->device, 0, vbo, 0, sizeof(Vertex));
while (cmd) {
switch (cmd->command) {
case SDL_RENDERCMD_SETDRAWCOLOR: {
/* currently this is sent with each vertex, but if we move to
shaders, we can put this in a uniform here and reduce vertex
buffer bandwidth */
break;
case SDL_RENDERCMD_SETDRAWCOLOR:
{
/* currently this is sent with each vertex, but if we move to
shaders, we can put this in a uniform here and reduce vertex
buffer bandwidth */
break;
}
case SDL_RENDERCMD_SETVIEWPORT:
{
SDL_Rect *viewport = &data->drawstate.viewport;
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
SDL_copyp(viewport, &cmd->data.viewport.rect);
data->drawstate.viewport_dirty = SDL_TRUE;
}
break;
}
case SDL_RENDERCMD_SETCLIPRECT:
{
const SDL_Rect *rect = &cmd->data.cliprect.rect;
if (data->drawstate.cliprect_enabled != cmd->data.cliprect.enabled) {
data->drawstate.cliprect_enabled = cmd->data.cliprect.enabled;
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
}
case SDL_RENDERCMD_SETVIEWPORT: {
SDL_Rect *viewport = &data->drawstate.viewport;
if (SDL_memcmp(viewport, &cmd->data.viewport.rect, sizeof(cmd->data.viewport.rect)) != 0) {
SDL_copyp(viewport, &cmd->data.viewport.rect);
data->drawstate.viewport_dirty = SDL_TRUE;
}
break;
if (SDL_memcmp(&data->drawstate.cliprect, rect, sizeof(*rect)) != 0) {
SDL_copyp(&data->drawstate.cliprect, rect);
data->drawstate.cliprect_dirty = SDL_TRUE;
}
break;
}
case SDL_RENDERCMD_CLEAR:
{
const DWORD color = D3DCOLOR_ARGB(cmd->data.color.a, cmd->data.color.r, cmd->data.color.g, cmd->data.color.b);
const SDL_Rect *viewport = &data->drawstate.viewport;
const int backw = istarget ? renderer->target->w : data->pparams.BackBufferWidth;
const int backh = istarget ? renderer->target->h : data->pparams.BackBufferHeight;
const SDL_bool viewport_equal = ((viewport->x == 0) && (viewport->y == 0) && (viewport->w == backw) && (viewport->h == backh)) ? SDL_TRUE : SDL_FALSE;
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE);
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
}
case SDL_RENDERCMD_SETCLIPRECT: {
const SDL_Rect *rect = &cmd->data.cliprect.rect;
if (data->drawstate.cliprect_enabled != cmd->data.cliprect.enabled) {
data->drawstate.cliprect_enabled = cmd->data.cliprect.enabled;
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
}
if (SDL_memcmp(&data->drawstate.cliprect, rect, sizeof(*rect)) != 0) {
SDL_copyp(&data->drawstate.cliprect, rect);
data->drawstate.cliprect_dirty = SDL_TRUE;
}
break;
/* Don't reset the viewport if we don't have to! */
if (!data->drawstate.viewport_dirty && viewport_equal) {
IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
} else {
/* Clear is defined to clear the entire render target */
D3DVIEWPORT9 wholeviewport = { 0, 0, 0, 0, 0.0f, 1.0f };
wholeviewport.Width = backw;
wholeviewport.Height = backh;
IDirect3DDevice9_SetViewport(data->device, &wholeviewport);
data->drawstate.viewport_dirty = SDL_TRUE; /* we still need to (re)set orthographic projection, so always mark it dirty. */
IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
}
case SDL_RENDERCMD_CLEAR: {
const DWORD color = D3DCOLOR_ARGB(cmd->data.color.a, cmd->data.color.r, cmd->data.color.g, cmd->data.color.b);
const SDL_Rect *viewport = &data->drawstate.viewport;
const int backw = istarget ? renderer->target->w : data->pparams.BackBufferWidth;
const int backh = istarget ? renderer->target->h : data->pparams.BackBufferHeight;
const SDL_bool viewport_equal = ((viewport->x == 0) && (viewport->y == 0) && (viewport->w == backw) && (viewport->h == backh)) ? SDL_TRUE : SDL_FALSE;
break;
}
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE);
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
}
/* Don't reset the viewport if we don't have to! */
if (!data->drawstate.viewport_dirty && viewport_equal) {
IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
} else {
/* Clear is defined to clear the entire render target */
D3DVIEWPORT9 wholeviewport = { 0, 0, 0, 0, 0.0f, 1.0f };
wholeviewport.Width = backw;
wholeviewport.Height = backh;
IDirect3DDevice9_SetViewport(data->device, &wholeviewport);
data->drawstate.viewport_dirty = SDL_TRUE; /* we still need to (re)set orthographic projection, so always mark it dirty. */
IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
}
break;
case SDL_RENDERCMD_DRAW_POINTS:
{
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, (UINT)(first / sizeof(Vertex)), (UINT)count);
} else {
const Vertex *verts = (Vertex *)(((Uint8 *)vertices) + first);
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, (UINT)count, verts, sizeof(Vertex));
}
break;
}
case SDL_RENDERCMD_DRAW_POINTS: {
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, (UINT) (first / sizeof (Vertex)), (UINT) count);
} else {
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, (UINT) count, verts, sizeof (Vertex));
case SDL_RENDERCMD_DRAW_LINES:
{
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
const Vertex *verts = (Vertex *)(((Uint8 *)vertices) + first);
/* DirectX 9 has the same line rasterization semantics as GDI,
so we need to close the endpoint of the line with a second draw call. */
const SDL_bool close_endpoint = ((count == 2) || (verts[0].x != verts[count - 1].x) || (verts[0].y != verts[count - 1].y));
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_LINESTRIP, (UINT)(first / sizeof(Vertex)), (UINT)(count - 1));
if (close_endpoint) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, (UINT)((first / sizeof(Vertex)) + (count - 1)), 1);
}
break;
}
case SDL_RENDERCMD_DRAW_LINES: {
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
/* DirectX 9 has the same line rasterization semantics as GDI,
so we need to close the endpoint of the line with a second draw call. */
const SDL_bool close_endpoint = ((count == 2) || (verts[0].x != verts[count-1].x) || (verts[0].y != verts[count-1].y));
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_LINESTRIP, (UINT) (first / sizeof (Vertex)), (UINT) (count - 1));
if (close_endpoint) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_POINTLIST, (UINT) ((first / sizeof (Vertex)) + (count - 1)), 1);
}
} else {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, (UINT) (count - 1), verts, sizeof (Vertex));
if (close_endpoint) {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, &verts[count-1], sizeof (Vertex));
}
} else {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, (UINT)(count - 1), verts, sizeof(Vertex));
if (close_endpoint) {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, &verts[count - 1], sizeof(Vertex));
}
break;
}
break;
}
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
case SDL_RENDERCMD_COPY: /* unused */
break;
case SDL_RENDERCMD_COPY: /* unused */
break;
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
case SDL_RENDERCMD_GEOMETRY: {
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLELIST, (UINT) (first / sizeof (Vertex)), (UINT) count / 3);
} else {
const Vertex* verts = (Vertex*)(((Uint8*)vertices) + first);
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLELIST, (UINT) count / 3, verts, sizeof(Vertex));
}
break;
case SDL_RENDERCMD_GEOMETRY:
{
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
SetDrawState(data, cmd);
if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLELIST, (UINT)(first / sizeof(Vertex)), (UINT)count / 3);
} else {
const Vertex *verts = (Vertex *)(((Uint8 *)vertices) + first);
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLELIST, (UINT)count / 3, verts, sizeof(Vertex));
}
break;
}
case SDL_RENDERCMD_NO_OP:
break;
case SDL_RENDERCMD_NO_OP:
break;
}
cmd = cmd->next;
@ -1316,12 +1288,10 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
return 0;
}
static int
D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)
static int D3D_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
Uint32 format, void *pixels, int pitch)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3DSURFACE_DESC desc;
LPDIRECT3DSURFACE9 backBuffer;
LPDIRECT3DSURFACE9 surface;
@ -1364,8 +1334,8 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
}
status = SDL_ConvertPixels(rect->w, rect->h,
D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch,
format, pixels, pitch);
D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch,
format, pixels, pitch);
IDirect3DSurface9_UnlockRect(surface);
@ -1374,10 +1344,9 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
return status;
}
static int
D3D_RenderPresent(SDL_Renderer * renderer)
static int D3D_RenderPresent(SDL_Renderer *renderer)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
HRESULT result;
if (!data->beginScene) {
@ -1400,11 +1369,10 @@ D3D_RenderPresent(SDL_Renderer * renderer)
return 0;
}
static void
D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
static void D3D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
D3D_RenderData *renderdata = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *data = (D3D_TextureData *)texture->driverdata;
if (renderdata->drawstate.texture == texture) {
renderdata->drawstate.texture = NULL;
@ -1433,10 +1401,9 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
texture->driverdata = NULL;
}
static void
D3D_DestroyRenderer(SDL_Renderer * renderer)
static void D3D_DestroyRenderer(SDL_Renderer *renderer)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
if (data) {
int i;
@ -1478,10 +1445,9 @@ D3D_DestroyRenderer(SDL_Renderer * renderer)
SDL_free(renderer);
}
static int
D3D_Reset(SDL_Renderer * renderer)
static int D3D_Reset(SDL_Renderer *renderer)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
const Float4X4 d3dmatrix = MatrixIdentity();
HRESULT result;
SDL_Texture *texture;
@ -1547,7 +1513,7 @@ D3D_Reset(SDL_Renderer * renderer)
data->drawstate.texture = NULL;
data->drawstate.shader = NULL;
data->drawstate.blend = SDL_BLENDMODE_INVALID;
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX *)&d3dmatrix);
/* Let the application know that render targets were reset */
{
@ -1559,8 +1525,7 @@ D3D_Reset(SDL_Renderer * renderer)
return 0;
}
static int
D3D_SetVSync(SDL_Renderer * renderer, const int vsync)
static int D3D_SetVSync(SDL_Renderer *renderer, const int vsync)
{
D3D_RenderData *data = renderer->driverdata;
if (vsync) {
@ -1578,7 +1543,7 @@ D3D_SetVSync(SDL_Renderer * renderer, const int vsync)
}
SDL_Renderer *
D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
D3D_CreateRenderer(SDL_Window *window, Uint32 flags)
{
SDL_Renderer *renderer;
D3D_RenderData *data;
@ -1599,13 +1564,13 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
return NULL;
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(*renderer));
if (renderer == NULL) {
SDL_OutOfMemory();
return NULL;
}
data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data));
data = (D3D_RenderData *)SDL_calloc(1, sizeof(*data));
if (data == NULL) {
SDL_free(renderer);
SDL_OutOfMemory();
@ -1632,9 +1597,9 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->SetTextureScaleMode = D3D_SetTextureScaleMode;
renderer->SetRenderTarget = D3D_SetRenderTarget;
renderer->QueueSetViewport = D3D_QueueSetViewport;
renderer->QueueSetDrawColor = D3D_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueSetDrawColor = D3D_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
renderer->QueueDrawPoints = D3D_QueueDrawPoints;
renderer->QueueDrawLines = D3D_QueueDrawPoints; /* lines and points queue vertices the same way. */
renderer->QueueDrawLines = D3D_QueueDrawPoints; /* lines and points queue vertices the same way. */
renderer->QueueGeometry = D3D_QueueGeometry;
renderer->RunCommandQueue = D3D_RunCommandQueue;
renderer->RenderReadPixels = D3D_RenderReadPixels;
@ -1759,25 +1724,24 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
SDL_RenderDriver D3D_RenderDriver = {
D3D_CreateRenderer,
{
"direct3d",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
1,
{SDL_PIXELFORMAT_ARGB8888},
0,
0}
{ "direct3d",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
1,
{ SDL_PIXELFORMAT_ARGB8888 },
0,
0 }
};
#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
#if defined(__WIN32__) || defined(__WINGDK__)
/* This function needs to always exist on Windows, for the Dynamic API. */
IDirect3DDevice9 *
SDL_RenderGetD3D9Device(SDL_Renderer * renderer)
SDL_RenderGetD3D9Device(SDL_Renderer *renderer)
{
IDirect3DDevice9 *device = NULL;
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
/* Make sure that this is a D3D renderer */
if (renderer->DestroyRenderer != D3D_DestroyRenderer) {