Ejemplo n.º 1
0
        private Texture2D GetZTexture(GraphicsDevice device, bool onlyThis)
        {
            Texture2D result = null;

            if (ContainsNothing || ContainsNoZ)
            {
                return(null);
            }
            if (!ZCache.TryGetTarget(out result) || ((CachableTexture2D)result).BeingDisposed || result.IsDisposed)
            {
                DecodeIfRequired(true);
                if (this.Width == 0 || this.Height == 0)
                {
                    ContainsNothing = true;
                    return(null);
                }
                if (ZBufferData == null)
                {
                    ContainsNoZ = true;
                    return(null);
                }
                result = new CachableTexture2D(device, this.Width, this.Height, false, SurfaceFormat.Alpha8);
                result.SetData <byte>(this.ZBufferData);
                ZCache = new WeakReference <Texture2D>(result);
                if (TimedReferenceController.CurrentType == CacheType.PERMANENT)
                {
                    PermaRefZ = result;
                }
                if (!IffFile.RETAIN_CHUNK_DATA)
                {
                    ZBufferData = null;
                    if (onlyThis)
                    {
                        PixelData = null;
                    }
                }
            }
            if (TimedReferenceController.CurrentType != CacheType.PERMANENT)
            {
                TimedReferenceController.KeepAlive(result, KeepAliveType.ACCESS);
            }
            return(result);
        }
Ejemplo n.º 2
0
        private Texture2D GetTexture(GraphicsDevice device, bool onlyThis)
        {
            if (ContainsNothing)
            {
                return(null);
            }
            Texture2D result = null;

            if (!PixelCache.TryGetTarget(out result) || ((CachableTexture2D)result).BeingDisposed || result.IsDisposed)
            {
                DecodeIfRequired(false);
                if (this.Width == 0 || this.Height == 0)
                {
                    ContainsNothing = true;
                    return(null);
                }
                var mip = FSOEnvironment.Enable3D && (FSOEnvironment.EnableNPOTMip || (Width == 128 && Height == 64));
                result = new CachableTexture2D(device, this.Width, this.Height, mip, SurfaceFormat.Color);
                if (mip)
                {
                    TextureUtils.UploadWithMips(result, device, this.PixelData);
                }
                else
                {
                    result.SetData <Color>(this.PixelData);
                }
                PixelCache = new WeakReference <Texture2D>(result);
                if (TimedReferenceController.CurrentType == CacheType.PERMANENT)
                {
                    PermaRefP = result;
                }
                if (!IffFile.RETAIN_CHUNK_DATA)
                {
                    PixelData = null;
                    //if (onlyThis && !FSOEnvironment.Enable3D) ZBufferData = null;
                }
            }
            if (TimedReferenceController.CurrentType != CacheType.PERMANENT)
            {
                TimedReferenceController.KeepAlive(result, KeepAliveType.ACCESS);
            }
            return(result);
        }
Ejemplo n.º 3
0
        private Texture2D GetZTexture(GraphicsDevice device, bool onlyThis)
        {
            Texture2D result = null;

            if (ContainsNothing || ContainsNoZ)
            {
                return(null);
            }
            if (!ZCache.TryGetTarget(out result) || ((CachableTexture2D)result).BeingDisposed || result.IsDisposed)
            {
                DecodeIfRequired(true);
                if (this.Width == 0 || this.Height == 0)
                {
                    ContainsNothing = true;
                    return(null);
                }
                if (ZBufferData == null)
                {
                    ContainsNoZ = true;
                    return(null);
                }
                if (FSOEnvironment.TexCompress)
                {
                    result = new CachableTexture2D(device, ((Width + 3) / 4) * 4, ((Height + 3) / 4) * 4, false, SurfaceFormat.Alpha8);
                    var tempZ = new byte[result.Width * result.Height];
                    var dind  = 0;
                    var sind  = 0;
                    for (int i = 0; i < Height; i++)
                    {
                        Array.Copy(ZBufferData, sind, tempZ, dind, Width);
                        sind += Width;
                        dind += result.Width;
                    }

                    result.SetData <byte>(tempZ);
                }
                else
                {
                    result = new CachableTexture2D(device, this.Width, this.Height, false, SurfaceFormat.Alpha8);
                    result.SetData <byte>(this.ZBufferData);
                }
                ZCache = new WeakReference <Texture2D>(result);
                if (TimedReferenceController.CurrentType == CacheType.PERMANENT)
                {
                    PermaRefZ = result;
                }
                if (!IffFile.RETAIN_CHUNK_DATA)
                {
                    //if (!FSOEnvironment.Enable3D) ZBufferData = null; disabled right now til we get a clean way of getting this post-world-texture for ultra lighting
                    if (onlyThis)
                    {
                        PixelData = null;
                    }
                }
            }
            if (TimedReferenceController.CurrentType != CacheType.PERMANENT)
            {
                TimedReferenceController.KeepAlive(result, KeepAliveType.ACCESS);
            }
            return(result);
        }