예제 #1
0
 public override void Dispose()
 {
     disposeChilderen();
     if (indexBuffer != null)
     {
         indexBuffer.Dispose();
         indexBuffer = null;
     }
     base.Dispose();
 }
예제 #2
0
 public override void Dispose()
 {
     disposeChilderen();
     if (indexBuffer != null)
     {
         indexBuffer.Dispose();
         indexBuffer = null;
     }
     base.Dispose();
 }
예제 #3
0
        /// <summary>
        /// Creates a new instance of <see cref="XNAIndexBufferImplementation"/>.
        /// </summary>
        /// <param name="renderer">The XNA renderer.</param>
        /// <param name="format">The index format.</param>
        /// <param name="indexCount">The number of indices.</param>
        /// <param name="usage">The buffer usage specifying what type of memory the buffer should be created in.</param>
        internal XNAIndexBufferImplementation(XNARenderer renderer, IndexFormat format, int indexCount, ResourceUsage usage)
            : base(format, indexCount, usage)
        {
            _renderer       = renderer;
            _graphicsDevice = renderer.GraphicsDevice;

            if (usage == ResourceUsage.Static)
            {
                _indexBuffer = new XFG.IndexBuffer(_graphicsDevice, XNAIndexFormat, indexCount, XFG.BufferUsage.None);
            }
            else
            {
                _indexBuffer = new XFG.DynamicIndexBuffer(_graphicsDevice, XNAIndexFormat, indexCount, XFG.BufferUsage.None);
            }
        }
예제 #4
0
        /// <summary>
        /// Creates a new instance of <see cref="XNAIndexBufferImplementation"/>.
        /// </summary>
        /// <param name="renderer">The XNA renderer.</param>
        /// <param name="indices">The index data</param>
        /// <param name="usage">The buffer usage specifying what type of memory the buffer should be created in.</param>
        internal XNAIndexBufferImplementation(XNARenderer renderer, DataBuffer <int> indices, ResourceUsage usage)
            : base(indices, usage)
        {
            _renderer       = renderer;
            _graphicsDevice = renderer.GraphicsDevice;

            if (usage == ResourceUsage.Static)
            {
                _indexBuffer = new XFG.IndexBuffer(_graphicsDevice, XNAIndexFormat, indices.Length, XFG.BufferUsage.None);
            }
            else
            {
                _indexBuffer = new XFG.DynamicIndexBuffer(_graphicsDevice, XNAIndexFormat, indices.Length, XFG.BufferUsage.None);
            }
            _indexBuffer.SetData <int>(indices.Buffer);
        }
예제 #5
0
		unsafe public XnaHardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, XFG.GraphicsDevice device, bool useSystemMemory, bool useShadowBuffer )
			: base( manager, type, numIndices, usage, useSystemMemory, useShadowBuffer )
		{
			_bufferType = ( type == IndexType.Size16 ) ? XFG.IndexElementSize.SixteenBits : XFG.IndexElementSize.ThirtyTwoBits;

			// create the buffer
            if (usage == BufferUsage.Dynamic || usage == BufferUsage.DynamicWriteOnly)
            {
                _xnaBuffer = new XFG.IndexBuffer(device, _bufferType, numIndices, XnaHelper.Convert(usage));
            }
            else 
                _xnaBuffer = new XFG.IndexBuffer(device, _bufferType, numIndices, XFG.BufferUsage.None);

			_bufferBytes = new byte[ sizeInBytes ];
			_bufferBytes.Initialize();
		}
