00001 #ifndef __EDGEBLEEDING_H 00002 #define __EDGEBLEEDING_H 00003 00004 #include <math.h> 00005 00006 // force inline functions to be inline to achieve max speed 00007 #ifndef _DEBUG 00008 #ifdef _MSC_VER 00009 #define inline __forceinline 00010 #endif 00011 #endif 00012 00013 #if defined(JAMBUILD) 00014 #include <Mudbox/mudbox.h> 00015 #include <Mudbox/SSE.h> 00016 #else 00017 #include "../../include/Mudbox/mudbox.h" 00018 #include "../../include/Mudbox/SSE.h" 00019 #endif 00020 00021 #include <QtCore/QCoreApplication> 00022 00023 #ifndef COMPILING_EDGEBLEEDING_DLL 00024 #define EBDLL MUDBOX_DLLIMPORT 00025 #else 00026 #define EBDLL MUDBOX_DLLEXPORT 00027 #endif 00028 00029 #define MAX_TEXTURE_COUNT 4 00030 class TextureCache 00031 { 00032 public: 00033 void Request( mudbox::Texture *pTexture ) 00034 { 00035 for( int i=0; i<cache.size(); i++ ) 00036 if( cache.at(i) == pTexture ) 00037 return; 00038 00039 if( cache.size() >= MAX_TEXTURE_COUNT ) 00040 { 00041 mudbox::Texture *pT = cache.takeFirst(); 00042 pT->AddDirtyTile( mudbox::ImgTile (0, 0, pT->Width(), pT->Height()) ); 00043 pT->SetLocation( mudbox::TexturePool::locationCPU ); 00044 }; 00045 00046 cache.append( pTexture ); 00047 if( pTexture->Location() != mudbox::TexturePool::locationGPU ) 00048 pTexture->SetLocation( mudbox::TexturePool::locationGPU ); 00049 }; 00050 00051 void Clear() 00052 { 00053 // for( int i=0; i<cache.size(); i++ ) 00054 // cache.at(i)->SetLocation( mudbox::TexturePool::locationCPU ); 00055 00056 cache.clear(); 00057 }; 00058 00059 private: 00060 QList<mudbox::Texture *> cache; 00061 }; 00062 00063 class EBDLL EdgeBleeding : public mudbox::Node 00064 { 00065 public: 00066 00067 Q_DECLARE_TR_FUNCTIONS(EdgeBleeding); 00068 DECLARE_CLASS; 00069 00070 EdgeBleeding( void ); 00071 static void Initializer(); 00072 00073 static void FillBleedingAreas( void ) { FillBleedingAreas( false ); } 00074 // the bBlend parameter when set to true will ensure that these functions do not 00075 // write transparent pixels -- this fixes a problem with seams opening 00076 // up on certain triangle edges. 00077 static void FillBleedingAreas( bool bBlend ); 00078 static void FillBleedingAreas( mudbox::Mesh *pMesh, mudbox::TexturePool *pTexture, bool bBlend = false ); 00079 static void FillBleedingAreasForTriangle(mudbox::Mesh *pMesh, mudbox::TexturePool *pTP, bool bBlend = false); 00080 00081 private: 00082 inline static float AdjustUV( float value ) 00083 { 00084 float d = 0.0f; 00085 return modff(value, &d); 00086 //while ( value > 1.0f ) 00087 // value -= 1.0f; 00088 //while ( value < 0.0f ) 00089 // value += 1.0f; 00090 //return value; 00091 }; 00092 00093 static TextureCache s_cTextureCache; 00094 }; 00095 00096 #endif