Beispiel #1
0
 public override void Dispose()
 {
     disposeChilderen();
     if (vertexBuffer != null)
     {
         vertexBuffer.Dispose();
         vertexBuffer = null;
     }
     base.Dispose();
 }
Beispiel #2
0
 public override void Dispose()
 {
     disposeChilderen();
     if (vertexBuffer != null)
     {
         vertexBuffer.Dispose();
         vertexBuffer = null;
     }
     base.Dispose();
 }
		public XnaHardwareVertexBuffer( HardwareBufferManagerBase manager, VertexDeclaration vertexDeclaration, int numVertices, BufferUsage usage, XFG.GraphicsDevice dev, bool useSystemMemory, bool useShadowBuffer )
            : base( manager, vertexDeclaration, numVertices, usage, useSystemMemory, useShadowBuffer )
		{
			_device = dev;
            if ( !( vertexDeclaration is XnaVertexDeclaration ) )
            {
                throw new AxiomException ("Invalid VertexDeclaration supplied, must be created by HardwareBufferManager.CreateVertexDeclaration()" );
            }
            if (usage == BufferUsage.Dynamic || usage == BufferUsage.DynamicWriteOnly)
            {
                _buffer = new XFG.DynamicVertexBuffer(_device, ( (XnaVertexDeclaration)vertexDeclaration ).XFGVertexDeclaration , numVertices, XnaHelper.Convert(usage));
            }
            else
                _buffer = new XFG.VertexBuffer(_device, ( (XnaVertexDeclaration)vertexDeclaration ).XFGVertexDeclaration, numVertices, XnaHelper.Convert(usage));

            _bufferBytes = new byte[ vertexDeclaration.GetVertexSize() * numVertices];
			_bufferBytes.Initialize();
		}
        /// <summary>
        /// Creates a new instance of <see cref="XNAVertexBufferImplementation"/>.
        /// </summary>
        /// <param name="renderer">The XNA renderer.</param>
        /// <param name="decl">The vertex declaration.</param>
        /// <param name="vertexCount">The vertex count.</param>
        /// <param name="usage">The resource usage.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if there was an error creating the XNA buffer</exception>
        internal XNAVertexBufferImplementation(XNARenderer renderer, VertexDeclaration decl, int vertexCount, ResourceUsage usage)
            : base(decl, vertexCount, usage)
        {
            _renderer       = renderer;
            _graphicsDevice = renderer.GraphicsDevice;

            try {
                XFG.VertexDeclaration xnaDecl = XNAHelper.ToXNAVertexDeclaration(decl);
                if (usage == ResourceUsage.Static)
                {
                    _vertexBuffer = new XFG.VertexBuffer(_graphicsDevice, xnaDecl, vertexCount, XFG.BufferUsage.None);
                }
                else
                {
                    _vertexBuffer = new XFG.DynamicVertexBuffer(_graphicsDevice, xnaDecl, vertexCount, XFG.BufferUsage.None);
                }
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating XNA buffer: \n" + e.Message, e);
            }
        }
Beispiel #5
0
        private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc, BufferUsages bufferUsage, VertexBufferTopologys vertexBufferTopology, float[] vertices, int[] indices)
        {
            try
            {
                video        = parent.FindParentOrSelfWithException <Video>();
                Topology     = vertexBufferTopology;
                bufferLayout = new BufferLayout(this, null, bufferLayoutDesc, true);

                vertexBuffer = new X.VertexBuffer(video.Device, bufferLayout.layout, vertexCount, X.BufferUsage.WriteOnly);
                Update(vertices, vertexCount);

                if (indices != null && indices.Length != 0)
                {
                    indexBuffer = new IndexBuffer(this, usage, indices);
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
 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);
 }
 public VertexBufferBinding(VertexBuffer vertexBuffer, int vertexOffset, int instanceFrequency)
 {
     this.InstanceFrequency = 0;
     this.VertexOffset      = 0;
     this.VertexBuffer      = default(VertexBuffer);
 }
 public unsafe void SetVertexBuffer(VertexBuffer vertexBuffer)
 {
 }
Beispiel #9
0
 public StaticVertexBuffer(XnaVertexBuffer vb)
 {
     vb = XnaBuffer;
 }
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
				}

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

			// If it is available, make the call to the
			// base class's Dispose(Boolean) method
			base.dispose( disposeManagedResources );
		}
Beispiel #11
0
 public void SetVertexBuffer(VertexBuffer vertexBuffer)
 {
     _vertexBuffer = vertexBuffer;
     GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer._bufferStore);
 }
Beispiel #12
0
 public void SetVertexBuffer(VertexBuffer vertexBuffer)
 {
     _vertexBuffer = vertexBuffer;
     GL11.BindBuffer(ALL11.ArrayBuffer, vertexBuffer._bufferStore);
 }
Beispiel #13
0
        private void init(DisposableI parent, BufferLayoutDescI bufferLayoutDesc, BufferUsages bufferUsage, VertexBufferTopologys vertexBufferTopology, float[] vertices, int[] indices)
        {
            try
            {
                video = parent.FindParentOrSelfWithException<Video>();
                Topology = vertexBufferTopology;
                bufferLayout = new BufferLayout(this, null, bufferLayoutDesc, true);

                vertexBuffer = new X.VertexBuffer(video.Device, bufferLayout.layout, vertexCount, X.BufferUsage.WriteOnly);
                Update(vertices, vertexCount);

                if (indices != null && indices.Length != 0) indexBuffer = new IndexBuffer(this, usage, indices);
            }
            catch (Exception e)
            {
                Dispose();
                throw e;
            }
        }
