- Added the parent Vertex and IndexBuffer to the Native implementation Create methods.
- OpenGL Vertex and IndexBuffer now decide whether it's a dynamic or a static buffer.
This commit is contained in:
parent
772d4be8d3
commit
30499fac83
@ -71,8 +71,8 @@ namespace ANX.Framework.Graphics
|
||||
this.indexCount = indexCount;
|
||||
this.bufferUsage = usage;
|
||||
|
||||
base.GraphicsDevice.ResourceCreated += new EventHandler<ResourceCreatedEventArgs>(GraphicsDevice_ResourceCreated);
|
||||
base.GraphicsDevice.ResourceDestroyed += new EventHandler<ResourceDestroyedEventArgs>(GraphicsDevice_ResourceDestroyed);
|
||||
base.GraphicsDevice.ResourceCreated += GraphicsDevice_ResourceCreated;
|
||||
base.GraphicsDevice.ResourceDestroyed += GraphicsDevice_ResourceDestroyed;
|
||||
|
||||
CreateNativeBuffer();
|
||||
}
|
||||
@ -128,7 +128,8 @@ namespace ANX.Framework.Graphics
|
||||
|
||||
private void CreateNativeBuffer()
|
||||
{
|
||||
this.nativeIndexBuffer = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateIndexBuffer(GraphicsDevice, indexElementSize, indexCount, bufferUsage);
|
||||
this.nativeIndexBuffer =
|
||||
AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateIndexBuffer(GraphicsDevice, this, indexElementSize, indexCount, bufferUsage);
|
||||
}
|
||||
|
||||
public void GetData<T>(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct
|
||||
|
@ -76,8 +76,8 @@ namespace ANX.Framework.Graphics
|
||||
this.vertexDeclaration = vertexDeclaration;
|
||||
this.bufferUsage = usage;
|
||||
|
||||
base.GraphicsDevice.ResourceCreated += new EventHandler<ResourceCreatedEventArgs>(GraphicsDevice_ResourceCreated);
|
||||
base.GraphicsDevice.ResourceDestroyed += new EventHandler<ResourceDestroyedEventArgs>(GraphicsDevice_ResourceDestroyed);
|
||||
base.GraphicsDevice.ResourceCreated += GraphicsDevice_ResourceCreated;
|
||||
base.GraphicsDevice.ResourceDestroyed += GraphicsDevice_ResourceDestroyed;
|
||||
|
||||
CreateNativeBuffer();
|
||||
}
|
||||
@ -111,7 +111,8 @@ namespace ANX.Framework.Graphics
|
||||
|
||||
private void CreateNativeBuffer()
|
||||
{
|
||||
this.nativeVertexBuffer = AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateVertexBuffer(GraphicsDevice, vertexDeclaration, vertexCount, bufferUsage);
|
||||
this.nativeVertexBuffer =
|
||||
AddInSystemFactory.Instance.GetDefaultCreator<IRenderSystemCreator>().CreateVertexBuffer(GraphicsDevice, this, vertexDeclaration, vertexCount, bufferUsage);
|
||||
}
|
||||
|
||||
public BufferUsage BufferUsage
|
||||
|
@ -67,9 +67,9 @@ namespace ANX.Framework.NonXNA
|
||||
|
||||
INativeRenderTarget2D CreateRenderTarget(GraphicsDevice graphics, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage);
|
||||
|
||||
INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage);
|
||||
INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexBuffer managedBuffer, IndexElementSize size, int indexCount, BufferUsage usage);
|
||||
|
||||
INativeBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage);
|
||||
INativeBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage);
|
||||
|
||||
INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream byteCode);
|
||||
INativeEffect CreateEffect(GraphicsDevice graphics, Effect managedEffect, Stream vertexShaderByteCode, Stream pixelShaderByteCode);
|
||||
|
@ -96,14 +96,16 @@ namespace ANX.Framework.Windows.DX10
|
||||
return new GraphicsDeviceWindowsDX10(presentationParameters);
|
||||
}
|
||||
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics,
|
||||
IndexBuffer managedBuffer, IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSystemChange(
|
||||
AddInType.RenderSystem);
|
||||
return new IndexBuffer_DX10(graphics, size, indexCount, usage);
|
||||
}
|
||||
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics,
|
||||
VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSystemChange(
|
||||
AddInType.RenderSystem);
|
||||
|
@ -173,10 +173,11 @@ namespace ANX.Framework.Windows.GL3
|
||||
/// <param name="usage">The usage type of the buffer.</param>
|
||||
/// <returns>Native OpenGL index buffer.</returns>
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics,
|
||||
IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
IndexBuffer managedBuffer, IndexElementSize size, int indexCount,
|
||||
BufferUsage usage)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem);
|
||||
return new IndexBufferGL3(size, indexCount, usage);
|
||||
return new IndexBufferGL3(managedBuffer, size, indexCount, usage);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -191,11 +192,12 @@ namespace ANX.Framework.Windows.GL3
|
||||
/// <param name="usage">The usage type of the buffer.</param>
|
||||
/// <returns>Native OpenGL vertex buffer.</returns>
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics,
|
||||
VertexDeclaration vertexDeclaration, int vertexCount,
|
||||
BufferUsage usage)
|
||||
VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration,
|
||||
int vertexCount, BufferUsage usage)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem);
|
||||
return new VertexBufferGL3(vertexDeclaration, vertexCount, usage);
|
||||
return new VertexBufferGL3(managedBuffer, vertexDeclaration, vertexCount,
|
||||
usage);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -59,6 +59,8 @@ namespace ANX.Framework.Windows.GL3
|
||||
public class IndexBufferGL3 : INativeBuffer
|
||||
{
|
||||
#region Private
|
||||
private IndexBuffer managedBuffer;
|
||||
|
||||
private int bufferHandle;
|
||||
/// <summary>
|
||||
/// Native index buffer handle.
|
||||
@ -86,17 +88,17 @@ namespace ANX.Framework.Windows.GL3
|
||||
/// <summary>
|
||||
/// Create a new Index Buffer object.
|
||||
/// </summary>
|
||||
internal IndexBufferGL3(IndexElementSize setElementSize,
|
||||
int setIndexCount, BufferUsage setUsage)
|
||||
internal IndexBufferGL3(IndexBuffer setManagedBuffer,
|
||||
IndexElementSize setElementSize, int setIndexCount, BufferUsage setUsage)
|
||||
{
|
||||
GraphicsResourceManager.UpdateResource(this, true);
|
||||
|
||||
managedBuffer = setManagedBuffer;
|
||||
indexCount = setIndexCount;
|
||||
elementSize = setElementSize;
|
||||
usage = setUsage;
|
||||
|
||||
// TODO: check if dynamic buffer
|
||||
bool isDynamicBuffer = false;
|
||||
bool isDynamicBuffer = managedBuffer is DynamicIndexBuffer;
|
||||
|
||||
usageHint = isDynamicBuffer ?
|
||||
BufferUsageHint.DynamicDraw :
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.Graphics;
|
||||
using ANX.Framework.NonXNA;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using ANX.Framework.NonXNA.Development;
|
||||
|
||||
#region License
|
||||
|
||||
@ -64,6 +63,8 @@ namespace ANX.Framework.Windows.GL3
|
||||
/// Info for OGL 3.3 sampler objects (sadly not implemented in OpenTK yet):
|
||||
/// http://www.sinanc.org/blog/?p=215
|
||||
/// </summary>
|
||||
[PercentageComplete(10)]
|
||||
[TestState(TestStateAttribute.TestState.Untested)]
|
||||
public class SamplerStateGL3 : INativeSamplerState
|
||||
{
|
||||
#region Public
|
||||
@ -150,7 +151,7 @@ namespace ANX.Framework.Windows.GL3
|
||||
/// Apply the sampler state.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice">Graphics device.</param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="index">The index of which sampler should be modified.</param>
|
||||
public void Apply(GraphicsDevice graphicsDevice, int index)
|
||||
{
|
||||
IsBound = true;
|
||||
|
@ -115,6 +115,7 @@ namespace ANX.Framework.Windows.GL3
|
||||
// empty lines, spaces and tabs at beginning and end and also
|
||||
// remove comments.
|
||||
List<string> lines = new List<string>(input.Split('\n'));
|
||||
input = "";
|
||||
for (int index = lines.Count - 1; index >= 0; index--)
|
||||
{
|
||||
lines[index] = lines[index].Trim();
|
||||
@ -125,15 +126,51 @@ namespace ANX.Framework.Windows.GL3
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: add /**/ comment checking and removing.
|
||||
input = lines[index] + input;
|
||||
}
|
||||
|
||||
input = "";
|
||||
foreach (string line in lines)
|
||||
#region Multiline comment removing
|
||||
input = input.Replace("/*/*", "/* /*");
|
||||
input = input.Replace("*/*/", "*/ */");
|
||||
|
||||
int length = input.Length;
|
||||
int foundStartIndex = -1;
|
||||
int openCommentsCount = 0;
|
||||
for (int index = 0; index < length - 1; index++)
|
||||
{
|
||||
input += line + "\n";
|
||||
if (input[index] == '/' &&
|
||||
input[index + 1] == '*')
|
||||
{
|
||||
if (openCommentsCount == 0)
|
||||
{
|
||||
foundStartIndex = index;
|
||||
}
|
||||
openCommentsCount++;
|
||||
}
|
||||
|
||||
if (input[index] == '*' &&
|
||||
input[index + 1] == '/')
|
||||
{
|
||||
openCommentsCount--;
|
||||
if (openCommentsCount == 0)
|
||||
{
|
||||
int commentLength = index - foundStartIndex + 2;
|
||||
length -= commentLength;
|
||||
index = foundStartIndex - 1;
|
||||
input = input.Remove(foundStartIndex, commentLength);
|
||||
foundStartIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (openCommentsCount > 0)
|
||||
{
|
||||
throw new Exception("Unable to clean the shader code because it seems " +
|
||||
"some multiline comments interfere with each other or with the code. " +
|
||||
"Please make sure your shader code and comments are well formatted!");
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Now to some additional cleanup
|
||||
string[] minimizables =
|
||||
{
|
||||
@ -145,8 +182,6 @@ namespace ANX.Framework.Windows.GL3
|
||||
input = input.Replace(mizable, mizable.Trim());
|
||||
}
|
||||
|
||||
input = input.Replace("\n", "");
|
||||
|
||||
return input;
|
||||
}
|
||||
#endregion
|
||||
@ -306,6 +341,27 @@ namespace ANX.Framework.Windows.GL3
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestCleanCodeWithExtendedComments
|
||||
public static void TestCleanCodeWithExtendedComments()
|
||||
{
|
||||
string input =
|
||||
@"// This is a simple comment.
|
||||
|
||||
/*Hello
|
||||
im a multiline comment*/
|
||||
|
||||
/* Multiline on a single line */
|
||||
|
||||
/* And now the hardcore...a multiline comment
|
||||
/*in a multiline comment/*in another one
|
||||
*/*/
|
||||
Wow...
|
||||
*/
|
||||
";
|
||||
Console.WriteLine(CleanCode(input));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TestParseShaderCode
|
||||
public static void TestParseShaderCode()
|
||||
{
|
||||
|
@ -62,6 +62,8 @@ namespace ANX.Framework.Windows.GL3
|
||||
public class VertexBufferGL3 : INativeBuffer
|
||||
{
|
||||
#region Private
|
||||
private VertexBuffer managedBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Native vertex buffer handle.
|
||||
/// </summary>
|
||||
@ -89,17 +91,18 @@ namespace ANX.Framework.Windows.GL3
|
||||
/// <summary>
|
||||
/// Create a new Vertex Buffer object.
|
||||
/// </summary>
|
||||
internal VertexBufferGL3(VertexDeclaration setVertexDeclaration,
|
||||
int setVertexCount, BufferUsage setUsage)
|
||||
internal VertexBufferGL3(VertexBuffer setManagedBuffer,
|
||||
VertexDeclaration setVertexDeclaration, int setVertexCount,
|
||||
BufferUsage setUsage)
|
||||
{
|
||||
GraphicsResourceManager.UpdateResource(this, true);
|
||||
|
||||
managedBuffer = setManagedBuffer;
|
||||
vertexDeclaration = setVertexDeclaration;
|
||||
usage = setUsage;
|
||||
vertexCount = setVertexCount;
|
||||
|
||||
// TODO: check if dynamic buffer
|
||||
bool isDynamicBuffer = false;
|
||||
bool isDynamicBuffer = managedBuffer is DynamicVertexBuffer;
|
||||
|
||||
usageHint = isDynamicBuffer ?
|
||||
BufferUsageHint.DynamicDraw :
|
||||
@ -224,6 +227,10 @@ namespace ANX.Framework.Windows.GL3
|
||||
GL.EnableVertexAttribArray(attribute.Location);
|
||||
VertexElement element = elements[(int)attribute.Location];
|
||||
|
||||
int size = 0;
|
||||
VertexAttribPointerType type = VertexAttribPointerType.Float;
|
||||
bool normalized = false;
|
||||
|
||||
switch (element.VertexElementUsage)
|
||||
{
|
||||
case VertexElementUsage.Binormal:
|
||||
@ -232,31 +239,33 @@ namespace ANX.Framework.Windows.GL3
|
||||
case VertexElementUsage.BlendIndices:
|
||||
case VertexElementUsage.BlendWeight:
|
||||
case VertexElementUsage.Position:
|
||||
GL.VertexAttribPointer((int)attribute.Location, 3,
|
||||
VertexAttribPointerType.Float, false,
|
||||
vertexDeclaration.VertexStride, element.Offset);
|
||||
size = 3;
|
||||
break;
|
||||
|
||||
case VertexElementUsage.Color:
|
||||
GL.VertexAttribPointer((int)attribute.Location, 4,
|
||||
VertexAttribPointerType.UnsignedByte,
|
||||
true, vertexDeclaration.VertexStride, element.Offset);
|
||||
size = 4;
|
||||
type = VertexAttribPointerType.UnsignedByte;
|
||||
normalized = true;
|
||||
break;
|
||||
|
||||
case VertexElementUsage.TextureCoordinate:
|
||||
GL.VertexAttribPointer((int)attribute.Location, 2,
|
||||
VertexAttribPointerType.Float, false,
|
||||
vertexDeclaration.VertexStride, element.Offset);
|
||||
size = 2;
|
||||
break;
|
||||
|
||||
case VertexElementUsage.Fog:
|
||||
case VertexElementUsage.PointSize:
|
||||
case VertexElementUsage.TessellateFactor:
|
||||
size = 1;
|
||||
break;
|
||||
|
||||
// TODO
|
||||
case VertexElementUsage.Depth:
|
||||
case VertexElementUsage.Fog:
|
||||
case VertexElementUsage.PointSize:
|
||||
case VertexElementUsage.Sample:
|
||||
case VertexElementUsage.TessellateFactor:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
GL.VertexAttribPointer((int)attribute.Location, size, type, normalized,
|
||||
vertexDeclaration.VertexStride, element.Offset);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -97,14 +97,16 @@ namespace ANX.RenderSystem.Windows.DX11
|
||||
return new GraphicsDeviceWindowsDX11(presentationParameters);
|
||||
}
|
||||
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics,
|
||||
IndexBuffer managedBuffer, IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSystemChange(
|
||||
AddInType.RenderSystem);
|
||||
return new IndexBuffer_DX11(graphics, size, indexCount, usage);
|
||||
}
|
||||
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics,
|
||||
VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
{
|
||||
AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem);
|
||||
return new VertexBuffer_DX11(graphics, vertexDeclaration, vertexCount, usage);
|
||||
|
@ -92,12 +92,14 @@ namespace ANX.Framework.Windows.DX10
|
||||
return new GraphicsDeviceWindowsDX10(presentationParameters);
|
||||
}
|
||||
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics, IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
public INativeBuffer CreateIndexBuffer(GraphicsDevice graphics,
|
||||
IndexBuffer managedBuffer, IndexElementSize size, int indexCount, BufferUsage usage)
|
||||
{
|
||||
return new IndexBuffer_DX10(graphics, size, indexCount, usage);
|
||||
}
|
||||
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
public INativeBuffer CreateVertexBuffer(GraphicsDevice graphics,
|
||||
VertexBuffer managedBuffer, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsage usage)
|
||||
{
|
||||
return new VertexBuffer_DX10(graphics, vertexDeclaration, vertexCount, usage);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user