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

0030807: Visualization, TKOpenGl - supporting cubemaps

A cubemap texture initialization has been implemented.
Setting environment cubemap as interactive background is posssible now.
This commit is contained in:
iko
2019-07-09 16:55:49 +03:00
committed by apn
parent c5cee3222f
commit 077a220c51
29 changed files with 1986 additions and 110 deletions

View File

@@ -48,6 +48,15 @@ Graphic3d_ClipPlane.hxx
Graphic3d_CStructure.cxx
Graphic3d_CStructure.hxx
Graphic3d_CTexture.hxx
Graphic3d_CubeMap.cxx
Graphic3d_CubeMap.hxx
Graphic3d_CubeMapOrder.cxx
Graphic3d_CubeMapOrder.hxx
Graphic3d_CubeMapPacked.cxx
Graphic3d_CubeMapPacked.hxx
Graphic3d_CubeMapSeparate.cxx
Graphic3d_CubeMapSeparate.hxx
Graphic3d_CubeMapSide.hxx
Graphic3d_CullingTool.cxx
Graphic3d_CullingTool.hxx
Graphic3d_CView.cxx

View File

@@ -19,6 +19,7 @@
#include <Aspect_Window.hxx>
#include <Graphic3d_BufferType.hxx>
#include <Graphic3d_Camera.hxx>
#include <Graphic3d_CubeMap.hxx>
#include <Graphic3d_CLight.hxx>
#include <Graphic3d_CStructure.hxx>
#include <Graphic3d_DataStructureManager.hxx>
@@ -373,6 +374,12 @@ public:
//! Sets background image fill style.
virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) = 0;
//! Returns cubemap being setted last time on background.
virtual Handle(Graphic3d_CubeMap) BackgroundCubeMap() const = 0;
//! Sets environment cubemap as background.
virtual void SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap) = 0;
//! Returns environment texture set for the view.
virtual Handle(Graphic3d_TextureEnv) TextureEnv() const = 0;

View File

@@ -0,0 +1,17 @@
// Author: Ilya Khramov
// 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 <Graphic3d_CubeMap.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMap, Graphic3d_TextureMap)

View File

@@ -0,0 +1,110 @@
// Author: Ilya Khramov
// 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 _Graphic3d_CubeMap_HeaderFile
#define _Graphic3d_CubeMap_HeaderFile
#include <Graphic3d_CubeMapOrder.hxx>
#include <Graphic3d_TextureMap.hxx>
//! Base class for cubemaps.
//! It is iterator over cubemap sides.
class Graphic3d_CubeMap : public Graphic3d_TextureMap
{
DEFINE_STANDARD_RTTIEXT(Graphic3d_CubeMap, Graphic3d_TextureMap)
public:
//! Constructor defining loading cubemap from file.
Graphic3d_CubeMap (const TCollection_AsciiString& theFileName) :
Graphic3d_TextureMap (theFileName, Graphic3d_TOT_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myIsTopDown (true),
myZIsInverted (false)
{}
//! Constructor defining direct cubemap initialization from PixMap.
Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)()) :
Graphic3d_TextureMap (thePixmap, Graphic3d_TOT_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myIsTopDown (true),
myZIsInverted (false)
{}
//! Returns whether the iterator has reached the end (true if it hasn't).
Standard_Boolean More() const { return !myEndIsReached; }
//! Returns current cubemap side (iterator state).
Graphic3d_CubeMapSide CurrentSide() const { return myCurrentSide; }
//! Moves iterator to the next cubemap side.
//! Uses OpenGL cubemap sides order +X -> -X -> +Y -> -Y -> +Z -> -Z.
void Next()
{
if (!myEndIsReached && myCurrentSide == Graphic3d_CMS_NEG_Z)
{
myEndIsReached = true;
}
else
{
myCurrentSide = Graphic3d_CubeMapSide (myCurrentSide + 1);
}
}
//! Returns whether row's memory layout is top-down.
Standard_Boolean IsTopDown() const
{
return myIsTopDown;
}
//! Sets Z axis inversion (vertical flipping).
void SetZInversion (Standard_Boolean theZIsInverted)
{
myZIsInverted = theZIsInverted;
}
//! Returns whether Z axis is inverted.
Standard_Boolean ZIsInverted() const
{
return myZIsInverted;
}
//! Returns PixMap containing current side of cubemap.
//! Returns null handle if current side is invalid.
virtual Handle(Image_PixMap) Value() = 0;
//! Sets iterator state to +X cubemap side.
Graphic3d_CubeMap& Reset()
{
myCurrentSide = Graphic3d_CMS_POS_X;
myEndIsReached = false;
return *this;
}
//! Empty destructor.
~Graphic3d_CubeMap() {}
protected:
Graphic3d_CubeMapSide myCurrentSide; //!< Iterator state
Standard_Boolean myEndIsReached; //!< Indicates whether end of iteration has been reached or hasn't
Standard_Boolean myIsTopDown; //!< Stores rows's memory layout
Standard_Boolean myZIsInverted; //!< Indicates whether Z axis is inverted that allows to synchronize vertical flip of cubemap
};
DEFINE_STANDARD_HANDLE(Graphic3d_CubeMap, Graphic3d_TextureMap)
#endif // _Graphic3d_CubeMap_HeaderFile

View File

@@ -0,0 +1,278 @@
// Author: Ilya Khramov
// 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 <Graphic3d_CubeMapOrder.hxx>
#include <Standard_Failure.hxx>
#include <bitset>
// =======================================================================
// function : Graphic3d_CubeMapOrder
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder::Graphic3d_CubeMapOrder()
:
myConvolution (0),
myHasOverflows (false)
{}
// =======================================================================
// function : Graphic3d_CubeMapOrder
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder::Graphic3d_CubeMapOrder (unsigned char thePosXLocation,
unsigned char theNegXLocation,
unsigned char thePosYLocation,
unsigned char theNegYLocation,
unsigned char thePosZLocation,
unsigned char theNegZLocation)
:
myConvolution (0),
myHasOverflows (false)
{
Set (Graphic3d_CMS_POS_X, thePosXLocation);
Set (Graphic3d_CMS_NEG_X, theNegXLocation);
Set (Graphic3d_CMS_POS_Y, thePosYLocation);
Set (Graphic3d_CMS_NEG_Y, theNegYLocation);
Set (Graphic3d_CMS_POS_Z, thePosZLocation);
Set (Graphic3d_CMS_NEG_Z, theNegZLocation);
}
// =======================================================================
// function : Graphic3d_CubeMapOrder
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder::Graphic3d_CubeMapOrder (const Graphic3d_ValidatedCubeMapOrder theOrder)
:
myConvolution (theOrder.Order.myConvolution),
myHasOverflows (theOrder.Order.myHasOverflows)
{}
// =======================================================================
// function : Set
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Set (const Graphic3d_CubeMapOrder& theOrder)
{
myConvolution = theOrder.myConvolution;
myHasOverflows = theOrder.myHasOverflows;
return *this;
}
// =======================================================================
// function : operator=
// purpose :
// =======================================================================
Graphic3d_ValidatedCubeMapOrder Graphic3d_CubeMapOrder::Validated() const
{
if (!IsValid())
{
throw Standard_Failure("Try of Graphic3d_ValidatedCubeMapOrder creation using invalid Graphic3d_CubeMapOrder");
}
return *this;
}
// =======================================================================
// function : Set
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue)
{
if (theValue > 5)
{
myHasOverflows = true;
return *this;
}
set (theCubeMapSide, theValue);
return *this;
}
// =======================================================================
// function : Get
// purpose :
// =======================================================================
unsigned char Graphic3d_CubeMapOrder::Get (Graphic3d_CubeMapSide theCubeMapSide) const
{
return get (static_cast<unsigned char> (theCubeMapSide));
}
// =======================================================================
// function : operator[]
// purpose :
// =======================================================================
unsigned char Graphic3d_CubeMapOrder::operator[] (Graphic3d_CubeMapSide theCubeMapSide) const
{
return Get (theCubeMapSide);
}
// =======================================================================
// function : SetDefault
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::SetDefault()
{
for (unsigned char i = 0; i < 6; ++i)
{
set (Graphic3d_CubeMapSide (i), i);
}
return *this;
}
// =======================================================================
// function : Permute
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Permute (Graphic3d_ValidatedCubeMapOrder thePermutation)
{
for (unsigned char i = 0; i < 6; ++i)
{
set (i, thePermutation->get (get (i)));
}
return *this;
}
// =======================================================================
// function : Permuted
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder Graphic3d_CubeMapOrder::Permuted (Graphic3d_ValidatedCubeMapOrder thePermutation) const
{
Graphic3d_CubeMapOrder anOrder = *this;
anOrder.Permute (thePermutation);
return anOrder;
}
// =======================================================================
// function : Swap
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Swap (Graphic3d_CubeMapSide theFirstSide,
Graphic3d_CubeMapSide theSecondSide)
{
unsigned char aTmp = Get (theFirstSide);
set (theFirstSide, Get(theSecondSide));
set (theSecondSide, aTmp);
return *this;
}
// =======================================================================
// function : Swapped
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder Graphic3d_CubeMapOrder::Swapped (Graphic3d_CubeMapSide theFirstSide,
Graphic3d_CubeMapSide theSecondSide) const
{
Graphic3d_CubeMapOrder anOrder = *this;
anOrder.Swap (theFirstSide, theSecondSide);
return anOrder;
}
// =======================================================================
// function : Clear
// purpose :
// =======================================================================
Graphic3d_CubeMapOrder& Graphic3d_CubeMapOrder::Clear()
{
myConvolution = 0;
myHasOverflows = false;
return *this;
}
// =======================================================================
// function : IsEmpty
// purpose :
// =======================================================================
bool Graphic3d_CubeMapOrder::IsEmpty() const
{
return myConvolution == 0;
}
// =======================================================================
// function : HasRepetitions
// purpose :
// =======================================================================
bool Graphic3d_CubeMapOrder::HasRepetitions() const
{
std::bitset<6> aBitSet;
for (unsigned char i = 0; i < 6; ++i)
{
std::bitset<6>::reference aFlag = aBitSet[get (i)];
if (aFlag)
{
return true;
}
aFlag = true;
}
return false;
}
// =======================================================================
// function : HasOverflows
// purpose :
// =======================================================================
bool Graphic3d_CubeMapOrder::HasOverflows() const
{
return myHasOverflows;
}
// =======================================================================
// function : IsValid
// purpose :
// =======================================================================
bool Graphic3d_CubeMapOrder::IsValid() const
{
return !HasRepetitions() && !HasOverflows();
}
// =======================================================================
// function : get
// purpose :
// =======================================================================
unsigned char Graphic3d_CubeMapOrder::get (unsigned char theCubeMapSide) const
{
return (myConvolution / (1 << (theCubeMapSide * 3))) % (1 << 3);
}
// =======================================================================
// function : set
// purpose :
// =======================================================================
void Graphic3d_CubeMapOrder::set (unsigned char theCubeMapSide, unsigned char theValue)
{
unsigned int aValuePlace = 1 << (theCubeMapSide * 3);
myConvolution -= aValuePlace * get (theCubeMapSide);
myConvolution += aValuePlace * theValue;
}
// =======================================================================
// function : set
// purpose :
// =======================================================================
void Graphic3d_CubeMapOrder::set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue)
{
set (static_cast<unsigned char> (theCubeMapSide), theValue);
}
// =======================================================================
// function : Default
// purpose :
// =======================================================================
const Graphic3d_ValidatedCubeMapOrder& Graphic3d_CubeMapOrder::Default()
{
static const Graphic3d_ValidatedCubeMapOrder aCubeMapOrder = Graphic3d_CubeMapOrder().SetDefault().Validated();
return aCubeMapOrder;
}

