24
24
#include "hw/xbox/nv2a/pgraph/swizzle.h"
25
25
#include "hw/xbox/nv2a/pgraph/s3tc.h"
26
26
#include "hw/xbox/nv2a/pgraph/texture.h"
27
+ #include "constants.h"
27
28
#include "debug.h"
28
29
#include "renderer.h"
30
+ #include <stdint.h>
29
31
30
- static TextureBinding * generate_texture (const TextureShape s , const uint8_t * texture_data , const uint8_t * palette_data );
32
+ static TextureBinding * generate_texture (const TextureShape s , const uint8_t * texture_data , const uint8_t * palette_data , uint32_t filter );
31
33
static void texture_binding_destroy (gpointer data );
32
34
33
35
struct pgraph_texture_possibly_dirty_struct {
@@ -343,7 +345,7 @@ void pgraph_gl_bind_textures(NV2AState *d)
343
345
344
346
if (key_out -> binding == NULL ) {
345
347
// Must create the texture
346
- key_out -> binding = generate_texture (state , texture_data , palette_data );
348
+ key_out -> binding = generate_texture (state , texture_data , palette_data , filter );
347
349
key_out -> binding -> data_hash = tex_data_hash ;
348
350
key_out -> binding -> scale = 1 ;
349
351
} else {
@@ -360,7 +362,7 @@ void pgraph_gl_bind_textures(NV2AState *d)
360
362
361
363
trace_nv2a_pgraph_surface_render_to_texture (
362
364
surface -> vram_addr , surface -> width , surface -> height );
363
- pgraph_gl_render_surface_to_texture (d , surface , binding , & state , i );
365
+ pgraph_gl_render_surface_to_texture (d , surface , binding , & state , i , filter );
364
366
binding -> draw_time = surface -> draw_time ;
365
367
binding -> scale = pg -> surface_scale_factor ;
366
368
}
@@ -403,9 +405,14 @@ gl_internal_format_to_s3tc_enum(GLint gl_internal_format)
403
405
static void upload_gl_texture (GLenum gl_target ,
404
406
const TextureShape s ,
405
407
const uint8_t * texture_data ,
406
- const uint8_t * palette_data )
408
+ const uint8_t * palette_data ,
409
+ uint32_t filter )
407
410
{
408
411
ColorFormatInfo f = kelvin_color_format_gl_map [s .color_format ];
412
+ uint32_t mask = kelvin_signed_format_mask_gl_map [s .color_format ];
413
+ if (mask && (filter & mask ) == mask )
414
+ f = kelvin_signed_color_format_gl_map [s .color_format ];
415
+
409
416
nv2a_profile_inc_counter (NV2A_PROF_TEX_UPLOAD );
410
417
411
418
unsigned int adjusted_width = s .width ;
@@ -620,9 +627,13 @@ static void upload_gl_texture(GLenum gl_target,
620
627
621
628
static TextureBinding * generate_texture (const TextureShape s ,
622
629
const uint8_t * texture_data ,
623
- const uint8_t * palette_data )
630
+ const uint8_t * palette_data ,
631
+ uint32_t filter )
624
632
{
625
633
ColorFormatInfo f = kelvin_color_format_gl_map [s .color_format ];
634
+ uint32_t mask = kelvin_signed_format_mask_gl_map [s .color_format ];
635
+ if (mask && (filter & mask ) == mask )
636
+ f = kelvin_signed_color_format_gl_map [s .color_format ];
626
637
627
638
/* Create a new opengl texture */
628
639
GLuint gl_texture ;
@@ -690,19 +701,19 @@ static TextureBinding* generate_texture(const TextureShape s,
690
701
length = (length + NV2A_CUBEMAP_FACE_ALIGNMENT - 1 ) & ~(NV2A_CUBEMAP_FACE_ALIGNMENT - 1 );
691
702
692
703
upload_gl_texture (GL_TEXTURE_CUBE_MAP_POSITIVE_X ,
693
- s , texture_data + 0 * length , palette_data );
704
+ s , texture_data + 0 * length , palette_data , filter );
694
705
upload_gl_texture (GL_TEXTURE_CUBE_MAP_NEGATIVE_X ,
695
- s , texture_data + 1 * length , palette_data );
706
+ s , texture_data + 1 * length , palette_data , filter );
696
707
upload_gl_texture (GL_TEXTURE_CUBE_MAP_POSITIVE_Y ,
697
- s , texture_data + 2 * length , palette_data );
708
+ s , texture_data + 2 * length , palette_data , filter );
698
709
upload_gl_texture (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y ,
699
- s , texture_data + 3 * length , palette_data );
710
+ s , texture_data + 3 * length , palette_data , filter );
700
711
upload_gl_texture (GL_TEXTURE_CUBE_MAP_POSITIVE_Z ,
701
- s , texture_data + 4 * length , palette_data );
712
+ s , texture_data + 4 * length , palette_data , filter );
702
713
upload_gl_texture (GL_TEXTURE_CUBE_MAP_NEGATIVE_Z ,
703
- s , texture_data + 5 * length , palette_data );
714
+ s , texture_data + 5 * length , palette_data , filter );
704
715
} else {
705
- upload_gl_texture (gl_target , s , texture_data , palette_data );
716
+ upload_gl_texture (gl_target , s , texture_data , palette_data , filter );
706
717
}
707
718
708
719
/* Linear textures don't support mipmapping */
0 commit comments