// // main.cpp // tests/gpu-test/src // // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "TestWindow.h" #include "TestTextures.h" using TestBuilder = std::function; using TestBuilders = std::list; #define INTERACTIVE class MyTestWindow : public TestWindow { using Parent = TestWindow; TestBuilders _testBuilders; GpuTestBase* _currentTest{ nullptr }; size_t _currentTestId{ 0 }; size_t _currentMaxTests{ 0 }; glm::mat4 _camera; QTime _time; void initGl() override { Parent::initGl(); _time.start(); updateCamera(); _testBuilders = TestBuilders({ [] { return new TexturesTest(); }, }); } void updateCamera() { float t = _time.elapsed() * 1e-3f; glm::vec3 unitscale{ 1.0f }; glm::vec3 up{ 0.0f, 1.0f, 0.0f }; float distance = 3.0f; glm::vec3 camera_position{ distance * sinf(t), 0.5f, distance * cosf(t) }; static const vec3 camera_focus(0); static const vec3 camera_up(0, 1, 0); _camera = glm::inverse(glm::lookAt(camera_position, camera_focus, up)); ViewFrustum frustum; frustum.setPosition(camera_position); frustum.setOrientation(glm::quat_cast(_camera)); frustum.setProjection(_projectionMatrix); } void renderFrame() override { updateCamera(); while ((!_currentTest || (_currentTestId >= _currentMaxTests)) && !_testBuilders.empty()) { if (_currentTest) { delete _currentTest; _currentTest = nullptr; } _currentTest = _testBuilders.front()(); _testBuilders.pop_front(); if (_currentTest) { auto statsObject = _currentTest->statsObject(); QUrl url = _currentTest->statUrl(); if (statsObject) { auto screens = qApp->screens(); auto primaryScreen = qApp->primaryScreen(); auto targetScreen = primaryScreen; for (const auto& screen : screens) { if (screen == primaryScreen) { continue; } targetScreen = screen; break; } auto destPoint = targetScreen->availableGeometry().topLeft(); QQuickView* view = new QQuickView(); view->rootContext()->setContextProperty("Stats", statsObject); view->setSource(url); view->show(); view->setPosition({ destPoint.x() + 100, destPoint.y() + 100 }); } _currentMaxTests = _currentTest->getTestCount(); _currentTestId = 0; } } if (!_currentTest && _testBuilders.empty()) { qApp->quit(); return; } // Tests might need to wait for resources to download if (!_currentTest->isReady()) { return; } gpu::doInBatch("main::renderFrame", _renderArgs->_context, [&](gpu::Batch& batch) { batch.setViewTransform(_camera); _renderArgs->_batch = &batch; _currentTest->renderTest(_currentTestId, *_renderArgs); _renderArgs->_batch = nullptr; }); } }; int main(int argc, char** argv) { setupHifiApplication("GPU Test"); qputenv("HIFI_DEBUG_OPENGL", QByteArray("1")); QApplication app(argc, argv); MyTestWindow window; app.exec(); return 0; }