225 |
glColor3f(.5 * L.x + .5, .5 * L.y + .5, .5 * L.z + .5); |
glColor3f(.5 * L.x + .5, .5 * L.y + .5, .5 * L.z + .5); |
226 |
} |
} |
227 |
|
|
228 |
|
|
229 |
void PaperPass::setUp_texgen(LightParam *param) { |
void PaperPass::setUp_texgen(LightParam *param) { |
230 |
setupcode(); |
setupcode(); |
231 |
|
|
232 |
/* Set up TexGen for each texture unit */ |
/* Set up TexGen for each texture unit */ |
233 |
GLenum unit = GL_TEXTURE0_ARB; |
GLenum unit = GL_TEXTURE0_ARB; |
234 |
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
235 |
glActiveTextureARB(unit++); |
glActiveTextureARB(unit++); |
236 |
if (it->get()) (*it)->setUp(param); |
if (it->get()) (*it)->setUp(param); |
237 |
else std::cerr << "Warning: ignoring null TexGen\n"; |
else std::cerr << "Warning: ignoring null TexGen\n"; |
238 |
} |
} |
239 |
|
|
240 |
/* Do general parametric setup */ |
/* Do general parametric setup */ |
241 |
for (vector<shared_ptr<LightSetup> >::iterator it = setup.begin(); it != setup.end(); ++it) { |
for (vector<shared_ptr<LightSetup> >::iterator it = setup.begin(); it != setup.end(); ++it) { |
242 |
if (it->get()) (*it)->setUp(param); |
if (it->get()) (*it)->setUp(param); |
243 |
else std::cerr << "Warning: ignoring null LightSetup\n"; |
else std::cerr << "Warning: ignoring null LightSetup\n"; |
244 |
} |
} |
245 |
} |
} |
246 |
|
|
247 |
void PaperPass::loadVP() { |
void PaperPass::loadVP() { |
248 |
std::ostringstream code; |
std::ostringstream code; |
249 |
|
|
250 |
code << "!!VP1.1 OPTION NV_position_invariant;\n" |
code << "!!VP1.1 OPTION NV_position_invariant;\n" |
251 |
<< "MOV o[COL0], v[COL0];\n" |
<< "MOV o[COL0], v[COL0];\n" |
252 |
<< "MOV o[COL1], v[COL1];\n"; |
<< "MOV o[COL1], v[COL1];\n"; |
253 |
|
|
254 |
int unit = 0; |
int unit = 0; |
255 |
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
256 |
if (it->get()) code << (*it)->getVPCode(unit); |
if (it->get()) code << (*it)->getVPCode(unit); |
257 |
else std::cerr << "Warning: ignoring null TexGen\n"; |
else std::cerr << "Warning: ignoring null TexGen\n"; |
258 |
unit++; |
unit++; |
259 |
} |
} |
260 |
|
|
261 |
code << "END\n"; |
code << "END\n"; |
262 |
|
|
263 |
//std::cerr << "Creating VPCode with the source " << code.str() << "\n"; |
//std::cerr << "Creating VPCode with the source " << code.str() << "\n"; |
264 |
|
|
265 |
texgenvp = VPCode(code.str().c_str()); |
texgenvp = VPCode(code.str().c_str()); |
266 |
} |
} |
267 |
|
|
268 |
void PaperPass::setUp_VP(LightParam *param) { |
void PaperPass::setUp_VP(LightParam *param) { |
269 |
if (texgenvp.getSource().length() == 0) loadVP(); |
if (texgenvp.getSource().length() == 0) loadVP(); |
270 |
|
|
271 |
setupcode(); |
setupcode(); |
272 |
|
|
273 |
/* Set up VP TexGen parameters for each texture unit */ |
/* Set up VP TexGen parameters for each texture unit */ |
274 |
int unit = 0; |
int unit = 0; |
275 |
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
276 |
if (it->get()) (*it)->setUp_VP(unit, param); |
if (it->get()) (*it)->setUp_VP(unit, param); |
277 |
else std::cerr << "Warning: ignoring null TexGen\n"; |
else std::cerr << "Warning: ignoring null TexGen\n"; |
278 |
unit++; |
unit++; |
279 |
} |
} |
280 |
|
|
281 |
/* Do general parametric setup */ |
/* Do general parametric setup */ |
282 |
for (vector<shared_ptr<LightSetup> >::iterator it = setup.begin(); it != setup.end(); ++it) { |
for (vector<shared_ptr<LightSetup> >::iterator it = setup.begin(); it != setup.end(); ++it) { |
283 |
if (it->get()) (*it)->setUp(param); |
if (it->get()) (*it)->setUp(param); |
284 |
else std::cerr << "Warning: ignoring null LightSetup\n"; |
else std::cerr << "Warning: ignoring null LightSetup\n"; |
285 |
} |
} |
286 |
|
|
287 |
texgenvp(); // Bind vertex program |
texgenvp(); // Bind vertex program |
288 |
#ifdef GL_VERTEX_PROGRAM_NV |
#ifdef GL_VERTEX_PROGRAM_NV |
289 |
glEnable(GL_VERTEX_PROGRAM_NV); |
glEnable(GL_VERTEX_PROGRAM_NV); |
290 |
#endif |
#endif |
291 |
} |
} |
292 |
|
|