• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ranakor

DX11
C++ DX API, help me get it?

14 posts in this topic

Ok so i'm coming from a .net background (multiple years of professional development).

I'm checking out microsoft DX11 samples and i just don't get it, am i missing something obvious & there's actually beauty there i'm not seeing? Or is this actually just flat ugly hard code for no reason? Is it legacy or are you actually supposed to write & consume APIs this way?

(just to be clear, this is half rant, half question, i'd be more than happy to learn my rant is unfounded & have this transition from a rant to an answered question, also i'm not saying i'm having a hard time, just to be clear i understand the sample perfectly fine, i just find it painstakingly hard for no reason).

 

Shed some light on all this for me

1) Why the hell is this so damn long & hard? I expected getting a DX11 window up & running (and rendering) with nothing inside to be a 10liner or so, maybe 20 tops, but not 250 like in the sample!

2) Why the typedefs? Seems to be adding confusion for no reason especially on simple types, am i missing something or is this just useless? typedef float               FLOAT

3) Why no constructors? Objects are just declared and initialized element by element, meaning you remove 1 line you don't get a default, you don't even get an exception, you get a nice access violation!

4) Why all the if(failed(bla)) ? Why isn't code throwing?

5) Probably the same as 3 but, why no sensible default values for everything? Declaring any directX object seems to be a full time job & a 10 liner!

6) Why is everything taking a pointer? I get the point for large (or medium) objects but why for example does something like the feature level, which isn't a large object nor an array, and that you're likely to be using once (or hell, maybe twice!) in your whole application get passed by pointer? I'm new at C++ but unless i get it wrong it means you must create a (local or global) variable, assign a value to it, and pass a pointer to it, if it was by reference you could just pass in D3D_FEATURE_LEVEL_11_0 for example

7) Typedef question again, it's confusing enough for float => FLOAT, but hell LPVOID*, i can't believe people starting with C++ make it through this!

8) __uuidof, so you even need custom keywords to get a simple directX sample app going on???

 

I'm not trying to bash C++ here, the only things i can't bare in it are header files and compilation speed, but i just don't get that API design, is it flaws in the API or in the sample? Or am i just getting it wrong? Because if this is the right way to do it this sounds just horrible to me, 250 lines to do nothing, 3X that much for a rotating cube (out of which only 60 lines are rendering, and about 300 setting up the device . . . ). I just don't get it! Hell SharpDX didn't feel that way at all.

 

I'm waiting, please enlighten me!

1

Share this post


Link to post
Share on other sites

Allow me to pick off part of #6:

 

D3D11CreateDeviceAndSwapChain has two parameters that accept pointers to D3D_FEATURE_LEVEL. The first one is a pointer because it is actually looking for an array of D3D_FEATURE_LEVEL (and the parameter following that one is the number of elements in the array). The second one is a pointer because it is an output parameter to where the feature level that was actually selected can be stored.

 

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476083(v=vs.85).aspx

 

[EDIT]

Also, I expect that a lot of the reasons for the API being structured how it is are due to http://en.wikipedia.org/wiki/Component_Object_Model

Edited by jrh2365
2

Share this post


Link to post
Share on other sites

1) Short version, modern languages and frameworks tend to do a lot of the work for you. This is the raw api.

2) typedef float FLOAT, might become typedef double FLOAT in the future, dont need to change as much later you can redefine FLOAT.

3) Windows has a long history with C, it tends to be the main focus when extending the windows apis, C has no constructors

4) see 3

5) see 3

6) see 3

7) see 3

8) see 3

0

Share this post


Link to post
Share on other sites

That's why I keep my distance from C++! Even in C# you need to write a lot of code just to set up a device. It is certainly nicer to look at, less * and & :D But once you begin writing your engine you can abstract away all that. In my own engine everything boils down to a call to DeviceManager.Initialize where I pass my own settings structure... and that's that.

0

Share this post


