Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions.

Both the extension (OES) and the core versions work, but the core versions are more correct for GLES2+ and they're less verbose.
This commit is contained in:
Alex Szpakowski 2014-10-28 01:34:40 -03:00
parent d89620a809
commit 28fe9f0cfc
3 changed files with 53 additions and 46 deletions

View File

@ -387,6 +387,9 @@ main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
/* create main window and renderer */ /* create main window and renderer */
window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
SDL_WINDOW_OPENGL | SDL_WINDOW_OPENGL |

View File

@ -21,8 +21,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h> #import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h> #import <OpenGLES/gltypes.h>
#import <OpenGLES/ES1/glext.h>
#import "SDL_uikitview.h" #import "SDL_uikitview.h"
/* /*
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.

View File

@ -24,6 +24,8 @@
#include <QuartzCore/QuartzCore.h> #include <QuartzCore/QuartzCore.h>
#include <OpenGLES/EAGLDrawable.h> #include <OpenGLES/EAGLDrawable.h>
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#include "SDL_uikitopenglview.h" #include "SDL_uikitopenglview.h"
#include "SDL_uikitmessagebox.h" #include "SDL_uikitmessagebox.h"
#include "SDL_uikitvideo.h" #include "SDL_uikitvideo.h"
@ -89,10 +91,15 @@
return nil; return nil;
} }
if (sRGB && UIKit_IsSystemVersionAtLeast(@"7.0")) { if (sRGB) {
/* sRGB EAGL drawable support was added in iOS 7 */ /* sRGB EAGL drawable support was added in iOS 7. */
if (UIKit_IsSystemVersionAtLeast(@"7.0")) {
colorFormat = kEAGLColorFormatSRGBA8; colorFormat = kEAGLColorFormatSRGBA8;
} else if (rBits >= 8 && gBits >= 8 && bBits >= 8) { } else {
SDL_SetError("sRGB drawables are not supported.");
return nil;
}
} else if (rBits >= 8 || gBits >= 8 || bBits >= 8) {
/* if user specifically requests rbg888 or some color format higher than 16bpp */ /* if user specifically requests rbg888 or some color format higher than 16bpp */
colorFormat = kEAGLColorFormatRGBA8; colorFormat = kEAGLColorFormatRGBA8;
} else { } else {
@ -113,50 +120,50 @@
self.contentScaleFactor = scale; self.contentScaleFactor = scale;
/* Create the color Renderbuffer Object */ /* Create the color Renderbuffer Object */
glGenRenderbuffersOES(1, &viewRenderbuffer); glGenRenderbuffers(1, &viewRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
if (![context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]) { if (![context renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer]) {
SDL_SetError("Failed creating OpenGL ES drawable"); SDL_SetError("Failed to create OpenGL ES drawable");
return nil; return nil;
} }
/* Create the Framebuffer Object */ /* Create the Framebuffer Object */
glGenFramebuffersOES(1, &viewFramebuffer); glGenFramebuffers(1, &viewFramebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
/* attach the color renderbuffer to the FBO */ /* attach the color renderbuffer to the FBO */
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
if ((useDepthBuffer) || (useStencilBuffer)) { if ((useDepthBuffer) || (useStencilBuffer)) {
if (useStencilBuffer) { if (useStencilBuffer) {
/* Apparently you need to pack stencil and depth into one buffer. */ /* Apparently you need to pack stencil and depth into one buffer. */
depthBufferFormat = GL_DEPTH24_STENCIL8_OES; depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
} else if (useDepthBuffer) { } else if (useDepthBuffer) {
/* iOS only has 24-bit depth buffers, even with GL_DEPTH_COMPONENT16_OES */ /* iOS only has 24-bit depth buffers, even with GL_DEPTH_COMPONENT16 */
depthBufferFormat = GL_DEPTH_COMPONENT24_OES; depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
} }
glGenRenderbuffersOES(1, &depthRenderbuffer); glGenRenderbuffers(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight); glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
if (useDepthBuffer) { if (useDepthBuffer) {
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
} }
if (useStencilBuffer) { if (useStencilBuffer) {
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
} }
} }
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) { if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
SDL_SetError("Failed creating OpenGL ES framebuffer"); SDL_SetError("Failed creating OpenGL ES framebuffer");
return nil; return nil;
} }
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
} }
return self; return self;
@ -174,25 +181,25 @@
- (void)updateFrame - (void)updateFrame
{ {
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
glDeleteRenderbuffersOES(1, &viewRenderbuffer); glDeleteRenderbuffers(1, &viewRenderbuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer); glGenRenderbuffers(1, &viewRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer]; [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
if (depthRenderbuffer != 0) { if (depthRenderbuffer != 0) {
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight); glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
} }
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
} }
- (void)setAnimationCallback:(int)interval - (void)setAnimationCallback:(int)interval
@ -236,16 +243,14 @@
[EAGLContext setCurrentContext:context]; [EAGLContext setCurrentContext:context];
} }
- (void)swapBuffers - (void)swapBuffers
{ {
/* viewRenderbuffer should always be bound here. Code that binds something /* viewRenderbuffer should always be bound here. Code that binds something
else is responsible for rebinding viewRenderbuffer, to reduce else is responsible for rebinding viewRenderbuffer, to reduce duplicate
duplicate state changes. */ state changes. */
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; [context presentRenderbuffer:GL_RENDERBUFFER];
} }
- (void)layoutSubviews - (void)layoutSubviews
{ {
[super layoutSubviews]; [super layoutSubviews];
@ -257,17 +262,17 @@
- (void)destroyFramebuffer - (void)destroyFramebuffer
{ {
if (viewFramebuffer != 0) { if (viewFramebuffer != 0) {
glDeleteFramebuffersOES(1, &viewFramebuffer); glDeleteFramebuffers(1, &viewFramebuffer);
viewFramebuffer = 0; viewFramebuffer = 0;
} }
if (viewRenderbuffer != 0) { if (viewRenderbuffer != 0) {
glDeleteRenderbuffersOES(1, &viewRenderbuffer); glDeleteRenderbuffers(1, &viewRenderbuffer);
viewRenderbuffer = 0; viewRenderbuffer = 0;
} }
if (depthRenderbuffer != 0) { if (depthRenderbuffer != 0) {
glDeleteRenderbuffersOES(1, &depthRenderbuffer); glDeleteRenderbuffers(1, &depthRenderbuffer);
depthRenderbuffer = 0; depthRenderbuffer = 0;
} }
} }