1 /***********************************************************************/ 2 /* Open Visualization Data Explorer */ 3 /* (C) Copyright IBM Corp. 1989,1999 */ 4 /* ALL RIGHTS RESERVED */ 5 /* This code licensed under the */ 6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 /***********************************************************************/ 8 /*********************************************************************/ 9 /* I.B.M. CONFIENTIAL */ 10 /*********************************************************************/ 11 12 #include <dxconfig.h> 13 14 15 #ifndef tdmPortOGL_h 16 #define tdmPortOGL_h 17 /*---------------------------------------------------------------------------*\ 18 $Source: /src/master/dx/src/exec/hwrender/opengl/hwPortOGL.h,v $ 19 20 Data structures used by OpenGL implementation of the DX hardware renderer. 21 22 \*---------------------------------------------------------------------------*/ 23 24 #if !defined(DX_NATIVE_WINDOWS) 25 #include <GL/glx.h> 26 #endif 27 #include <GL/gl.h> 28 29 typedef struct { 30 GLfloat x; 31 GLfloat y; 32 GLfloat z; 33 } oglVector ; 34 35 typedef struct { 36 GLfloat r; 37 GLfloat g; 38 GLfloat b; 39 } oglRGBColor ; 40 41 typedef struct ClipPlaneS { 42 double a; 43 double b; 44 double c; 45 double d; 46 } ClipPlaneT, ClipPlane; 47 48 #if defined(DX_NATIVE_WINDOWS) 49 50 typedef struct { 51 HGLRC hRC; 52 HDC hDC; 53 PAINTSTRUCT ps; 54 HWND win; 55 int winHeight; 56 int winWidth; 57 int xmaxscreen; 58 int ymaxscreen; 59 RGBColor background_color; 60 hwTranslationP translation; 61 int fontListBase; 62 int clipPlaneCount; 63 int maxClipPlanes; 64 WinT *winT; 65 HashTable displayListHash; 66 HashTable textureHash; 67 int doDisplayLists; 68 int currentTexture; 69 } tdmOGLctxT, *tdmOGLctx ; 70 71 #define DEFCONTEXT(ctx) \ 72 register tdmOGLctx _portContext = (tdmOGLctx)(ctx) 73 74 #define OGLHRC (((tdmOGLctx)_portContext)->hRC) 75 #define OGLHDC (((tdmOGLctx)_portContext)->hDC) 76 #define OGLPS (((tdmOGLctx)_portContext)->ps) 77 #define OGLXWIN (((tdmOGLctx)_portContext)->win) 78 #define WINWIDTH (((tdmOGLctx)_portContext)->winWidth) 79 #define WINHEIGHT (((tdmOGLctx)_portContext)->winHeight) 80 #define XMAXSCREEN (((tdmOGLctx)_portContext)->xmaxscreen) 81 #define YMAXSCREEN (((tdmOGLctx)_portContext)->ymaxscreen) 82 #define BACKGROUND_COLOR (((tdmOGLctx)_portContext)->background_color) 83 #define OGLTRANSLATION (((tdmOGLctx)_portContext)->translation) 84 #define FONTLISTBASE (((tdmOGLctx)_portContext)->fontListBase) 85 #define CLIP_PLANE_CNT (((tdmOGLctx)_portContext)->clipPlaneCount) 86 #define MAX_CLIP_PLANES (((tdmOGLctx)_portContext)->maxClipPlanes) 87 #define OGLWINT (((tdmOGLctx)_portContext)->winT) 88 #define DO_DISPLAY_LISTS (((tdmOGLctx)_portContext)->doDisplayLists) 89 #define DISPLAY_LIST_HASH (((tdmOGLctx)_portContext)->displayListHash) 90 #define TEXTURE_HASH (((tdmOGLctx)_portContext)->textureHash) 91 #define CURTEX (((tdmOGLctx)_portContext)->currentTexture) 92 #define PATTERN_INDEX 1 93 94 #else 95 96 typedef struct { 97 Display *dpy; 98 int screen; 99 Window win; 100 GLXContext ctx; 101 int winHeight; 102 int winWidth; 103 int xmaxscreen; 104 int ymaxscreen; 105 RGBColor background_color; 106 hwTranslationP translation; 107 int fontListBase; 108 int clipPlaneCount; 109 int maxClipPlanes; 110 WinT *winT; 111 HashTable displayListHash; 112 HashTable textureHash; 113 int doDisplayLists; 114 int currentTexture; 115 } tdmOGLctxT, *tdmOGLctx ; 116 117 #define DEFCONTEXT(ctx) \ 118 register tdmOGLctx _portContext = (tdmOGLctx)(ctx) 119 120 #define OGLDPY (((tdmOGLctx)_portContext)->dpy) 121 #define OGLSCREEN (((tdmOGLctx)_portContext)->screen) 122 #define OGLXWIN (((tdmOGLctx)_portContext)->win) 123 #define OGLCTX (((tdmOGLctx)_portContext)->ctx) 124 #define WINWIDTH (((tdmOGLctx)_portContext)->winWidth) 125 #define WINHEIGHT (((tdmOGLctx)_portContext)->winHeight) 126 #define XMAXSCREEN (((tdmOGLctx)_portContext)->xmaxscreen) 127 #define YMAXSCREEN (((tdmOGLctx)_portContext)->ymaxscreen) 128 #define BACKGROUND_COLOR (((tdmOGLctx)_portContext)->background_color) 129 #define OGLTRANSLATION (((tdmOGLctx)_portContext)->translation) 130 #define FONTLISTBASE (((tdmOGLctx)_portContext)->fontListBase) 131 #define CLIP_PLANE_CNT (((tdmOGLctx)_portContext)->clipPlaneCount) 132 #define MAX_CLIP_PLANES (((tdmOGLctx)_portContext)->maxClipPlanes) 133 #define OGLWINT (((tdmOGLctx)_portContext)->winT) 134 #define DO_DISPLAY_LISTS (((tdmOGLctx)_portContext)->doDisplayLists) 135 #define DISPLAY_LIST_HASH (((tdmOGLctx)_portContext)->displayListHash) 136 #define TEXTURE_HASH (((tdmOGLctx)_portContext)->textureHash) 137 #define CURTEX (((tdmOGLctx)_portContext)->currentTexture) 138 #define PATTERN_INDEX 1 139 140 #endif 141 142 int _dxf_isDisplayListOpenOGL(); 143 void _dxf_callDisplayListOGL(dxObject dlo); 144 dxObject _dxf_openDisplayListOGL(); 145 void _dxf_endDisplayListOGL(); 146 147 /* 148 * Debugging macros local to this port 149 */ 150 #if defined(DEBUG) 151 152 #if !defined(DXHW_OGL_ErrorList) 153 # define DXHW_OGL_ErrorList 154 static struct 155 { 156 int code; 157 char * str; 158 } 159 _errorList[] = 160 { 161 GL_INVALID_ENUM, "Invalid Enumeration", 162 GL_INVALID_VALUE, "Invalid Value", 163 GL_INVALID_OPERATION, "Invalid Operation", 164 GL_STACK_OVERFLOW, "Stack Overflow", 165 GL_STACK_UNDERFLOW, "Stack Underflow", 166 GL_OUT_OF_MEMORY, "Out of Memory" 167 }; 168 #endif 169 170 #if 0 171 #define OGL_FAIL_ON_ERROR(x) \ 172 { \ 173 GLenum err; \ 174 int iI; \ 175 \ 176 while((err = glGetError()) != GL_NO_ERROR) \ 177 { \ 178 for(iI = 0; iI < 6; iI++) \ 179 if(_errorList[iI].code == err) break; \ 180 printf("libGL error : %s() : %d(%s)\n",#x, \ 181 err, (iI > 5) ? "Unknown Error" : _errorList[iI].str); \ 182 } \ 183 } 184 #else 185 #define OGL_FAIL_ON_ERROR(x) 186 #endif 187 188 #define CHECK_RASTER_POS() \ 189 { \ 190 GLfloat pos[4]; \ 191 GLboolean valid; \ 192 \ 193 DEBUG_CALL((glGetFloatv (GL_CURRENT_RASTER_POSITION, pos))); \ 194 DEBUG_CALL((glGetBooleanv (GL_CURRENT_RASTER_POSITION_VALID, &valid))); \ 195 PRINT(("current raster position (%f, %f %f, %f) is %d", pos[0], \ 196 pos[1], pos[2], pos[3], valid)); \ 197 } 198 #else 199 #define OGL_FAIL_ON_ERROR(x) 200 #define CHECK_RASTER_POS() 201 #endif 202 203 /* 204 * World-to-screen utility macros. 205 */ 206 #define SET_WORLD_SCREEN(w, h) \ 207 { \ 208 GLfloat M[4][4] ; \ 209 \ 210 ENTRY(("SET_WORLD_SCREEN(%d, %d)", w, h)); \ 211 \ 212 glViewport (0, 0, w, h) ; \ 213 \ 214 WS[0][0] = 2.0 / ((w-1) + 0.5) ; \ 215 WS[1][1] = 2.0 / ((h-1) + 0.5) ; \ 216 glMatrixMode(GL_PROJECTION) ; \ 217 glLoadMatrixf((float *)WS) ; \ 218 \ 219 glMatrixMode(GL_MODELVIEW) ; \ 220 glLoadIdentity() ; \ 221 \ 222 DEBUG_CALL((glGetFloatv(GL_PROJECTION_MATRIX,(GLfloat *)M))); \ 223 PRINT(("\"%s\"","projection matrix")); \ 224 MPRINT(M) ; \ 225 DEBUG_CALL((glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)M))); \ 226 PRINT(("\"%s\"","model-view matrix")); \ 227 MPRINT(M) ; \ 228 EXIT(("")); \ 229 } 230 231 #define SET_RASTER_SCREEN(llx, lly) \ 232 { \ 233 ENTRY(("SET_RASTER_SCREEN(%d, %d)", llx, lly)); \ 234 \ 235 glPushAttrib(GL_VIEWPORT_BIT) ; \ 236 glMatrixMode(GL_MODELVIEW) ; \ 237 glPushMatrix() ; \ 238 \ 239 glMatrixMode(GL_PROJECTION) ; \ 240 glPushMatrix() ; \ 241 \ 242 SET_WORLD_SCREEN (WINWIDTH, WINHEIGHT) ; \ 243 \ 244 /* OpenGL transforms raster position by model/view/projection */ \ 245 PRINT(("calling glRasterPos2i(%d, %d)", llx, lly)); \ 246 \ 247 glRasterPos2i (llx, lly) ; \ 248 \ 249 glMatrixMode(GL_PROJECTION) ; \ 250 glPopMatrix() ; \ 251 glMatrixMode(GL_MODELVIEW) ; \ 252 glPopMatrix() ; \ 253 glPopAttrib() ; \ 254 \ 255 CHECK_RASTER_POS(); \ 256 EXIT(("")); \ 257 } 258 259 #if defined(DXHW_UselessCycles) 260 261 #define Apply(poi, mat, res) \ 262 { \ 263 res[0] = mat[0][0] * poi[0] + mat[1][0] * poi[1] + mat[2][0] * poi[2]; \ 264 res[1] = mat[0][1] * poi[0] + mat[1][1] * poi[1] + mat[2][1] * poi[2]; \ 265 res[2] = mat[0][2] * poi[0] + mat[1][2] * poi[1] + mat[2][2] * poi[2]; \ 266 } 267 268 #else 269 270 #define Apply(poi, mat, res) \ 271 res[2] = mat[0][2] * poi[0] + mat[1][2] * poi[1] + mat[2][2] * poi[2]; 272 273 #endif 274 275 #endif /* tdmPortOGL_h */ 276