0025809: Visualization, TKOpenGl - fix texture mapping in capping
[occt.git] / src / OpenGl / OpenGl_Context_1.mm
1 // Created on: 2012-11-12
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
17
18 #define GL_GLEXT_LEGACY // To prevent inclusion of system glext.h on Mac OS X 10.6.8
19
20 #import <Cocoa/Cocoa.h>
21
22 #include <OpenGl_GlCore11.hxx>
23 #include <OpenGl_Context.hxx>
24
25 #include <Standard_ProgramError.hxx>
26
27 // =======================================================================
28 // function : IsCurrent
29 // purpose  :
30 // =======================================================================
31 Standard_Boolean OpenGl_Context::IsCurrent() const
32 {
33   return myGContext != NULL
34       && [NSOpenGLContext currentContext] == (NSOpenGLContext* )myGContext;
35 }
36
37 // =======================================================================
38 // function : MakeCurrent
39 // purpose  :
40 // =======================================================================
41 Standard_Boolean OpenGl_Context::MakeCurrent()
42 {
43   if (myGContext == NULL)
44   {
45     Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
46     return Standard_False;
47   }
48
49   [(NSOpenGLContext* )myGContext makeCurrentContext];
50   return Standard_True;
51 }
52
53 // =======================================================================
54 // function : SwapBuffers
55 // purpose  :
56 // =======================================================================
57 void OpenGl_Context::SwapBuffers()
58 {
59   if (myGContext != NULL)
60   {
61     glFinish();
62     [(NSOpenGLContext* )myGContext flushBuffer];
63   }
64 }
65
66 // =======================================================================
67 // function : Init
68 // purpose  :
69 // =======================================================================
70 Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile)
71 {
72   if (myIsInitialized)
73   {
74     return Standard_True;
75   }
76
77   myGContext = [NSOpenGLContext currentContext];
78   if (myGContext == NULL)
79   {
80     return Standard_False;
81   }
82
83   init (theIsCoreProfile);
84   myIsInitialized = Standard_True;
85   return Standard_True;
86 }
87
88 #endif // __APPLE__