Skip to content

Commit

Permalink
Fix a bug that Legacy OpenGL matrix was corrupted. #399
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Feb 6, 2024
1 parent 5e1979a commit 3bad456
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7451,6 +7451,7 @@ static hook_t *g_phook_Mod_LoadBrushModel = NULL;
static hook_t *g_phook_Mod_UnloadSpriteTextures = NULL;
static hook_t *g_phook_triapi_RenderMode = NULL;
static hook_t *g_phook_triapi_BoxInPVS = NULL;
static hook_t* g_phook_triapi_GetMatrix = NULL;
//static hook_t *g_phook_triapi_Color4f = NULL;
static hook_t *g_phook_Draw_MiptexTexture = NULL;
static hook_t *g_phook_BuildGammaTable = NULL;
Expand Down Expand Up @@ -7493,6 +7494,7 @@ void R_UninstallHooksForEngineDLL(void)
Uninstall_Hook(Mod_UnloadSpriteTextures);
Uninstall_Hook(triapi_RenderMode);
Uninstall_Hook(triapi_BoxInPVS);
Uninstall_Hook(triapi_GetMatrix);
Uninstall_Hook(Draw_MiptexTexture);
Uninstall_Hook(BuildGammaTable);
Uninstall_Hook(R_CullBox);
Expand Down Expand Up @@ -7538,6 +7540,7 @@ void R_InstallHooks(void)
Install_InlineHook(Mod_UnloadSpriteTextures);
Install_InlineHook(triapi_RenderMode);
Install_InlineHook(triapi_BoxInPVS);
Install_InlineHook(triapi_GetMatrix);
Install_InlineHook(Draw_MiptexTexture);
Install_InlineHook(BuildGammaTable);
Install_InlineHook(R_CullBox);
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ void GL_DisableMultitexture(void);
void GL_EnableMultitexture(void);
void triapi_RenderMode(int mode);
int triapi_BoxInPVS(float* mins, float* maxs);
void triapi_GetMatrix(const int pname, float* matrix);
//void triapi_Color4f(float x, float y, float z, float w);
void GL_UnloadTextureByIdentifier(const char* identifier, bool notify_callback);
void GL_UnloadTextures(void);
Expand Down
28 changes: 22 additions & 6 deletions Plugins/Renderer/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,22 @@ mbasenode_t* R_PVSNode(mbasenode_t* basenode, vec3_t emins, vec3_t emaxs)
return NULL;
}

void triapi_GetMatrix(const int pname, float* matrix)
{
if (pname == GL_MODELVIEW_MATRIX)
{
memcpy(matrix, r_world_matrix, sizeof(float[16]));
return;
}
else if (pname == GL_PROJECTION_MATRIX)
{
memcpy(matrix, r_projection_matrix, sizeof(float[16]));
return;
}

return gPrivateFuncs.triapi_GetMatrix(pname, matrix);
}

int triapi_BoxInPVS(float* mins, float* maxs)
{
return R_PVSNode(r_worldmodel->nodes, mins, maxs) != NULL;
Expand Down Expand Up @@ -2920,23 +2936,23 @@ void R_AdjustScopeFOVForViewModel(float *fov)
}
}

void R_UseLegacyOpenGLMatrixForViewModel()
void R_LoadLegacyOpenGLMatrixForViewModel()
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(r_viewmodel_projection_matrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(r_world_matrix);
}

void R_UseLegacyOpenGLMatrixForWorld()
void R_LoadLegacyOpenGLMatrixForWorld()
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(r_projection_matrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(r_world_matrix);
}

void R_UseProjMatrixForViewModel(void)
void R_UploadProjMatrixForViewModel(void)
{
scene_ubo_t SceneUBO;
memcpy(SceneUBO.projMatrix, r_viewmodel_projection_matrix, sizeof(mat4));
Expand All @@ -2956,7 +2972,7 @@ void R_UseProjMatrixForViewModel(void)
}
}

void R_UseProjMatrixForWorld(void)
void R_LoadProjMatrixForWorld(void)
{
scene_ubo_t SceneUBO;
memcpy(SceneUBO.projMatrix, r_projection_matrix, sizeof(mat4));
Expand Down Expand Up @@ -3025,7 +3041,7 @@ void R_SetupGLForViewModel(void)

InvertMatrix(r_viewmodel_projection_matrix, r_viewmodel_projection_matrix_inv);

R_UseProjMatrixForViewModel();
R_UploadProjMatrixForViewModel();
}
}

Expand Down Expand Up @@ -3543,7 +3559,7 @@ void R_EndRenderOpaque(void)
}

//For backward compatibility, some Mods may use Legacy OpenGL 1.x Matrix
R_UseLegacyOpenGLMatrixForWorld();
R_LoadLegacyOpenGLMatrixForWorld();
}

void ClientDLL_DrawNormalTriangles(void)
Expand Down

0 comments on commit 3bad456

Please sign in to comment.