Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-zero default framebuffer is completely overridden at certain points #2803

Open
jgcodes2020 opened this issue Nov 12, 2023 · 3 comments
Open

Comments

@jgcodes2020
Copy link

I'm writing a custom frontend for Mupen64Plus. I have overridden VidExt_GL_GetDefaultFramebuffer to use an FBO I create. It seems that GLideN64 will somehow override this FBO, resetting all of its attachments. If I try naively to setup the framebuffer again, it seems to be fairly inconsistent on whether it wants to work or not.

Config settings:

[Video-GLideN64]

# Settings version. Don't touch it.
configVersion = 29
# Enable threaded video backend.
ThreadedVideo = False
# Set MultiSampling (MSAA) value. (0=off, 2,4,8,16=quality)
MultiSampling = 0
# Toggle Fast Approximate Anti-Aliasing (FXAA).
FXAA = False
# Screen aspect ratio. (0=stretch, 1=force 4:3, 2=force 16:9, 3=adjust)
AspectRatio = 1
# Swap frame buffers. (0=On VI update call, 1=On VI origin change, 2=On buffer update)
BufferSwapMode = 0
# Frame buffer size is the factor of N64 native resolution.
UseNativeResolutionFactor = 0
# Bilinear filtering mode. (0=N64 3point, 1=standard)
bilinearMode = True
# Remove halos around filtered textures.
enableHalosRemoval = False
# Max level of Anisotropic Filtering, 0 for off.
anisotropy = 0
# Enable dithering pattern on output image.
EnableDitheringPattern = False
# Enable hi-res noise dithering.
EnableHiresNoiseDithering = False
# Dither with color quantization.
DitheringQuantization = True
# Dithering mode for image in RDRAM. (0=disable, 1=bayer, 2=magic square, 3=blue noise)
RDRAMImageDitheringMode = 3
# Enable LOD emulation.
EnableLOD = True
# Enable hardware per-pixel lighting.
EnableHWLighting = False
# Enable pixel coverage calculation. Used for better blending emulation and wire-frame mode. Needs fast GPU.
EnableCoverage = False
# Enable software vertices clipping. Brings various benefits.
EnableClipping = True
# Use persistent storage for compiled shaders.
EnableShadersStorage = True
# Do not use shaders to emulate N64 blending modes. Works faster on slow GPU. Can cause glitches.
EnableLegacyBlending = False
# Enable hybrid integer scaling filter. Can be slow with low-end GPUs.
EnableHybridFilter = True
# Use fast but less accurate shaders. Can help with low-end GPUs.
EnableInaccurateTextureCoordinates = False
# Enable writing of fragment depth. Some mobile GPUs do not support it, thus made optional. Leave enabled.
EnableFragmentDepthWrite = True
# Use GLideN64 per-game settings.
EnableCustomSettings = True
# Make texrect coordinates continuous to avoid black lines between them. (0=Off, 1=Auto, 2=Force)
CorrectTexrectCoords = 0
# Render 2D texrects in native resolution to fix misalignment between parts of 2D image. (0=Off, 1=Optimized, 2=Unoptimized)
EnableNativeResTexrects = 0
# Render backgrounds mode. (HLE only). (0=One piece (fast), 1=Stripped (precise))
BackgroundsMode = 1
# Bound texture rectangle texture coordinates to the values they take in native resolutions. It prevents garbage due to fetching out of texture bounds, but can result in hard edges. (0=Off, 1=On)
EnableTexCoordBounds = 0
# Enable frame and/or depth buffer emulation.
EnableFBEmulation = False
# Copy auxiliary buffers to RDRAM.
EnableCopyAuxiliaryToRDRAM = False
# Enable N64 depth compare instead of OpenGL standard one. Experimental. (0=Off, 1=Fast, 2=Compatible)
EnableN64DepthCompare = 0
# Force depth buffer clear. Hack. Needed for Eikou no Saint Andrews.
ForceDepthBufferClear = False
# Disable buffers read/write with FBInfo. Use for games which do not work with FBInfo.
DisableFBInfo = True
# Read color buffer by 4kb chunks (strictly follow FBRead specification).
FBInfoReadColorChunk = False
# Read depth buffer by 4kb chunks (strictly follow FBRead specification).
FBInfoReadDepthChunk = True
# Enable color buffer copy to RDRAM. (0=do not copy, 1=copy in sync mode, 2=Double Buffer, 3=Triple Buffer)
EnableCopyColorToRDRAM = 2
# Enable depth buffer copy to RDRAM. (0=do not copy, 1=copy from video memory, 2=use software render)
EnableCopyDepthToRDRAM = 2
# Enable color buffer copy from RDRAM.
EnableCopyColorFromRDRAM = False
# Enable resulted image crop by Overscan.
EnableOverscan = False
# PAL mode. Left bound of Overscan.
OverscanPalLeft = 0
# PAL mode. Right bound of Overscan.
OverscanPalRight = 0
# PAL mode. Top bound of Overscan.
OverscanPalTop = 0
# PAL mode. Bottom bound of Overscan.
OverscanPalBottom = 0
# NTSC mode. Left bound of Overscan.
OverscanNtscLeft = 0
# NTSC mode. Right bound of Overscan.
OverscanNtscRight = 0
# NTSC mode. Top bound of Overscan.
OverscanNtscTop = 0
# NTSC mode. Bottom bound of Overscan.
OverscanNtscBottom = 0
# Texture filter. (0=none, 1=Smooth filtering 1, 2=Smooth filtering 2, 3=Smooth filtering 3, 4=Smooth filtering 4, 5=Sharp filtering 1, 6=Sharp filtering 2)
txFilterMode = 0
# Texture enhancement. (0=none, 1=store as is, 2=X2, 3=X2SAI, 4=HQ2X, 5=HQ2XS, 6=LQ2X, 7=LQ2XS, 8=HQ4X, 9=2xBRZ, 10=3xBRZ, 11=4xBRZ, 12=5xBRZ, 13=6xBRZ)
txEnhancementMode = 0
# Deposterize texture before enhancement.
txDeposterize = False
# Don't filter background textures.
txFilterIgnoreBG = False
# Size of memory cache for enhanced textures in megabytes.
txCacheSize = 100
# Use high resolution texture packs if available.
txHiresEnable = False
# Allow to fully use the alpha channel for high resolution textures.
txHiresFullAlphaChannel = True
# Use alternative method for paletted textures CRC calculation.
txHresAltCRC = False
# Zip texture cache.
txCacheCompression = True
# Force the use of 16-bit texture formats for HD textures.
txForce16bpp = False
# Save texture cache to hard disk.
txSaveCache = True
# Dump textures
txDump = False
# Use file storage instead of memory cache for enhanced textures.
txEnhancedTextureFileStorage = False
# Use file storage instead of memory cache for HD textures.
txHiresTextureFileStorage = False
# Use no file storage or cache for HD textures.
txNoTextureFileStorage = False
# Limit hi-res textures size in VRAM (in MB, 0 = no limit)
txHiresVramLimit = 0
# Path to folder with hi-res texture packs.
txPath = "/home/jgcodes/.local/share/mupen64plus//hires_texture"
# Path to folder where plugin saves texture cache files.
txCachePath = "/home/jgcodes/.cache/mupen64plus//cache"
# Path to folder where plugin saves dumped textures.
txDumpPath = "/home/jgcodes/.cache/mupen64plus//texture_dump"
# File name of True Type Font for text messages.
fontName = "FreeSans.ttf"
# Font size.
fontSize = 18
# Font color in RGB format.
fontColor = "B5E61D"
# Force gamma correction.
ForceGammaCorrection = False
# Gamma correction level.
GammaCorrectionLevel = 2.000000
# Show FPS counter.
ShowFPS = False
# Show VI/s counter.
ShowVIS = False
# Show percent counter.
ShowPercent = False
# Show internal resolution.
ShowInternalResolution = False
# Show rendering resolution.
ShowRenderingResolution = False
# Show statistics for drawn elements.
ShowStatistics = False
# Counters position. (1=top left, 2=top center, 4=top right, 8=bottom left, 16=bottom center, 32=bottom right)
CountersPos = 8
# Hotkey: toggle textures dump
hkTexDump = ""
# Hotkey: reload HD textures
hkHdTexReload = ""
# Hotkey: toggle HD textures
hkHdTexToggle = ""
# Hotkey: toggle texcoords bounds
hkTexCoordBounds = ""
# Hotkey: toggle 2D texrects in native resolution
hkNativeResTexrects = ""
# Hotkey: toggle VSync
hkVsync = ""
# Hotkey: toggle frame buffer emulation
hkFBEmulation = ""
# Hotkey: toggle N64 depth compare
hkN64DepthCompare = ""
# Hotkey: toggle OSD VI/S
hkOsdVis = ""
# Hotkey: toggle OSD FPS
hkOsdFps = ""
# Hotkey: toggle OSD percent
hkOsdPercent = ""
# Hotkey: toggle OSD internal resolution
hkOsdInternalResolution = ""
# Hotkey: toggle OSD rendering resolution
hkOsdRenderingResolution = ""
# Hotkey: toggle force gamma correction
hkForceGammaCorrection = ""
# Hotkey: toggle inaccurate texture coordinates
hkInaccurateTexCords = ""
@gonetz
Copy link
Owner

