ManaPlus
Public Member Functions | Private Attributes
MobileOpenGLScreenshotHelper Class Reference

#include <mobileopenglscreenshothelper.h>

Inheritance diagram for MobileOpenGLScreenshotHelper:
ScreenshotHelper

Public Member Functions

 MobileOpenGLScreenshotHelper ()
 
 ~MobileOpenGLScreenshotHelper ()
 
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 mobileopenglscreenshothelper.h.

Constructor & Destructor Documentation

◆ MobileOpenGLScreenshotHelper()

MobileOpenGLScreenshotHelper::MobileOpenGLScreenshotHelper ( )

Definition at line 40 of file mobileopenglscreenshothelper.cpp.

◆ ~MobileOpenGLScreenshotHelper()

MobileOpenGLScreenshotHelper::~MobileOpenGLScreenshotHelper ( )

Definition at line 46 of file mobileopenglscreenshothelper.cpp.

47 {
48 }

Member Function Documentation

◆ getScreenshot()

SDL_Surface * MobileOpenGLScreenshotHelper::getScreenshot ( )
virtual

< Surface is in system memory

< 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 58 of file mobileopenglscreenshothelper.cpp.

59 {
60  const int h = mainGraphics->mHeight;
61  const int w = mainGraphics->mWidth - (mainGraphics->mWidth % 4);
62  GLint pack = 1;
63 
64  SDL_Surface *const tmpImage = MSDL_CreateRGBSurface(
65  SDL_SWSURFACE, w, h, 32,
66  0x00ff0000U, 0x0000ff00U, 0x000000ffU, 0xff000000U);
67 
68  if (tmpImage == nullptr)
69  return nullptr;
70 
71  // Grap the pixel buffer and write it to the SDL surface
72  mglGetIntegerv(GL_PACK_ALIGNMENT, &pack);
73  mglPixelStorei(GL_PACK_ALIGNMENT, 1);
74  mglReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);
75 
76  const size_t lineSize = 3 * w;
77  GLubyte *const buf = new GLubyte[lineSize];
78 
79  SDL_Surface *const screenshot = MSDL_CreateRGBSurface(
80  SDL_SWSURFACE, w, h, 24,
81  0xff0000, 0x00ff00, 0x0000ff, 0x000000);
82 
83  if (screenshot == nullptr)
84  {
85  MSDL_FreeSurface(tmpImage);
86  delete [] buf;
87  return nullptr;
88  }
89 
90 #ifdef USE_SDL2
91  SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
92  SDL_SetSurfaceBlendMode(tmpImage, SDL_BLENDMODE_NONE);
93 #else // USE_SDL2
94 
95  // Make sure the alpha channel is not used, but copied to destination
96  SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
97 #endif // USE_SDL2
98 
99  if (SDL_MUSTLOCK(screenshot))
100  SDL_LockSurface(screenshot);
101 
102  SDL_BlitSurface(tmpImage, nullptr, screenshot, nullptr);
103  MSDL_FreeSurface(tmpImage);
104 
105  // Flip the screenshot, as OpenGL has 0,0 in bottom left
106  const int h2 = h / 2;
107  for (int i = 0; i < h2; i++)
108  {
109  GLubyte *const top = static_cast<GLubyte*>(
110  screenshot->pixels) + lineSize * i;
111  GLubyte *const bot = static_cast<GLubyte*>(
112  screenshot->pixels) + lineSize * (h - 1 - i);
113 
114  memcpy(buf, top, lineSize);
115  memcpy(top, bot, lineSize);
116  memcpy(bot, buf, lineSize);
117  }
118 
119  delete [] buf;
120 
121  if (config.getBoolValue("usefbo"))
123 
124  mglPixelStorei(GL_PACK_ALIGNMENT, pack);
125 
126  if (SDL_MUSTLOCK(screenshot))
127  SDL_UnlockSurface(screenshot);
128 
129  return screenshot;
130 }
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
#define MSDL_FreeSurface(surface)
Definition: debug.h:54
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, MSDL_FreeSurface, Graphics::mWidth, Actions::screenshot(), and top.

◆ prepare()

void MobileOpenGLScreenshotHelper::prepare ( )
virtual

Implements ScreenshotHelper.

Definition at line 50 of file mobileopenglscreenshothelper.cpp.

51 {
52  if (config.getBoolValue("usefbo"))
55  &mFbo);
56 }
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 MobileOpenGLScreenshotHelper::mFbo
private

Definition at line 49 of file mobileopenglscreenshothelper.h.

Referenced by getScreenshot(), and prepare().


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