Added V3d_View::SetBackgroundImage() accepting Graphic3d_Texture2D on input.
Graphic3d_CView/OpenGl_View have been modified to merge Graphic3d_CView::SetBackgroundImage()
and ::SetBackgroundCubeMap() implementations into a single method.
#include <Graphic3d_SequenceOfHClipPlane.hxx>
#include <Graphic3d_SequenceOfStructure.hxx>
#include <Graphic3d_Structure.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <Graphic3d_TypeOfAnswer.hxx>
#include <Graphic3d_TypeOfBackfacingModel.hxx>
//! Sets gradient background fill colors.
virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) = 0;
- //! Returns background image texture file path.
- virtual TCollection_AsciiString BackgroundImage() = 0;
+ //! Returns background image texture map.
+ virtual Handle(Graphic3d_TextureMap) BackgroundImage() = 0;
- //! Sets background image texture file path.
- virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) = 0;
+ //! Sets image texture or environment cubemap as backround.
+ //! @param theTextureMap [in] source to set a background;
+ //! should be either Graphic3d_Texture2D or Graphic3d_CubeMap
+ //! @param theToUpdatePBREnv [in] defines whether IBL maps will be generated or not
+ //! (see GeneratePBREnvironment())
+ virtual void SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap,
+ Standard_Boolean theToUpdatePBREnv = Standard_True) = 0;
//! Returns background image fill style.
virtual Aspect_FillMethod BackgroundImageStyle() const = 0;
//! Returns cubemap being setted last time on background.
virtual Handle(Graphic3d_CubeMap) BackgroundCubeMap() const = 0;
- //! Sets environment cubemap as background.
- //! @param theCubeMap cubemap source to be set as background
- //! @param theToUpdatePBREnv defines whether IBL maps will be generated or not (see 'GeneratePBREnvironment')
- virtual void SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap,
- Standard_Boolean theToUpdatePBREnv = Standard_True) = 0;
-
//! Generates PBR specular probe and irradiance map
//! in order to provide environment indirect illumination in PBR shading model (Image Based Lighting).
//! The source of environment data is background cubemap.
// function : SetBackgroundImage
// purpose :
// =======================================================================
-void OpenGl_View::SetBackgroundImage (const TCollection_AsciiString& theFilePath)
+void OpenGl_View::SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap,
+ Standard_Boolean theToUpdatePBREnv)
{
- // Prepare aspect for texture storage
- myBackgroundImagePath = theFilePath;
+ if (theTextureMap.IsNull()
+ || !theTextureMap->IsDone())
+ {
+ if (myBackgroundType == Graphic3d_TOB_TEXTURE
+ || myBackgroundType == Graphic3d_TOB_CUBEMAP)
+ {
+ myBackgroundType = Graphic3d_TOB_NONE;
+ if (theToUpdatePBREnv)
+ {
+ myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR;
+ }
+ }
+ return;
+ }
+
Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
- Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath));
- aTextureMap->EnableRepeat();
- aTextureMap->DisableModulate();
- aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL,
- Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
- Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
- anAspect->SetTextureMap (aTextureMap);
+ Handle(Graphic3d_TextureSet) aTextureSet = new Graphic3d_TextureSet (theTextureMap);
anAspect->SetInteriorStyle (Aspect_IS_SOLID);
anAspect->SetSuppressBackFaces (false);
- // Enable texture mapping
- if (aTextureMap->IsDone())
+ anAspect->SetShadingModel (Graphic3d_TOSM_UNLIT);
+ anAspect->SetTextureSet (aTextureSet);
+ anAspect->SetTextureMapOn (true);
+
+ if (Handle(Graphic3d_Texture2D) aTextureMap = Handle(Graphic3d_Texture2D)::DownCast (theTextureMap))
{
- anAspect->SetTextureMapOn();
+ if (theToUpdatePBREnv && myBackgroundType == Graphic3d_TOB_CUBEMAP)
+ {
+ myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR;
+ }
+
+ myTextureParams->SetAspect (anAspect);
+ myBackgroundType = Graphic3d_TOB_TEXTURE;
+ myBackgroundImage = aTextureMap;
+ return;
}
- else
+
+ if (Handle(Graphic3d_CubeMap) aCubeMap = Handle(Graphic3d_CubeMap)::DownCast (theTextureMap))
{
- anAspect->SetTextureMapOff();
+ if (theToUpdatePBREnv)
+ {
+ myPBREnvRequest = OpenGl_PBREnvRequest_BAKE;
+ }
+
+ aCubeMap->SetMipmapsGeneration (Standard_True);
+ if (const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext())
+ {
+ anAspect->SetShaderProgram (aCtx->ShaderManager()->GetBgCubeMapProgram());
+ }
+
+ myCubeMapParams->SetAspect (anAspect);
+
+ const OpenGl_Aspects* anAspectsBackup = myWorkspace->SetAspects (myCubeMapParams);
+ myWorkspace->ApplyAspects();
+ myWorkspace->SetAspects (anAspectsBackup);
+ myWorkspace->ApplyAspects();
+
+ myBackgroundType = Graphic3d_TOB_CUBEMAP;
+ myBackgroundCubeMap = aCubeMap;
return;
}
- // Set texture parameters
- myTextureParams->SetAspect (anAspect);
-
- myBackgroundType = Graphic3d_TOB_TEXTURE;
+ throw Standard_ProgramError ("OpenGl_View::SetBackgroundImage() - invalid texture map set for background");
}
// =======================================================================
{
return myPBREnvironment.IsNull() ? 0 : myPBREnvironment->SpecMapLevelsNumber();
}
-
-// =======================================================================
-// function : SetBackgroundCubeMap
-// purpose :
-// =======================================================================
-void OpenGl_View::SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap,
- Standard_Boolean theToUpdatePBREnv)
-{
- myBackgroundCubeMap = theCubeMap;
- if (theCubeMap.IsNull())
- {
- if (theToUpdatePBREnv)
- {
- myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR;
- }
- if (myBackgroundType == Graphic3d_TOB_CUBEMAP)
- {
- myBackgroundType = Graphic3d_TOB_NONE;
- }
- return;
- }
-
- theCubeMap ->SetMipmapsGeneration (Standard_True);
- Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
- Handle(Graphic3d_TextureSet) aTextureSet = new Graphic3d_TextureSet (myBackgroundCubeMap);
- anAspect->SetInteriorStyle (Aspect_IS_SOLID);
- anAspect->SetSuppressBackFaces (false);
- anAspect->SetTextureSet (aTextureSet);
-
- const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
- if (!aCtx.IsNull())
- {
- anAspect->SetShaderProgram (aCtx->ShaderManager()->GetBgCubeMapProgram());
- }
- anAspect->SetTextureMapOn (theCubeMap->IsDone());
- myCubeMapParams->SetAspect (anAspect);
-
- if (theToUpdatePBREnv)
- {
- myPBREnvRequest = OpenGl_PBREnvRequest_BAKE;
- }
- const OpenGl_Aspects* anAspectsBackup = myWorkspace->SetAspects (myCubeMapParams);
- myWorkspace->ApplyAspects();
- myWorkspace->SetAspects (anAspectsBackup);
- myWorkspace->ApplyAspects();
-
- myBackgroundType = Graphic3d_TOB_CUBEMAP;
-}
//=======================================================================
//function : InsertLayerBefore
//! Sets gradient background fill colors.
Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE;
- //! Returns background image texture file path.
- virtual TCollection_AsciiString BackgroundImage() Standard_OVERRIDE { return myBackgroundImagePath; }
+ //! Returns background image texture map.
+ virtual Handle(Graphic3d_TextureMap) BackgroundImage() Standard_OVERRIDE { return myBackgroundImage; }
- //! Sets background image texture file path.
- Standard_EXPORT virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) Standard_OVERRIDE;
+ //! Sets image texture or environment cubemap as backround.
+ //! @param theTextureMap [in] source to set a background;
+ //! should be either Graphic3d_Texture2D or Graphic3d_CubeMap
+ //! @param theToUpdatePBREnv [in] defines whether IBL maps will be generated or not
+ //! (see GeneratePBREnvironment())
+ Standard_EXPORT virtual void SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap,
+ Standard_Boolean theToUpdatePBREnv = Standard_True) Standard_OVERRIDE;
//! Returns background image fill style.
Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE;
//! Returns cubemap being set last time on background.
Standard_EXPORT Handle(Graphic3d_CubeMap) BackgroundCubeMap() const Standard_OVERRIDE;
- //! Sets environment cubemap as background.
- //! @param theCubeMap cubemap source to be set as background
- //! @param theToUpdatePBREnv defines whether IBL maps will be generated or not (see 'GeneratePBREnvironment')
- Standard_EXPORT virtual void SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap,
- Standard_Boolean theToUpdatePBREnv = Standard_True) Standard_OVERRIDE;
-
//! Generates PBR specular probe and irradiance map
//! in order to provide environment indirect illumination in PBR shading model (Image Based Lighting).
//! The source of environment data is background cubemap.
gp_XYZ myLocalOrigin;
Handle(OpenGl_FrameBuffer) myFBO;
Standard_Boolean myToShowGradTrihedron;
- TCollection_AsciiString myBackgroundImagePath;
+ Handle(Graphic3d_TextureMap) myBackgroundImage;
Handle(Graphic3d_TextureEnv) myTextureEnvData;
Graphic3d_GraduatedTrihedron myGTrihedronData;
const Aspect_FillMethod theFillStyle,
const Standard_Boolean theToUpdate)
{
- myView->SetBackgroundImage (theFileName);
- myView->SetBackgroundImageStyle (theFillStyle);
+ Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2Dmanual (theFileName);
+ aTextureMap->DisableModulate();
+ SetBackgroundImage (aTextureMap, theFillStyle, theToUpdate);
+}
+//=============================================================================
+//function : SetBackgroundImage
+//purpose :
+//=============================================================================
+void V3d_View::SetBackgroundImage (const Handle(Graphic3d_Texture2D)& theTexture,
+ const Aspect_FillMethod theFillStyle,
+ const Standard_Boolean theToUpdate)
+{
+ myView->SetBackgroundImage (theTexture);
+ myView->SetBackgroundImageStyle (theFillStyle);
if (myImmediateUpdate || theToUpdate)
{
Redraw();
Standard_Boolean theToUpdatePBREnv,
Standard_Boolean theToUpdate)
{
- myView->SetBackgroundCubeMap (theCubeMap, theToUpdatePBREnv);
+ myView->SetBackgroundImage (theCubeMap, theToUpdatePBREnv);
if (myImmediateUpdate || theToUpdate)
{
Redraw();
const Aspect_FillMethod theFillStyle = Aspect_FM_CENTERED,
const Standard_Boolean theToUpdate = Standard_False);
+ //! Defines the background texture of the view by supplying the texture and fill method (centered by default)
+ Standard_EXPORT void SetBackgroundImage (const Handle(Graphic3d_Texture2D)& theTexture,
+ const Aspect_FillMethod theFillStyle = Aspect_FM_CENTERED,
+ const Standard_Boolean theToUpdate = Standard_False);
+
//! Defines the textured background fill method of the view.
Standard_EXPORT void SetBgImageStyle (const Aspect_FillMethod theFillStyle,
const Standard_Boolean theToUpdate = Standard_False);