View File

@@ -0,0 +1,158 @@
// Author: Ilya Khramov
// 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 _Graphic3d_CubeMapOrder_HeaderFile
#define _Graphic3d_CubeMapOrder_HeaderFile
#include <Graphic3d_CubeMapSide.hxx>
#include <Standard_Macro.hxx>
class Graphic3d_ValidatedCubeMapOrder;
//! Graphic3d_CubeMapOrder maps sides of cubemap on tiles in packed cubemap image
//! to support different tiles order in such images.
//! Also it can be considered as permutation of numbers from 0 to 5.
//! It stores permutation in one integer as convolution.
class Graphic3d_CubeMapOrder
{
public:
//! Default constructor.
//! Creates empty order with zero convolution.
Standard_EXPORT Graphic3d_CubeMapOrder();
//! Initializes order with values.
Standard_EXPORT Graphic3d_CubeMapOrder (unsigned char thePosXLocation,
unsigned char theNegXLocation,
unsigned char thePosYLocation,
unsigned char theNegYLocation,
unsigned char thePosZLocation,
unsigned char theNegZLocation);
//! Creates Graphic3d_CubeMapOrder using Graphic3d_ValidatedCubeMapOrder.
Standard_EXPORT Graphic3d_CubeMapOrder (const Graphic3d_ValidatedCubeMapOrder theOrder);
//! Alias of 'operator='.
Standard_EXPORT Graphic3d_CubeMapOrder& Set (const Graphic3d_CubeMapOrder& theOrder);
//! Checks whether order is valid and returns object containing it.
//! If order is invalid then exception will be thrown.
//! This method is only way to create Graphic3d_ValidatedCubeMapOrder except copy constructor.
Standard_EXPORT Graphic3d_ValidatedCubeMapOrder Validated() const;
public:
//! Sets number of tile in packed cubemap image according passed cubemap side.
Standard_EXPORT Graphic3d_CubeMapOrder& Set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue);
//! Sets default order (just from 0 to 5)
Standard_EXPORT Graphic3d_CubeMapOrder& SetDefault();
//! Applies another cubemap order as permutation for the current one.
Standard_EXPORT Graphic3d_CubeMapOrder& Permute (Graphic3d_ValidatedCubeMapOrder anOrder);
//! Returns permuted by other cubemap order copy of current one.
Standard_EXPORT Graphic3d_CubeMapOrder Permuted (Graphic3d_ValidatedCubeMapOrder anOrder) const;
//! Swaps values of two cubemap sides.
Standard_EXPORT Graphic3d_CubeMapOrder& Swap (Graphic3d_CubeMapSide theFirstSide,
Graphic3d_CubeMapSide theSecondSide);
//! Returns copy of current order with swapped values of two cubemap sides.
Standard_EXPORT Graphic3d_CubeMapOrder Swapped (Graphic3d_CubeMapSide theFirstSide,
Graphic3d_CubeMapSide theSecondSide) const;
//! Returns value of passed cubemap side.
Standard_EXPORT unsigned char Get (Graphic3d_CubeMapSide theCubeMapSide) const;
//! Alias of 'Get'.
Standard_EXPORT unsigned char operator[] (Graphic3d_CubeMapSide theCubeMapSide) const;
//! Makes order empty.
Standard_EXPORT Graphic3d_CubeMapOrder& Clear();
//! Checks whether order is empty.
Standard_EXPORT bool IsEmpty() const;
//! Checks whether order has repetitions.
Standard_EXPORT bool HasRepetitions() const;
//! Checks whether attempts to assign index greater than 5 to any side happed.
Standard_EXPORT bool HasOverflows() const;
//! Checks whether order is valid.
//! Order is valid when it doesn't have repetitions
//! and there were not attempts to assign indexes greater than 5.
Standard_EXPORT bool IsValid() const;
public:
//! Returns default order in protector container class.
//! It is guaranteed to be valid.
Standard_EXPORT static const Graphic3d_ValidatedCubeMapOrder& Default();
private:
//! Alias of 'Get' with other parameter's type for more handful iteration.
unsigned char get (unsigned char theCubeMapSide) const;
//! Alias of 'set' with other parameter's type for more handful iteration and applying permutations.
void set (unsigned char theCubeMapSide, unsigned char theValue);
//! 'Set' without overflow's checking.
void set (Graphic3d_CubeMapSide theCubeMapSide, unsigned char theValue);
private:
unsigned int myConvolution; //!< Contains all values of permutation as power convolution
bool myHasOverflows; //!< Indicates if there are attempts to assign index greater than 5
};
//! Graphic3d_ValidatedCubeMapOrder contains completely valid order object.
//! The only way to create this class except copy constructor is 'Validated' method of Graphic3d_CubeMapOrder.
//! This class can initialize Graphic3d_CubeMapOrder.
//! It is supposed to be used in case of necessity of completely valid order (in function argument as example).
//! It helps to automate order's valid checks.
class Graphic3d_ValidatedCubeMapOrder
{
public:
friend class Graphic3d_CubeMapOrder;
//! Allows skip access to 'Order' field and work directly.
const Graphic3d_CubeMapOrder* operator->() const
{
return &Order;
}
public:
const Graphic3d_CubeMapOrder Order; //!< Completely valid order
private:
//! Only Graphic3d_CubeMapOrder can generate Graphic3d_ValidatedCubeMapOrder in 'Validated' method.
Graphic3d_ValidatedCubeMapOrder(const Graphic3d_CubeMapOrder theOrder)
:
Order(theOrder)
{}
//! Deleted 'operator='
Graphic3d_ValidatedCubeMapOrder& operator= (const Graphic3d_ValidatedCubeMapOrder&);
};
#endif // _Graphic3d_CubeMapOrder_HeaderFile

View File

@@ -0,0 +1,196 @@
// Author: Ilya Khramov
// 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 <Graphic3d_CubeMapPacked.hxx>
#include <Image_AlienPixMap.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMapPacked, Graphic3d_CubeMap)
// =======================================================================
// function : Graphic3d_CubeMapPacked
// purpose :
// =======================================================================
Graphic3d_CubeMapPacked::Graphic3d_CubeMapPacked (const TCollection_AsciiString& theFilePath,
const Graphic3d_ValidatedCubeMapOrder theOrder)
:
Graphic3d_CubeMap (theFilePath),
myOrder (theOrder),
myTileNumberX (1)
{}
// =======================================================================
// function : Graphic3d_CubeMapPacked
// purpose :
// =======================================================================
Graphic3d_CubeMapPacked::Graphic3d_CubeMapPacked (const Handle(Image_PixMap)& theImage,
const Graphic3d_ValidatedCubeMapOrder theOrder)
:
Graphic3d_CubeMap (Handle(Image_PixMap)()),
myOrder (theOrder),
myTileNumberX (1)
{
if (checkImage (theImage, myTileNumberX))
{
myPixMap = theImage;
}
}
// =======================================================================
// function : Value
// purpose :
// =======================================================================
Handle(Image_PixMap) Graphic3d_CubeMapPacked::Value()
{
if (myTileNumberX != 0)
{
if (myPixMap.IsNull())
{
TCollection_AsciiString aFilePath;
myPath.SystemName (aFilePath);
if (!aFilePath.IsEmpty())
{
tryLoadImage (aFilePath);
}
}
if (!myPixMap.IsNull())
{
Handle(Image_PixMap) aWrapper = new Image_PixMap();
Standard_Size aTileSize = myPixMap->SizeX() / myTileNumberX;
myIsTopDown = myPixMap->IsTopDown();
Graphic3d_CubeMapOrder anOrder = myOrder;
if (!myIsTopDown)
{
myPixMap->SetTopDown (true);
anOrder.Swap (Graphic3d_CMS_POS_Y, Graphic3d_CMS_NEG_Y);
}
unsigned int aTileIndexX = anOrder[myCurrentSide] % myTileNumberX;
unsigned int aTileIndexY = anOrder[myCurrentSide] / myTileNumberX;
aTileIndexY = myIsTopDown ? aTileIndexY : (6 / myTileNumberX - 1 - aTileIndexY);
if (aWrapper->InitWrapper (myPixMap->Format(),
myPixMap->ChangeRawValue(aTileIndexY * aTileSize, aTileIndexX * aTileSize),
aTileSize,
aTileSize,
myPixMap->SizeRowBytes()))
{
myPixMap->SetTopDown (myIsTopDown);
return aWrapper;
}
else
{
myPixMap->SetTopDown(myIsTopDown);
}
}
}
return Handle(Image_PixMap)();
}
// =======================================================================
// function : checkOrder
// purpose :
// =======================================================================
Standard_Boolean Graphic3d_CubeMapPacked::checkOrder (const NCollection_Array1<unsigned int>& theOrder)
{
Standard_Boolean anOrderIsValid = Standard_True;
if (theOrder.Size() != 6)
{
anOrderIsValid = Standard_False;
}
else
{
for (unsigned int i = 0; i < 6 && anOrderIsValid; ++i)
{
if (theOrder[i] > 5)
{
anOrderIsValid = Standard_False;
break;
}
for (unsigned int j = i + 1; j < 6; ++j)
{
if (theOrder[i] == theOrder[j])
{
anOrderIsValid = Standard_False;
break;
}
}
}
}
if (!anOrderIsValid)
{
throw Standard_Failure ("Ivalid order format in tiles of Graphic3d_CubeMapPacked");
}
return anOrderIsValid;
}
// =======================================================================
// function : checkImage
// purpose :
// =======================================================================
Standard_Boolean Graphic3d_CubeMapPacked::checkImage (const Handle(Image_PixMap)& theImage,
unsigned int& theTileNumberX)
{
Standard_Size aSizeX = theImage->SizeX();
Standard_Size aSizeY = theImage->SizeY();
if ((aSizeY % aSizeX == 0) && (aSizeY / aSizeX == 6))
{
theTileNumberX = 1;
}
else if ((aSizeX % aSizeY == 0) && (aSizeX / aSizeY == 6))
{
theTileNumberX = 6;
}
else if ((aSizeX % 2 == 0) && (aSizeY % 3 == 0) && (aSizeX / 2 == aSizeY / 3))
{
theTileNumberX = 2;
}
else if ((aSizeX % 3 == 0) && (aSizeY % 2 == 0) && (aSizeX / 3 == aSizeY / 2))
{
theTileNumberX = 3;
}
else
{
return Standard_False;
}
return Standard_True;
}
// =======================================================================
// function : tryLoadImage
// purpose :
// =======================================================================
void Graphic3d_CubeMapPacked::tryLoadImage (const TCollection_AsciiString& theFilePath)
{
Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap;
if (anImage->Load (theFilePath))
{
if (checkImage (anImage, myTileNumberX))
{
myPixMap = anImage;
}
}
}

