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.

80 lines
2.0 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. #undef MIN
  10. #undef MAX
  11. #define DONT_DEFINE_BOOL // Don't define BOOL!
  12. #include "tier0/threadtools.h"
  13. #include "tier1/interface.h"
  14. #include "tier1/strtools.h"
  15. #include "tier1/utllinkedlist.h"
  16. #include "glmgr/glmgr.h"
  17. // ------------------------------------------------------------------------------------ //
  18. // some glue to let GLMgr call into NS/ObjC classes.
  19. // ------------------------------------------------------------------------------------ //
  20. bool NewNSGLContext( unsigned long *attribs, PseudoNSGLContextPtr nsglShareCtx, PseudoNSGLContextPtr *nsglCtxOut, CGLContextObj *cglCtxOut )
  21. {
  22. NSAutoreleasePool *tempPool = [[NSAutoreleasePool alloc] init ];
  23. NSOpenGLPixelFormat *pixFmt = NULL;
  24. NSOpenGLContext *nsglCtx = NULL;
  25. bool result = true; // optimism
  26. if (result)
  27. {
  28. pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute*)attribs];
  29. if (!pixFmt)
  30. {
  31. Debugger(); // bad news
  32. result = false;
  33. }
  34. }
  35. if (result)
  36. {
  37. nsglCtx = [[NSOpenGLContext alloc] initWithFormat: pixFmt shareContext: (NSOpenGLContext*) nsglShareCtx ];
  38. if (!nsglCtx)
  39. {
  40. Debugger();
  41. result = false;
  42. }
  43. }
  44. if (result)
  45. {
  46. [nsglCtx makeCurrentContext];
  47. *nsglCtxOut = nsglCtx;
  48. *cglCtxOut = (CGLContextObj)[ (NSOpenGLContext*)nsglCtx CGLContextObj ];
  49. }
  50. else
  51. {
  52. *nsglCtxOut = NULL;
  53. *cglCtxOut = NULL;
  54. }
  55. [tempPool release];
  56. return result;
  57. }
  58. CGLContextObj GetCGLContextFromNSGL( PseudoNSGLContextPtr nsglCtx )
  59. {
  60. return (CGLContextObj)[ (NSOpenGLContext*)nsglCtx CGLContextObj];
  61. }
  62. void DelNSGLContext( PseudoNSGLContextPtr nsglCtx )
  63. {
  64. [ (NSOpenGLContext*)nsglCtx release ];
  65. }