Skip to content

Commit

Permalink
Naming cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel committed Mar 22, 2023
1 parent 6631bfb commit a0a86ee
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 74 deletions.
67 changes: 33 additions & 34 deletions src/glview/fbo.cc
Expand Up @@ -33,9 +33,9 @@ bool check_fbo_status()
GLenum status;
auto result = false;
if (use_ext()) {
status = GL_CHECK(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT), return false);
IF_GL_CHECK(status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)) return false;
} else {
status = GL_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER), return false);
IF_GL_CHECK(status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) return false;
}

if (status == GL_FRAMEBUFFER_COMPLETE) {
Expand Down Expand Up @@ -65,8 +65,8 @@ bool check_fbo_status()
bool fbo_ext_init(fbo_t *fbo, size_t width, size_t height)
{
// Generate and bind FBO
GL_CHECK(glGenFramebuffersEXT(1, &fbo->fbo_id), return false);
GL_CHECK(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo_id), return false);
IF_GL_CHECK(glGenFramebuffersEXT(1, &fbo->fbo_id)) return false;
IF_GL_CHECK(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo_id)) return false;

// Generate depth and render buffers
glGenRenderbuffersEXT(1, &fbo->depthbuf_id);
Expand All @@ -76,33 +76,32 @@ bool fbo_ext_init(fbo_t *fbo, size_t width, size_t height)
if (!fbo_resize(fbo, width, height)) return false;

// Attach render and depth buffers
GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, fbo->renderbuf_id),
return false);
IF_GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, fbo->renderbuf_id)) return false;

if (!check_fbo_status()) {
cerr << "Problem with OpenGL EXT framebuffer after specifying color render buffer.\n";
return false;
}

if (glewIsSupported("GL_EXT_packed_depth_stencil")) {
GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, fbo->depthbuf_id),
return false);
IF_GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, fbo->depthbuf_id))
return false;

GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, fbo->depthbuf_id),
return false);
IF_GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, fbo->depthbuf_id))
return false;

if (!check_fbo_status()) {
cerr << "Problem with OpenGL EXT framebuffer after specifying depth render buffer.\n";
return false;
}
} else {
cerr << "Warning: Cannot create stencil buffer (GL_EXT_packed_depth_stencil not supported)\n";
GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, fbo->depthbuf_id),
return false);
IF_GL_CHECK(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, fbo->depthbuf_id))
return false;

if (!check_fbo_status()) {
cerr << "Problem with OpenGL EXT framebuffer after specifying depth stencil render buffer.\n";
Expand All @@ -116,8 +115,8 @@ bool fbo_ext_init(fbo_t *fbo, size_t width, size_t height)
bool fbo_arb_init(fbo_t *fbo, size_t width, size_t height)
{
// Generate and bind FBO
GL_CHECK(glGenFramebuffers(1, &fbo->fbo_id), return false);
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fbo->fbo_id), return false);
IF_GL_CHECK(glGenFramebuffers(1, &fbo->fbo_id)) return false;
IF_GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fbo->fbo_id)) return false;

// Generate depth and render buffers
glGenRenderbuffers(1, &fbo->depthbuf_id);
Expand All @@ -127,9 +126,9 @@ bool fbo_arb_init(fbo_t *fbo, size_t width, size_t height)
if (!fbo_resize(fbo, width, height)) return false;

// Attach render and depth buffers
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, fbo->renderbuf_id),
return false);
IF_GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, fbo->renderbuf_id))
return false;

if (!check_fbo_status()) {
cerr << "Problem with OpenGL framebuffer after specifying color render buffer.\n";
Expand All @@ -141,9 +140,9 @@ bool fbo_arb_init(fbo_t *fbo, size_t width, size_t height)
// ie. instead of using GL_DEPTH_STENCIL_ATTACHMENT, do DEPTH then STENCIL.
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, fbo->depthbuf_id);
GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, fbo->depthbuf_id),
return false);
IF_GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, fbo->depthbuf_id))
return false;

if (!check_fbo_status()) {
cerr << "Problem with OpenGL framebuffer after specifying depth render buffer.\n";
Expand Down Expand Up @@ -182,24 +181,24 @@ bool fbo_resize(fbo_t *fbo, size_t width, size_t height)
if (use_ext()) {
glBindRenderbufferEXT(GL_RENDERBUFFER, fbo->depthbuf_id);
if (glewIsSupported("GL_EXT_packed_depth_stencil")) {
GL_CHECK(glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height),
return false);
IF_GL_CHECK(glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height))
return false;
} else {
GL_CHECK(glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height),
return false);
IF_GL_CHECK(glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height))
return false;
}

glBindRenderbufferEXT(GL_RENDERBUFFER, fbo->renderbuf_id);
GL_CHECK(glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA8, width, height),
return false);
IF_GL_CHECK(glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA8, width, height))
return false;
} else {
glBindRenderbuffer(GL_RENDERBUFFER, fbo->renderbuf_id);
GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height),
return false);
IF_GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height))
return false;

glBindRenderbuffer(GL_RENDERBUFFER, fbo->depthbuf_id);
GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height),
return false);
IF_GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height))
return false;

}

