Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLFBO.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Matevz Tadel, Aug 2009
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TGLFBO.h"
13#include "TGLIncludes.h"
14#include <TMath.h>
15#include <TString.h>
16#include <TError.h>
17
18#include <stdexcept>
19
20/** \class TGLFBO
21\ingroup opengl
22Frame-buffer object.
23
24Requires GL-1.5.
25
26Taken from Gled project, see:
27
28 http://www.gled.org/cgi-bin/viewcvs.cgi/trunk/libsets/GledCore/Pupils/
29
30See also:
31
32 http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt
33*/
34
36
39
40////////////////////////////////////////////////////////////////////////////////
41/// Constructor.
42
44 fFrameBuffer (0),
45 fColorTexture (0),
46 fDepthBuffer (0),
47 fMSFrameBuffer(0),
48 fMSColorBuffer(0),
49 fW (-1),
50 fH (-1),
51 fReqW (-1),
52 fReqH (-1),
53 fMSSamples (0),
54 fMSCoverageSamples (0),
55 fWScale (1),
56 fHScale (1),
57 fIsRescaled (kFALSE)
58{
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Destructor.
63
65{
66 Release();
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Acquire GL resources for given width, height and number of
71/// multi-sampling samples.
72
73void TGLFBO::Init(int w, int h, int ms_samples)
74{
75 static const std::string eh("TGLFBO::Init ");
76
77 // Should be replaced with ARB_framebuffer_object (SLC6).
79 {
80 throw std::runtime_error(eh + "GL_EXT_framebuffer_object extension required for FBO.");
81 }
82
83 fReqW = w; fReqH = h;
84
87 {
90 if (nw != w || nh != h)
91 {
92 fWScale = ((Float_t)w) / nw;
93 fHScale = ((Float_t)h) / nh;
94 w = nw; h = nh;
96 }
97 }
98
100 {
102 {
103 Info(eh.c_str(), "GL implementation does not support multi-sampling for FBOs.");
105 }
106 ms_samples = 0;
107 }
108
109 if (fFrameBuffer != 0)
110 {
111 if (fW == w && fH == h && fMSSamples == ms_samples)
112 return;
113 Release();
114 }
115
118 if (w > maxSize || h > maxSize)
119 {
120 throw std::runtime_error(eh + Form("maximum size supported by GL implementation is %d.", maxSize));
121 }
122
123 fW = w; fH = h; fMSSamples = ms_samples;
124
125 if (fMSSamples > 0)
126 {
128 {
131 GLint *modes = new GLint[2*n_modes];
133
134 for (int i = 0; i < n_modes; ++i)
135 {
136 if (modes[i*2+1] == fMSSamples && modes[i*2] > fMSCoverageSamples)
138 }
139
140 delete [] modes;
141 }
142 if (gDebug > 0) {
143 Info(eh.c_str(), "InitMultiSample coverage_samples=%d, color_samples=%d.", fMSCoverageSamples, fMSSamples);
144 }
146 }
147 else
148 {
149 if (gDebug > 0) {
150 Info(eh.c_str(), "InitStandard (no multi-sampling).");
151 }
152 InitStandard();
153 }
154
156
159
160 switch (status)
161 {
163 if (gDebug > 0)
164 printf("%sConstructed TGLFBO ... all fine.\n", eh.c_str());
165 break;
167 Release();
168 throw std::runtime_error(eh + "Constructed TGLFBO not supported, choose different formats.");
169 break;
170 default:
171 Release();
172 throw std::runtime_error(eh + "Constructed TGLFBO is not complete, unexpected error.");
173 break;
174 }
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Release the allocated GL resources.
179
193
194////////////////////////////////////////////////////////////////////////////////
195/// Bind the frame-buffer object.
196
198{
199 if (fMSSamples > 0) {
201 // On by default
202 // glEnable(GL_MULTISAMPLE);
203 // Experimenting:
204 // glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
205 // glEnable(GL_SAMPLE_COVERAGE_ARB);
206 } else {
208 }
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Unbind the frame-buffer object.
213
225
226////////////////////////////////////////////////////////////////////////////////
227/// Bind texture.
228
243
244////////////////////////////////////////////////////////////////////////////////
245/// Unbind texture.
246
248{
249 if (fIsRescaled)
250 {
252 glPopMatrix();
254 }
255
256 glPopAttrib();
257}
258
259////////////////////////////////////////////////////////////////////////////////
260
265
266//==============================================================================
267
268////////////////////////////////////////////////////////////////////////////////
269
278
279////////////////////////////////////////////////////////////////////////////////
280
295
296////////////////////////////////////////////////////////////////////////////////
297
321
322////////////////////////////////////////////////////////////////////////////////
323/// Initialize color-texture and attach it to current FB.
324
344
345////////////////////////////////////////////////////////////////////////////////
346/// Return state of fgRescaleToPow2 static member.
347
352
353////////////////////////////////////////////////////////////////////////////////
354/// Set state of fgRescaleToPow2 static member.
355/// Default is kTRUE as this works better on older hardware, especially ATI.
356
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Int_t gDebug
Definition TROOT.cxx:597
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
Frame-buffer object.
Definition TGLFBO.h:18
void InitStandard()
Definition TGLFBO.cxx:270
UInt_t fDepthBuffer
Definition TGLFBO.h:26
static Bool_t fgMultiSampleNAWarned
Definition TGLFBO.h:36
Int_t fW
Definition TGLFBO.h:30
void Unbind()
Unbind the frame-buffer object.
Definition TGLFBO.cxx:214
void UnbindTexture()
Unbind texture.
Definition TGLFBO.cxx:247
UInt_t CreateAndAttachRenderBuffer(Int_t format, Int_t type)
Definition TGLFBO.cxx:298
Int_t fMSCoverageSamples
Definition TGLFBO.h:30
virtual ~TGLFBO()
Destructor.
Definition TGLFBO.cxx:64
void Init(int w, int h, int ms_samples=0)
Acquire GL resources for given width, height and number of multi-sampling samples.
Definition TGLFBO.cxx:73
UInt_t fMSColorBuffer
Definition TGLFBO.h:28
UInt_t CreateAndAttachColorTexture()
Initialize color-texture and attach it to current FB.
Definition TGLFBO.cxx:325
void Bind()
Bind the frame-buffer object.
Definition TGLFBO.cxx:197
Float_t fHScale
Definition TGLFBO.h:32
Bool_t fIsRescaled
Definition TGLFBO.h:33
static void SetRescaleToPow2(Bool_t r)
Set state of fgRescaleToPow2 static member.
Definition TGLFBO.cxx:357
static Bool_t GetRescaleToPow2()
Return state of fgRescaleToPow2 static member.
Definition TGLFBO.cxx:348
Float_t fWScale
Definition TGLFBO.h:32
TGLFBO()
Constructor.
Definition TGLFBO.cxx:43
void SetAsReadBuffer()
Definition TGLFBO.cxx:261
void Release()
Release the allocated GL resources.
Definition TGLFBO.cxx:180
void InitMultiSample()
Definition TGLFBO.cxx:281
Int_t fReqW
Definition TGLFBO.h:30
void BindTexture()
Bind texture.
Definition TGLFBO.cxx:229
UInt_t fFrameBuffer
Definition TGLFBO.h:24
UInt_t fColorTexture
Definition TGLFBO.h:25
Int_t fMSSamples
Definition TGLFBO.h:30
Int_t fReqH
Definition TGLFBO.h:30
static Bool_t fgRescaleToPow2
Definition TGLFBO.h:35
Int_t fH
Definition TGLFBO.h:30
UInt_t fMSFrameBuffer
Definition TGLFBO.h:27
std::ostream & Info()
Definition hadd.cxx:171
Double_t Log2(Double_t x)
Returns the binary (base-2) logarithm of x.
Definition TMath.cxx:107
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).
Definition TMath.h:678