1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0032862: Visualization, Graphic3d_TextureMap - add 3D texture definition

Image_PixMap has been extended to support definition of 3D bitmap (as an array of 2D slices).

Graphic3d_TypeOfTexture enumeration values have been renamed to include full enum prefix.
Added Graphic3d_TypeOfTexture_3D redirecting to GL_TEXTURE_3D.
OpenGl_Texture::Init() has been extended to allow initialization of 3D texture.

Graphic3d_Texture2Dmanual merged into Graphic3d_Texture2D and marked as deprecated alias.
Graphic3d_TOT_2D_MIPMAP has been deprecated in favor of dedicated Graphic3d_TextureRoot::SetMipMaps().

Added Graphic3d_Texture3D class.
vtexture - added argument -3d for uploading 3D texture.
This commit is contained in:
kgv
2022-03-02 15:21:22 +03:00
committed by smoskvin
parent a9e5f65041
commit 633084b809
47 changed files with 1327 additions and 663 deletions

View File

@@ -48,7 +48,8 @@
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_CStructure.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_Texture3D.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_MediaTextureSet.hxx>
#include <Image_AlienPixMap.hxx>
@@ -4145,13 +4146,8 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
return 1;
}
int toModulate = -1;
int toSetSRgb = -1;
bool toSetFilter = false;
bool toSetAniso = false;
bool toSetTrsfAngle = false;
bool toSetTrsfTrans = false;
bool toSetTrsfScale = false;
int toModulate = -1, toSetSRgb = -1;
bool toSetFilter = false, toSetAniso = false, toSetTrsfAngle = false, toSetTrsfTrans = false, toSetTrsfScale = false;
Standard_ShortReal aTrsfRotAngle = 0.0f;
Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f);
Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f);
@@ -4161,12 +4157,8 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
Handle(AIS_InteractiveObject) aTexturedIO;
Handle(AIS_Shape) aTexturedShape;
Handle(Graphic3d_TextureSet) aTextureSetOld;
NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew;
bool toSetGenRepeat = false;
bool toSetGenScale = false;
bool toSetGenOrigin = false;
bool toSetImage = false;
bool toComputeUV = false;
NCollection_Vector<Handle(Graphic3d_TextureMap)> aTextureVecNew;
bool toSetGenRepeat = false, toSetGenScale = false, toSetGenOrigin = false, toSetImage = false, toComputeUV = false;
const TCollection_AsciiString aCommandName (theArgVec[0]);
bool toSetDefaults = aCommandName == "vtexdefault";
@@ -4441,6 +4433,38 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia);
aTextureSetOld.Nullify();
}
else if (aCommandName == "vtexture"
&& aTextureVecNew.IsEmpty()
&& aNameCase == "-3d")
{
TColStd_SequenceOfAsciiString aSlicesSeq;
for (; anArgIter + 1 < theArgsNb; ++anArgIter)
{
TCollection_AsciiString aSlicePath (theArgVec[anArgIter + 1]);
if (aSlicePath.StartsWith ("-"))
{
break;
}
aSlicesSeq.Append (aSlicePath);
}
if (aSlicesSeq.Size() < 2)
{
Message::SendFail() << "Syntax error at '" << aNameCase << "'";
return 1;
}
NCollection_Array1<TCollection_AsciiString> aSlices;
aSlices.Resize (0, aSlicesSeq.Size() - 1, false);
Standard_Integer aSliceIndex = 0;
for (const TCollection_AsciiString& aSliceIter : aSlicesSeq)
{
aSlices[aSliceIndex++] = aSliceIter;
}
toSetImage = true;
aTextureVecNew.SetValue (0, new Graphic3d_Texture3D (aSlices));
}
else if (aCommandName == "vtexture"
&& (aTextureVecNew.IsEmpty()
|| aNameCase.StartsWith ("-tex")))
@@ -4483,7 +4507,7 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
Message::SendFail() << "Syntax error: texture with ID " << aValue << " is undefined!";
return 1;
}
aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue)));
aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2D (Graphic3d_NameOfTexture2D (aValue)));
}
else if (aTexName == "?")
{
@@ -4507,11 +4531,11 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
Message::SendFail() << "Syntax error: non-existing image file has been specified '" << aTexName << "'.";
return 1;
}
aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName));
aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2D (aTexName));
}
else
{
aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)());
aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_TextureMap)());
}
if (aTextureVecNew.Value (aTexIndex))
@@ -4537,7 +4561,7 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size());
for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter)
{
Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
Handle(Graphic3d_TextureMap)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter);
Handle(Graphic3d_TextureRoot) aTextureOld;
if (!aTextureSetOld.IsNull()
&& aTexIter < aTextureSetOld->Size())
@@ -4549,17 +4573,21 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb,
&& !aTextureNew.IsNull())
{
*aTextureNew->GetParams() = *aTextureOld->GetParams();
if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld))
Handle(Graphic3d_Texture2D) aTex2dNew = Handle(Graphic3d_Texture2D)::DownCast (aTextureNew);
Handle(Graphic3d_Texture2D) aTex2dOld = Handle(Graphic3d_Texture2D)::DownCast (aTextureOld);
if (!aTex2dOld.IsNull()
&& !aTex2dNew.IsNull())
{
TCollection_AsciiString aFilePathOld, aFilePathNew;
aTextureOld->Path().SystemName (aFilePathOld);
aTextureNew->Path().SystemName (aFilePathNew);
if (aTextureNew->Name() == anOldManualTex->Name()
if (aTex2dNew->Name() == aTex2dOld->Name()
&& aFilePathOld == aFilePathNew
&& (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
&& (!aFilePathNew.IsEmpty() || aTex2dNew->Name() != Graphic3d_NOT_2D_UNKNOWN))
{
--aNbChanged;
aTextureNew = anOldManualTex;
aTextureNew = aTex2dOld;
}
}
}
@@ -6816,6 +6844,7 @@ Sets default deflection coefficient (0.0008) that defines the quality of the sha
addCmd ("vtexture", VTexture, /* [vtexture] */ R"(
vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]
[-tex0 Image0] [-tex1 Image1] [...]
[-3d Image0 Image1 ... ImageN]
[-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]
[-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]
[-modulate {on|off}] [-srgb {on|off}]=on
@@ -6836,6 +6865,7 @@ The options are:
-setFilter Setup texture filter
-setAnisoFilter Setup anisotropic filter for texture with mip-levels
-default Sets texture mapping default parameters
-3d Load 3D texture from the list of 2D image files
)" /* [vtexture] */);
addCmd ("vtexscale", VTexture, /* [vtexscale] */ R"(

View File

@@ -411,6 +411,15 @@ static Standard_Integer VShaderProg (Draw_Interpretor& ,
}
aProgram->SetHeader (aHeader);
}
else if (!aProgram.IsNull()
&& (anArg == "-defaultsampler"
|| anArg == "-defampler"
|| anArg == "-nodefaultsampler"
|| anArg == "-nodefsampler"))
{
bool toUseDefSampler = Draw::ParseOnOffNoIterator (theArgNb, theArgVec, anArgIter);
aProgram->SetDefaultSampler (toUseDefSampler);
}
else if (!anArg.StartsWith ("-")
&& GetMapOfAIS().IsBound2 (theArgVec[anArgIter]))
{
@@ -1187,6 +1196,7 @@ vshader name -vert VertexShader -frag FragmentShader [-geom GeometryShader]
[-header VersionHeader]
[-tessControl TessControlShader -tessEval TessEvaluationShader]
[-uniform Name FloatValue]
[-defaultSampler {0|1}]=1
Assign custom GLSL program to presentation aspects.
)" /* [vshader] */);

