Skip to content

Commit 39707be

Browse files
committed
More ddoc in dagon.render
1 parent bf5e9fb commit 39707be

3 files changed

Lines changed: 127 additions & 1 deletion

File tree

src/dagon/render/deferred/gbuffer.d

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2525
DEALINGS IN THE SOFTWARE.
2626
*/
2727

28+
/**
29+
* G-buffer abstraction for deferred rendering.
30+
*
31+
* Description:
32+
* This module provides a lightweight wrapper around OpenGL framebuffer and
33+
* texture attachments used for deferred shading. The GBuffer class owns
34+
* render targets for color, depth, normal, material (PBR), emission, velocity,
35+
* and radiance output.
36+
*
37+
* Copyright: Timur Gafarov 2019-2026
38+
* License: $(LINK2 https://boost.org/LICENSE_1_0.txt, Boost License 1.0).
39+
* Authors: Timur Gafarov
40+
*/
2841
module dagon.render.deferred.gbuffer;
2942

3043
import std.stdio;
@@ -37,20 +50,53 @@ import dagon.core.bindings;
3750
import dagon.core.logger;
3851
import dagon.render.framebuffer;
3952

53+
/**
54+
* Manages the G-buffer attachments.
55+
*
56+
* The G-Buffer (Geometry buffer) is a set of fragment attribute buffers
57+
* used to store screen-space geometry data in a deferred renderer.
58+
*/
4059
class GBuffer: Owner
4160
{
61+
/// Current framebuffer width.
4262
uint width;
63+
64+
/// Current framebuffer height.
4365
uint height;
4466

67+
/// OpenGL framebuffer object handle.
4568
GLuint framebuffer;
69+
70+
/// Color render target.
4671
GLuint colorTexture = 0;
72+
73+
/// Depth-stencil render target.
4774
GLuint depthTexture = 0;
75+
76+
/// Eye-space normal render target.
4877
GLuint normalTexture = 0;
78+
79+
/// Roughness-Metallic render target.
4980
GLuint pbrTexture = 0;
81+
82+
/// Emission render target.
5083
GLuint emissionTexture = 0;
84+
85+
/// Screen-space velocity render target.
5186
GLuint velocityTexture = 0;
87+
88+
/// Radiance framebuffer that is also attached to this G-buffer.
5289
Framebuffer radiance;
5390

91+
/**
92+
* Creates a new GBuffer for the given size and radiance target.
93+
*
94+
* Params:
95+
* w = Width of the G-buffer.
96+
* h = Height of the G-buffer.
97+
* radiance = Framebuffer used for radiance output.
98+
* owner = Owner object.
99+
*/
54100
this(uint w, uint h, Framebuffer radiance, Owner owner)
55101
{
56102
super(owner);
@@ -61,6 +107,12 @@ class GBuffer: Owner
61107
createFramebuffer();
62108
}
63109

110+
/**
111+
* Initializes and configures the framebuffer and its texture attachments.
112+
*
113+
* Recreates the G-buffer textures and rebinds them to a new
114+
* framebuffer object. It also validates framebuffer completeness.
115+
*/
64116
void createFramebuffer()
65117
{
66118
releaseFramebuffer();
@@ -155,6 +207,7 @@ class GBuffer: Owner
155207
glBindFramebuffer(GL_FRAMEBUFFER, 0);
156208
}
157209

210+
/// Releases the framebuffer and texture resources owned by this GBuffer.
158211
void releaseFramebuffer()
159212
{
160213
if (glIsFramebuffer(framebuffer))
@@ -179,21 +232,25 @@ class GBuffer: Owner
179232
glDeleteTextures(1, &velocityTexture);
180233
}
181234

235+
/// Destructor that ensures OpenGL resources are cleaned up.
182236
~this()
183237
{
184238
releaseFramebuffer();
185239
}
186240

241+
/// Binds the G-buffer for drawing.
187242
void bind()
188243
{
189244
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
190245
}
191246

247+
/// Unbinds any draw framebuffer and returns to the default framebuffer.
192248
void unbind()
193249
{
194250
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
195251
}
196252

253+
/// Clears all G-buffer attachments.
197254
void clear()
198255
{
199256
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
@@ -214,6 +271,7 @@ class GBuffer: Owner
214271
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
215272
}
216273

274+
/// Resizes the G-buffer and recreates the framebuffer attachments.
217275
void resize(uint w, uint h)
218276
{
219277
width = w;

src/dagon/render/deferred/package.d

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2525
DEALINGS IN THE SOFTWARE.
2626
*/
2727

28+
/**
29+
* Deferred rendering package.
30+
*
31+
* This module exposes the deferred renderer, including G-buffer
32+
* and all the render passes used. It serves as the entry point for
33+
* configuring the renderer and connecting scene data to the pipeline.
34+
*/
2835
module dagon.render.deferred;
2936

3037
import dlib.core.memory;
@@ -47,6 +54,13 @@ public import dagon.render.deferred.gbuffer;
4754
import dagon.render.postproc.filterpass;
4855
import dagon.render.postproc.shaders.denoise;
4956

57+
/**
58+
* Deferred renderer implementation.
59+
*
60+
* The DeferredRenderer manages the shading pipeline, including
61+
* shadow pre-pass, geometry pre-pass, IBL, lighting, occlusion, etc.
62+
* It also owns the G-buffer and intermediate render targets.
63+
*/
5064
class DeferredRenderer: Renderer
5165
{
5266
Texture brdf;
@@ -82,6 +96,7 @@ class DeferredRenderer: Renderer
8296
float ssaoDenoise = 1.0f;
8397
bool ssaoDenoiseDepthAware = true;
8498

99+
/// Enables or disables screen-space ambient occlusion.
85100
void ssaoEnabled(bool mode) @property
86101
{
87102
_ssaoEnabled = mode;
@@ -99,23 +114,34 @@ class DeferredRenderer: Renderer
99114
}
100115
}
101116

117+
/// Returns screen-space ambient occlusion state.
102118
bool ssaoEnabled() @property
103119
{
104120
return _ssaoEnabled;
105121
}
106122

123+
/// Adjusts the resolution scale of the SSAO buffers.
107124
void occlusionBufferDetail(float value) @property
108125
{
109126
_occlusionBufferDetail = value;
110127
occlusionView.resize(cast(uint)(view.width * _occlusionBufferDetail), cast(uint)(view.height * _occlusionBufferDetail));
111128
occlusionNoisyBuffer.resize(occlusionView.width, occlusionView.height);
112129
occlusionBuffer.resize(occlusionView.width, occlusionView.height);
113130
}
131+
132+
/// Returns the resolution scale of the SSAO buffers.
114133
float occlusionBufferDetail() @property
115134
{
116135
return _occlusionBufferDetail;
117136
}
118137

138+
/**
139+
* Creates the deferred renderer and initializes all render passes.
140+
*
141+
* Params:
142+
* application = The Application instance.
143+
* owner = Owner object.
144+
*/
119145
this(Application application, Owner owner)
120146
{
121147
super(application, owner);
@@ -188,6 +214,7 @@ class DeferredRenderer: Renderer
188214
passParticles.gbuffer = gbuffer;
189215
}
190216

217+
/// Loads the default BRDF lookup texture from a stream.
191218
void loadDefaultBRDF(InputStream istrm)
192219
{
193220
if (brdf)
@@ -209,6 +236,7 @@ class DeferredRenderer: Renderer
209236
}
210237
}
211238

239+
/// Assigns scene reference to all the render passes.
212240
override void scene(Scene s)
213241
{
214242
passShadow.group = s.world.spatial;
@@ -227,6 +255,7 @@ class DeferredRenderer: Renderer
227255
pipeline.environment = s.environment;
228256
}
229257

258+
/// Updates renderer state each frame.
230259
override void update(Time t)
231260
{
232261
passShadow.camera = activeCamera;
@@ -240,6 +269,7 @@ class DeferredRenderer: Renderer
240269
super.update(t);
241270
}
242271

272+
/// Resizes the renderer viewport and all associated buffers.
243273
override void setViewport(uint x, uint y, uint w, uint h)
244274
{
245275
super.setViewport(x, y, w, h);

src/dagon/render/stereorenderer.d

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,70 @@ import dagon.resource.scene;
4646
class StereoRenderer: Renderer
4747
{
4848
alias headView = view;
49+
50+
/// Left eye render view.
4951
RenderView viewLeft;
52+
53+
/// Right eye render view.
5054
RenderView viewRight;
5155

56+
/// Left eye output framebuffer.
5257
Framebuffer outputBufferLeft;
58+
59+
/// Right eye output framebuffer.
5360
Framebuffer outputBufferRight;
5461

62+
/**
63+
* Sets the left eye active camera for rendering.
64+
*
65+
* Params:
66+
* camera = The camera to use.
67+
*/
5568
void activeCameraLeft(Camera camera)
5669
{
5770
viewLeft.camera = camera;
5871
}
5972

73+
/**
74+
* Returns the currently active left eye camera.
75+
*
76+
* Returns:
77+
* The active left eye camera.
78+
*/
6079
Camera activeCameraLeft()
6180
{
6281
return viewLeft.camera;
6382
}
6483

84+
/**
85+
* Sets the right eye active camera for rendering.
86+
*
87+
* Params:
88+
* camera = The camera to use.
89+
*/
6590
void activeCameraRight(Camera camera)
6691
{
6792
viewRight.camera = camera;
6893
}
6994

95+
/**
96+
* Returns the currently active right eye camera.
97+
*
98+
* Returns:
99+
* The active right eye camera.
100+
*/
70101
Camera activeCameraRight()
71102
{
72103
return viewRight.camera;
73104
}
74-
105+
106+
/**
107+
* Constructs a stereo renderer with the given application and owner.
108+
*
109+
* Params:
110+
* application = Application object.
111+
* owner = Owner object.
112+
*/
75113
this(Application application, Owner owner)
76114
{
77115
super(application, owner);

0 commit comments

Comments
 (0)