mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1a67767e78 | ||
|
5b5f819f51 | ||
|
1d09c51ac2 | ||
|
06e6ef2726 |
@@ -1,7 +1,7 @@
|
||||
FoundationClasses TKernel TKMath
|
||||
ModelingData TKG2d TKG3d TKGeomBase TKBRep
|
||||
ModelingAlgorithms TKGeomAlgo TKTopAlgo TKPrim TKBO TKBool TKHLR TKFillet TKOffset TKFeat TKMesh TKXMesh TKShHealing
|
||||
Visualization TKService TKV3d TKOpenGl TKMeshVS TKIVtk TKD3DHost
|
||||
Visualization TKService TKV3d TKOpenGl TKMeshVS TKIVtk TKD3DHost TKVulkan
|
||||
ApplicationFramework TKCDF TKLCAF TKCAF TKBinL TKXmlL TKBin TKXml TKStdL TKStd TKTObj TKBinTObj TKXmlTObj TKVCAF
|
||||
DataExchange TKXSBase TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP TKIGES TKXCAF TKXDEIGES TKXDESTEP TKSTL TKVRML TKXmlXCAF TKBinXCAF
|
||||
Draw TKDraw TKTopTest TKViewerTest TKXSDRAW TKDCAF TKXDEDRAW TKTObjDRAW TKQADraw TKIVtkDraw DRAWEXE
|
||||
|
@@ -206,6 +206,7 @@ n Image
|
||||
n MeshVS
|
||||
n OpenGl
|
||||
n D3DHost
|
||||
n Vulkan
|
||||
n Prs3d
|
||||
n PrsMgr
|
||||
n Select3D
|
||||
@@ -223,6 +224,7 @@ r Shaders
|
||||
t TKMeshVS
|
||||
t TKOpenGl
|
||||
t TKD3DHost
|
||||
t TKVulkan
|
||||
t TKService
|
||||
t TKV3d
|
||||
n BinTObjDrivers
|
||||
|
@@ -58,6 +58,9 @@ if (USE_TCL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Vulkan
|
||||
set (CSF_vulkan "vulkan-1")
|
||||
|
||||
if (WIN32)
|
||||
set (CSF_advapi32 "advapi32.lib")
|
||||
set (CSF_gdi32 "gdi32.lib")
|
||||
|
@@ -1349,6 +1349,8 @@ proc osutils:csfList { theOS theCsfLibsMap theCsfFrmsMap } {
|
||||
set aLibsMap(CSF_LIBLZMA) "liblzma"
|
||||
}
|
||||
|
||||
set aLibsMap(CSF_vulkan) "vulkan-1"
|
||||
|
||||
if { "$theOS" == "wnt" } {
|
||||
# WinAPI libraries
|
||||
set aLibsMap(CSF_kernel32) "kernel32"
|
||||
|
@@ -33,6 +33,10 @@ Graphic3d_Buffer.cxx
|
||||
Graphic3d_Buffer.hxx
|
||||
Graphic3d_BufferRange.hxx
|
||||
Graphic3d_BufferType.hxx
|
||||
Graphic3d_BvhCStructureSet.cxx
|
||||
Graphic3d_BvhCStructureSet.hxx
|
||||
Graphic3d_BvhCStructureSetTrsfPers.cxx
|
||||
Graphic3d_BvhCStructureSetTrsfPers.hxx
|
||||
Graphic3d_Camera.cxx
|
||||
Graphic3d_Camera.hxx
|
||||
Graphic3d_CameraTile.hxx
|
||||
@@ -44,6 +48,8 @@ Graphic3d_ClipPlane.hxx
|
||||
Graphic3d_CStructure.cxx
|
||||
Graphic3d_CStructure.hxx
|
||||
Graphic3d_CTexture.hxx
|
||||
Graphic3d_CullingTool.cxx
|
||||
Graphic3d_CullingTool.hxx
|
||||
Graphic3d_CView.cxx
|
||||
Graphic3d_CView.hxx
|
||||
Graphic3d_DataStructureManager.cxx
|
||||
@@ -78,6 +84,7 @@ Graphic3d_MapOfAspectsToAspects.hxx
|
||||
Graphic3d_MapIteratorOfMapOfStructure.hxx
|
||||
Graphic3d_MapOfObject.hxx
|
||||
Graphic3d_MapOfStructure.hxx
|
||||
Graphic3d_MapOfZLayerSettings.hxx
|
||||
Graphic3d_MarkerImage.cxx
|
||||
Graphic3d_MarkerImage.hxx
|
||||
Graphic3d_Mat4.hxx
|
||||
@@ -173,5 +180,7 @@ Graphic3d_VerticalTextAlignment.hxx
|
||||
Graphic3d_ViewAffinity.cxx
|
||||
Graphic3d_ViewAffinity.hxx
|
||||
Graphic3d_WorldViewProjState.hxx
|
||||
Graphic3d_Layer.cxx
|
||||
Graphic3d_Layer.hxx
|
||||
Graphic3d_ZLayerId.hxx
|
||||
Graphic3d_ZLayerSettings.hxx
|
||||
|
@@ -13,18 +13,18 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <OpenGl_BVHClipPrimitiveSet.hxx>
|
||||
#include <Graphic3d_BvhCStructureSet.hxx>
|
||||
|
||||
#include <BVH_BinnedBuilder.hxx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
#include <Graphic3d_CStructure.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_BVHClipPrimitiveSet, BVH_PrimitiveSet3d)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_BvhCStructureSet, BVH_PrimitiveSet3d)
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_BVHClipPrimitiveSet
|
||||
// function : Graphic3d_BvhCStructureSet
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OpenGl_BVHClipPrimitiveSet::OpenGl_BVHClipPrimitiveSet()
|
||||
Graphic3d_BvhCStructureSet::Graphic3d_BvhCStructureSet()
|
||||
{
|
||||
myBuilder = new BVH_BinnedBuilder<Standard_Real, 3> (BVH_Constants_LeafNodeSizeSingle, BVH_Constants_MaxTreeDepth);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ OpenGl_BVHClipPrimitiveSet::OpenGl_BVHClipPrimitiveSet()
|
||||
// function : Size
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Integer OpenGl_BVHClipPrimitiveSet::Size() const
|
||||
Standard_Integer Graphic3d_BvhCStructureSet::Size() const
|
||||
{
|
||||
return myStructs.Size();
|
||||
}
|
||||
@@ -42,7 +42,7 @@ Standard_Integer OpenGl_BVHClipPrimitiveSet::Size() const
|
||||
// function : Box
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Graphic3d_BndBox3d OpenGl_BVHClipPrimitiveSet::Box (const Standard_Integer theIdx) const
|
||||
Graphic3d_BndBox3d Graphic3d_BvhCStructureSet::Box (const Standard_Integer theIdx) const
|
||||
{
|
||||
return myStructs.FindKey (theIdx + 1)->BoundingBox();
|
||||
}
|
||||
@@ -51,7 +51,7 @@ Graphic3d_BndBox3d OpenGl_BVHClipPrimitiveSet::Box (const Standard_Integer theId
|
||||
// function : Center
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Real OpenGl_BVHClipPrimitiveSet::Center (const Standard_Integer theIdx,
|
||||
Standard_Real Graphic3d_BvhCStructureSet::Center (const Standard_Integer theIdx,
|
||||
const Standard_Integer theAxis) const
|
||||
{
|
||||
Graphic3d_BndBox3d aBndBox = myStructs.FindKey (theIdx + 1)->BoundingBox();
|
||||
@@ -66,7 +66,7 @@ Standard_Real OpenGl_BVHClipPrimitiveSet::Center (const Standard_Integer theIdx,
|
||||
// function : Swap
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1,
|
||||
void Graphic3d_BvhCStructureSet::Swap (const Standard_Integer theIdx1,
|
||||
const Standard_Integer theIdx2)
|
||||
{
|
||||
myStructs.Swap (theIdx1 + 1, theIdx2 + 1);
|
||||
@@ -76,7 +76,7 @@ void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1,
|
||||
// function : Add
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct)
|
||||
Standard_Boolean Graphic3d_BvhCStructureSet::Add (const Graphic3d_CStructure* theStruct)
|
||||
{
|
||||
const Standard_Integer aSize = myStructs.Size();
|
||||
|
||||
@@ -94,7 +94,7 @@ Standard_Boolean OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStr
|
||||
// function : Remove
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct)
|
||||
Standard_Boolean Graphic3d_BvhCStructureSet::Remove (const Graphic3d_CStructure* theStruct)
|
||||
{
|
||||
const Standard_Integer anIndex = myStructs.FindIndex (theStruct);
|
||||
|
||||
@@ -114,7 +114,7 @@ Standard_Boolean OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* the
|
||||
// function : Clear
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHClipPrimitiveSet::Clear()
|
||||
void Graphic3d_BvhCStructureSet::Clear()
|
||||
{
|
||||
myStructs.Clear();
|
||||
MarkDirty();
|
||||
@@ -124,7 +124,7 @@ void OpenGl_BVHClipPrimitiveSet::Clear()
|
||||
// function : GetStructureById
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const OpenGl_Structure* OpenGl_BVHClipPrimitiveSet::GetStructureById (Standard_Integer theId)
|
||||
const Graphic3d_CStructure* Graphic3d_BvhCStructureSet::GetStructureById (Standard_Integer theId)
|
||||
{
|
||||
return myStructs.FindKey (theId + 1);
|
||||
}
|
@@ -13,19 +13,19 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _OpenGl_BVHClipPrimitiveSet_HeaderFile
|
||||
#define _OpenGl_BVHClipPrimitiveSet_HeaderFile
|
||||
#ifndef _Graphic3d_BvhCStructureSet_HeaderFile
|
||||
#define _Graphic3d_BvhCStructureSet_HeaderFile
|
||||
|
||||
#include <BVH_PrimitiveSet3d.hxx>
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <Graphic3d_BndBox3d.hxx>
|
||||
#include <NCollection_IndexedMap.hxx>
|
||||
|
||||
#include <OpenGl_Structure.hxx>
|
||||
class Graphic3d_CStructure;
|
||||
|
||||
//! Set of OpenGl_Structures for building BVH tree.
|
||||
class OpenGl_BVHClipPrimitiveSet : public BVH_PrimitiveSet3d
|
||||
class Graphic3d_BvhCStructureSet : public BVH_PrimitiveSet3d
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(OpenGl_BVHClipPrimitiveSet, BVH_PrimitiveSet3d)
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_BvhCStructureSet, BVH_PrimitiveSet3d)
|
||||
protected:
|
||||
|
||||
using BVH_PrimitiveSet3d::Box;
|
||||
@@ -33,7 +33,7 @@ protected:
|
||||
public:
|
||||
|
||||
//! Creates an empty primitive set for BVH clipping.
|
||||
OpenGl_BVHClipPrimitiveSet();
|
||||
Graphic3d_BvhCStructureSet();
|
||||
|
||||
//! Returns total number of structures.
|
||||
virtual Standard_Integer Size() const Standard_OVERRIDE;
|
||||
@@ -51,25 +51,25 @@ public:
|
||||
|
||||
//! Adds structure to the set.
|
||||
//! @return true if structure added, otherwise returns false (structure already in the set).
|
||||
Standard_Boolean Add (const OpenGl_Structure* theStruct);
|
||||
Standard_Boolean Add (const Graphic3d_CStructure* theStruct);
|
||||
|
||||
//! Removes the given structure from the set.
|
||||
//! @return true if structure removed, otherwise returns false (structure is not in the set).
|
||||
Standard_Boolean Remove (const OpenGl_Structure* theStruct);
|
||||
Standard_Boolean Remove (const Graphic3d_CStructure* theStruct);
|
||||
|
||||
//! Cleans the whole primitive set.
|
||||
void Clear();
|
||||
|
||||
//! Returns the structure corresponding to the given ID.
|
||||
const OpenGl_Structure* GetStructureById (Standard_Integer theId);
|
||||
const Graphic3d_CStructure* GetStructureById (Standard_Integer theId);
|
||||
|
||||
//! Access directly a collection of structures.
|
||||
const NCollection_IndexedMap<const OpenGl_Structure*>& Structures() const { return myStructs; }
|
||||
const NCollection_IndexedMap<const Graphic3d_CStructure*>& Structures() const { return myStructs; }
|
||||
|
||||
private:
|
||||
|
||||
NCollection_IndexedMap<const OpenGl_Structure*> myStructs; //!< Indexed map of structures.
|
||||
NCollection_IndexedMap<const Graphic3d_CStructure*> myStructs; //!< Indexed map of structures.
|
||||
|
||||
};
|
||||
|
||||
#endif // _OpenGl_BVHClipPrimitiveSet_HeaderFile
|
||||
#endif // _Graphic3d_BvhCStructureSet_HeaderFile
|
@@ -13,13 +13,15 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <OpenGl_BVHClipPrimitiveTrsfPersSet.hxx>
|
||||
#include <Graphic3d_BvhCStructureSetTrsfPers.hxx>
|
||||
|
||||
#include <Graphic3d_CStructure.hxx>
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_BVHClipPrimitiveTrsfPersSet
|
||||
// function : Graphic3d_BvhCStructureSetTrsfPers
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OpenGl_BVHClipPrimitiveTrsfPersSet::OpenGl_BVHClipPrimitiveTrsfPersSet (const Handle(Select3D_BVHBuilder3d)& theBuilder)
|
||||
Graphic3d_BvhCStructureSetTrsfPers::Graphic3d_BvhCStructureSetTrsfPers (const Handle(Select3D_BVHBuilder3d)& theBuilder)
|
||||
: myIsDirty (Standard_False),
|
||||
myBVH (new BVH_Tree<Standard_Real, 3>()),
|
||||
myBuilder (theBuilder)
|
||||
@@ -31,7 +33,7 @@ OpenGl_BVHClipPrimitiveTrsfPersSet::OpenGl_BVHClipPrimitiveTrsfPersSet (const Ha
|
||||
// function : Size
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Integer OpenGl_BVHClipPrimitiveTrsfPersSet::Size() const
|
||||
Standard_Integer Graphic3d_BvhCStructureSetTrsfPers::Size() const
|
||||
{
|
||||
return myStructs.Size();
|
||||
}
|
||||
@@ -40,7 +42,7 @@ Standard_Integer OpenGl_BVHClipPrimitiveTrsfPersSet::Size() const
|
||||
// function : Box
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Graphic3d_BndBox3d OpenGl_BVHClipPrimitiveTrsfPersSet::Box (const Standard_Integer theIdx) const
|
||||
Graphic3d_BndBox3d Graphic3d_BvhCStructureSetTrsfPers::Box (const Standard_Integer theIdx) const
|
||||
{
|
||||
return *myStructBoxes (theIdx + 1);
|
||||
}
|
||||
@@ -49,7 +51,7 @@ Graphic3d_BndBox3d OpenGl_BVHClipPrimitiveTrsfPersSet::Box (const Standard_Integ
|
||||
// function : Center
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Real OpenGl_BVHClipPrimitiveTrsfPersSet::Center (const Standard_Integer theIdx,
|
||||
Standard_Real Graphic3d_BvhCStructureSetTrsfPers::Center (const Standard_Integer theIdx,
|
||||
const Standard_Integer theAxis) const
|
||||
{
|
||||
const Graphic3d_BndBox3d& aBndBox = *myStructBoxes (theIdx + 1);
|
||||
@@ -60,7 +62,7 @@ Standard_Real OpenGl_BVHClipPrimitiveTrsfPersSet::Center (const Standard_Integer
|
||||
// function : Swap
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHClipPrimitiveTrsfPersSet::Swap (const Standard_Integer theIdx1,
|
||||
void Graphic3d_BvhCStructureSetTrsfPers::Swap (const Standard_Integer theIdx1,
|
||||
const Standard_Integer theIdx2)
|
||||
{
|
||||
const Standard_Integer aStructIdx1 = theIdx1 + 1;
|
||||
@@ -74,7 +76,7 @@ void OpenGl_BVHClipPrimitiveTrsfPersSet::Swap (const Standard_Integer theIdx1,
|
||||
// function : Add
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean OpenGl_BVHClipPrimitiveTrsfPersSet::Add (const OpenGl_Structure* theStruct)
|
||||
Standard_Boolean Graphic3d_BvhCStructureSetTrsfPers::Add (const Graphic3d_CStructure* theStruct)
|
||||
{
|
||||
const Standard_Integer aSize = myStructs.Size();
|
||||
|
||||
@@ -92,7 +94,7 @@ Standard_Boolean OpenGl_BVHClipPrimitiveTrsfPersSet::Add (const OpenGl_Structure
|
||||
// function : Remove
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean OpenGl_BVHClipPrimitiveTrsfPersSet::Remove (const OpenGl_Structure* theStruct)
|
||||
Standard_Boolean Graphic3d_BvhCStructureSetTrsfPers::Remove (const Graphic3d_CStructure* theStruct)
|
||||
{
|
||||
const Standard_Integer anIndex = myStructs.FindIndex (theStruct);
|
||||
|
||||
@@ -112,7 +114,7 @@ Standard_Boolean OpenGl_BVHClipPrimitiveTrsfPersSet::Remove (const OpenGl_Struct
|
||||
// function : Clear
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHClipPrimitiveTrsfPersSet::Clear()
|
||||
void Graphic3d_BvhCStructureSetTrsfPers::Clear()
|
||||
{
|
||||
myStructs.Clear();
|
||||
MarkDirty();
|
||||
@@ -122,7 +124,7 @@ void OpenGl_BVHClipPrimitiveTrsfPersSet::Clear()
|
||||
// function : GetStructureById
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const OpenGl_Structure* OpenGl_BVHClipPrimitiveTrsfPersSet::GetStructureById (Standard_Integer theId)
|
||||
const Graphic3d_CStructure* Graphic3d_BvhCStructureSetTrsfPers::GetStructureById (Standard_Integer theId)
|
||||
{
|
||||
return myStructs.FindKey (theId + 1);
|
||||
}
|
||||
@@ -131,13 +133,12 @@ const OpenGl_Structure* OpenGl_BVHClipPrimitiveTrsfPersSet::GetStructureById (St
|
||||
// function : BVH
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
const opencascade::handle<BVH_Tree<Standard_Real, 3> >&
|
||||
OpenGl_BVHClipPrimitiveTrsfPersSet::BVH (const Handle(Graphic3d_Camera)& theCamera,
|
||||
const OpenGl_Mat4d& theProjectionMatrix,
|
||||
const OpenGl_Mat4d& theWorldViewMatrix,
|
||||
const Standard_Integer theViewportWidth,
|
||||
const Standard_Integer theViewportHeight,
|
||||
const Graphic3d_WorldViewProjState& theWVPState)
|
||||
const opencascade::handle<BVH_Tree<Standard_Real, 3> >& Graphic3d_BvhCStructureSetTrsfPers::BVH (const Handle(Graphic3d_Camera)& theCamera,
|
||||
const Graphic3d_Mat4d& theProjectionMatrix,
|
||||
const Graphic3d_Mat4d& theWorldViewMatrix,
|
||||
const Standard_Integer theViewportWidth,
|
||||
const Standard_Integer theViewportHeight,
|
||||
const Graphic3d_WorldViewProjState& theWVPState)
|
||||
{
|
||||
if (!myIsDirty
|
||||
&& (myStructBoxesState.IsValid()
|
||||
@@ -150,7 +151,7 @@ const opencascade::handle<BVH_Tree<Standard_Real, 3> >&
|
||||
|
||||
for (Standard_Integer aStructIdx = 1; aStructIdx <= myStructs.Size(); ++aStructIdx)
|
||||
{
|
||||
const OpenGl_Structure* aStructure = myStructs (aStructIdx);
|
||||
const Graphic3d_CStructure* aStructure = myStructs (aStructIdx);
|
||||
|
||||
Handle(HBndBox3d) aBoundingBox = new HBndBox3d();
|
||||
*aBoundingBox = aStructure->BoundingBox();
|
@@ -13,24 +13,26 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile
|
||||
#define _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile
|
||||
#ifndef _Graphic3d_BvhCStructureSetTrsfPers_HeaderFile
|
||||
#define _Graphic3d_BvhCStructureSetTrsfPers_HeaderFile
|
||||
|
||||
#include <BVH_Set.hxx>
|
||||
#include <BVH_Tree.hxx>
|
||||
#include <Graphic3d_BndBox4f.hxx>
|
||||
#include <Graphic3d_BndBox3d.hxx>
|
||||
#include <Graphic3d_Mat4d.hxx>
|
||||
#include <Graphic3d_WorldViewProjState.hxx>
|
||||
#include <NCollection_Shared.hxx>
|
||||
#include <NCollection_IndexedMap.hxx>
|
||||
#include <OpenGl_Structure.hxx>
|
||||
#include <OpenGl_Vec.hxx>
|
||||
#include <Select3D_BVHBuilder3d.hxx>
|
||||
|
||||
class Graphic3d_Camera;
|
||||
class Graphic3d_CStructure;
|
||||
|
||||
//! Set of transformation persistent OpenGl_Structure for building BVH tree.
|
||||
//! Provides built-in mechanism to invalidate tree when world view projection state changes.
|
||||
//! Due to frequent invalidation of BVH tree the choice of BVH tree builder is made
|
||||
//! in favor of BVH linear builder (quick rebuild).
|
||||
class OpenGl_BVHClipPrimitiveTrsfPersSet : public BVH_Set<Standard_Real, 3>
|
||||
class Graphic3d_BvhCStructureSetTrsfPers : public BVH_Set<Standard_Real, 3>
|
||||
{
|
||||
private:
|
||||
|
||||
@@ -39,7 +41,7 @@ private:
|
||||
public:
|
||||
|
||||
//! Creates an empty primitive set for BVH clipping.
|
||||
OpenGl_BVHClipPrimitiveTrsfPersSet (const Handle(Select3D_BVHBuilder3d)& theBuilder);
|
||||
Graphic3d_BvhCStructureSetTrsfPers (const Handle(Select3D_BVHBuilder3d)& theBuilder);
|
||||
|
||||
//! Returns total number of structures.
|
||||
virtual Standard_Integer Size() const Standard_OVERRIDE;
|
||||
@@ -57,20 +59,20 @@ public:
|
||||
|
||||
//! Adds structure to the set.
|
||||
//! @return true if structure added, otherwise returns false (structure already in the set).
|
||||
Standard_Boolean Add (const OpenGl_Structure* theStruct);
|
||||
Standard_Boolean Add (const Graphic3d_CStructure* theStruct);
|
||||
|
||||
//! Removes the given structure from the set.
|
||||
//! @return true if structure removed, otherwise returns false (structure is not in the set).
|
||||
Standard_Boolean Remove (const OpenGl_Structure* theStruct);
|
||||
Standard_Boolean Remove (const Graphic3d_CStructure* theStruct);
|
||||
|
||||
//! Cleans the whole primitive set.
|
||||
void Clear();
|
||||
|
||||
//! Returns the structure corresponding to the given ID.
|
||||
const OpenGl_Structure* GetStructureById (Standard_Integer theId);
|
||||
const Graphic3d_CStructure* GetStructureById (Standard_Integer theId);
|
||||
|
||||
//! Access directly a collection of structures.
|
||||
const NCollection_IndexedMap<const OpenGl_Structure*>& Structures() const { return myStructs; }
|
||||
const NCollection_IndexedMap<const Graphic3d_CStructure*>& Structures() const { return myStructs; }
|
||||
|
||||
//! Marks object state as outdated (needs BVH rebuilding).
|
||||
void MarkDirty()
|
||||
@@ -80,8 +82,8 @@ public:
|
||||
|
||||
//! Returns BVH tree for the given world view projection (builds it if necessary).
|
||||
const opencascade::handle<BVH_Tree<Standard_Real, 3> >& BVH (const Handle(Graphic3d_Camera)& theCamera,
|
||||
const OpenGl_Mat4d& theProjectionMatrix,
|
||||
const OpenGl_Mat4d& theWorldViewMatrix,
|
||||
const Graphic3d_Mat4d& theProjectionMatrix,
|
||||
const Graphic3d_Mat4d& theWorldViewMatrix,
|
||||
const Standard_Integer theViewportWidth,
|
||||
const Standard_Integer theViewportHeight,
|
||||
const Graphic3d_WorldViewProjState& theWVPState);
|
||||
@@ -104,7 +106,7 @@ private:
|
||||
Handle(Select3D_BVHBuilder3d) myBuilder;
|
||||
|
||||
//! Indexed map of structures.
|
||||
NCollection_IndexedMap<const OpenGl_Structure*> myStructs;
|
||||
NCollection_IndexedMap<const Graphic3d_CStructure*> myStructs;
|
||||
|
||||
//! Cached set of bounding boxes precomputed for transformation persistent selectable objects.
|
||||
//! Cache exists only during computation of BVH Tree. Bounding boxes are world view projection
|
||||
@@ -115,4 +117,4 @@ private:
|
||||
Graphic3d_WorldViewProjState myStructBoxesState;
|
||||
};
|
||||
|
||||
#endif // _OpenGl_BVHClipPrimitiveTrsfPersSet_HeaderFile
|
||||
#endif // _Graphic3d_BvhCStructureSetTrsfPers_HeaderFile
|
@@ -19,7 +19,6 @@
|
||||
#include <Graphic3d_TransModeFlags.hxx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CStructure,Standard_Transient)
|
||||
|
||||
//=============================================================================
|
||||
@@ -39,7 +38,8 @@ Graphic3d_CStructure::Graphic3d_CStructure (const Handle(Graphic3d_StructureMana
|
||||
IsForHighlight (Standard_False),
|
||||
IsMutable (Standard_False),
|
||||
Is2dText (Standard_False),
|
||||
myGraphicDriver (theManager->GraphicDriver())
|
||||
myGraphicDriver (theManager->GraphicDriver()),
|
||||
myIsCulled (Standard_True)
|
||||
{
|
||||
Id = myGraphicDriver->NewIdentification();
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <Graphic3d_Vec3.hxx>
|
||||
#include <Graphic3d_ZLayerId.hxx>
|
||||
#include <Geom_Transformation.hxx>
|
||||
#include <NCollection_IndexedMap.hxx>
|
||||
|
||||
class Graphic3d_GraphicDriver;
|
||||
class Graphic3d_StructureManager;
|
||||
@@ -33,6 +34,35 @@ class Graphic3d_StructureManager;
|
||||
//! Low-level graphic structure interface
|
||||
class Graphic3d_CStructure : public Standard_Transient
|
||||
{
|
||||
protected:
|
||||
|
||||
//! Auxiliary wrapper to iterate through structure list.
|
||||
template<class Struct_t>
|
||||
class SubclassStructIterator
|
||||
{
|
||||
public:
|
||||
SubclassStructIterator (const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructs) : myIter (theStructs) {}
|
||||
Standard_Boolean More() const { return myIter.More(); }
|
||||
void Next() { myIter.Next(); }
|
||||
const Struct_t* Value() const { return (const Struct_t* )(myIter.Value()); }
|
||||
Struct_t* ChangeValue() { return (Struct_t* )(myIter.Value()); }
|
||||
private:
|
||||
NCollection_IndexedMap<const Graphic3d_CStructure*>::Iterator myIter;
|
||||
};
|
||||
|
||||
//! Auxiliary wrapper to iterate through group sequence.
|
||||
template<class Group_t>
|
||||
class SubclassGroupIterator
|
||||
{
|
||||
public:
|
||||
SubclassGroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
|
||||
Standard_Boolean More() const { return myIter.More(); }
|
||||
void Next() { myIter.Next(); }
|
||||
const Group_t* Value() const { return (const Group_t* )(myIter.Value().get()); }
|
||||
Group_t* ChangeValue() { return (Group_t* )(myIter.ChangeValue().get()); }
|
||||
private:
|
||||
Graphic3d_SequenceOfGroup::Iterator myIter;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
@@ -103,6 +133,28 @@ public:
|
||||
//! highlight flag is set to true
|
||||
const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
|
||||
|
||||
public:
|
||||
|
||||
//! Returns FALSE if the structure hits the current view volume, otherwise returns TRUE.
|
||||
Standard_Boolean IsCulled() const { return myIsCulled; }
|
||||
|
||||
//! Marks structure as culled/not culled - note that IsAlwaysRendered() is ignored here!
|
||||
void SetCulled (Standard_Boolean theIsCulled) const { myIsCulled = theIsCulled; }
|
||||
|
||||
//! Marks structure as overlapping the current view volume one.
|
||||
//! The method is called during traverse of BVH tree.
|
||||
void MarkAsNotCulled() const { myIsCulled = Standard_False; }
|
||||
|
||||
//! Checks if the structure should be included into BVH tree or not.
|
||||
Standard_Boolean IsAlwaysRendered() const
|
||||
{
|
||||
return IsInfinite
|
||||
|| IsForHighlight
|
||||
|| IsMutable
|
||||
|| Is2dText
|
||||
|| (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! Update structure visibility state
|
||||
@@ -133,6 +185,9 @@ public:
|
||||
//! Remove group from this structure
|
||||
virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) = 0;
|
||||
|
||||
//! Update render transformation matrix.
|
||||
virtual void updateLayerTransformation() {}
|
||||
|
||||
public:
|
||||
|
||||
int Id;
|
||||
@@ -168,6 +223,8 @@ protected:
|
||||
Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
|
||||
Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //! Current highlight style; is set only if highlight flag is true
|
||||
|
||||
mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_CStructure,Standard_Transient) // Type definition
|
||||
|
@@ -33,7 +33,9 @@ namespace
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Graphic3d_CView::Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr)
|
||||
: myStructureManager (theMgr),
|
||||
: myBgColor (Quantity_NOC_BLACK),
|
||||
myStructureManager (theMgr),
|
||||
myCamera (new Graphic3d_Camera()),
|
||||
myHiddenObjects (new Graphic3d_NMapOfTransient()),
|
||||
myIsInComputedMode (Standard_False),
|
||||
myIsActive (Standard_False),
|
||||
|
@@ -87,6 +87,12 @@ public:
|
||||
//! Returns true if the view was removed.
|
||||
Standard_Boolean IsRemoved() const { return myIsRemoved; }
|
||||
|
||||
//! Returns camera object of the view.
|
||||
virtual const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
|
||||
|
||||
//! Sets camera used by the view.
|
||||
virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
|
||||
|
||||
public:
|
||||
|
||||
//! Returns default Shading Model of the view; Graphic3d_TOSM_FRAGMENT by default.
|
||||
@@ -252,20 +258,6 @@ public:
|
||||
//! Returns True if the window associated to the view is defined.
|
||||
virtual Standard_Boolean IsDefined() const = 0;
|
||||
|
||||
//! Returns data of a graduated trihedron
|
||||
virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() = 0;
|
||||
|
||||
//! Displays Graduated Trihedron.
|
||||
virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) = 0;
|
||||
|
||||
//! Erases Graduated Trihedron.
|
||||
virtual void GraduatedTrihedronErase() = 0;
|
||||
|
||||
//! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
|
||||
//! @param theMin [in] the minimum point of scene.
|
||||
//! @param theMax [in] the maximum point of scene.
|
||||
virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) = 0;
|
||||
|
||||
//! Dump active rendering buffer into specified memory buffer.
|
||||
virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
|
||||
|
||||
@@ -352,10 +344,10 @@ public:
|
||||
Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; }
|
||||
|
||||
//! Returns background fill color.
|
||||
virtual Aspect_Background Background() const = 0;
|
||||
virtual Aspect_Background Background() const { return Aspect_Background (myBgColor.GetRGB()); }
|
||||
|
||||
//! Sets background fill color.
|
||||
virtual void SetBackground (const Aspect_Background& theBackground) = 0;
|
||||
virtual void SetBackground (const Aspect_Background& theBackground) { myBgColor.SetRGB (theBackground.Color()); }
|
||||
|
||||
//! Returns gradient background fill colors.
|
||||
virtual Aspect_GradientBackground GradientBackground() const = 0;
|
||||
@@ -387,12 +379,6 @@ public:
|
||||
//! Sets backfacing model for the view.
|
||||
virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) = 0;
|
||||
|
||||
//! Returns camera object of the view.
|
||||
virtual const Handle(Graphic3d_Camera)& Camera() const = 0;
|
||||
|
||||
//! Sets camera used by the view.
|
||||
virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) = 0;
|
||||
|
||||
//! Returns list of lights of the view.
|
||||
virtual const Handle(Graphic3d_LightSet)& Lights() const = 0;
|
||||
|
||||
@@ -421,6 +407,26 @@ public:
|
||||
//! Fills in the dictionary with statistic performance info.
|
||||
virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const = 0;
|
||||
|
||||
public: //! @name obsolete Graduated Trihedron functionality
|
||||
|
||||
//! Returns data of a graduated trihedron
|
||||
virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() { return myGTrihedronData; }
|
||||
|
||||
//! Displays Graduated Trihedron.
|
||||
virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) { (void )theTrihedronData; }
|
||||
|
||||
//! Erases Graduated Trihedron.
|
||||
virtual void GraduatedTrihedronErase() {}
|
||||
|
||||
//! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
|
||||
//! @param theMin [in] the minimum point of scene.
|
||||
//! @param theMax [in] the maximum point of scene.
|
||||
virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
|
||||
{
|
||||
(void )theMin;
|
||||
(void )theMax;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//! Adds the structure to display lists of the view.
|
||||
@@ -448,7 +454,9 @@ protected:
|
||||
|
||||
Standard_Integer myId;
|
||||
Graphic3d_RenderingParams myRenderParams;
|
||||
Quantity_ColorRGBA myBgColor;
|
||||
Handle(Graphic3d_StructureManager) myStructureManager;
|
||||
Handle(Graphic3d_Camera) myCamera;
|
||||
Graphic3d_SequenceOfStructure myStructsToCompute;
|
||||
Graphic3d_SequenceOfStructure myStructsComputed;
|
||||
Graphic3d_MapOfStructure myStructsDisplayed;
|
||||
@@ -459,6 +467,10 @@ protected:
|
||||
Graphic3d_TypeOfShadingModel myShadingModel;
|
||||
Graphic3d_TypeOfVisualization myVisualization;
|
||||
|
||||
protected:
|
||||
|
||||
Graphic3d_GraduatedTrihedron myGTrihedronData;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Graphic3d_CView_HeaderFile
|
||||
|
@@ -87,6 +87,7 @@ Graphic3d_Camera::Graphic3d_Camera()
|
||||
myZNear (DEFAULT_ZNEAR),
|
||||
myZFar (DEFAULT_ZFAR),
|
||||
myAspect (1.0),
|
||||
myIsZeroToOneDepth (false),
|
||||
myScale (1000.0),
|
||||
myZFocus (1.0),
|
||||
myZFocusType (FocusType_Relative),
|
||||
@@ -979,7 +980,7 @@ void Graphic3d_Camera::OrthoProj (const Elem_t theLeft,
|
||||
const Elem_t theTop,
|
||||
const Elem_t theNear,
|
||||
const Elem_t theFar,
|
||||
NCollection_Mat4<Elem_t>& theOutMx)
|
||||
NCollection_Mat4<Elem_t>& theOutMx) const
|
||||
{
|
||||
// row 0
|
||||
theOutMx.ChangeValue (0, 0) = Elem_t (2.0) / (theRight - theLeft);
|
||||
@@ -996,8 +997,16 @@ void Graphic3d_Camera::OrthoProj (const Elem_t theLeft,
|
||||
// row 2
|
||||
theOutMx.ChangeValue (2, 0) = Elem_t (0.0);
|
||||
theOutMx.ChangeValue (2, 1) = Elem_t (0.0);
|
||||
theOutMx.ChangeValue (2, 2) = Elem_t (-2.0) / (theFar - theNear);
|
||||
theOutMx.ChangeValue (2, 3) = - (theFar + theNear) / (theFar - theNear);
|
||||
if (myIsZeroToOneDepth)
|
||||
{
|
||||
theOutMx.ChangeValue (2, 2) = Elem_t (-1.0) / (theFar - theNear);
|
||||
theOutMx.ChangeValue (2, 3) = -theNear / (theFar - theNear);
|
||||
}
|
||||
else
|
||||
{
|
||||
theOutMx.ChangeValue (2, 2) = Elem_t (-2.0) / (theFar - theNear);
|
||||
theOutMx.ChangeValue (2, 3) = - (theFar + theNear) / (theFar - theNear);
|
||||
}
|
||||
|
||||
// row 3
|
||||
theOutMx.ChangeValue (3, 0) = Elem_t (0.0);
|
||||
@@ -1017,7 +1026,7 @@ void Graphic3d_Camera::PerspectiveProj (const Elem_t theLeft,
|
||||
const Elem_t theTop,
|
||||
const Elem_t theNear,
|
||||
const Elem_t theFar,
|
||||
NCollection_Mat4<Elem_t>& theOutMx)
|
||||
NCollection_Mat4<Elem_t>& theOutMx) const
|
||||
{
|
||||
// column 0
|
||||
theOutMx.ChangeValue (0, 0) = (Elem_t (2.0) * theNear) / (theRight - theLeft);
|
||||
@@ -1034,13 +1043,27 @@ void Graphic3d_Camera::PerspectiveProj (const Elem_t theLeft,
|
||||
// column 2
|
||||
theOutMx.ChangeValue (0, 2) = (theRight + theLeft) / (theRight - theLeft);
|
||||
theOutMx.ChangeValue (1, 2) = (theTop + theBottom) / (theTop - theBottom);
|
||||
theOutMx.ChangeValue (2, 2) = -(theFar + theNear) / (theFar - theNear);
|
||||
if (myIsZeroToOneDepth)
|
||||
{
|
||||
theOutMx.ChangeValue (2, 2) = theFar / (theNear - theFar);
|
||||
}
|
||||
else
|
||||
{
|
||||
theOutMx.ChangeValue (2, 2) = -(theFar + theNear) / (theFar - theNear);
|
||||
}
|
||||
theOutMx.ChangeValue (3, 2) = Elem_t (-1.0);
|
||||
|
||||
// column 3
|
||||
theOutMx.ChangeValue (0, 3) = Elem_t (0.0);
|
||||
theOutMx.ChangeValue (1, 3) = Elem_t (0.0);
|
||||
theOutMx.ChangeValue (2, 3) = -(Elem_t (2.0) * theFar * theNear) / (theFar - theNear);
|
||||
if (myIsZeroToOneDepth)
|
||||
{
|
||||
theOutMx.ChangeValue (2, 3) = -(theFar * theNear) / (theFar - theNear);
|
||||
}
|
||||
else
|
||||
{
|
||||
theOutMx.ChangeValue (2, 3) = -(Elem_t (2.0) * theFar * theNear) / (theFar - theNear);
|
||||
}
|
||||
theOutMx.ChangeValue (3, 3) = Elem_t (0.0);
|
||||
}
|
||||
|
||||
@@ -1058,7 +1081,7 @@ void Graphic3d_Camera::StereoEyeProj (const Elem_t theLeft,
|
||||
const Elem_t theIOD,
|
||||
const Elem_t theZFocus,
|
||||
const Standard_Boolean theIsLeft,
|
||||
NCollection_Mat4<Elem_t>& theOutMx)
|
||||
NCollection_Mat4<Elem_t>& theOutMx) const
|
||||
{
|
||||
Elem_t aDx = theIsLeft ? Elem_t (0.5) * theIOD : Elem_t (-0.5) * theIOD;
|
||||
Elem_t aDXStereoShift = aDx * theNear / theZFocus;
|
||||
@@ -1405,12 +1428,10 @@ void Graphic3d_Camera::FrustumPoints (NCollection_Array1<Graphic3d_Vec3d>& thePo
|
||||
|
||||
Standard_Real nLeft = 0.0, nRight = 0.0, nTop = 0.0, nBottom = 0.0;
|
||||
Standard_Real fLeft = 0.0, fRight = 0.0, fTop = 0.0, fBottom = 0.0;
|
||||
Standard_Real aNear = 0.0, aFar = 0.0;
|
||||
Standard_Real aNear = myZNear, aFar = myZFar;
|
||||
if (!IsOrthographic())
|
||||
{
|
||||
// handle perspective projection
|
||||
aNear = aProjectionMat.GetValue (2, 3) / (-1.0 + aProjectionMat.GetValue (2, 2));
|
||||
aFar = aProjectionMat.GetValue (2, 3) / ( 1.0 + aProjectionMat.GetValue (2, 2));
|
||||
// Near plane
|
||||
nLeft = aNear * (aProjectionMat.GetValue (0, 2) - 1.0) / aProjectionMat.GetValue (0, 0);
|
||||
nRight = aNear * (aProjectionMat.GetValue (0, 2) + 1.0) / aProjectionMat.GetValue (0, 0);
|
||||
@@ -1425,8 +1446,6 @@ void Graphic3d_Camera::FrustumPoints (NCollection_Array1<Graphic3d_Vec3d>& thePo
|
||||
else
|
||||
{
|
||||
// handle orthographic projection
|
||||
aNear = (1.0 / aProjectionMat.GetValue (2, 2)) * (aProjectionMat.GetValue (2, 3) + 1.0);
|
||||
aFar = (1.0 / aProjectionMat.GetValue (2, 2)) * (aProjectionMat.GetValue (2, 3) - 1.0);
|
||||
// Near plane
|
||||
nLeft = ( 1.0 + aProjectionMat.GetValue (0, 3)) / (-aProjectionMat.GetValue (0, 0));
|
||||
fLeft = nLeft;
|
||||
|
@@ -326,6 +326,20 @@ public:
|
||||
return myZFar;
|
||||
}
|
||||
|
||||
//! Return TRUE if camera should calculate projection matrix for [0, 1] depth range or for [-1, 1] range.
|
||||
//! FALSE by default.
|
||||
Standard_Boolean IsZeroToOneDepth() const { return myIsZeroToOneDepth; }
|
||||
|
||||
//! Set using [0, 1] depth range or [-1, 1] range.
|
||||
void SetZeroToOneDepth (Standard_Boolean theIsZeroToOne)
|
||||
{
|
||||
if (myIsZeroToOneDepth != theIsZeroToOne)
|
||||
{
|
||||
myIsZeroToOneDepth = theIsZeroToOne;
|
||||
InvalidateProjection();
|
||||
}
|
||||
}
|
||||
|
||||
//! Changes width / height display ratio.
|
||||
//! @param theAspect [in] the display ratio.
|
||||
Standard_EXPORT void SetAspect (const Standard_Real theAspect);
|
||||
@@ -562,14 +576,14 @@ private:
|
||||
//! @param theFar [in] the far mapping (clipping) coordinate.
|
||||
//! @param theOutMx [out] the projection matrix.
|
||||
template <typename Elem_t>
|
||||
static void
|
||||
void
|
||||
OrthoProj (const Elem_t theLeft,
|
||||
const Elem_t theRight,
|
||||
const Elem_t theBottom,
|
||||
const Elem_t theTop,
|
||||
const Elem_t theNear,
|
||||
const Elem_t theFar,
|
||||
NCollection_Mat4<Elem_t>& theOutMx);
|
||||
NCollection_Mat4<Elem_t>& theOutMx) const;
|
||||
|
||||
//! Compose perspective projection matrix for
|
||||
//! the passed camera volume mapping.
|
||||
@@ -581,14 +595,14 @@ private:
|
||||
//! @param theFar [in] the far mapping (clipping) coordinate.
|
||||
//! @param theOutMx [out] the projection matrix.
|
||||
template <typename Elem_t>
|
||||
static void
|
||||
void
|
||||
PerspectiveProj (const Elem_t theLeft,
|
||||
const Elem_t theRight,
|
||||
const Elem_t theBottom,
|
||||
const Elem_t theTop,
|
||||
const Elem_t theNear,
|
||||
const Elem_t theFar,
|
||||
NCollection_Mat4<Elem_t>& theOutMx);
|
||||
NCollection_Mat4<Elem_t>& theOutMx) const;
|
||||
|
||||
//! Compose projection matrix for L/R stereo eyes.
|
||||
//! @param theLeft [in] the left mapping (clipping) coordinate.
|
||||
@@ -603,7 +617,7 @@ private:
|
||||
//! @param theIsLeft [in] boolean flag to choose between L/R eyes.
|
||||
//! @param theOutMx [out] the projection matrix.
|
||||
template <typename Elem_t>
|
||||
static void
|
||||
void
|
||||
StereoEyeProj (const Elem_t theLeft,
|
||||
const Elem_t theRight,
|
||||
const Elem_t theBottom,
|
||||
@@ -613,7 +627,7 @@ private:
|
||||
const Elem_t theIOD,
|
||||
const Elem_t theZFocus,
|
||||
const Standard_Boolean theIsLeft,
|
||||
NCollection_Mat4<Elem_t>& theOutMx);
|
||||
NCollection_Mat4<Elem_t>& theOutMx) const;
|
||||
|
||||
//! Construct "look at" orientation transformation.
|
||||
//! Reference point differs for perspective and ortho modes
|
||||
@@ -666,6 +680,7 @@ private:
|
||||
Standard_Real myZNear; //!< Distance to near clipping plane.
|
||||
Standard_Real myZFar; //!< Distance to far clipping plane.
|
||||
Standard_Real myAspect; //!< Width to height display ratio.
|
||||
Standard_Boolean myIsZeroToOneDepth; //!< use [0, 1] depth range or [-1, 1]
|
||||
|
||||
Standard_Real myScale; //!< Specifies parallel scale for orthographic projection.
|
||||
Standard_Real myZFocus; //!< Stereographic focus value.
|
||||
|
@@ -13,17 +13,17 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Graphic3d_CullingTool.hxx>
|
||||
|
||||
#include <Precision.hxx>
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <OpenGl_BVHTreeSelector.hxx>
|
||||
#include <OpenGl_BVHClipPrimitiveSet.hxx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_BVHTreeSelector
|
||||
// function : Graphic3d_CullingTool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OpenGl_BVHTreeSelector::OpenGl_BVHTreeSelector()
|
||||
Graphic3d_CullingTool::Graphic3d_CullingTool()
|
||||
: myClipVerts (0, Graphic3d_Camera::FrustumVerticesNB),
|
||||
myIsProjectionParallel (Standard_True),
|
||||
myCamScale (1.0),
|
||||
@@ -36,7 +36,7 @@ OpenGl_BVHTreeSelector::OpenGl_BVHTreeSelector()
|
||||
// function : SetViewVolume
|
||||
// purpose : Retrieves view volume's planes equations and its vertices from projection and world-view matrices.
|
||||
// =======================================================================
|
||||
void OpenGl_BVHTreeSelector::SetViewVolume (const Handle(Graphic3d_Camera)& theCamera)
|
||||
void Graphic3d_CullingTool::SetViewVolume (const Handle(Graphic3d_Camera)& theCamera)
|
||||
{
|
||||
if (!myWorldViewProjState.IsChanged (theCamera->WorldViewProjState()))
|
||||
return;
|
||||
@@ -70,7 +70,7 @@ void OpenGl_BVHTreeSelector::SetViewVolume (const Handle(Graphic3d_Camera)& theC
|
||||
{
|
||||
for (Standard_Integer i = 0; i < 2; ++i)
|
||||
{
|
||||
OpenGl_Vec3d aPlanePnts[3];
|
||||
Graphic3d_Vec3d aPlanePnts[3];
|
||||
for (Standard_Integer aPntIter = 0; aPntIter < 3; ++aPntIter)
|
||||
{
|
||||
aShifts[aFaceIdx] = i;
|
||||
@@ -82,8 +82,8 @@ void OpenGl_BVHTreeSelector::SetViewVolume (const Handle(Graphic3d_Camera)& theC
|
||||
|
||||
myClipPlanes[aFaceIdx * 2 + i].Origin = aPlanePnts[0];
|
||||
myClipPlanes[aFaceIdx * 2 + i].Normal =
|
||||
OpenGl_Vec3d::Cross (aPlanePnts[1] - aPlanePnts[0],
|
||||
aPlanePnts[2] - aPlanePnts[0]).Normalized() * (i == 0 ? -1.f : 1.f);
|
||||
Graphic3d_Vec3d::Cross (aPlanePnts[1] - aPlanePnts[0],
|
||||
aPlanePnts[2] - aPlanePnts[0]).Normalized() * (i == 0 ? -1.f : 1.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,9 +92,9 @@ void OpenGl_BVHTreeSelector::SetViewVolume (const Handle(Graphic3d_Camera)& theC
|
||||
// function : SetViewportSize
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHTreeSelector::SetViewportSize (Standard_Integer theViewportWidth,
|
||||
Standard_Integer theViewportHeight,
|
||||
Standard_Real theResolutionRatio)
|
||||
void Graphic3d_CullingTool::SetViewportSize (Standard_Integer theViewportWidth,
|
||||
Standard_Integer theViewportHeight,
|
||||
Standard_Real theResolutionRatio)
|
||||
{
|
||||
myViewportHeight = theViewportHeight > 0 ? theViewportHeight : 1;
|
||||
myViewportWidth = theViewportWidth > 0 ? theViewportWidth : 1;
|
||||
@@ -106,8 +106,8 @@ void OpenGl_BVHTreeSelector::SetViewportSize (Standard_Integer theViewportWidth,
|
||||
// function : SignedPlanePointDistance
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Real OpenGl_BVHTreeSelector::SignedPlanePointDistance (const OpenGl_Vec4d& theNormal,
|
||||
const OpenGl_Vec4d& thePnt)
|
||||
Standard_Real Graphic3d_CullingTool::SignedPlanePointDistance (const Graphic3d_Vec4d& theNormal,
|
||||
const Graphic3d_Vec4d& thePnt)
|
||||
{
|
||||
const Standard_Real aNormLength = std::sqrt (theNormal.x() * theNormal.x()
|
||||
+ theNormal.y() * theNormal.y()
|
||||
@@ -128,8 +128,8 @@ Standard_Real OpenGl_BVHTreeSelector::SignedPlanePointDistance (const OpenGl_Vec
|
||||
// function : SetCullingDistance
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHTreeSelector::SetCullingDistance (CullingContext& theCtx,
|
||||
Standard_Real theDistance) const
|
||||
void Graphic3d_CullingTool::SetCullingDistance (CullingContext& theCtx,
|
||||
Standard_Real theDistance) const
|
||||
{
|
||||
theCtx.DistCull = -1.0;
|
||||
if (!myIsProjectionParallel)
|
||||
@@ -144,8 +144,8 @@ void OpenGl_BVHTreeSelector::SetCullingDistance (CullingContext& theCtx,
|
||||
// function : SetCullingSize
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHTreeSelector::SetCullingSize (CullingContext& theCtx,
|
||||
Standard_Real theSize) const
|
||||
void Graphic3d_CullingTool::SetCullingSize (CullingContext& theCtx,
|
||||
Standard_Real theSize) const
|
||||
{
|
||||
theCtx.SizeCull2 = -1.0;
|
||||
if (theSize > 0.0 && !Precision::IsInfinite (theSize))
|
||||
@@ -160,7 +160,7 @@ void OpenGl_BVHTreeSelector::SetCullingSize (CullingContext& theCtx,
|
||||
// function : CacheClipPtsProjections
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_BVHTreeSelector::CacheClipPtsProjections()
|
||||
void Graphic3d_CullingTool::CacheClipPtsProjections()
|
||||
{
|
||||
// project frustum onto its own normals
|
||||
const Standard_Integer anIncFactor = myIsProjectionParallel ? 2 : 1;
|
||||
@@ -179,9 +179,9 @@ void OpenGl_BVHTreeSelector::CacheClipPtsProjections()
|
||||
}
|
||||
|
||||
// project frustum onto main axes
|
||||
OpenGl_Vec3d anAxes[] = { OpenGl_Vec3d (1.0, 0.0, 0.0),
|
||||
OpenGl_Vec3d (0.0, 1.0, 0.0),
|
||||
OpenGl_Vec3d (0.0, 0.0, 1.0) };
|
||||
Graphic3d_Vec3d anAxes[] = { Graphic3d_Vec3d (1.0, 0.0, 0.0),
|
||||
Graphic3d_Vec3d (0.0, 1.0, 0.0),
|
||||
Graphic3d_Vec3d (0.0, 0.0, 1.0) };
|
||||
for (Standard_Integer aDim = 0; aDim < 3; ++aDim)
|
||||
{
|
||||
Standard_Real aMaxProj = -std::numeric_limits<Standard_Real>::max();
|
@@ -13,17 +13,16 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _OpenGl_BVHTreeSelector_HeaderFile
|
||||
#define _OpenGl_BVHTreeSelector_HeaderFile
|
||||
#ifndef _Graphic3d_CullingTool_HeaderFile
|
||||
#define _Graphic3d_CullingTool_HeaderFile
|
||||
|
||||
#include <Graphic3d_Camera.hxx>
|
||||
#include <Graphic3d_Vec4.hxx>
|
||||
#include <Graphic3d_WorldViewProjState.hxx>
|
||||
#include <OpenGl_Vec.hxx>
|
||||
|
||||
//! BVHTreeSelector class provides a possibility to store parameters of view volume,
|
||||
//! such as its vertices and equations, and contains methods detecting if given AABB overlaps
|
||||
//! view volume.
|
||||
class OpenGl_BVHTreeSelector
|
||||
//! Graphic3d_CullingTool class provides a possibility to store parameters of view volume,
|
||||
//! such as its vertices and equations, and contains methods detecting if given AABB overlaps view volume.
|
||||
class Graphic3d_CullingTool
|
||||
{
|
||||
public:
|
||||
//! Auxiliary structure holding non-persistent culling options.
|
||||
@@ -45,19 +44,19 @@ public:
|
||||
Normal (0.0, 0.0, 1.0) {}
|
||||
|
||||
//! Creates plane with specific parameters.
|
||||
Plane (const OpenGl_Vec3d& theOrigin,
|
||||
const OpenGl_Vec3d& theNormal)
|
||||
Plane (const Graphic3d_Vec3d& theOrigin,
|
||||
const Graphic3d_Vec3d& theNormal)
|
||||
: Origin (theOrigin),
|
||||
Normal (theNormal) {}
|
||||
|
||||
OpenGl_Vec3d Origin;
|
||||
OpenGl_Vec3d Normal;
|
||||
Graphic3d_Vec3d Origin;
|
||||
Graphic3d_Vec3d Normal;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
//! Creates an empty selector object with parallel projection type by default.
|
||||
Standard_EXPORT OpenGl_BVHTreeSelector();
|
||||
Standard_EXPORT Graphic3d_CullingTool();
|
||||
|
||||
//! Retrieves view volume's planes equations and its vertices from projection and world-view matrices.
|
||||
Standard_EXPORT void SetViewVolume (const Handle(Graphic3d_Camera)& theCamera);
|
||||
@@ -84,8 +83,8 @@ public:
|
||||
//! @param theMaxPt [in] minimum point of AABB
|
||||
//! @return Standard_True, if AABB is in viewing area, Standard_False otherwise
|
||||
bool IsCulled (const CullingContext& theCtx,
|
||||
const OpenGl_Vec3d& theMinPt,
|
||||
const OpenGl_Vec3d& theMaxPt) const
|
||||
const Graphic3d_Vec3d& theMinPt,
|
||||
const Graphic3d_Vec3d& theMaxPt) const
|
||||
{
|
||||
return isFullOut (theMinPt, theMaxPt)
|
||||
|| isTooDistant(theCtx, theMinPt, theMaxPt)
|
||||
@@ -96,13 +95,13 @@ public:
|
||||
const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
|
||||
|
||||
//! Returns current projection matrix.
|
||||
const OpenGl_Mat4d& ProjectionMatrix() const
|
||||
const Graphic3d_Mat4d& ProjectionMatrix() const
|
||||
{
|
||||
return myProjectionMat;
|
||||
}
|
||||
|
||||
//! Returns current world view transformation matrix.
|
||||
const OpenGl_Mat4d& WorldViewMatrix() const
|
||||
const Graphic3d_Mat4d& WorldViewMatrix() const
|
||||
{
|
||||
return myWorldViewMat;
|
||||
}
|
||||
@@ -128,15 +127,15 @@ protected:
|
||||
//! Calculates signed distance from plane to point.
|
||||
//! @param theNormal [in] the plane's normal.
|
||||
//! @param thePnt [in]
|
||||
Standard_EXPORT Standard_Real SignedPlanePointDistance (const OpenGl_Vec4d& theNormal,
|
||||
const OpenGl_Vec4d& thePnt);
|
||||
Standard_EXPORT Standard_Real SignedPlanePointDistance (const Graphic3d_Vec4d& theNormal,
|
||||
const Graphic3d_Vec4d& thePnt);
|
||||
|
||||
//! Detects if AABB overlaps view volume using separating axis theorem (SAT).
|
||||
//! @param theMinPt [in] maximum point of AABB.
|
||||
//! @param theMaxPt [in] minimum point of AABB.
|
||||
//! @return FALSE, if AABB is in viewing area, TRUE otherwise.
|
||||
bool isFullOut (const OpenGl_Vec3d& theMinPt,
|
||||
const OpenGl_Vec3d& theMaxPt) const
|
||||
bool isFullOut (const Graphic3d_Vec3d& theMinPt,
|
||||
const Graphic3d_Vec3d& theMaxPt) const
|
||||
{
|
||||
// E1
|
||||
// |_ E0
|
||||
@@ -168,11 +167,11 @@ protected:
|
||||
for (Standard_Integer aPlaneIter = 0; aPlaneIter < PlanesNB - 1; aPlaneIter += anIncFactor)
|
||||
{
|
||||
// frustum normals
|
||||
const OpenGl_Vec3d anAxis = myClipPlanes[aPlaneIter].Normal;
|
||||
const Graphic3d_Vec3d anAxis = myClipPlanes[aPlaneIter].Normal;
|
||||
|
||||
const OpenGl_Vec3d aPVertex (anAxis.x() > 0.0 ? theMaxPt.x() : theMinPt.x(),
|
||||
anAxis.y() > 0.0 ? theMaxPt.y() : theMinPt.y(),
|
||||
anAxis.z() > 0.0 ? theMaxPt.z() : theMinPt.z());
|
||||
const Graphic3d_Vec3d aPVertex (anAxis.x() > 0.0 ? theMaxPt.x() : theMinPt.x(),
|
||||
anAxis.y() > 0.0 ? theMaxPt.y() : theMinPt.y(),
|
||||
anAxis.z() > 0.0 ? theMaxPt.z() : theMinPt.z());
|
||||
Standard_Real aPnt0 = aPVertex.Dot (anAxis);
|
||||
|
||||
if (aPnt0 >= myMinClipProjectionPts[aPlaneIter]
|
||||
@@ -181,9 +180,9 @@ protected:
|
||||
continue;
|
||||
}
|
||||
|
||||
const OpenGl_Vec3d aNVertex (anAxis.x() > 0.0 ? theMinPt.x() : theMaxPt.x(),
|
||||
anAxis.y() > 0.0 ? theMinPt.y() : theMaxPt.y(),
|
||||
anAxis.z() > 0.0 ? theMinPt.z() : theMaxPt.z());
|
||||
const Graphic3d_Vec3d aNVertex (anAxis.x() > 0.0 ? theMinPt.x() : theMaxPt.x(),
|
||||
anAxis.y() > 0.0 ? theMinPt.y() : theMaxPt.y(),
|
||||
anAxis.z() > 0.0 ? theMinPt.z() : theMaxPt.z());
|
||||
Standard_Real aPnt1 = aNVertex.Dot (anAxis);
|
||||
|
||||
const Standard_Real aMin = aPnt0 < aPnt1 ? aPnt0 : aPnt1;
|
||||
@@ -200,8 +199,8 @@ protected:
|
||||
|
||||
//! Returns TRUE if given AABB should be discarded by distance culling criterion.
|
||||
bool isTooDistant (const CullingContext& theCtx,
|
||||
const OpenGl_Vec3d& theMinPt,
|
||||
const OpenGl_Vec3d& theMaxPt) const
|
||||
const Graphic3d_Vec3d& theMinPt,
|
||||
const Graphic3d_Vec3d& theMaxPt) const
|
||||
{
|
||||
if (theCtx.DistCull <= 0.0)
|
||||
{
|
||||
@@ -216,8 +215,8 @@ protected:
|
||||
|
||||
//! Returns TRUE if given AABB should be discarded by size culling criterion.
|
||||
bool isTooSmall (const CullingContext& theCtx,
|
||||
const OpenGl_Vec3d& theMinPt,
|
||||
const OpenGl_Vec3d& theMaxPt) const
|
||||
const Graphic3d_Vec3d& theMinPt,
|
||||
const Graphic3d_Vec3d& theMaxPt) const
|
||||
{
|
||||
if (theCtx.SizeCull2 <= 0.0)
|
||||
{
|
||||
@@ -232,8 +231,8 @@ protected:
|
||||
|
||||
// note that distances behind the Eye (aBndDist < 0) are not scaled correctly here,
|
||||
// but majority of such objects should be culled by frustum
|
||||
const OpenGl_Vec3d aBndCenter = (theMinPt + theMaxPt) * 0.5;
|
||||
const Standard_Real aBndDist = (aBndCenter - myCamEye).Dot (myCamDir);
|
||||
const Graphic3d_Vec3d aBndCenter = (theMinPt + theMaxPt) * 0.5;
|
||||
const Standard_Real aBndDist = (aBndCenter - myCamEye).Dot (myCamDir);
|
||||
return aBoxDiag2 < theCtx.SizeCull2 * aBndDist * aBndDist;
|
||||
}
|
||||
|
||||
@@ -253,8 +252,8 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
Plane myClipPlanes[PlanesNB]; //!< Planes
|
||||
NCollection_Array1<OpenGl_Vec3d> myClipVerts; //!< Vertices
|
||||
Plane myClipPlanes[PlanesNB]; //!< Planes
|
||||
NCollection_Array1<Graphic3d_Vec3d> myClipVerts; //!< Vertices
|
||||
|
||||
Handle(Graphic3d_Camera) myCamera; //!< camera definition
|
||||
|
||||
@@ -270,8 +269,8 @@ protected:
|
||||
|
||||
Standard_Boolean myIsProjectionParallel;
|
||||
|
||||
OpenGl_Mat4d myProjectionMat;
|
||||
OpenGl_Mat4d myWorldViewMat;
|
||||
Graphic3d_Mat4d myProjectionMat;
|
||||
Graphic3d_Mat4d myWorldViewMat;
|
||||
|
||||
Standard_Integer myViewportWidth;
|
||||
Standard_Integer myViewportHeight;
|
||||
@@ -285,4 +284,4 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
#endif // _OpenGl_BVHTreeSelector_HeaderFile
|
||||
#endif // _Graphic3d_CullingTool_HeaderFile
|
@@ -25,7 +25,71 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient)
|
||||
Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp)
|
||||
: myDisplayConnection (theDisp)
|
||||
{
|
||||
//
|
||||
// default layers are always presented in display layer sequence it can not be removed
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_False);
|
||||
aSettings.SetEnvironmentTexture (Standard_False);
|
||||
aSettings.SetEnableDepthTest (Standard_False);
|
||||
aSettings.SetEnableDepthWrite (Standard_False);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_BotOSD);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_BotOSD);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_False);
|
||||
aSettings.SetEnvironmentTexture (Standard_True);
|
||||
aSettings.SetEnableDepthTest (Standard_True);
|
||||
aSettings.SetEnableDepthWrite (Standard_True);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_Default);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_Default);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_True);
|
||||
aSettings.SetEnvironmentTexture (Standard_True);
|
||||
aSettings.SetEnableDepthTest (Standard_True);
|
||||
aSettings.SetEnableDepthWrite (Standard_True);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_Top);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_Top);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_True);
|
||||
aSettings.SetEnvironmentTexture (Standard_True);
|
||||
aSettings.SetEnableDepthTest (Standard_True);
|
||||
aSettings.SetEnableDepthWrite (Standard_True);
|
||||
aSettings.SetClearDepth (Standard_True);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_Topmost);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_Topmost);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_True);
|
||||
aSettings.SetEnvironmentTexture (Standard_False);
|
||||
aSettings.SetEnableDepthTest (Standard_False);
|
||||
aSettings.SetEnableDepthWrite (Standard_False);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_TopOSD);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_TopOSD);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, aSettings);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -53,4 +117,83 @@ Standard_Integer Graphic3d_GraphicDriver::NewIdentification()
|
||||
void Graphic3d_GraphicDriver::RemoveIdentification(const Standard_Integer theId)
|
||||
{
|
||||
myStructGenId.Free(theId);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ZLayerSettings
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
const Graphic3d_ZLayerSettings& Graphic3d_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
|
||||
{
|
||||
Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId), "Graphic3d_GraphicDriver::ZLayerSettings, Layer with theLayerId does not exist");
|
||||
return myMapOfZLayerSettings.Find (theLayerId);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : addZLayerIndex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Graphic3d_GraphicDriver::addZLayerIndex (const Graphic3d_ZLayerId theLayerId)
|
||||
{
|
||||
// remove index
|
||||
for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
|
||||
{
|
||||
if (aLayerIt.Value() == theLayerId)
|
||||
{
|
||||
myLayerSeq.Remove (aLayerIt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (myMapOfZLayerSettings.Find (theLayerId).IsImmediate())
|
||||
{
|
||||
myLayerSeq.Append (theLayerId);
|
||||
return;
|
||||
}
|
||||
|
||||
for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
|
||||
{
|
||||
const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerIt.Value());
|
||||
if (aSettings.IsImmediate())
|
||||
{
|
||||
aLayerIt.Previous();
|
||||
if (aLayerIt.More())
|
||||
{
|
||||
myLayerSeq.InsertAfter (aLayerIt, theLayerId);
|
||||
return;
|
||||
}
|
||||
|
||||
// first non-immediate layer
|
||||
myLayerSeq.Prepend (theLayerId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// no immediate layers
|
||||
myLayerSeq.Append (theLayerId);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetZLayerSettings
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Graphic3d_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
|
||||
const Graphic3d_ZLayerSettings& theSettings)
|
||||
{
|
||||
Graphic3d_ZLayerSettings* aSettings = myMapOfZLayerSettings.ChangeSeek (theLayerId);
|
||||
if (aSettings != NULL)
|
||||
{
|
||||
const bool isChanged = (aSettings->IsImmediate() != theSettings.IsImmediate());
|
||||
*aSettings = theSettings;
|
||||
if (isChanged)
|
||||
{
|
||||
addZLayerIndex (theLayerId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// abnormal case
|
||||
myMapOfZLayerSettings.Bind (theLayerId, theSettings);
|
||||
addZLayerIndex (theLayerId);
|
||||
}
|
||||
}
|
||||
|
@@ -42,9 +42,11 @@
|
||||
#include <Aspect_Handle.hxx>
|
||||
#include <Graphic3d_ZLayerId.hxx>
|
||||
#include <Graphic3d_ZLayerSettings.hxx>
|
||||
#include <Graphic3d_MapOfZLayerSettings.hxx>
|
||||
#include <Graphic3d_CLight.hxx>
|
||||
#include <Graphic3d_TypeOfLimit.hxx>
|
||||
#include <TColStd_Array2OfReal.hxx>
|
||||
#include <TColStd_MapOfInteger.hxx>
|
||||
#include <TColStd_SequenceOfInteger.hxx>
|
||||
|
||||
class Aspect_DisplayConnection;
|
||||
@@ -122,13 +124,16 @@ public:
|
||||
virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
|
||||
|
||||
//! Returns list of Z layers defined for the graphical driver.
|
||||
virtual void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const = 0;
|
||||
virtual void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
|
||||
{
|
||||
theLayerSeq.Assign (myLayerSeq);
|
||||
}
|
||||
|
||||
//! Sets the settings for a single Z layer.
|
||||
virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0;
|
||||
Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0;
|
||||
|
||||
//! Returns the settings of a single Z layer.
|
||||
virtual const Graphic3d_ZLayerSettings& ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const = 0;
|
||||
Standard_EXPORT virtual const Graphic3d_ZLayerSettings& ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const;
|
||||
|
||||
//! Returns view associated with the window if it is exists and is activated.
|
||||
//! Returns Standard_True if the view associated to the window exists.
|
||||
@@ -150,10 +155,16 @@ protected:
|
||||
//! Initializes the Driver
|
||||
Standard_EXPORT Graphic3d_GraphicDriver(const Handle(Aspect_DisplayConnection)& theDisp);
|
||||
|
||||
//! Insert index layer at proper position.
|
||||
Standard_EXPORT void addZLayerIndex (const Graphic3d_ZLayerId theLayerId);
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Aspect_DisplayConnection) myDisplayConnection;
|
||||
Aspect_GenId myStructGenId;
|
||||
TColStd_MapOfInteger myLayerIds;
|
||||
TColStd_SequenceOfInteger myLayerSeq;
|
||||
Graphic3d_MapOfZLayerSettings myMapOfZLayerSettings;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -1,6 +1,4 @@
|
||||
// Created on: 2014-03-31
|
||||
// Created by: Danila ULYANOV
|
||||
// Copyright (c) 2014 OPEN CASCADE SAS
|
||||
// Copyright (c) 2011-2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
@@ -13,23 +11,19 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <OpenGl_Layer.hxx>
|
||||
#include <Graphic3d_Layer.hxx>
|
||||
|
||||
#include <OpenGl_BVHTreeSelector.hxx>
|
||||
#include <OpenGl_Structure.hxx>
|
||||
#include <OpenGl_ShaderManager.hxx>
|
||||
#include <OpenGl_View.hxx>
|
||||
#include <OpenGl_Workspace.hxx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
#include <Graphic3d_CStructure.hxx>
|
||||
#include <Graphic3d_CullingTool.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Layer, Standard_Transient)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Layer, Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_Layer
|
||||
// function : Graphic3d_Layer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OpenGl_Layer::OpenGl_Layer (const Standard_Integer theNbPriorities,
|
||||
const Handle(Select3D_BVHBuilder3d)& theBuilder)
|
||||
Graphic3d_Layer::Graphic3d_Layer (Standard_Integer theNbPriorities,
|
||||
const Handle(Select3D_BVHBuilder3d)& theBuilder)
|
||||
: myArray (0, theNbPriorities - 1),
|
||||
myNbStructures (0),
|
||||
myNbStructuresNotCulled (0),
|
||||
@@ -41,10 +35,10 @@ OpenGl_Layer::OpenGl_Layer (const Standard_Integer theNbPriorities,
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~OpenGl_Layer
|
||||
// function : ~Graphic3d_Layer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OpenGl_Layer::~OpenGl_Layer()
|
||||
Graphic3d_Layer::~Graphic3d_Layer()
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -53,9 +47,9 @@ OpenGl_Layer::~OpenGl_Layer()
|
||||
// function : Add
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_Layer::Add (const OpenGl_Structure* theStruct,
|
||||
const Standard_Integer thePriority,
|
||||
Standard_Boolean isForChangePriority)
|
||||
void Graphic3d_Layer::Add (const Graphic3d_CStructure* theStruct,
|
||||
Standard_Integer thePriority,
|
||||
Standard_Boolean isForChangePriority)
|
||||
{
|
||||
const Standard_Integer anIndex = Min (Max (thePriority, 0), myArray.Length() - 1);
|
||||
if (theStruct == NULL)
|
||||
@@ -90,9 +84,9 @@ void OpenGl_Layer::Add (const OpenGl_Structure* theStruct,
|
||||
// function : Remove
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool OpenGl_Layer::Remove (const OpenGl_Structure* theStruct,
|
||||
Standard_Integer& thePriority,
|
||||
Standard_Boolean isForChangePriority)
|
||||
bool Graphic3d_Layer::Remove (const Graphic3d_CStructure* theStruct,
|
||||
Standard_Integer& thePriority,
|
||||
Standard_Boolean isForChangePriority)
|
||||
{
|
||||
if (theStruct == NULL)
|
||||
{
|
||||
@@ -103,41 +97,42 @@ bool OpenGl_Layer::Remove (const OpenGl_Structure* theStruct,
|
||||
const Standard_Integer aNbPriorities = myArray.Length();
|
||||
for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
|
||||
{
|
||||
OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
|
||||
|
||||
Graphic3d_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
|
||||
const Standard_Integer anIndex = aStructures.FindIndex (theStruct);
|
||||
if (anIndex != 0)
|
||||
if (anIndex == 0)
|
||||
{
|
||||
aStructures.Swap (anIndex, aStructures.Size());
|
||||
aStructures.RemoveLast();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isForChangePriority)
|
||||
aStructures.Swap (anIndex, aStructures.Size());
|
||||
aStructures.RemoveLast();
|
||||
|
||||
if (!isForChangePriority)
|
||||
{
|
||||
Standard_Boolean isAlwaysRend = theStruct->IsAlwaysRendered();
|
||||
if (!isAlwaysRend)
|
||||
{
|
||||
Standard_Boolean isAlwaysRend = theStruct->IsAlwaysRendered();
|
||||
if (!isAlwaysRend)
|
||||
if (!myBVHPrimitives.Remove (theStruct))
|
||||
{
|
||||
if (!myBVHPrimitives.Remove (theStruct))
|
||||
if (!myBVHPrimitivesTrsfPers.Remove (theStruct))
|
||||
{
|
||||
if (!myBVHPrimitivesTrsfPers.Remove (theStruct))
|
||||
{
|
||||
isAlwaysRend = Standard_True;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isAlwaysRend)
|
||||
{
|
||||
const Standard_Integer anIndex2 = myAlwaysRenderedMap.FindIndex (theStruct);
|
||||
if (anIndex2 != 0)
|
||||
{
|
||||
myAlwaysRenderedMap.Swap (myAlwaysRenderedMap.Size(), anIndex2);
|
||||
myAlwaysRenderedMap.RemoveLast();
|
||||
isAlwaysRend = Standard_True;
|
||||
}
|
||||
}
|
||||
}
|
||||
--myNbStructures;
|
||||
thePriority = aPriorityIter;
|
||||
return true;
|
||||
if (isAlwaysRend)
|
||||
{
|
||||
const Standard_Integer anIndex2 = myAlwaysRenderedMap.FindIndex (theStruct);
|
||||
if (anIndex2 != 0)
|
||||
{
|
||||
myAlwaysRenderedMap.Swap (myAlwaysRenderedMap.Size(), anIndex2);
|
||||
myAlwaysRenderedMap.RemoveLast();
|
||||
}
|
||||
}
|
||||
}
|
||||
--myNbStructures;
|
||||
thePriority = aPriorityIter;
|
||||
return true;
|
||||
}
|
||||
|
||||
thePriority = -1;
|
||||
@@ -148,7 +143,7 @@ bool OpenGl_Layer::Remove (const OpenGl_Structure* theStruct,
|
||||
// function : InvalidateBVHData
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_Layer::InvalidateBVHData()
|
||||
void Graphic3d_Layer::InvalidateBVHData()
|
||||
{
|
||||
myIsBVHPrimitivesNeedsReset = Standard_True;
|
||||
}
|
||||
@@ -178,11 +173,11 @@ inline bool isInfiniteBndBox (const Graphic3d_BndBox3d& theBndBox)
|
||||
// function : BoundingBox
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Bnd_Box OpenGl_Layer::BoundingBox (const Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
const Standard_Integer theWindowWidth,
|
||||
const Standard_Integer theWindowHeight,
|
||||
const Standard_Boolean theToIncludeAuxiliary) const
|
||||
Bnd_Box Graphic3d_Layer::BoundingBox (Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
Standard_Integer theWindowWidth,
|
||||
Standard_Integer theWindowHeight,
|
||||
Standard_Boolean theToIncludeAuxiliary) const
|
||||
{
|
||||
updateBVH();
|
||||
|
||||
@@ -194,12 +189,12 @@ Bnd_Box OpenGl_Layer::BoundingBox (const Standard_Integer theViewId,
|
||||
// Recompute layer bounding box
|
||||
myBoundingBox[aBoxId].SetVoid();
|
||||
|
||||
for (OpenGl_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
for (Graphic3d_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
{
|
||||
const OpenGl_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
const Graphic3d_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (Graphic3d_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStructure = aStructIter.Value();
|
||||
const Graphic3d_CStructure* aStructure = aStructIter.Value();
|
||||
if (!aStructure->IsVisible (theViewId))
|
||||
{
|
||||
continue;
|
||||
@@ -264,9 +259,9 @@ Bnd_Box OpenGl_Layer::BoundingBox (const Standard_Integer theViewId,
|
||||
}
|
||||
|
||||
// add transformation-persistent objects which depend on camera position (and thus can not be cached) for operations like Z-fit
|
||||
for (NCollection_IndexedMap<const OpenGl_Structure*>::Iterator aStructIter (myAlwaysRenderedMap); aStructIter.More(); aStructIter.Next())
|
||||
for (NCollection_IndexedMap<const Graphic3d_CStructure*>::Iterator aStructIter (myAlwaysRenderedMap); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStructure = aStructIter.Value();
|
||||
const Graphic3d_CStructure* aStructure = aStructIter.Value();
|
||||
if (!aStructure->IsVisible (theViewId))
|
||||
{
|
||||
continue;
|
||||
@@ -299,10 +294,10 @@ Bnd_Box OpenGl_Layer::BoundingBox (const Standard_Integer theViewId,
|
||||
// function : considerZoomPersistenceObjects
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Real OpenGl_Layer::considerZoomPersistenceObjects (const Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
Standard_Integer theWindowWidth,
|
||||
Standard_Integer theWindowHeight) const
|
||||
Standard_Real Graphic3d_Layer::considerZoomPersistenceObjects (Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
Standard_Integer theWindowWidth,
|
||||
Standard_Integer theWindowHeight) const
|
||||
{
|
||||
if (NbOfTransformPersistenceObjects() == 0)
|
||||
{
|
||||
@@ -313,12 +308,12 @@ Standard_Real OpenGl_Layer::considerZoomPersistenceObjects (const Standard_Integ
|
||||
const Graphic3d_Mat4d& aWorldViewMat = theCamera->OrientationMatrix();
|
||||
Standard_Real aMaxCoef = -std::numeric_limits<double>::max();
|
||||
|
||||
for (OpenGl_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
for (Graphic3d_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
{
|
||||
const OpenGl_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
const Graphic3d_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (Graphic3d_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStructure = aStructIter.Value();
|
||||
const Graphic3d_CStructure* aStructure = aStructIter.Value();
|
||||
if (!aStructure->IsVisible (theViewId)
|
||||
|| aStructure->TransformPersistence().IsNull()
|
||||
|| !aStructure->TransformPersistence()->IsZoomOrRotate())
|
||||
@@ -417,35 +412,11 @@ Standard_Real OpenGl_Layer::considerZoomPersistenceObjects (const Standard_Integ
|
||||
return (aMaxCoef > 0.0) ? aMaxCoef : 1.0;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : renderAll
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_Layer::renderAll (const Handle(OpenGl_Workspace)& theWorkspace) const
|
||||
{
|
||||
const Standard_Integer aViewId = theWorkspace->View()->Identification();
|
||||
for (OpenGl_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
{
|
||||
const OpenGl_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStruct = aStructIter.Value();
|
||||
if (aStruct->IsCulled()
|
||||
|| !aStruct->IsVisible (aViewId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
aStruct->Render (theWorkspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : updateBVH
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_Layer::updateBVH() const
|
||||
void Graphic3d_Layer::updateBVH() const
|
||||
{
|
||||
if (!myIsBVHPrimitivesNeedsReset)
|
||||
{
|
||||
@@ -456,12 +427,12 @@ void OpenGl_Layer::updateBVH() const
|
||||
myBVHPrimitivesTrsfPers.Clear();
|
||||
myAlwaysRenderedMap.Clear();
|
||||
myIsBVHPrimitivesNeedsReset = Standard_False;
|
||||
for (OpenGl_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
for (Graphic3d_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
{
|
||||
const OpenGl_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
const Graphic3d_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (Graphic3d_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStruct = aStructIter.Value();
|
||||
const Graphic3d_CStructure* aStruct = aStructIter.Value();
|
||||
if (aStruct->IsAlwaysRendered())
|
||||
{
|
||||
aStruct->MarkAsNotCulled();
|
||||
@@ -483,25 +454,24 @@ void OpenGl_Layer::updateBVH() const
|
||||
// function : UpdateCulling
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_Layer::UpdateCulling (const Standard_Integer theViewId,
|
||||
const OpenGl_BVHTreeSelector& theSelector,
|
||||
const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState)
|
||||
void Graphic3d_Layer::UpdateCulling (Standard_Integer theViewId,
|
||||
const Graphic3d_CullingTool& theSelector,
|
||||
const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState)
|
||||
{
|
||||
updateBVH();
|
||||
|
||||
myNbStructuresNotCulled = myNbStructures;
|
||||
if (theFrustumCullingState != Graphic3d_RenderingParams::FrustumCulling_NoUpdate)
|
||||
{
|
||||
Standard_Boolean toTraverse =
|
||||
(theFrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On);
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitives.Structures()); aStructIter.More(); aStructIter.Next())
|
||||
Standard_Boolean toTraverse = (theFrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On);
|
||||
for (Graphic3d_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitives.Structures()); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStruct = aStructIter.Value();
|
||||
const Graphic3d_CStructure* aStruct = aStructIter.Value();
|
||||
aStruct->SetCulled (toTraverse);
|
||||
}
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitivesTrsfPers.Structures()); aStructIter.More(); aStructIter.Next())
|
||||
for (Graphic3d_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitivesTrsfPers.Structures()); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStruct = aStructIter.Value();
|
||||
const Graphic3d_CStructure* aStruct = aStructIter.Value();
|
||||
aStruct->SetCulled (toTraverse);
|
||||
}
|
||||
}
|
||||
@@ -517,7 +487,7 @@ void OpenGl_Layer::UpdateCulling (const Standard_Integer theViewId,
|
||||
}
|
||||
|
||||
myNbStructuresNotCulled = myAlwaysRenderedMap.Extent();
|
||||
OpenGl_BVHTreeSelector::CullingContext aCullCtx;
|
||||
Graphic3d_CullingTool::CullingContext aCullCtx;
|
||||
theSelector.SetCullingDistance(aCullCtx, myLayerSettings.CullingDistance());
|
||||
theSelector.SetCullingSize (aCullCtx, myLayerSettings.CullingSize());
|
||||
for (Standard_Integer aBVHTreeIdx = 0; aBVHTreeIdx < 2; ++aBVHTreeIdx)
|
||||
@@ -529,8 +499,8 @@ void OpenGl_Layer::UpdateCulling (const Standard_Integer theViewId,
|
||||
if (myBVHPrimitivesTrsfPers.Size() == 0)
|
||||
continue;
|
||||
|
||||
const OpenGl_Mat4d& aProjection = theSelector.ProjectionMatrix();
|
||||
const OpenGl_Mat4d& aWorldView = theSelector.WorldViewMatrix();
|
||||
const Graphic3d_Mat4d& aProjection = theSelector.ProjectionMatrix();
|
||||
const Graphic3d_Mat4d& aWorldView = theSelector.WorldViewMatrix();
|
||||
const Graphic3d_WorldViewProjState& aWVPState = theSelector.WorldViewProjState();
|
||||
const Standard_Integer aViewportWidth = theSelector.ViewportWidth();
|
||||
const Standard_Integer aViewportHeight = theSelector.ViewportHeight();
|
||||
@@ -586,9 +556,9 @@ void OpenGl_Layer::UpdateCulling (const Standard_Integer theViewId,
|
||||
else
|
||||
{
|
||||
Standard_Integer aIdx = aBVHTree->BegPrimitive (aNode);
|
||||
const OpenGl_Structure* aStruct = isTrsfPers
|
||||
? myBVHPrimitivesTrsfPers.GetStructureById (aIdx)
|
||||
: myBVHPrimitives.GetStructureById (aIdx);
|
||||
const Graphic3d_CStructure* aStruct = isTrsfPers
|
||||
? myBVHPrimitivesTrsfPers.GetStructureById (aIdx)
|
||||
: myBVHPrimitives.GetStructureById (aIdx);
|
||||
if (aStruct->IsVisible (theViewId))
|
||||
{
|
||||
aStruct->MarkAsNotCulled();
|
||||
@@ -609,7 +579,7 @@ void OpenGl_Layer::UpdateCulling (const Standard_Integer theViewId,
|
||||
// function : Append
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean OpenGl_Layer::Append (const OpenGl_Layer& theOther)
|
||||
Standard_Boolean Graphic3d_Layer::Append (const Graphic3d_Layer& theOther)
|
||||
{
|
||||
// the source priority list shouldn't have more priorities
|
||||
const Standard_Integer aNbPriorities = theOther.NbPriorities();
|
||||
@@ -621,8 +591,8 @@ Standard_Boolean OpenGl_Layer::Append (const OpenGl_Layer& theOther)
|
||||
// add all structures to destination priority list
|
||||
for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
|
||||
{
|
||||
const OpenGl_IndexedMapOfStructure& aStructures = theOther.myArray (aPriorityIter);
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
const Graphic3d_IndexedMapOfStructure& aStructures = theOther.myArray (aPriorityIter);
|
||||
for (Graphic3d_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
Add (aStructIter.Value(), aPriorityIter);
|
||||
}
|
||||
@@ -635,139 +605,22 @@ Standard_Boolean OpenGl_Layer::Append (const OpenGl_Layer& theOther)
|
||||
//function : SetLayerSettings
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void OpenGl_Layer::SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings)
|
||||
void Graphic3d_Layer::SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings)
|
||||
{
|
||||
const Standard_Boolean toUpdateTrsf = !myLayerSettings.Origin().IsEqual (theSettings.Origin(), gp::Resolution());
|
||||
myLayerSettings = theSettings;
|
||||
if (toUpdateTrsf)
|
||||
if (!toUpdateTrsf)
|
||||
{
|
||||
for (OpenGl_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
return;
|
||||
}
|
||||
|
||||
for (Graphic3d_ArrayOfIndexedMapOfStructure::Iterator aMapIter (myArray); aMapIter.More(); aMapIter.Next())
|
||||
{
|
||||
Graphic3d_IndexedMapOfStructure& aStructures = aMapIter.ChangeValue();
|
||||
for (Graphic3d_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
OpenGl_IndexedMapOfStructure& aStructures = aMapIter.ChangeValue();
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
OpenGl_Structure* aStructure = const_cast<OpenGl_Structure*> (aStructIter.Value());
|
||||
aStructure->updateLayerTransformation();
|
||||
}
|
||||
Graphic3d_CStructure* aStructure = const_cast<Graphic3d_CStructure* >(aStructIter.Value());
|
||||
aStructure->updateLayerTransformation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Render
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void OpenGl_Layer::Render (const Handle(OpenGl_Workspace)& theWorkspace,
|
||||
const OpenGl_GlobalLayerSettings& theDefaultSettings) const
|
||||
{
|
||||
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
|
||||
// myLayerSettings.ToClearDepth() is handled outside
|
||||
|
||||
// handle depth test
|
||||
if (myLayerSettings.ToEnableDepthTest())
|
||||
{
|
||||
// assuming depth test is enabled by default
|
||||
glDepthFunc (theDefaultSettings.DepthFunc);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDepthFunc (GL_ALWAYS);
|
||||
}
|
||||
|
||||
// save environment texture
|
||||
Handle(OpenGl_TextureSet) anEnvironmentTexture = theWorkspace->EnvironmentTexture();
|
||||
if (!myLayerSettings.UseEnvironmentTexture())
|
||||
{
|
||||
theWorkspace->SetEnvironmentTexture (Handle(OpenGl_TextureSet)());
|
||||
}
|
||||
|
||||
// handle depth offset
|
||||
const Graphic3d_PolygonOffset anAppliedOffsetParams = theWorkspace->SetDefaultPolygonOffset (myLayerSettings.PolygonOffset());
|
||||
|
||||
// handle depth write
|
||||
theWorkspace->UseDepthWrite() = myLayerSettings.ToEnableDepthWrite() && theDefaultSettings.DepthMask == GL_TRUE;
|
||||
glDepthMask (theWorkspace->UseDepthWrite() ? GL_TRUE : GL_FALSE);
|
||||
|
||||
const Standard_Boolean hasLocalCS = !myLayerSettings.OriginTransformation().IsNull();
|
||||
const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
|
||||
Handle(Graphic3d_LightSet) aLightsBack = aManager->LightSourceState().LightSources();
|
||||
const bool hasOwnLights = aCtx->ColorMask() && !myLayerSettings.Lights().IsNull() && myLayerSettings.Lights() != aLightsBack;
|
||||
if (hasOwnLights)
|
||||
{
|
||||
myLayerSettings.Lights()->UpdateRevision();
|
||||
aManager->UpdateLightSourceStateTo (myLayerSettings.Lights());
|
||||
}
|
||||
|
||||
const Handle(Graphic3d_Camera)& aWorldCamera = theWorkspace->View()->Camera();
|
||||
if (hasLocalCS)
|
||||
{
|
||||
// Apply local camera transformation.
|
||||
// The vertex position is computed by the following formula in GLSL program:
|
||||
// gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
|
||||
// where:
|
||||
// occProjectionMatrix - matrix defining orthographic/perspective/stereographic projection
|
||||
// occWorldViewMatrix - world-view matrix defining Camera position and orientation
|
||||
// occModelWorldMatrix - model-world matrix defining Object transformation from local coordinate system to the world coordinate system
|
||||
// occVertex - input vertex position
|
||||
//
|
||||
// Since double precision is quite expensive on modern GPUs, and not available on old hardware,
|
||||
// all these values are passed with single float precision to the shader.
|
||||
// As result, single precision become insufficient for handling objects far from the world origin.
|
||||
//
|
||||
// Several approaches can be used to solve precision issues:
|
||||
// - [Broute force] migrate to double precision for all matrices and vertex position.
|
||||
// This is too expensive for most hardware.
|
||||
// - Store only translation part with double precision and pass it to GLSL program.
|
||||
// This requires modified GLSL programs for computing transformation
|
||||
// and extra packing mechanism for hardware not supporting double precision natively.
|
||||
// This solution is less expensive then previous one.
|
||||
// - Move translation part of occModelWorldMatrix into occWorldViewMatrix.
|
||||
// The main idea here is that while moving Camera towards the object,
|
||||
// Camera translation part and Object translation part will compensate each other
|
||||
// to fit into single float precision.
|
||||
// But this operation should be performed with double precision - this is why we are moving
|
||||
// translation part of occModelWorldMatrix to occWorldViewMatrix.
|
||||
//
|
||||
// All approaches might be useful in different scenarios, but for the moment we consider the last one as main scenario.
|
||||
// Here we do the trick:
|
||||
// - OpenGl_Layer defines the Local Origin, which is expected to be the center of objects stored within it.
|
||||
// This Local Origin is included into occWorldViewMatrix during rendering.
|
||||
// - OpenGl_Structure defines Object local transformation occModelWorldMatrix with subtracted Local Origin of the Layer.
|
||||
// This means that Object itself should be defined within either Local Transformation equal or near to Local Origin of the Layer.
|
||||
theWorkspace->View()->SetLocalOrigin (myLayerSettings.Origin());
|
||||
|
||||
NCollection_Mat4<Standard_Real> aWorldView = aWorldCamera->OrientationMatrix();
|
||||
Graphic3d_TransformUtils::Translate (aWorldView, myLayerSettings.Origin().X(), myLayerSettings.Origin().Y(), myLayerSettings.Origin().Z());
|
||||
|
||||
NCollection_Mat4<Standard_ShortReal> aWorldViewF;
|
||||
aWorldViewF.ConvertFrom (aWorldView);
|
||||
aCtx->WorldViewState.SetCurrent (aWorldViewF);
|
||||
aCtx->ShaderManager()->UpdateClippingState();
|
||||
aCtx->ShaderManager()->UpdateLightSourceState();
|
||||
}
|
||||
|
||||
// render priority list
|
||||
renderAll (theWorkspace);
|
||||
|
||||
if (hasOwnLights)
|
||||
{
|
||||
aManager->UpdateLightSourceStateTo (aLightsBack);
|
||||
}
|
||||
if (hasLocalCS)
|
||||
{
|
||||
aCtx->ShaderManager()->RevertClippingState();
|
||||
aCtx->ShaderManager()->UpdateLightSourceState();
|
||||
|
||||
aCtx->WorldViewState.SetCurrent (aWorldCamera->OrientationMatrixF());
|
||||
theWorkspace->View() ->SetLocalOrigin (gp_XYZ (0.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
// always restore polygon offset between layers rendering
|
||||
theWorkspace->SetDefaultPolygonOffset (anAppliedOffsetParams);
|
||||
|
||||
// restore environment texture
|
||||
if (!myLayerSettings.UseEnvironmentTexture())
|
||||
{
|
||||
theWorkspace->SetEnvironmentTexture (anEnvironmentTexture);
|
||||
}
|
||||
}
|
184
src/Graphic3d/Graphic3d_Layer.hxx
Normal file
184
src/Graphic3d/Graphic3d_Layer.hxx
Normal file
@@ -0,0 +1,184 @@
|
||||
// Copyright (c) 2011-2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Graphic3d_Layer_HeaderFile
|
||||
#define _Graphic3d_Layer_HeaderFile
|
||||
|
||||
#include <Graphic3d_BvhCStructureSet.hxx>
|
||||
#include <Graphic3d_BvhCStructureSetTrsfPers.hxx>
|
||||
#include <Graphic3d_Camera.hxx>
|
||||
#include <Graphic3d_ZLayerSettings.hxx>
|
||||
#include <Graphic3d_RenderingParams.hxx>
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <NCollection_IndexedMap.hxx>
|
||||
#include <NCollection_Sequence.hxx>
|
||||
|
||||
//! Defines index map of structures.
|
||||
typedef NCollection_IndexedMap<const Graphic3d_CStructure*> Graphic3d_IndexedMapOfStructure;
|
||||
|
||||
//! Defines array of indexed maps of structures.
|
||||
typedef NCollection_Array1<Graphic3d_IndexedMapOfStructure> Graphic3d_ArrayOfIndexedMapOfStructure;
|
||||
|
||||
class Graphic3d_CullingTool;
|
||||
|
||||
//! Presentations list sorted within priorities.
|
||||
class Graphic3d_Layer : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Graphic3d_Layer, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Initializes associated priority list and layer properties
|
||||
Standard_EXPORT Graphic3d_Layer (Standard_Integer theNbPriorities,
|
||||
const Handle(Select3D_BVHBuilder3d)& theBuilder);
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Graphic3d_Layer();
|
||||
|
||||
//! Returns BVH tree builder for frustom culling.
|
||||
const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHPrimitivesTrsfPers.Builder(); }
|
||||
|
||||
//! Assigns BVH tree builder for frustom culling.
|
||||
void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myBVHPrimitivesTrsfPers.SetBuilder (theBuilder); }
|
||||
|
||||
//! Return true if layer was marked with immediate flag.
|
||||
Standard_Boolean IsImmediate() const { return myLayerSettings.IsImmediate(); }
|
||||
|
||||
//! Returns settings of the layer object.
|
||||
const Graphic3d_ZLayerSettings& LayerSettings() const { return myLayerSettings; };
|
||||
|
||||
//! Sets settings of the layer object.
|
||||
Standard_EXPORT void SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings);
|
||||
|
||||
Standard_EXPORT void Add (const Graphic3d_CStructure* theStruct,
|
||||
Standard_Integer thePriority,
|
||||
Standard_Boolean isForChangePriority = Standard_False);
|
||||
|
||||
//! Remove structure and returns its priority, if the structure is not found, method returns negative value
|
||||
Standard_EXPORT bool Remove (const Graphic3d_CStructure* theStruct,
|
||||
Standard_Integer& thePriority,
|
||||
Standard_Boolean isForChangePriority = Standard_False);
|
||||
|
||||
//! @return the number of structures
|
||||
Standard_Integer NbStructures() const { return myNbStructures; }
|
||||
|
||||
//! Number of NOT culled structures in the layer.
|
||||
Standard_Integer NbStructuresNotCulled() const { return myNbStructuresNotCulled; }
|
||||
|
||||
//! Returns the number of available priority levels
|
||||
Standard_Integer NbPriorities() const { return myArray.Length(); }
|
||||
|
||||
//! Append layer of acceptable type (with similar number of priorities or less).
|
||||
//! Returns Standard_False if the list can not be accepted.
|
||||
Standard_EXPORT Standard_Boolean Append (const Graphic3d_Layer& theOther);
|
||||
|
||||
//! Returns array of structures.
|
||||
const Graphic3d_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
|
||||
|
||||
//! Marks BVH tree for given priority list as dirty and
|
||||
//! marks primitive set for rebuild.
|
||||
Standard_EXPORT void InvalidateBVHData();
|
||||
|
||||
//! Marks cached bounding box as obsolete.
|
||||
void InvalidateBoundingBox() const
|
||||
{
|
||||
myIsBoundingBoxNeedsReset[0] = myIsBoundingBoxNeedsReset[1] = true;
|
||||
}
|
||||
|
||||
//! Returns layer bounding box.
|
||||
//! @param theViewId view index to consider View Affinity in structure
|
||||
//! @param theCamera camera definition
|
||||
//! @param theWindowWidth viewport width (for applying transformation-persistence)
|
||||
//! @param theWindowHeight viewport height (for applying transformation-persistence)
|
||||
//! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
|
||||
//! @return computed bounding box
|
||||
Standard_EXPORT Bnd_Box BoundingBox (Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
Standard_Integer theWindowWidth,
|
||||
Standard_Integer theWindowHeight,
|
||||
Standard_Boolean theToIncludeAuxiliary) const;
|
||||
|
||||
//! Returns zoom-scale factor.
|
||||
Standard_EXPORT Standard_Real considerZoomPersistenceObjects (Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
Standard_Integer theWindowWidth,
|
||||
Standard_Integer theWindowHeight) const;
|
||||
|
||||
//! Update culling state - should be called before rendering.
|
||||
//! Traverses through BVH tree to determine which structures are in view volume.
|
||||
Standard_EXPORT void UpdateCulling (Standard_Integer theViewId,
|
||||
const Graphic3d_CullingTool& theSelector,
|
||||
const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState);
|
||||
|
||||
//! Returns TRUE if layer is empty or has been discarded entirely by culling test.
|
||||
bool IsCulled() const { return myNbStructuresNotCulled == 0; }
|
||||
|
||||
//! Returns number of transform persistence objects.
|
||||
Standard_Integer NbOfTransformPersistenceObjects() const
|
||||
{
|
||||
return myBVHPrimitivesTrsfPers.Size();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! Returns set of Graphic3d_CStructures structures for building BVH tree.
|
||||
const Graphic3d_BvhCStructureSet& CullableStructuresBVH() const { return myBVHPrimitives; }
|
||||
|
||||
//! Returns set of transform persistent Graphic3d_CStructures for building BVH tree.
|
||||
const Graphic3d_BvhCStructureSetTrsfPers& CullableTrsfPersStructuresBVH() const { return myBVHPrimitivesTrsfPers; }
|
||||
|
||||
//! Returns indexed map of always rendered structures.
|
||||
const NCollection_IndexedMap<const Graphic3d_CStructure*>& NonCullableStructures() const { return myAlwaysRenderedMap; }
|
||||
|
||||
protected:
|
||||
|
||||
//! Updates BVH trees if their state has been invalidated.
|
||||
Standard_EXPORT void updateBVH() const;
|
||||
|
||||
private:
|
||||
|
||||
//! Array of Graphic3d_CStructures by priority rendered in layer.
|
||||
Graphic3d_ArrayOfIndexedMapOfStructure myArray;
|
||||
|
||||
//! Overall number of structures rendered in the layer.
|
||||
Standard_Integer myNbStructures;
|
||||
|
||||
//! Number of NOT culled structures in the layer.
|
||||
Standard_Integer myNbStructuresNotCulled;
|
||||
|
||||
//! Layer setting flags.
|
||||
Graphic3d_ZLayerSettings myLayerSettings;
|
||||
|
||||
//! Set of Graphic3d_CStructures structures for building BVH tree.
|
||||
mutable Graphic3d_BvhCStructureSet myBVHPrimitives;
|
||||
|
||||
//! Set of transform persistent Graphic3d_CStructures for building BVH tree.
|
||||
mutable Graphic3d_BvhCStructureSetTrsfPers myBVHPrimitivesTrsfPers;
|
||||
|
||||
//! Indexed map of always rendered structures.
|
||||
mutable NCollection_IndexedMap<const Graphic3d_CStructure*> myAlwaysRenderedMap;
|
||||
|
||||
//! Is needed for implementation of stochastic order of BVH traverse.
|
||||
Standard_Boolean myBVHIsLeftChildQueuedFirst;
|
||||
|
||||
//! Defines if the primitive set for BVH is outdated.
|
||||
mutable Standard_Boolean myIsBVHPrimitivesNeedsReset;
|
||||
|
||||
//! Defines if the cached bounding box is outdated.
|
||||
mutable bool myIsBoundingBoxNeedsReset[2];
|
||||
|
||||
//! Cached layer bounding box.
|
||||
mutable Bnd_Box myBoundingBox[2];
|
||||
|
||||
};
|
||||
|
||||
#endif // _Graphic3d_Layer_HeaderFile
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2014 OPEN CASCADE SAS
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
@@ -11,14 +11,14 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _OpenGl_MapOfZLayerSettings_HeaderFile
|
||||
#define _OpenGl_MapOfZLayerSettings_HeaderFile
|
||||
#ifndef _Vulkan_MapOfZLayerSettings_HeaderFile
|
||||
#define _Vulkan_MapOfZLayerSettings_HeaderFile
|
||||
|
||||
#include <Standard_TypeDef.hxx>
|
||||
#include <NCollection_Map.hxx>
|
||||
#include <Graphic3d_ZLayerId.hxx>
|
||||
#include <Graphic3d_ZLayerSettings.hxx>
|
||||
|
||||
typedef NCollection_DataMap<Graphic3d_ZLayerId, Graphic3d_ZLayerSettings> OpenGl_MapOfZLayerSettings;
|
||||
typedef NCollection_DataMap<Graphic3d_ZLayerId, Graphic3d_ZLayerSettings> Graphic3d_MapOfZLayerSettings;
|
||||
|
||||
#endif // _OpenGl_MapOfZLayerSettings_HeaderFile
|
||||
#endif // _Vulkan_MapOfZLayerSettings_HeaderFile
|
@@ -18,6 +18,7 @@
|
||||
#include <Geom_Transformation.hxx>
|
||||
#include <Graphic3d_LightSet.hxx>
|
||||
#include <Graphic3d_PolygonOffset.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
enum Graphic3d_ZLayerSetting
|
||||
|
@@ -18,6 +18,7 @@ proc Visualization:toolkits { } {
|
||||
set aResult [list TKService \
|
||||
TKV3d \
|
||||
TKOpenGl \
|
||||
TKVulkan \
|
||||
TKMeshVS]
|
||||
|
||||
if { [info exists ::env(HAVE_VTK)] && "$::env(HAVE_VTK)" == "true" } {
|
||||
|
@@ -39,7 +39,6 @@ OpenGl_View_Raytrace.cxx
|
||||
OpenGl_View_Redraw.cxx
|
||||
OpenGl_GraduatedTrihedron.hxx
|
||||
OpenGl_GraduatedTrihedron.cxx
|
||||
OpenGl_MapOfZLayerSettings.hxx
|
||||
OpenGl_Material.hxx
|
||||
OpenGl_MaterialState.hxx
|
||||
OpenGl_Matrix.hxx
|
||||
@@ -63,12 +62,6 @@ OpenGl_Font.hxx
|
||||
OpenGl_Font.cxx
|
||||
OpenGl_BackgroundArray.cxx
|
||||
OpenGl_BackgroundArray.hxx
|
||||
OpenGl_BVHClipPrimitiveSet.cxx
|
||||
OpenGl_BVHClipPrimitiveSet.hxx
|
||||
OpenGl_BVHClipPrimitiveTrsfPersSet.cxx
|
||||
OpenGl_BVHClipPrimitiveTrsfPersSet.hxx
|
||||
OpenGl_BVHTreeSelector.cxx
|
||||
OpenGl_BVHTreeSelector.hxx
|
||||
OpenGl_CappingAlgo.cxx
|
||||
OpenGl_CappingAlgo.hxx
|
||||
OpenGl_CappingPlaneResource.cxx
|
||||
@@ -102,6 +95,7 @@ OpenGl_GlCore41.hxx
|
||||
OpenGl_GlCore42.hxx
|
||||
OpenGl_GlCore43.hxx
|
||||
OpenGl_GlCore44.hxx
|
||||
OpenGl_GlCore45.hxx
|
||||
OpenGl_LayerList.cxx
|
||||
OpenGl_LayerList.hxx
|
||||
OpenGl_LayerFilter.hxx
|
||||
@@ -109,7 +103,6 @@ OpenGl_GraphicDriver.cxx
|
||||
OpenGl_GraphicDriver.hxx
|
||||
OpenGl_IndexBuffer.cxx
|
||||
OpenGl_IndexBuffer.hxx
|
||||
OpenGl_Layer.cxx
|
||||
OpenGl_Layer.hxx
|
||||
OpenGl_RenderFilter.hxx
|
||||
OpenGl_Sampler.cxx
|
||||
|
@@ -36,6 +36,7 @@ OpenGl_Caps::OpenGl_Caps()
|
||||
useSystemBuffer (Standard_True),
|
||||
#endif
|
||||
swapInterval (1),
|
||||
useZeroToOneDepth (true), ///(Standard_False),
|
||||
buffersNoSwap (Standard_False),
|
||||
contextStereo (Standard_False),
|
||||
#ifdef OCCT_DEBUG
|
||||
@@ -70,6 +71,7 @@ OpenGl_Caps& OpenGl_Caps::operator= (const OpenGl_Caps& theCopy)
|
||||
ffpEnable = theCopy.ffpEnable;
|
||||
useSystemBuffer = theCopy.useSystemBuffer;
|
||||
swapInterval = theCopy.swapInterval;
|
||||
useZeroToOneDepth = theCopy.useZeroToOneDepth;
|
||||
buffersNoSwap = theCopy.buffersNoSwap;
|
||||
contextStereo = theCopy.contextStereo;
|
||||
contextDebug = theCopy.contextDebug;
|
||||
|
@@ -34,6 +34,7 @@ public: //! @name flags to disable particular functionality, should be used only
|
||||
Standard_Boolean usePolygonMode; //!< Enables Polygon Mode instead of built-in GLSL programs (OFF by default; unsupported on OpenGL ES)
|
||||
Standard_Boolean useSystemBuffer; //!< Enables usage of system backbuffer for blitting (OFF by default on desktop OpenGL and ON on OpenGL ES for testing)
|
||||
Standard_Integer swapInterval; //!< controls swap interval - 0 for VSync off and 1 for VSync on, 1 by default
|
||||
Standard_Boolean useZeroToOneDepth; //!< use [0, 1] depth range instead of [-1, 1] range, when possible (OFF by default)
|
||||
|
||||
public: //! @name context creation parameters
|
||||
|
||||
@@ -60,7 +61,7 @@ public: //! @name context creation parameters
|
||||
* (see OpenGl_Context - messages will be printed to standard output).
|
||||
* Affects performance - thus should not be turned on by products in released state.
|
||||
*
|
||||
* OFF by default. Currently implemented only for Windows (WGL).
|
||||
* OFF by default.
|
||||
*/
|
||||
Standard_Boolean contextDebug;
|
||||
|
||||
|
@@ -26,7 +26,7 @@
|
||||
#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>
|
||||
@@ -109,6 +109,8 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
|
||||
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),
|
||||
@@ -134,6 +136,7 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
|
||||
arbTexBindless (NULL),
|
||||
arbTBO (NULL),
|
||||
arbTboRGB32 (Standard_False),
|
||||
arbClipControl (Standard_False),
|
||||
arbIns (NULL),
|
||||
arbDbg (NULL),
|
||||
arbFBO (NULL),
|
||||
@@ -1266,8 +1269,11 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
|
||||
core43back = NULL;
|
||||
core44 = NULL;
|
||||
core44back = NULL;
|
||||
core45 = NULL;
|
||||
core45back = NULL;
|
||||
arbTBO = NULL;
|
||||
arbTboRGB32 = Standard_False;
|
||||
arbClipControl = Standard_False;
|
||||
arbIns = NULL;
|
||||
arbDbg = NULL;
|
||||
arbFBO = NULL;
|
||||
@@ -1532,6 +1538,7 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
|
||||
bool has42 = false;
|
||||
bool has43 = false;
|
||||
bool has44 = false;
|
||||
bool has45 = false;
|
||||
|
||||
// retrieve platform-dependent extensions
|
||||
#if defined(HAVE_EGL)
|
||||
@@ -2331,6 +2338,131 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
|
||||
&& FindProcShort (glBindImageTextures)
|
||||
&& FindProcShort (glBindVertexBuffers);
|
||||
|
||||
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);
|
||||
|
||||
// initialize debug context extension
|
||||
if (CheckExtension ("GL_ARB_debug_output"))
|
||||
{
|
||||
@@ -2419,6 +2551,12 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
|
||||
arbTexBindless = (OpenGl_ArbTexBindless* )(&(*myFuncs));
|
||||
}
|
||||
|
||||
if (CheckExtension ("GL_ARB_clip_control")
|
||||
&& FindProcShort (glClipControl))
|
||||
{
|
||||
arbClipControl = Standard_True;
|
||||
}
|
||||
|
||||
if (!has12)
|
||||
{
|
||||
checkWrongVersion (1, 2);
|
||||
@@ -2636,6 +2774,20 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
|
||||
{
|
||||
core44back = (OpenGl_GlCore44Back* )(&(*myFuncs));
|
||||
}
|
||||
|
||||
if (!has45)
|
||||
{
|
||||
checkWrongVersion (4, 5);
|
||||
myGlVerMajor = 4;
|
||||
myGlVerMinor = 4;
|
||||
return;
|
||||
}
|
||||
core45 = (OpenGl_GlCore45* )(&(*myFuncs));
|
||||
arbClipControl = Standard_True;
|
||||
if (!isCoreProfile)
|
||||
{
|
||||
core45back = (OpenGl_GlCore45Back* )(&(*myFuncs));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -132,6 +132,10 @@ template<typename theBaseClass_t> struct OpenGl_TmplCore44;
|
||||
typedef OpenGl_TmplCore44<OpenGl_GlCore43Back> OpenGl_GlCore44Back;
|
||||
typedef OpenGl_TmplCore44<OpenGl_GlCore43> OpenGl_GlCore44;
|
||||
|
||||
template<typename theBaseClass_t> struct OpenGl_TmplCore45;
|
||||
typedef OpenGl_TmplCore45<OpenGl_GlCore44Back> OpenGl_GlCore45Back;
|
||||
typedef OpenGl_TmplCore45<OpenGl_GlCore44> OpenGl_GlCore45;
|
||||
|
||||
class Graphic3d_PresentationAttributes;
|
||||
class OpenGl_Aspects;
|
||||
class OpenGl_FrameBuffer;
|
||||
@@ -853,6 +857,8 @@ public: //! @name core profiles
|
||||
OpenGl_GlCore43Back* core43back; //!< OpenGL 4.3 backward compatibility profile
|
||||
OpenGl_GlCore44* core44; //!< OpenGL 4.4 core profile
|
||||
OpenGl_GlCore44Back* core44back; //!< OpenGL 4.4 backward compatibility profile
|
||||
OpenGl_GlCore45* core45; //!< OpenGL 4.5 core profile
|
||||
OpenGl_GlCore45Back* core45back; //!< OpenGL 4.5 backward compatibility profile
|
||||
|
||||
Handle(OpenGl_Caps) caps; //!< context options
|
||||
|
||||
@@ -875,6 +881,7 @@ public: //! @name extensions
|
||||
OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture
|
||||
OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object
|
||||
Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0
|
||||
Standard_Boolean arbClipControl; //!< GL_ARB_clip_control, in core since 4.5
|
||||
OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced
|
||||
OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output
|
||||
OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object
|
||||
|
@@ -186,12 +186,12 @@ void OpenGl_FrameStats::updateStatistics (const Handle(Graphic3d_CView)& theView
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId,
|
||||
const OpenGl_IndexedMapOfStructure& theStructures,
|
||||
const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructures,
|
||||
Standard_Boolean theToCountElems,
|
||||
Standard_Boolean theToCountTris,
|
||||
Standard_Boolean theToCountMem)
|
||||
{
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (theStructures); aStructIter.More(); aStructIter.Next())
|
||||
for (OpenGl_Structure::StructIterator aStructIter (theStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStruct = aStructIter.Value();
|
||||
const bool isStructHidden = aStruct->IsCulled()
|
||||
|
@@ -17,9 +17,7 @@
|
||||
#include <Graphic3d_FrameStats.hxx>
|
||||
#include <NCollection_IndexedMap.hxx>
|
||||
|
||||
class OpenGl_Workspace;
|
||||
class OpenGl_Structure;
|
||||
typedef NCollection_IndexedMap<const OpenGl_Structure*> OpenGl_IndexedMapOfStructure;
|
||||
class Graphic3d_CStructure;
|
||||
|
||||
//! Class storing the frame statistics.
|
||||
class OpenGl_FrameStats : public Graphic3d_FrameStats
|
||||
@@ -48,7 +46,7 @@ protected:
|
||||
|
||||
//! Updates counters for structures.
|
||||
Standard_EXPORT virtual void updateStructures (Standard_Integer theViewId,
|
||||
const OpenGl_IndexedMapOfStructure& theStructures,
|
||||
const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructures,
|
||||
Standard_Boolean theToCountElems,
|
||||
Standard_Boolean theToCountTris,
|
||||
Standard_Boolean theToCountMem);
|
||||
|
159
src/OpenGl/OpenGl_GlCore45.hxx
Normal file
159
src/OpenGl/OpenGl_GlCore45.hxx
Normal file
@@ -0,0 +1,159 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _OpenGl_GlCore45_Header
|
||||
#define _OpenGl_GlCore45_Header
|
||||
|
||||
#include <OpenGl_GlCore44.hxx>
|
||||
|
||||
//! OpenGL 4.5 definition.
|
||||
template<typename theBaseClass_t>
|
||||
struct OpenGl_TmplCore45 : public theBaseClass_t
|
||||
{
|
||||
|
||||
public: //! @name OpenGL 4.5 additives to 4.4
|
||||
|
||||
#if !defined(GL_ES_VERSION_2_0)
|
||||
using theBaseClass_t::glClipControl;
|
||||
using theBaseClass_t::glCreateTransformFeedbacks;
|
||||
using theBaseClass_t::glTransformFeedbackBufferBase;
|
||||
using theBaseClass_t::glTransformFeedbackBufferRange;
|
||||
using theBaseClass_t::glGetTransformFeedbackiv;
|
||||
using theBaseClass_t::glGetTransformFeedbacki_v;
|
||||
using theBaseClass_t::glGetTransformFeedbacki64_v;
|
||||
using theBaseClass_t::glCreateBuffers;
|
||||
using theBaseClass_t::glNamedBufferStorage;
|
||||
using theBaseClass_t::glNamedBufferData;
|
||||
using theBaseClass_t::glNamedBufferSubData;
|
||||
using theBaseClass_t::glCopyNamedBufferSubData;
|
||||
using theBaseClass_t::glClearNamedBufferData;
|
||||
using theBaseClass_t::glClearNamedBufferSubData;
|
||||
using theBaseClass_t::glMapNamedBuffer;
|
||||
using theBaseClass_t::glMapNamedBufferRange;
|
||||
using theBaseClass_t::glUnmapNamedBuffer;
|
||||
using theBaseClass_t::glFlushMappedNamedBufferRange;
|
||||
using theBaseClass_t::glGetNamedBufferParameteriv;
|
||||
using theBaseClass_t::glGetNamedBufferParameteri64v;
|
||||
using theBaseClass_t::glGetNamedBufferPointerv;
|
||||
using theBaseClass_t::glGetNamedBufferSubData;
|
||||
using theBaseClass_t::glCreateFramebuffers;
|
||||
using theBaseClass_t::glNamedFramebufferRenderbuffer;
|
||||
using theBaseClass_t::glNamedFramebufferParameteri;
|
||||
using theBaseClass_t::glNamedFramebufferTexture;
|
||||
using theBaseClass_t::glNamedFramebufferTextureLayer;
|
||||
using theBaseClass_t::glNamedFramebufferDrawBuffer;
|
||||
using theBaseClass_t::glNamedFramebufferDrawBuffers;
|
||||
using theBaseClass_t::glNamedFramebufferReadBuffer;
|
||||
using theBaseClass_t::glInvalidateNamedFramebufferData;
|
||||
using theBaseClass_t::glInvalidateNamedFramebufferSubData;
|
||||
using theBaseClass_t::glClearNamedFramebufferiv;
|
||||
using theBaseClass_t::glClearNamedFramebufferuiv;
|
||||
using theBaseClass_t::glClearNamedFramebufferfv;
|
||||
using theBaseClass_t::glClearNamedFramebufferfi;
|
||||
using theBaseClass_t::glBlitNamedFramebuffer;
|
||||
using theBaseClass_t::glCheckNamedFramebufferStatus;
|
||||
using theBaseClass_t::glGetNamedFramebufferParameteriv;
|
||||
using theBaseClass_t::glGetNamedFramebufferAttachmentParameteriv;
|
||||
using theBaseClass_t::glCreateRenderbuffers;
|
||||
using theBaseClass_t::glNamedRenderbufferStorage;
|
||||
using theBaseClass_t::glNamedRenderbufferStorageMultisample;
|
||||
using theBaseClass_t::glGetNamedRenderbufferParameteriv;
|
||||
using theBaseClass_t::glCreateTextures;
|
||||
using theBaseClass_t::glTextureBuffer;
|
||||
using theBaseClass_t::glTextureBufferRange;
|
||||
using theBaseClass_t::glTextureStorage1D;
|
||||
using theBaseClass_t::glTextureStorage2D;
|
||||
using theBaseClass_t::glTextureStorage3D;
|
||||
using theBaseClass_t::glTextureStorage2DMultisample;
|
||||
using theBaseClass_t::glTextureStorage3DMultisample;
|
||||
using theBaseClass_t::glTextureSubImage1D;
|
||||
using theBaseClass_t::glTextureSubImage2D;
|
||||
using theBaseClass_t::glTextureSubImage3D;
|
||||
using theBaseClass_t::glCompressedTextureSubImage1D;
|
||||
using theBaseClass_t::glCompressedTextureSubImage2D;
|
||||
using theBaseClass_t::glCompressedTextureSubImage3D;
|
||||
using theBaseClass_t::glCopyTextureSubImage1D;
|
||||
using theBaseClass_t::glCopyTextureSubImage2D;
|
||||
using theBaseClass_t::glCopyTextureSubImage3D;
|
||||
using theBaseClass_t::glTextureParameterf;
|
||||
using theBaseClass_t::glTextureParameterfv;
|
||||
using theBaseClass_t::glTextureParameteri;
|
||||
using theBaseClass_t::glTextureParameterIiv;
|
||||
using theBaseClass_t::glTextureParameterIuiv;
|
||||
using theBaseClass_t::glTextureParameteriv;
|
||||
using theBaseClass_t::glGenerateTextureMipmap;
|
||||
using theBaseClass_t::glBindTextureUnit;
|
||||
using theBaseClass_t::glGetTextureImage;
|
||||
using theBaseClass_t::glGetCompressedTextureImage;
|
||||
using theBaseClass_t::glGetTextureLevelParameterfv;
|
||||
using theBaseClass_t::glGetTextureLevelParameteriv;
|
||||
using theBaseClass_t::glGetTextureParameterfv;
|
||||
using theBaseClass_t::glGetTextureParameterIiv;
|
||||
using theBaseClass_t::glGetTextureParameterIuiv;
|
||||
using theBaseClass_t::glGetTextureParameteriv;
|
||||
using theBaseClass_t::glCreateVertexArrays;
|
||||
using theBaseClass_t::glDisableVertexArrayAttrib;
|
||||
using theBaseClass_t::glEnableVertexArrayAttrib;
|
||||
using theBaseClass_t::glVertexArrayElementBuffer;
|
||||
using theBaseClass_t::glVertexArrayVertexBuffer;
|
||||
using theBaseClass_t::glVertexArrayVertexBuffers;
|
||||
using theBaseClass_t::glVertexArrayAttribBinding;
|
||||
using theBaseClass_t::glVertexArrayAttribFormat;
|
||||
using theBaseClass_t::glVertexArrayAttribIFormat;
|
||||
using theBaseClass_t::glVertexArrayAttribLFormat;
|
||||
using theBaseClass_t::glVertexArrayBindingDivisor;
|
||||
using theBaseClass_t::glGetVertexArrayiv;
|
||||
using theBaseClass_t::glGetVertexArrayIndexediv;
|
||||
using theBaseClass_t::glGetVertexArrayIndexed64iv;
|
||||
using theBaseClass_t::glCreateSamplers;
|
||||
using theBaseClass_t::glCreateProgramPipelines;
|
||||
using theBaseClass_t::glCreateQueries;
|
||||
using theBaseClass_t::glGetQueryBufferObjecti64v;
|
||||
using theBaseClass_t::glGetQueryBufferObjectiv;
|
||||
using theBaseClass_t::glGetQueryBufferObjectui64v;
|
||||
using theBaseClass_t::glGetQueryBufferObjectuiv;
|
||||
using theBaseClass_t::glMemoryBarrierByRegion;
|
||||
using theBaseClass_t::glGetTextureSubImage;
|
||||
using theBaseClass_t::glGetCompressedTextureSubImage;
|
||||
using theBaseClass_t::glGetGraphicsResetStatus;
|
||||
using theBaseClass_t::glGetnCompressedTexImage;
|
||||
using theBaseClass_t::glGetnTexImage;
|
||||
using theBaseClass_t::glGetnUniformdv;
|
||||
using theBaseClass_t::glGetnUniformfv;
|
||||
using theBaseClass_t::glGetnUniformiv;
|
||||
using theBaseClass_t::glGetnUniformuiv;
|
||||
using theBaseClass_t::glReadnPixels;
|
||||
using theBaseClass_t::glGetnMapdv;
|
||||
using theBaseClass_t::glGetnMapfv;
|
||||
using theBaseClass_t::glGetnMapiv;
|
||||
using theBaseClass_t::glGetnPixelMapfv;
|
||||
using theBaseClass_t::glGetnPixelMapuiv;
|
||||
using theBaseClass_t::glGetnPixelMapusv;
|
||||
using theBaseClass_t::glGetnPolygonStipple;
|
||||
using theBaseClass_t::glGetnColorTable;
|
||||
using theBaseClass_t::glGetnConvolutionFilter;
|
||||
using theBaseClass_t::glGetnSeparableFilter;
|
||||
using theBaseClass_t::glGetnHistogram;
|
||||
using theBaseClass_t::glGetnMinmax;
|
||||
using theBaseClass_t::glTextureBarrier;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
//! OpenGL 4.5 compatibility profile.
|
||||
typedef OpenGl_TmplCore45<OpenGl_GlCore44Back> OpenGl_GlCore45Back;
|
||||
|
||||
//! OpenGL 4.5 core profile.
|
||||
typedef OpenGl_TmplCore45<OpenGl_GlCore44> OpenGl_GlCore45;
|
||||
|
||||
#endif // _OpenGl_GlCore45_Header
|
@@ -1528,6 +1528,131 @@ public: //! @name OpenGL 4.4
|
||||
PFNGLBINDIMAGETEXTURESPROC glBindImageTextures;
|
||||
PFNGLBINDVERTEXBUFFERSPROC glBindVertexBuffers;
|
||||
|
||||
public: //! @name OpenGL 4.5
|
||||
|
||||
PFNGLCLIPCONTROLPROC glClipControl;
|
||||
PFNGLCREATETRANSFORMFEEDBACKSPROC glCreateTransformFeedbacks;
|
||||
PFNGLTRANSFORMFEEDBACKBUFFERBASEPROC glTransformFeedbackBufferBase;
|
||||
PFNGLTRANSFORMFEEDBACKBUFFERRANGEPROC glTransformFeedbackBufferRange;
|
||||
PFNGLGETTRANSFORMFEEDBACKIVPROC glGetTransformFeedbackiv;
|
||||
PFNGLGETTRANSFORMFEEDBACKI_VPROC glGetTransformFeedbacki_v;
|
||||
PFNGLGETTRANSFORMFEEDBACKI64_VPROC glGetTransformFeedbacki64_v;
|
||||
PFNGLCREATEBUFFERSPROC glCreateBuffers;
|
||||
PFNGLNAMEDBUFFERSTORAGEPROC glNamedBufferStorage;
|
||||
PFNGLNAMEDBUFFERDATAPROC glNamedBufferData;
|
||||
PFNGLNAMEDBUFFERSUBDATAPROC glNamedBufferSubData;
|
||||
PFNGLCOPYNAMEDBUFFERSUBDATAPROC glCopyNamedBufferSubData;
|
||||
PFNGLCLEARNAMEDBUFFERDATAPROC glClearNamedBufferData;
|
||||
PFNGLCLEARNAMEDBUFFERSUBDATAPROC glClearNamedBufferSubData;
|
||||
PFNGLMAPNAMEDBUFFERPROC glMapNamedBuffer;
|
||||
PFNGLMAPNAMEDBUFFERRANGEPROC glMapNamedBufferRange;
|
||||
PFNGLUNMAPNAMEDBUFFERPROC glUnmapNamedBuffer;
|
||||
PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEPROC glFlushMappedNamedBufferRange;
|
||||
PFNGLGETNAMEDBUFFERPARAMETERIVPROC glGetNamedBufferParameteriv;
|
||||
PFNGLGETNAMEDBUFFERPARAMETERI64VPROC glGetNamedBufferParameteri64v;
|
||||
PFNGLGETNAMEDBUFFERPOINTERVPROC glGetNamedBufferPointerv;
|
||||
PFNGLGETNAMEDBUFFERSUBDATAPROC glGetNamedBufferSubData;
|
||||
PFNGLCREATEFRAMEBUFFERSPROC glCreateFramebuffers;
|
||||
PFNGLNAMEDFRAMEBUFFERRENDERBUFFERPROC glNamedFramebufferRenderbuffer;
|
||||
PFNGLNAMEDFRAMEBUFFERPARAMETERIPROC glNamedFramebufferParameteri;
|
||||
PFNGLNAMEDFRAMEBUFFERTEXTUREPROC glNamedFramebufferTexture;
|
||||
PFNGLNAMEDFRAMEBUFFERTEXTURELAYERPROC glNamedFramebufferTextureLayer;
|
||||
PFNGLNAMEDFRAMEBUFFERDRAWBUFFERPROC glNamedFramebufferDrawBuffer;
|
||||
PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC glNamedFramebufferDrawBuffers;
|
||||
PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC glNamedFramebufferReadBuffer;
|
||||
PFNGLINVALIDATENAMEDFRAMEBUFFERDATAPROC glInvalidateNamedFramebufferData;
|
||||
PFNGLINVALIDATENAMEDFRAMEBUFFERSUBDATAPROC glInvalidateNamedFramebufferSubData;
|
||||
PFNGLCLEARNAMEDFRAMEBUFFERIVPROC glClearNamedFramebufferiv;
|
||||
PFNGLCLEARNAMEDFRAMEBUFFERUIVPROC glClearNamedFramebufferuiv;
|
||||
PFNGLCLEARNAMEDFRAMEBUFFERFVPROC glClearNamedFramebufferfv;
|
||||
PFNGLCLEARNAMEDFRAMEBUFFERFIPROC glClearNamedFramebufferfi;
|
||||
PFNGLBLITNAMEDFRAMEBUFFERPROC glBlitNamedFramebuffer;
|
||||
PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC glCheckNamedFramebufferStatus;
|
||||
PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVPROC glGetNamedFramebufferParameteriv;
|
||||
PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetNamedFramebufferAttachmentParameteriv;
|
||||
PFNGLCREATERENDERBUFFERSPROC glCreateRenderbuffers;
|
||||
PFNGLNAMEDRENDERBUFFERSTORAGEPROC glNamedRenderbufferStorage;
|
||||
PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEPROC glNamedRenderbufferStorageMultisample;
|
||||
PFNGLGETNAMEDRENDERBUFFERPARAMETERIVPROC glGetNamedRenderbufferParameteriv;
|
||||
PFNGLCREATETEXTURESPROC glCreateTextures;
|
||||
PFNGLTEXTUREBUFFERPROC glTextureBuffer;
|
||||
PFNGLTEXTUREBUFFERRANGEPROC glTextureBufferRange;
|
||||
PFNGLTEXTURESTORAGE1DPROC glTextureStorage1D;
|
||||
PFNGLTEXTURESTORAGE2DPROC glTextureStorage2D;
|
||||
PFNGLTEXTURESTORAGE3DPROC glTextureStorage3D;
|
||||
PFNGLTEXTURESTORAGE2DMULTISAMPLEPROC glTextureStorage2DMultisample;
|
||||
PFNGLTEXTURESTORAGE3DMULTISAMPLEPROC glTextureStorage3DMultisample;
|
||||
PFNGLTEXTURESUBIMAGE1DPROC glTextureSubImage1D;
|
||||
PFNGLTEXTURESUBIMAGE2DPROC glTextureSubImage2D;
|
||||
PFNGLTEXTURESUBIMAGE3DPROC glTextureSubImage3D;
|
||||
PFNGLCOMPRESSEDTEXTURESUBIMAGE1DPROC glCompressedTextureSubImage1D;
|
||||
PFNGLCOMPRESSEDTEXTURESUBIMAGE2DPROC glCompressedTextureSubImage2D;
|
||||
PFNGLCOMPRESSEDTEXTURESUBIMAGE3DPROC glCompressedTextureSubImage3D;
|
||||
PFNGLCOPYTEXTURESUBIMAGE1DPROC glCopyTextureSubImage1D;
|
||||
PFNGLCOPYTEXTURESUBIMAGE2DPROC glCopyTextureSubImage2D;
|
||||
PFNGLCOPYTEXTURESUBIMAGE3DPROC glCopyTextureSubImage3D;
|
||||
PFNGLTEXTUREPARAMETERFPROC glTextureParameterf;
|
||||
PFNGLTEXTUREPARAMETERFVPROC glTextureParameterfv;
|
||||
PFNGLTEXTUREPARAMETERIPROC glTextureParameteri;
|
||||
PFNGLTEXTUREPARAMETERIIVPROC glTextureParameterIiv;
|
||||
PFNGLTEXTUREPARAMETERIUIVPROC glTextureParameterIuiv;
|
||||
PFNGLTEXTUREPARAMETERIVPROC glTextureParameteriv;
|
||||
PFNGLGENERATETEXTUREMIPMAPPROC glGenerateTextureMipmap;
|
||||
PFNGLBINDTEXTUREUNITPROC glBindTextureUnit;
|
||||
PFNGLGETTEXTUREIMAGEPROC glGetTextureImage;
|
||||
PFNGLGETCOMPRESSEDTEXTUREIMAGEPROC glGetCompressedTextureImage;
|
||||
PFNGLGETTEXTURELEVELPARAMETERFVPROC glGetTextureLevelParameterfv;
|
||||
PFNGLGETTEXTURELEVELPARAMETERIVPROC glGetTextureLevelParameteriv;
|
||||
PFNGLGETTEXTUREPARAMETERFVPROC glGetTextureParameterfv;
|
||||
PFNGLGETTEXTUREPARAMETERIIVPROC glGetTextureParameterIiv;
|
||||
PFNGLGETTEXTUREPARAMETERIUIVPROC glGetTextureParameterIuiv;
|
||||
PFNGLGETTEXTUREPARAMETERIVPROC glGetTextureParameteriv;
|
||||
PFNGLCREATEVERTEXARRAYSPROC glCreateVertexArrays;
|
||||
PFNGLDISABLEVERTEXARRAYATTRIBPROC glDisableVertexArrayAttrib;
|
||||
PFNGLENABLEVERTEXARRAYATTRIBPROC glEnableVertexArrayAttrib;
|
||||
PFNGLVERTEXARRAYELEMENTBUFFERPROC glVertexArrayElementBuffer;
|
||||
PFNGLVERTEXARRAYVERTEXBUFFERPROC glVertexArrayVertexBuffer;
|
||||
PFNGLVERTEXARRAYVERTEXBUFFERSPROC glVertexArrayVertexBuffers;
|
||||
PFNGLVERTEXARRAYATTRIBBINDINGPROC glVertexArrayAttribBinding;
|
||||
PFNGLVERTEXARRAYATTRIBFORMATPROC glVertexArrayAttribFormat;
|
||||
PFNGLVERTEXARRAYATTRIBIFORMATPROC glVertexArrayAttribIFormat;
|
||||
PFNGLVERTEXARRAYATTRIBLFORMATPROC glVertexArrayAttribLFormat;
|
||||
PFNGLVERTEXARRAYBINDINGDIVISORPROC glVertexArrayBindingDivisor;
|
||||
PFNGLGETVERTEXARRAYIVPROC glGetVertexArrayiv;
|
||||
PFNGLGETVERTEXARRAYINDEXEDIVPROC glGetVertexArrayIndexediv;
|
||||
PFNGLGETVERTEXARRAYINDEXED64IVPROC glGetVertexArrayIndexed64iv;
|
||||
PFNGLCREATESAMPLERSPROC glCreateSamplers;
|
||||
PFNGLCREATEPROGRAMPIPELINESPROC glCreateProgramPipelines;
|
||||
PFNGLCREATEQUERIESPROC glCreateQueries;
|
||||
PFNGLGETQUERYBUFFEROBJECTI64VPROC glGetQueryBufferObjecti64v;
|
||||
PFNGLGETQUERYBUFFEROBJECTIVPROC glGetQueryBufferObjectiv;
|
||||
PFNGLGETQUERYBUFFEROBJECTUI64VPROC glGetQueryBufferObjectui64v;
|
||||
PFNGLGETQUERYBUFFEROBJECTUIVPROC glGetQueryBufferObjectuiv;
|
||||
PFNGLMEMORYBARRIERBYREGIONPROC glMemoryBarrierByRegion;
|
||||
PFNGLGETTEXTURESUBIMAGEPROC glGetTextureSubImage;
|
||||
PFNGLGETCOMPRESSEDTEXTURESUBIMAGEPROC glGetCompressedTextureSubImage;
|
||||
PFNGLGETGRAPHICSRESETSTATUSPROC glGetGraphicsResetStatus;
|
||||
PFNGLGETNCOMPRESSEDTEXIMAGEPROC glGetnCompressedTexImage;
|
||||
PFNGLGETNTEXIMAGEPROC glGetnTexImage;
|
||||
PFNGLGETNUNIFORMDVPROC glGetnUniformdv;
|
||||
PFNGLGETNUNIFORMFVPROC glGetnUniformfv;
|
||||
PFNGLGETNUNIFORMIVPROC glGetnUniformiv;
|
||||
PFNGLGETNUNIFORMUIVPROC glGetnUniformuiv;
|
||||
PFNGLREADNPIXELSPROC glReadnPixels;
|
||||
PFNGLGETNMAPDVPROC glGetnMapdv;
|
||||
PFNGLGETNMAPFVPROC glGetnMapfv;
|
||||
PFNGLGETNMAPIVPROC glGetnMapiv;
|
||||
PFNGLGETNPIXELMAPFVPROC glGetnPixelMapfv;
|
||||
PFNGLGETNPIXELMAPUIVPROC glGetnPixelMapuiv;
|
||||
PFNGLGETNPIXELMAPUSVPROC glGetnPixelMapusv;
|
||||
PFNGLGETNPOLYGONSTIPPLEPROC glGetnPolygonStipple;
|
||||
PFNGLGETNCOLORTABLEPROC glGetnColorTable;
|
||||
PFNGLGETNCONVOLUTIONFILTERPROC glGetnConvolutionFilter;
|
||||
PFNGLGETNSEPARABLEFILTERPROC glGetnSeparableFilter;
|
||||
PFNGLGETNHISTOGRAMPROC glGetnHistogram;
|
||||
PFNGLGETNMINMAXPROC glGetnMinmax;
|
||||
PFNGLTEXTUREBARRIERPROC glTextureBarrier;
|
||||
|
||||
public: //! @name GL_EXT_geometry_shader4
|
||||
|
||||
PFNGLPROGRAMPARAMETERIEXTPROC glProgramParameteriEXT;
|
||||
|
@@ -139,72 +139,6 @@ OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnectio
|
||||
{
|
||||
throw Aspect_GraphicDeviceDefinitionError("OpenGl_GraphicDriver: default context can not be initialized!");
|
||||
}
|
||||
|
||||
// default layers are always presented in display layer sequence it can not be removed
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_False);
|
||||
aSettings.SetEnvironmentTexture (Standard_False);
|
||||
aSettings.SetEnableDepthTest (Standard_False);
|
||||
aSettings.SetEnableDepthWrite (Standard_False);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_BotOSD);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_BotOSD);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_False);
|
||||
aSettings.SetEnvironmentTexture (Standard_True);
|
||||
aSettings.SetEnableDepthTest (Standard_True);
|
||||
aSettings.SetEnableDepthWrite (Standard_True);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_Default);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_Default);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_True);
|
||||
aSettings.SetEnvironmentTexture (Standard_True);
|
||||
aSettings.SetEnableDepthTest (Standard_True);
|
||||
aSettings.SetEnableDepthWrite (Standard_True);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_Top);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_Top);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_True);
|
||||
aSettings.SetEnvironmentTexture (Standard_True);
|
||||
aSettings.SetEnableDepthTest (Standard_True);
|
||||
aSettings.SetEnableDepthWrite (Standard_True);
|
||||
aSettings.SetClearDepth (Standard_True);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_Topmost);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_Topmost);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aSettings);
|
||||
}
|
||||
|
||||
{
|
||||
Graphic3d_ZLayerSettings aSettings;
|
||||
aSettings.SetImmediate (Standard_True);
|
||||
aSettings.SetEnvironmentTexture (Standard_False);
|
||||
aSettings.SetEnableDepthTest (Standard_False);
|
||||
aSettings.SetEnableDepthWrite (Standard_False);
|
||||
aSettings.SetClearDepth (Standard_False);
|
||||
aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
|
||||
myLayerIds.Add (Graphic3d_ZLayerId_TopOSD);
|
||||
myLayerSeq.Append (Graphic3d_ZLayerId_TopOSD);
|
||||
myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, aSettings);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@@ -570,50 +504,6 @@ void OpenGl_GraphicDriver::TextSize (const Handle(Graphic3d_CView)& theView,
|
||||
OpenGl_Text::StringSize(aCtx, aText, aTextAspect, aTextParam, theView->RenderingParams().Resolution, theWidth, theAscent, theDescent);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : addZLayerIndex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void OpenGl_GraphicDriver::addZLayerIndex (const Graphic3d_ZLayerId theLayerId)
|
||||
{
|
||||
// remove index
|
||||
for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
|
||||
{
|
||||
if (aLayerIt.Value() == theLayerId)
|
||||
{
|
||||
myLayerSeq.Remove (aLayerIt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (myMapOfZLayerSettings.Find (theLayerId).IsImmediate())
|
||||
{
|
||||
myLayerSeq.Append (theLayerId);
|
||||
return;
|
||||
}
|
||||
|
||||
for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
|
||||
{
|
||||
const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerIt.Value());
|
||||
if (aSettings.IsImmediate())
|
||||
{
|
||||
aLayerIt.Previous();
|
||||
if (aLayerIt.More())
|
||||
{
|
||||
myLayerSeq.InsertAfter (aLayerIt, theLayerId);
|
||||
return;
|
||||
}
|
||||
|
||||
// first non-immediate layer
|
||||
myLayerSeq.Prepend (theLayerId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// no immediate layers
|
||||
myLayerSeq.Append (theLayerId);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddZLayer
|
||||
//purpose :
|
||||
@@ -686,15 +576,6 @@ void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
|
||||
myLayerIds.Remove (theLayerId);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ZLayers
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void OpenGl_GraphicDriver::ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
|
||||
{
|
||||
theLayerSeq.Assign (myLayerSeq);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetZLayerSettings
|
||||
//purpose :
|
||||
@@ -702,22 +583,7 @@ void OpenGl_GraphicDriver::ZLayers (TColStd_SequenceOfInteger& theLayerSeq) cons
|
||||
void OpenGl_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
|
||||
const Graphic3d_ZLayerSettings& theSettings)
|
||||
{
|
||||
Graphic3d_ZLayerSettings* aSettings = myMapOfZLayerSettings.ChangeSeek (theLayerId);
|
||||
if (aSettings != NULL)
|
||||
{
|
||||
const bool isChanged = (aSettings->IsImmediate() != theSettings.IsImmediate());
|
||||
*aSettings = theSettings;
|
||||
if (isChanged)
|
||||
{
|
||||
addZLayerIndex (theLayerId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// abnormal case
|
||||
myMapOfZLayerSettings.Bind (theLayerId, theSettings);
|
||||
addZLayerIndex (theLayerId);
|
||||
}
|
||||
base_type::SetZLayerSettings (theLayerId, theSettings);
|
||||
|
||||
// Change Z layer settings in all managed views
|
||||
for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
|
||||
@@ -726,19 +592,6 @@ void OpenGl_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerI
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ZLayerSettings
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
const Graphic3d_ZLayerSettings& OpenGl_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
|
||||
{
|
||||
Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId),
|
||||
"OpenGl_GraphicDriver::ZLayerSettings, "
|
||||
"Layer with theLayerId does not exist");
|
||||
|
||||
return myMapOfZLayerSettings.Find (theLayerId);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Structure
|
||||
// purpose :
|
||||
|
@@ -20,39 +20,15 @@
|
||||
|
||||
#include <Aspect_Display.hxx>
|
||||
#include <Aspect_DisplayConnection.hxx>
|
||||
#include <Aspect_GradientFillMethod.hxx>
|
||||
#include <Aspect_FillMethod.hxx>
|
||||
#include <Aspect_TypeOfTriedronPosition.hxx>
|
||||
#include <Aspect_Handle.hxx>
|
||||
#include <Aspect_RenderingContext.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <Graphic3d_CView.hxx>
|
||||
#include <Graphic3d_CStructure.hxx>
|
||||
#include <Graphic3d_TextPath.hxx>
|
||||
#include <Graphic3d_HorizontalTextAlignment.hxx>
|
||||
#include <Graphic3d_VerticalTextAlignment.hxx>
|
||||
#include <Graphic3d_GraduatedTrihedron.hxx>
|
||||
#include <Graphic3d_TypeOfComposition.hxx>
|
||||
#include <Graphic3d_BufferType.hxx>
|
||||
#include <NCollection_DataMap.hxx>
|
||||
#include <OpenGl_Context.hxx>
|
||||
#include <OpenGl_MapOfZLayerSettings.hxx>
|
||||
#include <Quantity_NameOfColor.hxx>
|
||||
#include <Standard_CString.hxx>
|
||||
#include <TColStd_Array1OfInteger.hxx>
|
||||
#include <TColStd_Array2OfReal.hxx>
|
||||
#include <TColStd_HArray1OfByte.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_MapOfInteger.hxx>
|
||||
|
||||
class Aspect_Window;
|
||||
class Quantity_Color;
|
||||
class Graphic3d_Vertex;
|
||||
class TCollection_ExtendedString;
|
||||
class Image_PixMap;
|
||||
class OpenGl_Element;
|
||||
class OpenGl_Structure;
|
||||
class OpenGl_Text;
|
||||
class OpenGl_View;
|
||||
class OpenGl_Window;
|
||||
|
||||
@@ -143,15 +119,9 @@ public:
|
||||
//! (reserved for default layers that can not be removed).
|
||||
Standard_EXPORT void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
|
||||
|
||||
//! Returns list of Z layers defined for the graphical driver.
|
||||
Standard_EXPORT void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const Standard_OVERRIDE;
|
||||
|
||||
//! Sets the settings for a single Z layer.
|
||||
Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
|
||||
|
||||
//! Returns the settings of a single Z layer.
|
||||
Standard_EXPORT virtual const Graphic3d_ZLayerSettings& ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
|
||||
|
||||
public:
|
||||
|
||||
//! @return the visualization options
|
||||
@@ -191,9 +161,6 @@ public:
|
||||
void* getRawGlConfig() const { return myEglConfig; }
|
||||
#endif
|
||||
|
||||
//! Insert index layer at proper position.
|
||||
Standard_EXPORT void addZLayerIndex (const Graphic3d_ZLayerId theLayerId);
|
||||
|
||||
//! Set device lost flag for redrawn views.
|
||||
Standard_EXPORT void setDeviceLost();
|
||||
|
||||
@@ -218,10 +185,6 @@ protected:
|
||||
NCollection_Map<Handle(OpenGl_View)> myMapOfView;
|
||||
NCollection_DataMap<Standard_Integer, OpenGl_Structure*> myMapOfStructure;
|
||||
|
||||
TColStd_MapOfInteger myLayerIds;
|
||||
TColStd_SequenceOfInteger myLayerSeq;
|
||||
OpenGl_MapOfZLayerSettings myMapOfZLayerSettings;
|
||||
|
||||
mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures.
|
||||
mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays.
|
||||
|
||||
|
@@ -16,185 +16,8 @@
|
||||
#ifndef _OpenGl_Layer_Header
|
||||
#define _OpenGl_Layer_Header
|
||||
|
||||
#include <NCollection_Sequence.hxx>
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <Graphic3d_Layer.hxx>
|
||||
|
||||
#include <OpenGl_BVHClipPrimitiveSet.hxx>
|
||||
#include <OpenGl_BVHClipPrimitiveTrsfPersSet.hxx>
|
||||
#include <OpenGl_BVHTreeSelector.hxx>
|
||||
|
||||
#include <Graphic3d_ZLayerSettings.hxx>
|
||||
#include <Graphic3d_Camera.hxx>
|
||||
#include <OpenGl_GlCore11.hxx>
|
||||
|
||||
|
||||
struct OpenGl_GlobalLayerSettings
|
||||
{
|
||||
GLint DepthFunc;
|
||||
GLboolean DepthMask;
|
||||
};
|
||||
|
||||
//! Defines index map of OpenGL structures.
|
||||
typedef NCollection_IndexedMap<const OpenGl_Structure*> OpenGl_IndexedMapOfStructure;
|
||||
|
||||
//! Defines array of indexed maps of OpenGL structures.
|
||||
typedef NCollection_Array1<OpenGl_IndexedMapOfStructure> OpenGl_ArrayOfIndexedMapOfStructure;
|
||||
|
||||
//! Presentations list sorted within priorities.
|
||||
class OpenGl_Layer : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(OpenGl_Layer, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Initializes associated priority list and layer properties
|
||||
OpenGl_Layer (const Standard_Integer theNbPriorities,
|
||||
const Handle(Select3D_BVHBuilder3d)& theBuilder);
|
||||
|
||||
//! Destructor.
|
||||
virtual ~OpenGl_Layer();
|
||||
|
||||
//! Returns BVH tree builder for frustom culling.
|
||||
const Handle(Select3D_BVHBuilder3d)& FrustumCullingBVHBuilder() const { return myBVHPrimitivesTrsfPers.Builder(); }
|
||||
|
||||
//! Assigns BVH tree builder for frustom culling.
|
||||
void SetFrustumCullingBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myBVHPrimitivesTrsfPers.SetBuilder (theBuilder); }
|
||||
|
||||
//! Return true if layer was marked with immediate flag.
|
||||
Standard_Boolean IsImmediate() const { return myLayerSettings.IsImmediate(); }
|
||||
|
||||
//! Returns settings of the layer object.
|
||||
const Graphic3d_ZLayerSettings& LayerSettings() const { return myLayerSettings; };
|
||||
|
||||
//! Sets settings of the layer object.
|
||||
void SetLayerSettings (const Graphic3d_ZLayerSettings& theSettings);
|
||||
|
||||
void Add (const OpenGl_Structure* theStruct,
|
||||
const Standard_Integer thePriority,
|
||||
Standard_Boolean isForChangePriority = Standard_False);
|
||||
|
||||
//! Remove structure and returns its priority, if the structure is not found, method returns negative value
|
||||
bool Remove (const OpenGl_Structure* theStruct,
|
||||
Standard_Integer& thePriority,
|
||||
Standard_Boolean isForChangePriority = Standard_False);
|
||||
|
||||
//! @return the number of structures
|
||||
Standard_Integer NbStructures() const { return myNbStructures; }
|
||||
|
||||
//! Number of NOT culled structures in the layer.
|
||||
Standard_Integer NbStructuresNotCulled() const { return myNbStructuresNotCulled; }
|
||||
|
||||
//! Returns the number of available priority levels
|
||||
Standard_Integer NbPriorities() const { return myArray.Length(); }
|
||||
|
||||
//! Append layer of acceptable type (with similar number of priorities or less).
|
||||
//! Returns Standard_False if the list can not be accepted.
|
||||
Standard_Boolean Append (const OpenGl_Layer& theOther);
|
||||
|
||||
//! Returns array of OpenGL structures.
|
||||
const OpenGl_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
|
||||
|
||||
//! Marks BVH tree for given priority list as dirty and
|
||||
//! marks primitive set for rebuild.
|
||||
void InvalidateBVHData();
|
||||
|
||||
//! Marks cached bounding box as obsolete.
|
||||
void InvalidateBoundingBox() const
|
||||
{
|
||||
myIsBoundingBoxNeedsReset[0] = myIsBoundingBoxNeedsReset[1] = true;
|
||||
}
|
||||
|
||||
//! Returns layer bounding box.
|
||||
//! @param theViewId view index to consider View Affinity in structure
|
||||
//! @param theCamera camera definition
|
||||
//! @param theWindowWidth viewport width (for applying transformation-persistence)
|
||||
//! @param theWindowHeight viewport height (for applying transformation-persistence)
|
||||
//! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
|
||||
//! @return computed bounding box
|
||||
Bnd_Box BoundingBox (const Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
const Standard_Integer theWindowWidth,
|
||||
const Standard_Integer theWindowHeight,
|
||||
const Standard_Boolean theToIncludeAuxiliary) const;
|
||||
|
||||
//! Returns zoom-scale factor.
|
||||
Standard_Real considerZoomPersistenceObjects (const Standard_Integer theViewId,
|
||||
const Handle(Graphic3d_Camera)& theCamera,
|
||||
const Standard_Integer theWindowWidth,
|
||||
const Standard_Integer theWindowHeight) const;
|
||||
|
||||
//! Update culling state - should be called before rendering.
|
||||
//! Traverses through BVH tree to determine which structures are in view volume.
|
||||
void UpdateCulling (const Standard_Integer theViewId,
|
||||
const OpenGl_BVHTreeSelector& theSelector,
|
||||
const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState);
|
||||
|
||||
//! Returns TRUE if layer is empty or has been discarded entirely by culling test.
|
||||
bool IsCulled() const { return myNbStructuresNotCulled == 0; }
|
||||
|
||||
// Render all structures.
|
||||
void Render (const Handle(OpenGl_Workspace)& theWorkspace,
|
||||
const OpenGl_GlobalLayerSettings& theDefaultSettings) const;
|
||||
|
||||
//! Returns number of transform persistence objects.
|
||||
Standard_Integer NbOfTransformPersistenceObjects() const
|
||||
{
|
||||
return myBVHPrimitivesTrsfPers.Size();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! Returns set of OpenGl_Structures structures for building BVH tree.
|
||||
const OpenGl_BVHClipPrimitiveSet& CullableStructuresBVH() const { return myBVHPrimitives; }
|
||||
|
||||
//! Returns set of transform persistent OpenGl_Structures for building BVH tree.
|
||||
const OpenGl_BVHClipPrimitiveTrsfPersSet& CullableTrsfPersStructuresBVH() const { return myBVHPrimitivesTrsfPers; }
|
||||
|
||||
//! Returns indexed map of always rendered structures.
|
||||
const NCollection_IndexedMap<const OpenGl_Structure*>& NonCullableStructures() const { return myAlwaysRenderedMap; }
|
||||
|
||||
protected:
|
||||
|
||||
//! Updates BVH trees if their state has been invalidated.
|
||||
Standard_EXPORT void updateBVH() const;
|
||||
|
||||
//! Iterates through the hierarchical list of existing structures and renders them all.
|
||||
Standard_EXPORT void renderAll (const Handle(OpenGl_Workspace)& theWorkspace) const;
|
||||
|
||||
private:
|
||||
|
||||
//! Array of OpenGl_Structures by priority rendered in layer.
|
||||
OpenGl_ArrayOfIndexedMapOfStructure myArray;
|
||||
|
||||
//! Overall number of structures rendered in the layer.
|
||||
Standard_Integer myNbStructures;
|
||||
|
||||
//! Number of NOT culled structures in the layer.
|
||||
Standard_Integer myNbStructuresNotCulled;
|
||||
|
||||
//! Layer setting flags.
|
||||
Graphic3d_ZLayerSettings myLayerSettings;
|
||||
|
||||
//! Set of OpenGl_Structures structures for building BVH tree.
|
||||
mutable OpenGl_BVHClipPrimitiveSet myBVHPrimitives;
|
||||
|
||||
//! Set of transform persistent OpenGl_Structures for building BVH tree.
|
||||
mutable OpenGl_BVHClipPrimitiveTrsfPersSet myBVHPrimitivesTrsfPers;
|
||||
|
||||
//! Indexed map of always rendered structures.
|
||||
mutable NCollection_IndexedMap<const OpenGl_Structure*> myAlwaysRenderedMap;
|
||||
|
||||
//! Is needed for implementation of stochastic order of BVH traverse.
|
||||
Standard_Boolean myBVHIsLeftChildQueuedFirst;
|
||||
|
||||
//! Defines if the primitive set for BVH is outdated.
|
||||
mutable Standard_Boolean myIsBVHPrimitivesNeedsReset;
|
||||
|
||||
//! Defines if the cached bounding box is outdated.
|
||||
mutable bool myIsBoundingBoxNeedsReset[2];
|
||||
|
||||
//! Cached layer bounding box.
|
||||
mutable Bnd_Box myBoundingBox[2];
|
||||
|
||||
};
|
||||
typedef Graphic3d_Layer OpenGl_Layer;
|
||||
|
||||
#endif //_OpenGl_Layer_Header
|
||||
|
@@ -137,6 +137,12 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
struct OpenGl_GlobalLayerSettings
|
||||
{
|
||||
GLint DepthFunc;
|
||||
GLboolean DepthMask;
|
||||
};
|
||||
|
||||
//=======================================================================
|
||||
//function : OpenGl_LayerList
|
||||
//purpose : Constructor
|
||||
@@ -519,7 +525,7 @@ void OpenGl_LayerList::UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspa
|
||||
aTimer.Start();
|
||||
|
||||
const Standard_Integer aViewId = theWorkspace->View()->Identification();
|
||||
const OpenGl_BVHTreeSelector& aSelector = theWorkspace->View()->BVHTreeSelector();
|
||||
const Graphic3d_CullingTool& aSelector = theWorkspace->View()->BVHTreeSelector();
|
||||
for (OpenGl_IndexedLayerIterator anIts (myLayers); anIts.More(); anIts.Next())
|
||||
{
|
||||
OpenGl_Layer& aLayer = *anIts.ChangeValue();
|
||||
@@ -535,6 +541,143 @@ void OpenGl_LayerList::UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspa
|
||||
aStats->ActiveDataFrame()[Graphic3d_FrameStatsTimer_CpuCulling] = aTimer.UserTimeCPU();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : renderLayer
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void OpenGl_LayerList::renderLayer (const Handle(OpenGl_Workspace)& theWorkspace,
|
||||
const OpenGl_GlobalLayerSettings& theDefaultSettings,
|
||||
const Graphic3d_Layer& theLayer) const
|
||||
{
|
||||
const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
|
||||
|
||||
const Graphic3d_ZLayerSettings& aLayerSettings = theLayer.LayerSettings();
|
||||
// aLayerSettings.ToClearDepth() is handled outside
|
||||
|
||||
// handle depth test
|
||||
if (aLayerSettings.ToEnableDepthTest())
|
||||
{
|
||||
// assuming depth test is enabled by default
|
||||
glDepthFunc (theDefaultSettings.DepthFunc);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDepthFunc (GL_ALWAYS);
|
||||
}
|
||||
|
||||
// save environment texture
|
||||
Handle(OpenGl_TextureSet) anEnvironmentTexture = theWorkspace->EnvironmentTexture();
|
||||
if (!aLayerSettings.UseEnvironmentTexture())
|
||||
{
|
||||
theWorkspace->SetEnvironmentTexture (Handle(OpenGl_TextureSet)());
|
||||
}
|
||||
|
||||
// handle depth offset
|
||||
const Graphic3d_PolygonOffset anAppliedOffsetParams = theWorkspace->SetDefaultPolygonOffset (aLayerSettings.PolygonOffset());
|
||||
|
||||
// handle depth write
|
||||
theWorkspace->UseDepthWrite() = aLayerSettings.ToEnableDepthWrite() && theDefaultSettings.DepthMask == GL_TRUE;
|
||||
glDepthMask (theWorkspace->UseDepthWrite() ? GL_TRUE : GL_FALSE);
|
||||
|
||||
const Standard_Boolean hasLocalCS = !aLayerSettings.OriginTransformation().IsNull();
|
||||
const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager();
|
||||
Handle(Graphic3d_LightSet) aLightsBack = aManager->LightSourceState().LightSources();
|
||||
const bool hasOwnLights = aCtx->ColorMask() && !aLayerSettings.Lights().IsNull() && aLayerSettings.Lights() != aLightsBack;
|
||||
if (hasOwnLights)
|
||||
{
|
||||
aLayerSettings.Lights()->UpdateRevision();
|
||||
aManager->UpdateLightSourceStateTo (aLayerSettings.Lights());
|
||||
}
|
||||
|
||||
const Handle(Graphic3d_Camera)& aWorldCamera = theWorkspace->View()->Camera();
|
||||
if (hasLocalCS)
|
||||
{
|
||||
// Apply local camera transformation.
|
||||
// The vertex position is computed by the following formula in GLSL program:
|
||||
// gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
|
||||
// where:
|
||||
// occProjectionMatrix - matrix defining orthographic/perspective/stereographic projection
|
||||
// occWorldViewMatrix - world-view matrix defining Camera position and orientation
|
||||
// occModelWorldMatrix - model-world matrix defining Object transformation from local coordinate system to the world coordinate system
|
||||
// occVertex - input vertex position
|
||||
//
|
||||
// Since double precision is quite expensive on modern GPUs, and not available on old hardware,
|
||||
// all these values are passed with single float precision to the shader.
|
||||
// As result, single precision become insufficient for handling objects far from the world origin.
|
||||
//
|
||||
// Several approaches can be used to solve precision issues:
|
||||
// - [Broute force] migrate to double precision for all matrices and vertex position.
|
||||
// This is too expensive for most hardware.
|
||||
// - Store only translation part with double precision and pass it to GLSL program.
|
||||
// This requires modified GLSL programs for computing transformation
|
||||
// and extra packing mechanism for hardware not supporting double precision natively.
|
||||
// This solution is less expensive then previous one.
|
||||
// - Move translation part of occModelWorldMatrix into occWorldViewMatrix.
|
||||
// The main idea here is that while moving Camera towards the object,
|
||||
// Camera translation part and Object translation part will compensate each other
|
||||
// to fit into single float precision.
|
||||
// But this operation should be performed with double precision - this is why we are moving
|
||||
// translation part of occModelWorldMatrix to occWorldViewMatrix.
|
||||
//
|
||||
// All approaches might be useful in different scenarios, but for the moment we consider the last one as main scenario.
|
||||
// Here we do the trick:
|
||||
// - OpenGl_Layer defines the Local Origin, which is expected to be the center of objects stored within it.
|
||||
// This Local Origin is included into occWorldViewMatrix during rendering.
|
||||
// - OpenGl_Structure defines Object local transformation occModelWorldMatrix with subtracted Local Origin of the Layer.
|
||||
// This means that Object itself should be defined within either Local Transformation equal or near to Local Origin of the Layer.
|
||||
theWorkspace->View()->SetLocalOrigin (aLayerSettings.Origin());
|
||||
|
||||
NCollection_Mat4<Standard_Real> aWorldView = aWorldCamera->OrientationMatrix();
|
||||
Graphic3d_TransformUtils::Translate (aWorldView, aLayerSettings.Origin().X(), aLayerSettings.Origin().Y(), aLayerSettings.Origin().Z());
|
||||
|
||||
NCollection_Mat4<Standard_ShortReal> aWorldViewF;
|
||||
aWorldViewF.ConvertFrom (aWorldView);
|
||||
aCtx->WorldViewState.SetCurrent (aWorldViewF);
|
||||
aCtx->ShaderManager()->UpdateClippingState();
|
||||
aCtx->ShaderManager()->UpdateLightSourceState();
|
||||
}
|
||||
|
||||
// render priority list
|
||||
const Standard_Integer aViewId = theWorkspace->View()->Identification();
|
||||
for (Graphic3d_ArrayOfIndexedMapOfStructure::Iterator aMapIter (theLayer.ArrayOfStructures()); aMapIter.More(); aMapIter.Next())
|
||||
{
|
||||
const Graphic3d_IndexedMapOfStructure& aStructures = aMapIter.Value();
|
||||
for (OpenGl_Structure::StructIterator aStructIter (aStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStruct = aStructIter.Value();
|
||||
if (aStruct->IsCulled()
|
||||
|| !aStruct->IsVisible (aViewId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
aStruct->Render (theWorkspace);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasOwnLights)
|
||||
{
|
||||
aManager->UpdateLightSourceStateTo (aLightsBack);
|
||||
}
|
||||
if (hasLocalCS)
|
||||
{
|
||||
aCtx->ShaderManager()->RevertClippingState();
|
||||
aCtx->ShaderManager()->UpdateLightSourceState();
|
||||
|
||||
aCtx->WorldViewState.SetCurrent (aWorldCamera->OrientationMatrixF());
|
||||
theWorkspace->View() ->SetLocalOrigin (gp_XYZ (0.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
// always restore polygon offset between layers rendering
|
||||
theWorkspace->SetDefaultPolygonOffset (anAppliedOffsetParams);
|
||||
|
||||
// restore environment texture
|
||||
if (!aLayerSettings.UseEnvironmentTexture())
|
||||
{
|
||||
theWorkspace->SetEnvironmentTexture (anEnvironmentTexture);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Render
|
||||
//purpose :
|
||||
@@ -652,7 +795,7 @@ void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
|
||||
// the transparency post-processing stack.
|
||||
theWorkspace->ResetSkippedCounter();
|
||||
|
||||
aLayer.Render (theWorkspace, aDefaultSettings);
|
||||
renderLayer (theWorkspace, aDefaultSettings, aLayer);
|
||||
|
||||
if (aPassIter != 0
|
||||
&& theWorkspace->NbSkippedTransparentElements() > 0)
|
||||
@@ -751,7 +894,7 @@ void OpenGl_LayerList::renderTransparent (const Handle(OpenGl_Workspace)& theW
|
||||
|
||||
for (; theLayerIter != myTransparentToProcess.Back(); ++theLayerIter)
|
||||
{
|
||||
(*theLayerIter)->Render (theWorkspace, aGlobalSettings);
|
||||
renderLayer (theWorkspace, aGlobalSettings, *(*theLayerIter));
|
||||
}
|
||||
|
||||
// Revert state of rendering.
|
||||
|
@@ -19,12 +19,15 @@
|
||||
#include <OpenGl_Layer.hxx>
|
||||
#include <OpenGl_LayerFilter.hxx>
|
||||
|
||||
#include <Graphic3d_ZLayerId.hxx>
|
||||
#include <NCollection_Array1.hxx>
|
||||
#include <NCollection_Handle.hxx>
|
||||
#include <NCollection_Sequence.hxx>
|
||||
#include <NCollection_DataMap.hxx>
|
||||
|
||||
class OpenGl_Structure;
|
||||
class OpenGl_Workspace;
|
||||
struct OpenGl_GlobalLayerSettings;
|
||||
|
||||
typedef NCollection_Sequence<Handle(OpenGl_Layer)> OpenGl_SequenceOfLayers;
|
||||
typedef NCollection_DataMap<int, int> OpenGl_LayerSeqIds;
|
||||
@@ -124,14 +127,14 @@ protected:
|
||||
class OpenGl_LayerStack
|
||||
{
|
||||
public:
|
||||
typedef NCollection_Array1<const OpenGl_Layer*>::iterator iterator;
|
||||
typedef NCollection_Array1<const Graphic3d_Layer*>::iterator iterator;
|
||||
|
||||
//! Reallocate internal buffer of the stack.
|
||||
void Allocate (Standard_Integer theSize)
|
||||
{
|
||||
if (theSize > 0)
|
||||
{
|
||||
myStackSpace = new NCollection_Array1<const OpenGl_Layer*> (1, theSize);
|
||||
myStackSpace = new NCollection_Array1<const Graphic3d_Layer*> (1, theSize);
|
||||
myStackSpace->Init (NULL);
|
||||
myBackPtr = myStackSpace->begin();
|
||||
}
|
||||
@@ -185,6 +188,11 @@ protected:
|
||||
OpenGl_FrameBuffer* theReadDrawFbo,
|
||||
OpenGl_FrameBuffer* theOitAccumFbo) const;
|
||||
|
||||
// Render structures within specified layer.
|
||||
void renderLayer (const Handle(OpenGl_Workspace)& theWorkspace,
|
||||
const OpenGl_GlobalLayerSettings& theDefaultSettings,
|
||||
const Graphic3d_Layer& theLayer) const;
|
||||
|
||||
protected:
|
||||
|
||||
// number of structures temporary put to default layer
|
||||
|
@@ -107,7 +107,6 @@ OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& th
|
||||
myInstancedStructure (NULL),
|
||||
myIsRaytracable (Standard_False),
|
||||
myModificationState (0),
|
||||
myIsCulled (Standard_True),
|
||||
myIsMirrored (Standard_False)
|
||||
{
|
||||
updateLayerTransformation();
|
||||
|
@@ -29,33 +29,23 @@
|
||||
|
||||
#include <NCollection_List.hxx>
|
||||
|
||||
class OpenGl_Structure;
|
||||
class OpenGl_GraphicDriver;
|
||||
|
||||
DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
|
||||
typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
|
||||
|
||||
//! Implementation of low-level graphic structure.
|
||||
class OpenGl_Structure : public Graphic3d_CStructure
|
||||
{
|
||||
friend class OpenGl_Group;
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure)
|
||||
public:
|
||||
|
||||
//! Auxiliary wrapper to iterate OpenGl_Structure sequence.
|
||||
typedef SubclassStructIterator<OpenGl_Structure> StructIterator;
|
||||
|
||||
//! Auxiliary wrapper to iterate OpenGl_Group sequence.
|
||||
class GroupIterator
|
||||
{
|
||||
|
||||
public:
|
||||
GroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
|
||||
Standard_Boolean More() const { return myIter.More(); }
|
||||
void Next() { myIter.Next(); }
|
||||
const OpenGl_Group* Value() const { return (const OpenGl_Group* )(myIter.Value().operator->()); }
|
||||
OpenGl_Group* ChangeValue() { return (OpenGl_Group* )(myIter.ChangeValue().operator->()); }
|
||||
|
||||
private:
|
||||
Graphic3d_SequenceOfGroup::Iterator myIter;
|
||||
|
||||
};
|
||||
typedef SubclassGroupIterator<OpenGl_Group> GroupIterator;
|
||||
|
||||
public:
|
||||
|
||||
@@ -115,28 +105,6 @@ public:
|
||||
//! Releases structure resources.
|
||||
virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
|
||||
|
||||
//! Marks structure as culled/not culled - note that IsAlwaysRendered() is ignored here!
|
||||
void SetCulled (Standard_Boolean theIsCulled) const { myIsCulled = theIsCulled; }
|
||||
|
||||
//! Marks structure as overlapping the current view volume one.
|
||||
//! The method is called during traverse of BVH tree.
|
||||
void MarkAsNotCulled() const { myIsCulled = Standard_False; }
|
||||
|
||||
//! Returns Standard_False if the structure hits the current view volume, otherwise
|
||||
//! returns Standard_True. The default value for all structures before each traverse
|
||||
//! of BVH tree is Standard_True.
|
||||
Standard_Boolean IsCulled() const { return myIsCulled; }
|
||||
|
||||
//! Checks if the structure should be included into BVH tree or not.
|
||||
Standard_Boolean IsAlwaysRendered() const
|
||||
{
|
||||
return IsInfinite
|
||||
|| IsForHighlight
|
||||
|| IsMutable
|
||||
|| Is2dText
|
||||
|| (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d());
|
||||
}
|
||||
|
||||
//! This method releases GL resources without actual elements destruction.
|
||||
//! As result structure could be correctly destroyed layer without GL context
|
||||
//! (after last window was closed for example).
|
||||
@@ -158,7 +126,7 @@ public:
|
||||
Standard_Boolean IsRaytracable() const;
|
||||
|
||||
//! Update render transformation matrix.
|
||||
Standard_EXPORT void updateLayerTransformation();
|
||||
Standard_EXPORT virtual void updateLayerTransformation() Standard_OVERRIDE;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -184,16 +152,8 @@ protected:
|
||||
mutable Standard_Boolean myIsRaytracable;
|
||||
mutable Standard_Size myModificationState;
|
||||
|
||||
mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
|
||||
|
||||
Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
|
||||
|
||||
public:
|
||||
|
||||
DEFINE_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure) // Type definition
|
||||
|
||||
};
|
||||
|
||||
DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
|
||||
|
||||
#endif // OpenGl_Structure_Header
|
||||
|
@@ -51,8 +51,6 @@ OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
|
||||
myCaps (theCaps),
|
||||
myWasRedrawnGL (Standard_False),
|
||||
myBackfacing (Graphic3d_TOBM_AUTOMATIC),
|
||||
myBgColor (Quantity_NOC_BLACK),
|
||||
myCamera (new Graphic3d_Camera()),
|
||||
myToShowGradTrihedron (false),
|
||||
myZLayers (Structure_MAX_PRIORITY - Structure_MIN_PRIORITY + 1),
|
||||
myStateCounter (theCounter),
|
||||
@@ -192,15 +190,6 @@ void OpenGl_View::Remove()
|
||||
Graphic3d_CView::Remove();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetTextureEnv
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_View::SetCamera(const Handle(Graphic3d_Camera)& theCamera)
|
||||
{
|
||||
myCamera = theCamera;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetLocalOrigin
|
||||
// purpose :
|
||||
@@ -420,24 +409,6 @@ Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3
|
||||
#endif
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Background
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_Background OpenGl_View::Background() const
|
||||
{
|
||||
return Aspect_Background (myBgColor.GetRGB());
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetBackground
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OpenGl_View::SetBackground (const Aspect_Background& theBackground)
|
||||
{
|
||||
myBgColor.SetRGB (theBackground.Color());
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GradientBackground
|
||||
// purpose :
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include <Aspect_GradientFillMethod.hxx>
|
||||
|
||||
#include <Graphic3d_CView.hxx>
|
||||
#include <Graphic3d_CullingTool.hxx>
|
||||
#include <Graphic3d_GraduatedTrihedron.hxx>
|
||||
#include <Graphic3d_SequenceOfHClipPlane.hxx>
|
||||
#include <Graphic3d_ToneMappingMethod.hxx>
|
||||
@@ -37,7 +38,6 @@
|
||||
|
||||
#include <OpenGl_Aspects.hxx>
|
||||
#include <OpenGl_BackgroundArray.hxx>
|
||||
#include <OpenGl_BVHTreeSelector.hxx>
|
||||
#include <OpenGl_Context.hxx>
|
||||
#include <OpenGl_FrameBuffer.hxx>
|
||||
#include <OpenGl_FrameStatsPrs.hxx>
|
||||
@@ -127,21 +127,6 @@ public:
|
||||
//! Return true if view content cache has been invalidated.
|
||||
virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
|
||||
|
||||
//! Returns data of a graduated trihedron
|
||||
const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() Standard_OVERRIDE
|
||||
{ return myGTrihedronData; }
|
||||
|
||||
//! Displays Graduated Trihedron.
|
||||
Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
|
||||
|
||||
//! Erases Graduated Trihedron.
|
||||
Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
|
||||
|
||||
//! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
|
||||
//! @param theMin [in] the minimum point of scene.
|
||||
//! @param theMax [in] the maximum point of scene.
|
||||
Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
|
||||
|
||||
//! Dump active rendering buffer into specified memory buffer.
|
||||
//! In Ray-Tracing allow to get a raw HDR buffer using Graphic3d_BT_RGB_RayTraceHdrLeft buffer type,
|
||||
//! only Left view will be dumped ignoring stereoscopic parameter.
|
||||
@@ -211,12 +196,6 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
//! Returns background fill color.
|
||||
Standard_EXPORT virtual Aspect_Background Background() const Standard_OVERRIDE;
|
||||
|
||||
//! Sets background fill color.
|
||||
Standard_EXPORT virtual void SetBackground (const Aspect_Background& theBackground) Standard_OVERRIDE;
|
||||
|
||||
//! Returns gradient background fill colors.
|
||||
Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE;
|
||||
|
||||
@@ -247,18 +226,12 @@ public:
|
||||
//! Sets backfacing model for the view.
|
||||
virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; }
|
||||
|
||||
//! Returns camera object of the view.
|
||||
virtual const Handle(Graphic3d_Camera)& Camera() const Standard_OVERRIDE { return myCamera; }
|
||||
|
||||
//! Returns local camera origin currently set for rendering, might be modified during rendering.
|
||||
const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
|
||||
|
||||
//! Setup local camera origin currently set for rendering.
|
||||
Standard_EXPORT void SetLocalOrigin (const gp_XYZ& theOrigin);
|
||||
|
||||
//! Sets camera used by the view.
|
||||
Standard_EXPORT virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) Standard_OVERRIDE;
|
||||
|
||||
//! Returns list of lights of the view.
|
||||
virtual const Handle(Graphic3d_LightSet)& Lights() const Standard_OVERRIDE { return myLights; }
|
||||
|
||||
@@ -319,7 +292,7 @@ public:
|
||||
|
||||
//! Returns selector for BVH tree, providing a possibility to store information
|
||||
//! about current view volume and to detect which objects are overlapping it.
|
||||
const OpenGl_BVHTreeSelector& BVHTreeSelector() const { return myBVHSelector; }
|
||||
const Graphic3d_CullingTool& BVHTreeSelector() const { return myBVHSelector; }
|
||||
|
||||
//! Returns true if there are immediate structures to display
|
||||
bool HasImmediateStructures() const
|
||||
@@ -327,6 +300,19 @@ public:
|
||||
return myZLayers.NbImmediateStructures() != 0;
|
||||
}
|
||||
|
||||
public: //! @name obsolete Graduated Trihedron functionality
|
||||
|
||||
//! Displays Graduated Trihedron.
|
||||
Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
|
||||
|
||||
//! Erases Graduated Trihedron.
|
||||
Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
|
||||
|
||||
//! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
|
||||
//! @param theMin [in] the minimum point of scene.
|
||||
//! @param theMax [in] the maximum point of scene.
|
||||
Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
|
||||
|
||||
protected: //! @name Internal methods for managing GL resources
|
||||
|
||||
//! Initializes OpenGl resource for environment texture.
|
||||
@@ -458,9 +444,7 @@ protected:
|
||||
Standard_Boolean myWasRedrawnGL;
|
||||
|
||||
Graphic3d_TypeOfBackfacingModel myBackfacing;
|
||||
Quantity_ColorRGBA myBgColor;
|
||||
Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
|
||||
Handle(Graphic3d_Camera) myCamera;
|
||||
gp_XYZ myLocalOrigin;
|
||||
Handle(OpenGl_FrameBuffer) myFBO;
|
||||
Standard_Boolean myToShowGradTrihedron;
|
||||
@@ -484,7 +468,7 @@ protected:
|
||||
StateInfo myLastLightSourceState;
|
||||
|
||||
//! Is needed for selection of overlapping objects and storage of the current view volume
|
||||
OpenGl_BVHTreeSelector myBVHSelector;
|
||||
Graphic3d_CullingTool myBVHSelector;
|
||||
|
||||
OpenGl_GraduatedTrihedron myGraduatedTrihedron;
|
||||
OpenGl_FrameStatsPrs myFrameStatsPrs;
|
||||
@@ -678,6 +662,9 @@ protected: //! @name data types related to ray-tracing
|
||||
//! Actual ray-tracing depth (number of ray bounces).
|
||||
Standard_Integer NbBounces;
|
||||
|
||||
//! Define depth computation
|
||||
Standard_Boolean IsZeroToOneDepth;
|
||||
|
||||
//! Enables/disables light propagation through transparent media.
|
||||
Standard_Boolean TransparentShadows;
|
||||
|
||||
@@ -712,6 +699,7 @@ protected: //! @name data types related to ray-tracing
|
||||
RaytracingParams()
|
||||
: StackSize (THE_DEFAULT_STACK_SIZE),
|
||||
NbBounces (THE_DEFAULT_NB_BOUNCES),
|
||||
IsZeroToOneDepth (Standard_False),
|
||||
TransparentShadows (Standard_False),
|
||||
GlobalIllumination (Standard_False),
|
||||
UseBindlessTextures (Standard_False),
|
||||
|
@@ -111,11 +111,11 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode
|
||||
|
||||
if (aLayer.NbStructures() != 0)
|
||||
{
|
||||
const OpenGl_ArrayOfIndexedMapOfStructure& aStructArray = aLayer.ArrayOfStructures();
|
||||
const Graphic3d_ArrayOfIndexedMapOfStructure& aStructArray = aLayer.ArrayOfStructures();
|
||||
|
||||
for (Standard_Integer anIndex = 0; anIndex < aStructArray.Length(); ++anIndex)
|
||||
{
|
||||
for (OpenGl_IndexedMapOfStructure::Iterator aStructIt (aStructArray (anIndex)); aStructIt.More(); aStructIt.Next())
|
||||
for (OpenGl_Structure::StructIterator aStructIt (aStructArray.Value (anIndex)); aStructIt.More(); aStructIt.Next())
|
||||
{
|
||||
const OpenGl_Structure* aStructure = aStructIt.Value();
|
||||
|
||||
@@ -1115,6 +1115,11 @@ TCollection_AsciiString OpenGl_View::generateShaderPrefix (const Handle(OpenGl_C
|
||||
TCollection_AsciiString ("#define STACK_SIZE ") + TCollection_AsciiString (myRaytraceParameters.StackSize) + "\n" +
|
||||
TCollection_AsciiString ("#define NB_BOUNCES ") + TCollection_AsciiString (myRaytraceParameters.NbBounces);
|
||||
|
||||
if (myRaytraceParameters.IsZeroToOneDepth)
|
||||
{
|
||||
aPrefixString += TCollection_AsciiString ("\n#define ZERO_TO_ONE_DEPTH");
|
||||
}
|
||||
|
||||
if (myRaytraceParameters.TransparentShadows)
|
||||
{
|
||||
aPrefixString += TCollection_AsciiString ("\n#define TRANSPARENT_SHADOWS");
|
||||
@@ -1377,12 +1382,16 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theS
|
||||
}
|
||||
}
|
||||
|
||||
if (myRenderParams.RaytracingDepth != myRaytraceParameters.NbBounces
|
||||
const bool isZeroToOneDepth = myCaps->useZeroToOneDepth
|
||||
&& myWorkspace->GetGlContext()->arbClipControl;
|
||||
if (isZeroToOneDepth != myRaytraceParameters.IsZeroToOneDepth
|
||||
|| myRenderParams.RaytracingDepth != myRaytraceParameters.NbBounces
|
||||
|| myRenderParams.IsTransparentShadowEnabled != myRaytraceParameters.TransparentShadows
|
||||
|| myRenderParams.IsGlobalIlluminationEnabled != myRaytraceParameters.GlobalIllumination
|
||||
|| myRenderParams.TwoSidedBsdfModels != myRaytraceParameters.TwoSidedBsdfModels
|
||||
|| myRaytraceGeometry.HasTextures() != myRaytraceParameters.UseBindlessTextures)
|
||||
{
|
||||
myRaytraceParameters.IsZeroToOneDepth = isZeroToOneDepth;
|
||||
myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth;
|
||||
myRaytraceParameters.TransparentShadows = myRenderParams.IsTransparentShadowEnabled;
|
||||
myRaytraceParameters.GlobalIllumination = myRenderParams.IsGlobalIlluminationEnabled;
|
||||
|
@@ -168,6 +168,17 @@ void OpenGl_View::Redraw()
|
||||
aCtx->FrameStats()->FrameStart (myWorkspace->View(), false);
|
||||
aCtx->SetLineFeather (myRenderParams.LineFeather);
|
||||
|
||||
#if !defined(GL_ES_VERSION_2_0)
|
||||
if (aCtx->arbClipControl)
|
||||
{
|
||||
if (myCaps->useZeroToOneDepth != myCamera->IsZeroToOneDepth())
|
||||
{
|
||||
myCamera->SetZeroToOneDepth (myCaps->useZeroToOneDepth);
|
||||
}
|
||||
aCtx->Functions()->glClipControl (GL_LOWER_LEFT, myCamera->IsZeroToOneDepth() ? GL_ZERO_TO_ONE : GL_NEGATIVE_ONE_TO_ONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
// release pending GL resources
|
||||
aCtx->ReleaseDelayed();
|
||||
|
||||
|
@@ -180,6 +180,7 @@ static NCollection_Vec4<Standard_Real> safePointCast (const gp_Pnt& thePnt)
|
||||
//=======================================================================
|
||||
gp_Pnt SelectMgr_FrustumBuilder::unProject (const gp_Pnt& thePnt) const
|
||||
{
|
||||
/// TODO why these are not cached?
|
||||
Graphic3d_Mat4d aInvView;
|
||||
Graphic3d_Mat4d aInvProj;
|
||||
|
||||
@@ -217,6 +218,7 @@ gp_Pnt SelectMgr_FrustumBuilder::ProjectPntOnViewPlane (const Standard_Real& the
|
||||
{
|
||||
aX = 2.0 * theX / myWidth - 1.0;
|
||||
anY = (myHeight - 1 - theY) / myHeight * 2.0 - 1.0;
|
||||
/// TODO wrong NDC
|
||||
aZ = 2.0 * theZ - 1.0;
|
||||
}
|
||||
else
|
||||
|
@@ -804,7 +804,11 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
|
||||
vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);
|
||||
|
||||
float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);
|
||||
#ifdef ZERO_TO_ONE_DEPTH
|
||||
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);
|
||||
#else
|
||||
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;
|
||||
#endif
|
||||
}
|
||||
|
||||
SBSDF aBSDF;
|
||||
|
@@ -1012,7 +1012,11 @@ vec4 Radiance (in SRay theRay, in vec3 theInverse)
|
||||
vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);
|
||||
|
||||
float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);
|
||||
#ifdef ZERO_TO_ONE_DEPTH
|
||||
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);
|
||||
#else
|
||||
aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 aNormal = SmoothNormal (aHit.UV, aTriIndex);
|
||||
|
@@ -807,7 +807,11 @@ static const char Shaders_PathtraceBase_fs[] =
|
||||
" vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);\n"
|
||||
"\n"
|
||||
" float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);\n"
|
||||
" #ifdef ZERO_TO_ONE_DEPTH\n"
|
||||
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);\n"
|
||||
" #else\n"
|
||||
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;\n"
|
||||
" #endif\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" SBSDF aBSDF;\n"
|
||||
|
@@ -1015,7 +1015,11 @@ static const char Shaders_RaytraceBase_fs[] =
|
||||
" vec4 aNDCPoint = uViewMat * vec4 (theRay.Origin, 1.f);\n"
|
||||
"\n"
|
||||
" float aPolygonOffset = PolygonOffset (aHit.Normal, theRay.Origin);\n"
|
||||
" #ifdef ZERO_TO_ONE_DEPTH\n"
|
||||
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE);\n"
|
||||
" #else\n"
|
||||
" aRaytraceDepth = (aNDCPoint.z / aNDCPoint.w + aPolygonOffset * POLYGON_OFFSET_SCALE) * 0.5f + 0.5f;\n"
|
||||
" #endif\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" vec3 aNormal = SmoothNormal (aHit.UV, aTriIndex);\n"
|
||||
|
@@ -18,6 +18,7 @@ TKMesh
|
||||
TKV3d
|
||||
TKDraw
|
||||
TKOpenGl
|
||||
TKVulkan
|
||||
CSF_TclLibs
|
||||
CSF_TclTkLibs
|
||||
CSF_XwLibs
|
||||
|
3
src/TKVulkan/CMakeLists.txt
Normal file
3
src/TKVulkan/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
project(TKVulkan)
|
||||
|
||||
OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)
|
13
src/TKVulkan/EXTERNLIB
Normal file
13
src/TKVulkan/EXTERNLIB
Normal file
@@ -0,0 +1,13 @@
|
||||
TKernel
|
||||
TKService
|
||||
TKMath
|
||||
TKV3d
|
||||
CSF_TBB
|
||||
CSF_FREETYPE
|
||||
CSF_vulkan
|
||||
CSF_user32
|
||||
CSF_gdi32
|
||||
CSF_XwLibs
|
||||
CSF_Appkit
|
||||
CSF_IOKit
|
||||
CSF_objc
|
2
src/TKVulkan/FILES
Normal file
2
src/TKVulkan/FILES
Normal file
@@ -0,0 +1,2 @@
|
||||
EXTERNLIB
|
||||
PACKAGES
|
1
src/TKVulkan/PACKAGES
Normal file
1
src/TKVulkan/PACKAGES
Normal file
@@ -0,0 +1 @@
|
||||
Vulkan
|
@@ -83,6 +83,9 @@
|
||||
#include <Prs3d_Text.hxx>
|
||||
#include <Select3D_SensitivePrimitiveArray.hxx>
|
||||
|
||||
#include <Vulkan_Caps.hxx>
|
||||
#include <Vulkan_GraphicDriver.hxx>
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef DrawText
|
||||
#endif
|
||||
@@ -718,7 +721,7 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
|
||||
theViewToClone->Window()->Size (aPxWidth, aPxHeight);
|
||||
}
|
||||
|
||||
Handle(OpenGl_GraphicDriver) aGraphicDriver;
|
||||
Handle(Graphic3d_GraphicDriver) aGraphicDriver;
|
||||
ViewerTest_Names aViewNames(theViewName);
|
||||
if (ViewerTest_myViews.IsBound1 (aViewNames.GetViewName ()))
|
||||
aViewNames.SetViewName (aViewNames.GetViewerName() + "/" + CreateName<Handle(V3d_View)>(ViewerTest_myViews, "View"));
|
||||
@@ -765,15 +768,29 @@ TCollection_AsciiString ViewerTest::ViewerInit (const Standard_Integer thePxLeft
|
||||
// alternatively we can disable buffer swap at all, but this might be inappropriate for testing
|
||||
//ViewerTest_myDefaultCaps.buffersNoSwap = true;
|
||||
}
|
||||
aGraphicDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
|
||||
aGraphicDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
|
||||
|
||||
if (theDisplayName == "vulkan")
|
||||
{
|
||||
/// TODO
|
||||
const uint32_t anAppVer = Vulkan_GraphicDriver::DefineVersion (OCC_VERSION_MAJOR, OCC_VERSION_MINOR, OCC_VERSION_MAINTENANCE);
|
||||
Handle(Vulkan_GraphicDriver) aVkDriver = new Vulkan_GraphicDriver ("Draw Harness", anAppVer, GetDisplayConnection());
|
||||
aVkDriver->Options()->contextDebug = true;
|
||||
//aVkDriver->Options()->contextDebug = ViewerTest_myDefaultCaps.contextDebug;
|
||||
aGraphicDriver = aVkDriver;
|
||||
}
|
||||
else
|
||||
{
|
||||
Handle(OpenGl_GraphicDriver) aGlDriver = new OpenGl_GraphicDriver (GetDisplayConnection());
|
||||
aGlDriver->ChangeOptions() = ViewerTest_myDefaultCaps;
|
||||
aGraphicDriver = aGlDriver;
|
||||
}
|
||||
|
||||
ViewerTest_myDrivers.Bind (aViewNames.GetDriverName(), aGraphicDriver);
|
||||
toCreateViewer = Standard_True;
|
||||
}
|
||||
else
|
||||
{
|
||||
aGraphicDriver = Handle(OpenGl_GraphicDriver)::DownCast (ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName()));
|
||||
aGraphicDriver = ViewerTest_myDrivers.Find1 (aViewNames.GetDriverName());
|
||||
}
|
||||
|
||||
//Dispose the window if input parameters are default
|
||||
@@ -1108,7 +1125,7 @@ static int VInit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const cha
|
||||
#if defined(_WIN32) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
|
||||
if (!aDisplayName.IsEmpty())
|
||||
{
|
||||
aDisplayName.Clear();
|
||||
////aDisplayName.Clear();
|
||||
std::cout << "Warning: display parameter will be ignored.\n";
|
||||
}
|
||||
#endif
|
||||
@@ -6250,6 +6267,7 @@ static int VCaps (Draw_Interpretor& theDI,
|
||||
theDI << "SoftMode:" << (aCaps->contextNoAccel ? "1" : "0") << "\n";
|
||||
theDI << "FFP: " << (aCaps->ffpEnable ? "1" : "0") << "\n";
|
||||
theDI << "PolygonMode: " << (aCaps->usePolygonMode ? "1" : "0") << "\n";
|
||||
theDI << "DepthZeroToOne: " << (aCaps->useZeroToOneDepth ? "1" : "0") << "\n";
|
||||
theDI << "VSync: " << aCaps->swapInterval << "\n";
|
||||
theDI << "Compatible:" << (aCaps->contextCompatible ? "1" : "0") << "\n";
|
||||
theDI << "Stereo: " << (aCaps->contextStereo ? "1" : "0") << "\n";
|
||||
@@ -6319,6 +6337,19 @@ static int VCaps (Draw_Interpretor& theDI,
|
||||
}
|
||||
aCaps->pntSpritesDisable = !toEnable;
|
||||
}
|
||||
else if (anArgCase == "-depthzerotoone"
|
||||
|| anArgCase == "-zerotoonedepth"
|
||||
|| anArgCase == "-usezerotoonedepth"
|
||||
|| anArgCase == "-iszerotoonedepth")
|
||||
{
|
||||
Standard_Boolean toEnable = Standard_True;
|
||||
if (++anArgIter < theArgNb
|
||||
&& !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
|
||||
{
|
||||
--anArgIter;
|
||||
}
|
||||
aCaps->useZeroToOneDepth = toEnable;
|
||||
}
|
||||
else if (anArgCase == "-softmode")
|
||||
{
|
||||
Standard_Boolean toEnable = Standard_True;
|
||||
@@ -12696,6 +12727,23 @@ static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
|
||||
return 0;
|
||||
}
|
||||
|
||||
//===============================================================================================
|
||||
//function : VkInit
|
||||
//purpose :
|
||||
//===============================================================================================
|
||||
static int VkInit (Draw_Interpretor& ,
|
||||
Standard_Integer theArgsNb,
|
||||
const char** theArgVec)
|
||||
{
|
||||
(void )theArgsNb;
|
||||
(void )theArgVec;
|
||||
Handle(Aspect_DisplayConnection) aDisp = new Aspect_DisplayConnection();
|
||||
const uint32_t anAppVer = Vulkan_GraphicDriver::DefineVersion (OCC_VERSION_MAJOR, OCC_VERSION_MINOR, OCC_VERSION_MAINTENANCE);
|
||||
Handle(Vulkan_GraphicDriver) aDriver = new Vulkan_GraphicDriver ("Draw Harness", anAppVer, aDisp);
|
||||
aDriver->InitContext();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ViewerCommands
|
||||
//purpose :
|
||||
@@ -12705,6 +12753,9 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
|
||||
{
|
||||
|
||||
const char *group = "ZeViewer";
|
||||
|
||||
theCommands.Add("vkinit", "vkinit", __FILE__,VkInit,group); ///
|
||||
|
||||
theCommands.Add("vinit",
|
||||
"vinit [-name viewName] [-left leftPx] [-top topPx] [-width widthPx] [-height heightPx]"
|
||||
"\n\t\t: [-exitOnClose] [-closeOnEscape] [-cloneActive] [-2d_mode {on|off}=off]"
|
||||
@@ -12993,6 +13044,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
|
||||
__FILE__, VStereo, group);
|
||||
theCommands.Add ("vcaps",
|
||||
"vcaps [-vbo {0|1}] [-sprites {0|1}] [-ffp {0|1}] [-polygonMode {0|1}]"
|
||||
"\n\t\t: [-zeroToOneDepth {0|1}]"
|
||||
"\n\t\t: [-compatibleProfile {0|1}]"
|
||||
"\n\t\t: [-vsync {0|1}] [-useWinBuffer {0|1}]"
|
||||
"\n\t\t: [-quadBuffer {0|1}] [-stereo {0|1}]"
|
||||
@@ -13007,6 +13059,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
|
||||
"\n\t\t: sprite - use textured sprites instead of bitmaps"
|
||||
"\n\t\t: vsync - switch VSync on or off"
|
||||
"\n\t\t: winBuffer - allow using window buffer for rendering"
|
||||
"\n\t\t: zeroToOneDepth - use [0,1] depth range instead of [-1,1] range"
|
||||
"\n\t\t: Context creation options:"
|
||||
"\n\t\t: softMode - software OpenGL implementation"
|
||||
"\n\t\t: compatibleProfile - backward-compatible profile"
|
||||
|
57
src/Vulkan/FILES
Normal file
57
src/Vulkan/FILES
Normal file
@@ -0,0 +1,57 @@
|
||||
Vulkan_Buffer.cxx
|
||||
Vulkan_Buffer.hxx
|
||||
Vulkan_Caps.cxx
|
||||
Vulkan_Caps.hxx
|
||||
Vulkan_CommandBuffer.cxx
|
||||
Vulkan_CommandBuffer.hxx
|
||||
Vulkan_CommandPool.cxx
|
||||
Vulkan_CommandPool.hxx
|
||||
Vulkan_Context.cxx
|
||||
Vulkan_Context.hxx
|
||||
Vulkan_DescriptorPool.cxx
|
||||
Vulkan_DescriptorPool.hxx
|
||||
Vulkan_DescriptorSetLayout.cxx
|
||||
Vulkan_DescriptorSetLayout.hxx
|
||||
Vulkan_Device.cxx
|
||||
Vulkan_Device.hxx
|
||||
Vulkan_DeviceMemory.cxx
|
||||
Vulkan_DeviceMemory.hxx
|
||||
Vulkan_DeviceMemoryAllocator.cxx
|
||||
Vulkan_DeviceMemoryAllocator.hxx
|
||||
Vulkan_Fence.cxx
|
||||
Vulkan_Fence.hxx
|
||||
Vulkan_FrameBuffer.cxx
|
||||
Vulkan_FrameBuffer.hxx
|
||||
Vulkan_FrameStats.cxx
|
||||
Vulkan_FrameStats.hxx
|
||||
Vulkan_ForwardDecl.hxx
|
||||
Vulkan_GraphicDriver.cxx
|
||||
Vulkan_GraphicDriver.hxx
|
||||
Vulkan_Group.cxx
|
||||
Vulkan_Group.hxx
|
||||
Vulkan_Image.cxx
|
||||
Vulkan_Image.hxx
|
||||
Vulkan_Object.cxx
|
||||
Vulkan_Object.hxx
|
||||
Vulkan_Pipeline.cxx
|
||||
Vulkan_Pipeline.hxx
|
||||
Vulkan_PipelineCache.cxx
|
||||
Vulkan_PipelineCache.hxx
|
||||
Vulkan_PipelineLayout.cxx
|
||||
Vulkan_PipelineLayout.hxx
|
||||
Vulkan_PrimitiveArray.cxx
|
||||
Vulkan_PrimitiveArray.hxx
|
||||
Vulkan_RenderPass.cxx
|
||||
Vulkan_RenderPass.hxx
|
||||
Vulkan_Structure.cxx
|
||||
Vulkan_Structure.hxx
|
||||
Vulkan_StructureShadow.cxx
|
||||
Vulkan_StructureShadow.hxx
|
||||
Vulkan_Shader.cxx
|
||||
Vulkan_Shader.hxx
|
||||
Vulkan_Surface.cxx
|
||||
Vulkan_Surface.hxx
|
||||
Vulkan_View.cxx
|
||||
Vulkan_View.hxx
|
||||
Vulkan_Window.cxx
|
||||
Vulkan_Window.hxx
|
170
src/Vulkan/Vulkan_Buffer.cxx
Normal file
170
src/Vulkan/Vulkan_Buffer.cxx
Normal file
@@ -0,0 +1,170 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Buffer.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_DeviceMemory.hxx>
|
||||
#include <Vulkan_DeviceMemoryAllocator.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Buffer, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Buffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Buffer::Vulkan_Buffer()
|
||||
: myVkBuffer (NULL),
|
||||
mySize (0)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Buffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Buffer::~Vulkan_Buffer()
|
||||
{
|
||||
releaseBuffer();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Buffer::releaseBuffer()
|
||||
{
|
||||
mySize = 0;
|
||||
if (myVkBuffer != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_Buffer");
|
||||
vkDestroyBuffer (myDevice->Device(), myVkBuffer, myDevice->HostAllocator());
|
||||
myVkBuffer = NULL;
|
||||
}
|
||||
if (!myDevMemory.IsNull())
|
||||
{
|
||||
myDevMemory.Nullify();
|
||||
}
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Buffer::Create (const Handle(Vulkan_Device)& theDevice,
|
||||
Standard_Size theSize,
|
||||
Vulkan_BufferType theType)
|
||||
{
|
||||
if (myVkBuffer != NULL
|
||||
&& mySize == theSize
|
||||
&& myDevice == theDevice)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
|
||||
VkBufferCreateInfo aVkBuffInfo;
|
||||
aVkBuffInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
aVkBuffInfo.pNext = NULL;
|
||||
aVkBuffInfo.flags = 0;
|
||||
aVkBuffInfo.size = theSize;
|
||||
aVkBuffInfo.usage = 0;
|
||||
aVkBuffInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
aVkBuffInfo.queueFamilyIndexCount = 0;
|
||||
aVkBuffInfo.pQueueFamilyIndices = NULL;
|
||||
switch (theType)
|
||||
{
|
||||
case Vulkan_BufferType_Uniform: aVkBuffInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; break;
|
||||
case Vulkan_BufferType_Vertex: aVkBuffInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; break;
|
||||
case Vulkan_BufferType_Index: aVkBuffInfo.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; break;
|
||||
}
|
||||
|
||||
VkResult aRes = vkCreateBuffer (theDevice->Device(), &aVkBuffInfo, theDevice->HostAllocator(), &myVkBuffer);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create buffer", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
mySize = theSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Buffer::init (const Handle(Vulkan_Device)& theDevice,
|
||||
const void* theData,
|
||||
Standard_Size theNbBytes,
|
||||
Vulkan_BufferType theType)
|
||||
{
|
||||
if (!Create (theDevice, theNbBytes, theType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool toAllocMemory = myDevMemory.IsNull();
|
||||
if (toAllocMemory)
|
||||
{
|
||||
VkMemoryRequirements aVkMemReqs = {};
|
||||
vkGetBufferMemoryRequirements (theDevice->Device(), myVkBuffer, &aVkMemReqs);
|
||||
myDevMemory = theDevice->DeviceMemoryAllocator()->Allocate (aVkMemReqs, Vulkan_DeviceMemoryUsage_CpuToGpu);
|
||||
if (myDevMemory.IsNull())
|
||||
{
|
||||
Release();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (theData != NULL)
|
||||
{
|
||||
void* aDataPtr = NULL;
|
||||
const Vulkan_DeviceMemoryInfo aMemInfo = myDevMemory->DeviceMemoryInfo();
|
||||
VkResult aRes = vkMapMemory (theDevice->Device(), aMemInfo.DeviceMemory, aMemInfo.Offset, theNbBytes, 0, &aDataPtr);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to map device memory", aRes);
|
||||
return false;
|
||||
}
|
||||
memcpy (aDataPtr, theData, theNbBytes);
|
||||
vkUnmapMemory (theDevice->Device(), aMemInfo.DeviceMemory);
|
||||
}
|
||||
|
||||
if (toAllocMemory)
|
||||
{
|
||||
const Vulkan_DeviceMemoryInfo aMemInfo = myDevMemory->DeviceMemoryInfo();
|
||||
VkResult aRes = vkBindBufferMemory (theDevice->Device(), myVkBuffer, aMemInfo.DeviceMemory, aMemInfo.Offset);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to bind buffer memory", aRes);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
91
src/Vulkan/Vulkan_Buffer.hxx
Normal file
91
src/Vulkan/Vulkan_Buffer.hxx
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Buffer_HeaderFile
|
||||
#define _Vulkan_Buffer_HeaderFile
|
||||
|
||||
#include <Graphic3d_Vec.hxx>
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
class Vulkan_DeviceMemory;
|
||||
|
||||
enum Vulkan_BufferType
|
||||
{
|
||||
Vulkan_BufferType_Uniform, //!< VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
|
||||
Vulkan_BufferType_Vertex, //!< VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
|
||||
Vulkan_BufferType_Index, //!< VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
|
||||
};
|
||||
|
||||
//! This class defines an Vulkan buffer.
|
||||
class Vulkan_Buffer : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Buffer, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_Buffer();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Buffer();
|
||||
|
||||
//! Return object.
|
||||
VkBuffer Buffer() const { return myVkBuffer; }
|
||||
|
||||
//! Create the object, @sa vkCreateBuffer().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice,
|
||||
Standard_Size theSize,
|
||||
Vulkan_BufferType theType);
|
||||
|
||||
//! Init the object.
|
||||
bool Init (const Handle(Vulkan_Device)& theDevice,
|
||||
const Graphic3d_Vec2* theData,
|
||||
Standard_Size theLen)
|
||||
{
|
||||
const Standard_Size aSize = sizeof(*theData) * theLen;
|
||||
return init (theDevice, theData, aSize, Vulkan_BufferType_Vertex);
|
||||
}
|
||||
|
||||
//! Init the object.
|
||||
bool Init (const Handle(Vulkan_Device)& theDevice,
|
||||
const Graphic3d_Vec3* theData,
|
||||
Standard_Size theLen)
|
||||
{
|
||||
const Standard_Size aSize = sizeof(*theData) * theLen;
|
||||
return init (theDevice, theData, aSize, Vulkan_BufferType_Vertex);
|
||||
}
|
||||
|
||||
//protected:
|
||||
|
||||
//! Init the object.
|
||||
Standard_EXPORT bool init (const Handle(Vulkan_Device)& theDevice,
|
||||
const void* theData,
|
||||
Standard_Size theNbBytes,
|
||||
Vulkan_BufferType theType);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releaseBuffer(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyBuffer().
|
||||
Standard_EXPORT void releaseBuffer();
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_DeviceMemory) myDevMemory;
|
||||
VkBuffer myVkBuffer;
|
||||
Standard_Size mySize;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Buffer_HeaderFile
|
60
src/Vulkan/Vulkan_Caps.cxx
Normal file
60
src/Vulkan/Vulkan_Caps.cxx
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Caps.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Caps, Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Caps
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Caps::Vulkan_Caps()
|
||||
: swapInterval (1),
|
||||
buffersNoSwap (Standard_False),
|
||||
#ifdef OCCT_DEBUG
|
||||
contextDebug (Standard_True),
|
||||
#else
|
||||
contextDebug (Standard_False),
|
||||
#endif
|
||||
contextNoAccel (Standard_False),
|
||||
glslWarnings (Standard_False),
|
||||
suppressExtraMsg (Standard_True)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : operator=
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Caps& Vulkan_Caps::operator= (const Vulkan_Caps& theCopy)
|
||||
{
|
||||
swapInterval = theCopy.swapInterval;
|
||||
buffersNoSwap = theCopy.buffersNoSwap;
|
||||
contextDebug = theCopy.contextDebug;
|
||||
contextNoAccel = theCopy.contextNoAccel;
|
||||
contextDevice = theCopy.contextDevice;
|
||||
glslWarnings = theCopy.glslWarnings;
|
||||
suppressExtraMsg = theCopy.suppressExtraMsg;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Caps
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Caps::~Vulkan_Caps()
|
||||
{
|
||||
//
|
||||
}
|
85
src/Vulkan/Vulkan_Caps.hxx
Normal file
85
src/Vulkan/Vulkan_Caps.hxx
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Caps_HeaderFile
|
||||
#define _Vulkan_Caps_HeaderFile
|
||||
|
||||
#include <Standard_Type.hxx>
|
||||
#include <Standard_Transient.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
//! Class to define graphic driver capabilities.
|
||||
//! Notice that these options will be ignored if particular functionality does not provided by Vulkan driver
|
||||
class Vulkan_Caps : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Caps, Standard_Transient)
|
||||
public: //! @name flags to disable particular functionality, should be used only for testing purposes!
|
||||
|
||||
Standard_Integer swapInterval; //!< controls swap interval - 0 for VSync off and 1 for VSync on, 1 by default
|
||||
|
||||
public: //! @name context creation parameters
|
||||
|
||||
//! Specify that driver should not swap back/front buffers at the end of frame.
|
||||
//! Useful when OCCT Viewer is integrated into existing Vulkan rendering pipeline as part,
|
||||
//! thus swapping part is performed outside.
|
||||
//!
|
||||
//! OFF by default.
|
||||
Standard_Boolean buffersNoSwap;
|
||||
|
||||
//! Request debug Vulkan context. This flag requires support of necessary layers in Vulkan driver.
|
||||
//!
|
||||
//! When turned on Vulkan driver emits error and warning messages to provided callback.
|
||||
//! Affects performance - thus should not be turned on by products in released state.
|
||||
//!
|
||||
//! OFF by default.
|
||||
Standard_Boolean contextDebug;
|
||||
|
||||
//! Disable hardware acceleration.
|
||||
//!
|
||||
//! Flags to intentionally look for VK_PHYSICAL_DEVICE_TYPE_CPU devices.
|
||||
//!
|
||||
//! OFF by default.
|
||||
Standard_Boolean contextNoAccel;
|
||||
|
||||
//! Look for device with specified name.
|
||||
//!
|
||||
//! EMPTY by default.
|
||||
TCollection_AsciiString contextDevice;
|
||||
|
||||
public: //! @name flags to activate verbose output
|
||||
|
||||
//! Print GLSL program compilation/linkage warnings, if any. OFF by default.
|
||||
Standard_Boolean glslWarnings;
|
||||
|
||||
//! Suppress redundant messages from debug Vulkan context. ON by default.
|
||||
Standard_Boolean suppressExtraMsg;
|
||||
|
||||
public: //! @name class methods
|
||||
|
||||
//! Default constructor - initialize with most optimal values.
|
||||
Standard_EXPORT Vulkan_Caps();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Caps();
|
||||
|
||||
//! Copy maker.
|
||||
Standard_EXPORT Vulkan_Caps& operator= (const Vulkan_Caps& theCopy);
|
||||
|
||||
private:
|
||||
|
||||
//! Not implemented
|
||||
Vulkan_Caps (const Vulkan_Caps& );
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Caps_HeaderFile
|
235
src/Vulkan/Vulkan_CommandBuffer.cxx
Normal file
235
src/Vulkan/Vulkan_CommandBuffer.cxx
Normal file
@@ -0,0 +1,235 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_CommandBuffer.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_CommandPool.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_FrameBuffer.hxx>
|
||||
#include <Vulkan_Pipeline.hxx>
|
||||
#include <Vulkan_RenderPass.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_CommandBuffer, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_CommandBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_CommandBuffer::Vulkan_CommandBuffer()
|
||||
: myVkCmdBuffer (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_CommandBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_CommandBuffer::~Vulkan_CommandBuffer()
|
||||
{
|
||||
releaseBuffer();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_CommandBuffer::releaseBuffer()
|
||||
{
|
||||
if (myVkCmdBuffer != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_CommandBuffer");
|
||||
vkFreeCommandBuffers (myDevice->Device(), myCmdPool->CommandPool(), 1, &myVkCmdBuffer);
|
||||
myVkCmdBuffer = NULL;
|
||||
}
|
||||
myCmdPool.Nullify();
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_CommandBuffer::Create (const Handle(Vulkan_CommandPool)& thePool)
|
||||
{
|
||||
if (thePool.IsNull()
|
||||
|| thePool->CommandPool() == NULL)
|
||||
{
|
||||
Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (myVkCmdBuffer != NULL
|
||||
&& myCmdPool == thePool)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Release();
|
||||
myDevice = thePool->Device();
|
||||
myCmdPool = thePool;
|
||||
|
||||
VkCommandBufferAllocateInfo anAllocInfo;
|
||||
anAllocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
anAllocInfo.pNext = NULL;
|
||||
anAllocInfo.commandPool = myCmdPool->CommandPool();
|
||||
anAllocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
anAllocInfo.commandBufferCount = 1;
|
||||
|
||||
VkResult aRes = vkAllocateCommandBuffers (myDevice->Device(), &anAllocInfo, &myVkCmdBuffer);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to allocate command buffers", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
aRes = vkResetCommandBuffer (myVkCmdBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to reset command buffer", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ResetCommandBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_CommandBuffer::ResetCommandBuffer()
|
||||
{
|
||||
if (myVkCmdBuffer == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
VkResult aRes = vkResetCommandBuffer (myVkCmdBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailure ("failed to reset command buffer", aRes);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : BeginCommandBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_CommandBuffer::BeginCommandBuffer (const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_FrameBuffer)& theFrameBuffer)
|
||||
{
|
||||
VkCommandBufferInheritanceInfo anInherInfo;
|
||||
anInherInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
|
||||
anInherInfo.pNext = NULL;
|
||||
anInherInfo.renderPass = theRenderPass->RenderPass();
|
||||
anInherInfo.subpass = 0;
|
||||
anInherInfo.framebuffer = theFrameBuffer->FrameBuffer();
|
||||
anInherInfo.occlusionQueryEnable = VK_FALSE;
|
||||
anInherInfo.queryFlags = 0;
|
||||
anInherInfo.pipelineStatistics = 0;
|
||||
|
||||
VkCommandBufferBeginInfo aBuffBeginInfo;
|
||||
aBuffBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
aBuffBeginInfo.pNext = NULL;
|
||||
aBuffBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
aBuffBeginInfo.pInheritanceInfo = &anInherInfo;
|
||||
|
||||
vkBeginCommandBuffer (myVkCmdBuffer, &aBuffBeginInfo);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : EndCommandBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_CommandBuffer::EndCommandBuffer()
|
||||
{
|
||||
if (myVkCmdBuffer != NULL)
|
||||
{
|
||||
vkEndCommandBuffer (myVkCmdBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : BeginRenderPass
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_CommandBuffer::BeginRenderPass (const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_FrameBuffer)& theFrameBuffer,
|
||||
const Graphic3d_Vec2u& theSize,
|
||||
const Graphic3d_Vec4* theClearColor)
|
||||
{
|
||||
if (myVkCmdBuffer == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t aNbClears = 0;
|
||||
VkClearValue aClearValues[2];
|
||||
if (theClearColor != NULL)
|
||||
{
|
||||
aClearValues[aNbClears].color.float32[0] = theClearColor->r();
|
||||
aClearValues[aNbClears].color.float32[1] = theClearColor->g();
|
||||
aClearValues[aNbClears].color.float32[2] = theClearColor->b();
|
||||
aClearValues[aNbClears].color.float32[3] = theClearColor->a();
|
||||
++aNbClears;
|
||||
}
|
||||
{
|
||||
aClearValues[aNbClears].depthStencil.depth = 1.0f;
|
||||
aClearValues[aNbClears].depthStencil.stencil = 0;
|
||||
++aNbClears;
|
||||
}
|
||||
|
||||
VkRenderPassBeginInfo aPassBeginInfo;
|
||||
aPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
aPassBeginInfo.pNext = NULL;
|
||||
aPassBeginInfo.renderPass = theRenderPass->RenderPass();
|
||||
aPassBeginInfo.framebuffer = theFrameBuffer->FrameBuffer();
|
||||
aPassBeginInfo.renderArea = VkRect2D{
|
||||
VkOffset2D{0, 0},
|
||||
VkExtent2D{theSize.x(), theSize.y()}
|
||||
};
|
||||
aPassBeginInfo.clearValueCount = aNbClears;
|
||||
aPassBeginInfo.pClearValues = aClearValues;
|
||||
|
||||
vkCmdBeginRenderPass (myVkCmdBuffer, &aPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : EndRenderPass
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_CommandBuffer::EndRenderPass()
|
||||
{
|
||||
if (myVkCmdBuffer != NULL)
|
||||
{
|
||||
vkCmdEndRenderPass (myVkCmdBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : BindPipeline
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_CommandBuffer::BindPipeline (const Handle(Vulkan_Pipeline)& thePipeline)
|
||||
{
|
||||
if (myVkCmdBuffer != NULL)
|
||||
{
|
||||
vkCmdBindPipeline (myVkCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, thePipeline->Pipeline());
|
||||
}
|
||||
}
|
80
src/Vulkan/Vulkan_CommandBuffer.hxx
Normal file
80
src/Vulkan/Vulkan_CommandBuffer.hxx
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_CommandBuffer_HeaderFile
|
||||
#define _Vulkan_CommandBuffer_HeaderFile
|
||||
|
||||
#include <Graphic3d_Vec.hxx>
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
class Vulkan_CommandPool;
|
||||
class Vulkan_FrameBuffer;
|
||||
class Vulkan_Pipeline;
|
||||
class Vulkan_RenderPass;
|
||||
|
||||
//! This class defines an Vulkan command buffer.
|
||||
class Vulkan_CommandBuffer : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_CommandBuffer, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_CommandBuffer();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_CommandBuffer();
|
||||
|
||||
//! Return object.
|
||||
const VkCommandBuffer& CommandBuffer() const { return myVkCmdBuffer; }
|
||||
|
||||
//! Create the object, @sa vkAllocateCommandBuffers().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_CommandPool)& thePool);
|
||||
|
||||
//! Reset commands in this buffer, @sa vkResetCommandBuffer().
|
||||
Standard_EXPORT bool ResetCommandBuffer();
|
||||
|
||||
//! Begin writing command buffer, @sa vkBeginCommandBuffer().
|
||||
Standard_EXPORT void BeginCommandBuffer (const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_FrameBuffer)& theFrameBuffer);
|
||||
|
||||
//! End writing command buffer, @sa vkEndCommandBuffer().
|
||||
Standard_EXPORT void EndCommandBuffer();
|
||||
|
||||
//! Begin render pass, @sa vkCmdBeginRenderPass().
|
||||
Standard_EXPORT void BeginRenderPass (const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_FrameBuffer)& theFrameBuffer,
|
||||
const Graphic3d_Vec2u& theSize,
|
||||
const Graphic3d_Vec4* theClearColor);
|
||||
|
||||
//! End render pass, @sa vkCmdEndRenderPass().
|
||||
Standard_EXPORT void EndRenderPass();
|
||||
|
||||
//! Bind the pipeline, @sa vkCmdBindPipeline().
|
||||
Standard_EXPORT void BindPipeline (const Handle(Vulkan_Pipeline)& thePipeline);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releaseBuffer(); }
|
||||
|
||||
//! Release the object, @sa vkFreeCommandBuffers().
|
||||
Standard_EXPORT void releaseBuffer();
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_CommandPool) myCmdPool;
|
||||
VkCommandBuffer myVkCmdBuffer;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_CommandBuffer_HeaderFile
|
132
src/Vulkan/Vulkan_CommandPool.cxx
Normal file
132
src/Vulkan/Vulkan_CommandPool.cxx
Normal file
@@ -0,0 +1,132 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_CommandPool.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_CommandBuffer.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_CommandPool, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_CommandPool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_CommandPool::Vulkan_CommandPool()
|
||||
: myVkCmdPool (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_CommandPool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_CommandPool::~Vulkan_CommandPool()
|
||||
{
|
||||
releasePool();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releasePool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_CommandPool::releasePool()
|
||||
{
|
||||
if (myVkCmdPool != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_CommandPool");
|
||||
vkDestroyCommandPool (myDevice->Device(), myVkCmdPool, myDevice->HostAllocator());
|
||||
myVkCmdPool = NULL;
|
||||
}
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_CommandPool::Create (const Handle(Vulkan_Device)& theDevice)
|
||||
{
|
||||
if (myVkCmdPool != NULL
|
||||
&& myDevice == theDevice)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
|
||||
VkCommandPoolCreateInfo aVkCmdPoolInfo;
|
||||
aVkCmdPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
aVkCmdPoolInfo.pNext = NULL;
|
||||
aVkCmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||
aVkCmdPoolInfo.queueFamilyIndex = 0;
|
||||
|
||||
VkResult aRes = vkCreateCommandPool (theDevice->Device(), &aVkCmdPoolInfo, theDevice->HostAllocator(), &myVkCmdPool);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create command pool", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ResetPool())
|
||||
{
|
||||
Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ResetPool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_CommandPool::ResetPool()
|
||||
{
|
||||
if (myVkCmdPool == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
VkResult aRes = vkResetCommandPool (myDevice->Device(), myVkCmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailure ("failed to reset command pool", aRes);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AllocateBuffers
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Handle(Vulkan_CommandBuffer) Vulkan_CommandPool::AllocateBuffer()
|
||||
{
|
||||
Handle(Vulkan_CommandBuffer) aBuffer = new Vulkan_CommandBuffer();
|
||||
return aBuffer->Create (this)
|
||||
? aBuffer
|
||||
: Handle(Vulkan_CommandBuffer)();
|
||||
}
|
59
src/Vulkan/Vulkan_CommandPool.hxx
Normal file
59
src/Vulkan/Vulkan_CommandPool.hxx
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_CommandPool_HeaderFile
|
||||
#define _Vulkan_CommandPool_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
class Vulkan_CommandBuffer;
|
||||
|
||||
//! This class defines an Vulkan command pool.
|
||||
class Vulkan_CommandPool : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_CommandPool, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_CommandPool();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_CommandPool();
|
||||
|
||||
//! Return object.
|
||||
VkCommandPool CommandPool() const { return myVkCmdPool; }
|
||||
|
||||
//! Create the object, @sa vkCreateCommandPool().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice);
|
||||
|
||||
//! Reset command pool, @sa vkResetCommandPool().
|
||||
Standard_EXPORT bool ResetPool();
|
||||
|
||||
//! Allocate single command buffer from this pool, @sa vkAllocateCommandBuffers().
|
||||
Handle(Vulkan_CommandBuffer) AllocateBuffer();
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releasePool(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyCommandPool().
|
||||
Standard_EXPORT void releasePool();
|
||||
|
||||
protected:
|
||||
|
||||
VkCommandPool myVkCmdPool;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_CommandPool_HeaderFile
|
223
src/Vulkan/Vulkan_Context.cxx
Normal file
223
src/Vulkan/Vulkan_Context.cxx
Normal file
@@ -0,0 +1,223 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Context.hxx>
|
||||
|
||||
#include <Graphic3d_Camera.hxx>
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Buffer.hxx>
|
||||
#include <Vulkan_CommandBuffer.hxx>
|
||||
#include <Vulkan_CommandPool.hxx>
|
||||
#include <Vulkan_DescriptorPool.hxx>
|
||||
#include <Vulkan_DescriptorSetLayout.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_PipelineLayout.hxx>
|
||||
#include <Vulkan_Shader.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Vulkan_ShaderUnlit_vs_spv.pxx"
|
||||
#include "Vulkan_ShaderUnlit_fs_spv.pxx"
|
||||
#include "Vulkan_ShaderPhong_vs_spv.pxx"
|
||||
#include "Vulkan_ShaderPhong_fs_spv.pxx"
|
||||
#include "Vulkan_ShaderFlat_vs_spv.pxx"
|
||||
#include "Vulkan_ShaderFlat_fs_spv.pxx"
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Context, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Context
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Context::Vulkan_Context (const Handle(Vulkan_Device)& theDevice)
|
||||
: myCmdBuffer (NULL)
|
||||
{
|
||||
init (theDevice);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Context
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Context::~Vulkan_Context()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : release
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Context::release()
|
||||
{
|
||||
myCmdBuffer.Nullify();
|
||||
myDescPool.Nullify();
|
||||
myCmdPool.Nullify();
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : init
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Context::init (const Handle(Vulkan_Device)& theDevice)
|
||||
{
|
||||
myDevice = theDevice;
|
||||
myCmdPool = new Vulkan_CommandPool();
|
||||
myCmdPool->Create (theDevice);
|
||||
myDescPool = new Vulkan_DescriptorPool();
|
||||
myDescPool->Create (theDevice);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetCommandBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Context::SetCommandBuffer (const Handle(Vulkan_CommandBuffer)& theBuffer)
|
||||
{
|
||||
myCmdBuffer = theBuffer;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ResetState
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Context::ResetState (const Handle(Graphic3d_Camera)& theCamera)
|
||||
{
|
||||
myCamera = theCamera;
|
||||
myActivePipeline.Nullify();
|
||||
if (!myCmdPool->ResetPool()
|
||||
|| !myDescPool->ResetPool())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ActivatePipeline
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
const Handle(Vulkan_Pipeline)& Vulkan_Context::ActivatePipeline (const Vulkun_PipelineCfg& theCfg)
|
||||
{
|
||||
static Handle(Vulkan_PipelineLayout) aPipeLayout;
|
||||
static Handle(Vulkan_DescriptorSetLayout) aDescSetLayout = new Vulkan_DescriptorSetLayout();
|
||||
static Handle(Vulkan_Buffer) aShaderUniformBuffer;
|
||||
if (aPipeLayout.IsNull())
|
||||
{
|
||||
aDescSetLayout->Create (myDevice);
|
||||
|
||||
aPipeLayout = new Vulkan_PipelineLayout();
|
||||
aPipeLayout->Create (myDevice, aDescSetLayout);
|
||||
|
||||
aShaderUniformBuffer = new Vulkan_Buffer();
|
||||
}
|
||||
|
||||
Standard_Integer anIndex = myPipelineMap.Find (theCfg);
|
||||
if (anIndex == 0)
|
||||
{
|
||||
Handle(Vulkan_Shader) aShaderVert, aShaderFrag;
|
||||
aShaderVert = new Vulkan_Shader();
|
||||
aShaderFrag = new Vulkan_Shader();
|
||||
if (theCfg.ShadingModel == Graphic3d_TOSM_FRAGMENT)
|
||||
{
|
||||
aShaderVert->Create (myDevice, Vulkan_ShaderPhong_vs_spv, sizeof(Vulkan_ShaderPhong_vs_spv));
|
||||
aShaderFrag->Create (myDevice, Vulkan_ShaderPhong_fs_spv, sizeof(Vulkan_ShaderPhong_fs_spv));
|
||||
}
|
||||
else if (theCfg.ShadingModel == Graphic3d_TOSM_FACET)
|
||||
{
|
||||
aShaderVert->Create (myDevice, Vulkan_ShaderFlat_vs_spv, sizeof(Vulkan_ShaderFlat_vs_spv));
|
||||
aShaderFrag->Create (myDevice, Vulkan_ShaderFlat_fs_spv, sizeof(Vulkan_ShaderFlat_fs_spv));
|
||||
}
|
||||
else
|
||||
{
|
||||
aShaderVert->Create (myDevice, Vulkan_ShaderUnlit_vs_spv, sizeof(Vulkan_ShaderUnlit_vs_spv));
|
||||
aShaderFrag->Create (myDevice, Vulkan_ShaderUnlit_fs_spv, sizeof(Vulkan_ShaderUnlit_fs_spv));
|
||||
}
|
||||
|
||||
Handle(Vulkan_Pipeline) aPipeline = new Vulkan_Pipeline();
|
||||
aPipeline->Create (myDevice, myRenderPass, aPipeLayout, aShaderVert, aShaderFrag, Graphic3d_Vec2u (400, 400), theCfg);
|
||||
anIndex = myPipelineMap.Add (aPipeline);
|
||||
}
|
||||
|
||||
const Handle(Vulkan_Pipeline)& aPipeline = myPipelineMap.FindKey (anIndex);
|
||||
if (myActivePipeline == aPipeline)
|
||||
{
|
||||
return myActivePipeline;
|
||||
}
|
||||
|
||||
myActivePipeline = aPipeline;
|
||||
struct UniformsColors
|
||||
{
|
||||
Graphic3d_Mat4 occWorldViewMatrix;
|
||||
Graphic3d_Mat4 occProjectionMatrix;
|
||||
Graphic3d_Mat4 occModelWorldMatrix;
|
||||
Graphic3d_Vec4 uColor;
|
||||
} aUniformsColors;
|
||||
aUniformsColors.occProjectionMatrix = myCamera->ProjectionMatrixF();
|
||||
aUniformsColors.occWorldViewMatrix = myCamera->OrientationMatrixF();
|
||||
if (theCfg.PrimType == Graphic3d_TOPA_SEGMENTS)
|
||||
{
|
||||
aUniformsColors.uColor.SetValues (0.0f, 0.0f, 1.0f, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
aUniformsColors.uColor.SetValues (1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
aShaderUniformBuffer->init (myDevice, &aUniformsColors, sizeof(aUniformsColors), Vulkan_BufferType_Uniform);
|
||||
|
||||
std::vector<VkDescriptorSet> aVkDescriptorSets (1, NULL);
|
||||
{
|
||||
std::vector<VkDescriptorSetLayout> aDescSetLayouts (1, aDescSetLayout->DescriptorSetLayout());
|
||||
VkDescriptorSetAllocateInfo aDescSetAllocInfo = {};
|
||||
aDescSetAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
aDescSetAllocInfo.descriptorPool = myDescPool->DescriptorPool();
|
||||
aDescSetAllocInfo.descriptorSetCount = (uint32_t )aDescSetLayouts.size();
|
||||
aDescSetAllocInfo.pSetLayouts = aDescSetLayouts.data();
|
||||
|
||||
VkResult aRes = vkAllocateDescriptorSets (myDevice->Device(), &aDescSetAllocInfo, aVkDescriptorSets.data());
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailure ("failed to allocate descriptor sets", aRes);
|
||||
static const Handle(Vulkan_Pipeline) aDummy;
|
||||
return aDummy;
|
||||
}
|
||||
|
||||
VkDescriptorBufferInfo aVkDescBuffInfo = {};
|
||||
aVkDescBuffInfo.buffer = aShaderUniformBuffer->Buffer();
|
||||
aVkDescBuffInfo.offset = 0;
|
||||
aVkDescBuffInfo.range = VK_WHOLE_SIZE;
|
||||
|
||||
VkWriteDescriptorSet aVkWriteDescSet = {};
|
||||
aVkWriteDescSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
aVkWriteDescSet.dstSet = aVkDescriptorSets[0];
|
||||
aVkWriteDescSet.dstBinding = 0;
|
||||
aVkWriteDescSet.dstArrayElement = 0;
|
||||
aVkWriteDescSet.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
aVkWriteDescSet.descriptorCount = 1;
|
||||
aVkWriteDescSet.pBufferInfo = &aVkDescBuffInfo;
|
||||
aVkWriteDescSet.pImageInfo = NULL;
|
||||
aVkWriteDescSet.pTexelBufferView = NULL;
|
||||
vkUpdateDescriptorSets (myDevice->Device(), 1, &aVkWriteDescSet, 0, NULL);
|
||||
}
|
||||
|
||||
myCmdBuffer->BindPipeline (aPipeline);
|
||||
vkCmdBindDescriptorSets (myCmdBuffer->CommandBuffer(),
|
||||
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
aPipeline->PipelineLayout()->PipelineLayout(),
|
||||
0, 1, &aVkDescriptorSets[0], 0, NULL);
|
||||
return aPipeline;
|
||||
}
|
117
src/Vulkan/Vulkan_Context.hxx
Normal file
117
src/Vulkan/Vulkan_Context.hxx
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Context_HeaderFile
|
||||
#define _Vulkan_Context_HeaderFile
|
||||
|
||||
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
|
||||
#include <NCollection_IndexedMap.hxx>
|
||||
#include <Vulkan_Object.hxx>
|
||||
#include <Vulkan_Pipeline.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
class Graphic3d_Camera;
|
||||
class Vulkan_CommandBuffer;
|
||||
class Vulkan_CommandPool;
|
||||
class Vulkan_DescriptorPool;
|
||||
|
||||
//! Rendering context for Vulkan.
|
||||
class Vulkan_Context : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Context, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_Context (const Handle(Vulkan_Device)& theDevice);
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Context();
|
||||
|
||||
Standard_EXPORT bool ResetState (const Handle(Graphic3d_Camera)& theCamera);
|
||||
|
||||
//! Return camera.
|
||||
const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
|
||||
|
||||
//! Set camera.
|
||||
void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
|
||||
|
||||
//! Return render pass.
|
||||
const Handle(Vulkan_RenderPass)& RenderPass() const { return myRenderPass; }
|
||||
|
||||
//! Set render pass.
|
||||
void SetRenderPass (const Handle(Vulkan_RenderPass)& theRenderPass) { myRenderPass = theRenderPass; }
|
||||
|
||||
//! Return command pool.
|
||||
const Handle(Vulkan_CommandPool)& CommandPool() const { return myCmdPool; }
|
||||
|
||||
//! Return command buffer.
|
||||
const Handle(Vulkan_CommandBuffer)& CommandBuffer() const { return myCmdBuffer; }
|
||||
|
||||
//! Set command buffer.
|
||||
Standard_EXPORT void SetCommandBuffer (const Handle(Vulkan_CommandBuffer)& theBuffer);
|
||||
|
||||
//! Return descriptor pool.
|
||||
const Handle(Vulkan_DescriptorPool)& DescriptorPool() const { return myDescPool; }
|
||||
|
||||
//! Activate pipeline.
|
||||
Standard_EXPORT const Handle(Vulkan_Pipeline)& ActivatePipeline (const Vulkun_PipelineCfg& theCfg);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE;
|
||||
|
||||
//! Initialize context.
|
||||
Standard_EXPORT void init (const Handle(Vulkan_Device)& theDevice);
|
||||
|
||||
//! Map storing registered fonts.
|
||||
class Vulkan_PipelineMap : public NCollection_IndexedMap<Handle(Vulkan_Pipeline), Vulkan_Pipeline>
|
||||
{
|
||||
public:
|
||||
//! Empty constructor.
|
||||
Vulkan_PipelineMap() {}
|
||||
|
||||
//! Try finding font with specified parameters or the closest one.
|
||||
Standard_Integer Find (const Vulkun_PipelineCfg& theCfg) const
|
||||
{
|
||||
if (IsEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (IndexedMapNode* aNodeIter = (IndexedMapNode* )myData1[Vulkun_PipelineCfg::HashCode (theCfg, NbBuckets())];
|
||||
aNodeIter != NULL; aNodeIter = (IndexedMapNode* )aNodeIter->Next())
|
||||
{
|
||||
const Handle(Vulkan_Pipeline)& aKey = aNodeIter->Key1();
|
||||
if (aKey->Configuration().IsEqual (theCfg))
|
||||
{
|
||||
return aNodeIter->Index();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Graphic3d_Camera) myCamera;
|
||||
Handle(Vulkan_RenderPass) myRenderPass;
|
||||
Handle(Vulkan_CommandPool) myCmdPool;
|
||||
Handle(Vulkan_DescriptorPool) myDescPool;
|
||||
Handle(Vulkan_CommandBuffer) myCmdBuffer;
|
||||
Handle(Vulkan_Pipeline) myActivePipeline;
|
||||
Vulkan_PipelineMap myPipelineMap;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Context_HeaderFile
|
110
src/Vulkan/Vulkan_DescriptorPool.cxx
Normal file
110
src/Vulkan/Vulkan_DescriptorPool.cxx
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_DescriptorPool.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_DescriptorPool, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_DescriptorPool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DescriptorPool::Vulkan_DescriptorPool()
|
||||
: myVkDescPool (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_DescriptorPool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DescriptorPool::~Vulkan_DescriptorPool()
|
||||
{
|
||||
releasePool();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseFence
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_DescriptorPool::releasePool()
|
||||
{
|
||||
if (myVkDescPool != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_DescriptorPool");
|
||||
vkDestroyDescriptorPool (myDevice->Device(), myVkDescPool, myDevice->HostAllocator());
|
||||
myVkDescPool = NULL;
|
||||
}
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_DescriptorPool::Create (const Handle(Vulkan_Device)& theDevice)
|
||||
{
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
|
||||
VkDescriptorPoolSize aVkPoolSize = {};
|
||||
aVkPoolSize.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
aVkPoolSize.descriptorCount = 10;
|
||||
|
||||
VkDescriptorPoolCreateInfo aVkPoolInfo = {};
|
||||
aVkPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
aVkPoolInfo.poolSizeCount = 1;
|
||||
aVkPoolInfo.pPoolSizes = &aVkPoolSize;
|
||||
aVkPoolInfo.maxSets = 10;
|
||||
VkResult aRes = vkCreateDescriptorPool (theDevice->Device(), &aVkPoolInfo, theDevice->HostAllocator(), &myVkDescPool);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create descriptor pool", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ResetPool
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_DescriptorPool::ResetPool()
|
||||
{
|
||||
if (myVkDescPool == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
VkResult aRes = vkResetDescriptorPool (myDevice->Device(), myVkDescPool, 0);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailure ("failed to reset descriptor pool", aRes);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
54
src/Vulkan/Vulkan_DescriptorPool.hxx
Normal file
54
src/Vulkan/Vulkan_DescriptorPool.hxx
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_DescriptorPool_HeaderFile
|
||||
#define _Vulkan_DescriptorPool_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
//! This class defines an Vulkan descriptor pool.
|
||||
class Vulkan_DescriptorPool : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_DescriptorPool, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_DescriptorPool();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_DescriptorPool();
|
||||
|
||||
//! Return object.
|
||||
VkDescriptorPool DescriptorPool() const { return myVkDescPool; }
|
||||
|
||||
//! Create the object, @sa vkCreateDescriptorPool().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice);
|
||||
|
||||
//! Reset the fence, @sa vkResetDescriptorPool().
|
||||
Standard_EXPORT bool ResetPool();
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releasePool(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyDescriptorPool().
|
||||
Standard_EXPORT void releasePool();
|
||||
|
||||
protected:
|
||||
|
||||
VkDescriptorPool myVkDescPool;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_DescriptorPool_HeaderFile
|
93
src/Vulkan/Vulkan_DescriptorSetLayout.cxx
Normal file
93
src/Vulkan/Vulkan_DescriptorSetLayout.cxx
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_DescriptorSetLayout.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_DescriptorSetLayout, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_DescriptorSetLayout
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DescriptorSetLayout::Vulkan_DescriptorSetLayout()
|
||||
: myVkDescSetLayout (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_DescriptorSetLayout
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DescriptorSetLayout::~Vulkan_DescriptorSetLayout()
|
||||
{
|
||||
releaseLayout();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseLayout
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_DescriptorSetLayout::releaseLayout()
|
||||
{
|
||||
if (myVkDescSetLayout != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_DescriptorSetLayout");
|
||||
vkDestroyDescriptorSetLayout (myDevice->Device(), myVkDescSetLayout, myDevice->HostAllocator());
|
||||
myVkDescSetLayout = NULL;
|
||||
}
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_DescriptorSetLayout::Create (const Handle(Vulkan_Device)& theDevice)
|
||||
{
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
|
||||
VkDescriptorSetLayoutBinding aVkDescSetLayoutBinding = {};
|
||||
aVkDescSetLayoutBinding.binding = 0;
|
||||
aVkDescSetLayoutBinding.descriptorCount = 1;
|
||||
aVkDescSetLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
aVkDescSetLayoutBinding.pImmutableSamplers = NULL;
|
||||
aVkDescSetLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
///aVkDescSetLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo aVkDescLayoutInfo = {};
|
||||
aVkDescLayoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
aVkDescLayoutInfo.bindingCount = 1;
|
||||
aVkDescLayoutInfo.pBindings = &aVkDescSetLayoutBinding;
|
||||
VkResult aRes = vkCreateDescriptorSetLayout (theDevice->Device(), &aVkDescLayoutInfo, theDevice->HostAllocator(), &myVkDescSetLayout);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create descriptor set layout", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
51
src/Vulkan/Vulkan_DescriptorSetLayout.hxx
Normal file
51
src/Vulkan/Vulkan_DescriptorSetLayout.hxx
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_DescriptorSetLayout_HeaderFile
|
||||
#define _Vulkan_DescriptorSetLayout_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
//! This class defines an Vulkan descriptor set layout.
|
||||
class Vulkan_DescriptorSetLayout : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_DescriptorSetLayout, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_DescriptorSetLayout();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_DescriptorSetLayout();
|
||||
|
||||
//! Return object.
|
||||
const VkDescriptorSetLayout& DescriptorSetLayout() const { return myVkDescSetLayout; }
|
||||
|
||||
//! Create the object, @sa vkCreateDescriptorSetLayout().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releaseLayout(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyDescriptorSetLayout().
|
||||
Standard_EXPORT void releaseLayout();
|
||||
|
||||
protected:
|
||||
|
||||
VkDescriptorSetLayout myVkDescSetLayout;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_DescriptorSetLayout_HeaderFile
|
1105
src/Vulkan/Vulkan_Device.cxx
Normal file
1105
src/Vulkan/Vulkan_Device.cxx
Normal file
File diff suppressed because it is too large
Load Diff
123
src/Vulkan/Vulkan_Device.hxx
Normal file
123
src/Vulkan/Vulkan_Device.hxx
Normal file
@@ -0,0 +1,123 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Device_HeaderFile
|
||||
#define _Vulkan_Device_HeaderFile
|
||||
|
||||
#include <Graphic3d_DiagnosticInfo.hxx>
|
||||
#include <Vulkan_ForwardDecl.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TColStd_IndexedDataMapOfStringString.hxx>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Vulkan_Caps;
|
||||
class Vulkan_FrameStats;
|
||||
class Vulkan_DeviceMemoryAllocator;
|
||||
|
||||
//! This class defines an Vulkan graphic driver
|
||||
class Vulkan_Device : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Device, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Format VkResult enumeration.
|
||||
Standard_EXPORT static TCollection_AsciiString FormatVkError (int theErr);
|
||||
|
||||
//! Enumeration of known vendor ids.
|
||||
enum VendorId
|
||||
{
|
||||
VendorId_AMD = 0x1002,
|
||||
VendorId_NVIDIA = 0x10DE,
|
||||
VendorId_INTEL = 0x8086,
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
//! @param theAppName application name to be passed to driver
|
||||
//! @param theAppVersion application version to be passed to driver, see VK_MAKE_VERSION() macros
|
||||
//! @param theEngineName engine name to be passed to driver
|
||||
//! @param theEngineVersion engine version to be passed to driver, see VK_MAKE_VERSION() macros
|
||||
Standard_EXPORT Vulkan_Device (const TCollection_AsciiString& theAppName,
|
||||
const uint32_t theAppVersion,
|
||||
const TCollection_AsciiString& theEngineName,
|
||||
const uint32_t theEngineVersion);
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Device();
|
||||
|
||||
//! Release object.
|
||||
Standard_EXPORT void Release();
|
||||
|
||||
//! Perform initialization.
|
||||
Standard_EXPORT bool Init (const Handle(Vulkan_Caps)& theCaps);
|
||||
|
||||
//! Return vulkan instance.
|
||||
VkInstance Instance() const { return myVkInstance; }
|
||||
|
||||
//! Return device.
|
||||
VkDevice Device() const { return myVkDevice; }
|
||||
|
||||
//! Return physical device.
|
||||
VkPhysicalDevice PhysicalDevice() const { return myVkPhysDevice; }
|
||||
|
||||
//! Return custom allocator.
|
||||
const VkAllocationCallbacks* HostAllocator() const { return myVkHostAllocator.get(); }
|
||||
|
||||
//! Return application identifier specified at construction time.
|
||||
const TCollection_AsciiString& ApplicationName() const { return myAppName; }
|
||||
|
||||
//! Return engine identifier specified at construction time.
|
||||
const TCollection_AsciiString& EngineName() const { return myEngineName; }
|
||||
|
||||
//! Return application version specified at construction time.
|
||||
uint32_t ApplicationVersion() const { return myAppVersion; }
|
||||
|
||||
//! Return engine version specified at construction time.
|
||||
uint32_t EngineVersion() const { return myEngineVersion; }
|
||||
|
||||
//! Return frame stats.
|
||||
const Handle(Vulkan_FrameStats)& FrameStats() const { return myFrameStats; }
|
||||
|
||||
//! Return device memory allocator.
|
||||
const Handle(Vulkan_DeviceMemoryAllocator)& DeviceMemoryAllocator() const { return myDevMemAllocator; }
|
||||
|
||||
//! Allocate device memory.
|
||||
Standard_EXPORT VkDeviceMemory allocateDeviceMemory (const VkMemoryRequirements& theReqs);
|
||||
|
||||
//! Fill map with diagnostics information.
|
||||
Standard_EXPORT void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
|
||||
Graphic3d_DiagnosticInfo theFlags) const;
|
||||
|
||||
protected:
|
||||
|
||||
TCollection_AsciiString myAppName; //!< application identifier to be passed to driver
|
||||
TCollection_AsciiString myEngineName; //!< engine identifier to be passed to driver
|
||||
uint32_t myAppVersion; //!< application version to be passed to driver
|
||||
uint32_t myEngineVersion; //!< engine version to be passed to driver
|
||||
|
||||
VkInstance myVkInstance; //!< vulkan instance
|
||||
VkPhysicalDevice myVkPhysDevice; //!< physical device
|
||||
VkDevice myVkDevice; //!< device
|
||||
std::shared_ptr<VkAllocationCallbacks>
|
||||
myVkHostAllocator; //!< optional host memory allocator
|
||||
std::shared_ptr<VkPhysicalDeviceMemoryProperties>
|
||||
myVkDeviceMemory;
|
||||
Handle(Vulkan_FrameStats) myFrameStats;
|
||||
Handle(Vulkan_DeviceMemoryAllocator) myDevMemAllocator;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Device_HeaderFile
|
66
src/Vulkan/Vulkan_DeviceMemory.cxx
Normal file
66
src/Vulkan/Vulkan_DeviceMemory.cxx
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_DeviceMemory.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_DeviceMemoryAllocator.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_DeviceMemory, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_DeviceMemory
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DeviceMemory::Vulkan_DeviceMemory (const Handle(Vulkan_DeviceMemoryAllocator)& theAllocator,
|
||||
void* theOpaque)
|
||||
: myAllocator (theAllocator),
|
||||
myOpaque (theOpaque)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_DeviceMemory
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DeviceMemory::~Vulkan_DeviceMemory()
|
||||
{
|
||||
releaseRegion();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : DeviceMemoryInfo
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DeviceMemoryInfo Vulkan_DeviceMemory::DeviceMemoryInfo() const
|
||||
{
|
||||
return myOpaque != NULL ? myAllocator->memoryRegionInfo (*this) : Vulkan_DeviceMemoryInfo();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseRegion
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_DeviceMemory::releaseRegion()
|
||||
{
|
||||
if (myOpaque != NULL)
|
||||
{
|
||||
myAllocator->memoryRegionFree (*this);
|
||||
}
|
||||
myAllocator.Nullify();
|
||||
}
|
63
src/Vulkan/Vulkan_DeviceMemory.hxx
Normal file
63
src/Vulkan/Vulkan_DeviceMemory.hxx
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_DeviceMemory_HeaderFile
|
||||
#define _Vulkan_DeviceMemory_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
class Vulkan_DeviceMemoryAllocator;
|
||||
|
||||
//! Device memory region information.
|
||||
struct Vulkan_DeviceMemoryInfo
|
||||
{
|
||||
VkDeviceMemory DeviceMemory;
|
||||
VkDeviceSize Offset;
|
||||
VkDeviceSize Size;
|
||||
|
||||
Vulkan_DeviceMemoryInfo() : DeviceMemory (NULL), Offset (0), Size (0) {}
|
||||
};
|
||||
|
||||
//! This class defines an device memory block.
|
||||
class Vulkan_DeviceMemory : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_DeviceMemory, Standard_Transient)
|
||||
friend class Vulkan_DeviceMemoryAllocator;
|
||||
public:
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_DeviceMemory();
|
||||
|
||||
//! Return memory region.
|
||||
Standard_EXPORT Vulkan_DeviceMemoryInfo DeviceMemoryInfo() const;
|
||||
|
||||
protected:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_DeviceMemory (const Handle(Vulkan_DeviceMemoryAllocator)& theAllocator,
|
||||
void* theOpaque);
|
||||
|
||||
//! Release the object.
|
||||
void release() { releaseRegion(); }
|
||||
|
||||
//! Release the object.
|
||||
Standard_EXPORT void releaseRegion();
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_DeviceMemoryAllocator) myAllocator;
|
||||
void* myOpaque;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_DeviceMemory_HeaderFile
|
199
src/Vulkan/Vulkan_DeviceMemoryAllocator.cxx
Normal file
199
src/Vulkan/Vulkan_DeviceMemoryAllocator.cxx
Normal file
@@ -0,0 +1,199 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_DeviceMemoryAllocator.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_DeviceMemory.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#ifdef max
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
#define VMA_IMPLEMENTATION
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
namespace
|
||||
{
|
||||
static VmaMemoryUsage memUsageOcctToVma (Vulkan_DeviceMemoryUsage theUsage)
|
||||
{
|
||||
switch (theUsage)
|
||||
{
|
||||
case Vulkan_DeviceMemoryUsage_UNKNOWN: return VMA_MEMORY_USAGE_UNKNOWN;
|
||||
case Vulkan_DeviceMemoryUsage_GpuOnly: return VMA_MEMORY_USAGE_GPU_ONLY;
|
||||
case Vulkan_DeviceMemoryUsage_CpuOnly: return VMA_MEMORY_USAGE_CPU_ONLY;
|
||||
case Vulkan_DeviceMemoryUsage_CpuToGpu: return VMA_MEMORY_USAGE_CPU_TO_GPU;
|
||||
case Vulkan_DeviceMemoryUsage_GpuToCpu: return VMA_MEMORY_USAGE_GPU_TO_CPU;
|
||||
}
|
||||
return VMA_MEMORY_USAGE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_DeviceMemoryAllocator, Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_DeviceMemory
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DeviceMemoryAllocator::Vulkan_DeviceMemoryAllocator()
|
||||
: myVmaAllocator (NULL),
|
||||
myDevice (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_DeviceMemoryAllocator
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DeviceMemoryAllocator::~Vulkan_DeviceMemoryAllocator()
|
||||
{
|
||||
releaseAllocator();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseAllocator
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_DeviceMemoryAllocator::releaseAllocator()
|
||||
{
|
||||
if (myVmaAllocator != NULL)
|
||||
{
|
||||
vmaDestroyAllocator (myVmaAllocator);
|
||||
myVmaAllocator = NULL;
|
||||
}
|
||||
myDevice = NULL;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_DeviceMemoryAllocator::Create (const Handle(Vulkan_Device)& theDevice,
|
||||
bool toUseDedicatedAllocs)
|
||||
{
|
||||
release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice.get();
|
||||
|
||||
VmaAllocatorCreateInfo aVmaAllocInfo = {};
|
||||
aVmaAllocInfo.physicalDevice = theDevice->PhysicalDevice();
|
||||
aVmaAllocInfo.device = theDevice->Device();
|
||||
aVmaAllocInfo.flags = 0;
|
||||
if (toUseDedicatedAllocs)
|
||||
{
|
||||
// will be used by vmaCreateBuffer() and vmaCreateImage()
|
||||
aVmaAllocInfo.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
|
||||
}
|
||||
|
||||
VkResult aRes = vmaCreateAllocator (&aVmaAllocInfo, &myVmaAllocator);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
Message::DefaultMessenger()->Send (TCollection_AsciiString("Vulkan_DeviceMemoryAllocator, unable to create memory allocator: ") + Vulkan_Device::FormatVkError (aRes));
|
||||
release();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : memoryRegionInfo
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_DeviceMemoryInfo Vulkan_DeviceMemoryAllocator::memoryRegionInfo (const Vulkan_DeviceMemory& theMem) const
|
||||
{
|
||||
Vulkan_DeviceMemoryInfo anInfo;
|
||||
if (myVmaAllocator != NULL)
|
||||
{
|
||||
VmaAllocationInfo anAllocInfo = {};
|
||||
vmaGetAllocationInfo (myVmaAllocator, (VmaAllocation )theMem.myOpaque, &anAllocInfo);
|
||||
|
||||
anInfo.DeviceMemory = anAllocInfo.deviceMemory;
|
||||
anInfo.Offset = anAllocInfo.offset;
|
||||
anInfo.Size = anAllocInfo.size;
|
||||
}
|
||||
else
|
||||
{
|
||||
anInfo.DeviceMemory = (VkDeviceMemory )theMem.myOpaque;
|
||||
anInfo.Offset = 0;
|
||||
anInfo.Size = 0;
|
||||
}
|
||||
return anInfo;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : memoryRegionFree
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_DeviceMemoryAllocator::memoryRegionFree (Vulkan_DeviceMemory& theMem)
|
||||
{
|
||||
if (theMem.myOpaque != NULL)
|
||||
{
|
||||
if (myVmaAllocator != NULL)
|
||||
{
|
||||
vmaFreeMemory (myVmaAllocator, (VmaAllocation )theMem.myOpaque);
|
||||
}
|
||||
else
|
||||
{
|
||||
vkFreeMemory (myDevice->Device(), (VkDeviceMemory )theMem.myOpaque, myDevice->HostAllocator());
|
||||
}
|
||||
theMem.myOpaque = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Allocate
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Handle(Vulkan_DeviceMemory) Vulkan_DeviceMemoryAllocator::Allocate (const VkMemoryRequirements& theReqs,
|
||||
Vulkan_DeviceMemoryUsage theUsage)
|
||||
{
|
||||
if (myVmaAllocator == NULL)
|
||||
{
|
||||
VkDeviceMemory aVkDevMem = myDevice->allocateDeviceMemory (theReqs);
|
||||
if (aVkDevMem == NULL)
|
||||
{
|
||||
return Handle(Vulkan_DeviceMemory)();
|
||||
}
|
||||
Handle(Vulkan_DeviceMemory) aDevMem = new Vulkan_DeviceMemory (NULL, aVkDevMem);
|
||||
return aDevMem;
|
||||
}
|
||||
|
||||
VmaAllocation aVmaAlloc = NULL;
|
||||
VmaAllocationCreateInfo anAllocCreateInfo = {};
|
||||
anAllocCreateInfo.usage = memUsageOcctToVma (theUsage);
|
||||
|
||||
VmaAllocationInfo anAllocInfo = {};
|
||||
VkResult aRes = vmaAllocateMemory (myVmaAllocator, &theReqs, &anAllocCreateInfo, &aVmaAlloc, &anAllocInfo);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
Message::DefaultMessenger()->Send (TCollection_AsciiString ("Vulkan_DeviceMemoryAllocator, failed to allocate device memory [")
|
||||
+ int(theReqs.size) + "]:" + Vulkan_Device::FormatVkError (aRes), Message_Fail);
|
||||
return Handle(Vulkan_DeviceMemory)();
|
||||
}
|
||||
|
||||
Handle(Vulkan_DeviceMemory) aDevMem = new Vulkan_DeviceMemory (this, aVmaAlloc);
|
||||
return aDevMem;
|
||||
}
|
76
src/Vulkan/Vulkan_DeviceMemoryAllocator.hxx
Normal file
76
src/Vulkan/Vulkan_DeviceMemoryAllocator.hxx
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_DeviceMemoryAllocator_HeaderFile
|
||||
#define _Vulkan_DeviceMemoryAllocator_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
VK_DEFINE_HANDLE(VmaAllocator)
|
||||
class Vulkan_DeviceMemory;
|
||||
struct Vulkan_DeviceMemoryInfo;
|
||||
|
||||
enum Vulkan_DeviceMemoryUsage
|
||||
{
|
||||
Vulkan_DeviceMemoryUsage_UNKNOWN = -1, //!< unknown memory usage
|
||||
Vulkan_DeviceMemoryUsage_GpuOnly = 0, //!< memory to be used on device only
|
||||
Vulkan_DeviceMemoryUsage_CpuOnly, //!< memory to be mappable on host
|
||||
Vulkan_DeviceMemoryUsage_CpuToGpu, //!< memory that is both mappable on host and preferably fast to access by GPU
|
||||
Vulkan_DeviceMemoryUsage_GpuToCpu, //!< memory mappable on host and cached
|
||||
};
|
||||
|
||||
//! This class defines a memory allocator for device memory.
|
||||
//! It is expected to be created by Vulkan_Device itself.
|
||||
class Vulkan_DeviceMemoryAllocator : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_DeviceMemoryAllocator, Standard_Transient)
|
||||
friend class Vulkan_DeviceMemory;
|
||||
friend class Vulkan_Device;
|
||||
public:
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_DeviceMemoryAllocator();
|
||||
|
||||
//! Allocate new memory region.
|
||||
Handle(Vulkan_DeviceMemory) Allocate (const VkMemoryRequirements& theReqs,
|
||||
Vulkan_DeviceMemoryUsage theUsage);
|
||||
|
||||
protected:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_DeviceMemoryAllocator();
|
||||
|
||||
//! Create the object.
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice,
|
||||
bool toUseDedicatedAllocs);
|
||||
|
||||
//! Release the object.
|
||||
void release() { releaseAllocator(); }
|
||||
|
||||
//! Release the object.
|
||||
Standard_EXPORT void releaseAllocator();
|
||||
|
||||
//! Return memory region information.
|
||||
Standard_EXPORT Vulkan_DeviceMemoryInfo memoryRegionInfo (const Vulkan_DeviceMemory& theMem) const;
|
||||
|
||||
//! Release memory region.
|
||||
Standard_EXPORT void memoryRegionFree (Vulkan_DeviceMemory& theMem);
|
||||
|
||||
protected:
|
||||
|
||||
VmaAllocator myVmaAllocator;
|
||||
Vulkan_Device* myDevice;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_DeviceMemoryAllocator_HeaderFile
|
132
src/Vulkan/Vulkan_Fence.cxx
Normal file
132
src/Vulkan/Vulkan_Fence.cxx
Normal file
@@ -0,0 +1,132 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Fence.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Fence, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Fence
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Fence::Vulkan_Fence()
|
||||
: myVkFence (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Fence
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Fence::~Vulkan_Fence()
|
||||
{
|
||||
releaseFence();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseFence
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Fence::releaseFence()
|
||||
{
|
||||
if (myVkFence != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_Fence");
|
||||
vkDestroyFence (myDevice->Device(), myVkFence, myDevice->HostAllocator());
|
||||
myVkFence = NULL;
|
||||
}
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Fence::Create (const Handle(Vulkan_Device)& theDevice)
|
||||
{
|
||||
if (myVkFence != NULL
|
||||
&& myDevice == theDevice)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
|
||||
VkFenceCreateInfo aVkFenceInfo;
|
||||
aVkFenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
aVkFenceInfo.pNext = NULL;
|
||||
aVkFenceInfo.flags = 0;
|
||||
|
||||
VkResult aRes = vkCreateFence (theDevice->Device(), &aVkFenceInfo, theDevice->HostAllocator(), &myVkFence);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create fence", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Wait
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Fence::Wait()
|
||||
{
|
||||
if (myVkFence == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
VkResult aRes = vkWaitForFences (myDevice->Device(), 1, &myVkFence, VK_TRUE, UINT64_MAX);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailure ("failed to wait for fence", aRes);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Reset
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Fence::Reset()
|
||||
{
|
||||
if (myVkFence == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
VkResult aRes = vkResetFences (myDevice->Device(), 1, &myVkFence);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailure ("failed to reset fence", aRes);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
57
src/Vulkan/Vulkan_Fence.hxx
Normal file
57
src/Vulkan/Vulkan_Fence.hxx
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Fence_HeaderFile
|
||||
#define _Vulkan_Fence_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
//! This class defines an Vulkan fence.
|
||||
class Vulkan_Fence : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Fence, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_Fence();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Fence();
|
||||
|
||||
//! Return object.
|
||||
VkFence Fence() const { return myVkFence; }
|
||||
|
||||
//! Create the object, @sa vkCreateFence().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice);
|
||||
|
||||
//! Wait for the fence, @sa vkWaitForFences().
|
||||
Standard_EXPORT bool Wait();
|
||||
|
||||
//! Reset the fence, @sa vkResetFences().
|
||||
Standard_EXPORT bool Reset();
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releaseFence(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyFence().
|
||||
Standard_EXPORT void releaseFence();
|
||||
|
||||
protected:
|
||||
|
||||
VkFence myVkFence;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Fence_HeaderFile
|
67
src/Vulkan/Vulkan_ForwardDecl.hxx
Normal file
67
src/Vulkan/Vulkan_ForwardDecl.hxx
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_ForwardDecl_HeaderFile
|
||||
#define _Vulkan_ForwardDecl_HeaderFile
|
||||
|
||||
#include <Standard_TypeDef.hxx>
|
||||
|
||||
#ifndef VK_DEFINE_HANDLE
|
||||
#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
|
||||
|
||||
#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE)
|
||||
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
|
||||
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
|
||||
#else
|
||||
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
VK_DEFINE_HANDLE(VkInstance)
|
||||
VK_DEFINE_HANDLE(VkPhysicalDevice)
|
||||
VK_DEFINE_HANDLE(VkDevice)
|
||||
VK_DEFINE_HANDLE(VkQueue)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore)
|
||||
VK_DEFINE_HANDLE(VkCommandBuffer)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFence)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeviceMemory)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBuffer)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImage)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkEvent)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkQueryPool)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBufferView)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkShaderModule)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineCache)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineLayout)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkRenderPass)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipeline)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSetLayout)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorPool)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSet)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFramebuffer)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool)
|
||||
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSwapchainKHR)
|
||||
|
||||
struct VkAllocationCallbacks;
|
||||
struct VkMemoryRequirements;
|
||||
struct VkPhysicalDeviceMemoryProperties;
|
||||
struct VkSurfaceFormatKHR;
|
||||
|
||||
typedef uint64_t VkDeviceSize;
|
||||
#endif
|
||||
|
||||
#endif // _Vulkan_ForwardDecl_HeaderFile
|
123
src/Vulkan/Vulkan_FrameBuffer.cxx
Normal file
123
src/Vulkan/Vulkan_FrameBuffer.cxx
Normal file
@@ -0,0 +1,123 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_FrameBuffer.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_Image.hxx>
|
||||
#include <Vulkan_RenderPass.hxx>
|
||||
#include <Vulkan_Surface.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_FrameBuffer, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_FrameBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_FrameBuffer::Vulkan_FrameBuffer()
|
||||
: myVkFramebuffer (NULL),
|
||||
myVkImageView (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_FrameBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_FrameBuffer::~Vulkan_FrameBuffer()
|
||||
{
|
||||
releaseBuffer();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseBuffer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_FrameBuffer::releaseBuffer()
|
||||
{
|
||||
if (myVkFramebuffer != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_FrameBuffer");
|
||||
vkDestroyFramebuffer (myDevice->Device(), myVkFramebuffer, myDevice->HostAllocator());
|
||||
myVkFramebuffer = NULL;
|
||||
}
|
||||
myRenderPass.Nullify();
|
||||
myDepth.Nullify();
|
||||
mySurface.Nullify();
|
||||
myDevice.Nullify();
|
||||
myVkImageView = NULL;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_FrameBuffer::Create (const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_Surface)& theSurface,
|
||||
const uint32_t theChainIndex)
|
||||
{
|
||||
if (theRenderPass.IsNull()
|
||||
|| theSurface.IsNull())
|
||||
{
|
||||
Release();
|
||||
return false;
|
||||
}
|
||||
|
||||
const VkImageView anImageView = theSurface->ImageViews()[theChainIndex];
|
||||
if (myRenderPass == theRenderPass
|
||||
&& mySurface == theSurface
|
||||
&& myVkImageView == anImageView
|
||||
&& myDepth == theSurface->DepthImage()
|
||||
&& mySize == theSurface->Size())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Release();
|
||||
myRenderPass = theRenderPass;
|
||||
mySurface = theSurface;
|
||||
myDepth = theSurface->DepthImage();
|
||||
myDevice = theRenderPass->Device();
|
||||
myVkImageView = anImageView;
|
||||
mySize = theSurface->Size();
|
||||
|
||||
VkFramebufferCreateInfo aVkFboInfo = {};
|
||||
const VkImageView aVkImageViews[2] =
|
||||
{
|
||||
anImageView,
|
||||
!myDepth.IsNull() ? myDepth->ImageView() : NULL,
|
||||
};
|
||||
aVkFboInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
aVkFboInfo.pNext = NULL;
|
||||
aVkFboInfo.flags = 0;
|
||||
aVkFboInfo.renderPass = theRenderPass->RenderPass();
|
||||
aVkFboInfo.attachmentCount = 2;
|
||||
aVkFboInfo.pAttachments = aVkImageViews;
|
||||
aVkFboInfo.width = theSurface->Size().x();
|
||||
aVkFboInfo.height = theSurface->Size().y();
|
||||
aVkFboInfo.layers = 1;
|
||||
|
||||
VkResult aRes = vkCreateFramebuffer (myDevice->Device(), &aVkFboInfo, myDevice->HostAllocator(), &myVkFramebuffer);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create framebuffer", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
63
src/Vulkan/Vulkan_FrameBuffer.hxx
Normal file
63
src/Vulkan/Vulkan_FrameBuffer.hxx
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_FrameBuffer_HeaderFile
|
||||
#define _Vulkan_FrameBuffer_HeaderFile
|
||||
|
||||
#include <Graphic3d_Vec2.hxx>
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
class Vulkan_Image;
|
||||
class Vulkan_RenderPass;
|
||||
class Vulkan_Surface;
|
||||
|
||||
//! This class defines an Vulkan frame buffer.
|
||||
class Vulkan_FrameBuffer : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_FrameBuffer, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_FrameBuffer();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_FrameBuffer();
|
||||
|
||||
//! Return object.
|
||||
VkFramebuffer FrameBuffer() const { return myVkFramebuffer; }
|
||||
|
||||
//! Create the object, @sa vkCreateFramebuffer().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_Surface)& theSurface,
|
||||
const uint32_t theChainIndex);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releaseBuffer(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyFramebuffer().
|
||||
Standard_EXPORT void releaseBuffer();
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_RenderPass) myRenderPass;
|
||||
Handle(Vulkan_Surface) mySurface;
|
||||
Handle(Vulkan_Image) myDepth;
|
||||
VkFramebuffer myVkFramebuffer;
|
||||
VkImageView myVkImageView;
|
||||
Graphic3d_Vec2u mySize;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_FrameBuffer_HeaderFile
|
316
src/Vulkan/Vulkan_FrameStats.cxx
Normal file
316
src/Vulkan/Vulkan_FrameStats.cxx
Normal file
@@ -0,0 +1,316 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_FrameStats.hxx>
|
||||
|
||||
#include <Vulkan_View.hxx>
|
||||
#include <Vulkan_Structure.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_FrameStats, Graphic3d_FrameStats)
|
||||
|
||||
namespace
|
||||
{
|
||||
//! Return estimated data size.
|
||||
/**static Standard_Size estimatedDataSize (const Handle(OpenGl_Resource)& theRes)
|
||||
{
|
||||
return !theRes.IsNull() ? theRes->EstimatedDataSize() : 0;
|
||||
}*/
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_FrameStats
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_FrameStats::Vulkan_FrameStats()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_FrameStats
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_FrameStats::~Vulkan_FrameStats()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : IsFrameUpdated
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_FrameStats::IsFrameUpdated (Handle(Vulkan_FrameStats)& thePrev) const
|
||||
{
|
||||
const Graphic3d_FrameStatsData& aFrame = LastDataFrame();
|
||||
if (thePrev.IsNull())
|
||||
{
|
||||
thePrev = new Vulkan_FrameStats();
|
||||
}
|
||||
// check just a couple of major counters
|
||||
else if (myLastFrameIndex == thePrev->myLastFrameIndex
|
||||
&& Abs (aFrame.FrameRate() - thePrev->myCountersTmp.FrameRate()) <= 0.001
|
||||
&& Abs (aFrame.FrameRateCpu() - thePrev->myCountersTmp.FrameRateCpu()) <= 0.001
|
||||
&& aFrame[Graphic3d_FrameStatsCounter_NbLayers] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbLayers]
|
||||
&& aFrame[Graphic3d_FrameStatsCounter_NbLayersNotCulled] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbLayersNotCulled]
|
||||
&& aFrame[Graphic3d_FrameStatsCounter_NbStructs] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbStructs]
|
||||
&& aFrame[Graphic3d_FrameStatsCounter_NbStructsNotCulled] == thePrev->myCountersTmp[Graphic3d_FrameStatsCounter_NbStructsNotCulled])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
thePrev->myLastFrameIndex = myLastFrameIndex;
|
||||
thePrev->myCountersTmp = aFrame;
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : updateStatistics
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_FrameStats::updateStatistics (const Handle(Graphic3d_CView)& theView,
|
||||
bool theIsImmediateOnly)
|
||||
{
|
||||
const Vulkan_View* aView = dynamic_cast<const Vulkan_View*> (theView.get());
|
||||
if (aView == NULL)
|
||||
{
|
||||
myCounters.SetValue (myLastFrameIndex, myCountersTmp);
|
||||
myCountersTmp.Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
const Graphic3d_RenderingParams::PerfCounters aBits = theView->RenderingParams().CollectedStats;
|
||||
const Standard_Boolean toCountMem = (aBits & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0;
|
||||
const Standard_Boolean toCountTris = (aBits & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0
|
||||
|| (aBits & Graphic3d_RenderingParams::PerfCounters_Points) != 0;
|
||||
const Standard_Boolean toCountElems = (aBits & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0 || toCountTris || toCountMem;
|
||||
const Standard_Boolean toCountGroups = (aBits & Graphic3d_RenderingParams::PerfCounters_Groups) != 0 || toCountElems;
|
||||
const Standard_Boolean toCountStructs = (aBits & Graphic3d_RenderingParams::PerfCounters_Structures) != 0
|
||||
|| (aBits & Graphic3d_RenderingParams::PerfCounters_Layers) != 0 || toCountGroups;
|
||||
|
||||
/// TODO
|
||||
///myCountersTmp[Graphic3d_FrameStatsCounter_NbLayers] = aView->LayerList().Layers().Size();
|
||||
if (toCountStructs
|
||||
|| (aBits & Graphic3d_RenderingParams::PerfCounters_Layers) != 0)
|
||||
{
|
||||
const Standard_Integer aViewId = aView->Identification();
|
||||
/// TODO
|
||||
/*for (OpenGl_SequenceOfLayers::Iterator aLayerIter (aView->LayerList().Layers()); aLayerIter.More(); aLayerIter.Next())
|
||||
{
|
||||
const Handle(OpenGl_Layer)& aLayer = aLayerIter.Value();
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbStructs] += aLayer->NbStructures();
|
||||
if (theIsImmediateOnly && !aLayer->LayerSettings().IsImmediate())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!aLayer->IsCulled())
|
||||
{
|
||||
++myCountersTmp[Graphic3d_FrameStatsCounter_NbLayersNotCulled];
|
||||
}
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbStructsNotCulled] += aLayer->NbStructuresNotCulled();
|
||||
if (toCountGroups)
|
||||
{
|
||||
updateStructures (aViewId, aLayer->CullableStructuresBVH().Structures(), toCountElems, toCountTris, toCountMem);
|
||||
updateStructures (aViewId, aLayer->CullableTrsfPersStructuresBVH().Structures(), toCountElems, toCountTris, toCountMem);
|
||||
updateStructures (aViewId, aLayer->NonCullableStructures(), toCountElems, toCountTris, toCountMem);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
if (toCountMem)
|
||||
{
|
||||
// TODO
|
||||
/**for (OpenGl_Context::OpenGl_ResourcesMap::Iterator aResIter (aView->GlWindow()->GetGlContext()->SharedResources());
|
||||
aResIter.More(); aResIter.Next())
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesTextures] += aResIter.Value()->EstimatedDataSize();
|
||||
}
|
||||
|
||||
{
|
||||
Standard_Size& aMemFbos = myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesFbos];
|
||||
// main FBOs
|
||||
aMemFbos += estimatedDataSize (aView->myMainSceneFbos[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myMainSceneFbos[1]);
|
||||
aMemFbos += estimatedDataSize (aView->myImmediateSceneFbos[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myImmediateSceneFbos[1]);
|
||||
// OIT FBOs
|
||||
aMemFbos += estimatedDataSize (aView->myMainSceneFbosOit[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myMainSceneFbosOit[1]);
|
||||
aMemFbos += estimatedDataSize (aView->myImmediateSceneFbosOit[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myImmediateSceneFbosOit[1]);
|
||||
// dump FBO
|
||||
aMemFbos += estimatedDataSize (aView->myFBO);
|
||||
// RayTracing FBO
|
||||
aMemFbos += estimatedDataSize (aView->myOpenGlFBO);
|
||||
aMemFbos += estimatedDataSize (aView->myOpenGlFBO2);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceFBO1[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceFBO1[1]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceFBO2[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceFBO2[1]);
|
||||
// also RayTracing
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceOutputTexture[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceOutputTexture[1]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceVisualErrorTexture[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceVisualErrorTexture[1]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceTileOffsetsTexture[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceTileOffsetsTexture[1]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceTileSamplesTexture[0]);
|
||||
aMemFbos += estimatedDataSize (aView->myRaytraceTileSamplesTexture[1]);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : updateStructures
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_FrameStats::updateStructures (Standard_Integer theViewId,
|
||||
const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructures,
|
||||
Standard_Boolean theToCountElems,
|
||||
Standard_Boolean theToCountTris,
|
||||
Standard_Boolean theToCountMem)
|
||||
{
|
||||
for (Vulkan_Structure::StructIterator aStructIter (theStructures); aStructIter.More(); aStructIter.Next())
|
||||
{
|
||||
const Vulkan_Structure* aStruct = aStructIter.Value();
|
||||
const bool isStructHidden = aStruct->IsCulled()
|
||||
|| !aStruct->IsVisible (theViewId);
|
||||
for (; aStruct != NULL; aStruct = aStruct->InstancedStructure())
|
||||
{
|
||||
if (isStructHidden)
|
||||
{
|
||||
if (theToCountMem)
|
||||
{
|
||||
for (Vulkan_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next())
|
||||
{
|
||||
const Vulkan_Group* aGroup = aGroupIter.Value();
|
||||
// TODO
|
||||
/**for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next)
|
||||
{
|
||||
if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast<const OpenGl_PrimitiveArray*> (aNodeIter->elem))
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->AttributesVbo());
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->IndexVbo());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbGroupsNotCulled] += aStruct->Groups().Size();
|
||||
if (!theToCountElems)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Vulkan_Structure::GroupIterator aGroupIter (aStruct->Groups()); aGroupIter.More(); aGroupIter.Next())
|
||||
{
|
||||
const Vulkan_Group* aGroup = aGroupIter.Value();
|
||||
// TODO
|
||||
/**for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next)
|
||||
{
|
||||
if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast<const OpenGl_PrimitiveArray*> (aNodeIter->elem))
|
||||
{
|
||||
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
|
||||
if (theToCountMem)
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->AttributesVbo());
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += estimatedDataSize (aPrim->IndexVbo());
|
||||
}
|
||||
|
||||
if (aPrim->IsFillDrawMode())
|
||||
{
|
||||
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled];
|
||||
if (!theToCountTris)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const Handle(OpenGl_VertexBuffer)& anAttribs = aPrim->AttributesVbo();
|
||||
if (anAttribs.IsNull()
|
||||
|| !anAttribs->IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const Handle(OpenGl_VertexBuffer)& anIndices = aPrim->IndexVbo();
|
||||
const Standard_Integer aNbIndices = !anIndices.IsNull() ? anIndices->GetElemsNb() : anAttribs->GetElemsNb();
|
||||
const Standard_Integer aNbBounds = !aPrim->Bounds().IsNull() ? aPrim->Bounds()->NbBounds : 1;
|
||||
switch (aPrim->DrawMode())
|
||||
{
|
||||
case GL_TRIANGLES:
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 3;
|
||||
break;
|
||||
}
|
||||
case GL_TRIANGLE_STRIP:
|
||||
case GL_TRIANGLE_FAN:
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 2 * aNbBounds;
|
||||
break;
|
||||
}
|
||||
case GL_TRIANGLES_ADJACENCY:
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 6;
|
||||
break;
|
||||
}
|
||||
case GL_TRIANGLE_STRIP_ADJACENCY:
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 4 * aNbBounds;
|
||||
break;
|
||||
}
|
||||
#if !defined(GL_ES_VERSION_2_0)
|
||||
case GL_QUADS:
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 2;
|
||||
break;
|
||||
}
|
||||
case GL_QUAD_STRIP:
|
||||
{
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += (aNbIndices / 2 - aNbBounds) * 2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (aPrim->DrawMode() == GL_POINTS)
|
||||
{
|
||||
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled];
|
||||
if (theToCountTris)
|
||||
{
|
||||
const Handle(OpenGl_VertexBuffer)& anAttribs = aPrim->AttributesVbo();
|
||||
if (!anAttribs.IsNull()
|
||||
&& anAttribs->IsValid())
|
||||
{
|
||||
const Handle(OpenGl_VertexBuffer)& anIndices = aPrim->IndexVbo();
|
||||
const Standard_Integer aNbIndices = !anIndices.IsNull() ? anIndices->GetElemsNb() : anAttribs->GetElemsNb();
|
||||
myCountersTmp[Graphic3d_FrameStatsCounter_NbPointsNotCulled] += aNbIndices;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled];
|
||||
}
|
||||
}
|
||||
else if (const OpenGl_Text* aText = dynamic_cast<const OpenGl_Text*> (aNodeIter->elem))
|
||||
{
|
||||
(void )aText;
|
||||
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
|
||||
++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled];
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
src/Vulkan/Vulkan_FrameStats.hxx
Normal file
58
src/Vulkan/Vulkan_FrameStats.hxx
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_FrameStats_HeaderFile
|
||||
#define _Vulkan_FrameStats_HeaderFile
|
||||
|
||||
#include <Graphic3d_FrameStats.hxx>
|
||||
#include <NCollection_IndexedMap.hxx>
|
||||
|
||||
class Graphic3d_CStructure;
|
||||
|
||||
//! Class storing the frame statistics.
|
||||
class Vulkan_FrameStats : public Graphic3d_FrameStats
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_FrameStats, Graphic3d_FrameStats)
|
||||
public:
|
||||
|
||||
//! Default constructor.
|
||||
Standard_EXPORT Vulkan_FrameStats();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_FrameStats();
|
||||
|
||||
public:
|
||||
|
||||
//! Copy stats values into another instance (create new instance, if not exists).
|
||||
//! The main use of this method is to track changes in statistics (e.g. in conjunction with IsEqual() method).
|
||||
//! @return TRUE if frame data has been changed so that the presentation should be updated
|
||||
Standard_EXPORT virtual bool IsFrameUpdated (Handle(Vulkan_FrameStats)& thePrev) const;
|
||||
|
||||
protected:
|
||||
|
||||
//! Method to collect statistics from the View; called by FrameEnd().
|
||||
Standard_EXPORT virtual void updateStatistics (const Handle(Graphic3d_CView)& theView,
|
||||
bool theIsImmediateOnly) Standard_OVERRIDE;
|
||||
|
||||
//! Updates counters for structures.
|
||||
Standard_EXPORT virtual void updateStructures (Standard_Integer theViewId,
|
||||
const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructures,
|
||||
Standard_Boolean theToCountElems,
|
||||
Standard_Boolean theToCountTris,
|
||||
Standard_Boolean theToCountMem);
|
||||
|
||||
};
|
||||
|
||||
DEFINE_STANDARD_HANDLE(Vulkan_FrameStats, Graphic3d_FrameStats)
|
||||
|
||||
#endif // _Vulkan_FrameStats_HeaderFile
|
356
src/Vulkan/Vulkan_GraphicDriver.cxx
Normal file
356
src/Vulkan/Vulkan_GraphicDriver.cxx
Normal file
@@ -0,0 +1,356 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_GraphicDriver.hxx>
|
||||
|
||||
#include <Vulkan_Caps.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_View.hxx>
|
||||
#include <Vulkan_Structure.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_GraphicDriver, Graphic3d_GraphicDriver)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_GraphicDriver
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_GraphicDriver::Vulkan_GraphicDriver (const TCollection_AsciiString& theAppName,
|
||||
const uint32_t theAppVersion,
|
||||
const Handle(Aspect_DisplayConnection)& theDisp)
|
||||
: Graphic3d_GraphicDriver (theDisp),
|
||||
myVkDevice (new Vulkan_Device (theAppName, theAppVersion, "Open CASCADE Technology",
|
||||
DefineVersion (OCC_VERSION_MAJOR, OCC_VERSION_MINOR, OCC_VERSION_MAINTENANCE))),
|
||||
myCaps (new Vulkan_Caps()),
|
||||
myMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator()),
|
||||
myMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator())
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_GraphicDriver
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_GraphicDriver::~Vulkan_GraphicDriver()
|
||||
{
|
||||
ReleaseContext();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ReleaseContext
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_GraphicDriver::ReleaseContext()
|
||||
{
|
||||
myVkDevice->Release();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : InitContext
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean Vulkan_GraphicDriver::InitContext()
|
||||
{
|
||||
ReleaseContext();
|
||||
return myVkDevice->Init (myCaps);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : InquireLimit
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Integer Vulkan_GraphicDriver::InquireLimit (const Graphic3d_TypeOfLimit theType) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : DefaultTextHeight
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_ShortReal Vulkan_GraphicDriver::DefaultTextHeight() const
|
||||
{
|
||||
return 16.;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : MemoryInfo
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Boolean Vulkan_GraphicDriver::MemoryInfo (Standard_Size& theFreeBytes,
|
||||
TCollection_AsciiString& theInfo) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : TextSize
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_GraphicDriver::TextSize (const Handle(Graphic3d_CView)& theView,
|
||||
const Standard_CString theText,
|
||||
const Standard_ShortReal theHeight,
|
||||
Standard_ShortReal& theWidth,
|
||||
Standard_ShortReal& theAscent,
|
||||
Standard_ShortReal& theDescent) const
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddZLayer
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Vulkan_GraphicDriver::AddZLayer (const Graphic3d_ZLayerId theLayerId)
|
||||
{
|
||||
if (theLayerId < 1)
|
||||
{
|
||||
Standard_ASSERT_RAISE (theLayerId > 0, "Vulkan_GraphicDriver::AddZLayer, negative and zero IDs are reserved");
|
||||
}
|
||||
|
||||
myLayerIds.Add (theLayerId);
|
||||
|
||||
// Default z-layer settings
|
||||
myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings());
|
||||
addZLayerIndex (theLayerId);
|
||||
|
||||
// Add layer to all views
|
||||
for (NCollection_Map<Handle(Vulkan_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
|
||||
{
|
||||
aViewIt.Value()->AddZLayer (theLayerId);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveZLayer
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Vulkan_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
|
||||
{
|
||||
Standard_ASSERT_RAISE (theLayerId > 0,
|
||||
"Vulkan_GraphicDriver::AddZLayer, negative and zero IDs are reserved and can not be removed");
|
||||
|
||||
Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId),
|
||||
"Vulkan_GraphicDriver::RemoveZLayer, Layer with theLayerId does not exist");
|
||||
|
||||
// Remove layer from all of the views
|
||||
for (NCollection_Map<Handle(Vulkan_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
|
||||
{
|
||||
aViewIt.Value()->RemoveZLayer (theLayerId);
|
||||
}
|
||||
|
||||
// Unset Z layer for all of the structures.
|
||||
for (NCollection_DataMap<Standard_Integer, Vulkan_Structure*>::Iterator aStructIt (myMapOfStructure); aStructIt.More(); aStructIt.Next())
|
||||
{
|
||||
Vulkan_Structure* aStruct = aStructIt.ChangeValue();
|
||||
if (aStruct->ZLayer() == theLayerId)
|
||||
{
|
||||
aStruct->SetZLayer (Graphic3d_ZLayerId_Default);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove index
|
||||
for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
|
||||
{
|
||||
if (aLayerIt.Value() == theLayerId)
|
||||
{
|
||||
myLayerSeq.Remove (aLayerIt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
myMapOfZLayerSettings.UnBind (theLayerId);
|
||||
myLayerIds.Remove (theLayerId);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetZLayerSettings
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void Vulkan_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
|
||||
const Graphic3d_ZLayerSettings& theSettings)
|
||||
{
|
||||
base_type::SetZLayerSettings (theLayerId, theSettings);
|
||||
|
||||
// Change Z layer settings in all managed views
|
||||
for (NCollection_Map<Handle(Vulkan_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
|
||||
{
|
||||
aViewIt.Value()->SetZLayerSettings (theLayerId, theSettings);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Structure
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Handle(Graphic3d_CStructure) Vulkan_GraphicDriver::CreateStructure (const Handle(Graphic3d_StructureManager)& theManager)
|
||||
{
|
||||
Handle(Vulkan_Structure) aStructure = new Vulkan_Structure (theManager);
|
||||
myMapOfStructure.Bind (aStructure->Id, aStructure.get());
|
||||
return aStructure;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Structure
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure)
|
||||
{
|
||||
Vulkan_Structure* aStructure = NULL;
|
||||
if (!myMapOfStructure.Find (theCStructure->Id, aStructure))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
myMapOfStructure.UnBind (theCStructure->Id);
|
||||
/// TODO aStructure->Release (GetSharedContext());
|
||||
theCStructure.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : View
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Handle(Graphic3d_CView) Vulkan_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr)
|
||||
{
|
||||
Handle(Vulkan_View) aView = new Vulkan_View (theMgr, this);
|
||||
|
||||
myMapOfView.Add (aView);
|
||||
|
||||
for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
|
||||
{
|
||||
const Graphic3d_ZLayerId aLayerID = aLayerIt.Value();
|
||||
const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID);
|
||||
aView->AddZLayer (aLayerID);
|
||||
aView->SetZLayerSettings (aLayerID, aSettings);
|
||||
}
|
||||
|
||||
return aView;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : RemoveView
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_GraphicDriver::RemoveView (const Handle(Graphic3d_CView)& theView)
|
||||
{
|
||||
/**Handle(Vulkan_Context) aCtx = GetSharedContext();
|
||||
Handle(Vulkan_View) aView = Handle(Vulkan_View)::DownCast (theView);
|
||||
if (aView.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!myMapOfView.Remove (aView))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Handle(Vulkan_Window) aWindow = aView->GlWindow();
|
||||
if (!aWindow.IsNull()
|
||||
&& aWindow->GetGlContext()->MakeCurrent())
|
||||
{
|
||||
aCtx = aWindow->GetGlContext();
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to hijack another context if any
|
||||
const Handle(Vulkan_Context)& anOtherCtx = GetSharedContext();
|
||||
if (!anOtherCtx.IsNull()
|
||||
&& anOtherCtx != aWindow->GetGlContext())
|
||||
{
|
||||
aCtx = anOtherCtx;
|
||||
aCtx->MakeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
aView->ReleaseGlResources (aCtx);
|
||||
if (myMapOfView.IsEmpty())
|
||||
{
|
||||
// The last view removed but some objects still present.
|
||||
// Release GL resources now without object destruction.
|
||||
for (NCollection_DataMap<Standard_Integer, Vulkan_Structure*>::Iterator aStructIt (myMapOfStructure);
|
||||
aStructIt.More (); aStructIt.Next())
|
||||
{
|
||||
Vulkan_Structure* aStruct = aStructIt.ChangeValue();
|
||||
aStruct->ReleaseGlResources (aCtx);
|
||||
}
|
||||
|
||||
if (!myMapOfStructure.IsEmpty())
|
||||
{
|
||||
aView->StructureManager()->SetDeviceLost();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ViewExists
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean Vulkan_GraphicDriver::ViewExists (const Handle(Aspect_Window)& theWindow,
|
||||
Handle(Graphic3d_CView)& theView)
|
||||
{
|
||||
// Parse the list of views to find a view with the specified window
|
||||
/*#if defined(_WIN32) && !defined(OCCT_UWP)
|
||||
const Handle(WNT_Window) aWindowToFind = Handle(WNT_Window)::DownCast (theWindow);
|
||||
Aspect_Handle aWindowIdToFind = aWindowToFind->HWindow();
|
||||
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
|
||||
const Handle(Cocoa_Window) aWindowToFind = Handle(Cocoa_Window)::DownCast (theWindow);
|
||||
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
|
||||
UIView* aWindowIdToFind = aWindowToFind->HView();
|
||||
#else
|
||||
NSView* aWindowIdToFind = aWindowToFind->HView();
|
||||
#endif
|
||||
#elif defined(__ANDROID__) || defined(__QNX__) || defined(OCCT_UWP)
|
||||
(void )theWindow;
|
||||
int aWindowIdToFind = -1;
|
||||
#else
|
||||
const Handle(Xw_Window) aWindowToFind = Handle(Xw_Window)::DownCast (theWindow);
|
||||
int aWindowIdToFind = int (aWindowToFind->XWindow());
|
||||
#endif
|
||||
for (NCollection_Map<Handle(Vulkan_View)>::Iterator aViewIt (myMapOfView); aViewIt.More(); aViewIt.Next())
|
||||
{
|
||||
const Handle(Vulkan_View)& aView = aViewIt.Value();
|
||||
if (aView->IsDefined()
|
||||
&& aView->IsActive())
|
||||
{
|
||||
const Handle(Aspect_Window) anAspectWindow = aView->Window();
|
||||
|
||||
#if defined(_WIN32) && !defined(OCCT_UWP)
|
||||
const Handle(WNT_Window) aWindow = Handle(WNT_Window)::DownCast (anAspectWindow);
|
||||
Aspect_Handle aWindowIdOfView = aWindow->HWindow();
|
||||
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
|
||||
const Handle(Cocoa_Window) aWindow = Handle(Cocoa_Window)::DownCast (anAspectWindow);
|
||||
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
|
||||
UIView* aWindowIdOfView = aWindow->HView();
|
||||
#else
|
||||
NSView* aWindowIdOfView = aWindow->HView();
|
||||
#endif
|
||||
#elif defined(__ANDROID__) || defined(__QNX__) || defined(OCCT_UWP)
|
||||
int aWindowIdOfView = 0;
|
||||
#else
|
||||
const Handle(Xw_Window) aWindow = Handle(Xw_Window)::DownCast (anAspectWindow);
|
||||
int aWindowIdOfView = int(aWindow->XWindow());
|
||||
#endif
|
||||
if (aWindowIdOfView == aWindowIdToFind)
|
||||
{
|
||||
theView = aView;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return false;
|
||||
}
|
127
src/Vulkan/Vulkan_GraphicDriver.hxx
Normal file
127
src/Vulkan/Vulkan_GraphicDriver.hxx
Normal file
@@ -0,0 +1,127 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_GraphicDriver_HeaderFile
|
||||
#define _Vulkan_GraphicDriver_HeaderFile
|
||||
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
|
||||
class Vulkan_Caps;
|
||||
class Vulkan_Device;
|
||||
class Vulkan_Structure;
|
||||
class Vulkan_View;
|
||||
class Vulkan_Window;
|
||||
|
||||
//! This class defines an Vulkan graphic driver
|
||||
class Vulkan_GraphicDriver : public Graphic3d_GraphicDriver
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_GraphicDriver, Graphic3d_GraphicDriver)
|
||||
public:
|
||||
|
||||
//! This is VK_MAKE_VERSION() redefinition.
|
||||
//! Note that VK_MAKE_VERSION() uses different bits comparing to OCC_VERSION_HEX.
|
||||
static uint32_t DefineVersion (uint32_t theMajor, uint32_t theMinor, uint32_t thePatch)
|
||||
{
|
||||
return ((theMajor << 22) | (theMinor << 12) | thePatch);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
//! @param theAppName application name to be passed to Vulkan
|
||||
//! @param theAppVersion application version to be passed to Vulkan, see DefineVersion() method
|
||||
//! @param theDisp connection to display, required on Linux but optional on other systems
|
||||
Standard_EXPORT Vulkan_GraphicDriver (const TCollection_AsciiString& theAppName,
|
||||
const uint32_t theAppVersion,
|
||||
const Handle(Aspect_DisplayConnection)& theDisp);
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_GraphicDriver();
|
||||
|
||||
//! Release default context.
|
||||
Standard_EXPORT void ReleaseContext();
|
||||
|
||||
//! @return the visualization options
|
||||
Standard_EXPORT const Handle(Vulkan_Caps)& Options() const { return myCaps; }
|
||||
|
||||
//! Perform initialization of default OpenGL context.
|
||||
Standard_EXPORT Standard_Boolean InitContext();
|
||||
|
||||
//! Request limit of graphic resource of specific type.
|
||||
Standard_EXPORT virtual Standard_Integer InquireLimit (const Graphic3d_TypeOfLimit theType) const Standard_OVERRIDE;
|
||||
|
||||
public:
|
||||
|
||||
Standard_EXPORT virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual void RemoveView (const Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
|
||||
|
||||
public:
|
||||
|
||||
Standard_EXPORT virtual void TextSize (const Handle(Graphic3d_CView)& theView,
|
||||
const Standard_CString theText,
|
||||
const Standard_ShortReal theHeight,
|
||||
Standard_ShortReal& theWidth,
|
||||
Standard_ShortReal& theAscent,
|
||||
Standard_ShortReal& theDescent) const Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual Standard_ShortReal DefaultTextHeight() const Standard_OVERRIDE;
|
||||
|
||||
Standard_EXPORT virtual Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow,
|
||||
Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
|
||||
|
||||
public:
|
||||
|
||||
//! Adds a new top-level z layer with ID theLayerId for all views. Z layers allow drawing structures in higher layers
|
||||
//! in foreground of structures in lower layers. To add a structure to desired layer on display it is necessary to
|
||||
//! set the layer index for the structure. The passed theLayerId should be not less than 0 (reserved for default layers).
|
||||
Standard_EXPORT virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
|
||||
|
||||
//! Removes Z layer. All structures displayed at the moment in layer will be displayed in
|
||||
//! default layer (the bottom-level z layer). By default, there are always default
|
||||
//! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0
|
||||
//! (reserved for default layers that can not be removed).
|
||||
Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
|
||||
|
||||
//! Sets the settings for a single Z layer.
|
||||
Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
|
||||
|
||||
public:
|
||||
|
||||
//! Obsolete method.
|
||||
virtual void EnableVBO (const Standard_Boolean ) Standard_OVERRIDE {}
|
||||
|
||||
//! Returns information about GPU memory usage.
|
||||
//! Please read OpenGl_Context::MemoryInfo() for more description.
|
||||
Standard_EXPORT virtual Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes,
|
||||
TCollection_AsciiString& theInfo) const Standard_OVERRIDE;
|
||||
|
||||
public:
|
||||
|
||||
const Handle(Vulkan_Device)& Device() const { return myVkDevice; }
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_Device) myVkDevice;
|
||||
|
||||
Handle(Vulkan_Caps) myCaps;
|
||||
NCollection_Map<Handle(Vulkan_View)> myMapOfView;
|
||||
NCollection_DataMap<Standard_Integer, Vulkan_Structure*> myMapOfStructure;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_GraphicDriver_HeaderFile
|
337
src/Vulkan/Vulkan_Group.cxx
Normal file
337
src/Vulkan/Vulkan_Group.cxx
Normal file
@@ -0,0 +1,337 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Group.hxx>
|
||||
|
||||
#include <Graphic3d_ArrayOfPrimitives.hxx>
|
||||
#include <Graphic3d_GroupDefinitionError.hxx>
|
||||
#include <Graphic3d_Structure.hxx>
|
||||
#include <Vulkan_PrimitiveArray.hxx>
|
||||
#include <Vulkan_Structure.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Group, Graphic3d_Group)
|
||||
|
||||
namespace
|
||||
{
|
||||
//! Render element if it passes the filtering procedure. This method should
|
||||
//! be used for elements which can be used in scope of rendering algorithms.
|
||||
//! E.g. elements of groups during recursive rendering.
|
||||
//! If render filter is null, pure rendering is performed.
|
||||
//! @param theWorkspace [in] the rendering workspace.
|
||||
//! @param theFilter [in] the rendering filter to check whether the element
|
||||
//! should be rendered or not.
|
||||
//! @return True if element passes the check and renders,
|
||||
/*static bool renderFiltered (const Handle(OpenGl_Workspace)& theWorkspace,
|
||||
OpenGl_Element* theElement)
|
||||
{
|
||||
if (!theWorkspace->ShouldRender (theElement))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
theElement->Render (theWorkspace);
|
||||
return true;
|
||||
}*/
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Group
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Group::Vulkan_Group (const Handle(Graphic3d_Structure)& theStruct)
|
||||
: Graphic3d_Group (theStruct)
|
||||
//myAspects(NULL),
|
||||
//myFirst(NULL),
|
||||
//myLast(NULL)
|
||||
{
|
||||
const Vulkan_Structure* aStruct = dynamic_cast<Vulkan_Structure* >(myStructure->CStructure().get());
|
||||
if (aStruct == NULL)
|
||||
{
|
||||
throw Graphic3d_GroupDefinitionError("Vulkan_Group should be created by Vulkan_Structure!");
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Group
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Group::~Vulkan_Group()
|
||||
{
|
||||
/// TODO
|
||||
///Release (Handle(OpenGl_Context)());
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetGroupPrimitivesAspect
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect)
|
||||
{
|
||||
if (IsDeleted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (myAspects == NULL)
|
||||
{
|
||||
myAspects = new OpenGl_Aspects (theAspect);
|
||||
}
|
||||
else
|
||||
{
|
||||
myAspects->SetAspect (theAspect);
|
||||
}*/
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetPrimitivesAspect
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::SetPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect)
|
||||
{
|
||||
/*if (myAspects == NULL)
|
||||
{
|
||||
SetGroupPrimitivesAspect (theAspect);
|
||||
return;
|
||||
}
|
||||
else if (IsDeleted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OpenGl_Aspects* anAspects = new OpenGl_Aspects (theAspect);
|
||||
AddElement (anAspects);*/
|
||||
Update();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SynchronizeAspects
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::SynchronizeAspects()
|
||||
{
|
||||
/*if (myAspects != NULL)
|
||||
{
|
||||
myAspects->SynchronizeAspects();
|
||||
if (OpenGl_Structure* aStruct = myIsRaytracable ? GlStruct() : NULL)
|
||||
{
|
||||
aStruct->UpdateStateIfRaytracable (Standard_False);
|
||||
}
|
||||
}
|
||||
for (OpenGl_ElementNode* aNode = myFirst; aNode != NULL; aNode = aNode->next)
|
||||
{
|
||||
aNode->elem->SynchronizeAspects();
|
||||
}*/
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ReplaceAspects
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::ReplaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap)
|
||||
{
|
||||
if (theMap.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*Handle(Graphic3d_Aspects) anAspect;
|
||||
if (myAspects != NULL
|
||||
&& theMap.Find (myAspects->Aspect(), anAspect))
|
||||
{
|
||||
myAspects->SetAspect (anAspect);
|
||||
if (OpenGl_Structure* aStruct = myIsRaytracable ? GlStruct() : NULL)
|
||||
{
|
||||
aStruct->UpdateStateIfRaytracable (Standard_False);
|
||||
}
|
||||
}
|
||||
for (OpenGl_ElementNode* aNode = myFirst; aNode != NULL; aNode = aNode->next)
|
||||
{
|
||||
OpenGl_Aspects* aGlAspect = dynamic_cast<OpenGl_Aspects*> (aNode->elem);
|
||||
if (aGlAspect != NULL
|
||||
&& theMap.Find (aGlAspect->Aspect(), anAspect))
|
||||
{
|
||||
aGlAspect->SetAspect (anAspect);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AddPrimitiveArray
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
|
||||
const Handle(Graphic3d_IndexBuffer)& theIndices,
|
||||
const Handle(Graphic3d_Buffer)& theAttribs,
|
||||
const Handle(Graphic3d_BoundBuffer)& theBounds,
|
||||
const Standard_Boolean theToEvalMinMax)
|
||||
{
|
||||
if (IsDeleted()
|
||||
|| theAttribs.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Handle(Vulkan_PrimitiveArray) aPrimArray = new Vulkan_PrimitiveArray (theType, theIndices, theAttribs, theBounds);
|
||||
myElements.Append (aPrimArray);
|
||||
|
||||
Graphic3d_Group::AddPrimitiveArray (theType, theIndices, theAttribs, theBounds, theToEvalMinMax);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Text
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::Text (const Standard_CString theTextUtf,
|
||||
const Graphic3d_Vertex& thePoint,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Real theAngle,
|
||||
const Graphic3d_TextPath theTp,
|
||||
const Graphic3d_HorizontalTextAlignment theHta,
|
||||
const Graphic3d_VerticalTextAlignment theVta,
|
||||
const Standard_Boolean theToEvalMinMax)
|
||||
{
|
||||
if (IsDeleted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Graphic3d_Group::Text (theTextUtf, thePoint, theHeight, theAngle,
|
||||
theTp, theHta, theVta, theToEvalMinMax);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Text
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::Text (const Standard_CString theTextUtf,
|
||||
const gp_Ax2& theOrientation,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Real theAngle,
|
||||
const Graphic3d_TextPath theTp,
|
||||
const Graphic3d_HorizontalTextAlignment theHTA,
|
||||
const Graphic3d_VerticalTextAlignment theVTA,
|
||||
const Standard_Boolean theToEvalMinMax,
|
||||
const Standard_Boolean theHasOwnAnchor)
|
||||
{
|
||||
if (IsDeleted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Graphic3d_Group::Text (theTextUtf,
|
||||
theOrientation,
|
||||
theHeight,
|
||||
theAngle,
|
||||
theTp,
|
||||
theHTA,
|
||||
theVTA,
|
||||
theToEvalMinMax,
|
||||
theHasOwnAnchor);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetFlippingOptions
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::SetFlippingOptions (const Standard_Boolean ,
|
||||
const gp_Ax2& )
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetStencilTestOptions
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::SetStencilTestOptions (const Standard_Boolean )
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AddElement
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
/*void Vulkan_Group::AddElement (OpenGl_Element* theElem)
|
||||
{
|
||||
OpenGl_ElementNode *aNode = new OpenGl_ElementNode();
|
||||
|
||||
aNode->elem = theElem;
|
||||
aNode->next = NULL;
|
||||
(myLast? myLast->next : myFirst) = aNode;
|
||||
myLast = aNode;
|
||||
}*/
|
||||
|
||||
// =======================================================================
|
||||
// function : Render
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::Render (const Handle(Vulkan_Context)& theCtx) const
|
||||
{
|
||||
// Setup aspects
|
||||
/*theWorkspace->SetAllowFaceCulling (myIsClosed
|
||||
&& !theWorkspace->GetGlContext()->Clipping().IsClippingOrCappingOn());
|
||||
const OpenGl_Aspects* aBackAspects = theWorkspace->Aspects();
|
||||
const bool isAspectSet = myAspects != NULL && renderFiltered (theWorkspace, myAspects);*/
|
||||
|
||||
// Render group elements
|
||||
for (Vulkan_ListOfElements::Iterator aNodeIter (myElements); aNodeIter.More(); aNodeIter.Next())
|
||||
{
|
||||
aNodeIter.Value()->Render (theCtx);
|
||||
///renderFiltered (theWorkspace, aNodeIter->elem);
|
||||
}
|
||||
|
||||
// Restore aspects
|
||||
/*if (isAspectSet)
|
||||
theWorkspace->SetAspects (aBackAspects);*/
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Clear
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Group::Clear (const Standard_Boolean theToUpdateStructureMgr)
|
||||
{
|
||||
if (IsDeleted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
myElements.Clear();
|
||||
/*OpenGl_Structure* aStruct = GlStruct();
|
||||
const Handle(OpenGl_Context)& aCtx = aStruct->GlDriver()->GetSharedContext();
|
||||
|
||||
Release (aCtx);
|
||||
Graphic3d_Group::Clear (theToUpdateStructureMgr);*/
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Release
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
/*void Vulkan_Group::Release (const Handle(OpenGl_Context)& theGlCtx)
|
||||
{
|
||||
// Delete elements
|
||||
while (myFirst != NULL)
|
||||
{
|
||||
OpenGl_ElementNode* aNext = myFirst->next;
|
||||
OpenGl_Element::Destroy (theGlCtx.get(), myFirst->elem);
|
||||
delete myFirst;
|
||||
myFirst = aNext;
|
||||
}
|
||||
myLast = NULL;
|
||||
|
||||
OpenGl_Element::Destroy (theGlCtx.get(), myAspects);
|
||||
}*/
|
123
src/Vulkan/Vulkan_Group.hxx
Normal file
123
src/Vulkan/Vulkan_Group.hxx
Normal file
@@ -0,0 +1,123 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Group_HeaderFile
|
||||
#define _Vulkan_Group_HeaderFile
|
||||
|
||||
#include <Graphic3d_Group.hxx>
|
||||
|
||||
#include <NCollection_List.hxx>
|
||||
|
||||
class Vulkan_PrimitiveArray;
|
||||
typedef NCollection_List<Handle(Vulkan_PrimitiveArray)> Vulkan_ListOfElements;
|
||||
|
||||
class Vulkan_Context;
|
||||
|
||||
//! Implementation of low-level graphic group.
|
||||
class Vulkan_Group : public Graphic3d_Group
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Group, Graphic3d_Group)
|
||||
public:
|
||||
|
||||
//! Create empty group.
|
||||
//! Will throw exception if not created by OpenGl_Structure.
|
||||
Standard_EXPORT Vulkan_Group (const Handle(Graphic3d_Structure)& theStruct);
|
||||
|
||||
Standard_EXPORT virtual void Clear (const Standard_Boolean theToUpdateStructureMgr) Standard_OVERRIDE;
|
||||
|
||||
//! Return line aspect.
|
||||
virtual Handle(Graphic3d_Aspects) Aspects() const Standard_OVERRIDE
|
||||
{
|
||||
return Handle(Graphic3d_Aspects)();
|
||||
/*return myAspects != NULL
|
||||
? myAspects->Aspect()
|
||||
: Handle(Graphic3d_Aspects)();*/
|
||||
}
|
||||
|
||||
//! Update aspect.
|
||||
Standard_EXPORT virtual void SetGroupPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) Standard_OVERRIDE;
|
||||
|
||||
//! Append aspect as an element.
|
||||
Standard_EXPORT virtual void SetPrimitivesAspect (const Handle(Graphic3d_Aspects)& theAspect) Standard_OVERRIDE;
|
||||
|
||||
//! Update presentation aspects after their modification.
|
||||
Standard_EXPORT virtual void SynchronizeAspects() Standard_OVERRIDE;
|
||||
|
||||
//! Replace aspects specified in the replacement map.
|
||||
Standard_EXPORT virtual void ReplaceAspects (const Graphic3d_MapOfAspectsToAspects& theMap) Standard_OVERRIDE;
|
||||
|
||||
//! Add primitive array element
|
||||
Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
|
||||
const Handle(Graphic3d_IndexBuffer)& theIndices,
|
||||
const Handle(Graphic3d_Buffer)& theAttribs,
|
||||
const Handle(Graphic3d_BoundBuffer)& theBounds,
|
||||
const Standard_Boolean theToEvalMinMax) Standard_OVERRIDE;
|
||||
|
||||
//! Add text element
|
||||
Standard_EXPORT virtual void Text (const Standard_CString theTextUtf,
|
||||
const Graphic3d_Vertex& thePoint,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Real theAngle,
|
||||
const Graphic3d_TextPath theTp,
|
||||
const Graphic3d_HorizontalTextAlignment theHta,
|
||||
const Graphic3d_VerticalTextAlignment theVta,
|
||||
const Standard_Boolean theToEvalMinMax) Standard_OVERRIDE;
|
||||
|
||||
//! Add text element in 3D space.
|
||||
Standard_EXPORT virtual void Text (const Standard_CString theTextUtf,
|
||||
const gp_Ax2& theOrientation,
|
||||
const Standard_Real theHeight,
|
||||
const Standard_Real theAngle,
|
||||
const Graphic3d_TextPath theTp,
|
||||
const Graphic3d_HorizontalTextAlignment theHTA,
|
||||
const Graphic3d_VerticalTextAlignment theVTA,
|
||||
const Standard_Boolean theToEvalMinMax,
|
||||
const Standard_Boolean theHasOwnAnchor = Standard_True) Standard_OVERRIDE;
|
||||
|
||||
//! Add flipping element
|
||||
Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled,
|
||||
const gp_Ax2& theRefPlane) Standard_OVERRIDE;
|
||||
|
||||
//! Add stencil test element
|
||||
Standard_EXPORT virtual void SetStencilTestOptions (const Standard_Boolean theIsEnabled) Standard_OVERRIDE;
|
||||
|
||||
public:
|
||||
|
||||
//Vulkan_Structure* VkStruct() const { return (Vulkan_Structure* )(myStructure->CStructure().get()); }
|
||||
|
||||
//Standard_EXPORT void AddElement (OpenGl_Element* theElem);
|
||||
|
||||
Standard_EXPORT virtual void Render (const Handle(Vulkan_Context)& theCtx) const;
|
||||
//Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
|
||||
|
||||
//! Returns first OpenGL element node of the group.
|
||||
///const OpenGl_ElementNode* FirstNode() const { return myFirst; }
|
||||
|
||||
//! Returns OpenGL aspect.
|
||||
///const OpenGl_Aspects* GlAspects() const { return myAspects; }
|
||||
|
||||
protected:
|
||||
|
||||
Standard_EXPORT virtual ~Vulkan_Group();
|
||||
|
||||
///protected:
|
||||
public:
|
||||
|
||||
Vulkan_ListOfElements myElements;
|
||||
//OpenGl_Aspects* myAspects;
|
||||
//OpenGl_ElementNode* myFirst;
|
||||
//OpenGl_ElementNode* myLast;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Group_HeaderFile
|
153
src/Vulkan/Vulkan_Image.cxx
Normal file
153
src/Vulkan/Vulkan_Image.cxx
Normal file
@@ -0,0 +1,153 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Image.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_DeviceMemory.hxx>
|
||||
#include <Vulkan_DeviceMemoryAllocator.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Image, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Image
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Image::Vulkan_Image()
|
||||
: myVkFormat (new VkSurfaceFormatKHR()),
|
||||
myVkImage (NULL)
|
||||
{
|
||||
myVkFormat->format = VK_FORMAT_UNDEFINED;
|
||||
myVkFormat->colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Image
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Image::~Vulkan_Image()
|
||||
{
|
||||
releaseImage();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseImage
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Image::releaseImage()
|
||||
{
|
||||
if (myVkImageView != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_Image");
|
||||
vkDestroyImageView (myDevice->Device(), myVkImageView, myDevice->HostAllocator());
|
||||
myVkImageView = NULL;
|
||||
}
|
||||
if (myVkImage != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_Image");
|
||||
vkDestroyImage (myDevice->Device(), myVkImage, myDevice->HostAllocator());
|
||||
myVkImage = NULL;
|
||||
}
|
||||
myDepthMemory.Nullify();
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : CreateDepthStencil
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Image::CreateDepthStencil (const Handle(Vulkan_Device)& theDevice,
|
||||
const Graphic3d_Vec2u& theSize)
|
||||
{
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL
|
||||
|| theSize.x() == 0
|
||||
|| theSize.y() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
mySize = theSize;
|
||||
myVkFormat->format = VK_FORMAT_D32_SFLOAT_S8_UINT; ///VK_FORMAT_D24_UNORM_S8_UINT;///VK_FORMAT_D24_UNORM_S8_UINT;
|
||||
//myVkFormat->format = VK_FORMAT_D16_UNORM;
|
||||
|
||||
VkImageCreateInfo aDepthInfo = {};
|
||||
aDepthInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
aDepthInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
aDepthInfo.format = myVkFormat->format;
|
||||
aDepthInfo.extent = { theSize.x(), theSize.y(), 1 };
|
||||
aDepthInfo.mipLevels = 1;
|
||||
aDepthInfo.arrayLayers = 1;
|
||||
aDepthInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
aDepthInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
aDepthInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
aDepthInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
aDepthInfo.queueFamilyIndexCount = 0;
|
||||
aDepthInfo.pQueueFamilyIndices = NULL;
|
||||
///aDepthInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; /// TODO why???
|
||||
aDepthInfo.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkResult aRes = vkCreateImage (theDevice->Device(), &aDepthInfo, theDevice->HostAllocator(), &myVkImage);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create depth image", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
VkMemoryRequirements aMemReqs = {};
|
||||
vkGetImageMemoryRequirements (theDevice->Device(), myVkImage, &aMemReqs);
|
||||
myDepthMemory = theDevice->DeviceMemoryAllocator()->Allocate (aMemReqs, Vulkan_DeviceMemoryUsage_GpuOnly);
|
||||
if (myDepthMemory.IsNull())
|
||||
{
|
||||
logFailureAndRelease ("failed allocating depth image memory", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
const Vulkan_DeviceMemoryInfo aDevMemInfo = myDepthMemory->DeviceMemoryInfo();
|
||||
aRes = vkBindImageMemory (theDevice->Device(), myVkImage, aDevMemInfo.DeviceMemory, aDevMemInfo.Offset);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to bind image memory", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
VkImageViewCreateInfo aDepthImgViewInfo = {};
|
||||
aDepthImgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
aDepthImgViewInfo.image = myVkImage;
|
||||
aDepthImgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
aDepthImgViewInfo.format = aDepthInfo.format;
|
||||
aDepthImgViewInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
aDepthImgViewInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
aDepthImgViewInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
aDepthImgViewInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
aDepthImgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
aDepthImgViewInfo.subresourceRange.baseMipLevel = 0;
|
||||
aDepthImgViewInfo.subresourceRange.levelCount = 1;
|
||||
aDepthImgViewInfo.subresourceRange.baseArrayLayer = 0;
|
||||
aDepthImgViewInfo.subresourceRange.layerCount = 1;
|
||||
|
||||
aRes = vkCreateImageView (theDevice->Device(), &aDepthImgViewInfo, theDevice->HostAllocator(), &myVkImageView);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create image view", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
70
src/Vulkan/Vulkan_Image.hxx
Normal file
70
src/Vulkan/Vulkan_Image.hxx
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Image_HeaderFile
|
||||
#define _Vulkan_Image_HeaderFile
|
||||
|
||||
#include <Graphic3d_Vec2.hxx>
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Vulkan_DeviceMemory;
|
||||
|
||||
//! This class defines an Vulkan image.
|
||||
class Vulkan_Image : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Image, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_Image();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Image();
|
||||
|
||||
//! Return image.
|
||||
VkImage Image() const { return myVkImage; }
|
||||
|
||||
//! Return image view.
|
||||
VkImageView ImageView() const { return myVkImageView; }
|
||||
|
||||
//! Return image size.
|
||||
const Graphic3d_Vec2u& Size() const { return mySize; }
|
||||
|
||||
//! Return color surface format.
|
||||
const VkSurfaceFormatKHR& SurfaceFormat() const { return *myVkFormat; }
|
||||
|
||||
//! Create the object, @sa vkCreateImage(), vkCreateImageView().
|
||||
Standard_EXPORT bool CreateDepthStencil (const Handle(Vulkan_Device)& theDevice,
|
||||
const Graphic3d_Vec2u& theSize);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releaseImage(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyImage().
|
||||
Standard_EXPORT void releaseImage();
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_DeviceMemory) myDepthMemory;
|
||||
std::shared_ptr<VkSurfaceFormatKHR> myVkFormat;
|
||||
VkImage myVkImage;
|
||||
VkImageView myVkImageView;
|
||||
Graphic3d_Vec2u mySize;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Image_HeaderFile
|
62
src/Vulkan/Vulkan_Object.cxx
Normal file
62
src/Vulkan/Vulkan_Object.cxx
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Object, Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Object
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Object::Vulkan_Object()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Object
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Object::~Vulkan_Object()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : logFailure
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Object::logFailure (const TCollection_AsciiString& theMsg,
|
||||
int theVkErr,
|
||||
bool theToRelease)
|
||||
{
|
||||
if (theVkErr != VK_SUCCESS)
|
||||
{
|
||||
Message::DefaultMessenger()->Send (TCollection_AsciiString (DynamicType()->Name()) + ", " + theMsg + ": " + Vulkan_Device::FormatVkError (theVkErr));
|
||||
}
|
||||
else
|
||||
{
|
||||
Message::DefaultMessenger()->Send (TCollection_AsciiString (DynamicType()->Name()) + ", " + theMsg);
|
||||
}
|
||||
if (theToRelease)
|
||||
{
|
||||
Release();
|
||||
}
|
||||
}
|
76
src/Vulkan/Vulkan_Object.hxx
Normal file
76
src/Vulkan/Vulkan_Object.hxx
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Object_HeaderFile
|
||||
#define _Vulkan_Object_HeaderFile
|
||||
|
||||
#include <Vulkan_ForwardDecl.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
class Vulkan_Device;
|
||||
class TCollection_AsciiString;
|
||||
|
||||
//! Interface defining a Vulkan object.
|
||||
//! After initialization, object holds Vulkan_Device instance, so that it can be automatically released on destruction.
|
||||
//! Beware that Vulkan object might hold graphics memory, so that not releasing it at proper time could lead to memory issues.
|
||||
class Vulkan_Object : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Object, Standard_Transient)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_Object();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Object();
|
||||
|
||||
//! Release the object.
|
||||
void Release() { release(); }
|
||||
|
||||
//! Return the Vulkan device.
|
||||
const Handle(Vulkan_Device)& Device() const { return myDevice; }
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() = 0;
|
||||
|
||||
//! Log failure into messenger and release the object.
|
||||
void logFailureAndRelease (const TCollection_AsciiString& theMsg,
|
||||
int theVkErr)
|
||||
{
|
||||
logFailure (theMsg, theVkErr, true);
|
||||
}
|
||||
|
||||
//! Log failure into messenger.
|
||||
void logFailure (const TCollection_AsciiString& theMsg,
|
||||
int theVkErr,
|
||||
bool theToRelease = false);
|
||||
|
||||
//! @def Vulkan_AssertOnRelease
|
||||
//! Auxiliary macros to check that Vulkan object has been released in proper order.
|
||||
#ifdef _DEBUG
|
||||
#define Vulkan_AssertOnRelease(theName) \
|
||||
Standard_ASSERT_RETURN(!myDevice.IsNull(),theName##" destroyed without Vulkan device",); \
|
||||
Standard_ASSERT_RETURN(myDevice->Device()!=NULL,theName##"Vulkan_Buffer destroyed after Vulkan device destruction",);
|
||||
#else
|
||||
#define Vulkan_AssertOnRelease
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_Device) myDevice;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Object_HeaderFile
|
340
src/Vulkan/Vulkan_Pipeline.cxx
Normal file
340
src/Vulkan/Vulkan_Pipeline.cxx
Normal file
@@ -0,0 +1,340 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_Pipeline.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_PipelineCache.hxx>
|
||||
#include <Vulkan_PipelineLayout.hxx>
|
||||
#include <Vulkan_RenderPass.hxx>
|
||||
#include <Vulkan_Shader.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
//! Convert Graphic3d_TypeOfPrimitiveArray enumeration to VkPrimitiveTopology.
|
||||
VkPrimitiveTopology primType2VkTopology (Graphic3d_TypeOfPrimitiveArray thePrimType)
|
||||
{
|
||||
switch (thePrimType)
|
||||
{
|
||||
case Graphic3d_TOPA_POINTS: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
|
||||
case Graphic3d_TOPA_SEGMENTS: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
||||
case Graphic3d_TOPA_POLYLINES: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
|
||||
case Graphic3d_TOPA_TRIANGLES: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
case Graphic3d_TOPA_TRIANGLESTRIPS: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
|
||||
case Graphic3d_TOPA_TRIANGLEFANS: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
|
||||
//
|
||||
case Graphic3d_TOPA_LINES_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY;
|
||||
case Graphic3d_TOPA_LINE_STRIP_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY;
|
||||
case Graphic3d_TOPA_TRIANGLES_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY;
|
||||
case Graphic3d_TOPA_TRIANGLE_STRIP_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY;
|
||||
//
|
||||
case Graphic3d_TOPA_QUADRANGLES:
|
||||
case Graphic3d_TOPA_QUADRANGLESTRIPS:
|
||||
case Graphic3d_TOPA_POLYGONS:
|
||||
case Graphic3d_TOPA_UNDEFINED:
|
||||
return VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
|
||||
}
|
||||
return VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
|
||||
}
|
||||
|
||||
static VkFormat vertAttrib2VkFormat (Graphic3d_TypeOfData theType)
|
||||
{
|
||||
switch (theType)
|
||||
{
|
||||
case Graphic3d_TOD_USHORT: return VK_FORMAT_R16_UINT;
|
||||
case Graphic3d_TOD_UINT: return VK_FORMAT_R32_UINT;
|
||||
case Graphic3d_TOD_VEC2: return VK_FORMAT_R32G32_SFLOAT;
|
||||
case Graphic3d_TOD_VEC3: return VK_FORMAT_R32G32B32_SFLOAT;
|
||||
case Graphic3d_TOD_VEC4: return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
case Graphic3d_TOD_VEC4UB: return VK_FORMAT_B8G8R8A8_UNORM;
|
||||
case Graphic3d_TOD_FLOAT: return VK_FORMAT_R32_SFLOAT;
|
||||
}
|
||||
return VK_FORMAT_UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_Pipeline, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_Pipeline
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Pipeline::Vulkan_Pipeline()
|
||||
: myVkPipeline (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_Pipeline
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_Pipeline::~Vulkan_Pipeline()
|
||||
{
|
||||
releasePipeline();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releasePipeline
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_Pipeline::releasePipeline()
|
||||
{
|
||||
if (myVkPipeline != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_Pipeline");
|
||||
vkDestroyPipeline (myDevice->Device(), myVkPipeline, myDevice->HostAllocator());
|
||||
myVkPipeline = NULL;
|
||||
}
|
||||
myPipelineLayout.Nullify();
|
||||
myPipelineCache.Nullify();
|
||||
myShaderVert.Nullify();
|
||||
myShaderFrag.Nullify();
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_Pipeline::Create (const Handle(Vulkan_Device)& theDevice,
|
||||
const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_PipelineLayout)& theLayout,
|
||||
const Handle(Vulkan_Shader)& theShaderVert,
|
||||
const Handle(Vulkan_Shader)& theShaderFrag,
|
||||
const Graphic3d_Vec2u& theViewport,
|
||||
const Vulkun_PipelineCfg& theCfg)
|
||||
{
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL
|
||||
|| theShaderVert.IsNull()
|
||||
|| theShaderVert->Shader() == NULL
|
||||
|| theShaderFrag.IsNull()
|
||||
|| theShaderFrag->Shader() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
myShaderVert = theShaderVert;
|
||||
myShaderFrag = theShaderFrag;
|
||||
myPipelineLayout = theLayout;
|
||||
myCfg = theCfg;
|
||||
/*if (myPipelineLayout.IsNull())
|
||||
{
|
||||
myPipelineLayout = new Vulkan_PipelineLayout();
|
||||
if (!myPipelineLayout->Create (theDevice, NULL))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
if (myPipelineCache.IsNull())
|
||||
{
|
||||
myPipelineCache = new Vulkan_PipelineCache();
|
||||
if (!myPipelineCache->Create (theDevice))
|
||||
{
|
||||
Release();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
VkPipelineShaderStageCreateInfo aShaderStages[2] = {};
|
||||
{
|
||||
VkPipelineShaderStageCreateInfo& aVertStage = aShaderStages[0];
|
||||
aVertStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
aVertStage.pNext = NULL;
|
||||
aVertStage.flags = 0;
|
||||
aVertStage.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||
aVertStage.module = theShaderVert->Shader();
|
||||
aVertStage.pName = "main";
|
||||
aVertStage.pSpecializationInfo = NULL;
|
||||
}
|
||||
{
|
||||
VkPipelineShaderStageCreateInfo& aFragStage = aShaderStages[1];
|
||||
aFragStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
aFragStage.pNext = NULL;
|
||||
aFragStage.flags = 0;
|
||||
aFragStage.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
aFragStage.module = theShaderFrag->Shader();
|
||||
aFragStage.pName = "main";
|
||||
aFragStage.pSpecializationInfo = NULL;
|
||||
}
|
||||
|
||||
VkVertexInputBindingDescription aVertexInputBinding;
|
||||
aVertexInputBinding.binding = 0;
|
||||
aVertexInputBinding.stride = myCfg.Stride;
|
||||
aVertexInputBinding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
|
||||
std::vector<VkVertexInputAttributeDescription> aVertexInputAttributes (myCfg.NbAttributes);
|
||||
for (Standard_Integer anAttribIter = 0; anAttribIter < myCfg.NbAttributes; ++anAttribIter)
|
||||
{
|
||||
const Vulkun_VertexAttribute& anAttrib = myCfg.Attributes[anAttribIter];
|
||||
VkVertexInputAttributeDescription& anInAttrib = aVertexInputAttributes[anAttribIter];
|
||||
anInAttrib.location = anAttrib.Location;
|
||||
anInAttrib.binding = 0;
|
||||
anInAttrib.format = vertAttrib2VkFormat (anAttrib.DataType);
|
||||
anInAttrib.offset = anAttrib.Offset;
|
||||
}
|
||||
|
||||
VkPipelineVertexInputStateCreateInfo aVertexInput;
|
||||
aVertexInput.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
aVertexInput.pNext = NULL;
|
||||
aVertexInput.flags = 0;
|
||||
aVertexInput.vertexBindingDescriptionCount = 1;
|
||||
aVertexInput.pVertexBindingDescriptions = &aVertexInputBinding;
|
||||
aVertexInput.vertexAttributeDescriptionCount = (uint32_t )aVertexInputAttributes.size();
|
||||
aVertexInput.pVertexAttributeDescriptions = aVertexInputAttributes.data();
|
||||
|
||||
VkPipelineInputAssemblyStateCreateInfo anInputAssembly;
|
||||
anInputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||
anInputAssembly.pNext = NULL;
|
||||
anInputAssembly.flags = 0;
|
||||
anInputAssembly.topology = primType2VkTopology (myCfg.PrimType);
|
||||
anInputAssembly.primitiveRestartEnable = VK_FALSE;
|
||||
|
||||
VkViewport aViewport = {};
|
||||
aViewport.x = 0.0f;
|
||||
aViewport.y = (float )theViewport.y();
|
||||
aViewport.width = (float )theViewport.x();
|
||||
aViewport.height = -(float )theViewport.y();
|
||||
aViewport.minDepth = 0.0f;
|
||||
aViewport.maxDepth = 1.0f;
|
||||
VkRect2D aScissor = {};
|
||||
aScissor.offset.x = 0;
|
||||
aScissor.offset.y = 0;
|
||||
aScissor.extent.width = theViewport.x();
|
||||
aScissor.extent.height = theViewport.y();
|
||||
|
||||
VkPipelineViewportStateCreateInfo aViewportInfo;
|
||||
aViewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||
aViewportInfo.pNext = NULL;
|
||||
aViewportInfo.flags = 0;
|
||||
aViewportInfo.viewportCount = 1;
|
||||
aViewportInfo.pViewports = &aViewport;
|
||||
aViewportInfo.scissorCount = 1;
|
||||
aViewportInfo.pScissors = &aScissor;
|
||||
|
||||
VkPipelineRasterizationStateCreateInfo aRaster;
|
||||
aRaster.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
||||
aRaster.pNext = NULL;
|
||||
aRaster.flags = 0;
|
||||
aRaster.depthClampEnable = VK_FALSE;
|
||||
aRaster.rasterizerDiscardEnable = VK_FALSE;
|
||||
aRaster.polygonMode = VK_POLYGON_MODE_FILL;
|
||||
aRaster.cullMode = VK_CULL_MODE_BACK_BIT; ///VK_CULL_MODE_NONE;
|
||||
aRaster.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||
///aRaster.frontFace = VK_FRONT_FACE_CLOCKWISE;
|
||||
aRaster.depthBiasEnable = VK_FALSE;
|
||||
aRaster.depthBiasConstantFactor = 0.0f;
|
||||
aRaster.depthBiasClamp = 0.0f;
|
||||
aRaster.depthBiasSlopeFactor = 0.0f;
|
||||
aRaster.lineWidth = 1.0f;
|
||||
|
||||
VkPipelineMultisampleStateCreateInfo aMultisample;
|
||||
aMultisample.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||
aMultisample.pNext = NULL;
|
||||
aMultisample.flags = 0;
|
||||
aMultisample.rasterizationSamples = VkSampleCountFlagBits::VK_SAMPLE_COUNT_1_BIT;
|
||||
aMultisample.sampleShadingEnable = VK_FALSE;
|
||||
aMultisample.minSampleShading = 0;
|
||||
aMultisample.pSampleMask = NULL;
|
||||
aMultisample.alphaToCoverageEnable = VK_FALSE;
|
||||
aMultisample.alphaToOneEnable = VK_FALSE;
|
||||
|
||||
VkStencilOpState aNoOpStencil = {};
|
||||
aNoOpStencil.failOp = VK_STENCIL_OP_KEEP;
|
||||
aNoOpStencil.passOp = VK_STENCIL_OP_KEEP;
|
||||
aNoOpStencil.depthFailOp = VK_STENCIL_OP_KEEP;
|
||||
aNoOpStencil.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||
aNoOpStencil.compareMask = 0;
|
||||
aNoOpStencil.writeMask = 0;
|
||||
aNoOpStencil.reference = 0;
|
||||
|
||||
VkPipelineDepthStencilStateCreateInfo aDepthStencil;
|
||||
aDepthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||
aDepthStencil.pNext = NULL;
|
||||
aDepthStencil.flags = 0;
|
||||
aDepthStencil.depthTestEnable = VK_TRUE;
|
||||
aDepthStencil.depthWriteEnable = VK_TRUE;
|
||||
aDepthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
|
||||
aDepthStencil.depthBoundsTestEnable = VK_FALSE;
|
||||
aDepthStencil.stencilTestEnable = VK_FALSE;
|
||||
aDepthStencil.front = aNoOpStencil;
|
||||
aDepthStencil.back = aNoOpStencil;
|
||||
aDepthStencil.minDepthBounds = 0.0f;
|
||||
aDepthStencil.maxDepthBounds = 0.0f;
|
||||
|
||||
VkPipelineColorBlendAttachmentState aBlendAttachments;
|
||||
aBlendAttachments.blendEnable = VK_FALSE;
|
||||
aBlendAttachments.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
aBlendAttachments.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
aBlendAttachments.colorBlendOp = VK_BLEND_OP_ADD;
|
||||
aBlendAttachments.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
aBlendAttachments.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
aBlendAttachments.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
aBlendAttachments.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT;
|
||||
|
||||
VkPipelineColorBlendStateCreateInfo aBlending;
|
||||
aBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||
aBlending.pNext = NULL;
|
||||
aBlending.flags = 0;
|
||||
aBlending.logicOpEnable = VK_FALSE;
|
||||
aBlending.logicOp = VK_LOGIC_OP_CLEAR;
|
||||
aBlending.attachmentCount = 1;
|
||||
aBlending.pAttachments = &aBlendAttachments;
|
||||
aBlending.blendConstants;
|
||||
aBlending.blendConstants[0] = 1.0f;
|
||||
aBlending.blendConstants[1] = 1.0f;
|
||||
aBlending.blendConstants[2] = 1.0f;
|
||||
aBlending.blendConstants[3] = 1.0f;
|
||||
|
||||
VkGraphicsPipelineCreateInfo aPipeInfo;
|
||||
aPipeInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
aPipeInfo.pNext = NULL;
|
||||
aPipeInfo.flags = 0;
|
||||
aPipeInfo.stageCount = 2;
|
||||
aPipeInfo.pStages = aShaderStages;
|
||||
aPipeInfo.pVertexInputState = &aVertexInput;
|
||||
aPipeInfo.pInputAssemblyState = &anInputAssembly;
|
||||
aPipeInfo.pTessellationState = VK_NULL_HANDLE;
|
||||
aPipeInfo.pViewportState = &aViewportInfo;
|
||||
aPipeInfo.pRasterizationState = &aRaster;
|
||||
aPipeInfo.pMultisampleState = &aMultisample;
|
||||
aPipeInfo.pDepthStencilState = &aDepthStencil;
|
||||
aPipeInfo.pColorBlendState = &aBlending;
|
||||
aPipeInfo.pDynamicState = NULL;
|
||||
aPipeInfo.layout = myPipelineLayout->PipelineLayout();
|
||||
aPipeInfo.renderPass = theRenderPass->RenderPass();
|
||||
aPipeInfo.subpass = 0;
|
||||
aPipeInfo.basePipelineIndex = 0;
|
||||
aPipeInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||
|
||||
VkResult aRes = vkCreateGraphicsPipelines (theDevice->Device(),
|
||||
!myPipelineCache.IsNull() ? myPipelineCache->PipelineCache() : NULL,
|
||||
1, &aPipeInfo,
|
||||
theDevice->HostAllocator(), &myVkPipeline);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create pipeline", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
165
src/Vulkan/Vulkan_Pipeline.hxx
Normal file
165
src/Vulkan/Vulkan_Pipeline.hxx
Normal file
@@ -0,0 +1,165 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_Pipeline_HeaderFile
|
||||
#define _Vulkan_Pipeline_HeaderFile
|
||||
|
||||
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
|
||||
#include <Graphic3d_TypeOfShadingModel.hxx>
|
||||
#include <Graphic3d_Vec2.hxx>
|
||||
#include <Graphic3d_Buffer.hxx>
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
class Vulkan_PipelineCache;
|
||||
class Vulkan_PipelineLayout;
|
||||
class Vulkan_RenderPass;
|
||||
class Vulkan_Shader;
|
||||
|
||||
//! Close to Graphic3d_Attribute
|
||||
struct Vulkun_VertexAttribute
|
||||
{
|
||||
Graphic3d_TypeOfAttribute Location; //!< attribute identifier in vertex shader, 0 is reserved for vertex position
|
||||
Graphic3d_TypeOfData DataType; //!< vec2,vec3,vec4,vec4ub
|
||||
uint32_t Offset; //!< byte offset to the data within vertex buffer
|
||||
|
||||
Vulkun_VertexAttribute() : Location (Graphic3d_TOA_POS), DataType (Graphic3d_TOD_VEC3), Offset (0) {}
|
||||
|
||||
//! Matching two instances.
|
||||
bool IsEqual (const Vulkun_VertexAttribute& theOther) const
|
||||
{
|
||||
return Location == theOther.Location
|
||||
&& DataType == theOther.DataType
|
||||
&& Offset == theOther.Offset;
|
||||
}
|
||||
};
|
||||
|
||||
struct Vulkun_PipelineCfg
|
||||
{
|
||||
Graphic3d_TypeOfPrimitiveArray PrimType;
|
||||
Graphic3d_TypeOfShadingModel ShadingModel;
|
||||
Vulkun_VertexAttribute Attributes[5];
|
||||
Standard_Integer NbAttributes;
|
||||
uint32_t Stride;
|
||||
|
||||
Vulkun_PipelineCfg() : PrimType (Graphic3d_TOPA_UNDEFINED), ShadingModel (Graphic3d_TOSM_UNLIT), NbAttributes (0), Stride (0) {}
|
||||
|
||||
public:
|
||||
static const Standard_Integer THE_MAX_NB_ATTRIBUTES = 5;
|
||||
|
||||
//! Hash value, for Map interface.
|
||||
static Standard_Integer HashCode (const Vulkun_PipelineCfg& theCfg,
|
||||
const Standard_Integer theUpper)
|
||||
{
|
||||
uint32_t aHashCode = 0;
|
||||
aHashCode = aHashCode ^ ::HashCode (theCfg.PrimType, theUpper);
|
||||
aHashCode = aHashCode ^ ::HashCode (theCfg.NbAttributes, theUpper);
|
||||
aHashCode = aHashCode ^ ::HashCode (theCfg.ShadingModel, theUpper);
|
||||
return ::HashCode (Standard_Integer(aHashCode), theUpper);
|
||||
}
|
||||
|
||||
//! Matching two instances, for Map interface.
|
||||
bool IsEqual (const Vulkun_PipelineCfg& theOther) const
|
||||
{
|
||||
if (PrimType != theOther.PrimType
|
||||
|| NbAttributes != theOther.NbAttributes
|
||||
|| Stride != theOther.Stride)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
|
||||
{
|
||||
if (!Attributes[anAttribIter].IsEqual (theOther.Attributes[anAttribIter]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//! This class defines an Vulkan Pipeline.
|
||||
class Vulkan_Pipeline : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_Pipeline, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_Pipeline();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_Pipeline();
|
||||
|
||||
//! Return object.
|
||||
VkPipeline Pipeline() const { return myVkPipeline; }
|
||||
|
||||
//! Return pipeline layout.
|
||||
const Handle(Vulkan_PipelineLayout)& PipelineLayout() const { return myPipelineLayout; }
|
||||
|
||||
//! Create the object, @sa vkCreateGraphicsPipelines().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice,
|
||||
const Handle(Vulkan_RenderPass)& theRenderPass,
|
||||
const Handle(Vulkan_PipelineLayout)& theLayout,
|
||||
const Handle(Vulkan_Shader)& theShaderVert,
|
||||
const Handle(Vulkan_Shader)& theShaderFrag,
|
||||
const Graphic3d_Vec2u& theViewport,
|
||||
const Vulkun_PipelineCfg& theCfg);
|
||||
|
||||
//! Return primitive array type.
|
||||
const Vulkun_PipelineCfg& Configuration() const { return myCfg; }
|
||||
|
||||
//! Equality check.
|
||||
bool IsEqual (const Handle(Vulkan_Pipeline)& theOther) const
|
||||
{
|
||||
return !theOther.IsNull()
|
||||
&& (theOther == this
|
||||
|| myCfg.IsEqual (theOther->myCfg));
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
//! Hash value, for Map interface.
|
||||
static Standard_Integer HashCode (const Handle(Vulkan_Pipeline)& thePipeline,
|
||||
const Standard_Integer theUpper)
|
||||
{
|
||||
return !thePipeline.IsNull()
|
||||
? Vulkun_PipelineCfg::HashCode (thePipeline->myCfg, theUpper)
|
||||
: 1;
|
||||
}
|
||||
|
||||
//! Matching two instances, for Map interface.
|
||||
static bool IsEqual (const Handle(Vulkan_Pipeline)& thePipeline1,
|
||||
const Handle(Vulkan_Pipeline)& thePipeline2)
|
||||
{
|
||||
return thePipeline1->IsEqual (thePipeline2);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releasePipeline(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyPipeline().
|
||||
Standard_EXPORT void releasePipeline();
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_Shader) myShaderVert;
|
||||
Handle(Vulkan_Shader) myShaderFrag;
|
||||
Handle(Vulkan_PipelineCache) myPipelineCache;
|
||||
Handle(Vulkan_PipelineLayout) myPipelineLayout;
|
||||
VkPipeline myVkPipeline;
|
||||
Vulkun_PipelineCfg myCfg;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_Pipeline_HeaderFile
|
93
src/Vulkan/Vulkan_PipelineCache.cxx
Normal file
93
src/Vulkan/Vulkan_PipelineCache.cxx
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_PipelineCache.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_PipelineCache, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_PipelineCache
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_PipelineCache::Vulkan_PipelineCache()
|
||||
: myVkPipelineCache (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_PipelineCache
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_PipelineCache::~Vulkan_PipelineCache()
|
||||
{
|
||||
releasePipelineCache();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releasePipelineCache
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_PipelineCache::releasePipelineCache()
|
||||
{
|
||||
if (myVkPipelineCache != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_PipelineCache");
|
||||
vkDestroyPipelineCache (myDevice->Device(), myVkPipelineCache, myDevice->HostAllocator());
|
||||
myVkPipelineCache = NULL;
|
||||
}
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_PipelineCache::Create (const Handle(Vulkan_Device)& theDevice)
|
||||
{
|
||||
if (myVkPipelineCache != NULL
|
||||
&& myDevice == theDevice)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
|
||||
VkPipelineCacheCreateInfo aVkPipelineCacheInfo;
|
||||
aVkPipelineCacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
|
||||
aVkPipelineCacheInfo.pNext = NULL;
|
||||
aVkPipelineCacheInfo.flags = 0;
|
||||
aVkPipelineCacheInfo.initialDataSize = 0;
|
||||
aVkPipelineCacheInfo.pInitialData = NULL;
|
||||
|
||||
VkResult aRes = vkCreatePipelineCache (theDevice->Device(), &aVkPipelineCacheInfo, theDevice->HostAllocator(), &myVkPipelineCache);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create pipeline cache", aRes);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
51
src/Vulkan/Vulkan_PipelineCache.hxx
Normal file
51
src/Vulkan/Vulkan_PipelineCache.hxx
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_PipelineCache_HeaderFile
|
||||
#define _Vulkan_PipelineCache_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
//! This class defines an Vulkan Pipeline Cache.
|
||||
class Vulkan_PipelineCache : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_PipelineCache, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_PipelineCache();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_PipelineCache();
|
||||
|
||||
//! Return object.
|
||||
VkPipelineCache PipelineCache() const { return myVkPipelineCache; }
|
||||
|
||||
//! Create the object, @sa vkCreatePipelineCache().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releasePipelineCache(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyPipelineCache().
|
||||
Standard_EXPORT void releasePipelineCache();
|
||||
|
||||
protected:
|
||||
|
||||
VkPipelineCache myVkPipelineCache;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_PipelineCache_HeaderFile
|
101
src/Vulkan/Vulkan_PipelineLayout.cxx
Normal file
101
src/Vulkan/Vulkan_PipelineLayout.cxx
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_PipelineLayout.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_DescriptorSetLayout.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_PipelineLayout, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_PipelineLayout
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_PipelineLayout::Vulkan_PipelineLayout()
|
||||
: myVkPipelineLayout (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_PipelineLayout
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_PipelineLayout::~Vulkan_PipelineLayout()
|
||||
{
|
||||
releasePipelineLayout();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releasePipelineLayout
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_PipelineLayout::releasePipelineLayout()
|
||||
{
|
||||
if (myVkPipelineLayout != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_PipelineLayout");
|
||||
vkDestroyPipelineLayout (myDevice->Device(), myVkPipelineLayout, myDevice->HostAllocator());
|
||||
myVkPipelineLayout = NULL;
|
||||
}
|
||||
myDescSetLayout.Nullify();
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_PipelineLayout::Create (const Handle(Vulkan_Device)& theDevice,
|
||||
const Handle(Vulkan_DescriptorSetLayout)& theDescSetLayout)
|
||||
{
|
||||
if (myVkPipelineLayout != NULL
|
||||
&& myDevice == theDevice
|
||||
&& myDescSetLayout == theDescSetLayout)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
myDescSetLayout = theDescSetLayout;
|
||||
|
||||
VkPipelineLayoutCreateInfo aVkPipelineLayoutInfo;
|
||||
aVkPipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||
aVkPipelineLayoutInfo.pNext = NULL;
|
||||
aVkPipelineLayoutInfo.flags = 0;
|
||||
aVkPipelineLayoutInfo.setLayoutCount = 1;
|
||||
aVkPipelineLayoutInfo.pSetLayouts = &theDescSetLayout->DescriptorSetLayout();
|
||||
aVkPipelineLayoutInfo.pushConstantRangeCount = 0;
|
||||
aVkPipelineLayoutInfo.pPushConstantRanges = NULL;
|
||||
|
||||
VkResult aRes = vkCreatePipelineLayout (theDevice->Device(), &aVkPipelineLayoutInfo, theDevice->HostAllocator(), &myVkPipelineLayout);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create pipeline layout", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
55
src/Vulkan/Vulkan_PipelineLayout.hxx
Normal file
55
src/Vulkan/Vulkan_PipelineLayout.hxx
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_PipelineLayout_HeaderFile
|
||||
#define _Vulkan_PipelineLayout_HeaderFile
|
||||
|
||||
#include <Vulkan_Object.hxx>
|
||||
|
||||
class Vulkan_DescriptorSetLayout;
|
||||
|
||||
//! This class defines an Vulkan Pipeline Layout.
|
||||
class Vulkan_PipelineLayout : public Vulkan_Object
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_PipelineLayout, Vulkan_Object)
|
||||
public:
|
||||
|
||||
//! Constructor.
|
||||
Standard_EXPORT Vulkan_PipelineLayout();
|
||||
|
||||
//! Destructor.
|
||||
Standard_EXPORT virtual ~Vulkan_PipelineLayout();
|
||||
|
||||
//! Return object.
|
||||
VkPipelineLayout PipelineLayout() const { return myVkPipelineLayout; }
|
||||
|
||||
//! Create the object, @sa vkCreatePipelineLayout().
|
||||
Standard_EXPORT bool Create (const Handle(Vulkan_Device)& theDevice,
|
||||
const Handle(Vulkan_DescriptorSetLayout)& theDescSetLayout);
|
||||
|
||||
protected:
|
||||
|
||||
//! Release the object.
|
||||
virtual void release() Standard_OVERRIDE { releasePipelineLayout(); }
|
||||
|
||||
//! Release the object, @sa vkDestroyPipelineLayout().
|
||||
Standard_EXPORT void releasePipelineLayout();
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Vulkan_DescriptorSetLayout) myDescSetLayout;
|
||||
VkPipelineLayout myVkPipelineLayout;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_PipelineLayout_HeaderFile
|
124
src/Vulkan/Vulkan_PrimitiveArray.cxx
Normal file
124
src/Vulkan/Vulkan_PrimitiveArray.cxx
Normal file
@@ -0,0 +1,124 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_PrimitiveArray.hxx>
|
||||
|
||||
#include <Graphic3d_ArrayOfPrimitives.hxx>
|
||||
#include <Graphic3d_GroupDefinitionError.hxx>
|
||||
#include <Graphic3d_Structure.hxx>
|
||||
#include <Vulkan_Buffer.hxx>
|
||||
#include <Vulkan_CommandBuffer.hxx>
|
||||
#include <Vulkan_Context.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_PrimitiveArray, Standard_Transient)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_PrimitiveArray
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_PrimitiveArray::Vulkan_PrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
|
||||
const Handle(Graphic3d_IndexBuffer)& theIndices,
|
||||
const Handle(Graphic3d_Buffer)& theAttribs,
|
||||
const Handle(Graphic3d_BoundBuffer)& theBounds)
|
||||
: myIndices (theIndices),
|
||||
myAttribs (theAttribs),
|
||||
myBounds (theBounds),
|
||||
myType (theType)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_PrimitiveArray
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_PrimitiveArray::~Vulkan_PrimitiveArray()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Release
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_PrimitiveArray::Release()
|
||||
{
|
||||
myVboAttribs.Nullify();
|
||||
myVboIndices.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Render
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_PrimitiveArray::Render (const Handle(Vulkan_Context)& theCtx)
|
||||
{
|
||||
if (myVboAttribs.IsNull()
|
||||
&& !myAttribs.IsNull())
|
||||
{
|
||||
myVboAttribs = new Vulkan_Buffer();
|
||||
myVboAttribs->init (theCtx->Device(), myAttribs->Data(), myAttribs->Size(), Vulkan_BufferType_Vertex);
|
||||
}
|
||||
if (myVboIndices.IsNull()
|
||||
&& !myIndices.IsNull())
|
||||
{
|
||||
myVboIndices = new Vulkan_Buffer();
|
||||
myVboIndices->init (theCtx->Device(), myIndices->Data(), myIndices->Size(), Vulkan_BufferType_Index);
|
||||
}
|
||||
|
||||
if (myVboAttribs.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vulkun_PipelineCfg aCfg;
|
||||
aCfg.PrimType = myType;
|
||||
aCfg.NbAttributes = Min (myAttribs->NbAttributes, Vulkun_PipelineCfg::THE_MAX_NB_ATTRIBUTES);
|
||||
aCfg.Stride = myAttribs->IsInterleaved() ? myAttribs->Stride : 0;
|
||||
aCfg.ShadingModel = Graphic3d_TOSM_UNLIT;
|
||||
if (int(aCfg.PrimType) >= int(Graphic3d_TOPA_TRIANGLES))
|
||||
{
|
||||
aCfg.ShadingModel = aCfg.NbAttributes > 1 ? Graphic3d_TOSM_FRAGMENT : Graphic3d_TOSM_FACET;
|
||||
}
|
||||
uint32_t anOffset = 0;
|
||||
for (Standard_Integer anAttribIter = 0; anAttribIter < aCfg.NbAttributes; ++anAttribIter)
|
||||
{
|
||||
const Graphic3d_Attribute& anAttribSrc = myAttribs->Attribute (anAttribIter);
|
||||
Vulkun_VertexAttribute& anAttribDst = aCfg.Attributes[anAttribIter];
|
||||
anAttribDst.Location = anAttribSrc.Id;
|
||||
anAttribDst.DataType = anAttribSrc.DataType;
|
||||
anAttribDst.Offset = anOffset;
|
||||
|
||||
if (myAttribs->IsInterleaved())
|
||||
{
|
||||
anOffset += anAttribSrc.Stride();
|
||||
}
|
||||
}
|
||||
|
||||
VkBuffer aVkVertBuffers[1] = { myVboAttribs->Buffer() };
|
||||
VkDeviceSize aVkVertOffsets[1] = {0};
|
||||
const VkCommandBuffer& aVkCmdBuffer = theCtx->CommandBuffer()->CommandBuffer();
|
||||
theCtx->ActivatePipeline (aCfg);
|
||||
vkCmdBindVertexBuffers (aVkCmdBuffer, 0, 1, aVkVertBuffers, aVkVertOffsets);
|
||||
if (!myVboIndices.IsNull())
|
||||
{
|
||||
vkCmdBindIndexBuffer (aVkCmdBuffer, myVboIndices->Buffer(), 0, myIndices->Stride == 4 ? VK_INDEX_TYPE_UINT32 : VK_INDEX_TYPE_UINT16);
|
||||
vkCmdDrawIndexed (aVkCmdBuffer, myIndices->NbElements, 1, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
vkCmdDraw (aVkCmdBuffer, myAttribs->NbElements, 1, 0, 0);
|
||||
}
|
||||
}
|
54
src/Vulkan/Vulkan_PrimitiveArray.hxx
Normal file
54
src/Vulkan/Vulkan_PrimitiveArray.hxx
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _Vulkan_PrimitiveArray_HeaderFile
|
||||
#define _Vulkan_PrimitiveArray_HeaderFile
|
||||
|
||||
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
|
||||
class Graphic3d_Buffer;
|
||||
class Graphic3d_BoundBuffer;
|
||||
class Graphic3d_IndexBuffer;
|
||||
class Vulkan_Context;
|
||||
class Vulkan_Buffer;
|
||||
|
||||
class Vulkan_PrimitiveArray : public Standard_Transient
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(Vulkan_PrimitiveArray, Standard_Transient)
|
||||
public:
|
||||
|
||||
Standard_EXPORT Vulkan_PrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
|
||||
const Handle(Graphic3d_IndexBuffer)& theIndices,
|
||||
const Handle(Graphic3d_Buffer)& theAttribs,
|
||||
const Handle(Graphic3d_BoundBuffer)& theBounds);
|
||||
|
||||
Standard_EXPORT virtual ~Vulkan_PrimitiveArray();
|
||||
|
||||
Standard_EXPORT virtual void Release();
|
||||
|
||||
Standard_EXPORT virtual void Render (const Handle(Vulkan_Context)& theCtx);
|
||||
|
||||
protected:
|
||||
|
||||
Handle(Graphic3d_IndexBuffer) myIndices;
|
||||
Handle(Graphic3d_Buffer) myAttribs;
|
||||
Handle(Graphic3d_BoundBuffer) myBounds;
|
||||
|
||||
Handle(Vulkan_Buffer) myVboAttribs;
|
||||
Handle(Vulkan_Buffer) myVboIndices;
|
||||
Graphic3d_TypeOfPrimitiveArray myType;
|
||||
|
||||
};
|
||||
|
||||
#endif // _Vulkan_PrimitiveArray_HeaderFile
|
142
src/Vulkan/Vulkan_RenderPass.cxx
Normal file
142
src/Vulkan/Vulkan_RenderPass.cxx
Normal file
@@ -0,0 +1,142 @@
|
||||
// Copyright (c) 2019 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <Vulkan_RenderPass.hxx>
|
||||
|
||||
#include <Message.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
#include <Vulkan_Device.hxx>
|
||||
#include <Vulkan_Image.hxx>
|
||||
#include <Vulkan_Surface.hxx>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Vulkan_RenderPass, Vulkan_Object)
|
||||
|
||||
// =======================================================================
|
||||
// function : Vulkan_RenderPass
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_RenderPass::Vulkan_RenderPass()
|
||||
: myVkRenderPass (NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~Vulkan_RenderPass
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Vulkan_RenderPass::~Vulkan_RenderPass()
|
||||
{
|
||||
releaseRenderPass();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : releaseRenderPass
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Vulkan_RenderPass::releaseRenderPass()
|
||||
{
|
||||
if (myVkRenderPass != NULL)
|
||||
{
|
||||
Vulkan_AssertOnRelease("Vulkan_RenderPass");
|
||||
vkDestroyRenderPass (myDevice->Device(), myVkRenderPass, myDevice->HostAllocator());
|
||||
myVkRenderPass = NULL;
|
||||
}
|
||||
myDevice.Nullify();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Create
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Vulkan_RenderPass::Create (const Handle(Vulkan_Device)& theDevice,
|
||||
const Handle(Vulkan_Surface)& theSurface)
|
||||
{
|
||||
Release();
|
||||
if (theDevice.IsNull()
|
||||
|| theDevice->Device() == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
myDevice = theDevice;
|
||||
|
||||
VkAttachmentDescription aVkAttachments[2] = {};
|
||||
{
|
||||
VkAttachmentDescription& aColorAttach = aVkAttachments[0];
|
||||
aColorAttach.flags = 0;
|
||||
aColorAttach.format = !theSurface.IsNull() ? theSurface->ColorFormat().format : VK_FORMAT_UNDEFINED;
|
||||
aColorAttach.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
aColorAttach.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
aColorAttach.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
aColorAttach.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
aColorAttach.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
aColorAttach.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
aColorAttach.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
if (!theSurface->DepthImage().IsNull())
|
||||
{
|
||||
VkAttachmentDescription& aDepthAttach = aVkAttachments[1];
|
||||
aDepthAttach.flags = 0;
|
||||
aDepthAttach.format = theSurface->DepthImage()->SurfaceFormat().format;
|
||||
aDepthAttach.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
aDepthAttach.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
aDepthAttach.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
aDepthAttach.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
aDepthAttach.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
aDepthAttach.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
aDepthAttach.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
|
||||
VkAttachmentReference aColorAttachRef = {};
|
||||
aColorAttachRef.attachment = 0;
|
||||
aColorAttachRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkAttachmentReference aDepthAttachRef = {};
|
||||
aDepthAttachRef.attachment = 1;
|
||||
aDepthAttachRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkSubpassDescription aVkSubpassDesc;
|
||||
aVkSubpassDesc.flags = 0;
|
||||
aVkSubpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
aVkSubpassDesc.inputAttachmentCount = 0;
|
||||
aVkSubpassDesc.pInputAttachments = NULL;
|
||||
aVkSubpassDesc.colorAttachmentCount = 1;
|
||||
aVkSubpassDesc.pColorAttachments = &aColorAttachRef;
|
||||
aVkSubpassDesc.pResolveAttachments = NULL;
|
||||
aVkSubpassDesc.pDepthStencilAttachment = &aDepthAttachRef;
|
||||
aVkSubpassDesc.preserveAttachmentCount = 0;
|
||||
aVkSubpassDesc.pPreserveAttachments = NULL;
|
||||
|
||||
VkRenderPassCreateInfo aVkRenderPassInfo;
|
||||
aVkRenderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
aVkRenderPassInfo.pNext = NULL;
|
||||
aVkRenderPassInfo.flags = 0;
|
||||
aVkRenderPassInfo.attachmentCount = !theSurface->DepthImage().IsNull() ? 2 : 1;
|
||||
aVkRenderPassInfo.pAttachments = aVkAttachments;
|
||||
aVkRenderPassInfo.subpassCount = 1;
|
||||
aVkRenderPassInfo.pSubpasses = &aVkSubpassDesc;
|
||||
aVkRenderPassInfo.dependencyCount = 0;
|
||||
aVkRenderPassInfo.pDependencies = NULL;
|
||||
|
||||
VkResult aRes = vkCreateRenderPass (theDevice->Device(), &aVkRenderPassInfo, theDevice->HostAllocator(), &myVkRenderPass);
|
||||
if (aRes != VK_SUCCESS)
|
||||
{
|
||||
logFailureAndRelease ("failed to create render pass", aRes);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user