Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Actor.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #include <vlGraphics/Actor.hpp>
33 
34 using namespace vl;
35 
36 //-----------------------------------------------------------------------------
37 // Actor
38 //-----------------------------------------------------------------------------
40 {
43 }
44 //-----------------------------------------------------------------------------
45 void Actor::setLODs(Renderable* lod0, Renderable* lod1, Renderable* lod2, Renderable* lod3, Renderable* lod4, Renderable* lod5)
46 {
47  if (lod0) { VL_CHECK(0<VL_MAX_ACTOR_LOD) setLod(0,lod0); }
48  if (lod1) { VL_CHECK(1<VL_MAX_ACTOR_LOD) setLod(1,lod1); }
49  if (lod2) { VL_CHECK(2<VL_MAX_ACTOR_LOD) setLod(2,lod2); }
50  if (lod3) { VL_CHECK(3<VL_MAX_ACTOR_LOD) setLod(3,lod3); }
51  if (lod4) { VL_CHECK(4<VL_MAX_ACTOR_LOD) setLod(4,lod4); }
52  if (lod5) { VL_CHECK(5<VL_MAX_ACTOR_LOD) setLod(5,lod5); }
53 }
54 //-----------------------------------------------------------------------------
56 {
57  if (mLODEvaluator)
58  return mLODEvaluator->evaluate(this, camera);
59  else
60  return 0;
61 }
62 //-----------------------------------------------------------------------------
64 {
65  VL_CHECK_OGL();
67  glGenQueries(1, &mOcclusionQuery);
68  VL_CHECK_OGL();
70 }
71 //-----------------------------------------------------------------------------
73 {
75  {
76  if (mOcclusionQuery)
77  {
78  glDeleteQueries(1, &mOcclusionQuery);
79  mOcclusionQuery = 0;
80  }
81  }
82 }
83 //-----------------------------------------------------------------------------
84 bool Actor::boundsDirty() const
85 {
86  // (1) renderable dirty or we're not up to date with the renderable.
87  bool dirty = lod(0)->boundsDirty() || lod(0)->boundsUpdateTick() != mBoundsUpdateTick;
88 
89  // (2) we're not not up to date with the transform.
91 
92  return dirty;
93 }
94 //-----------------------------------------------------------------------------
96 {
97  if ( ! lod(0) ) {
98  return;
99  }
100 
101  bool geom_update = lod(0)->boundsDirty() || lod(0)->boundsUpdateTick() != mBoundsUpdateTick;
102 
103  if ( transform() && ( geom_update || transform()->worldMatrixUpdateTick() != mTransformUpdateTick ) )
104  {
105  lod(0)->boundingBox().transformed( mAABB, transform()->worldMatrix() );
107  mSphere = mAABB.isNull() ? Sphere() : mAABB;
109  }
110  else
111  if (geom_update)
112  {
113  mAABB = lod(0)->boundingBox();
114  mSphere = mAABB.isNull() ? Sphere() : mAABB;
116  }
117 }
118 //-----------------------------------------------------------------------------
119 void Actor::setUniform(Uniform* uniform) { gocUniformSet()->setUniform(uniform); }
120 //-----------------------------------------------------------------------------
121 const std::vector< ref<Uniform> >& Actor::uniforms() const { return getUniformSet()->uniforms(); }
122 //-----------------------------------------------------------------------------
123 std::vector< ref<Uniform> >& Actor::uniforms() { return gocUniformSet()->uniforms(); }
124 //-----------------------------------------------------------------------------
125 void Actor::eraseUniform(const char* name) { if(getUniformSet()) getUniformSet()->eraseUniform(name); }
126 //-----------------------------------------------------------------------------
127 void Actor::eraseUniform(const Uniform* uniform) { if(getUniformSet()) getUniformSet()->eraseUniform(uniform); }
128 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
131 Uniform* Actor::gocUniform(const char* name) { return gocUniformSet()->gocUniform(name); }
132 //-----------------------------------------------------------------------------
133 Uniform* Actor::getUniform(const char* name) { if (getUniformSet()) return getUniformSet()->getUniform(name); else return NULL; }
134 //-----------------------------------------------------------------------------
135 const Uniform* Actor::getUniform(const char* name) const { if (getUniformSet()) return getUniformSet()->getUniform(name); else return NULL; }
136 //-----------------------------------------------------------------------------
const Renderable * lod(int lod_index) const
Returns the Renderable object representing the LOD level specifed by lod_index.
Definition: Actor.hpp:173
Wraps an OpenGL Shading Language uniform to be associated to a GLSLProgram (see vl::GLSLProgram docum...
Definition: Uniform.hpp:59
Uniform * getUniform(const char *name)
Equivalent to getUniformSet()->getUniform(name, get_mode)
Definition: Actor.cpp:133
GLuint mOcclusionQuery
Definition: Actor.hpp:472
const std::vector< ref< Uniform > > & uniforms() const
Equivalent to getUniformSet()->uniforms()
Definition: Actor.cpp:121
Transform * transform()
Returns the Transform bound tho an Actor.
Definition: Actor.hpp:190
int evaluateLOD(Camera *camera)
Definition: Actor.cpp:55
Uniform * gocUniform(const char *name)
Definition: UniformSet.cpp:84
bool isNull() const
Returns true if the AABB is null.
Definition: AABB.hpp:60
void setUniform(Uniform *uniform, bool check_for_doubles=true)
Definition: UniformSet.cpp:45
virtual ~Actor()
Destructor.
Definition: Actor.cpp:39
long long mTransformUpdateTick
Definition: Actor.hpp:469
long long worldMatrixUpdateTick() const
Returns the internal update tick used to avoid unnecessary computations.
Definition: Transform.hpp:184
bool boundsDirty() const
Returns whether the bounding sphere or bounding box are "dirty", that is, meant to be recomputed...
Definition: Renderable.hpp:130
void eraseAllUniforms()
Definition: UniformSet.hpp:76
bool boundsDirty() const
Returns whether the Actor&#39;s bounding box and sphere are up to date.
Definition: Actor.cpp:84
void eraseUniform(const char *name)
Definition: UniformSet.cpp:64
AABB mAABB
Definition: Actor.hpp:458
UniformSet * gocUniformSet()
Creates and/or returns the installed UniformSet.
Definition: Actor.hpp:367
void dispatchOnActorDelete()
Calls all the onActorDelete() of all the ActorEventCallback installed on this Actor.
Definition: Actor.hpp:387
const UniformSet * getUniformSet() const
Returns the installed UniformSet.
Definition: Actor.hpp:345
const std::vector< ref< Uniform > > & uniforms() const
Definition: UniformSet.hpp:68
void createOcclusionQuery()
For internal use only.
Definition: Actor.cpp:63
void eraseAllUniforms()
Equivalent to getUniformSet()->eraseAllUniforms()
Definition: Actor.cpp:129
Visualization Library main namespace.
Sphere mSphere
Definition: Actor.hpp:459
long long mBoundsUpdateTick
Definition: Actor.hpp:470
void transformed(AABB &out, const mat4 &mat) const
Transforms an AABB by the given matrix and returns it into the out parameter.
Definition: AABB.hpp:165
An abstract class that represents all the objects that can be rendered.
Definition: Renderable.hpp:58
bool Has_Occlusion_Query
Definition: OpenGL.cpp:94
void setUniform(Uniform *uniform)
Equivalent to getUniformSet()->setUniform(uniform)
Definition: Actor.cpp:119
void deleteOcclusionQuery()
For internal use only.
Definition: Actor.cpp:72
#define NULL
Definition: OpenGLDefs.hpp:81
The Sphere class defines a sphere using a center and a radius using vl::real precision.
Definition: Sphere.hpp:43
void setLODs(Renderable *lod0, Renderable *lod1=NULL, Renderable *lod2=NULL, Renderable *lod3=NULL, Renderable *lod4=NULL, Renderable *lod5=NULL)
Utility function to assign one or more Renderable[s] to one or more LOD levels.
Definition: Actor.cpp:45
Uniform * gocUniform(const char *name)
Equivalent to getUniformSet()->getUniform(name, get_mode)
Definition: Actor.cpp:131
Uniform * getUniform(const char *name)
Definition: UniformSet.cpp:95
#define VL_CHECK_OGL()
Definition: OpenGL.hpp:156
void computeBounds()
Computes the bounding box and bounding sphere of an Actor if boundsDirty().
Definition: Actor.cpp:95
void setLod(int lod_index, Renderable *renderable)
Sets the Renderable object representing the LOD level specifed by lod_index.
Definition: Actor.hpp:159
void eraseUniform(const char *name)
Equivalent to getUniformSet()->eraseUniform(name)
Definition: Actor.cpp:125
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:49
const AABB & boundingBox() const
Returns the bounding box of a Renderable without recomputing the bounds if dirty. ...
Definition: Renderable.hpp:155
ref< LODEvaluator > mLODEvaluator
Definition: Actor.hpp:463
#define VL_CHECK(expr)
Definition: checks.hpp:73
long long boundsUpdateTick() const
Returns the bounds-update-tick which is a counter incremented every time the bounding box or bounding...
Definition: Renderable.hpp:124