]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_wgl.c
fix some bugs with cgGL path
[xonotic/darkplaces.git] / vid_wgl.c
index 2b1e9da23b9de875574777319d2d3e66e14b22c2..1902eef76d7a3c1f71296175105f979621d3a255 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -250,14 +250,14 @@ static void IN_StartupMouse (void);
 
 void VID_Finish (void)
 {
-       vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable;
-       if (vid_usingvsync != vid_usevsync && gl_videosyncavailable)
+       vid_usevsync = vid_vsync.integer && !cls.timedemo && qwglSwapIntervalEXT;
+       if (vid_usingvsync != vid_usevsync)
        {
                vid_usingvsync = vid_usevsync;
                qwglSwapIntervalEXT (vid_usevsync);
        }
 
-       if (r_render.integer && !vid_hidden)
+       if (!vid_hidden)
        {
                CHECKGLERROR
                if (r_speeds.integer == 2 || gl_finish.integer)
@@ -787,7 +787,7 @@ void VID_Init(void)
        IN_Init();
 }
 
-int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples)
+qboolean VID_InitMode(viddef_mode_t *mode)
 {
        int i;
        HDC hdc;
@@ -827,6 +827,13 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
        float *af;
        int attribs[128];
        float attribsf[16];
+       int bpp = mode->bitsperpixel;
+       int width = mode->width;
+       int height = mode->height;
+       int refreshrate = (int)floor(mode->refreshrate+0.5);
+       int stereobuffer = mode->stereobuffer;
+       int samples = mode->samples;
+       int fullscreen = mode->fullscreen;
 
        if (vid_initialized)
                Sys_Error("VID_InitMode called when video is already initialised");
@@ -928,8 +935,8 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                        foundmode = true;
                        gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
                        gdevmode.dmBitsPerPel = bpp;
-                       gdevmode.dmPelsWidth = *width;
-                       gdevmode.dmPelsHeight = *height;
+                       gdevmode.dmPelsWidth = width;
+                       gdevmode.dmPelsHeight = height;
                        gdevmode.dmSize = sizeof (gdevmode);
                        if(refreshrate)
                        {
@@ -954,24 +961,24 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                                        Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
                                        continue;
                                }
-                               if(developer.integer >= 100)
-                                       Con_Printf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency);
+                               if(developer_extra.integer)
+                                       Con_DPrintf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency);
                                if(thismode.dmBitsPerPel != (DWORD)bpp)
                                {
-                                       if(developer.integer >= 100)
-                                               Con_Printf("wrong bpp\n");
+                                       if(developer_extra.integer)
+                                               Con_DPrintf("wrong bpp\n");
                                        continue;
                                }
-                               if(thismode.dmPelsWidth != (DWORD)*width)
+                               if(thismode.dmPelsWidth != (DWORD)width)
                                {
-                                       if(developer.integer >= 100)
-                                               Con_Printf("wrong width\n");
+                                       if(developer_extra.integer)
+                                               Con_DPrintf("wrong width\n");
                                        continue;
                                }
-                               if(thismode.dmPelsHeight != (DWORD)*height)
+                               if(thismode.dmPelsHeight != (DWORD)height)
                                {
-                                       if(developer.integer >= 100)
-                                               Con_Printf("wrong height\n");
+                                       if(developer_extra.integer)
+                                               Con_DPrintf("wrong height\n");
                                        continue;
                                }
 
@@ -980,14 +987,14 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                                        // if we have a good mode, make sure this mode is better than the previous one, and allowed by the refreshrate
                                        if(thismode.dmDisplayFrequency > (DWORD)refreshrate)
                                        {
-                                               if(developer.integer >= 100)
-                                                       Con_Printf("too high refresh rate\n");
+                                               if(developer_extra.integer)
+                                                       Con_DPrintf("too high refresh rate\n");
                                                continue;
                                        }
                                        else if(thismode.dmDisplayFrequency <= gdevmode.dmDisplayFrequency)
                                        {
-                                               if(developer.integer >= 100)
-                                                       Con_Printf("doesn't beat previous best match (too low)\n");
+                                               if(developer_extra.integer)
+                                                       Con_DPrintf("doesn't beat previous best match (too low)\n");
                                                continue;
                                        }
                                }
