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 #ifndef CLOUD_SHADER_GEOMETRY_HXX
23 #define CLOUD_SHADER_GEOMETRY_HXX 1
27 #include <osg/BoundingBox>
29 #include <osg/Drawable>
30 #include <osg/Geometry>
31 #include <osg/RenderInfo>
34 #include <osg/buffered_value>
36 #include <simgear/math/SGMath.hxx>
37 #include <simgear/math/sg_random.h>
43 class CloudShaderGeometry : public osg::Drawable
47 const static unsigned int USR_ATTR_1 = 10;
48 const static unsigned int USR_ATTR_2 = 11;
52 setUseDisplayList(false);
55 CloudShaderGeometry(int vx, int vy, float width, float height) :
56 varieties_x(vx), varieties_y(vy)
58 setUseDisplayList(false);
60 float z = height/2.0f;
61 _bbox.expandBy(-x, -x, -z);
62 _bbox.expandBy(x, x, z);
65 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
66 CloudShaderGeometry(const CloudShaderGeometry& CloudShaderGeometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
67 osg::Drawable(CloudShaderGeometry,copyop) {}
69 META_Object(flightgear, CloudShaderGeometry);
72 CloudSprite(const SGVec3f& p, int tx, int ty, float w, float h,
74 position(p), texture_index_x(tx), texture_index_y(ty), width(w), height(h), shade(s), cloud_height(ch)
86 typedef std::vector<CloudSprite> CloudSpriteList;
87 CloudSpriteList _cloudsprites;
89 void insert(const CloudSprite& t)
90 { _cloudsprites.push_back(t); }
91 void insert(SGVec3f& p, int tx, int ty, float w, float h, float s, float ch)
92 { insert(CloudSprite(p, tx, ty, w, h, s, ch)); }
94 unsigned getNumCloudSprite() const
95 { return _cloudsprites.size(); }
96 CloudSprite& getCloudSprite(unsigned i)
97 { return _cloudsprites[i]; }
99 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
100 virtual osg::BoundingBox computeBound() const
105 void setGeometry(osg::Drawable* geometry)
107 _geometry = geometry;
110 void addSprite(const SGVec3f& p, int tx, int ty, float w, float h,
111 float s, float cull, float cloud_height);
113 osg::ref_ptr<osg::Drawable> _geometry;
118 // Bounding box extents.
119 osg::BoundingBox _bbox;
125 SortItem(size_t idx_, float depth_) : idx(idx_), depth(depth_) {}
126 SortItem() : idx(0), depth(0.0f) {}
130 SortData() : frameSorted(0), skip_limit(1), spriteIdx(0) {}
133 // This will be sorted by Z distance
134 typedef std::vector<SortItem> SortItemList;
135 SortItemList* spriteIdx;
138 mutable osg::buffered_object<SortData> _sortData;
140 virtual ~CloudShaderGeometry()
142 for (unsigned int i = 0; i < _sortData.size(); ++i)
143 delete _sortData[i].spriteIdx;