mirror of https://github.com/xemu-project/xemu.git
Respect surface format for zeta clears
This commit is contained in:
parent
f90a4cb5f9
commit
e754087e18
|
@ -2002,6 +2002,22 @@ static GraphicsObject* lookup_graphics_object(PGRAPHState *s,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 16 bit to [0.0, F16_MAX = 511.9375] */
|
||||||
|
static float convert_f16_to_float(uint16_t f16) {
|
||||||
|
if (f16 == 0x0000) { return 0.0; }
|
||||||
|
uint32_t i = (f16 << 11) + 0x3C000000;
|
||||||
|
return *(float*)&i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 24 bit to [0.0, F24_MAX] */
|
||||||
|
static float convert_f24_to_float(uint32_t f24) {
|
||||||
|
assert(!(f24 >> 24));
|
||||||
|
f24 &= 0xFFFFFF;
|
||||||
|
if (f24 == 0x000000) { return 0.0; }
|
||||||
|
uint32_t i = f24 << 7;
|
||||||
|
return *(float*)&i;
|
||||||
|
}
|
||||||
|
|
||||||
static void pgraph_update_memory_buffer(NV2AState *d, hwaddr addr, hwaddr size,
|
static void pgraph_update_memory_buffer(NV2AState *d, hwaddr addr, hwaddr size,
|
||||||
bool f)
|
bool f)
|
||||||
{
|
{
|
||||||
|
@ -5700,18 +5716,39 @@ static void pgraph_method(NV2AState *d,
|
||||||
uint32_t clear_zstencil =
|
uint32_t clear_zstencil =
|
||||||
d->pgraph.regs[NV_PGRAPH_ZSTENCILCLEARVALUE];
|
d->pgraph.regs[NV_PGRAPH_ZSTENCILCLEARVALUE];
|
||||||
GLint gl_clear_stencil;
|
GLint gl_clear_stencil;
|
||||||
GLdouble gl_clear_depth;
|
GLfloat gl_clear_depth;
|
||||||
|
|
||||||
|
/* FIXME: Put these in some lookup table */
|
||||||
|
const float f16_max = 511.9375f;
|
||||||
|
/* FIXME: 7 bits of mantissa unused. maybe use full buffer? */
|
||||||
|
const float f24_max = 3.4027977E38;
|
||||||
|
|
||||||
switch(pg->surface_shape.zeta_format) {
|
switch(pg->surface_shape.zeta_format) {
|
||||||
case NV097_SET_SURFACE_FORMAT_ZETA_Z16:
|
case NV097_SET_SURFACE_FORMAT_ZETA_Z16: {
|
||||||
/* FIXME: Remove bit for stencil clear? */
|
uint16_t z = clear_zstencil & 0xFFFF;
|
||||||
gl_clear_depth = (clear_zstencil & 0xFFFF) / (double)0xFFFF;
|
/* FIXME: Remove bit for stencil clear? */
|
||||||
break;
|
if (pg->surface_shape.z_format) {
|
||||||
case NV097_SET_SURFACE_FORMAT_ZETA_Z24S8:
|
gl_clear_depth = convert_f16_to_float(z) / f16_max;
|
||||||
gl_clear_stencil = clear_zstencil & 0xFF;
|
assert(false); /* FIXME: Untested */
|
||||||
gl_clear_depth = (clear_zstencil >> 8) / (double)0xFFFFFF;
|
} else {
|
||||||
break;
|
gl_clear_depth = z / (float)0xFFFF;
|
||||||
default:
|
}
|
||||||
assert(0);
|
break;
|
||||||
|
}
|
||||||
|
case NV097_SET_SURFACE_FORMAT_ZETA_Z24S8: {
|
||||||
|
gl_clear_stencil = clear_zstencil & 0xFF;
|
||||||
|
uint32_t z = clear_zstencil >> 8;
|
||||||
|
if (pg->surface_shape.z_format) {
|
||||||
|
gl_clear_depth = convert_f24_to_float(z) / f24_max;
|
||||||
|
assert(false); /* FIXME: Untested */
|
||||||
|
} else {
|
||||||
|
gl_clear_depth = z / (float)0xFFFFFF;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (parameter & NV097_CLEAR_SURFACE_Z) {
|
if (parameter & NV097_CLEAR_SURFACE_Z) {
|
||||||
gl_mask |= GL_DEPTH_BUFFER_BIT;
|
gl_mask |= GL_DEPTH_BUFFER_BIT;
|
||||||
|
|
Loading…
Reference in New Issue