mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 01:25:58 +01:00
renderer: properly pass 10-bit formats to opengl
This commit is contained in:
parent
a1924ae435
commit
4b592d0819
7 changed files with 33 additions and 13 deletions
|
@ -750,4 +750,16 @@ std::vector<SCallstackFrameInfo> getBacktrace() {
|
||||||
void throwError(const std::string& err) {
|
void throwError(const std::string& err) {
|
||||||
Debug::log(CRIT, "Critical error thrown: {}", err);
|
Debug::log(CRIT, "Critical error thrown: {}", err);
|
||||||
throw std::runtime_error(err);
|
throw std::runtime_error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t drmFormatToGL(uint32_t drm) {
|
||||||
|
switch (drm) {
|
||||||
|
case DRM_FORMAT_XRGB8888:
|
||||||
|
case DRM_FORMAT_XBGR8888: return GL_RGBA; // doesn't matter, opengl is gucci in this case.
|
||||||
|
case DRM_FORMAT_XRGB2101010:
|
||||||
|
case DRM_FORMAT_XBGR2101010: return GL_RGB10_A2;
|
||||||
|
default: return GL_RGBA;
|
||||||
|
}
|
||||||
|
UNREACHABLE();
|
||||||
|
return GL_RGBA;
|
||||||
}
|
}
|
|
@ -33,6 +33,7 @@ double normalizeAngleRad(double ang);
|
||||||
std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
|
std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
|
||||||
std::vector<SCallstackFrameInfo> getBacktrace();
|
std::vector<SCallstackFrameInfo> getBacktrace();
|
||||||
void throwError(const std::string& err);
|
void throwError(const std::string& err);
|
||||||
|
uint32_t drmFormatToGL(uint32_t drm);
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
[[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) {
|
[[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) {
|
||||||
|
|
|
@ -65,6 +65,7 @@ class CMonitor {
|
||||||
bool vrrActive = false; // this can be TRUE even if VRR is not active in the case that this display does not support it.
|
bool vrrActive = false; // this can be TRUE even if VRR is not active in the case that this display does not support it.
|
||||||
bool enabled10bit = false; // as above, this can be TRUE even if 10 bit failed.
|
bool enabled10bit = false; // as above, this can be TRUE even if 10 bit failed.
|
||||||
bool createdByUser = false;
|
bool createdByUser = false;
|
||||||
|
uint32_t drmFormat = DRM_FORMAT_INVALID;
|
||||||
|
|
||||||
bool pendingFrame = false; // if we schedule a frame during rendering, reschedule it after
|
bool pendingFrame = false; // if we schedule a frame during rendering, reschedule it after
|
||||||
bool renderingActive = false;
|
bool renderingActive = false;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
#include "Framebuffer.hpp"
|
#include "Framebuffer.hpp"
|
||||||
#include "OpenGL.hpp"
|
#include "OpenGL.hpp"
|
||||||
|
|
||||||
bool CFramebuffer::alloc(int w, int h) {
|
bool CFramebuffer::alloc(int w, int h, uint32_t drmFormat) {
|
||||||
bool firstAlloc = false;
|
bool firstAlloc = false;
|
||||||
RASSERT((w > 1 && h > 1), "cannot alloc a FB with negative / zero size! (attempted {}x{})", w, h);
|
RASSERT((w > 1 && h > 1), "cannot alloc a FB with negative / zero size! (attempted {}x{})", w, h);
|
||||||
|
|
||||||
|
uint32_t glFormat = drmFormatToGL(drmFormat);
|
||||||
|
uint32_t glType = glFormat != GL_RGBA ? GL_UNSIGNED_INT_2_10_10_10_REV : GL_UNSIGNED_BYTE;
|
||||||
|
|
||||||
if (m_iFb == (uint32_t)-1) {
|
if (m_iFb == (uint32_t)-1) {
|
||||||
firstAlloc = true;
|
firstAlloc = true;
|
||||||
glGenFramebuffers(1, &m_iFb);
|
glGenFramebuffers(1, &m_iFb);
|
||||||
|
@ -22,7 +25,7 @@ bool CFramebuffer::alloc(int w, int h) {
|
||||||
|
|
||||||
if (firstAlloc || m_vSize != Vector2D(w, h)) {
|
if (firstAlloc || m_vSize != Vector2D(w, h)) {
|
||||||
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
|
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
glTexImage2D(GL_TEXTURE_2D, 0, glFormat, w, h, 0, GL_RGBA, glType, 0);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0);
|
||||||
|
|
|
@ -7,7 +7,7 @@ class CFramebuffer {
|
||||||
public:
|
public:
|
||||||
~CFramebuffer();
|
~CFramebuffer();
|
||||||
|
|
||||||
bool alloc(int w, int h);
|
bool alloc(int w, int h, uint32_t format = GL_RGBA);
|
||||||
void bind();
|
void bind();
|
||||||
void release();
|
void release();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
|
@ -130,10 +130,10 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, CRegion* pDamage, bool fake) {
|
||||||
m_RenderData.pCurrentMonData->mirrorSwapFB.m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
m_RenderData.pCurrentMonData->mirrorSwapFB.m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
||||||
m_RenderData.pCurrentMonData->offMainFB.m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
m_RenderData.pCurrentMonData->offMainFB.m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
||||||
|
|
||||||
m_RenderData.pCurrentMonData->primaryFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y);
|
m_RenderData.pCurrentMonData->primaryFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, pMonitor->drmFormat);
|
||||||
m_RenderData.pCurrentMonData->mirrorFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y);
|
m_RenderData.pCurrentMonData->mirrorFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, pMonitor->drmFormat);
|
||||||
m_RenderData.pCurrentMonData->mirrorSwapFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y);
|
m_RenderData.pCurrentMonData->mirrorSwapFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, pMonitor->drmFormat);
|
||||||
m_RenderData.pCurrentMonData->offMainFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y);
|
m_RenderData.pCurrentMonData->offMainFB.alloc(pMonitor->vecPixelSize.x, pMonitor->vecPixelSize.y, pMonitor->drmFormat);
|
||||||
|
|
||||||
createBGTextureForMonitor(pMonitor);
|
createBGTextureForMonitor(pMonitor);
|
||||||
}
|
}
|
||||||
|
@ -1139,7 +1139,7 @@ void CHyprOpenGLImpl::preBlurForCurrentMonitor() {
|
||||||
const auto POUTFB = blurMainFramebufferWithDamage(1, &fakeDamage);
|
const auto POUTFB = blurMainFramebufferWithDamage(1, &fakeDamage);
|
||||||
|
|
||||||
// render onto blurFB
|
// render onto blurFB
|
||||||
m_RenderData.pCurrentMonData->blurFB.alloc(m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y);
|
m_RenderData.pCurrentMonData->blurFB.alloc(m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y, m_RenderData.pMonitor->drmFormat);
|
||||||
m_RenderData.pCurrentMonData->blurFB.bind();
|
m_RenderData.pCurrentMonData->blurFB.bind();
|
||||||
|
|
||||||
clear(CColor(0, 0, 0, 0));
|
clear(CColor(0, 0, 0, 0));
|
||||||
|
@ -1430,7 +1430,7 @@ void CHyprOpenGLImpl::makeRawWindowSnapshot(CWindow* pWindow, CFramebuffer* pFra
|
||||||
|
|
||||||
pFramebuffer->m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
pFramebuffer->m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
||||||
|
|
||||||
pFramebuffer->alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y);
|
pFramebuffer->alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y, PMONITOR->drmFormat);
|
||||||
|
|
||||||
pFramebuffer->bind();
|
pFramebuffer->bind();
|
||||||
|
|
||||||
|
@ -1488,7 +1488,7 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
|
||||||
|
|
||||||
PFRAMEBUFFER->m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
PFRAMEBUFFER->m_pStencilTex = &m_RenderData.pCurrentMonData->stencilTex;
|
||||||
|
|
||||||
PFRAMEBUFFER->alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y);
|
PFRAMEBUFFER->alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y, PMONITOR->drmFormat);
|
||||||
|
|
||||||
PFRAMEBUFFER->bind();
|
PFRAMEBUFFER->bind();
|
||||||
|
|
||||||
|
@ -1533,7 +1533,7 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) {
|
||||||
|
|
||||||
glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y);
|
glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y);
|
||||||
|
|
||||||
PFRAMEBUFFER->alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y);
|
PFRAMEBUFFER->alloc(PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y, PMONITOR->drmFormat);
|
||||||
|
|
||||||
PFRAMEBUFFER->bind();
|
PFRAMEBUFFER->bind();
|
||||||
|
|
||||||
|
@ -1721,7 +1721,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl
|
||||||
void CHyprOpenGLImpl::saveBufferForMirror() {
|
void CHyprOpenGLImpl::saveBufferForMirror() {
|
||||||
|
|
||||||
if (!m_RenderData.pCurrentMonData->monitorMirrorFB.isAllocated())
|
if (!m_RenderData.pCurrentMonData->monitorMirrorFB.isAllocated())
|
||||||
m_RenderData.pCurrentMonData->monitorMirrorFB.alloc(m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y);
|
m_RenderData.pCurrentMonData->monitorMirrorFB.alloc(m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y, m_RenderData.pMonitor->drmFormat);
|
||||||
|
|
||||||
m_RenderData.pCurrentMonData->monitorMirrorFB.bind();
|
m_RenderData.pCurrentMonData->monitorMirrorFB.bind();
|
||||||
|
|
||||||
|
|
|
@ -1877,7 +1877,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
bool set10bit = false;
|
bool set10bit = false;
|
||||||
|
pMonitor->drmFormat = DRM_FORMAT_INVALID;
|
||||||
|
|
||||||
for (auto& fmt : formats[(int)!pMonitorRule->enable10bit]) {
|
for (auto& fmt : formats[(int)!pMonitorRule->enable10bit]) {
|
||||||
wlr_output_set_render_format(pMonitor->output, fmt.second);
|
wlr_output_set_render_format(pMonitor->output, fmt.second);
|
||||||
|
@ -1888,6 +1889,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR
|
||||||
Debug::log(LOG, "output {} succeeded basic test on format {}", pMonitor->szName, fmt.first);
|
Debug::log(LOG, "output {} succeeded basic test on format {}", pMonitor->szName, fmt.first);
|
||||||
if (pMonitorRule->enable10bit && fmt.first.contains("101010"))
|
if (pMonitorRule->enable10bit && fmt.first.contains("101010"))
|
||||||
set10bit = true;
|
set10bit = true;
|
||||||
|
|
||||||
|
pMonitor->drmFormat = fmt.second;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue