0030434: Visualization, TKV3d - add "NoUpdate" state of frustum culling optimization
[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
a2e4f780 22#import <TargetConditionals.h>
23
24#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
25 #import <UIKit/UIKit.h>
26#else
27 #import <Cocoa/Cocoa.h>
28#endif
4fe56619 29
30#include <OpenGl_GlCore11.hxx>
31#include <OpenGl_Context.hxx>
a2e4f780 32#include <OpenGl_FrameBuffer.hxx>
4fe56619 33
34#include <Standard_ProgramError.hxx>
35
36// =======================================================================
37// function : IsCurrent
38// purpose :
39// =======================================================================
40Standard_Boolean OpenGl_Context::IsCurrent() const
41{
a2e4f780 42#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
43 return myGContext != NULL
44 && [EAGLContext currentContext] == myGContext;
45#else
4fe56619 46 return myGContext != NULL
a2e4f780 47 && [NSOpenGLContext currentContext] == myGContext;
48#endif
4fe56619 49}
50
51// =======================================================================
52// function : MakeCurrent
53// purpose :
54// =======================================================================
55Standard_Boolean OpenGl_Context::MakeCurrent()
56{
57 if (myGContext == NULL)
58 {
59 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
60 return Standard_False;
61 }
62
a2e4f780 63#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
64 return [EAGLContext setCurrentContext: myGContext] == YES;
65#else
66 [myGContext makeCurrentContext];
4fe56619 67 return Standard_True;
a2e4f780 68#endif
4fe56619 69}
70
71// =======================================================================
72// function : SwapBuffers
73// purpose :
74// =======================================================================
75void OpenGl_Context::SwapBuffers()
76{
a2e4f780 77 if (myGContext == NULL)
4fe56619 78 {
a2e4f780 79 return;
4fe56619 80 }
a2e4f780 81
82#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
83 if (myDefaultFbo.IsNull()
84 || !myDefaultFbo->IsValid()
85 || myDefaultFbo->ColorRenderBuffer() == 0)
86 {
87 return;
88 }
89
90 ::glBindRenderbuffer (GL_RENDERBUFFER, myDefaultFbo->ColorRenderBuffer());
91 [myGContext presentRenderbuffer: GL_RENDERBUFFER];
92 //::glBindRenderbuffer (GL_RENDERBUFFER, 0);
93#else
94 glFinish();
95 [myGContext flushBuffer];
96#endif
4fe56619 97}
98
99// =======================================================================
100// function : Init
101// purpose :
102// =======================================================================
4e1523ef 103Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile)
4fe56619 104{
105 if (myIsInitialized)
106 {
107 return Standard_True;
108 }
109
a2e4f780 110#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
111 myGContext = [EAGLContext currentContext];
112#else
4fe56619 113 myGContext = [NSOpenGLContext currentContext];
a2e4f780 114#endif
4fe56619 115 if (myGContext == NULL)
116 {
117 return Standard_False;
118 }
119
4e1523ef 120 init (theIsCoreProfile);
4fe56619 121 myIsInitialized = Standard_True;
122 return Standard_True;
123}
124
125#endif // __APPLE__