mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-23 04:27:45 +00:00
Properly set camera so model is visible
There's still a long way to go, but now it finally works :-)
This commit is contained in:
parent
92c52e358a
commit
eb13fbbb64
4 changed files with 31 additions and 10 deletions
|
@ -1,5 +1,13 @@
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
glm
|
||||||
|
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
||||||
|
GIT_TAG 0.9.9.8
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_MakeAvailable(glm)
|
||||||
|
|
||||||
add_library(renderer src/renderer.cpp)
|
add_library(renderer src/renderer.cpp)
|
||||||
target_include_directories(renderer PUBLIC include)
|
target_include_directories(renderer PUBLIC include)
|
||||||
target_link_libraries(renderer PUBLIC Vulkan::Vulkan fmt::fmt libxiv)
|
target_link_libraries(renderer PUBLIC Vulkan::Vulkan fmt::fmt libxiv glm::glm)
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
layout(location = 0) in vec3 inPosition;
|
layout(location = 0) in vec3 inPosition;
|
||||||
|
|
||||||
|
layout( push_constant ) uniform PushConstant {
|
||||||
|
mat4 mvp;
|
||||||
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(inPosition, 1.0);
|
gl_Position = mvp * vec4(inPosition, 1.0);
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -6,6 +6,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <valarray>
|
#include <valarray>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtx/transform.hpp>
|
||||||
|
|
||||||
Renderer::Renderer() {
|
Renderer::Renderer() {
|
||||||
VkApplicationInfo applicationInfo = {};
|
VkApplicationInfo applicationInfo = {};
|
||||||
|
@ -383,6 +385,12 @@ void Renderer::render(std::vector<RenderModel> models) {
|
||||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &model.vertexBuffer, offsets);
|
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &model.vertexBuffer, offsets);
|
||||||
vkCmdBindIndexBuffer(commandBuffer, model.indexBuffer, 0, VK_INDEX_TYPE_UINT16);
|
vkCmdBindIndexBuffer(commandBuffer, model.indexBuffer, 0, VK_INDEX_TYPE_UINT16);
|
||||||
|
|
||||||
|
glm::mat4 p = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, 100.0f);
|
||||||
|
glm::mat4 v = glm::lookAt(glm::vec3(2), glm::vec3(0), glm::vec3(0, 1, 0));
|
||||||
|
glm::mat4 mvp = p * v;
|
||||||
|
|
||||||
|
vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), &mvp);
|
||||||
|
|
||||||
vkCmdDrawIndexed(commandBuffer, model.numIndices, 1, 0, 0, 0);
|
vkCmdDrawIndexed(commandBuffer, model.numIndices, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,13 +570,12 @@ void Renderer::initPipeline() {
|
||||||
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||||
|
|
||||||
VkViewport viewport = {};
|
VkViewport viewport = {};
|
||||||
viewport.width = 640;
|
viewport.width = swapchainExtent.width;
|
||||||
viewport.height = 480;
|
viewport.height = swapchainExtent.height;
|
||||||
viewport.maxDepth = 1.0f;
|
viewport.maxDepth = 1.0f;
|
||||||
|
|
||||||
VkRect2D scissor = {};
|
VkRect2D scissor = {};
|
||||||
scissor.extent.width = 640;
|
scissor.extent = swapchainExtent;
|
||||||
scissor.extent.height = 489;
|
|
||||||
|
|
||||||
VkPipelineViewportStateCreateInfo viewportState = {};
|
VkPipelineViewportStateCreateInfo viewportState = {};
|
||||||
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||||
|
@ -595,15 +602,17 @@ void Renderer::initPipeline() {
|
||||||
colorBlending.attachmentCount = 1;
|
colorBlending.attachmentCount = 1;
|
||||||
colorBlending.pAttachments = &colorBlendAttachment;
|
colorBlending.pAttachments = &colorBlendAttachment;
|
||||||
|
|
||||||
std::array<VkDynamicState, 2> dynamicStates = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR};
|
|
||||||
|
|
||||||
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
||||||
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
||||||
dynamicState.dynamicStateCount = static_cast<uint32_t>(dynamicStates.size());
|
|
||||||
dynamicState.pDynamicStates = dynamicStates.data();
|
VkPushConstantRange pushConstantRange = {};
|
||||||
|
pushConstantRange.size = sizeof(glm::mat4);
|
||||||
|
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
|
||||||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||||
|
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||||
|
pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
|
||||||
|
|
||||||
vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &pipelineLayout);
|
vkCreatePipelineLayout(device, &pipelineLayoutInfo, nullptr, &pipelineLayout);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue