X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=vid_shared.c;h=212118b7d528e6ed754db583ebed1f2509224fd0;hb=1740f737276f086c2f19758f72881a20e5070b57;hp=561e0d8d274ad24e669ad16f8f9fd7184f7609cb;hpb=716cb9f1cb2554b0b9d4bbf4cd4e6f4d90faa7e1;p=xonotic%2Fdarkplaces.git diff --git a/vid_shared.c b/vid_shared.c index 561e0d8d..212118b7 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -16,17 +16,20 @@ 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 = false; +int vid_hidden = true; // LordHavoc: if window is not the active window, don't hog as much CPU time, // let go of the mouse, turn off sound, and restore system gamma ramps... int vid_activewindow = true; -cvar_t vid_fullscreen = {0, "vid_fullscreen", "1"}; -cvar_t vid_width = {0, "vid_width", "800"}; -cvar_t vid_height = {0, "vid_height", "600"}; -cvar_t vid_bitsperpixel = {0, "vid_bitsperpixel", "32"}; +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"}; @@ -95,6 +98,7 @@ void (GLAPIENTRY *qglClearDepth)(GLclampd depth); void (GLAPIENTRY *qglDepthFunc)(GLenum func); void (GLAPIENTRY *qglDepthMask)(GLboolean flag); void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val); +void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); @@ -104,7 +108,7 @@ void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, cons void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); void (GLAPIENTRY *qglArrayElement)(GLint i); -void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t); void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y); void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z); @@ -131,10 +135,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); @@ -221,12 +225,13 @@ static gl_extensionfunctionlist_t opengl110funcs[] = {"glDepthMask", (void **) &qglDepthMask}, {"glDepthRange", (void **) &qglDepthRange}, {"glDrawElements", (void **) &qglDrawElements}, + {"glColorMask", (void **) &qglColorMask}, {"glVertexPointer", (void **) &qglVertexPointer}, // {"glNormalPointer", (void **) &qglNormalPointer}, {"glColorPointer", (void **) &qglColorPointer}, {"glTexCoordPointer", (void **) &qglTexCoordPointer}, {"glArrayElement", (void **) &qglArrayElement}, - {"glColor4ub", (void **) &qglColor4ub}, + {"glColor4f", (void **) &qglColor4f}, {"glTexCoord2f", (void **) &qglTexCoord2f}, {"glVertex2f", (void **) &qglVertex2f}, {"glVertex3f", (void **) &qglVertex3f}, @@ -250,10 +255,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}, @@ -333,15 +338,6 @@ void VID_CheckExtensions(void) qglDrawRangeElements = qglDrawRangeElementsEXT; } -double VID_CompareMode(int width1, int height1, int bpp1, int width2, int height2, int bpp2) -{ - double dw, dh, db; - dw = ((width2 - width1) / 2048) * 16; - dh = ((height2 - height1) / 1536) * 4; - db = (bpp2 - bpp1) / 32; - return dw * dw + dh * dh + db * db; -} - void Force_CenterView_f (void) { cl.viewangles[PITCH] = 0; @@ -402,7 +398,7 @@ void IN_Mouse(usercmd_t *cmd, float mx, float my) } } -void VID_InitCvars(void) +void VID_Shared_Init(void) { int i; @@ -410,12 +406,14 @@ void VID_InitCvars(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); Cvar_RegisterVariable(&in_pitch_max); Cvar_RegisterVariable(&m_filter); Cmd_AddCommand("force_centerview", Force_CenterView_f); + Cmd_AddCommand("vid_restart", VID_Restart_f); // interpret command-line parameters if ((i = COM_CheckParm("-window")) != 0) @@ -428,17 +426,91 @@ void VID_InitCvars(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); } -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_fullscreen; +int current_vid_width; +int current_vid_height; +int current_vid_bitsperpixel; +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 return false; } + +static void VID_OpenSystems(void) +{ + R_Modules_Start(); + S_Open(); + CDAudio_Open(); +} + +static void VID_CloseSystems(void) +{ + CDAudio_Close(); + S_Close(); + R_Modules_Shutdown(); +} + +void VID_Restart_f(void) +{ + 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, 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, current_vid_stencil)) + Sys_Error("Unable to restore to last working video mode\n"); + } + VID_OpenSystems(); +} + +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, vid_stencil.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_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"); + } + } + VID_OpenSystems(); +} + +void VID_Close(void) +{ + VID_CloseSystems(); + VID_Shutdown(); +}