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>);
|
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[0] = coords[10] = rect.left();
|
||||||
coords[1] = coords[11] = rect.top();
|
coords[1] = coords[11] = rect.top();
|
||||||
coords[2] = rect.right();
|
coords[2] = rect.right();
|
||||||
|
|
@ -31,7 +31,6 @@ void FillTriangles(
|
||||||
gsl::span<const float> coords,
|
gsl::span<const float> coords,
|
||||||
not_null<QOpenGLBuffer*> buffer,
|
not_null<QOpenGLBuffer*> buffer,
|
||||||
not_null<QOpenGLShaderProgram*> program,
|
not_null<QOpenGLShaderProgram*> program,
|
||||||
QSize viewportWithFactor,
|
|
||||||
const QColor &color,
|
const QColor &color,
|
||||||
Fn<void()> additional) {
|
Fn<void()> additional) {
|
||||||
Expects(coords.size() % 6 == 0);
|
Expects(coords.size() % 6 == 0);
|
||||||
|
|
@ -42,8 +41,6 @@ void FillTriangles(
|
||||||
buffer->bind();
|
buffer->bind();
|
||||||
buffer->allocate(coords.data(), coords.size() * sizeof(GLfloat));
|
buffer->allocate(coords.data(), coords.size() * sizeof(GLfloat));
|
||||||
|
|
||||||
f.glUseProgram(program->programId());
|
|
||||||
program->setUniformValue("viewport", QSizeF(viewportWithFactor));
|
|
||||||
program->setUniformValue("s_color", Uniform(color));
|
program->setUniformValue("s_color", Uniform(color));
|
||||||
|
|
||||||
GLint position = program->attributeLocation("position");
|
GLint position = program->attributeLocation("position");
|
||||||
|
|
@ -65,6 +62,32 @@ void FillTriangles(
|
||||||
f.glDisableVertexAttribArray(position);
|
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(
|
void FillTexturedRectangle(
|
||||||
QOpenGLFunctions &f,
|
QOpenGLFunctions &f,
|
||||||
not_null<QOpenGLShaderProgram*> program,
|
not_null<QOpenGLShaderProgram*> program,
|
||||||
|
|
@ -120,8 +143,8 @@ void BackgroundFiller::fill(
|
||||||
const QRegion ®ion,
|
const QRegion ®ion,
|
||||||
QSize viewport,
|
QSize viewport,
|
||||||
float factor,
|
float factor,
|
||||||
const style::color &color) {
|
const QColor &color) {
|
||||||
const auto &rgb = color->c.toRgb();
|
const auto rgb = color.toRgb();
|
||||||
if (region.isEmpty()) {
|
if (region.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
} else if (region.end() - region.begin() == 1
|
} else if (region.end() - region.begin() == 1
|
||||||
|
|
@ -133,15 +156,18 @@ void BackgroundFiller::fill(
|
||||||
_bgTriangles.resize((region.end() - region.begin()) * 12);
|
_bgTriangles.resize((region.end() - region.begin()) * 12);
|
||||||
auto coords = _bgTriangles.data();
|
auto coords = _bgTriangles.data();
|
||||||
for (const auto rect : region) {
|
for (const auto rect : region) {
|
||||||
FillRectVertices(coords, TransformRect(rect, viewport, factor));
|
FillRectTriangleVertices(
|
||||||
|
coords,
|
||||||
|
TransformRect(rect, viewport, factor));
|
||||||
coords += 12;
|
coords += 12;
|
||||||
}
|
}
|
||||||
|
f.glUseProgram(_bgProgram->programId());
|
||||||
|
_bgProgram->setUniformValue("viewport", QSizeF(viewport * factor));
|
||||||
FillTriangles(
|
FillTriangles(
|
||||||
f,
|
f,
|
||||||
_bgTriangles,
|
_bgTriangles,
|
||||||
&*_bgBuffer,
|
&*_bgBuffer,
|
||||||
&*_bgProgram,
|
&*_bgProgram,
|
||||||
viewport * factor,
|
|
||||||
rgb);
|
rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,22 @@ class QOpenGLFunctions;
|
||||||
|
|
||||||
namespace Ui::GL {
|
namespace Ui::GL {
|
||||||
|
|
||||||
void FillRectVertices(float *coords, Rect rect);
|
void FillRectTriangleVertices(float *coords, Rect rect);
|
||||||
|
|
||||||
void FillTriangles(
|
void FillTriangles(
|
||||||
QOpenGLFunctions &f,
|
QOpenGLFunctions &f,
|
||||||
gsl::span<const float> coords,
|
gsl::span<const float> coords,
|
||||||
not_null<QOpenGLBuffer*> buffer,
|
not_null<QOpenGLBuffer*> buffer,
|
||||||
not_null<QOpenGLShaderProgram*> program,
|
not_null<QOpenGLShaderProgram*> program,
|
||||||
QSize viewportWithFactor,
|
|
||||||
const QColor &color,
|
const QColor &color,
|
||||||
Fn<void()> additional = nullptr);
|
Fn<void()> additional = nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
void FillRectangle(
|
||||||
|
QOpenGLFunctions &f,
|
||||||
|
not_null<QOpenGLShaderProgram*> program,
|
||||||
|
int skipVertices,
|
||||||
|
const QColor &color);
|
||||||
|
|
||||||
void FillTexturedRectangle(
|
void FillTexturedRectangle(
|
||||||
QOpenGLFunctions &f,
|
QOpenGLFunctions &f,
|
||||||
not_null<QOpenGLShaderProgram*> program,
|
not_null<QOpenGLShaderProgram*> program,
|
||||||
|
|
@ -42,7 +47,16 @@ public:
|
||||||
const QRegion ®ion,
|
const QRegion ®ion,
|
||||||
QSize viewport,
|
QSize viewport,
|
||||||
float factor,
|
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:
|
private:
|
||||||
std::optional<QOpenGLBuffer> _bgBuffer;
|
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() {
|
ShaderPart VertexViewportTransform() {
|
||||||
return {
|
return {
|
||||||
.header = R"(
|
.header = R"(
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ struct ShaderPart {
|
||||||
[[nodiscard]] ShaderPart VertexPassTextureCoord(char prefix = 'v');
|
[[nodiscard]] ShaderPart VertexPassTextureCoord(char prefix = 'v');
|
||||||
[[nodiscard]] ShaderPart FragmentSampleARGB32Texture();
|
[[nodiscard]] ShaderPart FragmentSampleARGB32Texture();
|
||||||
[[nodiscard]] ShaderPart FragmentSampleYUV420Texture();
|
[[nodiscard]] ShaderPart FragmentSampleYUV420Texture();
|
||||||
|
[[nodiscard]] ShaderPart FragmentGlobalOpacity();
|
||||||
[[nodiscard]] ShaderPart VertexViewportTransform();
|
[[nodiscard]] ShaderPart VertexViewportTransform();
|
||||||
[[nodiscard]] ShaderPart FragmentRoundCorners();
|
[[nodiscard]] ShaderPart FragmentRoundCorners();
|
||||||
[[nodiscard]] ShaderPart FragmentStaticColor();
|
[[nodiscard]] ShaderPart FragmentStaticColor();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue