📄 sdl_wingl.c
字号:
SDL_SetError("Unable to create GL context"); return(-1); } if ( WIN_GL_MakeCurrent(this) < 0 ) { return(-1); } gl_active = 1; /* Get the wglGetPixelFormatAttribivARB pointer for the context */ if ( this->gl_data->WGL_ARB_pixel_format ) { this->gl_data->wglGetPixelFormatAttribivARB = (BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *)) this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB"); } else { this->gl_data->wglGetPixelFormatAttribivARB = NULL; } /* Vsync control under Windows. Checking glGetString here is * somewhat a documented and reliable hack - it was originally * as a feature added by mistake, but since so many people rely * on it, it will not be removed. strstr should be safe here.*/ glGetStringFunc = WIN_GL_GetProcAddress(this, "glGetString"); if ( glGetStringFunc ) { wglext = (const char *)glGetStringFunc(GL_EXTENSIONS); } else { /* Uh oh, something is seriously wrong here... */ wglext = NULL; } if ( wglext && SDL_strstr(wglext, "WGL_EXT_swap_control") ) { this->gl_data->wglSwapIntervalEXT = WIN_GL_GetProcAddress(this, "wglSwapIntervalEXT"); this->gl_data->wglGetSwapIntervalEXT = WIN_GL_GetProcAddress(this, "wglGetSwapIntervalEXT"); } else { this->gl_data->wglSwapIntervalEXT = NULL; this->gl_data->wglGetSwapIntervalEXT = NULL; } if ( this->gl_config.swap_control >= 0 ) { if ( this->gl_data->wglSwapIntervalEXT ) { this->gl_data->wglSwapIntervalEXT(this->gl_config.swap_control); } }#else SDL_SetError("WIN driver not configured with OpenGL");#endif if ( gl_active ) { retval = 0; } else { retval = -1; } return(retval);}void WIN_GL_ShutDown(_THIS){#if SDL_VIDEO_OPENGL /* Clean up OpenGL */ if ( GL_hrc ) { this->gl_data->wglMakeCurrent(NULL, NULL); this->gl_data->wglDeleteContext(GL_hrc); GL_hrc = NULL; } if ( GL_hdc ) { ReleaseDC(SDL_Window, GL_hdc); GL_hdc = NULL; } gl_active = 0; WIN_GL_UnloadLibrary(this);#endif /* SDL_VIDEO_OPENGL */}#if SDL_VIDEO_OPENGL/* Make the current context active */int WIN_GL_MakeCurrent(_THIS){ int retval; retval = 0; if ( ! this->gl_data->wglMakeCurrent(GL_hdc, GL_hrc) ) { SDL_SetError("Unable to make GL context current"); retval = -1; } return(retval);}/* Get attribute data from wgl. */int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value){ int retval; if (attrib == SDL_GL_SWAP_CONTROL) { if ( this->gl_data->wglGetSwapIntervalEXT ) { *value = this->gl_data->wglGetSwapIntervalEXT(); return 0; } return -1; } if ( this->gl_data->wglGetPixelFormatAttribivARB ) { int wgl_attrib; switch(attrib) { case SDL_GL_RED_SIZE: wgl_attrib = WGL_RED_BITS_ARB; break; case SDL_GL_GREEN_SIZE: wgl_attrib = WGL_GREEN_BITS_ARB; break; case SDL_GL_BLUE_SIZE: wgl_attrib = WGL_BLUE_BITS_ARB; break; case SDL_GL_ALPHA_SIZE: wgl_attrib = WGL_ALPHA_BITS_ARB; break; case SDL_GL_DOUBLEBUFFER: wgl_attrib = WGL_DOUBLE_BUFFER_ARB; break; case SDL_GL_BUFFER_SIZE: wgl_attrib = WGL_COLOR_BITS_ARB; break; case SDL_GL_DEPTH_SIZE: wgl_attrib = WGL_DEPTH_BITS_ARB; break; case SDL_GL_STENCIL_SIZE: wgl_attrib = WGL_STENCIL_BITS_ARB; break; case SDL_GL_ACCUM_RED_SIZE: wgl_attrib = WGL_ACCUM_RED_BITS_ARB; break; case SDL_GL_ACCUM_GREEN_SIZE: wgl_attrib = WGL_ACCUM_GREEN_BITS_ARB; break; case SDL_GL_ACCUM_BLUE_SIZE: wgl_attrib = WGL_ACCUM_BLUE_BITS_ARB; break; case SDL_GL_ACCUM_ALPHA_SIZE: wgl_attrib = WGL_ACCUM_ALPHA_BITS_ARB; break; case SDL_GL_STEREO: wgl_attrib = WGL_STEREO_ARB; break; case SDL_GL_MULTISAMPLEBUFFERS: wgl_attrib = WGL_SAMPLE_BUFFERS_ARB; break; case SDL_GL_MULTISAMPLESAMPLES: wgl_attrib = WGL_SAMPLES_ARB; break; case SDL_GL_ACCELERATED_VISUAL: wgl_attrib = WGL_ACCELERATION_ARB; this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value); if ( *value == WGL_NO_ACCELERATION_ARB ) { *value = SDL_FALSE; } else { *value = SDL_TRUE; } return 0; default: return(-1); } this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value); return 0; } retval = 0; switch ( attrib ) { case SDL_GL_RED_SIZE: *value = GL_pfd.cRedBits; break; case SDL_GL_GREEN_SIZE: *value = GL_pfd.cGreenBits; break; case SDL_GL_BLUE_SIZE: *value = GL_pfd.cBlueBits; break; case SDL_GL_ALPHA_SIZE: *value = GL_pfd.cAlphaBits; break; case SDL_GL_DOUBLEBUFFER: if ( GL_pfd.dwFlags & PFD_DOUBLEBUFFER ) { *value = 1; } else { *value = 0; } break; case SDL_GL_BUFFER_SIZE: *value = GL_pfd.cColorBits; break; case SDL_GL_DEPTH_SIZE: *value = GL_pfd.cDepthBits; break; case SDL_GL_STENCIL_SIZE: *value = GL_pfd.cStencilBits; break; case SDL_GL_ACCUM_RED_SIZE: *value = GL_pfd.cAccumRedBits; break; case SDL_GL_ACCUM_GREEN_SIZE: *value = GL_pfd.cAccumGreenBits; break; case SDL_GL_ACCUM_BLUE_SIZE: *value = GL_pfd.cAccumBlueBits; break; case SDL_GL_ACCUM_ALPHA_SIZE: *value = GL_pfd.cAccumAlphaBits; break; case SDL_GL_STEREO: if ( GL_pfd.dwFlags & PFD_STEREO ) { *value = 1; } else { *value = 0; } break; case SDL_GL_MULTISAMPLEBUFFERS: *value = 0; break; case SDL_GL_MULTISAMPLESAMPLES: *value = 1; break; case SDL_GL_SWAP_CONTROL: if ( this->gl_data->wglGetSwapIntervalEXT ) { *value = this->gl_data->wglGetSwapIntervalEXT(); return 0; } else { return -1; } break; default: retval = -1; break; } return retval;}void WIN_GL_SwapBuffers(_THIS){ SwapBuffers(GL_hdc);}void WIN_GL_UnloadLibrary(_THIS){ if ( this->gl_config.driver_loaded ) { FreeLibrary((HMODULE)this->gl_config.dll_handle); this->gl_data->wglGetProcAddress = NULL; this->gl_data->wglCreateContext = NULL; this->gl_data->wglDeleteContext = NULL; this->gl_data->wglMakeCurrent = NULL; this->gl_data->wglGetPixelFormatAttribivARB = NULL; this->gl_data->wglSwapIntervalEXT = NULL; this->gl_data->wglGetSwapIntervalEXT = NULL; this->gl_config.dll_handle = NULL; this->gl_config.driver_loaded = 0; }}/* Passing a NULL path means load pointers from the application */int WIN_GL_LoadLibrary(_THIS, const char* path) { HMODULE handle; if ( gl_active ) { SDL_SetError("OpenGL context already created"); return -1; } if ( path == NULL ) { path = DEFAULT_GL_DRIVER_PATH; } handle = LoadLibrary(path); if ( handle == NULL ) { SDL_SetError("Could not load OpenGL library"); return -1; } /* Unload the old driver and reset the pointers */ WIN_GL_UnloadLibrary(this); /* Load new function pointers */ SDL_memset(this->gl_data, 0, sizeof(*this->gl_data)); this->gl_data->wglGetProcAddress = (void * (WINAPI *)(const char *)) GetProcAddress(handle, "wglGetProcAddress"); this->gl_data->wglCreateContext = (HGLRC (WINAPI *)(HDC)) GetProcAddress(handle, "wglCreateContext"); this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC)) GetProcAddress(handle, "wglDeleteContext"); this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC)) GetProcAddress(handle, "wglMakeCurrent"); this->gl_data->wglSwapIntervalEXT = (void (WINAPI *)(int)) GetProcAddress(handle, "wglSwapIntervalEXT"); this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *)(void)) GetProcAddress(handle, "wglGetSwapIntervalEXT"); if ( (this->gl_data->wglGetProcAddress == NULL) || (this->gl_data->wglCreateContext == NULL) || (this->gl_data->wglDeleteContext == NULL) || (this->gl_data->wglMakeCurrent == NULL) ) { SDL_SetError("Could not retrieve OpenGL functions"); FreeLibrary(handle); return -1; } this->gl_config.dll_handle = handle; SDL_strlcpy(this->gl_config.driver_path, path, SDL_arraysize(this->gl_config.driver_path)); this->gl_config.driver_loaded = 1; return 0;}void *WIN_GL_GetProcAddress(_THIS, const char* proc){ void *func; /* This is to pick up extensions */ func = this->gl_data->wglGetProcAddress(proc); if ( ! func ) { /* This is probably a normal GL function */ func = GetProcAddress(this->gl_config.dll_handle, proc); } return func;}#endif /* SDL_VIDEO_OPENGL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -