DirectX 10 in BlitzMax

BlitzMax Forums/BlitzMax Programming/DirectX 10 in BlitzMax

Is this possible? How much work would be involved?

I am just researching options for future development, and looking at language and graphics API combinations. This isn't going to happen in the immediate future. It would be nice if I could make a gradual transition from BMX to CPP, and just use BMX when writing a windowed app or tool.

Not sure why, but I always thought dx 10+ was only available in the .net languages. I would wage that i'm completely wrong though.

You can use the sdk with C++ and C# (headers included) and you can compile programms without the .net Framework.

bye

Its vista only, so a good way of cutting down your potential market to a miniscule one.

Nothing is impossible..

I dare to say that it shouldnt be a massive problem... The only one I can see is that currently, theres not really many resources surrounding DX10.

I've used DirectX 9 to make a small lib that roughly shares the same graphical properties of Max2D, and this was due to the fact the internet is literally dripping with DX9 resources.

http://www.syntaxbomb.com/forums/showthread.php?t=1998

I've poked around with DirectX10 regarding sprites and such, and its a different beast altogether and stopped after getting a sprite on the screen:-

http://www.syntaxbomb.com/forums/showthread.php?t=1851

I'll give it a year or two before I move up and have another play! :)

Dabz

Hi Dabz - I would pay for a stable, reliable Max2D DX9 replacement for Blitzmax. Using the DX9's sprite object, it should be a piece of cake to code. If I had time, I would give it a go myself.

Why not aim for Dx11 right away... ;)

DX11 is not going to be very different from DX10.

I will start the DX10 tutorials soon and see what I think.

You only need the interface and function definitions of Direct3D 10 to use it in BlitzMax. I have converted parts of the official D3D10 headers a few weeks ago. They are not complete and untested yet, but i think it's a good starting point.

DXGI Header

' DXGI ( DirectX Graphics Infrastructure ) Interface and Function Definitions
' Copyright © Christian Klaussner, 2008

Strict

Import pub.win32

Extern "Win32"

Type IDXGIObject Extends IUnknown
	Method SetPrivateData( name:Byte Ptr, size:Int, data:Byte Ptr )
	Method SetPrivateDataInterface( name:Byte Ptr, unknown:IUnknown Ptr )
	Method GetPrivateData( name:Byte Ptr, size:Int Ptr, data:Byte Ptr )
	Method GetParent( riid:Byte Ptr, parent:Byte Ptr Ptr )
End Type

Type IDXGIDeviceSubObject Extends IDXGIObject
	Method GetDevice( riid:Byte Ptr, device:Byte Ptr Ptr )
End Type

Type IDXGIResource Extends IDXGIDeviceSubObject
	Method GetSharedHandle( handle:Int Ptr )
	Method GetUsage( usage:Int Ptr )
	Method SetEvictionPriority( priority:Int )
	Method GetEvictionPriority( priority:Int Ptr )
End Type

Type IDXGISurface Extends IDXGIDeviceSubObject
	Method GetDesc( desc:Byte Ptr )
	Method Map( lockedrect:Byte Ptr, flags:Int )
	Method Unmap( )
End Type

Type IDXGIAdapter Extends IDXGIObject
	Method EnumOutputs( out:Int, output:Byte Ptr Ptr )
	Method GetDesc( desc:Byte Ptr Ptr )
	Method CheckInterfaceSupport( name:Byte Ptr, umdversion:Byte Ptr )
End Type

Type IDXGIOutput Extends IDXGIObject
	Method GetDesc( desc:Byte Ptr )
	Method GetDisplayModeList( format:Int, flags:Int, modes:Int Ptr, desc:Byte Ptr )
	Method FindClosestMatchingMode( mode:Byte Ptr, closest:Byte Ptr, device:IUnknown Ptr )
	Method WaitForVBlank( )
	Method TakeOwnership( device:IUnknown Ptr )
	Method ReleaseOwnership( )
	Method GetGammaControlCapabilities( caps:Byte Ptr )
	Method SetGammaControl( array:Byte Ptr )
	Method GetGammaControl( array:Byte Ptr )
	Method SetDisplaySurface( surface:IDXGISurface Ptr )
	Method GetDisplaySurfaceData( surface:IDXGISurface Ptr )
	Method GetFrameStatistics( stats:Byte Ptr )
