コード例 #1
0
        public VertexBuffer(Type type, int length, bool isStream = false)
        {
            TotalBuffers++;
            VBO = GL.GenBuffer();
            var usageHint = isStream ? GL.GL_STREAM_DRAW : GL.GL_STATIC_DRAW;

            streaming = isStream;
            this.type = type;
            try
            {
                vertextype = (IVertexType)Activator.CreateInstance(type);
                decl       = vertextype.GetVertexDeclaration();
            }
            catch (Exception)
            {
                throw new Exception(string.Format("{0} is not a valid IVertexType", type.FullName));
            }
            GL.GenVertexArrays(1, out VAO);
            GLBind.VertexArray(VAO);
            GL.BindBuffer(GL.GL_ARRAY_BUFFER, VBO);
            GL.BufferData(GL.GL_ARRAY_BUFFER, (IntPtr)(length * decl.Stride), IntPtr.Zero, usageHint);
            size = length;
            decl.SetPointers();
            VertexCount = length;
        }