[SlimDX] blend state

Started by
12 comments, last by ucfchuck 15 years, 6 months ago
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?
Advertisement
Once you create a SlimDX.Direct3D10.BlendState you can set it by assigning it to SlimDX.Device.OutputMerger.BlendState.
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
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.
so how do you create modify and set the blend state?
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.
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.

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.
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?
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).
Sirob Yes.» - status: Work-O-Rama.

This topic is closed to new replies.

Advertisement