Add SDL_HAVE_RENDER_GEOMETRY to compile or not with RenderGeometry support

main
Sylvain 2021-04-06 21:32:02 +02:00 committed by Sylvain Becker
parent b9bd9da78f
commit 47db47c1cc
11 changed files with 60 additions and 4 deletions

View File

@ -116,6 +116,12 @@
#define SDL_HAVE_YUV !SDL_LEAN_AND_MEAN
#endif
/* SDL Renderer
- SDL_RenderGeometry() */
#ifndef SDL_HAVE_RENDER_GEOMETRY
#define SDL_HAVE_RENDER_GEOMETRY !SDL_LEAN_AND_MEAN
#endif
#include "SDL_assert.h"
#include "SDL_log.h"

View File

@ -572,6 +572,7 @@ QueueCmdCopyEx(SDL_Renderer *renderer, SDL_Texture * texture,
return retval;
}
#if SDL_HAVE_RENDER_GEOMETRY
static int
QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
const float *xy, int xy_stride,
@ -599,6 +600,7 @@ QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
}
return retval;
}
#endif
static int UpdateLogicalSize(SDL_Renderer *renderer);
@ -3359,6 +3361,7 @@ SDL_RenderGeometry(SDL_Renderer *renderer,
return SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indice);
}
#if SDL_HAVE_RENDER_GEOMETRY
static int
remap_one_indice(
int prev,
@ -3696,6 +3699,7 @@ end:
return retval;
}
#endif
int
SDL_RenderGeometryRaw(SDL_Renderer *renderer,
@ -3706,6 +3710,7 @@ SDL_RenderGeometryRaw(SDL_Renderer *renderer,
int num_vertices,
const void *indices, int num_indices, int size_indice)
{
#if SDL_HAVE_RENDER_GEOMETRY
int i;
int retval = 0;
int count = indices ? num_indices : num_vertices;
@ -3806,8 +3811,12 @@ SDL_RenderGeometryRaw(SDL_Renderer *renderer,
renderer->scale.x, renderer->scale.y);
return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
#else
return SDL_SetError("SDL not built with RenderGeometry support");
#endif
}
int
SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)

View File

@ -129,11 +129,12 @@ struct SDL_Renderer
int (*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);
#if SDL_HAVE_RENDER_GEOMETRY
int (*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,
int num_vertices, const void *indices, int num_indices, int size_indice,
float scale_x, float scale_y);
#endif
int (*RunCommandQueue) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,

View File

@ -1020,6 +1020,7 @@ D3D_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t
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,
@ -1071,6 +1072,7 @@ D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *t
}
return 0;
}
#endif
static int
UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
@ -1486,6 +1488,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
}
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);
@ -1495,6 +1498,7 @@ 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, verts, sizeof(Vertex));
}
#endif
break;
}
@ -1792,7 +1796,9 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
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;

View File

@ -1865,6 +1865,7 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
return 0;
}
#if SDL_HAVE_RENDER_GEOMETRY
static int
D3D11_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,
@ -1919,6 +1920,7 @@ D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
}
return 0;
}
#endif
static int
D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
@ -2402,6 +2404,7 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
}
case SDL_RENDERCMD_GEOMETRY: {
#if SDL_HAVE_RENDER_GEOMETRY
SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count;
const size_t first = cmd->data.draw.first;
@ -2414,6 +2417,7 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
}
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, start, count);
#endif
break;
}
@ -2632,7 +2636,9 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueFillRects = D3D11_QueueFillRects;
renderer->QueueCopy = D3D11_QueueCopy;
renderer->QueueCopyEx = D3D11_QueueCopyEx;
#if SDL_HAVE_RENDER_GEOMETRY
renderer->QueueGeometry = D3D11_QueueGeometry;
#endif
renderer->RunCommandQueue = D3D11_RunCommandQueue;
renderer->RenderReadPixels = D3D11_RenderReadPixels;
renderer->RenderPresent = D3D11_RenderPresent;

View File

@ -1318,6 +1318,7 @@ METAL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
return 0;
}
#if SDL_HAVE_RENDER_GEOMETRY
static int
METAL_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,
@ -1362,6 +1363,7 @@ METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
return 0;
}
#endif
typedef struct
{
@ -1622,6 +1624,7 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
}
case SDL_RENDERCMD_GEOMETRY: {
#if SDL_HAVE_RENDER_GEOMETRY
const size_t count = cmd->data.draw.count;
SDL_Texture *texture = cmd->data.draw.texture;
@ -1632,6 +1635,7 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache);
[data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:count];
}
#endif
break;
}
@ -1997,7 +2001,9 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueFillRects = METAL_QueueFillRects;
renderer->QueueCopy = METAL_QueueCopy;
renderer->QueueCopyEx = METAL_QueueCopyEx;
#if SDL_HAVE_RENDER_GEOMETRY
renderer->QueueGeometry = METAL_QueueGeometry;
#endif
renderer->RunCommandQueue = METAL_RunCommandQueue;
renderer->RenderReadPixels = METAL_RenderReadPixels;
renderer->RenderPresent = METAL_RenderPresent;

View File

