fixed issue #475 (OpenGL3 RenderSystem SpriteBatch wrong colors)

This commit is contained in:
Glatzemann 2011-12-05 09:39:07 +00:00
parent 57314d888a
commit 72f8e735fb
6 changed files with 58 additions and 52 deletions

View File

@ -190,28 +190,30 @@ namespace ANX.Framework.Windows.GL3
{ {
IsBound = true; IsBound = true;
GL.BlendEquationSeparate( GL.Enable(EnableCap.Blend);
TranslateBlendFunction(ColorBlendFunction),
TranslateBlendFunction(AlphaBlendFunction));
ErrorHelper.Check("BlendEquationSeparate");
GL.BlendFuncSeparate( GL.BlendEquationSeparate(
TranslateBlendSrc(ColorSourceBlend), TranslateBlendFunction(ColorBlendFunction),
TranslateBlendDest(ColorDestinationBlend), TranslateBlendFunction(AlphaBlendFunction));
TranslateBlendSrc(AlphaSourceBlend), ErrorHelper.Check("BlendEquationSeparate");
TranslateBlendDest(AlphaDestinationBlend));
ErrorHelper.Check("BlendFuncSeparate");
SetColorWriteChannel(0, ColorWriteChannels); GL.BlendFuncSeparate(
SetColorWriteChannel(1, ColorWriteChannels1); TranslateBlendSrc(ColorSourceBlend),
SetColorWriteChannel(2, ColorWriteChannels2); TranslateBlendDest(ColorDestinationBlend),
SetColorWriteChannel(3, ColorWriteChannels3); TranslateBlendSrc(AlphaSourceBlend),
TranslateBlendDest(AlphaDestinationBlend));
ErrorHelper.Check("BlendFuncSeparate");
GL.BlendColor(BlendFactor.R * DatatypesMapping.ColorMultiplier, SetColorWriteChannel(0, ColorWriteChannels);
BlendFactor.G * DatatypesMapping.ColorMultiplier, SetColorWriteChannel(1, ColorWriteChannels1);
BlendFactor.B * DatatypesMapping.ColorMultiplier, SetColorWriteChannel(2, ColorWriteChannels2);
BlendFactor.A * DatatypesMapping.ColorMultiplier); SetColorWriteChannel(3, ColorWriteChannels3);
ErrorHelper.Check("BlendColor");
GL.BlendColor(BlendFactor.R * DatatypesMapping.ColorMultiplier,
BlendFactor.G * DatatypesMapping.ColorMultiplier,
BlendFactor.B * DatatypesMapping.ColorMultiplier,
BlendFactor.A * DatatypesMapping.ColorMultiplier);
ErrorHelper.Check("BlendColor");
// TODO: multi sample mask // TODO: multi sample mask
} }
@ -245,14 +247,10 @@ namespace ANX.Framework.Windows.GL3
/// <param name="channels">Mask channels to enable.</param> /// <param name="channels">Mask channels to enable.</param>
private void SetColorWriteChannel(int index, ColorWriteChannels channels) private void SetColorWriteChannel(int index, ColorWriteChannels channels)
{ {
bool r = (channels == Graphics.ColorWriteChannels.All || bool r = (channels & Graphics.ColorWriteChannels.Red) == Graphics.ColorWriteChannels.Red;
channels == Graphics.ColorWriteChannels.Red); bool g = (channels & Graphics.ColorWriteChannels.Green) == Graphics.ColorWriteChannels.Green;
bool g = (channels == Graphics.ColorWriteChannels.All || bool b = (channels & Graphics.ColorWriteChannels.Blue) == Graphics.ColorWriteChannels.Blue;
channels == Graphics.ColorWriteChannels.Green); bool a = (channels & Graphics.ColorWriteChannels.Alpha) == Graphics.ColorWriteChannels.Alpha;
bool b = (channels == Graphics.ColorWriteChannels.All ||
channels == Graphics.ColorWriteChannels.Blue);
bool a = (channels == Graphics.ColorWriteChannels.All ||
channels == Graphics.ColorWriteChannels.Alpha);
GL.ColorMask(index, r, g, b, a); GL.ColorMask(index, r, g, b, a);
ErrorHelper.Check("ColorMask"); ErrorHelper.Check("ColorMask");
@ -358,24 +356,25 @@ namespace ANX.Framework.Windows.GL3
/// <returns>OpenGL Blend Equation Mode.</returns> /// <returns>OpenGL Blend Equation Mode.</returns>
private BlendEquationMode TranslateBlendFunction(BlendFunction func) private BlendEquationMode TranslateBlendFunction(BlendFunction func)
{ {
switch (func) switch (func)
{ {
default: case BlendFunction.Add:
case BlendFunction.Add: return BlendEquationMode.FuncAdd;
return BlendEquationMode.FuncAdd;
case BlendFunction.Subtract: case BlendFunction.Subtract:
return BlendEquationMode.FuncSubtract; return BlendEquationMode.FuncSubtract;
case BlendFunction.ReverseSubtract: case BlendFunction.ReverseSubtract:
return BlendEquationMode.FuncReverseSubtract; return BlendEquationMode.FuncReverseSubtract;
case BlendFunction.Min: case BlendFunction.Min:
return BlendEquationMode.Min; return BlendEquationMode.Min;
case BlendFunction.Max: case BlendFunction.Max:
return BlendEquationMode.Max; return BlendEquationMode.Max;
} }
throw new ArgumentException("don't know how to translate BlendFunction '" + func.ToString() + "' to BlendEquationMode");
} }
#endregion #endregion
} }

