#include <OpenGl_ArbDbg.hxx>
#include <OpenGl_ArbFBO.hxx>
#include <OpenGl_ExtGS.hxx>
+#include <OpenGl_ArbSamplerObject.hxx>
#include <OpenGl_ArbTexBindless.hxx>
-#include <OpenGl_GlCore44.hxx>
+#include <OpenGl_GlCore45.hxx>
#include <OpenGl_FrameBuffer.hxx>
+#include <OpenGl_FrameStats.hxx>
#include <OpenGl_Sampler.hxx>
#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_Workspace.hxx>
+#include <OpenGl_Aspects.hxx>
+#include <Graphic3d_TransformUtils.hxx>
+#include <Graphic3d_RenderingParams.hxx>
#include <Message_Messenger.hxx>
#include <Standard_ProgramError.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context,Standard_Transient)
+
#if defined(HAVE_EGL)
#include <EGL/egl.h>
#ifdef _MSC_VER
//
#else
#include <OpenGL/OpenGL.h>
+ #include <CoreGraphics/CoreGraphics.h>
#endif
#else
#include <GL/glx.h> // glXGetProcAddress()
#endif
-#ifdef HAVE_GL2PS
- #include <gl2ps.h>
- #ifdef _MSC_VER
- #pragma comment (lib, "gl2ps.lib")
- #endif
-#endif
-
-
namespace
{
static const Handle(OpenGl_Resource) NULL_GL_RESOURCE;
+ static const OpenGl_Mat4 THE_IDENTITY_MATRIX;
+
+ //! Add key-value pair to the dictionary.
+ static void addInfo (TColStd_IndexedDataMapOfStringString& theDict,
+ const TCollection_AsciiString& theKey,
+ const TCollection_AsciiString& theValue)
+ {
+ theDict.ChangeFromIndex (theDict.Add (theKey, theValue)) = theValue;
+ }
+
+ //! Add key-value pair to the dictionary.
+ static void addInfo (TColStd_IndexedDataMapOfStringString& theDict,
+ const TCollection_AsciiString& theKey,
+ const char* theValue)
+ {
+ TCollection_AsciiString aValue (theValue != NULL ? theValue : "");
+ theDict.ChangeFromIndex (theDict.Add (theKey, aValue)) = aValue;
+ }
}
// =======================================================================
core43back (NULL),
core44 (NULL),
core44back (NULL),
+ core45 (NULL),
+ core45back (NULL),
caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()),
#if defined(GL_ES_VERSION_2_0)
hasHighp (Standard_False),
hasUintIndex(Standard_False),
hasTexRGBA8(Standard_False),
+ hasFlatShading (OpenGl_FeatureNotAvailable),
#else
hasHighp (Standard_True),
hasUintIndex(Standard_True),
hasTexRGBA8(Standard_True),
+ hasFlatShading (OpenGl_FeatureInCore),
#endif
+ hasDrawBuffers (OpenGl_FeatureNotAvailable),
+ hasFloatBuffer (OpenGl_FeatureNotAvailable),
+ hasHalfFloatBuffer (OpenGl_FeatureNotAvailable),
+ hasSampleVariables (OpenGl_FeatureNotAvailable),
+ hasGeometryStage (OpenGl_FeatureNotAvailable),
+ arbDrawBuffers (Standard_False),
arbNPTW (Standard_False),
arbTexRG (Standard_False),
+ arbTexFloat (Standard_False),
+ arbSamplerObject (NULL),
arbTexBindless (NULL),
arbTBO (NULL),
arbTboRGB32 (Standard_False),
arbDbg (NULL),
arbFBO (NULL),
arbFBOBlit (NULL),
+ arbSampleShading (Standard_False),
+ extFragDepth (Standard_False),
+ extDrawBuffers (Standard_False),
extGS (NULL),
extBgra(Standard_False),
extAnis(Standard_False),
extPDS (Standard_False),
atiMem (Standard_False),
nvxMem (Standard_False),
+ oesSampleVariables (Standard_False),
+ oesStdDerivatives (Standard_False),
mySharedResources (new OpenGl_ResourcesMap()),
myDelayed (new OpenGl_DelayReleaseMap()),
myUnusedResources (new OpenGl_ResourcesStack()),
myAnisoMax (1),
myTexClamp (GL_CLAMP_TO_EDGE),
myMaxTexDim (1024),
+ myMaxTexCombined (1),
+ myMaxDumpSizeX (1024),
+ myMaxDumpSizeY (1024),
myMaxClipPlanes (6),
+ myMaxMsaaSamples(0),
+ myMaxDrawBuffers (1),
+ myMaxColorAttachments (1),
myGlVerMajor (0),
myGlVerMinor (0),
myIsInitialized (Standard_False),
myIsStereoBuffers (Standard_False),
myIsGlNormalizeEnabled (Standard_False),
+ mySpriteTexUnit (Graphic3d_TextureUnit_0),
+ myHasRayTracing (Standard_False),
+ myHasRayTracingTextures (Standard_False),
+ myHasRayTracingAdaptiveSampling (Standard_False),
+ myHasRayTracingAdaptiveSamplingAtomic (Standard_False),
+ myFrameStats (new OpenGl_FrameStats()),
#if !defined(GL_ES_VERSION_2_0)
+ myPointSpriteOrig (GL_UPPER_LEFT),
myRenderMode (GL_RENDER),
+ myPolygonMode (GL_FILL),
#else
+ myPointSpriteOrig (0),
myRenderMode (0),
+ myPolygonMode (0),
#endif
+ myToCullBackFaces (false),
myReadBuffer (0),
- myDrawBuffer (0),
+ myDrawBuffers (0, 7),
myDefaultVao (0),
- myIsGlDebugCtx (Standard_False)
+ myColorMask (true),
+ myAlphaToCoverage (false),
+ myIsGlDebugCtx (Standard_False),
+ myResolution (Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION),
+ myResolutionRatio (1.0f),
+ myLineWidthScale (1.0f),
+ myLineFeather (1.0f),
+ myRenderScale (1.0f),
+ myRenderScaleInv (1.0f)
{
+ myViewport[0] = 0;
+ myViewport[1] = 0;
+ myViewport[2] = 0;
+ myViewport[3] = 0;
+ myViewportVirt[0] = 0;
+ myViewportVirt[1] = 0;
+ myViewportVirt[2] = 0;
+ myViewportVirt[3] = 0;
+
+ myPolygonOffset.Mode = Aspect_POM_Off;
+ myPolygonOffset.Factor = 0.0f;
+ myPolygonOffset.Units = 0.0f;
+
// system-dependent fields
#if defined(HAVE_EGL)
myDisplay = (Aspect_Display )EGL_NO_DISPLAY;
}
// release shared resources if any
- if (((const Handle(Standard_Transient)& )mySharedResources)->GetRefCount() <= 1)
+ if (mySharedResources->GetRefCount() <= 1)
{
myShaderManager.Nullify();
for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources);
mySharedResources.Nullify();
myDelayed.Nullify();
- // release sampler object
- if (!myTexSampler.IsNull())
- {
- myTexSampler->Release (this);
- }
-
-#if !defined(GL_ES_VERSION_2_0)
if (arbDbg != NULL
&& myIsGlDebugCtx
&& IsValid())
{
// reset callback
+ #if !defined(GL_ES_VERSION_2_0)
void* aPtr = NULL;
- glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM_ARB, &aPtr);
+ glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM, &aPtr);
if (aPtr == this)
+ #endif
{
- arbDbg->glDebugMessageCallbackARB (NULL, NULL);
+ arbDbg->glDebugMessageCallback (NULL, NULL);
}
myIsGlDebugCtx = Standard_False;
}
-#endif
}
// =======================================================================
}
// =======================================================================
-// function : MaxDegreeOfAnisotropy
-// purpose :
-// =======================================================================
-Standard_Integer OpenGl_Context::MaxDegreeOfAnisotropy() const
-{
- return myAnisoMax;
-}
-
-// =======================================================================
-// function : MaxTextureSize
-// purpose :
-// =======================================================================
-Standard_Integer OpenGl_Context::MaxTextureSize() const
-{
- return myMaxTexDim;
-}
-
-// =======================================================================
-// function : MaxClipPlanes
+// function : ResizeViewport
// purpose :
// =======================================================================
-Standard_Integer OpenGl_Context::MaxClipPlanes() const
+void OpenGl_Context::ResizeViewport (const Standard_Integer* theRect)
{
- return myMaxClipPlanes;
+ core11fwd->glViewport (theRect[0], theRect[1], theRect[2], theRect[3]);
+ myViewport[0] = theRect[0];
+ myViewport[1] = theRect[1];
+ myViewport[2] = theRect[2];
+ myViewport[3] = theRect[3];
+ if (HasRenderScale())
+ {
+ myViewportVirt[0] = Standard_Integer(theRect[0] * myRenderScaleInv);
+ myViewportVirt[1] = Standard_Integer(theRect[1] * myRenderScaleInv);
+ myViewportVirt[2] = Standard_Integer(theRect[2] * myRenderScaleInv);
+ myViewportVirt[3] = Standard_Integer(theRect[3] * myRenderScaleInv);
+ }
+ else
+ {
+ myViewportVirt[0] = theRect[0];
+ myViewportVirt[1] = theRect[1];
+ myViewportVirt[2] = theRect[2];
+ myViewportVirt[3] = theRect[3];
+ }
}
#if !defined(GL_ES_VERSION_2_0)
void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer)
{
#if !defined(GL_ES_VERSION_2_0)
- myDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer;
- if (myDrawBuffer < GL_COLOR_ATTACHMENT0
+ const Standard_Integer aDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer;
+ if (aDrawBuffer < GL_COLOR_ATTACHMENT0
&& arbFBO != NULL)
{
arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
}
- ::glDrawBuffer (myDrawBuffer);
+ ::glDrawBuffer (aDrawBuffer);
+
+ myDrawBuffers.Init (GL_NONE);
+ myDrawBuffers.SetValue (0, aDrawBuffer);
#else
(void )theDrawBuffer;
#endif
}
+// =======================================================================
+// function : SetDrawBuffers
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetDrawBuffers (const Standard_Integer theNb, const Standard_Integer* theDrawBuffers)
+{
+ Standard_ASSERT_RETURN (hasDrawBuffers, "Multiple draw buffers feature is not supported by the context", Standard_ASSERT_DO_NOTHING());
+
+ if (myDrawBuffers.Length() < theNb)
+ {
+ // should actually never happen here
+ myDrawBuffers.Resize (0, theNb - 1, false);
+ }
+ myDrawBuffers.Init (GL_NONE);
+
+ Standard_Boolean useDefaultFbo = Standard_False;
+ for (Standard_Integer anI = 0; anI < theNb; ++anI)
+ {
+ if (theDrawBuffers[anI] < GL_COLOR_ATTACHMENT0 && theDrawBuffers[anI] != GL_NONE)
+ {
+ useDefaultFbo = Standard_True;
+ }
+ else
+ {
+ myDrawBuffers.SetValue (anI, theDrawBuffers[anI]);
+ }
+ }
+ if (arbFBO != NULL && useDefaultFbo)
+ {
+ arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
+ }
+
+ myFuncs->glDrawBuffers (theNb, (const GLenum*)theDrawBuffers);
+}
+
+// =======================================================================
+// function : SetCullBackFaces
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetCullBackFaces (bool theToEnable)
+{
+ if (myToCullBackFaces == theToEnable)
+ {
+ return;
+ }
+
+ myToCullBackFaces = theToEnable;
+ if (theToEnable)
+ {
+ //glCullFace (GL_BACK); GL_BACK by default
+ core11fwd->glEnable (GL_CULL_FACE);
+ }
+ else
+ {
+ core11fwd->glDisable (GL_CULL_FACE);
+ }
+}
+
// =======================================================================
// function : FetchState
// purpose :
::glGetIntegerv (GL_RENDER_MODE, &myRenderMode);
}
- // cache buffers state
+ // cache read buffers state
::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer);
- ::glGetIntegerv (GL_DRAW_BUFFER, &myDrawBuffer);
+
+ // cache draw buffers state
+ if (myDrawBuffers.Length() < myMaxDrawBuffers)
+ {
+ myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false);
+ }
+ myDrawBuffers.Init (GL_NONE);
+
+ Standard_Integer aDrawBuffer = GL_NONE;
+ if (myMaxDrawBuffers == 1)
+ {
+ ::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer);
+ myDrawBuffers.SetValue (0, aDrawBuffer);
+ }
+ else
+ {
+ for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI)
+ {
+ ::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer);
+ myDrawBuffers.SetValue (anI, aDrawBuffer);
+ }
+ }
#endif
}
{
#if defined(HAVE_EGL)
if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
- || (EGLSurface )myWindow == EGL_NO_SURFACE
|| (EGLContext )myGContext == EGL_NO_CONTEXT)
{
return Standard_False;
{
#if defined(HAVE_EGL)
if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
- || (EGLSurface )myWindow == EGL_NO_SURFACE
|| (EGLContext )myGContext == EGL_NO_CONTEXT)
{
Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE)
{
// if there is no current context it might be impossible to use glGetError() correctly
- PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB,
+ PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
"eglMakeCurrent() has failed!");
myIsInitialized = Standard_False;
return Standard_False;
aMsg += (Standard_ExtString )aMsgBuff;
LocalFree (aMsgBuff);
}
- PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
+ PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH, aMsg);
myIsInitialized = Standard_False;
return Standard_False;
}
if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
{
// if there is no current context it might be impossible to use glGetError() correctly
- PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB,
+ PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
"glXMakeCurrent() has failed!");
myIsInitialized = Standard_False;
return Standard_False;
#if defined(HAVE_EGL)
return (void* )eglGetProcAddress (theFuncName);
#elif defined(_WIN32)
- return wglGetProcAddress (theFuncName);
+ return (void* )wglGetProcAddress (theFuncName);
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL;
#else
// function : ResetErrors
// purpose :
// =======================================================================
-void OpenGl_Context::ResetErrors()
+bool OpenGl_Context::ResetErrors (const bool theToPrintErrors)
{
- while (glGetError() != GL_NO_ERROR)
+ int aPrevErr = 0;
+ int anErr = ::glGetError();
+ const bool hasError = anErr != GL_NO_ERROR;
+ if (!theToPrintErrors)
{
- //
+ for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError())
+ {
+ //
+ }
+ return hasError;
+ }
+
+ for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError())
+ {
+ TCollection_ExtendedString anErrId;
+ switch (anErr)
+ {
+ case GL_INVALID_ENUM: anErrId = "GL_INVALID_ENUM"; break;
+ case GL_INVALID_VALUE: anErrId = "GL_INVALID_VALUE"; break;
+ case GL_INVALID_OPERATION: anErrId = "GL_INVALID_OPERATION"; break;
+ #ifdef GL_STACK_OVERFLOW
+ case GL_STACK_OVERFLOW: anErrId = "GL_STACK_OVERFLOW"; break;
+ case GL_STACK_UNDERFLOW: anErrId = "GL_STACK_UNDERFLOW"; break;
+ #endif
+ case GL_OUT_OF_MEMORY: anErrId = "GL_OUT_OF_MEMORY"; break;
+ case GL_INVALID_FRAMEBUFFER_OPERATION:
+ anErrId = "GL_INVALID_FRAMEBUFFER_OPERATION";
+ break;
+ default:
+ anErrId = TCollection_ExtendedString("#") + anErr;
+ break;
+ }
+
+ const TCollection_ExtendedString aMsg = TCollection_ExtendedString ("Unhandled GL error: ") + anErrId;
+ PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_OTHER, 0, GL_DEBUG_SEVERITY_LOW, aMsg);
}
+ return hasError;
}
// =======================================================================
static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN";
static Standard_CString THE_DBGMSG_SOURCES[] =
{
- ".OpenGL", // GL_DEBUG_SOURCE_API_ARB
- ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB
- ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER_ARB
- ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY_ARB
- "", // GL_DEBUG_SOURCE_APPLICATION_ARB
- ".Other" // GL_DEBUG_SOURCE_OTHER_ARB
+ ".OpenGL", // GL_DEBUG_SOURCE_API
+ ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM
+ ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER
+ ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY
+ "", // GL_DEBUG_SOURCE_APPLICATION
+ ".Other" // GL_DEBUG_SOURCE_OTHER
};
static Standard_CString THE_DBGMSG_TYPES[] =
{
- "Error", // GL_DEBUG_TYPE_ERROR_ARB
- "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB
- "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB
- "Portability", // GL_DEBUG_TYPE_PORTABILITY_ARB
- "Performance", // GL_DEBUG_TYPE_PERFORMANCE_ARB
- "Other" // GL_DEBUG_TYPE_OTHER_ARB
+ "Error", // GL_DEBUG_TYPE_ERROR
+ "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR
+ "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR
+ "Portability", // GL_DEBUG_TYPE_PORTABILITY
+ "Performance", // GL_DEBUG_TYPE_PERFORMANCE
+ "Other" // GL_DEBUG_TYPE_OTHER
};
-static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH_ARB
-static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM_ARB
-static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW_ARB
+static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH
+static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM
+static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW
-#if !defined(GL_ES_VERSION_2_0)
//! Callback for GL_ARB_debug_output extension
static void APIENTRY debugCallbackWrap(unsigned int theSource,
unsigned int theType,
OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage);
}
-#endif
// =======================================================================
// function : PushMessage
const TCollection_ExtendedString& theMessage)
{
if (caps->suppressExtraMsg
- && theSource >= GL_DEBUG_SOURCE_API_ARB
- && theSource <= GL_DEBUG_SOURCE_OTHER_ARB
- && myFilters[theSource - GL_DEBUG_SOURCE_API_ARB].Contains (theId))
+ && theSource >= GL_DEBUG_SOURCE_API
+ && theSource <= GL_DEBUG_SOURCE_OTHER
+ && myFilters[theSource - GL_DEBUG_SOURCE_API].Contains (theId))
{
return;
}
- Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API_ARB
- && theSource <= GL_DEBUG_SOURCE_OTHER_ARB)
- ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API_ARB]
+ Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API
+ && theSource <= GL_DEBUG_SOURCE_OTHER)
+ ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API]
: THE_DBGMSG_UNKNOWN;
- Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR_ARB
- && theType <= GL_DEBUG_TYPE_OTHER_ARB)
- ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR_ARB]
+ Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR
+ && theType <= GL_DEBUG_TYPE_OTHER)
+ ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR]
: THE_DBGMSG_UNKNOWN;
- Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB
+ Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH
? THE_DBGMSG_SEV_HIGH
- : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
+ : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM
? THE_DBGMSG_SEV_MEDIUM
: THE_DBGMSG_SEV_LOW);
- Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB
+ Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH
? Message_Alarm
- : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
+ : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM
? Message_Warning
: Message_Info);
Standard_Boolean OpenGl_Context::ExcludeMessage (const unsigned int theSource,
const unsigned int theId)
{
- return theSource >= GL_DEBUG_SOURCE_API_ARB
- && theSource <= GL_DEBUG_SOURCE_OTHER_ARB
- && myFilters[theSource - GL_DEBUG_SOURCE_API_ARB].Add (theId);
+ return theSource >= GL_DEBUG_SOURCE_API
+ && theSource <= GL_DEBUG_SOURCE_OTHER
+ && myFilters[theSource - GL_DEBUG_SOURCE_API].Add (theId);
}
// =======================================================================
Standard_Boolean OpenGl_Context::IncludeMessage (const unsigned int theSource,
const unsigned int theId)
{
- return theSource >= GL_DEBUG_SOURCE_API_ARB
- && theSource <= GL_DEBUG_SOURCE_OTHER_ARB
- && myFilters[theSource - GL_DEBUG_SOURCE_API_ARB].Remove (theId);
+ return theSource >= GL_DEBUG_SOURCE_API
+ && theSource <= GL_DEBUG_SOURCE_OTHER
+ && myFilters[theSource - GL_DEBUG_SOURCE_API].Remove (theId);
}
// =======================================================================
// function : checkWrongVersion
// purpose :
// ======================================================================
-void OpenGl_Context::checkWrongVersion (const Standard_Integer theGlVerMajor,
- const Standard_Integer theGlVerMinor)
+void OpenGl_Context::checkWrongVersion (Standard_Integer theGlVerMajor, Standard_Integer theGlVerMinor,
+ const char* theLastFailedProc)
{
if (!IsGlGreaterEqual (theGlVerMajor, theGlVerMinor))
{
return;
}
- TCollection_ExtendedString aMsg = TCollection_ExtendedString()
- + "Error! OpenGL context reports version "
- + myGlVerMajor + "." + myGlVerMinor
- + " but does not export required functions for "
- + theGlVerMajor + "." + theGlVerMinor;
- PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
- GL_DEBUG_TYPE_ERROR_ARB,
- 0,
- GL_DEBUG_SEVERITY_HIGH_ARB,
- aMsg);
+ PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
+ TCollection_AsciiString()
+ + "Error! OpenGL context reports version "
+ + myGlVerMajor + "." + myGlVerMinor
+ + " but does not export required functions for " + theGlVerMajor + "." + theGlVerMinor
+ + " (" + (theLastFailedProc != NULL ? theLastFailedProc : "") + ")\n"
+ + "Please report this issue to OpenGL driver vendor '" + myVendor + "'");
+
+ // lower internal version
+ if (theGlVerMinor > 0)
+ {
+ myGlVerMajor = theGlVerMajor;
+ myGlVerMinor = theGlVerMinor - 1;
+ return;
+ }
+#if defined(GL_ES_VERSION_2_0)
+ switch (theGlVerMajor)
+ {
+ case 3: myGlVerMajor = 2; myGlVerMinor = 0; return;
+ }
+#else
+ switch (theGlVerMajor)
+ {
+ case 2: myGlVerMajor = 1; myGlVerMinor = 5; return;
+ case 3: myGlVerMajor = 2; myGlVerMinor = 1; return;
+ case 4: myGlVerMajor = 3; myGlVerMinor = 3; return;
+ }
+#endif
}
// =======================================================================
// read version
myGlVerMajor = 0;
myGlVerMinor = 0;
+ myMaxMsaaSamples = 0;
+ myMaxDrawBuffers = 1;
+ myMaxColorAttachments = 1;
ReadGlVersion (myGlVerMajor, myGlVerMinor);
myVendor = (const char* )::glGetString (GL_VENDOR);
+ myVendor.LowerCase();
+ if (!caps->ffpEnable
+ && !IsGlGreaterEqual (2, 0))
+ {
+ caps->ffpEnable = true;
+ TCollection_ExtendedString aMsg =
+ TCollection_ExtendedString("OpenGL driver is too old! Context info:\n")
+ + " Vendor: " + (const char* )::glGetString (GL_VENDOR) + "\n"
+ + " Renderer: " + (const char* )::glGetString (GL_RENDERER) + "\n"
+ + " Version: " + (const char* )::glGetString (GL_VERSION) + "\n"
+ + " Fallback using deprecated fixed-function pipeline.\n"
+ + " Visualization might work incorrectly.\n"
+ " Consider upgrading the graphics driver.";
+ PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
+ }
#if defined(GL_ES_VERSION_2_0)
(void )theIsCoreProfile;
const bool isCoreProfile = false;
#else
- if (myVendor.Search ("NVIDIA") != -1)
+ if (myVendor.Search ("nvidia") != -1)
{
// Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW)
// will use VIDEO memory as the source for buffer object operations.
- ExcludeMessage (GL_DEBUG_SOURCE_API_ARB, 131185);
+ ExcludeMessage (GL_DEBUG_SOURCE_API, 131185);
}
if (IsGlGreaterEqual (3, 0))
{
core43back = NULL;
core44 = NULL;
core44back = NULL;
+ core45 = NULL;
+ core45back = NULL;
arbTBO = NULL;
arbTboRGB32 = Standard_False;
arbIns = NULL;
extGS = NULL;
myDefaultVao = 0;
+ //! Make record shorter to retrieve function pointer using variable with same name
+ const char* aLastFailedProc = NULL;
+ #define FindProcShort(theFunc) FindProcVerbose(aLastFailedProc, #theFunc, myFuncs->theFunc)
+
#if defined(GL_ES_VERSION_2_0)
hasTexRGBA8 = IsGlGreaterEqual (3, 0)
|| CheckExtension ("GL_EXT_texture_rg");
extBgra = CheckExtension ("GL_EXT_texture_format_BGRA8888");
extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
- extPDS = CheckExtension ("GL_OES_packed_depth_stencil");
+ extPDS = IsGlGreaterEqual (3, 0)
+ || CheckExtension ("GL_OES_packed_depth_stencil");
core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs));
if (IsGlGreaterEqual (2, 0))
arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs));
}
if (IsGlGreaterEqual (3, 0)
- && FindProc ("glBlitFramebuffer", myFuncs->glBlitFramebuffer))
+ && FindProcShort (glBlitFramebuffer))
{
arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs));
}
+ if (IsGlGreaterEqual (3, 0)
+ && FindProcShort (glGenSamplers)
+ && FindProcShort (glDeleteSamplers)
+ && FindProcShort (glIsSampler)
+ && FindProcShort (glBindSampler)
+ && FindProcShort (glSamplerParameteri)
+ && FindProcShort (glSamplerParameteriv)
+ && FindProcShort (glSamplerParameterf)
+ && FindProcShort (glSamplerParameterfv)
+ && FindProcShort (glGetSamplerParameteriv)
+ && FindProcShort (glGetSamplerParameterfv))
+ //&& FindProcShort (glSamplerParameterIiv) // only on Desktop or with extensions GL_OES_texture_border_clamp/GL_EXT_texture_border_clamp
+ //&& FindProcShort (glSamplerParameterIuiv)
+ //&& FindProcShort (glGetSamplerParameterIiv)
+ //&& FindProcShort (glGetSamplerParameterIuiv))
+ {
+ arbSamplerObject = (OpenGl_ArbSamplerObject* )(&(*myFuncs));
+ }
+ extFragDepth = !IsGlGreaterEqual(3, 0)
+ && CheckExtension ("GL_EXT_frag_depth");
+ if (IsGlGreaterEqual (3, 1)
+ && FindProcShort (glTexStorage2DMultisample))
+ {
+ // MSAA RenderBuffers have been defined in OpenGL ES 3.0,
+ // but MSAA Textures - only in OpenGL ES 3.1+
+ ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples);
+ }
hasUintIndex = IsGlGreaterEqual (3, 0)
|| CheckExtension ("GL_OES_element_index_uint");
{
hasHighp = Standard_True;
}
+
+ arbTexFloat = IsGlGreaterEqual (3, 0)
+ && FindProcShort (glTexImage3D);
+
+ const Standard_Boolean hasTexBuffer32 = IsGlGreaterEqual (3, 2) && FindProcShort (glTexBuffer);
+ const Standard_Boolean hasExtTexBuffer = CheckExtension ("GL_EXT_texture_buffer") && FindProc ("glTexBufferEXT", myFuncs->glTexBuffer);
+
+ if (hasTexBuffer32 || hasExtTexBuffer)
+ {
+ arbTBO = reinterpret_cast<OpenGl_ArbTBO*> (myFuncs.get());
+ }
+
+ // initialize debug context extension
+ if (CheckExtension ("GL_KHR_debug"))
+ {
+ // this functionality become a part of OpenGL ES 3.2
+ arbDbg = NULL;
+ // According to GL_KHR_debug spec, all functions should have KHR suffix.
+ // However, some implementations can export these functions without suffix.
+ if (FindProc ("glDebugMessageControlKHR", myFuncs->glDebugMessageControl)
+ && FindProc ("glDebugMessageInsertKHR", myFuncs->glDebugMessageInsert)
+ && FindProc ("glDebugMessageCallbackKHR", myFuncs->glDebugMessageCallback)
+ && FindProc ("glGetDebugMessageLogKHR", myFuncs->glGetDebugMessageLog))
+ {
+ arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
+ }
+
+ if (arbDbg != NULL
+ && caps->contextDebug)
+ {
+ // setup default callback
+ myIsGlDebugCtx = Standard_True;
+ arbDbg->glDebugMessageCallback (debugCallbackWrap, this);
+ ::glEnable (GL_DEBUG_OUTPUT);
+ if (caps->contextSyncDebug)
+ {
+ // note that some broken implementations (e.g. simulators) might generate error message on this call
+ ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
+ }
+ }
+ }
+
+ extDrawBuffers = CheckExtension ("GL_EXT_draw_buffers") && FindProc ("glDrawBuffersEXT", myFuncs->glDrawBuffers);
+ arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers") && FindProc ("glDrawBuffersARB", myFuncs->glDrawBuffers);
+
+ if (IsGlGreaterEqual (3, 0) && FindProcShort (glDrawBuffers))
+ {
+ hasDrawBuffers = OpenGl_FeatureInCore;
+ }
+ else if (extDrawBuffers || arbDrawBuffers)
+ {
+ hasDrawBuffers = OpenGl_FeatureInExtensions;
+ }
+
+ hasFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore :
+ CheckExtension ("GL_EXT_color_buffer_float") ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable;
+ hasHalfFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore :
+ CheckExtension ("GL_EXT_color_buffer_half_float") ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable;
+
+ oesSampleVariables = CheckExtension ("GL_OES_sample_variables");
+ oesStdDerivatives = CheckExtension ("GL_OES_standard_derivatives");
+ hasSampleVariables = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore :
+ oesSampleVariables ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable;
+ // without hasHighp, dFdx/dFdy precision is considered too low for flat shading (visual artifacts)
+ hasFlatShading = IsGlGreaterEqual (3, 0)
+ ? OpenGl_FeatureInCore
+ : (oesStdDerivatives && hasHighp
+ ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable);
+ if (!IsGlGreaterEqual (3, 1)
+ && myVendor.Search("qualcomm") != -1)
+ {
+ // dFdx/dFdy are completely broken on tested Adreno devices with versions below OpenGl ES 3.1
+ hasFlatShading = OpenGl_FeatureNotAvailable;
+ }
+
+ hasGeometryStage = IsGlGreaterEqual (3, 2)
+ ? OpenGl_FeatureInCore
+ : (CheckExtension ("GL_EXT_geometry_shader") && CheckExtension ("GL_EXT_shader_io_blocks")
+ ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable);
#else
myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP;
hasTexRGBA8 = Standard_True;
- arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two");
- extBgra = CheckExtension ("GL_EXT_bgra");
- extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
- extPDS = CheckExtension ("GL_EXT_packed_depth_stencil");
- atiMem = CheckExtension ("GL_ATI_meminfo");
- nvxMem = CheckExtension ("GL_NVX_gpu_memory_info");
+ arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers");
+ arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two");
+ arbTexFloat = IsGlGreaterEqual (3, 0)
+ || CheckExtension ("GL_ARB_texture_float");
+ arbSampleShading = CheckExtension ("GL_ARB_sample_shading");
+ extBgra = CheckExtension ("GL_EXT_bgra");
+ extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
+ extPDS = CheckExtension ("GL_EXT_packed_depth_stencil");
+ atiMem = CheckExtension ("GL_ATI_meminfo");
+ nvxMem = CheckExtension ("GL_NVX_gpu_memory_info");
+
+ hasDrawBuffers = IsGlGreaterEqual (2, 0) ? OpenGl_FeatureInCore :
+ arbDrawBuffers ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable;
+
+ hasFloatBuffer = hasHalfFloatBuffer = IsGlGreaterEqual (3, 0) ? OpenGl_FeatureInCore :
+ CheckExtension ("GL_ARB_color_buffer_float") ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable;
+
+ hasGeometryStage = IsGlGreaterEqual (3, 2)
+ ? OpenGl_FeatureInCore
+ : OpenGl_FeatureNotAvailable;
+
+ hasSampleVariables = IsGlGreaterEqual (4, 0) ? OpenGl_FeatureInCore :
+ arbSampleShading ? OpenGl_FeatureInExtensions
+ : OpenGl_FeatureNotAvailable;
GLint aStereo = GL_FALSE;
glGetIntegerv (GL_STEREO, &aStereo);
glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes);
#endif
+ if (hasDrawBuffers)
+ {
+ glGetIntegerv (GL_MAX_DRAW_BUFFERS, &myMaxDrawBuffers);
+ glGetIntegerv (GL_MAX_COLOR_ATTACHMENTS, &myMaxColorAttachments);
+ if (myDrawBuffers.Length() < myMaxDrawBuffers)
+ {
+ myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false);
+ }
+ }
+
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim);
+ if (IsGlGreaterEqual (2, 0))
+ {
+ glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &myMaxTexCombined);
+ }
+#if !defined(GL_ES_VERSION_2_0)
+ else if (IsGlGreaterEqual (1, 3))
+ {
+ // this is a maximum of texture units for FFP functionality,
+ // dramatically smaller than combined texture units available for GLSL
+ glGetIntegerv (GL_MAX_TEXTURE_UNITS, &myMaxTexCombined);
+ }
+#endif
+ mySpriteTexUnit = myMaxTexCombined >= 2
+ ? Graphic3d_TextureUnit_1
+ : Graphic3d_TextureUnit_0;
+
+ GLint aMaxVPortSize[2] = {0, 0};
+ glGetIntegerv (GL_MAX_VIEWPORT_DIMS, aMaxVPortSize);
+ myMaxDumpSizeX = Min (aMaxVPortSize[0], myMaxTexDim);
+ myMaxDumpSizeY = Min (aMaxVPortSize[1], myMaxTexDim);
+ if (myVendor == "intel")
+ {
+ // Intel drivers have known bug with empty dump for images with width>=5462
+ myMaxDumpSizeX = Min (myMaxDumpSizeX, 4096);
+ }
if (extAnis)
{
glGetIntegerv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &myAnisoMax);
}
- myClippingState.Init (myMaxClipPlanes);
+ myClippingState.Init();
#if !defined(GL_ES_VERSION_2_0)
bool has42 = false;
bool has43 = false;
bool has44 = false;
-
- //! Make record shorter to retrieve function pointer using variable with same name
- #define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc)
+ bool has45 = false;
// retrieve platform-dependent extensions
#if defined(HAVE_EGL)
FindProcShort (wglDXLockObjectsNV);
FindProcShort (wglDXUnlockObjectsNV);
}
+ if (CheckExtension (aWglExts, "WGL_AMD_gpu_association"))
+ {
+ FindProcShort (wglGetGPUIDsAMD);
+ FindProcShort (wglGetGPUInfoAMD);
+ FindProcShort (wglGetContextGPUIDAMD);
+ }
}
#elif defined(__APPLE__)
//
{
FindProcShort (glXSwapIntervalSGI);
}
- //extSwapTear = CheckExtension (aGlxExts, "GLX_EXT_swap_control_tear");
-#endif
-
- // initialize debug context extension
- if (CheckExtension ("GL_ARB_debug_output"))
- {
- arbDbg = NULL;
- if (FindProcShort (glDebugMessageControlARB)
- && FindProcShort (glDebugMessageInsertARB)
- && FindProcShort (glDebugMessageCallbackARB)
- && FindProcShort (glGetDebugMessageLogARB))
- {
- arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
- }
- if (arbDbg != NULL
- && caps->contextDebug)
+ if (CheckExtension (aGlxExts, "GLX_MESA_query_renderer"))
{
- // setup default callback
- myIsGlDebugCtx = Standard_True;
- arbDbg->glDebugMessageCallbackARB (debugCallbackWrap, this);
- if (caps->contextSyncDebug)
- {
- ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
- }
+ FindProcShort (glXQueryRendererIntegerMESA);
+ FindProcShort (glXQueryCurrentRendererIntegerMESA);
+ FindProcShort (glXQueryRendererStringMESA);
+ FindProcShort (glXQueryCurrentRendererStringMESA);
}
- }
+ //extSwapTear = CheckExtension (aGlxExts, "GLX_EXT_swap_control_tear");
+#endif
// load OpenGL 1.2 new functions
has12 = IsGlGreaterEqual (1, 2)
&& FindProcShort (glTexImage3D)
&& FindProcShort (glTexSubImage3D)
&& FindProcShort (glCopyTexSubImage3D);
+ if (!has12)
+ {
+ checkWrongVersion (1, 2, aLastFailedProc);
+ }
// load OpenGL 1.3 new functions
has13 = IsGlGreaterEqual (1, 3)
&& FindProcShort (glMultTransposeMatrixf)
&& FindProcShort (glMultTransposeMatrixd);
}
+ if (!has13)
+ {
+ checkWrongVersion (1, 3, aLastFailedProc);
+ }
// load OpenGL 1.4 new functions
has14 = IsGlGreaterEqual (1, 4)
&& FindProcShort (glPointParameterfv)
&& FindProcShort (glPointParameteri)
&& FindProcShort (glPointParameteriv);
+ if (!has14)
+ {
+ checkWrongVersion (1, 4, aLastFailedProc);
+ }
// load OpenGL 1.5 new functions
has15 = IsGlGreaterEqual (1, 5)
&& FindProcShort (glUnmapBuffer)
&& FindProcShort (glGetBufferParameteriv)
&& FindProcShort (glGetBufferPointerv);
+ if (has15)
+ {
+ if (!isCoreProfile)
+ {
+ core15 = (OpenGl_GlCore15* )(&(*myFuncs));
+ }
+ core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs));
+ }
+ else
+ {
+ checkWrongVersion (1, 5, aLastFailedProc);
+ }
// load OpenGL 2.0 new functions
has20 = IsGlGreaterEqual (2, 0)
&& FindProcShort (glVertexAttrib4uiv)
&& FindProcShort (glVertexAttrib4usv)
&& FindProcShort (glVertexAttribPointer);
+ if (has20)
+ {
+ const char* aGlslVer = (const char* )::glGetString (GL_SHADING_LANGUAGE_VERSION);
+ if (aGlslVer == NULL
+ || *aGlslVer == '\0')
+ {
+ // broken context has been detected
+ PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
+ TCollection_AsciiString("Error! OpenGL context reports version ")
+ + myGlVerMajor + "." + myGlVerMinor + " but reports wrong GLSL version");
+ myGlVerMajor = 1;
+ myGlVerMinor = 5;
+ }
+ else
+ {
+ if (!isCoreProfile)
+ {
+ core20 = (OpenGl_GlCore20* )(&(*myFuncs));
+ }
+ core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs));
+ }
+ }
+ else
+ {
+ checkWrongVersion (2, 0, aLastFailedProc);
+ }
// load OpenGL 2.1 new functions
has21 = IsGlGreaterEqual (2, 1)
&& FindProcShort (glUniformMatrix4x2fv)
&& FindProcShort (glUniformMatrix3x4fv)
&& FindProcShort (glUniformMatrix4x3fv);
+ if (!has21)
+ {
+ checkWrongVersion (2, 1, aLastFailedProc);
+ }
// load GL_ARB_framebuffer_object (added to OpenGL 3.0 core)
const bool hasFBO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_framebuffer_object"))
&& FindProcShort (glClearBufferfv)
&& FindProcShort (glClearBufferfi)
&& FindProcShort (glGetStringi);
+ if (!has30)
+ {
+ checkWrongVersion (3, 0, aLastFailedProc);
+ }
// load GL_ARB_uniform_buffer_object (added to OpenGL 3.1 core)
const bool hasUBO = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_uniform_buffer_object"))
&& FindProcShort (glDrawElementsInstanced)
&& FindProcShort (glTexBuffer)
&& FindProcShort (glPrimitiveRestartIndex);
+ if (has31)
+ {
+ arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
+ arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
+ }
+ else
+ {
+ checkWrongVersion (3, 1, aLastFailedProc);
+
+ // initialize TBO extension (ARB)
+ if (CheckExtension ("GL_ARB_texture_buffer_object")
+ && FindProc ("glTexBufferARB", myFuncs->glTexBuffer))
+ {
+ arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
+ }
+
+ // initialize hardware instancing extension (ARB)
+ if (CheckExtension ("GL_ARB_draw_instanced")
+ && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced)
+ && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced))
+ {
+ arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
+ }
+ }
+
+ arbTboRGB32 = CheckExtension ("GL_ARB_texture_buffer_object_rgb32");
// load GL_ARB_draw_elements_base_vertex (added to OpenGL 3.2 core)
const bool hasDrawElemsBaseVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_draw_elements_base_vertex"))
&& FindProcShort (glGetInteger64i_v)
&& FindProcShort (glGetBufferParameteri64v)
&& FindProcShort (glFramebufferTexture);
+ if (has32)
+ {
+ core32 = (OpenGl_GlCore32* )(&(*myFuncs));
+ if (isCoreProfile)
+ {
+ core32->glGenVertexArrays (1, &myDefaultVao);
+ }
+ else
+ {
+ core32back = (OpenGl_GlCore32Back* )(&(*myFuncs));
+ }
+ ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples);
+ }
+ else
+ {
+ checkWrongVersion (3, 2, aLastFailedProc);
+ }
// load GL_ARB_blend_func_extended (added to OpenGL 3.3 core)
const bool hasBlendFuncExtended = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_blend_func_extended"))
&& FindProcShort (glGetSamplerParameterIiv)
&& FindProcShort (glGetSamplerParameterfv)
&& FindProcShort (glGetSamplerParameterIuiv);
+ if (hasSamplerObjects)
+ {
+ arbSamplerObject = (OpenGl_ArbSamplerObject* )(&(*myFuncs));
+ }
// load GL_ARB_timer_query (added to OpenGL 3.3 core)
const bool hasTimerQuery = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_timer_query"))
&& hasTimerQuery
&& hasVertType21010101rev
&& FindProcShort (glVertexAttribDivisor);
+ if (has33)
+ {
+ core33 = (OpenGl_GlCore33* )(&(*myFuncs));
+ if (!isCoreProfile)
+ {
+ core33back = (OpenGl_GlCore33Back* )(&(*myFuncs));
+ }
+ }
+ else
+ {
+ checkWrongVersion (3, 3, aLastFailedProc);
+ }
// load GL_ARB_draw_indirect (added to OpenGL 4.0 core)
const bool hasDrawIndirect = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_draw_indirect"))
&& FindProcShort (glBlendEquationSeparatei)
&& FindProcShort (glBlendFunci)
&& FindProcShort (glBlendFuncSeparatei);
-
- // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core)
+ if (has40)
+ {
+ arbTboRGB32 = Standard_True; // in core since OpenGL 4.0
+ }
+ else
+ {
+ checkWrongVersion (4, 0, aLastFailedProc);
+ }
+
+ // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core)
const bool hasES2Compatibility = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_ES2_compatibility"))
&& FindProcShort (glReleaseShaderCompiler)
&& FindProcShort (glShaderBinary)
&& hasSeparateShaderObjects
&& hasVertAttrib64bit
&& hasViewportArray;
+ if (has41)
+ {
+ core41 = (OpenGl_GlCore41* )(&(*myFuncs));
+ if (!isCoreProfile)
+ {
+ core41back = (OpenGl_GlCore41Back* )(&(*myFuncs));
+ }
+ }
+ else
+ {
+ checkWrongVersion (4, 1, aLastFailedProc);
+ }
// load GL_ARB_base_instance (added to OpenGL 4.2 core)
const bool hasBaseInstance = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_base_instance"))
&& hasShaderAtomicCounters
&& hasShaderImgLoadStore
&& hasTextureStorage;
+ if (has42)
+ {
+ core42 = (OpenGl_GlCore42* )(&(*myFuncs));
+ if (!isCoreProfile)
+ {
+ core42back = (OpenGl_GlCore42Back* )(&(*myFuncs));
+ }
+ }
+ else
+ {
+ checkWrongVersion (4, 2, aLastFailedProc);
+ }
has43 = IsGlGreaterEqual (4, 3)
&& FindProcShort (glClearBufferData)
&& FindProcShort (glGetObjectLabel)
&& FindProcShort (glObjectPtrLabel)
&& FindProcShort (glGetObjectPtrLabel);
+ if (has43)
+ {
+ core43 = (OpenGl_GlCore43* )(&(*myFuncs));
+ if (!isCoreProfile)
+ {
+ core43back = (OpenGl_GlCore43Back* )(&(*myFuncs));
+ }
+ }
+ else
+ {
+ checkWrongVersion (4, 3, aLastFailedProc);
+ }
// load GL_ARB_clear_texture (added to OpenGL 4.4 core)
bool arbTexClear = (IsGlGreaterEqual (4, 4) || CheckExtension ("GL_ARB_clear_texture"))
&& FindProcShort (glBindSamplers)
&& FindProcShort (glBindImageTextures)
&& FindProcShort (glBindVertexBuffers);
-
- // initialize TBO extension (ARB)
- if (!has31
- && CheckExtension ("GL_ARB_texture_buffer_object")
- && FindProc ("glTexBufferARB", myFuncs->glTexBuffer))
+ if (has44)
{
- arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
+ core44 = (OpenGl_GlCore44* )(&(*myFuncs));
+ if (!isCoreProfile)
+ {
+ core44back = (OpenGl_GlCore44Back* )(&(*myFuncs));
+ }
+ }
+ else
+ {
+ checkWrongVersion (4, 4, aLastFailedProc);
+ }
+
+ has45 = IsGlGreaterEqual (4, 5)
+ && FindProcShort (glBindVertexBuffers)
+ && FindProcShort (glClipControl)
+ && FindProcShort (glCreateTransformFeedbacks)
+ && FindProcShort (glTransformFeedbackBufferBase)
+ && FindProcShort (glTransformFeedbackBufferRange)
+ && FindProcShort (glGetTransformFeedbackiv)
+ && FindProcShort (glGetTransformFeedbacki_v)
+ && FindProcShort (glGetTransformFeedbacki64_v)
+ && FindProcShort (glCreateBuffers)
+ && FindProcShort (glNamedBufferStorage)
+ && FindProcShort (glNamedBufferData)
+ && FindProcShort (glNamedBufferSubData)
+ && FindProcShort (glCopyNamedBufferSubData)
+ && FindProcShort (glClearNamedBufferData)
+ && FindProcShort (glClearNamedBufferSubData)
+ && FindProcShort (glMapNamedBuffer)
+ && FindProcShort (glMapNamedBufferRange)
+ && FindProcShort (glUnmapNamedBuffer)
+ && FindProcShort (glFlushMappedNamedBufferRange)
+ && FindProcShort (glGetNamedBufferParameteriv)
+ && FindProcShort (glGetNamedBufferParameteri64v)
+ && FindProcShort (glGetNamedBufferPointerv)
+ && FindProcShort (glGetNamedBufferSubData)
+ && FindProcShort (glCreateFramebuffers)
+ && FindProcShort (glNamedFramebufferRenderbuffer)
+ && FindProcShort (glNamedFramebufferParameteri)
+ && FindProcShort (glNamedFramebufferTexture)
+ && FindProcShort (glNamedFramebufferTextureLayer)
+ && FindProcShort (glNamedFramebufferDrawBuffer)
+ && FindProcShort (glNamedFramebufferDrawBuffers)
+ && FindProcShort (glNamedFramebufferReadBuffer)
+ && FindProcShort (glInvalidateNamedFramebufferData)
+ && FindProcShort (glInvalidateNamedFramebufferSubData)
+ && FindProcShort (glClearNamedFramebufferiv)
+ && FindProcShort (glClearNamedFramebufferuiv)
+ && FindProcShort (glClearNamedFramebufferfv)
+ && FindProcShort (glClearNamedFramebufferfi)
+ && FindProcShort (glBlitNamedFramebuffer)
+ && FindProcShort (glCheckNamedFramebufferStatus)
+ && FindProcShort (glGetNamedFramebufferParameteriv)
+ && FindProcShort (glGetNamedFramebufferAttachmentParameteriv)
+ && FindProcShort (glCreateRenderbuffers)
+ && FindProcShort (glNamedRenderbufferStorage)
+ && FindProcShort (glNamedRenderbufferStorageMultisample)
+ && FindProcShort (glGetNamedRenderbufferParameteriv)
+ && FindProcShort (glCreateTextures)
+ && FindProcShort (glTextureBuffer)
+ && FindProcShort (glTextureBufferRange)
+ && FindProcShort (glTextureStorage1D)
+ && FindProcShort (glTextureStorage2D)
+ && FindProcShort (glTextureStorage3D)
+ && FindProcShort (glTextureStorage2DMultisample)
+ && FindProcShort (glTextureStorage3DMultisample)
+ && FindProcShort (glTextureSubImage1D)
+ && FindProcShort (glTextureSubImage2D)
+ && FindProcShort (glTextureSubImage3D)
+ && FindProcShort (glCompressedTextureSubImage1D)
+ && FindProcShort (glCompressedTextureSubImage2D)
+ && FindProcShort (glCompressedTextureSubImage3D)
+ && FindProcShort (glCopyTextureSubImage1D)
+ && FindProcShort (glCopyTextureSubImage2D)
+ && FindProcShort (glCopyTextureSubImage3D)
+ && FindProcShort (glTextureParameterf)
+ && FindProcShort (glTextureParameterfv)
+ && FindProcShort (glTextureParameteri)
+ && FindProcShort (glTextureParameterIiv)
+ && FindProcShort (glTextureParameterIuiv)
+ && FindProcShort (glTextureParameteriv)
+ && FindProcShort (glGenerateTextureMipmap)
+ && FindProcShort (glBindTextureUnit)
+ && FindProcShort (glGetTextureImage)
+ && FindProcShort (glGetCompressedTextureImage)
+ && FindProcShort (glGetTextureLevelParameterfv)
+ && FindProcShort (glGetTextureLevelParameteriv)
+ && FindProcShort (glGetTextureParameterfv)
+ && FindProcShort (glGetTextureParameterIiv)
+ && FindProcShort (glGetTextureParameterIuiv)
+ && FindProcShort (glGetTextureParameteriv)
+ && FindProcShort (glCreateVertexArrays)
+ && FindProcShort (glDisableVertexArrayAttrib)
+ && FindProcShort (glEnableVertexArrayAttrib)
+ && FindProcShort (glVertexArrayElementBuffer)
+ && FindProcShort (glVertexArrayVertexBuffer)
+ && FindProcShort (glVertexArrayVertexBuffers)
+ && FindProcShort (glVertexArrayAttribBinding)
+ && FindProcShort (glVertexArrayAttribFormat)
+ && FindProcShort (glVertexArrayAttribIFormat)
+ && FindProcShort (glVertexArrayAttribLFormat)
+ && FindProcShort (glVertexArrayBindingDivisor)
+ && FindProcShort (glGetVertexArrayiv)
+ && FindProcShort (glGetVertexArrayIndexediv)
+ && FindProcShort (glGetVertexArrayIndexed64iv)
+ && FindProcShort (glCreateSamplers)
+ && FindProcShort (glCreateProgramPipelines)
+ && FindProcShort (glCreateQueries)
+ && FindProcShort (glGetQueryBufferObjecti64v)
+ && FindProcShort (glGetQueryBufferObjectiv)
+ && FindProcShort (glGetQueryBufferObjectui64v)
+ && FindProcShort (glGetQueryBufferObjectuiv)
+ && FindProcShort (glMemoryBarrierByRegion)
+ && FindProcShort (glGetTextureSubImage)
+ && FindProcShort (glGetCompressedTextureSubImage)
+ && FindProcShort (glGetGraphicsResetStatus)
+ && FindProcShort (glGetnCompressedTexImage)
+ && FindProcShort (glGetnTexImage)
+ && FindProcShort (glGetnUniformdv)
+ && FindProcShort (glGetnUniformfv)
+ && FindProcShort (glGetnUniformiv)
+ && FindProcShort (glGetnUniformuiv)
+ && FindProcShort (glReadnPixels)
+ && FindProcShort (glGetnMapdv)
+ && FindProcShort (glGetnMapfv)
+ && FindProcShort (glGetnMapiv)
+ && FindProcShort (glGetnPixelMapfv)
+ && FindProcShort (glGetnPixelMapuiv)
+ && FindProcShort (glGetnPixelMapusv)
+ && FindProcShort (glGetnPolygonStipple)
+ && FindProcShort (glGetnColorTable)
+ && FindProcShort (glGetnConvolutionFilter)
+ && FindProcShort (glGetnSeparableFilter)
+ && FindProcShort (glGetnHistogram)
+ && FindProcShort (glGetnMinmax)
+ && FindProcShort (glTextureBarrier);
+ if (has45)
+ {
+ core45 = (OpenGl_GlCore45* )(&(*myFuncs));
+ if (!isCoreProfile)
+ {
+ core45back = (OpenGl_GlCore45Back* )(&(*myFuncs));
+ }
+ }
+ else
+ {
+ checkWrongVersion (4, 5, aLastFailedProc);
}
- arbTboRGB32 = CheckExtension ("GL_ARB_texture_buffer_object_rgb32");
- // initialize hardware instancing extension (ARB)
- if (!has31
- && CheckExtension ("GL_ARB_draw_instanced")
- && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced)
- && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced))
+ // initialize debug context extension
+ if (CheckExtension ("GL_ARB_debug_output"))
{
- arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
+ arbDbg = NULL;
+ if (has43)
+ {
+ arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
+ }
+ else if (FindProc ("glDebugMessageControlARB", myFuncs->glDebugMessageControl)
+ && FindProc ("glDebugMessageInsertARB", myFuncs->glDebugMessageInsert)
+ && FindProc ("glDebugMessageCallbackARB", myFuncs->glDebugMessageCallback)
+ && FindProc ("glGetDebugMessageLogARB", myFuncs->glGetDebugMessageLog))
+ {
+ arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
+ }
+
+ if (arbDbg != NULL
+ && caps->contextDebug)
+ {
+ // setup default callback
+ myIsGlDebugCtx = Standard_True;
+ arbDbg->glDebugMessageCallback (debugCallbackWrap, this);
+ if (has43)
+ {
+ ::glEnable (GL_DEBUG_OUTPUT);
+ }
+ if (caps->contextSyncDebug)
+ {
+ ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
+ }
+ }
}
// initialize FBO extension (ARB)
arbTexBindless = (OpenGl_ArbTexBindless* )(&(*myFuncs));
}
- if (!has12)
- {
- checkWrongVersion (1, 2);
- myGlVerMajor = 1;
- myGlVerMinor = 1;
- return;
- }
- else if (!has13)
- {
- checkWrongVersion (1, 3);
- myGlVerMajor = 1;
- myGlVerMinor = 2;
- return;
- }
- else if (!has14)
- {
- checkWrongVersion (1, 4);
- myGlVerMajor = 1;
- myGlVerMinor = 3;
- return;
- }
- else if (!has15)
- {
- checkWrongVersion (1, 5);
- myGlVerMajor = 1;
- myGlVerMinor = 4;
- return;
- }
- if (!isCoreProfile)
- {
- core15 = (OpenGl_GlCore15* )(&(*myFuncs));
- }
- core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs));
-
- if (!has20)
- {
- checkWrongVersion (2, 0);
- myGlVerMajor = 1;
- myGlVerMinor = 5;
- return;
- }
-
- const char* aGlslVer = (const char* )::glGetString (GL_SHADING_LANGUAGE_VERSION);
- if (aGlslVer == NULL
- || *aGlslVer == '\0')
- {
- // broken context has been detected
- TCollection_ExtendedString aMsg = TCollection_ExtendedString()
- + "Error! OpenGL context reports version "
- + myGlVerMajor + "." + myGlVerMinor
- + " but reports wrong GLSL version";
- PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
- GL_DEBUG_TYPE_ERROR_ARB,
- 0,
- GL_DEBUG_SEVERITY_HIGH_ARB,
- aMsg);
- myGlVerMajor = 1;
- myGlVerMinor = 5;
- return;
- }
-
- if (!isCoreProfile)
- {
- core20 = (OpenGl_GlCore20* )(&(*myFuncs));
- }
- core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs));
-
- if (!has21)
- {
- checkWrongVersion (2, 1);
- myGlVerMajor = 2;
- myGlVerMinor = 0;
- return;
- }
-
- if (!has30)
- {
- checkWrongVersion (3, 0);
- myGlVerMajor = 2;
- myGlVerMinor = 1;
- return;
- }
-
- if (!has31)
- {
- checkWrongVersion (3, 1);
- myGlVerMajor = 3;
- myGlVerMinor = 0;
- return;
- }
- arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
- arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
-
- if (!has32)
- {
- checkWrongVersion (3, 2);
- myGlVerMajor = 3;
- myGlVerMinor = 1;
- return;
- }
- core32 = (OpenGl_GlCore32* )(&(*myFuncs));
- if (isCoreProfile)
- {
- core32->glGenVertexArrays (1, &myDefaultVao);
- }
- else
- {
- core32back = (OpenGl_GlCore32Back* )(&(*myFuncs));
- }
-
- if (!has33)
- {
- checkWrongVersion (3, 3);
- myGlVerMajor = 3;
- myGlVerMinor = 2;
- return;
- }
- core33 = (OpenGl_GlCore33* )(&(*myFuncs));
- if (!isCoreProfile)
- {
- core33back = (OpenGl_GlCore33Back* )(&(*myFuncs));
- }
-
- // initialize sampler object
- myTexSampler = new OpenGl_Sampler();
- myTexSampler->Init (*this);
-
- if (!has40)
- {
- checkWrongVersion (4, 0);
- myGlVerMajor = 3;
- myGlVerMinor = 3;
- return;
- }
- arbTboRGB32 = Standard_True; // in core since OpenGL 4.0
-
- if (!has41)
- {
- checkWrongVersion (4, 1);
- myGlVerMajor = 4;
- myGlVerMinor = 0;
- return;
- }
- core41 = (OpenGl_GlCore41* )(&(*myFuncs));
- if (!isCoreProfile)
+ if (has30)
{
- core41back = (OpenGl_GlCore41Back* )(&(*myFuncs));
+ // MSAA RenderBuffers have been defined in OpenGL 3.0,
+ // but MSAA Textures - only in OpenGL 3.2+
+ if (!has32
+ && CheckExtension ("GL_ARB_texture_multisample")
+ && FindProcShort (glTexImage2DMultisample))
+ {
+ GLint aNbColorSamples = 0, aNbDepthSamples = 0;
+ ::glGetIntegerv (GL_MAX_COLOR_TEXTURE_SAMPLES, &aNbColorSamples);
+ ::glGetIntegerv (GL_MAX_DEPTH_TEXTURE_SAMPLES, &aNbDepthSamples);
+ myMaxMsaaSamples = Min (aNbColorSamples, aNbDepthSamples);
+ }
+ if (!has43
+ && CheckExtension ("GL_ARB_texture_storage_multisample")
+ && FindProcShort (glTexStorage2DMultisample))
+ {
+ //
+ }
}
- if(!has42)
- {
- checkWrongVersion (4, 2);
- myGlVerMajor = 4;
- myGlVerMinor = 1;
- return;
- }
- core42 = (OpenGl_GlCore42* )(&(*myFuncs));
- if (!isCoreProfile)
- {
- core42back = (OpenGl_GlCore42Back* )(&(*myFuncs));
- }
+ // check whether ray tracing mode is supported
+ myHasRayTracing = has31
+ && arbTboRGB32
+ && arbFBOBlit != NULL;
- if (!has43)
- {
- checkWrongVersion (4, 3);
- myGlVerMajor = 4;
- myGlVerMinor = 2;
- return;
- }
- core43 = (OpenGl_GlCore43* )(&(*myFuncs));
- if (!isCoreProfile)
- {
- core43back = (OpenGl_GlCore43Back* )(&(*myFuncs));
- }
+ // check whether textures in ray tracing mode are supported
+ myHasRayTracingTextures = myHasRayTracing
+ && arbTexBindless != NULL;
- if (!has44)
- {
- checkWrongVersion (4, 4);
- myGlVerMajor = 4;
- myGlVerMinor = 3;
- return;
- }
- core44 = (OpenGl_GlCore44* )(&(*myFuncs));
- if (!isCoreProfile)
- {
- core44back = (OpenGl_GlCore44Back* )(&(*myFuncs));
- }
+ // check whether adaptive screen sampling in ray tracing mode is supported
+ myHasRayTracingAdaptiveSampling = myHasRayTracing
+ && has44;
+ myHasRayTracingAdaptiveSamplingAtomic = myHasRayTracingAdaptiveSampling
+ && CheckExtension ("GL_NV_shader_atomic_float");
#endif
}
// =======================================================================
TCollection_AsciiString OpenGl_Context::MemoryInfo() const
{
- TCollection_AsciiString anInfo;
+ TColStd_IndexedDataMapOfStringString aDict;
+ MemoryInfo (aDict);
+
+ TCollection_AsciiString aText;
+ for (TColStd_IndexedDataMapOfStringString::Iterator anIter (aDict); anIter.More(); anIter.Next())
+ {
+ if (!aText.IsEmpty())
+ {
+ aText += "\n";
+ }
+ aText += TCollection_AsciiString(" ") + anIter.Key() + ": " + anIter.Value();
+ }
+ return aText;
+}
+
+// =======================================================================
+// function : MemoryInfo
+// purpose :
+// =======================================================================
+void OpenGl_Context::MemoryInfo (TColStd_IndexedDataMapOfStringString& theDict) const
+{
+#if defined(GL_ES_VERSION_2_0)
+ (void )theDict;
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+ GLint aGlRendId = 0;
+ CGLGetParameter (CGLGetCurrentContext(), kCGLCPCurrentRendererID, &aGlRendId);
+
+ CGLRendererInfoObj aRendObj = NULL;
+ CGOpenGLDisplayMask aDispMask = CGDisplayIDToOpenGLDisplayMask (kCGDirectMainDisplay);
+ GLint aRendNb = 0;
+ CGLQueryRendererInfo (aDispMask, &aRendObj, &aRendNb);
+ for (GLint aRendIter = 0; aRendIter < aRendNb; ++aRendIter)
+ {
+ GLint aRendId = 0;
+ if (CGLDescribeRenderer (aRendObj, aRendIter, kCGLRPRendererID, &aRendId) != kCGLNoError
+ || aRendId != aGlRendId)
+ {
+ continue;
+ }
+
+ //kCGLRPVideoMemoryMegabytes = 131;
+ //kCGLRPTextureMemoryMegabytes = 132;
+ GLint aVMem = 0;
+ #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemoryMegabytes, &aVMem) == kCGLNoError)
+ {
+ addInfo (theDict, "GPU memory", TCollection_AsciiString() + aVMem + " MiB");
+ }
+ if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemoryMegabytes, &aVMem) == kCGLNoError)
+ {
+ addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + aVMem + " MiB");
+ }
+ #else
+ if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemory, &aVMem) == kCGLNoError)
+ {
+ addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB");
+ }
+ if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemory, &aVMem) == kCGLNoError)
+ {
+ addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB");
+ }
+ #endif
+ }
+#endif
+
#if !defined(GL_ES_VERSION_2_0)
if (atiMem)
{
glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues);
// total memory free in the pool
- anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValues[0] / 1024) + " MiB\n";
+ addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValues[0] / 1024) + " MiB");
- // largest available free block in the pool
- anInfo += TCollection_AsciiString (" Largest free block: ") + (aValues[1] / 1024) + " MiB\n";
+ if (aValues[1] != aValues[0])
+ {
+ // largest available free block in the pool
+ addInfo (theDict, "Largest free block", TCollection_AsciiString() + (aValues[1] / 1024) + " MiB");
+ }
if (aValues[2] != aValues[0])
{
// total auxiliary memory free
- anInfo += TCollection_AsciiString (" Free memory: ") + (aValues[2] / 1024) + " MiB\n";
+ addInfo (theDict, "Free auxiliary memory", TCollection_AsciiString() + (aValues[2] / 1024) + " MiB");
}
}
else if (nvxMem)
//current available dedicated video memory (in KiB), currently unused GPU memory
GLint aValue = 0;
glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue);
- anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValue / 1024) + " MiB\n";
+ addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValue / 1024) + " MiB");
// dedicated video memory, total size (in KiB) of the GPU memory
GLint aDedicated = 0;
glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated);
- anInfo += TCollection_AsciiString (" GPU memory: ") + (aDedicated / 1024) + " MiB\n";
+ addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aDedicated / 1024) + " MiB");
// total available memory, total size (in KiB) of the memory available for allocations
glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue);
if (aValue != aDedicated)
{
// different only for special configurations
- anInfo += TCollection_AsciiString (" Total memory: ") + (aValue / 1024) + " MiB\n";
+ addInfo (theDict, "Total memory", TCollection_AsciiString() + (aValue / 1024) + " MiB");
+ }
+ }
+#if defined(_WIN32)
+ else if (myFuncs->wglGetGPUInfoAMD != NULL
+ && myFuncs->wglGetContextGPUIDAMD != NULL)
+ {
+ GLuint aTotalMemMiB = 0;
+ UINT anAmdId = myFuncs->wglGetContextGPUIDAMD ((HGLRC )myGContext);
+ if (anAmdId != 0)
+ {
+ if (myFuncs->wglGetGPUInfoAMD (anAmdId, WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(aTotalMemMiB), &aTotalMemMiB) > 0)
+ {
+ addInfo (theDict, "GPU memory", TCollection_AsciiString() + (int )aTotalMemMiB + " MiB");
+ }
+ }
+ }
+#endif
+#endif
+
+#if !defined(GL_ES_VERSION_2_0) && !defined(__APPLE__) && !defined(_WIN32)
+ // GLX_RENDERER_VENDOR_ID_MESA
+ if (myFuncs->glXQueryCurrentRendererIntegerMESA != NULL)
+ {
+ unsigned int aVMemMiB = 0;
+ if (myFuncs->glXQueryCurrentRendererIntegerMESA (GLX_RENDERER_VIDEO_MEMORY_MESA, &aVMemMiB) != False)
+ {
+ addInfo (theDict, "GPU memory", TCollection_AsciiString() + int(aVMemMiB) + " MiB");
}
}
#endif
- return anInfo;
}
+// =======================================================================
+// function : DiagnosticInfo
+// purpose :
+// =======================================================================
+void OpenGl_Context::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
+ Graphic3d_DiagnosticInfo theFlags) const
+{
+ if ((theFlags & Graphic3d_DiagnosticInfo_NativePlatform) != 0)
+ {
+ #if defined(HAVE_EGL)
+ addInfo (theDict, "EGLVersion", ::eglQueryString ((EGLDisplay )myDisplay, EGL_VERSION));
+ addInfo (theDict, "EGLVendor", ::eglQueryString ((EGLDisplay )myDisplay, EGL_VENDOR));
+ addInfo (theDict, "EGLClientAPIs", ::eglQueryString ((EGLDisplay )myDisplay, EGL_CLIENT_APIS));
+ if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
+ {
+ addInfo (theDict, "EGLExtensions", ::eglQueryString ((EGLDisplay )myDisplay, EGL_EXTENSIONS));
+ }
+ #elif defined(_WIN32)
+ if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0
+ && myFuncs->wglGetExtensionsStringARB != NULL)
+ {
+ const char* aWglExts = myFuncs->wglGetExtensionsStringARB ((HDC )myWindowDC);
+ addInfo (theDict, "WGLExtensions", aWglExts);
+ }
+ #elif defined(__APPLE__)
+ //
+ #else
+ Display* aDisplay = (Display*)myDisplay;
+ const int aScreen = DefaultScreen(aDisplay);
+ addInfo (theDict, "GLXDirectRendering", ::glXIsDirect (aDisplay, (GLXContext )myGContext) ? "Yes" : "No");
+ addInfo (theDict, "GLXVendor", ::glXQueryServerString (aDisplay, aScreen, GLX_VENDOR));
+ addInfo (theDict, "GLXVersion", ::glXQueryServerString (aDisplay, aScreen, GLX_VERSION));
+ if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
+ {
+ const char* aGlxExts = ::glXQueryExtensionsString (aDisplay, aScreen);
+ addInfo(theDict, "GLXExtensions", aGlxExts);
+ }
+
+ addInfo (theDict, "GLXClientVendor", ::glXGetClientString (aDisplay, GLX_VENDOR));
+ addInfo (theDict, "GLXClientVersion", ::glXGetClientString (aDisplay, GLX_VERSION));
+ if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
+ {
+ addInfo (theDict, "GLXClientExtensions", ::glXGetClientString (aDisplay, GLX_EXTENSIONS));
+ }
+ #endif
+ }
+
+ if ((theFlags & Graphic3d_DiagnosticInfo_Device) != 0)
+ {
+ addInfo (theDict, "GLvendor", (const char*)::glGetString (GL_VENDOR));
+ addInfo (theDict, "GLdevice", (const char*)::glGetString (GL_RENDERER));
+ addInfo (theDict, "GLversion", (const char*)::glGetString (GL_VERSION));
+ if (IsGlGreaterEqual (2, 0))
+ {
+ addInfo (theDict, "GLSLversion", (const char*)::glGetString (GL_SHADING_LANGUAGE_VERSION));
+ }
+ if (myIsGlDebugCtx)
+ {
+ addInfo (theDict, "GLdebug", "ON");
+ }
+ }
+
+ if ((theFlags & Graphic3d_DiagnosticInfo_Limits) != 0)
+ {
+ addInfo (theDict, "Max texture size", TCollection_AsciiString(myMaxTexDim));
+ addInfo (theDict, "Max FBO dump size", TCollection_AsciiString() + myMaxDumpSizeX + "x" + myMaxDumpSizeY);
+ addInfo (theDict, "Max combined texture units", TCollection_AsciiString(myMaxTexCombined));
+ addInfo (theDict, "Max MSAA samples", TCollection_AsciiString(myMaxMsaaSamples));
+ }
+
+ if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0)
+ {
+ GLint aViewport[4] = {};
+ ::glGetIntegerv (GL_VIEWPORT, aViewport);
+ addInfo (theDict, "Viewport", TCollection_AsciiString() + aViewport[2] + "x" + aViewport[3]);
+ }
+
+ if ((theFlags & Graphic3d_DiagnosticInfo_Memory) != 0)
+ {
+ MemoryInfo (theDict);
+ }
+
+ if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
+ {
+ #if !defined(GL_ES_VERSION_2_0)
+ if (IsGlGreaterEqual (3, 0)
+ && myFuncs->glGetStringi != NULL)
+ {
+ TCollection_AsciiString anExtList;
+ GLint anExtNb = 0;
+ ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb);
+ for (GLint anIter = 0; anIter < anExtNb; ++anIter)
+ {
+ const char* anExtension = (const char*)myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint)anIter);
+ if (!anExtList.IsEmpty())
+ {
+ anExtList += " ";
+ }
+ anExtList += anExtension;
+ }
+ addInfo(theDict, "GLextensions", anExtList);
+ }
+ else
+ #endif
+ {
+ addInfo (theDict, "GLextensions", (const char*)::glGetString (GL_EXTENSIONS));
+ }
+ }
+}
// =======================================================================
// function : GetResource
}
// =======================================================================
-// function : DelayedRelease
+// function : ReleaseDelayed
// purpose :
// =======================================================================
-void OpenGl_Context::DelayedRelease (Handle(OpenGl_Resource)& theResource)
-{
- myUnusedResources->Prepend (theResource);
- theResource.Nullify();
-}
-
-// =======================================================================
-// function : ReleaseDelayed
-// purpose :
-// =======================================================================
-void OpenGl_Context::ReleaseDelayed()
+void OpenGl_Context::ReleaseDelayed()
{
// release queued elements
while (!myUnusedResources->IsEmpty())
continue;
}
- Handle(OpenGl_Resource)& aRes = mySharedResources->ChangeFind (aKey);
+ const Handle(OpenGl_Resource)& aRes = mySharedResources->ChangeFind (aKey);
if (aRes->GetRefCount() > 1)
{
// should be only 1 instance in mySharedResources
}
}
+// =======================================================================
+// function : BindTextures
+// purpose :
+// =======================================================================
+Handle(OpenGl_TextureSet) OpenGl_Context::BindTextures (const Handle(OpenGl_TextureSet)& theTextures)
+{
+ if (myActiveTextures == theTextures)
+ {
+ return myActiveTextures;
+ }
+
+ Handle(OpenGl_Context) aThisCtx (this);
+ OpenGl_TextureSet::Iterator aTextureIterOld (myActiveTextures), aTextureIterNew (theTextures);
+ for (;;)
+ {
+ if (!aTextureIterNew.More())
+ {
+ for (; aTextureIterOld.More(); aTextureIterOld.Next())
+ {
+ if (const Handle(OpenGl_Texture)& aTextureOld = aTextureIterOld.Value())
+ {
+ #if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
+ {
+ OpenGl_Sampler::resetGlobalTextureParams (aThisCtx, *aTextureOld, aTextureOld->Sampler()->Parameters());
+ }
+ #endif
+ aTextureOld->Unbind (aThisCtx);
+ }
+ }
+ break;
+ }
+
+ const Handle(OpenGl_Texture)& aTextureNew = aTextureIterNew.Value();
+ if (aTextureIterOld.More())
+ {
+ const Handle(OpenGl_Texture)& aTextureOld = aTextureIterOld.Value();
+ if (aTextureNew == aTextureOld)
+ {
+ aTextureIterNew.Next();
+ aTextureIterOld.Next();
+ continue;
+ }
+ else if (aTextureNew.IsNull()
+ || !aTextureNew->IsValid())
+ {
+ if (!aTextureOld.IsNull())
+ {
+ #if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
+ {
+ OpenGl_Sampler::resetGlobalTextureParams (aThisCtx, *aTextureOld, aTextureOld->Sampler()->Parameters());
+ }
+ #endif
+ aTextureOld->Unbind (aThisCtx);
+ }
+
+ aTextureIterNew.Next();
+ aTextureIterOld.Next();
+ continue;
+ }
+
+ aTextureIterOld.Next();
+ }
+ if (aTextureNew.IsNull())
+ {
+ aTextureIterNew.Next();
+ continue;
+ }
+
+ const Graphic3d_TextureUnit aTexUnit = aTextureNew->Sampler()->Parameters()->TextureUnit();
+ if (aTexUnit >= myMaxTexCombined)
+ {
+ PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
+ TCollection_AsciiString("Texture unit ") + aTexUnit + " for " + aTextureNew->ResourceId() + " exceeds hardware limit " + myMaxTexCombined);
+ aTextureIterNew.Next();
+ continue;
+ }
+
+ aTextureNew->Bind (aThisCtx);
+ if (aTextureNew->Sampler()->ToUpdateParameters())
+ {
+ if (aTextureNew->Sampler()->IsImmutable())
+ {
+ aTextureNew->Sampler()->Init (aThisCtx, *aTextureNew);
+ }
+ else
+ {
+ OpenGl_Sampler::applySamplerParams (aThisCtx, aTextureNew->Sampler()->Parameters(), aTextureNew->Sampler().get(), aTextureNew->GetTarget(), aTextureNew->HasMipmaps());
+ }
+ }
+ #if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
+ {
+ OpenGl_Sampler::applyGlobalTextureParams (aThisCtx, *aTextureNew, aTextureNew->Sampler()->Parameters());
+ }
+ #endif
+ aTextureIterNew.Next();
+ }
+
+ Handle(OpenGl_TextureSet) anOldTextures = myActiveTextures;
+ myActiveTextures = theTextures;
+ return anOldTextures;
+}
+
// =======================================================================
// function : BindProgram
// purpose :
{
return Standard_False;
}
+ else if (myActiveProgram == theProgram)
+ {
+ return Standard_True;
+ }
if (theProgram.IsNull()
|| !theProgram->IsValid())
return aFbo;
}
+// =======================================================================
+// function : SetShadingMaterial
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetShadingMaterial (const OpenGl_Aspects* theAspect,
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight)
+{
+ const Handle(Graphic3d_Aspects)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
+ ? (const Handle(Graphic3d_Aspects)& )theHighlight->BasicFillAreaAspect()
+ : theAspect->Aspect();
+
+ const bool toDistinguish = anAspect->Distinguish();
+ const bool toMapTexture = anAspect->ToMapTexture();
+ const Graphic3d_MaterialAspect& aMatFrontSrc = anAspect->FrontMaterial();
+ const Graphic3d_MaterialAspect& aMatBackSrc = toDistinguish
+ ? anAspect->BackMaterial()
+ : aMatFrontSrc;
+ const Quantity_Color& aFrontIntColor = anAspect->InteriorColor();
+ const Quantity_Color& aBackIntColor = toDistinguish
+ ? anAspect->BackInteriorColor()
+ : aFrontIntColor;
+
+ myMatFront.Init (aMatFrontSrc, aFrontIntColor);
+ if (toDistinguish)
+ {
+ myMatBack.Init (aMatBackSrc, aBackIntColor);
+ }
+ else
+ {
+ myMatBack = myMatFront;
+ }
+
+ if (!theHighlight.IsNull()
+ && theHighlight->BasicFillAreaAspect().IsNull())
+ {
+ myMatFront.SetColor (theHighlight->ColorRGBA());
+ myMatBack .SetColor (theHighlight->ColorRGBA());
+ }
+
+ Standard_ShortReal anAlphaFront = 1.0f;
+ Standard_ShortReal anAlphaBack = 1.0f;
+ if (CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack))
+ {
+ myMatFront.Diffuse.a() = anAlphaFront;
+ myMatBack .Diffuse.a() = anAlphaBack;
+ }
+
+ // do not update material properties in case of zero reflection mode,
+ // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway.
+ const OpenGl_MaterialState& aMatState = myShaderManager->MaterialState();
+ float anAlphaCutoff = anAspect->AlphaMode() == Graphic3d_AlphaMode_Mask
+ ? anAspect->AlphaCutoff()
+ : ShortRealLast();
+ if (anAspect->ToDrawEdges())
+ {
+ if (anAspect->InteriorStyle() == Aspect_IS_EMPTY
+ || (anAspect->InteriorStyle() == Aspect_IS_SOLID
+ && anAspect->EdgeColorRGBA().Alpha() < 1.0f))
+ {
+ anAlphaCutoff = 0.285f;
+ }
+ }
+ if (theAspect->ShadingModel() == Graphic3d_TOSM_UNLIT)
+ {
+ if (anAlphaCutoff == aMatState.AlphaCutoff())
+ {
+ return;
+ }
+ }
+ else if (myMatFront == aMatState.FrontMaterial()
+ && myMatBack == aMatState.BackMaterial()
+ && toDistinguish == aMatState.ToDistinguish()
+ && toMapTexture == aMatState.ToMapTexture()
+ && anAlphaCutoff == aMatState.AlphaCutoff())
+ {
+ return;
+ }
+
+ myShaderManager->UpdateMaterialStateTo (myMatFront, myMatBack, anAlphaCutoff, toDistinguish, toMapTexture);
+}
+
+// =======================================================================
+// function : CheckIsTransparent
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_Aspects* theAspect,
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight,
+ Standard_ShortReal& theAlphaFront,
+ Standard_ShortReal& theAlphaBack)
+{
+ const Handle(Graphic3d_Aspects)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
+ ? (const Handle(Graphic3d_Aspects)& )theHighlight->BasicFillAreaAspect()
+ : theAspect->Aspect();
+
+ const bool toDistinguish = anAspect->Distinguish();
+ const Graphic3d_MaterialAspect& aMatFrontSrc = anAspect->FrontMaterial();
+ const Graphic3d_MaterialAspect& aMatBackSrc = toDistinguish
+ ? anAspect->BackMaterial()
+ : aMatFrontSrc;
+
+ // handling transparency
+ if (!theHighlight.IsNull()
+ && theHighlight->BasicFillAreaAspect().IsNull())
+ {
+ theAlphaFront = theHighlight->ColorRGBA().Alpha();
+ theAlphaBack = theHighlight->ColorRGBA().Alpha();
+ }
+ else
+ {
+ theAlphaFront = aMatFrontSrc.Alpha();
+ theAlphaBack = aMatBackSrc .Alpha();
+ }
+
+ if (anAspect->AlphaMode() == Graphic3d_AlphaMode_BlendAuto)
+ {
+ return theAlphaFront < 1.0f
+ || theAlphaBack < 1.0f;
+ }
+ return anAspect->AlphaMode() == Graphic3d_AlphaMode_Blend;
+}
+
// =======================================================================
// function : SetColor4fv
// purpose :
aPattern = 0xFF18;
break;
}
+ case Aspect_TOL_EMPTY:
case Aspect_TOL_SOLID:
{
aPattern = 0xFFFF;
}
#if !defined(GL_ES_VERSION_2_0)
- if (theType != Aspect_TOL_SOLID)
+ if (aPattern != 0xFFFF)
{
- #ifdef HAVE_GL2PS
- if (IsFeedback())
- {
- gl2psEnable (GL2PS_LINE_STIPPLE);
- }
- #endif
-
if (core11 != NULL)
{
core11fwd->glEnable (GL_LINE_STIPPLE);
{
core11fwd->glDisable (GL_LINE_STIPPLE);
}
-
- #ifdef HAVE_GL2PS
- if (IsFeedback())
- {
- gl2psDisable (GL2PS_LINE_STIPPLE);
- }
- #endif
}
#endif
}
if (core11 != NULL)
{
// glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f
- core11fwd->glLineWidth (theWidth);
+ core11fwd->glLineWidth (theWidth * myLineWidthScale);
+ }
+}
+
+// =======================================================================
+// function : SetTextureMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams)
+{
+ if (theParams.IsNull())
+ {
+ return;
+ }
+ else if (!myActiveProgram.IsNull())
+ {
+ const GLint aUniLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_TRSF2D);
+ if (aUniLoc == OpenGl_ShaderProgram::INVALID_LOCATION)
+ {
+ return;
+ }
+
+ // pack transformation parameters
+ OpenGl_Vec4 aTrsf[2] =
+ {
+ OpenGl_Vec4 (-theParams->Translation().x(),
+ -theParams->Translation().y(),
+ theParams->Scale().x(),
+ theParams->Scale().y()),
+ OpenGl_Vec4 (static_cast<float> (std::sin (-theParams->Rotation() * M_PI / 180.0)),
+ static_cast<float> (std::cos (-theParams->Rotation() * M_PI / 180.0)),
+ 0.0f, 0.0f)
+ };
+ myActiveProgram->SetUniform (this, aUniLoc, 2, aTrsf);
+ return;
}
-#ifdef HAVE_GL2PS
- if (IsFeedback())
+
+#if !defined(GL_ES_VERSION_2_0)
+ if (core11 != NULL)
{
- gl2psLineWidth (theWidth);
+ GLint aMatrixMode = GL_TEXTURE;
+ ::glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
+
+ core11->glMatrixMode (GL_TEXTURE);
+ OpenGl_Mat4 aTextureMat;
+ const Graphic3d_Vec2& aScale = theParams->Scale();
+ const Graphic3d_Vec2& aTrans = theParams->Translation();
+ Graphic3d_TransformUtils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f);
+ Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f);
+ Graphic3d_TransformUtils::Rotate (aTextureMat, -theParams->Rotation(), 0.0f, 0.0f, 1.0f);
+ core11->glLoadMatrixf (aTextureMat);
+ core11->glMatrixMode (aMatrixMode);
}
#endif
}
#endif
}
+// =======================================================================
+// function : SetPointSpriteOrigin
+// purpose :
+// =======================================================================
+void OpenGl_Context::SetPointSpriteOrigin()
+{
+#if !defined(GL_ES_VERSION_2_0)
+ if (core15fwd == NULL)
+ {
+ return;
+ }
+
+ const int aNewState = !myActiveProgram.IsNull() ? GL_UPPER_LEFT : GL_LOWER_LEFT;
+ if (myPointSpriteOrig != aNewState)
+ {
+ myPointSpriteOrig = aNewState;
+ core15fwd->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, aNewState);
+ }
+#endif
+}
+
// =======================================================================
// function : SetGlNormalizeEnabled
// purpose :
}
// =======================================================================
-// function : ApplyModelWorldMatrix
+// function : SetPolygonMode
// purpose :
// =======================================================================
-void OpenGl_Context::ApplyModelWorldMatrix()
+Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode)
{
-#if !defined(GL_ES_VERSION_2_0)
- if (core11 != NULL)
+ if (myPolygonMode == theMode)
{
- core11->glMatrixMode (GL_MODELVIEW);
- core11->glLoadMatrixf (ModelWorldState.Current());
+ return myPolygonMode;
}
+
+ const Standard_Integer anOldPolygonMode = myPolygonMode;
+
+ myPolygonMode = theMode;
+
+#if !defined(GL_ES_VERSION_2_0)
+ ::glPolygonMode (GL_FRONT_AND_BACK, (GLenum)theMode);
#endif
- if (!myShaderManager->IsEmpty())
+ return anOldPolygonMode;
+}
+
+// =======================================================================
+// function : SetPolygonHatchEnabled
+// purpose :
+// =======================================================================
+bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled)
+{
+ if (myHatchStyles.IsNull())
{
- myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
+ return false;
+ }
+ else if (myHatchStyles->IsEnabled() == theIsEnabled)
+ {
+ return theIsEnabled;
}
+
+ return myHatchStyles->SetEnabled (this, theIsEnabled);
}
// =======================================================================
-// function : ApplyWorldViewMatrix
+// function : SetPolygonHatchStyle
// purpose :
// =======================================================================
-void OpenGl_Context::ApplyWorldViewMatrix()
+Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle)
{
-#if !defined(GL_ES_VERSION_2_0)
- if (core11 != NULL)
+ if (theStyle.IsNull())
{
- core11->glMatrixMode (GL_MODELVIEW);
- core11->glLoadMatrixf (WorldViewState.Current());
+ return 0;
}
-#endif
- if (!myShaderManager->IsEmpty())
+ if (myHatchStyles.IsNull())
{
- myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
+ if (!GetResource ("OpenGl_LineAttributes", myHatchStyles))
+ {
+ // share and register for release once the resource is no longer used
+ myHatchStyles = new OpenGl_LineAttributes();
+ ShareResource ("OpenGl_LineAttributes", myHatchStyles);
+ }
+ }
+ if (myHatchStyles->TypeOfHatch() == theStyle->HatchType())
+ {
+ return theStyle->HatchType();
}
+
+ return myHatchStyles->SetTypeOfHatch (this, theStyle);
}
// =======================================================================
-// function : ApplyModelViewMatrix
+// function : SetPolygonOffset
// purpose :
// =======================================================================
-void OpenGl_Context::ApplyModelViewMatrix()
+void OpenGl_Context::SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset)
{
+ const bool toFillOld = (myPolygonOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill;
+ const bool toFillNew = (theOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill;
+ if (toFillNew != toFillOld)
+ {
+ if (toFillNew)
+ {
+ glEnable (GL_POLYGON_OFFSET_FILL);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_FILL);
+ }
+ }
+
#if !defined(GL_ES_VERSION_2_0)
- if (core11 != NULL)
+ const bool toLineOld = (myPolygonOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line;
+ const bool toLineNew = (theOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line;
+ if (toLineNew != toLineOld)
+ {
+ if (toLineNew)
+ {
+ glEnable (GL_POLYGON_OFFSET_LINE);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_LINE);
+ }
+ }
+
+ const bool toPointOld = (myPolygonOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point;
+ const bool toPointNew = (theOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point;
+ if (toPointNew != toPointOld)
{
- OpenGl_Mat4 aModelView = WorldViewState.Current() * ModelWorldState.Current();
- core11->glMatrixMode (GL_MODELVIEW);
- core11->glLoadMatrixf (aModelView.GetData());
+ if (toPointNew)
+ {
+ glEnable (GL_POLYGON_OFFSET_POINT);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_POINT);
+ }
}
#endif
- if (!myShaderManager->IsEmpty())
+ if (myPolygonOffset.Factor != theOffset.Factor
+ || myPolygonOffset.Units != theOffset.Units)
+ {
+ glPolygonOffset (theOffset.Factor, theOffset.Units);
+ }
+ myPolygonOffset = theOffset;
+}
+
+// =======================================================================
+// function : ApplyModelWorldMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::ApplyModelWorldMatrix()
+{
+ if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current())
{
myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
+ }
+}
+
+// =======================================================================
+// function : ApplyWorldViewMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::ApplyWorldViewMatrix()
+{
+ if (myShaderManager->ModelWorldState().ModelWorldMatrix() != THE_IDENTITY_MATRIX)
+ {
+ myShaderManager->UpdateModelWorldStateTo (THE_IDENTITY_MATRIX);
+ }
+ if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current())
+ {
myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
}
}
// =======================================================================
-// function : ApplyProjectionMatrix
+// function : ApplyModelViewMatrix
// purpose :
// =======================================================================
-void OpenGl_Context::ApplyProjectionMatrix()
+void OpenGl_Context::ApplyModelViewMatrix()
{
-#if !defined(GL_ES_VERSION_2_0)
- if (core11 != NULL)
+ if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current())
+ {
+ myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
+ }
+ if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current())
{
- core11->glMatrixMode (GL_PROJECTION);
- core11->glLoadMatrixf (ProjectionState.Current().GetData());
+ myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
}
-#endif
+}
- if (!myShaderManager->IsEmpty())
+// =======================================================================
+// function : ApplyProjectionMatrix
+// purpose :
+// =======================================================================
+void OpenGl_Context::ApplyProjectionMatrix()
+{
+ if (myShaderManager->ProjectionState().ProjectionMatrix() != ProjectionState.Current())
{
myShaderManager->UpdateProjectionStateTo (ProjectionState.Current());
}
}
-
// =======================================================================
// function : EnableFeatures
// purpose :
// =======================================================================
void OpenGl_Context::DisableFeatures() const
{
-#if !defined(GL_ES_VERSION_2_0)
- glPixelTransferi (GL_MAP_COLOR, GL_FALSE);
-#endif
-
- /*
- * Disable stuff that's likely to slow down glDrawPixels.
- * (Omit as much of this as possible, when you know in advance
- * that the OpenGL state will already be set correctly.)
- */
+ // Disable stuff that's likely to slow down glDrawPixels.
glDisable(GL_DITHER);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
- glDisable(GL_TEXTURE_2D);
glDisable(GL_STENCIL_TEST);
#if !defined(GL_ES_VERSION_2_0)
+ if (core11 == NULL)
+ {
+ return;
+ }
+
+ glDisable(GL_TEXTURE_1D);
+ glDisable(GL_TEXTURE_2D);
+
glDisable(GL_LIGHTING);
glDisable(GL_ALPHA_TEST);
glDisable(GL_FOG);
glDisable(GL_LOGIC_OP);
- glDisable(GL_TEXTURE_1D);
glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
glPixelTransferi(GL_RED_SCALE, 1);
glPixelTransferi(GL_ALPHA_SCALE, 1);
glPixelTransferi(GL_ALPHA_BIAS, 0);
- /*
- * Disable extensions that could slow down glDrawPixels.
- * (Actually, you should check for the presence of the proper
- * extension before making these calls. I've omitted that
- * code for simplicity.)
- */
-
if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2))
{
-#ifdef GL_EXT_convolution
if (CheckExtension ("GL_CONVOLUTION_1D_EXT"))
glDisable(GL_CONVOLUTION_1D_EXT);
if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
glDisable(GL_SEPARABLE_2D_EXT);
-#endif
-#ifdef GL_EXT_histogram
if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
glDisable(GL_HISTOGRAM_EXT);
if (CheckExtension ("GL_MINMAX_EXT"))
glDisable(GL_MINMAX_EXT);
-#endif
-#ifdef GL_EXT_texture3D
if (CheckExtension ("GL_TEXTURE_3D_EXT"))
glDisable(GL_TEXTURE_3D_EXT);
-#endif
}
#endif
}
+
+// =======================================================================
+// function : SetColorMask
+// purpose :
+// =======================================================================
+bool OpenGl_Context::SetColorMask (bool theToWriteColor)
+{
+ const GLboolean toWrite = theToWriteColor ? GL_TRUE : GL_FALSE;
+ glColorMask (toWrite, toWrite, toWrite, toWrite);
+
+ const bool anOldValue = myColorMask;
+ myColorMask = theToWriteColor;
+ return anOldValue;
+}
+
+// =======================================================================
+// function : SetSampleAlphaToCoverage
+// purpose :
+// =======================================================================
+bool OpenGl_Context::SetSampleAlphaToCoverage (bool theToEnable)
+{
+ bool toEnable = myAllowAlphaToCov && theToEnable;
+ if (myAlphaToCoverage == toEnable)
+ {
+ return myAlphaToCoverage;
+ }
+
+ if (core15fwd != NULL)
+ {
+ if (toEnable)
+ {
+ //core15fwd->core15fwd->glSampleCoverage (1.0f, GL_FALSE);
+ core15fwd->glEnable (GL_SAMPLE_ALPHA_TO_COVERAGE);
+ }
+ else
+ {
+ core15fwd->glDisable (GL_SAMPLE_ALPHA_TO_COVERAGE);
+ }
+ }
+
+ const bool anOldValue = myAlphaToCoverage;
+ myAlphaToCoverage = toEnable;
+ return anOldValue;
+}