@ -1051,6 +1051,7 @@ GL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * te
return 0;
}
#if SDL_HAVE_RENDER_GEOMETRY
static int
GL_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,
@ -1107,6 +1108,7 @@ GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
}
return 0;
}
#endif
static void
SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, const GL_Shader shader)
@ -1430,6 +1432,7 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
}
case SDL_RENDERCMD_GEOMETRY: {
#if SDL_HAVE_RENDER_GEOMETRY
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count;
@ -1467,6 +1470,7 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
data->glEnd();
data->glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]);
}
#endif
break;
}
@ -1752,7 +1756,9 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueFillRects = GL_QueueFillRects;
renderer->QueueCopy = GL_QueueCopy;
renderer->QueueCopyEx = GL_QueueCopyEx;
#if SDL_HAVE_RENDER_GEOMETRY
renderer->QueueGeometry = GL_QueueGeometry;
#endif
renderer->RunCommandQueue = GL_RunCommandQueue;
renderer->RenderReadPixels = GL_RenderReadPixels;
renderer->RenderPresent = GL_RenderPresent;

View File

@ -755,6 +755,7 @@ GLES_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
return 0;
}
#if SDL_HAVE_RENDER_GEOMETRY
static int
GLES_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,
@ -811,6 +812,7 @@ GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *
}
return 0;
}
#endif
static void
SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
@ -1046,6 +1048,7 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
}
case SDL_RENDERCMD_GEOMETRY: {
#if SDL_HAVE_RENDER_GEOMETRY
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count;
@ -1068,7 +1071,7 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
data->glDrawArrays(GL_TRIANGLES, 0, (GLsizei) count);
data->glDisableClientState(GL_COLOR_ARRAY);
#endif
break;
}
@ -1282,7 +1285,9 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->QueueFillRects = GLES_QueueFillRects;
renderer->QueueCopy = GLES_QueueCopy;
renderer->QueueCopyEx = GLES_QueueCopyEx;
#if SDL_HAVE_RENDER_GEOMETRY
renderer->QueueGeometry = GLES_QueueGeometry;
#endif
renderer->RunCommandQueue = GLES_RunCommandQueue;
renderer->RenderReadPixels = GLES_RenderReadPixels;
renderer->RenderPresent = GLES_RenderPresent;

View File

@ -937,6 +937,7 @@ GLES2_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
return 0;
}
#if SDL_HAVE_RENDER_GEOMETRY
static int
GLES2_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,
@ -996,6 +997,7 @@ GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
return 0;
}
#endif
static int
SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_ImageSource imgsrc)
@ -1373,6 +1375,7 @@ GLES2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
}
case SDL_RENDERCMD_GEOMETRY: {
#if SDL_HAVE_RENDER_GEOMETRY
SDL_Texture *texture = cmd->data.draw.texture;
const size_t count = cmd->data.draw.count;
int ret;
@ -1386,6 +1389,7 @@ GLES2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
if (ret == 0) {
data->glDrawArrays(GL_TRIANGLES, 0, (GLsizei) count);
}
#endif
break;
}
@ -2183,7 +2187,9 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer->QueueFillRects = GLES2_QueueFillRects;
renderer->QueueCopy = GLES2_QueueCopy;
renderer->QueueCopyEx = GLES2_QueueCopyEx;
#if SDL_HAVE_RENDER_GEOMETRY
renderer->QueueGeometry = GLES2_QueueGeometry;
#endif
renderer->RunCommandQueue = GLES2_RunCommandQueue;
renderer->RenderReadPixels = GLES2_RenderReadPixels;
renderer->RenderPresent = GLES2_RenderPresent;

View File

@ -562,6 +562,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
}
#if SDL_HAVE_RENDER_GEOMETRY
typedef struct GeometryFillData
{
SDL_Point dst;
@ -657,6 +658,7 @@ SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *te
}
return 0;
}
#endif
static void
PrepTextureForCopy(const SDL_RenderCommand *cmd)
@ -833,6 +835,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
}
case SDL_RENDERCMD_GEOMETRY: {
#if SDL_HAVE_RENDER_GEOMETRY
int i;
SDL_Rect *verts = (SDL_Rect *) (((Uint8 *) vertices) + cmd->data.draw.first);
const int count = (int) cmd->data.draw.count;
@ -861,7 +864,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
SDL_SW_FillTriangle(surface, &(ptr[0].dst), &(ptr[1].dst), &(ptr[2].dst), blend, ptr[0].color, ptr[1].color, ptr[2].color);
}
}
#endif
break;
}
@ -974,7 +977,9 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
renderer->QueueFillRects = SW_QueueFillRects;
renderer->QueueCopy = SW_QueueCopy;
renderer->QueueCopyEx = SW_QueueCopyEx;
#if SDL_HAVE_RENDER_GEOMETRY
renderer->QueueGeometry = SW_QueueGeometry;
#endif
renderer->RunCommandQueue = SW_RunCommandQueue;
renderer->RenderReadPixels = SW_RenderReadPixels;
renderer->RenderPresent = SW_RenderPresent;

View File

@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED && SDL_HAVE_RENDER_GEOMETRY
#include "SDL_surface.h"
#include "SDL_triangle.h"