processFile process one file checking if it has the shaders extension, otherwise it is ignored. If the include flag is true the file is an include file otherwise it it a shader
(file string, include bool)
| 182 | // If the include flag is true the file is an include file otherwise it |
| 183 | // it a shader |
| 184 | func processFile(file string, include bool) { |
| 185 | |
| 186 | // Ignore file if it has not the shader extension |
| 187 | fext := filepath.Ext(file) |
| 188 | if fext != SHADEREXT { |
| 189 | return |
| 190 | } |
| 191 | |
| 192 | if *oVerbose { |
| 193 | logger.Printf("Processing: %s", file) |
| 194 | } |
| 195 | |
| 196 | // Get the file base name and its name with the extension |
| 197 | fbase := filepath.Base(file) |
| 198 | fname := fbase[:len(fbase)-len(fext)] |
| 199 | |
| 200 | // If not in include directory, the file must be a shader program |
| 201 | // which name must have the format: <name>_<shader_type> |
| 202 | if !include { |
| 203 | parts := strings.Split(string(fname), "_") |
| 204 | if len(parts) < 2 { |
| 205 | logger.Print(" IGNORED: file does not have a valid shader name") |
| 206 | return |
| 207 | } |
| 208 | stype := parts[len(parts)-1] |
| 209 | if !shaderTypes[stype] { |
| 210 | logger.Print(" IGNORED: invalid shader type") |
| 211 | return |
| 212 | } |
| 213 | sname := strings.Join(parts[:len(parts)-1], "_") |
| 214 | pinfo, ok := templData.Programs[sname] |
| 215 | if !ok { |
| 216 | templData.Programs[sname] = pinfo |
| 217 | } |
| 218 | switch stype { |
| 219 | case TYPE_VERTEX: |
| 220 | pinfo.Vertex = fname |
| 221 | case TYPE_FRAGMENT: |
| 222 | pinfo.Fragment = fname |
| 223 | case TYPE_GEOMETRY: |
| 224 | pinfo.Geometry = fname |
| 225 | } |
| 226 | templData.Programs[sname] = pinfo |
| 227 | } |
| 228 | |
| 229 | // Reads all file data |
| 230 | f, err := os.Open(file) |
| 231 | if err != nil { |
| 232 | panic(err) |
| 233 | } |
| 234 | defer f.Close() |
| 235 | data, err := ioutil.ReadAll(f) |
| 236 | if err != nil { |
| 237 | panic(err) |
| 238 | } |
| 239 | |
| 240 | // Appends entry in Includes or Shaders |
| 241 | if include { |
no test coverage detected