00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "glew/glew.H"
00011 #include "gl_extensions.H"
00012 #include "std/config.H"
00013
00014
00015
00016
00017
00018
00019 #ifdef STUB_GLX_SGIX_video_resize
00020
00021 int glXBindChannelToWindowSGIX (Display *, int, int, Window) { cerr << "gl_extensions.h::glXBindChannelToWindowSGIX() ********* STUB!!!!! *********\n"; return 0; }
00022 int glXChannelRectSGIX (Display *, int, int, int, int, int, int) { cerr << "gl_extensions.h::glXChannelRectSGIX() ********* STUB!!!!! *********\n"; return 0; }
00023 int glXQueryChannelRectSGIX (Display *, int, int, int *, int *, int *, int *) { cerr << "gl_extensions.h::glXQueryChannelRectSGIX() ********* STUB!!!!! *********\n"; return 0; }
00024 int glXQueryChannelDeltasSGIX (Display *, int, int, int *, int *, int *, int *) { cerr << "gl_extensions.h::glXQueryChannelDeltasSGIX() ********* STUB!!!!! *********\n"; return 0; }
00025 int glXChannelRectSyncSGIX (Display *, int, int, GLenum) { cerr << "gl_extensions.h::glXChannelRectSyncSGIX() ********* STUB!!!!! *********\n"; return 0; }
00026
00027 #endif // STUB_GLX_SGIX_video_resize
00028
00029
00030
00031
00032
00033 bool GLExtensions::_gl_arb_multitexture_supported = false;
00034 bool GLExtensions::_gl_nv_register_combiners_supported = false;
00035 bool GLExtensions::_gl_nv_vertex_program_supported = false;
00036 bool GLExtensions::_gl_ext_compiled_vertex_array_supported = false;
00037 bool GLExtensions::_gl_arb_vertex_program_supported = false;
00038 bool GLExtensions::_gl_arb_fragment_program_supported = false;
00039 bool GLExtensions::_gl_ati_fragment_shader_supported = false;
00040 bool GLExtensions::_gl_nv_fragment_program_option_supported = false;
00041 bool GLExtensions::_gl_arb_shader_objects_supported = false;
00042 bool GLExtensions::_gl_arb_vertex_shader_supported = false;
00043 bool GLExtensions::_gl_arb_fragment_shader_supported = false;
00044
00045 bool GLExtensions::_init = false;
00046
00047 bool GLExtensions::_debug = Config::get_var_bool("DEBUG_GL_EXTENSIONS",false,true);
00048
00049
00050
00051
00052
00053 GLExtensions::GLExtensions()
00054 {
00055 assert(0);
00056 }
00057
00058
00059
00060
00061
00062 GLExtensions::~GLExtensions()
00063 {
00064 assert(0);
00065 }
00066
00067
00068
00069
00070 void
00071 GLExtensions::internal_init()
00072 {
00073 assert(!_init);
00074 err_mesg(ERR_LEV_INFO, "GLExtensions::init() - Initializing GL extensions...");
00075 init_extensions();
00076 _init = true;
00077 err_mesg(ERR_LEV_INFO, "GLExtensions::init() - ...done.");
00078 }
00079
00080
00081
00082
00083
00084 void
00085 GLExtensions::init_extensions()
00086 {
00087
00088 _gl_arb_multitexture_supported = init_gl_arb_multitexture();
00089 _gl_nv_register_combiners_supported = init_gl_nv_register_combiners();
00090 _gl_nv_vertex_program_supported = init_gl_nv_vertex_program();
00091 _gl_ext_compiled_vertex_array_supported = init_gl_ext_compiled_vertex_array();
00092 _gl_arb_vertex_program_supported = init_gl_arb_vertex_program();
00093 _gl_arb_fragment_program_supported = init_gl_arb_fragment_program();
00094 _gl_ati_fragment_shader_supported = init_gl_ati_fragment_shader();
00095 _gl_nv_fragment_program_option_supported = init_gl_nv_fragment_program_option();
00096 _gl_arb_shader_objects_supported = init_gl_arb_shader_objects();
00097 _gl_arb_vertex_shader_supported = init_gl_arb_vertex_shader();
00098 _gl_arb_fragment_shader_supported = init_gl_arb_fragment_shader();
00099
00100 }
00101
00102
00103
00104
00105
00106 bool
00107 GLExtensions::init_gl_ext_compiled_vertex_array()
00108 {
00109 if (Config::get_var_bool("NO_GL_EXT_compiled_vertex_array",false,true))
00110 {
00111 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_EXT_compiled_vertex_array - Just saying no!");
00112 return false;
00113 }
00114
00115 #ifdef GL_EXT_compiled_vertex_array
00116
00117 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_EXT_compiled_vertex_array is defined in glext.h!");
00118
00119 if (is_extension_supported("GL_EXT_compiled_vertex_array"))
00120 {
00121 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_EXT_compiled_vertex_array is supported by hardware!");
00122 return true;
00123 }
00124 else
00125 {
00126 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_EXT_compiled_vertex_array is NOT supported by hardware!");
00127 return false;
00128 }
00129 #else //GL_EXT_compiled_vertex_array
00130 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_EXT_compiled_vertex_array is not defined in glext.h!");
00131 return false;
00132 #endif //GL_EXT_compiled_vertex_array
00133
00134 }
00135
00136
00137
00138
00139
00140 bool
00141 GLExtensions::init_gl_nv_vertex_program()
00142 {
00143 if (Config::get_var_bool("NO_GL_NV_vertex_program",false,true))
00144 {
00145 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_NV_vertex_program - Just saying no!");
00146 return false;
00147 }
00148
00149 #ifdef GL_NV_vertex_program
00150
00151 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_vertex_program is defined in glext.h!");
00152
00153 if (is_extension_supported("GL_NV_vertex_program"))
00154 {
00155 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_vertex_program is supported by hardware!");
00156 return true;
00157 }
00158 else
00159 {
00160 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_vertex_program is NOT supported by hardware!");
00161 return false;
00162 }
00163 #else
00164 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_NV_vertex_program is not defined in glext.h!");
00165 return false;
00166 #endif
00167
00168 }
00169
00170
00171
00172
00173
00174 bool
00175 GLExtensions::init_gl_arb_multitexture()
00176 {
00177 if (Config::get_var_bool("NO_GL_ARB_multitexture",false,true))
00178 {
00179 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_multitexture - Just saying no!");
00180 return false;
00181 }
00182
00183 #ifdef GL_ARB_multitexture
00184
00185 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_multitexture is defined in glext.h!");
00186
00187 if (is_extension_supported("GL_ARB_multitexture"))
00188 {
00189 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_multitexture is supported by hardware!");
00190 return true;
00191 }
00192 else
00193 {
00194 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_multitexture is NOT supported by hardware!");
00195 return false;
00196 }
00197 #else //GL_ARB_multitexture
00198 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_multitexture is not defined in glext.h!");
00199 return false;
00200 #endif //GL_ARB_multitexture
00201
00202 }
00203
00204
00205
00206
00207
00208 bool
00209 GLExtensions::init_gl_nv_register_combiners()
00210 {
00211 if (Config::get_var_bool("NO_GL_NV_register_combiners",false,true))
00212 {
00213 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_NV_register_combiners - Just saying no!");
00214 return false;
00215 }
00216
00217 #ifdef GL_NV_register_combiners
00218
00219 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_register_combiners is defined in glext.h!");
00220
00221 if (is_extension_supported("GL_NV_register_combiners"))
00222 {
00223 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_register_combiners is supported by hardware!");
00224 return true;
00225 }
00226 else
00227 {
00228 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_register_combiners is NOT supported by hardware!");
00229 return false;
00230 }
00231 #else //GL_NV_register_combiners
00232 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_NV_register_combiners is not defined in glext.h!");
00233 return false;
00234 #endif //GL_NV_register_combiners
00235
00236 }
00237
00238
00239
00240
00241
00242
00243 bool
00244 GLExtensions::init_gl_arb_vertex_program()
00245 {
00246 if (Config::get_var_bool("NO_GL_ARB_vertex_program",false,true))
00247 {
00248 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_vertex_program - Just saying no!");
00249 return false;
00250 }
00251
00252 #ifdef GL_ARB_vertex_program
00253
00254 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_vertex_program is defined in glext.h!");
00255
00256 if (is_extension_supported("GL_ARB_vertex_program"))
00257 {
00258 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_vertex_program is supported by hardware!");
00259 return true;
00260 }
00261 else
00262 {
00263 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_vertex_program is NOT supported by hardware!");
00264 return false;
00265 }
00266 #else
00267 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_vertex_program is not defined in glext.h!");
00268 return false;
00269 #endif
00270
00271 }
00272
00273
00274
00275
00276
00277
00278
00279 bool
00280 GLExtensions::init_gl_arb_fragment_program()
00281 {
00282 if (Config::get_var_bool("NO_GL_ARB_fragment_program",false,true))
00283 {
00284 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_fragment_program - Just saying no!");
00285 return false;
00286 }
00287
00288 #ifdef GL_ARB_fragment_program
00289
00290 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_fragment_program is defined in glext.h!");
00291
00292 if (is_extension_supported("GL_ARB_fragment_program"))
00293 {
00294 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_fragment_program is supported by hardware!");
00295 return true;
00296 }
00297 else
00298 {
00299 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_fragment_program is NOT supported by hardware!");
00300 return false;
00301 }
00302 #else
00303 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_fragment_program is not defined in glext.h!");
00304 return false;
00305 #endif
00306
00307 }
00308
00309
00310
00311
00312
00313
00314 bool
00315 GLExtensions::init_gl_ati_fragment_shader()
00316 {
00317 if (Config::get_var_bool("NO_GL_ATI_fragment_shader",false,true))
00318 {
00319 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ATI_fragment_shader - Just saying no!");
00320 return false;
00321 }
00322
00323 #ifdef GL_ATI_fragment_shader
00324
00325 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ATI_fragment_shader is defined in glext.h!");
00326
00327 if (is_extension_supported("GL_ATI_fragment_shader"))
00328 {
00329 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ATI_fragment_shader is supported by hardware!");
00330 return true;
00331 }
00332 else
00333 {
00334 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ATI_fragment_shader is NOT supported by hardware!");
00335 return false;
00336 }
00337 #else //GL_ATI_fragment_shader
00338 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ATI_fragment_shader is not defined in glext.h!");
00339 return false;
00340 #endif //GL_ATI_fragment_shader
00341
00342 }
00343
00344
00345
00346
00347
00348 bool
00349 GLExtensions::init_gl_nv_fragment_program_option()
00350 {
00351
00352 #ifdef GL_NV_fragment_program_option
00353
00354 if (is_extension_supported("GL_NV_fragment_program_option"))
00355 {
00356 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_fragment_program_option is supported by hardware!");
00357 return true;
00358 }
00359 else
00360 {
00361 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_NV_fragment_program_option is NOT supported by hardware!");
00362 return false;
00363 }
00364
00365 #else // GL_NV_fragment_program_option
00366
00367 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_NV_fragment_program_option is not defined in glext.h!");
00368 return false;
00369
00370 #endif // GL_NV_fragment_program_option
00371
00372 }
00373
00374
00375
00376
00377
00378 bool
00379 GLExtensions::init_gl_arb_shader_objects()
00380 {
00381
00382 #ifdef GL_ARB_shader_objects
00383
00384 if (is_extension_supported("GL_ARB_shader_objects"))
00385 {
00386 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_shader_objects is supported by hardware!");
00387 return true;
00388 }
00389 else
00390 {
00391 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_shader_objects is NOT supported by hardware!");
00392 return false;
00393 }
00394
00395 #else
00396
00397 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_shader_objects is not defined in glext.h!");
00398 return false;
00399
00400 #endif
00401
00402 }
00403
00404
00405
00406
00407
00408 bool
00409 GLExtensions::init_gl_arb_vertex_shader()
00410 {
00411
00412 #ifdef GL_ARB_vertex_shader
00413
00414 if (is_extension_supported("GL_ARB_vertex_shader") &&
00415 init_gl_arb_shader_objects() &&
00416 init_gl_arb_vertex_program())
00417 {
00418 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_vertex_shader is supported by hardware!");
00419 return true;
00420 }
00421 else
00422 {
00423 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_vertex_shader is NOT supported by hardware!");
00424 return false;
00425 }
00426
00427 #else
00428
00429 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_vertex_shader is not defined in glext.h!");
00430 return false;
00431
00432 #endif
00433
00434 }
00435
00436
00437
00438
00439
00440 bool
00441 GLExtensions::init_gl_arb_fragment_shader()
00442 {
00443
00444 #ifdef GL_ARB_fragment_shader
00445
00446 if (is_extension_supported("GL_ARB_fragment_shader") && init_gl_arb_shader_objects())
00447 {
00448 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_fragment_shader is supported by hardware!");
00449 return true;
00450 }
00451 else
00452 {
00453 err_mesg(ERR_LEV_INFO, "GLExtensions: GL_ARB_fragment_shader is NOT supported by hardware!");
00454 return false;
00455 }
00456
00457 #else
00458
00459 err_mesg(ERR_LEV_WARN, "GLExtensions: GL_ARB_fragment_shader is not defined in glext.h!");
00460 return false;
00461
00462 #endif
00463
00464 }
00465
00466
00467
00468
00469
00470 bool
00471 GLExtensions::is_extension_supported(const char *extension)
00472 {
00473
00474 return GLEWSingleton::Instance().is_supported(extension);
00475
00476 }
00477
00478
00479
00480
00481
00482 bool
00483 GLExtensions::gl_arb_vertex_program_loaded(
00484 Cstr_ptr &header,
00485 bool &native,
00486 const unsigned char *prog)
00487 {
00488 bool success;
00489
00490 if (!gl_arb_vertex_program_supported())
00491 {
00492 err_mesg(ERR_LEV_INFO, "%sGL_ARB_vertex_program not supported.", **header);
00493 native = false;
00494 success = false;
00495 }
00496 else
00497 {
00498 #ifdef GL_ARB_vertex_program
00499
00500 int i;
00501 unsigned char *err_buf1, *err_buf2;
00502 const GLubyte *err_str;
00503 GLint err_pos;
00504 GLint is_native;
00505
00506 GLenum err = glGetError();
00507
00508 err_mesg(ERR_LEV_INFO, "%sLoading program...", **header);
00509
00510 err_str = glGetString( GL_PROGRAM_ERROR_STRING_ARB );
00511 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err_pos );
00512 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &is_native);
00513
00514 native = (is_native != 0);
00515
00516 if (err_pos != -1)
00517 {
00518 int prog_len = strlen((const char *)prog); assert(err_pos <= prog_len);
00519
00520 int err_left = err_pos, err_right = err_pos;
00521
00522 while ((err_left > 0) &&
00523 (prog[err_left-1] != '\n' &&
00524 prog[err_left-1] != ';' &&
00525 prog[err_left-1] != '\r')) err_left--;
00526 while ((err_right < prog_len) &&
00527 (prog[err_right+1] != '\n' &&
00528 prog[err_right] != ';' &&
00529 prog[err_right+1] != '\r' &&
00530 prog[err_right+1] != 0 )) err_right++;
00531
00532 err_buf1 = new unsigned char [err_right - err_left + 2]; assert(err_buf1);
00533 err_buf2 = new unsigned char [err_right - err_left + 2]; assert(err_buf2);
00534
00535 for (i=0; i<(err_right-err_left+1); i++)
00536 {
00537 err_buf1[i] = prog[err_left+i];
00538 err_buf2[i] = ' ';
00539 }
00540 err_buf2[err_pos-err_left]='^';
00541
00542 err_buf1[i] = 0;
00543 err_buf2[i] = 0;
00544
00545 }
00546
00547 if ( err == GL_INVALID_OPERATION )
00548 {
00549 success = false;
00550
00551
00552
00553 assert(err_str && (err_str[0] != 0));
00554
00555 err_mesg(ERR_LEV_ERROR, "%s*** Failed! ***", **header);
00556
00557 if (err_pos != -1)
00558 {
00559 err_mesg(ERR_LEV_ERROR, "%sERROR LOCATION: %d", **header, err_pos);
00560 err_mesg(ERR_LEV_ERROR, "%sERROR EXCERPT: [%s]", **header, err_buf1);
00561 err_mesg(ERR_LEV_ERROR, "%s [%s]", **header, err_buf2);
00562 }
00563
00564 err_mesg(ERR_LEV_ERROR, "%sERROR STRING: '%s'", **header, err_str);
00565 }
00566 else
00567 {
00568 success = true;
00569
00570 if (native)
00571 err_mesg(ERR_LEV_INFO, "%sWill execute natively in hardware.", **header);
00572 else
00573 err_mesg(ERR_LEV_WARN, "%sWill execute **BUT** not natively in hardware. Using emulation...", **header);
00574
00575 if (err_pos != -1)
00576 {
00577 err_mesg(ERR_LEV_WARN, "%sWARNING LOCATION: %d", **header, err_pos);
00578 err_mesg(ERR_LEV_WARN, "%sWARNING EXCERPT: [%s]", **header, err_buf1);
00579 err_mesg(ERR_LEV_WARN, "%s [%s]", **header, err_buf2);
00580 }
00581
00582 if (err_str && (err_str[0] != 0))
00583 err_mesg(ERR_LEV_WARN, "%sWARNING STRING: '%s'", **header, err_str);
00584
00585 }
00586
00587 if (err_pos != -1)
00588 {
00589 delete[] err_buf1;
00590 delete[] err_buf2;
00591 }
00592
00593 GLint ins_num, ins_max, nins_num, nins_max;
00594 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_INSTRUCTIONS_ARB, &ins_num);
00595 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_INSTRUCTIONS_ARB, &ins_max);
00596 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &nins_num);
00597 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &nins_max);
00598
00599 GLint tmp_num, tmp_max, ntmp_num, ntmp_max;
00600 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_TEMPORARIES_ARB, &tmp_num);
00601 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_TEMPORARIES_ARB, &tmp_max);
00602 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_NATIVE_TEMPORARIES_ARB, &ntmp_num);
00603 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &ntmp_max);
00604
00605 GLint par_num, par_max, npar_num, npar_max;
00606 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_PARAMETERS_ARB, &par_num);
00607 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_PARAMETERS_ARB, &par_max);
00608 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_NATIVE_PARAMETERS_ARB, &npar_num);
00609 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &npar_max);
00610
00611 GLint att_num, att_max, natt_num, natt_max;
00612 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_ATTRIBS_ARB, &att_num);
00613 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ATTRIBS_ARB, &att_max);
00614 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_NATIVE_ATTRIBS_ARB, &natt_num);
00615 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, &natt_max);
00616
00617 GLint add_num, add_max, nadd_num, nadd_max;
00618 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_ADDRESS_REGISTERS_ARB, &add_num);
00619 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, &add_max);
00620 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, &nadd_num);
00621 glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, &nadd_max);
00622
00623 err_mesg(ERR_LEV_SPAM, "%sResource Usage:", **header);
00624 err_mesg(ERR_LEV_SPAM, "%s Instructions (ARB): MAX=%d USED=%d", **header, ins_max, ins_num);
00625 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, nins_max, nins_num);
00626 err_mesg(ERR_LEV_SPAM, "%s Temporaries (ARB): MAX=%d USED=%d", **header, tmp_max, tmp_num);
00627 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, ntmp_max, tmp_num);
00628 err_mesg(ERR_LEV_SPAM, "%s Parameters (ARB): MAX=%d USED=%d", **header, par_max, par_num);
00629 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, npar_max, npar_num);
00630 err_mesg(ERR_LEV_SPAM, "%s Attributes (ARB): MAX=%d USED=%d", **header, att_max, att_num);
00631 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, natt_max, natt_num);
00632 err_mesg(ERR_LEV_SPAM, "%s Addressors (ARB): MAX=%d USED=%d", **header, add_max, add_num);
00633 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, nadd_max, nadd_num);
00634 err_mesg(ERR_LEV_SPAM, "%s...done.", **header);
00635 #endif
00636 }
00637 return success;
00638 }
00639
00640
00641
00642
00643
00644 bool
00645 GLExtensions::gl_arb_fragment_program_loaded(
00646 Cstr_ptr &header,
00647 bool &native,
00648 const unsigned char *prog)
00649 {
00650 bool success;
00651
00652 if (!gl_arb_fragment_program_supported())
00653 {
00654 err_mesg(ERR_LEV_INFO, "%GL_ARB_fragment_program not supported.", **header);
00655 native = false;
00656 success = false;
00657 }
00658 else
00659 {
00660 #ifdef GL_ARB_fragment_program
00661
00662 int i;
00663 unsigned char *err_buf1, *err_buf2;
00664 const GLubyte *err_str;
00665 GLint err_pos;
00666 GLint is_native;
00667
00668 GLenum err = glGetError();
00669
00670 err_mesg(ERR_LEV_INFO, "%sLoading program...", **header);
00671
00672 err_str = glGetString( GL_PROGRAM_ERROR_STRING_ARB );
00673 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err_pos );
00674 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &is_native);
00675
00676 native = (is_native != 0);
00677
00678 if (err_pos != -1)
00679 {
00680 int prog_len = strlen((const char *)prog); assert(err_pos <= prog_len);
00681
00682 int err_left = err_pos, err_right = err_pos;
00683
00684 while ((err_left > 0) &&
00685 (prog[err_left-1] != '\n' &&
00686 prog[err_left-1] != ';' &&
00687 prog[err_left-1] != '\r')) err_left--;
00688 while ((err_right < prog_len) &&
00689 (prog[err_right+1] != '\n' &&
00690 prog[err_right] != ';' &&
00691 prog[err_right+1] != '\r' &&
00692 prog[err_right+1] != 0 )) err_right++;
00693
00694 err_buf1 = new unsigned char [err_right - err_left + 2]; assert(err_buf1);
00695 err_buf2 = new unsigned char [err_right - err_left + 2]; assert(err_buf2);
00696
00697 for (i=0; i<(err_right-err_left+1); i++)
00698 {
00699 err_buf1[i] = prog[err_left+i];
00700 err_buf2[i] = ' ';
00701 }
00702 err_buf2[err_pos-err_left]='^';
00703
00704 err_buf1[i] = 0;
00705 err_buf2[i] = 0;
00706
00707 }
00708
00709 if ( err == GL_INVALID_OPERATION )
00710 {
00711 success = false;
00712
00713
00714
00715 assert(err_str && (err_str[0] != 0));
00716
00717 err_mesg(ERR_LEV_ERROR, "%s*** Failed! ***", **header);
00718
00719 if (err_pos != -1)
00720 {
00721 err_mesg(ERR_LEV_ERROR, "%sERROR LOCATION: %d", **header, err_pos);
00722 err_mesg(ERR_LEV_ERROR, "%sERROR EXCERPT: [%s]", **header, err_buf1);
00723 err_mesg(ERR_LEV_ERROR, "%s [%s]", **header, err_buf2);
00724 }
00725
00726 err_mesg(ERR_LEV_ERROR, "%sERROR STRING: '%s'", **header, err_str);
00727
00728 }
00729 else
00730 {
00731 success = true;
00732
00733 if (native)
00734 err_mesg(ERR_LEV_INFO, "%sWill execute natively in hardware.", **header);
00735 else
00736 err_mesg(ERR_LEV_WARN, "%sWill execute **BUT** not natively in hardware. Using emulation...", **header);
00737
00738 if (err_pos != -1)
00739 {
00740 err_mesg(ERR_LEV_WARN, "%sWARNING LOCATION: %d", **header, err_pos);
00741 err_mesg(ERR_LEV_WARN, "%sWARNING EXCERPT: [%s]", **header, err_buf1);
00742 err_mesg(ERR_LEV_WARN, "%s [%s]", **header, err_buf2);
00743 }
00744
00745 if (err_str && (err_str[0] != 0))
00746 err_mesg(ERR_LEV_WARN, "%sWARNING STRING: '%s'", **header, err_str);
00747
00748 }
00749
00750 if (err_pos != -1)
00751 {
00752 delete[] err_buf1;
00753 delete[] err_buf2;
00754 }
00755
00756 GLint ins_num, ins_max, nins_num, nins_max;
00757 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_INSTRUCTIONS_ARB, &ins_num);
00758 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_INSTRUCTIONS_ARB, &ins_max);
00759 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &nins_num);
00760 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &nins_max);
00761
00762 GLint ains_num, ains_max, nains_num, nains_max;
00763 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_ALU_INSTRUCTIONS_ARB, &ains_num);
00764 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, &ains_max);
00765 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, &nains_num);
00766 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, &nains_max);
00767
00768 GLint tins_num, tins_max, ntins_num, ntins_max;
00769 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_TEX_INSTRUCTIONS_ARB, &tins_num);
00770 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, &tins_max);
00771 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, &ntins_num);
00772 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, &ntins_max);
00773
00774 GLint txns_num, txns_max, ntxns_num, ntxns_max;
00775 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_TEX_INDIRECTIONS_ARB, &txns_num);
00776 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, &txns_max);
00777 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, &ntxns_num);
00778 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, &ntxns_max);
00779
00780 GLint tmp_num, tmp_max, ntmp_num, ntmp_max;
00781 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_TEMPORARIES_ARB, &tmp_num);
00782 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_TEMPORARIES_ARB, &tmp_max);
00783 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_NATIVE_TEMPORARIES_ARB, &ntmp_num);
00784 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &ntmp_max);
00785
00786 GLint par_num, par_max, npar_num, npar_max;
00787 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_PARAMETERS_ARB, &par_num);
00788 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_PARAMETERS_ARB, &par_max);
00789 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_NATIVE_PARAMETERS_ARB, &npar_num);
00790 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &npar_max);
00791
00792 GLint att_num, att_max, natt_num, natt_max;
00793 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_ATTRIBS_ARB, &att_num);
00794 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ATTRIBS_ARB, &att_max);
00795 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_NATIVE_ATTRIBS_ARB, &natt_num);
00796 glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, &natt_max);
00797
00798 err_mesg(ERR_LEV_SPAM, "%sResource Usage:", **header);
00799 err_mesg(ERR_LEV_SPAM, "%s Instructions - ALL (ARB): MAX=%d USED=%d", **header, ins_max, ins_num);
00800 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, nins_max, nins_num);
00801 err_mesg(ERR_LEV_SPAM, "%s Instructions - ALU (ARB): MAX=%d USED=%d", **header, ains_max, ains_num);
00802 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, nains_max, nains_num);
00803 err_mesg(ERR_LEV_SPAM, "%s Instructions - TEX (ARB): MAX=%d USED=%d", **header, tins_max, tins_num);
00804 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, ntins_max, ntins_num);
00805 err_mesg(ERR_LEV_SPAM, "%s Tex Indirections (ARB): MAX=%d USED=%d", **header, txns_max, txns_num);
00806 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, ntxns_max, ntxns_num);
00807 err_mesg(ERR_LEV_SPAM, "%s Temporaries (ARB): MAX=%d USED=%d", **header, tmp_max, tmp_num);
00808 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, ntmp_max, tmp_num);
00809 err_mesg(ERR_LEV_SPAM, "%s Parameters (ARB): MAX=%d USED=%d", **header, par_max, par_num);
00810 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, npar_max, npar_num);
00811 err_mesg(ERR_LEV_SPAM, "%s Attributes (ARB): MAX=%d USED=%d", **header, att_max, att_num);
00812 err_mesg(ERR_LEV_SPAM, "%s (NATIVE): MAX=%d USED=%d", **header, natt_max, natt_num);
00813 err_mesg(ERR_LEV_SPAM, "%s...done.", **header);
00814 #endif
00815 }
00816 return success;
00817 }