57 , m_TextureReleased(
false)
59 , m_ClearColorGreen(1)
61 , m_ClearColorAlpha(1)
73 status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
74 if (status == GL_FRAMEBUFFER_COMPLETE_EXT)
79 const char*
value = getenv(
"NCBI_GBENCH_GLERROR");
96 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
97 msg =
"Framebuffer: Incomplete attachment";
99 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
100 msg =
"Framebuffer: Incomplete missing attachment";
102 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
103 msg =
"Framebuffer: Incomplete dimensions";
105 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
106 msg =
"Framebuffer: Incomplete formats";
108 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
109 msg =
"Framebuffer: Incomplete draw buffer";
111 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
112 msg =
"Framebuffer: Incomplete read buffer";
114 case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
115 msg =
"Framebuffer: Unsupported framebuffer";
118 msg =
"Framebuffer: Unknown error";
149 if (glewIsSupported(
"GL_EXT_framebuffer_object")) {
154 if (glIsFramebufferEXT(
m_Fb))
155 glDeleteFramebuffersEXT(1, &
m_Fb);
179 if (!glewIsSupported(
"GL_EXT_framebuffer_object"))
184 glGenFramebuffersEXT(1, &
m_Fb);
185 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_Fb);
188 glEnable(GL_TEXTURE_2D);
191 glBindTexture(GL_TEXTURE_2D,
m_FbTex);
192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
m_TexMag );
193 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
m_TexMin );
194 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
m_WrapS);
195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
m_WrapT);
199 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
201 GL_RGBA, GL_FLOAT,
NULL);
203 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,
m_FbTex, 0);
207 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,
m_DepthRb);
208 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, (GLsizei)
m_FrameSize, (GLsizei)
m_FrameSize);
210 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
m_DepthRb);
211 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
m_DepthRb);
216 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
220 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
226 if (
m_TexMin == GL_NEAREST_MIPMAP_NEAREST ||
227 m_TexMin == GL_LINEAR_MIPMAP_NEAREST ||
228 m_TexMin == GL_NEAREST_MIPMAP_LINEAR ||
229 m_TexMin == GL_LINEAR_MIPMAP_LINEAR )
247 int current_size = start_size;
249 std::vector<int> sizes;
251 if (!glewIsSupported(
"GL_EXT_framebuffer_object"))
255 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
258 if (current_size > max_tex_size)
261 sizes.push_back(current_size);
282 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_Fb);
284 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
285 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
288 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
290 glDrawBuffer(GL_BACK);
291 glReadBuffer(GL_BACK);
301 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,
m_Fb);
303 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
304 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
307 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
313 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
315 glDrawBuffer(GL_BACK);
316 glReadBuffer(GL_BACK);
324 glEnable(GL_TEXTURE_2D);
325 glBindTexture(GL_TEXTURE_2D,
m_FbTex);
330 glGenerateMipmapEXT(GL_TEXTURE_2D);
GLint m_TexMag
magnification filter
virtual void SetClearColor(float red, float green, float blue, float alpha)
void SetTextureWrap(GLint wraps, GLint wrapt)
Set texture paramters, if needed. Call before calling CreateFrameBuffer.
static std::vector< int > checkFramebufferAvailability(int start_size, int count)
Return an arrray of valid image output sizes.
GLint m_TexMin
Texture parameters.
virtual I3DTexture * Get3DTexture()
GLuint m_FbTex
Texture target id.
void Clear()
Deletes the current framebuffer, if any.
virtual void Render(std::function< void()> renderer)
void MakeCurrent(bool b)
Makes this framebuffer the current rendering target if b==true, and if b==false, makes the rendering ...
CGLFrameBuffer(size_t dim)
virtual void GenerateMipMaps()
Generates mipmaps for the texture rendering target.
size_t m_FrameSize
Size of framebuffer (in both dimensions).
GLuint m_DepthRb
Depth renderbuffer id.
static bool CheckFBOError()
Returns true and writes error message if framebuffer is invalid.
bool m_TextureReleased
if true, the texture is not deleted with the framebuffer
virtual void SetTextureFiltering(GLint min_filter, GLint mag_filter)
Set texture filtering parameters (default: GL_LINEAR)
virtual bool IsValid()
Returns true if framebuffer was created successfully.
virtual void CreateFrameBuffer()
Create, set and validate framebuffer.
NCBI_XNCBI_EXPORT void Abort(void)
Smart abort function.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
void Error(CExceptionArgs_Base &args)
static bool CheckGlError()
Check if there are any OpenGL errors.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
const GenericPointer< typename T::ValueType > T2 value
int strcmp(const char *str1, const char *str2)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)