0

我收到 EGL 错误:EGL 错误:类型 = 0x824c,严重性 = 0x9146,消息 =“纹理资源为 NULL,未指定级别”

在下面的前 3 行代码中为 texId1 执行 glTextSubImage 时出现此错误。texId2 上没有错误。想知道是否有其他人对这个错误可能是什么有任何想法?

此错误在 debugMessagecallback 中可见,并且关联的 glGetError() 是 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

4

1 回答 1

0

好的,这就是发生的事情,因此选择这个作为这篇文章的自我回答。我创建纹理的统一代码,我还尝试将其默认为白色。我通过分配 m_tex = Texture2D.whiteTexture 来做到这一点。目的是做类似 m_tex.whiteTexture; 这是不允许的,所以最终在我做的地方:-)

在幕后看起来 Unity 正在对我意外重新创建的 Texture2D.whiteTexture 使用 glTexStorage2D() 调用,使其不可变。我必须调整原始 tex 的大小这一事实对我来说应该很明显,我得到了一个新的纹理而不是颜色变化,但我专注于解释本机代码中的 gl 调用和错误代码。评论这些 whiteTexture 并调整大小后不再出现 gl 错误:

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();

还有一点需要注意的是,我继续使用 glTexSubImage2D 调用,其中 pixeldata 在与上述原始帖子相同的调用中传递。我不使用 glTexImage。我猜 Unity 在所有纹理创建上都使用ARB_texture_storage 扩展,从而使这些纹理不可变。这是扩展程序的注释:

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).

谢谢@Rabbid76 和@solidpixel。我相信所有的评论都会对其他人有用。干杯:-)

于 2019-04-15T23:33:16.403 回答