NDEVR
API Documentation
QtVulkanSession.h
1#pragma once
2#include <NDEVR/BaseValues.h>
3#include "../../VulkanGraphics/Headers/VulkanSession.h"
4#include "../../VulkanGraphics/Headers/VulkanShader.h"
5#include <NDEVR/ResourceResolver.h>
6#include <NDEVR/QTResourceListener.h>
7#include <NDEVR/ViewportOptions.h>
8#include <QString>
9#include <QIODevice>
10#include <QFile>
11namespace NDEVR
12{
17 class QtVulkanSession : public VulkanSession, public QObject
18 {
19 public:
23 : VulkanSession(device)
24 {}
25
28 {
29 static DynamicPointer<GraphicsSession> s_session;
30 if (s_session.isNull())
31 {
34 {
35 bool active = ViewportOptions::default_render_engine.get() == VulkanSession::VulkanRenderEngineID();
36 s_session->setActive(active);
37 if(active)
38 GraphicsDevice::SetDefaultGraphicsDevice(s_session->device());
39
40 }, s_session.as<QtVulkanSession>().rawptr()));
41 }
42 return s_session;
43 }
44
46 virtual void readShader(const StringView& shader) override
47 {
49 {
50 String shader_name = "Shaders/" + shader + "/" + VulkanShaderManager::formats[i] + ".spv";
51 ResourceResolver::ResolveResource(shader_name, [this, shader, i](bool success, const StringView& s)
52 {
53 if (success)
54 {
55 QFile file(s.getAs<QString>());
56 uint04 file_size = cast<uint04>(file.size());
57 Buffer<char> code(file_size, '\0');
58 success |= file.open(QIODevice::ReadOnly);
59 if (success)
60 {
61 code.setSize(cast<uint04>(file.read(code.begin(), cast<uint04>(file_size))));
62 shaderManager()->addShader(shader, cast<VulkanShaderManager::ShaderType>(i), code);
63 }
64 }
65 lib_assert(success, "Bad shader: " + s);
66 });
67
68 }
69 }
70 };
71}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
A ResourceListener which will always be executed on the main UI thread and can be tied to a Qt Object...
Definition QTTools.h:493
virtual void readShader(const StringView &shader) override
Reads and compiles a shader from resources.
static const DynamicPointer< GraphicsSession > & DefaultSession()
Returns the default shared graphics session, creating it if needed.
QtVulkanSession(const DynamicPointer< VulkanDevice > &device)
Constructs a QtVulkanSession with the given device.
static bool ResolveResource(const StringView &resource, const std::function< void(bool, const StringView &)> &on_finished=nullptr, bool ensure_unzipped=false)
Attempts to resolved a resource.
The core String View class for the NDEVR API.
Definition StringView.h:58
t_type getAs() const
Converts a string into an object.
Definition StringView.h:125
The core String class for the NDEVR API.
Definition String.h:95
static DynamicPointer< VulkanDevice > & DefaultVulkanDevice()
Returns a reference to the global default Vulkan device.
virtual const ConstPointer< GraphicsDevice > & device() const final override
Returns the graphics device (const).
static const StringView formats[ShaderType::e_shader_type_size]
File name suffixes for each shader type.
@ e_shader_type_size
The number of shader types (sentinel).
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
@ file
The source file path associated with this object.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
static ApplicationOption< UUID > default_render_engine
The UUID of the default rendering engine to use.