| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "LightPointDrawable.h" |
|---|
| 15 | |
|---|
| 16 | #include <osg/Point> |
|---|
| 17 | |
|---|
| 18 | using namespace osgSim; |
|---|
| 19 | |
|---|
| 20 | LightPointDrawable::LightPointDrawable(): |
|---|
| 21 | osg::Drawable(), |
|---|
| 22 | _endian(osg::getCpuByteOrder()), |
|---|
| 23 | _simulationTime(0.0), |
|---|
| 24 | _simulationTimeInterval(0.0) |
|---|
| 25 | { |
|---|
| 26 | |
|---|
| 27 | setSupportsDisplayList(false); |
|---|
| 28 | |
|---|
| 29 | _depthOff = new osg::Depth; |
|---|
| 30 | _depthOff->setWriteMask(false); |
|---|
| 31 | |
|---|
| 32 | _depthOn = new osg::Depth; |
|---|
| 33 | _depthOn->setWriteMask(true); |
|---|
| 34 | |
|---|
| 35 | _blendOne = new osg::BlendFunc; |
|---|
| 36 | _blendOne->setFunction(osg::BlendFunc::SRC_ALPHA,osg::BlendFunc::ONE); |
|---|
| 37 | |
|---|
| 38 | _blendOneMinusSrcAlpha = new osg::BlendFunc; |
|---|
| 39 | _blendOneMinusSrcAlpha->setFunction(osg::BlendFunc::SRC_ALPHA,osg::BlendFunc::ONE_MINUS_SRC_ALPHA); |
|---|
| 40 | |
|---|
| 41 | _colorMaskOff = new osg::ColorMask; |
|---|
| 42 | _colorMaskOff->setMask(false,false,false,false); |
|---|
| 43 | |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | LightPointDrawable::LightPointDrawable(const LightPointDrawable& lpd,const osg::CopyOp& copyop): |
|---|
| 47 | osg::Drawable(lpd,copyop), |
|---|
| 48 | _endian(lpd._endian), |
|---|
| 49 | _simulationTime(lpd._simulationTime), |
|---|
| 50 | _simulationTimeInterval(lpd._simulationTimeInterval), |
|---|
| 51 | _sizedOpaqueLightPointList(lpd._sizedOpaqueLightPointList), |
|---|
| 52 | _sizedAdditiveLightPointList(lpd._sizedAdditiveLightPointList), |
|---|
| 53 | _sizedBlendedLightPointList(lpd._sizedBlendedLightPointList) |
|---|
| 54 | { |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | void LightPointDrawable::reset() |
|---|
| 58 | { |
|---|
| 59 | SizedLightPointList::iterator itr; |
|---|
| 60 | for(itr=_sizedOpaqueLightPointList.begin(); |
|---|
| 61 | itr!=_sizedOpaqueLightPointList.end(); |
|---|
| 62 | ++itr) |
|---|
| 63 | { |
|---|
| 64 | if (!itr->empty()) |
|---|
| 65 | itr->erase(itr->begin(),itr->end()); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | for(itr=_sizedAdditiveLightPointList.begin(); |
|---|
| 69 | itr!=_sizedAdditiveLightPointList.end(); |
|---|
| 70 | ++itr) |
|---|
| 71 | { |
|---|
| 72 | if (!itr->empty()) |
|---|
| 73 | itr->erase(itr->begin(),itr->end()); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | for(itr=_sizedBlendedLightPointList.begin(); |
|---|
| 77 | itr!=_sizedBlendedLightPointList.end(); |
|---|
| 78 | ++itr) |
|---|
| 79 | { |
|---|
| 80 | if (!itr->empty()) |
|---|
| 81 | itr->erase(itr->begin(),itr->end()); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | void LightPointDrawable::drawImplementation(osg::RenderInfo& renderInfo) const |
|---|
| 87 | { |
|---|
| 88 | #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) |
|---|
| 89 | osg::State& state = *renderInfo.getState(); |
|---|
| 90 | |
|---|
| 91 | state.applyMode(GL_POINT_SMOOTH,true); |
|---|
| 92 | state.applyMode(GL_BLEND,true); |
|---|
| 93 | state.applyMode(GL_LIGHTING,false); |
|---|
| 94 | state.applyTextureMode(0,GL_TEXTURE_1D,false); |
|---|
| 95 | state.applyTextureMode(0,GL_TEXTURE_2D,false); |
|---|
| 96 | |
|---|
| 97 | glHint(GL_POINT_SMOOTH_HINT,GL_NICEST); |
|---|
| 98 | |
|---|
| 99 | state.applyAttribute(_depthOn.get()); |
|---|
| 100 | |
|---|
| 101 | state.applyAttribute(_blendOneMinusSrcAlpha.get()); |
|---|
| 102 | state.applyMode(GL_POINT_SMOOTH,true); |
|---|
| 103 | |
|---|
| 104 | SizedLightPointList::const_iterator sitr; |
|---|
| 105 | unsigned int pointsize; |
|---|
| 106 | for(pointsize=1,sitr=_sizedOpaqueLightPointList.begin(); |
|---|
| 107 | sitr!=_sizedOpaqueLightPointList.end(); |
|---|
| 108 | ++sitr,++pointsize) |
|---|
| 109 | { |
|---|
| 110 | |
|---|
| 111 | const LightPointList& lpl = *sitr; |
|---|
| 112 | if (!lpl.empty()) |
|---|
| 113 | { |
|---|
| 114 | glPointSize(pointsize); |
|---|
| 115 | |
|---|
| 116 | state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front()); |
|---|
| 117 | glDrawArrays(GL_POINTS,0,lpl.size()); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | state.applyMode(GL_BLEND,true); |
|---|
| 122 | state.applyAttribute(_depthOff.get()); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | state.applyAttribute(_blendOneMinusSrcAlpha.get()); |
|---|
| 126 | |
|---|
| 127 | for(pointsize=1,sitr=_sizedBlendedLightPointList.begin(); |
|---|
| 128 | sitr!=_sizedBlendedLightPointList.end(); |
|---|
| 129 | ++sitr,++pointsize) |
|---|
| 130 | { |
|---|
| 131 | |
|---|
| 132 | const LightPointList& lpl = *sitr; |
|---|
| 133 | if (!lpl.empty()) |
|---|
| 134 | { |
|---|
| 135 | glPointSize(pointsize); |
|---|
| 136 | |
|---|
| 137 | state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front()); |
|---|
| 138 | glDrawArrays(GL_POINTS,0,lpl.size()); |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | state.applyAttribute(_blendOne.get()); |
|---|
| 144 | |
|---|
| 145 | for(pointsize=1,sitr=_sizedAdditiveLightPointList.begin(); |
|---|
| 146 | sitr!=_sizedAdditiveLightPointList.end(); |
|---|
| 147 | ++sitr,++pointsize) |
|---|
| 148 | { |
|---|
| 149 | |
|---|
| 150 | const LightPointList& lpl = *sitr; |
|---|
| 151 | if (!lpl.empty()) |
|---|
| 152 | { |
|---|
| 153 | |
|---|
| 154 | glPointSize(pointsize); |
|---|
| 155 | |
|---|
| 156 | state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front()); |
|---|
| 157 | glDrawArrays(GL_POINTS,0,lpl.size()); |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | glPointSize(1); |
|---|
| 162 | |
|---|
| 163 | glHint(GL_POINT_SMOOTH_HINT,GL_FASTEST); |
|---|
| 164 | |
|---|
| 165 | state.haveAppliedAttribute(osg::StateAttribute::POINT); |
|---|
| 166 | |
|---|
| 167 | state.dirtyAllVertexArrays(); |
|---|
| 168 | state.disableAllVertexArrays(); |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | state.apply(); |
|---|
| 172 | #else |
|---|
| 173 | OSG_NOTICE<<"Warning: LightPointDrawable not supported."<<std::endl; |
|---|
| 174 | #endif |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | osg::BoundingBox LightPointDrawable::computeBound() const |
|---|
| 178 | { |
|---|
| 179 | osg::BoundingBox bbox; |
|---|
| 180 | |
|---|
| 181 | SizedLightPointList::const_iterator sitr; |
|---|
| 182 | for(sitr=_sizedOpaqueLightPointList.begin(); |
|---|
| 183 | sitr!=_sizedOpaqueLightPointList.end(); |
|---|
| 184 | ++sitr) |
|---|
| 185 | { |
|---|
| 186 | const LightPointList& lpl = *sitr; |
|---|
| 187 | for(LightPointList::const_iterator litr=lpl.begin(); |
|---|
| 188 | litr!=lpl.end(); |
|---|
| 189 | ++litr) |
|---|
| 190 | { |
|---|
| 191 | bbox.expandBy(litr->second); |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 194 | for(sitr=_sizedAdditiveLightPointList.begin(); |
|---|
| 195 | sitr!=_sizedAdditiveLightPointList.end(); |
|---|
| 196 | ++sitr) |
|---|
| 197 | { |
|---|
| 198 | const LightPointList& lpl = *sitr; |
|---|
| 199 | for(LightPointList::const_iterator litr=lpl.begin(); |
|---|
| 200 | litr!=lpl.end(); |
|---|
| 201 | ++litr) |
|---|
| 202 | { |
|---|
| 203 | bbox.expandBy(litr->second); |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | for(sitr=_sizedBlendedLightPointList.begin(); |
|---|
| 207 | sitr!=_sizedBlendedLightPointList.end(); |
|---|
| 208 | ++sitr) |
|---|
| 209 | { |
|---|
| 210 | const LightPointList& lpl = *sitr; |
|---|
| 211 | for(LightPointList::const_iterator litr=lpl.begin(); |
|---|
| 212 | litr!=lpl.end(); |
|---|
| 213 | ++litr) |
|---|
| 214 | { |
|---|
| 215 | bbox.expandBy(litr->second); |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | return bbox; |
|---|
| 220 | } |
|---|