]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_shared.c
fix v_flipped in cs_unproject (it was correct in cs_project) if a view port is set up
[xonotic/darkplaces.git] / vid_shared.c
index 3848c5f96712a690711142ab2d4b1b83defa191f..2b5ea935c155d1e72cd4e86d52e2b03fc4db7960 100644 (file)
@@ -393,12 +393,28 @@ 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)
+#if _MSC_VER >= 1400
+#define sscanf sscanf_s
+#endif
+
+int GL_CheckExtension(const char *minglver_or_ext, const dllfunction_t *funcs, const char *disableparm, int silent)
 {
        int failed = false;
        const dllfunction_t *func;
+       struct { int major, minor; } min_version, curr_version;
+       int ext;
 
-       Con_DPrintf("checking for %s...  ", name);
+       if(sscanf(minglver_or_ext, "%d.%d", &min_version.major, &min_version.minor) == 2)
+               ext = 0; // opengl version
+       else if(minglver_or_ext[0] != toupper(minglver_or_ext[0]))
+               ext = -1; // pseudo name
+       else
+               ext = 1; // extension name
+
+       if (ext)
+               Con_DPrintf("checking for %s...  ", minglver_or_ext);
+       else
+               Con_DPrintf("checking for OpenGL %s core features...  ", minglver_or_ext);
 
        for (func = funcs;func && func->name;func++)
                *func->funcvariable = NULL;
@@ -409,19 +425,40 @@ int GL_CheckExtension(const char *name, const dllfunction_t *funcs, const char *
                return false;
        }
 
-       if ((name[2] == '_' || name[3] == '_') && !strstr(gl_extensions ? gl_extensions : "", name) && !strstr(gl_platformextensions ? gl_platformextensions : "", name))
+       if (ext == 1) // opengl extension
        {
-               Con_DPrint("not detected\n");
-               return false;
+               if (!strstr(gl_extensions ? gl_extensions : "", minglver_or_ext) && !strstr(gl_platformextensions ? gl_platformextensions : "", minglver_or_ext))
+               {
+                       Con_DPrint("not detected\n");
+                       return false;
+               }
+       }
+
+       if(ext == 0) // opengl version
+       {
+               sscanf(gl_version, "%d.%d", &curr_version.major, &curr_version.minor);
+
+               if (curr_version.major < min_version.major || (curr_version.major == min_version.major && curr_version.minor < min_version.minor))
+               {
+                       Con_DPrintf("not detected (OpenGL %d.%d loaded)\n", curr_version.major, curr_version.minor);
+                       return false;
+               }
        }
 
        for (func = funcs;func && func->name != NULL;func++)
        {
+               // Con_DPrintf("\n    %s...  ", func->name);
+
                // functions are cleared before all the extensions are evaluated
                if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
                {
                        if (!silent)
-                               Con_DPrintf("OpenGL extension \"%s\" is missing function \"%s\" - broken driver!\n", name, func->name);
+                       {
+                               if (ext)
+                                       Con_DPrintf("%s is missing function \"%s\" - broken driver!\n", minglver_or_ext, func->name);
+                               else
+                                       Con_DPrintf("OpenGL %s core features are missing function \"%s\" - broken driver!\n", minglver_or_ext, func->name);
+                       }
                        failed = true;
                }
        }
@@ -760,7 +797,7 @@ void VID_CheckExtensions(void)
        gl_support_texture_compression = false;
        gl_support_arb_occlusion_query = false;
 
-       if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
+       if (!GL_CheckExtension("1.1", opengl110funcs, NULL, false))
                Sys_Error("OpenGL 1.1.0 functions not found");
 
        CHECKGLERROR
@@ -769,7 +806,7 @@ void VID_CheckExtensions(void)
        Con_DPrint("Checking OpenGL extensions...\n");
 
 // COMMANDLINEOPTION: GL: -nodrawrangeelements disables GL_EXT_draw_range_elements (renders faster)
-       if (!GL_CheckExtension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
+       if (!GL_CheckExtension("1.2", drawrangeelementsfuncs, "-nodrawrangeelements", true))
                GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
 
 // COMMANDLINEOPTION: GL: -nomtex disables GL_ARB_multitexture (required for faster map rendering)
@@ -796,12 +833,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);
-#ifndef __APPLE__
-       // TODO: blacklist this extension on Radeon X1600-X1950 hardware (they support it only with certain filtering/repeat modes)
-       // 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)
-       gl_support_arb_texture_non_power_of_two = GL_CheckExtension("GL_ARB_texture_non_power_of_two", NULL, "-notexturenonpoweroftwo", false);
-#endif
 // 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)
@@ -817,7 +848,7 @@ void VID_CheckExtensions(void)
        gl_support_ext_blend_subtract = GL_CheckExtension("GL_EXT_blend_subtract", blendequationfuncs, "-noblendsubtract", false);
 
 // COMMANDLINEOPTION: GL: -noseparatestencil disables use of OpenGL2.0 glStencilOpSeparate and GL_ATI_separate_stencil extensions (which accelerate shadow rendering)
-       if (!(gl_support_separatestencil = GL_CheckExtension("glStencilOpSeparate", gl2separatestencilfuncs, "-noseparatestencil", true)))
+       if (!(gl_support_separatestencil = (GL_CheckExtension("2.0", gl2separatestencilfuncs, "-noseparatestencil", true))))
                gl_support_separatestencil = GL_CheckExtension("GL_ATI_separate_stencil", atiseparatestencilfuncs, "-noseparatestencil", false);
 // COMMANDLINEOPTION: GL: -nostenciltwoside disables GL_EXT_stencil_two_side (which accelerate shadow rendering)
        gl_support_stenciltwoside = GL_CheckExtension("GL_EXT_stencil_two_side", stenciltwosidefuncs, "-nostenciltwoside", false);
@@ -838,6 +869,18 @@ 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);
@@ -929,7 +972,7 @@ void VID_UpdateGamma(qboolean force, int rampsize)
        BOUNDCVAR(v_gamma, 0.1, 5);
        BOUNDCVAR(v_contrast, 1, 5);
        BOUNDCVAR(v_brightness, 0, 0.8);
-       BOUNDCVAR(v_contrastboost, 0.0625, 16);
+       //BOUNDCVAR(v_contrastboost, 0.0625, 16);
        BOUNDCVAR(v_color_black_r, 0, 0.8);
        BOUNDCVAR(v_color_black_g, 0, 0.8);
        BOUNDCVAR(v_color_black_b, 0, 0.8);