- Implemented RenderTarget in OpenGL
- Implemented dynamic shader attributes mapping in the vertex buffer in OpenGL
This commit is contained in:
parent
1d61c78f88
commit
8239306d2e
@ -5,8 +5,8 @@ using System.IO;
|
|||||||
using ANX.Framework.Graphics;
|
using ANX.Framework.Graphics;
|
||||||
using ANX.Framework.NonXNA;
|
using ANX.Framework.NonXNA;
|
||||||
using ANX.Framework.NonXNA.RenderSystem;
|
using ANX.Framework.NonXNA.RenderSystem;
|
||||||
using OpenTK;
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
#region License
|
#region License
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Creator : IRenderSystemCreator
|
public class Creator : IRenderSystemCreator
|
||||||
{
|
{
|
||||||
private static Logger logger = LogManager.GetCurrentClassLogger();
|
private static Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
#region Public
|
#region Public
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -81,23 +81,23 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
get { return 100; }
|
get { return 100; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSupported
|
public bool IsSupported
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
//TODO: this is just a very basic version of test for support
|
//TODO: this is just a very basic version of test for support
|
||||||
return AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.Win32NT ||
|
return AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.Win32NT ||
|
||||||
AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.Unix ||
|
AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.Unix ||
|
||||||
AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.MacOSX;
|
AddInSystemFactory.Instance.OperatingSystem.Platform == PlatformID.MacOSX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region RegisterRenderSystemCreator
|
#region RegisterRenderSystemCreator
|
||||||
public void RegisterCreator(AddInSystemFactory factory)
|
public void RegisterCreator(AddInSystemFactory factory)
|
||||||
{
|
{
|
||||||
logger.Debug("adding OpenGL3 RenderSystem creator to creator collection of AddInSystemFactory");
|
logger.Debug("adding OpenGL3 RenderSystem creator to creator collection of AddInSystemFactory");
|
||||||
factory.AddCreator(this);
|
factory.AddCreator(this);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -105,16 +105,16 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
#region CreateGameHost
|
#region CreateGameHost
|
||||||
public GameHost CreateGameHost(Game game)
|
public GameHost CreateGameHost(Game game)
|
||||||
{
|
{
|
||||||
logger.Info("creating OpenGL3 GameHost");
|
logger.Info("creating OpenGL3 GameHost");
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new WindowsGameHost(game);
|
return new WindowsGameHost(game);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region CreateEffect
|
#region CreateEffect
|
||||||
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream byteCode)
|
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream byteCode)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
|
|
||||||
return new EffectGL3(managedEffect, byteCode);
|
return new EffectGL3(managedEffect, byteCode);
|
||||||
}
|
}
|
||||||
@ -122,9 +122,9 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect,
|
public INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect,
|
||||||
Stream vertexShaderByteCode, Stream pixelShaderByteCode)
|
Stream vertexShaderByteCode, Stream pixelShaderByteCode)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
|
|
||||||
return new EffectGL3(managedEffect, vertexShaderByteCode, pixelShaderByteCode);
|
return new EffectGL3(managedEffect, vertexShaderByteCode, pixelShaderByteCode);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -132,8 +132,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
INativeGraphicsDevice IRenderSystemCreator.CreateGraphicsDevice(
|
INativeGraphicsDevice IRenderSystemCreator.CreateGraphicsDevice(
|
||||||
PresentationParameters presentationParameters)
|
PresentationParameters presentationParameters)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new GraphicsDeviceWindowsGL3(presentationParameters);
|
return new GraphicsDeviceWindowsGL3(presentationParameters);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -150,8 +150,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
public INativeTexture2D CreateTexture(GraphicsDevice graphics,
|
public INativeTexture2D CreateTexture(GraphicsDevice graphics,
|
||||||
SurfaceFormat surfaceFormat, int width, int height, int mipCount)
|
SurfaceFormat surfaceFormat, int width, int height, int mipCount)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new Texture2DGL3(surfaceFormat, width, height, mipCount);
|
return new Texture2DGL3(surfaceFormat, width, height, mipCount);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -168,8 +168,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics,
|
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics,
|
||||||
IndexElementSize size, int indexCount, BufferUsage usage)
|
IndexElementSize size, int indexCount, BufferUsage usage)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new IndexBufferGL3(size, indexCount, usage);
|
return new IndexBufferGL3(size, indexCount, usage);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -187,8 +187,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
VertexDeclaration vertexDeclaration, int vertexCount,
|
VertexDeclaration vertexDeclaration, int vertexCount,
|
||||||
BufferUsage usage)
|
BufferUsage usage)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new VertexBufferGL3(vertexDeclaration, vertexCount, usage);
|
return new VertexBufferGL3(vertexDeclaration, vertexCount, usage);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -199,8 +199,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <returns>Native Blend State.</returns>
|
/// <returns>Native Blend State.</returns>
|
||||||
public INativeBlendState CreateBlendState()
|
public INativeBlendState CreateBlendState()
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new BlendStateGL3();
|
return new BlendStateGL3();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -211,8 +211,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <returns>Native Rasterizer State.</returns>
|
/// <returns>Native Rasterizer State.</returns>
|
||||||
public INativeRasterizerState CreateRasterizerState()
|
public INativeRasterizerState CreateRasterizerState()
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new RasterizerStateGL3();
|
return new RasterizerStateGL3();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -223,8 +223,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <returns>Native Depth Stencil State.</returns>
|
/// <returns>Native Depth Stencil State.</returns>
|
||||||
public INativeDepthStencilState CreateDepthStencilState()
|
public INativeDepthStencilState CreateDepthStencilState()
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new DepthStencilStateGL3();
|
return new DepthStencilStateGL3();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -235,8 +235,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <returns>Native Sampler State.</returns>
|
/// <returns>Native Sampler State.</returns>
|
||||||
public INativeSamplerState CreateSamplerState()
|
public INativeSamplerState CreateSamplerState()
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new SamplerStateGL3();
|
return new SamplerStateGL3();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -248,9 +248,9 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <returns>Byte code of the shader.</returns>
|
/// <returns>Byte code of the shader.</returns>
|
||||||
public byte[] GetShaderByteCode(PreDefinedShader type)
|
public byte[] GetShaderByteCode(PreDefinedShader type)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
|
|
||||||
if (type == PreDefinedShader.SpriteBatch)
|
if (type == PreDefinedShader.SpriteBatch)
|
||||||
{
|
{
|
||||||
return ShaderByteCode.SpriteBatchByteCode;
|
return ShaderByteCode.SpriteBatchByteCode;
|
||||||
}
|
}
|
||||||
@ -286,9 +286,9 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <returns>List of graphics adapters.</returns>
|
/// <returns>List of graphics adapters.</returns>
|
||||||
public ReadOnlyCollection<GraphicsAdapter> GetAdapterList()
|
public ReadOnlyCollection<GraphicsAdapter> GetAdapterList()
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
|
|
||||||
var result = new List<GraphicsAdapter>();
|
var result = new List<GraphicsAdapter>();
|
||||||
foreach (DisplayDevice device in DisplayDevice.AvailableDisplays)
|
foreach (DisplayDevice device in DisplayDevice.AvailableDisplays)
|
||||||
{
|
{
|
||||||
var displayModeCollection = new DisplayModeCollection();
|
var displayModeCollection = new DisplayModeCollection();
|
||||||
@ -347,8 +347,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
DepthFormat preferredDepthFormat, int preferredMultiSampleCount,
|
DepthFormat preferredDepthFormat, int preferredMultiSampleCount,
|
||||||
RenderTargetUsage usage)
|
RenderTargetUsage usage)
|
||||||
{
|
{
|
||||||
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
AddInSystemFactory.Instance.PreventRenderSystemChange();
|
||||||
return new RenderTarget2DGL3(width, height, mipMap, preferredFormat,
|
return new RenderTarget2DGL3(width, height, mipMap, preferredFormat,
|
||||||
preferredDepthFormat, preferredMultiSampleCount, usage);
|
preferredDepthFormat, preferredMultiSampleCount, usage);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -63,6 +63,16 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class EffectGL3 : INativeEffect
|
public class EffectGL3 : INativeEffect
|
||||||
{
|
{
|
||||||
|
#region ShaderAttribute (Helper struct)
|
||||||
|
public struct ShaderAttribute
|
||||||
|
{
|
||||||
|
public string Name;
|
||||||
|
public uint Location;
|
||||||
|
public int Size;
|
||||||
|
public ActiveAttribType Type;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Constants
|
#region Constants
|
||||||
private const string FragmentSeparator = "##!fragment!##";
|
private const string FragmentSeparator = "##!fragment!##";
|
||||||
#endregion
|
#endregion
|
||||||
@ -73,7 +83,13 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal int programHandle;
|
internal int programHandle;
|
||||||
|
|
||||||
private Effect managedEffect;
|
private Effect managedEffect;
|
||||||
|
|
||||||
|
internal Dictionary<string, ShaderAttribute> ActiveAttributes
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public
|
#region Public
|
||||||
@ -193,6 +209,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
throw new InvalidDataException("Failed to link the shader program " +
|
throw new InvalidDataException("Failed to link the shader program " +
|
||||||
"because of: " + programError);
|
"because of: " + programError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetAttributes();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -308,6 +326,31 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region GetAttributes
|
||||||
|
private void GetAttributes()
|
||||||
|
{
|
||||||
|
ActiveAttributes = new Dictionary<string, ShaderAttribute>();
|
||||||
|
int attributeCount;
|
||||||
|
GL.GetProgram(programHandle, ProgramParameter.ActiveAttributes,
|
||||||
|
out attributeCount);
|
||||||
|
for (int index = 0; index < attributeCount; index++)
|
||||||
|
{
|
||||||
|
int attributeSize;
|
||||||
|
ActiveAttribType attributeType;
|
||||||
|
string name = GL.GetActiveAttrib(programHandle, index,
|
||||||
|
out attributeSize, out attributeType);
|
||||||
|
uint attributeIndex = (uint)GL.GetAttribLocation(programHandle, name);
|
||||||
|
ActiveAttributes.Add(name, new ShaderAttribute
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Location = attributeIndex,
|
||||||
|
Size = attributeSize,
|
||||||
|
Type = attributeType,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Apply (TODO)
|
#region Apply (TODO)
|
||||||
public void Apply(GraphicsDevice graphicsDevice)
|
public void Apply(GraphicsDevice graphicsDevice)
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using ANX.Framework.Graphics;
|
using ANX.Framework.Graphics;
|
||||||
using ANX.Framework.NonXNA;
|
using ANX.Framework.NonXNA;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
using OpenTK.Platform;
|
using OpenTK.Platform;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
#region License
|
#region License
|
||||||
|
|
||||||
@ -64,63 +65,63 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
private const float ColorMultiplier = 1f / 255f;
|
private const float ColorMultiplier = 1f / 255f;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Interop
|
#region Interop
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int width, int height, uint uFlags);
|
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int width, int height, uint uFlags);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
|
static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct RECT
|
public struct RECT
|
||||||
{
|
{
|
||||||
public int Left; // x position of upper-left corner
|
public int Left; // x position of upper-left corner
|
||||||
public int Top; // y position of upper-left corner
|
public int Top; // y position of upper-left corner
|
||||||
public int Right; // x position of lower-right corner
|
public int Right; // x position of lower-right corner
|
||||||
public int Bottom; // y position of lower-right corner
|
public int Bottom; // y position of lower-right corner
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libX11")]
|
[DllImport("libX11")]
|
||||||
static extern IntPtr XCreateColormap(IntPtr display, IntPtr window, IntPtr visual, int alloc);
|
static extern IntPtr XCreateColormap(IntPtr display, IntPtr window, IntPtr visual, int alloc);
|
||||||
|
|
||||||
[DllImport("libX11", EntryPoint = "XGetVisualInfo")]
|
[DllImport("libX11", EntryPoint = "XGetVisualInfo")]
|
||||||
static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);
|
static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);
|
||||||
|
|
||||||
static IntPtr XGetVisualInfo(IntPtr display, int vinfo_mask, ref XVisualInfo template, out int nitems)
|
static IntPtr XGetVisualInfo(IntPtr display, int vinfo_mask, ref XVisualInfo template, out int nitems)
|
||||||
{
|
{
|
||||||
return XGetVisualInfoInternal(display, (IntPtr)vinfo_mask, ref template, out nitems);
|
return XGetVisualInfoInternal(display, (IntPtr)vinfo_mask, ref template, out nitems);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libX11")]
|
[DllImport("libX11")]
|
||||||
extern static int XPending(IntPtr diplay);
|
extern static int XPending(IntPtr diplay);
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
struct XVisualInfo
|
struct XVisualInfo
|
||||||
{
|
{
|
||||||
public IntPtr Visual;
|
public IntPtr Visual;
|
||||||
public IntPtr VisualID;
|
public IntPtr VisualID;
|
||||||
public int Screen;
|
public int Screen;
|
||||||
public int Depth;
|
public int Depth;
|
||||||
public int Class;
|
public int Class;
|
||||||
public long RedMask;
|
public long RedMask;
|
||||||
public long GreenMask;
|
public long GreenMask;
|
||||||
public long blueMask;
|
public long blueMask;
|
||||||
public int ColormapSize;
|
public int ColormapSize;
|
||||||
public int BitsPerRgb;
|
public int BitsPerRgb;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("id ({0}), screen ({1}), depth ({2}), class ({3})",
|
return String.Format("id ({0}), screen ({1}), depth ({2}), class ({3})",
|
||||||
VisualID, Screen, Depth, Class);
|
VisualID, Screen, Depth, Class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private
|
#region Private
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -136,6 +137,8 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
|
|
||||||
internal static VertexBufferGL3[] boundVertexBuffers =
|
internal static VertexBufferGL3[] boundVertexBuffers =
|
||||||
new VertexBufferGL3[0];
|
new VertexBufferGL3[0];
|
||||||
|
private static RenderTarget2DGL3[] boundRenderTargets =
|
||||||
|
new RenderTarget2DGL3[0];
|
||||||
internal static IndexBufferGL3 boundIndexBuffer;
|
internal static IndexBufferGL3 boundIndexBuffer;
|
||||||
internal static EffectGL3 activeEffect;
|
internal static EffectGL3 activeEffect;
|
||||||
#endregion
|
#endregion
|
||||||
@ -214,51 +217,51 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsMode graphicsMode = new GraphicsMode(DatatypesMapping.SurfaceToColorFormat(presentationParameters.BackBufferFormat),
|
GraphicsMode graphicsMode = new GraphicsMode(DatatypesMapping.SurfaceToColorFormat(presentationParameters.BackBufferFormat),
|
||||||
depth,
|
depth,
|
||||||
stencil,
|
stencil,
|
||||||
presentationParameters.MultiSampleCount // AntiAlias Samples: 2/4/8/16/32
|
presentationParameters.MultiSampleCount // AntiAlias Samples: 2/4/8/16/32
|
||||||
);
|
);
|
||||||
|
|
||||||
if (OpenTK.Configuration.RunningOnWindows)
|
if (OpenTK.Configuration.RunningOnWindows)
|
||||||
{
|
{
|
||||||
nativeWindowInfo = Utilities.CreateWindowsWindowInfo(presentationParameters.DeviceWindowHandle);
|
nativeWindowInfo = Utilities.CreateWindowsWindowInfo(presentationParameters.DeviceWindowHandle);
|
||||||
}
|
}
|
||||||
else if (OpenTK.Configuration.RunningOnX11)
|
else if (OpenTK.Configuration.RunningOnX11)
|
||||||
{
|
{
|
||||||
// Use reflection to retrieve the necessary values from Mono's Windows.Forms implementation.
|
// Use reflection to retrieve the necessary values from Mono's Windows.Forms implementation.
|
||||||
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||||
if (xplatui == null) throw new PlatformNotSupportedException(
|
if (xplatui == null) throw new PlatformNotSupportedException(
|
||||||
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
|
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
|
||||||
|
|
||||||
// get the required handles from the X11 API.
|
// get the required handles from the X11 API.
|
||||||
IntPtr display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
|
IntPtr display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
|
||||||
IntPtr rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
|
IntPtr rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
|
||||||
int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
|
int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
|
||||||
|
|
||||||
// get the XVisualInfo for this GraphicsMode
|
// get the XVisualInfo for this GraphicsMode
|
||||||
XVisualInfo info = new XVisualInfo();
|
XVisualInfo info = new XVisualInfo();
|
||||||
info.VisualID = graphicsMode.Index.Value;
|
info.VisualID = graphicsMode.Index.Value;
|
||||||
int dummy;
|
int dummy;
|
||||||
IntPtr infoPtr = XGetVisualInfo(display, 1 /* VisualInfoMask.ID */, ref info, out dummy);
|
IntPtr infoPtr = XGetVisualInfo(display, 1 /* VisualInfoMask.ID */, ref info, out dummy);
|
||||||
info = (XVisualInfo)Marshal.PtrToStructure(infoPtr, typeof(XVisualInfo));
|
info = (XVisualInfo)Marshal.PtrToStructure(infoPtr, typeof(XVisualInfo));
|
||||||
|
|
||||||
// set the X11 colormap.
|
// set the X11 colormap.
|
||||||
SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
|
SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
|
||||||
SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));
|
SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));
|
||||||
|
|
||||||
nativeWindowInfo = Utilities.CreateX11WindowInfo(display, screen, presentationParameters.DeviceWindowHandle, rootWindow, infoPtr);
|
nativeWindowInfo = Utilities.CreateX11WindowInfo(display, screen, presentationParameters.DeviceWindowHandle, rootWindow, infoPtr);
|
||||||
}
|
}
|
||||||
else if (OpenTK.Configuration.RunningOnMacOS)
|
else if (OpenTK.Configuration.RunningOnMacOS)
|
||||||
{
|
{
|
||||||
nativeWindowInfo = Utilities.CreateMacOSCarbonWindowInfo(presentationParameters.DeviceWindowHandle, false, true);
|
nativeWindowInfo = Utilities.CreateMacOSCarbonWindowInfo(presentationParameters.DeviceWindowHandle, false, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResizeRenderWindow(presentationParameters);
|
ResizeRenderWindow(presentationParameters);
|
||||||
|
|
||||||
nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo);
|
nativeContext = new GraphicsContext(graphicsMode, nativeWindowInfo);
|
||||||
nativeContext.MakeCurrent(nativeWindowInfo);
|
nativeContext.MakeCurrent(nativeWindowInfo);
|
||||||
@ -457,8 +460,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
GL.BindBuffer(BufferTarget.ArrayBuffer,
|
GL.BindBuffer(BufferTarget.ArrayBuffer,
|
||||||
boundVertexBuffers[index].BufferHandle);
|
boundVertexBuffers[index].BufferHandle);
|
||||||
ErrorHelper.Check("BindBuffer");
|
ErrorHelper.Check("BindBuffer");
|
||||||
boundVertexBuffers[index].MapVertexDeclaration(
|
boundVertexBuffers[index].MapVertexDeclaration(activeEffect);
|
||||||
activeEffect.programHandle);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -476,42 +478,81 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void ResizeRenderWindow(PresentationParameters presentationParameters)
|
#region ResizeRenderWindow
|
||||||
{
|
private void ResizeRenderWindow(
|
||||||
if (OpenTK.Configuration.RunningOnWindows)
|
PresentationParameters presentationParameters)
|
||||||
{
|
{
|
||||||
RECT windowRect;
|
if (OpenTK.Configuration.RunningOnWindows)
|
||||||
RECT clientRect;
|
{
|
||||||
if (GetWindowRect(presentationParameters.DeviceWindowHandle, out windowRect) &&
|
RECT windowRect;
|
||||||
GetClientRect(presentationParameters.DeviceWindowHandle, out clientRect))
|
RECT clientRect;
|
||||||
{
|
if (GetWindowRect(presentationParameters.DeviceWindowHandle,
|
||||||
int width = presentationParameters.BackBufferWidth + ((windowRect.Right - windowRect.Left) - clientRect.Right);
|
out windowRect) &&
|
||||||
int height = presentationParameters.BackBufferHeight + ((windowRect.Bottom - windowRect.Top) - clientRect.Bottom);
|
GetClientRect(presentationParameters.DeviceWindowHandle,
|
||||||
|
out clientRect))
|
||||||
|
{
|
||||||
|
int width = presentationParameters.BackBufferWidth +
|
||||||
|
((windowRect.Right - windowRect.Left) - clientRect.Right);
|
||||||
|
int height = presentationParameters.BackBufferHeight +
|
||||||
|
((windowRect.Bottom - windowRect.Top) - clientRect.Bottom);
|
||||||
|
|
||||||
SetWindowPos(presentationParameters.DeviceWindowHandle, IntPtr.Zero, windowRect.Left, windowRect.Top, width, height, 0);
|
SetWindowPos(presentationParameters.DeviceWindowHandle, IntPtr.Zero,
|
||||||
}
|
windowRect.Left, windowRect.Top, width, height, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
static object GetStaticFieldValue(Type type, string fieldName)
|
#region GetStaticFieldValue
|
||||||
{
|
static object GetStaticFieldValue(Type type, string fieldName)
|
||||||
return type.GetField(fieldName,
|
{
|
||||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
|
return type.GetField(fieldName,
|
||||||
}
|
BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
|
||||||
|
}
|
||||||
static void SetStaticFieldValue(Type type, string fieldName, object value)
|
#endregion
|
||||||
{
|
|
||||||
type.GetField(fieldName,
|
|
||||||
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).SetValue(null, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#region SetStaticFieldValue
|
||||||
|
static void SetStaticFieldValue(Type type, string fieldName, object value)
|
||||||
|
{
|
||||||
|
type.GetField(fieldName,
|
||||||
|
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).SetValue(null, value);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region SetRenderTargets
|
||||||
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (renderTargets == null)
|
||||||
}
|
{
|
||||||
|
if (boundRenderTargets.Length > 0)
|
||||||
|
{
|
||||||
|
for (int index = 0; index < boundRenderTargets.Length; index++)
|
||||||
|
{
|
||||||
|
boundRenderTargets[index].Unbind();
|
||||||
|
}
|
||||||
|
boundRenderTargets = new RenderTarget2DGL3[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boundRenderTargets = new RenderTarget2DGL3[renderTargets.Length];
|
||||||
|
for (int index = 0; index < renderTargets.Length; index++)
|
||||||
|
{
|
||||||
|
RenderTarget2D renderTarget =
|
||||||
|
renderTargets[index].RenderTarget as RenderTarget2D;
|
||||||
|
RenderTarget2DGL3 nativeRenderTarget =
|
||||||
|
renderTarget.NativeRenderTarget as RenderTarget2DGL3;
|
||||||
|
boundRenderTargets[index] = nativeRenderTarget;
|
||||||
|
|
||||||
|
nativeRenderTarget.Bind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GetBackBufferData (TODO)
|
||||||
public void GetBackBufferData<T>(Rectangle? rect, T[] data,
|
public void GetBackBufferData<T>(Rectangle? rect, T[] data,
|
||||||
int startIndex, int elementCount) where T : struct
|
int startIndex, int elementCount) where T : struct
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -521,22 +562,35 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
|
public void GetBackBufferData<T>(T[] data, int startIndex,
|
||||||
|
int elementCount) where T : struct
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ResizeBuffers (TODO)
|
||||||
public void ResizeBuffers(PresentationParameters presentationParameters)
|
public void ResizeBuffers(PresentationParameters presentationParameters)
|
||||||
{
|
{
|
||||||
ResizeRenderWindow(presentationParameters);
|
ResizeRenderWindow(presentationParameters);
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void Dispose()
|
#region Dispose
|
||||||
{
|
public void Dispose()
|
||||||
//TODO: implement
|
{
|
||||||
}
|
boundVertexBuffers = null;
|
||||||
|
boundIndexBuffer = null;
|
||||||
|
activeEffect = null;
|
||||||
|
boundRenderTargets = null;
|
||||||
|
|
||||||
}
|
nativeContext.Dispose();
|
||||||
|
nativeContext = null;
|
||||||
|
nativeWindowInfo.Dispose();
|
||||||
|
nativeWindowInfo = null;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.8.0")]
|
[assembly: AssemblyVersion("0.5.9.0")]
|
||||||
[assembly: AssemblyFileVersion("0.5.8.0")]
|
[assembly: AssemblyFileVersion("0.5.9.0")]
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")]
|
[assembly: InternalsVisibleTo("ANX.Framework.ContentPipeline")]
|
||||||
|
@ -1,15 +1,142 @@
|
|||||||
using System;
|
using System;
|
||||||
using ANX.Framework.NonXNA.RenderSystem;
|
|
||||||
using ANX.Framework.Graphics;
|
using ANX.Framework.Graphics;
|
||||||
|
using ANX.Framework.NonXNA.RenderSystem;
|
||||||
|
using OpenTK.Graphics.OpenGL;
|
||||||
|
|
||||||
namespace ANX.Framework.Windows.GL3
|
namespace ANX.Framework.Windows.GL3
|
||||||
{
|
{
|
||||||
public class RenderTarget2DGL3 : INativeRenderTarget2D
|
public class RenderTarget2DGL3 : Texture2DGL3, INativeRenderTarget2D
|
||||||
{
|
{
|
||||||
|
#region Private
|
||||||
|
private int framebufferHandle;
|
||||||
|
private int renderbufferHandle;
|
||||||
|
|
||||||
|
private bool generateMipmaps;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// TODO: usage, preferredMultiSampleCount
|
||||||
|
#region Constructor
|
||||||
public RenderTarget2DGL3(int width, int height, bool mipMap,
|
public RenderTarget2DGL3(int width, int height, bool mipMap,
|
||||||
SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat,
|
SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat,
|
||||||
int preferredMultiSampleCount, RenderTargetUsage usage)
|
int preferredMultiSampleCount, RenderTargetUsage usage)
|
||||||
{
|
{
|
||||||
|
generateMipmaps = mipMap;
|
||||||
|
PixelInternalFormat nativeFormat =
|
||||||
|
DatatypesMapping.SurfaceToPixelInternalFormat(preferredFormat);
|
||||||
|
|
||||||
|
#region Image creation
|
||||||
|
NativeHandle = GL.GenTexture();
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, NativeHandle);
|
||||||
|
GL.TexParameter(TextureTarget.Texture2D,
|
||||||
|
TextureParameterName.TextureMagFilter, (int)All.Linear);
|
||||||
|
GL.TexParameter(TextureTarget.Texture2D,
|
||||||
|
TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
|
||||||
|
GL.TexParameter(TextureTarget.Texture2D,
|
||||||
|
TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
|
||||||
|
if (generateMipmaps)
|
||||||
|
{
|
||||||
|
GL.TexParameter(TextureTarget.Texture2D,
|
||||||
|
TextureParameterName.GenerateMipmap, 1);
|
||||||
|
GL.TexParameter(TextureTarget.Texture2D,
|
||||||
|
TextureParameterName.TextureMinFilter, (int)All.LinearMipmapLinear);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GL.TexParameter(TextureTarget.Texture2D,
|
||||||
|
TextureParameterName.TextureMinFilter, (int)All.Linear);
|
||||||
|
}
|
||||||
|
|
||||||
|
GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
|
||||||
|
width, height, 0, (PixelFormat)nativeFormat, PixelType.UnsignedByte,
|
||||||
|
IntPtr.Zero);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// create a renderbuffer object to store depth info
|
||||||
|
GL.GenRenderbuffers(1, out renderbufferHandle);
|
||||||
|
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderbufferHandle);
|
||||||
|
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer,
|
||||||
|
DepthFormatConversion(preferredDepthFormat), width, height);
|
||||||
|
GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, 0);
|
||||||
|
|
||||||
|
// create a framebuffer object
|
||||||
|
GL.GenFramebuffers(1, out framebufferHandle);
|
||||||
|
GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebufferHandle);
|
||||||
|
|
||||||
|
// attach the texture to FBO color attachment point
|
||||||
|
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer,
|
||||||
|
FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D,
|
||||||
|
NativeHandle, 0);
|
||||||
|
|
||||||
|
// attach the renderbuffer to depth attachment point
|
||||||
|
GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer,
|
||||||
|
FramebufferAttachment.DepthAttachment,
|
||||||
|
RenderbufferTarget.Renderbuffer, renderbufferHandle);
|
||||||
|
|
||||||
|
// check FBO status
|
||||||
|
FramebufferErrorCode status = GL.CheckFramebufferStatus(
|
||||||
|
FramebufferTarget.Framebuffer);
|
||||||
|
if (status != FramebufferErrorCode.FramebufferComplete)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Failed to create the render target! Error=" + status);
|
||||||
|
}
|
||||||
|
|
||||||
|
// switch back to window-system-provided framebuffer
|
||||||
|
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DepthFormatConversion
|
||||||
|
private RenderbufferStorage DepthFormatConversion(DepthFormat depthFormat)
|
||||||
|
{
|
||||||
|
switch(depthFormat)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case DepthFormat.None:
|
||||||
|
// TODO
|
||||||
|
return RenderbufferStorage.DepthComponent16;
|
||||||
|
//return (RenderbufferStorage)All.DepthComponent;
|
||||||
|
|
||||||
|
case DepthFormat.Depth16:
|
||||||
|
return RenderbufferStorage.DepthComponent16;
|
||||||
|
|
||||||
|
case DepthFormat.Depth24:
|
||||||
|
return RenderbufferStorage.DepthComponent24;
|
||||||
|
|
||||||
|
case DepthFormat.Depth24Stencil8:
|
||||||
|
return RenderbufferStorage.DepthComponent32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Bind
|
||||||
|
public void Bind()
|
||||||
|
{
|
||||||
|
GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebufferHandle);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Unbind
|
||||||
|
public void Unbind()
|
||||||
|
{
|
||||||
|
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
|
||||||
|
if (generateMipmaps)
|
||||||
|
{
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, NativeHandle);
|
||||||
|
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Dispose
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
base.Dispose();
|
||||||
|
GL.DeleteFramebuffers(1, ref framebufferHandle);
|
||||||
|
GL.DeleteRenderbuffers(1, ref renderbufferHandle);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
#region SpriteBatchShader
|
#region SpriteBatchShader
|
||||||
internal static byte[] SpriteBatchByteCode = new byte[]
|
internal static byte[] SpriteBatchByteCode = new byte[]
|
||||||
{
|
{
|
||||||
160,
|
186,
|
||||||
003, 117, 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, 052, 032, 077, 097, 116, 114, 105, 120,
|
003, 117, 110, 105, 102, 111, 114, 109, 032, 109, 097, 116, 052, 032, 077, 097, 116, 114, 105, 120,
|
||||||
084, 114, 097, 110, 115, 102, 111, 114, 109, 059, 010, 097, 116, 116, 114, 105, 098, 117, 116, 101,
|
084, 114, 097, 110, 115, 102, 111, 114, 109, 059, 010, 097, 116, 116, 114, 105, 098, 117, 116, 101,
|
||||||
032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 010, 097, 116, 116, 114, 105, 098, 117, 116, 101,
|
032, 118, 101, 099, 052, 032, 112, 111, 115, 059, 010, 097, 116, 116, 114, 105, 098, 117, 116, 101,
|
||||||
@ -67,19 +67,20 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 042, 112, 111, 115, 059, 010, 100, 105,
|
114, 105, 120, 084, 114, 097, 110, 115, 102, 111, 114, 109, 042, 112, 111, 115, 059, 010, 100, 105,
|
||||||
102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, 010, 100,
|
102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 061, 116, 101, 120, 059, 010, 100,
|
||||||
105, 102, 102, 117, 115, 101, 067, 111, 108, 111, 114, 061, 099, 111, 108, 059, 125, 010, 035, 035,
|
105, 102, 102, 117, 115, 101, 067, 111, 108, 111, 114, 061, 099, 111, 108, 059, 125, 010, 035, 035,
|
||||||
033, 102, 114, 097, 103, 109, 101, 110, 116, 033, 035, 035, 010, 117, 110, 105, 102, 111, 114, 109,
|
033, 102, 114, 097, 103, 109, 101, 110, 116, 033, 035, 035, 010, 112, 114, 101, 099, 105, 115, 115,
|
||||||
032, 115, 097, 109, 112, 108, 101, 114, 050, 068, 032, 084, 101, 120, 116, 117, 114, 101, 059, 010,
|
105, 111, 110, 032, 109, 101, 100, 105, 117, 109, 112, 032, 102, 108, 111, 097, 116, 059, 010, 117,
|
||||||
118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100, 105, 102, 102, 117, 115, 101,
|
110, 105, 102, 111, 114, 109, 032, 115, 097, 109, 112, 108, 101, 114, 050, 068, 032, 084, 101, 120,
|
||||||
067, 111, 108, 111, 114, 059, 010, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 050, 032,
|
116, 117, 114, 101, 059, 010, 118, 097, 114, 121, 105, 110, 103, 032, 118, 101, 099, 052, 032, 100,
|
||||||
100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100, 059, 010, 118, 111, 105,
|
105, 102, 102, 117, 115, 101, 067, 111, 108, 111, 114, 059, 010, 118, 097, 114, 121, 105, 110, 103,
|
||||||
100, 032, 109, 097, 105, 110, 040, 118, 111, 105, 100, 041, 123, 010, 103, 108, 095, 070, 114, 097,
|
032, 118, 101, 099, 050, 032, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114,
|
||||||
103, 067, 111, 108, 111, 114, 061, 116, 101, 120, 116, 117, 114, 101, 050, 068, 040, 084, 101, 120,
|
100, 059, 010, 118, 111, 105, 100, 032, 109, 097, 105, 110, 040, 118, 111, 105, 100, 041, 123, 010,
|
||||||
116, 117, 114, 101, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101, 120, 067, 111, 111, 114, 100,
|
103, 108, 095, 070, 114, 097, 103, 067, 111, 108, 111, 114, 061, 116, 101, 120, 116, 117, 114, 101,
|
||||||
041, 042, 100, 105, 102, 102, 117, 115, 101, 067, 111, 108, 111, 114, 059, 125, 010, 095, 046, 094,
|
050, 068, 040, 084, 101, 120, 116, 117, 114, 101, 044, 100, 105, 102, 102, 117, 115, 101, 084, 101,
|
||||||
078, 240, 054, 006, 106, 005, 190, 104, 250, 201, 129, 166, 050, 199, 249, 189, 159, 008, 207, 084,
|
120, 067, 111, 111, 114, 100, 041, 042, 100, 105, 102, 102, 117, 115, 101, 067, 111, 108, 111, 114,
|
||||||
062, 171, 010, 076, 101, 119, 047, 079, 245, 134, 024, 149, 110, 166, 213, 153, 023, 179, 120, 191,
|
059, 125, 010, 204, 002, 066, 009, 044, 094, 101, 149, 163, 197, 203, 229, 083, 172, 100, 007, 002,
|
||||||
146, 106, 047, 180, 084, 037, 088, 036, 132, 126, 030, 027, 054, 044, 236, 120, 086, 102, 211, 178,
|
181, 147, 172, 186, 193, 103, 068, 009, 005, 065, 152, 020, 077, 034, 207, 124, 030, 210, 046, 182,
|
||||||
125
|
155, 204, 156, 086, 170, 100, 065, 083, 209, 239, 206, 226, 075, 115, 157, 118, 160, 025, 101, 098,
|
||||||
|
159, 062, 171, 094, 128, 095, 188
|
||||||
};
|
};
|
||||||
#endregion //SpriteBatchShader
|
#endregion //SpriteBatchShader
|
||||||
|
|
||||||
|
@ -89,14 +89,18 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The OpenGL texture handle.
|
/// The OpenGL texture handle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal int NativeHandle
|
protected internal int NativeHandle
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
private set;
|
protected set;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
|
internal Texture2DGL3()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new native OpenGL texture.
|
/// Create a new native OpenGL texture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -165,6 +169,11 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
"Loading mipmaps is not correctly implemented yet!");
|
"Loading mipmaps is not correctly implemented yet!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, NativeHandle);
|
||||||
|
#if DEBUG
|
||||||
|
ErrorHelper.Check("BindTexture");
|
||||||
|
#endif
|
||||||
|
|
||||||
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||||
|
|
||||||
// TODO: get size of first mipmap!
|
// TODO: get size of first mipmap!
|
||||||
@ -235,7 +244,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose the native OpenGL texture handle.
|
/// Dispose the native OpenGL texture handle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
GL.DeleteTexture(NativeHandle);
|
GL.DeleteTexture(NativeHandle);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -178,67 +178,54 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region MapVertexDeclaration
|
#region MapVertexDeclaration
|
||||||
internal void MapVertexDeclaration(int programHandle)
|
internal void MapVertexDeclaration(EffectGL3 effect)
|
||||||
{
|
{
|
||||||
int attributes;
|
|
||||||
GL.GetProgram(programHandle, ProgramParameter.ActiveAttributes,
|
|
||||||
out attributes);
|
|
||||||
|
|
||||||
VertexElement[] elements = vertexDeclaration.GetVertexElements();
|
VertexElement[] elements = vertexDeclaration.GetVertexElements();
|
||||||
if (elements.Length != attributes)
|
if (elements.Length != effect.ActiveAttributes.Count)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Mapping the VertexDeclaration " +
|
throw new InvalidOperationException("Mapping the VertexDeclaration " +
|
||||||
"onto the glsl attributes failed because we have " +
|
"onto the glsl attributes failed because we have " +
|
||||||
attributes + " Shader Attributes and " + elements.Length +
|
effect.ActiveAttributes.Count + " Shader Attributes and " +
|
||||||
" elements in the vertex declaration which doesn't fit!");
|
elements.Length + " elements in the vertex declaration which " +
|
||||||
|
"doesn't fit!");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (VertexElement element in elements)
|
foreach (string key in effect.ActiveAttributes.Keys)
|
||||||
{
|
{
|
||||||
// TODO: element.UsageIndex?
|
EffectGL3.ShaderAttribute attribute = effect.ActiveAttributes[key];
|
||||||
|
GL.EnableVertexAttribArray(attribute.Location);
|
||||||
|
VertexElement element = elements[(int)attribute.Location];
|
||||||
|
|
||||||
switch (element.VertexElementUsage)
|
switch (element.VertexElementUsage)
|
||||||
{
|
{
|
||||||
|
case VertexElementUsage.Binormal:
|
||||||
|
case VertexElementUsage.Normal:
|
||||||
|
case VertexElementUsage.Tangent:
|
||||||
|
case VertexElementUsage.BlendIndices:
|
||||||
|
case VertexElementUsage.BlendWeight:
|
||||||
case VertexElementUsage.Position:
|
case VertexElementUsage.Position:
|
||||||
int loc = GL.GetAttribLocation(programHandle, "pos");
|
GL.VertexAttribPointer((int)attribute.Location, 3,
|
||||||
ErrorHelper.Check("GetAttribLocation pos");
|
VertexAttribPointerType.Float, false,
|
||||||
GL.EnableVertexAttribArray(loc);
|
vertexDeclaration.VertexStride, element.Offset);
|
||||||
ErrorHelper.Check("EnableVertexAttribArray pos");
|
|
||||||
GL.VertexAttribPointer(loc, 3, VertexAttribPointerType.Float,
|
|
||||||
false, vertexDeclaration.VertexStride, element.Offset);
|
|
||||||
ErrorHelper.Check("VertexAttribPointer pos");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VertexElementUsage.Color:
|
case VertexElementUsage.Color:
|
||||||
int col = GL.GetAttribLocation(programHandle, "col");
|
GL.VertexAttribPointer((int)attribute.Location, 4,
|
||||||
ErrorHelper.Check("GetAttribLocation col");
|
VertexAttribPointerType.UnsignedByte,
|
||||||
GL.EnableVertexAttribArray(col);
|
true, vertexDeclaration.VertexStride, element.Offset);
|
||||||
ErrorHelper.Check("EnableVertexAttribArray col");
|
|
||||||
GL.VertexAttribPointer(col, 4, VertexAttribPointerType.UnsignedByte,
|
|
||||||
true, vertexDeclaration.VertexStride, element.Offset);
|
|
||||||
ErrorHelper.Check("VertexAttribPointer col");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VertexElementUsage.TextureCoordinate:
|
case VertexElementUsage.TextureCoordinate:
|
||||||
int tex = GL.GetAttribLocation(programHandle, "tex");
|
GL.VertexAttribPointer((int)attribute.Location, 2,
|
||||||
ErrorHelper.Check("GetAttribLocation tex");
|
VertexAttribPointerType.Float, false,
|
||||||
GL.EnableVertexAttribArray(tex);
|
vertexDeclaration.VertexStride, element.Offset);
|
||||||
ErrorHelper.Check("EnableVertexAttribArray tex");
|
|
||||||
GL.VertexAttribPointer(tex, 2, VertexAttribPointerType.Float,
|
|
||||||
false, vertexDeclaration.VertexStride, element.Offset);
|
|
||||||
ErrorHelper.Check("VertexAttribPointer tex");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
case VertexElementUsage.Binormal:
|
|
||||||
case VertexElementUsage.BlendIndices:
|
|
||||||
case VertexElementUsage.BlendWeight:
|
|
||||||
case VertexElementUsage.Depth:
|
case VertexElementUsage.Depth:
|
||||||
case VertexElementUsage.Fog:
|
case VertexElementUsage.Fog:
|
||||||
case VertexElementUsage.Normal:
|
|
||||||
case VertexElementUsage.PointSize:
|
case VertexElementUsage.PointSize:
|
||||||
case VertexElementUsage.Sample:
|
case VertexElementUsage.Sample:
|
||||||
case VertexElementUsage.Tangent:
|
|
||||||
case VertexElementUsage.TessellateFactor:
|
case VertexElementUsage.TessellateFactor:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using ANX.Framework.NonXNA;
|
||||||
|
|
||||||
namespace RenderTarget
|
namespace RenderTarget
|
||||||
{
|
{
|
||||||
@ -9,7 +10,8 @@ namespace RenderTarget
|
|||||||
/// Der Haupteinstiegspunkt für die Anwendung.
|
/// Der Haupteinstiegspunkt für die Anwendung.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
//AddInSystemFactory.Instance.PreferredRenderSystem = "OpenGL3";
|
||||||
using (Game1 game = new Game1())
|
using (Game1 game = new Game1())
|
||||||
{
|
{
|
||||||
game.Run();
|
game.Run();
|
||||||
|
@ -91,6 +91,10 @@
|
|||||||
<Project>{5BE49183-2F6F-4527-AC90-D816911FCF90}</Project>
|
<Project>{5BE49183-2F6F-4527-AC90-D816911FCF90}</Project>
|
||||||
<Name>ANX.Framework.Windows.DX10</Name>
|
<Name>ANX.Framework.Windows.DX10</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\RenderSystems\ANX.Framework.Windows.GL3\ANX.Framework.Windows.GL3.csproj">
|
||||||
|
<Project>{EB8258E0-6741-4DB9-B756-1EBDF67B1ED6}</Project>
|
||||||
|
<Name>ANX.Framework.Windows.GL3</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\SoundSystems\ANX.SoundSystem.Windows.XAudio\ANX.SoundSystem.Windows.XAudio.csproj">
|
<ProjectReference Include="..\..\SoundSystems\ANX.SoundSystem.Windows.XAudio\ANX.SoundSystem.Windows.XAudio.csproj">
|
||||||
<Project>{6A582788-C4D2-410C-96CD-177F75712D65}</Project>
|
<Project>{6A582788-C4D2-410C-96CD-177F75712D65}</Project>
|
||||||
<Name>ANX.SoundSystem.Windows.XAudio</Name>
|
<Name>ANX.SoundSystem.Windows.XAudio</Name>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using ANX.Framework.NonXNA;
|
||||||
|
|
||||||
namespace WindowsGame1
|
namespace WindowsGame1
|
||||||
{
|
{
|
||||||
@ -10,6 +11,7 @@ namespace WindowsGame1
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
//AddInSystemFactory.Instance.PreferredRenderSystem = "OpenGL3";
|
||||||
using (Game1 game = new Game1())
|
using (Game1 game = new Game1())
|
||||||
{
|
{
|
||||||
game.Run();
|
game.Run();
|
||||||
|
@ -53,7 +53,7 @@ attribute vec2 tex;
|
|||||||
|
|
||||||
varying vec4 diffuseColor;
|
varying vec4 diffuseColor;
|
||||||
varying vec2 diffuseTexCoord;
|
varying vec2 diffuseTexCoord;
|
||||||
void main(void)
|
void main( )
|
||||||
{
|
{
|
||||||
gl_Position = MatrixTransform * pos;
|
gl_Position = MatrixTransform * pos;
|
||||||
diffuseTexCoord = tex;
|
diffuseTexCoord = tex;
|
||||||
@ -66,11 +66,13 @@ void main(void)
|
|||||||
// Fragment Shader
|
// Fragment Shader
|
||||||
//
|
//
|
||||||
|
|
||||||
|
precission mediump float;
|
||||||
|
|
||||||
uniform sampler2D Texture;
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
varying vec4 diffuseColor;
|
varying vec4 diffuseColor;
|
||||||
varying vec2 diffuseTexCoord;
|
varying vec2 diffuseTexCoord;
|
||||||
void main(void)
|
void main( )
|
||||||
{
|
{
|
||||||
gl_FragColor = texture2D(Texture, diffuseTexCoord) * diffuseColor;
|
gl_FragColor = texture2D(Texture, diffuseTexCoord) * diffuseColor;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user