@@ -1626,7 +1626,11 @@ static int D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
1626
1626
const Uint8 * Uplane = Yplane + rect -> h * Ypitch ;
1627
1627
const Uint8 * Vplane = Uplane + ((rect -> h + 1 ) / 2 ) * UVpitch ;
1628
1628
1629
- return D3D11_UpdateTextureYUV (renderer , texture , rect , Yplane , Ypitch , Uplane , UVpitch , Vplane , UVpitch );
1629
+ if (texture -> format == SDL_PIXELFORMAT_YV12 ) {
1630
+ return D3D11_UpdateTextureYUV (renderer , texture , rect , Yplane , Ypitch , Vplane , UVpitch , Uplane , UVpitch );
1631
+ } else {
1632
+ return D3D11_UpdateTextureYUV (renderer , texture , rect , Yplane , Ypitch , Uplane , UVpitch , Vplane , UVpitch );
1633
+ }
1630
1634
}
1631
1635
#endif
1632
1636
@@ -1653,10 +1657,10 @@ static int D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
1653
1657
if (D3D11_UpdateTextureInternal (rendererData , textureData -> mainTexture , SDL_BYTESPERPIXEL (texture -> format ), rect -> x , rect -> y , rect -> w , rect -> h , Yplane , Ypitch ) < 0 ) {
1654
1658
return -1 ;
1655
1659
}
1656
- 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 ) {
1660
+ 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 ) {
1657
1661
return -1 ;
1658
1662
}
1659
- 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 ) {
1663
+ 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 ) {
1660
1664
return -1 ;
1661
1665
}
1662
1666
return 0 ;
@@ -1693,6 +1697,11 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
1693
1697
stagingTextureDesc .MiscFlags = 0 ;
1694
1698
stagingTextureDesc .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE ;
1695
1699
stagingTextureDesc .Usage = D3D11_USAGE_STAGING ;
1700
+ if (stagingTextureDesc .Format == DXGI_FORMAT_NV12 ||
1701
+ stagingTextureDesc .Format == DXGI_FORMAT_P010 ) {
1702
+ stagingTextureDesc .Width = (stagingTextureDesc .Width + 1 ) & ~1 ;
1703
+ stagingTextureDesc .Height = (stagingTextureDesc .Height + 1 ) & ~1 ;
1704
+ }
1696
1705
result = ID3D11Device_CreateTexture2D (rendererData -> d3dDevice ,
1697
1706
& stagingTextureDesc ,
1698
1707
NULL ,
@@ -1714,11 +1723,10 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
1714
1723
}
1715
1724
1716
1725
src = Yplane ;
1717
- dst = textureMemory .pData ;
1726
+ dst = ( Uint8 * ) textureMemory .pData ;
1718
1727
length = w ;
1719
1728
if (length == (UINT )Ypitch && length == textureMemory .RowPitch ) {
1720
- SDL_memcpy (dst , src , (size_t )length * rect -> h );
1721
- dst += length * rect -> h ;
1729
+ SDL_memcpy (dst , src , (size_t )length * h );
1722
1730
} else {
1723
1731
if (length > (UINT )Ypitch ) {
1724
1732
length = Ypitch ;
@@ -1733,26 +1741,21 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
1733
1741
}
1734
1742
}
1735
1743
1736
- /* Adjust dimensions for the UV plane */
1737
- w = ((w + 1 ) / 2 ) * 2 ;
1738
- h = ((h + 1 ) / 2 );
1739
-
1740
1744
src = UVplane ;
1741
1745
length = w ;
1742
- if (length == (UINT )UVpitch && length == textureMemory .RowPitch ) {
1743
- SDL_memcpy (dst , src , (size_t )length * h );
1746
+ h = (h + 1 ) / 2 ;
1747
+ if (stagingTextureDesc .Format == DXGI_FORMAT_P010 ) {
1748
+ length = (length + 3 ) & ~3 ;
1749
+ UVpitch = (UVpitch + 3 ) & ~3 ;
1744
1750
} else {
1745
- if (length > (UINT )UVpitch ) {
1746
- length = UVpitch ;
1747
- }
1748
- if (length > textureMemory .RowPitch ) {
1749
- length = textureMemory .RowPitch ;
1750
- }
1751
- for (row = 0 ; row < h ; ++ row ) {
1752
- SDL_memcpy (dst , src , length );
1753
- src += UVpitch ;
1754
- dst += textureMemory .RowPitch ;
1755
- }
1751
+ length = (length + 1 ) & ~1 ;
1752
+ UVpitch = (UVpitch + 1 ) & ~1 ;
1753
+ }
1754
+ dst = (Uint8 * )textureMemory .pData + stagingTextureDesc .Height * textureMemory .RowPitch ;
1755
+ for (row = 0 ; row < h ; ++ row ) {
1756
+ SDL_memcpy (dst , src , length );
1757
+ src += UVpitch ;
1758
+ dst += textureMemory .RowPitch ;
1756
1759
}
1757
1760
1758
1761
/* Commit the pixel buffer's changes back to the staging texture: */
0 commit comments