Be more consistent with depth write enabling/disabling

This commit is contained in:
UnknownShadow200 2024-06-05 22:04:28 +10:00
parent 8800578b65
commit dfd12d8c9f
7 changed files with 37 additions and 51 deletions

View file

@ -402,29 +402,39 @@ void EntityNames_Render(void) {
}
void EntityNames_RenderHovered(void) {
struct LocalPlayer* p = Entities.CurPlayer;
struct LocalPlayer* p = Entities.CurPlayer;
struct Entity* e;
cc_bool allNames, hadFog;
cc_bool setupState = false;
int i;
if (Entities.NamesMode == NAME_MODE_NONE) return;
allNames = !(Entities.NamesMode == NAME_MODE_HOVERED || Entities.NamesMode == NAME_MODE_ALL)
&& p->Hacks.CanSeeAllNames;
Gfx_SetAlphaTest(true);
Gfx_SetDepthTest(false);
hadFog = Gfx_GetFog();
if (hadFog) Gfx_SetFog(false);
for (i = 0; i < ENTITIES_MAX_COUNT; i++)
{
if (!Entities.List[i]) continue;
if ((i == closestEntityId || allNames) && Entities.List[i] != &p->Base) {
DrawName(Entities.List[i]);
e = Entities.List[i];
if (!e || e == &p->Base) continue;
if (!allNames && i != closestEntityId) continue;
/* Only alter the GPU state when actually necessary */
if (!setupState) {
Gfx_SetAlphaTest(true);
Gfx_SetDepthTest(false);
Gfx_SetDepthWrite(false);
setupState = true;
hadFog = Gfx_GetFog();
if (hadFog) Gfx_SetFog(false);
}
DrawName(e);
}
if (!setupState) return;
Gfx_SetAlphaTest(false);
Gfx_SetDepthTest(true);
Gfx_SetDepthWrite(true);
if (hadFog) Gfx_SetFog(true);
}

View file

@ -212,9 +212,7 @@ static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
static cc_bool depth_write = true, depth_test = true;
static void UpdateDepthState(void) {
// match Desktop behaviour, where disabling depth testing also disables depth writing
// TODO do we actually need to & here?
GX_SetZMode(depth_test, GX_LEQUAL, depth_write & depth_test);
GX_SetZMode(depth_test, GX_LEQUAL, depth_write);
}
void Gfx_SetDepthWrite(cc_bool enabled) {

View file

@ -292,28 +292,19 @@ static void SetAlphaBlend(cc_bool enabled) {
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
void Gfx_ClearColor(PackedCol color) {
cc_uint32 R = PackedCol_R(color);
cc_uint32 G = PackedCol_G(color);
cc_uint32 B = PackedCol_B(color);
clearColor = B | (G << 8) | (R << 16) | (0xFF << 24);
}
cc_uint32 R = PackedCol_R(color);
cc_uint32 G = PackedCol_G(color);
cc_uint32 B = PackedCol_B(color);
static cc_bool depth_write = true, depth_test = true;
static void UpdateDepthState(void) {
// match Desktop behaviour, where disabling depth testing also disables depth writing
rsxSetDepthWriteEnable(context, depth_write & depth_test);
rsxSetDepthTestEnable(context, depth_test);
clearColor = B | (G << 8) | (R << 16) | (0xFF << 24);
}
void Gfx_SetDepthWrite(cc_bool enabled) {
depth_write = enabled;
UpdateDepthState();
rsxSetDepthWriteEnable(context, enabled);
}
void Gfx_SetDepthTest(cc_bool enabled) {
depth_test = enabled;
UpdateDepthState();
rsxSetDepthTestEnable(context, enabled);
}
static void SetAlphaTest(cc_bool enabled) {

View file

@ -993,34 +993,18 @@ static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
// TODO
}
static cc_bool depth_write = true, depth_test = true;
static void UpdateDepthWrite(void) {
// match Desktop behaviour, where disabling depth testing also disables depth writing
// TODO do we actually need to & here?
cc_bool enabled = depth_write & depth_test;
void Gfx_SetDepthWrite(cc_bool enabled) {
int mode = enabled ? SCE_GXM_DEPTH_WRITE_ENABLED : SCE_GXM_DEPTH_WRITE_DISABLED;
sceGxmSetFrontDepthWriteEnable(gxm_context, mode);
sceGxmSetBackDepthWriteEnable(gxm_context, mode);
}
static void UpdateDepthFunction(void) {
int func = depth_test ? SCE_GXM_DEPTH_FUNC_LESS_EQUAL : SCE_GXM_DEPTH_FUNC_ALWAYS;
void Gfx_SetDepthTest(cc_bool enabled) {
int func = enabled ? SCE_GXM_DEPTH_FUNC_LESS_EQUAL : SCE_GXM_DEPTH_FUNC_ALWAYS;
sceGxmSetFrontDepthFunc(gxm_context, func);
sceGxmSetBackDepthFunc(gxm_context, func);
}
void Gfx_SetDepthWrite(cc_bool enabled) {
depth_write = enabled;
UpdateDepthWrite();
}
void Gfx_SetDepthTest(cc_bool enabled) {
depth_test = enabled;
UpdateDepthWrite();
UpdateDepthFunction();
}
/*########################################################################################################################*
*---------------------------------------------------------Matrices--------------------------------------------------------*
@ -1116,8 +1100,7 @@ void Gfx_ClearBuffers(GfxBuffers buffers) {
clear_vertices[3] = (struct VertexColoured){-1.0f, 1.0f, 1.0f, clear_color };
Gfx_SetAlphaTest(false);
// can't use Gfx_SetDepthTest because that also affects depth writing
depth_test = false; UpdateDepthFunction();
Gfx_SetDepthTest(false);
Gfx_SetVertexFormat(VERTEX_FORMAT_COLOURED);
Gfx_LoadIdentityMatrix(MATRIX_VIEW);
@ -1125,6 +1108,6 @@ void Gfx_ClearBuffers(GfxBuffers buffers) {
Gfx_BindVb(clearVB);
Gfx_DrawVb_IndexedTris(4);
depth_test = true; UpdateDepthFunction();
Gfx_SetDepthTest(true);
}
#endif

View file

@ -339,8 +339,8 @@ static void DrawTriangle(Vertex* V0, Vertex* V1, Vertex* V2) {
}
// Reject triangles completely outside
if ((minX < 0 && maxX < 0) || (minX > fb_maxX && maxX > fb_maxX)) return;
if ((minY < 0 && maxY < 0) || (minY > fb_maxY && maxY > fb_maxY)) return;
if (maxX < 0 || minX > fb_maxX) return;
if (maxY < 0 || minY > fb_maxY) return;
// Perform scissoring
minX = max(minX, 0); maxX = min(maxX, fb_maxX);

View file

@ -36,6 +36,7 @@ static void HeldBlockRenderer_RenderModel(void) {
Gfx_SetFaceCulling(true);
Gfx_SetDepthTest(false);
Gfx_SetDepthWrite(false);
/* TODO: Need to properly reallocate per model VB here */
if (Blocks.Draw[held_block] == DRAW_GAS) {
@ -56,6 +57,7 @@ static void HeldBlockRenderer_RenderModel(void) {
}
Gfx_SetDepthTest(true);
Gfx_SetDepthWrite(true);
Gfx_SetFaceCulling(false);
}

View file

@ -284,6 +284,7 @@ void Gfx_Begin2D(int width, int height) {
Gfx_LoadIdentityMatrix(MATRIX_VIEW);
Gfx_SetDepthTest(false);
Gfx_SetDepthWrite(false);
Gfx_SetAlphaBlending(true);
gfx_hadFog = Gfx_GetFog();
@ -293,6 +294,7 @@ void Gfx_Begin2D(int width, int height) {
void Gfx_End2D(void) {
Gfx_SetDepthTest(true);
Gfx_SetDepthWrite(true);
Gfx_SetAlphaBlending(false);
if (gfx_hadFog) Gfx_SetFog(true);