View File

@@ -0,0 +1,71 @@
// Author: Ilya Khramov
// 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 _Graphic3d_CubeMapPacked_HeaderFile
#define _Graphic3d_CubeMapPacked_HeaderFile
#include <Graphic3d_CubeMap.hxx>
#include <NCollection_Array1.hxx>
#include <OSD_Path.hxx>
//! Class is intended to process cubemap packed into single image plane.
class Graphic3d_CubeMapPacked : public Graphic3d_CubeMap
{
DEFINE_STANDARD_RTTIEXT(Graphic3d_CubeMapPacked, Graphic3d_CubeMap)
public:
//! Initialization to load cubemef from file.
//! @theFileName - path to the cubemap image
//! @theOrder - array conaining six different indexes of cubemap sides which maps tile grid to cubemap sides
Standard_EXPORT Graphic3d_CubeMapPacked (const TCollection_AsciiString& theFileName,
const Graphic3d_ValidatedCubeMapOrder theOrder = Graphic3d_CubeMapOrder::Default());
//! Initialization to set cubemap directly by PixMap.
//! @thePixMap - origin PixMap
//! @theOrder - array conaining six different indexes of cubemap sides which maps tile grid to cubemap sides
Standard_EXPORT Graphic3d_CubeMapPacked (const Handle(Image_PixMap)& theImage,
const Graphic3d_ValidatedCubeMapOrder theOrder = Graphic3d_CubeMapOrder::Default());
//! Returns current cubemap side as PixMap.
//! Resulting PixMap is memory wrapper over original image.
//! Returns null handle if current side or whole cubemap is invalid.
//! Origin image has to contain six quad tiles having one sizes without any gaps to be valid.
Standard_EXPORT Handle(Image_PixMap) Value() Standard_OVERRIDE;
//! Empty destructor.
~Graphic3d_CubeMapPacked() {}
private:
//! Checks whether given tiles order is valid.
static Standard_Boolean checkOrder (const NCollection_Array1<unsigned int>& theOrder);
//! Checks whether given pixmap is valid to contain six tiles.
static Standard_Boolean checkImage (const Handle(Image_PixMap)& theImage,
unsigned int& theTileNumberX);
//! Tries to load image from file and checks it after that.
//! Does nothing in case of fail.
void tryLoadImage (const TCollection_AsciiString &theFilePath);
protected:
Graphic3d_CubeMapOrder myOrder; //!< order mapping tile grit to cubemap sides
unsigned int myTileNumberX; //!< width of tile grid
};
DEFINE_STANDARD_HANDLE(Graphic3d_CubeMapPacked, Graphic3d_CubeMap)
#endif // _Graphic3d_CubeMapPacked_HeaderFile

