Robinson
Robinson

Reputation: 10122

glUnmapBuffer - return value and error code

Looking at glUnmapBuffer at the moment, according to some docs it returns GLboolean to indicate success (GL_TRUE) or failure (GL_FALSE). Presumably if it fails it sets the GL error.

My question is under what circumstances you would need to check to see if it returned with GL_TRUE in release builds, assuming you're checking glGetError after every OpenGL call in debug builds?

Or rather, why would this function need to return a bool success/fail when other OpenGL functions do not? I'm looking for the organising principle here, i.e. can it sometimes return GL_FALSE without having set the gl error?

EDIT:

OK, I found the answer. Not sure whether to leave this up because it's interesting. On this page:

"Because of its low-level nature, these protections have to be relaxed. Therefore, it is possible that, during the time a buffer is mapped, some kind of corruption happens. If this occurs, calling glUnmapBuffer​ will return GL_FALSE. At that point, the contents of the buffer in question are considered undefined. It may have your data, or it may have random garbage."

So as I'm specifying Windows 7 or later, I don't need to consider it (I think). Ironically, one of the reasons I switched out of Direct 3D into OpenGL was precisely this (with Direct 3D 9.0).

Upvotes: 3

Views: 462

Answers (1)

Bartek Banachewicz
Bartek Banachewicz

Reputation: 39380

Because it's not a regular OpenGL error:

(...) This can occur for system-specific reasons that affect the availability of graphics memory, such as screen mode changes. In such situations, GL_FALSE is returned and the data store contents are undefined. An application must detect this rare condition and reinitialize the data store.

This special mechanism was undoubtfully introduced to separate such cases from typical user interaction errors caught by glGetError.

Upvotes: 3

Related Questions