Testing a custom mesh type that I'm using by rendering some simple quads and have ran into a problem.
Edit: I think I'm just misunderstanding how this whole drawCall thing works in XNA. Messing with different commenting out arrangements is given me a lot of results compared to what I expected. Does it have something to do with Pass? Is there a way to like commit it?
First frame rendered looks this:
[attachment=10271:Frame1.PNG]
All others this:
[attachment=10272:OtherFrames.PNG]
Well first off all the red color data is in the otherchild item or the one that doesn't render the first time through for some reason. If I remove the otherchild draw call it becomes white like it should be. If I draw only 1 of the buffers it works fine, but not with 2.
Evidence that otherchild should be Red but not sprite is in the code below. I have also thoroughly verified with a debugger that the data in the VertexBuffer when I call SetData() is correct. So I am positive the issue is with how I am setting the buffers because it is rendering each sprite with the wrong buffer and their is no reference that exists between the 2 sprites that exists.
Sprite sprite = new Sprite();
Sprite otherchild = new Sprite();
Effect basic;
Camera2D camera;
protected override void Initialize()
{
new GameEngine(this, graphics);
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load<SpriteFont>("SegoeUIMono");
GameEngine.settings = Content.Load<Settings>("XMLFile1");
basic = Content.Load<Effect>("Basic");
sprite.quad.SetData();
otherchild.quad.color = Color.Red;
otherchild.quad.SetData();
sprite.transform.AddChild(otherchild.transform);
sprite.transform.scale = new Vector2(2.5f, 2.5f);
otherchild.transform.scale = new Vector2(2.0f,1.0f);
otherchild.transform.localPosition = new Vector3(3.0f, 0.0f, 0.0f);
camera = new Camera2D(0.1f,100.0f,50.0f,50.0f);
camera.transform.localPosition = new Vector3(0.0f, 0.0f, -10.0f);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Gray,1.0f,0);
basic.CurrentTechnique.Passes[0].Apply();
basic.Parameters["World"].SetValue(sprite.transform.world);
basic.Parameters["ViewProjection"].SetValue(camera.ViewProjectionMatrix);
sprite.Draw();
basic.CurrentTechnique.Passes[0].Apply();
basic.Parameters["World"].SetValue(otherchild.transform.world);
basic.Parameters["ViewProjection"].SetValue(camera.ViewProjectionMatrix);
otherchild.Draw();
GraphicsDevice.Present();
}
SpriteClass Draw() looks like this
public void Draw()
{
if (quad.hasBuffers)
{
GameEngine.graphicsDevice.Indices = quad.IndexBuffer;
GameEngine.graphicsDevice.SetVertexBuffer(quad.VertexBuffer);
GameEngine.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,quad.vertices.Length, 0,2);
}
}
Any reason that the wrong buffer would be used like that? I'm running out of things to check : /