Skip to content

Commit

Permalink
Add most of the work for in-viewer parameters. Also remove glew depen…
Browse files Browse the repository at this point in the history
…dency and move to glfw + glad (for offscreen rendering). See tools/utils/generate_glad.sh
  • Loading branch information
MrKepzie committed May 17, 2016
1 parent bbcfb38 commit a11e076
Show file tree
Hide file tree
Showing 125 changed files with 13,496 additions and 12,062 deletions.
2 changes: 1 addition & 1 deletion App/App.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ win32 {
CONFIG += app
}
CONFIG += moc
CONFIG += boost glew opengl qt cairo python shiboken pyside
CONFIG += boost opengl qt cairo python shiboken pyside glfw
CONFIG += static-gui static-engine static-host-support static-breakpadclient static-libmv static-openmvg static-ceres static-qhttpserver

QT += gui core opengl network
Expand Down
7 changes: 7 additions & 0 deletions Engine/AppInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ AppInstance::load(const CLArgs& cl,
return;
}

if (getAppID() == 0) {
QString missingOpenGLError;
if (!appPTR->hasPlatformNecessaryOpenGLRequirements(&missingOpenGLError)) {
throw std::runtime_error(missingOpenGLError.toStdString());
}
}

///if the app is a background project autorun and the project name is empty just throw an exception.
if ( ( (appPTR->getAppType() == AppManager::eAppTypeBackgroundAutoRun) ||
( appPTR->getAppType() == AppManager::eAppTypeBackgroundAutoRunLaunchedFromGui) ) ) {
Expand Down
83 changes: 78 additions & 5 deletions Engine/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#endif
#endif


#include <cairo/cairo.h>
#include <boost/version.hpp>

#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QTextCodec>
Expand All @@ -63,7 +67,7 @@


#include "Global/ProcInfo.h"

#include "Global/GLIncludes.h"

#include "Engine/AppInstance.h"
#include "Engine/Backdrop.h"
Expand Down Expand Up @@ -97,6 +101,11 @@

#include "sbkversion.h" // shiboken/pyside version

#define GLFW_VERSION_STRING NATRON_VERSION_STRINGIZE( \
GLFW_VERSION_MAJOR, \
GLFW_VERSION_MINOR, \
GLFW_VERSION_REVISION)

#if QT_VERSION < 0x050000
Q_DECLARE_METATYPE(QAbstractSocket::SocketState)
#endif
Expand Down Expand Up @@ -375,6 +384,8 @@ AppManager::~AppManager()
_imp->_viewerCache.reset();
_imp->_diskCache.reset();

// free OpenGL resources of glfw
_imp->teardownGlfw();
tearDownPython();

_instance = 0;
Expand Down Expand Up @@ -545,6 +556,9 @@ AppManager::loadInternal(const CLArgs& cl)
# endif


// Initialize OpenGL
_imp->initGlfw();

