From 7bdc2b2627ce22ccab493175d8f24bb819d97295 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 4 Mar 2022 14:07:31 -0800 Subject: [PATCH] viewport API update --- content/Graphics/CommandBuffer/_index.md | 11 ++++ content/Graphics/Intro.md | 2 +- .../GraphicsPipeline/ViewportState.md | 59 ------------------- .../Resources/GraphicsPipeline/_index.md | 1 - 4 files changed, 12 insertions(+), 61 deletions(-) delete mode 100644 content/Graphics/Resources/GraphicsPipeline/ViewportState.md diff --git a/content/Graphics/CommandBuffer/_index.md b/content/Graphics/CommandBuffer/_index.md index 7d1d408..8a0a44c 100644 --- a/content/Graphics/CommandBuffer/_index.md +++ b/content/Graphics/CommandBuffer/_index.md @@ -71,6 +71,17 @@ Note that if you use multiple graphics pipelines that all share a render pass, y Note that the graphics pipeline must be *compatible* with the current render pass. +## Viewport and Scissor State + +If you wish, you can set a custom viewport and scissor area. These will apply until the render pass ends or you set them again. + +```cs +myCommandBuffer.SetViewport(myViewport); +myCommandBuffer.SetScissor(myScissorArea); +``` + +These commands are completely optional - if you do not set them, the viewport and scissor will be set to the size of the smallest texture in the render pass. + ## Binding Buffers ```cs diff --git a/content/Graphics/Intro.md b/content/Graphics/Intro.md index a9aae57..cec55c4 100644 --- a/content/Graphics/Intro.md +++ b/content/Graphics/Intro.md @@ -4,7 +4,7 @@ date: 2021-01-24T20:54:00-08:00 weight: 1 --- -If the other MoonWorks tools have seemed simple so far, MoonWorks.Graphics may surprise you. Graphics is implemented using the [Refresh](https://gitea.moonside.games/MoonsideGames/Refresh) library. Refresh is based on Vulkan, an industry-standard cross-platform graphics API. It provides no "standard" rendering system that you can easily hook into, unlike what you may be used to with an engine like Unity. In order to render to the screen, you will need to set up some Shader Modules, a Graphics Pipeline, and provide vertex data to be rendered through the pipeline. +If the other MoonWorks tools have seemed simple so far, MoonWorks.Graphics may surprise you. Graphics is implemented using the [Refresh](https://gitea.moonside.games/MoonsideGames/Refresh) library. Refresh is based on Vulkan, an industry-standard cross-platform graphics API. It provides no "standard" rendering system that you can easily hook into, unlike what you may be used to with an engine like Unity. In order to render to the screen, you will need to set up a Texture, some Shader Modules, a Graphics Pipeline, and provide vertex data to be rendered through the pipeline. This might sound complicated, and I can't deny that, yeah, it's complicated. But everything is complicated at first. I promise to walk you through it as best I can, and once you understand how the pipeline works, you will have total control over your rendering and you will be able to create extremely high performance games that look exactly how you want. diff --git a/content/Graphics/Resources/GraphicsPipeline/ViewportState.md b/content/Graphics/Resources/GraphicsPipeline/ViewportState.md deleted file mode 100644 index 9313775..0000000 --- a/content/Graphics/Resources/GraphicsPipeline/ViewportState.md +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: "Viewport State" -date: 2021-01-28T13:20:55-08:00 -weight: 8 ---- - -The viewport state describes the dimensions of the viewport, which is an area of the framebuffer that will be rendered to. - -You define a viewport array like so: - -```cs -var myViewport = new Viewport -{ - X = 0, - Y = 0, - W = 1280, - H = 720, - MinDepth = 0, - MaxDepth = 1 -}; - -var myViewports = new Viewport[] { myViewport }; -``` - -This creates a 1280x720 viewport originating at the top-left corner with depth ranging from 0 to 1. - -You may provide multiple viewports. This can be handy for cases like, for example, rendering a picture-in-picture style mode. Postmodern! - -You also need to provide a "scissor rectangle". This is another way to reduce the number of pixels that will be rendered. When you define a scissor rectangle, any pixels outside of the rectangle are discarded. - -In this example, we want to render to the entire viewport, so we define a scissor rectangle with the same dimensions as the viewport. - -```cs -var myScissorRectangle = new Rect -{ - X = 0, - Y = 0, - W = 1280, - H = 720 -}; - -var myScissors = new Rect[] { myScissorRectangle }; -``` - -Finally we hand off these arrays to the ViewportState struct: - -```cs -var myViewportState = new ViewportState -{ - Viewports = myViewports, - Scissors = myScissors; -} -``` - -In many cases just want to provide viewport dimensions and not worry about the scissor. We have a shortcut for that! - -```cs -var myViewportState = new ViewportState(1280, 720); -``` diff --git a/content/Graphics/Resources/GraphicsPipeline/_index.md b/content/Graphics/Resources/GraphicsPipeline/_index.md index 90568d2..7225351 100644 --- a/content/Graphics/Resources/GraphicsPipeline/_index.md +++ b/content/Graphics/Resources/GraphicsPipeline/_index.md @@ -16,7 +16,6 @@ A graphics pipeline needs the following information in order to generate: * Multisample State * Rasterizer State * Primitive Type -* Viewport State * Blend Constants Whew, that's a lot! Let's break it down one thing at a time.