13#include "TGLIncludes.h"
74 static const std::string eh(
"TGLFBO::Init ");
79 if ( ! GLAD_GL_EXT_framebuffer_object)
81 throw std::runtime_error(eh +
"GL_EXT_framebuffer_object extension required for FBO.");
91 if (nw !=
w || nh !=
h)
100 if (ms_samples > 0 && ! GLAD_GL_EXT_framebuffer_multisample)
104 Info(eh.c_str(),
"GL implementation does not support multi-sampling for FBOs.");
118 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &maxSize);
119 if (
w > maxSize ||
h > maxSize)
121 throw std::runtime_error(eh +
Form(
"maximum size supported by GL implementation is %d.", maxSize));
128 if (GLAD_GL_NV_framebuffer_multisample_coverage)
131 glGetIntegerv(GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV, &n_modes);
132 GLint *modes =
new GLint[2*n_modes];
133 glGetIntegerv(GL_MULTISAMPLE_COVERAGE_MODES_NV, modes);
135 for (
int i = 0; i < n_modes; ++i)
151 Info(eh.c_str(),
"InitStandard (no multi-sampling).");
156 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
158 glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
159 glBindTexture (GL_TEXTURE_2D, 0);
163 case GL_FRAMEBUFFER_COMPLETE_EXT:
165 printf(
"%sConstructed TGLFBO ... all fine.\n", eh.c_str());
167 case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
169 throw std::runtime_error(eh +
"Constructed TGLFBO not supported, choose different formats.");
173 throw std::runtime_error(eh +
"Constructed TGLFBO is not complete, unexpected error.");
220 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,
fFrameBuffer);
221 glBlitFramebufferEXT(0, 0,
fW,
fH, 0, 0,
fW,
fH, GL_COLOR_BUFFER_BIT, GL_NEAREST);
224 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
232 glPushAttrib(GL_TEXTURE_BIT);
234 glEnable(GL_TEXTURE_2D);
238 glMatrixMode(GL_TEXTURE);
241 glMatrixMode(GL_MODELVIEW);
252 glMatrixMode(GL_TEXTURE);
254 glMatrixMode(GL_MODELVIEW);
264 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT,
fFrameBuffer);
303 glGenRenderbuffersEXT(1, &
id);
304 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,
id);
315 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
format,
fW,
fH);
318 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
type, GL_RENDERBUFFER_EXT,
id);
330 glGenTextures(1, &
id);
332 glBindTexture(GL_TEXTURE_2D,
id);
333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
336 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
337 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
fW,
fH, 0, GL_RGBA,
338 GL_UNSIGNED_BYTE,
nullptr);
340 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
341 GL_TEXTURE_2D,
id, 0);
bool Bool_t
Boolean (0=false, 1=true) (bool).
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
float Float_t
Float 4 bytes (float).
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void w
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
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
static Bool_t fgMultiSampleNAWarned
void Unbind()
Unbind the frame-buffer object.
void UnbindTexture()
Unbind texture.
UInt_t CreateAndAttachRenderBuffer(Int_t format, Int_t type)
virtual ~TGLFBO()
Destructor.
void Init(int w, int h, int ms_samples=0)
Acquire GL resources for given width, height and number of multi-sampling samples.
UInt_t CreateAndAttachColorTexture()
Initialize color-texture and attach it to current FB.
void Bind()
Bind the frame-buffer object.
static void SetRescaleToPow2(Bool_t r)
Set state of fgRescaleToPow2 static member.
static Bool_t GetRescaleToPow2()
Return state of fgRescaleToPow2 static member.
void Release()
Release the allocated GL resources.
void BindTexture()
Bind texture.
static Bool_t fgRescaleToPow2
Double_t Log2(Double_t x)
Returns the binary (base-2) logarithm of x.
Int_t CeilNint(Double_t x)
Returns the nearest integer of TMath::Ceil(x).