From 34d3361cb932b3dc2564035d219a96f504f3803d Mon Sep 17 00:00:00 2001
From: Timur Pocheptsov <Timur.Pocheptsov@cern.ch>
Date: Mon, 30 Jul 2012 10:08:30 +0000
Subject: [PATCH] Delay glu-quadric initialization, in ctor it can not be done
 - no GL context exist/is current and on Mac gluNewQuadric fails.

git-svn-id: http://root.cern.ch/svn/root/trunk@45281 27541ba8-7e3a-0410-8455-c3a389f83636
---
 graf3d/gl/inc/TGLRnrCtx.h   |  2 +-
 graf3d/gl/src/TGLRnrCtx.cxx | 25 ++++++++++++++++++++-----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/graf3d/gl/inc/TGLRnrCtx.h b/graf3d/gl/inc/TGLRnrCtx.h
index 344200d6d98..176bbede8fc 100644
--- a/graf3d/gl/inc/TGLRnrCtx.h
+++ b/graf3d/gl/inc/TGLRnrCtx.h
@@ -264,7 +264,7 @@ public:
    void  RegisterFontNoScale(Int_t size, const char* name, Int_t mode, TGLFont& out);
    void  ReleaseFont(TGLFont& font);
 
-   GLUquadric* GetGluQuadric() { return fQuadric; }
+   GLUquadric* GetGluQuadric();
 
    // Picture grabbing
    void     SetGrabImage(Bool_t gi) { fGrabImage = gi;   }
diff --git a/graf3d/gl/src/TGLRnrCtx.cxx b/graf3d/gl/src/TGLRnrCtx.cxx
index 45e66ab8d04..d88c471b94e 100644
--- a/graf3d/gl/src/TGLRnrCtx.cxx
+++ b/graf3d/gl/src/TGLRnrCtx.cxx
@@ -108,10 +108,6 @@ TGLRnrCtx::TGLRnrCtx(TGLViewerBase* viewer) :
    fColorSetStack->push_back(0);
 
    fSelectBuffer = new TGLSelectBuffer;
-   fQuadric = gluNewQuadric();
-   gluQuadricOrientation(fQuadric, (GLenum)GLU_OUTSIDE);
-   gluQuadricNormals    (fQuadric, (GLenum)GLU_SMOOTH);
-
    if (fViewer == 0)
    {
       // Assume external usage, initialize for highest quality.
@@ -353,7 +349,6 @@ void TGLRnrCtx::CloseDLCapture()
    fDLCaptureOpen = kFALSE;
 }
 
-
 /******************************************************************************/
 // TGLFont interface
 /******************************************************************************/
@@ -399,6 +394,26 @@ void TGLRnrCtx::RegisterFont(Int_t size, const char* name, Int_t mode, TGLFont&
   RegisterFontNoScale(TMath::Nint(size*fRenderScale), name, mode, out);
 }
 
+/******************************************************************************/
+// fQuadric's initialization.
+/******************************************************************************/
+
+//______________________________________________________________________
+GLUquadric *TGLRnrCtx::GetGluQuadric()
+{
+   // Initialize fQuadric.
+   
+   if (!fQuadric) {
+      if ((fQuadric = gluNewQuadric())) {
+         gluQuadricOrientation(fQuadric, (GLenum)GLU_OUTSIDE);
+         gluQuadricNormals(fQuadric, (GLenum)GLU_SMOOTH);
+      } else
+         Error("TGLRnrCtx::GetGluQuadric", "gluNewQuadric failed");
+   }
+   
+   return fQuadric;
+}
+
 
 /******************************************************************************/
 // Matrix manipulation helpers
-- 
GitLab