ソースを参照

Comments cleanup and Batch refactoring.

Lasse Öörni 13 年 前
コミット
d62812df86

+ 2 - 2
Engine/Graphics/AnimatedModel.h

@@ -56,11 +56,11 @@ public:
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
     /// Update before octree reinsertion. Animation is updated here.
     virtual void Update(const FrameInfo& frame);
-    /// Calculate distance and update batches for rendering. May be called from worker thread(s), possibly re-entrantly.
+    /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateBatches(const FrameInfo& frame);
     /// Prepare geometry for rendering. Called from a worker thread if possible (no GPU update.)
     virtual void UpdateGeometry(const FrameInfo& frame);
-    /// Return whether a geometry update is necessary, and if it should happen in a worker thread.
+    /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
     virtual UpdateGeometryType GetUpdateGeometryType();
     /// Add debug geometry to the debug renderer.
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);

+ 15 - 13
Engine/Graphics/Batch.h

@@ -55,17 +55,19 @@ struct Batch
     {
     }
     
-    /// Assign from a drawable's source data.
-    void CopyFrom(const SourceBatch& rhs)
+    /// Construct from a drawable's source batch.
+    Batch(const SourceBatch& rhs) :
+        distance_(rhs.distance_),
+        geometry_(rhs.geometry_),
+        material_(rhs.material_),
+        worldTransform_(rhs.worldTransform_),
+        lightQueue_(0),
+        shaderData_(rhs.shaderData_),
+        shaderDataSize_(rhs.shaderDataSize_),
+        geometryType_(rhs.geometryType_),
+        overrideView_(rhs.overrideView_),
+        isBase_(false)
     {
-        distance_ = rhs.distance_;
-        geometry_ = rhs.geometry_;
-        material_ = rhs.material_;
-        worldTransform_  = rhs.worldTransform_;
-        shaderData_ = rhs.shaderData_;
-        shaderDataSize_ = rhs.shaderDataSize_;
-        geometryType_ = rhs.geometryType_;
-        overrideView_ = rhs.overrideView_;
     }
     
     /// Calculate state sorting key, which consists of base pass flag, light, pass and geometry.
@@ -83,7 +85,7 @@ struct Batch
     Geometry* geometry_;
     /// Material.
     Material* material_;
-    /// Model world transform.
+    /// %Object's world transform.
     const Matrix3x4* worldTransform_;
     /// Camera.
     Camera* camera_;
@@ -101,7 +103,7 @@ struct Batch
     const float* shaderData_;
     /// Vertex shader data size in floats.
     unsigned shaderDataSize_;
-    /// Geometry type.
+    /// %Geometry type.
     GeometryType geometryType_;
     /// Override view transform flag.
     bool overrideView_;
@@ -164,7 +166,7 @@ struct BatchGroup : public Batch
     unsigned startIndex_;
 };
 
-/// Instanced draw call key.
+/// Instanced draw call grouping key.
 struct BatchGroupKey
 {
     /// Construct undefined.

+ 2 - 2
Engine/Graphics/BillboardSet.h

@@ -63,11 +63,11 @@ public:
     /// Register object factory.
     static void RegisterObject(Context* context);
     
-    /// Calculate distance and update batches for rendering. May be called from worker thread(s), possibly re-entrantly.
+    /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateBatches(const FrameInfo& frame);
     /// Prepare geometry for rendering. Called from a worker thread if possible (no GPU update.)
     virtual void UpdateGeometry(const FrameInfo& frame);
-    /// Return whether a geometry update is necessary, and if it should happen in a worker thread.
+    /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
     virtual UpdateGeometryType GetUpdateGeometryType();
     
     /// %Set material.

+ 4 - 4
Engine/Graphics/Drawable.h

@@ -94,13 +94,13 @@ struct SourceBatch
     SharedPtr<Geometry> geometry_;
     /// Material.
     SharedPtr<Material> material_;
-    /// Model world transform.
+    /// %Object's world transform.
     const Matrix3x4* worldTransform_;
     /// Vertex shader data.
     const float* shaderData_;
     /// Vertex shader data size in floats.
     unsigned shaderDataSize_;
-    /// Geometry type.
+    /// %Geometry type.
     GeometryType geometryType_;
     /// Override view transform flag.
     bool overrideView_;
@@ -127,11 +127,11 @@ public:
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
     /// Update before octree reinsertion. Is called from a worker thread. Needs to be requested with MarkForUpdate().
     virtual void Update(const FrameInfo& frame) {}
-    /// Calculate distance and update batches for rendering. May be called from worker thread(s), possibly re-entrantly.
+    /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateBatches(const FrameInfo& frame);
     /// Prepare geometry for rendering.
     virtual void UpdateGeometry(const FrameInfo& frame) {}
-    /// Return whether a geometry update is necessary, and if it should happen in a worker thread.
+    /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
     virtual UpdateGeometryType GetUpdateGeometryType() { return UPDATE_NONE; }
     /// Return number of occlusion geometry triangles.
     virtual unsigned GetNumOccluderTriangles() { return 0; }

+ 1 - 1
Engine/Graphics/GraphicsDefs.h

@@ -41,7 +41,7 @@ enum PrimitiveType
     LINE_LIST
 };
 
