Skip to content

Commit 3ece4e2

Browse files
committed
nv2a: Implement texture LOD bias
Fixes #767
1 parent 234840d commit 3ece4e2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

hw/xbox/nv2a/pgraph/gl/renderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef struct TextureBinding {
8080
bool border_color_set;
8181
GLenum gl_target;
8282
GLuint gl_texture;
83+
uint32_t lod_bias;
8384
} TextureBinding;
8485

8586
typedef struct ShaderModuleCacheKey {

hw/xbox/nv2a/pgraph/gl/texture.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ static void apply_texture_parameters(TextureBinding *binding,
120120
unsigned int addru = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRU);
121121
unsigned int addrv = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRV);
122122
unsigned int addrp = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRP);
123+
unsigned int lod_bias =
124+
GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS);
123125

124126
if (f->linear) {
125127
/* somtimes games try to set mipmap min filters on linear textures.
@@ -146,6 +148,15 @@ static void apply_texture_parameters(TextureBinding *binding,
146148
pgraph_texture_mag_filter_gl_map[mag_filter]);
147149
binding->mag_filter = mag_filter;
148150
}
151+
if (lod_bias != binding->lod_bias) {
152+
binding->lod_bias = lod_bias;
153+
int sign_extended_bias = lod_bias;
154+
if (lod_bias & (1 << 12)) {
155+
sign_extended_bias |= ~NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS;
156+
}
157+
float gl_bias = (float)sign_extended_bias / 256.f;
158+
glTexParameterf(binding->gl_target, GL_TEXTURE_LOD_BIAS, gl_bias);
159+
}
149160

150161
/* Texture wrapping */
151162
assert(addru < ARRAY_SIZE(pgraph_texture_addr_gl_map));

0 commit comments

Comments
 (0)