Upgrade to OpenGL ES 3.2 (#1879)

* upgrade to opengl 3.2

* cornerpin: no need for hack

* renderer: Update OCIO shader language to ES 3.0

Co-authored-by: Thomas Wilshaw <thomaswilshaw@gmail.com>
This commit is contained in:
itsmattkc
2022-03-20 11:17:18 -07:00
committed by GitHub
co-authored by Thomas Wilshaw
parent cdf9efa7f6
commit a4056d8454
28 changed files with 136 additions and 131 deletions
+1 -2
View File
@@ -190,9 +190,8 @@ int main(int argc, char *argv[])
//
// https://bugreports.qt.io/browse/QTBUG-46140
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
format.setVersion(2, 0);
format.setVersion(3, 2);
format.setProfile(QSurfaceFormat::CoreProfile);
format.setOption(QSurfaceFormat::DeprecatedFunctions);
format.setDepthBufferSize(24);
QSurfaceFormat::setDefaultFormat(format);
@@ -97,18 +97,9 @@ void CornerPinDistortNode::Value(const NodeValueRow &value, const NodeGlobals &g
ShaderCode CornerPinDistortNode::GetShaderCode(const QString &shader_id) const
{
Q_UNUSED(shader_id)
QString frag = FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.frag"));
QString vert = FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.vert"));
// HACK: No good, very bad hack
#ifndef Q_OS_MAC
frag.prepend(QStringLiteral("#version 130\n\n"));
vert.prepend(QStringLiteral("#version 130\n\n"));
#else
vert.prepend(QStringLiteral("#extension GL_EXT_gpu_shader4 : require\n\n"));
#endif
return ShaderCode(frag, vert);
return ShaderCode(FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.frag")),
FileFunctions::ReadFileAsString(QStringLiteral(":/shaders/cornerpin.vert")));
}
QPointF CornerPinDistortNode::ValueToPixel(int value, const NodeValueRow& row, const QVector2D &resolution) const
+6 -5
View File
@@ -52,10 +52,10 @@ ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, const Q
vert = QStringLiteral("uniform mat4 %1;\n"
"\n"
"attribute vec4 a_position;\n"
"attribute vec2 a_texcoord;\n"
"in vec4 a_position;\n"
"in vec2 a_texcoord;\n"
"\n"
"varying vec2 ove_texcoord;\n"
"out vec2 ove_texcoord;\n"
"\n"
"void main() {\n"
" gl_Position = %1 * a_position;\n"
@@ -97,12 +97,13 @@ ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, const Q
frag = QStringLiteral("uniform %1 %3;\n"
"uniform %2 %4;\n"
"\n"
"varying vec2 ove_texcoord;\n"
"in vec2 ove_texcoord;\n"
"out vec4 frag_color;\n"
"\n"
"void main(void) {\n"
" vec4 c = %5;\n"
" c.a = clamp(c.a, 0.0, 1.0);\n" // Ensure alpha is between 0.0 and 1.0
" gl_FragColor = c;\n"
" frag_color = c;\n"
"}\n").arg(GetShaderUniformType(type_a),
GetShaderUniformType(type_b),
param_a_in,
+2 -7
View File
@@ -887,14 +887,9 @@ GLuint OpenGLRenderer::GetCachedTexture(int width, int height, int depth, VideoP
GLuint OpenGLRenderer::CompileShader(GLenum type, const QString &code)
{
static const QString shader_preamble =
#ifndef Q_OS_MAC
// Use appropriate GL ES 2.0 shader header
QStringLiteral("#version 100\n\n"
// Use appropriate GL 3.2 shader header
QStringLiteral("#version 150\n\n"
"precision highp float;\n\n");
#else
// Use desktop GL equivalent header because apparently macOS doesn't support the ES header
QStringLiteral("#version 120\n\n");
#endif
QString complete_code;
+1 -1
View File
@@ -116,7 +116,7 @@ bool Renderer::GetColorContext(ColorProcessorPtr color_processor, Renderer::Colo
// Create shader description
const char* ocio_func_name = "OCIODisplay";
auto shader_desc = OCIO::GpuShaderDesc::CreateShaderDesc();
shader_desc->setLanguage(OCIO::GPU_LANGUAGE_GLSL_1_3);
shader_desc->setLanguage(OCIO::GPU_LANGUAGE_GLSL_ES_3_0);
shader_desc->setFunctionName(ocio_func_name);
shader_desc->setResourcePrefix("ocio_");
+8 -7
View File
@@ -3,29 +3,30 @@ uniform sampler2D blend_in;
uniform bool base_in_enabled;
uniform bool blend_in_enabled;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
vec4 base_col = texture2D(base_in, ove_texcoord);
vec4 blend_col = texture2D(blend_in, ove_texcoord);
vec4 base_col = texture(base_in, ove_texcoord);
vec4 blend_col = texture(blend_in, ove_texcoord);
if (!base_in_enabled && !blend_in_enabled) {
gl_FragColor = vec4(0.0);
frag_color = vec4(0.0);
return;
}
if (!base_in_enabled) {
gl_FragColor = blend_col;
frag_color = blend_col;
return;
}
if (!blend_in_enabled) {
gl_FragColor = base_col;
frag_color = base_col;
return;
}
base_col *= 1.0 - blend_col.a;
base_col += blend_col;
gl_FragColor = base_col;
frag_color = base_col;
}
+4 -3
View File
@@ -8,7 +8,8 @@ uniform vec2 resolution_in;
uniform int ove_iteration;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
// Gaussian function uses PI
#define M_PI 3.1415926535897932384626433832795
@@ -63,7 +64,7 @@ void main(void) {
int mode = determine_mode();
if (mode == MODE_NONE) {
gl_FragColor = texture2D(tex_in, ove_texcoord);
frag_color = texture2D(tex_in, ove_texcoord);
return;
}
@@ -119,5 +120,5 @@ void main(void) {
}
}
gl_FragColor = composite;
frag_color = composite;
}
+4 -3
View File
@@ -10,7 +10,8 @@ uniform mat4 ove_cropmatrix;
#define ALPHA_ASSOC 2
// Main texture coordinate
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
// Program will replace this with OCIO's auto-generated shader code
%1
@@ -31,7 +32,7 @@ vec4 deassoc(vec4 c) {
void main() {
vec2 cropped_coord = (vec4(ove_texcoord-vec2(0.5, 0.5), 0.0, 1.0)*ove_cropmatrix).xy + vec2(0.5, 0.5);
if (cropped_coord.x < 0.0 || cropped_coord.x >= 1.0 || cropped_coord.y < 0.0 || cropped_coord.y >= 1.0) {
gl_FragColor = vec4(0.0);
frag_color = vec4(0.0);
return;
}
@@ -52,5 +53,5 @@ void main() {
col = assoc(col);
}
gl_FragColor = col;
frag_color = col;
}
+8 -7
View File
@@ -4,12 +4,13 @@ uniform sampler2D tex_in;
uniform bool perspective_in;
// Input texture coordinate
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
varying vec2 q;
varying vec2 b1;
varying vec2 b2;
varying vec2 b3;
in vec2 q;
in vec2 b1;
in vec2 b2;
in vec2 b3;
float Wedge2D(vec2 v, vec2 w) {
return (v.x*w.y) - (v.y*w.x);
@@ -17,7 +18,7 @@ float Wedge2D(vec2 v, vec2 w) {
void main() {
if(perspective_in){
gl_FragColor = texture2D(tex_in, ove_texcoord);
frag_color = texture2D(tex_in, ove_texcoord);
} else {
float A = Wedge2D(b2, b3);
float B = Wedge2D(b3, q) - Wedge2D(b1, b2);
@@ -43,6 +44,6 @@ void main() {
uv.y = 1.0 - uv.y;
gl_FragColor = texture2D(tex_in, uv);
frag_color = texture2D(tex_in, uv);
}
}
+7 -7
View File
@@ -8,15 +8,15 @@ uniform vec2 resolution_in;
uniform mat4 ove_mvpmat;
attribute vec4 a_position;
attribute vec2 a_texcoord;
in vec4 a_position;
in vec2 a_texcoord;
varying vec2 ove_texcoord;
out vec2 ove_texcoord;
varying vec2 q;
varying vec2 b1;
varying vec2 b2;
varying vec2 b3;
out vec2 q;
out vec2 b1;
out vec2 b2;
out vec2 b3;
void main() {
// The slider inputs only contain the amount they have changed rather than
+4 -3
View File
@@ -8,7 +8,8 @@ uniform float feather_in;
uniform vec2 resolution_in;
// Input texture coordinate
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main() {
float multiplier = 1.0;
@@ -45,8 +46,8 @@ void main() {
if (multiplier > 0.0) {
vec4 color = texture2D(tex_in, ove_texcoord) * multiplier;
gl_FragColor = color;
frag_color = color;
} else {
gl_FragColor = vec4(0.0);
frag_color = vec4(0.0);
}
}
+3 -2
View File
@@ -10,7 +10,8 @@ uniform int curve_in;
uniform float ove_tprog_all;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
float TransformCurve(float linear) {
if (curve_in == EXPONENTIAL_CURVE) {
@@ -33,5 +34,5 @@ void main(void) {
composite += texture2D(in_block_in, ove_texcoord) * TransformCurve(ove_tprog_all);
}
gl_FragColor = composite;
frag_color = composite;
}
+3 -2
View File
@@ -2,9 +2,10 @@
uniform sampler2D ove_maintex;
// Input texture coordinate
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main() {
vec4 color = texture2D(ove_maintex, ove_texcoord);
gl_FragColor = color;
frag_color = color;
}
+3 -3
View File
@@ -1,9 +1,9 @@
uniform mat4 ove_mvpmat;
attribute vec4 a_position;
attribute vec2 a_texcoord;
in vec4 a_position;
in vec2 a_texcoord;
varying vec2 ove_texcoord;
out vec2 ove_texcoord;
void main() {
gl_Position = ove_mvpmat * a_position;
+3 -2
View File
@@ -2,7 +2,8 @@ uniform sampler2D ove_maintex;
uniform vec2 resolution_in;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
float round(float x)
{
@@ -19,5 +20,5 @@ void main() {
using_texcoord.y = (round(using_texcoord.y * half_vert) + 0.25) / half_vert;
vec4 color = texture2D(ove_maintex, using_texcoord);
gl_FragColor = color;
frag_color = color;
}
+6 -5
View File
@@ -8,19 +8,20 @@ uniform float ove_tprog_all;
uniform float ove_tprog_out;
uniform float ove_tprog_in;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
if (out_block_in_enabled && in_block_in_enabled) {
vec4 out_block_col = mix(texture2D(out_block_in, ove_texcoord), color_in, ove_tprog_out);
vec4 in_block_col = mix(texture2D(in_block_in, ove_texcoord), color_in, 1.0 - ove_tprog_in);
gl_FragColor = out_block_col + in_block_col;
frag_color = out_block_col + in_block_col;
} else if (out_block_in_enabled) {
gl_FragColor = mix(texture2D(out_block_in, ove_texcoord), color_in, ove_tprog_all);
frag_color = mix(texture2D(out_block_in, ove_texcoord), color_in, ove_tprog_all);
} else if (in_block_in_enabled) {
gl_FragColor = mix(texture2D(in_block_in, ove_texcoord), color_in, 1.0 - ove_tprog_all);
frag_color = mix(texture2D(in_block_in, ove_texcoord), color_in, 1.0 - ove_tprog_all);
} else {
gl_FragColor = vec4(0.0);
frag_color = vec4(0.0);
}
}
+4 -3
View File
@@ -2,11 +2,12 @@ uniform sampler2D tex_in;
uniform bool horiz_in;
uniform bool vert_in;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
if (!horiz_in && !vert_in) {
gl_FragColor = texture2D(tex_in, ove_texcoord);
frag_color = texture2D(tex_in, ove_texcoord);
return;
}
@@ -15,5 +16,5 @@ void main(void) {
if (horiz_in) new_coord.x = 1.0 - new_coord.x;
if (vert_in) new_coord.y = 1.0 - new_coord.y;
gl_FragColor = texture2D(tex_in, new_coord);
frag_color = texture2D(tex_in, new_coord);
}
+4 -3
View File
@@ -2,14 +2,15 @@ uniform sampler2D top_tex_in;
uniform sampler2D bottom_tex_in;
uniform vec2 resolution_in;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main() {
float y_pixel = floor(ove_texcoord.y * resolution_in.y);
if (mod(y_pixel, 2.0) == 0.0) {
gl_FragColor = texture2D(top_tex_in, ove_texcoord);
frag_color = texture2D(top_tex_in, ove_texcoord);
} else {
gl_FragColor = texture2D(bottom_tex_in, ove_texcoord);
frag_color = texture2D(bottom_tex_in, ove_texcoord);
}
}
+3 -2
View File
@@ -5,7 +5,8 @@ uniform float horiz_in;
uniform float vert_in;
// Input texture coordinate
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main() {
float x;
@@ -24,5 +25,5 @@ void main() {
}
vec4 color = texture2D(tex_in, vec2(x, y));
gl_FragColor = color;
frag_color = color;
}
+3 -3
View File
@@ -1,11 +1,11 @@
uniform float time_in;
varying vec2 ove_texcoord;
uniform float strength_in;
uniform bool color_in;
//uniform bool blend;
// precision lowp float;
in vec2 ove_texcoord;
out vec4 frag_color;
float PHI = 1.61803398874989484820459 * 00000.1; // Golden Ratio
float PI = 3.14159265358979323846264 * 00000.1; // PI
@@ -34,5 +34,5 @@ void main(void) {
noise = vec3(gold_noise(ove_texcoord, time_in + 69420.0));
}
gl_FragColor = vec4(noise, 1.0);
frag_color = vec4(noise, 1.0);
}
+3 -2
View File
@@ -2,7 +2,8 @@ uniform sampler2D ove_maintex;
uniform vec2 viewport;
uniform float histogram_scale;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
float histogram_width = ceil(histogram_scale * viewport.y);
@@ -27,5 +28,5 @@ void main(void) {
);
}
gl_FragColor = vec4(sum, 1.0);
frag_color = vec4(sum, 1.0);
}
+3 -3
View File
@@ -1,9 +1,9 @@
uniform float histogram_scale;
attribute vec4 a_position;
attribute vec2 a_texcoord;
in vec4 a_position;
in vec2 a_texcoord;
varying vec2 ove_texcoord;
out vec2 ove_texcoord;
mat4 scale_mat4(vec3 scale) {
return mat4(
+3 -2
View File
@@ -4,7 +4,8 @@ uniform vec2 viewport;
uniform float histogram_scale;
uniform float histogram_power;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
vec3 col = vec3(0.0);
@@ -26,5 +27,5 @@ void main(void) {
histogram_ratio = pow(sum / total_pixels, vec3(histogram_power));
col = step(vec3(ove_texcoord.y), histogram_ratio);
gl_FragColor = vec4(col, 1.0);
frag_color = vec4(col, 1.0);
}
+3 -2
View File
@@ -5,7 +5,8 @@ uniform vec3 luma_coeffs;
uniform float waveform_scale;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
float waveform_height = ceil(waveform_scale * viewport.y);
@@ -33,5 +34,5 @@ void main(void) {
}
col.rgb += vec3(col.w);
gl_FragColor = vec4(col.rgb, 1.0);
frag_color = vec4(col.rgb, 1.0);
}
+3 -3
View File
@@ -1,9 +1,9 @@
uniform float waveform_scale;
attribute vec4 a_position;
attribute vec2 a_texcoord;
in vec4 a_position;
in vec2 a_texcoord;
varying vec2 ove_texcoord;
out vec2 ove_texcoord;
mat4 scale_mat4(vec3 scale) {
return mat4(
+3 -2
View File
@@ -1,5 +1,6 @@
// Input texture coordinate
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
// Match with ShapeNode::Type
#define SHAPE_RECTANGLE 0
@@ -37,5 +38,5 @@ void main() {
col = color_in * (1.0-t);
}
gl_FragColor = col;
frag_color = col;
}
+3 -1
View File
@@ -1,5 +1,7 @@
uniform vec4 color_in;
out vec4 frag_color;
void main(void) {
gl_FragColor = color_in;
frag_color = color_in;
}
+4 -3
View File
@@ -9,7 +9,8 @@ uniform vec2 resolution_in;
// Standard inputs
uniform int ove_iteration;
varying vec2 ove_texcoord;
in vec2 ove_texcoord;
out vec4 frag_color;
void main(void) {
vec4 pixel_here = texture2D(tex_in, ove_texcoord);
@@ -20,7 +21,7 @@ void main(void) {
|| (inner_in && pixel_here.a == 0.0)
|| (!inner_in && pixel_here.a == 1.0)) {
// No-op, do nothing
gl_FragColor = pixel_here;
frag_color = pixel_here;
return;
}
@@ -74,5 +75,5 @@ void main(void) {
stroke_col = stroke_col * (1.0 - pixel_here.a) + pixel_here;
}
gl_FragColor = stroke_col;
frag_color = stroke_col;
}