#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_FrameBuffer.hxx>
+#include <OpenGl_FrameStats.hxx>
#include <OpenGl_Sampler.hxx>
#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_AspectFace.hxx>
#include <Graphic3d_TransformUtils.hxx>
+#include <Graphic3d_RenderingParams.hxx>
#include <Message_Messenger.hxx>
hasUintIndex(Standard_True),
hasTexRGBA8(Standard_True),
#endif
+ hasDrawBuffers (OpenGl_FeatureNotAvailable),
+ hasFloatBuffer (OpenGl_FeatureNotAvailable),
+ hasHalfFloatBuffer (OpenGl_FeatureNotAvailable),
+ hasSampleVariables (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),
myMaxClipPlanes (6),
myMaxMsaaSamples(0),
+ myMaxDrawBuffers (1),
+ myMaxColorAttachments (1),
myGlVerMajor (0),
myGlVerMinor (0),
myIsInitialized (Standard_False),
myHasRayTracing (Standard_False),
myHasRayTracingTextures (Standard_False),
myHasRayTracingAdaptiveSampling (Standard_False),
+ myFrameStats (new OpenGl_FrameStats()),
#if !defined(GL_ES_VERSION_2_0)
myPointSpriteOrig (GL_UPPER_LEFT),
myRenderMode (GL_RENDER),
#endif
myToCullBackFaces (false),
myReadBuffer (0),
- myDrawBuffer (0),
+ myDrawBuffers (1),
myDefaultVao (0),
+ myColorMask (true),
myIsGlDebugCtx (Standard_False),
- myResolutionRatio (1.0f)
+ myResolution (Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION),
+ myResolutionRatio (1.0f),
+ myLineWidthScale (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)
mySharedResources.Nullify();
myDelayed.Nullify();
- // release sampler object
- if (!myTexSampler.IsNull())
- {
- myTexSampler->Release (this);
- }
-
if (arbDbg != NULL
&& myIsGlDebugCtx
&& IsValid())
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.Clear();
+
+ if (aDrawBuffer != 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());
+
+ myDrawBuffers.Clear();
+
+ 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 if (theDrawBuffers[anI] != GL_NONE)
+ {
+ 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 :
::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
+ myDrawBuffers.Clear();
+
+ if (myMaxDrawBuffers == 1)
+ {
+ Standard_Integer aDrawBuffer;
+
+ ::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer);
+
+ if (aDrawBuffer != GL_NONE)
+ {
+ myDrawBuffers.SetValue (0, aDrawBuffer);
+ }
+ }
+ else
+ {
+ Standard_Integer aDrawBuffer;
+
+ for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI)
+ {
+ ::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer);
+
+ if (aDrawBuffer != GL_NONE)
+ {
+ myDrawBuffers.SetValue (anI, aDrawBuffer);
+ }
+ }
+ }
#endif
}
myGlVerMajor = 0;
myGlVerMinor = 0;
myMaxMsaaSamples = 0;
+ myMaxDrawBuffers = 1;
+ myMaxColorAttachments = 1;
ReadGlVersion (myGlVerMajor, myGlVerMinor);
myVendor = (const char* )::glGetString (GL_VENDOR);
if (!caps->ffpEnable
extGS = NULL;
myDefaultVao = 0;
+ //! Make record shorter to retrieve function pointer using variable with same name
+ #define FindProcShort(theFunc) FindProc(#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)
}
}
+ extDrawBuffers = CheckExtension ("GL_EXT_draw_buffers") && FindProc ("glDrawBuffersEXT", myFuncs->glDrawBuffers);
+ arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers") && FindProc ("glDrawBuffersARB", myFuncs->glDrawBuffers);
+
+ if (IsGlGreaterEqual (3, 0) && FindProc ("glDrawBuffers", myFuncs->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;
#else
myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP;
hasTexRGBA8 = Standard_True;
- arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two");
- arbTexFloat = IsGlGreaterEqual (3, 0)
- || CheckExtension ("GL_ARB_texture_float");
- 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;
+
+ 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);
+ }
+
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim);
+ if (IsGlGreaterEqual (1, 5))
+ {
+ glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &myMaxTexCombined);
+ }
if (extAnis)
{
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)
-
// 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 (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"))
core33back = (OpenGl_GlCore33Back* )(&(*myFuncs));
}
- // initialize sampler object
- myTexSampler = new OpenGl_Sampler();
- myTexSampler->Init (*this);
-
if (!has40)
{
checkWrongVersion (4, 0);
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)
if ((theFlags & Graphic3d_DiagnosticInfo_NativePlatform) != 0)
{
#if defined(HAVE_EGL)
- addInfo (theDict, "EGLVersion", ::eglQueryString ((Aspect_Display)myDisplay, EGL_VERSION));
- addInfo (theDict, "EGLVendor", ::eglQueryString ((Aspect_Display)myDisplay, EGL_VENDOR));
- addInfo (theDict, "EGLClientAPIs", ::eglQueryString ((Aspect_Display)myDisplay, EGL_CLIENT_APIS));
+ 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 ((Aspect_Display)myDisplay, EGL_EXTENSIONS));
+ addInfo (theDict, "EGLExtensions", ::eglQueryString ((EGLDisplay )myDisplay, EGL_EXTENSIONS));
}
#elif defined(_WIN32)
if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 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));
- addInfo (theDict, "GLSLversion", (const char*)::glGetString (GL_SHADING_LANGUAGE_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 combined texture units", TCollection_AsciiString(myMaxTexCombined));
addInfo (theDict, "Max MSAA samples", TCollection_AsciiString(myMaxMsaaSamples));
}
{
return;
}
- auto& aRes = mySharedResources->Find (theKey);
+ const Handle(OpenGl_Resource)& aRes = mySharedResources->Find (theKey);
if (aRes->GetRefCount() > 1)
{
return;
continue;
}
- auto& 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 :
// purpose :
// =======================================================================
void OpenGl_Context::SetShadingMaterial (const OpenGl_AspectFace* theAspect,
- const Handle(Graphic3d_PresentationAttributes)& theHighlight,
- const Standard_Boolean theUseDepthWrite,
- Standard_Integer& theRenderingPassFlags)
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight)
{
const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
? theHighlight->BasicFillAreaAspect()
myMatBack = myMatFront;
}
- // handling transparency
- float aTranspFront = (float )aMatFrontSrc.Transparency();
- float aTranspBack = (float )aMatBackSrc .Transparency();
if (!theHighlight.IsNull()
&& theHighlight->BasicFillAreaAspect().IsNull())
{
myMatFront.SetColor (theHighlight->ColorRGBA());
myMatBack .SetColor (theHighlight->ColorRGBA());
- aTranspFront = theHighlight->Transparency();
- aTranspBack = theHighlight->Transparency();
}
- if ((theRenderingPassFlags & OPENGL_NS_2NDPASSDO) != 0)
- {
- // second pass
- myMatFront.Diffuse.a() = aMatFrontSrc.EnvReflexion();
- myMatBack .Diffuse.a() = aMatBackSrc .EnvReflexion();
- }
- else
- {
- if (aMatFrontSrc.EnvReflexion() != 0.0f
- || aMatBackSrc .EnvReflexion() != 0.0f)
- {
- // if the material reflects the environment scene, the second pass is needed
- theRenderingPassFlags |= OPENGL_NS_2NDPASSNEED;
- }
- GLboolean aDepthMask = GL_TRUE;
- if (aTranspFront != 0.0f
- || aTranspBack != 0.0f)
- {
- // render transparent
- myMatFront.Diffuse.a() = 1.0f - aTranspFront;
- myMatBack .Diffuse.a() = 1.0f - aTranspBack;
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- aDepthMask = GL_FALSE;
- }
- else
- {
- // render opaque
- glBlendFunc (GL_ONE, GL_ZERO);
- glDisable (GL_BLEND);
- }
- if (theUseDepthWrite)
- {
- glDepthMask (aDepthMask);
- }
+ 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,
myShaderManager->UpdateMaterialStateTo (myMatFront, myMatBack, toDistinguish, toMapTexture);
}
+// =======================================================================
+// function : CheckIsTransparent
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_AspectFace* theAspect,
+ const Handle(Graphic3d_PresentationAttributes)& theHighlight,
+ Standard_ShortReal& theAlphaFront,
+ Standard_ShortReal& theAlphaBack)
+{
+ const Handle(Graphic3d_AspectFillArea3d)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
+ ? 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();
+ }
+
+ const bool isTransparent = theAlphaFront < 1.0f
+ || theAlphaBack < 1.0f;
+ return isTransparent;
+}
+
// =======================================================================
// function : SetColor4fv
// purpose :
if (core11 != NULL)
{
// glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f
- core11fwd->glLineWidth (theWidth * myResolutionRatio);
+ core11fwd->glLineWidth (theWidth * myLineWidthScale);
}
#ifdef HAVE_GL2PS
if (IsFeedback())
// pack transformation parameters
OpenGl_Vec4 aTrsf[2];
- aTrsf[0].xy() = theParams->Translation();
+ aTrsf[0].x() = -theParams->Translation().x();
+ aTrsf[0].y() = -theParams->Translation().y();
aTrsf[0].zw() = theParams->Scale();
aTrsf[1].x() = std::sin (-theParams->Rotation() * static_cast<float> (M_PI / 180.0));
aTrsf[1].y() = std::cos (-theParams->Rotation() * static_cast<float> (M_PI / 180.0));
return myHatchStyles->SetTypeOfHatch (this, theStyle);
}
+// =======================================================================
+// function : SetPolygonOffset
+// purpose :
+// =======================================================================
+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)
+ 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)
+ {
+ if (toPointNew)
+ {
+ glEnable (GL_POLYGON_OFFSET_POINT);
+ }
+ else
+ {
+ glDisable (GL_POLYGON_OFFSET_POINT);
+ }
+ }
+#endif
+
+ if (myPolygonOffset.Factor != theOffset.Factor
+ || myPolygonOffset.Units != theOffset.Units)
+ {
+ glPolygonOffset (theOffset.Factor, theOffset.Units);
+ }
+ myPolygonOffset = theOffset;
+}
+
// =======================================================================
// function : ApplyModelWorldMatrix
// 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;
+}