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 #define GL_GLEXT_LEGACY // To prevent inclusion of system glext.h on Mac OS X 10.6.8
20 #import <TargetConditionals.h>
22 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
23 #import <UIKit/UIKit.h>
25 #import <Cocoa/Cocoa.h>
28 #include <OpenGl_GlCore11.hxx>
29 #include <OpenGl_Context.hxx>
30 #include <OpenGl_FrameBuffer.hxx>
32 #include <Standard_ProgramError.hxx>
34 // =======================================================================
35 // function : IsCurrent
37 // =======================================================================
38 Standard_Boolean OpenGl_Context::IsCurrent() const
40 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
41 return myGContext != NULL
42 && [EAGLContext currentContext] == myGContext;
44 return myGContext != NULL
45 && [NSOpenGLContext currentContext] == myGContext;
49 // =======================================================================
50 // function : MakeCurrent
52 // =======================================================================
53 Standard_Boolean OpenGl_Context::MakeCurrent()
55 if (myGContext == NULL)
57 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
58 return Standard_False;
61 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
62 return [EAGLContext setCurrentContext: myGContext] == YES;
64 [myGContext makeCurrentContext];
69 // =======================================================================
70 // function : SwapBuffers
72 // =======================================================================
73 void OpenGl_Context::SwapBuffers()
75 if (myGContext == NULL)
80 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
81 if (myDefaultFbo.IsNull()
82 || !myDefaultFbo->IsValid()
83 || myDefaultFbo->ColorRenderBuffer() == 0)
88 ::glBindRenderbuffer (GL_RENDERBUFFER, myDefaultFbo->ColorRenderBuffer());
89 [myGContext presentRenderbuffer: GL_RENDERBUFFER];
90 //::glBindRenderbuffer (GL_RENDERBUFFER, 0);
93 [myGContext flushBuffer];
97 // =======================================================================
100 // =======================================================================
101 Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile)
105 return Standard_True;
108 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
109 myGContext = [EAGLContext currentContext];
111 myGContext = [NSOpenGLContext currentContext];
113 if (myGContext == NULL)
115 return Standard_False;
118 init (theIsCoreProfile);
119 myIsInitialized = Standard_True;
120 return Standard_True;