Skip to content

Commit

Permalink
work on isf editor
Browse files Browse the repository at this point in the history
misc small changes :: updated the apple frameworks to include headers as appropriate :: fixed a bug- isf editor would crash if no audio inputs were available :: dragging a .fs file onto the isf editor or its dock icon will display the contents of the file's parent folder and select the dragged file :: fixed a bug- the UI items created for 2d points had incorrectly-ranged Y vals (if no min/max was specified by the ISF's input) :: the cmd-f/ctrl-f panel is populated appropriate with search terms selected using cmd-e/ctrl-e :: added a way to synchronously compile a scene's shaders/program, and determine if they were able to compile/link successfully
  • Loading branch information
mrRay committed May 21, 2019
1 parent cd30b2c commit e15c37f
Show file tree
Hide file tree
Showing 30 changed files with 815 additions and 4,717 deletions.
3 changes: 3 additions & 0 deletions VVGL/include/GLContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class VVGL_EXPORT GLContext {
CGLContextObj sharedContextObj() { return sharedCtx; }
// this function returns the pixel format object
CGLPixelFormatObj pixelFormatObj() { return pxlFmt; }

// this function sets the context's current virtual screen- if you want to configure a context to use a specific GPU, this is how.
void setCurrentVirtualScreen(const int & n);
#elif defined(VVGL_SDK_IOS)
// "inCtx" is an EAGLContext! this function doesn't create anything- it just retains the passed ctx
GLContext(const void * inEAGLContext);
Expand Down
16 changes: 11 additions & 5 deletions VVGL/include/GLScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,19 @@ class VVGL_EXPORT GLScene {
bool _clearColorUpdated = false;

// these vars pertain to the program being used by the GL context
std::string *_vsString = nullptr;
std::string *_gsString = nullptr;
std::string *_fsString = nullptr;
std::string *_vsString = nullptr;
std::string *_gsString = nullptr;
std::string *_fsString = nullptr;
bool _vsStringUpdated = false;
bool _gsStringUpdated = false;
bool _fsStringUpdated = false;
bool _programReady = false; // set to 'true' only if all shaders compiled and the program was able to link successfully
uint32_t _program = 0; // 0, or the compiled program
uint32_t _vs = 0;
uint32_t _gs = 0;
uint32_t _fs = 0;
std::mutex _errLock;
std::mutex _errDictLock;
std::mutex _errLock;
std::mutex _errDictLock;
std::map<std::string,std::string> _errDict;

// this class- and subclasses of it- often need to create GPU resources. by default the global buffer pool (GetGlobalBufferPool()) will be used- unless this var is non-null...
Expand Down Expand Up @@ -190,6 +191,7 @@ class VVGL_EXPORT GLScene {
void setOrthoFlipped(const bool & n);
//! Gets the value of the _orthoFlipped member variable. If this is true, the orthographic projection or equivalent will be flipped vertically.
bool orthoFlipped() const;

///@}


Expand Down Expand Up @@ -232,6 +234,10 @@ class VVGL_EXPORT GLScene {
virtual std::string fragmentShaderString();
//! Gets the program ID.
inline uint32_t program() const { return _program; }
//! Returns whether or not the program was able to be compiled. Please note that this value will only be populared after the program has been compiled/linked, which only occurs when a frame gets rendered.
inline bool programReady() const { return _programReady; }
//! Under normal circumstances, the scene's shaders/program are only compiled/linked when a frame is rendered. If compilation is required synchronously, this method can be used to compile/link the program (if necessary)
void compileProgramIfNecessary();

///@}

Expand Down
3 changes: 2 additions & 1 deletion VVGL/src/GLBufferPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,8 @@ GLBufferRef CreateBufferForQImage(QImage * inImg, const bool & createInCurrentCo
desc.localSurfaceID = 0;

// this bit copies the image data to a manually-allocated block of memory. i'm not sure why, but if i don't do this, i get crashes under some circumstances
void *tmpData = malloc(desc.backingLengthForSize(gpuSize));
uint32_t backingSize = desc.backingLengthForSize(gpuSize);
void *tmpData = malloc(backingSize);
char *rPtr = static_cast<char*>(pixelData);
char *wPtr = static_cast<char*>(tmpData);
int rLineStride = inImg->bytesPerLine();
Expand Down
9 changes: 9 additions & 0 deletions VVGL/src/GLContext_Mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ bool GLContext::sameShareGroupAs(const CGLContextObj & inCtx) {
return true;
return false;
}


void GLContext::setCurrentVirtualScreen(const int & n) {
CGLError cglErr = CGLSetVirtualScreen(ctx, n);
if (cglErr != kCGLNoError)
cout << "ERR: " << cglErr << " in " << __PRETTY_FUNCTION__ << endl;
}


GLContext & GLContext::operator=(const GLContext & n) {
if (ctx != nullptr) {
CGLReleaseContext(ctx);
Expand Down
17 changes: 17 additions & 0 deletions VVGL/src/GLScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,21 @@ string GLScene::fragmentShaderString() {
return string("");
return string(*_fsString);
}
void GLScene::compileProgramIfNecessary() {
// get a lock, set the current GL context
lock_guard<recursive_mutex> lock(_renderLock);
if (_context == nullptr) {
cout << "\terr: bailing, ctx null, " << __PRETTY_FUNCTION__ << endl;
return;
}
_context->makeCurrentIfNotCurrent();

// prep for render
_renderPrep();

// cleanup after render
_renderCleanup();
}


/* ======================================== */
Expand Down Expand Up @@ -469,6 +484,7 @@ void GLScene::_renderPrep() {
GLERRLOG
_fs = 0;
}
_programReady = false;


{
Expand Down Expand Up @@ -661,6 +677,7 @@ void GLScene::_renderPrep() {
_program = 0;
}
else {
_programReady = true;
_orthoUni.cacheTheLoc(_program);
}
}
Expand Down
2 changes: 1 addition & 1 deletion VVISF/include/ISFScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class VVISF_EXPORT ISFScene : public VVGL::GLScene {
//! Unloads whatever ISF file is currently loaded.
void useFile() noexcept(false);
//! Loads the ISF file at the passed path.
void useFile(const std::string & inPath, const bool & inThrowExc=true) noexcept(false);
void useFile(const std::string & inPath, const bool & inThrowExc=true, const bool & inResetTimer=true) noexcept(false);
//! Starts using the ISF file represented by the passed ISFDoc.
void useDoc(ISFDocRef & inDoc);
//! Returns the ISFDoc currently being used by the scene. Interacting with this doc by setting the value of its inputs will directly affect rendering.
Expand Down
4 changes: 2 additions & 2 deletions VVISF/src/ISFPassTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void ISFPassTarget::setTargetSize(const VVGL::Size & inSize, const bool & inResi
}
// if that didn't work, use the globals...
if (bp == nullptr) {
cout << "\tERR: shouldnt be here, falling back to global buffer pool, " << __PRETTY_FUNCTION__ << endl;
//cout << "\tERR: shouldnt be here, falling back to global buffer pool, " << __PRETTY_FUNCTION__ << endl;
bp = GetGlobalBufferPool();
}
if (copier == nullptr) {
Expand Down Expand Up @@ -252,7 +252,7 @@ void ISFPassTarget::setFloatFlag(const bool & n) {
}
// if that didn't work, use the globals...
if (bp == nullptr) {
cout << "\tERR: shouldnt be here, falling back to global buffer pool, " << __PRETTY_FUNCTION__ << endl;
//cout << "\tERR: shouldnt be here, falling back to global buffer pool, " << __PRETTY_FUNCTION__ << endl;
bp = GetGlobalBufferPool();
}
if (copier == nullptr) {
Expand Down
30 changes: 17 additions & 13 deletions VVISF/src/ISFScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ISFScene::useFile() noexcept(false) {
_compiledInputTypeString=nullptr;
}
}
void ISFScene::useFile(const string & inPath, const bool & inThrowExc) noexcept(false) {
void ISFScene::useFile(const string & inPath, const bool & inThrowExc, const bool & inResetTimer) noexcept(false) {
//cout << __PRETTY_FUNCTION__ << "... " << inPath << endl;
try {
lock_guard<recursive_mutex> rlock(_renderLock);
Expand All @@ -85,12 +85,14 @@ void ISFScene::useFile(const string & inPath, const bool & inThrowExc) noexcept(
_doc = newDoc;

// reset the timestamper and render frame index
//timestamper.reset();
_baseTime = Timestamp();
_renderTime = 0.;
_renderTimeDelta = 0.;
_renderFrameIndex = 0;
_passIndex = 0;
if (inResetTimer) {
//timestamper.reset();
_baseTime = Timestamp();
_renderTime = 0.;
_renderTimeDelta = 0.;
_renderFrameIndex = 0;
_passIndex = 0;
}
if (_compiledInputTypeString!=nullptr) {
delete _compiledInputTypeString;
_compiledInputTypeString=nullptr;
Expand All @@ -103,12 +105,14 @@ void ISFScene::useFile(const string & inPath, const bool & inThrowExc) noexcept(
_errDict.insert(detail);
_doc = nullptr;
// reset the timestamper and render frame index
//timestamper.reset();
_baseTime = Timestamp();
_renderTime = 0.;
_renderTimeDelta = 0.;
_renderFrameIndex = 0;
_passIndex = 0;
if (inResetTimer) {
//timestamper.reset();
_baseTime = Timestamp();
_renderTime = 0.;
_renderTimeDelta = 0.;
_renderFrameIndex = 0;
_passIndex = 0;
}
if (_compiledInputTypeString!=nullptr) {
delete _compiledInputTypeString;
_compiledInputTypeString=nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class ISFAudioBufferList : public QObject

void generalInit() {
int bytesPerSample = _format.sampleSize() / 8;
numberOfFrames = _bufferData.size() / bytesPerSample;
numberOfChannels = 1;
numberOfFrames = (bytesPerSample==0) ? 0 : _bufferData.size() / bytesPerSample;
numberOfChannels = (bytesPerSample==0) ? 0 : 1;
}
};




#endif // ISFAUDIOBUFFERLIST_H
#endif // ISFAUDIOBUFFERLIST_H
16 changes: 16 additions & 0 deletions examples/Qt/ISFEditor/ISFEditor_app/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,21 @@
<false/>
<key>NSHighResolutionCapable</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>fs</string>
<string>org.khronos.glsl-source</string>
<string>glsl-src</string>
<string>fs</string>
<string>frag shader</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>

</dict>
</plist>
89 changes: 89 additions & 0 deletions examples/Qt/ISFEditor/ISFEditor_app/LoadingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ LoadingWindow::LoadingWindow(QWidget *parent) :
// save window position on app quit
connect(qApp, &QCoreApplication::aboutToQuit, this, &LoadingWindow::appQuitEvent);

// install an event filter on the QApplication instance to listen for "open document" events. this will pick up files dragged into windows as well as files dragged onto the dock icon.
qApp->installEventFilter(this);

//qDebug() << "\t" << __PRETTY_FUNCTION__ << " - FINISHED";
}
Expand Down Expand Up @@ -154,6 +156,63 @@ void LoadingWindow::finishedConversionDisplayFile(const QString & n) {



bool LoadingWindow::eventFilter(QObject * watched, QEvent * event) {

QString fileToOpen("");

switch (event->type()) {
case QEvent::FileOpen:
event->accept();
//qDebug() << "Event FileOpen, " << static_cast<QFileOpenEvent*>(event)->file();
fileToOpen = static_cast<QFileOpenEvent*>(event)->file();
break;
case QEvent::DragEnter:
case QEvent::DragLeave:
event->accept();
//qDebug() << "Event DragEnter";
break;
case QEvent::Drop:
{
event->accept();
const QMimeData *mimeData = static_cast<QDropEvent *>(event)->mimeData();
// If there is one file (not more) we open it
if (mimeData->urls().length() == 1) {
//QString fileName = mimeData->urls().first().toLocalFile();
fileToOpen = mimeData->urls().first().toLocalFile();
//qDebug() << "Event Drop, " << fileName;
}
}
break;

default:
return false;
}

LoadingWindow *lw = GetLoadingWindow();
if (fileToOpen.length() > 0 && lw != nullptr) {
QFileInfo fileInfo(fileToOpen);
if (fileInfo.exists()) {
if (fileInfo.isDir()) {
lw->setBaseDirectory(fileToOpen);
}
else {
lw->setBaseDirectory(fileInfo.dir().path());
lw->selectFile(fileToOpen);
}
}
if (fileInfo.exists() && !fileInfo.isDir()) {

}
}



return true;
}




void LoadingWindow::closeEvent(QCloseEvent * event) {
QSettings settings;
settings.setValue("LoadingWindowGeometry", saveGeometry());
Expand Down Expand Up @@ -561,6 +620,36 @@ void LoadingWindow::setBaseDirectory(const QString & inBaseDir) {
});
}
}
void LoadingWindow::selectFile(const QString & inFileToSelect) {
qDebug() << __PRETTY_FUNCTION__ << ", " << inFileToSelect;
QFileInfo fileInfo(inFileToSelect);
// if the file doesn't exist, bail
if (!fileInfo.exists())
return;
// if the file we were told to select is a directory...
if (fileInfo.isDir()) {
// update the base directory only if necessary
QString newBaseDir = inFileToSelect;
if (newBaseDir == getBaseDirectory())
return;
setBaseDirectory(newBaseDir);
}
// else the file we were told to select isn't a directory (it's a file)
else {
// update the base directory only if necessary
QString newBaseDir = fileInfo.dir().path();
if (newBaseDir != getBaseDirectory())
setBaseDirectory(newBaseDir);
// get the filter list view's data model, figure out if the index corresponding to the file path
QFileSystemModel *tmpModel = qobject_cast<QFileSystemModel*>(ui->filterListView->model());
if (tmpModel != nullptr) {
QModelIndex tmpIndex = tmpModel->index(inFileToSelect);
if (tmpIndex.isValid()) {
ui->filterListView->setCurrentIndex(tmpIndex);
}
}
}
}



Expand Down
3 changes: 3 additions & 0 deletions examples/Qt/ISFEditor/ISFEditor_app/LoadingWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ class LoadingWindow : public QWidget
QSpinBox * getHeightSB();
inline QString getBaseDirectory() { return baseDirectory; }
void setBaseDirectory(const QString & inBaseDir);
void selectFile(const QString & inFileToSelect);

void on_createNewFile();
void on_loadFile(const QString & n);
void on_saveFile();

void finishedConversionDisplayFile(const QString & n);

virtual bool eventFilter(QObject * watched, QEvent * event) override;

protected:
virtual void closeEvent(QCloseEvent * event) Q_DECL_OVERRIDE;
virtual void showEvent(QShowEvent * event) Q_DECL_OVERRIDE;
Expand Down
Loading

0 comments on commit e15c37f

Please sign in to comment.