├── .gitignore ├── CMakeLists.txt ├── FboQuickView.cpp ├── FboQuickView.h ├── FboQuickWindow.cpp ├── FboQuickWindow.h ├── FboQuickWrapperWindow.cpp ├── FboQuickWrapperWindow.h ├── LICENSE ├── QuickLayer.h ├── QuickLayer.mm ├── QuickLayer.pri ├── QuickLayerDemo ├── MainWidget.h ├── MainWidget.mm ├── QuickLayerDemo.pro ├── demo.qml ├── main.cpp └── main.qrc └── WrapperWindowDemo ├── WrapperWindowDemo.pro ├── demo.qml ├── main.cpp └── main.qrc /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build-*/ 3 | *.pro.user 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 2.8.11 ) 2 | 3 | file( GLOB QUICK_LAYER_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 4 | [^.]*.cpp 5 | [^.]*.mm 6 | [^.]*.h 7 | ) 8 | 9 | find_package( Qt5Quick ) 10 | 11 | include_directories( ${_qt5Core_install_prefix}/include ) 12 | 13 | add_library( QuickLayer ${QUICK_LAYER_SRC} ) 14 | 15 | qt5_use_modules( QuickLayer Quick ) 16 | -------------------------------------------------------------------------------- /FboQuickView.cpp: -------------------------------------------------------------------------------- 1 | #include "FboQuickView.h" 2 | 3 | #include 4 | #include 5 | 6 | FboQuickView::FboQuickView( QOpenGLContext* context /*= 0*/ ) 7 | : FboQuickWindow( context ), m_qmlComponent( 0 ), m_rootItem( 0 ) 8 | { 9 | } 10 | 11 | FboQuickView::~FboQuickView() 12 | { 13 | } 14 | 15 | QQmlContext* FboQuickView::rootContext() const 16 | { 17 | return m_qmlEngine.rootContext(); 18 | } 19 | 20 | void FboQuickView::setSource( const QUrl& source ) 21 | { 22 | if( m_rootItem ) { 23 | delete m_rootItem; 24 | m_rootItem = 0; 25 | } 26 | 27 | if( m_qmlComponent ) { 28 | delete m_qmlComponent; 29 | m_qmlComponent = 0; 30 | } 31 | 32 | if( !source.isEmpty() ) { 33 | m_qmlComponent = new QQmlComponent( &m_qmlEngine, &m_qmlEngine ); 34 | connect( m_qmlComponent, &QQmlComponent::statusChanged, 35 | this, &FboQuickView::componentStatusChanged ); 36 | m_qmlComponent->loadUrl( source ); 37 | } 38 | } 39 | 40 | void FboQuickView::setQml( const QString& qml, const QUrl& qmlUrl ) 41 | { 42 | if( m_rootItem ) { 43 | delete m_rootItem; 44 | m_rootItem = 0; 45 | } 46 | 47 | if( m_qmlComponent ) { 48 | delete m_qmlComponent; 49 | m_qmlComponent = 0; 50 | } 51 | 52 | if( !qml.isEmpty() ) { 53 | m_qmlComponent = new QQmlComponent( &m_qmlEngine, &m_qmlEngine ); 54 | connect( m_qmlComponent, &QQmlComponent::statusChanged, 55 | this, &FboQuickView::componentStatusChanged ); 56 | m_qmlComponent->setData( qml.toUtf8(), qmlUrl ); 57 | } 58 | } 59 | 60 | void FboQuickView::componentStatusChanged( QQmlComponent::Status status ) 61 | { 62 | Q_ASSERT( !m_rootItem ); 63 | 64 | if( QQmlComponent::Ready != status ) { 65 | Q_EMIT statusChanged( status ); 66 | return; 67 | } 68 | 69 | QScopedPointer rootObject( m_qmlComponent->create() ); 70 | m_rootItem = qobject_cast( rootObject.data() ); 71 | 72 | if( !m_rootItem ) { 73 | Q_EMIT statusChanged( QQmlComponent::Error ); 74 | return; 75 | } 76 | 77 | contentItem()->setFocus( true ); 78 | rootObject.take()->setParent( contentItem() ); 79 | m_rootItem->setParentItem( contentItem() ); 80 | 81 | QResizeEvent event( size(), size() ); 82 | resizeEvent( &event ); 83 | 84 | Q_EMIT statusChanged( QQmlComponent::Ready ); 85 | } 86 | 87 | void FboQuickView::resizeEvent( QResizeEvent* event ) 88 | { 89 | FboQuickWindow::resizeEvent( event ); 90 | 91 | if( m_rootItem ) 92 | m_rootItem->setSize( QSizeF( width(), height() ) ); 93 | } 94 | 95 | QList FboQuickView::errors() const 96 | { 97 | if( m_qmlComponent ) 98 | return m_qmlComponent->errors(); 99 | 100 | return QList(); 101 | } 102 | 103 | FboQuickView::Status FboQuickView::status() const 104 | { 105 | if( !m_qmlComponent ) 106 | return QQmlComponent::Null; 107 | 108 | return m_qmlComponent->status(); 109 | } 110 | -------------------------------------------------------------------------------- /FboQuickView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "FboQuickWindow.h" 7 | 8 | class FboQuickView : public FboQuickWindow 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | //takes ownership over passed QOpenGLContext 14 | FboQuickView( QOpenGLContext* = 0 ); 15 | ~FboQuickView(); 16 | 17 | QQmlContext* rootContext() const; 18 | 19 | QList errors() const; 20 | 21 | typedef QQmlComponent::Status Status; 22 | Status status() const; 23 | 24 | Q_SIGNALS: 25 | void statusChanged( Status ); 26 | 27 | public Q_SLOTS: 28 | void setSource( const QUrl& ); 29 | void setQml( const QString& qml, const QUrl& qmlUrl ); 30 | 31 | private Q_SLOTS: 32 | void componentStatusChanged( QQmlComponent::Status ); 33 | 34 | protected: 35 | void resizeEvent( QResizeEvent* event ); 36 | 37 | private: 38 | QQmlEngine m_qmlEngine; 39 | QQmlComponent* m_qmlComponent; 40 | QQuickItem* m_rootItem; 41 | }; 42 | -------------------------------------------------------------------------------- /FboQuickWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "FboQuickWindow.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | QQuickRenderControl* FboQuickWindow::createRenderControl() 12 | { 13 | return ( m_renderControl = new QQuickRenderControl ); 14 | } 15 | 16 | FboQuickWindow::FboQuickWindow( QOpenGLContext* context /*= 0*/ ) 17 | : QQuickWindow( createRenderControl() ), 18 | m_context( 0 ), m_offscreenSurface( 0 ), m_fbo( 0 ), 19 | m_needPolishAndSync( true ) 20 | { 21 | connect( this, &QQuickWindow::sceneGraphInitialized, 22 | this, &FboQuickWindow::sceneGraphInitialized ); 23 | connect( this, &QQuickWindow::sceneGraphInvalidated, 24 | this, &FboQuickWindow::sceneGraphInitialized ); 25 | 26 | connect( m_renderControl, &QQuickRenderControl::renderRequested, 27 | this, &FboQuickWindow::renderRequested ); 28 | connect( m_renderControl, &QQuickRenderControl::sceneChanged, 29 | this, &FboQuickWindow::sceneChanged ); 30 | 31 | m_renderTimer.setSingleShot( true ); 32 | m_renderTimer.setInterval( 5 ); 33 | connect( &m_renderTimer, &QTimer::timeout, 34 | this, &FboQuickWindow::render ); 35 | 36 | if( context ) 37 | init( context ); 38 | } 39 | 40 | FboQuickWindow::~FboQuickWindow() 41 | { 42 | disconnect( this, &QQuickWindow::sceneGraphInitialized, 43 | this, &FboQuickWindow::sceneGraphInitialized ); 44 | disconnect( this, &QQuickWindow::sceneGraphInvalidated, 45 | this, &FboQuickWindow::sceneGraphInitialized ); 46 | 47 | disconnect( m_renderControl, &QQuickRenderControl::renderRequested, 48 | this, &FboQuickWindow::renderRequested ); 49 | disconnect( m_renderControl, &QQuickRenderControl::sceneChanged, 50 | this, &FboQuickWindow::sceneChanged ); 51 | 52 | if( m_context && m_offscreenSurface && 53 | m_context->makeCurrent( m_offscreenSurface ) ) 54 | { 55 | m_renderControl->invalidate(); 56 | } 57 | 58 | destroyFbo(); 59 | 60 | delete m_offscreenSurface; 61 | delete m_renderControl; 62 | } 63 | 64 | void FboQuickWindow::init( QOpenGLContext* extContext ) 65 | { 66 | Q_ASSERT( extContext ); 67 | Q_ASSERT( !m_context && !m_offscreenSurface && !m_fbo ); 68 | 69 | extContext->setParent( this ); 70 | m_context = extContext; 71 | 72 | QSurfaceFormat format; 73 | format.setDepthBufferSize( 16 ); 74 | format.setStencilBufferSize( 8 ); 75 | 76 | m_context = new QOpenGLContext( this ); 77 | m_context->setFormat( format ); 78 | m_context->setShareContext( extContext ); 79 | m_context->create(); 80 | 81 | m_offscreenSurface = new QOffscreenSurface(); 82 | m_offscreenSurface->setFormat( m_context->format() ); 83 | m_offscreenSurface->create(); 84 | 85 | m_context->makeCurrent( m_offscreenSurface ); 86 | m_renderControl->initialize( m_context ); 87 | m_context->doneCurrent(); 88 | } 89 | 90 | void FboQuickWindow::createFbo() 91 | { 92 | Q_ASSERT( !m_fbo ); 93 | 94 | QSize size = this->size(); 95 | if( m_context && size.width() && size.height() ) { 96 | m_fbo = 97 | new QOpenGLFramebufferObject( size, 98 | QOpenGLFramebufferObject::CombinedDepthStencil ); 99 | setRenderTarget( m_fbo ); 100 | } 101 | } 102 | 103 | void FboQuickWindow::destroyFbo() 104 | { 105 | delete m_fbo; 106 | m_fbo = 0; 107 | } 108 | 109 | void FboQuickWindow::sceneGraphInitialized() 110 | { 111 | createFbo(); 112 | } 113 | 114 | void FboQuickWindow::sceneGraphInvalidated() 115 | { 116 | destroyFbo(); 117 | } 118 | 119 | void FboQuickWindow::renderRequested() 120 | { 121 | if( !m_renderTimer.isActive() ) 122 | m_renderTimer.start(); 123 | } 124 | 125 | void FboQuickWindow::sceneChanged() 126 | { 127 | m_needPolishAndSync = true; 128 | if( !m_renderTimer.isActive() ) 129 | m_renderTimer.start(); 130 | } 131 | 132 | void FboQuickWindow::render() 133 | { 134 | if( m_fbo && m_context->makeCurrent( m_offscreenSurface ) ) { 135 | if( m_needPolishAndSync ) { 136 | m_needPolishAndSync = false; 137 | //FIXME! better do it in separate thread 138 | m_renderControl->polishItems(); 139 | m_renderControl->sync(); 140 | } 141 | m_renderControl->render(); 142 | 143 | resetOpenGLState(); 144 | 145 | m_context->functions()->glFlush(); 146 | 147 | m_context->doneCurrent(); 148 | 149 | Q_EMIT sceneRendered(); 150 | } 151 | } 152 | 153 | void FboQuickWindow::resizeEvent( QResizeEvent* ) 154 | { 155 | if( m_context && m_context->makeCurrent( m_offscreenSurface ) ) { 156 | destroyFbo(); 157 | createFbo(); 158 | m_context->doneCurrent(); 159 | } 160 | } 161 | 162 | void FboQuickWindow::resize( const QSize& newSize ) 163 | { 164 | //have to emulate resize event since Qt don't generate some events on hidden window 165 | QResizeEvent event( size(), newSize ); 166 | setGeometry( 0, 0, newSize.width(), newSize.height() ); 167 | resizeEvent( &event ); 168 | } 169 | 170 | void FboQuickWindow::resize( int w, int h ) 171 | { 172 | resize( QSize( w, h ) ); 173 | } 174 | -------------------------------------------------------------------------------- /FboQuickWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | QT_FORWARD_DECLARE_CLASS( QOffscreenSurface ) 8 | 9 | class FboQuickWindow : public QQuickWindow 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | //takes ownership over passed QOpenGLContext 15 | FboQuickWindow( QOpenGLContext* = 0 ); 16 | ~FboQuickWindow(); 17 | 18 | QOpenGLFramebufferObject* fbo() const 19 | { return m_fbo; } 20 | 21 | //takes ownership over passed QOpenGLContext 22 | void init( QOpenGLContext* ); 23 | 24 | QOpenGLContext* glContext() 25 | { return m_context; } 26 | 27 | void scheduleResize( const QSize& newSize ); 28 | void scheduleResize( int w, int h ); 29 | 30 | void resize( const QSize& newSize ); 31 | void resize( int w, int h ); 32 | 33 | Q_SIGNALS: 34 | void sceneRendered(); 35 | 36 | private: 37 | using QQuickWindow::resize; //it shouldn't be used directly 38 | 39 | protected: 40 | void resizeEvent( QResizeEvent* ); 41 | 42 | private Q_SLOTS: 43 | void sceneGraphInitialized(); 44 | void sceneGraphInvalidated(); 45 | 46 | void renderRequested(); 47 | void sceneChanged(); 48 | 49 | void render(); 50 | 51 | private: 52 | QQuickRenderControl* createRenderControl(); 53 | 54 | void createFbo(); 55 | void destroyFbo(); 56 | 57 | private: 58 | QQuickRenderControl* m_renderControl; 59 | 60 | QOpenGLContext* m_context; 61 | QOffscreenSurface* m_offscreenSurface; 62 | QOpenGLFramebufferObject* m_fbo; 63 | 64 | bool m_needPolishAndSync; 65 | QTimer m_renderTimer; 66 | }; 67 | -------------------------------------------------------------------------------- /FboQuickWrapperWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "FboQuickWrapperWindow.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "FboQuickWindow.h" 9 | 10 | FboQuickWrapperWindow::FboQuickWrapperWindow( FboQuickWindow* fqw, 11 | QWindow* parent /*= nullptr*/ ) 12 | : QWindow( parent ), m_fboWindow( fqw ), m_context( nullptr ), 13 | m_program( nullptr ) 14 | { 15 | setSurfaceType(QSurface::OpenGLSurface); 16 | 17 | QOpenGLContext* sourceContext = fqw->glContext(); 18 | QSurfaceFormat format = sourceContext->format(); 19 | 20 | setFormat( format ); 21 | 22 | m_context = new QOpenGLContext( this ); 23 | m_context->setShareContext( sourceContext ); 24 | m_context->setFormat( format ); 25 | m_context->create(); 26 | 27 | connect( fqw, &FboQuickWindow::sceneRendered, 28 | this, &FboQuickWrapperWindow::render ); 29 | } 30 | 31 | void FboQuickWrapperWindow::resizeEvent( QResizeEvent* e ) 32 | { 33 | m_fboWindow->resize( e->size() ); 34 | } 35 | 36 | void FboQuickWrapperWindow::exposeEvent( QExposeEvent* ) 37 | { 38 | render(); 39 | } 40 | 41 | void FboQuickWrapperWindow::render() 42 | { 43 | if( !isExposed() ) 44 | return; 45 | 46 | m_context->makeCurrent( this ); 47 | 48 | enum { 49 | aVertex = 0, 50 | aTexCoord = 1, 51 | }; 52 | 53 | if( !m_program ) { 54 | initializeOpenGLFunctions(); 55 | 56 | static const char* vertexShaderSource = 57 | "attribute highp vec4 a_vertex;" 58 | "attribute lowp vec2 a_texCoord;" 59 | "varying lowp vec2 v_texCoord;" 60 | "void main() {" 61 | " v_texCoord = a_texCoord;" 62 | " gl_Position = a_vertex;" 63 | "}"; 64 | 65 | static const char* fragmentShaderSource = 66 | "varying lowp vec2 v_texCoord;" 67 | "uniform sampler2D tex;" 68 | "void main() {" 69 | " gl_FragColor = vec4( texture2D( tex, v_texCoord ).rgb, 1.0 );" 70 | "}"; 71 | 72 | m_program = new QOpenGLShaderProgram( m_context ); 73 | m_program->addShaderFromSourceCode( QOpenGLShader::Vertex, 74 | vertexShaderSource ); 75 | m_program->addShaderFromSourceCode( QOpenGLShader::Fragment, 76 | fragmentShaderSource ); 77 | m_program->link(); 78 | 79 | m_program->bindAttributeLocation( "a_vertex", aVertex ); 80 | m_program->bindAttributeLocation( "a_texCoord", aTexCoord ); 81 | } 82 | 83 | if( QOpenGLFramebufferObject* fbo = m_fboWindow->fbo() ) { 84 | glViewport(0, 0, width(), height()); 85 | 86 | glBindTexture( GL_TEXTURE_2D, fbo->texture() ); 87 | 88 | m_program->bind(); 89 | 90 | //FIXME! replace with vbo 91 | static const GLfloat v[] = { 92 | -1. , 1. , 0. , 93 | 1. , -1. , 0. , 94 | -1. , -1. , 0. , 95 | 96 | 1. , -1. , 0. , 97 | -1. , 1. , 0. , 98 | 1. , 1. , 0. , 99 | }; 100 | 101 | static const GLfloat t[] = { 102 | 0., 1., 103 | 1., 0., 104 | 0., 0., 105 | 106 | 1., 0., 107 | 0., 1., 108 | 1., 1., 109 | }; 110 | 111 | glVertexAttribPointer( aVertex, 3, GL_FLOAT, GL_FALSE, 0, v ); 112 | glEnableVertexAttribArray( 0 ); 113 | 114 | glVertexAttribPointer( aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, t ); 115 | glEnableVertexAttribArray( 1 ); 116 | 117 | glDrawArrays( GL_TRIANGLES, 0, 6 ); 118 | 119 | m_program->release(); 120 | } 121 | 122 | m_context->swapBuffers( this ); 123 | } 124 | 125 | void FboQuickWrapperWindow::mouseMoveEvent( QMouseEvent* e ) 126 | { 127 | QMouseEvent mouseEvent( e->type(), e->localPos(), e->localPos(), 128 | e->button(), e->buttons(), e->modifiers() ); 129 | QCoreApplication::sendEvent( m_fboWindow, &mouseEvent ); 130 | } 131 | 132 | void FboQuickWrapperWindow::mousePressEvent( QMouseEvent* e ) 133 | { 134 | QMouseEvent mouseEvent( e->type(), e->localPos(), e->localPos(), 135 | e->button(), e->buttons(), e->modifiers() ); 136 | QCoreApplication::sendEvent( m_fboWindow, &mouseEvent ); 137 | } 138 | 139 | void FboQuickWrapperWindow::mouseReleaseEvent( QMouseEvent* e ) 140 | { 141 | QMouseEvent mouseEvent( e->type(), e->localPos(), e->localPos(), 142 | e->button(), e->buttons(), e->modifiers() ); 143 | QCoreApplication::sendEvent( m_fboWindow, &mouseEvent ); 144 | } 145 | 146 | void FboQuickWrapperWindow::keyPressEvent( QKeyEvent* e ) 147 | { 148 | QCoreApplication::sendEvent( m_fboWindow, e ); 149 | } 150 | 151 | void FboQuickWrapperWindow::keyReleaseEvent( QKeyEvent* e ) 152 | { 153 | QCoreApplication::sendEvent( m_fboWindow, e ); 154 | } 155 | 156 | void FboQuickWrapperWindow::wheelEvent( QWheelEvent* e ) 157 | { 158 | QWheelEvent wheelEvent( e->pos(), e->pos(), e->delta(), 159 | e->buttons(), e->modifiers(), e->orientation() ); 160 | } 161 | -------------------------------------------------------------------------------- /FboQuickWrapperWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | QT_FORWARD_DECLARE_CLASS( QOpenGLShaderProgram ) 7 | 8 | class FboQuickWindow; //#include "FboQuickWindow.h" 9 | 10 | class FboQuickWrapperWindow 11 | : public QWindow, 12 | protected QOpenGLFunctions 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | FboQuickWrapperWindow( FboQuickWindow*, QWindow* parent = nullptr ); 18 | 19 | protected: 20 | void exposeEvent( QExposeEvent* ) override; 21 | void resizeEvent( QResizeEvent* ) override; 22 | 23 | void keyPressEvent( QKeyEvent* ) override; 24 | void keyReleaseEvent( QKeyEvent* ) override; 25 | void mouseMoveEvent( QMouseEvent* ) override; 26 | void mousePressEvent( QMouseEvent* ) override; 27 | void mouseReleaseEvent( QMouseEvent* ) override; 28 | void wheelEvent( QWheelEvent* ) override; 29 | 30 | private: 31 | void render(); 32 | 33 | private: 34 | FboQuickWindow* m_fboWindow; 35 | QOpenGLContext* m_context; 36 | 37 | QOpenGLShaderProgram* m_program; 38 | }; 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | (This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.) 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | {description} 474 | Copyright (C) {year} {fullname} 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | {signature of Ty Coon}, 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | 506 | -------------------------------------------------------------------------------- /QuickLayer.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright © 2014 Sergey Radionov 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation; either version 2.1 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program; if not, write to the Free Software Foundation, 16 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 17 | *****************************************************************************/ 18 | 19 | #import 20 | 21 | class FboQuickWindow; //#include "FboQuickWindow.h" 22 | 23 | @interface QuickLayer : NSOpenGLLayer 24 | { 25 | } 26 | - (id) initWithFboQuickWindow: (FboQuickWindow*) quickWindow; 27 | @end 28 | -------------------------------------------------------------------------------- /QuickLayer.mm: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Copyright © 2014 Sergey Radionov 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation; either version 2.1 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program; if not, write to the Free Software Foundation, 16 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 17 | *****************************************************************************/ 18 | 19 | #include "FboQuickView.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "QuickLayer.h" 26 | 27 | #include 28 | 29 | @implementation QuickLayer 30 | 31 | FboQuickWindow* _quickWindow; 32 | GLuint _program; 33 | 34 | - (id) initWithFboQuickWindow: (FboQuickWindow*) quickWindow 35 | { 36 | self = [super init]; 37 | 38 | if( self != nil ) { 39 | _program = 0; 40 | _quickWindow = quickWindow; 41 | } 42 | 43 | return self; 44 | } 45 | 46 | - (NSOpenGLPixelFormat*) openGLPixelFormatForDisplayMask: (uint32_t) __unused mask 47 | { 48 | NSOpenGLPixelFormatAttribute attrs[] = { 49 | NSOpenGLPFAColorSize, 24, 50 | NSOpenGLPFAStencilSize, 8, 51 | NSOpenGLPFADepthSize, 16, 52 | NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy, 53 | 0 54 | }; 55 | 56 | return [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; 57 | } 58 | 59 | - (void)internalInit: (NSOpenGLContext*) context 60 | { 61 | GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER ); 62 | const GLchar* vertexShaderSource = 63 | "attribute vec4 a_vertex;" 64 | "attribute vec2 a_texCoord;" 65 | "varying vec2 v_texCoord;" 66 | "void main() {" 67 | " v_texCoord = a_texCoord;" 68 | " gl_Position = a_vertex;" 69 | "}"; 70 | glShaderSource( vertexShader, 1, &vertexShaderSource, NULL ); 71 | glCompileShader( vertexShader ); 72 | 73 | GLuint fragmentShader = glCreateShader( GL_FRAGMENT_SHADER ); 74 | const GLchar* fragmentShaderSource = 75 | "varying vec2 v_texCoord;" 76 | "uniform sampler2D tex;" 77 | "void main() {" 78 | " gl_FragColor = vec4( texture2D( tex, v_texCoord ).rgb, 1.0 );" 79 | "}"; 80 | glShaderSource( fragmentShader, 1, &fragmentShaderSource, NULL ); 81 | glCompileShader( fragmentShader ); 82 | 83 | _program = glCreateProgram(); 84 | 85 | glAttachShader( _program, vertexShader ); 86 | glAttachShader( _program, fragmentShader ); 87 | 88 | glBindAttribLocation( _program, 0, "a_vertex" ); 89 | glBindAttribLocation( _program, 1, "a_texCoord" ); 90 | 91 | glLinkProgram( _program ); 92 | 93 | [NSOpenGLContext clearCurrentContext]; 94 | 95 | QOpenGLContext* layerContext = new QOpenGLContext; 96 | layerContext->setNativeHandle( QVariant::fromValue( QCocoaNativeContext( context ) ) ); 97 | layerContext->create(); 98 | 99 | _quickWindow->resize( self.frame.size.width, self.frame.size.height ); 100 | _quickWindow->init( layerContext ); 101 | } 102 | 103 | - (void)drawInOpenGLContext: (NSOpenGLContext*) context 104 | pixelFormat: (NSOpenGLPixelFormat*) __unused pixelFormat 105 | forLayerTime: (CFTimeInterval) __unused timeInterval 106 | displayTime: (const CVTimeStamp*) __unused timeStamp 107 | { 108 | if( !_program ) 109 | [self internalInit: context]; 110 | 111 | if( QOpenGLFramebufferObject* fbo = _quickWindow->fbo() ) { 112 | glBindTexture( GL_TEXTURE_2D, fbo->texture() ); 113 | 114 | glUseProgram( _program ); 115 | 116 | //FIXME! replace with vbo 117 | GLfloat v[] = { 118 | -1. , 1. , 0. , 119 | 1. , -1. , 0. , 120 | -1. , -1. , 0. , 121 | 122 | 1. , -1. , 0. , 123 | -1. , 1. , 0. , 124 | 1. , 1. , 0. , 125 | }; 126 | 127 | GLfloat t[] = { 128 | 0., 1., 129 | 1., 0., 130 | 0., 0., 131 | 132 | 1., 0., 133 | 0., 1., 134 | 1., 1., 135 | }; 136 | 137 | glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, v ); 138 | glEnableVertexAttribArray( 0 ); 139 | 140 | glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, t ); 141 | glEnableVertexAttribArray( 1 ); 142 | 143 | glDrawArrays ( GL_TRIANGLES, 0, 6 ); 144 | 145 | glUseProgram( 0 ); 146 | } 147 | } 148 | 149 | @end 150 | -------------------------------------------------------------------------------- /QuickLayer.pri: -------------------------------------------------------------------------------- 1 | CONFIG += c++11 2 | 3 | QT += quick 4 | 5 | HEADERS += \ 6 | $$PWD/FboQuickWindow.h \ 7 | $$PWD/FboQuickView.h \ 8 | $$PWD/FboQuickWrapperWindow.h 9 | 10 | SOURCES += \ 11 | $$PWD/FboQuickWindow.cpp \ 12 | $$PWD/FboQuickView.cpp \ 13 | $$PWD/FboQuickWrapperWindow.cpp 14 | 15 | macx { 16 | HEADERS += \ 17 | $$PWD/QuickLayer.h \ 18 | 19 | OBJECTIVE_HEADERS += \ 20 | $$PWD/QuickLayer.h 21 | 22 | OBJECTIVE_SOURCES += \ 23 | $$PWD/QuickLayer.mm 24 | 25 | LIBS += -framework Cocoa -framework QuartzCore 26 | 27 | INCLUDEPATH += $(QTDIR)/include 28 | } 29 | 30 | INCLUDEPATH += $$PWD 31 | -------------------------------------------------------------------------------- /QuickLayerDemo/MainWidget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../FboQuickView.h" 6 | 7 | class MainWidget : public QWidget 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | MainWidget(); 13 | ~MainWidget(); 14 | 15 | private: 16 | FboQuickView m_fboQuickView; 17 | }; 18 | -------------------------------------------------------------------------------- /QuickLayerDemo/MainWidget.mm: -------------------------------------------------------------------------------- 1 | #include "MainWidget.h" 2 | 3 | #include "../QuickLayer.h" 4 | 5 | MainWidget::MainWidget() 6 | { 7 | NSView* nsView = reinterpret_cast( this->winId() ); 8 | 9 | QuickLayer* nsOglLayer = 10 | [[QuickLayer alloc] initWithFboQuickWindow: &m_fboQuickView]; 11 | [nsOglLayer setAsynchronous:YES]; 12 | [nsView setLayer: nsOglLayer]; 13 | [nsView setWantsLayer: YES]; 14 | 15 | m_fboQuickView.setSource( QUrl( QStringLiteral( "qrc:/demo.qml" ) ) ); 16 | } 17 | 18 | MainWidget::~MainWidget() 19 | { 20 | } 21 | -------------------------------------------------------------------------------- /QuickLayerDemo/QuickLayerDemo.pro: -------------------------------------------------------------------------------- 1 | QT += core gui widgets 2 | 3 | TARGET = QuickLayerDemo 4 | TEMPLATE = app 5 | 6 | HEADERS += \ 7 | MainWidget.h 8 | 9 | SOURCES += \ 10 | main.cpp 11 | 12 | OBJECTIVE_SOURCES += \ 13 | MainWidget.mm 14 | 15 | RESOURCES += main.qrc 16 | 17 | LIBS += -framework Cocoa -framework QuartzCore 18 | 19 | include( ../QuickLayer.pri ) 20 | -------------------------------------------------------------------------------- /QuickLayerDemo/demo.qml: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** In addition, as a special exception, Digia gives you certain additional 27 | ** rights. These rights are described in the Digia Qt LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | import QtQuick 2.0 35 | import QtQuick.Particles 2.0 36 | 37 | Rectangle { 38 | id: root 39 | 40 | gradient: Gradient { 41 | GradientStop { position: 0; color: mouse.pressed ? "lightsteelblue" : "steelblue" } 42 | GradientStop { position: 1; color: "black" } 43 | } 44 | 45 | Text { 46 | anchors.centerIn: parent 47 | text: "Qt Quick in a texture" 48 | font.pointSize: 40 49 | color: "white" 50 | 51 | SequentialAnimation on rotation { 52 | PauseAnimation { duration: 2500 } 53 | NumberAnimation { from: 0; to: 360; duration: 5000; easing.type: Easing.InOutCubic } 54 | loops: Animation.Infinite 55 | } 56 | } 57 | 58 | ParticleSystem { 59 | id: particles 60 | anchors.fill: parent 61 | 62 | ImageParticle { 63 | id: smoke 64 | system: particles 65 | anchors.fill: parent 66 | groups: ["A", "B"] 67 | source: "qrc:///particleresources/glowdot.png" 68 | colorVariation: 0 69 | color: "#00111111" 70 | } 71 | ImageParticle { 72 | id: flame 73 | anchors.fill: parent 74 | system: particles 75 | groups: ["C", "D"] 76 | source: "qrc:///particleresources/glowdot.png" 77 | colorVariation: 0.1 78 | color: "#00ff400f" 79 | } 80 | 81 | Emitter { 82 | id: fire 83 | system: particles 84 | group: "C" 85 | 86 | y: parent.height 87 | width: parent.width 88 | 89 | emitRate: 350 90 | lifeSpan: 3500 91 | 92 | acceleration: PointDirection { y: -17; xVariation: 3 } 93 | velocity: PointDirection {xVariation: 3} 94 | 95 | size: 24 96 | sizeVariation: 8 97 | endSize: 4 98 | } 99 | 100 | TrailEmitter { 101 | id: fireSmoke 102 | group: "B" 103 | system: particles 104 | follow: "C" 105 | width: root.width 106 | height: root.height - 68 107 | 108 | emitRatePerParticle: 1 109 | lifeSpan: 2000 110 | 111 | velocity: PointDirection {y:-17*6; yVariation: -17; xVariation: 3} 112 | acceleration: PointDirection {xVariation: 3} 113 | 114 | size: 36 115 | sizeVariation: 8 116 | endSize: 16 117 | } 118 | 119 | TrailEmitter { 120 | id: fireballFlame 121 | anchors.fill: parent 122 | system: particles 123 | group: "D" 124 | follow: "E" 125 | 126 | emitRatePerParticle: 120 127 | lifeSpan: 180 128 | emitWidth: TrailEmitter.ParticleSize 129 | emitHeight: TrailEmitter.ParticleSize 130 | emitShape: EllipseShape{} 131 | 132 | size: 16 133 | sizeVariation: 4 134 | endSize: 4 135 | } 136 | 137 | TrailEmitter { 138 | id: fireballSmoke 139 | anchors.fill: parent 140 | system: particles 141 | group: "A" 142 | follow: "E" 143 | 144 | emitRatePerParticle: 128 145 | lifeSpan: 2400 146 | emitWidth: TrailEmitter.ParticleSize 147 | emitHeight: TrailEmitter.ParticleSize 148 | emitShape: EllipseShape{} 149 | 150 | velocity: PointDirection {yVariation: 16; xVariation: 16} 151 | acceleration: PointDirection {y: -16} 152 | 153 | size: 24 154 | sizeVariation: 8 155 | endSize: 8 156 | } 157 | 158 | Emitter { 159 | id: balls 160 | system: particles 161 | group: "E" 162 | 163 | y: parent.height 164 | width: parent.width 165 | 166 | emitRate: 2 167 | lifeSpan: 7000 168 | 169 | velocity: PointDirection {y:-17*4*2; xVariation: 6*6} 170 | acceleration: PointDirection {y: 17*2; xVariation: 6*6} 171 | 172 | size: 8 173 | sizeVariation: 4 174 | } 175 | 176 | Turbulence { //A bit of turbulence makes the smoke look better 177 | anchors.fill: parent 178 | groups: ["A","B"] 179 | strength: 32 180 | system: particles 181 | } 182 | } 183 | 184 | onWidthChanged: particles.reset() 185 | onHeightChanged: particles.reset() 186 | 187 | MouseArea { 188 | id: mouse 189 | anchors.fill: parent 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /QuickLayerDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "MainWidget.h" 2 | #include 3 | 4 | int main( int argc, char *argv[] ) 5 | { 6 | QApplication a( argc, argv ); 7 | MainWidget w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /QuickLayerDemo/main.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | demo.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /WrapperWindowDemo/WrapperWindowDemo.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | 5 | SOURCES += main.cpp 6 | 7 | RESOURCES += main.qrc 8 | 9 | include( ../QuickLayer.pri ) 10 | 11 | CONFIG += c++11 12 | -------------------------------------------------------------------------------- /WrapperWindowDemo/demo.qml: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the examples of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** In addition, as a special exception, Digia gives you certain additional 27 | ** rights. These rights are described in the Digia Qt LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | import QtQuick 2.0 35 | import QtQuick.Particles 2.0 36 | 37 | Rectangle { 38 | id: root 39 | 40 | gradient: Gradient { 41 | GradientStop { position: 0; color: mouse.pressed ? "lightsteelblue" : "steelblue" } 42 | GradientStop { position: 1; color: "black" } 43 | } 44 | 45 | Text { 46 | anchors.centerIn: parent 47 | text: "Qt Quick in a texture" 48 | font.pointSize: 40 49 | color: "white" 50 | 51 | SequentialAnimation on rotation { 52 | PauseAnimation { duration: 2500 } 53 | NumberAnimation { from: 0; to: 360; duration: 5000; easing.type: Easing.InOutCubic } 54 | loops: Animation.Infinite 55 | } 56 | } 57 | 58 | ParticleSystem { 59 | id: particles 60 | anchors.fill: parent 61 | 62 | ImageParticle { 63 | id: smoke 64 | system: particles 65 | anchors.fill: parent 66 | groups: ["A", "B"] 67 | source: "qrc:///particleresources/glowdot.png" 68 | colorVariation: 0 69 | color: "#00111111" 70 | } 71 | ImageParticle { 72 | id: flame 73 | anchors.fill: parent 74 | system: particles 75 | groups: ["C", "D"] 76 | source: "qrc:///particleresources/glowdot.png" 77 | colorVariation: 0.1 78 | color: "#00ff400f" 79 | } 80 | 81 | Emitter { 82 | id: fire 83 | system: particles 84 | group: "C" 85 | 86 | y: parent.height 87 | width: parent.width 88 | 89 | emitRate: 350 90 | lifeSpan: 3500 91 | 92 | acceleration: PointDirection { y: -17; xVariation: 3 } 93 | velocity: PointDirection {xVariation: 3} 94 | 95 | size: 24 96 | sizeVariation: 8 97 | endSize: 4 98 | } 99 | 100 | TrailEmitter { 101 | id: fireSmoke 102 | group: "B" 103 | system: particles 104 | follow: "C" 105 | width: root.width 106 | height: root.height - 68 107 | 108 | emitRatePerParticle: 1 109 | lifeSpan: 2000 110 | 111 | velocity: PointDirection {y:-17*6; yVariation: -17; xVariation: 3} 112 | acceleration: PointDirection {xVariation: 3} 113 | 114 | size: 36 115 | sizeVariation: 8 116 | endSize: 16 117 | } 118 | 119 | TrailEmitter { 120 | id: fireballFlame 121 | anchors.fill: parent 122 | system: particles 123 | group: "D" 124 | follow: "E" 125 | 126 | emitRatePerParticle: 120 127 | lifeSpan: 180 128 | emitWidth: TrailEmitter.ParticleSize 129 | emitHeight: TrailEmitter.ParticleSize 130 | emitShape: EllipseShape{} 131 | 132 | size: 16 133 | sizeVariation: 4 134 | endSize: 4 135 | } 136 | 137 | TrailEmitter { 138 | id: fireballSmoke 139 | anchors.fill: parent 140 | system: particles 141 | group: "A" 142 | follow: "E" 143 | 144 | emitRatePerParticle: 128 145 | lifeSpan: 2400 146 | emitWidth: TrailEmitter.ParticleSize 147 | emitHeight: TrailEmitter.ParticleSize 148 | emitShape: EllipseShape{} 149 | 150 | velocity: PointDirection {yVariation: 16; xVariation: 16} 151 | acceleration: PointDirection {y: -16} 152 | 153 | size: 24 154 | sizeVariation: 8 155 | endSize: 8 156 | } 157 | 158 | Emitter { 159 | id: balls 160 | system: particles 161 | group: "E" 162 | 163 | y: parent.height 164 | width: parent.width 165 | 166 | emitRate: 2 167 | lifeSpan: 7000 168 | 169 | velocity: PointDirection {y:-17*4*2; xVariation: 6*6} 170 | acceleration: PointDirection {y: 17*2; xVariation: 6*6} 171 | 172 | size: 8 173 | sizeVariation: 4 174 | } 175 | 176 | Turbulence { //A bit of turbulence makes the smoke look better 177 | anchors.fill: parent 178 | groups: ["A","B"] 179 | strength: 32 180 | system: particles 181 | } 182 | } 183 | 184 | onWidthChanged: particles.reset() 185 | onHeightChanged: particles.reset() 186 | 187 | MouseArea { 188 | id: mouse 189 | anchors.fill: parent 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /WrapperWindowDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "FboQuickView.h" 5 | #include "FboQuickWrapperWindow.h" 6 | 7 | int main( int argc, char *argv[] ) 8 | { 9 | QGuiApplication app( argc, argv ); 10 | 11 | QSize size( 640, 480 ); 12 | 13 | QOpenGLContext* context = new QOpenGLContext; 14 | context->create(); 15 | FboQuickView fboQuickView( context ); 16 | fboQuickView.resize( size ); 17 | fboQuickView.setSource( QUrl( QStringLiteral( "qrc:/demo.qml" ) ) ); 18 | 19 | FboQuickWrapperWindow window( &fboQuickView ); 20 | window.resize( size ); 21 | window.show(); 22 | 23 | return app.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /WrapperWindowDemo/main.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | demo.qml 4 | 5 | 6 | --------------------------------------------------------------------------------