diff --git a/ANX.Framework.TestCenter/Strukturen/ColorTest.cs b/ANX.Framework.TestCenter/Strukturen/ColorTest.cs index 67d47a9d..0f9f0939 100644 --- a/ANX.Framework.TestCenter/Strukturen/ColorTest.cs +++ b/ANX.Framework.TestCenter/Strukturen/ColorTest.cs @@ -681,5 +681,19 @@ namespace ANX.Framework.TestCenter.Strukturen } #endregion + + #region BugFixes + [Test] + public void BugFixIssue481() + { + Color textColor = new Color(new Vector4(1)); + + Assert.AreEqual((byte)255, textColor.R); + Assert.AreEqual((byte)255, textColor.G); + Assert.AreEqual((byte)255, textColor.B); + Assert.AreEqual((byte)255, textColor.A); + } + + #endregion } } diff --git a/ANX.Framework/Color.cs b/ANX.Framework/Color.cs index b388a676..b0930274 100644 --- a/ANX.Framework/Color.cs +++ b/ANX.Framework/Color.cs @@ -111,9 +111,8 @@ namespace ANX.Framework } public Color(Vector4 vector) + : this(vector.X, vector.Y, vector.Z, vector.W) { - this.packedValue = 0; - ((IPackedVector)this).PackFromVector4(vector); } private Color(uint packedValue) diff --git a/ANX.Framework/Graphics/DynamicIndexBuffer.cs b/ANX.Framework/Graphics/DynamicIndexBuffer.cs index ce7bcdfe..2b0b2e0e 100644 --- a/ANX.Framework/Graphics/DynamicIndexBuffer.cs +++ b/ANX.Framework/Graphics/DynamicIndexBuffer.cs @@ -56,39 +56,60 @@ namespace ANX.Framework.Graphics { public virtual event EventHandler ContentLost; + #region Private Members + private bool isContentLost; + + #endregion + public DynamicIndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage) : base(graphicsDevice, indexElementSize, indexCount, usage) { - throw new NotImplementedException(); + graphicsDevice.DeviceReset += new EventHandler(graphicsDevice_DeviceReset); } public DynamicIndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsage usage) : base(graphicsDevice, indexType, indexCount, usage) { - throw new NotImplementedException(); + graphicsDevice.DeviceReset += new EventHandler(graphicsDevice_DeviceReset); + } + + ~DynamicIndexBuffer() + { + base.GraphicsDevice.DeviceReset -= graphicsDevice_DeviceReset; + } + + private void graphicsDevice_DeviceReset(object sender, EventArgs e) + { + SetContentLost(true); } public void SetData(int offsetInBytes, T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct { - throw new NotImplementedException(); + //TODO: SetDataOptions not used + base.SetData(offsetInBytes, data, startIndex, elementCount); } public void SetData(T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct { - throw new NotImplementedException(); + //TODO: SetDataOptions not used + base.SetData(data, startIndex, elementCount); } public bool IsContentLost { get { - throw new NotImplementedException(); + return this.isContentLost; } } public void SetContentLost(bool isContentLost) { - throw new NotImplementedException(); + this.isContentLost = isContentLost; + if (isContentLost) + { + raise_ContentLost(this, EventArgs.Empty); + } } protected void raise_ContentLost(object sender, EventArgs args) diff --git a/ANX.Framework/Graphics/DynamicVertexBuffer.cs b/ANX.Framework/Graphics/DynamicVertexBuffer.cs index 31f30b77..bcf0541c 100644 --- a/ANX.Framework/Graphics/DynamicVertexBuffer.cs +++ b/ANX.Framework/Graphics/DynamicVertexBuffer.cs @@ -56,39 +56,60 @@ namespace ANX.Framework.Graphics { public virtual event EventHandler ContentLost; + #region Private Members + private bool isContentLost; + + #endregion + public DynamicVertexBuffer(GraphicsDevice graphicsDevice, Type vertexType, int vertexCount, BufferUsage usage) : base(graphicsDevice, vertexType, vertexCount, usage) { - throw new NotImplementedException(); + graphicsDevice.DeviceReset += new EventHandler(graphicsDevice_DeviceReset); } public DynamicVertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage) : base(graphicsDevice, vertexDeclaration, vertexCount, usage) { - throw new NotImplementedException(); + graphicsDevice.DeviceReset += new EventHandler(graphicsDevice_DeviceReset); + } + + ~DynamicVertexBuffer() + { + base.GraphicsDevice.DeviceReset -= graphicsDevice_DeviceReset; + } + + private void graphicsDevice_DeviceReset(object sender, EventArgs e) + { + SetContentLost(true); } public void SetData(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride, SetDataOptions options) where T : struct { - throw new NotImplementedException(); + //TODO: SetDataOptions not used + base.SetData(offsetInBytes, data, startIndex, elementCount, vertexStride); } public void SetData(T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct { - throw new NotImplementedException(); + //TODO: SetDataOptions not used + base.SetData(data, startIndex, elementCount); } public bool IsContentLost { get { - throw new NotImplementedException(); + return this.isContentLost; } } public void SetContentLost(bool isContentLost) { - throw new NotImplementedException(); + this.isContentLost = isContentLost; + if (isContentLost) + { + raise_ContentLost(this, EventArgs.Empty); + } } protected void raise_ContentLost(object sender, EventArgs args) diff --git a/ANX.Framework/Graphics/SpriteBatch.cs b/ANX.Framework/Graphics/SpriteBatch.cs index 3baa9cad..d174b2cb 100644 --- a/ANX.Framework/Graphics/SpriteBatch.cs +++ b/ANX.Framework/Graphics/SpriteBatch.cs @@ -66,9 +66,9 @@ namespace ANX.Framework.Graphics private SpriteSortMode currentSortMode; private SpriteInfo[] spriteInfos; private int currentBatchPosition; - private IndexBuffer indexBuffer; + private DynamicIndexBuffer indexBuffer; private VertexPositionColorTexture[] vertices; - private VertexBuffer vertexBuffer; + private DynamicVertexBuffer vertexBuffer; private BlendState blendState; private SamplerState samplerState; @@ -476,9 +476,27 @@ namespace ANX.Framework.Graphics if (this.indexBuffer == null) { - this.indexBuffer = new IndexBuffer(this.GraphicsDevice, IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly); + this.indexBuffer = new DynamicIndexBuffer(this.GraphicsDevice, IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly); + this.indexBuffer.ContentLost += new EventHandler(indexBuffer_ContentLost); } + SetIndexData(indexCount); + } + + private void indexBuffer_ContentLost(object sender, EventArgs e) + { + if (this.indexBuffer != null) + { + this.indexBuffer.ContentLost -= indexBuffer_ContentLost; + this.indexBuffer.Dispose(); + this.indexBuffer = null; + } + + InitializeIndexBuffer(InitialBatchSize); + } + + private void SetIndexData(int indexCount) + { short[] indices = new short[indexCount]; int baseIndex; @@ -503,10 +521,25 @@ namespace ANX.Framework.Graphics { if (this.vertexBuffer == null) { - this.vertexBuffer = new VertexBuffer(this.GraphicsDevice, typeof(VertexPositionColorTexture), InitialBatchSize * 4, BufferUsage.WriteOnly); + this.vertexBuffer = new DynamicVertexBuffer(this.GraphicsDevice, typeof(VertexPositionColorTexture), InitialBatchSize * 4, BufferUsage.WriteOnly); + this.vertexBuffer.ContentLost += new EventHandler(vertexBuffer_ContentLost); } } + private void vertexBuffer_ContentLost(object sender, EventArgs e) + { + this.currentBatchPosition = 0; + + if (this.vertexBuffer != null) + { + this.vertexBuffer.ContentLost -= vertexBuffer_ContentLost; + this.vertexBuffer.Dispose(); + this.vertexBuffer = null; + } + + InitializeVertexBuffer(); + } + private void SetRenderStates() { GraphicsDevice.BlendState = this.blendState != null ? this.blendState : BlendState.AlphaBlend;