diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index 3150195ce..596e0ace2 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -131,6 +131,7 @@ struct SDL_Renderer int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch); +#if SDL_HAVE_YUV int (*UpdateTextureYUV) (SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const Uint8 *Yplane, int Ypitch, @@ -140,6 +141,7 @@ struct SDL_Renderer const SDL_Rect * rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch); +#endif int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, void **pixels, int *pitch); void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture); diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index 8ca613501..ec8f13b89 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -1376,6 +1376,7 @@ D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, return 0; } +#if SDL_HAVE_YUV static int D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, @@ -1426,6 +1427,7 @@ D3D11_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture, } return 0; } +#endif static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, @@ -2539,8 +2541,10 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->SupportsBlendMode = D3D11_SupportsBlendMode; renderer->CreateTexture = D3D11_CreateTexture; renderer->UpdateTexture = D3D11_UpdateTexture; +#if SDL_HAVE_YUV renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV; renderer->UpdateTextureNV = D3D11_UpdateTextureNV; +#endif renderer->LockTexture = D3D11_LockTexture; renderer->UnlockTexture = D3D11_UnlockTexture; renderer->SetTextureScaleMode = D3D11_SetTextureScaleMode; diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index fcb828691..67ac1b663 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -803,6 +803,7 @@ METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, return 0; }} +#if SDL_HAVE_YUV static int METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, @@ -861,6 +862,7 @@ METAL_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture, return 0; }} +#endif static int METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, @@ -1877,8 +1879,10 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->SupportsBlendMode = METAL_SupportsBlendMode; renderer->CreateTexture = METAL_CreateTexture; renderer->UpdateTexture = METAL_UpdateTexture; +#if SDL_HAVE_YUV renderer->UpdateTextureYUV = METAL_UpdateTextureYUV; renderer->UpdateTextureNV = METAL_UpdateTextureNV; +#endif renderer->LockTexture = METAL_LockTexture; renderer->UnlockTexture = METAL_UnlockTexture; renderer->SetTextureScaleMode = METAL_SetTextureScaleMode; diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 722d30e76..eb9d7900d 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -128,11 +128,13 @@ typedef struct int pitch; SDL_Rect locked_rect; +#if SDL_HAVE_YUV /* YUV texture support */ SDL_bool yuv; SDL_bool nv12; GLuint utexture; GLuint vtexture; +#endif GL_FBOList *fbo; } GL_TextureData; @@ -577,6 +579,7 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) return -1; } +#if SDL_HAVE_YUV if (texture->format == SDL_PIXELFORMAT_YV12 || texture->format == SDL_PIXELFORMAT_IYUV) { data->yuv = SDL_TRUE; @@ -626,6 +629,7 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) renderdata->glTexImage2D(textype, 0, GL_LUMINANCE_ALPHA, (texture_w+1)/2, (texture_h+1)/2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); } +#endif return GL_CheckError("", renderer); } @@ -651,6 +655,7 @@ GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, renderdata->glTexSubImage2D(textype, 0, rect->x, rect->y, rect->w, rect->h, data->format, data->formattype, pixels); +#if SDL_HAVE_YUV if (data->yuv) { renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, ((pitch + 1) / 2)); @@ -687,10 +692,11 @@ GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, (rect->w + 1)/2, (rect->h + 1)/2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels); } - +#endif return GL_CheckError("glTexSubImage2D()", renderer); } +#if SDL_HAVE_YUV static int GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, @@ -758,7 +764,7 @@ GL_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture, return GL_CheckError("glTexSubImage2D()", renderer); } - +#endif static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, @@ -800,6 +806,7 @@ GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Scale renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode); renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode); +#if SDL_HAVE_YUV if (texture->format == SDL_PIXELFORMAT_YV12 || texture->format == SDL_PIXELFORMAT_IYUV) { renderdata->glBindTexture(textype, data->utexture); @@ -817,6 +824,7 @@ GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Scale renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode); renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode); } +#endif } static int @@ -1128,6 +1136,7 @@ SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) shader = SHADER_RGB; } +#if SDL_HAVE_YUV if (data->shaders) { if (texturedata->yuv || texturedata->nv12) { switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) { @@ -1164,11 +1173,13 @@ SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) } } } +#endif SetDrawState(data, cmd, shader); if (texture != data->drawstate.texture) { const GLenum textype = data->textype; +#if SDL_HAVE_YUV if (texturedata->yuv) { data->glActiveTextureARB(GL_TEXTURE2_ARB); data->glBindTexture(textype, texturedata->vtexture); @@ -1180,6 +1191,7 @@ SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) data->glActiveTextureARB(GL_TEXTURE1_ARB); data->glBindTexture(textype, texturedata->utexture); } +#endif data->glActiveTextureARB(GL_TEXTURE0_ARB); data->glBindTexture(textype, texturedata->texture); @@ -1471,10 +1483,12 @@ GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) if (data->texture) { renderdata->glDeleteTextures(1, &data->texture); } +#if SDL_HAVE_YUV if (data->yuv) { renderdata->glDeleteTextures(1, &data->utexture); renderdata->glDeleteTextures(1, &data->vtexture); } +#endif SDL_free(data->pixels); SDL_free(data); texture->driverdata = NULL; @@ -1528,6 +1542,7 @@ GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, floa GL_ActivateRenderer(renderer); data->glEnable(textype); +#if SDL_HAVE_YUV if (texturedata->yuv) { data->glActiveTextureARB(GL_TEXTURE2_ARB); data->glBindTexture(textype, texturedata->vtexture); @@ -1537,6 +1552,7 @@ GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, floa data->glActiveTextureARB(GL_TEXTURE0_ARB); } +#endif data->glBindTexture(textype, texturedata->texture); data->drawstate.texturing = SDL_TRUE; @@ -1557,6 +1573,7 @@ GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) GL_ActivateRenderer(renderer); +#if SDL_HAVE_YUV if (texturedata->yuv) { data->glActiveTextureARB(GL_TEXTURE2_ARB); data->glDisable(textype); @@ -1566,6 +1583,7 @@ GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture) data->glActiveTextureARB(GL_TEXTURE0_ARB); } +#endif data->glDisable(textype); @@ -1621,8 +1639,10 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->SupportsBlendMode = GL_SupportsBlendMode; renderer->CreateTexture = GL_CreateTexture; renderer->UpdateTexture = GL_UpdateTexture; +#if SDL_HAVE_YUV renderer->UpdateTextureYUV = GL_UpdateTextureYUV; renderer->UpdateTextureNV = GL_UpdateTextureNV; +#endif renderer->LockTexture = GL_LockTexture; renderer->UnlockTexture = GL_UnlockTexture; renderer->SetTextureScaleMode = GL_SetTextureScaleMode; diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index bf6bf93ac..ce9bf2693 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -58,11 +58,13 @@ typedef struct GLES2_TextureData GLenum pixel_type; void *pixel_data; int pitch; +#if SDL_HAVE_YUV /* YUV texture support */ SDL_bool yuv; SDL_bool nv12; GLenum texture_v; GLenum texture_u; +#endif GLES2_FBOList *fbo; } GLES2_TextureData; @@ -1037,6 +1039,7 @@ SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_I if (texture) { GLES2_TextureData *tdata = (GLES2_TextureData *) texture->driverdata; +#if SDL_HAVE_YUV if (tdata->yuv) { data->glActiveTexture(GL_TEXTURE2); data->glBindTexture(tdata->texture_type, tdata->texture_v); @@ -1051,6 +1054,7 @@ SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_I data->glActiveTexture(GL_TEXTURE0); } +#endif data->glBindTexture(tdata->texture_type, tdata->texture); } @@ -1483,10 +1487,12 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) #endif data->pixel_format = format; data->pixel_type = type; +#if SDL_HAVE_YUV data->yuv = ((texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12)); data->nv12 = ((texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21)); data->texture_u = 0; data->texture_v = 0; +#endif scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR; /* Allocate a blob for image renderdata */ @@ -1494,6 +1500,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) size_t size; data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); size = texture->h * data->pitch; +#if SDL_HAVE_YUV if (data->yuv) { /* Need to add size for the U and V planes */ size += 2 * ((texture->h + 1) / 2) * ((data->pitch + 1) / 2); @@ -1501,6 +1508,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) /* Need to add size for the U/V plane */ size += 2 * ((texture->h + 1) / 2) * ((data->pitch + 1) / 2); } +#endif data->pixel_data = SDL_calloc(1, size); if (!data->pixel_data) { SDL_free(data); @@ -1511,6 +1519,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) /* Allocate the texture */ GL_CheckError("", renderer); +#if SDL_HAVE_YUV if (data->yuv) { renderdata->glGenTextures(1, &data->texture_v); if (GL_CheckError("glGenTexures()", renderer) < 0) { @@ -1554,6 +1563,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) return -1; } } +#endif renderdata->glGenTextures(1, &data->texture); if (GL_CheckError("glGenTexures()", renderer) < 0) { @@ -1646,6 +1656,7 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect tdata->pixel_type, pixels, pitch, SDL_BYTESPERPIXEL(texture->format)); +#if SDL_HAVE_YUV if (tdata->yuv) { /* Skip to the correct offset into the next texture */ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch); @@ -1692,10 +1703,12 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect GL_UNSIGNED_BYTE, pixels, 2 * ((pitch + 1) / 2), 2); } +#endif return GL_CheckError("glTexSubImage2D()", renderer); } +#if SDL_HAVE_YUV static int GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, @@ -1788,7 +1801,7 @@ GLES2_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture, return GL_CheckError("glTexSubImage2D()", renderer); } - +#endif static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, @@ -1826,6 +1839,7 @@ GLES2_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Sc GLES2_TextureData *data = (GLES2_TextureData *) texture->driverdata; GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR; +#if SDL_HAVE_YUV if (data->yuv) { renderdata->glActiveTexture(GL_TEXTURE2); renderdata->glBindTexture(data->texture_type, data->texture_v); @@ -1842,6 +1856,7 @@ GLES2_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Sc renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, glScaleMode); renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, glScaleMode); } +#endif renderdata->glActiveTexture(GL_TEXTURE0); renderdata->glBindTexture(data->texture_type, data->texture); @@ -1892,12 +1907,14 @@ GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) /* Destroy the texture */ if (tdata) { data->glDeleteTextures(1, &tdata->texture); +#if SDL_HAVE_YUV if (tdata->texture_v) { data->glDeleteTextures(1, &tdata->texture_v); } if (tdata->texture_u) { data->glDeleteTextures(1, &tdata->texture_u); } +#endif SDL_free(tdata->pixel_data); SDL_free(tdata); texture->driverdata = NULL; @@ -2167,8 +2184,10 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags) renderer->SupportsBlendMode = GLES2_SupportsBlendMode; renderer->CreateTexture = GLES2_CreateTexture; renderer->UpdateTexture = GLES2_UpdateTexture; +#if SDL_HAVE_YUV renderer->UpdateTextureYUV = GLES2_UpdateTextureYUV; renderer->UpdateTextureNV = GLES2_UpdateTextureNV; +#endif renderer->LockTexture = GLES2_LockTexture; renderer->UnlockTexture = GLES2_UnlockTexture; renderer->SetTextureScaleMode = GLES2_SetTextureScaleMode;