Add FragmentGlobalOpacity shader part.
This commit is contained in:
parent
06f7b1d4ec
commit
02049aeaa8
4 changed files with 64 additions and 12 deletions
|
|
@ -15,7 +15,7 @@ namespace Ui::GL {
|
|||
|
||||
static_assert(std::is_same_v<float, GLfloat>);
|
||||
|
||||
void FillRectVertices(float *coords, Rect rect) {
|
||||
void FillRectTriangleVertices(float *coords, Rect rect) {
|
||||
coords[0] = coords[10] = rect.left();
|
||||
coords[1] = coords[11] = rect.top();
|
||||
coords[2] = rect.right();
|
||||
|
|
@ -31,7 +31,6 @@ void FillTriangles(
|
|||
gsl::span<const float> coords,
|
||||
not_null<QOpenGLBuffer*> buffer,
|
||||
not_null<QOpenGLShaderProgram*> program,
|
||||
QSize viewportWithFactor,
|
||||
const QColor &color,
|
||||
Fn<void()> additional) {
|
||||
Expects(coords.size() % 6 == 0);
|
||||
|
|
@ -42,8 +41,6 @@ void FillTriangles(
|
|||
buffer->bind();
|
||||
buffer->allocate(coords.data(), coords.size() * sizeof(GLfloat));
|
||||
|
||||
f.glUseProgram(program->programId());
|
||||
program->setUniformValue("viewport", QSizeF(viewportWithFactor));
|
||||
program->setUniformValue("s_color", Uniform(color));
|
||||
|
||||
GLint position = program->attributeLocation("position");
|
||||
|
|
@ -65,6 +62,32 @@ void FillTriangles(
|
|||
f.glDisableVertexAttribArray(position);
|
||||
}
|
||||
|
||||
void FillRectangle(
|
||||
QOpenGLFunctions &f,
|
||||
not_null<QOpenGLShaderProgram*> program,
|
||||
int skipVertices,
|
||||
const QColor &color) {
|
||||
const auto shift = [&](int elements) {
|
||||
return reinterpret_cast<const void*>(
|
||||
(skipVertices * 4 + elements) * sizeof(GLfloat));
|
||||
};
|
||||
program->setUniformValue("s_color", Uniform(color));
|
||||
|
||||
GLint position = program->attributeLocation("position");
|
||||
f.glVertexAttribPointer(
|
||||
position,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
2 * sizeof(GLfloat),
|
||||
shift(0));
|
||||
f.glEnableVertexAttribArray(position);
|
||||
|
||||
f.glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
f.glDisableVertexAttribArray(position);
|
||||
}
|
||||
|
||||
void FillTexturedRectangle(
|
||||
QOpenGLFunctions &f,
|
||||
not_null<QOpenGLShaderProgram*> program,
|
||||
|
|
@ -120,8 +143,8 @@ void BackgroundFiller::fill(
|
|||
const QRegion ®ion,
|
||||
QSize viewport,
|
||||
float factor,
|
||||
const style::color &color) {
|
||||
const auto &rgb = color->c.toRgb();
|
||||
const QColor &color) {
|
||||
const auto rgb = color.toRgb();
|
||||
if (region.isEmpty()) {
|
||||
return;
|
||||
} else if (region.end() - region.begin() == 1
|
||||
|
|
@ -133,15 +156,18 @@ void BackgroundFiller::fill(
|
|||
_bgTriangles.resize((region.end() - region.begin()) * 12);
|
||||
auto coords = _bgTriangles.data();
|
||||
for (const auto rect : region) {
|
||||
FillRectVertices(coords, TransformRect(rect, viewport, factor));
|
||||
FillRectTriangleVertices(
|
||||
coords,
|
||||
TransformRect(rect, viewport, factor));
|
||||
coords += 12;
|
||||
}
|
||||
f.glUseProgram(_bgProgram->programId());
|
||||
_bgProgram->setUniformValue("viewport", QSizeF(viewport * factor));
|
||||
FillTriangles(
|
||||
f,
|
||||
_bgTriangles,
|
||||
&*_bgBuffer,
|
||||
&*_bgProgram,
|
||||
viewport * factor,
|
||||
rgb);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,17 +16,22 @@ class QOpenGLFunctions;
|
|||
|
||||
namespace Ui::GL {
|
||||
|
||||
void FillRectVertices(float *coords, Rect rect);
|
||||
|
||||
void FillRectTriangleVertices(float *coords, Rect rect);
|
||||
void FillTriangles(
|
||||
QOpenGLFunctions &f,
|
||||
gsl::span<const float> coords,
|
||||
not_null<QOpenGLBuffer*> buffer,
|
||||
not_null<QOpenGLShaderProgram*> program,
|
||||
QSize viewportWithFactor,
|
||||
const QColor &color,
|
||||
Fn<void()> additional = nullptr);
|
||||
|
||||
|
||||
void FillRectangle(
|
||||
QOpenGLFunctions &f,
|
||||
not_null<QOpenGLShaderProgram*> program,
|
||||
int skipVertices,
|
||||
const QColor &color);
|
||||
|
||||
void FillTexturedRectangle(
|
||||
QOpenGLFunctions &f,
|
||||
not_null<QOpenGLShaderProgram*> program,
|
||||
|
|
@ -42,7 +47,16 @@ public:
|
|||
const QRegion ®ion,
|
||||
QSize viewport,
|
||||
float factor,
|
||||
const style::color &color);
|
||||
const QColor &color);
|
||||
|
||||
void fill(
|
||||
QOpenGLFunctions &f,
|
||||
const QRegion ®ion,
|
||||
QSize viewport,
|
||||
float factor,
|
||||
const style::color &color) {
|
||||
return fill(f, region, viewport, factor, color->c);
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<QOpenGLBuffer> _bgBuffer;
|
||||
|
|
|
|||
|
|
@ -88,6 +88,17 @@ uniform sampler2D v_texture;
|
|||
};
|
||||
}
|
||||
|
||||
ShaderPart FragmentGlobalOpacity() {
|
||||
return {
|
||||
.header = R"(
|
||||
uniform float g_opacity;
|
||||
)",
|
||||
.body = R"(
|
||||
result *= g_opacity;
|
||||
)",
|
||||
};
|
||||
}
|
||||
|
||||
ShaderPart VertexViewportTransform() {
|
||||
return {
|
||||
.header = R"(
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ struct ShaderPart {
|
|||
[[nodiscard]] ShaderPart VertexPassTextureCoord(char prefix = 'v');
|
||||
[[nodiscard]] ShaderPart FragmentSampleARGB32Texture();
|
||||
[[nodiscard]] ShaderPart FragmentSampleYUV420Texture();
|
||||
[[nodiscard]] ShaderPart FragmentGlobalOpacity();
|
||||
[[nodiscard]] ShaderPart VertexViewportTransform();
|
||||
[[nodiscard]] ShaderPart FragmentRoundCorners();
|
||||
[[nodiscard]] ShaderPart FragmentStaticColor();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue