- fixed DrawUserIndexPrimitives (issue #531)

This commit is contained in:
Glatzemann 2012-09-20 10:23:03 +00:00 committed by Konstantin Koch
parent 8523993cb2
commit 9414d12668
9 changed files with 102 additions and 44 deletions

View File

@ -413,7 +413,8 @@ namespace ANX.Framework.Graphics
}
set
{
this.viewport = value;
this.viewport = value;
NativeDevice.SetViewport(this.viewport); //TODO: this is not optimal...
}
}

View File

@ -644,7 +644,7 @@ namespace ANX.Framework.Graphics
else if (hash1 < hash2)
return 1;
return 0;
return y.layerDepth.CompareTo(x.layerDepth);
}
}

View File

@ -260,10 +260,19 @@ namespace ANX.RenderSystem.Windows.DX10
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
DxIndexBuffer idx10 = new DxIndexBuffer(nativeDevice, indexFormat, indexCount, BufferUsage.None);
if (indexData.GetType() == typeof(Int16[]))
IndexElementSize indexElementSize;
if (indexData.GetType() == typeof(Int16[]))
{
idx10.SetData<short>(null, (short[])indexData);
indexElementSize = IndexElementSize.SixteenBits;
}
else
{
idx10.SetData<int>(null, (int[])indexData);
indexElementSize = IndexElementSize.ThirtyTwoBits;
}
nativeDevice.InputAssembler.SetIndexBuffer(idx10.NativeBuffer, DxFormatConverter.Translate(indexElementSize), 0);
DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount);
}

View File

@ -32,7 +32,7 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.17.0")]
[assembly: AssemblyFileVersion("0.7.17.0")]
[assembly: AssemblyVersion("0.7.18.*")]
[assembly: AssemblyFileVersion("0.7.18.0")]
[assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")]

View File

@ -275,11 +275,20 @@ namespace ANX.RenderSystem.Windows.DX11
nativeDevice.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
DxIndexBuffer idx10 = new DxIndexBuffer(nativeDevice.Device, indexFormat, indexCount, BufferUsage.None);
DxIndexBuffer idx11 = new DxIndexBuffer(nativeDevice.Device, indexFormat, indexCount, BufferUsage.None);
IndexElementSize indexElementSize;
if (indexData.GetType() == typeof(Int16[]))
idx10.SetData<short>(null, (short[])indexData);
{
idx11.SetData<short>(null, (short[])indexData);
indexElementSize = IndexElementSize.SixteenBits;
}
else
idx10.SetData<int>(null, (int[])indexData);
{
idx11.SetData<int>(null, (int[])indexData);
indexElementSize = IndexElementSize.ThirtyTwoBits;
}
nativeDevice.InputAssembler.SetIndexBuffer(idx11.NativeBuffer, DxFormatConverter.Translate(indexElementSize), 0);
DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount);
}

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Buildnummer
// Revision
//
[assembly: AssemblyVersion("0.7.9.0")]
[assembly: AssemblyFileVersion("0.7.9.0")]
[assembly: AssemblyVersion("0.7.10.*")]
[assembly: AssemblyFileVersion("0.7.10.0")]

View File

@ -177,15 +177,20 @@ namespace ANX.RenderSystem.Windows.Metro
NativeDevice.NativeContext.InputAssembler.SetVertexBuffers(0, nativeVertexBufferBindings);
IndexBuffer_Metro idxMetro = new IndexBuffer_Metro(NativeDevice.NativeDevice, indexFormat, indexCount, BufferUsage.None);
IndexElementSize indexElementSize;
if (indexData.GetType() == typeof(Int16[]))
{
idxMetro.SetData<short>(null, (short[])indexData);
indexElementSize = IndexElementSize.SixteenBits;
}
else
{
idxMetro.SetData<int>(null, (int[])indexData);
indexElementSize = IndexElementSize.ThirtyTwoBits;
}
NativeDevice.NativeContext.InputAssembler.SetIndexBuffer(idxMetro.NativeBuffer, FormatConverter.Translate(indexElementSize), 0);
DrawIndexedPrimitives(primitiveType, 0, vertexOffset, numVertices, indexOffset, primitiveCount);
}

