Skip to content

Commit

Permalink
Fixing Qt 3D example
Browse files Browse the repository at this point in the history
  • Loading branch information
jherico committed Oct 28, 2019
1 parent 06e9ac1 commit 6e28599
Show file tree
Hide file tree
Showing 45 changed files with 583 additions and 433 deletions.
3 changes: 2 additions & 1 deletion cmake/macros/SetupQt.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

macro(setup_qt)
find_package(Qt5 QUIET COMPONENTS ${ARGN})
find_package(Qt5 5.14 QUIET COMPONENTS ${ARGN})
if (Qt5_FOUND)
message(STATUS "Qt ${Qt5_VERSION} found")
if (NOT Qt5_BIN_DIR)
get_property(QMAKE_EXECUTABLE TARGET Qt5::qmake PROPERTY LOCATION)
get_filename_component(Qt5_BIN_DIR ${QMAKE_EXECUTABLE} DIRECTORY CACHE)
Expand Down
17 changes: 12 additions & 5 deletions data/qml/dynamicscene.qml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import QtQuick 2.0

Rectangle {
id: window
color: "red"
anchors.fill: parent
anchors.margins: 50
Item {
width: 800
height: 600
Rectangle {
id: window
color: "red"
width: 100
height: 100
//anchors.fill: parent
anchors.margins: 50
ColorAnimation on color { loops: Animation.Infinite; from: "blue"; to: "yellow"; duration: 1000 }
}
}
6 changes: 3 additions & 3 deletions src/common/basis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class BasisReader {
}
}

uint32_t getImageSize(uint32_t arrayIndex = 0, uint32_t faceIndex = 0) const {
return imageInfo.m_orig_height * imageInfo.m_orig_width * sizeof(uint32_t);
}
uint32_t getImageSize(uint32_t arrayIndex = 0, uint32_t faceIndex = 0) const {
return imageInfo.m_orig_height * imageInfo.m_orig_width * sizeof(uint32_t);
}

