Inheritance: HardwareIndexBuffer
Exemplo n.º 1
0
        public HardwareIndexBuffer(HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage,
                                   bool useSystemMemory, bool useShadowBuffer)
            : base(usage, useSystemMemory, useShadowBuffer)
        {
            this.type       = type;
            this.numIndices = numIndices;
            this.Manager    = manager;
            // calc the index buffer size
            sizeInBytes = numIndices;

            if (type == IndexType.Size32)
            {
                this.indexSize = Memory.SizeOf(typeof(int));
            }
            else
            {
                this.indexSize = Memory.SizeOf(typeof(short));
            }

            sizeInBytes *= this.indexSize;

            // create a shadow buffer if required
            if (useShadowBuffer)
            {
                shadowBuffer = new DefaultHardwareIndexBuffer(this.Manager, type, numIndices, BufferUsage.Dynamic);
            }
        }
Exemplo n.º 2
0
        /// Create a hardware vertex buffer
        public override HardwareIndexBuffer CreateIndexBuffer(IndexType itype, int numIndices, BufferUsage usage,
                                                              bool useShadowBuffer)
        {
            var ib = new DefaultHardwareIndexBuffer(itype, numIndices, usage);

            return(ib);
        }
Exemplo n.º 3
0
		/// <summary>
		/// Populate with data as obtained from an IRenderable.
        /// </summary>
		/// <remarks>
		/// Will share the buffers.
		/// In case there are no index data associated with the <see cref="IRenderable"/>, i.e. <see cref="RenderOperation.useIndices"/> is false,
		/// custom software index buffer is created to provide default index data to the builder.
		/// This makes it possible for derived classes to handle the data in a convenient way.
		/// </remarks>
		public void AddObject( IRenderable obj )
		{
			if ( obj == null )
				throw new ArgumentNullException();

			RenderOperation renderOp = obj.RenderOperation;

			IndexData indexData;
			if ( renderOp.useIndices )
			{
				indexData = renderOp.indexData;
			}
			else
			{
				//Create custom index buffer
				int vertexCount = renderOp.vertexData.vertexCount;
				IndexType itype = vertexCount > UInt16.MaxValue ?
				IndexType.Size32 : IndexType.Size16;

				DefaultHardwareIndexBuffer ibuf = new DefaultHardwareIndexBuffer( itype, vertexCount, BufferUsage.Static );
				customIndexBufferList.Add( ibuf ); //to be disposed later

				indexData = new IndexData();
				indexData.indexBuffer = ibuf;
				indexData.indexCount = vertexCount;
				indexData.indexStart = 0;

				//Fill buffer with indices
				IntPtr ibuffer =
				indexData.indexBuffer.Lock( BufferLocking.Normal );
				try
				{
					unsafe
					{
						Int16* ibuf16 = (Int16*)ibuffer;
						Int32* ibuf32 = (Int32*)ibuffer;
						for ( int i = 0; i < indexData.indexCount; i++ )
						{
							if ( itype == IndexType.Size16 )
							{
								ibuf16[ i ] = (Int16)i;
							}
							else
							{
								ibuf32[ i ] = i;
							}
						}
					} //unsafe
				}
				finally
				{
					indexData.indexBuffer.Unlock();
				}
			}

			AddVertexData( renderOp.vertexData );
			AddIndexData( indexData, vertexDataList.Count - 1,
			renderOp.operationType );
		}
