Hello! I have drawing layers. Each layer has its own RenderTarget2D. Each layer sets its rendertarget to the graphics device before drawing, and sets null at the end of drawing. Then all RenderTarget from each layer are drawn in turn. The problem is that I use two KNI projects: Windows and Desktops. Everything works fine only on Windows. If I run the project DesktopGL, then the first frame draws all my objects normally, and then the textures all disappear. And if I use a purely Monogame project, then there are no such problems there. Can you tell me what the problem might be?
foreach (var layer in layers)
{
if(camera != null)
{
if (!camera.Layer.HasFlag(layer.Key))
continue;
matrix = camera.Projection;
}
RenderComponents renderComponents = layer.Value;
// The layer code is executed here
renderComponents.Begin(spriteBatch, SpriteSortMode.FrontToBack, null, null, null, null, null, matrix);
renderComponents.Draw(spriteBatch);
renderComponents.End(spriteBatch);
}
GraphicsDevice.Clear(Color.CornflowerBlue);
// Here we draw each RenderTarget from each layer with Position zero and Color.White
foreach (var item in layers.Values)
{
spriteBatch.Begin(SpriteSortMode.Immediate);
spriteBatch.Draw(item.RenderTarget2D);
spriteBatch.End();
}
We do not know if the issue has anything to do with rendertargets or is something else.
For example we do not know with what parameters you create the rendertargets, if you are ‘eating’ exceptions, if matrix is set, or any other logical error.
You have to start reducing your code down to a workable test case.
Usually by the time you are halfway in the process you will discover the bug yourself.
This is with the latest version 3.8.9201, correct?
My apologies. I checked the code without using RenderTarget2D - the problem is the same, only the first frame draws everything, and the next frames do not. I’m trying to figure it out. A little later I will write about the result of the work.
It detach the IndexBuffer, but it doesn’t set the _indexBufferDirty.
In fact, we don’t need to detach the indexBuffer. DrawArrays(…) operate on the VertexBuffer alone.
DrawUserPrimitives is used by the Physics2D.Diagnostics, so for now you would need to disable it until the next version.