Skip to content

Commit

Permalink
new screenshot debug option in gltf_viewer
Browse files Browse the repository at this point in the history
screenshots are saved in the current directory as 
"screenshotXX.ppm" with XX increasing after each
screenshot.
  • Loading branch information
pixelflinger committed Aug 21, 2024
1 parent 574518e commit 1c2ffc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions libs/viewer/include/viewer/AutomationEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ class UTILS_PUBLIC AutomationEngine {
*/
static void exportSettings(const Settings& settings, const char* filename);

static void exportScreenshot(View* view, Renderer* renderer, std::string filename,
bool autoclose, AutomationEngine* automationEngine);

Options getOptions() const { return mOptions; }
bool isRunning() const { return mIsRunning; }
size_t currentTest() const { return mCurrentTest; }
Expand Down
5 changes: 3 additions & 2 deletions libs/viewer/src/AutomationEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void convertRGBAtoRGB(void* buffer, uint32_t width, uint32_t height) {
}
}

static void exportScreenshot(View* view, Renderer* renderer, std::string filename,
void AutomationEngine::exportScreenshot(View* view, Renderer* renderer, std::string filename,
bool autoclose, AutomationEngine* automationEngine) {
const Viewport& vp = view->getViewport();
const size_t byteCount = vp.width * vp.height * 4;
Expand Down Expand Up @@ -244,7 +244,8 @@ void AutomationEngine::tick(Engine* engine, const ViewerContent& content, float
}

if (mOptions.exportScreenshots) {
exportScreenshot(content.view, content.renderer, prefix + ".ppm", isLastTest, this);
AutomationEngine::exportScreenshot(
content.view, content.renderer, prefix + ".ppm", isLastTest, this);
}

if (isLastTest) {
Expand Down
25 changes: 21 additions & 4 deletions samples/gltf_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@
#include <algorithm>
#include <array>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <string>

#include "generated/resources/gltf_demo.h"
Expand Down Expand Up @@ -137,6 +139,8 @@ struct App {

AutomationSpec* automationSpec = nullptr;
AutomationEngine* automationEngine = nullptr;
bool screenshot = false;
uint8_t screenshotSeq = 0;
};

static const char* DEFAULT_IBL = "assets/ibl/lightroom_14b";
Expand Down Expand Up @@ -877,10 +881,15 @@ int main(int argc, char** argv) {

if (ImGui::CollapsingHeader("Debug")) {
auto& debug = engine->getDebugRegistry();
if (ImGui::Button("Capture frame")) {
bool* captureFrame =
debug.getPropertyAddress<bool>("d.renderer.doFrameCapture");
*captureFrame = true;
if (engine->getBackend() == Engine::Backend::METAL) {
if (ImGui::Button("Capture frame")) {
bool* captureFrame =
debug.getPropertyAddress<bool>("d.renderer.doFrameCapture");
*captureFrame = true;
}
}
if (ImGui::Button("Screenshot")) {
app.screenshot = true;
}
ImGui::Checkbox("Disable buffer padding",
debug.getPropertyAddress<bool>("d.renderer.disable_buffer_padding"));
Expand Down Expand Up @@ -1138,6 +1147,14 @@ int main(int argc, char** argv) {
};

auto postRender = [&app](Engine* engine, View* view, Scene*, Renderer* renderer) {
if (app.screenshot) {
std::ostringstream stringStream;
stringStream << "screenshot" << std::setfill('0') << std::setw(2) << +app.screenshotSeq;
AutomationEngine::exportScreenshot(
view, renderer, stringStream.str() + ".ppm", false, app.automationEngine);
++app.screenshotSeq;
app.screenshot = false;
}
if (app.automationEngine->shouldClose()) {
FilamentApp::get().close();
return;
Expand Down

0 comments on commit 1c2ffc9

Please sign in to comment.