viewport API update
continuous-integration/drone/push Build is passing Details

main
cosmonaut 2022-03-04 14:07:31 -08:00
parent 63c1bc1e52
commit 7bdc2b2627
4 changed files with 12 additions and 61 deletions

View File

@ -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

View File

@ -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.

View File

@ -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);
```

View File

@ -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.