瀏覽代碼

Removed the light to light queue map. Instead store the light queue pointer directly to the light.

Lasse Öörni 13 年之前
父節點
當前提交
139ef6d6e2

+ 1 - 1
Engine/Core/Signal.h

@@ -33,7 +33,7 @@ public:
     /// Destruct.
     /// Destruct.
     ~Signal();
     ~Signal();
     
     
-    /// Set the signal. Will be automatically reset once a waiting thread wakes up.
+    /// %Set the signal. Will be automatically reset once a waiting thread wakes up.
     void Set();
     void Set();
     
     
     /// Wait on the signal.
     /// Wait on the signal.

+ 1 - 1
Engine/Graphics/Direct3D9/D3D9RenderSurface.h

@@ -40,7 +40,7 @@ public:
     /// Destruct.
     /// Destruct.
     ~RenderSurface();
     ~RenderSurface();
     
     
-    /// Set viewport for auxiliary view rendering.
+    /// %Set viewport for auxiliary view rendering.
     void SetViewport(Viewport* viewport);
     void SetViewport(Viewport* viewport);
     /// %Set linked color rendertarget.
     /// %Set linked color rendertarget.
     void SetLinkedRenderTarget(RenderSurface* renderTarget);
     void SetLinkedRenderTarget(RenderSurface* renderTarget);

+ 11 - 5
Engine/Graphics/Light.cpp

@@ -82,19 +82,20 @@ OBJECTTYPESTATIC(Light);
 Light::Light(Context* context) :
 Light::Light(Context* context) :
     Drawable(context),
     Drawable(context),
     lightType_(DEFAULT_LIGHTTYPE),
     lightType_(DEFAULT_LIGHTTYPE),
-    perVertex_(false),
+    shadowBias_(BiasParameters(DEFAULT_CONSTANTBIAS, DEFAULT_SLOPESCALEDBIAS)),
+    shadowCascade_(CascadeParameters(M_LARGE_VALUE, 0.0f, 0.0f, 0.0f, DEFAULT_SHADOWFADESTART)),
+    shadowFocus_(FocusParameters(true, true, true, DEFAULT_SHADOWQUANTIZE, DEFAULT_SHADOWMINVIEW)),
+    lightQueue_(0),
     specularIntensity_(0.0f),
     specularIntensity_(0.0f),
     range_(DEFAULT_RANGE),
     range_(DEFAULT_RANGE),
     fov_(DEFAULT_FOV),
     fov_(DEFAULT_FOV),
     aspectRatio_(1.0f),
     aspectRatio_(1.0f),
     fadeDistance_(0.0f),
     fadeDistance_(0.0f),
     shadowFadeDistance_(0.0f),
     shadowFadeDistance_(0.0f),
-    shadowBias_(BiasParameters(DEFAULT_CONSTANTBIAS, DEFAULT_SLOPESCALEDBIAS)),
-    shadowCascade_(CascadeParameters(M_LARGE_VALUE, 0.0f, 0.0f, 0.0f, DEFAULT_SHADOWFADESTART)),
-    shadowFocus_(FocusParameters(true, true, true, DEFAULT_SHADOWQUANTIZE, DEFAULT_SHADOWMINVIEW)),
     shadowIntensity_(0.0f),
     shadowIntensity_(0.0f),
     shadowResolution_(1.0f),
     shadowResolution_(1.0f),
-    shadowNearFarRatio_(DEFAULT_SHADOWNEARFARRATIO)
+    shadowNearFarRatio_(DEFAULT_SHADOWNEARFARRATIO),
+    perVertex_(false)
 {
 {
     drawableFlags_ =  DRAWABLE_LIGHT;
     drawableFlags_ =  DRAWABLE_LIGHT;
 }
 }
@@ -521,3 +522,8 @@ void Light::SetIntensitySortValue(const BoundingBox& box)
         break;
         break;
     }
     }
 }
 }
+
+void Light::SetLightQueue(LightBatchQueue* queue)
+{
+    lightQueue_ = queue;
+}

+ 21 - 14
Engine/Graphics/Light.h

@@ -31,6 +31,7 @@ class Camera;
 class Texture;
 class Texture;
 class Texture2D;
 class Texture2D;
 class TextureCube;
 class TextureCube;
