Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/Renderer.cpp
Show First 20 Lines • Show All 421 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return !g_app_minimized && (g_app_has_focus || !g_VideoMode.IsInFullscreen()); | return !g_app_minimized && (g_app_has_focus || !g_VideoMode.IsInFullscreen()); | ||||
} | } | ||||
void CRenderer::RenderFrame(const bool needsPresent) | void CRenderer::RenderFrame(const bool needsPresent) | ||||
{ | { | ||||
// Do not render if not focused while in fullscreen or minimised, | // Do not render if not focused while in fullscreen or minimised, | ||||
// as that triggers a difficult-to-reproduce crash on some graphic cards. | // as that triggers a difficult-to-reproduce crash on some graphic cards. | ||||
if (!ShouldRender()) | // We might need to overwrite this for video rendering. | ||||
if (!needsPresent && !ShouldRender()) | |||||
return; | return; | ||||
if (m_ScreenShotType == ScreenShotType::BIG) | if (m_ScreenShotType == ScreenShotType::BIG) | ||||
{ | { | ||||
RenderBigScreenShot(needsPresent); | RenderBigScreenShot(needsPresent); | ||||
} | } | ||||
else if (m_ScreenShotType == ScreenShotType::DEFAULT) | else if (m_ScreenShotType == ScreenShotType::DEFAULT) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | if (renderLogger) | ||||
// Profile information | // Profile information | ||||
g_ProfileViewer.RenderProfile(canvas); | g_ProfileViewer.RenderProfile(canvas); | ||||
} | } | ||||
} | } | ||||
void CRenderer::RenderScreenShot(const bool needsPresent) | void CRenderer::RenderScreenShot(const bool needsPresent) | ||||
{ | { | ||||
m_ScreenShotType = ScreenShotType::NONE; | m_ScreenShotType = ScreenShotType::NONE; | ||||
std::string screenshotFormat; | |||||
CFG_GET_VAL("videorendering.format", screenshotFormat); | |||||
// get next available numbered filename | // get next available numbered filename | ||||
// note: %04d -> always 4 digits, so sorting by filename works correctly. | // note: %04d -> always 4 digits, so sorting by filename works correctly. | ||||
const VfsPath filenameFormat(L"screenshots/screenshot%04d.png"); | const VfsPath basenameFormat(L"screenshots/videoscreen%04d"); | ||||
const VfsPath filenameFormat = basenameFormat.ChangeExtension(screenshotFormat); | |||||
VfsPath filename; | VfsPath filename; | ||||
vfs::NextNumberedFilename(g_VFS, filenameFormat, g_NextScreenShotNumber, filename); | vfs::NextNumberedFilename(g_VFS, filenameFormat, g_NextScreenShotNumber, filename); | ||||
const size_t width = static_cast<size_t>(g_xres), height = static_cast<size_t>(g_yres); | const size_t width = static_cast<size_t>(g_xres), height = static_cast<size_t>(g_yres); | ||||
const size_t bpp = 24; | const size_t bpp = 24; | ||||
if (needsPresent && !g_VideoMode.GetBackendDevice()->AcquireNextBackbuffer()) | if (needsPresent && !g_VideoMode.GetBackendDevice()->AcquireNextBackbuffer()) | ||||
return; | return; | ||||
Show All 10 Lines | void CRenderer::RenderScreenShot(const bool needsPresent) | ||||
if (t.wrap(width, height, bpp, TEX_BOTTOM_UP, buf, hdr_size) < 0) | if (t.wrap(width, height, bpp, TEX_BOTTOM_UP, buf, hdr_size) < 0) | ||||
return; | return; | ||||
m->deviceCommandContext->ReadbackFramebufferSync(0, 0, width, height, img); | m->deviceCommandContext->ReadbackFramebufferSync(0, 0, width, height, img); | ||||
m->deviceCommandContext->Flush(); | m->deviceCommandContext->Flush(); | ||||
if (needsPresent) | if (needsPresent) | ||||
g_VideoMode.GetBackendDevice()->Present(); | g_VideoMode.GetBackendDevice()->Present(); | ||||
if (tex_write(&t, filename) == INFO::OK) | int quality; | ||||
CFG_GET_VAL("videorendering.jpeg_quality", quality); | |||||
if (tex_write(&t, filename, quality) == INFO::OK) | |||||
{ | { | ||||
OsPath realPath; | OsPath realPath; | ||||
g_VFS->GetRealPath(filename, realPath); | g_VFS->GetRealPath(filename, realPath); | ||||
LOGMESSAGERENDER(g_L10n.Translate("Screenshot written to '%s'"), realPath.string8()); | |||||
debug_printf( | |||||
CStr(g_L10n.Translate("Screenshot written to '%s'") + "\n").c_str(), | |||||
realPath.string8().c_str()); | |||||
} | } | ||||
else | else | ||||
LOGERROR("Error writing screenshot to '%s'", filename.string8()); | LOGERROR("Error writing screenshot to '%s'", filename.string8()); | ||||
} | } | ||||
void CRenderer::RenderBigScreenShot(const bool needsPresent) | void CRenderer::RenderBigScreenShot(const bool needsPresent) | ||||
{ | { | ||||
m_ScreenShotType = ScreenShotType::NONE; | m_ScreenShotType = ScreenShotType::NONE; | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | void CRenderer::RenderBigScreenShot(const bool needsPresent) | ||||
// Restore the viewport settings | // Restore the viewport settings | ||||
{ | { | ||||
g_Renderer.Resize(g_xres, g_yres); | g_Renderer.Resize(g_xres, g_yres); | ||||
SViewPort vp = { 0, 0, g_xres, g_yres }; | SViewPort vp = { 0, 0, g_xres, g_yres }; | ||||
g_Game->GetView()->SetViewport(vp); | g_Game->GetView()->SetViewport(vp); | ||||
g_Game->GetView()->GetCamera()->SetProjectionFromCamera(oldCamera); | g_Game->GetView()->GetCamera()->SetProjectionFromCamera(oldCamera); | ||||
} | } | ||||
if (tex_write(&t, filename) == INFO::OK) | int quality; | ||||
CFG_GET_VAL("videorendering.jpeg_quality", quality); | |||||
if (tex_write(&t, filename, quality) == INFO::OK) | |||||
{ | { | ||||
OsPath realPath; | OsPath realPath; | ||||
g_VFS->GetRealPath(filename, realPath); | g_VFS->GetRealPath(filename, realPath); | ||||
LOGMESSAGERENDER(g_L10n.Translate("Screenshot written to '%s'"), realPath.string8()); | |||||
debug_printf( | |||||
CStr(g_L10n.Translate("Screenshot written to '%s'") + "\n").c_str(), | |||||
realPath.string8().c_str()); | |||||
} | } | ||||
else | else | ||||
LOGERROR("Error writing screenshot to '%s'", filename.string8()); | LOGERROR("Error writing screenshot to '%s'", filename.string8()); | ||||
free(tileData); | free(tileData); | ||||
} | } | ||||
void CRenderer::BeginFrame() | void CRenderer::BeginFrame() | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator