/project/jni/sdl-1.3/src/video/windows/SDL_windowsopengl.c

https://github.com/aichunyu/FFPlayer · C · 652 lines · 514 code · 94 blank · 44 comment · 106 complexity · 604cfdc379afd41e2fdd4e686bbe40cf MD5 · raw file

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_config.h"
  19. #if SDL_VIDEO_DRIVER_WINDOWS
  20. #include "SDL_windowsvideo.h"
  21. /* WGL implementation of SDL OpenGL support */
  22. #if SDL_VIDEO_OPENGL_WGL
  23. #include "SDL_opengl.h"
  24. #define DEFAULT_OPENGL "OPENGL32.DLL"
  25. #ifndef WGL_ARB_create_context
  26. #define WGL_ARB_create_context
  27. #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
  28. #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
  29. #define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
  30. #define WGL_CONTEXT_FLAGS_ARB 0x2093
  31. #define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
  32. #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
  33. #ifndef WGL_ARB_create_context_profile
  34. #define WGL_ARB_create_context_profile
  35. #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
  36. #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
  37. #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
  38. #endif
  39. #ifndef WGL_ARB_create_context_robustness
  40. #define WGL_ARB_create_context_robustness
  41. #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
  42. #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
  43. #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
  44. #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
  45. #endif
  46. #endif
  47. #ifndef WGL_EXT_create_context_es2_profile
  48. #define WGL_EXT_create_context_es2_profile
  49. #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
  50. #endif
  51. typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC,
  52. HGLRC
  53. hShareContext,
  54. const int
  55. *attribList);
  56. int
  57. WIN_GL_LoadLibrary(_THIS, const char *path)
  58. {
  59. LPTSTR wpath;
  60. HANDLE handle;
  61. if (path == NULL) {
  62. path = SDL_getenv("SDL_OPENGL_LIBRARY");
  63. }
  64. if (path == NULL) {
  65. path = DEFAULT_OPENGL;
  66. }
  67. wpath = WIN_UTF8ToString(path);
  68. _this->gl_config.dll_handle = LoadLibrary(wpath);
  69. SDL_free(wpath);
  70. if (!_this->gl_config.dll_handle) {
  71. char message[1024];
  72. SDL_snprintf(message, SDL_arraysize(message), "LoadLibrary(\"%s\")",
  73. path);
  74. WIN_SetError(message);
  75. return -1;
  76. }
  77. SDL_strlcpy(_this->gl_config.driver_path, path,
  78. SDL_arraysize(_this->gl_config.driver_path));
  79. /* Allocate OpenGL memory */
  80. _this->gl_data =
  81. (struct SDL_GLDriverData *) SDL_calloc(1,
  82. sizeof(struct
  83. SDL_GLDriverData));
  84. if (!_this->gl_data) {
  85. SDL_OutOfMemory();
  86. return -1;
  87. }
  88. /* Load function pointers */
  89. handle = _this->gl_config.dll_handle;
  90. _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
  91. GetProcAddress(handle, "wglGetProcAddress");
  92. _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
  93. GetProcAddress(handle, "wglCreateContext");
  94. _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
  95. GetProcAddress(handle, "wglDeleteContext");
  96. _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
  97. GetProcAddress(handle, "wglMakeCurrent");
  98. _this->gl_data->wglSwapIntervalEXT = (void (WINAPI *) (int))
  99. GetProcAddress(handle, "wglSwapIntervalEXT");
  100. _this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *) (void))
  101. GetProcAddress(handle, "wglGetSwapIntervalEXT");
  102. if (!_this->gl_data->wglGetProcAddress ||
  103. !_this->gl_data->wglCreateContext ||
  104. !_this->gl_data->wglDeleteContext ||
  105. !_this->gl_data->wglMakeCurrent) {
  106. SDL_SetError("Could not retrieve OpenGL functions");
  107. SDL_UnloadObject(handle);
  108. return -1;
  109. }
  110. return 0;
  111. }
  112. void *
  113. WIN_GL_GetProcAddress(_THIS, const char *proc)
  114. {
  115. void *func;
  116. /* This is to pick up extensions */
  117. func = _this->gl_data->wglGetProcAddress(proc);
  118. if (!func) {
  119. /* This is probably a normal GL function */
  120. func = GetProcAddress(_this->gl_config.dll_handle, proc);
  121. }
  122. return func;
  123. }
  124. void
  125. WIN_GL_UnloadLibrary(_THIS)
  126. {
  127. FreeLibrary((HMODULE) _this->gl_config.dll_handle);
  128. _this->gl_config.dll_handle = NULL;
  129. /* Free OpenGL memory */
  130. SDL_free(_this->gl_data);
  131. _this->gl_data = NULL;
  132. }
  133. static void
  134. WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
  135. {
  136. SDL_zerop(pfd);
  137. pfd->nSize = sizeof(*pfd);
  138. pfd->nVersion = 1;
  139. pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
  140. if (_this->gl_config.double_buffer) {
  141. pfd->dwFlags |= PFD_DOUBLEBUFFER;
  142. }
  143. if (_this->gl_config.stereo) {
  144. pfd->dwFlags |= PFD_STEREO;
  145. }
  146. pfd->iLayerType = PFD_MAIN_PLANE;
  147. pfd->iPixelType = PFD_TYPE_RGBA;
  148. pfd->cRedBits = _this->gl_config.red_size;
  149. pfd->cGreenBits = _this->gl_config.green_size;
  150. pfd->cBlueBits = _this->gl_config.blue_size;
  151. pfd->cAlphaBits = _this->gl_config.alpha_size;
  152. if (_this->gl_config.buffer_size) {
  153. pfd->cColorBits =
  154. _this->gl_config.buffer_size - _this->gl_config.alpha_size;
  155. } else {
  156. pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
  157. }
  158. pfd->cAccumRedBits = _this->gl_config.accum_red_size;
  159. pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
  160. pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
  161. pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
  162. pfd->cAccumBits =
  163. (pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
  164. pfd->cAccumAlphaBits);
  165. pfd->cDepthBits = _this->gl_config.depth_size;
  166. pfd->cStencilBits = _this->gl_config.stencil_size;
  167. }
  168. /* Choose the closest pixel format that meets or exceeds the target.
  169. FIXME: Should we weight any particular attribute over any other?
  170. */
  171. static int
  172. WIN_GL_ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR * target)
  173. {
  174. PIXELFORMATDESCRIPTOR pfd;
  175. int count, index, best = 0;
  176. unsigned int dist, best_dist = ~0U;
  177. count = DescribePixelFormat(hdc, 1, sizeof(pfd), NULL);
  178. for (index = 1; index <= count; index++) {
  179. if (!DescribePixelFormat(hdc, index, sizeof(pfd), &pfd)) {
  180. continue;
  181. }
  182. if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
  183. continue;
  184. }
  185. if (pfd.iLayerType != target->iLayerType) {
  186. continue;
  187. }
  188. if (pfd.iPixelType != target->iPixelType) {
  189. continue;
  190. }
  191. dist = 0;
  192. if (pfd.cColorBits < target->cColorBits) {
  193. continue;
  194. } else {
  195. dist += (pfd.cColorBits - target->cColorBits);
  196. }
  197. if (pfd.cRedBits < target->cRedBits) {
  198. continue;
  199. } else {
  200. dist += (pfd.cRedBits - target->cRedBits);
  201. }
  202. if (pfd.cGreenBits < target->cGreenBits) {
  203. continue;
  204. } else {
  205. dist += (pfd.cGreenBits - target->cGreenBits);
  206. }
  207. if (pfd.cBlueBits < target->cBlueBits) {
  208. continue;
  209. } else {
  210. dist += (pfd.cBlueBits - target->cBlueBits);
  211. }
  212. if (pfd.cAlphaBits < target->cAlphaBits) {
  213. continue;
  214. } else {
  215. dist += (pfd.cAlphaBits - target->cAlphaBits);
  216. }
  217. if (pfd.cAccumBits < target->cAccumBits) {
  218. continue;
  219. } else {
  220. dist += (pfd.cAccumBits - target->cAccumBits);
  221. }
  222. if (pfd.cAccumRedBits < target->cAccumRedBits) {
  223. continue;
  224. } else {
  225. dist += (pfd.cAccumRedBits - target->cAccumRedBits);
  226. }
  227. if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
  228. continue;
  229. } else {
  230. dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
  231. }
  232. if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
  233. continue;
  234. } else {
  235. dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
  236. }
  237. if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
  238. continue;
  239. } else {
  240. dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
  241. }
  242. if (pfd.cDepthBits < target->cDepthBits) {
  243. continue;
  244. } else {
  245. dist += (pfd.cDepthBits - target->cDepthBits);
  246. }
  247. if (pfd.cStencilBits < target->cStencilBits) {
  248. continue;
  249. } else {
  250. dist += (pfd.cStencilBits - target->cStencilBits);
  251. }
  252. if (dist < best_dist) {
  253. best = index;
  254. best_dist = dist;
  255. }
  256. }
  257. return best;
  258. }
  259. static SDL_bool
  260. HasExtension(const char *extension, const char *extensions)
  261. {
  262. const char *start;
  263. const char *where, *terminator;
  264. /* Extension names should not have spaces. */
  265. where = SDL_strchr(extension, ' ');
  266. if (where || *extension == '\0')
  267. return SDL_FALSE;
  268. if (!extensions)
  269. return SDL_FALSE;
  270. /* It takes a bit of care to be fool-proof about parsing the
  271. * OpenGL extensions string. Don't be fooled by sub-strings,
  272. * etc. */
  273. start = extensions;
  274. for (;;) {
  275. where = SDL_strstr(start, extension);
  276. if (!where)
  277. break;
  278. terminator = where + SDL_strlen(extension);
  279. if (where == start || *(where - 1) == ' ')
  280. if (*terminator == ' ' || *terminator == '\0')
  281. return SDL_TRUE;
  282. start = terminator;
  283. }
  284. return SDL_FALSE;
  285. }
  286. static void
  287. WIN_GL_InitExtensions(_THIS, HDC hdc)
  288. {
  289. const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
  290. const char *extensions;
  291. wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
  292. _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
  293. if (wglGetExtensionsStringARB) {
  294. extensions = wglGetExtensionsStringARB(hdc);
  295. } else {
  296. extensions = NULL;
  297. }
  298. /* Check for WGL_ARB_pixel_format */
  299. _this->gl_data->WGL_ARB_pixel_format = 0;
  300. if (HasExtension("WGL_ARB_pixel_format", extensions)) {
  301. _this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
  302. (HDC, const int *,
  303. const FLOAT *, UINT,
  304. int *, UINT *))
  305. WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
  306. _this->gl_data->wglGetPixelFormatAttribivARB =
  307. (BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
  308. WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
  309. if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
  310. (_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
  311. _this->gl_data->WGL_ARB_pixel_format = 1;
  312. }
  313. }
  314. /* Check for WGL_EXT_swap_control */
  315. if (HasExtension("WGL_EXT_swap_control", extensions)) {
  316. _this->gl_data->wglSwapIntervalEXT =
  317. WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
  318. _this->gl_data->wglGetSwapIntervalEXT =
  319. WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
  320. } else {
  321. _this->gl_data->wglSwapIntervalEXT = NULL;
  322. _this->gl_data->wglGetSwapIntervalEXT = NULL;
  323. }
  324. }
  325. static int
  326. WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
  327. {
  328. HWND hwnd;
  329. HDC hdc;
  330. PIXELFORMATDESCRIPTOR pfd;
  331. HGLRC hglrc;
  332. int pixel_format = 0;
  333. unsigned int matching;
  334. hwnd =
  335. CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
  336. 10, 10, NULL, NULL, SDL_Instance, NULL);
  337. WIN_PumpEvents(_this);
  338. hdc = GetDC(hwnd);
  339. WIN_GL_SetupPixelFormat(_this, &pfd);
  340. SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
  341. hglrc = _this->gl_data->wglCreateContext(hdc);
  342. if (hglrc) {
  343. _this->gl_data->wglMakeCurrent(hdc, hglrc);
  344. WIN_GL_InitExtensions(_this, hdc);
  345. if (_this->gl_data->WGL_ARB_pixel_format) {
  346. _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
  347. 1, &pixel_format,
  348. &matching);
  349. }
  350. _this->gl_data->wglMakeCurrent(NULL, NULL);
  351. _this->gl_data->wglDeleteContext(hglrc);
  352. }
  353. ReleaseDC(hwnd, hdc);
  354. DestroyWindow(hwnd);
  355. WIN_PumpEvents(_this);
  356. return pixel_format;
  357. }
  358. int
  359. WIN_GL_SetupWindow(_THIS, SDL_Window * window)
  360. {
  361. HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
  362. PIXELFORMATDESCRIPTOR pfd;
  363. int pixel_format = 0;
  364. int iAttribs[64];
  365. int *iAttr;
  366. float fAttribs[1] = { 0 };
  367. WIN_GL_SetupPixelFormat(_this, &pfd);
  368. /* setup WGL_ARB_pixel_format attribs */
  369. iAttr = &iAttribs[0];
  370. *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
  371. *iAttr++ = GL_TRUE;
  372. *iAttr++ = WGL_RED_BITS_ARB;
  373. *iAttr++ = _this->gl_config.red_size;
  374. *iAttr++ = WGL_GREEN_BITS_ARB;
  375. *iAttr++ = _this->gl_config.green_size;
  376. *iAttr++ = WGL_BLUE_BITS_ARB;
  377. *iAttr++ = _this->gl_config.blue_size;
  378. if (_this->gl_config.alpha_size) {
  379. *iAttr++ = WGL_ALPHA_BITS_ARB;
  380. *iAttr++ = _this->gl_config.alpha_size;
  381. }
  382. *iAttr++ = WGL_DOUBLE_BUFFER_ARB;
  383. *iAttr++ = _this->gl_config.double_buffer;
  384. *iAttr++ = WGL_DEPTH_BITS_ARB;
  385. *iAttr++ = _this->gl_config.depth_size;
  386. if (_this->gl_config.stencil_size) {
  387. *iAttr++ = WGL_STENCIL_BITS_ARB;
  388. *iAttr++ = _this->gl_config.stencil_size;
  389. }
  390. if (_this->gl_config.accum_red_size) {
  391. *iAttr++ = WGL_ACCUM_RED_BITS_ARB;
  392. *iAttr++ = _this->gl_config.accum_red_size;
  393. }
  394. if (_this->gl_config.accum_green_size) {
  395. *iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
  396. *iAttr++ = _this->gl_config.accum_green_size;
  397. }
  398. if (_this->gl_config.accum_blue_size) {
  399. *iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
  400. *iAttr++ = _this->gl_config.accum_blue_size;
  401. }
  402. if (_this->gl_config.accum_alpha_size) {
  403. *iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
  404. *iAttr++ = _this->gl_config.accum_alpha_size;
  405. }
  406. if (_this->gl_config.stereo) {
  407. *iAttr++ = WGL_STEREO_ARB;
  408. *iAttr++ = GL_TRUE;
  409. }
  410. if (_this->gl_config.multisamplebuffers) {
  411. *iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
  412. *iAttr++ = _this->gl_config.multisamplebuffers;
  413. }
  414. if (_this->gl_config.multisamplesamples) {
  415. *iAttr++ = WGL_SAMPLES_ARB;
  416. *iAttr++ = _this->gl_config.multisamplesamples;
  417. }
  418. *iAttr++ = WGL_ACCELERATION_ARB;
  419. *iAttr++ = WGL_FULL_ACCELERATION_ARB;
  420. *iAttr = 0;
  421. /* Choose and set the closest available pixel format */
  422. if (_this->gl_config.accelerated != 0) {
  423. pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
  424. }
  425. if (!pixel_format && _this->gl_config.accelerated != 1) {
  426. iAttr[-1] = WGL_NO_ACCELERATION_ARB;
  427. pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
  428. }
  429. if (!pixel_format) {
  430. pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
  431. }
  432. if (!pixel_format) {
  433. SDL_SetError("No matching GL pixel format available");
  434. return -1;
  435. }
  436. if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
  437. WIN_SetError("SetPixelFormat()");
  438. return (-1);
  439. }
  440. return 0;
  441. }
  442. SDL_GLContext
  443. WIN_GL_CreateContext(_THIS, SDL_Window * window)
  444. {
  445. HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
  446. HGLRC context;
  447. if (_this->gl_config.major_version < 3) {
  448. context = _this->gl_data->wglCreateContext(hdc);
  449. } else {
  450. PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
  451. HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
  452. if (!temp_context) {
  453. SDL_SetError("Could not create GL context");
  454. return NULL;
  455. }
  456. /* Make the context current */
  457. if (WIN_GL_MakeCurrent(_this, window, temp_context) < 0) {
  458. WIN_GL_DeleteContext(_this, temp_context);
  459. return NULL;
  460. }
  461. wglCreateContextAttribsARB =
  462. (PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
  463. wglGetProcAddress("wglCreateContextAttribsARB");
  464. if (!wglCreateContextAttribsARB) {
  465. SDL_SetError("GL 3.x is not supported");
  466. context = temp_context;
  467. } else {
  468. /* max 8 attributes plus terminator */
  469. int attribs[9] = {
  470. WGL_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version,
  471. WGL_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version,
  472. 0
  473. };
  474. int iattr = 4;
  475. /* SDL profile bits match WGL profile bits */
  476. if( _this->gl_config.profile_mask != 0 ) {
  477. attribs[iattr++] = WGL_CONTEXT_PROFILE_MASK_ARB;
  478. attribs[iattr++] = _this->gl_config.profile_mask;
  479. }
  480. /* SDL flags match WGL flags */
  481. if( _this->gl_config.flags != 0 ) {
  482. attribs[iattr++] = WGL_CONTEXT_FLAGS_ARB;
  483. attribs[iattr++] = _this->gl_config.flags;
  484. }
  485. attribs[iattr++] = 0;
  486. /* Create the GL 3.x context */
  487. context = wglCreateContextAttribsARB(hdc, 0, attribs);
  488. /* Delete the GL 2.x context */
  489. _this->gl_data->wglDeleteContext(temp_context);
  490. }
  491. }
  492. if (!context) {
  493. WIN_SetError("Could not create GL context");
  494. return NULL;
  495. }
  496. if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
  497. WIN_GL_DeleteContext(_this, context);
  498. return NULL;
  499. }
  500. WIN_GL_InitExtensions(_this, hdc);
  501. return context;
  502. }
  503. int
  504. WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
  505. {
  506. HDC hdc;
  507. int status;
  508. if (window) {
  509. hdc = ((SDL_WindowData *) window->driverdata)->hdc;
  510. } else {
  511. hdc = NULL;
  512. }
  513. if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
  514. WIN_SetError("wglMakeCurrent()");
  515. status = -1;
  516. } else {
  517. status = 0;
  518. }
  519. return status;
  520. }
  521. int
  522. WIN_GL_SetSwapInterval(_THIS, int interval)
  523. {
  524. if (_this->gl_data->wglSwapIntervalEXT) {
  525. _this->gl_data->wglSwapIntervalEXT(interval);
  526. return 0;
  527. } else {
  528. SDL_Unsupported();
  529. return -1;
  530. }
  531. }
  532. int
  533. WIN_GL_GetSwapInterval(_THIS)
  534. {
  535. if (_this->gl_data->wglGetSwapIntervalEXT) {
  536. return _this->gl_data->wglGetSwapIntervalEXT();
  537. } else {
  538. SDL_Unsupported();
  539. return -1;
  540. }
  541. }
  542. void
  543. WIN_GL_SwapWindow(_THIS, SDL_Window * window)
  544. {
  545. HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
  546. SwapBuffers(hdc);
  547. }
  548. void
  549. WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
  550. {
  551. _this->gl_data->wglDeleteContext((HGLRC) context);
  552. }
  553. #endif /* SDL_VIDEO_OPENGL_WGL */
  554. #endif /* SDL_VIDEO_DRIVER_WINDOWS */
  555. /* vi: set ts=4 sw=4 expandtab: */