+struct LightBatchQueue;
 
 
 /// %Light types.
 /// %Light types.
 enum LightType
 enum LightType
@@ -241,10 +242,14 @@ public:
     void SetIntensitySortValue(float distance);
     void SetIntensitySortValue(float distance);
     /// %Set sort value based on overall intensity over a bounding box.
     /// %Set sort value based on overall intensity over a bounding box.
     void SetIntensitySortValue(const BoundingBox& box);
     void SetIntensitySortValue(const BoundingBox& box);
+    /// %Set light queue used for this light. Called by View.
+    void SetLightQueue(LightBatchQueue* queue);
     /// Return directional light quad transform for either near or far split.
     /// Return directional light quad transform for either near or far split.
     Matrix3x4 GetDirLightTransform(Camera* camera, bool getNearQuad = false);
     Matrix3x4 GetDirLightTransform(Camera* camera, bool getNearQuad = false);
     /// Return light volume model transform.
     /// Return light volume model transform.
     const Matrix3x4& GetVolumeTransform(Camera* camera);
     const Matrix3x4& GetVolumeTransform(Camera* camera);
+    /// Return light queue. Called by View.
+    LightBatchQueue* GetLightQueue() const { return lightQueue_; }
     
     
     /// %Set ramp texture attribute.
     /// %Set ramp texture attribute.
     void SetRampTextureAttr(ResourceRef value);
     void SetRampTextureAttr(ResourceRef value);
@@ -262,10 +267,22 @@ protected:
 private:
 private:
     /// Light type.
     /// Light type.
     LightType lightType_;
     LightType lightType_;
-    /// Per-vertex lighting flag.
-    bool perVertex_;
     /// Color.
     /// Color.
     Color color_;
     Color color_;
+    /// Shadow depth bias parameters.
+    BiasParameters shadowBias_;
+    /// Directional light cascaded shadow parameters.
+    CascadeParameters shadowCascade_;
+    /// Shadow map focus parameters.
+    FocusParameters shadowFocus_;
+    /// Custom world transform for the light volume.
+    Matrix3x4 volumeTransform_;
+    /// Range attenuation texture.
+    SharedPtr<Texture> rampTexture_;
+    /// Spotlight attenuation texture.
+    SharedPtr<Texture> shapeTexture_;
+    /// Light queue.
+    LightBatchQueue* lightQueue_;
     /// Specular intensity.
     /// Specular intensity.
     float specularIntensity_;
     float specularIntensity_;
     /// Range.
     /// Range.
@@ -278,22 +295,12 @@ private:
     float fadeDistance_;
     float fadeDistance_;
     /// Shadow fade start distance.
     /// Shadow fade start distance.
     float shadowFadeDistance_;
     float shadowFadeDistance_;
-    /// Shadow depth bias parameters.
-    BiasParameters shadowBias_;
-    /// Directional light cascaded shadow parameters.
-    CascadeParameters shadowCascade_;
-    /// Shadow map focus parameters.
-    FocusParameters shadowFocus_;
-    /// Custom world transform for the light volume.
-    Matrix3x4 volumeTransform_;
     /// Shadow intensity.
     /// Shadow intensity.
     float shadowIntensity_;
     float shadowIntensity_;
     /// Shadow resolution.
     /// Shadow resolution.
     float shadowResolution_;
     float shadowResolution_;
     /// Shadow camera near/far clip distance ratio.
     /// Shadow camera near/far clip distance ratio.
     float shadowNearFarRatio_;
     float shadowNearFarRatio_;
-    /// Range attenuation texture.
-    SharedPtr<Texture> rampTexture_;
-    /// Spotlight attenuation texture.
-    SharedPtr<Texture> shapeTexture_;
+    /// Per-vertex lighting flag.
+    bool perVertex_;
 };
 };

+ 2 - 2
Engine/Graphics/PostProcess.h

@@ -110,7 +110,7 @@ public:
     
     
     /// Load parameters from an XML file. Return true if successful.
     /// Load parameters from an XML file. Return true if successful.
     bool LoadParameters(XMLFile* file);
     bool LoadParameters(XMLFile* file);
