CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
FWTGLViewer Class Reference

#include "FWTGLViewer.h"

Inheritance diagram for FWTGLViewer:

Public Member Functions

void DrawHiLod (Bool_t swap_buffers)
 
 FWTGLViewer (const TGWindow *parent)
 
TGLFBO * GenerateFbo (Int_t w, Int_t h, Float_t pixel_object_scale)
 
void JustSwap ()
 
TGLFBO * MakeFbo ()
 
TGLFBO * MakeFboHeight (Int_t height, Bool_t pixel_object_scale=kTRUE)
 
TGLFBO * MakeFboScale (Float_t scale, Bool_t pixel_object_scale=kTRUE)
 
TGLFBO * MakeFboWidth (Int_t width, Bool_t pixel_object_scale=kTRUE)
 
virtual ~FWTGLViewer ()
 

Private Member Functions

 FWTGLViewer (const FWTGLViewer &)
 
const FWTGLVieweroperator= (const FWTGLViewer &)
 

Private Attributes

TGLFBO * m_fbo
 
int m_fbo_h
 
int m_fbo_w
 

Detailed Description

Description: [one line class summary]

Usage: <usage>

Definition at line 32 of file FWTGLViewer.h.

Constructor & Destructor Documentation

FWTGLViewer::FWTGLViewer ( const TGWindow *  parent)

Definition at line 39 of file FWTGLViewer.cc.

39  :
40  TGLEmbeddedViewer(parent, 0, 0, 0),
41  m_fbo(0),
42  m_fbo_w(-1), m_fbo_h(-1)
43 {
44 }
TGLFBO * m_fbo
Definition: FWTGLViewer.h:62
FWTGLViewer::~FWTGLViewer ( )
virtual

Definition at line 51 of file FWTGLViewer.cc.

References m_fbo.

52 {
53  delete m_fbo;
54 }
TGLFBO * m_fbo
Definition: FWTGLViewer.h:62
FWTGLViewer::FWTGLViewer ( const FWTGLViewer )
private

Member Function Documentation

void FWTGLViewer::DrawHiLod ( Bool_t  swap_buffers)

Definition at line 76 of file FWTGLViewer.cc.

77 {
78  fRedrawTimer->Stop();
79 
80  // Ignore request if GL window or context not yet availible or shown.
81  if ((!fGLWidget && fGLDevice == -1) || (fGLWidget && !fGLWidget->IsMapped()))
82  {
83  return;
84  }
85 
86  // Take scene draw lock - to be revisited
87  if ( ! TakeLock(kDrawLock))
88  {
89  // If taking drawlock fails the previous draw is still in progress
90  // set timer to do this one later
91  Error("FWTGLViewer::DrawHiLodNoSwap", "viewer locked - skipping this draw.");
92  fRedrawTimer->RequestDraw(100, TGLRnrCtx::kLODHigh);
93  return;
94  }
95 
96  fLOD = TGLRnrCtx::kLODHigh;
97 
98  DoDraw(swap_buffers);
99 }
TGLFBO * FWTGLViewer::GenerateFbo ( Int_t  w,
Int_t  h,
Float_t  pixel_object_scale 
)

Definition at line 158 of file FWTGLViewer.cc.

References h, m_fbo, m_fbo_h, m_fbo_w, and w.

Referenced by MakeFbo(), MakeFboHeight(), MakeFboScale(), and MakeFboWidth().

159 {
160  // Generate FBO -- function that does the actual work.
161 
162  static const TString eh("FWTGLViewer::SavePictureUsingFBO");
163 
164  if ( ! GLEW_EXT_framebuffer_object)
165  {
166  ::Warning(eh, "Missing FBO support.");
167  }
168 
169  if ( ! TakeLock(kDrawLock)) {
170  ::Error(eh, "viewer locked - try later.");
171  return 0;
172  }
173 
174  TUnlocker ulck(this);
175 
176  MakeCurrent();
177 
178  if (m_fbo == 0)
179  {
180  m_fbo = new TGLFBO();
181  }
182  if (m_fbo_w != w || m_fbo_h != h)
183  {
184  try
185  {
186  m_fbo->Init(w, h, fGLWidget->GetPixelFormat()->GetSamples());
187  }
188  catch (std::runtime_error& exc)
189  {
190  m_fbo_w = m_fbo_h = -1;
191 
192  ::Error(eh, "%s",exc.what());
193  return 0;
194  }
195 
196  m_fbo_w = w; m_fbo_h = h;
197  }
198 
199  TGLRect old_vp(fViewport);
200  SetViewport(0, 0, w, h);
201 
202  Float_t old_scale = 1;
203  if (pixel_object_scale != 0)
204  {
205  old_scale = fRnrCtx->GetRenderScale();
206  fRnrCtx->SetRenderScale(old_scale * pixel_object_scale);
207  }
208 
209  m_fbo->Bind();
210 
211  fLOD = TGLRnrCtx::kLODHigh;
212  fRnrCtx->SetGrabImage(kTRUE);
213 
214  DoDraw(kFALSE);
215 
216  fRnrCtx->SetGrabImage(kFALSE);
217 
218  m_fbo->Unbind();
219 
220  if (pixel_object_scale != 0)
221  {
222  fRnrCtx->SetRenderScale(old_scale);
223  }
224 
225  SetViewport(old_vp);
226 
227  return m_fbo;
228 }
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
TGLFBO * m_fbo
Definition: FWTGLViewer.h:62
void FWTGLViewer::JustSwap ( )

