private static CachedTexture getCachedTexture(int width, int height, int pixelFormat, int offset) { CachedTexture cachedTexture; if (pspsharp.graphics.RE.IRenderingEngine_Fields.isTextureTypeIndexed[pixelFormat]) { switch (pixelFormat) { case TPSM_PIXEL_STORAGE_MODE_8BIT_INDEXED: cachedTexture = new CachedTextureIndexed8Bit(width, height, pixelFormat, offset); break; case TPSM_PIXEL_STORAGE_MODE_16BIT_INDEXED: cachedTexture = new CachedTextureIndexed16Bit(width, height, pixelFormat, offset); break; case TPSM_PIXEL_STORAGE_MODE_32BIT_INDEXED: cachedTexture = new CachedTextureIndexed32Bit(width, height, pixelFormat, offset); break; default: VideoEngine.log_Renamed.error(string.Format("CachedTexture: unsupported indexed texture format {0:D}", pixelFormat)); return(null); } cachedTexture.setClut(); } else if (width == Utilities.makePow2(width)) { if (offset == 0) { cachedTexture = new CachedTexturePow2(width, height, pixelFormat); } else { cachedTexture = new CachedTextureOffsetPow2(width, height, pixelFormat, offset); } } else { if (offset == 0) { cachedTexture = new CachedTextureNonPow2(width, height, pixelFormat); } else { cachedTexture = new CachedTextureOffsetNonPow2(width, height, pixelFormat, offset); } } return(cachedTexture); }
private CachedTexture resampleTexture(int width, int height) { if (resampleInfos.Count >= 5 && VideoEngine.log_Renamed.InfoEnabled) { VideoEngine.log_Renamed.info(string.Format("Resampling texture from ({0:D},{1:D}) to ({2:D},{3:D}), pixelFormat={4:D}, resampled {5:D} times", cachedTextureOriginal.width, cachedTextureOriginal.height, width, height, cachedTextureOriginal.pixelFormat, resampleInfos.Count)); } else if (VideoEngine.log_Renamed.DebugEnabled) { VideoEngine.log_Renamed.debug(string.Format("Resampling texture from ({0:D},{1:D}) to ({2:D},{3:D}), pixelFormat={4:D}, resampled {5:D} times", cachedTextureOriginal.width, cachedTextureOriginal.height, width, height, cachedTextureOriginal.pixelFormat, resampleInfos.Count)); } RESoftware.textureResamplingStatistics.start(); int widthPow2 = makePow2(width); int heightPow2 = makePow2(height); int[] buffer = new int[widthPow2 * heightPow2]; int widthSkipEOL = widthPow2 - width; if (cachedTextureOriginal.width == (width << 1) && cachedTextureOriginal.height == (height << 1)) { // Optimized common case: minimize texture by a factor of 2 resampleTextureMinimize2(buffer, width, height, widthSkipEOL); } else if ((cachedTextureOriginal.width << 1) == width && (cachedTextureOriginal.height << 1) == height) { // Optimized common case: magnify texture by a factor of 2 resampleTextureMagnify2(buffer, width, height, widthSkipEOL); } else { // Generic case: magnify/minimize by arbitrary factors float widthFactor = cachedTextureOriginal.width / (float)width; float heightFactor = cachedTextureOriginal.height / (float)height; resampleTexture(buffer, width, height, widthSkipEOL, widthFactor, heightFactor); } CachedTexture cachedTextureResampled = new CachedTexturePow2(widthPow2, heightPow2, width, height, GeCommands.TPSM_PIXEL_STORAGE_MODE_32BIT_ABGR8888); cachedTextureResampled.setBuffer(buffer, 0, buffer.Length); ResampleInfo resampleInfo = new ResampleInfo(width, height, cachedTextureResampled); resampleInfos.AddLast(resampleInfo); RESoftware.textureResamplingStatistics.end(); return(cachedTextureResampled); }