ManaPlus
Public Member Functions | Private Attributes
OpenGLScreenshotHelper Class Reference

#include <openglscreenshothelper.h>

Inheritance diagram for OpenGLScreenshotHelper:
ScreenshotHelper

Public Member Functions

 OpenGLScreenshotHelper ()
 
 ~OpenGLScreenshotHelper ()
 
void prepare ()
 
SDL_Surface * getScreenshot ()
 
- Public Member Functions inherited from ScreenshotHelper
 ScreenshotHelper ()
 
virtual ~ScreenshotHelper ()
 

Private Attributes

FBOInfo mFbo
 

Detailed Description

Definition at line 35 of file openglscreenshothelper.h.

Constructor & Destructor Documentation

◆ OpenGLScreenshotHelper()

OpenGLScreenshotHelper::OpenGLScreenshotHelper ( )

Definition at line 39 of file openglscreenshothelper.cpp.

39  :
41  mFbo()
42 {
43 }

◆ ~OpenGLScreenshotHelper()

OpenGLScreenshotHelper::~OpenGLScreenshotHelper ( )

Definition at line 45 of file openglscreenshothelper.cpp.

46 {
47 }

Member Function Documentation

◆ getScreenshot()

SDL_Surface * OpenGLScreenshotHelper::getScreenshot ( )
virtual

< Surface is in system memory

< Surface is in video memory

< Use asynchronous blits if possible

< Surface is RLE encoded

< Surface is in video memory

< Use asynchronous blits if possible

< Surface is RLE encoded

Implements ScreenshotHelper.

Definition at line 57 of file openglscreenshothelper.cpp.

58 {
59  const int h = mainGraphics->mHeight;
60  const int w = mainGraphics->mWidth - (mainGraphics->mWidth % 4);
61  GLint pack = 1;
62 
63  SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
64  SDL_SWSURFACE, w, h, 24,
65  0xff0000, 0x00ff00, 0x0000ff, 0x000000);
66 
67  if (screenshot == nullptr)
68  return nullptr;
69 
70  if (SDL_MUSTLOCK(screenshot))
71  SDL_LockSurface(screenshot);
72 
73  const size_t lineSize = 3 * w;
74  GLubyte *const buf = new GLubyte[lineSize];
75 
76  // Grap the pixel buffer and write it to the SDL surface
77  mglGetIntegerv(GL_PACK_ALIGNMENT, &pack);
78  mglPixelStorei(GL_PACK_ALIGNMENT, 1);
79  mglReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, screenshot->pixels);
80 
81  // Flip the screenshot, as OpenGL has 0,0 in bottom left
82  const int h2 = h / 2;
83  for (int i = 0; i < h2; i++)
84  {
85  GLubyte *const top = static_cast<GLubyte*>(
86  screenshot->pixels) + lineSize * i;
87  GLubyte *const bot = static_cast<GLubyte*>(
88  screenshot->pixels) + lineSize * (h - 1 - i);
89 
90  memcpy(buf, top, lineSize);
91  memcpy(top, bot, lineSize);
92  memcpy(bot, buf, lineSize);
93  }
94 
95  delete [] buf;
96 
97  if (config.getBoolValue("usefbo"))
99 
100  mglPixelStorei(GL_PACK_ALIGNMENT, pack);
101 
102  if (SDL_MUSTLOCK(screenshot))
103  SDL_UnlockSurface(screenshot);
104 
105  return screenshot;
106 }
bool getBoolValue(const std::string &key) const
static void deleteFBO(FBOInfo *const fbo)
int mWidth
Definition: graphics.h:484
int mHeight
Definition: graphics.h:485
Configuration config
#define MSDL_CreateRGBSurface(flags, w, h, d, r, g, b, a)
Definition: debug.h:55
Graphics * mainGraphics
Definition: graphics.cpp:109
const Image *restrict const top
GraphicsManager graphicsManager
#define mglReadPixels(...)
Definition: mgl.hpp:109
#define mglGetIntegerv(...)
Definition: mgl.hpp:95
#define mglPixelStorei(...)
Definition: mgl.hpp:107
bool screenshot(InputEvent &event)
Definition: actions.cpp:51

References config, GraphicsManager::deleteFBO(), Configuration::getBoolValue(), graphicsManager, mainGraphics, mFbo, mglGetIntegerv, mglPixelStorei, mglReadPixels, Graphics::mHeight, MSDL_CreateRGBSurface, Graphics::mWidth, Actions::screenshot(), and top.

◆ prepare()

void OpenGLScreenshotHelper::prepare ( )
virtual

Implements ScreenshotHelper.

Definition at line 49 of file openglscreenshothelper.cpp.

50 {
51  if (config.getBoolValue("usefbo"))
54  &mFbo);
55 }
static void createFBO(const int width, const int height, FBOInfo *const fbo)

References config, GraphicsManager::createFBO(), Configuration::getBoolValue(), graphicsManager, mainGraphics, mFbo, Graphics::mHeight, and Graphics::mWidth.

Field Documentation

◆ mFbo

FBOInfo OpenGLScreenshotHelper::mFbo
private

Definition at line 49 of file openglscreenshothelper.h.

Referenced by getScreenshot(), and prepare().


The documentation for this class was generated from the following files: