mcst-linux-kernel/patches-2024.06.26/gl4es-1.1.4/0183-Added-fbo-resolution-h...

126 lines
4.8 KiB
Diff

From ab082d7b3611bb49a82dd6959478bfdfb7c85d47 Mon Sep 17 00:00:00 2001
From: JohnnyonFlame <johnnyonflame@hotmail.com>
Date: Sun, 7 Nov 2021 05:10:33 -0300
Subject: [PATCH 183/233] Added fbo resolution hack. The envvar
LIBGL_FB_TEX_SCALE controls the scale of the framebuffer textures.
---
src/gl/framebuffers.c | 13 +++++++++++--
src/gl/init.c | 4 ++++
src/gl/init.h | 1 +
src/gl/raster.c | 20 ++++++++++++++++++++
src/gl/texture.h | 1 +
5 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/gl/framebuffers.c b/src/gl/framebuffers.c
index 4aa512da..b189ff88 100644
--- a/src/gl/framebuffers.c
+++ b/src/gl/framebuffers.c
@@ -449,8 +449,10 @@ void APIENTRY_GL4ES gl4es_glFramebufferTexture2D(GLenum target, GLenum attachmen
LOGE("texture for FBO not found, name=%u\n", texture);
} else {
texture = tex->glname;
- // check if texture is shrinked...
- if (tex->shrink || tex->useratio || (tex->adjust && (hardext.npot==1 || hardext.npot==2) && !globals4es.potframebuffer)) {
+ tex->fbtex_ratio = (globals4es.fbtexscale > 0.0f) ? globals4es.fbtexscale : 0.0f;
+
+ // check if texture is shrinked or if fb texture is being scaled...
+ if (globals4es.fbtexscale > 0.0f || tex->shrink || tex->useratio || (tex->adjust && (hardext.npot==1 || hardext.npot==2) && !globals4es.potframebuffer)) {
LOGD("%s texture for FBO\n",(tex->useratio)?"going back to npot size pot'ed":"unshrinking shrinked");
if(tex->shrink || tex->useratio) {
if(tex->useratio) {
@@ -461,6 +463,13 @@ void APIENTRY_GL4ES gl4es_glFramebufferTexture2D(GLenum target, GLenum attachmen
tex->height *= 1<<tex->shrink;
}
}
+
+ // Use FBO Ratio
+ if (tex->fbtex_ratio > 0.0f) {
+ tex->width *= tex->fbtex_ratio;
+ tex->height *= tex->fbtex_ratio;
+ }
+
tex->nwidth = (hardext.npot>0 || hardext.esversion>1)?tex->width:npot(tex->width);
tex->nheight = (hardext.npot>0 || hardext.esversion>1)?tex->height:npot(tex->height);
tex->adjustxy[0] = (float)tex->width / tex->nwidth;
diff --git a/src/gl/init.c b/src/gl/init.c
index e7dc31ae..bc81924e 100644
--- a/src/gl/init.c
+++ b/src/gl/init.c
@@ -685,6 +685,10 @@ void initialize_gl4es() {
}
}
}
+
+ if(GetEnvVarFloat("LIBGL_FB_TEX_SCALE",&globals4es.fbtexscale,0.0f)) {
+ SHUT_LOGD("Framebuffer Textures will be scaled by %.2f\n", globals4es.fbtexscale);
+ }
}
diff --git a/src/gl/init.h b/src/gl/init.h
index 87d73139..bdfbbae9 100644
--- a/src/gl/init.h
+++ b/src/gl/init.h
@@ -74,6 +74,7 @@ typedef struct _globals4es {
int glxnative;
int normalize; // force normal normalization (workaround a bug)
int blitfb0;
+ float fbtexscale;
#ifndef NO_GBM
char drmcard[50];
#endif
diff --git a/src/gl/raster.c b/src/gl/raster.c
index 80260757..197dc836 100644
--- a/src/gl/raster.c
+++ b/src/gl/raster.c
@@ -59,6 +59,16 @@ void APIENTRY_GL4ES gl4es_glWindowPos3f(GLfloat x, GLfloat y, GLfloat z) {
}
void APIENTRY_GL4ES gl4es_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
+ if (glstate->fbo.current_fb->id != 0) {
+ gltexture_t *tex = gl4es_getTexture(glstate->fbo.current_fb->t_color[0], glstate->fbo.current_fb->color[0]);
+ if (tex->fbtex_ratio > 0.0f) {
+ width *= tex->fbtex_ratio;
+ height *= tex->fbtex_ratio;
+ x *= tex->fbtex_ratio;
+ y *= tex->fbtex_ratio;
+ }
+ }
+
if(!glstate->list.pending)
PUSH_IF_COMPILING(glViewport);
if( glstate->raster.viewport.x!=x ||
@@ -84,6 +94,16 @@ void APIENTRY_GL4ES gl4es_glViewport(GLint x, GLint y, GLsizei width, GLsizei he
}
void APIENTRY_GL4ES gl4es_glScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
+ if (glstate->fbo.current_fb->id != 0) {
+ gltexture_t *tex = gl4es_getTexture(glstate->fbo.current_fb->t_color[0], glstate->fbo.current_fb->color[0]);
+ if (tex->fbtex_ratio > 0.0f) {
+ width *= tex->fbtex_ratio;
+ height *= tex->fbtex_ratio;
+ x *= tex->fbtex_ratio;
+ y *= tex->fbtex_ratio;
+ }
+ }
+
if(!glstate->list.pending)
PUSH_IF_COMPILING(glScissor);
#ifdef AMIGAOS4
diff --git a/src/gl/texture.h b/src/gl/texture.h
index 4d4f27b4..4614a234 100644
--- a/src/gl/texture.h
+++ b/src/gl/texture.h
@@ -155,6 +155,7 @@ typedef struct {
GLvoid *data; // in case we want to keep a copy of it (it that case, always RGBA/GL_UNSIGNED_BYTE
glsampler_t sampler; // internal sampler if not superceeded by glBindSampler
glsampler_t actual; // actual sampler
+ float fbtex_ratio; // Lower rendering resolution
} gltexture_t;
KHASH_MAP_DECLARE_INT(tex, gltexture_t *);
--
2.11.0