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