#include <OpenGl_SceneGeometry.hxx>
#include <OpenGl_Structure.hxx>
#include <OpenGl_Sampler.hxx>
+#include <OpenGl_ShaderManager.hxx>
#include <OpenGl_Texture.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Window.hxx>
void OpenGl_Material::Init (const Graphic3d_MaterialAspect& theMat,
const Quantity_Color& theInteriorColor)
{
- const bool isPhysic = theMat.MaterialType (Graphic3d_MATERIAL_PHYSIC) == Standard_True;
+ const bool isPhysic = theMat.MaterialType (Graphic3d_MATERIAL_PHYSIC);
// ambient component
if (theMat.ReflectionMode (Graphic3d_TOR_AMBIENT))
{
const OpenGl_Vec3& aSrcAmb = isPhysic ? theMat.AmbientColor() : theInteriorColor;
- Ambient = OpenGl_Vec4 (aSrcAmb * (float )theMat.Ambient(), 1.0f);
+ Ambient = OpenGl_Vec4 (aSrcAmb * theMat.Ambient(), 1.0f);
}
else
{
if (theMat.ReflectionMode (Graphic3d_TOR_DIFFUSE))
{
const OpenGl_Vec3& aSrcDif = isPhysic ? theMat.DiffuseColor() : theInteriorColor;
- Diffuse = OpenGl_Vec4 (aSrcDif * (float )theMat.Diffuse(), 1.0f);
+ Diffuse = OpenGl_Vec4 (aSrcDif * theMat.Diffuse(), 1.0f);
}
else
{
if (theMat.ReflectionMode (Graphic3d_TOR_SPECULAR))
{
const OpenGl_Vec3& aSrcSpe = isPhysic ? (const OpenGl_Vec3& )theMat.SpecularColor() : THE_WHITE_COLOR.rgb();
- Specular = OpenGl_Vec4 (aSrcSpe * (float )theMat.Specular(), 1.0f);
+ Specular = OpenGl_Vec4 (aSrcSpe * theMat.Specular(), 1.0f);
}
else
{
if (theMat.ReflectionMode (Graphic3d_TOR_EMISSION))
{
const OpenGl_Vec3& aSrcEms = isPhysic ? theMat.EmissiveColor() : theInteriorColor;
- Emission = OpenGl_Vec4 (aSrcEms * (float )theMat.Emissive(), 1.0f);
+ Emission = OpenGl_Vec4 (aSrcEms * theMat.Emissive(), 1.0f);
}
else
{
Emission = THE_BLACK_COLOR;
}
- ChangeShine() = 128.0f * float(theMat.Shininess());
- ChangeTransparency() = 1.0f - (float )theMat.Transparency();
+ ChangeShine() = 128.0f * theMat.Shininess();
+ ChangeTransparency() = 1.0f - theMat.Transparency();
}
// =======================================================================
// purpose :
// =======================================================================
OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow)
-: NamedStatus (0),
- HighlightColor (&THE_WHITE_COLOR),
- myView (theView),
+: myView (theView),
myWindow (theWindow),
myGlContext (!theWindow.IsNull() ? theWindow->GetGlContext() : NULL),
myUseZBuffer (Standard_True),
myAspectFaceSet (&myDefaultAspectFace),
myAspectMarkerSet (&myDefaultAspectMarker),
myAspectTextSet (&myDefaultAspectText),
- myAspectFaceAppliedWithHL (false),
//
ViewMatrix_applied (&myDefaultMatrix),
StructureMatrix_applied (&myDefaultMatrix),
myToAllowFaceCulling (false),
- myToHighlight (false),
myModelViewMatrix (myDefaultMatrix)
{
if (!myGlContext.IsNull() && myGlContext->MakeCurrent())
ResetAppliedAspect();
+ // reset state for safety
+ myGlContext->BindProgram (Handle(OpenGl_ShaderProgram)());
+ if (myGlContext->core20fwd != NULL)
+ {
+ myGlContext->core20fwd->glUseProgram (OpenGl_ShaderProgram::NO_PROGRAM);
+ }
+ myGlContext->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
return Standard_True;
}
{
myGlContext->BindDefaultVao();
- NamedStatus = !myTextureBound.IsNull() ? OPENGL_NS_TEXTURE : 0;
- HighlightColor = &THE_WHITE_COLOR;
+ myHighlightStyle.Nullify();
myToAllowFaceCulling = false;
myAspectLineSet = &myDefaultAspectLine;
myAspectFaceSet = &myDefaultAspectFace;
return aPrevTexture;
}
-// =======================================================================
-// function : updateMaterial
-// purpose :
-// =======================================================================
-void OpenGl_Workspace::updateMaterial (const int theFlag)
-{
- // Case of hidden line
- if (myAspectFaceSet->Aspect()->InteriorStyle() == Aspect_IS_HIDDENLINE)
- {
- // copy all values including line edge aspect
- *myAspectFaceHl.Aspect().operator->() = *myAspectFaceSet->Aspect();
- myAspectFaceHl.SetAspectEdge (myAspectFaceSet->AspectEdge());
- myAspectFaceHl.Aspect()->SetInteriorColor (myView->BackgroundColor().GetRGB());
- myAspectFaceHl.SetNoLighting (true);
- myAspectFaceSet = &myAspectFaceHl;
- return;
- }
-
- const Graphic3d_MaterialAspect* aSrcMat = &myAspectFaceSet->Aspect()->FrontMaterial();
- const Quantity_Color* aSrcIntColor = &myAspectFaceSet->Aspect()->InteriorColor();
- GLenum aFace = GL_FRONT_AND_BACK;
- if (theFlag == TEL_BACK_MATERIAL)
- {
- aFace = GL_BACK;
- aSrcMat = &myAspectFaceSet->Aspect()->BackMaterial();
- aSrcIntColor = &myAspectFaceSet->Aspect()->BackInteriorColor();
- }
- else if (myAspectFaceSet->Aspect()->Distinguish()
- && !(NamedStatus & OPENGL_NS_RESMAT))
- {
- aFace = GL_FRONT;
- }
-
- myMatTmp.Init (*aSrcMat, *aSrcIntColor);
- if (myToHighlight)
- {
- myMatTmp.SetColor (*HighlightColor);
- }
-
- // handling transparency
- if (NamedStatus & OPENGL_NS_2NDPASSDO)
- {
- // second pass
- myMatTmp.Diffuse.a() = aSrcMat->EnvReflexion();
- }
- else
- {
- if (aSrcMat->EnvReflexion() != 0.0f)
- {
- // if the material reflects the environment scene, the second pass is needed
- NamedStatus |= OPENGL_NS_2NDPASSNEED;
- }
-
- const float aTransp = (float )aSrcMat->Transparency();
- if (aTransp != 0.0f)
- {
- // render transparent
- myMatTmp.Diffuse.a() = 1.0f - aTransp;
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable (GL_BLEND);
- if (myUseDepthWrite)
- {
- glDepthMask (GL_FALSE);
- }
- }
- else
- {
- // render opaque
- glBlendFunc (GL_ONE, GL_ZERO);
- glDisable (GL_BLEND);
- if (myUseDepthWrite)
- {
- glDepthMask (GL_TRUE);
- }
- }
- }
-
- // do not update material properties in case of zero reflection mode,
- // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway.
- if (myAspectFaceSet->IsNoLighting())
- {
- return;
- }
-
- // reset material
- if (NamedStatus & OPENGL_NS_RESMAT)
- {
- #if !defined(GL_ES_VERSION_2_0)
- if (myGlContext->core11 != NULL)
- {
- myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData());
- myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData());
- myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData());
- myGlContext->core11->glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData());
- myGlContext->core11->glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine());
- }
- #endif
-
- if (theFlag == TEL_FRONT_MATERIAL)
- {
- myMatFront = myMatTmp;
- myMatBack = myMatTmp;
- }
- else
- {
- myMatBack = myMatTmp;
- }
-
- NamedStatus &= ~OPENGL_NS_RESMAT;
- return;
- }
-
- // reduce updates
- OpenGl_Material& anOld = (theFlag == TEL_FRONT_MATERIAL)
- ? myMatFront
- : myMatBack;
-#if !defined(GL_ES_VERSION_2_0)
- if (myGlContext->core11 != NULL)
- {
- if (myMatTmp.Ambient.r() != anOld.Ambient.r()
- || myMatTmp.Ambient.g() != anOld.Ambient.g()
- || myMatTmp.Ambient.b() != anOld.Ambient.b())
- {
- myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData());
- }
- if (myMatTmp.Diffuse.r() != anOld.Diffuse.r()
- || myMatTmp.Diffuse.g() != anOld.Diffuse.g()
- || myMatTmp.Diffuse.b() != anOld.Diffuse.b()
- || fabs (myMatTmp.Diffuse.a() - anOld.Diffuse.a()) > 0.01f)
- {
- myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData());
- }
- if (myMatTmp.Specular.r() != anOld.Specular.r()
- || myMatTmp.Specular.g() != anOld.Specular.g()
- || myMatTmp.Specular.b() != anOld.Specular.b())
- {
- myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData());
- }
- if (myMatTmp.Emission.r() != anOld.Emission.r()
- || myMatTmp.Emission.g() != anOld.Emission.g()
- || myMatTmp.Emission.b() != anOld.Emission.b())
- {
- myGlContext->core11->glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData());
- }
- if (myMatTmp.Shine() != anOld.Shine())
- {
- myGlContext->core11->glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine());
- }
- }
-#endif
- anOld = myMatTmp;
- if (aFace == GL_FRONT_AND_BACK)
- {
- myMatBack = myMatTmp;
- }
-}
-
// =======================================================================
// function : SetAspectLine
// purpose :
}
if (toSuppressBackFaces)
{
- if (!(NamedStatus & OPENGL_NS_2NDPASSDO)
- && (float )myAspectFaceSet->Aspect()->FrontMaterial().Transparency() != 0.0f)
+ if ((float )myAspectFaceSet->Aspect()->FrontMaterial().Transparency() != 0.0f)
{
// disable culling in case of translucent shading aspect
toSuppressBackFaces = false;
}
if (myAspectFaceSet->Aspect() == myAspectFaceApplied
- && myToHighlight == myAspectFaceAppliedWithHL)
+ && myHighlightStyle == myAspectFaceAppliedWithHL)
{
return myAspectFaceSet;
}
- myAspectFaceAppliedWithHL = myToHighlight;
+ myAspectFaceAppliedWithHL = myHighlightStyle;
#if !defined(GL_ES_VERSION_2_0)
const Aspect_InteriorStyle anIntstyle = myAspectFaceSet->Aspect()->InteriorStyle();
}
}
- updateMaterial (TEL_FRONT_MATERIAL);
- if (myAspectFaceSet->Aspect()->Distinguish())
+ // Case of hidden line
+ if (myAspectFaceSet->Aspect()->InteriorStyle() == Aspect_IS_HIDDENLINE)
+ {
+ // copy all values including line edge aspect
+ *myAspectFaceHl.Aspect().operator->() = *myAspectFaceSet->Aspect();
+ myAspectFaceHl.SetAspectEdge (myAspectFaceSet->AspectEdge());
+ myAspectFaceHl.Aspect()->SetInteriorColor (myView->BackgroundColor().GetRGB());
+ myAspectFaceHl.SetNoLighting (true);
+ myAspectFaceSet = &myAspectFaceHl;
+ }
+ else
{
- updateMaterial (TEL_BACK_MATERIAL);
+ myGlContext->SetShadingMaterial (myAspectFaceSet, myHighlightStyle);
}
if (myAspectFaceSet->Aspect()->ToMapTexture())
switch (theImage.Format())
{
#if !defined(GL_ES_VERSION_2_0)
- case Image_PixMap::ImgGray:
+ case Image_Format_Gray:
aFormat = GL_DEPTH_COMPONENT;
aType = GL_UNSIGNED_BYTE;
break;
- case Image_PixMap::ImgGrayF:
+ case Image_Format_GrayF:
aFormat = GL_DEPTH_COMPONENT;
aType = GL_FLOAT;
break;
- case Image_PixMap::ImgRGB:
+ case Image_Format_RGB:
aFormat = GL_RGB;
aType = GL_UNSIGNED_BYTE;
break;
- case Image_PixMap::ImgBGR:
+ case Image_Format_BGR:
aFormat = GL_BGR;
aType = GL_UNSIGNED_BYTE;
break;
- case Image_PixMap::ImgBGRA:
- case Image_PixMap::ImgBGR32:
+ case Image_Format_BGRA:
+ case Image_Format_BGR32:
aFormat = GL_BGRA;
aType = GL_UNSIGNED_BYTE;
break;
- case Image_PixMap::ImgBGRF:
+ case Image_Format_BGRF:
aFormat = GL_BGR;
aType = GL_FLOAT;
break;
- case Image_PixMap::ImgBGRAF:
+ case Image_Format_BGRAF:
aFormat = GL_BGRA;
aType = GL_FLOAT;
break;
#else
- case Image_PixMap::ImgGray:
- case Image_PixMap::ImgGrayF:
- case Image_PixMap::ImgBGRF:
- case Image_PixMap::ImgBGRAF:
+ case Image_Format_Gray:
+ case Image_Format_GrayF:
+ case Image_Format_BGRF:
+ case Image_Format_BGRAF:
return Standard_False;
- case Image_PixMap::ImgBGRA:
- case Image_PixMap::ImgBGR32:
+ case Image_Format_BGRA:
+ case Image_Format_BGR32:
aFormat = GL_RGBA;
aType = GL_UNSIGNED_BYTE;
toSwapRgbaBgra = true;
break;
- case Image_PixMap::ImgBGR:
- case Image_PixMap::ImgRGB:
+ case Image_Format_BGR:
+ case Image_Format_RGB:
aFormat = GL_RGBA;
aType = GL_UNSIGNED_BYTE;
toConvRgba2Rgb = true;
break;
#endif
- case Image_PixMap::ImgRGBA:
- case Image_PixMap::ImgRGB32:
+ case Image_Format_RGBA:
+ case Image_Format_RGB32:
aFormat = GL_RGBA;
aType = GL_UNSIGNED_BYTE;
break;
- case Image_PixMap::ImgRGBF:
+ case Image_Format_RGBF:
aFormat = GL_RGB;
aType = GL_FLOAT;
break;
- case Image_PixMap::ImgRGBAF:
+ case Image_Format_RGBAF:
aFormat = GL_RGBA;
aType = GL_FLOAT;
break;
- case Image_PixMap::ImgAlpha:
- case Image_PixMap::ImgAlphaF:
+ case Image_Format_Alpha:
+ case Image_Format_AlphaF:
return Standard_False; // GL_ALPHA is no more supported in core context
- case Image_PixMap::ImgUNKNOWN:
+ case Image_Format_UNKNOWN:
return Standard_False;
}
// while order in memory depends on the flag and processed by ChangeRow() method
glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, aRowBuffer.ChangeData());
const Image_ColorRGBA* aRowDataRgba = (const Image_ColorRGBA* )aRowBuffer.Data();
- if (theImage.Format() == Image_PixMap::ImgBGR)
+ if (theImage.Format() == Image_Format_BGR)
{
convertRowFromRgba ((Image_ColorBGR* )theImage.ChangeRow (aRow), aRowDataRgba, theImage.SizeX());
}
}
// =======================================================================
-// function : CanRender
+// function : ShouldRender
// purpose :
// =======================================================================
-Standard_Boolean OpenGl_RaytraceFilter::CanRender (const OpenGl_Element* theElement)
+Standard_Boolean OpenGl_RaytraceFilter::ShouldRender (const Handle(OpenGl_Workspace)& theWorkspace,
+ const OpenGl_Element* theElement)
{
Standard_Boolean aPrevFilterResult = Standard_True;
if (!myPrevRenderFilter.IsNull())
{
- aPrevFilterResult = myPrevRenderFilter->CanRender (theElement);
+ aPrevFilterResult = myPrevRenderFilter->ShouldRender (theWorkspace, theElement);
}
return aPrevFilterResult &&
!OpenGl_Raytrace::IsRaytracedElement (theElement);