[346] | 1 | /* osgVisual test. distortionNG, experimental. |
---|
| 2 | * |
---|
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 4 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 5 | * in the Software without restriction, including without limitation the rights |
---|
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 7 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 8 | * furnished to do so, subject to the following conditions: |
---|
| 9 | * |
---|
| 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 16 | * THE SOFTWARE. |
---|
| 17 | */ |
---|
| 18 | |
---|
[310] | 19 | #include "extViewer.h" |
---|
[329] | 20 | #include "distortionNG.h" |
---|
[310] | 21 | |
---|
[329] | 22 | #include <osg/PolygonOffset> |
---|
[334] | 23 | #include <osg/Texture2D> |
---|
| 24 | #include <osg/TextureRectangle> |
---|
| 25 | #include <osg/TexMat> |
---|
| 26 | #include <osg/ComputeBoundsVisitor> |
---|
| 27 | #include <osg/Vec2> |
---|
[313] | 28 | |
---|
[334] | 29 | #include <osgDB/ReadFile> |
---|
| 30 | #include <osgDB/FileUtils> |
---|
[313] | 31 | |
---|
| 32 | #include <osgUtil/SmoothingVisitor> |
---|
| 33 | |
---|
[346] | 34 | #include "DistortionManipulator.h" |
---|
| 35 | |
---|
[311] | 36 | extViewer::extViewer() : Viewer() |
---|
[310] | 37 | { |
---|
| 38 | } |
---|
| 39 | |
---|
[311] | 40 | extViewer::extViewer(osg::ArgumentParser& arguments) : Viewer(arguments) |
---|
[310] | 41 | { |
---|
[346] | 42 | // Add help for command-line options here |
---|
[342] | 43 | arguments.getApplicationUsage()->addCommandLineOption("--distort","load distortion file and set up geometrical distortion for viewer. This includes blending"); |
---|
| 44 | arguments.getApplicationUsage()->addCommandLineOption("--blend","Set up viewer vor simple blending CullDrawThreadPerContext threading model for viewer."); |
---|
[345] | 45 | |
---|
| 46 | osgDB::Registry::instance()->addFileExtensionAlias("dist", "osgt"); |
---|
[310] | 47 | } |
---|
[311] | 48 | |
---|
| 49 | extViewer::extViewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop) : Viewer(viewer, copyop) |
---|
| 50 | { |
---|
| 51 | |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | extViewer::~extViewer() |
---|
| 55 | { |
---|
| 56 | |
---|
| 57 | } |
---|
| 58 | |
---|
[342] | 59 | //static osg::Texture2D* loadTexture( const std::string& fileName ) |
---|
| 60 | //{ |
---|
| 61 | // std::string foundFileName = osgDB::findDataFile(fileName); |
---|
| 62 | // if (foundFileName.length() != 0 ) |
---|
| 63 | // { |
---|
| 64 | // // load distortion map texture file |
---|
| 65 | // osg::Image* image = osgDB::readImageFile(foundFileName); |
---|
| 66 | // if (image) |
---|
| 67 | // { |
---|
| 68 | // osg::Texture2D* texture = new osg::Texture2D; |
---|
| 69 | // texture->setImage(image); |
---|
| 70 | // texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
---|
| 71 | // texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); |
---|
| 72 | // texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); |
---|
| 73 | // texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); |
---|
| 74 | // return texture; |
---|
| 75 | // } |
---|
| 76 | // } |
---|
| 77 | // |
---|
| 78 | // OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl; |
---|
| 79 | // |
---|
| 80 | // return NULL; |
---|
| 81 | //} |
---|
[336] | 82 | |
---|
[342] | 83 | //static osg::TextureRectangle* loadTextureRect( const std::string& fileName ) |
---|
| 84 | //{ |
---|
| 85 | // std::string foundFileName = osgDB::findDataFile(fileName); |
---|
| 86 | // if (foundFileName.length() != 0 ) |
---|
| 87 | // { |
---|
| 88 | // // load distortion map texture file |
---|
| 89 | // osg::Image* image = osgDB::readImageFile(foundFileName); |
---|
| 90 | // if (image) |
---|
| 91 | // { |
---|
| 92 | // osg::TextureRectangle* texture = new osg::TextureRectangle; |
---|
| 93 | // texture->setImage(image); |
---|
| 94 | // texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); |
---|
| 95 | // texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); |
---|
| 96 | // texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE); |
---|
| 97 | // texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE); |
---|
| 98 | // return texture; |
---|
| 99 | // } |
---|
| 100 | // } |
---|
| 101 | // |
---|
| 102 | // OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl; |
---|
| 103 | // |
---|
| 104 | // return NULL; |
---|
| 105 | //} |
---|
[336] | 106 | |
---|
[332] | 107 | static osg::Geometry* createMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, unsigned int columns, unsigned int rows, osg::Image* intensityMap, bool applyIntensityMapAsColours, const osg::Matrix& projectorMatrix) |
---|
| 108 | { |
---|
[331] | 109 | // Create Quad to render on |
---|
| 110 | osg::ref_ptr<osg::Geometry> geom = new osg::Geometry; |
---|
| 111 | |
---|
| 112 | geom->setUseDisplayList( false ); |
---|
| 113 | |
---|
| 114 | osg::Vec3 xAxis(widthVector); |
---|
| 115 | float width = widthVector.length(); |
---|
| 116 | xAxis /= width; |
---|
| 117 | |
---|
| 118 | osg::Vec3 yAxis(heightVector); |
---|
| 119 | float height = heightVector.length(); |
---|
| 120 | yAxis /= height; |
---|
| 121 | |
---|
| 122 | osg::Vec3 dx = xAxis*(width/((float)(columns-1))); |
---|
| 123 | osg::Vec3 dy = yAxis*(height/((float)(rows-1))); |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | // Create vertices and coordinates |
---|
| 127 | osg::Vec3Array* vertices = new osg::Vec3Array; |
---|
| 128 | osg::Vec2Array* texcoords0 = new osg::Vec2Array; |
---|
| 129 | osg::Vec2Array* texcoords1 = intensityMap==0 ? new osg::Vec2Array : 0; |
---|
| 130 | osg::Vec4Array* colors = new osg::Vec4Array; |
---|
| 131 | |
---|
| 132 | geom->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); |
---|
| 133 | |
---|
| 134 | for ( unsigned int row=0; row<rows; row++ ) |
---|
| 135 | { |
---|
| 136 | for ( unsigned int col=0; col<columns; col++ ) |
---|
| 137 | { |
---|
| 138 | // Create coordinates of the mesh node (geometry). |
---|
| 139 | vertices->push_back( origin+dy*row+dx*col ); |
---|
| 140 | |
---|
| 141 | // Create tex coordinates |
---|
| 142 | osg::Vec2 texcoord = osg::Vec2((float)col/(float)(columns-1), (float)row/(float)(rows-1)); |
---|
| 143 | |
---|
| 144 | // Set Coordinates for RTT-Texture (scene rendering) |
---|
| 145 | texcoords0->push_back( texcoord ); |
---|
| 146 | |
---|
| 147 | // Set Color of the mesh node |
---|
[332] | 148 | if (intensityMap && applyIntensityMapAsColours) |
---|
[331] | 149 | { |
---|
| 150 | colors->push_back(intensityMap->getColor(texcoord)); |
---|
| 151 | } |
---|
| 152 | else |
---|
| 153 | { |
---|
| 154 | colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | // Set coordinates for second texcoords array (if applyIntensityMapAsColours==true) |
---|
[333] | 158 | if (texcoords1) |
---|
| 159 | texcoords1->push_back( texcoord ); |
---|
[331] | 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // Pass the created vertex array to the points geometry object. |
---|
| 164 | geom->setUseVertexBufferObjects( true ); |
---|
| 165 | geom->setVertexArray(vertices); |
---|
| 166 | |
---|
| 167 | geom->setColorArray(colors); |
---|
| 168 | geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); |
---|
| 169 | |
---|
| 170 | geom->setTexCoordArray(0,texcoords0); |
---|
[333] | 171 | if (texcoords1) |
---|
| 172 | geom->setTexCoordArray(1,texcoords1); |
---|
[331] | 173 | |
---|
[340] | 174 | // Quads grid |
---|
| 175 | for ( unsigned int row=0; row<rows-1; row++ ) // each strip consists of two affected vertex rows, so we need only row-1 strips. |
---|
| 176 | { |
---|
[345] | 177 | osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::QUAD_STRIP, columns*2); // columns*2 = number of involved vertices for this strip. |
---|
[340] | 178 | for ( unsigned int col=0; col<columns; col++ ) |
---|
| 179 | { |
---|
| 180 | (*de)[col*2 + 0] = row*columns + col; |
---|
| 181 | (*de)[col*2 + 1] = (row+1)*columns + col; |
---|
| 182 | } |
---|
| 183 | geom->addPrimitiveSet( de.get() ); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | //// Triangle grid |
---|
[339] | 187 | //for ( unsigned int row=0; row<rows-1; row++ ) // each strip consists of two affected vertex rows, so we need only row-1 strips. |
---|
| 188 | //{ |
---|
[340] | 189 | // osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLE_STRIP, columns * 2 ); |
---|
[339] | 190 | // for ( unsigned int col=0; col<columns; col++ ) |
---|
| 191 | // { |
---|
| 192 | // (*de)[col*2 + 0] = row*columns + col; |
---|
| 193 | // (*de)[col*2 + 1] = (row+1)*columns + col; |
---|
| 194 | // } |
---|
| 195 | // geom->addPrimitiveSet( de.get() ); |
---|
| 196 | //} |
---|
[331] | 197 | |
---|
| 198 | return geom.release(); |
---|
| 199 | } |
---|
| 200 | |
---|
[315] | 201 | void extViewer::setUpViewForManualDistortion(unsigned int screenNum, osg::Image* intensityMap, const osg::Matrixd& projectorMatrix) |
---|
[311] | 202 | { |
---|
[313] | 203 | OSG_INFO<<"View::setUpViewForManualDistortion(sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl; |
---|
| 204 | |
---|
[311] | 205 | osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); |
---|
| 206 | if (!wsi) |
---|
| 207 | { |
---|
| 208 | OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; |
---|
| 209 | return; |
---|
| 210 | } |
---|
| 211 | |
---|
[313] | 212 | osg::GraphicsContext::ScreenIdentifier si; |
---|
[311] | 213 | si.readDISPLAY(); |
---|
| 214 | |
---|
| 215 | // displayNum has not been set so reset it to 0. |
---|
| 216 | if (si.displayNum<0) si.displayNum = 0; |
---|
| 217 | |
---|
| 218 | si.screenNum = screenNum; |
---|
| 219 | |
---|
| 220 | unsigned int width, height; |
---|
| 221 | wsi->getScreenResolution(si, width, height); |
---|
| 222 | |
---|
| 223 | osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; |
---|
| 224 | traits->hostName = si.hostName; |
---|
| 225 | traits->displayNum = si.displayNum; |
---|
| 226 | traits->screenNum = si.screenNum; |
---|
| 227 | traits->x = 0; |
---|
| 228 | traits->y = 0; |
---|
| 229 | traits->width = width; |
---|
| 230 | traits->height = height; |
---|
| 231 | traits->windowDecoration = false; |
---|
| 232 | traits->doubleBuffer = true; |
---|
| 233 | traits->sharedContext = 0; |
---|
| 234 | |
---|
[331] | 235 | bool applyIntensityMapAsColours = false; |
---|
[311] | 236 | |
---|
[313] | 237 | osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); |
---|
[311] | 238 | if (!gc) |
---|
| 239 | { |
---|
| 240 | OSG_NOTICE<<"GraphicsWindow has not been created successfully."<<std::endl; |
---|
| 241 | return; |
---|
| 242 | } |
---|
[333] | 243 | |
---|
[328] | 244 | // Set up projection Matrix as it is done in View::setUpViewOnSingleScreen( |
---|
| 245 | double fovy, aspectRatio, zNear, zFar; |
---|
| 246 | _camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); |
---|
[313] | 247 | |
---|
[328] | 248 | double newAspectRatio = double(traits->width) / double(traits->height); |
---|
| 249 | double aspectRatioChange = newAspectRatio / aspectRatio; |
---|
| 250 | if (aspectRatioChange != 1.0) |
---|
| 251 | { |
---|
| 252 | _camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0); |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | |
---|
[313] | 256 | int tex_width = width; |
---|
| 257 | int tex_height = height; |
---|
| 258 | |
---|
| 259 | int camera_width = tex_width; |
---|
| 260 | int camera_height = tex_height; |
---|
| 261 | |
---|
[334] | 262 | osg::TextureRectangle* sceneTexture = new osg::TextureRectangle; |
---|
[313] | 263 | |
---|
[334] | 264 | sceneTexture->setTextureSize(tex_width, tex_height); |
---|
| 265 | sceneTexture->setInternalFormat(GL_RGB); |
---|
| 266 | sceneTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
---|
| 267 | sceneTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); |
---|
| 268 | sceneTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); |
---|
| 269 | sceneTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); |
---|
[313] | 270 | |
---|
| 271 | |
---|
| 272 | #if 0 |
---|
| 273 | osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; |
---|
| 274 | GLenum buffer = GL_FRONT; |
---|
| 275 | #else |
---|
| 276 | osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT; |
---|
| 277 | GLenum buffer = GL_FRONT; |
---|
| 278 | #endif |
---|
| 279 | |
---|
| 280 | // Scene camera |
---|
| 281 | { |
---|
| 282 | osg::ref_ptr<osg::Camera> camera = new osg::Camera; |
---|
[315] | 283 | camera->setName("Scene cam"); |
---|
[313] | 284 | camera->setGraphicsContext(gc.get()); |
---|
| 285 | camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height)); |
---|
| 286 | camera->setDrawBuffer(buffer); |
---|
| 287 | camera->setReadBuffer(buffer); |
---|
| 288 | camera->setAllowEventFocus(false); |
---|
| 289 | // tell the camera to use OpenGL frame buffer object where supported. |
---|
| 290 | camera->setRenderTargetImplementation(renderTargetImplementation); |
---|
| 291 | // attach the texture and use it as the color buffer. |
---|
[334] | 292 | camera->attach(osg::Camera::COLOR_BUFFER, sceneTexture); |
---|
[313] | 293 | |
---|
| 294 | addSlave(camera.get(), osg::Matrixd(), osg::Matrixd()); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | // distortion correction set up. |
---|
| 298 | { |
---|
[333] | 299 | osg::Geode* geode = new osg::Geode(); |
---|
[313] | 300 | |
---|
[333] | 301 | // new we need to add the scene texture to the mesh, we do so by creating a |
---|
[313] | 302 | // StateSet to contain the Texture StateAttribute. |
---|
[336] | 303 | osg::StateSet* stateset = geode->getOrCreateStateSet(); |
---|
| 304 | stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON); |
---|
| 305 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
---|
[313] | 306 | |
---|
[336] | 307 | osg::TexMat* texmat = new osg::TexMat; |
---|
[337] | 308 | texmat->setScaleByTextureRectangleSize(true); |
---|
[336] | 309 | stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); |
---|
[313] | 310 | |
---|
[333] | 311 | // If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1 |
---|
| 312 | if (!applyIntensityMapAsColours && intensityMap) |
---|
[341] | 313 | setUpIntensityMapBlending(stateset, intensityMap, screenNum, 0, 1); |
---|
[337] | 314 | |
---|
| 315 | osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, intensityMap, applyIntensityMapAsColours, projectorMatrix); |
---|
| 316 | geode->addDrawable(distortionMesh); |
---|
| 317 | |
---|
[313] | 318 | osg::ref_ptr<osg::Camera> camera = new osg::Camera; |
---|
| 319 | camera->setGraphicsContext(gc.get()); |
---|
| 320 | camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT ); |
---|
[336] | 321 | camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) ); |
---|
[313] | 322 | camera->setViewport(new osg::Viewport(0, 0, width, height)); |
---|
| 323 | GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT; |
---|
| 324 | camera->setDrawBuffer(buffer); |
---|
| 325 | camera->setReadBuffer(buffer); |
---|
| 326 | camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); |
---|
| 327 | camera->setAllowEventFocus(false); |
---|
| 328 | camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); |
---|
| 329 | //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); |
---|
| 330 | |
---|
| 331 | camera->setProjectionMatrixAsOrtho2D(0,width,0,height); |
---|
| 332 | camera->setViewMatrix(osg::Matrix::identity()); |
---|
| 333 | |
---|
[338] | 334 | // selector |
---|
| 335 | geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); |
---|
| 336 | geode->getOrCreateStateSet()->setAttributeAndModes( new osg::PolygonOffset(1.0f, 1.0f) ); |
---|
[340] | 337 | osg::ref_ptr<distortionHandler> selectorHandler = new distortionHandler( camera, distortionMesh ); |
---|
[329] | 338 | osg::ref_ptr<osg::Group> root = new osg::Group; |
---|
| 339 | root->addChild(geode); |
---|
[340] | 340 | osg::Geode* selectorHighlighter = selectorHandler->createVertexHighlighter(); |
---|
| 341 | selectorHighlighter->setCullingActive(false); // disable the culling for the selector, otherwise the selector is culled away on the edge. |
---|
| 342 | root->addChild(selectorHighlighter); |
---|
| 343 | addEventHandler( selectorHandler.get() ); |
---|
[329] | 344 | camera->addChild(root); |
---|
[338] | 345 | // Avoid that the highlighter is culled away |
---|
| 346 | osg::CullSettings::CullingMode mode = camera->getCullingMode(); |
---|
| 347 | camera->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) ); |
---|
[329] | 348 | |
---|
[346] | 349 | // Add the distortionHandler |
---|
| 350 | addEventHandler(new osgViewer::DistortionManipulator); |
---|
[329] | 351 | |
---|
[346] | 352 | |
---|
[320] | 353 | camera->setName("Dist Cam"); |
---|
[313] | 354 | |
---|
| 355 | addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); |
---|
| 356 | } |
---|
[341] | 357 | } |
---|
| 358 | |
---|
| 359 | void extViewer::setUpIntensityMapBlending(osg::StateSet* stateset, osg::Image* intensityMap, unsigned int screenNum, int rttSceneTextureUnit, int intensityMapTextureUnit) |
---|
| 360 | { |
---|
| 361 | if(stateset == NULL || intensityMap == NULL) |
---|
| 362 | { |
---|
| 363 | OSG_NOTICE<<"Error, no intensityMap or stateset for intensityMapBlending specified."<<std::endl; |
---|
| 364 | return; |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); |
---|
| 368 | if (!wsi) |
---|
| 369 | { |
---|
| 370 | OSG_NOTICE<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; |
---|
| 371 | return; |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | osg::GraphicsContext::ScreenIdentifier si; |
---|
| 375 | si.readDISPLAY(); |
---|
| 376 | |
---|
| 377 | // displayNum has not been set so reset it to 0. |
---|
| 378 | if (si.displayNum<0) si.displayNum = 0; |
---|
| 379 | |
---|
| 380 | si.screenNum = screenNum; |
---|
| 381 | |
---|
| 382 | unsigned int width, height; |
---|
| 383 | wsi->getScreenResolution(si, width, height); |
---|
| 384 | |
---|
| 385 | // Resize intensityMap if the dimensions are wrong |
---|
| 386 | if(intensityMap->s()!=width || intensityMap->t()!=height) |
---|
| 387 | intensityMap->scaleImage(width, height, intensityMap->r()); |
---|
| 388 | |
---|
| 389 | osg::TextureRectangle* intensityMapTexture = new osg::TextureRectangle(intensityMap); |
---|
| 390 | intensityMapTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
---|
| 391 | intensityMapTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); |
---|
| 392 | intensityMapTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); |
---|
| 393 | intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); |
---|
| 394 | |
---|
| 395 | stateset->setTextureAttributeAndModes(intensityMapTextureUnit, intensityMapTexture, osg::StateAttribute::ON); |
---|
| 396 | |
---|
| 397 | // create shaders for blending |
---|
| 398 | osg::Program* distortProgram = new osg::Program; |
---|
| 399 | distortProgram->setName( "intensityMapBlending" ); |
---|
| 400 | osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" ); |
---|
| 401 | fShader->setName("intensityMapFragShader"); |
---|
| 402 | |
---|
| 403 | if ( fShader ) |
---|
| 404 | { |
---|
| 405 | distortProgram->addShader( fShader ); |
---|
| 406 | stateset->addUniform( new osg::Uniform("sceneTexture", rttSceneTextureUnit) ); |
---|
| 407 | stateset->addUniform( new osg::Uniform("intensityMapTexture", intensityMapTextureUnit) ); |
---|
| 408 | stateset->setAttributeAndModes(distortProgram, osg::StateAttribute::ON); |
---|
| 409 | } |
---|
[325] | 410 | } |
---|