Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public void Resize(int vertexCount, bool keepData = false)
        {
            int tempVBO = 0;

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

            ThreadingHelper.BlockOnUIThread(() =>
            {
                VertexAttributes.ApplyAttributes(vao, VertexDeclaration);
                GL.BindVertexArray(0);
                this.VertexCount = vertexCount;
                GL.DeleteBuffer(vbo);
                vbo = tempVBO;
            }, true, this);    /*
                                * ThreadingHelper.BlockOnUIThread(() =>
                                * {
                                *
                                * }, true);*/
            if (keepData)
            {
                //TODO:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 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);
 }
Exemplo n.º 4
0
        internal void EnsureVAO()
        {
            if (vao != null && vao.vbo != vbo)
            {
                vao.vbo = vbo;
                vao.Bind();
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                VertexAttributes.ApplyAttributes(vao, VertexDeclaration);

                GL.BindVertexArray(0);
            }
        }
Exemplo n.º 5
0
        internal void EnsureVAO()
        {
            if (vao != null && vao.vbo != vbo)
            {
                vao.vbo = vbo;
                vao.Bind();
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
                VertexAttributes.ApplyAttributes(vao, VertexDeclaration);

                GL.BindVertexArray(0);

                if (tempVBO == -1)
                {
                    return;
                }
                GL.DeleteBuffer(tempVBO);
                tempVBO = -1;
            }
        }
Exemplo n.º 6
0
 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();
 }