View File

@@ -55,7 +55,7 @@
#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_GraphicDriverFactory.hxx>
#include <Graphic3d_NameOfTextureEnv.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Graphic3d_Texture2D.hxx>
#include <Graphic3d_TextureEnv.hxx>
#include <Graphic3d_TextureParams.hxx>
#include <Graphic3d_TypeOfTextureFilter.hxx>
@@ -3069,7 +3069,7 @@ static int VBackground (Draw_Interpretor& theDI,
if (!anImagePath.IsEmpty())
{
Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2Dmanual (anImagePath);
Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2D (anImagePath);
aTextureMap->DisableModulate();
aTextureMap->SetColorMap (isSRgb);
if (!aTextureMap->IsDone())
@@ -5897,7 +5897,7 @@ public:
aMat.SetSpecularColor (Quantity_NOC_BLACK);
aMat.SetEmissiveColor (Quantity_NOC_BLACK);
aFillAspect->SetFrontMaterial (aMat);
aFillAspect->SetTextureMap (new Graphic3d_Texture2Dmanual (theImage));
aFillAspect->SetTextureMap (new Graphic3d_Texture2D (theImage));
aFillAspect->SetTextureMapOn();
}
{
@@ -8609,7 +8609,7 @@ static int VClipPlane (Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
}
TCollection_AsciiString aTextureName (aChangeArgs[1]);
Handle(Graphic3d_Texture2Dmanual) aTexture = new Graphic3d_Texture2Dmanual(aTextureName);
Handle(Graphic3d_Texture2D) aTexture = new Graphic3d_Texture2D (aTextureName);
if (!aTexture->IsDone())
{
aClipPlane->SetCappingTexture (NULL);