Bunch of changes + fixes

This commit is contained in:
2026-09-26 01:49:45 -07:00
parent e05926ad74
commit b24945ec9d
9 changed files with 40 additions and 19 deletions
+7 -5
View File
@@ -91,12 +91,13 @@ void ImGuiRenderer::beginFrame() {
}
ImTextureID ImGuiRenderer::getTextureId(RenderTargetHandle handle) {
vk::ImageView view =
resources.renderTargetPool.get(handle).getImage().getView();
const RenderTarget& target = resources.renderTargetPool.get(handle);
vk::ImageView view = target.getImage().getView();
auto it = textures.find(handle.index);
if (it != textures.end()) {
if (it->second.generation == handle.generation && it->second.view == view) {
if (it->second.generation == handle.generation &&
it->second.version == target.getVersion()) {
return (ImTextureID)it->second.descriptorSet;
}
ImGui_ImplVulkan_RemoveTexture(it->second.descriptorSet);
@@ -107,7 +108,8 @@ ImTextureID ImGuiRenderer::getTextureId(RenderTargetHandle handle) {
// left in once the scene pass has finished.
VkDescriptorSet descriptorSet = ImGui_ImplVulkan_AddTexture(
static_cast<VkImageView>(view), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
textures[handle.index] = {handle.generation, view, descriptorSet};
textures[handle.index] = {handle.generation, target.getVersion(),
descriptorSet};
return (ImTextureID)descriptorSet;
}
@@ -120,7 +122,7 @@ void ImGuiRenderer::releaseStaleTextures() {
bool stale =
!renderTargetPool.isAlive(handle) ||
renderTargetPool.get(handle).getImage().getView() != it->second.view;
renderTargetPool.get(handle).getVersion() != it->second.version;
if (stale) {
ImGui_ImplVulkan_RemoveTexture(it->second.descriptorSet);
it = textures.erase(it);
+1 -1
View File
@@ -37,7 +37,7 @@ class ImGuiRenderer {
struct Texture {
u32 generation;
vk::ImageView view;
u32 version;
VkDescriptorSet descriptorSet;
};
+1
View File
@@ -39,6 +39,7 @@ void RenderTarget::applyPendingResize() {
}
void RenderTarget::create(u32 width, u32 height) {
this->version++;
this->image = Image::Builder(this->device)
.setExtent(width, height)
.setFormat(this->format)
+2
View File
@@ -27,6 +27,7 @@ class RenderTarget {
Image& getImage() const { return *this->image; }
vk::Extent2D getExtent() const;
u32 getVersion() const { return this->version; }
void requestResize(u32 width, u32 height);
@@ -46,6 +47,7 @@ class RenderTarget {
std::unique_ptr<Image> image;
std::optional<vk::Extent2D> pendingExtent;
u32 version = 0;
};
} // namespace sophia
+18
View File
@@ -16,6 +16,24 @@ Entity Scene::createEntity(const std::string& name) {
return entity;
}
Entity Scene::createCamera(const std::string& name) {
Entity camera = createEntity(name);
camera.addComponent<CameraComponent>();
if (this->activeCamera == entt::null) {
this->activeCamera = camera;
}
return camera;
}
Entity Scene::getActiveCamera() {
if (this->activeCamera == entt::null) {
return {};
}
return {this->activeCamera, this};
}
void Scene::setActiveCamera(Entity camera) { this->activeCamera = camera; }
void Scene::destroyEntity(Entity entity) {
if (this->activeCamera == entity) {
this->activeCamera = entt::null;