예제 #1
0
        private bool copyToStaging(VTexPage page, StagingBufferSet buffers, IndirectionTexture indirectionTexture, OriginalTextureInfo textureUnit)
        {
            bool usedPhysicalPage = false;

            try
            {
                if (page.mip >= textureUnit.MipOffset)
                {
                    //Load or grab from cache
                    using (var pageHandle = textureCache.getImage(page, indirectionTexture, textureUnit, textelsPerPage, padding, padding2))
                    {
                        buffers.setPhysicalPage(pageHandle.PixelBox, virtualTextureManager.getPhysicalTexture(textureUnit.TextureUnit), padding);
                        usedPhysicalPage = true;
                    }
                }
                else
                {
                    Logging.Log.Warning("Unable to load mip map level {0} for texture {1}", page.mip - textureUnit.MipOffset, textureUnit.TextureFileName);
                }
            }
            catch (Exception ex)
            {
                Logging.Log.Error("{0} loading image {1}. Message: {2}", ex.GetType().Name, textureUnit.TextureFileName, ex.Message);
            }
            return(usedPhysicalPage);
        }
예제 #2
0
        internal TexturePageHandle getImage(VTexPage page, IndirectionTexture indirectionTexture, OriginalTextureInfo textureUnit, int textelsPerPage, int padding, int padding2)
        {
            String textureName;

            if (texturesArePaged)
            {
                textureName = textureUnit.TextureFileName;
            }
            else
            {
                textureName = String.Format("{0}_{1}", textureUnit.TextureFileName, indirectionTexture.RealTextureSize.Width >> page.mip);
            }
            TextureCacheHandle cacheHandle;

            if (!this.TryGetValue(textureName, out cacheHandle))
            {
                String file = textureUnit.TextureFileName;
                if (texturesArePaged) //Paged Images
                {
                    //using (var perfMon = new LogPerformanceBlock(String.Format("Loaded image {0} in {{0}} ms", file), Logging.LogLevel.Info, "TextureCache"))
                    //{
                    PagedImage pagedImage = new PagedImage();
                    pagedImage.load(() => VirtualFileSystem.Instance.openStream(file, Engine.Resources.FileMode.Open, Engine.Resources.FileAccess.Read));
                    cacheHandle = this.Add(textureName, pagedImage);
                    //}
                }
                else //Normal Images
                {
                    String extension  = Path.GetExtension(file);
                    String directFile = textureUnit.TextureFileName.Substring(0, file.Length - extension.Length);
                    directFile = String.Format("{0}_{1}{2}", directFile, indirectionTexture.RealTextureSize.Width >> page.mip, extension);
                    if (VirtualFileSystem.Instance.exists(directFile))
                    {
                        var image = doLoadImage(extension, directFile);
                        cacheHandle = this.Add(textureName, image);
                    }
                    else
                    {
                        //Not using cache for full size images, this is a rare case that we are not really supporting right now
                        Image image = doLoadImage(extension, textureUnit.TextureFileName);

                        //If we aren't mip 0 resize accordingly
                        if (page.mip > image.NumMipmaps && page.mip != 0)
                        {
                            using (Image original = image)
                            {
                                image = new Image(original.Width >> page.mip, original.Height >> page.mip, original.Depth, original.Format, original.NumFaces, original.NumMipmaps);
                                using (var src = original.getPixelBox())
                                {
                                    using (var dest = image.getPixelBox())
                                    {
                                        Image.Scale(src, dest, Image.Filter.FILTER_BILINEAR);
                                    }
                                }
                            }
                        }
                        cacheHandle = this.Add(textureName, image);
                    }
                }
            }
            return(cacheHandle.createTexturePageHandle(page, indirectionTexture, padding, padding2, textelsPerPage, textureUnit.MipOffset));
        }
예제 #3
0
 private Task <bool> fireCopyToStaging(VTexPage page, StagingBufferSet buffers, IndirectionTexture indirectionTexture, OriginalTextureInfo textureUnit)
 {
     return(Task.Run(() => copyToStaging(page, buffers, indirectionTexture, textureUnit)));
 }