gonetz commented Aug 10, 2024

Is it still actual?
GLideN64 calls VidExt_GL_GetDefaultFramebuffer in DisplayWindowMupen64plus::_getDefaultFramebuffer().
May be you need to check, if it calls your overridden version, not the core one.

It seems that GLideN64 will somehow override this FBO, resetting all of its attachments.

GLideN64 can reset attachments only for those FBOs which it allocated. If you use the same GL context as the plugin and allocates a FBO for your needs, you should be safe, because GL won't create another FBO with the same id.

@alice-mkh
Copy link

alice-mkh commented Sep 10, 2024

I can confirm this is happening as well. I thought it was a bug on my side since it works in RMG, but apparently looks like the default fbo there is just 0: https://doc.qt.io/qt-6/qopenglcontext.html#defaultFramebufferObject

VidExt_GL_GetDefaultFramebuffer() is definitely called - a debug print inside it works.

@alice-mkh
Copy link

Looks like the culprit is this line: https://github.com/gonetz/GLideN64/blob/master/src/FrameBuffer.cpp#L53

combined with this: https://github.com/gonetz/GLideN64/blob/master/src/FrameBuffer.cpp#L35

In other words, it's deleting the default framebuffer.

diff --git a/src/FrameBuffer.cpp b/src/FrameBuffer.cpp
index 68cf2bf4..9d6ba513 100644
--- a/src/FrameBuffer.cpp
+++ b/src/FrameBuffer.cpp
@@ -50,7 +50,8 @@ FrameBuffer::~FrameBuffer()
        gfxContext.deleteFramebuffer(m_depthFBO);
        gfxContext.deleteFramebuffer(m_resolveFBO);
        gfxContext.deleteFramebuffer(m_SubFBO);
-       gfxContext.deleteFramebuffer(m_copyFBO);
+       if (m_copyFBO != ObjectHandle::defaultFramebuffer)
+               gfxContext.deleteFramebuffer(m_copyFBO);
 
        textureCache().removeFrameBufferTexture(m_pTexture);
        textureCache().removeFrameBufferTexture(m_pDepthTexture);

So this fixes it for me. I don't know enough to say if it's a good solution or not, so I'll just leave it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants