File indexing completed on 2026-10-02 09:13:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef OpenGl_Workspace_HeaderFile
0017 #define OpenGl_Workspace_HeaderFile
0018
0019 #include <Graphic3d_BufferType.hxx>
0020 #include <Graphic3d_PresentationAttributes.hxx>
0021
0022 #include <OpenGl_Aspects.hxx>
0023 #include <OpenGl_Vec.hxx>
0024
0025 class OpenGl_FrameBuffer;
0026 class OpenGl_Group;
0027 class OpenGl_View;
0028 class OpenGl_Window;
0029 class Image_PixMap;
0030
0031
0032
0033 class OpenGl_Workspace : public Standard_Transient
0034 {
0035 public:
0036
0037 Standard_EXPORT OpenGl_Workspace(OpenGl_View* theView,
0038 const occ::handle<OpenGl_Window>& theWindow);
0039
0040
0041 ~OpenGl_Workspace() override = default;
0042
0043
0044 Standard_EXPORT bool Activate();
0045
0046 OpenGl_View* View() const { return myView; }
0047
0048 const occ::handle<OpenGl_Context>& GetGlContext() { return myGlContext; }
0049
0050 Standard_EXPORT occ::handle<OpenGl_FrameBuffer> FBOCreate(const int theWidth,
0051 const int theHeight);
0052
0053 Standard_EXPORT void FBORelease(occ::handle<OpenGl_FrameBuffer>& theFbo);
0054
0055 bool BufferDump(const occ::handle<OpenGl_FrameBuffer>& theFbo,
0056 Image_PixMap& theImage,
0057 const Graphic3d_BufferType& theBufferType);
0058
0059 Standard_EXPORT int Width() const;
0060
0061 Standard_EXPORT int Height() const;
0062
0063
0064
0065 bool SetUseZBuffer(const bool theToUse)
0066 {
0067 const bool wasUsed = myUseZBuffer;
0068 myUseZBuffer = theToUse;
0069 return wasUsed;
0070 }
0071
0072
0073 bool& UseZBuffer() { return myUseZBuffer; }
0074
0075
0076 bool& UseDepthWrite() { return myUseDepthWrite; }
0077
0078
0079
0080 Standard_EXPORT Graphic3d_PolygonOffset
0081 SetDefaultPolygonOffset(const Graphic3d_PolygonOffset& theOffset);
0082
0083
0084
0085
0086 bool ToAllowFaceCulling() const { return myToAllowFaceCulling; }
0087
0088
0089
0090
0091 bool SetAllowFaceCulling(bool theToAllow)
0092 {
0093 const bool wasAllowed = myToAllowFaceCulling;
0094 myToAllowFaceCulling = theToAllow;
0095 return wasAllowed;
0096 }
0097
0098
0099 bool ToHighlight() const { return !myHighlightStyle.IsNull(); }
0100
0101
0102 const occ::handle<Graphic3d_PresentationAttributes>& HighlightStyle() const
0103 {
0104 return myHighlightStyle;
0105 }
0106
0107
0108 void SetHighlightStyle(const occ::handle<Graphic3d_PresentationAttributes>& theStyle)
0109 {
0110 myHighlightStyle = theStyle;
0111 }
0112
0113
0114 const NCollection_Vec4<float>& EdgeColor() const
0115 {
0116 return !myHighlightStyle.IsNull() ? myHighlightStyle->ColorRGBA()
0117 : myAspectsSet->Aspect()->EdgeColorRGBA();
0118 }
0119
0120
0121 const NCollection_Vec4<float>& InteriorColor() const
0122 {
0123 return !myHighlightStyle.IsNull() ? myHighlightStyle->ColorRGBA()
0124 : myAspectsSet->Aspect()->InteriorColorRGBA();
0125 }
0126
0127
0128 const NCollection_Vec4<float>& BackInteriorColor() const
0129 {
0130 return !myHighlightStyle.IsNull() ? myHighlightStyle->ColorRGBA()
0131 : myAspectsSet->Aspect()->Distinguish() ? myAspectsSet->Aspect()->BackInteriorColorRGBA()
0132 : myAspectsSet->Aspect()->InteriorColorRGBA();
0133 }
0134
0135
0136 const NCollection_Vec4<float>& TextColor() const
0137 {
0138 return !myHighlightStyle.IsNull() ? myHighlightStyle->ColorRGBA()
0139 : myAspectsSet->Aspect()->ColorRGBA();
0140 }
0141
0142
0143 const NCollection_Vec4<float>& TextSubtitleColor() const
0144 {
0145 return !myHighlightStyle.IsNull() ? myHighlightStyle->ColorRGBA()
0146 : myAspectsSet->Aspect()->ColorSubTitleRGBA();
0147 }
0148
0149
0150 const OpenGl_Aspects* Aspects() const { return myAspectsSet; }
0151
0152
0153 Standard_EXPORT const OpenGl_Aspects* SetAspects(const OpenGl_Aspects* theAspect);
0154
0155
0156 const occ::handle<OpenGl_TextureSet>& TextureSet() const
0157 {
0158 const occ::handle<OpenGl_TextureSet>& aTextureSet =
0159 myAspectsSet->TextureSet(myGlContext, ToHighlight());
0160 return !aTextureSet.IsNull() || myAspectsSet->Aspect()->ToMapTexture() ? aTextureSet
0161 : myEnvironmentTexture;
0162 }
0163
0164
0165
0166
0167 Standard_EXPORT const OpenGl_Aspects* ApplyAspects(bool theToBindTextures = true);
0168
0169
0170 void ResetAppliedAspect();
0171
0172
0173
0174 int RenderFilter() const { return myRenderFilter; }
0175
0176
0177
0178 void SetRenderFilter(int theFilter) { myRenderFilter = theFilter; }
0179
0180
0181
0182
0183
0184 bool ShouldRender(const OpenGl_Element* theElement, const OpenGl_Group* theGroup);
0185
0186
0187
0188
0189 int NbSkippedTransparentElements() { return myNbSkippedTranspElems; }
0190
0191
0192
0193 void ResetSkippedCounter() { myNbSkippedTranspElems = 0; }
0194
0195
0196 const OpenGl_Aspects& NoneCulling() const { return myNoneCulling; }
0197
0198
0199 const OpenGl_Aspects& FrontCulling() const { return myFrontCulling; }
0200
0201
0202 void SetEnvironmentTexture(const occ::handle<OpenGl_TextureSet>& theTexture)
0203 {
0204 myEnvironmentTexture = theTexture;
0205 }
0206
0207
0208 const occ::handle<OpenGl_TextureSet>& EnvironmentTexture() const { return myEnvironmentTexture; }
0209
0210
0211 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0212
0213 protected:
0214 OpenGl_View* myView;
0215 occ::handle<OpenGl_Window> myWindow;
0216 occ::handle<OpenGl_Context> myGlContext;
0217 bool myUseZBuffer;
0218 bool myUseDepthWrite;
0219 OpenGl_Aspects myNoneCulling;
0220 OpenGl_Aspects myFrontCulling;
0221
0222 protected:
0223
0224 int myNbSkippedTranspElems;
0225 int myRenderFilter;
0226
0227
0228 OpenGl_Aspects myDefaultAspects;
0229 const OpenGl_Aspects* myAspectsSet;
0230 occ::handle<Graphic3d_Aspects> myAspectsApplied;
0231
0232 occ::handle<Graphic3d_PresentationAttributes> myAspectFaceAppliedWithHL;
0233
0234 bool myToAllowFaceCulling;
0235 occ::handle<Graphic3d_PresentationAttributes> myHighlightStyle;
0236
0237 OpenGl_Aspects myAspectFaceHl;
0238
0239 occ::handle<OpenGl_TextureSet> myEnvironmentTexture;
0240
0241 public:
0242 DEFINE_STANDARD_RTTIEXT(OpenGl_Workspace, Standard_Transient)
0243 DEFINE_STANDARD_ALLOC
0244 };
0245
0246 #endif