| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "LightPointSpriteDrawable.h" |
|---|
| 15 | |
|---|
| 16 | #include <osg/Point> |
|---|
| 17 | |
|---|
| 18 | using namespace osgSim; |
|---|
| 19 | |
|---|
| 20 | LightPointSpriteDrawable::LightPointSpriteDrawable(): |
|---|
| 21 | osgSim::LightPointDrawable() |
|---|
| 22 | { |
|---|
| 23 | _sprite = new osg::PointSprite; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | LightPointSpriteDrawable::LightPointSpriteDrawable(const LightPointSpriteDrawable& lpsd,const osg::CopyOp& copyop): |
|---|
| 27 | osgSim::LightPointDrawable(lpsd,copyop) |
|---|
| 28 | { |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | void LightPointSpriteDrawable::drawImplementation(osg::RenderInfo& renderInfo) const |
|---|
| 32 | { |
|---|
| 33 | #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) |
|---|
| 34 | osg::State& state = *renderInfo.getState(); |
|---|
| 35 | |
|---|
| 36 | if (!state.getModeValidity(GL_POINT_SPRITE_ARB)) |
|---|
| 37 | { |
|---|
| 38 | LightPointDrawable::drawImplementation(renderInfo); |
|---|
| 39 | return; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | state.applyMode(GL_POINT_SMOOTH,true); |
|---|
| 43 | state.applyMode(GL_BLEND,true); |
|---|
| 44 | state.applyMode(GL_LIGHTING,false); |
|---|
| 45 | state.applyTextureMode(0,GL_TEXTURE_2D,true); |
|---|
| 46 | |
|---|
| 47 | state.applyMode(GL_POINT_SPRITE_ARB,true); |
|---|
| 48 | state.applyTextureAttribute(0,_sprite.get()); |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | glHint(GL_POINT_SMOOTH_HINT,GL_NICEST); |
|---|
| 54 | |
|---|
| 55 | state.applyAttribute(_depthOn.get()); |
|---|
| 56 | |
|---|
| 57 | state.applyAttribute(_blendOneMinusSrcAlpha.get()); |
|---|
| 58 | state.applyMode(GL_POINT_SMOOTH,true); |
|---|
| 59 | |
|---|
| 60 | SizedLightPointList::const_iterator sitr; |
|---|
| 61 | unsigned int pointsize; |
|---|
| 62 | for(pointsize=1,sitr=_sizedOpaqueLightPointList.begin(); |
|---|
| 63 | sitr!=_sizedOpaqueLightPointList.end(); |
|---|
| 64 | ++sitr,++pointsize) |
|---|
| 65 | { |
|---|
| 66 | |
|---|
| 67 | const LightPointList& lpl = *sitr; |
|---|
| 68 | if (!lpl.empty()) |
|---|
| 69 | { |
|---|
| 70 | glPointSize(pointsize); |
|---|
| 71 | |
|---|
| 72 | state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front()); |
|---|
| 73 | glDrawArrays(GL_POINTS,0,lpl.size()); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | state.applyMode(GL_BLEND,true); |
|---|
| 78 | state.applyAttribute(_depthOff.get()); |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | state.applyAttribute(_blendOneMinusSrcAlpha.get()); |
|---|
| 82 | |
|---|
| 83 | for(pointsize=1,sitr=_sizedBlendedLightPointList.begin(); |
|---|
| 84 | sitr!=_sizedBlendedLightPointList.end(); |
|---|
| 85 | ++sitr,++pointsize) |
|---|
| 86 | { |
|---|
| 87 | |
|---|
| 88 | const LightPointList& lpl = *sitr; |
|---|
| 89 | if (!lpl.empty()) |
|---|
| 90 | { |
|---|
| 91 | glPointSize(pointsize); |
|---|
| 92 | |
|---|
| 93 | state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front()); |
|---|
| 94 | glDrawArrays(GL_POINTS,0,lpl.size()); |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | state.applyAttribute(_blendOne.get()); |
|---|
| 100 | |
|---|
| 101 | for(pointsize=1,sitr=_sizedAdditiveLightPointList.begin(); |
|---|
| 102 | sitr!=_sizedAdditiveLightPointList.end(); |
|---|
| 103 | ++sitr,++pointsize) |
|---|
| 104 | { |
|---|
| 105 | |
|---|
| 106 | const LightPointList& lpl = *sitr; |
|---|
| 107 | if (!lpl.empty()) |
|---|
| 108 | { |
|---|
| 109 | |
|---|
| 110 | glPointSize(pointsize); |
|---|
| 111 | |
|---|
| 112 | state.setInterleavedArrays(GL_C4UB_V3F,0,&lpl.front()); |
|---|
| 113 | glDrawArrays(GL_POINTS,0,lpl.size()); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | glPointSize(1); |
|---|
| 118 | |
|---|
| 119 | glHint(GL_POINT_SMOOTH_HINT,GL_FASTEST); |
|---|
| 120 | |
|---|
| 121 | state.haveAppliedAttribute(osg::StateAttribute::POINT); |
|---|
| 122 | |
|---|
| 123 | state.dirtyAllVertexArrays(); |
|---|
| 124 | state.disableAllVertexArrays(); |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | state.apply(); |
|---|
| 128 | #else |
|---|
| 129 | OSG_NOTICE<<"Warning: LightPointDrawable not supported."<<std::endl; |
|---|
| 130 | #endif |
|---|
| 131 | } |
|---|
| 132 | |
|---|