End Type

Type IDXGISwapChain Extends IDXGIDeviceSubObject
	Method Present( interval:Int, flags:Int )
	Method GetBuffer( buffer:Int, riid:Byte Ptr, surface:Byte Ptr Ptr )
	Method SetFullscreenState( fullscreen:Int, target:IDXGIOutput Ptr )
	Method GetFullscreenState( fullscreen:Int Ptr, target:IDXGIOutput Ptr Ptr )
	Method GetDesc( desc:Byte Ptr )
	Method ResizeBuffers( count:Int, width:Int, height:Int, format:Int, flags:Int )
	Method ResizeTarget( parameters:Byte Ptr )
	Method GetContainingOutput( output:IDXGIOutput Ptr Ptr )
	Method GetFrameStatistics( stats:Byte Ptr )
	Method GetLastPresentCount( count:Int Ptr )
End Type

Type IDXGIFactory Extends IDXGIObject
	Method EnumAdapters( index:Int, adapter:IDXGIAdapter Ptr Ptr )
	Method MakeWindowAssociation( handle:Int, flags:Int )
	Method CreateSwapChain( device:IUnknown Ptr, desc:Int, swapchain:IDXGISwapChain Ptr Ptr )
	Method CreateSoftwareAdapter( hmodule:Int, adapter:IDXGIAdapter Ptr Ptr )
End Type

Type IDXGIDevice Extends IDXGIObject
	Method GetAdapter( adapter:IDXGIAdapter Ptr Ptr )
	Method CreateSurface( desc:Byte Ptr, num:Int, usage:Int, resource:Byte Ptr, surface:IDXGISurface Ptr Ptr )
	Method QueryResourceResidency( resources:Byte Ptr Ptr, status:Int Ptr, numres:Int )
	Method SetGPUThreadPriority( priority:Int )
	Method GetGPUThreadPriority( priority:Int Ptr )
End Type

Function CreateDXGIFactory( riid:Byte Ptr, factory:Byte Ptr Ptr )

End Extern


D3D10 Header

' Direct3D 10 Interface and Function Definitions
' Copyright © Christian Klaussner, 2008

Strict

Import pub.win32
Include "dxgiheader.bmx"

Extern "Win32"

' Core Interfaces

Type ID3D10BlendState Extends ID3D10DeviceChild
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10DepthStencilState Extends ID3D10DeviceChild
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10InputLayout Extends ID3D10DeviceChild
End Type

Type ID3D10RasterizerState Extends ID3D10DeviceChild
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10SamplerState Extends ID3D10DeviceChild
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10Asynchronous Extends ID3D10DeviceChild
	Method Begin( )
	Method End_( )
	Method GetData( data:Byte Ptr, size:Int, flags:Int )
	Method GetDataSize( )
End Type

Type ID3D10Blob Extends IUnknown
	Method GetBufferPointer:Byte Ptr( )
	Method GetBufferSize( )
End Type

Type ID3D10Counter Extends ID3D10Asynchronous
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10Debug Extends IUnknown
	Method SetFeatureMask( mask:Int )
	Method GetFeatureMask( )
	Method SetPresentPerRenderOpDelay( milliseconds:Int )
	Method GetPresentPerRenderOpDelay( )
	Method SetSwapChain( IDXGISwapChain Ptr )
	Method GetSwapChain( IDXGISwapChain Ptr Ptr )
	Method Validate( )
End Type

