remove Xe From engine class names
This commit is contained in:
parent
4ab67b4793
commit
f81d611f0e
33 changed files with 344 additions and 343 deletions
|
@ -5,15 +5,15 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
VkDeviceSize XeBuffer::getAlignment(VkDeviceSize instanceSize, VkDeviceSize minOffsetAlignment) {
|
||||
VkDeviceSize Buffer::getAlignment(VkDeviceSize instanceSize, VkDeviceSize minOffsetAlignment) {
|
||||
if (minOffsetAlignment > 0) {
|
||||
return (instanceSize + minOffsetAlignment - 1) & ~(minOffsetAlignment - 1);
|
||||
}
|
||||
return instanceSize;
|
||||
}
|
||||
|
||||
XeBuffer::XeBuffer(
|
||||
XeDevice &device,
|
||||
Buffer::Buffer(
|
||||
Device &device,
|
||||
VkDeviceSize instanceSize,
|
||||
uint32_t instanceCount,
|
||||
VkBufferUsageFlags usageFlags,
|
||||
|
@ -29,25 +29,25 @@ XeBuffer::XeBuffer(
|
|||
device.createBuffer(bufferSize, usageFlags, memoryPropertyFlags, buffer, memory);
|
||||
}
|
||||
|
||||
XeBuffer::~XeBuffer() {
|
||||
Buffer::~Buffer() {
|
||||
unmap();
|
||||
vkDestroyBuffer(xeDevice.device(), buffer, nullptr);
|
||||
vkFreeMemory(xeDevice.device(), memory, nullptr);
|
||||
}
|
||||
|
||||
VkResult XeBuffer::map(VkDeviceSize size, VkDeviceSize offset) {
|
||||
VkResult Buffer::map(VkDeviceSize size, VkDeviceSize offset) {
|
||||
assert(buffer && memory && "Called map on buffer before create");
|
||||
return vkMapMemory(xeDevice.device(), memory, offset, size, 0, &mapped);
|
||||
}
|
||||
|
||||
void XeBuffer::unmap() {
|
||||
void Buffer::unmap() {
|
||||
if (mapped) {
|
||||
vkUnmapMemory(xeDevice.device(), memory);
|
||||
mapped = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void XeBuffer::writeToBuffer(void *data, VkDeviceSize size, VkDeviceSize offset) {
|
||||
void Buffer::writeToBuffer(void *data, VkDeviceSize size, VkDeviceSize offset) {
|
||||
assert(mapped && "Cannot copy to unmapped buffer");
|
||||
|
||||
if (size == VK_WHOLE_SIZE) {
|
||||
|
@ -59,7 +59,7 @@ void XeBuffer::writeToBuffer(void *data, VkDeviceSize size, VkDeviceSize offset)
|
|||
}
|
||||
}
|
||||
|
||||
VkResult XeBuffer::flush(VkDeviceSize size, VkDeviceSize offset) {
|
||||
VkResult Buffer::flush(VkDeviceSize size, VkDeviceSize offset) {
|
||||
VkMappedMemoryRange mappedRange = {};
|
||||
mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||
mappedRange.memory = memory;
|
||||
|
@ -68,7 +68,7 @@ VkResult XeBuffer::flush(VkDeviceSize size, VkDeviceSize offset) {
|
|||
return vkFlushMappedMemoryRanges(xeDevice.device(), 1, &mappedRange);
|
||||
}
|
||||
|
||||
VkResult XeBuffer::invalidate(VkDeviceSize size, VkDeviceSize offset) {
|
||||
VkResult Buffer::invalidate(VkDeviceSize size, VkDeviceSize offset) {
|
||||
VkMappedMemoryRange mappedRange = {};
|
||||
mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||
mappedRange.memory = memory;
|
||||
|
@ -77,7 +77,7 @@ VkResult XeBuffer::invalidate(VkDeviceSize size, VkDeviceSize offset) {
|
|||
return vkInvalidateMappedMemoryRanges(xeDevice.device(), 1, &mappedRange);
|
||||
}
|
||||
|
||||
VkDescriptorBufferInfo XeBuffer::descriptorInfo(VkDeviceSize size, VkDeviceSize offset) {
|
||||
VkDescriptorBufferInfo Buffer::descriptorInfo(VkDeviceSize size, VkDeviceSize offset) {
|
||||
return VkDescriptorBufferInfo{
|
||||
buffer,
|
||||
offset,
|
||||
|
@ -85,17 +85,17 @@ VkDescriptorBufferInfo XeBuffer::descriptorInfo(VkDeviceSize size, VkDeviceSize
|
|||
};
|
||||
}
|
||||
|
||||
void XeBuffer::writeToIndex(void *data, int index) {
|
||||
void Buffer::writeToIndex(void *data, int index) {
|
||||
writeToBuffer(data, instanceSize, index * alignmentSize);
|
||||
}
|
||||
|
||||
VkResult XeBuffer::flushIndex(int index) { return flush(alignmentSize, index * alignmentSize); }
|
||||
VkResult Buffer::flushIndex(int index) { return flush(alignmentSize, index * alignmentSize); }
|
||||
|
||||
VkDescriptorBufferInfo XeBuffer::descriptorInfoForIndex(int index) {
|
||||
VkDescriptorBufferInfo Buffer::descriptorInfoForIndex(int index) {
|
||||
return descriptorInfo(alignmentSize, index * alignmentSize);
|
||||
}
|
||||
|
||||
VkResult XeBuffer::invalidateIndex(int index) {
|
||||
VkResult Buffer::invalidateIndex(int index) {
|
||||
return invalidate(alignmentSize, index * alignmentSize);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeBuffer {
|
||||
class Buffer {
|
||||
public:
|
||||
XeBuffer(
|
||||
XeDevice& device,
|
||||
Buffer(
|
||||
Device& device,
|
||||
VkDeviceSize instanceSize,
|
||||
uint32_t instanceCount,
|
||||
VkBufferUsageFlags usageFlags,
|
||||
VkMemoryPropertyFlags memoryPropertyFlags,
|
||||
VkDeviceSize minOffsetAlignment = 1);
|
||||
~XeBuffer();
|
||||
~Buffer();
|
||||
|
||||
XeBuffer(const XeBuffer&) = delete;
|
||||
XeBuffer& operator=(const XeBuffer&) = delete;
|
||||
Buffer(const Buffer&) = delete;
|
||||
Buffer& operator=(const Buffer&) = delete;
|
||||
|
||||
VkResult map(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
|
||||
void unmap();
|
||||
|
@ -43,7 +43,7 @@ class XeBuffer {
|
|||
private:
|
||||
static VkDeviceSize getAlignment(VkDeviceSize instanceSize, VkDeviceSize minOffsetAlignment);
|
||||
|
||||
XeDevice& xeDevice;
|
||||
Device& xeDevice;
|
||||
void* mapped = nullptr;
|
||||
VkBuffer buffer = VK_NULL_HANDLE;
|
||||
VkDeviceMemory memory = VK_NULL_HANDLE;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
void XeCamera::setOrthographicProjection(
|
||||
void Camera::setOrthographicProjection(
|
||||
float left, float right, float top, float bottom, float near, float far) {
|
||||
projectionMatrix = glm::mat4{1.0f};
|
||||
projectionMatrix[0][0] = 2.f / (right - left);
|
||||
|
@ -16,7 +16,7 @@ void XeCamera::setOrthographicProjection(
|
|||
projectionMatrix[3][2] = -near / (far - near);
|
||||
}
|
||||
|
||||
void XeCamera::setPerspectiveProjection(float fovy, float aspect, float near, float far) {
|
||||
void Camera::setPerspectiveProjection(float fovy, float aspect, float near, float far) {
|
||||
assert(glm::abs(aspect - std::numeric_limits<float>::epsilon()) > 0.0f);
|
||||
const float tanHalfFovy = tan(fovy / 2.f);
|
||||
projectionMatrix = glm::mat4{0.0f};
|
||||
|
@ -27,7 +27,7 @@ void XeCamera::setPerspectiveProjection(float fovy, float aspect, float near, fl
|
|||
projectionMatrix[3][2] = -(far * near) / (far - near);
|
||||
}
|
||||
|
||||
void XeCamera::setViewDirection(glm::vec3 position, glm::vec3 direction, glm::vec3 up) {
|
||||
void Camera::setViewDirection(glm::vec3 position, glm::vec3 direction, glm::vec3 up) {
|
||||
const glm::vec3 w{glm::normalize(direction)};
|
||||
const glm::vec3 u{glm::normalize(glm::cross(w, up))};
|
||||
const glm::vec3 v{glm::cross(w, u)};
|
||||
|
@ -47,11 +47,11 @@ void XeCamera::setViewDirection(glm::vec3 position, glm::vec3 direction, glm::ve
|
|||
viewMatrix[3][2] = -glm::dot(w, position);
|
||||
}
|
||||
|
||||
void XeCamera::setViewTarget(glm::vec3 position, glm::vec3 target, glm::vec3 up) {
|
||||
void Camera::setViewTarget(glm::vec3 position, glm::vec3 target, glm::vec3 up) {
|
||||
setViewDirection(position, target - position, up);
|
||||
}
|
||||
|
||||
void XeCamera::setViewYXZ(glm::vec3 position, glm::vec3 rotation) {
|
||||
void Camera::setViewYXZ(glm::vec3 position, glm::vec3 rotation) {
|
||||
const float c3 = glm::cos(rotation.z);
|
||||
const float s3 = glm::sin(rotation.z);
|
||||
const float c2 = glm::cos(rotation.x);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeCamera {
|
||||
class Camera {
|
||||
public:
|
||||
|
||||
void setOrthographicProjection(
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeDescriptorSetLayout::Builder &XeDescriptorSetLayout::Builder::addBinding(
|
||||
DescriptorSetLayout::Builder &DescriptorSetLayout::Builder::addBinding(
|
||||
uint32_t binding,
|
||||
VkDescriptorType descriptorType,
|
||||
VkShaderStageFlags stageFlags,
|
||||
|
@ -22,12 +22,12 @@ XeDescriptorSetLayout::Builder &XeDescriptorSetLayout::Builder::addBinding(
|
|||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<XeDescriptorSetLayout> XeDescriptorSetLayout::Builder::build() const {
|
||||
return std::make_unique<XeDescriptorSetLayout>(xeDevice, bindings);
|
||||
std::unique_ptr<DescriptorSetLayout> DescriptorSetLayout::Builder::build() const {
|
||||
return std::make_unique<DescriptorSetLayout>(xeDevice, bindings);
|
||||
}
|
||||
|
||||
XeDescriptorSetLayout::XeDescriptorSetLayout(
|
||||
XeDevice &xeDevice, std::unordered_map<uint32_t, VkDescriptorSetLayoutBinding> bindings)
|
||||
DescriptorSetLayout::DescriptorSetLayout(
|
||||
Device &xeDevice, std::unordered_map<uint32_t, VkDescriptorSetLayoutBinding> bindings)
|
||||
: xeDevice{xeDevice}, bindings{bindings} {
|
||||
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings{};
|
||||
for (auto kv : bindings) {
|
||||
|
@ -48,32 +48,32 @@ XeDescriptorSetLayout::XeDescriptorSetLayout(
|
|||
}
|
||||
}
|
||||
|
||||
XeDescriptorSetLayout::~XeDescriptorSetLayout() {
|
||||
DescriptorSetLayout::~DescriptorSetLayout() {
|
||||
vkDestroyDescriptorSetLayout(xeDevice.device(), descriptorSetLayout, nullptr);
|
||||
}
|
||||
|
||||
XeDescriptorPool::Builder &XeDescriptorPool::Builder::addPoolSize(
|
||||
DescriptorPool::Builder &DescriptorPool::Builder::addPoolSize(
|
||||
VkDescriptorType descriptorType, uint32_t count) {
|
||||
poolSizes.push_back({descriptorType, count});
|
||||
return *this;
|
||||
}
|
||||
|
||||
XeDescriptorPool::Builder &XeDescriptorPool::Builder::setPoolFlags(
|
||||
DescriptorPool::Builder &DescriptorPool::Builder::setPoolFlags(
|
||||
VkDescriptorPoolCreateFlags flags) {
|
||||
poolFlags = flags;
|
||||
return *this;
|
||||
}
|
||||
XeDescriptorPool::Builder &XeDescriptorPool::Builder::setMaxSets(uint32_t count) {
|
||||
DescriptorPool::Builder &DescriptorPool::Builder::setMaxSets(uint32_t count) {
|
||||
maxSets = count;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<XeDescriptorPool> XeDescriptorPool::Builder::build() const {
|
||||
return std::make_unique<XeDescriptorPool>(xeDevice, maxSets, poolFlags, poolSizes);
|
||||
std::unique_ptr<DescriptorPool> DescriptorPool::Builder::build() const {
|
||||
return std::make_unique<DescriptorPool>(xeDevice, maxSets, poolFlags, poolSizes);
|
||||
}
|
||||
|
||||
XeDescriptorPool::XeDescriptorPool(
|
||||
XeDevice &xeDevice,
|
||||
DescriptorPool::DescriptorPool(
|
||||
Device &xeDevice,
|
||||
uint32_t maxSets,
|
||||
VkDescriptorPoolCreateFlags poolFlags,
|
||||
const std::vector<VkDescriptorPoolSize> &poolSizes)
|
||||
|
@ -91,11 +91,11 @@ XeDescriptorPool::XeDescriptorPool(
|
|||
}
|
||||
}
|
||||
|
||||
XeDescriptorPool::~XeDescriptorPool() {
|
||||
DescriptorPool::~DescriptorPool() {
|
||||
vkDestroyDescriptorPool(xeDevice.device(), descriptorPool, nullptr);
|
||||
}
|
||||
|
||||
bool XeDescriptorPool::allocateDescriptor(
|
||||
bool DescriptorPool::allocateDescriptor(
|
||||
const VkDescriptorSetLayout descriptorSetLayout, VkDescriptorSet &descriptor) const {
|
||||
VkDescriptorSetAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
|
@ -109,7 +109,7 @@ bool XeDescriptorPool::allocateDescriptor(
|
|||
return true;
|
||||
}
|
||||
|
||||
void XeDescriptorPool::freeDescriptors(std::vector<VkDescriptorSet> &descriptors) const {
|
||||
void DescriptorPool::freeDescriptors(std::vector<VkDescriptorSet> &descriptors) const {
|
||||
vkFreeDescriptorSets(
|
||||
xeDevice.device(),
|
||||
descriptorPool,
|
||||
|
@ -117,14 +117,14 @@ void XeDescriptorPool::freeDescriptors(std::vector<VkDescriptorSet> &descriptors
|
|||
descriptors.data());
|
||||
}
|
||||
|
||||
void XeDescriptorPool::resetPool() {
|
||||
void DescriptorPool::resetPool() {
|
||||
vkResetDescriptorPool(xeDevice.device(), descriptorPool, 0);
|
||||
}
|
||||
|
||||
XeDescriptorWriter::XeDescriptorWriter(XeDescriptorSetLayout &setLayout, XeDescriptorPool &pool)
|
||||
DescriptorWriter::DescriptorWriter(DescriptorSetLayout &setLayout, DescriptorPool &pool)
|
||||
: setLayout{setLayout}, pool{pool} {}
|
||||
|
||||
XeDescriptorWriter &XeDescriptorWriter::writeBuffer(
|
||||
DescriptorWriter &DescriptorWriter::writeBuffer(
|
||||
uint32_t binding, VkDescriptorBufferInfo *bufferInfo) {
|
||||
assert(setLayout.bindings.count(binding) == 1 && "Layout does not contain specified binding");
|
||||
|
||||
|
@ -145,7 +145,7 @@ XeDescriptorWriter &XeDescriptorWriter::writeBuffer(
|
|||
return *this;
|
||||
}
|
||||
|
||||
XeDescriptorWriter &XeDescriptorWriter::writeImage(
|
||||
DescriptorWriter &DescriptorWriter::writeImage(
|
||||
uint32_t binding, VkDescriptorImageInfo *imageInfo) {
|
||||
assert(setLayout.bindings.count(binding) == 1 && "Layout does not contain specified binding");
|
||||
|
||||
|
@ -166,7 +166,7 @@ XeDescriptorWriter &XeDescriptorWriter::writeImage(
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool XeDescriptorWriter::build(VkDescriptorSet &set) {
|
||||
bool DescriptorWriter::build(VkDescriptorSet &set) {
|
||||
bool success = pool.allocateDescriptor(setLayout.getDescriptorSetLayout(), set);
|
||||
if (!success) {
|
||||
return false;
|
||||
|
@ -175,7 +175,7 @@ bool XeDescriptorWriter::build(VkDescriptorSet &set) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void XeDescriptorWriter::overwrite(VkDescriptorSet &set) {
|
||||
void DescriptorWriter::overwrite(VkDescriptorSet &set) {
|
||||
for (auto &write : writes) {
|
||||
write.dstSet = set;
|
||||
}
|
||||
|
|
|
@ -9,66 +9,66 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeDescriptorSetLayout {
|
||||
class DescriptorSetLayout {
|
||||
public:
|
||||
class Builder {
|
||||
public:
|
||||
Builder(XeDevice &xeDevice) : xeDevice{xeDevice} {}
|
||||
Builder(Device &xeDevice) : xeDevice{xeDevice} {}
|
||||
|
||||
Builder &addBinding(
|
||||
uint32_t binding,
|
||||
VkDescriptorType descriptorType,
|
||||
VkShaderStageFlags stageFlags,
|
||||
VkSampler *sampler);
|
||||
std::unique_ptr<XeDescriptorSetLayout> build() const;
|
||||
std::unique_ptr<DescriptorSetLayout> build() const;
|
||||
|
||||
private:
|
||||
XeDevice &xeDevice;
|
||||
Device &xeDevice;
|
||||
std::unordered_map<uint32_t, VkDescriptorSetLayoutBinding> bindings{};
|
||||
};
|
||||
|
||||
XeDescriptorSetLayout(
|
||||
XeDevice &xeDevice, std::unordered_map<uint32_t, VkDescriptorSetLayoutBinding> bindings);
|
||||
~XeDescriptorSetLayout();
|
||||
XeDescriptorSetLayout(const XeDescriptorSetLayout &) = delete;
|
||||
XeDescriptorSetLayout &operator=(const XeDescriptorSetLayout &) = delete;
|
||||
DescriptorSetLayout(
|
||||
Device &xeDevice, std::unordered_map<uint32_t, VkDescriptorSetLayoutBinding> bindings);
|
||||
~DescriptorSetLayout();
|
||||
DescriptorSetLayout(const DescriptorSetLayout &) = delete;
|
||||
DescriptorSetLayout &operator=(const DescriptorSetLayout &) = delete;
|
||||
|
||||
VkDescriptorSetLayout getDescriptorSetLayout() const { return descriptorSetLayout; }
|
||||
|
||||
private:
|
||||
XeDevice &xeDevice;
|
||||
Device &xeDevice;
|
||||
VkDescriptorSetLayout descriptorSetLayout;
|
||||
std::unordered_map<uint32_t, VkDescriptorSetLayoutBinding> bindings;
|
||||
|
||||
friend class XeDescriptorWriter;
|
||||
friend class DescriptorWriter;
|
||||
};
|
||||
|
||||
class XeDescriptorPool {
|
||||
class DescriptorPool {
|
||||
public:
|
||||
class Builder {
|
||||
public:
|
||||
Builder(XeDevice &xeDevice) : xeDevice{xeDevice} {}
|
||||
Builder(Device &xeDevice) : xeDevice{xeDevice} {}
|
||||
|
||||
Builder &addPoolSize(VkDescriptorType descriptorType, uint32_t count);
|
||||
Builder &setPoolFlags(VkDescriptorPoolCreateFlags flags);
|
||||
Builder &setMaxSets(uint32_t count);
|
||||
std::unique_ptr<XeDescriptorPool> build() const;
|
||||
std::unique_ptr<DescriptorPool> build() const;
|
||||
|
||||
private:
|
||||
XeDevice &xeDevice;
|
||||
Device &xeDevice;
|
||||
std::vector<VkDescriptorPoolSize> poolSizes{};
|
||||
uint32_t maxSets = 1000;
|
||||
VkDescriptorPoolCreateFlags poolFlags = 0;
|
||||
};
|
||||
|
||||
XeDescriptorPool(
|
||||
XeDevice &xeDevice,
|
||||
DescriptorPool(
|
||||
Device &xeDevice,
|
||||
uint32_t maxSets,
|
||||
VkDescriptorPoolCreateFlags poolFlags,
|
||||
const std::vector<VkDescriptorPoolSize> &poolSizes);
|
||||
~XeDescriptorPool();
|
||||
XeDescriptorPool(const XeDescriptorPool &) = delete;
|
||||
XeDescriptorPool &operator=(const XeDescriptorPool &) = delete;
|
||||
~DescriptorPool();
|
||||
DescriptorPool(const DescriptorPool &) = delete;
|
||||
DescriptorPool &operator=(const DescriptorPool &) = delete;
|
||||
|
||||
bool allocateDescriptor(
|
||||
const VkDescriptorSetLayout descriptorSetLayout, VkDescriptorSet &descriptor) const;
|
||||
|
@ -78,25 +78,25 @@ class XeDescriptorPool {
|
|||
void resetPool();
|
||||
|
||||
private:
|
||||
XeDevice &xeDevice;
|
||||
Device &xeDevice;
|
||||
VkDescriptorPool descriptorPool;
|
||||
|
||||
friend class XeDescriptorWriter;
|
||||
friend class DescriptorWriter;
|
||||
};
|
||||
|
||||
class XeDescriptorWriter {
|
||||
class DescriptorWriter {
|
||||
public:
|
||||
XeDescriptorWriter(XeDescriptorSetLayout &setLayout, XeDescriptorPool &pool);
|
||||
DescriptorWriter(DescriptorSetLayout &setLayout, DescriptorPool &pool);
|
||||
|
||||
XeDescriptorWriter &writeBuffer(uint32_t binding, VkDescriptorBufferInfo *bufferInfo);
|
||||
XeDescriptorWriter &writeImage(uint32_t binding, VkDescriptorImageInfo *imageInfo);
|
||||
DescriptorWriter &writeBuffer(uint32_t binding, VkDescriptorBufferInfo *bufferInfo);
|
||||
DescriptorWriter &writeImage(uint32_t binding, VkDescriptorImageInfo *imageInfo);
|
||||
|
||||
bool build(VkDescriptorSet &set);
|
||||
void overwrite(VkDescriptorSet &set);
|
||||
|
||||
private:
|
||||
XeDescriptorSetLayout &setLayout;
|
||||
XeDescriptorPool &pool;
|
||||
DescriptorSetLayout &setLayout;
|
||||
DescriptorPool &pool;
|
||||
std::vector<VkWriteDescriptorSet> writes;
|
||||
};
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ void DestroyDebugUtilsMessengerEXT(
|
|||
}
|
||||
|
||||
// class member functions
|
||||
XeDevice::XeDevice(XeWindow &window) : window{window} {
|
||||
Device::Device(Window &window) : window{window} {
|
||||
createInstance();
|
||||
setupDebugMessenger();
|
||||
createSurface();
|
||||
|
@ -56,7 +56,7 @@ XeDevice::XeDevice(XeWindow &window) : window{window} {
|
|||
createCommandPool();
|
||||
}
|
||||
|
||||
XeDevice::~XeDevice() {
|
||||
Device::~Device() {
|
||||
vkDestroyCommandPool(device_, commandPool, nullptr);
|
||||
vkDestroyDevice(device_, nullptr);
|
||||
|
||||
|
@ -68,7 +68,7 @@ XeDevice::~XeDevice() {
|
|||
vkDestroyInstance(instance, nullptr);
|
||||
}
|
||||
|
||||
void XeDevice::createInstance() {
|
||||
void Device::createInstance() {
|
||||
if (enableValidationLayers && !checkValidationLayerSupport()) {
|
||||
throw std::runtime_error("validation layers requested, but not available!");
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ void XeDevice::createInstance() {
|
|||
hasGflwRequiredInstanceExtensions();
|
||||
}
|
||||
|
||||
void XeDevice::pickPhysicalDevice() {
|
||||
void Device::pickPhysicalDevice() {
|
||||
uint32_t deviceCount = 0;
|
||||
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
|
||||
if (deviceCount == 0) {
|
||||
|
@ -133,7 +133,7 @@ void XeDevice::pickPhysicalDevice() {
|
|||
std::cout << "Physical device: " << properties.deviceName << std::endl;
|
||||
}
|
||||
|
||||
void XeDevice::createLogicalDevice() {
|
||||
void Device::createLogicalDevice() {
|
||||
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
|
||||
|
||||
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
|
||||
|
@ -179,7 +179,7 @@ void XeDevice::createLogicalDevice() {
|
|||
vkGetDeviceQueue(device_, indices.presentFamily, 0, &presentQueue_);
|
||||
}
|
||||
|
||||
void XeDevice::createCommandPool() {
|
||||
void Device::createCommandPool() {
|
||||
QueueFamilyIndices queueFamilyIndices = findPhysicalQueueFamilies();
|
||||
|
||||
VkCommandPoolCreateInfo poolInfo = {};
|
||||
|
@ -193,9 +193,9 @@ void XeDevice::createCommandPool() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeDevice::createSurface() { window.createWindowSurface(instance, &surface_); }
|
||||
void Device::createSurface() { window.createWindowSurface(instance, &surface_); }
|
||||
|
||||
bool XeDevice::isDeviceSuitable(VkPhysicalDevice device) {
|
||||
bool Device::isDeviceSuitable(VkPhysicalDevice device) {
|
||||
QueueFamilyIndices indices = findQueueFamilies(device);
|
||||
|
||||
bool extensionsSupported = checkDeviceExtensionSupport(device);
|
||||
|
@ -213,7 +213,7 @@ bool XeDevice::isDeviceSuitable(VkPhysicalDevice device) {
|
|||
supportedFeatures.samplerAnisotropy;
|
||||
}
|
||||
|
||||
void XeDevice::populateDebugMessengerCreateInfo(
|
||||
void Device::populateDebugMessengerCreateInfo(
|
||||
VkDebugUtilsMessengerCreateInfoEXT &createInfo) {
|
||||
createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||
|
@ -226,7 +226,7 @@ void XeDevice::populateDebugMessengerCreateInfo(
|
|||
createInfo.pUserData = nullptr; // Optional
|
||||
}
|
||||
|
||||
void XeDevice::setupDebugMessenger() {
|
||||
void Device::setupDebugMessenger() {
|
||||
if (!enableValidationLayers) return;
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo;
|
||||
populateDebugMessengerCreateInfo(createInfo);
|
||||
|
@ -235,7 +235,7 @@ void XeDevice::setupDebugMessenger() {
|
|||
}
|
||||
}
|
||||
|
||||
bool XeDevice::checkValidationLayerSupport() {
|
||||
bool Device::checkValidationLayerSupport() {
|
||||
uint32_t layerCount;
|
||||
vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
|
||||
|
||||
|
@ -260,7 +260,7 @@ bool XeDevice::checkValidationLayerSupport() {
|
|||
return true;
|
||||
}
|
||||
|
||||
std::vector<const char *> XeDevice::getRequiredExtensions() {
|
||||
std::vector<const char *> Device::getRequiredExtensions() {
|
||||
uint32_t glfwExtensionCount = 0;
|
||||
const char **glfwExtensions;
|
||||
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
||||
|
@ -274,7 +274,7 @@ std::vector<const char *> XeDevice::getRequiredExtensions() {
|
|||
return extensions;
|
||||
}
|
||||
|
||||
void XeDevice::hasGflwRequiredInstanceExtensions() {
|
||||
void Device::hasGflwRequiredInstanceExtensions() {
|
||||
uint32_t extensionCount = 0;
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
|
||||
std::vector<VkExtensionProperties> extensions(extensionCount);
|
||||
|
@ -297,7 +297,7 @@ void XeDevice::hasGflwRequiredInstanceExtensions() {
|
|||
}
|
||||
}
|
||||
|
||||
bool XeDevice::checkDeviceExtensionSupport(VkPhysicalDevice device) {
|
||||
bool Device::checkDeviceExtensionSupport(VkPhysicalDevice device) {
|
||||
uint32_t extensionCount;
|
||||
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);
|
||||
|
||||
|
@ -317,7 +317,7 @@ bool XeDevice::checkDeviceExtensionSupport(VkPhysicalDevice device) {
|
|||
return requiredExtensions.empty();
|
||||
}
|
||||
|
||||
QueueFamilyIndices XeDevice::findQueueFamilies(VkPhysicalDevice device) {
|
||||
QueueFamilyIndices Device::findQueueFamilies(VkPhysicalDevice device) {
|
||||
QueueFamilyIndices indices;
|
||||
|
||||
uint32_t queueFamilyCount = 0;
|
||||
|
@ -348,7 +348,7 @@ QueueFamilyIndices XeDevice::findQueueFamilies(VkPhysicalDevice device) {
|
|||
return indices;
|
||||
}
|
||||
|
||||
SwapChainSupportDetails XeDevice::querySwapChainSupport(VkPhysicalDevice device) {
|
||||
SwapChainSupportDetails Device::querySwapChainSupport(VkPhysicalDevice device) {
|
||||
SwapChainSupportDetails details;
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface_, &details.capabilities);
|
||||
|
||||
|
@ -374,7 +374,7 @@ SwapChainSupportDetails XeDevice::querySwapChainSupport(VkPhysicalDevice device)
|
|||
return details;
|
||||
}
|
||||
|
||||
VkFormat XeDevice::findSupportedFormat(
|
||||
VkFormat Device::findSupportedFormat(
|
||||
const std::vector<VkFormat> &candidates, VkImageTiling tiling, VkFormatFeatureFlags features) {
|
||||
for (VkFormat format : candidates) {
|
||||
VkFormatProperties props;
|
||||
|
@ -390,7 +390,7 @@ VkFormat XeDevice::findSupportedFormat(
|
|||
throw std::runtime_error("failed to find supported format!");
|
||||
}
|
||||
|
||||
uint32_t XeDevice::findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) {
|
||||
uint32_t Device::findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties) {
|
||||
VkPhysicalDeviceMemoryProperties memProperties;
|
||||
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &memProperties);
|
||||
for (uint32_t i = 0; i < memProperties.memoryTypeCount; i++) {
|
||||
|
@ -403,7 +403,7 @@ uint32_t XeDevice::findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags pro
|
|||
throw std::runtime_error("failed to find suitable memory type!");
|
||||
}
|
||||
|
||||
void XeDevice::createBuffer(
|
||||
void Device::createBuffer(
|
||||
VkDeviceSize size,
|
||||
VkBufferUsageFlags usage,
|
||||
VkMemoryPropertyFlags properties,
|
||||
|
@ -434,7 +434,7 @@ void XeDevice::createBuffer(
|
|||
vkBindBufferMemory(device_, buffer, bufferMemory, 0);
|
||||
}
|
||||
|
||||
VkCommandBuffer XeDevice::beginSingleTimeCommands() {
|
||||
VkCommandBuffer Device::beginSingleTimeCommands() {
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
|
@ -452,7 +452,7 @@ VkCommandBuffer XeDevice::beginSingleTimeCommands() {
|
|||
return commandBuffer;
|
||||
}
|
||||
|
||||
void XeDevice::endSingleTimeCommands(VkCommandBuffer commandBuffer) {
|
||||
void Device::endSingleTimeCommands(VkCommandBuffer commandBuffer) {
|
||||
vkEndCommandBuffer(commandBuffer);
|
||||
|
||||
VkSubmitInfo submitInfo{};
|
||||
|
@ -466,7 +466,7 @@ void XeDevice::endSingleTimeCommands(VkCommandBuffer commandBuffer) {
|
|||
vkFreeCommandBuffers(device_, commandPool, 1, &commandBuffer);
|
||||
}
|
||||
|
||||
void XeDevice::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) {
|
||||
void Device::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) {
|
||||
VkCommandBuffer commandBuffer = beginSingleTimeCommands();
|
||||
|
||||
VkBufferCopy copyRegion{};
|
||||
|
@ -478,7 +478,7 @@ void XeDevice::copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize s
|
|||
endSingleTimeCommands(commandBuffer);
|
||||
}
|
||||
|
||||
void XeDevice::copyBufferToImage(
|
||||
void Device::copyBufferToImage(
|
||||
VkBuffer buffer, VkImage image, uint32_t width, uint32_t height, uint32_t layerCount) {
|
||||
VkCommandBuffer commandBuffer = beginSingleTimeCommands();
|
||||
|
||||
|
@ -505,7 +505,7 @@ void XeDevice::copyBufferToImage(
|
|||
endSingleTimeCommands(commandBuffer);
|
||||
}
|
||||
|
||||
void XeDevice::createImageWithInfo(
|
||||
void Device::createImageWithInfo(
|
||||
const VkImageCreateInfo &imageInfo,
|
||||
VkMemoryPropertyFlags properties,
|
||||
VkImage &image,
|
||||
|
|
|
@ -21,7 +21,7 @@ struct QueueFamilyIndices {
|
|||
bool isComplete() { return graphicsFamilyHasValue && presentFamilyHasValue; }
|
||||
};
|
||||
|
||||
class XeDevice {
|
||||
class Device {
|
||||
public:
|
||||
#ifdef NDEBUG
|
||||
const bool enableValidationLayers = false;
|
||||
|
@ -29,13 +29,13 @@ class XeDevice {
|
|||
const bool enableValidationLayers = true;
|
||||
#endif
|
||||
|
||||
XeDevice(XeWindow &window);
|
||||
~XeDevice();
|
||||
Device(Window &window);
|
||||
~Device();
|
||||
|
||||
XeDevice(const XeDevice &) = delete;
|
||||
void operator=(const XeDevice &) = delete;
|
||||
XeDevice(XeDevice &&) = delete;
|
||||
XeDevice &operator=(XeDevice &&) = delete;
|
||||
Device(const Device &) = delete;
|
||||
void operator=(const Device &) = delete;
|
||||
Device(Device &&) = delete;
|
||||
Device &operator=(Device &&) = delete;
|
||||
|
||||
VkCommandPool getCommandPool() { return commandPool; }
|
||||
VkDevice device() { return device_; }
|
||||
|
@ -90,7 +90,7 @@ class XeDevice {
|
|||
VkInstance instance;
|
||||
VkDebugUtilsMessengerEXT debugMessenger;
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
XeWindow &window;
|
||||
Window &window;
|
||||
VkCommandPool commandPool;
|
||||
|
||||
VkDevice device_;
|
||||
|
|
|
@ -8,46 +8,47 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeEngine::XeEngine(int width, int height, std::string name) : xeWindow{width, height, name},
|
||||
Engine::Engine(int width, int height, std::string name) : xeWindow{width, height, name},
|
||||
xeDevice{xeWindow},
|
||||
xeRenderer{xeWindow, xeDevice},
|
||||
xeCamera{} {
|
||||
loadDescriptorPool();
|
||||
alutInit(0, NULL);
|
||||
|
||||
std::cout << "Audio device: " << alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER) << "\n";
|
||||
};
|
||||
|
||||
XeEngine::~XeEngine() {
|
||||
Engine::~Engine() {
|
||||
alutExit();
|
||||
};
|
||||
|
||||
void XeEngine::loadDescriptorPool() {
|
||||
xeDescriptorPool = XeDescriptorPool::Builder(xeDevice)
|
||||
.setMaxSets(XeSwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, XeSwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
.addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, XeSwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, XeSwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
void Engine::loadDescriptorPool() {
|
||||
xeDescriptorPool = DescriptorPool::Builder(xeDevice)
|
||||
.setMaxSets(SwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
.addPoolSize(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, SwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, SwapChain::MAX_FRAMES_IN_FLIGHT)
|
||||
.build();
|
||||
}
|
||||
|
||||
std::shared_ptr<XeModel> XeEngine::loadModelFromFile(const std::string &filename) {
|
||||
return XeModel::createModelFromFile(xeDevice, filename);
|
||||
std::shared_ptr<Model> Engine::loadModelFromFile(const std::string &filename) {
|
||||
return Model::createModelFromFile(xeDevice, filename);
|
||||
}
|
||||
|
||||
std::shared_ptr<XeModel> XeEngine::loadModelFromData(std::vector<XeModel::Vertex> vertices, std::vector<uint32_t> indices) {
|
||||
XeModel::Builder builder{};
|
||||
std::shared_ptr<Model> Engine::loadModelFromData(std::vector<Model::Vertex> vertices, std::vector<uint32_t> indices) {
|
||||
Model::Builder builder{};
|
||||
builder.vertices = vertices;
|
||||
if(indices.size() > 0) {
|
||||
builder.indices = indices;
|
||||
}
|
||||
return std::make_shared<XeModel>(xeDevice, builder);
|
||||
return std::make_shared<Model>(xeDevice, builder);
|
||||
}
|
||||
|
||||
std::shared_ptr<XeImage> XeEngine::loadImage(const std::string &filename) {
|
||||
return std::make_shared<XeImage>(xeDevice, filename);
|
||||
std::shared_ptr<Image> Engine::loadImage(const std::string &filename) {
|
||||
return std::make_shared<Image>(xeDevice, filename);
|
||||
}
|
||||
|
||||
bool XeEngine::poll() {
|
||||
bool Engine::poll() {
|
||||
glfwPollEvents();
|
||||
auto newTime = std::chrono::high_resolution_clock::now();
|
||||
frameTime = std::chrono::duration<float, std::chrono::seconds::period>(newTime - currentTime).count();
|
||||
|
|
|
@ -11,23 +11,23 @@
|
|||
#include <string>
|
||||
namespace xe {
|
||||
|
||||
class XeEngine {
|
||||
class Engine {
|
||||
|
||||
public:
|
||||
|
||||
XeEngine(int width, int height, std::string name);
|
||||
Engine(int width, int height, std::string name);
|
||||
|
||||
~XeEngine();
|
||||
~Engine();
|
||||
|
||||
XeEngine(const XeEngine&) = delete;
|
||||
XeEngine operator=(const XeEngine&) = delete;
|
||||
Engine(const Engine&) = delete;
|
||||
Engine operator=(const Engine&) = delete;
|
||||
|
||||
XeWindow& getWindow() {return xeWindow;}
|
||||
XeCamera& getCamera() {return xeCamera;}
|
||||
Window& getWindow() {return xeWindow;}
|
||||
Camera& getCamera() {return xeCamera;}
|
||||
|
||||
std::shared_ptr<XeModel> loadModelFromFile(const std::string &filename);
|
||||
std::shared_ptr<XeModel> loadModelFromData(std::vector<XeModel::Vertex> vertices, std::vector<uint32_t> indices);
|
||||
std::shared_ptr<XeImage> loadImage(const std::string &filename);
|
||||
std::shared_ptr<Model> loadModelFromFile(const std::string &filename);
|
||||
std::shared_ptr<Model> loadModelFromData(std::vector<Model::Vertex> vertices, std::vector<uint32_t> indices);
|
||||
std::shared_ptr<Image> loadImage(const std::string &filename);
|
||||
|
||||
bool beginFrame() { return xeRenderer.beginFrame(); }
|
||||
void endFrame() { xeRenderer.endFrame(); }
|
||||
|
@ -40,19 +40,19 @@ class XeEngine {
|
|||
|
||||
void loadDescriptorPool();
|
||||
|
||||
XeWindow xeWindow;
|
||||
XeDevice xeDevice;
|
||||
XeRenderer xeRenderer;
|
||||
XeCamera xeCamera;
|
||||
Window xeWindow;
|
||||
Device xeDevice;
|
||||
Renderer xeRenderer;
|
||||
Camera xeCamera;
|
||||
|
||||
std::chrono::_V2::system_clock::time_point currentTime;
|
||||
float frameTime;
|
||||
|
||||
float FOV = 50.f;
|
||||
|
||||
std::unique_ptr<XeDescriptorPool> xeDescriptorPool;
|
||||
std::unique_ptr<DescriptorPool> xeDescriptorPool;
|
||||
|
||||
friend class XeRenderSystem;
|
||||
friend class RenderSystem;
|
||||
};
|
||||
|
||||
}
|
|
@ -21,28 +21,28 @@ struct TransformComponent {
|
|||
|
||||
};
|
||||
|
||||
class XeGameObject {
|
||||
class GameObject {
|
||||
public:
|
||||
using id_t = unsigned int;
|
||||
|
||||
static XeGameObject createGameObject() {
|
||||
static GameObject createGameObject() {
|
||||
static id_t currentId = 0;
|
||||
return XeGameObject(currentId++);
|
||||
return GameObject(currentId++);
|
||||
}
|
||||
|
||||
XeGameObject(const XeGameObject &) = delete;
|
||||
XeGameObject &operator=(const XeGameObject &) = delete;
|
||||
XeGameObject(XeGameObject&&) = default;
|
||||
XeGameObject &operator=(XeGameObject &&) = default;
|
||||
GameObject(const GameObject &) = delete;
|
||||
GameObject &operator=(const GameObject &) = delete;
|
||||
GameObject(GameObject&&) = default;
|
||||
GameObject &operator=(GameObject &&) = default;
|
||||
|
||||
id_t getId() { return id; }
|
||||
|
||||
std::shared_ptr<XeModel> model{};
|
||||
std::shared_ptr<Model> model{};
|
||||
glm::vec3 color{};
|
||||
TransformComponent transform;
|
||||
|
||||
private:
|
||||
XeGameObject(id_t objId) : id{objId} {}
|
||||
GameObject(id_t objId) : id{objId} {}
|
||||
|
||||
id_t id;
|
||||
};
|
||||
|
|
|
@ -10,18 +10,18 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeImage::XeImage(XeDevice &xeDevice, const std::string &filename) : xeDevice{xeDevice} {
|
||||
Image::Image(Device &xeDevice, const std::string &filename) : xeDevice{xeDevice} {
|
||||
createTextureImage(filename);
|
||||
createTextureImageView();
|
||||
}
|
||||
|
||||
XeImage::~XeImage() {
|
||||
Image::~Image() {
|
||||
vkDestroyImage(xeDevice.device(), textureImage, nullptr);
|
||||
vkFreeMemory(xeDevice.device(), textureImageMemory, nullptr);
|
||||
vkDestroyImageView(xeDevice.device(), textureImageView, nullptr);
|
||||
}
|
||||
|
||||
void XeImage::createTextureImage(const std::string &filename) {
|
||||
void Image::createTextureImage(const std::string &filename) {
|
||||
int texWidth, texHeight, texChannels;
|
||||
stbi_uc* pixels = stbi_load(filename.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
|
||||
VkDeviceSize imageSize = texWidth * texHeight * 4;
|
||||
|
@ -59,7 +59,7 @@ void XeImage::createTextureImage(const std::string &filename) {
|
|||
|
||||
}
|
||||
|
||||
void XeImage::createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
|
||||
void Image::createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
|
||||
|
||||
VkImageCreateInfo imageInfo{};
|
||||
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
|
@ -95,7 +95,7 @@ void XeImage::createImage(uint32_t width, uint32_t height, VkFormat format, VkIm
|
|||
vkBindImageMemory(xeDevice.device(), image, imageMemory, 0);
|
||||
}
|
||||
|
||||
void XeImage::transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout) {
|
||||
void Image::transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout) {
|
||||
VkCommandBuffer commandBuffer = xeDevice.beginSingleTimeCommands();
|
||||
|
||||
VkImageMemoryBarrier barrier{};
|
||||
|
@ -142,7 +142,7 @@ void XeImage::transitionImageLayout(VkImage image, VkFormat format, VkImageLayou
|
|||
xeDevice.endSingleTimeCommands(commandBuffer);
|
||||
}
|
||||
|
||||
void XeImage::copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height) {
|
||||
void Image::copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height) {
|
||||
VkCommandBuffer commandBuffer = xeDevice.beginSingleTimeCommands();
|
||||
|
||||
VkBufferImageCopy region{};
|
||||
|
@ -165,7 +165,7 @@ void XeImage::copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width,
|
|||
xeDevice.endSingleTimeCommands(commandBuffer);
|
||||
}
|
||||
|
||||
void XeImage::createTextureImageView() {
|
||||
void Image::createTextureImageView() {
|
||||
VkImageViewCreateInfo viewInfo{};
|
||||
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
viewInfo.image = textureImage;
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeImage {
|
||||
class Image {
|
||||
|
||||
public:
|
||||
|
||||
XeImage(XeDevice &xeDevice, const std::string &filename);
|
||||
~XeImage();
|
||||
Image(Device &xeDevice, const std::string &filename);
|
||||
~Image();
|
||||
|
||||
XeImage(const XeImage&) = delete;
|
||||
XeImage operator=(const XeImage&) = delete;
|
||||
Image(const Image&) = delete;
|
||||
Image operator=(const Image&) = delete;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -24,13 +24,13 @@ class XeImage {
|
|||
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height);
|
||||
void createTextureImageView();
|
||||
|
||||
XeDevice &xeDevice;
|
||||
Device &xeDevice;
|
||||
|
||||
VkImage textureImage;
|
||||
VkImageView textureImageView;
|
||||
VkDeviceMemory textureImageMemory;
|
||||
|
||||
friend class XeRenderSystem;
|
||||
friend class RenderSystem;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<xe::XeModel::Vertex> {
|
||||
size_t operator()(xe::XeModel::Vertex const &vertex) const {
|
||||
struct hash<xe::Model::Vertex> {
|
||||
size_t operator()(xe::Model::Vertex const &vertex) const {
|
||||
size_t seed = 0;
|
||||
xe::hashCombine(seed, vertex.position, vertex.normal, vertex.uv);
|
||||
return seed;
|
||||
|
@ -24,26 +24,26 @@ struct hash<xe::XeModel::Vertex> {
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeModel::XeModel(XeDevice &device, const XeModel::Builder &builder) : xeDevice{device} {
|
||||
Model::Model(Device &device, const Model::Builder &builder) : xeDevice{device} {
|
||||
createVertexBuffers(builder.vertices);
|
||||
createIndexBuffers(builder.indices);
|
||||
}
|
||||
|
||||
XeModel::~XeModel() {}
|
||||
Model::~Model() {}
|
||||
|
||||
std::unique_ptr<XeModel> XeModel::createModelFromFile(XeDevice &device, const std::string &filepath) {
|
||||
std::unique_ptr<Model> Model::createModelFromFile(Device &device, const std::string &filepath) {
|
||||
Builder builder{};
|
||||
builder.loadModel(filepath);
|
||||
return std::make_unique<XeModel>(device, builder);
|
||||
return std::make_unique<Model>(device, builder);
|
||||
}
|
||||
|
||||
void XeModel::createVertexBuffers(const std::vector<Vertex> &vertices) {
|
||||
void Model::createVertexBuffers(const std::vector<Vertex> &vertices) {
|
||||
vertexCount = static_cast<uint32_t>(vertices.size());
|
||||
assert(vertexCount >= 3 && "Vertex count must be atleast 3");
|
||||
VkDeviceSize bufferSize = sizeof(vertices[0]) * vertexCount;
|
||||
uint32_t vertexSize = sizeof(vertices[0]);
|
||||
|
||||
XeBuffer stagingBuffer {
|
||||
Buffer stagingBuffer {
|
||||
xeDevice,
|
||||
vertexSize,
|
||||
vertexCount,
|
||||
|
@ -54,7 +54,7 @@ void XeModel::createVertexBuffers(const std::vector<Vertex> &vertices) {
|
|||
stagingBuffer.map();
|
||||
stagingBuffer.writeToBuffer((void *)vertices.data());
|
||||
|
||||
vertexBuffer = std::make_unique<XeBuffer>(
|
||||
vertexBuffer = std::make_unique<Buffer>(
|
||||
xeDevice,
|
||||
vertexSize,
|
||||
vertexCount,
|
||||
|
@ -65,7 +65,7 @@ void XeModel::createVertexBuffers(const std::vector<Vertex> &vertices) {
|
|||
xeDevice.copyBuffer(stagingBuffer.getBuffer(), vertexBuffer->getBuffer(), bufferSize);
|
||||
}
|
||||
|
||||
void XeModel::createIndexBuffers(const std::vector<uint32_t> &indices) {
|
||||
void Model::createIndexBuffers(const std::vector<uint32_t> &indices) {
|
||||
indexCount = static_cast<uint32_t>(indices.size());
|
||||
hasIndexBuffer = indexCount > 0;
|
||||
|
||||
|
@ -76,7 +76,7 @@ void XeModel::createIndexBuffers(const std::vector<uint32_t> &indices) {
|
|||
VkDeviceSize bufferSize = sizeof(indices[0]) * indexCount;
|
||||
uint32_t indexSize = sizeof(indices[0]);
|
||||
|
||||
XeBuffer stagingBuffer {
|
||||
Buffer stagingBuffer {
|
||||
xeDevice,
|
||||
indexSize,
|
||||
indexCount,
|
||||
|
@ -87,7 +87,7 @@ void XeModel::createIndexBuffers(const std::vector<uint32_t> &indices) {
|
|||
stagingBuffer.map();
|
||||
stagingBuffer.writeToBuffer((void *)indices.data());
|
||||
|
||||
indexBuffer = std::make_unique<XeBuffer>(
|
||||
indexBuffer = std::make_unique<Buffer>(
|
||||
xeDevice,
|
||||
indexSize,
|
||||
indexCount,
|
||||
|
@ -98,7 +98,7 @@ void XeModel::createIndexBuffers(const std::vector<uint32_t> &indices) {
|
|||
xeDevice.copyBuffer(stagingBuffer.getBuffer(), indexBuffer->getBuffer(), bufferSize);
|
||||
}
|
||||
|
||||
void XeModel::bind(VkCommandBuffer commandBuffer) {
|
||||
void Model::bind(VkCommandBuffer commandBuffer) {
|
||||
VkBuffer buffers[] = {vertexBuffer->getBuffer()};
|
||||
VkDeviceSize offsets[] = {0};
|
||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, buffers, offsets);
|
||||
|
@ -108,7 +108,7 @@ void XeModel::bind(VkCommandBuffer commandBuffer) {
|
|||
}
|
||||
}
|
||||
|
||||
void XeModel::draw(VkCommandBuffer commandBuffer) {
|
||||
void Model::draw(VkCommandBuffer commandBuffer) {
|
||||
if (hasIndexBuffer) {
|
||||
vkCmdDrawIndexed(commandBuffer, indexCount, 1, 0, 0, 0);
|
||||
} else {
|
||||
|
@ -116,7 +116,7 @@ void XeModel::draw(VkCommandBuffer commandBuffer) {
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<VkVertexInputBindingDescription> XeModel::Vertex::getBindingDescriptions() {
|
||||
std::vector<VkVertexInputBindingDescription> Model::Vertex::getBindingDescriptions() {
|
||||
std::vector<VkVertexInputBindingDescription> bindingDescriptions(1);
|
||||
bindingDescriptions[0].binding = 0;
|
||||
bindingDescriptions[0].stride = sizeof(Vertex);
|
||||
|
@ -124,7 +124,7 @@ std::vector<VkVertexInputBindingDescription> XeModel::Vertex::getBindingDescript
|
|||
return bindingDescriptions;
|
||||
}
|
||||
|
||||
std::vector<VkVertexInputAttributeDescription> XeModel::Vertex::getAttributeDescriptions() {
|
||||
std::vector<VkVertexInputAttributeDescription> Model::Vertex::getAttributeDescriptions() {
|
||||
std::vector<VkVertexInputAttributeDescription> attributeDescptions{};
|
||||
|
||||
attributeDescptions.push_back({0, 0, VK_FORMAT_R32G32B32_SFLOAT, offsetof(Vertex, position)});
|
||||
|
@ -135,7 +135,7 @@ std::vector<VkVertexInputAttributeDescription> XeModel::Vertex::getAttributeDesc
|
|||
return attributeDescptions;
|
||||
}
|
||||
|
||||
void XeModel::Builder::loadModel(const std::string &filepath) {
|
||||
void Model::Builder::loadModel(const std::string &filepath) {
|
||||
tinyobj::attrib_t attrib;
|
||||
std::vector<tinyobj::shape_t> shapes;
|
||||
std::vector<tinyobj::material_t> materials;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeModel {
|
||||
class Model {
|
||||
public:
|
||||
|
||||
struct Vertex {
|
||||
|
@ -35,13 +35,13 @@ class XeModel {
|
|||
void loadModel(const std::string &filepath);
|
||||
};
|
||||
|
||||
XeModel(XeDevice &device, const XeModel::Builder &builder);
|
||||
~XeModel();
|
||||
Model(Device &device, const Model::Builder &builder);
|
||||
~Model();
|
||||
|
||||
XeModel(const XeModel &) = delete;
|
||||
XeModel operator=(const XeModel &) = delete;
|
||||
Model(const Model &) = delete;
|
||||
Model operator=(const Model &) = delete;
|
||||
|
||||
static std::unique_ptr<XeModel> createModelFromFile(XeDevice &device, const std::string &filepath);
|
||||
static std::unique_ptr<Model> createModelFromFile(Device &device, const std::string &filepath);
|
||||
|
||||
void bind(VkCommandBuffer commandBuffer);
|
||||
void draw(VkCommandBuffer commandBuffer);
|
||||
|
@ -50,13 +50,13 @@ class XeModel {
|
|||
void createVertexBuffers(const std::vector<Vertex> &vertices);
|
||||
void createIndexBuffers(const std::vector<uint32_t> &indices);
|
||||
|
||||
XeDevice &xeDevice;
|
||||
Device &xeDevice;
|
||||
|
||||
std::unique_ptr<XeBuffer> vertexBuffer;
|
||||
std::unique_ptr<Buffer> vertexBuffer;
|
||||
uint32_t vertexCount;
|
||||
|
||||
bool hasIndexBuffer = false;
|
||||
std::unique_ptr<XeBuffer> indexBuffer;
|
||||
std::unique_ptr<Buffer> indexBuffer;
|
||||
uint32_t indexCount;
|
||||
};
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XePipeline::XePipeline(
|
||||
XeDevice &device,
|
||||
Pipeline::Pipeline(
|
||||
Device &device,
|
||||
const std::string& vertFilepath,
|
||||
const std::string& fragFilepath,
|
||||
const PipelineConfigInfo& configInfo)
|
||||
|
@ -21,13 +21,13 @@ namespace xe {
|
|||
createGraphicsPipeline(vertFilepath, fragFilepath, configInfo);
|
||||
}
|
||||
|
||||
XePipeline::~XePipeline() {
|
||||
Pipeline::~Pipeline() {
|
||||
vkDestroyShaderModule(xeDevice.device(), vertShaderModule, nullptr);
|
||||
vkDestroyShaderModule(xeDevice.device(), fragShaderModule, nullptr);
|
||||
vkDestroyPipeline(xeDevice.device(), graphicsPipeline, nullptr);
|
||||
}
|
||||
|
||||
std::vector<char> XePipeline::readFile(const std::string& filepath) {
|
||||
std::vector<char> Pipeline::readFile(const std::string& filepath) {
|
||||
|
||||
std::ifstream file{filepath, std::ios::ate | std::ios::binary};
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace xe {
|
|||
return buffer;
|
||||
};
|
||||
|
||||
void XePipeline::createGraphicsPipeline(
|
||||
void Pipeline::createGraphicsPipeline(
|
||||
const std::string& vertFilePath,
|
||||
const std::string& fragFilepath,
|
||||
const PipelineConfigInfo& configInfo) {
|
||||
|
@ -78,8 +78,8 @@ namespace xe {
|
|||
shaderStages[1].pNext = nullptr;
|
||||
shaderStages[1].pSpecializationInfo = nullptr;
|
||||
|
||||
auto bindingDescriptions = XeModel::Vertex::getBindingDescriptions();
|
||||
auto attributeDescptions = XeModel::Vertex::getAttributeDescriptions();
|
||||
auto bindingDescriptions = Model::Vertex::getBindingDescriptions();
|
||||
auto attributeDescptions = Model::Vertex::getAttributeDescriptions();
|
||||
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
|
||||
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescptions.size());
|
||||
|
@ -112,7 +112,7 @@ namespace xe {
|
|||
}
|
||||
}
|
||||
|
||||
void XePipeline::createShaderModule(const std::vector<char>& code, VkShaderModule* shaderModule) {
|
||||
void Pipeline::createShaderModule(const std::vector<char>& code, VkShaderModule* shaderModule) {
|
||||
VkShaderModuleCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
createInfo.codeSize = code.size();
|
||||
|
@ -124,11 +124,11 @@ namespace xe {
|
|||
|
||||
}
|
||||
|
||||
void XePipeline::bind(VkCommandBuffer commandBuffer) {
|
||||
void Pipeline::bind(VkCommandBuffer commandBuffer) {
|
||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
|
||||
}
|
||||
|
||||
void XePipeline::defaultPipelineConfigInfo(PipelineConfigInfo& configInfo) {
|
||||
void Pipeline::defaultPipelineConfigInfo(PipelineConfigInfo& configInfo) {
|
||||
|
||||
configInfo.inputAssemblyInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
configInfo.inputAssemblyInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
|
|
|
@ -27,17 +27,17 @@ struct PipelineConfigInfo {
|
|||
uint32_t subpass = 0;
|
||||
};
|
||||
|
||||
class XePipeline {
|
||||
class Pipeline {
|
||||
public:
|
||||
XePipeline(
|
||||
XeDevice &device,
|
||||
Pipeline(
|
||||
Device &device,
|
||||
const std::string& vertFilepath,
|
||||
const std::string& fragFilepath,
|
||||
const PipelineConfigInfo& configInfo);
|
||||
~XePipeline();
|
||||
~Pipeline();
|
||||
|
||||
XePipeline(const XePipeline&) = delete;
|
||||
XePipeline operator=(const XePipeline&) = delete;
|
||||
Pipeline(const Pipeline&) = delete;
|
||||
Pipeline operator=(const Pipeline&) = delete;
|
||||
|
||||
void bind(VkCommandBuffer commandBuffer);
|
||||
static void defaultPipelineConfigInfo(PipelineConfigInfo& configInfo);
|
||||
|
@ -52,7 +52,7 @@ class XePipeline {
|
|||
|
||||
void createShaderModule(const std::vector<char>& code, VkShaderModule* shaderModule);
|
||||
|
||||
XeDevice& xeDevice;
|
||||
Device& xeDevice;
|
||||
VkPipeline graphicsPipeline;
|
||||
VkShaderModule vertShaderModule;
|
||||
VkShaderModule fragShaderModule;
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeRenderSystem::XeRenderSystem(
|
||||
XeEngine &xeEngine,
|
||||
RenderSystem::RenderSystem(
|
||||
Engine &xeEngine,
|
||||
std::string vert,
|
||||
std::string frag,
|
||||
std::map<uint32_t, uint32_t> uniformBindings,
|
||||
std::map<uint32_t, XeImage*> imageBindings,
|
||||
std::map<uint32_t, Image*> imageBindings,
|
||||
uint32_t pushCunstantDataSize,
|
||||
bool cullingEnabled
|
||||
) : xeDevice{xeEngine.xeDevice},
|
||||
|
@ -39,12 +39,12 @@ XeRenderSystem::XeRenderSystem(
|
|||
}
|
||||
|
||||
|
||||
XeRenderSystem::~XeRenderSystem() {
|
||||
RenderSystem::~RenderSystem() {
|
||||
vkDestroyPipelineLayout(xeDevice.device(), pipelineLayout, nullptr);
|
||||
vkDestroySampler(xeDevice.device(), textureSampler, nullptr);
|
||||
};
|
||||
|
||||
void XeRenderSystem::createTextureSampler() {
|
||||
void RenderSystem::createTextureSampler() {
|
||||
VkSamplerCreateInfo samplerInfo{};
|
||||
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
samplerInfo.magFilter = VK_FILTER_LINEAR;
|
||||
|
@ -67,8 +67,8 @@ void XeRenderSystem::createTextureSampler() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeRenderSystem::createDescriptorSetLayout() {
|
||||
XeDescriptorSetLayout::Builder builder{xeDevice};
|
||||
void RenderSystem::createDescriptorSetLayout() {
|
||||
DescriptorSetLayout::Builder builder{xeDevice};
|
||||
|
||||
for ( const auto &[binding, size]: uniformBindings) {
|
||||
builder.addBinding(binding, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, nullptr);
|
||||
|
@ -81,14 +81,14 @@ void XeRenderSystem::createDescriptorSetLayout() {
|
|||
xeDescriptorSetLayout = builder.build();
|
||||
}
|
||||
|
||||
void XeRenderSystem::createUniformBuffers() {
|
||||
void RenderSystem::createUniformBuffers() {
|
||||
for ( const auto &[binding, bufferSize]: uniformBindings) {
|
||||
uboBuffers[binding] = std::vector<std::unique_ptr<XeBuffer>>(XeSwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
uboBuffers[binding] = std::vector<std::unique_ptr<Buffer>>(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
for (int i = 0; i < uboBuffers[binding].size(); i++) {
|
||||
uboBuffers[binding][i] = std::make_unique<XeBuffer>(
|
||||
uboBuffers[binding][i] = std::make_unique<Buffer>(
|
||||
xeDevice,
|
||||
bufferSize,
|
||||
XeSwapChain::MAX_FRAMES_IN_FLIGHT,
|
||||
SwapChain::MAX_FRAMES_IN_FLIGHT,
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
uboBuffers[binding][i]->map();
|
||||
|
@ -96,18 +96,18 @@ void XeRenderSystem::createUniformBuffers() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeRenderSystem::createDescriptorSets() {
|
||||
void RenderSystem::createDescriptorSets() {
|
||||
|
||||
descriptorSets = std::vector<VkDescriptorSet>(XeSwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
descriptorSets = std::vector<VkDescriptorSet>(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
for (int i = 0; i < descriptorSets.size(); i++) {
|
||||
updateDescriptorSet(i, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void XeRenderSystem::updateDescriptorSet(int frameIndex, bool allocate) {
|
||||
void RenderSystem::updateDescriptorSet(int frameIndex, bool allocate) {
|
||||
|
||||
XeDescriptorWriter writer{*xeDescriptorSetLayout, *xeDescriptorPool};
|
||||
DescriptorWriter writer{*xeDescriptorSetLayout, *xeDescriptorPool};
|
||||
|
||||
std::vector<VkDescriptorBufferInfo> bufferInfos{};
|
||||
|
||||
|
@ -135,7 +135,7 @@ void XeRenderSystem::updateDescriptorSet(int frameIndex, bool allocate) {
|
|||
}
|
||||
|
||||
|
||||
void XeRenderSystem::createPipelineLayout() {
|
||||
void RenderSystem::createPipelineLayout() {
|
||||
|
||||
VkPushConstantRange pushConstantRange;
|
||||
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
@ -164,17 +164,17 @@ void XeRenderSystem::createPipelineLayout() {
|
|||
}
|
||||
|
||||
|
||||
void XeRenderSystem::createPipeline(VkRenderPass renderPass, std::string vert, std::string frag, bool cullingEnabled) {
|
||||
void RenderSystem::createPipeline(VkRenderPass renderPass, std::string vert, std::string frag, bool cullingEnabled) {
|
||||
assert(pipelineLayout != nullptr && "Cannot create pipeline before pipeline layout");
|
||||
|
||||
PipelineConfigInfo pipelineConfig{};
|
||||
XePipeline::defaultPipelineConfigInfo(pipelineConfig);
|
||||
Pipeline::defaultPipelineConfigInfo(pipelineConfig);
|
||||
if (cullingEnabled) {
|
||||
pipelineConfig.rasterizationInfo.cullMode = VK_CULL_MODE_BACK_BIT;
|
||||
}
|
||||
pipelineConfig.renderPass = renderPass;
|
||||
pipelineConfig.pipelineLayout = pipelineLayout;
|
||||
xePipeline = std::make_unique<XePipeline>(
|
||||
xePipeline = std::make_unique<Pipeline>(
|
||||
xeDevice,
|
||||
vert,
|
||||
frag,
|
||||
|
@ -182,7 +182,7 @@ void XeRenderSystem::createPipeline(VkRenderPass renderPass, std::string vert, s
|
|||
);
|
||||
}
|
||||
|
||||
void XeRenderSystem::start() {
|
||||
void RenderSystem::start() {
|
||||
xeRenderer.beginSwapChainRenderPass(xeRenderer.getCurrentCommandBuffer());
|
||||
xePipeline->bind(xeRenderer.getCurrentCommandBuffer());
|
||||
if(descriptorSets.size() > 0) {
|
||||
|
@ -200,7 +200,7 @@ void XeRenderSystem::start() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeRenderSystem::loadPushConstant(void *pushConstantData) {
|
||||
void RenderSystem::loadPushConstant(void *pushConstantData) {
|
||||
vkCmdPushConstants(
|
||||
xeRenderer.getCurrentCommandBuffer(),
|
||||
pipelineLayout,
|
||||
|
@ -210,23 +210,23 @@ void XeRenderSystem::loadPushConstant(void *pushConstantData) {
|
|||
pushConstantData);
|
||||
}
|
||||
|
||||
void XeRenderSystem::loadUniformObject(uint32_t binding, void *uniformBufferData) {
|
||||
void RenderSystem::loadUniformObject(uint32_t binding, void *uniformBufferData) {
|
||||
uboBuffers[binding][xeRenderer.getFrameIndex()]->writeToBuffer(uniformBufferData);
|
||||
}
|
||||
|
||||
void XeRenderSystem::loadTexture(uint32_t binding, XeImage *image) {
|
||||
void RenderSystem::loadTexture(uint32_t binding, Image *image) {
|
||||
imageBindings[binding] = image;
|
||||
updateDescriptorSet(xeRenderer.getFrameIndex(), false);
|
||||
}
|
||||
|
||||
void XeRenderSystem::render(XeGameObject &gameObject) {
|
||||
void RenderSystem::render(GameObject &gameObject) {
|
||||
|
||||
gameObject.model->bind(xeRenderer.getCurrentCommandBuffer());
|
||||
gameObject.model->draw(xeRenderer.getCurrentCommandBuffer());
|
||||
|
||||
}
|
||||
|
||||
void XeRenderSystem::stop() {
|
||||
void RenderSystem::stop() {
|
||||
xeRenderer.endSwapChainRenderPass(xeRenderer.getCurrentCommandBuffer());
|
||||
}
|
||||
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeRenderSystem {
|
||||
class RenderSystem {
|
||||
public:
|
||||
|
||||
class Builder {
|
||||
public:
|
||||
Builder(XeEngine &xeEngine, std::string vert, std::string frag) : xeEngine{xeEngine}, vert{vert}, frag{frag} {}
|
||||
Builder(Engine &xeEngine, std::string vert, std::string frag) : xeEngine{xeEngine}, vert{vert}, frag{frag} {}
|
||||
|
||||
Builder& addPushConstant(uint32_t size) {
|
||||
pushCunstantDataSize = size;
|
||||
|
@ -31,7 +31,7 @@ class XeRenderSystem {
|
|||
return *this;
|
||||
}
|
||||
|
||||
Builder& addTextureBinding(uint32_t binding, XeImage* image) {
|
||||
Builder& addTextureBinding(uint32_t binding, Image* image) {
|
||||
imageBindings[binding] = image;
|
||||
return *this;
|
||||
}
|
||||
|
@ -41,14 +41,14 @@ class XeRenderSystem {
|
|||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<XeRenderSystem> build() {
|
||||
return std::make_unique<XeRenderSystem>(xeEngine, std::move(vert), std::move(frag), std::move(uniformBindings), std::move(imageBindings), std::move(pushCunstantDataSize), std::move(cullingEnabled));
|
||||
std::unique_ptr<RenderSystem> build() {
|
||||
return std::make_unique<RenderSystem>(xeEngine, std::move(vert), std::move(frag), std::move(uniformBindings), std::move(imageBindings), std::move(pushCunstantDataSize), std::move(cullingEnabled));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::map<uint32_t, uint32_t> uniformBindings{};
|
||||
std::map<uint32_t, XeImage*> imageBindings{};
|
||||
std::map<uint32_t, Image*> imageBindings{};
|
||||
uint32_t pushCunstantDataSize{0};
|
||||
|
||||
std::string vert;
|
||||
|
@ -56,29 +56,29 @@ class XeRenderSystem {
|
|||
|
||||
bool cullingEnabled{false};
|
||||
|
||||
XeEngine &xeEngine;
|
||||
Engine &xeEngine;
|
||||
};
|
||||
|
||||
XeRenderSystem(
|
||||
XeEngine &xeEngine,
|
||||
RenderSystem(
|
||||
Engine &xeEngine,
|
||||
std::string vert,
|
||||
std::string frag,
|
||||
std::map<uint32_t, uint32_t> uniformBindings,
|
||||
std::map<uint32_t, XeImage*> imageBindings,
|
||||
std::map<uint32_t, Image*> imageBindings,
|
||||
uint32_t pushCunstantDataSize,
|
||||
bool cullingEnabled
|
||||
);
|
||||
|
||||
~XeRenderSystem();
|
||||
~RenderSystem();
|
||||
|
||||
XeRenderSystem(const XeRenderSystem &) = delete;
|
||||
XeRenderSystem operator=(const XeRenderSystem &) = delete;
|
||||
RenderSystem(const RenderSystem &) = delete;
|
||||
RenderSystem operator=(const RenderSystem &) = delete;
|
||||
|
||||
void start();
|
||||
void loadPushConstant(void *pushConstantData);
|
||||
void loadUniformObject(uint32_t binding, void *uniformBufferData);
|
||||
void loadTexture(uint32_t binding, XeImage *image);
|
||||
void render(XeGameObject &gameObject);
|
||||
void loadTexture(uint32_t binding, Image *image);
|
||||
void render(GameObject &gameObject);
|
||||
void stop();
|
||||
|
||||
private:
|
||||
|
@ -95,12 +95,12 @@ class XeRenderSystem {
|
|||
bool boundDescriptor{false};
|
||||
|
||||
|
||||
XeDevice& xeDevice;
|
||||
XeRenderer& xeRenderer;
|
||||
Device& xeDevice;
|
||||
Renderer& xeRenderer;
|
||||
|
||||
std::map<uint32_t, std::vector<std::unique_ptr<XeBuffer>>> uboBuffers{};
|
||||
std::map<uint32_t, std::vector<std::unique_ptr<Buffer>>> uboBuffers{};
|
||||
std::map<uint32_t, uint32_t> uniformBindings;
|
||||
std::map<uint32_t, XeImage*> imageBindings;
|
||||
std::map<uint32_t, Image*> imageBindings;
|
||||
std::vector<VkDescriptorSet> descriptorSets;
|
||||
|
||||
uint32_t pushCunstantDataSize;
|
||||
|
@ -108,9 +108,9 @@ class XeRenderSystem {
|
|||
VkSampler textureSampler;
|
||||
|
||||
VkPipelineLayout pipelineLayout;
|
||||
std::unique_ptr<XePipeline> xePipeline;
|
||||
std::unique_ptr<XeDescriptorPool> &xeDescriptorPool;
|
||||
std::unique_ptr<XeDescriptorSetLayout> xeDescriptorSetLayout;
|
||||
std::unique_ptr<Pipeline> xePipeline;
|
||||
std::unique_ptr<DescriptorPool> &xeDescriptorPool;
|
||||
std::unique_ptr<DescriptorSetLayout> xeDescriptorSetLayout;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -14,14 +14,14 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeRenderer::XeRenderer(XeWindow& window, XeDevice& device) : xeWindow{window}, xeDevice{device} {
|
||||
Renderer::Renderer(Window& window, Device& device) : xeWindow{window}, xeDevice{device} {
|
||||
recreateSwapChain();
|
||||
createCommandBuffers();
|
||||
}
|
||||
|
||||
XeRenderer::~XeRenderer() { freeCommandBuffers(); }
|
||||
Renderer::~Renderer() { freeCommandBuffers(); }
|
||||
|
||||
void XeRenderer::recreateSwapChain() {
|
||||
void Renderer::recreateSwapChain() {
|
||||
auto extent = xeWindow.getExtent();
|
||||
while (extent.width == 0 || extent.height == 0) {
|
||||
extent = xeWindow.getExtent();
|
||||
|
@ -31,10 +31,10 @@ void XeRenderer::recreateSwapChain() {
|
|||
vkDeviceWaitIdle(xeDevice.device());
|
||||
|
||||
if(xeSwapChain == nullptr) {
|
||||
xeSwapChain = std::make_unique<XeSwapChain>(xeDevice, extent);
|
||||
xeSwapChain = std::make_unique<SwapChain>(xeDevice, extent);
|
||||
} else {
|
||||
std::shared_ptr<XeSwapChain> oldSwapChain = std::move(xeSwapChain);
|
||||
xeSwapChain = std::make_unique<XeSwapChain>(xeDevice, extent, oldSwapChain);
|
||||
std::shared_ptr<SwapChain> oldSwapChain = std::move(xeSwapChain);
|
||||
xeSwapChain = std::make_unique<SwapChain>(xeDevice, extent, oldSwapChain);
|
||||
|
||||
if(!oldSwapChain->compareSwapFormats(*xeSwapChain.get())) {
|
||||
throw std::runtime_error("Swap chain image (or depth) format has changed");
|
||||
|
@ -45,9 +45,9 @@ void XeRenderer::recreateSwapChain() {
|
|||
// we'll come back to this in just a moment
|
||||
}
|
||||
|
||||
void XeRenderer::createCommandBuffers() {
|
||||
void Renderer::createCommandBuffers() {
|
||||
|
||||
commandBuffers.resize(XeSwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
commandBuffers.resize(SwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
|
@ -61,7 +61,7 @@ void XeRenderer::createCommandBuffers() {
|
|||
|
||||
}
|
||||
|
||||
void XeRenderer::freeCommandBuffers() {
|
||||
void Renderer::freeCommandBuffers() {
|
||||
vkFreeCommandBuffers(
|
||||
xeDevice.device(),
|
||||
xeDevice.getCommandPool(),
|
||||
|
@ -70,7 +70,7 @@ void XeRenderer::freeCommandBuffers() {
|
|||
commandBuffers.clear();
|
||||
}
|
||||
|
||||
VkCommandBuffer XeRenderer::beginFrame() {
|
||||
VkCommandBuffer Renderer::beginFrame() {
|
||||
assert(!isFrameStarted && "Can't acll beingFrame while already in progress");
|
||||
|
||||
auto result = xeSwapChain->acquireNextImage(¤tImageIndex);
|
||||
|
@ -97,7 +97,7 @@ VkCommandBuffer XeRenderer::beginFrame() {
|
|||
return commandBuffer;
|
||||
}
|
||||
|
||||
void XeRenderer::endFrame() {
|
||||
void Renderer::endFrame() {
|
||||
assert(isFrameStarted && "Can't call endFrame while frame is not in progress");
|
||||
auto commandBuffer = getCurrentCommandBuffer();
|
||||
if(vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {
|
||||
|
@ -111,10 +111,10 @@ void XeRenderer::endFrame() {
|
|||
}
|
||||
|
||||
isFrameStarted = false;
|
||||
currentFrameIndex = (currentFrameIndex + 1) % XeSwapChain::MAX_FRAMES_IN_FLIGHT;
|
||||
currentFrameIndex = (currentFrameIndex + 1) % SwapChain::MAX_FRAMES_IN_FLIGHT;
|
||||
}
|
||||
|
||||
void XeRenderer::beginSwapChainRenderPass(VkCommandBuffer commandBuffer){
|
||||
void Renderer::beginSwapChainRenderPass(VkCommandBuffer commandBuffer){
|
||||
assert(isFrameStarted && "Can't call beginSwapChainRenderPass while frame is not in progress");
|
||||
assert(commandBuffer == getCurrentCommandBuffer() && "Can't begin render pass on command buffer from a different frame");
|
||||
|
||||
|
@ -146,7 +146,7 @@ void XeRenderer::beginSwapChainRenderPass(VkCommandBuffer commandBuffer){
|
|||
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
|
||||
}
|
||||
|
||||
void XeRenderer::endSwapChainRenderPass(VkCommandBuffer commandBuffer){
|
||||
void Renderer::endSwapChainRenderPass(VkCommandBuffer commandBuffer){
|
||||
assert(isFrameStarted && "Can't call endSwapChainRenderPass while frame is not in progress");
|
||||
assert(commandBuffer == getCurrentCommandBuffer() && "Can't end render pass on command buffer from a different frame");
|
||||
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
#include <cassert>
|
||||
|
||||
namespace xe {
|
||||
class XeRenderer {
|
||||
class Renderer {
|
||||
public:
|
||||
|
||||
XeRenderer(XeWindow &window, XeDevice &device);
|
||||
~XeRenderer();
|
||||
Renderer(Window &window, Device &device);
|
||||
~Renderer();
|
||||
|
||||
XeRenderer(const XeRenderer &) = delete;
|
||||
XeRenderer operator=(const XeRenderer &) = delete;
|
||||
Renderer(const Renderer &) = delete;
|
||||
Renderer operator=(const Renderer &) = delete;
|
||||
|
||||
VkRenderPass getSwapChainRenderPass() const { return xeSwapChain->getRenderPass(); }
|
||||
float getAspectRatio() const { return xeSwapChain->extentAspectRatio(); }
|
||||
|
@ -43,9 +43,9 @@ class XeRenderer {
|
|||
void freeCommandBuffers();
|
||||
void recreateSwapChain();
|
||||
|
||||
XeWindow& xeWindow;
|
||||
XeDevice& xeDevice;
|
||||
std::unique_ptr<XeSwapChain> xeSwapChain;
|
||||
Window& xeWindow;
|
||||
Device& xeDevice;
|
||||
std::unique_ptr<SwapChain> xeSwapChain;
|
||||
std::vector<VkCommandBuffer> commandBuffers;
|
||||
|
||||
uint32_t currentImageIndex;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeSound::XeSound(const std::string& filename) {
|
||||
Sound::Sound(const std::string& filename) {
|
||||
|
||||
buffer = alutCreateBufferFromFile(filename.c_str());
|
||||
|
||||
|
@ -21,43 +21,43 @@ XeSound::XeSound(const std::string& filename) {
|
|||
|
||||
}
|
||||
|
||||
XeSound::~XeSound() {
|
||||
Sound::~Sound() {
|
||||
alDeleteSources(1, &source);
|
||||
alDeleteBuffers(1, &buffer);
|
||||
}
|
||||
|
||||
void XeSound::play() {
|
||||
void Sound::play() {
|
||||
stop();
|
||||
alSourcePlay(source);
|
||||
};
|
||||
|
||||
void XeSound::stop() {
|
||||
void Sound::stop() {
|
||||
alSourceStop(source);
|
||||
};
|
||||
|
||||
void XeSound::pause() {
|
||||
void Sound::pause() {
|
||||
alSourcePause(source);
|
||||
};
|
||||
|
||||
void XeSound::resume() {
|
||||
void Sound::resume() {
|
||||
alSourcePlay(source);
|
||||
};
|
||||
|
||||
bool XeSound::isPlaying() {
|
||||
bool Sound::isPlaying() {
|
||||
ALint playing;
|
||||
alGetSourcei(source, AL_SOURCE_STATE, &playing);
|
||||
return playing == AL_PLAYING;
|
||||
};
|
||||
|
||||
void XeSound::setPosition(glm::vec3 position) {
|
||||
void Sound::setPosition(glm::vec3 position) {
|
||||
alSource3f(source, AL_POSITION, position.x, position.y, position.z);
|
||||
};
|
||||
|
||||
void XeSound::setLooping(bool looping) {
|
||||
void Sound::setLooping(bool looping) {
|
||||
alSourcei(source, AL_LOOPING, looping ? 1 : 0);
|
||||
};
|
||||
|
||||
void XeSound::setVolume(float volume) {
|
||||
void Sound::setVolume(float volume) {
|
||||
alSourcef(source, AL_GAIN, volume);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeSound {
|
||||
class Sound {
|
||||
|
||||
public:
|
||||
|
||||
XeSound(const std::string& filename);
|
||||
~XeSound();
|
||||
Sound(const std::string& filename);
|
||||
~Sound();
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
|
|
|
@ -11,21 +11,21 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
bool XeSwapChain::initialSwapChainCreated = false;
|
||||
bool SwapChain::initialSwapChainCreated = false;
|
||||
|
||||
XeSwapChain::XeSwapChain(XeDevice &deviceRef, VkExtent2D extent)
|
||||
SwapChain::SwapChain(Device &deviceRef, VkExtent2D extent)
|
||||
: device{deviceRef}, windowExtent{extent} {
|
||||
init();
|
||||
}
|
||||
|
||||
XeSwapChain::XeSwapChain(XeDevice &deviceRef, VkExtent2D extent, std::shared_ptr<XeSwapChain> previous)
|
||||
SwapChain::SwapChain(Device &deviceRef, VkExtent2D extent, std::shared_ptr<SwapChain> previous)
|
||||
: device{deviceRef}, windowExtent{extent}, oldSwapChain{previous} {
|
||||
init();
|
||||
|
||||
oldSwapChain = nullptr;
|
||||
}
|
||||
|
||||
void XeSwapChain::init() {
|
||||
void SwapChain::init() {
|
||||
createSwapChain();
|
||||
createImageViews();
|
||||
createRenderPass();
|
||||
|
@ -35,7 +35,7 @@ void XeSwapChain::init() {
|
|||
initialSwapChainCreated = true;
|
||||
}
|
||||
|
||||
XeSwapChain::~XeSwapChain() {
|
||||
SwapChain::~SwapChain() {
|
||||
for (auto imageView : swapChainImageViews) {
|
||||
vkDestroyImageView(device.device(), imageView, nullptr);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ XeSwapChain::~XeSwapChain() {
|
|||
}
|
||||
}
|
||||
|
||||
VkResult XeSwapChain::acquireNextImage(uint32_t *imageIndex) {
|
||||
VkResult SwapChain::acquireNextImage(uint32_t *imageIndex) {
|
||||
vkWaitForFences(
|
||||
device.device(),
|
||||
1,
|
||||
|
@ -84,7 +84,7 @@ VkResult XeSwapChain::acquireNextImage(uint32_t *imageIndex) {
|
|||
return result;
|
||||
}
|
||||
|
||||
VkResult XeSwapChain::submitCommandBuffers(
|
||||
VkResult SwapChain::submitCommandBuffers(
|
||||
const VkCommandBuffer *buffers, uint32_t *imageIndex) {
|
||||
if (imagesInFlight[*imageIndex] != VK_NULL_HANDLE) {
|
||||
vkWaitForFences(device.device(), 1, &imagesInFlight[*imageIndex], VK_TRUE, UINT64_MAX);
|
||||
|
@ -132,7 +132,7 @@ VkResult XeSwapChain::submitCommandBuffers(
|
|||
return result;
|
||||
}
|
||||
|
||||
void XeSwapChain::createSwapChain() {
|
||||
void SwapChain::createSwapChain() {
|
||||
SwapChainSupportDetails swapChainSupport = device.getSwapChainSupport();
|
||||
|
||||
VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats);
|
||||
|
@ -189,7 +189,7 @@ void XeSwapChain::createSwapChain() {
|
|||
swapChainExtent = extent;
|
||||
}
|
||||
|
||||
void XeSwapChain::createImageViews() {
|
||||
void SwapChain::createImageViews() {
|
||||
swapChainImageViews.resize(swapChainImages.size());
|
||||
for (size_t i = 0; i < swapChainImages.size(); i++) {
|
||||
VkImageViewCreateInfo viewInfo{};
|
||||
|
@ -210,7 +210,7 @@ void XeSwapChain::createImageViews() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeSwapChain::createRenderPass() {
|
||||
void SwapChain::createRenderPass() {
|
||||
VkAttachmentDescription depthAttachment{};
|
||||
depthAttachment.format = findDepthFormat();
|
||||
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
@ -271,7 +271,7 @@ void XeSwapChain::createRenderPass() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeSwapChain::createFramebuffers() {
|
||||
void SwapChain::createFramebuffers() {
|
||||
swapChainFramebuffers.resize(imageCount());
|
||||
for (size_t i = 0; i < imageCount(); i++) {
|
||||
std::array<VkImageView, 2> attachments = {swapChainImageViews[i], depthImageViews[i]};
|
||||
|
@ -296,7 +296,7 @@ void XeSwapChain::createFramebuffers() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeSwapChain::createDepthResources() {
|
||||
void SwapChain::createDepthResources() {
|
||||
VkFormat depthFormat = findDepthFormat();
|
||||
swapChainDepthFormat = depthFormat;
|
||||
VkExtent2D swapChainExtent = getSwapChainExtent();
|
||||
|
@ -345,7 +345,7 @@ void XeSwapChain::createDepthResources() {
|
|||
}
|
||||
}
|
||||
|
||||
void XeSwapChain::createSyncObjects() {
|
||||
void SwapChain::createSyncObjects() {
|
||||
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
|
@ -369,7 +369,7 @@ void XeSwapChain::createSyncObjects() {
|
|||
}
|
||||
}
|
||||
|
||||
VkSurfaceFormatKHR XeSwapChain::chooseSwapSurfaceFormat(
|
||||
VkSurfaceFormatKHR SwapChain::chooseSwapSurfaceFormat(
|
||||
const std::vector<VkSurfaceFormatKHR> &availableFormats) {
|
||||
for (const auto &availableFormat : availableFormats) {
|
||||
if (availableFormat.format == VK_FORMAT_B8G8R8A8_UNORM &&
|
||||
|
@ -381,7 +381,7 @@ VkSurfaceFormatKHR XeSwapChain::chooseSwapSurfaceFormat(
|
|||
return availableFormats[0];
|
||||
}
|
||||
|
||||
VkPresentModeKHR XeSwapChain::chooseSwapPresentMode(
|
||||
VkPresentModeKHR SwapChain::chooseSwapPresentMode(
|
||||
const std::vector<VkPresentModeKHR> &availablePresentModes) {
|
||||
for (const auto &availablePresentMode : availablePresentModes) {
|
||||
if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
|
||||
|
@ -404,7 +404,7 @@ VkPresentModeKHR XeSwapChain::chooseSwapPresentMode(
|
|||
return VK_PRESENT_MODE_FIFO_KHR;
|
||||
}
|
||||
|
||||
VkExtent2D XeSwapChain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities) {
|
||||
VkExtent2D SwapChain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities) {
|
||||
if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max()) {
|
||||
return capabilities.currentExtent;
|
||||
} else {
|
||||
|
@ -420,7 +420,7 @@ VkExtent2D XeSwapChain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabil
|
|||
}
|
||||
}
|
||||
|
||||
VkFormat XeSwapChain::findDepthFormat() {
|
||||
VkFormat SwapChain::findDepthFormat() {
|
||||
return device.findSupportedFormat(
|
||||
{VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT},
|
||||
VK_IMAGE_TILING_OPTIMAL,
|
||||
|
|
|
@ -11,16 +11,16 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
class XeSwapChain {
|
||||
class SwapChain {
|
||||
public:
|
||||
static constexpr int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
|
||||
XeSwapChain(XeDevice &deviceRef, VkExtent2D windowExtent);
|
||||
XeSwapChain(XeDevice &deviceRef, VkExtent2D windowExtent, std::shared_ptr<XeSwapChain> previous);
|
||||
~XeSwapChain();
|
||||
SwapChain(Device &deviceRef, VkExtent2D windowExtent);
|
||||
SwapChain(Device &deviceRef, VkExtent2D windowExtent, std::shared_ptr<SwapChain> previous);
|
||||
~SwapChain();
|
||||
|
||||
XeSwapChain(const XeSwapChain &) = delete;
|
||||
XeSwapChain operator=(const XeSwapChain &) = delete;
|
||||
SwapChain(const SwapChain &) = delete;
|
||||
SwapChain operator=(const SwapChain &) = delete;
|
||||
|
||||
VkFramebuffer getFrameBuffer(int index) { return swapChainFramebuffers[index]; }
|
||||
VkRenderPass getRenderPass() { return renderPass; }
|
||||
|
@ -39,7 +39,7 @@ class XeSwapChain {
|
|||
VkResult acquireNextImage(uint32_t *imageIndex);
|
||||
VkResult submitCommandBuffers(const VkCommandBuffer *buffers, uint32_t *imageIndex);
|
||||
|
||||
bool compareSwapFormats(const XeSwapChain& swapChain) const {
|
||||
bool compareSwapFormats(const SwapChain& swapChain) const {
|
||||
return swapChain.swapChainDepthFormat == swapChainDepthFormat &&
|
||||
swapChain.swapChainImageFormat == swapChainImageFormat;
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ class XeSwapChain {
|
|||
std::vector<VkImage> swapChainImages;
|
||||
std::vector<VkImageView> swapChainImageViews;
|
||||
|
||||
XeDevice &device;
|
||||
Device &device;
|
||||
VkExtent2D windowExtent;
|
||||
|
||||
VkSwapchainKHR swapChain;
|
||||
std::shared_ptr<XeSwapChain> oldSwapChain;
|
||||
std::shared_ptr<SwapChain> oldSwapChain;
|
||||
|
||||
std::vector<VkSemaphore> imageAvailableSemaphores;
|
||||
std::vector<VkSemaphore> renderFinishedSemaphores;
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
|
||||
namespace xe {
|
||||
|
||||
XeWindow::XeWindow(int w, int h, std::string name) : width{w}, height{h}, windowName{name} {
|
||||
Window::Window(int w, int h, std::string name) : width{w}, height{h}, windowName{name} {
|
||||
initWindow();
|
||||
}
|
||||
|
||||
XeWindow::~XeWindow() {
|
||||
Window::~Window() {
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void XeWindow::initWindow() {
|
||||
void Window::initWindow() {
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
|
@ -25,14 +25,14 @@ namespace xe {
|
|||
glfwSetFramebufferSizeCallback(window, framebufferResizeCallback);
|
||||
}
|
||||
|
||||
void XeWindow::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface){
|
||||
void Window::createWindowSurface(VkInstance instance, VkSurfaceKHR *surface){
|
||||
if (glfwCreateWindowSurface(instance, window, nullptr, surface) != VK_SUCCESS) {
|
||||
throw std::runtime_error("failed to create window surface");
|
||||
}
|
||||
}
|
||||
|
||||
void XeWindow::framebufferResizeCallback(GLFWwindow *window, int width, int height){
|
||||
auto xeWindow = reinterpret_cast<XeWindow *>(glfwGetWindowUserPointer(window));
|
||||
void Window::framebufferResizeCallback(GLFWwindow *window, int width, int height){
|
||||
auto xeWindow = reinterpret_cast<Window *>(glfwGetWindowUserPointer(window));
|
||||
xeWindow->frameBufferResized = true;
|
||||
xeWindow->width = width;
|
||||
xeWindow->height = height;
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
#include <string>
|
||||
namespace xe {
|
||||
|
||||
class XeWindow {
|
||||
class Window {
|
||||
public:
|
||||
XeWindow(int w, int h, std::string name);
|
||||
~XeWindow();
|
||||
Window(int w, int h, std::string name);
|
||||
~Window();
|
||||
|
||||
XeWindow(const XeWindow &) = delete;
|
||||
XeWindow &operator=(const XeWindow &);
|
||||
Window(const Window &) = delete;
|
||||
Window &operator=(const Window &);
|
||||
|
||||
bool shouldClose() { return glfwWindowShouldClose(window); }
|
||||
VkExtent2D getExtent() { return { static_cast<uint32_t>(width), static_cast<uint32_t>(height)}; }
|
||||
|
|
|
@ -27,16 +27,16 @@ FirstApp::~FirstApp() {}
|
|||
|
||||
void FirstApp::run() {
|
||||
|
||||
std::shared_ptr<xe::XeImage> image = xeEngine.loadImage("res/image/texture.png");
|
||||
std::shared_ptr<xe::XeImage> image2 = xeEngine.loadImage("res/image/scaly.png");
|
||||
std::shared_ptr<xe::Image> image = xeEngine.loadImage("res/image/texture.png");
|
||||
std::shared_ptr<xe::Image> image2 = xeEngine.loadImage("res/image/ltt.");
|
||||
|
||||
SimpleRenderer renderer{xeEngine, image.get()};
|
||||
|
||||
xe::XeSound sound{"res/sound/when_the_world_ends.wav"};
|
||||
xe::Sound sound{"res/sound/when_the_world_ends.wav"};
|
||||
sound.setLooping(true);
|
||||
sound.play();
|
||||
|
||||
auto viewerObject = xe::XeGameObject::createGameObject();
|
||||
auto viewerObject = xe::GameObject::createGameObject();
|
||||
viewerObject.transform.translation = {-7.f, 3.f, -7.f};
|
||||
viewerObject.transform.rotation.y = glm::radians(45.f);
|
||||
KeyboardMovementController cameraController{};
|
||||
|
@ -60,15 +60,15 @@ void FirstApp::run() {
|
|||
}
|
||||
|
||||
void FirstApp::loadGameObjects() {
|
||||
std::shared_ptr<xe::XeModel> xeModel = xeEngine.loadModelFromFile("res/models/stanford-dragon.obj");
|
||||
std::shared_ptr<xe::Model> xeModel = xeEngine.loadModelFromFile("res/models/stanford-dragon.obj");
|
||||
|
||||
auto dragon = xe::XeGameObject::createGameObject();
|
||||
auto dragon = xe::GameObject::createGameObject();
|
||||
dragon.model = xeModel;
|
||||
dragon.transform.translation = {.0f, .0f, 2.5f};
|
||||
dragon.transform.scale = {.5f, .5f, .5f};
|
||||
gameObjects.push_back(std::move(dragon));
|
||||
|
||||
auto dragon2 = xe::XeGameObject::createGameObject();
|
||||
auto dragon2 = xe::GameObject::createGameObject();
|
||||
dragon2.model = xeModel;
|
||||
dragon2.transform.translation = {5.0f, .0f, -1.5f};
|
||||
dragon2.transform.rotation.y = glm::radians(90.f);
|
||||
|
|
|
@ -26,8 +26,8 @@ class FirstApp {
|
|||
|
||||
void loadGameObjects();
|
||||
|
||||
xe::XeEngine xeEngine;
|
||||
xe::Engine xeEngine;
|
||||
|
||||
std::vector<xe::XeGameObject> gameObjects;
|
||||
std::vector<xe::GameObject> gameObjects;
|
||||
};
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace app {
|
||||
|
||||
void KeyboardMovementController::moveInPlaneXZ(GLFWwindow* window, float dt, xe::XeGameObject& gameObject) {
|
||||
void KeyboardMovementController::moveInPlaneXZ(GLFWwindow* window, float dt, xe::GameObject& gameObject) {
|
||||
glm::vec3 rotate{0};
|
||||
if(glfwGetKey(window, keys.lookRight) == GLFW_PRESS) rotate.y += 1.f;
|
||||
if(glfwGetKey(window, keys.lookLeft) == GLFW_PRESS) rotate.y -= 1.f;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace app {
|
|||
int lookDown = GLFW_KEY_DOWN;
|
||||
};
|
||||
|
||||
void moveInPlaneXZ(GLFWwindow* window, float dt, xe::XeGameObject& gameObject);
|
||||
void moveInPlaneXZ(GLFWwindow* window, float dt, xe::GameObject& gameObject);
|
||||
|
||||
KeyMappings keys{};
|
||||
float moveSpeed{3.f};
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
namespace app {
|
||||
|
||||
SimpleRenderer::SimpleRenderer(xe::XeEngine &xeEngine, xe::XeImage *xeImage) {
|
||||
xeRenderSystem = xe::XeRenderSystem::Builder(xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv")
|
||||
SimpleRenderer::SimpleRenderer(xe::Engine &xeEngine, xe::Image *xeImage) {
|
||||
xeRenderSystem = xe::RenderSystem::Builder(xeEngine, "res/shaders/simple_shader.vert.spv", "res/shaders/simple_shader.frag.spv")
|
||||
.addPushConstant(sizeof(PushConstant))
|
||||
.addUniformBinding(0, sizeof(UniformBuffer))
|
||||
.addTextureBinding(1, xeImage)
|
||||
|
@ -14,7 +14,7 @@ SimpleRenderer::SimpleRenderer(xe::XeEngine &xeEngine, xe::XeImage *xeImage) {
|
|||
.build();
|
||||
}
|
||||
|
||||
void SimpleRenderer::render(std::vector<xe::XeGameObject> &gameObjects, xe::XeCamera &xeCamera, xe::XeImage *xeImage) {
|
||||
void SimpleRenderer::render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera, xe::Image *xeImage) {
|
||||
|
||||
xeRenderSystem->loadTexture(1, xeImage);
|
||||
|
||||
|
|
|
@ -19,17 +19,17 @@ class SimpleRenderer {
|
|||
|
||||
public:
|
||||
|
||||
SimpleRenderer(xe::XeEngine &xeEngine, xe::XeImage *xeImage);
|
||||
SimpleRenderer(xe::Engine &xeEngine, xe::Image *xeImage);
|
||||
|
||||
~SimpleRenderer() {};
|
||||
|
||||
SimpleRenderer(const SimpleRenderer&) = delete;
|
||||
SimpleRenderer operator=(const SimpleRenderer&) = delete;
|
||||
|
||||
void render(std::vector<xe::XeGameObject> &gameObjects, xe::XeCamera &xeCamera, xe::XeImage *xeImage);
|
||||
void render(std::vector<xe::GameObject> &gameObjects, xe::Camera &xeCamera, xe::Image *xeImage);
|
||||
|
||||
private:
|
||||
std::unique_ptr<xe::XeRenderSystem> xeRenderSystem;
|
||||
std::unique_ptr<xe::RenderSystem> xeRenderSystem;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue