/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2023, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2023 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// // Renderer mip-map texture levels storage. #ifndef ODTRVISTEXTUREMIPMAP #define ODTRVISTEXTUREMIPMAP #include "TrVisTexture.h" #include "OdVector.h" #include "TD_PackPush.h" /** \details Mip-map texture levels storage. */ class OdTrVisTextureMipMap : public OdRxObject { protected: OdUInt32 m_nLevels; bool m_bAnisotropic; bool m_bSmooth; typedef OdVector TexturesArray; struct Level { OdTrVisTexturePtr m_pIsotropic; TexturesArray m_anisotropyX, m_anisotropyY; Level() : m_anisotropyX(0, 1), m_anisotropyY(0, 1) {} }; OdVector m_levels; protected: OdTrVisTextureMipMap(); void generateIsotropic(const OdTrVisTexture *pTexture, bool bSmooth); void generateAnisotropyFromIsotropic(); void removeAnisotropy(); OdTrVisTexturePtr createTexture(const OdTrVisTexture *pFrom, OdUInt32 nWidth, OdUInt32 nHeight); void resampleTexture(OdTrVisTexture *pTo, const OdTrVisTexture *pFrom, bool bSmooth); public: ~OdTrVisTextureMipMap() override; // Original texture data. const OdTrVisTexture *originalTexture() const { return (isInitialized()) ? m_levels.getPtr()->m_pIsotropic.get() : nullptr; } const OdTrVisTexture *safeOriginalTexture() const { if (!isInitialized()) throw OdError(eNullPtr); return m_levels.getPtr()->m_pIsotropic; } OdUInt32 originalTextureWidth() const { return safeOriginalTexture()->getTextureWidth(); } OdUInt32 originalTextureHeight() const { return safeOriginalTexture()->getTextureHeight(); } // Format information. OdUInt32 getDataAlignment() const { return safeOriginalTexture()->getDataAlignment(); } bool isFPImage() const { return safeOriginalTexture()->isFPImage(); } OdUInt32 channelsMask() const { return safeOriginalTexture()->channelsMask(); } OdTrVisTexture::Format format() const { return safeOriginalTexture()->format(); } OdUInt32 pixelSize() const { return safeOriginalTexture()->pixelSize(); } // Stored mip-map information. OdUInt32 numLevels() const { return m_nLevels; } bool isInitialized() const { return m_nLevels > 0; } bool isAnisotropic() const { return m_bAnisotropic; } bool isSmoothFilterApplied() const { return m_bSmooth; } // Mip-map level accessors. const OdTrVisTexture *isotropicLevel(OdUInt32 nLevel) { if (nLevel < m_nLevels) return m_levels.getPtr()[nLevel].m_pIsotropic; return nullptr; } const OdTrVisTexture *anisotropicLevel(OdUInt32 nLevelX, OdUInt32 nLevelY) { if (nLevelX < m_nLevels && nLevelY < m_nLevels) { const bool bAnisotropyY = nLevelX < nLevelY/*, bIsotropy = nLevelX == nLevelY*/; const Level &pLevel = m_levels.getPtr()[(bAnisotropyY) ? nLevelX : nLevelY]; return (bAnisotropyY) ? pLevel.m_anisotropyY.getPtr()[nLevelY] : pLevel.m_anisotropyX.getPtr()[nLevelX]; } return nullptr; } // Mip-map generation. // Only valid with empty arrays. void generate(const OdTrVisTexture *pTexture, bool bAnisotropic = false, bool bSmooth = true); // Only valid with previously computed arrays. void update(bool bSmooth); void update() { update(isSmoothFilterApplied()); } // Converts isotropic to anisotropic or vice versa. void convert(bool bAnisotropic); // Clear. void clear(); }; typedef OdSmartPtr OdTrVisTextureMipMapPtr; #include "TD_PackPop.h" #endif // ODTRVISTEXTUREMIPMAP