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 <Aspect_TypeOfLine.hxx>
24 #include <NCollection_DataMap.hxx>
25 #include <NCollection_Map.hxx>
26 #include <NCollection_Handle.hxx>
27 #include <NCollection_List.hxx>
28 #include <Message.hxx>
29 #include <OpenGl_Caps.hxx>
30 #include <OpenGl_Vec.hxx>
31 #include <OpenGl_Resource.hxx>
32 #include <Standard_Transient.hxx>
33 #include <TCollection_AsciiString.hxx>
34 #include <TColStd_PackedMapOfInteger.hxx>
35 #include <OpenGl_Clipping.hxx>
36 #include <OpenGl_GlCore11.hxx>
37 #include <OpenGl_Utils.hxx>
39 //! Forward declarations
40 #if defined(__APPLE__)
41 #import <TargetConditionals.h>
42 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
50 @class NSOpenGLContext;
52 struct NSOpenGLContext;
57 struct OpenGl_GlFunctions;
62 struct OpenGl_ArbFBOBlit;
64 struct OpenGl_ArbTexBindless;
66 template<typename theBaseClass_t> struct OpenGl_TmplCore12;
67 typedef OpenGl_TmplCore12<OpenGl_GlCore11> OpenGl_GlCore12;
68 typedef OpenGl_TmplCore12<OpenGl_GlCore11Fwd> OpenGl_GlCore12Fwd;
70 struct OpenGl_GlCore13;
71 struct OpenGl_GlCore13Fwd;
73 template<typename theBaseClass_t> struct OpenGl_TmplCore14;
74 typedef OpenGl_TmplCore14<OpenGl_GlCore13> OpenGl_GlCore14;
75 typedef OpenGl_TmplCore14<OpenGl_GlCore13Fwd> OpenGl_GlCore14Fwd;
77 template<typename theBaseClass_t> struct OpenGl_TmplCore15;
78 typedef OpenGl_TmplCore15<OpenGl_GlCore14> OpenGl_GlCore15;
79 typedef OpenGl_TmplCore15<OpenGl_GlCore14Fwd> OpenGl_GlCore15Fwd;
81 template<typename theBaseClass_t> struct OpenGl_TmplCore20;
82 typedef OpenGl_TmplCore20<OpenGl_GlCore15> OpenGl_GlCore20;
83 typedef OpenGl_TmplCore20<OpenGl_GlCore15Fwd> OpenGl_GlCore20Fwd;
85 template<typename theBaseClass_t> struct OpenGl_TmplCore21;
86 typedef OpenGl_TmplCore21<OpenGl_GlCore20> OpenGl_GlCore21;
87 typedef OpenGl_TmplCore21<OpenGl_GlCore20Fwd> OpenGl_GlCore21Fwd;
89 template<typename theBaseClass_t> struct OpenGl_TmplCore30;
90 typedef OpenGl_TmplCore30<OpenGl_GlCore21> OpenGl_GlCore30;
91 typedef OpenGl_TmplCore30<OpenGl_GlCore21Fwd> OpenGl_GlCore30Fwd;
93 template<typename theBaseClass_t> struct OpenGl_TmplCore31;
94 typedef OpenGl_TmplCore31<OpenGl_GlCore30> OpenGl_GlCore31Back;
95 typedef OpenGl_TmplCore31<OpenGl_GlCore30Fwd> OpenGl_GlCore31;
97 template<typename theBaseClass_t> struct OpenGl_TmplCore32;
98 typedef OpenGl_TmplCore32<OpenGl_GlCore31Back> OpenGl_GlCore32Back;
99 typedef OpenGl_TmplCore32<OpenGl_GlCore31> OpenGl_GlCore32;
101 template<typename theBaseClass_t> struct OpenGl_TmplCore33;
102 typedef OpenGl_TmplCore33<OpenGl_GlCore32Back> OpenGl_GlCore33Back;
103 typedef OpenGl_TmplCore33<OpenGl_GlCore32> OpenGl_GlCore33;
105 template<typename theBaseClass_t> struct OpenGl_TmplCore40;
106 typedef OpenGl_TmplCore40<OpenGl_GlCore33Back> OpenGl_GlCore40Back;
107 typedef OpenGl_TmplCore40<OpenGl_GlCore33> OpenGl_GlCore40;
109 template<typename theBaseClass_t> struct OpenGl_TmplCore41;
110 typedef OpenGl_TmplCore41<OpenGl_GlCore40Back> OpenGl_GlCore41Back;
111 typedef OpenGl_TmplCore41<OpenGl_GlCore40> OpenGl_GlCore41;
113 template<typename theBaseClass_t> struct OpenGl_TmplCore42;
114 typedef OpenGl_TmplCore42<OpenGl_GlCore41Back> OpenGl_GlCore42Back;
115 typedef OpenGl_TmplCore42<OpenGl_GlCore41> OpenGl_GlCore42;
117 template<typename theBaseClass_t> struct OpenGl_TmplCore43;
118 typedef OpenGl_TmplCore43<OpenGl_GlCore42Back> OpenGl_GlCore43Back;
119 typedef OpenGl_TmplCore43<OpenGl_GlCore42> OpenGl_GlCore43;
121 template<typename theBaseClass_t> struct OpenGl_TmplCore44;
122 typedef OpenGl_TmplCore44<OpenGl_GlCore43Back> OpenGl_GlCore44Back;
123 typedef OpenGl_TmplCore44<OpenGl_GlCore43> OpenGl_GlCore44;
125 //! This class generalize access to the GL context and available extensions.
127 //! Functions related to specific OpenGL version or extension are grouped into structures which can be accessed as fields of this class.
128 //! The most simple way to check that required functionality is available - is NULL check for the group:
130 //! if (myContext->core20 != NULL)
132 //! myGlProgram = myContext->core20->glCreateProgram();
133 //! .. do more stuff ..
137 //! .. compatibility with outdated configurations ..
141 //! Current implementation provide access to OpenGL core functionality up to 4.4 version (core12, core13, core14, core15, fields core20)
142 //! as well as several extensions (arbTBO, arbFBO, etc.).
144 //! OpenGL context might be initialized in Core Profile. In this case deprecated functionality become unavailable.
145 //! To make code easily adaptable to wide range of OpenGL versions, function sets related to each version has two kinds of suffixes:
146 //! - "back" for version 3.2+.
147 //! Represents function set for Backward-Compatible Profile.
148 //! Function sets without this suffix represents core profile.
149 //! - "fwd" for version 3.0-.
150 //! Represents non-deprecated function set of earlier OpenGL versions, which are still available within OpenGL 3.2 Core Profile.
151 //! Function sets without this suffix represents complete list of functions related to specific OpenGL version.
153 //! To select which core** function set should be used in specific case:
154 //! - Determine the minimal OpenGL version required for implemented functionality and use it to access all functions.
155 //! For example, if algorithm requires OpenGL 2.1+, it is better to write core20fwd->glEnable() rather than core11fwd->glEnable() for uniformity.
156 //! - If functionality will work within Core Profile, use function sets with appropriate suffix.
157 //! - Validate minimal requirements at initialization/creation time and omit checks within code where algorithm should be already initialized.
158 //! Properly escape code incompatible with Core Profile. The simplest way to check Core Profile is "if (core11 == NULL)".
160 //! Simplified extensions classification:
161 //! - prefixed with NV, AMD, ATI are vendor-specific (however may be provided by other vendors in some cases);
162 //! - prefixed with EXT are accepted by 2+ vendors;
163 //! - prefixed with ARB are accepted by Architecture Review Board and are candidates
164 //! for inclusion into GL core functionality.
165 //! Some functionality can be represented in several extensions simultaneously.
166 //! In this case developer should be careful because different specification may differ
167 //! in aspects (like enumeration values and error-handling).
169 //! Notice that some systems provide mechanisms to simultaneously incorporate with GL contexts with different capabilities.
170 //! For this reason OpenGl_Context should be initialized and used for each GL context independently.
171 class OpenGl_Context : public Standard_Transient
175 //! Function for getting power of to number larger or equal to input number.
176 //! @param theNumber number to 'power of two'
177 //! @param theThreshold upper threshold
178 //! @return power of two number
179 inline static Standard_Integer GetPowerOfTwo (const Standard_Integer theNumber,
180 const Standard_Integer theThreshold)
182 for (Standard_Integer p2 = 2; p2 <= theThreshold; p2 <<= 1)
194 //! Empty constructor. You should call Init() to perform initialization with bound GL context.
195 Standard_EXPORT OpenGl_Context (const Handle(OpenGl_Caps)& theCaps = NULL);
198 Standard_EXPORT virtual ~OpenGl_Context();
200 //! Release all resources, including shared ones
201 Standard_EXPORT void forcedRelease();
203 //! Share GL context resources.
204 //! theShareCtx - handle to context to retrieve handles to shared resources.
205 Standard_EXPORT void Share (const Handle(OpenGl_Context)& theShareCtx);
207 //! Initialize class from currently bound OpenGL context. Method should be called only once.
208 //! @return false if no GL context is bound to the current thread
209 Standard_EXPORT Standard_Boolean Init (const Standard_Boolean theIsCoreProfile = Standard_False);
211 //! @return true if this context is valid (has been initialized)
212 inline Standard_Boolean IsValid() const
214 return myIsInitialized;
217 #if defined(HAVE_EGL)
218 //! Initialize class from specified surface and rendering context. Method should be called only once.
219 //! @return false if OpenGL context can not be bound to specified surface
220 Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theEglSurface,
221 const Aspect_Display theEglDisplay,
222 const Aspect_RenderingContext theEglContext,
223 const Standard_Boolean theIsCoreProfile = Standard_False);
224 #elif defined(_WIN32)
225 //! Initialize class from specified window and rendering context. Method should be called only once.
226 //! @return false if OpenGL context can not be bound to specified window
227 Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow,
228 const Aspect_Handle theWindowDC,
229 const Aspect_RenderingContext theGContext,
230 const Standard_Boolean theIsCoreProfile = Standard_False);
232 //! @return the window handle (HWND) currently bound to this OpenGL context
233 inline Aspect_Handle Window() const
238 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
239 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
241 //! Initialize class from specified OpenGL ES context (EAGLContext). Method should be called only once.
242 Standard_EXPORT Standard_Boolean Init (EAGLContext* theGContext,
243 const Standard_Boolean theIsCoreProfile = Standard_False);
246 //! Initialize class from specified OpenGL context (NSOpenGLContext). Method should be called only once.
247 Standard_EXPORT Standard_Boolean Init (NSOpenGLContext* theGContext,
248 const Standard_Boolean theIsCoreProfile = Standard_False);
252 //! Initialize class from specified window and rendering context. Method should be called only once.
253 //! @return false if OpenGL context can not be bound to specified window
254 Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow,
255 const Aspect_Display theDisplay,
256 const Aspect_RenderingContext theGContext,
257 const Standard_Boolean theIsCoreProfile = Standard_False);
259 //! @return the window handle (GLXDrawable) currently bound to this OpenGL context
260 inline Aspect_Drawable Window() const
266 //! Read OpenGL version information from active context.
267 Standard_EXPORT static void ReadGlVersion (Standard_Integer& theGlVerMajor,
268 Standard_Integer& theGlVerMinor);
270 //! Check if theExtName extension is supported by active GL context.
271 Standard_EXPORT Standard_Boolean CheckExtension (const char* theExtName) const;
273 //! Check if theExtName extension is in extensions string.
274 Standard_EXPORT static Standard_Boolean CheckExtension (const char* theExtString,
275 const char* theExtName);
277 //! Auxiliary template to retrieve GL function pointer.
278 //! Pointer to function retrieved from library is statically casted
279 //! to requested type - there no way to check real signature of exported function.
280 //! The context should be bound before call.
281 template <typename FuncType_t>
282 Standard_Boolean FindProc (const char* theFuncName,
283 FuncType_t& theFuncPtr)
285 theFuncPtr = (FuncType_t )findProc (theFuncName);
286 return (theFuncPtr != NULL);
289 //! @return true if detected GL version is greater or equal to requested one.
290 inline Standard_Boolean IsGlGreaterEqual (const Standard_Integer theVerMajor,
291 const Standard_Integer theVerMinor) const
293 return (myGlVerMajor > theVerMajor)
294 || (myGlVerMajor == theVerMajor && myGlVerMinor >= theVerMinor);
297 //! Access entire map of loaded OpenGL functions.
298 const OpenGl_GlFunctions* Functions() const { return myFuncs.operator->(); }
300 //! Clean up errors stack for this GL context (glGetError() in loop).
301 Standard_EXPORT void ResetErrors();
303 //! This method uses system-dependent API to retrieve information
304 //! about GL context bound to the current thread.
305 //! @return true if current thread is bound to this GL context
306 Standard_EXPORT Standard_Boolean IsCurrent() const;
308 //! Activates current context.
309 //! Class should be initialized with appropriate info.
310 Standard_EXPORT Standard_Boolean MakeCurrent();
312 //! Swap front/back buffers for this GL context (should be activated before!).
313 Standard_EXPORT void SwapBuffers();
315 //! Setup swap interval (VSync).
316 Standard_EXPORT Standard_Boolean SetSwapInterval (const Standard_Integer theInterval);
318 //! Return true if active mode is GL_RENDER (cached state)
319 Standard_Boolean IsRender() const
321 #if !defined(GL_ES_VERSION_2_0)
322 return myRenderMode == GL_RENDER;
324 return Standard_True;
328 //! Return true if active mode is GL_FEEDBACK (cached state)
329 Standard_Boolean IsFeedback() const
331 #if !defined(GL_ES_VERSION_2_0)
332 return myRenderMode == GL_FEEDBACK;
334 return Standard_False;
338 //! This function retrieves information from GL about free GPU memory that is:
339 //! - OS-dependent. On some OS it is per-process and on others - for entire system.
340 //! - Vendor-dependent. Currently available only on NVIDIA and AMD/ATi drivers only.
341 //! - Numbers meaning may vary.
342 //! You should use this info only for diagnostics purposes.
343 //! @return free GPU dedicated memory in bytes.
344 Standard_EXPORT Standard_Size AvailableMemory() const;
346 //! This function retrieves information from GL about GPU memory
347 //! and contains more vendor-specific values than AvailableMemory().
348 Standard_EXPORT TCollection_AsciiString MemoryInfo() const;
350 //! Access shared resource by its name.
351 //! @param theKey - unique identifier;
352 //! @return handle to shared resource or NULL.
353 Standard_EXPORT const Handle(OpenGl_Resource)& GetResource (const TCollection_AsciiString& theKey) const;
355 //! Access shared resource by its name.
356 //! @param theKey - unique identifier;
357 //! @param theValue - handle to fill;
358 //! @return true if resource was shared.
359 template<typename TheHandleType>
360 Standard_Boolean GetResource (const TCollection_AsciiString& theKey,
361 TheHandleType& theValue) const
363 const Handle(OpenGl_Resource)& aResource = GetResource (theKey);
364 if (aResource.IsNull())
366 return Standard_False;
369 theValue = TheHandleType::DownCast (aResource);
370 return !theValue.IsNull();
373 //! Register shared resource.
374 //! Notice that after registration caller shouldn't release it by himself -
375 //! it will be automatically released on context destruction.
376 //! @param theKey - unique identifier, shouldn't be empty;
377 //! @param theResource - new resource to register, shouldn't be NULL.
378 Standard_EXPORT Standard_Boolean ShareResource (const TCollection_AsciiString& theKey,
379 const Handle(OpenGl_Resource)& theResource);
381 //! Release shared resource.
382 //! If there are more than one reference to this resource
383 //! (also used by some other existing object) then call will be ignored.
384 //! This means that current object itself should nullify handle before this call.
385 //! Notice that this is unrecommended operation at all and should be used
386 //! only in case of fat resources to release memory for other needs.
387 //! @param theKey unique identifier
388 //! @param theToDelay postpone release until next redraw call
389 Standard_EXPORT void ReleaseResource (const TCollection_AsciiString& theKey,
390 const Standard_Boolean theToDelay = Standard_False);
392 //! Append resource to queue for delayed clean up.
393 //! Resources in this queue will be released at next redraw call.
394 Standard_EXPORT void DelayedRelease (Handle(OpenGl_Resource)& theResource);
396 //! Clean up the delayed release queue.
397 Standard_EXPORT void ReleaseDelayed();
399 //! @return tool for management of clippings within this context.
400 inline OpenGl_Clipping& ChangeClipping() { return myClippingState; }
402 //! @return tool for management of clippings within this context.
403 inline const OpenGl_Clipping& Clipping() const { return myClippingState; }
405 //! @return tool for management of shader programs within this context.
406 inline const Handle(OpenGl_ShaderManager)& ShaderManager() const { return myShaderManager; }
410 //! Either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1).
411 Standard_Integer TextureWrapClamp() const { return myTexClamp; }
413 //! @return maximum degree of anisotropy texture filter
414 Standard_EXPORT Standard_Integer MaxDegreeOfAnisotropy() const;
416 //! @return value for GL_MAX_TEXTURE_SIZE
417 Standard_EXPORT Standard_Integer MaxTextureSize() const;
419 //! Get maximum number of clip planes supported by OpenGl.
420 //! This value is implementation dependent. At least 6
421 //! planes should be supported by OpenGl (see specs).
422 //! @return value for GL_MAX_CLIP_PLANES
423 Standard_EXPORT Standard_Integer MaxClipPlanes() const;
425 //! Returns true if VBO is supported and permitted.
426 inline bool ToUseVbo() const
428 return core15fwd != NULL
429 && !caps->vboDisable;
432 //! @return cached state of GL_NORMALIZE.
433 Standard_Boolean IsGlNormalizeEnabled() const { return myIsGlNormalizeEnabled; }
435 //! Sets GL_NORMALIZE enabled or disabled.
436 //! @return old value of the flag
437 Standard_EXPORT Standard_Boolean SetGlNormalizeEnabled (Standard_Boolean isEnabled);
439 //! Applies matrix stored in ModelWorldState to OpenGl.
440 Standard_EXPORT void ApplyModelWorldMatrix();
442 //! Applies matrix stored in WorldViewState to OpenGl.
443 Standard_EXPORT void ApplyWorldViewMatrix();
445 //! Applies combination of matrices stored in ModelWorldState and WorldViewState to OpenGl.
446 Standard_EXPORT void ApplyModelViewMatrix();
448 //! Applies matrix stored in ProjectionState to OpenGl.
449 Standard_EXPORT void ApplyProjectionMatrix();
453 //! @return messenger instance
454 inline const Handle(Message_Messenger)& Messenger() const
456 return ::Message::DefaultMessenger();
459 //! Callback for GL_ARB_debug_output extension
460 //! @param theSource message source within GL_DEBUG_SOURCE_ enumeration
461 //! @param theType message type within GL_DEBUG_TYPE_ enumeration
462 //! @param theId message ID within source
463 //! @param theSeverity message severity within GL_DEBUG_SEVERITY_ enumeration
464 //! @param theMessage the message itself
465 Standard_EXPORT void PushMessage (const unsigned int theSource,
466 const unsigned int theType,
467 const unsigned int theId,
468 const unsigned int theSeverity,
469 const TCollection_ExtendedString& theMessage);
471 //! Adds a filter for messages with theId and theSource (GL_DEBUG_SOURCE_)
472 Standard_EXPORT Standard_Boolean ExcludeMessage (const unsigned int theSource,
473 const unsigned int theId);
475 //! Removes a filter for messages with theId and theSource (GL_DEBUG_SOURCE_)
476 Standard_EXPORT Standard_Boolean IncludeMessage (const unsigned int theSource,
477 const unsigned int theId);
479 //! @return true if OpenGl context supports left and
480 //! right rendering buffers.
481 Standard_Boolean HasStereoBuffers() const
483 #if !defined(GL_ES_VERSION_2_0)
484 return myIsStereoBuffers;
486 return Standard_False;
490 public: //! @name methods to alter or retrieve current state
492 //! Return active read buffer.
493 Standard_Integer ReadBuffer() { return myReadBuffer; }
495 //! Switch read buffer, wrapper for ::glReadBuffer().
496 Standard_EXPORT void SetReadBuffer (const Standard_Integer theReadBuffer);
498 //! Return active draw buffer.
499 Standard_Integer DrawBuffer() { return myDrawBuffer; }
501 //! Switch draw buffer, wrapper for ::glDrawBuffer().
502 Standard_EXPORT void SetDrawBuffer (const Standard_Integer theDrawBuffer);
504 //! Switch read/draw buffers.
505 void SetReadDrawBuffer (const Standard_Integer theBuffer)
507 SetReadBuffer (theBuffer);
508 SetDrawBuffer (theBuffer);
511 //! Fetch OpenGl context state. This class tracks value of several OpenGl
512 //! state variables. Consulting the cached values is quicker than
513 //! doing the same via OpenGl API. Call this method if any of the controlled
514 //! OpenGl state variables has a possibility of being out-of-date.
515 Standard_EXPORT void FetchState();
517 //! @return active GLSL program
518 const Handle(OpenGl_ShaderProgram)& ActiveProgram() const
520 return myActiveProgram;
523 //! @return OpenGL sampler object used to override default texture parameters
524 const Handle(OpenGl_Sampler)& TextureSampler()
529 //! Bind specified program to current context,
530 //! or unbind previous one when NULL specified.
531 //! @return true if some program is bound to context
532 Standard_EXPORT Standard_Boolean BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram);
534 //! Setup current color.
535 Standard_EXPORT void SetColor4fv (const OpenGl_Vec4& theColor);
537 //! Setup type of line.
538 Standard_EXPORT void SetTypeOfLine (const Aspect_TypeOfLine theType,
539 const Standard_ShortReal theFactor = 1.0f);
541 //! Setup width of line.
542 Standard_EXPORT void SetLineWidth (const Standard_ShortReal theWidth);
544 //! Setup point size.
545 Standard_EXPORT void SetPointSize (const Standard_ShortReal theSize);
547 //! Bind default Vertex Array Object
548 Standard_EXPORT void BindDefaultVao();
550 //! Default Frame Buffer Object.
551 const Handle(OpenGl_FrameBuffer)& DefaultFrameBuffer() const
556 //! Setup new Default Frame Buffer Object and return previously set.
557 //! This call doesn't change Active FBO!
558 Standard_EXPORT Handle(OpenGl_FrameBuffer) SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo);
560 //! Return debug context initialization state.
561 Standard_Boolean IsDebugContext() const
563 return myIsGlDebugCtx;
568 //! Wrapper to system function to retrieve GL function pointer by name.
569 Standard_EXPORT void* findProc (const char* theFuncName);
571 //! Print error if not all functions have been exported by context for reported version.
572 //! Note that this will never happen when using GLX, since returned functions can not be validated.
573 //! @param theGlVerMajor the OpenGL major version with missing functions
574 //! @param theGlVerMinor the OpenGL minor version with missing functions
575 Standard_EXPORT void checkWrongVersion (const Standard_Integer theGlVerMajor,
576 const Standard_Integer theGlVerMinor);
578 //! Private initialization function that should be called only once.
579 Standard_EXPORT void init (const Standard_Boolean theIsCoreProfile);
581 public: //! @name core profiles
583 OpenGl_GlCore11* core11; //!< OpenGL 1.1 core functionality
584 OpenGl_GlCore11Fwd* core11fwd; //!< OpenGL 1.1 without deprecated entry points
585 OpenGl_GlCore15* core15; //!< OpenGL 1.5 core functionality
586 OpenGl_GlCore15Fwd* core15fwd; //!< OpenGL 1.5 without deprecated entry points
587 OpenGl_GlCore20* core20; //!< OpenGL 2.0 core functionality (includes 1.5)
588 OpenGl_GlCore20Fwd* core20fwd; //!< OpenGL 2.0 without deprecated entry points
589 OpenGl_GlCore32* core32; //!< OpenGL 3.2 core profile
590 OpenGl_GlCore32Back* core32back; //!< OpenGL 3.2 backward compatibility profile
591 OpenGl_GlCore33* core33; //!< OpenGL 3.3 core profile
592 OpenGl_GlCore33Back* core33back; //!< OpenGL 3.3 backward compatibility profile
593 OpenGl_GlCore41* core41; //!< OpenGL 4.1 core profile
594 OpenGl_GlCore41Back* core41back; //!< OpenGL 4.1 backward compatibility profile
595 OpenGl_GlCore42* core42; //!< OpenGL 4.2 core profile
596 OpenGl_GlCore42Back* core42back; //!< OpenGL 4.2 backward compatibility profile
597 OpenGl_GlCore43* core43; //!< OpenGL 4.3 core profile
598 OpenGl_GlCore43Back* core43back; //!< OpenGL 4.3 backward compatibility profile
599 OpenGl_GlCore44* core44; //!< OpenGL 4.4 core profile
600 OpenGl_GlCore44Back* core44back; //!< OpenGL 4.4 backward compatibility profile
602 Handle(OpenGl_Caps) caps; //!< context options
604 public: //! @name extensions
606 Standard_Boolean hasHighp; //!< highp in GLSL ES fragment shader is supported
607 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)
608 Standard_Boolean hasTexRGBA8; //!< always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_rgb8_rgba8
609 Standard_Boolean arbNPTW; //!< GL_ARB_texture_non_power_of_two
610 Standard_Boolean arbTexRG; //!< GL_ARB_texture_rg
611 OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture
612 OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object
613 Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0
614 OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced
615 OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output
616 OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object
617 OpenGl_ArbFBOBlit* arbFBOBlit; //!< glBlitFramebuffer function, moved out from OpenGl_ArbFBO structure for compatibility with OpenGL ES 2.0
618 OpenGl_ExtGS* extGS; //!< GL_EXT_geometry_shader4
619 Standard_Boolean extBgra; //!< GL_EXT_bgra or GL_EXT_texture_format_BGRA8888 on OpenGL ES
620 Standard_Boolean extAnis; //!< GL_EXT_texture_filter_anisotropic
621 Standard_Boolean extPDS; //!< GL_EXT_packed_depth_stencil
622 Standard_Boolean atiMem; //!< GL_ATI_meminfo
623 Standard_Boolean nvxMem; //!< GL_NVX_gpu_memory_info
625 private: // system-dependent fields
627 #if defined(HAVE_EGL)
628 Aspect_Drawable myWindow; //!< EGL surface : EGLSurface
629 Aspect_Display myDisplay; //!< EGL connection to the Display : EGLDisplay
630 Aspect_RenderingContext myGContext; //!< EGL rendering context : EGLContext
631 #elif defined(_WIN32)
632 Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND
633 Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC
634 Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC
635 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
636 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
637 EAGLContext* myGContext; //!< Rendering Context handle
639 NSOpenGLContext* myGContext; //!< Rendering Context handle
642 Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable
643 Aspect_Display myDisplay; //!< connection to the X-server : Display*
644 Aspect_RenderingContext myGContext; //!< X-GLX rendering context : GLXContext
647 private: // context info
649 typedef NCollection_DataMap<TCollection_AsciiString, Standard_Integer> OpenGl_DelayReleaseMap;
650 typedef NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)> OpenGl_ResourcesMap;
651 typedef NCollection_List<Handle(OpenGl_Resource)> OpenGl_ResourcesStack;
653 Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key
654 Handle(OpenGl_DelayReleaseMap) myDelayed; //!< shared resources for delayed release
655 Handle(OpenGl_ResourcesStack) myUnusedResources; //!< stack of resources for delayed clean up
657 OpenGl_Clipping myClippingState; //!< state of clip planes
659 void* myGlLibHandle; //!< optional handle to GL library
660 NCollection_Handle<OpenGl_GlFunctions>
661 myFuncs; //!< mega structure for all GL functions
662 Standard_Integer myAnisoMax; //!< maximum level of anisotropy texture filter
663 Standard_Integer myTexClamp; //!< either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1)
664 Standard_Integer myMaxTexDim; //!< value for GL_MAX_TEXTURE_SIZE
665 Standard_Integer myMaxClipPlanes; //!< value for GL_MAX_CLIP_PLANES
666 Standard_Integer myGlVerMajor; //!< cached GL version major number
667 Standard_Integer myGlVerMinor; //!< cached GL version minor number
668 Standard_Boolean myIsInitialized; //!< flag indicates initialization state
669 Standard_Boolean myIsStereoBuffers; //!< context supports stereo buffering
670 Standard_Boolean myIsGlNormalizeEnabled; //!< GL_NORMALIZE flag
671 //!< Used to tell OpenGl that normals should be normalized
673 Handle(OpenGl_ShaderManager) myShaderManager; //! support object for managing shader programs
675 private: //! @name fields tracking current state
677 Handle(OpenGl_ShaderProgram) myActiveProgram; //!< currently active GLSL program
678 Handle(OpenGl_Sampler) myTexSampler; //!< currently active sampler object
679 Handle(OpenGl_FrameBuffer) myDefaultFbo; //!< default Frame Buffer Object
680 Standard_Integer myRenderMode; //!< value for active rendering mode
681 Standard_Integer myReadBuffer; //!< current read buffer
682 Standard_Integer myDrawBuffer; //!< current draw buffer
683 unsigned int myDefaultVao; //!< default Vertex Array Object
684 Standard_Boolean myIsGlDebugCtx; //!< debug context initialization state
685 TCollection_AsciiString myVendor; //!< Graphics Driver's vendor
686 TColStd_PackedMapOfInteger myFilters[6]; //!< messages suppressing filter (for sources from GL_DEBUG_SOURCE_API_ARB to GL_DEBUG_SOURCE_OTHER_ARB)
690 OpenGl_Utils::MatrixState<Standard_ShortReal> ModelWorldState; //!< state of orientation matrix
691 OpenGl_Utils::MatrixState<Standard_ShortReal> WorldViewState; //!< state of orientation matrix
692 OpenGl_Utils::MatrixState<Standard_ShortReal> ProjectionState; //!< state of projection matrix
696 //! Copying allowed only within Handles
697 OpenGl_Context (const OpenGl_Context& );
698 OpenGl_Context& operator= (const OpenGl_Context& );
702 DEFINE_STANDARD_RTTI(OpenGl_Context, Standard_Transient) // Type definition
704 friend class OpenGl_Window;
708 #endif // _OpenGl_Context_H__