summaryrefslogtreecommitdiff
path: root/src/render/OpenGL.cpp
diff options
context:
space:
mode:
authorTom Englund <tomenglund26@gmail.com>2025-09-27 18:46:26 +0200
committerVaxry <43317083+vaxerski@users.noreply.github.com>2025-09-28 23:20:52 +0200
commiteb25dfd399d481ce770c8851416b70b077892afc (patch)
tree91f1810996f6e001d4e9e964b5b17bc43266ba8b /src/render/OpenGL.cpp
parentb627885788acbab4c768632f800e010467ffbaf9 (diff)
opengl: move from unordered_set to array
setCapStatus is a a heavy used function in hot rendering paths, it shows up in profiling as using a bit of cpu just because of unordered_set hashing etc, move to a enum and array and cache only the heavily used ones.
Diffstat (limited to 'src/render/OpenGL.cpp')
-rw-r--r--src/render/OpenGL.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index e1ecdd2f..fd5ce164 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -3170,18 +3170,36 @@ void CHyprOpenGLImpl::setViewport(GLint x, GLint y, GLsizei width, GLsizei heigh
}
void CHyprOpenGLImpl::setCapStatus(int cap, bool status) {
- // check if the capability status is already set to the desired status
- auto it = m_capStatus.find(cap);
- bool currentStatus = (it != m_capStatus.end()) ? it->second : false; // default to 'false' if not found
+ const auto getCapIndex = [cap]() {
+ switch (cap) {
+ case GL_BLEND: return CAP_STATUS_BLEND;
+ case GL_SCISSOR_TEST: return CAP_STATUS_SCISSOR_TEST;
+ case GL_STENCIL_TEST: return CAP_STATUS_STENCIL_TEST;
+ default: return CAP_STATUS_END;
+ }
+ };
+
+ auto idx = getCapIndex();
+
+ if (idx == CAP_STATUS_END) {
+ if (status)
+ glEnable(cap);
+ else
+ glDisable(cap);
- if (currentStatus == status)
return;
+ }
- m_capStatus[cap] = status;
+ if (m_capStatus[idx] == status)
+ return;
- // Enable or disable the capability based on status
- auto func = status ? [](int c) { glEnable(c); } : [](int c) { glDisable(c); };
- func(cap);
+ if (status) {
+ m_capStatus[idx] = status;
+ glEnable(cap);
+ } else {
+ m_capStatus[idx] = status;
+ glDisable(cap);
+ }
}
uint32_t CHyprOpenGLImpl::getPreferredReadFormat(PHLMONITOR pMonitor) {