コード例 #1
0
ファイル: VertexBuffer.cs プロジェクト: marsat02/engenious
 internal bool Bind()
 {
     if (vao == null)
     {
         return(false);
     }
     vao.Bind();
     GraphicsDevice.CheckError();
     return(true);
 }
コード例 #2
0
ファイル: VertexBuffer.cs プロジェクト: marsat02/engenious
        public VertexBuffer(GraphicsDevice graphicsDevice, Type vertexType, int vertexCount, BufferUsageHint usage = BufferUsageHint.StaticDraw)
            : this(graphicsDevice, vertexCount, usage)
        {
            IVertexType tp = Activator.CreateInstance(vertexType) as IVertexType;

            if (tp == null)
            {
                throw new ArgumentException("must be a vertexType");
            }

            this.VertexDeclaration = tp.VertexDeclaration;
            ThreadingHelper.BlockOnUIThread(() =>
            {
                vbo = GL.GenBuffer();
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertexCount * VertexDeclaration.VertexStride), IntPtr.Zero, (OpenTK.Graphics.OpenGL4.BufferUsageHint)BufferUsage);
            });
            ThreadingHelper.BlockOnUIThread(() =>
            {
                vao     = new VertexAttributes();
                vao.vbo = vbo;
                vao.Bind();
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                VertexAttributes.ApplyAttributes(vao, VertexDeclaration);

                GL.BindVertexArray(0);
            }, true);
            GraphicsDevice.CheckError();
        }
コード例 #3
0
 public static void ApplyAttributes(VertexAttributes attribs, VertexDeclaration declaration)
 {
     attribs.Bind();
     foreach (var el in declaration.VertexElements)
     {
         attribs.Add(el, declaration.VertexStride, declaration.InstanceDivisor);
     }
     GL.BindVertexArray(0);
 }
コード例 #4
0
ファイル: VertexBuffer.cs プロジェクト: marsat02/engenious
 public VertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsageHint usage = BufferUsageHint.StaticDraw)
     : this(graphicsDevice, vertexCount, usage)
 {
     this.VertexDeclaration = vertexDeclaration;
     ThreadingHelper.BlockOnUIThread(() =>
     {
         vbo = GL.GenBuffer();
         GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
         GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertexCount * VertexDeclaration.VertexStride), IntPtr.Zero, (OpenTK.Graphics.OpenGL4.BufferUsageHint)BufferUsage);
     });
     ThreadingHelper.BlockOnUIThread(() =>
     {
         vao     = new VertexAttributes();
         vao.vbo = vbo;
         vao.Bind();
         GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
         VertexAttributes.ApplyAttributes(vao, VertexDeclaration);
         GL.BindVertexArray(0);
     }, true);
     GraphicsDevice.CheckError();
 }