コード例 #1
0
        /// <summary>
        /// Clean up.
        /// </summary>
        public void Dispose()
        {
            // unsubscribe from events
            Framework.Instance.DeviceCreated -= new Bonsai.Core.EventArgs.DeviceEventHandler(Instance_DeviceCreated);
            Framework.Instance.DeviceLost    -= new EventHandler(Instance_DeviceLost);
            Framework.Instance.DeviceReset   -= new Bonsai.Core.EventArgs.DeviceEventHandler(Instance_DeviceReset);

            if ((fileName != null) && (_textures.ContainsKey(fileName)))
            {
                GlobalTexture globalTexture = _textures[fileName];
                globalTexture.ReferenceCount--;
                if (globalTexture.ReferenceCount == 0)
                {
                    globalTexture.BaseTexture.Dispose();
                    globalTexture.BaseTexture = null;
                    _textures.Remove(fileName);
                }
                else
                {
                    _textures[fileName] = globalTexture;
                }
            }
            else
            {
                if (texture != null)
                {
                    texture.Dispose();
                    texture = null;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Loads the actual texture.
        /// </summary>
        protected virtual void LoadTexture(string folder)
        {
            ImageInformation info = new ImageInformation();

            try
            {
                // First look for the texture in the same folder as the input folder
                if (File.Exists(fileName))
                {
                    info = TextureLoader.ImageInformationFromFile(fileName);
                }
                else
                {
                    fileName = Utility.FindMediaFile(fileName, folder);
                    info     = TextureLoader.ImageInformationFromFile(fileName);
                }
            }
            catch (MediaNotFoundException)
            {
                // Couldn't find it anywhere, skip it
                return;
            }
            catch
            {
                return;
            }
            if (_textures.ContainsKey(fileName))
            {
                GlobalTexture globalTexture = _textures[fileName];
                texture = globalTexture.BaseTexture;
                globalTexture.ReferenceCount = globalTexture.ReferenceCount + 1;
                _textures[fileName]          = globalTexture;
            }
            else
            {
                switch (info.ResourceType)
                {
                case ResourceType.Textures:
                    texture = TextureLoader.FromFile(Framework.Instance.Device, fileName);
                    break;

                case ResourceType.CubeTexture:
                    texture = TextureLoader.FromCubeFile(Framework.Instance.Device, fileName);
                    break;

                case ResourceType.VolumeTexture:
                    texture = TextureLoader.FromVolumeFile(Framework.Instance.Device, fileName);
                    break;
                }
                if (texture != null)
                {
                    GlobalTexture globalTexture = new GlobalTexture();
                    globalTexture.BaseTexture    = texture;
                    globalTexture.ReferenceCount = 1;
                    _textures.Add(fileName, globalTexture);
                }
            }
        }