Skip to content

Commit

Permalink
Direct3D: remove RenderCopy and RenderCopyEx from back-end
Browse files Browse the repository at this point in the history
  • Loading branch information
1bsyl committed Sep 20, 2021
1 parent fe6af68 commit 0c11765
Showing 1 changed file with 2 additions and 196 deletions.
198 changes: 2 additions & 196 deletions src/render/direct3d/SDL_render_d3d.c
Expand Up @@ -51,7 +51,6 @@ typedef struct
SDL_bool cliprect_enabled_dirty;
SDL_Rect cliprect;
SDL_bool cliprect_dirty;
SDL_bool is_copy_ex;
LPDIRECT3DPIXELSHADER9 shader;
} D3D_DrawStateCache;

Expand Down Expand Up @@ -878,149 +877,6 @@ D3D_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FR
return 0;
}

static int
D3D_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
{
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
float minx, miny, maxx, maxy;
float minu, maxu, minv, maxv;
const size_t vertslen = sizeof (Vertex) * 4;
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);

if (!verts) {
return -1;
}

cmd->data.draw.count = 1;

minx = dstrect->x - 0.5f;
miny = dstrect->y - 0.5f;
maxx = dstrect->x + dstrect->w - 0.5f;
maxy = dstrect->y + dstrect->h - 0.5f;

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;

verts->x = minx;
verts->y = miny;
verts->z = 0.0f;
verts->color = color;
verts->u = minu;
verts->v = minv;
verts++;

verts->x = maxx;
verts->y = miny;
verts->z = 0.0f;
verts->color = color;
verts->u = maxu;
verts->v = minv;
verts++;

verts->x = maxx;
verts->y = maxy;
verts->z = 0.0f;
verts->color = color;
verts->u = maxu;
verts->v = maxv;
verts++;

verts->x = minx;
verts->y = maxy;
verts->z = 0.0f;
verts->color = color;
verts->u = minu;
verts->v = maxv;
verts++;

return 0;
}

static int
D3D_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
const SDL_Rect * srcquad, const SDL_FRect * dstrect,
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
{
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
float minx, miny, maxx, maxy;
float minu, maxu, minv, maxv;
const size_t vertslen = sizeof (Vertex) * 5;
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);

if (!verts) {
return -1;
}

cmd->data.draw.count = 1;

minx = -center->x;
maxx = dstrect->w - center->x;
miny = -center->y;
maxy = dstrect->h - center->y;

if (flip & SDL_FLIP_HORIZONTAL) {
minu = (float) (srcquad->x + srcquad->w) / texture->w;
maxu = (float) srcquad->x / texture->w;
} else {
minu = (float) srcquad->x / texture->w;
maxu = (float) (srcquad->x + srcquad->w) / texture->w;
}

if (flip & SDL_FLIP_VERTICAL) {
minv = (float) (srcquad->y + srcquad->h) / texture->h;
maxv = (float) srcquad->y / texture->h;
} else {
minv = (float) srcquad->y / texture->h;
maxv = (float) (srcquad->y + srcquad->h) / texture->h;
}

verts->x = minx;
verts->y = miny;
verts->z = 0.0f;
verts->color = color;
verts->u = minu;
verts->v = minv;
verts++;

verts->x = maxx;
verts->y = miny;
verts->z = 0.0f;
verts->color = color;
verts->u = maxu;
verts->v = minv;
verts++;

verts->x = maxx;
verts->y = maxy;
verts->z = 0.0f;
verts->color = color;
verts->u = maxu;
verts->v = maxv;
verts++;

verts->x = minx;
verts->y = maxy;
verts->z = 0.0f;
verts->color = color;
verts->u = minu;
verts->v = maxv;
verts++;

verts->x = dstrect->x + center->x - 0.5f; /* X translation */
verts->y = dstrect->y + center->y - 0.5f; /* Y translation */
verts->z = (float)(M_PI * (float) angle / 180.0f); /* rotation */
verts->color = 0;
verts->u = 0.0f;
verts->v = 0.0f;
verts++;

