Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
OcclusionQuery.cs
Go to the documentation of this file.
1using System;
5
7
9{
10 private int _pixelCount;
11
12 private bool _isAvailable;
13
14 private bool _isInBeginEndPair;
15
16 private bool _hasCalledBegin;
17
19
20 internal unsafe IDirect3DQuery9* pComPtr;
21
22 public int PixelCount
23 {
24 get
25 {
26 if (!IsComplete)
27 {
29 }
30 return _pixelCount;
31 }
32 }
33
34 public unsafe bool IsComplete
35 {
36 [return: MarshalAs(UnmanagedType.U1)]
37 get
38 {
40 IDirect3DQuery9* ptr = pComPtr;
41 if (ptr == null)
42 {
43 return false;
44 }
45 if (!_hasCalledBegin)
46 {
47 return false;
48 }
49 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint pixelCount);
50 byte b = ((((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, void*, uint, uint, int>)(int)(*(uint*)(*(int*)ptr + 28)))((nint)ptr, &pixelCount, 4u, 1u) == 0) ? ((byte)1) : ((byte)0));
51 _isAvailable = b != 0;
52 if (b != 0)
53 {
54 _pixelCount = (int)pixelCount;
55 }
56 return b != 0;
57 }
58 }
59
60 private unsafe OcclusionQuery(IDirect3DQuery9* pInterface, GraphicsDevice pDevice)
61 {
62 pComPtr = pInterface;
63 ((object)this)._002Ector();
64 try
65 {
66 _parent = pDevice;
67 return;
68 }
69 catch
70 {
71 //try-fault
72 base.Dispose(true);
73 throw;
74 }
75 }
76
77 public unsafe OcclusionQuery(GraphicsDevice graphicsDevice)
78 {
79 try
80 {
81 if (graphicsDevice == null)
82 {
84 }
85 if (!graphicsDevice._profileCapabilities.OcclusionQuery)
86 {
88 }
90 fixed (IDirect3DQuery9** ptr = &pComPtr)
91 {
92 int num = *(int*)graphicsDevice.pComPtr + 472;
93 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DQUERYTYPE, IDirect3DQuery9**, int>)(int)(*(uint*)num))((nint)graphicsDevice.pComPtr, (_D3DQUERYTYPE)9, ptr);
94 if (num2 < 0)
95 {
97 }
98 _parent = graphicsDevice;
100 return;
101 }
102 }
103 catch
104 {
105 //try-fault
106 base.Dispose(true);
107 throw;
108 }
109 }
110
111 public unsafe void Begin()
112 {
114 {
116 }
118 {
120 }
121 IDirect3DQuery9* ptr = pComPtr;
122 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, int>)(int)(*(uint*)(*(int*)ptr + 24)))((nint)ptr, 2u);
123 if (num < 0)
124 {
126 }
127 _isAvailable = false;
128 _isInBeginEndPair = true;
129 _hasCalledBegin = true;
131 }
132
133 public unsafe void End()
134 {
136 {
138 }
139 IDirect3DQuery9* ptr = pComPtr;
140 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, int>)(int)(*(uint*)(*(int*)ptr + 24)))((nint)ptr, 1u);
141 if (num < 0)
142 {
144 }
145 _isInBeginEndPair = false;
146 }
147
148 internal virtual int SaveDataForRecreation()
149 {
150 return 0;
151 }
152
154 {
155 //ILSpy generated this explicit interface implementation from .override directive in SaveDataForRecreation
156 return this.SaveDataForRecreation();
157 }
158
159 internal unsafe virtual int RecreateAndPopulateObject()
160 {
161 if (pComPtr != null)
162 {
163 return -2147467259;
164 }
165 fixed (IDirect3DQuery9** ptr = &pComPtr)
166 {
167 int num = *(int*)_parent.pComPtr + 472;
168 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DQUERYTYPE, IDirect3DQuery9**, int>)(int)(*(uint*)num))((nint)_parent.pComPtr, (_D3DQUERYTYPE)9, ptr);
169 if (num2 >= 0)
170 {
172 }
173 return num2;
174 }
175 }
176
178 {
179 //ILSpy generated this explicit interface implementation from .override directive in RecreateAndPopulateObject
180 return this.RecreateAndPopulateObject();
181 }
182
183 internal unsafe virtual void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
184 {
185 GraphicsDevice parent = _parent;
186 if (parent != null && pComPtr != null)
187 {
188 parent.Resources.ReleaseAllReferences(_internalHandle, disposeManagedResource);
189 }
190 _isAvailable = false;
191 pComPtr = null;
192 }
193
194 void IGraphicsResource.ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
195 {
196 //ILSpy generated this explicit interface implementation from .override directive in ReleaseNativeObject
197 this.ReleaseNativeObject(disposeManagedResource);
198 }
199
200 internal unsafe static OcclusionQuery GetManagedObject(IDirect3DQuery9* pInterface, GraphicsDevice pDevice, uint pool)
201 {
202 OcclusionQuery occlusionQuery = pDevice.Resources.GetCachedObject(pInterface) as OcclusionQuery;
203 if (occlusionQuery != null)
204 {
205 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)pInterface + 8)))((nint)pInterface);
206 occlusionQuery.isDisposed = false;
207 GC.ReRegisterForFinalize(occlusionQuery);
208 }
209 else
210 {
211 occlusionQuery = new OcclusionQuery(pInterface, pDevice);
212 pDevice.Resources.AddTrackedObject(occlusionQuery, pInterface, pool, 0uL, ref occlusionQuery._internalHandle);
213 }
214 return occlusionQuery;
215 }
216
217 private void OnObjectCreation()
218 {
219 }
220
221 private void _0021OcclusionQuery()
222 {
223 if (!isDisposed)
224 {
225 isDisposed = true;
226 ReleaseNativeObject(disposeManagedResource: true);
227 }
228 }
229
230 private void _007EOcclusionQuery()
231 {
232 if (!isDisposed)
233 {
234 isDisposed = true;
235 ReleaseNativeObject(disposeManagedResource: true);
236 }
237 }
238
239 [HandleProcessCorruptedStateExceptions]
240 protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
241 {
242 if (P_0)
243 {
244 try
245 {
247 return;
248 }
249 finally
250 {
251 base.Dispose(true);
252 }
253 }
254 try
255 {
257 }
258 finally
259 {
260 base.Dispose(false);
261 }
262 }
263}
unsafe void AddTrackedObject(object managedObject, void *pComPtr, uint resourceManagementMode, ulong handle, ref ulong updatedHandle)
unsafe void ReleaseAllReferences(ulong handle, [MarshalAs(UnmanagedType.U1)] bool dispose)
virtual void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
static Exception GetExceptionFromResult(uint result)
unsafe OcclusionQuery(IDirect3DQuery9 *pInterface, GraphicsDevice pDevice)
override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
static unsafe OcclusionQuery GetManagedObject(IDirect3DQuery9 *pInterface, GraphicsDevice pDevice, uint pool)
unsafe OcclusionQuery(GraphicsDevice graphicsDevice)
virtual unsafe void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
static void ReRegisterForFinalize(object obj)
Definition GC.cs:214
Definition GC.cs:8
void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)