Commit | Line | Data |
---|---|---|
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 | |
58655684 | 16 | #if defined(_WIN32) |
5f8b738e | 17 | #include <windows.h> |
18 | #endif | |
19 | ||
2166f0fa SK |
20 | #include <OpenGl_Context.hxx> |
21 | ||
5e27df78 | 22 | #include <OpenGl_ArbTBO.hxx> |
23 | #include <OpenGl_ArbIns.hxx> | |
58655684 | 24 | #include <OpenGl_ArbDbg.hxx> |
01ca42b2 | 25 | #include <OpenGl_ArbFBO.hxx> |
37eb4787 | 26 | #include <OpenGl_ExtGS.hxx> |
cc8cbabe | 27 | #include <OpenGl_ArbSamplerObject.hxx> |
25ef750e | 28 | #include <OpenGl_ArbTexBindless.hxx> |
4e1523ef | 29 | #include <OpenGl_GlCore44.hxx> |
a2e4f780 | 30 | #include <OpenGl_FrameBuffer.hxx> |
15669413 | 31 | #include <OpenGl_FrameStats.hxx> |
25ef750e | 32 | #include <OpenGl_Sampler.hxx> |
30f0ad28 | 33 | #include <OpenGl_ShaderManager.hxx> |
299e0ab9 | 34 | #include <OpenGl_Workspace.hxx> |
35 | #include <OpenGl_AspectFace.hxx> | |
79f4f036 | 36 | #include <Graphic3d_TransformUtils.hxx> |
56689b27 | 37 | #include <Graphic3d_RenderingParams.hxx> |
5f8b738e | 38 | |
cbf18624 | 39 | #include <Message_Messenger.hxx> |
30f0ad28 | 40 | |
a174a3c5 | 41 | #include <NCollection_Vector.hxx> |
42 | ||
2bd4c032 | 43 | #include <Standard_ProgramError.hxx> |
44 | ||
f5f4ebd0 | 45 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context,Standard_Transient) |
46 | ||
da8bb41d | 47 | #if defined(HAVE_EGL) |
48 | #include <EGL/egl.h> | |
49 | #ifdef _MSC_VER | |
50 | #pragma comment(lib, "libEGL.lib") | |
51 | #endif | |
52 | #elif defined(_WIN32) | |
5f8b738e | 53 | // |
54 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
55 | #include <dlfcn.h> | |
f978241f | 56 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
57 | // | |
58 | #else | |
59 | #include <OpenGL/OpenGL.h> | |
26d9c835 | 60 | #include <CoreGraphics/CoreGraphics.h> |
f978241f | 61 | #endif |
5f8b738e | 62 | #else |
63 | #include <GL/glx.h> // glXGetProcAddress() | |
64 | #endif | |
65 | ||
5e27df78 | 66 | namespace |
67 | { | |
68 | static const Handle(OpenGl_Resource) NULL_GL_RESOURCE; | |
458e3c0d | 69 | static const OpenGl_Mat4 THE_IDENTITY_MATRIX; |
26d9c835 | 70 | |
71 | //! Add key-value pair to the dictionary. | |
72 | static void addInfo (TColStd_IndexedDataMapOfStringString& theDict, | |
73 | const TCollection_AsciiString& theKey, | |
74 | const TCollection_AsciiString& theValue) | |
75 | { | |
76 | theDict.ChangeFromIndex (theDict.Add (theKey, theValue)) = theValue; | |
77 | } | |
78 | ||
79 | //! Add key-value pair to the dictionary. | |
80 | static void addInfo (TColStd_IndexedDataMapOfStringString& theDict, | |
81 | const TCollection_AsciiString& theKey, | |
82 | const char* theValue) | |
83 | { | |
84 | TCollection_AsciiString aValue (theValue != NULL ? theValue : ""); | |
85 | theDict.ChangeFromIndex (theDict.Add (theKey, aValue)) = aValue; | |
86 | } | |
01ca42b2 | 87 | } |
5e27df78 | 88 | |
2166f0fa SK |
89 | // ======================================================================= |
90 | // function : OpenGl_Context | |
91 | // purpose : | |
92 | // ======================================================================= | |
58655684 | 93 | OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps) |
01ca42b2 | 94 | : core11 (NULL), |
95 | core11fwd (NULL), | |
96 | core15 (NULL), | |
97 | core15fwd (NULL), | |
98 | core20 (NULL), | |
99 | core20fwd (NULL), | |
100 | core32 (NULL), | |
101 | core32back (NULL), | |
25ef750e | 102 | core33 (NULL), |
103 | core33back (NULL), | |
01ca42b2 | 104 | core41 (NULL), |
105 | core41back (NULL), | |
106 | core42 (NULL), | |
107 | core42back (NULL), | |
108 | core43 (NULL), | |
109 | core43back (NULL), | |
110 | core44 (NULL), | |
111 | core44back (NULL), | |
58655684 | 112 | caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()), |
ca3c13d1 | 113 | #if defined(GL_ES_VERSION_2_0) |
114 | hasHighp (Standard_False), | |
e99a2f7c | 115 | hasUintIndex(Standard_False), |
ca3c13d1 | 116 | hasTexRGBA8(Standard_False), |
c39bb31b | 117 | hasFlatShading (OpenGl_FeatureNotAvailable), |
ca3c13d1 | 118 | #else |
119 | hasHighp (Standard_True), | |
e99a2f7c | 120 | hasUintIndex(Standard_True), |
ca3c13d1 | 121 | hasTexRGBA8(Standard_True), |
c39bb31b | 122 | hasFlatShading (OpenGl_FeatureInCore), |
ca3c13d1 | 123 | #endif |
a1073ae2 | 124 | hasDrawBuffers (OpenGl_FeatureNotAvailable), |
125 | hasFloatBuffer (OpenGl_FeatureNotAvailable), | |
126 | hasHalfFloatBuffer (OpenGl_FeatureNotAvailable), | |
127 | hasSampleVariables (OpenGl_FeatureNotAvailable), | |
128 | arbDrawBuffers (Standard_False), | |
25ef750e | 129 | arbNPTW (Standard_False), |
130 | arbTexRG (Standard_False), | |
74fb257d | 131 | arbTexFloat (Standard_False), |
cc8cbabe | 132 | arbSamplerObject (NULL), |
25ef750e | 133 | arbTexBindless (NULL), |
5e27df78 | 134 | arbTBO (NULL), |
25ef750e | 135 | arbTboRGB32 (Standard_False), |
5e27df78 | 136 | arbIns (NULL), |
58655684 | 137 | arbDbg (NULL), |
01ca42b2 | 138 | arbFBO (NULL), |
b86bb3df | 139 | arbFBOBlit (NULL), |
a1073ae2 | 140 | arbSampleShading (Standard_False), |
1ce0716b | 141 | extFragDepth (Standard_False), |
a1073ae2 | 142 | extDrawBuffers (Standard_False), |
37eb4787 | 143 | extGS (NULL), |
bf75be98 | 144 | extBgra(Standard_False), |
145 | extAnis(Standard_False), | |
30f0ad28 | 146 | extPDS (Standard_False), |
f0430952 | 147 | atiMem (Standard_False), |
148 | nvxMem (Standard_False), | |
a1073ae2 | 149 | oesSampleVariables (Standard_False), |
8c3237d4 | 150 | oesStdDerivatives (Standard_False), |
5e27df78 | 151 | mySharedResources (new OpenGl_ResourcesMap()), |
a174a3c5 | 152 | myDelayed (new OpenGl_DelayReleaseMap()), |
3125ebb6 | 153 | myUnusedResources (new OpenGl_ResourcesStack()), |
4269bd1b | 154 | myClippingState (), |
5f8b738e | 155 | myGlLibHandle (NULL), |
01ca42b2 | 156 | myFuncs (new OpenGl_GlFunctions()), |
2f6cb3ac | 157 | myAnisoMax (1), |
ca3c13d1 | 158 | myTexClamp (GL_CLAMP_TO_EDGE), |
eafb234b | 159 | myMaxTexDim (1024), |
cc8cbabe | 160 | myMaxTexCombined (1), |
4269bd1b | 161 | myMaxClipPlanes (6), |
3c4b62a4 | 162 | myMaxMsaaSamples(0), |
a1073ae2 | 163 | myMaxDrawBuffers (1), |
164 | myMaxColorAttachments (1), | |
5f8b738e | 165 | myGlVerMajor (0), |
166 | myGlVerMinor (0), | |
b5ac8292 | 167 | myIsInitialized (Standard_False), |
168 | myIsStereoBuffers (Standard_False), | |
7d9e854b | 169 | myIsGlNormalizeEnabled (Standard_False), |
3a9b5dc8 | 170 | myHasRayTracing (Standard_False), |
171 | myHasRayTracingTextures (Standard_False), | |
172 | myHasRayTracingAdaptiveSampling (Standard_False), | |
15669413 | 173 | myFrameStats (new OpenGl_FrameStats()), |
ca3c13d1 | 174 | #if !defined(GL_ES_VERSION_2_0) |
fd59283a | 175 | myPointSpriteOrig (GL_UPPER_LEFT), |
7d3e64ef | 176 | myRenderMode (GL_RENDER), |
6d0e6be5 | 177 | myPolygonMode (GL_FILL), |
ca3c13d1 | 178 | #else |
fd59283a | 179 | myPointSpriteOrig (0), |
ca3c13d1 | 180 | myRenderMode (0), |
6d0e6be5 | 181 | myPolygonMode (0), |
ca3c13d1 | 182 | #endif |
b6472664 | 183 | myToCullBackFaces (false), |
38a0206f | 184 | myReadBuffer (0), |
c3487460 | 185 | myDrawBuffers (0, 7), |
4e1523ef | 186 | myDefaultVao (0), |
f88457e6 | 187 | myColorMask (true), |
c40eb6b9 | 188 | myAlphaToCoverage (false), |
75c262a9 | 189 | myIsGlDebugCtx (Standard_False), |
56689b27 | 190 | myResolution (Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION), |
191 | myResolutionRatio (1.0f), | |
192 | myLineWidthScale (1.0f), | |
193 | myRenderScale (1.0f), | |
194 | myRenderScaleInv (1.0f) | |
2166f0fa | 195 | { |
3bffef55 | 196 | myViewport[0] = 0; |
197 | myViewport[1] = 0; | |
198 | myViewport[2] = 0; | |
199 | myViewport[3] = 0; | |
56689b27 | 200 | myViewportVirt[0] = 0; |
201 | myViewportVirt[1] = 0; | |
202 | myViewportVirt[2] = 0; | |
203 | myViewportVirt[3] = 0; | |
3bffef55 | 204 | |
8d1a539c | 205 | myPolygonOffset.Mode = Aspect_POM_Off; |
206 | myPolygonOffset.Factor = 0.0f; | |
207 | myPolygonOffset.Units = 0.0f; | |
208 | ||
4e1523ef | 209 | // system-dependent fields |
210 | #if defined(HAVE_EGL) | |
211 | myDisplay = (Aspect_Display )EGL_NO_DISPLAY; | |
212 | myWindow = (Aspect_Drawable )EGL_NO_SURFACE; | |
458c2c58 | 213 | myGContext = (Aspect_RenderingContext )EGL_NO_CONTEXT; |
4e1523ef | 214 | #elif defined(_WIN32) |
215 | myWindow = NULL; | |
216 | myWindowDC = NULL; | |
217 | myGContext = NULL; | |
218 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
5f8b738e | 219 | // Vendors can not extend functionality on this system |
220 | // and developers are limited to OpenGL support provided by Mac OS X SDK. | |
221 | // We retrieve function pointers from system library | |
222 | // to generalize extensions support on all platforms. | |
223 | // In this way we also reach binary compatibility benefit between OS releases | |
224 | // if some newest functionality is optionally used. | |
225 | // Notice that GL version / extension availability checks are required | |
226 | // because function pointers may be available but not functionality itself | |
227 | // (depends on renderer). | |
a2e4f780 | 228 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
229 | myGContext = NULL; | |
230 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY); | |
231 | #else | |
4e1523ef | 232 | myGContext = NULL; |
5f8b738e | 233 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY); |
a2e4f780 | 234 | #endif |
4e1523ef | 235 | #else |
236 | myDisplay = NULL; | |
237 | myWindow = 0; | |
238 | myGContext = 0; | |
5f8b738e | 239 | #endif |
a2e4f780 | 240 | |
01ca42b2 | 241 | memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions)); |
30f0ad28 | 242 | myShaderManager = new OpenGl_ShaderManager (this); |
2166f0fa SK |
243 | } |
244 | ||
245 | // ======================================================================= | |
246 | // function : ~OpenGl_Context | |
247 | // purpose : | |
248 | // ======================================================================= | |
249 | OpenGl_Context::~OpenGl_Context() | |
250 | { | |
5e27df78 | 251 | // release clean up queue |
252 | ReleaseDelayed(); | |
253 | ||
4e1523ef | 254 | #if !defined(GL_ES_VERSION_2_0) |
255 | // release default VAO | |
256 | if (myDefaultVao != 0 | |
257 | && IsValid() | |
258 | && core32 != NULL) | |
259 | { | |
260 | core32->glDeleteVertexArrays (1, &myDefaultVao); | |
261 | } | |
262 | myDefaultVao = 0; | |
263 | #endif | |
264 | ||
a2e4f780 | 265 | // release default FBO |
266 | if (!myDefaultFbo.IsNull()) | |
267 | { | |
268 | myDefaultFbo->Release (this); | |
269 | myDefaultFbo.Nullify(); | |
270 | } | |
271 | ||
5e27df78 | 272 | // release shared resources if any |
4796758e | 273 | if (mySharedResources->GetRefCount() <= 1) |
5e27df78 | 274 | { |
392ac980 | 275 | myShaderManager.Nullify(); |
5e27df78 | 276 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); |
277 | anIter.More(); anIter.Next()) | |
278 | { | |
279 | anIter.Value()->Release (this); | |
280 | } | |
e1c659da | 281 | |
282 | // release delayed resources added during deletion of shared resources | |
283 | while (!myUnusedResources->IsEmpty()) | |
284 | { | |
285 | myUnusedResources->First()->Release (this); | |
286 | myUnusedResources->RemoveFirst(); | |
287 | } | |
5e27df78 | 288 | } |
c357e426 | 289 | else if (myShaderManager->IsSameContext (this)) |
392ac980 | 290 | { |
291 | myShaderManager->SetContext (NULL); | |
292 | } | |
5e27df78 | 293 | mySharedResources.Nullify(); |
a174a3c5 | 294 | myDelayed.Nullify(); |
5e27df78 | 295 | |
cbf18624 | 296 | if (arbDbg != NULL |
4e1523ef | 297 | && myIsGlDebugCtx |
f8c8ba7a | 298 | && IsValid()) |
cbf18624 | 299 | { |
300 | // reset callback | |
0deb6f04 | 301 | #if !defined(GL_ES_VERSION_2_0) |
cbf18624 | 302 | void* aPtr = NULL; |
3b523c4c | 303 | glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM, &aPtr); |
cbf18624 | 304 | if (aPtr == this) |
0deb6f04 | 305 | #endif |
cbf18624 | 306 | { |
0deb6f04 | 307 | arbDbg->glDebugMessageCallback (NULL, NULL); |
cbf18624 | 308 | } |
4e1523ef | 309 | myIsGlDebugCtx = Standard_False; |
cbf18624 | 310 | } |
5f8b738e | 311 | } |
312 | ||
05e2200b | 313 | // ======================================================================= |
314 | // function : forcedRelease | |
315 | // purpose : | |
316 | // ======================================================================= | |
317 | void OpenGl_Context::forcedRelease() | |
318 | { | |
319 | ReleaseDelayed(); | |
320 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); | |
321 | anIter.More(); anIter.Next()) | |
322 | { | |
323 | anIter.Value()->Release (this); | |
324 | } | |
325 | mySharedResources->Clear(); | |
326 | myShaderManager->clear(); | |
327 | myShaderManager->SetContext (NULL); | |
e1c659da | 328 | |
329 | // release delayed resources added during deletion of shared resources | |
330 | while (!myUnusedResources->IsEmpty()) | |
331 | { | |
332 | myUnusedResources->First()->Release (this); | |
333 | myUnusedResources->RemoveFirst(); | |
334 | } | |
05e2200b | 335 | } |
336 | ||
3bffef55 | 337 | // ======================================================================= |
338 | // function : ResizeViewport | |
339 | // purpose : | |
340 | // ======================================================================= | |
341 | void OpenGl_Context::ResizeViewport (const Standard_Integer* theRect) | |
342 | { | |
343 | core11fwd->glViewport (theRect[0], theRect[1], theRect[2], theRect[3]); | |
344 | myViewport[0] = theRect[0]; | |
345 | myViewport[1] = theRect[1]; | |
346 | myViewport[2] = theRect[2]; | |
347 | myViewport[3] = theRect[3]; | |
56689b27 | 348 | if (HasRenderScale()) |
349 | { | |
350 | myViewportVirt[0] = Standard_Integer(theRect[0] * myRenderScaleInv); | |
351 | myViewportVirt[1] = Standard_Integer(theRect[1] * myRenderScaleInv); | |
352 | myViewportVirt[2] = Standard_Integer(theRect[2] * myRenderScaleInv); | |
353 | myViewportVirt[3] = Standard_Integer(theRect[3] * myRenderScaleInv); | |
354 | } | |
355 | else | |
356 | { | |
357 | myViewportVirt[0] = theRect[0]; | |
358 | myViewportVirt[1] = theRect[1]; | |
359 | myViewportVirt[2] = theRect[2]; | |
360 | myViewportVirt[3] = theRect[3]; | |
361 | } | |
3bffef55 | 362 | } |
363 | ||
ca3c13d1 | 364 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 365 | inline Standard_Integer stereoToMonoBuffer (const Standard_Integer theBuffer) |
366 | { | |
367 | switch (theBuffer) | |
b5ac8292 | 368 | { |
38a0206f | 369 | case GL_BACK_LEFT: |
370 | case GL_BACK_RIGHT: | |
371 | return GL_BACK; | |
372 | case GL_FRONT_LEFT: | |
373 | case GL_FRONT_RIGHT: | |
374 | return GL_FRONT; | |
375 | default: | |
376 | return theBuffer; | |
b5ac8292 | 377 | } |
378 | } | |
38a0206f | 379 | #endif |
b5ac8292 | 380 | |
381 | // ======================================================================= | |
38a0206f | 382 | // function : SetReadBuffer |
b5ac8292 | 383 | // purpose : |
384 | // ======================================================================= | |
38a0206f | 385 | void OpenGl_Context::SetReadBuffer (const Standard_Integer theReadBuffer) |
b5ac8292 | 386 | { |
ca3c13d1 | 387 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 388 | myReadBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theReadBuffer) : theReadBuffer; |
389 | if (myReadBuffer < GL_COLOR_ATTACHMENT0 | |
390 | && arbFBO != NULL) | |
b5ac8292 | 391 | { |
38a0206f | 392 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 393 | } |
38a0206f | 394 | ::glReadBuffer (myReadBuffer); |
395 | #else | |
396 | (void )theReadBuffer; | |
ca3c13d1 | 397 | #endif |
b5ac8292 | 398 | } |
399 | ||
400 | // ======================================================================= | |
38a0206f | 401 | // function : SetDrawBuffer |
b5ac8292 | 402 | // purpose : |
403 | // ======================================================================= | |
38a0206f | 404 | void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer) |
b5ac8292 | 405 | { |
ca3c13d1 | 406 | #if !defined(GL_ES_VERSION_2_0) |
a1073ae2 | 407 | const Standard_Integer aDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer; |
408 | if (aDrawBuffer < GL_COLOR_ATTACHMENT0 | |
38a0206f | 409 | && arbFBO != NULL) |
b5ac8292 | 410 | { |
38a0206f | 411 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 412 | } |
a1073ae2 | 413 | ::glDrawBuffer (aDrawBuffer); |
414 | ||
c3487460 | 415 | myDrawBuffers.Init (GL_NONE); |
416 | myDrawBuffers.SetValue (0, aDrawBuffer); | |
38a0206f | 417 | #else |
418 | (void )theDrawBuffer; | |
ca3c13d1 | 419 | #endif |
b5ac8292 | 420 | } |
421 | ||
a1073ae2 | 422 | // ======================================================================= |
423 | // function : SetDrawBuffers | |
424 | // purpose : | |
425 | // ======================================================================= | |
426 | void OpenGl_Context::SetDrawBuffers (const Standard_Integer theNb, const Standard_Integer* theDrawBuffers) | |
427 | { | |
428 | Standard_ASSERT_RETURN (hasDrawBuffers, "Multiple draw buffers feature is not supported by the context", Standard_ASSERT_DO_NOTHING()); | |
429 | ||
c3487460 | 430 | if (myDrawBuffers.Length() < theNb) |
431 | { | |
432 | // should actually never happen here | |
433 | myDrawBuffers.Resize (0, theNb - 1, false); | |
434 | } | |
435 | myDrawBuffers.Init (GL_NONE); | |
a1073ae2 | 436 | |
437 | Standard_Boolean useDefaultFbo = Standard_False; | |
438 | for (Standard_Integer anI = 0; anI < theNb; ++anI) | |
439 | { | |
b17e5bae | 440 | if (theDrawBuffers[anI] < GL_COLOR_ATTACHMENT0 && theDrawBuffers[anI] != GL_NONE) |
a1073ae2 | 441 | { |
442 | useDefaultFbo = Standard_True; | |
443 | } | |
c3487460 | 444 | else |
a1073ae2 | 445 | { |
b17e5bae | 446 | myDrawBuffers.SetValue (anI, theDrawBuffers[anI]); |
a1073ae2 | 447 | } |
448 | } | |
449 | if (arbFBO != NULL && useDefaultFbo) | |
450 | { | |
451 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); | |
452 | } | |
453 | ||
454 | myFuncs->glDrawBuffers (theNb, (const GLenum*)theDrawBuffers); | |
455 | } | |
456 | ||
b6472664 | 457 | // ======================================================================= |
458 | // function : SetCullBackFaces | |
459 | // purpose : | |
460 | // ======================================================================= | |
461 | void OpenGl_Context::SetCullBackFaces (bool theToEnable) | |
462 | { | |
463 | if (myToCullBackFaces == theToEnable) | |
464 | { | |
465 | return; | |
466 | } | |
467 | ||
468 | myToCullBackFaces = theToEnable; | |
469 | if (theToEnable) | |
470 | { | |
471 | //glCullFace (GL_BACK); GL_BACK by default | |
472 | core11fwd->glEnable (GL_CULL_FACE); | |
473 | } | |
474 | else | |
475 | { | |
476 | core11fwd->glDisable (GL_CULL_FACE); | |
477 | } | |
478 | } | |
479 | ||
b5ac8292 | 480 | // ======================================================================= |
481 | // function : FetchState | |
482 | // purpose : | |
483 | // ======================================================================= | |
484 | void OpenGl_Context::FetchState() | |
485 | { | |
ca3c13d1 | 486 | #if !defined(GL_ES_VERSION_2_0) |
b5ac8292 | 487 | // cache feedback mode state |
4e1523ef | 488 | if (core11 != NULL) |
489 | { | |
490 | ::glGetIntegerv (GL_RENDER_MODE, &myRenderMode); | |
491 | } | |
b5ac8292 | 492 | |
a1073ae2 | 493 | // cache read buffers state |
38a0206f | 494 | ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer); |
a1073ae2 | 495 | |
496 | // cache draw buffers state | |
c3487460 | 497 | if (myDrawBuffers.Length() < myMaxDrawBuffers) |
498 | { | |
499 | myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false); | |
500 | } | |
501 | myDrawBuffers.Init (GL_NONE); | |
a1073ae2 | 502 | |
c3487460 | 503 | Standard_Integer aDrawBuffer = GL_NONE; |
a1073ae2 | 504 | if (myMaxDrawBuffers == 1) |
505 | { | |
a1073ae2 | 506 | ::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer); |
c3487460 | 507 | myDrawBuffers.SetValue (0, aDrawBuffer); |
a1073ae2 | 508 | } |
509 | else | |
510 | { | |
a1073ae2 | 511 | for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI) |
512 | { | |
513 | ::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer); | |
c3487460 | 514 | myDrawBuffers.SetValue (anI, aDrawBuffer); |
a1073ae2 | 515 | } |
516 | } | |
ca3c13d1 | 517 | #endif |
b5ac8292 | 518 | } |
519 | ||
5e27df78 | 520 | // ======================================================================= |
521 | // function : Share | |
522 | // purpose : | |
523 | // ======================================================================= | |
524 | void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx) | |
525 | { | |
526 | if (!theShareCtx.IsNull()) | |
527 | { | |
528 | mySharedResources = theShareCtx->mySharedResources; | |
a174a3c5 | 529 | myDelayed = theShareCtx->myDelayed; |
3125ebb6 | 530 | myUnusedResources = theShareCtx->myUnusedResources; |
392ac980 | 531 | myShaderManager = theShareCtx->myShaderManager; |
5e27df78 | 532 | } |
533 | } | |
534 | ||
4fe56619 | 535 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
536 | ||
86fa64d9 | 537 | // ======================================================================= |
538 | // function : IsCurrent | |
539 | // purpose : | |
540 | // ======================================================================= | |
541 | Standard_Boolean OpenGl_Context::IsCurrent() const | |
542 | { | |
da8bb41d | 543 | #if defined(HAVE_EGL) |
544 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
545 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
546 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
547 | { | |
548 | return Standard_False; | |
549 | } | |
550 | ||
551 | return (((EGLDisplay )myDisplay == eglGetCurrentDisplay()) | |
552 | && ((EGLContext )myGContext == eglGetCurrentContext()) | |
553 | && ((EGLSurface )myWindow == eglGetCurrentSurface (EGL_DRAW))); | |
554 | #elif defined(_WIN32) | |
86fa64d9 | 555 | if (myWindowDC == NULL || myGContext == NULL) |
556 | { | |
557 | return Standard_False; | |
558 | } | |
559 | return (( (HDC )myWindowDC == wglGetCurrentDC()) | |
560 | && ((HGLRC )myGContext == wglGetCurrentContext())); | |
561 | #else | |
562 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) | |
563 | { | |
564 | return Standard_False; | |
565 | } | |
566 | ||
567 | return ( ((Display* )myDisplay == glXGetCurrentDisplay()) | |
568 | && ((GLXContext )myGContext == glXGetCurrentContext()) | |
569 | && ((GLXDrawable )myWindow == glXGetCurrentDrawable())); | |
570 | #endif | |
571 | } | |
572 | ||
2bd4c032 | 573 | // ======================================================================= |
574 | // function : MakeCurrent | |
575 | // purpose : | |
576 | // ======================================================================= | |
577 | Standard_Boolean OpenGl_Context::MakeCurrent() | |
578 | { | |
da8bb41d | 579 | #if defined(HAVE_EGL) |
580 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
581 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
582 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
583 | { | |
584 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
585 | return Standard_False; | |
586 | } | |
587 | ||
588 | if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE) | |
589 | { | |
590 | // if there is no current context it might be impossible to use glGetError() correctly | |
3b523c4c | 591 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, |
da8bb41d | 592 | "eglMakeCurrent() has failed!"); |
593 | myIsInitialized = Standard_False; | |
594 | return Standard_False; | |
595 | } | |
596 | #elif defined(_WIN32) | |
86fa64d9 | 597 | if (myWindowDC == NULL || myGContext == NULL) |
2bd4c032 | 598 | { |
86fa64d9 | 599 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); |
600 | return Standard_False; | |
601 | } | |
602 | ||
603 | // technically it should be safe to activate already bound GL context | |
604 | // however some drivers (Intel etc.) may FAIL doing this for unknown reason | |
605 | if (IsCurrent()) | |
606 | { | |
392ac980 | 607 | myShaderManager->SetContext (this); |
86fa64d9 | 608 | return Standard_True; |
609 | } | |
610 | else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE) | |
611 | { | |
612 | // notice that glGetError() couldn't be used here! | |
613 | wchar_t* aMsgBuff = NULL; | |
614 | DWORD anErrorCode = GetLastError(); | |
615 | FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
616 | NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL); | |
cbf18624 | 617 | TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. "); |
86fa64d9 | 618 | if (aMsgBuff != NULL) |
619 | { | |
cbf18624 | 620 | aMsg += (Standard_ExtString )aMsgBuff; |
86fa64d9 | 621 | LocalFree (aMsgBuff); |
622 | } | |
3b523c4c | 623 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH, aMsg); |
fd4a6963 | 624 | myIsInitialized = Standard_False; |
2bd4c032 | 625 | return Standard_False; |
626 | } | |
627 | #else | |
86fa64d9 | 628 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) |
629 | { | |
630 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
631 | return Standard_False; | |
632 | } | |
633 | ||
634 | if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext)) | |
2bd4c032 | 635 | { |
636 | // if there is no current context it might be impossible to use glGetError() correctly | |
3b523c4c | 637 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, |
cbf18624 | 638 | "glXMakeCurrent() has failed!"); |
fd4a6963 | 639 | myIsInitialized = Standard_False; |
2bd4c032 | 640 | return Standard_False; |
641 | } | |
642 | #endif | |
392ac980 | 643 | myShaderManager->SetContext (this); |
2bd4c032 | 644 | return Standard_True; |
645 | } | |
646 | ||
5e27df78 | 647 | // ======================================================================= |
648 | // function : SwapBuffers | |
649 | // purpose : | |
650 | // ======================================================================= | |
651 | void OpenGl_Context::SwapBuffers() | |
652 | { | |
da8bb41d | 653 | #if defined(HAVE_EGL) |
654 | if ((EGLSurface )myWindow != EGL_NO_SURFACE) | |
655 | { | |
656 | eglSwapBuffers ((EGLDisplay )myDisplay, (EGLSurface )myWindow); | |
657 | } | |
658 | #elif defined(_WIN32) | |
5e27df78 | 659 | if ((HDC )myWindowDC != NULL) |
660 | { | |
661 | ::SwapBuffers ((HDC )myWindowDC); | |
662 | glFlush(); | |
663 | } | |
664 | #else | |
665 | if ((Display* )myDisplay != NULL) | |
666 | { | |
667 | glXSwapBuffers ((Display* )myDisplay, (GLXDrawable )myWindow); | |
668 | } | |
669 | #endif | |
670 | } | |
671 | ||
4fe56619 | 672 | #endif // __APPLE__ |
673 | ||
f978241f | 674 | // ======================================================================= |
675 | // function : SetSwapInterval | |
676 | // purpose : | |
677 | // ======================================================================= | |
678 | Standard_Boolean OpenGl_Context::SetSwapInterval (const Standard_Integer theInterval) | |
679 | { | |
680 | #if defined(HAVE_EGL) | |
681 | if (::eglSwapInterval ((EGLDisplay )myDisplay, theInterval) == EGL_TRUE) | |
682 | { | |
683 | return Standard_True; | |
684 | } | |
685 | #elif defined(_WIN32) | |
686 | if (myFuncs->wglSwapIntervalEXT != NULL) | |
687 | { | |
688 | myFuncs->wglSwapIntervalEXT (theInterval); | |
689 | return Standard_True; | |
690 | } | |
691 | #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
692 | // | |
693 | #elif defined(__APPLE__) | |
694 | if (::CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &theInterval) == kCGLNoError) | |
695 | { | |
696 | return Standard_True; | |
697 | } | |
698 | #else | |
699 | if (theInterval == -1 | |
700 | && myFuncs->glXSwapIntervalEXT != NULL) | |
701 | { | |
702 | typedef int (*glXSwapIntervalEXT_t_x)(Display* theDisplay, GLXDrawable theDrawable, int theInterval); | |
703 | glXSwapIntervalEXT_t_x aFuncPtr = (glXSwapIntervalEXT_t_x )myFuncs->glXSwapIntervalEXT; | |
704 | aFuncPtr ((Display* )myDisplay, (GLXDrawable )myWindow, theInterval); | |
705 | return Standard_True; | |
706 | } | |
707 | else if (myFuncs->glXSwapIntervalSGI != NULL) | |
708 | { | |
709 | myFuncs->glXSwapIntervalSGI (theInterval); | |
710 | return Standard_True; | |
711 | } | |
712 | #endif | |
713 | return Standard_False; | |
714 | } | |
715 | ||
5f8b738e | 716 | // ======================================================================= |
717 | // function : findProc | |
718 | // purpose : | |
719 | // ======================================================================= | |
720 | void* OpenGl_Context::findProc (const char* theFuncName) | |
721 | { | |
da8bb41d | 722 | #if defined(HAVE_EGL) |
723 | return (void* )eglGetProcAddress (theFuncName); | |
724 | #elif defined(_WIN32) | |
7c65581d | 725 | return (void* )wglGetProcAddress (theFuncName); |
5f8b738e | 726 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
727 | return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL; | |
728 | #else | |
729 | return (void* )glXGetProcAddress ((const GLubyte* )theFuncName); | |
730 | #endif | |
2166f0fa SK |
731 | } |
732 | ||
733 | // ======================================================================= | |
734 | // function : CheckExtension | |
735 | // purpose : | |
736 | // ======================================================================= | |
2bd4c032 | 737 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const |
2166f0fa | 738 | { |
5f8b738e | 739 | if (theExtName == NULL) |
740 | { | |
0797d9d3 | 741 | #ifdef OCCT_DEBUG |
5f8b738e | 742 | std::cerr << "CheckExtension called with NULL string!\n"; |
63c629aa | 743 | #endif |
5f8b738e | 744 | return Standard_False; |
745 | } | |
5f8b738e | 746 | |
4e1523ef | 747 | #if !defined(GL_ES_VERSION_2_0) |
5f8b738e | 748 | // available since OpenGL 3.0 |
749 | // and the ONLY way to check extensions with OpenGL 3.1+ core profile | |
4e1523ef | 750 | if (IsGlGreaterEqual (3, 0) |
751 | && myFuncs->glGetStringi != NULL) | |
5f8b738e | 752 | { |
753 | GLint anExtNb = 0; | |
4e1523ef | 754 | ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb); |
755 | const size_t anExtNameLen = strlen (theExtName); | |
5f8b738e | 756 | for (GLint anIter = 0; anIter < anExtNb; ++anIter) |
757 | { | |
4e1523ef | 758 | const char* anExtension = (const char* )myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint )anIter); |
759 | const size_t aTestExtNameLen = strlen (anExtension); | |
760 | if (aTestExtNameLen == anExtNameLen | |
761 | && strncmp (anExtension, theExtName, anExtNameLen) == 0) | |
5f8b738e | 762 | { |
763 | return Standard_True; | |
764 | } | |
765 | } | |
766 | return Standard_False; | |
4e1523ef | 767 | } |
768 | #endif | |
5f8b738e | 769 | |
770 | // use old way with huge string for all extensions | |
771 | const char* anExtString = (const char* )glGetString (GL_EXTENSIONS); | |
772 | if (anExtString == NULL) | |
773 | { | |
7e7c2f0b | 774 | Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning); |
2166f0fa SK |
775 | return Standard_False; |
776 | } | |
58655684 | 777 | return CheckExtension (anExtString, theExtName); |
778 | } | |
779 | ||
780 | // ======================================================================= | |
781 | // function : CheckExtension | |
782 | // purpose : | |
783 | // ======================================================================= | |
784 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtString, | |
785 | const char* theExtName) | |
786 | { | |
787 | if (theExtString == NULL) | |
788 | { | |
789 | return Standard_False; | |
790 | } | |
2166f0fa SK |
791 | |
792 | // Search for theExtName in the extensions string. | |
793 | // Use of strstr() is not sufficient because extension names can be prefixes of other extension names. | |
58655684 | 794 | char* aPtrIter = (char* )theExtString; |
795 | const char* aPtrEnd = aPtrIter + strlen (theExtString); | |
796 | const size_t anExtNameLen = strlen (theExtName); | |
2166f0fa SK |
797 | while (aPtrIter < aPtrEnd) |
798 | { | |
6a7d83c4 | 799 | const size_t n = strcspn (aPtrIter, " "); |
5f8b738e | 800 | if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0)) |
801 | { | |
2166f0fa | 802 | return Standard_True; |
5f8b738e | 803 | } |
2166f0fa SK |
804 | aPtrIter += (n + 1); |
805 | } | |
806 | return Standard_False; | |
807 | } | |
808 | ||
4fe56619 | 809 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
810 | ||
2166f0fa SK |
811 | // ======================================================================= |
812 | // function : Init | |
813 | // purpose : | |
814 | // ======================================================================= | |
4e1523ef | 815 | Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile) |
2166f0fa | 816 | { |
2bd4c032 | 817 | if (myIsInitialized) |
5f8b738e | 818 | { |
f0430952 | 819 | return Standard_True; |
5f8b738e | 820 | } |
2bd4c032 | 821 | |
da8bb41d | 822 | #if defined(HAVE_EGL) |
823 | myDisplay = (Aspect_Display )eglGetCurrentDisplay(); | |
824 | myGContext = (Aspect_RenderingContext )eglGetCurrentContext(); | |
825 | myWindow = (Aspect_Drawable )eglGetCurrentSurface(EGL_DRAW); | |
826 | #elif defined(_WIN32) | |
2bd4c032 | 827 | myWindowDC = (Aspect_Handle )wglGetCurrentDC(); |
828 | myGContext = (Aspect_RenderingContext )wglGetCurrentContext(); | |
829 | #else | |
830 | myDisplay = (Aspect_Display )glXGetCurrentDisplay(); | |
831 | myGContext = (Aspect_RenderingContext )glXGetCurrentContext(); | |
832 | myWindow = (Aspect_Drawable )glXGetCurrentDrawable(); | |
833 | #endif | |
f0430952 | 834 | if (myGContext == NULL) |
835 | { | |
836 | return Standard_False; | |
837 | } | |
2bd4c032 | 838 | |
4e1523ef | 839 | init (theIsCoreProfile); |
2bd4c032 | 840 | myIsInitialized = Standard_True; |
f0430952 | 841 | return Standard_True; |
2bd4c032 | 842 | } |
843 | ||
4fe56619 | 844 | #endif // __APPLE__ |
845 | ||
2bd4c032 | 846 | // ======================================================================= |
847 | // function : Init | |
848 | // purpose : | |
849 | // ======================================================================= | |
da8bb41d | 850 | #if defined(HAVE_EGL) |
851 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theEglSurface, | |
852 | const Aspect_Display theEglDisplay, | |
4e1523ef | 853 | const Aspect_RenderingContext theEglContext, |
854 | const Standard_Boolean theIsCoreProfile) | |
da8bb41d | 855 | #elif defined(_WIN32) |
f0430952 | 856 | Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow, |
857 | const Aspect_Handle theWindowDC, | |
4e1523ef | 858 | const Aspect_RenderingContext theGContext, |
859 | const Standard_Boolean theIsCoreProfile) | |
4fe56619 | 860 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 861 | |
862 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
863 | Standard_Boolean OpenGl_Context::Init (EAGLContext* theGContext, | |
4e1523ef | 864 | const Standard_Boolean theIsCoreProfile) |
a2e4f780 | 865 | #else |
866 | Standard_Boolean OpenGl_Context::Init (NSOpenGLContext* theGContext, | |
867 | const Standard_Boolean theIsCoreProfile) | |
868 | #endif | |
869 | ||
2bd4c032 | 870 | #else |
f0430952 | 871 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow, |
872 | const Aspect_Display theDisplay, | |
4e1523ef | 873 | const Aspect_RenderingContext theGContext, |
874 | const Standard_Boolean theIsCoreProfile) | |
2bd4c032 | 875 | #endif |
876 | { | |
877 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!"); | |
da8bb41d | 878 | #if defined(HAVE_EGL) |
879 | myWindow = theEglSurface; | |
880 | myGContext = theEglContext; | |
881 | myDisplay = theEglDisplay; | |
882 | #elif defined(_WIN32) | |
2bd4c032 | 883 | myWindow = theWindow; |
884 | myGContext = theGContext; | |
2bd4c032 | 885 | myWindowDC = theWindowDC; |
4fe56619 | 886 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 887 | myGContext = theGContext; |
2bd4c032 | 888 | #else |
4fe56619 | 889 | myWindow = theWindow; |
890 | myGContext = theGContext; | |
2bd4c032 | 891 | myDisplay = theDisplay; |
892 | #endif | |
86fa64d9 | 893 | if (myGContext == NULL || !MakeCurrent()) |
f0430952 | 894 | { |
895 | return Standard_False; | |
896 | } | |
2bd4c032 | 897 | |
4e1523ef | 898 | init (theIsCoreProfile); |
2bd4c032 | 899 | myIsInitialized = Standard_True; |
f0430952 | 900 | return Standard_True; |
5f8b738e | 901 | } |
902 | ||
903 | // ======================================================================= | |
904 | // function : ResetErrors | |
905 | // purpose : | |
906 | // ======================================================================= | |
f9f740d6 | 907 | bool OpenGl_Context::ResetErrors (const bool theToPrintErrors) |
5f8b738e | 908 | { |
3c4b62a4 | 909 | int aPrevErr = 0; |
910 | int anErr = ::glGetError(); | |
f9f740d6 | 911 | const bool hasError = anErr != GL_NO_ERROR; |
3c4b62a4 | 912 | if (!theToPrintErrors) |
5f8b738e | 913 | { |
3c4b62a4 | 914 | for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError()) |
915 | { | |
916 | // | |
917 | } | |
f9f740d6 | 918 | return hasError; |
3c4b62a4 | 919 | } |
920 | ||
921 | for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError()) | |
922 | { | |
923 | TCollection_ExtendedString anErrId; | |
924 | switch (anErr) | |
925 | { | |
926 | case GL_INVALID_ENUM: anErrId = "GL_INVALID_ENUM"; break; | |
927 | case GL_INVALID_VALUE: anErrId = "GL_INVALID_VALUE"; break; | |
928 | case GL_INVALID_OPERATION: anErrId = "GL_INVALID_OPERATION"; break; | |
929 | #ifdef GL_STACK_OVERFLOW | |
930 | case GL_STACK_OVERFLOW: anErrId = "GL_STACK_OVERFLOW"; break; | |
931 | case GL_STACK_UNDERFLOW: anErrId = "GL_STACK_UNDERFLOW"; break; | |
932 | #endif | |
933 | case GL_OUT_OF_MEMORY: anErrId = "GL_OUT_OF_MEMORY"; break; | |
934 | case GL_INVALID_FRAMEBUFFER_OPERATION: | |
935 | anErrId = "GL_INVALID_FRAMEBUFFER_OPERATION"; | |
936 | break; | |
937 | default: | |
938 | anErrId = TCollection_ExtendedString("#") + anErr; | |
939 | break; | |
940 | } | |
941 | ||
942 | const TCollection_ExtendedString aMsg = TCollection_ExtendedString ("Unhandled GL error: ") + anErrId; | |
82f443b6 | 943 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_OTHER, 0, GL_DEBUG_SEVERITY_LOW, aMsg); |
5f8b738e | 944 | } |
f9f740d6 | 945 | return hasError; |
5f8b738e | 946 | } |
947 | ||
948 | // ======================================================================= | |
4e1523ef | 949 | // function : ReadGlVersion |
5f8b738e | 950 | // purpose : |
951 | // ======================================================================= | |
4e1523ef | 952 | void OpenGl_Context::ReadGlVersion (Standard_Integer& theGlVerMajor, |
953 | Standard_Integer& theGlVerMinor) | |
5f8b738e | 954 | { |
955 | // reset values | |
4e1523ef | 956 | theGlVerMajor = 0; |
957 | theGlVerMinor = 0; | |
5f8b738e | 958 | |
ca3c13d1 | 959 | #ifdef GL_MAJOR_VERSION |
960 | // available since OpenGL 3.0 and OpenGL 3.0 ES | |
86325709 | 961 | GLint aMajor = 0, aMinor = 0; |
5f8b738e | 962 | glGetIntegerv (GL_MAJOR_VERSION, &aMajor); |
963 | glGetIntegerv (GL_MINOR_VERSION, &aMinor); | |
30f0ad28 | 964 | // glGetError() sometimes does not report an error here even if |
86325709 | 965 | // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants. |
ca3c13d1 | 966 | // This happens on some renderers like e.g. Cygwin MESA. |
86325709 | 967 | // Thus checking additionally if GL has put anything to |
968 | // the output variables. | |
4e1523ef | 969 | if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0) |
5f8b738e | 970 | { |
4e1523ef | 971 | theGlVerMajor = aMajor; |
972 | theGlVerMinor = aMinor; | |
5f8b738e | 973 | return; |
974 | } | |
4e1523ef | 975 | for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError()) |
976 | { | |
977 | if (anErr == GL_NO_ERROR | |
978 | || anErr == aPrevErr) | |
979 | { | |
980 | break; | |
981 | } | |
982 | } | |
ca3c13d1 | 983 | #endif |
5f8b738e | 984 | |
985 | // Read version string. | |
ca3c13d1 | 986 | // Notice that only first two numbers split by point '2.1 XXXXX' are significant. |
5f8b738e | 987 | // Following trash (after space) is vendor-specific. |
988 | // New drivers also returns micro version of GL like '3.3.0' which has no meaning | |
989 | // and should be considered as vendor-specific too. | |
990 | const char* aVerStr = (const char* )glGetString (GL_VERSION); | |
991 | if (aVerStr == NULL || *aVerStr == '\0') | |
992 | { | |
993 | // invalid GL context | |
994 | return; | |
995 | } | |
996 | ||
ca3c13d1 | 997 | //#if defined(GL_ES_VERSION_2_0) |
998 | // skip "OpenGL ES-** " section | |
999 | for (; *aVerStr != '\0'; ++aVerStr) | |
1000 | { | |
1001 | if (*aVerStr >= '0' && *aVerStr <= '9') | |
1002 | { | |
1003 | break; | |
1004 | } | |
1005 | } | |
1006 | //#endif | |
1007 | ||
5f8b738e | 1008 | // parse string for major number |
1009 | char aMajorStr[32]; | |
1010 | char aMinorStr[32]; | |
1011 | size_t aMajIter = 0; | |
1012 | while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9') | |
1013 | { | |
1014 | ++aMajIter; | |
1015 | } | |
1016 | if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr)) | |
1017 | { | |
1018 | return; | |
1019 | } | |
1020 | memcpy (aMajorStr, aVerStr, aMajIter); | |
1021 | aMajorStr[aMajIter] = '\0'; | |
1022 | ||
1023 | // parse string for minor number | |
86325709 | 1024 | aVerStr += aMajIter + 1; |
1025 | size_t aMinIter = 0; | |
5f8b738e | 1026 | while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9') |
1027 | { | |
1028 | ++aMinIter; | |
1029 | } | |
86325709 | 1030 | if (aMinIter == 0 || aMinIter >= sizeof(aMinorStr)) |
5f8b738e | 1031 | { |
1032 | return; | |
1033 | } | |
86325709 | 1034 | memcpy (aMinorStr, aVerStr, aMinIter); |
1035 | aMinorStr[aMinIter] = '\0'; | |
5f8b738e | 1036 | |
1037 | // read numbers | |
4e1523ef | 1038 | theGlVerMajor = atoi (aMajorStr); |
1039 | theGlVerMinor = atoi (aMinorStr); | |
5f8b738e | 1040 | |
4e1523ef | 1041 | if (theGlVerMajor <= 0) |
5f8b738e | 1042 | { |
4e1523ef | 1043 | theGlVerMajor = 0; |
1044 | theGlVerMinor = 0; | |
5f8b738e | 1045 | } |
1046 | } | |
1047 | ||
58655684 | 1048 | static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN"; |
1049 | static Standard_CString THE_DBGMSG_SOURCES[] = | |
1050 | { | |
3b523c4c | 1051 | ".OpenGL", // GL_DEBUG_SOURCE_API |
1052 | ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM | |
1053 | ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER | |
1054 | ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY | |
1055 | "", // GL_DEBUG_SOURCE_APPLICATION | |
1056 | ".Other" // GL_DEBUG_SOURCE_OTHER | |
58655684 | 1057 | }; |
1058 | ||
1059 | static Standard_CString THE_DBGMSG_TYPES[] = | |
1060 | { | |
3b523c4c | 1061 | "Error", // GL_DEBUG_TYPE_ERROR |
1062 | "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR | |
1063 | "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR | |
1064 | "Portability", // GL_DEBUG_TYPE_PORTABILITY | |
1065 | "Performance", // GL_DEBUG_TYPE_PERFORMANCE | |
1066 | "Other" // GL_DEBUG_TYPE_OTHER | |
58655684 | 1067 | }; |
1068 | ||
3b523c4c | 1069 | static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH |
1070 | static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM | |
1071 | static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW | |
58655684 | 1072 | |
cbf18624 | 1073 | //! Callback for GL_ARB_debug_output extension |
58655684 | 1074 | static void APIENTRY debugCallbackWrap(unsigned int theSource, |
1075 | unsigned int theType, | |
1076 | unsigned int theId, | |
1077 | unsigned int theSeverity, | |
1078 | int /*theLength*/, | |
1079 | const char* theMessage, | |
9293178b | 1080 | const void* theUserParam) |
cbf18624 | 1081 | { |
1082 | OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam; | |
1083 | aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage); | |
1084 | } | |
1085 | ||
1086 | // ======================================================================= | |
1087 | // function : PushMessage | |
1088 | // purpose : | |
1089 | // ======================================================================= | |
1090 | void OpenGl_Context::PushMessage (const unsigned int theSource, | |
1091 | const unsigned int theType, | |
1092 | const unsigned int theId, | |
1093 | const unsigned int theSeverity, | |
1094 | const TCollection_ExtendedString& theMessage) | |
58655684 | 1095 | { |
c87535af | 1096 | if (caps->suppressExtraMsg |
3b523c4c | 1097 | && theSource >= GL_DEBUG_SOURCE_API |
1098 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1099 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Contains (theId)) | |
c87535af | 1100 | { |
1101 | return; | |
1102 | } | |
1103 | ||
3b523c4c | 1104 | Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API |
1105 | && theSource <= GL_DEBUG_SOURCE_OTHER) | |
1106 | ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API] | |
58655684 | 1107 | : THE_DBGMSG_UNKNOWN; |
3b523c4c | 1108 | Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR |
1109 | && theType <= GL_DEBUG_TYPE_OTHER) | |
1110 | ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR] | |
58655684 | 1111 | : THE_DBGMSG_UNKNOWN; |
3b523c4c | 1112 | Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH |
58655684 | 1113 | ? THE_DBGMSG_SEV_HIGH |
3b523c4c | 1114 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM |
58655684 | 1115 | ? THE_DBGMSG_SEV_MEDIUM |
1116 | : THE_DBGMSG_SEV_LOW); | |
3b523c4c | 1117 | Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH |
cbf18624 | 1118 | ? Message_Alarm |
3b523c4c | 1119 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM |
cbf18624 | 1120 | ? Message_Warning |
1121 | : Message_Info); | |
1122 | ||
1123 | TCollection_ExtendedString aMsg; | |
1124 | aMsg += "TKOpenGl"; aMsg += aSrc; | |
1125 | aMsg += " | Type: "; aMsg += aType; | |
1126 | aMsg += " | ID: "; aMsg += (Standard_Integer )theId; | |
1127 | aMsg += " | Severity: "; aMsg += aSev; | |
1128 | aMsg += " | Message:\n "; | |
1129 | aMsg += theMessage; | |
7e7c2f0b | 1130 | Messenger()->Send (aMsg, aGrav); |
58655684 | 1131 | } |
1132 | ||
c87535af | 1133 | // ======================================================================= |
1134 | // function : ExcludeMessage | |
1135 | // purpose : | |
1136 | // ====================================================================== | |
1137 | Standard_Boolean OpenGl_Context::ExcludeMessage (const unsigned int theSource, | |
1138 | const unsigned int theId) | |
1139 | { | |
3b523c4c | 1140 | return theSource >= GL_DEBUG_SOURCE_API |
1141 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1142 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Add (theId); | |
c87535af | 1143 | } |
1144 | ||
1145 | // ======================================================================= | |
1146 | // function : IncludeMessage | |
1147 | // purpose : | |
1148 | // ====================================================================== | |
1149 | Standard_Boolean OpenGl_Context::IncludeMessage (const unsigned int theSource, | |
1150 | const unsigned int theId) | |
1151 | { | |
3b523c4c | 1152 | return theSource >= GL_DEBUG_SOURCE_API |
1153 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1154 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Remove (theId); | |
c87535af | 1155 | } |
1156 | ||
ee51a9fe | 1157 | // ======================================================================= |
1158 | // function : checkWrongVersion | |
1159 | // purpose : | |
1160 | // ====================================================================== | |
1161 | void OpenGl_Context::checkWrongVersion (const Standard_Integer theGlVerMajor, | |
1162 | const Standard_Integer theGlVerMinor) | |
1163 | { | |
1164 | if (!IsGlGreaterEqual (theGlVerMajor, theGlVerMinor)) | |
1165 | { | |
1166 | return; | |
1167 | } | |
1168 | ||
1169 | TCollection_ExtendedString aMsg = TCollection_ExtendedString() | |
1170 | + "Error! OpenGL context reports version " | |
1171 | + myGlVerMajor + "." + myGlVerMinor | |
1172 | + " but does not export required functions for " | |
1173 | + theGlVerMajor + "." + theGlVerMinor; | |
3b523c4c | 1174 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, |
1175 | GL_DEBUG_TYPE_ERROR, | |
ee51a9fe | 1176 | 0, |
3b523c4c | 1177 | GL_DEBUG_SEVERITY_HIGH, |
ee51a9fe | 1178 | aMsg); |
1179 | } | |
1180 | ||
5f8b738e | 1181 | // ======================================================================= |
1182 | // function : init | |
1183 | // purpose : | |
1184 | // ======================================================================= | |
4e1523ef | 1185 | void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) |
5f8b738e | 1186 | { |
1187 | // read version | |
4e1523ef | 1188 | myGlVerMajor = 0; |
1189 | myGlVerMinor = 0; | |
3c4b62a4 | 1190 | myMaxMsaaSamples = 0; |
a1073ae2 | 1191 | myMaxDrawBuffers = 1; |
1192 | myMaxColorAttachments = 1; | |
4e1523ef | 1193 | ReadGlVersion (myGlVerMajor, myGlVerMinor); |
c87535af | 1194 | myVendor = (const char* )::glGetString (GL_VENDOR); |
be375252 | 1195 | if (!caps->ffpEnable |
1196 | && !IsGlGreaterEqual (2, 0)) | |
1197 | { | |
1198 | caps->ffpEnable = true; | |
1199 | TCollection_ExtendedString aMsg = | |
1200 | TCollection_ExtendedString("OpenGL driver is too old! Context info:\n") | |
1201 | + " Vendor: " + (const char* )::glGetString (GL_VENDOR) + "\n" | |
1202 | + " Renderer: " + (const char* )::glGetString (GL_RENDERER) + "\n" | |
1203 | + " Version: " + (const char* )::glGetString (GL_VERSION) + "\n" | |
1204 | + " Fallback using deprecated fixed-function pipeline.\n" | |
1205 | + " Visualization might work incorrectly.\n" | |
1206 | " Consider upgrading the graphics driver."; | |
1207 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aMsg); | |
1208 | } | |
4e1523ef | 1209 | |
1210 | #if defined(GL_ES_VERSION_2_0) | |
1211 | (void )theIsCoreProfile; | |
1212 | const bool isCoreProfile = false; | |
1213 | #else | |
c87535af | 1214 | |
1215 | if (myVendor.Search ("NVIDIA") != -1) | |
1216 | { | |
1217 | // Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) | |
1218 | // will use VIDEO memory as the source for buffer object operations. | |
3b523c4c | 1219 | ExcludeMessage (GL_DEBUG_SOURCE_API, 131185); |
c87535af | 1220 | } |
4e1523ef | 1221 | if (IsGlGreaterEqual (3, 0)) |
1222 | { | |
1223 | // retrieve auxiliary function in advance | |
1224 | FindProc ("glGetStringi", myFuncs->glGetStringi); | |
1225 | } | |
1226 | ||
d4271fe5 | 1227 | bool isCoreProfile = false; |
4e1523ef | 1228 | if (IsGlGreaterEqual (3, 2)) |
1229 | { | |
d4271fe5 | 1230 | isCoreProfile = (theIsCoreProfile == Standard_True); |
4e1523ef | 1231 | |
d4271fe5 | 1232 | // detect Core profile |
c6ad5e5f | 1233 | if (!isCoreProfile) |
4e1523ef | 1234 | { |
d4271fe5 | 1235 | GLint aProfile = 0; |
1236 | ::glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &aProfile); | |
1237 | isCoreProfile = (aProfile & GL_CONTEXT_CORE_PROFILE_BIT) != 0; | |
4e1523ef | 1238 | } |
1239 | } | |
4e1523ef | 1240 | #endif |
1241 | ||
1242 | core11 = NULL; | |
1243 | if (!isCoreProfile) | |
1244 | { | |
1245 | core11 = (OpenGl_GlCore11* )(&(*myFuncs)); | |
1246 | } | |
01ca42b2 | 1247 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); |
1248 | core15 = NULL; | |
1249 | core15fwd = NULL; | |
1250 | core20 = NULL; | |
1251 | core20fwd = NULL; | |
1252 | core32 = NULL; | |
1253 | core32back = NULL; | |
25ef750e | 1254 | core33 = NULL; |
1255 | core33back = NULL; | |
01ca42b2 | 1256 | core41 = NULL; |
1257 | core41back = NULL; | |
1258 | core42 = NULL; | |
1259 | core42back = NULL; | |
1260 | core43 = NULL; | |
1261 | core43back = NULL; | |
1262 | core44 = NULL; | |
1263 | core44back = NULL; | |
1264 | arbTBO = NULL; | |
25ef750e | 1265 | arbTboRGB32 = Standard_False; |
01ca42b2 | 1266 | arbIns = NULL; |
1267 | arbDbg = NULL; | |
1268 | arbFBO = NULL; | |
b86bb3df | 1269 | arbFBOBlit = NULL; |
01ca42b2 | 1270 | extGS = NULL; |
4e1523ef | 1271 | myDefaultVao = 0; |
01ca42b2 | 1272 | |
cc8cbabe | 1273 | //! Make record shorter to retrieve function pointer using variable with same name |
1274 | #define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc) | |
1275 | ||
ca3c13d1 | 1276 | #if defined(GL_ES_VERSION_2_0) |
1277 | ||
1278 | hasTexRGBA8 = IsGlGreaterEqual (3, 0) | |
1279 | || CheckExtension ("GL_OES_rgb8_rgba8"); | |
05e2200b | 1280 | // NPOT textures has limited support within OpenGL ES 2.0 |
1281 | // which are relaxed by OpenGL ES 3.0 or some extensions | |
1282 | //arbNPTW = IsGlGreaterEqual (3, 0) | |
1283 | // || CheckExtension ("GL_OES_texture_npot") | |
1284 | // || CheckExtension ("GL_NV_texture_npot_2D_mipmap"); | |
1285 | arbNPTW = Standard_True; | |
ca3c13d1 | 1286 | arbTexRG = IsGlGreaterEqual (3, 0) |
1287 | || CheckExtension ("GL_EXT_texture_rg"); | |
1288 | extBgra = CheckExtension ("GL_EXT_texture_format_BGRA8888"); | |
1289 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
e473b95f | 1290 | extPDS = IsGlGreaterEqual (3, 0) |
1291 | || CheckExtension ("GL_OES_packed_depth_stencil"); | |
ca3c13d1 | 1292 | |
1293 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); | |
1294 | if (IsGlGreaterEqual (2, 0)) | |
1295 | { | |
1296 | // enable compatible functions | |
1297 | core20 = (OpenGl_GlCore20* )(&(*myFuncs)); | |
1298 | core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs)); | |
1299 | core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs)); | |
b86bb3df | 1300 | arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs)); |
1301 | } | |
1302 | if (IsGlGreaterEqual (3, 0) | |
cc8cbabe | 1303 | && FindProcShort (glBlitFramebuffer)) |
b86bb3df | 1304 | { |
1305 | arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs)); | |
ca3c13d1 | 1306 | } |
cc8cbabe | 1307 | if (IsGlGreaterEqual (3, 0) |
1308 | && FindProcShort (glGenSamplers) | |
1309 | && FindProcShort (glDeleteSamplers) | |
1310 | && FindProcShort (glIsSampler) | |
1311 | && FindProcShort (glBindSampler) | |
1312 | && FindProcShort (glSamplerParameteri) | |
1313 | && FindProcShort (glSamplerParameteriv) | |
1314 | && FindProcShort (glSamplerParameterf) | |
1315 | && FindProcShort (glSamplerParameterfv) | |
1316 | && FindProcShort (glGetSamplerParameteriv) | |
1317 | && FindProcShort (glGetSamplerParameterfv)) | |
1318 | //&& FindProcShort (glSamplerParameterIiv) // only on Desktop or with extensions GL_OES_texture_border_clamp/GL_EXT_texture_border_clamp | |
1319 | //&& FindProcShort (glSamplerParameterIuiv) | |
1320 | //&& FindProcShort (glGetSamplerParameterIiv) | |
1321 | //&& FindProcShort (glGetSamplerParameterIuiv)) | |
1322 | { | |
1323 | arbSamplerObject = (OpenGl_ArbSamplerObject* )(&(*myFuncs)); | |
1324 | } | |
1ce0716b | 1325 | extFragDepth = !IsGlGreaterEqual(3, 0) |
1326 | && CheckExtension ("GL_EXT_frag_depth"); | |
3c4b62a4 | 1327 | if (IsGlGreaterEqual (3, 1) |
1328 | && FindProc ("glTexStorage2DMultisample", myFuncs->glTexStorage2DMultisample)) | |
1329 | { | |
1330 | // MSAA RenderBuffers have been defined in OpenGL ES 3.0, | |
1331 | // but MSAA Textures - only in OpenGL ES 3.1+ | |
1332 | ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples); | |
1333 | } | |
ca3c13d1 | 1334 | |
e99a2f7c | 1335 | hasUintIndex = IsGlGreaterEqual (3, 0) |
1336 | || CheckExtension ("GL_OES_element_index_uint"); | |
1337 | hasHighp = CheckExtension ("GL_OES_fragment_precision_high"); | |
ca3c13d1 | 1338 | GLint aRange[2] = {0, 0}; |
447c4115 | 1339 | GLint aPrec = 0; |
1340 | ::glGetShaderPrecisionFormat (GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, aRange, &aPrec); | |
1341 | if (aPrec != 0) | |
ca3c13d1 | 1342 | { |
1343 | hasHighp = Standard_True; | |
1344 | } | |
74fb257d | 1345 | |
1346 | arbTexFloat = IsGlGreaterEqual (3, 0) | |
1347 | && FindProc ("glTexImage3D", myFuncs->glTexImage3D); | |
20aeeb7b | 1348 | |
1349 | const Standard_Boolean hasTexBuffer32 = IsGlGreaterEqual (3, 2) && FindProc ("glTexBuffer", myFuncs->glTexBuffer); | |
1350 | const Standard_Boolean hasExtTexBuffer = CheckExtension ("GL_EXT_texture_buffer") && FindProc ("glTexBufferEXT", myFuncs->glTexBuffer); | |
1351 | ||
1352 | if (hasTexBuffer32 || hasExtTexBuffer) | |
1353 | { | |
1354 | arbTBO = reinterpret_cast<OpenGl_ArbTBO*> (myFuncs.get()); | |
1355 | } | |
0deb6f04 | 1356 | |
1357 | // initialize debug context extension | |
1358 | if (CheckExtension ("GL_KHR_debug")) | |
1359 | { | |
1360 | // this functionality become a part of OpenGL ES 3.2 | |
1361 | arbDbg = NULL; | |
1362 | // According to GL_KHR_debug spec, all functions should have KHR suffix. | |
1363 | // However, some implementations can export these functions without suffix. | |
1364 | if (FindProc ("glDebugMessageControlKHR", myFuncs->glDebugMessageControl) | |
1365 | && FindProc ("glDebugMessageInsertKHR", myFuncs->glDebugMessageInsert) | |
1366 | && FindProc ("glDebugMessageCallbackKHR", myFuncs->glDebugMessageCallback) | |
1367 | && FindProc ("glGetDebugMessageLogKHR", myFuncs->glGetDebugMessageLog)) | |
1368 | { | |
1369 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); | |
1370 | } | |
1371 | ||
1372 | if (arbDbg != NULL | |
1373 | && caps->contextDebug) | |
1374 | { | |
1375 | // setup default callback | |
1376 | myIsGlDebugCtx = Standard_True; | |
1377 | arbDbg->glDebugMessageCallback (debugCallbackWrap, this); | |
1378 | ::glEnable (GL_DEBUG_OUTPUT); | |
1379 | if (caps->contextSyncDebug) | |
1380 | { | |
1381 | // note that some broken implementations (e.g. simulators) might generate error message on this call | |
1382 | ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS); | |
1383 | } | |
1384 | } | |
1385 | } | |
1386 | ||
a1073ae2 | 1387 | extDrawBuffers = CheckExtension ("GL_EXT_draw_buffers") && FindProc ("glDrawBuffersEXT", myFuncs->glDrawBuffers); |
1388 | arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers") && FindProc ("glDrawBuffersARB", myFuncs->glDrawBuffers); | |
1389 | ||
1390 | if (IsGlGreaterEqual (3, 0) && FindProc ("glDrawBuffers", myFuncs->glDrawBuffers)) | |
1391 | { | |
1392 | hasDrawBuffers = OpenGl_FeatureInCore; | |
1393 | } | |
1394 | else if (extDrawBuffers || arbDrawBuffers) | |
1395 | { | |
1396 | hasDrawBuffers = OpenGl_FeatureInExtensions; | |
1397 | } | |
1398 | ||
1399 | hasFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore : | |
1400 | CheckExtension ("GL_EXT_color_buffer_float") ? OpenGl_FeatureInExtensions | |
1401 | : OpenGl_FeatureNotAvailable; | |
1402 | hasHalfFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore : | |
1403 | CheckExtension ("GL_EXT_color_buffer_half_float") ? OpenGl_FeatureInExtensions | |
1404 | : OpenGl_FeatureNotAvailable; | |
1405 | ||
1406 | oesSampleVariables = CheckExtension ("GL_OES_sample_variables"); | |
8c3237d4 | 1407 | oesStdDerivatives = CheckExtension ("GL_OES_standard_derivatives"); |
a1073ae2 | 1408 | hasSampleVariables = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore : |
1409 | oesSampleVariables ? OpenGl_FeatureInExtensions | |
1410 | : OpenGl_FeatureNotAvailable; | |
c39bb31b | 1411 | // without hasHighp, dFdx/dFdy precision is considered too low for flat shading (visual artifacts) |
1412 | hasFlatShading = IsGlGreaterEqual (3, 0) | |
1413 | ? OpenGl_FeatureInCore | |
1414 | : (oesStdDerivatives && hasHighp | |
1415 | ? OpenGl_FeatureInExtensions | |
1416 | : OpenGl_FeatureNotAvailable); | |
1417 | if (!IsGlGreaterEqual (3, 1) | |
1418 | && myVendor.Search("Qualcomm") != -1) | |
1419 | { | |
1420 | // dFdx/dFdy are completely broken on tested Adreno devices with versions below OpenGl ES 3.1 | |
1421 | hasFlatShading = OpenGl_FeatureNotAvailable; | |
1422 | } | |
ca3c13d1 | 1423 | #else |
1424 | ||
1425 | myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP; | |
1426 | ||
1427 | hasTexRGBA8 = Standard_True; | |
a1073ae2 | 1428 | arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers"); |
1429 | arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two"); | |
1430 | arbTexFloat = IsGlGreaterEqual (3, 0) | |
1431 | || CheckExtension ("GL_ARB_texture_float"); | |
1432 | arbSampleShading = CheckExtension ("GL_ARB_sample_shading"); | |
1433 | extBgra = CheckExtension ("GL_EXT_bgra"); | |
1434 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
1435 | extPDS = CheckExtension ("GL_EXT_packed_depth_stencil"); | |
1436 | atiMem = CheckExtension ("GL_ATI_meminfo"); | |
1437 | nvxMem = CheckExtension ("GL_NVX_gpu_memory_info"); | |
1438 | ||
1439 | hasDrawBuffers = IsGlGreaterEqual (2, 0) ? OpenGl_FeatureInCore : | |
1440 | arbDrawBuffers ? OpenGl_FeatureInExtensions | |
1441 | : OpenGl_FeatureNotAvailable; | |
1442 | ||
1443 | hasFloatBuffer = hasHalfFloatBuffer = IsGlGreaterEqual (3, 0) ? OpenGl_FeatureInCore : | |
1444 | CheckExtension ("GL_ARB_color_buffer_float") ? OpenGl_FeatureInExtensions | |
1445 | : OpenGl_FeatureNotAvailable; | |
1446 | ||
1447 | hasSampleVariables = IsGlGreaterEqual (4, 0) ? OpenGl_FeatureInCore : | |
1448 | arbSampleShading ? OpenGl_FeatureInExtensions | |
1449 | : OpenGl_FeatureNotAvailable; | |
bf75be98 | 1450 | |
ca3c13d1 | 1451 | GLint aStereo = GL_FALSE; |
b5ac8292 | 1452 | glGetIntegerv (GL_STEREO, &aStereo); |
1453 | myIsStereoBuffers = aStereo == 1; | |
1454 | ||
ca3c13d1 | 1455 | // get number of maximum clipping planes |
1456 | glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes); | |
1457 | #endif | |
1458 | ||
a1073ae2 | 1459 | if (hasDrawBuffers) |
1460 | { | |
1461 | glGetIntegerv (GL_MAX_DRAW_BUFFERS, &myMaxDrawBuffers); | |
1462 | glGetIntegerv (GL_MAX_COLOR_ATTACHMENTS, &myMaxColorAttachments); | |
c3487460 | 1463 | if (myDrawBuffers.Length() < myMaxDrawBuffers) |
1464 | { | |
1465 | myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false); | |
1466 | } | |
a1073ae2 | 1467 | } |
1468 | ||
ca3c13d1 | 1469 | glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim); |
cc8cbabe | 1470 | if (IsGlGreaterEqual (1, 5)) |
1471 | { | |
1472 | glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &myMaxTexCombined); | |
1473 | } | |
ca3c13d1 | 1474 | |
bf75be98 | 1475 | if (extAnis) |
1476 | { | |
1477 | glGetIntegerv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &myAnisoMax); | |
1478 | } | |
f0430952 | 1479 | |
25c35042 | 1480 | myClippingState.Init(); |
4269bd1b | 1481 | |
ca3c13d1 | 1482 | #if !defined(GL_ES_VERSION_2_0) |
1483 | ||
01ca42b2 | 1484 | bool has12 = false; |
1485 | bool has13 = false; | |
1486 | bool has14 = false; | |
1487 | bool has15 = false; | |
1488 | bool has20 = false; | |
1489 | bool has21 = false; | |
1490 | bool has30 = false; | |
1491 | bool has31 = false; | |
1492 | bool has32 = false; | |
1493 | bool has33 = false; | |
1494 | bool has40 = false; | |
1495 | bool has41 = false; | |
1496 | bool has42 = false; | |
1497 | bool has43 = false; | |
1498 | bool has44 = false; | |
1499 | ||
4e1523ef | 1500 | // retrieve platform-dependent extensions |
f978241f | 1501 | #if defined(HAVE_EGL) |
1502 | // | |
1503 | #elif defined(_WIN32) | |
01ca42b2 | 1504 | if (FindProcShort (wglGetExtensionsStringARB)) |
1505 | { | |
1506 | const char* aWglExts = myFuncs->wglGetExtensionsStringARB (wglGetCurrentDC()); | |
1507 | if (CheckExtension (aWglExts, "WGL_EXT_swap_control")) | |
1508 | { | |
1509 | FindProcShort (wglSwapIntervalEXT); | |
1510 | } | |
1511 | if (CheckExtension (aWglExts, "WGL_ARB_pixel_format")) | |
1512 | { | |
1513 | FindProcShort (wglChoosePixelFormatARB); | |
1514 | } | |
1515 | if (CheckExtension (aWglExts, "WGL_ARB_create_context_profile")) | |
1516 | { | |
1517 | FindProcShort (wglCreateContextAttribsARB); | |
1518 | } | |
1519 | if (CheckExtension (aWglExts, "WGL_NV_DX_interop")) | |
1520 | { | |
1521 | FindProcShort (wglDXSetResourceShareHandleNV); | |
1522 | FindProcShort (wglDXOpenDeviceNV); | |
1523 | FindProcShort (wglDXCloseDeviceNV); | |
1524 | FindProcShort (wglDXRegisterObjectNV); | |
1525 | FindProcShort (wglDXUnregisterObjectNV); | |
1526 | FindProcShort (wglDXObjectAccessNV); | |
1527 | FindProcShort (wglDXLockObjectsNV); | |
1528 | FindProcShort (wglDXUnlockObjectsNV); | |
1529 | } | |
2eacd0b8 | 1530 | if (CheckExtension (aWglExts, "WGL_AMD_gpu_association")) |
1531 | { | |
1532 | FindProcShort (wglGetGPUIDsAMD); | |
1533 | FindProcShort (wglGetGPUInfoAMD); | |
1534 | FindProcShort (wglGetContextGPUIDAMD); | |
1535 | } | |
01ca42b2 | 1536 | } |
f978241f | 1537 | #elif defined(__APPLE__) |
1538 | // | |
1539 | #else | |
1540 | const char* aGlxExts = ::glXQueryExtensionsString ((Display* )myDisplay, DefaultScreen ((Display* )myDisplay)); | |
1541 | if (CheckExtension (aGlxExts, "GLX_EXT_swap_control")) | |
1542 | { | |
1543 | FindProcShort (glXSwapIntervalEXT); | |
1544 | } | |
1545 | if (CheckExtension (aGlxExts, "GLX_SGI_swap_control")) | |
1546 | { | |
1547 | FindProcShort (glXSwapIntervalSGI); | |
1548 | } | |
26d9c835 | 1549 | if (CheckExtension (aGlxExts, "GLX_MESA_query_renderer")) |
1550 | { | |
1551 | FindProcShort (glXQueryRendererIntegerMESA); | |
1552 | FindProcShort (glXQueryCurrentRendererIntegerMESA); | |
1553 | FindProcShort (glXQueryRendererStringMESA); | |
1554 | FindProcShort (glXQueryCurrentRendererStringMESA); | |
1555 | } | |
f978241f | 1556 | //extSwapTear = CheckExtension (aGlxExts, "GLX_EXT_swap_control_tear"); |
01ca42b2 | 1557 | #endif |
1558 | ||
01ca42b2 | 1559 | // load OpenGL 1.2 new functions |
1560 | has12 = IsGlGreaterEqual (1, 2) | |
1561 | && FindProcShort (glBlendColor) | |
1562 | && FindProcShort (glBlendEquation) | |
1563 | && FindProcShort (glDrawRangeElements) | |
1564 | && FindProcShort (glTexImage3D) | |
1565 | && FindProcShort (glTexSubImage3D) | |
1566 | && FindProcShort (glCopyTexSubImage3D); | |
1567 | ||
1568 | // load OpenGL 1.3 new functions | |
1569 | has13 = IsGlGreaterEqual (1, 3) | |
1570 | && FindProcShort (glActiveTexture) | |
1571 | && FindProcShort (glSampleCoverage) | |
1572 | && FindProcShort (glCompressedTexImage3D) | |
1573 | && FindProcShort (glCompressedTexImage2D) | |
1574 | && FindProcShort (glCompressedTexImage1D) | |
1575 | && FindProcShort (glCompressedTexSubImage3D) | |
1576 | && FindProcShort (glCompressedTexSubImage2D) | |
1577 | && FindProcShort (glCompressedTexSubImage1D) | |
4e1523ef | 1578 | && FindProcShort (glGetCompressedTexImage); |
1579 | ||
1580 | if (!isCoreProfile) | |
1581 | { | |
1582 | has13 = has13 | |
01ca42b2 | 1583 | && FindProcShort (glClientActiveTexture) |
1584 | && FindProcShort (glMultiTexCoord1d) | |
1585 | && FindProcShort (glMultiTexCoord1dv) | |
1586 | && FindProcShort (glMultiTexCoord1f) | |
1587 | && FindProcShort (glMultiTexCoord1fv) | |
1588 | && FindProcShort (glMultiTexCoord1i) | |
1589 | && FindProcShort (glMultiTexCoord1iv) | |
1590 | && FindProcShort (glMultiTexCoord1s) | |
1591 | && FindProcShort (glMultiTexCoord1sv) | |
1592 | && FindProcShort (glMultiTexCoord2d) | |
1593 | && FindProcShort (glMultiTexCoord2dv) | |
1594 | && FindProcShort (glMultiTexCoord2f) | |
1595 | && FindProcShort (glMultiTexCoord2fv) | |
1596 | && FindProcShort (glMultiTexCoord2i) | |
1597 | && FindProcShort (glMultiTexCoord2iv) | |
1598 | && FindProcShort (glMultiTexCoord2s) | |
1599 | && FindProcShort (glMultiTexCoord2sv) | |
1600 | && FindProcShort (glMultiTexCoord3d) | |
1601 | && FindProcShort (glMultiTexCoord3dv) | |
1602 | && FindProcShort (glMultiTexCoord3f) | |
1603 | && FindProcShort (glMultiTexCoord3fv) | |
1604 | && FindProcShort (glMultiTexCoord3i) | |
1605 | && FindProcShort (glMultiTexCoord3iv) | |
1606 | && FindProcShort (glMultiTexCoord3s) | |
1607 | && FindProcShort (glMultiTexCoord3sv) | |
1608 | && FindProcShort (glMultiTexCoord4d) | |
1609 | && FindProcShort (glMultiTexCoord4dv) | |
1610 | && FindProcShort (glMultiTexCoord4f) | |
1611 | && FindProcShort (glMultiTexCoord4fv) | |
1612 | && FindProcShort (glMultiTexCoord4i) | |
1613 | && FindProcShort (glMultiTexCoord4iv) | |
1614 | && FindProcShort (glMultiTexCoord4s) | |
1615 | && FindProcShort (glMultiTexCoord4sv) | |
1616 | && FindProcShort (glLoadTransposeMatrixf) | |
1617 | && FindProcShort (glLoadTransposeMatrixd) | |
1618 | && FindProcShort (glMultTransposeMatrixf) | |
1619 | && FindProcShort (glMultTransposeMatrixd); | |
4e1523ef | 1620 | } |
01ca42b2 | 1621 | |
1622 | // load OpenGL 1.4 new functions | |
1623 | has14 = IsGlGreaterEqual (1, 4) | |
1624 | && FindProcShort (glBlendFuncSeparate) | |
1625 | && FindProcShort (glMultiDrawArrays) | |
1626 | && FindProcShort (glMultiDrawElements) | |
1627 | && FindProcShort (glPointParameterf) | |
1628 | && FindProcShort (glPointParameterfv) | |
1629 | && FindProcShort (glPointParameteri) | |
1630 | && FindProcShort (glPointParameteriv); | |
1631 | ||
1632 | // load OpenGL 1.5 new functions | |
1633 | has15 = IsGlGreaterEqual (1, 5) | |
1634 | && FindProcShort (glGenQueries) | |
1635 | && FindProcShort (glDeleteQueries) | |
1636 | && FindProcShort (glIsQuery) | |
1637 | && FindProcShort (glBeginQuery) | |
1638 | && FindProcShort (glEndQuery) | |
1639 | && FindProcShort (glGetQueryiv) | |
1640 | && FindProcShort (glGetQueryObjectiv) | |
1641 | && FindProcShort (glGetQueryObjectuiv) | |
1642 | && FindProcShort (glBindBuffer) | |
1643 | && FindProcShort (glDeleteBuffers) | |
1644 | && FindProcShort (glGenBuffers) | |
1645 | && FindProcShort (glIsBuffer) | |
1646 | && FindProcShort (glBufferData) | |
1647 | && FindProcShort (glBufferSubData) | |
1648 | && FindProcShort (glGetBufferSubData) | |
1649 | && FindProcShort (glMapBuffer) | |
1650 | && FindProcShort (glUnmapBuffer) | |
1651 | && FindProcShort (glGetBufferParameteriv) | |
1652 | && FindProcShort (glGetBufferPointerv); | |
1653 | ||
1654 | // load OpenGL 2.0 new functions | |
1655 | has20 = IsGlGreaterEqual (2, 0) | |
1656 | && FindProcShort (glBlendEquationSeparate) | |
1657 | && FindProcShort (glDrawBuffers) | |
1658 | && FindProcShort (glStencilOpSeparate) | |
1659 | && FindProcShort (glStencilFuncSeparate) | |
1660 | && FindProcShort (glStencilMaskSeparate) | |
1661 | && FindProcShort (glAttachShader) | |
1662 | && FindProcShort (glBindAttribLocation) | |
1663 | && FindProcShort (glCompileShader) | |
1664 | && FindProcShort (glCreateProgram) | |
1665 | && FindProcShort (glCreateShader) | |
1666 | && FindProcShort (glDeleteProgram) | |
1667 | && FindProcShort (glDeleteShader) | |
1668 | && FindProcShort (glDetachShader) | |
1669 | && FindProcShort (glDisableVertexAttribArray) | |
1670 | && FindProcShort (glEnableVertexAttribArray) | |
1671 | && FindProcShort (glGetActiveAttrib) | |
1672 | && FindProcShort (glGetActiveUniform) | |
1673 | && FindProcShort (glGetAttachedShaders) | |
1674 | && FindProcShort (glGetAttribLocation) | |
1675 | && FindProcShort (glGetProgramiv) | |
1676 | && FindProcShort (glGetProgramInfoLog) | |
1677 | && FindProcShort (glGetShaderiv) | |
1678 | && FindProcShort (glGetShaderInfoLog) | |
1679 | && FindProcShort (glGetShaderSource) | |
1680 | && FindProcShort (glGetUniformLocation) | |
1681 | && FindProcShort (glGetUniformfv) | |
1682 | && FindProcShort (glGetUniformiv) | |
1683 | && FindProcShort (glGetVertexAttribdv) | |
1684 | && FindProcShort (glGetVertexAttribfv) | |
1685 | && FindProcShort (glGetVertexAttribiv) | |
1686 | && FindProcShort (glGetVertexAttribPointerv) | |
1687 | && FindProcShort (glIsProgram) | |
1688 | && FindProcShort (glIsShader) | |
1689 | && FindProcShort (glLinkProgram) | |
1690 | && FindProcShort (glShaderSource) | |
1691 | && FindProcShort (glUseProgram) | |
1692 | && FindProcShort (glUniform1f) | |
1693 | && FindProcShort (glUniform2f) | |
1694 | && FindProcShort (glUniform3f) | |
1695 | && FindProcShort (glUniform4f) | |
1696 | && FindProcShort (glUniform1i) | |
1697 | && FindProcShort (glUniform2i) | |
1698 | && FindProcShort (glUniform3i) | |
1699 | && FindProcShort (glUniform4i) | |
1700 | && FindProcShort (glUniform1fv) | |
1701 | && FindProcShort (glUniform2fv) | |
1702 | && FindProcShort (glUniform3fv) | |
1703 | && FindProcShort (glUniform4fv) | |
1704 | && FindProcShort (glUniform1iv) | |
1705 | && FindProcShort (glUniform2iv) | |
1706 | && FindProcShort (glUniform3iv) | |
1707 | && FindProcShort (glUniform4iv) | |
1708 | && FindProcShort (glUniformMatrix2fv) | |
1709 | && FindProcShort (glUniformMatrix3fv) | |
1710 | && FindProcShort (glUniformMatrix4fv) | |
1711 | && FindProcShort (glValidateProgram) | |
1712 | && FindProcShort (glVertexAttrib1d) | |
1713 | && FindProcShort (glVertexAttrib1dv) | |
1714 | && FindProcShort (glVertexAttrib1f) | |
1715 | && FindProcShort (glVertexAttrib1fv) | |
1716 | && FindProcShort (glVertexAttrib1s) | |
1717 | && FindProcShort (glVertexAttrib1sv) | |
1718 | && FindProcShort (glVertexAttrib2d) | |
1719 | && FindProcShort (glVertexAttrib2dv) | |
1720 | && FindProcShort (glVertexAttrib2f) | |
1721 | && FindProcShort (glVertexAttrib2fv) | |
1722 | && FindProcShort (glVertexAttrib2s) | |
1723 | && FindProcShort (glVertexAttrib2sv) | |
1724 | && FindProcShort (glVertexAttrib3d) | |
1725 | && FindProcShort (glVertexAttrib3dv) | |
1726 | && FindProcShort (glVertexAttrib3f) | |
1727 | && FindProcShort (glVertexAttrib3fv) | |
1728 | && FindProcShort (glVertexAttrib3s) | |
1729 | && FindProcShort (glVertexAttrib3sv) | |
1730 | && FindProcShort (glVertexAttrib4Nbv) | |
1731 | && FindProcShort (glVertexAttrib4Niv) | |
1732 | && FindProcShort (glVertexAttrib4Nsv) | |
1733 | && FindProcShort (glVertexAttrib4Nub) | |
1734 | && FindProcShort (glVertexAttrib4Nubv) | |
1735 | && FindProcShort (glVertexAttrib4Nuiv) | |
1736 | && FindProcShort (glVertexAttrib4Nusv) | |
1737 | && FindProcShort (glVertexAttrib4bv) | |
1738 | && FindProcShort (glVertexAttrib4d) | |
1739 | && FindProcShort (glVertexAttrib4dv) | |
1740 | && FindProcShort (glVertexAttrib4f) | |
1741 | && FindProcShort (glVertexAttrib4fv) | |
1742 | && FindProcShort (glVertexAttrib4iv) | |
1743 | && FindProcShort (glVertexAttrib4s) | |
1744 | && FindProcShort (glVertexAttrib4sv) | |
1745 | && FindProcShort (glVertexAttrib4ubv) | |
1746 | && FindProcShort (glVertexAttrib4uiv) | |
1747 | && FindProcShort (glVertexAttrib4usv) | |
1748 | && FindProcShort (glVertexAttribPointer); | |
1749 | ||
1750 | // load OpenGL 2.1 new functions | |
1751 | has21 = IsGlGreaterEqual (2, 1) | |
1752 | && FindProcShort (glUniformMatrix2x3fv) | |
1753 | && FindProcShort (glUniformMatrix3x2fv) | |
1754 | && FindProcShort (glUniformMatrix2x4fv) | |
1755 | && FindProcShort (glUniformMatrix4x2fv) | |
1756 | && FindProcShort (glUniformMatrix3x4fv) | |
1757 | && FindProcShort (glUniformMatrix4x3fv); | |
1758 | ||
1759 | // load GL_ARB_framebuffer_object (added to OpenGL 3.0 core) | |
1760 | const bool hasFBO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_framebuffer_object")) | |
1761 | && FindProcShort (glIsRenderbuffer) | |
1762 | && FindProcShort (glBindRenderbuffer) | |
1763 | && FindProcShort (glDeleteRenderbuffers) | |
1764 | && FindProcShort (glGenRenderbuffers) | |
1765 | && FindProcShort (glRenderbufferStorage) | |
1766 | && FindProcShort (glGetRenderbufferParameteriv) | |
1767 | && FindProcShort (glIsFramebuffer) | |
1768 | && FindProcShort (glBindFramebuffer) | |
1769 | && FindProcShort (glDeleteFramebuffers) | |
1770 | && FindProcShort (glGenFramebuffers) | |
1771 | && FindProcShort (glCheckFramebufferStatus) | |
1772 | && FindProcShort (glFramebufferTexture1D) | |
1773 | && FindProcShort (glFramebufferTexture2D) | |
1774 | && FindProcShort (glFramebufferTexture3D) | |
1775 | && FindProcShort (glFramebufferRenderbuffer) | |
1776 | && FindProcShort (glGetFramebufferAttachmentParameteriv) | |
1777 | && FindProcShort (glGenerateMipmap) | |
1778 | && FindProcShort (glBlitFramebuffer) | |
1779 | && FindProcShort (glRenderbufferStorageMultisample) | |
1780 | && FindProcShort (glFramebufferTextureLayer); | |
1781 | ||
1782 | // load GL_ARB_vertex_array_object (added to OpenGL 3.0 core) | |
1783 | const bool hasVAO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_vertex_array_object")) | |
1784 | && FindProcShort (glBindVertexArray) | |
1785 | && FindProcShort (glDeleteVertexArrays) | |
1786 | && FindProcShort (glGenVertexArrays) | |
1787 | && FindProcShort (glIsVertexArray); | |
1788 | ||
1789 | // load GL_ARB_map_buffer_range (added to OpenGL 3.0 core) | |
1790 | const bool hasMapBufferRange = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_map_buffer_range")) | |
1791 | && FindProcShort (glMapBufferRange) | |
1792 | && FindProcShort (glFlushMappedBufferRange); | |
1793 | ||
1794 | // load OpenGL 3.0 new functions | |
1795 | has30 = IsGlGreaterEqual (3, 0) | |
1796 | && hasFBO | |
1797 | && hasVAO | |
1798 | && hasMapBufferRange | |
1799 | && FindProcShort (glColorMaski) | |
1800 | && FindProcShort (glGetBooleani_v) | |
1801 | && FindProcShort (glGetIntegeri_v) | |
1802 | && FindProcShort (glEnablei) | |
1803 | && FindProcShort (glDisablei) | |
1804 | && FindProcShort (glIsEnabledi) | |
1805 | && FindProcShort (glBeginTransformFeedback) | |
1806 | && FindProcShort (glEndTransformFeedback) | |
1807 | && FindProcShort (glBindBufferRange) | |
1808 | && FindProcShort (glBindBufferBase) | |
1809 | && FindProcShort (glTransformFeedbackVaryings) | |
1810 | && FindProcShort (glGetTransformFeedbackVarying) | |
1811 | && FindProcShort (glClampColor) | |
1812 | && FindProcShort (glBeginConditionalRender) | |
1813 | && FindProcShort (glEndConditionalRender) | |
1814 | && FindProcShort (glVertexAttribIPointer) | |
1815 | && FindProcShort (glGetVertexAttribIiv) | |
1816 | && FindProcShort (glGetVertexAttribIuiv) | |
1817 | && FindProcShort (glVertexAttribI1i) | |
1818 | && FindProcShort (glVertexAttribI2i) | |
1819 | && FindProcShort (glVertexAttribI3i) | |
1820 | && FindProcShort (glVertexAttribI4i) | |
1821 | && FindProcShort (glVertexAttribI1ui) | |
1822 | && FindProcShort (glVertexAttribI2ui) | |
1823 | && FindProcShort (glVertexAttribI3ui) | |
1824 | && FindProcShort (glVertexAttribI4ui) | |
1825 | && FindProcShort (glVertexAttribI1iv) | |
1826 | && FindProcShort (glVertexAttribI2iv) | |
1827 | && FindProcShort (glVertexAttribI3iv) | |
1828 | && FindProcShort (glVertexAttribI4iv) | |
1829 | && FindProcShort (glVertexAttribI1uiv) | |
1830 | && FindProcShort (glVertexAttribI2uiv) | |
1831 | && FindProcShort (glVertexAttribI3uiv) | |
1832 | && FindProcShort (glVertexAttribI4uiv) | |
1833 | && FindProcShort (glVertexAttribI4bv) | |
1834 | && FindProcShort (glVertexAttribI4sv) | |
1835 | && FindProcShort (glVertexAttribI4ubv) | |
1836 | && FindProcShort (glVertexAttribI4usv) | |
1837 | && FindProcShort (glGetUniformuiv) | |
1838 | && FindProcShort (glBindFragDataLocation) | |
1839 | && FindProcShort (glGetFragDataLocation) | |
1840 | && FindProcShort (glUniform1ui) | |
1841 | && FindProcShort (glUniform2ui) | |
1842 | && FindProcShort (glUniform3ui) | |
1843 | && FindProcShort (glUniform4ui) | |
1844 | && FindProcShort (glUniform1uiv) | |
1845 | && FindProcShort (glUniform2uiv) | |
1846 | && FindProcShort (glUniform3uiv) | |
1847 | && FindProcShort (glUniform4uiv) | |
1848 | && FindProcShort (glTexParameterIiv) | |
1849 | && FindProcShort (glTexParameterIuiv) | |
1850 | && FindProcShort (glGetTexParameterIiv) | |
1851 | && FindProcShort (glGetTexParameterIuiv) | |
1852 | && FindProcShort (glClearBufferiv) | |
1853 | && FindProcShort (glClearBufferuiv) | |
1854 | && FindProcShort (glClearBufferfv) | |
1855 | && FindProcShort (glClearBufferfi) | |
1856 | && FindProcShort (glGetStringi); | |
1857 | ||
1858 | // load GL_ARB_uniform_buffer_object (added to OpenGL 3.1 core) | |
1859 | const bool hasUBO = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_uniform_buffer_object")) | |
1860 | && FindProcShort (glGetUniformIndices) | |
1861 | && FindProcShort (glGetActiveUniformsiv) | |
1862 | && FindProcShort (glGetActiveUniformName) | |
1863 | && FindProcShort (glGetUniformBlockIndex) | |
1864 | && FindProcShort (glGetActiveUniformBlockiv) | |
1865 | && FindProcShort (glGetActiveUniformBlockName) | |
1866 | && FindProcShort (glUniformBlockBinding); | |
1867 | ||
1868 | // load GL_ARB_copy_buffer (added to OpenGL 3.1 core) | |
1869 | const bool hasCopyBufSubData = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_copy_buffer")) | |
1870 | && FindProcShort (glCopyBufferSubData); | |
1871 | ||
1872 | if (has30) | |
2166f0fa | 1873 | { |
01ca42b2 | 1874 | // NPOT textures are required by OpenGL 2.0 specifications |
1875 | // but doesn't hardware accelerated by some ancient OpenGL 2.1 hardware (GeForce FX, RadeOn 9700 etc.) | |
1876 | arbNPTW = Standard_True; | |
1877 | arbTexRG = Standard_True; | |
2166f0fa SK |
1878 | } |
1879 | ||
01ca42b2 | 1880 | // load OpenGL 3.1 new functions |
1881 | has31 = IsGlGreaterEqual (3, 1) | |
1882 | && hasUBO | |
1883 | && hasCopyBufSubData | |
1884 | && FindProcShort (glDrawArraysInstanced) | |
1885 | && FindProcShort (glDrawElementsInstanced) | |
1886 | && FindProcShort (glTexBuffer) | |
1887 | && FindProcShort (glPrimitiveRestartIndex); | |
1888 | ||
1889 | // load GL_ARB_draw_elements_base_vertex (added to OpenGL 3.2 core) | |
1890 | const bool hasDrawElemsBaseVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_draw_elements_base_vertex")) | |
1891 | && FindProcShort (glDrawElementsBaseVertex) | |
1892 | && FindProcShort (glDrawRangeElementsBaseVertex) | |
1893 | && FindProcShort (glDrawElementsInstancedBaseVertex) | |
1894 | && FindProcShort (glMultiDrawElementsBaseVertex); | |
1895 | ||
1896 | // load GL_ARB_provoking_vertex (added to OpenGL 3.2 core) | |
1897 | const bool hasProvokingVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_provoking_vertex")) | |
1898 | && FindProcShort (glProvokingVertex); | |
1899 | ||
1900 | // load GL_ARB_sync (added to OpenGL 3.2 core) | |
1901 | const bool hasSync = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_sync")) | |
1902 | && FindProcShort (glFenceSync) | |
1903 | && FindProcShort (glIsSync) | |
1904 | && FindProcShort (glDeleteSync) | |
1905 | && FindProcShort (glClientWaitSync) | |
1906 | && FindProcShort (glWaitSync) | |
1907 | && FindProcShort (glGetInteger64v) | |
1908 | && FindProcShort (glGetSynciv); | |
1909 | ||
1910 | // load GL_ARB_texture_multisample (added to OpenGL 3.2 core) | |
1911 | const bool hasTextureMultisample = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_texture_multisample")) | |
1912 | && FindProcShort (glTexImage2DMultisample) | |
1913 | && FindProcShort (glTexImage3DMultisample) | |
1914 | && FindProcShort (glGetMultisamplefv) | |
1915 | && FindProcShort (glSampleMaski); | |
1916 | ||
1917 | // load OpenGL 3.2 new functions | |
1918 | has32 = IsGlGreaterEqual (3, 2) | |
1919 | && hasDrawElemsBaseVert | |
1920 | && hasProvokingVert | |
1921 | && hasSync | |
1922 | && hasTextureMultisample | |
1923 | && FindProcShort (glGetInteger64i_v) | |
1924 | && FindProcShort (glGetBufferParameteri64v) | |
1925 | && FindProcShort (glFramebufferTexture); | |
1926 | ||
1927 | // load GL_ARB_blend_func_extended (added to OpenGL 3.3 core) | |
1928 | const bool hasBlendFuncExtended = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_blend_func_extended")) | |
1929 | && FindProcShort (glBindFragDataLocationIndexed) | |
1930 | && FindProcShort (glGetFragDataIndex); | |
1931 | ||
1932 | // load GL_ARB_sampler_objects (added to OpenGL 3.3 core) | |
1933 | const bool hasSamplerObjects = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_sampler_objects")) | |
1934 | && FindProcShort (glGenSamplers) | |
1935 | && FindProcShort (glDeleteSamplers) | |
1936 | && FindProcShort (glIsSampler) | |
1937 | && FindProcShort (glBindSampler) | |
1938 | && FindProcShort (glSamplerParameteri) | |
1939 | && FindProcShort (glSamplerParameteriv) | |
1940 | && FindProcShort (glSamplerParameterf) | |
1941 | && FindProcShort (glSamplerParameterfv) | |
1942 | && FindProcShort (glSamplerParameterIiv) | |
1943 | && FindProcShort (glSamplerParameterIuiv) | |
1944 | && FindProcShort (glGetSamplerParameteriv) | |
1945 | && FindProcShort (glGetSamplerParameterIiv) | |
1946 | && FindProcShort (glGetSamplerParameterfv) | |
1947 | && FindProcShort (glGetSamplerParameterIuiv); | |
cc8cbabe | 1948 | if (hasSamplerObjects) |
1949 | { | |
1950 | arbSamplerObject = (OpenGl_ArbSamplerObject* )(&(*myFuncs)); | |
1951 | } | |
01ca42b2 | 1952 | |
1953 | // load GL_ARB_timer_query (added to OpenGL 3.3 core) | |
1954 | const bool hasTimerQuery = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_timer_query")) | |
1955 | && FindProcShort (glQueryCounter) | |
1956 | && FindProcShort (glGetQueryObjecti64v) | |
1957 | && FindProcShort (glGetQueryObjectui64v); | |
1958 | ||
1959 | // load GL_ARB_vertex_type_2_10_10_10_rev (added to OpenGL 3.3 core) | |
1960 | const bool hasVertType21010101rev = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_vertex_type_2_10_10_10_rev")) | |
0e628baf | 1961 | && FindProcShort (glVertexAttribP1ui) |
1962 | && FindProcShort (glVertexAttribP1uiv) | |
1963 | && FindProcShort (glVertexAttribP2ui) | |
1964 | && FindProcShort (glVertexAttribP2uiv) | |
1965 | && FindProcShort (glVertexAttribP3ui) | |
1966 | && FindProcShort (glVertexAttribP3uiv) | |
1967 | && FindProcShort (glVertexAttribP4ui) | |
1968 | && FindProcShort (glVertexAttribP4uiv); | |
1969 | ||
1970 | if ( hasVertType21010101rev | |
1971 | && !isCoreProfile) | |
1972 | { | |
1973 | // load deprecated functions | |
1974 | const bool hasVertType21010101revExt = | |
1975 | FindProcShort (glVertexP2ui) | |
01ca42b2 | 1976 | && FindProcShort (glVertexP2uiv) |
1977 | && FindProcShort (glVertexP3ui) | |
1978 | && FindProcShort (glVertexP3uiv) | |
1979 | && FindProcShort (glVertexP4ui) | |
1980 | && FindProcShort (glVertexP4uiv) | |
1981 | && FindProcShort (glTexCoordP1ui) | |
1982 | && FindProcShort (glTexCoordP1uiv) | |
1983 | && FindProcShort (glTexCoordP2ui) | |
1984 | && FindProcShort (glTexCoordP2uiv) | |
1985 | && FindProcShort (glTexCoordP3ui) | |
1986 | && FindProcShort (glTexCoordP3uiv) | |
1987 | && FindProcShort (glTexCoordP4ui) | |
1988 | && FindProcShort (glTexCoordP4uiv) | |
1989 | && FindProcShort (glMultiTexCoordP1ui) | |
1990 | && FindProcShort (glMultiTexCoordP1uiv) | |
1991 | && FindProcShort (glMultiTexCoordP2ui) | |
1992 | && FindProcShort (glMultiTexCoordP2uiv) | |
1993 | && FindProcShort (glMultiTexCoordP3ui) | |
1994 | && FindProcShort (glMultiTexCoordP3uiv) | |
1995 | && FindProcShort (glMultiTexCoordP4ui) | |
1996 | && FindProcShort (glMultiTexCoordP4uiv) | |
1997 | && FindProcShort (glNormalP3ui) | |
1998 | && FindProcShort (glNormalP3uiv) | |
1999 | && FindProcShort (glColorP3ui) | |
2000 | && FindProcShort (glColorP3uiv) | |
2001 | && FindProcShort (glColorP4ui) | |
2002 | && FindProcShort (glColorP4uiv) | |
2003 | && FindProcShort (glSecondaryColorP3ui) | |
0e628baf | 2004 | && FindProcShort (glSecondaryColorP3uiv); |
2005 | (void )hasVertType21010101revExt; | |
2006 | } | |
01ca42b2 | 2007 | |
2008 | // load OpenGL 3.3 extra functions | |
2009 | has33 = IsGlGreaterEqual (3, 3) | |
2010 | && hasBlendFuncExtended | |
2011 | && hasSamplerObjects | |
2012 | && hasTimerQuery | |
2013 | && hasVertType21010101rev | |
2014 | && FindProcShort (glVertexAttribDivisor); | |
2015 | ||
2016 | // load GL_ARB_draw_indirect (added to OpenGL 4.0 core) | |
2017 | const bool hasDrawIndirect = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_draw_indirect")) | |
2018 | && FindProcShort (glDrawArraysIndirect) | |
2019 | && FindProcShort (glDrawElementsIndirect); | |
2020 | ||
2021 | // load GL_ARB_gpu_shader_fp64 (added to OpenGL 4.0 core) | |
2022 | const bool hasShaderFP64 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_gpu_shader_fp64")) | |
2023 | && FindProcShort (glUniform1d) | |
2024 | && FindProcShort (glUniform2d) | |
2025 | && FindProcShort (glUniform3d) | |
2026 | && FindProcShort (glUniform4d) | |
2027 | && FindProcShort (glUniform1dv) | |
2028 | && FindProcShort (glUniform2dv) | |
2029 | && FindProcShort (glUniform3dv) | |
2030 | && FindProcShort (glUniform4dv) | |
2031 | && FindProcShort (glUniformMatrix2dv) | |
2032 | && FindProcShort (glUniformMatrix3dv) | |
2033 | && FindProcShort (glUniformMatrix4dv) | |
2034 | && FindProcShort (glUniformMatrix2x3dv) | |
2035 | && FindProcShort (glUniformMatrix2x4dv) | |
2036 | && FindProcShort (glUniformMatrix3x2dv) | |
2037 | && FindProcShort (glUniformMatrix3x4dv) | |
2038 | && FindProcShort (glUniformMatrix4x2dv) | |
2039 | && FindProcShort (glUniformMatrix4x3dv) | |
2040 | && FindProcShort (glGetUniformdv); | |
2041 | ||
2042 | // load GL_ARB_shader_subroutine (added to OpenGL 4.0 core) | |
2043 | const bool hasShaderSubroutine = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_shader_subroutine")) | |
2044 | && FindProcShort (glGetSubroutineUniformLocation) | |
2045 | && FindProcShort (glGetSubroutineIndex) | |
2046 | && FindProcShort (glGetActiveSubroutineUniformiv) | |
2047 | && FindProcShort (glGetActiveSubroutineUniformName) | |
2048 | && FindProcShort (glGetActiveSubroutineName) | |
2049 | && FindProcShort (glUniformSubroutinesuiv) | |
2050 | && FindProcShort (glGetUniformSubroutineuiv) | |
2051 | && FindProcShort (glGetProgramStageiv); | |
2052 | ||
2053 | // load GL_ARB_tessellation_shader (added to OpenGL 4.0 core) | |
2054 | const bool hasTessellationShader = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_tessellation_shader")) | |
2055 | && FindProcShort (glPatchParameteri) | |
2056 | && FindProcShort (glPatchParameterfv); | |
2057 | ||
2058 | // load GL_ARB_transform_feedback2 (added to OpenGL 4.0 core) | |
2059 | const bool hasTrsfFeedback2 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback2")) | |
2060 | && FindProcShort (glBindTransformFeedback) | |
2061 | && FindProcShort (glDeleteTransformFeedbacks) | |
2062 | && FindProcShort (glGenTransformFeedbacks) | |
2063 | && FindProcShort (glIsTransformFeedback) | |
2064 | && FindProcShort (glPauseTransformFeedback) | |
2065 | && FindProcShort (glResumeTransformFeedback) | |
2066 | && FindProcShort (glDrawTransformFeedback); | |
2067 | ||
2068 | // load GL_ARB_transform_feedback3 (added to OpenGL 4.0 core) | |
2069 | const bool hasTrsfFeedback3 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback3")) | |
2070 | && FindProcShort (glDrawTransformFeedbackStream) | |
2071 | && FindProcShort (glBeginQueryIndexed) | |
2072 | && FindProcShort (glEndQueryIndexed) | |
2073 | && FindProcShort (glGetQueryIndexediv); | |
2074 | ||
2075 | // load OpenGL 4.0 new functions | |
2076 | has40 = IsGlGreaterEqual (4, 0) | |
2077 | && hasDrawIndirect | |
2078 | && hasShaderFP64 | |
2079 | && hasShaderSubroutine | |
2080 | && hasTessellationShader | |
2081 | && hasTrsfFeedback2 | |
2082 | && hasTrsfFeedback3 | |
2083 | && FindProcShort (glMinSampleShading) | |
2084 | && FindProcShort (glBlendEquationi) | |
2085 | && FindProcShort (glBlendEquationSeparatei) | |
2086 | && FindProcShort (glBlendFunci) | |
2087 | && FindProcShort (glBlendFuncSeparatei); | |
2088 | ||
2089 | // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core) | |
2090 | const bool hasES2Compatibility = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_ES2_compatibility")) | |
2091 | && FindProcShort (glReleaseShaderCompiler) | |
2092 | && FindProcShort (glShaderBinary) | |
2093 | && FindProcShort (glGetShaderPrecisionFormat) | |
2094 | && FindProcShort (glDepthRangef) | |
2095 | && FindProcShort (glClearDepthf); | |
2096 | ||
2097 | // load GL_ARB_get_program_binary (added to OpenGL 4.1 core) | |
2098 | const bool hasGetProgramBinary = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_get_program_binary")) | |
2099 | && FindProcShort (glGetProgramBinary) | |
2100 | && FindProcShort (glProgramBinary) | |
2101 | && FindProcShort (glProgramParameteri); | |
2102 | ||
2103 | ||
2104 | // load GL_ARB_separate_shader_objects (added to OpenGL 4.1 core) | |
2105 | const bool hasSeparateShaderObjects = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_separate_shader_objects")) | |
2106 | && FindProcShort (glUseProgramStages) | |
2107 | && FindProcShort (glActiveShaderProgram) | |
2108 | && FindProcShort (glCreateShaderProgramv) | |
2109 | && FindProcShort (glBindProgramPipeline) | |
2110 | && FindProcShort (glDeleteProgramPipelines) | |
2111 | && FindProcShort (glGenProgramPipelines) | |
2112 | && FindProcShort (glIsProgramPipeline) | |
2113 | && FindProcShort (glGetProgramPipelineiv) | |
2114 | && FindProcShort (glProgramUniform1i) | |
2115 | && FindProcShort (glProgramUniform1iv) | |
2116 | && FindProcShort (glProgramUniform1f) | |
2117 | && FindProcShort (glProgramUniform1fv) | |
2118 | && FindProcShort (glProgramUniform1d) | |
2119 | && FindProcShort (glProgramUniform1dv) | |
2120 | && FindProcShort (glProgramUniform1ui) | |
2121 | && FindProcShort (glProgramUniform1uiv) | |
2122 | && FindProcShort (glProgramUniform2i) | |
2123 | && FindProcShort (glProgramUniform2iv) | |
2124 | && FindProcShort (glProgramUniform2f) | |
2125 | && FindProcShort (glProgramUniform2fv) | |
2126 | && FindProcShort (glProgramUniform2d) | |
2127 | && FindProcShort (glProgramUniform2dv) | |
2128 | && FindProcShort (glProgramUniform2ui) | |
2129 | && FindProcShort (glProgramUniform2uiv) | |
2130 | && FindProcShort (glProgramUniform3i) | |
2131 | && FindProcShort (glProgramUniform3iv) | |
2132 | && FindProcShort (glProgramUniform3f) | |
2133 | && FindProcShort (glProgramUniform3fv) | |
2134 | && FindProcShort (glProgramUniform3d) | |
2135 | && FindProcShort (glProgramUniform3dv) | |
2136 | && FindProcShort (glProgramUniform3ui) | |
2137 | && FindProcShort (glProgramUniform3uiv) | |
2138 | && FindProcShort (glProgramUniform4i) | |
2139 | && FindProcShort (glProgramUniform4iv) | |
2140 | && FindProcShort (glProgramUniform4f) | |
2141 | && FindProcShort (glProgramUniform4fv) | |
2142 | && FindProcShort (glProgramUniform4d) | |
2143 | && FindProcShort (glProgramUniform4dv) | |
2144 | && FindProcShort (glProgramUniform4ui) | |
2145 | && FindProcShort (glProgramUniform4uiv) | |
2146 | && FindProcShort (glProgramUniformMatrix2fv) | |
2147 | && FindProcShort (glProgramUniformMatrix3fv) | |
2148 | && FindProcShort (glProgramUniformMatrix4fv) | |
2149 | && FindProcShort (glProgramUniformMatrix2dv) | |
2150 | && FindProcShort (glProgramUniformMatrix3dv) | |
2151 | && FindProcShort (glProgramUniformMatrix4dv) | |
2152 | && FindProcShort (glProgramUniformMatrix2x3fv) | |
2153 | && FindProcShort (glProgramUniformMatrix3x2fv) | |
2154 | && FindProcShort (glProgramUniformMatrix2x4fv) | |
2155 | && FindProcShort (glProgramUniformMatrix4x2fv) | |
2156 | && FindProcShort (glProgramUniformMatrix3x4fv) | |
2157 | && FindProcShort (glProgramUniformMatrix4x3fv) | |
2158 | && FindProcShort (glProgramUniformMatrix2x3dv) | |
2159 | && FindProcShort (glProgramUniformMatrix3x2dv) | |
2160 | && FindProcShort (glProgramUniformMatrix2x4dv) | |
2161 | && FindProcShort (glProgramUniformMatrix4x2dv) | |
2162 | && FindProcShort (glProgramUniformMatrix3x4dv) | |
2163 | && FindProcShort (glProgramUniformMatrix4x3dv) | |
2164 | && FindProcShort (glValidateProgramPipeline) | |
2165 | && FindProcShort (glGetProgramPipelineInfoLog); | |
2166 | ||
2167 | // load GL_ARB_vertex_attrib_64bit (added to OpenGL 4.1 core) | |
2168 | const bool hasVertAttrib64bit = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_vertex_attrib_64bit")) | |
2169 | && FindProcShort (glVertexAttribL1d) | |
2170 | && FindProcShort (glVertexAttribL2d) | |
2171 | && FindProcShort (glVertexAttribL3d) | |
2172 | && FindProcShort (glVertexAttribL4d) | |
2173 | && FindProcShort (glVertexAttribL1dv) | |
2174 | && FindProcShort (glVertexAttribL2dv) | |
2175 | && FindProcShort (glVertexAttribL3dv) | |
2176 | && FindProcShort (glVertexAttribL4dv) | |
2177 | && FindProcShort (glVertexAttribLPointer) | |
2178 | && FindProcShort (glGetVertexAttribLdv); | |
2179 | ||
2180 | // load GL_ARB_viewport_array (added to OpenGL 4.1 core) | |
2181 | const bool hasViewportArray = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_viewport_array")) | |
2182 | && FindProcShort (glViewportArrayv) | |
2183 | && FindProcShort (glViewportIndexedf) | |
2184 | && FindProcShort (glViewportIndexedfv) | |
2185 | && FindProcShort (glScissorArrayv) | |
2186 | && FindProcShort (glScissorIndexed) | |
2187 | && FindProcShort (glScissorIndexedv) | |
2188 | && FindProcShort (glDepthRangeArrayv) | |
2189 | && FindProcShort (glDepthRangeIndexed) | |
2190 | && FindProcShort (glGetFloati_v) | |
2191 | && FindProcShort (glGetDoublei_v); | |
2192 | ||
2193 | has41 = IsGlGreaterEqual (4, 1) | |
2194 | && hasES2Compatibility | |
2195 | && hasGetProgramBinary | |
2196 | && hasSeparateShaderObjects | |
2197 | && hasVertAttrib64bit | |
2198 | && hasViewportArray; | |
2199 | ||
2200 | // load GL_ARB_base_instance (added to OpenGL 4.2 core) | |
2201 | const bool hasBaseInstance = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_base_instance")) | |
2202 | && FindProcShort (glDrawArraysInstancedBaseInstance) | |
2203 | && FindProcShort (glDrawElementsInstancedBaseInstance) | |
2204 | && FindProcShort (glDrawElementsInstancedBaseVertexBaseInstance); | |
2205 | ||
2206 | // load GL_ARB_transform_feedback_instanced (added to OpenGL 4.2 core) | |
2207 | const bool hasTrsfFeedbackInstanced = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_transform_feedback_instanced")) | |
2208 | && FindProcShort (glDrawTransformFeedbackInstanced) | |
2209 | && FindProcShort (glDrawTransformFeedbackStreamInstanced); | |
2210 | ||
2211 | // load GL_ARB_internalformat_query (added to OpenGL 4.2 core) | |
2212 | const bool hasInternalFormatQuery = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_internalformat_query")) | |
2213 | && FindProcShort (glGetInternalformativ); | |
2214 | ||
2215 | // load GL_ARB_shader_atomic_counters (added to OpenGL 4.2 core) | |
2216 | const bool hasShaderAtomicCounters = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_atomic_counters")) | |
2217 | && FindProcShort (glGetActiveAtomicCounterBufferiv); | |
2218 | ||
2219 | // load GL_ARB_shader_image_load_store (added to OpenGL 4.2 core) | |
2220 | const bool hasShaderImgLoadStore = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_image_load_store")) | |
2221 | && FindProcShort (glBindImageTexture) | |
2222 | && FindProcShort (glMemoryBarrier); | |
2223 | ||
2224 | // load GL_ARB_texture_storage (added to OpenGL 4.2 core) | |
2225 | const bool hasTextureStorage = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_texture_storage")) | |
2226 | && FindProcShort (glTexStorage1D) | |
2227 | && FindProcShort (glTexStorage2D) | |
c87535af | 2228 | && FindProcShort (glTexStorage3D); |
01ca42b2 | 2229 | |
2230 | has42 = IsGlGreaterEqual (4, 2) | |
2231 | && hasBaseInstance | |
2232 | && hasTrsfFeedbackInstanced | |
2233 | && hasInternalFormatQuery | |
2234 | && hasShaderAtomicCounters | |
2235 | && hasShaderImgLoadStore | |
2236 | && hasTextureStorage; | |
2237 | ||
2238 | has43 = IsGlGreaterEqual (4, 3) | |
2239 | && FindProcShort (glClearBufferData) | |
2240 | && FindProcShort (glClearBufferSubData) | |
2241 | && FindProcShort (glDispatchCompute) | |
2242 | && FindProcShort (glDispatchComputeIndirect) | |
2243 | && FindProcShort (glCopyImageSubData) | |
2244 | && FindProcShort (glFramebufferParameteri) | |
2245 | && FindProcShort (glGetFramebufferParameteriv) | |
2246 | && FindProcShort (glGetInternalformati64v) | |
2247 | && FindProcShort (glInvalidateTexSubImage) | |
2248 | && FindProcShort (glInvalidateTexImage) | |
2249 | && FindProcShort (glInvalidateBufferSubData) | |
2250 | && FindProcShort (glInvalidateBufferData) | |
2251 | && FindProcShort (glInvalidateFramebuffer) | |
2252 | && FindProcShort (glInvalidateSubFramebuffer) | |
2253 | && FindProcShort (glMultiDrawArraysIndirect) | |
2254 | && FindProcShort (glMultiDrawElementsIndirect) | |
2255 | && FindProcShort (glGetProgramInterfaceiv) | |
2256 | && FindProcShort (glGetProgramResourceIndex) | |
2257 | && FindProcShort (glGetProgramResourceName) | |
2258 | && FindProcShort (glGetProgramResourceiv) | |
2259 | && FindProcShort (glGetProgramResourceLocation) | |
2260 | && FindProcShort (glGetProgramResourceLocationIndex) | |
2261 | && FindProcShort (glShaderStorageBlockBinding) | |
2262 | && FindProcShort (glTexBufferRange) | |
2263 | && FindProcShort (glTexStorage2DMultisample) | |
2264 | && FindProcShort (glTexStorage3DMultisample) | |
2265 | && FindProcShort (glTextureView) | |
2266 | && FindProcShort (glBindVertexBuffer) | |
2267 | && FindProcShort (glVertexAttribFormat) | |
2268 | && FindProcShort (glVertexAttribIFormat) | |
2269 | && FindProcShort (glVertexAttribLFormat) | |
2270 | && FindProcShort (glVertexAttribBinding) | |
2271 | && FindProcShort (glVertexBindingDivisor) | |
2272 | && FindProcShort (glDebugMessageControl) | |
2273 | && FindProcShort (glDebugMessageInsert) | |
2274 | && FindProcShort (glDebugMessageCallback) | |
2275 | && FindProcShort (glGetDebugMessageLog) | |
2276 | && FindProcShort (glPushDebugGroup) | |
2277 | && FindProcShort (glPopDebugGroup) | |
2278 | && FindProcShort (glObjectLabel) | |
2279 | && FindProcShort (glGetObjectLabel) | |
2280 | && FindProcShort (glObjectPtrLabel) | |
2281 | && FindProcShort (glGetObjectPtrLabel); | |
2282 | ||
2283 | // load GL_ARB_clear_texture (added to OpenGL 4.4 core) | |
2284 | bool arbTexClear = (IsGlGreaterEqual (4, 4) || CheckExtension ("GL_ARB_clear_texture")) | |
2285 | && FindProcShort (glClearTexImage) | |
2286 | && FindProcShort (glClearTexSubImage); | |
2287 | ||
2288 | has44 = IsGlGreaterEqual (4, 4) | |
2289 | && arbTexClear | |
2290 | && FindProcShort (glBufferStorage) | |
2291 | && FindProcShort (glBindBuffersBase) | |
2292 | && FindProcShort (glBindBuffersRange) | |
2293 | && FindProcShort (glBindTextures) | |
2294 | && FindProcShort (glBindSamplers) | |
2295 | && FindProcShort (glBindImageTextures) | |
2296 | && FindProcShort (glBindVertexBuffers); | |
2297 | ||
0deb6f04 | 2298 | // initialize debug context extension |
2299 | if (CheckExtension ("GL_ARB_debug_output")) | |
2300 | { | |
2301 | arbDbg = NULL; | |
2302 | if (has43) | |
2303 | { | |
2304 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); | |
2305 | } | |
2306 | else if (FindProc ("glDebugMessageControlARB", myFuncs->glDebugMessageControl) | |
2307 | && FindProc ("glDebugMessageInsertARB", myFuncs->glDebugMessageInsert) | |
2308 | && FindProc ("glDebugMessageCallbackARB", myFuncs->glDebugMessageCallback) | |
2309 | && FindProc ("glGetDebugMessageLogARB", myFuncs->glGetDebugMessageLog)) | |
2310 | { | |
2311 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); | |
2312 | } | |
2313 | ||
2314 | if (arbDbg != NULL | |
2315 | && caps->contextDebug) | |
2316 | { | |
2317 | // setup default callback | |
2318 | myIsGlDebugCtx = Standard_True; | |
2319 | arbDbg->glDebugMessageCallback (debugCallbackWrap, this); | |
2320 | if (has43) | |
2321 | { | |
2322 | ::glEnable (GL_DEBUG_OUTPUT); | |
2323 | } | |
2324 | if (caps->contextSyncDebug) | |
2325 | { | |
2326 | ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS); | |
2327 | } | |
2328 | } | |
2329 | } | |
2330 | ||
5e27df78 | 2331 | // initialize TBO extension (ARB) |
01ca42b2 | 2332 | if (!has31 |
2333 | && CheckExtension ("GL_ARB_texture_buffer_object") | |
2334 | && FindProc ("glTexBufferARB", myFuncs->glTexBuffer)) | |
5e27df78 | 2335 | { |
01ca42b2 | 2336 | arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs)); |
5e27df78 | 2337 | } |
25ef750e | 2338 | arbTboRGB32 = CheckExtension ("GL_ARB_texture_buffer_object_rgb32"); |
5e27df78 | 2339 | |
2340 | // initialize hardware instancing extension (ARB) | |
01ca42b2 | 2341 | if (!has31 |
2342 | && CheckExtension ("GL_ARB_draw_instanced") | |
2343 | && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced) | |
2344 | && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced)) | |
5e27df78 | 2345 | { |
01ca42b2 | 2346 | arbIns = (OpenGl_ArbIns* )(&(*myFuncs)); |
5e27df78 | 2347 | } |
2348 | ||
01ca42b2 | 2349 | // initialize FBO extension (ARB) |
2350 | if (hasFBO) | |
2166f0fa | 2351 | { |
b86bb3df | 2352 | arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs)); |
2353 | arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs)); | |
01ca42b2 | 2354 | extPDS = Standard_True; // extension for EXT, but part of ARB |
2166f0fa | 2355 | } |
5f8b738e | 2356 | |
37eb4787 | 2357 | // initialize GS extension (EXT) |
01ca42b2 | 2358 | if (CheckExtension ("GL_EXT_geometry_shader4") |
2359 | && FindProcShort (glProgramParameteriEXT)) | |
37eb4787 | 2360 | { |
01ca42b2 | 2361 | extGS = (OpenGl_ExtGS* )(&(*myFuncs)); |
37eb4787 | 2362 | } |
2363 | ||
25ef750e | 2364 | // initialize bindless texture extension (ARB) |
2365 | if (CheckExtension ("GL_ARB_bindless_texture") | |
2366 | && FindProcShort (glGetTextureHandleARB) | |
2367 | && FindProcShort (glGetTextureSamplerHandleARB) | |
2368 | && FindProcShort (glMakeTextureHandleResidentARB) | |
2369 | && FindProcShort (glMakeTextureHandleNonResidentARB) | |
2370 | && FindProcShort (glGetImageHandleARB) | |
2371 | && FindProcShort (glMakeImageHandleResidentARB) | |
2372 | && FindProcShort (glMakeImageHandleNonResidentARB) | |
2373 | && FindProcShort (glUniformHandleui64ARB) | |
2374 | && FindProcShort (glUniformHandleui64vARB) | |
2375 | && FindProcShort (glProgramUniformHandleui64ARB) | |
2376 | && FindProcShort (glProgramUniformHandleui64vARB) | |
2377 | && FindProcShort (glIsTextureHandleResidentARB) | |
2378 | && FindProcShort (glIsImageHandleResidentARB) | |
2379 | && FindProcShort (glVertexAttribL1ui64ARB) | |
2380 | && FindProcShort (glVertexAttribL1ui64vARB) | |
2381 | && FindProcShort (glGetVertexAttribLui64vARB)) | |
2382 | { | |
2383 | arbTexBindless = (OpenGl_ArbTexBindless* )(&(*myFuncs)); | |
2384 | } | |
2385 | ||
01ca42b2 | 2386 | if (!has12) |
86325709 | 2387 | { |
ee51a9fe | 2388 | checkWrongVersion (1, 2); |
86325709 | 2389 | myGlVerMajor = 1; |
2390 | myGlVerMinor = 1; | |
2391 | return; | |
5f8b738e | 2392 | } |
01ca42b2 | 2393 | else if (!has13) |
5f8b738e | 2394 | { |
ee51a9fe | 2395 | checkWrongVersion (1, 3); |
01ca42b2 | 2396 | myGlVerMajor = 1; |
2397 | myGlVerMinor = 2; | |
2398 | return; | |
5f8b738e | 2399 | } |
01ca42b2 | 2400 | else if (!has14) |
5f8b738e | 2401 | { |
ee51a9fe | 2402 | checkWrongVersion (1, 4); |
86325709 | 2403 | myGlVerMajor = 1; |
01ca42b2 | 2404 | myGlVerMinor = 3; |
86325709 | 2405 | return; |
5f8b738e | 2406 | } |
01ca42b2 | 2407 | else if (!has15) |
86325709 | 2408 | { |
ee51a9fe | 2409 | checkWrongVersion (1, 5); |
01ca42b2 | 2410 | myGlVerMajor = 1; |
2411 | myGlVerMinor = 4; | |
2412 | return; | |
5f8b738e | 2413 | } |
4e1523ef | 2414 | if (!isCoreProfile) |
2415 | { | |
2416 | core15 = (OpenGl_GlCore15* )(&(*myFuncs)); | |
2417 | } | |
01ca42b2 | 2418 | core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs)); |
2419 | ||
2420 | if (!has20) | |
86325709 | 2421 | { |
ee51a9fe | 2422 | checkWrongVersion (2, 0); |
2423 | myGlVerMajor = 1; | |
2424 | myGlVerMinor = 5; | |
2425 | return; | |
2426 | } | |
2427 | ||
2428 | const char* aGlslVer = (const char* )::glGetString (GL_SHADING_LANGUAGE_VERSION); | |
2429 | if (aGlslVer == NULL | |
2430 | || *aGlslVer == '\0') | |
2431 | { | |
2432 | // broken context has been detected | |
2433 | TCollection_ExtendedString aMsg = TCollection_ExtendedString() | |
2434 | + "Error! OpenGL context reports version " | |
2435 | + myGlVerMajor + "." + myGlVerMinor | |
2436 | + " but reports wrong GLSL version"; | |
3b523c4c | 2437 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, |
2438 | GL_DEBUG_TYPE_ERROR, | |
ee51a9fe | 2439 | 0, |
3b523c4c | 2440 | GL_DEBUG_SEVERITY_HIGH, |
ee51a9fe | 2441 | aMsg); |
86325709 | 2442 | myGlVerMajor = 1; |
01ca42b2 | 2443 | myGlVerMinor = 5; |
86325709 | 2444 | return; |
5f8b738e | 2445 | } |
01ca42b2 | 2446 | |
4e1523ef | 2447 | if (!isCoreProfile) |
2448 | { | |
2449 | core20 = (OpenGl_GlCore20* )(&(*myFuncs)); | |
2450 | } | |
01ca42b2 | 2451 | core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs)); |
2452 | ||
2453 | if (!has21) | |
5f8b738e | 2454 | { |
ee51a9fe | 2455 | checkWrongVersion (2, 1); |
01ca42b2 | 2456 | myGlVerMajor = 2; |
2457 | myGlVerMinor = 0; | |
2458 | return; | |
86325709 | 2459 | } |
01ca42b2 | 2460 | |
2461 | if (!has30) | |
86325709 | 2462 | { |
ee51a9fe | 2463 | checkWrongVersion (3, 0); |
01ca42b2 | 2464 | myGlVerMajor = 2; |
2465 | myGlVerMinor = 1; | |
86325709 | 2466 | return; |
2467 | } | |
01ca42b2 | 2468 | |
3c4b62a4 | 2469 | // MSAA RenderBuffers have been defined in OpenGL 3.0, |
2470 | // but MSAA Textures - only in OpenGL 3.2+ | |
2471 | if (!has32 | |
2472 | && CheckExtension ("GL_ARB_texture_multisample") | |
2473 | && FindProcShort (glTexImage2DMultisample)) | |
2474 | { | |
2475 | GLint aNbColorSamples = 0, aNbDepthSamples = 0; | |
2476 | ::glGetIntegerv (GL_MAX_COLOR_TEXTURE_SAMPLES, &aNbColorSamples); | |
2477 | ::glGetIntegerv (GL_MAX_DEPTH_TEXTURE_SAMPLES, &aNbDepthSamples); | |
2478 | myMaxMsaaSamples = Min (aNbColorSamples, aNbDepthSamples); | |
2479 | } | |
2480 | if (!has43 | |
2481 | && CheckExtension ("GL_ARB_texture_storage_multisample") | |
2482 | && FindProcShort (glTexStorage2DMultisample)) | |
2483 | { | |
2484 | // | |
2485 | } | |
2486 | ||
01ca42b2 | 2487 | if (!has31) |
2488 | { | |
ee51a9fe | 2489 | checkWrongVersion (3, 1); |
01ca42b2 | 2490 | myGlVerMajor = 3; |
2491 | myGlVerMinor = 0; | |
2492 | return; | |
2493 | } | |
2494 | arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs)); | |
2495 | arbIns = (OpenGl_ArbIns* )(&(*myFuncs)); | |
2496 | ||
3a9b5dc8 | 2497 | // check whether ray tracing mode is supported |
2498 | myHasRayTracing = has31 | |
2499 | && arbTboRGB32 | |
2500 | && arbFBOBlit != NULL; | |
2501 | ||
2502 | // check whether textures in ray tracing mode are supported | |
2503 | myHasRayTracingTextures = myHasRayTracing | |
2504 | && arbTexBindless != NULL; | |
2505 | ||
2506 | // check whether adaptive screen sampling in ray tracing mode is supported | |
2507 | myHasRayTracingAdaptiveSampling = myHasRayTracing | |
2508 | && has44 | |
2509 | && CheckExtension ("GL_NV_shader_atomic_float"); | |
2510 | ||
01ca42b2 | 2511 | if (!has32) |
86325709 | 2512 | { |
ee51a9fe | 2513 | checkWrongVersion (3, 2); |
01ca42b2 | 2514 | myGlVerMajor = 3; |
2515 | myGlVerMinor = 1; | |
2516 | return; | |
86325709 | 2517 | } |
4e1523ef | 2518 | core32 = (OpenGl_GlCore32* )(&(*myFuncs)); |
2519 | if (isCoreProfile) | |
2520 | { | |
2521 | core32->glGenVertexArrays (1, &myDefaultVao); | |
2522 | } | |
2523 | else | |
2524 | { | |
2525 | core32back = (OpenGl_GlCore32Back* )(&(*myFuncs)); | |
2526 | } | |
3c4b62a4 | 2527 | ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples); |
01ca42b2 | 2528 | |
2529 | if (!has33) | |
86325709 | 2530 | { |
ee51a9fe | 2531 | checkWrongVersion (3, 3); |
01ca42b2 | 2532 | myGlVerMajor = 3; |
2533 | myGlVerMinor = 2; | |
2534 | return; | |
86325709 | 2535 | } |
4e1523ef | 2536 | core33 = (OpenGl_GlCore33* )(&(*myFuncs)); |
2537 | if (!isCoreProfile) | |
2538 | { | |
2539 | core33back = (OpenGl_GlCore33Back* )(&(*myFuncs)); | |
2540 | } | |
25ef750e | 2541 | |
01ca42b2 | 2542 | if (!has40) |
86325709 | 2543 | { |
ee51a9fe | 2544 | checkWrongVersion (4, 0); |
01ca42b2 | 2545 | myGlVerMajor = 3; |
2546 | myGlVerMinor = 3; | |
2547 | return; | |
2548 | } | |
25ef750e | 2549 | arbTboRGB32 = Standard_True; // in core since OpenGL 4.0 |
01ca42b2 | 2550 | |
2551 | if (!has41) | |
2552 | { | |
ee51a9fe | 2553 | checkWrongVersion (4, 1); |
01ca42b2 | 2554 | myGlVerMajor = 4; |
2555 | myGlVerMinor = 0; | |
2556 | return; | |
2557 | } | |
4e1523ef | 2558 | core41 = (OpenGl_GlCore41* )(&(*myFuncs)); |
2559 | if (!isCoreProfile) | |
2560 | { | |
2561 | core41back = (OpenGl_GlCore41Back* )(&(*myFuncs)); | |
2562 | } | |
01ca42b2 | 2563 | |
2564 | if(!has42) | |
2565 | { | |
ee51a9fe | 2566 | checkWrongVersion (4, 2); |
01ca42b2 | 2567 | myGlVerMajor = 4; |
2568 | myGlVerMinor = 1; | |
2569 | return; | |
2570 | } | |
4e1523ef | 2571 | core42 = (OpenGl_GlCore42* )(&(*myFuncs)); |
2572 | if (!isCoreProfile) | |
2573 | { | |
2574 | core42back = (OpenGl_GlCore42Back* )(&(*myFuncs)); | |
2575 | } | |
01ca42b2 | 2576 | |
4e1523ef | 2577 | if (!has43) |
01ca42b2 | 2578 | { |
ee51a9fe | 2579 | checkWrongVersion (4, 3); |
01ca42b2 | 2580 | myGlVerMajor = 4; |
2581 | myGlVerMinor = 2; | |
2582 | return; | |
2583 | } | |
4e1523ef | 2584 | core43 = (OpenGl_GlCore43* )(&(*myFuncs)); |
2585 | if (!isCoreProfile) | |
2586 | { | |
2587 | core43back = (OpenGl_GlCore43Back* )(&(*myFuncs)); | |
2588 | } | |
01ca42b2 | 2589 | |
2590 | if (!has44) | |
2591 | { | |
ee51a9fe | 2592 | checkWrongVersion (4, 4); |
01ca42b2 | 2593 | myGlVerMajor = 4; |
2594 | myGlVerMinor = 3; | |
2595 | return; | |
5f8b738e | 2596 | } |
4e1523ef | 2597 | core44 = (OpenGl_GlCore44* )(&(*myFuncs)); |
2598 | if (!isCoreProfile) | |
2599 | { | |
2600 | core44back = (OpenGl_GlCore44Back* )(&(*myFuncs)); | |
2601 | } | |
ca3c13d1 | 2602 | #endif |
2166f0fa | 2603 | } |
f0430952 | 2604 | |
2605 | // ======================================================================= | |
2606 | // function : MemoryInfo | |
2607 | // purpose : | |
2608 | // ======================================================================= | |
2609 | Standard_Size OpenGl_Context::AvailableMemory() const | |
2610 | { | |
ca3c13d1 | 2611 | #if !defined(GL_ES_VERSION_2_0) |
f0430952 | 2612 | if (atiMem) |
2613 | { | |
2614 | // this is actually information for VBO pool | |
2615 | // however because pools are mostly shared | |
2616 | // it can be used for total GPU memory estimations | |
2617 | GLint aMemInfo[4]; | |
2618 | aMemInfo[0] = 0; | |
2619 | glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aMemInfo); | |
2620 | // returned value is in KiB, however this maybe changed in future | |
2621 | return Standard_Size(aMemInfo[0]) * 1024; | |
2622 | } | |
2623 | else if (nvxMem) | |
2624 | { | |
2625 | // current available dedicated video memory (in KiB), currently unused GPU memory | |
2626 | GLint aMemInfo = 0; | |
2627 | glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aMemInfo); | |
2628 | return Standard_Size(aMemInfo) * 1024; | |
2629 | } | |
ca3c13d1 | 2630 | #endif |
f0430952 | 2631 | return 0; |
2632 | } | |
2633 | ||
2634 | // ======================================================================= | |
2635 | // function : MemoryInfo | |
2636 | // purpose : | |
2637 | // ======================================================================= | |
2638 | TCollection_AsciiString OpenGl_Context::MemoryInfo() const | |
2639 | { | |
26d9c835 | 2640 | TColStd_IndexedDataMapOfStringString aDict; |
2641 | MemoryInfo (aDict); | |
2642 | ||
2643 | TCollection_AsciiString aText; | |
2644 | for (TColStd_IndexedDataMapOfStringString::Iterator anIter (aDict); anIter.More(); anIter.Next()) | |
2645 | { | |
2646 | if (!aText.IsEmpty()) | |
2647 | { | |
2648 | aText += "\n"; | |
2649 | } | |
2650 | aText += TCollection_AsciiString(" ") + anIter.Key() + ": " + anIter.Value(); | |
2651 | } | |
2652 | return aText; | |
2653 | } | |
2654 | ||
2655 | // ======================================================================= | |
2656 | // function : MemoryInfo | |
2657 | // purpose : | |
2658 | // ======================================================================= | |
2659 | void OpenGl_Context::MemoryInfo (TColStd_IndexedDataMapOfStringString& theDict) const | |
2660 | { | |
2661 | #if defined(GL_ES_VERSION_2_0) | |
2662 | (void )theDict; | |
2663 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
2664 | GLint aGlRendId = 0; | |
2665 | CGLGetParameter (CGLGetCurrentContext(), kCGLCPCurrentRendererID, &aGlRendId); | |
2666 | ||
2667 | CGLRendererInfoObj aRendObj = NULL; | |
2668 | CGOpenGLDisplayMask aDispMask = CGDisplayIDToOpenGLDisplayMask (kCGDirectMainDisplay); | |
2669 | GLint aRendNb = 0; | |
2670 | CGLQueryRendererInfo (aDispMask, &aRendObj, &aRendNb); | |
2671 | for (GLint aRendIter = 0; aRendIter < aRendNb; ++aRendIter) | |
2672 | { | |
2673 | GLint aRendId = 0; | |
2674 | if (CGLDescribeRenderer (aRendObj, aRendIter, kCGLRPRendererID, &aRendId) != kCGLNoError | |
2675 | || aRendId != aGlRendId) | |
2676 | { | |
2677 | continue; | |
2678 | } | |
2679 | ||
2680 | //kCGLRPVideoMemoryMegabytes = 131; | |
2681 | //kCGLRPTextureMemoryMegabytes = 132; | |
2682 | GLint aVMem = 0; | |
2683 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 | |
2684 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemoryMegabytes, &aVMem) == kCGLNoError) | |
2685 | { | |
2686 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + aVMem + " MiB"); | |
2687 | } | |
2688 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemoryMegabytes, &aVMem) == kCGLNoError) | |
2689 | { | |
2690 | addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + aVMem + " MiB"); | |
2691 | } | |
2692 | #else | |
2693 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemory, &aVMem) == kCGLNoError) | |
2694 | { | |
2695 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB"); | |
2696 | } | |
2697 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemory, &aVMem) == kCGLNoError) | |
2698 | { | |
2699 | addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB"); | |
2700 | } | |
2701 | #endif | |
2702 | } | |
2703 | #endif | |
2704 | ||
ca3c13d1 | 2705 | #if !defined(GL_ES_VERSION_2_0) |
f0430952 | 2706 | if (atiMem) |
2707 | { | |
2708 | GLint aValues[4]; | |
2709 | memset (aValues, 0, sizeof(aValues)); | |
2710 | glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues); | |
2711 | ||
2712 | // total memory free in the pool | |
26d9c835 | 2713 | addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValues[0] / 1024) + " MiB"); |
f0430952 | 2714 | |
26d9c835 | 2715 | if (aValues[1] != aValues[0]) |
2716 | { | |
2717 | // largest available free block in the pool | |
2718 | addInfo (theDict, "Largest free block", TCollection_AsciiString() + (aValues[1] / 1024) + " MiB"); | |
2719 | } | |
f0430952 | 2720 | if (aValues[2] != aValues[0]) |
2721 | { | |
2722 | // total auxiliary memory free | |
26d9c835 | 2723 | addInfo (theDict, "Free auxiliary memory", TCollection_AsciiString() + (aValues[2] / 1024) + " MiB"); |
f0430952 | 2724 | } |
2725 | } | |
2726 | else if (nvxMem) | |
2727 | { | |
2728 | //current available dedicated video memory (in KiB), currently unused GPU memory | |
2729 | GLint aValue = 0; | |
2730 | glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue); | |
26d9c835 | 2731 | addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValue / 1024) + " MiB"); |
f0430952 | 2732 | |
2733 | // dedicated video memory, total size (in KiB) of the GPU memory | |
2734 | GLint aDedicated = 0; | |
2735 | glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated); | |
26d9c835 | 2736 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aDedicated / 1024) + " MiB"); |
f0430952 | 2737 | |
2738 | // total available memory, total size (in KiB) of the memory available for allocations | |
2739 | glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue); | |
2740 | if (aValue != aDedicated) | |
2741 | { | |
2742 | // different only for special configurations | |
26d9c835 | 2743 | addInfo (theDict, "Total memory", TCollection_AsciiString() + (aValue / 1024) + " MiB"); |
2744 | } | |
2745 | } | |
2eacd0b8 | 2746 | #if defined(_WIN32) |
2747 | else if (myFuncs->wglGetGPUInfoAMD != NULL | |
2748 | && myFuncs->wglGetContextGPUIDAMD != NULL) | |
2749 | { | |
2750 | GLuint aTotalMemMiB = 0; | |
2751 | UINT anAmdId = myFuncs->wglGetContextGPUIDAMD ((HGLRC )myGContext); | |
2752 | if (anAmdId != 0) | |
2753 | { | |
2754 | if (myFuncs->wglGetGPUInfoAMD (anAmdId, WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(aTotalMemMiB), &aTotalMemMiB) > 0) | |
2755 | { | |
2756 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + (int )aTotalMemMiB + " MiB"); | |
2757 | } | |
2758 | } | |
2759 | } | |
2760 | #endif | |
26d9c835 | 2761 | #endif |
2762 | ||
2763 | #if !defined(GL_ES_VERSION_2_0) && !defined(__APPLE__) && !defined(_WIN32) | |
2764 | // GLX_RENDERER_VENDOR_ID_MESA | |
2765 | if (myFuncs->glXQueryCurrentRendererIntegerMESA != NULL) | |
2766 | { | |
2767 | unsigned int aVMemMiB = 0; | |
2768 | if (myFuncs->glXQueryCurrentRendererIntegerMESA (GLX_RENDERER_VIDEO_MEMORY_MESA, &aVMemMiB) != False) | |
2769 | { | |
2770 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + int(aVMemMiB) + " MiB"); | |
f0430952 | 2771 | } |
2772 | } | |
ca3c13d1 | 2773 | #endif |
f0430952 | 2774 | } |
5e27df78 | 2775 | |
26d9c835 | 2776 | // ======================================================================= |
2777 | // function : DiagnosticInfo | |
2778 | // purpose : | |
2779 | // ======================================================================= | |
2780 | void OpenGl_Context::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict, | |
2781 | Graphic3d_DiagnosticInfo theFlags) const | |
2782 | { | |
2783 | if ((theFlags & Graphic3d_DiagnosticInfo_NativePlatform) != 0) | |
2784 | { | |
2785 | #if defined(HAVE_EGL) | |
6cde53c4 | 2786 | addInfo (theDict, "EGLVersion", ::eglQueryString ((EGLDisplay )myDisplay, EGL_VERSION)); |
2787 | addInfo (theDict, "EGLVendor", ::eglQueryString ((EGLDisplay )myDisplay, EGL_VENDOR)); | |
2788 | addInfo (theDict, "EGLClientAPIs", ::eglQueryString ((EGLDisplay )myDisplay, EGL_CLIENT_APIS)); | |
26d9c835 | 2789 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) |
2790 | { | |
6cde53c4 | 2791 | addInfo (theDict, "EGLExtensions", ::eglQueryString ((EGLDisplay )myDisplay, EGL_EXTENSIONS)); |
26d9c835 | 2792 | } |
2793 | #elif defined(_WIN32) | |
2794 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0 | |
2795 | && myFuncs->wglGetExtensionsStringARB != NULL) | |
2796 | { | |
2797 | const char* aWglExts = myFuncs->wglGetExtensionsStringARB ((HDC )myWindowDC); | |
2798 | addInfo (theDict, "WGLExtensions", aWglExts); | |
2799 | } | |
2800 | #elif defined(__APPLE__) | |
2801 | // | |
2802 | #else | |
2803 | Display* aDisplay = (Display*)myDisplay; | |
2804 | const int aScreen = DefaultScreen(aDisplay); | |
2805 | addInfo (theDict, "GLXDirectRendering", ::glXIsDirect (aDisplay, (GLXContext )myGContext) ? "Yes" : "No"); | |
2806 | addInfo (theDict, "GLXVendor", ::glXQueryServerString (aDisplay, aScreen, GLX_VENDOR)); | |
2807 | addInfo (theDict, "GLXVersion", ::glXQueryServerString (aDisplay, aScreen, GLX_VERSION)); | |
2808 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) | |
2809 | { | |
2810 | const char* aGlxExts = ::glXQueryExtensionsString (aDisplay, aScreen); | |
2811 | addInfo(theDict, "GLXExtensions", aGlxExts); | |
2812 | } | |
2813 | ||
2814 | addInfo (theDict, "GLXClientVendor", ::glXGetClientString (aDisplay, GLX_VENDOR)); | |
2815 | addInfo (theDict, "GLXClientVersion", ::glXGetClientString (aDisplay, GLX_VERSION)); | |
2816 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) | |
2817 | { | |
2818 | addInfo (theDict, "GLXClientExtensions", ::glXGetClientString (aDisplay, GLX_EXTENSIONS)); | |
2819 | } | |
2820 | #endif | |
2821 | } | |
2822 | ||
2823 | if ((theFlags & Graphic3d_DiagnosticInfo_Device) != 0) | |
2824 | { | |
2825 | addInfo (theDict, "GLvendor", (const char*)::glGetString (GL_VENDOR)); | |
2826 | addInfo (theDict, "GLdevice", (const char*)::glGetString (GL_RENDERER)); | |
2827 | addInfo (theDict, "GLversion", (const char*)::glGetString (GL_VERSION)); | |
048e1b3b | 2828 | if (IsGlGreaterEqual (2, 0)) |
2829 | { | |
2830 | addInfo (theDict, "GLSLversion", (const char*)::glGetString (GL_SHADING_LANGUAGE_VERSION)); | |
2831 | } | |
26d9c835 | 2832 | if (myIsGlDebugCtx) |
2833 | { | |
2834 | addInfo (theDict, "GLdebug", "ON"); | |
2835 | } | |
2836 | } | |
2837 | ||
2838 | if ((theFlags & Graphic3d_DiagnosticInfo_Limits) != 0) | |
2839 | { | |
2840 | addInfo (theDict, "Max texture size", TCollection_AsciiString(myMaxTexDim)); | |
cc8cbabe | 2841 | addInfo (theDict, "Max combined texture units", TCollection_AsciiString(myMaxTexCombined)); |
26d9c835 | 2842 | addInfo (theDict, "Max MSAA samples", TCollection_AsciiString(myMaxMsaaSamples)); |
2843 | } | |
2844 | ||
2845 | if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0) | |
2846 | { | |
2847 | GLint aViewport[4] = {}; | |
2848 | ::glGetIntegerv (GL_VIEWPORT, aViewport); | |
2849 | addInfo (theDict, "Viewport", TCollection_AsciiString() + aViewport[2] + "x" + aViewport[3]); | |
2850 | } | |
2851 | ||
2852 | if ((theFlags & Graphic3d_DiagnosticInfo_Memory) != 0) | |
2853 | { | |
2854 | MemoryInfo (theDict); | |
2855 | } | |
2856 | ||
2857 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) | |
2858 | { | |
2859 | #if !defined(GL_ES_VERSION_2_0) | |
2860 | if (IsGlGreaterEqual (3, 0) | |
2861 | && myFuncs->glGetStringi != NULL) | |
2862 | { | |
2863 | TCollection_AsciiString anExtList; | |
2864 | GLint anExtNb = 0; | |
2865 | ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb); | |
2866 | for (GLint anIter = 0; anIter < anExtNb; ++anIter) | |
2867 | { | |
2868 | const char* anExtension = (const char*)myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint)anIter); | |
2869 | if (!anExtList.IsEmpty()) | |
2870 | { | |
2871 | anExtList += " "; | |
2872 | } | |
2873 | anExtList += anExtension; | |
2874 | } | |
2875 | addInfo(theDict, "GLextensions", anExtList); | |
2876 | } | |
2877 | else | |
2878 | #endif | |
2879 | { | |
2880 | addInfo (theDict, "GLextensions", (const char*)::glGetString (GL_EXTENSIONS)); | |
2881 | } | |
2882 | } | |
2883 | } | |
5e27df78 | 2884 | |
2885 | // ======================================================================= | |
2886 | // function : GetResource | |
2887 | // purpose : | |
2888 | // ======================================================================= | |
2889 | const Handle(OpenGl_Resource)& OpenGl_Context::GetResource (const TCollection_AsciiString& theKey) const | |
2890 | { | |
2891 | return mySharedResources->IsBound (theKey) ? mySharedResources->Find (theKey) : NULL_GL_RESOURCE; | |
2892 | } | |
2893 | ||
2894 | // ======================================================================= | |
2895 | // function : ShareResource | |
2896 | // purpose : | |
2897 | // ======================================================================= | |
2898 | Standard_Boolean OpenGl_Context::ShareResource (const TCollection_AsciiString& theKey, | |
2899 | const Handle(OpenGl_Resource)& theResource) | |
2900 | { | |
2901 | if (theKey.IsEmpty() || theResource.IsNull()) | |
2902 | { | |
2903 | return Standard_False; | |
2904 | } | |
2905 | return mySharedResources->Bind (theKey, theResource); | |
2906 | } | |
2907 | ||
2908 | // ======================================================================= | |
2909 | // function : ReleaseResource | |
2910 | // purpose : | |
2911 | // ======================================================================= | |
a174a3c5 | 2912 | void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey, |
2913 | const Standard_Boolean theToDelay) | |
5e27df78 | 2914 | { |
2915 | if (!mySharedResources->IsBound (theKey)) | |
2916 | { | |
2917 | return; | |
2918 | } | |
71c810df | 2919 | const Handle(OpenGl_Resource)& aRes = mySharedResources->Find (theKey); |
5e27df78 | 2920 | if (aRes->GetRefCount() > 1) |
2921 | { | |
2922 | return; | |
2923 | } | |
2924 | ||
a174a3c5 | 2925 | if (theToDelay) |
2926 | { | |
2927 | myDelayed->Bind (theKey, 1); | |
2928 | } | |
2929 | else | |
2930 | { | |
2931 | aRes->Release (this); | |
2932 | mySharedResources->UnBind (theKey); | |
2933 | } | |
5e27df78 | 2934 | } |
2935 | ||
2936 | // ======================================================================= | |
5e27df78 | 2937 | // function : ReleaseDelayed |
2938 | // purpose : | |
2939 | // ======================================================================= | |
2940 | void OpenGl_Context::ReleaseDelayed() | |
2941 | { | |
a174a3c5 | 2942 | // release queued elements |
3125ebb6 | 2943 | while (!myUnusedResources->IsEmpty()) |
5e27df78 | 2944 | { |
3125ebb6 | 2945 | myUnusedResources->First()->Release (this); |
2946 | myUnusedResources->RemoveFirst(); | |
5e27df78 | 2947 | } |
a174a3c5 | 2948 | |
265d4508 | 2949 | // release delayed shared resources |
a174a3c5 | 2950 | NCollection_Vector<TCollection_AsciiString> aDeadList; |
2951 | for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed); | |
2952 | anIter.More(); anIter.Next()) | |
2953 | { | |
2954 | if (++anIter.ChangeValue() <= 2) | |
2955 | { | |
2956 | continue; // postpone release one more frame to ensure noone use it periodically | |
2957 | } | |
2958 | ||
2959 | const TCollection_AsciiString& aKey = anIter.Key(); | |
2960 | if (!mySharedResources->IsBound (aKey)) | |
2961 | { | |
2962 | // mixed unshared strategy delayed/undelayed was used! | |
2963 | aDeadList.Append (aKey); | |
2964 | continue; | |
2965 | } | |
2966 | ||
71c810df | 2967 | const Handle(OpenGl_Resource)& aRes = mySharedResources->ChangeFind (aKey); |
a174a3c5 | 2968 | if (aRes->GetRefCount() > 1) |
2969 | { | |
2970 | // should be only 1 instance in mySharedResources | |
2971 | // if not - resource was reused again | |
2972 | aDeadList.Append (aKey); | |
2973 | continue; | |
2974 | } | |
2975 | ||
2976 | // release resource if no one requiested it more than 2 redraw calls | |
2977 | aRes->Release (this); | |
2978 | mySharedResources->UnBind (aKey); | |
2979 | aDeadList.Append (aKey); | |
2980 | } | |
2981 | ||
2982 | for (Standard_Integer anIter = 0; anIter < aDeadList.Length(); ++anIter) | |
2983 | { | |
2984 | myDelayed->UnBind (aDeadList.Value (anIter)); | |
2985 | } | |
5e27df78 | 2986 | } |
7d3e64ef | 2987 | |
cc8cbabe | 2988 | // ======================================================================= |
2989 | // function : BindTextures | |
2990 | // purpose : | |
2991 | // ======================================================================= | |
2992 | Handle(OpenGl_TextureSet) OpenGl_Context::BindTextures (const Handle(OpenGl_TextureSet)& theTextures) | |
2993 | { | |
2994 | if (myActiveTextures == theTextures) | |
2995 | { | |
2996 | return myActiveTextures; | |
2997 | } | |
2998 | ||
2999 | Handle(OpenGl_Context) aThisCtx (this); | |
3000 | OpenGl_TextureSet::Iterator aTextureIterOld (myActiveTextures), aTextureIterNew (theTextures); | |
3001 | for (;;) | |
3002 | { | |
3003 | if (!aTextureIterNew.More()) | |
3004 | { | |
3005 | for (; aTextureIterOld.More(); aTextureIterOld.Next()) | |
3006 | { | |
3007 | if (const Handle(OpenGl_Texture)& aTextureOld = aTextureIterOld.Value()) | |
3008 | { | |
3009 | #if !defined(GL_ES_VERSION_2_0) | |
3010 | if (core11 != NULL) | |
3011 | { | |
3012 | OpenGl_Sampler::resetGlobalTextureParams (aThisCtx, *aTextureOld, aTextureOld->Sampler()->Parameters()); | |
3013 | } | |
3014 | #endif | |
3015 | aTextureOld->Unbind (aThisCtx); | |
3016 | } | |
3017 | } | |
3018 | break; | |
3019 | } | |
3020 | ||
3021 | const Handle(OpenGl_Texture)& aTextureNew = aTextureIterNew.Value(); | |
3022 | if (aTextureIterOld.More()) | |
3023 | { | |
3024 | const Handle(OpenGl_Texture)& aTextureOld = aTextureIterOld.Value(); | |
3025 | if (aTextureNew == aTextureOld) | |
3026 | { | |
3027 | aTextureIterNew.Next(); | |
3028 | aTextureIterOld.Next(); | |
3029 | continue; | |
3030 | } | |
3031 | else if (aTextureNew.IsNull() | |
3032 | || !aTextureNew->IsValid()) | |
3033 | { | |
3034 | if (!aTextureOld.IsNull()) | |
3035 | { | |
3036 | #if !defined(GL_ES_VERSION_2_0) | |
3037 | if (core11 != NULL) | |
3038 | { | |
3039 | OpenGl_Sampler::resetGlobalTextureParams (aThisCtx, *aTextureOld, aTextureOld->Sampler()->Parameters()); | |
3040 | } | |
3041 | #endif | |
3042 | aTextureOld->Unbind (aThisCtx); | |
3043 | } | |
3044 | ||
3045 | aTextureIterNew.Next(); | |
3046 | aTextureIterOld.Next(); | |
3047 | continue; | |
3048 | } | |
3049 | ||
3050 | aTextureIterOld.Next(); | |
3051 | } | |
3052 | if (aTextureNew.IsNull()) | |
3053 | { | |
3054 | aTextureIterNew.Next(); | |
3055 | continue; | |
3056 | } | |
3057 | ||
3058 | const Graphic3d_TextureUnit aTexUnit = aTextureNew->Sampler()->Parameters()->TextureUnit(); | |
3059 | if (aTexUnit >= myMaxTexCombined) | |
3060 | { | |
3061 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, | |
3062 | TCollection_AsciiString("Texture unit ") + aTexUnit + " for " + aTextureNew->ResourceId() + " exceeds hardware limit " + myMaxTexCombined); | |
3063 | aTextureIterNew.Next(); | |
3064 | continue; | |
3065 | } | |
3066 | ||
3067 | aTextureNew->Bind (aThisCtx); | |
3068 | if (aTextureNew->Sampler()->ToUpdateParameters()) | |
3069 | { | |
3070 | if (aTextureNew->Sampler()->IsImmutable()) | |
3071 | { | |
3072 | aTextureNew->Sampler()->Init (aThisCtx, *aTextureNew); | |
3073 | } | |
3074 | else | |
3075 | { | |
3076 | OpenGl_Sampler::applySamplerParams (aThisCtx, aTextureNew->Sampler()->Parameters(), aTextureNew->Sampler().get(), aTextureNew->GetTarget(), aTextureNew->HasMipmaps()); | |
3077 | } | |
3078 | } | |
3079 | #if !defined(GL_ES_VERSION_2_0) | |
3080 | if (core11 != NULL) | |
3081 | { | |
3082 | OpenGl_Sampler::applyGlobalTextureParams (aThisCtx, *aTextureNew, aTextureNew->Sampler()->Parameters()); | |
3083 | } | |
3084 | #endif | |
3085 | aTextureIterNew.Next(); | |
3086 | } | |
3087 | ||
3088 | Handle(OpenGl_TextureSet) anOldTextures = myActiveTextures; | |
3089 | myActiveTextures = theTextures; | |
3090 | return anOldTextures; | |
3091 | } | |
3092 | ||
7d3e64ef | 3093 | // ======================================================================= |
3094 | // function : BindProgram | |
3095 | // purpose : | |
3096 | // ======================================================================= | |
8625ef7e | 3097 | Standard_Boolean OpenGl_Context::BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram) |
7d3e64ef | 3098 | { |
8625ef7e | 3099 | if (core20fwd == NULL) |
3100 | { | |
3101 | return Standard_False; | |
3102 | } | |
8613985b | 3103 | else if (myActiveProgram == theProgram) |
3104 | { | |
3105 | return Standard_True; | |
3106 | } | |
8625ef7e | 3107 | |
7d3e64ef | 3108 | if (theProgram.IsNull() |
3109 | || !theProgram->IsValid()) | |
3110 | { | |
3111 | if (!myActiveProgram.IsNull()) | |
3112 | { | |
3113 | core20fwd->glUseProgram (OpenGl_ShaderProgram::NO_PROGRAM); | |
3114 | myActiveProgram.Nullify(); | |
3115 | } | |
8625ef7e | 3116 | return Standard_False; |
7d3e64ef | 3117 | } |
3118 | ||
3119 | myActiveProgram = theProgram; | |
3120 | core20fwd->glUseProgram (theProgram->ProgramId()); | |
8625ef7e | 3121 | return Standard_True; |
3122 | } | |
3123 | ||
4e1523ef | 3124 | // ======================================================================= |
3125 | // function : BindDefaultVao | |
3126 | // purpose : | |
3127 | // ======================================================================= | |
3128 | void OpenGl_Context::BindDefaultVao() | |
3129 | { | |
3130 | #if !defined(GL_ES_VERSION_2_0) | |
3131 | if (myDefaultVao == 0 | |
3132 | || core32 == NULL) | |
3133 | { | |
3134 | return; | |
3135 | } | |
3136 | ||
3137 | core32->glBindVertexArray (myDefaultVao); | |
3138 | #endif | |
3139 | } | |
3140 | ||
a2e4f780 | 3141 | // ======================================================================= |
3142 | // function : SetDefaultFrameBuffer | |
3143 | // purpose : | |
3144 | // ======================================================================= | |
3145 | Handle(OpenGl_FrameBuffer) OpenGl_Context::SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo) | |
3146 | { | |
3147 | Handle(OpenGl_FrameBuffer) aFbo = myDefaultFbo; | |
3148 | myDefaultFbo = theFbo; | |
3149 | return aFbo; | |
3150 | } | |
3151 | ||
8625ef7e | 3152 | // ======================================================================= |
299e0ab9 | 3153 | // function : SetShadingMaterial |
3154 | // purpose : | |
3155 | // ======================================================================= | |
f9ba5c4d | 3156 | void OpenGl_Context::SetShadingMaterial (const OpenGl_AspectFace* theAspect, |
a1073ae2 | 3157 | const Handle(Graphic3d_PresentationAttributes)& theHighlight) |
299e0ab9 | 3158 | { |
8613985b | 3159 | const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull()) |
3160 | ? theHighlight->BasicFillAreaAspect() | |
3161 | : theAspect->Aspect(); | |
3162 | ||
3163 | const bool toDistinguish = anAspect->Distinguish(); | |
3164 | const bool toMapTexture = anAspect->ToMapTexture(); | |
3165 | const Graphic3d_MaterialAspect& aMatFrontSrc = anAspect->FrontMaterial(); | |
3166 | const Graphic3d_MaterialAspect& aMatBackSrc = toDistinguish | |
3167 | ? anAspect->BackMaterial() | |
3168 | : aMatFrontSrc; | |
3169 | const Quantity_Color& aFrontIntColor = anAspect->InteriorColor(); | |
3170 | const Quantity_Color& aBackIntColor = toDistinguish | |
3171 | ? anAspect->BackInteriorColor() | |
3172 | : aFrontIntColor; | |
3173 | ||
3174 | myMatFront.Init (aMatFrontSrc, aFrontIntColor); | |
3175 | if (toDistinguish) | |
3176 | { | |
3177 | myMatBack.Init (aMatBackSrc, aBackIntColor); | |
3178 | } | |
3179 | else | |
299e0ab9 | 3180 | { |
8613985b | 3181 | myMatBack = myMatFront; |
3182 | } | |
299e0ab9 | 3183 | |
8613985b | 3184 | if (!theHighlight.IsNull() |
3185 | && theHighlight->BasicFillAreaAspect().IsNull()) | |
3186 | { | |
3187 | myMatFront.SetColor (theHighlight->ColorRGBA()); | |
3188 | myMatBack .SetColor (theHighlight->ColorRGBA()); | |
8613985b | 3189 | } |
a1073ae2 | 3190 | |
a71a71de | 3191 | Standard_ShortReal anAlphaFront = 1.0f; |
3192 | Standard_ShortReal anAlphaBack = 1.0f; | |
3193 | if (CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack)) | |
8613985b | 3194 | { |
a71a71de | 3195 | myMatFront.Diffuse.a() = anAlphaFront; |
3196 | myMatBack .Diffuse.a() = anAlphaBack; | |
299e0ab9 | 3197 | } |
8613985b | 3198 | |
3199 | // do not update material properties in case of zero reflection mode, | |
3200 | // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway. | |
c40eb6b9 | 3201 | const OpenGl_MaterialState& aMatState = myShaderManager->MaterialState(); |
3202 | const float anAlphaCutoff = anAspect->AlphaMode() == Graphic3d_AlphaMode_Mask | |
3203 | ? anAspect->AlphaCutoff() | |
3204 | : ShortRealLast(); | |
dc89236f | 3205 | if (theAspect->ShadingModel() == Graphic3d_TOSM_UNLIT) |
8613985b | 3206 | { |
c40eb6b9 | 3207 | if (anAlphaCutoff == aMatState.AlphaCutoff()) |
3208 | { | |
3209 | return; | |
3210 | } | |
8613985b | 3211 | } |
c40eb6b9 | 3212 | else if (myMatFront == aMatState.FrontMaterial() |
3213 | && myMatBack == aMatState.BackMaterial() | |
3214 | && toDistinguish == aMatState.ToDistinguish() | |
3215 | && toMapTexture == aMatState.ToMapTexture() | |
3216 | && anAlphaCutoff == aMatState.AlphaCutoff()) | |
8613985b | 3217 | { |
3218 | return; | |
3219 | } | |
3220 | ||
c40eb6b9 | 3221 | myShaderManager->UpdateMaterialStateTo (myMatFront, myMatBack, anAlphaCutoff, toDistinguish, toMapTexture); |
299e0ab9 | 3222 | } |
3223 | ||
a1073ae2 | 3224 | // ======================================================================= |
3225 | // function : CheckIsTransparent | |
3226 | // purpose : | |
3227 | // ======================================================================= | |
3228 | Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_AspectFace* theAspect, | |
3229 | const Handle(Graphic3d_PresentationAttributes)& theHighlight, | |
a71a71de | 3230 | Standard_ShortReal& theAlphaFront, |
3231 | Standard_ShortReal& theAlphaBack) | |
a1073ae2 | 3232 | { |
3233 | const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull()) | |
3234 | ? theHighlight->BasicFillAreaAspect() | |
3235 | : theAspect->Aspect(); | |
3236 | ||
3237 | const bool toDistinguish = anAspect->Distinguish(); | |
3238 | const Graphic3d_MaterialAspect& aMatFrontSrc = anAspect->FrontMaterial(); | |
3239 | const Graphic3d_MaterialAspect& aMatBackSrc = toDistinguish | |
3240 | ? anAspect->BackMaterial() | |
3241 | : aMatFrontSrc; | |
3242 | ||
3243 | // handling transparency | |
a1073ae2 | 3244 | if (!theHighlight.IsNull() |
3245 | && theHighlight->BasicFillAreaAspect().IsNull()) | |
3246 | { | |
a71a71de | 3247 | theAlphaFront = theHighlight->ColorRGBA().Alpha(); |
3248 | theAlphaBack = theHighlight->ColorRGBA().Alpha(); | |
3249 | } | |
3250 | else | |
3251 | { | |
3252 | theAlphaFront = aMatFrontSrc.Alpha(); | |
3253 | theAlphaBack = aMatBackSrc .Alpha(); | |
a1073ae2 | 3254 | } |
3255 | ||
c40eb6b9 | 3256 | if (anAspect->AlphaMode() == Graphic3d_AlphaMode_BlendAuto) |
3257 | { | |
3258 | return theAlphaFront < 1.0f | |
3259 | || theAlphaBack < 1.0f; | |
3260 | } | |
3261 | return anAspect->AlphaMode() == Graphic3d_AlphaMode_Blend; | |
a1073ae2 | 3262 | } |
3263 | ||
299e0ab9 | 3264 | // ======================================================================= |
8625ef7e | 3265 | // function : SetColor4fv |
3266 | // purpose : | |
3267 | // ======================================================================= | |
3268 | void OpenGl_Context::SetColor4fv (const OpenGl_Vec4& theColor) | |
3269 | { | |
3270 | if (!myActiveProgram.IsNull()) | |
3271 | { | |
3272 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_COLOR), theColor); | |
3273 | } | |
3274 | #if !defined(GL_ES_VERSION_2_0) | |
3275 | else if (core11 != NULL) | |
3276 | { | |
3277 | core11->glColor4fv (theColor.GetData()); | |
3278 | } | |
3279 | #endif | |
3280 | } | |
3281 | ||
ac116c22 | 3282 | // ======================================================================= |
3283 | // function : SetTypeOfLine | |
3284 | // purpose : | |
3285 | // ======================================================================= | |
3286 | void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType, | |
3287 | const Standard_ShortReal theFactor) | |
3288 | { | |
3289 | Standard_Integer aPattern = 0xFFFF; | |
3290 | switch (theType) | |
3291 | { | |
3292 | case Aspect_TOL_DASH: | |
3293 | { | |
3294 | aPattern = 0xFFC0; | |
3295 | break; | |
3296 | } | |
3297 | case Aspect_TOL_DOT: | |
3298 | { | |
3299 | aPattern = 0xCCCC; | |
3300 | break; | |
3301 | } | |
3302 | case Aspect_TOL_DOTDASH: | |
3303 | { | |
3304 | aPattern = 0xFF18; | |
3305 | break; | |
3306 | } | |
3a4a3962 | 3307 | case Aspect_TOL_EMPTY: |
ac116c22 | 3308 | case Aspect_TOL_SOLID: |
3309 | { | |
3310 | aPattern = 0xFFFF; | |
3311 | break; | |
3312 | } | |
3313 | case Aspect_TOL_USERDEFINED: | |
3314 | { | |
3315 | aPattern = 0xFF24; | |
3316 | break; | |
3317 | } | |
3318 | } | |
3319 | ||
c04c30b3 | 3320 | if (!myActiveProgram.IsNull()) |
ac116c22 | 3321 | { |
3322 | myActiveProgram->SetUniform (this, "uPattern", aPattern); | |
3323 | myActiveProgram->SetUniform (this, "uFactor", theFactor); | |
3324 | return; | |
3325 | } | |
3326 | ||
3327 | #if !defined(GL_ES_VERSION_2_0) | |
3a4a3962 | 3328 | if (aPattern != 0xFFFF) |
ac116c22 | 3329 | { |
ac116c22 | 3330 | if (core11 != NULL) |
3331 | { | |
3332 | core11fwd->glEnable (GL_LINE_STIPPLE); | |
3333 | ||
3334 | core11->glLineStipple (static_cast<GLint> (theFactor), | |
3335 | static_cast<GLushort> (aPattern)); | |
3336 | } | |
3337 | } | |
3338 | else | |
3339 | { | |
3340 | if (core11 != NULL) | |
3341 | { | |
3342 | core11fwd->glDisable (GL_LINE_STIPPLE); | |
3343 | } | |
ac116c22 | 3344 | } |
3345 | #endif | |
3346 | } | |
3347 | ||
3348 | // ======================================================================= | |
3349 | // function : SetLineWidth | |
3350 | // purpose : | |
3351 | // ======================================================================= | |
3352 | void OpenGl_Context::SetLineWidth (const Standard_ShortReal theWidth) | |
3353 | { | |
3354 | if (core11 != NULL) | |
3355 | { | |
3356 | // glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f | |
56689b27 | 3357 | core11fwd->glLineWidth (theWidth * myLineWidthScale); |
ac116c22 | 3358 | } |
ac116c22 | 3359 | } |
3360 | ||
79f4f036 | 3361 | // ======================================================================= |
3362 | // function : SetTextureMatrix | |
3363 | // purpose : | |
3364 | // ======================================================================= | |
3365 | void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams) | |
3366 | { | |
3367 | if (theParams.IsNull()) | |
3368 | { | |
3369 | return; | |
3370 | } | |
3371 | else if (!myActiveProgram.IsNull()) | |
3372 | { | |
3373 | const GLint aUniLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_TRSF2D); | |
3374 | if (aUniLoc == OpenGl_ShaderProgram::INVALID_LOCATION) | |
3375 | { | |
3376 | return; | |
3377 | } | |
3378 | ||
3379 | // pack transformation parameters | |
bc379358 | 3380 | OpenGl_Vec4 aTrsf[2] = |
3381 | { | |
3382 | OpenGl_Vec4 (-theParams->Translation().x(), | |
3383 | -theParams->Translation().y(), | |
3384 | theParams->Scale().x(), | |
3385 | theParams->Scale().y()), | |
3386 | OpenGl_Vec4 (static_cast<float> (std::sin (-theParams->Rotation() * M_PI / 180.0)), | |
3387 | static_cast<float> (std::cos (-theParams->Rotation() * M_PI / 180.0)), | |
3388 | 0.0f, 0.0f) | |
3389 | }; | |
79f4f036 | 3390 | myActiveProgram->SetUniform (this, aUniLoc, 2, aTrsf); |
3391 | return; | |
3392 | } | |
3393 | ||
3394 | #if !defined(GL_ES_VERSION_2_0) | |
3395 | if (core11 != NULL) | |
3396 | { | |
3397 | GLint aMatrixMode = GL_TEXTURE; | |
3398 | ::glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode); | |
3399 | ||
3400 | core11->glMatrixMode (GL_TEXTURE); | |
3401 | OpenGl_Mat4 aTextureMat; | |
3402 | const Graphic3d_Vec2& aScale = theParams->Scale(); | |
3403 | const Graphic3d_Vec2& aTrans = theParams->Translation(); | |
3404 | Graphic3d_TransformUtils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f); | |
3405 | Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f); | |
3406 | Graphic3d_TransformUtils::Rotate (aTextureMat, -theParams->Rotation(), 0.0f, 0.0f, 1.0f); | |
3407 | core11->glLoadMatrixf (aTextureMat); | |
3408 | core11->glMatrixMode (aMatrixMode); | |
3409 | } | |
3410 | #endif | |
3411 | } | |
3412 | ||
8625ef7e | 3413 | // ======================================================================= |
3414 | // function : SetPointSize | |
3415 | // purpose : | |
3416 | // ======================================================================= | |
3417 | void OpenGl_Context::SetPointSize (const Standard_ShortReal theSize) | |
3418 | { | |
3419 | if (!myActiveProgram.IsNull()) | |
3420 | { | |
3421 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_POINT_SIZE), theSize); | |
3422 | #if !defined(GL_ES_VERSION_2_0) | |
3423 | //myContext->core11fwd->glEnable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
3424 | #endif | |
3425 | } | |
3426 | #if !defined(GL_ES_VERSION_2_0) | |
3427 | //else | |
3428 | { | |
3429 | core11fwd->glPointSize (theSize); | |
3430 | if (core20fwd != NULL) | |
3431 | { | |
3432 | //myContext->core11fwd->glDisable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
3433 | } | |
3434 | } | |
3435 | #endif | |
7d3e64ef | 3436 | } |
7d9e854b | 3437 | |
fd59283a | 3438 | // ======================================================================= |
3439 | // function : SetPointSpriteOrigin | |
3440 | // purpose : | |
3441 | // ======================================================================= | |
3442 | void OpenGl_Context::SetPointSpriteOrigin() | |
3443 | { | |
3444 | #if !defined(GL_ES_VERSION_2_0) | |
3445 | if (core15fwd == NULL) | |
3446 | { | |
3447 | return; | |
3448 | } | |
3449 | ||
3450 | const int aNewState = !myActiveProgram.IsNull() ? GL_UPPER_LEFT : GL_LOWER_LEFT; | |
3451 | if (myPointSpriteOrig != aNewState) | |
3452 | { | |
3453 | myPointSpriteOrig = aNewState; | |
3454 | core15fwd->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, aNewState); | |
3455 | } | |
3456 | #endif | |
3457 | } | |
3458 | ||
7d9e854b | 3459 | // ======================================================================= |
3460 | // function : SetGlNormalizeEnabled | |
3461 | // purpose : | |
3462 | // ======================================================================= | |
3463 | Standard_Boolean OpenGl_Context::SetGlNormalizeEnabled (Standard_Boolean isEnabled) | |
3464 | { | |
3465 | if (isEnabled == myIsGlNormalizeEnabled) | |
3466 | { | |
3467 | return myIsGlNormalizeEnabled; | |
3468 | } | |
3469 | ||
3470 | Standard_Boolean anOldGlNormalize = myIsGlNormalizeEnabled; | |
3471 | ||
3472 | myIsGlNormalizeEnabled = isEnabled; | |
3473 | ||
3474 | #if !defined(GL_ES_VERSION_2_0) | |
39070532 | 3475 | if (core11 != NULL) |
7d9e854b | 3476 | { |
39070532 | 3477 | if (isEnabled) |
3478 | { | |
3479 | ::glEnable (GL_NORMALIZE); | |
3480 | } | |
3481 | else | |
3482 | { | |
3483 | ::glDisable (GL_NORMALIZE); | |
3484 | } | |
7d9e854b | 3485 | } |
3486 | #endif | |
3487 | ||
3488 | return anOldGlNormalize; | |
3489 | } | |
c827ea3a | 3490 | |
6d0e6be5 | 3491 | // ======================================================================= |
3492 | // function : SetPolygonMode | |
3493 | // purpose : | |
3494 | // ======================================================================= | |
3495 | Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode) | |
3496 | { | |
3497 | if (myPolygonMode == theMode) | |
3498 | { | |
3499 | return myPolygonMode; | |
3500 | } | |
3501 | ||
3502 | const Standard_Integer anOldPolygonMode = myPolygonMode; | |
3503 | ||
3504 | myPolygonMode = theMode; | |
3505 | ||
3506 | #if !defined(GL_ES_VERSION_2_0) | |
3507 | ::glPolygonMode (GL_FRONT_AND_BACK, (GLenum)theMode); | |
3508 | #endif | |
3509 | ||
3510 | return anOldPolygonMode; | |
3511 | } | |
3512 | ||
3513 | // ======================================================================= | |
3514 | // function : SetPolygonHatchEnabled | |
3515 | // purpose : | |
3516 | // ======================================================================= | |
3517 | bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled) | |
3518 | { | |
3519 | if (myHatchStyles.IsNull()) | |
3520 | { | |
3521 | return false; | |
3522 | } | |
3523 | else if (myHatchStyles->IsEnabled() == theIsEnabled) | |
3524 | { | |
3525 | return theIsEnabled; | |
3526 | } | |
3527 | ||
3528 | return myHatchStyles->SetEnabled (this, theIsEnabled); | |
3529 | } | |
3530 | ||
3531 | // ======================================================================= | |
3532 | // function : SetPolygonHatchStyle | |
3533 | // purpose : | |
3534 | // ======================================================================= | |
640d5fe2 | 3535 | Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) |
6d0e6be5 | 3536 | { |
ec7c343f | 3537 | if (theStyle.IsNull()) |
3538 | { | |
3539 | return 0; | |
3540 | } | |
3541 | ||
6d0e6be5 | 3542 | if (myHatchStyles.IsNull()) |
3543 | { | |
3544 | if (!GetResource ("OpenGl_LineAttributes", myHatchStyles)) | |
3545 | { | |
3546 | // share and register for release once the resource is no longer used | |
3547 | myHatchStyles = new OpenGl_LineAttributes(); | |
3548 | ShareResource ("OpenGl_LineAttributes", myHatchStyles); | |
6d0e6be5 | 3549 | } |
3550 | } | |
640d5fe2 | 3551 | if (myHatchStyles->TypeOfHatch() == theStyle->HatchType()) |
6d0e6be5 | 3552 | { |
640d5fe2 | 3553 | return theStyle->HatchType(); |
6d0e6be5 | 3554 | } |
3555 | ||
640d5fe2 | 3556 | return myHatchStyles->SetTypeOfHatch (this, theStyle); |
6d0e6be5 | 3557 | } |
3558 | ||
8d1a539c | 3559 | // ======================================================================= |
3560 | // function : SetPolygonOffset | |
3561 | // purpose : | |
3562 | // ======================================================================= | |
3563 | void OpenGl_Context::SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset) | |
3564 | { | |
3565 | const bool toFillOld = (myPolygonOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill; | |
3566 | const bool toFillNew = (theOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill; | |
3567 | if (toFillNew != toFillOld) | |
3568 | { | |
3569 | if (toFillNew) | |
3570 | { | |
3571 | glEnable (GL_POLYGON_OFFSET_FILL); | |
3572 | } | |
3573 | else | |
3574 | { | |
3575 | glDisable (GL_POLYGON_OFFSET_FILL); | |
3576 | } | |
3577 | } | |
3578 | ||
3579 | #if !defined(GL_ES_VERSION_2_0) | |
3580 | const bool toLineOld = (myPolygonOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line; | |
3581 | const bool toLineNew = (theOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line; | |
3582 | if (toLineNew != toLineOld) | |
3583 | { | |
3584 | if (toLineNew) | |
3585 | { | |
3586 | glEnable (GL_POLYGON_OFFSET_LINE); | |
3587 | } | |
3588 | else | |
3589 | { | |
3590 | glDisable (GL_POLYGON_OFFSET_LINE); | |
3591 | } | |
3592 | } | |
3593 | ||
3594 | const bool toPointOld = (myPolygonOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point; | |
3595 | const bool toPointNew = (theOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point; | |
3596 | if (toPointNew != toPointOld) | |
3597 | { | |
3598 | if (toPointNew) | |
3599 | { | |
3600 | glEnable (GL_POLYGON_OFFSET_POINT); | |
3601 | } | |
3602 | else | |
3603 | { | |
3604 | glDisable (GL_POLYGON_OFFSET_POINT); | |
3605 | } | |
3606 | } | |
3607 | #endif | |
3608 | ||
3609 | if (myPolygonOffset.Factor != theOffset.Factor | |
3610 | || myPolygonOffset.Units != theOffset.Units) | |
3611 | { | |
3612 | glPolygonOffset (theOffset.Factor, theOffset.Units); | |
3613 | } | |
3614 | myPolygonOffset = theOffset; | |
3615 | } | |
3616 | ||
c827ea3a | 3617 | // ======================================================================= |
3618 | // function : ApplyModelWorldMatrix | |
3619 | // purpose : | |
3620 | // ======================================================================= | |
3621 | void OpenGl_Context::ApplyModelWorldMatrix() | |
3622 | { | |
8613985b | 3623 | if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current()) |
c827ea3a | 3624 | { |
3625 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); | |
3626 | } | |
3627 | } | |
3628 | ||
3629 | // ======================================================================= | |
3630 | // function : ApplyWorldViewMatrix | |
3631 | // purpose : | |
3632 | // ======================================================================= | |
3633 | void OpenGl_Context::ApplyWorldViewMatrix() | |
3634 | { | |
8613985b | 3635 | if (myShaderManager->ModelWorldState().ModelWorldMatrix() != THE_IDENTITY_MATRIX) |
c827ea3a | 3636 | { |
8613985b | 3637 | myShaderManager->UpdateModelWorldStateTo (THE_IDENTITY_MATRIX); |
c827ea3a | 3638 | } |
8613985b | 3639 | if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current()) |
c827ea3a | 3640 | { |
3641 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); | |
3642 | } | |
3643 | } | |
3644 | ||
3645 | // ======================================================================= | |
3646 | // function : ApplyModelViewMatrix | |
3647 | // purpose : | |
3648 | // ======================================================================= | |
3649 | void OpenGl_Context::ApplyModelViewMatrix() | |
3650 | { | |
8613985b | 3651 | if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current()) |
c827ea3a | 3652 | { |
8613985b | 3653 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); |
c827ea3a | 3654 | } |
8613985b | 3655 | if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current()) |
c827ea3a | 3656 | { |
8613985b | 3657 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); |
c827ea3a | 3658 | } |
3659 | } | |
3660 | ||
3661 | // ======================================================================= | |
3662 | // function : ApplyProjectionMatrix | |
3663 | // purpose : | |
3664 | // ======================================================================= | |
3665 | void OpenGl_Context::ApplyProjectionMatrix() | |
3666 | { | |
8613985b | 3667 | if (myShaderManager->ProjectionState().ProjectionMatrix() != ProjectionState.Current()) |
c827ea3a | 3668 | { |
3669 | myShaderManager->UpdateProjectionStateTo (ProjectionState.Current()); | |
3670 | } | |
3671 | } | |
c357e426 | 3672 | |
c357e426 | 3673 | // ======================================================================= |
3674 | // function : EnableFeatures | |
3675 | // purpose : | |
3676 | // ======================================================================= | |
3677 | void OpenGl_Context::EnableFeatures() const | |
3678 | { | |
3679 | // | |
3680 | } | |
3681 | ||
3682 | // ======================================================================= | |
3683 | // function : DisableFeatures | |
3684 | // purpose : | |
3685 | // ======================================================================= | |
3686 | void OpenGl_Context::DisableFeatures() const | |
3687 | { | |
a0b49de4 | 3688 | // Disable stuff that's likely to slow down glDrawPixels. |
c357e426 | 3689 | glDisable(GL_DITHER); |
3690 | glDisable(GL_BLEND); | |
3691 | glDisable(GL_DEPTH_TEST); | |
c357e426 | 3692 | glDisable(GL_STENCIL_TEST); |
3693 | ||
3694 | #if !defined(GL_ES_VERSION_2_0) | |
a0b49de4 | 3695 | if (core11 == NULL) |
3696 | { | |
3697 | return; | |
3698 | } | |
3699 | ||
3700 | glDisable(GL_TEXTURE_1D); | |
3701 | glDisable(GL_TEXTURE_2D); | |
3702 | ||
c357e426 | 3703 | glDisable(GL_LIGHTING); |
3704 | glDisable(GL_ALPHA_TEST); | |
3705 | glDisable(GL_FOG); | |
3706 | glDisable(GL_LOGIC_OP); | |
c357e426 | 3707 | |
3708 | glPixelTransferi(GL_MAP_COLOR, GL_FALSE); | |
3709 | glPixelTransferi(GL_RED_SCALE, 1); | |
3710 | glPixelTransferi(GL_RED_BIAS, 0); | |
3711 | glPixelTransferi(GL_GREEN_SCALE, 1); | |
3712 | glPixelTransferi(GL_GREEN_BIAS, 0); | |
3713 | glPixelTransferi(GL_BLUE_SCALE, 1); | |
3714 | glPixelTransferi(GL_BLUE_BIAS, 0); | |
3715 | glPixelTransferi(GL_ALPHA_SCALE, 1); | |
3716 | glPixelTransferi(GL_ALPHA_BIAS, 0); | |
3717 | ||
c357e426 | 3718 | if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2)) |
3719 | { | |
c357e426 | 3720 | if (CheckExtension ("GL_CONVOLUTION_1D_EXT")) |
3721 | glDisable(GL_CONVOLUTION_1D_EXT); | |
3722 | ||
3723 | if (CheckExtension ("GL_CONVOLUTION_2D_EXT")) | |
3724 | glDisable(GL_CONVOLUTION_2D_EXT); | |
3725 | ||
3726 | if (CheckExtension ("GL_SEPARABLE_2D_EXT")) | |
3727 | glDisable(GL_SEPARABLE_2D_EXT); | |
c357e426 | 3728 | |
c357e426 | 3729 | if (CheckExtension ("GL_SEPARABLE_2D_EXT")) |
3730 | glDisable(GL_HISTOGRAM_EXT); | |
3731 | ||
3732 | if (CheckExtension ("GL_MINMAX_EXT")) | |
3733 | glDisable(GL_MINMAX_EXT); | |
c357e426 | 3734 | |
c357e426 | 3735 | if (CheckExtension ("GL_TEXTURE_3D_EXT")) |
3736 | glDisable(GL_TEXTURE_3D_EXT); | |
c357e426 | 3737 | } |
3738 | #endif | |
3739 | } | |
f88457e6 | 3740 | |
3741 | // ======================================================================= | |
3742 | // function : SetColorMask | |
3743 | // purpose : | |
3744 | // ======================================================================= | |
3745 | bool OpenGl_Context::SetColorMask (bool theToWriteColor) | |
3746 | { | |
3747 | const GLboolean toWrite = theToWriteColor ? GL_TRUE : GL_FALSE; | |
3748 | glColorMask (toWrite, toWrite, toWrite, toWrite); | |
3749 | ||
3750 | const bool anOldValue = myColorMask; | |
3751 | myColorMask = theToWriteColor; | |
3752 | return anOldValue; | |
3753 | } | |
c40eb6b9 | 3754 | |
3755 | // ======================================================================= | |
3756 | // function : SetSampleAlphaToCoverage | |
3757 | // purpose : | |
3758 | // ======================================================================= | |
3759 | bool OpenGl_Context::SetSampleAlphaToCoverage (bool theToEnable) | |
3760 | { | |
3761 | if (myAlphaToCoverage == theToEnable) | |
3762 | { | |
3763 | return myAlphaToCoverage; | |
3764 | } | |
3765 | ||
3766 | if (core15fwd != NULL) | |
3767 | { | |
3768 | if (theToEnable) | |
3769 | { | |
3770 | //core15fwd->core15fwd->glSampleCoverage (1.0f, GL_FALSE); | |
3771 | core15fwd->glEnable (GL_SAMPLE_ALPHA_TO_COVERAGE); | |
3772 | } | |
3773 | else | |
3774 | { | |
3775 | core15fwd->glDisable (GL_SAMPLE_ALPHA_TO_COVERAGE); | |
3776 | } | |
3777 | } | |
3778 | ||
3779 | const bool anOldValue = myAlphaToCoverage; | |
3780 | myAlphaToCoverage = theToEnable; | |
3781 | return anOldValue; | |
3782 | } |