Skip to content

Commit

Permalink
fix the path loading
Browse files Browse the repository at this point in the history
  • Loading branch information
WinteryFox committed Dec 2, 2023
1 parent 39a5442 commit c4f1f3f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
29 changes: 14 additions & 15 deletions src/engine/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@ namespace Vixen {
clearColor(clearColor) {}

glm::mat4 Camera::view() const {
// const auto &reverse = glm::conjugate(rotation);
// glm::mat4 rot = glm::toMat4(reverse);
// glm::mat4 translation = glm::translate({1.0}, -position);
// glm::vec3 front;
// front.x = static_cast<float>(cos(glm::radians(rotation.x)) * cos(glm::radians(rotation.y)));
// front.y = static_cast<float>(sin(glm::radians(rotation.y)));
// front.z = static_cast<float>(sin(glm::radians(rotation.x)) * cos(glm::radians(rotation.y)));
//
// return rot * translation;
return glm::lookAt(
// front = normalize(front);
// const auto &right = normalize(cross(front, glm::vec3(0.0f, 1.0f, 0.0f)));
// const auto &up = normalize(cross(right, front));
//
// return lookAt(position, position + front, up);
return lookAt(
position,
glm::vec3(0, 0, 0),
{0.0f, 1.0f, 0.0f}
);
}

glm::mat4 Camera::perspective(const float aspectRatio) const {
// return glm::perspective(
// glm::radians(fieldOfView),
// aspectRatio,
// nearPlane,
// farPlane
// );
return glm::perspective(
glm::radians(45.0f),
1.7f,
0.1f,
10.0f
glm::radians(fieldOfView),
aspectRatio,
nearPlane,
farPlane
);
}

Expand Down
22 changes: 16 additions & 6 deletions src/engine/vk/VkDescriptorSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ namespace Vixen::Vk {
);
}

void VkDescriptorSet::updateUniformBuffer(const uint32_t binding, const VkBuffer& buffer) const {
void VkDescriptorSet::updateUniformBuffer(
const uint32_t binding,
const VkBuffer& buffer,
const uint32_t offset,
const uint32_t size
) const {
if (offset + size > buffer.getSize())
throw std::runtime_error("Offset plus size is greater than buffer size");

const VkDescriptorBufferInfo bufferInfo{
.buffer = buffer.getBuffer(),
// TODO: This can't be hardcoded in the future to deal with buffers storing
// multiple descriptors (or other things), will need a better solution
.offset = 0,
.range = buffer.getSize()
.offset = offset,
.range = size
};

const VkWriteDescriptorSet write{
Expand All @@ -68,7 +74,11 @@ namespace Vixen::Vk {
vkUpdateDescriptorSets(device->getDevice(), 1, &write, 0, nullptr);
}

void VkDescriptorSet::updateCombinedImageSampler(const uint32_t binding, const VkSampler &sampler, const VkImageView &view) const {
void VkDescriptorSet::updateCombinedImageSampler(
const uint32_t binding,
const VkSampler& sampler,
const VkImageView& view
) const {
const VkDescriptorImageInfo imageInfo{
.sampler = sampler.getSampler(),
.imageView = view.getImageView(),
Expand Down
4 changes: 3 additions & 1 deletion src/engine/vk/VkDescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ namespace Vixen::Vk {

void updateUniformBuffer(
uint32_t binding,
const VkBuffer& buffer
const VkBuffer& buffer,
uint32_t offset,
uint32_t size
) const;

void updateCombinedImageSampler(
Expand Down
2 changes: 1 addition & 1 deletion src/engine/vk/VkImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace Vixen::Vk {
VkImage VkImage::from(const std::shared_ptr<Device>& device, const std::string& path) {
FreeImage_Initialise();

const auto& format = FreeImage_GetFileType(path.c_str(), 0);
const auto& format = FreeImage_GetFileType(path.c_str(), static_cast<int>(path.length()));
if (format == FIF_UNKNOWN)
error("Failed to determine image format, possibly unsupported format?");

Expand Down
17 changes: 11 additions & 6 deletions src/engine/vk/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int main() {
}
);

auto camera = Vixen::Camera(glm::vec3{2.0f, 2.0f, 2.0f});
auto camera = Vixen::Camera(glm::vec3{1.0f, 1.0f, 1.0f});

const std::vector<VkDescriptorPoolSize> sizes{
{
Expand All @@ -134,12 +134,12 @@ int main() {
camera.perspective(static_cast<float>(width) / static_cast<float>(height))
};

auto descriptorPool = std::make_shared<Vixen::Vk::VkDescriptorPool>(vixen.device, sizes, 2);
auto descriptorPool = std::make_shared<Vixen::Vk::VkDescriptorPool>(vixen.device, sizes, 1);
auto mvp = Vixen::Vk::VkDescriptorSet(vixen.device, descriptorPool, *program.getDescriptorSetLayout());
mvp.updateUniformBuffer(0, uniformBuffer);
mvp.updateUniformBuffer(0, uniformBuffer, 0, uniformBuffer.getSize());

auto image = std::make_shared<Vixen::Vk::VkImage>(
Vixen::Vk::VkImage::from(vixen.device, "texture.jpg"));
Vixen::Vk::VkImage::from(vixen.device, "../../src/engine/vk/test/texture.jpg"));
auto view = Vixen::Vk::VkImageView(image, VK_IMAGE_ASPECT_COLOR_BIT);
auto sampler = Vixen::Vk::VkSampler(vixen.device);

Expand All @@ -161,8 +161,13 @@ int main() {
const double& now = glfwGetTime();
double deltaTime = now - lastFrame;
lastFrame = now;
ubo.model = glm::rotate(ubo.model, static_cast<float>(deltaTime) * glm::radians(90.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
ubo.model = rotate(ubo.model, static_cast<float>(deltaTime) * glm::radians(90.0f),
glm::vec3(0.0f, 0.0f, 1.0f));
ubo.view = camera.view();
ubo.projection = camera.perspective(
static_cast<float>(vixen.swapchain.getExtent().width) /
static_cast<float>(vixen.swapchain.getExtent().height)
);
uniformBuffer.write(reinterpret_cast<const char*>(&ubo), sizeof(UniformBufferObject), 0);

renderer->render(buffer, vertices.size(), indices.size(), descriptorSets);
Expand Down

0 comments on commit c4f1f3f

Please sign in to comment.