mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
Only fill in gpu info when /client gpuinfo is actually called, instead of always filling it at gfx init
This commit is contained in:
parent
fc58658e58
commit
e709ce33f2
14
src/Chat.c
14
src/Chat.c
@ -339,12 +339,18 @@ static struct ChatCommand HelpCommand = {
|
||||
};
|
||||
|
||||
static void GpuInfoCommand_Execute(const String* args, int argsCount) {
|
||||
char linesBuffer[GFX_APIINFO_LINES][STRING_SIZE];
|
||||
String lines[GFX_APIINFO_LINES];
|
||||
int i;
|
||||
Gfx_UpdateApiInfo();
|
||||
|
||||
for (i = 0; i < Array_Elems(Gfx_ApiInfo); i++) {
|
||||
if (!Gfx_ApiInfo[i].length) continue;
|
||||
Chat_Add1("&a%s", &Gfx_ApiInfo[i]);
|
||||
for (i = 0; i < GFX_APIINFO_LINES; i++) {
|
||||
String_InitArray(lines[i], linesBuffer[i]);
|
||||
}
|
||||
Gfx_GetApiInfo(lines);
|
||||
|
||||
for (i = 0; i < GFX_APIINFO_LINES; i++) {
|
||||
if (!lines[i].length) continue;
|
||||
Chat_Add1("&a%s", &lines[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,6 @@ static void Game_Load(void) {
|
||||
Game_Fov = 70;
|
||||
|
||||
Gfx_Init();
|
||||
Gfx_MakeApiInfo();
|
||||
Gfx.Mipmaps = Options_GetBool(OPT_MIPMAPS, false);
|
||||
|
||||
Game_UpdateDimensions();
|
||||
|
@ -299,6 +299,7 @@ static IDirect3D9* d3d;
|
||||
static IDirect3DDevice9* device;
|
||||
static DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
|
||||
static D3DFORMAT gfx_viewFormat, gfx_depthFormat;
|
||||
static float totalMem;
|
||||
|
||||
#define D3D9_SetRenderState(state, value, name) \
|
||||
ReturnCode res = IDirect3DDevice9_SetRenderState(device, state, value); if (res) Logger_Abort2(res, name);
|
||||
@ -390,6 +391,7 @@ void Gfx_Init(void) {
|
||||
Gfx.MaxTexHeight = caps.MaxTextureHeight;
|
||||
Gfx.CustomMipmapsLevels = true;
|
||||
Gfx_RestoreState();
|
||||
totalMem = IDirect3DDevice9_GetAvailableTextureMem(device) / (1024.0f * 1024.0f);
|
||||
}
|
||||
|
||||
bool Gfx_TryRestoreContext(void) {
|
||||
@ -931,27 +933,21 @@ static const int D3D9_DepthBufferBts(D3DFORMAT format) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static float gfx_totalMem;
|
||||
void Gfx_MakeApiInfo(void) {
|
||||
void Gfx_GetApiInfo(String* lines) {
|
||||
D3DADAPTER_IDENTIFIER9 adapter = { 0 };
|
||||
int pointerSize = sizeof(void*) * 8;
|
||||
int depthBits = D3D9_DepthBufferBts(gfx_depthFormat);
|
||||
float curMem;
|
||||
|
||||
IDirect3D9_GetAdapterIdentifier(d3d, D3DADAPTER_DEFAULT, 0, &adapter);
|
||||
gfx_totalMem = IDirect3DDevice9_GetAvailableTextureMem(device) / (1024.0f * 1024.0f);
|
||||
curMem = IDirect3DDevice9_GetAvailableTextureMem(device) / (1024.0f * 1024.0f);
|
||||
|
||||
String_Format1(&Gfx_ApiInfo[0], "-- Using Direct3D9 (%i bit) --", &pointerSize);
|
||||
String_Format1(&Gfx_ApiInfo[1], "Adapter: %c", adapter.Description);
|
||||
String_Format1(&Gfx_ApiInfo[2], "Processing mode: %c", D3D9_StrFlags());
|
||||
Gfx_UpdateApiInfo();
|
||||
String_Format2(&Gfx_ApiInfo[4], "Max texture size: (%i, %i)", &Gfx.MaxTexWidth, &Gfx.MaxTexHeight);
|
||||
String_Format1(&Gfx_ApiInfo[5], "Depth buffer bits: %i", &depthBits);
|
||||
}
|
||||
|
||||
void Gfx_UpdateApiInfo(void) {
|
||||
float mem = IDirect3DDevice9_GetAvailableTextureMem(device) / (1024.0f * 1024.0f);
|
||||
Gfx_ApiInfo[3].length = 0;
|
||||
String_Format2(&Gfx_ApiInfo[3], "Video memory: %f2 MB total, %f2 free", &gfx_totalMem, &mem);
|
||||
String_Format1(&lines[0], "-- Using Direct3D9 (%i bit) --", &pointerSize);
|
||||
String_Format1(&lines[1], "Adapter: %c", adapter.Description);
|
||||
String_Format1(&lines[2], "Processing mode: %c", D3D9_StrFlags());
|
||||
String_Format2(&lines[3], "Video memory: %f2 MB total, %f2 free", &totalMem, &curMem);
|
||||
String_Format2(&lines[4], "Max texture size: (%i, %i)", &Gfx.MaxTexWidth, &Gfx.MaxTexHeight);
|
||||
String_Format1(&lines[5], "Depth buffer bits: %i", &depthBits);
|
||||
}
|
||||
|
||||
void Gfx_OnWindowResize(void) {
|
||||
@ -1243,37 +1239,32 @@ ReturnCode Gfx_TakeScreenshot(struct Stream* output) {
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool nv_mem;
|
||||
void Gfx_MakeApiInfo(void) {
|
||||
void Gfx_GetApiInfo(String* lines) {
|
||||
static const String memExt = String_FromConst("GL_NVX_gpu_memory_info");
|
||||
/* NOTE: glGetString actually returns UTF8, but I just treat it as code page 437 */
|
||||
String extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));
|
||||
int totalKb, curKb;
|
||||
float total, cur;
|
||||
String extensions;
|
||||
int depthBits, pointerSize = sizeof(void*) * 8;
|
||||
|
||||
nv_mem = String_CaselessContains(&extensions, &memExt);
|
||||
glGetIntegerv(GL_DEPTH_BITS, &depthBits);
|
||||
|
||||
String_Format1(&Gfx_ApiInfo[0], "-- Using OpenGL (%i bit) --", &pointerSize);
|
||||
String_Format1(&Gfx_ApiInfo[1], "Vendor: %c", glGetString(GL_VENDOR));
|
||||
String_Format1(&Gfx_ApiInfo[2], "Renderer: %c", glGetString(GL_RENDERER));
|
||||
String_Format1(&Gfx_ApiInfo[3], "GL version: %c", glGetString(GL_VERSION));
|
||||
String_Format1(&lines[0], "-- Using OpenGL (%i bit) --", &pointerSize);
|
||||
String_Format1(&lines[1], "Vendor: %c", glGetString(GL_VENDOR));
|
||||
String_Format1(&lines[2], "Renderer: %c", glGetString(GL_RENDERER));
|
||||
String_Format1(&lines[3], "GL version: %c", glGetString(GL_VERSION));
|
||||
/* Memory usage line goes here */
|
||||
String_Format2(&Gfx_ApiInfo[5], "Max texture size: (%i, %i)", &Gfx.MaxTexWidth, &Gfx.MaxTexHeight);
|
||||
String_Format1(&Gfx_ApiInfo[6], "Depth buffer bits: %i", &depthBits);
|
||||
}
|
||||
String_Format2(&lines[5], "Max texture size: (%i, %i)", &Gfx.MaxTexWidth, &Gfx.MaxTexHeight);
|
||||
String_Format1(&lines[6], "Depth buffer bits: %i", &depthBits);
|
||||
|
||||
void Gfx_UpdateApiInfo(void) {
|
||||
int totalKb = 0, curKb = 0;
|
||||
float total, cur;
|
||||
/* NOTE: glGetString returns UTF8, but I just treat it as code page 437 */
|
||||
extensions = String_FromReadonly((const char*)glGetString(GL_EXTENSIONS));
|
||||
if (!String_CaselessContains(&extensions, &memExt)) return;
|
||||
|
||||
if (!nv_mem) return;
|
||||
glGetIntegerv(0x9048, &totalKb);
|
||||
glGetIntegerv(0x9049, &curKb);
|
||||
if (totalKb <= 0 || curKb <= 0) return;
|
||||
|
||||
total = totalKb / 1024.0f; cur = curKb / 1024.0f;
|
||||
Gfx_ApiInfo[4].length = 0;
|
||||
String_Format2(&Gfx_ApiInfo[4], "Video memory: %f2 MB total, %f2 free", &total, &cur);
|
||||
String_Format2(&lines[4], "Video memory: %f2 MB total, %f2 free", &total, &cur);
|
||||
}
|
||||
|
||||
bool Gfx_WarnIfNecessary(void) {
|
||||
@ -1555,7 +1546,6 @@ static void Gfx_SwitchProgram(void) {
|
||||
if (gfx_texTransform) index += 2;
|
||||
if (gfx_alphaTest) index += 1;
|
||||
|
||||
|
||||
shader = &shaders[index];
|
||||
if (shader == gfx_activeShader) { Gfx_ReloadUniforms(); return; }
|
||||
if (!shader->program) Gfx_CompileProgram(shader);
|
||||
|
@ -37,7 +37,7 @@ CC_VAR extern struct _GfxData {
|
||||
struct Matrix View, Projection;
|
||||
} Gfx;
|
||||
|
||||
extern String Gfx_ApiInfo[7];
|
||||
#define GFX_APIINFO_LINES 7
|
||||
extern GfxResourceID Gfx_defaultIb;
|
||||
extern GfxResourceID Gfx_quadVb, Gfx_texVb;
|
||||
|
||||
@ -150,11 +150,10 @@ void Gfx_SetFpsLimit(bool value, float minFrameMillis);
|
||||
/* Updates state when the window's dimensions have changed. */
|
||||
/* NOTE: This may require recreating the context depending on the backend. */
|
||||
void Gfx_OnWindowResize(void);
|
||||
/* Fills Gfx_ApiInfo with information about the backend state and the user's GPU. */
|
||||
void Gfx_MakeApiInfo(void);
|
||||
/* Updates Gfx_ApiInfo with current backend state information. */
|
||||
/* NOTE: This updates information such as current free memory, etc. */
|
||||
void Gfx_UpdateApiInfo(void);
|
||||
/* Gets information about the user's GPU and current backend state. */
|
||||
/* Backend state may be depth buffer bits, current free memory, etc. */
|
||||
/* NOTE: lines must be an array of at least GFX_APIINFO_LINES */
|
||||
void Gfx_GetApiInfo(String* lines);
|
||||
|
||||
/* Raises ContextLost event and updates state for lost contexts. */
|
||||
void Gfx_LoseContext(const char* reason);
|
||||
|
Loading…
x
Reference in New Issue
Block a user