mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 13:01:19 +00:00
Attempt to fix coordinate system
This commit is contained in:
parent
604513f44d
commit
591d0ea3c2
2
dependencies/VulkanMemoryAllocator
vendored
2
dependencies/VulkanMemoryAllocator
vendored
@ -1 +1 @@
|
|||||||
Subproject commit c351692490513cdb0e5a2c925aaf7ea4a9b672f4
|
Subproject commit 0e89587db3ebee4d463f191bd296374c5fafc8ea
|
@ -107,8 +107,9 @@ class Scene {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Application* const app_;
|
Application* const app_;
|
||||||
|
public:
|
||||||
Entity next_entity_id_ = 1; // 0 is not a valid entity
|
Entity next_entity_id_ = 1; // 0 is not a valid entity
|
||||||
|
private:
|
||||||
uint64_t framecount_ = 0;
|
uint64_t framecount_ = 0;
|
||||||
|
|
||||||
/* ecs stuff */
|
/* ecs stuff */
|
||||||
|
@ -21,4 +21,5 @@ void main() {
|
|||||||
vec3 position = mat3(frameSetUniformBuffer.view) * vec3(constants.model * vec4(inPosition, 1.0));
|
vec3 position = mat3(frameSetUniformBuffer.view) * vec3(constants.model * vec4(inPosition, 1.0));
|
||||||
gl_Position = (globalSetUniformBuffer.proj * vec4(position, 0.0)).xyzz;
|
gl_Position = (globalSetUniformBuffer.proj * vec4(position, 0.0)).xyzz;
|
||||||
fragUV = inUV;
|
fragUV = inUV;
|
||||||
|
gl_Position.y *= -1.0;
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,6 @@ void main() {
|
|||||||
|
|
||||||
vec3 lightPos = vec3(2000.0, 2000.0, -2000.0);
|
vec3 lightPos = vec3(2000.0, 2000.0, -2000.0);
|
||||||
fragLightPos = vec3(frameSetUniformBuffer.view * vec4(lightPos, 1.0));
|
fragLightPos = vec3(frameSetUniformBuffer.view * vec4(lightPos, 1.0));
|
||||||
|
|
||||||
|
gl_Position.y *= -1.0;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util/files.h"
|
#include "util/files.h"
|
||||||
|
|
||||||
|
static constexpr bool flip_viewport = false;
|
||||||
|
|
||||||
inline static void checkVulkanError(VkResult errorCode, int lineNo) {
|
inline static void checkVulkanError(VkResult errorCode, int lineNo) {
|
||||||
if (errorCode != VK_SUCCESS) {
|
if (errorCode != VK_SUCCESS) {
|
||||||
const std::string message("VULKAN ERROR ON LINE " + std::to_string(lineNo));
|
const std::string message("VULKAN ERROR ON LINE " + std::to_string(lineNo));
|
||||||
@ -271,7 +273,7 @@ static VkShaderModule compileShader(VkDevice device, shaderc_shader_kind kind,
|
|||||||
VkShaderModuleCreateInfo createInfo{};
|
VkShaderModuleCreateInfo createInfo{};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||||
createInfo.codeSize = shaderBytecode.size() * sizeof(uint32_t);
|
createInfo.codeSize = shaderBytecode.size() * sizeof(uint32_t);
|
||||||
createInfo.pCode = compiledShader.cbegin();
|
createInfo.pCode = compiledShader.cbegin();
|
||||||
|
|
||||||
VkShaderModule shaderModule;
|
VkShaderModule shaderModule;
|
||||||
if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) !=
|
if (vkCreateShaderModule(device, &createInfo, nullptr, &shaderModule) !=
|
||||||
@ -398,8 +400,6 @@ GFXDevice::GFXDevice(const char* appName, const char* appVersion,
|
|||||||
DeviceRequirements deviceRequirements{};
|
DeviceRequirements deviceRequirements{};
|
||||||
deviceRequirements.requiredExtensions.push_back(
|
deviceRequirements.requiredExtensions.push_back(
|
||||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||||
deviceRequirements.requiredExtensions.push_back(
|
|
||||||
VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME);
|
|
||||||
deviceRequirements.optionalExtensions.push_back(
|
deviceRequirements.optionalExtensions.push_back(
|
||||||
VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME);
|
VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME);
|
||||||
deviceRequirements.optionalExtensions.push_back(
|
deviceRequirements.optionalExtensions.push_back(
|
||||||
@ -728,10 +728,17 @@ gfx::DrawBuffer* GFXDevice::BeginRender() {
|
|||||||
VK_SUBPASS_CONTENTS_INLINE);
|
VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
|
||||||
VkViewport viewport{};
|
VkViewport viewport{};
|
||||||
viewport.x = 0.0f;
|
if (flip_viewport) {
|
||||||
viewport.y = (float)pimpl->swapchain.extent.height;
|
viewport.x = 0.0f;
|
||||||
viewport.width = (float)pimpl->swapchain.extent.width;
|
viewport.y = (float)pimpl->swapchain.extent.height;
|
||||||
viewport.height = -(float)pimpl->swapchain.extent.height;
|
viewport.width = (float)pimpl->swapchain.extent.width;
|
||||||
|
viewport.height = -(float)pimpl->swapchain.extent.height;
|
||||||
|
} else {
|
||||||
|
viewport.x = 0.0f;
|
||||||
|
viewport.y = 0.0f;
|
||||||
|
viewport.width = (float)pimpl->swapchain.extent.width;
|
||||||
|
viewport.height = (float)pimpl->swapchain.extent.height;
|
||||||
|
}
|
||||||
viewport.minDepth = 0.0f;
|
viewport.minDepth = 0.0f;
|
||||||
viewport.maxDepth = 1.0f;
|
viewport.maxDepth = 1.0f;
|
||||||
vkCmdSetViewport(frameData.drawBuf, 0, 1, &viewport);
|
vkCmdSetViewport(frameData.drawBuf, 0, 1, &viewport);
|
||||||
@ -950,10 +957,17 @@ gfx::Pipeline* GFXDevice::CreatePipeline(const gfx::PipelineInfo& info) {
|
|||||||
inputAssembly.primitiveRestartEnable = VK_FALSE;
|
inputAssembly.primitiveRestartEnable = VK_FALSE;
|
||||||
|
|
||||||
VkViewport viewport{};
|
VkViewport viewport{};
|
||||||
viewport.x = 0.0f;
|
if (flip_viewport) {
|
||||||
viewport.y = (float)pimpl->swapchain.extent.height;
|
viewport.x = 0.0f;
|
||||||
viewport.width = (float)pimpl->swapchain.extent.width;
|
viewport.y = (float)pimpl->swapchain.extent.height;
|
||||||
viewport.height = -(float)pimpl->swapchain.extent.height;
|
viewport.width = (float)pimpl->swapchain.extent.width;
|
||||||
|
viewport.height = -(float)pimpl->swapchain.extent.height;
|
||||||
|
} else {
|
||||||
|
viewport.x = 0.0f;
|
||||||
|
viewport.y = 0.0f;
|
||||||
|
viewport.width = (float)pimpl->swapchain.extent.width;
|
||||||
|
viewport.height = (float)pimpl->swapchain.extent.height;
|
||||||
|
}
|
||||||
viewport.minDepth = 0.0f;
|
viewport.minDepth = 0.0f;
|
||||||
viewport.maxDepth = 1.0f;
|
viewport.maxDepth = 1.0f;
|
||||||
|
|
||||||
@ -1172,7 +1186,8 @@ gfx::DescriptorSet* GFXDevice::AllocateDescriptorSet(
|
|||||||
void GFXDevice::FreeDescriptorSet(const gfx::DescriptorSet* set) {
|
void GFXDevice::FreeDescriptorSet(const gfx::DescriptorSet* set) {
|
||||||
assert(set != nullptr);
|
assert(set != nullptr);
|
||||||
VKCHECK(vkFreeDescriptorSets(pimpl->device.device, pimpl->descriptorPool,
|
VKCHECK(vkFreeDescriptorSets(pimpl->device.device, pimpl->descriptorPool,
|
||||||
static_cast<uint32_t>(set->sets.size()), set->sets.data()));
|
static_cast<uint32_t>(set->sets.size()),
|
||||||
|
set->sets.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GFXDevice::UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set,
|
void GFXDevice::UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set,
|
||||||
@ -1413,7 +1428,7 @@ gfx::Image* GFXDevice::CreateImage(uint32_t w, uint32_t h,
|
|||||||
const void* imageData) {
|
const void* imageData) {
|
||||||
assert(imageData != nullptr);
|
assert(imageData != nullptr);
|
||||||
|
|
||||||
if (pimpl->FRAMECOUNT != 0) abort(); // TODO. This is annoying
|
if (pimpl->FRAMECOUNT != 0) abort(); // TODO. This is annoying
|
||||||
|
|
||||||
gfx::Image* out = new gfx::Image{};
|
gfx::Image* out = new gfx::Image{};
|
||||||
|
|
||||||
|
@ -4,6 +4,24 @@
|
|||||||
#include <glm/trigonometric.hpp>
|
#include <glm/trigonometric.hpp>
|
||||||
#include <glm/ext/matrix_clip_space.hpp>
|
#include <glm/ext/matrix_clip_space.hpp>
|
||||||
|
|
||||||
|
[[maybe_unused]] static glm::mat4 GenPerspectiveMatrix(float vertical_fov_radians,
|
||||||
|
float aspect_ratio, float znear,
|
||||||
|
float zfar) {
|
||||||
|
float g = 1.0f / tan(vertical_fov_radians * 0.5);
|
||||||
|
float k1 = zfar / (zfar - znear);
|
||||||
|
float k2 = -(zfar * znear) / (znear - zfar);
|
||||||
|
glm::mat4 m{1.0f};
|
||||||
|
|
||||||
|
m[0][0] = g / aspect_ratio;
|
||||||
|
m[1][1] = g;
|
||||||
|
m[2][2] = k1;
|
||||||
|
m[2][3] = -1.0f;
|
||||||
|
m[3][2] = k2;
|
||||||
|
m[3][3] = 0.0f;
|
||||||
|
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
Renderer::Renderer(const char* app_name, const char* app_version,
|
Renderer::Renderer(const char* app_name, const char* app_version,
|
||||||
@ -71,7 +89,7 @@ void Renderer::PreRender(bool window_is_resized, glm::mat4 camera_transform) {
|
|||||||
uint32_t w, h;
|
uint32_t w, h;
|
||||||
device_->GetViewportSize(&w, &h);
|
device_->GetViewportSize(&w, &h);
|
||||||
viewport_aspect_ratio_ = (float)w / (float)h;
|
viewport_aspect_ratio_ = (float)w / (float)h;
|
||||||
const glm::mat4 proj_matrix = glm::perspectiveZO(
|
const glm::mat4 proj_matrix = glm::perspectiveRH_ZO(
|
||||||
camera_settings_.vertical_fov_radians, viewport_aspect_ratio_,
|
camera_settings_.vertical_fov_radians, viewport_aspect_ratio_,
|
||||||
camera_settings_.clip_near, camera_settings_.clip_far);
|
camera_settings_.clip_near, camera_settings_.clip_far);
|
||||||
/* update SET 0 (rarely changing uniforms)*/
|
/* update SET 0 (rarely changing uniforms)*/
|
||||||
|
@ -144,7 +144,7 @@ namespace engine::util {
|
|||||||
aiProcess_GenSmoothNormals |
|
aiProcess_GenSmoothNormals |
|
||||||
aiProcess_GenUVCoords |
|
aiProcess_GenUVCoords |
|
||||||
aiProcess_TransformUVCoords |
|
aiProcess_TransformUVCoords |
|
||||||
aiProcess_FlipUVs | // Maybe?
|
aiProcess_FlipUVs | // Collada uses bottom-left origin
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -147,8 +147,6 @@ namespace engine {
|
|||||||
const std::vector<const char*> windowExtensions = getWindowExtensions(window);
|
const std::vector<const char*> windowExtensions = getWindowExtensions(window);
|
||||||
std::vector<const char*> instanceExtensionsToUse = windowExtensions;
|
std::vector<const char*> instanceExtensionsToUse = windowExtensions;
|
||||||
|
|
||||||
instanceExtensionsToUse.push_back(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
|
|
||||||
|
|
||||||
const char* validationLayer = nullptr;
|
const char* validationLayer = nullptr;
|
||||||
if (useValidation) {
|
if (useValidation) {
|
||||||
validationLayer = getValidationLayer();
|
validationLayer = getValidationLayer();
|
||||||
|
@ -117,14 +117,9 @@ namespace engine {
|
|||||||
|
|
||||||
/* create swapchain */
|
/* create swapchain */
|
||||||
|
|
||||||
VkSurfaceFullScreenExclusiveInfoEXT fullscreenInfo{};
|
|
||||||
fullscreenInfo.sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT;
|
|
||||||
fullscreenInfo.pNext = nullptr;
|
|
||||||
fullscreenInfo.fullScreenExclusive = VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT;
|
|
||||||
|
|
||||||
VkSwapchainCreateInfoKHR scInfo{
|
VkSwapchainCreateInfoKHR scInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
||||||
.pNext = &fullscreenInfo,
|
.pNext = nullptr,
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.surface = info.surface,
|
.surface = info.surface,
|
||||||
.minImageCount = minImageCount,
|
.minImageCount = minImageCount,
|
||||||
|
BIN
test/res/models/MY_AXES.dae
(Stored with Git LFS)
Normal file
BIN
test/res/models/MY_AXES.dae
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
test/res/models/cobble_house/_stone_bricks.png
Normal file
BIN
test/res/models/cobble_house/_stone_bricks.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.0 MiB |
BIN
test/res/models/terrain.dae
(Stored with Git LFS)
BIN
test/res/models/terrain.dae
(Stored with Git LFS)
Binary file not shown.
BIN
test/res/models/uvcheck.dae
(Stored with Git LFS)
Normal file
BIN
test/res/models/uvcheck.dae
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
test/res/textures/uvcheck.png
Normal file
BIN
test/res/textures/uvcheck.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
@ -142,16 +142,17 @@ void PlayGame(GameSettings settings) {
|
|||||||
LOG_DEBUG("Textbox custom component initialised!");
|
LOG_DEBUG("Textbox custom component initialised!");
|
||||||
};
|
};
|
||||||
|
|
||||||
textboxComponent->onUpdate = [](float ts) {
|
textboxComponent->onUpdate = [&](float ts) {
|
||||||
static float time_elapsed;
|
static float time_elapsed;
|
||||||
time_elapsed += ts;
|
time_elapsed += ts;
|
||||||
if (time_elapsed >= 1.0f) {
|
if (time_elapsed >= 1.0f) {
|
||||||
time_elapsed = 0.0f;
|
time_elapsed = 0.0f;
|
||||||
LOG_INFO("COMPONENT UPDATE");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
engine::util::LoadMeshFromFile(my_scene, app.GetResourcePath("models/MY_AXES.dae"), true);
|
||||||
|
my_scene->GetComponent<engine::TransformComponent>(engine::util::LoadMeshFromFile(my_scene, app.GetResourcePath("models/uvcheck.dae"), true))->position += glm::vec3{20.0f, 20.0f, 20.0f};
|
||||||
/* teapot */
|
/* teapot */
|
||||||
my_scene
|
my_scene
|
||||||
->GetComponent<engine::TransformComponent>(
|
->GetComponent<engine::TransformComponent>(
|
||||||
|
Loading…
Reference in New Issue
Block a user