Counter Strike : Global Offensive Source Code
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.

104 lines
3.1 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. //
  3. // glmgrext.h
  4. // helper file for extension testing and runtime importing of entry points
  5. //
  6. //===============================================================================
  7. #pragma once
  8. #include <OpenGL/gl.h>
  9. #include <OpenGL/glext.h>
  10. #include <mach-o/dyld.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "glmgr/glmgr.h"
  14. PFNglColorMaskIndexedEXT pfnglColorMaskIndexedEXT;
  15. PFNglEnableIndexedEXT pfnglEnableIndexedEXT;
  16. PFNglDisableIndexedEXT pfnglDisableIndexedEXT;
  17. PFNglGetFramebufferAttachmentParameteriv pfnglGetFramebufferAttachmentParameteriv;
  18. PFNglUniformBufferEXT pfnglUniformBufferEXT;
  19. void * NSGLGetProcAddress (const char *name)
  20. {
  21. NSSymbol symbol;
  22. char *symbolName = (char *)malloc (strlen (name) + 2);
  23. strcpy(symbolName + 1, name);
  24. symbolName[0] = '_';
  25. symbol = NULL;
  26. if (NSIsSymbolNameDefined (symbolName))
  27. symbol = NSLookupAndBindSymbol (symbolName);
  28. free (symbolName);
  29. return symbol ? NSAddressOfSymbol (symbol) : NULL;
  30. }
  31. void GLMSetupExtensions( void )
  32. {
  33. pfnglColorMaskIndexedEXT = (PFNglColorMaskIndexedEXT) NSGLGetProcAddress( "glColorMaskIndexedEXT" );
  34. pfnglEnableIndexedEXT = (PFNglEnableIndexedEXT) NSGLGetProcAddress( "glEnableIndexedEXT" );
  35. pfnglDisableIndexedEXT = (PFNglDisableIndexedEXT) NSGLGetProcAddress( "glDisableIndexedEXT" );
  36. pfnglGetFramebufferAttachmentParameteriv = (PFNglGetFramebufferAttachmentParameteriv) NSGLGetProcAddress( "glGetFramebufferAttachmentParameteriv" );
  37. pfnglUniformBufferEXT = (PFNglUniformBufferEXT) NSGLGetProcAddress( "glUniformBufferEXT" );
  38. }
  39. /*
  40. #define INSTANTIATE_GL_IMPORTS
  41. #include "glmgr/glmgr.h" // will include glmgrext.h
  42. #undef INSTANTIATE_GL_IMPORTS
  43. // helper class for looking up function names
  44. // see http://andrewtolbert.com/svn/personal/OpenGLSuperBible/shared/gltools.cpp
  45. // also http://developer.apple.com/mac/library/DOCUMENTATION/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_entrypts/opengl_entrypts.html
  46. class CFunctionImporter
  47. {
  48. public:
  49. CFBundleRef m_bundle;
  50. CFunctionImporter( CFStringRef bundleID ) // for example CFSTR("com.apple.OpenGL")
  51. {
  52. m_bundle = CFBundleGetBundleWithIdentifier( bundleID );
  53. if ( m_bundle )
  54. CFRetain( m_bundle );
  55. }
  56. ~CFunctionImporter()
  57. {
  58. if( m_bundle )
  59. {
  60. CFRelease(m_bundle);
  61. m_bundle = NULL;
  62. }
  63. }
  64. void *FindFunctionByName(CFStringRef name) // ex CFSTR("glColorMaskedIndexedEXT")
  65. {
  66. void *result = NULL;
  67. if (m_bundle)
  68. {
  69. result = CFBundleGetFunctionPointerForName(m_bundle, name);
  70. }
  71. return result;
  72. }
  73. };
  74. void GLMSetupExtensions( void )
  75. {
  76. CFunctionImporter importer( CFSTR("com.apple.OpenGL") );
  77. #define DO_IMPORT(name) name = (name##FuncPtr)importer.FindFunctionByName( CFSTR(#name) );
  78. #ifndef GL_EXT_draw_buffers2
  79. // FIXME we're not checking for the extension string yet, we're just grabbing func ptrs
  80. DO_IMPORT(glColorMaskIndexedEXT);
  81. DO_IMPORT(glEnableIndexedEXT);
  82. DO_IMPORT(glDisableIndexedEXT);
  83. #endif
  84. }
  85. */