From 2af53ce087a880c63a43f1e498b64488a0d25846 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Fri, 24 Jul 2020 22:51:09 +1000 Subject: [PATCH] Novidia: make use of glTexImage1D or glTexSubImage1D configurable --- .../source/plugins/Novidia/src/dllmain.cpp | 63 +++++++++---------- .../source/plugins/Novidia/src/framework.h | 8 +-- .../source/plugins/Novidia/src/glStuff.h | 2 + 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/source-code/source/plugins/Novidia/src/dllmain.cpp b/source-code/source/plugins/Novidia/src/dllmain.cpp index 3d3d1a5..553a115 100644 --- a/source-code/source/plugins/Novidia/src/dllmain.cpp +++ b/source-code/source/plugins/Novidia/src/dllmain.cpp @@ -4,44 +4,26 @@ // upload to the SSBO instead after processing -void h_uploadModelTransformBuf(DWORD* a1, int a2) +// two versions because apparently TexSubImage can cause major stuttering +void h_uploadModelTransformBuf_TexImage(DWORD* a1, int a2) { uploadModelTransformBuf(a1, a2); + glActiveTexture(GL_TEXTURE8); + glBindTexture(GL_TEXTURE_1D, buf_tex); + glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 0x3000 / sizeof(float) / 4, 0, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330); + glActiveTexture(GL_TEXTURE0); +} +void h_uploadModelTransformBuf_TexSubImage(DWORD* a1, int a2) +{ + uploadModelTransformBuf(a1, a2); + glActiveTexture(GL_TEXTURE8); glBindTexture(GL_TEXTURE_1D, buf_tex); glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 0x3000 / sizeof(float) / 4, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330); glActiveTexture(GL_TEXTURE0); } -/* -void h_glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) -{ - if (performTransform) - { - glActiveTexture(GL_TEXTURE8); - glBindTexture(GL_TEXTURE_1D, buf_tex); - //glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 0x3000 / sizeof(float) / 4, 0, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330); - glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 0x3000 / sizeof(float) / 4, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330); - //glActiveTexture(GL_TEXTURE0); - } - glDrawElements(mode, count, type, indices); -} - -void h_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void* indices) -{ - if (performTransform) - { - glActiveTexture(GL_TEXTURE8); - glBindTexture(GL_TEXTURE_1D, buf_tex); - //glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 0x3000 / sizeof(float) / 4, 0, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330); - glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 0x3000 / sizeof(float) / 4, GL_RGBA, GL_FLOAT, *(float**)0x1411a3330); - //glActiveTexture(GL_TEXTURE0); - } - glDrawRangeElements(mode,start, end, count, type, indices); -} -*/ - // just a crash fix void h_glBindBuffer(GLenum target, GLuint buffer) { @@ -106,7 +88,8 @@ void h_glutSetCursor(int cursor) glGenTextures(1, &buf_tex); printf("[Novidia] Buffer texture id: %d\n", buf_tex); glBindTexture(GL_TEXTURE_1D, buf_tex); - glTexStorage1D(GL_TEXTURE_1D, 1, GL_RGBA32F, 0x3000 / sizeof(float) / 4); + if (use_TexSubImage) + glTexStorage1D(GL_TEXTURE_1D, 1, GL_RGBA32F, 0x3000 / sizeof(float) / 4); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -127,7 +110,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv if (ul_reason_for_call == DLL_PROCESS_ATTACH) { - //loadConfig(); + loadConfig(); DisableThreadLibraryCalls(hModule); @@ -135,10 +118,15 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv DetourUpdateThread(GetCurrentThread()); printf("[Novidia] Hooking glutSetCursor\n"); DetourAttach(&(PVOID&)glutSetCursor, h_glutSetCursor); - printf("[Novidia] Hooking uploadModelTransformBuf\n"); - DetourAttach(&(PVOID&)uploadModelTransformBuf, h_uploadModelTransformBuf); printf("[Novidia] Hooking wglGetProcAddress\n"); DetourAttach(&(PVOID&)wGlGetProcAddress_forhook, h_wglGetProcAddress); + + printf("[Novidia] Hooking uploadModelTransformBuf\n"); + if (use_TexSubImage) + DetourAttach(&(PVOID&)uploadModelTransformBuf, h_uploadModelTransformBuf_TexSubImage); + else + DetourAttach(&(PVOID&)uploadModelTransformBuf, h_uploadModelTransformBuf_TexImage); + DetourTransactionCommit(); } @@ -149,6 +137,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv using namespace PluginConfig; +PluginConfigOption config[] = { + { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"use_TexSubImage", L"general", CONFIG_FILE, L"Use glTexSubImage", L"glTexSubImage should offer higher performance, but stuttering has been reported when it is used.\nTry disabling this if you have issues.", true, false } }, +}; + extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) { return L"Novidia"; @@ -157,4 +149,9 @@ extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) { return L"Novidia by somewhatlurker\n\nPerforms some model skinning transformations in an alternate way to enable functionality on non-Nvidia hardware.\nAlso fixes crashing on non-Nvidia hardware."; +} + +extern "C" __declspec(dllexport) PluginConfigArray GetPluginOptions(void) +{ + return PluginConfigArray{ _countof(config), config }; } \ No newline at end of file diff --git a/source-code/source/plugins/Novidia/src/framework.h b/source-code/source/plugins/Novidia/src/framework.h index 1929848..4f7c123 100644 --- a/source-code/source/plugins/Novidia/src/framework.h +++ b/source-code/source/plugins/Novidia/src/framework.h @@ -24,7 +24,8 @@ bool checkBufferTargetOk(GLenum target) int __stdcall stub() { return 1; } -/* +bool use_TexSubImage; + std::wstring ExePath() { WCHAR buffer[MAX_PATH]; GetModuleFileNameW(NULL, buffer, MAX_PATH); @@ -43,6 +44,5 @@ LPCWSTR CONFIG_FILE = CONFIG_FILE_STRING.c_str(); void loadConfig() { - -} -*/ \ No newline at end of file + use_TexSubImage = GetPrivateProfileIntW(L"general", L"use_TexSubImage", 1, CONFIG_FILE) > 0 ? true : false; +} \ No newline at end of file diff --git a/source-code/source/plugins/Novidia/src/glStuff.h b/source-code/source/plugins/Novidia/src/glStuff.h index bbb1864..00a6153 100644 --- a/source-code/source/plugins/Novidia/src/glStuff.h +++ b/source-code/source/plugins/Novidia/src/glStuff.h @@ -54,6 +54,7 @@ typedef char GLchar; void(__cdecl* glGenTextures)(GLsizei n, GLuint* textures) = *(void(__cdecl**)(GLsizei, GLuint*))0x140965ad8; void(__cdecl* glBindTexture)(GLenum target, GLuint texture) = *(void(__cdecl**)(GLenum, GLuint))0x140965bf8; void(__cdecl* glTexParameteri)(GLenum target, GLenum pname, GLint param) = *(void(__cdecl**)(GLenum, GLenum, GLint))0x140965a18; +void(__cdecl* glTexImage1D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void* data) = *(void(__cdecl**)(GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, const void*))0x140965b58; void(__cdecl* glTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void* pixels) = (void(__cdecl*)(GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const void*))GetProcAddress(ogl32, "glTexSubImage1D"); // these are all imported using wglGetProcAddress and can't be initialised until after the OpenGL context is created @@ -73,6 +74,7 @@ struct { {&glGenTextures, "glGenTextures", false}, {&glBindTexture, "glBindTexture", false}, {&glTexParameteri, "glTexParameteri", false}, + {&glTexImage1D, "glTexImage1D", false}, {&glTexSubImage1D, "glTexSubImage1D", false}, {&glActiveTexture, "glActiveTexture", true}, {&glTexStorage1D, "glTexStorage1D", true},