View File

@ -24,6 +24,6 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.5.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.2.6.*")]
[assembly: AssemblyFileVersion("0.2.6.0")]
[assembly: GuidAttribute("855A261E-DB66-4CB2-97F3-34BC9DA4DAA1")]

View File

@ -41,6 +41,9 @@ namespace Primitives
VertexBuffer cubeVertexBuffer;
IndexBuffer cubeIndexBuffer;
bool[] enabled = new bool[] { true, true, true, true, true };
KeyboardState lastKeyState;
#region Corners of cube
static Vector3 topLeftFront = new Vector3( -1.0f, 1.0f, 1.0f );
static Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 1.0f);
@ -158,6 +161,8 @@ namespace Primitives
protected override void Initialize()
{
base.Initialize();
lastKeyState = Keyboard.GetState();
}
protected override void LoadContent()
@ -215,6 +220,25 @@ namespace Primitives
this.worldMatrix = Matrix.CreateRotationY(rotation);
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.D1) && !lastKeyState.IsKeyDown(Keys.D1))
enabled[0] = !enabled[0];
if (keyState.IsKeyDown(Keys.D2) && !lastKeyState.IsKeyDown(Keys.D2))
enabled[1] = !enabled[1];
if (keyState.IsKeyDown(Keys.D3) && !lastKeyState.IsKeyDown(Keys.D3))
enabled[2] = !enabled[2];
if (keyState.IsKeyDown(Keys.D4) && !lastKeyState.IsKeyDown(Keys.D4))
enabled[3] = !enabled[3];
if (keyState.IsKeyDown(Keys.D5) && !lastKeyState.IsKeyDown(Keys.D5))
enabled[4] = !enabled[4];
lastKeyState = keyState;
base.Update(gameTime);
}
@ -231,11 +255,11 @@ namespace Primitives
spriteBatch.Draw(bgTexture, new Rectangle(0, 400, 300, 200), Color.Green);
spriteBatch.Draw(bgTexture, new Rectangle(300, 400, 300, 200), Color.LightSeaGreen);
DrawShadowText(spriteBatch, this.font, "DrawInstancedPrimitives", new Vector2(10, 10), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawPrimitives", new Vector2(10, 210), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawIndexedPrimitives", new Vector2(310, 210), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawUserPrimitives", new Vector2(10, 410), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawUserIndexedPrimitives", new Vector2(310, 410), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawInstancedPrimitives\n (press 1 to " + (enabled[0] ? "disable" : "enable") + ")" , new Vector2(10, 10), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawPrimitives\n (press 2 to " + (enabled[1] ? "disable" : "enable") + ")", new Vector2(10, 210), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawIndexedPrimitives\n (press 3 to " + (enabled[2] ? "disable" : "enable") + ")", new Vector2(310, 210), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawUserPrimitives\n (press 4 to " + (enabled[3] ? "disable" : "enable") + ")", new Vector2(10, 410), Color.White, Color.Black);
DrawShadowText(spriteBatch, this.font, "DrawUserIndexedPrimitives\n (press 5 to " + (enabled[4] ? "disable" : "enable") + ")", new Vector2(310, 410), Color.White, Color.Black);
spriteBatch.End();
@ -249,49 +273,59 @@ namespace Primitives
this.basicEffect.CurrentTechnique.Passes[0].Apply();
#region DrawPrimitives
GraphicsDevice.Viewport = new Viewport(0, 200, 300, 200);
GraphicsDevice.SetVertexBuffer(this.cubeNoIndicesBuffer);
GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, cubeNoIndices.Length / 3);
if (enabled[1])
{
GraphicsDevice.Viewport = new Viewport(0, 200, 300, 200);
GraphicsDevice.SetVertexBuffer(this.cubeNoIndicesBuffer);
GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, cubeNoIndices.Length / 3);
}
#endregion // DrawPrimitives
#region DrawIndexedPrimitives
GraphicsDevice.Viewport = new Viewport(300, 200, 300, 200);
GraphicsDevice.SetVertexBuffer(this.cubeVertexBuffer);
GraphicsDevice.Indices = this.cubeIndexBuffer;
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, cubeVertices.Length, 0, cubeNoIndices.Length / 3);
if (enabled[2])
{
GraphicsDevice.Viewport = new Viewport(300, 200, 300, 200);
GraphicsDevice.SetVertexBuffer(this.cubeVertexBuffer);
GraphicsDevice.Indices = this.cubeIndexBuffer;
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, cubeVertices.Length, 0, cubeNoIndices.Length / 3);
}
#endregion
#region DrawUserPrimitives
GraphicsDevice.Viewport = new Viewport(0, 400, 300, 200);
GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, this.cubeNoIndices, 0, this.cubeNoIndices.Length / 3);
if (enabled[3])
{
GraphicsDevice.Viewport = new Viewport(0, 400, 300, 200);
GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, this.cubeNoIndices, 0, this.cubeNoIndices.Length / 3);
}
#endregion
#region DrawUserIndexedPrimitives
GraphicsDevice.Viewport = new Viewport(300, 400, 300, 200);
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, this.cubeVertices, 0, this.cubeVertices.Length, this.cubeIndices, 0, this.cubeIndices.Length / 3);
if (enabled[4])
{
GraphicsDevice.Viewport = new Viewport(300, 400, 300, 200);
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, this.cubeVertices, 0, this.cubeVertices.Length, this.cubeIndices, 0, this.cubeIndices.Length / 3);
}
#endregion
#region DrawInstancedPrimitives
GraphicsDevice.Viewport = new Viewport(0, 0, 600, 200);
if (enabled[0])
{
GraphicsDevice.Viewport = new Viewport(0, 0, 600, 200);
this.hardwareInstanceEffect.Parameters["View"].SetValue(this.instancedViewMatrix);
this.hardwareInstanceEffect.Parameters["Projection"].SetValue(this.instancedProjectionMatrix);
this.hardwareInstanceEffect.Parameters["World"].SetValue(this.worldMatrix);
this.hardwareInstanceEffect.CurrentTechnique.Passes[0].Apply();
instanceVertexBuffer.SetData<Matrix>(this.instanceTransformMatrices, 0, this.instanceTransformMatrices.Length, SetDataOptions.Discard);
GraphicsDevice.SetVertexBuffers(cubeVertexBuffer, new VertexBufferBinding(instanceVertexBuffer, 0, 1));
GraphicsDevice.Indices = this.cubeIndexBuffer;
GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, this.cubeVertices.Length, 0, this.cubeIndices.Length / 3, 5);
this.hardwareInstanceEffect.Parameters["View"].SetValue(this.instancedViewMatrix);
this.hardwareInstanceEffect.Parameters["Projection"].SetValue(this.instancedProjectionMatrix);
this.hardwareInstanceEffect.Parameters["World"].SetValue(this.worldMatrix);
this.hardwareInstanceEffect.CurrentTechnique.Passes[0].Apply();
instanceVertexBuffer.SetData<Matrix>(this.instanceTransformMatrices, 0, this.instanceTransformMatrices.Length, SetDataOptions.Discard);
GraphicsDevice.SetVertexBuffers(cubeVertexBuffer, new VertexBufferBinding(instanceVertexBuffer, 0, 1));
GraphicsDevice.Indices = this.cubeIndexBuffer;
GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, this.cubeVertices.Length, 0, this.cubeIndices.Length / 3, 5);
}
#endregion
base.Draw(gameTime);
@ -300,8 +334,8 @@ namespace Primitives
private void DrawShadowText(SpriteBatch spriteBatch, SpriteFont font, String text, Vector2 position, Color foreground, Color shadow)
{
spriteBatch.DrawString(font, text, position + new Vector2(2, 2), shadow);
spriteBatch.DrawString(font, text, position, foreground);
spriteBatch.DrawString(font, text, position + new Vector2(2, 2), shadow, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f);
spriteBatch.DrawString(font, text, position, foreground, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);
}
}
}