Jump to content
  • Advertisement
Sign in to follow this  

DX11 SharpDX not similar to D11/c++?

This topic is 2038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts




I just read a Dx11 Book to understand the API, i would translate it to C#/SharpDX.


But the Book describes the way to create a VertexBuffer like:


first the Description:

desc.ByteWidth = size; 
desc.MiscFlags = 0; 
desc.StructureByteStride = 0; 

So in SharpDX i don't have MiscFlags and ByteWidth ....


next, create the Buffer:

HRESULT hr = g_pDevice->CreateBuffer( &desc, pData, &pBuffer ); 

in SharpDX MiniCube Demo the way to create a Buffer:

var vertices = Buffer.Create(device, BindFlags.VertexBuffer, new[]{......});

Here is a difference with C++D3D and Sharpdx..




Or to create DeviceContext/SwapChain. 




and SharpDX:


I thought  SharpDX and C++ D3D are similar, why are the difference?



So now my question is: When i reading this book how i find die right SharpDX Commands to recreate in SharpDX?




Sorry for my english i hope you understand what i mean and can give me a answer..




Edited by montify

Share this post

Link to post
Share on other sites
  • Google 'SharpDX' combined with the native name. First hit for 'sharpdx D3D11_BUFFER_DESC' leads me to the doc page. The C# and native identifiers are listed in table form.
  • Design follows C# idioms and what the language can resp. can't do compared to C++. E.g. free functions end up as public static functions tied to the class making the most sense. The samples you gave are constructors in nature, and since C# constructor cannot be named arbitrarily they end up as ... public static. You will learn where to look as you're learning the DX API.
  • The native memory/pointer related stuff ends up as C# arrays, usually. Though you could go raw pointers in C#, too, I don't recommend doing so. Get familiar with the DataStream class and the magic of generics. SharpDX has many (generic) convenience functions anyway.
  • Intellisense (if you're using VS) is also nice to find stuff quickly.
By the way: Which Book ? Luna's ?

Share this post

Link to post
Share on other sites

SharpDX does reorganise the API a little, but it is done consistently and it is done so that it makes more sense to how you would do things in C#. You do need to be careful that objects are being disposed of correctly, e.g. if you frequently set the rasterizer state (which is set using a property) without disposing of the previous you will introduce memory leaks.


I've just had a book published on using SharpDX with Direct3D - Direct3D Rendering Cookbook, the first chapter outlines some of the mappings between the native and managed API. Amazon provides a preview of some of this chapter that you may find useful.


The second chapter "Rendering with Direct3D" provides examples of how to create vertex buffers, here is an excerpt of the code used for a simple triangle renderer:

            // Create a triangle
            triangleVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] {
            /*  Vertex Position                       Vertex Color */
                new Vector4(0.0f, 0.0f, 0.5f, 1.0f),  new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Base-right
                new Vector4(-0.5f, 0.0f, 0.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Base-left
                new Vector4(-0.25f, 1f, 0.25f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // Apex
            triangleBinding = new VertexBufferBinding(triangleVertices, Utilities.SizeOf<Vector4>() * 2, 0);



Edited by spazzarama

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!