diff --git a/app/widget/viewer/viewerglwidget.cpp b/app/widget/viewer/viewerglwidget.cpp index bfdc011cf..7a9c0fee6 100644 --- a/app/widget/viewer/viewerglwidget.cpp +++ b/app/widget/viewer/viewerglwidget.cpp @@ -8,28 +8,44 @@ #include "render/gl/shadergenerators.h" ViewerGLWidget::ViewerGLWidget(QWidget *parent) : - QOpenGLWidget(parent) + QOpenGLWidget(parent), + texture_(0) { } +void ViewerGLWidget::SetTexture(GLuint tex) +{ + // Update the texture + texture_ = tex; + + // Paint the texture + update(); +} + +void ViewerGLWidget::initializeGL() +{ + // Re-retrieve pipeline pertaining to this context + pipeline_ = olive::gl::GetDefaultPipeline(); +} + void ViewerGLWidget::paintGL() { - /* + // Get functions attached to this context (they will already be initialized) QOpenGLFunctions* f = context()->functions(); - f->glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + // Clear background to empty + f->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); f->glClear(GL_COLOR_BUFFER_BIT); - QOpenGLTexture* tex = new QOpenGLTexture(img); + // Check if we have a texture to draw + if (texture_ > 0) { + // Bind retrieved texture + f->glBindTexture(GL_TEXTURE_2D, texture_); - ShaderPtr pipeline = olive::gl::GetDefaultPipeline(); + // Blit using the pipeline retrieved in initializeGL() + olive::gl::Blit(pipeline_, true); - tex->bind(); - - olive::gl::Blit(pipeline, true); - - tex->release(); - - delete tex; - */ + // Release retrieved texture + f->glBindTexture(GL_TEXTURE_2D, 0); + } } diff --git a/app/widget/viewer/viewerglwidget.h b/app/widget/viewer/viewerglwidget.h index ae84cc68b..eee686dda 100644 --- a/app/widget/viewer/viewerglwidget.h +++ b/app/widget/viewer/viewerglwidget.h @@ -1,18 +1,91 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + #ifndef VIEWERGLWIDGET_H #define VIEWERGLWIDGET_H #include +#include "render/gl/shaderptr.h" + +/** + * @brief The ViewerGLWidget class + * + * The inner display/rendering widget of a Viewer class. Actual rendering/composition occurs elsewhere offscreen and + * multithreaded, so its main purpose is receiving an OpenGL texture to display it. + * + * The main entry point is SetTexture() which will receive an OpenGL texture ID, store it, and then call update() to + * draw it on screen. The drawing function is in paintGL() (called during the update() process by Qt) and is fairly + * simple OpenGL drawing code standardized around OpenGL ES 3.2 Core. + * + * If the texture has been modified and you're 100% sure this widget is using the same texture object, it's possible + * to call update() directly to trigger a repaint, however this is not recommended. If you are not 100% sure it'll be + * the same texture object, use SetTexture() since it will nearly always be faster to just set it than to check *and* + * set it. + */ class ViewerGLWidget : public QOpenGLWidget { public: + /** + * @brief ViewerGLWidget Constructor + * + * @param parent + * + * QWidget parent. + */ ViewerGLWidget(QWidget* parent); + /** + * @brief Set the texture to draw and draw it + * + * Use this function + * + * @param tex + */ void SetTexture(GLuint tex); protected: + /** + * @brief Initialize function to set up the OpenGL context upon its construction + * + * Currently primarily used to regenerate the pipeline shader used for drawing. + */ + virtual void initializeGL() override; + + /** + * @brief Paint function to display the texture (received in SetTexture()) on screen. + * + * Simple OpenGL drawing function for painting the texture on screen. Standardized around OpenGL ES 3.2 Core. + */ virtual void paintGL() override; private: + /** + * @brief Internal reference to the OpenGL texture to draw. Set in SetTexture() and used in paintGL(). + */ GLuint texture_; + + /** + * @brief Internal shader object to use as the pipeline shader + * + * Retrieved every initializeGL() in order to stay up to date when new contexts are generated. + */ + ShaderPtr pipeline_; }; #endif // VIEWERGLWIDGET_H