Sign in to follow this  
ucfchuck

[SlimDX] blend state

Recommended Posts

can anyone point me in the direction of an example of how to set the blend state for slimdx using d3d10. the regular sdk supports a setblendstate or something but i havent been able to find an equivalent function in slimdx?

Share this post


Link to post
Share on other sites
SlimDX.Direct3D10.BlendStateDescription statedescr= new SlimDX.Direct3D10.BlendStateDescription();

statedescr.BlendOperation = D3D10.BlendOperation.Maximum;
statedescr.SetBlendEnable(0, true);
statedescr.SetBlendEnable(1, true);
statedescr.SetWriteMask(0, SlimDX.Direct3D10.ColorWriteMaskFlags.All);
statedescr.SetWriteMask(1, SlimDX.Direct3D10.ColorWriteMaskFlags.All);

D3D10.BlendState newstate;
newstate = D3D10.BlendState.FromDescription(g_pd3dDevice, statedescr);
/||\ at this line
An unhandled exception of type 'SlimDX.Direct3D10.Direct3D10Exception' occurred in SlimDX.dll

Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)



how do you set the description values for the newstate? i tried

newstate.Description.BlendOperation = D3D10.BlendOperation.Maximum;

and got the error

Cannot modify the return value of 'SlimDX.Direct3D10.BlendState.Description' because it is not a variable

Share this post


Link to post
Share on other sites
States are immutable in D3D10. Once created you cannot modify the properties for the state; the Description is essentially read-only, and we allow the language semantics to enforce that for us (the description is a value type, which is why you cannot modify the properties of the description returned by the Description getter).

If you enable the debug layer during device creation, and turn on unmanaged debugging, the runtime will provide you with more information about what argument was invalid.

Share this post


Link to post
Share on other sites
You create a blend state object by creating a blend state description and filling it out. Then you provide that description object to D3D10 and ask it for a blend state object that matches that description. In SlimDX, this is done by calling the BlendState constructor.

Then you set that blend state object on the pipeline as previously mentioned. If you want a new set of blend state properties, you create a new description and a new blend state, and set that. In D3D10, you don't modify individual aspects of the current blend state, you maintain a set of the blend states your application will use and set them wholesale when it is time to use them.

You don't modify existing state objects.

Share this post


Link to post
Share on other sites
how do i enable the debug layer during device creation?

i keep getting an error saying :
//////////////////////////////
An unhandled exception of type 'SlimDX.Direct3D10.Direct3D10Exception' occurred in SlimDX.dll

Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

///////////////////////////////

and then

///////////////////////////////
Managed Debugging Assistant 'LoaderLock' has detected a problem in 'G:\Users\chuck\Desktop\code\WindowsFormsApplication3\WindowsFormsApplication3\bin\Debug\WindowsFormsApplication3.vshost.exe'.
Additional Information: DLL 'G:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.Direct3D.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Share this post


Link to post
Share on other sites
Quote:

how do i enable the debug layer during device creation?

When you create the D3D10 Device, pass DeviceCreationFlags.Debug.

Quote:

Managed Debugging Assistant 'LoaderLock' has detected a problem in 'G:\Users\chuck\Desktop\code\WindowsFormsApplication3\WindowsFormsApplication3\bin\Debug\WindowsFormsApplication3.vshost.exe'.
Additional Information: DLL 'G:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.Direct3D.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Note my added emphasis to the error message: This is a well-known problem with Managed DirectX. Why are you using Managed DirectX and SlimDX at the same time? SlimDX is designed to replace MDX; you don't need to use them concurrently, and in fact I can't think of a good reason you'd really want to.

Remove the reference to the MDX assemblies.

Share this post


Link to post
Share on other sites
the mdx stuff was just from a previous attempt at debugging something else, so i removed all references to it, the DeviceCreationFlags.Debug was already being set, and i turned on unmanaged debugging. but still i only get the one error code and no more info on the problem. its still just

An unhandled exception of type 'SlimDX.Direct3D10.Direct3D10Exception' occurred in SlimDX.dll

Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)


is this all meant to be handled in the fx file or something?

Share this post


Link to post
Share on other sites
You need to enable unmanaged debugging in the Visual Studio options (Tools -> Options -> Debugging).

