From 47db47c1ccceb37700d7a911321bf1fddd7934ee Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 6 Apr 2021 21:32:02 +0200 Subject: [PATCH] Add SDL_HAVE_RENDER_GEOMETRY to compile or not with RenderGeometry support --- src/SDL_internal.h | 6 ++++++ src/render/SDL_render.c | 9 +++++++++ src/render/SDL_sysrender.h | 3 ++- src/render/direct3d/SDL_render_d3d.c | 6 ++++++ src/render/direct3d11/SDL_render_d3d11.c | 6 ++++++ src/render/metal/SDL_render_metal.m | 6 ++++++ src/render/opengl/SDL_render_gl.c | 6 ++++++ src/render/opengles/SDL_render_gles.c | 7 ++++++- src/render/opengles2/SDL_render_gles2.c | 6 ++++++ src/render/software/SDL_render_sw.c | 7 ++++++- src/render/software/SDL_triangle.c | 2 +- 11 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/SDL_internal.h b/src/SDL_internal.h index 660c24740..6e52cd53a 100644 --- a/src/SDL_internal.h +++ b/src/SDL_internal.h @@ -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" diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 11995032c..5640e9467 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -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) diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index 5c2add1f3..dca54401a 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -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, diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index 3e4f8bd2b..27b661f8a 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -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; diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index 46a3ec1d6..dfa2d1296 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -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; diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index ace1f5e02..2e1dcad99 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -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; diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index ac090bbae..387dac782 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -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; diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c index d594447dc..1c42625dc 100644 --- a/src/render/opengles/SDL_render_gles.c +++ b/src/render/opengles/SDL_render_gles.c @@ -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; diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 3b8d5d39a..4e43a506a 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -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; diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 47242a495..bd09d5c33 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -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; diff --git a/src/render/software/SDL_triangle.c b/src/render/software/SDL_triangle.c index 03f4a52a7..8c9bc63cc 100644 --- a/src/render/software/SDL_triangle.c +++ b/src/render/software/SDL_triangle.c @@ -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"