1 |
#include "Paper.hxx" |
#include "Paper.hxx" |
2 |
|
|
3 |
|
#include <sstream> |
4 |
|
|
5 |
namespace Paper { |
namespace Paper { |
6 |
TexGen::TexGen(const float *tex_mat) { |
TexGen::TexGen(const float *tex_mat) { |
7 |
svec[0] = tex_mat[0]; |
svec[0] = tex_mat[0]; |
18 |
rvec[1] = tex_mat[9]; |
rvec[1] = tex_mat[9]; |
19 |
rvec[2] = tex_mat[10]; |
rvec[2] = tex_mat[10]; |
20 |
rvec[3] = tex_mat[11]; |
rvec[3] = tex_mat[11]; |
21 |
} |
} |
22 |
|
|
23 |
|
void TexGen::setUpVP(int unit) { |
24 |
|
GLuint base = unit * 4 + 60; |
25 |
|
|
26 |
|
// XXX: This could also be implemented as CallGL code |
27 |
|
#ifdef GL_VERTEX_PROGRAM_NV |
28 |
|
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 0, svec); |
29 |
|
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 1, tvec); |
30 |
|
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 2, rvec); |
31 |
|
|
32 |
|
//float qvec[4] = { 0, 0, 0, 1 }; |
33 |
|
//glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 3, qvec); |
34 |
|
#endif |
35 |
|
} |
36 |
|
|
37 |
|
string TexGen::getVPCode(int unit) { |
38 |
|
GLuint base = unit * 4 + 60; |
39 |
|
|
40 |
|
std::ostringstream code; |
41 |
|
|
42 |
|
code << "DP4 o[TEX0].x, c[" << base + 0 << "], v[TEX0]\n" |
43 |
|
<< "DP4 o[TEX0].y, c[" << base + 1 << "], v[TEX0]\n" |
44 |
|
<< "DP4 o[TEX0].z, c[" << base + 2 << "], v[TEX0]\n" |
45 |
|
<< "MOV o[TEX0].w, v[TEX0].w\n"; |
46 |
|
// << "DP4 o[TEX0].w, c[" << base + 3 << "], v[TEX0]\n"; |
47 |
|
|
48 |
|
return code.str(); |
49 |
|
} |
50 |
|
|
51 |
void TexGen::setUp(LightParam *param) { |
void TexGen::setUp(LightParam *param) { |
52 |
glMatrixMode(GL_MODELVIEW); |
glMatrixMode(GL_MODELVIEW); |
176 |
} |
} |
177 |
} |
} |
178 |
|
|
179 |
|
void PaperPass::loadVP() { |
180 |
|
string code = |
181 |
|
"!!VP1.0\n" |
182 |
|
"MOV o[HPOS], v[OPOS]\n" |
183 |
|
"MOV o[COL0], v[COL0]\n" |
184 |
|
"MOV o[COL1], v[COL1]\n"; |
185 |
|
|
186 |
|
int unit = 0; |
187 |
|
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
188 |
|
if (it->get()) code += (*it)->getVPCode(unit); |
189 |
|
else std::cerr << "Warning: ignoring null TexGen\n"; |
190 |
|
unit++; |
191 |
|
} |
192 |
|
|
193 |
|
std::cerr << "Creating VPCode with the source " << code << "\n"; |
194 |
|
|
195 |
|
texgenvp = VPCode(code.c_str()); |
196 |
|
} |
197 |
|
|
198 |
|
void PaperPass::setUpVP(LightParam *param) { |
199 |
|
if (texgenvp.getSource().length() == 0) |
200 |
|
loadVP(); |
201 |
|
|
202 |
|
/* Set up VP TexGen parameters for each texture unit */ |
203 |
|
int unit = 0; |
204 |
|
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it != texgen.end(); ++it) { |
205 |
|
if (it->get()) (*it)->setUpVP(unit); |
206 |
|
else std::cerr << "Warning: ignoring null TexGen\n"; |
207 |
|
unit++; |
208 |
|
} |
209 |
|
|
210 |
|
/* Do general parametric setup */ |
211 |
|
for (vector<shared_ptr<LightSetup> >::iterator it = setup.begin(); it != setup.end(); ++it) { |
212 |
|
if (it->get()) (*it)->setUp(param); |
213 |
|
else std::cerr << "Warning: ignoring null LightSetup\n"; |
214 |
|
} |
215 |
|
|
216 |
|
texgenvp(); // Bind vertex program |
217 |
|
#ifdef GL_VERTEX_PROGRAM_NV |
218 |
|
glEnable(GL_VERTEX_PROGRAM_NV); |
219 |
|
#endif |
220 |
|
} |
221 |
|
|
222 |
|
void PaperPass::tearDownVP() { |
223 |
|
teardowncode(); |
224 |
|
#ifdef GL_VERTEX_PROGRAM_NV |
225 |
|
glDisable(GL_VERTEX_PROGRAM_NV); |
226 |
|
#endif |
227 |
|
} |
228 |
|
|
229 |
} |
} |