32 #include "frameData.h"
38 #include "framesOrderer.h"
44 , _bgColor( eq::Vector3f::ZERO )
45 , _drawRange( eq::Range::ALL )
46 , _taint( getenv(
"EQ_TAINT_CHANNELS" ))
50 _frame.setFrameData( frameData );
53 static void checkError(
const std::string& msg )
55 const GLenum error = glGetError();
56 if (error != GL_NO_ERROR)
57 LBERROR << msg <<
" GL Error: " << error << std::endl;
73 frameData->resetPlugins();
79 const uint32_t frameNumber )
81 _drawRange = eq::Range::ALL;
82 _bgColor = eq::Vector3f( 0.f, 0.f, 0.f );
87 _bgColor = eq::Vector3f( 1.f, 1.f, 1.f );
101 if( _drawRange == eq::Range::ALL )
102 glClearColor( _bgColor.r(), _bgColor.g(), _bgColor.b(), 1.0f );
104 glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
106 glClear( GL_COLOR_BUFFER_BIT );
110 static void setLights( eq::Matrix4f& invRotationM )
112 GLfloat lightAmbient[] = {0.05f, 0.05f, 0.05f, 1.0f};
113 GLfloat lightDiffuse[] = {0.9f , 0.9f , 0.9f , 1.0f};
114 GLfloat lightSpecular[] = {0.8f , 0.8f , 0.8f , 1.0f};
115 GLfloat lightPosition[] = {1.0f , 1.0f , 1.0f , 0.0f};
117 glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
118 glLightfv( GL_LIGHT0, GL_DIFFUSE, lightDiffuse );
119 glLightfv( GL_LIGHT0, GL_SPECULAR, lightSpecular );
125 glMultMatrixf( invRotationM.array );
126 glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
131 static eq::Vector4f _getTaintColor(
const ColorMode colorMode,
132 const eq::Vector3f& color )
135 return eq::Vector4f::ZERO;
137 eq::Vector4f taintColor( color.r(), color.g(), color.b(), 1.0 );
142 taintColor.a() = alpha;
152 EQ_GL_CALL( glMatrixMode( GL_PROJECTION ));
153 EQ_GL_CALL( glLoadIdentity( ));
156 EQ_GL_CALL( glMatrixMode( GL_MODELVIEW ));
157 EQ_GL_CALL( glLoadIdentity( ));
161 const FrameData& frameData = _getFrameData();
162 const eq::Matrix4f& rotation = frameData.getRotation();
163 const eq::Vector3f& translation = frameData.getTranslation();
165 eq::Matrix4f invRotationM;
166 rotation.inverse( invRotationM );
167 setLights( invRotationM );
171 glTranslatef( translation.x(), translation.y(), translation.z() );
172 glMultMatrixf( rotation.array );
175 Renderer* renderer = pipe->getRenderer();
176 LBASSERT( renderer );
178 eq::Matrix4f modelviewM;
179 eq::Matrix3f modelviewITM;
180 _calcMVandITMV( modelviewM, modelviewITM );
183 const eq::Vector4f taintColor = _getTaintColor( frameData.getColorMode(),
185 const int normalsQuality = _getFrameData().getNormalsQuality();
187 const eq::Range& range =
getRange();
188 renderer->render( range, modelviewM, modelviewITM, invRotationM,
189 taintColor, normalsQuality );
190 checkError(
"error during rendering " );
201 const FrameData& frameData = _getFrameData();
202 return frameData.useOrtho();
205 const FrameData& Channel::_getFrameData()
const
208 return pipe->getFrameData();
211 void Channel::_calcMVandITMV(
212 eq::Matrix4f& modelviewM,
213 eq::Matrix3f& modelviewITM )
const
215 const FrameData& frameData = _getFrameData();
216 const Pipe* pipe =
static_cast< const Pipe*
>(
getPipe( ));
217 const Renderer* renderer = pipe->getRenderer();
221 const VolumeScaling& volScaling = renderer->getVolumeScaling();
223 eq::Matrix4f scale( eq::Matrix4f::ZERO );
224 scale.at(0,0) = volScaling.W;
225 scale.at(1,1) = volScaling.H;
226 scale.at(2,2) = volScaling.D;
229 modelviewM = scale * frameData.getRotation();
231 modelviewM.set_translation( frameData.getTranslation( ));
235 eq::Matrix4f modelviewIM;
236 modelviewM.inverse( modelviewIM );
237 eq::Matrix3f( modelviewIM ).transpose_to( modelviewITM );
241 static void _expandPVP( eq::PixelViewport& pvp,
const eq::Images& images,
242 const eq::Vector2i& offset )
244 for( eq::Images::const_iterator i = images.begin();
245 i != images.end(); ++i )
247 const eq::PixelViewport imagePVP = (*i)->getPixelViewport() + offset;
248 pvp.merge( imagePVP );
253 void Channel::clearViewport(
const eq::PixelViewport &pvp )
256 glScissor( pvp.x, pvp.y, pvp.w, pvp.h );
258 if( _drawRange == eq::Range::ALL )
259 glClearColor( _bgColor.r(), _bgColor.g(), _bgColor.b(), 1.0f );
261 glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
263 glClear( GL_COLOR_BUFFER_BIT );
267 glScissor( 0, 0, windowPVP.w, windowPVP.h );
270 void Channel::_orderFrames(
eq::Frames& frames )
272 eq::Matrix4f modelviewM;
273 eq::Matrix3f modelviewITM;
274 const FrameData& frameData = _getFrameData();
275 const eq::Matrix4f& rotation = frameData.getRotation();
278 _calcMVandITMV( modelviewM, modelviewITM );
280 orderFrames( frames, modelviewM, modelviewITM, rotation,
useOrtho( ));
286 const bool composeOnly = (_drawRange == eq::Range::ALL);
291 eq::PixelViewport coveredPVP;
293 eq::Zoom zoom( eq::Zoom::NONE );
296 for( eq::Frames::const_iterator i = frames.begin();
297 i != frames.end(); ++i )
305 const eq::Range& range = frame->
getRange();
306 if( range == eq::Range::ALL )
310 dbFrames.push_back( frame );
317 if( dbFrames.empty( ))
325 if( !composeOnly && coveredPVP.hasArea( ))
328 data->setRange( _drawRange );
329 dbFrames.push_back( &_frame );
332 _orderFrames( dbFrames );
335 eq::Range newRange( 1.f, 0.f );
336 for(
size_t i = 0; i < dbFrames.size(); ++i )
338 const eq::Range range = dbFrames[i]->getRange();
339 if( newRange.start > range.start ) newRange.start = range.start;
340 if( newRange.end < range.end ) newRange.end = range.end;
342 _drawRange = newRange;
347 if( _bgColor == eq::Vector3f::ZERO && dbFrames.front() == &_frame )
348 dbFrames.erase( dbFrames.begin( ));
349 else if( coveredPVP.hasArea())
355 data->setPixelViewport( coveredPVP );
357 clearViewport( coveredPVP );
360 _frame.
setOffset( eq::Vector2i( coveredPVP.x, coveredPVP.y ));
370 catch(
const co::Exception& e )
372 LBWARN << e.what() << std::endl;
378 void Channel::_startAssemble()
389 const FrameData& frameData = _getFrameData();
408 void Channel::_drawLogo( )
416 glMatrixMode( GL_PROJECTION );
419 glMatrixMode( GL_MODELVIEW );
422 glDisable( GL_DEPTH_TEST );
423 glDisable( GL_LIGHTING );
424 glEnable( GL_BLEND );
425 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
427 glColor3f( 1.0f, 1.0f, 1.0f );
428 const GLenum target = texture->
getTarget();
431 glTexParameteri( target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
432 glTexParameteri( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
434 const float tWidth = float( texture->
getWidth( ) );
435 const float tHeight = float( texture->
getHeight( ) );
437 const float width = target == GL_TEXTURE_2D ? 1.0f : tWidth;
438 const float height = target == GL_TEXTURE_2D ? 1.0f : tHeight;
440 glBegin( GL_QUADS ); {
441 glTexCoord2f( 0, 0 );
442 glVertex3f( 5.0f, 5.0f, 0.0f );
444 glTexCoord2f( width, 0 );
445 glVertex3f( tWidth + 5.0f, 5.0f, 0.0f );
447 glTexCoord2f( width, height );
448 glVertex3f( tWidth + 5.0f, tHeight + 5.0f, 0.0f );
450 glTexCoord2f( 0, height );
451 glVertex3f( 5.0f, tHeight + 5.0f, 0.0f );
456 glDisable( GL_BLEND );
459 void Channel::_drawHelp()
461 const FrameData& frameData = _getFrameData();
462 std::string message = frameData.getMessage();
464 if( !frameData.showHelp() && message.empty( ))
471 glDisable( GL_LIGHTING );
472 glDisable( GL_DEPTH_TEST );
474 glColor3f( 1.f, 1.f, 1.f );
476 if( frameData.showHelp( ))
479 std::string help = EVolve::getHelp();
482 for(
size_t pos = help.find(
'\n' ); pos != std::string::npos;
483 pos = help.find(
'\n' ))
485 glRasterPos3f( 10.f, y, 0.99f );
487 font->
draw( help.substr( 0, pos ));
488 help = help.substr( pos + 1 );
492 glRasterPos3f( 10.f, y, 0.99f );
496 if( !message.empty( ))
503 const float width = pvp.w / vp.w;
504 const float xOffset = vp.x * width;
506 const float height = pvp.h / vp.h;
507 const float yOffset = vp.y * height;
508 const float yMiddle = 0.5f * height;
509 float y = yMiddle - yOffset;
511 for(
size_t pos = message.find(
'\n' ); pos != std::string::npos;
512 pos = message.find(
'\n' ))
514 glRasterPos3f( 10.f - xOffset, y, 0.99f );
516 font->
draw( message.substr( 0, pos ));
517 message = message.substr( pos + 1 );
521 glRasterPos3f( 10.f - xOffset, y, 0.99f );
522 font->
draw( message );
A holder for multiple images.
A channel represents a two-dimensional viewport within a Window.
virtual void setupAssemblyState()
Setup the OpenGL state for a readback or assemble operation.
const Images & getImages() const
virtual void applyViewport() const
Apply the OpenGL viewport for the current rendering task.
Sampling of Frame::waitReady.
virtual void frameStart(const uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
const PixelViewport & getPixelViewport() const
virtual void frameViewFinish(const eq::uint128_t &frameID)
Finish updating a destination channel.
virtual void frameDraw(const eq::uint128_t &frameID)
Draw the scene.
virtual void frameAssemble(const eq::uint128_t &frameID)
Assemble all input frames.
const PixelViewports & getRegions() const
Get the current regions of interest.
A Window represents an on-screen or off-screen drawable.
void setBuffers(const uint32_t buffers)
Set the enabled frame buffer attachments.
virtual void frameStart(const eq::uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
const Viewport & getViewport() const
const Frames & getInputFrames()
void applyScreenFrustum() const
Apply an orthographic frustum for pixel-based 2D operations.
const Vector2i & getOffset() const
static uint32_t assembleFramesSorted(const Frames &frames, Channel *channel, util::Accum *accum, const bool blendAlpha=false)
Assemble all frames in the given order using the fastest implemented algorithm on the given channel...
virtual void outlineViewport()
Outline the current pixel viewport.
A wrapper around AGL, WGL and GLX bitmap fonts.
void disableBuffer(const Buffer buffer)
Disable the usage of a frame buffer attachment for all images.
const Frames & getOutputFrames()
virtual void applyBuffer()
Apply the current rendering buffer, including the color mask.
void waitReady(const uint32_t timeout=LB_TIMEOUT_INDEFINITE) const
Wait for the frame to become available.
void draw(const std::string &text) const
Draw text on the current raster position.
int32_t getHeight() const
virtual bool configExit()
Exit this channel.
A facility class to manage OpenGL objects across shared contexts.
void readback(ObjectManager *glObjects, const DrawableConfig &config)
Read back an image.
std::vector< Image * > Images
A vector of pointers to eq::Image.
void bind() const
Bind the texture.
const Matrix4f & getHeadTransform() const
Return the view matrix.
const Range & getRange() const
virtual void applyHeadTransform() const
Apply the transformation to position the view frustum.
const Range & getRange() const
virtual void frameReadback(const eq::uint128_t &frameID)
Read back the rendered frame buffer into the output frames.
void setZoom(const Zoom &zoom)
Set the zoom for this frame holder.
const Vector3ub & getUniqueColor() const
Samples one channel statistics event.
50% unique color + 50% original color
A holder for a frame data and related parameters.
virtual bool configInit(const eq::uint128_t &initID)
Initialize this channel.
FrameDataPtr getFrameData()
virtual void applyFrustum() const
Apply the frustum matrix for the current rendering task.
const Zoom & getZoom() const
virtual bool configExit()
Exit this channel.
const DrawableConfig & getDrawableConfig() const
std::vector< Frame * > Frames
A vector of pointers to eq::Frame.
void setOffset(const Vector2i &offset)
Set the position of the frame wrt the channel.
virtual bool configInit(const uint128_t &initID)
Initialize this channel.
EQFABRIC_INL void setNearFar(const float nearPlane, const float farPlane)
Set the near and far planes for this channel.
Frames::const_iterator FramesCIter
A const_iterator over a eq::Frame vector.
A wrapper around OpenGL textures.
virtual void frameViewFinish(const uint128_t &frameID)
Finish updating a destination channel.
const PixelViewport & getPixelViewport() const
ObjectManager * getObjectManager()
static void assembleFrame(const Frame *frame, Channel *channel)
Assemble a frame into the frame buffer using the default algorithm.
virtual void frameClear(const eq::uint128_t &frameID)
Clear the frame buffer.
virtual bool useOrtho() const
Select perspective or orthographic rendering.
lunchbox::RefPtr< FrameData > FrameDataPtr
A reference-counted pointer to an eq::FrameData.
virtual void frameReadback(const uint128_t &frameID)
Read back the rendered frame buffer into the output frames.
Render using the colors defined in the ply file.
unsigned getTarget() const
void setQuality(const Frame::Buffer buffer, const float quality)
Set the minimum quality after compression.
virtual void resetAssemblyState()
Reset the OpenGL state after an assembly operation.