diff --git a/libs/gfx/include/psemek/gfx/memory.hpp b/libs/gfx/include/psemek/gfx/memory.hpp new file mode 100644 index 00000000..06fa7d10 --- /dev/null +++ b/libs/gfx/include/psemek/gfx/memory.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +namespace psemek::gfx +{ + + std::optional available_memory(); + +} diff --git a/libs/gfx/source/memory.cpp b/libs/gfx/source/memory.cpp new file mode 100644 index 00000000..017f5fc4 --- /dev/null +++ b/libs/gfx/source/memory.cpp @@ -0,0 +1,29 @@ +#include +#include + +namespace psemek::gfx +{ + + std::optional available_memory() + { + static bool const nvx = gl::sys::has_extension("GL_NVX_gpu_memory_info"); + static bool const ati = gl::sys::has_extension("GL_ATI_meminfo"); + + if (nvx) + { + GLint value = 0; + gl::GetIntegerv(0x9049, &value); + return static_cast(value) * 1024; + } + + if (ati) + { + GLint values[4]{}; + gl::GetIntegerv(0x87FC, values); + return static_cast(values[0]) * 1024; + } + + return std::nullopt; + } + +}