Browse Source

DebugTools: port screenshot() away from std::string.

Simple & easy, for a change.
pull/499/head
Vladimír Vondruš 3 years ago
parent
commit
19ba0796e8
  1. 11
      src/Magnum/DebugTools/Screenshot.cpp
  2. 18
      src/Magnum/DebugTools/Screenshot.h
  3. 1
      src/Magnum/DebugTools/Test/ScreenshotGLTest.cpp

11
src/Magnum/DebugTools/Screenshot.cpp

@ -26,9 +26,8 @@
#include "Screenshot.h"
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Containers/StringView.h>
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/DebugStl.h>
#include "Magnum/PixelFormat.h"
#include "Magnum/Image.h"
@ -39,12 +38,12 @@
namespace Magnum { namespace DebugTools {
bool screenshot(GL::AbstractFramebuffer& framebuffer, const std::string& filename) {
bool screenshot(GL::AbstractFramebuffer& framebuffer, const Containers::StringView filename) {
PluginManager::Manager<Trade::AbstractImageConverter> manager;
return screenshot(manager, framebuffer, filename);
}
bool screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, const std::string& filename) {
bool screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, const Containers::StringView filename) {
/* Get the implementation-specific color read format for given framebuffer */
const GL::PixelFormat format = framebuffer.implementationColorReadFormat();
const GL::PixelType type = framebuffer.implementationColorReadType();
@ -68,12 +67,12 @@ bool screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager,
return screenshot(manager, framebuffer, *genericFormat, filename);
}
bool screenshot(GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const std::string& filename) {
bool screenshot(GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const Containers::StringView filename) {
PluginManager::Manager<Trade::AbstractImageConverter> manager;
return screenshot(manager, framebuffer, format, filename);
}
bool screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const std::string& filename) {
bool screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, const PixelFormat format, const Containers::StringView filename) {
Containers::Pointer<Trade::AbstractImageConverter> converter;
if(!(converter = manager.loadAndInstantiate("AnyImageConverter")))
return false;

18
src/Magnum/DebugTools/Screenshot.h

@ -29,7 +29,6 @@
* @brief Function @ref Magnum::DebugTools::screenshot()
*/
#include <string>
#include <Corrade/PluginManager/PluginManager.h>
#include "Magnum/Magnum.h"
@ -37,6 +36,11 @@
#include "Magnum/GL/GL.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
/* The filename used to be a std::string */
#include <Corrade/Containers/StringStl.h>
#endif
namespace Magnum { namespace DebugTools {
/**
@ -51,7 +55,7 @@ using @ref GL::AbstractFramebuffer::implementationColorReadFormat() and
@ref GL::AbstractFramebuffer::implementationColorReadType() and then mapped
back to the generic @ref Magnum::PixelFormat "PixelFormat". If, for some
reason, the driver-suggested pixel format is not desired, use the
@ref screenshot(GL::AbstractFramebuffer&, PixelFormat, const std::string&)
@ref screenshot(GL::AbstractFramebuffer&, PixelFormat, Containers::StringView)
overload instead.
The read pixel data are saved using the
@ -66,7 +70,7 @@ map the detected pixel format back to a generic format, if either the
for given file format could not be loaded, or if the file saving fails (for
example due to unsupported pixel format). A message is printed in each case.
*/
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(GL::AbstractFramebuffer& framebuffer, const std::string& filename);
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(GL::AbstractFramebuffer& framebuffer, Containers::StringView filename);
/** @overload
@m_since{2019,10}
@ -75,7 +79,7 @@ Useful in case you already have an instance of the converter plugin manager in
your application or if you intend to save screenshots often, as the operation
doesn't involve costly dynamic library loading and unloading on every call.
*/
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, const std::string& filename);
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, Containers::StringView filename);
/**
@brief Save a screenshot in requested pixel format to a file
@ -84,12 +88,12 @@ bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager<Trade::AbstractI
@param filename File where to save
@m_since{2019,10}
Similar to @ref screenshot(GL::AbstractFramebuffer&, PixelFormat, const std::string&)
Similar to @ref screenshot(GL::AbstractFramebuffer&, PixelFormat, Containers::StringView)
but with an explicit pixel format. Useful in cases where the driver-suggested
pixel format is not desired, however note that supplying a format that's
incompatible with the framebuffer may result in GL errors.
*/
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(GL::AbstractFramebuffer& framebuffer, PixelFormat format, const std::string& filename);
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(GL::AbstractFramebuffer& framebuffer, PixelFormat format, Containers::StringView filename);
/** @overload
@m_since{2019,10}
@ -98,7 +102,7 @@ Useful in case you already have an instance of the converter plugin manager in
your application or if you intend to save screenshots often, as the operation
doesn't involve costly dynamic library loading and unloading on every call.
*/
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, PixelFormat format, const std::string& filename);
bool MAGNUM_DEBUGTOOLS_EXPORT screenshot(PluginManager::Manager<Trade::AbstractImageConverter>& manager, GL::AbstractFramebuffer& framebuffer, PixelFormat format, Containers::StringView filename);
}}

1
src/Magnum/DebugTools/Test/ScreenshotGLTest.cpp

@ -26,7 +26,6 @@
#include <sstream>
#include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringStl.h> /** @todo remove when screenshot() is <string>-free */
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h>

Loading…
Cancel
Save