@@ -155,7 +155,12 @@ void ShaderObject::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
155155 if (newVertGLSLFile.exists ()){
156156 copyFileToPatchFolder (this ->patchFolderPath ,newVertGLSLFile.getAbsolutePath ());
157157 }else {
158- ofFile vertToRead (ofToDataPath (" scripts/empty.vert" ));
158+ ofFile vertToRead;
159+ if (ofIsGLProgrammableRenderer ()){
160+ vertToRead.open (ofToDataPath (" scripts/empty.vert" ));
161+ }else {
162+ vertToRead.open (ofToDataPath (" scripts/empty_120.vert" ));
163+ }
159164 ofFile patchFolderNewFrag (filepath);
160165 string pf_fsName = patchFolderNewFrag.getFileName ();
161166 string pf_vsName = patchFolderNewFrag.getEnclosingDirectory ()+patchFolderNewFrag.getFileName ().substr (0 ,pf_fsName.find_last_of (' .' ))+" .vert" ;
@@ -171,7 +176,12 @@ void ShaderObject::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
171176 if (newFragGLSLFile.exists ()){
172177 filepath = copyFileToPatchFolder (this ->patchFolderPath ,newFragGLSLFile.getAbsolutePath ());
173178 }else {
174- ofFile fragToRead (ofToDataPath (" scripts/empty.frag" ));
179+ ofFile fragToRead;
180+ if (ofIsGLProgrammableRenderer ()){
181+ fragToRead.open (ofToDataPath (" scripts/empty.frag" ));
182+ }else {
183+ fragToRead.open (ofToDataPath (" scripts/empty_120.frag" ));
184+ }
175185 ofFile patchFolderNewVert (newVertOpened);
176186 string pf_vsName = patchFolderNewVert.getFileName ();
177187 string pf_fsName = patchFolderNewVert.getEnclosingDirectory ()+patchFolderNewVert.getFileName ().substr (0 ,pf_vsName.find_last_of (' .' ))+" .frag" ;
@@ -187,18 +197,29 @@ void ShaderObject::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchOb
187197 if (shaderScriptSaved){
188198 shaderScriptSaved = false ;
189199 // create and open the new one
190- ofFile fileToRead (ofToDataPath (" scripts/empty.frag" ));
200+ ofFile fileToRead;
201+ if (ofIsGLProgrammableRenderer ()){
202+ fileToRead.open (ofToDataPath (" scripts/empty.frag" ));
203+ }else {
204+ fileToRead.open (ofToDataPath (" scripts/empty_120.frag" ));
205+ }
191206 ofFile newGLSLFile (lastShaderScript);
192207 ofFile::copyFromTo (fileToRead.getAbsolutePath (),checkFileExtension (newGLSLFile.getAbsolutePath (), ofToUpper (newGLSLFile.getExtension ()), " FRAG" ),true ,true );
193208 ofFile correctedFileToRead (checkFileExtension (newGLSLFile.getAbsolutePath (), ofToUpper (newGLSLFile.getExtension ()), " FRAG" ));
194209
195- ofFile vertToRead (ofToDataPath (" scripts/empty.vert" ));
210+ ofFile vertToRead;
211+ if (ofIsGLProgrammableRenderer ()){
212+ vertToRead.open (ofToDataPath (" scripts/empty.vert" ));
213+ }else {
214+ vertToRead.open (ofToDataPath (" scripts/empty_120.vert" ));
215+ }
196216 string fsName = newGLSLFile.getFileName ();
197217 string vsName = newGLSLFile.getEnclosingDirectory ()+newGLSLFile.getFileName ().substr (0 ,fsName.find_last_of (' .' ))+" .vert" ;
198218 ofFile newVertGLSLFile (vsName);
199219 ofFile::copyFromTo (vertToRead.getAbsolutePath (),newVertGLSLFile.getAbsolutePath (),true ,true );
200220
201221 currentScriptFile = correctedFileToRead;
222+
202223 if (currentScriptFile.exists ()){
203224 filepath = currentScriptFile.getAbsolutePath ();
204225 loadScript (filepath);
@@ -561,7 +582,6 @@ void ShaderObject::doFragmentShader(){
561582 unsigned long subVarMiddle = fragmentShader.find (" ;//" ,subVarStart);
562583 unsigned long subVarEnd = fragmentShader.find (" @" ,subVarStart);
563584 string varName = fragmentShader.substr (subVarMiddle+3 ,subVarEnd-subVarMiddle-3 );
564-
565585 float tempValue = 0 .0f ;
566586 map<string,float >::const_iterator it = tempVars.find (" GUI_FLOAT_" +varName);
567587 if (it!=tempVars.end ()){
@@ -634,20 +654,23 @@ void ShaderObject::doFragmentShader(){
634654 this ->saveConfig (false );
635655
636656 // Compile the shader and load it to the GPU
637- quad.clear ();
657+ if (ofIsGLProgrammableRenderer ()) {
658+ quad.clear ();
659+ }
638660 shader->unload ();
639661
640662 if (!ofIsGLProgrammableRenderer ()) {
641663 if (vertexShader != " " ){
642664 shader->setupShaderFromSource (GL_VERTEX_SHADER, vertexShader);
643665 }
644666 shader->setupShaderFromSource (GL_FRAGMENT_SHADER, fragmentShader);
667+ scriptLoaded = shader->linkProgram ();
645668 }else {
646669 size_t lastindex = filepath.find_last_of (" ." );
647670 string rawname = filepath.substr (0 , lastindex);
648671 shader->load (rawname);
672+ scriptLoaded = shader->isLoaded ();
649673 }
650- scriptLoaded = shader->isLoaded ();
651674
652675 if (scriptLoaded){
653676 ofLog (OF_LOG_NOTICE," [verbose] SHADER: %s [%ix%i] loaded on GPU!" ,filepath.c_str (),output_width,output_height);
@@ -742,20 +765,30 @@ void ShaderObject::loadScript(string scriptFile){
742765 size_t lastindex = filepath.find_last_of (" ." );
743766 string rawname = filepath.substr (0 , lastindex);
744767 test.load (rawname);
768+
769+ if (test.isLoaded ()){
770+ test.unload ();
771+ watcher.removeAllPaths ();
772+ watcher.addPath (filepath);
773+ if (vertexShader != " " ){
774+ watcher.addPath (vertexShaderFile.getAbsolutePath ());
775+ }
776+ doFragmentShader ();
777+ }
745778 }else {
746779 if (vertexShader != " " ){
747780 test.setupShaderFromSource (GL_VERTEX_SHADER, vertexShader);
748781 }
749782 test.setupShaderFromSource (GL_FRAGMENT_SHADER, fragmentShader);
750- }
751- if (test.isLoaded ()){
752- test.unload ();
753- watcher.removeAllPaths ();
754- watcher.addPath (filepath);
755- if (vertexShader != " " ){
756- watcher.addPath (vertexShaderFile.getAbsolutePath ());
783+
784+ if (test.linkProgram ()){
785+ watcher.removeAllPaths ();
786+ watcher.addPath (filepath);
787+ if (vertexShader != " " ){
788+ watcher.addPath (vertexShaderFile.getAbsolutePath ());
789+ }
790+ doFragmentShader ();
757791 }
758- doFragmentShader ();
759792 }
760793
761794 }else {
0 commit comments