This commit is contained in:
itsmattkc
2018-08-26 19:06:05 +10:00
parent 9ef6edf85f
commit a4246d1235
6 changed files with 99 additions and 42 deletions
+3 -3
View File
@@ -3,8 +3,8 @@
#include <QImage>
GaussianBlurEffect::GaussianBlurEffect(Clip *c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_GAUSSIANBLUR_EFFECT), frag(QOpenGLShader::Fragment), vert(QOpenGLShader::Vertex) {
enable_opengl = false;
enable_image = true;
enable_opengl = true;
enable_image = false;
vert.compileSourceCode("attribute vec2 position;\nvoid main() { gl_Position = vec4(position, 1, 1); }");
frag.compileSourceCode("uniform vec3 resolution;\nuniform sampler2D image;\nuniform bool flip;\nuniform vec2 direction;\n\nvoid main() {\n vec2 uv = vec2(gl_FragCoord.xy / resolution.xy);\n if (flip) {\n uv.y = 1.0 - uv.y;\n }\n\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 / resolution.xy)) * 0.3162162162;\n color += texture2D(image, uv - (off1 / resolution.xy)) * 0.3162162162;\n color += texture2D(image, uv + (off2 / resolution.xy)) * 0.0702702703;\n color += texture2D(image, uv - (off2 / resolution.xy)) * 0.0702702703;\n gl_FragColor = color;\n}\n");
@@ -80,7 +80,7 @@ void GaussianBlurEffect::process_image(double timecode, uint8_t *data, int width
void GaussianBlurEffect::process_gl(double timecode, GLTextureCoords &coords) {
program.bind();
program.setUniformValue("resolution", 1920, 1080, 0);
program.setUniformValue("flip", true);
program.setUniformValue("flip", false);
program.setUniformValue("direction", 0, 20);
}
+16 -10
View File
@@ -37,6 +37,7 @@
QTimer autorecovery_timer;
QString config_dir;
QString appName = "Olive (August 2018 | Alpha)";
void MainWindow::setup_layout() {
panel_project->show();
@@ -78,12 +79,11 @@ MainWindow::MainWindow(QWidget *parent) :
qApp->setPalette(darkPalette);
// end style
setWindowState(Qt::WindowMaximized);
ui->setupUi(this);
setWindowTitle("Olive (August 2018 | Alpha)");
updateTitle("");
setWindowState(Qt::WindowMaximized);
statusBar()->showMessage("Welcome to Olive");
setDockNestingEnabled(true);
@@ -111,7 +111,7 @@ MainWindow::MainWindow(QWidget *parent) :
autorecovery_filename = data_dir + "/autorecovery.ove";
if (QFile::exists(autorecovery_filename)) {
if (QMessageBox::question(NULL, "Auto-recovery", "Olive didn't close properly and an autorecovery file was detected. Would you like to open it?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
project_url = autorecovery_filename;
updateTitle(autorecovery_filename);
panel_project->load_project();
}
}
@@ -318,7 +318,7 @@ bool MainWindow::save_project_as() {
if (!fn.endsWith(".ove", Qt::CaseInsensitive)) {
fn += ".ove";
}
project_url = fn;
updateTitle(fn);
panel_project->save_project(false);
return true;
}
@@ -351,7 +351,12 @@ bool MainWindow::can_close_project() {
return false;
}
}
return true;
return true;
}
void MainWindow::updateTitle(const QString& url) {
project_url = url;
setWindowTitle(appName + " - " + ((project_url.isEmpty()) ? "<untitled>" : project_url));
}
void MainWindow::closeEvent(QCloseEvent *e) {
@@ -371,7 +376,7 @@ void MainWindow::on_action_Open_Project_triggered()
{
QString fn = QFileDialog::getOpenFileName(this, "Open Project...", "", OLIVE_FILE_FILTER);
if (!fn.isEmpty() && can_close_project()) {
project_url = fn;
updateTitle(fn);
panel_project->load_project();
undo_stack.clear();
}
@@ -384,6 +389,7 @@ void MainWindow::on_actionProject_triggered()
undo_stack.clear();
project_url.clear();
panel_project->new_project();
updateTitle("");
panel_timeline->redraw_all_clips(false);
panel_timeline->playhead = 0;
}
@@ -635,8 +641,8 @@ void MainWindow::load_recent_project() {
recent_projects.removeAt(index);
panel_project->save_recent_projects();
}
} else if (can_close_project()) {
project_url = recent_url;
} else if (can_close_project()) {
updateTitle(recent_url);
panel_project->load_project();
}
}
+1
View File
@@ -176,6 +176,7 @@ private:
bool save_project_as();
bool save_project();
bool can_close_project();
void updateTitle(const QString &url);
};
#endif // MAINWINDOW_H
+1
View File
@@ -140,6 +140,7 @@ void Viewer::update_sequence() {
update_end_timecode();
}
viewer_widget->initializeGL();
viewer_widget->repaint();
update();
+75 -29
View File
@@ -17,6 +17,7 @@
#include <QAudioOutput>
#include <QOpenGLShaderProgram>
#include <QtMath>
#include <QOpenGLFramebufferObject>
extern "C" {
#include <libavformat/avformat.h>
@@ -27,7 +28,8 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
multithreaded(true),
force_audio(false),
enable_paint(true),
flip(false)
flip(false),
fbo(NULL)
{
QSurfaceFormat format;
format.setDepthBufferSize(24);
@@ -59,15 +61,15 @@ void ViewerWidget::retry() {
update();
}
void ViewerWidget::initializeGL() {
void ViewerWidget::initializeGL() {
/*if (fbo != NULL) {
delete fbo;
fbo = NULL;
}*/
connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(deleteFunction()));
initializeOpenGLFunctions();
glClearColor(0, 0, 0, 1);
glMatrixMode(GL_PROJECTION);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
initializeOpenGLFunctions();
update();
}
@@ -80,6 +82,28 @@ void ViewerWidget::paintEvent(QPaintEvent *e) {
if (enable_paint) QOpenGLWidget::paintEvent(e);
}
GLuint ViewerWidget::draw_clip(GLuint texture) {
glPushMatrix();
glLoadIdentity();
glOrtho(0, 1, 0, 1, -1, 1);
fbo->bind();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); // top left
glVertex2f(0, 0); // top left
glTexCoord2f(1, 0); // top right
glVertex2f(1, 0); // top right
glTexCoord2f(1, 1); // bottom right
glVertex2f(1, 1); // bottom right
glTexCoord2f(0, 1); // bottom left
glVertex2f(0, 1); // bottom left
glEnd();
glBindTexture(GL_TEXTURE_2D, NULL);
fbo->release();
glPopMatrix();
return fbo->takeTexture();
}
void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
Sequence* s = sequence;
long playhead = panel_timeline->playhead;
@@ -160,17 +184,23 @@ void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
if (c->texture == NULL) {
qDebug() << "[WARNING] Texture hasn't been created yet";
texture_failed = true;
} else if (playhead >= c->timeline_in) {
MediaStream* ms = static_cast<Media*>(c->media)->get_stream_from_file_index(c->track < 0, c->media_stream);
} else if (playhead >= c->timeline_in) {
MediaStream* ms = static_cast<Media*>(c->media)->get_stream_from_file_index(c->track < 0, c->media_stream);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0, 1.0, 1.0, 1.0);
glLoadIdentity();
int half_width = sequence->width/2;
int half_height = sequence->height/2;
if (flip) half_height = -half_height;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0, 1.0, 1.0, 1.0);
glLoadIdentity();
glOrtho(-half_width, half_width, half_height, -half_height, -1, 1);
glViewport(0, 0, ms->video_width, ms->video_height);
int half_width = sequence->width/2;
int half_height = sequence->height/2;
if (flip) half_height = -half_height;
glOrtho(-half_width, half_width, half_height, -half_height, -1, 1);
// TEMP DEBUG CODE
if (fbo != NULL) delete fbo;
fbo = new QOpenGLFramebufferObject(ms->video_width, ms->video_height);
GLuint composite_texture = draw_clip(c->texture->textureId());
// END
GLTextureCoords coords;
coords.vertexTopLeftX = coords.vertexBottomLeftX = -ms->video_width/2;
@@ -180,11 +210,13 @@ void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
coords.textureTopLeftY = coords.textureTopRightY = coords.textureTopLeftX = coords.textureBottomLeftX = 0;
coords.textureBottomLeftY = coords.textureBottomRightY = coords.textureTopRightX = coords.textureBottomRightX = 1.0;
// EFFECT CODE START
for (int j=0;j<c->effects.size();j++) {
if (c->effects.at(j)->enable_opengl && c->effects.at(j)->is_enabled()) {
c->effects.at(j)->process_gl(((double)(panel_timeline->playhead-c->timeline_in+c->clip_in)/(double)sequence->frame_rate), coords);
composite_texture = draw_clip(composite_texture);
}
}
}
if (c->opening_transition != NULL) {
int transition_progress = playhead - c->timeline_in;
@@ -199,10 +231,22 @@ void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
c->closing_transition->process_transition((double)transition_progress/(double)c->closing_transition->length);
}
}
// EFFECT CODE END
c->texture->bind();
for (int j=0;j<c->effects.size();j++) {
if (c->effects.at(j)->enable_opengl && c->effects.at(j)->is_enabled()) {
c->effects.at(j)->clean_gl();
}
}
glBegin(GL_QUADS);
glViewport(0, 0, width(), height());
glBindTexture(GL_TEXTURE_2D, composite_texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBegin(GL_QUADS);
glTexCoord2f(coords.textureTopLeftX, coords.textureTopLeftY); // top left
glVertex2f(coords.vertexTopLeftX, coords.vertexTopLeftY); // top left
glTexCoord2f(coords.textureTopRightX, coords.textureTopRightY); // top right
@@ -211,15 +255,9 @@ void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
glVertex2f(coords.vertexBottomRightX, coords.vertexBottomRightY); // bottom right
glTexCoord2f(coords.textureBottomLeftX, coords.textureBottomLeftY); // bottom left
glVertex2f(coords.vertexBottomLeftX, coords.vertexBottomLeftY); // bottom left
glEnd();
glEnd();
c->texture->release();
for (int j=0;j<c->effects.size();j++) {
if (c->effects.at(j)->enable_opengl && c->effects.at(j)->is_enabled()) {
c->effects.at(j)->clean_gl();
}
}
glDeleteTextures(1, &composite_texture);
}
} else if (render_audio &&
c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
@@ -227,7 +265,7 @@ void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
// clip is not caching, start caching audio
cache_clip(c, playhead, false, false, c->audio_reset, nest);
c->lock.unlock();
}
}
break;
case MEDIA_TYPE_SEQUENCE:
nests.append(c);
@@ -239,6 +277,11 @@ void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
}
void ViewerWidget::paintGL() {
glClearColor(0, 0, 0, 1);
glMatrixMode(GL_PROJECTION);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
bool loop = true;
while (loop) {
loop = false;
@@ -261,4 +304,7 @@ void ViewerWidget::paintGL() {
}
}
}
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
+3
View File
@@ -10,6 +10,7 @@
#include <QMutex>
#include <QWaitCondition>
class QOpenGLFramebufferObject;
struct Clip;
struct Sequence;
@@ -30,10 +31,12 @@ protected:
// void resizeGL(int w, int h);
private:
QTimer retry_timer;
QOpenGLFramebufferObject* fbo;
private slots:
void retry();
void deleteFunction();
void compose_sequence(QVector<Clip*>& nests, bool render_audio);
GLuint draw_clip(GLuint texture);
};
#endif // VIEWERWIDGET_H