Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CGoGN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Pitiot
CGoGN
Commits
157b8818
Commit
157b8818
authored
Oct 05, 2012
by
Sylvain Thery
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add fbo rendering class
parent
3b07d12b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
296 additions
and
0 deletions
+296
-0
include/Utils/fbo.h
include/Utils/fbo.h
+100
-0
src/Utils/fbo.cpp
src/Utils/fbo.cpp
+196
-0
No files found.
include/Utils/fbo.h
0 → 100644
View file @
157b8818
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGoGN_GLSL_FBO__
#define __CGoGN_GLSL_FBO__
#include <GL/glew.h>
#include "Utils/gl_def.h"
#include <iostream>
#include <vector>
namespace
CGoGN
{
namespace
Utils
{
class
FBO
{
public:
/// default constructor
FBO
();
/**
* constructor with size of frame buffer
* @param width width in pixel
* @param height heigt in pixel
*/
FBO
(
unsigned
int
width
,
unsigned
int
height
);
/// destructor
~
FBO
();
/**
*
*/
void
attachRender
(
GLenum
internalformat
);
/**
*
*/
void
attachTexture
(
GLenum
internalformat
,
GLint
filter
=
GL_LINEAR
);
void
bindTexInput
();
void
bindTexInput
(
int
num
);
void
bindTexOutput
();
void
bindTexOutput
(
int
num
);
void
unbind
();
void
setSize
(
unsigned
int
width
,
unsigned
int
height
)
{
m_width
=
width
;
m_height
=
height
;
}
void
checkFBO
();
protected:
unsigned
int
m_width
;
unsigned
int
m_height
;
int
m_maxColorAttachments
;
CGoGNGLuint
m_fboID
;
CGoGNGLuint
m_renderID
;
std
::
vector
<
CGoGNGLuint
>
m_texID
;
CGoGNGLenumTable
m_attachmentPoints
;
};
}
}
#endif
/* FRAMEBUFFER_HPP */
src/Utils/fbo.cpp
0 → 100644
View file @
157b8818
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Utils/fbo.h"
namespace
CGoGN
{
namespace
Utils
{
FBO
::
FBO
()
{
glGetIntegerv
(
GL_MAX_COLOR_ATTACHMENTS
,
&
m_maxColorAttachments
);
*
m_attachmentPoints
=
new
GLenum
[
m_maxColorAttachments
];
glGenFramebuffers
(
1
,
&
(
*
m_fboID
));
}
FBO
::
FBO
(
unsigned
int
width
,
unsigned
int
height
)
{
glGetIntegerv
(
GL_MAX_COLOR_ATTACHMENTS
,
&
m_maxColorAttachments
);
*
m_attachmentPoints
=
new
GLenum
[
m_maxColorAttachments
];
glGenFramebuffers
(
1
,
&
(
*
m_fboID
));
m_width
=
width
;
m_height
=
height
;
}
FBO
::~
FBO
()
{
GLuint
tex_id
;
for
(
unsigned
int
i
=
0
;
i
<
m_texID
.
size
();
++
i
)
{
tex_id
=
*
(
m_texID
.
at
(
i
));
glDeleteTextures
(
1
,
&
tex_id
);
}
glDeleteFramebuffers
(
1
,
&
(
*
m_fboID
));
delete
[]
*
m_attachmentPoints
;
}
void
FBO
::
attachRender
(
GLenum
internalformat
)
{
GLenum
attachment
;
GLuint
renderID
;
if
(
internalformat
==
GL_DEPTH_COMPONENT
)
{
attachment
=
GL_DEPTH_ATTACHMENT
;
}
else
if
(
internalformat
==
GL_STENCIL_INDEX
)
{
attachment
=
GL_STENCIL_ATTACHMENT
;
}
else
if
(
internalformat
==
GL_DEPTH_STENCIL
)
{
attachment
=
GL_DEPTH_STENCIL_ATTACHMENT
;
}
else
{
std
::
cout
<<
"FBO::attachRender : Bad Internal Format"
<<
std
::
endl
;
return
;
}
glGenRenderbuffers
(
1
,
&
renderID
);
glBindFramebuffer
(
GL_FRAMEBUFFER
,
*
m_fboID
);
glBindRenderbuffer
(
GL_RENDERBUFFER
,
renderID
);
glRenderbufferStorage
(
GL_RENDERBUFFER
,
internalformat
,
m_width
,
m_height
);
glFramebufferRenderbuffer
(
GL_FRAMEBUFFER
,
attachment
,
GL_RENDERBUFFER
,
renderID
);
*
m_renderID
=
renderID
;
}
void
FBO
::
attachTexture
(
GLenum
internalformat
,
GLint
filter
)
{
GLenum
attachment
;
GLenum
format
;
GLenum
type
;
GLuint
texID
;
if
(
int
(
m_texID
.
size
())
==
m_maxColorAttachments
)
{
std
::
cout
<<
"FBO::attachTexture : The number of texture has been exceeded"
<<
std
::
endl
;
return
;
}
attachment
=
GL_COLOR_ATTACHMENT0
+
m_texID
.
size
();
if
(
internalformat
==
GL_RGBA
)
{
format
=
GL_RGBA
;
type
=
GL_FLOAT
;
}
if
(
internalformat
==
GL_RGB
)
{
format
=
GL_RGB
;
type
=
GL_FLOAT
;
}
if
(
internalformat
==
GL_RGBA32F
)
{
format
=
GL_RGBA
;
type
=
GL_FLOAT
;
}
if
(
internalformat
==
GL_RGB32F
)
{
format
=
GL_RGB
;
type
=
GL_FLOAT
;
}
glGenTextures
(
1
,
&
texID
);
glBindFramebuffer
(
GL_FRAMEBUFFER
,
*
m_fboID
);
glBindTexture
(
GL_TEXTURE_2D
,
texID
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
internalformat
,
m_width
,
m_height
,
0
,
format
,
type
,
NULL
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
filter
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
filter
);
glFramebufferTexture2D
(
GL_FRAMEBUFFER
,
attachment
,
GL_TEXTURE_2D
,
texID
,
0
);
m_texID
.
push_back
(
CGoGNGLuint
(
texID
));
(
*
m_attachmentPoints
)[
m_texID
.
size
()
-
1
]
=
attachment
;
}
void
FBO
::
bindTexInput
()
{
for
(
unsigned
int
i
=
0
;
i
<
m_texID
.
size
();
++
i
)
{
glActiveTexture
(
GL_TEXTURE0
+
i
);
glBindTexture
(
GL_TEXTURE_2D
,
*
(
m_texID
[
i
]));
}
}
void
FBO
::
bindTexInput
(
int
num
)
{
glBindTexture
(
GL_TEXTURE_2D
,
*
(
m_texID
[
num
]));
}
void
FBO
::
bindTexOutput
()
{
glBindFramebuffer
(
GL_FRAMEBUFFER
,
*
m_fboID
);
if
(
m_texID
.
size
()
==
1
)
{
glDrawBuffer
((
*
m_attachmentPoints
)[
0
]);
}
else
{
glDrawBuffers
(
m_texID
.
size
(),
*
m_attachmentPoints
);
}
}
void
FBO
::
bindTexOutput
(
int
num
)
{
glBindFramebuffer
(
GL_FRAMEBUFFER
,
*
m_fboID
);
glDrawBuffer
((
*
m_attachmentPoints
)[
num
]);
}
void
FBO
::
unbind
()
{
glBindFramebuffer
(
GL_FRAMEBUFFER
,
0
);
}
void
FBO
::
checkFBO
()
{
GLenum
status
;
glBindFramebuffer
(
GL_FRAMEBUFFER
,
*
m_fboID
);
status
=
glCheckFramebufferStatus
(
GL_FRAMEBUFFER
);
if
(
status
!=
GL_FRAMEBUFFER_COMPLETE
)
{
std
::
cout
<<
"FBO STATUS ERROR : "
<<
status
<<
std
::
endl
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment