worked on feature #478 and #479

fixed bug #481
This commit is contained in:
Glatzemann 2011-12-05 13:19:42 +00:00
parent 7bc2a4a340
commit 0a903c67cc
5 changed files with 106 additions and 18 deletions

View File

@ -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
}
}

View File

@ -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)

View File

@ -56,39 +56,60 @@ namespace ANX.Framework.Graphics
{
public virtual event EventHandler<EventArgs> 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<EventArgs>(graphicsDevice_DeviceReset);
}
public DynamicIndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsage usage)
: base(graphicsDevice, indexType, indexCount, usage)
{
throw new NotImplementedException();
graphicsDevice.DeviceReset += new EventHandler<EventArgs>(graphicsDevice_DeviceReset);
}
~DynamicIndexBuffer()
{
base.GraphicsDevice.DeviceReset -= graphicsDevice_DeviceReset;
}
private void graphicsDevice_DeviceReset(object sender, EventArgs e)
{
SetContentLost(true);
}
public void SetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct
{
throw new NotImplementedException();
//TODO: SetDataOptions not used
base.SetData<T>(offsetInBytes, data, startIndex, elementCount);
}
public void SetData<T>(T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct
{
throw new NotImplementedException();
//TODO: SetDataOptions not used
base.SetData<T>(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)

View File

@ -56,39 +56,60 @@ namespace ANX.Framework.Graphics
{
public virtual event EventHandler<EventArgs> 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<EventArgs>(graphicsDevice_DeviceReset);
}
public DynamicVertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
: base(graphicsDevice, vertexDeclaration, vertexCount, usage)
{
throw new NotImplementedException();
graphicsDevice.DeviceReset += new EventHandler<EventArgs>(graphicsDevice_DeviceReset);
}
~DynamicVertexBuffer()
{
base.GraphicsDevice.DeviceReset -= graphicsDevice_DeviceReset;
}
private void graphicsDevice_DeviceReset(object sender, EventArgs e)
{
SetContentLost(true);
}
public void SetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride, SetDataOptions options) where T : struct
{
throw new NotImplementedException();
//TODO: SetDataOptions not used
base.SetData<T>(offsetInBytes, data, startIndex, elementCount, vertexStride);
}
public void SetData<T>(T[] data, int startIndex, int elementCount, SetDataOptions options) where T : struct
{
throw new NotImplementedException();
//TODO: SetDataOptions not used
base.SetData<T>(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)

View File

@ -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<EventArgs>(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<EventArgs>(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;