Пример #1
0
        public VertexBuffer(int size)
        {
            OpenGL.glGenBuffers(1, out buffer);
            OpenGL.CheckGLError();
            Bind();

            // Generates a buffer with uninitialized memory.
            OpenGL.glBufferData(OpenGL.GL_ARRAY_BUFFER,
                                new IntPtr(VertexSize * size),
                                IntPtr.Zero,
                                OpenGL.GL_DYNAMIC_DRAW);
            OpenGL.CheckGLError();

            // We need to zero all the memory. Let's generate a smallish array and copy that over the whole buffer.
            var zeroedArrayElementSize = Math.Min(size, 2048);
            var ptr = GCHandle.Alloc(new T[zeroedArrayElementSize], GCHandleType.Pinned);

            try
            {
                for (var offset = 0; offset < size; offset += zeroedArrayElementSize)
                {
                    var length = Math.Min(zeroedArrayElementSize, size - offset);
                    OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
                                           new IntPtr(VertexSize * offset),
                                           new IntPtr(VertexSize * length),
                                           ptr.AddrOfPinnedObject());
                    OpenGL.CheckGLError();
                }
            }
            finally
            {
                ptr.Free();
            }
        }
Пример #2
0
 public void SetData(IntPtr data, int start, int length)
 {
     Bind();
     OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
                            new IntPtr(VertexSize * start),
                            new IntPtr(VertexSize * length),
                            data);
     OpenGL.CheckGLError();
 }
Пример #3
0
 public override void SetData(IntPtr data, int start, int length)
 {
     //Console.WriteLine("buffer SetData2()" + buffer);
     //ActivateVAOBeforeGLDraw();
     //ActivateVertextBuffer();
     //BindOnce();
     OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
                            new IntPtr(VertexSize * start),
                            new IntPtr(VertexSize * length),
                            data);
     OpenGL.CheckGLError();
 }
Пример #4
0
        public override void SetData(T[] data, int start, int length)
        {
            //Console.WriteLine("buffer SetData() in buffer number : " + buffer);

            var ptr = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
                                       new IntPtr(VertexSize * start),
                                       new IntPtr(VertexSize * length),
                                       ptr.AddrOfPinnedObject());
            }
            finally
            {
                ptr.Free();
            }

            OpenGL.CheckGLError();
        }
Пример #5
0
        public void SetData(T[] data, int start, int length)
        {
            Bind();

            var ptr = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
                                       new IntPtr(VertexSize * start),
                                       new IntPtr(VertexSize * length),
                                       ptr.AddrOfPinnedObject());
            }
            finally
            {
                ptr.Free();
            }

            OpenGL.CheckGLError();
        }
Пример #6
0
        public VertexBuffer(int size, string ownername)
        {
                        #if DEBUG_VERTEX
            Console.WriteLine("VB created owner: " + ownername);
#endif
            this.ownername = ownername;
            GraphicsContext.VAOReserveStack += 1;             //помечаем, что резерв уменьшился.
            LocalVertexArrayIndex            = GraphicsContext.VAOReserveStack;


            BindOnceOpen();

            // Generates a buffer with uninitialized memory.
            OpenGL.glBufferData(OpenGL.GL_ARRAY_BUFFER,
                                new IntPtr(VertexSize * size),
                                IntPtr.Zero,
                                OpenGL.GL_DYNAMIC_DRAW);
            OpenGL.CheckGLError();

            // We need to zero all the memory. Let's generate a smallish array and copy that over the whole buffer.
            var zeroedArrayElementSize = Math.Min(size, 2048);
            var ptr = GCHandle.Alloc(new T[zeroedArrayElementSize], GCHandleType.Pinned);
            try
            {
                for (var offset = 0; offset < size; offset += zeroedArrayElementSize)
                {
                    var length = Math.Min(zeroedArrayElementSize, size - offset);
                    OpenGL.glBufferSubData(OpenGL.GL_ARRAY_BUFFER,
                                           new IntPtr(VertexSize * offset),
                                           new IntPtr(VertexSize * length),
                                           ptr.AddrOfPinnedObject());
                    OpenGL.CheckGLError();
                }
            }
            finally
            {
                ptr.Free();
            }
            BindOnceClose();
        }