Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

toon_texture_1D.C

Go to the documentation of this file.
00001 /*********************************************************************
00002  * Legacy toon shader, 1D textures, no pixel shaders
00003  **********************************************************************/
00004 
00005 #include "gtex/gl_extensions.H"
00006 #include "gtex/paper_effect.H"
00007 #include "geom/gl_view.H"
00008 #include "std/config.H"
00009 #include "toon_texture_1D.H"
00010 
00011 /**********************************************************************
00012  * Globals
00013  * changed (appended with "_1D") 
00014  * so it doesn't conflict with new toon_texture globals
00015  **********************************************************************/
00016 
00017 bool     ntt_paper_flag_1D;       //If paper's being used
00018 Wpt      ntt_light_pos_1D;        //Used to fetch light pos
00019 Wvec     ntt_light_dir_1D;        //Used to fetch light dir
00020 bool     ntt_positional_1D;       //Used to flag if pos or dir
00021 
00022 bool     ntt_is_init_vertex_program_1D = false;
00023 bool     ntt_use_vertex_program_1D = false;
00024 bool     ntt_use_vertex_program_arb_1D = false;
00025 bool     ntt_use_vertex_program_nv_1D = false;
00026 
00027 GLuint   ntt_toon_prog_nv_1D;
00028 GLuint   ntt_toon_prog_arb_1D;
00029 
00030 //these are unchanged as they are inside the object
00031 LIST<str_ptr>*    ToonTexture_1D::_toon_texture_names = 0;
00032 LIST<TEXTUREptr>* ToonTexture_1D::_toon_texture_ptrs = 0;
00033 LIST<str_ptr>*    ToonTexture_1D::_toon_texture_remap_orig_names = 0;
00034 LIST<str_ptr>*    ToonTexture_1D::_toon_texture_remap_new_names = 0;
00035 
00036 /*****************************************************************
00037  * Texture Remapping
00038  *****************************************************************/
00039 
00040 char *toon_remap_base_1D = "nprdata/toon_textures/";
00041 char *toon_remap_fnames_1D[][2] = 
00042 {
00043 //   {"dark-8.png",    "1D--dark-8.png"},
00044 //   {"mydot4.png",    "2D--dash-normal-8-32.png"},
00045 //   {"one_d.png",     "1D--gauss-narrow-8.png"},
00046    {NULL,            NULL}
00047 };
00048 
00049 /*****************************************************************
00050  * Shaders
00051  *****************************************************************/
00052 
00053 const unsigned char NPRToonShaderNV_1D[]=
00054 //c[0]-c[3] modelview
00055 //c[4]-c[7] projection
00056 //c[12]-c[15] texture0
00057 //c[16]-c[19] texture1
00058 //c[20] xy(1,1) in ndc
00059 //c[21] light pos
00060 //c[22] light dir
00061 //c[23] pos->1,1,1,1 dir->0,0,0,0
00062 {
00063    "!!VP1.0\
00064 DP4 R0.x,v[OPOS],c[0];\
00065 DP4 R0.y,v[OPOS],c[1];\
00066 DP4 R0.z,v[OPOS],c[2];\
00067 DP4 R0.w,v[OPOS],c[3];\
00068 DP4 R1.x,R0,c[4];\
00069 DP4 R1.y,R0,c[5];\
00070 DP4 R1.z,R0,c[6];\
00071 DP4 R1.w,R0,c[7];\
00072 MOV o[HPOS],R1;\
00073 MUL R2,R1,c[20];\
00074 DP4 o[TEX1].x,R2,c[16];\
00075 DP4 o[TEX1].y,R2,c[17];\
00076 DP4 o[TEX1].z,R2,c[18];\
00077 DP4 o[TEX1].w,R2,c[19];\
00078 ADD R4,c[21],-v[OPOS];\
00079 DP3 R4.w,R4,R4;\
00080 RSQ R4.w,R4.w;\
00081 MUL R4,R4,R4.w;\
00082 SLT R11,R11,R11;\
00083 SGE R10,R11,c[23];\
00084 MUL R5,c[23],R4;\
00085 MAD R5,R10,c[22],R5;\
00086 DP3 R6.x,v[NRML],R5;\
00087 MOV R6.yzw,R11;\
00088 DP4 o[TEX0].x,R6,c[12];\
00089 DP4 o[TEX0].y,R6,c[13];\
00090 MOV o[COL0],v[COL0];\
00091 END"
00092 };
00093 
00094 
00095 const unsigned char NPRToonShaderARB_1D[]=
00096 //c[20] xy(1,1) in ndc
00097 //c[21] light pos
00098 //c[22] light dir
00099 //c[23] pos->1,1,1,1 dir->0,0,0,0
00100 {
00101    "!!ARBvp1.0\n\
00102 \
00103 ATTRIB iPos  = vertex.position;\
00104 ATTRIB iNorm = vertex.normal;\
00105 ATTRIB iCol  = vertex.color;\
00106 \
00107 OUTPUT oPos  = result.position;\
00108 OUTPUT oCol  = result.color;\
00109 OUTPUT oTex0 = result.texcoord[0];\
00110 OUTPUT oTex1 = result.texcoord[1];\
00111 \
00112 PARAM  cZero      = {0.0,0.0,0.0,0.0};\
00113 PARAM  cOne       = {1.0,1.0,1.0,1.0};\
00114 PARAM  cNDC       = program.env[20];\
00115 PARAM  cLPos      = program.env[21];\
00116 PARAM  cLDir      = program.env[22];\
00117 PARAM  cLPosFlag  = program.env[23];\
00118 \
00119 PARAM  mMVP[4] =  { state.matrix.mvp };\
00120 PARAM  mTex0[4] =  { state.matrix.texture[0] };\
00121 PARAM  mTex1[4] =  { state.matrix.texture[1] };\
00122 \
00123 TEMP   tXY;\
00124 TEMP   tNDC;\
00125 TEMP   tLDirFlag;\
00126 TEMP   tLPosVec;\
00127 TEMP   tLFinalVec;\
00128 TEMP   tLDot;\
00129 \
00130 DP4 tXY.x, mMVP[0], iPos;\
00131 DP4 tXY.y, mMVP[1], iPos;\
00132 DP4 tXY.z, mMVP[2], iPos;\
00133 DP4 tXY.w, mMVP[3], iPos;\
00134 \
00135 MUL tNDC,tXY,cNDC;\
00136 \
00137 ADD tLPosVec,  cLPos,   -iPos;\
00138 DP3 tLPosVec.w,tLPosVec, tLPosVec;\
00139 RSQ tLPosVec.w,tLPosVec.w;\
00140 MUL tLPosVec,  tLPosVec, tLPosVec.w;\
00141 \
00142 SGE tLDirFlag,cZero,cLPosFlag;\
00143 \
00144 MUL tLFinalVec,cLPosFlag,tLPosVec;\
00145 MAD tLFinalVec,tLDirFlag,cLDir,tLFinalVec;\
00146 \
00147 DP3 tLDot.x,iNorm,tLFinalVec;\
00148 ABS tLDot.x,tLDot.x;\
00149 MOV tLDot.yz,cZero;\
00150 MOV tLDot.w, cOne;\
00151 \
00152 DP4 oTex0.x, mTex0[0], tLDot;\
00153 DP4 oTex0.y, mTex0[1], tLDot;\
00154 DP4 oTex0.z, mTex0[2], tLDot;\
00155 DP4 oTex0.w, mTex0[3], tLDot;\
00156 \
00157 DP4 oTex1.x, mTex1[0], tNDC;\
00158 DP4 oTex1.y, mTex1[1], tNDC;\
00159 DP4 oTex1.z, mTex1[2], tNDC;\
00160 DP4 oTex1.w, mTex1[3], tNDC;\
00161 \
00162 MOV oPos, tXY;\
00163 MOV oCol, iCol;\
00164 \
00165 END"
00166 
00167 };
00168 
00169 
00170 /////////////////////////////////////
00171 // init_vertex_program_nv()
00172 /////////////////////////////////////
00173 
00174 bool ntt_init_vertex_program_nv_1D()
00175 {
00176 #ifdef NON_NVIDIA_GFX
00177    return false;
00178 #else
00179    if (GLExtensions::gl_nv_vertex_program_supported())
00180       {
00181          err_mesg(ERR_LEV_INFO, "ToonTexture_1D::init() - Can use NV vertex programs!");
00182 #ifdef GL_NV_vertex_program
00183          glGenProgramsNV(1, &ntt_toon_prog_nv_1D); 
00184          glBindProgramNV(GL_VERTEX_PROGRAM_NV, ntt_toon_prog_nv_1D); 
00185          glLoadProgramNV(GL_VERTEX_PROGRAM_NV, ntt_toon_prog_nv_1D, strlen((char * ) NPRToonShaderNV_1D), NPRToonShaderNV_1D);
00186 #endif
00187          return true;
00188       }
00189    else
00190       {
00191          return false;
00192       }
00193 #endif
00194 }
00195 
00196 /////////////////////////////////////
00197 // init_vertex_program_arb()
00198 /////////////////////////////////////
00199 
00200 bool ntt_init_vertex_program_arb_1D()
00201 {
00202    assert(!ntt_is_init_vertex_program_1D);
00203 
00204    if (GLExtensions::gl_arb_vertex_program_supported())
00205       {
00206          bool success = false, native = false;
00207          err_mesg(ERR_LEV_INFO, "ToonTexture_1D::init() - Can use ARB vertex programs!");
00208 #ifdef GL_ARB_vertex_program
00209          glGenProgramsARB(1, &ntt_toon_prog_arb_1D); 
00210          glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_arb_1D); 
00211          glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
00212                             strlen((char * ) NPRToonShaderARB_1D), NPRToonShaderARB_1D);
00213          success = GLExtensions::gl_arb_vertex_program_loaded("ToonTexture_1D::init() - ", native, NPRToonShaderARB_1D);
00214 #endif
00215          return success;
00216       }
00217    else
00218       {
00219          return false;
00220       }
00221 }
00222 
00223 /////////////////////////////////////
00224 // init_vertex_program()
00225 /////////////////////////////////////
00226 
00227 void ntt_init_vertex_program_1D()
00228 {
00229    assert(!ntt_is_init_vertex_program_1D);
00230 
00231    ntt_use_vertex_program_arb_1D = ntt_init_vertex_program_arb_1D();
00232    ntt_use_vertex_program_nv_1D =  ntt_init_vertex_program_nv_1D();
00233 
00234    if (ntt_use_vertex_program_nv_1D || ntt_use_vertex_program_arb_1D)
00235       {
00236          err_mesg(ERR_LEV_INFO, "ToonTexture_1D::init() - Will use vertex programs!");
00237          ntt_use_vertex_program_1D = true;
00238       }
00239    else
00240       {
00241          err_mesg(ERR_LEV_INFO, "ToonTexture_1D::init() - Won't be using vertex programs!");
00242          ntt_use_vertex_program_1D = false;
00243       }
00244 
00245    ntt_is_init_vertex_program_1D = true;
00246 }
00247 
00248 /////////////////////////////////////
00249 // setup_vertex_program_nv()
00250 /////////////////////////////////////
00251 void ntt_setup_vertex_program_nv_1D()
00252 {
00253 #if defined(GL_NV_vertex_program) && !defined(NON_NVIDIA_GFX)
00254 
00255    NDCpt n(XYpt(1,1));
00256 
00257    glBindProgramNV(GL_VERTEX_PROGRAM_NV, ntt_toon_prog_nv_1D); 
00258 
00259    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW, GL_IDENTITY_NV);
00260    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4, GL_PROJECTION, GL_IDENTITY_NV);
00261    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 12, GL_TEXTURE, GL_IDENTITY_NV);
00262    if (GLExtensions::gl_arb_multitexture_supported())
00263       {
00264 #ifdef GL_ARB_multitexture
00265          glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 16, GL_TEXTURE1_ARB, GL_IDENTITY_NV);
00266 #endif
00267       }
00268 
00269    glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 20, (float)n[0], (float)n[1], 1, 1);
00270 
00271    glProgramParameter4dNV(GL_VERTEX_PROGRAM_NV, 21,  
00272                           ntt_light_pos_1D[0], ntt_light_pos_1D[1], ntt_light_pos_1D[2], 1.0f);
00273    glProgramParameter4dNV(GL_VERTEX_PROGRAM_NV, 22,  
00274                           ntt_light_dir_1D[0], ntt_light_dir_1D[1], ntt_light_dir_1D[2], 0.0f);
00275    if (ntt_positional_1D)
00276       glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 23, 1, 1, 1, 1);
00277    else
00278       glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 23, 0, 0, 0, 0);
00279 
00280    glEnable(GL_VERTEX_PROGRAM_NV);  //GL_ENABLE_BIT
00281 
00282 #endif
00283 }
00284 
00285 /////////////////////////////////////
00286 // done_vertex_program_nv()
00287 /////////////////////////////////////
00288 void ntt_done_vertex_program_nv_1D()
00289 {
00290 #if defined(GL_NV_vertex_program) && !defined(NON_NVIDIA_GFX)
00291    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0,  GL_NONE, GL_IDENTITY_NV);
00292    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4,  GL_NONE, GL_IDENTITY_NV);
00293    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 12, GL_NONE, GL_IDENTITY_NV);
00294    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 16, GL_NONE, GL_IDENTITY_NV);
00295    glDisable(GL_VERTEX_PROGRAM_NV);  //GL_ENABLE_BIT
00296 #endif
00297 }
00298 
00299 
00300 /////////////////////////////////////
00301 // setup_vertex_program_arb()
00302 /////////////////////////////////////
00303 void ntt_setup_vertex_program_arb_1D()
00304 {
00305 #ifdef GL_ARB_vertex_program
00306    NDCpt n(XYpt(1,1));
00307 
00308    glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ntt_toon_prog_arb_1D); 
00309 
00310    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 20, n[0], n[1], 1.0, 1.0);
00311 
00312    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 21, 
00313                               ntt_light_pos_1D[0], ntt_light_pos_1D[1], ntt_light_pos_1D[2], 1.0);
00314    glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 22,  
00315                               ntt_light_dir_1D[0], ntt_light_dir_1D[1], ntt_light_dir_1D[2], 0.0);
00316    if (ntt_positional_1D)
00317       glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 23, 1.0, 1.0, 1.0, 1.0);
00318    else
00319       glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 23, 0.0, 0.0, 0.0, 0.0);
00320 
00321 
00322    glEnable(GL_VERTEX_PROGRAM_ARB);  //GL_ENABLE_BIT
00323 
00324 #endif
00325 }
00326 
00327 /////////////////////////////////////
00328 // done_vertex_program_arb()
00329 /////////////////////////////////////
00330 void ntt_done_vertex_program_arb_1D()
00331 {
00332 #ifdef GL_ARB_vertex_program
00333    glDisable(GL_VERTEX_PROGRAM_ARB);  //GL_ENABLE_BIT
00334 #endif
00335 }
00336 
00337 /////////////////////////////////////
00338 // setup_vertex_program()
00339 /////////////////////////////////////
00340 void ntt_setup_vertex_program_1D()
00341 {
00342    assert(ntt_use_vertex_program_1D);
00343 
00344    if (ntt_use_vertex_program_arb_1D)
00345       {
00346          ntt_setup_vertex_program_arb_1D();
00347       }
00348    else if (ntt_use_vertex_program_nv_1D)
00349       {
00350          ntt_setup_vertex_program_nv_1D();
00351       }
00352    else
00353       {
00354          assert(0);
00355       }
00356 }
00357 
00358 /////////////////////////////////////
00359 // done_vertex_program()
00360 /////////////////////////////////////
00361 void ntt_done_vertex_program_1D()
00362 {
00363    assert(ntt_use_vertex_program_1D);
00364 
00365    if (ntt_use_vertex_program_arb_1D)
00366       {
00367          ntt_done_vertex_program_arb_1D();
00368       }
00369    else if (ntt_use_vertex_program_nv_1D)
00370       {
00371          ntt_done_vertex_program_nv_1D();
00372       }
00373    else
00374       {
00375          assert(0);
00376       }
00377 
00378 }
00379 
00380 
00381 
00382 /**********************************************************************
00383  * ToonTexCB:
00384  **********************************************************************/
00385 void 
00386 ToonTexCB_1D::faceCB(CBvert* v, CBface*f) 
00387 {
00388    Wvec n;
00389    f->vert_normal(v,n);
00390 
00391    if (!ntt_use_vertex_program_1D)
00392       {
00393          if (ntt_positional_1D)
00394             glTexCoord2d(n * (ntt_light_pos_1D - v->loc()).normalized(), 0);
00395          else
00396             glTexCoord2d(n * ntt_light_dir_1D, 0);
00397    
00398          if (ntt_paper_flag_1D)
00399             PaperEffect::paper_coord(NDCZpt(v->wloc()).data());
00400 
00401          glVertex3dv(v->loc().data());
00402       }
00403    else
00404       {
00405          glNormal3dv(n.data());
00406          glVertex3dv(v->loc().data());
00407       }
00408 
00409 }
00410 
00411 /**********************************************************************
00412  * ToonTexture_1D:
00413  **********************************************************************/
00414 
00415 /////////////////////////////////////
00416 // Static Variable Initialization
00417 /////////////////////////////////////
00418 TAGlist *       ToonTexture_1D::_ntt_tags = 0;
00419 
00420 /////////////////////////////////////
00421 // update_lights()
00422 /////////////////////////////////////
00423 void
00424 ToonTexture_1D::update_lights(CVIEWptr& v) 
00425 {
00426    if (_light_index == -1)
00427       {
00428          ntt_positional_1D = !_light_dir;
00429          if (ntt_positional_1D)
00430             {
00431                Wpt pos(_light_coords[0],_light_coords[1],_light_coords[2]);
00432                if (_light_cam)
00433                   ntt_light_pos_1D = v->cam()->xform().inverse() * pos;
00434                else
00435                   ntt_light_pos_1D = pos;
00436                ntt_light_pos_1D = _patch->inv_xform() * ntt_light_pos_1D;
00437             }
00438          else
00439             {
00440                if (_light_cam)
00441                   ntt_light_dir_1D = v->cam()->xform().inverse() * _light_coords;
00442                else
00443                   ntt_light_dir_1D = _light_coords;
00444                ntt_light_dir_1D = (_patch->inv_xform() * ntt_light_dir_1D).normalized();
00445             }
00446       }
00447    else
00448       {
00449          ntt_positional_1D = v->light_get_positional(_light_index);
00450          if (ntt_positional_1D)
00451             {
00452                if (v->light_get_in_cam_space(_light_index))
00453                   ntt_light_pos_1D = v->cam()->xform().inverse() * 
00454                      v->light_get_coordinates_p(_light_index);
00455                else
00456                   ntt_light_pos_1D = v->light_get_coordinates_p(_light_index);
00457                ntt_light_pos_1D = _patch->inv_xform() * ntt_light_pos_1D;
00458             }
00459          else
00460             {
00461                if (v->light_get_in_cam_space(_light_index))
00462                   ntt_light_dir_1D = v->cam()->xform().inverse() * 
00463                      v->light_get_coordinates_v(_light_index);
00464                else
00465                   ntt_light_dir_1D = v->light_get_coordinates_v(_light_index);
00466                ntt_light_dir_1D = (_patch->inv_xform() * ntt_light_dir_1D).normalized();
00467             }
00468       }
00469 }
00470 
00471 /////////////////////////////////////
00472 // draw()
00473 /////////////////////////////////////
00474 int
00475 ToonTexture_1D::draw(CVIEWptr& v) 
00476 {
00477    GL_VIEW::print_gl_errors("ToonTexture_1D::draw - Begin");
00478 
00479    int dl;
00480    
00481    if (_ctrl)
00482       return _ctrl->draw(v);
00483 
00484    ntt_paper_flag_1D = (_use_paper==1)?(true):(false);
00485 
00486    if (!ntt_is_init_vertex_program_1D) 
00487       ntt_init_vertex_program_1D();
00488 
00489    if (ntt_paper_flag_1D)
00490       {
00491          // The enclosing NPRTexture will have already
00492          // rendered the mesh in 'background' mode.
00493          // We should enable blending and draw with
00494          // z <= mode...
00495       }
00496 
00497    update_tex();
00498    update_lights(v);
00499 
00500    glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | 
00501                 GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00502 
00503    GL_COL(_color, _alpha*alpha());      // GL_CURRENT_BIT
00504    glDisable(GL_LIGHTING);              // GL_ENABLE_BIT
00505 
00506    if (_tex) {
00507       _tex->apply_texture();            // GL_TEXTURE_BIT, GL_ENABLE_BIT
00508    }
00509 
00510    //if ((_ntt_paper_flag_1D) || (_alpha<1.0))
00511    //XXX - Just always blend, there may be alpha
00512    //in the texture...
00513    static bool OPAQUE_COMPOSITE =
00514       Config::get_var_bool("OPAQUE_COMPOSITE",false,true);
00515 
00516    if ((v->get_render_mode() == VIEW::TRANSPARENT_MODE) && (OPAQUE_COMPOSITE)) {
00517       glDisable(GL_BLEND);
00518       glBlendFunc(GL_ONE, GL_ZERO);
00519    } else {
00520       glEnable(GL_BLEND);                               //GL_ENABLE_BIT
00521       if (PaperEffect::is_alpha_premult())
00522          glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);   //GL_COLOR_BUFFER_BIT
00523       else
00524          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //GL_COLOR_BUFFER_BIT
00525    }
00526 
00527    //Don't write depth if not using the background texture
00528    if (!_transparent)
00529       {
00530          glDepthMask(GL_FALSE);                             //GL_DEPTH_BUFFER_BIT
00531       }
00532 
00533    NDCZpt origin(0,0,0);
00534    if (ntt_paper_flag_1D && _travel_paper)
00535       {
00536          Wpt_list wbox;
00537          NDCZpt_list nbox;
00538       
00539 
00540          (_patch->xform() * _patch->mesh()->get_bb()).points(wbox);
00541          while (wbox.num() > 0) nbox += wbox.pop();
00542       
00543          static bool SCREEN_BOX = Config::get_var_bool("SCREEN_BOX",false,true);
00544 
00545          if (SCREEN_BOX)
00546             {
00547                double minx = nbox[0][0];
00548                double maxx = nbox[0][0];
00549                double miny = nbox[0][1];
00550                double maxy = nbox[0][1];
00551                for (int i=1; i<nbox.num(); i++)
00552                   {
00553                      if (nbox[i][0] < minx) minx = nbox[i][0];
00554                      if (nbox[i][0] > maxx) maxx = nbox[i][0];
00555                      if (nbox[i][1] < miny) miny = nbox[i][1];
00556                      if (nbox[i][1] > maxy) maxy = nbox[i][1];
00557                      origin[0] = (minx + maxx)/2.0;
00558                      origin[1] = (miny + maxy)/2.0;
00559                   }
00560             }
00561          else
00562             {
00563                origin = nbox.average();
00564             }
00565       }
00566    PaperEffect::begin_paper_effect(ntt_paper_flag_1D, origin[0], origin[1]);
00567 
00568    if (ntt_use_vertex_program_1D) 
00569       {
00570       
00571 
00572          // Try it with the display list
00573          if (BasicTexture::dl_valid(v))
00574             {
00575                ntt_setup_vertex_program_1D();       // GL_ENABLE_BIT, ???
00576                BasicTexture::draw(v);
00577                ntt_done_vertex_program_1D();
00578 
00579                PaperEffect::end_paper_effect(ntt_paper_flag_1D);
00580 
00581                glPopAttrib();
00582 
00583                return _patch->num_faces();
00584             }
00585 
00586          // Failed. Create it.
00587          dl = _dl.get_dl(v, 1, _patch->stamp());
00588          if (dl)
00589             glNewList(dl, GL_COMPILE);
00590       }
00591 
00592    set_face_culling();                  // GL_ENABLE_BIT
00593    _patch->draw_tri_strips(_cb);
00594 
00595    if (ntt_use_vertex_program_1D) 
00596       {
00597          // End the display list here
00598          if (_dl.dl(v)) {
00599             _dl.close_dl(v);
00600 
00601             // Built it, now execute it
00602             ntt_setup_vertex_program_1D();       // GL_ENABLE_BIT, ???
00603             BasicTexture::draw(v);
00604             ntt_done_vertex_program_1D();
00605          }
00606       }
00607 
00608    PaperEffect::end_paper_effect(ntt_paper_flag_1D);
00609 
00610    glPopAttrib();
00611 
00612    GL_VIEW::print_gl_errors("ToonTexture_1D::draw - End");
00613 
00614    return _patch->num_faces();
00615 }
00616 
00617 /////////////////////////////////////
00618 // update()
00619 /////////////////////////////////////
00620 
00621 
00622 void
00623 ToonTexture_1D::update_tex(void)
00624 {
00625 
00626    int ind;
00627 
00628    if (!_toon_texture_names)
00629       {
00630          _toon_texture_names = new LIST<str_ptr>; assert(_toon_texture_names);
00631          _toon_texture_ptrs = new LIST<TEXTUREptr>; assert(_toon_texture_ptrs);
00632 
00633          _toon_texture_remap_orig_names = new LIST<str_ptr>; assert(_toon_texture_remap_orig_names);
00634          _toon_texture_remap_new_names = new LIST<str_ptr>; assert(_toon_texture_remap_new_names);
00635 
00636          int i = 0;
00637          while (toon_remap_fnames_1D[i][0] != NULL)
00638             {
00639                _toon_texture_remap_orig_names->add(str_ptr(toon_remap_base_1D) + toon_remap_fnames_1D[i][0]);
00640                _toon_texture_remap_new_names->add(str_ptr(toon_remap_base_1D) + toon_remap_fnames_1D[i][1]);
00641                i++;
00642             }
00643       }
00644 
00645    str_ptr tf = _tex_name;
00646 
00647    if (tf == NULL_STR)
00648       {
00649          assert(_tex == NULL);
00650          //_tex_name = NULL_STR;
00651          //_tex = NULL;
00652       }
00653    else if (_tex == NULL)
00654       {
00655          if ((ind = _toon_texture_names->get_index(tf)) != BAD_IND)
00656             {
00657                //Finding original name in cache...
00658 
00659                //If its a failed texture...
00660                if ((*_toon_texture_ptrs)[ind] == NULL)
00661                   {
00662                      //...see if it was remapped...
00663                      int ii = _toon_texture_remap_orig_names->get_index(tf);
00664                      //...and change to looking up the remapped name            
00665                      if (ii != BAD_IND)
00666                         {
00667                            str_ptr old_tf = tf;
00668                            tf = (*_toon_texture_remap_new_names)[ii];
00669 
00670                            ind = _toon_texture_names->get_index(tf);
00671 
00672                            err_mesg(ERR_LEV_SPAM, 
00673                                     "ToonTexture_1D::set_texture() - Previously remapped --===<<[[{{ (%s) ---> (%s) }}]]>>===--", 
00674                                     **(Config::JOT_ROOT()+old_tf), **(Config::JOT_ROOT()+tf) );
00675                         }
00676                   }
00677 
00678                //Now see if the final name yields a good texture...
00679                if ((*_toon_texture_ptrs)[ind] != NULL)
00680                   {
00681                      _tex = (*_toon_texture_ptrs)[ind];
00682                      _tex_name = tf;
00683                      err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::set_texture() - Using cached copy of texture.");
00684                   }
00685                else
00686                   {
00687                      err_mesg(ERR_LEV_INFO, "ToonTexture_1D::set_texture() - **ERROR** Previous caching failure: '%s'...", **tf);
00688                      _tex = NULL;
00689                      _tex_name = NULL_STR;
00690                   }
00691             }
00692          //Haven't seen this name before...
00693          else
00694             {
00695                err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::set_texture() - Not in cache...");
00696       
00697                Image i(Config::JOT_ROOT()+tf);
00698 
00699                //Can't load the texture?
00700                if (i.empty())
00701                   {
00702                      //...check for a remapped file...
00703                      int ii = _toon_texture_remap_orig_names->get_index(tf);
00704 
00705                      //...and use that name instead....
00706                      if (ii != BAD_IND)
00707                         {
00708                            //...but also indicate that the original name is bad...
00709 
00710                            _toon_texture_names->add(tf);
00711                            _toon_texture_ptrs->add(NULL);
00712 
00713                            str_ptr old_tf = tf;
00714                            tf = (*_toon_texture_remap_new_names)[ii];
00715 
00716                            err_mesg(ERR_LEV_ERROR, 
00717                                     "ToonTexture_1D::set_texture() - Remapping --===<<[[{{ (%s) ---> (%s) }}]]>>===--", 
00718                                     **(Config::JOT_ROOT()+old_tf), **(Config::JOT_ROOT()+tf) );
00719 
00720                            i.load_file(**(Config::JOT_ROOT()+tf));
00721                         }
00722                   }
00723 
00724                //If the final name loads, store the cached texture...
00725                if (!i.empty())
00726                   {
00727                      TEXTUREglptr t = new TEXTUREgl("");
00728 
00729                      t->set_save_img(true);
00730                      t->set_mipmap(true);
00731                      t->set_wrap_s(GL_CLAMP_TO_EDGE);
00732                      t->set_wrap_t(GL_CLAMP_TO_EDGE);
00733                      t->set_image(i.copy(),i.width(),i.height(),i.bpp());
00734          
00735 
00736                      _toon_texture_names->add(tf);
00737                      _toon_texture_ptrs->add(t);
00738 
00739                      err_mesg(ERR_LEV_INFO, "ToonTexture_1D::set_texture() - Cached: (w=%d h=%d bpp=%u) %s",
00740                               i.width(), i.height(), i.bpp(), **(Config::JOT_ROOT()+tf));;
00741 
00742                      _tex = t;
00743                      _tex_name = tf;
00744                   }
00745                //Otherwise insert a failed NULL
00746                else
00747                   {
00748                      err_mesg(ERR_LEV_ERROR, "ToonTexture_1D::set_texture() - *****ERROR***** Failed loading to cache: '%s'...", **(Config::JOT_ROOT()+tf));
00749          
00750                      _toon_texture_names->add(tf);
00751                      _toon_texture_ptrs->add(NULL);
00752 
00753                      _tex = NULL;
00754                      _tex_name = NULL_STR;
00755                   }
00756             }   
00757       }
00758 
00759 
00760 
00761 }
00762 
00763 /////////////////////////////////////
00764 // tags()
00765 /////////////////////////////////////
00766 CTAGlist &
00767 ToonTexture_1D::tags() const
00768 {
00769    if (!_ntt_tags) {
00770       _ntt_tags = new TAGlist;
00771       *_ntt_tags += OGLTexture::tags();
00772 
00773       *_ntt_tags += new TAG_val<ToonTexture_1D,int>(
00774          "use_paper",
00775          &ToonTexture_1D::use_paper_);
00776       *_ntt_tags += new TAG_val<ToonTexture_1D,int>(
00777          "travel_paper",
00778          &ToonTexture_1D::travel_paper_);
00779       *_ntt_tags += new TAG_val<ToonTexture_1D,COLOR>(
00780          "COLOR",
00781          &ToonTexture_1D::color_);
00782       *_ntt_tags += new TAG_val<ToonTexture_1D,double>(
00783          "alpha",
00784          &ToonTexture_1D::alpha_);
00785 
00786       *_ntt_tags += new TAG_val<ToonTexture_1D,int>(
00787          "light_index",
00788          &ToonTexture_1D::light_index_);
00789       *_ntt_tags += new TAG_val<ToonTexture_1D,int>(
00790          "light_dir",
00791          &ToonTexture_1D::light_dir_);
00792       *_ntt_tags += new TAG_val<ToonTexture_1D,int>(
00793          "light_cam",
00794          &ToonTexture_1D::light_cam_);
00795       *_ntt_tags += new TAG_val<ToonTexture_1D,Wvec>(
00796          "light_coords",
00797          &ToonTexture_1D::light_coords_);
00798 
00799 
00800       *_ntt_tags += new TAG_meth<ToonTexture_1D>(
00801          "texture",
00802          &ToonTexture_1D::put_tex_name,
00803          &ToonTexture_1D::get_tex_name,
00804          1);
00805       *_ntt_tags += new TAG_meth<ToonTexture_1D>(
00806          "layer_name",
00807          &ToonTexture_1D::put_layer_name,
00808          &ToonTexture_1D::get_layer_name,
00809          1);
00810 
00811 
00812       *_ntt_tags += new TAG_meth<ToonTexture_1D>(
00813          "transparent",
00814          &ToonTexture_1D::put_transparent,
00815          &ToonTexture_1D::get_transparent,
00816          0);
00817       *_ntt_tags += new TAG_meth<ToonTexture_1D>(
00818          "annotate",
00819          &ToonTexture_1D::put_annotate,
00820          &ToonTexture_1D::get_annotate,
00821          0);
00822 
00823    }
00824    return *_ntt_tags;
00825 }
00826 ////////////////////////////////////
00827 // put_layer_name()
00828 /////////////////////////////////////
00829 void
00830 ToonTexture_1D::put_layer_name(TAGformat &d) const
00831 {
00832    err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::put_layer_name()");
00833         
00834    d.id();
00835    if (get_layer_name() == NULL_STR)
00836       {
00837          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::put_layer_name() - Wrote NULL string.");
00838          *d << "NULL_STR";
00839          *d << " ";
00840       }
00841    else
00842       {
00843          *d << **(get_layer_name());
00844          *d << " ";
00845          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::put_layer_name() - Wrote string: '%s'", **get_tex_name());
00846       }
00847    d.end_id();
00848 }
00849 
00850 /////////////////////////////////////
00851 // get_layer_name()
00852 /////////////////////////////////////
00853 
00854 void
00855 ToonTexture_1D::get_layer_name(TAGformat &d)
00856 {
00857    err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::get_layer_name()");
00858 
00859    //XXX - May need something to handle filenames with spaces
00860 
00861    str_ptr str, lay, space;
00862    *d >> str;      
00863    if (!(*d).ascii()) *d >> space; 
00864 
00865    if (str == "NULL_STR") 
00866       {
00867          lay = NULL_STR;
00868          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::get_layer_name() - Loaded NULL string.");
00869       }
00870    else
00871       {
00872          lay = str;
00873          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::get_layer_name() - Loaded string: '%s'", **lay);
00874       }
00875    set_layer_name(lay);
00876 
00877 }
00878 
00879 ////////////////////////////////////
00880 // put_texname()
00881 /////////////////////////////////////
00882 void
00883 ToonTexture_1D::put_tex_name(TAGformat &d) const
00884 {
00885    err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::put_tex_name()");
00886 
00887    //XXX - May need something to handle filenames with spaces
00888 
00889    d.id();
00890    if (_tex_name == NULL_STR)
00891       {
00892          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::put_tex_name() - Wrote NULL string.");
00893          *d << "NULL_STR";
00894          *d << " ";
00895       }
00896    else
00897       {
00898          *d << **(get_tex_name());
00899          *d << " ";
00900          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::put_tex_name() - Wrote string: '%s'", **get_tex_name());
00901       }
00902    d.end_id();
00903 }
00904 
00905 /////////////////////////////////////
00906 // get_tex_name()
00907 /////////////////////////////////////
00908 
00909 void
00910 ToonTexture_1D::get_tex_name(TAGformat &d)
00911 {
00912    err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::get_tex_name()");
00913 
00914    //XXX - May need something to handle filenames with spaces
00915 
00916    str_ptr str, space;
00917    *d >> str;      
00918    if (!(*d).ascii()) *d >> space; 
00919 
00920    if (str == "NULL_STR") 
00921       {
00922          str = NULL_STR;
00923          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::get_tex_name() - Loaded NULL string.");
00924       }
00925    else
00926       {
00927          err_mesg(ERR_LEV_SPAM, "ToonTexture_1D::get_tex_name() - Loaded string: '%s'", **str);
00928       }
00929    set_tex_name(str);
00930 
00931 }
00932 
00933 
00934 ////////////////////////////////////
00935 // put_transparent()
00936 /////////////////////////////////////
00937 void
00938 ToonTexture_1D::put_transparent(TAGformat &d) const
00939 {
00940    // XXX - Deprecated
00941 }
00942 
00943 /////////////////////////////////////
00944 // get_transparent()
00945 /////////////////////////////////////
00946 void
00947 ToonTexture_1D::get_transparent(TAGformat &d)
00948 {
00949    err_mesg(ERR_LEV_WARN, "ToonTexture_1D::get_transparent() - ***NOTE: Loading OLD format file!***");
00950 
00951    *d >> _transparent;
00952 }
00953 
00954 ////////////////////////////////////
00955 // put_annotate()
00956 /////////////////////////////////////
00957 void
00958 ToonTexture_1D::put_annotate(TAGformat &d) const
00959 {
00960    // XXX - Deprecated
00961 }
00962 
00963 /////////////////////////////////////
00964 // get_annotate()
00965 /////////////////////////////////////
00966 void
00967 ToonTexture_1D::get_annotate(TAGformat &d)
00968 {
00969    err_mesg(ERR_LEV_WARN, "ToonTexture_1D::get_annotate() - ***NOTE: Loading OLD format file!***");
00970    
00971    *d >> _annotate;
00972 }
00973 
00974 // end of file toon_texture.C

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4