有没有一种方法可以使用单个缓冲区渲染未连接到教其他行的单独行的缓冲区?
目前我正在为每条线创建一个 VBO,并且我正在尝试渲染数千条线,但我认为我所做的不正确,有人可以提供解决方案,目前这是我的线渲染代码:
问候!
using OpenTK.Graphics.OpenGL;
using System;
using OpenTK;
using lolGL;
internal class Polyline : Entity
{
~Polyline()
{
EmptyBuffer();
}
public Polyline(float[] points)
{
this.vbo_size = points.Length;
GL.GenBuffers(2, this.vbo_id);
GL.BindBuffer(BufferTarget.ArrayBuffer, this.vbo_id[0]);
GL.BufferData<float>(BufferTarget.ArrayBuffer, new IntPtr(points.Length * BlittableValueType.StrideOf<float>(points)), points, BufferUsageHint.StaticDraw);
Vertices = points;
}
public override void ApplyColorMap(int[] colors)
{
GL.BindBuffer(BufferTarget.ArrayBuffer, this.vbo_id[1]);
GL.BufferData<int>(BufferTarget.ArrayBuffer, new IntPtr(colors.Length * BlittableValueType.StrideOf<int>(colors)), colors, BufferUsageHint.StaticDraw);
Colors = colors;
this.HasColor = true;
}
public override void Render(FrameEventArgs e)
{
if (!this.Visible)
return;
GL.PointSize(this.PointSize);
GL.EnableClientState(ArrayCap.VertexArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, this.vbo_id[0]);
GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, new IntPtr(0));
if (this.HasColor)
{
GL.EnableClientState(ArrayCap.ColorArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, this.vbo_id[1]);
GL.ColorPointer(4, ColorPointerType.UnsignedByte, 4, IntPtr.Zero);
}
GL.DrawArrays(BeginMode.Lines, 0, this.vbo_size);
GL.DisableClientState(ArrayCap.VertexArray);
GL.DisableClientState(ArrayCap.ColorArray);
GL.DisableClientState(ArrayCap.IndexArray);
GL.DisableClientState(ArrayCap.NormalArray);
}
public override void Dispose()
{
EmptyBuffer();
}
public override void EmptyBuffer()
{
Vertices = (float[])null;
Colors = (int[])null;
}
public override void Delete()
{
GL.DeleteBuffers(vbo_id.Length, vbo_id);
this.vbo_id = new int[2];
Dispose();
}
}