gl_renderer.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 /* Author: Suat Gedikli */
00036 
00037 #ifndef MOVEIT_MESH_FILTER_GLRENDERER_
00038 #define MOVEIT_MESH_FILTER_GLRENDERER_
00039 
00040 #include <GL/glew.h>
00041 #ifdef __APPLE__
00042 #include <OpenGL/gl.h>
00043 #else
00044 #include <GL/gl.h>
00045 #endif
00046 #include <string>
00047 #include <boost/thread.hpp>
00048 
00049 namespace mesh_filter
00050 {
00054 class GLRenderer
00055 {
00056 public:
00065   GLRenderer (unsigned width, unsigned height, float near = 0.1, float far = 10.0);
00066 
00068   ~GLRenderer ();
00069 
00074   void begin () const;
00075 
00080   void end () const;
00081 
00087   void callList (GLuint list) const;
00088 
00094   void getColorBuffer(unsigned char* buffer) const;
00095 
00101   void getDepthBuffer(float* buffer) const;
00102 
00110   GLuint setShadersFromFile (const std::string& vertex_filename, const std::string& fragment_filename);
00111 
00119   GLuint setShadersFromString (const std::string& vertex_shader, const std::string& fragment_shader);
00120 
00129   void setCameraParameters (float fx, float fy, float cx, float cy);
00130 
00137   void setClippingRange (float near, float far);
00138 
00144   const float& getNearClippingDistance () const;
00145 
00151   const float& getFarClippingDistance () const;
00152 
00158   const unsigned getWidth () const;
00159 
00165   const unsigned getHeight () const;
00166 
00173   void setBufferSize (unsigned width, unsigned height);
00174 
00180   const GLuint& getProgramID () const;
00181 
00187   GLuint getDepthTexture () const;
00188 
00194   GLuint getColorTexture () const;
00195 
00196 private:
00201   void setCameraParameters () const;
00202 
00209   void readShaderCodeFromFile (const std::string& filename, std::string& source) const;
00210 
00218   GLuint loadShaders (const std::string& vertex_source, const std::string& fragment_source) const;
00219 
00227   GLuint createShader (GLuint shaderID, const std::string& source) const;
00228 
00233   void initFrameBuffers ();
00234 
00239   void deleteFrameBuffers ();
00240 
00245   static void createGLContext ();
00246 
00251   static void deleteGLContext ();
00252 
00254   unsigned width_;
00255 
00257   unsigned height_;
00258 
00260   GLuint fbo_id_;
00261 
00263   GLuint rbo_id_;
00264 
00266   GLuint rgb_id_;
00267 
00269   GLuint depth_id_;
00270 
00272   GLuint program_;
00273 
00275   float near_;
00276 
00278   float far_;
00279 
00281   float fx_;
00282 
00284   float fy_;
00285 
00287   float cx_;
00288 
00290   float cy_;
00291 
00293   static std::map<boost::thread::id, std::pair<unsigned, GLuint> > context_;
00294 
00295   /* \brief lock for context map */
00296   static boost::mutex context_lock_;
00297 
00298   static bool glutInitialized_;
00299 
00300 };
00301 } // namespace mesh_filter
00302 #endif


perception
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Wed Aug 26 2015 12:43:21