Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TextureCollection.cs
Go to the documentation of this file.
1using System;
3
5
6public sealed class TextureCollection
7{
9
10 private int _textureOffset;
11
12 internal int _maxTextures;
13
14 public unsafe Texture this[int index]
15 {
16 get
17 {
18 IntPtr pComPtr = (IntPtr)_parent.pComPtr;
20 if (index >= 0 && index < _maxTextures)
21 {
22 IDirect3DBaseTexture9* ptr = null;
23 IDirect3DTexture9* ptr2 = null;
24 IDirect3DCubeTexture9* ptr3 = null;
25 IDirect3DVolumeTexture9* ptr4 = null;
26 try
27 {
28 IDirect3DDevice9* pComPtr2 = _parent.pComPtr;
29 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DBaseTexture9**, int>)(int)(*(uint*)(*(int*)pComPtr2 + 256)))((nint)pComPtr2, (uint)(_textureOffset + index), &ptr);
30 if (num < 0)
31 {
33 }
34 if (ptr == null)
35 {
36 return null;
37 }
38 int num2;
39 if (((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _GUID*, void**, int>)(int)(*(uint*)(int)(*(uint*)ptr)))((nint)ptr, (_GUID*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref _003CModule_003E.IID_IDirect3DTexture9), (void**)(&ptr2)) >= 0)
40 {
41 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC);
42 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr2 + 68)))((nint)ptr2, 0u, &d3DSURFACE_DESC);
43 if (num2 >= 0)
44 {
45 return Texture2D.GetManagedObject(ptr2, _parent, System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 12)));
46 }
47 }
48 else if (((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _GUID*, void**, int>)(int)(*(uint*)(int)(*(uint*)ptr)))((nint)ptr, (_GUID*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref _003CModule_003E.IID_IDirect3DCubeTexture9), (void**)(&ptr3)) >= 0)
49 {
50 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC2);
51 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr3 + 68)))((nint)ptr3, 0u, &d3DSURFACE_DESC2);
52 if (num2 >= 0)
53 {
54 return TextureCube.GetManagedObject(ptr3, _parent, System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC2, 12)));
55 }
56 }
57 else
58 {
59 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _GUID*, void**, int>)(int)(*(uint*)(int)(*(uint*)ptr)))((nint)ptr, (_GUID*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref _003CModule_003E.IID_IDirect3DVolumeTexture9), (void**)(&ptr4));
60 if (num2 >= 0)
61 {
62 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DVOLUME_DESC d3DVOLUME_DESC);
63 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DVOLUME_DESC*, int>)(int)(*(uint*)(*(int*)ptr4 + 68)))((nint)ptr4, 0u, &d3DVOLUME_DESC);
64 if (num2 >= 0)
65 {
66 return Texture3D.GetManagedObject(ptr4, _parent, System.Runtime.CompilerServices.Unsafe.As<_D3DVOLUME_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVOLUME_DESC, 12)));
67 }
68 }
69 }
71 }
72 finally
73 {
74 if (ptr != null)
75 {
76 IDirect3DBaseTexture9* intPtr = ptr;
77 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr + 8)))((nint)intPtr);
78 ptr = null;
79 }
80 }
81 }
82 throw new ArgumentOutOfRangeException("index");
83 }
84 set
85 {
86 IntPtr pComPtr = (IntPtr)_parent.pComPtr;
88 IDirect3DBaseTexture9* ptr = null;
89 if (value != null)
90 {
91 ptr = value.GetComPtr();
92 IntPtr pComPtr2 = (IntPtr)ptr;
93 Helpers.CheckDisposed(value, pComPtr2);
94 if (value.isActiveRenderTarget)
95 {
97 }
98 if (_textureOffset > 0 && ((byte*)value.pStateTracker)[16] == 0)
99 {
101 }
102 }
103 if (index >= 0 && index < _maxTextures)
104 {
105 int num = _textureOffset + index;
106 int num2 = ((num < 257) ? num : (num - 241));
107 uint num3 = (uint)(1 << num2);
108 EffectPass activePass = _parent.activePass;
109 if (activePass != null && (activePass._textureFlags & num3) != 0)
110 {
111 activePass.EndPass();
112 _parent.activePass = null;
113 }
114 IDirect3DDevice9* pComPtr3 = _parent.pComPtr;
115 int num4 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DBaseTexture9*, int>)(int)(*(uint*)(*(int*)pComPtr3 + 260)))((nint)pComPtr3, (uint)num, ptr);
116 if (num4 < 0)
117 {
118 if (value != null && value.GraphicsDevice != _parent)
119 {
121 }
122 throw GraphicsHelpers.GetExceptionFromResult((uint)num4);
123 }
125 uint num5 = ~num3;
126 if (value != null)
127 {
128 StateTrackerTexture* pStateTracker2 = value.pStateTracker;
129 *(int*)((byte*)pStateTracker + 136) = (*(int*)((byte*)pStateTracker2 + 20) << num2) | (*(int*)((byte*)pStateTracker + 136) & (int)num5);
130 *(int*)((byte*)pStateTracker + 140) = (*(int*)((byte*)pStateTracker2 + 24) << num2) | (*(int*)((byte*)pStateTracker + 140) & (int)num5);
131 }
132 else
133 {
134 *(int*)((byte*)pStateTracker + 136) &= (int)num5;
135 *(int*)((byte*)pStateTracker + 140) &= (int)num5;
136 }
137 return;
138 }
139 throw new ArgumentOutOfRangeException("index");
140 }
141 }
142
143 internal TextureCollection(GraphicsDevice parent, int textureOffset, int maxTextures)
144 {
145 _parent = parent;
146 _textureOffset = textureOffset;
147 _maxTextures = maxTextures;
148 base._002Ector();
149 }
150
151 internal unsafe void ResetState()
152 {
153 int num = 0;
154 if (0 >= _maxTextures)
155 {
156 return;
157 }
158 while (true)
159 {
160 IntPtr pComPtr = (IntPtr)_parent.pComPtr;
161 Helpers.CheckDisposed(_parent, pComPtr);
162 if (num < 0 || num >= _maxTextures)
163 {
164 break;
165 }
166 int num2 = _textureOffset + num;
167 int num3 = ((num2 < 257) ? num2 : (num2 - 241));
168 uint num4 = (uint)(1 << num3);
169 EffectPass activePass = _parent.activePass;
170 if (activePass != null && (activePass._textureFlags & num4) != 0)
171 {
172 activePass.EndPass();
173 _parent.activePass = null;
174 }
175 IDirect3DDevice9* pComPtr2 = _parent.pComPtr;
176 int num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DBaseTexture9*, int>)(int)(*(uint*)(*(int*)pComPtr2 + 260)))((nint)pComPtr2, (uint)num2, null);
177 if (num5 >= 0)
178 {
180 uint num6 = ~num4;
181 *(int*)((byte*)pStateTracker + 136) &= (int)num6;
182 *(int*)((byte*)pStateTracker + 140) &= (int)num6;
183 num++;
184 if (num >= _maxTextures)
185 {
186 return;
187 }
188 continue;
189 }
190 throw GraphicsHelpers.GetExceptionFromResult((uint)num5);
191 }
192 throw new ArgumentOutOfRangeException("index");
193 }
194}
static Exception GetExceptionFromResult(uint result)
static unsafe Texture2D GetManagedObject(IDirect3DTexture9 *pInterface, GraphicsDevice pDevice, uint pool)
Definition Texture2D.cs:902
static unsafe Texture3D GetManagedObject(IDirect3DVolumeTexture9 *pInterface, GraphicsDevice pDevice, uint pool)
Definition Texture3D.cs:617
TextureCollection(GraphicsDevice parent, int textureOffset, int maxTextures)
static unsafe TextureCube GetManagedObject(IDirect3DCubeTexture9 *pInterface, GraphicsDevice pDevice, uint pool)
static void CheckDisposed(object obj, IntPtr pComPtr)
Definition Helpers.cs:188