33 #include "configEvent.h"
36 # define snprintf _snprintf
39 namespace eqPixelBench
43 #pragma warning(disable: 411) // class defines no constructor to initialize ...
46 const char* internalFormatString;
47 const uint32_t internalFormat;
48 const size_t pixelSize;
51 #pragma warning(default: 411)
53 #define ENUM_MAP_ITEM( internalFormat, pixelSize ) \
54 { #internalFormat, EQ_COMPRESSOR_DATATYPE_ ## internalFormat, pixelSize }
56 static EnumMap _enums[] = {
57 ENUM_MAP_ITEM( RGBA32F, 16 ),
58 ENUM_MAP_ITEM( RGBA, 4 ),
59 ENUM_MAP_ITEM( RGB10_A2, 4 ),
60 ENUM_MAP_ITEM( RGBA16F, 8 ),
61 ENUM_MAP_ITEM( RGBA32F, 16 ),
62 ENUM_MAP_ITEM( DEPTH, 4 ),
71 _frame.setFrameData( frameData );
73 for(
unsigned i = 0; i < NUM_IMAGES; ++i )
84 const uint32_t frameNumber )
87 const lunchbox::Clock* clock = config->
getClock();
91 const std::string formatType =
"app->pipe thread latency";
92 _sendEvent( START_LATENCY, clock->getTimef(), eq::Vector2i( 0, 0 ),
105 glMatrixMode( GL_PROJECTION );
110 glMatrixMode( GL_MODELVIEW );
116 _testFormats( 1.0f );
117 _testFormats( 0.5f );
118 _testFormats( 2.0f );
119 _testTiledOperations();
120 _testDepthAssemble();
125 void Channel::_testFormats(
float applyZoom )
135 const eq::Vector2i offset( pvp.x, pvp.y );
136 const eq::Zoom zoom( applyZoom, applyZoom );
138 lunchbox::Clock clock;
142 for( uint32_t i=0; _enums[i].internalFormatString; ++i )
144 const uint32_t internalFormat = _enums[i].internalFormat;
151 const std::vector< uint32_t >& names =
154 for( std::vector< uint32_t >::const_iterator j = names.begin();
155 j != names.end(); ++j )
157 _draw( eq::uint128_t( 0 ));
162 const uint32_t outputToken =
164 std::stringstream formatType;
165 formatType << _enums[i].internalFormatString << outputToken << *j;
173 while( clock.getTime64() < 100 )
181 const float msec = clock.getTimef() / float( nLoops );
182 const GLenum error = glGetError();
183 if( error != GL_NO_ERROR )
188 const eq::Vector2i area( pixels.
pvp.w, pixels.
pvp.h );
189 const uint64_t dataSizeGPU = area.x() * area.y() *
191 const uint64_t dataSizeCPU =
194 _sendEvent( READBACK, msec, area, formatType.str(), dataSizeGPU,
199 _sendEvent( READBACK, -static_cast<float>( e.glError ),
200 eq::Vector2i(), formatType.str(), 0, 0 );
211 const uint64_t dataSizeCPU =
218 const float msec = clock.getTimef() / float( nLoops );
219 const GLenum error = glGetError();
220 if( error != GL_NO_ERROR )
225 const eq::Vector2i area( pixels.
pvp.w, pixels.
pvp.h );
226 const uint64_t dataSizeGPU =
228 _sendEvent( ASSEMBLE, msec, area, formatType.str(), dataSizeGPU,
233 _sendEvent( ASSEMBLE, -static_cast<float>( e.glError ),
234 eq::Vector2i(), formatType.str(), 0, 0 );
240 void Channel::_testTiledOperations()
246 LBASSERT( images[0] );
249 const eq::Vector2i offset( pvp.x, pvp.y );
254 lunchbox::Clock clock;
259 eq::PixelViewport subPVP = pvp;
260 subPVP.h /= NUM_IMAGES;
262 for(
unsigned i = 0; i < NUM_IMAGES; ++i )
264 LBASSERT( images[ i ] );
265 images[ i ]->setPixelViewport( subPVP );
268 for(
unsigned tiles = 0; tiles < NUM_IMAGES; ++tiles )
270 EQ_GL_CALL( _draw( eq::uint128_t( )));
271 area.y() = subPVP.h * (tiles+1);
274 std::stringstream formatType;
275 formatType << tiles+1 <<
" depth tiles";
278 for(
unsigned j = 0; j <= tiles; ++j )
280 subPVP.y = pvp.y + j * subPVP.h;
283 EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
289 eq::Zoom::NONE, glObjects );
290 image->
finishReadback( eq::Zoom::NONE, glObjects->glewGetContext());
291 msec += clock.getTimef();
294 _sendEvent( READBACK, msec, area, formatType.str(), 0, 0 );
296 if( tiles == NUM_IMAGES-1 )
297 for(
unsigned j = 0; j <= tiles; ++j )
298 _saveImage( images[j],
299 "EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
304 formatType << tiles+1 <<
" color tiles";
307 for(
unsigned j = 0; j <= tiles; ++j )
309 subPVP.y = pvp.y + j * subPVP.h;
313 EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA,
319 eq::Zoom::NONE, glObjects );
320 image->
finishReadback( eq::Zoom::NONE, glObjects->glewGetContext());
321 msec += clock.getTimef();
323 _sendEvent( READBACK, msec, area, formatType.str(), 0, 0 );
325 if( tiles == NUM_IMAGES-1 )
326 for(
unsigned j = 0; j <= tiles; ++j )
327 _saveImage( images[j],
"EQ_COMPRESSOR_DATATYPE_BGRA",
"tiles" );
330 subPVP.y = pvp.y + tiles * subPVP.h;
339 formatType <<
"tiles, GL1.1, " << tiles+1 <<
" images";
342 for(
unsigned j = 0; j <= tiles; ++j )
345 msec = clock.getTimef();
346 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
350 formatType <<
"tiles, CPU, " << tiles+1 <<
" images";
352 std::vector< eq::Frame* > frames;
353 frames.push_back( &_frame );
357 msec = clock.getTimef();
358 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
362 void Channel::_testDepthAssemble()
372 const eq::Vector2i offset( pvp.x, pvp.y );
377 lunchbox::Clock clock;
382 for(
unsigned i = 0; i < NUM_IMAGES; ++i )
391 for( uint64_t i = 0; i < NUM_IMAGES; ++i )
393 _draw( eq::uint128_t( i ));
399 EQ_COMPRESSOR_TRANSFER_RGBA_TO_BGRA,
403 EQ_COMPRESSOR_TRANSFER_DEPTH_TO_DEPTH_UNSIGNED_INT,
410 pvp, eq::Zoom::NONE, glObjects );
411 image->
finishReadback( eq::Zoom::NONE, glObjects->glewGetContext( ));
415 if( i == NUM_IMAGES-1 )
416 _saveImage( image,
"EQ_COMPRESSOR_DATATYPE_DEPTH_UNSIGNED_INT",
426 std::stringstream formatType;
427 formatType <<
"depth, GL1.1, " << i+1 <<
" images";
430 for(
unsigned j = 0; j <= i; ++j )
433 float msec = clock.getTimef();
434 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
437 if( GLEW_VERSION_2_0 )
440 formatType <<
"depth, GLSL, " << i+1 <<
" images";
443 for(
unsigned j = 0; j <= i; ++j )
445 msec = clock.getTimef();
446 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
451 formatType <<
"depth, CPU, " << i+1 <<
" images";
453 std::vector< eq::Frame* > frames;
454 frames.push_back( &_frame );
458 msec = clock.getTimef();
459 _sendEvent( ASSEMBLE, msec, area, formatType.str(), 0, 0 );
463 void Channel::_sendEvent( ConfigEventType type,
const float msec,
464 const eq::Vector2i& area,
465 const std::string& formatType,
466 const uint64_t dataSizeGPU,
467 const uint64_t dataSizeCPU )
472 std::stringstream strName;
474 name = strName.str();
478 << msec << name << area << formatType << dataSizeGPU << dataSizeCPU;
481 void Channel::_saveImage(
const eq::Image* image,
482 const char* externalformat,
487 static uint32_t counter = 0;
488 std::ostringstream stringstream;
489 stringstream <<
"Image_" << ++counter <<
"_" << externalformat <<
"_"
494 void Channel::_draw(
const eq::uint128_t& spin )
497 EQ_GL_CALL( glPushAttrib( GL_ALL_ATTRIB_BITS ));
500 EQ_GL_CALL( glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ));
501 EQ_GL_CALL( glEnable( GL_DEPTH_TEST ));
503 const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
504 glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
506 const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
507 glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient );
510 glRotatef( static_cast< float >( spin.low() + 3 ) * 10, 1.0f, 0.5f, 0.25f );
514 glColor3f( 1.0f, 0.5f, 0.5f );
515 glNormal3f( 0.0f, 0.0f, 1.0f );
516 glBegin( GL_TRIANGLE_STRIP );
517 glVertex3f( .7f, .7f, -1.0f );
518 glVertex3f( -.7f, .7f, -1.0f );
519 glVertex3f( .7f, -.7f, -1.0f );
520 glVertex3f( -.7f, -.7f, -1.0f );
524 glColor3f( 0.5f, 1.0f, 0.5f );
525 glNormal3f( 0.0f, 1.0f, 0.0f );
526 glBegin( GL_TRIANGLE_STRIP );
527 glVertex3f( .7f, -1.0f, .7f );
528 glVertex3f( -.7f, -1.0f, .7f );
529 glVertex3f( .7f, -1.0f, -.7f );
530 glVertex3f( -.7f, -1.0f, -.7f );
534 glColor3f( 0.5f, 0.5f, 1.0f );
535 glNormal3f( 0.0f, 0.0f, -1.0f );
536 glBegin( GL_TRIANGLE_STRIP );
537 glVertex3f( .7f, .7f, 1.0f );
538 glVertex3f( -.7f, .7f, 1.0f );
539 glVertex3f( .7f, -.7f, 1.0f );
540 glVertex3f( -.7f, -.7f, 1.0f );
544 glColor3f( 1.0f, 1.0f, 0.5f );
545 glNormal3f( 0.f, -1.f, 0.f );
546 glBegin( GL_TRIANGLE_STRIP );
547 glVertex3f( .7f, 1.0f, .7f );
548 glVertex3f( -.7f, 1.0f, .7f );
549 glVertex3f( .7f, 1.0f, -.7f );
550 glVertex3f( -.7f, 1.0f, -.7f );
554 glColor3f( 1.0f, 0.5f, 1.0f );
555 glNormal3f( -1.f, 0.f, 0.f );
556 glBegin( GL_TRIANGLE_STRIP );
557 glVertex3f( 1.0f, .7f, .7f );
558 glVertex3f( 1.0f, -.7f, .7f );
559 glVertex3f( 1.0f, .7f, -.7f );
560 glVertex3f( 1.0f, -.7f, -.7f );
564 glColor3f( 0.5f, 1.0f, 1.0f );
565 glNormal3f( 1.f, 0.f, 0.f );
566 glBegin( GL_TRIANGLE_STRIP );
567 glVertex3f( -1.0f, .7f, .7f );
568 glVertex3f( -1.0f, -.7f, .7f );
569 glVertex3f( -1.0f, .7f, -.7f );
570 glVertex3f( -1.0f, -.7f, -.7f );
573 EQ_GL_CALL( glPopAttrib( ));
A holder for multiple images.
static void assembleImageDB_FF(const Image *image, const ImageOp &op)
Start a Z-based assembly of the image color and depth attachment, based on OpenGL 1...
A channel represents a two-dimensional viewport within a Window.
Exception class for Equalizer operations.
const PixelData & getPixelData(const Frame::Buffer) const
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.
virtual void frameStart(const uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
The pixel data structure manages the pixel information for images.
static void assembleImageDB_GLSL(const Image *image, const ImageOp &op)
Start a Z-based assembly of the image color and depth attachment, using GLSL.
void setInternalFormat(const Frame::Buffer buffer, const uint32_t internalFormat)
Set the internal format for the given buffer.
A Window represents an on-screen or off-screen drawable.
const GLEWContext * glewGetContext() const
Get the GLEW context for this channel.
Channel * channel
The destination channel.
virtual void applyBuffer()
Apply the current rendering buffer, including the color mask.
Zoom zoom
The zoom factor.
virtual bool configExit()
Exit this channel.
A facility class to manage OpenGL objects across shared contexts.
use main memory to store pixel data
std::vector< Image * > Images
A vector of pointers to eq::Image.
uint32_t getExternalFormat(const Frame::Buffer buffer) const
Get the external format of the given buffer.
void sendEvent(ConfigEvent &event)
Send an (old) event to the application node.
virtual bool configExit()
Exit this channel.
void flush()
Free all cached data of this image.
virtual void applyHeadTransform() const
Apply the transformation to position the view frustum.
uint32_t buffers
The Frame buffer attachments to use.
const lunchbox::Clock * getClock() const
void setQuality(const Frame::Buffer buffer, const float quality)
Set the minimum quality after a full download-compression path.
uint32_t getPixelDataSize(const Frame::Buffer buffer) const
void setAlphaUsage(const bool enabled)
Set alpha data preservation during download and compression.
bool hasPixelData(const Frame::Buffer buffer) const
A structure describing an image assembly task.
Image * newImage(const Frame::Type type, const DrawableConfig &config)
Allocate and add a new image.
Vector2i offset
The offset wrt destination window.
static void assembleImage(const Image *image, const ImageOp &operation)
Assemble an image into the frame buffer.
FrameDataPtr getFrameData()
virtual void applyFrustum() const
Apply the frustum matrix for the current rendering task.
void bindFrameBuffer()
Rebind the current alternate FBO of the channel or window.
void setPixelViewport(const PixelViewport &pvp)
Set the internal pixel viewport of the image.
void finishReadback(const Zoom &zoom, const GLEWContext *glewContext)
Finish an asynchronous readback.
virtual void frameDraw(const uint128_t &frameID)
Draw the scene.
const PixelViewport & getPixelViewport() const
ObjectManager * getObjectManager()
virtual void frameStart(const eq::uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
const std::string & getName() const
lunchbox::RefPtr< FrameData > FrameDataPtr
A reference-counted pointer to an eq::FrameData.
bool writeImages(const std::string &filenameTemplate) const
Write all valid pixel data as separate images.
PixelViewport pvp
The dimensions of the pixel data in pixels.
void clearPixelData(const Frame::Buffer buffer)
Clear and validate an image buffer.
bool startReadback(const uint32_t buffers, const PixelViewport &pvp, const Zoom &zoom, ObjectManager *glObjects)
Start reading back an image from the frame buffer.
virtual void frameDraw(const eq::uint128_t &frameID)
Draw the scene.
static uint32_t assembleFramesCPU(const Frames &frames, Channel *channel, const bool blendAlpha=false)
Assemble all frames in the given order in a memory buffer using the CPU before assembling the result ...
virtual void resetAssemblyState()
Reset the OpenGL state after an assembly operation.