diff --git a/hw/xbox/nv2a/pgraph.c b/hw/xbox/nv2a/pgraph.c index 9d9247feca..a134a2a661 100644 --- a/hw/xbox/nv2a/pgraph.c +++ b/hw/xbox/nv2a/pgraph.c @@ -28,6 +28,9 @@ #include "ui/xemu-settings.h" #include "qemu/fast-hash.h" +const float f16_max = 511.9375f; +const float f24_max = 1.0E30; + static NV2AState *g_nv2a; GloContext *g_nv2a_context_render; GloContext *g_nv2a_context_display; @@ -3493,10 +3496,6 @@ DEF_METHOD(NV097, CLEAR_SURFACE) GLint gl_clear_stencil; GLfloat gl_clear_depth; - /* FIXME: Put these in some lookup table */ - const float f16_max = 511.9375f; - const float f24_max = 1.0E30; - switch(pg->surface_shape.zeta_format) { case NV097_SET_SURFACE_FORMAT_ZETA_Z16: { uint16_t z = clear_zstencil & 0xFFFF; @@ -4180,8 +4179,18 @@ static void pgraph_shader_update_constants(PGRAPHState *pg, *(float*)&pg->regs[NV_PGRAPH_FOGPARAM1]); } - float zclip_max = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMAX]; - float zclip_min = *(float*)&pg->regs[NV_PGRAPH_ZCLIPMIN]; + /* FIXME: Handle NV_PGRAPH_ZCLIPMIN, NV_PGRAPH_ZCLIPMAX */ + float zmax; + switch (pg->surface_shape.zeta_format) { + case NV097_SET_SURFACE_FORMAT_ZETA_Z16: + zmax = pg->surface_shape.z_format ? f16_max : (float)0xFFFF; + break; + case NV097_SET_SURFACE_FORMAT_ZETA_Z24S8: + zmax = pg->surface_shape.z_format ? f24_max : (float)0xFFFFFF; + break; + default: + assert(0); + } if (fixed_function) { /* update lighting constants */ @@ -4238,19 +4247,15 @@ static void pgraph_shader_update_constants(PGRAPHState *pg, float m11 = 0.5 * (pg->surface_binding_dim.width/aa_width); float m22 = -0.5 * (pg->surface_binding_dim.height/aa_height); - float m33 = zclip_max - zclip_min; + float m33 = zmax; float m41 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][0]; float m42 = *(float*)&pg->vsh_constants[NV_IGRAPH_XF_XFCTX_VPOFF][1]; - float m43 = zclip_min; - if (m33 == 0.0) { - m33 = 1.0; - } float invViewport[16] = { 1.0/m11, 0, 0, 0, 0, 1.0/m22, 0, 0, 0, 0, 1.0/m33, 0, - -1.0+m41/m11, 1.0+m42/m22, -m43/m33, 1.0 + -1.0+m41/m11, 1.0+m42/m22, 0, 1.0 }; if (binding->inv_viewport_loc != -1) { @@ -4284,7 +4289,7 @@ static void pgraph_shader_update_constants(PGRAPHState *pg, } if (binding->clip_range_loc != -1) { - glUniform2f(binding->clip_range_loc, zclip_min, zclip_max); + glUniform2f(binding->clip_range_loc, 0, zmax); } /* Clipping regions */