mozilla

Revision 94149 of Debugging OpenGL

  • Revision slug: Debugging/Debugging_OpenGL
  • Revision title: Debugging OpenGL
  • Revision id: 94149
  • Created:
  • Creator: JoeDrew
  • Is current revision? No
  • Comment 1 words added, 2 words removed
Tags: 

Revision Content

{{ gecko_minversion_header("2.0") }}

For various reasons, debugging OpenGL related code can be tricky. This article provides suggestions for how to improve your efficiency while debugging OpenGL code in Gecko.

OpenGL debug mode

When running a debug build, you can enable the OpenGL debug mode by defining the environment variable MOZ_GL_DEBUG. If you start up Firefox with this variable defined, the following behavior changes occur:

  • Each time you issue an OpenGL call, a check is performed to ensure that the GL context is current, using a thread-local static variable to keep track of this. If the context isn't current, the call aborts.
  • Every time an OpenGL call completes, glFinish() gets run automatically. This flushes out each call, essentially turning OpenGL into a synchronous API. This makes debugging crashes caused by an OpenGL call much easier, since the stack you see will match where the call was issued, rather than some time in the future when it happens to run and crash.
  • If an OpenGL error occurred when executing the call, an error message is output.

If you need more verbose debug output, you can enable the verbose debug mode by defining the environment variable MOZ_GL_DEBUG_VERBOSE. With this enabled, messages are printed before and after every OpenGL call. This can help make it much easier to debug crashes and hangs that make the computer unusable (thereby stymieing attempts to debug).

The MOZ_GL_DEBUG_ABORT_ON_ERROR environment variable, if set, causes Firefox to abort as soon as an OpenGL error occurs. This is generally only useful in cases where you know that no error should occur, since there are cases where perfectly valid WebGL code may generate OpenGL errors.

You don't have to define more than one of these; for example, if you set MOZ_GL_DEBUG_ABORT_ON_ERROR, the MOZ_GL_DEBUG setting is assumed.

See also

Revision Source

<p>{{ gecko_minversion_header("2.0") }}</p>
<p>For various reasons, debugging <a class=" external" href="http://www.opengl.org/" title="http://www.opengl.org/">OpenGL</a> related code can be tricky. This article provides suggestions for how to improve your efficiency while debugging OpenGL code in Gecko.</p>
<h2 id="OpenGL debug_mode">OpenGL debug mode</h2>
<p>When running a <a class=" external" href="http://ftp.mozilla.org/pub/mozilla.org/firefox/tinderbox-builds/" title="http://ftp.mozilla.org/pub/mozilla.org/firefox/tinderbox-builds/">debug build</a>, you can enable the OpenGL debug mode by defining the environment variable <code>MOZ_GL_DEBUG</code>. If you start up Firefox with this variable defined, the following behavior changes occur:</p>
<ul> <li>Each time you issue an OpenGL call, a check is performed to ensure that the GL context is current, using a thread-local static variable to keep track of this. If the context isn't current, the call aborts.</li> <li>Every time an OpenGL call completes, <a class=" external" href="http://www.opengl.org/sdk/docs/man4/xhtml/glFinish.xml" title="http://www.opengl.org/sdk/docs/man4/xhtml/glFinish.xml"><code>glFinish()</code></a> gets run automatically. This flushes out each call, essentially turning OpenGL into a synchronous API. This makes debugging crashes caused by an OpenGL call much easier, since the stack you see will match where the call was issued, rather than some time in the future when it happens to run and crash.</li> <li>If an OpenGL error occurred when executing the call, an error message is output.</li>
</ul>
<p>If you need more verbose debug output, you can enable the verbose debug mode by defining the environment variable <code>MOZ_GL_DEBUG_VERBOSE</code>. With this enabled, messages are printed before and after every OpenGL call. This can help make it much easier to debug crashes and hangs that make the computer unusable (thereby stymieing attempts to debug).</p>
<p>The <code>MOZ_GL_DEBUG_ABORT_ON_ERROR</code> environment variable, if set, causes Firefox to abort as soon as an OpenGL error occurs. This is generally only useful in cases where you know that no error should occur, since there are cases where perfectly valid WebGL code may generate OpenGL errors.</p>
<p>You don't have to define more than one of these; for example, if you set <code>MOZ_GL_DEBUG_ABORT_ON_ERROR</code>, the <code>MOZ_GL_DEBUG</code> setting is assumed.</p>
<h2 id="See_also">See also</h2>
<ul> <li><a href="/en/WebGL" title="en/WebGL">WebGL</a></li> <li><a href="/En/Debugging" title="en/Debugging">Debugging</a></li>
</ul>
Revert to this revision