View File

@@ -0,0 +1,185 @@
// Author: Ilya Khramov
// 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 <Graphic3d_CubeMapSeparate.hxx>
#include <Image_AlienPixMap.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <OSD_File.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CubeMapSeparate, Graphic3d_CubeMap)
// =======================================================================
// function : Graphic3d_CubeMapSeparate
// purpose :
// =======================================================================
Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<TCollection_AsciiString>& thePaths)
{
if (thePaths.Size() == 6)
{
for (unsigned int i = 0; i < 6; ++i)
{
myPaths[i] = thePaths[i];
}
}
else
{
throw Standard_Failure("Invalid number of paths to load Graphic3d_CubeMapSeparate");
}
}
// =======================================================================
// function : Graphic3d_CubeMapSeparate
// purpose :
// =======================================================================
Graphic3d_CubeMapSeparate::Graphic3d_CubeMapSeparate (const NCollection_Array1<Handle(Image_PixMap)>& theImages)
{
if (theImages.Size() == 6)
{
if (theImages[0].IsNull())
{
return;
}
if (theImages[0]->SizeX() != theImages[0]->SizeY())
{
return;
}
myImages[0] = theImages[0];
myIsTopDown = myImages[0]->IsTopDown();
for (unsigned int i = 1; i < 6; ++i)
{
if (!theImages[i].IsNull())
{
if (theImages[i]->SizeX() == myImages[0]->SizeX()
&& theImages[i]->SizeY() == myImages[0]->SizeY()
&& theImages[i]->Format() == myImages[0]->Format()
&& theImages[i]->IsTopDown() == myImages[0]->IsTopDown())
{
myImages[i] = theImages[i];
continue;
}
}
resetImages();
return;
}
}
else
{
throw Standard_Failure("Invalid number of images in Graphic3d_CubeMapSeparate initialization");
}
}
// =======================================================================
// function : Value
// purpose :
// =======================================================================
Handle(Image_PixMap) Graphic3d_CubeMapSeparate::Value()
{
Graphic3d_CubeMapOrder anOrder = Graphic3d_CubeMapOrder::Default();
if (!myIsTopDown)
{
anOrder.Swap(Graphic3d_CMS_POS_Y, Graphic3d_CMS_NEG_Y);
}
if (!myImages[anOrder[myCurrentSide]].IsNull())
{
return myImages[anOrder[myCurrentSide]];
}
else
{
TCollection_AsciiString aFilePath;
myPaths[anOrder[myCurrentSide]].SystemName(aFilePath);
if (!aFilePath.IsEmpty())
{
Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap;
if (anImage->Load(aFilePath))
{
if (anImage->SizeX() == anImage->SizeY())
{
if (myCurrentSide == 0)
{
mySize = anImage->SizeX();
myFormat = anImage->Format();
myIsTopDown = anImage->IsTopDown();
return anImage;
}
else
{
if (anImage->Format() == myFormat
&& anImage->SizeX() == mySize
&& anImage->IsTopDown() == myIsTopDown)
{
return anImage;
}
else
{
Message::DefaultMessenger()->Send(TCollection_AsciiString() +
"'" + aFilePath + "' inconsistent image format or dimension in Graphic3d_CubeMapSeparate");
}
}
}
}
else
{
Message::DefaultMessenger()->Send(TCollection_AsciiString() +
"Unable to load '" + aFilePath + "' image of Graphic3d_CubeMapSeparate");
}
}
else
{
Message::DefaultMessenger()->Send(TCollection_AsciiString() +
"[" + myCurrentSide + "] path of Graphic3d_CubeMapSeparate is invalid");
}
}
return Handle(Image_PixMap)();
}
// =======================================================================
// function : IsDone
// purpose :
// =======================================================================
Standard_Boolean Graphic3d_CubeMapSeparate::IsDone() const
{
if (!myImages[0].IsNull())
{
return Standard_True;
}
for (unsigned int i = 0; i < 6; ++i)
{
OSD_File aCubeMapFile(myPaths[i]);
if (!aCubeMapFile.Exists())
{
return Standard_False;
}
}
return Standard_True;
}
// =======================================================================
// function : resetImages
// purpose :
// =======================================================================
void Graphic3d_CubeMapSeparate::resetImages()
{
for (unsigned int i = 0; i < 6; ++i)
{
myImages[i].Nullify();
}
}

