Skip to content

Commit

Permalink
Add ability to save content of frame buffer to file for debug purposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonetz committed Oct 7, 2018
1 parent fa0175b commit a2ccd79
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/DisplayWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "VI.h"
#include "Graphics/Context.h"
#include "DisplayWindow.h"
#include "PluginAPI.h"
#include "FrameBuffer.h"

void DisplayWindow::start()
{
Expand Down Expand Up @@ -56,6 +58,23 @@ void DisplayWindow::saveScreenshot()
m_bCaptureScreen = false;
}

void DisplayWindow::saveBufferContent(FrameBuffer * _pBuffer)
{
saveBufferContent(_pBuffer->m_FBO, _pBuffer->m_pTexture);
}

void DisplayWindow::saveBufferContent(graphics::ObjectHandle _fbo, CachedTexture *_pTexture)
{
if (wcslen(m_strScreenDirectory) == 0) {
api().FindPluginPath(m_strScreenDirectory);
std::wstring pluginPath(m_strScreenDirectory);
if (pluginPath.back() != L'/')
pluginPath += L'/';
::wcsncpy(m_strScreenDirectory, pluginPath.c_str(), pluginPath.length() + 1);
}
_saveBufferContent(_fbo, _pTexture);
}

bool DisplayWindow::changeWindow()
{
if (!m_bToggleFullscreen)
Expand Down
3 changes: 3 additions & 0 deletions src/DisplayWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class DisplayWindow
void restart();
void swapBuffers();
void saveScreenshot();
void saveBufferContent(FrameBuffer * _pBuffer);
void saveBufferContent(graphics::ObjectHandle _fbo, CachedTexture *_pTexture);
bool changeWindow();
bool resizeWindow();
void closeWindow();
Expand Down Expand Up @@ -71,6 +73,7 @@ class DisplayWindow
virtual void _stop() = 0;
virtual void _swapBuffers() = 0;
virtual void _saveScreenshot() = 0;
virtual void _saveBufferContent(graphics::ObjectHandle _fbo, CachedTexture *_pTexture) = 0;
virtual void _changeWindow() = 0;
virtual bool _resizeWindow() = 0;
virtual void _readScreen(void **_pDest, long *_pWidth, long *_pHeight) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DisplayWindowMupen64plus : public DisplayWindow
void _stop() override;
void _swapBuffers() override;
void _saveScreenshot() override;
void _saveBufferContent(graphics::ObjectHandle _fbo, CachedTexture *_pTexture) override;
bool _resizeWindow() override;
void _changeWindow() override;
void _readScreen(void **_pDest, long *_pWidth, long *_pHeight) override {}
Expand Down Expand Up @@ -125,6 +126,10 @@ void DisplayWindowMupen64plus::_saveScreenshot()
{
}

void DisplayWindowMupen64plus::_saveBufferContent(graphics::ObjectHandle /*_fbo*/, CachedTexture* /*_pTexture*/)
{
}

bool DisplayWindowMupen64plus::_resizeWindow()
{
_setAttributes();
Expand Down
19 changes: 19 additions & 0 deletions src/Graphics/OpenGLContext/windows/windows_DisplayWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DisplayWindowWindows : public DisplayWindow
void _stop() override;
void _swapBuffers() override;
void _saveScreenshot() override;
void _saveBufferContent(graphics::ObjectHandle _fbo, CachedTexture *_pTexture) override;
bool _resizeWindow() override;
void _changeWindow() override;
void _readScreen(void **_pDest, long *_pWidth, long *_pHeight) override;
Expand Down Expand Up @@ -177,6 +178,24 @@ void DisplayWindowWindows::_saveScreenshot()
free( pixelData );
}

void DisplayWindowWindows::_saveBufferContent(graphics::ObjectHandle _fbo, CachedTexture *_pTexture)
{
unsigned char * pixelData = NULL;
GLint oldMode;
glGetIntegerv(GL_READ_BUFFER, &oldMode);
gfxContext.bindFramebuffer(graphics::bufferTarget::READ_FRAMEBUFFER, _fbo);
pixelData = (unsigned char*)malloc(_pTexture->realWidth * _pTexture->realHeight * 3);
glReadPixels(0, 0, _pTexture->realWidth, _pTexture->realHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelData);
if (graphics::BufferAttachmentParam(oldMode) == graphics::bufferAttachment::COLOR_ATTACHMENT0) {
FrameBuffer * pCurrentBuffer = frameBufferList().getCurrent();
if (pCurrentBuffer != nullptr)
gfxContext.bindFramebuffer(graphics::bufferTarget::READ_FRAMEBUFFER, pCurrentBuffer->m_FBO);
}
glReadBuffer(oldMode);
SaveScreenshot(m_strScreenDirectory, RSP.romname, _pTexture->realWidth, _pTexture->realHeight, pixelData);
free(pixelData);
}

void DisplayWindowWindows::_changeWindow()
{
static LONG windowedStyle;
Expand Down

0 comments on commit a2ccd79

Please sign in to comment.