devkitPro / citro3d

Homebrew PICA200 GPU wrapper library for Nintendo 3DS
zlib License
244 stars 34 forks source link

Question: Is it possible to change a render target's frame buffer format mid-program? #49

Open BallM4788 opened 4 years ago

BallM4788 commented 4 years ago

I'm trying to improve a program that can run different classic adventure games, each having their own color format(s) under which they run. Some of the more graphically-intensive games that have a 16-bit native color format (namely RGB565) run slowly on the 3DS because they're being converted up to RGBA8 so they can be passed to the render target.

I can't just change the program to run in a 16-bit color format because some of the games have a native 32-bit color format, so I think the best solution would be to change the render target's color buffer appropriately when a game is started. Is this even possible to do with citro3d? If so, do you have any suggestions on how I should go about it? I've been trying on my own, but I've not had any luck.

Here's the backend source for reference, and here is what I've done so far: ballm4788/scummvm@08e955719a8eab293231406fd08042b62712d617. Most of the relevant code is in "osystem-graphics.cpp," "sprite.h," and "sprite.cpp." "OSystem_3DS::initGraphics" is called during startup, and "OSystem_3DS::initSize" is called when loading up a game.

In what I've done so far, everything works fine with games that are non-16-bit or can adapt to 32-bit, but attempting to start up a 16-bit game (in my case, I've been using Riven for testing), a black screen shows, but the 3DS doesn't crash. The only way to get back to the 3DS home screen at that point is to hold the power button until the 3DS turns off and then turn it back on again.

asiekierka commented 4 years ago

Wouldn't C3D_RenderTargetDelete and creating a new one be sufficient for your use-case? As long as it happens outside of C3D_Frame... It's what I'm doing, at least.

fincs commented 4 years ago

While @asiekierka provided a workaround, I feel like that is somehow not right. With the advent of wide mode, I think it would be worthwhile to look into this again and provide a way to alias the same region of memory for multiple rendertargets with different formats and even dimensions. I can't guarantee a timeframe in which the necessary design/work will be done, though.

BallM4788 commented 3 years ago

I ended up working around this with help a long time ago. @fincs were you still looking into this, or can I close this issue?