gl_fxmesa.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. ** GLW_IMP.C
  3. **
  4. ** This file contains ALL Linux specific stuff having to do with the
  5. ** OpenGL refresh. When a port is being made the following functions
  6. ** must be implemented by the port:
  7. **
  8. ** GLimp_EndFrame
  9. ** GLimp_Init
  10. ** GLimp_Shutdown
  11. ** GLimp_SwitchFullscreen
  12. **
  13. */
  14. #include <termios.h>
  15. #include <sys/ioctl.h>
  16. #include <sys/stat.h>
  17. #include <sys/vt.h>
  18. #include <stdarg.h>
  19. #include <stdio.h>
  20. #include <signal.h>
  21. #include "../ref_gl/gl_local.h"
  22. #include "../client/keys.h"
  23. #include "../linux/rw_linux.h"
  24. #include <GL/fxmesa.h>
  25. /*****************************************************************************/
  26. static qboolean GLimp_SwitchFullscreen( int width, int height );
  27. qboolean GLimp_InitGL (void);
  28. extern cvar_t *vid_fullscreen;
  29. extern cvar_t *vid_ref;
  30. static fxMesaContext fc = NULL;
  31. #define NUM_RESOLUTIONS 3
  32. static resolutions[NUM_RESOLUTIONS][3]={
  33. { 512, 384, GR_RESOLUTION_512x384 },
  34. { 640, 400, GR_RESOLUTION_640x400 },
  35. { 640, 480, GR_RESOLUTION_640x480 }
  36. };
  37. static int findres(int *width, int *height)
  38. {
  39. int i;
  40. for(i=0;i<NUM_RESOLUTIONS;i++)
  41. if((*width<=resolutions[i][0]) && (*height<=resolutions[i][1])) {
  42. *width = resolutions[i][0];
  43. *height = resolutions[i][1];
  44. return resolutions[i][2];
  45. }
  46. *width = 640;
  47. *height = 480;
  48. return GR_RESOLUTION_640x480;
  49. }
  50. static void signal_handler(int sig)
  51. {
  52. printf("Received signal %d, exiting...\n", sig);
  53. GLimp_Shutdown();
  54. _exit(0);
  55. }
  56. static void InitSig(void)
  57. {
  58. signal(SIGHUP, signal_handler);
  59. signal(SIGQUIT, signal_handler);
  60. signal(SIGILL, signal_handler);
  61. signal(SIGTRAP, signal_handler);
  62. signal(SIGIOT, signal_handler);
  63. signal(SIGBUS, signal_handler);
  64. signal(SIGFPE, signal_handler);
  65. signal(SIGSEGV, signal_handler);
  66. signal(SIGTERM, signal_handler);
  67. }
  68. /*
  69. ** GLimp_SetMode
  70. */
  71. int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
  72. {
  73. int width, height;
  74. GLint attribs[32];
  75. ri.Con_Printf( PRINT_ALL, "Initializing OpenGL display\n");
  76. ri.Con_Printf (PRINT_ALL, "...setting mode %d:", mode );
  77. if ( !ri.Vid_GetModeInfo( &width, &height, mode ) )
  78. {
  79. ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
  80. return rserr_invalid_mode;
  81. }
  82. ri.Con_Printf( PRINT_ALL, " %d %d\n", width, height );
  83. // destroy the existing window
  84. GLimp_Shutdown ();
  85. // set fx attribs
  86. attribs[0] = FXMESA_DOUBLEBUFFER;
  87. attribs[1] = FXMESA_ALPHA_SIZE;
  88. attribs[2] = 1;
  89. attribs[3] = FXMESA_DEPTH_SIZE;
  90. attribs[4] = 1;
  91. attribs[5] = FXMESA_NONE;
  92. fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
  93. attribs);
  94. if (!fc)
  95. return rserr_invalid_mode;
  96. *pwidth = width;
  97. *pheight = height;
  98. // let the sound and input subsystems know about the new window
  99. ri.Vid_NewWindow (width, height);
  100. fxMesaMakeCurrent(fc);
  101. return rserr_ok;
  102. }
  103. /*
  104. ** GLimp_Shutdown
  105. **
  106. ** This routine does all OS specific shutdown procedures for the OpenGL
  107. ** subsystem. Under OpenGL this means NULLing out the current DC and
  108. ** HGLRC, deleting the rendering context, and releasing the DC acquired
  109. ** for the window. The state structure is also nulled out.
  110. **
  111. */
  112. void GLimp_Shutdown( void )
  113. {
  114. if (fc) {
  115. fxMesaDestroyContext(fc);
  116. fc = NULL;
  117. }
  118. }
  119. /*
  120. ** GLimp_Init
  121. **
  122. ** This routine is responsible for initializing the OS specific portions
  123. ** of OpenGL.
  124. */
  125. int GLimp_Init( void *hinstance, void *wndproc )
  126. {
  127. InitSig();
  128. return true;
  129. }
  130. /*
  131. ** GLimp_BeginFrame
  132. */
  133. void GLimp_BeginFrame( float camera_seperation )
  134. {
  135. }
  136. /*
  137. ** GLimp_EndFrame
  138. **
  139. ** Responsible for doing a swapbuffers and possibly for other stuff
  140. ** as yet to be determined. Probably better not to make this a GLimp
  141. ** function and instead do a call to GLimp_SwapBuffers.
  142. */
  143. void GLimp_EndFrame (void)
  144. {
  145. glFlush();
  146. fxMesaSwapBuffers();
  147. }
  148. /*
  149. ** GLimp_AppActivate
  150. */
  151. void GLimp_AppActivate( qboolean active )
  152. {
  153. }
  154. extern void gl3DfxSetPaletteEXT(GLuint *pal);
  155. void Fake_glColorTableEXT( GLenum target, GLenum internalformat,
  156. GLsizei width, GLenum format, GLenum type,
  157. const GLvoid *table )
  158. {
  159. byte temptable[256][4];
  160. byte *intbl;
  161. int i;
  162. for (intbl = (byte *)table, i = 0; i < 256; i++) {
  163. temptable[i][2] = *intbl++;
  164. temptable[i][1] = *intbl++;
  165. temptable[i][0] = *intbl++;
  166. temptable[i][3] = 255;
  167. }
  168. gl3DfxSetPaletteEXT((GLuint *)temptable);
  169. }