Exemplo n.º 4
0
		/// <summary>
		/// Populate with data as obtained from an IRenderable.
		/// </summary>
		/// <remarks>
		/// Will share the buffers.
		/// In case there are no index data associated with the <see cref="IRenderable"/>, i.e. <see cref="RenderOperation.useIndices"/> is false,
		/// custom software index buffer is created to provide default index data to the builder.
		/// This makes it possible for derived classes to handle the data in a convenient way.
		/// </remarks>
		public void AddObject( IRenderable obj )
		{
			if ( obj == null )
			{
				throw new ArgumentNullException();
			}

			var renderOp = obj.RenderOperation;

			IndexData indexData;
			if ( renderOp.useIndices )
			{
				indexData = renderOp.indexData;
			}
			else
			{
				//Create custom index buffer
				var vertexCount = renderOp.vertexData.vertexCount;
				var itype = vertexCount > UInt16.MaxValue ? IndexType.Size32 : IndexType.Size16;

				var ibuf = new DefaultHardwareIndexBuffer( itype, vertexCount, BufferUsage.Static );
				this.customIndexBufferList.Add( ibuf ); //to be disposed later

				indexData = new IndexData();
				indexData.indexBuffer = ibuf;
				indexData.indexCount = vertexCount;
				indexData.indexStart = 0;

				//Fill buffer with indices
				var ibuffer = indexData.indexBuffer.Lock( BufferLocking.Normal );
				try
				{
#if !AXIOM_SAFE_ONLY
					unsafe
#endif
					{
						var ibuf16 = ibuffer.ToShortPointer();
						var ibuf32 = ibuffer.ToIntPointer();
						for ( var i = 0; i < indexData.indexCount; i++ )
						{
							if ( itype == IndexType.Size16 )
							{
								ibuf16[ i ] = (Int16)i;
							}
							else
							{
								ibuf32[ i ] = i;
							}
						}
					} //unsafe
				}
				finally
				{
					indexData.indexBuffer.Unlock();
				}
			}

			AddVertexData( renderOp.vertexData );
			AddIndexData( indexData, this.vertexDataList.Count - 1, renderOp.operationType );
		}
Exemplo n.º 5
0
		public HardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage,
		                            bool useSystemMemory, bool useShadowBuffer )
			: base( usage, useSystemMemory, useShadowBuffer )
		{
			this.type = type;
			this.numIndices = numIndices;
			this.Manager = manager;
			// calc the index buffer size
			sizeInBytes = numIndices;

			if ( type == IndexType.Size32 )
			{
				this.indexSize = Memory.SizeOf( typeof ( int ) );
			}
			else
			{
				this.indexSize = Memory.SizeOf( typeof ( short ) );
			}

			sizeInBytes *= this.indexSize;

			// create a shadow buffer if required
			if ( useShadowBuffer )
			{
				shadowBuffer = new DefaultHardwareIndexBuffer( this.Manager, type, numIndices, BufferUsage.Dynamic );
			}
		}
Exemplo n.º 6
0
        /// <summary>
        /// Populate with data as obtained from an IRenderable.
        /// </summary>
        /// <remarks>
        /// Will share the buffers.
        /// In case there are no index data associated with the <see cref="IRenderable"/>, i.e. <see cref="RenderOperation.useIndices"/> is false,
        /// custom software index buffer is created to provide default index data to the builder.
        /// This makes it possible for derived classes to handle the data in a convenient way.
        /// </remarks>
        public void AddObject(IRenderable obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException();
            }

            var renderOp = obj.RenderOperation;

            IndexData indexData;

            if (renderOp.useIndices)
            {
                indexData = renderOp.indexData;
            }
            else
            {
                //Create custom index buffer
                var vertexCount = renderOp.vertexData.vertexCount;
                var itype       = vertexCount > UInt16.MaxValue ? IndexType.Size32 : IndexType.Size16;

                var ibuf = new DefaultHardwareIndexBuffer(itype, vertexCount, BufferUsage.Static);
                this.customIndexBufferList.Add(ibuf); //to be disposed later

                indexData             = new IndexData();
                indexData.indexBuffer = ibuf;
                indexData.indexCount  = vertexCount;
                indexData.indexStart  = 0;

                //Fill buffer with indices
                var ibuffer = indexData.indexBuffer.Lock(BufferLocking.Normal);
                try
                {
#if !AXIOM_SAFE_ONLY
                    unsafe
#endif
                    {
                        var ibuf16 = ibuffer.ToShortPointer();
                        var ibuf32 = ibuffer.ToIntPointer();
                        for (var i = 0; i < indexData.indexCount; i++)
                        {
                            if (itype == IndexType.Size16)
                            {
                                ibuf16[i] = (Int16)i;
                            }
                            else
                            {
                                ibuf32[i] = i;
                            }
                        }
                    } //unsafe
                }
                finally
                {
                    indexData.indexBuffer.Unlock();
                }
            }

            AddVertexData(renderOp.vertexData);
            AddIndexData(indexData, this.vertexDataList.Count - 1, renderOp.operationType);
        }
		/// Create a hardware vertex buffer
		public override HardwareIndexBuffer CreateIndexBuffer( IndexType itype, int numIndices, BufferUsage usage, bool useShadowBuffer )
		{
			DefaultHardwareIndexBuffer ib = new DefaultHardwareIndexBuffer( itype, numIndices, usage );
			return ib;
		}