TRX/lib/glrage/Screenshot.cpp

52 lines
1.1 KiB
C++
Raw Normal View History

2021-11-12 20:03:04 +01:00
#include "Screenshot.hpp"
#include "ContextImpl.hpp"
#include <glrage_gl/Screenshot.hpp>
2021-11-14 23:59:19 +01:00
#include <glrage_util/StringUtils.hpp>
2021-11-12 20:03:04 +01:00
#include <cstdint>
#include <exception>
#include <fstream>
#include <stdexcept>
#include <string>
#include <vector>
namespace glrage {
void Screenshot::schedule(bool schedule)
{
m_schedule = schedule;
}
void Screenshot::captureScheduled()
{
if (m_schedule) {
capture();
m_schedule = false;
}
}
void Screenshot::capture()
{
// find unused screenshot file name
2021-11-14 23:42:18 +01:00
std::string basePath = ContextImpl::instance().getBasePath();
std::string path;
2021-11-12 20:03:04 +01:00
DWORD dwAttrib;
do {
std::string fileName =
StringUtils::format("screenshot%04d.tga", m_index++);
2021-11-14 23:42:18 +01:00
path = basePath + "\\" + fileName;
2021-11-12 20:03:04 +01:00
dwAttrib = GetFileAttributes(path.c_str());
} while (dwAttrib != INVALID_FILE_ATTRIBUTES && m_index < 9999);
// rather unlikely, but better safe than sorry
if (dwAttrib != INVALID_FILE_ATTRIBUTES) {
throw std::runtime_error("All available screenshot slots are used up!");
}
// actual capture
gl::Screenshot::capture(path);
}
2021-11-14 23:42:18 +01:00
} // namespace glrage