Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectXTK - how to reset winding order/RH-to-LH after sprite batch?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Buckeye   Crossbones+   -  Reputation: 4448

Like
0Likes
Like

Posted 18 May 2014 - 04:52 PM

Problem: DirectXTK SpriteFont/SpriteBatch set a state I can't determine. I want to be able to reset whatever it's doing. Looking for information.

 

Setup: D3D11, DirectXTK, Windows 7, Windows SDK 8.1

 

I'm trying out the DirectXTK and using SpriteFont/SpriteBatch for text. Some state gets changed which, after googling, examining code, reading docs, etc., I haven't been able to determine.

 

The symptom is that meshes rendered with LH projection and rasterstate set to cull-back-face appear ... I'm guessing... maybe RH or cull-front-face.. I can't tell for sure.

 

Before:

captured11_before.png

 

After drawing text with font/spritebatch:

captured11.png

// initialization
    g_States.reset(new CommonStates(g_pd3dDevice));
    g_Sprites.reset(new SpriteBatch(g_pImmediateContext));
    g_Font.reset(new SpriteFont(g_pd3dDevice, L"c:\\visualstudio\\d11engine4\\DirectXTK\\italic.spritefont"));

    ....
// rendering
    if (bViewStats) // turns on and off text display
    {
        g_Sprites->Begin(SpriteSortMode_Deferred);
        g_Font->DrawString(g_Sprites.get(), L"DirectXTK Simple Sample", XMFLOAT2(100, 10), Colors::Yellow);
        g_Sprites->End();
    }

Yeah, I copied and pasted some code from the DirectXTK simple sample - but I have tried to find the answer. Really.

 

Any help?


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


Sponsor:

#2 unbird   Crossbones+   -  Reputation: 4973

Like
2Likes
Like

Posted 18 May 2014 - 05:40 PM

I wonder if this (only) the winding. Rather looks like depth is failing.

 

Hmmm... have a look at SpriteBatch::Impl::PrepareForRendering, seems depth stencil state is changed, too. 

 

Edit: From a quick glance, it doesn't look like states are reset automatically (SpriteBatch::End()), so you probably have to do that yourself.


Edited by unbird, 18 May 2014 - 05:52 PM.


#3 Buckeye   Crossbones+   -  Reputation: 4448

Like
0Likes
Like

Posted 18 May 2014 - 08:24 PM

As always, unbird, you lead me in the right direction. I created a default depth stencil state and set that state after the sprite batch call. Works like a champ.

 

In case anyone's interested, these are the states that are set by SpriteBatch::Begin()

    auto blendState        = mBlendState        ? mBlendState.Get()        : mDeviceResources->stateObjects.AlphaBlend();
    auto depthStencilState = mDepthStencilState ? mDepthStencilState.Get() : mDeviceResources->stateObjects.DepthNone();
    auto rasterizerState   = mRasterizerState   ? mRasterizerState.Get()   : mDeviceResources->stateObjects.CullCounterClockwise();
    auto samplerState      = mSamplerState      ? mSamplerState.Get()      : mDeviceResources->stateObjects.LinearClamp();

In my render routine, I set the appropriate rasterizer state (both fillmode and cullmode) and the blend state as needed for various draw routines. Sampler states are set in each shader. That sets all but the depthstencilstate. So I revised my render routine:

    if (bViewStats)
    {
        g_Sprites->Begin(SpriteSortMode_Deferred);
        g_Font->DrawString(g_Sprites.get(), L"DirectXTK Simple Sample", XMFLOAT2(100, 10), Colors::Yellow);
        g_Sprites->End();
        g_pImmediateContext->OMSetDepthStencilState(pDefaultDepthStencilState, D3D11_COMPARISON_LESS); // restore the default
    }

I salute you! And, if anyone cares, the pix below is a PNG frame capture showing GDI, GDI+ and DirectXTK font rendering all playing nice in the backbuffer.

Attached Thumbnails

  • captured11.png

Edited by Buckeye, 18 May 2014 - 08:28 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#4 L. Spiro   Crossbones+   -  Reputation: 13306

Like
0Likes
Like

Posted 18 May 2014 - 09:42 PM

I don’t know about DirectXTK, but if it is based around ID3DXSprite then it should have a flag similar to that of D3DXSPRITE_DONOTMODIFY_RENDERSTATE in Begin().
This is one of the most important flags to set as it will kill your performance otherwise (and cause bugs with more sophisticated engine wrappers which remove redundant render states, again for performance).


A quick glance at the documentation reveals they do have a way to override the states they change in Begin().
http://directxtk.codeplex.com/wikipage?title=SpriteBatch&referringTitle=DirectXTK

You should be overriding it to change only what is necessary, and instead of restoring them all only restore as needed. Render-state changes are to be avoided as much as possible.


L. Spiro

Edited by L. Spiro, 18 May 2014 - 09:42 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 Buckeye   Crossbones+   -  Reputation: 4448

Like
0Likes
Like

Posted 18 May 2014 - 09:57 PM


A quick glance at the documentation reveals they do have a way to override the states they change in Begin().

 

I don't want to override the spritebatch states. I want to restore the states it changes back to what I need for the rest of my routines.

 


You should be overriding it to change only what is necessary, and instead of restoring them all only restore as needed

 

See my post above. I stated that I change the states as needed.


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS