Browse Source

Added viewmask parameter to octree queries to avoid manual viewmask checking in View and to allow partial scene queries for logic.
Reordered ray query parameters; added default query parameters to script.
Renamed BeginRender & EndRender events to BeginRendering & EndRendering.

Lasse Öörni 14 years ago
parent
commit
e22483e482

+ 1 - 1
Bin/Data/Scripts/TestScene.as

@@ -447,7 +447,7 @@ void HandlePostRenderUpdate()
     if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
     if (ui.GetElementAt(pos, true) is null && testScene.octree !is null)
     {
     {
         Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
         Ray cameraRay = camera.GetScreenRay(float(pos.x) / graphics.width, float(pos.y) / graphics.height);
-        Array<RayQueryResult> result = testScene.octree.Raycast(cameraRay, DRAWABLE_GEOMETRY, 250.0, RAY_TRIANGLE);
+        Array<RayQueryResult> result = testScene.octree.Raycast(cameraRay, RAY_TRIANGLE, 250.0, DRAWABLE_GEOMETRY);
         if (result.length > 0)
         if (result.length > 0)
         {
         {
             Drawable@ object = result[0].drawable;
             Drawable@ object = result[0].drawable;

+ 6 - 5
Docs/ScriptAPI.dox

@@ -103,6 +103,7 @@
 - uint DRAWABLE_GEOMETRY
 - uint DRAWABLE_GEOMETRY
 - uint DRAWABLE_LIGHT
 - uint DRAWABLE_LIGHT
 - uint DRAWABLE_ZONE
 - uint DRAWABLE_ZONE
+- uint DRAWABLE_ANY
 - uint DEFAULT_VIEWMASK
 - uint DEFAULT_VIEWMASK
 - uint DEFAULT_LIGHTMASK
 - uint DEFAULT_LIGHTMASK
 - int QUALITY_LOW
 - int QUALITY_LOW
@@ -1893,11 +1894,11 @@ Methods:<br>
 - void Remove()
 - void Remove()
 - void Resize(const BoundingBox&, uint)
 - void Resize(const BoundingBox&, uint)
 - void DrawDebugGeometry(bool) const
 - void DrawDebugGeometry(bool) const
-- RayQueryResult[]@ Raycast(const Ray&, uint8, float, RayQueryLevel)
-- Node@[]@ GetDrawables(const Vector3&, uint8)
-- Node@[]@ GetDrawables(const BoundingBox&, uint8)
-- Node@[]@ GetDrawables(const Frustum&, uint8)
-- Node@[]@ GetDrawables(const Sphere&, uint8)
+- RayQueryResult[]@ Raycast(const Ray&, RayQueryLevel arg1 = RAY_TRIANGLE, float arg2 = M_INFINITY, uint8 arg3 = DRAWABLE_ANY, uint arg4 = DEFAULT_VIEWMASK)
+- Node@[]@ GetDrawables(const Vector3&, uint8 arg1 = DRAWABLE_ANY, uint arg2 = DEFAULT_VIEWMASK)
+- Node@[]@ GetDrawables(const BoundingBox&, uint8 arg1 = DRAWABLE_ANY, uint arg2 = DEFAULT_VIEWMASK)
+- Node@[]@ GetDrawables(const Frustum&, uint8 arg1 = DRAWABLE_ANY, uint arg2 = DEFAULT_VIEWMASK)
+- Node@[]@ GetDrawables(const Sphere&, uint8 arg1 = DRAWABLE_ANY, uint arg2 = DEFAULT_VIEWMASK)
 
 
 Properties:<br>
 Properties:<br>
 - ShortStringHash type (readonly)
 - ShortStringHash type (readonly)

+ 6 - 0
Engine/Core/Profiler.cpp

@@ -47,6 +47,7 @@ Profiler::Profiler(Context* context) :
     current_ = root_;
     current_ = root_;
     
     
     SubscribeToEvent(E_BEGINFRAME, HANDLER(Profiler, HandleBeginFrame));
     SubscribeToEvent(E_BEGINFRAME, HANDLER(Profiler, HandleBeginFrame));
+    SubscribeToEvent(E_ENDFRAME, HANDLER(Profiler, HandleEndFrame));
 }
 }
 
 
 Profiler::~Profiler()
 Profiler::~Profiler()
@@ -174,3 +175,8 @@ void Profiler::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
 {
 {
     BeginFrame();
     BeginFrame();
 }
 }
+
+void Profiler::HandleEndFrame(StringHash eventType, VariantMap& eventData)
+{
+    EndFrame();
+}

+ 3 - 1
Engine/Core/Profiler.h

@@ -202,7 +202,7 @@ public:
     
     
     /// Begin the profiling frame. Called by HandleBeginFrame()
     /// Begin the profiling frame. Called by HandleBeginFrame()
     void BeginFrame();
     void BeginFrame();
-    /// End the profiling frame
+    /// End the profiling frame. Called by HandleEndFrame()
     void EndFrame();
     void EndFrame();
     /// Begin a new accumulation period
     /// Begin a new accumulation period
     void ClearAccumulated();
     void ClearAccumulated();
@@ -217,6 +217,8 @@ private:
     void GetData(ProfilerBlock* block, String& output, unsigned indent, bool showUnused, bool showAccumulated, bool showTotal) const;
     void GetData(ProfilerBlock* block, String& output, unsigned indent, bool showUnused, bool showAccumulated, bool showTotal) const;
     /// Handle begin frame event
     /// Handle begin frame event
     void HandleBeginFrame(StringHash eventType, VariantMap& eventData);
     void HandleBeginFrame(StringHash eventType, VariantMap& eventData);
+    /// Handle end frame event
+    void HandleEndFrame(StringHash eventType, VariantMap& eventData);
     
     
     /// Current profiling block
     /// Current profiling block
     ProfilerBlock* current_;
     ProfilerBlock* current_;

+ 16 - 15
Engine/Engine/GraphicsAPI.cpp

@@ -370,6 +370,7 @@ static void RegisterDrawable(asIScriptEngine* engine)
     engine->RegisterGlobalProperty("uint DRAWABLE_GEOMETRY", (void*)&DRAWABLE_GEOMETRY);
     engine->RegisterGlobalProperty("uint DRAWABLE_GEOMETRY", (void*)&DRAWABLE_GEOMETRY);
     engine->RegisterGlobalProperty("uint DRAWABLE_LIGHT", (void*)&DRAWABLE_LIGHT);
     engine->RegisterGlobalProperty("uint DRAWABLE_LIGHT", (void*)&DRAWABLE_LIGHT);
     engine->RegisterGlobalProperty("uint DRAWABLE_ZONE", (void*)&DRAWABLE_ZONE);
     engine->RegisterGlobalProperty("uint DRAWABLE_ZONE", (void*)&DRAWABLE_ZONE);
+    engine->RegisterGlobalProperty("uint DRAWABLE_ANY", (void*)&DRAWABLE_ANY);
     engine->RegisterGlobalProperty("uint DEFAULT_VIEWMASK", (void*)&DEFAULT_VIEWMASK);
     engine->RegisterGlobalProperty("uint DEFAULT_VIEWMASK", (void*)&DEFAULT_VIEWMASK);
     engine->RegisterGlobalProperty("uint DEFAULT_LIGHTMASK", (void*)&DEFAULT_LIGHTMASK);
     engine->RegisterGlobalProperty("uint DEFAULT_LIGHTMASK", (void*)&DEFAULT_LIGHTMASK);
     
     
@@ -854,42 +855,42 @@ static Node* RayQueryResultGetNode(RayQueryResult* ptr)
     return ptr->node_;
     return ptr->node_;
 }
 }
 
 
