From: havoc Date: Fri, 27 Sep 2002 07:30:05 +0000 (+0000) Subject: stencil is now supported (optional, off by default, use vid_stencil to enable) X-Git-Tag: RELEASE_0_2_0_RC1~189 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1f7e4ae8b04d68b88f1c63c87a6b819b2a4a76f6;p=xonotic%2Fdarkplaces.git stencil is now supported (optional, off by default, use vid_stencil to enable) vid_ cvars are updated when VID_Mode succeeds GL stencil functions enabled git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2452 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/glquake.h b/glquake.h index d9ce90ee..120da2c9 100644 --- a/glquake.h +++ b/glquake.h @@ -348,10 +348,10 @@ extern void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z); extern void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); -//extern void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask); -//extern void (GLAPIENTRY *qglStencilMask)(GLuint mask); -//extern void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass); -//extern void (GLAPIENTRY *qglClearStencil)(GLint s); +extern void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask); +extern void (GLAPIENTRY *qglStencilMask)(GLuint mask); +extern void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass); +extern void (GLAPIENTRY *qglClearStencil)(GLint s); //extern void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param); extern void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param); diff --git a/makefile b/makefile index 09a468c9..8c487a92 100644 --- a/makefile +++ b/makefile @@ -39,9 +39,9 @@ SHAREDOBJECTS= builddate.o cmd.o collision.o common.o crc.o cvar.o filematch.o h CPUOPTIMIZATIONS= #use this line for profiling -#PROFILEOPTION=-pg -g +PROFILEOPTION=-pg -g #use this line for no profiling -PROFILEOPTION= +#PROFILEOPTION= #note: #the -Werror can be removed to compile even if there are warnings, diff --git a/vid.h b/vid.h index 0b83a027..e892b80a 100644 --- a/vid.h +++ b/vid.h @@ -49,6 +49,9 @@ extern cvar_t vid_width; extern cvar_t vid_height; extern cvar_t vid_bitsperpixel; extern cvar_t vid_mouse; +extern cvar_t vid_stencil; + +extern int gl_stencil; // brand of graphics chip extern const char *gl_vendor; @@ -101,7 +104,6 @@ void GL_Init (void); void VID_CheckExtensions(void); void VID_Init (void); -int VID_Mode(int fullscreen, int width, int height, int bpp); // Called at startup void VID_Shutdown (void); diff --git a/vid_glx.c b/vid_glx.c index 50a12966..6ccbbc2a 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -645,39 +645,35 @@ void VID_Init(void) mouse_avail = false; } -int VID_InitMode(int fullscreen, int width, int height, int bpp) +void VID_BuildGLXAttrib(int *attrib, int stencil, int gamma) { - int i; -// LordHavoc: FIXME: finish this code, we need to allocate colors before we can store them -#if 0 - int gammaattrib[] = + *attrib++ = GLX_RGBA; + *attrib++ = GLX_RED_SIZE;*attrib++ = 1; + *attrib++ = GLX_GREEN_SIZE;*attrib++ = 1; + *attrib++ = GLX_BLUE_SIZE;*attrib++ = 1; + *attrib++ = GLX_DOUBLEBUFFER; + *attrib++ = GLX_DEPTH_SIZE;*attrib++ = 1; + if (stencil) { - GLX_RGBA, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - GLX_DOUBLEBUFFER, - GLX_DEPTH_SIZE, 1, - GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR, - None - }; -#endif - int nogammaattrib[] = + *attrib++ = GLX_STENCIL_SIZE;*attrib++ = 8; + } + if (gamma) { - GLX_RGBA, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - GLX_DOUBLEBUFFER, - GLX_DEPTH_SIZE, 1, - None + *attrib++ = GLX_X_VISUAL_TYPE;*attrib++ = GLX_DIRECT_COLOR; }; + *attrib++ = None; +} + +int VID_InitMode(int fullscreen, int width, int height, int bpp, int stencil) +{ + int i; + int attrib[32]; XSetWindowAttributes attr; unsigned long mask; Window root; XVisualInfo *visinfo; int MajorVersion, MinorVersion; - + if (!GL_OpenLibrary("libGL.so.1")) { Con_Printf("Unable to load GL driver\n"); @@ -717,11 +713,15 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp) // LordHavoc: FIXME: finish this code, we need to allocate colors before we can store them #if 0 if (!COM_CheckParm("-nogamma")) - visinfo = qglXChooseVisual(vidx11_display, scrnum, gammaattrib); + { + VID_BuildGLXAttrib(attrib, stencil, true); + visinfo = qglXChooseVisual(vidx11_display, scrnum, attrib); + } #endif if (!visinfo) { - visinfo = qglXChooseVisual(vidx11_display, scrnum, nogammaattrib); + VID_BuildGLXAttrib(attrib, stencil, false); + visinfo = qglXChooseVisual(vidx11_display, scrnum, attrib); if (!visinfo) { Con_Printf("Couldn't get an RGB, Double-buffered, Depth visual\n"); diff --git a/vid_null.c b/vid_null.c index 5505ea67..3492943d 100644 --- a/vid_null.c +++ b/vid_null.c @@ -69,7 +69,7 @@ void VID_Init(void) InitSig(); // trap evil signals } -int VID_InitMode(int fullscreen, int width, int height, int bpp) +int VID_InitMode(int fullscreen, int width, int height, int bpp, int stencil) { return false; } diff --git a/vid_shared.c b/vid_shared.c index 6fb1f5c0..0806ce06 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -16,6 +16,8 @@ int gl_combine_extension = false; int gl_supportslockarrays = false; // LordHavoc: GLX_SGI_video_sync and WGL_EXT_swap_control int gl_videosyncavailable = false; +// indicates that stencil is available +int gl_stencil = false; // LordHavoc: if window is hidden, don't update screen int vid_hidden = true; @@ -27,6 +29,7 @@ cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"}; cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"}; cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"}; cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "16"}; +cvar_t vid_stencil = {CVAR_SAVE, "vid_stencil", "0"}; cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"}; cvar_t gl_combine = {0, "gl_combine", "1"}; @@ -131,10 +134,10 @@ void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z); void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); -//void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask); -//void (GLAPIENTRY *qglStencilMask)(GLuint mask); -//void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass); -//void (GLAPIENTRY *qglClearStencil)(GLint s); +void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask); +void (GLAPIENTRY *qglStencilMask)(GLuint mask); +void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass); +void (GLAPIENTRY *qglClearStencil)(GLint s); //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param); void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param); @@ -250,10 +253,10 @@ static gl_extensionfunctionlist_t opengl110funcs[] = // {"glTranslated", (void **) &qglTranslated}, {"glTranslatef", (void **) &qglTranslatef}, {"glReadPixels", (void **) &qglReadPixels}, -// {"glStencilFunc", (void **) &qglStencilFunc}, -// {"glStencilMask", (void **) &qglStencilMask}, -// {"glStencilOp", (void **) &qglStencilOp}, -// {"glClearStencil", (void **) &qglClearStencil}, + {"glStencilFunc", (void **) &qglStencilFunc}, + {"glStencilMask", (void **) &qglStencilMask}, + {"glStencilOp", (void **) &qglStencilOp}, + {"glClearStencil", (void **) &qglClearStencil}, // {"glTexEnvf", (void **) &qglTexEnvf}, {"glTexEnvi", (void **) &qglTexEnvi}, // {"glTexParameterf", (void **) &qglTexParameterf}, @@ -401,6 +404,7 @@ void VID_Shared_Init(void) Cvar_RegisterVariable(&vid_width); Cvar_RegisterVariable(&vid_height); Cvar_RegisterVariable(&vid_bitsperpixel); + Cvar_RegisterVariable(&vid_stencil); Cvar_RegisterVariable(&vid_mouse); Cvar_RegisterVariable(&gl_combine); Cvar_RegisterVariable(&in_pitch_min); @@ -420,25 +424,33 @@ void VID_Shared_Init(void) Cvar_SetQuick(&vid_height, com_argv[i+1]); if ((i = COM_CheckParm("-bpp")) != 0) Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]); + if ((i = COM_CheckParm("-nostencil")) != 0) + Cvar_SetValueQuick(&vid_stencil, 0); + if ((i = COM_CheckParm("-stencil")) != 0) + Cvar_SetValueQuick(&vid_stencil, 1); } int current_vid_fullscreen; int current_vid_width; int current_vid_height; int current_vid_bitsperpixel; -extern int VID_InitMode (int fullscreen, int width, int height, int bpp); -int VID_Mode(int fullscreen, int width, int height, int bpp) +int current_vid_stencil; +extern int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil); +int VID_Mode(int fullscreen, int width, int height, int bpp, int stencil) { - if (fullscreen) - Con_Printf("Video: %dx%dx%d fullscreen\n", width, height, bpp); - else - Con_Printf("Video: %dx%d windowed\n", width, height); - if (VID_InitMode(fullscreen, width, height, bpp)) + Con_Printf("Video: %s %dx%dx%d %s\n", fullscreen ? "fullscreen" : "window", width, height, bpp, stencil ? "with stencil" : "without stencil"); + if (VID_InitMode(fullscreen, width, height, bpp, stencil)) { current_vid_fullscreen = fullscreen; current_vid_width = width; current_vid_height = height; current_vid_bitsperpixel = bpp; + current_vid_stencil = stencil; + Cvar_SetValueQuick(&vid_fullscreen, fullscreen); + Cvar_SetValueQuick(&vid_width, width); + Cvar_SetValueQuick(&vid_height, height); + Cvar_SetValueQuick(&vid_bitsperpixel, bpp); + Cvar_SetValueQuick(&vid_stencil, stencil); return true; } else @@ -461,14 +473,14 @@ static void VID_CloseSystems(void) void VID_Restart_f(void) { - Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp, to %s %dx%dx%dbpp.\n", - current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, - vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer); + Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp %s, to %s %dx%dx%dbpp %s.\n", + current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil ? "with stencil" : "without stencil", + vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer ? "with stencil" : "without stencil"); VID_Close(); - if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) + if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer)) { Con_Printf("Video mode change failed\n"); - if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel)) + if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil)) Sys_Error("Unable to restore to last working video mode\n"); } VID_OpenSystems(); @@ -477,16 +489,20 @@ void VID_Restart_f(void) void VID_Open(void) { Con_Printf("Starting video system\n"); - if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) + if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer)) { - if (vid_fullscreen.integer) + Con_Printf("Desired video mode fail, trying fallbacks...\n"); + if (!vid_stencil.integer || !VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, false)) { - if (!VID_Mode(true, 640, 480, 16)) - if (!VID_Mode(false, 640, 480, 16)) - Sys_Error("Video modes failed\n"); + if (vid_fullscreen.integer) + { + if (!VID_Mode(true, 640, 480, 16, false)) + if (!VID_Mode(false, 640, 480, 16, false)) + Sys_Error("Video modes failed\n"); + } + else + Sys_Error("Windowed video failed\n"); } - else - Sys_Error("Windowed video failed\n"); } VID_OpenSystems(); } diff --git a/vid_wgl.c b/vid_wgl.c index d9396128..d2c01840 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -671,7 +671,7 @@ void VID_Init(void) Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f); } -int VID_InitMode (int fullscreen, int width, int height, int bpp) +int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil) { int i; HDC hdc; @@ -703,10 +703,15 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) HGLRC baseRC; int CenterX, CenterY; const char *gldrivername; - + if (vid_initialized) Sys_Error("VID_InitMode called when video is already initialised\n"); + if (stencil) + pfd.cStencilBits = 8; + else + pfd.cStencilBits = 0; + gldrivername = "opengl32.dll"; i = COM_CheckParm("-gl_driver"); if (i && i < com_argc - 1)