Esempio n. 1
0
        public unsafe IndexBufferPtr GetIndex()
        {
            if (this.indexBufferPtr != null)
            {
                return(this.indexBufferPtr);
            }

            int vertexCount = (faceCount * 2 + 2) * (this.pipeline.Count - 1);

            using (var buffer = new OneIndexBuffer <uint>(DrawMode.QuadStrip, BufferUsage.StaticDraw))
            {
                buffer.Create(vertexCount + (this.pipeline.Count - 1));
                var  array         = (uint *)buffer.Header.ToPointer();
                uint positionIndex = 0;
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (i % (faceCount * 2 + 2 + 1) == (faceCount * 2 + 2))
                    {
                        array[i] = uint.MaxValue;//分割各个圆柱体
                    }
                    else
                    {
                        array[i] = positionIndex++;
                    }
                }

                this.indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
            }

            return(this.indexBufferPtr);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        protected override void DisposeUnmanagedResources()
        {
            VertexArrayObject vao = this.vertexArrayObject;

            if (vao != null)
            {
                vao.Dispose();
            }
            VertexAttributeBufferPtr[] vbos = this.vertexAttributeBufferPtrs;
            if (vbos != null)
            {
                foreach (var item in vbos)
                {
                    item.Dispose();
                }
            }
            IndexBufferPtr indexBufferPtr = this.indexBufferPtr;

            if (indexBufferPtr != null)
            {
                indexBufferPtr.Dispose();
            }
            ShaderProgram program = this.Program;

            if (program != null)
            {
                program.Dispose();
            }
        }
        public FormIndexBufferPtrBoard(IndexBufferPtr indexBufferPtr = null)
        {
            InitializeComponent();

            if (indexBufferPtr != null)
            {
                this.SetTarget(indexBufferPtr);
            }
        }
Esempio n. 4
0
        public FormIndexBufferPtrBoard(IndexBufferPtr indexBufferPtr = null)
        {
            InitializeComponent();

            if (indexBufferPtr != null)
            {
                this.SetTarget(indexBufferPtr);
            }
        }
        public void SetTarget(IndexBufferPtr indexBufferPtr)
        {
            if (indexBufferPtr == null) { throw new ArgumentNullException(); }

            this.controller = indexBufferPtr.CreateController();

            UpdateUI(this.controller);

            this.Text = string.Format("{0}", this.controller);
        }
 public IndexBufferPtr GetIndexBufferPtr()
 {
     if (indexBufferPtr == null)
     {
         using (var buffer = new ZeroIndexBuffer(DrawMode.TriangleFan, 0, 4))
         {
             indexBufferPtr = buffer.GetBufferPtr();
         }
     }
     return(indexBufferPtr);
 }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new ZeroIndexBuffer(this.model.GetDrawModel(), 0, this.model.positions.Length))
                {
                    indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(indexBufferPtr);
        }
Esempio n. 8
0
        public IndexBufferPtr GetIndex()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new ZeroIndexBuffer(DrawMode.Points, 0, particleCount))
                {
                    indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                }
            }

            return(indexBufferPtr);
        }
Esempio n. 9
0
        public void SetTarget(IndexBufferPtr indexBufferPtr)
        {
            if (indexBufferPtr == null)
            {
                throw new ArgumentNullException();
            }

            this.controller = indexBufferPtr.CreateController();

            UpdateUI(this.controller);

            this.Text = string.Format("{0}", this.controller);
        }
Esempio n. 10
0
            public IndexBufferPtr GetIndex()
            {
                if (indexBufferPtr == null)
                {
                    using (var buffer = new ZeroIndexBuffer(
                               DrawMode.TriangleFan, 0, vertsData.Length))
                    {
                        indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                    }
                }

                return(indexBufferPtr);
            }
Esempio n. 11
0
        public IndexBufferPtr GetIndex()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new ZeroIndexBuffer(
                           DrawMode.QuadStrip, 0, positions.Length))
                {
                    indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                }
            }

            return(indexBufferPtr);
        }
Esempio n. 12
0
        public IndexBufferPtr GetIndex()
        {
            if (this.indexBufferPtr == null)
            {
                using (var buffer = new ZeroIndexBuffer(DrawMode.TriangleFan, 0, this.model.positions.Length))
                {
                    this.indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                }

                return(this.indexBufferPtr);
            }

            return(indexBufferPtr);
        }
