Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
StaticBillboardSet.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------------------
2Copyright (c) 2006 John Judnich
3
4This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
5Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
61. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
72. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
83. This notice may not be removed or altered from any source distribution.
9-------------------------------------------------------------------------------------*/
10
11//StaticBillboardSet.h
12//Provides a method of displaying billboards faster than Ogre's built-in BillboardSet
13//functions by taking advantage of the static nature of tree billboards (note:
14//StaticBillboardSet does not allow billboards to be moved or deleted individually in
15//real-time)
16//-------------------------------------------------------------------------------------
17
18#ifndef __StaticBillboardSet_H__
19#define __StaticBillboardSet_H__
20
21#include <OgrePrerequisites.h>
22#include <OgreRoot.h>
23#include <OgreRenderSystem.h>
24#include <OgreVector3.h>
25#include <OgreMesh.h>
26#include <OgreMaterial.h>
27#include <OgreBillboard.h>
28#include <OgreBillboardSet.h>
29#include <OgreMaterialManager.h>
30#include <OgreSceneNode.h>
31#include <OgreStringConverter.h>
32
33namespace Forests
34{
35
36 class SBMaterialRef;
37 typedef std::map<Ogre::Material*, SBMaterialRef*> SBMaterialRefList;
38
39 //--------------------------------------------------------------------------
49 {
50 //-----------------------------------------------------------------------------
51 //Internal class - do not use
53 {
54 public:
55 // Constructor
56 StaticBillboard(const Ogre::Vector3 &pos, float xScale, float yScale,
57 const Ogre::ColourValue &clr, Ogre::uint16 texcrdIndexU, Ogre::uint16 texcrdIndexV) :
58 xPos((float)pos.x), yPos((float)pos.y), zPos((float)pos.z), xScaleHalf(0.5f * xScale), yScaleHalf(0.5f * yScale),
59 texcoordIndexU(texcrdIndexU), texcoordIndexV(texcrdIndexV)
60 {
61 Ogre::Root::getSingletonPtr()->getRenderSystem()->convertColourValue(clr, &color);
62 }
63
64
65 // SVA mem friendly aligment
66 float xPos, yPos, zPos;
67 //float xScale, yScale;
69 Ogre::uint32 color;
71 };
72
73 public:
81 StaticBillboardSet(Ogre::SceneManager *mgr, Ogre::SceneNode *rootSceneNode);
83
98 void createBillboard(const Ogre::Vector3 &position, float xScale = 1.0f, float yScale = 1.0f,
99 const Ogre::ColourValue &color = Ogre::ColourValue::White, Ogre::uint16 texcoordIndexU = 0, Ogre::uint16 texcoordIndexV = 0)
100 {
101 mBillboardBuffer.push_back(new StaticBillboard(position, xScale, yScale, color, texcoordIndexU, texcoordIndexV));
102 }
103
113 void setBillboardOrigin(Ogre::BillboardOrigin origin);
114
117 Ogre::BillboardOrigin getBillboardOrigin() const { return mBBOrigin; }
118
121 void setVisible(bool visible)
122 {
123 if (mVisible != visible)
124 {
125 mVisible = visible;
126 mpSceneNode->setVisible(visible);
127 }
128 }
129
150 void setFade(bool enabled, Ogre::Real visibleDist, Ogre::Real invisibleDist);
151
154 void build();
155
159 void clear();
160
168 void setMaterial(const Ogre::String &materialName, const Ogre::String &resourceGroup =
169 Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
170
182 void setTextureStacksAndSlices(Ogre::uint16 stacks, Ogre::uint16 slices);
183
195 static void updateAll(const Ogre::Vector3 &cameraDirection);
196
197 private:
199 Ogre::MaterialPtr getFadeMaterial(const Ogre::MaterialPtr &protoMaterial, Ogre::Real visibleDist, Ogre::Real invisibleDist);
200
201 private:
202
203 typedef std::vector < StaticBillboard* > TBillBuf;
204
205 bool mVisible;
207
208 Ogre::SceneManager* mpSceneMgr;
209 Ogre::SceneNode* mpSceneNode;
210 Ogre::Entity* mpEntity;
211 Ogre::MeshPtr mPtrMesh;
212 Ogre::String mEntityName;
213 Ogre::MaterialPtr mPtrMaterial;
214 Ogre::MaterialPtr mPtrFadeMaterial;
216
217 Ogre::BillboardOrigin mBBOrigin;
218 Ogre::Real mFadeVisibleDist;
221
222
223 // static data
224 private:
225
226 typedef std::map<Ogre::String, Ogre::MaterialPtr> FadedMaterialMap;
227
228 static bool s_isGLSL;
229 //static bool s_shadersGenerated; ///< First instance generate shaders for billboard rendering
230 static unsigned int s_nSelfInstances;
232
233 //static Ogre::uint32 selfInstances;
234 static unsigned long GUID;
235 static Ogre::String getUniqueID(const Ogre::String &prefix) { return prefix + Ogre::StringConverter::toString(++GUID); }
236 };
237
238
239
240 //-------------------------------------------------------------------------------------
241
242 //SBMaterialRef::addMaterialRef() and ::removeMaterialRef() are used to keep track
243 //of all the materials in use by the billboard system. This is necessary when keeping
244 //the materials' vertex shaders up-to-date. To get the list of all materials in use,
245 //use getList().
247 {
248 public:
249 static void addMaterialRef(const Ogre::MaterialPtr &matP, Ogre::BillboardOrigin o);
250 static void removeMaterialRef(const Ogre::MaterialPtr &matP);
251
252 inline static SBMaterialRefList &getList() { return selfList; }
253
254 inline Ogre::Material *getMaterial() { return material; }
255 inline Ogre::BillboardOrigin getOrigin() { return origin; }
256
257 private:
258 SBMaterialRef(Ogre::Material *mat, Ogre::BillboardOrigin o);
259
261
262 Ogre::uint32 refCount;
263 Ogre::Material *material;
264 Ogre::BillboardOrigin origin;
265 };
266}
267
268#endif
static void removeMaterialRef(const Ogre::MaterialPtr &matP)
static SBMaterialRefList selfList
static SBMaterialRefList & getList()
Ogre::Material * getMaterial()
Ogre::BillboardOrigin origin
Ogre::BillboardOrigin getOrigin()
static void addMaterialRef(const Ogre::MaterialPtr &matP, Ogre::BillboardOrigin o)
StaticBillboard(const Ogre::Vector3 &pos, float xScale, float yScale, const Ogre::ColourValue &clr, Ogre::uint16 texcrdIndexU, Ogre::uint16 texcrdIndexV)
A faster alternative to Ogre's built-in BillboardSet class.
Ogre::BillboardOrigin getBillboardOrigin() const
Returns the current billboard origin.
void setBillboardOrigin(Ogre::BillboardOrigin origin)
Sets the billboard's origin (pivotal point)
Ogre::MaterialPtr getFadeMaterial(const Ogre::MaterialPtr &protoMaterial, Ogre::Real visibleDist, Ogre::Real invisibleDist)
static unsigned int s_nSelfInstances
Instances counter.
void setFade(bool enabled, Ogre::Real visibleDist, Ogre::Real invisibleDist)
Enables/disables distance fade-out for this billboard set.
Ogre::SceneManager * mpSceneMgr
void build()
Performs final steps required for the created billboards to appear in the scene.
void setVisible(bool visible)
Sets whether or not this StaticBillboardSet will be rendered.
static FadedMaterialMap s_mapFadedMaterial
std::map< Ogre::String, Ogre::MaterialPtr > FadedMaterialMap
std::vector< StaticBillboard * > TBillBuf
static Ogre::String getUniqueID(const Ogre::String &prefix)
void setTextureStacksAndSlices(Ogre::uint16 stacks, Ogre::uint16 slices)
Sets how many horizontal slices and vertical stacks the currently applied material is using.
void createBillboard(const Ogre::Vector3 &position, float xScale=1.0f, float yScale=1.0f, const Ogre::ColourValue &color=Ogre::ColourValue::White, Ogre::uint16 texcoordIndexU=0, Ogre::uint16 texcoordIndexV=0)
Adds a billboard to the StaticBillboardSet at the specified position.
void setMaterial(const Ogre::String &materialName, const Ogre::String &resourceGroup=Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME)
Applies a material to the billboards in this set.
Ogre::BillboardOrigin mBBOrigin
void clear()
Deletes all billboards from the scene.
static void updateAll(const Ogre::Vector3 &cameraDirection)
Manually updates all StaticBillboardSet objects for a frame.
std::map< Ogre::Material *, SBMaterialRef * > SBMaterialRefList