Filters.BaseFilter CreateCoreScreenControl() { if (Global.Emulator is MelonDS nds) { //TODO: need to pipe layout settings into here now var filter = new Filters.ScreenControlNDS(nds); return(filter); } return(null); }
private FilterProgram UpdateSourceInternal(JobInfo job) { //no drawing actually happens. it's important not to begin drawing on a control if (!job.Simulate && !job.Offscreen) { GLManager.Activate(CR_GraphicsControl); if (job.ChainOutsize.Width == 0 || job.ChainOutsize.Height == 0) { // this has to be a NOP, because lots of stuff will malfunction on a 0-sized viewport if (_currentFilterProgram != null) { UpdateSourceDrawingWork(job); //but we still need to do this, because of vsync } return(null); } } IVideoProvider videoProvider = job.VideoProvider; bool simulate = job.Simulate; Size chainOutsize = job.ChainOutsize; //simulate = true; int[] videoBuffer = videoProvider.GetVideoBuffer(); int bufferWidth = videoProvider.BufferWidth; int bufferHeight = videoProvider.BufferHeight; int presenterTextureWidth = bufferWidth; int presenterTextureHeight = bufferHeight; bool isGlTextureId = videoBuffer.Length == 1; int vw = videoProvider.VirtualWidth; int vh = videoProvider.VirtualHeight; //TODO: it is bad that this is happening outside the filter chain //the filter chain has the ability to add padding... //for now, we have to have some hacks. this could be improved by refactoring the filter setup hacks to be in one place only though //could the PADDING be done as filters too? that would be nice. var fCoreScreenControl = CreateCoreScreenControl(); if (fCoreScreenControl != null) { var sz = fCoreScreenControl.PresizeInput("default", new Size(bufferWidth, bufferHeight)); presenterTextureWidth = vw = sz.Width; presenterTextureHeight = vh = sz.Height; } if (Global.Config.DispFixAspectRatio) { if (Global.Config.DispManagerAR == EDispManagerAR.System) { //Already set } if (Global.Config.DispManagerAR == EDispManagerAR.Custom) { //not clear what any of these other options mean for "screen controlled" systems vw = Global.Config.DispCustomUserARWidth; vh = Global.Config.DispCustomUserARHeight; } if (Global.Config.DispManagerAR == EDispManagerAR.CustomRatio) { //not clear what any of these other options mean for "screen controlled" systems FixRatio(Global.Config.DispCustomUserArx, Global.Config.DispCustomUserAry, videoProvider.BufferWidth, videoProvider.BufferHeight, out vw, out vh); } } var padding = CalculateCompleteContentPadding(true, false); vw += padding.Horizontal; vh += padding.Vertical; BitmapBuffer bb = null; Texture2d videoTexture = null; if (!simulate) { if (isGlTextureId) { //FYI: this is a million years from happening on n64, since it's all geriatric non-FBO code //is it workable for saturn? videoTexture = GL.WrapGLTexture2d(new IntPtr(videoBuffer[0]), bufferWidth, bufferHeight); } else { //wrap the VideoProvider data in a BitmapBuffer (no point to refactoring that many IVideoProviders) bb = new BitmapBuffer(bufferWidth, bufferHeight, videoBuffer); bb.DiscardAlpha(); //now, acquire the data sent from the videoProvider into a texture videoTexture = VideoTextureFrugalizer.Get(bb); // lets not use this. lets define BizwareGL to make clamp by default (TBD: check opengl) //GL.SetTextureWrapMode(videoTexture, true); } } // record the size of what we received, since lua and stuff is gonna want to draw onto it currEmuWidth = bufferWidth; currEmuHeight = bufferHeight; //build the default filter chain and set it up with services filters will need Size chainInsize = new Size(bufferWidth, bufferHeight); var filterProgram = BuildDefaultChain(chainInsize, chainOutsize, job.IncludeOSD, job.IncludeUserFilters); filterProgram.GuiRenderer = Renderer; filterProgram.GL = GL; //setup the source image filter Filters.SourceImage fInput = filterProgram["input"] as Filters.SourceImage; fInput.Texture = videoTexture; //setup the final presentation filter Filters.FinalPresentation fPresent = filterProgram["presentation"] as Filters.FinalPresentation; fPresent.VirtualTextureSize = new Size(vw, vh); fPresent.TextureSize = new Size(presenterTextureWidth, presenterTextureHeight); fPresent.BackgroundColor = videoProvider.BackgroundColor; fPresent.GuiRenderer = Renderer; fPresent.Flip = isGlTextureId; fPresent.Config_FixAspectRatio = Global.Config.DispFixAspectRatio; fPresent.Config_FixScaleInteger = Global.Config.DispFixScaleInteger; fPresent.Padding = ClientExtraPadding; fPresent.AutoPrescale = Global.Config.DispAutoPrescale; fPresent.GL = GL; //POOPY. why are we delivering the GL context this way? such bad Filters.ScreenControlNDS fNDS = filterProgram["CoreScreenControl"] as Filters.ScreenControlNDS; if (fNDS != null) { fNDS.GuiRenderer = Renderer; fNDS.GL = GL; } filterProgram.Compile("default", chainInsize, chainOutsize, !job.Offscreen); if (simulate) { } else { _currentFilterProgram = filterProgram; UpdateSourceDrawingWork(job); } // cleanup: bb?.Dispose(); return(filterProgram); }