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 const eq::Matrix4f& modelview = _computeModelView();
181 const eq::Vector4f taintColor = _getTaintColor( frameData.getColorMode(),
183 const int normalsQuality = _getFrameData().getNormalsQuality();
185 const eq::Range& range =
getRange();
186 renderer->render( range, modelview, invRotationM, taintColor,
188 checkError(
"error during rendering " );
199 const FrameData& frameData = _getFrameData();
200 return frameData.useOrtho();
203 const FrameData& Channel::_getFrameData()
const
206 return pipe->getFrameData();
209 eq::Matrix4f Channel::_computeModelView()
const
211 const FrameData& frameData = _getFrameData();
212 const Pipe* pipe =
static_cast< const Pipe*
>(
getPipe( ));
213 const Renderer* renderer = pipe->getRenderer();
214 eq::Matrix4f modelView( eq::Matrix4f::IDENTITY );
218 const VolumeScaling& volScaling = renderer->getVolumeScaling();
220 eq::Matrix4f scale( eq::Matrix4f::ZERO );
221 scale.at(0,0) = volScaling.W;
222 scale.at(1,1) = volScaling.H;
223 scale.at(2,2) = volScaling.D;
226 modelView = scale * frameData.getRotation();
228 modelView.set_translation( frameData.getTranslation( ));
233 static void _expandPVP( eq::PixelViewport& pvp,
const eq::Images& images,
234 const eq::Vector2i& offset )
236 for( eq::Images::const_iterator i = images.begin();
237 i != images.end(); ++i )
239 const eq::PixelViewport imagePVP = (*i)->getPixelViewport() + offset;
240 pvp.merge( imagePVP );
245 void Channel::clearViewport(
const eq::PixelViewport &pvp )
248 glScissor( pvp.x, pvp.y, pvp.w, pvp.h );
250 if( _drawRange == eq::Range::ALL )
251 glClearColor( _bgColor.r(), _bgColor.g(), _bgColor.b(), 1.0f );
253 glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
255 glClear( GL_COLOR_BUFFER_BIT );
259 glScissor( 0, 0, windowPVP.w, windowPVP.h );
262 void Channel::_orderFrames(
eq::Frames& frames )
264 const FrameData& frameData = _getFrameData();
265 const eq::Matrix4f& rotation = frameData.getRotation();
267 const eq::Matrix4f& modelView =
useOrtho() ? eq::Matrix4f::IDENTITY :
271 eq::Matrix3f modelviewITM;
272 eq::Matrix4f modelviewIM;
273 modelView.inverse( modelviewIM );
274 eq::Matrix3f( modelviewIM ).transpose_to( modelviewITM );
276 orderFrames( frames, modelView, modelviewITM, rotation,
useOrtho( ));
282 const bool composeOnly = (_drawRange == eq::Range::ALL);
286 eq::PixelViewport coveredPVP;
288 eq::Zoom zoom( eq::Zoom::NONE );
291 for( eq::Frames::const_iterator i = frames.begin();
292 i != frames.end(); ++i )
300 const eq::Range& range = frame->
getRange();
301 if( range == eq::Range::ALL )
305 dbFrames.push_back( frame );
312 if( dbFrames.empty( ))
320 if( !composeOnly && coveredPVP.hasArea( ))
323 data->setRange( _drawRange );
324 dbFrames.push_back( &_frame );
327 _orderFrames( dbFrames );
330 eq::Range newRange( 1.f, 0.f );
331 for(
size_t i = 0; i < dbFrames.size(); ++i )
333 const eq::Range range = dbFrames[i]->getRange();
334 if( newRange.start > range.start ) newRange.start = range.start;
335 if( newRange.end < range.end ) newRange.end = range.end;
337 _drawRange = newRange;
342 if( _bgColor == eq::Vector3f::ZERO && dbFrames.front() == &_frame )
343 dbFrames.erase( dbFrames.begin( ));
344 else if( coveredPVP.hasArea())
350 data->setPixelViewport( coveredPVP );
352 clearViewport( coveredPVP );
355 _frame.
setOffset( eq::Vector2i( coveredPVP.x, coveredPVP.y ));
365 catch(
const co::Exception& e )
367 LBWARN << e.what() << std::endl;
373 void Channel::_startAssemble()
384 const FrameData& frameData = _getFrameData();
403 void Channel::_drawLogo( )
411 glMatrixMode( GL_PROJECTION );
414 glMatrixMode( GL_MODELVIEW );
417 glDisable( GL_DEPTH_TEST );
418 glDisable( GL_LIGHTING );
419 glEnable( GL_BLEND );
420 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
422 glColor3f( 1.0f, 1.0f, 1.0f );
423 const GLenum target = texture->
getTarget();
426 glTexParameteri( target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
427 glTexParameteri( target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
429 const float tWidth = float( texture->
getWidth( ) );
430 const float tHeight = float( texture->
getHeight( ) );
432 const float width = target == GL_TEXTURE_2D ? 1.0f : tWidth;
433 const float height = target == GL_TEXTURE_2D ? 1.0f : tHeight;
435 glBegin( GL_QUADS ); {
436 glTexCoord2f( 0, 0 );
437 glVertex3f( 5.0f, 5.0f, 0.0f );
439 glTexCoord2f( width, 0 );
440 glVertex3f( tWidth + 5.0f, 5.0f, 0.0f );
442 glTexCoord2f( width, height );
443 glVertex3f( tWidth + 5.0f, tHeight + 5.0f, 0.0f );
445 glTexCoord2f( 0, height );
446 glVertex3f( 5.0f, tHeight + 5.0f, 0.0f );
451 glDisable( GL_BLEND );
454 void Channel::_drawHelp()
456 const FrameData& frameData = _getFrameData();
457 std::string message = frameData.getMessage();
459 if( !frameData.showHelp() && message.empty( ))
466 glDisable( GL_LIGHTING );
467 glDisable( GL_DEPTH_TEST );
469 glColor3f( 1.f, 1.f, 1.f );
471 if( frameData.showHelp( ))
474 std::string help = EVolve::getHelp();
477 for(
size_t pos = help.find(
'\n' ); pos != std::string::npos;
478 pos = help.find(
'\n' ))
480 glRasterPos3f( 10.f, y, 0.99f );
482 font->
draw( help.substr( 0, pos ));
483 help = help.substr( pos + 1 );
487 glRasterPos3f( 10.f, y, 0.99f );
491 if( !message.empty( ))
498 const float width = pvp.w / vp.w;
499 const float xOffset = vp.x * width;
501 const float height = pvp.h / vp.h;
502 const float yOffset = vp.y * height;
503 const float yMiddle = 0.5f * height;
504 float y = yMiddle - yOffset;
506 for(
size_t pos = message.find(
'\n' ); pos != std::string::npos;
507 pos = message.find(
'\n' ))
509 glRasterPos3f( 10.f - xOffset, y, 0.99f );
511 font->
draw( message.substr( 0, pos ));
512 message = message.substr( pos + 1 );
516 glRasterPos3f( 10.f - xOffset, y, 0.99f );
517 font->
draw( message );
const PixelViewport & getPixelViewport() const
virtual EQ_API void frameReadback(const uint128_t &frameID, const Frames &frames)
Read back the rendered frame buffer into the output frames.
void frameAssemble(const eq::uint128_t &, const eq::Frames &) override
Assemble all input frames.
virtual EQ_API void outlineViewport()
Outline the current pixel viewport.
A channel represents a two-dimensional viewport within a Window.
virtual EQ_API void frameStart(const uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
EQ_API void applyScreenFrustum() const
Apply an orthographic frustum for pixel-based 2D operations.
virtual EQ_API bool configInit(const uint128_t &initID)
Initialize this channel.
void frameReadback(const eq::uint128_t &, const eq::Frames &) override
Read back the rendered frame buffer into the output frames.
EQ_API void setBuffers(const uint32_t buffers)
Set the enabled frame buffer attachments.
EQ_API void bind() const
Bind the texture.
EQ_API const Range & getRange() const
A wrapper around AGL, WGL and GLX bitmap fonts.
EQ_API void readback(util::ObjectManager &glObjects, const DrawableConfig &config)
Read back an image.
virtual EQ_API void applyViewport() const
Apply the OpenGL viewport for the current rendering task.
virtual EQ_API void applyFrustum() const
Apply the frustum matrix for the current rendering task.
A wrapper around OpenGL textures.
void frameClear(const eq::uint128_t &frameID) override
Clear the frame buffer.
EQFABRIC_INL const PixelViewport & getPixelViewport() const
EQFABRIC_INL void setNearFar(const float nearPlane, const float farPlane)
Set the near and far planes for this channel.
static void assembleFrame(const Frame *frame, Channel *channel)
Assemble a frame into the frame buffer using the default algorithm.
EQFABRIC_API void setOffset(const Vector2i &offset)
Set the position of the frame wrt the channel.
EQ_API void draw(const std::string &text) const
Draw text on the current raster position.
void frameViewFinish(const eq::uint128_t &frameID) override
Finish updating a destination channel.
std::vector< Image * > Images
A vector of pointers to eq::Image.
void frameStart(const eq::uint128_t &frameID, const uint32_t frameNumber) override
Start rendering a frame.
bool configInit(const eq::uint128_t &initID) override
Initialize this channel.
EQ_API util::ObjectManager & getObjectManager()
EQ_API void setQuality(const Frame::Buffer buffer, const float quality)
Set the minimum quality after compression.
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...
A Window represents an on-screen or off-screen drawable.
bool useOrtho() const override
Select perspective or orthographic rendering.
EQ_API const Vector3ub & getUniqueColor() const
virtual EQ_API void applyHeadTransform() const
Apply the transformation to position the view frustum.
EQ_API void waitReady(const uint32_t timeout=LB_TIMEOUT_INDEFINITE) const
Wait for the frame to become available.
const Viewport & getViewport() const
EQFABRIC_API const Zoom & getZoom() const
A holder for multiple images.
EQ_API const DrawableConfig & getDrawableConfig() const
EQ_API void disableBuffer(const Buffer buffer)
Disable the usage of a frame buffer attachment for all images.
virtual EQ_API bool configExit()
Exit this channel.
std::vector< Frame * > Frames
A vector of pointers to eq::Frame.
void frameDraw(const eq::uint128_t &frameID) override
Draw the scene.
Frames::const_iterator FramesCIter
A const_iterator over a eq::Frame vector.
const Range & getRange() const
EQ_API const Images & getImages() const
const Matrix4f & getHeadTransform() const
Return the view matrix.
virtual EQ_API void frameViewFinish(const uint128_t &frameID)
Finish updating a destination channel.
EQ_API int32_t getWidth() const
A facility class to manage OpenGL objects across shared contexts.
EQ_API int32_t getHeight() const
virtual EQ_API void setupAssemblyState()
Setup the OpenGL state for a readback or assemble operation.
EQ_API unsigned getTarget() const
A holder for a frame data and related parameters.
virtual EQ_API void applyBuffer()
Apply the current rendering buffer, including the color mask.
lunchbox::RefPtr< FrameData > FrameDataPtr
A reference-counted pointer to an eq::FrameData.
virtual EQ_API void resetAssemblyState()
Reset the OpenGL state after an assembly operation.
bool configExit() override
Exit this channel.
Render using the colors defined in the ply file.
EQ_API const PixelViewports & getRegions() const
Get the current regions of interest.
50% unique color + 50% original color
EQFABRIC_API void setZoom(const Zoom &zoom)
Set the zoom for this frame holder.
EQFABRIC_API const Vector2i & getOffset() const
EQ_API FrameDataPtr getFrameData()
Samples one channel statistics event.