I'm having some problems porting my D3D code to OpenGL ES. I have a Graphics Device class that encapsulates all rendering commands. The code below is in an ObjC++ file.
The problem code is the called to get the render buffer width and height. It doesn't actually return any value in the w or h GLints.
It should be noted that the code below is from an older iPhone project, and it works there. Am I missing something really stupid?
Checking the framebuffer status returns a value of complete, since OpenGL ES seems quite happy to initialize a depth buffer with the garbage w and h values I pass to it!
bool GraphicsDevice::Initialize(id<EAGLDrawable> eaglLayer)
{
EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if(context == nil)
{
return false;
}
[EAGLContext setCurrentContext:context];
this->eaglContext = context;
glGenFramebuffers(1, &frameBuffer);
glBindBuffer(GL_FRAMEBUFFER, frameBuffer);
glGenRenderbuffers(1, &renderBuffer);
glBindBuffer(GL_RENDERBUFFER, renderBuffer);
[eaglContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer];
GLint w, h;
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &w);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &h);
SetWidth(static_cast<unsigned int>(w));
SetHeight(static_cast<unsigned int>(h));
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBuffer);
glGenRenderbuffers(1, &depthBuffer);
glBindBuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
System::Log("Framebuffer not complete");
return false;
}
return true;
}