Game Development Reference
In-Depth Information
DeviceCreationFlags.Debug , which creates a Direct3D device that supports
the debug layer. Of course, you would change this to something else before you re-
lease your game, since the debug code slows down the game and hurts perform-
ance.
The third parameter specifies feature levels. In this case, we have only used
FeatureLevel.Level_11_0 , which means we want the Direct3D 11 features. As
this parameter is an array, you can, of course, provide more than one feature level if
your program needs to support more levels.
Thefourth parameterisour SwapChainDescription object, andthelasttwopara-
meters begin with the out keyword. This means they are actually output from the
function, or in other words, the variables we pass in are modified by the function to
return data. In this case, the fifth parameter is our m_Device member variable, and
the sixth parameter is our m_SwapChain variable. So this function creates the Dir-
ect3D device and stores it in the variable we passed into the fifth parameter. And it
also creates the swap chain, storing it in the variable that we passed into the sixth
parameter.
The next thing we need to do is create our render target. As you can see, the next
piece of code is a using block, which creates a SlimDX.Direct3D11.Resource
object using the Resource class's static method, FromSwapChain() . The <Tex-
ture2D> part of this line indicates that the function is generic . A generic method
is one that allows you to specify a data type when you call it. In other words, it is a
function that is able to act on multiple data types, whereas a normal function can't
do that. In this case, we have specified the data type of Direct3D11.Texture2D .
A Texture2D object represents an image. The FromSwapChain() method takes
two parameters. The first one is the swap chain we want to create the resource from,
and the second parameter is the index of one of the buffers in that swap chain.
Then, inside of this using statement, we have a single line of code that creates our
RenderTargetView object. This object is essentially our render target. As you can
see, we pass in two parameters when we create the RenderTargetView object.
The first parameter isour Direct3D device, and the second parameter isthe resource
we just created.
The next line of code stores the Direct3D device context in our m_DeviceContext
membervariable.Rememberthatthisvariableisjustforconvenience.Usingitallows
Search WWH ::




Custom Search