0023009: Request of a new feature for units management during step import
[occt.git] / src / OpenGl / OpenGl_Context.hxx
CommitLineData
b311480e 1// Created on: 2012-01-26
2// Created by: Kirill GAVRILOV
3// Copyright (c) 2012-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
2166f0fa
SK
20
21#ifndef _OpenGl_Context_H__
22#define _OpenGl_Context_H__
23
2166f0fa
SK
24#include <Standard_Transient.hxx>
25#include <Handle_OpenGl_Context.hxx>
26
5f8b738e 27//! Forward declarations
28struct OpenGl_GlCore12;
29struct OpenGl_GlCore13;
30struct OpenGl_GlCore14;
31struct OpenGl_GlCore15;
32struct OpenGl_GlCore20;
33struct OpenGl_ArbVBO;
34struct OpenGl_ExtFBO;
2166f0fa 35
5f8b738e 36//! This class generalize access to the GL context and available extensions.
37//!
38//! Functions are grouped into structures and accessed as fields.
39//! You should check the group for NULL before usage (if group is not NULL
40//! then all functions are available):
41//! @code
42//! if (myContext->core20 != NULL)
43//! {
44//! myGlProgram = myContext->core20->glCreateProgram();
45//! .. do more stuff ..
46//! }
47//! else
48//! {
49//! .. compatibility with outdated configurations ..
50//! }
51//! @endcode
52//!
53//! Current implementation provide access to OpenGL core functionality up to 2.0 version
54//! (core12, core13, core14, core15, fields core20).
55//! within several extensions (arbVBO, extFBO, etc.).
56//!
57//! Simplified extensions classification:
58//! - prefixed with NV, AMD, ATI are vendor-specific (however may be provided by other vendors in some cases);
59//! - prefixed with EXT are accepted by 2+ vendors;
60//! - prefixed with ARB are accepted by Architecture Review Board and are candidates
61//! for inclusion into GL core functionality.
62//! Some functionality can be represented in several extensions simultaneously.
63//! In this case developer should be careful because different specification may differ
64//! in aspects (like enumeration values and error-handling).
65//!
66//! Notice that some systems provide mechanisms to simultaneously incorporate with GL contexts
67//! with different capabilities. Thats why OpenGl_Context should be initialized and used
68//! for each GL context individually.
2166f0fa
SK
69class OpenGl_Context : public Standard_Transient
70{
71public:
72
5f8b738e 73 //! Empty constructor. You should call Init() to perform initialization with bound GL context.
74 Standard_EXPORT OpenGl_Context();
75
76 //! Destructor.
77 Standard_EXPORT virtual ~OpenGl_Context();
2166f0fa
SK
78
79 //! Initialize available extensions.
80 //! GL context should be active!
5f8b738e 81 Standard_EXPORT void Init();
2166f0fa 82
5f8b738e 83 //! Check if theExtName extension is supported by active GL context.
84 Standard_EXPORT static Standard_Boolean CheckExtension (const char* theExtName);
2166f0fa
SK
85
86 //! Auxiliary template to retrieve GL function pointer.
5f8b738e 87 //! Pointer to function retrieved from library is statically casted
88 //! to requested type - there no way to check real signature of exported function.
2166f0fa
SK
89 //! The context should be bound before call.
90 template <typename FuncType_t>
5f8b738e 91 Standard_Boolean FindProc (const char* theFuncName,
92 FuncType_t& theFuncPtr)
2166f0fa 93 {
5f8b738e 94 theFuncPtr = (FuncType_t )findProc (theFuncName);
2166f0fa
SK
95 return (theFuncPtr != NULL);
96 }
97
5f8b738e 98 //! @return true if detected GL version is higher or equal to requested one.
99 inline Standard_Boolean IsGlUpperEqual (const Standard_Integer theVerMajor,
100 const Standard_Integer theVerMinor)
101 {
102 return (myGlVerMajor > theVerMajor)
103 || (myGlVerMajor == theVerMajor && myGlVerMinor >= theVerMinor);
104 }
105
106 //! Clean up errors stack for this GL context (glGetError() in loop).
107 Standard_EXPORT void ResetErrors();
108
109private:
110
111 //! Wrapper to system function to retrieve GL function pointer by name.
112 Standard_EXPORT void* findProc (const char* theFuncName);
113
114 //! Read OpenGL version information from active context.
115 Standard_EXPORT void readGlVersion();
116
117 //! Private initialization function that should be called only once.
118 Standard_EXPORT void init();
119
120public: // core profiles
121
122 OpenGl_GlCore12* core12;
123 OpenGl_GlCore13* core13;
124 OpenGl_GlCore14* core14;
125 OpenGl_GlCore15* core15;
126 OpenGl_GlCore20* core20;
127
128public: // extensions
129
130 OpenGl_ArbVBO* arbVBO;
131 OpenGl_ExtFBO* extFBO;
132
133private:
2166f0fa 134
5f8b738e 135 void* myGlLibHandle; //!< optional handle to GL library
136 OpenGl_GlCore20* myGlCore20; //!< common structure for GL core functions upto 2.0
137 Standard_Integer myGlVerMajor; //!< cached GL version major number
138 Standard_Integer myGlVerMinor; //!< cached GL version minor number
139 Standard_Boolean myIsInitialized; //!< flag to indicate initialization state
2166f0fa
SK
140
141public:
142
5f8b738e 143 DEFINE_STANDARD_RTTI(OpenGl_Context) // Type definition
2166f0fa
SK
144
145};
146
147#endif // _OpenGl_Context_H__