Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
4.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: wglcli.c
  3. *
  4. * Routines to support OpenGL client implementation.
  5. *
  6. * Created: 01-17-1995
  7. * Author: Hock San Lee [hockl]
  8. *
  9. * Copyright (c) 1995 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #ifdef _CLIENTSIDE_
  14. #include <wingdip.h>
  15. #include <glp.h>
  16. #include <glscreen.h>
  17. #include <glgenwin.h>
  18. #include "wgldef.h"
  19. PGLDRIVER pgldrvLoadInstalledDriver(HDC hdc);
  20. // Mirror code from gre\rcobj.cxx
  21. // Need DC and RC validation similar to those of DCOBJ and RCOBJ!!!
  22. HANDLE __wglCreateContext(GLWINDOWID *pgwid, GLSURF *pgsurf)
  23. {
  24. HANDLE hrcSrv;
  25. if (hrcSrv = (HANDLE) glsrvCreateContext(pgwid, pgsurf))
  26. {
  27. return(hrcSrv);
  28. }
  29. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  30. return((HANDLE) 0);
  31. }
  32. BOOL __wglDeleteContext(HANDLE hrcSrv)
  33. {
  34. wglValidateWindows();
  35. return(glsrvDeleteContext((PVOID) hrcSrv));
  36. }
  37. BOOL __wglMakeCurrent(GLWINDOWID *pgwid, HANDLE hrcSrv, BOOL bMeta)
  38. {
  39. BOOL bRet = FALSE;
  40. ULONG iError = ERROR_INVALID_HANDLE; // Default error code
  41. GLGENwindow *pwnd;
  42. wglValidateWindows();
  43. if (!hrcSrv)
  44. {
  45. glsrvLoseCurrent(GLTEB_SRVCONTEXT());
  46. return(TRUE);
  47. }
  48. pwnd = pwndGetFromID(pgwid);
  49. // Metafiles are allowed to not have pixel formats and therefore
  50. // to not have GLGENwindows. Other types must have a genwin.
  51. if (pwnd != NULL || bMeta)
  52. {
  53. iError = ERROR_NOT_ENOUGH_MEMORY;
  54. bRet = glsrvMakeCurrent(pgwid, (PVOID) hrcSrv, pwnd);
  55. }
  56. else
  57. {
  58. WARNING("__wglMakeCurrent: No pixel genwin\n");
  59. iError = ERROR_INVALID_PIXEL_FORMAT;
  60. }
  61. if (pwnd != NULL)
  62. {
  63. pwndRelease(pwnd);
  64. }
  65. if (!bRet)
  66. {
  67. SetLastError(iError);
  68. }
  69. return(bRet);
  70. }
  71. BOOL __wglShareLists(HANDLE hrcSrvShare, HANDLE hrcSrvSource)
  72. {
  73. ULONG iError;
  74. iError = glsrvShareLists((VOID *) hrcSrvShare, (VOID *) hrcSrvSource);
  75. if (iError == ERROR_SUCCESS)
  76. {
  77. return(TRUE);
  78. }
  79. else
  80. {
  81. SetLastError(iError);
  82. return(FALSE);
  83. }
  84. }
  85. BOOL __wglAttention()
  86. {
  87. return
  88. (
  89. glsrvAttention((VOID *) NULL, (VOID *) GLTEB_SRVCONTEXT(),
  90. (VOID *) NULL, (VOID *) NULL)
  91. );
  92. }
  93. int WINAPI __DrvDescribePixelFormat(HDC hdc, int ipfd, UINT cjpfd,
  94. LPPIXELFORMATDESCRIPTOR ppfd)
  95. {
  96. int iRet = 0;
  97. PGLDRIVER pglDriver;
  98. if ((pglDriver = pgldrvLoadInstalledDriver(hdc)) &&
  99. (pglDriver->dwFlags & GLDRIVER_CLIENT_BUFFER_CALLS))
  100. {
  101. ASSERTOPENGL(pglDriver->pfnDrvDescribePixelFormat != NULL,
  102. "Missing DrvDescribePixelFormat\n");
  103. iRet = pglDriver->pfnDrvDescribePixelFormat(hdc, ipfd, cjpfd, ppfd);
  104. }
  105. #ifndef _WIN95_
  106. else
  107. {
  108. iRet = GdiDescribePixelFormat(hdc, ipfd, cjpfd, ppfd);
  109. }
  110. #endif
  111. return iRet;
  112. }
  113. BOOL WINAPI __DrvSetPixelFormat(HDC hdc, int ipfd, PVOID *pwnd)
  114. {
  115. BOOL bRet = FALSE;
  116. PGLDRIVER pglDriver;
  117. if ((pglDriver = pgldrvLoadInstalledDriver(hdc)) &&
  118. (pglDriver->dwFlags & GLDRIVER_CLIENT_BUFFER_CALLS))
  119. {
  120. ASSERTOPENGL(pglDriver->pfnDrvSetPixelFormat != NULL,
  121. "Missing DrvSetPixelFormat\n");
  122. bRet = pglDriver->pfnDrvSetPixelFormat(hdc, ipfd);
  123. }
  124. #ifndef _WIN95_
  125. else
  126. {
  127. bRet = GdiSetPixelFormat(hdc, ipfd);
  128. }
  129. #endif
  130. if ( bRet && pwnd )
  131. {
  132. ((GLGENwindow *) pwnd)->pvDriver = (PVOID) pglDriver;
  133. ((GLGENwindow *) pwnd)->ulFlags |= GLGENWIN_DRIVERSET;
  134. }
  135. return bRet;
  136. }
  137. BOOL WINAPI __DrvSwapBuffers(HDC hdc, BOOL bFinish)
  138. {
  139. BOOL bRet = FALSE;
  140. PGLDRIVER pglDriver;
  141. if ((pglDriver = pgldrvLoadInstalledDriver(hdc)) &&
  142. (pglDriver->dwFlags & GLDRIVER_CLIENT_BUFFER_CALLS))
  143. {
  144. ASSERTOPENGL(pglDriver->pfnDrvSwapBuffers != NULL,
  145. "Missing DrvSwapBuffers\n");
  146. // If the driver has not indicated that it doesn't
  147. // need glFinish synchronization on swap then call
  148. // glFinish to sync things.
  149. if (bFinish && !(pglDriver->dwFlags & GLDRIVER_NO_FINISH_ON_SWAP))
  150. {
  151. glFinish();
  152. }
  153. bRet = pglDriver->pfnDrvSwapBuffers(hdc);
  154. }
  155. #ifndef _WIN95_
  156. else
  157. {
  158. if (bFinish)
  159. {
  160. // In this case we always call glFinish for compatibility
  161. // with previous version's behavior.
  162. glFinish();
  163. }
  164. bRet = GdiSwapBuffers(hdc);
  165. }
  166. #endif
  167. return bRet;
  168. }
  169. BOOL __wglCopyContext(HANDLE hrcSrvSrc, HANDLE hrcSrvDest, UINT fuFlags)
  170. {
  171. return glsrvCopyContext((VOID *) hrcSrvSrc, (VOID *) hrcSrvDest, fuFlags);
  172. }
  173. #endif // _CLIENTSIDE_