Rendering textures

This commit is contained in:
vaxerski 2022-04-05 14:33:54 +02:00
parent 67343898ff
commit 19d9465042
7 changed files with 125 additions and 23 deletions

View file

@ -113,22 +113,18 @@ void Events::listener_monitorFrame(void* owner, void* data) {
return; return;
g_pHyprOpenGL->begin(PMONITOR); g_pHyprOpenGL->begin(PMONITOR);
g_pHyprOpenGL->clear(CColor(11, 55, 11, 255)); g_pHyprOpenGL->clear(CColor(11, 11, 11, 255));
wlr_box box = {1,1,100,300}; g_pHyprRenderer->renderAllClientsForMonitor(PMONITOR->ID, &now);
g_pHyprOpenGL->renderRect(&box, CColor(255,0,255,255));
wlr_renderer_begin(g_pCompositor->m_sWLRRenderer, PMONITOR->vecSize.x, PMONITOR->vecSize.y);
wlr_output_render_software_cursors(PMONITOR->output, NULL);
wlr_renderer_end(g_pCompositor->m_sWLRRenderer);
g_pHyprOpenGL->end(); g_pHyprOpenGL->end();
// wlr_renderer_begin(g_pCompositor->m_sWLRRenderer, PMONITOR->vecSize.x, PMONITOR->vecSize.y);
// wlr_renderer_clear(g_pCompositor->m_sWLRRenderer, bgcol);
// g_pHyprRenderer->renderAllClientsForMonitor(PMONITOR->ID, &now);
// wlr_output_render_software_cursors(PMONITOR->output, NULL);
// wlr_renderer_end(g_pCompositor->m_sWLRRenderer);
wlr_output_commit(PMONITOR->output); wlr_output_commit(PMONITOR->output);
} }

View file

