0

I get an EGL error: EGL ERROR: type = 0x824c, severity = 0x9146, message = "texture resource is NULL, no level was specified"

This error appears when executing glTextSubImage for texId1 in the first 3 lines of code below. No errors on the texId2. Wondering if anyone else has any ideas on what this error could be?

This error is visible in the debugMessagecallback and the associated glGetError() is GL_INVALID_OPERATION.

   //render loop
   glBindTexture(GL_TEXTURE_2D, (GLuint)texId1);
   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_textureWidth,    g_textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixelsdata1);

   glBindTexture(GL_TEXTURE_2D, 0); //unbind tex


   glBindTexture(GL_TEXTURE_2D, (GLuint)texId2);
   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_textureWidth,      g_textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixelsdata2);

   glBindTexture(GL_TEXTURE_2D, 0); //unbind tex

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
srf guy
  • 21
  • 2
  • Are you sure that you've specified the texture image `texId1` before, by `glTexImage2D`? – Rabbid76 Apr 14 '19 at 18:23
  • @Rabbifd76 I have tried various combinations: 1. With both glTexImage2D(with nullptr for pixeldata) and glTexSubImage2D calls as follows: ` glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, g_textureWidth, g_textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_textureWidth, g_textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata1); ` The glTexImage2D shows "unable to create level with an immutable texture" and the glGetError() is GL_INVALID_OPERATION after glTexImage2D call. – srf guy Apr 14 '19 at 18:55
  • 2. With just glTexImage2D call with pixeldata set as follows: `glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, g_textureWidth, g_textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelsdata2); //set pixeldata too` I see same errors - The glTexImage2D shows "unable to create level with an immutable texture" and the glGetError() is GL_INVALID_OPERATION after glTexImage2D call. – srf guy Apr 14 '19 at 19:00
  • Unity texture is created as follows which are updated in the native code: `m_tex = new Texture2D(1920, 1080, TextureFormat.RGBA32, false); m_tex.filterMode = FilterMode.Bilinear; m_tex = Texture2D.whiteTexture; m_tex.Resize(1920, 1080); m_tex.Apply();` – srf guy Apr 14 '19 at 19:02
  • @Rabbid76 let me know if you have suggestions based on the updates, the code in the first comment is as follows: `glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, g_textureWidth, g_textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, g_textureWidth, g_textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata1);` – srf guy Apr 14 '19 at 19:10
  • The error about immutability sounds like the game engine already allocated storage using `glTexStorage2D()`, and something about the new calls conflicts with that. You can't modify size or format of immutable storage once it's been created. Find when it was first backed with storage and post that please ... – solidpixel Apr 14 '19 at 23:43

1 Answers1

0

Okay here's what happened and thus picking this as the self-answer to this post. The unity code where I created the textures, I also tried to default it to white color. I did so by assigning m_tex = Texture2D.whiteTexture. The intent was to do something like m_tex.whiteTexture; which is not allowed so ended up where I did:-)

Under the hood looks like Unity is using glTexStorage2D() call on Texture2D.whiteTexture that I recreated accidentally, making it immutable. The very fact that I had to resize my original tex should made it obvious for me that I got a new texture instead of color change, but so much for my focus on interpreting gl calls and error codes in my native code. After commenting these whiteTexture and resize no more gl errors:

m_tex = new Texture2D(1920, 1080, TextureFormat.RGBA32, false);
m_tex.filterMode = FilterMode.Bilinear;

//m_tex = Texture2D.whiteTexture;
//m_tex.Resize(1920, 1080);
m_tex.Apply();

One more note I continue to use just the glTexSubImage2D call with pixeldata passed in the same call as in the original post above. I don't use glTexImage. I guess Unity is using ARB_texture_storage extension on all texture creation thus making these textures immutable. Here's the note from the extension:

When using this extension, it is no longer possible to supply texture
data using TexImage*. Instead, data can be uploaded using TexSubImage*,
or produced by other means (such as render-to-texture, mipmap generation,
or rendering to a sibling EGLImage).

ThankYou @Rabbid76 and @solidpixel. I am sure all the comments will useful for others. Cheers:-)

srf guy
  • 21
  • 2