CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
TrVisTexture.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 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#include "TPtr.h"
32#include "RxObjectImpl.h"
33
37
38class OdTrVisTexture : public OdRxObject
39{
40protected:
44
46
47public:
51 enum Format
52 { // Basic 8 bit formats
61
62 //Depth/Stencil
65 kDepth24Stencil8,//Most used depth format. getColor() returns only depth value. For stencil data use textureData() function
67
68 //16 bit
73
74 //Float
81
82 //Signed normalized
91
93 };
94
101 {
103 float floatRGBA[ 4 ];
104 };
105
126
128
129 // non-virtual part of OdTrVisTexture inline interface.
130
131 // Typical data accessors
136
137 const OdUInt8 *textureData() const { return (const OdUInt8*)m_pTextureData; }
139
140 // Part of virtual OdTrVisTexture interface
141
142 // 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).
143 virtual OdUInt32 subDivLimit() const = 0;
144
145 // Typically textures store data as integers, but may as floats. So we require ability to access texture pixels similarly for all texture sub-types.
146 virtual bool isFPImage() const = 0;
147
148 virtual void getColor(OdUInt32 nX, OdUInt32 nY, TextureColor &color) const = 0;
149 virtual void setColor( OdUInt32 nX, OdUInt32 nY, const TextureColor &color ) = 0;
150
151 // This is also can be helpful for algorithms optimization to have accessors for entire scanlines
152 virtual void getScanline(OdUInt32 startLine, OdUInt32 linesCount, TextureColor *pScanline) const
153 {
154 for( OdUInt32 i = 0; i < linesCount; ++i )
155 {
157 for( OdUInt32 j = 0; j < getTextureWidth(); ++j )
158 {
159 getColor( j, startLine + i, pScanline[ j + offset ] );
160 }
161 }
162 }
163
164 virtual void setScanline(OdUInt32 startLine, OdUInt32 linesCount, const TextureColor *pScanline)
165 {
166 for( OdUInt32 i = 0; i < linesCount; ++i )
167 {
169 for( OdUInt32 j = 0; j < getTextureWidth(); ++j )
170 {
171 setColor( j, startLine + i, pScanline[ j + offset ] );
172 }
173 }
174 }
175
176 // Probably we will require color setters or etc.
177
178 // Textures in Lut format contain color indexes. Color palette can be stored simply as another 1D texture.
179 virtual void setPalette(const OdTrVisTexture *pTexture) = 0;
180 virtual OdTrVisTexture *palette() = 0;
181 virtual const OdTrVisTexture *palette() const = 0;
182
183 // We can't rescale indexed textures with bilinear interpolation
184 virtual bool isSmoothResampleSupported() const = 0;
185
186 virtual Format format() const = 0;
187
191 virtual OdUInt32 pixelSize() const = 0;
192
196 virtual TextureColor getMaxValues() const = 0;
200 virtual TextureColor getMinValues() const;
204 static void prepareTextureColors( TextureColor* colors, size_t size, const TextureColorContext& context );
208 virtual void beginEditing() = 0;
209 virtual void endEditing() = 0;
210};
211
213
214
219{
220public:
226public:
234 static OdTrVisTexturePtr convert( OdTrVisTexture::Format fmt, const OdTrVisTexture* pTexture, OdUInt32 nNewAlign = 0, const OdTrVisTexture* pPalette = NULL );
238 static OdTrVisTexturePtr convert( OdTrVisTexture *pTextureTo, const OdTrVisTexture* pTextureFrom, Resampler method = kNearest );
242 static void cropTexture(OdTrVisTexture *pTexture, OdUInt32 nPosX, OdUInt32 nPosY, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nNewAlign = 0);
246 static OdTrVisTexturePtr crop(const OdTrVisTexture *pTexture, OdUInt32 nPosX, OdUInt32 nPosY, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nNewAlign = 0);
250 static void negateTexture(OdTrVisTexture* pTexture);
254 static OdTrVisTexturePtr negate(const OdTrVisTexture* pTexture);
258 static void grayscaleTexture(OdTrVisTexture* pTexture, OdUInt32 nApplyComponent = 7);
262 static OdTrVisTexturePtr grayscale(const OdTrVisTexture* pTexture, OdUInt32 nApplyComponent = 7);
266 static void blurTexture(OdTrVisTexture* pTexture, OdUInt32 nSizeKernel = 3, float fKernelMultiplier = 1.0f);
270 static OdTrVisTexturePtr blur(const OdTrVisTexture* pTexture, OdUInt32 nSizeKernel = 3, float fKernelMultiplier = 1.0f);
274 static void sphereMapTexture(OdTrVisTexture *pTexture, const OdTrVisTexture *pRightTexture, const OdTrVisTexture *pLeftTexture,
275 const OdTrVisTexture *pTopTexture, const OdTrVisTexture *pBottomTexture, const OdTrVisTexture *pFrontTexture,
276 const OdTrVisTexture *pBackTexture, int antiAliasLevel = 1, bool bSineCorrection = false);
280 static OdTrVisTexturePtr sphereMap(const OdTrVisTexture *pRightTexture, const OdTrVisTexture *pLeftTexture, const OdTrVisTexture *pTopTexture,
281 const OdTrVisTexture *pBottomTexture, const OdTrVisTexture *pFrontTexture, const OdTrVisTexture *pBackTexture,
282 int antiAliasLevel = 1, bool bSineCorrection = false);
287 { float m_coef[4];
288 ChannelMapping &set(float redMap, float greenMap, float blueMap, float alphaMap)
289 { m_coef[0] = redMap; m_coef[1] = greenMap; m_coef[2] = blueMap; m_coef[3] = alphaMap; return *this; }
290 explicit ChannelMapping(float redMap = 0.0f, float greenMap = 0.0f, float blueMap = 0.0, float alphaMap = 0.0)
291 { set(redMap, greenMap, blueMap, alphaMap); } };
292
293
295 static void remapTextureChannels(OdTrVisTexture* pTexture, const ChannelMapping &redMap = ChannelMapping(1.0f),
296 const ChannelMapping &greenMap = ChannelMapping(0.0f, 1.0f), const ChannelMapping &blueMap = ChannelMapping(0.0f, 0.0f, 1.0f),
297 const ChannelMapping &alphaMap = ChannelMapping(0.0f, 0.0f, 0.0f, 1.0f));
301 static OdTrVisTexturePtr mapChannels(const OdTrVisTexture* pTexture, const ChannelMapping &redMap = ChannelMapping(1.0f),
302 const ChannelMapping &greenMap = ChannelMapping(0.0f, 1.0f), const ChannelMapping &blueMap = ChannelMapping(0.0f, 0.0f, 1.0f),
303 const ChannelMapping &alphaMap = ChannelMapping(0.0f, 0.0f, 0.0f, 1.0f));
307 static OdTrVisTexturePtr clone(const OdTrVisTexture* pTexture);
311 static OdTrVisTexturePtr resample( Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, const OdTrVisTexture* pTexture );
315 static OdTrVisTexturePtr convertAndResample( OdTrVisTexture::Format fmt, Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, const OdTrVisTexture* pTexture, OdUInt32 nNewAlign = 0, const OdTrVisTexture* pPalette = NULL );
319 static OdTrVisTexturePtr resamplePow2(Resampler method, bool bRequirePow2, const OdTrVisTexture *pTexture, OdUInt32 nMaxSize);
324 OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, const void* buffer, Resampler method, const OdTrVisTexture* pPalette = NULL );
325
329 static OdTrVisTexturePtr createPow2TextureFrom( OdTrVisTexture::Format fmt, bool bRequirePow2, OdUInt32 nMaxSize, OdUInt32 nAlign,
330 OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, const void* buffer, Resampler method, const OdTrVisTexture* pPalette = NULL );
331
335 static OdTrVisTexturePtr createTextureFrom( OdTrVisTexture::Format fmt, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nAlign, const void* buffer, const OdTrVisTexture* pPalette = NULL,
336 bool bOwnExistBuffer = false );
340 static bool pow2ResampleDimensions( OdUInt32 &nResultWidth, OdUInt32 &nResultHeight, OdUInt32 nInWidth, OdUInt32 nInHeight, bool bRequirePow2, OdUInt32 nMaxSize );
344 static bool save(const OdTrVisTexture *pTexture, const OdString &fileName);
345};
346
347
348#include "TD_PackPop.h"
349
350#endif
unsigned int OdUInt32
unsigned char OdUInt8
OdSmartPtr< OdTrVisTexture > OdTrVisTexturePtr
OdUInt8 * textureData()
OdUInt32 m_nWidth
virtual void endEditing()=0
virtual void beginEditing()=0
virtual const OdTrVisTexture * palette() const =0
virtual TextureColor getMaxValues() const =0
virtual void getColor(OdUInt32 nX, OdUInt32 nY, TextureColor &color) const =0
virtual void setScanline(OdUInt32 startLine, OdUInt32 linesCount, const TextureColor *pScanline)
OdUInt32 m_nAlignment
virtual OdTrVisTexture * palette()=0
virtual void setColor(OdUInt32 nX, OdUInt32 nY, const TextureColor &color)=0
virtual TextureColor getMinValues() const
OdUInt32 getScanlineLength() const
virtual OdUInt32 subDivLimit() const =0
OdUInt32 m_nScanLength
void * m_pTextureData
virtual OdUInt32 pixelSize() const =0
virtual bool isSmoothResampleSupported() const =0
static void prepareTextureColors(TextureColor *colors, size_t size, const TextureColorContext &context)
virtual ~OdTrVisTexture()
virtual void getScanline(OdUInt32 startLine, OdUInt32 linesCount, TextureColor *pScanline) const
const OdUInt8 * textureData() const
virtual Format format() const =0
OdUInt32 getDataAlignment() const
virtual void setPalette(const OdTrVisTexture *pTexture)=0
virtual bool isFPImage() const =0
OdUInt32 m_nHeight
OdUInt32 getTextureHeight() const
OdUInt32 getTextureWidth() const
static bool save(const OdTrVisTexture *pTexture, const OdString &fileName)
static OdTrVisTexturePtr convert(OdTrVisTexture *pTextureTo, const OdTrVisTexture *pTextureFrom, Resampler method=kNearest)
static OdTrVisTexturePtr blur(const OdTrVisTexture *pTexture, OdUInt32 nSizeKernel=3, float fKernelMultiplier=1.0f)
static OdTrVisTexturePtr convertAndResample(OdTrVisTexture::Format fmt, Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, const OdTrVisTexture *pTexture, OdUInt32 nNewAlign=0, const OdTrVisTexture *pPalette=NULL)
static OdTrVisTexturePtr createTextureFrom(OdTrVisTexture::Format fmt, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nAlign, OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, const void *buffer, Resampler method, const OdTrVisTexture *pPalette=NULL)
static OdTrVisTexturePtr mapChannels(const OdTrVisTexture *pTexture, const ChannelMapping &redMap=ChannelMapping(1.0f), const ChannelMapping &greenMap=ChannelMapping(0.0f, 1.0f), const ChannelMapping &blueMap=ChannelMapping(0.0f, 0.0f, 1.0f), const ChannelMapping &alphaMap=ChannelMapping(0.0f, 0.0f, 0.0f, 1.0f))
static OdTrVisTexturePtr createTextureFrom(OdTrVisTexture::Format fmt, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nAlign, const void *buffer, const OdTrVisTexture *pPalette=NULL, bool bOwnExistBuffer=false)
static void grayscaleTexture(OdTrVisTexture *pTexture, OdUInt32 nApplyComponent=7)
static void remapTextureChannels(OdTrVisTexture *pTexture, const ChannelMapping &redMap=ChannelMapping(1.0f), const ChannelMapping &greenMap=ChannelMapping(0.0f, 1.0f), const ChannelMapping &blueMap=ChannelMapping(0.0f, 0.0f, 1.0f), const ChannelMapping &alphaMap=ChannelMapping(0.0f, 0.0f, 0.0f, 1.0f))
static void blurTexture(OdTrVisTexture *pTexture, OdUInt32 nSizeKernel=3, float fKernelMultiplier=1.0f)
static bool pow2ResampleDimensions(OdUInt32 &nResultWidth, OdUInt32 &nResultHeight, OdUInt32 nInWidth, OdUInt32 nInHeight, bool bRequirePow2, OdUInt32 nMaxSize)
static void sphereMapTexture(OdTrVisTexture *pTexture, const OdTrVisTexture *pRightTexture, const OdTrVisTexture *pLeftTexture, const OdTrVisTexture *pTopTexture, const OdTrVisTexture *pBottomTexture, const OdTrVisTexture *pFrontTexture, const OdTrVisTexture *pBackTexture, int antiAliasLevel=1, bool bSineCorrection=false)
static OdTrVisTexturePtr createTexture(OdTrVisTexture::Format fmt, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nAlign=4)
static OdTrVisTexturePtr sphereMap(const OdTrVisTexture *pRightTexture, const OdTrVisTexture *pLeftTexture, const OdTrVisTexture *pTopTexture, const OdTrVisTexture *pBottomTexture, const OdTrVisTexture *pFrontTexture, const OdTrVisTexture *pBackTexture, int antiAliasLevel=1, bool bSineCorrection=false)
static OdTrVisTexturePtr grayscale(const OdTrVisTexture *pTexture, OdUInt32 nApplyComponent=7)
static OdTrVisTexturePtr negate(const OdTrVisTexture *pTexture)
static OdTrVisTexturePtr convert(OdTrVisTexture::Format fmt, const OdTrVisTexture *pTexture, OdUInt32 nNewAlign=0, const OdTrVisTexture *pPalette=NULL)
static void cropTexture(OdTrVisTexture *pTexture, OdUInt32 nPosX, OdUInt32 nPosY, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nNewAlign=0)
static OdTrVisTexturePtr createPow2TextureFrom(OdTrVisTexture::Format fmt, bool bRequirePow2, OdUInt32 nMaxSize, OdUInt32 nAlign, OdTrVisTexture::Format bufferFmt, OdUInt32 bufferWidth, OdUInt32 bufferHeight, OdUInt32 bufferAlign, const void *buffer, Resampler method, const OdTrVisTexture *pPalette=NULL)
static OdTrVisTexturePtr resamplePow2(Resampler method, bool bRequirePow2, const OdTrVisTexture *pTexture, OdUInt32 nMaxSize)
static OdTrVisTexturePtr resample(Resampler method, OdUInt32 newWidth, OdUInt32 newHeight, const OdTrVisTexture *pTexture)
static void negateTexture(OdTrVisTexture *pTexture)
static OdTrVisTexturePtr clone(const OdTrVisTexture *pTexture)
static OdTrVisTexturePtr crop(const OdTrVisTexture *pTexture, OdUInt32 nPosX, OdUInt32 nPosY, OdUInt32 nWidth, OdUInt32 nHeight, OdUInt32 nNewAlign=0)
GLuint buffer
Definition gles2_ext.h:178
GLsizeiptr size
Definition gles2_ext.h:182
GLintptr offset
Definition gles2_ext.h:183
void prepareContext(const OdTrVisTexture *pSrc, const OdTrVisTexture *pDst)
ChannelMapping(float redMap=0.0f, float greenMap=0.0f, float blueMap=0.0, float alphaMap=0.0)
ChannelMapping & set(float redMap, float greenMap, float blueMap, float alphaMap)