summaryrefslogtreecommitdiff
path: root/src/render/OpenGL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/OpenGL.cpp')
-rw-r--r--src/render/OpenGL.cpp119
1 files changed, 110 insertions, 9 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index 67c11c23..91849701 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -338,6 +338,8 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() {
initDRMFormats();
+ initAssets();
+
static auto P = g_pHookSystem->hookDynamic("preRender", [&](void* self, SCallbackInfo& info, std::any data) { preRender(std::any_cast<CMonitor*>(data)); });
RASSERT(eglMakeCurrent(m_pEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!");
@@ -2614,14 +2616,17 @@ void CHyprOpenGLImpl::renderSplash(cairo_t* const CAIRO, cairo_surface_t* const
cairo_surface_flush(CAIROSURFACE);
}
-void CHyprOpenGLImpl::createBackgroundTexture(const std::string& texPath) {
- const auto CAIROSURFACE = cairo_image_surface_create_from_png(texPath.c_str());
- const auto CAIROFORMAT = cairo_image_surface_get_format(CAIROSURFACE);
+SP<CTexture> CHyprOpenGLImpl::loadAsset(const std::string& file) {
+ const auto CAIROSURFACE = cairo_image_surface_create_from_png(file.c_str());
- m_pBackgroundTexture = makeShared<CTexture>();
+ if (!CAIROSURFACE)
+ return nullptr;
- m_pBackgroundTexture->allocate();
- m_pBackgroundTexture->m_vSize = {cairo_image_surface_get_width(CAIROSURFACE), cairo_image_surface_get_height(CAIROSURFACE)};
+ const auto CAIROFORMAT = cairo_image_surface_get_format(CAIROSURFACE);
+ auto tex = makeShared<CTexture>();
+
+ tex->allocate();
+ tex->m_vSize = {cairo_image_surface_get_width(CAIROSURFACE), cairo_image_surface_get_height(CAIROSURFACE)};
const GLint glIFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ?
#ifdef GLES2
@@ -2634,7 +2639,7 @@ void CHyprOpenGLImpl::createBackgroundTexture(const std::string& texPath) {
const GLint glType = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_FLOAT : GL_UNSIGNED_BYTE;
const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
- glBindTexture(GL_TEXTURE_2D, m_pBackgroundTexture->m_iTexID);
+ glBindTexture(GL_TEXTURE_2D, tex->m_iTexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
#ifndef GLES2
@@ -2643,9 +2648,105 @@ void CHyprOpenGLImpl::createBackgroundTexture(const std::string& texPath) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
}
#endif
- glTexImage2D(GL_TEXTURE_2D, 0, glIFormat, m_pBackgroundTexture->m_vSize.x, m_pBackgroundTexture->m_vSize.y, 0, glFormat, glType, DATA);
+ glTexImage2D(GL_TEXTURE_2D, 0, glIFormat, tex->m_vSize.x, tex->m_vSize.y, 0, glFormat, glType, DATA);
+
+ cairo_surface_destroy(CAIROSURFACE);
+
+ return tex;
+}
+
+SP<CTexture> CHyprOpenGLImpl::renderText(const std::string& text, CColor col, int pt, bool italic) {
+ SP<CTexture> tex = makeShared<CTexture>();
+
+ static auto FONT = CConfigValue<std::string>("misc:font_family");
+
+ const auto FONTFAMILY = *FONT;
+ const auto FONTSIZE = pt;
+ const auto COLOR = col;
+
+ auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1920, 1080 /* arbitrary, just for size */);
+ auto CAIRO = cairo_create(CAIROSURFACE);
+
+ PangoLayout* layoutText = pango_cairo_create_layout(CAIRO);
+ PangoFontDescription* pangoFD = pango_font_description_new();
+
+ pango_font_description_set_family_static(pangoFD, FONTFAMILY.c_str());
+ pango_font_description_set_absolute_size(pangoFD, FONTSIZE * PANGO_SCALE);
+ pango_font_description_set_style(pangoFD, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
+ pango_font_description_set_weight(pangoFD, PANGO_WEIGHT_NORMAL);
+ pango_layout_set_font_description(layoutText, pangoFD);
+
+ cairo_set_source_rgba(CAIRO, COLOR.r, COLOR.g, COLOR.b, COLOR.a);
+
+ int textW = 0, textH = 0;
+ pango_layout_set_text(layoutText, text.c_str(), -1);
+ pango_layout_get_size(layoutText, &textW, &textH);
+ textW /= PANGO_SCALE;
+ textH /= PANGO_SCALE;
+
+ pango_font_description_free(pangoFD);
+ g_object_unref(layoutText);
+ cairo_destroy(CAIRO);
+ cairo_surface_destroy(CAIROSURFACE);
+
+ CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, textW, textH);
+ CAIRO = cairo_create(CAIROSURFACE);
+
+ layoutText = pango_cairo_create_layout(CAIRO);
+ pangoFD = pango_font_description_new();
+
+ pango_font_description_set_family_static(pangoFD, FONTFAMILY.c_str());
+ pango_font_description_set_absolute_size(pangoFD, FONTSIZE * PANGO_SCALE);
+ pango_font_description_set_style(pangoFD, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
+ pango_font_description_set_weight(pangoFD, PANGO_WEIGHT_NORMAL);
+ pango_layout_set_font_description(layoutText, pangoFD);
+ pango_layout_set_text(layoutText, text.c_str(), -1);
+
+ cairo_set_source_rgba(CAIRO, COLOR.r, COLOR.g, COLOR.b, COLOR.a);
+
+ cairo_move_to(CAIRO, 0, 0);
+ pango_cairo_show_layout(CAIRO, layoutText);
+
+ pango_font_description_free(pangoFD);
+ g_object_unref(layoutText);
+
+ cairo_surface_flush(CAIROSURFACE);
+
+ tex->allocate();
+ tex->m_vSize = {cairo_image_surface_get_width(CAIROSURFACE), cairo_image_surface_get_height(CAIROSURFACE)};
+
+ const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
+ glBindTexture(GL_TEXTURE_2D, tex->m_iTexID);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+#ifndef GLES2
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
+#endif
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->m_vSize.x, tex->m_vSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, DATA);
+ cairo_destroy(CAIRO);
cairo_surface_destroy(CAIROSURFACE);
+
+ return tex;
+}
+
+void CHyprOpenGLImpl::initAssets() {
+ std::string assetsPath = "";
+#ifndef DATAROOTDIR
+ assetsPath = "/usr/share/hypr/";
+#else
+ assetsPath = std::format("{}{}", DATAROOTDIR, "/hypr/");
+#endif
+
+ m_pLockDeadTexture = loadAsset(assetsPath + "lockdead.png");
+ m_pLockDead2Texture = loadAsset(assetsPath + "lockdead2.png");
+
+ m_pLockTtyTextTexture = renderText(std::format("Running on tty {}",
+ g_pCompositor->m_pAqBackend->hasSession() && g_pCompositor->m_pAqBackend->session->vt > 0 ?
+ std::to_string(g_pCompositor->m_pAqBackend->session->vt) :
+ "unknown"),
+ CColor{0.9F, 0.9F, 0.9F, 0.7F}, 20, true);
}
void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) {
@@ -2694,7 +2795,7 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) {
return; // the texture will be empty, oh well. We'll clear with a solid color anyways.
}
- createBackgroundTexture(texPath);
+ m_pBackgroundTexture = loadAsset(texPath);
}
// create a new one with cairo