Type ID3D10Device Extends IUnknown
	Method VSSetConstantBuffers( startsslot:Int, numbuffers:Int, buffers:ID3D10Buffer Ptr Ptr )
	Method PSSetShaderResources( startsslot:Int, numviews:Int, resviews:ID3D10ShaderResourceView Ptr Ptr )
	Method PSSetShader( pixelshader:ID3D10PixelShader Ptr )
	Method PSSetSamplers( startsslot:Int, numsamplers:Int, samplers:ID3D10SamplerState Ptr Ptr )
	Method VSSetShader( vertexshader:ID3D10VertexShader Ptr )
	Method DrawIndexed( indexcount:Int, startindexloc:Int, basevertexloc:Int )
	Method Draw( vertexcount:Int, startvertexloc:Int )
	Method PSSetConstantBuffers( startsslot:Int, numbuffers:Int, buffers:ID3D10Buffer Ptr Ptr )
	Method IASetInputLayout( layout:ID3D10InputLayout Ptr )
	Method IASetVertexBuffers( startsslot:Int, numbuffers:Int, buffers:ID3D10Buffer Ptr Ptr, strides:Int Ptr, offsets:Int Ptr )
	Method IASetIndexBuffer( buffer:ID3D10Buffer Ptr, format:Int, offset:Int )
	Method DrawIndexedInstanced( indexcountperinst:Int, instcount:Int, startindexloc:Int, basevertexloc:Int, startinstloc:Int )
	Method DrawInstanced( vertexcountperinst:Int, instcount:Int, startvertexloc:Int, startinstanceloc:Int )
	Method GSSetConstantBuffers( startsslot:Int, numbuffers:Int, buffers:ID3D10Buffer Ptr Ptr )
	Method GSSetShader( geometeryshader:ID3D10GeometryShader Ptr )
	Method IASetPrimitiveTopology( topology:Int )
	Method VSSetShaderResources( startsslot:Int, numviews:Int, resviews:ID3D10ShaderResourceView Ptr Ptr )
	Method VSSetSamplers( startsslot:Int, numsamplers:Int, samplers:ID3D10SamplerState Ptr Ptr )
	Method SetPredication( predicate:ID3D10Predicate, predicatevalue:Int )
	Method GSSetShaderResources( startsslot:Int, numviews:Int, resviews:ID3D10ShaderResourceView Ptr Ptr )
	Method GSSetSamplers( startsslot:Int, numsamplers:Int, samplers:ID3D10SamplerState Ptr Ptr )
	Method OMSetRenderTargets( numviews:Int, rendertargetviews:ID3D10RenderTargetView Ptr Ptr, depthstencilview:ID3D10DepthStencilView Ptr )
	Method OMSetBlendState( blendstate:ID3D10BlendState Ptr, blendfactor:Float Ptr, samplemask:Int )
	Method OMSetDepthStencilState( depthstencilstate:ID3D10DepthStencilState Ptr, stencilref:Int )
	Method SOSetTargets( numbuffers:Int, targets:ID3D10Buffer Ptr Ptr, offsets:Int Ptr )
	Method DrawAuto( )
	Method RSSetState( state:ID3D10RasterizerState Ptr )
	Method RSSetViewports( numviewports:Int, viewports:Byte Ptr )
	Method RSSetScissorRects( numrects:Int, rects:Byte Ptr )
	Method CopySubresourceRegion( destres:ID3D10Resource Ptr, dstsubres:Int, x:Int, y:Int, z:Int, srcres:ID3D10Resource Ptr, srcsubres:Int, srcbox:Byte Ptr )
	Method CopyResource( destres:ID3D10Resource Ptr, srcres:ID3D10Resource Ptr )
	Method UpdateSubresource( destres:ID3D10Resource Ptr, destsubres:Int, destbox:Byte Ptr, srcdata:Byte Ptr, rowpitch:Int, depthpitch:Int )
	Method ClearRenderTargetView( rendertargetview:ID3D10RenderTargetView Ptr, color:Float Ptr )
	Method ClearDepthStencilView( depthstencilview:ID3D10DepthStencilView Ptr, flags:Int, depth:Float, stencil:Byte )
	Method GenerateMips( shaderresourceview:ID3D10ShaderResourceView )
	Method ResolveSubresource( desres:ID3D10Resource Ptr, destsubres:Int, srcres:ID3D10Resource Ptr, srcsubres:Int, format:Int )
	Method VSGetConstantBuffers( startslot:Int, numbuffers:Int, buffers:ID3D10Buffer Ptr Ptr )
	Method PSGetShaderResources( startslot:Int, numviews:Int, shaderresviews:ID3D10ShaderResourceView Ptr Ptr )
	Method PSGetShader( pixelshader:ID3D10PixelShader )
	Method PSGetSamplers( startslot:Int, numsamplers:Int, samplers:ID3D10SamplerState Ptr Ptr )
	Method VSGetShader( vertexshader:ID3D10VertexShader )
	Method PSGetConstantBuffers( startslot:Int, numbuffers:Int, buffers:ID3D10Buffer Ptr Ptr )
	Method IAGetInputLayout( inputlayout:ID3D10InputLayout Ptr Ptr )
	Method IAGetVertexBuffers( startslot:Int, numbuffers:Int, vertexbuffers:ID3D10Buffer Ptr Ptr, strides:Int Ptr, offsets:Int Ptr )
	Method IAGetIndexBuffer( indexbuffer:ID3D10Buffer Ptr Ptr, format:Int Ptr, offset:Int Ptr )
	Method GSGetConstantBuffers( startslot:Int, numbuffers:Int, buffers:ID3D10Buffer Ptr Ptr )
	Method GSGetShader( geometryshader:ID3D10GeometryShader Ptr Ptr )
	Method IAGetPrimitiveTopology( topology:Int Ptr )
	Method VSGetShaderResources( startslot:Int, numviews:Int, resviews:ID3D10ShaderResourceView Ptr Ptr )
	Method VSGetSamplers( startslot:Int, numsamplers:Int, samplers:ID3D10SamplerState Ptr Ptr )
	Method GetPredication( predicate:ID3D10Predicate Ptr Ptr, predicatevalue:Int Ptr )
	Method GSGetShaderResources( startslot:Int, numviews:Int, resviews:ID3D10ShaderResourceView Ptr Ptr )
	Method GSGetSamplers( startslot:Int, numsamplers:Int, samplers:ID3D10SamplerState Ptr Ptr )
	Method OMGetRenderTargets( numviews:Int, rendertargetviews:ID3D10RenderTargetView Ptr Ptr )
	Method OMGetBlendState( blendstate:ID3D10BlendState Ptr Ptr, blendfactor:Float Ptr, samplemask:Int Ptr )
	Method OMGetDepthStencilState( depthstencilstate:ID3D10DepthStencilState Ptr Ptr, stencilref:Int )
	Method SOGetTargets( numbuffers:Int, sotargets:ID3D10Buffer Ptr Ptr, offsets:Int Ptr )
	Method RSGetState( rasterizerstate:ID3D10RasterizerState Ptr Ptr )
	Method RSGetViewports( numviews:Int Ptr, viewports:Byte Ptr )
	Method RSGetScissorRects( numrects:Int Ptr, rects:Byte Ptr )
	Method GetDeviceRemovedReason( )
	Method SetExceptionMode( raiseflags:Int )
	Method GetExceptionMode( )
	Method GetPrivateData( guid:Byte Ptr, datasize:Int Ptr, data:Byte Ptr )
	Method SetPrivateData( guid:Byte Ptr, datasize:Int, data:Byte Ptr )
	Method SetPrivateDataInterface( guid:Byte Ptr, data:IUnknown Ptr )
	Method ClearState( )
	Method Flush( )
	Method CreateBuffer( desc:Byte Ptr, initialdata:Byte Ptr, buffer:ID3D10Buffer Ptr Ptr )
	
	Method CreateTexture1D( desc:Byte Ptr, initialdata:Byte Ptr, texture:ID3D10Texture1D Ptr Ptr )
	Method CreateTexture2D( desc:Byte Ptr, initialdata:Byte Ptr, texture:ID3D10Texture2D Ptr Ptr )
	Method CreateTexture3D( desc:Byte Ptr, initialdata:Byte Ptr, texture:ID3D10Texture3D Ptr Ptr )
	
	Method CreateShaderResourceView( resource:ID3D10Resource Ptr, desc:Byte Ptr, resview:ID3D10ShaderResourceView Ptr Ptr )
	Method CreateRenderTargetView( resource:ID3D10Resource Ptr, desc:Byte Ptr, rendertargetview:ID3D10RenderTargetView Ptr Ptr )
	Method CreateDepthStencilView( resource:ID3D10Resource Ptr, desc:Byte Ptr, depthstencilview:ID3D10DepthStencilView Ptr Ptr )
	
	Method CreateInputLayout( desc:Byte Ptr, numelements:Int, bytecode:Byte Ptr, codelength:Int, layout:ID3D10InputLayout Ptr Ptr )
	Method CreateVertexShader( bytecode:Byte Ptr, codelength:Int, vertexshader:ID3D10VertexShader Ptr Ptr )
	Method CreateGeometryShader( bytecode:Byte Ptr, codelength:Int, geometryshader:ID3D10GeometryShader Ptr Ptr )
	Method CreateGeometryShaderWithStreamOutput( bytecode:Byte Ptr, codelength:Int, declaration:Byte Ptr, numentries:Int, streamstride:Int, geometryshader:ID3D10GeometryShader Ptr Ptr )
	Method CreatePixelShader( bytecode:Byte Ptr, codelength:Int, pixelshader:ID3D10PixelShader Ptr Ptr )
	
	Method CreateBlendState( desc:Byte Ptr, state:ID3D10BlendState Ptr Ptr )
	Method CreateDepthStencilState( desc:Byte Ptr, state:ID3D10DepthStencilState Ptr Ptr )
	Method CreateRasterizerState( desc:Byte Ptr, state:ID3D10RasterizerState Ptr Ptr )
	Method CreateSamplerState( desc:Byte Ptr, state:ID3D10SamplerState Ptr Ptr )
	
	Method CreateQuery( desc:Byte Ptr, query:ID3D10Query Ptr Ptr )
	Method CreatePredicate( desc:Byte Ptr, predicate:ID3D10Predicate Ptr Ptr )
	Method CreateCounter( desc:Byte Ptr, counter:ID3D10Counter Ptr Ptr )
	
	Method CheckFormatSupport( format:Int, support:Int Ptr )
	Method CheckMultisampleQualityLevels( format:Int, samplecount:Int, numqualitylevels:Int Ptr )
	Method CheckCounterInfo( counterinfo:Byte Ptr )
	Method CheckCounter( desc:Byte Ptr, countertype:Int Ptr, active:Int Ptr, name$z, namelength:Int, units$z, unitslength:Int, description$z, descriptionlength:Int )
	
	Method GetCreationFlags( )
	Method OpenSharedResource( res:Int, returned:Byte Ptr, resource:Byte Ptr Ptr )
	Method SetTextFilterSize( width:Int, height:Int )
	Method GetTextFilterSize( width:Int Ptr, height:Int Ptr )
