我收到一个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
答案 0 :(得分: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 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).
谢谢@ Rabbid76和@solidpixel。我相信所有评论对其他人都会有用。干杯:-)