{"id":59,"date":"2014-08-04T18:22:49","date_gmt":"2014-08-04T18:22:49","guid":{"rendered":"https:\/\/blogs.scummvm.org\/subr3v\/?p=59"},"modified":"2022-05-23T18:23:47","modified_gmt":"2022-05-23T18:23:47","slug":"dirty-rectangle-system-pt-4","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/subr3v\/2014\/08\/04\/dirty-rectangle-system-pt-4\/","title":{"rendered":"Dirty Rectangle System Pt 4"},"content":{"rendered":"<p>In the past week I&#8217;ve been working on the last two tasks for dirty rects:<br \/>\nThe first one was implementing a system that allowed to clip a draw call and only render a portion of what&#8217;s supposed to be drawn, I implemented this in three different ways, based on the type of the draw call:<\/p>\n<p>Blitting draw calls were implemented with a scissor rectangle logic inside the blitting module: this allows the clipping to be very fast as the clipped parts are skipped completely.<\/p>\n<p>Rasterization draw calls are implemented in a different way: this time the scissor rectangle function is implemented on a pixel level, which means that every pixel is checked to be within the scissor rect before being written to the color buffer: this allows the dirty rects system to ignore everything that is outside the dirty region and thus manages to not cover regions that shouldn&#8217;t be touched that frame.<\/p>\n<p>Clear buffers draw calls are clipped with a special function inside FrameBuffer that only clears a region of the screen instead of clearing everything.<\/p>\n<p>This covers the implementation of the first sub task: the second one was to detect which regions of the screen changed and output a list of rectangles that need to be updated.<\/p>\n<p>This task was implemented by keeping a copy of the previous frame draw calls and comparing the current frame draw calls with the previous one: this comparison tries to find the first difference between the two lists and then marks as dirty every rectangle that is covered by subsequent draw calls.<br \/>\nOnce this list is obtained with this method I also use a simple merging algorithm to avoid re-rendering of the same region with overlapping rectangles and also to reduce the number of draw calls.<\/p>\n<p>What happens after I have this information can be described with the following pseudocode:<\/p>\n<pre>foreach (drawCall in currentFrame.drawCalls) {\r\n    foreach (dirtyRegion in currentFrame.dirtyRegions) {\r\n        if (drawCall.dirtyRegion.intersects(dirtyRegion)) {\r\n           drawCall.execute(dirtyRegion);\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>There&#8217;s only one problem with this implementation: I have found that EMI intro sequence is not detected properly and causes some glitches whereas everything else works fine.<\/p>\n<p>From what I&#8217;ve seen though this method isn&#8217;t helping the overall engine performance by much: as most of the time is spent in 3D rasterization this system doesn&#8217;t cope well with animated models that change very frequently and fails to be effective.<\/p>\n<p>I will keep you updated with how this progresses in the next blog posts, stay tuned for more info!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the past week I&#8217;ve been working on the last two tasks for dirty rects: The first one was implementing a system that allowed to clip a draw call and only render a portion of what&#8217;s supposed to be drawn, I implemented this in three different ways, based on the type of the draw call: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":130,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts\/59\/revisions\/130"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}