Skip to main content
GameDev.net gamedev.net
🔒 Locked

[SlimDX] blend state

Started by ucfchuck Sep 19, 2008 at 11:19 AM 12 replies 5.7k views
Original Post
ucfchuck
ucfchuck
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?
jpetrie
jpetrie
Once you create a SlimDX.Direct3D10.BlendState you can set it by assigning it to SlimDX.Device.OutputMerger.BlendState.
ucfchuck
ucfchuck
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
jpetrie
jpetrie
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.
ucfchuck
ucfchuck
so how do you create modify and set the blend state?
jpetrie
jpetrie
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.
ucfchuck
ucfchuck
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.

jpetrie
jpetrie
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.
ucfchuck
ucfchuck
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?
sirob
sirob
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.
ucfchuck
ucfchuck
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)
sirob
sirob
Make sure you're passing the Debug flag at device creation and look in the Output window in VS (View -> Output).
Sirob Yes.» - status: Work-O-Rama.
ucfchuck
ucfchuck
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]
ucfchuck
ucfchuck
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;
};

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.