]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor handling of viewport Y axis
authorMikko Rasa <tdb@tdb.fi>
Sun, 12 Dec 2021 21:44:04 +0000 (23:44 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 12 Dec 2021 21:44:04 +0000 (23:44 +0200)
Only invert it for the swapchain render target.  This makes it easier to
sample render target textures consistently.

source/backends/vulkan/camera_backend.cpp
source/backends/vulkan/commands_backend.cpp
source/backends/vulkan/commands_backend.h
source/backends/vulkan/pipelinestate_backend.cpp
source/backends/vulkan/pipelinestate_backend.h

index 9eba4289ce1eb9166569ef1f6e01589c5abb3f99..10e294f7c66d4850886430083633e72d164087e7 100644 (file)
@@ -7,7 +7,6 @@ namespace GL {
 void VulkanCamera::adjust_projection_matrix(Matrix &proj_matrix)
 {
        Matrix adjust;
-       adjust(1, 1) = -1.0f;
        adjust(2, 2) = 0.5f;
        adjust(2, 3) = 0.5f;
        proj_matrix = adjust*proj_matrix;
index 643710d5aefeb103d7e3380f5c9f50423ce4ed4f..9c074c87da184e279c1a0d9b0120b74e0ed12324 100644 (file)
@@ -81,14 +81,14 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value
        Synchronizer &sync = device.get_synchronizer();
        sync.reset();
 
-       bool to_present = false;
+       fb_is_swapchain = false;
        unsigned n_attachments = framebuffer->get_format().size();
-       for(unsigned i=0; i<n_attachments; ++i)
+       for(unsigned i=0; (!fb_is_swapchain && i<n_attachments); ++i)
                if(dynamic_cast<const SwapChainTexture *>(framebuffer->get_attachment(i)))
-                       to_present = true;
-       if(!to_present)
+                       fb_is_swapchain = true;
+       if(!fb_is_swapchain)
                framebuffer->prepare_image_layouts(clear && !viewport);
-       VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, (!clear_values && !viewport), to_present);
+       VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, (!clear_values && !viewport), fb_is_swapchain);
 
        framebuffer->refresh();
 
@@ -102,7 +102,7 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value
        if(viewport)
        {
                begin_info.renderArea.offset.x = viewport->left;
-               begin_info.renderArea.offset.y = framebuffer->get_height()-(viewport->bottom+viewport->height);
+               begin_info.renderArea.offset.y = viewport->bottom;
                begin_info.renderArea.extent.width = viewport->width;
                begin_info.renderArea.extent.height = viewport->height;
        }
@@ -233,7 +233,7 @@ void VulkanCommands::draw_instanced(const Batch &batch, unsigned count)
                 begin_render_pass(false, 0);
 
        pipeline_state->refresh();
-       pipeline_state->apply(current_buffer);
+       pipeline_state->apply(current_buffer, fb_is_swapchain);
        unsigned first_index = batch.get_offset()/batch.get_index_size();
        vk.CmdDrawIndexed(current_buffer, batch.size(), count, first_index, 0, 0);
 }
index a89225a6f6cdaa82279ec08e444e500b79789161..994acca2df342cea6724c4812cd923f3ed34bd3f 100644 (file)
@@ -42,6 +42,7 @@ protected:
        const PipelineState *pipeline_state = 0;
        const Framebuffer *framebuffer = 0;
        const Rect *viewport = 0;
+       bool fb_is_swapchain = false;
 
        VulkanCommands();
        ~VulkanCommands();
index 419a7e4c149545b3de9ce19cd211da7bef5e563d..a1a03d3d8fcb31d2646027036bb4936a237d4194 100644 (file)
@@ -356,7 +356,7 @@ unsigned VulkanPipelineState::fill_descriptor_writes(unsigned index, vector<char
        return n_writes;
 }
 
-void VulkanPipelineState::apply(VkCommandBuffer command_buffer) const
+void VulkanPipelineState::apply(VkCommandBuffer command_buffer, bool negative_viewport) const
 {
        const PipelineState &self = *static_cast<const PipelineState *>(this);
        const VulkanFunctions &vk = device.get_functions();
@@ -387,7 +387,7 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer) const
        if(self.viewport)
        {
                viewport.x = self.viewport->left;
-               viewport.y = self.framebuffer->get_height()-(self.viewport->bottom+self.viewport->height);
+               viewport.y = self.viewport->bottom;
                viewport.width = self.viewport->width;
                viewport.height = self.viewport->height;
        }
@@ -398,6 +398,11 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer) const
                viewport.width = self.framebuffer->get_width();
                viewport.height = self.framebuffer->get_height();
        }
+       if(negative_viewport)
+       {
+               viewport.y += viewport.height;
+               viewport.height = -viewport.height;
+       }
        viewport.minDepth = 0.0f;
        viewport.maxDepth = 1.0f;
        vk.CmdSetViewport(command_buffer, 0, 1, &viewport);
@@ -406,7 +411,7 @@ void VulkanPipelineState::apply(VkCommandBuffer command_buffer) const
        if(self.scissor)
        {
                scissor.offset.x = self.scissor->left;
-               scissor.offset.y = self.framebuffer->get_height()-(self.scissor->bottom+self.scissor->height);
+               scissor.offset.y = self.scissor->bottom;
                scissor.extent.width = self.scissor->width;
                scissor.extent.height = self.scissor->height;
        }
index e675ff335c8cf311ad59cc9fe013e27804a4b0c0..19f7f902d1e7257ba4430a4dd7d7af8b9244a12d 100644 (file)
@@ -33,7 +33,7 @@ protected:
        VkDescriptorSetLayout get_descriptor_set_layout(unsigned) const;
        unsigned fill_descriptor_writes(unsigned, std::vector<char> &) const;
 
-       void apply(VkCommandBuffer) const;
+       void apply(VkCommandBuffer, bool) const;
 };
 
 using PipelineStateBackend = VulkanPipelineState;