|
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. |
2 | 2 |
|
3 | 3 | #include "framebuffer.h"
|
4 | 4 |
|
@@ -30,26 +30,42 @@ GlFramebuffer::GlFramebuffer(const std::shared_ptr<GlContext> &context,
|
30 | 30 |
|
31 | 31 | glBindFramebuffer(GL_FRAMEBUFFER, handle);
|
32 | 32 |
|
33 |
| - std::vector<GLenum> drawBuffers; |
| 33 | + std::vector<GLenum> draw_buffers; |
34 | 34 |
|
35 | 35 | if (textures.empty()) {
|
36 | 36 | throw Error{ERR << "At least 1 texture must be assigned to texture framebuffer."};
|
37 | 37 | }
|
38 | 38 |
|
39 |
| - size_t colorTextureCount = 0; |
| 39 | + size_t color_texture_count = 0; |
| 40 | + size_t depth_texture_count = 0; |
40 | 41 | 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 | + } |
43 | 51 | 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."}; |
49 | 65 | }
|
50 | 66 | }
|
51 | 67 |
|
52 |
| - glDrawBuffers(drawBuffers.size(), drawBuffers.data()); |
| 68 | + glDrawBuffers(draw_buffers.size(), draw_buffers.data()); |
53 | 69 |
|
54 | 70 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
55 | 71 | throw Error(MSG(err) << "Could not create OpenGL framebuffer.");
|
|
0 commit comments