HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>


ogl.h

00001 /*
00002  * Copyright (c) 1998 by Tech Soft 3D, LLC.
00003  * The information contained herein is confidential and proprietary to
00004  * Tech Soft 3D, LLC., and considered a trade secret as defined under
00005  * civil and criminal statutes.  Tech Soft 3D shall pursue its civil
00006  * and criminal remedies in the event of unauthorized use or misappropriation
00007  * of its trade secrets.  Use of this information by anyone other than
00008  * authorized employees of Tech Soft 3D, LLC. is granted only under a
00009  * written non-disclosure agreement, expressly prescribing the scope and
00010  * manner of such use.
00011  *
00012  * $Id: ogl_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $
00013  */
00014 
00015 
00016 
00017 #ifndef OGL_H_DEFINED
00018 #define OGL_H_DEFINED
00019 
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 
00024 #include "database.h"
00025 #include "driver.h"
00026 #include "hpserror.h"
00027 #include "patterns.h"
00028 #include "phedron.h"
00029 #include "please.h"
00030 #include "searchh.h"
00031 #include "tandt.h"
00032 #include "hversion.h"
00033 #include "adt.h"
00034 
00035 
00036 #ifdef GLX_DRIVER
00037 # include <GL/glx.h>
00038 # include "x11data.h"
00039 
00040 # ifdef LINUX_SYSTEM
00041 #   define caddr_t char*
00042 #   ifndef __cplusplus
00043       typedef struct GLUquadric GLUquadric;
00044 #   endif
00045 # endif
00046 # ifdef IRIX_SYSTEM
00047 #   undef   SGI_TIMINGx 
00048 #   undef   DEBUGx  
00049 # endif
00050 # if defined(NUTCRACKER)
00051 /* for machine missing pbuffers */
00052       typedef Window GLXPbuffer;
00053 #ifndef EXCEED_BUILD
00054       typedef void *GLXFBConfig;
00055 #endif
00056 #define glXChooseFBConfig(x1,x2,x3,x4) null
00057 #define glXGetVisualFromFBConfig(x1,x2) null
00058 #define glXCreatePbuffer(x1,x2,x3) null 
00059 #endif
00060 # define MAX_SOLARIS_OVERLAY_COLORS 256
00061 # define SOLARIS_RESERVED_COLORS 65
00062 #endif
00063 
00064 #ifdef WGL_DRIVER
00065 #   ifndef WIN32_LEAN_AND_MEAN
00066 #       define WIN32_LEAN_AND_MEAN
00067 #   endif
00068 # include <windows.h>
00069 # include "msw.h"
00070 #endif
00071 
00072 #ifdef OSX_SYSTEM
00073 # undef local
00074 # undef OS_INLINE
00075 # define OS_INLINE static __inline__ /* workaround for a problem in agl headers */
00076 # include <AGL/agl.h>
00077 # undef local
00078 # define local static
00079 # include <OpenGL/gl.h>
00080 # include <OpenGL/glu.h>
00081 # include <Carbon/Carbon.h>
00082 #else
00083 # include <GL/gl.h>
00084 # include <GL/glu.h>
00085 #endif
00086 
00087 #ifndef AGLM
00088 # define AGLM(x)
00089 #endif
00090 
00091 
00092 
00093 /* Debug_NO_TWO_SIDED_LIGHTING is a way of indicating that it is okay for the 
00094  * back face of objects to appear dark, even if they are not culled away.  This
00095  * will improve performance significantly on some systems. */
00096 #define Debug_NO_TWO_SIDED_LIGHTING 0x00000001
00097 #define DEBUG_GLX_INDIRECT          0x00000002
00098 #define Debug_OSX_UNDERLAY          0x00000004
00099 #define Debug_PUNT_BIG_TEXTURE      0x00000008
00100 #define DEBUG_MARKER_SIZE_CLAMP_TO_HW_MAX 0x00000010
00101 #define DEBUG_MARKER_POINTSMOOTH_CIRCLES  0x00000020
00102 /* Debug_NO_WINDOWS_HOOK is provided so that users can tell us not to hook into
00103  * the message queue for a window - this means that the user must process
00104  * ALL messages and call HC_Update_Display when they want hoops to draw
00105  * into the provided window is unused on unix*/
00106 #define Debug_NO_WINDOWS_HOOK       0x00000040
00107 #define Debug_USE_QGL_CONTEXT       0x00000080
00108 #define Debug_WGL_NO_SHARELISTS     0x00000100
00109 #define Debug_QMOVES_NO_ZDAMAGE     0x00000200
00110 #define Debug_ENVIRONMENT_MAP_FORCE_MULTIPASS 0x00000400
00111 #define Debug_UNUSED12              0x00000800
00112 #define DEBUG_MITRE_TO_DEFAULT      0x00001000
00113 /*default clear is white*/
00114 #define DEBUG_STARTUP_NO_CLEAR      0x00002000
00115 #define DEBUG_STARTUP_CLEAR_BLACK   0x00004000
00116 #define DEBUG_FORCE_XOR_OVERLAY     0x00008000
00117 #define DEBUG_NO_VERTEX_ARRAYS      0x00010000
00118 #define Debug_FLUSH_INTERVAL        0x00020000
00119 #define Debug_UNUSED19              0x00040000
00120 #define Debug_UNUSED20              0x00080000
00121 #define Debug_USE_WINDOW_IS_IMAGE   0x00100000
00122 #define Debug_16BIT_ZBUFFER         0x00200000
00123 #define Debug_HLR_ACTIVE            0x00400000
00124 #define Debug_NO_OGL_OVERLAY_PLANES 0x00800000
00125 #define Debug_FORCE_SOFTWARE        0x01000000
00126 #define DEBUG_FORCE_REAL_OVERLAY    0x02000000
00127 #define DEBUG_DISABLE_OCTANE2_HACK  0x04000000
00128 #define DEBUG_OGL_STUB              0x08000000
00129 
00130 /* #define PRINT_ACTIONS */
00131 #ifdef PRINT_ACTIONS
00132 #  define ACTION_NAME(action_name, is_draw) \
00133     OutputDebugString (action_name); \
00134     OutputDebugString ("\n"); 
00135 #else
00136 #  define ACTION_NAME(action_name, is_draw) \
00137     if (is_draw && BIT(ogldata->dc->options.debug, DEBUG_OGL_STUB)) \
00138         return;
00139 #endif
00140 
00141 
00142 /* XBIT STUFF */
00143 
00144 #define XBIT_NONE                           0L
00145 #define XBIT_UNDRAW_OVERLAY_FRONT_AND_BACK  1L
00146 #define XBIT_BAD_KTX                        2L
00147 #define XBIT_DOUBLE_BUFFER_SWAP_ONLY        3L
00148 #define XBIT_BAD_VERTEX_ARRAYS              4L
00149 #define XBIT_BAD_SCISSORING                 5L
00150 #define XBIT_EYE_SPACE_DEPTH                6L
00151 #define XBIT_FORCE_DEFAULT_SOFTWARE         7L
00152 #define XBIT_BAD_OVERLAY                    8L
00153 #define XBIT_BAD_STENCIL                    9L
00154 #define XBIT_BAD_TRANSPARENT_POINT          10L
00155 #define XBIT_RESTORE_REGION_ZBUFFER_OFF     11L
00156 #define XBIT_BAD_MULTILIGHT                 12L
00157 #define XBIT_BAD_DISPLAY_LIST               13L
00158 #define XBIT_FORCE_OLD_CHOOSE_PIXEL_FORMAT  14L
00159 #define XBIT_BAD_PIXEL_STORE                15L
00160 #define XBIT_RASTERS_AS_VERTICES            16L
00161 #define XBIT_ALLOW_DRAWPIXEL_RESTORE        17L
00162 #define XBIT_DOUBLE_BUFFER_COPY_ONLY        18L
00163 #define XBIT_LIES_ABOUT_SWAP                19L
00164 #define XBIT_PIXEL_OPERATIONS_EXPENSIVE     20L /* currently used only in direct-to-ogl HStencilProbe from mvo */
00165 #define XBIT_BAD_PHONG                      21L
00166 #define XBIT_BAD_PATTERNED_LINES            22L
00167 #define XBIT_BAD_PBUFFER                    23L
00168 #define XBIT_BAD_SPOTLIGHT_TEXTURE          24L
00169 #define XBIT_4142_WORKAROUND                25L
00170 #define XBIT_BAD_TWO_SIDED_LIGHTING         26L
00171 #define XBIT_BAD_FLAT_VERTEX_ARRAYS         27L
00172 #define XBIT_BAD_WGL_ARB_BUFFER             28L
00173 #define XBIT_BAD_MSAA_WGL_ARB_BUFFER        29L
00174 #define XBIT_WGL_ARB_BUFFER_1024_LIMIT      30L
00175 #define XBIT_FLAT_TRISTRIP_MISMATCH         31L
00176 #define XBIT_BAD_NONDL_VERTEX_ARRAYS        32L
00177 #define XBIT_BAD_SINGLE_BUFFERING           33L
00178 #define XBIT_BAD_ACCUMULATION_BUFFER        34L
00179 #define XBIT_BAD_16BIT_ACCUMULATION_BUFFER  35L
00180 #define XBIT_LINE_PATTERN_NEEDS_BLENDING    36L
00181 #define XBIT_SLOW_MSAA_DEPTH_TEXTURE        37L
00182 #define XBIT_BAD_MSAA_ACCUMULATION_BUFFER   38L
00183 #define XBIT_BAD_VERTEX_BUFFER_OBJECT       39L
00184 
00185 /* local typedefs: */
00186 
00187 typedef struct {
00188     GLint factor;
00189     GLushort pattern;
00190 }
00191 OGLlpattern;
00192 
00193 
00194 #define OGL_MAX_PASSES 64
00195 typedef int OGL_Render_Pass;
00196 #define RC_PASS_DIFFUSE                     (OGL_Render_Pass)(0x0001)
00197 #define RC_PASS_DIFFUSE_FRONT               (OGL_Render_Pass)(0x0002)
00198 #define RC_PASS_DIFFUSE_BACK                (OGL_Render_Pass)(0x0004)
00199 #define RC_PASS_DIFFUSE_TEXTURE             (OGL_Render_Pass)(0x0008)
00200 #define RC_PASS_DIFFUSE_MULTITEXTURE        (OGL_Render_Pass)(0x0010)
00201 #define RC_PASS_SPECULAR_TEXTURE            (OGL_Render_Pass)(0x0020)
00202 #define RC_PASS_ENVIRONMENT_TEXTURE         (OGL_Render_Pass)(0x0040)
00203 #define RC_PASS_SPOT_LIGHT_TEXTURE          (OGL_Render_Pass)(0x0080)
00204 #define RC_PASS_BUMP_TEXTURE                (OGL_Render_Pass)(0x0100)
00205 #define RC_PASS_IMAGE                       (OGL_Render_Pass)(0x0200)
00206 #define RC_PASS_INDEXED                     (OGL_Render_Pass)(0x0400)
00207                                                              
00208 typedef int OGL_Render_Control_Flags;                        
00209 #define RCF_PARAMETER_FIXUP         (OGL_Render_Control_Flags)(0x0001) 
00210 #define RCF_TEXTURE_MODULATES_LIGHT (OGL_Render_Control_Flags)(0x0002) 
00211 #define RCF_SYNTHETIC_PARAMS        (OGL_Render_Control_Flags)(0x0004) 
00212 #define RCF_IGNORE_TRANSFORM        (OGL_Render_Control_Flags)(0x0008) 
00213 #define RCF_GEN_WORLD_PARAMS        (OGL_Render_Control_Flags)(0x0010)
00214 #define RCF_GEN_ENVIRONMENT_PARAMS  (OGL_Render_Control_Flags)(0x0020) 
00215 #define RCF_FRONT_PASS              (OGL_Render_Control_Flags)(0x0040) 
00216 #define RCF_BACK_PASS               (OGL_Render_Control_Flags)(0x0080) 
00217 #define RCF_STATUS_PARAMS           (OGL_Render_Control_Flags)(0x0100) 
00218 #define RCF_BUMPMAP                 (OGL_Render_Control_Flags)(0x0200) 
00219 #define RCF_FAKE_TWO_SIDED_LIGHTING (OGL_Render_Control_Flags)(0x0400) 
00220 #define RCF_SUPPRESS_SPECULAR       (OGL_Render_Control_Flags)(0x0800) 
00221 
00222 
00223 typedef struct {
00224     HT_Point *vTangent;
00225     HT_Point *vBiNormal;
00226     HT_Point *vNormal;
00227     HT_Point *vTangentVertices;
00228     int length;
00229 } Bumpmap_data;
00230 
00231 
00232 typedef struct {
00233     unsigned int n;
00234     unsigned int pass;
00235     unsigned int passes;
00236     GLuint id[OGL_MAX_PASSES];
00237     
00238     HT_Texture *txr[OGL_MAX_PASSES];
00239     OGL_Render_Pass usage[OGL_MAX_PASSES];
00240     HT_RGB material_color[OGL_MAX_PASSES];
00241     HT_RGB specular_material_color[OGL_MAX_PASSES];
00242     int param_offset[OGL_MAX_PASSES];
00243     HT_Parameter const *params[OGL_MAX_PASSES];
00244     HT_Integer32 param_width[OGL_MAX_PASSES];    
00245     int flags[OGL_MAX_PASSES];
00246     int param_count[OGL_MAX_PASSES];
00247     HT_Light_Instance const *light[OGL_MAX_PASSES];
00248     int multipass[OGL_MAX_PASSES];
00249     Bumpmap_data  bm_parameters;
00250 } OGL_Render_Control;
00251 
00252 #if 0
00253 /* use get_display_list in ogl.c instead. */
00254 #define GET_DISPLAY_LIST(nr, _ogldata, source, dl, odl, list_type, list_new) SEMI_PROTECT(\
00255     (list_new) = HI_Get_Display_List((nr)->display_context->actor, &source, &dl); \
00256     if (!(dl)->list) { \
00257         ZALLOC((odl), OGL_Display_List); \
00258         (dl)->list = (void*)(odl); \
00259         (odl)->type = list_type; \
00260         (odl)->peer = (dl); \
00261         (odl)->next = (_ogldata)->cache.display_lists; \
00262         (odl)->prev = &((_ogldata)->cache.display_lists); \
00263         if ((_ogldata)->cache.display_lists) \
00264             (_ogldata)->cache.display_lists->prev= &(odl)->next; \
00265         (_ogldata)->cache.display_lists = (odl); \
00266         (list_new)=true; \
00267     } \
00268     (odl) = (OGL_Display_List*)(dl)->list; \
00269     if (odl) (odl)->ogldata = (_ogldata); \
00270 )
00271 #endif
00272 
00273 #define OGL_VBO_ARRAYS              0x0002 
00274 #define OGL_VBO_STRIP_ARRAYS        0x0004
00275 
00276 struct OGL_Vertex_Buffer_Object{
00277     HT_Bounding const *bounding_buffer;  /* non-null iff boundings need xform */
00278     HT_Bounding const **boundings;
00279     int         count;          /* number of ts's pe's or pm's */
00280     int         point_count;
00281 
00282     GLuint      points_vbo;
00283     GLuint      normals_vbo;
00284     GLuint      params_vbo;
00285     GLuint      colors_vbo;
00286     int         param_width;
00287 
00288     int         position_offset;
00289     int         normals_offset;
00290     int         params_offset;
00291     int         colors_offset;
00292     int         stride;
00293     int         index_size;
00294 
00295     GLuint      vi_vbo_long;   /* strips */
00296     int         *vi_offsets_long;
00297     int         *lengths_long;
00298     int         strips_long;
00299     int         total_long;
00300 
00301     GLuint      vi_vbo_short;  /* triangles or lines */
00302     int         total_short;
00303     int         *vi_offsets_short;
00304 
00305     int         flags;
00306 };
00307 
00308 struct OGLData; //forward
00309 
00310 #define OGL_DL_NONE                 0
00311 #define OGL_DL_TEXTURE              1
00312 #define OGL_DL_GEOMETRY             2
00313 #define OGL_DL_GEOMETRY_VBO         3
00314 #define OGL_DL_SEGMENT_POLYLINE     4
00315 #define OGL_DL_SEGMENT_TREE         5
00316 #define OGL_DL_SHADOW_MAP           6
00317 
00318 #define OGL_DL_BLESSED_GEOMETRY 0x0001
00319 #define OGL_DL_BLESSED_SEGMENT  0x0002
00320 #define OGL_DL_SINGLE_INSTANCED 0x0004 /* indicates that gdl's can be promoted to segdl's for free */
00321 
00322 #define FLUSH_INTERVAL 100
00323 
00324 struct OGL_Display_List {
00325     HT_Display_List *peer; /* must be first */
00326     OGL_Display_List *next;
00327     OGL_Display_List **prev;
00328     OGLData *ogldata;
00329     unsigned int type;
00330     int vram_usage;     /* approximate amount of memory this object consumes */
00331 
00332     union {
00333         struct {
00334             HT_Image const *image;
00335             GLuint id;
00336             GLuint *env_ids;
00337         } texture;
00338         struct {
00339             /* the following member can represent either a GLuint or a 
00340                OGL_Vertex_Buffer_Object *, depending on the type */
00341             POINTER_SIZED_INT id;
00342             HT_Integer32 param_width;
00343             HT_Integer32 param_flags;
00344             unsigned int rendo_flags;
00345             unsigned int special_flags;
00346             struct {
00347                 int total;
00348                 int strips;
00349                 int point_count;
00350             }   stats;
00351         } geometry;
00352         struct {
00353             POINTER_SIZED_INT   id;
00354             int                 resolution;
00355             float               transform[16];
00356             //bool projectionsValid;
00357             //float lightProjection[16];
00358             //float lightModelview[16];
00359             //float lightEyeDistance;
00360             //HT_Key depthImageKey;
00361         }   shadow_map;
00362         struct {
00363             HT_Polyedge *pe;
00364             int budget;
00365             int continued_budget;
00366             float max_deviation;
00367             float max_angle;
00368             float max_length;
00369         } polyline;
00370         struct {
00371             HT_VList *tristrips_list; /* ogl_display_list */
00372             HT_VList *polyedges_list; /* ogl_display_list */
00373             HT_VList *polylines_list; /* ogl_display_list */
00374             HT_Type_Flags visibility;
00375             HT_Rendo_Flags interpolation_options;
00376             unsigned int blessed; /* tracks permission to compile for real */
00377         } segment_tree;
00378 
00379     } item;
00380 };
00381 
00382 
00383 
00384 /* Display list "bin packing" */
00385 typedef struct {
00386     unsigned int id;
00387     HT_Net_Rendition const *nr;
00388     int flags;                      /* any special flags */
00389     int point_count;                /* keep track of the current size, so we know if it's getting too big */
00390     int extra_data;                 /* any extra useful data (such as face count) */
00391     HT_VList *geo_list;             /* list of geometry */
00392     OGL_Display_List *segdl;        /* output; the resulting display list */
00393 } OGL_Display_List_Bin;
00394 
00395 
00396 /* A geometry / matrix pair */
00397 typedef struct {
00398     void            *geo;
00399     HT_Matrix const *mat;
00400     HT_Net_Rendition *nr;
00401 } geo_mat_pair;
00402 
00403 
00404 typedef struct {
00405     HT_Display_List const *dl;
00406     float priority;
00407     int vram;
00408 } dlheapable;
00409 
00410 
00411 typedef struct {
00412     dlheapable          **dlarray;
00413     int                 allocated;
00414     int                 used;
00415 } dlheap;
00416 
00417 
00418 /* args are HT_Matrix, HT_Vector, HT_Point, HT_Vector alter */
00419 #define TRANSFORM_VERTEX_NORMAL(mat,nrm,pt,xnrm) SEMI_PROTECT(\
00420     float d = nrm.x*pt.x + nrm.y*pt.y + nrm.z*pt.z; \
00421     xnrm.x = nrm.x*mat->adjoint[0][0] + nrm.y*mat->adjoint[0][1] + nrm.z*mat->adjoint[0][2] + d*mat->adjoint[0][3]; \
00422     xnrm.y = nrm.x*mat->adjoint[1][0] + nrm.y*mat->adjoint[1][1] + nrm.z*mat->adjoint[1][2] + d*mat->adjoint[1][3]; \
00423     xnrm.z = nrm.x*mat->adjoint[2][0] + nrm.y*mat->adjoint[2][1] + nrm.z*mat->adjoint[2][2] + d*mat->adjoint[2][3]; \
00424     if (BIT (mat->contents, Matrix_Contents_SCALE)) \
00425         HI_Normalize ((HT_Vector *)&xnrm); \
00426 )
00427 
00428 #define TRANSFORM_EDGE_NORMAL(mat,nrm,pt,xnrm) TRANSFORM_VERTEX_NORMAL(mat,nrm,pt,xnrm)
00429 
00430 /* args are HT_Matrix, HT_Plane, HT_Plane alter 
00431  * assumes that mat->adjoint has been validated with HI_Validate_Matrix_Adjoint */
00432 #define TRANSFORM_FACE_NORMAL(mat,pln,xnrm) SEMI_PROTECT(\
00433     xnrm.a = pln.a*mat->adjoint[0][0] + pln.b*mat->adjoint[0][1] + pln.c*mat->adjoint[0][2] + pln.d*mat->adjoint[0][3]; \
00434     xnrm.b = pln.a*mat->adjoint[1][0] + pln.b*mat->adjoint[1][1] + pln.c*mat->adjoint[1][2] + pln.d*mat->adjoint[1][3]; \
00435     xnrm.c = pln.a*mat->adjoint[2][0] + pln.b*mat->adjoint[2][1] + pln.c*mat->adjoint[2][2] + pln.d*mat->adjoint[2][3]; \
00436     xnrm.d = pln.a*mat->adjoint[3][0] + pln.b*mat->adjoint[3][1] + pln.c*mat->adjoint[3][2] + pln.d*mat->adjoint[3][3]; \
00437     if (BIT (mat->contents, Matrix_Contents_SCALE)) \
00438         HI_Normalize_Plane ((HT_Plane *)&xnrm); \
00439 )
00440 /* args are HT_Matrix, HT_Point, HT_Point alter */
00441 #define TRANSFORM_POINT(mat,pt,xpt) SEMI_PROTECT(\
00442     float inv_w = 1.0f / TRANSW (mat->elements,pt); \
00443     xpt.x = TRANSX(mat->elements, pt) * inv_w; \
00444     xpt.y = TRANSY(mat->elements, pt) * inv_w; \
00445     xpt.z = TRANSZ(mat->elements, pt) * inv_w; \
00446 )
00447 #define TRANSFORMED_GLVERTEX(mat,pt) SEMI_PROTECT(\
00448     HT_Point _xpt; \
00449     TRANSFORM_POINT(mat,pt,_xpt); \
00450     glVertex3fv ((GLfloat *)&_xpt.x); \
00451 )
00452 
00453 #define TRANSFORMED_GLNORMAL_GLVERTEX(mat,flip,adjoint_z,nrm,pt) SEMI_PROTECT(\
00454     HT_Point _xpt; \
00455     HT_Vector _xnrm; \
00456     TRANSFORM_POINT(mat,pt,_xpt); \
00457     TRANSFORM_VERTEX_NORMAL (mat,nrm,pt,_xnrm);\
00458     NORMAL (flip,_xnrm, _xpt, adjoint_z);\
00459     glVertex3fv ((GLfloat *)&_xpt.x); \
00460 )
00461 
00462 typedef struct ogl_collector {
00463     struct ogl_collector *next;
00464     HT_Net_Rendition const *nr;
00465     HT_VList *list_tristrips;
00466     HT_VList *list_polyedges;
00467     HT_VList *list_polylines;   /* lines, curves and arcs*/
00468     unsigned HT_Integer32 mask, original_mask;  /* Action_Mask_* bits 1==handled, 0==not handled */
00469     bool punted_gref;
00470     bool gref_attributes;
00471     bool compile_only;
00472 } OGL_Collector;
00473 
00474 
00475 #ifdef WGL_DRIVER
00476 /* these are used by the REGION_ACTIONS */
00477 typedef void * HPBUFFERARB;
00478 #endif
00479 
00480 typedef enum {
00481     OGLR_INVALID = 0,
00482     OGLR_KTX_BUFFER_REGION = 1,
00483     OGLR_DEPTH_TEXTURE_RECT = 2,
00484     OGLR_DEPTH_TEXTURE_SQUARE = 3,
00485     OGLR_WGL_ARB_BUFFER = 4,
00486     OGLR_MAKE_CONTEXT_CURRENT = 5,
00487     OGLR_DRAW_PIXELS = 6
00488 } oglregion_type;
00489 
00490 typedef struct {
00491     /* used for vanilla read/draw pixels case */
00492     void *buffer;
00493     int size;
00494     oglregion_type type;
00495     HT_Int_Rectangle original_area;
00496     GLuint id;   
00497 #ifdef WGL_DRIVER
00498     /* used for arb buffer region case */
00499     HANDLE handle;
00500     HPBUFFERARB pbuffer;
00501     HDC hDC;
00502     HGLRC hGLRC;
00503 #endif
00504 } oglregion;
00505 
00506 
00507 #ifdef _DEBUG
00508 #   define DEBUG_FLUSH()    glFlush()
00509 #else
00510 #   define DEBUG_FLUSH()    (void)0
00511 #endif
00512 
00513 
00514 #ifdef GLX_DRIVER
00515 
00516 /* Structure format for SERVER_OVERLAY_VISUALS property. */
00517 typedef struct _XOverlayVisual {
00518     unsigned long overlay_visual;
00519     unsigned long transparent_type;
00520 #define OVERLAYS_None                   0x0
00521 #define OVERLAYS_TransparentPixel       0x1
00522 #define OVERLAYS_TransparentMask        0x2
00523     unsigned long value;
00524     unsigned long layer;
00525 }
00526 XOverlayVisual;
00527 
00528 #endif
00529 
00530 
00531 #ifdef WGL_DRIVER
00532 
00533 /****************************
00534 * Font handling data
00535 ****************************/
00536 
00537 typedef struct OGLFontData {
00538     float yscale;
00539     int fake_ysize;
00540     int real_ysize;
00541     int descent;
00542     int max_char_width;
00543 
00544 #define OGL_FONT_DATA_BUFFER_SIZE (1<<8)
00545 #define OGL_FONT_DATA_BUFFER_MASK (OGL_FONT_DATA_BUFFER_SIZE-1)
00546 
00547     HT_Stencil_Bitmap * stencil[OGL_FONT_DATA_BUFFER_SIZE];
00548 
00549     LOGFONT log_font;
00550     HFONT hFont;
00551 
00552     float xrrotation;
00553     HT_Stencil_Bitmap * rotated_stencil[OGL_FONT_DATA_BUFFER_SIZE];
00554     LOGFONT rotated_log_font;
00555     HFONT rotated_hFont;
00556 }
00557 OGLFontData;
00558 
00559 #endif
00560 
00561 typedef int DC_Type;
00562 #define DCT_UNDEFINED       ((DC_Type)0)
00563 #define DCT_OUR_WINDOW      ((DC_Type)1)
00564 #define DCT_THEIR_WINDOW    ((DC_Type)2)
00565 #define DCT_IMAGE           ((DC_Type)3)
00566 #define DCT_PBUFFER_IMAGE   ((DC_Type)4)
00567 #define DCT_FBO_IMAGE       ((DC_Type)5)
00568 
00569 /****************************
00570 * Extension functions prototypes
00571 ****************************/
00572 
00573 #ifdef WGL_DRIVER
00574     /* setup */
00575     typedef const char * (FAR __stdcall * wglGetExtensionsStringARBProc)(HDC hdc);
00576     typedef GLboolean (FAR __stdcall * wglChoosePixelFormatARBProc) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
00577     typedef GLboolean (FAR __stdcall * wglGetPixelFormatAttribivARBProc) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
00578     typedef GLboolean (FAR __stdcall * wglGetPixelFormatAttribfvARBProc) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, float *pfValues);
00579     typedef GLboolean (FAR __stdcall * wglChoosePixelFormatARBProc) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
00580     /* spriting */
00581     typedef HANDLE (FAR __stdcall * wglCreateBufferRegionARBProc) (HDC hDC, int iLayerPlane, UINT uType);
00582     typedef void (FAR __stdcall * wglDeleteBufferRegionARBProc) (HANDLE region);
00583     typedef void (FAR __stdcall * wglSaveBufferRegionARBProc) (HANDLE region, GLint x, GLint y, GLsizei width, GLsizei height);
00584     typedef void (FAR __stdcall * wglRestoreBufferRegionARBProc) (HANDLE region, GLint x, GLint y, GLsizei width, GLsizei height, GLint xDest, GLint yDest);
00585     typedef GLboolean (FAR __stdcall * wglMakeContextCurrentARBProc) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
00586     typedef HANDLE (FAR __stdcall * wglCreatePbufferARBProc) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
00587     typedef HDC (FAR __stdcall * wglGetPbufferDCARBProc) (HANDLE hPbuffer);
00588     typedef int (FAR __stdcall * wglReleasePbufferDCARBProc) (HANDLE hPbuffer, HDC hDC);
00589     typedef GLboolean (FAR __stdcall * wglDestroyPbufferARBProc) (HANDLE hPbuffer);
00590     typedef GLboolean (FAR __stdcall * wglQueryPbufferARBProc) (HANDLE hPbuffer);
00591     typedef GLuint (FAR __stdcall * glNewKTXBufferRegionProc) (GLenum type);
00592     typedef void (FAR __stdcall * glDeleteKTXBufferRegionProc) (GLuint region);
00593     typedef void (FAR __stdcall * glReadKTXBufferRegionProc) (GLuint region, GLint x, GLint y, GLsizei width, GLsizei height);
00594     typedef void (FAR __stdcall * glDrawKTXBufferRegionProc) (GLuint region, GLint x, GLint y, GLsizei width, GLsizei height, GLint xDest, GLint yDest);
00595     typedef GLuint (FAR __stdcall * glKTXBufferRegionEnabledProc) (void);
00596     /* multitexture */
00597     typedef void (FAR __stdcall * glActiveTextureARBProc) (GLenum format);
00598     typedef void (FAR __stdcall * glClientActiveTextureARBProc) (GLenum format);
00599     typedef void (FAR __stdcall * glMultiTexCoord2fvARBProc) (GLenum format, const GLfloat *);
00600     /* vertex/pixel shaders */
00601     typedef void (FAR __stdcall *glGenProgramsARBProc) (GLsizei n, GLuint *programs);
00602     typedef void (FAR __stdcall *glDeleteProgramsARBProc) (GLsizei n, const GLuint *programs);
00603     typedef void (FAR __stdcall *glProgramStringARBProc) (GLenum target, GLenum format, GLsizei len, const void *string);
00604     typedef void (FAR __stdcall *glBindProgramARBProc) (GLenum target, GLuint program);
00605     typedef void (FAR __stdcall *glProgramEnvParameter4fARBProc) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
00606     /* ARB shader objects */
00607     typedef void (FAR __stdcall *glShaderSourceARBProc) (GLuint shader, GLsizei nstrings, const char **strings, const GLint *lengths);
00608     typedef void (FAR __stdcall *glCompileShaderARBProc) (GLuint shader);
00609     typedef void (FAR __stdcall *glGetInfoLogARBProc) (GLuint shader, GLsizei maxLength, GLsizei *length, char *buffer);
00610     typedef void (FAR __stdcall *glAttachObjectARBProc) (GLuint program, GLuint shader);
00611     typedef void (FAR __stdcall *glDetachObjectARBProc) (GLuint program, GLuint shader);
00612     typedef void (FAR __stdcall *glDeleteShaderARBProc) (GLuint shader);
00613     typedef void (FAR __stdcall *glLinkProgramARBProc) (GLuint program);
00614     typedef GLuint (FAR __stdcall *glCreateShaderObjectARBProc) (GLenum shader_type);
00615     typedef GLuint (FAR __stdcall *glCreateProgramObjectARBProc) (void);
00616     typedef void (FAR __stdcall *glDeleteProgramARBProc) (GLuint program);
00617     typedef void (FAR __stdcall *glUseProgramObjectARBProc) (GLuint program);
00618     typedef void (FAR __stdcall *glGetObjectParameterfvARBProc) (GLuint shader, GLenum pname, GLfloat *params);
00619     typedef void (FAR __stdcall *glGetObjectParameterivARBProc) (GLuint shader, GLenum pname, GLint *params);
00620     /* ARB occlusion query */
00621     typedef void (FAR __stdcall *glGenQueriesARBProc) (GLsizei n, GLuint *ids);
00622     typedef void (FAR __stdcall *glDeleteQueriesARBProc) (GLsizei n, const GLuint *ids);
00623     typedef void (FAR __stdcall *glBeginQueryARBProc) (GLenum target, GLuint id);
00624     typedef void (FAR __stdcall *glEndQueryARBProc) (GLenum target);
00625     typedef void (FAR __stdcall *glGetQueryivARBProc) (GLenum target, GLenum pname, GLint *params);
00626     typedef void (FAR __stdcall *glGetQueryObjectuivARBProc) (GLuint id, GLenum pname, GLuint *params);
00627     /* NV occlusion query */
00628     typedef void (FAR __stdcall *glGenOcclusionQueriesNVProc) (GLsizei n, GLuint *ids);
00629     typedef void (FAR __stdcall *glDeleteOcclusionQueriesNVProc) (GLsizei n, const GLuint *ids);
00630     typedef void (FAR __stdcall *glBeginOcclusionQueryNVProc) (GLuint id);
00631     typedef void (FAR __stdcall *glEndOcclusionQueryNVProc) (void);
00632     typedef void (FAR __stdcall *glGetOcclusionQueryuivNVProc) (GLuint id, GLenum pname, GLuint *params);
00633     /* NV fence */
00634     typedef void (FAR __stdcall *glGenFencesNVProc)(GLsizei n, GLuint *fences);
00635     typedef void (FAR __stdcall *glDeleteFencesNVProc)(GLsizei n, const GLuint *fences);
00636     typedef void (FAR __stdcall *glSetFenceNVProc)(GLuint fence, GLenum condition);
00637     typedef GLboolean (FAR __stdcall *glTestFenceNVProc)(GLuint fence);
00638     typedef void (FAR __stdcall *glFinishFenceNVProc)(GLuint fence);
00639     typedef GLboolean (FAR __stdcall *glIsFenceNVProc)(GLuint fence);
00640     typedef void (FAR __stdcall *glGetFenceivNVProc)(GLuint fence, GLenum pname, GLint *params);
00641     /* ARB PointParameter */
00642     typedef void (FAR __stdcall *glPointParameterfARBProc)(GLenum pname, GLfloat param);
00643     typedef void (FAR __stdcall *glPointParameterfvARBProc)(GLenum pname, const GLfloat *param);
00644     /* ARB Texture Compression */
00645     typedef void (FAR __stdcall *glCompressedTexImage2DARBProc)(GLenum target, GLint level, 
00646                 GLenum internalformat, GLsizei width, GLsizei height, 
00647                 GLint border, GLsizei imageSize, const GLvoid *data);
00648     typedef void (FAR __stdcall *glPrimitiveRestartNVProc)(void);
00649     typedef void (FAR __stdcall *glPrimitiveRestartIndexNVProc)(GLuint index);
00650 
00651     /* EXT_framebuffer_object */
00652     typedef GLboolean (FAR __stdcall *glIsRenderbufferEXTProc)(GLuint renderbuffer);
00653     
00654     typedef void (FAR __stdcall *glBindRenderbufferEXTProc)(GLenum target, GLuint renderbuffer);
00655     typedef void (FAR __stdcall *glDeleteRenderbuffersEXTProc)(GLsizei n, const GLuint *renderbuffers);
00656     typedef void (FAR __stdcall *glGenRenderbuffersEXTProc)(GLsizei n, GLuint *renderbuffers);
00657     typedef void (FAR __stdcall *glRenderbufferStorageEXTProc)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
00658     typedef void (FAR __stdcall *glGetRenderbufferParameterivEXTProc)(GLenum target, GLenum pname, GLint *params);
00659 
00660     typedef GLboolean (FAR __stdcall *glIsFramebufferEXTProc)(GLuint framebuffer);
00661     typedef void (FAR __stdcall *glBindFramebufferEXTProc)(GLenum target, GLuint framebuffer);
00662     typedef void (FAR __stdcall *glDeleteFramebuffersEXTProc)(GLsizei n, const GLuint *framebuffers);
00663     typedef void (FAR __stdcall *glGenFramebuffersEXTProc)(GLsizei n, GLuint *framebuffers);
00664     typedef GLenum (FAR __stdcall *glCheckFramebufferStatusEXTProc)(GLenum target);
00665 
00666     typedef void (FAR __stdcall *glFramebufferTexture1DEXTProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
00667     typedef void (FAR __stdcall *glFramebufferTexture2DEXTProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
00668     typedef void (FAR __stdcall *glFramebufferTexture3DEXTProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
00669 
00670     typedef void (FAR __stdcall *glFramebufferRenderbufferEXTProc)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
00671     typedef void (FAR __stdcall *glGetFramebufferAttachmentParameterivEXTProc)(GLenum target, GLenum attachment, GLenum pname, GLint *params);
00672     typedef void (FAR __stdcall *glGenerateMipmapEXTProc)(GLenum target);
00673 
00674     /* ARB Vertex Buffer Objects */
00675     typedef void (FAR __stdcall *glBindBufferARBProc)(GLenum target, GLuint buffer);
00676     typedef void (FAR __stdcall *glDeleteBuffersARBProc)(GLsizei n, const GLuint *buffers);
00677     typedef void (FAR __stdcall *glGenBuffersARBProc)(GLsizei n, GLuint *buffers);
00678     typedef GLboolean (FAR __stdcall *glIsBufferARBProc)(GLuint buffer);
00679     typedef void (FAR __stdcall *glBufferDataARBProc)(GLenum target, GLsizei size, const void *data, GLenum usage);
00680     typedef void (FAR __stdcall *glBufferSubDataARBProc)(GLenum target, GLint *offset, GLsizei *size, const void *data);
00681     typedef void (FAR __stdcall *glGetBufferSubDataARBProc)(GLenum target, GLint *offset, GLsizei *size, void *data);
00682     typedef void * (FAR __stdcall *glMapBufferARBProc)(GLenum target, GLenum access);
00683     typedef GLboolean (FAR __stdcall *glUnmapBufferARBProc)(GLenum target);
00684     typedef void (FAR __stdcall *glGetBufferParameterivARBProc)(GLenum target, GLenum pname, int *params);
00685     typedef void (FAR __stdcall *glGetBufferPointervARBProc)(GLenum target, GLenum pname, void **params);
00686 
00687     /* glDrawRangeElementsEXT */
00688     typedef void (FAR __stdcall *glDrawRangeElementsEXTProc)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
00689 
00690     /* glMultiDrawArraysEXT */
00691     typedef void (FAR __stdcall *glMultiDrawArraysEXTProc) (GLenum, GLint *, GLsizei *, GLsizei);
00692     typedef void (FAR __stdcall *glMultiDrawElementsEXTProc) (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei);
00693 
00694 #endif
00695 
00696 #if defined(GLX_DRIVER) || defined(AGL_DRIVER)
00697     /* spriting */
00698     typedef GLuint (*glNewKTXBufferRegionProc) (GLenum type);
00699     typedef void (*glDeleteKTXBufferRegionProc) (GLuint region);
00700     typedef void (*glReadKTXBufferRegionProc) (GLuint region, GLint x, GLint y, GLsizei width, GLsizei height);
00701     typedef void (*glDrawKTXBufferRegionProc) (GLuint region, GLint x, GLint y, GLsizei width, GLsizei height, GLint xDest, GLint yDest);
00702     typedef GLuint (*glKTXBufferRegionEnabledProc) (void);
00703     /* multitexture */
00704     typedef void (*glActiveTextureARBProc) (GLenum format);
00705     typedef void (*glClientActiveTextureARBProc) (GLenum format);
00706     typedef void (*glMultiTexCoord2fvARBProc) (GLenum format, const GLfloat *);
00707     /* vertex/pixel shaders */
00708     typedef void (*glGenProgramsARBProc) (GLsizei n, GLuint *programs);
00709     typedef void (*glDeleteProgramsARBProc) (GLsizei n, const GLuint *programs);
00710     typedef void (*glProgramStringARBProc) (GLenum target, GLenum format, GLsizei len, const void *string);
00711     typedef void (*glBindProgramARBProc) (GLenum target, GLuint program);
00712     typedef void (*glProgramEnvParameter4fARBProc) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
00713     /* ARB shader objects */
00714     typedef void (*glShaderSourceARBProc) (GLuint shader, GLsizei nstrings, const char **strings, const GLint *lengths);
00715     typedef void (*glCompileShaderARBProc) (GLuint shader);
00716     typedef void (*glGetInfoLogARBProc) (GLuint shader, GLsizei maxLength, GLsizei *length, char *buffer);
00717     typedef void (*glAttachObjectARBProc) (GLuint program, GLuint shader);
00718     typedef void (*glDetachObjectARBProc) (GLuint program, GLuint shader);
00719     typedef void (*glDeleteShaderARBProc) (GLuint shader);
00720     typedef void (*glLinkProgramARBProc) (GLuint program);
00721     typedef GLuint (*glCreateShaderObjectARBProc) (GLenum shader_type);
00722     typedef GLuint (*glCreateProgramObjectARBProc) (void);
00723     typedef void (*glDeleteProgramARBProc) (GLuint program);
00724     typedef void (*glUseProgramObjectARBProc) (GLuint program);
00725     typedef void (*glGetObjectParameterfvARBProc) (GLuint shader, GLenum pname, GLfloat *params);
00726     typedef void (*glGetObjectParameterivARBProc) (GLuint shader, GLenum pname, GLint *params);
00727     /* ARB occlusion query */
00728     typedef void (*glGenQueriesARBProc) (GLsizei n, GLuint *ids);
00729     typedef void (*glDeleteQueriesARBProc) (GLsizei n, const GLuint *ids);
00730     typedef void (*glBeginQueryARBProc) (GLenum target, GLuint id);
00731     typedef void (*glEndQueryARBProc) (GLenum target);
00732     typedef void (*glGetQueryivARBProc) (GLenum target, GLenum pname, GLint *params);
00733     typedef void (*glGetQueryObjectuivARBProc) (GLuint id, GLenum pname, GLuint *params);
00734     /* NV occlusion query */
00735     typedef void (*glGenOcclusionQueriesNVProc) (GLsizei n, GLuint *ids);
00736     typedef void (*glDeleteOcclusionQueriesNVProc) (GLsizei n, const GLuint *ids);
00737     typedef void (*glBeginOcclusionQueryNVProc) (GLuint id);
00738     typedef void (*glEndOcclusionQueryNVProc) (void);
00739     typedef void (*glGetOcclusionQueryuivNVProc) (GLuint id, GLenum pname, GLuint *params);
00740     /* NV fence */
00741     typedef void (*glGenFencesNVProc)(GLsizei n, GLuint *fences);
00742     typedef void (*glDeleteFencesNVProc)(GLsizei n, const GLuint *fences);
00743     typedef void (*glSetFenceNVProc)(GLuint fence, GLenum condition);
00744     typedef GLboolean (*glTestFenceNVProc)(GLuint fence);
00745     typedef void (*glFinishFenceNVProc)(GLuint fence);
00746     typedef GLboolean (*glIsFenceNVProc)(GLuint fence);
00747     typedef void (*glGetFenceivNVProc)(GLuint fence, GLenum pname, GLint *params);
00748     /* ARB PointParameter */
00749     typedef void (*glPointParameterfARBProc)(GLenum pname, GLfloat param);
00750     typedef void (*glPointParameterfvARBProc)(GLenum pname, const GLfloat *param);
00751     /* ARB Texture Compression */
00752     typedef void (*glCompressedTexImage2DARBProc)(GLenum target, GLint level, 
00753                 GLenum internalformat, GLsizei width, GLsizei height, 
00754                 GLint border, GLsizei imageSize, const GLvoid *data);
00755     typedef void (*glPrimitiveRestartNVProc)(void);
00756     typedef void (*glPrimitiveRestartIndexNVProc)(GLuint index);
00757 
00758 
00759     /* EXT_framebuffer_object */
00760     typedef GLboolean (*glIsRenderbufferEXTProc)(GLuint renderbuffer);
00761     
00762     typedef void (*glBindRenderbufferEXTProc)(GLenum target, GLuint renderbuffer);
00763     typedef void (*glDeleteRenderbuffersEXTProc)(GLsizei n, const GLuint *renderbuffers);
00764     typedef void (*glGenRenderbuffersEXTProc)(GLsizei n, GLuint *renderbuffers);
00765     typedef void (*glRenderbufferStorageEXTProc)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
00766     typedef void (*glGetRenderbufferParameterivEXTProc)(GLenum target, GLenum pname, GLint *params);
00767 
00768     typedef GLboolean (*glIsFramebufferEXTProc)(GLuint framebuffer);
00769     typedef void (*glBindFramebufferEXTProc)(GLenum target, GLuint framebuffer);
00770     typedef void (*glDeleteFramebuffersEXTProc)(GLsizei n, const GLuint *framebuffers);
00771     typedef void (*glGenFramebuffersEXTProc)(GLsizei n, GLuint *framebuffers);
00772     typedef GLenum (*glCheckFramebufferStatusEXTProc)(GLenum target);
00773 
00774     typedef void (*glFramebufferTexture1DEXTProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
00775     typedef void (*glFramebufferTexture2DEXTProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
00776     typedef void (*glFramebufferTexture3DEXTProc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
00777 
00778     typedef void (*glFramebufferRenderbufferEXTProc)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
00779     typedef void (*glGetFramebufferAttachmentParameterivEXTProc)(GLenum target, GLenum attachment, GLenum pname, GLint *params);
00780     typedef void (*glGenerateMipmapEXTProc)(GLenum target);
00781 
00782     /* ARB Vertex Buffer Objects */
00783     typedef void (*glBindBufferARBProc)(GLenum target, GLuint buffer);
00784     typedef void (*glDeleteBuffersARBProc)(GLsizei n, const GLuint *buffers);
00785     typedef void (*glGenBuffersARBProc)(GLsizei n, GLuint *buffers);
00786     typedef GLboolean (*glIsBufferARBProc)(GLuint buffer);
00787     typedef void (*glBufferDataARBProc)(GLenum target, GLsizei size, const void *data, GLenum usage);
00788     typedef void (*glBufferSubDataARBProc)(GLenum target, GLint *offset, GLsizei *size, const void *data);
00789     typedef void (*glGetBufferSubDataARBProc)(GLenum target, GLint *offset, GLsizei *size, void *data);
00790     typedef void * (*glMapBufferARBProc)(GLenum target, GLenum access);
00791     typedef GLboolean (*glUnmapBufferARBProc)(GLenum target);
00792     typedef void (*glGetBufferParameterivARBProc)(GLenum target, GLenum pname, int *params);
00793     typedef void (*glGetBufferPointervARBProc)(GLenum target, GLenum pname, void **params);
00794 
00795     /* glDrawRangeElementsEXT */
00796     typedef void (*glDrawRangeElementsEXTProc)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
00797 
00798     /* glMultiDrawArraysEXT */
00799     typedef void (*glMultiDrawArraysEXTProc) (GLenum, GLint *, GLsizei *, GLsizei);
00800     typedef void (*glMultiDrawElementsEXTProc) (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei);
00801 
00802 # if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)
00803     typedef void *AGLPbuffer;
00804 # endif
00805 
00806 #endif
00807 
00808 
00809 #define ENV_MAP_TEXTURE_COUNT 11
00810 #define SPOT_LIGHT_TEXTURE_COUNT 20
00811 
00812 
00813 /* INTERNAL ACTION TABLE */
00814  
00815 typedef void (HC_CDECL *ogl_standard_action)(OGLData alter * ogldata, HT_Net_Rendition const * nr);
00816 typedef void (HC_CDECL *ogl_turn_off_lights_action)(OGLData alter * ogldata);
00817 typedef void (HC_CDECL *ogl_turn_on_lights_action)(OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Light_Rendition const * lr);
00818 typedef void (HC_CDECL *ogl_set_handedness_action)(OGLData alter * ogldata, HT_Transform_Rendition const * tr, int flags);
00819 typedef void (HC_CDECL *ogl_set_line_rendition_action)(OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Line_Rendition const * lr);
00820 typedef void (HC_CDECL *ogl_set_material_action)(OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Material_Rendition const * matr, HT_RGB const *use_color, HT_RGB const *use_specular_color);
00821 typedef void (HC_CDECL *ogl_set_indexed_material_action)(OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Material_Rendition const * matr);
00822 typedef void (HC_CDECL *ogl_set_overlay_color_action)(OGLData alter * ogldata, HT_Driver_Color const * color);
00823 typedef GLuint (HC_CDECL *ogl_define_texture_action)(OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Texture alter *txr, HT_Material_Components usage, int texture_unit);
00824 typedef bool (HC_CDECL *ogl_define_interpolation_texture_action)(OGLData alter * ogldata, HT_Net_Rendition const * nr);
00825 
00826 struct ogl_actions{
00827     ogl_standard_action         set_3d_xform;
00828     ogl_standard_action         set_dc_xform;
00829     ogl_standard_action         normal_z_buffer;
00830     ogl_standard_action         displaced_z_buffer;
00831     ogl_turn_off_lights_action  turn_off_lights;
00832     ogl_turn_on_lights_action   turn_on_lights;
00833     ogl_set_handedness_action   set_handedness;
00834     ogl_set_line_rendition_action   set_line_rendition;
00835     ogl_set_material_action     set_material;
00836     ogl_set_indexed_material_action set_texture_indexed_material;
00837     ogl_set_overlay_color_action    set_overlay_color;
00838     ogl_define_texture_action   define_texture;
00839     ogl_define_interpolation_texture_action define_interpolation_texture;
00840 };
00841  
00842 
00843 #ifndef DISABLE_OGL_ACTIONS
00844 
00845 /*OGL_ACTIONS*/
00846  
00847 /*INTERNAL ACTION MACROS*/
00848 #define OGL_SET_3D_XFORM(ogldata, nr) \
00849     (*(ogldata)->actions.set_3d_xform)(ogldata, nr);
00850 
00851 #define OGL_SET_DC_XFORM(ogldata, nr) \
00852     (*(ogldata)->actions.set_dc_xform)(ogldata, nr);
00853 
00854 #define OGL_TURN_OFF_LIGHTS(ogldata) \
00855     (*(ogldata)->actions.turn_off_lights)(ogldata);
00856 
00857 #define OGL_TURN_ON_LIGHTS(ogldata, nr, lr) \
00858     (*(ogldata)->actions.turn_on_lights)(ogldata, nr, lr);
00859 
00860 #define OGL_SET_HANDEDNESS(ogldata, tr, flags) \
00861     (*(ogldata)->actions.set_handedness)(ogldata, tr, flags);
00862 
00863 #define OGL_SET_LINE_RENDITION(ogldata, nr, lr) \
00864     (*(ogldata)->actions.set_line_rendition)(ogldata, nr, lr);
00865 
00866 #define OGL_SET_MATERIAL(ogldata, nr, mr, clr, sclr) \
00867     (*(ogldata)->actions.set_material)(ogldata, nr, mr, clr, sclr);
00868 
00869 #define OGL_SET_TEXTURE_INDEXED_MATERIAL(ogldata, nr, mr) \
00870     (*(ogldata)->actions.set_texture_indexed_material)(ogldata, nr, mr);
00871 
00872 #define OGL_SET_OVERLAY_COLOR(ogldata, color) \
00873     (*(ogldata)->actions.set_overlay_color)(ogldata, color);
00874     
00875 #define OGL_DEFINE_TEXTURE(ogldata, nr, txr, usage, texture_unit) \
00876     (*(ogldata)->actions.define_texture)(ogldata, nr, txr, usage, texture_unit);
00877     
00878 #define OGL_DEFINE_INTERPOLATION_TEXTURE(ogldata, nr) \
00879     (*(ogldata)->actions.define_interpolation_texture)(ogldata, nr);
00880     
00881 #else
00882 
00883 /*DISABLE_OGL_ACTIONS*/
00884  
00885 /*INTERNAL ACTION MACROS*/
00886 #define OGL_SET_3D_XFORM(ogldata, nr) set_3d_xform(ogldata, nr);
00887 
00888 #define OGL_SET_DC_XFORM(ogldata, nr) set_dc_xform(ogldata, nr);
00889 
00890 #define OGL_TURN_OFF_LIGHTS(ogldata) turn_off_lights(ogldata);
00891 
00892 #define OGL_TURN_ON_LIGHTS(ogldata, nr, lr) turn_on_lights(ogldata, nr, lr);
00893 
00894 #define OGL_SET_HANDEDNESS(ogldata, tr, flags) set_handedness(ogldata, tr, flags);
00895 
00896 #define OGL_SET_LINE_RENDITION(ogldata, nr, lr) set_line_rendition(ogldata, nr, lr);
00897 
00898 #define OGL_SET_MATERIAL(ogldata, nr, mr, clr, sclr) set_material(ogldata, nr, mr, clr, sclr);
00899 
00900 #define OGL_SET_TEXTURE_INDEXED_MATERIAL(ogldata, nr, mr) set_texture_indexed_material(ogldata, nr, mr);
00901 
00902 #define OGL_SET_OVERLAY_COLOR(ogldata, color) set_overlay_color(ogldata, color);
00903     
00904 #define OGL_DEFINE_TEXTURE(ogldata, nr) define_texture(ogldata, nr);
00905     
00906 #define OGL_DEFINE_INTERPOLATION_TEXTURE(ogldata, nr) define_interpolation_texture(ogldata, nr);
00907     
00908 #endif
00909 
00910 /*DEFAULT INTERNAL ACTION MACROS*/
00911 
00912 #define OGL_DEFAULT_SET_3D_XFORM(ogldata, nr) \
00913     (*(ogldata)->default_actions.set_3d_xform)(ogldata, nr);
00914 
00915 #define OGL_DEFAULT_SET_DC_XFORM(ogldata, nr) \
00916     (*(ogldata)->default_actions.set_dc_xform)(ogldata, nr);
00917 
00918 #define OGL_DEFAULT_TURN_OFF_LIGHTS(ogldata) \
00919     (*(ogldata)->default_actions.turn_off_lights)(ogldata);
00920 
00921 #define OGL_DEFAULT_TURN_ON_LIGHTS(ogldata, nr, lr) \
00922     (*(ogldata)->default_actions.turn_on_lights)(ogldata, nr, lr);
00923 
00924 #define OGL_DEFAULT_SET_HANDEDNESS(ogldata, tr, flags) \
00925     (*(ogldata)->default_actions.set_handedness)(ogldata, tr, flags);
00926 
00927 #define OGL_DEFAULT_SET_LINE_RENDITION(ogldata, nr, lr) \
00928     (*(ogldata)->default_actions.set_line_rendition)(ogldata, nr, lr);
00929 
00930 #define OGL_DEFAULT_SET_MATERIAL(ogldata, nr, mr, clr, sclr) \
00931     (*(ogldata)->default_actions.set_material)(ogldata, nr, mr, clr, sclr);
00932 
00933 #define OGL_DEFAULT_SET_TEXTURE_INDEXED_MATERIAL(ogldata, nr, mr) \
00934     (*(ogldata)->default_actions.set_texture_indexed_material)(ogldata, nr, mr);
00935 
00936 #define OGL_DEFAULT_SET_OVERLAY_COLOR(ogldata, color) \
00937     (*(ogldata)->default_actions.set_overlay_color)(ogldata, color);
00938     
00939 #define OGL_DEFAULT_DEFINE_TEXTURE(ogldata, nr) \
00940     (*(ogldata)->default_actions.define_texture)(ogldata, nr);
00941     
00942 #define OGL_DEFAULT_DEFINE_INTERPOLATION_TEXTURE(ogldata, nr) \
00943     (*(ogldata)->default_actions.define_interpolation_texture)(ogldata, nr);
00944     
00945 
00946 
00947 struct OGLData {
00948 
00949 #ifdef GLX_DRIVER
00950 
00951     Display             *display;
00952     Window              window;
00953     GLXContext          context;
00954     XVisualInfo         *visualinfo;
00955     Screen              *screen;
00956     Visual              *visual;
00957     GLXPbuffer          pbuffer;  /* if we are rendering as a pbuffer image */
00958 
00959     /* use to mung the X11 driver */
00960     HT_Action_Table x11;
00961 
00962     struct {
00963         Window window;
00964         GLXContext context;
00965         Colormap colormap;
00966         int next_color;
00967         int num_colors;
00968         long width;
00969         long height;
00970         int trans_pixel;
00971         HT_Driver_Color alter *colors;
00972     } overlay;
00973 
00974 #endif
00975 
00976 #ifdef WGL_DRIVER
00977 
00978     HWND hWND;
00979 
00980     HDC hDC; 
00981     HDC hInfoDC;
00982     HPBUFFERARB pbuffer; /* if we are rendering as a pbuffer image */
00983 
00984     /*for software hack*/
00985     bool use_memory_buffer;
00986     HDC hMemDC; 
00987     HBITMAP hBitmap;
00988     HBITMAP old_hBitmap;
00989 
00990     HGLRC hGLRC;
00991     HDC   prevDC;
00992     HGLRC prevGLRC;
00993     HGLRC overlayGLRC;
00994     WNDPROC saved_window_proc;
00995     HPALETTE ghPalette, ghpalOld;
00996 
00997     /*
00998      * Dimensions
00999      */
01000     RECT master_rectangle;
01001     HT_Int_XY old_size;
01002     HT_Int_XY old_position;
01003     HT_Int_XY original_aspect;
01004 
01005     int bottom_border;
01006     int right_border;
01007     int left_border;
01008     int top_border;
01009 
01010     int yfudge;
01011     int y_screen_fudge;
01012     int mouse_x;
01013     int mouse_y;
01014 
01015     /***********************/
01016     /*FONT DATA */
01017     int font_transformability;
01018 
01019     /* Logical font list */
01020     HT_Log_Font_Item *local_font_list;
01021 
01022 
01023 #define      LEFT_MOUSE      0x01
01024 #define      MIDDLE_MOUSE    0x04
01025 #define      RIGHT_MOUSE     0x02
01026 
01027     int mouse_buttons;
01028     bool mouse_was_queued;
01029     bool pending_resize;
01030     bool kill_me;
01031 #endif
01032 
01033 #ifdef AGL_DRIVER
01034 
01035     WindowRef window;
01036     AGLPbuffer pbuffer;  /* replacement for "window" when drawing to pbuffers */
01037 
01038     /* x,y,w,h outer then inner*/
01039     int * use_clip_override;
01040     int last_clip_override[8];
01041 
01042     GDHandle device;
01043     GDHandle info_device;
01044 
01045     AGLContext curr_AGLContext;
01046     AGLContext prev_AGLContext;
01047     GrafPtr curr_GrafPtr;
01048     GrafPtr prev_GrafPtr;
01049 
01050     EventHandlerUPP window_EventHandlerUPP; 
01051     EventHandlerRef event_handler_ref;
01052 
01053     int yfudge;
01054     int y_screen_fudge;
01055 
01056     float window_aspect;
01057 
01058     int mouse_x;
01059     int mouse_y;
01060 
01061 #define      LEFT_MOUSE      0x01
01062 #define      MIDDLE_MOUSE    0x04
01063 #define      RIGHT_MOUSE     0x02
01064 
01065     int mouse_buttons;
01066     bool mouse_was_queued;
01067 
01068     UInt32 key_state;
01069 
01070     bool pending_resize;
01071     bool kill_me;
01072 #endif
01073 
01074 
01075     /*DON"T PUT ANY PLATFORM SPECIFIC DATA BELOW HERE EXCEPT IN THE EXTENTIONS AREA*/
01076     DC_Type dc_type;
01077     char *revision_string;
01078 
01079     ogl_actions actions;
01080     ogl_actions default_actions;
01081 
01082     bool double_buffering;
01083     int accumulation_bits;
01084 
01085     HT_Image * output_image;
01086     void *output_image_scratch;
01087     int output_image_scratch_size;
01088     
01089     HT_Display_Context const *dc;
01090 
01091     unsigned int flush_interval;
01092     GLint stencil_planes;
01093     GLint zbuffer_planes;
01094     int zbuffer_max;
01095 
01096     int max_line_weight;
01097 
01098     bool can_texture;
01099     bool can_stencil;
01100     bool can_anti_alias; 
01101     int anti_alias_samples; 
01102     bool can_phong;
01103 
01104     bool fog_on;
01105     bool transparency_on;
01106     bool line_smooth_on;
01107 
01108     int spriting_method;
01109     bool has_overlay_planes;
01110     bool overlay_dirty;
01111 
01112 #define VERTEX_INDICES_SCRATCH_SIZE 16384
01113     int *vertex_indices_scratch_array;
01114 #define OGL_SCRATCH_SPACE_SIZE 4096 /* must be even */
01115     HT_Point *points_scratch_space;
01116     HT_Vector *normals_scratch_space;
01117     HT_RGB *colors_scratch_space;
01118     float *params_scratch_space;
01119 
01120     GLint max_lights;
01121     int lights_in_use;
01122 #define LIGHTS_INVALID  -1
01123 #define LIGHTS_OFF  0
01124 #define LIGHTS_NORMAL   1
01125 #define LIGHTS_PHONG    2
01126     int light_mode;
01127     bool is_spotlight[32];
01128     bool disable_spotlight_texture;
01129     bool cannot_spotlight_texture_condition;
01130 
01131     GLint max_cutting_planes;
01132     GLint max_texture_size;
01133 
01134     bool adjoint_Z_valid;
01135     float alter adjoint_Z[4];
01136 
01137     int n_cutting_planes_in_use;
01138     bool cutting_planes_on;
01139 
01140     bool net_modelling_is_identity;
01141     GLfloat alter world_to_eye[16];
01142     GLfloat alter modelview[4][4];  
01143 
01144 #define INVALID_INCARNATION (HT_Incarnation) -1
01145 #define INDC(incarn)        (-(incarn))
01146 #define IN3D(incarn)        (incarn)
01147     HT_Incarnation tr_incarnation;
01148     HT_Incarnation geom_incarnation;
01149     HT_Incarnation light_incarnation;
01150     HT_Incarnation cutting_plane_incarnation;
01151     HT_Incarnation fog_incarnation;
01152     HT_Incarnation clip_region_incarnation;
01153 
01154     /* cache current OpenGL state */
01155 #define INVALID_CACHE       (0xfeeeeeedU)
01156     struct {
01157         int texture_unit;
01158         bool colormaterial;
01159         GLenum colormaterialmode;
01160         int face_pattern;
01161         HT_Line_Style const *line_style;
01162         GLfloat line_weight;
01163         HT_Driver_Color color;
01164         HT_Driver_Color backcolor;
01165         HT_Driver_Color window_color;
01166 
01167         /* zbuffer_modes: */
01168 #define Z_OFF                   0
01169 #define Z_NORMAL                1
01170 #define Z_DISPLACED             2
01171 #define Z_RAW           3
01172         int zbuffer_mode;
01173         float       z_max;
01174         float       z_range[2];
01175         float       total_displacement;
01176 
01177         GLenum shade_model;
01178 
01179         /* drawing modes: */
01180 #define DRAW_MODE_NORMAL    0
01181 #define DRAW_MODE_OVERLAY   1
01182         int draw_mode;
01183 
01184         /* drawing overlay via XOR */
01185         bool xor_on;
01186 
01187         struct
01188         {
01189             HT_RGB a_d;     /* ambient and diffuse color of lighted objects */
01190             HT_RGB specular;    /* specular reflectance of lighted objects */
01191             HT_RGB emission;    /* emission objects */
01192             HT_RGB ambient; /* the global ambient illumination in a scene */
01193             GLfloat shininess;
01194         }
01195         material, back_material;
01196 
01197         GLint local_viewer; /* local or infinite viewers for the light model*/
01198 
01199         /* culling stuff */
01200         bool culling;
01201         GLenum cull_face;
01202 
01203 #define SCISSOR_MODE_OFF    0
01204 #define SCISSOR_MODE_ON     1
01205         /* whether scissor clipping is enabled */
01206         bool scissor_mode;  
01207         GLint scissor_x;        
01208         GLint scissor_y;
01209         GLsizei scissor_w;
01210         GLsizei scissor_h;
01211 
01212         GLint viewport_x;       
01213         GLint viewport_y;
01214         GLsizei viewport_w;
01215         GLsizei viewport_h;
01216 
01217         GLfloat pixel_zoom_x;
01218         GLfloat pixel_zoom_y;
01219 
01220         GLint pixel_unpack_alignment;
01221 
01222         /* whether auto normalize is enabled */
01223         bool normalize; 
01224 
01225         GLenum frontface;
01226         int two_sided;
01227 
01228         bool color_array;
01229         bool vertex_array;
01230         bool normal_array;
01231         bool param_array;
01232 
01233         GLuint texture_current;
01234         GLuint texture_indexed;
01235         GLuint texture_solidcolor;
01236         HT_Named_Material* texture_indexed_mapped_materials;
01237 
01238         /* note that we should never add caching for glTexParameteri (at least not
01239          * here) because it is separate per-texture state, not per-texunit */
01240 #define OGL_MAX_TEXTURE_UNITS 8
01241         GLint texture_wrap_s[OGL_MAX_TEXTURE_UNITS];
01242         GLint texture_wrap_t[OGL_MAX_TEXTURE_UNITS];
01243         GLint texture_env_mode[OGL_MAX_TEXTURE_UNITS];
01244         GLint texture_gen_mode[OGL_MAX_TEXTURE_UNITS];
01245         bool texture_gen[OGL_MAX_TEXTURE_UNITS];
01246         GLint texture_perspective_correction[OGL_MAX_TEXTURE_UNITS];
01247         bool textures_on[OGL_MAX_TEXTURE_UNITS];
01248 
01249         bool  stencil_on;
01250 
01251         int stereo_mode;
01252         float   stereo_skew;
01253         GLenum  default_buffer_mode;
01254 #define ANTI_ALIAS_OFF 0
01255 #define ANTI_ALIAS_ON  1
01256         int anti_alias_mode;
01257 
01258         struct {
01259             GLuint texture_id;
01260             float gloss;
01261             HT_Camera const *camera_pointer;
01262         } phong;
01263 
01264         int depth_function;
01265         GLboolean depth_mask;
01266         GLboolean color_mask;
01267         bool compiling_display_lists;
01268         bool compiling_geometry_display_lists;
01269 
01270         OGL_Render_Control render_control;
01271 
01272         GLuint list_base;
01273         GLenum volume_hint;
01274 
01275         GLenum blendfunc_sfactor;
01276         GLenum blendfunc_dfactor;
01277         bool blend_on;
01278 
01279             OGL_Display_List *display_lists;
01280     } cache;
01281 
01282     bool use_vertex_arrays;
01283 
01284 #define NUM_FACE_PATTERNS       (FP_WINDOW_TRANSPARENT + 1)
01285     /* 32bit x 32bit mask */
01286     GLubyte alter fpatterns[NUM_FACE_PATTERNS][128];    
01287     
01288     /* for transparency stippling and user-defined patterns */
01289     int stipple_incarnation;
01290     unsigned int stipple_pattern[32];
01291 
01292     /*XBIT STUFF */
01293     HT_Driver_Config *card_entry;
01294 
01295     /* for rendering nurbs curves */
01296     GLUnurbsObj *nurbs;
01297 
01298     /* for short-circuiting parts of set_[dc,3d]_xform functions */
01299     bool dc_mode;
01300     bool dc_mode_zbuffering;
01301     HT_Camera const *camera_pointer;
01302     float final_wlimit;
01303     float aspect;
01304     long extent_width;
01305     long extent_height;
01306     int window_width;
01307     int window_height;
01308     long dc_width;
01309     long dc_height;
01310     HT_TR_Flags world_handedness;
01311     HT_Incarnation modelling_matrix_incarnation;
01312     bool depth_peeling_mode;
01313     bool is_high_color;
01314 
01315     /*PUT ANY EXTENTIONS STUFF BELOW HERE INCLUDING PLATFORM SPECIFIC ONES*/
01316 
01317     /* true if the renderer has extention*/ 
01318     /* even if chosen pixel format/visual does not */
01319     bool supports_multisample; 
01320     bool supports_clip_volume_hint;
01321     bool supports_ARB_texture_mirrored_repeat;
01322     bool need_texture_border;
01323     bool separate_specular;
01324     bool supports_dot3;
01325     int version_major;
01326     int version_minor;
01327 
01328     bool supports_texture_filter_anisotropic;
01329     bool supports_buffer_region;
01330     bool supports_pbuffer;  
01331     bool supports_fbo_buffer;   
01332     bool supports_make_context_current; 
01333     bool supports_bgra;
01334     bool supports_display_lists;
01335     bool supports_texture_non_power_of_two;
01336     bool supports_texture_rectangle;
01337     bool supports_texture_compression_s3tc;
01338     bool supports_ARB_depth_texture;
01339     bool supports_ARB_shadow;
01340 
01341 #ifdef WGL_DRIVER
01342     bool supports_wgl_arb_pixel_format;
01343     wglGetPixelFormatAttribivARBProc wglGetPixelFormatAttribivARB;
01344     wglChoosePixelFormatARBProc wglChoosePixelFormatARB;
01345 
01346     wglCreateBufferRegionARBProc wglCreateBufferRegionARB;
01347     wglDeleteBufferRegionARBProc wglDeleteBufferRegionARB;
01348     wglSaveBufferRegionARBProc wglSaveBufferRegionARB;
01349     wglRestoreBufferRegionARBProc wglRestoreBufferRegionARB;
01350 
01351     wglCreatePbufferARBProc wglCreatePbufferARB;
01352     wglGetPbufferDCARBProc wglGetPbufferDCARB;
01353     wglReleasePbufferDCARBProc wglReleasePbufferDCARB;
01354     wglDestroyPbufferARBProc wglDestroyPbufferARB;
01355     wglQueryPbufferARBProc wglQueryPbufferARB;
01356 
01357     wglMakeContextCurrentARBProc wglMakeContextCurrentARB;
01358 #endif
01359 
01360     bool supports_ktx_buffer;
01361     glNewKTXBufferRegionProc glNewKTXBufferRegion;
01362     glDeleteKTXBufferRegionProc glDeleteKTXBufferRegion;
01363     glReadKTXBufferRegionProc glReadKTXBufferRegion;
01364     glDrawKTXBufferRegionProc glDrawKTXBufferRegion;
01365 
01366 #ifdef glActiveTextureARB
01367 #  undef glActiveTextureARB
01368 #endif
01369 #ifdef glGenProgramsARB
01370 #  undef glGenProgramsARB
01371 #endif
01372 #ifdef glDeleteProgramsARB
01373 #  undef glDeleteProgramsARB
01374 #endif
01375 #ifdef glProgramStringARB
01376 #  undef glProgramStringARB
01377 #endif
01378 #ifdef glBindProgramARB
01379 #  undef glBindProgramARB
01380 #endif
01381 #ifdef glShaderSourceARB
01382 #  undef glShaderSourceARB
01383 #endif
01384 #ifdef glCompileShaderARB
01385 #  undef glCompileShaderARB
01386 #endif
01387 #ifdef glGetInfoLogARB
01388 #  undef glGetInfoLogARB
01389 #endif
01390 #ifdef glAttachObjectARB
01391 #  undef glAttachObjectARB
01392 #endif
01393 #ifdef glDetachObjectARB
01394 #  undef glDetachObjectARB
01395 #endif
01396 #ifdef glDeleteShaderARB
01397 #  undef glDeleteShaderARB
01398 #endif
01399 #ifdef glLinkProgramARB
01400 #  undef glLinkProgramARB
01401 #endif
01402 #ifdef glCreateShaderObjectARB
01403 #  undef glCreateShaderObjectARB
01404 #endif
01405 #ifdef glDeleteProgramARB
01406 #  undef glDeleteProgramARB
01407 #endif
01408 #ifdef glUseProgramObjectARB
01409 #  undef glUseProgramObjectARB
01410 #endif
01411 
01412 #ifdef glGetObjectParameterfvARB
01413 #  undef glGetObjectParameterfvARB
01414 #endif
01415 #ifdef glGetObjectParameterivARB
01416 #  undef glGetObjectParameterivARB
01417 #endif
01418 
01419     glActiveTextureARBProc glActiveTextureARB;
01420     glClientActiveTextureARBProc glClientActiveTextureARB;
01421     glMultiTexCoord2fvARBProc glMultiTexCoord2fvARB;
01422     GLint max_texture_units;
01423 
01424     bool supports_ARB_vertex_program;
01425     bool supports_ARB_fragment_program;
01426     bool supports_ARB_fragment_program_shadow;
01427     glGenProgramsARBProc glGenProgramsARB;
01428     glDeleteProgramsARBProc glDeleteProgramsARB;
01429     glProgramStringARBProc glProgramStringARB;
01430     glBindProgramARBProc glBindProgramARB;
01431 
01432     bool supports_ARB_shader_objects;
01433     glShaderSourceARBProc glShaderSourceARB;
01434     glCompileShaderARBProc glCompileShaderARB;
01435     glAttachObjectARBProc glAttachObjectARB;
01436     glGetInfoLogARBProc glGetInfoLogARB;
01437     glDetachObjectARBProc glDetachObjectARB;
01438     glDeleteShaderARBProc glDeleteShaderARB;
01439     glLinkProgramARBProc glLinkProgramARB;
01440     glCreateShaderObjectARBProc glCreateShaderObjectARB;
01441     glCreateProgramObjectARBProc glCreateProgramObjectARB;
01442     glDeleteProgramARBProc glDeleteProgramARB;
01443     glUseProgramObjectARBProc glUseProgramObjectARB;
01444     glGetObjectParameterfvARBProc glGetObjectParameterfvARB;
01445     glGetObjectParameterivARBProc glGetObjectParameterivARB;
01446     glProgramEnvParameter4fARBProc glProgramEnvParameter4fARB;
01447 
01448     /* occlusion query */
01449     glGenQueriesARBProc glGenQueriesARB;
01450     glDeleteQueriesARBProc glDeleteQueriesARB;
01451     glBeginQueryARBProc glBeginQueryARB;
01452     glEndQueryARBProc glEndQueryARB;
01453     glGetQueryivARBProc glGetQueryivARB;
01454     glGetQueryObjectuivARBProc glGetQueryObjectuivARB;
01455     glGenOcclusionQueriesNVProc glGenOcclusionQueriesNV;
01456     glDeleteOcclusionQueriesNVProc glDeleteOcclusionQueriesNV;
01457     glBeginOcclusionQueryNVProc glBeginOcclusionQueryNV;
01458     glEndOcclusionQueryNVProc glEndOcclusionQueryNV;
01459     glGetOcclusionQueryuivNVProc glGetOcclusionQueryuivNV;
01460     bool occlusion_query_flush_required;
01461 
01462     /* VBO */
01463     bool supports_vbo;
01464     glBindBufferARBProc glBindBufferARB;
01465     glDeleteBuffersARBProc glDeleteBuffersARB;          
01466     glGenBuffersARBProc glGenBuffersARB;                
01467     glIsBufferARBProc glIsBufferARB;                    
01468     glBufferDataARBProc glBufferDataARB;                
01469     glBufferSubDataARBProc glBufferSubDataARB;          
01470     glGetBufferSubDataARBProc glGetBufferSubDataARB;        
01471     glMapBufferARBProc glMapBufferARB;              
01472     glUnmapBufferARBProc glUnmapBufferARB;              
01473     glGetBufferParameterivARBProc glGetBufferParameterivARB;        
01474     glGetBufferPointervARBProc glGetBufferPointervARB;      
01475 
01476     /* glDrawRangeElements */
01477     glDrawRangeElementsEXTProc glDrawRangeElementsEXT;
01478     glMultiDrawElementsEXTProc glMultiDrawElementsEXT;
01479     glMultiDrawArraysEXTProc glMultiDrawArraysEXT;
01480 
01481     /* NV fence */
01482     bool supports_nvfence;
01483     glGenFencesNVProc glGenFencesNV;
01484     glDeleteFencesNVProc glDeleteFencesNV; 
01485     glSetFenceNVProc glSetFenceNV;
01486     glTestFenceNVProc glTestFenceNV;
01487     glFinishFenceNVProc glFinishFenceNV;
01488     glIsFenceNVProc glIsFenceNV;
01489     glGetFenceivNVProc glGetFenceivNV; 
01490 
01491     /* ARB PointParameter */
01492     bool supports_point_parameters;
01493     glPointParameterfARBProc _glPointParameterfARB;
01494     glPointParameterfvARBProc _glPointParameterfvARB;
01495 
01496     /* Primitive Restart */
01497 #define PRIMITIVE_RESTART_INDEX 0xFFFFFFFF
01498     bool supports_NV_primitive_restart;
01499     glPrimitiveRestartNVProc _glPrimitiveRestartNV;
01500     glPrimitiveRestartIndexNVProc _glPrimitiveRestartIndexNV;
01501 
01502     /* ARB Texture Compression */
01503     bool supports_ARB_texture_compression;
01504     glCompressedTexImage2DARBProc glCompressedTexImage2DARB;
01505 
01506     /* EXT_framebuffer_object */
01507     bool supports_EXT_framebuffer_object;
01508     bool supports_EXT_packed_depth_stencil;
01509 
01510     glIsRenderbufferEXTProc glIsRenderbufferEXT;
01511     glBindRenderbufferEXTProc glBindRenderbufferEXT;
01512     glDeleteRenderbuffersEXTProc glDeleteRenderbuffersEXT;
01513     glGenRenderbuffersEXTProc glGenRenderbuffersEXT;
01514     glRenderbufferStorageEXTProc glRenderbufferStorageEXT;
01515     glGetRenderbufferParameterivEXTProc glGetRenderbufferParameterivEXT;
01516 
01517     glIsFramebufferEXTProc glIsFramebufferEXT;
01518     glBindFramebufferEXTProc glBindFramebufferEXT;
01519     glDeleteFramebuffersEXTProc glDeleteFramebuffersEXT;
01520     glGenFramebuffersEXTProc glGenFramebuffersEXT;
01521     glCheckFramebufferStatusEXTProc glCheckFramebufferStatusEXT;
01522 
01523     glFramebufferTexture1DEXTProc glFramebufferTexture1DEXT;
01524     glFramebufferTexture2DEXTProc glFramebufferTexture2DEXT;
01525     glFramebufferTexture3DEXTProc glFramebufferTexture3DEXT;
01526 
01527     glFramebufferRenderbufferEXTProc glFramebufferRenderbufferEXT;
01528     glGetFramebufferAttachmentParameterivEXTProc glGetFramebufferAttachmentParameterivEXT;
01529     glGenerateMipmapEXTProc glGenerateMipmapEXT;
01530 
01531     GLuint fbo_fb;
01532     GLuint fbo_color_tex;
01533     GLuint fbo_depth_rb;
01534     GLuint fbo_stencil_rb;
01535     GLuint fbo_depth_stencil_rb;
01536     GLint fbo_max_color_attachments;
01537     GLint fbo_max_renderbuffer_size;
01538 
01539     int fbo_width;
01540     int fbo_height;
01541 
01542     /* used for drawing cylinders */
01543     GLUquadric *cyl_quad; 
01544     GLUquadric *wire_cyl_quad;
01545     /* used for drawing spheres */
01546     GLUquadric *sphere_quad; 
01547     GLUquadric *wire_sphere_quad;
01548 
01549     bool is_software;
01550     bool continuous_mode;
01551     bool no_transparency_punting;
01552 
01553     HT_Texture *spot_light_textures[ SPOT_LIGHT_TEXTURE_COUNT + 1 ];
01554     bool disable_blending;
01555 
01556 #define DEPTH_PEELING_MAX_LAYERS    16
01557 #define DEPTH_PEELING_Z_TEXTURES    1
01558     GLuint depth_peeling_z_textures[DEPTH_PEELING_Z_TEXTURES];
01559     GLuint depth_peeling_rgba_textures[DEPTH_PEELING_MAX_LAYERS+1];
01560     int depth_peeling_width;
01561     int depth_peeling_height;
01562 
01563     GLuint depth_blit_program_id;
01564     GLuint depth_blit_shader_id;
01565     GLuint depth_blit_square_program_id;
01566     GLuint depth_blit_square_shader_id;
01567 
01568     HT_Integer32            collect_geometry;
01569     OGL_Collector           *collect_list;
01570     bool                ref_matrix_neg3x3;
01571     dlheap                  geometry_dl_requests;
01572     dlheap                  segment_dl_requests;
01573     HT_VList                *seen_list;
01574 
01575     bool region_buffer_in_use;
01576 };
01577 
01578 
01579 #ifndef DISABLE_OGL_ANTI_ALIAS
01580 # ifdef TEST_RIG_1
01581 #   define FORCE_ANTI_ALIAS_OFF(ogldata)  SEMI_PROTECT (\
01582       ogldata->cache.anti_alias_mode = ANTI_ALIAS_OFF;    \
01583       if (ogldata->can_anti_alias)                       \
01584           glDisable(MULTISAMPLE_ARB);                   \
01585       else                                                \
01586           ENSURE_LINE_SMOOTH_OFF(ogldata);                \
01587   )
01588 
01589 #   define FORCE_ANTI_ALIAS_ON(ogldata)  SEMI_PROTECT (\
01590       ogldata->cache.anti_alias_mode = ANTI_ALIAS_ON;     \
01591       if (ogldata->can_anti_alias) {                     \
01592           glEnable(MULTISAMPLE_ARB);                    \
01593       } else {                                            \
01594           ENSURE_LINE_SMOOTH_ON(ogldata);                \
01595           ENSURE_BLEND_ON(ogldata);                     \
01596       }                                                   \
01597   )
01598 # else
01599 #   define FORCE_ANTI_ALIAS_OFF(ogldata)  SEMI_PROTECT (\
01600       ogldata->cache.anti_alias_mode = ANTI_ALIAS_OFF;    \
01601       if (ogldata->can_anti_alias)                       \
01602           glDisable(MULTISAMPLE_ARB);                   \
01603   )
01604 
01605 #   define FORCE_ANTI_ALIAS_ON(ogldata)  SEMI_PROTECT (\
01606       ogldata->cache.anti_alias_mode = ANTI_ALIAS_ON;     \
01607       if (ogldata->can_anti_alias)                       \
01608           glEnable(MULTISAMPLE_ARB);                    \
01609   )
01610 # endif
01611 # define ENSURE_ANTI_ALIAS(ogldata, mode) SEMI_PROTECT (\
01612       if (ogldata->cache.xor_on) {                        \
01613           if (ogldata->cache.anti_alias_mode)            \
01614               FORCE_ANTI_ALIAS_OFF(ogldata);              \
01615       }                                                   \
01616       else if (ogldata->cache.anti_alias_mode != mode) {  \
01617           if (mode)                                        \
01618               FORCE_ANTI_ALIAS_ON(ogldata);               \
01619           else                                            \
01620               FORCE_ANTI_ALIAS_OFF(ogldata);              \
01621       }                                                   \
01622 )
01623 #else
01624 # define FORCE_ANTI_ALIAS_OFF(ogldata,mode) 
01625 # define FORCE_ANTI_ALIAS_ON(ogldata,mode) 
01626 # define ENSURE_ANTI_ALIAS(ogldata,mode) 
01627 #endif
01628 
01629 
01630 #define FORCE_TEXTURE_UNIT(ogldata, tu) SEMI_PROTECT(   \
01631     if (ogldata->glActiveTextureARB) {                  \
01632         (*ogldata->glActiveTextureARB)(GL_TEXTURE0_ARB + tu); } \
01633     ogldata->cache.texture_unit = tu;                   \
01634 )
01635 
01636 #define ENSURE_TEXTURE_UNIT(ogldata, tu)    SEMI_PROTECT(\
01637     if (ogldata->cache.texture_unit != tu)  {           \
01638         FORCE_TEXTURE_UNIT (ogldata, tu);  }            \
01639 )
01640 
01641 
01642 #define ENSURE_TEXTURES_OFF(ogldata, unit) SEMI_PROTECT (\
01643     ENSURE_TEXTURE_UNIT(ogldata, unit);                 \
01644     if (ogldata->cache.textures_on[unit])   {               \
01645         glDisable (GL_TEXTURE_2D);                      \
01646         ogldata->cache.textures_on[unit] = false;               \
01647     }       \
01648 )
01649 
01650 #define ENSURE_TEXTURES_ON(ogldata, unit) SEMI_PROTECT (\
01651     ENSURE_TEXTURE_UNIT(ogldata, unit);                 \
01652     if (!ogldata->cache.textures_on[unit])  {               \
01653         glEnable (GL_TEXTURE_2D);                       \
01654         ogldata->cache.textures_on[unit] = true;                \
01655     }       \
01656 )
01657 
01658 
01659 
01660 /* direct lookup from upper stereo_mode to GL buffer selection */
01661 static const GLenum stereo_back_buffers[]  = { GL_BACK,  GL_BACK_LEFT,  GL_BACK_RIGHT  };
01662 static const GLenum stereo_front_buffers[] = { GL_FRONT, GL_FRONT_LEFT, GL_FRONT_RIGHT };
01663 
01664 #define FORCE_STEREO(ogldata, mode) SEMI_PROTECT (                                  \
01665     if (ogldata->double_buffering)                                                  \
01666         glDrawBuffer (stereo_back_buffers[ogldata->cache.stereo_mode = mode]);      \
01667     else                                                                            \
01668         glDrawBuffer (stereo_front_buffers[ogldata->cache.stereo_mode = mode]);     \
01669 )
01670 
01671 #define ENSURE_STEREO(ogldata, mode) SEMI_PROTECT (\
01672     if (ogldata->cache.stereo_mode != mode)         \
01673         FORCE_STEREO(ogldata, mode);                \
01674 )
01675 
01676 
01677 
01678 #define EQ_RGB(c1, c2) ((c1).red == (c2).red && (c1).green == (c2).green && (c1).blue == (c2).blue)
01679 
01680 #define FORCE_CULLING(ogldata, face)        SEMI_PROTECT(\
01681     ogldata->cache.cull_face = face; \
01682     glCullFace (face); \
01683     ogldata->cache.culling = true; \
01684     glEnable (GL_CULL_FACE); \
01685 )
01686 
01687 #define ENSURE_CULLING(ogldata, face)       SEMI_PROTECT(\
01688     if (ogldata->cache.cull_face != face) { \
01689         ogldata->cache.cull_face = face; \
01690         glCullFace (face); \
01691     } \
01692     if (!ogldata->cache.culling) { \
01693         ogldata->cache.culling = true; \
01694         glEnable (GL_CULL_FACE); \
01695     } \
01696 )
01697 
01698 #define FORCE_CULLING_OFF(ogldata) SEMI_PROTECT(\
01699     ogldata->cache.culling = false; \
01700     glDisable (GL_CULL_FACE); \
01701 )
01702 
01703 #define ENSURE_CULLING_OFF(ogldata) SEMI_PROTECT(\
01704     if (ogldata->cache.culling) { \
01705         FORCE_CULLING_OFF (ogldata); \
01706     } \
01707 )
01708 
01709 #define FORCE_SHADE_MODEL(ogldata, model) SEMI_PROTECT(\
01710     ogldata->cache.shade_model = model; \
01711     glShadeModel (model); \
01712 )
01713 
01714 #define ENSURE_SHADE_MODEL(ogldata, model) SEMI_PROTECT(\
01715     if (ogldata->cache.shade_model != model) \
01716         FORCE_SHADE_MODEL (ogldata, model); \
01717 )
01718 
01719 
01720 
01721 #define FORCE_LIGHTS_OFF(ogldata) SEMI_PROTECT(\
01722     OGL_TURN_OFF_LIGHTS(ogldata); \
01723     ogldata->light_mode = LIGHTS_OFF; \
01724 )
01725 
01726 #define FORCE_LIGHTS_ON(ogldata, nr, lr, mode) SEMI_PROTECT(\
01727     OGL_TURN_ON_LIGHTS(ogldata, nr, (lr)); \
01728     ogldata->light_mode = mode; \
01729     ogldata->light_incarnation = (lr)->incarnation; \
01730 )
01731 
01732 #define ENSURE_LIGHTS_OFF(ogldata) SEMI_PROTECT(\
01733     if (ogldata->light_mode != LIGHTS_OFF) \
01734         FORCE_LIGHTS_OFF(ogldata); \
01735 )
01736 
01737 #define ENSURE_LIGHTS_ON(ogldata, nr, lr) SEMI_PROTECT(\
01738     if (ogldata->light_mode != LIGHTS_NORMAL || ogldata->light_incarnation != (lr)->incarnation || \
01739         ogldata->cache.material.ambient.red != nr->misc_rendition->ambient.red || \
01740         ogldata->cache.material.ambient.green != nr->misc_rendition->ambient.green || \
01741         ogldata->cache.material.ambient.blue != nr->misc_rendition->ambient.blue) \
01742         FORCE_LIGHTS_ON(ogldata, (nr), (lr), LIGHTS_NORMAL); \
01743 )
01744 
01745 #define ENSURE_LIGHTS_PHONG(ogldata, nr, lr) SEMI_PROTECT(\
01746     if (ogldata->light_mode != LIGHTS_PHONG || ogldata->light_incarnation != (lr)->incarnation || \
01747         ogldata->cache.material.ambient.red != nr->misc_rendition->ambient.red || \
01748         ogldata->cache.material.ambient.green != nr->misc_rendition->ambient.green || \
01749         ogldata->cache.material.ambient.blue != nr->misc_rendition->ambient.blue) \
01750         FORCE_LIGHTS_ON(ogldata, (nr), (lr), LIGHTS_PHONG); \
01751 )
01752 
01753 #define FORCE_TWO_SIDED(ogldata, mode) SEMI_PROTECT(\
01754     ogldata->cache.two_sided = mode; \
01755     glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, mode); \
01756 )
01757 
01758 #define ENSURE_TWO_SIDED(ogldata, mode) SEMI_PROTECT(\
01759     if (ogldata->cache.two_sided != mode) \
01760         FORCE_TWO_SIDED (ogldata, mode); \
01761 )
01762 
01763 #define FORCE_FRONT_FACE(ogldata, mode) SEMI_PROTECT(\
01764     ogldata->cache.frontface = mode; \
01765     glFrontFace (mode); \
01766 )
01767 
01768 #define ENSURE_FRONT_FACE(ogldata, mode) SEMI_PROTECT(\
01769     if (ogldata->cache.frontface != mode) \
01770         FORCE_FRONT_FACE (ogldata, mode); \
01771 )
01772 
01773 
01774 #define FORCE_WINDOW_COLOR(ogldata, newcolor) SEMI_PROTECT(\
01775     HT_RGB          out; \
01776     (ogldata)->cache.window_color.whichever = (newcolor)->whichever; \
01777     out.red   = UNSIGNED_CHARTOINT ((newcolor)->direct_rgb.r) * (1.0f/255.0f); \
01778     out.green = UNSIGNED_CHARTOINT ((newcolor)->direct_rgb.g) * (1.0f/255.0f); \
01779     out.blue  = UNSIGNED_CHARTOINT ((newcolor)->direct_rgb.b) * (1.0f/255.0f); \
01780     glClearColor (out.red, out.green, out.blue, 1.0f); \
01781 )
01782 
01783 #define ENSURE_WINDOW_COLOR(ogldata, newcolor)  SEMI_PROTECT(\
01784     if (ogldata->cache.window_color.whichever != (newcolor)->whichever || \
01785         ogldata->cache.window_color.whichever == INVALID_CACHE) \
01786         FORCE_WINDOW_COLOR(ogldata, newcolor); \
01787 )
01788 
01789 
01790 #define ENSURE_ZBUFFER_OFF(ogldata)          SEMI_PROTECT(\
01791     if (ogldata->cache.zbuffer_mode != Z_OFF) { \
01792         set_z_buffer(ogldata, nr, Z_OFF); \
01793     } \
01794 )
01795 
01796 
01797 #define ENSURE_ZBUFFER_RAW(ogldata) SEMI_PROTECT(\
01798     if (ogldata->cache.zbuffer_mode != Z_RAW) \
01799         set_z_buffer(ogldata, null, Z_RAW); \
01800 )
01801 
01802 #define ENSURE_ZBUFFER_NORMAL(ogldata,nr)               SEMI_PROTECT(\
01803     if ((nr)->transform_rendition->z_buffering) { \
01804         if (ogldata->cache.zbuffer_mode != Z_NORMAL || \
01805             ogldata->cache.z_range[0] != (nr)->transform_rendition->z_range[0] || \
01806             ogldata->cache.z_range[1] != (nr)->transform_rendition->z_range[1] || \
01807             ogldata->cache.total_displacement != \
01808                 (nr)->transform_rendition->general_displacement) { \
01809             set_z_buffer(ogldata, nr, Z_NORMAL); \
01810         } \
01811     } else { \
01812         ENSURE_ZBUFFER_OFF ((ogldata)); \
01813     } \
01814 )
01815 
01816 
01817 #define ENSURE_ZBUFFER_DISPLACED(ogldata,nr)            SEMI_PROTECT(\
01818   if ((nr)->transform_rendition->z_buffering) { \
01819     if (ogldata->cache.zbuffer_mode != Z_DISPLACED || \
01820         ogldata->cache.z_range[0] != (nr)->transform_rendition->z_range[0] || \
01821         ogldata->cache.z_range[1] != (nr)->transform_rendition->z_range[1] || \
01822         ogldata->cache.total_displacement != \
01823             ((nr)->transform_rendition->face_displacement + \
01824                 (nr)->transform_rendition->general_displacement)) { \
01825         set_z_buffer(ogldata, nr, Z_DISPLACED); \
01826     } \
01827   } else { \
01828     ENSURE_ZBUFFER_OFF ((ogldata)); \
01829   } \
01830 )
01831 
01832 #define ENSURE_ZBUFFER_NOT_DISPLACED(ogldata,nr)            SEMI_PROTECT( \
01833     if (ogldata->cache.total_displacement != 0.0f)              \
01834         set_z_buffer(ogldata, nr, Z_RAW);               \
01835 )
01836 
01837 
01838 #define FORCE_DEPTH_FUNCTION(ogldata,val) SEMI_PROTECT(\
01839     glDepthFunc(val); \
01840     ogldata->cache.depth_function = val; \
01841 )
01842 
01843 #define ENSURE_DEPTH_FUNCTION(ogldata,val) SEMI_PROTECT(\
01844     if (ogldata->cache.depth_function != val) \
01845         FORCE_DEPTH_FUNCTION(ogldata,val); \
01846 )
01847 
01848 
01849 #define FORCE_DEPTH_MASK(ogldata,val) SEMI_PROTECT(\
01850     ogldata->cache.depth_mask = (GLboolean)val; \
01851     glDepthMask ((GLboolean)val); \
01852 )
01853 
01854 #define ENSURE_DEPTH_MASK(ogldata,val) SEMI_PROTECT(\
01855     if (ogldata->cache.depth_mask != (GLboolean)(val)) \
01856         FORCE_DEPTH_MASK(ogldata,val); \
01857 )
01858 
01859 
01860 #define FORCE_COLOR_MASK(ogldata,val) SEMI_PROTECT(\
01861     if (!val) \
01862         glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); \
01863     else \
01864         glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); \
01865     ogldata->cache.color_mask = val; \
01866 )
01867 
01868 #define ENSURE_COLOR_MASK(ogldata, val) SEMI_PROTECT(\
01869     if (!ogldata->cache.color_mask != !val) \
01870         FORCE_COLOR_MASK(ogldata,val); \
01871 )
01872 
01873 
01874 #define FORCE_COLOR(ogldata, newcolor)      SEMI_PROTECT(\
01875     (ogldata)->cache.color.whichever = (newcolor)->whichever; \
01876     if (ogldata->cache.draw_mode == DRAW_MODE_NORMAL) { \
01877         if ((newcolor)->direct_rgb.a != 255) \
01878             glColor4ub ((newcolor)->direct_rgb.r, (newcolor)->direct_rgb.g, \
01879                         (newcolor)->direct_rgb.b, (newcolor)->direct_rgb.a); \
01880         else \
01881             glColor3ub ((newcolor)->direct_rgb.r, (newcolor)->direct_rgb.g, (newcolor)->direct_rgb.b); \
01882     } else { \
01883         OGL_SET_OVERLAY_COLOR (ogldata, &((ogldata)->cache.color)); \
01884     } \
01885 )
01886 
01887 #define FORCE_COLOR_4F(r,g,b,a) SEMI_PROTECT(\
01888     if (float(a) == 1.0f) \
01889         glColor3f(r,g,b); \
01890     else \
01891         glColor4f(r,g,b,a); \
01892 )
01893 
01894 #define FORCE_COLOR_4UB(r,g,b,a) SEMI_PROTECT(\
01895     if ((a) == 255) \
01896         glColor3ub(r,g,b); \
01897     else \
01898         glColor4ub(r,g,b,a); \
01899 )
01900 
01901 #define ENSURE_COLOR(ogldata, newcolor, nr)     SEMI_PROTECT(\
01902     if ((ogldata)->cache.xor_on) { \
01903         HT_Driver_Color xor_color; \
01904         xor_color.whichever = (newcolor)->whichever; \
01905         xor_color.direct_rgb.r ^= (nr)->window_rendition->window_color.direct_rgb.r; \
01906         xor_color.direct_rgb.g ^= (nr)->window_rendition->window_color.direct_rgb.g; \
01907         xor_color.direct_rgb.b ^= (nr)->window_rendition->window_color.direct_rgb.b; \
01908         if ((ogldata)->cache.color.whichever == INVALID_CACHE || \
01909             (ogldata)->cache.color.whichever != xor_color.whichever) { \
01910             FORCE_COLOR(ogldata, &xor_color); \
01911         } \
01912     } else { \
01913         if ((ogldata)->cache.color.whichever == INVALID_CACHE || \
01914             (ogldata)->cache.color.whichever != (newcolor)->whichever) { \
01915             FORCE_COLOR(ogldata, newcolor); \
01916         } \
01917     } \
01918 )
01919 
01920 #define FORCE_LINE_PATTERN(ogldata, lstyle) \
01921     (ogldata)->cache.line_style = lstyle; \
01922     if (!BIT(lstyle->flags, LSF_SOLID)) { \
01923         glLineStipple ((GLint)(lstyle)->scale16, (GLushort)(lstyle)->bits16); \
01924         glEnable (GL_LINE_STIPPLE); \
01925         if (XBIT_TEST(ogldata->card_entry->xbits, XBIT_LINE_PATTERN_NEEDS_BLENDING)) \
01926             ENSURE_BLEND_ON (ogldata); \
01927     } else \
01928         glDisable (GL_LINE_STIPPLE);
01929 
01930 #define ENSURE_LINE_PATTERN(ogldata, lstyle) SEMI_PROTECT(\
01931     if ((ogldata)->cache.line_style != (lstyle)) \
01932         FORCE_LINE_PATTERN(ogldata, lstyle); \
01933 )
01934 
01935 #define FORCE_LINE_WEIGHT(ogldata, width) \
01936     glLineWidth ((GLfloat)((ogldata)->cache.line_weight = (GLfloat)(width)))
01937 
01938 #define ENSURE_LINE_WEIGHT(ogldata, lwidth) SEMI_PROTECT(\
01939     if ((ogldata)->cache.line_weight != (GLfloat)(lwidth)) { \
01940         FORCE_LINE_WEIGHT(ogldata, lwidth); \
01941     } \
01942 )
01943 
01944 
01945 #define LINE_STYLE_PUNT(ogldata,lr,weight)\
01946         (!BIT((lr)->line_style->flags, LSF_SOLID) && \
01947          (\
01948             /* can't trust this card's glLineStipple */ \
01949             XBIT_TEST(ogldata->card_entry->xbits, XBIT_BAD_PATTERNED_LINES) || \
01950             /* no accurate 16-bit representation */ \
01951             !BIT((lr)->line_style->flags, LSF_BITS16) || \
01952             ANYBIT((lr)->line_style->flags, LSF_COMPLEX_ANYBITS)\
01953         ) ||\
01954          weight > 2 && !BIT ((ogldata)->dc->options.debug, DEBUG_MITRE_TO_DEFAULT) ||\
01955          weight > (ogldata)->max_line_weight\
01956         )
01957 
01958 #define FORCE_FACE_PATTERN(ogldata, fpattern) \
01959     glPolygonStipple ((GLubyte const *)((ogldata)->fpatterns[(ogldata)->cache.face_pattern = fpattern]))
01960 
01961 #define ENSURE_FACE_PATTERN(ogldata, fpattern)  SEMI_PROTECT(\
01962     if (fpattern == FP_USER_DEFINED) { \
01963         glPolygonStipple ((GLubyte const *)((ogldata)->stipple_pattern)); \
01964     } \
01965     else if ((ogldata)->cache.face_pattern != (fpattern)) { \
01966         FORCE_FACE_PATTERN(ogldata, fpattern); \
01967     } \
01968 )
01969 
01970 #define FORCE_MATERIAL_COLOR_ON(ogldata)        SEMI_PROTECT(\
01971     ogldata->cache.colormaterial = true; \
01972     glEnable (GL_COLOR_MATERIAL); \
01973 )
01974 
01975 #define ENSURE_MATERIAL_COLOR_ON(ogldata)   SEMI_PROTECT(\
01976     if (!ogldata->cache.colormaterial) { \
01977         FORCE_MATERIAL_COLOR_ON(ogldata); \
01978     } \
01979 )
01980 
01981 #define FORCE_MATERIAL_COLOR_OFF(ogldata)   SEMI_PROTECT(\
01982     ogldata->cache.colormaterial = false; \
01983     glDisable (GL_COLOR_MATERIAL); \
01984 )
01985 
01986 #define ENSURE_MATERIAL_COLOR_OFF(ogldata)  SEMI_PROTECT(\
01987     if (ogldata->cache.colormaterial) { \
01988         FORCE_MATERIAL_COLOR_OFF(ogldata); \
01989     } \
01990 )
01991 
01992 #define FORCE_MATERIAL_COLOR_MODE(ogldata,mode) SEMI_PROTECT(\
01993     ogldata->cache.colormaterialmode = mode; \
01994     glColorMaterial(mode,GL_AMBIENT_AND_DIFFUSE); \
01995 )
01996 
01997 #define ENSURE_MATERIAL_COLOR_MODE(ogldata,mode)    SEMI_PROTECT(\
01998     if (ogldata->cache.colormaterialmode != mode) { \
01999         FORCE_MATERIAL_COLOR_MODE(ogldata,mode); \
02000     } \
02001 )
02002 
02003 
02004 #define FORCE_CUTTING_OFF(ogldata)              SEMI_PROTECT(\
02005     int i_fcoff = ogldata->n_cutting_planes_in_use; \
02006     while (--i_fcoff >= 0)  \
02007         glDisable (GL_CLIP_PLANE0 + i_fcoff); \
02008     ogldata->cutting_planes_on = false; \
02009     ogldata->n_cutting_planes_in_use=0; \
02010 )
02011 
02012 #define ENSURE_CUTTING_OFF(ogldata)             SEMI_PROTECT(\
02013     if (ogldata->cutting_planes_on) { \
02014         FORCE_CUTTING_OFF(ogldata); \
02015     } \
02016 )
02017 
02018 #define FORCE_CUTTING_ON(ogldata)               SEMI_PROTECT(\
02019     int i_fcon = ogldata->n_cutting_planes_in_use; \
02020     while (i_fcon-- > 0) \
02021         glEnable (GL_CLIP_PLANE0 + i_fcon); \
02022     ogldata->cutting_planes_on = true; \
02023 )
02024 
02025 #define ENSURE_CUTTING_ON(ogldata)              SEMI_PROTECT(\
02026     if (ogldata->cutting_planes_on == false) { \
02027         FORCE_CUTTING_ON(ogldata); \
02028     } \
02029 )
02030 
02031 
02032 #define FORCE_XPARENCY_ON(ogldata)      SEMI_PROTECT(\
02033     ogldata->transparency_on = true; \
02034     ENSURE_BLEND_ON(ogldata); \
02035 )
02036 
02037 #define ENSURE_XPARENCY_ON(ogldata)     SEMI_PROTECT (\
02038     if (!ogldata->transparency_on) \
02039         FORCE_XPARENCY_ON(ogldata); \
02040 )
02041 
02042 #define FORCE_XPARENCY_OFF(ogldata)     SEMI_PROTECT(\
02043     ogldata->transparency_on = false; \
02044     ENSURE_BLEND_OFF(ogldata); \
02045 )
02046 
02047 #define ENSURE_XPARENCY_OFF(ogldata)        SEMI_PROTECT(\
02048     if (ogldata->transparency_on) \
02049         FORCE_XPARENCY_OFF(ogldata); \
02050 )
02051 
02052 #define ENSURE_TRANSPARENCY(ogldata, set)       SEMI_PROTECT(\
02053     if ((set) && !ogldata->disable_blending)    ENSURE_XPARENCY_ON(ogldata);  \
02054     else    ENSURE_XPARENCY_OFF(ogldata); \
02055 )
02056 
02057 #define ENSURE_LINE_SMOOTH_OFF(ogldata) SEMI_PROTECT (\
02058     if (ogldata->line_smooth_on) { \
02059         ogldata->line_smooth_on = false; \
02060         glDisable (GL_LINE_SMOOTH); \
02061     } \
02062 )
02063 
02064 #define ENSURE_LINE_SMOOTH_ON(ogldata) SEMI_PROTECT (\
02065     if (!ogldata->line_smooth_on) { \
02066         ogldata->line_smooth_on = true; \
02067         glEnable (GL_LINE_SMOOTH); \
02068     } \
02069 )
02070 
02071 #define ENSURE_LINE_SMOOTH(ogldata, set) SEMI_PROTECT (\
02072     if (set) \
02073         ENSURE_LINE_SMOOTH_ON(ogldata); \
02074     else \
02075         ENSURE_LINE_SMOOTH_OFF(ogldata); \
02076 )
02077 
02078 
02079 #define ENSURE_FOG_OFF(ogldata, nr) SEMI_PROTECT (\
02080     if (ogldata->fog_on) { \
02081     ogldata->fog_on = false; \
02082     glDisable (GL_FOG); \
02083     } \
02084 )
02085 
02086 #define ENSURE_FOG_ON(ogldata, nr) SEMI_PROTECT (\
02087     ogldata->fog_on = true; \
02088     glEnable (GL_FOG); \
02089     if (nr->visualization_rendition->incarnation != ogldata->fog_incarnation) { \
02090         float fog_color[4]; \
02091         ogldata->fog_incarnation = nr->visualization_rendition->incarnation; \
02092         glFogi (GL_FOG_MODE, GL_LINEAR); \
02093         fog_color[0] = nr->window_rendition->window_color.direct_rgb.r * (1.0f / 255.0f); \
02094         fog_color[1] = nr->window_rendition->window_color.direct_rgb.g * (1.0f / 255.0f); \
02095         fog_color[2] = nr->window_rendition->window_color.direct_rgb.b * (1.0f / 255.0f); \
02096         fog_color[3] = COMPLETELY_OPAQUE_ALPHA; \
02097         glFogfv (GL_FOG_COLOR, fog_color); \
02098         /* do not do pixel fog calculations */ \
02099         glHint (GL_FOG_HINT, GL_DONT_CARE); \
02100         if (nr->transform_rendition->camera->projection == Projection_PERSPECTIVE) { \
02101             glFogf (GL_FOG_START, nr->visualization_rendition->fog.hither); \
02102             glFogf (GL_FOG_END, nr->visualization_rendition->fog.yon); \
02103         }  \
02104         else {  \
02105             glFogf (GL_FOG_START, nr->visualization_rendition->fog.hither - tr->camera->eye_distance); \
02106             glFogf (GL_FOG_END, nr->visualization_rendition->fog.yon - tr->camera->eye_distance); \
02107         } \
02108     } \
02109 )
02110 
02111 
02112 #ifdef AGL_DRIVER
02113 
02114 #define FORCE_DRAW_MODE(ogldata, mode)      SEMI_PROTECT(\
02115     ogldata->cache.draw_mode = mode; \
02116     if (mode == DRAW_MODE_NORMAL) { \
02117         aglSetCurrentContext(ogldata->curr_AGLContext); \
02118     } else { \
02119         /*TODO: OVERLAY CONTEXT GOES HERE*/ \
02120     } \
02121 )
02122 
02123 #endif
02124 
02125 #ifdef GLX_DRIVER
02126 
02127 #define FORCE_DRAW_MODE(ogldata, mode)      SEMI_PROTECT(\
02128     ogldata->cache.draw_mode = mode; \
02129     if (mode == DRAW_MODE_NORMAL) { \
02130     glXMakeCurrent (ogldata->display, ogldata->window, ogldata->context); \
02131     } else { \
02132     glXMakeCurrent (ogldata->display, ogldata->overlay.window, ogldata->overlay.context); \
02133     } \
02134 )
02135 
02136 #endif
02137 
02138 #ifdef WGL_DRIVER
02139 
02140 #define FORCE_DRAW_MODE(ogldata, mode)      SEMI_PROTECT(\
02141     ogldata->cache.draw_mode = mode;\
02142     if (mode == DRAW_MODE_NORMAL) {\
02143         if (ogldata->use_memory_buffer)\
02144         wglMakeCurrent (ogldata->hMemDC, ogldata->hGLRC);\
02145         else\
02146         wglMakeCurrent (ogldata->hDC, ogldata->hGLRC);\
02147     } else { \
02148         /*TODO: OVERLAY CONTEXT GOES HERE*/ \
02149         wglMakeCurrent (ogldata->hDC, ogldata->hGLRC);\
02150     } \
02151 )
02152 
02153 #endif
02154 
02155 #define ENSURE_DRAW_MODE(ogldata, mode)     SEMI_PROTECT(\
02156     if (ogldata->cache.draw_mode != mode) \
02157     FORCE_DRAW_MODE(ogldata, mode); \
02158 )
02159 
02160 
02161 #define INVALIDATE_SCISSOR_SET(ogldata)  SEMI_PROTECT(\
02162     ogldata->cache.scissor_x = INVALID_CACHE; \
02163     ogldata->cache.scissor_y = INVALID_CACHE; \
02164     ogldata->cache.scissor_w = INVALID_CACHE; \
02165     ogldata->cache.scissor_h = INVALID_CACHE; \
02166 )
02167 
02168 #define FORCE_SCISSOR_OFF(ogldata)  SEMI_PROTECT(\
02169     INVALIDATE_SCISSOR_SET(ogldata); \
02170     ogldata->cache.scissor_mode = SCISSOR_MODE_OFF; \
02171     glDisable (GL_SCISSOR_TEST); \
02172 )
02173 
02174 #define ENSURE_SCISSOR_OFF(ogldata) SEMI_PROTECT(\
02175     if (ogldata->cache.scissor_mode != SCISSOR_MODE_OFF) \
02176     FORCE_SCISSOR_OFF (ogldata); \
02177 )
02178 
02179 #define FORCE_SCISSOR_ON(ogldata)   SEMI_PROTECT(\
02180     INVALIDATE_SCISSOR_SET(ogldata); \
02181     ogldata->cache.scissor_mode = SCISSOR_MODE_ON; \
02182     glEnable (GL_SCISSOR_TEST); \
02183 )
02184 
02185 #define ENSURE_SCISSOR_ON(ogldata)  SEMI_PROTECT(\
02186     if (ogldata->cache.scissor_mode != SCISSOR_MODE_ON) \
02187     FORCE_SCISSOR_ON (ogldata); \
02188 )
02189 
02190 #define ENSURE_SCISSOR_SET(ogldata, x, y, w, h)  SEMI_PROTECT(\
02191     if ((x != ogldata->cache.scissor_x) || (y != ogldata->cache.scissor_y) || \
02192     (w != ogldata->cache.scissor_w) || (h != ogldata->cache.scissor_h)) { \
02193     glScissor ((ogldata->cache.scissor_x = x), (ogldata->cache.scissor_y = y), \
02194            (ogldata->cache.scissor_w = w), (ogldata->cache.scissor_h = h)); \
02195     } \
02196 )
02197 
02198 #define INVALIDATE_PIXEL_ZOOM(ogldata)  SEMI_PROTECT(\
02199     ogldata->cache.pixel_zoom_x = 10000000.0f; \
02200     ogldata->cache.pixel_zoom_y = 10000000.0f; \
02201 )
02202 
02203 #define ENSURE_PIXEL_ZOOM(ogldata, x, y)  SEMI_PROTECT(\
02204     if (((x) != ogldata->cache.pixel_zoom_x) || ((y) != ogldata->cache.pixel_zoom_y)) { \
02205     glPixelZoom ((ogldata->cache.pixel_zoom_x = (x)), (ogldata->cache.pixel_zoom_y = (y))); \
02206     } \
02207 )
02208 
02209 #define INVALIDATE_PIXEL_UNPACK_ALIGNMENT(ogldata)  SEMI_PROTECT(\
02210     ogldata->cache.pixel_unpack_alignment = INVALID_CACHE; \
02211 )
02212 
02213 #define ENSURE_PIXEL_UNPACK_ALIGNMENT(ogldata, a)  SEMI_PROTECT(\
02214     if (((a) != ogldata->cache.pixel_unpack_alignment)) { \
02215         ogldata->cache.pixel_unpack_alignment = (a); \
02216     glPixelStorei (GL_PACK_ALIGNMENT, (a)); \
02217     glPixelStorei (GL_UNPACK_ALIGNMENT, (a)); \
02218     } \
02219 )
02220 
02221 
02222 
02223 #define FORCE_STENCIL_OFF(ogldata)  SEMI_PROTECT(\
02224     ogldata->cache.stencil_on = false; \
02225     glDisable (GL_STENCIL_TEST); \
02226 )
02227 
02228 #define ENSURE_STENCIL_OFF(ogldata) SEMI_PROTECT(\
02229     if (ogldata->cache.stencil_on) \
02230         FORCE_STENCIL_OFF (ogldata); \
02231 )
02232 
02233 #define FORCE_STENCIL_ON(ogldata)   SEMI_PROTECT(\
02234     ogldata->cache.stencil_on = true; \
02235     glEnable (GL_STENCIL_TEST); \
02236 )
02237 
02238 #define ENSURE_STENCIL_ON(ogldata)  SEMI_PROTECT(\
02239     if (ogldata->cache.stencil_on != SCISSOR_MODE_ON) \
02240         FORCE_STENCIL_ON (ogldata); \
02241 )
02242 
02243 
02244 
02245 
02246 
02247 #define INVALIDATE_VIEWPORT_SET(ogldata)  SEMI_PROTECT(\
02248     ogldata->cache.viewport_x = INVALID_CACHE; \
02249     ogldata->cache.viewport_y = INVALID_CACHE; \
02250     ogldata->cache.viewport_w = INVALID_CACHE; \
02251     ogldata->cache.viewport_h = INVALID_CACHE; \
02252 )
02253 
02254 #define ENSURE_VIEWPORT_SET(ogldata, x, y, w, h)  SEMI_PROTECT(\
02255     if ((x != ogldata->cache.viewport_x) || (y != ogldata->cache.viewport_y) || \
02256     (w != ogldata->cache.viewport_w) || (h != ogldata->cache.viewport_h)) { \
02257     glViewport((ogldata->cache.viewport_x = x), (ogldata->cache.viewport_y = y), \
02258            (ogldata->cache.viewport_w = w), (ogldata->cache.viewport_h = h)); \
02259     } \
02260 )
02261 
02262 
02263 #define FORCE_NORMALIZE_OFF(ogldata)    SEMI_PROTECT(\
02264     ogldata->cache.normalize = false; \
02265     glDisable (GL_NORMALIZE); \
02266 )
02267 
02268 #define ENSURE_NORMALIZE_OFF(ogldata)   SEMI_PROTECT(\
02269     if (ogldata->cache.normalize) \
02270     FORCE_NORMALIZE_OFF (ogldata); \
02271 )
02272 
02273 #define FORCE_NORMALIZE_ON(ogldata) SEMI_PROTECT(\
02274     ogldata->cache.normalize = true; \
02275     glEnable (GL_NORMALIZE); \
02276 )
02277 
02278 #define ENSURE_NORMALIZE_ON(ogldata)    SEMI_PROTECT(\
02279     if (!ogldata->cache.normalize) \
02280     FORCE_NORMALIZE_ON (ogldata); \
02281 )
02282 
02283 
02284 
02285 #define FORCE_COLOR_ARRAY_ON(ogldata) SEMI_PROTECT(\
02286     ogldata->cache.color_array = true; \
02287     glEnableClientState(GL_COLOR_ARRAY); \
02288 )
02289 
02290 #define FORCE_COLOR_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02291     ogldata->cache.color_array = false; \
02292     glDisableClientState(GL_COLOR_ARRAY); \
02293 )
02294 
02295 #define ENSURE_COLOR_ARRAY_ON(ogldata) SEMI_PROTECT(\
02296     if (!ogldata->cache.color_array) \
02297         FORCE_COLOR_ARRAY_ON(ogldata); \
02298 )
02299 
02300 #define ENSURE_COLOR_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02301     if (ogldata->cache.color_array) \
02302         FORCE_COLOR_ARRAY_OFF(ogldata); \
02303 )
02304 
02305 
02306 #define FORCE_VERTEX_ARRAY_ON(ogldata) SEMI_PROTECT(\
02307     ogldata->cache.vertex_array = true; \
02308     glEnableClientState(GL_VERTEX_ARRAY); \
02309 )
02310 
02311 #define FORCE_VERTEX_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02312     ogldata->cache.vertex_array = false; \
02313     glDisableClientState(GL_VERTEX_ARRAY); \
02314 )
02315 
02316 #define ENSURE_VERTEX_ARRAY_ON(ogldata) SEMI_PROTECT(\
02317     if (!ogldata->cache.vertex_array) \
02318         FORCE_VERTEX_ARRAY_ON(ogldata); \
02319 )
02320 
02321 #define ENSURE_VERTEX_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02322     if (ogldata->cache.vertex_array) \
02323         FORCE_VERTEX_ARRAY_OFF(ogldata); \
02324 )
02325 
02326 
02327 #define FORCE_NORMAL_ARRAY_ON(ogldata) SEMI_PROTECT(\
02328     ogldata->cache.normal_array = true; \
02329     glEnableClientState(GL_NORMAL_ARRAY); \
02330 )
02331 
02332 #define FORCE_NORMAL_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02333     ogldata->cache.normal_array = false; \
02334     glDisableClientState(GL_NORMAL_ARRAY); \
02335 )
02336 
02337 #define ENSURE_NORMAL_ARRAY_ON(ogldata) SEMI_PROTECT(\
02338     if (!ogldata->cache.normal_array) \
02339         FORCE_NORMAL_ARRAY_ON(ogldata); \
02340 )
02341 
02342 #define ENSURE_NORMAL_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02343     if (ogldata->cache.normal_array) \
02344         FORCE_NORMAL_ARRAY_OFF(ogldata); \
02345 )
02346 
02347 
02348 #define FORCE_TEXTURE_COORD_ARRAY_ON(ogldata) SEMI_PROTECT(\
02349     ogldata->cache.param_array = true; \
02350     glEnableClientState(GL_TEXTURE_COORD_ARRAY); \
02351 )
02352 
02353 #define FORCE_TEXTURE_COORD_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02354     ogldata->cache.param_array = false; \
02355     glDisableClientState(GL_TEXTURE_COORD_ARRAY); \
02356 )
02357 
02358 #define ENSURE_TEXTURE_COORD_ARRAY_ON(ogldata) SEMI_PROTECT(\
02359     if (!ogldata->cache.param_array) \
02360         FORCE_TEXTURE_COORD_ARRAY_ON(ogldata); \
02361 )
02362 
02363 #define ENSURE_TEXTURE_COORD_ARRAY_OFF(ogldata) SEMI_PROTECT(\
02364     if (ogldata->cache.param_array) \
02365         FORCE_TEXTURE_COORD_ARRAY_OFF(ogldata); \
02366 )
02367 
02368 
02369 #define FORCE_TEXTURE_WRAP_S(ogldata, mode, texture_unit)   SEMI_PROTECT(\
02370     ENSURE_TEXTURE_UNIT(ogldata, texture_unit); \
02371     ogldata->cache.texture_wrap_s[texture_unit] = mode; \
02372     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode); \
02373 )
02374 
02375 #define ENSURE_TEXTURE_WRAP_S(ogldata, mode, texture_unit)  SEMI_PROTECT(\
02376     if (ogldata->cache.texture_wrap_s[texture_unit] != mode) \
02377         FORCE_TEXTURE_WRAP_S(ogldata, mode, texture_unit); \
02378 )
02379 
02380 #define FORCE_TEXTURE_WRAP_T(ogldata, mode, texture_unit)   SEMI_PROTECT(\
02381     ENSURE_TEXTURE_UNIT(ogldata, texture_unit); \
02382     ogldata->cache.texture_wrap_t[texture_unit] = mode; \
02383     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode); \
02384 )
02385 
02386 #define ENSURE_TEXTURE_WRAP_T(ogldata, mode, texture_unit)  SEMI_PROTECT(\
02387     if (ogldata->cache.texture_wrap_t[texture_unit] != mode) \
02388     FORCE_TEXTURE_WRAP_T(ogldata, mode, texture_unit); \
02389 )
02390 
02391 #define FORCE_TEXTURE_ENV_MODE(ogldata, mode, texture_unit) SEMI_PROTECT(\
02392     ENSURE_TEXTURE_UNIT(ogldata, texture_unit); \
02393     ogldata->cache.texture_env_mode[texture_unit] = mode; \
02394     glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode); \
02395 )
02396 
02397 #define ENSURE_TEXTURE_ENV_MODE(ogldata, mode, texture_unit)    SEMI_PROTECT(\
02398     if (ogldata->cache.texture_env_mode[texture_unit] != mode) \
02399     FORCE_TEXTURE_ENV_MODE(ogldata, mode, texture_unit); \
02400 )
02401 
02402 #define FORCE_TEXTURE_PERSPECTIVE_CORRECTION_ON(ogldata, texture_unit)  SEMI_PROTECT(\
02403     ENSURE_TEXTURE_UNIT(ogldata, texture_unit); \
02404     ogldata->cache.texture_perspective_correction[texture_unit] = 1; \
02405     glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); \
02406 )
02407 
02408 #define ENSURE_TEXTURE_PERSPECTIVE_CORRECTION_ON(ogldata, texture_unit) SEMI_PROTECT(\
02409     if (ogldata->cache.texture_perspective_correction[texture_unit] != 1) \
02410         FORCE_TEXTURE_PERSPECTIVE_CORRECTION_ON(ogldata, texture_unit); \
02411 )
02412 
02413 #define FORCE_TEXTURE_PERSPECTIVE_CORRECTION_OFF(ogldata, texture_unit) SEMI_PROTECT(\
02414     ENSURE_TEXTURE_UNIT(ogldata, texture_unit); \
02415     ogldata->cache.texture_perspective_correction[texture_unit] = 0; \
02416     glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); \
02417 )
02418 
02419 #define ENSURE_TEXTURE_PERSPECTIVE_CORRECTION_OFF(ogldata, texture_unit)    SEMI_PROTECT(\
02420     if (ogldata->cache.texture_perspective_correction[texture_unit] != 0) \
02421         FORCE_TEXTURE_PERSPECTIVE_CORRECTION_OFF(ogldata, texture_unit); \
02422 )
02423 
02424 #define FORCE_TEXTURE_GEN_OFF(ogldata, texture_unit)    SEMI_PROTECT(\
02425     ogldata->cache.texture_gen[texture_unit] = false; \
02426     glDisable (GL_TEXTURE_GEN_S); \
02427     glDisable (GL_TEXTURE_GEN_T); \
02428 )
02429 
02430 #define ENSURE_TEXTURE_GEN_OFF(ogldata, texture_unit)   SEMI_PROTECT(\
02431     if (ogldata->cache.texture_gen[texture_unit]) \
02432         FORCE_TEXTURE_GEN_OFF (ogldata, texture_unit); \
02433 )
02434 
02435 #define FORCE_TEXTURE_GEN_ON(ogldata, texture_unit) SEMI_PROTECT(\
02436     ogldata->cache.texture_gen[texture_unit] = true; \
02437     glEnable (GL_TEXTURE_GEN_S); \
02438     glEnable (GL_TEXTURE_GEN_T); \
02439 )
02440 
02441 #define ENSURE_TEXTURE_GEN_ON(ogldata, texture_unit)    SEMI_PROTECT(\
02442     if (!ogldata->cache.texture_gen[texture_unit]) \
02443         FORCE_TEXTURE_GEN_ON (ogldata, texture_unit); \
02444 )
02445 
02446 #define FORCE_TEXTURE_GEN_MODE(ogldata, mode, texture_unit) SEMI_PROTECT(\
02447     ENSURE_TEXTURE_UNIT(ogldata, texture_unit); \
02448     ogldata->cache.texture_gen_mode[texture_unit] = mode; \
02449     glTexGenf (GL_S, GL_TEXTURE_GEN_MODE, mode); \
02450     glTexGenf (GL_T, GL_TEXTURE_GEN_MODE, mode); \
02451 )
02452 
02453 #define ENSURE_TEXTURE_GEN_MODE(ogldata, mode, texture_unit)  SEMI_PROTECT(\
02454     if (ogldata->cache.texture_gen_mode[texture_unit] != mode) \
02455         FORCE_TEXTURE_GEN_MODE(ogldata, mode, texture_unit); \
02456 )
02457 
02458 
02459 
02460 
02461 #define INVALIDATE_TEXTURE_SETTING_CACHE(ogldata, texture_unit) SEMI_PROTECT(\
02462     (ogldata)->cache.texture_wrap_s[texture_unit] = INVALID_CACHE; \
02463     (ogldata)->cache.texture_wrap_t[texture_unit] = INVALID_CACHE; \
02464     (ogldata)->cache.texture_env_mode[texture_unit] = INVALID_CACHE; \
02465     (ogldata)->cache.texture_gen_mode[texture_unit] = INVALID_CACHE; \
02466     (ogldata)->cache.texture_perspective_correction[texture_unit] = INVALID_CACHE; \
02467 )
02468 
02469 
02470 #define INVALIDATE_COLOR_AND_LIGHT_A_D(ogldata) SEMI_PROTECT(\
02471     (ogldata)->cache.color.whichever = INVALID_CACHE; \
02472     (ogldata)->cache.material.a_d.red = -1.0f; \
02473     (ogldata)->cache.material.a_d.green = -1.0f; \
02474     (ogldata)->cache.material.a_d.blue = -1.0f; \
02475 )
02476 
02477 
02478 #define FORCE_LOCAL_VIEWER(ogldata, mode) SEMI_PROTECT(\
02479     (ogldata)->cache.local_viewer = mode;\
02480     glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, mode); \
02481 )
02482 
02483 #define ENSURE_LOCAL_VIEWER(ogldata, mode) SEMI_PROTECT(\
02484     if ((ogldata)->cache.local_viewer != mode) { \
02485     FORCE_LOCAL_VIEWER(ogldata, mode); \
02486     } \
02487 )
02488 
02489 
02490 #define FORCE_BLEND_FUNC(ogldata, nsfactor, ndfactor) SEMI_PROTECT(\
02491     (ogldata)->cache.blendfunc_sfactor = nsfactor; \
02492     (ogldata)->cache.blendfunc_dfactor = ndfactor; \
02493     glBlendFunc(nsfactor, ndfactor); \
02494 )
02495 
02496 #define ENSURE_BLEND_FUNC(ogldata, nsfactor, ndfactor) SEMI_PROTECT(\
02497     if ((ogldata)->cache.blendfunc_sfactor != nsfactor || \
02498     (ogldata)->cache.blendfunc_dfactor != ndfactor) { \
02499     FORCE_BLEND_FUNC(ogldata, nsfactor, ndfactor); \
02500     } \
02501 )
02502 
02503 #define FORCE_BLEND_OFF(ogldata)    SEMI_PROTECT(\
02504     ogldata->cache.blend_on = false; \
02505     glDisable (GL_BLEND); \
02506 )
02507 
02508 #define ENSURE_BLEND_OFF(ogldata)   SEMI_PROTECT(\
02509     if (ogldata->cache.blend_on) \
02510         FORCE_BLEND_OFF (ogldata); \
02511 )
02512 
02513 #define FORCE_BLEND_ON(ogldata) SEMI_PROTECT(\
02514     ogldata->cache.blend_on = true; \
02515     glEnable (GL_BLEND); \
02516 )
02517 
02518 #define ENSURE_BLEND_ON(ogldata)    SEMI_PROTECT(\
02519     if (!ogldata->cache.blend_on) \
02520         FORCE_BLEND_ON (ogldata); \
02521 )
02522 
02523 
02524 #define ENSURE_DC_XFORM(ogldata, nr) SEMI_PROTECT(\
02525     if ((ogldata)->tr_incarnation != INDC ((nr)->transform_rendition->incarnation)) { \
02526         OGL_SET_DC_XFORM ((ogldata), (nr)); \
02527     } \
02528 )
02529 
02530 
02531 /* update the ref_matrix_negative_3x3 boolean, and make sure handedness stays 
02532  * in synch.  (ref_matrix_negative_3x3 tracks whether geometry has been put 
02533  * through a geometry reference with a negative scale matrix */
02534 #define ENSURE_NEG3X3(ogldata, tr, val) SEMI_PROTECT(\
02535     if (val != ogldata->ref_matrix_neg3x3) { \
02536         ogldata->ref_matrix_neg3x3 = val; \
02537         OGL_SET_HANDEDNESS (ogldata, tr, 0); \
02538     } \
02539     else \
02540         ogldata->ref_matrix_neg3x3 = val; \
02541 )
02542 
02543 
02544 #define ENSURE_3D_XFORM(ogldata, nr) SEMI_PROTECT(\
02545     if ((ogldata)->tr_incarnation != IN3D ((nr)->transform_rendition->incarnation)) { \
02546         OGL_SET_3D_XFORM ((ogldata), (nr)); \
02547     } \
02548     else { \
02549         HT_Matrix const *mat = nr->display_context->current_geo_ref.matrix; \
02550         bool neg3x3 = mat && BIT (mat->contents, Matrix_Contents_NEG3X3); \
02551         ENSURE_NEG3X3 (ogldata, nr->transform_rendition, neg3x3); \
02552     } \
02553 )
02554 
02555 #define ENSURE_ADJOINT_Z_VALID(ogldata, nr) SEMI_PROTECT(\
02556     if (!(ogldata)->adjoint_Z_valid) { \
02557     if (BIT (nr->transform_rendition->matrix->flags, Matrix_ADJOINT_VALID)) { \
02558         ogldata->adjoint_Z[0] = nr->transform_rendition->matrix->adjoint[2][0]; \
02559         ogldata->adjoint_Z[1] = nr->transform_rendition->matrix->adjoint[2][1]; \
02560         ogldata->adjoint_Z[2] = nr->transform_rendition->matrix->adjoint[2][2]; \
02561         ogldata->adjoint_Z[3] = nr->transform_rendition->matrix->adjoint[2][3]; \
02562     } \
02563     else { \
02564         HI_Adjoint_44_Z ((const float *) nr->transform_rendition->matrix->elements, \
02565                  ogldata->adjoint_Z); \
02566     } \
02567     (ogldata)->adjoint_Z_valid = true; \
02568     } \
02569 )
02570 
02571 #define FORCE_LIST_BASE(ogldata, base)  SEMI_PROTECT(\
02572     ogldata->cache.list_base = base; \
02573     glListBase (base); \
02574 )
02575 
02576 #define ENSURE_LIST_BASE(ogldata, base) SEMI_PROTECT(\
02577     if (ogldata->cache.list_base != base) \
02578     FORCE_LIST_BASE(ogldata, base); \
02579 )
02580 
02581 #define INVALIDATE_LIST_BASE(ogldata) SEMI_PROTECT(\
02582     ogldata->cache.list_base = INVALID_CACHE; \
02583 )
02584 
02585 #define ENSURE_CLIP_VOLUME_HINT(ogldata, hint) SEMI_PROTECT(\
02586     if (ogldata->supports_clip_volume_hint && ogldata->cache.volume_hint != hint) { \
02587         glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,(ogldata->cache.volume_hint=hint)); \
02588     } \
02589 )
02590 
02591 
02592 
02593 #  define OGL_ALLOC_TEXTURE(id) do { id=0 ; glGenTextures (1, &id); }while (0)
02594 #  define OGL_FREE_TEXTURE(id) do { glDeleteTextures (1, &id); id=0;}while (0)
02595 
02596 /* on AGL_DRIVER or quartz driver, quartz data is on dc->data */
02597 #define OGLD(dc) ((OGLData alter *)((dc)->data2))
02598 #define OGLNRD(nr) (OGLD((nr)->display_context))
02599 
02600 #ifdef GLX_DRIVER
02601 #  define X11D(dc) ((X11Data alter *)((dc)->data))
02602 #  define X11NRD(nr) (X11D(nr->display_context))
02603 #endif
02604 
02605 #ifdef WGL_DRIVER
02606 #define SYSTEM_DATA() ((System_Data alter *)OUR (system_specific_data))
02607 #endif
02608 
02609 
02610 /* weak imports for run-time detection of features that first became available
02611  * after MacOS 10.2, and declaration of stubs for compiles on older OS versions */
02612 #ifdef OSX_SYSTEM
02613 #  if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3)
02614   typedef CGContextRef (*CGGLContextCreateProc) (void *glContext, CGSize size, CGColorSpaceRef colorspace);
02615   typedef GLboolean (*aglSetPBufferProc) (AGLContext, AGLPbuffer, GLint, GLint, GLint);
02616   typedef GLboolean (*aglCreatePBufferProc) (GLint, GLint, GLenum, GLenum, long, AGLPbuffer *);
02617   typedef GLboolean (*aglDestroyPBufferProc) (AGLPbuffer);
02618   extern CGGLContextCreateProc CGGLContextCreate;
02619   extern aglSetPBufferProc aglSetPBuffer;
02620   extern aglCreatePBufferProc aglCreatePBuffer;
02621   extern aglDestroyPBufferProc aglDestroyPBuffer;
02622 #  else
02623   extern CGContextRef CGGLContextCreate (
02624     void *glContext, 
02625     CGSize size, 
02626     CGColorSpaceRef colorspace
02627 )  __attribute__((weak_import));
02628 
02629   extern GLboolean aglSetPBuffer (
02630     AGLContext ctx, 
02631     AGLPbuffer pbuffer, 
02632     GLint face, 
02633     GLint level, 
02634     GLint screen 
02635 )  __attribute__((weak_import));
02636 
02637   extern GLboolean aglCreatePBuffer (
02638     GLint width, 
02639     GLint height, 
02640     GLenum target, 
02641     GLenum internalFormat, 
02642     long max_level, 
02643     AGLPbuffer *pbuffer
02644 )  __attribute__((weak_import));
02645 
02646   extern GLboolean aglDestroyPBuffer (
02647     AGLPbuffer pbuffer
02648 )  __attribute__((weak_import));
02649 #  endif
02650 #endif
02651 
02652 
02653 #ifdef DECLARE_OGL_PROTOTYPES
02654 local void setup_ogl (HT_Display_Context alter * dc);
02655 local void init_ogldata (HT_Display_Context alter * dc);
02656 local void init_ogl_actions (OGLData alter * ogldata);
02657 local void invalidate_cache (OGLData alter * ogldata);
02658 local void identify_renderer (HT_Display_Context alter * dc);
02659 local void get_extension_specific_actions (OGLData alter * ogldata);
02660 local void update_physical_info (HT_Display_Context alter * dc);
02661 
02662 local void clear_z_buffer (HT_Net_Rendition const * nr, int left, int right, int bottom, int top);
02663 
02664 local void clear_overlay (HT_Display_Context const * dc);
02665 local void clear_screen (HT_Display_Context const * dc);
02666 
02667 local void turn_off_lights (OGLData alter * ogldata);
02668 local void turn_on_lights (OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Light_Rendition const * lr);
02669 
02670 local void set_dc_xform (OGLData alter * ogldata, HT_Net_Rendition const * nr);
02671 local void set_3d_xform (OGLData alter * ogldata, HT_Net_Rendition const * nr);
02672 local void set_handedness (OGLData alter * ogldata, HT_Transform_Rendition const * tr, int flags);
02673 
02674 local void set_line_rendition (OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Line_Rendition const * lr);
02675 local void set_material (OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Material_Rendition const * matr, HT_RGB const *use_color, HT_RGB const *use_specular_color);
02676 local void set_texture_indexed_material (OGLData alter * ogldata, HT_Net_Rendition const * nr, HT_Material_Rendition const * mr);
02677 local void set_overlay_color (OGLData alter * ogldata, HT_Driver_Color const * color);
02678 
02679 
02680 local void draw_overlay_list (HT_Net_Rendition const * nr);
02681 local void undraw_overlay_list (HT_Net_Rendition const * nr);
02682 
02683 
02684 local void insert_colormap_texture_image  (HT_Net_Rendition const * nr, GLint width, int use_mipmaps);
02685 
02686 local GLuint define_texture (
02687     OGLData alter * ogldata, 
02688     HT_Net_Rendition const * nr, 
02689     HT_Texture alter *txr, 
02690     HT_Material_Components usage,
02691     int texture_unit
02692     );
02693 local bool bind_texture (
02694     OGLData alter *ogldata,
02695     HT_Net_Rendition const * nr, 
02696     HT_Texture alter *txr, 
02697     OGL_Render_Control_Flags rcf,
02698     HT_Material_Components usage,
02699     GLuint id,
02700     int texture_unit
02701     ); 
02702 
02703 local bool define_interpolation_texture (OGLData alter * ogldata, HT_Net_Rendition const * nr);
02704 
02705 local void draw_dc_polydot (HT_Net_Rendition const * nr, int count, HT_DC_Point const * where);
02706 local void draw_dc_polyline (HT_Net_Rendition const * nr, int count, HT_DC_Point const * points);
02707 local void draw_dc_rectangle (HT_Net_Rendition const * nr, int left, int right, int bottom, int top);
02708 local void draw_dc_polytriangle (HT_Net_Rendition const * nr, int count, HT_DC_Point const * points);
02709 local void draw_dc_colorized_polytriangle (HT_Net_Rendition const * nr, int count, HT_DC_Point const * points, HT_RGBAS32 const * color, bool single);
02710 local void draw_dc_gouraud_polytriangle (HT_Net_Rendition const * nr, int count, HT_DC_Point const * points, HT_RGBAS32 const * colors);
02711 local void draw_dc_gouraud_polyline (HT_Net_Rendition const * nr, int count, HT_DC_Point const *points, HT_RGBAS32 const *colors);
02712 local void draw_dc_face (HT_Net_Rendition const * nr, int count, HT_DC_Point const * points);
02713 local void draw_dc_colorized_face (HT_Net_Rendition const * nr, int count, HT_DC_Point const * points, HT_RGBAS32 const * color);
02714 local void draw_dc_textured_polytriangle (HT_Net_Rendition const * nr, int count, HT_DC_Point const * points, HT_RGBA const * color, HT_Plane const * plane, HT_Parameter const * vertex_params, HT_Integer32 param_width, HT_Parameter_Flags param_flags);
02715 local void draw_dc_rgb32_rasters (HT_Net_Rendition const * nr, HT_DC_Point const * start, HT_DC_Point const * end, int row_bytes, HT_RGBAS32 const * raster);
02716 
02717 local bool punt_3d_tristrip (HT_Net_Rendition const * nr, HT_Tristrip const * ts);
02718 
02719 local void segment_render (HT_Net_Rendition const * nr, HT_Geometry const * g, HT_Action_Mask mask, bool single);
02720 local void draw_3d_polyline (HT_Net_Rendition const * nr, HT_Polyline const * polyline);
02721 local void draw_3d_polygon (HT_Net_Rendition const * nr, HT_Polygon const * polygon);
02722 
02723 local void draw_3d_nurbs_curve (auto HT_Net_Rendition const * nr, auto HT_NURBS_Curve const * curve);
02724 local void draw_3d_tristrip (auto HT_Net_Rendition const * nr, auto HT_Tristrip const * ts);
02725 local void draw_indexed_tristrip (auto HT_Net_Rendition const * nr, auto HT_Tristrip const * ts);
02726 
02727 local HT_Polyedge alter *lines_to_polyedge (HT_Net_Rendition const *nr, HT_Geometry const *start_g);
02728 local OGL_Display_List *edgeodl_to_lineodl (HT_Net_Rendition const *nr, OGL_Display_List alter *odl);
02729 local void really_draw_3d_polyedge (HT_Net_Rendition const * nr, HT_Line_Rendition const *er, HT_Polyedge const * pe);
02730 local void draw_3d_polyedge (HT_Net_Rendition const * nr, HT_Polyedge const * pe);
02731 local void draw_3d_polymarker (HT_Net_Rendition const * nr, HT_Polymarker const * pm);
02732 
02733 local void create_region (HT_Net_Rendition const * nr, HT_Int_Rectangle const * area, void **image, void **z);
02734 local void save_region (HT_Net_Rendition const * nr, HT_Int_Rectangle const * area, void alter * image, void alter * z);
02735 local void restore_region (HT_Net_Rendition const * nr, HT_Int_Rectangle const * area, void alter * image, void alter * z);
02736 local void destroy_region (HT_Net_Rendition const * nr, void alter * image, void alter * z);
02737 
02738 local void destroy_list (HT_Display_Context alter * dc, void *list);
02739 local void show_image_data (void *list);
02740 local bool start_device (HT_Display_Context alter * dc);
02741 local void stop_device (HT_Display_Context alter * dc);
02742 local void init_picture (HT_Net_Rendition const * nr);
02743 local void finish_picture (HT_Net_Rendition const * nr,
02744                 bool swap_buffers);
02745 local void finish_update (HT_Display_Context const * dc);
02746 local void init_update (HT_Display_Context const * dc);
02747 local POINTER_SIZED_INT get_outer_window (HT_Display_Context const *const_dc);
02748 local void free_outer_window (HT_Display_Context const *dc);
02749 local void resize_outer_window (HT_Display_Context const *dc);
02750 local void get_current_info (HT_Display_Context alter * dc);
02751 local void get_physical_info (HT_Display_Context alter * dc);
02752 local bool request_location (
02753     HT_Display_Context const * dc,
02754     int alter * button,
02755     int alter * x, 
02756     int alter * y);
02757 local bool request_keyboard (
02758     HT_Display_Context const * dc,
02759     int alter * button, 
02760     int alter * status);
02761 local void set_z_buffer (OGLData alter * ogldata, HT_Net_Rendition const * nr, int mode);
02762 
02763         
02764 local bool common_make_fbo_current(OGLData alter * ogldata);
02765 local bool common_setup_fbo(OGLData alter * ogldata, bool test_it_only);
02766 local void common_cleanup_fbo(OGLData alter * ogldata);
02767 
02768 #endif /* ogl prototypes */
02769 
02770 #endif
02771 /*OGL_H_DEFINED*/
02772 
02773 
02774 
02775 
02776 
02777 
02778 
02779 
02780 
02781 
Main Index
HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>