예제 #6
0
        public IndexBuffer(DisposableI parent, BufferUsages bufferUsage, int[] indices)
            : base(parent, bufferUsage, indices)
        {
            try
            {
                video = parent.FindParentOrSelfWithException<Video>();

                #if SILVERLIGHT
                X.IndexElementSize elementSize = X.IndexElementSize.SixteenBits;
                #else
                X.IndexElementSize elementSize = _32BitIndices ? X.IndexElementSize.ThirtyTwoBits : X.IndexElementSize.SixteenBits;
                #endif
                indexBuffer = new X.IndexBuffer(video.Device, elementSize, indices.Length, X.BufferUsage.WriteOnly);
                Update(indices, indexCount);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
예제 #7
0
        public IndexBuffer(DisposableI parent, BufferUsages bufferUsage, int[] indices)
            : base(parent, bufferUsage, indices)
        {
            try
            {
                video = parent.FindParentOrSelfWithException <Video>();

                                #if SILVERLIGHT
                X.IndexElementSize elementSize = X.IndexElementSize.SixteenBits;
                                #else
                X.IndexElementSize elementSize = _32BitIndices ? X.IndexElementSize.ThirtyTwoBits : X.IndexElementSize.SixteenBits;
                                #endif
                indexBuffer = new X.IndexBuffer(video.Device, elementSize, indices.Length, X.BufferUsage.WriteOnly);
                Update(indices, indexCount);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
예제 #8
0
        /// <summary>
        /// Creates a new instance of <see cref="XNAIndexBufferImplementation"/>.
        /// </summary>
        /// <param name="renderer">The XNA renderer.</param>
        /// <param name="indices">The index data</param>
        /// <param name="usage">The buffer usage specifying what type of memory the buffer should be created in.</param>
        internal XNAIndexBufferImplementation(XNARenderer renderer, DataBuffer <short> indices, ResourceUsage usage)
            : base(indices, usage)
        {
            if (indices == null)
            {
                throw new ArgumentNullException("indices", "Indices cannot be null.");
            }

            _renderer       = renderer;
            _graphicsDevice = renderer.GraphicsDevice;

            if (usage == ResourceUsage.Static)
            {
                _indexBuffer = new XFG.IndexBuffer(_graphicsDevice, XNAIndexFormat, indices.Length, XFG.BufferUsage.None);
            }
            else
            {
                _indexBuffer = new XFG.DynamicIndexBuffer(_graphicsDevice, XNAIndexFormat, indices.Length, XFG.BufferUsage.None);
            }

            _indexBuffer.SetData <short>(indices.Buffer);
        }
 public BillboardResource(GraphicsDevice device)
 {
     this._VertexDeclaration = new Microsoft.Xna.Framework.Graphics.VertexDeclaration(device, BillboardResource.BillboardVertex.VertexElements);
     this._VertexBuffer = new Microsoft.Xna.Framework.Graphics.VertexBuffer(device, typeof(BillboardResource.BillboardVertex), 4, BufferUsage.WriteOnly);
     this._IndexBuffer = new Microsoft.Xna.Framework.Graphics.IndexBuffer(device, typeof(short), 6, BufferUsage.WriteOnly);
     short[] indices = new short[] { 0, 1, 2, 2, 1, 3 };
     Vector3[] positions = new Vector3[] { new Vector3(0.5f, 1f, 0f), new Vector3(-0.5f, 1f, 0f), new Vector3(0.5f, 0f, 0f), new Vector3(-0.5f, 0f, 0f) };
     Vector2[] uvs = new Vector2[] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f) };
     Vector3[] tangents = new Vector3[4];
     Vector3[] binormals = new Vector3[4];
     this.BuildTangentSpaceDataForTriangleList(indices, positions, uvs, tangents, binormals);
     BillboardResource.BillboardVertex[] verts = new BillboardResource.BillboardVertex[4];
     verts[0].Position = positions[0];
     verts[0].TextureCoordinate = uvs[0];
     verts[0].Normal = Vector3.Forward;
     verts[0].Tangent = tangents[0];
     verts[0].Binormal = binormals[0];
     verts[1].Position = positions[1];
     verts[1].TextureCoordinate = uvs[1];
     verts[1].Normal = Vector3.Forward;
     verts[1].Tangent = tangents[1];
     verts[1].Binormal = binormals[1];
     verts[2].Position = positions[2];
     verts[2].TextureCoordinate = uvs[2];
     verts[2].Normal = Vector3.Forward;
     verts[2].Tangent = tangents[2];
     verts[2].Binormal = binormals[2];
     verts[3].Position = positions[3];
     verts[3].TextureCoordinate = uvs[3];
     verts[3].Normal = Vector3.Forward;
     verts[3].Tangent = tangents[3];
     verts[3].Binormal = binormals[3];
     this._VertexBuffer.SetData<BillboardResource.BillboardVertex>(verts);
     this._IndexBuffer.SetData<short>(indices);
     this._BoundingSphere = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(positions);
 }
예제 #10
0
 private void SetIndexBuffer(IndexBuffer indexBuffer)
 {
     _indexBuffer = indexBuffer;
     GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer._bufferStore);
 }
예제 #11
0
 private void SetIndexBuffer(IndexBuffer indexBuffer)
 {
     _indexBuffer = indexBuffer;
     GL11.BindBuffer(ALL11.ElementArrayBuffer, indexBuffer._bufferStore);
 }
예제 #12
0
 private void SetIndexBuffer(IndexBuffer indexBuffer)
 {
     _indexBuffer = indexBuffer;
     // GG TODO do we need this?
     //GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer._bufferStore);
 }
예제 #13
0
파일: Model.cs 프로젝트: leha-bot/Mono.XNA
        private static ModelMeshPart[] ReadMeshParts(ContentReader input, VertexBuffer vertexBuffer, IndexBuffer indexBuffer, VertexDeclaration[] vertexDeclarations)
        {
            int length = input.ReadInt32();

            ModelMeshPart[] meshParts = new ModelMeshPart[length];
            for (int i = 0; i < length; i++)
            {
                int streamOffset   = input.ReadInt32();
                int baseVertex     = input.ReadInt32();
                int numVertices    = input.ReadInt32();
                int startIndex     = input.ReadInt32();
                int primitiveCount = input.ReadInt32();
                int index          = input.ReadInt32();
                VertexDeclaration vertexDeclaration = vertexDeclarations[index];
                object            tag = input.ReadObject <object>();
                meshParts[i] = new ModelMeshPart(streamOffset, baseVertex, numVertices, startIndex, primitiveCount, vertexBuffer, indexBuffer, vertexDeclaration, tag);
                int uniqueI = i;
                input.ReadSharedResource <Effect>(delegate(Effect effect)
                {
                    meshParts[uniqueI].Effect = effect;
                });
            }
            return(meshParts);
        }
예제 #14
0
 public static void CreateBuffers <T>(RTSRenderer renderer, T[] verts, VertexDeclaration vd, short[] inds, out VertexBuffer vb, out IndexBuffer ib, BufferUsage bu = BufferUsage.WriteOnly) where T : struct, IVertexType
 {
     vb = renderer.CreateVertexBuffer(vd, verts.Length, bu);
     vb.SetData(verts);
     ib = renderer.CreateIndexBuffer(IndexElementSize.SixteenBits, inds.Length, bu);
     ib.SetData(inds);
 }
        protected void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    if (this._VertexBuffer != null)
                        this._VertexBuffer.Dispose();
                    if (this._IndexBuffer != null)
                        this._IndexBuffer.Dispose();
                    if (this._VertexDeclaration != null)
                        this._VertexDeclaration.Dispose();

                }
                this._IndexBuffer = null;
                this._VertexBuffer = null;
                this._VertexDeclaration = null;
                this.disposed = true;
            }
        }
