Вопрос

I have a mesh built that I want to view in WireFrame mode. I am currently setting my GraphicsDevice this way...

TheGraphicsDevice.RasterizerState = new RasterizerState()
{
    FillMode = FillMode.WireFrame,
    CullMode = CullMode.None
};

This is doing what I want but it seems I have to set the RasterizerState every time Draw() is called.

Is there a way to set the RasterizerState to WireFrame just once? (Like when I first declare my GraphicsDevice variable?) I've tried every combination I can think of but it seems to only work when I (re-)set it in the Draw() method.

Это было полезно?

Решение

If you are drawing a combination of 3d items and 2d items (using SpriteBatch) then calling spriteBatch.Begin() will reset the fillmode back to solid. So in that case you have to set it to wireframe each frame (or use saveState with your spritebatch) when you draw your 3d items.

If you are only drawing 3d items then you can set it once during initialization and not need to keep resetting it.

If you need to set it each frame, don't do it like your snippet. That's allocating new memory each frame that ends up needing to be gc(ed). Instead, make one custom RasterizationState object and reuse it each frame.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top