render.cpp
2672 bytes
1#include "render.hpp"
2
3#include <GLES2/gl2.h>
4#include <hyprland/src/render/OpenGL.hpp>
5#include <hyprland/src/render/gl/GLTexture.hpp>
6#include <hyprland/src/render/Shader.hpp>
7#include <hyprutils/math/Box.hpp>
8#include <hyprutils/math/Misc.hpp>
9#include <hyprutils/math/Vector2D.hpp>
10
11#include "render/Renderer.hpp"
12#include "render/Texture.hpp"
13#include "shaders.hpp"
14
15using Render::GL::g_pHyprOpenGL;
16using Hyprutils::Math::CBox;
17
18void Hy3Render::renderTab(
19 const CBox& box,
20 float opacity,
21 bool blur,
22 const CHyprColor& fillColor,
23 const CHyprColor& borderColor,
24 int borderWidth,
25 int radius
26) {
27 static auto& shader = Hy3Shaders::instance()->tab;
28 auto& rdata = g_pHyprRenderer->m_renderData;
29
30 auto rbox = box;
31 rdata.renderModif.applyToBox(rbox);
32
33 const auto& monitorSize = rdata.pMonitor->m_transformedSize;
34 auto monitorBox = CBox {Vector2D(), monitorSize};
35
36 auto glMatrix = g_pHyprRenderer->projectBoxToTarget(monitorBox, Hyprutils::Math::HYPRUTILS_TRANSFORM_NORMAL);
37
38 g_pHyprOpenGL->useShader(shader.program);
39
40#ifndef GLES2
41 glUniformMatrix3fv(shader.proj, 1, GL_TRUE, glMatrix.getMatrix().data());
42#else
43 glMatrix.transpose();
44 glUniformMatrix3fv(shader.proj, 1, GL_FALSE, glMatrix.getMatrix().data());
45#endif
46
47 WP<Render::ITexture> blurTex;
48
49 if (blur) {
50 blurTex = rdata.pMonitor->resources()->m_blurFB->getTexture();
51 if (!blurTex) blur = false;
52 }
53
54 if (blur) {
55 GLCALL(glActiveTexture(GL_TEXTURE0));
56 //GLCALL(glBindTexture(blurTex->m_target, blurTex->m_texID));
57 GLCALL(glBindTexture(GL_TEXTURE_2D, blurTex->m_texID));
58 GLCALL(glUniform1i(shader.blurTex, 0));
59 }
60
61 GLCALL(glUniform1i(shader.applyBlur, blur));
62
63 // premultiplied
64 GLCALL(glUniform4f(
65 shader.fillColor,
66 fillColor.r * fillColor.a,
67 fillColor.g * fillColor.a,
68 fillColor.b * fillColor.a,
69 fillColor.a
70 ));
71
72 if (borderWidth != 0) {
73 GLCALL(glUniform4f(
74 shader.borderColor,
75 borderColor.r * borderColor.a,
76 borderColor.g * borderColor.a,
77 borderColor.b * borderColor.a,
78 borderColor.a
79 ));
80 }
81
82 GLCALL(glUniform2f(shader.monitorSize, monitorSize.x, monitorSize.y));
83 GLCALL(glUniform2f(shader.pixelOffset, rbox.x, rbox.y));
84 GLCALL(glUniform2f(shader.pixelSize, rbox.w, rbox.h));
85 GLCALL(glUniform1f(shader.opacity, opacity));
86 GLCALL(glUniform1f(shader.outerRadius, radius));
87 GLCALL(glUniform1f(shader.borderWidth, borderWidth));
88
89 GLCALL(glBindVertexArray(shader.program->getUniformLocation(SHADER_SHADER_VAO)));
90 GLCALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
91 GLCALL(glBindVertexArray(0));
92
93 if (blur) {
94 // GLCALL(glBindTexture(blurTex->m_target, 0));
95 GLCALL(glBindTexture(GL_TEXTURE_2D, 0));
96 }
97}