-    /// Set number of passes.
+    /// %Set number of passes.
     void SetNumPasses(unsigned passes);
     void SetNumPasses(unsigned passes);
     /// Create a rendertarget. Width and height are either absolute pixels or viewport size divisors. Return true if successful.
     /// Create a rendertarget. Width and height are either absolute pixels or viewport size divisors. Return true if successful.
     bool CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool sizeDivisor, bool filtered);
     bool CreateRenderTarget(const String& name, unsigned width, unsigned height, unsigned format, bool sizeDivisor, bool filtered);
@@ -120,7 +120,7 @@ public:
     void SetShaderParameter(const String& name, const Vector4& value);
     void SetShaderParameter(const String& name, const Vector4& value);
     /// Remove global shader parameter.
     /// Remove global shader parameter.
     void RemoveShaderParameter(const String& name);
     void RemoveShaderParameter(const String& name);
-    /// Set active flag.
+    /// %Set active flag.
     void SetActive(bool active);
     void SetActive(bool active);
     /// Clone the post-process.
     /// Clone the post-process.
     SharedPtr<PostProcess> Clone();
     SharedPtr<PostProcess> Clone();

+ 1 - 1
Engine/Graphics/Renderer.h

@@ -307,7 +307,7 @@ public:
     void SetBatchShaders(Batch& batch, Technique* technique, Pass* pass, bool allowShadows = true);
     void SetBatchShaders(Batch& batch, Technique* technique, Pass* pass, bool allowShadows = true);
     /// Choose shaders for a light volume batch.
     /// Choose shaders for a light volume batch.
     void SetLightVolumeBatchShaders(Batch& batch);
     void SetLightVolumeBatchShaders(Batch& batch);
-    /// Set cull mode while taking possible projection flipping into account.
+    /// %Set cull mode while taking possible projection flipping into account.
     void SetCullMode(CullMode mode, Camera* camera);
     void SetCullMode(CullMode mode, Camera* camera);
     /// Ensure sufficient size of the instancing vertex buffer. Return true if successful.
     /// Ensure sufficient size of the instancing vertex buffer. Return true if successful.
     bool ResizeInstancingBuffer(unsigned numInstances);
     bool ResizeInstancingBuffer(unsigned numInstances);

+ 5 - 5
Engine/Graphics/View.cpp

@@ -651,6 +651,7 @@ void View::GetDrawables()
     {
     {
         Light* light = lights_[i];
         Light* light = lights_[i];
         light->SetIntensitySortValue(camera_->GetDistance(light->GetWorldPosition()));
         light->SetIntensitySortValue(camera_->GetDistance(light->GetWorldPosition()));
+        light->SetLightQueue(0);
     }
     }
     
     
     Sort(lights_.Begin(), lights_.End(), CompareDrawables);
     Sort(lights_.Begin(), lights_.End(), CompareDrawables);
@@ -687,7 +688,6 @@ void View::GetBatches()
     // Build light queues and lit batches
     // Build light queues and lit batches
     {
     {
         maxLightsDrawables_.Clear();
         maxLightsDrawables_.Clear();
-        lightQueueMapping_.Clear();
         
         
         // Preallocate light queues: per-pixel lights which have lit geometries
         // Preallocate light queues: per-pixel lights which have lit geometries
         unsigned numLightQueues = 0;
         unsigned numLightQueues = 0;
@@ -719,7 +719,7 @@ void View::GetBatches()
                 
                 
                 // Initialize light queue. Store light-to-queue mapping so that the queue can be found later
                 // Initialize light queue. Store light-to-queue mapping so that the queue can be found later
                 LightBatchQueue& lightQueue = lightQueues_[usedLightQueues++];
                 LightBatchQueue& lightQueue = lightQueues_[usedLightQueues++];
-                lightQueueMapping_[light] = &lightQueue;
+                light->SetLightQueue(&lightQueue);
                 lightQueue.light_ = light;
                 lightQueue.light_ = light;
                 lightQueue.litBatches_.Clear();
                 lightQueue.litBatches_.Clear();
                 lightQueue.volumeBatches_.Clear();
                 lightQueue.volumeBatches_.Clear();
@@ -844,9 +844,9 @@ void View::GetBatches()
             {
             {
                 Light* light = lights[i];
                 Light* light = lights[i];
                 // Find the correct light queue again
                 // Find the correct light queue again
-                Map<Light*, LightBatchQueue*>::Iterator j = lightQueueMapping_.Find(light);
-                if (j != lightQueueMapping_.End())
-                    GetLitBatches(drawable, *(j->second_));
+                LightBatchQueue* queue = light->GetLightQueue();
+                if (queue)
+                    GetLitBatches(drawable, *queue);
             }
             }
         }
         }
     }
     }

