00001
00002
00003
00004 #include "geom/texturegl.H"
00005 #include "mesh/ioblock.H"
00006 #include "mesh/lmesh.H"
00007 #include "std/config.H"
00008
00009 #include "basic_texture.H"
00010 #include "color_id_texture.H"
00011 #include "control_line.H"
00012 #include "creases_texture.H"
00013 #include "curvature_texture.H"
00014 #include "line_drawing.H"
00015 #include "fader_texture.H"
00016 #include "flat_shade.H"
00017 #include "hidden_line.H"
00018 #include "key_line.H"
00019 #include "normals_texture.H"
00020 #include "ref_image.H"
00021 #include "sil_frame.H"
00022 #include "smooth_shade.H"
00023 #include "solid_color.H"
00024 #include "tri_strips_texture.H"
00025 #include "wireframe.H"
00026 #include "zxsil_frame.H"
00027 #include "toon_texture_1D.H"
00028 #include "glsl_shader.H"
00029 #include "halftone_shader.H"
00030 #include "halftone_shader_ex.H"
00031 #include "glsl_xtoon.H"
00032 #include "glsl_toon.H"
00033 #include "glsl_halo.H"
00034 #include "glsl_toon_halo.H"
00035 #include "dots.H"
00036 #include "dots_ex.H"
00037 #include "glsl_hatching.H"
00038 #include "glsl_marble.H"
00039 #include "msld.H"
00040
00041
00042 class DecoderAdds {
00043 public:
00044 DecoderAdds() {
00045 DECODER_ADD(ColorIDTexture);
00046 DECODER_ADD(ControlFrameTexture);
00047 DECODER_ADD(ControlLineTexture);
00048 DECODER_ADD(CreasesTexture);
00049 DECODER_ADD(CurvatureTexture);
00050 DECODER_ADD(FlatShadeTexture);
00051 DECODER_ADD(HiddenLineTexture);
00052 DECODER_ADD(KeyLineTexture);
00053 DECODER_ADD(LineDrawingTexture);
00054 DECODER_ADD(NormalsTexture);
00055 DECODER_ADD(SilFrameTexture);
00056 DECODER_ADD(SmoothShadeTexture);
00057 DECODER_ADD(SolidColorTexture);
00058 DECODER_ADD(TriStripsTexture);
00059 DECODER_ADD(VertColorTexture);
00060 DECODER_ADD(WireframeTexture);
00061 DECODER_ADD(ZcrossFrameTexture);
00062 DECODER_ADD(ToonTexture_1D);
00063 DECODER_ADD(GLSLShader);
00064 DECODER_ADD(GLSLLightingShader);
00065 DECODER_ADD(HalftoneShader);
00066 DECODER_ADD(HalftoneShaderEx);
00067 DECODER_ADD(GLSLXToonShader);
00068 DECODER_ADD(GLSLToonShader);
00069 DECODER_ADD(GLSLHaloShader);
00070 DECODER_ADD(GLSLToonShaderHalo);
00071 DECODER_ADD(DotsShader);
00072 DECODER_ADD(DotsShader_EX);
00073 DECODER_ADD(GLSLHatching);
00074 DECODER_ADD(GLSLMarbleShader);
00075 DECODER_ADD(MSLDShader);
00076 }
00077 } DecoderAdds_static;
00078
00079 class SetupGL {
00080 public:
00081 SetupGL() {
00082
00083
00084 VisRefImage::init();
00085 }
00086 } SetupGL_static;
00087
00088
00089
00090
00091 int OGLTexture::draw_stencil() {
00092
00093 if (_patch == NULL) return -1;
00094
00095 glColorMask(0, 0, 0, 0);
00096 glDisable(GL_DEPTH_TEST);
00097
00098 glStencilFunc(GL_ALWAYS, 1, 0xFF);
00099 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
00100
00101
00102 GLStripCB cb;
00103 _patch->draw_tri_strips(&cb);
00104
00105 glColorMask(1, 1, 1, 1);
00106 glEnable(GL_DEPTH_TEST);
00107
00108 return 1;
00109 }
00110
00111 bool
00112 OGLTexture::set_face_culling() const
00113 {
00114
00115
00116 static bool no_cull = Config::get_var_bool("JOT_NO_FACE_CULLING",false);
00117
00118
00119 BMESH* m = get_cur_mesh(mesh());
00120 bool ret = (!no_cull && m && m->is_closed_surface());
00121 if (ret) glEnable (GL_CULL_FACE);
00122 else glDisable(GL_CULL_FACE);
00123 return ret;
00124 }
00125
00126 int
00127 OGLTexture::draw_vis_ref()
00128 {
00129
00130 GTexture *tex = _patch->get_tex(ColorIDTexture::static_name());
00131
00132
00133
00134
00135 return tex ? tex->draw(VIEW::peek()) : 0;
00136 }
00137
00138 int
00139 OGLTexture::draw_id_ref()
00140 {
00141 ColorIDTexture *tex = (ColorIDTexture*)
00142 _patch->get_tex(ColorIDTexture::static_name());
00143
00144 if (tex) {
00145
00146
00147
00148
00149 return (
00150 (use_ref_image() & REF_IMG_ID) ?
00151 tex->draw(VIEW::peek()) :
00152 tex->draw_black(VIEW::peek())
00153 );
00154 }
00155
00156 return 0;
00157 }
00158
00159 int
00160 OGLTexture::draw_id_sils(bool omit_concave_sils, GLfloat width)
00161 {
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 EdgeStrip& sils = _patch->cur_sils();
00173
00174 if (omit_concave_sils) {
00175
00176 static EdgeStrip convex_sil_edges = sils.get_filtered(ConvexEdgeFilter());
00177 ColorIDTexture::draw_edges(&convex_sil_edges, width);
00178 } else {
00179 ColorIDTexture::draw_edges(&sils, width);
00180 }
00181
00182 return 0;
00183 }
00184
00185 int
00186 OGLTexture::draw_id_triangles(bool use_polygon_offset,
00187 bool draw_id_colors,
00188 double offset_factor,
00189 double offset_units)
00190 {
00191
00192
00193
00194 ColorIDTexture *tex = (ColorIDTexture*)
00195 _patch->get_tex(ColorIDTexture::static_name());
00196 if (tex) {
00197 if (use_polygon_offset)
00198 GL_VIEW::init_polygon_offset((float)offset_factor,
00199 (float)offset_units);
00200 if (draw_id_colors) tex->draw(VIEW::peek());
00201 else tex->draw_black(VIEW::peek());
00202 if (use_polygon_offset)
00203 GL_VIEW::end_polygon_offset();
00204 } else
00205 err_msg( "OGLTexture::draw_id_triangles: warning -- no ColorIDTexture");
00206
00207 return _patch->num_faces();
00208 }
00209
00210 int
00211 OGLTexture::draw_id_creases(GLfloat width)
00212 {
00213
00214
00215
00216 EdgeStrip* creases = _patch->cur_creases();
00217
00218 ColorIDTexture::draw_edges(creases, width);
00219
00220 return 0;
00221 }
00222
00223 void
00224 OGLTexture::draw_vert_and_edge_strips(
00225 bool disable_lights,
00226 GLfloat line_width,
00227 GLfloat point_size,
00228 bool set_color,
00229 CCOLOR& color
00230 ) const
00231 {
00232
00233
00234
00235
00236
00237 if (_patch->num_edge_strips() > 0) {
00238 if (disable_lights) {
00239 glDisable(GL_LIGHTING);
00240 disable_lights = 0;
00241 }
00242 if (set_color) {
00243 glColor3dv(color.data());
00244 set_color = 0;
00245 }
00246 glLineWidth(line_width);
00247 _patch->draw_edge_strips(_cb);
00248 glLineWidth(1.0);
00249 }
00250
00251
00252 if (_patch->num_vert_strips() > 0) {
00253 if (disable_lights)
00254 glDisable(GL_LIGHTING);
00255 if (set_color)
00256 glColor3dv(color.data());
00257 glPointSize(point_size);
00258 _patch->draw_vert_strips(_cb);
00259 glPointSize(1.0);
00260 }
00261 }
00262
00263 void
00264 OGLTexture::check_patch_texture_map()
00265 {
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 if (!_patch || _patch->has_texture())
00278 return;
00279
00280 Cstr_ptr& n = _patch->texture_file();
00281
00282 if (n && n != NULL_STR) {
00283 TEXTUREptr tex = new TEXTUREgl(n);
00284
00285 if (tex->load_texture()) {
00286 _patch->set_texture(tex);
00287 }
00288
00289 _patch->set_texture_file(NULL_STR);
00290 }
00291 }
00292
00293
00294
00295
00296 int
00297 BasicTexture::draw(CVIEWptr &v)
00298 {
00299
00300
00301
00302 int ret = dl_valid(v);
00303
00304 if (ret==1) glCallList(_dl.dl(v));
00305
00306 return ret;
00307 }
00308
00309 int
00310 BasicTexture::dl_valid(CVIEWptr &v)
00311 {
00312
00313
00314 if (_dl.valid(v, (int) _patch->stamp())) {
00315 return 1;
00316 } else {
00317 return 0;
00318 }
00319 }
00320
00321