00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #ifndef  _SO_TEXTURE_
00026 #define  _SO_TEXTURE_
00027 
00028 #include <Inventor/fields/SoSFVec4f.h>
00029 #include <Inventor/fields/SoSFEnum.h>
00030 #include <Inventor/fields/SoSFImage.h>
00031 #include <Inventor/fields/SoSFString.h>
00032 #include <Inventor/fields/SoSFBool.h>
00033 #include <Inventor/fields/SoSFFloat.h>
00034 #include <Inventor/fields/SoSFColor.h>
00035 #include <Inventor/nodes/SoNode.h>
00036 #include <Inventor/sys/SoGLType.h>
00037 #include <Inventor/elements/SoTextureImageElement.h>
00038 #include <SoDeprecationRules.h>
00039 
00040 class SoFieldSensor;
00041 class SoNodeSensor;
00042 class SbRasterImage;
00043 class SoGLTexture;
00044 
00045 #ifndef GL_COMBINE
00046 #define GL_COMBINE 0x8570
00047 #endif
00048 #ifndef GL_CLAMP_TO_BORDER
00049 #define GL_CLAMP_TO_BORDER 0x812D
00050 #endif
00051 #ifndef GL_CLAMP_TO_EDGE
00052 #define GL_CLAMP_TO_EDGE 0x812F
00053 #endif
00054 #ifndef GL_MIRRORED_REPEAT
00055 #define GL_MIRRORED_REPEAT 0x8370
00056 #endif
00057 
00058 
00060 
00061 
00062 
00063 
00064 
00066 
00133 class  SoTexture : public SoNode {
00134 
00135   SO_NODE_ABSTRACT_HEADER(SoTexture);
00136 
00137 public:
00141   enum InternalFormat {
00143     AUTO_INTERNAL_FORMAT,
00145     ALPHA_FORMAT,SoDEPRECATED ALPHA4, 
00149     ALPHA8,  
00151     ALPHA12,  
00153     ALPHA16,  
00155     LUMINANCE_FORMAT,  SoDEPRECATED LUMINANCE4,  
00159     LUMINANCE8,  
00161     LUMINANCE12,  
00163     LUMINANCE16,  
00165     LUMINANCE_ALPHA, 
00167     LUMINANCE4_ALPHA4,  
00169     LUMINANCE6_ALPHA2,  
00171     LUMINANCE8_ALPHA8,  
00173     LUMINANCE12_ALPHA4, 
00175     LUMINANCE12_ALPHA12, 
00177     LUMINANCE16_ALPHA16, 
00179     INTENSITY_FORMAT,  SoDEPRECATED INTENSITY4, 
00183     INTENSITY8, 
00185     INTENSITY12, 
00187     INTENSITY16,  
00189     R3_G3_B2,  
00191     RGB_FORMAT,  
00193     RGB4,  
00195     RGB5,  
00197     RGB8,  
00199     RGB10,  
00201     RGB12,  
00203     RGB16,  
00205     RGBA_FORMAT,  
00207     RGBA2,  
00209     RGBA4,  
00211     RGB5_ALPHA1,  
00213     RGBA8,  
00215     RGB10_ALPHA2,  
00217     RGBA12,  
00219     RGBA16, 
00221     RGBA_FLOAT32, 
00223     RGB_FLOAT32, 
00225     ALPHA_FLOAT32, 
00227     INTENSITY_FLOAT32, 
00229     LUMINANCE_FLOAT32, 
00231     LUMINANCE_ALPHA_FLOAT32, 
00233     RGBA_FLOAT16, 
00235     RGB_FLOAT16, 
00237     ALPHA_FLOAT16, 
00239     INTENSITY_FLOAT16, 
00241     LUMINANCE_FLOAT16, 
00243     LUMINANCE_ALPHA_FLOAT16, 
00245     COMPRESSED_ALPHA, 
00247     COMPRESSED_LUMINANCE,    
00249     COMPRESSED_LUMINANCE_ALPHA, 
00251     COMPRESSED_INTENSITY, 
00253     COMPRESSED_RGB, 
00255     COMPRESSED_RGBA,
00259     COMPRESSED_LUMINANCE_LATC1,
00263     COMPRESSED_SIGNED_LUMINANCE_LATC1,
00267     COMPRESSED_LUMINANCE_ALPHA_LATC2,
00271     COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2,
00275     COMPRESSED_RED_RGTC1,
00279     COMPRESSED_SIGNED_RED_RGTC1,
00283     COMPRESSED_RED_GREEN_RGTC2,
00287     COMPRESSED_SIGNED_RED_GREEN_RGTC2,
00291     DEPTH_COMPONENT16,
00295     DEPTH_COMPONENT24,
00299     DEPTH24_STENCIL8
00300   };
00301 
00303   enum Model {
00307     MODULATE = GL_MODULATE,
00308 
00318     DECAL = GL_DECAL,
00319 
00323     BLEND = GL_BLEND,
00324 
00330     REPLACE = GL_REPLACE,
00331 
00341     ADD = GL_ADD,
00342 
00353     COMBINE = GL_COMBINE
00354 
00355   };
00356 
00358   enum Wrap {
00362     REPEAT = GL_REPEAT,
00363 
00367     CLAMP = GL_CLAMP,
00368 
00379     CLAMP_TO_BORDER         = GL_CLAMP_TO_BORDER,
00380 
00391     CLAMP_TO_EDGE         = GL_CLAMP_TO_EDGE,
00392 
00403     MIRRORED_REPEAT         = GL_MIRRORED_REPEAT
00404 
00405   };
00406 
00412   enum Filter
00413   {
00415     AUTO  = 0,
00417     NEAREST = GL_NEAREST,
00419     LINEAR = GL_LINEAR,
00421     NEAREST_MIPMAP_NEAREST = GL_NEAREST_MIPMAP_NEAREST,
00423     NEAREST_MIPMAP_LINEAR = GL_NEAREST_MIPMAP_LINEAR,
00425     LINEAR_MIPMAP_NEAREST = GL_LINEAR_MIPMAP_NEAREST,
00427     LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR
00428   } ;
00429   
00433   enum HW_Feature {  
00437     HW_NPOT = 0,
00438 
00442     HW_FLOATFORMAT,
00443 
00447     HW_DEPTHFORMAT,
00448 
00452     HW_AUTOMIPMAP,
00453 
00457     HW_BORDER_CLAMP,
00458 
00462     HW_EDGE_CLAMP,
00463 
00467     HW_MIRRORED_REPEAT,
00468 
00472     HW_COMPRESSION_S3TC,
00473 
00477     HW_COMPRESSION_LATC,
00478 
00482    HW_COMPRESSION_RGTC,
00483 
00484 #ifndef HIDDEN_FROM_DOC 
00485     HW_LAST
00486 #endif
00487   };
00488 
00489 #if 1             SoDEPRECATED
00498   SoSFBool useAutoMipmap;
00499 
00500 #endif 
00511   SoSFEnum internalFormat;
00512 
00526   SoSFBool enableCompressedTexture;
00527 
00533   SoSFEnum wrapS;
00534 
00539   SoSFEnum model;
00540 
00544   SoSFColor blendColor;
00545 
00552   SoSFBool enableBorder;
00553 
00560   SoSFVec4f borderColor;
00561 
00573   SoSFFloat maxAnisotropy;
00574 
00591   SoSFEnum minFilter;
00592 
00612   SoSFEnum magFilter;
00613 
00615   
00616   
00617   enum FileType
00618   {
00620     UNKNOWN,
00622     RGB,
00624     SGI,
00626     TIFF,
00628     GIF,
00630     JPEG,
00632     BMP,
00634     PNG,
00636     JPEG2000,
00638     PGX,
00640     PNM,
00642     RAS,
00644     DDS,
00646     HDRI,
00648     NUM_FILETYPES
00649   };
00650 
00660   void setBitmapFileType(FileType in_type);
00661 
00665   FileType getBitmapFileType(void) { return (m_filetype); }
00666 
00674   static SbBool isSupported(HW_Feature feature);
00675 
00680   inline virtual void setOverride(const SbBool state)
00681   { override.setValue(state); }
00682 
00686   inline virtual SbBool isOverride() const
00687   { return override.getValue(); }
00688 
00689 private:
00690   virtual void        doAction(SoAction *action)=0;
00691   virtual void        GLRender(SoGLRenderAction *action)=0;
00692   virtual void        callback(SoCallbackAction *action);
00693 
00694 private:
00695   static void initClass();
00696   static void exitClass();
00697 
00698   virtual void notify(SoNotList *list);
00699 
00704   virtual bool affectsPath() const;
00705 
00706   SoSFBool override;
00707 
00708   static SoTexture::InternalFormat getInternalFormatFromDataType(SoState* state, SoSFImage::DataType dataType, int nc, SbBool enableCompressedTexture = FALSE, const SbVec4f& borderColor = SbVec4f(0.0f,0.0f,0.0f,1.0f) );
00709 
00710   
00711   
00712   
00713   static GLenum describeInternalFormat(SoState*state, SoTexture::InternalFormat texInternalFormat, int* nc = NULL, SbDataType* componentType = NULL);
00714 
00715   static bool isClampToEdgeAvailable(SoState* state);
00716 
00721   static FileType checkFileType( const SbString& filename );
00722 
00726   static SbRasterImage* readTexture( const SbString& filename, FileType filetype = UNKNOWN );
00727 
00733   static std::vector< SbRasterImage* > readTextures( const std::vector< SbString >& filenames, bool splitCubeMaps, FileType filetype = UNKNOWN );
00734 
00738   static bool isTextureObjectSupported( SoState* state );
00739 
00743   static bool isTextureFloatSupported( SoState* state );
00744 
00748   static bool isTextureCompressionSupported( SoState* state);
00749 
00753   static bool isTextureDepthSupported( SoState* state);
00754 
00758   static bool isPalettedTextureSupported( SoState* state);
00759 
00763   static bool isSharedTexturePaletteSupported( SoState* state);
00764 
00768   static bool isTextureRectangleSupported( SoState* state);
00769 
00773   static bool isTextureRGSupported( SoState* state);
00774 
00775 private:
00776   SoTexture();
00777 
00778   virtual ~SoTexture();
00779 
00780   int getReadStatus() { return m_readStatus; }
00781   void setReadStatus(int s) { m_readStatus = s; }
00782 
00783   SoFieldSensor *wrapSSensor;
00784   SoFieldSensor *maxAnisotropySensor;
00785 
00786   bool bFieldChanging;  
00787 
00795   static SbString getFileTypeSuffix( FileType type );
00796 
00797   FileType m_filetype;
00798   SbBool m_userfileType;
00799 
00801   virtual GLenum getGLInternalFormat(SoSFImage& image, float quality = 1.0);
00802   
00803 
00804   static SbVec4i32 selectGCParams(InternalFormat intFmt);  
00805 
00806   static void convertHDRI_RGBE_TO_FLOAT32(SbRasterImage* rasterIn, float* floatOut, float exposureFactor);
00807   static void convertHDRI_FLOAT32_TO_UCHAR(float* fcol, unsigned char* outBuff, int width, int height);
00808   static void convertHDRI_FLOAT32_TO_UCHAR( SoSFImage* );
00809 
00815   virtual bool isTextureConfigurationValid(SoState* state, const SoTextureImageElement::SoTexImageData& config);
00816 
00818   SoGLTexture* m_texture;
00819 
00820 private:
00821 
00822   static SbRasterImage* readTextureDataFromFile( const SbString& filename, FileType filetype );
00823 
00824   static std::vector< SbRasterImage* > splitRasterImage( SbRasterImage* sourceImage );
00825 
00826   static void readImageSection( unsigned char* input, int inputWidth, 
00827                       int xOffset, int yOffset, int width, int height, 
00828                       int elementSize, unsigned char* output, bool invertAndMirror);
00829 
00830   int m_readStatus;
00831 
00832   static SbBool m_featuresInitialized;
00833   static SbBool m_features[HW_LAST];
00834   static bool s_ivNoTextureObject;
00835   static int s_texture_object_extensionID;
00836   static int s_clamp_to_edge_EXT_extensionID;
00837   static int s_clamp_to_edge_SGIS_extensionID;
00838   static int s_texture_float_extensionID;
00839   static int s_texture_compression_extensionID;
00840   static int s_detph_texture_ARB_extensionID;
00841   static int s_paletted_texture_extensionID;
00842   static int s_shared_texture_palette_extensionID;
00843   static int s_texture_rectangle_extensionID;
00844   static int s_texture_rg_extensionID;
00845 
00846 };
00847 
00848 #endif 
00849 
00850