00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <renderable/renderPass.h>
00025
00026 #include <iostream>
00027 #include <GL/glUtil.h>
00028
00029 using namespace std;
00030 using namespace gutz;
00031
00032 using namespace glift;
00033
00034
00035 RenderPass::RenderPass( DrawableGLI* prim, const vec4i& viewport, bool restoreView )
00036 {
00037 m_prim = VecDrawP(1, prim );
00038 bool changeView = (viewport != 0);
00039 initMembers( m_prim, NULL, NULL, false, changeView, viewport, restoreView );
00040 }
00041
00042 RenderPass::RenderPass( const VecDrawP& prims, const vec4i& viewport, bool restoreView )
00043 {
00044 bool changeView = (viewport != 0);
00045 initMembers( prims, NULL, NULL, false, changeView, viewport, restoreView );
00046 }
00047
00048
00049 RenderPass::RenderPass( DrawableGLI* prim, SingleTex* texDest,
00050 const vec4i& viewport, bool restoreView )
00051 {
00052 m_prim = VecDrawP(1, prim );
00053 bool changeView = (viewport != 0);
00054 initMembers( m_prim, texDest, NULL, false, changeView, viewport, restoreView );
00055 }
00056
00057 RenderPass::RenderPass( const VecDrawP& prims, SingleTex* texDest,
00058 const vec4i& viewport, bool restoreView )
00059 {
00060 bool changeView = (viewport != 0);
00061 initMembers( prims, texDest, NULL, false, changeView, viewport, restoreView );
00062 }
00063
00064
00065 RenderPass::RenderPass( DrawableGLI* prim, PBuffGlift* pbuffDest, bool restoreContext,
00066 const vec4i& viewport, bool restoreView )
00067 {
00068 m_prim = VecDrawP(1, prim );
00069 bool changeView = (viewport != 0);
00070 initMembers( m_prim, NULL, pbuffDest, restoreContext, changeView, viewport, restoreView );
00071 }
00072
00073 RenderPass::RenderPass( const VecDrawP& prims, PBuffGlift* pbuffDest, bool restoreContext,
00074 const vec4i& viewport, bool restoreView )
00075 {
00076 bool changeView = (viewport != 0);
00077 initMembers( prims, NULL, pbuffDest, restoreContext, changeView, viewport, restoreView );
00078 }
00079
00080
00081 RenderPass::RenderPass( DrawableGLI* prim, SingleTex* texDest, PBuffGlift* pbuffDest,
00082 bool restoreContext, const vec4i& viewport, bool restoreView )
00083 {
00084 m_prim = VecDrawP(1, prim );
00085 bool changeView = (viewport != 0);
00086 initMembers( m_prim, texDest, pbuffDest, restoreContext, changeView, viewport, restoreView );
00087 }
00088
00089 RenderPass::RenderPass( const VecDrawP& prims, SingleTex* texDest, PBuffGlift* pbuffDest,
00090 bool restoreContext, const vec4i& viewport, bool restoreView )
00091 {
00092 bool changeView = (viewport != 0);
00093 initMembers( prims, texDest, pbuffDest, restoreContext, changeView, viewport, restoreView );
00094 }
00095
00096
00097 RenderPass::RenderPass( const RenderPass& rhs )
00098 {
00099 initMembers( rhs );
00100 }
00101
00102 RenderPass& RenderPass::operator=(const RenderPass& rhs)
00103 {
00104 if( &rhs != this ) {
00105 initMembers( rhs );
00106 }
00107 return *this;
00108 }
00109
00110 RenderPass::~RenderPass()
00111 {}
00112
00113 void RenderPass::initMembers( const RenderPass& rhs )
00114 {
00115 initMembers( rhs.m_prim, rhs.m_texDest, rhs.m_pbuffDest, rhs.m_restoreCTX,
00116 rhs.m_changeView, rhs.m_viewport, rhs.m_restoreView );
00117 }
00118
00119 void RenderPass::initMembers( const VecDrawP& prim, SingleTex* texDest, PBuffGlift* pbuffDest,
00120 bool restoreCTX, bool changeView, const vec4i& viewport, bool restoreView )
00121
00122 {
00123 m_prim = prim;
00124 m_texDest = texDest;
00125 m_pbuffDest = pbuffDest;
00126 m_restoreCTX = restoreCTX;
00127 m_changeView = changeView;
00128 m_restoreView= restoreView;
00129 m_viewport = viewport;
00130 m_saveVP = vec4i();
00131
00132 for(uint i=0; i < m_prim.size(); i++) {
00133 if( m_prim[i] == NULL ) {
00134 err() << "initMembers(...) Error:\n"
00135 << "\tprim[" << i << "] == NULL.\n";
00136 exit(1);
00137 }
00138 }
00139 }
00140
00141 void RenderPass::setViewport( const vec4i& viewport, bool restoreView )
00142 {
00143 m_viewport = viewport;
00144 m_restoreView = restoreView;
00145 }
00146
00147 void RenderPass::renderDef()
00148 {
00149
00150 glErr(err(),"renderDef 0");
00151 if( m_pbuffDest ) {
00152 m_pbuffDest->enable(m_restoreCTX);
00153 }
00154 glErr(err(), "renderDef 1");
00155
00156 setViewport();
00157 drawPrims();
00158 restoreViewport();
00159
00160 if( m_texDest ) {
00161 glFlush();
00162
00163 m_texDest->copyToTex( 0, vec3i(0), vec2i(m_viewport[0], m_viewport[2]),
00164 vec2i(m_viewport[1], m_viewport[2]) );
00165 }
00166
00167
00168 if( m_pbuffDest && m_restoreCTX ) {
00169 m_pbuffDest->disable();
00170 }
00171
00172 glErr(err(), "renderDef(...)");
00173 }
00174