changed: gcc8 base update
[opensg.git] / Source / System / Window / Background / OSGPolygonBackground.cpp
blob1696896eca2ecdb2ee3729f50873303e8932e779
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 "OSGMaterial.h"
48 #include "OSGViewport.h"
50 #include "OSGPolygonBackground.h"
51 #include "OSGTileCameraDecorator.h"
52 #include "OSGDrawEnv.h"
53 #include "OSGRenderActionBase.h"
54 #include "OSGPrimeMaterial.h"
56 OSG_USING_NAMESPACE
58 // Documentation for this class is emited in the
59 // OSGPolygonBackgroundBase.cpp file.
60 // To modify it, please change the .fcd file (OSGPolygonBackground.fcd) and
61 // regenerate the base file.
63 /***************************************************************************\
64 * Class variables *
65 \***************************************************************************/
67 /***************************************************************************\
68 * Class methods *
69 \***************************************************************************/
71 void PolygonBackground::initMethod(InitPhase ePhase)
73 Inherited::initMethod(ePhase);
77 /***************************************************************************\
78 * Instance methods *
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
82 - private -
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 PolygonBackground::PolygonBackground(void) :
88 Inherited()
92 PolygonBackground::PolygonBackground(const PolygonBackground &source) :
93 Inherited(source)
97 PolygonBackground::~PolygonBackground(void)
101 /*----------------------------- class specific ----------------------------*/
103 void PolygonBackground::clear(DrawEnv *pEnv)
105 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
106 if(pEnv->getPixelWidth() == 0 ||
107 pEnv->getPixelHeight() == 0 )
109 FWARNING(("Port has zero size: nothing to render to!\n"));
110 return;
113 if(getMFPositions()->size() == 0 ||
114 getMFPositions()->size() != getMFTexCoords()->size())
116 FWARNING(("PolygonBackground::clear: positions and texcoords have "
117 "different/ invalid sizes (%" PRISize " vs. %" PRISize ")!\n",
118 getMFPositions()->size(), getMFTexCoords()->size()));
119 return;
122 Int32 bit = getClearStencilBit(); // 0x0
124 if(bit >= 0)
126 glClearStencil(bit);
128 glClear(GL_COLOR_BUFFER_BIT |
129 GL_DEPTH_BUFFER_BIT |
130 GL_STENCIL_BUFFER_BIT);
132 else
134 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
137 glPushAttrib(GL_ALL_ATTRIB_BITS);
139 glDisable(GL_DEPTH_TEST);
140 glDepthFunc(GL_ALWAYS);
142 if(getCleanup())
143 glDepthMask(GL_FALSE);
145 Real32 aspectX = 1.0f, aspectY = 1.0f;
147 if(getAspectHeight() != 0 && getAspectWidth() != 0)
149 aspectX = (Real32(pEnv->getPixelHeight()) / getAspectHeight()) /
150 (Real32(pEnv->getPixelWidth ()) / getAspectWidth ());
153 Real32 sFac = getScale() > 0 ? getScale() : 1.0f;
154 UInt32 fullWidth;
155 UInt32 fullHeight;
157 if(!getTile())
159 beginOrthoRender(pEnv, getNormalizedX(), getNormalizedY(),
160 fullWidth, fullHeight );
162 Real32 t = 0;
164 if(getAspectHeight() != 0 && getAspectWidth() != 0 &&
165 fullHeight != 0 && fullHeight != 0 )
167 aspectX = (Real32(fullHeight) / getAspectHeight()) /
168 (Real32(fullWidth ) / getAspectWidth ());
170 t = Real32(fullWidth) * (1.0f - aspectX) * 0.5f;
171 t *= Real32(pEnv->getPixelWidth()) / fullWidth;
174 glTranslatef(t, 0.0f, 0.0f);
175 glScalef (aspectX, aspectY, 1.0f);
177 Real32 tW = (1.0f - sFac) * 0.5f * Real32(pEnv->getPixelWidth ());
178 Real32 tH = (1.0f - sFac) * 0.5f * Real32(pEnv->getPixelHeight());
180 glTranslatef(tW, tH, 0.0f);
181 glScalef (sFac, sFac, 1.0f);
183 else
185 glScalef(sFac, sFac, 1.0f);
186 glScalef(aspectX, aspectY, 1.0f);
188 beginOrthoRender(pEnv, getNormalizedX(), getNormalizedY(),
189 fullWidth, fullHeight );
193 getMaterial()->getState()->activate(pEnv);
195 const Vec3f *tc = &getMFTexCoords()->front();
196 const Pnt2f *pos = &getMFPositions()->front();
198 glBegin(GL_POLYGON);
200 for (UInt16 i=0; i < getMFPositions()->size(); i++)
202 glTexCoord3fv( tc[i].getValues());
203 glVertex2fv (pos[i].getValues());
206 glEnd();
208 getMaterial()->getState()->deactivate(pEnv);
210 glScalef(1, 1, 1);
212 if(getCleanup())
214 if(bit >= 0)
216 glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
218 else
220 glClear(GL_DEPTH_BUFFER_BIT);
224 endOrthoRender(pEnv);
226 glPopAttrib();
227 #endif
230 void PolygonBackground::changed(ConstFieldMaskArg whichField,
231 UInt32 origin,
232 BitVector details)
234 Inherited::changed(whichField, origin, details);
237 void PolygonBackground::dump( UInt32 ,
238 const BitVector ) const
240 SLOG << "Dump PolygonBackground NI" << std::endl;