1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version.  The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * OpenSceneGraph Public License for more details.
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     // Assume the point sprite texture map is already specified
50     // (typically in the owning LightPointNode StateSet).
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 
setBP(jvmtiEnv * jvmti_env,JNIEnv * env,jclass klass)67         const LightPointList& lpl = *sitr;
68         if (!lpl.empty())
69         {
70             glPointSize(pointsize);
71             //glInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
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());
ClassLoad(jvmtiEnv * jvmti_env,JNIEnv * env,jthread thread,jclass klass)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             //glInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
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)
VMStart(jvmtiEnv * jvmti_env,JNIEnv * jni_env)104     {
105 
106         const LightPointList& lpl = *sitr;
107         if (!lpl.empty())
108         {
109             //state.applyMode(GL_POINT_SMOOTH,pointsize!=1);
110             glPointSize(pointsize);
111             //glInterleavedArrays(GL_C4UB_V3F,0,&lpl.front());
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 
Breakpoint(jvmtiEnv * jvmti_env,JNIEnv * env,jthread thr,jmethodID method,jlocation loc)123     state.dirtyAllVertexArrays();
124     state.disableAllVertexArrays();
125 
126     // restore the state afterwards.
127     state.apply();
128 #else
129     OSG_NOTICE<<"Warning: LightPointDrawable not supported."<<std::endl;
130 #endif
131 }
132 
133 
134