Link to post
Share on other sites

One thing not a lot of people realize is that most of the Windows API samples are written so that non-C and C++ programmers will understand them. For instance, when initializing structs the API samples will use ZeroMemory() despite the fact that = {} will do the same thing. However, non-C or C++ programmers won't necessarily understand that, so the explicit ZeroMemory() call is used instead.

2

Share this post


Link to post
Share on other sites

Ok so as i expected most of it is to be blamed on legacy or COM, actually makes me quite happy to hear that.

 

Is there any library on the C++ side that does the same as SharpDX for .net? (keep the same low level API access, but wrap it in namespaced classes with default constructors etc, something that would feel more "modern C++ish" without being an engine but that would be a good base for starting one without doing my own wrappers on everything?)

0

Share this post


Link to post
Share on other sites
4) Why all the if(failed(bla)) ? Why isn't code throwing? 

 

 NEVER use exceptions in C++! I love HRESULT error codes
 

6) Why is everything taking a pointer? I get the point for large (or medium) objects but why for example does something like the feature level, which isn't a large object nor an array, and that you're likely to be using once (or hell, maybe twice!) in your whole application get passed by pointer? I'm new at C++ but unless i get it wrong it means you must create a (local or global) variable, assign a value to it, and pass a pointer to it, if it was by reference you could just pass in D3D_FEATURE_LEVEL_11_0 for example

 

 Use CComPtr(atlbase.h) if you dont like pointers...

 

LPVOID

 

well.... i really dont care about PVOID LPVOID FLOAT ect...


D3D is designed for performance and user-control.. If you dont like that then you can use something like irrlicht/ogre/panda/whatever

0

Share this post


Link to post
Share on other sites

 

4) Why all the if(failed(bla)) ? Why isn't code throwing? 

 

 NEVER use exceptions in C++! I love HRESULT error codes
 

6) Why is everything taking a pointer? I get the point for large (or medium) objects but why for example does something like the feature level, which isn't a large object nor an array, and that you're likely to be using once (or hell, maybe twice!) in your whole application get passed by pointer? I'm new at C++ but unless i get it wrong it means you must create a (local or global) variable, assign a value to it, and pass a pointer to it, if it was by reference you could just pass in D3D_FEATURE_LEVEL_11_0 for example

 

 Use CComPtr(atlbase.h) if you dont like pointers...

 

LPVOID

 

well.... i really dont care about PVOID LPVOID FLOAT ect...


D3D is designed for performance and user-control.. If you dont like that then you can use something like irrlicht/ogre/panda/whatever

 

None of this relates to performance at all, unless you consider "setting up directx" a performance critical part of any application where it's important to saveup nanoseconds in object instantiation and saving 4 bytes copies here & there? Performance is no reason here (i could get it if it was in per frame actions, but just not here), nor does it relate to user control at all. Anyway i already had my answers earlier on this thread, it's just com limitations & legacy code.

 

So now just looking for a thin wrapper around it, NOT an engine, something like a directX for actual C++ and not com/C.

