// 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.Globalization;
using System.Reflection;
using SharpDX.Mathematics.Interop;
namespace SharpDX.Direct3D9
{
public partial class Device
{
///
/// Creates a device to represent the display adapter.
///
///
/// This method returns a fully working device interface, set to the required display mode (or windowed), and allocated with the appropriate back buffers. To begin rendering, the application needs only to create and set a depth buffer (assuming EnableAutoDepthStencil is FALSE in ). When you create a Direct3D device, you supply two different window parameters: a focus window (hFocusWindow) and a device window (the hDeviceWindow in ). The purpose of each window is: The focus window alerts Direct3D when an application switches from foreground mode to background mode (via Alt-Tab, a mouse click, or some other method). A single focus window is shared by each device created by an application. The device window determines the location and size of the back buffer on screen. This is used by Direct3D when the back buffer contents are copied to the front buffer during {{Present}}. This method should not be run during the handling of WM_CREATE. An application should never pass a window handle to Direct3D while handling WM_CREATE. Any call to create, release, or reset the device must be done using the same thread as the window procedure of the focus window. Note that D3DCREATE_HARDWARE_VERTEXPROCESSING, D3DCREATE_MIXED_VERTEXPROCESSING, and D3DCREATE_SOFTWARE_VERTEXPROCESSING are mutually exclusive flags, and at least one of these vertex processing flags must be specified when calling this method. Back buffers created as part of the device are only lockable if D3DPRESENTFLAG_LOCKABLE_BACKBUFFER is specified in the presentation parameters. (Multisampled back buffers and depth surfaces are never lockable.) The methods {{Reset}}, , and {{TestCooperativeLevel}} must be called from the same thread that used this method to create a device. D3DFMT_UNKNOWN can be specified for the windowed mode back buffer format when calling CreateDevice, {{Reset}}, and {{CreateAdditionalSwapChain}}. This means the application does not have to query the current desktop format before calling CreateDevice for windowed mode. For full-screen mode, the back buffer format must be specified. If you attempt to create a device on a 0x0 sized window, CreateDevice will fail.
///
/// an instance of
/// Ordinal number that denotes the display adapter. {{D3DADAPTER_DEFAULT}} is always the primary display adapter.
/// Member of the enumerated type that denotes the desired device type. If the desired device type is not available, the method will fail.
/// The focus window alerts Direct3D when an application switches from foreground mode to background mode. See Remarks. For full-screen mode, the window specified must be a top-level window. For windowed mode, this parameter may be NULL only if the hDeviceWindow member of pPresentationParameters is set to a valid, non-NULL value.
/// Combination of one or more options that control device creation. For more information, see {{D3DCREATE}}.
/// Pointer to a structure, describing the presentation parameters for the device to be created. If BehaviorFlags specifies {{D3DCREATE_ADAPTERGROUP_DEVICE}}, pPresentationParameters is an array. Regardless of the number of heads that exist, only one depth/stencil surface is automatically created. For Windows 2000 and Windows XP, the full-screen device display refresh rate is set in the following order: User-specified nonzero ForcedRefreshRate registry key, if supported by the device. Application-specified nonzero refresh rate value in the presentation parameter. Refresh rate of the latest desktop mode, if supported by the device. 75 hertz if supported by the device. 60 hertz if supported by the device. Device default. An unsupported refresh rate will default to the closest supported refresh rate below it. For example, if the application specifies 63 hertz, 60 hertz will be used. There are no supported refresh rates below 57 hertz. pPresentationParameters is both an input and an output parameter. Calling this method may change several members including: If BackBufferCount, BackBufferWidth, and BackBufferHeight are 0 before the method is called, they will be changed when the method returns. If BackBufferFormat equals before the method is called, it will be changed when the method returns.
/// If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be one of the following: D3DERR_DEVICELOST, D3DERR_INVALIDCALL, D3DERR_NOTAVAILABLE, D3DERR_OUTOFVIDEOMEMORY.
/// HRESULT CreateDevice([None] UINT Adapter,[None] D3DDEVTYPE DeviceType,[None] HWND hFocusWindow,[None] int BehaviorFlags,[None] D3DPRESENT_PARAMETERS* pPresentationParameters,[None] IDirect3DDevice9** ppReturnedDeviceInterface)
public Device(Direct3D direct3D, int adapter, SharpDX.Direct3D9.DeviceType deviceType, IntPtr hFocusWindow, CreateFlags behaviorFlags, params SharpDX.Direct3D9.PresentParameters[] presentationParametersRef)
{
direct3D.CreateDevice(adapter, deviceType, hFocusWindow, behaviorFlags, presentationParametersRef, this);
}
///
/// Gets the available texture memory.
///
public long AvailableTextureMemory
{
get
{
return unchecked((uint)GetAvailableTextureMem());
}
}
///
/// Gets the driver level.
///
public DriverLevel DriverLevel
{
get
{
return (DriverLevel)D3DX9.GetDriverLevel(this);
}
}
///
/// Gets the pixel shader profile.
///
public string PixelShaderProfile
{
get
{
return D3DX9.GetPixelShaderProfile(this);
}
}
///
/// Gets the vertex shader profile.
///
public string VertexShaderProfile
{
get
{
return D3DX9.GetVertexShaderProfile(this);
}
}
///
/// Clears one or more surfaces such as a render target, a stencil buffer, and a depth buffer.
///
/// Flags that specify which surfaces will be cleared.
/// The color that will be used to fill the cleared render target.
/// The value that will be used to fill the cleared depth buffer.
/// The value that will be used to fill the cleared stencil buffer.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::Clear([None] int Count,[In, Buffer, Optional] const D3DRECT* pRects,[None] int Flags,[None] D3DCOLOR Color,[None] float Z,[None] int Stencil)
public void Clear(ClearFlags clearFlags, RawColorBGRA color, float zdepth, int stencil)
{
this.Clear_(0, null, clearFlags, color, zdepth, stencil);
}
///
/// Clears one or more surfaces such as a render target, a stencil buffer, and a depth buffer.
///
/// Flags that specify which surfaces will be cleared.
/// The color that will be used to fill the cleared render target.
/// The value that will be used to fill the cleared depth buffer.
/// The value that will be used to fill the cleared stencil buffer.
/// The areas on the surfaces that will be cleared.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::Clear([None] int Count,[In, Buffer, Optional] const D3DRECT* pRects,[None] int Flags,[None] D3DCOLOR Color,[None] float Z,[None] int Stencil)
public void Clear(ClearFlags clearFlags, RawColorBGRA color, float zdepth, int stencil, RawRectangle[] rectangles)
{
this.Clear_( rectangles == null?0:rectangles.Length, rectangles, clearFlags, color, zdepth, stencil);
}
///
/// Allows an application to fill a rectangular area of a D3DPOOL_DEFAULT surface with a specified color.
///
///
/// This method can only be applied to a render target, a render-target texture surface, or an off-screen plain surface with a pool type of D3DPOOL_DEFAULT. IDirect3DDevice9::ColorFill will work with all formats. However, when using a reference or software device, the only formats supported are D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, D3DFMT_R5G6B5, D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_YUY2, D3DFMT_G8R8_G8B8, D3DFMT_UYVY, D3DFMT_R8G8_B8G8, D3DFMT_R16F, D3DFMT_G16R16F, D3DFMT_A16B16G16R16F, D3DFMT_R32F, D3DFMT_G32R32F, and D3DFMT_A32B32G32R32F. When using a DirectX 7 or DirectX 8.x driver, the only YUV formats supported are D3DFMT_UYVY and D3DFMT_YUY2.
///
/// Pointer to the surface to be filled.
/// Color used for filling.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::ColorFill([None] IDirect3DSurface9* pSurface,[In, Optional] const RECT* pRect,[None] D3DCOLOR color)
public void ColorFill(SharpDX.Direct3D9.Surface surfaceRef, RawColorBGRA color)
{
this.ColorFill(surfaceRef, null, color);
}
///
/// Draws the indexed user primitives.
///
///
///
/// Type of the primitive.
/// Minimum index of the vertex.
/// The vertex count.
/// The primitive count.
/// The index data.
/// The index data format.
/// The vertex data.
/// The vertex stride.
/// A object describing the result of the operation.
public void DrawIndexedUserPrimitives(PrimitiveType primitiveType, int minimumVertexIndex, int vertexCount, int primitiveCount, S[] indexData, Format indexDataFormat, T[] vertexData)
where S : struct
where T : struct
{
DrawIndexedUserPrimitives(primitiveType, 0, 0, minimumVertexIndex, vertexCount, primitiveCount, indexData, indexDataFormat, vertexData);
}
///
/// Draws the indexed user primitives.
///
///
///
/// Type of the primitive.
/// The start index.
/// Minimum index of the vertex.
/// The vertex count.
/// The primitive count.
/// The index data.
/// The index data format.
/// The vertex data.
/// A object describing the result of the operation.
public void DrawIndexedUserPrimitives(PrimitiveType primitiveType, int startIndex, int minimumVertexIndex, int vertexCount, int primitiveCount, S[] indexData, Format indexDataFormat, T[] vertexData)
where S : struct
where T : struct
{
DrawIndexedUserPrimitives(primitiveType, startIndex, 0, minimumVertexIndex, vertexCount, primitiveCount, indexData, indexDataFormat, vertexData);
}
///
/// Draws the indexed user primitives.
///
///
///
/// Type of the primitive.
/// The start index.
/// The start vertex.
/// Minimum index of the vertex.
/// The vertex count.
/// The primitive count.
/// The index data.
/// The index data format.
/// The vertex data.
/// A object describing the result of the operation.
public void DrawIndexedUserPrimitives(PrimitiveType primitiveType, int startIndex, int startVertex, int minimumVertexIndex, int vertexCount, int primitiveCount, S[] indexData, Format indexDataFormat, T[] vertexData)
where S : struct
where T : struct
{
unsafe
{
DrawIndexedPrimitiveUP(primitiveType, minimumVertexIndex, vertexCount, primitiveCount, (IntPtr)Interop.Fixed(ref indexData[startIndex]), indexDataFormat, (IntPtr)Interop.Fixed(ref vertexData[startVertex]), Utilities.SizeOf());
}
}
///
/// Draws the rectangle patch.
///
/// The handle.
/// The segment counts.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::DrawRectPatch([In] unsigned int Handle,[In, Buffer] const float* pNumSegs,[In] const void* pRectPatchInfo)
public void DrawRectanglePatch(int handle, float[] segmentCounts)
{
DrawRectanglePatch(handle, segmentCounts, IntPtr.Zero);
}
///
/// Draws the rectangle patch.
///
/// The handle.
/// The segment counts.
/// The info.
///
/// A object describing the result of the operation.
///
/// IDirect3DDevice9::DrawRectPatch
public void DrawRectanglePatch(int handle, float[] segmentCounts, RectanglePatchInfo info)
{
unsafe
{
DrawRectanglePatch(handle, segmentCounts, new IntPtr(&info));
}
}
///
/// Draws the triangle patch.
///
/// The handle.
/// The segment counts.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::DrawTriPatch([In] unsigned int Handle,[In, Buffer] const float* pNumSegs,[In] const void* pTriPatchInfo)
public void DrawTrianglePatch(int handle, float[] segmentCounts)
{
DrawTrianglePatch(handle, segmentCounts, IntPtr.Zero);
}
///
/// Draws the triangle patch.
///
/// The handle.
/// The segment counts.
/// The info.
///
/// A object describing the result of the operation.
///
public void DrawTrianglePatch(int handle, float[] segmentCounts, TrianglePatchInfo info)
{
unsafe
{
DrawTrianglePatch(handle, segmentCounts, new IntPtr(&info));
}
}
///
/// Draws the user primitives.
///
///
/// Type of the primitive.
/// The primitive count.
/// The data.
///
/// A object describing the result of the operation.
///
public void DrawUserPrimitives(PrimitiveType primitiveType, int primitiveCount, T[] data) where T : struct
{
DrawUserPrimitives(primitiveType, 0, primitiveCount, data);
}
///
/// Draws the user primitives.
///
///
/// Type of the primitive.
/// The start index.
/// The primitive count.
/// The data.
///
/// A object describing the result of the operation.
///
public void DrawUserPrimitives(PrimitiveType primitiveType, int startIndex, int primitiveCount, T[] data) where T : struct
{
unsafe
{
DrawPrimitiveUP(primitiveType, primitiveCount, (IntPtr)Interop.Fixed(ref data[startIndex]), Utilities.SizeOf());
}
}
///
/// Gets the back buffer.
///
/// The swap chain.
/// The back buffer.
/// A object describing the result of the operation.
public SharpDX.Direct3D9.Surface GetBackBuffer(int swapChain, int backBuffer)
{
return GetBackBuffer(swapChain, backBuffer, BackBufferType.Mono);
}
///
/// Gets the palette entries.
///
/// The palette number.
/// An array of
public PaletteEntry[] GetPaletteEntries(int paletteNumber)
{
var entries = new PaletteEntry[256];
GetPaletteEntries(paletteNumber, entries);
return entries;
}
///
/// Gets the pixel shader boolean constant.
///
/// The start register.
/// The count.
/// An array of boolean constants
public bool[] GetPixelShaderBooleanConstant(int startRegister, int count)
{
unsafe
{
if (count < 1024)
{
var result = stackalloc int[count];
GetPixelShaderConstantB(startRegister, (IntPtr)result, count);
return Utilities.ConvertToBoolArray(result, count);
}
else
{
var result = new RawBool[count];
fixed (void* pResult = result)
GetPixelShaderConstantB(startRegister, (IntPtr)pResult, count);
return Utilities.ConvertToBoolArray(result);
}
}
}
///
/// Gets the pixel shader float constant.
///
/// The start register.
/// The count.
/// An array of float constants
public float[] GetPixelShaderFloatConstant(int startRegister, int count)
{
var result = new float[count];
GetPixelShaderConstantF(startRegister, result, count);
return result;
}
///
/// Gets the pixel shader integer constant.
///
/// The start register.
/// The count.
/// An array of int constants
public int[] GetPixelShaderIntegerConstant(int startRegister, int count)
{
var result = new int[count];
GetPixelShaderConstantI(startRegister, result, count);
return result;
}
///
/// Gets the state of the render.
///
/// The state.
/// The render state value
/// HRESULT IDirect3DDevice9::GetRenderState([In] D3DRENDERSTATETYPE State,[In] void* pValue)
public int GetRenderState(SharpDX.Direct3D9.RenderState state)
{
unsafe
{
int result = 0;
GetRenderState(state, new IntPtr(&result));
return result;
}
}
///
/// Gets the state of the render.
///
/// Type of the state value.
/// The state.
///
/// The render state value
///
/// HRESULT IDirect3DDevice9::GetRenderState([In] D3DRENDERSTATETYPE State,[In] void* pValue)
public T GetRenderState(SharpDX.Direct3D9.RenderState state) where T : struct
{
unsafe
{
T result = default(T);
GetRenderState(state, (IntPtr)Interop.Fixed(ref result));
return result;
}
}
///
/// Gets the state of the sampler.
///
/// The sampler.
/// The state.
///
/// The sampler state value
///
/// HRESULT IDirect3DDevice9::GetSamplerState([In] unsigned int Sampler,[In] D3DSAMPLERSTATETYPE Type,[In] void* pValue)
public int GetSamplerState(int sampler, SharpDX.Direct3D9.SamplerState state)
{
unsafe
{
int result = 0;
GetSamplerState(sampler, state, new IntPtr(&result));
return result;
}
}
///
/// Gets the state of the sampler.
///
/// Type of the sampler state value
/// The sampler.
/// The state.
///
/// The sampler state value
///
/// HRESULT IDirect3DDevice9::GetSamplerState([In] unsigned int Sampler,[In] D3DSAMPLERSTATETYPE Type,[In] void* pValue)
public T GetSamplerState(int sampler, SharpDX.Direct3D9.SamplerState state) where T : struct
{
unsafe
{
T result = default(T);
GetSamplerState(sampler, state, (IntPtr)Interop.Fixed(ref result));
return result;
}
}
///
/// Gets the state of the texture stage.
///
/// The stage.
/// The type.
///
/// The texture stage state.
///
/// HRESULT IDirect3DDevice9::GetTextureStageState([In] unsigned int Stage,[In] D3DTEXTURESTAGESTATETYPE Type,[In] void* pValue)
public int GetTextureStageState(int stage, SharpDX.Direct3D9.TextureStage type)
{
unsafe
{
int result = 0;
GetTextureStageState(stage, type, new IntPtr(&result));
return result;
}
}
///
/// Gets the state of the texture stage.
///
/// Type of the texture stage state
/// The stage.
/// The type.
///
/// The texture stage state.
///
/// HRESULT IDirect3DDevice9::GetTextureStageState([In] unsigned int Stage,[In] D3DTEXTURESTAGESTATETYPE Type,[In] void* pValue)
public T GetTextureStageState(int stage, SharpDX.Direct3D9.TextureStage type) where T : struct
{
unsafe
{
T result = default(T);
GetTextureStageState(stage, type, (IntPtr)Interop.Fixed(ref result));
return result;
}
}
///
/// Gets the vertex shader boolean constant.
///
/// The start register.
/// The count.
/// An array of boolean constants
/// HRESULT IDirect3DDevice9::GetVertexShaderConstantB([In] unsigned int StartRegister,[In] void* pConstantData,[In] unsigned int BoolCount)
public bool[] GetVertexShaderBooleanConstant(int startRegister, int count)
{
unsafe
{
if (count < 1024)
{
var result = stackalloc int[count];
return Utilities.ConvertToBoolArray(result, count);
}
else
{
var result = new RawBool[count];
fixed (void* pResult = result)
GetVertexShaderConstantB(startRegister, (IntPtr)pResult, count);
return Utilities.ConvertToBoolArray(result);
}
}
}
///
/// Gets the vertex shader float constant.
///
/// The start register.
/// The count.
/// An array of float constants
/// HRESULT IDirect3DDevice9::GetVertexShaderConstantF([In] unsigned int StartRegister,[In, Buffer] float* pConstantData,[In] unsigned int Vector4fCount)
public float[] GetVertexShaderFloatConstant(int startRegister, int count)
{
var result = new float[count];
GetVertexShaderConstantF(startRegister, result, count);
return result;
}
///
/// Gets the vertex shader integer constant.
///
/// The start register.
/// The count.
/// An array of int constants
/// HRESULT IDirect3DDevice9::GetVertexShaderConstantI([In] unsigned int StartRegister,[Out] int* pConstantData,[In] unsigned int Vector4iCount)
public int[] GetVertexShaderIntegerConstant(int startRegister, int count)
{
var result = new int[count];
GetVertexShaderConstantI(startRegister, result, count);
return result;
}
///
/// Sets the cursor position.
///
/// The point.
/// if set to true [flags].
/// void IDirect3DDevice9::SetCursorPosition([In] int X,[In] int Y,[In] unsigned int Flags)
public void SetCursorPosition(RawPoint point, bool flags)
{
SetCursorPosition(point.X, point.Y, flags);
}
///
/// Sets the cursor position.
///
/// The x.
/// The y.
/// if set to true [flags].
/// void IDirect3DDevice9::SetCursorPosition([In] int X,[In] int Y,[In] unsigned int Flags)
public void SetCursorPosition(int x, int y, bool flags)
{
SetCursorPosition(x, y, flags?1:0);
}
///
/// Sets the cursor properties.
///
/// The point.
/// The cursor bitmap ref.
///
/// HRESULT IDirect3DDevice9::SetCursorProperties([In] unsigned int XHotSpot,[In] unsigned int YHotSpot,[In] IDirect3DSurface9* pCursorBitmap)
public void SetCursorProperties(RawPoint point, SharpDX.Direct3D9.Surface cursorBitmapRef)
{
SetCursorProperties(point.X, point.Y, cursorBitmapRef);
}
///
/// Sets the gamma ramp.
///
/// The swap chain.
/// The ramp ref.
/// if set to true [calibrate].
/// void IDirect3DDevice9::SetGammaRamp([In] unsigned int iSwapChain,[In] unsigned int Flags,[In] const D3DGAMMARAMP* pRamp)
public void SetGammaRamp(int swapChain, ref SharpDX.Direct3D9.GammaRamp rampRef, bool calibrate)
{
SetGammaRamp(swapChain, calibrate ? 1 : 0, ref rampRef);
}
///
/// Presents the contents of the next buffer in the sequence of back buffers to the screen.
///
/// A object describing the result of the operation.
/// IDirect3DDevice9::Present
public void Present()
{
Present(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
}
///
/// Presents the contents of the next buffer in the sequence of back buffers to the screen.
///
/// The area of the back buffer that should be presented.
/// The area of the front buffer that should receive the result of the presentation.
/// A object describing the result of the operation.
/// IDirect3DDevice9::Present
public void Present(RawRectangle sourceRectangle, RawRectangle destinationRectangle)
{
Present(sourceRectangle, destinationRectangle, IntPtr.Zero);
}
///
/// Presents the contents of the next buffer in the sequence of back buffers to the screen.
///
/// The area of the back buffer that should be presented.
/// The area of the front buffer that should receive the result of the presentation.
/// The destination window whose client area is taken as the target for this presentation.
/// A object describing the result of the operation.
/// IDirect3DDevice9::Present
public void Present(RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride)
{
unsafe
{
Present(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, IntPtr.Zero);
}
}
///
/// Presents the contents of the next buffer in the sequence of back buffers to the screen.
///
/// The area of the back buffer that should be presented.
/// The area of the front buffer that should receive the result of the presentation.
/// The destination window whose client area is taken as the target for this presentation.
/// Specifies a region on the back buffer that contains the minimal amount of pixels that need to be updated.
/// A object describing the result of the operation.
/// IDirect3DDevice9::Present
public void Present(RawRectangle sourceRectangle, RawRectangle destinationRectangle, IntPtr windowOverride, IntPtr dirtyRegionRGNData)
{
unsafe
{
Present(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, dirtyRegionRGNData);
}
}
///
/// Resets the stream source frequency by setting the frequency to 1.
///
/// The stream index.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetStreamSourceFreq([In] unsigned int StreamNumber,[In] unsigned int Setting)
public void ResetStreamSourceFrequency(int stream)
{
SetStreamSourceFrequency(stream, 1);
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetPixelShaderConstant(int startRegister, RawMatrix[] data)
{
unsafe
{
fixed (void* pData = data)
SetPixelShaderConstantF(startRegister, (IntPtr)pData, data.Length << 2); // *4 is enough
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetPixelShaderConstant(int startRegister, RawVector4[] data)
{
unsafe
{
fixed (void* pData = data)
SetPixelShaderConstantF(startRegister, (IntPtr)pData, data.Length); // a vector4 is only one register
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantB([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int BoolCount)
public void SetPixelShaderConstant(int startRegister, bool[] data)
{
unsafe
{
if (data.Length < 1024)
{
var result = stackalloc int[data.Length];
Utilities.ConvertToIntArray(data, result);
SetPixelShaderConstantB(startRegister, (IntPtr)result, data.Length);
}
else
{
var result = Utilities.ConvertToIntArray(data);
fixed (void* pResult = result)
SetPixelShaderConstantB(startRegister, (IntPtr)pResult, data.Length);
}
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantI([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4iCount)
public void SetPixelShaderConstant(int startRegister, int[] data)
{
unsafe
{
fixed (void* pData = data)
SetPixelShaderConstantI(startRegister, (IntPtr)pData, data.Length >> 2); // /4 as it's the count of Vector4i
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetPixelShaderConstant(int startRegister, float[] data)
{
unsafe
{
fixed (void* pData = data)
SetPixelShaderConstantF(startRegister, (IntPtr)pData, data.Length >> 2); // /4 as it's the count of Vector4f
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public unsafe void SetPixelShaderConstant(int startRegister, RawMatrix* data)
{
SetPixelShaderConstantF(startRegister, (IntPtr)data, 4); // a matrix is only 4 registers
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetPixelShaderConstant(int startRegister, RawMatrix data)
{
unsafe
{
SetPixelShaderConstantF(startRegister, new IntPtr(&data), 4); // a matrix is only 4 registers
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
/// The count.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public unsafe void SetPixelShaderConstant(int startRegister, RawMatrix* data, int count)
{
SetPixelShaderConstantF(startRegister, (IntPtr)data, count << 2); // *4 is enough as a matrix is still 4 registers
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetPixelShaderConstant(int startRegister, RawMatrix[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetPixelShaderConstantF(startRegister, (IntPtr)pData, count << 2); // *4 is enough as a matrix is still 4 registers
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetPixelShaderConstant(int startRegister, RawVector4[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetPixelShaderConstantF(startRegister, (IntPtr)pData, count); // count is enough, as a Vector4f is only one register
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantB([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int BoolCount)
public void SetPixelShaderConstant(int startRegister, bool[] data, int offset, int count)
{
unsafe
{
if (count < 1024)
{
var result = stackalloc int[data.Length];
Utilities.ConvertToIntArray(data, result);
SetPixelShaderConstantB(startRegister, new IntPtr(&result[offset]), count);
}
else
{
var result = Utilities.ConvertToIntArray(data);
fixed (void* pResult = &result[offset])
SetPixelShaderConstantB(startRegister, (IntPtr)pResult, count);
}
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantI([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4iCount)
public void SetPixelShaderConstant(int startRegister, int[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetPixelShaderConstantI(startRegister, (IntPtr) pData, count);
}
}
///
/// Sets the pixel shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetPixelShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetPixelShaderConstant(int startRegister, float[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetPixelShaderConstantF(startRegister, (IntPtr)pData, count);
}
}
///
/// Sets the RenderState.
///
/// State of the render.
/// if set to true [enable].
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetRenderState([In] D3DRENDERSTATETYPE State,[In] unsigned int Value)
public void SetRenderState(RenderState renderState, bool enable)
{
SetRenderState(renderState, enable ? 1 : 0);
}
///
/// Sets the RenderState.
///
/// State of the render.
/// A float value.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetRenderState([In] D3DRENDERSTATETYPE State,[In] unsigned int Value)
public void SetRenderState(RenderState renderState, float value)
{
unsafe
{
SetRenderState(renderState, *(int*)&value);
}
}
///
/// Sets the RenderState.
///
/// Type of the enum value
/// State of the render.
/// An enum value.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetRenderState([In] D3DRENDERSTATETYPE State,[In] unsigned int Value)
public void SetRenderState(RenderState renderState, T value) where T : struct, IConvertible
{
if (!typeof(T).GetTypeInfo().IsEnum)
throw new ArgumentException("T must be an enum type", "value");
SetRenderState(renderState, value.ToInt32(CultureInfo.InvariantCulture));
}
///
/// Sets the SamplerState.
///
/// The sampler.
/// The type.
/// The texture filter.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetSamplerState([In] unsigned int Sampler,[In] D3DSAMPLERSTATETYPE Type,[In] unsigned int Value)
public void SetSamplerState(int sampler, SharpDX.Direct3D9.SamplerState type, TextureFilter textureFilter)
{
SetSamplerState(sampler, type, (int)textureFilter);
}
///
/// Sets the SamplerState.
///
/// The sampler.
/// The type.
/// The texture address.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetSamplerState([In] unsigned int Sampler,[In] D3DSAMPLERSTATETYPE Type,[In] unsigned int Value)
public void SetSamplerState(int sampler, SharpDX.Direct3D9.SamplerState type, TextureAddress textureAddress)
{
SetSamplerState(sampler, type, (int)textureAddress);
}
///
/// Sets the SamplerState.
///
/// The sampler.
/// The type.
/// A float value.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetSamplerState([In] unsigned int Sampler,[In] D3DSAMPLERSTATETYPE Type,[In] unsigned int Value)
public void SetSamplerState(int sampler, SharpDX.Direct3D9.SamplerState type, float value)
{
unsafe
{
SetSamplerState(sampler, type, *(int*)&value);
}
}
///
/// Sets the stream source frequency.
///
/// The stream.
/// The frequency.
/// The source.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetStreamSourceFreq([In] unsigned int StreamNumber,[In] unsigned int Setting)
public void SetStreamSourceFrequency(int stream, int frequency, StreamSource source)
{
int value = (source == StreamSource.IndexedData) ? 0x40000000 : unchecked((int)0x80000000);
SetStreamSourceFrequency(stream, frequency | value);
}
///
/// Sets the state of the texture stage.
///
/// The stage.
/// The type.
/// The texture argument.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetTextureStageState([In] unsigned int Stage,[In] D3DTEXTURESTAGESTATETYPE Type,[In] unsigned int Value)
public void SetTextureStageState(int stage, TextureStage type, TextureArgument textureArgument)
{
SetTextureStageState(stage, type, (int)textureArgument);
}
///
/// Sets the state of the texture stage.
///
/// The stage.
/// The type.
/// The texture operation.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetTextureStageState([In] unsigned int Stage,[In] D3DTEXTURESTAGESTATETYPE Type,[In] unsigned int Value)
public void SetTextureStageState(int stage, TextureStage type, TextureOperation textureOperation)
{
SetTextureStageState(stage, type, (int)textureOperation);
}
///
/// Sets the state of the texture stage.
///
/// The stage.
/// The type.
/// The texture transform.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetTextureStageState([In] unsigned int Stage,[In] D3DTEXTURESTAGESTATETYPE Type,[In] unsigned int Value)
public void SetTextureStageState(int stage, TextureStage type, TextureTransform textureTransform)
{
SetTextureStageState(stage, type, (int)textureTransform);
}
///
/// Sets the state of the texture stage.
///
/// The stage.
/// The type.
/// The value.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetTextureStageState([In] unsigned int Stage,[In] D3DTEXTURESTAGESTATETYPE Type,[In] unsigned int Value)
public void SetTextureStageState(int stage, TextureStage type, float value)
{
unsafe
{
SetTextureStageState(stage, type, *(int*)&value);
}
}
///
/// Sets the transform.
///
/// The state.
/// The matrix ref.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetTransform([In] D3DTRANSFORMSTATETYPE State,[In] const D3DMATRIX* pMatrix)
public void SetTransform(SharpDX.Direct3D9.TransformState state, ref RawMatrix matrixRef)
{
SetTransform_((int)state, ref matrixRef);
}
///
/// Sets the transform.
///
/// The index.
/// The matrix ref.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetTransform([In] D3DTRANSFORMSTATETYPE State,[In] const D3DMATRIX* pMatrix)
public void SetTransform(int index, ref RawMatrix matrixRef)
{
SetTransform_(index + 256, ref matrixRef);
}
///
/// Sets the transform.
///
/// The state.
/// The matrix ref.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetTransform([In] D3DTRANSFORMSTATETYPE State,[In] const D3DMATRIX* pMatrix)
public void SetTransform(SharpDX.Direct3D9.TransformState state, RawMatrix matrixRef)
{
SetTransform_((int)state, ref matrixRef);
}
///
/// Sets the transform.
///
/// The index.
/// The matrix ref.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetTransform([In] D3DTRANSFORMSTATETYPE State,[In] const D3DMATRIX* pMatrix)
public void SetTransform(int index, RawMatrix matrixRef)
{
SetTransform_(index + 256, ref matrixRef);
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetVertexShaderConstant(int startRegister, RawMatrix[] data)
{
unsafe
{
fixed (void* pData = data)
SetVertexShaderConstantF(startRegister, (IntPtr)pData, data.Length << 2);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetVertexShaderConstant(int startRegister, RawVector4[] data)
{
unsafe
{
fixed (void* pData = data)
SetVertexShaderConstantF(startRegister, (IntPtr)pData, data.Length >> 2);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantB([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int BoolCount)
public void SetVertexShaderConstant(int startRegister, bool[] data)
{
unsafe
{
if (data.Length < 1024)
{
var result = stackalloc int[data.Length];
Utilities.ConvertToIntArray(data, result);
SetVertexShaderConstantB(startRegister, (IntPtr)result, data.Length);
}
else
{
var result = Utilities.ConvertToIntArray(data);
fixed (void* pResult = result)
SetVertexShaderConstantB(startRegister, (IntPtr)pResult, data.Length);
}
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantI([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4iCount)
public void SetVertexShaderConstant(int startRegister, int[] data)
{
unsafe
{
fixed (void* pData = data)
SetVertexShaderConstantI(startRegister, (IntPtr)pData, data.Length >> 2);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetVertexShaderConstant(int startRegister, float[] data)
{
unsafe
{
fixed (void* pData = data)
SetVertexShaderConstantF(startRegister, (IntPtr)pData, data.Length >> 2);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public unsafe void SetVertexShaderConstant(int startRegister, RawMatrix* data)
{
SetVertexShaderConstantF(startRegister, (IntPtr)data, 4);
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetVertexShaderConstant(int startRegister, RawMatrix data)
{
unsafe
{
SetVertexShaderConstantF(startRegister, new IntPtr(&data), 4);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
/// The count.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public unsafe void SetVertexShaderConstant(int startRegister, RawMatrix* data, int count)
{
SetVertexShaderConstantF(startRegister, (IntPtr)data, count << 2);
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetVertexShaderConstant(int startRegister, RawMatrix[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetVertexShaderConstantF(startRegister, (IntPtr)pData, count << 2);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetVertexShaderConstant(int startRegister, RawVector4[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetVertexShaderConstantF(startRegister, (IntPtr)pData, count >> 2);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantB([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int BoolCount)
public void SetVertexShaderConstant(int startRegister, bool[] data, int offset, int count)
{
unsafe
{
if (count < 1024)
{
var result = stackalloc int[data.Length];
Utilities.ConvertToIntArray(data, result);
SetVertexShaderConstantB(startRegister, new IntPtr(&result[offset]), count);
}
else
{
var result = Utilities.ConvertToIntArray(data);
fixed (void* pResult = &result[offset])
SetVertexShaderConstantB(startRegister, (IntPtr)pResult, count);
}
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantI([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4iCount)
public void SetVertexShaderConstant(int startRegister, int[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetVertexShaderConstantI(startRegister, (IntPtr)pData, count);
}
}
///
/// Sets the vertex shader constant.
///
/// The start register.
/// The data.
/// The offset.
/// The count.
/// A object describing the result of the operation.
/// HRESULT IDirect3DDevice9::SetVertexShaderConstantF([In] unsigned int StartRegister,[In] const void* pConstantData,[In] unsigned int Vector4fCount)
public void SetVertexShaderConstant(int startRegister, float[] data, int offset, int count)
{
unsafe
{
fixed (void* pData = &data[offset])
SetVertexShaderConstantF(startRegister, (IntPtr)pData, count);
}
}
///
/// Stretches the rectangle.
///
/// The source surface ref.
/// The dest surface ref.
/// The filter.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::StretchRect([In] IDirect3DSurface9* pSourceSurface,[In, Optional] const RECT* pSourceRect,[In] IDirect3DSurface9* pDestSurface,[In, Optional] const RECT* pDestRect,[In] D3DTEXTUREFILTERTYPE Filter)
public void StretchRectangle(SharpDX.Direct3D9.Surface sourceSurfaceRef, SharpDX.Direct3D9.Surface destSurfaceRef, SharpDX.Direct3D9.TextureFilter filter)
{
StretchRectangle(sourceSurfaceRef, null, destSurfaceRef, null, filter);
}
///
/// Gets or sets a value indicating whether the cursor can be displayed.
///
///
/// true if the cursor can be displayed; otherwise, false.
///
public bool ShowCursor
{
get
{
bool previousValue = GetSetShowCursor(true);
GetSetShowCursor(previousValue);
return previousValue;
}
set
{
GetSetShowCursor(value);
}
}
///
/// Updates the surface.
///
/// The source surface ref.
/// The destination surface ref.
///
/// A object describing the result of the operation.
///
/// HRESULT IDirect3DDevice9::UpdateSurface([In] IDirect3DSurface9* pSourceSurface,[In] const RECT* pSourceRect,[In] IDirect3DSurface9* pDestinationSurface,[In] const POINT* pDestPoint)
public void UpdateSurface(SharpDX.Direct3D9.Surface sourceSurfaceRef, SharpDX.Direct3D9.Surface destinationSurfaceRef)
{
UpdateSurface(sourceSurfaceRef, null, destinationSurfaceRef, null);
}
}
}