Commit | Line | Data |
---|---|---|
6aca4d39 | 1 | // Created on: 2012-01-26 |
b311480e | 2 | // Created by: Kirill GAVRILOV |
6aca4d39 | 3 | // Copyright (c) 2012-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2166f0fa SK |
16 | #ifndef _OpenGl_Context_H__ |
17 | #define _OpenGl_Context_H__ | |
18 | ||
2bd4c032 | 19 | #include <Aspect_Handle.hxx> |
6d0e6be5 | 20 | #include <Aspect_HatchStyle.hxx> |
2bd4c032 | 21 | #include <Aspect_Drawable.hxx> |
22 | #include <Aspect_Display.hxx> | |
23 | #include <Aspect_RenderingContext.hxx> | |
ac116c22 | 24 | #include <Aspect_TypeOfLine.hxx> |
5e27df78 | 25 | #include <NCollection_DataMap.hxx> |
26d9c835 | 26 | #include <Graphic3d_DiagnosticInfo.hxx> |
cc8cbabe | 27 | #include <Graphic3d_TextureUnit.hxx> |
4269bd1b | 28 | #include <NCollection_Map.hxx> |
5e27df78 | 29 | #include <NCollection_Handle.hxx> |
3125ebb6 | 30 | #include <NCollection_List.hxx> |
a1073ae2 | 31 | #include <NCollection_SparseArray.hxx> |
cbf18624 | 32 | #include <Message.hxx> |
58655684 | 33 | #include <OpenGl_Caps.hxx> |
6d0e6be5 | 34 | #include <OpenGl_LineAttributes.hxx> |
8613985b | 35 | #include <OpenGl_Material.hxx> |
825aa485 | 36 | #include <OpenGl_MatrixState.hxx> |
8625ef7e | 37 | #include <OpenGl_Vec.hxx> |
5e27df78 | 38 | #include <OpenGl_Resource.hxx> |
cc8cbabe | 39 | #include <OpenGl_TextureSet.hxx> |
2166f0fa | 40 | #include <Standard_Transient.hxx> |
26d9c835 | 41 | #include <TColStd_IndexedDataMapOfStringString.hxx> |
c87535af | 42 | #include <TColStd_PackedMapOfInteger.hxx> |
30f0ad28 | 43 | #include <OpenGl_Clipping.hxx> |
b5ac8292 | 44 | #include <OpenGl_GlCore11.hxx> |
c04c30b3 | 45 | |
46 | #include <NCollection_Shared.hxx> | |
2166f0fa | 47 | |
5f8b738e | 48 | //! Forward declarations |
a2e4f780 | 49 | #if defined(__APPLE__) |
50 | #import <TargetConditionals.h> | |
51 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
52 | #ifdef __OBJC__ | |
53 | @class EAGLContext; | |
54 | #else | |
55 | struct EAGLContext; | |
56 | #endif | |
57 | #else | |
58 | #ifdef __OBJC__ | |
59 | @class NSOpenGLContext; | |
60 | #else | |
61 | struct NSOpenGLContext; | |
62 | #endif | |
63 | #endif | |
64 | #endif | |
65 | ||
01ca42b2 | 66 | struct OpenGl_GlFunctions; |
5e27df78 | 67 | struct OpenGl_ArbTBO; |
68 | struct OpenGl_ArbIns; | |
58655684 | 69 | struct OpenGl_ArbDbg; |
01ca42b2 | 70 | struct OpenGl_ArbFBO; |
b86bb3df | 71 | struct OpenGl_ArbFBOBlit; |
cc8cbabe | 72 | struct OpenGl_ArbSamplerObject; |
25ef750e | 73 | struct OpenGl_ArbTexBindless; |
cc8cbabe | 74 | struct OpenGl_ExtGS; |
2166f0fa | 75 | |
01ca42b2 | 76 | template<typename theBaseClass_t> struct OpenGl_TmplCore12; |
77 | typedef OpenGl_TmplCore12<OpenGl_GlCore11> OpenGl_GlCore12; | |
78 | typedef OpenGl_TmplCore12<OpenGl_GlCore11Fwd> OpenGl_GlCore12Fwd; | |
79 | ||
80 | struct OpenGl_GlCore13; | |
81 | struct OpenGl_GlCore13Fwd; | |
82 | ||
83 | template<typename theBaseClass_t> struct OpenGl_TmplCore14; | |
84 | typedef OpenGl_TmplCore14<OpenGl_GlCore13> OpenGl_GlCore14; | |
85 | typedef OpenGl_TmplCore14<OpenGl_GlCore13Fwd> OpenGl_GlCore14Fwd; | |
86 | ||
87 | template<typename theBaseClass_t> struct OpenGl_TmplCore15; | |
88 | typedef OpenGl_TmplCore15<OpenGl_GlCore14> OpenGl_GlCore15; | |
89 | typedef OpenGl_TmplCore15<OpenGl_GlCore14Fwd> OpenGl_GlCore15Fwd; | |
90 | ||
91 | template<typename theBaseClass_t> struct OpenGl_TmplCore20; | |
92 | typedef OpenGl_TmplCore20<OpenGl_GlCore15> OpenGl_GlCore20; | |
93 | typedef OpenGl_TmplCore20<OpenGl_GlCore15Fwd> OpenGl_GlCore20Fwd; | |
94 | ||
95 | template<typename theBaseClass_t> struct OpenGl_TmplCore21; | |
96 | typedef OpenGl_TmplCore21<OpenGl_GlCore20> OpenGl_GlCore21; | |
97 | typedef OpenGl_TmplCore21<OpenGl_GlCore20Fwd> OpenGl_GlCore21Fwd; | |
98 | ||
99 | template<typename theBaseClass_t> struct OpenGl_TmplCore30; | |
100 | typedef OpenGl_TmplCore30<OpenGl_GlCore21> OpenGl_GlCore30; | |
101 | typedef OpenGl_TmplCore30<OpenGl_GlCore21Fwd> OpenGl_GlCore30Fwd; | |
102 | ||
103 | template<typename theBaseClass_t> struct OpenGl_TmplCore31; | |
104 | typedef OpenGl_TmplCore31<OpenGl_GlCore30> OpenGl_GlCore31Back; | |
105 | typedef OpenGl_TmplCore31<OpenGl_GlCore30Fwd> OpenGl_GlCore31; | |
106 | ||
107 | template<typename theBaseClass_t> struct OpenGl_TmplCore32; | |
108 | typedef OpenGl_TmplCore32<OpenGl_GlCore31Back> OpenGl_GlCore32Back; | |
109 | typedef OpenGl_TmplCore32<OpenGl_GlCore31> OpenGl_GlCore32; | |
110 | ||
111 | template<typename theBaseClass_t> struct OpenGl_TmplCore33; | |
112 | typedef OpenGl_TmplCore33<OpenGl_GlCore32Back> OpenGl_GlCore33Back; | |
113 | typedef OpenGl_TmplCore33<OpenGl_GlCore32> OpenGl_GlCore33; | |
114 | ||
115 | template<typename theBaseClass_t> struct OpenGl_TmplCore40; | |
116 | typedef OpenGl_TmplCore40<OpenGl_GlCore33Back> OpenGl_GlCore40Back; | |
117 | typedef OpenGl_TmplCore40<OpenGl_GlCore33> OpenGl_GlCore40; | |
118 | ||
119 | template<typename theBaseClass_t> struct OpenGl_TmplCore41; | |
120 | typedef OpenGl_TmplCore41<OpenGl_GlCore40Back> OpenGl_GlCore41Back; | |
121 | typedef OpenGl_TmplCore41<OpenGl_GlCore40> OpenGl_GlCore41; | |
122 | ||
123 | template<typename theBaseClass_t> struct OpenGl_TmplCore42; | |
124 | typedef OpenGl_TmplCore42<OpenGl_GlCore41Back> OpenGl_GlCore42Back; | |
125 | typedef OpenGl_TmplCore42<OpenGl_GlCore41> OpenGl_GlCore42; | |
126 | ||
127 | template<typename theBaseClass_t> struct OpenGl_TmplCore43; | |
128 | typedef OpenGl_TmplCore43<OpenGl_GlCore42Back> OpenGl_GlCore43Back; | |
129 | typedef OpenGl_TmplCore43<OpenGl_GlCore42> OpenGl_GlCore43; | |
130 | ||
131 | template<typename theBaseClass_t> struct OpenGl_TmplCore44; | |
132 | typedef OpenGl_TmplCore44<OpenGl_GlCore43Back> OpenGl_GlCore44Back; | |
133 | typedef OpenGl_TmplCore44<OpenGl_GlCore43> OpenGl_GlCore44; | |
134 | ||
f838dac4 | 135 | class Graphic3d_PresentationAttributes; |
bf5f0ca2 | 136 | class OpenGl_Aspects; |
cc8cbabe | 137 | class OpenGl_FrameBuffer; |
138 | class OpenGl_Sampler; | |
139 | class OpenGl_ShaderProgram; | |
140 | class OpenGl_ShaderManager; | |
15669413 | 141 | class OpenGl_FrameStats; |
c04c30b3 | 142 | |
a1073ae2 | 143 | enum OpenGl_FeatureFlag |
144 | { | |
145 | OpenGl_FeatureNotAvailable = 0, //!< Feature is not supported by OpenGl implementation. | |
146 | OpenGl_FeatureInExtensions = 1, //!< Feature is supported as extension. | |
147 | OpenGl_FeatureInCore = 2 //!< Feature is supported as part of core profile. | |
148 | }; | |
149 | ||
c04c30b3 | 150 | DEFINE_STANDARD_HANDLE(OpenGl_Context, Standard_Transient) |
151 | ||
5f8b738e | 152 | //! This class generalize access to the GL context and available extensions. |
153 | //! | |
4e1523ef | 154 | //! Functions related to specific OpenGL version or extension are grouped into structures which can be accessed as fields of this class. |
155 | //! The most simple way to check that required functionality is available - is NULL check for the group: | |
5f8b738e | 156 | //! @code |
157 | //! if (myContext->core20 != NULL) | |
158 | //! { | |
159 | //! myGlProgram = myContext->core20->glCreateProgram(); | |
160 | //! .. do more stuff .. | |
161 | //! } | |
162 | //! else | |
163 | //! { | |
164 | //! .. compatibility with outdated configurations .. | |
165 | //! } | |
166 | //! @endcode | |
167 | //! | |
4e1523ef | 168 | //! Current implementation provide access to OpenGL core functionality up to 4.4 version (core12, core13, core14, core15, fields core20) |
169 | //! as well as several extensions (arbTBO, arbFBO, etc.). | |
170 | //! | |
171 | //! OpenGL context might be initialized in Core Profile. In this case deprecated functionality become unavailable. | |
172 | //! To make code easily adaptable to wide range of OpenGL versions, function sets related to each version has two kinds of suffixes: | |
173 | //! - "back" for version 3.2+. | |
174 | //! Represents function set for Backward-Compatible Profile. | |
175 | //! Function sets without this suffix represents core profile. | |
176 | //! - "fwd" for version 3.0-. | |
177 | //! Represents non-deprecated function set of earlier OpenGL versions, which are still available within OpenGL 3.2 Core Profile. | |
178 | //! Function sets without this suffix represents complete list of functions related to specific OpenGL version. | |
179 | //! | |
180 | //! To select which core** function set should be used in specific case: | |
181 | //! - Determine the minimal OpenGL version required for implemented functionality and use it to access all functions. | |
182 | //! For example, if algorithm requires OpenGL 2.1+, it is better to write core20fwd->glEnable() rather than core11fwd->glEnable() for uniformity. | |
183 | //! - If functionality will work within Core Profile, use function sets with appropriate suffix. | |
184 | //! - Validate minimal requirements at initialization/creation time and omit checks within code where algorithm should be already initialized. | |
185 | //! Properly escape code incompatible with Core Profile. The simplest way to check Core Profile is "if (core11 == NULL)". | |
5f8b738e | 186 | //! |
187 | //! Simplified extensions classification: | |
188 | //! - prefixed with NV, AMD, ATI are vendor-specific (however may be provided by other vendors in some cases); | |
189 | //! - prefixed with EXT are accepted by 2+ vendors; | |
190 | //! - prefixed with ARB are accepted by Architecture Review Board and are candidates | |
191 | //! for inclusion into GL core functionality. | |
192 | //! Some functionality can be represented in several extensions simultaneously. | |
193 | //! In this case developer should be careful because different specification may differ | |
194 | //! in aspects (like enumeration values and error-handling). | |
195 | //! | |
4e1523ef | 196 | //! Notice that some systems provide mechanisms to simultaneously incorporate with GL contexts with different capabilities. |
197 | //! For this reason OpenGl_Context should be initialized and used for each GL context independently. | |
2166f0fa SK |
198 | class OpenGl_Context : public Standard_Transient |
199 | { | |
8613985b | 200 | DEFINE_STANDARD_RTTIEXT(OpenGl_Context, Standard_Transient) |
201 | friend class OpenGl_Window; | |
a174a3c5 | 202 | public: |
203 | ||
15669413 | 204 | typedef NCollection_Shared< NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)> > OpenGl_ResourcesMap; |
205 | ||
a174a3c5 | 206 | //! Function for getting power of to number larger or equal to input number. |
207 | //! @param theNumber number to 'power of two' | |
208 | //! @param theThreshold upper threshold | |
209 | //! @return power of two number | |
210 | inline static Standard_Integer GetPowerOfTwo (const Standard_Integer theNumber, | |
211 | const Standard_Integer theThreshold) | |
212 | { | |
213 | for (Standard_Integer p2 = 2; p2 <= theThreshold; p2 <<= 1) | |
214 | { | |
215 | if (theNumber <= p2) | |
216 | { | |
217 | return p2; | |
218 | } | |
219 | } | |
220 | return theThreshold; | |
221 | } | |
222 | ||
2166f0fa SK |
223 | public: |
224 | ||
5f8b738e | 225 | //! Empty constructor. You should call Init() to perform initialization with bound GL context. |
58655684 | 226 | Standard_EXPORT OpenGl_Context (const Handle(OpenGl_Caps)& theCaps = NULL); |
5f8b738e | 227 | |
228 | //! Destructor. | |
229 | Standard_EXPORT virtual ~OpenGl_Context(); | |
2166f0fa | 230 | |
05e2200b | 231 | //! Release all resources, including shared ones |
232 | Standard_EXPORT void forcedRelease(); | |
233 | ||
5e27df78 | 234 | //! Share GL context resources. |
235 | //! theShareCtx - handle to context to retrieve handles to shared resources. | |
236 | Standard_EXPORT void Share (const Handle(OpenGl_Context)& theShareCtx); | |
237 | ||
7e7c2f0b | 238 | //! Initialize class from currently bound OpenGL context. Method should be called only once. |
239 | //! @return false if no GL context is bound to the current thread | |
4e1523ef | 240 | Standard_EXPORT Standard_Boolean Init (const Standard_Boolean theIsCoreProfile = Standard_False); |
2166f0fa | 241 | |
fd4a6963 | 242 | //! @return true if this context is valid (has been initialized) |
243 | inline Standard_Boolean IsValid() const | |
244 | { | |
245 | return myIsInitialized; | |
246 | } | |
247 | ||
da8bb41d | 248 | #if defined(HAVE_EGL) |
249 | //! Initialize class from specified surface and rendering context. Method should be called only once. | |
250 | //! @return false if OpenGL context can not be bound to specified surface | |
251 | Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theEglSurface, | |
252 | const Aspect_Display theEglDisplay, | |
4e1523ef | 253 | const Aspect_RenderingContext theEglContext, |
254 | const Standard_Boolean theIsCoreProfile = Standard_False); | |
da8bb41d | 255 | #elif defined(_WIN32) |
7e7c2f0b | 256 | //! Initialize class from specified window and rendering context. Method should be called only once. |
257 | //! @return false if OpenGL context can not be bound to specified window | |
f0430952 | 258 | Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow, |
259 | const Aspect_Handle theWindowDC, | |
4e1523ef | 260 | const Aspect_RenderingContext theGContext, |
261 | const Standard_Boolean theIsCoreProfile = Standard_False); | |
7e7c2f0b | 262 | |
263 | //! @return the window handle (HWND) currently bound to this OpenGL context | |
264 | inline Aspect_Handle Window() const | |
265 | { | |
266 | return myWindow; | |
267 | } | |
268 | ||
4fe56619 | 269 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 270 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
271 | ||
272 | //! Initialize class from specified OpenGL ES context (EAGLContext). Method should be called only once. | |
273 | Standard_EXPORT Standard_Boolean Init (EAGLContext* theGContext, | |
274 | const Standard_Boolean theIsCoreProfile = Standard_False); | |
275 | #else | |
276 | ||
7e7c2f0b | 277 | //! Initialize class from specified OpenGL context (NSOpenGLContext). Method should be called only once. |
a2e4f780 | 278 | Standard_EXPORT Standard_Boolean Init (NSOpenGLContext* theGContext, |
4e1523ef | 279 | const Standard_Boolean theIsCoreProfile = Standard_False); |
a2e4f780 | 280 | #endif |
2bd4c032 | 281 | #else |
a2e4f780 | 282 | |
7e7c2f0b | 283 | //! Initialize class from specified window and rendering context. Method should be called only once. |
284 | //! @return false if OpenGL context can not be bound to specified window | |
f0430952 | 285 | Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow, |
286 | const Aspect_Display theDisplay, | |
4e1523ef | 287 | const Aspect_RenderingContext theGContext, |
288 | const Standard_Boolean theIsCoreProfile = Standard_False); | |
7e7c2f0b | 289 | |
290 | //! @return the window handle (GLXDrawable) currently bound to this OpenGL context | |
291 | inline Aspect_Drawable Window() const | |
292 | { | |
293 | return myWindow; | |
294 | } | |
2bd4c032 | 295 | #endif |
296 | ||
4e1523ef | 297 | //! Read OpenGL version information from active context. |
298 | Standard_EXPORT static void ReadGlVersion (Standard_Integer& theGlVerMajor, | |
299 | Standard_Integer& theGlVerMinor); | |
300 | ||
5f8b738e | 301 | //! Check if theExtName extension is supported by active GL context. |
2bd4c032 | 302 | Standard_EXPORT Standard_Boolean CheckExtension (const char* theExtName) const; |
2166f0fa | 303 | |
58655684 | 304 | //! Check if theExtName extension is in extensions string. |
305 | Standard_EXPORT static Standard_Boolean CheckExtension (const char* theExtString, | |
306 | const char* theExtName); | |
307 | ||
2166f0fa | 308 | //! Auxiliary template to retrieve GL function pointer. |
5f8b738e | 309 | //! Pointer to function retrieved from library is statically casted |
310 | //! to requested type - there no way to check real signature of exported function. | |
2166f0fa SK |
311 | //! The context should be bound before call. |
312 | template <typename FuncType_t> | |
5f8b738e | 313 | Standard_Boolean FindProc (const char* theFuncName, |
314 | FuncType_t& theFuncPtr) | |
2166f0fa | 315 | { |
5f8b738e | 316 | theFuncPtr = (FuncType_t )findProc (theFuncName); |
2166f0fa SK |
317 | return (theFuncPtr != NULL); |
318 | } | |
319 | ||
2bd4c032 | 320 | //! @return true if detected GL version is greater or equal to requested one. |
321 | inline Standard_Boolean IsGlGreaterEqual (const Standard_Integer theVerMajor, | |
7e7c2f0b | 322 | const Standard_Integer theVerMinor) const |
5f8b738e | 323 | { |
324 | return (myGlVerMajor > theVerMajor) | |
325 | || (myGlVerMajor == theVerMajor && myGlVerMinor >= theVerMinor); | |
326 | } | |
327 | ||
26d9c835 | 328 | //! Return cached GL version major number. |
329 | Standard_Integer VersionMajor() const { return myGlVerMajor; } | |
330 | ||
331 | //! Return cached GL version minor number. | |
332 | Standard_Integer VersionMinor() const { return myGlVerMinor; } | |
333 | ||
f978241f | 334 | //! Access entire map of loaded OpenGL functions. |
335 | const OpenGl_GlFunctions* Functions() const { return myFuncs.operator->(); } | |
336 | ||
5f8b738e | 337 | //! Clean up errors stack for this GL context (glGetError() in loop). |
f9f740d6 | 338 | //! @return true if some error has been cleared |
339 | Standard_EXPORT bool ResetErrors (const bool theToPrintErrors = false); | |
5f8b738e | 340 | |
86fa64d9 | 341 | //! This method uses system-dependent API to retrieve information |
342 | //! about GL context bound to the current thread. | |
343 | //! @return true if current thread is bound to this GL context | |
344 | Standard_EXPORT Standard_Boolean IsCurrent() const; | |
345 | ||
2bd4c032 | 346 | //! Activates current context. |
347 | //! Class should be initialized with appropriate info. | |
348 | Standard_EXPORT Standard_Boolean MakeCurrent(); | |
349 | ||
5e27df78 | 350 | //! Swap front/back buffers for this GL context (should be activated before!). |
351 | Standard_EXPORT void SwapBuffers(); | |
352 | ||
f978241f | 353 | //! Setup swap interval (VSync). |
354 | Standard_EXPORT Standard_Boolean SetSwapInterval (const Standard_Integer theInterval); | |
355 | ||
b5ac8292 | 356 | //! Return true if active mode is GL_RENDER (cached state) |
357 | Standard_Boolean IsRender() const | |
358 | { | |
ca3c13d1 | 359 | #if !defined(GL_ES_VERSION_2_0) |
b5ac8292 | 360 | return myRenderMode == GL_RENDER; |
ca3c13d1 | 361 | #else |
362 | return Standard_True; | |
363 | #endif | |
b5ac8292 | 364 | } |
664cae74 | 365 | |
b5ac8292 | 366 | //! Return true if active mode is GL_FEEDBACK (cached state) |
367 | Standard_Boolean IsFeedback() const | |
368 | { | |
ca3c13d1 | 369 | #if !defined(GL_ES_VERSION_2_0) |
b5ac8292 | 370 | return myRenderMode == GL_FEEDBACK; |
ca3c13d1 | 371 | #else |
372 | return Standard_False; | |
373 | #endif | |
b5ac8292 | 374 | } |
664cae74 | 375 | |
f0430952 | 376 | //! This function retrieves information from GL about free GPU memory that is: |
377 | //! - OS-dependent. On some OS it is per-process and on others - for entire system. | |
378 | //! - Vendor-dependent. Currently available only on NVIDIA and AMD/ATi drivers only. | |
379 | //! - Numbers meaning may vary. | |
380 | //! You should use this info only for diagnostics purposes. | |
381 | //! @return free GPU dedicated memory in bytes. | |
382 | Standard_EXPORT Standard_Size AvailableMemory() const; | |
383 | ||
384 | //! This function retrieves information from GL about GPU memory | |
385 | //! and contains more vendor-specific values than AvailableMemory(). | |
386 | Standard_EXPORT TCollection_AsciiString MemoryInfo() const; | |
387 | ||
26d9c835 | 388 | //! This function retrieves information from GL about GPU memory. |
389 | Standard_EXPORT void MemoryInfo (TColStd_IndexedDataMapOfStringString& theDict) const; | |
390 | ||
391 | //! Fill in the dictionary with OpenGL info. | |
392 | //! Should be called with bound context. | |
393 | Standard_EXPORT void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict, | |
394 | Graphic3d_DiagnosticInfo theFlags) const; | |
395 | ||
5e27df78 | 396 | //! Access shared resource by its name. |
397 | //! @param theKey - unique identifier; | |
398 | //! @return handle to shared resource or NULL. | |
399 | Standard_EXPORT const Handle(OpenGl_Resource)& GetResource (const TCollection_AsciiString& theKey) const; | |
400 | ||
401 | //! Access shared resource by its name. | |
402 | //! @param theKey - unique identifier; | |
403 | //! @param theValue - handle to fill; | |
404 | //! @return true if resource was shared. | |
405 | template<typename TheHandleType> | |
406 | Standard_Boolean GetResource (const TCollection_AsciiString& theKey, | |
407 | TheHandleType& theValue) const | |
408 | { | |
409 | const Handle(OpenGl_Resource)& aResource = GetResource (theKey); | |
410 | if (aResource.IsNull()) | |
411 | { | |
412 | return Standard_False; | |
413 | } | |
414 | ||
415 | theValue = TheHandleType::DownCast (aResource); | |
416 | return !theValue.IsNull(); | |
417 | } | |
418 | ||
419 | //! Register shared resource. | |
420 | //! Notice that after registration caller shouldn't release it by himself - | |
421 | //! it will be automatically released on context destruction. | |
422 | //! @param theKey - unique identifier, shouldn't be empty; | |
423 | //! @param theResource - new resource to register, shouldn't be NULL. | |
424 | Standard_EXPORT Standard_Boolean ShareResource (const TCollection_AsciiString& theKey, | |
425 | const Handle(OpenGl_Resource)& theResource); | |
426 | ||
427 | //! Release shared resource. | |
428 | //! If there are more than one reference to this resource | |
429 | //! (also used by some other existing object) then call will be ignored. | |
430 | //! This means that current object itself should nullify handle before this call. | |
431 | //! Notice that this is unrecommended operation at all and should be used | |
432 | //! only in case of fat resources to release memory for other needs. | |
a174a3c5 | 433 | //! @param theKey unique identifier |
434 | //! @param theToDelay postpone release until next redraw call | |
435 | Standard_EXPORT void ReleaseResource (const TCollection_AsciiString& theKey, | |
436 | const Standard_Boolean theToDelay = Standard_False); | |
5e27df78 | 437 | |
438 | //! Append resource to queue for delayed clean up. | |
439 | //! Resources in this queue will be released at next redraw call. | |
aa00364d | 440 | template <class T> |
441 | void DelayedRelease (Handle(T)& theResource) | |
442 | { | |
443 | myUnusedResources->Prepend (theResource); | |
444 | theResource.Nullify(); | |
445 | } | |
5e27df78 | 446 | |
447 | //! Clean up the delayed release queue. | |
448 | Standard_EXPORT void ReleaseDelayed(); | |
449 | ||
15669413 | 450 | //! Return map of shared resources. |
451 | const OpenGl_ResourcesMap& SharedResources() const { return *mySharedResources; } | |
452 | ||
4269bd1b | 453 | //! @return tool for management of clippings within this context. |
30f0ad28 | 454 | inline OpenGl_Clipping& ChangeClipping() { return myClippingState; } |
4269bd1b | 455 | |
456 | //! @return tool for management of clippings within this context. | |
30f0ad28 | 457 | inline const OpenGl_Clipping& Clipping() const { return myClippingState; } |
458 | ||
459 | //! @return tool for management of shader programs within this context. | |
460 | inline const Handle(OpenGl_ShaderManager)& ShaderManager() const { return myShaderManager; } | |
4269bd1b | 461 | |
462 | public: | |
463 | ||
ca3c13d1 | 464 | //! Either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1). |
465 | Standard_Integer TextureWrapClamp() const { return myTexClamp; } | |
466 | ||
bf75be98 | 467 | //! @return maximum degree of anisotropy texture filter |
3c4b62a4 | 468 | Standard_Integer MaxDegreeOfAnisotropy() const { return myAnisoMax; } |
bf75be98 | 469 | |
470 | //! @return value for GL_MAX_TEXTURE_SIZE | |
3c4b62a4 | 471 | Standard_Integer MaxTextureSize() const { return myMaxTexDim; } |
472 | ||
cc8cbabe | 473 | //! @return value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS |
474 | Standard_Integer MaxCombinedTextureUnits() const { return myMaxTexCombined; } | |
475 | ||
3c4b62a4 | 476 | //! @return value for GL_MAX_SAMPLES |
477 | Standard_Integer MaxMsaaSamples() const { return myMaxMsaaSamples; } | |
bf75be98 | 478 | |
6997ff1c | 479 | //! @return maximum FBO width for image dump |
480 | Standard_Integer MaxDumpSizeX() const { return myMaxDumpSizeX; } | |
481 | ||
482 | //! @return maximum FBO height for image dump | |
483 | Standard_Integer MaxDumpSizeY() const { return myMaxDumpSizeY; } | |
484 | ||
a1073ae2 | 485 | //! @return value for GL_MAX_DRAW_BUFFERS |
486 | Standard_Integer MaxDrawBuffers() const { return myMaxDrawBuffers; } | |
487 | ||
488 | //! @return value for GL_MAX_COLOR_ATTACHMENTS | |
489 | Standard_Integer MaxColorAttachments() const { return myMaxColorAttachments; } | |
490 | ||
4269bd1b | 491 | //! Get maximum number of clip planes supported by OpenGl. |
7e7c2f0b | 492 | //! This value is implementation dependent. At least 6 |
4269bd1b | 493 | //! planes should be supported by OpenGl (see specs). |
494 | //! @return value for GL_MAX_CLIP_PLANES | |
3c4b62a4 | 495 | Standard_Integer MaxClipPlanes() const { return myMaxClipPlanes; } |
4269bd1b | 496 | |
3a9b5dc8 | 497 | //! @return TRUE if ray tracing mode is supported |
498 | Standard_Boolean HasRayTracing() const { return myHasRayTracing; } | |
499 | ||
500 | //! @return TRUE if textures in ray tracing mode are supported | |
501 | Standard_Boolean HasRayTracingTextures() const { return myHasRayTracingTextures; } | |
502 | ||
503 | //! @return TRUE if adaptive screen sampling in ray tracing mode is supported | |
504 | Standard_Boolean HasRayTracingAdaptiveSampling() const { return myHasRayTracingAdaptiveSampling; } | |
505 | ||
e084dbbc | 506 | //! @return TRUE if atomic adaptive screen sampling in ray tracing mode is supported |
507 | Standard_Boolean HasRayTracingAdaptiveSamplingAtomic() const { return myHasRayTracingAdaptiveSamplingAtomic; } | |
508 | ||
7d3e64ef | 509 | //! Returns true if VBO is supported and permitted. |
510 | inline bool ToUseVbo() const | |
511 | { | |
512 | return core15fwd != NULL | |
513 | && !caps->vboDisable; | |
514 | } | |
515 | ||
7d9e854b | 516 | //! @return cached state of GL_NORMALIZE. |
517 | Standard_Boolean IsGlNormalizeEnabled() const { return myIsGlNormalizeEnabled; } | |
518 | ||
519 | //! Sets GL_NORMALIZE enabled or disabled. | |
520 | //! @return old value of the flag | |
521 | Standard_EXPORT Standard_Boolean SetGlNormalizeEnabled (Standard_Boolean isEnabled); | |
522 | ||
6d0e6be5 | 523 | //! @return cached state of polygon rasterization mode (glPolygonMode()). |
524 | Standard_Integer PolygonMode() const { return myPolygonMode; } | |
525 | ||
526 | //! Sets polygon rasterization mode (glPolygonMode() function). | |
527 | //! @return old value of the rasterization mode. | |
528 | Standard_EXPORT Standard_Integer SetPolygonMode (const Standard_Integer theMode); | |
529 | ||
530 | //! @return cached enabled state of polygon hatching rasterization. | |
531 | bool IsPolygonHatchEnabled() const | |
532 | { | |
533 | return !myHatchStyles.IsNull() && myHatchStyles->TypeOfHatch() != 0; | |
534 | } | |
535 | ||
536 | //! Sets enabled state of polygon hatching rasterization | |
537 | //! without affecting currently selected hatching pattern. | |
538 | //! @return previous state of polygon hatching mode. | |
539 | Standard_EXPORT bool SetPolygonHatchEnabled (const bool theIsEnabled); | |
540 | ||
541 | //! @return cached state of polygon hatch type. | |
542 | Standard_Integer PolygonHatchStyle() const | |
543 | { | |
544 | return myHatchStyles.IsNull() ? Aspect_HS_SOLID : myHatchStyles->TypeOfHatch(); | |
545 | } | |
546 | ||
547 | //! Sets polygon hatch pattern. | |
548 | //! Zero-index value is a default alias for solid filling. | |
549 | //! @param the type of hatch supported by base implementation of | |
550 | //! OpenGl_LineAttributes (Aspect_HatchStyle) or the type supported by custom | |
551 | //! implementation derived from OpenGl_LineAttributes class. | |
552 | //! @return old type of hatch. | |
640d5fe2 | 553 | Standard_EXPORT Standard_Integer SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle); |
6d0e6be5 | 554 | |
8d1a539c | 555 | //! Sets and applies current polygon offset. |
556 | Standard_EXPORT void SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset); | |
557 | ||
558 | //! Returns currently applied polygon offset parameters. | |
559 | const Graphic3d_PolygonOffset& PolygonOffset() const { return myPolygonOffset; } | |
560 | ||
c827ea3a | 561 | //! Applies matrix stored in ModelWorldState to OpenGl. |
5e94009d | 562 | Standard_EXPORT void ApplyModelWorldMatrix(); |
c827ea3a | 563 | |
564 | //! Applies matrix stored in WorldViewState to OpenGl. | |
5e94009d | 565 | Standard_EXPORT void ApplyWorldViewMatrix(); |
c827ea3a | 566 | |
567 | //! Applies combination of matrices stored in ModelWorldState and WorldViewState to OpenGl. | |
5e94009d | 568 | Standard_EXPORT void ApplyModelViewMatrix(); |
c827ea3a | 569 | |
570 | //! Applies matrix stored in ProjectionState to OpenGl. | |
5e94009d | 571 | Standard_EXPORT void ApplyProjectionMatrix(); |
c827ea3a | 572 | |
cbf18624 | 573 | public: |
574 | ||
7e7c2f0b | 575 | //! @return messenger instance |
857ffd5e | 576 | inline const Handle(Message_Messenger)& Messenger() const |
cbf18624 | 577 | { |
8fa64b52 | 578 | return ::Message::DefaultMessenger(); |
cbf18624 | 579 | } |
580 | ||
581 | //! Callback for GL_ARB_debug_output extension | |
582 | //! @param theSource message source within GL_DEBUG_SOURCE_ enumeration | |
583 | //! @param theType message type within GL_DEBUG_TYPE_ enumeration | |
584 | //! @param theId message ID within source | |
585 | //! @param theSeverity message severity within GL_DEBUG_SEVERITY_ enumeration | |
586 | //! @param theMessage the message itself | |
587 | Standard_EXPORT void PushMessage (const unsigned int theSource, | |
588 | const unsigned int theType, | |
589 | const unsigned int theId, | |
590 | const unsigned int theSeverity, | |
591 | const TCollection_ExtendedString& theMessage); | |
592 | ||
c87535af | 593 | //! Adds a filter for messages with theId and theSource (GL_DEBUG_SOURCE_) |
594 | Standard_EXPORT Standard_Boolean ExcludeMessage (const unsigned int theSource, | |
595 | const unsigned int theId); | |
b5ac8292 | 596 | |
c87535af | 597 | //! Removes a filter for messages with theId and theSource (GL_DEBUG_SOURCE_) |
598 | Standard_EXPORT Standard_Boolean IncludeMessage (const unsigned int theSource, | |
599 | const unsigned int theId); | |
b5ac8292 | 600 | |
601 | //! @return true if OpenGl context supports left and | |
602 | //! right rendering buffers. | |
603 | Standard_Boolean HasStereoBuffers() const | |
604 | { | |
ca3c13d1 | 605 | #if !defined(GL_ES_VERSION_2_0) |
b5ac8292 | 606 | return myIsStereoBuffers; |
ca3c13d1 | 607 | #else |
608 | return Standard_False; | |
609 | #endif | |
b5ac8292 | 610 | } |
611 | ||
7d3e64ef | 612 | public: //! @name methods to alter or retrieve current state |
613 | ||
15669413 | 614 | //! Return structure holding frame statistics. |
615 | const Handle(OpenGl_FrameStats)& FrameStats() const { return myFrameStats; } | |
616 | ||
5e30547b | 617 | //! Set structure holding frame statistics. |
618 | //! This call makes sense only if application defines OpenGl_FrameStats sub-class. | |
619 | void SetFrameStats (const Handle(OpenGl_FrameStats)& theStats) { myFrameStats = theStats; } | |
620 | ||
3bffef55 | 621 | //! Return cached viewport definition (x, y, width, height). |
622 | const Standard_Integer* Viewport() const { return myViewport; } | |
623 | ||
624 | //! Resize the viewport (alias for glViewport). | |
625 | //! @param theRect viewport definition (x, y, width, height) | |
626 | Standard_EXPORT void ResizeViewport (const Standard_Integer theRect[4]); | |
627 | ||
56689b27 | 628 | //! Return virtual viewport definition (x, y, width, height). |
629 | const Standard_Integer* VirtualViewport() const { return myViewportVirt; } | |
630 | ||
38a0206f | 631 | //! Return active read buffer. |
632 | Standard_Integer ReadBuffer() { return myReadBuffer; } | |
b5ac8292 | 633 | |
38a0206f | 634 | //! Switch read buffer, wrapper for ::glReadBuffer(). |
635 | Standard_EXPORT void SetReadBuffer (const Standard_Integer theReadBuffer); | |
b5ac8292 | 636 | |
a1073ae2 | 637 | //! Return active draw buffer attached to a render target referred by index (layout location). |
c3487460 | 638 | Standard_Integer DrawBuffer (Standard_Integer theIndex = 0) const |
a1073ae2 | 639 | { |
c3487460 | 640 | return theIndex >= myDrawBuffers.Lower() |
641 | && theIndex <= myDrawBuffers.Upper() | |
642 | ? myDrawBuffers.Value (theIndex) | |
643 | : GL_NONE; | |
a1073ae2 | 644 | } |
38a0206f | 645 | |
646 | //! Switch draw buffer, wrapper for ::glDrawBuffer(). | |
647 | Standard_EXPORT void SetDrawBuffer (const Standard_Integer theDrawBuffer); | |
648 | ||
a1073ae2 | 649 | //! Switch draw buffer, wrapper for ::glDrawBuffers (GLsizei, const GLenum*). |
650 | Standard_EXPORT void SetDrawBuffers (const Standard_Integer theNb, const Standard_Integer* theDrawBuffers); | |
651 | ||
38a0206f | 652 | //! Switch read/draw buffers. |
653 | void SetReadDrawBuffer (const Standard_Integer theBuffer) | |
654 | { | |
655 | SetReadBuffer (theBuffer); | |
656 | SetDrawBuffer (theBuffer); | |
657 | } | |
b5ac8292 | 658 | |
f88457e6 | 659 | //! Return cached flag indicating writing into color buffer is enabled or disabled (glColorMask). |
660 | bool ColorMask() const { return myColorMask; } | |
661 | ||
662 | //! Enable/disable writing into color buffer (wrapper for glColorMask). | |
663 | Standard_EXPORT bool SetColorMask (bool theToWriteColor); | |
664 | ||
2a332745 | 665 | //! Return TRUE if GL_SAMPLE_ALPHA_TO_COVERAGE usage is allowed. |
666 | bool AllowSampleAlphaToCoverage() const { return myAllowAlphaToCov; } | |
667 | ||
668 | //! Allow GL_SAMPLE_ALPHA_TO_COVERAGE usage. | |
669 | void SetAllowSampleAlphaToCoverage (bool theToEnable) { myAllowAlphaToCov = theToEnable; } | |
670 | ||
c40eb6b9 | 671 | //! Return GL_SAMPLE_ALPHA_TO_COVERAGE state. |
672 | bool SampleAlphaToCoverage() const { return myAlphaToCoverage; } | |
673 | ||
674 | //! Enable/disable GL_SAMPLE_ALPHA_TO_COVERAGE. | |
675 | Standard_EXPORT bool SetSampleAlphaToCoverage (bool theToEnable); | |
676 | ||
b6472664 | 677 | //! Return back face culling state. |
678 | bool ToCullBackFaces() const { return myToCullBackFaces; } | |
679 | ||
680 | //! Enable or disable back face culling (glEnable (GL_CULL_FACE)). | |
681 | Standard_EXPORT void SetCullBackFaces (bool theToEnable); | |
682 | ||
b5ac8292 | 683 | //! Fetch OpenGl context state. This class tracks value of several OpenGl |
684 | //! state variables. Consulting the cached values is quicker than | |
685 | //! doing the same via OpenGl API. Call this method if any of the controlled | |
686 | //! OpenGl state variables has a possibility of being out-of-date. | |
687 | Standard_EXPORT void FetchState(); | |
688 | ||
cc8cbabe | 689 | //! @return active textures |
690 | const Handle(OpenGl_TextureSet)& ActiveTextures() const { return myActiveTextures; } | |
691 | ||
692 | //! Bind specified texture set to current context, | |
693 | //! or unbind previous one when NULL specified. | |
694 | Standard_EXPORT Handle(OpenGl_TextureSet) BindTextures (const Handle(OpenGl_TextureSet)& theTextures); | |
695 | ||
7d3e64ef | 696 | //! @return active GLSL program |
697 | const Handle(OpenGl_ShaderProgram)& ActiveProgram() const | |
698 | { | |
699 | return myActiveProgram; | |
700 | } | |
701 | ||
702 | //! Bind specified program to current context, | |
703 | //! or unbind previous one when NULL specified. | |
8625ef7e | 704 | //! @return true if some program is bound to context |
705 | Standard_EXPORT Standard_Boolean BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram); | |
706 | ||
299e0ab9 | 707 | //! Setup current shading material. |
bf5f0ca2 | 708 | Standard_EXPORT void SetShadingMaterial (const OpenGl_Aspects* theAspect, |
a1073ae2 | 709 | const Handle(Graphic3d_PresentationAttributes)& theHighlight); |
710 | ||
711 | //! Checks if transparency is required for the given aspect and highlight style. | |
bf5f0ca2 | 712 | Standard_EXPORT static Standard_Boolean CheckIsTransparent (const OpenGl_Aspects* theAspect, |
a1073ae2 | 713 | const Handle(Graphic3d_PresentationAttributes)& theHighlight, |
a71a71de | 714 | Standard_ShortReal& theAlphaFront, |
715 | Standard_ShortReal& theAlphaBack); | |
716 | ||
717 | //! Checks if transparency is required for the given aspect and highlight style. | |
bf5f0ca2 | 718 | static Standard_Boolean CheckIsTransparent (const OpenGl_Aspects* theAspect, |
a71a71de | 719 | const Handle(Graphic3d_PresentationAttributes)& theHighlight) |
720 | { | |
721 | Standard_ShortReal anAlphaFront = 1.0f, anAlphaBack = 1.0f; | |
722 | return CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack); | |
723 | } | |
299e0ab9 | 724 | |
8625ef7e | 725 | //! Setup current color. |
726 | Standard_EXPORT void SetColor4fv (const OpenGl_Vec4& theColor); | |
727 | ||
ac116c22 | 728 | //! Setup type of line. |
729 | Standard_EXPORT void SetTypeOfLine (const Aspect_TypeOfLine theType, | |
730 | const Standard_ShortReal theFactor = 1.0f); | |
731 | ||
732 | //! Setup width of line. | |
733 | Standard_EXPORT void SetLineWidth (const Standard_ShortReal theWidth); | |
734 | ||
8625ef7e | 735 | //! Setup point size. |
736 | Standard_EXPORT void SetPointSize (const Standard_ShortReal theSize); | |
7d3e64ef | 737 | |
fd59283a | 738 | //! Setup point sprite origin using GL_POINT_SPRITE_COORD_ORIGIN state: |
739 | //! - GL_UPPER_LEFT when GLSL program is active; | |
740 | //! flipping should be handled in GLSL program for compatibility with OpenGL ES | |
741 | //! - GL_LOWER_LEFT for FFP | |
742 | Standard_EXPORT void SetPointSpriteOrigin(); | |
743 | ||
79f4f036 | 744 | //! Setup texture matrix to active GLSL program or to FFP global state using glMatrixMode (GL_TEXTURE). |
745 | Standard_EXPORT void SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams); | |
746 | ||
4e1523ef | 747 | //! Bind default Vertex Array Object |
748 | Standard_EXPORT void BindDefaultVao(); | |
749 | ||
a2e4f780 | 750 | //! Default Frame Buffer Object. |
751 | const Handle(OpenGl_FrameBuffer)& DefaultFrameBuffer() const | |
752 | { | |
753 | return myDefaultFbo; | |
754 | } | |
755 | ||
756 | //! Setup new Default Frame Buffer Object and return previously set. | |
757 | //! This call doesn't change Active FBO! | |
758 | Standard_EXPORT Handle(OpenGl_FrameBuffer) SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo); | |
759 | ||
4e1523ef | 760 | //! Return debug context initialization state. |
761 | Standard_Boolean IsDebugContext() const | |
762 | { | |
763 | return myIsGlDebugCtx; | |
764 | } | |
765 | ||
c357e426 | 766 | Standard_EXPORT void EnableFeatures() const; |
767 | ||
768 | Standard_EXPORT void DisableFeatures() const; | |
769 | ||
56689b27 | 770 | //! Return resolution for rendering text. |
771 | unsigned int Resolution() const { return myResolution; } | |
772 | ||
773 | //! Resolution scale factor (rendered resolution to standard resolution). | |
774 | //! This scaling factor for parameters like text size to be properly displayed on device (screen / printer). | |
775 | Standard_ShortReal ResolutionRatio() const { return myResolutionRatio; } | |
776 | ||
777 | //! Rendering scale factor (rendering viewport height to real window buffer height). | |
778 | Standard_ShortReal RenderScale() const { return myRenderScale; } | |
779 | ||
780 | //! Return TRUE if rendering scale factor is not 1. | |
781 | Standard_Boolean HasRenderScale() const { return Abs (myRenderScale - 1.0f) > 0.0001f; } | |
782 | ||
783 | //! Rendering scale factor (inverted value). | |
784 | Standard_ShortReal RenderScaleInv() const { return myRenderScaleInv; } | |
785 | ||
2a332745 | 786 | //! Return scale factor for line width. |
787 | Standard_ShortReal LineWidthScale() const { return myLineWidthScale; } | |
788 | ||
56689b27 | 789 | //! Set resolution ratio. |
790 | //! Note that this method rounds @theRatio to nearest integer. | |
791 | void SetResolution (unsigned int theResolution, | |
792 | Standard_ShortReal theRatio, | |
793 | Standard_ShortReal theScale) | |
794 | { | |
795 | myResolution = (unsigned int )(theScale * theResolution + 0.5f); | |
796 | myRenderScale = theScale; | |
797 | myRenderScaleInv = 1.0f / theScale; | |
798 | SetResolutionRatio (theRatio * theScale); | |
799 | } | |
800 | ||
75c262a9 | 801 | //! Set resolution ratio. |
802 | //! Note that this method rounds @theRatio to nearest integer. | |
803 | void SetResolutionRatio (const Standard_ShortReal theRatio) | |
804 | { | |
56689b27 | 805 | myResolutionRatio = theRatio; |
806 | myLineWidthScale = Max (1.0f, std::floor (theRatio + 0.5f)); | |
75c262a9 | 807 | } |
808 | ||
2a332745 | 809 | //! Return line feater width in pixels. |
810 | Standard_ShortReal LineFeather() const { return myLineFeather; } | |
811 | ||
812 | //! Set line feater width. | |
813 | void SetLineFeather(Standard_ShortReal theValue) { myLineFeather = theValue; } | |
814 | ||
c39bb31b | 815 | //! Return Graphics Driver's vendor. |
816 | const TCollection_AsciiString& Vendor() const { return myVendor; } | |
817 | ||
5f8b738e | 818 | private: |
819 | ||
820 | //! Wrapper to system function to retrieve GL function pointer by name. | |
821 | Standard_EXPORT void* findProc (const char* theFuncName); | |
822 | ||
ee51a9fe | 823 | //! Print error if not all functions have been exported by context for reported version. |
824 | //! Note that this will never happen when using GLX, since returned functions can not be validated. | |
825 | //! @param theGlVerMajor the OpenGL major version with missing functions | |
826 | //! @param theGlVerMinor the OpenGL minor version with missing functions | |
827 | Standard_EXPORT void checkWrongVersion (const Standard_Integer theGlVerMajor, | |
828 | const Standard_Integer theGlVerMinor); | |
829 | ||
5f8b738e | 830 | //! Private initialization function that should be called only once. |
4e1523ef | 831 | Standard_EXPORT void init (const Standard_Boolean theIsCoreProfile); |
5f8b738e | 832 | |
01ca42b2 | 833 | public: //! @name core profiles |
834 | ||
835 | OpenGl_GlCore11* core11; //!< OpenGL 1.1 core functionality | |
836 | OpenGl_GlCore11Fwd* core11fwd; //!< OpenGL 1.1 without deprecated entry points | |
837 | OpenGl_GlCore15* core15; //!< OpenGL 1.5 core functionality | |
838 | OpenGl_GlCore15Fwd* core15fwd; //!< OpenGL 1.5 without deprecated entry points | |
839 | OpenGl_GlCore20* core20; //!< OpenGL 2.0 core functionality (includes 1.5) | |
840 | OpenGl_GlCore20Fwd* core20fwd; //!< OpenGL 2.0 without deprecated entry points | |
841 | OpenGl_GlCore32* core32; //!< OpenGL 3.2 core profile | |
842 | OpenGl_GlCore32Back* core32back; //!< OpenGL 3.2 backward compatibility profile | |
25ef750e | 843 | OpenGl_GlCore33* core33; //!< OpenGL 3.3 core profile |
844 | OpenGl_GlCore33Back* core33back; //!< OpenGL 3.3 backward compatibility profile | |
01ca42b2 | 845 | OpenGl_GlCore41* core41; //!< OpenGL 4.1 core profile |
846 | OpenGl_GlCore41Back* core41back; //!< OpenGL 4.1 backward compatibility profile | |
847 | OpenGl_GlCore42* core42; //!< OpenGL 4.2 core profile | |
848 | OpenGl_GlCore42Back* core42back; //!< OpenGL 4.2 backward compatibility profile | |
849 | OpenGl_GlCore43* core43; //!< OpenGL 4.3 core profile | |
850 | OpenGl_GlCore43Back* core43back; //!< OpenGL 4.3 backward compatibility profile | |
851 | OpenGl_GlCore44* core44; //!< OpenGL 4.4 core profile | |
852 | OpenGl_GlCore44Back* core44back; //!< OpenGL 4.4 backward compatibility profile | |
5f8b738e | 853 | |
58655684 | 854 | Handle(OpenGl_Caps) caps; //!< context options |
855 | ||
01ca42b2 | 856 | public: //! @name extensions |
5f8b738e | 857 | |
a1073ae2 | 858 | Standard_Boolean hasHighp; //!< highp in GLSL ES fragment shader is supported |
859 | Standard_Boolean hasUintIndex; //!< GLuint for index buffer is supported (always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_element_index_uint) | |
860 | Standard_Boolean hasTexRGBA8; //!< always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_rgb8_rgba8 | |
c39bb31b | 861 | OpenGl_FeatureFlag hasFlatShading; //!< Complex flag indicating support of Flat shading (Graphic3d_TOSM_FACET) (always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_standard_derivatives) |
a1073ae2 | 862 | OpenGl_FeatureFlag hasDrawBuffers; //!< Complex flag indicating support of multiple draw buffers (desktop OpenGL 2.0, OpenGL ES 3.0, GL_ARB_draw_buffers, GL_EXT_draw_buffers) |
863 | OpenGl_FeatureFlag hasFloatBuffer; //!< Complex flag indicating support of float color buffer format (desktop OpenGL 3.0, GL_ARB_color_buffer_float, GL_EXT_color_buffer_float) | |
864 | OpenGl_FeatureFlag hasHalfFloatBuffer; //!< Complex flag indicating support of half-float color buffer format (desktop OpenGL 3.0, GL_ARB_color_buffer_float, GL_EXT_color_buffer_half_float) | |
865 | OpenGl_FeatureFlag hasSampleVariables; //!< Complex flag indicating support of MSAA variables in GLSL shader (desktop OpenGL 4.0, GL_ARB_sample_shading) | |
2a332745 | 866 | OpenGl_FeatureFlag hasGeometryStage; //!< Complex flag indicating support of Geometry shader (desktop OpenGL 3.2, OpenGL ES 3.2, GL_EXT_geometry_shader) |
a1073ae2 | 867 | Standard_Boolean arbDrawBuffers; //!< GL_ARB_draw_buffers |
868 | Standard_Boolean arbNPTW; //!< GL_ARB_texture_non_power_of_two | |
869 | Standard_Boolean arbTexRG; //!< GL_ARB_texture_rg | |
870 | Standard_Boolean arbTexFloat; //!< GL_ARB_texture_float (on desktop OpenGL - since 3.0 or as extension GL_ARB_texture_float; on OpenGL ES - since 3.0) | |
cc8cbabe | 871 | OpenGl_ArbSamplerObject* arbSamplerObject; //!< GL_ARB_sampler_objects (on desktop OpenGL - since 3.3 or as extension GL_ARB_sampler_objects; on OpenGL ES - since 3.0) |
a1073ae2 | 872 | OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture |
873 | OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object | |
874 | Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0 | |
875 | OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced | |
876 | OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output | |
877 | OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object | |
878 | OpenGl_ArbFBOBlit* arbFBOBlit; //!< glBlitFramebuffer function, moved out from OpenGl_ArbFBO structure for compatibility with OpenGL ES 2.0 | |
879 | Standard_Boolean arbSampleShading; //!< GL_ARB_sample_shading | |
880 | Standard_Boolean extFragDepth; //!< GL_EXT_frag_depth on OpenGL ES 2.0 (gl_FragDepthEXT built-in variable, before OpenGL ES 3.0) | |
881 | Standard_Boolean extDrawBuffers; //!< GL_EXT_draw_buffers | |
882 | OpenGl_ExtGS* extGS; //!< GL_EXT_geometry_shader4 | |
883 | Standard_Boolean extBgra; //!< GL_EXT_bgra or GL_EXT_texture_format_BGRA8888 on OpenGL ES | |
884 | Standard_Boolean extAnis; //!< GL_EXT_texture_filter_anisotropic | |
885 | Standard_Boolean extPDS; //!< GL_EXT_packed_depth_stencil | |
886 | Standard_Boolean atiMem; //!< GL_ATI_meminfo | |
887 | Standard_Boolean nvxMem; //!< GL_NVX_gpu_memory_info | |
888 | Standard_Boolean oesSampleVariables; //!< GL_OES_sample_variables | |
8c3237d4 | 889 | Standard_Boolean oesStdDerivatives; //!< GL_OES_standard_derivatives |
5f8b738e | 890 | |
8613985b | 891 | public: //! @name public properties tracking current state |
892 | ||
893 | OpenGl_MatrixState<Standard_ShortReal> ModelWorldState; //!< state of orientation matrix | |
894 | OpenGl_MatrixState<Standard_ShortReal> WorldViewState; //!< state of orientation matrix | |
895 | OpenGl_MatrixState<Standard_ShortReal> ProjectionState; //!< state of projection matrix | |
896 | ||
5e27df78 | 897 | private: // system-dependent fields |
2166f0fa | 898 | |
da8bb41d | 899 | #if defined(HAVE_EGL) |
900 | Aspect_Drawable myWindow; //!< EGL surface : EGLSurface | |
901 | Aspect_Display myDisplay; //!< EGL connection to the Display : EGLDisplay | |
902 | Aspect_RenderingContext myGContext; //!< EGL rendering context : EGLContext | |
903 | #elif defined(_WIN32) | |
2bd4c032 | 904 | Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND |
905 | Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC | |
906 | Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC | |
4fe56619 | 907 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 908 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
909 | EAGLContext* myGContext; //!< Rendering Context handle | |
910 | #else | |
911 | NSOpenGLContext* myGContext; //!< Rendering Context handle | |
912 | #endif | |
2bd4c032 | 913 | #else |
914 | Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable | |
915 | Aspect_Display myDisplay; //!< connection to the X-server : Display* | |
916 | Aspect_RenderingContext myGContext; //!< X-GLX rendering context : GLXContext | |
917 | #endif | |
918 | ||
5e27df78 | 919 | private: // context info |
920 | ||
c04c30b3 | 921 | typedef NCollection_Shared< NCollection_DataMap<TCollection_AsciiString, Standard_Integer> > OpenGl_DelayReleaseMap; |
c04c30b3 | 922 | typedef NCollection_Shared< NCollection_List<Handle(OpenGl_Resource)> > OpenGl_ResourcesStack; |
5e27df78 | 923 | |
a174a3c5 | 924 | Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key |
925 | Handle(OpenGl_DelayReleaseMap) myDelayed; //!< shared resources for delayed release | |
3125ebb6 | 926 | Handle(OpenGl_ResourcesStack) myUnusedResources; //!< stack of resources for delayed clean up |
5e27df78 | 927 | |
30f0ad28 | 928 | OpenGl_Clipping myClippingState; //!< state of clip planes |
4269bd1b | 929 | |
7d9e854b | 930 | void* myGlLibHandle; //!< optional handle to GL library |
01ca42b2 | 931 | NCollection_Handle<OpenGl_GlFunctions> |
7d9e854b | 932 | myFuncs; //!< mega structure for all GL functions |
933 | Standard_Integer myAnisoMax; //!< maximum level of anisotropy texture filter | |
934 | Standard_Integer myTexClamp; //!< either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1) | |
935 | Standard_Integer myMaxTexDim; //!< value for GL_MAX_TEXTURE_SIZE | |
cc8cbabe | 936 | Standard_Integer myMaxTexCombined; //!< value for GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS |
6997ff1c | 937 | Standard_Integer myMaxDumpSizeX; //!< maximum FBO width for image dump |
938 | Standard_Integer myMaxDumpSizeY; //!< maximum FBO height for image dump | |
7d9e854b | 939 | Standard_Integer myMaxClipPlanes; //!< value for GL_MAX_CLIP_PLANES |
3c4b62a4 | 940 | Standard_Integer myMaxMsaaSamples; //!< value for GL_MAX_SAMPLES |
a1073ae2 | 941 | Standard_Integer myMaxDrawBuffers; //!< value for GL_MAX_DRAW_BUFFERS |
942 | Standard_Integer myMaxColorAttachments; //!< value for GL_MAX_COLOR_ATTACHMENTS | |
7d9e854b | 943 | Standard_Integer myGlVerMajor; //!< cached GL version major number |
944 | Standard_Integer myGlVerMinor; //!< cached GL version minor number | |
945 | Standard_Boolean myIsInitialized; //!< flag indicates initialization state | |
946 | Standard_Boolean myIsStereoBuffers; //!< context supports stereo buffering | |
947 | Standard_Boolean myIsGlNormalizeEnabled; //!< GL_NORMALIZE flag | |
948 | //!< Used to tell OpenGl that normals should be normalized | |
2166f0fa | 949 | |
e084dbbc | 950 | Standard_Boolean myHasRayTracing; //! indicates whether ray tracing mode is supported |
951 | Standard_Boolean myHasRayTracingTextures; //! indicates whether textures in ray tracing mode are supported | |
952 | Standard_Boolean myHasRayTracingAdaptiveSampling; //! indicates whether adaptive screen sampling in ray tracing mode is supported | |
953 | Standard_Boolean myHasRayTracingAdaptiveSamplingAtomic; //! indicates whether atomic adaptive screen sampling in ray tracing mode is supported | |
3a9b5dc8 | 954 | |
30f0ad28 | 955 | Handle(OpenGl_ShaderManager) myShaderManager; //! support object for managing shader programs |
956 | ||
7d3e64ef | 957 | private: //! @name fields tracking current state |
958 | ||
15669413 | 959 | Handle(OpenGl_FrameStats) myFrameStats; //!< structure accumulating frame statistics |
6d0e6be5 | 960 | Handle(OpenGl_ShaderProgram) myActiveProgram; //!< currently active GLSL program |
cc8cbabe | 961 | Handle(OpenGl_TextureSet) myActiveTextures; //!< currently bound textures |
962 | //!< currently active sampler objects | |
6d0e6be5 | 963 | Handle(OpenGl_FrameBuffer) myDefaultFbo; //!< default Frame Buffer Object |
964 | Handle(OpenGl_LineAttributes) myHatchStyles; //!< resource holding predefined hatch styles patterns | |
3bffef55 | 965 | Standard_Integer myViewport[4]; //!< current viewport |
56689b27 | 966 | Standard_Integer myViewportVirt[4]; //!< virtual viewport |
6d0e6be5 | 967 | Standard_Integer myPointSpriteOrig; //!< GL_POINT_SPRITE_COORD_ORIGIN state (GL_UPPER_LEFT by default) |
968 | Standard_Integer myRenderMode; //!< value for active rendering mode | |
969 | Standard_Integer myPolygonMode; //!< currently used polygon rasterization mode (glPolygonMode) | |
8d1a539c | 970 | Graphic3d_PolygonOffset myPolygonOffset; //!< currently applied polygon offset |
6d0e6be5 | 971 | bool myToCullBackFaces; //!< back face culling mode enabled state (glIsEnabled (GL_CULL_FACE)) |
972 | Standard_Integer myReadBuffer; //!< current read buffer | |
c3487460 | 973 | NCollection_Array1<Standard_Integer> |
974 | myDrawBuffers; //!< current draw buffers | |
6d0e6be5 | 975 | unsigned int myDefaultVao; //!< default Vertex Array Object |
f88457e6 | 976 | Standard_Boolean myColorMask; //!< flag indicating writing into color buffer is enabled or disabled (glColorMask) |
2a332745 | 977 | Standard_Boolean myAllowAlphaToCov; //!< flag allowing GL_SAMPLE_ALPHA_TO_COVERAGE usage |
c40eb6b9 | 978 | Standard_Boolean myAlphaToCoverage; //!< flag indicating GL_SAMPLE_ALPHA_TO_COVERAGE state |
6d0e6be5 | 979 | Standard_Boolean myIsGlDebugCtx; //!< debug context initialization state |
980 | TCollection_AsciiString myVendor; //!< Graphics Driver's vendor | |
981 | TColStd_PackedMapOfInteger myFilters[6]; //!< messages suppressing filter (for sources from GL_DEBUG_SOURCE_API_ARB to GL_DEBUG_SOURCE_OTHER_ARB) | |
56689b27 | 982 | unsigned int myResolution; //!< Pixels density (PPI), defines scaling factor for parameters like text size |
6d0e6be5 | 983 | Standard_ShortReal myResolutionRatio; //!< scaling factor for parameters like text size |
56689b27 | 984 | //! to be properly displayed on device (screen / printer) |
985 | Standard_ShortReal myLineWidthScale; //!< scaling factor for line width | |
2a332745 | 986 | Standard_ShortReal myLineFeather; //!< line feater width in pixels |
56689b27 | 987 | Standard_ShortReal myRenderScale; //!< scaling factor for rendering resolution |
988 | Standard_ShortReal myRenderScaleInv; //!< scaling factor for rendering resolution (inverted value) | |
8613985b | 989 | OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates) |
990 | OpenGl_Material myMatBack; //!< current back material state | |
c827ea3a | 991 | |
5e27df78 | 992 | private: |
993 | ||
994 | //! Copying allowed only within Handles | |
995 | OpenGl_Context (const OpenGl_Context& ); | |
996 | OpenGl_Context& operator= (const OpenGl_Context& ); | |
997 | ||
2166f0fa SK |
998 | }; |
999 | ||
1000 | #endif // _OpenGl_Context_H__ |