If you're using Express, this option isn't available (I think). If you have express, you can use debugview to capture the debug output (this works if you don't have Express, too).

Share this post


Link to post
Share on other sites
im on vs2008 full edition. there is no unmanaged debugging option in the tools->options->debugging. i found it in properties->debug where it has a thing for enabling unmanaged code debugging. but it doesnt give me anymore information.
just
An unhandled exception of type 'SlimDX.Direct3D10.Direct3D10Exception' occurred in SlimDX.dll

Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

Share this post


Link to post
Share on other sites
Make sure you're passing the Debug flag at device creation and look in the Output window in VS (View -> Output).

Share this post


Link to post
Share on other sites
usercontrol.g_pd3dDevice = new D3D10.Device(D3D10.DeviceCreationFlags.Debug);

and in the output window, "Show output from : Debug" and there are a ton of loaded dlls and everything up until :

...
'WindowsFormsApplication3.exe': Loaded 'G:\Windows\System32\d3dx10_38.dll'
'WindowsFormsApplication3.exe': Loaded 'G:\Windows\System32\D3DCompiler_38.dll'
'WindowsFormsApplication3.exe': Loaded 'G:\Windows\System32\d3d10_1.dll'
'WindowsFormsApplication3.exe': Loaded 'G:\Windows\System32\d3d10_1core.dll'
'WindowsFormsApplication3.exe': Loaded 'G:\Windows\System32\D3DX9_38.dll'
An unhandled exception of type 'SlimDX.Direct3D10.Direct3D10Exception' occurred in SlimDX.dll

Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

The thread 'Win32 Thread' (0x11bc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xf6c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x12fc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1604) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x121c) has exited with code 0 (0x0).
The program '[5164] WindowsFormsApplication3.exe: Managed' has exited with code 0 (0x0).
The program '[5164] WindowsFormsApplication3.exe: Native' has exited with code 0 (0x0).



from this code, where it crashes at the BlendState.FromDescription():

D3D10.BlendStateDescription statedescr = new D3D10.BlendStateDescription();

statedescr.BlendOperation = D3D10.BlendOperation.Maximum;
statedescr.SetBlendEnable(0, true);
statedescr.SetBlendEnable(1, true);
statedescr.SetWriteMask(0, SlimDX.Direct3D10.ColorWriteMaskFlags.All);
statedescr.SetWriteMask(1, SlimDX.Direct3D10.ColorWriteMaskFlags.All);
statedescr.DestinationBlend = SlimDX.Direct3D10.BlendOption.DestinationColor;
statedescr.SourceBlend = SlimDX.Direct3D10.BlendOption.SourceColor;
D3D10.BlendState newstate = D3D10.BlendState.FromDescription(g_pd3dDevice, statedescr);
g_pd3dDevice.OutputMerger.BlendState = newstate;



?????

You create a blend state object by creating a blend state description and filling it out.

D3D10.BlendStateDescription statedescr = new D3D10.BlendStateDescription();

statedescr.BlendOperation = D3D10.BlendOperation.Maximum;
statedescr.SetBlendEnable(0, true);
statedescr.SetBlendEnable(1, true);
statedescr.SetWriteMask(0, SlimDX.Direct3D10.ColorWriteMaskFlags.All);
statedescr.SetWriteMask(1, SlimDX.Direct3D10.ColorWriteMaskFlags.All);
statedescr.DestinationBlend = SlimDX.Direct3D10.BlendOption.DestinationColor;
statedescr.SourceBlend = SlimDX.Direct3D10.BlendOption.SourceColor;

Then you provide that description object to D3D10 and ask it for a blend state object that matches that description. In SlimDX, this is done by calling the BlendState constructor.

D3D10.BlendState newstate = D3D10.BlendState.FromDescription(g_pd3dDevice, statedescr);


Then you set that blend state object on the pipeline as previously mentioned.

g_pd3dDevice.OutputMerger.BlendState = newstate;


[Edited by - ucfchuck on September 22, 2008 4:54:48 PM]

Share this post


Link to post
Share on other sites
nevermind, im just using hlsl stuff for it now. basically straight out of tutorial 14 from the sdk
BlendState SrcColorBlendingAdd
{
BlendEnable[0] = TRUE;
BlendEnable[1] = TRUE;
SrcBlend = SRC_COLOR;
DestBlend = ONE;//DEST_COLOR;
BlendOp = ADD;
SrcBlendAlpha = ZERO;
DestBlendAlpha = ZERO;
BlendOpAlpha = ADD;
RenderTargetWriteMask[0] = 0x0F;
};

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this