View File

@@ -0,0 +1,71 @@
// Author: Ilya Khramov
// 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 _Graphic3d_CubeMapSeparate_HeaderFile
#define _Graphic3d_CubeMapSeparate_HeaderFile
#include <Graphic3d_CubeMap.hxx>
#include <NCollection_Array1.hxx>
#include <OSD_Path.hxx>
//! Class to manage cubemap located in six different images.
class Graphic3d_CubeMapSeparate : public Graphic3d_CubeMap
{
DEFINE_STANDARD_RTTIEXT(Graphic3d_CubeMapSeparate, Graphic3d_CubeMap)
public:
//! Initializes cubemap to be loaded from file.
//! @thePaths - array of paths to separate image files (has to have size equal 6).
Standard_EXPORT Graphic3d_CubeMapSeparate (const NCollection_Array1<TCollection_AsciiString>& thePaths);
//! Initializes cubemap to be setted directly from PixMaps.
//! @theImages - array if PixMaps (has to have size equal 6).
Standard_EXPORT Graphic3d_CubeMapSeparate(const NCollection_Array1<Handle(Image_PixMap)>& theImages);
//! Returns current side of cubemap as PixMap.
//! Returns null handle if current side or whole cubemap is invalid.
//! All origin images have to have the same sizes, format and quad shapes to form valid cubemap.
Standard_EXPORT Handle(Image_PixMap) Value() Standard_OVERRIDE;
//! Returns NULL.
virtual Handle(Image_PixMap) GetImage() const Standard_OVERRIDE
{
return Handle(Image_PixMap)();
}
//! Checks if a texture class is valid or not.
//! Returns true if the construction of the class is correct.
Standard_EXPORT Standard_Boolean IsDone() const Standard_OVERRIDE;
//! Empty destructor.
~Graphic3d_CubeMapSeparate() {}
protected:
OSD_Path myPaths[6]; //!< array of paths to cubemap images
Handle(Image_PixMap) myImages[6]; //!< array of cubemap images
Standard_Size mySize; //!< size of each side of cubemap
Image_Format myFormat; //!< format each side of cubemap
private:
//! Nulifies whole images array.
void resetImages();
};
DEFINE_STANDARD_HANDLE(Graphic3d_CubeMapSeparate, Graphic3d_CubeMap)
#endif // _Graphic3d_CubeMapSeparate_HeaderFile

