changed: gcc8 base update
[opensg.git] / Source / System / Cluster / Window / SortLast / OSGSepiaComposer.cpp
blob8069b95794f8debda04197e70918e389f956b0f2
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 <stdlib.h>
44 #include <stdio.h>
46 #include "OSGConfig.h"
47 #include "OSGSepiaComposer.h"
49 OSG_USING_NAMESPACE
51 /*! \class OSG::SepiaComposer
53 This composer implements the binary swap composition.
56 void SepiaComposer::initMethod(InitPhase ePhase)
58 Inherited::initMethod(ePhase);
61 /*----------------------- constructors & destructors ----------------------*/
63 SepiaComposer::SepiaComposer(void) :
64 Inherited ( ),
65 _descphysaddr (0 ),
66 _descvirtaddr (NULL),
67 #ifdef OSG_WITH_SEPIA
68 _pam ( ),
69 #endif
70 _frame (0 ),
71 _pbuffer (NULL),
72 _zbuffer (NULL),
73 _fromNode (0 ),
74 _toNode (0 ),
75 _dmaBufferHandle(0 )
79 SepiaComposer::SepiaComposer(const SepiaComposer &source) :
80 Inherited (source),
81 _descphysaddr (0 ),
82 _descvirtaddr (NULL ),
83 #ifdef OSG_WITH_SEPIA
84 _pam ( ),
85 #endif
86 _frame (0 ),
87 _pbuffer (NULL ),
88 _zbuffer (NULL ),
89 _fromNode (0 ),
90 _toNode (0 ),
91 _dmaBufferHandle(0 )
95 SepiaComposer::~SepiaComposer(void)
99 /*----------------------------- class specific ----------------------------*/
101 void SepiaComposer::changed(ConstFieldMaskArg whichField,
102 UInt32 origin,
103 BitVector details)
105 Inherited::changed(whichField, origin, details);
108 void SepiaComposer::dump( UInt32 ,
109 const BitVector ) const
111 SLOG << "Dump SepiaComposer NI" << std::endl;
114 /*----------------------------- features ---------------------------------*/
116 /*! Currently it is not possible to do rendering on the client
118 bool SepiaComposer::getClientRendering()
120 return false;
123 /*----------------------------- composition -------------------------------*/
125 void SepiaComposer::open(void)
127 #ifdef OSG_WITH_SEPIA
128 // sync all renderers and the client
129 Connection *connection=clusterWindow()->getNetwork()->getMainConnection();
130 if(isClient())
132 connection->wait();
133 connection->signal();
135 else
137 connection->signal();
138 connection->wait();
141 bool isDisplay;
142 _toNode = clusterId()+1;
143 _fromNode = clusterId()-1;
145 if(isClient())
147 _toNode = SEPIA_NO_NODE;
148 isDisplay = true;
150 else
152 isDisplay = false;
154 if(clusterId() == 0)
156 _fromNode = SEPIA_NO_NODE;
158 // printf("init %d %d\n",getWidth(),getHeight());
160 int bfsize = clusterWindow()->getWidth() * clusterWindow()->getHeight() * 4;
162 /* open the default Sepia */
163 _pam = SepiaOpen(NULL);
164 /* set the ServerNet node number for this node */
165 SepiaSetNodeNumber(_pam, clusterId());
166 /* set the node type: Rendering or Display */
167 SepiaSetNodeType(_pam, isDisplay ? DISPLAY_NODE : RENDERING_NODE);
168 /* initialize the Sepia */
169 SepiaInit(_pam);
170 /* Insure that cleanup is done when we exit */
171 // !!!! atexit(finalizeSepia);
173 SINFO << "Use readPixel Mode" << std::endl;
174 /* set the channel format */
175 SepiaSetFormat(_pam, TWO_32b_CHANNELS_DISPLAY_ONE);
177 if (isDisplay) {
178 _pbuffer = SepiaAllocateAlignedMemory (bfsize);
179 SepiaLockAndBuildDescriptors (_pam, _pbuffer, NULL,
180 bfsize,
181 isDisplay,
182 &_descvirtaddr,
183 &_descphysaddr);
185 else
187 /*--render node specific setup--*/
188 SepiaSetVerbose(_pam,1);
190 /* set the comparison to less than and 32 bit Z depth */
191 SetCompzParameters(_pam, GL_LESS, Z32);
193 /* setup two buffers: one for the pixels and one for the depth information */
194 _pbuffer = SepiaAllocateAlignedMemory (bfsize);
195 _zbuffer = SepiaAllocateAlignedMemory (bfsize);
196 SepiaLockAndBuildDescriptors (_pam,
197 _pbuffer, _zbuffer,
198 bfsize, isDisplay,
199 &_descvirtaddr,
200 &_descphysaddr);
202 #endif
205 void SepiaComposer::composeWindow(void)
207 #ifdef OSG_WITH_SEPIA
208 int width=clusterWindow()->getWidth();
209 int height=clusterWindow()->getHeight();
210 // sync all renderers and the client
211 Connection *connection=clusterWindow()->getNetwork()->getMainConnection();
212 if(isClient())
214 connection->wait();
215 connection->signal();
217 else
219 connection->signal();
220 connection->wait();
223 // display node ?
224 if (isClient())
226 SepiaStartTransfer(_pam, _fromNode,
227 SEPIA_NO_NODE,
228 _descphysaddr);
229 usleep(1000);
230 /* wait until we have a buffer to display */
231 SepiaWaitTransfer(_pam);
233 glViewport(0,0,width,height);
235 glClearColor(0.0, 0.0, 0.0, 0.0);
236 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
238 glPushMatrix();
239 glLoadIdentity();
240 glMatrixMode(GL_PROJECTION);
241 glPushMatrix();
242 glLoadIdentity();
243 glOrtho(0, width, 0, height,-1,1);
245 glDisable(GL_SCISSOR_TEST);
246 glRasterPos2i(0, 0);
247 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
248 glPixelZoom(1.0, 1.0);
249 glDrawPixels(width,height,
250 GL_RGBA, GL_UNSIGNED_BYTE,
251 _pbuffer);
252 glPopMatrix();
253 glMatrixMode(GL_MODELVIEW);
254 glPopMatrix();
256 else
258 glPixelStorei(GL_PACK_ALIGNMENT, 1);
259 glReadPixels( 0, /* GLint x - lower left corner */
260 0, /* GLint y - lower left corner */
261 width, /* GLsizei width */
262 height, /* GLsizei height */
263 GL_RGBA, /* GLenum format */
264 GL_UNSIGNED_BYTE, /* GLenum type */
265 _pbuffer);
266 glReadPixels( 0, /* GLint x - lower left corner */
267 0, /* GLint y - lower left corner */
268 width, /* GLsizei width */
269 height , /* GLsizei height */
270 GL_DEPTH_COMPONENT, /* GLenum format */
271 GL_UNSIGNED_INT, /* GLenum type */
272 _zbuffer);
274 SepiaStartTransfer(_pam,
275 _fromNode,
276 _toNode,
277 _descphysaddr);
279 /* wait for the transfer to complete */
280 SepiaWaitTransfer(_pam);
282 #endif
285 void SepiaComposer::close(void)
289 /*----------------------------- features ---------------------------------*/
291 /*----------------------------- helper ------------------------------------*/
293 /*----------------------------- thread proc -------------------------------*/