Switched to the core versions of OpenGL ES framebuffer object and renderbuffer functions. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Tue, 28 Oct 2014 01:34:40 -0300
branchiOS-improvements
changeset 95206a655264dd47
parent 9519 37ade10d4570
child 9521 4c218c80b34d
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.
Xcode-iOS/Demos/src/fireworks.c
src/video/uikit/SDL_uikitopenglview.h
src/video/uikit/SDL_uikitopenglview.m
     1.1 --- a/Xcode-iOS/Demos/src/fireworks.c	Fri Oct 24 04:06:45 2014 -0300
     1.2 +++ b/Xcode-iOS/Demos/src/fireworks.c	Tue Oct 28 01:34:40 2014 -0300
     1.3 @@ -387,6 +387,9 @@
     1.4      SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
     1.5      SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
     1.6  
     1.7 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
     1.8 +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
     1.9 +
    1.10      /* create main window and renderer */
    1.11      window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
    1.12                                  SDL_WINDOW_OPENGL |
     2.1 --- a/src/video/uikit/SDL_uikitopenglview.h	Fri Oct 24 04:06:45 2014 -0300
     2.2 +++ b/src/video/uikit/SDL_uikitopenglview.h	Tue Oct 28 01:34:40 2014 -0300
     2.3 @@ -21,8 +21,7 @@
     2.4  
     2.5  #import <UIKit/UIKit.h>
     2.6  #import <OpenGLES/EAGL.h>
     2.7 -#import <OpenGLES/ES1/gl.h>
     2.8 -#import <OpenGLES/ES1/glext.h>
     2.9 +#import <OpenGLES/gltypes.h>
    2.10  #import "SDL_uikitview.h"
    2.11  /*
    2.12      This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
     3.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Fri Oct 24 04:06:45 2014 -0300
     3.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Tue Oct 28 01:34:40 2014 -0300
     3.3 @@ -24,6 +24,8 @@
     3.4  
     3.5  #include <QuartzCore/QuartzCore.h>
     3.6  #include <OpenGLES/EAGLDrawable.h>
     3.7 +#include <OpenGLES/ES2/gl.h>
     3.8 +#include <OpenGLES/ES2/glext.h>
     3.9  #include "SDL_uikitopenglview.h"
    3.10  #include "SDL_uikitmessagebox.h"
    3.11  #include "SDL_uikitvideo.h"
    3.12 @@ -89,10 +91,15 @@
    3.13              return nil;
    3.14          }
    3.15  
    3.16 -        if (sRGB && UIKit_IsSystemVersionAtLeast(@"7.0")) {
    3.17 -             /* sRGB EAGL drawable support was added in iOS 7 */
    3.18 -            colorFormat = kEAGLColorFormatSRGBA8;
    3.19 -        } else if (rBits >= 8 && gBits >= 8 && bBits >= 8) {
    3.20 +        if (sRGB) {
    3.21 +            /* sRGB EAGL drawable support was added in iOS 7. */
    3.22 +            if (UIKit_IsSystemVersionAtLeast(@"7.0")) {
    3.23 +                colorFormat = kEAGLColorFormatSRGBA8;
    3.24 +            } else {
    3.25 +                SDL_SetError("sRGB drawables are not supported.");
    3.26 +                return nil;
    3.27 +            }
    3.28 +        } else if (rBits >= 8 || gBits >= 8 || bBits >= 8) {
    3.29              /* if user specifically requests rbg888 or some color format higher than 16bpp */
    3.30              colorFormat = kEAGLColorFormatRGBA8;
    3.31          } else {
    3.32 @@ -113,50 +120,50 @@
    3.33          self.contentScaleFactor = scale;
    3.34  
    3.35          /* Create the color Renderbuffer Object */
    3.36 -        glGenRenderbuffersOES(1, &viewRenderbuffer);
    3.37 -        glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    3.38 +        glGenRenderbuffers(1, &viewRenderbuffer);
    3.39 +        glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
    3.40  
    3.41 -        if (![context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:eaglLayer]) {
    3.42 -            SDL_SetError("Failed creating OpenGL ES drawable");
    3.43 +        if (![context renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer]) {
    3.44 +            SDL_SetError("Failed to create OpenGL ES drawable");
    3.45              return nil;
    3.46          }
    3.47  
    3.48          /* Create the Framebuffer Object */
    3.49 -        glGenFramebuffersOES(1, &viewFramebuffer);
    3.50 -        glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    3.51 +        glGenFramebuffers(1, &viewFramebuffer);
    3.52 +        glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
    3.53  
    3.54          /* attach the color renderbuffer to the FBO */
    3.55 -        glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
    3.56 +        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
    3.57  
    3.58 -        glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    3.59 -        glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
    3.60 +        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
    3.61 +        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
    3.62  
    3.63          if ((useDepthBuffer) || (useStencilBuffer)) {
    3.64              if (useStencilBuffer) {
    3.65                  /* Apparently you need to pack stencil and depth into one buffer. */
    3.66                  depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
    3.67              } else if (useDepthBuffer) {
    3.68 -                /* iOS only has 24-bit depth buffers, even with GL_DEPTH_COMPONENT16_OES */
    3.69 +                /* iOS only has 24-bit depth buffers, even with GL_DEPTH_COMPONENT16 */
    3.70                  depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
    3.71              }
    3.72  
    3.73 -            glGenRenderbuffersOES(1, &depthRenderbuffer);
    3.74 -            glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
    3.75 -            glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight);
    3.76 +            glGenRenderbuffers(1, &depthRenderbuffer);
    3.77 +            glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
    3.78 +            glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
    3.79              if (useDepthBuffer) {
    3.80 -                glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    3.81 +                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
    3.82              }
    3.83              if (useStencilBuffer) {
    3.84 -                glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    3.85 +                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
    3.86              }
    3.87          }
    3.88  
    3.89 -        if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
    3.90 +        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
    3.91              SDL_SetError("Failed creating OpenGL ES framebuffer");
    3.92              return nil;
    3.93          }
    3.94  
    3.95 -        glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    3.96 +        glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
    3.97      }
    3.98  
    3.99      return self;
   3.100 @@ -174,30 +181,30 @@
   3.101  
   3.102  - (void)updateFrame
   3.103  {
   3.104 -    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
   3.105 -    glBindRenderbufferOES(GL_RENDERBUFFER_OES, 0);
   3.106 -    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, 0);
   3.107 -    glDeleteRenderbuffersOES(1, &viewRenderbuffer);
   3.108 +    glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
   3.109 +    glBindRenderbuffer(GL_RENDERBUFFER, 0);
   3.110 +    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
   3.111 +    glDeleteRenderbuffers(1, &viewRenderbuffer);
   3.112  
   3.113 -    glGenRenderbuffersOES(1, &viewRenderbuffer);
   3.114 -    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
   3.115 -    [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
   3.116 -    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
   3.117 +    glGenRenderbuffers(1, &viewRenderbuffer);
   3.118 +    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
   3.119 +    [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
   3.120 +    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
   3.121  
   3.122 -    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
   3.123 -    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
   3.124 +    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
   3.125 +    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
   3.126  
   3.127      if (depthRenderbuffer != 0) {
   3.128 -        glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
   3.129 -        glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depthBufferFormat, backingWidth, backingHeight);
   3.130 +        glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
   3.131 +        glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
   3.132      }
   3.133  
   3.134 -    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
   3.135 +    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
   3.136  }
   3.137  
   3.138  - (void)setAnimationCallback:(int)interval
   3.139 -    callback:(void (*)(void*))callback
   3.140 -    callbackParam:(void*)callbackParam
   3.141 +                    callback:(void (*)(void*))callback
   3.142 +               callbackParam:(void*)callbackParam
   3.143  {
   3.144      [self stopAnimation];
   3.145  
   3.146 @@ -236,16 +243,14 @@
   3.147      [EAGLContext setCurrentContext:context];
   3.148  }
   3.149  
   3.150 -
   3.151  - (void)swapBuffers
   3.152  {
   3.153      /* viewRenderbuffer should always be bound here. Code that binds something
   3.154 -        else is responsible for rebinding viewRenderbuffer, to reduce
   3.155 -        duplicate state changes. */
   3.156 -    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
   3.157 +       else is responsible for rebinding viewRenderbuffer, to reduce duplicate
   3.158 +       state changes. */
   3.159 +    [context presentRenderbuffer:GL_RENDERBUFFER];
   3.160  }
   3.161  
   3.162 -
   3.163  - (void)layoutSubviews
   3.164  {
   3.165      [super layoutSubviews];
   3.166 @@ -257,17 +262,17 @@
   3.167  - (void)destroyFramebuffer
   3.168  {
   3.169      if (viewFramebuffer != 0) {
   3.170 -        glDeleteFramebuffersOES(1, &viewFramebuffer);
   3.171 +        glDeleteFramebuffers(1, &viewFramebuffer);
   3.172          viewFramebuffer = 0;
   3.173      }
   3.174  
   3.175      if (viewRenderbuffer != 0) {
   3.176 -        glDeleteRenderbuffersOES(1, &viewRenderbuffer);
   3.177 +        glDeleteRenderbuffers(1, &viewRenderbuffer);
   3.178          viewRenderbuffer = 0;
   3.179      }
   3.180  
   3.181      if (depthRenderbuffer != 0) {
   3.182 -        glDeleteRenderbuffersOES(1, &depthRenderbuffer);
   3.183 +        glDeleteRenderbuffers(1, &depthRenderbuffer);
   3.184          depthRenderbuffer = 0;
   3.185      }
   3.186  }