End Type

Type ID3D10DeviceChild Extends IUnknown
	Method GetDevice( device:ID3D10Device Ptr Ptr )
	Method GetPrivateData( guid:Byte Ptr, size:Int Ptr, data:Byte Ptr )
	Method SetPrivateData( guid:Byte Ptr, size:Int, data:Byte Ptr )
	Method SetPrivateDataInterface( guid:Byte Ptr, data:IUnknown Ptr )
End Type

Type ID3D10Inlcude
	Method Open( includetype:Int, filename$z, parentdata:Byte Ptr, data:Byte Ptr Ptr, bytes:Int Ptr )
	Method Close( data:Byte Ptr )
End Type

Type ID3D10InfoQueue Extends IUnknown
	Method SetMessageCountLimit( limit:Long )
	Method ClearStoredMessage( )
	Method GetMessage( index:Long, message:Byte Ptr, length:Int )
	Method GetNumMessagesAllowedByStorageFilter:Long( )
	Method GetNumMessagesDeniedByStorageFilter:Long( )
	Method GetNumStoredMessages:Long( )
	Method GetNumStoredMessagesAllowedByRetrievalFilter:Long( )
	Method GetNumMessagesDiscardedByMessageCountLimit:Long( )
	Method GetMessageCountLimit:Long( )
	Method AddStorageFilterEntries( filter:Byte Ptr )
	Method GetStorageFilter( filter:Byte Ptr, length:Int )
	Method ClearStorageFilter( )
	Method PushEmptyStorageFilter( )
	Method PushCopyOfStorageFilter( )
	Method PushStorageFilter( filter:Byte Ptr )
	Method PopStorageFilter( filter:Byte Ptr )
	Method GetStorageFilterStackSize:Int( )
	Method AddRetrievalFilterEntries( filter:Byte Ptr )
	Method GetRetrievalFilter( filter:Byte Ptr, length:Int )
	Method ClearRetrievalFilter( )
	Method PushEmptyRetrievalFilter( )
	Method PushCopyOfRetrievalFilter( )
	Method PushRetrievalFilter( filter:Byte Ptr )
	Method PopRetrievalFilter( )
	Method GetRetrievalFilterStackSize( )
	Method AddMessage( category:Int, severity:Int, id:Int, desc$z )
	Method AddApplicationMessage( severity:Int, desc$z )
	Method SetBreakOnCategory( category:Int, enable:Int )
	Method SetBreakOnSeverity( severity:Int, enable:Int )
	Method SetBreakOnID( id:Int, enable:Int )
	Method GetBreakOnCategory:Int( category:Int )
	Method GetBreakOnSeverity:Int( severity:Int )
	Method GetBreakOnID:Int( id:Int )
	Method SetMuteDebugOutput( mute:Int )
	Method GetMuteDebugOutput:Int( )