View File

@@ -0,0 +1,29 @@
// Author: Ilya Khramov
// 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 _Graphic3d_CubeMapSide_HeaderFile
#define _Graphic3d_CubeMapSide_HeaderFile
//! Sides of cubemap in order of OpenGL rules
enum Graphic3d_CubeMapSide
{
Graphic3d_CMS_POS_X, //!< X axis positive direction side
Graphic3d_CMS_NEG_X, //!< X axis negative direction side
Graphic3d_CMS_POS_Y, //!< Y axis positive direction side
Graphic3d_CMS_NEG_Y, //!< Y axis negative direction side
Graphic3d_CMS_POS_Z, //!< Z axis positive direction side
Graphic3d_CMS_NEG_Z, //!< Z axis negative direction side
};
#endif // _Graphic3d_CubeMapSide_HeaderFile

View File

@@ -40,6 +40,8 @@ enum Graphic3d_TextureUnit
//Graphic3d_TextureUnit_MetallicRoughness = Graphic3d_TextureUnit_2, //!< metalness+roughness of the material
//Graphic3d_TextureUnit_Emissive = Graphic3d_TextureUnit_3, //!< emissive map controls the color and intensity of the light being emitted by the material
//Graphic3d_TextureUnit_Occlusion = Graphic3d_TextureUnit_4, //!< occlusion map indicating areas of indirect lighting
Graphic3d_TextureUnit_EnvMap = Graphic3d_TextureUnit_0 //!< environment cubemap for background
};
enum
{

View File

@@ -20,9 +20,15 @@
//! Describes type of view background.
enum Graphic3d_TypeOfBackground
{
Graphic3d_TOB_NONE,
Graphic3d_TOB_NONE = -1,
Graphic3d_TOB_GRADIENT,
Graphic3d_TOB_TEXTURE
Graphic3d_TOB_TEXTURE,
Graphic3d_TOB_CUBEMAP
};
enum
{
Graphic3d_TypeOfBackground_NB = Graphic3d_TOB_CUBEMAP + 1
};
#endif // _Graphic3d_TypeOfBackground_HeaderFile

View File

@@ -22,7 +22,8 @@ enum Graphic3d_TypeOfTexture
{
Graphic3d_TOT_1D,
Graphic3d_TOT_2D,
Graphic3d_TOT_2D_MIPMAP
Graphic3d_TOT_2D_MIPMAP,
Graphic3d_TOT_CUBEMAP
};
#endif // _Graphic3d_TypeOfTexture_HeaderFile