1 // Created on: 2012-11-12
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
18 #ifndef GL_GLEXT_LEGACY
19 #define GL_GLEXT_LEGACY // To prevent inclusion of system glext.h on Mac OS X 10.6.8
22 // macOS 10.4 deprecated OpenGL framework - suppress useless warnings
23 #define GL_SILENCE_DEPRECATION
25 #import <TargetConditionals.h>
27 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
28 #import <UIKit/UIKit.h>
30 #import <Cocoa/Cocoa.h>
33 #include <OpenGl_GlCore11.hxx>
34 #include <OpenGl_Context.hxx>
35 #include <OpenGl_FrameBuffer.hxx>
37 #include <Standard_ProgramError.hxx>
39 // =======================================================================
40 // function : IsCurrent
42 // =======================================================================
43 Standard_Boolean OpenGl_Context::IsCurrent() const
45 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
46 return myGContext != NULL
47 && [EAGLContext currentContext] == myGContext;
49 return myGContext != NULL
50 && [NSOpenGLContext currentContext] == myGContext;
54 // =======================================================================
55 // function : MakeCurrent
57 // =======================================================================
58 Standard_Boolean OpenGl_Context::MakeCurrent()
60 if (myGContext == NULL)
62 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
63 return Standard_False;
66 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
67 return [EAGLContext setCurrentContext: myGContext] == YES;
69 [myGContext makeCurrentContext];
74 // =======================================================================
75 // function : SwapBuffers
77 // =======================================================================
78 void OpenGl_Context::SwapBuffers()
80 if (myGContext == NULL)
85 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
86 if (myDefaultFbo.IsNull()
87 || !myDefaultFbo->IsValid()
88 || myDefaultFbo->ColorRenderBuffer() == 0)
93 ::glBindRenderbuffer (GL_RENDERBUFFER, myDefaultFbo->ColorRenderBuffer());
94 [myGContext presentRenderbuffer: GL_RENDERBUFFER];
95 //::glBindRenderbuffer (GL_RENDERBUFFER, 0);
98 [myGContext flushBuffer];
102 // =======================================================================
105 // =======================================================================
106 Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile)
110 return Standard_True;
113 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
114 myGContext = [EAGLContext currentContext];
116 myGContext = [NSOpenGLContext currentContext];
118 if (myGContext == NULL)
120 return Standard_False;
123 init (theIsCoreProfile);
124 myIsInitialized = Standard_True;
125 return Standard_True;