File indexing completed on 2026-09-27 09:18:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _OpenGl_TileSampler_H
0017 #define _OpenGl_TileSampler_H
0018
0019 #include <OpenGl_Texture.hxx>
0020 #include <OpenGl_HaltonSampler.hxx>
0021
0022 #include <Image_PixMapTypedData.hxx>
0023 #include <NCollection_LinearVector.hxx>
0024
0025 class Graphic3d_RenderingParams;
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class OpenGl_TileSampler
0036 {
0037 public:
0038
0039 Standard_EXPORT OpenGl_TileSampler();
0040
0041
0042 NCollection_Vec2<int> TileSize() const { return NCollection_Vec2<int>(myTileSize, myTileSize); }
0043
0044
0045 float VarianceScaleFactor() const { return myScaleFactor; }
0046
0047
0048 int NbTilesX() const { return (int)myTiles.SizeX; }
0049
0050
0051 int NbTilesY() const { return (int)myTiles.SizeY; }
0052
0053
0054 int NbTiles() const { return int(myTiles.SizeX * myTiles.SizeY); }
0055
0056
0057 const NCollection_Vec2<int>& ViewSize() const { return myViewSize; }
0058
0059
0060 NCollection_Vec2<int> NbOffsetTiles(bool theAdaptive) const
0061 {
0062 return theAdaptive
0063 ? NCollection_Vec2<int>((int)myOffsetsShrunk.SizeX, (int)myOffsetsShrunk.SizeY)
0064 : NCollection_Vec2<int>((int)myOffsets.SizeX, (int)myOffsets.SizeY);
0065 }
0066
0067
0068 NCollection_Vec2<int> NbOffsetTilesMax() const
0069 {
0070 return NbOffsetTiles(true).cwiseMax(NbOffsetTiles(false));
0071 }
0072
0073
0074 NCollection_Vec2<int> OffsetTilesViewport(bool theAdaptive) const
0075 {
0076 return NbOffsetTiles(theAdaptive) * myTileSize;
0077 }
0078
0079
0080 NCollection_Vec2<int> OffsetTilesViewportMax() const { return NbOffsetTilesMax() * myTileSize; }
0081
0082
0083 int MaxTileSamples() const
0084 {
0085 int aNbSamples = 0;
0086 for (size_t aRowIter = 0; aRowIter < myTiles.SizeY; ++aRowIter)
0087 {
0088 for (size_t aColIter = 0; aColIter < myTiles.SizeX; ++aColIter)
0089 {
0090 aNbSamples = (std::max)(aNbSamples, static_cast<int>(myTiles.Value(aRowIter, aColIter)));
0091 }
0092 }
0093 return aNbSamples;
0094 }
0095
0096
0097 Standard_EXPORT void SetSize(const Graphic3d_RenderingParams& theParams,
0098 const NCollection_Vec2<int>& theSize);
0099
0100
0101
0102 Standard_EXPORT void GrabVarianceMap(const occ::handle<OpenGl_Context>& theContext,
0103 const occ::handle<OpenGl_Texture>& theTexture);
0104
0105
0106 void Reset() { myLastSample = 0; }
0107
0108
0109 bool UploadSamples(const occ::handle<OpenGl_Context>& theContext,
0110 const occ::handle<OpenGl_Texture>& theSamplesTexture,
0111 const bool theAdaptive)
0112 {
0113 return upload(theContext, theSamplesTexture, occ::handle<OpenGl_Texture>(), theAdaptive);
0114 }
0115
0116
0117 bool UploadOffsets(const occ::handle<OpenGl_Context>& theContext,
0118 const occ::handle<OpenGl_Texture>& theOffsetsTexture,
0119 const bool theAdaptive)
0120 {
0121 return upload(theContext, occ::handle<OpenGl_Texture>(), theOffsetsTexture, theAdaptive);
0122 }
0123
0124 protected:
0125
0126 int tileArea(int theX, int theY) const
0127 {
0128 const int aSizeX = (std::min)(myTileSize, myViewSize.x() - theX * myTileSize);
0129 const int aSizeY = (std::min)(myTileSize, myViewSize.y() - theY * myTileSize);
0130 return aSizeX * aSizeY;
0131 }
0132
0133
0134 Standard_EXPORT NCollection_Vec2<int> nextTileToSample();
0135
0136
0137 Standard_EXPORT bool upload(const occ::handle<OpenGl_Context>& theContext,
0138 const occ::handle<OpenGl_Texture>& theSamplesTexture,
0139 const occ::handle<OpenGl_Texture>& theOffsetsTexture,
0140 const bool theAdaptive);
0141
0142
0143 Standard_EXPORT void dumpMap(std::ostream& theStream,
0144 const Image_PixMapTypedData<int>& theMap,
0145 const char* theTitle) const;
0146
0147 protected:
0148
0149 Image_PixMapTypedData<unsigned int> myTiles;
0150 Image_PixMapTypedData<unsigned int> myTileSamples;
0151 Image_PixMapTypedData<float> myVarianceMap;
0152 Image_PixMapTypedData<int> myVarianceRaw;
0153 Image_PixMapTypedData<NCollection_Vec2<int>> myOffsets;
0154 Image_PixMapTypedData<NCollection_Vec2<int>> myOffsetsShrunk;
0155 NCollection_LinearVector<float> myMarginalMap;
0156 OpenGl_HaltonSampler mySampler;
0157 unsigned int myLastSample;
0158 float myScaleFactor;
0159
0160 int myTileSize;
0161 NCollection_Vec2<int> myViewSize;
0162 };
0163
0164 #endif