Skip to content

Commit 6023b34

Browse files
committed
renderer: Figure out attachment points with switch command.
1 parent ce1adf2 commit 6023b34

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

libopenage/renderer/opengl/framebuffer.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017-2024 the openage authors. See copying.md for legal info.
1+
// Copyright 2017-2025 the openage authors. See copying.md for legal info.
22

33
#include "framebuffer.h"
44

@@ -30,26 +30,42 @@ GlFramebuffer::GlFramebuffer(const std::shared_ptr<GlContext> &context,
3030

3131
glBindFramebuffer(GL_FRAMEBUFFER, handle);
3232

33-
std::vector<GLenum> drawBuffers;
33+
std::vector<GLenum> draw_buffers;
3434

3535
if (textures.empty()) {
3636
throw Error{ERR << "At least 1 texture must be assigned to texture framebuffer."};
3737
}
3838

39-
size_t colorTextureCount = 0;
39+
size_t color_texture_count = 0;
40+
size_t depth_texture_count = 0;
4041
for (auto const &texture : textures) {
41-
// TODO figure out attachment points from pixel formats
42-
if (texture->get_info().get_format() == resources::pixel_format::depth24) {
42+
auto fmt = texture->get_info().get_format();
43+
switch (fmt) {
44+
case resources::pixel_format::depth24:
45+
depth_texture_count += 1;
46+
if (depth_texture_count > 1) {
47+
log::log(WARN << "Framebuffer already has one depth texture attached. "
48+
<< "Assignment of additional depth texture ignored.");
49+
break;
50+
}
4351
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture->get_handle(), 0);
44-
}
45-
else {
46-
auto attachmentPoint = GL_COLOR_ATTACHMENT0 + colorTextureCount++;
47-
glFramebufferTexture2D(GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, texture->get_handle(), 0);
48-
drawBuffers.push_back(attachmentPoint);
52+
break;
53+
case resources::pixel_format::r16ui:
54+
case resources::pixel_format::r32ui:
55+
case resources::pixel_format::rgba8:
56+
case resources::pixel_format::rgb8:
57+
case resources::pixel_format::bgr8:
58+
case resources::pixel_format::rgba8ui: {
59+
auto attachment_point = GL_COLOR_ATTACHMENT0 + color_texture_count++;
60+
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment_point, GL_TEXTURE_2D, texture->get_handle(), 0);
61+
draw_buffers.push_back(attachment_point);
62+
} break;
63+
default:
64+
throw Error{ERR << "Unsupported pixel format for framebuffer texture."};
4965
}
5066
}
5167

52-
glDrawBuffers(drawBuffers.size(), drawBuffers.data());
68+
glDrawBuffers(draw_buffers.size(), draw_buffers.data());
5369

5470
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
5571
throw Error(MSG(err) << "Could not create OpenGL framebuffer.");

0 commit comments

Comments
 (0)