1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00
Files
occt/src/Graphic3d/Graphic3d_CubeMap.hxx
kgv faff37677c 0031478: Visualization, TKOpenGl - allow uploading Cubemap in compressed DDS format when supported by GPU
Graphic3d_TextureRoot::GetCompressedImage() - added new interface for fetching compressed texture image.
Default implementation detects DDS image files using Image_DDSParser parser.

Graphic3d_TextureRoot::GetImage() has been extended with new parameter
- the list of image formats supported by OpenGL driver.
Graphic3d_TextureRoot::convertToCompatible() implicitly converts
BGRA image to RGBA on OpenGL ES, which normally does not support BGR formats.

OpenGl_Caps::isTopDownTextureUV - new property defines how application defines
UV texture coordinates in primitive arrays.
OpenGl_Context::SetTextureMatrix() compares this flag with OpenGl_Texture::IsTopDown()
and automatically flips V coordinate in case of mismatch.

OpenGl_Texture now holds exact number of mipmap levels
instead of Boolean flag indicating that they are defined.
This allows loading DDS files with incomplete mipmap level set
by setting GL_TEXTURE_MAX_LEVEL to appropriate value instead of default 1000
(causing black textures in case if mipmap levels are not defined till 1x1).

Fixed order of texture coordinates transformation within GLSL program to match FFP matrix:
Rotate -> Translate -> Scale (previously Rotation was applied afterwards).
2020-05-22 11:08:34 +03:00

117 lines
4.2 KiB
C++

// 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,
Standard_Boolean theToGenerateMipmaps = Standard_False) :
Graphic3d_TextureMap (theFileName, Graphic3d_TOT_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myZIsInverted (false),
myHasMipmaps (theToGenerateMipmaps)
{}
//! Constructor defining direct cubemap initialization from PixMap.
Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)(),
Standard_Boolean theToGenerateMipmaps = Standard_False) :
Graphic3d_TextureMap (thePixmap, Graphic3d_TOT_CUBEMAP),
myCurrentSide (Graphic3d_CMS_POS_X),
myEndIsReached (false),
myZIsInverted (false),
myHasMipmaps (theToGenerateMipmaps)
{}
//! 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);
}
}
//! 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 whether mipmaps of cubemap will be generated or not.
Standard_Boolean HasMipmaps() const { return myHasMipmaps; }
//! Sets whether to generate mipmaps of cubemap or not.
void SetMipmapsGeneration (Standard_Boolean theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; }
//! Returns current cubemap side as compressed PixMap.
//! Returns null handle if current side is invalid or if image is not in supported compressed format.
virtual Handle(Image_CompressedPixMap) CompressedValue (const Handle(Image_SupportedFormats)& theSupported) = 0;
//! Returns PixMap containing current side of cubemap.
//! Returns null handle if current side is invalid.
virtual Handle(Image_PixMap) Value (const Handle(Image_SupportedFormats)& theSupported) = 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 myZIsInverted; //!< Indicates whether Z axis is inverted that allows to synchronize vertical flip of cubemap
Standard_Boolean myHasMipmaps; //!< Indicates whether mipmaps of cubemap will be generated or not
};
DEFINE_STANDARD_HANDLE(Graphic3d_CubeMap, Graphic3d_TextureMap)
#endif // _Graphic3d_CubeMap_HeaderFile