added latest GL-RenderSystem improvements by Astror Enales
This commit is contained in:
parent
8326720ee3
commit
e6a3178238
@ -45,11 +45,15 @@
|
||||
<Compile Include="DatatypesMapping.cs" />
|
||||
<Compile Include="DepthStencilStateGL3.cs" />
|
||||
<Compile Include="EffectGL3.cs" />
|
||||
<Compile Include="EffectParameterGL3.cs" />
|
||||
<Compile Include="EffectTechniqueGL3.cs" />
|
||||
<Compile Include="GraphicsDeviceWindowsGL3.cs" />
|
||||
<Compile Include="IndexBufferGL3.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RasterizerStateGL3.cs" />
|
||||
<Compile Include="SamplerStateGL3.cs" />
|
||||
<Compile Include="Texture2DGL3.cs" />
|
||||
<Compile Include="VertexBufferGL3.cs" />
|
||||
<Compile Include="WindowsGameHost.cs" />
|
||||
<Compile Include="WindowsGameWindow.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -1,14 +1,7 @@
|
||||
#region Using Statements
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ANX.Framework;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.Graphics;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
#endregion // Using Statements
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
|
||||
#region License
|
||||
|
||||
@ -59,6 +52,9 @@ using System.IO;
|
||||
|
||||
namespace ANX.Framework.Windows.GL3
|
||||
{
|
||||
/// <summary>
|
||||
/// OpenGL graphics creator.
|
||||
/// </summary>
|
||||
public class Creator : IRenderSystemCreator
|
||||
{
|
||||
#region Public
|
||||
@ -91,13 +87,13 @@ namespace ANX.Framework.Windows.GL3
|
||||
#region CreateEffect
|
||||
public INativeEffect CreateEffect(GraphicsDevice graphics, Stream byteCode)
|
||||
{
|
||||
return new EffectGL3(graphics, byteCode);
|
||||
return new EffectGL3(byteCode);
|
||||
}
|
||||
|
||||
public INativeEffect CreateEffect(GraphicsDevice graphics,
|
||||
Stream vertexShaderByteCode, Stream pixelShaderByteCode)
|
||||
{
|
||||
return new EffectGL3(graphics, vertexShaderByteCode, pixelShaderByteCode);
|
||||
return new EffectGL3(vertexShaderByteCode, pixelShaderByteCode);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -129,17 +125,40 @@ namespace ANX.Framework.Windows.GL3
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateIndexBuffer
|
||||
/// <summary>
|
||||
/// Create a native index buffer.
|
||||
/// </summary>
|
||||
/// <param name="graphics">The current graphics device.</param>
|
||||
/// <param name="size">The size of a single index element.</param>
|
||||
/// <param name="indexCount">The number of indices stored in the buffer.
|
||||
/// </param>
|
||||
/// <param name="usage">The usage type of the buffer.</param>
|
||||
/// <returns>Native OpenGL index buffer.</returns>
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics,
|
||||
IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new IndexBufferGL3(size, indexCount, usage);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateVertexBuffer
|
||||
/// <summary>
|
||||
/// Create a native vertex buffer.
|
||||
/// </summary>
|
||||
/// <param name="graphics">The current graphics device.</param>
|
||||
/// <param name="size">The vertex declaration for the buffer.</param>
|
||||
/// <param name="indexCount">The number of vertices stored in the buffer.
|
||||
/// </param>
|
||||
/// <param name="usage">The usage type of the buffer.</param>
|
||||
/// <returns>Native OpenGL vertex buffer.</returns>
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics,
|
||||
VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
VertexDeclaration vertexDeclaration, int vertexCount,
|
||||
BufferUsage usage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new VertexBufferGL3(vertexDeclaration, vertexCount, usage);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateBlendState
|
||||
/// <summary>
|
||||
@ -185,6 +204,12 @@ namespace ANX.Framework.Windows.GL3
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetShaderByteCode (TODO)
|
||||
/// <summary>
|
||||
/// Get the byte code of a pre defined shader.
|
||||
/// </summary>
|
||||
/// <param name="type">Pre defined shader type.</param>
|
||||
/// <returns>Byte code of the shader.</returns>
|
||||
public byte[] GetShaderByteCode(PreDefinedShader type)
|
||||
{
|
||||
switch (type)
|
||||
@ -197,5 +222,6 @@ namespace ANX.Framework.Windows.GL3
|
||||
"' isn't supported yet!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Otk = OpenTK.Graphics;
|
||||
using ANX.Framework.Graphics;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
#region License
|
||||
|
||||
@ -54,15 +55,18 @@ namespace ANX.Framework.Windows.GL3
|
||||
{
|
||||
public const float ColorMultiplier = 1f / 255f;
|
||||
|
||||
public static void Convert(ref Color anxColor, out Otk.Color4 otkColor)
|
||||
#region Convert ANX.Color -> OpenTK.Color4
|
||||
public static void Convert(ref Color anxColor, out Color4 otkColor)
|
||||
{
|
||||
otkColor.R = anxColor.R * ColorMultiplier;
|
||||
otkColor.G = anxColor.G * ColorMultiplier;
|
||||
otkColor.B = anxColor.B * ColorMultiplier;
|
||||
otkColor.A = anxColor.A * ColorMultiplier;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static void Convert(ref Otk.Color4 otkColor, out Color anxColor)
|
||||
#region Convert OpenTK.Color4 -> ANX.Color
|
||||
public static void Convert(ref Color4 otkColor, out Color anxColor)
|
||||
{
|
||||
anxColor = new Color(otkColor.R, otkColor.G, otkColor.B, otkColor.A);
|
||||
|
||||
@ -73,5 +77,76 @@ namespace ANX.Framework.Windows.GL3
|
||||
//byte a = (byte)(otkColor.A * 255);
|
||||
//anxColor.PackedValue = (uint)(r + (g << 8) + (b << 16) + (a << 24));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SurfaceToColorFormat (TODO)
|
||||
/// <summary>
|
||||
/// Translate the XNA surface format to an OpenGL ColorFormat.
|
||||
/// </summary>
|
||||
/// <param name="format">XNA surface format.</param>
|
||||
/// <returns>Translated color format for OpenGL.</returns>
|
||||
public static ColorFormat SurfaceToColorFormat(SurfaceFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
// TODO
|
||||
case SurfaceFormat.Dxt1:
|
||||
case SurfaceFormat.Dxt3:
|
||||
case SurfaceFormat.Dxt5:
|
||||
case SurfaceFormat.HdrBlendable:
|
||||
throw new NotImplementedException("Surface Format '" + format +
|
||||
"' isn't implemented yet!");
|
||||
|
||||
// TODO: CHECK!
|
||||
case SurfaceFormat.NormalizedByte2:
|
||||
return new ColorFormat(8, 8, 0, 0);
|
||||
|
||||
//DONE
|
||||
default:
|
||||
case SurfaceFormat.Color:
|
||||
case SurfaceFormat.NormalizedByte4:
|
||||
return new ColorFormat(8, 8, 8, 8);
|
||||
|
||||
case SurfaceFormat.HalfVector2:
|
||||
return new ColorFormat(16, 16, 0, 0);
|
||||
|
||||
case SurfaceFormat.HalfVector4:
|
||||
return new ColorFormat(16, 16, 16, 16);
|
||||
|
||||
case SurfaceFormat.Bgra4444:
|
||||
return new ColorFormat(4, 4, 4, 4);
|
||||
|
||||
case SurfaceFormat.Bgra5551:
|
||||
return new ColorFormat(5, 5, 5, 1);
|
||||
|
||||
case SurfaceFormat.Alpha8:
|
||||
return new ColorFormat(0, 0, 0, 8);
|
||||
|
||||
case SurfaceFormat.Bgr565:
|
||||
return new ColorFormat(5, 6, 5, 0);
|
||||
|
||||
case SurfaceFormat.Rg32:
|
||||
return new ColorFormat(16, 16, 0, 0);
|
||||
|
||||
case SurfaceFormat.Rgba1010102:
|
||||
return new ColorFormat(10, 10, 10, 2);
|
||||
|
||||
case SurfaceFormat.Rgba64:
|
||||
return new ColorFormat(16, 16, 16, 16);
|
||||
|
||||
case SurfaceFormat.HalfSingle:
|
||||
return new ColorFormat(16, 0, 0, 0);
|
||||
|
||||
case SurfaceFormat.Single:
|
||||
return new ColorFormat(32, 0, 0, 0);
|
||||
|
||||
case SurfaceFormat.Vector2:
|
||||
return new ColorFormat(32, 32, 0, 0);
|
||||
|
||||
case SurfaceFormat.Vector4:
|
||||
return new ColorFormat(32, 32, 32, 32);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
#region License
|
||||
|
||||
@ -53,16 +54,97 @@ using ANX.Framework.NonXNA;
|
||||
|
||||
namespace ANX.Framework.Windows.GL3
|
||||
{
|
||||
/// <summary>
|
||||
/// Native OpenGL Effect implementation.
|
||||
/// </summary>
|
||||
public class EffectGL3 : INativeEffect
|
||||
{
|
||||
public EffectGL3(GraphicsDevice device, Stream vertexShaderByteCode,
|
||||
#region Private
|
||||
/// <summary>
|
||||
/// The native shader handle.
|
||||
/// </summary>
|
||||
private int programHandle;
|
||||
#endregion
|
||||
|
||||
#region Constructor (TODO)
|
||||
/// <summary>
|
||||
/// Create a new effect instance of separate streams.
|
||||
/// </summary>
|
||||
/// <param name="vertexShaderByteCode">The vertex shader code.</param>
|
||||
/// <param name="pixelShaderByteCode">The fragment shader code.</param>
|
||||
public EffectGL3(Stream vertexShaderByteCode,
|
||||
Stream pixelShaderByteCode)
|
||||
{
|
||||
CreateShader("", "");
|
||||
}
|
||||
|
||||
public EffectGL3(GraphicsDevice device, Stream byteCode)
|
||||
/// <summary>
|
||||
/// Create a new effect instance of one streams.
|
||||
/// </summary>
|
||||
/// <param name="byteCode">The byte code of the shader.</param>
|
||||
public EffectGL3(Stream byteCode)
|
||||
{
|
||||
CreateShader("", "");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CreateShader
|
||||
private void CreateShader(string vertexSource, string fragmentSource)
|
||||
{
|
||||
int vertexShader = GL.CreateShader(ShaderType.VertexShader);
|
||||
string vertexError = CompileShader(vertexShader, vertexSource);
|
||||
if (String.IsNullOrEmpty(vertexError) == false)
|
||||
{
|
||||
throw new InvalidDataException("Failed to compile the vertex " +
|
||||
"shader because of: " + vertexError);
|
||||
}
|
||||
|
||||
int fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
|
||||
string fragmentError = CompileShader(fragmentShader, fragmentSource);
|
||||
if (String.IsNullOrEmpty(fragmentError) == false)
|
||||
{
|
||||
throw new InvalidDataException("Failed to compile the fragment " +
|
||||
"shader because of: " + fragmentError);
|
||||
}
|
||||
|
||||
programHandle = GL.CreateProgram();
|
||||
GL.AttachShader(programHandle, vertexShader);
|
||||
GL.AttachShader(programHandle, fragmentShader);
|
||||
GL.LinkProgram(programHandle);
|
||||
|
||||
int result;
|
||||
GL.GetProgram(programHandle, ProgramParameter.LinkStatus, out result);
|
||||
if (result == 0)
|
||||
{
|
||||
string programError;
|
||||
GL.GetProgramInfoLog(programHandle, out programError);
|
||||
throw new InvalidDataException("Failed to link the shader program " +
|
||||
"because of: " + programError);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CompileShader
|
||||
private string CompileShader(int shader, string source)
|
||||
{
|
||||
GL.ShaderSource(shader, source);
|
||||
GL.CompileShader(shader);
|
||||
|
||||
int result;
|
||||
GL.GetShader(shader, ShaderParameter.CompileStatus, out result);
|
||||
if (result == 0)
|
||||
{
|
||||
string error = "";
|
||||
GL.GetShaderInfoLog(shader, out error);
|
||||
|
||||
GL.DeleteShader(shader);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region INativeEffect Member
|
||||
|
||||
@ -99,13 +181,24 @@ namespace ANX.Framework.Windows.GL3
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable Member
|
||||
|
||||
#region Dispose
|
||||
/// <summary>
|
||||
/// Dispose the native shader data.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
GL.DeleteProgram(programHandle);
|
||||
|
||||
int result;
|
||||
GL.GetProgram(programHandle, ProgramParameter.DeleteStatus, out result);
|
||||
if (result == 0)
|
||||
{
|
||||
string deleteError;
|
||||
GL.GetProgramInfoLog(programHandle, out deleteError);
|
||||
throw new Exception("Failed to delete the shader program because of: " +
|
||||
deleteError);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
97
ANX.Framework.Windows.GL3/EffectParameterGL3.cs
Normal file
97
ANX.Framework.Windows.GL3/EffectParameterGL3.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.Graphics;
|
||||
|
||||
#region License
|
||||
|
||||
//
|
||||
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
|
||||
//
|
||||
// This file is released under the Ms-PL license.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Microsoft Public License (Ms-PL)
|
||||
//
|
||||
// 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
|
||||
|
||||
namespace ANX.Framework.Windows.GL3
|
||||
{
|
||||
/// <summary>
|
||||
/// Native OpenGL implementation of an effect parameter.
|
||||
/// </summary>
|
||||
public class EffectParameterGL3 : INativeEffectParameter
|
||||
{
|
||||
#region Public
|
||||
/// <summary>
|
||||
/// The name of the effect parameter.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
/// Create a ne effect parameter object.
|
||||
/// </summary>
|
||||
internal EffectParameterGL3()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetValue (TODO)
|
||||
/// <summary>
|
||||
/// Set a matrix value to the effect parameter.
|
||||
/// </summary>
|
||||
/// <param name="value">Value for the parameter</param>
|
||||
public void SetValue(Matrix value)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a texture value to the effect parameter.
|
||||
/// </summary>
|
||||
/// <param name="value">Value for the parameter</param>
|
||||
public void SetValue(Texture value)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
78
ANX.Framework.Windows.GL3/EffectTechniqueGL3.cs
Normal file
78
ANX.Framework.Windows.GL3/EffectTechniqueGL3.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using ANX.Framework.NonXNA;
|
||||
|
||||
#region License
|
||||
|
||||
//
|
||||
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
|
||||
//
|
||||
// This file is released under the Ms-PL license.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Microsoft Public License (Ms-PL)
|
||||
//
|
||||
// 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
|
||||
|
||||
namespace ANX.Framework.Windows.GL3
|
||||
{
|
||||
/// <summary>
|
||||
/// Native OpenGL implementation of an effect technique.
|
||||
/// </summary>
|
||||
public class EffectTechniqueGL3 : INativeEffectTechnique
|
||||
{
|
||||
#region Public
|
||||
/// <summary>
|
||||
/// The name of the effect technique.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
/// Create a ne effect technique object.
|
||||
/// </summary>
|
||||
internal EffectTechniqueGL3()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -138,7 +138,8 @@ namespace ANX.Framework.Windows.GL3
|
||||
presentationParameters.DeviceWindowHandle);
|
||||
|
||||
GraphicsMode graphicsMode = new GraphicsMode(
|
||||
SurfaceToColorFormat(presentationParameters.BackBufferFormat),
|
||||
DatatypesMapping.SurfaceToColorFormat(
|
||||
presentationParameters.BackBufferFormat),
|
||||
depth, stencil,
|
||||
// AntiAlias Samples: 2/4/8/16/32
|
||||
presentationParameters.MultiSampleCount);
|
||||
@ -149,31 +150,6 @@ namespace ANX.Framework.Windows.GL3
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SurfaceToColorFormat (TODO)
|
||||
/// <summary>
|
||||
/// Translate the XNA surface format to an OpenGL ColorFormat.
|
||||
/// </summary>
|
||||
/// <param name="format">XNA surface format.</param>
|
||||
/// <returns>Translated color format for OpenGL.</returns>
|
||||
private static ColorFormat SurfaceToColorFormat(SurfaceFormat format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case SurfaceFormat.Bgra4444:
|
||||
return new ColorFormat(4, 4, 4, 4);
|
||||
|
||||
case SurfaceFormat.Bgra5551:
|
||||
return new ColorFormat(5, 5, 5, 1);
|
||||
|
||||
// TODO: rest of the stuff
|
||||
|
||||
default:
|
||||
case SurfaceFormat.Color:
|
||||
return new ColorFormat(8, 8, 8, 8);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void DrawUserPrimitive()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
127
ANX.Framework.Windows.GL3/IndexBufferGL3.cs
Normal file
127
ANX.Framework.Windows.GL3/IndexBufferGL3.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
#region License
|
||||
|
||||
//
|
||||
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
|
||||
//
|
||||
// This file is released under the Ms-PL license.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Microsoft Public License (Ms-PL)
|
||||
//
|
||||
// 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
|
||||
|
||||
namespace ANX.Framework.Windows.GL3
|
||||
{
|
||||
/// <summary>
|
||||
/// Native OpenGL implementation of a Index Buffer.
|
||||
/// </summary>
|
||||
public class IndexBufferGL3 : INativeBuffer
|
||||
{
|
||||
#region Private
|
||||
/// <summary>
|
||||
/// Native index buffer handle.
|
||||
/// </summary>
|
||||
private int bufferHandle;
|
||||
|
||||
private int indexCount;
|
||||
|
||||
private IndexElementSize elementSize;
|
||||
|
||||
private BufferUsage usage;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
/// Create a new Index Buffer object.
|
||||
/// </summary>
|
||||
internal IndexBufferGL3(IndexElementSize setElementSize,
|
||||
int setIndexCount, BufferUsage setUsage)
|
||||
{
|
||||
indexCount = setIndexCount;
|
||||
elementSize = setElementSize;
|
||||
usage = setUsage;
|
||||
|
||||
GL.GenBuffers(1, out bufferHandle);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetData (TODO)
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data)
|
||||
where T : struct
|
||||
{
|
||||
// TODO: check
|
||||
IntPtr size = (IntPtr)((elementSize == IndexElementSize.SixteenBits ?
|
||||
16 : 32) * data.Length);
|
||||
|
||||
// TODO: check
|
||||
BufferUsageHint usageHint = usage == BufferUsage.WriteOnly ?
|
||||
BufferUsageHint.StaticDraw :
|
||||
BufferUsageHint.DynamicDraw;
|
||||
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, size, data, usageHint);
|
||||
}
|
||||
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data,
|
||||
int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
}
|
||||
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes,
|
||||
T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
/// <summary>
|
||||
/// Dispose the native index buffer data.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
GL.DeleteBuffers(1, ref bufferHandle);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
#region License
|
||||
|
||||
@ -56,10 +57,17 @@ namespace ANX.Framework.Windows.GL3
|
||||
/// <para />
|
||||
/// Basically this is a wrapper class for setting the different values all
|
||||
/// at once, because OpenGL has no State objects like DirectX.
|
||||
/// <para />
|
||||
/// Info for OpenGL filter states:
|
||||
/// http://gregs-blog.com/2008/01/17/opengl-texture-filter-parameters-explained/
|
||||
///
|
||||
/// Info for OGL 3.3 sampler objects (sadly not implemented in OpenTK yet):
|
||||
/// http://www.sinanc.org/blog/?p=215
|
||||
/// </summary>
|
||||
public class SamplerStateGL3 : INativeSamplerState
|
||||
{
|
||||
#region Public
|
||||
#region IsBound
|
||||
/// <summary>
|
||||
/// Flag if the state object is bound to the device.
|
||||
/// </summary>
|
||||
@ -68,49 +76,64 @@ namespace ANX.Framework.Windows.GL3
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddressU
|
||||
public TextureAddressMode AddressU
|
||||
{
|
||||
set;
|
||||
private get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddressV
|
||||
public TextureAddressMode AddressV
|
||||
{
|
||||
set;
|
||||
private get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddressW
|
||||
public TextureAddressMode AddressW
|
||||
{
|
||||
set;
|
||||
private get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filter
|
||||
public TextureFilter Filter
|
||||
{
|
||||
set;
|
||||
private get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MaxAnisotropy
|
||||
public int MaxAnisotropy
|
||||
{
|
||||
set;
|
||||
private get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MaxMipLevel
|
||||
public int MaxMipLevel
|
||||
{
|
||||
set;
|
||||
private get;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MipMapLevelOfDetailBias
|
||||
public float MipMapLevelOfDetailBias
|
||||
{
|
||||
set;
|
||||
private get;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
|
108
ANX.Framework.Windows.GL3/VertexBufferGL3.cs
Normal file
108
ANX.Framework.Windows.GL3/VertexBufferGL3.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using ANX.Framework.NonXNA;
|
||||
using ANX.Framework.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
#region License
|
||||
|
||||
//
|
||||
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
|
||||
//
|
||||
// This file is released under the Ms-PL license.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Microsoft Public License (Ms-PL)
|
||||
//
|
||||
// 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
|
||||
|
||||
namespace ANX.Framework.Windows.GL3
|
||||
{
|
||||
/// <summary>
|
||||
/// Native OpenGL implementation of a Vertex Buffer.
|
||||
/// <para />
|
||||
/// Information about vbo/ibo: http://playcontrol.net/ewing/jibberjabber/opengl_vertex_buffer_object.html
|
||||
/// </summary>
|
||||
public class VertexBufferGL3 : INativeBuffer
|
||||
{
|
||||
#region Private
|
||||
/// <summary>
|
||||
/// Native vertex buffer handle.
|
||||
/// </summary>
|
||||
private int bufferHandle;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
/// Create a new Vertex Buffer object.
|
||||
/// </summary>
|
||||
internal VertexBufferGL3(VertexDeclaration vertexDeclaration,
|
||||
int vertexCount, BufferUsage usage)
|
||||
{
|
||||
GL.GenBuffers(1, out bufferHandle);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetData (TODO)
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data)
|
||||
where T : struct
|
||||
{
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
|
||||
}
|
||||
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, T[] data,
|
||||
int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
}
|
||||
|
||||
public void SetData<T>(GraphicsDevice graphicsDevice, int offsetInBytes,
|
||||
T[] data, int startIndex, int elementCount) where T : struct
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
/// <summary>
|
||||
/// Dispose the native index buffer data.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
GL.DeleteBuffers(1, ref bufferHandle);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user