コード例 #1
0
ファイル: VertexBuffer.cs プロジェクト: marsat02/engenious
        public void Resize(int vertexCount, bool keepData = false)
        {
            int tempVBO = 0;

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

            ThreadingHelper.BlockOnUIThread(() =>
            {
                this.VertexCount = vertexCount;
                GL.DeleteBuffer(vbo);
                vbo = tempVBO;
                GraphicsDevice.CheckError();
            });    /*
                    * ThreadingHelper.BlockOnUIThread(() =>
                    * {
                    *
                    * }, true);*/
            if (keepData)
            {
                //TODO:
                throw new NotImplementedException();
            }
        }
コード例 #2
0
        public IndexBuffer(GraphicsDevice graphicsDevice, Type indexType, int indexCount, BufferUsageHint usage = BufferUsageHint.StaticDraw)
            : base(graphicsDevice)
        {
            elementSize = System.Runtime.InteropServices.Marshal.SizeOf(indexType);
            if (elementSize <= 8)
            {
                this.IndexElementSize = DrawElementsType.UnsignedByte;
            }
            else if (elementSize <= 16)
            {
                this.IndexElementSize = DrawElementsType.UnsignedShort;
            }
            else if (elementSize <= 32)
            {
                this.IndexElementSize = DrawElementsType.UnsignedInt;
            }
            else
            {
                throw new ArgumentException("Invalid Type(bigger than 32 bits)");
            }

            this.IndexCount  = indexCount;
            this.BufferUsage = usage;
            ThreadingHelper.BlockOnUIThread(() =>
            {
                ibo = GL.GenBuffer();
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo);
                GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(indexCount * elementSize), IntPtr.Zero, (OpenTK.Graphics.OpenGL4.BufferUsageHint)BufferUsage);
            });
            GraphicsDevice.CheckError();
            //buffer = new byte[indexCount * (int)IndexElementSize / 8];
        }
コード例 #3
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();
        }
コード例 #4
0
ファイル: VertexBuffer.cs プロジェクト: marsat02/engenious
 internal bool Bind()
 {
     if (vao == null)
     {
         return(false);
     }
     vao.Bind();
     GraphicsDevice.CheckError();
     return(true);
 }
コード例 #5
0
ファイル: VertexBuffer.cs プロジェクト: marsat02/engenious
        public void SetData <T>(T[] data) where T : struct
        {
            ThreadingHelper.BlockOnUIThread(() =>
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);

                GCHandle buffer = GCHandle.Alloc(data, GCHandleType.Pinned);
                GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr(data.Length * VertexDeclaration.VertexStride), buffer.AddrOfPinnedObject());    //TODO use bufferusage
                buffer.Free();
            });
            GraphicsDevice.CheckError();
        }
コード例 #6
0
ファイル: VertexBuffer.cs プロジェクト: marsat02/engenious
        public void SetData <T>(int offsetInBytes, T[] data, int startIndex, int elementCount, int vertexStride) where T : struct
        {
            ThreadingHelper.BlockOnUIThread(() =>
            {
                //vao.Bind();//TODO: verify
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);

                GCHandle buffer = GCHandle.Alloc(data, GCHandleType.Pinned);
                GL.BufferSubData(BufferTarget.ArrayBuffer, new IntPtr(offsetInBytes), new IntPtr(elementCount * vertexStride), buffer.AddrOfPinnedObject() + startIndex * vertexStride);

                buffer.Free();
            });
            GraphicsDevice.CheckError();
        }
コード例 #7
0
 public IndexBuffer(GraphicsDevice graphicsDevice, DrawElementsType indexElementSize, int indexCount, BufferUsageHint usage = BufferUsageHint.StaticDraw)
     : base(graphicsDevice)
 {
     this.IndexElementSize = indexElementSize;
     this.IndexCount       = indexCount;
     this.BufferUsage      = usage;
     ThreadingHelper.BlockOnUIThread(() =>
     {
         ibo = GL.GenBuffer();
         GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo);
         elementSize = (indexElementSize == DrawElementsType.UnsignedByte ? 1 : (indexElementSize == DrawElementsType.UnsignedShort ? 2 : 4));
         GL.BufferData(BufferTarget.ElementArrayBuffer, new IntPtr(indexCount * elementSize), IntPtr.Zero, (OpenTK.Graphics.OpenGL4.BufferUsageHint)BufferUsage);
     });
     GraphicsDevice.CheckError();
     //buffer = new byte[indexCount * (int)IndexElementSize / 8];
 }
コード例 #8
0
        public void SetData <T>(T[] data) where T : struct
        {
            if (data.Length == 0)
            {
                return;
            }



            ThreadingHelper.BlockOnUIThread(() =>
            {
                Bind();
                GL.BufferSubData <T>(BufferTarget.ElementArrayBuffer, IntPtr.Zero, new IntPtr(data.Length * Marshal.SizeOf(default(T))), data);   //TODO:
            });
            GraphicsDevice.CheckError();
            //Buffer.BlockCopy (data, 0, buffer, 0, data.Length);
        }
コード例 #9
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();
 }
コード例 #10
0
        public void SetData <T>(int offsetInBytes, T[] data, int startIndex, int elementCount) where T : struct //TODO: valuetype?
        {
            if (elementCount == 0 || data.Length == 0)
            {
                return;
            }



            int elSize = Marshal.SizeOf(typeof(T));

            GCHandle buffer = GCHandle.Alloc(data, GCHandleType.Pinned);

            ThreadingHelper.BlockOnUIThread(() =>
            {
                Bind();
                GL.BufferSubData(BufferTarget.ElementArrayBuffer, new IntPtr(offsetInBytes), new IntPtr(elementCount * elSize), buffer.AddrOfPinnedObject() + startIndex * elSize);    //TODO:
            });
            buffer.Free();
            GraphicsDevice.CheckError();
            //Buffer.BlockCopy (data, startIndex, buffer, offsetInBytes, elementCount);
        }
コード例 #11
0
        public void SetData <T>(T[] data, int startIndex, int elementCount) where T : struct
        {
            if (elementCount == 0 || data.Length == 0)
            {
                return;
            }


            int elSize = Marshal.SizeOf(typeof(T));

            GCHandle buffer = GCHandle.Alloc(data, GCHandleType.Pinned);

            ThreadingHelper.BlockOnUIThread(() =>
            {
                Bind();

                GL.BufferSubData(BufferTarget.ElementArrayBuffer, IntPtr.Zero, new IntPtr(elementCount * elSize), buffer.AddrOfPinnedObject() + startIndex * elSize);    //TODO:
            });
            buffer.Free();
            GraphicsDevice.CheckError();
            //GL.BufferData<T> (BufferTarget.ElementArrayBuffer, new IntPtr (elementCount * Marshal.SizeOf(T)), data[startIndex], BufferUsageHint.StaticDraw);//TODO:
            //Buffer.BlockCopy (data, startIndex, buffer, 0, elementCount);
        }
コード例 #12
0
 internal void Bind()
 {
     GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo);
     GraphicsDevice.CheckError();
 }