std::set<const OpenGl_Structure*> anElements;
// Set of all currently visible and "raytracable" primitive arrays.
- std::set<const OpenGl_PrimitiveArray*> anArrays;
+ std::set<Standard_Size> anArrayIDs;
const OpenGl_LayerList& aList = myView->LayerList();
for (aStructIt.Init (aStructArray (anIndex)); aStructIt.More(); aStructIt.Next())
{
- Standard_ShortReal* aTransform (NULL);
-
const OpenGl_Structure* aStructure = aStructIt.Value();
if (theMode == OpenGl_GUM_CHECK)
if (aPrimArray != NULL)
{
// Collect all primitive arrays in scene.
- anArrays.insert (aPrimArray);
+ anArrayIDs.insert (aPrimArray->GetUID());
}
}
}
if (!aStructure->IsRaytracable())
continue;
- if (aStructure->Transformation()->mat != NULL)
- {
- if (aTransform == NULL)
- aTransform = new Standard_ShortReal[16];
-
- for (Standard_Integer i = 0; i < 4; ++i)
- for (Standard_Integer j = 0; j < 4; ++j)
- {
- aTransform[j * 4 + i] = aStructure->Transformation()->mat[i][j];
- }
- }
-
- AddRaytraceStructure (aStructure, aTransform, anElements);
+ AddRaytraceStructure (aStructure, anElements);
}
-
- delete [] aTransform;
}
}
}
// If primitive array of object not in "anArrays" set then it was hided or deleted.
// If primitive array present in "anArrays" set but we don't have associated object yet, then
// the object is new and still has to be built.
- if ((aTriangleSet != NULL) && ((anArrays.find (aTriangleSet->AssociatedPArray())) != anArrays.end()))
+ if ((aTriangleSet != NULL) && ((anArrayIDs.find (aTriangleSet->AssociatedPArrayID())) != anArrayIDs.end()))
{
anUnchangedObjects.Append (myRaytraceGeometry.Objects().Value (anObjectIdx));
- myArrayToTrianglesMap[aTriangleSet->AssociatedPArray()] = aTriangleSet;
+ myArrayToTrianglesMap[aTriangleSet->AssociatedPArrayID()] = aTriangleSet;
}
}
const BVH_Vec4f aSize = myRaytraceGeometry.Box().Size();
- myRaytraceSceneEpsilon = Max (1e-7f, 1e-4f * sqrtf (
+ myRaytraceSceneEpsilon = Max (1e-6f, 1e-4f * sqrtf (
aSize.x() * aSize.x() + aSize.y() * aSize.y() + aSize.z() * aSize.z()));
return UploadRaytraceData();
// function : AddRaytraceStructure
// purpose : Adds OpenGL structure to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_Workspace::AddRaytraceStructure (const OpenGl_Structure* theStructure,
- const Standard_ShortReal* theTransform, std::set<const OpenGl_Structure*>& theElements)
+Standard_Boolean OpenGl_Workspace::AddRaytraceStructure (const OpenGl_Structure* theStructure, std::set<const OpenGl_Structure*>& theElements)
{
theElements.insert (theStructure);
myRaytraceGeometry.Materials.push_back (aStructMaterial);
}
+ Standard_ShortReal aStructTransformArr[16];
+ Standard_ShortReal* aStructTransform = NULL;
+ if (theStructure->Transformation()->mat != NULL)
+ {
+ aStructTransform = aStructTransformArr;
+ for (Standard_Integer i = 0; i < 4; ++i)
+ {
+ for (Standard_Integer j = 0; j < 4; ++j)
+ {
+ aStructTransform[j * 4 + i] = theStructure->Transformation()->mat[i][j];
+ }
+ }
+ }
+
+ AddRaytraceGroups (theStructure, aStructMatID, aStructTransform);
+
+ // Process all connected OpenGL structures
+ for (OpenGl_ListOfStructure::Iterator anIts (theStructure->ConnectedStructures()); anIts.More(); anIts.Next())
+ {
+ if (anIts.Value()->IsRaytracable())
+ AddRaytraceGroups (anIts.Value(), aStructMatID, aStructTransform);
+ }
+
+ myStructureStates[theStructure] = theStructure->ModificationState();
+ return Standard_True;
+}
+
+// =======================================================================
+// function : AddRaytraceGroups
+// purpose : Adds OpenGL groups to ray-traced scene geometry
+// =======================================================================
+Standard_Boolean OpenGl_Workspace::AddRaytraceGroups (const OpenGl_Structure* theStructure,
+ const Standard_Integer theStructMatId,
+ const Standard_ShortReal* theTransform)
+{
for (OpenGl_Structure::GroupIterator aGroupIter (theStructure->DrawGroups()); aGroupIter.More(); aGroupIter.Next())
{
// Get group material
myRaytraceGeometry.Materials.push_back (aGroupMaterial);
}
- Standard_Integer aMatID = aGroupMatID < 0 ? aStructMatID : aGroupMatID;
+ Standard_Integer aMatID = aGroupMatID < 0 ? theStructMatId : aGroupMatID;
if (aMatID < 0)
{
{
OpenGl_PrimitiveArray* aPrimArray = dynamic_cast<OpenGl_PrimitiveArray*> (aNode->elem);
- std::map<const OpenGl_PrimitiveArray*, OpenGl_TriangleSet*>::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray);
-
if (aPrimArray != NULL)
{
+ std::map<Standard_Size, OpenGl_TriangleSet*>::iterator aSetIter = myArrayToTrianglesMap.find (aPrimArray->GetUID());
+
if (aSetIter != myArrayToTrianglesMap.end())
{
OpenGl_TriangleSet* aSet = aSetIter->second;
}
}
- Standard_ShortReal* aTransform = NULL;
-
- // Process all connected OpenGL structures
- for (OpenGl_ListOfStructure::Iterator anIts (theStructure->ConnectedStructures()); anIts.More(); anIts.Next())
- {
- if (anIts.Value()->Transformation()->mat != NULL)
- {
- if (aTransform == NULL)
- aTransform = new Standard_ShortReal[16];
-
- for (Standard_Integer i = 0; i < 4; ++i)
- for (Standard_Integer j = 0; j < 4; ++j)
- {
- aTransform[j * 4 + i] =
- anIts.Value()->Transformation()->mat[i][j];
- }
- }
-
- if (anIts.Value()->IsRaytracable())
- AddRaytraceStructure (anIts.Value(), aTransform != NULL ? aTransform : theTransform, theElements);
- }
-
- delete[] aTransform;
-
- myStructureStates[theStructure] = theStructure->ModificationState();
-
return Standard_True;
}
}
#endif
- OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray);
+ OpenGl_TriangleSet* aSet = new OpenGl_TriangleSet (theArray->GetUID());
{
aSet->Vertices.reserve (anAttribs->NbElements);
aSet->Normals .reserve (anAttribs->NbElements);
aShaderProgram->SetSampler (myGlContext,
"uEnvironmentMapTexture", OpenGl_RT_EnvironmentMapTexture);
+ aShaderProgram->SetSampler (myGlContext,
+ "uOpenGlColorTexture", OpenGl_RT_OpenGlColorTexture);
+ aShaderProgram->SetSampler (myGlContext,
+ "uOpenGlDepthTexture", OpenGl_RT_OpenGlDepthTexture);
+
if (anIndex == 1)
{
aShaderProgram->SetSampler (myGlContext,
aShaderProgram->GetUniformLocation (myGlContext, "uDirectLT");
myUniformLocations[anIndex][OpenGl_RT_uDirectRT] =
aShaderProgram->GetUniformLocation (myGlContext, "uDirectRT");
+ myUniformLocations[anIndex][OpenGl_RT_uInvModelProj] =
+ aShaderProgram->GetUniformLocation (myGlContext, "uInvModelProj");
myUniformLocations[anIndex][OpenGl_RT_uLightCount] =
aShaderProgram->GetUniformLocation (myGlContext, "uLightCount");
// =======================================================================
void OpenGl_Workspace::ReleaseRaytraceResources()
{
+ NullifyResource (myGlContext, myOpenGlFBO);
NullifyResource (myGlContext, myRaytraceFBO1);
NullifyResource (myGlContext, myRaytraceFBO2);
void OpenGl_Workspace::UpdateCamera (const NCollection_Mat4<GLdouble>& theOrientation,
const NCollection_Mat4<GLdouble>& theViewMapping,
OpenGl_Vec3 theOrigins[4],
- OpenGl_Vec3 theDirects[4])
+ OpenGl_Vec3 theDirects[4],
+ NCollection_Mat4<GLdouble>& theInvModelProj)
{
- NCollection_Mat4<GLdouble> aInvModelProj;
-
// compute inverse model-view-projection matrix
- (theViewMapping * theOrientation).Inverted (aInvModelProj);
+ (theViewMapping * theOrientation).Inverted (theInvModelProj);
Standard_Integer aOriginIndex = 0;
Standard_Integer aDirectIndex = 0;
-1.0,
1.0);
- aOrigin = aInvModelProj * aOrigin;
+ aOrigin = theInvModelProj * aOrigin;
aOrigin.x() = aOrigin.x() / aOrigin.w();
aOrigin.y() = aOrigin.y() / aOrigin.w();
1.0,
1.0);
- aDirect = aInvModelProj * aDirect;
+ aDirect = theInvModelProj * aDirect;
aDirect.x() = aDirect.x() / aDirect.w();
aDirect.y() = aDirect.y() / aDirect.w();
const Standard_Integer theSizeY,
const OpenGl_Vec3 theOrigins[4],
const OpenGl_Vec3 theDirects[4],
+ const OpenGl_Matrix& theInvModelProj,
OpenGl_FrameBuffer* theFrameBuffer)
{
mySceneMinPointTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
myGeometryVertexTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryVertexTexture);
myGeometryNormalTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryNormalTexture);
myGeometryTriangTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryTriangTexture);
+ mySceneTransformTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneTransformTexture);
myRaytraceMaterialTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceMaterialTexture);
myRaytraceLightSrcTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceLightSrcTexture);
- mySceneTransformTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneTransformTexture);
+
+ myOpenGlFBO->ColorTexture()->Bind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlColorTexture);
+ myOpenGlFBO->DepthStencilTexture()->Bind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlDepthTexture);
if (theCView.RenderParams.IsAntialiasingEnabled) // render source image to FBO
{
myUniformLocations[0][OpenGl_RT_uDirectLT], theDirects[2]);
myRaytraceProgram->SetUniform (myGlContext,
myUniformLocations[0][OpenGl_RT_uDirectRT], theDirects[3]);
+ myRaytraceProgram->SetUniform (myGlContext,
+ myUniformLocations[0][OpenGl_RT_uInvModelProj], theInvModelProj);
myRaytraceProgram->SetUniform (myGlContext,
myUniformLocations[0][OpenGl_RT_uSceneRad], myRaytraceSceneRadius);
myRaytraceProgram->SetUniform (myGlContext,
{
myRaytraceProgram->Unbind (myGlContext);
+ myOpenGlFBO->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlColorTexture);
+ myOpenGlFBO->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlDepthTexture);
+ mySceneMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
+ mySceneMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMaxPointTexture);
+ mySceneNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneNodeInfoTexture);
+ myObjectMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMinPointTexture);
+ myObjectMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMaxPointTexture);
+ myObjectNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectNodeInfoTexture);
+ myGeometryVertexTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryVertexTexture);
+ myGeometryNormalTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryNormalTexture);
+ myGeometryTriangTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryTriangTexture);
+ myRaytraceMaterialTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceMaterialTexture);
+ myRaytraceLightSrcTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceLightSrcTexture);
+ mySceneTransformTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneTransformTexture);
+
+ myGlContext->core15fwd->glActiveTexture (GL_TEXTURE0);
+
return Standard_True;
}
myUniformLocations[1][OpenGl_RT_uDirectLT], theDirects[2]);
myPostFSAAProgram->SetUniform (myGlContext,
myUniformLocations[1][OpenGl_RT_uDirectRT], theDirects[3]);
+ myRaytraceProgram->SetUniform (myGlContext,
+ myUniformLocations[1][OpenGl_RT_uInvModelProj], theInvModelProj);
myPostFSAAProgram->SetUniform (myGlContext,
myUniformLocations[1][OpenGl_RT_uSceneRad], myRaytraceSceneRadius);
myPostFSAAProgram->SetUniform (myGlContext,
myUniformLocations[1][OpenGl_RT_aPosition]);
myPostFSAAProgram->Unbind (myGlContext);
+ myRaytraceFBO1->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_FSAAInputTexture);
+ myOpenGlFBO->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlColorTexture);
+ myOpenGlFBO->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlDepthTexture);
+ mySceneMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
+ mySceneMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMaxPointTexture);
+ mySceneNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneNodeInfoTexture);
+ myObjectMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMinPointTexture);
+ myObjectMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMaxPointTexture);
+ myObjectNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectNodeInfoTexture);
+ myGeometryVertexTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryVertexTexture);
+ myGeometryNormalTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryNormalTexture);
+ myGeometryTriangTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryTriangTexture);
+ myRaytraceMaterialTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceMaterialTexture);
+ myRaytraceLightSrcTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_RaytraceLightSrcTexture);
+ mySceneTransformTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneTransformTexture);
+
+ myGlContext->core15fwd->glActiveTexture (GL_TEXTURE0);
return Standard_True;
}
const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const Standard_Boolean theToSwap,
+ const Aspect_CLayer2d& theCOverLayer,
+ const Aspect_CLayer2d& theCUnderLayer,
OpenGl_FrameBuffer* theFrameBuffer)
{
- if (!UpdateRaytraceGeometry (OpenGl_GUM_CHECK))
- return Standard_False;
-
if (!InitRaytraceResources (theCView))
return Standard_False;
OpenGl_Vec3 aOrigins[4];
OpenGl_Vec3 aDirects[4];
+ NCollection_Mat4<GLdouble> anInvModelProj;
UpdateCamera (aOrientationMatrix,
aViewMappingMatrix,
aOrigins,
- aDirects);
+ aDirects,
+ anInvModelProj);
+
+ OpenGl_Matrix anInvModelProjMatrix;
+ for (Standard_Integer j = 0; j < 4; ++j)
+ {
+ for (Standard_Integer i = 0; i < 4; ++i)
+ {
+ anInvModelProjMatrix.mat[j][i] = static_cast<GLfloat>(anInvModelProj.GetValue(i,j));
+ }
+ }
Standard_Boolean wasBlendingEnabled = glIsEnabled (GL_BLEND);
Standard_Boolean wasDepthTestEnabled = glIsEnabled (GL_DEPTH_TEST);
glDisable (GL_DEPTH_TEST);
+ if (theFrameBuffer != NULL)
+ {
+ theFrameBuffer->BindBuffer (myGlContext);
+ }
+
if (NamedStatus & OPENGL_NS_WHITEBACK)
{
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT);
- if (theFrameBuffer != NULL)
- theFrameBuffer->BindBuffer (myGlContext);
-
myView->DrawBackground (*this);
+ myView->RedrawLayer2d (myPrintContext, theCView, theCUnderLayer);
+
// Generate ray-traced image
glMatrixMode (GL_PROJECTION);
+ glPushMatrix();
glLoadIdentity();
glMatrixMode (GL_MODELVIEW);
+ glPushMatrix();
glLoadIdentity();
glEnable (GL_BLEND);
theSizeY,
aOrigins,
aDirects,
+ anInvModelProjMatrix,
theFrameBuffer);
myRaytraceScreenQuad.Unbind (myGlContext);
if (wasDepthTestEnabled)
glEnable (GL_DEPTH_TEST);
+ glMatrixMode (GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode (GL_MODELVIEW);
+ glPopMatrix();
+
+ // Redraw trihedron
+ myView->RedrawTrihedron (this);
+
+ // Redraw overlay
+ const int aMode = 0;
+ DisplayCallback (theCView, (aMode | OCC_PRE_OVERLAY));
+ myView->RedrawLayer2d (myPrintContext, theCView, theCOverLayer);
+ DisplayCallback (theCView, aMode);
+
// Swap the buffers
if (theToSwap)
{
return Standard_True;
}
+
+IMPLEMENT_STANDARD_HANDLE(OpenGl_RaytraceFilter, OpenGl_RenderFilter)
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_RaytraceFilter, OpenGl_RenderFilter)
+
+// =======================================================================
+// function : CanRender
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_RaytraceFilter::CanRender (const OpenGl_Element* theElement)
+{
+ Standard_Boolean aPrevFilterResult = Standard_True;
+ if (!myPrevRenderFilter.IsNull())
+ {
+ aPrevFilterResult = myPrevRenderFilter->CanRender(theElement);
+ }
+ return aPrevFilterResult &&
+ !OpenGl_Raytrace::IsRaytracedElement (theElement);
+}