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 mipLevel = 0;
00155 imgFormat = 0;
00156 imgDataType = SbDataType::UNKNOWN;
00157 imgData = NULL;
00158 copyData = true;
00159 }
00160
00162 size_t subImageSize() const;
00163 };
00164
00165 class SamplerConfiguration
00166 {
00167 RENDERER_RESOURCE(SamplerConfiguration);
00168 public:
00169 SbVec4f borderColor;
00170 float maxAnisotropy;
00171
00172 uint32_t sAddressMode;
00173 uint32_t tAddressMode;
00174 uint32_t rAddressMode;
00175
00176 uint32_t model;
00177
00178 uint8_t minFilter;
00179 uint8_t magFilter;
00180 uint8_t mipmapFilter;
00181
00183 static uint8_t getAutoMagFilter(float quality);
00184 static void getAutoMinFilter(uint8_t& minFilter, uint8_t& mipmapFilter, float quality);
00185
00186 bool isUsingMipmaps() const;
00187 bool operator== (const SamplerConfiguration& sc) const;
00188
00189 SamplerConfiguration();
00190 ~SamplerConfiguration() { destroyRendererResource(); }
00191 };
00192
00193
00194 struct SoTexImageData
00195 {
00196 SoTexture* texture;
00197 SamplerConfiguration samplerConfiguration;
00198
00199
00200 SoTexImageData();
00201
00202 uint8_t texType;
00203 SoGLTexture* gltexture;
00204 SbVec3i32 size;
00205 int numComponents;
00206 const void* buffer[MAX_TEXTURE_NBR];
00207 SoBufferObject* bufferObjects[MAX_TEXTURE_NBR];
00208 SbColor blendColor;
00209 bool enableBorder;
00210
00211 uint8_t imgFormat;
00212 SoSFImage::DataType dataType;
00213 GLint GLInternalFormat;
00214 SoRenderToTextureProperty* renderToTextureProperty;
00215 bool renderToTexturePropertyFirstPass;
00216
00217
00218 int hasTransparency;
00219 bool isCompressed;
00220 int numCompressedMipmaps;
00221 float quality;
00222 int currentTexture;
00223
00224
00225 struct SubTexture
00226 {
00227 int textureName;
00228 SbVec3i32 size;
00229 SbVec3i32 offset;
00230 const void* bytes;
00231 };
00232 std::vector<SubTexture> subtextures;
00233
00234
00235 bool enabled;
00236
00237 int32_t wrapS;
00238 int32_t wrapR;
00239 int32_t wrapT;
00240 int32_t model;
00241 float maxAnisotropy;
00242 SbVec4f borderColor;
00243 uint8_t texFormat;
00244
00245 };
00246
00247
00248 SoTexImageData& getTexImageData(const int unit) const;
00249
00250 private:
00251 SoTextureImageElementBase::Target m_target;
00252
00253 SbBool hasTransparency(SoState *state, int unit) const;
00254 void getElt(SoState *state, int &_minFilter,int &_magFilter, float &_maxAnisotropy, int unit) const;
00255
00256 const void * getElt(SoState *state, SbVec2i32 &_size,
00257 int &_numComponents, SoSFImage::DataType &_dataType,
00258 GLint &_GLInternalFormat, int &_wrapS, int &_wrapT,
00259 int &_model, SbColor &_blendColor, int unit, int currentTexture = -1) const;
00260
00261 virtual void setElt(const SbVec2i32 &s, int nc,
00262 const void *buffer, SoBufferObject* bufferObject, SoSFImage::DataType dataType,
00263 GLint GLInternalFormat, SoRenderToTextureProperty* renderToTex,
00264 int wrapS, int wrapT, int wrapR, int model,
00265 const SbColor &blendColor, float _maxAnisotropy,
00266 SbBool _enableBorder, const SbVec4f &_borderColor,
00267 SbBool isCompressed, int numCompressedMipmaps,
00268 int hasTransparency = -1 ,
00269 int unit=0, int currentTexture=-1);
00270
00271 virtual void setElt(SoState *state, SoNode *node, const SoTexImageData& config);
00272
00273 virtual void setSubElt(const SbVec2i32 &subSize,
00274 int xoffset, int yoffset,
00275 const void *buffer, int texname,
00276 int unit=0);
00277
00278 virtual void setFilterElt(int _minFilter, int _magFilter, int currUnit);
00279
00280
00281 virtual ~SoTextureImageElementBase();
00282
00283
00284
00285 typedef std::vector<SoTexImageData> SoTexImageDataList;
00286 mutable SoTexImageDataList m_texImageDataList;
00287
00288 friend class SoVRMLAppearance;
00289 };
00290
00291 #ifdef _WIN32
00292 #pragma warning( pop )
00293 #endif
00294
00295 #endif
00296
00297
00298