Hi.
First time posting.
Quite new to graphics programming. First time with Vulkan. Right now I’m not trying to write the most optimal code. I actually plan writing this entire project from scratch after it’s done. Hence the bloated code.
I set up Vulkan as per Branden Gela’s tutorial and then I implemented textures following Lukasino’s tutorial.
Currently in my scene’s constructor I’m setting up a global pool:
globalPool = lve::LveDescriptorPool::Builder(lveDevice)
.setMaxSets(lve::LveSwapChain::MAX_FRAMES_IN_FLIGHT)
.addPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, lve::LveSwapChain::MAX_FRAMES_IN_FLIGHT)
.addPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,lve::LveSwapChain::MAX_FRAMES_IN_FLIGHT)
.build();
loadGameObjects();
And then when it’s being run I set up a descriptor set layout and write my texture to a vkdescriptor.
auto globalSetLayout = lve::LveDescriptorSetLayout::Builder(lveDevice)
.addBinding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_ALL_GRAPHICS)
.addBinding(1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT)
.build();
lve::Texture texture = lve::Texture(lveDevice, "Images/Sprites/Blaze.png");
VkDescriptorImageInfo imageInfo = {};
imageInfo.sampler = texture.getSampler();
imageInfo.imageView = texture.getImageView();
imageInfo.imageLayout = texture.getImageLayout();
std::vector<VkDescriptorSet> globalDescriptorSets(lve::LveSwapChain::MAX_FRAMES_IN_FLIGHT);
for (int i = 0; i < globalDescriptorSets.size(); i++) {
auto bufferInfo = uboBuffers[i]->descriptorInfo();
lve::LveDescriptorWriter(*globalSetLayout, *globalPool)
.writeBuffer(0, &bufferInfo)
.writeImage(1,&imageInfo)
.build(globalDescriptorSets[i]);
Now this is where the tricky part comes in. I’m told I need create a separate descriptor for each texture-model combination. Or add all the textures to a texture array? Or rewrite each texture once it’s been rendered.
But with my setup, I use a frame info which passes all the gameobjects in my scene as well as everything in the vk descriptor.
auto commandBuffer = lveRenderer.beginFrame();
if (!commandBuffer) continue;
lveRenderer.beginSwapChainRenderPass(commandBuffer);
int frameIndex = lveRenderer.getFrameIndex();
lve::FrameInfo frameInfo{
frameIndex,
frameTime,
commandBuffer,
camera,
globalDescriptorSets[frameIndex],
gameObjects
};
simpleRenderSystem.getlvePipelinePtr()->bind(commandBuffer);
lveRenderer.bindPipelineEssentials(commandBuffer, frameInfo);
simpleRenderSystem.bindDescriptorSets(frameInfo);
//update
lve::GlobalUbo ubo{};
ubo.projection = camera.getProjection();
ubo.view = camera.getView();
ubo.inverseView = camera.getInverseView();
pointLightSystem.update(frameInfo, ubo);
uboBuffers[frameIndex]->writeToBuffer(&ubo);
uboBuffers[frameIndex]->flush();
//order here matters
simpleRenderSystem.renderGameObects(frameInfo);
pointLightSystem.render(frameInfo);
nrd::NrdDebugLinePipeline* debugPipelinePtr = simpleRenderSystem.getDebugPipelinePtr();
debugPipelinePtr->bind(commandBuffer);
lveRenderer.bindPipelineEssentials(commandBuffer, frameInfo);
simpleRenderSystem.bindDescriptorSets(frameInfo);
//render
// Update and render the debug line
simpleRenderSystem.renderGameObects(frameInfo);
lveRenderer.endSwapChainRenderPass(commandBuffer);
lveRenderer.endFrame();
So how do I update the frame info to take a different texture for different gameobject?
This is how my render function is set up btw:
void SimpleRenderSystem::renderGameObects(
FrameInfo & frameInfo)
{
//lvePipeline->bind(frameInfo.commandBuffer);
//update
for (auto& obj : frameInfo.gameObjects) {
if (obj->model == nullptr) continue;//IF THE Gameobj->ct doesn't have a model
//obj->transform.rotation.y = glm::mod(obj->transform.rotation.y + 0.0001f, glm::two_pi<float>());
//obj->transform.rotation.x = glm::mod(obj->transform.rotation.x + 0.0001f, glm::two_pi<float>());
obj->bind(frameInfo);
obj->draw(frameInfo, pipelineLayout);
}
}
I plan on animating the game objects by changing the UV coordinates. I don’t know if there’s anything I should consider at this stage for it to work. I’m trying to make a 2.5D beat em up. I know using Vulkan for it is Overkill, but I really want to learn Vulkan while making something I like.