arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

renderPass.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////
00002 // 6/6/02       Aaron Lefohn    Scientific Computing and Imaging Institute
00003 // School of Computing          University of Utah
00004 //
00005 //  This library is free software; you can redistribute it and/or
00006 //  modify it under the terms of the GNU Lesser General Public
00007 //  License as published by the Free Software Foundation; either
00008 //  version 2.1 of the License, or (at your option) any later version.
00009 //
00010 //  This library is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 //  Lesser General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU Lesser General Public
00016 //  License along with this library; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 #if !defined(AFX_RENDERPASS_H__2E3F741E_4225_473E_8516_81E4C39BCA31__INCLUDED_)
00020 #define AFX_RENDERPASS_H__2E3F741E_4225_473E_8516_81E4C39BCA31__INCLUDED_
00021 
00022 #if _MSC_VER > 1000
00023 #pragma once
00024 #endif // _MSC_VER > 1000
00025 
00026 #include "renderableGLI.h"
00027 #include <GL/glew.h>
00028 #include "../texture/singleTex.h"
00029 #include "../state/pbuffGlift.h"
00030 #include "../drawable/drawableGLI.h"
00031 #include <mathGutz.h>
00032 #include <vector>
00033 
00034 namespace glift {
00035 
00036 typedef std::vector<DrawableGLI*> VecDrawP;
00037 
00038 /////////////////////////////////////////////////////////////////////////
00039 ///
00040 /// RenderPass.h: interface for the RenderPass class.
00041 ///
00042 /// - This class encapsulates an entire render pass.
00043 /// - The destination of the render pass is either the color buffer or a pbuffer.
00044 /// - A texture may optionally be specified as a copy-to-texture destination
00045 /// - An alternate viewport may optionally be set for this RenderPass. The \n
00046 ///   viewport is NOT restored after the pass unless 'restoreViewport' is true.
00047 /// - If a pbuffer destination is used, the previous rendering target is NOT \n
00048 ///   restored unless "restoreContext" is set to 'true.'
00049 ///////////////////////////////////////////////////////////////////////
00050 /// TODO: Add the ability to add a GenState vector to these constructors
00051 class _export_ RenderPass : public RenderableGLI
00052 {
00053 public:
00054    /// Standard, Render-To-ColorBuffer constructors
00055    RenderPass( DrawableGLI* prim, const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false);
00056    RenderPass( const VecDrawP& prims, const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false);
00057 
00058    /// Copy colorBuffer to 'texDest'
00059    RenderPass( DrawableGLI* prim, SingleTex* texDest, 
00060       const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false );
00061    RenderPass( const VecDrawP& prims, SingleTex* texDest, 
00062       const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false );
00063 
00064    /// Render to Texture using PBuffer
00065    RenderPass( DrawableGLI* prim, PBuffGlift* pbuffDest, bool restoreContext=false,
00066       const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false );
00067    RenderPass( const VecDrawP& prims, PBuffGlift* pbuffDest, bool restoreContext=false,
00068       const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false );
00069 
00070    /// Render to Pbuffer and Copy to Texture (when Render-to-Texture is not available)
00071    RenderPass( DrawableGLI* prim, SingleTex* texDest, PBuffGlift* pbuffDest, bool restoreContext=false, 
00072       const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false );
00073    RenderPass( const VecDrawP& prims, SingleTex* texDest, PBuffGlift* pbuffDest, bool restoreContext=false, 
00074       const gutz::vec4i& viewport=gutz::vec4i(), bool restoreView=false );
00075 
00076    RenderPass( const RenderPass& rhs );
00077    RenderPass& operator=(const RenderPass& rhs);
00078    virtual ~RenderPass();
00079 
00080    /// Set Functions
00081    void setViewport( const gutz::vec4i& viewport, bool restoreView=false );
00082    void setDest( PBuffGlift* pbuff )    {m_pbuffDest = pbuff;}
00083    void setDest( SingleTex* tex )               {m_texDest = tex;}
00084 
00085 protected:
00086    virtual void renderDef();
00087 
00088    inline void  setViewport();
00089    inline void drawPrims();
00090    inline void  restoreViewport();
00091 
00092 private:
00093    VecDrawP             m_prim;                   /// The primitives to draw
00094    PBuffGlift*          m_pbuffDest;      /// PBuffer destination (optional)
00095    SingleTex*           m_texDest;                /// Texture destination (optional) 
00096    bool             m_restoreCTX;         /// Restore context after a pbuffer renderPass?
00097    bool                 m_changeView;     /// Should the viewport change?
00098    bool                 m_restoreView;    /// Restore previous viewport?
00099    gutz::vec4i          m_saveVP;                 /// The saved viewport
00100    gutz::vec4i          m_viewport;               /// Viewport for this render pass (optional)
00101 
00102    RenderPass(); //Disallow default construction
00103 
00104    /// **** These Functions are used by constructors ****
00105    void initMembers( const RenderPass& rhs );
00106    void initMembers( const VecDrawP& prim, SingleTex* texDest, PBuffGlift* pbuffDest, 
00107       bool m_restoreCTX, bool changeView, const gutz::vec4i& viewport,  bool restoreView );
00108 };
00109 
00110 inline void RenderPass::setViewport()
00111 {
00112    if( m_changeView ) {
00113       if( m_restoreView ) {
00114          glGetIntegerv(GL_VIEWPORT, &m_saveVP[0]);
00115       }
00116       glViewport(m_viewport[0], m_viewport[1], m_viewport[2], m_viewport[3]);
00117    }
00118 }
00119 
00120 inline void RenderPass::restoreViewport()
00121 {
00122    if( m_changeView && m_restoreView) {
00123       glViewport(m_saveVP[0], m_saveVP[1], m_saveVP[2], m_saveVP[3]);
00124    }
00125 }
00126 
00127 inline void RenderPass::drawPrims()
00128 {
00129    for( uint i=0; i < m_prim.size(); i++) {
00130       m_prim[i]->draw();
00131    }
00132 }
00133 
00134 } /// End of namespace glift
00135 
00136 #endif /// !defined(AFX_RENDERPASS_H__2E3F741E_4225_473E_8516_81E4C39BCA31__INCLUDED_)

Send questions, comments, and bug reports to:
jmk