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