Expand Down
88 changes: 48 additions & 40 deletions src/glview/system-gl.h
Expand Up @@ -19,69 +19,77 @@ namespace {
bool glCheck(const char *stmt, const char *file, int line)
{
if (const auto err = glGetError(); err != GL_NO_ERROR) {
LOG(message_group::Error, Location::NONE, "",
"OpenGL error: %1$s (0x%2$04x) in %3$s:%4$d\n"
" %5$s\n", gluErrorString(err), err, file, line, stmt);
return false;
LOG(message_group::Error, Location::NONE, "",
"OpenGL error: %1$s (0x%2$04x) in %3$s:%4$d\n"
" %5$s\n", gluErrorString(err), err, file, line, stmt);
return false;
}
return true;
return true;
}

// Returns true on OK, false on error
// Returns true on OK, false on error
bool glCheckd(const char *stmt, const char *file, int line)
{
if (const auto err = glGetError(); err != GL_NO_ERROR) {
PRINTDB("OpenGL error: %s (0x%04x) in %s:%d\n"
" %s\n", gluErrorString(err) % err % file % line % stmt);
return false;
" %s\n", gluErrorString(err) % err % file % line % stmt);
return false;
}
return true;
return true;
}

} // namespace

// We have 3 different GL checks
// GL_DEBUG_CHECKD(statement, [onerror])
// Outputs PRINTDB() in debug mode only. Executes onerror statement on error, if given.
// This is fast in release mode (no-op if the onerror statement isn't provided).
// GL_CHECK(statement, onerror) Outputs LOG(Error) in both release and debug mode. Executes onerror statement on error
// We have 4 different GL checks:
// GL_CHECK(statement);
// Outputs LOG(Error) in both release and debug mode.
// Always prints the output on error.
// IF_GL_CHECK(statement) then_statement;
// Outputs LOG(Error) in both release and debug mode.
// Always prints the output on error.
// GL_CHECKD(statement, [onerror]) Outputs PRINTDB() in both release and debug mode. Executes onerror statement on error, if given
// Executes then_statement on error.
// GL_CHECKD(statement);
// Outputs PRINTDB() in both release and debug mode.
// Prints the output on error only if --debug is used
// GL_DEBUG_CHECKD(statement)
// Outputs PRINTDB() in debug mode only.
// This is fast in release mode (executes statement only).

// GL_CHECK(statement);
// Use this for important error output causes output on error, also in release mode.
//
// This example will print an error if glClear() fails:
// GL_CHECK(glClear());
#define GL_CHECK(stmt) stmt; glCheck(#stmt, __FILE__, __LINE__)

// IF_GL_CHECK(statement) then_statement;
// Use this for important error handling which always causes an error, also in release mode
//
// This example will print an error and return false if glClear() fails:
// IF_GL_CHECK(glClear()) return false;
#define IF_GL_CHECK(stmt) stmt; if (!glCheck(#stmt, __FILE__, __LINE__))

// GL_DEBUG_CHECKD(statement, [onerror])
// GL_CHECKD(statement);
// Use this for OpenGL debug error output which should make it into the release build
// Enable debug output at runtime using --enable=
// Note: This always checks glGetError(), so it will have performance implications.
//
// This example will print an error if glClear() fails, and if --debug is specified:
// GL_CHECKD(glClear());
#define GL_CHECKD(stmt) stmt; glCheckd(#stmt, __FILE__, __LINE__)

// GL_DEBUG_CHECKD(statement)
// Use this for OpenGL debug output which needs to be fast in release mode
// Debug output is only available for debug build and only when using --enable= at runtime
//
// This example will print an error if glClear() fails if --debug is specified, but yields just glClear in release mode.
// GL_DEBUG_CHECKD(glClear());
#ifdef DEBUG
#define GET_GL_DEBUG_CHECKD(_1, _2, NAME, ...) NAME
#define GL_DEBUG_CHECKD_ONLY(stmt) stmt; glCheckd(#stmt, __FILE__, __LINE__)
#define GL_DEBUG_CHECKD_ERR(stmt, onerror) stmt; if (!glCheckd(#stmt, __FILE__, __LINE__)) { onerror; }
#define GL_DEBUG_CHECKD(...) GET_GL_CHECKD(__VA_ARGS__, GL_DEBUG_CHECKD_ERR, GL_DEBUG_CHECKD_ONLY)(__VA_ARGS__)
#define GL_DEBUG_CHECKD(stmt) stmt; glCheckd(#stmt, __FILE__, __LINE__)
#else
#define GET_GL_DEBUG_CHECKD(_1, _2, NAME, ...) NAME
#define GL_DEBUG_CHECKD_ONLY(stmt) stmt
#define GL_DEBUG_CHECKD_ERR(stmt, onerror) stmt; if (glGetError != GL_NO_ERROR) { onerror; }
#define GL_DEBUG_CHECKD(...) GET_GL_CHECKD(__VA_ARGS__, GL_DEBUG_CHECKD_ERR, GL_DEBUG_CHECKD_ONLY)(__VA_ARGS__)
#define GL_DEBUG_CHECKD(stmt) stmt
#endif

// GL_CHECK(statement, onerror)
// Use this for important error handling which always causes an error, also in release mode
// This example will print an error and return false if glClear() fails:
// GL_CHECK(glClear(), return false);
#define GL_CHECK(stmt, onerror) stmt; if (!glCheck(#stmt, __FILE__, __LINE__)) { onerror; }

// GL_CHECKD(statement, [onerror])
// Use this for OpenGL debug error output which should make it into the release build
// Enable debug output at runtime using --enable=
// This example will print an error if --debug is specified and return if glClear() fails:
// GL_CHECK(glClear(), return);
#define GET_GL_CHECKD(_1, _2, NAME, ...) NAME
#define GL_CHECKD_ONLY(stmt) stmt; glCheckd(#stmt, __FILE__, __LINE__)
#define GL_CHECKD_ERR(stmt, onerror) stmt; if (!glCheckd(#stmt, __FILE__, __LINE__)) { onerror; }
#define GL_CHECKD(...) GET_GL_CHECKD(__VA_ARGS__, GL_CHECKD_ERR, GL_CHECKD_ONLY)(__VA_ARGS__)

#else // NULLGL

#define GLint int
Expand Down

0 comments on commit a0a86ee

Please sign in to comment.