#include "myTerrainTechnique.h" #include using namespace osgTerrain; myTerrainTechnique::myTerrainTechnique(void) : osgTerrain::GeometryTechnique() { //OSG_ALWAYS<init() calls technique->generateGeometry() which creates the drawable according to the heightfield. To modify the height, the heightfield must be modified prior to the original techniques init() function. To modiy the drawable shape (e.g. Cutting wholes in the area), the function technique->generateGeometry() must be modified. */ HeightFieldLayer* hfl = dynamic_cast( getTerrainTile()->getElevationLayer() ); osg::HeightField* h = hfl->getHeightField(); h->setHeight( 0,0, 1000); ImageLayer* il = dynamic_cast( getTerrainTile()->getColorLayer(0) ); osg::Image* img = il->getImage(); //img->setInternalTextureFormat( GL_RGBA ); /* if( img->getPixelFormat() == GL_RGBA ) OSG_ALWAYS << "Format ist RGBA" << std::endl; if( img->getPixelFormat() == GL_RGB ) OSG_ALWAYS << "Format ist RGB" << std::endl; if( img->getPixelFormat() == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ) OSG_ALWAYS << "Format ist GL_COMPRESSED_RGB_S3TC_DXT1_EXT" << std::endl;*/ //osg::ref_ptr img2 = new osg::Image(); //img2->setInternalTextureFormat( GL_RGBA ); //OSG_ALWAYS << "test: " << std::hex << img->getPixelFormat() << std::endl; GeometryTechnique::init(dirtyMask, assumeMultiThreaded); //getTerrainTile()->getLocator()-> OpenThreads::Thread::microSleep( 50000 ); } void myTerrainTechnique::ConvertImage(osg::ref_ptr a_toImage, osg::ref_ptr a_fromImage, GLenum a_pixelFormat, GLenum a_dataType) { GLenum dataType = a_fromImage -> getDataType(); //setInternalTextureFormat( 0); // tmp a_toImage -> allocateImage( a_fromImage -> s(), a_fromImage -> t(), a_fromImage -> r(), a_pixelFormat, a_dataType, a_fromImage -> getPacking()); //// Wenn Quelle und Ziel RGBA sind //if( a_toImage -> getPixelFormat() == GL_RGBA && a_fromImage -> getPixelFormat() == GL_RGBA) //{ // unsigned nr = a_fromImage->t(); // unsigned nc = a_fromImage->s(); // for (unsigned r = 0; r < nr; ++r) // { // for (unsigned c = 0; c < nc; ++c) // { // unsigned char * fromPixelData = a_fromImage -> data(c, nr-r-1); // unsigned char * toPixelData = a_toImage -> data(c, nr-r-1); // // Copy r, g, b, a. // for( int component = 0; component < 4; ++ component) // { // My_OSG_Library::OSG_PixelComponent pixelComponent( a_fromImage -> getDataType(), fromPixelData, component /* r, g, b, a */); // pixelComponent.Store( a_toImage -> getDataType(), toPixelData, component); // } // } // } //} //else // Wenn Quelle RGB ist und Ziel RGBA //if( a_toImage -> getPixelFormat() == GL_RGBA && a_fromImage -> getPixelFormat() == GL_RGB) //{ // unsigned nr = a_fromImage -> t(); // unsigned nc = a_fromImage -> s(); // for (unsigned r = 0; r < nr; ++r) // { // for (unsigned c = 0; c < nc; ++c) // { // unsigned char * fromPixelData = a_fromImage -> data(c, nr-r-1); // unsigned char * toPixelData = a_toImage -> data(c, nr-r-1); // // Copy r, g, b. // for( int component = 0; component < 3; ++ component) // { // My_OSG_Library::OSG_PixelComponent pixelComponent( a_fromImage -> getDataType(), fromPixelData, component /* r, g, b */); // pixelComponent.Store( a_toImage -> getDataType(), toPixelData, component); // } // // Initialize alpha to opaque. // My_OSG_Library::OSG_PixelComponent::One().Store( a_toImage -> getDataType(), toPixelData, 3); // } // } //} }