gui.h 1.9 KB
Newer Older
M
Matt Pharr 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
// pbrt is Copyright(c) 1998-2020 Matt Pharr, Wenzel Jakob, and Greg Humphreys.
// The pbrt source code is licensed under the Apache License, Version 2.0.
// SPDX: Apache-2.0

#ifndef PBRT_UTIL_GUI_H
#define PBRT_UTIL_GUI_H

#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <pbrt/pbrt.h>

#ifdef PBRT_BUILD_GPU_RENDERER
#include <pbrt/gpu/cudagl.h>
#endif  //  PBRT_BUILD_GPU_RENDERER
#include <pbrt/util/color.h>
#include <pbrt/util/transform.h>
#include <pbrt/util/vecmath.h>

#include <set>
#include <string>

namespace pbrt {

enum DisplayState { EXIT, RESET, NONE };

class GUI {
  public:
    GUI(std::string title, Vector2i resolution, Bounds3f sceneBounds);
    ~GUI();

    RGB *MapFramebuffer() {
#ifdef PBRT_BUILD_GPU_RENDERER
        if (cudaFramebuffer)
            return cudaFramebuffer->Map();
        else
#endif  // PBRT_BUILD_GPU_RENDERER
            return cpuFramebuffer;
    }
    void UnmapFramebuffer() {
#ifdef PBRT_BUILD_GPU_RENDERER
        if (cudaFramebuffer)
            cudaFramebuffer->Unmap();
#endif  // PBRT_BUILD_GPU_RENDERER
    }

    DisplayState RefreshDisplay();

    // It's a little messy that the state of values controlled via the UI
    // are just public variables here but it's probably not worth putting
    // an abstraction layer on top of all this at this point.
    Transform GetCameraTransform() const { return movingFromCamera; }
    Float exposure = 1.f;
    bool printCameraTransform = false;

    void keyboardCallback(GLFWwindow *window, int key, int scan, int action, int mods);

  private:
    bool processKeys();

    std::set<char> keysDown;
    Float moveScale = 1.f;
    Transform movingFromCamera;
    Vector2i resolution;
    bool recordFrames = false;
    int frameNumber = 0;

#ifdef PBRT_BUILD_GPU_RENDERER
    CUDAOutputBuffer<RGB> *cudaFramebuffer = nullptr;
#endif
    RGB *cpuFramebuffer = nullptr;
    GLFWwindow *window = nullptr;
};

}  // namespace pbrt

#endif  // PBRT_UTIL_GUI_H