Garry's Mod Wiki

Revision Difference

render_rendertargets#561261

<cat>Don'tListMePlease Dev</cat> <title>Render Reference - Render Targets</title> # Render Library References⤶ ⤶ <note>This page is under active development and should not be read by anyone, let alone people other than the author</note>⤶ ⤶ # Render Library References⤶ These pages seek to provide helpful insight into the groups of functions provided by the <page text="Render Library">render</page>. The major function groups are: * <page text="Beams">Beam_Rendering</page> * <page text="Minification and Magnification Texture Filters">render_min_mag_filters</page> * **Render Targets** # Render Targets ## A Note on Layout⤶ This page is laid out with the intention of first building understanding of the concepts, then only once that understanding exists do we introduce the code side. Feel free to read the page in whatever way helps you understand the contents best.⤶ ⤶ # What are Render Targets?⤶ **A Render Target is a special kind of image** that is created during gameplay via the game's code, rather than a pre-existing image that is loaded from the game's files. ⤶ ## Some Basic Facts⤶ ⤶ Render Targets, because they are fundamentally just images, have a fixed resolution, measured in pixels, that is defined when they are first created. ⤶ ⤶ **Render Targets have a fixed resolution, measured in pixels**, that is defined when they are first created. ⤶ Unless your specific use-case has a reason not to, it's recommended to use the game's render resolution (Obtained via <page text="ScrW">Global.ScrW</page> and <page text="ScrH">Global.ScrH</page>.) ⤶ Each Render Target is comprised of three (3) parts:⤶ 1. The Color Channel 2. The Depth Buffer⤶ 3. The Stencil Buffer⤶ ⤶ ## The Color Channel⤶ The Color Channel (or simply "Color") is what is visible on the Render Target. Very simply, this is what you would see if you drew the Render Target onto the screen. ⤶ ## The Depth Buffer⤶ ## The Stencil Buffer ⤶ ## Each Render Target is comprised of three layers:⤶ ⤶ ## 1. The Color Channel The Color Channel (or simply "Color") is what is visible on the Render Target. This is what you would see if you drew the Render Target onto the screen. ⤶ ⤶ Generally speaking, each pixel in this layer contains 3 or 4 numbers representing the color (Red, green, and blue) and the alpha (or translucency/transparency.) ⤶ The specific contents of each pixel in this layer will depend on the <page text="Image Format">Enums/IMAGE_FORMAT</page> used when the Render Target is created.⤶ ⤶ By default each pixel of a Render Target's Color Channel contains 4 separate 8-bit whole, integer numbers containing values from 0-255 where each represents, in order, red, green, blue, and alpha. This is represented by the <page text="Image Format">Enums/IMAGE_FORMAT</page> enum `IMAGE_FORMAT_BGRA8888`⤶ ## 2. The Depth Buffer The Depth Buffer is an image the same ⤶ ⤶ ## 3. The Stencil Buffer⤶ ## How Render Targets are Used to Draw Frames Render Targets are used for anything that needs to be drawn dynamically, including the view you see while playing the game. Internally, the engine creates two two Render Targets (Called "Frame Buffers") when the game starts. At any given time, one of these two Render Targets is considered "in front" and the other is considered "in back". When your monitor asks for a frame to draw, the game sends it whatever is in the Front Render Target. Meanwhile, the game renders the next frame to the Back Render Target where it won't be seen by the player. When the next frame is finished, the two Render Targets are swapped (Called "Spinning") and the game starts sending the new Front Render Target to the monitor.