End Type

Type ID3D10Multithread Extends IUnknown
	Method Enter( )
	Method Leave( )
	Method SetMultithreadProtected( protect:Int )
	Method GetMultithreadProtected:Int( )
End Type

Type ID3D10Predicate Extends ID3D10Query
End Type


Type ID3D10Query Extends ID3D10Asynchronous
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10SwitchToRef Extends IUnknown
	Method SetUseRef( useref:Int )
	Method GetUseRef:Int( )
End Type

' Resource Interfaces

Type ID3D10Buffer Extends ID3D10Resource
	Method Map( maptype:Int, flags:Int, data:Byte Ptr Ptr )
	Method Unmap( )
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10Resource Extends ID3D10DeviceChild
	Method GetType( rtype:Int Ptr )
	Method SetEvictionPriority( priority:Int )
	Method GetEvictionPriority:Int( )
End Type

Type ID3D10Texture1D Extends ID3D10Resource
	Method Map( subres:Int, maptype:Int, flags:Int, data:Byte Ptr Ptr )
	Method Unmap( subres:Int )
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10Texture2D Extends ID3D10Resource
	Method Map( subres:Int, maptype:Int, flags:Int, tex:Byte Ptr )
	Method Unmap( subres:Int )
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10Texture3D Extends ID3D10Resource
	Method Map( subres:Int, maptype:Int, flags:Int, tex:Byte Ptr Ptr )
	Method Unmap( subres:Int )
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10DepthStencilView Extends ID3D10View
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10RenderTargetView Extends ID3D10View
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10ShaderResourceView Extends ID3D10View
	Method GetDesc( desc:Byte Ptr )
End Type

Type ID3D10View Extends ID3D10DeviceChild
	Method GetResource( resource:ID3D10Resource Ptr Ptr )
End Type

' Shader Interfaces

Type ID3D10VertexShader Extends ID3D10DeviceChild
End Type

Type ID3D10GeometryShader Extends ID3D10DeviceChild
End Type

Type ID3D10PixelShader Extends ID3D10DeviceChild
End Type

Type ID3D10ShaderReflection
	' TODO
End Type

Type ID3D10ShaderReflectionConstantBuffer
	' TODO
End Type

Type ID3D10ShaderReflectionType
	' TODO
End Type

Type ID3D10ShaderReflectionVariable
	' TODO
End Type

End Extern