Parent directory

render.cpp

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