CFx SDK Documentation  2020SP3
TrVisTexture.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 // GLES2 device textures
24 
25 #ifndef ODTRVISTEXTURE
26 #define ODTRVISTEXTURE
27 
28 #include "TD_PackPush.h"
29 
30 #include "TrVisDefs.h"
31 
36 class OdTrVisTexture : public OdRxObject
37 {
38 protected:
42 
44 
45 public:
49  enum Format
50  {
61  };
69  {
71  float floatRGBA[ 4 ];
72  };
77  {
79  {
80  kNone = 0,
83  };
85 
86  void prepareContext( const OdTrVisTexture* pSrc, const OdTrVisTexture* pDst );
87 
88  bool isSrcInt;
89  bool isDstInt;
92  double scalesMult[ 4 ];
93  };
94 
95  virtual ~OdTrVisTexture();
96 
97  // non-virtual part of OdTrVisTexture inline interface.
98 
99  // Typical data accessors
100  OdUInt32 getTextureWidth() const { return m_nWidth; }
101  OdUInt32 getTextureHeight() const { return m_nHeight; }
104 
105  const OdUInt8 *textureData() const { return (const OdUInt8*)m_pTextureData; }
107 
108  // Part of virtual OdTrVisTexture interface
109 
110  // Some types of texture formats can have limitation (for example S3TC - DXT formats require consists from 4x4 blocks, so texture size must be divideable by 4).
111  virtual OdUInt32 subDivLimit() const = 0;
112 
113  // Typically textures store data as integers, but may as floats. So we require ability to access texture pixels similarly for all texture sub-types.
114  virtual bool isFPImage() const = 0;
115 
116  virtual void getColor(OdUInt32 nX, OdUInt32 nY, TextureColor &color) const = 0;
117  virtual void setColor( OdUInt32 nX, OdUInt32 nY, const TextureColor &color ) = 0;
118 
119  // This is also can be helpful for algorithms optimization to have accessors for entire scanlines
120  virtual void getScanline(OdUInt32 startLine, OdUInt32 linesCount, TextureColor *pScanline) const
121  {
122  for( OdUInt32 i = 0; i < linesCount; ++i )
123  {
125  for( OdUInt32 j = 0; j < getTextureWidth(); ++j )
126  {
127  getColor( j, startLine + i, pScanline[ j + offset ] );
128  }
129  }
130  }
131 
132  virtual void setScanline(OdUInt32 startLine, OdUInt32 linesCount, const TextureColor *pScanline)
133  {
134  for( OdUInt32 i = 0; i < linesCount; ++i )
135  {
137  for( OdUInt32 j = 0; j < getTextureWidth(); ++j )
138  {
139  setColor( j, startLine + i, pScanline[ j + offset ] );
140  }
141  }
142  }
143 
144  // Probably we will require color setters or etc.
145 
146  // Textures in Lut format contain color indexes. Color palette can be stored simply as another 1D texture.
147  virtual void setPalette(OdTrVisTexture *pTexture) = 0;
148  virtual OdTrVisTexture *palette() = 0;
149  virtual const OdTrVisTexture *palette() const = 0;
150 
151  // We can't rescale indexed textures with bilinear interpolation
152  virtual bool isSmoothResampleSupported() const = 0;
153 
154  virtual Format format() const = 0;
158  virtual TextureColor getMaxValues() const = 0;
162  static void prepareTextureColors( TextureColor* colors, OdUInt32 size, const TextureColorContext& context );
166  virtual void beginEditing() = 0;
167  virtual void endEditing() = 0;
168 };
169 
171 
176 {
177 public:
179  {
181  kBilinear
182  };
183 public:
191  static OdTrVisTexturePtr convert( OdTrVisTexture::Format fmt, OdTrVisTexture* pTexture, OdUInt32 nNewAlign = 0, OdTrVisTexture* pPalette = NULL );
195  static OdTrVisTexturePtr convert( OdTrVisTexture *pTextureTo, const OdTrVisTexture* pTextureFrom, Resampler method = kNearest );
199  static OdTrVisTexturePtr resample( Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, OdTrVisTexture* pTexture );
203  static OdTrVisTexturePtr convertAndResample( OdTrVisTexture::Format fmt, Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, OdTrVisTexture* pTexture, OdUInt32 nNewAlign = 0, OdTrVisTexture* pPalette = NULL );
207  static OdTrVisTexturePtr resamplePow2(Resampler method, bool bRequirePow2, OdTrVisTexture *pTexture, OdUInt32 nMaxSize);
212  OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, void* buffer, Resampler method, OdTrVisTexture* pPalette = NULL );
213 
217  static OdTrVisTexturePtr createPow2TextureFrom( OdTrVisTexture::Format fmt, bool bRequirePow2, OdUInt32 nMaxSize, OdUInt32 nAlign,
218  OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, void* buffer, Resampler method, OdTrVisTexture* pPalette = NULL );
219 
224  bool bOwnExistBuffer = false );
228  static bool save(OdTrVisTexture *pTexture, const OdString &fileName);
229 
230 };
231 
232 
233 #include "TD_PackPop.h"
234 
235 #endif
OdTrVisTexture::TextureColorContext::kDifferentDataTypes
@ kDifferentDataTypes
Definition: TrVisTexture.h:81
OdString
Definition: OdString.h:95
NULL
#define NULL
Definition: GsProperties.h:177
OdTrVisTexture::kAlpha
@ kAlpha
Definition: TrVisTexture.h:59
OdTrVisTexture::setPalette
virtual void setPalette(OdTrVisTexture *pTexture)=0
OdTrVisTexture::kFloatRGBA
@ kFloatRGBA
Definition: TrVisTexture.h:55
OdTrVisTexture::m_nScanLength
OdUInt32 m_nScanLength
Definition: TrVisTexture.h:40
OdUInt8
unsigned char OdUInt8
Definition: OdPlatformSettings.h:759
OdTrVisTextureManager::save
static bool save(OdTrVisTexture *pTexture, const OdString &fileName)
OdTrVisTexture::getScanline
virtual void getScanline(OdUInt32 startLine, OdUInt32 linesCount, TextureColor *pScanline) const
Definition: TrVisTexture.h:120
OdTrVisTextureManager::createTexture
static OdTrVisTexturePtr createTexture(OdTrVisTexture::Format fmt, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nAlign=4)
OdTrVisTexture::prepareTextureColors
static void prepareTextureColors(TextureColor *colors, OdUInt32 size, const TextureColorContext &context)
buffer
GLuint buffer
Definition: gles2_ext.h:178
OdTrVisTexture::isFPImage
virtual bool isFPImage() const =0
OdTrVisTexture::textureData
const OdUInt8 * textureData() const
Definition: TrVisTexture.h:105
OdRxObject
Definition: RxObject.h:564
OdTrVisTexture::kHalfFloatRGBA
@ kHalfFloatRGBA
Definition: TrVisTexture.h:57
OdTrVisTexture::subDivLimit
virtual OdUInt32 subDivLimit() const =0
OdTrVisTexture::kPalette
@ kPalette
Definition: TrVisTexture.h:56
OdTrVisTexture::TextureColor::floatRGBA
float floatRGBA[4]
Definition: TrVisTexture.h:71
OdTrVisTexture::~OdTrVisTexture
virtual ~OdTrVisTexture()
OdTrVisTextureManager::convert
static OdTrVisTexturePtr convert(OdTrVisTexture::Format fmt, OdTrVisTexture *pTexture, OdUInt32 nNewAlign=0, OdTrVisTexture *pPalette=NULL)
OdTrVisTexture::TextureColorContext::isDstInt
bool isDstInt
Definition: TrVisTexture.h:89
TD_PackPop.h
OdTrVisTexture::kRGBA
@ kRGBA
Definition: TrVisTexture.h:53
OdTrVisTexture::kBGR
@ kBGR
Definition: TrVisTexture.h:52
OdTrVisTexture::setScanline
virtual void setScanline(OdUInt32 startLine, OdUInt32 linesCount, const TextureColor *pScanline)
Definition: TrVisTexture.h:132
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdTrVisTexturePtr
OdSmartPtr< OdTrVisTexture > OdTrVisTexturePtr
Definition: TrVisTexture.h:170
size
GLsizeiptr size
Definition: gles2_ext.h:182
OdTrVisTexture::getColor
virtual void getColor(OdUInt32 nX, OdUInt32 nY, TextureColor &color) const =0
OdTrVisTextureManager::Resampler
Resampler
Definition: TrVisTexture.h:179
OdTrVisTexture::Format
Format
Definition: TrVisTexture.h:50
OdTrVisTextureManager::createTextureFrom
static OdTrVisTexturePtr createTextureFrom(OdTrVisTexture::Format fmt, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nAlign, void *buffer, OdTrVisTexture *pPalette=NULL, bool bOwnExistBuffer=false)
OdTrVisTexture::setColor
virtual void setColor(OdUInt32 nX, OdUInt32 nY, const TextureColor &color)=0
OdTrVisTexture::m_pTextureData
void * m_pTextureData
Definition: TrVisTexture.h:41
OdTrVisTextureManager
Definition: TrVisTexture.h:176
OdTrVisTexture::kRed
@ kRed
Definition: TrVisTexture.h:58
OdTrVisTexture::kColorDepth32bit
@ kColorDepth32bit
Definition: TrVisTexture.h:60
OdTrVisTexture::TextureColorContext::srcMax
TextureColor srcMax
Definition: TrVisTexture.h:90
OdTrVisTexture::palette
virtual OdTrVisTexture * palette()=0
OdTrVisTextureManager::convert
static OdTrVisTexturePtr convert(OdTrVisTexture *pTextureTo, const OdTrVisTexture *pTextureFrom, Resampler method=kNearest)
OdTrVisTexture::TextureColor::intRGBA
OdUInt32 intRGBA[4]
Definition: TrVisTexture.h:70
OdSmartPtr< OdTrVisTexture >
OdTrVisTextureManager::createPow2TextureFrom
static OdTrVisTexturePtr createPow2TextureFrom(OdTrVisTexture::Format fmt, bool bRequirePow2, OdUInt32 nMaxSize, OdUInt32 nAlign, OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, void *buffer, Resampler method, OdTrVisTexture *pPalette=NULL)
offset
GLintptr offset
Definition: gles2_ext.h:183
OdTrVisTexture::TextureColorContext::kDifferentScales
@ kDifferentScales
Definition: TrVisTexture.h:82
OdTrVisTextureManager::kBilinear
@ kBilinear
Definition: TrVisTexture.h:181
OdTrVisTexture::TextureColorContext::kNone
@ kNone
Definition: TrVisTexture.h:80
TrVisDefs.h
OdTrVisTexture::format
virtual Format format() const =0
OdTrVisTexture::TextureColor
Definition: TrVisTexture.h:69
OdTrVisTexture::getScanlineLength
OdUInt32 getScanlineLength() const
Definition: TrVisTexture.h:102
TD_PackPush.h
OdTrVisTexture::TextureColorContext::difference
OdUInt8 difference
Definition: TrVisTexture.h:84
OdTrVisTexture::kRGB
@ kRGB
Definition: TrVisTexture.h:51
OdTrVisTextureManager::convertAndResample
static OdTrVisTexturePtr convertAndResample(OdTrVisTexture::Format fmt, Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, OdTrVisTexture *pTexture, OdUInt32 nNewAlign=0, OdTrVisTexture *pPalette=NULL)
OdTrVisTexture
Definition: TrVisTexture.h:37
OdTrVisTexture::m_nHeight
OdUInt32 m_nHeight
Definition: TrVisTexture.h:39
OdTrVisTexture::m_nAlignment
OdUInt32 m_nAlignment
Definition: TrVisTexture.h:40
OdTrVisTexture::TextureColorContext
Definition: TrVisTexture.h:77
OdTrVisTextureManager::resamplePow2
static OdTrVisTexturePtr resamplePow2(Resampler method, bool bRequirePow2, OdTrVisTexture *pTexture, OdUInt32 nMaxSize)
OdTrVisTexture::palette
virtual const OdTrVisTexture * palette() const =0
OdTrVisTexture::TextureColorContext::isSrcInt
bool isSrcInt
Definition: TrVisTexture.h:88
OdTrVisTexture::OdTrVisTexture
OdTrVisTexture()
OdTrVisTexture::TextureColorContext::scalesMult
double scalesMult[4]
Definition: TrVisTexture.h:92
OdTrVisTextureManager::resample
static OdTrVisTexturePtr resample(Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, OdTrVisTexture *pTexture)
OdTrVisTexture::getTextureHeight
OdUInt32 getTextureHeight() const
Definition: TrVisTexture.h:101
OdTrVisTexture::TextureColorContext::dstMax
TextureColor dstMax
Definition: TrVisTexture.h:91
OdTrVisTexture::getDataAlignment
OdUInt32 getDataAlignment() const
Definition: TrVisTexture.h:103
OdTrVisTexture::textureData
OdUInt8 * textureData()
Definition: TrVisTexture.h:106
OdTrVisTexture::getMaxValues
virtual TextureColor getMaxValues() const =0
OdTrVisTexture::TextureColorContext::prepareContext
void prepareContext(const OdTrVisTexture *pSrc, const OdTrVisTexture *pDst)
OdTrVisTexture::endEditing
virtual void endEditing()=0
OdTrVisTexture::beginEditing
virtual void beginEditing()=0
OdTrVisTexture::getTextureWidth
OdUInt32 getTextureWidth() const
Definition: TrVisTexture.h:100
OdTrVisTexture::kBGRA
@ kBGRA
Definition: TrVisTexture.h:54
OdTrVisTexture::isSmoothResampleSupported
virtual bool isSmoothResampleSupported() const =0
OdTrVisTextureManager::createTextureFrom
static OdTrVisTexturePtr createTextureFrom(OdTrVisTexture::Format fmt, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nAlign, OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, void *buffer, Resampler method, OdTrVisTexture *pPalette=NULL)
OdTrVisTexture::TextureColorContext::Difference
Difference
Definition: TrVisTexture.h:79
OdTrVisTexture::m_nWidth
OdUInt32 m_nWidth
Definition: TrVisTexture.h:39
OdTrVisTextureManager::kNearest
@ kNearest
Definition: TrVisTexture.h:180