Definition at line 101 of file FWTGLViewer.cc.

102 {
103  fGLWidget->SwapBuffers();
104 }
TGLFBO * FWTGLViewer::MakeFbo ( )

Definition at line 111 of file FWTGLViewer.cc.

References GenerateFbo().

Referenced by FWTEveViewer::CaptureAndSaveImage().

112 {
113  // Generate FBO with same dimensions as the viewport.
114 
115  return GenerateFbo(fViewport.Width(), fViewport.Height(), kFALSE);
116 }
TGLFBO * GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale)
Definition: FWTGLViewer.cc:158
TGLFBO * FWTGLViewer::MakeFboHeight ( Int_t  height,
Bool_t  pixel_object_scale = kTRUE 
)

Definition at line 132 of file FWTGLViewer.cc.

References GenerateFbo(), Scenarios_cff::scale, and ApeEstimator_cff::width.

Referenced by FWTEveViewer::CaptureAndSaveImage().

133 {
134  // Generate FBO with given height (width scaled proportinally).
135  // If pixel_object_scale is true (default), the corresponding
136  // scaling gets calculated from the current window size.
137 
138  Float_t scale = Float_t(height) / fViewport.Height();
139  Int_t width = TMath::Nint(scale*fViewport.Width());
140 
141  return GenerateFbo(width, height, pixel_object_scale ? scale : 0);
142 }
TGLFBO * GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale)
Definition: FWTGLViewer.cc:158
TGLFBO * FWTGLViewer::MakeFboScale ( Float_t  scale,
Bool_t  pixel_object_scale = kTRUE 
)

Definition at line 145 of file FWTGLViewer.cc.

References GenerateFbo(), and w.

146 {
147  // Generate FBO with given scale to current window size.
148  // If pixel_object_scale is true (default), the same scaling is
149  // used.
150 
151  Int_t w = TMath::Nint(scale*fViewport.Width());
152  Int_t h = TMath::Nint(scale*fViewport.Height());
153 
154  return GenerateFbo(w, h, pixel_object_scale ? scale : 0);
155 }
TGLFBO * GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale)
Definition: FWTGLViewer.cc:158
const double w
Definition: UKUtility.cc:23
TGLFBO * FWTGLViewer::MakeFboWidth ( Int_t  width,
Bool_t  pixel_object_scale = kTRUE 
)

Definition at line 119 of file FWTGLViewer.cc.

References GenerateFbo(), and Scenarios_cff::scale.

120 {
121  // Generate FBO with given width (height scaled proportinally).
122  // If pixel_object_scale is true (default), the corresponding
123  // scaling gets calculated from the current window size.
124 
125  Float_t scale = Float_t(width) / fViewport.Width();
126  Int_t height = TMath::Nint(scale*fViewport.Height());
127 
128  return GenerateFbo(width, height, pixel_object_scale ? scale : 0);
129 }
TGLFBO * GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale)
Definition: FWTGLViewer.cc:158
const FWTGLViewer& FWTGLViewer::operator= ( const FWTGLViewer )
private

Member Data Documentation

TGLFBO* FWTGLViewer::m_fbo
private

Definition at line 62 of file FWTGLViewer.h.

Referenced by GenerateFbo(), and ~FWTGLViewer().

int FWTGLViewer::m_fbo_h
private

Definition at line 63 of file FWTGLViewer.h.

Referenced by GenerateFbo().

int FWTGLViewer::m_fbo_w
private

Definition at line 63 of file FWTGLViewer.h.

Referenced by GenerateFbo().