1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
47 #include "OSGSepiaComposer.h"
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) :
79 SepiaComposer::SepiaComposer(const SepiaComposer
&source
) :
82 _descvirtaddr (NULL
),
95 SepiaComposer::~SepiaComposer(void)
99 /*----------------------------- class specific ----------------------------*/
101 void SepiaComposer::changed(ConstFieldMaskArg whichField
,
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()
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();
133 connection
->signal();
137 connection
->signal();
142 _toNode
= clusterId()+1;
143 _fromNode
= clusterId()-1;
147 _toNode
= SEPIA_NO_NODE
;
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 */
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
);
178 _pbuffer
= SepiaAllocateAlignedMemory (bfsize
);
179 SepiaLockAndBuildDescriptors (_pam
, _pbuffer
, NULL
,
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
,
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();
215 connection
->signal();
219 connection
->signal();
226 SepiaStartTransfer(_pam
, _fromNode
,
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
);
240 glMatrixMode(GL_PROJECTION
);
243 glOrtho(0, width
, 0, height
,-1,1);
245 glDisable(GL_SCISSOR_TEST
);
247 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
248 glPixelZoom(1.0, 1.0);
249 glDrawPixels(width
,height
,
250 GL_RGBA
, GL_UNSIGNED_BYTE
,
253 glMatrixMode(GL_MODELVIEW
);
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 */
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 */
274 SepiaStartTransfer(_pam
,
279 /* wait for the transfer to complete */
280 SepiaWaitTransfer(_pam
);
285 void SepiaComposer::close(void)
289 /*----------------------------- features ---------------------------------*/
291 /*----------------------------- helper ------------------------------------*/
293 /*----------------------------- thread proc -------------------------------*/