[162] | 1 | #include "myTerrainTechnique.h" |
---|
| 2 | #include <osgTerrain/TerrainTile> |
---|
| 3 | |
---|
[163] | 4 | using namespace osgTerrain; |
---|
| 5 | |
---|
[168] | 6 | myTerrainTechnique::myTerrainTechnique(void) : osgTerrain::GeometryTechnique() |
---|
[162] | 7 | { |
---|
[170] | 8 | //OSG_ALWAYS<<className()<<"Constructed by Constructor"<<std::endl; |
---|
[168] | 9 | |
---|
[162] | 10 | } |
---|
| 11 | |
---|
[165] | 12 | myTerrainTechnique::myTerrainTechnique(const GeometryTechnique& TerrainTechnique,const osg::CopyOp& copyop): |
---|
| 13 | osgTerrain::GeometryTechnique(TerrainTechnique,copyop) |
---|
[163] | 14 | { |
---|
[165] | 15 | //OSG_ALWAYS<<className()<<"Constructed by Copy-Constructor"<<std::endl; |
---|
[163] | 16 | } |
---|
| 17 | |
---|
[162] | 18 | myTerrainTechnique::~myTerrainTechnique(void) |
---|
| 19 | { |
---|
| 20 | } |
---|
| 21 | |
---|
[169] | 22 | void myTerrainTechnique::init(int dirtyMask, bool assumeMultiThreaded) |
---|
[162] | 23 | { |
---|
[169] | 24 | /* The heightfield es extracted from the tile in the techniques init function. technique->init() calls technique->generateGeometry() which creates the drawable according to the heightfield. |
---|
| 25 | To modify the height, the heightfield must be modified prior to the original techniques init() function. |
---|
| 26 | |
---|
| 27 | To modiy the drawable shape (e.g. Cutting wholes in the area), the function technique->generateGeometry() must be modified. |
---|
| 28 | */ |
---|
| 29 | |
---|
[168] | 30 | HeightFieldLayer* hfl = dynamic_cast<HeightFieldLayer*>( getTerrainTile()->getElevationLayer() ); |
---|
| 31 | osg::HeightField* h = hfl->getHeightField(); |
---|
| 32 | h->setHeight( 0,0, 1000); |
---|
[162] | 33 | |
---|
[171] | 34 | ImageLayer* il = dynamic_cast<ImageLayer*>( getTerrainTile()->getColorLayer(0) ); |
---|
| 35 | osg::Image* img = il->getImage(); |
---|
[172] | 36 | //img->setInternalTextureFormat( GL_RGBA ); |
---|
[171] | 37 | |
---|
[172] | 38 | if( img->getPixelFormat() == GL_RGBA ) |
---|
| 39 | OSG_ALWAYS << "Format ist RGBA" << std::endl; |
---|
| 40 | if( img->getPixelFormat() == GL_RGB ) |
---|
| 41 | OSG_ALWAYS << "Format ist RGB" << std::endl; |
---|
| 42 | if( img->getPixelFormat() == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ) |
---|
| 43 | OSG_ALWAYS << "Format ist GL_COMPRESSED_RGB_S3TC_DXT1_EXT" << std::endl; |
---|
[171] | 44 | |
---|
[172] | 45 | |
---|
| 46 | |
---|
| 47 | //osg::ref_ptr<osg::Image> img2 = new osg::Image(); |
---|
| 48 | //img2->setInternalTextureFormat( GL_RGBA ); |
---|
| 49 | //OSG_ALWAYS << "test: " << std::hex << img->getPixelFormat() << std::endl; |
---|
| 50 | |
---|
[169] | 51 | GeometryTechnique::init(dirtyMask, assumeMultiThreaded); |
---|
[175] | 52 | |
---|
| 53 | getTerrainTile()->getLocator()-> |
---|
| 54 | |
---|
[172] | 55 | } |
---|
| 56 | |
---|
| 57 | void myTerrainTechnique::ConvertImage(osg::ref_ptr<osg::Image> a_toImage, osg::ref_ptr<osg::Image> a_fromImage, GLenum a_pixelFormat, GLenum a_dataType) |
---|
| 58 | { |
---|
| 59 | GLenum dataType = a_fromImage -> getDataType(); |
---|
| 60 | |
---|
| 61 | //setInternalTextureFormat( 0); // tmp |
---|
| 62 | a_toImage -> allocateImage( |
---|
| 63 | a_fromImage -> s(), |
---|
| 64 | a_fromImage -> t(), |
---|
| 65 | a_fromImage -> r(), |
---|
| 66 | a_pixelFormat, a_dataType, a_fromImage -> getPacking()); |
---|
| 67 | |
---|
| 68 | //// Wenn Quelle und Ziel RGBA sind |
---|
| 69 | //if( a_toImage -> getPixelFormat() == GL_RGBA && a_fromImage -> getPixelFormat() == GL_RGBA) |
---|
| 70 | //{ |
---|
| 71 | // unsigned nr = a_fromImage->t(); |
---|
| 72 | // unsigned nc = a_fromImage->s(); |
---|
| 73 | // for (unsigned r = 0; r < nr; ++r) |
---|
| 74 | // { |
---|
| 75 | // for (unsigned c = 0; c < nc; ++c) |
---|
| 76 | // { |
---|
| 77 | // unsigned char * fromPixelData = a_fromImage -> data(c, nr-r-1); |
---|
| 78 | // unsigned char * toPixelData = a_toImage -> data(c, nr-r-1); |
---|
| 79 | |
---|
| 80 | // // Copy r, g, b, a. |
---|
| 81 | // for( int component = 0; component < 4; ++ component) |
---|
| 82 | // { |
---|
| 83 | // My_OSG_Library::OSG_PixelComponent pixelComponent( a_fromImage -> getDataType(), fromPixelData, component /* r, g, b, a */); |
---|
| 84 | // pixelComponent.Store( a_toImage -> getDataType(), toPixelData, component); |
---|
| 85 | // } |
---|
| 86 | // } |
---|
| 87 | // } |
---|
| 88 | //} |
---|
| 89 | //else |
---|
| 90 | // Wenn Quelle RGB ist und Ziel RGBA |
---|
| 91 | //if( a_toImage -> getPixelFormat() == GL_RGBA && a_fromImage -> getPixelFormat() == GL_RGB) |
---|
| 92 | //{ |
---|
| 93 | // unsigned nr = a_fromImage -> t(); |
---|
| 94 | // unsigned nc = a_fromImage -> s(); |
---|
| 95 | // for (unsigned r = 0; r < nr; ++r) |
---|
| 96 | // { |
---|
| 97 | // for (unsigned c = 0; c < nc; ++c) |
---|
| 98 | // { |
---|
| 99 | // unsigned char * fromPixelData = a_fromImage -> data(c, nr-r-1); |
---|
| 100 | // unsigned char * toPixelData = a_toImage -> data(c, nr-r-1); |
---|
| 101 | |
---|
| 102 | // // Copy r, g, b. |
---|
| 103 | // for( int component = 0; component < 3; ++ component) |
---|
| 104 | // { |
---|
| 105 | // My_OSG_Library::OSG_PixelComponent pixelComponent( a_fromImage -> getDataType(), fromPixelData, component /* r, g, b */); |
---|
| 106 | // pixelComponent.Store( a_toImage -> getDataType(), toPixelData, component); |
---|
| 107 | // } |
---|
| 108 | |
---|
| 109 | // // Initialize alpha to opaque. |
---|
| 110 | // My_OSG_Library::OSG_PixelComponent::One().Store( a_toImage -> getDataType(), toPixelData, 3); |
---|
| 111 | // } |
---|
| 112 | // } |
---|
| 113 | //} |
---|
[166] | 114 | } |
---|