CSCI441 OpenGL Library 6.1.0.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
FramebufferUtils.hpp
Go to the documentation of this file.
1
14#ifndef CSCI441_FRAMEBUFFER_UTILS_HPP
15#define CSCI441_FRAMEBUFFER_UTILS_HPP
16
17#include "constants.h"
18#include "LogUtils.hpp"
19
20#ifdef CSCI441_USE_GLEW
21 #include <GL/glew.h>
22#else
23 #include <glad/gl.h>
24#endif
25
26#include <cstdio>
27
28//**********************************************************************************
29
30namespace CSCI441 {
31
36 namespace FramebufferUtils {
37
43 [[maybe_unused]] void printFramebufferInfo( GLenum target, GLuint fbo );
44
50 [[maybe_unused]] void printFramebufferStatusMessage( GLenum target, GLuint fbo );
51
56 void printFramebufferStatusMessage( GLenum target );
57 }
58}
59
60//**********************************************************************************
61//**********************************************************************************
62// Outward facing function implementations
63
64[[maybe_unused]]
65inline void CSCI441::FramebufferUtils::printFramebufferInfo( const GLenum target, const GLuint fbo ) {
66 int res, i = 0;
67 GLint buffer;
68
69 if(glIsFramebuffer(fbo)) {
70 glBindFramebuffer( target, fbo );
71
72 do {
73 glGetIntegerv( GL_DRAW_BUFFER0 + i, &buffer );
74 if( buffer != GL_NONE ) {
75 CSCI441::LogUtils::log("[FBO]: Shader Output Location %d -> color attachment %d\n", i, buffer - GL_COLOR_ATTACHMENT0 );
76 glGetFramebufferAttachmentParameteriv( target, buffer, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &res );
77 CSCI441::LogUtils::log("[FBO]: \tAttachment Type: %s\n", res == GL_TEXTURE ? "Texture" : "Render Buffer" );
78 glGetFramebufferAttachmentParameteriv( target, buffer, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &res );
79 CSCI441::LogUtils::log("[FBO]: \tAttachment object name: %d\n", res );
80 }
81 ++i;
82 } while( buffer != GL_NONE );
83 } else {
84 CSCI441::LogUtils::logError("[FBO]: Error: %d is not a framebuffer\n", fbo);
85 }
86}
87
88[[maybe_unused]]
89inline void CSCI441::FramebufferUtils::printFramebufferStatusMessage( const GLenum target, const GLuint fbo ) {
90 if(glIsFramebuffer(fbo)) {
91 glBindFramebuffer( target, fbo );
93 } else {
94 CSCI441::LogUtils::logError("[FBO]: Error: %d is not a framebuffer\n", fbo);
95 }
96}
97
99 GLenum status = glCheckFramebufferStatus( target );
100 if( status == GL_FRAMEBUFFER_COMPLETE )
101 CSCI441::LogUtils::log("[FBO]: Framebuffer initialized completely!\n" );
102 else {
103 CSCI441::LogUtils::logError("[FBO]: Framebuffer failed to initialize completely 0x%x.\n", status );
104
105 switch(status) {
106 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
107 CSCI441::LogUtils::logError("[FBO]: An attachment could not be bound to framebuffer object!\n");
108 break;
109
110 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
111 CSCI441::LogUtils::logError("[FBO]: Attachments are missing! At least one image (texture) must be bound to the framebuffer object!\n");
112 break;
113
114 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
115 CSCI441::LogUtils::logError("[FBO]: The dimensions of the buffers attached to the currently used framebuffer object do not match!\n");
116 break;
117
118 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
119 CSCI441::LogUtils::logError("[FBO]: The formats of the currently used framebuffer object are not supported or do not fit together!\n");
120 break;
121
122 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
123 CSCI441::LogUtils::logError("[FBO]: A Draw buffer is incomplete or undefined. All draw buffers must specify attachment points that have images attached.\n");
124 break;
125
126 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
127 CSCI441::LogUtils::logError("[FBO]: A Read buffer is incomplete or undefined. All read buffers must specify attachment points that have images attached.\n");
128 break;
129
130 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
131 CSCI441::LogUtils::logError("[FBO]: All images must have the same number of multisample samples.\n");
132 break;
133
134 case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS :
135 CSCI441::LogUtils::logError("[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");
136 break;
137
138 case GL_FRAMEBUFFER_UNSUPPORTED:
139 CSCI441::LogUtils::logError("[FBO]: Attempt to use an unsupported format combination!\n");
140 break;
141
142 default:
143 CSCI441::LogUtils::logError("[FBO]: Unknown error while attempting to create framebuffer object!\n");
144 break;
145 }
146 }
147}
148
149#endif // CSCI441_FRAMEBUFFER_UTILS_HPP
void printFramebufferInfo(GLenum target, GLuint fbo)
Prints the framebuffer information for the FBO attached to the corresponding target.
Definition: FramebufferUtils.hpp:65
void printFramebufferStatusMessage(GLenum target, GLuint fbo)
Prints the framebuffer status for the FBO attached to the corresponding target.
Definition: FramebufferUtils.hpp:89
void log(const char *MSG,...)
log a message to both the standard output stream and file
Definition: LogUtils.hpp:116
void logError(const char *MSG,...)
log a message to both the standard error stream and file
Definition: LogUtils.hpp:128
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17
OpenGL Framebuffer Utility functions.