Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SetRenderTargets() [2/2]

unsafe void Microsoft.Xna.Framework.Graphics.GraphicsDevice.SetRenderTargets ( RenderTargetBinding * pBindings,
int renderTargetCount )
inlineprivate

Definition at line 1824 of file GraphicsDevice.cs.

1825 {
1826 IntPtr intPtr = (IntPtr)pComPtr;
1827 Helpers.CheckDisposed(this, intPtr);
1828 if (renderTargetCount == currentRenderTargetCount)
1829 {
1830 int num = 0;
1831 if (0 >= renderTargetCount)
1832 {
1833 return;
1834 }
1835 RenderTargetBinding[] array = currentRenderTargetBindings;
1836 int num2 = System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>();
1837 RenderTargetBinding* ptr = pBindings;
1838 while (ptr->_renderTarget == array[num]._renderTarget && ptr->_cubeMapFace == array[num]._cubeMapFace)
1839 {
1840 num++;
1841 ptr = (RenderTargetBinding*)(num2 + (byte*)ptr);
1842 if (num >= renderTargetCount)
1843 {
1844 return;
1845 }
1846 }
1847 if (num >= renderTargetCount)
1848 {
1849 return;
1850 }
1851 }
1852 int maxRenderTargets = _profileCapabilities.MaxRenderTargets;
1853 if (renderTargetCount > maxRenderTargets)
1854 {
1855 _profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileMaxRenderTargets, maxRenderTargets);
1856 }
1857 int num3 = 0;
1858 if (0 < renderTargetCount)
1859 {
1860 do
1861 {
1862 Texture renderTarget = ((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num3 + (byte*)pBindings))->_renderTarget;
1863 if (renderTarget != null)
1864 {
1865 IntPtr intPtr2 = (IntPtr)renderTarget.GetComPtr();
1866 Helpers.CheckDisposed(renderTarget, intPtr2);
1867 if (renderTarget.GraphicsDevice == this)
1868 {
1869 if (num3 > 0)
1870 {
1871 int num4 = 0;
1872 if (0 < num3)
1873 {
1874 int num5 = System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>();
1875 RenderTargetBinding* ptr2 = pBindings;
1876 do
1877 {
1878 if (renderTarget != ptr2->_renderTarget)
1879 {
1880 num4++;
1881 ptr2 = (RenderTargetBinding*)(num5 + (byte*)ptr2);
1882 continue;
1883 }
1884 throw new ArgumentException(FrameworkResources.CannotSetAlreadyUsedRenderTarget);
1885 }
1886 while (num4 < num3);
1887 }
1888 if (!RenderTargetHelper.IsSameSize(renderTarget, pBindings->_renderTarget))
1889 {
1890 throw new ArgumentException(FrameworkResources.RenderTargetsMustMatch);
1891 }
1892 }
1893 num3++;
1894 continue;
1895 }
1896 throw new InvalidOperationException(FrameworkResources.InvalidDevice);
1897 }
1898 throw new ArgumentException(FrameworkResources.NullNotAllowed);
1899 }
1900 while (num3 < renderTargetCount);
1901 }
1902 if (currentRenderTargetCount <= 0)
1903 {
1905 }
1906 else
1907 {
1908 if (lazyClearFlags != 0)
1909 {
1911 }
1912 int num6 = 0;
1914 {
1915 do
1916 {
1917 ResolveRenderTarget(num6);
1918 num6++;
1919 }
1920 while (num6 < currentRenderTargetCount);
1921 }
1922 }
1923 int num7 = 0;
1924 willItBlend = true;
1925 currentViewport = default(Viewport);
1926 currentViewport.MaxDepth = 1f;
1927 if (renderTargetCount <= 0)
1928 {
1929 IDirect3DSurface9* ptr3 = null;
1930 IDirect3DDevice9* ptr4 = pComPtr;
1931 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, _D3DBACKBUFFER_TYPE, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr4 + 72)))((nint)ptr4, 0u, 0u, (_D3DBACKBUFFER_TYPE)0, &ptr3);
1932 IDirect3DDevice9* ptr5 = pComPtr;
1933 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr5 + 148)))((nint)ptr5, 0u, ptr3);
1934 if (ptr3 != null)
1935 {
1936 IDirect3DSurface9* intPtr3 = ptr3;
1937 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr3 + 8)))((nint)intPtr3);
1938 ptr3 = null;
1939 }
1940 if (num7 >= 0)
1941 {
1942 ptr5 = pComPtr;
1943 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr5 + 156)))((nint)ptr5, pImplicitDepthSurface);
1944 }
1945 if (pInternalCachedParams.RenderTargetUsage == RenderTargetUsage.DiscardContents)
1946 {
1947 lazyClearFlags = 7;
1948 }
1949 else
1950 {
1952 }
1953 currentViewport.Width = pInternalCachedParams.BackBufferWidth;
1954 currentViewport.Height = pInternalCachedParams.BackBufferHeight;
1955 }
1956 else
1957 {
1958 lazyClearFlags = 0;
1959 int num8 = 0;
1960 if (0 < renderTargetCount)
1961 {
1962 do
1963 {
1964 Texture renderTarget2 = ((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num8 + (byte*)pBindings))->_renderTarget;
1965 RenderTargetHelper renderTargetHelper = RenderTargetHelper.FromRenderTarget(renderTarget2);
1966 currentRenderTargets[num8] = renderTargetHelper;
1967 ref RenderTargetBinding reference = ref currentRenderTargetBindings[num8];
1968 reference = System.Runtime.CompilerServices.Unsafe.Read<RenderTargetBinding>(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num8 + (byte*)pBindings);
1969 renderTarget2.isActiveRenderTarget = true;
1970 if (!renderTargetHelper.willItBlend)
1971 {
1972 willItBlend = false;
1973 whyWontItBlend = renderTargetHelper.format;
1974 }
1975 if (num7 >= 0)
1976 {
1977 IDirect3DSurface9* renderTargetSurface = renderTargetHelper.GetRenderTargetSurface(((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num8 + (byte*)pBindings))->_cubeMapFace);
1978 IDirect3DDevice9* ptr6 = pComPtr;
1979 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr6 + 148)))((nint)ptr6, (uint)num8, renderTargetSurface);
1980 if (renderTargetSurface != null)
1981 {
1982 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)renderTargetSurface + 8)))((nint)renderTargetSurface);
1983 }
1984 if (num7 >= 0 && num8 == 0)
1985 {
1986 IDirect3DDevice9* ptr7 = pComPtr;
1987 num7 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr7 + 156)))((nint)ptr7, renderTargetHelper.pDepthSurface);
1988 }
1989 }
1990 if (renderTargetHelper.usage == RenderTargetUsage.DiscardContents)
1991 {
1992 int num9 = (lazyClearFlags |= 1);
1993 if (num8 == 0)
1994 {
1995 lazyClearFlags = num9 | 6;
1996 }
1997 }
1998 else if (renderTargetHelper.pRenderTargetSurface != null && (renderTargetHelper.isCubemap || renderTarget2.renderTargetContentsDirty) && num7 >= 0)
1999 {
2000 if (_insideScene)
2001 {
2002 IDirect3DDevice9* intPtr4 = pComPtr;
2003 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr4 + 168)))((nint)intPtr4);
2004 }
2005 IDirect3DSurface9* destinationSurface = renderTargetHelper.GetDestinationSurface(((RenderTargetBinding*)(System.Runtime.CompilerServices.Unsafe.SizeOf<RenderTargetBinding>() * num8 + (byte*)pBindings))->_cubeMapFace, 0);
2006 IDirect3DSurface9* pRenderTargetSurface = renderTargetHelper.pRenderTargetSurface;
2007 IDirect3DDevice9* ptr8 = pComPtr;
2008 int num10 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, IDirect3DSurface9*, tagRECT*, IDirect3DSurface9*, tagRECT*, _D3DTEXTUREFILTERTYPE, int>)(int)(*(uint*)(*(int*)ptr8 + 136)))((nint)ptr8, destinationSurface, null, pRenderTargetSurface, null, (_D3DTEXTUREFILTERTYPE)0);
2009 num7 = ((num10 < 0) ? _003CModule_003E.D3DXLoadSurfaceFromSurface(pRenderTargetSurface, null, null, destinationSurface, null, null, uint.MaxValue, 0u) : num10);
2010 if (destinationSurface != null)
2011 {
2012 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)destinationSurface + 8)))((nint)destinationSurface);
2013 }
2014 if (num7 >= 0)
2015 {
2016 renderTarget2.renderTargetContentsDirty = false;
2017 }
2018 if (_insideScene)
2019 {
2020 IDirect3DDevice9* intPtr5 = pComPtr;
2021 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr5 + 164)))((nint)intPtr5);
2022 }
2023 }
2024 num8++;
2025 }
2026 while (num8 < renderTargetCount);
2027 }
2028 currentViewport.Width = currentRenderTargets[0].width;
2029 currentViewport.Height = currentRenderTargets[0].height;
2030 }
2031 int num11 = renderTargetCount;
2032 if (renderTargetCount < currentRenderTargetCount)
2033 {
2034 do
2035 {
2036 currentRenderTargets[num11] = null;
2037 currentRenderTargetBindings[num11] = default(RenderTargetBinding);
2038 if (num11 > 0)
2039 {
2040 IDirect3DDevice9* ptr9 = pComPtr;
2041 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9*, int>)(int)(*(uint*)(*(int*)ptr9 + 148)))((nint)ptr9, (uint)num11, null);
2042 }
2043 num11++;
2044 }
2045 while (num11 < currentRenderTargetCount);
2046 }
2047 currentRenderTargetCount = renderTargetCount;
2049 if (num7 < 0)
2050 {
2051 throw GraphicsHelpers.GetExceptionFromResult((uint)num7);
2052 }
2053 }

