Expose ui scaling and orientation
This commit is contained in:
@@ -84,6 +84,9 @@ namespace OpenVulkano
|
|||||||
[[nodiscard]] virtual uint32_t GetWindowId() const = 0;
|
[[nodiscard]] virtual uint32_t GetWindowId() const = 0;
|
||||||
|
|
||||||
virtual void* GetNativeWindowHandle() = 0;
|
virtual void* GetNativeWindowHandle() = 0;
|
||||||
|
|
||||||
|
virtual float GetContentScale() const { return 1; }
|
||||||
|
virtual float GetInterfaceOrientation() const { return 0; }
|
||||||
protected:
|
protected:
|
||||||
static uint32_t CreateWindowId()
|
static uint32_t CreateWindowId()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenVulkano
|
|||||||
if (w > 0 && h > 0)
|
if (w > 0 && h > 0)
|
||||||
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);*/
|
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);*/
|
||||||
io.DisplaySize = { static_cast<float>(m_window->GetWidth()), static_cast<float>(m_window->GetHeight()) };
|
io.DisplaySize = { static_cast<float>(m_window->GetWidth()), static_cast<float>(m_window->GetHeight()) };
|
||||||
io.DisplayFramebufferScale = { 1, 1 };
|
io.DisplayFramebufferScale = { m_window->GetContentScale(), m_window->GetContentScale() };
|
||||||
|
|
||||||
//if (bd->WantUpdateMonitors)
|
//if (bd->WantUpdateMonitors)
|
||||||
//ImGui_ImplGlfw_UpdateMonitors();
|
//ImGui_ImplGlfw_UpdateMonitors();
|
||||||
@@ -68,4 +68,4 @@ namespace OpenVulkano
|
|||||||
io.BackendPlatformUserData = nullptr;
|
io.BackendPlatformUserData = nullptr;
|
||||||
io.BackendFlags = ImGuiBackendFlags_None;
|
io.BackendFlags = ImGuiBackendFlags_None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ namespace OpenVulkano
|
|||||||
IWindowHandler* handler = nullptr;
|
IWindowHandler* handler = nullptr;
|
||||||
void* caMetalLayer = nullptr;
|
void* caMetalLayer = nullptr;
|
||||||
bool tickHandler = true;
|
bool tickHandler = true;
|
||||||
|
float contentScale = 1;
|
||||||
|
float orientation = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Init(RenderAPI::RenderApi renderApi) override {}
|
void Init(RenderAPI::RenderApi renderApi) override {}
|
||||||
@@ -82,6 +84,14 @@ namespace OpenVulkano
|
|||||||
void Close() override {}
|
void Close() override {}
|
||||||
|
|
||||||
void OnResize(uint32_t width, uint32_t height);
|
void OnResize(uint32_t width, uint32_t height);
|
||||||
|
|
||||||
|
virtual float GetContentScale() const override { return contentScale; }
|
||||||
|
|
||||||
|
virtual float GetInterfaceOrientation() const override { return orientation; }
|
||||||
|
|
||||||
|
void SetContentScale(float scale) { contentScale = scale; }
|
||||||
|
|
||||||
|
void SetOrientation(float orientation) { this->orientation = orientation; }
|
||||||
|
|
||||||
void TickHandler();
|
void TickHandler();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,4 +21,6 @@
|
|||||||
-(void)WillDisappear;
|
-(void)WillDisappear;
|
||||||
-(void)DidDisappear;
|
-(void)DidDisappear;
|
||||||
-(void)DidUnload;
|
-(void)DidUnload;
|
||||||
|
|
||||||
|
-(void)SetInterfaceOrientation:(float)orientation;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ using namespace OpenVulkano;
|
|||||||
|
|
||||||
- (void) mtkView:(MTKView *) view drawableSizeWillChange:(CGSize) size
|
- (void) mtkView:(MTKView *) view drawableSizeWillChange:(CGSize) size
|
||||||
{
|
{
|
||||||
|
window->SetContentScale(UIScreen.mainScreen.nativeScale);
|
||||||
window->OnResize(size.width, size.height);
|
window->OnResize(size.width, size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +83,8 @@ using namespace OpenVulkano;
|
|||||||
|
|
||||||
- (void)commonInit {
|
- (void)commonInit {
|
||||||
[self setMultipleTouchEnabled:YES];
|
[self setMultipleTouchEnabled:YES];
|
||||||
|
|
||||||
self.contentScaleFactor = UIScreen.mainScreen.nativeScale / 1.5f;
|
self.contentScaleFactor = UIScreen.mainScreen.nativeScale;
|
||||||
|
|
||||||
auto size = self.bounds.size;
|
auto size = self.bounds.size;
|
||||||
auto sizeX = size.width * self.contentScaleFactor;
|
auto sizeX = size.width * self.contentScaleFactor;
|
||||||
auto sizeY = size.height * self.contentScaleFactor;
|
auto sizeY = size.height * self.contentScaleFactor;
|
||||||
@@ -126,10 +126,17 @@ using namespace OpenVulkano;
|
|||||||
auto size = self.bounds.size;
|
auto size = self.bounds.size;
|
||||||
auto sizeX = size.width * self.contentScaleFactor;
|
auto sizeX = size.width * self.contentScaleFactor;
|
||||||
auto sizeY = size.height * self.contentScaleFactor;
|
auto sizeY = size.height * self.contentScaleFactor;
|
||||||
|
m_window.SetContentScale(self.contentScaleFactor);
|
||||||
m_window.OnResize(sizeX, sizeY);
|
m_window.OnResize(sizeX, sizeY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)SetInterfaceOrientation:(float)orientation
|
||||||
|
{
|
||||||
|
m_window.SetOrientation(orientation);
|
||||||
|
}
|
||||||
|
|
||||||
- (Math::Vector2f)getTouchPosition:(UITouch*)touch
|
- (Math::Vector2f)getTouchPosition:(UITouch*)touch
|
||||||
{
|
{
|
||||||
CGPoint uitouchLocation = [touch locationInView:touch.view];
|
CGPoint uitouchLocation = [touch locationInView:touch.view];
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenVulkano::Scene
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ICloseable* renderCamera = nullptr;
|
ICloseable* renderCamera = nullptr;
|
||||||
static constexpr inline size_t SIZE = sizeof(Math::Matrix4f) * 3 + sizeof(Math::Vector4f) + sizeof(float) * 8 + 16;
|
static constexpr inline size_t SIZE = sizeof(Math::Matrix4f) * 3 + sizeof(Math::Vector4f) + sizeof(float) * 12;
|
||||||
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_UNIFORM_BUFFER_DYNAMIC, 1, ShaderProgramType::ALL_GRAPHICS };
|
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_UNIFORM_BUFFER_DYNAMIC, 1, ShaderProgramType::ALL_GRAPHICS };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -26,7 +26,8 @@ namespace OpenVulkano::Scene
|
|||||||
float m_nearPlane, m_farPlane, m_width, m_height;
|
float m_nearPlane, m_farPlane, m_width, m_height;
|
||||||
float m_fov = 0, m_aspect = 0, m_scaleFactor = 0, m_perPixelScaleFactor = 0;
|
float m_fov = 0, m_aspect = 0, m_scaleFactor = 0, m_perPixelScaleFactor = 0;
|
||||||
float m_contentScaleFactor = 1, m_zoom = 1; // For use with ortho camera
|
float m_contentScaleFactor = 1, m_zoom = 1; // For use with ortho camera
|
||||||
std::array<uint8_t, 8> m_userData{};
|
float m_interfaceOrientation = 0;
|
||||||
|
float m_padding = 0; //Unused
|
||||||
|
|
||||||
Camera() : m_nearPlane(0), m_farPlane(0), m_width(0), m_height(0) {}
|
Camera() : m_nearPlane(0), m_farPlane(0), m_width(0), m_height(0) {}
|
||||||
|
|
||||||
@@ -55,32 +56,19 @@ namespace OpenVulkano::Scene
|
|||||||
|
|
||||||
virtual void SetSize(const float width, const float height)
|
virtual void SetSize(const float width, const float height)
|
||||||
{
|
{
|
||||||
if (m_width == width && m_height == height) return;
|
if (m_width == width && m_height == height) [[likely]] return;
|
||||||
m_width = width;
|
m_width = width;
|
||||||
m_height = height;
|
m_height = height;
|
||||||
UpdateProjectionMatrix();
|
UpdateProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNearPlane(float nearPlane)
|
void SetNearPlane(float nearPlane) { m_nearPlane = nearPlane; }
|
||||||
{
|
|
||||||
m_nearPlane = nearPlane;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetFarPlane(float farPlane)
|
void SetFarPlane(float farPlane) { m_farPlane = farPlane; }
|
||||||
{
|
|
||||||
m_farPlane = farPlane;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
[[nodiscard]] float NearPlane() const { return m_nearPlane; }
|
||||||
|
|
||||||
[[nodiscard]] float NearPlane() const
|
[[nodiscard]] float FarPlane() const { return m_farPlane; }
|
||||||
{
|
|
||||||
return m_nearPlane;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] float FarPlane() const
|
|
||||||
{
|
|
||||||
return m_farPlane;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetContentScaleFactor(float contentScale = 1)
|
void SetContentScaleFactor(float contentScale = 1)
|
||||||
{
|
{
|
||||||
@@ -88,6 +76,10 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] float GetContentScaleFactor() const { return 1.0f / m_contentScaleFactor; }
|
[[nodiscard]] float GetContentScaleFactor() const { return 1.0f / m_contentScaleFactor; }
|
||||||
|
|
||||||
|
void SetInterfaceOrientation(float orientation) { m_interfaceOrientation = orientation; }
|
||||||
|
|
||||||
|
float GetInterfaceOrientation() const { return m_interfaceOrientation; }
|
||||||
|
|
||||||
void SetZoom(float zoom) { m_zoom = 1.0f / zoom; }
|
void SetZoom(float zoom) { m_zoom = 1.0f / zoom; }
|
||||||
|
|
||||||
@@ -126,10 +118,7 @@ namespace OpenVulkano::Scene
|
|||||||
return m_viewProjection;
|
return m_viewProjection;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const Math::Vector4f& GetPosition() const
|
[[nodiscard]] const Math::Vector4f& GetPosition() const { return m_camPosition; }
|
||||||
{
|
|
||||||
return m_camPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] Math::Vector3f GetRightVector() const
|
[[nodiscard]] Math::Vector3f GetRightVector() const
|
||||||
{
|
{
|
||||||
@@ -155,12 +144,6 @@ namespace OpenVulkano::Scene
|
|||||||
return {m_viewProjection};
|
return {m_viewProjection};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The 16 byte of user data can be used to transmit additional data about the camera to the shader.
|
|
||||||
* @return reference to the custom data array
|
|
||||||
*/
|
|
||||||
[[nodiscard]] std::array<uint8_t, 8>& GetUserData() { return m_userData; }
|
|
||||||
|
|
||||||
[[nodiscard]] float GetScaleFactor() const { return m_scaleFactor; }
|
[[nodiscard]] float GetScaleFactor() const { return m_scaleFactor; }
|
||||||
[[nodiscard]] float GetPixelScaleFactor() const { return m_perPixelScaleFactor; }
|
[[nodiscard]] float GetPixelScaleFactor() const { return m_perPixelScaleFactor; }
|
||||||
|
|
||||||
@@ -202,6 +185,7 @@ namespace OpenVulkano::Scene
|
|||||||
|
|
||||||
void SetSize(const float width, const float height) override
|
void SetSize(const float width, const float height) override
|
||||||
{
|
{
|
||||||
|
if (m_width == width && m_height == height) [[likely]] return;
|
||||||
m_aspect = width / height;
|
m_aspect = width / height;
|
||||||
Camera::SetSize(width, height);
|
Camera::SetSize(width, height);
|
||||||
m_perPixelScaleFactor = m_height / m_scaleFactor;
|
m_perPixelScaleFactor = m_height / m_scaleFactor;
|
||||||
@@ -235,20 +219,14 @@ namespace OpenVulkano::Scene
|
|||||||
m_perPixelScaleFactor = m_height / m_scaleFactor;
|
m_perPixelScaleFactor = m_height / m_scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] float GetFov() const
|
[[nodiscard]] float GetFov() const { return Math::Utils::degrees(m_fov); }
|
||||||
{
|
|
||||||
return Math::Utils::degrees(m_fov);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] float GetFovX() const
|
[[nodiscard]] float GetFovX() const
|
||||||
{
|
{
|
||||||
return 2.0f * atanf(tanf(GetFov() * 0.5f) * m_aspect);
|
return 2.0f * atanf(tanf(GetFov() * 0.5f) * m_aspect);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] float GetFovRad() const
|
[[nodiscard]] float GetFovRad() const { return m_fov; }
|
||||||
{
|
|
||||||
return m_fov;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] float GetFovXRad() const
|
[[nodiscard]] float GetFovXRad() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ namespace OpenVulkano::Vulkan
|
|||||||
{
|
{
|
||||||
currentImageId = context.swapChain.AcquireNextImage();
|
currentImageId = context.swapChain.AcquireNextImage();
|
||||||
scene->GetCamera()->SetSize(context.window->GetWidth(), context.window->GetHeight());
|
scene->GetCamera()->SetSize(context.window->GetWidth(), context.window->GetHeight());
|
||||||
|
scene->GetCamera()->SetContentScaleFactor(context.window->GetContentScale());
|
||||||
|
scene->GetCamera()->SetInterfaceOrientation(context.window->GetInterfaceOrientation());
|
||||||
Render();
|
Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user