00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _SO_TEXTURE_IMAGE_ELEMENT_BASE
00023 #define _SO_TEXTURE_IMAGE_ELEMENT_BASE
00024
00025 #if defined(_WIN32)
00026 #pragma warning( push )
00027 #pragma warning( disable: 4251 ) // 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
00028 #endif
00029
00030 #define MAX_TEXTURE_NBR 6
00031
00032
00033
00034 #include <Inventor/SbColor.h>
00035 #include <Inventor/elements/SoReplacedTextureElement.h>
00036 #include <Inventor/fields/SoSFImage.h>
00037 #include <Inventor/SbPImpl.h>
00038 #include <Inventor/renderer/RendererResourceMacro.h>
00039
00040 #ifdef _WIN32
00041 #pragma warning(push)
00042 #pragma warning(disable:4251)
00043 #endif
00044
00045 #ifndef GL_TEXTURE_CUBE_MAP
00046 #define GL_TEXTURE_CUBE_MAP 0x8513
00047 #endif
00048 #ifndef GL_TEXTURE_2D
00049 #define GL_TEXTURE_2D 0x0DE1
00050 #endif
00051
00052 #ifdef _WIN32
00053 #pragma warning( push )
00054 #pragma warning(disable:4251)
00055 #endif
00056
00057
00058 class SoRenderToTextureProperty;
00059 class SoBufferObject;
00060 class SoGLTexture;
00061 class SoTexture;
00062
00063 SO_PIMPL_BASE_PUBLIC_DECLARATION(SoTextureImageElementBase)
00064
00065
00077 SoEXTENDER_Documented class SoTextureImageElementBase : public SoReplacedTextureElement
00078 {
00079 SO_PIMPL_BASE_PUBLIC_HEADER(SoTextureImageElementBase);
00080
00081 SO_ELEMENT_ABSTRACT_HEADER(SoTextureImageElementBase);
00082
00083 public:
00084
00086 enum Target {
00088 TEXTURE2D = GL_TEXTURE_2D,
00090 TEXTURECUBEMAP = GL_TEXTURE_CUBE_MAP
00091 };
00092
00096 virtual void print(FILE *fp) const;
00097
00101 virtual void push(SoState *state) ;
00102
00103 private:
00105 virtual void commonInit();
00106
00108 virtual void init(SoState *state);
00109
00110 private:
00111
00112 static void initClass();
00113 static void exitClass();
00114
00115 SoTextureImageElementBase::Target getTargetTexture(){return m_target;}
00116
00117 struct TextureDataConfiguration
00118 {
00119 uint32_t xOffset;
00120 uint32_t yOffset;
00121 uint32_t zOffset;
00122
00123 uint32_t width;
00124 uint32_t height;
00125 uint32_t depth;
00126 uint8_t face;
00127
00128 uint8_t imgFormat;
00129 SbDataType imgDataType;
00130
00131 uint32_t rowLength;
00132 uint32_t imageHeight;
00133
00134 int mipLevel;
00135 void* imgData;
00136
00142 bool copyData;
00143
00144 TextureDataConfiguration()
00145 {
00146 xOffset = 0;
00147 yOffset = 0;
00148 zOffset = 0;
00149 width = 0;
00150 height = 0;
00151 depth = 0;
00152 face = 0;
00153 rowLength = 0;
00154 imageHeight = 0;
00155 mipLevel = 0;
00156 imgFormat = 0;
00157 imgDataType = SbDataType::UNKNOWN;
00158 imgData = NULL;
00159 copyData = true;
00160 }
00161
00163 size_t subImageSize() const;
00164 };
00165
00166 class SamplerConfiguration : public SoRefCounter
00167 {
00168 RENDERER_RESOURCE(SamplerConfiguration);
00169 public:
00170 SbVec4f borderColor;
00171 float maxAnisotropy;
00172
00173 uint32_t sAddressMode;
00174 uint32_t tAddressMode;
00175 uint32_t rAddressMode;
00176
00177 uint32_t model;
00178
00179 uint8_t minFilter;
00180 uint8_t magFilter;
00181 uint8_t mipmapFilter;
00182
00184 static uint8_t getAutoMagFilter(float quality);
00185 static void getAutoMinFilter(uint8_t& minFilter, uint8_t& mipmapFilter, float quality);
00186
00187 bool isUsingMipmaps() const;
00188 bool operator== (const SamplerConfiguration& sc) const;
00189 bool operator!=( const SamplerConfiguration& sc ) const
00190 {
00191 return !operator==( sc );
00192 }
00193
00194 SamplerConfiguration();
00195 ~SamplerConfiguration() { destroyRendererResource(); }
00196
00197 private:
00198 SamplerConfiguration( const SamplerConfiguration& )
00199 : SoRefCounter()
00200 {}
00201 };
00202
00203
00204 struct SoTexImageData
00205 {
00206 SoTexture* texture;
00207 SoRef<SamplerConfiguration> samplerConfiguration;
00208
00209
00210 SoTexImageData();
00211
00212 uint8_t texType;
00213 SoGLTexture* gltexture;
00214 SbVec3i32 size;
00215 int numComponents;
00216 const void* buffer[MAX_TEXTURE_NBR];
00217 SoBufferObject* bufferObjects[MAX_TEXTURE_NBR];
00218 SbColor blendColor;
00219 bool enableBorder;
00220
00221 uint8_t imgFormat;
00222 SoSFImage::DataType dataType;
00223 GLint GLInternalFormat;
00224 SoRenderToTextureProperty* renderToTextureProperty;
00225 bool renderToTexturePropertyFirstPass;
00226
00227
00228 int hasTransparency;
00229 bool isCompressed;
00230 int numCompressedMipmaps;
00231 float quality;
00232 int currentTexture;
00233
00234
00235 struct SubTexture
00236 {
00237 int textureName;
00238 SbVec3i32 size;
00239 SbVec3i32 offset;
00240 const void* bytes;
00241 };
00242 std::vector<SubTexture> subtextures;
00243
00244
00245 bool enabled;
00246
00247 int32_t wrapS;
00248 int32_t wrapR;
00249 int32_t wrapT;
00250 int32_t model;
00251 float maxAnisotropy;
00252 SbVec4f borderColor;
00253 uint8_t texFormat;
00254
00255 };
00256
00257
00258 SoTexImageData& getTexImageData(const int unit) const;
00259
00260 private:
00261 SoTextureImageElementBase::Target m_target;
00262
00263 SbBool hasTransparency(SoState *state, int unit) const;
00264 void getElt(SoState *state, int &_minFilter,int &_magFilter, float &_maxAnisotropy, int unit) const;
00265
00266 const void * getElt(SoState *state, SbVec2i32 &_size,
00267 int &_numComponents, SoSFImage::DataType &_dataType,
00268 GLint &_GLInternalFormat, int &_wrapS, int &_wrapT,
00269 int &_model, SbColor &_blendColor, int unit, int currentTexture = -1) const;
00270
00271 virtual void setElt(const SbVec2i32 &s, int nc,
00272 const void *buffer, SoBufferObject* bufferObject, SoSFImage::DataType dataType,
00273 GLint GLInternalFormat, SoRenderToTextureProperty* renderToTex,
00274 int wrapS, int wrapT, int wrapR, int model,
00275 const SbColor &blendColor, float _maxAnisotropy,
00276 SbBool _enableBorder, const SbVec4f &_borderColor,
00277 SbBool isCompressed, int numCompressedMipmaps,
00278 int hasTransparency = -1 ,
00279 int unit=0, int currentTexture=-1);
00280
00281 virtual void setElt(SoState *state, SoNode *node, const SoTexImageData& config);
00282
00283 virtual void setSubElt(const SbVec2i32 &subSize,
00284 int xoffset, int yoffset,
00285 const void *buffer, int texname,
00286 int unit=0);
00287
00288 virtual void setFilterElt(int _minFilter, int _magFilter, int currUnit);
00289
00290
00291 virtual ~SoTextureImageElementBase();
00292
00293
00294
00295 typedef std::vector<SoTexImageData> SoTexImageDataList;
00296 mutable SoTexImageDataList m_texImageDataList;
00297
00298 friend class SoVRMLAppearance;
00299 };
00300
00301 #ifdef _WIN32
00302 #pragma warning( pop )
00303 #endif
00304
00305 #endif
00306
00307
00308