title: How to obtain raw (unconverted) texture data in OpenGL?
body: <p>I need to serialise an arbitrary OpenGL texture object to be able to restore it later with the <em>exact</em> same state and data.</p>
  
  <p>I'm looking for a way to get the texture image data. Here's what I've found so far:</p>
  
  <ul>
  <li><p>There's <code>glGetTexImage</code>. </p>
  
  <p>It allows to gets the texture image, but it requires a specified format/type pair (like  (<code>GL_RGB</code>,&nbsp;<code>GL_HALF_FLOAT</code>) to which it performs a conversion.</p>
  
  <p>The allowed formats and types don't map 1:1 to image formats though, and won't allow to get more obscure formats like <code>GL_R3_G3_B2</code> without additional conversion.</p>
  
  <p>Also correctly determining the C type for base internal formats (like <code>GL_RGB</code> with no size) involves some non-trivial labour.</p></li>
  <li><p>There's <code>ARB_internalformat_query2</code> that allows to ask for <code>GL_GET_TEXTURE_IMAGE_FORMAT</code> and <code>GL_GET_TEXTURE_IMAGE_TYPE</code> which represent the best choices for <code>glGetTexImage</code> for a given texture.</p>
  
  <p>Nice, but suffers from the same limitations as <code>glGetTexImage</code> and isn't widely available.</p></li>
  <li><p>There's the wonderful <code>glGetCompressedTexImage</code> that elegantly returns the compressed texture's data as-is, but it neither works for non-compressed images nor has a counterpart that would.</p></li>
  </ul>
  
  <p>None of these allows to get or set raw data for non-compressed textures. Is there a way?</p>