OpenGL.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #ifndef SE_INCL_OPENGL_H
  13. #define SE_INCL_OPENGL_H
  14. #ifdef PRAGMA_ONCE
  15. #pragma once
  16. #endif
  17. #include "gl_types.h"
  18. /* rcg10042001 wraped for platform. */
  19. #if (defined _MSC_VER)
  20. #define DLLFUNCTION(dll, output, name, inputs, params, required) \
  21. extern output (__stdcall *p##name) inputs
  22. #elif (defined PLATFORM_UNIX)
  23. #define DLLFUNCTION(dll, output, name, inputs, params, required) \
  24. extern output (*p##name) inputs
  25. #define __stdcall
  26. #else
  27. #error please define your platform here.
  28. #endif
  29. #include "gl_functions.h"
  30. #undef DLLFUNCTION
  31. // extensions
  32. extern void (__stdcall *pglLockArraysEXT)(GLint first, GLsizei count);
  33. extern void (__stdcall *pglUnlockArraysEXT)(void);
  34. extern GLboolean (__stdcall *pwglSwapIntervalEXT)(GLint interval);
  35. extern GLint (__stdcall *pwglGetSwapIntervalEXT)(void);
  36. extern void (__stdcall *pglActiveTextureARB)(GLenum texunit);
  37. extern void (__stdcall *pglClientActiveTextureARB)(GLenum texunit);
  38. #ifdef PLATFORM_WIN32 /* !!! FIXME: Move to abstraction layer. --rcg. */
  39. // t-buffer support
  40. extern char *(__stdcall *pwglGetExtensionsStringARB)(HDC hdc);
  41. extern BOOL (__stdcall *pwglChoosePixelFormatARB)(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  42. extern BOOL (__stdcall *pwglGetPixelFormatAttribivARB)(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int *piAttributes, int *piValues);
  43. #endif
  44. extern void (__stdcall *pglTBufferMask3DFX)(GLuint mask);
  45. // GL_NV_vertex_array_range & GL_NV_fence
  46. #ifdef PLATFORM_WIN32 /* !!! FIXME: Move to abstraction layer. --rcg. */
  47. extern void *(__stdcall *pwglAllocateMemoryNV)(GLint size, GLfloat readfreq, GLfloat writefreq, GLfloat priority);
  48. extern void (__stdcall *pwglFreeMemoryNV)(void *pointer);
  49. #endif
  50. extern void (__stdcall *pglVertexArrayRangeNV)(GLsizei length, void *pointer);
  51. extern void (__stdcall *pglFlushVertexArrayRangeNV)(void);
  52. extern GLboolean (__stdcall *pglTestFenceNV)(GLuint fence);
  53. extern GLboolean (__stdcall *pglIsFenceNV)(GLuint fence);
  54. extern void (__stdcall *pglGenFencesNV)(GLsizei n, GLuint *fences);
  55. extern void (__stdcall *pglDeleteFencesNV)(GLsizei n, const GLuint *fences);
  56. extern void (__stdcall *pglSetFenceNV)(GLuint fence, GLenum condition);
  57. extern void (__stdcall *pglFinishFenceNV)(GLuint fence);
  58. extern void (__stdcall *pglGetFenceivNV)(GLuint fence, GLenum pname, GLint *params);
  59. // ATI GL_ATI[X]_pn_triangles
  60. extern void (__stdcall *pglPNTrianglesiATI)( GLenum pname, GLint param);
  61. extern void (__stdcall *pglPNTrianglesfATI)( GLenum pname, GLfloat param);
  62. // additional tools -----------------------------------------------------
  63. // set color from croteam format
  64. inline void glCOLOR( COLOR col)
  65. {
  66. /* rcg10052001 Platform-wrappers. */
  67. #if (defined USE_PORTABLE_C)
  68. col = ( ((col << 24) ) |
  69. ((col << 8) & 0x00FF0000) |
  70. ((col >> 8) & 0x0000FF00) |
  71. ((col >> 24) ) );
  72. #elif (defined _MSC_VER)
  73. __asm {
  74. mov eax,dword ptr [col]
  75. bswap eax
  76. mov dword ptr [col],eax
  77. }
  78. #elif (defined __GNUC__)
  79. __asm__ __volatile__ (
  80. "bswapl %%eax \n\t"
  81. : "=a" (col)
  82. : "a" (col)
  83. );
  84. #else
  85. #error please define for your platform.
  86. #endif
  87. pglColor4ubv((GLubyte*)&col);
  88. }
  89. // check windows errors always
  90. extern void WIN_CheckError(BOOL bRes, const char *strDescription);
  91. #define WIN_CHECKERROR(result, string) WIN_CheckError(result, string);
  92. extern BOOL glbUsingVARs; // vertex_array_range
  93. // common textures
  94. extern GLuint _uiFillTextureNo; // binding for flat fill emulator texture
  95. extern GLuint _uiFogTextureNo; // binding for fog texture
  96. extern GLuint _uiHazeTextureNo; // binding for haze texture
  97. extern GLuint _uiPatternTextureNo; // binding for pattern texture
  98. // internal!
  99. inline void pglActiveTexture(INDEX texunit)
  100. {
  101. ASSERT( texunit>=0 && texunit<4);
  102. ASSERT( pglActiveTextureARB!=NULL);
  103. ASSERT( pglClientActiveTextureARB!=NULL);
  104. pglActiveTextureARB( GLenum(GL_TEXTURE0_ARB+texunit));
  105. pglClientActiveTextureARB(GLenum(GL_TEXTURE0_ARB+texunit));
  106. }
  107. #endif /* include-once check. */