Skip to content

Commit 2f5eb16

Browse files
committed
Started on simple deferred renderer
1 parent bef9a9d commit 2f5eb16

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Find more efficient OpenGL bindings. ModernGL (https://pypi.python.org/pypi/ModernGL)
55
don't have a binary distribution for darwin.
66

7-
- Runtime re-loading of shaders
7+
- Framebuffer Blitting
88
- Properly verify all settings
99
- Make EffectControllers
1010
- TrackSystemEffectController

demosys/deferred/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .renderer import DeferredRenderer # noqa

demosys/deferred/renderer.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from demosys.opengl import FBO
2+
from demosys.opengl import Texture
3+
from OpenGL import GL
4+
5+
6+
class DeferredRenderer:
7+
8+
def __init__(self, width, height, gbuffer=None, lightbuffer=None):
9+
self.gbuffer = gbuffer
10+
self.lightbuffer = lightbuffer
11+
12+
# FIXME: We might want double buffering here as well
13+
# Create geometry buffer if not supplied
14+
if not self.gbuffer:
15+
self.gbuffer = FBO()
16+
# RGBA color attachment
17+
self.gbuffer.add_color_attachment(
18+
Texture.create_2d(width=width, height=height,
19+
internal_format=GL.GL_RGBA8, format=GL.GL_RGBA,
20+
min_filter=GL.GL_NEAREST, mag_filter=GL.GL_NEAREST,
21+
wrap_s=GL.GL_CLAMP_TO_EDGE, wrap_t=GL.GL_CLAMP_TO_EDGE)
22+
)
23+
# 16 bit RGB float buffer for normals
24+
self.gbuffer.add_color_attachment(
25+
Texture.create_2d(width=width, height=height,
26+
format=GL.GL_RGB, internal_format=GL.GL_RGB16F, type=GL.GL_FLOAT,
27+
min_filter=GL.GL_NEAREST, mag_filter=GL.GL_NEAREST,
28+
wrap_s=GL.GL_CLAMP_TO_EDGE, wrap_t=GL.GL_CLAMP_TO_EDGE)
29+
)
30+
# 24 bit depth, 8 bit stencil
31+
self.gbuffer.set_depth_attachment(
32+
Texture.create_2d(width=width, height=height,
33+
internal_format=GL.GL_DEPTH24_STENCIL8, format=GL.GL_DEPTH_COMPONENT,
34+
min_filter=GL.GL_NEAREST, mag_filter=GL.GL_NEAREST,
35+
wrap_s=GL.GL_CLAMP_TO_EDGE, wrap_t=GL.GL_CLAMP_TO_EDGE, wrap_r=GL.GL_CLAMP_TO_EDGE)
36+
)
37+
if not self.lightbuffer:
38+
self.lightbuffer = FBO()
39+
# 8 bit light accumulation buffer
40+
self.lightbuffer.add_color_attachment(
41+
Texture.create_2d(width=width, height=height,
42+
internal_format=GL.GL_RED, format=GL.GL_RED, type=GL.GL_UNSIGNED_BYTE,
43+
min_filter=GL.GL_NEAREST, mag_filter=GL.GL_NEAREST,
44+
wrap_s=GL.GL_CLAMP_TO_EDGE, wrap_t=GL.GL_CLAMP_TO_EDGE)
45+
)
46+
# Attach the same depth buffer as the geometry buffer
47+
self.lightbuffer.set_depth_attachment(self.gbuffer.depth_buffer)
48+
49+
def render_geometry(self):
50+
pass

0 commit comments

Comments
 (0)