예제 #16
0
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
				}

				if ( _xnaBuffer != null )
				{
					_xnaBuffer.Dispose();
					_xnaBuffer = null;
				}
			}

			// If it is available, make the call to the
			// base class's Dispose(Boolean) method
			base.dispose( disposeManagedResources );
		}
예제 #17
0
 public static void CreateBuffers <T>(GraphicsDevice g, T[] verts, VertexDeclaration vd, short[] inds, out VertexBuffer vb, out IndexBuffer ib, BufferUsage bu = BufferUsage.WriteOnly) where T : struct, IVertexType
 {
     vb = new VertexBuffer(g, vd, verts.Length, bu);
     vb.SetData(verts);
     ib = new IndexBuffer(g, IndexElementSize.SixteenBits, inds.Length, bu);
     ib.SetData(inds);
 }
예제 #18
0
        internal ModelMesh(string name, ModelBone parentBone, BoundingSphere boundingSphere, VertexBuffer vertexBuffer, IndexBuffer indexBuffer, ModelMeshPart[] meshParts, object tag)
        {
            this.boundingSphere = new BoundingSphere();
            this.effects        = new ModelEffectCollection();
            this.name           = name;
            this.parentBone     = parentBone;
            this.boundingSphere = boundingSphere;
            this.vertexBuffer   = vertexBuffer;
            this.indexBuffer    = indexBuffer;
            this.meshParts      = new ModelMeshPartCollection(meshParts);
            this.tag            = tag;
            int length = meshParts.Length;

            for (int i = 0; i < length; i++)
            {
                ModelMeshPart part = meshParts[i];
                part.parent = this;
            }
        }