mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-04 18:06:22 +03:00
0031683: Visualization - V3d_View::SetBackgroundImage() should accept Image_PixMap
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.
This commit is contained in:
parent
bf0114a372
commit
99289bed0a
@ -31,6 +31,7 @@
|
||||
#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>
|
||||
@ -363,11 +364,16 @@ public:
|
||||
//! 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;
|
||||
@ -378,12 +384,6 @@ public:
|
||||
//! 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.
|
||||
|
@ -483,35 +483,71 @@ void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBac
|
||||
// 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;
|
||||
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);
|
||||
anAspect->SetInteriorStyle (Aspect_IS_SOLID);
|
||||
anAspect->SetSuppressBackFaces (false);
|
||||
// Enable texture mapping
|
||||
if (aTextureMap->IsDone())
|
||||
if (theTextureMap.IsNull()
|
||||
|| !theTextureMap->IsDone())
|
||||
{
|
||||
anAspect->SetTextureMapOn();
|
||||
}
|
||||
else
|
||||
{
|
||||
anAspect->SetTextureMapOff();
|
||||
if (myBackgroundType == Graphic3d_TOB_TEXTURE
|
||||
|| myBackgroundType == Graphic3d_TOB_CUBEMAP)
|
||||
{
|
||||
myBackgroundType = Graphic3d_TOB_NONE;
|
||||
if (theToUpdatePBREnv)
|
||||
{
|
||||
myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Set texture parameters
|
||||
myTextureParams->SetAspect (anAspect);
|
||||
Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
|
||||
Handle(Graphic3d_TextureSet) aTextureSet = new Graphic3d_TextureSet (theTextureMap);
|
||||
anAspect->SetInteriorStyle (Aspect_IS_SOLID);
|
||||
anAspect->SetSuppressBackFaces (false);
|
||||
anAspect->SetShadingModel (Graphic3d_TOSM_UNLIT);
|
||||
anAspect->SetTextureSet (aTextureSet);
|
||||
anAspect->SetTextureMapOn (true);
|
||||
|
||||
myBackgroundType = Graphic3d_TOB_TEXTURE;
|
||||
if (Handle(Graphic3d_Texture2D) aTextureMap = Handle(Graphic3d_Texture2D)::DownCast (theTextureMap))
|
||||
{
|
||||
if (theToUpdatePBREnv && myBackgroundType == Graphic3d_TOB_CUBEMAP)
|
||||
{
|
||||
myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR;
|
||||
}
|
||||
|
||||
myTextureParams->SetAspect (anAspect);
|
||||
myBackgroundType = Graphic3d_TOB_TEXTURE;
|
||||
myBackgroundImage = aTextureMap;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Handle(Graphic3d_CubeMap) aCubeMap = Handle(Graphic3d_CubeMap)::DownCast (theTextureMap))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
throw Standard_ProgramError ("OpenGl_View::SetBackgroundImage() - invalid texture map set for background");
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
@ -549,54 +585,6 @@ unsigned int OpenGl_View::SpecIBLMapLevels() const
|
||||
{
|
||||
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
|
||||
|
@ -211,11 +211,16 @@ public:
|
||||
//! 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;
|
||||
@ -226,12 +231,6 @@ public:
|
||||
//! 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.
|
||||
@ -481,7 +480,7 @@ protected:
|
||||
gp_XYZ myLocalOrigin;
|
||||
Handle(OpenGl_FrameBuffer) myFBO;
|
||||
Standard_Boolean myToShowGradTrihedron;
|
||||
TCollection_AsciiString myBackgroundImagePath;
|
||||
Handle(Graphic3d_TextureMap) myBackgroundImage;
|
||||
Handle(Graphic3d_TextureEnv) myTextureEnvData;
|
||||
Graphic3d_GraduatedTrihedron myGTrihedronData;
|
||||
|
||||
|
@ -479,9 +479,21 @@ void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
|
||||
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();
|
||||
@ -510,7 +522,7 @@ void V3d_View::SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap
|
||||
Standard_Boolean theToUpdatePBREnv,
|
||||
Standard_Boolean theToUpdate)
|
||||
{
|
||||
myView->SetBackgroundCubeMap (theCubeMap, theToUpdatePBREnv);
|
||||
myView->SetBackgroundImage (theCubeMap, theToUpdatePBREnv);
|
||||
if (myImmediateUpdate || theToUpdate)
|
||||
{
|
||||
Redraw();
|
||||
|
@ -224,6 +224,11 @@ public:
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user