1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
import moderngl
import pytest
def test_framebuffer_color_attachment(ctx):
rbo = ctx.renderbuffer((16, 16))
ctx.framebuffer(rbo)
def test_framebuffer_get_color_attachments(ctx):
rbo1 = ctx.renderbuffer((16, 16))
rbo2 = ctx.renderbuffer((16, 16))
rbo3 = ctx.renderbuffer((16, 16))
fbo1 = ctx.framebuffer(rbo1)
fbo2 = ctx.framebuffer([rbo2, rbo1])
fbo3 = ctx.framebuffer([rbo1, rbo2, rbo3])
assert len(fbo1.color_attachments) == 1
assert len(fbo2.color_attachments) == 2
assert len(fbo3.color_attachments) == 3
assert isinstance(fbo1.color_attachments[0], moderngl.Renderbuffer)
assert isinstance(fbo2.color_attachments[0], moderngl.Renderbuffer)
assert isinstance(fbo2.color_attachments[1], moderngl.Renderbuffer)
assert isinstance(fbo3.color_attachments[0], moderngl.Renderbuffer)
assert isinstance(fbo3.color_attachments[1], moderngl.Renderbuffer)
assert isinstance(fbo3.color_attachments[2], moderngl.Renderbuffer)
assert rbo1 in fbo1.color_attachments
assert rbo2 in fbo2.color_attachments
assert rbo2 in fbo3.color_attachments
assert rbo2 not in fbo1.color_attachments
assert rbo3 not in fbo1.color_attachments
assert rbo3 not in fbo2.color_attachments
def test_framebuffer_get_depth_attachment(ctx):
rbo1 = ctx.renderbuffer((16, 16))
rbo2 = ctx.depth_renderbuffer((16, 16))
fbo1 = ctx.framebuffer(rbo1)
fbo2 = ctx.framebuffer(rbo1, rbo2)
assert fbo1.depth_attachment is None
assert isinstance(fbo2.depth_attachment, moderngl.Renderbuffer)
assert fbo1.depth_attachment != rbo2
assert fbo2.depth_attachment == rbo2
def test_framebuffer_color_mask(ctx):
fbo = ctx.framebuffer(ctx.renderbuffer((16, 16)))
assert fbo.color_mask == (True, True, True, True)
def test_framebuffer_single_channel_color_mask(ctx):
fbo = ctx.framebuffer(ctx.renderbuffer((16, 16), components=1))
assert fbo.color_mask == (True, True, True, True)
def test_framebuffer_mixed_channels_color_mask(ctx):
fbo = ctx.framebuffer([
ctx.renderbuffer((16, 16), components=1),
ctx.renderbuffer((16, 16), components=2),
ctx.renderbuffer((16, 16), components=3),
ctx.renderbuffer((16, 16), components=4),
])
expected = (
(True, True, True, True),
(True, True, True, True),
(True, True, True, True),
(True, True, True, True),
)
assert fbo.color_mask == expected
def test_framebuffer_depth_mask_1(ctx):
fbo = ctx.framebuffer(
ctx.renderbuffer((16, 16)),
ctx.depth_renderbuffer((16, 16)),
)
assert fbo.depth_mask is True
def test_framebuffer_depth_mask_2(ctx):
fbo = ctx.framebuffer(
ctx.renderbuffer((16, 16))
)
assert fbo.depth_mask is False
def test_framebuffer_color_attachments(ctx):
rbo1 = ctx.renderbuffer((16, 16))
rbo2 = ctx.renderbuffer((16, 16))
rbo3 = ctx.renderbuffer((16, 16))
ctx.framebuffer([rbo1, rbo2, rbo3])
def test_framebuffer_multiple_color_masks(ctx):
fbo = ctx.framebuffer([
ctx.renderbuffer((16, 16)),
ctx.renderbuffer((16, 16)),
])
expected = ((True, True, True, True), (True, True, True, True))
assert fbo.color_mask == expected
def test_framebuffer_size_mismatch(ctx):
with pytest.raises(moderngl.Error):
rbo1 = ctx.renderbuffer((16, 16))
rbo2 = ctx.depth_renderbuffer((32, 32))
ctx.framebuffer(rbo1, rbo2)
def test_framebuffer_color_attachments_size_mismatch(ctx):
with pytest.raises(moderngl.Error):
rbo1 = ctx.renderbuffer((16, 16))
rbo2 = ctx.renderbuffer((32, 32))
ctx.framebuffer([rbo1, rbo2])
def test_depth_framebuffer(ctx):
rbo1 = ctx.renderbuffer((16, 16))
rbo2 = ctx.depth_renderbuffer((16, 16))
ctx.framebuffer(rbo1, rbo2)
def test_framebuffer_multisample(ctx):
if ctx.max_samples < 2:
pytest.skip('multisampling is not supported')
rbo1 = ctx.renderbuffer((16, 16), samples=2)
ctx.framebuffer(rbo1)
def test_depth_framebuffer_multisample(ctx):
if ctx.max_samples < 2:
pytest.skip('multisampling is not supported')
rbo1 = ctx.renderbuffer((16, 16), samples=2)
rbo2 = ctx.depth_renderbuffer((16, 16), samples=2)
ctx.framebuffer(rbo1, rbo2)
def test_framebuffer_multisample_sample_mismatch(ctx):
if ctx.max_samples < 2:
pytest.skip('multisampling is not supported')
with pytest.raises(moderngl.Error):
rbo1 = ctx.renderbuffer((16, 16))
rbo2 = ctx.depth_renderbuffer((16, 16), samples=2)
ctx.framebuffer(rbo1, rbo2)
def test_empty_framebuffer(ctx):
with pytest.raises(moderngl.Error):
ctx.framebuffer([])
def test_framebuffer_having_depth_in_colors(ctx):
with pytest.raises(moderngl.Error):
ctx.framebuffer(ctx.depth_renderbuffer((16, 16)))
def test_framebuffer_having_color_in_depth(ctx):
with pytest.raises(moderngl.Error):
ctx.framebuffer(
ctx.renderbuffer((16, 16)),
ctx.renderbuffer((16, 16)),
)
|