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 | ||
ac116c22 | 66 | #ifdef HAVE_GL2PS |
67 | #include <gl2ps.h> | |
68 | #ifdef _MSC_VER | |
69 | #pragma comment (lib, "gl2ps.lib") | |
70 | #endif | |
71 | #endif | |
72 | ||
2166f0fa | 73 | |
5e27df78 | 74 | namespace |
75 | { | |
76 | static const Handle(OpenGl_Resource) NULL_GL_RESOURCE; | |
458e3c0d | 77 | static const OpenGl_Mat4 THE_IDENTITY_MATRIX; |
26d9c835 | 78 | |
79 | //! Add key-value pair to the dictionary. | |
80 | static void addInfo (TColStd_IndexedDataMapOfStringString& theDict, | |
81 | const TCollection_AsciiString& theKey, | |
82 | const TCollection_AsciiString& theValue) | |
83 | { | |
84 | theDict.ChangeFromIndex (theDict.Add (theKey, theValue)) = theValue; | |
85 | } | |
86 | ||
87 | //! Add key-value pair to the dictionary. | |
88 | static void addInfo (TColStd_IndexedDataMapOfStringString& theDict, | |
89 | const TCollection_AsciiString& theKey, | |
90 | const char* theValue) | |
91 | { | |
92 | TCollection_AsciiString aValue (theValue != NULL ? theValue : ""); | |
93 | theDict.ChangeFromIndex (theDict.Add (theKey, aValue)) = aValue; | |
94 | } | |
01ca42b2 | 95 | } |
5e27df78 | 96 | |
2166f0fa SK |
97 | // ======================================================================= |
98 | // function : OpenGl_Context | |
99 | // purpose : | |
100 | // ======================================================================= | |
58655684 | 101 | OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps) |
01ca42b2 | 102 | : core11 (NULL), |
103 | core11fwd (NULL), | |
104 | core15 (NULL), | |
105 | core15fwd (NULL), | |
106 | core20 (NULL), | |
107 | core20fwd (NULL), | |
108 | core32 (NULL), | |
109 | core32back (NULL), | |
25ef750e | 110 | core33 (NULL), |
111 | core33back (NULL), | |
01ca42b2 | 112 | core41 (NULL), |
113 | core41back (NULL), | |
114 | core42 (NULL), | |
115 | core42back (NULL), | |
116 | core43 (NULL), | |
117 | core43back (NULL), | |
118 | core44 (NULL), | |
119 | core44back (NULL), | |
58655684 | 120 | caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()), |
ca3c13d1 | 121 | #if defined(GL_ES_VERSION_2_0) |
122 | hasHighp (Standard_False), | |
e99a2f7c | 123 | hasUintIndex(Standard_False), |
ca3c13d1 | 124 | hasTexRGBA8(Standard_False), |
125 | #else | |
126 | hasHighp (Standard_True), | |
e99a2f7c | 127 | hasUintIndex(Standard_True), |
ca3c13d1 | 128 | hasTexRGBA8(Standard_True), |
129 | #endif | |
a1073ae2 | 130 | hasDrawBuffers (OpenGl_FeatureNotAvailable), |
131 | hasFloatBuffer (OpenGl_FeatureNotAvailable), | |
132 | hasHalfFloatBuffer (OpenGl_FeatureNotAvailable), | |
133 | hasSampleVariables (OpenGl_FeatureNotAvailable), | |
134 | arbDrawBuffers (Standard_False), | |
25ef750e | 135 | arbNPTW (Standard_False), |
136 | arbTexRG (Standard_False), | |
74fb257d | 137 | arbTexFloat (Standard_False), |
cc8cbabe | 138 | arbSamplerObject (NULL), |
25ef750e | 139 | arbTexBindless (NULL), |
5e27df78 | 140 | arbTBO (NULL), |
25ef750e | 141 | arbTboRGB32 (Standard_False), |
5e27df78 | 142 | arbIns (NULL), |
58655684 | 143 | arbDbg (NULL), |
01ca42b2 | 144 | arbFBO (NULL), |
b86bb3df | 145 | arbFBOBlit (NULL), |
a1073ae2 | 146 | arbSampleShading (Standard_False), |
1ce0716b | 147 | extFragDepth (Standard_False), |
a1073ae2 | 148 | extDrawBuffers (Standard_False), |
37eb4787 | 149 | extGS (NULL), |
bf75be98 | 150 | extBgra(Standard_False), |
151 | extAnis(Standard_False), | |
30f0ad28 | 152 | extPDS (Standard_False), |
f0430952 | 153 | atiMem (Standard_False), |
154 | nvxMem (Standard_False), | |
a1073ae2 | 155 | oesSampleVariables (Standard_False), |
8c3237d4 | 156 | oesStdDerivatives (Standard_False), |
5e27df78 | 157 | mySharedResources (new OpenGl_ResourcesMap()), |
a174a3c5 | 158 | myDelayed (new OpenGl_DelayReleaseMap()), |
3125ebb6 | 159 | myUnusedResources (new OpenGl_ResourcesStack()), |
4269bd1b | 160 | myClippingState (), |
5f8b738e | 161 | myGlLibHandle (NULL), |
01ca42b2 | 162 | myFuncs (new OpenGl_GlFunctions()), |
2f6cb3ac | 163 | myAnisoMax (1), |
ca3c13d1 | 164 | myTexClamp (GL_CLAMP_TO_EDGE), |
eafb234b | 165 | myMaxTexDim (1024), |
cc8cbabe | 166 | myMaxTexCombined (1), |
4269bd1b | 167 | myMaxClipPlanes (6), |
3c4b62a4 | 168 | myMaxMsaaSamples(0), |
a1073ae2 | 169 | myMaxDrawBuffers (1), |
170 | myMaxColorAttachments (1), | |
5f8b738e | 171 | myGlVerMajor (0), |
172 | myGlVerMinor (0), | |
b5ac8292 | 173 | myIsInitialized (Standard_False), |
174 | myIsStereoBuffers (Standard_False), | |
7d9e854b | 175 | myIsGlNormalizeEnabled (Standard_False), |
3a9b5dc8 | 176 | myHasRayTracing (Standard_False), |
177 | myHasRayTracingTextures (Standard_False), | |
178 | myHasRayTracingAdaptiveSampling (Standard_False), | |
15669413 | 179 | myFrameStats (new OpenGl_FrameStats()), |
ca3c13d1 | 180 | #if !defined(GL_ES_VERSION_2_0) |
fd59283a | 181 | myPointSpriteOrig (GL_UPPER_LEFT), |
7d3e64ef | 182 | myRenderMode (GL_RENDER), |
6d0e6be5 | 183 | myPolygonMode (GL_FILL), |
ca3c13d1 | 184 | #else |
fd59283a | 185 | myPointSpriteOrig (0), |
ca3c13d1 | 186 | myRenderMode (0), |
6d0e6be5 | 187 | myPolygonMode (0), |
ca3c13d1 | 188 | #endif |
b6472664 | 189 | myToCullBackFaces (false), |
38a0206f | 190 | myReadBuffer (0), |
a1073ae2 | 191 | myDrawBuffers (1), |
4e1523ef | 192 | myDefaultVao (0), |
f88457e6 | 193 | myColorMask (true), |
75c262a9 | 194 | myIsGlDebugCtx (Standard_False), |
56689b27 | 195 | myResolution (Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION), |
196 | myResolutionRatio (1.0f), | |
197 | myLineWidthScale (1.0f), | |
198 | myRenderScale (1.0f), | |
199 | myRenderScaleInv (1.0f) | |
2166f0fa | 200 | { |
3bffef55 | 201 | myViewport[0] = 0; |
202 | myViewport[1] = 0; | |
203 | myViewport[2] = 0; | |
204 | myViewport[3] = 0; | |
56689b27 | 205 | myViewportVirt[0] = 0; |
206 | myViewportVirt[1] = 0; | |
207 | myViewportVirt[2] = 0; | |
208 | myViewportVirt[3] = 0; | |
3bffef55 | 209 | |
8d1a539c | 210 | myPolygonOffset.Mode = Aspect_POM_Off; |
211 | myPolygonOffset.Factor = 0.0f; | |
212 | myPolygonOffset.Units = 0.0f; | |
213 | ||
4e1523ef | 214 | // system-dependent fields |
215 | #if defined(HAVE_EGL) | |
216 | myDisplay = (Aspect_Display )EGL_NO_DISPLAY; | |
217 | myWindow = (Aspect_Drawable )EGL_NO_SURFACE; | |
458c2c58 | 218 | myGContext = (Aspect_RenderingContext )EGL_NO_CONTEXT; |
4e1523ef | 219 | #elif defined(_WIN32) |
220 | myWindow = NULL; | |
221 | myWindowDC = NULL; | |
222 | myGContext = NULL; | |
223 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
5f8b738e | 224 | // Vendors can not extend functionality on this system |
225 | // and developers are limited to OpenGL support provided by Mac OS X SDK. | |
226 | // We retrieve function pointers from system library | |
227 | // to generalize extensions support on all platforms. | |
228 | // In this way we also reach binary compatibility benefit between OS releases | |
229 | // if some newest functionality is optionally used. | |
230 | // Notice that GL version / extension availability checks are required | |
231 | // because function pointers may be available but not functionality itself | |
232 | // (depends on renderer). | |
a2e4f780 | 233 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
234 | myGContext = NULL; | |
235 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY); | |
236 | #else | |
4e1523ef | 237 | myGContext = NULL; |
5f8b738e | 238 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY); |
a2e4f780 | 239 | #endif |
4e1523ef | 240 | #else |
241 | myDisplay = NULL; | |
242 | myWindow = 0; | |
243 | myGContext = 0; | |
5f8b738e | 244 | #endif |
a2e4f780 | 245 | |
01ca42b2 | 246 | memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions)); |
30f0ad28 | 247 | myShaderManager = new OpenGl_ShaderManager (this); |
2166f0fa SK |
248 | } |
249 | ||
250 | // ======================================================================= | |
251 | // function : ~OpenGl_Context | |
252 | // purpose : | |
253 | // ======================================================================= | |
254 | OpenGl_Context::~OpenGl_Context() | |
255 | { | |
5e27df78 | 256 | // release clean up queue |
257 | ReleaseDelayed(); | |
258 | ||
4e1523ef | 259 | #if !defined(GL_ES_VERSION_2_0) |
260 | // release default VAO | |
261 | if (myDefaultVao != 0 | |
262 | && IsValid() | |
263 | && core32 != NULL) | |
264 | { | |
265 | core32->glDeleteVertexArrays (1, &myDefaultVao); | |
266 | } | |
267 | myDefaultVao = 0; | |
268 | #endif | |
269 | ||
a2e4f780 | 270 | // release default FBO |
271 | if (!myDefaultFbo.IsNull()) | |
272 | { | |
273 | myDefaultFbo->Release (this); | |
274 | myDefaultFbo.Nullify(); | |
275 | } | |
276 | ||
5e27df78 | 277 | // release shared resources if any |
4796758e | 278 | if (mySharedResources->GetRefCount() <= 1) |
5e27df78 | 279 | { |
392ac980 | 280 | myShaderManager.Nullify(); |
5e27df78 | 281 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); |
282 | anIter.More(); anIter.Next()) | |
283 | { | |
284 | anIter.Value()->Release (this); | |
285 | } | |
e1c659da | 286 | |
287 | // release delayed resources added during deletion of shared resources | |
288 | while (!myUnusedResources->IsEmpty()) | |
289 | { | |
290 | myUnusedResources->First()->Release (this); | |
291 | myUnusedResources->RemoveFirst(); | |
292 | } | |
5e27df78 | 293 | } |
c357e426 | 294 | else if (myShaderManager->IsSameContext (this)) |
392ac980 | 295 | { |
296 | myShaderManager->SetContext (NULL); | |
297 | } | |
5e27df78 | 298 | mySharedResources.Nullify(); |
a174a3c5 | 299 | myDelayed.Nullify(); |
5e27df78 | 300 | |
cbf18624 | 301 | if (arbDbg != NULL |
4e1523ef | 302 | && myIsGlDebugCtx |
f8c8ba7a | 303 | && IsValid()) |
cbf18624 | 304 | { |
305 | // reset callback | |
0deb6f04 | 306 | #if !defined(GL_ES_VERSION_2_0) |
cbf18624 | 307 | void* aPtr = NULL; |
3b523c4c | 308 | glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM, &aPtr); |
cbf18624 | 309 | if (aPtr == this) |
0deb6f04 | 310 | #endif |
cbf18624 | 311 | { |
0deb6f04 | 312 | arbDbg->glDebugMessageCallback (NULL, NULL); |
cbf18624 | 313 | } |
4e1523ef | 314 | myIsGlDebugCtx = Standard_False; |
cbf18624 | 315 | } |
5f8b738e | 316 | } |
317 | ||
05e2200b | 318 | // ======================================================================= |
319 | // function : forcedRelease | |
320 | // purpose : | |
321 | // ======================================================================= | |
322 | void OpenGl_Context::forcedRelease() | |
323 | { | |
324 | ReleaseDelayed(); | |
325 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); | |
326 | anIter.More(); anIter.Next()) | |
327 | { | |
328 | anIter.Value()->Release (this); | |
329 | } | |
330 | mySharedResources->Clear(); | |
331 | myShaderManager->clear(); | |
332 | myShaderManager->SetContext (NULL); | |
e1c659da | 333 | |
334 | // release delayed resources added during deletion of shared resources | |
335 | while (!myUnusedResources->IsEmpty()) | |
336 | { | |
337 | myUnusedResources->First()->Release (this); | |
338 | myUnusedResources->RemoveFirst(); | |
339 | } | |
05e2200b | 340 | } |
341 | ||
3bffef55 | 342 | // ======================================================================= |
343 | // function : ResizeViewport | |
344 | // purpose : | |
345 | // ======================================================================= | |
346 | void OpenGl_Context::ResizeViewport (const Standard_Integer* theRect) | |
347 | { | |
348 | core11fwd->glViewport (theRect[0], theRect[1], theRect[2], theRect[3]); | |
349 | myViewport[0] = theRect[0]; | |
350 | myViewport[1] = theRect[1]; | |
351 | myViewport[2] = theRect[2]; | |
352 | myViewport[3] = theRect[3]; | |
56689b27 | 353 | if (HasRenderScale()) |
354 | { | |
355 | myViewportVirt[0] = Standard_Integer(theRect[0] * myRenderScaleInv); | |
356 | myViewportVirt[1] = Standard_Integer(theRect[1] * myRenderScaleInv); | |
357 | myViewportVirt[2] = Standard_Integer(theRect[2] * myRenderScaleInv); | |
358 | myViewportVirt[3] = Standard_Integer(theRect[3] * myRenderScaleInv); | |
359 | } | |
360 | else | |
361 | { | |
362 | myViewportVirt[0] = theRect[0]; | |
363 | myViewportVirt[1] = theRect[1]; | |
364 | myViewportVirt[2] = theRect[2]; | |
365 | myViewportVirt[3] = theRect[3]; | |
366 | } | |
3bffef55 | 367 | } |
368 | ||
ca3c13d1 | 369 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 370 | inline Standard_Integer stereoToMonoBuffer (const Standard_Integer theBuffer) |
371 | { | |
372 | switch (theBuffer) | |
b5ac8292 | 373 | { |
38a0206f | 374 | case GL_BACK_LEFT: |
375 | case GL_BACK_RIGHT: | |
376 | return GL_BACK; | |
377 | case GL_FRONT_LEFT: | |
378 | case GL_FRONT_RIGHT: | |
379 | return GL_FRONT; | |
380 | default: | |
381 | return theBuffer; | |
b5ac8292 | 382 | } |
383 | } | |
38a0206f | 384 | #endif |
b5ac8292 | 385 | |
386 | // ======================================================================= | |
38a0206f | 387 | // function : SetReadBuffer |
b5ac8292 | 388 | // purpose : |
389 | // ======================================================================= | |
38a0206f | 390 | void OpenGl_Context::SetReadBuffer (const Standard_Integer theReadBuffer) |
b5ac8292 | 391 | { |
ca3c13d1 | 392 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 393 | myReadBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theReadBuffer) : theReadBuffer; |
394 | if (myReadBuffer < GL_COLOR_ATTACHMENT0 | |
395 | && arbFBO != NULL) | |
b5ac8292 | 396 | { |
38a0206f | 397 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 398 | } |
38a0206f | 399 | ::glReadBuffer (myReadBuffer); |
400 | #else | |
401 | (void )theReadBuffer; | |
ca3c13d1 | 402 | #endif |
b5ac8292 | 403 | } |
404 | ||
405 | // ======================================================================= | |
38a0206f | 406 | // function : SetDrawBuffer |
b5ac8292 | 407 | // purpose : |
408 | // ======================================================================= | |
38a0206f | 409 | void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer) |
b5ac8292 | 410 | { |
ca3c13d1 | 411 | #if !defined(GL_ES_VERSION_2_0) |
a1073ae2 | 412 | const Standard_Integer aDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer; |
413 | if (aDrawBuffer < GL_COLOR_ATTACHMENT0 | |
38a0206f | 414 | && arbFBO != NULL) |
b5ac8292 | 415 | { |
38a0206f | 416 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 417 | } |
a1073ae2 | 418 | ::glDrawBuffer (aDrawBuffer); |
419 | ||
420 | myDrawBuffers.Clear(); | |
421 | ||
422 | if (aDrawBuffer != GL_NONE) | |
423 | { | |
424 | myDrawBuffers.SetValue (0, aDrawBuffer); | |
425 | } | |
38a0206f | 426 | #else |
427 | (void )theDrawBuffer; | |
ca3c13d1 | 428 | #endif |
b5ac8292 | 429 | } |
430 | ||
a1073ae2 | 431 | // ======================================================================= |
432 | // function : SetDrawBuffers | |
433 | // purpose : | |
434 | // ======================================================================= | |
435 | void OpenGl_Context::SetDrawBuffers (const Standard_Integer theNb, const Standard_Integer* theDrawBuffers) | |
436 | { | |
437 | Standard_ASSERT_RETURN (hasDrawBuffers, "Multiple draw buffers feature is not supported by the context", Standard_ASSERT_DO_NOTHING()); | |
438 | ||
439 | myDrawBuffers.Clear(); | |
440 | ||
441 | Standard_Boolean useDefaultFbo = Standard_False; | |
442 | for (Standard_Integer anI = 0; anI < theNb; ++anI) | |
443 | { | |
444 | #if !defined(GL_ES_VERSION_2_0) | |
445 | const Standard_Integer aDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffers[anI]) : theDrawBuffers[anI]; | |
446 | #else | |
447 | const Standard_Integer aDrawBuffer = theDrawBuffers[anI]; | |
448 | #endif | |
449 | if (aDrawBuffer < GL_COLOR_ATTACHMENT0 && aDrawBuffer != GL_NONE) | |
450 | { | |
451 | useDefaultFbo = Standard_True; | |
452 | } | |
453 | else if (aDrawBuffer != GL_NONE) | |
454 | { | |
455 | myDrawBuffers.SetValue (anI, aDrawBuffer); | |
456 | } | |
457 | } | |
458 | if (arbFBO != NULL && useDefaultFbo) | |
459 | { | |
460 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); | |
461 | } | |
462 | ||
463 | myFuncs->glDrawBuffers (theNb, (const GLenum*)theDrawBuffers); | |
464 | } | |
465 | ||
b6472664 | 466 | // ======================================================================= |
467 | // function : SetCullBackFaces | |
468 | // purpose : | |
469 | // ======================================================================= | |
470 | void OpenGl_Context::SetCullBackFaces (bool theToEnable) | |
471 | { | |
472 | if (myToCullBackFaces == theToEnable) | |
473 | { | |
474 | return; | |
475 | } | |
476 | ||
477 | myToCullBackFaces = theToEnable; | |
478 | if (theToEnable) | |
479 | { | |
480 | //glCullFace (GL_BACK); GL_BACK by default | |
481 | core11fwd->glEnable (GL_CULL_FACE); | |
482 | } | |
483 | else | |
484 | { | |
485 | core11fwd->glDisable (GL_CULL_FACE); | |
486 | } | |
487 | } | |
488 | ||
b5ac8292 | 489 | // ======================================================================= |
490 | // function : FetchState | |
491 | // purpose : | |
492 | // ======================================================================= | |
493 | void OpenGl_Context::FetchState() | |
494 | { | |
ca3c13d1 | 495 | #if !defined(GL_ES_VERSION_2_0) |
b5ac8292 | 496 | // cache feedback mode state |
4e1523ef | 497 | if (core11 != NULL) |
498 | { | |
499 | ::glGetIntegerv (GL_RENDER_MODE, &myRenderMode); | |
500 | } | |
b5ac8292 | 501 | |
a1073ae2 | 502 | // cache read buffers state |
38a0206f | 503 | ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer); |
a1073ae2 | 504 | |
505 | // cache draw buffers state | |
506 | myDrawBuffers.Clear(); | |
507 | ||
508 | if (myMaxDrawBuffers == 1) | |
509 | { | |
510 | Standard_Integer aDrawBuffer; | |
511 | ||
512 | ::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer); | |
513 | ||
514 | if (aDrawBuffer != GL_NONE) | |
515 | { | |
516 | myDrawBuffers.SetValue (0, aDrawBuffer); | |
517 | } | |
518 | } | |
519 | else | |
520 | { | |
521 | Standard_Integer aDrawBuffer; | |
522 | ||
523 | for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI) | |
524 | { | |
525 | ::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer); | |
526 | ||
527 | if (aDrawBuffer != GL_NONE) | |
528 | { | |
529 | myDrawBuffers.SetValue (anI, aDrawBuffer); | |
530 | } | |
531 | } | |
532 | } | |
ca3c13d1 | 533 | #endif |
b5ac8292 | 534 | } |
535 | ||
5e27df78 | 536 | // ======================================================================= |
537 | // function : Share | |
538 | // purpose : | |
539 | // ======================================================================= | |
540 | void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx) | |
541 | { | |
542 | if (!theShareCtx.IsNull()) | |
543 | { | |
544 | mySharedResources = theShareCtx->mySharedResources; | |
a174a3c5 | 545 | myDelayed = theShareCtx->myDelayed; |
3125ebb6 | 546 | myUnusedResources = theShareCtx->myUnusedResources; |
392ac980 | 547 | myShaderManager = theShareCtx->myShaderManager; |
5e27df78 | 548 | } |
549 | } | |
550 | ||
4fe56619 | 551 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
552 | ||
86fa64d9 | 553 | // ======================================================================= |
554 | // function : IsCurrent | |
555 | // purpose : | |
556 | // ======================================================================= | |
557 | Standard_Boolean OpenGl_Context::IsCurrent() const | |
558 | { | |
da8bb41d | 559 | #if defined(HAVE_EGL) |
560 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
561 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
562 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
563 | { | |
564 | return Standard_False; | |
565 | } | |
566 | ||
567 | return (((EGLDisplay )myDisplay == eglGetCurrentDisplay()) | |
568 | && ((EGLContext )myGContext == eglGetCurrentContext()) | |
569 | && ((EGLSurface )myWindow == eglGetCurrentSurface (EGL_DRAW))); | |
570 | #elif defined(_WIN32) | |
86fa64d9 | 571 | if (myWindowDC == NULL || myGContext == NULL) |
572 | { | |
573 | return Standard_False; | |
574 | } | |
575 | return (( (HDC )myWindowDC == wglGetCurrentDC()) | |
576 | && ((HGLRC )myGContext == wglGetCurrentContext())); | |
577 | #else | |
578 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) | |
579 | { | |
580 | return Standard_False; | |
581 | } | |
582 | ||
583 | return ( ((Display* )myDisplay == glXGetCurrentDisplay()) | |
584 | && ((GLXContext )myGContext == glXGetCurrentContext()) | |
585 | && ((GLXDrawable )myWindow == glXGetCurrentDrawable())); | |
586 | #endif | |
587 | } | |
588 | ||
2bd4c032 | 589 | // ======================================================================= |
590 | // function : MakeCurrent | |
591 | // purpose : | |
592 | // ======================================================================= | |
593 | Standard_Boolean OpenGl_Context::MakeCurrent() | |
594 | { | |
da8bb41d | 595 | #if defined(HAVE_EGL) |
596 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
597 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
598 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
599 | { | |
600 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
601 | return Standard_False; | |
602 | } | |
603 | ||
604 | if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE) | |
605 | { | |
606 | // if there is no current context it might be impossible to use glGetError() correctly | |
3b523c4c | 607 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, |
da8bb41d | 608 | "eglMakeCurrent() has failed!"); |
609 | myIsInitialized = Standard_False; | |
610 | return Standard_False; | |
611 | } | |
612 | #elif defined(_WIN32) | |
86fa64d9 | 613 | if (myWindowDC == NULL || myGContext == NULL) |
2bd4c032 | 614 | { |
86fa64d9 | 615 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); |
616 | return Standard_False; | |
617 | } | |
618 | ||
619 | // technically it should be safe to activate already bound GL context | |
620 | // however some drivers (Intel etc.) may FAIL doing this for unknown reason | |
621 | if (IsCurrent()) | |
622 | { | |
392ac980 | 623 | myShaderManager->SetContext (this); |
86fa64d9 | 624 | return Standard_True; |
625 | } | |
626 | else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE) | |
627 | { | |
628 | // notice that glGetError() couldn't be used here! | |
629 | wchar_t* aMsgBuff = NULL; | |
630 | DWORD anErrorCode = GetLastError(); | |
631 | FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
632 | NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL); | |
cbf18624 | 633 | TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. "); |
86fa64d9 | 634 | if (aMsgBuff != NULL) |
635 | { | |
cbf18624 | 636 | aMsg += (Standard_ExtString )aMsgBuff; |
86fa64d9 | 637 | LocalFree (aMsgBuff); |
638 | } | |
3b523c4c | 639 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH, aMsg); |
fd4a6963 | 640 | myIsInitialized = Standard_False; |
2bd4c032 | 641 | return Standard_False; |
642 | } | |
643 | #else | |
86fa64d9 | 644 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) |
645 | { | |
646 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
647 | return Standard_False; | |
648 | } | |
649 | ||
650 | if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext)) | |
2bd4c032 | 651 | { |
652 | // if there is no current context it might be impossible to use glGetError() correctly | |
3b523c4c | 653 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, |
cbf18624 | 654 | "glXMakeCurrent() has failed!"); |
fd4a6963 | 655 | myIsInitialized = Standard_False; |
2bd4c032 | 656 | return Standard_False; |
657 | } | |
658 | #endif | |
392ac980 | 659 | myShaderManager->SetContext (this); |
2bd4c032 | 660 | return Standard_True; |
661 | } | |
662 | ||
5e27df78 | 663 | // ======================================================================= |
664 | // function : SwapBuffers | |
665 | // purpose : | |
666 | // ======================================================================= | |
667 | void OpenGl_Context::SwapBuffers() | |
668 | { | |
da8bb41d | 669 | #if defined(HAVE_EGL) |
670 | if ((EGLSurface )myWindow != EGL_NO_SURFACE) | |
671 | { | |
672 | eglSwapBuffers ((EGLDisplay )myDisplay, (EGLSurface )myWindow); | |
673 | } | |
674 | #elif defined(_WIN32) | |
5e27df78 | 675 | if ((HDC )myWindowDC != NULL) |
676 | { | |
677 | ::SwapBuffers ((HDC )myWindowDC); | |
678 | glFlush(); | |
679 | } | |
680 | #else | |
681 | if ((Display* )myDisplay != NULL) | |
682 | { | |
683 | glXSwapBuffers ((Display* )myDisplay, (GLXDrawable )myWindow); | |
684 | } | |
685 | #endif | |
686 | } | |
687 | ||
4fe56619 | 688 | #endif // __APPLE__ |
689 | ||
f978241f | 690 | // ======================================================================= |
691 | // function : SetSwapInterval | |
692 | // purpose : | |
693 | // ======================================================================= | |
694 | Standard_Boolean OpenGl_Context::SetSwapInterval (const Standard_Integer theInterval) | |
695 | { | |
696 | #if defined(HAVE_EGL) | |
697 | if (::eglSwapInterval ((EGLDisplay )myDisplay, theInterval) == EGL_TRUE) | |
698 | { | |
699 | return Standard_True; | |
700 | } | |
701 | #elif defined(_WIN32) | |
702 | if (myFuncs->wglSwapIntervalEXT != NULL) | |
703 | { | |
704 | myFuncs->wglSwapIntervalEXT (theInterval); | |
705 | return Standard_True; | |
706 | } | |
707 | #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
708 | // | |
709 | #elif defined(__APPLE__) | |
710 | if (::CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &theInterval) == kCGLNoError) | |
711 | { | |
712 | return Standard_True; | |
713 | } | |
714 | #else | |
715 | if (theInterval == -1 | |
716 | && myFuncs->glXSwapIntervalEXT != NULL) | |
717 | { | |
718 | typedef int (*glXSwapIntervalEXT_t_x)(Display* theDisplay, GLXDrawable theDrawable, int theInterval); | |
719 | glXSwapIntervalEXT_t_x aFuncPtr = (glXSwapIntervalEXT_t_x )myFuncs->glXSwapIntervalEXT; | |
720 | aFuncPtr ((Display* )myDisplay, (GLXDrawable )myWindow, theInterval); | |
721 | return Standard_True; | |
722 | } | |
723 | else if (myFuncs->glXSwapIntervalSGI != NULL) | |
724 | { | |
725 | myFuncs->glXSwapIntervalSGI (theInterval); | |
726 | return Standard_True; | |
727 | } | |
728 | #endif | |
729 | return Standard_False; | |
730 | } | |
731 | ||
5f8b738e | 732 | // ======================================================================= |
733 | // function : findProc | |
734 | // purpose : | |
735 | // ======================================================================= | |
736 | void* OpenGl_Context::findProc (const char* theFuncName) | |
737 | { | |
da8bb41d | 738 | #if defined(HAVE_EGL) |
739 | return (void* )eglGetProcAddress (theFuncName); | |
740 | #elif defined(_WIN32) | |
7c65581d | 741 | return (void* )wglGetProcAddress (theFuncName); |
5f8b738e | 742 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
743 | return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL; | |
744 | #else | |
745 | return (void* )glXGetProcAddress ((const GLubyte* )theFuncName); | |
746 | #endif | |
2166f0fa SK |
747 | } |
748 | ||
749 | // ======================================================================= | |
750 | // function : CheckExtension | |
751 | // purpose : | |
752 | // ======================================================================= | |
2bd4c032 | 753 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const |
2166f0fa | 754 | { |
5f8b738e | 755 | if (theExtName == NULL) |
756 | { | |
0797d9d3 | 757 | #ifdef OCCT_DEBUG |
5f8b738e | 758 | std::cerr << "CheckExtension called with NULL string!\n"; |
63c629aa | 759 | #endif |
5f8b738e | 760 | return Standard_False; |
761 | } | |
5f8b738e | 762 | |
4e1523ef | 763 | #if !defined(GL_ES_VERSION_2_0) |
5f8b738e | 764 | // available since OpenGL 3.0 |
765 | // and the ONLY way to check extensions with OpenGL 3.1+ core profile | |
4e1523ef | 766 | if (IsGlGreaterEqual (3, 0) |
767 | && myFuncs->glGetStringi != NULL) | |
5f8b738e | 768 | { |
769 | GLint anExtNb = 0; | |
4e1523ef | 770 | ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb); |
771 | const size_t anExtNameLen = strlen (theExtName); | |
5f8b738e | 772 | for (GLint anIter = 0; anIter < anExtNb; ++anIter) |
773 | { | |
4e1523ef | 774 | const char* anExtension = (const char* )myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint )anIter); |
775 | const size_t aTestExtNameLen = strlen (anExtension); | |
776 | if (aTestExtNameLen == anExtNameLen | |
777 | && strncmp (anExtension, theExtName, anExtNameLen) == 0) | |
5f8b738e | 778 | { |
779 | return Standard_True; | |
780 | } | |
781 | } | |
782 | return Standard_False; | |
4e1523ef | 783 | } |
784 | #endif | |
5f8b738e | 785 | |
786 | // use old way with huge string for all extensions | |
787 | const char* anExtString = (const char* )glGetString (GL_EXTENSIONS); | |
788 | if (anExtString == NULL) | |
789 | { | |
7e7c2f0b | 790 | Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning); |
2166f0fa SK |
791 | return Standard_False; |
792 | } | |
58655684 | 793 | return CheckExtension (anExtString, theExtName); |
794 | } | |
795 | ||
796 | // ======================================================================= | |
797 | // function : CheckExtension | |
798 | // purpose : | |
799 | // ======================================================================= | |
800 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtString, | |
801 | const char* theExtName) | |
802 | { | |
803 | if (theExtString == NULL) | |
804 | { | |
805 | return Standard_False; | |
806 | } | |
2166f0fa SK |
807 | |
808 | // Search for theExtName in the extensions string. | |
809 | // Use of strstr() is not sufficient because extension names can be prefixes of other extension names. | |
58655684 | 810 | char* aPtrIter = (char* )theExtString; |
811 | const char* aPtrEnd = aPtrIter + strlen (theExtString); | |
812 | const size_t anExtNameLen = strlen (theExtName); | |
2166f0fa SK |
813 | while (aPtrIter < aPtrEnd) |
814 | { | |
6a7d83c4 | 815 | const size_t n = strcspn (aPtrIter, " "); |
5f8b738e | 816 | if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0)) |
817 | { | |
2166f0fa | 818 | return Standard_True; |
5f8b738e | 819 | } |
2166f0fa SK |
820 | aPtrIter += (n + 1); |
821 | } | |
822 | return Standard_False; | |
823 | } | |
824 | ||
4fe56619 | 825 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
826 | ||
2166f0fa SK |
827 | // ======================================================================= |
828 | // function : Init | |
829 | // purpose : | |
830 | // ======================================================================= | |
4e1523ef | 831 | Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile) |
2166f0fa | 832 | { |
2bd4c032 | 833 | if (myIsInitialized) |
5f8b738e | 834 | { |
f0430952 | 835 | return Standard_True; |
5f8b738e | 836 | } |
2bd4c032 | 837 | |
da8bb41d | 838 | #if defined(HAVE_EGL) |
839 | myDisplay = (Aspect_Display )eglGetCurrentDisplay(); | |
840 | myGContext = (Aspect_RenderingContext )eglGetCurrentContext(); | |
841 | myWindow = (Aspect_Drawable )eglGetCurrentSurface(EGL_DRAW); | |
842 | #elif defined(_WIN32) | |
2bd4c032 | 843 | myWindowDC = (Aspect_Handle )wglGetCurrentDC(); |
844 | myGContext = (Aspect_RenderingContext )wglGetCurrentContext(); | |
845 | #else | |
846 | myDisplay = (Aspect_Display )glXGetCurrentDisplay(); | |
847 | myGContext = (Aspect_RenderingContext )glXGetCurrentContext(); | |
848 | myWindow = (Aspect_Drawable )glXGetCurrentDrawable(); | |
849 | #endif | |
f0430952 | 850 | if (myGContext == NULL) |
851 | { | |
852 | return Standard_False; | |
853 | } | |
2bd4c032 | 854 | |
4e1523ef | 855 | init (theIsCoreProfile); |
2bd4c032 | 856 | myIsInitialized = Standard_True; |
f0430952 | 857 | return Standard_True; |
2bd4c032 | 858 | } |
859 | ||
4fe56619 | 860 | #endif // __APPLE__ |
861 | ||
2bd4c032 | 862 | // ======================================================================= |
863 | // function : Init | |
864 | // purpose : | |
865 | // ======================================================================= | |
da8bb41d | 866 | #if defined(HAVE_EGL) |
867 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theEglSurface, | |
868 | const Aspect_Display theEglDisplay, | |
4e1523ef | 869 | const Aspect_RenderingContext theEglContext, |
870 | const Standard_Boolean theIsCoreProfile) | |
da8bb41d | 871 | #elif defined(_WIN32) |
f0430952 | 872 | Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow, |
873 | const Aspect_Handle theWindowDC, | |
4e1523ef | 874 | const Aspect_RenderingContext theGContext, |
875 | const Standard_Boolean theIsCoreProfile) | |
4fe56619 | 876 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 877 | |
878 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
879 | Standard_Boolean OpenGl_Context::Init (EAGLContext* theGContext, | |
4e1523ef | 880 | const Standard_Boolean theIsCoreProfile) |
a2e4f780 | 881 | #else |
882 | Standard_Boolean OpenGl_Context::Init (NSOpenGLContext* theGContext, | |
883 | const Standard_Boolean theIsCoreProfile) | |
884 | #endif | |
885 | ||
2bd4c032 | 886 | #else |
f0430952 | 887 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow, |
888 | const Aspect_Display theDisplay, | |
4e1523ef | 889 | const Aspect_RenderingContext theGContext, |
890 | const Standard_Boolean theIsCoreProfile) | |
2bd4c032 | 891 | #endif |
892 | { | |
893 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!"); | |
da8bb41d | 894 | #if defined(HAVE_EGL) |
895 | myWindow = theEglSurface; | |
896 | myGContext = theEglContext; | |
897 | myDisplay = theEglDisplay; | |
898 | #elif defined(_WIN32) | |
2bd4c032 | 899 | myWindow = theWindow; |
900 | myGContext = theGContext; | |
2bd4c032 | 901 | myWindowDC = theWindowDC; |
4fe56619 | 902 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 903 | myGContext = theGContext; |
2bd4c032 | 904 | #else |
4fe56619 | 905 | myWindow = theWindow; |
906 | myGContext = theGContext; | |
2bd4c032 | 907 | myDisplay = theDisplay; |
908 | #endif | |
86fa64d9 | 909 | if (myGContext == NULL || !MakeCurrent()) |
f0430952 | 910 | { |
911 | return Standard_False; | |
912 | } | |
2bd4c032 | 913 | |
4e1523ef | 914 | init (theIsCoreProfile); |
2bd4c032 | 915 | myIsInitialized = Standard_True; |
f0430952 | 916 | return Standard_True; |
5f8b738e | 917 | } |
918 | ||
919 | // ======================================================================= | |
920 | // function : ResetErrors | |
921 | // purpose : | |
922 | // ======================================================================= | |
f9f740d6 | 923 | bool OpenGl_Context::ResetErrors (const bool theToPrintErrors) |
5f8b738e | 924 | { |
3c4b62a4 | 925 | int aPrevErr = 0; |
926 | int anErr = ::glGetError(); | |
f9f740d6 | 927 | const bool hasError = anErr != GL_NO_ERROR; |
3c4b62a4 | 928 | if (!theToPrintErrors) |
5f8b738e | 929 | { |
3c4b62a4 | 930 | for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError()) |
931 | { | |
932 | // | |
933 | } | |
f9f740d6 | 934 | return hasError; |
3c4b62a4 | 935 | } |
936 | ||
937 | for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError()) | |
938 | { | |
939 | TCollection_ExtendedString anErrId; | |
940 | switch (anErr) | |
941 | { | |
942 | case GL_INVALID_ENUM: anErrId = "GL_INVALID_ENUM"; break; | |
943 | case GL_INVALID_VALUE: anErrId = "GL_INVALID_VALUE"; break; | |
944 | case GL_INVALID_OPERATION: anErrId = "GL_INVALID_OPERATION"; break; | |
945 | #ifdef GL_STACK_OVERFLOW | |
946 | case GL_STACK_OVERFLOW: anErrId = "GL_STACK_OVERFLOW"; break; | |
947 | case GL_STACK_UNDERFLOW: anErrId = "GL_STACK_UNDERFLOW"; break; | |
948 | #endif | |
949 | case GL_OUT_OF_MEMORY: anErrId = "GL_OUT_OF_MEMORY"; break; | |
950 | case GL_INVALID_FRAMEBUFFER_OPERATION: | |
951 | anErrId = "GL_INVALID_FRAMEBUFFER_OPERATION"; | |
952 | break; | |
953 | default: | |
954 | anErrId = TCollection_ExtendedString("#") + anErr; | |
955 | break; | |
956 | } | |
957 | ||
958 | const TCollection_ExtendedString aMsg = TCollection_ExtendedString ("Unhandled GL error: ") + anErrId; | |
82f443b6 | 959 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_OTHER, 0, GL_DEBUG_SEVERITY_LOW, aMsg); |
5f8b738e | 960 | } |
f9f740d6 | 961 | return hasError; |
5f8b738e | 962 | } |
963 | ||
964 | // ======================================================================= | |
4e1523ef | 965 | // function : ReadGlVersion |
5f8b738e | 966 | // purpose : |
967 | // ======================================================================= | |
4e1523ef | 968 | void OpenGl_Context::ReadGlVersion (Standard_Integer& theGlVerMajor, |
969 | Standard_Integer& theGlVerMinor) | |
5f8b738e | 970 | { |
971 | // reset values | |
4e1523ef | 972 | theGlVerMajor = 0; |
973 | theGlVerMinor = 0; | |
5f8b738e | 974 | |
ca3c13d1 | 975 | #ifdef GL_MAJOR_VERSION |
976 | // available since OpenGL 3.0 and OpenGL 3.0 ES | |
86325709 | 977 | GLint aMajor = 0, aMinor = 0; |
5f8b738e | 978 | glGetIntegerv (GL_MAJOR_VERSION, &aMajor); |
979 | glGetIntegerv (GL_MINOR_VERSION, &aMinor); | |
30f0ad28 | 980 | // glGetError() sometimes does not report an error here even if |
86325709 | 981 | // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants. |
ca3c13d1 | 982 | // This happens on some renderers like e.g. Cygwin MESA. |
86325709 | 983 | // Thus checking additionally if GL has put anything to |
984 | // the output variables. | |
4e1523ef | 985 | if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0) |
5f8b738e | 986 | { |
4e1523ef | 987 | theGlVerMajor = aMajor; |
988 | theGlVerMinor = aMinor; | |
5f8b738e | 989 | return; |
990 | } | |
4e1523ef | 991 | for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError()) |
992 | { | |
993 | if (anErr == GL_NO_ERROR | |
994 | || anErr == aPrevErr) | |
995 | { | |
996 | break; | |
997 | } | |
998 | } | |
ca3c13d1 | 999 | #endif |
5f8b738e | 1000 | |
1001 | // Read version string. | |
ca3c13d1 | 1002 | // Notice that only first two numbers split by point '2.1 XXXXX' are significant. |
5f8b738e | 1003 | // Following trash (after space) is vendor-specific. |
1004 | // New drivers also returns micro version of GL like '3.3.0' which has no meaning | |
1005 | // and should be considered as vendor-specific too. | |
1006 | const char* aVerStr = (const char* )glGetString (GL_VERSION); | |
1007 | if (aVerStr == NULL || *aVerStr == '\0') | |
1008 | { | |
1009 | // invalid GL context | |
1010 | return; | |
1011 | } | |
1012 | ||
ca3c13d1 | 1013 | //#if defined(GL_ES_VERSION_2_0) |
1014 | // skip "OpenGL ES-** " section | |
1015 | for (; *aVerStr != '\0'; ++aVerStr) | |
1016 | { | |
1017 | if (*aVerStr >= '0' && *aVerStr <= '9') | |
1018 | { | |
1019 | break; | |
1020 | } | |
1021 | } | |
1022 | //#endif | |
1023 | ||
5f8b738e | 1024 | // parse string for major number |
1025 | char aMajorStr[32]; | |
1026 | char aMinorStr[32]; | |
1027 | size_t aMajIter = 0; | |
1028 | while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9') | |
1029 | { | |
1030 | ++aMajIter; | |
1031 | } | |
1032 | if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr)) | |
1033 | { | |
1034 | return; | |
1035 | } | |
1036 | memcpy (aMajorStr, aVerStr, aMajIter); | |
1037 | aMajorStr[aMajIter] = '\0'; | |
1038 | ||
1039 | // parse string for minor number | |
86325709 | 1040 | aVerStr += aMajIter + 1; |
1041 | size_t aMinIter = 0; | |
5f8b738e | 1042 | while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9') |
1043 | { | |
1044 | ++aMinIter; | |
1045 | } | |
86325709 | 1046 | if (aMinIter == 0 || aMinIter >= sizeof(aMinorStr)) |
5f8b738e | 1047 | { |
1048 | return; | |
1049 | } | |
86325709 | 1050 | memcpy (aMinorStr, aVerStr, aMinIter); |
1051 | aMinorStr[aMinIter] = '\0'; | |
5f8b738e | 1052 | |
1053 | // read numbers | |
4e1523ef | 1054 | theGlVerMajor = atoi (aMajorStr); |
1055 | theGlVerMinor = atoi (aMinorStr); | |
5f8b738e | 1056 | |
4e1523ef | 1057 | if (theGlVerMajor <= 0) |
5f8b738e | 1058 | { |
4e1523ef | 1059 | theGlVerMajor = 0; |
1060 | theGlVerMinor = 0; | |
5f8b738e | 1061 | } |
1062 | } | |
1063 | ||
58655684 | 1064 | static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN"; |
1065 | static Standard_CString THE_DBGMSG_SOURCES[] = | |
1066 | { | |
3b523c4c | 1067 | ".OpenGL", // GL_DEBUG_SOURCE_API |
1068 | ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM | |
1069 | ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER | |
1070 | ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY | |
1071 | "", // GL_DEBUG_SOURCE_APPLICATION | |
1072 | ".Other" // GL_DEBUG_SOURCE_OTHER | |
58655684 | 1073 | }; |
1074 | ||
1075 | static Standard_CString THE_DBGMSG_TYPES[] = | |
1076 | { | |
3b523c4c | 1077 | "Error", // GL_DEBUG_TYPE_ERROR |
1078 | "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR | |
1079 | "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR | |
1080 | "Portability", // GL_DEBUG_TYPE_PORTABILITY | |
1081 | "Performance", // GL_DEBUG_TYPE_PERFORMANCE | |
1082 | "Other" // GL_DEBUG_TYPE_OTHER | |
58655684 | 1083 | }; |
1084 | ||
3b523c4c | 1085 | static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH |
1086 | static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM | |
1087 | static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW | |
58655684 | 1088 | |
cbf18624 | 1089 | //! Callback for GL_ARB_debug_output extension |
58655684 | 1090 | static void APIENTRY debugCallbackWrap(unsigned int theSource, |
1091 | unsigned int theType, | |
1092 | unsigned int theId, | |
1093 | unsigned int theSeverity, | |
1094 | int /*theLength*/, | |
1095 | const char* theMessage, | |
9293178b | 1096 | const void* theUserParam) |
cbf18624 | 1097 | { |
1098 | OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam; | |
1099 | aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage); | |
1100 | } | |
1101 | ||
1102 | // ======================================================================= | |
1103 | // function : PushMessage | |
1104 | // purpose : | |
1105 | // ======================================================================= | |
1106 | void OpenGl_Context::PushMessage (const unsigned int theSource, | |
1107 | const unsigned int theType, | |
1108 | const unsigned int theId, | |
1109 | const unsigned int theSeverity, | |
1110 | const TCollection_ExtendedString& theMessage) | |
58655684 | 1111 | { |
c87535af | 1112 | if (caps->suppressExtraMsg |
3b523c4c | 1113 | && theSource >= GL_DEBUG_SOURCE_API |
1114 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1115 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Contains (theId)) | |
c87535af | 1116 | { |
1117 | return; | |
1118 | } | |
1119 | ||
3b523c4c | 1120 | Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API |
1121 | && theSource <= GL_DEBUG_SOURCE_OTHER) | |
1122 | ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API] | |
58655684 | 1123 | : THE_DBGMSG_UNKNOWN; |
3b523c4c | 1124 | Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR |
1125 | && theType <= GL_DEBUG_TYPE_OTHER) | |
1126 | ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR] | |
58655684 | 1127 | : THE_DBGMSG_UNKNOWN; |
3b523c4c | 1128 | Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH |
58655684 | 1129 | ? THE_DBGMSG_SEV_HIGH |
3b523c4c | 1130 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM |
58655684 | 1131 | ? THE_DBGMSG_SEV_MEDIUM |
1132 | : THE_DBGMSG_SEV_LOW); | |
3b523c4c | 1133 | Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH |
cbf18624 | 1134 | ? Message_Alarm |
3b523c4c | 1135 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM |
cbf18624 | 1136 | ? Message_Warning |
1137 | : Message_Info); | |
1138 | ||
1139 | TCollection_ExtendedString aMsg; | |
1140 | aMsg += "TKOpenGl"; aMsg += aSrc; | |
1141 | aMsg += " | Type: "; aMsg += aType; | |
1142 | aMsg += " | ID: "; aMsg += (Standard_Integer )theId; | |
1143 | aMsg += " | Severity: "; aMsg += aSev; | |
1144 | aMsg += " | Message:\n "; | |
1145 | aMsg += theMessage; | |
7e7c2f0b | 1146 | Messenger()->Send (aMsg, aGrav); |
58655684 | 1147 | } |
1148 | ||
c87535af | 1149 | // ======================================================================= |
1150 | // function : ExcludeMessage | |
1151 | // purpose : | |
1152 | // ====================================================================== | |
1153 | Standard_Boolean OpenGl_Context::ExcludeMessage (const unsigned int theSource, | |
1154 | const unsigned int theId) | |
1155 | { | |
3b523c4c | 1156 | return theSource >= GL_DEBUG_SOURCE_API |
1157 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1158 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Add (theId); | |
c87535af | 1159 | } |
1160 | ||
1161 | // ======================================================================= | |
1162 | // function : IncludeMessage | |
1163 | // purpose : | |
1164 | // ====================================================================== | |
1165 | Standard_Boolean OpenGl_Context::IncludeMessage (const unsigned int theSource, | |
1166 | const unsigned int theId) | |
1167 | { | |
3b523c4c | 1168 | return theSource >= GL_DEBUG_SOURCE_API |
1169 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1170 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Remove (theId); | |
c87535af | 1171 | } |
1172 | ||
ee51a9fe | 1173 | // ======================================================================= |
1174 | // function : checkWrongVersion | |
1175 | // purpose : | |
1176 | // ====================================================================== | |
1177 | void OpenGl_Context::checkWrongVersion (const Standard_Integer theGlVerMajor, | |
1178 | const Standard_Integer theGlVerMinor) | |
1179 | { | |
1180 | if (!IsGlGreaterEqual (theGlVerMajor, theGlVerMinor)) | |
1181 | { | |
1182 | return; | |
1183 | } | |
1184 | ||
1185 | TCollection_ExtendedString aMsg = TCollection_ExtendedString() | |
1186 | + "Error! OpenGL context reports version " | |
1187 | + myGlVerMajor + "." + myGlVerMinor | |
1188 | + " but does not export required functions for " | |
1189 | + theGlVerMajor + "." + theGlVerMinor; | |
3b523c4c | 1190 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, |
1191 | GL_DEBUG_TYPE_ERROR, | |
ee51a9fe | 1192 | 0, |
3b523c4c | 1193 | GL_DEBUG_SEVERITY_HIGH, |
ee51a9fe | 1194 | aMsg); |
1195 | } | |
1196 | ||
5f8b738e | 1197 | // ======================================================================= |
1198 | // function : init | |
1199 | // purpose : | |
1200 | // ======================================================================= | |
4e1523ef | 1201 | void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) |
5f8b738e | 1202 | { |
1203 | // read version | |
4e1523ef | 1204 | myGlVerMajor = 0; |
1205 | myGlVerMinor = 0; | |
3c4b62a4 | 1206 | myMaxMsaaSamples = 0; |
a1073ae2 | 1207 | myMaxDrawBuffers = 1; |
1208 | myMaxColorAttachments = 1; | |
4e1523ef | 1209 | ReadGlVersion (myGlVerMajor, myGlVerMinor); |
c87535af | 1210 | myVendor = (const char* )::glGetString (GL_VENDOR); |
be375252 | 1211 | if (!caps->ffpEnable |
1212 | && !IsGlGreaterEqual (2, 0)) | |
1213 | { | |
1214 | caps->ffpEnable = true; | |
1215 | TCollection_ExtendedString aMsg = | |
1216 | TCollection_ExtendedString("OpenGL driver is too old! Context info:\n") | |
1217 | + " Vendor: " + (const char* )::glGetString (GL_VENDOR) + "\n" | |
1218 | + " Renderer: " + (const char* )::glGetString (GL_RENDERER) + "\n" | |
1219 | + " Version: " + (const char* )::glGetString (GL_VERSION) + "\n" | |
1220 | + " Fallback using deprecated fixed-function pipeline.\n" | |
1221 | + " Visualization might work incorrectly.\n" | |
1222 | " Consider upgrading the graphics driver."; | |
1223 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aMsg); | |
1224 | } | |
4e1523ef | 1225 | |
1226 | #if defined(GL_ES_VERSION_2_0) | |
1227 | (void )theIsCoreProfile; | |
1228 | const bool isCoreProfile = false; | |
1229 | #else | |
c87535af | 1230 | |
1231 | if (myVendor.Search ("NVIDIA") != -1) | |
1232 | { | |
1233 | // Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) | |
1234 | // will use VIDEO memory as the source for buffer object operations. | |
3b523c4c | 1235 | ExcludeMessage (GL_DEBUG_SOURCE_API, 131185); |
c87535af | 1236 | } |
4e1523ef | 1237 | if (IsGlGreaterEqual (3, 0)) |
1238 | { | |
1239 | // retrieve auxiliary function in advance | |
1240 | FindProc ("glGetStringi", myFuncs->glGetStringi); | |
1241 | } | |
1242 | ||
d4271fe5 | 1243 | bool isCoreProfile = false; |
4e1523ef | 1244 | if (IsGlGreaterEqual (3, 2)) |
1245 | { | |
d4271fe5 | 1246 | isCoreProfile = (theIsCoreProfile == Standard_True); |
4e1523ef | 1247 | |
d4271fe5 | 1248 | // detect Core profile |
c6ad5e5f | 1249 | if (!isCoreProfile) |
4e1523ef | 1250 | { |
d4271fe5 | 1251 | GLint aProfile = 0; |
1252 | ::glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &aProfile); | |
1253 | isCoreProfile = (aProfile & GL_CONTEXT_CORE_PROFILE_BIT) != 0; | |
4e1523ef | 1254 | } |
1255 | } | |
4e1523ef | 1256 | #endif |
1257 | ||
1258 | core11 = NULL; | |
1259 | if (!isCoreProfile) | |
1260 | { | |
1261 | core11 = (OpenGl_GlCore11* )(&(*myFuncs)); | |
1262 | } | |
01ca42b2 | 1263 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); |
1264 | core15 = NULL; | |
1265 | core15fwd = NULL; | |
1266 | core20 = NULL; | |
1267 | core20fwd = NULL; | |
1268 | core32 = NULL; | |
1269 | core32back = NULL; | |
25ef750e | 1270 | core33 = NULL; |
1271 | core33back = NULL; | |
01ca42b2 | 1272 | core41 = NULL; |
1273 | core41back = NULL; | |
1274 | core42 = NULL; | |
1275 | core42back = NULL; | |
1276 | core43 = NULL; | |
1277 | core43back = NULL; | |
1278 | core44 = NULL; | |
1279 | core44back = NULL; | |
1280 | arbTBO = NULL; | |
25ef750e | 1281 | arbTboRGB32 = Standard_False; |
01ca42b2 | 1282 | arbIns = NULL; |
1283 | arbDbg = NULL; | |
1284 | arbFBO = NULL; | |
b86bb3df | 1285 | arbFBOBlit = NULL; |
01ca42b2 | 1286 | extGS = NULL; |
4e1523ef | 1287 | myDefaultVao = 0; |
01ca42b2 | 1288 | |
cc8cbabe | 1289 | //! Make record shorter to retrieve function pointer using variable with same name |
1290 | #define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc) | |
1291 | ||
ca3c13d1 | 1292 | #if defined(GL_ES_VERSION_2_0) |
1293 | ||
1294 | hasTexRGBA8 = IsGlGreaterEqual (3, 0) | |
1295 | || CheckExtension ("GL_OES_rgb8_rgba8"); | |
05e2200b | 1296 | // NPOT textures has limited support within OpenGL ES 2.0 |
1297 | // which are relaxed by OpenGL ES 3.0 or some extensions | |
1298 | //arbNPTW = IsGlGreaterEqual (3, 0) | |
1299 | // || CheckExtension ("GL_OES_texture_npot") | |
1300 | // || CheckExtension ("GL_NV_texture_npot_2D_mipmap"); | |
1301 | arbNPTW = Standard_True; | |
ca3c13d1 | 1302 | arbTexRG = IsGlGreaterEqual (3, 0) |
1303 | || CheckExtension ("GL_EXT_texture_rg"); | |
1304 | extBgra = CheckExtension ("GL_EXT_texture_format_BGRA8888"); | |
1305 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
e473b95f | 1306 | extPDS = IsGlGreaterEqual (3, 0) |
1307 | || CheckExtension ("GL_OES_packed_depth_stencil"); | |
ca3c13d1 | 1308 | |
1309 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); | |
1310 | if (IsGlGreaterEqual (2, 0)) | |
1311 | { | |
1312 | // enable compatible functions | |
1313 | core20 = (OpenGl_GlCore20* )(&(*myFuncs)); | |
1314 | core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs)); | |
1315 | core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs)); | |
b86bb3df | 1316 | arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs)); |
1317 | } | |
1318 | if (IsGlGreaterEqual (3, 0) | |
cc8cbabe | 1319 | && FindProcShort (glBlitFramebuffer)) |
b86bb3df | 1320 | { |
1321 | arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs)); | |
ca3c13d1 | 1322 | } |
cc8cbabe | 1323 | if (IsGlGreaterEqual (3, 0) |
1324 | && FindProcShort (glGenSamplers) | |
1325 | && FindProcShort (glDeleteSamplers) | |
1326 | && FindProcShort (glIsSampler) | |
1327 | && FindProcShort (glBindSampler) | |
1328 | && FindProcShort (glSamplerParameteri) | |
1329 | && FindProcShort (glSamplerParameteriv) | |
1330 | && FindProcShort (glSamplerParameterf) | |
1331 | && FindProcShort (glSamplerParameterfv) | |
1332 | && FindProcShort (glGetSamplerParameteriv) | |
1333 | && FindProcShort (glGetSamplerParameterfv)) | |
1334 | //&& FindProcShort (glSamplerParameterIiv) // only on Desktop or with extensions GL_OES_texture_border_clamp/GL_EXT_texture_border_clamp | |
1335 | //&& FindProcShort (glSamplerParameterIuiv) | |
1336 | //&& FindProcShort (glGetSamplerParameterIiv) | |
1337 | //&& FindProcShort (glGetSamplerParameterIuiv)) | |
1338 | { | |
1339 | arbSamplerObject = (OpenGl_ArbSamplerObject* )(&(*myFuncs)); | |
1340 | } | |
1ce0716b | 1341 | extFragDepth = !IsGlGreaterEqual(3, 0) |
1342 | && CheckExtension ("GL_EXT_frag_depth"); | |
3c4b62a4 | 1343 | if (IsGlGreaterEqual (3, 1) |
1344 | && FindProc ("glTexStorage2DMultisample", myFuncs->glTexStorage2DMultisample)) | |
1345 | { | |
1346 | // MSAA RenderBuffers have been defined in OpenGL ES 3.0, | |
1347 | // but MSAA Textures - only in OpenGL ES 3.1+ | |
1348 | ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples); | |
1349 | } | |
ca3c13d1 | 1350 | |
e99a2f7c | 1351 | hasUintIndex = IsGlGreaterEqual (3, 0) |
1352 | || CheckExtension ("GL_OES_element_index_uint"); | |
1353 | hasHighp = CheckExtension ("GL_OES_fragment_precision_high"); | |
ca3c13d1 | 1354 | GLint aRange[2] = {0, 0}; |
447c4115 | 1355 | GLint aPrec = 0; |
1356 | ::glGetShaderPrecisionFormat (GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, aRange, &aPrec); | |
1357 | if (aPrec != 0) | |
ca3c13d1 | 1358 | { |
1359 | hasHighp = Standard_True; | |
1360 | } | |
74fb257d | 1361 | |
1362 | arbTexFloat = IsGlGreaterEqual (3, 0) | |
1363 | && FindProc ("glTexImage3D", myFuncs->glTexImage3D); | |
20aeeb7b | 1364 | |
1365 | const Standard_Boolean hasTexBuffer32 = IsGlGreaterEqual (3, 2) && FindProc ("glTexBuffer", myFuncs->glTexBuffer); | |
1366 | const Standard_Boolean hasExtTexBuffer = CheckExtension ("GL_EXT_texture_buffer") && FindProc ("glTexBufferEXT", myFuncs->glTexBuffer); | |
1367 | ||
1368 | if (hasTexBuffer32 || hasExtTexBuffer) | |
1369 | { | |
1370 | arbTBO = reinterpret_cast<OpenGl_ArbTBO*> (myFuncs.get()); | |
1371 | } | |
0deb6f04 | 1372 | |
1373 | // initialize debug context extension | |
1374 | if (CheckExtension ("GL_KHR_debug")) | |
1375 | { | |
1376 | // this functionality become a part of OpenGL ES 3.2 | |
1377 | arbDbg = NULL; | |
1378 | // According to GL_KHR_debug spec, all functions should have KHR suffix. | |
1379 | // However, some implementations can export these functions without suffix. | |
1380 | if (FindProc ("glDebugMessageControlKHR", myFuncs->glDebugMessageControl) | |
1381 | && FindProc ("glDebugMessageInsertKHR", myFuncs->glDebugMessageInsert) | |
1382 | && FindProc ("glDebugMessageCallbackKHR", myFuncs->glDebugMessageCallback) | |
1383 | && FindProc ("glGetDebugMessageLogKHR", myFuncs->glGetDebugMessageLog)) | |
1384 | { | |
1385 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); | |
1386 | } | |
1387 | ||
1388 | if (arbDbg != NULL | |
1389 | && caps->contextDebug) | |
1390 | { | |
1391 | // setup default callback | |
1392 | myIsGlDebugCtx = Standard_True; | |
1393 | arbDbg->glDebugMessageCallback (debugCallbackWrap, this); | |
1394 | ::glEnable (GL_DEBUG_OUTPUT); | |
1395 | if (caps->contextSyncDebug) | |
1396 | { | |
1397 | // note that some broken implementations (e.g. simulators) might generate error message on this call | |
1398 | ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS); | |
1399 | } | |
1400 | } | |
1401 | } | |
1402 | ||
a1073ae2 | 1403 | extDrawBuffers = CheckExtension ("GL_EXT_draw_buffers") && FindProc ("glDrawBuffersEXT", myFuncs->glDrawBuffers); |
1404 | arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers") && FindProc ("glDrawBuffersARB", myFuncs->glDrawBuffers); | |
1405 | ||
1406 | if (IsGlGreaterEqual (3, 0) && FindProc ("glDrawBuffers", myFuncs->glDrawBuffers)) | |
1407 | { | |
1408 | hasDrawBuffers = OpenGl_FeatureInCore; | |
1409 | } | |
1410 | else if (extDrawBuffers || arbDrawBuffers) | |
1411 | { | |
1412 | hasDrawBuffers = OpenGl_FeatureInExtensions; | |
1413 | } | |
1414 | ||
1415 | hasFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore : | |
1416 | CheckExtension ("GL_EXT_color_buffer_float") ? OpenGl_FeatureInExtensions | |
1417 | : OpenGl_FeatureNotAvailable; | |
1418 | hasHalfFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore : | |
1419 | CheckExtension ("GL_EXT_color_buffer_half_float") ? OpenGl_FeatureInExtensions | |
1420 | : OpenGl_FeatureNotAvailable; | |
1421 | ||
1422 | oesSampleVariables = CheckExtension ("GL_OES_sample_variables"); | |
8c3237d4 | 1423 | oesStdDerivatives = CheckExtension ("GL_OES_standard_derivatives"); |
a1073ae2 | 1424 | hasSampleVariables = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore : |
1425 | oesSampleVariables ? OpenGl_FeatureInExtensions | |
1426 | : OpenGl_FeatureNotAvailable; | |
ca3c13d1 | 1427 | #else |
1428 | ||
1429 | myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP; | |
1430 | ||
1431 | hasTexRGBA8 = Standard_True; | |
a1073ae2 | 1432 | arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers"); |
1433 | arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two"); | |
1434 | arbTexFloat = IsGlGreaterEqual (3, 0) | |
1435 | || CheckExtension ("GL_ARB_texture_float"); | |
1436 | arbSampleShading = CheckExtension ("GL_ARB_sample_shading"); | |
1437 | extBgra = CheckExtension ("GL_EXT_bgra"); | |
1438 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
1439 | extPDS = CheckExtension ("GL_EXT_packed_depth_stencil"); | |
1440 | atiMem = CheckExtension ("GL_ATI_meminfo"); | |
1441 | nvxMem = CheckExtension ("GL_NVX_gpu_memory_info"); | |
1442 | ||
1443 | hasDrawBuffers = IsGlGreaterEqual (2, 0) ? OpenGl_FeatureInCore : | |
1444 | arbDrawBuffers ? OpenGl_FeatureInExtensions | |
1445 | : OpenGl_FeatureNotAvailable; | |
1446 | ||
1447 | hasFloatBuffer = hasHalfFloatBuffer = IsGlGreaterEqual (3, 0) ? OpenGl_FeatureInCore : | |
1448 | CheckExtension ("GL_ARB_color_buffer_float") ? OpenGl_FeatureInExtensions | |
1449 | : OpenGl_FeatureNotAvailable; | |
1450 | ||
1451 | hasSampleVariables = IsGlGreaterEqual (4, 0) ? OpenGl_FeatureInCore : | |
1452 | arbSampleShading ? OpenGl_FeatureInExtensions | |
1453 | : OpenGl_FeatureNotAvailable; | |
bf75be98 | 1454 | |
ca3c13d1 | 1455 | GLint aStereo = GL_FALSE; |
b5ac8292 | 1456 | glGetIntegerv (GL_STEREO, &aStereo); |
1457 | myIsStereoBuffers = aStereo == 1; | |
1458 | ||
ca3c13d1 | 1459 | // get number of maximum clipping planes |
1460 | glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes); | |
1461 | #endif | |
1462 | ||
a1073ae2 | 1463 | if (hasDrawBuffers) |
1464 | { | |
1465 | glGetIntegerv (GL_MAX_DRAW_BUFFERS, &myMaxDrawBuffers); | |
1466 | glGetIntegerv (GL_MAX_COLOR_ATTACHMENTS, &myMaxColorAttachments); | |
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 | |
4269bd1b | 1480 | myClippingState.Init (myMaxClipPlanes); |
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. | |
3201 | if (theAspect->IsNoLighting()) | |
3202 | { | |
3203 | return; | |
3204 | } | |
3205 | ||
3206 | if (myMatFront == myShaderManager->MaterialState().FrontMaterial() | |
3207 | && myMatBack == myShaderManager->MaterialState().BackMaterial() | |
3208 | && toDistinguish == myShaderManager->MaterialState().ToDistinguish() | |
3209 | && toMapTexture == myShaderManager->MaterialState().ToMapTexture()) | |
3210 | { | |
3211 | return; | |
3212 | } | |
3213 | ||
3214 | myShaderManager->UpdateMaterialStateTo (myMatFront, myMatBack, toDistinguish, toMapTexture); | |
299e0ab9 | 3215 | } |
3216 | ||
a1073ae2 | 3217 | // ======================================================================= |
3218 | // function : CheckIsTransparent | |
3219 | // purpose : | |
3220 | // ======================================================================= | |
3221 | Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_AspectFace* theAspect, | |
3222 | const Handle(Graphic3d_PresentationAttributes)& theHighlight, | |
a71a71de | 3223 | Standard_ShortReal& theAlphaFront, |
3224 | Standard_ShortReal& theAlphaBack) | |
a1073ae2 | 3225 | { |
3226 | const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull()) | |
3227 | ? theHighlight->BasicFillAreaAspect() | |
3228 | : theAspect->Aspect(); | |
3229 | ||
3230 | const bool toDistinguish = anAspect->Distinguish(); | |
3231 | const Graphic3d_MaterialAspect& aMatFrontSrc = anAspect->FrontMaterial(); | |
3232 | const Graphic3d_MaterialAspect& aMatBackSrc = toDistinguish | |
3233 | ? anAspect->BackMaterial() | |
3234 | : aMatFrontSrc; | |
3235 | ||
3236 | // handling transparency | |
a1073ae2 | 3237 | if (!theHighlight.IsNull() |
3238 | && theHighlight->BasicFillAreaAspect().IsNull()) | |
3239 | { | |
a71a71de | 3240 | theAlphaFront = theHighlight->ColorRGBA().Alpha(); |
3241 | theAlphaBack = theHighlight->ColorRGBA().Alpha(); | |
3242 | } | |
3243 | else | |
3244 | { | |
3245 | theAlphaFront = aMatFrontSrc.Alpha(); | |
3246 | theAlphaBack = aMatBackSrc .Alpha(); | |
a1073ae2 | 3247 | } |
3248 | ||
a71a71de | 3249 | const bool isTransparent = theAlphaFront < 1.0f |
3250 | || theAlphaBack < 1.0f; | |
3251 | return isTransparent; | |
a1073ae2 | 3252 | } |
3253 | ||
299e0ab9 | 3254 | // ======================================================================= |
8625ef7e | 3255 | // function : SetColor4fv |
3256 | // purpose : | |
3257 | // ======================================================================= | |
3258 | void OpenGl_Context::SetColor4fv (const OpenGl_Vec4& theColor) | |
3259 | { | |
3260 | if (!myActiveProgram.IsNull()) | |
3261 | { | |
3262 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_COLOR), theColor); | |
3263 | } | |
3264 | #if !defined(GL_ES_VERSION_2_0) | |
3265 | else if (core11 != NULL) | |
3266 | { | |
3267 | core11->glColor4fv (theColor.GetData()); | |
3268 | } | |
3269 | #endif | |
3270 | } | |
3271 | ||
ac116c22 | 3272 | // ======================================================================= |
3273 | // function : SetTypeOfLine | |
3274 | // purpose : | |
3275 | // ======================================================================= | |
3276 | void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType, | |
3277 | const Standard_ShortReal theFactor) | |
3278 | { | |
3279 | Standard_Integer aPattern = 0xFFFF; | |
3280 | switch (theType) | |
3281 | { | |
3282 | case Aspect_TOL_DASH: | |
3283 | { | |
3284 | aPattern = 0xFFC0; | |
3285 | break; | |
3286 | } | |
3287 | case Aspect_TOL_DOT: | |
3288 | { | |
3289 | aPattern = 0xCCCC; | |
3290 | break; | |
3291 | } | |
3292 | case Aspect_TOL_DOTDASH: | |
3293 | { | |
3294 | aPattern = 0xFF18; | |
3295 | break; | |
3296 | } | |
3a4a3962 | 3297 | case Aspect_TOL_EMPTY: |
ac116c22 | 3298 | case Aspect_TOL_SOLID: |
3299 | { | |
3300 | aPattern = 0xFFFF; | |
3301 | break; | |
3302 | } | |
3303 | case Aspect_TOL_USERDEFINED: | |
3304 | { | |
3305 | aPattern = 0xFF24; | |
3306 | break; | |
3307 | } | |
3308 | } | |
3309 | ||
c04c30b3 | 3310 | if (!myActiveProgram.IsNull()) |
ac116c22 | 3311 | { |
3312 | myActiveProgram->SetUniform (this, "uPattern", aPattern); | |
3313 | myActiveProgram->SetUniform (this, "uFactor", theFactor); | |
3314 | return; | |
3315 | } | |
3316 | ||
3317 | #if !defined(GL_ES_VERSION_2_0) | |
3a4a3962 | 3318 | if (aPattern != 0xFFFF) |
ac116c22 | 3319 | { |
3320 | #ifdef HAVE_GL2PS | |
3321 | if (IsFeedback()) | |
3322 | { | |
3323 | gl2psEnable (GL2PS_LINE_STIPPLE); | |
3324 | } | |
3325 | #endif | |
3326 | ||
3327 | if (core11 != NULL) | |
3328 | { | |
3329 | core11fwd->glEnable (GL_LINE_STIPPLE); | |
3330 | ||
3331 | core11->glLineStipple (static_cast<GLint> (theFactor), | |
3332 | static_cast<GLushort> (aPattern)); | |
3333 | } | |
3334 | } | |
3335 | else | |
3336 | { | |
3337 | if (core11 != NULL) | |
3338 | { | |
3339 | core11fwd->glDisable (GL_LINE_STIPPLE); | |
3340 | } | |
3341 | ||
3342 | #ifdef HAVE_GL2PS | |
3343 | if (IsFeedback()) | |
3344 | { | |
3345 | gl2psDisable (GL2PS_LINE_STIPPLE); | |
3346 | } | |
3347 | #endif | |
3348 | } | |
3349 | #endif | |
3350 | } | |
3351 | ||
3352 | // ======================================================================= | |
3353 | // function : SetLineWidth | |
3354 | // purpose : | |
3355 | // ======================================================================= | |
3356 | void OpenGl_Context::SetLineWidth (const Standard_ShortReal theWidth) | |
3357 | { | |
3358 | if (core11 != NULL) | |
3359 | { | |
3360 | // glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f | |
56689b27 | 3361 | core11fwd->glLineWidth (theWidth * myLineWidthScale); |
ac116c22 | 3362 | } |
3363 | #ifdef HAVE_GL2PS | |
3364 | if (IsFeedback()) | |
3365 | { | |
3366 | gl2psLineWidth (theWidth); | |
3367 | } | |
3368 | #endif | |
3369 | } | |
3370 | ||
79f4f036 | 3371 | // ======================================================================= |
3372 | // function : SetTextureMatrix | |
3373 | // purpose : | |
3374 | // ======================================================================= | |
3375 | void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams) | |
3376 | { | |
3377 | if (theParams.IsNull()) | |
3378 | { | |
3379 | return; | |
3380 | } | |
3381 | else if (!myActiveProgram.IsNull()) | |
3382 | { | |
3383 | const GLint aUniLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_TRSF2D); | |
3384 | if (aUniLoc == OpenGl_ShaderProgram::INVALID_LOCATION) | |
3385 | { | |
3386 | return; | |
3387 | } | |
3388 | ||
3389 | // pack transformation parameters | |
3390 | OpenGl_Vec4 aTrsf[2]; | |
a6dee93d | 3391 | aTrsf[0].x() = -theParams->Translation().x(); |
3392 | aTrsf[0].y() = -theParams->Translation().y(); | |
79f4f036 | 3393 | aTrsf[0].zw() = theParams->Scale(); |
3394 | aTrsf[1].x() = std::sin (-theParams->Rotation() * static_cast<float> (M_PI / 180.0)); | |
3395 | aTrsf[1].y() = std::cos (-theParams->Rotation() * static_cast<float> (M_PI / 180.0)); | |
3396 | myActiveProgram->SetUniform (this, aUniLoc, 2, aTrsf); | |
3397 | return; | |
3398 | } | |
3399 | ||
3400 | #if !defined(GL_ES_VERSION_2_0) | |
3401 | if (core11 != NULL) | |
3402 | { | |
3403 | GLint aMatrixMode = GL_TEXTURE; | |
3404 | ::glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode); | |
3405 | ||
3406 | core11->glMatrixMode (GL_TEXTURE); | |
3407 | OpenGl_Mat4 aTextureMat; | |
3408 | const Graphic3d_Vec2& aScale = theParams->Scale(); | |
3409 | const Graphic3d_Vec2& aTrans = theParams->Translation(); | |
3410 | Graphic3d_TransformUtils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f); | |
3411 | Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f); | |
3412 | Graphic3d_TransformUtils::Rotate (aTextureMat, -theParams->Rotation(), 0.0f, 0.0f, 1.0f); | |
3413 | core11->glLoadMatrixf (aTextureMat); | |
3414 | core11->glMatrixMode (aMatrixMode); | |
3415 | } | |
3416 | #endif | |
3417 | } | |
3418 | ||
8625ef7e | 3419 | // ======================================================================= |
3420 | // function : SetPointSize | |
3421 | // purpose : | |
3422 | // ======================================================================= | |
3423 | void OpenGl_Context::SetPointSize (const Standard_ShortReal theSize) | |
3424 | { | |
3425 | if (!myActiveProgram.IsNull()) | |
3426 | { | |
3427 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_POINT_SIZE), theSize); | |
3428 | #if !defined(GL_ES_VERSION_2_0) | |
3429 | //myContext->core11fwd->glEnable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
3430 | #endif | |
3431 | } | |
3432 | #if !defined(GL_ES_VERSION_2_0) | |
3433 | //else | |
3434 | { | |
3435 | core11fwd->glPointSize (theSize); | |
3436 | if (core20fwd != NULL) | |
3437 | { | |
3438 | //myContext->core11fwd->glDisable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
3439 | } | |
3440 | } | |
3441 | #endif | |
7d3e64ef | 3442 | } |
7d9e854b | 3443 | |
fd59283a | 3444 | // ======================================================================= |
3445 | // function : SetPointSpriteOrigin | |
3446 | // purpose : | |
3447 | // ======================================================================= | |
3448 | void OpenGl_Context::SetPointSpriteOrigin() | |
3449 | { | |
3450 | #if !defined(GL_ES_VERSION_2_0) | |
3451 | if (core15fwd == NULL) | |
3452 | { | |
3453 | return; | |
3454 | } | |
3455 | ||
3456 | const int aNewState = !myActiveProgram.IsNull() ? GL_UPPER_LEFT : GL_LOWER_LEFT; | |
3457 | if (myPointSpriteOrig != aNewState) | |
3458 | { | |
3459 | myPointSpriteOrig = aNewState; | |
3460 | core15fwd->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, aNewState); | |
3461 | } | |
3462 | #endif | |
3463 | } | |
3464 | ||
7d9e854b | 3465 | // ======================================================================= |
3466 | // function : SetGlNormalizeEnabled | |
3467 | // purpose : | |
3468 | // ======================================================================= | |
3469 | Standard_Boolean OpenGl_Context::SetGlNormalizeEnabled (Standard_Boolean isEnabled) | |
3470 | { | |
3471 | if (isEnabled == myIsGlNormalizeEnabled) | |
3472 | { | |
3473 | return myIsGlNormalizeEnabled; | |
3474 | } | |
3475 | ||
3476 | Standard_Boolean anOldGlNormalize = myIsGlNormalizeEnabled; | |
3477 | ||
3478 | myIsGlNormalizeEnabled = isEnabled; | |
3479 | ||
3480 | #if !defined(GL_ES_VERSION_2_0) | |
39070532 | 3481 | if (core11 != NULL) |
7d9e854b | 3482 | { |
39070532 | 3483 | if (isEnabled) |
3484 | { | |
3485 | ::glEnable (GL_NORMALIZE); | |
3486 | } | |
3487 | else | |
3488 | { | |
3489 | ::glDisable (GL_NORMALIZE); | |
3490 | } | |
7d9e854b | 3491 | } |
3492 | #endif | |
3493 | ||
3494 | return anOldGlNormalize; | |
3495 | } | |
c827ea3a | 3496 | |
6d0e6be5 | 3497 | // ======================================================================= |
3498 | // function : SetPolygonMode | |
3499 | // purpose : | |
3500 | // ======================================================================= | |
3501 | Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode) | |
3502 | { | |
3503 | if (myPolygonMode == theMode) | |
3504 | { | |
3505 | return myPolygonMode; | |
3506 | } | |
3507 | ||
3508 | const Standard_Integer anOldPolygonMode = myPolygonMode; | |
3509 | ||
3510 | myPolygonMode = theMode; | |
3511 | ||
3512 | #if !defined(GL_ES_VERSION_2_0) | |
3513 | ::glPolygonMode (GL_FRONT_AND_BACK, (GLenum)theMode); | |
3514 | #endif | |
3515 | ||
3516 | return anOldPolygonMode; | |
3517 | } | |
3518 | ||
3519 | // ======================================================================= | |
3520 | // function : SetPolygonHatchEnabled | |
3521 | // purpose : | |
3522 | // ======================================================================= | |
3523 | bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled) | |
3524 | { | |
3525 | if (myHatchStyles.IsNull()) | |
3526 | { | |
3527 | return false; | |
3528 | } | |
3529 | else if (myHatchStyles->IsEnabled() == theIsEnabled) | |
3530 | { | |
3531 | return theIsEnabled; | |
3532 | } | |
3533 | ||
3534 | return myHatchStyles->SetEnabled (this, theIsEnabled); | |
3535 | } | |
3536 | ||
3537 | // ======================================================================= | |
3538 | // function : SetPolygonHatchStyle | |
3539 | // purpose : | |
3540 | // ======================================================================= | |
640d5fe2 | 3541 | Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) |
6d0e6be5 | 3542 | { |
ec7c343f | 3543 | if (theStyle.IsNull()) |
3544 | { | |
3545 | return 0; | |
3546 | } | |
3547 | ||
6d0e6be5 | 3548 | if (myHatchStyles.IsNull()) |
3549 | { | |
3550 | if (!GetResource ("OpenGl_LineAttributes", myHatchStyles)) | |
3551 | { | |
3552 | // share and register for release once the resource is no longer used | |
3553 | myHatchStyles = new OpenGl_LineAttributes(); | |
3554 | ShareResource ("OpenGl_LineAttributes", myHatchStyles); | |
6d0e6be5 | 3555 | } |
3556 | } | |
640d5fe2 | 3557 | if (myHatchStyles->TypeOfHatch() == theStyle->HatchType()) |
6d0e6be5 | 3558 | { |
640d5fe2 | 3559 | return theStyle->HatchType(); |
6d0e6be5 | 3560 | } |
3561 | ||
640d5fe2 | 3562 | return myHatchStyles->SetTypeOfHatch (this, theStyle); |
6d0e6be5 | 3563 | } |
3564 | ||
8d1a539c | 3565 | // ======================================================================= |
3566 | // function : SetPolygonOffset | |
3567 | // purpose : | |
3568 | // ======================================================================= | |
3569 | void OpenGl_Context::SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset) | |
3570 | { | |
3571 | const bool toFillOld = (myPolygonOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill; | |
3572 | const bool toFillNew = (theOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill; | |
3573 | if (toFillNew != toFillOld) | |
3574 | { | |
3575 | if (toFillNew) | |
3576 | { | |
3577 | glEnable (GL_POLYGON_OFFSET_FILL); | |
3578 | } | |
3579 | else | |
3580 | { | |
3581 | glDisable (GL_POLYGON_OFFSET_FILL); | |
3582 | } | |
3583 | } | |
3584 | ||
3585 | #if !defined(GL_ES_VERSION_2_0) | |
3586 | const bool toLineOld = (myPolygonOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line; | |
3587 | const bool toLineNew = (theOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line; | |
3588 | if (toLineNew != toLineOld) | |
3589 | { | |
3590 | if (toLineNew) | |
3591 | { | |
3592 | glEnable (GL_POLYGON_OFFSET_LINE); | |
3593 | } | |
3594 | else | |
3595 | { | |
3596 | glDisable (GL_POLYGON_OFFSET_LINE); | |
3597 | } | |
3598 | } | |
3599 | ||
3600 | const bool toPointOld = (myPolygonOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point; | |
3601 | const bool toPointNew = (theOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point; | |
3602 | if (toPointNew != toPointOld) | |
3603 | { | |
3604 | if (toPointNew) | |
3605 | { | |
3606 | glEnable (GL_POLYGON_OFFSET_POINT); | |
3607 | } | |
3608 | else | |
3609 | { | |
3610 | glDisable (GL_POLYGON_OFFSET_POINT); | |
3611 | } | |
3612 | } | |
3613 | #endif | |
3614 | ||
3615 | if (myPolygonOffset.Factor != theOffset.Factor | |
3616 | || myPolygonOffset.Units != theOffset.Units) | |
3617 | { | |
3618 | glPolygonOffset (theOffset.Factor, theOffset.Units); | |
3619 | } | |
3620 | myPolygonOffset = theOffset; | |
3621 | } | |
3622 | ||
c827ea3a | 3623 | // ======================================================================= |
3624 | // function : ApplyModelWorldMatrix | |
3625 | // purpose : | |
3626 | // ======================================================================= | |
3627 | void OpenGl_Context::ApplyModelWorldMatrix() | |
3628 | { | |
8613985b | 3629 | if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current()) |
c827ea3a | 3630 | { |
3631 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); | |
3632 | } | |
3633 | } | |
3634 | ||
3635 | // ======================================================================= | |
3636 | // function : ApplyWorldViewMatrix | |
3637 | // purpose : | |
3638 | // ======================================================================= | |
3639 | void OpenGl_Context::ApplyWorldViewMatrix() | |
3640 | { | |
8613985b | 3641 | if (myShaderManager->ModelWorldState().ModelWorldMatrix() != THE_IDENTITY_MATRIX) |
c827ea3a | 3642 | { |
8613985b | 3643 | myShaderManager->UpdateModelWorldStateTo (THE_IDENTITY_MATRIX); |
c827ea3a | 3644 | } |
8613985b | 3645 | if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current()) |
c827ea3a | 3646 | { |
3647 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); | |
3648 | } | |
3649 | } | |
3650 | ||
3651 | // ======================================================================= | |
3652 | // function : ApplyModelViewMatrix | |
3653 | // purpose : | |
3654 | // ======================================================================= | |
3655 | void OpenGl_Context::ApplyModelViewMatrix() | |
3656 | { | |
8613985b | 3657 | if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current()) |
c827ea3a | 3658 | { |
8613985b | 3659 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); |
c827ea3a | 3660 | } |
8613985b | 3661 | if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current()) |
c827ea3a | 3662 | { |
8613985b | 3663 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); |
c827ea3a | 3664 | } |
3665 | } | |
3666 | ||
3667 | // ======================================================================= | |
3668 | // function : ApplyProjectionMatrix | |
3669 | // purpose : | |
3670 | // ======================================================================= | |
3671 | void OpenGl_Context::ApplyProjectionMatrix() | |
3672 | { | |
8613985b | 3673 | if (myShaderManager->ProjectionState().ProjectionMatrix() != ProjectionState.Current()) |
c827ea3a | 3674 | { |
3675 | myShaderManager->UpdateProjectionStateTo (ProjectionState.Current()); | |
3676 | } | |
3677 | } | |
c357e426 | 3678 | |
c357e426 | 3679 | // ======================================================================= |
3680 | // function : EnableFeatures | |
3681 | // purpose : | |
3682 | // ======================================================================= | |
3683 | void OpenGl_Context::EnableFeatures() const | |
3684 | { | |
3685 | // | |
3686 | } | |
3687 | ||
3688 | // ======================================================================= | |
3689 | // function : DisableFeatures | |
3690 | // purpose : | |
3691 | // ======================================================================= | |
3692 | void OpenGl_Context::DisableFeatures() const | |
3693 | { | |
a0b49de4 | 3694 | // Disable stuff that's likely to slow down glDrawPixels. |
c357e426 | 3695 | glDisable(GL_DITHER); |
3696 | glDisable(GL_BLEND); | |
3697 | glDisable(GL_DEPTH_TEST); | |
c357e426 | 3698 | glDisable(GL_STENCIL_TEST); |
3699 | ||
3700 | #if !defined(GL_ES_VERSION_2_0) | |
a0b49de4 | 3701 | if (core11 == NULL) |
3702 | { | |
3703 | return; | |
3704 | } | |
3705 | ||
3706 | glDisable(GL_TEXTURE_1D); | |
3707 | glDisable(GL_TEXTURE_2D); | |
3708 | ||
c357e426 | 3709 | glDisable(GL_LIGHTING); |
3710 | glDisable(GL_ALPHA_TEST); | |
3711 | glDisable(GL_FOG); | |
3712 | glDisable(GL_LOGIC_OP); | |
c357e426 | 3713 | |
3714 | glPixelTransferi(GL_MAP_COLOR, GL_FALSE); | |
3715 | glPixelTransferi(GL_RED_SCALE, 1); | |
3716 | glPixelTransferi(GL_RED_BIAS, 0); | |
3717 | glPixelTransferi(GL_GREEN_SCALE, 1); | |
3718 | glPixelTransferi(GL_GREEN_BIAS, 0); | |
3719 | glPixelTransferi(GL_BLUE_SCALE, 1); | |
3720 | glPixelTransferi(GL_BLUE_BIAS, 0); | |
3721 | glPixelTransferi(GL_ALPHA_SCALE, 1); | |
3722 | glPixelTransferi(GL_ALPHA_BIAS, 0); | |
3723 | ||
c357e426 | 3724 | if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2)) |
3725 | { | |
c357e426 | 3726 | if (CheckExtension ("GL_CONVOLUTION_1D_EXT")) |
3727 | glDisable(GL_CONVOLUTION_1D_EXT); | |
3728 | ||
3729 | if (CheckExtension ("GL_CONVOLUTION_2D_EXT")) | |
3730 | glDisable(GL_CONVOLUTION_2D_EXT); | |
3731 | ||
3732 | if (CheckExtension ("GL_SEPARABLE_2D_EXT")) | |
3733 | glDisable(GL_SEPARABLE_2D_EXT); | |
c357e426 | 3734 | |
c357e426 | 3735 | if (CheckExtension ("GL_SEPARABLE_2D_EXT")) |
3736 | glDisable(GL_HISTOGRAM_EXT); | |
3737 | ||
3738 | if (CheckExtension ("GL_MINMAX_EXT")) | |
3739 | glDisable(GL_MINMAX_EXT); | |
c357e426 | 3740 | |
c357e426 | 3741 | if (CheckExtension ("GL_TEXTURE_3D_EXT")) |
3742 | glDisable(GL_TEXTURE_3D_EXT); | |
c357e426 | 3743 | } |
3744 | #endif | |
3745 | } | |
f88457e6 | 3746 | |
3747 | // ======================================================================= | |
3748 | // function : SetColorMask | |
3749 | // purpose : | |
3750 | // ======================================================================= | |
3751 | bool OpenGl_Context::SetColorMask (bool theToWriteColor) | |
3752 | { | |
3753 | const GLboolean toWrite = theToWriteColor ? GL_TRUE : GL_FALSE; | |
3754 | glColorMask (toWrite, toWrite, toWrite, toWrite); | |
3755 | ||
3756 | const bool anOldValue = myColorMask; | |
3757 | myColorMask = theToWriteColor; | |
3758 | return anOldValue; | |
3759 | } |