6aca4d39 |
1 | // Created on: 2012-11-12 |
4fe56619 |
2 | // Created by: Kirill GAVRILOV |
6aca4d39 |
3 | // Copyright (c) 2012-2014 OPEN CASCADE SAS |
4fe56619 |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
4fe56619 |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
4fe56619 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
4fe56619 |
15 | |
16 | #if defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
17 | |
0e9d3b83 |
18 | #define GL_GLEXT_LEGACY // To prevent inclusion of system glext.h on Mac OS X 10.6.8 |
19 | |
a2e4f780 |
20 | #import <TargetConditionals.h> |
21 | |
22 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
23 | #import <UIKit/UIKit.h> |
24 | #else |
25 | #import <Cocoa/Cocoa.h> |
26 | #endif |
4fe56619 |
27 | |
28 | #include <OpenGl_GlCore11.hxx> |
29 | #include <OpenGl_Context.hxx> |
a2e4f780 |
30 | #include <OpenGl_FrameBuffer.hxx> |
4fe56619 |
31 | |
32 | #include <Standard_ProgramError.hxx> |
33 | |
34 | // ======================================================================= |
35 | // function : IsCurrent |
36 | // purpose : |
37 | // ======================================================================= |
38 | Standard_Boolean OpenGl_Context::IsCurrent() const |
39 | { |
a2e4f780 |
40 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
41 | return myGContext != NULL |
42 | && [EAGLContext currentContext] == myGContext; |
43 | #else |
4fe56619 |
44 | return myGContext != NULL |
a2e4f780 |
45 | && [NSOpenGLContext currentContext] == myGContext; |
46 | #endif |
4fe56619 |
47 | } |
48 | |
49 | // ======================================================================= |
50 | // function : MakeCurrent |
51 | // purpose : |
52 | // ======================================================================= |
53 | Standard_Boolean OpenGl_Context::MakeCurrent() |
54 | { |
55 | if (myGContext == NULL) |
56 | { |
57 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); |
58 | return Standard_False; |
59 | } |
60 | |
a2e4f780 |
61 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
62 | return [EAGLContext setCurrentContext: myGContext] == YES; |
63 | #else |
64 | [myGContext makeCurrentContext]; |
4fe56619 |
65 | return Standard_True; |
a2e4f780 |
66 | #endif |
4fe56619 |
67 | } |
68 | |
69 | // ======================================================================= |
70 | // function : SwapBuffers |
71 | // purpose : |
72 | // ======================================================================= |
73 | void OpenGl_Context::SwapBuffers() |
74 | { |
a2e4f780 |
75 | if (myGContext == NULL) |
4fe56619 |
76 | { |
a2e4f780 |
77 | return; |
4fe56619 |
78 | } |
a2e4f780 |
79 | |
80 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
81 | if (myDefaultFbo.IsNull() |
82 | || !myDefaultFbo->IsValid() |
83 | || myDefaultFbo->ColorRenderBuffer() == 0) |
84 | { |
85 | return; |
86 | } |
87 | |
88 | ::glBindRenderbuffer (GL_RENDERBUFFER, myDefaultFbo->ColorRenderBuffer()); |
89 | [myGContext presentRenderbuffer: GL_RENDERBUFFER]; |
90 | //::glBindRenderbuffer (GL_RENDERBUFFER, 0); |
91 | #else |
92 | glFinish(); |
93 | [myGContext flushBuffer]; |
94 | #endif |
4fe56619 |
95 | } |
96 | |
97 | // ======================================================================= |
98 | // function : Init |
99 | // purpose : |
100 | // ======================================================================= |
4e1523ef |
101 | Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile) |
4fe56619 |
102 | { |
103 | if (myIsInitialized) |
104 | { |
105 | return Standard_True; |
106 | } |
107 | |
a2e4f780 |
108 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
109 | myGContext = [EAGLContext currentContext]; |
110 | #else |
4fe56619 |
111 | myGContext = [NSOpenGLContext currentContext]; |
a2e4f780 |
112 | #endif |
4fe56619 |
113 | if (myGContext == NULL) |
114 | { |
115 | return Standard_False; |
116 | } |
117 | |
4e1523ef |
118 | init (theIsCoreProfile); |
4fe56619 |
119 | myIsInitialized = Standard_True; |
120 | return Standard_True; |
121 | } |
122 | |
123 | #endif // __APPLE__ |