-
Notifications
You must be signed in to change notification settings - Fork 3
/
FramebufferUtils.hpp
146 lines (120 loc) · 5.41 KB
/
FramebufferUtils.hpp
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
/**
* @file FramebufferUtils.hpp
* @brief Helper functions to work with OpenGL Framebuffer
* @author Dr. Jeffrey Paone
*
* @copyright MIT License Copyright (c) 2020 Dr. Jeffrey Paone
*
* These functions, classes, and constants help minimize common
* code that needs to be written.
*
* @warning This header file depends upon GLAD (or alternatively GLEW)
*/
#ifndef CSCI441_FRAMEBUFFER_UTILS_HPP
#define CSCI441_FRAMEBUFFER_UTILS_HPP
#ifdef CSCI441_USE_GLEW
#include <GL/glew.h>
#else
#include <glad/gl.h>
#endif
#include <cstdio>
//**********************************************************************************
namespace CSCI441 {
/**
* @namespace FramebufferUtils
* @brief OpenGL Framebuffer Utility functions
*/
namespace FramebufferUtils {
/**
* @brief Prints the framebuffer information for the FBO attached to the corresponding target
* @param target framebuffer target to bind named framebuffer to
* @param fbo name of a framebuffer object
*/
[[maybe_unused]] void printFramebufferInfo( GLenum target, GLuint fbo );
/**
* @brief Prints the framebuffer status for the FBO attached to the corresponding target
* @param target framebuffer target to bind named framebuffer to
* @param fbo name of a framebuffer object
*/
[[maybe_unused]] void printFramebufferStatusMessage( GLenum target, GLuint fbo );
/**
* @brief Prints the framebuffer status for the FBO currently attached to the corresponding target
* @param target framebuffer target to check status of bound framebuffer
*/
void printFramebufferStatusMessage( GLenum target );
}
}
//**********************************************************************************
//**********************************************************************************
// Outward facing function implementations
[[maybe_unused]]
inline void CSCI441::FramebufferUtils::printFramebufferInfo( const GLenum target, const GLuint fbo ) {
int res, i = 0;
GLint buffer;
if(glIsFramebuffer(fbo)) {
glBindFramebuffer( target, fbo );
do {
glGetIntegerv( GL_DRAW_BUFFER0 + i, &buffer );
if( buffer != GL_NONE ) {
printf( "[FBO]: Shader Output Location %d -> color attachment %d\n", i, buffer - GL_COLOR_ATTACHMENT0 );
glGetFramebufferAttachmentParameteriv( target, buffer, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &res );
printf( "[FBO]: \tAttachment Type: %s\n", res == GL_TEXTURE ? "Texture" : "Render Buffer" );
glGetFramebufferAttachmentParameteriv( target, buffer, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &res );
printf( "[FBO]: \tAttachment object name: %d\n", res );
}
++i;
} while( buffer != GL_NONE );
} else {
fprintf(stderr, "[FBO]: Error: %d is not a framebuffer\n", fbo);
}
}
[[maybe_unused]]
inline void CSCI441::FramebufferUtils::printFramebufferStatusMessage( const GLenum target, const GLuint fbo ) {
if(glIsFramebuffer(fbo)) {
glBindFramebuffer( target, fbo );
printFramebufferStatusMessage(target);
} else {
fprintf(stderr, "[FBO]: Error: %d is not a framebuffer\n", fbo);
}
}
inline void CSCI441::FramebufferUtils::printFramebufferStatusMessage( const GLenum target ) {
GLenum status = glCheckFramebufferStatus( target );
if( status == GL_FRAMEBUFFER_COMPLETE )
printf( "[FBO]: Framebuffer initialized completely!\n" );
else {
fprintf( stderr, "[FBO]: Framebuffer failed to initialize completely 0x%x.\n", status );
switch(status) {
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
fprintf(stderr, "[FBO]: An attachment could not be bound to framebuffer object!\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
fprintf(stderr, "[FBO]: Attachments are missing! At least one image (texture) must be bound to the framebuffer object!\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
fprintf(stderr, "[FBO]: The dimensions of the buffers attached to the currently used framebuffer object do not match!\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
fprintf(stderr, "[FBO]: The formats of the currently used framebuffer object are not supported or do not fit together!\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
fprintf(stderr, "[FBO]: A Draw buffer is incomplete or undefined. All draw buffers must specify attachment points that have images attached.\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
fprintf(stderr, "[FBO]: A Read buffer is incomplete or undefined. All read buffers must specify attachment points that have images attached.\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
fprintf(stderr, "[FBO]: All images must have the same number of multisample samples.\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS :
fprintf(stderr, "[FBO]: If a layered image is attached to one attachment, then all attachments must be layered attachments. The attached layers do not have to have the same number of layers, nor do the layers have to come from the same kind of texture.\n");
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
fprintf(stderr, "[FBO]: Attempt to use an unsupported format combination!\n");
break;
default:
fprintf(stderr, "[FBO]: Unknown error while attempting to create framebuffer object!\n");
break;
}
}
}
#endif // CSCI441_FRAMEBUFFER_UTILS_HPP