Question

Running any of the "Sample" projects that come with MonoGame will result in "MonoGameGLException". This occurs in the Texture2D constructor at the following code..

GL.CompressedTexImage2D(TextureTarget.Texture2D, 0, glInternalFormat,
    this.width, this.height, 0,
    imageSize, IntPtr.Zero);
GraphicsExtensions.CheckGLError(); <-- Error here

The value for "glInternalFormat" is:

OpenTK.Graphics.OpenGL.PixelInternalFormat.CompressedRgbaS3tcDxt3Ext

This occurs on Ubuntu Linux running on an Intel integrated graphics card.

Was it helpful?

Solution

TL;DR

This is an error that is caused because the OpenGL implementation (Mesa) does not contain support for the internal texture format (S3TC). Install the libtxc_dxtn library to add this functionality to Mesa.

The Problem

OpenGL is the graphics API that MonoGame uses to render graphics. Since OpenGL is just an API, you need some implementation of that API in order to have it work on your system. If you had an NVIDIA or ATI card, you could download their proprietary drivers (which include closed-source implementations of the OpenGL API). If you are not using their proprietary drivers (or are using a card like Intel graphics card that has open source drivers), then you are probably running Mesa, which is an open-source implementation of the OpenGL API standard.

OpenGL has a base standard, but it also has many extensions. One of these extensions is EXT_texture_compression_s3tc. This is an extension that allows the user to specify that the textures we are loading into the graphics card should be compressed using a specific algorithm of the S3TC family of algorithms. That is what the "GL.CompressedTexImage2D" line actually does: it requests that we make room for a texture that will be compressed using the DXT3 algorithm.

Mesa does not implement ALL of the OpenGL API and list of extensions. Specifically, they do not implement the S3TC extension (due to legal reasons).

"Invalid Enum" is the error that Mesa is throwing because you are trying to tell Mesa to use an extension (as specified by the enumerated value PixelInternalFormat.CompressedRgbaS3tcDxt3Ext) that Mesa does not support. This is the standard way an OpenGL implementation tells you that you are referring to an unsupported value.

The Solution

So, there are two options to fix this:

First, workaround MonoGame so that it stops using S3TC. This might require changing MonoGame code, or perhaps there is a better way using the ContentPipeline to specify what texture compression algorithm to use.

Second, install the S3TC algorithm. While Mesa does not include S3TC by default, you can include an external library for Mesa. More details on the Mesa Wiki S3TC page. Mesa needed to be built with a specific compiler flag, and then the library needs to be installed. In my Ubuntu install (12.04), I'm assuming that the Mesa package did have this flag enabled when compiling, since installing the library worked well. In Ubuntu, I installed the libtxc-dxtn-s2tc0 package.

sudo apt-get install libtxc-dxtn-s2tc0

After that, all the MonoGame samples were working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top