Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Improvements #207

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion MonoGame.Framework/Content/ContentManager.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MonoGame.Framework/Graphics/Effect/AlphaTestEffect.cs

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions MonoGame.Framework/Graphics/Effect/AlphaTestEffectCode.cs
Expand Up @@ -7,53 +7,53 @@ internal static class AlphaTestEffectCode
{
internal static string AlphaTestEffectFragmentCode() {

StringBuilder sb = new StringBuilder();
var sb = new StringBuilder();

string code = "uniform sampler2D Texture;\n"
+ "uniform vec4 DiffuseColor;\n"
+ "uniform vec4 AlphaTest;\n"
+ "uniform vec3 FogColor;\n"
+ "uniform vec4 FogVector;\n"
+ "uniform mat4 WorldViewProj;\n"
+ "uniform int ShaderIndex;\n"
const string code = "uniform sampler2D Texture;\n"
+ "uniform vec4 DiffuseColor;\n"
+ "uniform vec4 AlphaTest;\n"
+ "uniform vec3 FogColor;\n"
+ "uniform vec4 FogVector;\n"
+ "uniform mat4 WorldViewProj;\n"
+ "uniform int ShaderIndex;\n"

+ "void main() {\n"
+ "void main() {\n"

// Defined here so that they show up as parameters
+ "vec4 dc = DiffuseColor;\n"
+ "vec4 at = AlphaTest;\n"
+ "vec3 fc = FogColor;\n"
+ "vec4 fv = FogVector;\n"
+ "mat4 proj = WorldViewProj;\n"
+ "int shaderIndex = ShaderIndex;\n"
// End Defines
// Defined here so that they show up as parameters
+ "vec4 dc = DiffuseColor;\n"
+ "vec4 at = AlphaTest;\n"
+ "vec3 fc = FogColor;\n"
+ "vec4 fv = FogVector;\n"
+ "mat4 proj = WorldViewProj;\n"
+ "int shaderIndex = ShaderIndex;\n"
// End Defines

+ "vec4 color = texture2D(Texture, gl_TexCoord[0].xy);\n"
+ "vec4 color = texture2D(Texture, gl_TexCoord[0].xy);\n"

// 7 is the index that is being passed for Eq/Ne with diffuse and no fog
+ "float retDiscard = 0.0;\n"
+ "if (ShaderIndex == 7) {\n"
+ " float absRet = abs(color.a - AlphaTest.x);\n"
+ " if (absRet < AlphaTest.y)\n"
+ " retDiscard = AlphaTest.z;\n"
+ " else\n"
+ " retDiscard = AlphaTest.w;\n"
+ "}\n"
+ "else { // Here we will default to Lt/Gt\n"
// 7 is the index that is being passed for Eq/Ne with diffuse and no fog
+ "float retDiscard = 0.0;\n"
+ "if (ShaderIndex == 7) {\n"
+ " float absRet = abs(color.a - AlphaTest.x);\n"
+ " if (absRet < AlphaTest.y)\n"
+ " retDiscard = AlphaTest.z;\n"
+ " else\n"
+ " retDiscard = AlphaTest.w;\n"
+ "}\n"
+ "else { // Here we will default to Lt/Gt\n"

+ " if (color.a < AlphaTest.x)\n"
+ " retDiscard = AlphaTest.z;\n"
+ " else\n"
+ " retDiscard = AlphaTest.w;\n"
+ "}\n"
+ " if (color.a < AlphaTest.x)\n"
+ " retDiscard = AlphaTest.z;\n"
+ " else\n"
+ " retDiscard = AlphaTest.w;\n"
+ "}\n"

+ "if (retDiscard == -1.0) {\n"
+ " discard;\n"
+ "}\n"
+ "if (retDiscard == -1.0) {\n"
+ " discard;\n"
+ "}\n"

+ "gl_FragColor = gl_Color * color;\n"
+ "gl_FragColor = gl_Color * color;\n"

+ "}\n";
+ "}\n";


return code;
Expand Down
2 changes: 0 additions & 2 deletions MonoGame.Framework/Graphics/Effect/EffectHelpers.cs
Expand Up @@ -9,8 +9,6 @@

//#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
//#endregion

namespace Microsoft.Xna.Framework.Graphics
Expand Down
4 changes: 0 additions & 4 deletions MonoGame.Framework/Graphics/GraphicsResource.cs
Expand Up @@ -47,10 +47,6 @@ public abstract class GraphicsResource : IDisposable

internal GraphicsDevice graphicsDevice;

public GraphicsResource ()
{
}

protected virtual void DoDisposing(EventArgs e)
{
if (Disposing != null)
Expand Down
135 changes: 135 additions & 0 deletions MonoGame.Framework/Graphics/PackedVector/NormalizedShort2.cs
@@ -0,0 +1,135 @@
// #region License
// /*
// Microsoft Public License (Ms-PL)
// MonoGame - Copyright © 2009 The MonoGame Team
//
// All rights reserved.
//
// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
// accept the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
// U.S. copyright law.
//
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
// your patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
// permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
// purpose and non-infringement.
// */
// #endregion License
//
// Author: Kenneth James Pouncey

using System;

namespace Microsoft.Xna.Framework.Graphics.PackedVector
{
public struct NormalizedShort2 : IPackedVector<uint>, IEquatable<NormalizedShort2>
{
private uint short2Packed;

public NormalizedShort2(Vector2 vector)
{
short2Packed = PackInTwo(vector.X, vector.Y);
}

public NormalizedShort2(float x, float y)
{
short2Packed = PackInTwo(x, y);
}

public static bool operator !=(NormalizedShort2 a, NormalizedShort2 b)
{
return !a.Equals (b);
}

public static bool operator ==(NormalizedShort2 a, NormalizedShort2 b)
{
return a.Equals (b);
}

public uint PackedValue {
get {
return short2Packed;
}
set {
short2Packed = value;
}
}

public override bool Equals (object obj)
{
throw new NotImplementedException ();
}

public bool Equals(NormalizedShort2 other)
{
throw new NotImplementedException ();
}

public override int GetHashCode ()
{
return short2Packed.GetHashCode();
}

public override string ToString ()
{
// not sure what to return here
// microsoft returns some funky formatted string
return string.Format("{0} / {1}", (short)(short2Packed & 0xFFFF), (short)(short2Packed >> 0x10) );
}

public Vector2 ToVector2 ()
{
var v2 = new Vector2 ();
v2.X = (short)(short2Packed & 0xFFFF);
v2.Y = (short)(short2Packed >> 0x10);
return v2;
}

private static uint PackInTwo (float vectorX, float vectorY)
{
const float maxPos = 0x7FFF;
const float minNeg = ~(int)maxPos;

// clamp the value between min and max values
var word2 = (uint)((int)Math.Max (Math.Min (vectorX, maxPos), minNeg) & 0xFFFF);
var word1 = (uint)(((int)Math.Max (Math.Min (vectorY, maxPos), minNeg) & 0xFFFF) << 0x10);

return (word2 | word1);
}

void IPackedVector.PackFromVector4 (Vector4 vector)
{
short2Packed = PackInTwo(vector.X, vector.Y);
}

Vector4 IPackedVector.ToVector4 ()
{
var v4 = new Vector4 (0,0,0,1);
v4.X = (short)(short2Packed & 0xFFFF);
v4.Y = (short)(short2Packed >> 0x10);
return v4;
}
}
}
39 changes: 19 additions & 20 deletions MonoGame.Framework/Graphics/PackedVector/Short2.cs
Expand Up @@ -41,22 +41,21 @@
// Author: Kenneth James Pouncey

using System;
using Microsoft.Xna.Framework;

namespace Microsoft.Xna.Framework.Graphics.PackedVector
{
public struct Short2 : IPackedVector<uint>, IPackedVector, IEquatable<Short2>
public struct Short2 : IPackedVector<uint>, IEquatable<Short2>
{
private uint short2Packed;
private uint _short2Packed;

public Short2 (Vector2 vector)
{
short2Packed = Short2.PackInTwo (vector.X, vector.Y);
_short2Packed = PackInTwo (vector.X, vector.Y);
}

public Short2 (Single x,Single y)
{
short2Packed = Short2.PackInTwo (x, y);
_short2Packed = PackInTwo (x, y);
}

public static bool operator !=(Short2 a, Short2 b)
Expand All @@ -71,10 +70,10 @@ public Short2 (Single x,Single y)

public uint PackedValue {
get {
return short2Packed;
return _short2Packed;
}
set {
short2Packed = value;
_short2Packed = value;
}
}

Expand All @@ -90,46 +89,46 @@ public bool Equals (Short2 other)

public override int GetHashCode ()
{
return short2Packed.GetHashCode();
return _short2Packed.GetHashCode();
}

public override string ToString ()
{
// not sure what to return here
// microsoft returns some funky formatted string
return string.Format("{0} / {1}", (short)(short2Packed & 0xFFFF), (short)(short2Packed >> 0x10) );
return string.Format("{0} / {1}", (short)(_short2Packed & 0xFFFF), (short)(_short2Packed >> 0x10) );
}

public Vector2 ToVector2 ()
{
Vector2 v2 = new Vector2 ();
v2.X = (short)(short2Packed & 0xFFFF);
v2.Y = (short)(short2Packed >> 0x10);
var v2 = new Vector2 ();
v2.X = (short)(_short2Packed & 0xFFFF);
v2.Y = (short)(_short2Packed >> 0x10);
return v2;
}

private static uint PackInTwo (float vectorX, float vectorY)
{
float maxPos = 0x7FFF; // Largest two byte positive number 0xFFFF >> 1;
float minNeg = ~(int)maxPos; // two's complement
const float maxPos = 0x7FFF; // Largest two byte positive number 0xFFFF >> 1;
const float minNeg = ~(int)maxPos; // two's complement

// clamp the value between min and max values
uint word2 = (uint)((int)Math.Max (Math.Min (vectorX, maxPos), minNeg) & 0xFFFF);
uint word1 = (uint)(((int)Math.Max (Math.Min (vectorY, maxPos), minNeg) & 0xFFFF) << 0x10);
var word2 = (uint)((int)Math.Max (Math.Min (vectorX, maxPos), minNeg) & 0xFFFF);
var word1 = (uint)(((int)Math.Max (Math.Min (vectorY, maxPos), minNeg) & 0xFFFF) << 0x10);

return (word2 | word1);
}

void IPackedVector.PackFromVector4 (Vector4 vector)
{
short2Packed = Short2.PackInTwo (vector.X, vector.Y);
_short2Packed = Short2.PackInTwo (vector.X, vector.Y);
}

Vector4 IPackedVector.ToVector4 ()
{
Vector4 v4 = new Vector4 (0,0,0,1);
v4.X = (short)(short2Packed & 0xFFFF);
v4.Y = (short)(short2Packed >> 0x10);
var v4 = new Vector4 (0,0,0,1);
v4.X = (short)(_short2Packed & 0xFFFF);
v4.Y = (short)(_short2Packed >> 0x10);
return v4;
}
}
Expand Down
15 changes: 8 additions & 7 deletions MonoGame.Framework/Graphics/Vertices/IndexBuffer.cs
Expand Up @@ -10,9 +10,8 @@

namespace Microsoft.Xna.Framework.Graphics
{
public class IndexBuffer
public class IndexBuffer : GraphicsResource
{
private GraphicsDevice _graphics;
internal Type _type;
internal int _count;
private object _buffer;
Expand All @@ -34,12 +33,12 @@ internal static void CreateFrameBuffers()
_delayedBufferDelegates.Clear();
}

public IndexBuffer(GraphicsDevice Graphics, Type type, int count, BufferUsage bufferUsage)
public IndexBuffer(GraphicsDevice graphics, Type type, int count, BufferUsage bufferUsage)
{
if (type != typeof(uint) && type != typeof(ushort) && type != typeof(byte))
throw new NotSupportedException("The only types that are supported are: uint, ushort and byte");

this._graphics = Graphics;
this.graphicsDevice = graphics;
this._type = type;
this._count = count;
this._bufferUsage = bufferUsage;
Expand All @@ -64,17 +63,19 @@ public IndexBuffer(GraphicsDevice Graphics, Type type, int count, BufferUsage bu
_allBuffers[_bufferIndex] = this;
}

public void Dispose ()
public override void Dispose ()
{
GL11.GenBuffers(0, ref _bufferStore);
}
base.Dispose();
}
}



public class DynamicIndexBuffer : IndexBuffer
{
public DynamicIndexBuffer(GraphicsDevice Graphics, Type type, int count, BufferUsage bufferUsage) : base(Graphics, type, count, bufferUsage)
public DynamicIndexBuffer(GraphicsDevice graphics, Type type, int count, BufferUsage bufferUsage)
: base(graphics, type, count, bufferUsage)
{
}
}
Expand Down