mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-29 14:38:29 +00:00
Fixed updating NV12 and YV12 textures on the direct3d11 renderer
Fixes https://github.com/libsdl-org/SDL/issues/9928
This commit is contained in:
@@ -1626,7 +1626,11 @@ static int D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||||||
const Uint8 *Uplane = Yplane + rect->h * Ypitch;
|
const Uint8 *Uplane = Yplane + rect->h * Ypitch;
|
||||||
const Uint8 *Vplane = Uplane + ((rect->h + 1) / 2) * UVpitch;
|
const Uint8 *Vplane = Uplane + ((rect->h + 1) / 2) * UVpitch;
|
||||||
|
|
||||||
return D3D11_UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, UVpitch, Vplane, UVpitch);
|
if (texture->format == SDL_PIXELFORMAT_YV12) {
|
||||||
|
return D3D11_UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Vplane, UVpitch, Uplane, UVpitch);
|
||||||
|
} else {
|
||||||
|
return D3D11_UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, UVpitch, Vplane, UVpitch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1653,10 +1657,10 @@ static int D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||||||
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
|
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) {
|
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Uplane, Upitch) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) {
|
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Vplane, Vpitch) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1693,6 +1697,11 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||||||
stagingTextureDesc.MiscFlags = 0;
|
stagingTextureDesc.MiscFlags = 0;
|
||||||
stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
|
stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
if (stagingTextureDesc.Format == DXGI_FORMAT_NV12 ||
|
||||||
|
stagingTextureDesc.Format == DXGI_FORMAT_P010) {
|
||||||
|
stagingTextureDesc.Width = (stagingTextureDesc.Width + 1) & ~1;
|
||||||
|
stagingTextureDesc.Height = (stagingTextureDesc.Height + 1) & ~1;
|
||||||
|
}
|
||||||
result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
|
result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
|
||||||
&stagingTextureDesc,
|
&stagingTextureDesc,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -1714,11 +1723,10 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||||||
}
|
}
|
||||||
|
|
||||||
src = Yplane;
|
src = Yplane;
|
||||||
dst = textureMemory.pData;
|
dst = (Uint8 *)textureMemory.pData;
|
||||||
length = w;
|
length = w;
|
||||||
if (length == (UINT)Ypitch && length == textureMemory.RowPitch) {
|
if (length == (UINT)Ypitch && length == textureMemory.RowPitch) {
|
||||||
SDL_memcpy(dst, src, (size_t)length * rect->h);
|
SDL_memcpy(dst, src, (size_t)length * h);
|
||||||
dst += length * rect->h;
|
|
||||||
} else {
|
} else {
|
||||||
if (length > (UINT)Ypitch) {
|
if (length > (UINT)Ypitch) {
|
||||||
length = Ypitch;
|
length = Ypitch;
|
||||||
@@ -1733,26 +1741,21 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust dimensions for the UV plane */
|
|
||||||
w = ((w + 1) / 2) * 2;
|
|
||||||
h = ((h + 1) / 2);
|
|
||||||
|
|
||||||
src = UVplane;
|
src = UVplane;
|
||||||
length = w;
|
length = w;
|
||||||
if (length == (UINT)UVpitch && length == textureMemory.RowPitch) {
|
h = (h + 1) / 2;
|
||||||
SDL_memcpy(dst, src, (size_t)length * h);
|
if (stagingTextureDesc.Format == DXGI_FORMAT_P010) {
|
||||||
|
length = (length + 3) & ~3;
|
||||||
|
UVpitch = (UVpitch + 3) & ~3;
|
||||||
} else {
|
} else {
|
||||||
if (length > (UINT)UVpitch) {
|
length = (length + 1) & ~1;
|
||||||
length = UVpitch;
|
UVpitch = (UVpitch + 1) & ~1;
|
||||||
}
|
}
|
||||||
if (length > textureMemory.RowPitch) {
|
dst = (Uint8 *)textureMemory.pData + stagingTextureDesc.Height * textureMemory.RowPitch;
|
||||||
length = textureMemory.RowPitch;
|
for (row = 0; row < h; ++row) {
|
||||||
}
|
SDL_memcpy(dst, src, length);
|
||||||
for (row = 0; row < h; ++row) {
|
src += UVpitch;
|
||||||
SDL_memcpy(dst, src, length);
|
dst += textureMemory.RowPitch;
|
||||||
src += UVpitch;
|
|
||||||
dst += textureMemory.RowPitch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Commit the pixel buffer's changes back to the staging texture: */
|
/* Commit the pixel buffer's changes back to the staging texture: */
|
||||||
|
Reference in New Issue
Block a user