// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.IO;
using SharpDX.Direct3D;
using SharpDX.Mathematics.Interop;
namespace SharpDX.Direct3D9
{
public partial class Surface
{
///
/// Creates a depth-stencil surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [discard].
/// A reference to a , representing the created depth-stencil surface resource.
/// HRESULT IDirect3DDevice9::CreateDepthStencilSurface([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Discard,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle)
public static Surface CreateDepthStencil(
Device device, int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool discard)
{
return device.CreateDepthStencilSurface(width, height, format, multisampleType, multisampleQuality, discard, IntPtr.Zero);
}
///
/// Creates a depth-stencil surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [discard].
/// The shared handle.
/// A reference to a , representing the created depth-stencil surface resource.
/// HRESULT IDirect3DDevice9::CreateDepthStencilSurface([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Discard,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle)
public static Surface CreateDepthStencil(
Device device, int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool discard, ref IntPtr sharedHandle)
{
unsafe
{
fixed (void* pSharedHandle = &sharedHandle)
return device.CreateDepthStencilSurface(width, height, format, multisampleType, multisampleQuality, discard, (IntPtr)pSharedHandle);
}
}
///
/// Creates a depth-stencil surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [discard].
/// The usage.
/// A reference to a , representing the created depth-stencil surface resource.
/// HRESULT IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Discard,[Out, Fast] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle,[In] unsigned int Usage)
public static Surface CreateDepthStencilEx(
DeviceEx device, int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool discard, Usage usage)
{
return device.CreateDepthStencilSurfaceEx(width, height, format, multisampleType, multisampleQuality, discard, IntPtr.Zero, (int)usage);
}
///
/// Creates a depth-stencil surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [discard].
/// The usage.
/// The shared handle.
/// A reference to a , representing the created depth-stencil surface resource.
/// HRESULT IDirect3DDevice9Ex::CreateDepthStencilSurfaceEx([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Discard,[Out, Fast] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle,[In] unsigned int Usage)
public static Surface CreateDepthStencilEx(
DeviceEx device,
int width,
int height,
Format format,
MultisampleType multisampleType,
int multisampleQuality,
bool discard,
Usage usage,
ref IntPtr sharedHandle)
{
unsafe
{
fixed (void* pSharedHandle = &sharedHandle)
return device.CreateDepthStencilSurfaceEx(
width, height, format, multisampleType, multisampleQuality, discard, (IntPtr)pSharedHandle, (int)usage);
}
}
///
/// Create an off-screen surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// The pool.
/// A created.
/// HRESULT IDirect3DDevice9::CreateOffscreenPlainSurface([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[Out, Fast] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle)
public static Surface CreateOffscreenPlain(Device device, int width, int height, Format format, Pool pool)
{
return device.CreateOffscreenPlainSurface(width, height, format, pool, IntPtr.Zero);
}
///
/// Create an off-screen surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// The pool.
/// The shared handle.
/// A created.
/// HRESULT IDirect3DDevice9::CreateOffscreenPlainSurface([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[Out, Fast] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle)
public static Surface CreateOffscreenPlain(Device device, int width, int height, Format format, Pool pool, ref IntPtr sharedHandle)
{
unsafe
{
fixed (void* pSharedHandle = &sharedHandle)
return device.CreateOffscreenPlainSurface(width, height, format, pool, (IntPtr)pSharedHandle);
}
}
///
/// Create an off-screen surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// The pool.
/// The usage.
///
/// A created.
///
/// HRESULT IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle,[In] unsigned int Usage)
public static Surface CreateOffscreenPlainEx(DeviceEx device, int width, int height, Format format, Pool pool, Usage usage)
{
return device.CreateOffscreenPlainSurfaceEx(width, height, format, pool, IntPtr.Zero, (int)usage);
}
///
/// Create an off-screen surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// The pool.
/// The usage.
/// The shared handle.
///
/// A created.
///
/// HRESULT IDirect3DDevice9Ex::CreateOffscreenPlainSurfaceEx([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle,[In] unsigned int Usage)
public static Surface CreateOffscreenPlainEx(DeviceEx device, int width, int height, Format format, Pool pool, Usage usage, ref IntPtr sharedHandle)
{
unsafe
{
fixed (void* pSharedHandle = &sharedHandle)
return device.CreateOffscreenPlainSurfaceEx(width, height, format, pool, (IntPtr)pSharedHandle, (int)usage);
}
}
///
/// Creates a render-target surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [lockable].
///
/// A render-target .
///
/// HRESULT IDirect3DDevice9::CreateRenderTarget([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Lockable,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle)
public static Surface CreateRenderTarget(
Device device, int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool lockable)
{
return device.CreateRenderTarget(width, height, format, multisampleType, multisampleQuality, lockable, IntPtr.Zero);
}
///
/// Creates a render-target surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [lockable].
/// The shared handle.
///
/// A render-target .
///
/// HRESULT IDirect3DDevice9::CreateRenderTarget([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Lockable,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle)
public static Surface CreateRenderTarget(
Device device, int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool lockable, ref IntPtr sharedHandle)
{
unsafe
{
fixed (void* pSharedHandle = &sharedHandle)
return device.CreateRenderTarget(width, height, format, multisampleType, multisampleQuality, lockable, (IntPtr)pSharedHandle);
}
}
///
/// Creates a render-target surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [lockable].
/// The usage.
/// A render-target .
/// HRESULT IDirect3DDevice9Ex::CreateRenderTargetEx([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Lockable,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle,[In] unsigned int Usage)
public static Surface CreateRenderTargetEx(
DeviceEx device, int width, int height, Format format, MultisampleType multisampleType, int multisampleQuality, bool lockable, Usage usage)
{
return device.CreateRenderTargetEx(width, height, format, multisampleType, multisampleQuality, lockable, IntPtr.Zero, (int)usage);
}
///
/// Creates a render-target surface.
///
/// The device.
/// The width.
/// The height.
/// The format.
/// Type of the multisample.
/// The multisample quality.
/// if set to true [lockable].
/// The usage.
/// The shared handle.
/// A render-target .
/// HRESULT IDirect3DDevice9Ex::CreateRenderTargetEx([In] unsigned int Width,[In] unsigned int Height,[In] D3DFORMAT Format,[In] D3DMULTISAMPLE_TYPE MultiSample,[In] unsigned int MultisampleQuality,[In] BOOL Lockable,[Out] IDirect3DSurface9** ppSurface,[In] void** pSharedHandle,[In] unsigned int Usage)
public static Surface CreateRenderTargetEx(
DeviceEx device,
int width,
int height,
Format format,
MultisampleType multisampleType,
int multisampleQuality,
bool lockable,
Usage usage,
ref IntPtr sharedHandle)
{
unsafe
{
fixed (void* pSharedHandle = &sharedHandle)
return device.CreateRenderTargetEx(width, height, format, multisampleType, multisampleQuality, lockable, (IntPtr)pSharedHandle, (int)usage);
}
}
///
/// Loads a surface from a file.
///
/// The surface.
/// Name of the file.
/// The filter.
/// The color key.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileW([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const wchar_t* pSrcFile,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFile(Surface surface, string fileName, Filter filter, int colorKey)
{
D3DX9.LoadSurfaceFromFileW(surface, null, IntPtr.Zero, fileName, IntPtr.Zero, filter, colorKey, IntPtr.Zero);
}
///
/// Loads a surface from a file.
///
/// The surface.
/// Name of the file.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileW([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const wchar_t* pSrcFile,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFile(Surface surface, string fileName, Filter filter, int colorKey, RawRectangle sourceRectangle, RawRectangle destinationRectangle)
{
unsafe
{
D3DX9.LoadSurfaceFromFileW(
surface, null, new IntPtr(&destinationRectangle), fileName, new IntPtr(&sourceRectangle), filter, colorKey, IntPtr.Zero);
}
}
///
/// Loads a surface from a file.
///
/// The surface.
/// Name of the file.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The image information.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileW([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const wchar_t* pSrcFile,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFile(
Surface surface,
string fileName,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
out ImageInformation imageInformation)
{
FromFile(surface, fileName, filter, colorKey, sourceRectangle, destinationRectangle, null, out imageInformation);
}
///
/// Loads a surface from a file.
///
/// The surface.
/// Name of the file.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The palette.
/// The image information.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileW([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const wchar_t* pSrcFile,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFile(
Surface surface,
string fileName,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
PaletteEntry[] palette,
out ImageInformation imageInformation)
{
unsafe
{
fixed (void* pImageInformation = &imageInformation)
D3DX9.LoadSurfaceFromFileW(
surface, palette, new IntPtr(&destinationRectangle), fileName, new IntPtr(&sourceRectangle), filter, colorKey, (IntPtr)pImageInformation);
}
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The memory.
/// The filter.
/// The color key.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFileInMemory(Surface surface, byte[] memory, Filter filter, int colorKey)
{
unsafe
{
fixed (void* pMemory = memory)
D3DX9.LoadSurfaceFromFileInMemory(
surface, null, IntPtr.Zero, (IntPtr)pMemory, memory.Length, IntPtr.Zero, filter, colorKey, IntPtr.Zero);
}
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The memory.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFileInMemory(
Surface surface, byte[] memory, Filter filter, int colorKey, RawRectangle sourceRectangle, RawRectangle destinationRectangle)
{
unsafe
{
fixed (void* pMemory = memory)
D3DX9.LoadSurfaceFromFileInMemory(
surface,
null,
new IntPtr(&destinationRectangle),
(IntPtr)pMemory,
memory.Length,
new IntPtr(&sourceRectangle),
filter,
colorKey,
IntPtr.Zero);
}
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The memory.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The image information.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFileInMemory(
Surface surface,
byte[] memory,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
out ImageInformation imageInformation)
{
FromFileInMemory(surface, memory, filter, colorKey, sourceRectangle, destinationRectangle, null, out imageInformation);
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The memory.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The palette.
/// The image information.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFileInMemory(
Surface surface,
byte[] memory,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
PaletteEntry[] palette,
out ImageInformation imageInformation)
{
unsafe
{
fixed (void* pMemory = memory)
fixed (void* pImageInformation = &imageInformation)
D3DX9.LoadSurfaceFromFileInMemory(
surface,
palette,
new IntPtr(&destinationRectangle),
(IntPtr)pMemory,
memory.Length,
new IntPtr(&sourceRectangle),
filter,
colorKey,
(IntPtr)pImageInformation);
}
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFileInStream(Surface surface, Stream stream, Filter filter, int colorKey)
{
if (stream is DataStream)
{
D3DX9.LoadSurfaceFromFileInMemory(
surface, null, IntPtr.Zero, ((DataStream)stream).PositionPointer, (int)(stream.Length - stream.Position), IntPtr.Zero, filter, colorKey, IntPtr.Zero);
}
else
{
unsafe
{
var data = Utilities.ReadStream(stream);
fixed (void* pData = data)
D3DX9.LoadSurfaceFromFileInMemory(surface, null, IntPtr.Zero, (IntPtr)pData, data.Length, IntPtr.Zero, filter, colorKey, IntPtr.Zero);
}
}
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFileInStream(
Surface surface, Stream stream, Filter filter, int colorKey, RawRectangle sourceRectangle, RawRectangle destinationRectangle)
{
CreateFromFileInStream(surface, stream, filter, colorKey, sourceRectangle, destinationRectangle, null, IntPtr.Zero);
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The image information.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static void FromFileInStream(
Surface surface,
Stream stream,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
out ImageInformation imageInformation)
{
FromFileInStream(surface, stream, filter, colorKey, sourceRectangle, destinationRectangle, null, out imageInformation);
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The palette.
/// The image information.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
public static unsafe void FromFileInStream(
Surface surface,
Stream stream,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
PaletteEntry[] palette,
out ImageInformation imageInformation)
{
fixed (void* pImageInformation = &imageInformation)
CreateFromFileInStream(surface, stream, filter, colorKey, sourceRectangle, destinationRectangle, palette, (IntPtr)pImageInformation);
}
///
/// Loads a surface from a file in memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The palette.
/// The image information.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromFileInMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)
private static unsafe void CreateFromFileInStream(
Surface surface,
Stream stream,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
PaletteEntry[] palette,
IntPtr imageInformation)
{
if (stream is DataStream)
{
D3DX9.LoadSurfaceFromFileInMemory(
surface,
palette,
new IntPtr(&destinationRectangle),
((DataStream)stream).PositionPointer,
(int)(stream.Length - stream.Position),
new IntPtr(&sourceRectangle),
filter,
colorKey,
imageInformation);
}
else
{
var data = Utilities.ReadStream(stream);
fixed (void* pData = data)
D3DX9.LoadSurfaceFromFileInMemory(
surface,
palette,
new IntPtr(&destinationRectangle),
(IntPtr)pData,
data.Length,
new IntPtr(&sourceRectangle),
filter,
colorKey,
imageInformation);
}
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The data.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromMemory(
Surface surface, byte[] data, Filter filter, int colorKey, Format sourceFormat, int sourcePitch, RawRectangle sourceRectangle)
{
FromMemory(surface, data, filter, colorKey, sourceFormat, sourcePitch, sourceRectangle, null, null);
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The data.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
/// The destination rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromMemory(
Surface surface,
byte[] data,
Filter filter,
int colorKey,
Format sourceFormat,
int sourcePitch,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle)
{
FromMemory(surface, data, filter, colorKey, sourceFormat, sourcePitch, sourceRectangle, destinationRectangle, null, null);
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The data.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
/// The source palette.
/// The destination palette.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromMemory(
Surface surface,
byte[] data,
Filter filter,
int colorKey,
Format sourceFormat,
int sourcePitch,
RawRectangle sourceRectangle,
PaletteEntry[] sourcePalette,
PaletteEntry[] destinationPalette)
{
unsafe
{
fixed (void* pData = data)
D3DX9.LoadSurfaceFromMemory(
surface,
destinationPalette,
IntPtr.Zero,
(IntPtr)pData,
sourceFormat,
sourcePitch,
sourcePalette,
new IntPtr(&sourceRectangle),
filter,
colorKey);
}
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The data.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
/// The destination rectangle.
/// The source palette.
/// The destination palette.
/// A object describing the result of the operation.
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromMemory(
Surface surface,
byte[] data,
Filter filter,
int colorKey,
Format sourceFormat,
int sourcePitch,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
PaletteEntry[] sourcePalette,
PaletteEntry[] destinationPalette)
{
unsafe
{
fixed (void* pData = data)
D3DX9.LoadSurfaceFromMemory(
surface,
destinationPalette,
new IntPtr(&destinationRectangle),
(IntPtr)pData,
sourceFormat,
sourcePitch,
sourcePalette,
new IntPtr(&sourceRectangle),
filter,
colorKey);
}
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromStream(
Surface surface, Stream stream, Filter filter, int colorKey, Format sourceFormat, int sourcePitch, RawRectangle sourceRectangle)
{
FromStream(surface, stream, filter, colorKey, sourceFormat, sourcePitch, sourceRectangle, null, null);
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
/// The destination rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromStream(
Surface surface,
Stream stream,
Filter filter,
int colorKey,
Format sourceFormat,
int sourcePitch,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle)
{
FromStream(surface, stream, filter, colorKey, sourceFormat, sourcePitch, sourceRectangle, destinationRectangle, null, null);
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
/// The source palette.
/// The destination palette.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromStream(
Surface surface,
Stream stream,
Filter filter,
int colorKey,
Format sourceFormat,
int sourcePitch,
RawRectangle sourceRectangle,
PaletteEntry[] sourcePalette,
PaletteEntry[] destinationPalette)
{
unsafe
{
if (stream is DataStream)
{
D3DX9.LoadSurfaceFromMemory(
surface,
destinationPalette,
IntPtr.Zero,
((DataStream)stream).PositionPointer,
sourceFormat,
sourcePitch,
sourcePalette,
new IntPtr(&sourceRectangle),
filter,
colorKey);
}
else
{
var data = Utilities.ReadStream(stream);
fixed (void* pData = data)
D3DX9.LoadSurfaceFromMemory(
surface,
destinationPalette,
IntPtr.Zero,
(IntPtr)pData,
sourceFormat,
sourcePitch,
sourcePalette,
new IntPtr(&sourceRectangle),
filter,
colorKey);
}
}
}
///
/// Loads a surface from memory.
///
/// The surface.
/// The stream.
/// The filter.
/// The color key.
/// The source format.
/// The source pitch.
/// The source rectangle.
/// The destination rectangle.
/// The source palette.
/// The destination palette.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromMemory([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcPitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromStream(
Surface surface,
Stream stream,
Filter filter,
int colorKey,
Format sourceFormat,
int sourcePitch,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
PaletteEntry[] sourcePalette,
PaletteEntry[] destinationPalette)
{
unsafe
{
if (stream is DataStream)
{
D3DX9.LoadSurfaceFromMemory(
surface,
destinationPalette,
new IntPtr(&destinationRectangle),
((DataStream)stream).PositionPointer,
sourceFormat,
sourcePitch,
sourcePalette,
new IntPtr(&sourceRectangle),
filter,
colorKey);
}
else
{
var data = Utilities.ReadStream(stream);
fixed (void* pData = data)
D3DX9.LoadSurfaceFromMemory(
surface,
destinationPalette,
new IntPtr(&destinationRectangle),
(IntPtr)pData,
sourceFormat,
sourcePitch,
sourcePalette,
new IntPtr(&sourceRectangle),
filter,
colorKey);
}
}
}
///
/// Loads a surface from a source surface.
///
/// The destination surface.
/// The source surface.
/// The filter.
/// The color key.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromSurface([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromSurface(Surface destinationSurface, Surface sourceSurface, Filter filter, int colorKey)
{
D3DX9.LoadSurfaceFromSurface(destinationSurface, null, IntPtr.Zero, sourceSurface, null, IntPtr.Zero, filter, colorKey);
}
///
/// Loads a surface from a source surface.
///
/// The destination surface.
/// The source surface.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromSurface([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromSurface(
Surface destinationSurface, Surface sourceSurface, Filter filter, int colorKey, RawRectangle sourceRectangle, RawRectangle destinationRectangle)
{
FromSurface(destinationSurface, sourceSurface, filter, colorKey, sourceRectangle, destinationRectangle, null, null);
}
///
/// Loads a surface from a source surface.
///
/// The destination surface.
/// The source surface.
/// The filter.
/// The color key.
/// The source rectangle.
/// The destination rectangle.
/// The destination palette.
/// The source palette.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXLoadSurfaceFromSurface([In] IDirect3DSurface9* pDestSurface,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestRect,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect,[In] D3DX_FILTER Filter,[In] int ColorKey)
public static void FromSurface(
Surface destinationSurface,
Surface sourceSurface,
Filter filter,
int colorKey,
RawRectangle sourceRectangle,
RawRectangle destinationRectangle,
PaletteEntry[] destinationPalette,
PaletteEntry[] sourcePalette)
{
unsafe
{
D3DX9.LoadSurfaceFromSurface(
destinationSurface,
destinationPalette,
new IntPtr(&destinationRectangle),
sourceSurface,
sourcePalette,
new IntPtr(&sourceRectangle),
filter,
colorKey);
}
}
///
/// Gets the parent cube texture or texture (mipmap) object, if this surface is a child level of a cube texture or a mipmap.
/// This method can also provide access to the parent swap chain if the surface is a back-buffer child.
///
///
/// The GUID.
/// The parent container texture.
public T GetContainer(Guid guid) where T : ComObject
{
IntPtr containerPtr;
GetContainer(guid, out containerPtr);
return FromPointer(containerPtr);
}
///
/// Locks a rectangle on a surface.
///
/// The type of lock to perform.
/// A pointer to the locked region
/// HRESULT IDirect3DSurface9::LockRect([Out] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)
public DataRectangle LockRectangle(LockFlags flags)
{
LockedRectangle lockedRect;
LockRectangle(out lockedRect, IntPtr.Zero, flags);
return new DataRectangle(lockedRect.PBits, lockedRect.Pitch);
}
///
/// Locks a rectangle on a surface.
///
/// The rectangle to lock.
/// The type of lock to perform.
/// A pointer to the locked region
/// HRESULT IDirect3DSurface9::LockRect([Out] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)
public DataRectangle LockRectangle(RawRectangle rect, LockFlags flags)
{
unsafe
{
LockedRectangle lockedRect;
LockRectangle(out lockedRect, new IntPtr(&rect), flags);
return new DataRectangle(lockedRect.PBits, lockedRect.Pitch);
}
}
///
/// Locks a rectangle on a surface.
///
/// The type of lock to perform.
/// The stream pointing to the locked region.
/// A pointer to the locked region
/// HRESULT IDirect3DSurface9::LockRect([Out] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)
public DataRectangle LockRectangle(LockFlags flags, out DataStream stream)
{
LockedRectangle lockedRect;
LockRectangle(out lockedRect, IntPtr.Zero, flags);
stream = new DataStream(lockedRect.PBits, lockedRect.Pitch * Description.Height, true, (flags & LockFlags.ReadOnly) == 0);
return new DataRectangle(lockedRect.PBits, lockedRect.Pitch);
}
///
/// Locks a rectangle on a surface.
///
/// The rectangle to lock.
/// The type of lock to perform.
/// The stream pointing to the locked region.
/// A pointer to the locked region
/// HRESULT IDirect3DSurface9::LockRect([Out] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags)
public DataRectangle LockRectangle(RawRectangle rect, LockFlags flags, out DataStream stream)
{
unsafe
{
LockedRectangle lockedRect;
LockRectangle(out lockedRect, new IntPtr(&rect), flags);
stream = new DataStream(lockedRect.PBits, lockedRect.Pitch * Description.Height, true, (flags & LockFlags.ReadOnly) == 0);
return new DataRectangle(lockedRect.PBits, lockedRect.Pitch);
}
}
///
/// Saves a surface to a file.
///
/// The surface.
/// Name of the file.
/// The format.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXSaveSurfaceToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect)
public static void ToFile(Surface surface, string fileName, ImageFileFormat format)
{
D3DX9.SaveSurfaceToFileW(fileName, format, surface, null, IntPtr.Zero);
}
///
/// Saves a surface to a file.
///
/// The surface.
/// Name of the file.
/// The format.
/// The rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXSaveSurfaceToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect)
public static void ToFile(Surface surface, string fileName, ImageFileFormat format, RawRectangle rectangle)
{
ToFile(surface, fileName, format, rectangle, null);
}
///
/// Saves a surface to a file.
///
/// The surface.
/// Name of the file.
/// The format.
/// The rectangle.
/// The palette.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXSaveSurfaceToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect)
public static void ToFile(Surface surface, string fileName, ImageFileFormat format, RawRectangle rectangle, PaletteEntry[] palette)
{
unsafe
{
D3DX9.SaveSurfaceToFileW(fileName, format, surface, palette, new IntPtr(&rectangle));
}
}
///
/// Saves a surface to a stream.
///
/// The surface.
/// The format.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXSaveSurfaceToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect)
public static DataStream ToStream(Surface surface, ImageFileFormat format)
{
Blob blob;
D3DX9.SaveSurfaceToFileInMemory(out blob, format, surface, null, IntPtr.Zero);
return new DataStream(blob);
}
///
/// Saves a surface to a stream.
///
/// The surface.
/// The format.
/// The rectangle.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXSaveSurfaceToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect)
public static DataStream ToStream(Surface surface, ImageFileFormat format, RawRectangle rectangle)
{
return ToStream(surface, format, rectangle, null);
}
///
/// Saves a surface to a stream.
///
/// The surface.
/// The format.
/// The rectangle.
/// The palette.
///
/// A object describing the result of the operation.
///
/// HRESULT D3DXSaveSurfaceToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DSurface9* pSrcSurface,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcRect)
public static DataStream ToStream(Surface surface, ImageFileFormat format, RawRectangle rectangle, PaletteEntry[] palette)
{
unsafe
{
Blob blob;
D3DX9.SaveSurfaceToFileInMemory(out blob, format, surface, palette, new IntPtr(&rectangle));
return new DataStream(blob);
}
}
}
}