Skip to content

Commit 1154b32

Browse files
Merge branch 'luaglm' into luaglm-dev/cfx
2 parents 3714ffd + 2db96c1 commit 1154b32

23 files changed

Lines changed: 1563 additions & 209 deletions

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ OPTION(GLM_FORCE_SILENT_WARNINGS "Silent C++ warnings from language extensions"
583583

584584
# Formerly known as 'GLM_FORCE_QUAT_DATA_WXYZ', however, changed without support
585585
# for backwards compatibility in-mind; must be compensated for in source.
586-
OPTION(GLM_FORCE_QUAT_DATA_XYZW "Force GLM to store quat data as x,y,z,w instead of w,x,y,z" ON)
586+
OPTION(GLM_FORCE_QUAT_DATA_XYZW "Force GLM to store quat data as x,y,z,w instead of w,x,y,z" OFF)
587587
# GLM_FORCE_PRECISION_{ LOWP_FLOAT, MEDIUMP_FLOAT, HIGHP_FLOAT }
588588

589589
ADD_COMPILE_DEFINITIONS(GLM_ENABLE_EXPERIMENTAL)
@@ -654,7 +654,8 @@ IF( GLM_FORCE_SILENT_WARNINGS )
654654
ENDIF()
655655

656656
IF( GLM_FORCE_QUAT_DATA_XYZW )
657-
ADD_COMPILE_DEFINITIONS(GLM_FORCE_QUAT_DATA_XYZW)
657+
MESSAGE(FATAL_ERROR "Disable GLM_FORCE_QUAT_DATA_XYZW" )
658+
# ADD_COMPILE_DEFINITIONS(GLM_FORCE_QUAT_DATA_XYZW)
658659
ENDIF()
659660

660661
IF( LUA_GLM_INCLUDE_EXT )

EXTENDED.md

Lines changed: 86 additions & 47 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ See [libs/scripts](libs/scripts) for a collection of example/test scripts using
558558
1. Support for integer vectors/matrices. Either by introducing an additional type, e.g., `LUA_TVECTORI`, or splitting the vector tag `LUA_TVECTOR` into `LUA_TVECTOR2`, `LUA_TVECTOR3`, `LUA_TVECTOR4`, and `LUA_TQUAT` and use variant bits for the primitive type.
559559
1. Replace `glm/gtc/random.{inl,hpp}` with a variant that takes advantage of CXX11's [Pseudo-random number generation](https://en.cppreference.com/w/cpp/numeric/random) facilities (and unify it with `math.random`).
560560
1. One downside to vectors/quaternions being an explicit `Value` is that they increase the minimum Value size to at least 16 bytes. Given that types in Lua are fairly transparent, it may be beneficial to introduce, or at least experiment with, a compile-time option to make vector/quaternion types collectible.
561-
1. Support for triangles and meshes, retrofit current spatial indexing structures for triangles, and consider BSPs.
561+
1. Support for meshes and retrofit current spatial indexing structures for triangles; consider BSPs.
562562
1. Include broad phase collision scripting examples, e.g., dynamic AABB tree and/or multibox sweep-and-prune.
563563
1. Initial support for frustums (both orthographic and perspective) and OBBs, or, at minimum, the more computationally complex parts of these structures.
564564
1. Allow some binding functions to be independently applied to each value or structure on the call stack. If disabled, only operate on the minimum number of required objects (following lmathlib). For example:
@@ -580,6 +580,7 @@ See [libs/scripts](libs/scripts) for a collection of example/test scripts using
580580
Ordered by priority.
581581
1. [geom](libs/glm-binding/geom): SIMD support (... for the most commonly use functions).
582582
1. Add support for two-dimensional geometrical structures: Ray2D, Line2D, Plane2D.
583+
1. Optimize `binding` functions that use 'glm_i2v'. Logic redundant with ``gLuaSharedTrait::Next(LB)``.
583584
1. Optimize `glm_createMatrix`. Profiling case '4x4 matrix creation (lua_Alloc)' is the one of the slowest operations in the added vector/matrix API. Worse when using the default Windows allocator.
584585
1. Optimize runtime swizzling: `swizzle` and `glmVec_get`. It is likely possible to improve this operation by 15/20 percent.
585586
1. Improve support for `glm::mat3x4` and `glm::mat4x3`.

lglm.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#define lglm_cpp
88
#define LUA_CORE
99

10+
/* @TEMP Disallow 820a2c0e625f26000c688d841836bb10483be34d */
11+
#if defined(GLM_FORCE_QUAT_DATA_XYZW)
12+
#error "glm broke compatbility, please compile without GLM_FORCE_QUAT_DATA_XYZW"
13+
#endif
14+
1015
/*
1116
@@ LUA_API_LINKAGE is a mark for the linkage specification to core API functions
1217
*/
@@ -1035,8 +1040,12 @@ lua_Integer luaO_HashString(const char *string, size_t length, int ignore_case)
10351040
hash ^= (hash >> 11);
10361041
hash += (hash << 15);
10371042

1043+
#if defined(GRIT_POWER_UHASH)
1044+
return l_castU2S(hash);
1045+
#else
10381046
// @TODO: Eventually avoid sign-extension issues. If ever...
10391047
return (lua_Integer)(int)hash;
1048+
#endif
10401049
}
10411050

