Skip to content

Commit 55a9e9c

Browse files
committed
fragment shader now always pair (forced) with vertex shader
1 parent 61ec73d commit 55a9e9c

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/objects/scripting/ShaderObject.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,35 @@ void ShaderObject::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
149149
string fileExtension = ofToUpper(currentScriptFile.getExtension());
150150
if(fileExtension == "FRAG") {
151151
filepath = copyFileToPatchFolder(this->patchFolderPath,currentScriptFile.getAbsolutePath());
152+
string fsName = currentScriptFile.getFileName();
153+
string vsName = currentScriptFile.getEnclosingDirectory()+currentScriptFile.getFileName().substr(0,fsName.find_last_of('.'))+".vert";
154+
ofFile newVertGLSLFile (vsName);
155+
if(newVertGLSLFile.exists()){
156+
copyFileToPatchFolder(this->patchFolderPath,newVertGLSLFile.getAbsolutePath());
157+
}else{
158+
ofFile vertToRead(ofToDataPath("scripts/empty.vert"));
159+
ofFile patchFolderNewFrag(filepath);
160+
string pf_fsName = patchFolderNewFrag.getFileName();
161+
string pf_vsName = patchFolderNewFrag.getEnclosingDirectory()+patchFolderNewFrag.getFileName().substr(0,pf_fsName.find_last_of('.'))+".vert";
162+
ofFile::copyFromTo(vertToRead.getAbsolutePath(),pf_vsName,true,true);
163+
}
152164
loadScript(filepath);
153165
reloading = true;
154166
}else if(fileExtension == "VERT"){
167+
string newVertOpened = copyFileToPatchFolder(this->patchFolderPath,currentScriptFile.getAbsolutePath());
155168
string vsName = currentScriptFile.getFileName();
156169
string fsName = currentScriptFile.getEnclosingDirectory()+currentScriptFile.getFileName().substr(0,vsName.find_last_of('.'))+".frag";
157-
filepath = fsName;
158-
filepath = copyFileToPatchFolder(this->patchFolderPath,filepath);
170+
ofFile newFragGLSLFile (fsName);
171+
if(newFragGLSLFile.exists()){
172+
filepath = copyFileToPatchFolder(this->patchFolderPath,newFragGLSLFile.getAbsolutePath());
173+
}else{
174+
ofFile fragToRead(ofToDataPath("scripts/empty.frag"));
175+
ofFile patchFolderNewVert(newVertOpened);
176+
string pf_vsName = patchFolderNewVert.getFileName();
177+
string pf_fsName = patchFolderNewVert.getEnclosingDirectory()+patchFolderNewVert.getFileName().substr(0,pf_vsName.find_last_of('.'))+".frag";
178+
ofFile::copyFromTo(fragToRead.getAbsolutePath(),pf_fsName,true,true);
179+
filepath = pf_fsName;
180+
}
159181
loadScript(filepath);
160182
reloading = true;
161183
}
@@ -169,6 +191,13 @@ void ShaderObject::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
169191
ofFile newGLSLFile (lastShaderScript);
170192
ofFile::copyFromTo(fileToRead.getAbsolutePath(),checkFileExtension(newGLSLFile.getAbsolutePath(), ofToUpper(newGLSLFile.getExtension()), "FRAG"),true,true);
171193
ofFile correctedFileToRead(checkFileExtension(newGLSLFile.getAbsolutePath(), ofToUpper(newGLSLFile.getExtension()), "FRAG"));
194+
195+
ofFile vertToRead(ofToDataPath("scripts/empty.vert"));
196+
string fsName = newGLSLFile.getFileName();
197+
string vsName = newGLSLFile.getEnclosingDirectory()+newGLSLFile.getFileName().substr(0,fsName.find_last_of('.'))+".vert";
198+
ofFile newVertGLSLFile (vsName);
199+
ofFile::copyFromTo(vertToRead.getAbsolutePath(),newVertGLSLFile.getAbsolutePath(),true,true);
200+
172201
currentScriptFile = correctedFileToRead;
173202
if (currentScriptFile.exists()){
174203
filepath = currentScriptFile.getAbsolutePath();

src/ofxVisualProgramming.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,23 @@ void ofxVisualProgramming::update(){
214214
// update scripts objects files map
215215
ofFile tempsofp(patchObjects[leftToRightIndexOrder[i].second]->getFilepath());
216216
string fileExt = ofToUpper(tempsofp.getExtension());
217-
if(fileExt == "LUA" || fileExt == "PY" || fileExt == "SH" || fileExt == "FRAG"){
217+
if(fileExt == "LUA" || fileExt == "PY" || fileExt == "SH"){
218218
map<string,string>::iterator sofpIT = scriptsObjectsFilesPaths.find(tempsofp.getFileName());
219219
if (sofpIT == scriptsObjectsFilesPaths.end()){
220220
// not found, insert it
221221
scriptsObjectsFilesPaths.insert( pair<string,string>(tempsofp.getFileName(),tempsofp.getAbsolutePath()) );
222222
}
223+
}else if(fileExt == "FRAG"){
224+
map<string,string>::iterator sofpIT = scriptsObjectsFilesPaths.find(tempsofp.getFileName());
225+
if (sofpIT == scriptsObjectsFilesPaths.end()){
226+
// not found, insert FRAG
227+
scriptsObjectsFilesPaths.insert( pair<string,string>(tempsofp.getFileName(),tempsofp.getAbsolutePath()) );
228+
// insert VERT
229+
string fsName = tempsofp.getFileName();
230+
string vsName = tempsofp.getEnclosingDirectory()+tempsofp.getFileName().substr(0,fsName.find_last_of('.'))+".vert";
231+
ofFile newVertGLSLFile (vsName);
232+
scriptsObjectsFilesPaths.insert( pair<string,string>(newVertGLSLFile.getFileName(),newVertGLSLFile.getAbsolutePath()) );
233+
}
223234
}
224235
}
225236
}

0 commit comments

Comments
 (0)