| | 1 | /* OpenSceneGraph example, osgpackeddepthstencil. |
| | 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 | |
| | 120 | arguments.getApplicationUsage()->addCommandLineOption("--fbo","Use Frame Buffer Object for render to texture, where supported."); |
| | 121 | arguments.getApplicationUsage()->addCommandLineOption("--pbuffer-rtt","Use Pixel Buffer for render to texture, where supported."); |
| | 122 | arguments.getApplicationUsage()->addCommandLineOption("--nopds", "Don't use packed depth stencil."); |
| | 123 | arguments.getApplicationUsage()->addCommandLineOption("--fbo-samples",""); |
| | 124 | arguments.getApplicationUsage()->addCommandLineOption("--color-samples", ""); |
| | 125 | |
| | 131 | |
| | 132 | // if user request help write it out to cout. |
| | 133 | if (arguments.read("-h") || arguments.read("--help")) |
| | 134 | { |
| | 135 | arguments.getApplicationUsage()->write(std::cout); |
| | 136 | return 1; |
| | 137 | } |
| | 138 | |
| | 139 | osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; |
| | 140 | int colorSamples = 0, samples = 0; |
| | 141 | bool usePDS = true; |
| | 142 | |
| | 143 | while (arguments.read("--fbo")) { renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; } |
| | 144 | while (arguments.read("--pbuffer-rtt")) { renderImplementation = osg::Camera::PIXEL_BUFFER_RTT; } |
| | 145 | while (arguments.read("--nopds")) { usePDS = false; } |
| | 146 | while (arguments.read("--fbo-samples", samples)) {} |
| | 147 | while (arguments.read("--color-samples", colorSamples)) {} |
| | 148 | |
| 128 | | rttCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); |
| 129 | | |
| 130 | | #define USE_PACKED_DEPTH_STENCIL |
| 131 | | |
| 132 | | #ifdef USE_PACKED_DEPTH_STENCIL |
| 133 | | rttCamera->attach(osg::Camera::PACKED_DEPTH_STENCIL_BUFFER, GL_DEPTH_STENCIL_EXT); |
| 134 | | #else |
| 135 | | // this doesn't work on NVIDIA/Vista 64bit |
| 136 | | // FBO status = 0x8cd6 (FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT) |
| 137 | | rttCamera->attach(osg::Camera::DEPTH_BUFFER, GL_DEPTH_COMPONENT); |
| 138 | | rttCamera->attach(osg::Camera::STENCIL_BUFFER, GL_STENCIL_INDEX_EXT); |
| 139 | | #endif |
| 140 | | rttCamera->attach(osg::Camera::COLOR_BUFFER, texture); |
| | 172 | rttCamera->setRenderTargetImplementation(renderImplementation); |
| | 173 | |
| | 174 | if(usePDS) |
| | 175 | { |
| | 176 | rttCamera->attach(osg::Camera::PACKED_DEPTH_STENCIL_BUFFER, GL_DEPTH_STENCIL_EXT); |
| | 177 | } |
| | 178 | else |
| | 179 | { |
| | 180 | // this doesn't work on NVIDIA/Vista 64bit |
| | 181 | // FBO status = 0x8cd6 (FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT) |
| | 182 | rttCamera->attach(osg::Camera::DEPTH_BUFFER, GL_DEPTH_COMPONENT); |
| | 183 | rttCamera->attach(osg::Camera::STENCIL_BUFFER, GL_STENCIL_INDEX8_EXT); |
| | 184 | } |
| | 185 | |
| | 186 | rttCamera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 0, false, samples, colorSamples); |