Esempio n. 13
0
        public IndexBufferPtr GetIndex()
        {
            if (this.indexBufferPtr != null)
            {
                return(this.indexBufferPtr);
            }

            using (var buffer = new ZeroIndexBuffer(DrawMode.Points, 0, this.positions.Count))
            {
                this.indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
            }

            return(this.indexBufferPtr);
        }
Esempio n. 14
0
        /// <summary>
        /// 将此Buffer的数据上传到GPU内存,并获取在GPU上的指针。执行此方法后,此对象中的非托管内存即可释放掉,不再占用CPU内存。
        /// Uploads this buffer to GPU memory and gets its pointer.
        /// It's totally OK to free memory of unmanaged array stored in this buffer object after this method invoked.
        /// </summary>
        /// <returns></returns>
        public IndexBufferPtr GetBufferPtr()
        {
            if (bufferPtr == null)
            {
                if (glGenBuffers == null)
                {
                    glGenBuffers = OpenGL.GetDelegateFor <OpenGL.glGenBuffers>();
                    glBindBuffer = OpenGL.GetDelegateFor <OpenGL.glBindBuffer>();
                    glBufferData = OpenGL.GetDelegateFor <OpenGL.glBufferData>();
                }

                bufferPtr = Upload2GPU();
            }

            return(bufferPtr);
        }
Esempio n. 15
0
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (this.indexBufferPtr == null)
            {
                int uCount = GetUCount(interval);
                int vCount = GetVCount(interval);
                using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.LineStrip, BufferUsage.StaticDraw))
                {
                    int count = (uCount + 1) * vCount + (vCount + 1 + 1) * uCount;
                    buffer.Create(count);
                    int index = 0;
                    unsafe
                    {
                        var array = (uint *)buffer.Header.ToPointer();
                        // vertical lines.
                        for (int i = 0; i < vCount; i++)
                        {
                            for (int j = 0; j < uCount; j++)
                            {
                                array[index++] = (uint)(i + j * vCount);
                            }
                            array[index++] = uint.MaxValue;// primitive restart index.
                        }
                        // horizontal lines.
                        for (int i = 0; i < uCount; i++)
                        {
                            for (int j = 0; j < vCount; j++)
                            {
                                array[index++] = (uint)(j + i * vCount);
                            }
                            array[index++] = (uint)(0 + i * vCount);
                            array[index++] = uint.MaxValue;// primitive restart index.
                        }
                    }

                    this.indexBufferPtr = buffer.GetBufferPtr();
                }
                //using (var buffer = new ZeroIndexBuffer(
                //    DrawMode.Points, 0, uCount * vCount))
                //{
                //    indexBufferPtr = buffer.GetBufferPtr();
                //}
            }

            return(this.indexBufferPtr);
        }
Esempio n. 16
0
 public static IndexBufferPtrController CreateController(this IndexBufferPtr indexBufferPtr)
 {
     {
         var ptr = indexBufferPtr as ZeroIndexBufferPtr;
         if (ptr != null)
         {
             return(new ZeroIndexBufferPtrController(ptr));
         }
     }
     {
         var ptr = indexBufferPtr as OneIndexBufferPtr;
         if (ptr != null)
         {
             return(new OneIndexBufferPtrController(ptr));
         }
     }
     {
         throw new NotImplementedException();
     }
 }
Esempio n. 17
0
        public IndexBufferPtr GetIndexBufferPtr()
        {
            if (indexBufferPtr == null)
            {
                using (var buffer = new OneIndexBuffer(IndexElementType.UInt, DrawMode.Triangles, BufferUsage.StaticDraw))
                {
                    buffer.Create(3 * 3);
                    unsafe
                    {
                        var array = (uint *)buffer.Header.ToPointer();
                        array[0] = 0; array[1] = 1; array[2] = 3;
                        array[3] = 0; array[4] = 3; array[5] = 2;
                        array[6] = 1; array[7] = 3; array[8] = 2;
                    }

                    indexBufferPtr = buffer.GetBufferPtr();
                }
            }

            return(indexBufferPtr);
        }
