Skip to content

Commit

Permalink
[OpenGL] Improve getSuggestedDefaultDepthBufferResolution()
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 17, 2023
1 parent cab2613 commit 69e0f3f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/framework/wzapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ enum DialogType {
WZ_DECL_NONNULL(2, 3) void wzDisplayDialog(DialogType type, const char *title, const char *message); ///< Throw up a modal warning dialog - title & message are UTF-8 text

WzString wzGetPlatform();
uint32_t wzGetSystemRAM(); // in MiB
std::vector<screeninfo> wzAvailableResolutions();
screeninfo wzGetCurrentFullscreenDisplayMode();
std::vector<unsigned int> wzAvailableDisplayScales();
Expand Down
41 changes: 29 additions & 12 deletions lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "lib/framework/frame.h"
#include "lib/framework/wzapp.h"
#include "screen.h"
#include "gfx_api_gl.h"
#include "lib/exceptionhandler/dumpinfo.h"
Expand Down Expand Up @@ -61,6 +62,8 @@ PFNGLDRAWARRAYSINSTANCEDPROC wz_dyn_glDrawArraysInstanced = nullptr;
PFNGLDRAWELEMENTSINSTANCEDPROC wz_dyn_glDrawElementsInstanced = nullptr;
PFNGLVERTEXATTRIBDIVISORPROC wz_dyn_glVertexAttribDivisor = nullptr;

static const GLubyte* wzSafeGlGetString(GLenum name);

static GLenum to_gl_internalformat(const gfx_api::pixel_format& format, bool gles)
{
switch (format)
Expand Down Expand Up @@ -2968,7 +2971,7 @@ static void GLAPIENTRY khr_callback(GLenum source, GLenum type, GLuint id, GLenu
debug(log_level, "GL::%s(%s:%s) : %s", cbsource(source), cbtype(type), cbseverity(severity), (message != nullptr) ? message : "");
}

optional<uint32_t> gl_context::getSuggestedDefaultDepthBufferResolution() const
uint32_t gl_context::getSuggestedDefaultDepthBufferResolution() const
{
// Use a (very simple) heuristic, that may or may not be useful - but basically try to find graphics cards that have lots of memory...
if (GLAD_GL_NVX_gpu_memory_info)
Expand All @@ -2991,25 +2994,39 @@ optional<uint32_t> gl_context::getSuggestedDefaultDepthBufferResolution() const
// For GL_ATI_meminfo, get the current free texture memory (stats_kb[0])
GLint stats_kb[4] = {0, 0, 0, 0};
glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, stats_kb);
if (stats_kb[0] <= 0)
if (stats_kb[0] > 0)
{
return nullopt;
}
uint32_t currentFreeTextureMemory_mb = static_cast<uint32_t>(stats_kb[0] / 1024);
uint32_t currentFreeTextureMemory_mb = static_cast<uint32_t>(stats_kb[0] / 1024);

if (currentFreeTextureMemory_mb >= 4096) // If >= 4 GB free texture memory
{
return 4096;
if (currentFreeTextureMemory_mb >= 4096) // If >= 4 GB free texture memory
{
return 4096;
}
else
{
return 2048;
}
}
else
}

// don't currently have a good way of checking video memory on this system
// instead, check system RAM
auto systemRAMinMiB = wzGetSystemRAM();
if (systemRAMinMiB >= 16384) // If >= 16 GB of system RAM
{
#if defined(WZ_OS_WIN)
WzString openGL_renderer = (const char*)wzSafeGlGetString(GL_RENDERER);
if (openGL_renderer.startsWith("Intel(R) HD Graphics"))
{
// always default to 2048 on Intel HD Graphics...
return 2048;
}
#endif
return 4096;
}
else
{
// don't currently have a good way of checking on this system
return nullopt;
return 2048;
}
}

Expand Down Expand Up @@ -3080,7 +3097,7 @@ bool gl_context::_initialize(const gfx_api::backend_Impl_Factory& impl, int32_t
depthBufferResolution = _depthMapResolution;
if (depthBufferResolution == 0)
{
depthBufferResolution = getSuggestedDefaultDepthBufferResolution().value_or(2048);
depthBufferResolution = getSuggestedDefaultDepthBufferResolution();
}

createSceneRenderpass();
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/gfx_api_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ struct gl_context final : public gfx_api::context
void disableVertexAttribArray(GLuint index);
std::string calculateFormattedRendererInfoString() const;
bool isBlocklistedGraphicsDriver() const;
optional<uint32_t> getSuggestedDefaultDepthBufferResolution() const;
uint32_t getSuggestedDefaultDepthBufferResolution() const;

uint32_t viewportWidth = 0;
uint32_t viewportHeight = 0;
Expand Down
7 changes: 7 additions & 0 deletions lib/sdl/main_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ WzString wzGetPlatform()
return WzString::fromUtf8(SDL_GetPlatform());
}

// Get system RAM (in MiB)
uint32_t wzGetSystemRAM()
{
auto systemRAMResult = SDL_GetSystemRAM();
return (systemRAMResult > 0) ? static_cast<uint32_t>(systemRAMResult) : 0;
}

// See if we have TEXT in the clipboard
bool has_scrap(void)
{
Expand Down

0 comments on commit 69e0f3f

Please sign in to comment.