1 // Created on: 2012-01-26
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_Context_H__
17 #define _OpenGl_Context_H__
19 #include <Aspect_Handle.hxx>
20 #include <Aspect_Drawable.hxx>
21 #include <Aspect_Display.hxx>
22 #include <Aspect_RenderingContext.hxx>
23 #include <Handle_OpenGl_Context.hxx>
24 #include <Handle_OpenGl_Sampler.hxx>
25 #include <Handle_OpenGl_ShaderManager.hxx>
26 #include <Handle_OpenGl_ShaderProgram.hxx>
27 #include <NCollection_DataMap.hxx>
28 #include <NCollection_Map.hxx>
29 #include <NCollection_Handle.hxx>
30 #include <NCollection_List.hxx>
31 #include <Message.hxx>
32 #include <OpenGl_Caps.hxx>
33 #include <OpenGl_Vec.hxx>
34 #include <OpenGl_Resource.hxx>
35 #include <Standard_Transient.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <Handle_OpenGl_Context.hxx>
38 #include <OpenGl_Clipping.hxx>
39 #include <OpenGl_GlCore11.hxx>
40 #include <OpenGl_Utils.hxx>
42 //! Forward declarations
43 struct OpenGl_GlFunctions;
48 struct OpenGl_ArbFBOBlit;
50 struct OpenGl_ArbTexBindless;
52 template<typename theBaseClass_t> struct OpenGl_TmplCore12;
53 typedef OpenGl_TmplCore12<OpenGl_GlCore11> OpenGl_GlCore12;
54 typedef OpenGl_TmplCore12<OpenGl_GlCore11Fwd> OpenGl_GlCore12Fwd;
56 struct OpenGl_GlCore13;
57 struct OpenGl_GlCore13Fwd;
59 template<typename theBaseClass_t> struct OpenGl_TmplCore14;
60 typedef OpenGl_TmplCore14<OpenGl_GlCore13> OpenGl_GlCore14;
61 typedef OpenGl_TmplCore14<OpenGl_GlCore13Fwd> OpenGl_GlCore14Fwd;
63 template<typename theBaseClass_t> struct OpenGl_TmplCore15;
64 typedef OpenGl_TmplCore15<OpenGl_GlCore14> OpenGl_GlCore15;
65 typedef OpenGl_TmplCore15<OpenGl_GlCore14Fwd> OpenGl_GlCore15Fwd;
67 template<typename theBaseClass_t> struct OpenGl_TmplCore20;
68 typedef OpenGl_TmplCore20<OpenGl_GlCore15> OpenGl_GlCore20;
69 typedef OpenGl_TmplCore20<OpenGl_GlCore15Fwd> OpenGl_GlCore20Fwd;
71 template<typename theBaseClass_t> struct OpenGl_TmplCore21;
72 typedef OpenGl_TmplCore21<OpenGl_GlCore20> OpenGl_GlCore21;
73 typedef OpenGl_TmplCore21<OpenGl_GlCore20Fwd> OpenGl_GlCore21Fwd;
75 template<typename theBaseClass_t> struct OpenGl_TmplCore30;
76 typedef OpenGl_TmplCore30<OpenGl_GlCore21> OpenGl_GlCore30;
77 typedef OpenGl_TmplCore30<OpenGl_GlCore21Fwd> OpenGl_GlCore30Fwd;
79 template<typename theBaseClass_t> struct OpenGl_TmplCore31;
80 typedef OpenGl_TmplCore31<OpenGl_GlCore30> OpenGl_GlCore31Back;
81 typedef OpenGl_TmplCore31<OpenGl_GlCore30Fwd> OpenGl_GlCore31;
83 template<typename theBaseClass_t> struct OpenGl_TmplCore32;
84 typedef OpenGl_TmplCore32<OpenGl_GlCore31Back> OpenGl_GlCore32Back;
85 typedef OpenGl_TmplCore32<OpenGl_GlCore31> OpenGl_GlCore32;
87 template<typename theBaseClass_t> struct OpenGl_TmplCore33;
88 typedef OpenGl_TmplCore33<OpenGl_GlCore32Back> OpenGl_GlCore33Back;
89 typedef OpenGl_TmplCore33<OpenGl_GlCore32> OpenGl_GlCore33;
91 template<typename theBaseClass_t> struct OpenGl_TmplCore40;
92 typedef OpenGl_TmplCore40<OpenGl_GlCore33Back> OpenGl_GlCore40Back;
93 typedef OpenGl_TmplCore40<OpenGl_GlCore33> OpenGl_GlCore40;
95 template<typename theBaseClass_t> struct OpenGl_TmplCore41;
96 typedef OpenGl_TmplCore41<OpenGl_GlCore40Back> OpenGl_GlCore41Back;
97 typedef OpenGl_TmplCore41<OpenGl_GlCore40> OpenGl_GlCore41;
99 template<typename theBaseClass_t> struct OpenGl_TmplCore42;
100 typedef OpenGl_TmplCore42<OpenGl_GlCore41Back> OpenGl_GlCore42Back;
101 typedef OpenGl_TmplCore42<OpenGl_GlCore41> OpenGl_GlCore42;
103 template<typename theBaseClass_t> struct OpenGl_TmplCore43;
104 typedef OpenGl_TmplCore43<OpenGl_GlCore42Back> OpenGl_GlCore43Back;
105 typedef OpenGl_TmplCore43<OpenGl_GlCore42> OpenGl_GlCore43;
107 template<typename theBaseClass_t> struct OpenGl_TmplCore44;
108 typedef OpenGl_TmplCore44<OpenGl_GlCore43Back> OpenGl_GlCore44Back;
109 typedef OpenGl_TmplCore44<OpenGl_GlCore43> OpenGl_GlCore44;
111 //! This class generalize access to the GL context and available extensions.
113 //! Functions related to specific OpenGL version or extension are grouped into structures which can be accessed as fields of this class.
114 //! The most simple way to check that required functionality is available - is NULL check for the group:
116 //! if (myContext->core20 != NULL)
118 //! myGlProgram = myContext->core20->glCreateProgram();
119 //! .. do more stuff ..
123 //! .. compatibility with outdated configurations ..
127 //! Current implementation provide access to OpenGL core functionality up to 4.4 version (core12, core13, core14, core15, fields core20)
128 //! as well as several extensions (arbTBO, arbFBO, etc.).
130 //! OpenGL context might be initialized in Core Profile. In this case deprecated functionality become unavailable.
131 //! To make code easily adaptable to wide range of OpenGL versions, function sets related to each version has two kinds of suffixes:
132 //! - "back" for version 3.2+.
133 //! Represents function set for Backward-Compatible Profile.
134 //! Function sets without this suffix represents core profile.
135 //! - "fwd" for version 3.0-.
136 //! Represents non-deprecated function set of earlier OpenGL versions, which are still available within OpenGL 3.2 Core Profile.
137 //! Function sets without this suffix represents complete list of functions related to specific OpenGL version.
139 //! To select which core** function set should be used in specific case:
140 //! - Determine the minimal OpenGL version required for implemented functionality and use it to access all functions.
141 //! For example, if algorithm requires OpenGL 2.1+, it is better to write core20fwd->glEnable() rather than core11fwd->glEnable() for uniformity.
142 //! - If functionality will work within Core Profile, use function sets with appropriate suffix.
143 //! - Validate minimal requirements at initialization/creation time and omit checks within code where algorithm should be already initialized.
144 //! Properly escape code incompatible with Core Profile. The simplest way to check Core Profile is "if (core11 == NULL)".
146 //! Simplified extensions classification:
147 //! - prefixed with NV, AMD, ATI are vendor-specific (however may be provided by other vendors in some cases);
148 //! - prefixed with EXT are accepted by 2+ vendors;
149 //! - prefixed with ARB are accepted by Architecture Review Board and are candidates
150 //! for inclusion into GL core functionality.
151 //! Some functionality can be represented in several extensions simultaneously.
152 //! In this case developer should be careful because different specification may differ
153 //! in aspects (like enumeration values and error-handling).
155 //! Notice that some systems provide mechanisms to simultaneously incorporate with GL contexts with different capabilities.
156 //! For this reason OpenGl_Context should be initialized and used for each GL context independently.
157 class OpenGl_Context : public Standard_Transient
161 //! Function for getting power of to number larger or equal to input number.
162 //! @param theNumber number to 'power of two'
163 //! @param theThreshold upper threshold
164 //! @return power of two number
165 inline static Standard_Integer GetPowerOfTwo (const Standard_Integer theNumber,
166 const Standard_Integer theThreshold)
168 for (Standard_Integer p2 = 2; p2 <= theThreshold; p2 <<= 1)
180 //! Empty constructor. You should call Init() to perform initialization with bound GL context.
181 Standard_EXPORT OpenGl_Context (const Handle(OpenGl_Caps)& theCaps = NULL);
184 Standard_EXPORT virtual ~OpenGl_Context();
186 //! Release all resources, including shared ones
187 Standard_EXPORT void forcedRelease();
189 //! Share GL context resources.
190 //! theShareCtx - handle to context to retrieve handles to shared resources.
191 Standard_EXPORT void Share (const Handle(OpenGl_Context)& theShareCtx);
193 //! Initialize class from currently bound OpenGL context. Method should be called only once.
194 //! @return false if no GL context is bound to the current thread
195 Standard_EXPORT Standard_Boolean Init (const Standard_Boolean theIsCoreProfile = Standard_False);
197 //! @return true if this context is valid (has been initialized)
198 inline Standard_Boolean IsValid() const
200 return myIsInitialized;
203 #if defined(HAVE_EGL)
204 //! Initialize class from specified surface and rendering context. Method should be called only once.
205 //! @return false if OpenGL context can not be bound to specified surface
206 Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theEglSurface,
207 const Aspect_Display theEglDisplay,
208 const Aspect_RenderingContext theEglContext,
209 const Standard_Boolean theIsCoreProfile = Standard_False);
210 #elif defined(_WIN32)
211 //! Initialize class from specified window and rendering context. Method should be called only once.
212 //! @return false if OpenGL context can not be bound to specified window
213 Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow,
214 const Aspect_Handle theWindowDC,
215 const Aspect_RenderingContext theGContext,
216 const Standard_Boolean theIsCoreProfile = Standard_False);
218 //! @return the window handle (HWND) currently bound to this OpenGL context
219 inline Aspect_Handle Window() const
224 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
225 //! Initialize class from specified OpenGL context (NSOpenGLContext). Method should be called only once.
226 Standard_EXPORT Standard_Boolean Init (const void* theGContext,
227 const Standard_Boolean theIsCoreProfile = Standard_False);
229 //! Initialize class from specified window and rendering context. Method should be called only once.
230 //! @return false if OpenGL context can not be bound to specified window
231 Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow,
232 const Aspect_Display theDisplay,
233 const Aspect_RenderingContext theGContext,
234 const Standard_Boolean theIsCoreProfile = Standard_False);
236 //! @return the window handle (GLXDrawable) currently bound to this OpenGL context
237 inline Aspect_Drawable Window() const
243 //! Read OpenGL version information from active context.
244 Standard_EXPORT static void ReadGlVersion (Standard_Integer& theGlVerMajor,
245 Standard_Integer& theGlVerMinor);
247 //! Check if theExtName extension is supported by active GL context.
248 Standard_EXPORT Standard_Boolean CheckExtension (const char* theExtName) const;
250 //! Check if theExtName extension is in extensions string.
251 Standard_EXPORT static Standard_Boolean CheckExtension (const char* theExtString,
252 const char* theExtName);
254 //! Auxiliary template to retrieve GL function pointer.
255 //! Pointer to function retrieved from library is statically casted
256 //! to requested type - there no way to check real signature of exported function.
257 //! The context should be bound before call.
258 template <typename FuncType_t>
259 Standard_Boolean FindProc (const char* theFuncName,
260 FuncType_t& theFuncPtr)
262 theFuncPtr = (FuncType_t )findProc (theFuncName);
263 return (theFuncPtr != NULL);
266 //! @return true if detected GL version is greater or equal to requested one.
267 inline Standard_Boolean IsGlGreaterEqual (const Standard_Integer theVerMajor,
268 const Standard_Integer theVerMinor) const
270 return (myGlVerMajor > theVerMajor)
271 || (myGlVerMajor == theVerMajor && myGlVerMinor >= theVerMinor);
274 //! Clean up errors stack for this GL context (glGetError() in loop).
275 Standard_EXPORT void ResetErrors();
277 //! This method uses system-dependent API to retrieve information
278 //! about GL context bound to the current thread.
279 //! @return true if current thread is bound to this GL context
280 Standard_EXPORT Standard_Boolean IsCurrent() const;
282 //! Activates current context.
283 //! Class should be initialized with appropriate info.
284 Standard_EXPORT Standard_Boolean MakeCurrent();
286 //! Swap front/back buffers for this GL context (should be activated before!).
287 Standard_EXPORT void SwapBuffers();
289 //! Return true if active mode is GL_RENDER (cached state)
290 Standard_Boolean IsRender() const
292 #if !defined(GL_ES_VERSION_2_0)
293 return myRenderMode == GL_RENDER;
295 return Standard_True;
299 //! Return true if active mode is GL_FEEDBACK (cached state)
300 Standard_Boolean IsFeedback() const
302 #if !defined(GL_ES_VERSION_2_0)
303 return myRenderMode == GL_FEEDBACK;
305 return Standard_False;
309 //! This function retrieves information from GL about free GPU memory that is:
310 //! - OS-dependent. On some OS it is per-process and on others - for entire system.
311 //! - Vendor-dependent. Currently available only on NVIDIA and AMD/ATi drivers only.
312 //! - Numbers meaning may vary.
313 //! You should use this info only for diagnostics purposes.
314 //! @return free GPU dedicated memory in bytes.
315 Standard_EXPORT Standard_Size AvailableMemory() const;
317 //! This function retrieves information from GL about GPU memory
318 //! and contains more vendor-specific values than AvailableMemory().
319 Standard_EXPORT TCollection_AsciiString MemoryInfo() const;
321 //! Access shared resource by its name.
322 //! @param theKey - unique identifier;
323 //! @return handle to shared resource or NULL.
324 Standard_EXPORT const Handle(OpenGl_Resource)& GetResource (const TCollection_AsciiString& theKey) const;
326 //! Access shared resource by its name.
327 //! @param theKey - unique identifier;
328 //! @param theValue - handle to fill;
329 //! @return true if resource was shared.
330 template<typename TheHandleType>
331 Standard_Boolean GetResource (const TCollection_AsciiString& theKey,
332 TheHandleType& theValue) const
334 const Handle(OpenGl_Resource)& aResource = GetResource (theKey);
335 if (aResource.IsNull())
337 return Standard_False;
340 theValue = TheHandleType::DownCast (aResource);
341 return !theValue.IsNull();
344 //! Register shared resource.
345 //! Notice that after registration caller shouldn't release it by himself -
346 //! it will be automatically released on context destruction.
347 //! @param theKey - unique identifier, shouldn't be empty;
348 //! @param theResource - new resource to register, shouldn't be NULL.
349 Standard_EXPORT Standard_Boolean ShareResource (const TCollection_AsciiString& theKey,
350 const Handle(OpenGl_Resource)& theResource);
352 //! Release shared resource.
353 //! If there are more than one reference to this resource
354 //! (also used by some other existing object) then call will be ignored.
355 //! This means that current object itself should nullify handle before this call.
356 //! Notice that this is unrecommended operation at all and should be used
357 //! only in case of fat resources to release memory for other needs.
358 //! @param theKey unique identifier
359 //! @param theToDelay postpone release until next redraw call
360 Standard_EXPORT void ReleaseResource (const TCollection_AsciiString& theKey,
361 const Standard_Boolean theToDelay = Standard_False);
363 //! Append resource to queue for delayed clean up.
364 //! Resources in this queue will be released at next redraw call.
365 Standard_EXPORT void DelayedRelease (Handle(OpenGl_Resource)& theResource);
367 //! Clean up the delayed release queue.
368 Standard_EXPORT void ReleaseDelayed();
370 //! @return tool for management of clippings within this context.
371 inline OpenGl_Clipping& ChangeClipping() { return myClippingState; }
373 //! @return tool for management of clippings within this context.
374 inline const OpenGl_Clipping& Clipping() const { return myClippingState; }
376 //! @return tool for management of shader programs within this context.
377 inline const Handle(OpenGl_ShaderManager)& ShaderManager() const { return myShaderManager; }
381 //! Either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1).
382 Standard_Integer TextureWrapClamp() const { return myTexClamp; }
384 //! @return maximum degree of anisotropy texture filter
385 Standard_EXPORT Standard_Integer MaxDegreeOfAnisotropy() const;
387 //! @return value for GL_MAX_TEXTURE_SIZE
388 Standard_EXPORT Standard_Integer MaxTextureSize() const;
390 //! Get maximum number of clip planes supported by OpenGl.
391 //! This value is implementation dependent. At least 6
392 //! planes should be supported by OpenGl (see specs).
393 //! @return value for GL_MAX_CLIP_PLANES
394 Standard_EXPORT Standard_Integer MaxClipPlanes() const;
396 //! Returns true if VBO is supported and permitted.
397 inline bool ToUseVbo() const
399 return core15fwd != NULL
400 && !caps->vboDisable;
403 //! @return cached state of GL_NORMALIZE.
404 Standard_Boolean IsGlNormalizeEnabled() const { return myIsGlNormalizeEnabled; }
406 //! Sets GL_NORMALIZE enabled or disabled.
407 //! @return old value of the flag
408 Standard_EXPORT Standard_Boolean SetGlNormalizeEnabled (Standard_Boolean isEnabled);
410 //! Applies matrix stored in ModelWorldState to OpenGl.
411 void ApplyModelWorldMatrix();
413 //! Applies matrix stored in WorldViewState to OpenGl.
414 void ApplyWorldViewMatrix();
416 //! Applies combination of matrices stored in ModelWorldState and WorldViewState to OpenGl.
417 void ApplyModelViewMatrix();
419 //! Applies matrix stored in ProjectionState to OpenGl.
420 void ApplyProjectionMatrix();
424 //! @return messenger instance
425 inline const Handle(Message_Messenger)& Messenger() const
427 return ::Message::DefaultMessenger();
430 //! Callback for GL_ARB_debug_output extension
431 //! @param theSource message source within GL_DEBUG_SOURCE_ enumeration
432 //! @param theType message type within GL_DEBUG_TYPE_ enumeration
433 //! @param theId message ID within source
434 //! @param theSeverity message severity within GL_DEBUG_SEVERITY_ enumeration
435 //! @param theMessage the message itself
436 Standard_EXPORT void PushMessage (const unsigned int theSource,
437 const unsigned int theType,
438 const unsigned int theId,
439 const unsigned int theSeverity,
440 const TCollection_ExtendedString& theMessage);
444 //! @return true if OpenGl context supports left and
445 //! right rendering buffers.
446 Standard_Boolean HasStereoBuffers() const
448 #if !defined(GL_ES_VERSION_2_0)
449 return myIsStereoBuffers;
451 return Standard_False;
455 public: //! @name methods to alter or retrieve current state
457 //! Switch to left stereographic rendering buffer.
458 //! This method can be used to keep unchanged choise
459 //! of front/back/both buffer rendering.
460 Standard_EXPORT void SetDrawBufferLeft();
462 //! Switch to right stereographic rendering buffer.
463 //! This method can be used to keep unchanged choise
464 //! of front/back/both buffer rendering.
465 Standard_EXPORT void SetDrawBufferRight();
467 //! Switch to non-stereographic rendering buffer.
468 //! This method can be used to keep unchanged choise
469 //! of front/back/both buffer rendering.
470 Standard_EXPORT void SetDrawBufferMono();
472 //! Fetch OpenGl context state. This class tracks value of several OpenGl
473 //! state variables. Consulting the cached values is quicker than
474 //! doing the same via OpenGl API. Call this method if any of the controlled
475 //! OpenGl state variables has a possibility of being out-of-date.
476 Standard_EXPORT void FetchState();
478 //! @return active GLSL program
479 const Handle(OpenGl_ShaderProgram)& ActiveProgram() const
481 return myActiveProgram;
484 //! @return OpenGL sampler object used to override default texture parameters
485 const Handle(OpenGl_Sampler)& TextureSampler()
490 //! Bind specified program to current context,
491 //! or unbind previous one when NULL specified.
492 //! @return true if some program is bound to context
493 Standard_EXPORT Standard_Boolean BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram);
495 //! Setup current color.
496 Standard_EXPORT void SetColor4fv (const OpenGl_Vec4& theColor);
498 //! Setup point size.
499 Standard_EXPORT void SetPointSize (const Standard_ShortReal theSize);
501 //! Bind default Vertex Array Object
502 Standard_EXPORT void BindDefaultVao();
504 //! Return debug context initialization state.
505 Standard_Boolean IsDebugContext() const
507 return myIsGlDebugCtx;
512 //! Wrapper to system function to retrieve GL function pointer by name.
513 Standard_EXPORT void* findProc (const char* theFuncName);
515 //! Print error if not all functions have been exported by context for reported version.
516 //! Note that this will never happen when using GLX, since returned functions can not be validated.
517 //! @param theGlVerMajor the OpenGL major version with missing functions
518 //! @param theGlVerMinor the OpenGL minor version with missing functions
519 Standard_EXPORT void checkWrongVersion (const Standard_Integer theGlVerMajor,
520 const Standard_Integer theGlVerMinor);
522 //! Private initialization function that should be called only once.
523 Standard_EXPORT void init (const Standard_Boolean theIsCoreProfile);
525 public: //! @name core profiles
527 OpenGl_GlCore11* core11; //!< OpenGL 1.1 core functionality
528 OpenGl_GlCore11Fwd* core11fwd; //!< OpenGL 1.1 without deprecated entry points
529 OpenGl_GlCore15* core15; //!< OpenGL 1.5 core functionality
530 OpenGl_GlCore15Fwd* core15fwd; //!< OpenGL 1.5 without deprecated entry points
531 OpenGl_GlCore20* core20; //!< OpenGL 2.0 core functionality (includes 1.5)
532 OpenGl_GlCore20Fwd* core20fwd; //!< OpenGL 2.0 without deprecated entry points
533 OpenGl_GlCore32* core32; //!< OpenGL 3.2 core profile
534 OpenGl_GlCore32Back* core32back; //!< OpenGL 3.2 backward compatibility profile
535 OpenGl_GlCore33* core33; //!< OpenGL 3.3 core profile
536 OpenGl_GlCore33Back* core33back; //!< OpenGL 3.3 backward compatibility profile
537 OpenGl_GlCore41* core41; //!< OpenGL 4.1 core profile
538 OpenGl_GlCore41Back* core41back; //!< OpenGL 4.1 backward compatibility profile
539 OpenGl_GlCore42* core42; //!< OpenGL 4.2 core profile
540 OpenGl_GlCore42Back* core42back; //!< OpenGL 4.2 backward compatibility profile
541 OpenGl_GlCore43* core43; //!< OpenGL 4.3 core profile
542 OpenGl_GlCore43Back* core43back; //!< OpenGL 4.3 backward compatibility profile
543 OpenGl_GlCore44* core44; //!< OpenGL 4.4 core profile
544 OpenGl_GlCore44Back* core44back; //!< OpenGL 4.4 backward compatibility profile
546 Handle(OpenGl_Caps) caps; //!< context options
548 public: //! @name extensions
550 Standard_Boolean hasHighp; //!< highp in GLSL ES fragment shader is supported
551 Standard_Boolean hasTexRGBA8; //!< always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_rgb8_rgba8
552 Standard_Boolean arbNPTW; //!< GL_ARB_texture_non_power_of_two
553 Standard_Boolean arbTexRG; //!< GL_ARB_texture_rg
554 OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture
555 OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object
556 Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0
557 OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced
558 OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output
559 OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object
560 OpenGl_ArbFBOBlit* arbFBOBlit; //!< glBlitFramebuffer function, moved out from OpenGl_ArbFBO structure for compatibility with OpenGL ES 2.0
561 OpenGl_ExtGS* extGS; //!< GL_EXT_geometry_shader4
562 Standard_Boolean extBgra; //!< GL_EXT_bgra or GL_EXT_texture_format_BGRA8888 on OpenGL ES
563 Standard_Boolean extAnis; //!< GL_EXT_texture_filter_anisotropic
564 Standard_Boolean extPDS; //!< GL_EXT_packed_depth_stencil
565 Standard_Boolean atiMem; //!< GL_ATI_meminfo
566 Standard_Boolean nvxMem; //!< GL_NVX_gpu_memory_info
568 private: // system-dependent fields
570 #if defined(HAVE_EGL)
571 Aspect_Drawable myWindow; //!< EGL surface : EGLSurface
572 Aspect_Display myDisplay; //!< EGL connection to the Display : EGLDisplay
573 Aspect_RenderingContext myGContext; //!< EGL rendering context : EGLContext
574 #elif defined(_WIN32)
575 Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND
576 Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC
577 Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC
578 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
579 void* myGContext; //!< Rendering Context handle : NSOpenGLContext
581 Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable
582 Aspect_Display myDisplay; //!< connection to the X-server : Display*
583 Aspect_RenderingContext myGContext; //!< X-GLX rendering context : GLXContext
586 private: // context info
588 typedef NCollection_DataMap<TCollection_AsciiString, Standard_Integer> OpenGl_DelayReleaseMap;
589 typedef NCollection_Handle<OpenGl_DelayReleaseMap> Handle(OpenGl_DelayReleaseMap);
590 typedef NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)> OpenGl_ResourcesMap;
591 typedef NCollection_Handle<OpenGl_ResourcesMap> Handle(OpenGl_ResourcesMap);
592 typedef NCollection_List<Handle(OpenGl_Resource)> OpenGl_ResourcesStack;
593 typedef NCollection_Handle<OpenGl_ResourcesStack> Handle(OpenGl_ResourcesStack);
595 Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key
596 Handle(OpenGl_DelayReleaseMap) myDelayed; //!< shared resources for delayed release
597 Handle(OpenGl_ResourcesStack) myUnusedResources; //!< stack of resources for delayed clean up
599 OpenGl_Clipping myClippingState; //!< state of clip planes
601 void* myGlLibHandle; //!< optional handle to GL library
602 NCollection_Handle<OpenGl_GlFunctions>
603 myFuncs; //!< mega structure for all GL functions
604 Standard_Integer myAnisoMax; //!< maximum level of anisotropy texture filter
605 Standard_Integer myTexClamp; //!< either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1)
606 Standard_Integer myMaxTexDim; //!< value for GL_MAX_TEXTURE_SIZE
607 Standard_Integer myMaxClipPlanes; //!< value for GL_MAX_CLIP_PLANES
608 Standard_Integer myGlVerMajor; //!< cached GL version major number
609 Standard_Integer myGlVerMinor; //!< cached GL version minor number
610 Standard_Boolean myIsInitialized; //!< flag indicates initialization state
611 Standard_Boolean myIsStereoBuffers; //!< context supports stereo buffering
612 Standard_Boolean myIsGlNormalizeEnabled; //!< GL_NORMALIZE flag
613 //!< Used to tell OpenGl that normals should be normalized
615 Handle(OpenGl_ShaderManager) myShaderManager; //! support object for managing shader programs
617 private: //! @name fields tracking current state
619 Handle(OpenGl_ShaderProgram) myActiveProgram; //!< currently active GLSL program
620 Handle(OpenGl_Sampler) myTexSampler; //!< currently active sampler object
621 Standard_Integer myRenderMode; //!< value for active rendering mode
622 Standard_Integer myDrawBuffer; //!< current draw buffer
623 unsigned int myDefaultVao; //!< default Vertex Array Object
624 Standard_Boolean myIsGlDebugCtx; //!< debug context initialization state
628 OpenGl_Utils::MatrixState<Standard_ShortReal> ModelWorldState; //!< state of orientation matrix
629 OpenGl_Utils::MatrixState<Standard_ShortReal> WorldViewState; //!< state of orientation matrix
630 OpenGl_Utils::MatrixState<Standard_ShortReal> ProjectionState; //!< state of projection matrix
634 //! Copying allowed only within Handles
635 OpenGl_Context (const OpenGl_Context& );
636 OpenGl_Context& operator= (const OpenGl_Context& );
640 DEFINE_STANDARD_RTTI(OpenGl_Context) // Type definition
642 friend class OpenGl_Window;
646 #endif // _OpenGl_Context_H__