References Microsoft.Xna.Framework.Graphics.GraphicsDevice._insideScene, Microsoft.Xna.Framework.Graphics.GraphicsDevice._profileCapabilities, System.array, Microsoft.Xna.Framework.Graphics.PresentationParameters.BackBufferHeight, Microsoft.Xna.Framework.Graphics.PresentationParameters.BackBufferWidth, Microsoft.Xna.Framework.FrameworkResources.CannotSetAlreadyUsedRenderTarget, Microsoft.Xna.Framework.Helpers.CheckDisposed(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.ClearDirtyBuffers(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.currentRenderTargetBindings, Microsoft.Xna.Framework.Graphics.GraphicsDevice.currentRenderTargetCount, Microsoft.Xna.Framework.Graphics.GraphicsDevice.currentRenderTargets, Microsoft.Xna.Framework.Graphics.GraphicsDevice.currentViewport, Microsoft.Xna.Framework.Graphics.GraphicsDevice.DefaultClearOptions, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.format, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.FromRenderTarget(), Microsoft.Xna.Framework.Graphics.Texture.GetComPtr(), Microsoft.Xna.Framework.Graphics.RenderTargetHelper.GetDestinationSurface(), Microsoft.Xna.Framework.Graphics.GraphicsHelpers.GetExceptionFromResult(), Microsoft.Xna.Framework.Graphics.RenderTargetHelper.GetRenderTargetSurface(), Microsoft.Xna.Framework.Graphics.GraphicsResource.GraphicsDevice, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.height, Microsoft.Xna.Framework.FrameworkResources.InvalidDevice, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.isCubemap, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.IsSameSize(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.lazyClearFlags, Microsoft.Xna.Framework.Graphics.ProfileCapabilities.MaxRenderTargets, Microsoft.Xna.Framework.FrameworkResources.NullNotAllowed, Microsoft.Xna.Framework.Graphics.GraphicsDevice.pComPtr, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.pDepthSurface, Microsoft.Xna.Framework.Graphics.GraphicsDevice.pImplicitDepthSurface, Microsoft.Xna.Framework.Graphics.GraphicsDevice.pInternalCachedParams, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.pRenderTargetSurface, Microsoft.Xna.Framework.FrameworkResources.ProfileMaxRenderTargets, Microsoft.Xna.Framework.Graphics.Texture.renderTargetContentsDirty, Microsoft.Xna.Framework.FrameworkResources.RenderTargetsMustMatch, Microsoft.Xna.Framework.Graphics.PresentationParameters.RenderTargetUsage, Microsoft.Xna.Framework.Graphics.GraphicsDevice.ResolveRenderTarget(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.savedBackBufferClearFlags, Microsoft.Xna.Framework.Graphics.ProfileCapabilities.ThrowNotSupportedException(), Microsoft.Xna.Framework.Graphics.RenderTargetHelper.usage, Microsoft.Xna.Framework.Graphics.GraphicsDevice.whyWontItBlend, Microsoft.Xna.Framework.Graphics.RenderTargetHelper.width, Microsoft.Xna.Framework.Graphics.GraphicsDevice.willItBlend, and Microsoft.Xna.Framework.Graphics.RenderTargetHelper.willItBlend.