Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
RenderTarget.h
Go to the documentation of this file.
1/**
2 * @file RenderTarget.h
3 * @ingroup mnd_graphics
4 * @brief Offscreen FBO with colour, view-normal and depth attachments.
5 *
6 * Used to implement the engine's "internal resolution" pixelation
7 * effect. Render the scene at a small size (e.g. 320x240) into the
8 * RenderTarget, then BlitNearest() it into the window framebuffer. The
9 * non-filtered upscale produces crisp PSX-era chunky pixels.
10 *
11 * The second colour attachment receives view-space normals encoded as
12 * `N*0.5+0.5` (RGBA8) so the outline post-pass can do depth+normal edge
13 * detection. Depth is a sampleable texture rather than a renderbuffer
14 * for the same reason.
15 */
16
17#pragma once
18
19#include "GL/glew.h"
20
21namespace mnd
22{
23
24/**
25 * @ingroup mnd_graphics
26 * @brief Offscreen FBO with MRT colour + sampleable depth for low-resolution rendering.
27 *
28 * Attachment layout matches lit_pixel.frag:
29 * COLOR_ATTACHMENT0 -> shaded RGBA8 colour
30 * COLOR_ATTACHMENT1 -> view-space normals (encoded N*0.5+0.5, RGBA8)
31 * DEPTH_ATTACHMENT -> DEPTH_COMPONENT24 texture (sampleable)
32 */
34{
35public:
36 bool Create(int w, int h);
37 void Resize(int w, int h);
38 void Destroy();
39
40 void Bind();
41 static void BindDefault(int winW, int winH);
42
43 GLuint ColorTex() const { return m_color; }
44 GLuint NormalTex() const { return m_normal; }
45 GLuint DepthTex() const { return m_depth; }
46 int Width() const { return m_w; }
47 int Height() const { return m_h; }
48 bool IsValid() const { return m_fbo != 0; }
49
50private:
51 GLuint m_fbo = 0;
52 GLuint m_color = 0;
53 GLuint m_normal = 0;
54 GLuint m_depth = 0;
55 int m_w = 0;
56 int m_h = 0;
57};
58
59/// Blit modes for BlitNearest.
60enum class BlitMode : int
61{
62 Color = 0, ///< Sample RGB straight through (default).
63 SplatRed = 1, ///< Output (r,r,r,1) — used for visualising depth.
64 DecodeNrm = 2, ///< Output rgb as-is from a packed-normal texture (no remap).
65};
66
67/// Fullscreen nearest-neighbor blit of a 2D texture into the currently bound framebuffer.
68/// Lazily compiles its own vertex-less shader on first call. Safe to call every frame.
69void BlitNearest(GLuint srcTexture, int dstW, int dstH, BlitMode mode = BlitMode::Color);
70
71} // namespace mnd
unsigned int GLuint
Definition GLForward.h:11
Offscreen FBO with MRT colour + sampleable depth for low-resolution rendering.
int Width() const
int Height() const
static void BindDefault(int winW, int winH)
bool IsValid() const
GLuint NormalTex() const
GLuint DepthTex() const
bool Create(int w, int h)
void Resize(int w, int h)
GLuint ColorTex() const
BlitMode
Blit modes for BlitNearest.
@ SplatRed
Output (r,r,r,1) — used for visualising depth.
@ DecodeNrm
Output rgb as-is from a packed-normal texture (no remap).
@ Color
Sample RGB straight through (default).
void BlitNearest(GLuint srcTexture, int dstW, int dstH, BlitMode mode)