-static CScriptArray* OctreeRaycast(const Ray& ray, unsigned char drawableFlags, float maxDistance, RayQueryLevel level, Octree* ptr)
+static CScriptArray* OctreeRaycast(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask, Octree* ptr)
 {
 {
     PODVector<RayQueryResult> result;
     PODVector<RayQueryResult> result;
-    RayOctreeQuery query(result, ray, drawableFlags, false, false, maxDistance, level);
+    RayOctreeQuery query(result, ray, level, maxDistance, drawableFlags, viewMask);
     ptr->GetDrawables(query);
     ptr->GetDrawables(query);
     return VectorToArray<RayQueryResult>(result, "Array<RayQueryResult>");
     return VectorToArray<RayQueryResult>(result, "Array<RayQueryResult>");
 }
 }
 
 
-static CScriptArray* OctreeGetDrawablesPoint(const Vector3& point, unsigned char drawableFlags, Octree* ptr)
+static CScriptArray* OctreeGetDrawablesPoint(const Vector3& point, unsigned char drawableFlags, unsigned viewMask, Octree* ptr)
 {
 {
     PODVector<Drawable*> result;
     PODVector<Drawable*> result;
-    PointOctreeQuery query(result, point, drawableFlags);
+    PointOctreeQuery query(result, point, drawableFlags, viewMask);
     ptr->GetDrawables(query);
     ptr->GetDrawables(query);
     return VectorToHandleArray<Drawable>(result, "Array<Drawable@>");
     return VectorToHandleArray<Drawable>(result, "Array<Drawable@>");
 }
 }
 
 
-static CScriptArray* OctreeGetDrawablesBox(const BoundingBox& box, unsigned char drawableFlags, Octree* ptr)
+static CScriptArray* OctreeGetDrawablesBox(const BoundingBox& box, unsigned char drawableFlags, unsigned viewMask, Octree* ptr)
 {
 {
     PODVector<Drawable*> result;
     PODVector<Drawable*> result;
-    BoxOctreeQuery query(result, box, drawableFlags);
+    BoxOctreeQuery query(result, box, drawableFlags, viewMask);
     ptr->GetDrawables(query);
     ptr->GetDrawables(query);
     return VectorToHandleArray<Drawable>(result, "Array<Drawable@>");
     return VectorToHandleArray<Drawable>(result, "Array<Drawable@>");
 }
 }
 
 
-static CScriptArray* OctreeGetDrawablesFrustum(const Frustum& frustum, unsigned char drawableFlags, Octree* ptr)
+static CScriptArray* OctreeGetDrawablesFrustum(const Frustum& frustum, unsigned char drawableFlags, unsigned viewMask, Octree* ptr)
 {
 {
     PODVector<Drawable*> result;
     PODVector<Drawable*> result;
-    FrustumOctreeQuery query(result, frustum, drawableFlags);
+    FrustumOctreeQuery query(result, frustum, drawableFlags, viewMask);
     ptr->GetDrawables(query);
     ptr->GetDrawables(query);
     return VectorToHandleArray<Drawable>(result, "Array<Node@>");
     return VectorToHandleArray<Drawable>(result, "Array<Node@>");
 }
 }
 
 
-static CScriptArray* OctreeGetDrawablesSphere(const Sphere& sphere, unsigned char drawableFlags, Octree* ptr)
+static CScriptArray* OctreeGetDrawablesSphere(const Sphere& sphere, unsigned char drawableFlags, unsigned viewMask, Octree* ptr)
 {
 {
     PODVector<Drawable*> result;
     PODVector<Drawable*> result;
-    SphereOctreeQuery query(result, sphere, drawableFlags);
+    SphereOctreeQuery query(result, sphere, drawableFlags, viewMask);
     ptr->GetDrawables(query);
     ptr->GetDrawables(query);
     return VectorToHandleArray<Drawable>(result, "Array<Node@>");
     return VectorToHandleArray<Drawable>(result, "Array<Node@>");
 }
 }
@@ -923,11 +924,11 @@ static void RegisterOctree(asIScriptEngine* engine)
     RegisterComponent<Octree>(engine, "Octree");
     RegisterComponent<Octree>(engine, "Octree");
     engine->RegisterObjectMethod("Octree", "void Resize(const BoundingBox&in, uint)", asMETHOD(Octree, Resize), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "void Resize(const BoundingBox&in, uint)", asMETHOD(Octree, Resize), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "void DrawDebugGeometry(bool) const", asMETHOD(Octree, DrawDebugGeometry), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "void DrawDebugGeometry(bool) const", asMETHOD(Octree, DrawDebugGeometry), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Octree", "Array<RayQueryResult>@ Raycast(const Ray&in, uint8, float, RayQueryLevel)", asFUNCTION(OctreeRaycast), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const Vector3&in, uint8)", asFUNCTION(OctreeGetDrawablesPoint), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const BoundingBox&in, uint8)", asFUNCTION(OctreeGetDrawablesBox), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const Frustum&in, uint8)", asFUNCTION(OctreeGetDrawablesFrustum), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const Sphere&in, uint8)", asFUNCTION(OctreeGetDrawablesSphere), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Octree", "Array<RayQueryResult>@ Raycast(const Ray&in, RayQueryLevel level = RAY_TRIANGLE, float maxDistance = M_INFINITY, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeRaycast), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const Vector3&in, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeGetDrawablesPoint), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const BoundingBox&in, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeGetDrawablesBox), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const Frustum&in, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeGetDrawablesFrustum), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Octree", "Array<Node@>@ GetDrawables(const Sphere&in, uint8 drawableFlags = DRAWABLE_ANY, uint viewMask = DEFAULT_VIEWMASK)", asFUNCTION(OctreeGetDrawablesSphere), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Octree", "const BoundingBox& get_worldBoundingBox() const", asMETHODPR(Octree, GetWorldBoundingBox, () const, const BoundingBox&), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "const BoundingBox& get_worldBoundingBox() const", asMETHODPR(Octree, GetWorldBoundingBox, () const, const BoundingBox&), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "uint get_numLevels() const", asMETHOD(Octree, GetNumLevels), asCALL_THISCALL);
     engine->RegisterObjectMethod("Octree", "uint get_numLevels() const", asMETHOD(Octree, GetNumLevels), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "Octree@+ get_octree() const", asFUNCTION(SceneGetOctree), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Scene", "Octree@+ get_octree() const", asFUNCTION(SceneGetOctree), asCALL_CDECL_OBJLAST);

+ 2 - 2
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -573,7 +573,7 @@ bool Graphics::BeginFrame()
     numPrimitives_ = 0;
     numPrimitives_ = 0;
     numBatches_ = 0;
     numBatches_ = 0;
     
     
-    SendEvent(E_BEGINRENDER);
+    SendEvent(E_BEGINRENDERING);
     
     
     return true;
     return true;
 }
 }
@@ -585,7 +585,7 @@ void Graphics::EndFrame()
     if (!IsInitialized())
     if (!IsInitialized())
         return;
         return;
     
     
-    SendEvent(E_ENDRENDER);
+    SendEvent(E_ENDRENDERING);
     
     
     // Optionally flush GPU buffer to avoid control lag or framerate fluctuations due to pre-render
     // Optionally flush GPU buffer to avoid control lag or framerate fluctuations due to pre-render
     if (impl_->frameQuery_ && flushGPU_)
     if (impl_->frameQuery_ && flushGPU_)

+ 1 - 0
Engine/Graphics/Drawable.h

@@ -31,6 +31,7 @@
 static const unsigned DRAWABLE_GEOMETRY = 0x1;
 static const unsigned DRAWABLE_GEOMETRY = 0x1;
 static const unsigned DRAWABLE_LIGHT = 0x2;
 static const unsigned DRAWABLE_LIGHT = 0x2;
 static const unsigned DRAWABLE_ZONE = 0x4;
 static const unsigned DRAWABLE_ZONE = 0x4;
+static const unsigned DRAWABLE_ANY = 0xff;
 static const unsigned DEFAULT_VIEWMASK = M_MAX_UNSIGNED;
 static const unsigned DEFAULT_VIEWMASK = M_MAX_UNSIGNED;
 static const unsigned DEFAULT_LIGHTMASK = M_MAX_UNSIGNED;
 static const unsigned DEFAULT_LIGHTMASK = M_MAX_UNSIGNED;
 
 

