mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-22 13:29:49 +01:00
optimize data feeding to gradient renderer
This commit is contained in:
parent
0948b078e1
commit
684c59e5bc
3 changed files with 8 additions and 13 deletions
|
@ -382,7 +382,7 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
|
|||
}
|
||||
|
||||
try {
|
||||
data->m_vColors.push_back(configStringToInt(var));
|
||||
data->m_vColors.push_back(CColor(configStringToInt(var)) * (1.f / 255.f));
|
||||
} catch (std::exception& e) {
|
||||
Debug::log(WARN, "Error reading value of %s", COMMAND.c_str());
|
||||
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. " + e.what();
|
||||
|
|
|
@ -242,6 +242,7 @@ void CHyprOpenGLImpl::initShaders() {
|
|||
m_RenderData.pCurrentMonData->m_shBORDER1.gradient = glGetUniformLocation(prog, "gradient");
|
||||
m_RenderData.pCurrentMonData->m_shBORDER1.gradientLength = glGetUniformLocation(prog, "gradientLength");
|
||||
m_RenderData.pCurrentMonData->m_shBORDER1.angle = glGetUniformLocation(prog, "angle");
|
||||
m_RenderData.pCurrentMonData->m_shBORDER1.alpha = glGetUniformLocation(prog, "alpha");
|
||||
|
||||
m_RenderData.pCurrentMonData->m_bShadersInitialized = true;
|
||||
|
||||
|
@ -846,19 +847,13 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad,
|
|||
wlr_matrix_transpose(glMatrix, glMatrix);
|
||||
glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBORDER1.proj, 1, GL_FALSE, glMatrix);
|
||||
#endif
|
||||
|
||||
// TODO: make gradients already in 0 ... 1 and just pass vec.data(), alpha in shader
|
||||
float* gradientValues = (float*)malloc(sizeof(float) * grad.m_vColors.size() * 4);
|
||||
for (size_t i = 0; i < grad.m_vColors.size(); ++i) {
|
||||
gradientValues[i * 4] = grad.m_vColors[i].r / 255.f;
|
||||
gradientValues[i * 4 + 1] = grad.m_vColors[i].g / 255.f;
|
||||
gradientValues[i * 4 + 2] = grad.m_vColors[i].b / 255.f;
|
||||
gradientValues[i * 4 + 3] = grad.m_vColors[i].a / 255.f * a;
|
||||
}
|
||||
|
||||
glUniform4fv(m_RenderData.pCurrentMonData->m_shBORDER1.gradient, grad.m_vColors.size(), gradientValues);
|
||||
static_assert(sizeof(CColor) == 4 * sizeof(float)); // otherwise the line below this will fail
|
||||
|
||||
glUniform4fv(m_RenderData.pCurrentMonData->m_shBORDER1.gradient, grad.m_vColors.size(), (float*)grad.m_vColors.data());
|
||||
glUniform1i(m_RenderData.pCurrentMonData->m_shBORDER1.gradientLength, grad.m_vColors.size());
|
||||
glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.angle, grad.m_fAngle);
|
||||
glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.alpha, a);
|
||||
|
||||
wlr_box transformedBox;
|
||||
wlr_box_transform(&transformedBox, box, wlr_output_transform_invert(m_RenderData.pMonitor->transform),
|
||||
|
@ -907,8 +902,6 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CGradientValueData& grad,
|
|||
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
free(gradientValues);
|
||||
|
||||
// fix back box
|
||||
box->x += scaledBorderSize;
|
||||
box->y += scaledBorderSize;
|
||||
|
|
|
@ -17,6 +17,7 @@ uniform int primitiveMultisample;
|
|||
uniform vec4 gradient[10];
|
||||
uniform int gradientLength;
|
||||
uniform float angle;
|
||||
uniform float alpha;
|
||||
|
||||
vec4 getColorForCoord(vec2 normalizedCoord) {
|
||||
if (gradientLength < 2)
|
||||
|
@ -36,6 +37,7 @@ void main() {
|
|||
vec2 originalPixCoord = fullSize * v_texcoord;
|
||||
|
||||
vec4 pixColor = getColorForCoord(v_texcoord);
|
||||
pixColor[3] *= alpha;
|
||||
|
||||
bool done = false;
|
||||
|
||||
|
|
Loading…
Reference in a new issue