0025442: Visualization, TKOpenGl - prevent inclusion of system header glxext.h
[occt.git] / src / OpenGl / OpenGl_Context.hxx
CommitLineData
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>
20#include <Aspect_Drawable.hxx>
21#include <Aspect_Display.hxx>
22#include <Aspect_RenderingContext.hxx>
5e27df78 23#include <Handle_OpenGl_Context.hxx>
25ef750e 24#include <Handle_OpenGl_Sampler.hxx>
30f0ad28 25#include <Handle_OpenGl_ShaderManager.hxx>
7d3e64ef 26#include <Handle_OpenGl_ShaderProgram.hxx>
5e27df78 27#include <NCollection_DataMap.hxx>
4269bd1b 28#include <NCollection_Map.hxx>
5e27df78 29#include <NCollection_Handle.hxx>
3125ebb6 30#include <NCollection_List.hxx>
cbf18624 31#include <Message.hxx>
58655684 32#include <OpenGl_Caps.hxx>
8625ef7e 33#include <OpenGl_Vec.hxx>
5e27df78 34#include <OpenGl_Resource.hxx>
2166f0fa 35#include <Standard_Transient.hxx>
f0430952 36#include <TCollection_AsciiString.hxx>
2166f0fa 37#include <Handle_OpenGl_Context.hxx>
30f0ad28 38#include <OpenGl_Clipping.hxx>
b5ac8292 39#include <OpenGl_GlCore11.hxx>
2166f0fa 40
5f8b738e 41//! Forward declarations
01ca42b2 42struct OpenGl_GlFunctions;
5e27df78 43struct OpenGl_ArbTBO;
44struct OpenGl_ArbIns;
58655684 45struct OpenGl_ArbDbg;
01ca42b2 46struct OpenGl_ArbFBO;
37eb4787 47struct OpenGl_ExtGS;
25ef750e 48struct OpenGl_ArbTexBindless;
2166f0fa 49
01ca42b2 50template<typename theBaseClass_t> struct OpenGl_TmplCore12;
51typedef OpenGl_TmplCore12<OpenGl_GlCore11> OpenGl_GlCore12;
52typedef OpenGl_TmplCore12<OpenGl_GlCore11Fwd> OpenGl_GlCore12Fwd;
53
54struct OpenGl_GlCore13;
55struct OpenGl_GlCore13Fwd;
56
57template<typename theBaseClass_t> struct OpenGl_TmplCore14;
58typedef OpenGl_TmplCore14<OpenGl_GlCore13> OpenGl_GlCore14;
59typedef OpenGl_TmplCore14<OpenGl_GlCore13Fwd> OpenGl_GlCore14Fwd;
60
61template<typename theBaseClass_t> struct OpenGl_TmplCore15;
62typedef OpenGl_TmplCore15<OpenGl_GlCore14> OpenGl_GlCore15;
63typedef OpenGl_TmplCore15<OpenGl_GlCore14Fwd> OpenGl_GlCore15Fwd;
64
65template<typename theBaseClass_t> struct OpenGl_TmplCore20;
66typedef OpenGl_TmplCore20<OpenGl_GlCore15> OpenGl_GlCore20;
67typedef OpenGl_TmplCore20<OpenGl_GlCore15Fwd> OpenGl_GlCore20Fwd;
68
69template<typename theBaseClass_t> struct OpenGl_TmplCore21;
70typedef OpenGl_TmplCore21<OpenGl_GlCore20> OpenGl_GlCore21;
71typedef OpenGl_TmplCore21<OpenGl_GlCore20Fwd> OpenGl_GlCore21Fwd;
72
73template<typename theBaseClass_t> struct OpenGl_TmplCore30;
74typedef OpenGl_TmplCore30<OpenGl_GlCore21> OpenGl_GlCore30;
75typedef OpenGl_TmplCore30<OpenGl_GlCore21Fwd> OpenGl_GlCore30Fwd;
76
77template<typename theBaseClass_t> struct OpenGl_TmplCore31;
78typedef OpenGl_TmplCore31<OpenGl_GlCore30> OpenGl_GlCore31Back;
79typedef OpenGl_TmplCore31<OpenGl_GlCore30Fwd> OpenGl_GlCore31;
80
81template<typename theBaseClass_t> struct OpenGl_TmplCore32;
82typedef OpenGl_TmplCore32<OpenGl_GlCore31Back> OpenGl_GlCore32Back;
83typedef OpenGl_TmplCore32<OpenGl_GlCore31> OpenGl_GlCore32;
84
85template<typename theBaseClass_t> struct OpenGl_TmplCore33;
86typedef OpenGl_TmplCore33<OpenGl_GlCore32Back> OpenGl_GlCore33Back;
87typedef OpenGl_TmplCore33<OpenGl_GlCore32> OpenGl_GlCore33;
88
89template<typename theBaseClass_t> struct OpenGl_TmplCore40;
90typedef OpenGl_TmplCore40<OpenGl_GlCore33Back> OpenGl_GlCore40Back;
91typedef OpenGl_TmplCore40<OpenGl_GlCore33> OpenGl_GlCore40;
92
93template<typename theBaseClass_t> struct OpenGl_TmplCore41;
94typedef OpenGl_TmplCore41<OpenGl_GlCore40Back> OpenGl_GlCore41Back;
95typedef OpenGl_TmplCore41<OpenGl_GlCore40> OpenGl_GlCore41;
96
97template<typename theBaseClass_t> struct OpenGl_TmplCore42;
98typedef OpenGl_TmplCore42<OpenGl_GlCore41Back> OpenGl_GlCore42Back;
99typedef OpenGl_TmplCore42<OpenGl_GlCore41> OpenGl_GlCore42;
100
101template<typename theBaseClass_t> struct OpenGl_TmplCore43;
102typedef OpenGl_TmplCore43<OpenGl_GlCore42Back> OpenGl_GlCore43Back;
103typedef OpenGl_TmplCore43<OpenGl_GlCore42> OpenGl_GlCore43;
104
105template<typename theBaseClass_t> struct OpenGl_TmplCore44;
106typedef OpenGl_TmplCore44<OpenGl_GlCore43Back> OpenGl_GlCore44Back;
107typedef OpenGl_TmplCore44<OpenGl_GlCore43> OpenGl_GlCore44;
108
5f8b738e 109//! This class generalize access to the GL context and available extensions.
110//!
111//! Functions are grouped into structures and accessed as fields.
112//! You should check the group for NULL before usage (if group is not NULL
113//! then all functions are available):
114//! @code
115//! if (myContext->core20 != NULL)
116//! {
117//! myGlProgram = myContext->core20->glCreateProgram();
118//! .. do more stuff ..
119//! }
120//! else
121//! {
122//! .. compatibility with outdated configurations ..
123//! }
124//! @endcode
125//!
126//! Current implementation provide access to OpenGL core functionality up to 2.0 version
127//! (core12, core13, core14, core15, fields core20).
01ca42b2 128//! within several extensions (arbTBO, arbFBO, etc.).
5f8b738e 129//!
130//! Simplified extensions classification:
131//! - prefixed with NV, AMD, ATI are vendor-specific (however may be provided by other vendors in some cases);
132//! - prefixed with EXT are accepted by 2+ vendors;
133//! - prefixed with ARB are accepted by Architecture Review Board and are candidates
134//! for inclusion into GL core functionality.
135//! Some functionality can be represented in several extensions simultaneously.
136//! In this case developer should be careful because different specification may differ
137//! in aspects (like enumeration values and error-handling).
138//!
139//! Notice that some systems provide mechanisms to simultaneously incorporate with GL contexts
140//! with different capabilities. Thats why OpenGl_Context should be initialized and used
141//! for each GL context individually.
2166f0fa
SK
142class OpenGl_Context : public Standard_Transient
143{
a174a3c5 144public:
145
146 //! Function for getting power of to number larger or equal to input number.
147 //! @param theNumber number to 'power of two'
148 //! @param theThreshold upper threshold
149 //! @return power of two number
150 inline static Standard_Integer GetPowerOfTwo (const Standard_Integer theNumber,
151 const Standard_Integer theThreshold)
152 {
153 for (Standard_Integer p2 = 2; p2 <= theThreshold; p2 <<= 1)
154 {
155 if (theNumber <= p2)
156 {
157 return p2;
158 }
159 }
160 return theThreshold;
161 }
162
2166f0fa
SK
163public:
164
5f8b738e 165 //! Empty constructor. You should call Init() to perform initialization with bound GL context.
58655684 166 Standard_EXPORT OpenGl_Context (const Handle(OpenGl_Caps)& theCaps = NULL);
5f8b738e 167
168 //! Destructor.
169 Standard_EXPORT virtual ~OpenGl_Context();
2166f0fa 170
05e2200b 171 //! Release all resources, including shared ones
172 Standard_EXPORT void forcedRelease();
173
5e27df78 174 //! Share GL context resources.
175 //! theShareCtx - handle to context to retrieve handles to shared resources.
176 Standard_EXPORT void Share (const Handle(OpenGl_Context)& theShareCtx);
177
7e7c2f0b 178 //! Initialize class from currently bound OpenGL context. Method should be called only once.
179 //! @return false if no GL context is bound to the current thread
f0430952 180 Standard_EXPORT Standard_Boolean Init();
2166f0fa 181
fd4a6963 182 //! @return true if this context is valid (has been initialized)
183 inline Standard_Boolean IsValid() const
184 {
185 return myIsInitialized;
186 }
187
da8bb41d 188#if defined(HAVE_EGL)
189 //! Initialize class from specified surface and rendering context. Method should be called only once.
190 //! @return false if OpenGL context can not be bound to specified surface
191 Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theEglSurface,
192 const Aspect_Display theEglDisplay,
193 const Aspect_RenderingContext theEglContext);
194#elif defined(_WIN32)
7e7c2f0b 195 //! Initialize class from specified window and rendering context. Method should be called only once.
196 //! @return false if OpenGL context can not be bound to specified window
f0430952 197 Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow,
198 const Aspect_Handle theWindowDC,
199 const Aspect_RenderingContext theGContext);
7e7c2f0b 200
201 //! @return the window handle (HWND) currently bound to this OpenGL context
202 inline Aspect_Handle Window() const
203 {
204 return myWindow;
205 }
206
4fe56619 207#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
7e7c2f0b 208 //! Initialize class from specified OpenGL context (NSOpenGLContext). Method should be called only once.
4fe56619 209 Standard_EXPORT Standard_Boolean Init (const void* theGContext);
2bd4c032 210#else
7e7c2f0b 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
f0430952 213 Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow,
214 const Aspect_Display theDisplay,
215 const Aspect_RenderingContext theGContext);
7e7c2f0b 216
217 //! @return the window handle (GLXDrawable) currently bound to this OpenGL context
218 inline Aspect_Drawable Window() const
219 {
220 return myWindow;
221 }
2bd4c032 222#endif
223
5f8b738e 224 //! Check if theExtName extension is supported by active GL context.
2bd4c032 225 Standard_EXPORT Standard_Boolean CheckExtension (const char* theExtName) const;
2166f0fa 226
58655684 227 //! Check if theExtName extension is in extensions string.
228 Standard_EXPORT static Standard_Boolean CheckExtension (const char* theExtString,
229 const char* theExtName);
230
2166f0fa 231 //! Auxiliary template to retrieve GL function pointer.
5f8b738e 232 //! Pointer to function retrieved from library is statically casted
233 //! to requested type - there no way to check real signature of exported function.
2166f0fa
SK
234 //! The context should be bound before call.
235 template <typename FuncType_t>
5f8b738e 236 Standard_Boolean FindProc (const char* theFuncName,
237 FuncType_t& theFuncPtr)
2166f0fa 238 {
5f8b738e 239 theFuncPtr = (FuncType_t )findProc (theFuncName);
2166f0fa
SK
240 return (theFuncPtr != NULL);
241 }
242
2bd4c032 243 //! @return true if detected GL version is greater or equal to requested one.
244 inline Standard_Boolean IsGlGreaterEqual (const Standard_Integer theVerMajor,
7e7c2f0b 245 const Standard_Integer theVerMinor) const
5f8b738e 246 {
247 return (myGlVerMajor > theVerMajor)
248 || (myGlVerMajor == theVerMajor && myGlVerMinor >= theVerMinor);
249 }
250
251 //! Clean up errors stack for this GL context (glGetError() in loop).
252 Standard_EXPORT void ResetErrors();
253
86fa64d9 254 //! This method uses system-dependent API to retrieve information
255 //! about GL context bound to the current thread.
256 //! @return true if current thread is bound to this GL context
257 Standard_EXPORT Standard_Boolean IsCurrent() const;
258
2bd4c032 259 //! Activates current context.
260 //! Class should be initialized with appropriate info.
261 Standard_EXPORT Standard_Boolean MakeCurrent();
262
5e27df78 263 //! Swap front/back buffers for this GL context (should be activated before!).
264 Standard_EXPORT void SwapBuffers();
265
b5ac8292 266 //! Return true if active mode is GL_RENDER (cached state)
267 Standard_Boolean IsRender() const
268 {
ca3c13d1 269 #if !defined(GL_ES_VERSION_2_0)
b5ac8292 270 return myRenderMode == GL_RENDER;
ca3c13d1 271 #else
272 return Standard_True;
273 #endif
b5ac8292 274 }
664cae74 275
b5ac8292 276 //! Return true if active mode is GL_FEEDBACK (cached state)
277 Standard_Boolean IsFeedback() const
278 {
ca3c13d1 279 #if !defined(GL_ES_VERSION_2_0)
b5ac8292 280 return myRenderMode == GL_FEEDBACK;
ca3c13d1 281 #else
282 return Standard_False;
283 #endif
b5ac8292 284 }
664cae74 285
f0430952 286 //! This function retrieves information from GL about free GPU memory that is:
287 //! - OS-dependent. On some OS it is per-process and on others - for entire system.
288 //! - Vendor-dependent. Currently available only on NVIDIA and AMD/ATi drivers only.
289 //! - Numbers meaning may vary.
290 //! You should use this info only for diagnostics purposes.
291 //! @return free GPU dedicated memory in bytes.
292 Standard_EXPORT Standard_Size AvailableMemory() const;
293
294 //! This function retrieves information from GL about GPU memory
295 //! and contains more vendor-specific values than AvailableMemory().
296 Standard_EXPORT TCollection_AsciiString MemoryInfo() const;
297
5e27df78 298 //! Access shared resource by its name.
299 //! @param theKey - unique identifier;
300 //! @return handle to shared resource or NULL.
301 Standard_EXPORT const Handle(OpenGl_Resource)& GetResource (const TCollection_AsciiString& theKey) const;
302
303 //! Access shared resource by its name.
304 //! @param theKey - unique identifier;
305 //! @param theValue - handle to fill;
306 //! @return true if resource was shared.
307 template<typename TheHandleType>
308 Standard_Boolean GetResource (const TCollection_AsciiString& theKey,
309 TheHandleType& theValue) const
310 {
311 const Handle(OpenGl_Resource)& aResource = GetResource (theKey);
312 if (aResource.IsNull())
313 {
314 return Standard_False;
315 }
316
317 theValue = TheHandleType::DownCast (aResource);
318 return !theValue.IsNull();
319 }
320
321 //! Register shared resource.
322 //! Notice that after registration caller shouldn't release it by himself -
323 //! it will be automatically released on context destruction.
324 //! @param theKey - unique identifier, shouldn't be empty;
325 //! @param theResource - new resource to register, shouldn't be NULL.
326 Standard_EXPORT Standard_Boolean ShareResource (const TCollection_AsciiString& theKey,
327 const Handle(OpenGl_Resource)& theResource);
328
329 //! Release shared resource.
330 //! If there are more than one reference to this resource
331 //! (also used by some other existing object) then call will be ignored.
332 //! This means that current object itself should nullify handle before this call.
333 //! Notice that this is unrecommended operation at all and should be used
334 //! only in case of fat resources to release memory for other needs.
a174a3c5 335 //! @param theKey unique identifier
336 //! @param theToDelay postpone release until next redraw call
337 Standard_EXPORT void ReleaseResource (const TCollection_AsciiString& theKey,
338 const Standard_Boolean theToDelay = Standard_False);
5e27df78 339
340 //! Append resource to queue for delayed clean up.
341 //! Resources in this queue will be released at next redraw call.
342 Standard_EXPORT void DelayedRelease (Handle(OpenGl_Resource)& theResource);
343
344 //! Clean up the delayed release queue.
345 Standard_EXPORT void ReleaseDelayed();
346
4269bd1b 347 //! @return tool for management of clippings within this context.
30f0ad28 348 inline OpenGl_Clipping& ChangeClipping() { return myClippingState; }
4269bd1b 349
350 //! @return tool for management of clippings within this context.
30f0ad28 351 inline const OpenGl_Clipping& Clipping() const { return myClippingState; }
352
353 //! @return tool for management of shader programs within this context.
354 inline const Handle(OpenGl_ShaderManager)& ShaderManager() const { return myShaderManager; }
4269bd1b 355
356public:
357
ca3c13d1 358 //! Either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1).
359 Standard_Integer TextureWrapClamp() const { return myTexClamp; }
360
bf75be98 361 //! @return maximum degree of anisotropy texture filter
362 Standard_EXPORT Standard_Integer MaxDegreeOfAnisotropy() const;
363
364 //! @return value for GL_MAX_TEXTURE_SIZE
365 Standard_EXPORT Standard_Integer MaxTextureSize() const;
366
4269bd1b 367 //! Get maximum number of clip planes supported by OpenGl.
7e7c2f0b 368 //! This value is implementation dependent. At least 6
4269bd1b 369 //! planes should be supported by OpenGl (see specs).
370 //! @return value for GL_MAX_CLIP_PLANES
371 Standard_EXPORT Standard_Integer MaxClipPlanes() const;
372
7d3e64ef 373 //! Returns true if VBO is supported and permitted.
374 inline bool ToUseVbo() const
375 {
376 return core15fwd != NULL
377 && !caps->vboDisable;
378 }
379
7d9e854b 380 //! @return cached state of GL_NORMALIZE.
381 Standard_Boolean IsGlNormalizeEnabled() const { return myIsGlNormalizeEnabled; }
382
383 //! Sets GL_NORMALIZE enabled or disabled.
384 //! @return old value of the flag
385 Standard_EXPORT Standard_Boolean SetGlNormalizeEnabled (Standard_Boolean isEnabled);
386
cbf18624 387public:
388
7e7c2f0b 389 //! @return messenger instance
857ffd5e 390 inline const Handle(Message_Messenger)& Messenger() const
cbf18624 391 {
8fa64b52 392 return ::Message::DefaultMessenger();
cbf18624 393 }
394
395 //! Callback for GL_ARB_debug_output extension
396 //! @param theSource message source within GL_DEBUG_SOURCE_ enumeration
397 //! @param theType message type within GL_DEBUG_TYPE_ enumeration
398 //! @param theId message ID within source
399 //! @param theSeverity message severity within GL_DEBUG_SEVERITY_ enumeration
400 //! @param theMessage the message itself
401 Standard_EXPORT void PushMessage (const unsigned int theSource,
402 const unsigned int theType,
403 const unsigned int theId,
404 const unsigned int theSeverity,
405 const TCollection_ExtendedString& theMessage);
406
b5ac8292 407
408
409 //! @return true if OpenGl context supports left and
410 //! right rendering buffers.
411 Standard_Boolean HasStereoBuffers() const
412 {
ca3c13d1 413 #if !defined(GL_ES_VERSION_2_0)
b5ac8292 414 return myIsStereoBuffers;
ca3c13d1 415 #else
416 return Standard_False;
417 #endif
b5ac8292 418 }
419
7d3e64ef 420public: //! @name methods to alter or retrieve current state
421
b5ac8292 422 //! Switch to left stereographic rendering buffer.
423 //! This method can be used to keep unchanged choise
424 //! of front/back/both buffer rendering.
425 Standard_EXPORT void SetDrawBufferLeft();
426
427 //! Switch to right stereographic rendering buffer.
428 //! This method can be used to keep unchanged choise
429 //! of front/back/both buffer rendering.
430 Standard_EXPORT void SetDrawBufferRight();
431
432 //! Switch to non-stereographic rendering buffer.
433 //! This method can be used to keep unchanged choise
434 //! of front/back/both buffer rendering.
435 Standard_EXPORT void SetDrawBufferMono();
436
437 //! Fetch OpenGl context state. This class tracks value of several OpenGl
438 //! state variables. Consulting the cached values is quicker than
439 //! doing the same via OpenGl API. Call this method if any of the controlled
440 //! OpenGl state variables has a possibility of being out-of-date.
441 Standard_EXPORT void FetchState();
442
7d3e64ef 443 //! @return active GLSL program
444 const Handle(OpenGl_ShaderProgram)& ActiveProgram() const
445 {
446 return myActiveProgram;
447 }
448
25ef750e 449 //! @return OpenGL sampler object used to override default texture parameters
450 const Handle(OpenGl_Sampler)& TextureSampler()
451 {
452 return myTexSampler;
453 }
454
7d3e64ef 455 //! Bind specified program to current context,
456 //! or unbind previous one when NULL specified.
8625ef7e 457 //! @return true if some program is bound to context
458 Standard_EXPORT Standard_Boolean BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram);
459
460 //! Setup current color.
461 Standard_EXPORT void SetColor4fv (const OpenGl_Vec4& theColor);
462
463 //! Setup point size.
464 Standard_EXPORT void SetPointSize (const Standard_ShortReal theSize);
7d3e64ef 465
5f8b738e 466private:
467
468 //! Wrapper to system function to retrieve GL function pointer by name.
469 Standard_EXPORT void* findProc (const char* theFuncName);
470
471 //! Read OpenGL version information from active context.
472 Standard_EXPORT void readGlVersion();
473
474 //! Private initialization function that should be called only once.
475 Standard_EXPORT void init();
476
01ca42b2 477public: //! @name core profiles
478
479 OpenGl_GlCore11* core11; //!< OpenGL 1.1 core functionality
480 OpenGl_GlCore11Fwd* core11fwd; //!< OpenGL 1.1 without deprecated entry points
481 OpenGl_GlCore15* core15; //!< OpenGL 1.5 core functionality
482 OpenGl_GlCore15Fwd* core15fwd; //!< OpenGL 1.5 without deprecated entry points
483 OpenGl_GlCore20* core20; //!< OpenGL 2.0 core functionality (includes 1.5)
484 OpenGl_GlCore20Fwd* core20fwd; //!< OpenGL 2.0 without deprecated entry points
485 OpenGl_GlCore32* core32; //!< OpenGL 3.2 core profile
486 OpenGl_GlCore32Back* core32back; //!< OpenGL 3.2 backward compatibility profile
25ef750e 487 OpenGl_GlCore33* core33; //!< OpenGL 3.3 core profile
488 OpenGl_GlCore33Back* core33back; //!< OpenGL 3.3 backward compatibility profile
01ca42b2 489 OpenGl_GlCore41* core41; //!< OpenGL 4.1 core profile
490 OpenGl_GlCore41Back* core41back; //!< OpenGL 4.1 backward compatibility profile
491 OpenGl_GlCore42* core42; //!< OpenGL 4.2 core profile
492 OpenGl_GlCore42Back* core42back; //!< OpenGL 4.2 backward compatibility profile
493 OpenGl_GlCore43* core43; //!< OpenGL 4.3 core profile
494 OpenGl_GlCore43Back* core43back; //!< OpenGL 4.3 backward compatibility profile
495 OpenGl_GlCore44* core44; //!< OpenGL 4.4 core profile
496 OpenGl_GlCore44Back* core44back; //!< OpenGL 4.4 backward compatibility profile
5f8b738e 497
58655684 498 Handle(OpenGl_Caps) caps; //!< context options
499
01ca42b2 500public: //! @name extensions
5f8b738e 501
25ef750e 502 Standard_Boolean hasHighp; //!< highp in GLSL ES fragment shader is supported
503 Standard_Boolean hasTexRGBA8; //!< always available on desktop; on OpenGL ES - since 3.0 or as extension GL_OES_rgb8_rgba8
504 Standard_Boolean arbNPTW; //!< GL_ARB_texture_non_power_of_two
505 Standard_Boolean arbTexRG; //!< GL_ARB_texture_rg
506 OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture
507 OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object
508 Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0
509 OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced
510 OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output
511 OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object
512 OpenGl_ExtGS* extGS; //!< GL_EXT_geometry_shader4
513 Standard_Boolean extBgra; //!< GL_EXT_bgra or GL_EXT_texture_format_BGRA8888 on OpenGL ES
514 Standard_Boolean extAnis; //!< GL_EXT_texture_filter_anisotropic
515 Standard_Boolean extPDS; //!< GL_EXT_packed_depth_stencil
516 Standard_Boolean atiMem; //!< GL_ATI_meminfo
517 Standard_Boolean nvxMem; //!< GL_NVX_gpu_memory_info
5f8b738e 518
5e27df78 519private: // system-dependent fields
2166f0fa 520
da8bb41d 521#if defined(HAVE_EGL)
522 Aspect_Drawable myWindow; //!< EGL surface : EGLSurface
523 Aspect_Display myDisplay; //!< EGL connection to the Display : EGLDisplay
524 Aspect_RenderingContext myGContext; //!< EGL rendering context : EGLContext
525#elif defined(_WIN32)
2bd4c032 526 Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND
527 Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC
528 Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC
4fe56619 529#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
530 void* myGContext; //!< Rendering Context handle : NSOpenGLContext
2bd4c032 531#else
532 Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable
533 Aspect_Display myDisplay; //!< connection to the X-server : Display*
534 Aspect_RenderingContext myGContext; //!< X-GLX rendering context : GLXContext
535#endif
536
5e27df78 537private: // context info
538
a174a3c5 539 typedef NCollection_DataMap<TCollection_AsciiString, Standard_Integer> OpenGl_DelayReleaseMap;
540 typedef NCollection_Handle<OpenGl_DelayReleaseMap> Handle(OpenGl_DelayReleaseMap);
5e27df78 541 typedef NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)> OpenGl_ResourcesMap;
542 typedef NCollection_Handle<OpenGl_ResourcesMap> Handle(OpenGl_ResourcesMap);
3125ebb6 543 typedef NCollection_List<Handle(OpenGl_Resource)> OpenGl_ResourcesStack;
544 typedef NCollection_Handle<OpenGl_ResourcesStack> Handle(OpenGl_ResourcesStack);
5e27df78 545
a174a3c5 546 Handle(OpenGl_ResourcesMap) mySharedResources; //!< shared resources with unique identification key
547 Handle(OpenGl_DelayReleaseMap) myDelayed; //!< shared resources for delayed release
3125ebb6 548 Handle(OpenGl_ResourcesStack) myUnusedResources; //!< stack of resources for delayed clean up
5e27df78 549
30f0ad28 550 OpenGl_Clipping myClippingState; //!< state of clip planes
4269bd1b 551
7d9e854b 552 void* myGlLibHandle; //!< optional handle to GL library
01ca42b2 553 NCollection_Handle<OpenGl_GlFunctions>
7d9e854b 554 myFuncs; //!< mega structure for all GL functions
555 Standard_Integer myAnisoMax; //!< maximum level of anisotropy texture filter
556 Standard_Integer myTexClamp; //!< either GL_CLAMP_TO_EDGE (1.2+) or GL_CLAMP (1.1)
557 Standard_Integer myMaxTexDim; //!< value for GL_MAX_TEXTURE_SIZE
558 Standard_Integer myMaxClipPlanes; //!< value for GL_MAX_CLIP_PLANES
559 Standard_Integer myGlVerMajor; //!< cached GL version major number
560 Standard_Integer myGlVerMinor; //!< cached GL version minor number
561 Standard_Boolean myIsInitialized; //!< flag indicates initialization state
562 Standard_Boolean myIsStereoBuffers; //!< context supports stereo buffering
563 Standard_Boolean myIsGlNormalizeEnabled; //!< GL_NORMALIZE flag
564 //!< Used to tell OpenGl that normals should be normalized
2166f0fa 565
30f0ad28 566 Handle(OpenGl_ShaderManager) myShaderManager; //! support object for managing shader programs
567
7d3e64ef 568private: //! @name fields tracking current state
569
570 Handle(OpenGl_ShaderProgram) myActiveProgram; //!< currently active GLSL program
25ef750e 571 Handle(OpenGl_Sampler) myTexSampler; //!< currently active sampler object
7d3e64ef 572 Standard_Integer myRenderMode; //!< value for active rendering mode
573 Standard_Integer myDrawBuffer; //!< current draw buffer
574
5e27df78 575private:
576
577 //! Copying allowed only within Handles
578 OpenGl_Context (const OpenGl_Context& );
579 OpenGl_Context& operator= (const OpenGl_Context& );
580
2166f0fa
SK
581public:
582
5f8b738e 583 DEFINE_STANDARD_RTTI(OpenGl_Context) // Type definition
2166f0fa 584
5e27df78 585 friend class OpenGl_Window;
586
2166f0fa
SK
587};
588
589#endif // _OpenGl_Context_H__