Skip to content

Commit

Permalink
[XR/XrSession] Added XrSession
Browse files Browse the repository at this point in the history
- This holds the graphics information (swapchains, images, image views), the XR space used, and all other necessary information to be used for each frame
  • Loading branch information
Razakhel committed Nov 12, 2024
1 parent 77423c6 commit 11f8844
Show file tree
Hide file tree
Showing 5 changed files with 618 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/xrDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ int main() {
Raz::Logger::setLoggingLevel(Raz::LoggingLevel::ALL);

Raz::XrContext xrContext("RaZ - XR demo");

Raz::RenderSystem render(1280, 720, "RaZ");
Raz::XrSession xrSession(xrContext);
} catch (const std::exception& exception) {
Raz::Logger::error("Exception occurred: "s + exception.what());
}
Expand Down
1 change: 1 addition & 0 deletions include/RaZ/RaZ.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#include "Utils/ThreadPool.hpp"
#include "Utils/TypeUtils.hpp"
#include "XR/XrContext.hpp"
#include "XR/XrSession.hpp"

using namespace Raz::Literals;

Expand Down
2 changes: 2 additions & 0 deletions include/RaZ/XR/XrContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct XrDebugUtilsMessengerEXT_T;
namespace Raz {

class XrContext {
friend class XrSession;

public:
explicit XrContext(const std::string& appName);

Expand Down
69 changes: 69 additions & 0 deletions include/RaZ/XR/XrSession.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

#ifndef RAZ_XRSESSION_HPP
#define RAZ_XRSESSION_HPP

using XrSession = struct XrSession_T*;
struct XrInstance_T;
struct XrSpace_T;
struct XrSwapchain_T;
struct XrSwapchainImageOpenGLKHR;
struct XrViewConfigurationView;

namespace Raz {

class XrContext;

class XrSession {
public:
explicit XrSession(const XrContext& context);

void begin(unsigned int viewConfigType);
void end();
void renderFrame(const std::vector<XrViewConfigurationView>& viewConfigViews,
unsigned int viewConfigType,
unsigned int environmentBlendMode);

~XrSession();

private:
using XrInstance = XrInstance_T*;
using XrSpace = XrSpace_T*;
using XrSwapchain = XrSwapchain_T*;
struct ImageViewCreateInfo;
struct RenderLayerInfo;
enum class SwapchainType : uint8_t;

struct SwapchainInfo {
XrSwapchain swapchain {};
int64_t swapchainFormat {};
std::vector<void*> imageViews {};
};

void createSwapchains(const std::vector<XrViewConfigurationView>& viewConfigViews);
void destroySwapchains();
void createSwapchainImages(SwapchainInfo& swapchainInfo, SwapchainType swapchainType);
unsigned int createSwapchainImageView(const ImageViewCreateInfo& imageViewCreateInfo);
void destroySwapchainImageView(void* imageView);
void createReferenceSpace();
void destroyReferenceSpace();
bool renderLayer(RenderLayerInfo& layerInfo,
const std::vector<XrViewConfigurationView>& viewConfigViews,
unsigned int viewConfigType);

::XrSession m_handle {};
XrInstance m_instance {};
int m_state {};
bool m_isRunning = false;

std::vector<SwapchainInfo> m_colorSwapchainInfos;
std::vector<SwapchainInfo> m_depthSwapchainInfos;
std::unordered_map<XrSwapchain, std::pair<SwapchainType, std::vector<XrSwapchainImageOpenGLKHR>>> m_swapchainImages;
std::unordered_map<unsigned int, ImageViewCreateInfo> m_imageViews;

XrSpace m_localSpace {};
};

} // namespace Raz

#endif // RAZ_XRSESSION_HPP
Loading

0 comments on commit 11f8844

Please sign in to comment.