File indexing completed on 2023-03-17 11:01:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <stdexcept>
0016
0017
0018
0019 #include "TMath.h"
0020
0021 #include "TGLIncludes.h"
0022 #include "TGLFBO.h"
0023 #include "TGLWidget.h"
0024
0025 #include "Fireworks/Core/interface/FWTGLViewer.h"
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 FWTGLViewer::FWTGLViewer(const TGWindow* parent)
0039 : TGLEmbeddedViewer(parent, nullptr, nullptr, 0), m_fbo(nullptr), m_fbo_w(-1), m_fbo_h(-1) {}
0040
0041
0042
0043
0044
0045
0046 FWTGLViewer::~FWTGLViewer() { delete m_fbo; }
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 void FWTGLViewer::DrawHiLod(Bool_t swap_buffers) {
0069 fRedrawTimer->Stop();
0070
0071
0072 if ((!fGLWidget && fGLDevice == -1) || (fGLWidget && !fGLWidget->IsMapped())) {
0073 return;
0074 }
0075
0076
0077 if (!TakeLock(kDrawLock)) {
0078
0079
0080 Error("FWTGLViewer::DrawHiLodNoSwap", "viewer locked - skipping this draw.");
0081 fRedrawTimer->RequestDraw(100, TGLRnrCtx::kLODHigh);
0082 return;
0083 }
0084
0085 fLOD = TGLRnrCtx::kLODHigh;
0086
0087 DoDraw(swap_buffers);
0088 }
0089
0090 void FWTGLViewer::JustSwap() { fGLWidget->SwapBuffers(); }
0091
0092
0093
0094
0095
0096
0097 TGLFBO* FWTGLViewer::MakeFbo() {
0098
0099
0100 return GenerateFbo(fViewport.Width(), fViewport.Height(), kFALSE);
0101 }
0102
0103
0104 TGLFBO* FWTGLViewer::MakeFboWidth(Int_t width, Bool_t pixel_object_scale) {
0105
0106
0107
0108
0109 Float_t scale = Float_t(width) / fViewport.Width();
0110 Int_t height = TMath::Nint(scale * fViewport.Height());
0111
0112 return GenerateFbo(width, height, pixel_object_scale ? scale : 0);
0113 }
0114
0115
0116 TGLFBO* FWTGLViewer::MakeFboHeight(Int_t height, Bool_t pixel_object_scale) {
0117
0118
0119
0120
0121 Float_t scale = Float_t(height) / fViewport.Height();
0122 Int_t width = TMath::Nint(scale * fViewport.Width());
0123
0124 return GenerateFbo(width, height, pixel_object_scale ? scale : 0);
0125 }
0126
0127
0128 TGLFBO* FWTGLViewer::MakeFboScale(Float_t scale, Bool_t pixel_object_scale) {
0129
0130
0131
0132
0133 Int_t w = TMath::Nint(scale * fViewport.Width());
0134 Int_t h = TMath::Nint(scale * fViewport.Height());
0135
0136 return GenerateFbo(w, h, pixel_object_scale ? scale : 0);
0137 }
0138
0139
0140 TGLFBO* FWTGLViewer::GenerateFbo(Int_t w, Int_t h, Float_t pixel_object_scale) {
0141
0142
0143 static const TString eh("FWTGLViewer::SavePictureUsingFBO");
0144
0145 if (!GLEW_EXT_framebuffer_object) {
0146 ::Warning(eh, "Missing FBO support.");
0147 }
0148
0149 if (!TakeLock(kDrawLock)) {
0150 ::Error(eh, "viewer locked - try later.");
0151 return nullptr;
0152 }
0153
0154 TUnlocker ulck(this);
0155
0156 MakeCurrent();
0157
0158 if (m_fbo == nullptr) {
0159 m_fbo = new TGLFBO();
0160 }
0161 if (m_fbo_w != w || m_fbo_h != h) {
0162 try {
0163 m_fbo->Init(w, h, fGLWidget->GetPixelFormat()->GetSamples());
0164 } catch (std::runtime_error& exc) {
0165 m_fbo_w = m_fbo_h = -1;
0166
0167 ::Error(eh, "%s", exc.what());
0168 return nullptr;
0169 }
0170
0171 m_fbo_w = w;
0172 m_fbo_h = h;
0173 }
0174
0175 TGLRect old_vp(fViewport);
0176 SetViewport(0, 0, w, h);
0177
0178 Float_t old_scale = 1;
0179 if (pixel_object_scale != 0) {
0180 old_scale = fRnrCtx->GetRenderScale();
0181 fRnrCtx->SetRenderScale(old_scale * pixel_object_scale);
0182 }
0183
0184 m_fbo->Bind();
0185
0186 fLOD = TGLRnrCtx::kLODHigh;
0187 fRnrCtx->SetGrabImage(kTRUE);
0188
0189 DoDraw(kFALSE);
0190
0191 fRnrCtx->SetGrabImage(kFALSE);
0192
0193 m_fbo->Unbind();
0194
0195 if (pixel_object_scale != 0) {
0196 fRnrCtx->SetRenderScale(old_scale);
0197 }
0198
0199 SetViewport(old_vp);
0200
0201 return m_fbo;
0202 }
0203
0204
0205
0206
0207
0208
0209
0210