Working on all OpenGL classes and working on hardcore
error checking integration (later on this will be disabled).
This commit is contained in:
parent
26f81c06a7
commit
ad1bc47a24
@ -22,6 +22,7 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
@ -30,6 +31,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="OpenTK">
|
<Reference Include="OpenTK">
|
||||||
@ -47,6 +49,7 @@
|
|||||||
<Compile Include="EffectGL3.cs" />
|
<Compile Include="EffectGL3.cs" />
|
||||||
<Compile Include="EffectParameterGL3.cs" />
|
<Compile Include="EffectParameterGL3.cs" />
|
||||||
<Compile Include="EffectTechniqueGL3.cs" />
|
<Compile Include="EffectTechniqueGL3.cs" />
|
||||||
|
<Compile Include="ErrorHelper.cs" />
|
||||||
<Compile Include="GraphicsDeviceWindowsGL3.cs" />
|
<Compile Include="GraphicsDeviceWindowsGL3.cs" />
|
||||||
<Compile Include="IndexBufferGL3.cs" />
|
<Compile Include="IndexBufferGL3.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@ -260,72 +260,6 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region VertexElementFormatToVertexPointerType (TODO)
|
|
||||||
/// <summary>
|
|
||||||
/// Translate the XNA VertexElementFormat to an OpenGL VertexPointerType.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="format">XNA VertexElementFormat.</param>
|
|
||||||
/// <param name="size">Returns the size of the vertex element.</param>
|
|
||||||
/// <returns>Translated VertexPointerType for OpenGL.</returns>
|
|
||||||
public static VertexPointerType VertexElementFormatToVertexPointerType(
|
|
||||||
VertexElementFormat format, out int size)
|
|
||||||
{
|
|
||||||
switch (format)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case VertexElementFormat.Vector2:
|
|
||||||
size = 2;
|
|
||||||
return VertexPointerType.Float;
|
|
||||||
|
|
||||||
case VertexElementFormat.Vector3:
|
|
||||||
size = 3;
|
|
||||||
return VertexPointerType.Float;
|
|
||||||
|
|
||||||
case VertexElementFormat.Vector4:
|
|
||||||
size = 4;
|
|
||||||
return VertexPointerType.Float;
|
|
||||||
|
|
||||||
case VertexElementFormat.Single:
|
|
||||||
size = 1;
|
|
||||||
return VertexPointerType.Float;
|
|
||||||
|
|
||||||
case VertexElementFormat.HalfVector2:
|
|
||||||
size = 2;
|
|
||||||
return VertexPointerType.HalfFloat;
|
|
||||||
|
|
||||||
case VertexElementFormat.HalfVector4:
|
|
||||||
size = 4;
|
|
||||||
return VertexPointerType.HalfFloat;
|
|
||||||
|
|
||||||
// TODO: check difference Short2/NormalizedShort2
|
|
||||||
case VertexElementFormat.NormalizedShort2:
|
|
||||||
size = 2;
|
|
||||||
return VertexPointerType.Short;
|
|
||||||
|
|
||||||
// TODO: check difference Short4/NormalizedShort4
|
|
||||||
case VertexElementFormat.NormalizedShort4:
|
|
||||||
size = 4;
|
|
||||||
return VertexPointerType.Short;
|
|
||||||
|
|
||||||
// TODO: check difference Short2/NormalizedShort2
|
|
||||||
case VertexElementFormat.Short2:
|
|
||||||
size = 2;
|
|
||||||
return VertexPointerType.Short;
|
|
||||||
|
|
||||||
// TODO: check difference Short4/NormalizedShort4
|
|
||||||
case VertexElementFormat.Short4:
|
|
||||||
size = 4;
|
|
||||||
return VertexPointerType.Short;
|
|
||||||
|
|
||||||
// TODO: check
|
|
||||||
case VertexElementFormat.Byte4:
|
|
||||||
case VertexElementFormat.Color:
|
|
||||||
size = 1;
|
|
||||||
return VertexPointerType.Int;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Tests
|
#region Tests
|
||||||
private class Tests
|
private class Tests
|
||||||
{
|
{
|
||||||
|
@ -71,7 +71,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The native shader handle.
|
/// The native shader handle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int programHandle;
|
internal int programHandle;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public
|
#region Public
|
||||||
@ -305,8 +305,13 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
#region Apply (TODO)
|
#region Apply (TODO)
|
||||||
public void Apply(GraphicsDevice graphicsDevice)
|
public void Apply(GraphicsDevice graphicsDevice)
|
||||||
{
|
{
|
||||||
GL.Enable(EnableCap.Texture2D);
|
if (GraphicsDeviceWindowsGL3.activeEffect != this)
|
||||||
GL.UseProgram(programHandle);
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine("GL: Shader.Apply");
|
||||||
|
GL.UseProgram(programHandle);
|
||||||
|
GraphicsDeviceWindowsGL3.activeEffect = this;
|
||||||
|
ErrorHelper.Check("UseProgram");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -101,22 +101,40 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// <param name="value">Value for the parameter</param>
|
/// <param name="value">Value for the parameter</param>
|
||||||
public void SetValue(Matrix value)
|
public void SetValue(Matrix value)
|
||||||
{
|
{
|
||||||
GL.UniformMatrix4(UniformIndex, 16, false, ref value.M11);
|
GL.UseProgram(parentEffect.programHandle);
|
||||||
|
System.Diagnostics.Debug.WriteLine("GL: Setting Matrix uniform " + value);
|
||||||
|
OpenTK.Matrix4 matrix = new OpenTK.Matrix4(
|
||||||
|
value.M11, value.M12, value.M13, value.M14,
|
||||||
|
value.M21, value.M22, value.M23, value.M24,
|
||||||
|
value.M31, value.M32, value.M33, value.M34,
|
||||||
|
value.M41, value.M42, value.M43, value.M44);
|
||||||
|
|
||||||
|
GL.UniformMatrix4(UniformIndex, false, ref matrix);
|
||||||
|
ErrorHelper.Check("UniformMatrix4");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Texture textureCache = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set a texture value to the effect parameter.
|
/// Set a texture value to the effect parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">Value for the parameter</param>
|
/// <param name="value">Value for the parameter</param>
|
||||||
public void SetValue(Texture value)
|
public void SetValue(Texture value)
|
||||||
{
|
{
|
||||||
// TODO: multiple texture units
|
GL.UseProgram(parentEffect.programHandle);
|
||||||
TextureUnit textureUnit = TextureUnit.Texture0;
|
if (textureCache == null ||
|
||||||
GL.ActiveTexture(textureUnit);
|
textureCache != value)
|
||||||
int handle = (value.NativeTexture as Texture2DGL3).NativeHandle;
|
{
|
||||||
GL.BindTexture(TextureTarget.Texture2D, handle);
|
// TODO: multiple texture units
|
||||||
int unitIndex = (int)(textureUnit - TextureUnit.Texture0);
|
TextureUnit textureUnit = TextureUnit.Texture0;
|
||||||
GL.Uniform1(UniformIndex, 1, ref unitIndex);
|
GL.Enable(EnableCap.Texture2D);
|
||||||
|
GL.ActiveTexture(textureUnit);
|
||||||
|
int handle = (value.NativeTexture as Texture2DGL3).NativeHandle;
|
||||||
|
System.Diagnostics.Debug.WriteLine("GL: Setting Texture uniform " + handle);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, handle);
|
||||||
|
int unitIndex = (int)(textureUnit - TextureUnit.Texture0);
|
||||||
|
GL.Uniform1(UniformIndex, 1, ref unitIndex);
|
||||||
|
ErrorHelper.Check("Uniform1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
34
RenderSystems/ANX.Framework.Windows.GL3/ErrorHelper.cs
Normal file
34
RenderSystems/ANX.Framework.Windows.GL3/ErrorHelper.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenTK.Graphics.OpenGL;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace ANX.Framework.Windows.GL3
|
||||||
|
{
|
||||||
|
internal static class ErrorHelper
|
||||||
|
{
|
||||||
|
public static void Check(string extraInformation = "")
|
||||||
|
{
|
||||||
|
ErrorCode code = GL.GetError();
|
||||||
|
if (code != ErrorCode.NoError)
|
||||||
|
{
|
||||||
|
string frameInfo = "";
|
||||||
|
foreach (StackFrame frame in new StackTrace().GetFrames())
|
||||||
|
{
|
||||||
|
MethodBase method = frame.GetMethod();
|
||||||
|
frameInfo += "\n\t" + "at " + method.DeclaringType + "." +
|
||||||
|
method + ":" + frame.GetFileLineNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
string message = "OpenGL Error '" + code + "' Checked at: '" +
|
||||||
|
extraInformation + "'" + frameInfo;
|
||||||
|
|
||||||
|
Console.WriteLine(message);
|
||||||
|
Debug.WriteLine(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -74,6 +74,11 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
/// to the graphics device.
|
/// to the graphics device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IWindowInfo nativeWindowInfo;
|
private IWindowInfo nativeWindowInfo;
|
||||||
|
|
||||||
|
internal static VertexBufferGL3[] boundVertexBuffers =
|
||||||
|
new VertexBufferGL3[0];
|
||||||
|
internal static IndexBufferGL3 boundIndexBuffer;
|
||||||
|
internal static EffectGL3 activeEffect;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
@ -158,6 +163,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
public void SetViewport(Viewport viewport)
|
public void SetViewport(Viewport viewport)
|
||||||
{
|
{
|
||||||
GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
|
GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
|
||||||
|
ErrorHelper.Check("SetViewport");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -177,6 +183,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
color.B * ColorMultiplier, color.A * ColorMultiplier);
|
color.B * ColorMultiplier, color.A * ColorMultiplier);
|
||||||
}
|
}
|
||||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
|
ErrorHelper.Check("Clear");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -217,6 +224,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
GL.ClearDepth(depth);
|
GL.ClearDepth(depth);
|
||||||
GL.ClearStencil(stencil);
|
GL.ClearStencil(stencil);
|
||||||
GL.Clear(mask);
|
GL.Clear(mask);
|
||||||
|
ErrorHelper.Check("Clear");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -234,60 +242,117 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region DrawIndexedPrimitives
|
||||||
public void DrawIndexedPrimitives(PrimitiveType primitiveType,
|
public void DrawIndexedPrimitives(PrimitiveType primitiveType,
|
||||||
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
|
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
|
||||||
int primitiveCount)
|
int primitiveCount)
|
||||||
{
|
{
|
||||||
// TODO: DrawElementsType, baseVertex, minVertexIndex, numVertices, startIndex
|
System.Diagnostics.Debug.WriteLine("GL: DrawIndexedPrimitives");
|
||||||
GL.DrawElements(DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
|
// TODO: baseVertex, minVertexIndex, numVertices, startIndex, primitiveCount
|
||||||
numVertices, DrawElementsType.UnsignedShort, 0);
|
DrawElementsType elementsType =
|
||||||
}
|
boundIndexBuffer.elementSize == IndexElementSize.SixteenBits ?
|
||||||
|
DrawElementsType.UnsignedShort :
|
||||||
|
DrawElementsType.UnsignedInt;
|
||||||
|
|
||||||
|
GL.DrawElements(
|
||||||
|
DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
|
||||||
|
numVertices, elementsType, 0);
|
||||||
|
ErrorHelper.Check("DrawElements");
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DrawInstancedPrimitives (TODO)
|
||||||
public void DrawInstancedPrimitives(PrimitiveType primitiveType,
|
public void DrawInstancedPrimitives(PrimitiveType primitiveType,
|
||||||
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
|
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
|
||||||
int primitiveCount, int instanceCount)
|
int primitiveCount, int instanceCount)
|
||||||
{
|
{
|
||||||
|
//GL.DrawArraysInstanced(
|
||||||
|
// DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
|
||||||
|
// baseVertex, numVertices, instanceCount);
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DrawUserIndexedPrimitives (TODO)
|
||||||
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType,
|
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType,
|
||||||
T[] vertexData, int vertexOffset, int numVertices, Array indexData,
|
T[] vertexData, int vertexOffset, int numVertices, Array indexData,
|
||||||
int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
|
int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
|
||||||
IndexElementSize indexFormat) where T : struct, IVertexType
|
IndexElementSize indexFormat) where T : struct, IVertexType
|
||||||
{
|
{
|
||||||
|
//BeginMode mode = DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType);
|
||||||
|
|
||||||
|
//if (indexFormat == IndexElementSize.SixteenBits)
|
||||||
|
//{
|
||||||
|
// ushort[] indices = new ushort[indexData.Length];
|
||||||
|
// indexData.CopyTo(indices, 0);
|
||||||
|
// GL.DrawElements(mode, numVertices, DrawElementsType.UnsignedShort,
|
||||||
|
// indices);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// uint[] indices = new uint[indexData.Length];
|
||||||
|
// indexData.CopyTo(indices, 0);
|
||||||
|
// GL.DrawElements(mode, numVertices, DrawElementsType.UnsignedInt,
|
||||||
|
// indices);
|
||||||
|
//}
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DrawUserPrimitives (TODO)
|
||||||
public void DrawUserPrimitives<T>(PrimitiveType primitiveType,
|
public void DrawUserPrimitives<T>(PrimitiveType primitiveType,
|
||||||
T[] vertexData, int vertexOffset, int primitiveCount,
|
T[] vertexData, int vertexOffset, int primitiveCount,
|
||||||
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
|
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DrawPrimitives (TODO: check)
|
||||||
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
|
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
|
||||||
int primitiveCount)
|
int primitiveCount)
|
||||||
{
|
{
|
||||||
// TODO: DrawElementsType
|
GL.DrawArrays(
|
||||||
GL.DrawElements(DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
|
DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
|
||||||
primitiveCount, DrawElementsType.UnsignedInt, vertexOffset);
|
vertexOffset, primitiveCount);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region SetVertexBuffers
|
||||||
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
|
public void SetVertexBuffers(VertexBufferBinding[] vertexBuffers)
|
||||||
{
|
{
|
||||||
foreach (VertexBufferBinding binding in vertexBuffers)
|
boundVertexBuffers = new VertexBufferGL3[vertexBuffers.Length];
|
||||||
|
for (int index = 0; index < vertexBuffers.Length; index++)
|
||||||
{
|
{
|
||||||
INativeBuffer vertexBuffer = binding.VertexBuffer.NativeVertexBuffer;
|
System.Diagnostics.Debug.WriteLine("GL: SetVertexBuffer " + index);
|
||||||
|
boundVertexBuffers[index] =
|
||||||
|
(VertexBufferGL3)vertexBuffers[index].VertexBuffer.NativeVertexBuffer;
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer,
|
GL.BindBuffer(BufferTarget.ArrayBuffer,
|
||||||
((VertexBufferGL3)vertexBuffer).BufferHandle);
|
boundVertexBuffers[index].BufferHandle);
|
||||||
|
ErrorHelper.Check("BindBuffer");
|
||||||
|
boundVertexBuffers[index].MapVertexDeclaration(
|
||||||
|
activeEffect.programHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region SetIndexBuffer
|
||||||
public void SetIndexBuffer(IndexBuffer indexBuffer)
|
public void SetIndexBuffer(IndexBuffer indexBuffer)
|
||||||
{
|
{
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer,
|
IndexBufferGL3 nativeBuffer =
|
||||||
((IndexBufferGL3)indexBuffer.NativeIndexBuffer).BufferHandle);
|
(IndexBufferGL3)indexBuffer.NativeIndexBuffer;
|
||||||
|
|
||||||
|
if (boundIndexBuffer != nativeBuffer)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine("GL: SetIndexBuffer");
|
||||||
|
boundIndexBuffer = nativeBuffer;
|
||||||
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer,
|
||||||
|
nativeBuffer.BufferHandle);
|
||||||
|
ErrorHelper.Check("BindBuffer");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
|
|
||||||
private int indexCount;
|
private int indexCount;
|
||||||
|
|
||||||
private IndexElementSize elementSize;
|
internal IndexElementSize elementSize;
|
||||||
|
|
||||||
private BufferUsage usage;
|
private BufferUsage usage;
|
||||||
|
|
||||||
@ -97,6 +97,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
usageHint = BufferUsageHint.DynamicDraw;
|
usageHint = BufferUsageHint.DynamicDraw;
|
||||||
|
|
||||||
GL.GenBuffers(1, out bufferHandle);
|
GL.GenBuffers(1, out bufferHandle);
|
||||||
|
ErrorHelper.Check("GenBuffers");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -151,15 +152,18 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
2 : 4) * data.Length);
|
2 : 4) * data.Length);
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle);
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle);
|
||||||
|
ErrorHelper.Check("BindBuffer");
|
||||||
|
|
||||||
if (offset != 0)
|
if (offset == 0)
|
||||||
{
|
{
|
||||||
GL.BufferData(BufferTarget.ElementArrayBuffer, size, data, usageHint);
|
GL.BufferData(BufferTarget.ElementArrayBuffer, size, data, usageHint);
|
||||||
|
ErrorHelper.Check("BufferData size=" + size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GL.BufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)offset,
|
GL.BufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)offset,
|
||||||
size, data);
|
size, data);
|
||||||
|
ErrorHelper.Check("BufferSubData offset=" + offset + " size=" + size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -171,6 +175,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
GL.DeleteBuffers(1, ref bufferHandle);
|
GL.DeleteBuffers(1, ref bufferHandle);
|
||||||
|
ErrorHelper.Check("DeleteBuffers");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
CullFaceMode.Front :
|
CullFaceMode.Front :
|
||||||
CullFaceMode.Back);
|
CullFaceMode.Back);
|
||||||
}
|
}
|
||||||
|
ErrorHelper.Check("Set CullMode");
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
GL.PolygonMode(MaterialFace.FrontAndBack,
|
GL.PolygonMode(MaterialFace.FrontAndBack,
|
||||||
@ -188,6 +189,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
{
|
{
|
||||||
GL.Disable(EnableCap.ScissorTest);
|
GL.Disable(EnableCap.ScissorTest);
|
||||||
}
|
}
|
||||||
|
ErrorHelper.Check("Set ScissorTest");
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DepthBias / SlopeScaleDepthBias (TODO: test!)
|
#region DepthBias / SlopeScaleDepthBias (TODO: test!)
|
||||||
@ -206,6 +208,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
{
|
{
|
||||||
GL.Disable(EnableCap.PolygonOffsetFill);
|
GL.Disable(EnableCap.PolygonOffsetFill);
|
||||||
}
|
}
|
||||||
|
ErrorHelper.Check("Set DepthBias");
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region MultiSampleAntiAlias
|
#region MultiSampleAntiAlias
|
||||||
@ -217,6 +220,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
{
|
{
|
||||||
GL.Disable(EnableCap.Multisample);
|
GL.Disable(EnableCap.Multisample);
|
||||||
}
|
}
|
||||||
|
ErrorHelper.Check("Set Multisample");
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -110,10 +110,14 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
width = setWidth;
|
width = setWidth;
|
||||||
height = setHeight;
|
height = setHeight;
|
||||||
numberOfMipMaps = mipCount;
|
numberOfMipMaps = mipCount;
|
||||||
|
nativeFormat =
|
||||||
|
DatatypesMapping.SurfaceToPixelInternalFormat(surfaceFormat);
|
||||||
isCompressed = nativeFormat.ToString().StartsWith("Compressed");
|
isCompressed = nativeFormat.ToString().StartsWith("Compressed");
|
||||||
|
|
||||||
NativeHandle = GL.GenTexture();
|
NativeHandle = GL.GenTexture();
|
||||||
|
ErrorHelper.Check("GenTexture");
|
||||||
GL.BindTexture(TextureTarget.Texture2D, NativeHandle);
|
GL.BindTexture(TextureTarget.Texture2D, NativeHandle);
|
||||||
|
ErrorHelper.Check("BindTexture");
|
||||||
|
|
||||||
int wrapMode = (int)All.ClampToEdge;
|
int wrapMode = (int)All.ClampToEdge;
|
||||||
int filter = (int)(mipCount > 1 ? All.LinearMipmapLinear : All.Linear);
|
int filter = (int)(mipCount > 1 ? All.LinearMipmapLinear : All.Linear);
|
||||||
@ -126,9 +130,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
TextureParameterName.TextureMagFilter, filter);
|
TextureParameterName.TextureMagFilter, filter);
|
||||||
GL.TexParameter(TextureTarget.Texture2D,
|
GL.TexParameter(TextureTarget.Texture2D,
|
||||||
TextureParameterName.TextureMinFilter, filter);
|
TextureParameterName.TextureMinFilter, filter);
|
||||||
|
ErrorHelper.Check("TexParameter");
|
||||||
nativeFormat =
|
|
||||||
DatatypesMapping.SurfaceToPixelInternalFormat(surfaceFormat);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -171,12 +173,14 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
{
|
{
|
||||||
GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
|
GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
|
||||||
width, height, 0, mipmapByteSize, dataPointer);
|
width, height, 0, mipmapByteSize, dataPointer);
|
||||||
|
ErrorHelper.Check("CompressedTexImage2D Format=" + nativeFormat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
|
GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
|
||||||
width, height, 0, (PixelFormat)nativeFormat,
|
width, height, 0, (PixelFormat)nativeFormat,
|
||||||
PixelType.UnsignedByte, dataPointer);
|
PixelType.UnsignedByte, dataPointer);
|
||||||
|
ErrorHelper.Check("TexImage2D Format=" + nativeFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mipmapWidth = width;
|
int mipmapWidth = width;
|
||||||
@ -195,12 +199,14 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
GL.CompressedTexImage2D(TextureTarget.Texture2D, index,
|
GL.CompressedTexImage2D(TextureTarget.Texture2D, index,
|
||||||
nativeFormat, width, height, 0, mipmapByteSize,
|
nativeFormat, width, height, 0, mipmapByteSize,
|
||||||
dataPointer);
|
dataPointer);
|
||||||
|
ErrorHelper.Check("CompressedTexImage2D Format=" + nativeFormat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GL.TexImage2D(TextureTarget.Texture2D, index, nativeFormat,
|
GL.TexImage2D(TextureTarget.Texture2D, index, nativeFormat,
|
||||||
mipmapWidth, mipmapHeight, 0, (PixelFormat)nativeFormat,
|
mipmapWidth, mipmapHeight, 0, (PixelFormat)nativeFormat,
|
||||||
PixelType.UnsignedByte, dataPointer);
|
PixelType.UnsignedByte, dataPointer);
|
||||||
|
ErrorHelper.Check("TexImage2D Format=" + nativeFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +224,7 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
GL.DeleteTexture(NativeHandle);
|
GL.DeleteTexture(NativeHandle);
|
||||||
|
ErrorHelper.Check("DeleteTexture");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -100,9 +100,12 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
usageHint = BufferUsageHint.DynamicDraw;
|
usageHint = BufferUsageHint.DynamicDraw;
|
||||||
|
|
||||||
GL.GenBuffers(1, out bufferHandle);
|
GL.GenBuffers(1, out bufferHandle);
|
||||||
|
ErrorHelper.Check("GenBuffers");
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
|
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
|
||||||
|
ErrorHelper.Check("BindBuffer");
|
||||||
IntPtr size = (IntPtr)(vertexDeclaration.VertexStride * setVertexCount);
|
IntPtr size = (IntPtr)(vertexDeclaration.VertexStride * setVertexCount);
|
||||||
GL.BufferData(BufferTarget.ArrayBuffer, size, IntPtr.Zero, usageHint);
|
GL.BufferData(BufferTarget.ArrayBuffer, size, IntPtr.Zero, usageHint);
|
||||||
|
ErrorHelper.Check("BufferData");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -156,42 +159,62 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
IntPtr size = (IntPtr)(vertexDeclaration.VertexStride * data.Length);
|
IntPtr size = (IntPtr)(vertexDeclaration.VertexStride * data.Length);
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
|
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
|
||||||
|
ErrorHelper.Check("BindBuffer");
|
||||||
// TODO: check the handling with MapBuffer etc. (See link above)
|
|
||||||
|
|
||||||
MapVertexDeclaration();
|
|
||||||
|
|
||||||
GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)offset, size, data);
|
GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)offset, size, data);
|
||||||
|
ErrorHelper.Check("BufferSubData");
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region MapVertexDeclaration
|
#region MapVertexDeclaration
|
||||||
private void MapVertexDeclaration()
|
internal void MapVertexDeclaration(int programHandle)
|
||||||
{
|
{
|
||||||
foreach (VertexElement element in vertexDeclaration.GetVertexElements())
|
foreach (VertexElement element in vertexDeclaration.GetVertexElements())
|
||||||
{
|
{
|
||||||
int size;
|
// TODO: element.UsageIndex?
|
||||||
VertexPointerType type =
|
|
||||||
DatatypesMapping.VertexElementFormatToVertexPointerType(
|
|
||||||
element.VertexElementFormat, out size);
|
|
||||||
|
|
||||||
switch (element.VertexElementUsage)
|
switch (element.VertexElementUsage)
|
||||||
{
|
{
|
||||||
case VertexElementUsage.Position:
|
case VertexElementUsage.Position:
|
||||||
GL.EnableClientState(ArrayCap.VertexArray);
|
GL.EnableClientState(ArrayCap.VertexArray);
|
||||||
|
int loc = GL.GetAttribLocation(programHandle, "pos");
|
||||||
|
GL.EnableVertexAttribArray(loc);
|
||||||
|
GL.VertexAttribPointer(loc, 3, VertexAttribPointerType.Float,
|
||||||
|
false, vertexDeclaration.VertexStride, element.Offset);
|
||||||
|
ErrorHelper.Check();
|
||||||
break;
|
break;
|
||||||
// case VertexElementUsage.Color:
|
|
||||||
//GL.EnableClientState(ArrayCap.ColorArray);
|
|
||||||
// break;
|
|
||||||
// case VertexElementUsage.TextureCoordinate:
|
|
||||||
//GL.EnableClientState(ArrayCap.TextureCoordArray);
|
|
||||||
// break;
|
|
||||||
// TODO more
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: usage index?
|
case VertexElementUsage.Color:
|
||||||
GL.VertexPointer(size, type, vertexDeclaration.VertexStride,
|
GL.EnableClientState(ArrayCap.ColorArray);
|
||||||
element.Offset);
|
int col = GL.GetAttribLocation(programHandle, "col");
|
||||||
|
GL.EnableVertexAttribArray(col);
|
||||||
|
GL.VertexAttribPointer(col, 4, VertexAttribPointerType.Float,
|
||||||
|
false, vertexDeclaration.VertexStride, element.Offset);
|
||||||
|
ErrorHelper.Check();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VertexElementUsage.TextureCoordinate:
|
||||||
|
GL.EnableClientState(ArrayCap.TextureCoordArray);
|
||||||
|
int tex = GL.GetAttribLocation(programHandle, "tex");
|
||||||
|
GL.EnableVertexAttribArray(tex);
|
||||||
|
GL.VertexAttribPointer(tex, 2, VertexAttribPointerType.Float,
|
||||||
|
false, vertexDeclaration.VertexStride, element.Offset);
|
||||||
|
ErrorHelper.Check();
|
||||||
|
break;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
case VertexElementUsage.Binormal:
|
||||||
|
case VertexElementUsage.BlendIndices:
|
||||||
|
case VertexElementUsage.BlendWeight:
|
||||||
|
case VertexElementUsage.Depth:
|
||||||
|
case VertexElementUsage.Fog:
|
||||||
|
case VertexElementUsage.Normal:
|
||||||
|
case VertexElementUsage.PointSize:
|
||||||
|
case VertexElementUsage.Sample:
|
||||||
|
case VertexElementUsage.Tangent:
|
||||||
|
case VertexElementUsage.TessellateFactor:
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -205,5 +228,5 @@ namespace ANX.Framework.Windows.GL3
|
|||||||
GL.DeleteBuffers(1, ref bufferHandle);
|
GL.DeleteBuffers(1, ref bufferHandle);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
uniform mat4 MatrixTransform;
|
uniform mat4 MatrixTransform;
|
||||||
|
|
||||||
attribute vec4 pos;
|
attribute vec4 pos;
|
||||||
attribute vec4 col;
|
attribute vec4 col;
|
||||||
attribute vec2 tex;
|
attribute vec2 tex;
|
||||||
@ -66,9 +67,9 @@ void main(void)
|
|||||||
//
|
//
|
||||||
|
|
||||||
uniform sampler2D Texture;
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
varying vec4 diffuseColor;
|
varying vec4 diffuseColor;
|
||||||
varying vec2 diffuseTexCoord;
|
varying vec2 diffuseTexCoord;
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
gl_FragColor = texture2D(Texture, diffuseTexCoord) * diffuseColor;
|
gl_FragColor = texture2D(Texture, diffuseTexCoord) * diffuseColor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user