public void Draw() { if (updated) { UpdateBuffer(); updated = false; } GLStates.ActiveTexture(TextureUnit.Texture0); GLStates.BindTexture(TextureTarget.Texture2D, TiledTexture.TextureId); GLStates.BindBuffer(BufferTarget.ElementArrayBuffer, Quad.IBO); GLStates.UseProgram(program.ProgramId); GLStates.BindBuffer(BufferTarget.ArrayBuffer, Quad.VBO); GLStates.EnableVertexAttribArray(program.GetAttribLocation("vertex_position")); GL.VertexAttribPointer(program.GetAttribLocation("vertex_position"), 2, VertexAttribPointerType.Float, false, 0, 0); if (BackColor) { GLStates.BindBuffer(BufferTarget.ArrayBuffer, tileBO); GLStates.EnableVertexAttribArray(program.GetAttribLocation("tex_position")); GL.VertexAttribPointer(program.GetAttribLocation("tex_position"), 2, VertexAttribPointerType.Float, false, 10 * sizeof(float), 0); GL.VertexAttribDivisor(program.GetAttribLocation("tex_position"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("vx_color")); GL.VertexAttribPointer(program.GetAttribLocation("vx_color"), 4, VertexAttribPointerType.Float, false, 10 * sizeof(float), 2 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("vx_color"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("vx_back_color")); GL.VertexAttribPointer(program.GetAttribLocation("vx_back_color"), 4, VertexAttribPointerType.Float, false, 10 * sizeof(float), 6 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("vx_back_color"), 1); } else { GLStates.BindBuffer(BufferTarget.ArrayBuffer, tileBO); GLStates.EnableVertexAttribArray(program.GetAttribLocation("tex_position")); GL.VertexAttribPointer(program.GetAttribLocation("tex_position"), 2, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0); GL.VertexAttribDivisor(program.GetAttribLocation("tex_position"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("vx_color")); GL.VertexAttribPointer(program.GetAttribLocation("vx_color"), 4, VertexAttribPointerType.Float, false, 6 * sizeof(float), 2 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("vx_color"), 1); } GL.DrawElementsInstanced(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedByte, IntPtr.Zero, drawCount); }
public void Draw() { UpdateBuffer(); GLStates.Enable(EnableCap.Blend); GLStates.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GLStates.ActiveTexture(TextureUnit.Texture0); GLStates.BindTexture(TextureTarget.Texture2D, TiledTexture.TextureId); GLStates.BindBuffer(BufferTarget.ElementArrayBuffer, Quad.IBO); GLStates.UseProgram(program.ProgramId); GLStates.BindBuffer(BufferTarget.ArrayBuffer, Quad.VBO); GLStates.EnableVertexAttribArray(program.GetAttribLocation("vertex_position")); GL.VertexAttribPointer(program.GetAttribLocation("vertex_position"), 2, VertexAttribPointerType.Float, false, 0, 0); GLStates.BindBuffer(BufferTarget.ArrayBuffer, bufferObject.Id); GLStates.EnableVertexAttribArray(program.GetAttribLocation("sprite_position")); GL.VertexAttribPointer(program.GetAttribLocation("sprite_position"), 2, VertexAttribPointerType.Float, false, 13 * sizeof(float), 0); GL.VertexAttribDivisor(program.GetAttribLocation("sprite_position"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("size")); GL.VertexAttribPointer(program.GetAttribLocation("size"), 2, VertexAttribPointerType.Float, false, 13 * sizeof(float), 2 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("size"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("tex_position")); GL.VertexAttribPointer(program.GetAttribLocation("tex_position"), 2, VertexAttribPointerType.Float, false, 13 * sizeof(float), 4 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("tex_position"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("scale")); GL.VertexAttribPointer(program.GetAttribLocation("scale"), 2, VertexAttribPointerType.Float, false, 13 * sizeof(float), 6 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("scale"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("rotation")); GL.VertexAttribPointer(program.GetAttribLocation("rotation"), 1, VertexAttribPointerType.Float, false, 13 * sizeof(float), 8 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("rotation"), 1); GLStates.EnableVertexAttribArray(program.GetAttribLocation("vx_color")); GL.VertexAttribPointer(program.GetAttribLocation("vx_color"), 4, VertexAttribPointerType.Float, false, 13 * sizeof(float), 9 * sizeof(float)); GL.VertexAttribDivisor(program.GetAttribLocation("vx_color"), 1); GL.DrawElementsInstanced(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedByte, IntPtr.Zero, Sprites.Count); }