+ 2 - 2
Engine/Graphics/GraphicsEvents.h

@@ -51,11 +51,11 @@ EVENT(E_SCREENMODE, ScreenMode)
 }
 }
 
 
 /// Frame rendering started
 /// Frame rendering started
-EVENT(E_BEGINRENDER, BeginRender)
+EVENT(E_BEGINRENDERING, BeginRendering)
 {
 {
 }
 }
 
 
 /// Frame rendering ended
 /// Frame rendering ended
-EVENT(E_ENDRENDER, EndRender)
+EVENT(E_ENDRENDERING, EndRendering)
 {
 {
 }
 }

+ 11 - 13
Engine/Graphics/Octree.cpp

@@ -183,13 +183,10 @@ void Octant::GetDrawablesInternal(OctreeQuery& query, bool inside) const
     for (PODVector<Drawable*>::ConstIterator i = drawables_.Begin(); i != drawables_.End(); ++i)
     for (PODVector<Drawable*>::ConstIterator i = drawables_.Begin(); i != drawables_.End(); ++i)
     {
     {
         Drawable* drawable = *i;
         Drawable* drawable = *i;
-        unsigned flags = drawable->GetDrawableFlags();
         
         
-        if (!(flags & query.drawableFlags_) || !drawable->IsVisible())
-            continue;
-        if (query.occludersOnly_ && !drawable->IsOccluder())
-            continue;
-        if (query.shadowCastersOnly_ && !drawable->GetCastShadows())
+        if (!(drawable->GetDrawableFlags() & query.drawableFlags_) || !(drawable->GetViewMask() & query.viewMask_) ||
+            !drawable->IsVisible() || (query.occludersOnly_ && !drawable->IsOccluder()) || (query.shadowCastersOnly_ &&
+            !drawable->GetCastShadows()))
             continue;
             continue;
         
         
         if (query.TestDrawable(drawable->GetWorldBoundingBox(), inside) != OUTSIDE)
         if (query.TestDrawable(drawable->GetWorldBoundingBox(), inside) != OUTSIDE)
@@ -217,11 +214,9 @@ void Octant::GetDrawablesInternal(RayOctreeQuery& query) const
         Drawable* drawable = *i;
         Drawable* drawable = *i;
         unsigned drawableFlags = drawable->GetDrawableFlags();
         unsigned drawableFlags = drawable->GetDrawableFlags();
         
         
-        if (!(drawableFlags & query.drawableFlags_) || !drawable->IsVisible())
-            continue;
-        if (query.occludersOnly_ && !drawable->IsOccluder())
-            continue;
-        if (query.shadowCastersOnly_ && !drawable->GetCastShadows())
+        if (!(drawable->GetDrawableFlags() & query.drawableFlags_) || !(drawable->GetViewMask() & query.viewMask_) ||
+            !drawable->IsVisible() || (query.occludersOnly_ && !drawable->IsOccluder()) || (query.shadowCastersOnly_ &&
+            !drawable->GetCastShadows()))
             continue;
             continue;
         
         
         float drawableDist = drawable->GetWorldBoundingBox().Distance(query.ray_);
         float drawableDist = drawable->GetWorldBoundingBox().Distance(query.ray_);
@@ -281,8 +276,11 @@ void Octree::RegisterObject(Context* context)
 {
 {
     context->RegisterFactory<Octree>();
     context->RegisterFactory<Octree>();
     
     
-    ATTRIBUTE(Octree, VAR_VECTOR3, "Bounding Box Min", worldBoundingBox_.min_, Vector3(-DEFAULT_OCTREE_SIZE, -DEFAULT_OCTREE_SIZE, -DEFAULT_OCTREE_SIZE), AM_DEFAULT);
-    ATTRIBUTE(Octree, VAR_VECTOR3, "Bounding Box Max", worldBoundingBox_.max_, Vector3(DEFAULT_OCTREE_SIZE, DEFAULT_OCTREE_SIZE, DEFAULT_OCTREE_SIZE), AM_DEFAULT);
+    Vector3 defaultBoundsMin = Vector3::UNITY * DEFAULT_OCTREE_SIZE;
+    Vector3 defaultBoundsMax = -Vector3::UNITY * DEFAULT_OCTREE_SIZE;
+    
+    ATTRIBUTE(Octree, VAR_VECTOR3, "Bounding Box Min", worldBoundingBox_.min_, defaultBoundsMin, AM_DEFAULT);
+    ATTRIBUTE(Octree, VAR_VECTOR3, "Bounding Box Max", worldBoundingBox_.max_, defaultBoundsMax, AM_DEFAULT);
     ATTRIBUTE(Octree, VAR_INT, "Number of Levels", numLevels_, DEFAULT_OCTREE_LEVELS, AM_DEFAULT);
     ATTRIBUTE(Octree, VAR_INT, "Number of Levels", numLevels_, DEFAULT_OCTREE_LEVELS, AM_DEFAULT);
 }
 }
 
 

+ 32 - 23
Engine/Graphics/OctreeQuery.h

@@ -24,6 +24,7 @@
 #pragma once
 #pragma once
 
 
 #include "BoundingBox.h"
 #include "BoundingBox.h"
+#include "Drawable.h"
 #include "Frustum.h"
 #include "Frustum.h"
 #include "Ray.h"
 #include "Ray.h"
 #include "Sphere.h"
 #include "Sphere.h"
@@ -37,9 +38,10 @@ class OctreeQuery
 {
 {
 public:
 public:
     /// Construct with result vector, include/exclude flags and whether to get only occluders or shadowcasters
     /// Construct with result vector, include/exclude flags and whether to get only occluders or shadowcasters
-    OctreeQuery(PODVector<Drawable*>& result, unsigned char drawableFlags, bool occludersOnly, bool shadowCastersOnly) :
+    OctreeQuery(PODVector<Drawable*>& result, unsigned char drawableFlags, unsigned viewMask, bool occludersOnly, bool shadowCastersOnly) :
         result_(result),
         result_(result),
         drawableFlags_(drawableFlags),
         drawableFlags_(drawableFlags),
+        viewMask_(viewMask),
         occludersOnly_(occludersOnly),
         occludersOnly_(occludersOnly),
         shadowCastersOnly_(shadowCastersOnly)
         shadowCastersOnly_(shadowCastersOnly)
     {
     {
@@ -59,6 +61,8 @@ public:
     PODVector<Drawable*>& result_;
     PODVector<Drawable*>& result_;
     /// Drawable flags to include
     /// Drawable flags to include
     unsigned char drawableFlags_;
     unsigned char drawableFlags_;
+    /// Drawable layers to include
+    unsigned viewMask_;
     /// Get occluders only flag
     /// Get occluders only flag
     bool occludersOnly_;
     bool occludersOnly_;
     /// Get shadowcasters only flag
     /// Get shadowcasters only flag
@@ -70,9 +74,9 @@ class PointOctreeQuery : public OctreeQuery
 {
 {
 public:
 public:
     /// Construct with point and query parameters
     /// Construct with point and query parameters
-    PointOctreeQuery(PODVector<Drawable*>& result, const Vector3& point, unsigned char drawableFlags, bool occludersOnly = false,
-        bool shadowCastersOnly = false) :
-        OctreeQuery(result, drawableFlags, occludersOnly, shadowCastersOnly),
+    PointOctreeQuery(PODVector<Drawable*>& result, const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY,
+        unsigned viewMask = DEFAULT_VIEWMASK, bool occludersOnly = false, bool shadowCastersOnly = false) :
+        OctreeQuery(result, drawableFlags, viewMask, occludersOnly, shadowCastersOnly),
         point_(point)
         point_(point)
     {
     {
     }
     }
@@ -91,9 +95,9 @@ class SphereOctreeQuery : public OctreeQuery
 {
 {
 public:
 public:
     /// Construct with sphere and query parameters
     /// Construct with sphere and query parameters
-    SphereOctreeQuery(PODVector<Drawable*>& result, const Sphere& sphere, unsigned char drawableFlags, bool occludersOnly = false,
-        bool shadowCastersOnly = false) :
-        OctreeQuery(result, drawableFlags, occludersOnly, shadowCastersOnly),
+    SphereOctreeQuery(PODVector<Drawable*>& result, const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY,
+        unsigned viewMask = DEFAULT_VIEWMASK, bool occludersOnly = false, bool shadowCastersOnly = false) :
+        OctreeQuery(result, drawableFlags, viewMask, occludersOnly, shadowCastersOnly),
         sphere_(sphere)
         sphere_(sphere)
     {
     {
     }
     }
@@ -112,9 +116,9 @@ class BoxOctreeQuery : public OctreeQuery
 {
 {
 public:
 public:
     /// Construct with bounding box and query parameters
     /// Construct with bounding box and query parameters
-    BoxOctreeQuery(PODVector<Drawable*>& result, const BoundingBox& box, unsigned char drawableFlags, bool occludersOnly = false,
-        bool shadowCastersOnly = false) :
-        OctreeQuery(result, drawableFlags, occludersOnly, shadowCastersOnly),
+    BoxOctreeQuery(PODVector<Drawable*>& result, const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY,
+        unsigned viewMask = DEFAULT_VIEWMASK, bool occludersOnly = false, bool shadowCastersOnly = false) :
+        OctreeQuery(result, drawableFlags, viewMask, occludersOnly, shadowCastersOnly),
         box_(box)
         box_(box)
     {
     {
     }
     }
@@ -133,9 +137,9 @@ class FrustumOctreeQuery : public OctreeQuery
 {
 {
 public:
 public:
     /// Construct with frustum and query parameters
     /// Construct with frustum and query parameters
-    FrustumOctreeQuery(PODVector<Drawable*>& result, const Frustum& frustum, unsigned char drawableFlags, bool occludersOnly = false,
-        bool shadowCastersOnly = false) :
-        OctreeQuery(result, drawableFlags, occludersOnly, shadowCastersOnly),
+    FrustumOctreeQuery(PODVector<Drawable*>& result, const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY,
+        unsigned viewMask = DEFAULT_VIEWMASK, bool occludersOnly = false, bool shadowCastersOnly = false) :
+        OctreeQuery(result, drawableFlags, viewMask, occludersOnly, shadowCastersOnly),
         frustum_(frustum)
         frustum_(frustum)
     {
     {
     }
     }
@@ -155,8 +159,9 @@ class OccludedFrustumOctreeQuery : public OctreeQuery
 public:
 public:
     /// Construct with frustum, occlusion buffer pointer and query parameters
     /// Construct with frustum, occlusion buffer pointer and query parameters
     OccludedFrustumOctreeQuery(PODVector<Drawable*>& result, const Frustum& frustum, OcclusionBuffer* buffer,
     OccludedFrustumOctreeQuery(PODVector<Drawable*>& result, const Frustum& frustum, OcclusionBuffer* buffer,
-            unsigned char drawableFlags, bool occludersOnly = false, bool shadowCastersOnly = false) :
-        OctreeQuery(result, drawableFlags, occludersOnly, shadowCastersOnly),
+        unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK, bool occludersOnly = false,
+        bool shadowCastersOnly = false) :
+        OctreeQuery(result, drawableFlags, viewMask, occludersOnly, shadowCastersOnly),
         frustum_(frustum),
         frustum_(frustum),
         buffer_(buffer)
         buffer_(buffer)
     {
     {
@@ -206,24 +211,28 @@ class RayOctreeQuery
 {
 {
 public:
 public:
     /// Construct with ray and query parameters
     /// Construct with ray and query parameters
-    RayOctreeQuery(PODVector<RayQueryResult>& result, const Ray& ray, unsigned char drawableFlags, bool occludersOnly = false,
-        bool shadowCastersOnly = false, float maxDistance = M_INFINITY, RayQueryLevel level = RAY_TRIANGLE) :
-        ray_(ray),
+    RayOctreeQuery(PODVector<RayQueryResult>& result, const Ray& ray, RayQueryLevel level = RAY_TRIANGLE,
+        float maxDistance = M_INFINITY, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK, 
+        bool occludersOnly = false, bool shadowCastersOnly = false) :
         result_(result),
         result_(result),
+        ray_(ray),
+        level_(level),
+        maxDistance_(maxDistance),
         drawableFlags_(drawableFlags),
         drawableFlags_(drawableFlags),
+        viewMask_(viewMask),
         occludersOnly_(occludersOnly),
         occludersOnly_(occludersOnly),
-        shadowCastersOnly_(shadowCastersOnly),
-        maxDistance_(maxDistance),
-        level_(level)
+        shadowCastersOnly_(shadowCastersOnly)
     {
     {
     }
     }
     
     
-    /// Ray
-    Ray ray_;
     /// Result vector reference
     /// Result vector reference
     PODVector<RayQueryResult>& result_;
     PODVector<RayQueryResult>& result_;
+    /// Ray
+    Ray ray_;
     /// Drawable flags to include
     /// Drawable flags to include
     unsigned char drawableFlags_;
     unsigned char drawableFlags_;
+    /// Drawable layers to include
+    unsigned viewMask_;
     /// Get occluders only flag
     /// Get occluders only flag
     bool occludersOnly_;
     bool occludersOnly_;
     /// Get shadowcasters only flag
     /// Get shadowcasters only flag

+ 2 - 2
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -426,7 +426,7 @@ bool Graphics::BeginFrame()
     numPrimitives_ = 0;
     numPrimitives_ = 0;
     numBatches_ = 0;
     numBatches_ = 0;
     
     
-    SendEvent(E_BEGINRENDER);
+    SendEvent(E_BEGINRENDERING);
     
     
     return true;
     return true;
 }
 }
@@ -438,7 +438,7 @@ void Graphics::EndFrame()
     if (!IsInitialized())
     if (!IsInitialized())
         return;
         return;
     
     
-    SendEvent(E_ENDRENDER);
+    SendEvent(E_ENDRENDERING);
     
     
     glfwSwapBuffers();
     glfwSwapBuffers();
 }
 }

+ 19 - 23
Engine/Graphics/View.cpp

@@ -273,7 +273,7 @@ void View::GetDrawables()
     
     
     // Get zones & find the zone camera is in
     // Get zones & find the zone camera is in
     PODVector<Zone*> zones;
     PODVector<Zone*> zones;
-    PointOctreeQuery query(reinterpret_cast<PODVector<Drawable*>& >(zones), cameraPos, DRAWABLE_ZONE);
+    PointOctreeQuery query(reinterpret_cast<PODVector<Drawable*>& >(zones), cameraPos, DRAWABLE_ZONE, camera_->GetViewMask());
     octree_->GetDrawables(query);
     octree_->GetDrawables(query);
     
     
     int highestZonePriority = M_MIN_INT;
     int highestZonePriority = M_MIN_INT;
@@ -293,7 +293,7 @@ void View::GetDrawables()
     
     
     if (maxOccluderTriangles_ > 0)
     if (maxOccluderTriangles_ > 0)
     {
     {
-        FrustumOctreeQuery query(occluders_, camera_->GetFrustum(), DRAWABLE_GEOMETRY, true, false);
+        FrustumOctreeQuery query(occluders_, camera_->GetFrustum(), DRAWABLE_GEOMETRY, camera_->GetViewMask(), true, false);
         
         
         octree_->GetDrawables(query);
         octree_->GetDrawables(query);
         UpdateOccluders(occluders_, camera_);
         UpdateOccluders(occluders_, camera_);
@@ -317,7 +317,8 @@ void View::GetDrawables()
     else
     else
     {
     {
         // Get geometries & lights using occlusion
         // Get geometries & lights using occlusion
-        OccludedFrustumOctreeQuery query(tempDrawables_, camera_->GetFrustum(), buffer, DRAWABLE_GEOMETRY | DRAWABLE_LIGHT);
+        OccludedFrustumOctreeQuery query(tempDrawables_, camera_->GetFrustum(), buffer, DRAWABLE_GEOMETRY | DRAWABLE_LIGHT,
+            camera_->GetViewMask());
         octree_->GetDrawables(query);
         octree_->GetDrawables(query);
     }
     }
     
     
@@ -327,16 +328,10 @@ void View::GetDrawables()
     sceneViewBox_.min_ = sceneViewBox_.max_ = Vector3::ZERO;
     sceneViewBox_.min_ = sceneViewBox_.max_ = Vector3::ZERO;
     sceneViewBox_.defined_ = false;
     sceneViewBox_.defined_ = false;
     Matrix3x4 view(camera_->GetInverseWorldTransform());
     Matrix3x4 view(camera_->GetInverseWorldTransform());
-    unsigned cameraViewMask = camera_->GetViewMask();
     
     
     for (unsigned i = 0; i < tempDrawables_.Size(); ++i)
     for (unsigned i = 0; i < tempDrawables_.Size(); ++i)
     {
     {
         Drawable* drawable = tempDrawables_[i];
         Drawable* drawable = tempDrawables_[i];
-        
-        // Check view mask
-        if (!(cameraViewMask & drawable->GetViewMask()))
-            continue;
-        
         drawable->UpdateDistance(frame_);
         drawable->UpdateDistance(frame_);
         
         
         // If draw distance non-zero, check it
         // If draw distance non-zero, check it
@@ -1010,7 +1005,6 @@ void View::UpdateOccluders(PODVector<Drawable*>& occluders, Camera* camera)
     float halfViewSize = camera->GetHalfViewSize();
     float halfViewSize = camera->GetHalfViewSize();
     float invOrthoSize = 1.0f / camera->GetOrthoSize();
     float invOrthoSize = 1.0f / camera->GetOrthoSize();
     Vector3 cameraPos = camera->GetWorldPosition();
     Vector3 cameraPos = camera->GetWorldPosition();
-    unsigned cameraViewMask = camera->GetViewMask();
     
     
     for (unsigned i = 0; i < occluders.Size(); ++i)
     for (unsigned i = 0; i < occluders.Size(); ++i)
     {
     {
@@ -1018,10 +1012,6 @@ void View::UpdateOccluders(PODVector<Drawable*>& occluders, Camera* camera)
         occluder->UpdateDistance(frame_);
         occluder->UpdateDistance(frame_);
         bool erase = false;
         bool erase = false;
         
         
-        // Check view mask
-        if (!(cameraViewMask & occluder->GetViewMask()))
-            erase = true;
-        
         // Check occluder's draw distance (in main camera view)
         // Check occluder's draw distance (in main camera view)
         float maxDistance = occluder->GetDrawDistance();
         float maxDistance = occluder->GetDrawDistance();
         if (maxDistance > 0.0f && occluder->GetDistance() > maxDistance)
         if (maxDistance > 0.0f && occluder->GetDistance() > maxDistance)
@@ -1127,7 +1117,8 @@ unsigned View::ProcessLight(Light* light)
         SetupShadowCamera(light, true);
         SetupShadowCamera(light, true);
         
         
         // Get occluders, which must be shadow-casting themselves
         // Get occluders, which must be shadow-casting themselves
-        FrustumOctreeQuery query(shadowOccluders_, shadowCamera->GetFrustum(), DRAWABLE_GEOMETRY, true, true);
+        FrustumOctreeQuery query(shadowOccluders_, shadowCamera->GetFrustum(), DRAWABLE_GEOMETRY, camera_->GetViewMask(), true,
+            true);
         octree_->GetDrawables(query);
         octree_->GetDrawables(query);
         
         
         UpdateOccluders(shadowOccluders_, shadowCamera);
         UpdateOccluders(shadowOccluders_, shadowCamera);
@@ -1247,14 +1238,15 @@ unsigned View::ProcessLight(Light* light)
                 if (!useOcclusion)
                 if (!useOcclusion)
                 {
                 {
                     // Get potential shadow casters without occlusion
                     // Get potential shadow casters without occlusion
-                    FrustumOctreeQuery query(tempDrawables_, shadowCamera->GetFrustum(), DRAWABLE_GEOMETRY);
+                    FrustumOctreeQuery query(tempDrawables_, shadowCamera->GetFrustum(), DRAWABLE_GEOMETRY,
+                        camera_->GetViewMask());
                     octree_->GetDrawables(query);
                     octree_->GetDrawables(query);
                 }
                 }
                 else
                 else
                 {
                 {
                     // Get potential shadow casters with occlusion
                     // Get potential shadow casters with occlusion
                     OccludedFrustumOctreeQuery query(tempDrawables_, shadowCamera->GetFrustum(), buffer,
                     OccludedFrustumOctreeQuery query(tempDrawables_, shadowCamera->GetFrustum(), buffer,
-                        DRAWABLE_GEOMETRY);
+                        DRAWABLE_GEOMETRY, camera_->GetViewMask());
                     octree_->GetDrawables(query);
                     octree_->GetDrawables(query);
                 }
                 }
                 
                 
@@ -1264,7 +1256,8 @@ unsigned View::ProcessLight(Light* light)
             
             
         case LIGHT_POINT:
         case LIGHT_POINT:
             {
             {
-                SphereOctreeQuery query(tempDrawables_, Sphere(split->GetWorldPosition(), split->GetRange()), DRAWABLE_GEOMETRY);
+                SphereOctreeQuery query(tempDrawables_, Sphere(split->GetWorldPosition(), split->GetRange()), DRAWABLE_GEOMETRY,
+                    camera_->GetViewMask());
                 octree_->GetDrawables(query);
                 octree_->GetDrawables(query);
                 ProcessLightQuery(i, tempDrawables_, geometryBox, shadowCasterBox, true, false);
                 ProcessLightQuery(i, tempDrawables_, geometryBox, shadowCasterBox, true, false);
             }
             }
@@ -1273,7 +1266,8 @@ unsigned View::ProcessLight(Light* light)
         case LIGHT_SPOT:
         case LIGHT_SPOT:
         case LIGHT_SPLITPOINT:
         case LIGHT_SPLITPOINT:
             {
             {
-                FrustumOctreeQuery query(tempDrawables_, splitLights_[i]->GetFrustum(), DRAWABLE_GEOMETRY);
+                FrustumOctreeQuery query(tempDrawables_, splitLights_[i]->GetFrustum(), DRAWABLE_GEOMETRY,
+                    camera_->GetViewMask());
                 octree_->GetDrawables(query);
                 octree_->GetDrawables(query);
                 ProcessLightQuery(i, tempDrawables_, geometryBox, shadowCasterBox, true, isSplitShadowed);
                 ProcessLightQuery(i, tempDrawables_, geometryBox, shadowCasterBox, true, isSplitShadowed);
             }
             }
@@ -1295,7 +1289,8 @@ unsigned View::ProcessLight(Light* light)
             Camera* shadowCamera = split->GetShadowCamera();
             Camera* shadowCamera = split->GetShadowCamera();
             Texture2D* shadowMap = split->GetShadowMap();
             Texture2D* shadowMap = split->GetShadowMap();
             if (shadowCamera->GetZoom() >= 1.0f)
             if (shadowCamera->GetZoom() >= 1.0f)
-                shadowCamera->SetZoom(shadowCamera->GetZoom() * ((float)(shadowMap->GetWidth() - 2) / (float)shadowMap->GetWidth()));
+                shadowCamera->SetZoom(shadowCamera->GetZoom() * ((float)(shadowMap->GetWidth() - 2) /
+                    (float)shadowMap->GetWidth()));
         }
         }
         
         
         // Update count of total lit geometries & shadow casters
         // Update count of total lit geometries & shadow casters
@@ -1359,8 +1354,8 @@ void View::ProcessLightQuery(unsigned splitIndex, const PODVector<Drawable*>& re
         if (light->GetLightType() != LIGHT_DIRECTIONAL)
         if (light->GetLightType() != LIGHT_DIRECTIONAL)
             lightViewFrustum = camera_->GetSplitFrustum(sceneViewBox_.min_.z_, sceneViewBox_.max_.z_).Transformed(lightView);
             lightViewFrustum = camera_->GetSplitFrustum(sceneViewBox_.min_.z_, sceneViewBox_.max_.z_).Transformed(lightView);
         else
         else
-            lightViewFrustum = camera_->GetSplitFrustum(Max(sceneViewBox_.min_.z_, light->GetNearSplit() - light->GetNearFadeRange()),
-                Min(sceneViewBox_.max_.z_, light->GetFarSplit())).Transformed(lightView);
+            lightViewFrustum = camera_->GetSplitFrustum(Max(sceneViewBox_.min_.z_, light->GetNearSplit() - 
+                light->GetNearFadeRange()), Min(sceneViewBox_.max_.z_, light->GetFarSplit())).Transformed(lightView);
         lightViewFrustumBox.Define(lightViewFrustum);
         lightViewFrustumBox.Define(lightViewFrustum);
         
         
         // Check for degenerate split frustum: in that case there is no need to get shadow casters
         // Check for degenerate split frustum: in that case there is no need to get shadow casters
@@ -1554,7 +1549,8 @@ void View::SetupShadowCamera(Light* light, bool shadowOcclusion)
             if (light->GetLightType() == LIGHT_SPOT && parameters.zoomOut_)
             if (light->GetLightType() == LIGHT_SPOT && parameters.zoomOut_)
             {
             {
                 // Make sure the out-zooming does not start while we are inside the spot
                 // Make sure the out-zooming does not start while we are inside the spot
-                float distance = Max((camera_->GetInverseWorldTransform() * light->GetWorldPosition()).z_ - light->GetRange(), 1.0f);
+                float distance = Max((camera_->GetInverseWorldTransform() * light->GetWorldPosition()).z_ - light->GetRange(),
+                    1.0f);
                 float lightPixels = (((float)height_ * light->GetRange() * camera_->GetZoom() * 0.5f) / distance);
                 float lightPixels = (((float)height_ * light->GetRange() * camera_->GetZoom() * 0.5f) / distance);
                 
                 
                 // Clamp pixel amount to a sufficient minimum to avoid self-shadowing artifacts due to loss of precision
                 // Clamp pixel amount to a sufficient minimum to avoid self-shadowing artifacts due to loss of precision