View File

@ -158,7 +158,7 @@ namespace ANX.Framework.Windows.GL3
nativeWindowInfo = Utilities.CreateWindowsWindowInfo( nativeWindowInfo = Utilities.CreateWindowsWindowInfo(
presentationParameters.DeviceWindowHandle); presentationParameters.DeviceWindowHandle);
GraphicsMode graphicsMode = new GraphicsMode( GraphicsMode graphicsMode = new GraphicsMode(
DatatypesMapping.SurfaceToColorFormat( DatatypesMapping.SurfaceToColorFormat(
presentationParameters.BackBufferFormat), presentationParameters.BackBufferFormat),
depth, stencil, depth, stencil,

View File

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

View File

@ -125,7 +125,7 @@ namespace ANX.Framework.Windows.GL3
int wrapMode = (int)All.ClampToEdge; int wrapMode = (int)All.ClampToEdge;
int filter = (int)(mipCount > 1 ? All.LinearMipmapLinear : All.Linear); int filter = (int)(mipCount > 1 ? All.LinearMipmapLinear : All.Linear);
GL.TexParameter(TextureTarget.Texture2D, GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureWrapS, wrapMode); TextureParameterName.TextureWrapS, wrapMode);
GL.TexParameter(TextureTarget.Texture2D, GL.TexParameter(TextureTarget.Texture2D,
@ -147,7 +147,7 @@ namespace ANX.Framework.Windows.GL3
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data) public void SetData<T>(GraphicsDevice graphicsDevice, T[] data)
where T : struct where T : struct
{ {
SetData<T>(graphicsDevice, data, 0, data.Length); SetData<T>(graphicsDevice, 0, data, 0, data.Length);
} }
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data, public void SetData<T>(GraphicsDevice graphicsDevice, T[] data,
@ -186,9 +186,9 @@ namespace ANX.Framework.Windows.GL3
} }
else else
{ {
GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat, GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
width, height, 0, (PixelFormat)nativeFormat, width, height, 0, (PixelFormat)nativeFormat,
PixelType.UnsignedByte, dataPointer); PixelType.UnsignedByte, dataPointer);
#if DEBUG #if DEBUG
ErrorHelper.Check("TexImage2D Format=" + nativeFormat); ErrorHelper.Check("TexImage2D Format=" + nativeFormat);
#endif #endif

View File

@ -215,7 +215,7 @@ namespace ANX.Framework.Windows.GL3
GL.EnableVertexAttribArray(col); GL.EnableVertexAttribArray(col);
ErrorHelper.Check("EnableVertexAttribArray col"); ErrorHelper.Check("EnableVertexAttribArray col");
GL.VertexAttribPointer(col, 4, VertexAttribPointerType.UnsignedByte, GL.VertexAttribPointer(col, 4, VertexAttribPointerType.UnsignedByte,
false, vertexDeclaration.VertexStride, element.Offset); true, vertexDeclaration.VertexStride, element.Offset);
ErrorHelper.Check("VertexAttribPointer col"); ErrorHelper.Check("VertexAttribPointer col");
break; break;

View File

@ -108,10 +108,17 @@ namespace WindowsGame1
// Create a new SpriteBatch, which can be used to draw textures. // Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice); spriteBatch = new SpriteBatch(GraphicsDevice);
//this.texture = Content.Load<Texture2D>(@"Textures/DotColor4x4"); //this.alternateTexture = Content.Load<Texture2D>(@"Textures/DotColor4x4");
this.alternateTexture = Content.Load<Texture2D>(@"Textures/DotWhiteTopLeft5x5"); this.alternateTexture = Content.Load<Texture2D>(@"Textures/DotWhiteTopLeft5x5");
this.texture = Content.Load<Texture2D>(@"Textures/ANX.logo"); this.texture = Content.Load<Texture2D>(@"Textures/ANX.logo");
//this.texture = new Texture2D(GraphicsDevice, 64, 64);
//this.alternateTexture = new Texture2D(GraphicsDevice, 64, 64);
//Color[] color = new Color[this.alternateTexture.Width * this.alternateTexture.Height];
//for (int i = 0; i < color.Length; i++)
//{
// color[i] = new Color(1.0f, 1.0f, 0, 0.5f);
//}
//this.alternateTexture.SetData<Color>(color);
} }
/// <summary> /// <summary>