0025442: Visualization, TKOpenGl - prevent inclusion of system header glxext.h
[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
0e9d3b83 18#define GL_GLEXT_LEGACY // To prevent inclusion of system glext.h on Mac OS X 10.6.8
19
4fe56619 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// =======================================================================
31Standard_Boolean OpenGl_Context::IsCurrent() const
32{
33 return myGContext != NULL
34 && [NSOpenGLContext currentContext] == (NSOpenGLContext* )myGContext;
35}
36
37// =======================================================================
38// function : MakeCurrent
39// purpose :
40// =======================================================================
41Standard_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// =======================================================================
57void 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// =======================================================================
70Standard_Boolean OpenGl_Context::Init()
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();
84 myIsInitialized = Standard_True;
85 return Standard_True;
86}
87
88#endif // __APPLE__