void VideoBackend::Shutdown() { s_BackendInitialized = false; if (g_renderer) { s_efbAccessRequested = false; s_FifoShuttingDown = false; s_swapRequested = false; DLCache::Shutdown(); Fifo_Shutdown(); PostProcessing::Shutdown(); // The following calls are NOT Thread Safe // And need to be called from the video thread TextureConverter::Shutdown(); VertexLoaderManager::Shutdown(); VertexShaderCache::Shutdown(); VertexShaderManager::Shutdown(); PixelShaderManager::Shutdown(); PixelShaderCache::Shutdown(); delete g_vertex_manager; delete g_texture_cache; OpcodeDecoder_Shutdown(); delete g_renderer; g_renderer = NULL; } OpenGL_Shutdown(); }
void OglDestroyWindow(void){ if (gameStates.ogl.bInitialized){ OglSmashTextureListInternal(); if (mouse_hidden){ ShowCursor(TRUE); mouse_hidden = 0; } if (g_hWnd){ key_close(); mouse_close(); joy_close(); if (!FindArg( "-nosound" )) DigiClose(); OpenGL_Shutdown(); DestroyWindow(g_hWnd); }else Error("OglDestroyWindow: no g_hWnd?\n"); gameStates.ogl.bInitialized=0; } return; }
// Entering this function, the following values must be valid // GLPREF_width,GLPREF_height: preferred width and height // GLPREF_windowed: do we want windowed or full screen mode // g_hWnd: handle to the window created for OpenGL // On exit from this function (if returned true) the following values will be set // GLSTATE_width,GLSTATE_height: real width and height of screen // hDC: device context of the window // GL_ResourceContext: OpenGL resource context // Saved_gammaValues: Initial gamma values bool OpenGL_Initialize(void) { char *errstr=""; int width,height; int pf; PIXELFORMATDESCRIPTOR pfd;//, pfd_copy; GLPREF_windowed=!gameStates.ogl.bFullScreen; if (FindArg("-gl_test1")){ GLSTATE_width = GLPREF_width; GLSTATE_height = GLPREF_height; }else{ if(!GLPREF_windowed) { // First set our display mode // Create direct draw surface int retval; devmode.dmSize=sizeof(devmode); devmode.dmBitsPerPel=16; devmode.dmPelsWidth=GLPREF_width; devmode.dmPelsHeight=GLPREF_height; devmode.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; if ((retval=FindArg("-gl_refresh"))){ devmode.dmDisplayFrequency=atoi(Args[retval+1]); if (devmode.dmDisplayFrequency>=60)//uhh, I hope no one actually wants a refresh lower than 60.. gag. devmode.dmFields|=DM_DISPLAYFREQUENCY; //printf("trying refresh %i hz\n",devmode.dmDisplayFrequency); } retval=ChangeDisplaySettings(&devmode,CDS_FULLSCREEN); if (retval!=DISP_CHANGE_SUCCESSFUL) { // we couldn't switch to the desired screen mode // fall back to 640x480 retval=-1; devmode.dmBitsPerPel=16; devmode.dmPelsWidth=640; devmode.dmPelsHeight=480; devmode.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; retval=ChangeDisplaySettings(&devmode,CDS_FULLSCREEN); if (retval!=DISP_CHANGE_SUCCESSFUL) { errstr="ChangeDisplaySettings"; // we couldn't even switch to 640x480, we're out of here // restore screen mode to default ChangeDisplaySettings(NULL,0); goto OpenGLError; }else { // successful, change our global settings to reflect what // mode we are at GLPREF_width=640; GLPREF_height=480; } }else { // success at changing the video mode } } if(GLPREF_windowed) { // we want windowed mode, figure out how big the window is RECT rect; GetWindowRect(g_hWnd,&rect); width=abs(rect.right-rect.left); height=abs(rect.bottom-rect.top); }else { RECT rect; // full screen mode, we want the window to be on top of everything SetWindowPos(g_hWnd,HWND_TOPMOST,0,0,GLPREF_width,GLPREF_height,SWP_FRAMECHANGED); width=GLPREF_width; height=GLPREF_height; GetWindowRect(g_hWnd,&rect); } GLSTATE_width = width; GLSTATE_height = height; } hDC = GetDC(g_hWnd); // Now we finally setup OpenGL // If OpenGL is to be dynamically loaded, do this now (if the DLL isn't already // loaded) // remove the following error when you figure out what you want to do // it's put here to make sure you notice this #ifdef OGL_RUNTIME_LOAD OglInitLoadLibrary(); #endif // Setup our pixel format memset(&pfd,0,sizeof(pfd); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; // pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_GENERIC_ACCELERATED; pfd.iPixelType = PFD_TYPE_RGBA; //let the ogl driver decide. (fixes no hw accel in 16bit mode in w2k with tnt2) // pfd.cColorBits = 16; // pfd.cAlphaBits = 8; // pfd.cDepthBits = 0; // pfd.cAccumBits = 0; // pfd.cStencilBits = 0; pfd.iLayerType = PFD_MAIN_PLANE; pfd.dwLayerMask = PFD_MAIN_PLANE; // Find the user's "best match" PFD pf = ChoosePixelFormat(hDC,&pfd); if(pf == 0) { errstr="ChoosePixelFormat"; // no pixel format closely matches goto OpenGLError; } // Set the new PFD if(SetPixelFormat(hDC,pf,&pfd)==FALSE) { errstr="SetPixelFormat"; // unable to set the pixel format goto OpenGLError; } // Now retrieve the PFD, we need to check some things /* if(DescribePixelFormat(hDC,pf,sizeof(PIXELFORMATDESCRIPTOR),&pfd_copy)==0) { errstr="DescribePixelFormat"; // unable to get the PFD goto OpenGLError; } // Make sure we are hardware accelerated if((pfd_copy.dwFlags&PFD_GENERIC_ACCELERATED)==0&&(pfd_copy.dwFlags&PFD_GENERIC_FORMAT)!=0) { // we are not hardware accelerated! goto OpenGLError; }*/ // Finally, create our OpenGL context and make it current GL_ResourceContext = wglCreateContext(hDC); if(GL_ResourceContext==NULL) { errstr="wglCreateContext"; // we couldn't create a context! goto OpenGLError; } // Make the context current wglMakeCurrent(hDC,GL_ResourceContext); // Save our gamma values because we'll probably be changing them, // this way we can restore them on exit // GetDeviceGammaRamp(hDC,(LPVOID)Saved_gammaValues); return true; OpenGLError: // Shutdown OpenGL OpenGL_Shutdown(); Error("opengl init error: %s\n",errstr); return false; }