protected override void OnUnloadResources( GraphicsLoadEventArgs e ) { Helpers.DisposeAndClear( ref vbPntb ); if( e.AllResources ) { //also unload managed Helpers.DisposeAndClear( ref vbTcCl ); Helpers.DisposeAndClear( ref ib ); Helpers.DisposeAndClear( ref decl ); } base.OnUnloadResources( e ); }
protected virtual void OnUnloadResources( GraphicsLoadEventArgs e ) { if( UnloadResources != null ) UnloadResources( this, e ); }
protected override void OnLoadResources( GraphicsLoadEventArgs e ) { GraphicsStream gs; Device dev = Device; if( e.AllResources ) { //load managed resources decl = new VertexDeclaration( dev, ModelVertexElements ); ib = new IndexBuffer( typeof( ushort ), model.Indices.Count, dev, Usage.None, Pool.Managed ); ib.SetData( model.Indices.ToArray(), 0, LockFlags.None ); vbTcCl = new VertexBuffer( dev, ModelVertexTexCoordColor.Size * model.Vertices.Count, Usage.None, VertexFormats.None, Pool.Managed ); //make sure we don't have random bits floating around in the unused channels gs = vbTcCl.Lock( 0, 0, LockFlags.None ); try { Helpers.ZeroMemory( gs.InternalData, gs.Length ); } finally { vbTcCl.Unlock(); gs = null; } UploadVerticesTcCl(); } vbPntb = new VertexBuffer( dev, ModelVertexPosNormTanBin.Size * model.Vertices.Count, Usage.Dynamic, VertexFormats.None, Pool.Default ); //make sure we don't have random bits floating around in the unused channels gs = vbPntb.Lock( 0, 0, LockFlags.NoOverwrite ); try { Helpers.ZeroMemory( gs.InternalData, gs.Length ); } finally { vbPntb.Unlock(); gs = null; } base.OnLoadResources( e ); }