void readImageToBuffer(void* outputBuffer, uint32_t arrayIndex = 0, uint32_t faceIndex = 0) const {
uint32_t imageIndex = arrayIndex * (basist::cBASISTexTypeCubemapArray ? 6 : 1);
Expand Down
10 changes: 5 additions & 5 deletions src/common/gl/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ void GLAPIENTRY MessageCallback(GLenum source,
GLsizei length,
const GLchar* message,
const void* userParam) {
if (type == GL_DEBUG_TYPE_OTHER) {
return;
}
auto level = toLogLevel(severity);
LOG_FORMATTED(level, fmt::format("GL CALLBACK: 0x{:x}, message = {}", type, message).c_str());
if (type == GL_DEBUG_TYPE_OTHER) {
return;
}
auto level = toLogLevel(severity);
LOG_FORMATTED(level, fmt::format("GL CALLBACK: 0x{:x}, message = {}", type, message).c_str());
}

void xr_examples::gl::enableDebugLogging() {
Expand Down
6 changes: 3 additions & 3 deletions src/common/gl/pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct AttributeFormat {
Integer,
Long,
};
AttributeFormat(Type type = Type::Float, uint32_t size = 4, uint32_t scalarType = 0x1406, uint32_t offset = 0) : type(type), size(size), scalarType(scalarType), offset(offset) {}
Type type;
AttributeFormat(Type type = Type::Float, uint32_t size = 4, uint32_t scalarType = 0x1406, uint32_t offset = 0) : type(type), size(size), scalarType(scalarType), offset(offset) {}
Type type;
uint32_t size;
uint32_t scalarType;
uint32_t offset;
Expand All @@ -33,7 +33,7 @@ struct Pipeline {
void setAttributeIFormat(uint32_t location, uint32_t size, uint32_t scalarType, uint32_t offset = 0);
void destroy() noexcept;
void create();
void bind();
void bind();

std::unordered_map<ShaderStage, std::list<std::string>> shaderSources;
std::unordered_map<uint32_t, AttributeFormat> attributes;
Expand Down
21 changes: 9 additions & 12 deletions src/common/gl/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using namespace xr_examples::gl;

struct Scene::Private {
using EyeStates = xr_examples::EyeStates;
using HandStates = xr_examples::HandStates;
using EyeStates = xr_examples::EyeStates;
using HandStates = xr_examples::HandStates;

Private() {}

Expand All @@ -20,20 +20,17 @@ struct Scene::Private {
void loadCubemap(const std::string& filename) {
}

void loadScene(const std::string& filename) {
void loadScene(const std::string& filename) {
}

void render(Framebuffer& framebuffer) {
framebuffer.bind();
framebuffer.clear();
xr::for_each_side_index([&](uint32_t eyeIndex) {
framebuffer.setViewport(eyeIndex);
framebuffer.setViewportSide(eyeIndex);
});
framebuffer.bindDefault();
}

HandStates handStates;
EyeStates eyeStates;
HandStates handStates;
EyeStates eyeStates;
};

Scene::~Scene() {
Expand All @@ -48,7 +45,7 @@ void Scene::create() {
}

void Scene::setCubemap(const std::string& cubemapPrefix) {
d->loadCubemap(cubemapPrefix);
d->loadCubemap(cubemapPrefix);
}

void Scene::loadModel(const std::string& modelfile) {
Expand All @@ -60,11 +57,11 @@ void Scene::render(xr_examples::Framebuffer& stereoFramebuffer) {
}

void Scene::updateHands(const xr_examples::HandStates& handStates) {
d->handStates = handStates;
d->handStates = handStates;
}

void Scene::updateEyes(const xr_examples::EyeStates& eyeStates) {
d->eyeStates = eyeStates;
d->eyeStates = eyeStates;
}

#if 0
Expand Down
6 changes: 3 additions & 3 deletions src/common/gl/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Scene : public xr_examples::Scene {
virtual ~Scene();
void render(xr_examples::Framebuffer& stereoFramebuffer) override;
void create() override;
void setCubemap(const std::string& cubemapPrefix) override;
void loadModel(const std::string& modelfile) override;
void destroy() override;
void setCubemap(const std::string& cubemapPrefix) override;
void loadModel(const std::string& modelfile) override;
void destroy() override;
void updateHands(const HandStates& handStates) override;
void updateEyes(const EyeStates& eyeStates) override;

Expand Down
10 changes: 5 additions & 5 deletions src/common/gl/threadedSwapchainRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void ThreadedSwapchainRenderer::create(const xr::Extent2Di& size, const xr::Sess

auto glContext = window.createOffscreenContext();
glContext->makeCurrent();
gl::enableDebugLogging();
gl::enableDebugLogging();
// Framebuffers are not shared between contexts, so we have to create ours AFTER creating and making the offscreen context current
framebuffer.create(size);
// Always make sure the first entry in the swapchain is valid for submission in a layer BEFORE we return on the main thread
Expand All @@ -24,17 +24,17 @@ void ThreadedSwapchainRenderer::create(const xr::Extent2Di& size, const xr::Sess
framebuffer.bindDefault();
framebuffer.advance();
}
// Let derived class do any one-time GL context setup required
// Let derived class do any one-time GL context setup required
initContext();
// Release offscreen context on the main thread
// Release offscreen context on the main thread
glContext->doneCurrent();

// Launch the rendering thread. The offscreen context will remain current on that thread for the duration
// Launch the rendering thread. The offscreen context will remain current on that thread for the duration
thread = std::make_unique<std::thread>([=] {
glContext->makeCurrent();
run();
glContext->doneCurrent();
glContext->destroy();
glContext->destroy();
});

window.makeCurrent();
Expand Down
6 changes: 3 additions & 3 deletions src/common/gl/threadedSwapchainRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class ThreadedSwapchainRenderer {
public:
void requestNewFrame();

virtual void render() = 0;
virtual void render() = 0;
virtual void initContext() = 0;

virtual void create(const xr::Extent2Di& size, const xr::Session& session, Window& window);
const xr::Swapchain& getSwapchain() const;
const xr::Swapchain& getSwapchain() const;

private:
using Mutex = std::mutex;
using Lock = std::unique_lock<Mutex>;

SwapchainFramebuffer framebuffer;
SwapchainFramebuffer framebuffer;
std::condition_variable conditional;
std::mutex mutex;
std::unique_ptr<std::thread> thread;
Expand Down
2 changes: 1 addition & 1 deletion src/common/glad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#include <glad/glad.h>

void xr_examples::glad::init() {
gladLoadGL();
gladLoadGL();
}
2 changes: 1 addition & 1 deletion src/common/glad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace xr_examples { namespace glad {

void init();
void init();

}} // namespace xr_examples::glad
2 changes: 1 addition & 1 deletion src/common/glfw/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace xr_examples { namespace glfw {
struct OffscreenContext : xr_examples::Context {
OffscreenContext(GLFWwindow* parentContext) {
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
context = glfwCreateWindow(100, 100, "", nullptr, parentContext);
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/glfw/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Window : public xr_examples::Window {
struct Private;
public:
static void init();
static void deinit();
static void deinit();

Window();
virtual ~Window();
Expand All @@ -21,7 +21,7 @@ class Window : public xr_examples::Window {
void runWindowLoop(const ::std::function<void()>& handler) override;
void swapBuffers() const override;
void requestClose() override;
Context::Pointer createOffscreenContext() const override;
Context::Pointer createOffscreenContext() const override;

xr::Extent2Di getSize() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/common/imgui/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct Renderer::Private {

if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f) {
// Apply scissor/clipping rectangle
//currentScissor = { clip_rect.x, fb_height - clip_rect.w, clip_rect.z - clip_rect.x, clip_rect.w - clip_rect.y };
//currentScissor = { clip_rect.x, fb_height - clip_rect.w, clip_rect.z - clip_rect.x, clip_rect.w - clip_rect.y };
glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x),
(int)(clip_rect.w - clip_rect.y));
// Bind texture, Draw
Expand Down
10 changes: 5 additions & 5 deletions src/common/imgui/panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
namespace xr_examples { namespace imgui {

class Renderer : public xr_examples::gl::ThreadedSwapchainRenderer {
using Parent = xr_examples::gl::ThreadedSwapchainRenderer;
using Parent = xr_examples::gl::ThreadedSwapchainRenderer;
struct Private;

public:
using Handler = std::function<void()>;
using Handler = std::function<void()>;
static void init();

void render() override;
void initContext() override;
void setHandler(const Handler& handler);
void initContext() override;
void setHandler(const Handler& handler);

private:
std::shared_ptr<Private> d;
Handler handler;
Handler handler;
};

}} // namespace xr_examples::imgui
Expand Down
6 changes: 3 additions & 3 deletions src/common/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ struct HandState {
xr::Posef grip;
xr::Posef aim;
float squeeze{ -1.0 };
bool squeezeTouched{ false };
bool squeezeTouched{ false };
float trigger{ -1.0 };
bool triggerTouched{ false };
bool triggerTouched{ false };
xr::Vector2f thumb;
bool thumbClicked{ false };
bool thumbTouched{ false };
Expand Down Expand Up @@ -86,7 +86,7 @@ struct Framebuffer {
virtual void setViewport(const xr::Rect2Di& viewport) = 0;
virtual uint32_t id() = 0;

virtual void setViewport(uint32_t side) final {
virtual void setViewportSide(uint32_t side) final {
xr::Rect2Di result{ { 0, 0 }, eyeSize };
if (side == 1) {
result.offset.x += eyeSize.width;
Expand Down
6 changes: 3 additions & 3 deletions src/common/magnum/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ magnum::Framebuffer::~Framebuffer() {

void magnum::Framebuffer::create(const xr::Extent2Di& size) {
this->size = size;
this->eyeSize = size;
eyeSize.width /= 2;
this->eyeSize = size;
eyeSize.width /= 2;
d = std::make_shared<Private>(fromXr(size));
}

Expand Down Expand Up @@ -75,7 +75,7 @@ void magnum::Framebuffer::setViewport(const xr::Rect2Di& viewport) {
}

uint32_t magnum::Framebuffer::id() {
return d->object.id();
return d->object.id();
}


Expand Down
4 changes: 2 additions & 2 deletions src/common/magnum/framebuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class Framebuffer : public xr_examples::Framebuffer {
void create(const xr::Extent2Di& size) override;
void bind(Target target = Draw) override;
void clear(const xr::Color4f& color, float depth, int stencil) override;
void destroy() override { d.reset(); }
void destroy() override { d.reset(); }
void bindDefault(Target target = Draw) override;
void setViewport(const xr::Rect2Di& viewport) override;
uint32_t id() override;
uint32_t id() override;
private:
std::shared_ptr<Private> d;
};
Expand Down
4 changes: 2 additions & 2 deletions src/common/magnum/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline Magnum::Matrix4 fromXrGL(const xr::Fovf& fov, float nearZ = 0.01f, float
const float tanAngleWidth = tanAngleRight - tanAngleLeft;
const float tanAngleHeight = tanAngleUp - tanAngleDown;

Magnum::Vector4 result[4];
Magnum::Vector4 result[4];
const float offsetZ = nearZ;
result[0][0] = 2 / tanAngleWidth;
result[1][0] = 0;
Expand All @@ -61,7 +61,7 @@ inline Magnum::Matrix4 fromXrGL(const xr::Fovf& fov, float nearZ = 0.01f, float
result[1][3] = 0;
result[2][3] = -1;
result[3][3] = 0;
return Magnum::Matrix4{result[0], result[1], result[2], result[3]};
return Magnum::Matrix4{result[0], result[1], result[2], result[3]};
}

inline Magnum::Matrix4 fromXr(const xr::Posef& p) {
Expand Down
Loading

0 comments on commit 6e28599

Please sign in to comment.