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
35
38
39////////////////////////////////////////////////////////////////////////////////
40/// Constructor.
41
43 fFrameBuffer (0),
44 fColorTexture (0),
45 fDepthBuffer (0),
46 fMSFrameBuffer(0),
47 fMSColorBuffer(0),
48 fW (-1),
49 fH (-1),
50 fReqW (-1),
51 fReqH (-1),
52 fMSSamples (0),
53 fMSCoverageSamples (0),
54 fWScale (1),
55 fHScale (1),
56 fIsRescaled (kFALSE)
57{
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Destructor.
62
64{
65 Release();
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Acquire GL resources for given width, height and number of
70/// multi-sampling samples.
71
72void TGLFBO::Init(int w, int h, int ms_samples)
73{
74 static const std::string eh("TGLFBO::Init ");
75
76 // Should be replaced with ARB_framebuffer_object (SLC6).
78 {
79 throw std::runtime_error(eh + "GL_EXT_framebuffer_object extension required for FBO.");
80 }
81
82 fReqW = w; fReqH = h;
83
86 {
89 if (nw != w || nh != h)
90 {
91 fWScale = ((Float_t)w) / nw;
92 fHScale = ((Float_t)h) / nh;
93 w = nw; h = nh;
95 }
96 }
97
99 {
101 {
102 Info(eh.c_str(), "GL implementation does not support multi-sampling for FBOs.");
104 }
105 ms_samples = 0;
106 }
107
108 if (fFrameBuffer != 0)
109 {
110 if (fW == w && fH == h && fMSSamples == ms_samples)
111 return;
112 Release();
113 }
114
117 if (w > maxSize || h > maxSize)
118 {
119 throw std::runtime_error(eh + Form("maximum size supported by GL implementation is %d.", maxSize));
120 }
121
122 fW = w; fH = h; fMSSamples = ms_samples;
123
124 if (fMSSamples > 0)
125 {
127 {
130 GLint *modes = new GLint[2*n_modes];
132
133 for (int i = 0; i < n_modes; ++i)
134 {
135 if (modes[i*2+1] == fMSSamples && modes[i*2] > fMSCoverageSamples)
137 }
138
139 delete [] modes;
140 }
141 if (gDebug > 0) {
142 Info(eh.c_str(), "InitMultiSample coverage_samples=%d, color_samples=%d.", fMSCoverageSamples, fMSSamples);
143 }
145 }
146 else
147 {
148 if (gDebug > 0) {
149 Info(eh.c_str(), "InitStandard (no multi-sampling).");
150 }
151 InitStandard();
152 }
153
155
158
159 switch (status)
160 {
162 if (gDebug > 0)
163 printf("%sConstructed TGLFBO ... all fine.\n", eh.c_str());
164 break;
166 Release();
167 throw std::runtime_error(eh + "Constructed TGLFBO not supported, choose different formats.");
168 break;
169 default:
170 Release();
171 throw std::runtime_error(eh + "Constructed TGLFBO is not complete, unexpected error.");
172 break;
173 }
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Release the allocated GL resources.
178
192
193////////////////////////////////////////////////////////////////////////////////
194/// Bind the frame-buffer object.
195
197{
198 if (fMSSamples > 0) {
200 // On by default
201 // glEnable(GL_MULTISAMPLE);
202 // Experimenting:
203 // glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
204 // glEnable(GL_SAMPLE_COVERAGE_ARB);
205 } else {
207 }
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Unbind the frame-buffer object.
212
224
225////////////////////////////////////////////////////////////////////////////////
226/// Bind texture.
227
242
243////////////////////////////////////////////////////////////////////////////////
244/// Unbind texture.
245
247{
248 if (fIsRescaled)
249 {
251 glPopMatrix();
253 }
254
255 glPopAttrib();
256}
257
258////////////////////////////////////////////////////////////////////////////////
259
264
265//==============================================================================
266
267////////////////////////////////////////////////////////////////////////////////
268
277
278////////////////////////////////////////////////////////////////////////////////
279
294
295////////////////////////////////////////////////////////////////////////////////
296
320
321////////////////////////////////////////////////////////////////////////////////
322/// Initialize color-texture and attach it to current FB.
323
343
344////////////////////////////////////////////////////////////////////////////////
345/// Return state of fgRescaleToPow2 static member.
346
351
352////////////////////////////////////////////////////////////////////////////////
353/// Set state of fgRescaleToPow2 static member.
354/// Default is kTRUE as this works better on older hardware, especially ATI.
355
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
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
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
void InitStandard()
Definition TGLFBO.cxx:269
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:213
void UnbindTexture()
Unbind texture.
Definition TGLFBO.cxx:246
UInt_t CreateAndAttachRenderBuffer(Int_t format, Int_t type)
Definition TGLFBO.cxx:297
Int_t fMSCoverageSamples
Definition TGLFBO.h:30
virtual ~TGLFBO()
Destructor.
Definition TGLFBO.cxx:63
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:72
UInt_t fMSColorBuffer
Definition TGLFBO.h:28
UInt_t CreateAndAttachColorTexture()
Initialize color-texture and attach it to current FB.
Definition TGLFBO.cxx:324
void Bind()
Bind the frame-buffer object.
Definition TGLFBO.cxx:196
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:356
static Bool_t GetRescaleToPow2()
Return state of fgRescaleToPow2 static member.
Definition TGLFBO.cxx:347
Float_t fWScale
Definition TGLFBO.h:32
TGLFBO()
Constructor.
Definition TGLFBO.cxx:42
void SetAsReadBuffer()
Definition TGLFBO.cxx:260
void Release()
Release the allocated GL resources.
Definition TGLFBO.cxx:179
void InitMultiSample()
Definition TGLFBO.cxx:280
Int_t fReqW
Definition TGLFBO.h:30
void BindTexture()
Bind texture.
Definition TGLFBO.cxx:228
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
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:685