Ejemplo n.º 1
0
        public override Stream OpenResource(string resourceName, string groupName, bool searchGroupsIfNotFound, Resource resourceBeingLoaded)
        {
            var extension = Path.GetExtension(resourceName).Substring(1);

            if (extension == "xnb")
            {
                return(base.OpenResource(resourceName, groupName, searchGroupsIfNotFound, resourceBeingLoaded));
            }

            if (Root.Instance.RenderSystem.ConfigOptions["Use Content Pipeline"].Value == "Yes")
            {
                if (CodecManager.Instance.GetCodec(extension).GetType().Name != "NullCodec")
                {
                    var acm = new AxiomContentManager((XnaRenderSystem)Root.Instance.RenderSystem, "");
#if SILVERLIGHT
                    var texture = acm.Load <WriteableBitmap>(resourceName);
#else
                    var texture = acm.Load <Texture2D>(resourceName);
#endif
                    return(new XnaImageCodecStream(texture));
                }
                return(base.OpenResource(resourceName, groupName, searchGroupsIfNotFound, resourceBeingLoaded));
            }

            return(base.OpenResource(resourceName, groupName, searchGroupsIfNotFound, resourceBeingLoaded));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        private void LoadVolumeTexture()
        {
#if SILVERLIGHT
            throw new NotSupportedException("TextureType.ThreeD is not supported in Silverlight 5.");
#else
            Debug.Assert(TextureType == TextureType.ThreeD);
            if (Root.Instance.RenderSystem.ConfigOptions["Use Content Pipeline"].Value == "Yes")
            {
                var acm = new AxiomContentManager((XnaRenderSystem)Root.Instance.RenderSystem, "");
                _volumeTexture           = acm.Load <Texture3D>(Name);
                _texture                 = _volumeTexture;
                internalResourcesCreated = true;
            }
#endif
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        private void LoadCubeTexture()
        {
            Debug.Assert(TextureType == TextureType.CubeMap, "this.TextureType == TextureType.CubeMap");

            if (Root.Instance.RenderSystem.ConfigOptions["Use Content Pipeline"].Value == "Yes")
            {
                var acm = new AxiomContentManager((XnaRenderSystem)Root.Instance.RenderSystem, "");
                _cubeTexture             = acm.Load <TextureCube>(Name);
                _texture                 = _cubeTexture;
                internalResourcesCreated = true;
            }
#if !(XBOX || XBOX360)
            else
            {
                /* Use internal .dds loader instead */
                //if ( Name.EndsWith( ".dds" ) )
                //{
                //    Stream stream = ResourceGroupManager.Instance.OpenResource( Name );
                //    _cubeTexture = XFG.TextureCube.FromFile( _device, stream );
                //    stream.Close();
                //}
                //else
                {
                    ConstructCubeFaceNames(Name);
                    // Load from 6 separate files
                    // Use Axiom codecs
                    var images = new List <Image>();

                    var pos = Name.LastIndexOf(".");
                    var ext = Name.Substring(pos + 1);

                    for (var i = 0; i < 6; i++)
                    {
                        var strm  = ResourceGroupManager.Instance.OpenResource(cubeFaceNames[i], Group, true, this);
                        var image = Image.FromStream(strm, ext);
                        images.Add(image);
                        strm.Close();
                    }

                    LoadImages(images.ToArray());
                }
                _texture = _cubeTexture;
                internalResourcesCreated = true;
            }
#endif
        }
Ejemplo n.º 4
0
        private void LoadNormalTexture()
        {
            Debug.Assert(TextureType == TextureType.OneD || TextureType == TextureType.TwoD);

            if (Root.Instance.RenderSystem.ConfigOptions["Use Content Pipeline"].Value == "Yes")
            {
                var acm = new AxiomContentManager((XnaRenderSystem)Root.Instance.RenderSystem, "Content");
                _normTexture             = acm.Load <Texture2D>(Name);
                _texture                 = _normTexture;
                Width                    = _normTexture.Width;
                Height                   = _normTexture.Height;
                internalResourcesCreated = true;
            }
#if !(XBOX || XBOX360)
            else
            {
                Stream stream;
                if (Name.EndsWith(".dds"))
                {
                    stream = ResourceGroupManager.Instance.OpenResource(Name);

                    // use Xna to load the image directly from the stream
                    //XFG.TextureCreationParameters tcp = new XFG.TextureCreationParameters();
                    //tcp.Filter = Microsoft.Xna.Framework.Graphics.FilterOptions.Triangle;
                    //tcp.MipLevels = MipmapCount;

                    //Not sure how to set MipLevels. _normTexture.LevelCount is get-only...
#if SILVERLIGHT
                    var im = new BitmapImage();
                    im.SetSource(stream);
                    _normTexture = new Texture2D(_device, im.PixelWidth, im.PixelHeight, false, SurfaceFormat.Color);
                    im.CopyTo(_normTexture);
#else
                    _normTexture = Texture2D.FromStream(_device, stream);                       //.FromFile( _device, stream, tcp );
#endif

                    // store a ref for the base texture interface
                    _texture = _normTexture;

                    //reset stream position to read Texture information
                    ////stream.Position = 0;

                    // set the image data attributes

                    //Not sure if these lines accomplish the same thing as the below commented-out ones.
                    SetSrcAttributes(_normTexture.Width, _normTexture.Height, 1,
                                     XnaHelper.Convert(_normTexture.Format));
                    SetFinalAttributes(_normTexture.Width, _normTexture.Height, 1,
                                       XnaHelper.Convert(_normTexture.Format));

                    //XFG.TextureInformation info = XFG.Texture2D.GetTextureInformation( stream );
                    //SetSrcAttributes( info.Width, info.Height, 1, XnaHelper.Convert( info.Format ) );
                    //SetFinalAttributes( info.Width, info.Height, 1, XnaHelper.Convert( info.Format ) );

                    internalResourcesCreated = true;
                }
                else
                {
                    // find & load resource data intro stream to allow resource group changes if required
                    stream = ResourceGroupManager.Instance.OpenResource(Name, Group, true, this);
//#if SILVERLIGHT
//                    if (stream == null)
//                    {
//                        Name += ".png";
//                        stream = ResourceGroupManager.Instance.OpenResource( Name, Group, true, this );
//                    }
//#endif
                    var pos = Name.LastIndexOf(".");
                    var ext = Name.Substring(pos + 1);

                    // Call internal LoadImages, not LoadImage since that's external and
                    // will determine load status etc again
                    var image = Image.FromStream(stream, ext);
                    LoadImages(new[]
                    {
                        image
                    });
                    image.Dispose();
                }

                if (stream != null)
                {
                    stream.Close();
                }
            }
#endif
        }