fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Window / FrameBufferObjects / OSGFBOViewport.cpp
blob934ce6baaef3c8c9743b8c56b4e502108f34a0ac
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
47 #include "OSGGL.h"
49 #include "OSGFBOViewport.h"
50 #include "OSGFrameBufferObject.h"
51 #include "OSGDrawEnv.h"
53 #include "OSGCamera.h"
54 #include "OSGBackground.h"
55 #include "OSGWindow.h"
56 #include "OSGFrameBufferAttachment.h"
58 OSG_BEGIN_NAMESPACE
60 // Documentation for this class is emited in the
61 // OSGFBOViewportBase.cpp file.
62 // To modify it, please change the .fcd file (OSGFBOViewport.fcd) and
63 // regenerate the base file.
65 Int32 FBOViewport::computePixelLeft(void) const
67 if(getLeft() > 1)
68 return Int32(getLeft());
70 if(getFrameBufferObject() == NULL)
71 return Int32(getLeft());
73 return Int32(getFrameBufferObject()->getWidth() * getLeft());
76 Int32 FBOViewport::computePixelRight(void) const
78 // >1: pixel
79 if(getRight() > 1)
80 return Int32(getRight());
82 if(getFrameBufferObject() == NULL)
83 return Int32(getRight());
85 // <=1: partial screen, use 1 less to not overlap other windows
86 return Int32(getFrameBufferObject()->getWidth() * getRight() - 1);
89 Int32 FBOViewport::computePixelBottom(void) const
91 if(getBottom() > 1)
92 return Int32(getBottom());
94 if(getFrameBufferObject() == NULL)
95 return Int32(getBottom());
97 return Int32(getFrameBufferObject()->getHeight() * getBottom());
100 Int32 FBOViewport::computePixelTop(void) const
102 // >1: pixel
103 if(getTop() > 1)
104 return Int32(getTop());
106 if(getFrameBufferObject() == NULL)
107 return Int32(getTop());
109 // <=1: partial screen, use 1 less to not overlap other windows
110 return Int32(getFrameBufferObject()->getHeight() * getTop() - 1);
113 bool FBOViewport::computeIsFullWindow(void) const
115 if(getFrameBufferObject() == NULL)
116 return true;
118 return
119 computePixelBottom() == 0 &&
120 computePixelLeft() == 0 &&
121 computePixelTop() == getFrameBufferObject()->getHeight() - 1 &&
122 computePixelRight() == getFrameBufferObject()->getWidth () - 1;
125 /*----------------------- constructors & destructors ----------------------*/
127 FBOViewport::FBOViewport(void) :
128 Inherited()
132 FBOViewport::FBOViewport(const FBOViewport &source) :
133 Inherited(source)
137 FBOViewport::~FBOViewport(void)
141 /*----------------------------- class specific ----------------------------*/
143 void FBOViewport::initMethod(InitPhase ePhase)
145 Inherited::initMethod(ePhase);
148 void FBOViewport::changed(ConstFieldMaskArg whichField,
149 UInt32 origin,
150 BitVector details)
152 Inherited::changed(whichField, origin, details);
155 void FBOViewport::dump( UInt32 ,
156 const BitVector ) const
158 SLOG << "Dump DBOViewport NI" << std::endl;
162 FrameBufferObject *FBOViewport::getTarget(void)
164 return this->getFrameBufferObject();
167 #ifdef OSG_OLD_RENDER_ACTION
168 void FBOViewport::render(DrawActionBase *action)
170 if(getFrameBufferObject() != NULL)
172 DrawEnv oEnv;
173 oEnv.setWindow(action->getWindow());
175 getFrameBufferObject()->activate(&oEnv);
177 Inherited::render(action);
179 getFrameBufferObject()->deactivate(&oEnv);
181 else
183 Inherited::render(action);
186 #endif
188 OSG_END_NAMESPACE