+ 0 - 2
Engine/Graphics/View.h

@@ -242,8 +242,6 @@ private:
     PODVector<Light*> lights_;
     PODVector<Light*> lights_;
     /// Drawables that limit their maximum light count.
     /// Drawables that limit their maximum light count.
     HashSet<Drawable*> maxLightsDrawables_;
     HashSet<Drawable*> maxLightsDrawables_;
-    /// Lookup map for the processed lights' light queues.
-    Map<Light*, LightBatchQueue*> lightQueueMapping_;
     /// Base pass batches.
     /// Base pass batches.
     BatchQueue baseQueue_;
     BatchQueue baseQueue_;
     /// Pre-transparent pass batches.
     /// Pre-transparent pass batches.

+ 3 - 3
Engine/Graphics/Viewport.h

@@ -47,11 +47,11 @@ public:
     /// Destruct.
     /// Destruct.
     ~Viewport();
     ~Viewport();
     
     
-    /// Set scene.
+    /// %Set scene.
     void SetScene(Scene* scene);
     void SetScene(Scene* scene);
-    /// Set camera.
+    /// %Set camera.
     void SetCamera(Camera* camera);
     void SetCamera(Camera* camera);
-    /// Set rectangle.
+    /// %Set rectangle.
     void SetRect(const IntRect& rect);
     void SetRect(const IntRect& rect);
     /// Add a post-processing effect at the end of the chain.
     /// Add a post-processing effect at the end of the chain.
     void AddPostProcess(PostProcess* effect);
     void AddPostProcess(PostProcess* effect);

+ 2 - 2
Engine/Math/Polyhedron.h

@@ -101,9 +101,9 @@ public:
     Vector<Vector<Vector3> > faces_;
     Vector<Vector<Vector3> > faces_;
     
     
 private:
 private:
-    /// Set a triangle face by index.
+    /// %Set a triangle face by index.
     void SetFace(unsigned index, const Vector3& v0, const Vector3& v1, const Vector3& v2);
     void SetFace(unsigned index, const Vector3& v0, const Vector3& v1, const Vector3& v2);
-    /// Set a quadrilateral face by index.
+    /// %Set a quadrilateral face by index.
     void SetFace(unsigned index, const Vector3& v0, const Vector3& v1, const Vector3& v2, const Vector3& v3);
     void SetFace(unsigned index, const Vector3& v0, const Vector3& v1, const Vector3& v2, const Vector3& v3);
     /// Internal vector for clipped vertices.
     /// Internal vector for clipped vertices.
     Vector<Vector3> clippedVertices_;
     Vector<Vector3> clippedVertices_;

+ 2 - 2
Engine/Math/Random.h

@@ -23,9 +23,9 @@
 
 
 #pragma once
 #pragma once
 
 
-/// Set the random seed. The default seed is 1.
+/// %Set the random seed. The default seed is 1.
 void SetRandomSeed(unsigned seed);
 void SetRandomSeed(unsigned seed);
 /// Return the current random seed.
 /// Return the current random seed.
 unsigned GetRandomSeed();
 unsigned GetRandomSeed();
-/// Internal random generation function, which should operate similarly to MSVC rand().
+/// Return a random number between 0-32767. Should operate similarly to MSVC rand().
 int Rand();
 int Rand();

+ 1 - 1
Engine/Scene/Scene.h

@@ -160,7 +160,7 @@ public:
     void ComponentAdded(Component* component);
     void ComponentAdded(Component* component);
     /// Component removed. Remove from ID map.
     /// Component removed. Remove from ID map.
     void ComponentRemoved(Component* component);
     void ComponentRemoved(Component* component);
-    /// Set node user variable reverse mappings.
+    /// %Set node user variable reverse mappings.
     void SetVarNamesAttr(String value);
     void SetVarNamesAttr(String value);
     /// Return node user variable reverse mappings.
     /// Return node user variable reverse mappings.
     String GetVarNamesAttr() const;
     String GetVarNamesAttr() const;