+#elif defined( __MACH__ )
+ // Get the current context.
+ CGLContextObj hglrc = CGLGetCurrentContext();
+ if (NULL == hglrc)
+ fprintf(stderr, "Couldn't get current context!");
+
+ CGLPixelFormatObj pixFormat = NULL;
+ long int iNumFormats;
+ CGLError error;
+
+ // Copy the _pixelFormatAttribs into another array to fix
+ // typecast issues
+ CGLPixelFormatAttribute *pixFormatAttribs =
+ (CGLPixelFormatAttribute *)malloc(sizeof(CGLPixelFormatAttribute)
+ * _pixelFormatAttribs.size());
+
+ for (unsigned int ii = 0; ii < _pixelFormatAttribs.size(); ii++)
+ {
+ pixFormatAttribs[ii] =
+ (CGLPixelFormatAttribute)_pixelFormatAttribs[ii];
+ }
+
+ if (error =
+ CGLChoosePixelFormat(&pixFormatAttribs[0], &pixFormat, &iNumFormats))
+ {
+ fprintf(stderr,
+ "RenderTexture Error: CGLChoosePixelFormat() failed.\n");
+ _cglCheckError(error);
+ return false;
+ }
+ if ( iNumFormats <= 0 )
+ {
+ fprintf(stderr,
+ "RenderTexture Error: Couldn't find a suitable "+
+ "pixel format.\n");
+ return false;
+ }
+
+ // Free the copy of the _pixelFormatAttribs array
+ free(pixFormatAttribs);
+
+ // Create the context.
+ error = CGLCreateContext(pixFormat, (_bShareObjects)
+ ? CGLGetCurrentContext() : NULL, &_hGLContext);
+ if (error)
+ {
+ fprintf(stderr,
+ "RenderTexture Error: CGLCreateContext() failed.\n");
+ _cglCheckError(error);
+ return false;
+ }
+ CGLDestroyPixelFormat(pixFormat);
+
+ // Create the p-buffer.
+ error = CGLCreatePBuffer(_iWidth, _iHeight, (_bRectangle)
+ ? GL_TEXTURE_RECTANGLE_EXT : GL_TEXTURE_2D, GL_RGBA, 0, &_hPBuffer);
+ if (error)
+ {
+ fprintf(stderr,
+ "RenderTexture Error: CGLCreatePBuffer() failed.\n");
+ _cglCheckError(error);
+ return false;
+ }
+
+ long screen;
+ if (error = CGLGetVirtualScreen(CGLGetCurrentContext(), &screen))
+ {
+ _cglCheckError(error);
+ return false;
+ }
+ if (error = CGLSetPBuffer(_hGLContext, _hPBuffer, 0, 0, screen))
+ {
+ _cglCheckError(error);
+ return false;
+ }
+
+ // Determine the actual width and height we were able to create.
+ //wglQueryPbufferARB( _hPBuffer, WGL_PBUFFER_WIDTH_ARB, &_iWidth );
+ //wglQueryPbufferARB( _hPBuffer, WGL_PBUFFER_HEIGHT_ARB, &_iHeight );
+
+ _bInitialized = true;
+
+ /*
+ // get the actual number of bits allocated:
+ int attrib = WGL_RED_BITS_ARB;
+ //int bits[6];
+ int value;
+ _iNumColorBits[0] =
+ (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ ? value : 0;
+ attrib = WGL_GREEN_BITS_ARB;
+ _iNumColorBits[1] =
+ (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ ? value : 0;
+ attrib = WGL_BLUE_BITS_ARB;
+ _iNumColorBits[2] =
+ (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ ? value : 0;
+ attrib = WGL_ALPHA_BITS_ARB;
+ _iNumColorBits[3] =
+ (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ ? value : 0;
+ attrib = WGL_DEPTH_BITS_ARB;
+ _iNumDepthBits =
+ (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ ? value : 0;
+ attrib = WGL_STENCIL_BITS_ARB;
+ _iNumStencilBits =
+ (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ ? value : 0;
+ attrib = WGL_DOUBLE_BUFFER_ARB;
+ _bDoubleBuffered =
+ (wglGetPixelFormatAttribivARB(_hDC, iFormat, 0, 1, &attrib, &value))
+ ? (value?true:false) : false;
+ */
+
+#if defined(_DEBUG) | defined(DEBUG)
+ fprintf(stderr, "Created a %dx%d RenderTexture with BPP(%d, %d, %d, %d)",
+ _iWidth, _iHeight,
+ _iNumColorBits[0], _iNumColorBits[1],
+ _iNumColorBits[2], _iNumColorBits[3]);
+ if (_iNumDepthBits) fprintf(stderr, " depth=%d", _iNumDepthBits);
+ if (_iNumStencilBits) fprintf(stderr, " stencil=%d", _iNumStencilBits);
+ if (_bDoubleBuffered) fprintf(stderr, " double buffered");
+ fprintf(stderr, "\n");
+#endif
+
+#else // !_WIN32, !__MACH_