2 #include "CloudScene.h"
44 osg::ref_ptr<osg::Program> sh_blur_linear_vert1;
45 osg::ref_ptr<osg::Program> sh_blur_linear_hori1;
46 osg::ref_ptr<osg::Uniform> uniform_blur_texsize2;
47 osg::ref_ptr<osg::Uniform> uniform_blur_texsize1;
49 osg::ref_ptr<osg::Camera> cam_hud;
50 osg::ref_ptr<osg::StateSet> nodessP;
51 osg::ref_ptr<osg::Program> planeProg;
60 BlurShadowGeometry( osg::ref_ptr<osg::Program> prog_vert1, osg::ref_ptr<osg::Uniform> _uniform_blur_texsize,
int mode)
62 sh_blur_linear_vert1 = (prog_vert1);
63 uniform_blur_texsize = _uniform_blur_texsize;
72 void drawImplementation(osg::RenderInfo& renderInfo)
const
74 if (_internalOptimizedGeometry.valid())
76 _internalOptimizedGeometry->drawImplementation(renderInfo);
80 osg::State& state = *renderInfo.getState();
82 bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE;
83 if (checkForGLErrors) state.checkGLErrors(
"start of Geometry::drawImplementation()");
85 bool useFastPath = areFastPathsUsed();
88 bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
89 bool handleVertexAttributes = !_vertexAttribList.empty();
91 osg::ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
93 arrayDispatchers.reset();
94 arrayDispatchers.setUseVertexAttribAlias(useFastPath && state.getUseVertexAttributeAliasing());
95 arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath);
97 arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get());
98 arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get());
99 arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get());
100 arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get());
102 if (handleVertexAttributes)
104 for(
unsigned int unit=0;unit<_vertexAttribList.size();++unit)
106 arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding, unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get());
111 arrayDispatchers.dispatch(BIND_OVERALL,0);
113 state.lazyDisablingOfVertexAttributes();
118 if( _vertexData.array.valid() )
119 state.setVertexPointer(_vertexData.array.get());
121 if (_normalData.binding==BIND_PER_VERTEX && _normalData.array.valid())
122 state.setNormalPointer(_normalData.array.get());
124 if (_colorData.binding==BIND_PER_VERTEX && _colorData.array.valid())
125 state.setColorPointer(_colorData.array.get());
127 if (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.array.valid())
128 state.setSecondaryColorPointer(_secondaryColorData.array.get());
130 if (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.array.valid())
131 state.setFogCoordPointer(_fogCoordData.array.get());
133 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
135 const osg::Array* array = _texCoordList[unit].array.get();
136 if (array) state.setTexCoordPointer(unit,array);
139 if( handleVertexAttributes )
141 for(
unsigned int index = 0; index < _vertexAttribList.size(); ++index )
143 const osg::Array* array = _vertexAttribList[index].array.get();
144 const AttributeBinding ab = _vertexAttribList[index].binding;
145 if( ab == BIND_PER_VERTEX && array )
147 state.setVertexAttribPointer( index, array, _vertexAttribList[index].normalize );
154 for(
unsigned int unit=0;unit<_texCoordList.size();++unit)
156 arrayDispatchers.activateTexCoordArray(BIND_PER_VERTEX, unit, _texCoordList[unit].array.get(), _texCoordList[unit].indices.get());
159 arrayDispatchers.activateVertexArray(BIND_PER_VERTEX, _vertexData.array.get(), _vertexData.indices.get());
162 state.applyDisablingOfVertexAttributes();
164 bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET);
165 bool bindPerPrimitiveActive = arrayDispatchers.active(BIND_PER_PRIMITIVE);
167 if (checkForGLErrors) state.checkGLErrors(
"Geometry::drawImplementation() after vertex arrays setup.");
170 osg::GL2Extensions* extension = osg::GL2Extensions::Get(0,
true);
172 glClearColor(0.f, 0.1f, 0.f, 1.f);
180 glViewport(0,0,1024, 1024);
181 Scene::fbo_vert_linear_blur2->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
182 glClear( GL_COLOR_BUFFER_BIT);
186 Scene::fbo_hori_linear_blur2->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
187 glClear( GL_COLOR_BUFFER_BIT);
190 for(
unsigned int primitiveSetNum=0; primitiveSetNum!= _primitives.size() ; ++primitiveSetNum)
193 if (bindPerPrimitiveSetActive)
194 arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum);
196 const osg::PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get();
199 glDisable(GL_DEPTH_TEST);
200 glDisable(GL_CULL_FACE);
202 osg::State& state = *renderInfo.getState();
204 osg::Depth* depth2 =
new osg::Depth(osg::Depth::ALWAYS, 0.0, 1.0,
false);
205 depth2->apply(state);
210 glViewport(0.f, 0.f, 1024, 1024);
211 sh_blur_linear_vert1->apply(state);
213 Scene::fbo_vert_linear_blur2->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
214 uniform_blur_texsize->set(1024.f);
215 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
216 primitiveset->draw(state, usingVertexBufferObjects);
220 glViewport(0.f, 0.f, 1024, 1024);
221 sh_blur_linear_vert1->apply(state);
223 Scene::fbo_hori_linear_blur2->apply(state, osg::FrameBufferObject::READ_DRAW_FRAMEBUFFER);
224 uniform_blur_texsize->set(1024.f);
225 uniform_blur_texsize->apply(extension, state.getUniformLocation(
"texsize"));
226 primitiveset->draw(state, usingVertexBufferObjects);
229 glEnable(GL_DEPTH_TEST);
235 state.unbindVertexBufferObject();
236 state.unbindElementBufferObject();
238 if (checkForGLErrors) state.checkGLErrors(
"end of Geometry::drawImplementation().");
241 osg::ref_ptr<osg::Program> sh_blur_linear_vert1;
242 osg::ref_ptr<osg::Uniform> uniform_blur_texsize;
261 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
263 osgUtil::CullVisitor* cv =
dynamic_cast<osgUtil::CullVisitor*
>(nv);
264 osg::ref_ptr<osg::Geode> geometry =
dynamic_cast<osg::Geode*
> (node);
267 if(geometry && cv &&
false)