Skip to content

Commit

Permalink
Fixed bug 4882 - Fix build for iOS when disabling OpenGL
Browse files Browse the repository at this point in the history
Aaron Barany

Since OpenGL is deprecated on iOS, it is advantageous to be able to remove all OpenGL related code when building SDL for iOS. This patch adds the necessary #if checks to compile in this case.
  • Loading branch information
slouken committed Dec 4, 2019
1 parent e5af951 commit b757602
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/video/uikit/SDL_uikitevents.m
Expand Up @@ -65,7 +65,9 @@ touch events to get processed (which is important to get certain
} while(result == kCFRunLoopRunHandledSource);

/* See the comment in the function definition. */
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
UIKit_GL_RestoreCurrentContext();
#endif
}

#endif /* SDL_VIDEO_DRIVER_UIKIT */
Expand Down
4 changes: 4 additions & 0 deletions src/video/uikit/SDL_uikitopengles.h
Expand Up @@ -21,6 +21,8 @@
#ifndef SDL_uikitopengles_
#define SDL_uikitopengles_

#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2

#include "../SDL_sysvideo.h"

extern int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window,
Expand All @@ -35,6 +37,8 @@ extern int UIKit_GL_LoadLibrary(_THIS, const char *path);

extern void UIKit_GL_RestoreCurrentContext(void);

#endif // SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2

#endif /* SDL_uikitopengles_ */

/* vi: set ts=4 sw=4 expandtab: */
2 changes: 1 addition & 1 deletion src/video/uikit/SDL_uikitopengles.m
Expand Up @@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"

#if SDL_VIDEO_DRIVER_UIKIT
#if SDL_VIDEO_DRIVER_UIKIT && (SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2)

#include "SDL_uikitopengles.h"
#import "SDL_uikitopenglview.h"
Expand Down
4 changes: 4 additions & 0 deletions src/video/uikit/SDL_uikitopenglview.h
Expand Up @@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/

#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2

#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES3/gl.h>
Expand Down Expand Up @@ -57,4 +59,6 @@

@end

#endif // SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2

/* vi: set ts=4 sw=4 expandtab: */
2 changes: 1 addition & 1 deletion src/video/uikit/SDL_uikitopenglview.m
Expand Up @@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"

#if SDL_VIDEO_DRIVER_UIKIT
#if SDL_VIDEO_DRIVER_UIKIT && (SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2)

#include <OpenGLES/EAGLDrawable.h>
#include <OpenGLES/ES2/glext.h>
Expand Down
2 changes: 2 additions & 0 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -116,13 +116,15 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
device->HasClipboardText = UIKit_HasClipboardText;

/* OpenGL (ES) functions */
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
device->GL_GetDrawableSize = UIKit_GL_GetDrawableSize;
device->GL_SwapWindow = UIKit_GL_SwapWindow;
device->GL_CreateContext = UIKit_GL_CreateContext;
device->GL_DeleteContext = UIKit_GL_DeleteContext;
device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
#endif
device->free = UIKit_DeleteDevice;

#if SDL_VIDEO_VULKAN
Expand Down
2 changes: 2 additions & 0 deletions src/video/uikit/SDL_uikitviewcontroller.m
Expand Up @@ -180,7 +180,9 @@ - (void)doLoop:(CADisplayLink*)sender
/* Don't run the game loop while a messagebox is up */
if (!UIKit_ShowingMessageBox()) {
/* See the comment in the function definition. */
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
UIKit_GL_RestoreCurrentContext();
#endif

animationCallback(animationCallbackParam);
}
Expand Down
4 changes: 4 additions & 0 deletions src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -364,12 +364,16 @@ - (void)layoutSubviews

/* These struct members were added in SDL 2.0.4. */
if (versionnum >= SDL_VERSIONNUM(2,0,4)) {
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
if ([data.viewcontroller.view isKindOfClass:[SDL_uikitopenglview class]]) {
SDL_uikitopenglview *glview = (SDL_uikitopenglview *)data.viewcontroller.view;
info->info.uikit.framebuffer = glview.drawableFramebuffer;
info->info.uikit.colorbuffer = glview.drawableRenderbuffer;
info->info.uikit.resolveFramebuffer = glview.msaaResolveFramebuffer;
} else {
#else
{
#endif
info->info.uikit.framebuffer = 0;
info->info.uikit.colorbuffer = 0;
info->info.uikit.resolveFramebuffer = 0;
Expand Down

0 comments on commit b757602

Please sign in to comment.