Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sgl.h

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sgl.h
00021  *  Project: 26 June 1997
00022  *  Summary: Top level include file with miscellaneous constants and macros,
00023  *         : and various hacks needed for cross platform compatibility.
00024  *****************************************************************************/
00025 
00026 #ifndef __SGL_H
00027 #define __SGL_H
00028 
00029 #define SGL_MAJOR_VERSION 1
00030 #define SGL_MINOR_VERSION 0
00031 
00032 #if defined(WIN32) && defined(_DLL)
00033 // The next define will come from the makefile for archive objects.
00034 # ifdef sgl_DLL_FILE
00035 #  define SGL_DLL_API __declspec(dllexport)
00036 # else
00037 #  define SGL_DLL_API __declspec(dllimport)
00038 # endif
00039 #else
00040 # define SGL_DLL_API
00041 #endif
00042 
00043 // the following encapsulates a bunch of hacks to get around cross platform
00044 // issues when Windoze is involved.
00045 #include <sgl_windows.h>
00046 
00047 // a bunch of hacks to select standard conforming iostream stuff if available
00048 // on the platform
00049 
00050 #if defined(WIN32) || (defined(sgi) && defined(_STANDARD_C_PLUS_PLUS)) || (defined(__GNUC__) && (((__GNUC__==2) && (__GNUC_MINOR__>=91)) || __GNUC__>2))
00051 # include <iostream>
00052 # include <iomanip>
00053 # include <fstream>
00054 #else
00055 # include <iostream.h>
00056 # include <iomanip.h>
00057 # include <fstream.h>
00058 #endif
00059 
00060 #ifndef __gl_h_
00061 # include <GL/gl.h>
00062 #endif
00063 
00064 
00065 #include <stdlib.h>
00066 #include <math.h>
00067 #include <float.h>  // for {FLT,DBL}_{MIN,MAX}
00068 #include <assert.h>
00069 #include <string.h>
00070 
00071 #include <vector>
00072 
00073 #if 0
00074 // use for testing traversal speed by not really drawing geometry
00075 # define SGL_NO_VERTEX_ARRAYS
00076 # define glVertex3fv glColor3fv
00077 #endif
00078 
00079 #ifndef TRUE
00080 # define TRUE 1
00081 #endif
00082 
00083 #ifndef FALSE
00084 # define FALSE 0
00085 #endif
00086 
00087 #ifndef NULL
00088 # define NULL (void *)0
00089 #endif
00090 
00091 // ANSI value; 1E-7 should be fine too
00092 const float sglFltEpsilon = (float) 1.0e-7;
00093 
00094 // ANSI value, &1E-16 should be fine
00095 const double sglDblEpsilon = 1.0e-16;
00096 
00097 #ifndef M_PI
00098 # define M_PI 3.14159265358979323846
00099 #endif
00100 
00101 #ifndef M_PI_2
00102 # define M_PI_2 1.57079632679489661923
00103 #endif
00104 
00105 #ifndef M_PI_4
00106 # define M_PI_4 0.78539816339744830962
00107 #endif
00108 
00109 const double cTanPi8 = tan(M_PI/8.0);
00110 
00111 #ifndef M_LOG2E
00112 # define M_LOG2E 1.4426950408889634074
00113 #endif
00114 
00115 template <class T>
00116 inline T SGL_ABS(T a)
00117 {
00118    return (a >= 0 ? a : -a);
00119 }
00120 
00121 template <class T>
00122 inline T SGL_MIN(T a, T b)
00123 {
00124    return (a < b ? a : b);
00125 }
00126 
00127 template <class T>
00128 inline T SGL_MAX(T a, T b)
00129 {
00130    return (a > b ? a : b);
00131 }
00132 
00133 inline bool sglAlmostEqual(float a, float b)
00134 {
00135    return SGL_ABS((a)-(b)) < sglFltEpsilon;
00136 }
00137 
00138 inline bool sglAlmostEqual(double a, double b)
00139 {
00140    return SGL_ABS((a)-(b)) < sglDblEpsilon;
00141 }
00142 
00143 template <class T>
00144 inline T sglRelativeError(T a, T b)
00145 {
00146    return SGL_ABS(a-b)/SGL_MAX(SGL_ABS(a), SGL_ABS(b));
00147 }
00148 
00149 inline bool sglRelativelyEqual(
00150    float a, float b, float relative_error = 1.0e-6)
00151 {
00152    return sglRelativeError(a, b) < relative_error;
00153 }
00154 
00155 inline bool sglRelativelyEqual(
00156    double a, double b, double relative_error = 1.0e-14)
00157 {
00158    return sglRelativeError(a, b) < relative_error;
00159 }
00160 
00161 template <class T, class S>
00162 inline bool SGL_ALMOST_EQUAL(T a, S b, double eps)
00163 {
00164    return SGL_ABS(a-b) < eps;
00165 }
00166 
00167 #ifndef SGL_SWAP
00168 # define SGL_SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
00169 #endif
00170 
00171 
00172 // Use the std namespace. To do this we must first guarantee that it exists.
00173 #if defined(__sgi) || defined(__WIN32_) || defined(WIN32) || (defined(__GNUC__) && __GNUC__>2)
00174 namespace std {}
00175 using namespace std;
00176 #endif
00177 
00178 
00179 class sglLock;
00180 
00181 
00198 class SGL_DLL_API sgl
00199 {
00200 public:
00206    static void initialize(ostream* default_stream = &cout);
00207 
00208 
00214    static GLuint getDisplayList();
00215 
00219    static void releaseDisplayList(GLuint dlist);
00220 
00226    static void deleteUnusedDisplayLists();
00227 
00233    static GLuint getTextureObj();
00234 
00238    static void releaseTextureObj(GLuint tex_obj);
00239 
00245    static void deleteUnusedTextureObjs();
00246 
00251    static unsigned int nextPower2(unsigned int val);
00252 
00259    static void *getDLLHandle(const char *dll_name);
00260 
00266    static void *getFuncPtr(void *dll, const char *func_name);
00267 
00272    static void *getGLFuncPtr(const char *func_name);
00273 
00274 protected:
00276    sgl();
00278    ~sgl();
00279 
00280 private:
00282    sgl(const sgl &);
00284    sgl &operator=(const sgl &);
00285 
00286 public:
00287    static bool            s_initialized;
00288 
00289    static GLint           s_max_prefetch_indices;
00290    static GLint           s_max_prefetch_vertices;
00291    static void (APIENTRY *drawRangeElements)(GLenum, GLuint, GLuint,
00292                                              GLsizei, GLenum, const GLvoid *);
00293 
00294    static GLint           s_max_texture_size;
00295    static GLint           s_clamp_to_edge;
00296    static GLenum          s_rescale_normal;
00297    static float           s_max_texture_max_anisotropy;
00298    static GLint           s_num_texture_units;
00299 
00300    static void (APIENTRY *setActiveTextureUnit)(GLenum);
00301    static void (APIENTRY *setClientActiveTextureUnit)(GLenum);
00302    typedef void (APIENTRY *multiTexCoordFunc)(GLenum, const GLfloat*);
00303    static multiTexCoordFunc getMultiTexFunc(const char *type);
00304    static multiTexCoordFunc multiTexCoord1sv;
00305    static multiTexCoordFunc multiTexCoord2sv;
00306    static multiTexCoordFunc multiTexCoord3sv;
00307    static multiTexCoordFunc multiTexCoord4sv;
00308    static multiTexCoordFunc multiTexCoord1iv;
00309    static multiTexCoordFunc multiTexCoord2iv;
00310    static multiTexCoordFunc multiTexCoord3iv;
00311    static multiTexCoordFunc multiTexCoord4iv;
00312    static multiTexCoordFunc multiTexCoord1fv;
00313    static multiTexCoordFunc multiTexCoord2fv;
00314    static multiTexCoordFunc multiTexCoord3fv;
00315    static multiTexCoordFunc multiTexCoord4fv;
00316    static multiTexCoordFunc multiTexCoord1dv;
00317    static multiTexCoordFunc multiTexCoord2dv;
00318    static multiTexCoordFunc multiTexCoord3dv;
00319    static multiTexCoordFunc multiTexCoord4dv;
00320 
00321    static unsigned int    s_num_statelet_types;
00322 
00323    static GLenum          s_stencil_inc_wrap;
00324    static GLenum          s_stencil_dec_wrap;
00325    static GLint           s_num_stencil_bits;
00326 
00327    static bool            s_multisample_capable;
00328 
00329    static bool            s_texture_env_add_capable;
00330    static bool            s_texture_env_combine_capable;
00331    static bool            s_texture_env_dot3_capable;
00332 
00333    static bool            s_occlusion_capable;
00334    static GLenum          s_occlusion_enable_flag;
00335    static GLenum          s_occlusion_result_flag;
00336 
00337    // texture compression
00338    enum CompressionVendor
00339    {
00340       eCOMPRESSION_VENDOR_ARB,
00341       eCOMPRESSION_VENDOR_S3
00342    };
00343    static bool            s_texture_compression_capable;
00344    static CompressionVendor s_texture_compression_vendor;
00345    static void (APIENTRY *compressedTexImage2D)(
00346       GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *);
00347    static void (APIENTRY *getCompressedTexImage)(GLenum, GLint, GLvoid *);
00348 
00349    // auto-generate mipmap
00350    static bool            s_auto_mipmap_capable;
00351    static GLenum          s_auto_mipmap_enable_flag;
00352 
00353    // texture LOD bias
00354    static bool            s_texture_lod_bias_capable;
00355    static float           s_max_texture_lod_bias;
00356 
00357    // individual texture LOD
00358    static bool            s_texture_lod_capable;
00359 
00360    // fog distance equation support
00361    static bool            s_fog_distance_capable;
00362 
00363    // point parameters extension
00364    static bool            s_point_parameters_capable;
00365    static float           s_point_default_size_min;
00366    static float           s_point_default_size_max;
00367    static float           s_point_default_fade_threshold;
00368    static void (APIENTRY *pointParameterf)( GLenum, GLfloat );
00369    static void (APIENTRY *pointParameterfv)( GLenum, GLfloat * );
00370 
00371    // cube map extension
00372    static bool            s_texture_cube_map_capable;
00373    static GLint           s_max_cube_map_texture_size;
00374 
00375    // number of lights supported by OGL
00376    static GLint           s_max_lights;
00377 
00378 private:
00379    static vector<GLuint>  s_unused_display_lists;
00380    static sglLock        *s_dlist_lock;
00381 
00382    static vector<GLuint>  s_unused_texture_objs;
00383    static sglLock        *s_tex_lock;
00384 };
00385 
00386 
00387 #if (defined(MESA_MAJOR_VERSION) && ((MESA_MAJOR_VERSION<3) || ((MESA_MAJOR_VERSION==3) && (MESA_MINOR_VERSION<1))))
00388 # define SGL_NO_VERTEX_ARRAYS
00389 #endif
00390 
00391 #if !defined(WIN32) && !(defined(__GNUC__) && (((__GNUC__==2) && (__GNUC_MINOR__ <= 8)) || (__GNUC__<2)))
00392 # define TEMPLATE_OSTREAM_HACK
00393 #endif
00394 
00395 
00396 #ifndef GL_TEXTURE_COMPRESSION_HINT_ARB
00397 #define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84ef
00398 #endif
00399 
00400 #ifndef GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB
00401 #define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86a0
00402 #endif
00403 
00404 #ifndef GL_TEXTURE_COMPRESSED_ARB
00405 #define GL_TEXTURE_COMPRESSED_ARB 0x86a1
00406 #endif
00407 
00408 #ifndef GL_TEXTURE_FILTER_CONTROL_EXT
00409 #define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500
00410 #endif
00411 
00412 #ifndef GL_TEXTURE_LOD_BIAS_EXT
00413 #define GL_TEXTURE_LOD_BIAS_EXT 0x8501
00414 #endif
00415 
00416 #ifndef GL_MAX_TEXTURE_LOD_BIAS_EXT
00417 #define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84fd
00418 #endif
00419 
00420 #ifndef GL_TEXTURE_MIN_LOD_SGIS
00421 #define GL_TEXTURE_MIN_LOD_SGIS 0x813a
00422 #endif
00423 
00424 #ifndef GL_TEXTURE_MAX_LOD_SGIS
00425 #define GL_TEXTURE_MAX_LOD_SGIS 0x813b
00426 #endif
00427 
00428 #ifndef GL_TEXTURE_BASE_LEVEL_SGIS
00429 #define GL_TEXTURE_BASE_LEVEL_SGIS 0x813c
00430 #endif
00431 
00432 #ifndef GL_TEXTURE_MAX_LEVEL_SGIS
00433 #define GL_TEXTURE_MAX_LEVEL_SGIS 0x813d
00434 #endif
00435 
00436 // cube map tokens GL_ARB_texture_cube_map extension
00437 #ifndef GL_NORMAL_MAP_ARB
00438 #define GL_NORMAL_MAP_ARB 0x8511
00439 #endif
00440 
00441 #ifndef GL_REFLECTION_MAP_ARB
00442 #define GL_REFLECTION_MAP_ARB 0x8512
00443 #endif
00444 
00445 #ifndef GL_TEXTURE_CUBE_MAP_ARB
00446 #define GL_TEXTURE_CUBE_MAP_ARB 0x8513
00447 #endif
00448 
00449 #ifndef GL_TEXTURE_BINDING_CUBE_MAP_ARB
00450 #define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514
00451 #endif
00452 
00453 #ifndef GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
00454 #define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515
00455 #endif
00456 
00457 #ifndef GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
00458 #define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516
00459 #endif
00460 
00461 #ifndef GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
00462 #define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517
00463 #endif
00464 
00465 #ifndef GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
00466 #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518
00467 #endif
00468 
00469 #ifndef GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
00470 #define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519
00471 #endif
00472 
00473 #ifndef GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
00474 #define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851a
00475 #endif
00476 
00477 #ifndef GL_PROXY_TEXTURE_CUBE_MAP_ARB
00478 #define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851b
00479 #endif
00480 
00481 #ifndef GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
00482 #define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851c
00483 #endif
00484 
00485 // fog function tokens
00486 #ifndef GL_FOG_DISTANCE_MODE_NV
00487 #define GL_FOG_DISTANCE_MODE_NV 0x855a
00488 #endif
00489 
00490 #ifndef GL_EYE_RADIAL_NV
00491 #define GL_EYE_RADIAL_NV 0x855b
00492 #endif
00493 
00494 #ifndef GL_EYE_PLANE_ABSOLUTE_NV
00495 #define GL_EYE_PLANE_ABSOLUTE_NV 0x855c
00496 #endif
00497 
00498 #ifndef GL_POINT_SIZE_MIN_EXT
00499 #define GL_POINT_SIZE_MIN_EXT 0x8126
00500 #endif
00501 
00502 #ifndef GL_POINT_SIZE_MAX_EXT
00503 #define GL_POINT_SIZE_MAX_EXT 0x8127
00504 #endif
00505 
00506 #ifndef GL_POINT_FADE_THRESHOLD_SIZE_EXT
00507 #define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128
00508 #endif
00509 
00510 #ifndef GL_DISTANCE_ATTENUATION_EXT
00511 #define GL_DISTANCE_ATTENUATION_EXT 0x8129
00512 #endif
00513 
00514 #ifndef GL_TEXTURE0
00515 #define GL_TEXTURE0 0x84C0
00516 #endif
00517 
00518 #ifndef GL_COMBINE
00519 #define GL_COMBINE 0x8570
00520 #endif
00521 
00522 #ifndef GL_COMBINE_RGB
00523 #define GL_COMBINE_RGB 0x8571
00524 #endif
00525 
00526 #ifndef GL_COMBINE_ALPHA
00527 #define GL_COMBINE_ALPHA 0x8572
00528 #endif
00529 
00530 #ifndef GL_SOURCE0_RGB
00531 #define GL_SOURCE0_RGB 0x8580
00532 #endif
00533 
00534 #ifndef GL_SOURCE0_ALPHA
00535 #define GL_SOURCE0_ALPHA 0x8588
00536 #endif
00537 
00538 #ifndef GL_OPERAND0_RGB
00539 #define GL_OPERAND0_RGB 0x8590
00540 #endif
00541 
00542 #ifndef GL_OPERAND0_ALPHA
00543 #define GL_OPERAND0_ALPHA 0x8598
00544 #endif
00545 
00546 #ifndef GL_RGB_SCALE
00547 #define GL_RGB_SCALE 0x8573
00548 #endif
00549 
00550 #ifndef GL_ADD_SIGNED
00551 #define GL_ADD_SIGNED 0x8574
00552 #endif
00553 
00554 #ifndef GL_INTERPOLATE
00555 #define GL_INTERPOLATE 0x8575
00556 #endif
00557 
00558 #ifndef GL_SUBTRACT
00559 #define GL_SUBTRACT 0x84E7
00560 #endif
00561 
00562 #ifndef GL_CONSTANT
00563 #define GL_CONSTANT 0x8576
00564 #endif
00565 
00566 #ifndef GL_PRIMARY_COLOR
00567 #define GL_PRIMARY_COLOR 0x8577
00568 #endif
00569 
00570 #ifndef GL_PREVIOUS
00571 #define GL_PREVIOUS 0x8578
00572 #endif
00573 
00574 #ifndef GL_DOT3_RGB
00575 #define GL_DOT3_RGB 0x86AE
00576 #endif
00577 
00578 #ifndef GL_DOT3_RGBA
00579 #define GL_DOT3_RGBA 0x86AF
00580 #endif
00581 
00582 
00583 #endif

Generated at Mon Jul 1 18:00:04 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001