CMS 3D CMS Logo

List of all members | Public 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)
 
 FWTGLViewer (const FWTGLViewer &)=delete
 
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)
 
const FWTGLVieweroperator= (const FWTGLViewer &)=delete
 
 ~FWTGLViewer () override
 

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() [1/2]

FWTGLViewer::FWTGLViewer ( const TGWindow *  parent)

Definition at line 38 of file FWTGLViewer.cc.

39  : TGLEmbeddedViewer(parent, nullptr, nullptr, 0), m_fbo(nullptr), m_fbo_w(-1), m_fbo_h(-1) {}
TGLFBO * m_fbo
Definition: FWTGLViewer.h:60

◆ ~FWTGLViewer()

FWTGLViewer::~FWTGLViewer ( )
override

Definition at line 46 of file FWTGLViewer.cc.

References m_fbo.

46 { delete m_fbo; }
TGLFBO * m_fbo
Definition: FWTGLViewer.h:60

◆ FWTGLViewer() [2/2]

FWTGLViewer::FWTGLViewer ( const FWTGLViewer )
delete

Member Function Documentation

◆ DrawHiLod()

void FWTGLViewer::DrawHiLod ( Bool_t  swap_buffers)

Definition at line 68 of file FWTGLViewer.cc.

68  {
69  fRedrawTimer->Stop();
70 
71  // Ignore request if GL window or context not yet availible or shown.
72  if ((!fGLWidget && fGLDevice == -1) || (fGLWidget && !fGLWidget->IsMapped())) {
73  return;
74  }
75 
76  // Take scene draw lock - to be revisited
77  if (!TakeLock(kDrawLock)) {
78  // If taking drawlock fails the previous draw is still in progress
79  // set timer to do this one later
80  Error("FWTGLViewer::DrawHiLodNoSwap", "viewer locked - skipping this draw.");
81  fRedrawTimer->RequestDraw(100, TGLRnrCtx::kLODHigh);
82  return;
83  }
84 
85  fLOD = TGLRnrCtx::kLODHigh;
86 
87  DoDraw(swap_buffers);
88 }
edm::ErrorSummaryEntry Error

◆ GenerateFbo()

TGLFBO * FWTGLViewer::GenerateFbo ( Int_t  w,
Int_t  h,
Float_t  pixel_object_scale 
)

Definition at line 140 of file FWTGLViewer.cc.

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

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

140  {
141  // Generate FBO -- function that does the actual work.
142 
143  static const TString eh("FWTGLViewer::SavePictureUsingFBO");
144 
145  if (!GLEW_EXT_framebuffer_object) {
146  ::Warning(eh, "Missing FBO support.");
147  }
148 
149  if (!TakeLock(kDrawLock)) {
150  ::Error(eh, "viewer locked - try later.");
151  return nullptr;
152  }
153 
154  TUnlocker ulck(this);
155 
156  MakeCurrent();
157 
158  if (m_fbo == nullptr) {
159  m_fbo = new TGLFBO();
160  }
161  if (m_fbo_w != w || m_fbo_h != h) {
162  try {
163  m_fbo->Init(w, h, fGLWidget->GetPixelFormat()->GetSamples());
164  } catch (std::runtime_error& exc) {
165  m_fbo_w = m_fbo_h = -1;
166 
167  ::Error(eh, "%s", exc.what());
168  return nullptr;
169  }
170 
171  m_fbo_w = w;
172  m_fbo_h = h;
173  }
174 
175  TGLRect old_vp(fViewport);
176  SetViewport(0, 0, w, h);
177 
178  Float_t old_scale = 1;
179  if (pixel_object_scale != 0) {
180  old_scale = fRnrCtx->GetRenderScale();
181  fRnrCtx->SetRenderScale(old_scale * pixel_object_scale);
182  }
183 
184  m_fbo->Bind();
185 
186  fLOD = TGLRnrCtx::kLODHigh;
187  fRnrCtx->SetGrabImage(kTRUE);
188 
189  DoDraw(kFALSE);
190 
191  fRnrCtx->SetGrabImage(kFALSE);
192 
193  m_fbo->Unbind();
194 
195  if (pixel_object_scale != 0) {
196  fRnrCtx->SetRenderScale(old_scale);
197  }
198 
199  SetViewport(old_vp);
200 
201  return m_fbo;
202 }
edm::ErrorSummaryEntry Error
T w() const
TGLFBO * m_fbo
Definition: FWTGLViewer.h:60
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ JustSwap()

void FWTGLViewer::JustSwap ( )

Definition at line 90 of file FWTGLViewer.cc.

90 { fGLWidget->SwapBuffers(); }

◆ MakeFbo()

TGLFBO * FWTGLViewer::MakeFbo ( )

Definition at line 97 of file FWTGLViewer.cc.

References GenerateFbo().

Referenced by FWTEveViewer::CaptureAndSaveImage().

97  {
98  // Generate FBO with same dimensions as the viewport.
99 
100  return GenerateFbo(fViewport.Width(), fViewport.Height(), kFALSE);
101 }
TGLFBO * GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale)
Definition: FWTGLViewer.cc:140

◆ MakeFboHeight()

TGLFBO * FWTGLViewer::MakeFboHeight ( Int_t  height,
Bool_t  pixel_object_scale = kTRUE 
)

Definition at line 116 of file FWTGLViewer.cc.

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

Referenced by FWTEveViewer::CaptureAndSaveImage().

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

◆ MakeFboScale()

TGLFBO * FWTGLViewer::MakeFboScale ( Float_t  scale,
Bool_t  pixel_object_scale = kTRUE 
)

Definition at line 128 of file FWTGLViewer.cc.

References GenerateFbo(), h, L1EGammaClusterEmuProducer_cfi::scale, and w().

128  {
129  // Generate FBO with given scale to current window size.
130  // If pixel_object_scale is true (default), the same scaling is
131  // used.
132 
133  Int_t w = TMath::Nint(scale * fViewport.Width());
134  Int_t h = TMath::Nint(scale * fViewport.Height());
135 
136  return GenerateFbo(w, h, pixel_object_scale ? scale : 0);
137 }
TGLFBO * GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale)
Definition: FWTGLViewer.cc:140
T w() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ MakeFboWidth()

TGLFBO * FWTGLViewer::MakeFboWidth ( Int_t  width,
Bool_t  pixel_object_scale = kTRUE 
)

Definition at line 104 of file FWTGLViewer.cc.

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

104  {
105  // Generate FBO with given width (height scaled proportinally).
106  // If pixel_object_scale is true (default), the corresponding
107  // scaling gets calculated from the current window size.
108 
109  Float_t scale = Float_t(width) / fViewport.Width();
110  Int_t height = TMath::Nint(scale * fViewport.Height());
111 
112  return GenerateFbo(width, height, pixel_object_scale ? scale : 0);
113 }
TGLFBO * GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale)
Definition: FWTGLViewer.cc:140

◆ operator=()

const FWTGLViewer& FWTGLViewer::operator= ( const FWTGLViewer )
delete

Member Data Documentation

◆ m_fbo

TGLFBO* FWTGLViewer::m_fbo
private

Definition at line 60 of file FWTGLViewer.h.

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

◆ m_fbo_h

int FWTGLViewer::m_fbo_h
private

Definition at line 61 of file FWTGLViewer.h.

Referenced by GenerateFbo().

◆ m_fbo_w

int FWTGLViewer::m_fbo_w
private

Definition at line 61 of file FWTGLViewer.h.

Referenced by GenerateFbo().