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).
77 // Similar for GL_EXT_framebuffer_multisample.
78 // This then requires changing all relevant EXT calls and enums.
80 {
81 throw std::runtime_error(eh + "GL_EXT_framebuffer_object extension required for FBO.");
82 }
83
84 fReqW = w; fReqH = h;
85
88 {
91 if (nw != w || nh != h)
92 {
93 fWScale = ((Float_t)w) / nw;
94 fHScale = ((Float_t)h) / nh;
95 w = nw; h = nh;
97 }
98 }
99
101 {
103 {
104 Info(eh.c_str(), "GL implementation does not support multi-sampling for FBOs.");
106 }
107 ms_samples = 0;
108 }
109
110 if (fFrameBuffer != 0)
111 {
112 if (fW == w && fH == h && fMSSamples == ms_samples)
113 return;
114 Release();
115 }
116
119 if (w > maxSize || h > maxSize)
120 {
121 throw std::runtime_error(eh + Form("maximum size supported by GL implementation is %d.", maxSize));
122 }
123
124 fW = w; fH = h; fMSSamples = ms_samples;
125
126 if (fMSSamples > 0)
127 {
129 {
132 GLint *modes = new GLint[2*n_modes];
134
135 for (int i = 0; i < n_modes; ++i)
136 {
137 if (modes[i*2+1] == fMSSamples && modes[i*2] > fMSCoverageSamples)
139 }
140
141 delete [] modes;
142 }
143 if (gDebug > 0) {
144 Info(eh.c_str(), "InitMultiSample coverage_samples=%d, color_samples=%d.", fMSCoverageSamples, fMSSamples);
145 }
147 }
148 else
149 {
150 if (gDebug > 0) {
151 Info(eh.c_str(), "InitStandard (no multi-sampling).");
152 }
153 InitStandard();
154 }
155
157
160
161 switch (status)
162 {
164 if (gDebug > 0)
165 printf("%sConstructed TGLFBO ... all fine.\n", eh.c_str());
166 break;
168 Release();
169 throw std::runtime_error(eh + "Constructed TGLFBO not supported, choose different formats.");
170 break;
171 default:
172 Release();
173 throw std::runtime_error(eh + "Constructed TGLFBO is not complete, unexpected error.");
174 break;
175 }
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Release the allocated GL resources.
180
194
195////////////////////////////////////////////////////////////////////////////////
196/// Bind the frame-buffer object.
197
199{
200 if (fMSSamples > 0) {
202 // On by default
203 // glEnable(GL_MULTISAMPLE);
204 // Experimenting:
205 // glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE_ARB);
206 // glEnable(GL_SAMPLE_COVERAGE_ARB);
207 } else {
209 }
210}
211
212////////////////////////////////////////////////////////////////////////////////
213/// Unbind the frame-buffer object.
214
226
227////////////////////////////////////////////////////////////////////////////////
228/// Bind texture.
229
244
245////////////////////////////////////////////////////////////////////////////////
246/// Unbind texture.
247
249{
250 if (fIsRescaled)
251 {
253 glPopMatrix();
255 }
256
257 glPopAttrib();
258}
259
260////////////////////////////////////////////////////////////////////////////////
261
266
267//==============================================================================
268
269////////////////////////////////////////////////////////////////////////////////
270
279
280////////////////////////////////////////////////////////////////////////////////
281
296
297////////////////////////////////////////////////////////////////////////////////
298
322
323////////////////////////////////////////////////////////////////////////////////
324/// Initialize color-texture and attach it to current FB.
325
345
346////////////////////////////////////////////////////////////////////////////////
347/// Return state of fgRescaleToPow2 static member.
348
353
354////////////////////////////////////////////////////////////////////////////////
355/// Set state of fgRescaleToPow2 static member.
356/// Default is kTRUE as this works better on older hardware, especially ATI.
357
#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:271
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:215
void UnbindTexture()
Unbind texture.
Definition TGLFBO.cxx:248
UInt_t CreateAndAttachRenderBuffer(Int_t format, Int_t type)
Definition TGLFBO.cxx:299
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:326
void Bind()
Bind the frame-buffer object.
Definition TGLFBO.cxx:198
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:358
static Bool_t GetRescaleToPow2()
Return state of fgRescaleToPow2 static member.
Definition TGLFBO.cxx:349
Float_t fWScale
Definition TGLFBO.h:32
TGLFBO()
Constructor.
Definition TGLFBO.cxx:42
void SetAsReadBuffer()
Definition TGLFBO.cxx:262
void Release()
Release the allocated GL resources.
Definition TGLFBO.cxx:181
void InitMultiSample()
Definition TGLFBO.cxx:282
Int_t fReqW
Definition TGLFBO.h:30
void BindTexture()
Bind texture.
Definition TGLFBO.cxx:230
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