/// <inheritdoc/> protected override void OnDispose() { try { _vb?.Dispose(); _ib?.Dispose(); _material.HoldReference(); } finally { base.OnDispose(); } }
/// <summary> /// Creates a new textured vertex group /// </summary> /// <param name="primitiveType">The type of primitives to generate from the vertexes</param> /// <param name="vertexes">An array for vertexes with position and texture information</param> /// <param name="indexes">An array of indexes for the index buffer; <c>null</c> for no indexes</param> /// <param name="material">The material to use for rendering</param> public VertexGroup(PrimitiveType primitiveType, PositionTextured[] vertexes, short[] indexes, XMaterial material) { #region Sanity checks if (vertexes == null) { throw new ArgumentNullException(nameof(vertexes)); } #endregion _primitiveType = primitiveType; _vertexCount = vertexes.Length; _material = material; // ReSharper disable once ImpureMethodCallOnReadonlyValueField _material.HoldReference(); _buildVertexBuffer = () => BufferHelper.CreateVertexBuffer(Engine.Device, vertexes, PositionTextured.Format); Initialize(indexes); }
//--------------------// #region Texture helper /// <summary> /// Loads the textures for the <see cref="CpuParticle"/> sprites /// </summary> private void UpdateSpriteTextures() { // Release previous textures _material1.ReleaseReference(); _material2.ReleaseReference(); #region First-life material // Start with empty material _material1 = XMaterial.DefaultMaterial; if (!string.IsNullOrEmpty(Preset.Particle1Texture)) { // Get texture path string texture = Path.Combine("Particles", Preset.Particle1Texture); // Check if texture path is valid if (ContentManager.FileExists("Textures", texture)) { _material1 = new XMaterial(XTexture.Get(Engine, texture)); _material1.HoldReference(); } } #endregion #region Second-life material _material2 = XMaterial.DefaultMaterial; if (!string.IsNullOrEmpty(Preset.Particle2Texture)) { // Get texture path string texture = Path.Combine("Particles", Preset.Particle2Texture); // Check if texture path is valid if (ContentManager.FileExists("Textures", texture)) { _material2 = new XMaterial(XTexture.Get(Engine, texture)); _material2.HoldReference(); } } #endregion Preset.TexturesDirty = false; }