Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RenderTargetHelper.cs
Go to the documentation of this file.
1using System;
4
6
8{
10
11 internal unsafe IDirect3DSurface9* pRenderTargetSurface;
12
13 internal unsafe IDirect3DSurface9* pDepthSurface;
14
15 internal int width;
16
17 internal int height;
18
20
22
23 internal int multiSampleCount;
24
26
27 internal bool isCubemap;
28
29 internal int pixelSize;
30
31 internal bool willItBlend;
32
34 {
35 pTexture = texture;
37 pDepthSurface = null;
38 this.width = width;
39 this.height = height;
40 this.format = format;
41 this.depthFormat = depthFormat;
42 this.multiSampleCount = multiSampleCount;
43 this.usage = usage;
44 base._002Ector();
45 isCubemap = texture is TextureCube;
46 pixelSize = Texture.GetExpectedByteSizeFromFormat(_003CModule_003E.ConvertXnaFormatToWindows(format));
47 int num = ((!profileCapabilities.InvalidBlendFormats.Contains(format)) ? 1 : 0);
48 willItBlend = (byte)num != 0;
49 }
50
52 {
54 }
55
57 {
59 }
60
61 internal unsafe void ReleaseNativeObject()
62 {
63 IDirect3DSurface9* ptr = pRenderTargetSurface;
64 if (ptr != null)
65 {
66 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr + 8)))((nint)ptr);
68 }
69 IDirect3DSurface9* ptr2 = pDepthSurface;
70 if (ptr2 != null)
71 {
72 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr2 + 8)))((nint)ptr2);
73 pDepthSurface = null;
74 }
75 }
76
77 internal unsafe void CreateSurfaces(GraphicsDevice graphicsDevice)
78 {
79 if (multiSampleCount != 0)
80 {
81 fixed (IDirect3DSurface9** ptr = &pRenderTargetSurface)
82 {
83 try
84 {
85 int num = *(int*)graphicsDevice.pComPtr + 112;
86 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, _D3DFORMAT, _D3DMULTISAMPLE_TYPE, uint, int, IDirect3DSurface9**, void**, int>)(int)(*(uint*)num))((nint)graphicsDevice.pComPtr, (uint)width, (uint)height, _003CModule_003E.ConvertXnaFormatToWindows(format), (_D3DMULTISAMPLE_TYPE)multiSampleCount, 0u, 0, ptr, null);
87 if (num2 < 0)
88 {
90 }
91 }
92 catch
93 {
94 //try-fault
95 ptr = null;
96 throw;
97 }
98 }
99 }
100 if (depthFormat != 0)
101 {
102 IntPtr intPtr = IntPtr.Zero;
103 if (usage == RenderTargetUsage.DiscardContents)
104 {
105 intPtr = graphicsDevice.Resources.FindResourceW(GetSharedDepthSurface);
106 }
107 if (intPtr != IntPtr.Zero)
108 {
109 pDepthSurface = (IDirect3DSurface9*)intPtr.ToPointer();
110 }
111 else
112 {
113 fixed (IDirect3DSurface9** ptr2 = &pDepthSurface)
114 {
115 try
116 {
117 int num3 = *(int*)graphicsDevice.pComPtr + 116;
118 int num4 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, _D3DFORMAT, _D3DMULTISAMPLE_TYPE, uint, int, IDirect3DSurface9**, void**, int>)(int)(*(uint*)num3))((nint)graphicsDevice.pComPtr, (uint)width, (uint)height, _003CModule_003E.ConvertXnaFormatToWindows(depthFormat), (_D3DMULTISAMPLE_TYPE)multiSampleCount, 0u, 0, ptr2, null);
119 if (num4 < 0)
120 {
121 throw GraphicsHelpers.GetExceptionFromResult((uint)num4);
122 }
123 }
124 catch
125 {
126 //try-fault
127 ptr2 = null;
128 throw;
129 }
130 }
131 }
132 }
133 try
134 {
135 return;
136 }
137 catch
138 {
139 //try-fault
140 throw;
141 }
142 }
143
144 internal unsafe IntPtr GetSharedDepthSurface(object managedObject)
145 {
146 RenderTargetHelper helper;
147 if (managedObject is RenderTarget2D renderTarget2D)
148 {
149 helper = renderTarget2D.helper;
150 }
151 else
152 {
153 if (!(managedObject is RenderTargetCube renderTargetCube))
154 {
155 return IntPtr.Zero;
156 }
157 helper = renderTargetCube.helper;
158 }
159 if (helper != null && helper.usage == RenderTargetUsage.DiscardContents && helper.width == width && helper.height == height && helper.depthFormat == depthFormat && helper.multiSampleCount == multiSampleCount)
160 {
161 IDirect3DSurface9* ptr = helper.pDepthSurface;
162 if (ptr != null)
163 {
164 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr + 4)))((nint)ptr);
165 return new IntPtr(ptr);
166 }
167 }
168 return IntPtr.Zero;
169 }
170
171 internal unsafe IDirect3DSurface9* GetRenderTargetSurface(CubeMapFace faceType)
172 {
173 IDirect3DSurface9* ptr = null;
174 IDirect3DSurface9* ptr2 = pRenderTargetSurface;
175 if (ptr2 != null)
176 {
177 ptr = ptr2;
178 IDirect3DSurface9* intPtr = ptr;
179 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr + 4)))((nint)intPtr);
180 }
181 else if (isCubemap)
182 {
183 IDirect3DCubeTexture9* pComPtr = ((TextureCube)pTexture).pComPtr;
184 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DCUBEMAP_FACES, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)pComPtr + 72)))((nint)pComPtr, (_D3DCUBEMAP_FACES)faceType, 0u, &ptr);
185 }
186 else
187 {
188 IDirect3DTexture9* pComPtr2 = ((Texture2D)pTexture).pComPtr;
189 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)pComPtr2 + 72)))((nint)pComPtr2, 0u, &ptr);
190 }
191 return ptr;
192 }
193
194 internal unsafe IDirect3DSurface9* GetDestinationSurface(CubeMapFace faceType, int mipLevel)
195 {
196 IDirect3DSurface9* result = null;
197 if (isCubemap)
198 {
199 IDirect3DCubeTexture9* pComPtr = ((TextureCube)pTexture).pComPtr;
200 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DCUBEMAP_FACES, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)pComPtr + 72)))((nint)pComPtr, (_D3DCUBEMAP_FACES)faceType, (uint)mipLevel, &result);
201 }
202 else
203 {
204 IDirect3DTexture9* pComPtr2 = ((Texture2D)pTexture).pComPtr;
205 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)pComPtr2 + 72)))((nint)pComPtr2, (uint)mipLevel, &result);
206 }
207 return result;
208 }
209
210 internal static RenderTargetHelper FromRenderTarget(Texture renderTarget)
211 {
212 if (renderTarget is RenderTarget2D renderTarget2D)
213 {
214 return renderTarget2D.helper;
215 }
216 if (renderTarget is RenderTargetCube renderTargetCube)
217 {
218 return renderTargetCube.helper;
219 }
220 return null;
221 }
222
223 [return: MarshalAs(UnmanagedType.U1)]
224 internal static bool IsSameSize(Texture renderTargetA, Texture renderTargetB)
225 {
226 RenderTargetHelper renderTargetHelper = ((!(renderTargetA is RenderTarget2D renderTarget2D)) ? ((!(renderTargetA is RenderTargetCube renderTargetCube)) ? null : renderTargetCube.helper) : renderTarget2D.helper);
227 RenderTargetHelper renderTargetHelper2 = ((!(renderTargetB is RenderTarget2D renderTarget2D2)) ? ((!(renderTargetB is RenderTargetCube renderTargetCube2)) ? null : renderTargetCube2.helper) : renderTarget2D2.helper);
228 int num = ((renderTargetHelper.width == renderTargetHelper2.width && renderTargetHelper.height == renderTargetHelper2.height && renderTargetHelper.multiSampleCount == renderTargetHelper2.multiSampleCount && renderTargetHelper.pixelSize == renderTargetHelper2.pixelSize) ? 1 : 0);
229 return (byte)num != 0;
230 }
231
232 [HandleProcessCorruptedStateExceptions]
233 protected virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
234 {
235 if (P_0)
236 {
238 return;
239 }
240 try
241 {
243 }
244 finally
245 {
246 base.Finalize();
247 }
248 }
249
250 public virtual sealed void Dispose()
251 {
252 Dispose(true);
253 GC.SuppressFinalize(this);
254 }
255
257 {
258 Dispose(false);
259 }
260}
IntPtr FindResourceW(Converter< object, IntPtr > selectionFilter)
static Exception GetExceptionFromResult(uint result)
unsafe RenderTargetHelper(IDynamicGraphicsResource texture, int width, int height, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage, ProfileCapabilities profileCapabilities)
virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
unsafe IDirect3DSurface9 * GetRenderTargetSurface(CubeMapFace faceType)
unsafe void CreateSurfaces(GraphicsDevice graphicsDevice)
static RenderTargetHelper FromRenderTarget(Texture renderTarget)
unsafe IntPtr GetSharedDepthSurface(object managedObject)
unsafe IDirect3DSurface9 * GetDestinationSurface(CubeMapFace faceType, int mipLevel)
static bool IsSameSize(Texture renderTargetA, Texture renderTargetB)
static byte GetExpectedByteSizeFromFormat(_D3DFORMAT format)
Definition Texture.cs:72
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static readonly IntPtr Zero
Definition IntPtr.cs:18
unsafe void * ToPointer()
Definition IntPtr.cs:210