summaryrefslogtreecommitdiff
path: root/engine/xe_render_system.cpp
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2022-09-26 18:03:07 -0400
committerTyler Murphy <tylermurphy534@gmail.com>2022-09-26 18:03:07 -0400
commit873ca38c0dc8966cd54a18dd74d40c709d83eb32 (patch)
tree0d49e34d566d23bb73f534294737e253613a2a01 /engine/xe_render_system.cpp
parentundo nearest neighbor (diff)
downloadminecraftvulkan-873ca38c0dc8966cd54a18dd74d40c709d83eb32.tar.gz
minecraftvulkan-873ca38c0dc8966cd54a18dd74d40c709d83eb32.tar.bz2
minecraftvulkan-873ca38c0dc8966cd54a18dd74d40c709d83eb32.zip
texture arrays
Diffstat (limited to 'engine/xe_render_system.cpp')
-rw-r--r--engine/xe_render_system.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/engine/xe_render_system.cpp b/engine/xe_render_system.cpp
index cdfe3cb..f2f0e43 100644
--- a/engine/xe_render_system.cpp
+++ b/engine/xe_render_system.cpp
@@ -8,6 +8,7 @@ RenderSystem::RenderSystem(
std::string frag,
std::map<uint32_t, uint32_t> uniformBindings,
std::map<uint32_t, Image*> imageBindings,
+ std::map<uint32_t, std::vector<Image*>> imageArrayBindings,
uint32_t pushCunstantDataSize,
bool cullingEnabled,
std::vector<VkVertexInputAttributeDescription> attributeDescptions,
@@ -17,7 +18,8 @@ RenderSystem::RenderSystem(
xeDescriptorPool{xeEngine.xeDescriptorPool},
pushCunstantDataSize{pushCunstantDataSize},
uniformBindings{uniformBindings},
- imageBindings{imageBindings} {
+ imageBindings{imageBindings},
+ imageArrayBindings{imageArrayBindings} {
createDescriptorSetLayout();
createUniformBuffers();
createDescriptorSets();
@@ -33,11 +35,15 @@ 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);
+ builder.addBinding(binding, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, nullptr, 1);
}
for ( const auto &[binding, image]: imageBindings) {
- builder.addBinding(binding, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, &(image->textureSampler));
+ builder.addBinding(binding, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, &(image->textureSampler), 1);
+ }
+
+ for ( const auto &[binding, images]: imageArrayBindings) {
+ builder.addBinding(binding, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 0, images.size());
}
xeDescriptorSetLayout = builder.build();
@@ -88,6 +94,18 @@ void RenderSystem::updateDescriptorSet(int frameIndex, bool allocate) {
writer.writeImage(binding, &imageInfo);
}
+ std::vector<VkDescriptorImageInfo> imageInfos{};
+ for ( const auto &[binding, images]: imageArrayBindings) {
+ for( const auto &image: images) {
+ VkDescriptorImageInfo imageInfo{};
+ imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+ imageInfo.imageView = image->textureImageView;
+ imageInfo.sampler = image->textureSampler;
+ imageInfos.push_back(imageInfo);
+ }
+ writer.writeImageArray(binding, &imageInfos);
+ }
+
if (allocate) {
writer.build(descriptorSets[frameIndex]);
} else {
@@ -183,6 +201,11 @@ void RenderSystem::loadTexture(uint32_t binding, Image *image) {
updateDescriptorSet(xeRenderer.getFrameIndex(), false);
}
+void RenderSystem::loadTextureArray(uint32_t binding, std::vector<Image*>& images) {
+ imageArrayBindings[binding] = images;
+ updateDescriptorSet(xeRenderer.getFrameIndex(), false);
+}
+
void RenderSystem::render(GameObject &gameObject) {
gameObject.model->bind(xeRenderer.getCurrentCommandBuffer());