예제 #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();
        }
예제 #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();
            }
        }
예제 #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
        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);
            }
        }
예제 #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;
            }
        }
예제 #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();
 }