| 119 | GLFWOSPRayWindow *GLFWOSPRayWindow::activeWindow = nullptr; |
| 120 | |
| 121 | GLFWOSPRayWindow::GLFWOSPRayWindow( |
| 122 | const vec2i &windowSize, bool denoiserAvail, bool denoiserGPUAvail) |
| 123 | : denoiserAvailable(denoiserAvail) |
| 124 | { |
| 125 | if (activeWindow != nullptr) { |
| 126 | throw std::runtime_error("Cannot create more than one GLFWOSPRayWindow!"); |
| 127 | } |
| 128 | |
| 129 | if (denoiserAvailable) { |
| 130 | denoiser = cpp::ImageOperation("denoiser"); |
| 131 | denoiserEnabled = denoiserGPUAvail; |
| 132 | updateFrameOpsNextFrame = denoiserEnabled; |
| 133 | } |
| 134 | |
| 135 | activeWindow = this; |
| 136 | |
| 137 | glfwSetErrorCallback(error_callback); |
| 138 | if (!glfwInit()) { |
| 139 | throw std::runtime_error("Failed to initialize GLFW!"); |
| 140 | } |
| 141 | |
| 142 | glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE); |
| 143 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
| 144 | #ifdef __APPLE_ |
| 145 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); |
| 146 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); |
| 147 | const char *glslVersion = "#version 150"; |
| 148 | #else |
| 149 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); |
| 150 | const char *glslVersion = "#version 130"; |
| 151 | #endif |
| 152 | |
| 153 | glfwWindow = glfwCreateWindow( |
| 154 | windowSize.x, windowSize.y, "OSPRay Examples", nullptr, nullptr); |
| 155 | |
| 156 | if (!glfwWindow) { |
| 157 | glfwTerminate(); |
| 158 | throw std::runtime_error("Failed to create GLFW window!"); |
| 159 | } |
| 160 | glfwMakeContextCurrent(glfwWindow); |
| 161 | |
| 162 | // Setup Dear ImGui context |
| 163 | IMGUI_CHECKVERSION(); |
| 164 | ImGui::CreateContext(); |
| 165 | ImGuiIO &io = ImGui::GetIO(); |
| 166 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; |
| 167 | |
| 168 | ImGui_ImplGlfw_InitForOpenGL(glfwWindow, false); |
| 169 | |
| 170 | // set GLFW callbacks |
| 171 | glfwSetFramebufferSizeCallback( |
| 172 | glfwWindow, [](GLFWwindow *, int newWidth, int newHeight) { |
| 173 | activeWindow->reshape(vec2i{newWidth, newHeight}); |
| 174 | }); |
| 175 | |
| 176 | glfwSetCursorPosCallback(glfwWindow, [](GLFWwindow *, double x, double y) { |
| 177 | ImGuiIO &io = ImGui::GetIO(); |
| 178 | if (!activeWindow->showUi || !io.WantCaptureMouse) { |