Effect.cc (1706B)
1 /* Copyright 2013 Brian Swetland <swetland@frotz.net> 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <string> 17 18 #include "stringutils.h" 19 20 #include "Effect.h" 21 22 void Effect::apply(void) { 23 pgm.use(); 24 } 25 26 int Effect::init(const char *name) { 27 const char *x = strchr(name, '+'); 28 if (x) { 29 int len = x - name; 30 string128 sname(stringptr(name, len)); 31 string1024 defines; 32 x++; 33 while (*x) { 34 const char *n = x; 35 x = strchr(n, '+'); 36 defines.append("#define "); 37 if (x) { 38 defines.append(n, x-n); 39 defines.append("\n"); 40 x++; 41 } else { 42 defines.append(n); 43 defines.append("\n"); 44 break; 45 } 46 } 47 sname.append(".vertex"); 48 if (vs.load(sname, defines)) 49 return -1; 50 sname.trim(len).append(".fragment"); 51 if (ps.load(sname, defines)) 52 return -1; 53 } else { 54 string128 sname(name); 55 int len = sname.length(); 56 sname.append(".vertex"); 57 if (vs.load(sname)) 58 return -1; 59 sname.trim(len).append(".fragment"); 60 if (ps.load(sname)) 61 return -1; 62 } 63 if (pgm.link(&vs, &ps)) 64 return -1; 65 return 0; 66 } 67 68 Effect *Effect::load(const char *name) { 69 Effect *e = new Effect(); 70 if (e->init(name)) { 71 delete e; 72 return nullptr; 73 } else { 74 return e; 75 } 76 }