mirror of
https://github.com/love2d/love.git
synced 2026-08-19 04:06:17 +02:00
vulkan: android: fix display orientation
This commit is contained in:
@@ -566,6 +566,7 @@ graphics::Shader::BuiltinUniformData Graphics::getCurrentBuiltinUniformData() {
|
|||||||
|
|
||||||
data.transformMatrix = getTransform();
|
data.transformMatrix = getTransform();
|
||||||
data.projectionMatrix = getDeviceProjection();
|
data.projectionMatrix = getDeviceProjection();
|
||||||
|
data.projectionMatrix = displayRotation * data.projectionMatrix ;
|
||||||
|
|
||||||
// The normal matrix is the transpose of the inverse of the rotation portion
|
// The normal matrix is the transpose of the inverse of the rotation portion
|
||||||
// (top-left 3x3) of the transform matrix.
|
// (top-left 3x3) of the transform matrix.
|
||||||
@@ -951,6 +952,35 @@ void Graphics::createSwapChain() {
|
|||||||
VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes);
|
VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes);
|
||||||
VkExtent2D extent = chooseSwapExtent(swapChainSupport.capabilities);
|
VkExtent2D extent = chooseSwapExtent(swapChainSupport.capabilities);
|
||||||
|
|
||||||
|
if (swapChainSupport.capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR ||
|
||||||
|
swapChainSupport.capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
|
||||||
|
uint32_t width, height;
|
||||||
|
width = extent.width;
|
||||||
|
height = extent.height;
|
||||||
|
extent.width = height;
|
||||||
|
extent.height = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto currentTransform = swapChainSupport.capabilities.currentTransform;
|
||||||
|
constexpr float PI = 3.14159265358979323846f;
|
||||||
|
float angle = 0.0f;
|
||||||
|
if (currentTransform & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
|
||||||
|
angle = 0.0f;
|
||||||
|
} else if (currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) {
|
||||||
|
angle = -PI / 2.0f;
|
||||||
|
} else if (currentTransform & VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR) {
|
||||||
|
angle = -PI;
|
||||||
|
} else if (currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
|
||||||
|
angle = -3.0f * PI / 2.0f;
|
||||||
|
}
|
||||||
|
float data[] = {
|
||||||
|
cosf(angle), -sinf(angle), 0.0f, 0.0f,
|
||||||
|
sinf(angle), cosf(angle), 0.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f,
|
||||||
|
};
|
||||||
|
displayRotation = Matrix4(data);
|
||||||
|
|
||||||
uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1;
|
uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1;
|
||||||
if (swapChainSupport.capabilities.maxImageCount > 0 && imageCount > swapChainSupport.capabilities.maxImageCount) {
|
if (swapChainSupport.capabilities.maxImageCount > 0 && imageCount > swapChainSupport.capabilities.maxImageCount) {
|
||||||
imageCount = swapChainSupport.capabilities.maxImageCount;
|
imageCount = swapChainSupport.capabilities.maxImageCount;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace love {
|
namespace love {
|
||||||
@@ -244,7 +243,8 @@ private:
|
|||||||
VkQueue graphicsQueue = VK_NULL_HANDLE;
|
VkQueue graphicsQueue = VK_NULL_HANDLE;
|
||||||
VkQueue presentQueue = VK_NULL_HANDLE;
|
VkQueue presentQueue = VK_NULL_HANDLE;
|
||||||
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||||
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
||||||
|
Matrix4 displayRotation;
|
||||||
std::vector<VkImage> swapChainImages;
|
std::vector<VkImage> swapChainImages;
|
||||||
VkFormat swapChainImageFormat = VK_FORMAT_UNDEFINED;
|
VkFormat swapChainImageFormat = VK_FORMAT_UNDEFINED;
|
||||||
VkExtent2D swapChainExtent = VkExtent2D();
|
VkExtent2D swapChainExtent = VkExtent2D();
|
||||||
@@ -274,9 +274,9 @@ private:
|
|||||||
// functions that need to be called to cleanup objects that were needed for rendering a frame.
|
// functions that need to be called to cleanup objects that were needed for rendering a frame.
|
||||||
// just like batchedDrawBuffers we need a vector for each frame in flight.
|
// just like batchedDrawBuffers we need a vector for each frame in flight.
|
||||||
std::vector<std::vector<std::function<void()>>> cleanUpFunctions;
|
std::vector<std::vector<std::function<void()>>> cleanUpFunctions;
|
||||||
graphics::Texture* currentTexture = nullptr;
|
|
||||||
|
|
||||||
// render pass variables.
|
// render pass variables.
|
||||||
|
graphics::Texture* currentTexture = nullptr;
|
||||||
Texture* renderTargetTexture = nullptr;
|
Texture* renderTargetTexture = nullptr;
|
||||||
float currentViewportWidth = 0;
|
float currentViewportWidth = 0;
|
||||||
float currentViewportHeight = 0;
|
float currentViewportHeight = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user