Skip to content

Commit

Permalink
Simplify _readScreen2 for non-mobile builds
Browse files Browse the repository at this point in the history
Removes an unnecessary allocation while keeping the codepath that was supposedly necessary on android.
  • Loading branch information
Morilli authored and gonetz committed Aug 4, 2024
1 parent 35d2f03 commit e7c1f93
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,21 @@ void DisplayWindowMupen64plus::_readScreen2(void * _dest, int * _width, int * _h
if (_dest == nullptr)
return;

u8 *pBufferData = (u8*)malloc((*_width)*(*_height) * 4);
if (pBufferData == nullptr)
return;
u8 *pDest = (u8*)_dest;

#if !defined(OS_ANDROID) && !defined(OS_IOS)
GLint oldMode;
glGetIntegerv(GL_READ_BUFFER, &oldMode);
if (_front != 0)
glReadBuffer(GL_FRONT);
else
glReadBuffer(GL_BACK);
glReadPixels(0, m_heightOffset, m_screenWidth, m_screenHeight, GL_RGBA, GL_UNSIGNED_BYTE, pBufferData);
glReadPixels(0, m_heightOffset, m_screenWidth, m_screenHeight, GL_RGB, GL_UNSIGNED_BYTE, _dest);
glReadBuffer(oldMode);
#else
u8 *pBufferData = (u8*)malloc((*_width)*(*_height) * 4);
if (pBufferData == nullptr)
return;
u8 *pDest = (u8*)_dest;
glReadPixels(0, m_heightOffset, m_screenWidth, m_screenHeight, GL_RGBA, GL_UNSIGNED_BYTE, pBufferData);
#endif

//Convert RGBA to RGB
for (s32 y = 0; y < *_height; ++y) {
Expand All @@ -283,6 +281,7 @@ void DisplayWindowMupen64plus::_readScreen2(void * _dest, int * _width, int * _h
}

free(pBufferData);
#endif
}

graphics::ObjectHandle DisplayWindowMupen64plus::_getDefaultFramebuffer()
Expand Down

0 comments on commit e7c1f93

Please sign in to comment.