Abstracts the OpenGL frame buffer objects, and provides an interface to render meshes, and retrieve the color and depth ap from opengl. More...
#include <gl_renderer.h>
Public Member Functions | |
void | begin () const |
initializes the frame buffers for rendering and or manipulating | |
void | callList (GLuint list) const |
executes a OpenGL list | |
void | end () const |
finalizes the frame buffers after rendering and/or manipulating | |
void | getColorBuffer (unsigned char *buffer) const |
retrieves the color buffer from OpenGL | |
GLuint | getColorTexture () const |
returns the handle of the color buffer as an OpenGL texture object | |
void | getDepthBuffer (float *buffer) const |
retrieves the depth buffer from OpenGL | |
GLuint | getDepthTexture () const |
returns the handle of the depth buffer as an OpenGL texture object | |
const float & | getFarClippingDistance () const |
returns the distance of the far clipping plane in meters | |
const unsigned | getHeight () const |
returns the height of the frame buffer objects in pixels | |
const float & | getNearClippingDistance () const |
returns the distance of the near clipping plane in meters | |
const GLuint & | getProgramID () const |
const unsigned | getWidth () const |
returns the width of the frame buffer objectsin pixels | |
GLRenderer (unsigned width, unsigned height, float near=0.1, float far=10.0) | |
constructs the frame buffer object in a new OpenGL context. | |
void | setBufferSize (unsigned width, unsigned height) |
set the size of fram buffers | |
void | setCameraParameters (float fx, float fy, float cx, float cy) |
set the camera parameters | |
void | setClippingRange (float near, float far) |
sets the near and far clipping plane distances in meters | |
GLuint | setShadersFromFile (const std::string &vertex_filename, const std::string &fragment_filename) |
loads, compiles, links and adds GLSL shaders from files to the current OpenGL context. | |
GLuint | setShadersFromString (const std::string &vertex_shader, const std::string &fragment_shader) |
loads, compiles, links and adds GLSL shaders from string to the current OpenGL context. | |
~GLRenderer () | |
destructor, destroys frame buffer objects and OpenGL context | |
Private Member Functions | |
GLuint | createShader (GLuint shaderID, const std::string &source) const |
create a OpenGL shader object from the shader source code | |
void | deleteFrameBuffers () |
deletes the frame buffer objects | |
void | initFrameBuffers () |
initializes the frame buffer objects | |
GLuint | loadShaders (const std::string &vertex_source, const std::string &fragment_source) const |
Compiles, Links and adds the GLSL shaders from strings containing the source codes. | |
void | readShaderCodeFromFile (const std::string &filename, std::string &source) const |
reads shader source code from file to a string | |
void | setCameraParameters () const |
sets the OpenGL camera parameters | |
Static Private Member Functions | |
static void | createGLContext () |
create the OpenGL context if required. Only on context is created for each thread | |
static void | deleteGLContext () |
deletes OpenGL context for the current thread | |
Private Attributes | |
float | cx_ |
x-coordinate of principal point of camera in pixels | |
float | cy_ |
y-coordinate of principal point of camera in pixels | |
GLuint | depth_id_ |
handle to depth buffer | |
float | far_ |
distance of far clipping plane in meters | |
GLuint | fbo_id_ |
handle to frame buffer object | |
float | fx_ |
focal length in x-direction of camera in pixels | |
float | fy_ |
focal length in y-direction of camera in pixels | |
unsigned | height_ |
height of frame buffer objects in pixels | |
float | near_ |
distance of near clipping plane in meters | |
GLuint | program_ |
handle to program that is currently used | |
GLuint | rbo_id_ |
handle to render buffer object | |
GLuint | rgb_id_ |
handle to color buffer | |
unsigned | width_ |
width of frame buffer objects in pixels | |
Static Private Attributes | |
static std::map < boost::thread::id, std::pair < unsigned, GLuint > > | context_ |
map from thread id to OpenGL context | |
static boost::mutex | context_lock_ |
static bool | glutInitialized_ = false |
Abstracts the OpenGL frame buffer objects, and provides an interface to render meshes, and retrieve the color and depth ap from opengl.
Definition at line 58 of file gl_renderer.h.
mesh_filter::GLRenderer::GLRenderer | ( | unsigned | width, |
unsigned | height, | ||
float | near = 0.1 , |
||
float | far = 10.0 |
||
) |
constructs the frame buffer object in a new OpenGL context.
[in] | width | the width of the frame buffers |
[in] | height | height of the framebuffers |
[in] | near | distance of the near clipping plane in meters |
[in] | far | distance of the far clipping plane in meters |
Definition at line 56 of file gl_renderer.cpp.
destructor, destroys frame buffer objects and OpenGL context
Definition at line 75 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::begin | ( | ) | const |
initializes the frame buffers for rendering and or manipulating
Definition at line 185 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::callList | ( | GLuint | list | ) | const |
executes a OpenGL list
[in] | list | the handle of the OpenGL list to be executed |
Definition at line 195 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::createGLContext | ( | ) | [static, private] |
create the OpenGL context if required. Only on context is created for each thread
Definition at line 367 of file gl_renderer.cpp.
GLuint mesh_filter::GLRenderer::createShader | ( | GLuint | shaderID, |
const std::string & | source | ||
) | const [private] |
create a OpenGL shader object from the shader source code
[in] | shaderID | type of shader to be created (e.g. GL_VERTEX_SHADER or GL_FRAGMENT_SHADER) |
[in] | source | the source code of the shader to be created |
Definition at line 259 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::deleteFrameBuffers | ( | ) | [private] |
deletes the frame buffer objects
Definition at line 171 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::deleteGLContext | ( | ) | [static, private] |
deletes OpenGL context for the current thread
Definition at line 415 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::end | ( | ) | const |
finalizes the frame buffers after rendering and/or manipulating
Definition at line 202 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::getColorBuffer | ( | unsigned char * | buffer | ) | const |
retrieves the color buffer from OpenGL
[out] | buffer | pointer to memory where the color values need to be stored |
Definition at line 209 of file gl_renderer.cpp.
GLuint mesh_filter::GLRenderer::getColorTexture | ( | ) | const |
returns the handle of the color buffer as an OpenGL texture object
Definition at line 434 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::getDepthBuffer | ( | float * | buffer | ) | const |
retrieves the depth buffer from OpenGL
[out] | buffer | pointer to memory where the depth values need to be stored |
Definition at line 217 of file gl_renderer.cpp.
GLuint mesh_filter::GLRenderer::getDepthTexture | ( | ) | const |
returns the handle of the depth buffer as an OpenGL texture object
Definition at line 439 of file gl_renderer.cpp.
const float & mesh_filter::GLRenderer::getFarClippingDistance | ( | ) | const |
returns the distance of the far clipping plane in meters
Definition at line 254 of file gl_renderer.cpp.
const unsigned mesh_filter::GLRenderer::getHeight | ( | ) | const |
returns the height of the frame buffer objects in pixels
Definition at line 449 of file gl_renderer.cpp.
const float & mesh_filter::GLRenderer::getNearClippingDistance | ( | ) | const |
returns the distance of the near clipping plane in meters
Definition at line 249 of file gl_renderer.cpp.
const GLuint & mesh_filter::GLRenderer::getProgramID | ( | ) | const |
Definition at line 244 of file gl_renderer.cpp.
const unsigned mesh_filter::GLRenderer::getWidth | ( | ) | const |
returns the width of the frame buffer objectsin pixels
Definition at line 444 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::initFrameBuffers | ( | ) | [private] |
initializes the frame buffer objects
Definition at line 129 of file gl_renderer.cpp.
GLuint mesh_filter::GLRenderer::loadShaders | ( | const std::string & | vertex_source, |
const std::string & | fragment_source | ||
) | const [private] |
Compiles, Links and adds the GLSL shaders from strings containing the source codes.
[in] | vertex_source | string containing the vertex shader source code |
[in] | fragment_source | string containing the fragment shader source code |
Definition at line 312 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::readShaderCodeFromFile | ( | const std::string & | filename, |
std::string & | source | ||
) | const [private] |
reads shader source code from file to a string
[in] | filename | path to file containing the shader source code |
[out] | source | string to be filled with the shader source code |
Definition at line 289 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::setBufferSize | ( | unsigned | width, |
unsigned | height | ||
) |
set the size of fram buffers
[in] | width | width of frame buffer in pixels |
[in] | height | height of frame buffer in pixels |
Definition at line 84 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::setCameraParameters | ( | float | fx, |
float | fy, | ||
float | cx, | ||
float | cy | ||
) |
set the camera parameters
[in] | fx | focal length in x-direction |
[in] | fy | focal length in y-direction |
[in] | cx | x component of principal point |
[in] | cy | y component of principal point |
Definition at line 105 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::setCameraParameters | ( | ) | const [private] |
sets the OpenGL camera parameters
Definition at line 113 of file gl_renderer.cpp.
void mesh_filter::GLRenderer::setClippingRange | ( | float | near, |
float | far | ||
) |
sets the near and far clipping plane distances in meters
[in] | near | distance of the near clipping plane in meters |
[in] | far | distance of the far clipping plane in meters |
Definition at line 95 of file gl_renderer.cpp.
GLuint mesh_filter::GLRenderer::setShadersFromFile | ( | const std::string & | vertex_filename, |
const std::string & | fragment_filename | ||
) |
loads, compiles, links and adds GLSL shaders from files to the current OpenGL context.
[in] | vertex_filename | path to vertex shader source code. Can set to "" (empty string) if no vertex shader is used. |
[in] | fragment_filename | path to fragemnt shader source code. Can be set to "" if no fragment shader is used. |
Definition at line 225 of file gl_renderer.cpp.
GLuint mesh_filter::GLRenderer::setShadersFromString | ( | const std::string & | vertex_shader, |
const std::string & | fragment_shader | ||
) |
loads, compiles, links and adds GLSL shaders from string to the current OpenGL context.
[in] | vertex_shader | source code of the vertex shader. Can be "" if no vertex shader is used. |
[in] | fragment_shader | source code of the fragment shader. Can be "" if no fragment shader is used. |
Definition at line 238 of file gl_renderer.cpp.
map< boost::thread::id, pair< unsigned, GLuint > > mesh_filter::GLRenderer::context_ [static, private] |
map from thread id to OpenGL context
Definition at line 298 of file gl_renderer.h.
boost::mutex mesh_filter::GLRenderer::context_lock_ [static, private] |
Definition at line 301 of file gl_renderer.h.
float mesh_filter::GLRenderer::cx_ [private] |
x-coordinate of principal point of camera in pixels
Definition at line 292 of file gl_renderer.h.
float mesh_filter::GLRenderer::cy_ [private] |
y-coordinate of principal point of camera in pixels
Definition at line 295 of file gl_renderer.h.
GLuint mesh_filter::GLRenderer::depth_id_ [private] |
handle to depth buffer
Definition at line 274 of file gl_renderer.h.
float mesh_filter::GLRenderer::far_ [private] |
distance of far clipping plane in meters
Definition at line 283 of file gl_renderer.h.
GLuint mesh_filter::GLRenderer::fbo_id_ [private] |
handle to frame buffer object
Definition at line 265 of file gl_renderer.h.
float mesh_filter::GLRenderer::fx_ [private] |
focal length in x-direction of camera in pixels
Definition at line 286 of file gl_renderer.h.
float mesh_filter::GLRenderer::fy_ [private] |
focal length in y-direction of camera in pixels
Definition at line 289 of file gl_renderer.h.
bool mesh_filter::GLRenderer::glutInitialized_ = false [static, private] |
Definition at line 303 of file gl_renderer.h.
unsigned mesh_filter::GLRenderer::height_ [private] |
height of frame buffer objects in pixels
Definition at line 262 of file gl_renderer.h.
float mesh_filter::GLRenderer::near_ [private] |
distance of near clipping plane in meters
Definition at line 280 of file gl_renderer.h.
GLuint mesh_filter::GLRenderer::program_ [private] |
handle to program that is currently used
Definition at line 277 of file gl_renderer.h.
GLuint mesh_filter::GLRenderer::rbo_id_ [private] |
handle to render buffer object
Definition at line 268 of file gl_renderer.h.
GLuint mesh_filter::GLRenderer::rgb_id_ [private] |
handle to color buffer
Definition at line 271 of file gl_renderer.h.
unsigned mesh_filter::GLRenderer::width_ [private] |
width of frame buffer objects in pixels
Definition at line 259 of file gl_renderer.h.