Compare commits
No commits in common. "cb848e71090ca44fcf92721b9223d04d42cfb58d" and "84099f07ed768aa25c46d25cec1e81aa01fd713a" have entirely different histories.
cb848e7109
...
84099f07ed
8 changed files with 37 additions and 35 deletions
|
|
@ -3,20 +3,13 @@ module;
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "VulkanBuffer.h"
|
#include "VulkanBuffer.h"
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <iostream>
|
|
||||||
#include <format>
|
|
||||||
|
|
||||||
module Crafter.Graphics;
|
module Crafter.Graphics;
|
||||||
import Crafter.Math;
|
import Crafter.Math;
|
||||||
import Crafter.Event;
|
|
||||||
using namespace Crafter;
|
using namespace Crafter;
|
||||||
|
|
||||||
Camera::Camera(float fov, float aspectRatio, float near, float far) {
|
Camera::Camera(float fov, float aspectRatio, float near, float far) {
|
||||||
projection = MatrixRowMajor<float, 4, 4, 1>::Perspective(fov, aspectRatio, near, far);
|
projection = Matrix<float, 4, 4, 1>::Projection(fov, aspectRatio, near, far);
|
||||||
view = MatrixRowMajor<float, 4, 4, 1>::Identity();
|
view = Matrix<float, 4, 4, 1>::Idenity();
|
||||||
}
|
projectionView = camera.matrices.perspective*camera.matrices.view;
|
||||||
|
|
||||||
void Camera::Update() {
|
|
||||||
projectionView = projection*view;
|
|
||||||
onUpdate.Invoke();
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,16 +6,13 @@ export module Crafter.Graphics:Camera;
|
||||||
import :VulkanBuffer;
|
import :VulkanBuffer;
|
||||||
import Crafter.Component;
|
import Crafter.Component;
|
||||||
import Crafter.Math;
|
import Crafter.Math;
|
||||||
import Crafter.Event;
|
|
||||||
|
|
||||||
namespace Crafter {
|
namespace Crafter {
|
||||||
export class Camera : public Component {
|
export class Camera : public Component {
|
||||||
public:
|
public:
|
||||||
MatrixRowMajor<float, 4, 4, 1> projection;
|
Matrix<float, 4, 4, 1> projection;
|
||||||
MatrixRowMajor<float, 4, 4, 1> view;
|
Matrix<float, 4, 4, 1> view;
|
||||||
MatrixRowMajor<float, 4, 4, 1> projectionView;
|
Matrix<float, 4, 4, 1> projectionView;
|
||||||
Event<void> onUpdate;
|
|
||||||
Camera(float fov, float aspectRatio, float near, float far);
|
Camera(float fov, float aspectRatio, float near, float far);
|
||||||
void Update();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,24 +11,19 @@ import Crafter.Component;
|
||||||
import :Mesh;
|
import :Mesh;
|
||||||
import :Camera;
|
import :Camera;
|
||||||
import :VulkanPipeline;
|
import :VulkanPipeline;
|
||||||
import Crafter.Math;
|
|
||||||
|
|
||||||
namespace Crafter {
|
namespace Crafter {
|
||||||
export template <typename VertexType>
|
export template <typename VertexType>
|
||||||
class MeshShader : public Component {
|
class MeshShader {
|
||||||
public:
|
public:
|
||||||
MatrixRowMajor<float, 4, 4, 1> transform;
|
//glm::mat4 transform;
|
||||||
ComponentRefOwning<Mesh<VertexType>> mesh;
|
ComponentRefOwning<Mesh<VertexType>> mesh;
|
||||||
ComponentRefOwning<Camera> camera;
|
ComponentRefOwning<Camera> camera;
|
||||||
Buffer<MatrixRowMajor<float, 4, 4, 1>> mvp;
|
Buffer<float> mvp;
|
||||||
std::uint32_t threadCount;
|
std::uint32_t threadCount;
|
||||||
EventListener<void> cameraUpdate;
|
MeshShader(Mesh<VertexType>* mesh, Camera* camera) : threadCount(std::ceil(static_cast<double>(mesh->indexCount)/64/3)), mvp(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), mesh(mesh), camera(camera) {
|
||||||
MeshShader(Mesh<VertexType>* mesh, Camera* camera) : threadCount(std::ceil(static_cast<double>(mesh->indexCount)/64/3)), mvp(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), mesh(mesh), camera(camera), cameraUpdate(
|
|
||||||
&camera->onUpdate, [this](){
|
|
||||||
Update();
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
transform = MatrixRowMajor<float, 4, 4, 1>::Identity();
|
|
||||||
}
|
}
|
||||||
void WriteDescriptors(DescriptorSet& set) {
|
void WriteDescriptors(DescriptorSet& set) {
|
||||||
set.Write(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &mvp.descriptor);
|
set.Write(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &mvp.descriptor);
|
||||||
|
|
@ -36,7 +31,7 @@ namespace Crafter {
|
||||||
set.Write(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2, &mesh.component->indicies.descriptor);
|
set.Write(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2, &mesh.component->indicies.descriptor);
|
||||||
}
|
}
|
||||||
void Update() {
|
void Update() {
|
||||||
*mvp.value = camera.component->projectionView*transform;
|
//mvp.value[0] = camera.component->projectionView*transform;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,13 @@ module;
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#define GLM_FORCE_RADIANS
|
||||||
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/matrix_inverse.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
export module Crafter.Graphics:TextureShader;
|
export module Crafter.Graphics:TextureShader;
|
||||||
import Crafter.Component;
|
import Crafter.Component;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,13 @@ module;
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#define GLM_FORCE_RADIANS
|
||||||
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/matrix_inverse.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
export module Crafter.Graphics:VulkanTexture;
|
export module Crafter.Graphics:VulkanTexture;
|
||||||
import Crafter.Component;
|
import Crafter.Component;
|
||||||
|
|
|
||||||
|
|
@ -155,11 +155,9 @@ void keyboard_key(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t t
|
||||||
if(window->heldkeys[keypress]) {
|
if(window->heldkeys[keypress]) {
|
||||||
window->onKeyHold[keypress].Invoke();
|
window->onKeyHold[keypress].Invoke();
|
||||||
} else{
|
} else{
|
||||||
window->heldkeys[keypress] = true;
|
|
||||||
window->onKeyDown[keypress].Invoke();
|
window->onKeyDown[keypress].Invoke();
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
window->heldkeys[keypress] = false;
|
|
||||||
window->onKeyUp[keypress].Invoke();
|
window->onKeyUp[keypress].Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +196,7 @@ void WindowWayland::seat_handle_capabilities(void* data, wl_seat* seat, uint32_t
|
||||||
}
|
}
|
||||||
if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
|
if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
|
||||||
wl_keyboard* keyboard = wl_seat_get_keyboard(seat);
|
wl_keyboard* keyboard = wl_seat_get_keyboard(seat);
|
||||||
wl_keyboard_add_listener(keyboard, &keyboard_listener, window);
|
wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,6 @@ void WindowWaylandVulkan::Start() {
|
||||||
vkCmdSetScissor(drawCmdBuffers[currentBuffer], 0, 1, &scissor);
|
vkCmdSetScissor(drawCmdBuffers[currentBuffer], 0, 1, &scissor);
|
||||||
|
|
||||||
onDraw.Invoke(drawCmdBuffers[currentBuffer]);
|
onDraw.Invoke(drawCmdBuffers[currentBuffer]);
|
||||||
mouseDelta = {0, 0};
|
|
||||||
|
|
||||||
VulkanDevice::vkCmdEndRenderingKHRProc(drawCmdBuffers[currentBuffer]);
|
VulkanDevice::vkCmdEndRenderingKHRProc(drawCmdBuffers[currentBuffer]);
|
||||||
|
|
||||||
|
|
|
||||||
12
main.cpp
12
main.cpp
|
|
@ -2,10 +2,16 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
#define GLM_FORCE_RADIANS
|
||||||
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/matrix_inverse.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
import Crafter.Graphics;
|
import Crafter.Graphics;
|
||||||
import Crafter.Asset;
|
import Crafter.Asset;
|
||||||
import Crafter.Event;
|
import Crafter.Event;
|
||||||
import Crafter.Math;
|
|
||||||
using namespace Crafter;
|
using namespace Crafter;
|
||||||
|
|
||||||
typedef VulkanShader<"MeshShaderXYZUV.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 3, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2}}}> MeshVulkanShader;
|
typedef VulkanShader<"MeshShaderXYZUV.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 3, {{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2}}}> MeshVulkanShader;
|
||||||
|
|
@ -23,14 +29,14 @@ int main() {
|
||||||
Asset asset;
|
Asset asset;
|
||||||
asset.LoadFull("cannon.cras");
|
asset.LoadFull("cannon.cras");
|
||||||
|
|
||||||
Camera camera(1.57079633, 16 / 9, 0.01, 512);
|
Camera camera;
|
||||||
camera.Update();
|
|
||||||
Mesh<VertexUV>* mesh = Mesh<VertexUV>::FromAssetUV(asset.entries[0].data.data());
|
Mesh<VertexUV>* mesh = Mesh<VertexUV>::FromAssetUV(asset.entries[0].data.data());
|
||||||
DescriptorSet descriptors;
|
DescriptorSet descriptors;
|
||||||
Pipeline::GetDescriptorSet(descriptors);
|
Pipeline::GetDescriptorSet(descriptors);
|
||||||
|
|
||||||
MeshShader<VertexUV> meshShader(mesh, &camera);
|
MeshShader<VertexUV> meshShader(mesh, &camera);
|
||||||
meshShader.WriteDescriptors(descriptors);
|
meshShader.WriteDescriptors(descriptors);
|
||||||
|
meshShader.transform = glm::mat4(1.0f);
|
||||||
meshShader.Update();
|
meshShader.Update();
|
||||||
|
|
||||||
Asset asset2;
|
Asset asset2;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue