2 * Copyright (c) 2007-2010 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 #include "../DataBox.h"
\r
25 #include "../DataRectangle.h"
\r
27 #include "BaseTexture.h"
\r
28 #include "Surface.h"
\r
30 #include "Effect9.h"
\r
31 #include "ConstantTable.h"
\r
32 #include "TextureShader.h"
\r
33 #include "Delegates.h"
\r
35 #include "ImageInformation.h"
\r
36 #include "CubeTextureRequirements.h"
\r
43 /// Represents a cubic texture resource.
\r
45 /// <unmanaged>IDirect3DCubeTexture9</unmanaged>
\r
46 public ref class CubeTexture : public BaseTexture
\r
48 COMOBJECT(IDirect3DCubeTexture9, CubeTexture);
\r
51 static CubeTexture^ FromMemory_Internal( SlimDX::Direct3D9::Device^ device, const void* memory, UINT sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, ImageInformation* imageInformation, PaletteEntry* palette );
\r
55 /// Initializes a new instance of the <see cref="CubeTexture"/> class.
\r
57 /// <param name="device">The device used to create the texture.</param>
\r
58 /// <param name="edgeLength">The length of each edge of the texture, in pixels.</param>
\r
59 /// <param name="levelCount">Number of mipmap levels in the texture. If set to 0, mipmaps will automatically be generated.</param>
\r
60 /// <param name="usage">The requested usage for the texture.</param>
\r
61 /// <param name="format">The surface format of the texture.</param>
\r
62 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
63 CubeTexture( SlimDX::Direct3D9::Device^ device, int edgeLength, int levelCount, Usage usage, Format format, Pool pool );
\r
66 /// Initializes a new instance of the <see cref="CubeTexture"/> class.
\r
68 /// <param name="device">The device used to create the texture.</param>
\r
69 /// <param name="edgeLength">The length of each edge of the texture, in pixels.</param>
\r
70 /// <param name="levelCount">Number of mipmap levels in the texture. If set to 0, mipmaps will automatically be generated.</param>
\r
71 /// <param name="usage">The requested usage for the texture.</param>
\r
72 /// <param name="format">The surface format of the texture.</param>
\r
73 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
74 /// <param name="sharedHandle">The variable that will receive the shared handle for this resource.</param>
\r
75 /// <remarks>This method is only available in Direct3D9 Ex.</remarks>
\r
76 CubeTexture( SlimDX::Direct3D9::Device^ device, int edgeLength, int levelCount, Usage usage, Format format, Pool pool, [Out] System::IntPtr% sharedHandle );
\r
79 /// Releases all resources used by the <see cref="CubeTexture"/>.
\r
81 virtual ~CubeTexture() { }
\r
84 /// Checks texture-creation parameters.
\r
86 /// <param name="device">Device associated with the texture.</param>
\r
87 /// <param name="size">Requested size of the texture.</param>
\r
88 /// <param name="mipLevelCount">Requested number of mipmap levels for the texture.</param>
\r
89 /// <param name="usage">The requested usage for the texture.</param>
\r
90 /// <param name="format">Requested format for the texture.</param>
\r
91 /// <param name="pool">Memory class where the resource will be placed.</param>
\r
92 /// <returns>A value type containing the proposed values to pass to the texture creation functions.</returns>
\r
93 static CubeTextureRequirements CheckRequirements( SlimDX::Direct3D9::Device^ device, int size, int mipLevelCount, Usage usage, Format format, Pool pool );
\r
96 /// Creates a texture from a specified block of memory.
\r
98 /// <param name="device">The device to be associated with the texture.</param>
\r
99 /// <param name="memory">The memory block representing the texture.</param>
\r
100 /// <param name="size">Size of the texture, in pixels.</param>
\r
101 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
102 /// <param name="usage">The requested usage for the texture.</param>
\r
103 /// <param name="format">The surface format of the texture.</param>
\r
104 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
105 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
106 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
107 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
108 /// <param name="imageInformation">When the method completes, contains additional information about the texture.</param>
\r
109 /// <param name="palette">When the method completes, contains the texture palette.</param>
\r
110 /// <returns>The created texture object.</returns>
\r
111 static CubeTexture^ FromMemory( SlimDX::Direct3D9::Device^ device, array<System::Byte>^ memory, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, [Out] ImageInformation% imageInformation, [Out] array<PaletteEntry>^% palette );
\r
114 /// Creates a texture from a specified block of memory.
\r
116 /// <param name="device">The device to be associated with the texture.</param>
\r
117 /// <param name="memory">The memory block representing the texture.</param>
\r
118 /// <param name="size">Size of the texture, in pixels.</param>
\r
119 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
120 /// <param name="usage">The requested usage for the texture.</param>
\r
121 /// <param name="format">The surface format of the texture.</param>
\r
122 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
123 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
124 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
125 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
126 /// <param name="imageInformation">When the method completes, contains additional information about the texture.</param>
\r
127 /// <returns>The created texture object.</returns>
\r
128 static CubeTexture^ FromMemory( SlimDX::Direct3D9::Device^ device, array<System::Byte>^ memory, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, [Out] ImageInformation% imageInformation );
\r
131 /// Creates a texture from a specified block of memory.
\r
133 /// <param name="device">The device to be associated with the texture.</param>
\r
134 /// <param name="memory">The memory block representing the texture.</param>
\r
135 /// <param name="size">Size of the texture, in pixels.</param>
\r
136 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
137 /// <param name="usage">The requested usage for the texture.</param>
\r
138 /// <param name="format">The surface format of the texture.</param>
\r
139 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
140 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
141 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
142 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
143 /// <returns>The created texture object.</returns>
\r
144 static CubeTexture^ FromMemory( SlimDX::Direct3D9::Device^ device, array<System::Byte>^ memory, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey );
\r
147 /// Creates a texture from a specified block of memory.
\r
149 /// <param name="device">The device to be associated with the texture.</param>
\r
150 /// <param name="memory">The memory block representing the texture.</param>
\r
151 /// <param name="usage">The requested usage for the texture.</param>
\r
152 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
153 /// <returns>The created texture object.</returns>
\r
154 static CubeTexture^ FromMemory( SlimDX::Direct3D9::Device^ device, array<System::Byte>^ memory, Usage usage, Pool pool );
\r
157 /// Creates a texture from a specified block of memory.
\r
159 /// <param name="device">The device to be associated with the texture.</param>
\r
160 /// <param name="memory">The memory block representing the texture.</param>
\r
161 /// <returns>The created texture object.</returns>
\r
162 static CubeTexture^ FromMemory( SlimDX::Direct3D9::Device^ device, array<System::Byte>^ memory );
\r
165 /// Creates a texture from a stream.
\r
167 /// <param name="device">The device to be associated with the texture.</param>
\r
168 /// <param name="stream">The stream containing the texture data.</param>
\r
169 /// <param name="sizeBytes">The size of the data, in bytes.</param>
\r
170 /// <param name="size">Size of the texture, in pixels.</param>
\r
171 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
172 /// <param name="usage">The requested usage for the texture.</param>
\r
173 /// <param name="format">The surface format of the texture.</param>
\r
174 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
175 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
176 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
177 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
178 /// <param name="imageInformation">When the method completes, contains additional information about the texture.</param>
\r
179 /// <param name="palette">When the method completes, contains the texture palette.</param>
\r
180 /// <returns>The created texture object.</returns>
\r
181 static CubeTexture^ FromStream( SlimDX::Direct3D9::Device^ device, System::IO::Stream^ stream, int sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, [Out] ImageInformation% imageInformation, [Out] array<PaletteEntry>^% palette );
\r
184 /// Creates a texture from a stream.
\r
186 /// <param name="device">The device to be associated with the texture.</param>
\r
187 /// <param name="stream">The stream containing the texture data.</param>
\r
188 /// <param name="sizeBytes">The size of the data, in bytes.</param>
\r
189 /// <param name="size">Size of the texture, in pixels.</param>
\r
190 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
191 /// <param name="usage">The requested usage for the texture.</param>
\r
192 /// <param name="format">The surface format of the texture.</param>
\r
193 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
194 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
195 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
196 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
197 /// <param name="imageInformation">When the method completes, contains additional information about the texture.</param>
\r
198 /// <returns>The created texture object.</returns>
\r
199 static CubeTexture^ FromStream( SlimDX::Direct3D9::Device^ device, System::IO::Stream^ stream, int sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, [Out] ImageInformation% imageInformation );
\r
202 /// Creates a texture from a stream.
\r
204 /// <param name="device">The device to be associated with the texture.</param>
\r
205 /// <param name="stream">The stream containing the texture data.</param>
\r
206 /// <param name="sizeBytes">The size of the data, in bytes.</param>
\r
207 /// <param name="size">Size of the texture, in pixels.</param>
\r
208 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
209 /// <param name="usage">The requested usage for the texture.</param>
\r
210 /// <param name="format">The surface format of the texture.</param>
\r
211 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
212 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
213 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
214 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
215 /// <returns>The created texture object.</returns>
\r
216 static CubeTexture^ FromStream( SlimDX::Direct3D9::Device^ device, System::IO::Stream^ stream, int sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey );
\r
219 /// Creates a texture from a stream.
\r
221 /// <param name="device">The device to be associated with the texture.</param>
\r
222 /// <param name="stream">The stream containing the texture data.</param>
\r
223 /// <param name="size">Size of the texture, in pixels.</param>
\r
224 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
225 /// <param name="usage">The requested usage for the texture.</param>
\r
226 /// <param name="format">The surface format of the texture.</param>
\r
227 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
228 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
229 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
230 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
231 /// <returns>The created texture object.</returns>
\r
232 static CubeTexture^ FromStream( SlimDX::Direct3D9::Device^ device, System::IO::Stream^ stream, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey );
\r
235 /// Creates a texture from a stream.
\r
237 /// <param name="device">The device to be associated with the texture.</param>
\r
238 /// <param name="stream">The stream containing the texture data.</param>
\r
239 /// <param name="usage">The requested usage for the texture.</param>
\r
240 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
241 /// <returns>The created texture object.</returns>
\r
242 static CubeTexture^ FromStream( SlimDX::Direct3D9::Device^ device, System::IO::Stream^ stream, Usage usage, Pool pool );
\r
245 /// Creates a texture from a stream.
\r
247 /// <param name="device">The device to be associated with the texture.</param>
\r
248 /// <param name="stream">The stream containing the texture data.</param>
\r
249 /// <returns>The created texture object.</returns>
\r
250 static CubeTexture^ FromStream( SlimDX::Direct3D9::Device^ device, System::IO::Stream^ stream );
\r
253 /// Loads a texture from file.
\r
255 /// <param name="device">The device to be associated with the texture.</param>
\r
256 /// <param name="fileName">The name of the file containing the image.</param>
\r
257 /// <param name="size">Size of the texture, in pixels.</param>
\r
258 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
259 /// <param name="usage">The requested usage for the texture.</param>
\r
260 /// <param name="format">The surface format of the texture.</param>
\r
261 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
262 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
263 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
264 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
265 /// <param name="imageInformation">When the method completes, contains additional information about the texture.</param>
\r
266 /// <param name="palette">When the method completes, contains the texture palette.</param>
\r
267 /// <returns>The created texture object.</returns>
\r
268 static CubeTexture^ FromFile( SlimDX::Direct3D9::Device^ device, System::String^ fileName, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, [Out] ImageInformation% imageInformation, [Out] array<PaletteEntry>^% palette );
\r
271 /// Loads a texture from file.
\r
273 /// <param name="device">The device to be associated with the texture.</param>
\r
274 /// <param name="fileName">The name of the file containing the image.</param>
\r
275 /// <param name="size">Size of the texture, in pixels.</param>
\r
276 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
277 /// <param name="usage">The requested usage for the texture.</param>
\r
278 /// <param name="format">The surface format of the texture.</param>
\r
279 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
280 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
281 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
282 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
283 /// <param name="imageInformation">When the method completes, contains additional information about the texture.</param>
\r
284 /// <returns>The created texture object.</returns>
\r
285 static CubeTexture^ FromFile( SlimDX::Direct3D9::Device^ device, System::String^ fileName, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, [Out] ImageInformation% imageInformation );
\r
288 /// Loads a texture from file.
\r
290 /// <param name="device">The device to be associated with the texture.</param>
\r
291 /// <param name="fileName">The name of the file containing the image.</param>
\r
292 /// <param name="size">Size of the texture, in pixels.</param>
\r
293 /// <param name="levelCount">Number of mipmap levels requested. If set to 0, mipmaps will automatically be generated.</param>
\r
294 /// <param name="usage">The requested usage for the texture.</param>
\r
295 /// <param name="format">The surface format of the texture.</param>
\r
296 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
297 /// <param name="filter">Combination of flags controlling how the image is filtered.</param>
\r
298 /// <param name="mipFilter">Combination of flags controlling how the mipmaps are filtered.</param>
\r
299 /// <param name="colorKey">Color value in the image to replace with black, or 0 to disable the color key.</param>
\r
300 /// <returns>The created texture object.</returns>
\r
301 static CubeTexture^ FromFile( SlimDX::Direct3D9::Device^ device, System::String^ fileName, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey );
\r
304 /// Loads a texture from file.
\r
306 /// <param name="device">The device to be associated with the texture.</param>
\r
307 /// <param name="fileName">The name of the file containing the image.</param>
\r
308 /// <param name="usage">The requested usage for the texture.</param>
\r
309 /// <param name="pool">The memory class into which the texture should be placed.</param>
\r
310 /// <returns>The created texture object.</returns>
\r
311 static CubeTexture^ FromFile( SlimDX::Direct3D9::Device^ device, System::String^ fileName, Usage usage, Pool pool );
\r
314 /// Loads a texture from file.
\r
316 /// <param name="device">The device to be associated with the texture.</param>
\r
317 /// <param name="fileName">The name of the file containing the image.</param>
\r
318 /// <returns>The created texture object.</returns>
\r
319 static CubeTexture^ FromFile( SlimDX::Direct3D9::Device^ device, System::String^ fileName );
\r
322 /// Uses a user-provided function to fill each texel of each mip level of a given texture.
\r
324 /// <param name="callback">A function that is used to fill the texture.</param>
\r
325 /// <returns>A <see cref="SlimDX::Result"/> object describing the result of the operation.</returns>
\r
326 [System::Security::Permissions::SecurityPermission( System::Security::Permissions::SecurityAction::LinkDemand, Flags=System::Security::Permissions::SecurityPermissionFlag::UnmanagedCode )]
\r
327 Result Fill( Fill3DCallback^ callback );
\r
330 /// Uses a compiled HLSL shader function to fill each texel of each mip level of a given texture.
\r
332 /// <param name="shader">A texture shader object that is used to fill the texture.</param>
\r
333 /// <returns>A <see cref="SlimDX::Result"/> object describing the result of the operation.</returns>
\r
334 Result Fill( TextureShader^ shader );
\r
337 /// Locks a texture resource.
\r
339 /// <param name="face">The cube map face to operate on.</param>
\r
340 /// <param name="level">The level of the texture to lock.</param>
\r
341 /// <param name="flags">Locking flags.</param>
\r
342 /// <returns>A <see cref="DataRectangle"/> describing the locked region.</returns>
\r
343 DataRectangle^ LockRectangle( CubeMapFace face, int level, LockFlags flags );
\r
346 /// Locks a rectangle on a texture resource.
\r
348 /// <param name="face">The cube map face to operate on.</param>
\r
349 /// <param name="level">The level of the texture to lock.</param>
\r
350 /// <param name="rectangle">The region on the texture to lock.</param>
\r
351 /// <param name="flags">Locking flags.</param>
\r
352 /// <returns>A <see cref="DataRectangle"/> describing the locked region.</returns>
\r
353 DataRectangle^ LockRectangle( CubeMapFace face, int level, System::Drawing::Rectangle rectangle, LockFlags flags );
\r
356 /// Unlocks a previously locked region of a texture.
\r
358 /// <param name="face">The cube map face to operate on.</param>
\r
359 /// <param name="level">The level of the texture to unlock.</param>
\r
360 /// <returns>A <see cref="SlimDX::Result"/> object describing the result of the operation.</returns>
\r
361 Result UnlockRectangle( CubeMapFace face, int level );
\r
364 /// Adds a dirty region to a texture resource.
\r
366 /// <param name="face">The cube map face to operate on.</param>
\r
367 /// <param name="rectangle">A rectangle specifying the dirty region to add.</param>
\r
368 /// <returns>A <see cref="SlimDX::Result"/> object describing the result of the operation.</returns>
\r
369 Result AddDirtyRectangle( CubeMapFace face, System::Drawing::Rectangle rectangle );
\r
372 /// Marks the entire texture face as dirty.
\r
374 /// <param name="face">The cube map face to operate on.</param>
\r
375 /// <returns>A <see cref="SlimDX::Result"/> object describing the result of the operation.</returns>
\r
376 Result AddDirtyRectangle( CubeMapFace face );
\r
379 /// Retrieves a level description of a texture resource.
\r
381 /// <param name="level">Identifies the level whose description is to be retrieved.</param>
\r
382 /// <returns>The surface description of the specified level.</returns>
\r
383 SurfaceDescription GetLevelDescription( int level );
\r
386 /// Retrieves the specified surface level.
\r
388 /// <param name="face">The cube map face to operate on.</param>
\r
389 /// <param name="level">Identifies the level whose surface is to be retrieved.</param>
\r
390 /// <returns>The surface of the specified level.</returns>
\r
391 Surface^ GetCubeMapSurface( CubeMapFace face, int level );
\r