Merge pull request #3426 from Sonicadvance1/ES_fix_framedump
Add support for framedumping to OpenGL ES.
This commit is contained in:
commit
e1f21602fd
|
@ -836,7 +836,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
|
||||||
{
|
{
|
||||||
s_recordWidth = source_width;
|
s_recordWidth = source_width;
|
||||||
s_recordHeight = source_height;
|
s_recordHeight = source_height;
|
||||||
bAVIDumping = AVIDump::Start(s_recordWidth, s_recordHeight);
|
bAVIDumping = AVIDump::Start(s_recordWidth, s_recordHeight, AVIDump::DumpFormat::FORMAT_BGR);
|
||||||
if (!bAVIDumping)
|
if (!bAVIDumping)
|
||||||
{
|
{
|
||||||
PanicAlert("Error dumping frames to AVI.");
|
PanicAlert("Error dumping frames to AVI.");
|
||||||
|
|
|
@ -1361,65 +1361,63 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frame dumps are handled a little differently in Windows
|
// Frame dumps are handled a little differently in Windows
|
||||||
// Frame dumping disabled entirely on GLES3
|
|
||||||
if (GLInterface->GetMode() == GLInterfaceMode::MODE_OPENGL)
|
|
||||||
{
|
|
||||||
#if defined(HAVE_LIBAV) || defined (_WIN32)
|
#if defined(HAVE_LIBAV) || defined (_WIN32)
|
||||||
if (SConfig::GetInstance().m_DumpFrames)
|
if (SConfig::GetInstance().m_DumpFrames)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
||||||
if (frame_data.empty() || w != flipped_trc.GetWidth() ||
|
|
||||||
h != flipped_trc.GetHeight())
|
|
||||||
{
|
|
||||||
w = flipped_trc.GetWidth();
|
|
||||||
h = flipped_trc.GetHeight();
|
|
||||||
frame_data.resize(3 * w * h);
|
|
||||||
}
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
||||||
glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_BGR, GL_UNSIGNED_BYTE, &frame_data[0]);
|
|
||||||
if (w > 0 && h > 0)
|
|
||||||
{
|
|
||||||
if (!bLastFrameDumped)
|
|
||||||
{
|
|
||||||
bAVIDumping = AVIDump::Start(w, h);
|
|
||||||
if (!bAVIDumping)
|
|
||||||
{
|
|
||||||
OSD::AddMessage("AVIDump Start failed", 2000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OSD::AddMessage(StringFromFormat(
|
|
||||||
"Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)",
|
|
||||||
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h), 2000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (bAVIDumping)
|
|
||||||
{
|
|
||||||
FlipImageData(&frame_data[0], w, h);
|
|
||||||
AVIDump::AddFrame(&frame_data[0], w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
bLastFrameDumped = true;
|
if (frame_data.empty() ||
|
||||||
}
|
w != flipped_trc.GetWidth() || h != flipped_trc.GetHeight())
|
||||||
else
|
{
|
||||||
|
w = flipped_trc.GetWidth();
|
||||||
|
h = flipped_trc.GetHeight();
|
||||||
|
frame_data.resize(4 * w * h);
|
||||||
|
}
|
||||||
|
|
||||||
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_RGBA, GL_UNSIGNED_BYTE, &frame_data[0]);
|
||||||
|
if (w > 0 && h > 0)
|
||||||
|
{
|
||||||
|
if (!bLastFrameDumped)
|
||||||
{
|
{
|
||||||
NOTICE_LOG(VIDEO, "Error reading framebuffer");
|
bAVIDumping = AVIDump::Start(w, h, AVIDump::DumpFormat::FORMAT_RGBA);
|
||||||
|
if (!bAVIDumping)
|
||||||
|
{
|
||||||
|
OSD::AddMessage("AVIDump Start failed", 2000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OSD::AddMessage(StringFromFormat(
|
||||||
|
"Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)",
|
||||||
|
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h), 2000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (bAVIDumping)
|
||||||
|
{
|
||||||
|
FlipImageData(&frame_data[0], w, h, 4);
|
||||||
|
AVIDump::AddFrame(&frame_data[0], w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
bLastFrameDumped = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (bLastFrameDumped && bAVIDumping)
|
NOTICE_LOG(VIDEO, "Error reading framebuffer");
|
||||||
{
|
|
||||||
std::vector<u8>().swap(frame_data);
|
|
||||||
w = h = 0;
|
|
||||||
AVIDump::Stop();
|
|
||||||
bAVIDumping = false;
|
|
||||||
OSD::AddMessage("Stop dumping frames", 2000);
|
|
||||||
}
|
|
||||||
bLastFrameDumped = false;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (bLastFrameDumped && bAVIDumping)
|
||||||
|
{
|
||||||
|
std::vector<u8>().swap(frame_data);
|
||||||
|
w = h = 0;
|
||||||
|
AVIDump::Stop();
|
||||||
|
bAVIDumping = false;
|
||||||
|
OSD::AddMessage("Stop dumping frames", 2000);
|
||||||
|
}
|
||||||
|
bLastFrameDumped = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
// Finish up the current frame, print some stats
|
// Finish up the current frame, print some stats
|
||||||
|
|
||||||
SetWindowSize(fbStride, fbHeight);
|
SetWindowSize(fbStride, fbHeight);
|
||||||
|
|
|
@ -35,6 +35,7 @@ static AVFormatContext* s_format_context = nullptr;
|
||||||
static AVStream* s_stream = nullptr;
|
static AVStream* s_stream = nullptr;
|
||||||
static AVFrame* s_src_frame = nullptr;
|
static AVFrame* s_src_frame = nullptr;
|
||||||
static AVFrame* s_scaled_frame = nullptr;
|
static AVFrame* s_scaled_frame = nullptr;
|
||||||
|
AVPixelFormat s_pix_fmt = AV_PIX_FMT_BGR24;
|
||||||
static uint8_t* s_yuv_buffer = nullptr;
|
static uint8_t* s_yuv_buffer = nullptr;
|
||||||
static SwsContext* s_sws_context = nullptr;
|
static SwsContext* s_sws_context = nullptr;
|
||||||
static int s_width;
|
static int s_width;
|
||||||
|
@ -54,8 +55,13 @@ static void InitAVCodec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AVIDump::Start(int w, int h)
|
bool AVIDump::Start(int w, int h, DumpFormat format)
|
||||||
{
|
{
|
||||||
|
if (format == DumpFormat::FORMAT_BGR)
|
||||||
|
s_pix_fmt = AV_PIX_FMT_BGR24;
|
||||||
|
else
|
||||||
|
s_pix_fmt = AV_PIX_FMT_RGBA;
|
||||||
|
|
||||||
s_width = w;
|
s_width = w;
|
||||||
s_height = h;
|
s_height = h;
|
||||||
|
|
||||||
|
@ -147,12 +153,12 @@ static void PreparePacket(AVPacket* pkt)
|
||||||
|
|
||||||
void AVIDump::AddFrame(const u8* data, int width, int height)
|
void AVIDump::AddFrame(const u8* data, int width, int height)
|
||||||
{
|
{
|
||||||
avpicture_fill((AVPicture*)s_src_frame, const_cast<u8*>(data), AV_PIX_FMT_BGR24, width, height);
|
avpicture_fill((AVPicture*)s_src_frame, const_cast<u8*>(data), s_pix_fmt, width, height);
|
||||||
|
|
||||||
// Convert image from BGR24 to desired pixel format, and scale to initial
|
// Convert image from {BGR24, RGBA} to desired pixel format, and scale to initial
|
||||||
// width and height
|
// width and height
|
||||||
if ((s_sws_context = sws_getCachedContext(s_sws_context,
|
if ((s_sws_context = sws_getCachedContext(s_sws_context,
|
||||||
width, height, AV_PIX_FMT_BGR24,
|
width, height, s_pix_fmt,
|
||||||
s_width, s_height, s_stream->codec->pix_fmt,
|
s_width, s_height, s_stream->codec->pix_fmt,
|
||||||
SWS_BICUBIC, nullptr, nullptr, nullptr)))
|
SWS_BICUBIC, nullptr, nullptr, nullptr)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,13 @@ private:
|
||||||
static void CloseFile();
|
static void CloseFile();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool Start(int w, int h);
|
enum class DumpFormat
|
||||||
|
{
|
||||||
|
FORMAT_BGR,
|
||||||
|
FORMAT_RGBA
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool Start(int w, int h, DumpFormat format);
|
||||||
static void AddFrame(const u8* data, int width, int height);
|
static void AddFrame(const u8* data, int width, int height);
|
||||||
static void Stop();
|
static void Stop();
|
||||||
static void DoState();
|
static void DoState();
|
||||||
|
|
Loading…
Reference in New Issue