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.

85 lines
2.1 KiB

  1. //========= Copyright 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: provide some call-out glue to ObjC from the C++ GLMgr code
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include <Cocoa/Cocoa.h>
  9. #include <OpenGL/OpenGL.h>
  10. #include <OpenGL/gl.h>
  11. #include <OpenGL/glext.h>
  12. #undef MIN
  13. #undef MAX
  14. #define DONT_DEFINE_BOOL // Don't define BOOL!
  15. #include "tier0/threadtools.h"
  16. #include "tier1/interface.h"
  17. #include "tier1/strtools.h"
  18. #include "tier1/utllinkedlist.h"
  19. #include "togl/rendermechanism.h"
  20. // ------------------------------------------------------------------------------------ //
  21. // some glue to let GLMgr call into NS/ObjC classes.
  22. // ------------------------------------------------------------------------------------ //
  23. bool NewNSGLContext( unsigned long *attribs, PseudoNSGLContextPtr nsglShareCtx, PseudoNSGLContextPtr *nsglCtxOut, CGLContextObj *cglCtxOut )
  24. {
  25. NSAutoreleasePool *tempPool = [[NSAutoreleasePool alloc] init ];
  26. NSOpenGLPixelFormat *pixFmt = NULL;
  27. NSOpenGLContext *nsglCtx = NULL;
  28. bool result = true; // optimism
  29. if (result)
  30. {
  31. pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute*)attribs];
  32. if (!pixFmt)
  33. {
  34. Debugger(); // bad news
  35. result = false;
  36. }
  37. }
  38. if (result)
  39. {
  40. nsglCtx = [[NSOpenGLContext alloc] initWithFormat: pixFmt shareContext: (NSOpenGLContext*) nsglShareCtx ];
  41. if (!nsglCtx)
  42. {
  43. Debugger();
  44. result = false;
  45. }
  46. }
  47. if (result)
  48. {
  49. [nsglCtx makeCurrentContext];
  50. *nsglCtxOut = nsglCtx;
  51. *cglCtxOut = (CGLContextObj)[ (NSOpenGLContext*)nsglCtx CGLContextObj ];
  52. }
  53. else
  54. {
  55. *nsglCtxOut = NULL;
  56. *cglCtxOut = NULL;
  57. }
  58. [tempPool release];
  59. return result;
  60. }
  61. CGLContextObj GetCGLContextFromNSGL( PseudoNSGLContextPtr nsglCtx )
  62. {
  63. return (CGLContextObj)[ (NSOpenGLContext*)nsglCtx CGLContextObj];
  64. }
  65. void DelNSGLContext( PseudoNSGLContextPtr nsglCtx )
  66. {
  67. [ (NSOpenGLContext*)nsglCtx release ];
  68. }