Browse Source

Make GetLodGeometry() and occlusionLodLevel signed

1vanK 3 years ago
parent
commit
44f3b51ca2

+ 16 - 16
Source/Urho3D/AngelScript/Generated_Members.h

@@ -17896,8 +17896,8 @@ template <class T> void RegisterMembers_Drawable(asIScriptEngine* engine, const
     // float Drawable::GetLodDistance() const
     engine->RegisterObjectMethod(className, "float GetLodDistance() const", AS_METHODPR(T, GetLodDistance, () const, float), AS_CALL_THISCALL);
 
-    // virtual Geometry* Drawable::GetLodGeometry(unsigned batchIndex, unsigned level)
-    engine->RegisterObjectMethod(className, "Geometry@+ GetLodGeometry(uint, uint)", AS_METHODPR(T, GetLodGeometry, (unsigned, unsigned), Geometry*), AS_CALL_THISCALL);
+    // virtual Geometry* Drawable::GetLodGeometry(i32 batchIndex, i32 level)
+    engine->RegisterObjectMethod(className, "Geometry@+ GetLodGeometry(int, int)", AS_METHODPR(T, GetLodGeometry, (i32, i32), Geometry*), AS_CALL_THISCALL);
 
     // unsigned Drawable::GetMaxLights() const
     engine->RegisterObjectMethod(className, "uint GetMaxLights() const", AS_METHODPR(T, GetMaxLights, () const, unsigned), AS_CALL_THISCALL);
@@ -18919,9 +18919,9 @@ template <class T> void RegisterMembers_Terrain(asIScriptEngine* engine, const c
     engine->RegisterObjectMethod(className, "const IntVector2& GetNumVertices() const", AS_METHODPR(T, GetNumVertices, () const, const IntVector2&), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "const IntVector2& get_numVertices() const", AS_METHODPR(T, GetNumVertices, () const, const IntVector2&), AS_CALL_THISCALL);
 
-    // unsigned Terrain::GetOcclusionLodLevel() const
-    engine->RegisterObjectMethod(className, "uint GetOcclusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_occlusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, unsigned), AS_CALL_THISCALL);
+    // i32 Terrain::GetOcclusionLodLevel() const
+    engine->RegisterObjectMethod(className, "int GetOcclusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_occlusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, i32), AS_CALL_THISCALL);
 
     // TerrainPatch* Terrain::GetPatch(i32 index) const
     engine->RegisterObjectMethod(className, "TerrainPatch@+ GetPatch(int) const", AS_METHODPR(T, GetPatch, (i32) const, TerrainPatch*), AS_CALL_THISCALL);
@@ -19040,12 +19040,12 @@ template <class T> void RegisterMembers_Terrain(asIScriptEngine* engine, const c
     engine->RegisterObjectMethod(className, "void SetOccluder(bool)", AS_METHODPR(T, SetOccluder, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_occluder(bool)", AS_METHODPR(T, SetOccluder, (bool), void), AS_CALL_THISCALL);
 
-    // void Terrain::SetOcclusionLodLevel(unsigned level)
-    engine->RegisterObjectMethod(className, "void SetOcclusionLodLevel(uint)", AS_METHODPR(T, SetOcclusionLodLevel, (unsigned), void), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_occlusionLodLevel(uint)", AS_METHODPR(T, SetOcclusionLodLevel, (unsigned), void), AS_CALL_THISCALL);
+    // void Terrain::SetOcclusionLodLevel(i32 level)
+    engine->RegisterObjectMethod(className, "void SetOcclusionLodLevel(int)", AS_METHODPR(T, SetOcclusionLodLevel, (i32), void), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_occlusionLodLevel(int)", AS_METHODPR(T, SetOcclusionLodLevel, (i32), void), AS_CALL_THISCALL);
 
-    // void Terrain::SetOcclusionLodLevelAttr(unsigned value)
-    engine->RegisterObjectMethod(className, "void SetOcclusionLodLevelAttr(uint)", AS_METHODPR(T, SetOcclusionLodLevelAttr, (unsigned), void), AS_CALL_THISCALL);
+    // void Terrain::SetOcclusionLodLevelAttr(i32 value)
+    engine->RegisterObjectMethod(className, "void SetOcclusionLodLevelAttr(int)", AS_METHODPR(T, SetOcclusionLodLevelAttr, (i32), void), AS_CALL_THISCALL);
 
     // void Terrain::SetPatchSize(int size)
     engine->RegisterObjectMethod(className, "void SetPatchSize(int)", AS_METHODPR(T, SetPatchSize, (int), void), AS_CALL_THISCALL);
@@ -23165,9 +23165,9 @@ template <class T> void RegisterMembers_StaticModel(asIScriptEngine* engine, con
     engine->RegisterObjectMethod(className, "uint GetNumGeometries() const", AS_METHODPR(T, GetNumGeometries, () const, unsigned), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "uint get_numGeometries() const", AS_METHODPR(T, GetNumGeometries, () const, unsigned), AS_CALL_THISCALL);
 
-    // unsigned StaticModel::GetOcclusionLodLevel() const
-    engine->RegisterObjectMethod(className, "uint GetOcclusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_occlusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, unsigned), AS_CALL_THISCALL);
+    // i32 StaticModel::GetOcclusionLodLevel() const
+    engine->RegisterObjectMethod(className, "int GetOcclusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_occlusionLodLevel() const", AS_METHODPR(T, GetOcclusionLodLevel, () const, i32), AS_CALL_THISCALL);
 
     // bool StaticModel::IsInside(const Vector3& point) const
     engine->RegisterObjectMethod(className, "bool IsInside(const Vector3&in) const", AS_METHODPR(T, IsInside, (const Vector3&) const, bool), AS_CALL_THISCALL);
@@ -23189,9 +23189,9 @@ template <class T> void RegisterMembers_StaticModel(asIScriptEngine* engine, con
     // void StaticModel::SetModelAttr(const ResourceRef& value)
     engine->RegisterObjectMethod(className, "void SetModelAttr(const ResourceRef&in)", AS_METHODPR(T, SetModelAttr, (const ResourceRef&), void), AS_CALL_THISCALL);
 
-    // void StaticModel::SetOcclusionLodLevel(unsigned level)
-    engine->RegisterObjectMethod(className, "void SetOcclusionLodLevel(uint)", AS_METHODPR(T, SetOcclusionLodLevel, (unsigned), void), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_occlusionLodLevel(uint)", AS_METHODPR(T, SetOcclusionLodLevel, (unsigned), void), AS_CALL_THISCALL);
+    // void StaticModel::SetOcclusionLodLevel(i32 level)
+    engine->RegisterObjectMethod(className, "void SetOcclusionLodLevel(int)", AS_METHODPR(T, SetOcclusionLodLevel, (i32), void), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_occlusionLodLevel(int)", AS_METHODPR(T, SetOcclusionLodLevel, (i32), void), AS_CALL_THISCALL);
 
     // virtual void Drawable::Update(const FrameInfo& frame)
     engine->RegisterObjectMethod(className, "void Update(const FrameInfo&in)", AS_METHODPR(T, Update, (const FrameInfo&), void), AS_CALL_THISCALL);

+ 4 - 1
Source/Urho3D/Graphics/CustomGeometry.cpp

@@ -116,8 +116,11 @@ void CustomGeometry::ProcessRayQuery(const RayOctreeQuery& query, Vector<RayQuer
     }
 }
 
-Geometry* CustomGeometry::GetLodGeometry(unsigned batchIndex, unsigned level)
+Geometry* CustomGeometry::GetLodGeometry(i32 batchIndex, i32 level)
 {
+    assert(batchIndex >= 0);
+    assert(level >= 0 || level == NINDEX);
+
     return batchIndex < geometries_.Size() ? geometries_[batchIndex] : nullptr;
 }
 

+ 1 - 1
Source/Urho3D/Graphics/CustomGeometry.h

@@ -43,7 +43,7 @@ public:
     /// Process octree raycast. May be called from a worker thread.
     void ProcessRayQuery(const RayOctreeQuery& query, Vector<RayQueryResult>& results) override;
     /// Return the geometry for a specific LOD level.
-    Geometry* GetLodGeometry(unsigned batchIndex, unsigned level) override;
+    Geometry* GetLodGeometry(i32 batchIndex, i32 level) override;
     /// Return number of occlusion geometry triangles.
     unsigned GetNumOccluderTriangles() override;
     /// Draw to occlusion buffer. Return true if did not run out of triangles.

+ 4 - 1
Source/Urho3D/Graphics/Drawable.cpp

@@ -126,8 +126,11 @@ void Drawable::UpdateBatches(const FrameInfo& frame)
         lodDistance_ = newLodDistance;
 }
 
-Geometry* Drawable::GetLodGeometry(unsigned batchIndex, unsigned level)
+Geometry* Drawable::GetLodGeometry(i32 batchIndex, i32 level)
 {
+    assert(batchIndex >= 0);
+    assert(level >= 0 || level == NINDEX);
+
     // By default return the visible batch geometry
     if (batchIndex < batches_.Size())
         return batches_[batchIndex].geometry_;

+ 1 - 1
Source/Urho3D/Graphics/Drawable.h

@@ -125,7 +125,7 @@ public:
     virtual UpdateGeometryType GetUpdateGeometryType() { return UPDATE_NONE; }
 
     /// Return the geometry for a specific LOD level.
-    virtual Geometry* GetLodGeometry(unsigned batchIndex, unsigned level);
+    virtual Geometry* GetLodGeometry(i32 batchIndex, i32 level);
 
     /// Return number of occlusion geometry triangles.
     virtual unsigned GetNumOccluderTriangles() { return 0; }

+ 10 - 5
Source/Urho3D/Graphics/StaticModel.cpp

@@ -27,7 +27,7 @@ extern const char* GEOMETRY_CATEGORY;
 
 StaticModel::StaticModel(Context* context) :
     Drawable(context, DrawableTypes::Geometry),
-    occlusionLodLevel_(M_MAX_UNSIGNED),
+    occlusionLodLevel_(NINDEX),
     materialsAttr_(Material::GetTypeStatic())
 {
 }
@@ -49,7 +49,7 @@ void StaticModel::RegisterObject(Context* context)
     URHO3D_ACCESSOR_ATTRIBUTE("Shadow Distance", GetShadowDistance, SetShadowDistance, 0.0f, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("LOD Bias", GetLodBias, SetLodBias, 1.0f, AM_DEFAULT);
     URHO3D_COPY_BASE_ATTRIBUTES(Drawable);
-    URHO3D_ATTRIBUTE("Occlusion LOD Level", occlusionLodLevel_, M_MAX_UNSIGNED, AM_DEFAULT);
+    URHO3D_ATTRIBUTE("Occlusion LOD Level", occlusionLodLevel_, NINDEX, AM_DEFAULT);
 }
 
 void StaticModel::ProcessRayQuery(const RayOctreeQuery& query, Vector<RayQueryResult>& results)
@@ -134,13 +134,16 @@ void StaticModel::UpdateBatches(const FrameInfo& frame)
     }
 }
 
-Geometry* StaticModel::GetLodGeometry(unsigned batchIndex, unsigned level)
+Geometry* StaticModel::GetLodGeometry(i32 batchIndex, i32 level)
 {
+    assert(batchIndex >= 0);
+    assert(level >= 0 || level == NINDEX);
+
     if (batchIndex >= geometries_.Size())
         return nullptr;
 
     // If level is out of range, use visible geometry
-    if (level < geometries_[batchIndex].Size())
+    if (level >= 0 && level < geometries_[batchIndex].Size())
         return geometries_[batchIndex][level];
     else
         return batches_[batchIndex].geometry_;
@@ -274,8 +277,10 @@ bool StaticModel::SetMaterial(unsigned index, Material* material)
     return true;
 }
 
-void StaticModel::SetOcclusionLodLevel(unsigned level)
+void StaticModel::SetOcclusionLodLevel(i32 level)
 {
+    assert(level >= 0 || level == NINDEX);
+
     occlusionLodLevel_ = level;
     MarkNetworkUpdate();
 }

+ 5 - 5
Source/Urho3D/Graphics/StaticModel.h

@@ -38,7 +38,7 @@ public:
     /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
     void UpdateBatches(const FrameInfo& frame) override;
     /// Return the geometry for a specific LOD level.
-    Geometry* GetLodGeometry(unsigned batchIndex, unsigned level) override;
+    Geometry* GetLodGeometry(i32 batchIndex, i32 level) override;
     /// Return number of occlusion geometry triangles.
     unsigned GetNumOccluderTriangles() override;
     /// Draw to occlusion buffer. Return true if did not run out of triangles.
@@ -53,9 +53,9 @@ public:
     /// Set material on one geometry. Return true if successful.
     /// @property{set_materials}
     virtual bool SetMaterial(unsigned index, Material* material);
-    /// Set occlusion LOD level. By default (M_MAX_UNSIGNED) same as visible.
+    /// Set occlusion LOD level. By default (NINDEX) same as visible.
     /// @property
-    void SetOcclusionLodLevel(unsigned level);
+    void SetOcclusionLodLevel(i32 level);
     /// Apply default materials from a material list file. If filename is empty (default), the model's resource name with extension .txt will be used.
     void ApplyMaterialList(const String& fileName = String::EMPTY);
 
@@ -76,7 +76,7 @@ public:
 
     /// Return occlusion LOD level.
     /// @property
-    unsigned GetOcclusionLodLevel() const { return occlusionLodLevel_; }
+    i32 GetOcclusionLodLevel() const { return occlusionLodLevel_; }
 
     /// Determines if the given world space point is within the model geometry.
     bool IsInside(const Vector3& point) const;
@@ -111,7 +111,7 @@ protected:
     /// Model.
     SharedPtr<Model> model_;
     /// Occlusion LOD level.
-    unsigned occlusionLodLevel_;
+    i32 occlusionLodLevel_;
     /// Material list attribute.
     mutable ResourceRefList materialsAttr_;
 

+ 10 - 6
Source/Urho3D/Graphics/Terrain.cpp

@@ -72,7 +72,7 @@ Terrain::Terrain(Context* context) :
     lastPatchSize_(0),
     numLodLevels_(1),
     maxLodLevels_(MAX_LOD_LEVELS),
-    occlusionLodLevel_(M_MAX_UNSIGNED),
+    occlusionLodLevel_(NINDEX),
     smoothing_(false),
     visible_(true),
     castShadows_(false),
@@ -126,7 +126,7 @@ void Terrain::RegisterObject(Context* context)
     URHO3D_ACCESSOR_ATTRIBUTE("Light Mask", GetLightMask, SetLightMask, DEFAULT_LIGHTMASK, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Shadow Mask", GetShadowMask, SetShadowMask, DEFAULT_SHADOWMASK, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Zone Mask", GetZoneMask, SetZoneMask, DEFAULT_ZONEMASK, AM_DEFAULT);
-    URHO3D_ACCESSOR_ATTRIBUTE("Occlusion LOD level", GetOcclusionLodLevel, SetOcclusionLodLevelAttr, M_MAX_UNSIGNED, AM_DEFAULT);
+    URHO3D_ACCESSOR_ATTRIBUTE("Occlusion LOD level", GetOcclusionLodLevel, SetOcclusionLodLevelAttr, NINDEX, AM_DEFAULT);
 }
 
 void Terrain::ApplyAttributes()
@@ -199,8 +199,10 @@ void Terrain::SetMaxLodLevels(unsigned levels)
     }
 }
 
-void Terrain::SetOcclusionLodLevel(unsigned level)
+void Terrain::SetOcclusionLodLevel(i32 level)
 {
+    assert(level >= 0 || level == NINDEX);
+
     if (level != occlusionLodLevel_)
     {
         occlusionLodLevel_ = level;
@@ -663,8 +665,8 @@ void Terrain::CreatePatchGeometry(TerrainPatch* patch)
     auto* occlusionData = (float*)occlusionCpuVertexData.Get();
     BoundingBox box;
 
-    unsigned occlusionLevel = occlusionLodLevel_;
-    if (occlusionLevel > numLodLevels_ - 1)
+    i32 occlusionLevel = occlusionLodLevel_;
+    if (occlusionLevel > numLodLevels_ - 1 || occlusionLevel == NINDEX)
         occlusionLevel = numLodLevels_ - 1;
 
     if (vertexData)
@@ -819,8 +821,10 @@ void Terrain::SetMaxLodLevelsAttr(unsigned value)
     }
 }
 
-void Terrain::SetOcclusionLodLevelAttr(unsigned value)
+void Terrain::SetOcclusionLodLevelAttr(i32 value)
 {
+    assert(value >= 0 || value == NINDEX);
+
     if (value != occlusionLodLevel_)
     {
         occlusionLodLevel_ = value;

+ 5 - 5
Source/Urho3D/Graphics/Terrain.h

@@ -43,9 +43,9 @@ public:
     /// Set maximum number of LOD levels for terrain patches. This can be between 1-4.
     /// @property
     void SetMaxLodLevels(unsigned levels);
-    /// Set LOD level used for terrain patch occlusion. By default (M_MAX_UNSIGNED) the coarsest. Since the LOD level used needs to be fixed, using finer LOD levels may result in false positive occlusion in cases where the actual rendered geometry is coarser, so use with caution.
+    /// Set LOD level used for terrain patch occlusion. By default (NINDEX) the coarsest. Since the LOD level used needs to be fixed, using finer LOD levels may result in false positive occlusion in cases where the actual rendered geometry is coarser, so use with caution.
     /// @property
-    void SetOcclusionLodLevel(unsigned level);
+    void SetOcclusionLodLevel(i32 level);
     /// Set smoothing of heightmap.
     /// @property
     void SetSmoothing(bool enable);
@@ -127,7 +127,7 @@ public:
 
     /// Return LOD level used for occlusion.
     /// @property
-    unsigned GetOcclusionLodLevel() const { return occlusionLodLevel_; }
+    i32 GetOcclusionLodLevel() const { return occlusionLodLevel_; }
 
     /// Return whether smoothing is in use.
     /// @property
@@ -234,7 +234,7 @@ public:
     /// Set max LOD levels attribute.
     void SetMaxLodLevelsAttr(unsigned value);
     /// Set occlusion LOD level attribute.
-    void SetOcclusionLodLevelAttr(unsigned value);
+    void SetOcclusionLodLevelAttr(i32 value);
     /// Return heightmap attribute.
     ResourceRef GetHeightMapAttr() const;
     /// Return material attribute.
@@ -315,7 +315,7 @@ private:
     /// Maximum number of LOD levels.
     unsigned maxLodLevels_;
     /// LOD level used for occlusion.
-    unsigned occlusionLodLevel_;
+    i32 occlusionLodLevel_;
     /// Smoothing enable flag.
     bool smoothing_;
     /// Visible flag.

+ 4 - 1
Source/Urho3D/Graphics/TerrainPatch.cpp

@@ -140,8 +140,11 @@ UpdateGeometryType TerrainPatch::GetUpdateGeometryType()
     return UPDATE_MAIN_THREAD;
 }
 
-Geometry* TerrainPatch::GetLodGeometry(unsigned batchIndex, unsigned level)
+Geometry* TerrainPatch::GetLodGeometry(i32 batchIndex, i32 level)
 {
+    assert(batchIndex >= 0);
+    assert(level >= 0 || level == NINDEX);
+
     if (!level)
         return maxLodGeometry_;
     else

+ 1 - 1
Source/Urho3D/Graphics/TerrainPatch.h

@@ -35,7 +35,7 @@ public:
     /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
     UpdateGeometryType GetUpdateGeometryType() override;
     /// Return the geometry for a specific LOD level.
-    Geometry* GetLodGeometry(unsigned batchIndex, unsigned level) override;
+    Geometry* GetLodGeometry(i32 batchIndex, i32 level) override;
     /// Return number of occlusion geometry triangles.
     unsigned GetNumOccluderTriangles() override;
     /// Draw to occlusion buffer. Return true if did not run out of triangles.