{{ message }}
Repository navigation
Main: constant-initialize the Matrix3, Matrix4, Affine3, Quaternion and AxisAlignedBox constants - #3761
Open
ybai08 wants to merge 1 commit into
Open
Main: constant-initialize the Matrix3, Matrix4, Affine3, Quaternion and AxisAlignedBox constants#3761ybai08 wants to merge 1 commit into
ybai08 wants to merge 1 commit into
Conversation
…nd AxisAlignedBox constants Make the constructors used to define ZERO, IDENTITY, CLIPSPACE2DTOIMAGESPACE, BOX_NULL and BOX_INFINITE constexpr. Their definitions are then constant-initialized, so they are already set when another translation unit reads them during its own dynamic initialization. Unlike OGRECave#3313 and OGRECave#3315 the constants stay objects, so this keeps the ABI. Matrix4 and Affine3 initialize their entries through a new protected constexpr TransformBase constructor. Part of OGRECave#3321.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Part of #3321. This covers the five classes still unticked in its checklist: AxisAlignedBox, Matrix3, Matrix4, Affine3 and Quaternion.
The constructors used to define
ZERO,IDENTITY,CLIPSPACE2DTOIMAGESPACE,BOX_NULLandBOX_INFINITEare nowconstexpr. The definitions in the .cpp files are unchanged, but they now meet the C++14 rule for constant initialization: a static object initialized by a constexpr constructor with constant arguments. They are therefore set before any dynamic initialization runs, so another translation unit (or a static library user) that reads them from its own static initializer no longer depends on initialization order.This differs from #3313/#3315: the constants stay objects (
static const Matrix4 IDENTITY;) instead of becoming references, so the ABI doesn't change. If you'd rather keep the #3315 pattern for consistency, that is a small follow-up on top of the constexpr constructors.Changes:
Matrix3(9 reals),Quaternion(w, x, y, z)and bothAxisAlignedBoxconstructors initialize their members in the member initializer list and areconstexpr. TheAxisAlignedBoxvalues are the same as before: (-0.5) to (0.5), with the given extent.Matrix4(16 reals)andAffine3(12 reals)areconstexpr. C++14 requires a constexpr constructor to initialize every member, andmlives inTransformBase. So this adds a protected constexprTransformBase/TransformBaseRealconstructor that takes all 16 entries, and the two constructors forward to it.Affine3passes0, 0, 0, 1for the last row, as before.Matrix3::EPSILON,msSvdMaxIterationsandQuaternion::msEpsilonare scalars with constant initializers, so they were already fine.Tests (Tests/OgreMain/src/General.cpp):
constexprvariables built with each of these constructors at namespace scope. This compiles only if the constructors are usable in constant expressions, which is what the constants rely on.Math.ConstexprConstructorschecks the entry order (row-major,Affine3's last row) and the two box extents.Math.StaticConstantschecks the values of all eleven constants.Verification (macOS arm64, Apple clang, Unix Makefiles generator, Debug,
OGRE_BUILD_LIBS_AS_FRAMEWORKS=OFF, all render systems off, samples and tests on):constexpr variable cannot have non-literal typeforMatrix3,Matrix4,Affine3,Quaternionand bothAxisAlignedBoxvariables (6 errors).___cxx_global_var_init*innm -mof each object file), before -> after:OgreMatrix3.cpp.o3 -> 1,OgreMatrix4.cpp.o6 -> 1,OgreQuaternion.cpp.o3 -> 1,OgreAxisAlignedBox.cpp.o3 -> 1. The remaining one is the samestd::stringinitializer thatOgreVector.cpp.o(already converted) also has.Test_Ogre --gtest_filter=-UseCustomCapabilitiesTests*:DotSceneTests.exportImport,QuaternionTests.Precision), 3 failed;Root.shutdown,MaterialSerializer.BasicandImage.Compressed. All three come from this non-framework build: they can'tdlopenContents/Frameworks/Plugin_ParticleFX.framework.makeof all targets (including the tools and SampleBrowser) succeeds with the change.Not run: GCC, MSVC, Linux/Windows builds, the SWIG bindings, visual tests, and an Xcode-generator build.