@@ -996,8 +1003,8 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                                        // we do have one, but it isn't good... make sure it has a lower frequency than the previous one
                                        if(thismode.dmDisplayFrequency >= gdevmode.dmDisplayFrequency)
                                        {
-                                               if(developer.integer >= 100)
-                                                       Con_Printf("doesn't beat previous best match (too high)\n");
+                                               if(developer_extra.integer)
+                                                       Con_DPrintf("doesn't beat previous best match (too high)\n");
                                                continue;
                                        }
                                }
@@ -1008,25 +1015,25 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                                        foundgoodmode = true;
                                else
                                {
-                                       if(developer.integer >= 100)
-                                               Con_Printf("(out of range)\n");
+                                       if(developer_extra.integer)
+                                               Con_DPrintf("(out of range)\n");
                                }
                                foundmode = true;
-                               if(developer.integer >= 100)
-                                       Con_Printf("accepted\n");
+                               if(developer_extra.integer)
+                                       Con_DPrintf("accepted\n");
                        }
                }
 
                if (!foundmode)
                {
                        VID_Shutdown();
-                       Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", *width, *height, bpp);
+                       Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", width, height, bpp);
                        return false;
                }
                else if(ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
                {
                        VID_Shutdown();
-                       Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", *width, *height, bpp);
+                       Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
                        return false;
                }
 
@@ -1059,8 +1066,8 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
 
        rect.top = 0;
        rect.left = 0;
-       rect.right = *width;
-       rect.bottom = *height;
+       rect.right = width;
+       rect.bottom = height;
        AdjustWindowRectEx(&rect, WindowStyle, false, 0);
 
        if (fullscreen)
@@ -1095,7 +1102,7 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
                if (!mainwindow)
                {
-                       Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %d, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), NULL, NULL, (int)global_hInstance, NULL);
+                       Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), NULL, NULL, global_hInstance, NULL);
                        VID_Shutdown();
                        return false;
                }
@@ -1108,14 +1115,14 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                if (!pixelformat)
                {
                        VID_Shutdown();
-                       Con_Printf("ChoosePixelFormat(%d, %p) failed\n", (int)baseDC, &pfd);
+                       Con_Printf("ChoosePixelFormat(%p, %p) failed\n", baseDC, &pfd);
                        return false;
                }
 
                if (SetPixelFormat(baseDC, pixelformat, &pfd) == false)
                {
                        VID_Shutdown();
-                       Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", (int)baseDC, pixelformat, &pfd);
+                       Con_Printf("SetPixelFormat(%p, %d, %p) failed\n", baseDC, pixelformat, &pfd);
                        return false;
                }
 
@@ -1136,7 +1143,7 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
                if (!qwglMakeCurrent(baseDC, baseRC))
                {
                        VID_Shutdown();
-                       Con_Printf("wglMakeCurrent(%d, %d) failed\n", (int)baseDC, (int)baseRC);
+                       Con_Printf("wglMakeCurrent(%p, %p) failed\n", baseDC, baseRC);
                        return false;
                }
 
@@ -1215,10 +1222,8 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
        // fix the leftover Alt from any Alt-Tab or the like that switched us away
        ClearAllStates ();
 
-       gl_videosyncavailable = false;
-
 // COMMANDLINEOPTION: Windows WGL: -novideosync disables WGL_EXT_swap_control
-       gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);
+       GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);
 
        GL_Init ();
 
@@ -1233,7 +1238,7 @@ int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshr
        IN_StartupMouse ();
        IN_StartupJoystick ();
 
-       if (gl_videosyncavailable)
+       if (qwglSwapIntervalEXT)
        {
                vid_usevsync = vid_vsync.integer != 0;
                vid_usingvsync = vid_vsync.integer != 0;