-/// Geometry type.
+/// %Geometry type.
 enum GeometryType
 {
     GEOM_STATIC = 0,

+ 1 - 1
Engine/Graphics/Light.h

@@ -161,7 +161,7 @@ public:
     virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& src);
     /// Process octree raycast. May be called from a worker thread.
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
-    /// Calculate distance and update batches for rendering. May be called from worker thread(s), possibly re-entrantly.
+    /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateBatches(const FrameInfo& frame);
     /// Add debug geometry to the debug renderer.
     virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);

+ 1 - 1
Engine/Graphics/Skybox.h

@@ -40,7 +40,7 @@ public:
     
     /// Process octree raycast. May be called from a worker thread.
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
-    /// Calculate distance and update batches for rendering. May be called from worker thread(s), possibly re-entrantly.
+    /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateBatches(const FrameInfo& frame);
     
 protected:

+ 1 - 1
Engine/Graphics/StaticModel.h

@@ -51,7 +51,7 @@ public:
     
     /// Process octree raycast. May be called from a worker thread.
     virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
-    /// Calculate distance and update batches for rendering. May be called from worker thread(s), possibly re-entrantly.
+    /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     virtual void UpdateBatches(const FrameInfo& frame);
     /// Return number of occlusion geometry triangles.
     virtual unsigned GetNumOccluderTriangles();

+ 6 - 12
Engine/Graphics/View.cpp

@@ -781,14 +781,13 @@ void View::GetBatches()
                             if (!srcBatch.geometry_ || !tech)
                                 continue;
                             
-                            Batch destBatch;
-                            destBatch.pass_ = tech->GetPass(PASS_SHADOW);
+                            Pass* pass = tech->GetPass(PASS_SHADOW);
                             // Skip if material has no shadow pass
-                            if (!destBatch.pass_)
+                            if (!pass)
                                 continue;
                             
-                            // Copy the rest of the batch
-                            destBatch.CopyFrom(srcBatch);
+                            Batch destBatch(srcBatch);
+                            destBatch.pass_ = pass;
                             destBatch.camera_ = shadowCamera;
                             destBatch.zone_ = zone;
                             destBatch.lightQueue_ = &lightQueue;
@@ -896,10 +895,7 @@ void View::GetBatches()
                 if (!srcBatch.geometry_ || !tech)
                     continue;
                 
-                Batch destBatch;
-                
-                // Copy the rest of the batch
-                destBatch.CopyFrom(srcBatch);
+                Batch destBatch(srcBatch);
                 destBatch.camera_ = camera_;
                 destBatch.zone_ = zone;
                 destBatch.isBase_ = true;
@@ -1120,7 +1116,7 @@ void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue)
             tech->HasPass(PASS_DEFERRED)))
             continue;
         
-        Batch destBatch;
+        Batch destBatch(srcBatch);
         
         // Check for lit base pass. Because it uses the replace blend mode, it must be ensured to be the first light
         // Also vertex lighting or ambient gradient require the non-lit base pass, so skip in those cases
@@ -1142,8 +1138,6 @@ void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue)
         if (!destBatch.pass_)
             continue;
         
-        // Fill the rest of the batch
-        destBatch.CopyFrom(srcBatch);
         destBatch.camera_ = camera_;
         destBatch.lightQueue_ = &lightQueue;
         destBatch.zone_ = zone;