Switch: Improve screenshot texture handling

This commit is contained in:
Vicki Pfau 2023-01-28 20:31:46 -08:00
parent 70e31df683
commit 1a29a92c3a
1 changed files with 21 additions and 4 deletions

View File

@ -82,6 +82,7 @@ static GLuint insizeLocation;
static GLuint colorLocation; static GLuint colorLocation;
static GLuint tex; static GLuint tex;
static GLuint oldTex; static GLuint oldTex;
static GLuint screenshotTex;
static struct GUIFont* font; static struct GUIFont* font;
static color_t* frameBuffer; static color_t* frameBuffer;
@ -379,8 +380,6 @@ static void _gameUnloaded(struct mGUIRunner* runner) {
static void _drawTex(struct mGUIRunner* runner, unsigned width, unsigned height, bool faded, bool blendTop) { static void _drawTex(struct mGUIRunner* runner, unsigned width, unsigned height, bool faded, bool blendTop) {
glViewport(0, 1080 - vheight, vwidth, vheight); glViewport(0, 1080 - vheight, vwidth, vheight);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glUseProgram(program); glUseProgram(program);
glBindVertexArray(vao); glBindVertexArray(vao);
@ -493,11 +492,16 @@ static void _drawFrame(struct mGUIRunner* runner, bool faded) {
} }
if (interframeBlending) { if (interframeBlending) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, oldTex); glBindTexture(GL_TEXTURE_2D, oldTex);
_drawTex(runner, width, height, faded, false); _drawTex(runner, width, height, faded, false);
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
_drawTex(runner, width, height, faded, true); _drawTex(runner, width, height, faded, true);
} else { } else {
glDisable(GL_BLEND);
_drawTex(runner, width, height, faded, false); _drawTex(runner, width, height, faded, false);
} }
@ -523,10 +527,15 @@ static void _drawFrame(struct mGUIRunner* runner, bool faded) {
static void _drawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsigned width, unsigned height, bool faded) { static void _drawScreenshot(struct mGUIRunner* runner, const color_t* pixels, unsigned width, unsigned height, bool faded) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, screenshotTex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
runner->core->desiredVideoDimensions(runner->core, &width, &height);
glDisable(GL_BLEND);
bool wasPbo = usePbo;
usePbo = false;
_drawTex(runner, width, height, faded, false); _drawTex(runner, width, height, faded, false);
usePbo = wasPbo;
} }
static uint16_t _pollGameInput(struct mGUIRunner* runner) { static uint16_t _pollGameInput(struct mGUIRunner* runner) {
@ -711,6 +720,13 @@ static void glInit(void) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenTextures(1, &screenshotTex);
glBindTexture(GL_TEXTURE_2D, screenshotTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenBuffers(1, &pbo); glGenBuffers(1, &pbo);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER, 256 * 256 * 4, NULL, GL_STREAM_DRAW); glBufferData(GL_PIXEL_UNPACK_BUFFER, 256 * 256 * 4, NULL, GL_STREAM_DRAW);
@ -790,6 +806,7 @@ static void glDeinit(void) {
glDeleteFramebuffers(1, &copyFbo); glDeleteFramebuffers(1, &copyFbo);
glDeleteTextures(1, &tex); glDeleteTextures(1, &tex);
glDeleteTextures(1, &oldTex); glDeleteTextures(1, &oldTex);
glDeleteTextures(1, &screenshotTex);
glDeleteBuffers(1, &vbo); glDeleteBuffers(1, &vbo);
glDeleteProgram(program); glDeleteProgram(program);
glDeleteVertexArrays(1, &vao); glDeleteVertexArrays(1, &vao);