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