0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[occt.git] / src / OpenGl / OpenGl_Context_1.mm
CommitLineData
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
896faa72 18#ifndef GL_GLEXT_LEGACY
0e9d3b83 19#define GL_GLEXT_LEGACY // To prevent inclusion of system glext.h on Mac OS X 10.6.8
896faa72 20#endif
0e9d3b83 21
42451ec0 22// macOS 10.4 deprecated OpenGL framework - suppress useless warnings
23#define GL_SILENCE_DEPRECATION
24
a2e4f780 25#import <TargetConditionals.h>
26
27#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
28 #import <UIKit/UIKit.h>
29#else
30 #import <Cocoa/Cocoa.h>
31#endif
4fe56619 32
33#include <OpenGl_GlCore11.hxx>
34#include <OpenGl_Context.hxx>
a2e4f780 35#include <OpenGl_FrameBuffer.hxx>
4fe56619 36
37#include <Standard_ProgramError.hxx>
38
39// =======================================================================
40// function : IsCurrent
41// purpose :
42// =======================================================================
43Standard_Boolean OpenGl_Context::IsCurrent() const
44{
a2e4f780 45#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
46 return myGContext != NULL
47 && [EAGLContext currentContext] == myGContext;
48#else
4fe56619 49 return myGContext != NULL
a2e4f780 50 && [NSOpenGLContext currentContext] == myGContext;
51#endif
4fe56619 52}
53
54// =======================================================================
55// function : MakeCurrent
56// purpose :
57// =======================================================================
58Standard_Boolean OpenGl_Context::MakeCurrent()
59{
60 if (myGContext == NULL)
61 {
62 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
63 return Standard_False;
64 }
65
a2e4f780 66#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
67 return [EAGLContext setCurrentContext: myGContext] == YES;
68#else
69 [myGContext makeCurrentContext];
4fe56619 70 return Standard_True;
a2e4f780 71#endif
4fe56619 72}
73
74// =======================================================================
75// function : SwapBuffers
76// purpose :
77// =======================================================================
78void OpenGl_Context::SwapBuffers()
79{
a2e4f780 80 if (myGContext == NULL)
4fe56619 81 {
a2e4f780 82 return;
4fe56619 83 }
a2e4f780 84
85#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
86 if (myDefaultFbo.IsNull()
87 || !myDefaultFbo->IsValid()
88 || myDefaultFbo->ColorRenderBuffer() == 0)
89 {
90 return;
91 }
92
93 ::glBindRenderbuffer (GL_RENDERBUFFER, myDefaultFbo->ColorRenderBuffer());
94 [myGContext presentRenderbuffer: GL_RENDERBUFFER];
95 //::glBindRenderbuffer (GL_RENDERBUFFER, 0);
96#else
97 glFinish();
98 [myGContext flushBuffer];
99#endif
4fe56619 100}
101
102// =======================================================================
103// function : Init
104// purpose :
105// =======================================================================
4e1523ef 106Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile)
4fe56619 107{
108 if (myIsInitialized)
109 {
110 return Standard_True;
111 }
112
a2e4f780 113#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
114 myGContext = [EAGLContext currentContext];
115#else
4fe56619 116 myGContext = [NSOpenGLContext currentContext];
a2e4f780 117#endif
4fe56619 118 if (myGContext == NULL)
119 {
120 return Standard_False;
121 }
122
4e1523ef 123 init (theIsCoreProfile);
4fe56619 124 myIsInitialized = Standard_True;
125 return Standard_True;
126}
127
128#endif // __APPLE__