_imp->_settings.reset( new Settings() );
_imp->_settings->initializeKnobsPublic();
///Call restore after initializing knobs
Expand Down Expand Up @@ -1129,8 +1143,17 @@ AppManager::registerBuiltInPlugin(const QString& iconPath,
for (std::list<std::string>::iterator it = grouping.begin(); it != grouping.end(); ++it) {
qgrouping.push_back( QString::fromUtf8( it->c_str() ) );
}
Plugin* p = registerPlugin(qgrouping, QString::fromUtf8( node->getPluginID().c_str() ), QString::fromUtf8( node->getPluginLabel().c_str() ),

// Empty since statically bundled
QString resourcesPath = QString();

Plugin* p = registerPlugin(resourcesPath,qgrouping, QString::fromUtf8( node->getPluginID().c_str() ), QString::fromUtf8( node->getPluginLabel().c_str() ),
iconPath, QStringList(), node->isReader(), node->isWriter(), binary, node->renderThreadSafety() == eRenderSafetyUnsafe, node->getMajorVersion(), node->getMinorVersion(), isDeprecated);

std::list<PluginActionShortcut> shortcuts;
node->getPluginShortcuts(&shortcuts);
p->setShorcuts(shortcuts);

if (internalUseOnly) {
p->setForInternalUseOnly(true);
}
Expand Down Expand Up @@ -1528,7 +1551,7 @@ AppManager::loadPythonGroups()
if (gotInfos) {
qDebug() << "Loading " << moduleName;
QStringList grouping = QString::fromUtf8( pluginGrouping.c_str() ).split( QChar::fromLatin1('/') );
Plugin* p = registerPlugin(grouping, QString::fromUtf8( pluginID.c_str() ), QString::fromUtf8( pluginLabel.c_str() ), QString::fromUtf8( iconFilePath.c_str() ), QStringList(), false, false, 0, false, version, 0, false);
Plugin* p = registerPlugin(modulePath, grouping, QString::fromUtf8( pluginID.c_str() ), QString::fromUtf8( pluginLabel.c_str() ), QString::fromUtf8( iconFilePath.c_str() ), QStringList(), false, false, 0, false, version, 0, false);

p->setPythonModule(modulePath + moduleName);
p->setToolsetScript(isToolset);
Expand All @@ -1537,7 +1560,8 @@ AppManager::loadPythonGroups()
} // AppManager::loadPythonGroups

Plugin*
AppManager::registerPlugin(const QStringList & groups,
AppManager::registerPlugin(const QString& resourcesPath,
const QStringList & groups,
const QString & pluginID,
const QString & pluginLabel,
const QString & pluginIconPath,
Expand All @@ -1555,7 +1579,7 @@ AppManager::registerPlugin(const QStringList & groups,
if (mustCreateMutex) {
pluginMutex = new QMutex(QMutex::Recursive);
}
Plugin* plugin = new Plugin(binary, pluginID, pluginLabel, pluginIconPath, groupIconPath, groups, pluginMutex, major, minor,
Plugin* plugin = new Plugin(binary, resourcesPath, pluginID, pluginLabel, pluginIconPath, groupIconPath, groups, pluginMutex, major, minor,
isReader, isWriter, isDeprecated);
std::string stdID = pluginID.toStdString();

Expand Down Expand Up @@ -2985,6 +3009,55 @@ AppManager::hasThreadsRendering() const
return false;
}



QString
AppManager::getGlfwVersion() const
{
return QString::fromUtf8(GLFW_VERSION_STRING) + QString::fromUtf8(" / ") + QString::fromUtf8( glfwGetVersionString() );
}

bool
AppManager::hasPlatformNecessaryOpenGLRequirements(QString* missingOpenGLError) const
{
if (missingOpenGLError) {
*missingOpenGLError = _imp->missingOpenglError;
}
return _imp->hasRequiredOpenGLVersionAndExtensions;
}

QString
AppManager::getOpenGLVersion() const
{
QString glslVer = QString::fromUtf8((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
QString openglVer = QString::fromUtf8((const char*)glGetString(GL_VERSION));
return openglVer + QString::fromUtf8(", GLSL ") + glslVer;
}

QString
AppManager::getBoostVersion() const
{
return QString::fromUtf8(BOOST_LIB_VERSION);
}

QString
AppManager::getQtVersion() const
{
return QString::fromUtf8(QT_VERSION_STR) + QString::fromUtf8(" / ") + QString::fromUtf8( qVersion() );
}

QString
AppManager::getCairoVersion() const
{
return QString::fromUtf8(CAIRO_VERSION_STRING) + QString::fromUtf8(" / ") + QString::fromUtf8( cairo_version_string() );
}

QString
AppManager::getPySideVersion() const
{
return QString::fromUtf8(SHIBOKEN_VERSION);
}

const NATRON_NAMESPACE::OfxHost*
AppManager::getOFXHost() const
{
Expand Down
17 changes: 16 additions & 1 deletion Engine/AppManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ class AppManager
{
}

Plugin* registerPlugin(const QStringList & groups,
Plugin* registerPlugin(const QString& resourcesPath,
const QStringList & groups,
const QString & pluginID,
const QString & pluginLabel,
const QString & pluginIconPath,
Expand Down Expand Up @@ -512,6 +513,20 @@ class AppManager
void setPluginsUseInputImageCopyToRender(bool b);
bool isCopyInputImageForPluginRenderEnabled() const;

bool hasPlatformNecessaryOpenGLRequirements(QString* missingOpenGLError = 0) const;

QString getGlfwVersion() const;

QString getOpenGLVersion() const;

QString getBoostVersion() const;

QString getQtVersion() const;

QString getCairoVersion() const;

QString getPySideVersion() const;

public Q_SLOTS:

void exitAppWithSaveWarning()
Expand Down
69 changes: 69 additions & 0 deletions Engine/AppManagerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ GCC_DIAG_ON(unused-parameter)

#include "Global/QtCompat.h" // for removeRecursively
#include "Global/GlobalDefines.h"
#include "Global/GLIncludes.h"

#include "Engine/FStreamsSupport.h"
#include "Engine/CacheSerialization.h"
Expand Down Expand Up @@ -111,6 +112,7 @@ AppManagerPrivate::AppManagerPrivate()
#endif
, natronPythonGIL(QMutex::Recursive)
, pluginsUseInputImageCopyToRender(false)
, hasRequiredOpenGLVersionAndExtensions(true)
{
setMaxCacheFiles();

Expand Down Expand Up @@ -516,4 +518,71 @@ AppManagerPrivate::setMaxCacheFiles()
maxCacheFiles = hardMax * 0.9;
}


#ifdef DEBUG
static void glfw_error_callback(int error, const char* description)
{
qDebug() << "GLFW ERROR: " << __FILE__ << __LINE__ << error << description;
}
#endif

void
AppManagerPrivate::initGlfw()
{


assert(QThread::currentThread() == qApp->thread());

#ifdef DEBUG
// May be called before glfwInit()
glfwSetErrorCallback(glfw_error_callback);
#endif

hasRequiredOpenGLVersionAndExtensions = true;

if (glfwInit() != GL_TRUE) {
hasRequiredOpenGLVersionAndExtensions = false;
missingOpenglError = QObject::tr("Failed to initialize OpenGL requirements of the GLFW library on your platform.");
return;
}


#ifdef GL_TRACE_CALLS
glad_set_pre_callback(pre_gl_call);
glad_set_post_callback(post_gl_call);
#endif

// gladLoadGLLoader needs a window, so create a hidden one

glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
GLFWwindow* offscreen_window = glfwCreateWindow(200, 200 , "", NULL, NULL);
if (!offscreen_window) {
hasRequiredOpenGLVersionAndExtensions = false;
missingOpenglError = QObject::tr("Failed to create GLFW window.");
return;
}

glfwMakeContextCurrent(offscreen_window);


if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) {
missingOpenglError = QObject::tr("Failed to load required OpenGL functions. " NATRON_APPLICATION_NAME " requires at least OpenGL 2.0 with the following extensions: ");
missingOpenglError += QString::fromUtf8("GL_ARB_vertex_buffer_object,GL_ARB_pixel_buffer_object,GL_ARB_vertex_array_object,GL_ARB_framebuffer_object,GL_ARB_texture_float");
missingOpenglError += QLatin1String("\n");
missingOpenglError += QObject::tr("Your OpenGL version ");
missingOpenglError += appPTR->getOpenGLVersion();
hasRequiredOpenGLVersionAndExtensions = false;
return;
}

// OpenGL is now read to be used! just include "Global/GLIncludes.h"
}

void
AppManagerPrivate::teardownGlfw()
{
// Terminates GLFW, clearing any resources allocated by GLFW.
glfwTerminate();
}

NATRON_NAMESPACE_EXIT;
8 changes: 8 additions & 0 deletions Engine/AppManagerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ struct AppManagerPrivate
// Copy of the setting knob for faster access from OfxImage constructor
bool pluginsUseInputImageCopyToRender;

// True if we can use OpenGL
bool hasRequiredOpenGLVersionAndExtensions;
QString missingOpenglError;

AppManagerPrivate();

~AppManagerPrivate();
Expand Down Expand Up @@ -167,6 +171,10 @@ struct AppManagerPrivate

void createBreakpadHandler(const QString& breakpadPipePath, int breakpad_client_fd);
#endif

void initGlfw();

void teardownGlfw();
};

NATRON_NAMESPACE_EXIT;
Expand Down
Loading

0 comments on commit a11e076

Please sign in to comment.