Esempio n. 18
0
        private IndexBufferPtr GetIndexBufferPtr()
        {
            IndexBufferPtr ptr = null;

            using (var buffer = new OneIndexBuffer <uint>(DrawMode.QuadStrip, BufferUsage.StaticDraw))
            {
                int dimSize = this.DataSource.DimenSize;
                buffer.Create(dimSize * 2 * (Marshal.SizeOf(typeof(HalfHexahedronIndex)) / sizeof(uint)));
                unsafe
                {
                    var array = (HalfHexahedronIndex *)buffer.Header.ToPointer();
                    for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
                    {
                        array[gridIndex * 2].dot0         = (uint)(8 * gridIndex + 6);
                        array[gridIndex * 2].dot1         = (uint)(8 * gridIndex + 2);
                        array[gridIndex * 2].dot2         = (uint)(8 * gridIndex + 7);
                        array[gridIndex * 2].dot3         = (uint)(8 * gridIndex + 3);
                        array[gridIndex * 2].dot4         = (uint)(8 * gridIndex + 4);
                        array[gridIndex * 2].dot5         = (uint)(8 * gridIndex + 0);
                        array[gridIndex * 2].dot6         = (uint)(8 * gridIndex + 5);
                        array[gridIndex * 2].dot7         = (uint)(8 * gridIndex + 1);
                        array[gridIndex * 2].restartIndex = uint.MaxValue;

                        array[gridIndex * 2 + 1].dot0         = (uint)(8 * gridIndex + 3);
                        array[gridIndex * 2 + 1].dot1         = (uint)(8 * gridIndex + 0);
                        array[gridIndex * 2 + 1].dot2         = (uint)(8 * gridIndex + 2);
                        array[gridIndex * 2 + 1].dot3         = (uint)(8 * gridIndex + 1);
                        array[gridIndex * 2 + 1].dot4         = (uint)(8 * gridIndex + 6);
                        array[gridIndex * 2 + 1].dot5         = (uint)(8 * gridIndex + 5);
                        array[gridIndex * 2 + 1].dot6         = (uint)(8 * gridIndex + 7);
                        array[gridIndex * 2 + 1].dot7         = (uint)(8 * gridIndex + 4);
                        array[gridIndex * 2 + 1].restartIndex = uint.MaxValue;
                    }
                }
                ptr = buffer.GetBufferPtr() as IndexBufferPtr;
            }

            return(ptr);
        }
Esempio n. 19
0
        public IndexBufferPtr GetIndex()
        {
            if (indexBufferPtr == null)
            {
                if (model.positions.Length < byte.MaxValue)
                {
                    using (var buffer = new OneIndexBuffer <byte>(DrawMode.TriangleStrip, BufferUsage.StaticDraw))
                    {
                        buffer.Alloc(model.indexes.Length);
                        unsafe
                        {
                            var indexArray = (byte *)buffer.Header.ToPointer();
                            for (int i = 0; i < model.indexes.Length; i++)
                            {
                                if (model.indexes[i] == uint.MaxValue)
                                {
                                    indexArray[i] = byte.MaxValue;
                                }
                                else
                                {
                                    indexArray[i] = (byte)model.indexes[i];
                                }
                            }
                        }

                        indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                    }
                }
                else if (model.positions.Length < ushort.MaxValue)
                {
                    using (var buffer = new OneIndexBuffer <ushort>(DrawMode.TriangleStrip, BufferUsage.StaticDraw))
                    {
                        buffer.Alloc(model.indexes.Length);
                        unsafe
                        {
                            var indexArray = (ushort *)buffer.Header.ToPointer();
                            for (int i = 0; i < model.indexes.Length; i++)
                            {
                                if (model.indexes[i] == uint.MaxValue)
                                {
                                    indexArray[i] = ushort.MaxValue;
                                }
                                else
                                {
                                    indexArray[i] = (ushort)model.indexes[i];
                                }
                            }
                        }

                        indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                    }
                }
                else
                {
                    using (var buffer = new OneIndexBuffer <uint>(DrawMode.TriangleStrip, BufferUsage.StaticDraw))
                    {
                        buffer.Alloc(model.indexes.Length);
                        unsafe
                        {
                            var indexArray = (uint *)buffer.Header.ToPointer();
                            for (int i = 0; i < model.indexes.Length; i++)
                            {
                                indexArray[i] = model.indexes[i];
                            }
                        }

                        indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                    }
                }
            }

            return(indexBufferPtr);
        }
            public IndexBufferPtr GetIndex()
            {
                if (indexBufferPtr == null)
                {
                    using (var buffer = new ZeroIndexBuffer(
                      DrawMode.Points, 0, particleCount))
                    {
                        indexBufferPtr = buffer.GetBufferPtr() as IndexBufferPtr;
                    }
                }

                return indexBufferPtr;
            }