10421051
/* gritLua functions stored in lbaselib; considered deprecated */
@@ -1280,8 +1289,13 @@ LUA_API void lua_pushvector (lua_State *L, lua_Float4 f4, int variant) {
12801289
}
12811290
else if (b_variant == LUA_VVECTOR1)
12821291
lua_pushnumber(L, cast_num(f4.x));
1283-
else if (b_variant == LUA_VQUAT)
1292+
else if (b_variant == LUA_VQUAT) {
1293+
#if defined(GLM_FORCE_QUAT_DATA_XYZW)
1294+
glm_pushvec_quat(L, glmVector(glm::qua<glm_Float>(f4.x, f4.y, f4.z, f4.w)));
1295+
#else
12841296
glm_pushvec_quat(L, glmVector(glm::qua<glm_Float>(f4.w, f4.x, f4.y, f4.z)));
1297+
#endif
1298+
}
12851299
else
12861300
glm_pushvec(L, glmVector(glm::vec<4, glm_Float>(f4.x, f4.y, f4.z, f4.w)), glm_dimensions(b_variant));
12871301
}
@@ -1647,12 +1661,20 @@ LUA_API int glmVec_qua(lua_State *L) {
16471661
if (ttisvector3(o2)) // <angle, axis>, degrees for gritLua compatibility
16481662
return glm_pushquat(L, glm::angleAxis(cast_glmfloat(glm::radians(nvalue(o1))), glm_vecvalue(o2).v3));
16491663
else if (ttisnumber(o2)) { // <w, x, y, z>
1664+
#if defined(GLM_FORCE_QUAT_DATA_XYZW)
1665+
const glm_Float w = cast_glmfloat(nvalue(o1));
1666+
const glm_Float x = cast_glmfloat(nvalue(o2));
1667+
const glm_Float y = cast_glmfloat(luaL_checknumber(L, 3));
1668+
const glm_Float z = cast_glmfloat(luaL_checknumber(L, 4));
1669+
return glm_pushquat(L, glm::qua<glm_Float>(x, y, z, w));
1670+
#else
16501671
return glm_pushquat(L, glm::qua<glm_Float>(
16511672
cast_glmfloat(nvalue(o1)),
16521673
cast_glmfloat(nvalue(o2)),
16531674
cast_glmfloat(luaL_checknumber(L, 3)),
16541675
cast_glmfloat(luaL_checknumber(L, 4)))
16551676
);
1677+
#endif
16561678
}
16571679
return luaL_error(L, "{w, x, y, z} or {angle, axis} expected");
16581680
}

libs/glm-binding/bindings.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extern LUA_API_LINKAGE {
4949
#include "geom/line.hpp"
5050
#include "geom/linesegment.hpp"
5151
#include "geom/ray.hpp"
52+
#include "geom/triangle.hpp"
5253
#include "geom/sphere.hpp"
5354
#include "geom/plane.hpp"
5455
#include "geom/polygon.hpp"
@@ -656,6 +657,22 @@ struct gLuaBase {
656657
return 2;
657658
}
658659

660+
template<glm::length_t D, typename T>
661+
LUA_TRAIT_QUALIFIER int Pull(const gLuaBase &LB, int idx_, glm::Triangle<D, T> &t) {
662+
Pull(LB, idx_, t.a);
663+
Pull(LB, idx_ + 1, t.b);
664+
Pull(LB, idx_ + 2, t.c);
665+
return 3;
666+
}
667+
668+
template<glm::length_t D, typename T>
669+
LUA_TRAIT_QUALIFIER int Push(gLuaBase &LB, const glm::Triangle<D, T> &t) {
670+
Push(LB, t.a);
671+
Push(LB, t.b);
672+
Push(LB, t.c);
673+
return 3;
674+
}
675+
659676
template<glm::length_t D, typename T>
660677
LUA_TRAIT_QUALIFIER int Pull(const gLuaBase &LB, int idx_, glm::Sphere<D, T> &s) {
661678
Pull(LB, idx_, s.pos);

libs/glm-binding/ext/quat_extensions.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
*/
1414
#ifndef __EXT_EXTENSION_QUAT_HPP__
1515
#define __EXT_EXTENSION_QUAT_HPP__
16+
17+
/* @TEMP Disallow 820a2c0e625f26000c688d841836bb10483be34d */
18+
#if defined(GLM_FORCE_QUAT_DATA_XYZW)
19+
#error "glm broke compatbility, please compile without GLM_FORCE_QUAT_DATA_XYZW"
20+
#endif
21+
1622
#if !defined(GLM_ENABLE_EXPERIMENTAL)
1723
#define GLM_ENABLE_EXPERIMENTAL
1824
#endif

0 commit comments

Comments
 (0)