return 0;
}

#if SDL_HAVE_RENDER_GEOMETRY
static int
D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const int *color, int color_stride, const float *uv, int uv_stride,
Expand Down Expand Up @@ -1073,7 +929,6 @@ D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t
}
return 0;
}
#endif

static int
UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
Expand Down Expand Up @@ -1174,8 +1029,6 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
static int
SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
{
const SDL_bool was_copy_ex = data->drawstate.is_copy_ex;
const SDL_bool is_copy_ex = (cmd->command == SDL_RENDERCMD_COPY_EX);
SDL_Texture *texture = cmd->data.draw.texture;
const SDL_BlendMode blend = cmd->data.draw.blend;

Expand Down Expand Up @@ -1234,14 +1087,6 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
data->drawstate.blend = blend;
}

if (is_copy_ex != was_copy_ex) {
if (!is_copy_ex) { /* SDL_RENDERCMD_COPY_EX will set this, we only want to reset it here if necessary. */
const Float4X4 d3dmatrix = MatrixIdentity();
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*) &d3dmatrix);
}
data->drawstate.is_copy_ex = is_copy_ex;
}

if (data->drawstate.viewport_dirty) {
const SDL_Rect *viewport = &data->drawstate.viewport;
const D3DVIEWPORT9 d3dviewport = { viewport->x, viewport->y, viewport->w, viewport->h, 0.0f, 1.0f };
Expand Down Expand Up @@ -1450,46 +1295,13 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
break;
}

case SDL_RENDERCMD_COPY: {
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
SetDrawState(data, cmd);
if (vbo) {
size_t offset = 0;
for (i = 0; i < count; ++i, offset += 4) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) ((first / sizeof (Vertex)) + offset), 2);
}
} else {
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
for (i = 0; i < count; ++i, verts += 4) {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
}
}
case SDL_RENDERCMD_COPY: /* unused */
break;
}

case SDL_RENDERCMD_COPY_EX: {
const size_t first = cmd->data.draw.first;
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
const Vertex *transvert = verts + 4;
const float translatex = transvert->x;
const float translatey = transvert->y;
const float rotation = transvert->z;
const Float4X4 d3dmatrix = MatrixMultiply(MatrixRotationZ(rotation), MatrixTranslation(translatex, translatey, 0));
SetDrawState(data, cmd);

IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);

if (vbo) {
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) (first / sizeof (Vertex)), 2);
} else {
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
}
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
}

case SDL_RENDERCMD_GEOMETRY: {
#if SDL_HAVE_RENDER_GEOMETRY
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
SetDrawState(data, cmd);
Expand All @@ -1499,7 +1311,6 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
const Vertex* verts = (Vertex*)(((Uint8*)vertices) + first);
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLELIST, (UINT) count / 3, verts, sizeof(Vertex));
}
#endif
break;
}

Expand Down Expand Up @@ -1730,7 +1541,6 @@ D3D_Reset(SDL_Renderer * renderer)
data->drawstate.texture = NULL;
data->drawstate.shader = NULL;
data->drawstate.blend = SDL_BLENDMODE_INVALID;
data->drawstate.is_copy_ex = SDL_FALSE;
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);

/* Let the application know that render targets were reset */
Expand Down Expand Up @@ -1813,11 +1623,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueDrawPoints = D3D_QueueDrawPoints;
renderer->QueueDrawLines = D3D_QueueDrawPoints; /* lines and points queue vertices the same way. */
renderer->QueueFillRects = D3D_QueueFillRects;
renderer->QueueCopy = D3D_QueueCopy;
renderer->QueueCopyEx = D3D_QueueCopyEx;
#if SDL_HAVE_RENDER_GEOMETRY
renderer->QueueGeometry = D3D_QueueGeometry;
#endif
renderer->RunCommandQueue = D3D_RunCommandQueue;
renderer->RenderReadPixels = D3D_RenderReadPixels;
renderer->RenderPresent = D3D_RenderPresent;
Expand Down

0 comments on commit 0c11765

Please sign in to comment.