#include "texture.h"Vá para o código-fonte deste arquivo.
Estruturas de Dados | |
| struct | ARBProgram |
| Representa um shader. Mais... | |
Funções | |
| ARBProgram | loadARBProg (const char *filename, int numTextures, Texture *textures) |
| void | loadARBProgs (char *directory, char *extension, int numTextures, Texture *textures, int *numProgs, ARBProgram **progs) |
| void | activateARBProg (ARBProgram *prog) |
| void | deactivateARBProg (ARBProgram *prog) |
Esse arquivo define funcionalidades que representam o programa que vai na GPU.
Nesse arquivo são definidas a estrutura ARBProgram e funções para carregar e ativar/desativar programas. /* Copyright (c) 2005 Institute for Visualization and Interactive Systems, University of Stuttgart, Germany
This source code is distributed as part of the single-pass volume rendering project. Details about this project can be found on the project web page at http://www.vis.uni-stuttgart.de/eng/research/ fields/current/spvolren. This file may be distributed, modified, and used free of charge as long as this copyright notice is included in its original form. Commercial use is strictly prohibited.
Filename: arbprogram.h
Definição no arquivo arbprogram.h.
| void activateARBProg | ( | ARBProgram * | prog | ) |
Ativa shader, colocando-o "para dentro" da GPU.
| prog | Shader a ser carregado. |
Definição na linha 332 do arquivo arbprogram.c.
00333 { 00334 texActivate(prog->numTextureObjects, prog->textureObjects); 00335 glEnable(prog->programType); 00336 glBindProgramARB(prog->programType, prog->id); 00337 }
| void deactivateARBProg | ( | ARBProgram * | prog | ) |
Desativa shader, "tirando-o" da GPU.
| prog | Shader a ser carregado. |
Definição na linha 339 do arquivo arbprogram.c.
00340 { 00341 texDeactivate(prog->numTextureObjects, prog->textureObjects); 00342 glDisable(prog->programType); 00343 glBindProgramARB(prog->programType, 0); 00344 }
| ARBProgram loadARBProg | ( | const char * | filename, | |
| int | numTextures, | |||
| Texture * | textures | |||
| ) |
Carrega um shader a partir de um arquivo e texturas das quais amostragens serão feitas.
| filename | Nome do arquivo do qual o shader será extraído. | |
| numTextures | Número de texturas sendo carregadas | |
| textures | Texturas. |
Definição na linha 142 do arquivo arbprogram.c.
00143 { 00144 ARBProgram prog; 00145 int fd; 00146 struct stat statbuf; 00147 char *fnp; 00148 00149 if (! (fnp = strrchr(filename, DIR_SEP))) { 00150 fnp = (char *) filename; 00151 } else { 00152 fnp++; 00153 } 00154 00155 if (! (prog.filename = strdup(fnp))) { 00156 fprintf(stderr, "cannot duplicate filename\n"); 00157 exit(1); 00158 } 00159 00160 #if defined WIN32 00161 if ((fd = open(filename, O_RDONLY | O_BINARY)) < 0) { 00162 #else 00163 if ((fd = open(filename, O_RDONLY)) < 0) { 00164 #endif 00165 perror("opening file failed"); 00166 exit(1); 00167 } 00168 00169 if (fstat(fd, &statbuf) < 0) { 00170 fprintf(stderr, "failed to get file stats of %s\n", 00171 filename); 00172 } 00173 00174 prog.size = statbuf.st_size; 00175 00176 if (! (prog.prog = (char *)malloc(prog.size + 1))) { 00177 fprintf(stderr, "not enough memory for " 00178 "program\n"); 00179 exit(1); 00180 } 00181 00182 if (read(fd, prog.prog, prog.size) != prog.size) { 00183 fprintf(stderr, "reading file %s failed\n", 00184 prog.filename); 00185 exit(1); 00186 } 00187 prog.prog[prog.size] = '\0'; 00188 00189 if (! loadProgram(&prog, numTextures, textures)) { 00190 fprintf(stderr, "exiting due to parse error in program " 00191 "'%s'\n", prog.filename); 00192 exit(1); 00193 } 00194 close(fd); 00195 00196 return prog; 00197 }
| void loadARBProgs | ( | char * | directory, | |
| char * | extension, | |||
| int | numTextures, | |||
| Texture * | textures, | |||
| int * | numProgs, | |||
| ARBProgram ** | progs | |||
| ) |
Carrega uma sequência de shaders.
| directory | Diretório onde shaders se encontram. | |
| extension | Extensão do shader (fp para fragment program/pixel shader, vp para vertex program) | |
| numTextures | Número de texturas sendo carregadas | |
| textures | Texturas. | |
| numProgs | Número de shaders a serem carregados. | |
| progs | Array a ser preenchido com os shaders. |
Definição na linha 200 do arquivo arbprogram.c.
00203 { 00204 ARBProgram *prog; 00205 struct dirent *entry; 00206 struct stat statbuf; 00207 DIR *dp; 00208 char *file; 00209 00210 *numProgs = 0; 00211 *progs = NULL; 00212 00213 fprintf(stderr, "\nloading programs ...\n"); 00214 00215 if ((dp = opendir(directory)) == NULL) { 00216 fprintf(stderr, "cannot open current directory\n"); 00217 return; 00218 } 00219 00220 while((entry = readdir(dp))) { 00221 if (! (file = (char *)malloc(strlen(directory) + strlen(entry->d_name) + 2))) { 00222 fprintf(stderr, "not enough memory for file template\n"); 00223 exit(1); 00224 } 00225 strcpy(file, directory); 00226 if (!endsWith(directory, "/")) { 00227 strcat(file, "/"); 00228 } 00229 strcat(file, entry->d_name); 00230 lstat(file, &statbuf); 00231 if (S_ISREG(statbuf.st_mode)) { 00232 if (endsWith(entry->d_name, extension)) { 00233 (*numProgs)++; 00234 if (! (*progs = (ARBProgram *)realloc(*progs, 00235 *numProgs * sizeof(ARBProgram)))) { 00236 fprintf(stderr, "not enough memory for " 00237 "program structures\n"); 00238 exit(1); 00239 } 00240 prog = &(*progs)[*numProgs - 1]; 00241 00242 *prog = loadARBProg(file, numTextures, textures); 00243 } 00244 } 00245 free(file); 00246 } 00247 closedir(dp); 00248 00249 if (! *numProgs) { 00250 fprintf(stderr, "no programs found\n"); 00251 exit(1); 00252 } 00253 00254 fprintf(stderr, "\n"); 00255 00256 /* Sort the programs according to their names since otherwise the 00257 order will continuously change when editing the files */ 00258 qsort(*progs, *numProgs, sizeof(ARBProgram), arbpCompare); 00259 }
1.6.1