54 fMSCoverageSamples (0),
75 static const std::string eh(
"TGLFBO::Init ");
78 if (!GLEW_EXT_framebuffer_object)
80 throw std::runtime_error(eh +
"GL_EXT_framebuffer_object extension required for FBO.");
90 if (nw != w || nh != h)
99 if (ms_samples > 0 && ! GLEW_EXT_framebuffer_multisample)
103 Info(eh.c_str(),
"GL implementation does not support multi-sampling for FBOs.");
117 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &maxSize);
118 if (w > maxSize || h > maxSize)
120 throw std::runtime_error(eh +
Form(
"maximum size supported by GL implementation is %d.", maxSize));
127 if (GLEW_NV_framebuffer_multisample_coverage)
130 glGetIntegerv(GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV, &n_modes);
131 GLint *modes =
new GLint[2*n_modes];
132 glGetIntegerv(GL_MULTISAMPLE_COVERAGE_MODES_NV, modes);
134 for (
int i = 0; i < n_modes; ++i)
150 Info(eh.c_str(),
"InitStandard (no multi-sampling).");
155 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
157 glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
158 glBindTexture (GL_TEXTURE_2D, 0);
162 case GL_FRAMEBUFFER_COMPLETE_EXT:
164 printf(
"%sConstructed TGLFBO ... all fine.\n", eh.c_str());
166 case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
168 throw std::runtime_error(eh +
"Constructed TGLFBO not supported, choose different formats.");
172 throw std::runtime_error(eh +
"Constructed TGLFBO is not complete, unexpected error.");
219 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,
fFrameBuffer);
220 glBlitFramebufferEXT(0, 0,
fW,
fH, 0, 0,
fW,
fH, GL_COLOR_BUFFER_BIT, GL_NEAREST);
223 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
231 glPushAttrib(GL_TEXTURE_BIT);
233 glEnable(GL_TEXTURE_2D);
237 glMatrixMode(GL_TEXTURE);
240 glMatrixMode(GL_MODELVIEW);
251 glMatrixMode(GL_TEXTURE);
253 glMatrixMode(GL_MODELVIEW);
263 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT,
fFrameBuffer);
302 glGenRenderbuffersEXT(1, &
id);
303 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,
id);
310 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,
fMSSamples, format,
fW,
fH);
314 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, format,
fW,
fH);
317 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, type, GL_RENDERBUFFER_EXT,
id);
329 glGenTextures(1, &
id);
331 glBindTexture(GL_TEXTURE_2D,
id);
332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
334 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
335 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
336 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
fW,
fH, 0, GL_RGBA,
337 GL_UNSIGNED_BYTE,
NULL);
339 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
340 GL_TEXTURE_2D,
id, 0);
static void SetRescaleToPow2(Bool_t r)
Set state of fgRescaleToPow2 static member.
UInt_t CreateAndAttachRenderBuffer(Int_t format, Int_t type)
UInt_t CreateAndAttachColorTexture()
Initialize color-texture and attach it to current FB.
void Unbind()
Unbind the frame-buffer object.
void Bind()
Bind the frame-buffer object.
virtual ~TGLFBO()
Destructor.
Double_t Log2(Double_t x)
void Release()
Release the allocated GL resources.
static std::string format(double x, double y, int digits, int width)
static Bool_t GetRescaleToPow2()
Return state of fgRescaleToPow2 static member.
void Info(const char *location, const char *msgfmt,...)
void Init(int w, int h, int ms_samples=0)
Acquire GL resources for given width, height and number of multi-sampling samples.
char * Form(const char *fmt,...)
static Bool_t fgMultiSampleNAWarned
void BindTexture()
Bind texture.
void UnbindTexture()
Unbind texture.
static Bool_t fgRescaleToPow2
Int_t CeilNint(Double_t x)