3 * Copyright (c) 2007-2010 SlimDX Group
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 * of this software and associated documentation files (the "Software"), to deal
\r
7 * in the Software without restriction, including without limitation the rights
\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 * copies of the Software, and to permit persons to whom the Software is
\r
10 * furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
23 #include <windows.h>
\r
27 #include "../stack_array.h"
\r
28 #include "../DataStream.h"
\r
29 #include "../ComObject.h"
\r
30 #include "../Utilities.h"
\r
32 #include "Direct3D9Exception.h"
\r
35 #include "Direct3D.h"
\r
36 #include "PresentParameters.h"
\r
37 #include "VertexBuffer.h"
\r
38 #include "IndexBuffer.h"
\r
39 #include "Texture.h"
\r
40 #include "PixelShader9.h"
\r
41 #include "VertexShader9.h"
\r
43 #include "SwapChain.h"
\r
44 #include "StateBlock.h"
\r
47 using namespace System;
\r
48 using namespace System::Collections::Generic;
\r
49 using namespace System::Drawing;
\r
50 using namespace System::Runtime::InteropServices;
\r
51 using namespace System::Windows::Forms;
\r
59 // this is called by DeviceEx
\r
62 Device::Device( SlimDX::Direct3D9::Direct3D^ direct3D, int adapter, DeviceType deviceType, IntPtr controlHandle, CreateFlags createFlags, ... array<PresentParameters^>^ presentParameters )
\r
64 IDirect3DDevice9* device;
\r
65 stack_array<D3DPRESENT_PARAMETERS> d3dpp = stackalloc( D3DPRESENT_PARAMETERS, presentParameters->Length );
\r
67 for( int p = 0; p < presentParameters->Length; ++p )
\r
68 d3dpp[p] = presentParameters[p]->ToUnmanaged();
\r
70 HRESULT hr = direct3D->InternalPointer->CreateDevice( adapter,
\r
71 static_cast<D3DDEVTYPE>( deviceType ),
\r
72 static_cast<HWND>( controlHandle.ToPointer() ),
\r
73 static_cast<DWORD>( createFlags ),
\r
74 reinterpret_cast<D3DPRESENT_PARAMETERS*>( &d3dpp[0] ),
\r
77 if( RECORD_D3D9( hr ).IsFailure )
\r
78 throw gcnew Direct3D9Exception( Result::Last );
\r
80 for( int p = 0; p < presentParameters->Length; ++p )
\r
82 presentParameters[p]->BackBufferCount = d3dpp[p].BackBufferCount;
\r
83 presentParameters[p]->BackBufferFormat = static_cast<Format>( d3dpp[p].BackBufferFormat );
\r
84 presentParameters[p]->BackBufferWidth = d3dpp[p].BackBufferWidth;
\r
85 presentParameters[p]->BackBufferHeight = d3dpp[p].BackBufferHeight;
\r
91 void Device::VertexFormat::set( SlimDX::Direct3D9::VertexFormat value )
\r
93 HRESULT hr = InternalPointer->SetFVF( static_cast<DWORD>( value ) );
\r
97 SlimDX::Direct3D9::VertexFormat Device::VertexFormat::get()
\r
100 HRESULT hr = InternalPointer->GetFVF( &fvf );
\r
103 return static_cast<SlimDX::Direct3D9::VertexFormat>( fvf );
\r
106 void Device::VertexDeclaration::set( SlimDX::Direct3D9::VertexDeclaration^ value )
\r
109 if( value != nullptr )
\r
110 hr = InternalPointer->SetVertexDeclaration( value->InternalPointer );
\r
112 hr = InternalPointer->SetVertexDeclaration( NULL );
\r
117 SlimDX::Direct3D9::VertexDeclaration^ Device::VertexDeclaration::get()
\r
119 IDirect3DVertexDeclaration9* decl;
\r
120 HRESULT hr = InternalPointer->GetVertexDeclaration( &decl );
\r
122 if( RECORD_D3D9( hr ).IsFailure )
\r
125 return SlimDX::Direct3D9::VertexDeclaration::FromPointer( decl );
\r
128 Result Device::DrawPrimitives( PrimitiveType primitiveType, int startIndex, int primitiveCount )
\r
130 HRESULT hr = InternalPointer->DrawPrimitive( static_cast<D3DPRIMITIVETYPE>( primitiveType ), startIndex, primitiveCount );
\r
131 return RECORD_D3D9( hr );
\r
134 generic<typename T>
\r
135 Result Device::DrawUserPrimitives( PrimitiveType primitiveType, int primitiveCount, array<T>^ data )
\r
137 return DrawUserPrimitives<T>( primitiveType, 0, primitiveCount, data );
\r
140 // disables bogus warning:
\r
141 //SlimDX::Direct3D9::Device::DrawIndexedUserPrimitives<T>' : recursive on
\r
142 // all control paths, function will cause runtime stack overflow
\r
143 #pragma warning(disable:4717)
\r
144 generic<typename T>
\r
145 Result Device::DrawUserPrimitives( PrimitiveType primitiveType, int startIndex, int primitiveCount, array<T>^ data )
\r
147 pin_ptr<T> pinned_data = &data[startIndex];
\r
149 HRESULT hr = InternalPointer->DrawPrimitiveUP( static_cast<D3DPRIMITIVETYPE>( primitiveType ), primitiveCount,
\r
150 pinned_data, static_cast<DWORD>( sizeof(T) ) );
\r
151 return RECORD_D3D9( hr );
\r
153 #pragma warning(default:4717)
\r
155 Result Device::DrawIndexedPrimitives( PrimitiveType primitiveType, int baseVertexIndex, int minVertexIndex,
\r
156 int numVertices, int startIndex, int primCount )
\r
158 HRESULT hr = InternalPointer->DrawIndexedPrimitive( static_cast<D3DPRIMITIVETYPE>( primitiveType ), baseVertexIndex,
\r
159 minVertexIndex, numVertices, startIndex, primCount );
\r
160 return RECORD_D3D9( hr );
\r
163 generic<typename S, typename T>
\r
164 Result Device::DrawIndexedUserPrimitives( PrimitiveType primitiveType, int minVertexIndex, int numVertices, int primitiveCount,
\r
165 array<S>^ indexData, Format indexDataFormat, array<T>^ vertexData, int vertexStride )
\r
167 return DrawIndexedUserPrimitives<S,T>( primitiveType, 0, 0, minVertexIndex, numVertices, primitiveCount, indexData, indexDataFormat, vertexData, vertexStride );
\r
170 generic<typename S, typename T>
\r
171 Result Device::DrawIndexedUserPrimitives( PrimitiveType primitiveType, int startIndex, int minVertexIndex, int numVertices, int primitiveCount,
\r
172 array<S>^ indexData, Format indexDataFormat, array<T>^ vertexData, int vertexStride )
\r
174 return DrawIndexedUserPrimitives<S,T>( primitiveType, startIndex, 0, minVertexIndex, numVertices, primitiveCount, indexData, indexDataFormat, vertexData, vertexStride );
\r
177 // disables bogus warning: 'SlimDX::Direct3D9::Device::DrawIndexedUserPrimitives<S,T>' : recursive on all control paths,
\r
178 // function will cause runtime stack overflow
\r
179 #pragma warning(disable:4717)
\r
180 generic<typename S, typename T>
\r
181 Result Device::DrawIndexedUserPrimitives( PrimitiveType primitiveType, int startIndex, int startVertex, int minVertexIndex, int numVertices, int primitiveCount,
\r
182 array<S>^ indexData, Format indexDataFormat, array<T>^ vertexData, int vertexStride )
\r
184 pin_ptr<S> pinnedIndices = &indexData[startIndex];
\r
185 pin_ptr<T> pinnedVertices = &vertexData[startVertex];
\r
187 HRESULT hr = InternalPointer->DrawIndexedPrimitiveUP( static_cast<D3DPRIMITIVETYPE>( primitiveType ), minVertexIndex, numVertices,
\r
188 primitiveCount, pinnedIndices, static_cast<D3DFORMAT>( indexDataFormat ), pinnedVertices, vertexStride );
\r
189 return RECORD_D3D9( hr );
\r
191 #pragma warning(default:4717)
\r
193 Result Device::Clear( ClearFlags clearFlags, Color4 color, float zdepth, int stencil, array<System::Drawing::Rectangle>^ rectangles )
\r
195 return Clear( clearFlags, color.ToArgb(), zdepth, stencil, rectangles );
\r
198 Result Device::Clear( ClearFlags clearFlags, int color, float zdepth, int stencil, array<System::Drawing::Rectangle>^ rectangles )
\r
200 if( rectangles == nullptr )
\r
202 return Clear( clearFlags, color, zdepth, stencil );
\r
205 stack_array<D3DRECT> rects = stackalloc( D3DRECT, rectangles->Length );
\r
206 for( int i = 0; i < rectangles->Length; i++ )
\r
209 rect.x1 = rectangles[i].Left;
\r
210 rect.y1 = rectangles[i].Top;
\r
211 rect.x2 = rectangles[i].Right;
\r
212 rect.y2 = rectangles[i].Bottom;
\r
217 HRESULT hr = InternalPointer->Clear( rectangles->Length, &rects[0], static_cast<DWORD>( clearFlags ), static_cast<D3DCOLOR>( color ), zdepth, stencil );
\r
218 return RECORD_D3D9( hr );
\r
221 Result Device::Clear( ClearFlags clearFlags, Color4 color, float zdepth, int stencil )
\r
223 return Clear( clearFlags, color.ToArgb(), zdepth, stencil );
\r
226 Result Device::Clear( ClearFlags clearFlags, int color, float zdepth, int stencil )
\r
228 HRESULT hr = InternalPointer->Clear( 0, 0, static_cast<DWORD>( clearFlags ), static_cast<D3DCOLOR>( color ), zdepth, stencil );
\r
229 return RECORD_D3D9( hr );
\r
232 Result Device::BeginScene()
\r
234 HRESULT hr = InternalPointer->BeginScene();
\r
235 return RECORD_D3D9( hr );
\r
238 Result Device::EndScene()
\r
240 HRESULT hr = InternalPointer->EndScene();
\r
241 return RECORD_D3D9( hr );
\r
244 Result Device::Present()
\r
246 HRESULT hr = InternalPointer->Present( 0, 0, 0, 0 );
\r
247 return RECORD_D3D9( hr );
\r
250 Result Device::Present( SlimDX::Direct3D9::Present flags )
\r
252 IDirect3DSwapChain9* swapChain;
\r
254 HRESULT hr = InternalPointer->GetSwapChain( 0, &swapChain );
\r
256 if( RECORD_D3D9( hr ).IsFailure )
\r
257 return Result::Last;
\r
259 hr = swapChain->Present( 0, 0, 0, 0, static_cast<DWORD>( flags ) );
\r
262 hr = swapChain->Release();
\r
265 return Result::Last;
\r
268 Result Device::Present( System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle )
\r
270 RECT nativeSourceRect = { sourceRectangle.Left, sourceRectangle.Top, sourceRectangle.Right, sourceRectangle.Bottom };
\r
271 RECT nativeDestRect = { destinationRectangle.Left, destinationRectangle.Top, destinationRectangle.Right, destinationRectangle.Bottom };
\r
273 RECT *sourcePtr = NULL;
\r
274 RECT *destPtr = NULL;
\r
276 if( sourceRectangle != Rectangle::Empty )
\r
277 sourcePtr = &nativeSourceRect;
\r
278 if( destinationRectangle != Rectangle::Empty )
\r
279 destPtr = &nativeDestRect;
\r
281 HRESULT hr = InternalPointer->Present( sourcePtr, destPtr, NULL, NULL );
\r
283 return RECORD_D3D9( hr );
\r
286 Result Device::Present( System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle, System::IntPtr windowOverride )
\r
288 RECT nativeSourceRect = { sourceRectangle.Left, sourceRectangle.Top, sourceRectangle.Right, sourceRectangle.Bottom };
\r
289 RECT nativeDestRect = { destinationRectangle.Left, destinationRectangle.Top, destinationRectangle.Right, destinationRectangle.Bottom };
\r
291 RECT *sourcePtr = NULL;
\r
292 RECT *destPtr = NULL;
\r
294 if( sourceRectangle != Rectangle::Empty )
\r
295 sourcePtr = &nativeSourceRect;
\r
296 if( destinationRectangle != Rectangle::Empty )
\r
297 destPtr = &nativeDestRect;
\r
299 HRESULT hr = InternalPointer->Present( sourcePtr, destPtr, static_cast<HWND>( windowOverride.ToPointer() ), NULL );
\r
301 return RECORD_D3D9( hr );
\r
304 Result Device::Present( System::Drawing::Rectangle sourceRectangle, System::Drawing::Rectangle destinationRectangle, System::IntPtr windowOverride, System::Drawing::Region^ region )
\r
306 RECT nativeSourceRect = { sourceRectangle.Left, sourceRectangle.Top, sourceRectangle.Right, sourceRectangle.Bottom };
\r
307 RECT nativeDestRect = { destinationRectangle.Left, destinationRectangle.Top, destinationRectangle.Right, destinationRectangle.Bottom };
\r
309 RGNDATA nativeRegion;
\r
310 Graphics^ graphics = Graphics::FromHwnd( windowOverride );
\r
311 int count = GetRegionData( static_cast<HRGN>( region->GetHrgn(graphics).ToPointer() ), 0, NULL );
\r
312 GetRegionData( static_cast<HRGN>( region->GetHrgn(graphics).ToPointer() ), count, &nativeRegion );
\r
315 RECT *sourcePtr = NULL;
\r
316 RECT *destPtr = NULL;
\r
318 if( sourceRectangle != Rectangle::Empty )
\r
319 sourcePtr = &nativeSourceRect;
\r
320 if( destinationRectangle != Rectangle::Empty )
\r
321 destPtr = &nativeDestRect;
\r
323 HRESULT hr = InternalPointer->Present( sourcePtr, destPtr, static_cast<HWND>( windowOverride.ToPointer() ), &nativeRegion );
\r
325 return RECORD_D3D9( hr );
\r
328 RasterStatus Device::GetRasterStatus( int swapChain )
\r
330 D3DRASTER_STATUS status;
\r
331 HRESULT hr = InternalPointer->GetRasterStatus( swapChain, &status );
\r
333 if( RECORD_D3D9( hr ).IsFailure )
\r
334 return SlimDX::Direct3D9::RasterStatus();
\r
336 SlimDX::Direct3D9::RasterStatus result;
\r
337 result.InVBlank = status.InVBlank > 0;
\r
338 result.Scanline = status.ScanLine;
\r
342 Result Device::SetRenderState( RenderState state, int value )
\r
344 HRESULT hr = InternalPointer->SetRenderState( static_cast<D3DRENDERSTATETYPE>( state ), value );
\r
345 return RECORD_D3D9( hr );
\r
348 Result Device::SetRenderState( RenderState state, bool value )
\r
350 BOOL boolValue = value ? TRUE : FALSE;
\r
351 HRESULT hr = InternalPointer->SetRenderState( static_cast<D3DRENDERSTATETYPE>( state ), boolValue );
\r
352 return RECORD_D3D9( hr );
\r
355 Result Device::SetRenderState( RenderState state, float value )
\r
357 DWORD* dwValue = reinterpret_cast<DWORD*>( &value );
\r
358 HRESULT hr = InternalPointer->SetRenderState( static_cast<D3DRENDERSTATETYPE>( state ), *dwValue );
\r
359 return RECORD_D3D9( hr );
\r
362 generic<typename T>
\r
363 Result Device::SetRenderState( RenderState state, T value )
\r
365 return SetRenderState( state, static_cast<int>( value ) );
\r
368 Result Device::SetTextureStageState( int stage, TextureStage type, int value )
\r
370 HRESULT hr = InternalPointer->SetTextureStageState( stage, static_cast<D3DTEXTURESTAGESTATETYPE>( type ), value );
\r
371 return RECORD_D3D9( hr );
\r
374 Result Device::SetTextureStageState( int stage, TextureStage type, TextureOperation texOp )
\r
376 return SetTextureStageState( stage, type, static_cast<int>( texOp ) );
\r
379 Result Device::SetTextureStageState( int stage, TextureStage type, TextureArgument texArg )
\r
381 return SetTextureStageState( stage, type, static_cast<int>( texArg ) );
\r
384 Result Device::SetTextureStageState( int stage, TextureStage type, TextureTransform texTransform )
\r
386 return SetTextureStageState( stage, type, static_cast<int>( texTransform ) );
\r
389 Result Device::SetTextureStageState( int stage, TextureStage type, float value )
\r
391 int* dwValue = reinterpret_cast<int*>( &value );
\r
392 return SetTextureStageState( stage, type, *dwValue );
\r
395 Result Device::SetSamplerState( int sampler, SamplerState type, int value )
\r
397 HRESULT hr = InternalPointer->SetSamplerState( sampler, static_cast<D3DSAMPLERSTATETYPE>( type ), value );
\r
398 return RECORD_D3D9( hr );
\r
401 Result Device::SetSamplerState( int sampler, SamplerState type, float value )
\r
403 DWORD* dwValue = reinterpret_cast<DWORD*>( &value );
\r
404 HRESULT hr = InternalPointer->SetSamplerState( sampler, static_cast<D3DSAMPLERSTATETYPE>( type ), *dwValue );
\r
405 return RECORD_D3D9( hr );
\r
408 Result Device::SetSamplerState( int sampler, SamplerState type, TextureAddress textureAddress )
\r
410 return SetSamplerState( sampler, type, static_cast<int>( textureAddress ) );
\r
413 Result Device::SetSamplerState( int sampler, SamplerState type, TextureFilter texFilter )
\r
415 return SetSamplerState( sampler, type, static_cast<int>( texFilter ) );
\r
418 Result Device::SetTransform( TransformState state, Matrix* value )
\r
420 HRESULT hr = InternalPointer->SetTransform( static_cast<D3DTRANSFORMSTATETYPE>( state ), reinterpret_cast<const D3DMATRIX*>( value ) );
\r
421 return RECORD_D3D9( hr );
\r
424 Result Device::SetTransform( TransformState state, Matrix value )
\r
426 HRESULT hr = InternalPointer->SetTransform( static_cast<D3DTRANSFORMSTATETYPE>( state ), reinterpret_cast<const D3DMATRIX*>( &value ) );
\r
427 return RECORD_D3D9( hr );
\r
430 Matrix Device::GetTransform( TransformState state )
\r
433 HRESULT hr = InternalPointer->GetTransform( static_cast<D3DTRANSFORMSTATETYPE>( state ), reinterpret_cast<D3DMATRIX*>( &result ) );
\r
438 Result Device::SetTransform( int index, Matrix* value )
\r
440 return SetTransform( static_cast<TransformState>( index + 256 ), value );
\r
443 Result Device::SetTransform( int index, Matrix value )
\r
445 return SetTransform( static_cast<TransformState>( index + 256 ), value );
\r
448 Matrix Device::GetTransform( int index )
\r
450 return GetTransform( static_cast<TransformState>( index + 256 ) );
\r
453 Result Device::MultiplyTransform( TransformState state, Matrix value )
\r
455 HRESULT hr = InternalPointer->MultiplyTransform( static_cast<D3DTRANSFORMSTATETYPE>( state ), reinterpret_cast<const D3DMATRIX*>( &value ) );
\r
456 return RECORD_D3D9( hr );
\r
459 Result Device::SetStreamSource( int stream, VertexBuffer^ streamData, int offsetInBytes, int stride )
\r
461 IDirect3DVertexBuffer9* vbPointer = streamData != nullptr ? streamData->InternalPointer : NULL;
\r
462 HRESULT hr = InternalPointer->SetStreamSource( stream, vbPointer, offsetInBytes, stride );
\r
463 return RECORD_D3D9( hr );
\r
466 Result Device::SetStreamSourceFrequency( int stream, int frequency, StreamSource source )
\r
469 if( source == StreamSource::IndexedData )
\r
470 value = D3DSTREAMSOURCE_INDEXEDDATA;
\r
472 value = D3DSTREAMSOURCE_INSTANCEDATA;
\r
474 HRESULT hr = InternalPointer->SetStreamSourceFreq( stream, value | frequency );
\r
475 return RECORD_D3D9( hr );
\r
478 Result Device::ResetStreamSourceFrequency( int stream )
\r
480 HRESULT hr = InternalPointer->SetStreamSourceFreq( stream, 1 );
\r
481 return RECORD_D3D9( hr );
\r
484 SlimDX::Direct3D9::Material Device::Material::get()
\r
486 SlimDX::Direct3D9::Material material;
\r
488 HRESULT hr = InternalPointer->GetMaterial( reinterpret_cast<D3DMATERIAL9*>( &material ) );
\r
494 void Device::Material::set( SlimDX::Direct3D9::Material material )
\r
496 HRESULT hr = InternalPointer->SetMaterial( reinterpret_cast<const D3DMATERIAL9*>( &material ) );
\r
500 Result Device::TestCooperativeLevel()
\r
502 HRESULT hr = InternalPointer->TestCooperativeLevel();
\r
503 return Result( hr );
\r
506 Result Device::Reset( PresentParameters^ presentParameters )
\r
508 D3DPRESENT_PARAMETERS d3dpp;
\r
510 d3dpp = presentParameters->ToUnmanaged();
\r
511 HRESULT hr = InternalPointer->Reset( &d3dpp );
\r
514 presentParameters->BackBufferCount = d3dpp.BackBufferCount;
\r
515 presentParameters->BackBufferFormat = static_cast<Format>( d3dpp.BackBufferFormat );
\r
516 presentParameters->BackBufferWidth = d3dpp.BackBufferWidth;
\r
517 presentParameters->BackBufferHeight = d3dpp.BackBufferHeight;
\r
519 return Result::Last;
\r
522 Result Device::SetTexture( int sampler, BaseTexture^ texture )
\r
524 IDirect3DBaseTexture9* texturePointer = texture != nullptr ? texture->InternalPointer : NULL;
\r
525 HRESULT hr = InternalPointer->SetTexture( sampler, texturePointer );
\r
526 return RECORD_D3D9( hr );
\r
529 BaseTexture^ Device::GetTexture( int stage )
\r
531 IDirect3DBaseTexture9 *texture;
\r
532 HRESULT hr = InternalPointer->GetTexture( stage, &texture );
\r
533 if( RECORD_D3D9( hr ).IsFailure )
\r
536 return BaseTexture::FromUnmanaged( texture );
\r
539 Result Device::SetRenderTarget( int rtIndex, Surface^ target )
\r
541 IDirect3DSurface9* surfacePointer = target != nullptr ? target->InternalPointer : NULL;
\r
542 HRESULT hr = InternalPointer->SetRenderTarget( rtIndex, surfacePointer );
\r
543 return RECORD_D3D9( hr );
\r
546 void Device::PixelShader::set( SlimDX::Direct3D9::PixelShader^ shader )
\r
548 IDirect3DPixelShader9 *ptr = shader != nullptr ? shader->InternalPointer : NULL;
\r
549 HRESULT hr = InternalPointer->SetPixelShader( ptr );
\r
553 void Device::VertexShader::set( SlimDX::Direct3D9::VertexShader^ shader )
\r
555 IDirect3DVertexShader9 *ptr = shader != nullptr ? shader->InternalPointer : NULL;
\r
556 HRESULT hr = InternalPointer->SetVertexShader( ptr );
\r
560 void Device::DepthStencilSurface::set( Surface^ target )
\r
562 IDirect3DSurface9* surface = target != nullptr ? target->InternalPointer : NULL;
\r
563 HRESULT hr = InternalPointer->SetDepthStencilSurface( surface );
\r
567 Surface^ Device::GetBackBuffer( int swapChain, int backBuffer )
\r
569 IDirect3DSurface9* buffer;
\r
571 HRESULT hr = InternalPointer->GetBackBuffer( swapChain, backBuffer, D3DBACKBUFFER_TYPE_MONO, &buffer );
\r
573 if( RECORD_D3D9( hr ).IsFailure )
\r
576 return Surface::FromPointer( buffer );
\r
579 bool Device::IsQuerySupported( QueryType type )
\r
581 HRESULT hr = InternalPointer->CreateQuery( static_cast<D3DQUERYTYPE>( type ), NULL );
\r
582 if( hr == D3DERR_NOTAVAILABLE )
\r
585 if( RECORD_D3D9( hr ).IsFailure )
\r
591 Capabilities^ Device::Capabilities::get()
\r
594 HRESULT hr = InternalPointer->GetDeviceCaps( &caps );
\r
597 return gcnew SlimDX::Direct3D9::Capabilities( caps );
\r
600 System::Int64 Device::AvailableTextureMemory::get()
\r
602 return InternalPointer->GetAvailableTextureMem();
\r
605 int Device::ValidateDevice()
\r
607 DWORD passCount = 0;
\r
609 HRESULT hr = InternalPointer->ValidateDevice( &passCount );
\r
615 bool Device::ShowCursor::get()
\r
617 BOOL prev = InternalPointer->ShowCursor( true );
\r
618 RECORD_D3D9( InternalPointer->ShowCursor( prev ) );
\r
623 void Device::ShowCursor::set( bool value )
\r
625 RECORD_D3D9( InternalPointer->ShowCursor( value ) );
\r
628 bool Device::SoftwareVertexProcessing::get()
\r
630 return InternalPointer->GetSoftwareVertexProcessing() > 0;
\r
633 void Device::SoftwareVertexProcessing::set( bool value )
\r
635 HRESULT hr = InternalPointer->SetSoftwareVertexProcessing( value );
\r
639 Surface^ Device::DepthStencilSurface::get()
\r
641 IDirect3DSurface9* surface;
\r
643 HRESULT hr = InternalPointer->GetDepthStencilSurface( &surface );
\r
645 if( RECORD_D3D9( hr ).IsFailure )
\r
648 return Surface::FromPointer( surface );
\r
651 SlimDX::Direct3D9::Viewport Device::Viewport::get()
\r
653 SlimDX::Direct3D9::Viewport viewport;
\r
654 HRESULT hr = InternalPointer->GetViewport( reinterpret_cast<D3DVIEWPORT9*>( &viewport ) );
\r
660 void Device::Viewport::set( SlimDX::Direct3D9::Viewport value )
\r
662 HRESULT hr = InternalPointer->SetViewport( reinterpret_cast<const D3DVIEWPORT9*>( &value ) );
\r
666 void Device::ScissorRect::set(Drawing::Rectangle rect)
\r
668 RECT scissorRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };
\r
669 HRESULT hr = InternalPointer->SetScissorRect(&scissorRect);
\r
673 Drawing::Rectangle Device::ScissorRect::get()
\r
675 RECT scissorRect; // Scissor rectangle.
\r
677 HRESULT hr = InternalPointer->GetScissorRect(&scissorRect);
\r
680 return Utilities::ConvertRect(scissorRect);
\r
683 Surface^ Device::GetRenderTarget( int index )
\r
685 IDirect3DSurface9* surface;
\r
687 HRESULT hr = InternalPointer->GetRenderTarget( index, &surface );
\r
689 if( RECORD_D3D9( hr ).IsFailure )
\r
692 return Surface::FromPointer( surface );
\r
695 generic<typename T>
\r
696 T Device::GetRenderState( RenderState state )
\r
699 HRESULT hr = InternalPointer->GetRenderState( static_cast<D3DRENDERSTATETYPE>( state ), &value );
\r
702 return Utilities::FromIntToT<T>( value );
\r
705 int Device::GetRenderState( RenderState state )
\r
708 HRESULT hr = InternalPointer->GetRenderState( static_cast<D3DRENDERSTATETYPE>( state ), &value );
\r
714 generic<typename T>
\r
715 T Device::GetSamplerState( int sampler, SamplerState type )
\r
718 HRESULT hr = InternalPointer->GetSamplerState( sampler, static_cast<D3DSAMPLERSTATETYPE>( type ), &value );
\r
721 return Utilities::FromIntToT<T>( value );
\r
724 int Device::GetSamplerState( int sampler, SamplerState type )
\r
727 HRESULT hr = InternalPointer->GetSamplerState( sampler, static_cast<D3DSAMPLERSTATETYPE>( type ), &value );
\r
733 generic<typename T>
\r
734 T Device::GetTextureStageState( int stage, TextureStage type )
\r
737 HRESULT hr = InternalPointer->GetTextureStageState( stage, static_cast<D3DTEXTURESTAGESTATETYPE>( type ), &value );
\r
740 return Utilities::FromIntToT<T>( value );
\r
743 int Device::GetTextureStageState( int stage, TextureStage type )
\r
746 HRESULT hr = InternalPointer->GetTextureStageState( stage, static_cast<D3DTEXTURESTAGESTATETYPE>( type ), &value );
\r
752 array<PaletteEntry>^ Device::GetPaletteEntries( int paletteNumber )
\r
754 array<PaletteEntry>^ result = gcnew array<PaletteEntry>( 256 );
\r
755 pin_ptr<PaletteEntry> pinnedResult = &result[0];
\r
757 HRESULT hr = InternalPointer->GetPaletteEntries( paletteNumber, reinterpret_cast<PALETTEENTRY*>( pinnedResult ) );
\r
759 if( RECORD_D3D9( hr ).IsFailure )
\r
765 Result Device::SetPaletteEntries( int paletteNumber, array<PaletteEntry>^ entries )
\r
767 if( entries != nullptr && entries->Length != 256 )
\r
768 throw gcnew ArgumentException( "Palettes must have exactly 256 entries.", "entries" );
\r
770 pin_ptr<PaletteEntry> pinnedEntries = entries == nullptr ? nullptr : &entries[0];
\r
772 HRESULT hr = InternalPointer->SetPaletteEntries( paletteNumber, reinterpret_cast<PALETTEENTRY*>( pinnedEntries ) );
\r
773 return RECORD_D3D9( hr );
\r
776 GammaRamp^ Device::GetGammaRamp( int swapChain )
\r
779 InternalPointer->GetGammaRamp( swapChain, &ramp );
\r
781 return gcnew GammaRamp( ramp );
\r
784 void Device::SetGammaRamp( int swapChain, GammaRamp^ ramp, bool calibrate )
\r
788 flags = D3DSGR_CALIBRATE;
\r
790 flags = D3DSGR_NO_CALIBRATION;
\r
792 D3DGAMMARAMP result = ramp->ToUnmanaged();
\r
793 InternalPointer->SetGammaRamp( swapChain, flags, &result );
\r
796 Result Device::GetStreamSource( int stream, [Out] VertexBuffer^% streamData, [Out] int% offsetBytes, [Out] int% stride )
\r
798 IDirect3DVertexBuffer9* localVb;
\r
799 UINT localOffset, localStride;
\r
801 HRESULT hr = InternalPointer->GetStreamSource( stream, &localVb, &localOffset, &localStride );
\r
803 if( RECORD_D3D9( hr ).IsFailure )
\r
805 streamData = nullptr;
\r
808 return Result::Last;
\r
811 streamData = VertexBuffer::FromPointer( localVb );
\r
812 offsetBytes = localOffset;
\r
813 stride = localStride;
\r
815 return Result::Last;
\r
818 Result Device::GetStreamSourceFrequency( int stream, [Out] int% frequency, [Out] StreamSource% source )
\r
820 UINT localFreq = 0;
\r
822 //set outputs to known defaults
\r
824 source = StreamSource::IndexedData;
\r
826 HRESULT hr = InternalPointer->GetStreamSourceFreq( stream, &localFreq );
\r
829 //default setting was indexed data, so just check if it's actually instance data
\r
830 if( localFreq & D3DSTREAMSOURCE_INSTANCEDATA )
\r
832 source = StreamSource::InstanceData;
\r
835 //mask out the flags that are in the upper bits
\r
836 UINT mask = ~(D3DSTREAMSOURCE_INSTANCEDATA | D3DSTREAMSOURCE_INDEXEDDATA);
\r
838 frequency = localFreq;
\r
840 return Result::Last;
\r
843 SwapChain^ Device::GetSwapChain( int swapChainIndex )
\r
845 IDirect3DSwapChain9* swapChain;
\r
847 HRESULT hr = InternalPointer->GetSwapChain( swapChainIndex, &swapChain );
\r
849 if( RECORD_D3D9( hr ).IsFailure )
\r
852 return SwapChain::FromPointer( swapChain );
\r
855 IndexBuffer^ Device::Indices::get()
\r
857 IDirect3DIndexBuffer9* indices;
\r
859 HRESULT hr = InternalPointer->GetIndices( &indices );
\r
861 if( RECORD_D3D9( hr ).IsFailure )
\r
864 return IndexBuffer::FromPointer( indices );
\r
867 void Device::Indices::set( IndexBuffer^ indices )
\r
870 if( indices != nullptr )
\r
871 hr = InternalPointer->SetIndices( indices->InternalPointer );
\r
873 hr = InternalPointer->SetIndices( NULL );
\r
878 Result Device::ProcessVertices( int sourceStartIndex, int destinationIndex, int vertexCount, VertexBuffer^ destinationBuffer,
\r
879 SlimDX::Direct3D9::VertexDeclaration^ vertexDeclaration, LockFlags flags )
\r
881 IDirect3DVertexBuffer9* vb = destinationBuffer->InternalPointer;
\r
882 IDirect3DVertexDeclaration9* decl = vertexDeclaration != nullptr ? vertexDeclaration->InternalPointer : NULL;
\r
884 HRESULT hr = InternalPointer->ProcessVertices( sourceStartIndex, destinationIndex, vertexCount, vb, decl, static_cast<DWORD>( flags ) );
\r
885 return RECORD_D3D9( hr );
\r
888 array<bool>^ Device::GetVertexShaderBooleanConstant( int startRegister, int count )
\r
890 stack_array<BOOL> booleans = stackalloc( BOOL, count );
\r
892 HRESULT hr = InternalPointer->GetVertexShaderConstantB( startRegister, &booleans[0], count );
\r
893 if( RECORD_D3D9( hr ).IsFailure )
\r
896 array<bool>^ results = gcnew array<bool>( count );
\r
897 for( int i = 0; i < count; i++ )
\r
898 results[i] = (booleans[i] != 0);
\r
903 array<float>^ Device::GetVertexShaderFloatConstant( int startRegister, int count )
\r
905 stack_array<FLOAT> floats = stackalloc( FLOAT, count );
\r
907 HRESULT hr = InternalPointer->GetVertexShaderConstantF( startRegister, &floats[0], count );
\r
908 if( RECORD_D3D9( hr ).IsFailure )
\r
911 array<float>^ results = gcnew array<float>( count );
\r
912 for( int i = 0; i < count; i++ )
\r
913 results[i] = floats[i];
\r
918 array<int>^ Device::GetVertexShaderIntegerConstant( int startRegister, int count )
\r
920 stack_array<INT> integers = stackalloc( INT, count );
\r
922 HRESULT hr = InternalPointer->GetVertexShaderConstantI( startRegister, &integers[0], count );
\r
923 if( RECORD_D3D9( hr ).IsFailure )
\r
926 array<int>^ results = gcnew array<int>( count );
\r
927 for( int i = 0; i < count; i++ )
\r
928 results[i] = integers[i];
\r
933 array<bool>^ Device::GetPixelShaderBooleanConstant( int startRegister, int count )
\r
935 stack_array<BOOL> booleans = stackalloc( BOOL, count );
\r
937 HRESULT hr = InternalPointer->GetPixelShaderConstantB( startRegister, &booleans[0], count );
\r
938 if( RECORD_D3D9( hr ).IsFailure )
\r
941 array<bool>^ results = gcnew array<bool>( count );
\r
942 for( int i = 0; i < count; i++ )
\r
943 results[i] = (booleans[i] != 0);
\r
948 array<float>^ Device::GetPixelShaderFloatConstant( int startRegister, int count )
\r
950 stack_array<FLOAT> floats = stackalloc( FLOAT, count );
\r
952 HRESULT hr = InternalPointer->GetPixelShaderConstantF( startRegister, &floats[0], count );
\r
953 if( RECORD_D3D9( hr ).IsFailure )
\r
956 array<float>^ results = gcnew array<float>( count );
\r
957 for( int i = 0; i < count; i++ )
\r
958 results[i] = floats[i];
\r
963 array<int>^ Device::GetPixelShaderIntegerConstant( int startRegister, int count )
\r
965 stack_array<INT> integers = stackalloc( INT, count );
\r
967 HRESULT hr = InternalPointer->GetPixelShaderConstantI( startRegister, &integers[0], count );
\r
968 if( RECORD_D3D9( hr ).IsFailure )
\r
971 array<int>^ results = gcnew array<int>( count );
\r
972 for( int i = 0; i < count; i++ )
\r
973 results[i] = integers[i];
\r
978 Result Device::SetVertexShaderConstant( int startRegister, array<bool>^ data, int offset, int count )
\r
980 Utilities::CheckArrayBounds( data, offset, count );
\r
982 array<BOOL>^ boolData = Array::ConvertAll<bool, int>( data, gcnew Converter<bool, int>( Convert::ToInt32 ) );
\r
983 pin_ptr<BOOL> pinnedData = &boolData[0];
\r
985 Utilities::CheckArrayBounds( data, offset, count );
\r
986 HRESULT hr = InternalPointer->SetVertexShaderConstantB( startRegister, pinnedData + offset, count );
\r
987 return RECORD_D3D9( hr );
\r
990 Result Device::SetVertexShaderConstant( int startRegister, array<float>^ data, int offset, int count )
\r
992 pin_ptr<float> pinnedData = &data[0];
\r
994 Utilities::CheckArrayBounds( data, offset, count * 4 );
\r
995 HRESULT hr = InternalPointer->SetVertexShaderConstantF( startRegister, pinnedData + offset, count );
\r
996 return RECORD_D3D9( hr );
\r
999 Result Device::SetVertexShaderConstant( int startRegister, array<Vector4>^ data, int offset, int count )
\r
1001 pin_ptr<Vector4> pinnedData = &data[0];
\r
1002 float* pinnedDataPointer = reinterpret_cast<float*>( pinnedData + offset );
\r
1004 Utilities::CheckArrayBounds( data, offset, count );
\r
1005 HRESULT hr = InternalPointer->SetVertexShaderConstantF( startRegister, pinnedDataPointer, count );
\r
1006 return RECORD_D3D9( hr );
\r
1009 Result Device::SetVertexShaderConstant( int startRegister, array<int>^ data, int offset, int count )
\r
1011 pin_ptr<int> pinnedData = &data[0];
\r
1013 Utilities::CheckArrayBounds( data, offset, count * 4 );
\r
1014 HRESULT hr = InternalPointer->SetVertexShaderConstantI( startRegister, pinnedData + offset, count );
\r
1015 return RECORD_D3D9( hr );
\r
1018 Result Device::SetVertexShaderConstant( int startRegister, Matrix data )
\r
1020 HRESULT hr = InternalPointer->SetVertexShaderConstantF( startRegister, reinterpret_cast<float*>( &data ), 4 );
\r
1021 return RECORD_D3D9( hr );
\r
1024 Result Device::SetVertexShaderConstant( int startRegister, Matrix* data, int count )
\r
1026 HRESULT hr = InternalPointer->SetVertexShaderConstantF( startRegister, reinterpret_cast<float*>( data ), count * 4 );
\r
1027 return RECORD_D3D9( hr );
\r
1030 Result Device::SetVertexShaderConstant( int startRegister, array<Matrix>^ data, int offset, int count )
\r
1032 pin_ptr<Matrix> pinnedData = &data[0];
\r
1034 Utilities::CheckBounds( 0, data->Length, offset, count );
\r
1035 HRESULT hr = InternalPointer->SetVertexShaderConstantF( startRegister, reinterpret_cast<float*>( pinnedData + offset ), count * 4 );
\r
1036 return RECORD_D3D9( hr );
\r
1039 Result Device::SetPixelShaderConstant( int startRegister, array<bool>^ data, int offset, int count )
\r
1041 array<BOOL>^ boolData = Array::ConvertAll<bool, int>( data, gcnew Converter<bool, int>( Convert::ToInt32 ) );
\r
1042 pin_ptr<BOOL> pinnedData = &boolData[0];
\r
1044 Utilities::CheckArrayBounds( data, offset, count );
\r
1045 HRESULT hr = InternalPointer->SetPixelShaderConstantB( startRegister, pinnedData + offset, count );
\r
1046 return RECORD_D3D9( hr );
\r
1049 Result Device::SetPixelShaderConstant( int startRegister, array<float>^ data, int offset, int count )
\r
1051 pin_ptr<float> pinnedData = &data[0];
\r
1053 Utilities::CheckArrayBounds( data, offset, count * 4 );
\r
1054 HRESULT hr = InternalPointer->SetPixelShaderConstantF( startRegister, pinnedData + offset, count );
\r
1055 return RECORD_D3D9( hr );
\r
1058 Result Device::SetPixelShaderConstant( int startRegister, array<Vector4>^ data, int offset, int count )
\r
1060 pin_ptr<Vector4> pinnedData = &data[0];
\r
1061 float* pinnedDataPointer = reinterpret_cast<float*>( pinnedData + offset );
\r
1063 Utilities::CheckArrayBounds( data, offset, count );
\r
1064 HRESULT hr = InternalPointer->SetPixelShaderConstantF( startRegister, pinnedDataPointer, count );
\r
1065 return RECORD_D3D9( hr );
\r
1068 Result Device::SetPixelShaderConstant( int startRegister, array<int>^ data, int offset, int count )
\r
1070 pin_ptr<int> pinnedData = &data[0];
\r
1072 Utilities::CheckArrayBounds( data, offset, count * 4 );
\r
1073 HRESULT hr = InternalPointer->SetPixelShaderConstantI( startRegister, pinnedData + offset, count );
\r
1074 return RECORD_D3D9( hr );
\r
1077 Result Device::SetPixelShaderConstant( int startRegister, Matrix data )
\r
1079 HRESULT hr = InternalPointer->SetPixelShaderConstantF( startRegister, reinterpret_cast<float*>( &data ), 4 );
\r
1080 return RECORD_D3D9( hr );
\r
1083 Result Device::SetPixelShaderConstant( int startRegister, Matrix* data, int count )
\r
1085 HRESULT hr = InternalPointer->SetPixelShaderConstantF( startRegister, reinterpret_cast<float*>( data ), count * 4 );
\r
1086 return RECORD_D3D9( hr );
\r
1089 Result Device::SetPixelShaderConstant( int startRegister, array<Matrix>^ data, int offset, int count )
\r
1091 pin_ptr<Matrix> pinnedData = &data[0];
\r
1093 Utilities::CheckBounds( 0, data->Length, offset, count );
\r
1094 HRESULT hr = InternalPointer->SetPixelShaderConstantF( startRegister, reinterpret_cast<float*>( pinnedData + offset ), count * 4 );
\r
1095 return RECORD_D3D9( hr );
\r
1098 Result Device::StretchRectangle( Surface^ source, System::Drawing::Rectangle sourceRect, Surface^ destination,
\r
1099 System::Drawing::Rectangle destRect, TextureFilter filter )
\r
1101 RECT nativeSourceRect = { sourceRect.Left, sourceRect.Top, sourceRect.Right, sourceRect.Bottom };
\r
1102 RECT nativeDestRect = { destRect.Left, destRect.Top, destRect.Right, destRect.Bottom };
\r
1104 HRESULT hr = InternalPointer->StretchRect( source->InternalPointer, &nativeSourceRect, destination->InternalPointer,
\r
1105 &nativeDestRect, static_cast<D3DTEXTUREFILTERTYPE>( filter ) );
\r
1106 return RECORD_D3D9( hr );
\r
1109 Result Device::StretchRectangle( Surface^ source, Surface^ destination, TextureFilter filter )
\r
1111 HRESULT hr = InternalPointer->StretchRect( source->InternalPointer, NULL, destination->InternalPointer,
\r
1112 NULL, static_cast<D3DTEXTUREFILTERTYPE>( filter ) );
\r
1113 return RECORD_D3D9( hr );
\r
1116 Result Device::UpdateSurface( Surface^ source, System::Drawing::Rectangle sourceRect,
\r
1117 Surface^ destination, System::Drawing::Point destinationPoint )
\r
1119 RECT nativeSourceRect = { sourceRect.Left, sourceRect.Top, sourceRect.Right, sourceRect.Bottom };
\r
1120 POINT nativeDestPoint = { destinationPoint.X, destinationPoint.Y };
\r
1122 HRESULT hr = InternalPointer->UpdateSurface( source->InternalPointer, &nativeSourceRect,
\r
1123 destination->InternalPointer, &nativeDestPoint );
\r
1124 return RECORD_D3D9( hr );
\r
1127 Result Device::UpdateSurface( Surface^ source, Surface^ destination )
\r
1129 HRESULT hr = InternalPointer->UpdateSurface( source->InternalPointer, NULL, destination->InternalPointer, NULL );
\r
1130 return RECORD_D3D9( hr );
\r
1133 Result Device::UpdateTexture( BaseTexture^ sourceTexture, BaseTexture^ destinationTexture )
\r
1135 HRESULT hr = InternalPointer->UpdateTexture( sourceTexture->InternalPointer, destinationTexture->InternalPointer );
\r
1136 return RECORD_D3D9( hr );
\r
1139 Result Device::ColorFill( Surface^ destSurface, System::Drawing::Rectangle destRect, Color4 color )
\r
1141 RECT nativeDestRect = { destRect.Left, destRect.Top, destRect.Right, destRect.Bottom };
\r
1143 HRESULT hr = InternalPointer->ColorFill( destSurface->InternalPointer, &nativeDestRect, static_cast<D3DCOLOR>( color.ToArgb() ) );
\r
1144 return RECORD_D3D9( hr );
\r
1147 Result Device::ColorFill( Surface^ destSurface, Color4 color )
\r
1149 HRESULT hr = InternalPointer->ColorFill( destSurface->InternalPointer, NULL, static_cast<D3DCOLOR>( color.ToArgb() ) );
\r
1150 return RECORD_D3D9( hr );
\r
1153 Result Device::BeginStateBlock()
\r
1155 HRESULT hr = InternalPointer->BeginStateBlock();
\r
1156 return RECORD_D3D9( hr );
\r
1159 StateBlock^ Device::EndStateBlock()
\r
1161 IDirect3DStateBlock9* stateBlock;
\r
1162 HRESULT hr = InternalPointer->EndStateBlock( &stateBlock );
\r
1164 if( RECORD_D3D9( hr ).IsFailure )
\r
1167 return StateBlock::FromPointer( stateBlock );
\r
1170 SlimDX::Direct3D9::CreationParameters Device::CreationParameters::get()
\r
1172 SlimDX::Direct3D9::CreationParameters parameters;
\r
1173 D3DDEVICE_CREATION_PARAMETERS dcp;
\r
1175 HRESULT hr = InternalPointer->GetCreationParameters( &dcp );
\r
1176 if( RECORD_D3D9( hr ).IsFailure )
\r
1177 return SlimDX::Direct3D9::CreationParameters();
\r
1179 parameters.AdapterOrdinal = dcp.AdapterOrdinal;
\r
1180 parameters.DeviceType = static_cast<DeviceType>( dcp.DeviceType );
\r
1181 parameters.Window = IntPtr( dcp.hFocusWindow );
\r
1182 parameters.BehaviorFlags = static_cast<CreateFlags>( dcp.BehaviorFlags );
\r
1184 return parameters;
\r
1187 SlimDX::Direct3D9::ClipStatus Device::ClipStatus::get()
\r
1189 D3DCLIPSTATUS9 status;
\r
1191 HRESULT hr = InternalPointer->GetClipStatus( &status );
\r
1192 if( RECORD_D3D9( hr ).IsFailure )
\r
1193 return SlimDX::Direct3D9::ClipStatus();
\r
1195 SlimDX::Direct3D9::ClipStatus result;
\r
1196 result.ClipUnion = static_cast<ClipFlags>( status.ClipUnion );
\r
1197 result.ClipIntersection = static_cast<ClipFlags>( status.ClipIntersection );
\r
1202 void Device::ClipStatus::set( SlimDX::Direct3D9::ClipStatus value )
\r
1204 HRESULT hr = InternalPointer->SetClipStatus( reinterpret_cast<const D3DCLIPSTATUS9*>( &value ) );
\r
1205 RECORD_D3D9( hr );
\r
1208 int Device::SwapChainCount::get()
\r
1210 return InternalPointer->GetNumberOfSwapChains();
\r
1213 float Device::NPatchMode::get()
\r
1215 return InternalPointer->GetNPatchMode();
\r
1218 void Device::NPatchMode::set( float value )
\r
1220 HRESULT hr = InternalPointer->SetNPatchMode( value );
\r
1221 RECORD_D3D9( hr );
\r
1224 Result Device::DrawTrianglePatch( int handle, array<float>^ numSegments, TrianglePatchInfo info )
\r
1226 pin_ptr<float> pinnedSegments = &numSegments[0];
\r
1228 HRESULT hr = InternalPointer->DrawTriPatch( handle, pinnedSegments, reinterpret_cast<D3DTRIPATCH_INFO*>( &info ) );
\r
1229 return RECORD_D3D9( hr );
\r
1232 Result Device::DrawTrianglePatch( int handle, array<float>^ numSegments )
\r
1234 pin_ptr<float> pinnedSegments = &numSegments[0];
\r
1236 HRESULT hr = InternalPointer->DrawTriPatch( handle, pinnedSegments, NULL );
\r
1237 return RECORD_D3D9( hr );
\r
1240 Result Device::DrawRectanglePatch( int handle, array<float>^ numSegments, RectanglePatchInfo info )
\r
1242 pin_ptr<float> pinnedSegments = &numSegments[0];
\r
1244 HRESULT hr = InternalPointer->DrawRectPatch( handle, pinnedSegments, reinterpret_cast<D3DRECTPATCH_INFO*>( &info ) );
\r
1245 return RECORD_D3D9( hr );
\r
1248 Result Device::DrawRectanglePatch( int handle, array<float>^ numSegments )
\r
1250 pin_ptr<float> pinnedSegments = &numSegments[0];
\r
1252 HRESULT hr = InternalPointer->DrawRectPatch( handle, pinnedSegments, NULL );
\r
1253 return RECORD_D3D9( hr );
\r
1256 Result Device::DeletePatch( int handle )
\r
1258 HRESULT hr = InternalPointer->DeletePatch( handle );
\r
1259 return RECORD_D3D9( hr );
\r
1262 DisplayMode Device::GetDisplayMode( int swapChain )
\r
1264 DisplayMode displayMode;
\r
1266 HRESULT hr = InternalPointer->GetDisplayMode( swapChain, reinterpret_cast<D3DDISPLAYMODE*>( &displayMode ) );
\r
1267 RECORD_D3D9( hr );
\r
1269 return displayMode;
\r
1272 Result Device::EvictManagedResources()
\r
1274 HRESULT hr = InternalPointer->EvictManagedResources();
\r
1275 return RECORD_D3D9( hr );
\r
1278 Result Device::SetDialogBoxMode( bool enableDialogs )
\r
1280 HRESULT hr = InternalPointer->SetDialogBoxMode( enableDialogs );
\r
1281 return RECORD_D3D9( hr );
\r
1284 Result Device::EnableLight( int lightIndex, bool enable )
\r
1286 HRESULT hr = InternalPointer->LightEnable( lightIndex, enable );
\r
1287 return RECORD_D3D9( hr );
\r
1290 bool Device::IsLightEnabled( int lightIndex )
\r
1292 BOOL enabled = FALSE;
\r
1293 HRESULT hr = InternalPointer->GetLightEnable( lightIndex, &enabled );
\r
1294 RECORD_D3D9( hr );
\r
1296 return enabled > 0;
\r
1299 Result Device::SetLight( int lightIndex, Light lightData )
\r
1301 HRESULT hr = InternalPointer->SetLight( lightIndex, reinterpret_cast<const D3DLIGHT9*>( &lightData ) );
\r
1302 return RECORD_D3D9( hr );
\r
1305 Light Device::GetLight( int lightIndex )
\r
1308 HRESULT hr = InternalPointer->GetLight( lightIndex, reinterpret_cast<D3DLIGHT9*>( &light ) );
\r
1309 RECORD_D3D9( hr );
\r
1314 Result Device::SetCursor( Cursor^ cursor, bool addWatermark )
\r
1316 if( cursor == nullptr )
\r
1317 return RECORD_D3D9( S_OK );
\r
1319 IDirect3DSurface9 *cursorSurface = NULL;
\r
1320 ICONINFO iconInfo = {0};
\r
1323 BITMAPINFO bmi = {0};
\r
1326 int heightSrc = 0;
\r
1327 int heightDest = 0;
\r
1330 stack_array<COLORREF> arrayColor;
\r
1331 HDC hdcColor = NULL;
\r
1332 HDC hdcScreen = NULL;
\r
1333 HDC hdcMask = NULL;
\r
1334 HGDIOBJ oldObject;
\r
1337 if( !GetIconInfo( static_cast<HICON>( cursor->Handle.ToPointer() ), &iconInfo ) )
\r
1338 return RECORD_D3D9( E_FAIL );
\r
1340 if( GetObject( static_cast<HGDIOBJ>( iconInfo.hbmMask ), sizeof( BITMAP ), static_cast<LPVOID>( &bmp ) ) == 0 )
\r
1342 if( iconInfo.hbmMask != NULL )
\r
1343 DeleteObject( iconInfo.hbmMask );
\r
1344 if( iconInfo.hbmColor != NULL )
\r
1345 DeleteObject( iconInfo.hbmColor );
\r
1346 return RECORD_D3D9( E_FAIL );
\r
1349 width = bmp.bmWidth;
\r
1350 heightSrc = bmp.bmHeight;
\r
1352 if( iconInfo.hbmColor == NULL )
\r
1355 heightDest = heightSrc / 2;
\r
1360 heightDest = heightSrc;
\r
1363 if( FAILED( hr = InternalPointer->CreateOffscreenPlainSurface( width, heightDest, D3DFMT_A8R8G8B8,
\r
1364 D3DPOOL_SCRATCH, &cursorSurface, NULL ) ) )
\r
1366 if( iconInfo.hbmMask != NULL )
\r
1367 DeleteObject( iconInfo.hbmMask );
\r
1368 if( iconInfo.hbmColor != NULL )
\r
1369 DeleteObject( iconInfo.hbmColor );
\r
1370 return RECORD_D3D9( hr );
\r
1373 stack_array<COLORREF> arrayMask = stackalloc( COLORREF, width * heightSrc );
\r
1375 bmi.bmiHeader.biSize = sizeof( bmi.bmiHeader );
\r
1376 bmi.bmiHeader.biWidth = width;
\r
1377 bmi.bmiHeader.biHeight = heightSrc;
\r
1378 bmi.bmiHeader.biPlanes = 1;
\r
1379 bmi.bmiHeader.biBitCount = 32;
\r
1380 bmi.bmiHeader.biCompression = BI_RGB;
\r
1382 hdcScreen = GetDC( NULL );
\r
1383 hdcMask = CreateCompatibleDC( hdcScreen );
\r
1384 if( hdcMask == NULL )
\r
1386 if( iconInfo.hbmMask != NULL )
\r
1387 DeleteObject( iconInfo.hbmMask );
\r
1388 if( iconInfo.hbmColor != NULL )
\r
1389 DeleteObject( iconInfo.hbmColor );
\r
1390 if( hdcScreen != NULL )
\r
1391 ReleaseDC( NULL, hdcScreen );
\r
1392 if( cursorSurface != NULL )
\r
1393 cursorSurface->Release();
\r
1394 return RECORD_D3D9( E_FAIL );
\r
1397 oldObject = SelectObject( hdcMask, iconInfo.hbmMask );
\r
1398 GetDIBits( hdcMask, iconInfo.hbmMask, 0, heightSrc, &arrayMask[0], &bmi, DIB_RGB_COLORS );
\r
1399 SelectObject( hdcMask, oldObject );
\r
1403 arrayColor = stack_array<COLORREF>( width * heightDest );
\r
1404 hdcColor = CreateCompatibleDC( hdcScreen );
\r
1405 if( hdcColor == NULL )
\r
1407 if( iconInfo.hbmMask != NULL )
\r
1408 DeleteObject( iconInfo.hbmMask );
\r
1409 if( iconInfo.hbmColor != NULL )
\r
1410 DeleteObject( iconInfo.hbmColor );
\r
1411 if( hdcScreen != NULL )
\r
1412 ReleaseDC( NULL, hdcScreen );
\r
1413 if( hdcMask != NULL )
\r
1414 DeleteDC( hdcMask );
\r
1415 if( hdcColor != NULL )
\r
1416 DeleteDC( hdcColor );
\r
1417 if( cursorSurface != NULL )
\r
1418 cursorSurface->Release();
\r
1419 return RECORD_D3D9( E_FAIL );
\r
1422 SelectObject( hdcColor, iconInfo.hbmColor );
\r
1423 GetDIBits( hdcColor, iconInfo.hbmColor, 0, heightDest, &arrayColor[0], &bmi, DIB_RGB_COLORS );
\r
1426 D3DLOCKED_RECT lr;
\r
1427 cursorSurface->LockRect( &lr, NULL, 0 );
\r
1428 bitmap = static_cast<DWORD*>( lr.pBits );
\r
1430 for( int y = 0; y < heightDest; y++ )
\r
1432 for( int x = 0; x < width; x++ )
\r
1436 color = arrayMask[width * ( heightDest - 1 - y ) + x];
\r
1437 mask = arrayMask[width * ( heightSrc - 1 - y ) + x];
\r
1441 color = arrayColor[width * ( heightDest - 1 - y ) + x];
\r
1442 mask = arrayMask[width * ( heightDest - 1 - y ) + x];
\r
1446 bitmap[width * y + x] = 0xff000000 | color;
\r
1448 bitmap[width * y + x] = 0x00000000;
\r
1450 if( addWatermark && x < 12 && y < 5 )
\r
1452 const WORD wMask[5] = { 0xccc0, 0xa2a0, 0xa4a0, 0xa2a0, 0xccc0 };
\r
1453 if( wMask[y] & ( 1 << ( 15 - x ) ) )
\r
1454 bitmap[width * y + x] |= 0xff808080;
\r
1459 cursorSurface->UnlockRect();
\r
1461 hr = InternalPointer->SetCursorProperties( iconInfo.xHotspot, iconInfo.yHotspot, cursorSurface );
\r
1463 if( iconInfo.hbmMask != NULL )
\r
1464 DeleteObject( iconInfo.hbmMask );
\r
1465 if( iconInfo.hbmColor != NULL )
\r
1466 DeleteObject( iconInfo.hbmColor );
\r
1467 if( hdcScreen != NULL )
\r
1468 ReleaseDC( NULL, hdcScreen );
\r
1469 if( hdcMask != NULL )
\r
1470 DeleteDC( hdcMask );
\r
1471 if( hdcColor != NULL )
\r
1472 DeleteDC( hdcColor );
\r
1473 if( cursorSurface != NULL )
\r
1474 cursorSurface->Release();
\r
1475 return RECORD_D3D9( hr );
\r
1478 void Device::SetCursorPosition( int x, int y, bool immediateUpdate )
\r
1480 DWORD flags = immediateUpdate ? D3DCURSOR_IMMEDIATE_UPDATE : 0;
\r
1481 InternalPointer->SetCursorPosition( x, y, flags );
\r
1484 Result Device::SetCursorProperties( int hotspotX, int hotspotY, Surface^ cursorBitmap )
\r
1486 IDirect3DSurface9* surface = cursorBitmap != nullptr ? cursorBitmap->InternalPointer : NULL;
\r
1487 HRESULT hr = InternalPointer->SetCursorProperties( hotspotX, hotspotY, surface );
\r
1488 return RECORD_D3D9( hr );
\r
1491 void Device::CurrentTexturePalette::set( int value )
\r
1493 HRESULT hr = InternalPointer->SetCurrentTexturePalette( value );
\r
1494 RECORD_D3D9( hr );
\r
1497 int Device::CurrentTexturePalette::get()
\r
1499 unsigned int palette = 0;
\r
1500 HRESULT hr = InternalPointer->GetCurrentTexturePalette( &palette );
\r
1501 RECORD_D3D9( hr );
\r
1503 return static_cast<int>( palette );
\r
1506 VertexShader^ Device::VertexShader::get()
\r
1508 IDirect3DVertexShader9* vs;
\r
1509 HRESULT hr = InternalPointer->GetVertexShader( &vs );
\r
1511 if( RECORD_D3D9( hr ).IsFailure )
\r
1514 return SlimDX::Direct3D9::VertexShader::FromPointer( vs );
\r
1517 PixelShader^ Device::PixelShader::get()
\r
1519 IDirect3DPixelShader9* ps;
\r
1520 HRESULT hr = InternalPointer->GetPixelShader( &ps );
\r
1522 if( RECORD_D3D9( hr ).IsFailure )
\r
1525 return SlimDX::Direct3D9::PixelShader::FromPointer( ps );
\r
1528 DriverLevel Device::DriverLevel::get()
\r
1530 return static_cast<SlimDX::Direct3D9::DriverLevel>( D3DXGetDriverLevel( InternalPointer ) );
\r
1533 String^ Device::VertexShaderProfile::get()
\r
1535 LPCSTR profile = D3DXGetVertexShaderProfile( InternalPointer );
\r
1536 return gcnew String( profile );
\r
1539 String^ Device::PixelShaderProfile::get()
\r
1541 LPCSTR profile = D3DXGetPixelShaderProfile( InternalPointer );
\r
1542 return gcnew String( profile );
\r
1545 Result Device::SetR2VBMode( bool enableR2VB )
\r
1547 return SetRenderState( RenderState::PointSize, static_cast<int>( r2vbGlbEnable_Set( enableR2VB ) ) );
\r
1550 Result Device::BindRenderTargetToVertexStream( R2VBSampler sampler, Texture^ r2vbTarget, int stream, int stride, VertexBuffer^ dummyVb )
\r
1552 if( SetTexture( D3DDMAPSAMPLER, r2vbTarget ).IsFailure )
\r
1553 return Result::Last;
\r
1555 if( SetRenderState( RenderState::PointSize, static_cast<int>( r2vbVStrm2SmpMap_Set( stream, static_cast<int>( sampler ) ) ) ).IsFailure )
\r
1556 return Result::Last;
\r
1558 if( SetStreamSource( stream, dummyVb, 0, stride ).IsFailure )
\r
1559 return Result::Last;
\r
1561 return RECORD_D3D9( D3D_OK );
\r
1564 Result Device::RestoreVertexStream( int stream )
\r
1566 if( SetRenderState( RenderState::PointSize, static_cast<int>( r2vbVStrm2SmpMap_Set( stream, R2VB_VSMP_OVR_DIS ) ) ).IsFailure )
\r
1567 return Result::Last;
\r
1569 return SetTexture( D3DDMAPSAMPLER, nullptr );
\r
1572 Result Device::SetClipPlane( int index, Plane clipPlane )
\r
1574 HRESULT hr = InternalPointer->SetClipPlane( index, reinterpret_cast<const float*>( &clipPlane ) );
\r
1575 return RECORD_D3D9( hr );
\r
1578 Plane Device::GetClipPlane( int index )
\r
1581 HRESULT hr = InternalPointer->GetClipPlane( index, reinterpret_cast<float*>( &plane ) );
\r
1582 RECORD_D3D9( hr );
\r
1587 Result Device::GetFrontBufferData( int swapChain, Surface^ destinationSurface )
\r
1589 IDirect3DSurface9* surface = destinationSurface != nullptr ? destinationSurface->InternalPointer : NULL;
\r
1590 HRESULT hr = InternalPointer->GetFrontBufferData( swapChain, surface );
\r
1591 return RECORD_D3D9( hr );
\r
1594 Result Device::GetRenderTargetData( Surface^ renderTarget, Surface^ destinationSurface )
\r
1596 IDirect3DSurface9* target = renderTarget != nullptr ? renderTarget->InternalPointer : NULL;
\r
1597 IDirect3DSurface9* destination = destinationSurface != nullptr ? destinationSurface->InternalPointer : NULL;
\r
1598 HRESULT hr = InternalPointer->GetRenderTargetData( target, destination );
\r
1599 return RECORD_D3D9( hr );
\r
1602 SlimDX::Direct3D9::Direct3D^ Device::Direct3D::get()
\r
1604 IDirect3D9 *pointer;
\r
1606 HRESULT hr = InternalPointer->GetDirect3D( &pointer );
\r
1607 if( RECORD_D3D9( hr ).IsFailure )
\r
1610 return SlimDX::Direct3D9::Direct3D::FromPointer( pointer );
\r