Anyone could recommand such a thing? Something very thin where i could still refer to DX documentation, but just use it in a more "modern C++" way, C++11 is fine (within visual studio 2013's limitations)

0

Share this post


Link to post
Share on other sites


None of this relates to performance at all

 

Exceptions have a noticeable performance impact, which is one of the reasons many game projects at least do not use them. From that perspective it makes sense from an API point of view to not rely on them (in addition to C legacy)

 

I don't know of any wrappers like that you are describing, but you could take just the API abstraction layer of any openly available engine and start with that instead of interfacing directly with d3d if you really wanted to. It would be better to use it natively if you want to learn how it works though I think.
 

2

Share this post


Link to post
Share on other sites


None of this relates to performance at all, unless you consider "setting up directx" a performance critical part of any application where it's important to saveup nanoseconds in object instantiation and saving 4 bytes copies here & there? Performance is no reason here (i could get it if it was in per frame actions, but just not here), nor does it relate to user control at all. Anyway i already had my answers earlier on this thread, it's just com limitations & legacy code.

 

Setting up DirectX can be a "performance critical" part. Just depends whom you work for. 

Some places have STRICT requirements on startup times.

Last company i worked at our game window had to be up and displaying something in under three seconds or all hell broke loose.

0

Share this post


Link to post
Share on other sites

Jason Z's (http://hieroglyph3.codeplex.com/) has really good wrappers!

 

Like he said, Hieroglyph 3 is a layered framework that can be used at a high level or at a lower level.  At the very least, you can take a look at it and see if it does what you want.  There are lots of sample applications, ranging from very simple (just clearing the window to a different color) all the way up to volume rendering, Kinect integration, and deferred/light pre-pass rendering.

 

If you want something very light, you can grab pieces of the framework and use them as you see fit - it is licensed under MIT, so it is quite liberal for you to use.

0

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  
Followers 0

  • Similar Content

    • By lonewolff
      Hi Guys,
      I am revisiting an old DX11 framework I was creating a while back and am scratching my head with a small issue.
      I am trying to set the pixel shader resources and am getting the following error on every loop.
      As you can see in the below code, I am clearing out the shader resources as per the documentation. (Even going overboard and doing it both sides of the main PSSet call). But I just can't get rid of the error. Which results in the render target not being drawn.
      ID3D11ShaderResourceView* srv = { 0 }; d3dContext->PSSetShaderResources(0, 1, &srv); for (std::vector<RenderTarget>::iterator it = rtVector.begin(); it != rtVector.end(); ++it) { if (it->szName == name) { //std::cout << it->srv <<"\r\n"; d3dContext->PSSetShaderResources(0, 1, &it->srv); break; } } d3dContext->PSSetShaderResources(0, 1, &srv);  
      I am storing the RT's in a vector and setting them by name. I have tested the it->srv and am retrieving a valid pointer.
      At this stage I am out of ideas.
      Any help would be greatly appreciated
       
    • By bowerbirdcn
      hi, guys, how to understand the math used in CDXUTDirectionWidget ::UpdateLightDir 
      the  following code snippet is taken from MS DXTU source code
       
        D3DXMATRIX mInvView;
          D3DXMatrixInverse( &mInvView, NULL, &m_mView );
          mInvView._41 = mInvView._42 = mInvView._43 = 0;
          D3DXMATRIX mLastRotInv;
          D3DXMatrixInverse( &mLastRotInv, NULL, &m_mRotSnapshot );
          D3DXMATRIX mRot = *m_ArcBall.GetRotationMatrix();
          m_mRotSnapshot = mRot;
          // Accumulate the delta of the arcball's rotation in view space.
          // Note that per-frame delta rotations could be problematic over long periods of time.
          m_mRot *= m_mView * mLastRotInv * mRot * mInvView;
          // Since we're accumulating delta rotations, we need to orthonormalize 
          // the matrix to prevent eventual matrix skew
          D3DXVECTOR3* pXBasis = ( D3DXVECTOR3* )&m_mRot._11;
          D3DXVECTOR3* pYBasis = ( D3DXVECTOR3* )&m_mRot._21;
          D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&m_mRot._31;
          D3DXVec3Normalize( pXBasis, pXBasis );
          D3DXVec3Cross( pYBasis, pZBasis, pXBasis );
          D3DXVec3Normalize( pYBasis, pYBasis );
          D3DXVec3Cross( pZBasis, pXBasis, pYBasis );
       
       
      https://github.com/Microsoft/DXUT/blob/master/Optional/DXUTcamera.cpp
    • By YixunLiu
      Hi,
      I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
      Anybody know a fast method to calculate the intersected boundary of these two geometries?
       
      Thanks.
       
      YL
       
    • By hiya83
      Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
      Thanks!
    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
  • Popular Now