[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx/libpaper Paper.cxx Paper.hxx
From: |
Janne V. Kujala |
Subject: |
[Gzz-commits] gzz/gfx/libpaper Paper.cxx Paper.hxx |
Date: |
Tue, 10 Sep 2002 06:49:02 -0400 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Janne V. Kujala <address@hidden> 02/09/10 06:49:01
Modified files:
gfx/libpaper : Paper.cxx Paper.hxx
Log message:
VP fix: transform object coordinates using modelview and projection
matrices
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/Paper.cxx.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/Paper.hxx.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: gzz/gfx/libpaper/Paper.cxx
diff -c gzz/gfx/libpaper/Paper.cxx:1.5 gzz/gfx/libpaper/Paper.cxx:1.6
*** gzz/gfx/libpaper/Paper.cxx:1.5 Mon Sep 9 07:22:39 2002
--- gzz/gfx/libpaper/Paper.cxx Tue Sep 10 06:49:01 2002
***************
*** 2,7 ****
--- 2,11 ----
#include <sstream>
+ /* define positions of tracked matrices inside the NV vertex program
registers */
+ #define m_p_addr 0 // product of projection and modelview matrices
+ #define paper_addr 4 // object-to-paper-coordinate mapping matrix
+
namespace Paper {
TexGen::TexGen(const float *tex_mat) {
svec[0] = tex_mat[0];
***************
*** 18,36 ****
rvec[1] = tex_mat[9];
rvec[2] = tex_mat[10];
rvec[3] = tex_mat[11];
- }
! void TexGen::setUpVP(int unit) {
! GLuint base = unit * 4 + 60;
// XXX: This could also be implemented as CallGL code
#ifdef GL_VERTEX_PROGRAM_NV
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 0, svec);
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 1, tvec);
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 2, rvec);
!
! //float qvec[4] = { 0, 0, 0, 1 };
! //glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 3, qvec);
#endif
}
--- 22,42 ----
rvec[1] = tex_mat[9];
rvec[2] = tex_mat[10];
rvec[3] = tex_mat[11];
! qvec[0] = 0;
! qvec[0] = 0;
! qvec[0] = 0;
! qvec[0] = 1;
! }
+ void TexGen::setUpVP(int unit, LightParam * param) {
// XXX: This could also be implemented as CallGL code
#ifdef GL_VERTEX_PROGRAM_NV
+ GLuint base = unit * 4 + 60;
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 0, svec);
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 1, tvec);
glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 2, rvec);
! glProgramParameter4fvNV(GL_VERTEX_PROGRAM_NV, base + 3, qvec);
#endif
}
***************
*** 42,49 ****
code << "DP4 o[TEX" << unit << "].x, c[" << base + 0 << "], v[TEX0]\n"
<< "DP4 o[TEX" << unit << "].y, c[" << base + 1 << "], v[TEX0]\n"
<< "DP4 o[TEX" << unit << "].z, c[" << base + 2 << "], v[TEX0]\n"
! << "MOV o[TEX" << unit << "].w, v[TEX0].w\n";
! // << "DP4 o[TEX" << unit << "].w, c[" << base + 3 << "],
v[TEX0]\n";
return code.str();
}
--- 48,54 ----
code << "DP4 o[TEX" << unit << "].x, c[" << base + 0 << "], v[TEX0]\n"
<< "DP4 o[TEX" << unit << "].y, c[" << base + 1 << "], v[TEX0]\n"
<< "DP4 o[TEX" << unit << "].z, c[" << base + 2 << "], v[TEX0]\n"
! << "DP4 o[TEX" << unit << "].w, c[" << base + 3 << "], v[TEX0]\n";
return code.str();
}
***************
*** 71,76 ****
--- 76,118 ----
glPopMatrix();
}
+ void TexGenEmboss::setUpVP(int unit, LightParam * param) {
+ TexGen::setUpVP(unit, param);
+
+ float mat0[16];
+ glGetFloatv(GL_MODELVIEW_MATRIX, mat0);
+
+ float mat[16] = { param->e0.x, param->e0.y, param->e0.z, 0,
+ param->e1.x, param->e1.y, param->e1.z, 0,
+ param->e2.x, param->e2.y, param->e2.z, 0,
+ param->orig.x, param->orig.y, param->orig.z, 1 };
+
+ glMatrixMode(GL_MATRIX0_NV);
+ glLoadMatrixf(mat0);
+ glMultMatrixf(mat);
+ glMatrixMode(GL_MODELVIEW);
+
+ glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, paper_addr, GL_MATRIX0_NV,
GL_INVERSE_TRANSPOSE_NV);
+
+ }
+
+
+ string TexGenEmboss::getVPCode(int unit) {
+ GLuint base = unit * 4 + 60;
+
+ std::ostringstream code;
+
+ code << "DP4 o[TEX" << unit << "].x, c[" << base + 0 << "], v[TEX0]\n"
+ << "DP4 o[TEX" << unit << "].y, c[" << base + 1 << "], v[TEX0]\n"
+ << "DP4 o[TEX" << unit << "].z, c[" << base + 2 << "], v[TEX0]\n"
+ << "DP4 o[TEX" << unit << "].w, c[" << base + 3 << "], v[TEX0]\n";
+
+ // XXX: compute embossing shift
+
+ return code.str();
+ }
+
+
void TexGenEmboss::setUp(LightParam *param) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
***************
*** 177,208 ****
}
void PaperPass::loadVP() {
! string code =
! "!!VP1.0\n"
! "MOV o[HPOS], v[OPOS]\n"
! "MOV o[COL0], v[COL0]\n"
! "MOV o[COL1], v[COL1]\n";
int unit = 0;
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it !=
texgen.end(); ++it) {
! if (it->get()) code += (*it)->getVPCode(unit);
else std::cerr << "Warning: ignoring null TexGen\n";
unit++;
}
! std::cerr << "Creating VPCode with the source " << code << "\n";
! texgenvp = VPCode(code.c_str());
}
void PaperPass::setUpVP(LightParam *param) {
if (texgenvp.getSource().length() == 0)
loadVP();
/* Set up VP TexGen parameters for each texture unit */
int unit = 0;
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it !=
texgen.end(); ++it) {
! if (it->get()) (*it)->setUpVP(unit);
else std::cerr << "Warning: ignoring null TexGen\n";
unit++;
}
--- 219,257 ----
}
void PaperPass::loadVP() {
! std::ostringstream code;
!
! code << "!!VP1.0\n"
! << "DP4 o[HPOS].x, v[OPOS], c[" << m_p_addr + 0 << "]\n"
! << "DP4 o[HPOS].y, v[OPOS], c[" << m_p_addr + 1 << "]\n"
! << "DP4 o[HPOS].z, v[OPOS], c[" << m_p_addr + 2 << "]\n"
! << "DP4 o[HPOS].w, v[OPOS], c[" << m_p_addr + 3 << "]\n"
! << "MOV o[COL0], v[COL0]\n"
! << "MOV o[COL1], v[COL1]\n";
int unit = 0;
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it !=
texgen.end(); ++it) {
! if (it->get()) code << (*it)->getVPCode(unit);
else std::cerr << "Warning: ignoring null TexGen\n";
unit++;
}
! std::cerr << "Creating VPCode with the source " << code.str() << "\n";
! texgenvp = VPCode(code.str().c_str());
}
void PaperPass::setUpVP(LightParam *param) {
if (texgenvp.getSource().length() == 0)
loadVP();
+ /* Track the product of modelview and projection matrices */
+ glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, m_p_addr, GL_MATRIX0_NV,
GL_MODELVIEW_PROJECTION_NV);
+
/* Set up VP TexGen parameters for each texture unit */
int unit = 0;
for (vector<shared_ptr<TexGen> >::iterator it = texgen.begin(); it !=
texgen.end(); ++it) {
! if (it->get()) (*it)->setUpVP(unit, param);
else std::cerr << "Warning: ignoring null TexGen\n";
unit++;
}
Index: gzz/gfx/libpaper/Paper.hxx
diff -c gzz/gfx/libpaper/Paper.hxx:1.6 gzz/gfx/libpaper/Paper.hxx:1.7
*** gzz/gfx/libpaper/Paper.hxx:1.6 Mon Sep 9 07:19:14 2002
--- gzz/gfx/libpaper/Paper.hxx Tue Sep 10 06:49:01 2002
***************
*** 79,84 ****
--- 79,85 ----
float svec[4];
float tvec[4];
float rvec[4];
+ float qvec[4]; // XXX: Currently always initialized to 0,0,0,1
public:
/** Create a new texgen.
***************
*** 88,97 ****
TexGen(const float *tex_mat) ;
virtual void setUp(LightParam *param) ;
!
! virtual void TexGen::setUpVP(int unit);
!
! virtual string TexGen::getVPCode(int unit);
};
/** TexGen for embossing.
--- 89,96 ----
TexGen(const float *tex_mat) ;
virtual void setUp(LightParam *param) ;
! virtual void setUpVP(int unit, LightParam * param);
! virtual string getVPCode(int unit);
};
/** TexGen for embossing.
***************
*** 111,116 ****
--- 110,117 ----
virtual void setUp(LightParam *param) ;
+ virtual void setUpVP(int unit, LightParam * param);
+ virtual string getVPCode(int unit);
};
/** TexGen for transforming light intensity or direction map
- [Gzz-commits] gzz/gfx/libpaper Paper.cxx Paper.hxx,
Janne V. Kujala <=