]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_shared.c
fix stupid endless loop
[xonotic/darkplaces.git] / vid_shared.c
index cf6949952284600f77b1131c9c81554a84eded25..620a757a4d3bee2055bcce6bd6c5db03d370fbe9 100644 (file)
@@ -10,7 +10,7 @@ qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha,
 qboolean isRagePro = false; // LordHavoc: the ATI Rage Pro has limitations with per pixel alpha (the color scaler does not apply to per pixel alpha images...), although not as bad as a G200.
 
 // AK FIXME -> input_dest
-qboolean in_client_mouse = false;
+qboolean in_client_mouse = true;
 
 // AK where should it be placed ?
 float in_mouse_x, in_mouse_y;
@@ -63,6 +63,8 @@ int gl_support_fragment_shader = false;
 int gl_support_arb_vertex_buffer_object = false;
 //GL_ARB_texture_compression
 int gl_support_texture_compression = false;
+//GL_ARB_occlusion_query
+int gl_support_arb_occlusion_query = false;
 
 // LordHavoc: if window is hidden, don't update screen
 qboolean vid_hidden = true;
@@ -382,6 +384,15 @@ void (GLAPIENTRY *qglCompressedTexSubImage2DARB)(GLenum target, GLint level, GLi
 void (GLAPIENTRY *qglCompressedTexSubImage1DARB)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
 void (GLAPIENTRY *qglGetCompressedTexImageARB)(GLenum target, GLint lod, void *img);
 
+void (GLAPIENTRY *qglGenQueriesARB)(GLsizei n, GLuint *ids);
+void (GLAPIENTRY *qglDeleteQueriesARB)(GLsizei n, const GLuint *ids);
+GLboolean (GLAPIENTRY *qglIsQueryARB)(GLuint qid);
+void (GLAPIENTRY *qglBeginQueryARB)(GLenum target, GLuint qid);
+void (GLAPIENTRY *qglEndQueryARB)(GLenum target);
+void (GLAPIENTRY *qglGetQueryivARB)(GLenum target, GLenum pname, GLint *params);
+void (GLAPIENTRY *qglGetQueryObjectivARB)(GLuint qid, GLenum pname, GLint *params);
+void (GLAPIENTRY *qglGetQueryObjectuivARB)(GLuint qid, GLenum pname, GLuint *params);
+
 int GL_CheckExtension(const char *name, const dllfunction_t *funcs, const char *disableparm, int silent)
 {
        int failed = false;
@@ -705,6 +716,19 @@ static dllfunction_t texturecompressionfuncs[] =
        {NULL, NULL}
 };
 
+static dllfunction_t occlusionqueryfuncs[] =
+{
+       {"glGenQueriesARB",              (void **) &qglGenQueriesARB},
+       {"glDeleteQueriesARB",           (void **) &qglDeleteQueriesARB},
+       {"glIsQueryARB",                 (void **) &qglIsQueryARB},
+       {"glBeginQueryARB",              (void **) &qglBeginQueryARB},
+       {"glEndQueryARB",                (void **) &qglEndQueryARB},
+       {"glGetQueryivARB",              (void **) &qglGetQueryivARB},
+       {"glGetQueryObjectivARB",        (void **) &qglGetQueryObjectivARB},
+       {"glGetQueryObjectuivARB",       (void **) &qglGetQueryObjectuivARB},
+       {NULL, NULL}
+};
+
 void VID_CheckExtensions(void)
 {
        gl_stencil = vid_bitsperpixel.integer == 32;
@@ -734,6 +758,7 @@ void VID_CheckExtensions(void)
        gl_support_fragment_shader = false;
        gl_support_arb_vertex_buffer_object = false;
        gl_support_texture_compression = false;
+       gl_support_arb_occlusion_query = false;
 
        if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
                Sys_Error("OpenGL 1.1.0 functions not found");
@@ -771,9 +796,6 @@ void VID_CheckExtensions(void)
 // COMMANDLINEOPTION: GL: -nocubemap disables GL_ARB_texture_cube_map (required for bumpmapping)
        if ((gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false)))
                qglGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &gl_max_cube_map_texture_size);
