|
|
1.1 root 1: /* 1.1.1.2 ! root 2: Copyright (C) 1997-2001 Id Software, Inc. ! 3: ! 4: This program is free software; you can redistribute it and/or ! 5: modify it under the terms of the GNU General Public License ! 6: as published by the Free Software Foundation; either version 2 ! 7: of the License, or (at your option) any later version. ! 8: ! 9: This program is distributed in the hope that it will be useful, ! 10: but WITHOUT ANY WARRANTY; without even the implied warranty of ! 11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! 12: ! 13: See the GNU General Public License for more details. ! 14: ! 15: You should have received a copy of the GNU General Public License ! 16: along with this program; if not, write to the Free Software ! 17: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! 18: ! 19: */ ! 20: /* 1.1 root 21: ** GLW_IMP.C 22: ** 23: ** This file contains ALL Linux specific stuff having to do with the 24: ** OpenGL refresh. When a port is being made the following functions 25: ** must be implemented by the port: 26: ** 27: ** GLimp_EndFrame 28: ** GLimp_Init 29: ** GLimp_Shutdown 30: ** GLimp_SwitchFullscreen 31: ** 32: */ 33: 34: #include <termios.h> 35: #include <sys/ioctl.h> 36: #include <sys/stat.h> 37: #include <sys/vt.h> 38: #include <stdarg.h> 39: #include <stdio.h> 40: #include <signal.h> 41: 42: #include "../ref_gl/gl_local.h" 43: #include "../client/keys.h" 44: #include "../linux/rw_linux.h" 45: 1.1.1.2 ! root 46: #include "../linux/glw_linux.h" ! 47: 1.1 root 48: #include <GL/fxmesa.h> 49: 50: /*****************************************************************************/ 51: 1.1.1.2 ! root 52: glwstate_t glw_state; ! 53: 1.1 root 54: static qboolean GLimp_SwitchFullscreen( int width, int height ); 55: qboolean GLimp_InitGL (void); 56: 57: extern cvar_t *vid_fullscreen; 58: extern cvar_t *vid_ref; 59: 60: static fxMesaContext fc = NULL; 61: 1.1.1.2 ! root 62: #define NUM_RESOLUTIONS 16 1.1 root 63: 64: static resolutions[NUM_RESOLUTIONS][3]={ 1.1.1.2 ! root 65: { 320,200, GR_RESOLUTION_320x200 }, ! 66: { 320,240, GR_RESOLUTION_320x240 }, ! 67: { 400,256, GR_RESOLUTION_400x256 }, ! 68: { 400,300, GR_RESOLUTION_400x300 }, ! 69: { 512,384, GR_RESOLUTION_512x384 }, ! 70: { 640,200, GR_RESOLUTION_640x200 }, ! 71: { 640,350, GR_RESOLUTION_640x350 }, ! 72: { 640,400, GR_RESOLUTION_640x400 }, ! 73: { 640,480, GR_RESOLUTION_640x480 }, ! 74: { 800,600, GR_RESOLUTION_800x600 }, ! 75: { 960,720, GR_RESOLUTION_960x720 }, ! 76: { 856,480, GR_RESOLUTION_856x480 }, ! 77: { 512,256, GR_RESOLUTION_512x256 }, ! 78: { 1024,768, GR_RESOLUTION_1024x768 }, ! 79: { 1280,1024,GR_RESOLUTION_1280x1024 }, ! 80: { 1600,1200,GR_RESOLUTION_1600x1200 } 1.1 root 81: }; 82: 83: static int findres(int *width, int *height) 84: { 85: int i; 86: 87: for(i=0;i<NUM_RESOLUTIONS;i++) 88: if((*width<=resolutions[i][0]) && (*height<=resolutions[i][1])) { 89: *width = resolutions[i][0]; 90: *height = resolutions[i][1]; 91: return resolutions[i][2]; 92: } 93: 94: *width = 640; 95: *height = 480; 96: return GR_RESOLUTION_640x480; 97: } 98: 99: static void signal_handler(int sig) 100: { 101: printf("Received signal %d, exiting...\n", sig); 102: GLimp_Shutdown(); 103: _exit(0); 104: } 105: 106: static void InitSig(void) 107: { 108: signal(SIGHUP, signal_handler); 109: signal(SIGQUIT, signal_handler); 110: signal(SIGILL, signal_handler); 111: signal(SIGTRAP, signal_handler); 112: signal(SIGIOT, signal_handler); 113: signal(SIGBUS, signal_handler); 114: signal(SIGFPE, signal_handler); 115: signal(SIGSEGV, signal_handler); 116: signal(SIGTERM, signal_handler); 117: } 118: 119: /* 120: ** GLimp_SetMode 121: */ 122: int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen ) 123: { 124: int width, height; 125: GLint attribs[32]; 126: 127: ri.Con_Printf( PRINT_ALL, "Initializing OpenGL display\n"); 128: 129: ri.Con_Printf (PRINT_ALL, "...setting mode %d:", mode ); 130: 131: if ( !ri.Vid_GetModeInfo( &width, &height, mode ) ) 132: { 133: ri.Con_Printf( PRINT_ALL, " invalid mode\n" ); 134: return rserr_invalid_mode; 135: } 136: 137: ri.Con_Printf( PRINT_ALL, " %d %d\n", width, height ); 138: 139: // destroy the existing window 140: GLimp_Shutdown (); 141: 142: // set fx attribs 143: attribs[0] = FXMESA_DOUBLEBUFFER; 144: attribs[1] = FXMESA_ALPHA_SIZE; 145: attribs[2] = 1; 146: attribs[3] = FXMESA_DEPTH_SIZE; 147: attribs[4] = 1; 148: attribs[5] = FXMESA_NONE; 149: 1.1.1.2 ! root 150: fc = qfxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz, 1.1 root 151: attribs); 152: if (!fc) 153: return rserr_invalid_mode; 154: 155: *pwidth = width; 156: *pheight = height; 157: 158: // let the sound and input subsystems know about the new window 159: ri.Vid_NewWindow (width, height); 160: 1.1.1.2 ! root 161: qfxMesaMakeCurrent(fc); 1.1 root 162: 163: return rserr_ok; 164: } 165: 166: /* 167: ** GLimp_Shutdown 168: ** 169: ** This routine does all OS specific shutdown procedures for the OpenGL 170: ** subsystem. Under OpenGL this means NULLing out the current DC and 171: ** HGLRC, deleting the rendering context, and releasing the DC acquired 172: ** for the window. The state structure is also nulled out. 173: ** 174: */ 175: void GLimp_Shutdown( void ) 176: { 177: if (fc) { 1.1.1.2 ! root 178: qfxMesaDestroyContext(fc); 1.1 root 179: fc = NULL; 180: } 181: } 182: 183: /* 184: ** GLimp_Init 185: ** 186: ** This routine is responsible for initializing the OS specific portions 187: ** of OpenGL. 188: */ 189: int GLimp_Init( void *hinstance, void *wndproc ) 190: { 191: InitSig(); 192: 193: return true; 194: } 195: 196: /* 197: ** GLimp_BeginFrame 198: */ 199: void GLimp_BeginFrame( float camera_seperation ) 200: { 201: } 202: 203: /* 204: ** GLimp_EndFrame 205: ** 206: ** Responsible for doing a swapbuffers and possibly for other stuff 207: ** as yet to be determined. Probably better not to make this a GLimp 208: ** function and instead do a call to GLimp_SwapBuffers. 209: */ 210: void GLimp_EndFrame (void) 211: { 1.1.1.2 ! root 212: qglFlush(); ! 213: qfxMesaSwapBuffers(); 1.1 root 214: } 215: 216: /* 217: ** GLimp_AppActivate 218: */ 219: void GLimp_AppActivate( qboolean active ) 220: { 221: } 222: 223: void Fake_glColorTableEXT( GLenum target, GLenum internalformat, 224: GLsizei width, GLenum format, GLenum type, 225: const GLvoid *table ) 226: { 227: byte temptable[256][4]; 228: byte *intbl; 229: int i; 230: 231: for (intbl = (byte *)table, i = 0; i < 256; i++) { 232: temptable[i][2] = *intbl++; 233: temptable[i][1] = *intbl++; 234: temptable[i][0] = *intbl++; 235: temptable[i][3] = 255; 236: } 1.1.1.2 ! root 237: qglEnable( GL_SHARED_TEXTURE_PALETTE_EXT ); ! 238: qgl3DfxSetPaletteEXT((GLuint *)temptable); 1.1 root 239: } 240:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.