Great! It has become much clearer.
Now I would like to clarify the simple way to achieve individual sprites drawning, with acceptable perfomance.
This is my tryout for simple triangle. It is any corect?
C#, i think it does really matter, otherwise - please say
namespace Test
{
public struct Vertex
{
public Vector2 pos;
public Color4 col;
public Vector2 tex;
public Vertex(Vector2 pos, Color4 col, Vector2 tex)
{
this.pos = pos;
this.col = col;
this.tex = tex;
}
}
class VboRenderer
{
private int VboId;
private int EboId;
private Vertex[] Vertices;
private ushort[] Indices;
public VboRenderer()
{
InitializeVBO();
}
private void InitializeVBO()
{
//Initialize vertex data and index data
//Simple triangle in ccw winding
Vertices = new Vertex[3]
{
new Vertex(new Vector2(0, 0), Color4.White, new Vector2(0, 0)),
new Vertex(new Vector2(100, 0), Color4.White, new Vector2(1, 0)),
new Vertex(new Vector2(0, 100), Color4.White, new Vector2(0, 1))
};
//Index data for what order to draw vertices
Indices = new ushort[3]
{
0, 1, 2
};
//Generate a vbo buffer
GL.GenBuffers(1, out VboId);
GL.BindBuffer(BufferTarget.ArrayBuffer, VboId);
GL.BufferData(BufferTarget.ArrayBuffer,
(IntPtr)(Vertices.Length * BlittableValueType.StrideOf(new Vertex())),
Vertices, BufferUsageHint.StaticDraw);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
//Generate a ebo buffer
GL.GenBuffers(1, out EboId);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, EboId);
GL.BufferData(BufferTarget.ElementArrayBuffer,
(IntPtr)(Indices.Length * sizeof(ushort)),
Indices, BufferUsageHint.StaticDraw);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
}
public void RenderVBO()
{
GL.PushMatrix();
GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableClientState(ArrayCap.ColorArray);
GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, VboId);
// here is the where i stuck
GL.VertexPointer( 2 , VertexPointerType.Float, BlittableValueType.StrideOf( ? ), ? ); // ??? Vertex.pos
GL.VertexPointer( ? , VertexPointerType. ? , BlittableValueType.StrideOf( ? ), ? ); // ??? Vertex.col
GL.VertexPointer( 2 , VertexPointerType.Float, BlittableValueType.StrideOf( ? ), ? ); // ??? Vertex.tex
GL.BindBuffer(BufferTarget.ElementArrayBuffer, EboId);
GL.DrawElements(PrimitiveType.Triangles, Indices.Length, DrawElementsType.UnsignedShort, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
GL.DisableClientState(ArrayCap.VertexArray);
GL.DisableClientState(ArrayCap.ColorArray);
GL.DisableClientState(ArrayCap.TextureCoordArray);
GL.PopMatrix();
}
}
}
So in RenderVBO method i need to call GL.VertexPointer to define vertices layout and i think i need to use "offset"parameter ?
How do i do this kind of defining the data with custom Vertex type, contains Vector2 and Color4 … ?
How do i find correct stride value fo Vertex ?