Beispiel #14
0
 public void SetVertexBuffer(VertexBuffer vertexBuffer)
 {
     _vertexBuffersDirty |= (vertexBuffer == null)
                            ? _vertexBuffers.Clear()
                            : _vertexBuffers.Set(vertexBuffer, 0);
 }
        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;
            }
        }
Beispiel #16
0
 public Cheetah.VertexBuffer CreateStaticVertexBuffer(object data, int length)
 {
     XnaVertexBuffer vb = new XnaVertexBuffer(Device, length, ResourceUsage.None, ResourcePool.Managed);
     return new StaticVertexBuffer(vb);
 }
 public void SetVertexBuffer(VertexBuffer vertexBuffer)
 {
     _vertexBuffer = vertexBuffer;
     // GG TODO do we need this?
     //GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer._bufferStore);
 }
Beispiel #18
0
 public void SetSource(VertexBuffer vb, int offsetInBytes, int vertexStride)
 {
     throw new NotImplementedException();
 }
 public VertexBufferBinding(VertexBuffer vertexBuffer, int vertexOffset)
     : this(vertexBuffer, vertexOffset, 0)
 {
 }
Beispiel #20
0
        public Cheetah.VertexBuffer CreateStaticVertexBuffer(object data, int length)
        {
            XnaVertexBuffer vb = new XnaVertexBuffer(Device, length, ResourceUsage.None, ResourcePool.Managed);

            return(new StaticVertexBuffer(vb));
        }
 public VertexBufferBinding(VertexBuffer vertexBuffer)
     : this(vertexBuffer, 0)
 {
 }
Beispiel #22
0
        public Cheetah.DynamicVertexBuffer CreateDynamicVertexBuffer(int length)
        {
            XnaVertexBuffer vb = new XnaVertexBuffer(Device, length, ResourceUsage.None, ResourcePool.Managed);

            return(new DynamicVertexBuffer(vb));
        }
Beispiel #23
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;
            }
        }
Beispiel #24
0
 public Cheetah.DynamicVertexBuffer CreateDynamicVertexBuffer(int length)
 {
     XnaVertexBuffer vb = new XnaVertexBuffer(Device, length, ResourceUsage.None, ResourcePool.Managed);
     return new DynamicVertexBuffer(vb);
 }
Beispiel #25
0
 public void SetVertexBuffer(VertexBuffer vertexBuffer)
 {
     SetVertexBuffer(vertexBuffer, 0);
 }
Beispiel #26
0
 public DynamicVertexBuffer(XnaVertexBuffer vb)
 {
     vb = XnaBuffer;
 }
Beispiel #27
0
        protected override void RenderBuffer()
        {
            if (underlyingbuffer == null)
            {
                underlyingbuffer = new Microsoft.Xna.Framework.Graphics.VertexBuffer(renderer.idevice, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.None);
                List<VertexPositionNormalTexture> mlists = new List<VertexPositionNormalTexture>();
                for (int i = 0; i < vertices.Length; i++)
                {
                mlists.Add(new VertexPositionNormalTexture(new Vector3(vertices[i].X,vertices[i].Y,vertices[i].Z),new Vector3(normals[i].X,normals[i].Y,normals[i].Z),new Vector2(texcoords[i].X,texcoords[i].Y)));

                }
                underlyingbuffer.SetData<VertexPositionNormalTexture>(mlists.ToArray());

            }
            if (!renderer.rendertargetscene)
            {
                renderer.shader.Texture = renderer.texture;
            }
             renderer.shader.World = Matrix.Identity;//Matrix.CreateWorld(new Vector3(0, 0, 0), Vector3.Forward, Vector3.Up);
             if (renderer.rendertargetscene)
             {
             renderer.shader.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)renderer.tex.Width/(float)renderer.tex.Height, 1, 500);
             }
             else
             {
             renderer.shader.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, renderer.idevice.Viewport.AspectRatio, 1, 500);
             }
            if (!isstatic)
            {
                if (renderer.rendertargetscene)
                {
                    renderer.shader.View = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, 1), Vector3.Up) * Matrix.CreateTranslation(new Vector3(-Position.X + renderer.position.X, Position.Y + renderer.position.Y, -Position.Z + renderer.position.Z)) * Matrix.CreateRotationY(renderer.rotation.Y) * Matrix.CreateRotationX(renderer.rotation.X) * Matrix.CreateRotationZ(renderer.rotation.Z) * renderer.matrix;

                }
                else
                {
                    renderer.shader.View = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, 1), Vector3.Up) * Matrix.CreateTranslation(new Vector3(-Position.X + renderer.cameraPosition.X, Position.Y + renderer.cameraPosition.Y, -Position.Z + renderer.cameraPosition.Z)) * renderer.matrix;
                }
            }
            else
            {
                renderer.shader.View = Matrix.CreateLookAt(new Vector3(Position.X, Position.Y, Position.Z), new Vector3(0, 0, 0), Vector3.Up);

            }
            renderer.idevice.SetVertexBuffer(underlyingbuffer, 0);
            renderer.shader.CurrentTechnique.Passes[0].Apply();

            renderer.idevice.DrawPrimitives(PrimitiveType.TriangleList, 0, vertices.Length / 3);
        }
 public unsafe void SetVertexBuffer(VertexBuffer vertexBuffer, int vertexOffset)
 {
 }
Beispiel #29
0
 public StaticVertexBuffer(XnaVertexBuffer vb)
 {
     vb = XnaBuffer;
 }
Beispiel #30
0
 public DynamicVertexBuffer(XnaVertexBuffer vb)
 {
     vb = XnaBuffer;
 }