3 * Copyright (C) 2008 Stuart Buchanan
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #include <osgDB/Registry>
23 #include <osgDB/Input>
24 #include <osgDB/ParameterOutput>
26 #include "ShaderGeometry.hxx"
29 using namespace osgDB;
33 void ShaderGeometry::drawImplementation(RenderInfo& renderInfo) const
35 for(PositionSizeList::const_iterator itr = _trees.begin();
38 glColor4fv(itr->ptr());
39 _geometry->draw(renderInfo);
43 BoundingBox ShaderGeometry::computeBound() const
45 BoundingBox geom_box = _geometry->getBound();
47 for(PositionSizeList::const_iterator itr = _trees.begin();
50 bb.expandBy(geom_box.corner(0)*(*itr)[3] +
51 Vec3((*itr)[0], (*itr)[1], (*itr)[2]));
52 bb.expandBy(geom_box.corner(7)*(*itr)[3] +
53 Vec3((*itr)[0], (*itr)[1], (*itr)[2]));
58 bool ShaderGeometry_readLocalData(Object& obj, Input& fr)
60 bool iteratorAdvanced = false;
62 ShaderGeometry& geom = static_cast<ShaderGeometry&>(obj);
64 if ((fr[0].matchWord("geometry"))) {
66 iteratorAdvanced = true;
67 Drawable* drawable = fr.readDrawable();
69 geom._geometry = drawable;
72 if ((fr.matchSequence("instances %i"))) {
73 int entry = fr[0].getNoNestedBrackets();
75 fr[1].getInt(capacity);
76 geom._trees.reserve(capacity);
78 iteratorAdvanced = true;
80 while (!fr.eof() && fr[0].getNoNestedBrackets() > entry) {
82 if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y())
83 && fr[2].getFloat(v.z()) && fr[3].getFloat(v.w())) {
85 geom._trees.push_back(v);
91 return iteratorAdvanced;
94 bool ShaderGeometry_writeLocalData(const Object& obj, Output& fw)
96 const ShaderGeometry& geom = static_cast<const ShaderGeometry&>(obj);
98 fw.indent() << "geometry" << std::endl;
99 fw.writeObject(*geom._geometry);
100 fw.indent() << "instances " << geom._trees.size() << std::endl;
101 fw.indent() << "{" << std::endl;
103 for (ShaderGeometry::PositionSizeList::const_iterator iter
104 = geom._trees.begin();
105 iter != geom._trees.end();
107 fw.indent() << iter->x() << " " << iter->y() << " " << iter->z() << " "
108 << iter->w() << std::endl;
111 fw.indent() << "}" << std::endl;
115 osgDB::RegisterDotOsgWrapperProxy shaderGeometryProxy
119 "Object Drawable ShaderGeometry",
120 &ShaderGeometry_readLocalData,
121 &ShaderGeometry_writeLocalData