nearly finished gles transition

This commit is contained in:
itsmattkc
2019-03-17 18:19:12 +11:00
parent c8496ac2a8
commit 05ac0314d7
19 changed files with 344 additions and 392 deletions
+26 -31
View File
@@ -120,7 +120,7 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
parent_clip(c),
meta(em),
flags_(0),
glslProgram(nullptr),
shader_program_(nullptr),
texture(nullptr),
isOpen(false),
bound(false),
@@ -304,9 +304,9 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
for (int i=0;i<attributes.size();i++) {
const QXmlStreamAttribute& attr = attributes.at(i);
if (attr.name() == "vert") {
vertPath = attr.value().toString();
shader_vert_path_ = attr.value().toString();
} else if (attr.name() == "frag") {
fragPath = attr.value().toString();
shader_frag_path_ = attr.value().toString();
} else if (attr.name() == "iterations") {
setIterations(attr.value().toInt());
}
@@ -708,9 +708,9 @@ bool Effect::is_open() {
}
void Effect::validate_meta_path() {
if (!meta->path.isEmpty() || (vertPath.isEmpty() && fragPath.isEmpty())) return;
if (!meta->path.isEmpty() || (shader_vert_path_.isEmpty() && shader_frag_path_.isEmpty())) return;
QList<QString> effects_paths = get_effects_paths();
const QString& test_fn = vertPath.isEmpty() ? fragPath : vertPath;
const QString& test_fn = shader_vert_path_.isEmpty() ? shader_frag_path_ : shader_vert_path_;
for (int i=0;i<effects_paths.size();i++) {
if (QFileInfo::exists(effects_paths.at(i) + "/" + test_fn)) {
for (int j=0;j<olive::effects.size();j++) {
@@ -733,19 +733,19 @@ void Effect::open() {
if (QOpenGLContext::currentContext() == nullptr) {
qWarning() << "No current context to create a shader program for - will retry next repaint";
} else {
glslProgram = new QOpenGLShaderProgram();
shader_program_ = std::make_shared<QOpenGLShaderProgram>();
validate_meta_path();
bool glsl_compiled = true;
if (!vertPath.isEmpty()) {
if (glslProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, meta->path + "/" + vertPath)) {
if (!shader_vert_path_.isEmpty()) {
if (shader_program_->addShaderFromSourceFile(QOpenGLShader::Vertex, meta->path + "/" + shader_vert_path_)) {
qInfo() << "Vertex shader added successfully";
} else {
glsl_compiled = false;
qWarning() << "Vertex shader could not be added";
}
}
if (!fragPath.isEmpty()) {
if (glslProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, meta->path + "/" + fragPath)) {
if (!shader_frag_path_.isEmpty()) {
if (shader_program_->addShaderFromSourceFile(QOpenGLShader::Fragment, meta->path + "/" + shader_frag_path_)) {
qInfo() << "Fragment shader added successfully";
} else {
glsl_compiled = false;
@@ -753,7 +753,7 @@ void Effect::open() {
}
}
if (glsl_compiled) {
if (glslProgram->link()) {
if (shader_program_->link()) {
qInfo() << "Shader program linked successfully";
} else {
qWarning() << "Shader program failed to link";
@@ -771,15 +771,12 @@ void Effect::close() {
qWarning() << "Tried to close an effect that was already closed";
}
delete_texture();
if (glslProgram != nullptr) {
delete glslProgram;
glslProgram = nullptr;
}
shader_program_ = nullptr;
isOpen = false;
}
bool Effect::is_glsl_linked() {
return glslProgram != nullptr && glslProgram->isLinked();
return shader_program_ != nullptr && shader_program_->isLinked();
}
void Effect::startEffect() {
@@ -789,13 +786,13 @@ void Effect::startEffect() {
}
if (olive::CurrentRuntimeConfig.shaders_are_enabled
&& (Flags() & Effect::ShaderFlag)
&& glslProgram->isLinked()) {
bound = glslProgram->bind();
&& shader_program_->isLinked()) {
bound = shader_program_->bind();
}
}
void Effect::endEffect() {
if (bound) glslProgram->release();
if (bound) shader_program_->release();
bound = false;
}
@@ -827,9 +824,9 @@ EffectPtr Effect::copy(Clip *c) {
}
void Effect::process_shader(double timecode, GLTextureCoords&, int iteration) {
glslProgram->setUniformValue("resolution", parent_clip->media_width(), parent_clip->media_height());
glslProgram->setUniformValue("time", GLfloat(timecode));
glslProgram->setUniformValue("iteration", iteration);
shader_program_->setUniformValue("resolution", parent_clip->media_width(), parent_clip->media_height());
shader_program_->setUniformValue("time", GLfloat(timecode));
shader_program_->setUniformValue("iteration", iteration);
for (int i=0;i<rows.size();i++) {
EffectRow* row = rows.at(i);
@@ -840,14 +837,14 @@ void Effect::process_shader(double timecode, GLTextureCoords&, int iteration) {
case EffectField::EFFECT_FIELD_DOUBLE:
{
DoubleField* double_field = static_cast<DoubleField*>(field);
glslProgram->setUniformValue(double_field->id().toUtf8().constData(),
shader_program_->setUniformValue(double_field->id().toUtf8().constData(),
GLfloat(double_field->GetDoubleAt(timecode)));
}
break;
case EffectField::EFFECT_FIELD_COLOR:
{
ColorField* color_field = static_cast<ColorField*>(field);
glslProgram->setUniformValue(
shader_program_->setUniformValue(
color_field->id().toUtf8().constData(),
GLfloat(color_field->GetColorAt(timecode).redF()),
GLfloat(color_field->GetColorAt(timecode).greenF()),
@@ -856,10 +853,10 @@ void Effect::process_shader(double timecode, GLTextureCoords&, int iteration) {
}
break;
case EffectField::EFFECT_FIELD_BOOL:
glslProgram->setUniformValue(field->id().toUtf8().constData(), field->GetValueAt(timecode).toBool());
shader_program_->setUniformValue(field->id().toUtf8().constData(), field->GetValueAt(timecode).toBool());
break;
case EffectField::EFFECT_FIELD_COMBO:
glslProgram->setUniformValue(field->id().toUtf8().constData(), field->GetValueAt(timecode).toInt());
shader_program_->setUniformValue(field->id().toUtf8().constData(), field->GetValueAt(timecode).toInt());
break;
// can you even send a string to a uniform value?
@@ -1058,7 +1055,7 @@ void Effect::redraw(double) {
}
bool Effect::valueHasChanged(double timecode) {
if (cachedValues.size() == 0) {
if (cachedValues.isEmpty()) {
for (int i=0;i<row_count();i++) {
EffectRow* crow = row(i);
@@ -1089,10 +1086,8 @@ bool Effect::valueHasChanged(double timecode) {
}
void Effect::delete_texture() {
if (texture != nullptr) {
delete texture;
texture = nullptr;
}
delete texture;
texture = nullptr;
}
const EffectMeta* get_meta_from_name(const QString& input) {
+13 -28
View File
@@ -44,6 +44,7 @@
#include "ui/checkboxex.h"
#include "effectrow.h"
#include "effectgizmo.h"
#include "rendering/qopenglshaderprogramptr.h"
class Clip;
@@ -113,33 +114,17 @@ enum EffectInternal {
};
struct GLTextureCoords {
int grid_size;
QMatrix4x4 matrix;
int vertexTopLeftX;
int vertexTopLeftY;
int vertexTopLeftZ;
int vertexTopRightX;
int vertexTopRightY;
int vertexTopRightZ;
int vertexBottomLeftX;
int vertexBottomLeftY;
int vertexBottomLeftZ;
int vertexBottomRightX;
int vertexBottomRightY;
int vertexBottomRightZ;
QVector3D vertex_top_left;
QVector3D vertex_top_right;
QVector3D vertex_bottom_left;
QVector3D vertex_bottom_right;
float textureTopLeftX;
float textureTopLeftY;
float textureTopLeftQ;
float textureTopRightX;
float textureTopRightY;
float textureTopRightQ;
float textureBottomRightX;
float textureBottomRightY;
float textureBottomRightQ;
float textureBottomLeftX;
float textureBottomLeftY;
float textureBottomLeftQ;
QVector2D texture_top_left;
QVector2D texture_top_right;
QVector2D texture_bottom_left;
QVector2D texture_bottom_right;
int blendmode;
float opacity;
@@ -240,9 +225,9 @@ private slots:
void load_from_file();
protected:
// glsl effect
QOpenGLShaderProgram* glslProgram;
QString vertPath;
QString fragPath;
QOpenGLShaderProgramPtr shader_program_;
QString shader_vert_path_;
QString shader_frag_path_;
// superimpose effect
QImage img;
+3 -1
View File
@@ -183,7 +183,9 @@ QVariant EffectField::GetValueAt(double timecode)
} else {
QColor before_data = keyframes.at(before_keyframe).data.value<QColor>();
QColor after_data = keyframes.at(after_keyframe).data.value<QColor>();
value = QColor(lerp(before_data.red(), after_data.red(), progress), lerp(before_data.green(), after_data.green(), progress), lerp(before_data.blue(), after_data.blue(), progress));
value = QColor(lerp(before_data.red(), after_data.red(), progress),
lerp(before_data.green(), after_data.green(), progress),
lerp(before_data.blue(), after_data.blue(), progress));
}
persistent_data_ = value;
break;
+1 -1
View File
@@ -45,7 +45,7 @@ class EffectGizmo : public QObject {
public:
EffectGizmo(Effect* parent, int type);
QVector<QPoint> world_pos;
QVector<QVector3D> world_pos;
QVector<QPoint> screen_pos;
DoubleField* x_field1;
+15 -19
View File
@@ -63,35 +63,31 @@ CornerPinEffect::CornerPinEffect(Clip* c, const EffectMeta *em) : Effect(c, em)
bottom_right_gizmo->x_field1 = bottom_right_x;
bottom_right_gizmo->y_field1 = bottom_right_y;
vertPath = "cornerpin.vert";
fragPath = "cornerpin.frag";
shader_vert_path_ = "cornerpin.vert";
shader_frag_path_ = "cornerpin.frag";
}
void CornerPinEffect::process_coords(double timecode, GLTextureCoords &coords, int) {
coords.vertexTopLeftX += top_left_x->GetDoubleAt(timecode);
coords.vertexTopLeftY += top_left_y->GetDoubleAt(timecode);
coords.vertex_top_left += QVector3D(top_left_x->GetDoubleAt(timecode), top_left_y->GetDoubleAt(timecode), 0.0f);
coords.vertexTopRightX += top_right_x->GetDoubleAt(timecode);
coords.vertexTopRightY += top_right_y->GetDoubleAt(timecode);
coords.vertex_top_right += QVector3D(top_right_x->GetDoubleAt(timecode), top_right_y->GetDoubleAt(timecode), 0.0f);
coords.vertexBottomLeftX += bottom_left_x->GetDoubleAt(timecode);
coords.vertexBottomLeftY += bottom_left_y->GetDoubleAt(timecode);
coords.vertex_bottom_left += QVector3D(bottom_left_x->GetDoubleAt(timecode), bottom_left_y->GetDoubleAt(timecode), 0.0f);
coords.vertexBottomRightX += bottom_right_x->GetDoubleAt(timecode);
coords.vertexBottomRightY += bottom_right_y->GetDoubleAt(timecode);
coords.vertex_bottom_right += QVector3D(bottom_right_x->GetDoubleAt(timecode), bottom_right_y->GetDoubleAt(timecode), 0.0f);
}
void CornerPinEffect::process_shader(double timecode, GLTextureCoords &coords, int) {
glslProgram->setUniformValue("p0", GLfloat(coords.vertexBottomLeftX), GLfloat(coords.vertexBottomLeftY));
glslProgram->setUniformValue("p1", GLfloat(coords.vertexBottomRightX), GLfloat(coords.vertexBottomRightY));
glslProgram->setUniformValue("p2", GLfloat(coords.vertexTopLeftX), GLfloat(coords.vertexTopLeftY));
glslProgram->setUniformValue("p3", GLfloat(coords.vertexTopRightX), GLfloat(coords.vertexTopRightY));
glslProgram->setUniformValue("perspective", perspective->GetBoolAt(timecode));
shader_program_->setUniformValue("p0", coords.vertex_bottom_left.x(), coords.vertex_bottom_left.y());
shader_program_->setUniformValue("p1", coords.vertex_bottom_right.x(), coords.vertex_bottom_right.y());
shader_program_->setUniformValue("p2", coords.vertex_top_left.x(), coords.vertex_top_left.y());
shader_program_->setUniformValue("p3", coords.vertex_top_right.x(), coords.vertex_top_right.y());
shader_program_->setUniformValue("perspective", perspective->GetBoolAt(timecode));
}
void CornerPinEffect::gizmo_draw(double, GLTextureCoords &coords) {
top_left_gizmo->world_pos[0] = QPoint(coords.vertexTopLeftX, coords.vertexTopLeftY);
top_right_gizmo->world_pos[0] = QPoint(coords.vertexTopRightX, coords.vertexTopRightY);
bottom_right_gizmo->world_pos[0] = QPoint(coords.vertexBottomRightX, coords.vertexBottomRightY);
bottom_left_gizmo->world_pos[0] = QPoint(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
top_left_gizmo->world_pos[0] = coords.vertex_top_left;
top_right_gizmo->world_pos[0] = coords.vertex_top_right;
bottom_right_gizmo->world_pos[0] = coords.vertex_bottom_right;
bottom_left_gizmo->world_pos[0] = coords.vertex_bottom_left;
}
+4 -9
View File
@@ -78,15 +78,10 @@ void ShakeEffect::process_coords(double timecode, GLTextureCoords& coords, int)
yoff *= multiplier;
rotoff *= rotmult;
coords.vertexTopLeftX += xoff;
coords.vertexTopRightX += xoff;
coords.vertexBottomLeftX += xoff;
coords.vertexBottomRightX += xoff;
coords.vertexTopLeftY += yoff;
coords.vertexTopRightY += yoff;
coords.vertexBottomLeftY += yoff;
coords.vertexBottomRightY += yoff;
coords.vertex_top_left += QVector3D(xoff, yoff, 0.0);
coords.vertex_top_right += QVector3D(xoff, yoff, 0.0);
coords.vertex_bottom_left += QVector3D(xoff, yoff, 0.0);
coords.vertex_bottom_right += QVector3D(xoff, yoff, 0.0);
glRotatef(rotoff, 0, 0, 1);
}
+2 -2
View File
@@ -151,8 +151,8 @@ TextEffect::TextEffect(Clip* c, const EffectMeta* em) :
connect(shadow_bool, SIGNAL(Toggled(bool)), this, SLOT(shadow_enable(bool)));
connect(outline_bool, SIGNAL(Toggled(bool)), this, SLOT(outline_enable(bool)));
vertPath = "common.vert";
fragPath = "dropshadow.frag";
shader_vert_path_ = "common.vert";
shader_frag_path_ = "dropshadow.frag";
}
void TextEffect::redraw(double timecode) {
+28 -21
View File
@@ -198,14 +198,10 @@ void TransformEffect::process_coords(double timecode, GLTextureCoords& coords, i
int anchor_x_offset = qRound(anchor_x_box->GetDoubleAt(timecode));
int anchor_y_offset = qRound(anchor_y_box->GetDoubleAt(timecode));
coords.vertexTopLeftX -= anchor_x_offset;
coords.vertexTopRightX -= anchor_x_offset;
coords.vertexBottomLeftX -= anchor_x_offset;
coords.vertexBottomRightX -= anchor_x_offset;
coords.vertexTopLeftY -= anchor_y_offset;
coords.vertexTopRightY -= anchor_y_offset;
coords.vertexBottomLeftY -= anchor_y_offset;
coords.vertexBottomRightY -= anchor_y_offset;
coords.vertex_top_left -= QVector3D(anchor_x_offset, anchor_y_offset, 0.0f);
coords.vertex_top_right -= QVector3D(anchor_x_offset, anchor_y_offset, 0.0f);
coords.vertex_bottom_left -= QVector3D(anchor_x_offset, anchor_y_offset, 0.0f);
coords.vertex_bottom_right -= QVector3D(anchor_x_offset, anchor_y_offset, 0.0f);
// rotation
glRotated(rotation->GetDoubleAt(timecode), 0, 0, 1);
@@ -223,19 +219,30 @@ void TransformEffect::process_coords(double timecode, GLTextureCoords& coords, i
}
void TransformEffect::gizmo_draw(double, GLTextureCoords& coords) {
top_left_gizmo->world_pos[0] = QPoint(coords.vertexTopLeftX, coords.vertexTopLeftY);
top_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexTopLeftX, coords.vertexTopRightX, 0.5), lerp(coords.vertexTopLeftY, coords.vertexTopRightY, 0.5));
top_right_gizmo->world_pos[0] = QPoint(coords.vertexTopRightX, coords.vertexTopRightY);
right_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexTopRightX, coords.vertexBottomRightX, 0.5), lerp(coords.vertexTopRightY, coords.vertexBottomRightY, 0.5));
bottom_right_gizmo->world_pos[0] = QPoint(coords.vertexBottomRightX, coords.vertexBottomRightY);
bottom_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexBottomRightX, coords.vertexBottomLeftX, 0.5), lerp(coords.vertexBottomRightY, coords.vertexBottomLeftY, 0.5));
bottom_left_gizmo->world_pos[0] = QPoint(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
left_center_gizmo->world_pos[0] = QPoint(lerp(coords.vertexBottomLeftX, coords.vertexTopLeftX, 0.5), lerp(coords.vertexBottomLeftY, coords.vertexTopLeftY, 0.5));
top_left_gizmo->world_pos[0] = coords.vertex_top_left;
top_right_gizmo->world_pos[0] = coords.vertex_top_right;
bottom_right_gizmo->world_pos[0] = coords.vertex_bottom_right;
bottom_left_gizmo->world_pos[0] = coords.vertex_bottom_left;
rotate_gizmo->world_pos[0] = QPoint(lerp(top_center_gizmo->world_pos[0].x(), bottom_center_gizmo->world_pos[0].x(), -0.1), lerp(top_center_gizmo->world_pos[0].y(), bottom_center_gizmo->world_pos[0].y(), -0.1));
top_center_gizmo->world_pos[0] = QVector3D(lerp(coords.vertex_top_left.x(), coords.vertex_top_right.x(), 0.5),
lerp(coords.vertex_top_left.y(), coords.vertex_top_right.y(), 0.5),
0.0f);
right_center_gizmo->world_pos[0] = QVector3D(lerp(coords.vertex_top_right.x(), coords.vertex_bottom_right.x(), 0.5),
lerp(coords.vertex_top_right.y(), coords.vertex_bottom_right.y(), 0.5),
0.0f);
bottom_center_gizmo->world_pos[0] = QVector3D(lerp(coords.vertex_bottom_right.x(), coords.vertex_bottom_left.x(), 0.5),
lerp(coords.vertex_bottom_right.y(), coords.vertex_bottom_left.y(), 0.5),
0.0f);
left_center_gizmo->world_pos[0] = QVector3D(lerp(coords.vertex_bottom_left.x(), coords.vertex_top_left.x(), 0.5),
lerp(coords.vertex_bottom_left.y(), coords.vertex_top_left.y(), 0.5),
0.0f);
rect_gizmo->world_pos[0] = QPoint(coords.vertexTopLeftX, coords.vertexTopLeftY);
rect_gizmo->world_pos[1] = QPoint(coords.vertexTopRightX, coords.vertexTopRightY);
rect_gizmo->world_pos[2] = QPoint(coords.vertexBottomRightX, coords.vertexBottomRightY);
rect_gizmo->world_pos[3] = QPoint(coords.vertexBottomLeftX, coords.vertexBottomLeftY);
rotate_gizmo->world_pos[0] = QVector3D(lerp(top_center_gizmo->world_pos[0].x(), bottom_center_gizmo->world_pos[0].x(), -0.1),
lerp(top_center_gizmo->world_pos[0].y(), bottom_center_gizmo->world_pos[0].y(), -0.1),
0.0f);
rect_gizmo->world_pos[0] = coords.vertex_top_left;
rect_gizmo->world_pos[1] = coords.vertex_top_right;
rect_gizmo->world_pos[2] = coords.vertex_bottom_right;
rect_gizmo->world_pos[3] = coords.vertex_bottom_left;
}