PVRTgles2Ext.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /******************************************************************************
  2. @File PVRTgles2Ext.cpp
  3. @Title PVRTgles2Ext
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform Independent
  7. @Description OpenGL ES 2.0 extensions
  8. ******************************************************************************/
  9. #include <string.h>
  10. #include "PVRTContext.h"
  11. #include "PVRTgles2Ext.h"
  12. /****************************************************************************
  13. ** Local code
  14. ****************************************************************************/
  15. #if defined(TARGET_OS_IPHONE)
  16. // the extensions supported on the iPhone are treated as core functions of gl
  17. // so use this macro to assign the function pointers in this class appropriately.
  18. #define PVRGetProcAddress(x) ::x
  19. #else
  20. #if defined(EGL_NOT_PRESENT) || (defined(__BADA__) && defined(_X86_)) // Bada simulator
  21. #if defined(__PALMPDK__)
  22. #include "SDL.h"
  23. #define PVRGetProcAddress(x) SDL_GLES_GetProcAddress(#x)
  24. #else
  25. #define PVRGetProcAddress(x) NULL
  26. #endif
  27. #else
  28. #define PVRGetProcAddress(x) eglGetProcAddress(#x)
  29. #endif
  30. #endif
  31. /****************************************************************************
  32. ** Class: CPVRTgles2Ext
  33. ****************************************************************************/
  34. /*!***************************************************************************
  35. @Function LoadExtensions
  36. @Description Initialises IMG extensions
  37. *****************************************************************************/
  38. void CPVRTgles2Ext::LoadExtensions()
  39. {
  40. glMultiDrawElementsEXT = 0;
  41. glMultiDrawArraysEXT = 0;
  42. glMapBufferOES = 0;
  43. glUnmapBufferOES = 0;
  44. glGetBufferPointervOES = 0;
  45. glDiscardFramebufferEXT = 0;
  46. // Supported extensions provide new entry points for OpenGL ES 2.0.
  47. const GLubyte *pszGLExtensions;
  48. /* Retrieve GL extension string */
  49. pszGLExtensions = glGetString(GL_EXTENSIONS);
  50. #if !defined(TARGET_OS_IPHONE)
  51. /* GL_EXT_multi_draw_arrays */
  52. if (strstr((char *)pszGLExtensions, "GL_EXT_multi_draw_arrays"))
  53. {
  54. glMultiDrawElementsEXT = (PFNGLMULTIDRAWELEMENTS) PVRGetProcAddress(glMultiDrawElementsEXT);
  55. glMultiDrawArraysEXT = (PFNGLMULTIDRAWARRAYS) PVRGetProcAddress(glMultiDrawArraysEXT);
  56. }
  57. /* GL_EXT_multi_draw_arrays */
  58. if (strstr((char *)pszGLExtensions, "GL_OES_mapbuffer"))
  59. {
  60. glMapBufferOES = (PFNGLMAPBUFFEROES) PVRGetProcAddress(glMapBufferOES);
  61. glUnmapBufferOES = (PFNGLUNMAPBUFFEROES) PVRGetProcAddress(glUnmapBufferOES);
  62. glGetBufferPointervOES = (PFNGLGETBUFFERPOINTERVOES) PVRGetProcAddress(glGetBufferPointervOES);
  63. }
  64. #endif
  65. #if defined(GL_EXT_discard_framebuffer)
  66. /* GL_EXT_discard_framebuffer */
  67. if (strstr((char *)pszGLExtensions, "GL_EXT_discard_framebuffer"))
  68. {
  69. glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXT) PVRGetProcAddress(glDiscardFramebufferEXT);
  70. }
  71. #endif
  72. }
  73. /*!***********************************************************************
  74. @Function IsGLExtensionSupported
  75. @Input extension extension to query for
  76. @Returns True if the extension is supported
  77. @Description Queries for support of an extension
  78. *************************************************************************/
  79. bool CPVRTgles2Ext::IsGLExtensionSupported(const char *extension)
  80. {
  81. // The recommended technique for querying OpenGL extensions;
  82. // from http://opengl.org/resources/features/OGLextensions/
  83. const GLubyte *extensions = NULL;
  84. const GLubyte *start;
  85. GLubyte *where, *terminator;
  86. /* Extension names should not have spaces. */
  87. where = (GLubyte *) strchr(extension, ' ');
  88. if (where || *extension == '\0')
  89. return 0;
  90. extensions = glGetString(GL_EXTENSIONS);
  91. /* It takes a bit of care to be fool-proof about parsing the
  92. OpenGL extensions string. Don't be fooled by sub-strings, etc. */
  93. start = extensions;
  94. for (;;) {
  95. where = (GLubyte *) strstr((const char *) start, extension);
  96. if (!where)
  97. break;
  98. terminator = where + strlen(extension);
  99. if (where == start || *(where - 1) == ' ')
  100. if (*terminator == ' ' || *terminator == '\0')
  101. return true;
  102. start = terminator;
  103. }
  104. return false;
  105. }
  106. /*****************************************************************************
  107. End of file (PVRTglesExt.cpp)
  108. *****************************************************************************/