src/video/windows/SDL_windowsopengl.c
changeset 7037 3fedf1f25b94
parent 6885 700f1b25f77f
child 7191 75360622e65f
equal deleted inserted replaced
7036:8c891504e325 7037:3fedf1f25b94
    89     SDL_free(wpath);
    89     SDL_free(wpath);
    90     if (!_this->gl_config.dll_handle) {
    90     if (!_this->gl_config.dll_handle) {
    91         char message[1024];
    91         char message[1024];
    92         SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
    92         SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
    93                      path);
    93                      path);
    94         WIN_SetError(message);
    94         return WIN_SetError(message);
    95         return -1;
       
    96     }
    95     }
    97     SDL_strlcpy(_this->gl_config.driver_path, path,
    96     SDL_strlcpy(_this->gl_config.driver_path, path,
    98                 SDL_arraysize(_this->gl_config.driver_path));
    97                 SDL_arraysize(_this->gl_config.driver_path));
    99 
    98 
   100     /* Allocate OpenGL memory */
    99     /* Allocate OpenGL memory */
   101     _this->gl_data =
   100     _this->gl_data =
   102         (struct SDL_GLDriverData *) SDL_calloc(1,
   101         (struct SDL_GLDriverData *) SDL_calloc(1,
   103                                                sizeof(struct
   102                                                sizeof(struct
   104                                                       SDL_GLDriverData));
   103                                                       SDL_GLDriverData));
   105     if (!_this->gl_data) {
   104     if (!_this->gl_data) {
   106         SDL_OutOfMemory();
   105         return SDL_OutOfMemory();
   107         return -1;
       
   108     }
   106     }
   109 
   107 
   110     /* Load function pointers */
   108     /* Load function pointers */
   111     handle = _this->gl_config.dll_handle;
   109     handle = _this->gl_config.dll_handle;
   112     _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
   110     _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
   122 
   120 
   123     if (!_this->gl_data->wglGetProcAddress ||
   121     if (!_this->gl_data->wglGetProcAddress ||
   124         !_this->gl_data->wglCreateContext ||
   122         !_this->gl_data->wglCreateContext ||
   125         !_this->gl_data->wglDeleteContext ||
   123         !_this->gl_data->wglDeleteContext ||
   126         !_this->gl_data->wglMakeCurrent) {
   124         !_this->gl_data->wglMakeCurrent) {
   127         SDL_SetError("Could not retrieve OpenGL functions");
       
   128         SDL_UnloadObject(handle);
   125         SDL_UnloadObject(handle);
   129         return -1;
   126         return SDL_SetError("Could not retrieve OpenGL functions");
   130     }
   127     }
   131 
   128 
   132     return 0;
   129     return 0;
   133 }
   130 }
   134 
   131 
   510     }
   507     }
   511     if (!pixel_format) {
   508     if (!pixel_format) {
   512         pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
   509         pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
   513     }
   510     }
   514     if (!pixel_format) {
   511     if (!pixel_format) {
   515         SDL_SetError("No matching GL pixel format available");
   512         return SDL_SetError("No matching GL pixel format available");
   516         return -1;
       
   517     }
   513     }
   518     if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
   514     if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
   519         WIN_SetError("SetPixelFormat()");
   515         return WIN_SetError("SetPixelFormat()");
   520         return (-1);
       
   521     }
   516     }
   522     return 0;
   517     return 0;
   523 }
   518 }
   524 
   519 
   525 SDL_GLContext
   520 SDL_GLContext
   609 
   604 
   610 int
   605 int
   611 WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   606 WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   612 {
   607 {
   613     HDC hdc;
   608     HDC hdc;
   614     int status;
       
   615 
   609 
   616     if (!_this->gl_data) {
   610     if (!_this->gl_data) {
   617         SDL_SetError("OpenGL not initialized");
   611         return SDL_SetError("OpenGL not initialized");
   618         return -1;
       
   619     }
   612     }
   620 
   613 
   621     if (window) {
   614     if (window) {
   622         hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   615         hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   623     } else {
   616     } else {
   624         hdc = NULL;
   617         hdc = NULL;
   625     }
   618     }
   626     if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
   619     if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
   627         WIN_SetError("wglMakeCurrent()");
   620         return WIN_SetError("wglMakeCurrent()");
   628         status = -1;
   621     }
   629     } else {
   622     return 0;
   630         status = 0;
       
   631     }
       
   632     return status;
       
   633 }
   623 }
   634 
   624 
   635 int
   625 int
   636 WIN_GL_SetSwapInterval(_THIS, int interval)
   626 WIN_GL_SetSwapInterval(_THIS, int interval)
   637 {
   627 {
   638     int retval = -1;
       
   639     if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) {
   628     if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) {
   640         SDL_SetError("Negative swap interval unsupported in this GL");
   629         return SDL_SetError("Negative swap interval unsupported in this GL");
   641     } else if (_this->gl_data->wglSwapIntervalEXT) {
   630     } else if (_this->gl_data->wglSwapIntervalEXT) {
   642         if (_this->gl_data->wglSwapIntervalEXT(interval) == TRUE) {
   631         if (_this->gl_data->wglSwapIntervalEXT(interval) != TRUE) {
   643             retval = 0;
   632             return WIN_SetError("wglSwapIntervalEXT()");
   644         } else {
       
   645             WIN_SetError("wglSwapIntervalEXT()");
       
   646         }
   633         }
   647     } else {
   634     } else {
   648         SDL_Unsupported();
   635         return SDL_Unsupported();
   649     }
   636     }
   650     return retval;
   637     return 0;
   651 }
   638 }
   652 
   639 
   653 int
   640 int
   654 WIN_GL_GetSwapInterval(_THIS)
   641 WIN_GL_GetSwapInterval(_THIS)
   655 {
   642 {