@ -84,5 +84,6 @@ extern "C" {
#endif #endif
#include <GLES3/gl32.h> #include <GLES3/gl32.h>
#include <GLES2/gl2ext.h>
#include "helpers/Vector2D.hpp" #include "helpers/Vector2D.hpp"

View file

@ -152,7 +152,7 @@ void CHyprOpenGLImpl::renderRect(wlr_box* box, const CColor& col) {
glUseProgram(m_shQUAD.program); glUseProgram(m_shQUAD.program);
glUniformMatrix3fv(m_shQUAD.proj, 1, GL_FALSE, glMatrix); glUniformMatrix3fv(m_shQUAD.proj, 1, GL_FALSE, glMatrix);
glUniform4f(m_shQUAD.color, col.r / 255.f, col.g / 255.f, col.r / 255.f, col.a / 255.f); glUniform4f(m_shQUAD.color, col.r / 255.f, col.g / 255.f, col.b / 255.f, col.a / 255.f);
glVertexAttribPointer(m_shQUAD.posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); glVertexAttribPointer(m_shQUAD.posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts);
@ -161,4 +161,65 @@ void CHyprOpenGLImpl::renderRect(wlr_box* box, const CColor& col) {
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(m_shQUAD.posAttrib); glDisableVertexAttribArray(m_shQUAD.posAttrib);
}
void CHyprOpenGLImpl::renderTexture(wlr_texture* tex,float matrix[9], float alpha) {
RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!");
renderTexture(CTexture(tex), matrix, alpha);
}
void CHyprOpenGLImpl::renderTexture(const CTexture& tex, float matrix[9], float alpha) {
RASSERT(m_RenderData.pMonitor, "Tried to render texture without begin()!");
RASSERT((tex.m_iTexID > 0), "Attempted to draw NULL texture!");
float glMatrix[9];
wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix);
wlr_matrix_multiply(glMatrix, matrixFlip180, glMatrix);
wlr_matrix_transpose(glMatrix, glMatrix);
CShader* shader = nullptr;
switch (tex.m_iType) {
case TEXTURE_RGBA:
shader = &m_shRGBA;
glEnable(GL_BLEND);
break;
case TEXTURE_RGBX:
shader = &m_shRGBX;
if (alpha == 255.f)
glDisable(GL_BLEND);
break;
case TEXTURE_EXTERNAL:
shader = &m_shEXT;
glEnable(GL_BLEND);
break;
default:
RASSERT(false, "tex.m_iTarget unsupported!");
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(tex.m_iTarget, tex.m_iTexID);
glTexParameteri(tex.m_iTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glUseProgram(shader->program);
glUniformMatrix3fv(shader->proj, 1, GL_FALSE, glMatrix);
glUniform1i(shader->tex, 0);
glUniform1f(shader->alpha, alpha / 255.f);
glVertexAttribPointer(shader->posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts);
glVertexAttribPointer(shader->texAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts);
glEnableVertexAttribArray(shader->posAttrib);
glEnableVertexAttribArray(shader->texAttrib);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(shader->posAttrib);
glDisableVertexAttribArray(shader->texAttrib);
glBindTexture(tex.m_iTarget, 0);
} }

View file

@ -8,6 +8,7 @@
#include "Shaders.hpp" #include "Shaders.hpp"
#include "Shader.hpp" #include "Shader.hpp"
#include "Texture.hpp"
inline const float matrixFlip180[] = { inline const float matrixFlip180[] = {
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
@ -35,6 +36,8 @@ public:
void end(); void end();
void renderRect(wlr_box*, const CColor&); void renderRect(wlr_box*, const CColor&);
void renderTexture(wlr_texture*, float matrix[9], float a);
void renderTexture(const CTexture&, float matrix[9], float a);
void clear(const CColor&); void clear(const CColor&);
void scissor(const wlr_box*); void scissor(const wlr_box*);

View file

@ -21,7 +21,7 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
wlr_box windowBox; wlr_box windowBox;
if (RDATA->surface && surface == RDATA->surface) { if (RDATA->surface && surface == RDATA->surface) {
windowBox = {(int)outputX + RDATA->x + x, (int)outputY + RDATA->y + y, RDATA->w, RDATA->h}; windowBox = {(int)outputX + RDATA->x + x, (int)outputY + RDATA->y + y, RDATA->w, RDATA->h};
wlr_renderer_scissor(g_pCompositor->m_sWLRRenderer, &windowBox); g_pHyprOpenGL->scissor(&windowBox);
} else { } else {
windowBox = {(int)outputX + RDATA->x + x, (int)outputY + RDATA->y + y, surface->current.width, surface->current.height}; windowBox = {(int)outputX + RDATA->x + x, (int)outputY + RDATA->y + y, surface->current.width, surface->current.height};
} }
@ -31,13 +31,13 @@ void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
float matrix[9]; float matrix[9];
wlr_matrix_project_box(matrix, &windowBox, TRANSFORM, 0, RDATA->output->transform_matrix); wlr_matrix_project_box(matrix, &windowBox, TRANSFORM, 0, RDATA->output->transform_matrix);
wlr_render_texture_with_matrix(g_pCompositor->m_sWLRRenderer, TEXTURE, matrix, 1); // TODO: fadein/out g_pHyprOpenGL->renderTexture(TEXTURE, matrix, 255.f); // TODO: fadeinout
wlr_surface_send_frame_done(surface, RDATA->when); wlr_surface_send_frame_done(surface, RDATA->when);
wlr_presentation_surface_sampled_on_output(g_pCompositor->m_sWLRPresentation, surface, RDATA->output); wlr_presentation_surface_sampled_on_output(g_pCompositor->m_sWLRPresentation, surface, RDATA->output);
wlr_renderer_scissor(g_pCompositor->m_sWLRRenderer, nullptr); g_pHyprOpenGL->scissor(nullptr);
} }
bool shouldRenderWindow(CWindow* pWindow, SMonitor* pMonitor) { bool shouldRenderWindow(CWindow* pWindow, SMonitor* pMonitor) {
@ -395,29 +395,27 @@ void CHyprRenderer::arrangeLayersForMonitor(const int& monitor) {
void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor) { void CHyprRenderer::drawBorderForWindow(CWindow* pWindow, SMonitor* pMonitor) {
const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size"); const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size");
const auto BORDERCOL = pWindow->m_cRealBorderColor.getAsHex(); const auto BORDERCOL = pWindow->m_cRealBorderColor;
const float BORDERWLRCOL[4] = {RED(BORDERCOL), GREEN(BORDERCOL), BLUE(BORDERCOL), ALPHA(BORDERCOL)};
Vector2D correctPos = pWindow->m_vRealPosition - pMonitor->vecPosition; Vector2D correctPos = pWindow->m_vRealPosition - pMonitor->vecPosition;
// top // top
wlr_box border = {correctPos.x - BORDERSIZE, correctPos.y - BORDERSIZE, pWindow->m_vRealSize.x + 2 * BORDERSIZE, BORDERSIZE}; wlr_box border = {correctPos.x - BORDERSIZE, correctPos.y - BORDERSIZE, pWindow->m_vRealSize.x + 2 * BORDERSIZE, BORDERSIZE};
wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); g_pHyprOpenGL->renderRect(&border, BORDERCOL);
// bottom // bottom
border.y = correctPos.y + pWindow->m_vRealSize.y; border.y = correctPos.y + pWindow->m_vRealSize.y;
wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); g_pHyprOpenGL->renderRect(&border, BORDERCOL);
// left // left
border.y = correctPos.y; border.y = correctPos.y;
border.width = BORDERSIZE; border.width = BORDERSIZE;
border.height = pWindow->m_vRealSize.y; border.height = pWindow->m_vRealSize.y;
wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); g_pHyprOpenGL->renderRect(&border, BORDERCOL);
// right // right
border.x = correctPos.x + pWindow->m_vRealSize.x; border.x = correctPos.x + pWindow->m_vRealSize.x;
wlr_render_rect(g_pCompositor->m_sWLRRenderer, &border, BORDERWLRCOL, pMonitor->output->transform_matrix); g_pHyprOpenGL->renderRect(&border, BORDERCOL);
} }
void damageSurfaceIter(struct wlr_surface* surface, int x, int y, void* data) { void damageSurfaceIter(struct wlr_surface* surface, int x, int y, void* data) {

22
src/render/Texture.cpp Normal file
View file

@ -0,0 +1,22 @@
#include "Texture.hpp"
CTexture::CTexture() {
// naffin'
}
CTexture::CTexture(wlr_texture* tex) {
RASSERT(wlr_texture_is_gles2(tex), "wlr_texture provided to CTexture that isn't GLES2!");
wlr_gles2_texture_attribs attrs;
wlr_gles2_texture_get_attribs(tex, &attrs);
m_iTarget = attrs.target;
m_iTexID = attrs.tex;
if (m_iTarget == GL_TEXTURE_2D) {
m_iType = attrs.has_alpha ? TEXTURE_RGBA : TEXTURE_RGBX;
} else {
m_iType = TEXTURE_EXTERNAL;
}
m_vSize = Vector2D(tex->width, tex->height);
}

21
src/render/Texture.hpp Normal file
View file

@ -0,0 +1,21 @@
#pragma once
#include "../defines.hpp"
enum TEXTURETYPE {
TEXTURE_INVALID, // Invalid
TEXTURE_RGBA, // 4 channels
TEXTURE_RGBX, // discard A
TEXTURE_EXTERNAL, // EGLImage
};
class CTexture {
public:
CTexture();
CTexture(wlr_texture*);
TEXTURETYPE m_iType = TEXTURE_RGBA;
GLenum m_iTarget = GL_TEXTURE_2D;
GLuint m_iTexID = 0;
Vector2D m_vSize;
};