Skip to content

Commit

Permalink
Implement view screenshot feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tribal-tec committed Jan 9, 2017
1 parent 3537b31 commit 9440d9f
Show file tree
Hide file tree
Showing 18 changed files with 398 additions and 55 deletions.
2 changes: 2 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog {#Changelog}
* [608](https://github.com/Eyescale/Equalizer/pull/608):
Make Frame::Buffer enum an enum class to ease bitmask handling;
enum values are now Frame::Buffer::value instead of Frame::BUFFER_VALUE
* [607](https://github.com/Eyescale/Equalizer/pull/607):
Implement view screenshot feature with eq::View::enableScreenshot()
* [606](https://github.com/Eyescale/Equalizer/pull/606):
Remove unused big-endian/byteswap support
* [601](https://github.com/Eyescale/Equalizer/pull/601):
Expand Down
3 changes: 1 addition & 2 deletions eq/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,7 @@ void Channel::_transmitImage( const co::ObjectVersion& frameDataVersion,

if( isCompressed )
{
BOOST_FOREACH( const pression::CompressorChunk& chunk,
data->compressedData.chunks )
for( const auto& chunk : data->compressedData.chunks )
{
const uint64_t dataSize = chunk.getNumBytes();

Expand Down
14 changes: 12 additions & 2 deletions eq/config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2005-2016, Stefan Eilemann <eile@equalizergraphics.com>
/* Copyright (c) 2005-2017, Stefan Eilemann <eile@equalizergraphics.com>
* Daniel Nachbaur <danielnachbaur@gmail.com>
* Cedric Stalder <cedric Stalder@gmail.com>
*
Expand Down Expand Up @@ -36,9 +36,9 @@
#include "view.h"
#include "window.h"

#include <eq/fabric/commands.h>
#include <eq/fabric/axisEvent.h>
#include <eq/fabric/buttonEvent.h>
#include <eq/fabric/commands.h>
#include <eq/fabric/keyEvent.h>
#include <eq/fabric/pointerEvent.h>
#include <eq/fabric/sizeEvent.h>
Expand Down Expand Up @@ -668,6 +668,16 @@ bool Config::handleEvent( EventICommand command )
return false;
}

case EVENT_VIEW_SCREENSHOT:
{
const uint128_t& originator = command.read< uint128_t >();
LBASSERT( originator != 0 );
View* view = find< View >( originator );
if( view )
return view->handleEvent( command );
return false;
}

case EVENT_NODE_TIMEOUT:
case EVENT_WINDOW_SCREENSAVER:

Expand Down
40 changes: 29 additions & 11 deletions eq/detail/channel.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "../resultImageListener.h"
#include "fileFrameWriter.h"

#include <boost/foreach.hpp>

#ifdef EQUALIZER_USE_DEFLECT
# include "../deflect/proxy.h"
#endif
Expand Down Expand Up @@ -101,29 +99,49 @@ public:
}
#endif

if( resultImageListeners.empty( ))
eq::View* view = channel.getView();
eq::Frame::Buffer buffers = view->getScreenshotBuffers();
if( !resultImageListeners.empty( ))
buffers |= eq::Frame::Buffer::color;

if( buffers == eq::Frame::Buffer::none )
return;

downloadFramebuffer( channel );
BOOST_FOREACH( ResultImageListener* listener, resultImageListeners )
downloadFramebuffer( channel, buffers );
for( ResultImageListener* listener : resultImageListeners )
listener->notifyNewImage( channel, framebufferImage );

if( view->getScreenshotBuffers() != eq::Frame::Buffer::none )
{
view->sendScreenshotEvent( channel.getViewport(),
channel.getPipe()->getCurrentFrame(),
framebufferImage );
}
}

void downloadFramebuffer( eq::Channel& channel )
void downloadFramebuffer( eq::Channel& channel,
const eq::Frame::Buffer buffers )
{
framebufferImage.setAlphaUsage( true );
framebufferImage.setQuality( eq::Frame::Buffer::color, 1.0f );
framebufferImage.setStorageType( eq::Frame::TYPE_MEMORY );
framebufferImage.setInternalFormat( eq::Frame::Buffer::color, GL_RGBA );

if( framebufferImage.startReadback( eq::Frame::Buffer::color,
if( buffers & eq::Frame::Buffer::color )
framebufferImage.startReadback( eq::Frame::Buffer::color,
channel.getPixelViewport(),
channel.getContext(),
channel.getZoom(),
channel.getObjectManager( )))
{
framebufferImage.finishReadback( channel.glewGetContext( ));
}
channel.getObjectManager( ));

if( buffers & eq::Frame::Buffer::depth )
framebufferImage.startReadback( eq::Frame::Buffer::depth,
channel.getPixelViewport(),
channel.getContext(),
channel.getZoom(),
channel.getObjectManager( ));

framebufferImage.finishReadback( channel.glewGetContext( ));
}

/** The configInit/configExit state. */
Expand Down
4 changes: 3 additions & 1 deletion eq/fabric/eventType.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2016, Stefan.Eilemann@epfl.ch
/* Copyright (c) 2016-2017, Stefan.Eilemann@epfl.ch
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
Expand Down Expand Up @@ -83,6 +83,8 @@ enum EventType // Also update string table in event.cpp
EVENT_WINDOW_ERROR, //!< Window error event. @sa CONFIG_ERROR
EVENT_CHANNEL_ERROR, //!< Channel error event. @sa CONFIG_ERROR

EVENT_VIEW_SCREENSHOT, //!< Viewport, frameNumber, Image with requested buffers

// todo
EVENT_NODE_TIMEOUT, //!< Node has timed out
EVENT_WINDOW_SCREENSAVER, //!< A window screensaver request (Win32 only)
Expand Down
27 changes: 18 additions & 9 deletions eq/fabric/view.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2008-2015, Stefan Eilemann <eile@equalizergraphics.com>
/* Copyright (c) 2008-2017, Stefan Eilemann <eile@equalizergraphics.com>
* Daniel Nachbaur <danielnachbaur@gmail.com>
* Cedric Stalder <cedric.stalder@gmail.com>
*
Expand All @@ -21,11 +21,12 @@
#define EQFABRIC_VIEW_H

#include <eq/fabric/api.h>
#include <eq/fabric/equalizer.h> // member
#include <eq/fabric/frustum.h> // base class
#include <eq/fabric/object.h> // base class
#include <eq/fabric/equalizer.h> // member
#include <eq/fabric/frame.h> // enum Frame::Buffer
#include <eq/fabric/frustum.h> // base class
#include <eq/fabric/object.h> // base class
#include <eq/fabric/types.h>
#include <eq/fabric/viewport.h> // member
#include <eq/fabric/viewport.h> // member

#define EQ_MM 1000.f
#define EQ_CM 100.f
Expand Down Expand Up @@ -208,6 +209,12 @@ class View : public Object, public Frustum
* @version 1.0
*/
EQFABRIC_INL uint64_t getCapabilities() const;

/**
* @return the currently set buffers for screenshot feature
* @version 2.1
*/
EQFABRIC_INL Frame::Buffer getScreenshotBuffers() const;
//@}

void setCapabilities( const uint64_t bitmask ); //!< @internal
Expand All @@ -228,11 +235,12 @@ class View : public Object, public Frustum
DIRTY_EQUALIZERS = Object::DIRTY_CUSTOM << 9,
DIRTY_MODELUNIT = Object::DIRTY_CUSTOM << 10,
DIRTY_ATTRIBUTES = Object::DIRTY_CUSTOM << 11,
DIRTY_SCREENSHOT = Object::DIRTY_CUSTOM << 12,
DIRTY_VIEW_BITS =
DIRTY_VIEWPORT | DIRTY_OBSERVER | DIRTY_OVERDRAW |
DIRTY_FRUSTUM | DIRTY_MODE | DIRTY_MINCAPS | DIRTY_MAXCAPS |
DIRTY_CAPABILITIES | DIRTY_OBJECT_BITS | DIRTY_EQUALIZER |
DIRTY_EQUALIZERS | DIRTY_MODELUNIT | DIRTY_ATTRIBUTES
DIRTY_EQUALIZERS | DIRTY_MODELUNIT | DIRTY_ATTRIBUTES | DIRTY_SCREENSHOT
};

/** String attributes. */
Expand Down Expand Up @@ -295,6 +303,9 @@ class View : public Object, public Frustum
/** @internal */
virtual void notifyFrustumChanged() { setDirty( DIRTY_FRUSTUM ); }

/** @internal */
void _setScreenshotBuffers( Frame::Buffer buffers );

private:
/** Parent layout (application-side). */
L* const _layout;
Expand All @@ -311,6 +322,7 @@ class View : public Object, public Frustum
uint64_t _capabilities; //!< intersection of all active channel caps
uint32_t _equalizers; //!< Active Equalizers
float _modelUnit; //!< Scaling of scene in this view
Frame::Buffer _screenshotBuffers;

struct BackupData
{
Expand All @@ -325,9 +337,6 @@ class View : public Object, public Frustum

/** String attributes. */
std::string _sAttributes[SATTR_ALL];

struct Private;
Private* _private; // placeholder for binary-compatible changes
};

template< class L, class V, class O >
Expand Down
23 changes: 22 additions & 1 deletion eq/fabric/view.ipp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* Copyright (c) 2008-2016, Stefan Eilemann <eile@equalizergraphics.com>
/* Copyright (c) 2008-2017, Stefan Eilemann <eile@equalizergraphics.com>
* Daniel Nachbaur <danielnachbaur@gmail.com>
* Cedric Stalder <cedric.stalder@gmail.com>
*
Expand Down Expand Up @@ -49,6 +49,7 @@ View< L, V, O >::View( L* layout )
, _capabilities( LB_BIT_ALL_64 )
, _equalizers( EQUALIZER_ALL )
, _modelUnit( EQ_M )
, _screenshotBuffers( Frame::Buffer::none )
{
// Note: Views are an exception to the strong structuring, since render
// client views are multi-buffered (once per pipe) and do not have a parent
Expand Down Expand Up @@ -98,6 +99,8 @@ void View< L, V, O >::serialize( co::DataOStream& os, const uint64_t dirtyBits )
os << _modelUnit;
if( dirtyBits & DIRTY_ATTRIBUTES )
os << co::Array< std::string >( _sAttributes, SATTR_ALL );
if( dirtyBits & DIRTY_SCREENSHOT )
os << _screenshotBuffers;
}

template< class L, class V, class O >
Expand Down Expand Up @@ -168,6 +171,8 @@ void View< L, V, O >::deserialize( co::DataIStream& is,
is >> _modelUnit;
if( dirtyBits & DIRTY_ATTRIBUTES )
is >> co::Array< std::string >( _sAttributes, SATTR_ALL );
if( dirtyBits & DIRTY_SCREENSHOT )
is >> _screenshotBuffers;
}

template< class L, class V, class O >
Expand Down Expand Up @@ -364,6 +369,22 @@ uint64_t View< L, V, O >::getCapabilities() const
return _capabilities;
}

template< class L, class V, class O >
void View< L, V, O >::_setScreenshotBuffers( const Frame::Buffer buffers )
{
if( _screenshotBuffers == buffers )
return;

_screenshotBuffers = buffers;
setDirty( DIRTY_SCREENSHOT );
}

template< class L, class V, class O >
Frame::Buffer View< L, V, O >::getScreenshotBuffers() const
{
return _screenshotBuffers;
}

template< class L, class V, class O >
const std::string& View< L, V, O >::getSAttribute( const SAttribute attr ) const
{
Expand Down
Loading

0 comments on commit 9440d9f

Please sign in to comment.