diff --git a/RenderSystems/ANX.Framework.Windows.GL3/ANX.Framework.Windows.GL3.csproj b/RenderSystems/ANX.Framework.Windows.GL3/ANX.Framework.Windows.GL3.csproj
index 39b88990..4dcff9fd 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/ANX.Framework.Windows.GL3.csproj
+++ b/RenderSystems/ANX.Framework.Windows.GL3/ANX.Framework.Windows.GL3.csproj
@@ -22,6 +22,7 @@
prompt
4
x86
+ Auto
pdbonly
@@ -30,6 +31,7 @@
TRACE
prompt
4
+ x86
@@ -47,6 +49,7 @@
+
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/DatatypesMapping.cs b/RenderSystems/ANX.Framework.Windows.GL3/DatatypesMapping.cs
index 35e98d5c..311e6b14 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/DatatypesMapping.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/DatatypesMapping.cs
@@ -260,72 +260,6 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
- #region VertexElementFormatToVertexPointerType (TODO)
- ///
- /// Translate the XNA VertexElementFormat to an OpenGL VertexPointerType.
- ///
- /// XNA VertexElementFormat.
- /// Returns the size of the vertex element.
- /// Translated VertexPointerType for OpenGL.
- 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
private class Tests
{
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/EffectGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/EffectGL3.cs
index 83d8e301..2831ab50 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/EffectGL3.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/EffectGL3.cs
@@ -71,7 +71,7 @@ namespace ANX.Framework.Windows.GL3
///
/// The native shader handle.
///
- private int programHandle;
+ internal int programHandle;
#endregion
#region Public
@@ -305,8 +305,13 @@ namespace ANX.Framework.Windows.GL3
#region Apply (TODO)
public void Apply(GraphicsDevice graphicsDevice)
{
- GL.Enable(EnableCap.Texture2D);
- GL.UseProgram(programHandle);
+ if (GraphicsDeviceWindowsGL3.activeEffect != this)
+ {
+ System.Diagnostics.Debug.WriteLine("GL: Shader.Apply");
+ GL.UseProgram(programHandle);
+ GraphicsDeviceWindowsGL3.activeEffect = this;
+ ErrorHelper.Check("UseProgram");
+ }
}
#endregion
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs
index 5408dadb..4623dcf9 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/EffectParameterGL3.cs
@@ -101,22 +101,40 @@ namespace ANX.Framework.Windows.GL3
/// Value for the parameter
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;
///
/// Set a texture value to the effect parameter.
///
/// Value for the parameter
public void SetValue(Texture value)
{
- // TODO: multiple texture units
- TextureUnit textureUnit = TextureUnit.Texture0;
- GL.ActiveTexture(textureUnit);
- int handle = (value.NativeTexture as Texture2DGL3).NativeHandle;
- GL.BindTexture(TextureTarget.Texture2D, handle);
- int unitIndex = (int)(textureUnit - TextureUnit.Texture0);
- GL.Uniform1(UniformIndex, 1, ref unitIndex);
+ GL.UseProgram(parentEffect.programHandle);
+ if (textureCache == null ||
+ textureCache != value)
+ {
+ // TODO: multiple texture units
+ TextureUnit textureUnit = TextureUnit.Texture0;
+ 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
}
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/ErrorHelper.cs b/RenderSystems/ANX.Framework.Windows.GL3/ErrorHelper.cs
new file mode 100644
index 00000000..dcadccd6
--- /dev/null
+++ b/RenderSystems/ANX.Framework.Windows.GL3/ErrorHelper.cs
@@ -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);
+ }
+ }
+ }
+}
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs
index 729a60a5..782fa909 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/GraphicsDeviceWindowsGL3.cs
@@ -74,6 +74,11 @@ namespace ANX.Framework.Windows.GL3
/// to the graphics device.
///
private IWindowInfo nativeWindowInfo;
+
+ internal static VertexBufferGL3[] boundVertexBuffers =
+ new VertexBufferGL3[0];
+ internal static IndexBufferGL3 boundIndexBuffer;
+ internal static EffectGL3 activeEffect;
#endregion
#region Constructor
@@ -158,6 +163,7 @@ namespace ANX.Framework.Windows.GL3
public void SetViewport(Viewport viewport)
{
GL.Viewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);
+ ErrorHelper.Check("SetViewport");
}
#endregion
@@ -177,6 +183,7 @@ namespace ANX.Framework.Windows.GL3
color.B * ColorMultiplier, color.A * ColorMultiplier);
}
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
+ ErrorHelper.Check("Clear");
}
///
@@ -217,6 +224,7 @@ namespace ANX.Framework.Windows.GL3
GL.ClearDepth(depth);
GL.ClearStencil(stencil);
GL.Clear(mask);
+ ErrorHelper.Check("Clear");
}
#endregion
@@ -234,60 +242,117 @@ namespace ANX.Framework.Windows.GL3
}
#endregion
+ #region DrawIndexedPrimitives
public void DrawIndexedPrimitives(PrimitiveType primitiveType,
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
int primitiveCount)
{
- // TODO: DrawElementsType, baseVertex, minVertexIndex, numVertices, startIndex
- GL.DrawElements(DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
- numVertices, DrawElementsType.UnsignedShort, 0);
- }
+ System.Diagnostics.Debug.WriteLine("GL: DrawIndexedPrimitives");
+ // TODO: baseVertex, minVertexIndex, numVertices, startIndex, primitiveCount
+ 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,
int baseVertex, int minVertexIndex, int numVertices, int startIndex,
int primitiveCount, int instanceCount)
{
+ //GL.DrawArraysInstanced(
+ // DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
+ // baseVertex, numVertices, instanceCount);
throw new NotImplementedException();
}
+ #endregion
+ #region DrawUserIndexedPrimitives (TODO)
public void DrawUserIndexedPrimitives(PrimitiveType primitiveType,
- T[] vertexData, int vertexOffset, int numVertices, Array indexData,
- int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
- IndexElementSize indexFormat) where T : struct, IVertexType
+ T[] vertexData, int vertexOffset, int numVertices, Array indexData,
+ int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration,
+ 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();
}
+ #endregion
+ #region DrawUserPrimitives (TODO)
public void DrawUserPrimitives(PrimitiveType primitiveType,
T[] vertexData, int vertexOffset, int primitiveCount,
VertexDeclaration vertexDeclaration) where T : struct, IVertexType
{
throw new NotImplementedException();
}
+ #endregion
+ #region DrawPrimitives (TODO: check)
public void DrawPrimitives(PrimitiveType primitiveType, int vertexOffset,
int primitiveCount)
{
- // TODO: DrawElementsType
- GL.DrawElements(DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
- primitiveCount, DrawElementsType.UnsignedInt, vertexOffset);
+ GL.DrawArrays(
+ DatatypesMapping.PrimitiveTypeToBeginMode(primitiveType),
+ vertexOffset, primitiveCount);
}
+ #endregion
+ #region SetVertexBuffers
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,
- ((VertexBufferGL3)vertexBuffer).BufferHandle);
+ boundVertexBuffers[index].BufferHandle);
+ ErrorHelper.Check("BindBuffer");
+ boundVertexBuffers[index].MapVertexDeclaration(
+ activeEffect.programHandle);
}
}
+ #endregion
+ #region SetIndexBuffer
public void SetIndexBuffer(IndexBuffer indexBuffer)
{
- GL.BindBuffer(BufferTarget.ElementArrayBuffer,
- ((IndexBufferGL3)indexBuffer.NativeIndexBuffer).BufferHandle);
+ IndexBufferGL3 nativeBuffer =
+ (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)
{
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/IndexBufferGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/IndexBufferGL3.cs
index 539ba618..37c154bd 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/IndexBufferGL3.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/IndexBufferGL3.cs
@@ -72,7 +72,7 @@ namespace ANX.Framework.Windows.GL3
private int indexCount;
- private IndexElementSize elementSize;
+ internal IndexElementSize elementSize;
private BufferUsage usage;
@@ -97,6 +97,7 @@ namespace ANX.Framework.Windows.GL3
usageHint = BufferUsageHint.DynamicDraw;
GL.GenBuffers(1, out bufferHandle);
+ ErrorHelper.Check("GenBuffers");
}
#endregion
@@ -151,15 +152,18 @@ namespace ANX.Framework.Windows.GL3
2 : 4) * data.Length);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, bufferHandle);
+ ErrorHelper.Check("BindBuffer");
- if (offset != 0)
+ if (offset == 0)
{
GL.BufferData(BufferTarget.ElementArrayBuffer, size, data, usageHint);
+ ErrorHelper.Check("BufferData size=" + size);
}
else
{
GL.BufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)offset,
size, data);
+ ErrorHelper.Check("BufferSubData offset=" + offset + " size=" + size);
}
}
#endregion
@@ -171,6 +175,7 @@ namespace ANX.Framework.Windows.GL3
public void Dispose()
{
GL.DeleteBuffers(1, ref bufferHandle);
+ ErrorHelper.Check("DeleteBuffers");
}
#endregion
}
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/RasterizerStateGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/RasterizerStateGL3.cs
index e2fcbcf6..a9af59f7 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/RasterizerStateGL3.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/RasterizerStateGL3.cs
@@ -174,6 +174,7 @@ namespace ANX.Framework.Windows.GL3
CullFaceMode.Front :
CullFaceMode.Back);
}
+ ErrorHelper.Check("Set CullMode");
#endregion
GL.PolygonMode(MaterialFace.FrontAndBack,
@@ -188,6 +189,7 @@ namespace ANX.Framework.Windows.GL3
{
GL.Disable(EnableCap.ScissorTest);
}
+ ErrorHelper.Check("Set ScissorTest");
#endregion
#region DepthBias / SlopeScaleDepthBias (TODO: test!)
@@ -206,6 +208,7 @@ namespace ANX.Framework.Windows.GL3
{
GL.Disable(EnableCap.PolygonOffsetFill);
}
+ ErrorHelper.Check("Set DepthBias");
#endregion
#region MultiSampleAntiAlias
@@ -217,6 +220,7 @@ namespace ANX.Framework.Windows.GL3
{
GL.Disable(EnableCap.Multisample);
}
+ ErrorHelper.Check("Set Multisample");
#endregion
}
#endregion
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/Texture2DGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/Texture2DGL3.cs
index 07eb9cd4..cbce9cd1 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/Texture2DGL3.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/Texture2DGL3.cs
@@ -110,10 +110,14 @@ namespace ANX.Framework.Windows.GL3
width = setWidth;
height = setHeight;
numberOfMipMaps = mipCount;
+ nativeFormat =
+ DatatypesMapping.SurfaceToPixelInternalFormat(surfaceFormat);
isCompressed = nativeFormat.ToString().StartsWith("Compressed");
NativeHandle = GL.GenTexture();
+ ErrorHelper.Check("GenTexture");
GL.BindTexture(TextureTarget.Texture2D, NativeHandle);
+ ErrorHelper.Check("BindTexture");
int wrapMode = (int)All.ClampToEdge;
int filter = (int)(mipCount > 1 ? All.LinearMipmapLinear : All.Linear);
@@ -126,9 +130,7 @@ namespace ANX.Framework.Windows.GL3
TextureParameterName.TextureMagFilter, filter);
GL.TexParameter(TextureTarget.Texture2D,
TextureParameterName.TextureMinFilter, filter);
-
- nativeFormat =
- DatatypesMapping.SurfaceToPixelInternalFormat(surfaceFormat);
+ ErrorHelper.Check("TexParameter");
}
#endregion
@@ -171,12 +173,14 @@ namespace ANX.Framework.Windows.GL3
{
GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
width, height, 0, mipmapByteSize, dataPointer);
+ ErrorHelper.Check("CompressedTexImage2D Format=" + nativeFormat);
}
else
{
GL.TexImage2D(TextureTarget.Texture2D, 0, nativeFormat,
width, height, 0, (PixelFormat)nativeFormat,
PixelType.UnsignedByte, dataPointer);
+ ErrorHelper.Check("TexImage2D Format=" + nativeFormat);
}
int mipmapWidth = width;
@@ -195,12 +199,14 @@ namespace ANX.Framework.Windows.GL3
GL.CompressedTexImage2D(TextureTarget.Texture2D, index,
nativeFormat, width, height, 0, mipmapByteSize,
dataPointer);
+ ErrorHelper.Check("CompressedTexImage2D Format=" + nativeFormat);
}
else
{
GL.TexImage2D(TextureTarget.Texture2D, index, nativeFormat,
mipmapWidth, mipmapHeight, 0, (PixelFormat)nativeFormat,
PixelType.UnsignedByte, dataPointer);
+ ErrorHelper.Check("TexImage2D Format=" + nativeFormat);
}
}
}
@@ -218,6 +224,7 @@ namespace ANX.Framework.Windows.GL3
public void Dispose()
{
GL.DeleteTexture(NativeHandle);
+ ErrorHelper.Check("DeleteTexture");
}
#endregion
}
diff --git a/RenderSystems/ANX.Framework.Windows.GL3/VertexBufferGL3.cs b/RenderSystems/ANX.Framework.Windows.GL3/VertexBufferGL3.cs
index f4062b78..2b1dccf2 100644
--- a/RenderSystems/ANX.Framework.Windows.GL3/VertexBufferGL3.cs
+++ b/RenderSystems/ANX.Framework.Windows.GL3/VertexBufferGL3.cs
@@ -100,9 +100,12 @@ namespace ANX.Framework.Windows.GL3
usageHint = BufferUsageHint.DynamicDraw;
GL.GenBuffers(1, out bufferHandle);
+ ErrorHelper.Check("GenBuffers");
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
+ ErrorHelper.Check("BindBuffer");
IntPtr size = (IntPtr)(vertexDeclaration.VertexStride * setVertexCount);
GL.BufferData(BufferTarget.ArrayBuffer, size, IntPtr.Zero, usageHint);
+ ErrorHelper.Check("BufferData");
}
#endregion
@@ -156,42 +159,62 @@ namespace ANX.Framework.Windows.GL3
IntPtr size = (IntPtr)(vertexDeclaration.VertexStride * data.Length);
GL.BindBuffer(BufferTarget.ArrayBuffer, bufferHandle);
-
- // TODO: check the handling with MapBuffer etc. (See link above)
-
- MapVertexDeclaration();
+ ErrorHelper.Check("BindBuffer");
GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)offset, size, data);
+ ErrorHelper.Check("BufferSubData");
}
#endregion
#region MapVertexDeclaration
- private void MapVertexDeclaration()
+ internal void MapVertexDeclaration(int programHandle)
{
foreach (VertexElement element in vertexDeclaration.GetVertexElements())
{
- int size;
- VertexPointerType type =
- DatatypesMapping.VertexElementFormatToVertexPointerType(
- element.VertexElementFormat, out size);
+ // TODO: element.UsageIndex?
switch (element.VertexElementUsage)
{
case VertexElementUsage.Position:
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;
- // case VertexElementUsage.Color:
- //GL.EnableClientState(ArrayCap.ColorArray);
- // break;
- // case VertexElementUsage.TextureCoordinate:
- //GL.EnableClientState(ArrayCap.TextureCoordArray);
- // break;
- // TODO more
- }
- // TODO: usage index?
- GL.VertexPointer(size, type, vertexDeclaration.VertexStride,
- element.Offset);
+ case VertexElementUsage.Color:
+ GL.EnableClientState(ArrayCap.ColorArray);
+ 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
@@ -205,5 +228,5 @@ namespace ANX.Framework.Windows.GL3
GL.DeleteBuffers(1, ref bufferHandle);
}
#endregion
- }
+ }
}
diff --git a/shader/GL3/SpriteBatch_GLSL.fx b/shader/GL3/SpriteBatch_GLSL.fx
index 727d1e9f..d5f51b0c 100644
--- a/shader/GL3/SpriteBatch_GLSL.fx
+++ b/shader/GL3/SpriteBatch_GLSL.fx
@@ -46,6 +46,7 @@
//
uniform mat4 MatrixTransform;
+
attribute vec4 pos;
attribute vec4 col;
attribute vec2 tex;
@@ -66,9 +67,9 @@ void main(void)
//
uniform sampler2D Texture;
+
varying vec4 diffuseColor;
varying vec2 diffuseTexCoord;
-
void main(void)
{
gl_FragColor = texture2D(Texture, diffuseTexCoord) * diffuseColor;