-       // TODO: blacklist this extension on Radeon X1600-X1950 hardware (they support it only with certain filtering/repeat modes)
-// COMMANDLINEOPTION: GL: -notexturenonpoweroftwo disables GL_ARB_texture_non_power_of_two (which saves video memory if it is supported, but crashes on some buggy drivers)
-       gl_support_arb_texture_non_power_of_two = GL_CheckExtension("GL_ARB_texture_non_power_of_two", NULL, "-notexturenonpoweroftwo", false);
 // COMMANDLINEOPTION: GL: -notexturecompression disables GL_ARB_texture_compression (which saves video memory if it is supported, but can also degrade image quality, see gl_texturecompression cvar documentation for more information)
        gl_support_texture_compression = GL_CheckExtension("GL_ARB_texture_compression", texturecompressionfuncs, "-notexturecompression", false);
 // COMMANDLINEOPTION: GL: -nocva disables GL_EXT_compiled_vertex_array (renders faster)
@@ -810,6 +832,21 @@ void VID_CheckExtensions(void)
                        if ((gl_support_vertex_shader = GL_CheckExtension("GL_ARB_vertex_shader", vertexshaderfuncs, "-novertexshader", false)))
                                gl_support_fragment_shader = GL_CheckExtension("GL_ARB_fragment_shader", NULL, "-nofragmentshader", false);
        CHECKGLERROR
+#ifndef __APPLE__
+       // LordHavoc: this is blocked on Mac OS X because the drivers claim support but often can't accelerate it or crash when used.
+// COMMANDLINEOPTION: GL: -notexturenonpoweroftwo disables GL_ARB_texture_non_power_of_two (which saves video memory if it is supported, but crashes on some buggy drivers)
+       
+       {
+               // blacklist this extension on Radeon X1600-X1950 hardware (they support it only with certain filtering/repeat modes)
+               int val = 0;
+               if(gl_support_vertex_shader)
+                       qglGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &val);
+               gl_support_arb_texture_non_power_of_two = val > 0 && GL_CheckExtension("GL_ARB_texture_non_power_of_two", NULL, "-notexturenonpoweroftwo", false);
+       }
+#endif
+
+// COMMANDLINEOPTION: GL: -noocclusionquery disables GL_ARB_occlusion_query (which allows coronas to fade according to visibility, and potentially used for rendering optimizations)
+       gl_support_arb_occlusion_query = GL_CheckExtension("GL_ARB_occlusion_query", occlusionqueryfuncs, "-noocclusionquery", false);
 }
 
 void Force_CenterView_f (void)
@@ -1066,9 +1103,11 @@ void VID_Shared_Init(void)
 
 int VID_Mode(int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples)
 {
+       int requestedWidth = width;
+       int requestedHeight = height;
        cl_ignoremousemoves = 2;
        Con_Printf("Initializing Video Mode: %s %dx%dx%dx%dhz%s%s\n", fullscreen ? "fullscreen" : "window", width, height, bpp, refreshrate, stereobuffer ? " stereo" : "", samples > 1 ? va(" (%ix AA)", samples) : "");
-       if (VID_InitMode(fullscreen, width, height, bpp, vid_userefreshrate.integer ? max(1, refreshrate) : 0, stereobuffer, samples))
+       if (VID_InitMode(fullscreen, &width, &height, bpp, vid_userefreshrate.integer ? max(1, refreshrate) : 0, stereobuffer, samples))
        {
                vid.fullscreen = fullscreen;
                vid.width = width;
@@ -1086,6 +1125,10 @@ int VID_Mode(int fullscreen, int width, int height, int bpp, int refreshrate, in
                if(vid_userefreshrate.integer)
                        Cvar_SetValueQuick(&vid_refreshrate, refreshrate);
                Cvar_SetValueQuick(&vid_stereobuffer, stereobuffer);
+
+               if(width != requestedWidth || height != requestedHeight)
+                       Con_Printf("Chose a similar video mode %dx%d instead of the requested mode %dx%d\n", width, height, requestedWidth, requestedHeight);
+
                return true;
        }
        else