28 #include "../../idlib/precompiled.h" 
   29 #include "../../renderer/tr_local.h" 
   32 #include <sys/types.h> 
   44 static int scrnum = 0;
 
   50 static GLXContext ctx = 
NULL;
 
   52 static bool vidmode_ext = 
false;
 
   53 static int vidmode_MajorVersion = 0, vidmode_MinorVersion = 0;  
 
   55 static XF86VidModeModeInfo **vidmodes;
 
   56 static int num_vidmodes;
 
   57 static bool vidmode_active = 
false;
 
   60 static int save_rampsize = 0;
 
   61 static unsigned short *save_red, *save_green, *save_blue;
 
   72                 common->
DPrintf(
"GLimp_EnableLogging - disabled at compile time (ID_GL_HARDLINK)\n");
 
   95         qglXMakeCurrent( 
dpy, 
win, ctx );
 
  100         qglXMakeCurrent( 
dpy, None, 
NULL );
 
  111         if ( save_rampsize ) {
 
  117         XF86VidModeGetGammaRampSize( 
dpy, scrnum, &save_rampsize);
 
  118         save_red = (
unsigned short *)malloc(save_rampsize*
sizeof(
unsigned short));
 
  119         save_green = (
unsigned short *)malloc(save_rampsize*
sizeof(
unsigned short));
 
  120         save_blue = (
unsigned short *)malloc(save_rampsize*
sizeof(
unsigned short));
 
  121         XF86VidModeGetGammaRamp( 
dpy, scrnum, save_rampsize, save_red, save_green, save_blue);
 
  135         XF86VidModeSetGammaRamp( 
dpy, scrnum, save_rampsize, save_red, save_green, save_blue);
 
  137         free(save_red); free(save_green); free(save_blue);
 
  154                 XF86VidModeGetGammaRampSize( 
dpy, scrnum, &size);
 
  159                         unsigned short *l_red, *l_green, *l_blue;
 
  160                         l_red = (
unsigned short *)malloc(size*
sizeof(
unsigned short));
 
  161                         l_green = (
unsigned short *)malloc(size*
sizeof(
unsigned short));
 
  162                         l_blue = (
unsigned short *)malloc(size*
sizeof(
unsigned short));
 
  165                         for(i=0; i<size-1; i++) {
 
  166                                 r_f = (
float)i*255.0
f/(
float)(size-1);
 
  167                                 r_i = (
int)floor(r_f);
 
  169                                 l_red[
i] = (
int)round((1.0
f-r_f)*(
float)red[r_i]+r_f*(
float)red[r_i+1]);
 
  170                                 l_green[
i] = (
int)round((1.0
f-r_f)*(
float)green[r_i]+r_f*(
float)green[r_i+1]);
 
  171                                 l_blue[
i] = (
int)round((1.0
f-r_f)*(
float)blue[r_i]+r_f*(
float)blue[r_i+1]);                             
 
  173                         l_red[size-1] = red[255]; l_green[size-1] = green[255]; l_blue[size-1] = blue[255];
 
  174                         XF86VidModeSetGammaRamp( 
dpy, scrnum, size, l_red, l_green, l_blue );
 
  175                         free(l_red); free(l_green); free(l_blue);
 
  177                         XF86VidModeSetGammaRamp( 
dpy, scrnum, size, red, green, blue );
 
  189                 qglXDestroyContext( 
dpy, ctx );
 
  191 #if !defined( ID_GL_HARDLINK ) 
  195                 XDestroyWindow( 
dpy, 
win );
 
  196                 if ( vidmode_active ) {
 
  197                         XF86VidModeSwitchToMode( 
dpy, scrnum, vidmodes[0] );
 
  205                 vidmode_active = 
false;
 
  214         qglXSwapBuffers( 
dpy, 
win );
 
  222         int dga_MajorVersion = 0, dga_MinorVersion = 0;
 
  226 #if defined( ID_ENABLE_DGA ) 
  227         if ( !XF86DGAQueryVersion( 
dpy, &dga_MajorVersion, &dga_MinorVersion ) ) {
 
  229                 common->
Printf( 
"Failed to detect DGA DirectVideo Mouse\n" );
 
  233                 common->
Printf( 
"DGA DirectVideo Mouse (Version %d.%d) initialized\n",
 
  234                                    dga_MajorVersion, dga_MinorVersion );
 
  252         common->
Printf( 
"  Major opcode of failed request: %d\n", ev->request_code );
 
  253         common->
Printf( 
"  Minor opcode of failed request: %d\n", ev->minor_code );
 
  254         common->
Printf( 
"  Serial number of failed request: %lu\n", ev->serial );
 
  255         XGetErrorText( l_dpy, ev->error_code, buf, 1024 );
 
  266                 common->
DPrintf( 
"not opening the display: dedicated server\n" );
 
  273         if ( !XInitThreads() ) {
 
  281         if ( !( 
dpy = XOpenDisplay(
NULL) ) ) {
 
  285         scrnum = DefaultScreen( 
dpy );
 
  307 #define ATTR_RED_IDX 2 
  308 #define ATTR_GREEN_IDX 4 
  309 #define ATTR_BLUE_IDX 6 
  310 #define ATTR_DEPTH_IDX 9 
  311 #define ATTR_STENCIL_IDX 11 
  312 #define ATTR_ALPHA_IDX 13 
  314         XVisualInfo *visinfo;
 
  315         XSetWindowAttributes attr;
 
  316         XSizeHints sizehints;
 
  318         int colorbits, depthbits, stencilbits;
 
  319         int tcolorbits, tdepthbits, tstencilbits;
 
  320         int actualWidth, actualHeight;
 
  322         const char *glstring;
 
  330         root = RootWindow( 
dpy, scrnum );
 
  336         if ( !XF86VidModeQueryVersion( 
dpy, &vidmode_MajorVersion, &vidmode_MinorVersion ) ) {
 
  338                 common->
Printf(
"XFree86-VidModeExtension not available\n");
 
  341                 common->
Printf(
"Using XFree86-VidModeExtension Version %d.%d\n",
 
  342                                    vidmode_MajorVersion, vidmode_MinorVersion);
 
  348                 int best_fit, best_dist, dist, 
x, 
y;
 
  350                 XF86VidModeGetAllModeLines( 
dpy, scrnum, &num_vidmodes, &vidmodes );
 
  357                         for (i = 0; i < num_vidmodes; i++) {
 
  358                                 if (a.
width > vidmodes[i]->hdisplay ||
 
  359                                         a.
height > vidmodes[i]->vdisplay)
 
  362                                 x = a.
width - vidmodes[
i]->hdisplay;
 
  363                                 y = a.
height - vidmodes[
i]->vdisplay;
 
  364                                 dist = (x * 
x) + (y * y);
 
  365                                 if (dist < best_dist) {
 
  371                         if (best_fit != -1) {
 
  372                                 actualWidth = vidmodes[best_fit]->hdisplay;
 
  373                                 actualHeight = vidmodes[best_fit]->vdisplay;
 
  376                                 XF86VidModeSwitchToMode(
dpy, scrnum, vidmodes[best_fit]);
 
  377                                 vidmode_active = 
true;
 
  381                                 XF86VidModeSetViewPort(
dpy, scrnum, 0, 0);
 
  383                                 common->
Printf( 
"Free86-VidModeExtension Activated at %dx%d\n", actualWidth, actualHeight );
 
  387                                 common->
Printf( 
"Free86-VidModeExtension: No acceptable modes found\n" );
 
  390                         common->
Printf( 
"XFree86-VidModeExtension: not fullscreen, ignored\n" );
 
  398         for (i = 0; i < 16; i++) {
 
  403                 if ((i % 4) == 0 && i) {
 
  413                                 else if (depthbits == 16)
 
  416                                 if (stencilbits == 24)
 
  418                                 else if (stencilbits == 16)
 
  423                 tcolorbits = colorbits;
 
  424                 tdepthbits = depthbits;
 
  425                 tstencilbits = stencilbits;
 
  428                         if (tcolorbits == 24)
 
  433                         if (tdepthbits == 24)
 
  435                         else if (tdepthbits == 16)
 
  440                         if (tstencilbits == 24)
 
  442                         else if (tstencilbits == 16)
 
  448                 if (tcolorbits == 24) {
 
  462                 visinfo = qglXChooseVisual(
dpy, scrnum, attrib);
 
  467                 common->
Printf( 
"Using %d/%d/%d Color bits, %d Alpha bits, %d depth, %d stencil display.\n",
 
  484         attr.background_pixel = BlackPixel(
dpy, scrnum);
 
  485         attr.border_pixel = 0;
 
  486         attr.colormap = XCreateColormap(
dpy, root, visinfo->visual, AllocNone);
 
  488         if (vidmode_active) {
 
  489                 mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore |
 
  490                         CWEventMask | CWOverrideRedirect;
 
  491                 attr.override_redirect = True;
 
  492                 attr.backing_store = NotUseful;
 
  493                 attr.save_under = False;
 
  495                 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
 
  498         win = XCreateWindow(
dpy, root, 0, 0,
 
  499                                                 actualWidth, actualHeight,
 
  500                                                 0, visinfo->depth, InputOutput,
 
  501                                                 visinfo->visual, mask, &attr);
 
  507         sizehints.flags = PMinSize | PMaxSize;
 
  508         sizehints.min_width = sizehints.max_width = actualWidth;
 
  509         sizehints.min_height = sizehints.max_height = actualHeight;
 
  511         XSetWMNormalHints(
dpy, 
win, &sizehints);
 
  515         if ( vidmode_active ) {
 
  516                 XMoveWindow( 
dpy, 
win, 0, 0 );
 
  521         ctx = qglXCreateContext(
dpy, visinfo, 
NULL, True);
 
  527         qglXMakeCurrent(
dpy, 
win, ctx);
 
  567 #ifndef ID_GL_HARDLINK 
  598         static int run_once = 0;
 
  599         int major, minor, 
value;
 
  613         common->
Printf( 
"guessing video ram ( use +set sys_videoRam to force ) ..\n" );
 
  622                 common->
Printf( 
"found XNVCtrl extension %d.%d\n", major, minor );
 
  625                                 run_once = value / 1024;
 
  628                                 common->
Printf( 
"XNVCtrlQueryAttribute NV_CTRL_VIDEO_RAM failed\n" );
 
  631                         common->
Printf( 
"default screen %d is not controlled by NVIDIA driver\n", l_scrnum );
 
  636         if ( ( fd = open( 
"/proc/dri/0/umm", 
O_RDONLY ) ) != -1 ) {
 
  638                 char umm_buf[ 1024 ];
 
  640                 if ( ( len = read( fd, umm_buf, 1024 ) ) != -1 ) {
 
  643                         umm_buf[ len-1 ] = 
'\0';
 
  645                         line = strtok( umm_buf, 
"\n" );
 
  648                                 if ( strlen( line ) >= 13 && strstr( line, 
"max   LFB =" ) == line ) {
 
  649                                         total += atoi( line + 12 );
 
  650                                 } 
else if ( strlen( line ) >= 13 && strstr( line, 
"max   Inv =" ) == line ) {
 
  651                                         total += atoi( line + 12 );
 
  653                                 line = strtok( 
NULL, 
"\n" );
 
  656                                 run_once = total / 1048576;
 
  662                         common->
Printf( 
"read /proc/dri/0/umm failed: %s\n", strerror( errno ) );
 
  665         common->
Printf( 
"guess failed, return default low-end VRAM setting ( 64MB VRAM )\n" );
 
void GLimp_ActivateContext()
 
GLsizei const GLfloat * value
 
bool GLimp_SetScreenParms(glimpParms_t parms)
 
void GLimp_SetGamma(unsigned short red[256], unsigned short green[256], unsigned short blue[256])
 
assert(prefInfo.fullscreenBtn)
 
idCVarSystem * cvarSystem
 
int Sys_GetVideoRam(void)
 
bool GLimp_Init(glimpParms_t a)
 
#define NV_CTRL_VIDEO_RAM
 
virtual int GetCVarInteger(const char *name) const =0
 
int GLX_Init(glimpParms_t a)
 
idCVar sys_videoRam("sys_videoRam","0", CVAR_SYSTEM|CVAR_ARCHIVE|CVAR_INTEGER,"Texture memory on the video card (in megabytes) - 0: autodetect", 0, 512)
 
void GLimp_WakeBackEnd(void *a)
 
void * GLimp_BackEndSleep()
 
virtual void SetCVarBool(const char *name, const bool value, int flags=0)=0
 
int GetInteger(void) const 
 
void GLimp_RestoreGamma()
 
void GLimp_FrontEndSleep()
 
GLubyte GLubyte GLubyte a
 
virtual void Printf(const char *fmt,...) id_attribute((format(printf
 
void GLimp_EnableLogging(bool enable)
 
int idXErrorHandler(Display *l_dpy, XErrorEvent *ev)
 
Bool XNVCTRLQueryVersion(Display *dpy, int *major, int *minor)
 
Bool XNVCTRLQueryAttribute(Display *dpy, int screen, unsigned int display_mask, unsigned int attribute, int *value)
 
bool GLimp_SpawnRenderThread(void(*a)())
 
Bool XNVCTRLIsNvScreen(Display *dpy, int screen)
 
virtual void DPrintf(const char *fmt,...) id_attribute((format(printf
 
void GLimp_DeactivateContext()
 
bool GLimp_OpenDisplay(void)
 
void Sys_GrabMouseCursor(bool)