/// <summary> /// Upload the Vertices into Buffer Data. /// </summary> public void Update(Vertex[] vertices) { // Assign vertices information _vertices = vertices; _length = vertices.Length; // Pin the vertices, prevent GC wipe this pointer using (var memory = new MemoryLock(_vertices)) { var pointer = memory.Address; // Calculate the stride and upload the vertices var stride = Vertex.Stride; GL.VertexPointer(2, VertexPointerType.Float, stride, pointer.Increment(0)); GLChecker.CheckError(); GL.TexCoordPointer(2, TexCoordPointerType.Float, stride, pointer.Increment(8)); GLChecker.CheckError(); GL.ColorPointer(4, ColorPointerType.UnsignedByte, stride, pointer.Increment(16)); GLChecker.CheckError(); } }
/// <summary> /// Render the vertices using current implementation. /// </summary> public void Render(PrimitiveType type) { // Notes: // GL.GetError() cannot be called upon render the immediate mode implementation. // There is no way to check automatically whether our data is valid or not. // Just make sure the specified colors, texcoords and positions are valid and correct. // Check the error before begin(?) GLChecker.CheckError(); // Specify primitive mode. GL.Begin((OpenTK.Graphics.OpenGL.PrimitiveType)((int)type)); // Set the Color, Texture Coordinate and Positions. for (int i = 0; i < _vertices.Length; i++) { // Color. GL.Color4(_vertices[i].Color.R, _vertices[i].Color.G, _vertices[i].Color.B, _vertices[i].Color.A); // TexCoord. GL.TexCoord2(_vertices[i].TexCoords.X, _vertices[i].TexCoords.Y); // Position. GL.Vertex2(_vertices[i].Position.X, _vertices[i].TexCoords.Y); } // Finished. GL.End(); // Check error again(?) GLChecker.CheckError(); }