我正在游戏过程中执行以下C ++代码(除此之外一切运行正常),我在渲染时没有运行它:
MetaBalls::MetaBalls() : largeTexture(NULL), metaballsShader(NULL), smallTexture(NULL), smallFBO(0), largeFBO(0) {
// 1. Compile shader that will render small texture onto larger texture using blur threshold
CRender::Instance()->CreateShader("Shaders/metaballs.fs", "Shaders/metaballs.vs", &metaballsShader);
metaballsShader->_locations["projview"] = glGetUniformLocation(metaballsShader->_program, "projview");
// 4. Load the sprite that will be rendered as particles on the small texture
// TODO: batch render this
m_metaballSprite.InitSprite("Embellishments/particle.png", OFFSCREEN);
// 2. Create new texture and 2 frame buffers
// First frame buffer to render small texture, second frame buffer to scale small texture up into big one
glGenTextures(1, &smallTexture);
glBindTexture(GL_TEXTURE_2D, smallTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8_OES, SMALL_TEX_W, SMALL_TEX_H, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// 3. Create second larger texture to contain final water textured (rendered in game as sprite)
glGenTextures(1, &largeTexture);
glBindTexture(GL_TEXTURE_2D, largeTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8_OES, LARGE_TEX_W, LARGE_TEX_H, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// 5. Attach small texture to frame buffer
glGenFramebuffers(1, &smallFBO);
glBindFramebuffer(GL_FRAMEBUFFER, smallFBO);
glBindTexture(GL_TEXTURE_2D, smallTexture);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, smallTexture, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
s3eDebugErrorShow(S3E_MESSAGE_CONTINUE_STOP, "Metaballs small framebuffer incomplete");
}
// 6. Attach large texture to other frame buffer
glGenFramebuffers(1, &largeFBO);
glBindFramebuffer(GL_FRAMEBUFFER, largeFBO);
glBindTexture(GL_TEXTURE_2D, largeTexture);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, largeTexture, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
s3eDebugErrorShow(S3E_MESSAGE_CONTINUE_STOP, "Metaballs small framebuffer incomplete");
}
// 7. Build geometry for small frame buffer
float w = PTM_DOWNSCALE(SMALL_TEX_W);
float h = PTM_DOWNSCALE(SMALL_TEX_H);
CRender::Instance()->BuildQuad(
tVertex( b2Vec3(0,0,0), b2Vec2(0,1) ),
tVertex( b2Vec3(w,0,0), b2Vec2(1,1) ),
tVertex( b2Vec3(w,h,0), b2Vec2(1,0) ),
tVertex( b2Vec3(0,h,0), b2Vec2(0,0) ),
smallBuffer);
// 8. Build geometry for large frame buffer
w = PTM_DOWNSCALE(SMALL_TEX_W);
h = PTM_DOWNSCALE(SMALL_TEX_H);
CRender::Instance()->BuildQuad(
tVertex( b2Vec3(0,0,0), b2Vec2(0,1) ),
tVertex( b2Vec3(w,0,0), b2Vec2(1,1) ),
tVertex( b2Vec3(w,h,0), b2Vec2(1,0) ),
tVertex( b2Vec3(0,h,0), b2Vec2(0,0) ),
largeBuffer);
// return to default state
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
我的问题是我收到OpenGL ES 2.0报告的错误:
GL Error GL_INVALID_OPERATION on entry to function glGenFramebuffers(1, 0xd8450e8)
如果我在函数开头附近切换上述opengl调用的顺序,我可以在glGenTextures行,glBindFramebuffer或者在第一个CreateShader函数内执行的glCreateProgram()中得到GL_INVALID_OPERATION。虽然使用当前的调用顺序,着色器正在加载和编译。
我得到的错误打破了opengl.org上这些调用的记录结果,例如,如果你传递glGenFrameBuffers没有返回的非零值,glGenFramebuffers应该只返回GL_INVALID_OPERATION。但是,我检查了从glGenFrameBuffers返回的整数......它们是2和3.因为我已经有了第三个帧缓冲区elseware,所以没有错。我也尝试同时生成纹理和帧缓冲区,但它们会生成相同的GLuint,并且会出现相同的错误。
知道怎么可能导致这个错误?我在这个类中运行的类似代码在过去没问题。