Skip to content

Commit

Permalink
Hotfix v1.0.2
Browse files Browse the repository at this point in the history
* Optimize point light accumulation, somewhat
* Update dependencies
  • Loading branch information
xndc committed Sep 16, 2019
1 parent 22dec37 commit 916ea3c
Show file tree
Hide file tree
Showing 51 changed files with 960 additions and 237 deletions.
1 change: 1 addition & 0 deletions lib/cglm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ win/Debug
cglm-test-ios*
/cglm.pc
test-driver
[email protected]
4 changes: 4 additions & 0 deletions lib/cglm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ if `msbuild` won't work (because of multi version VS) then try to build with `de
$ devenv cglm.sln /Build Release
```

#### Running Tests on Windows

You can see test project in same visual studio solution file. It is enough to run that project to run tests.

### Building Docs
First you need install Sphinx: http://www.sphinx-doc.org/en/master/usage/installation.html
then:
Expand Down
2 changes: 1 addition & 1 deletion lib/cglm/cglm.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Pod::Spec.new do |s|

# Description
s.name = "cglm"
s.version = "0.5.1"
s.version = "0.6.1"
s.summary = "📽 Optimized OpenGL/Graphics Math (glm) for C"
s.description = <<-DESC
cglm is math library for graphics programming for C. It is similar to original glm but it is written for C instead of C++ (you can use here too). See the documentation or README for all features.
Expand Down
7 changes: 7 additions & 0 deletions lib/cglm/docs/source/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ For instance you may called **glm_vec4_** functions for **vec3** data type.
It will try to write 32 byte but since **vec3** is 24 byte it should throw
memory access error or exit the app without saying anything.

**UPDATE - IMPORTANT:**

| On MSVC or some other compilers, if alignment is enabled (default) then double check alignment requirements if you got a crash.
| If you send GLM_VEC4_ONE or similar macros directly to a function, it may be crashed.
| Because compiler may not apply alignment as defined on **typedef** to that macro while passing it (on stack) to a function.
Wrong Results:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions lib/cglm/include/cglm/mat4.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ glm_mat4_quat(mat4 m, versor dest) {
/*!
* @brief multiply vector with mat4
*
* actually the result is vec4, after multiplication the last component
* is trimmed. if you need it don't use this func.
*
* @param[in] m mat4(affine transform)
* @param[in] v vec3
* @param[in] last 4th item to make it vec4
Expand Down
38 changes: 32 additions & 6 deletions lib/cglm/test/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ typedef struct test_entry_t {
#define TEST_ENTRY(FUN) { #FUN, test_ ## FUN, 0, 0 },
#define TEST_LIST static test_entry_t tests[] =

#define TEST_OK 1
#define TEST_SUCCESS return (test_status_t){NULL, TEST_OK};

#define TEST_IMPL(FUN) \
test_status_t test_ ## FUN (void); \
test_status_t test_ ## FUN()

#define ASSERT_EXT(expr, msg) \
if (!(expr)) { \
fprintf(stderr, \
Expand All @@ -70,12 +77,31 @@ typedef struct test_entry_t {

#define ASSERT_CHOOSER(...) ASSERT_ARG3(__VA_ARGS__, ASSERT_ARG2, ASSERT_ARG1)
#define ASSERT(...) do { ASSERT_CHOOSER(__VA_ARGS__)(__VA_ARGS__) } while(0);
#define ASSERTIFY(expr) do { \
test_status_t ts; \
ts = expr; \
if (ts.status != TEST_OK) { \
fprintf(stderr, \
RED " assert fail" RESET \
" in " BOLDCYAN "%s " RESET \
"on " BOLDMAGENTA "line %d" RESET \
" : " BOLDWHITE " ASSERTIFY(%s)\n" RESET, \
__FILE__, \
__LINE__, \
#expr); \
return (test_status_t){ts.msg, 0}; \
} \
} while(0);

#define TEST_OK 1
#define TEST_SUCCESS return (test_status_t){NULL, TEST_OK};

#define TEST_IMPL(FUN) \
test_status_t test_ ## FUN (void); \
test_status_t test_ ## FUN()
#if defined(_WIN32)
# define drand48() ((float)(rand() / (RAND_MAX + 1.0)))
# define OK_TEXT "ok:"
# define FAIL_TEXT "fail:"
# define FINAL_TEXT "^_^"
#else
# define OK_TEXT "✔︎"
# define FAIL_TEXT "𐄂"
# define FINAL_TEXT "🎉"
#endif

#endif /* common_h */
51 changes: 35 additions & 16 deletions lib/cglm/test/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,47 @@

#include <stdlib.h>
#include <time.h>
#include <string.h>

int
main(int argc, const char * argv[]) {
test_entry_t *entry;
test_status_t st;
int32_t i, count, passed, failed;
double start, end, elapsed;
int32_t i, count, passed, failed, maxlen;
double start, end, elapsed, total;

passed = failed = 0;
passed = failed = maxlen = 0;
total = 0.0;
count = sizeof(tests) / sizeof(tests[0]);

fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET);


for (i = 0; i < count; i++) {
int32_t len;

entry = tests + i;
len = (int32_t)strlen(entry->name);

maxlen = GLM_MAX(maxlen, len);
}

maxlen += 5;

fprintf(stderr,
BOLDWHITE " %-*s %-*s\n",
maxlen, "Test Name", maxlen, "Elapsed Time");

for (i = 0; i < count; i++) {
entry = tests + i;
start = clock();
st = entry->entry();
end = clock();
elapsed = (end - start) / CLOCKS_PER_SEC;
total += elapsed;

if (!st.status) {
fprintf(stderr,
BOLDRED " 𐄂" BOLDWHITE " %s " RESET,
entry->name);
BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name);
if (st.msg) {
fprintf(stderr,
YELLOW "- %s" RESET,
Expand All @@ -44,29 +61,31 @@ main(int argc, const char * argv[]) {

failed++;
} else {
fprintf(stderr, GREEN " ✔︎" RESET " %s - " , entry->name);
fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name);

if (elapsed > 0.01)
fprintf(stderr, YELLOW "%.2f", elapsed);
fprintf(stderr, YELLOW "%.2fs", elapsed);
else
fprintf(stderr, "0");

fprintf(stderr, "s\n" RESET);
fprintf(stderr, "\n" RESET);
passed++;
}
}

if (failed == 0) {
fprintf(stderr, BOLDGREEN "\n All tests are passed 🎉\n" RESET);
fprintf(stderr,
BOLDGREEN "\n All tests are passed " FINAL_TEXT "\n" RESET);
}

fprintf(stderr,
CYAN "\ncglm test results:\n" RESET
"------------------\n"
CYAN "\ncglm test results (%0.2fs):\n" RESET
"--------------------------\n"

MAGENTA "%d" RESET " tests are runned, "
GREEN "%d" RESET " %s passed, "
RED "%d" RESET " %s failed\n\n" RESET,
total,
count,
passed,
passed > 1 ? "are" : "is",
Expand Down
22 changes: 11 additions & 11 deletions lib/cglm/test/src/test_affine.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t1, t2, t3); /* R * T */

glm_translate(t1, (vec3){34, 57, 36});
ASSERT(test_assert_mat4_eq(t1, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t1, t3))

/* test rotate is postmultiplied */
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
Expand All @@ -26,7 +26,7 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t2, t1, t3); /* T * R */

glm_rotate(t2, GLM_PI_4f, GLM_YUP);
ASSERT(test_assert_mat4_eq(t2, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t2, t3))

/* test scale is postmultiplied */
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
Expand All @@ -37,31 +37,31 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t3, t4, t5); /* T * R * S */

glm_scale(t3, (vec3){3, 5, 6});
ASSERT(test_assert_mat4_eq(t3, t5).status == 1)
ASSERTIFY(test_assert_mat4_eq(t3, t5))

/* test translate_x */
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 0, 0});

glmc_mat4_mul(t1, t2, t3); /* R * T */
glm_translate_x(t1, 34);
ASSERT(test_assert_mat4_eq(t1, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t1, t3))

/* test translate_y */
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){0, 57, 0});

glmc_mat4_mul(t1, t2, t3); /* R * T */
glm_translate_y(t1, 57);
ASSERT(test_assert_mat4_eq(t1, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t1, t3))

/* test translate_z */
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){0, 0, 36});

glmc_mat4_mul(t1, t2, t3); /* R * T */
glm_translate_z(t1, 36);
ASSERT(test_assert_mat4_eq(t1, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t1, t3))

/* test rotate_x */
glmc_rotate_make(t1, GLM_PI_4f, (vec3){1, 0, 0});
Expand All @@ -70,7 +70,7 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t2, t1, t3); /* T * R */

glm_rotate_x(t2, GLM_PI_4f, t2);
ASSERT(test_assert_mat4_eq(t2, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t2, t3))

/* test rotate_y */
glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 1, 0});
Expand All @@ -79,7 +79,7 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t2, t1, t3); /* T * R */

glm_rotate_y(t2, GLM_PI_4f, t2);
ASSERT(test_assert_mat4_eq(t2, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t2, t3))

/* test rotate_z */
glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
Expand All @@ -88,7 +88,7 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t2, t1, t3); /* T * R */

glm_rotate_z(t2, GLM_PI_4f, t2);
ASSERT(test_assert_mat4_eq(t2, t3).status == 1)
ASSERTIFY(test_assert_mat4_eq(t2, t3))

/* test rotate */
glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
Expand All @@ -97,7 +97,7 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t2, t1, t3); /* T * R */
glmc_rotate(t2, GLM_PI_4f, (vec3){0, 0, 1});

ASSERT(test_assert_mat4_eq(t3, t2).status == 1)
ASSERTIFY(test_assert_mat4_eq(t3, t2))

/* test scale_uni */
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
Expand All @@ -108,7 +108,7 @@ TEST_IMPL(affine) {
glmc_mat4_mul(t3, t4, t5); /* T * R * S */

glm_scale_uni(t3, 3);
ASSERT(test_assert_mat4_eq(t3, t5).status == 1)
ASSERTIFY(test_assert_mat4_eq(t3, t5))

TEST_SUCCESS
}
4 changes: 2 additions & 2 deletions lib/cglm/test/src/test_bezier.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ TEST_IMPL(bezier) {
Bs_plain = test_bezier_plain(s, p0, c0, c1, p1);

ASSERT(glm_eq(Bs, Bs_plain));
ASSERT(test_assert_eqf(smc, Bs_plain).status == 1)
ASSERT(test_assert_eqf(Bs, smc).status == 1)
ASSERTIFY(test_assert_eqf(smc, Bs_plain))
ASSERTIFY(test_assert_eqf(Bs, smc))

/* test cubic hermite */
smc = glm_smc(s, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1});
Expand Down
12 changes: 6 additions & 6 deletions lib/cglm/test/src/test_cam.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST_IMPL(camera_lookat) {

glm_look(eye, dir, up, view2);

ASSERT(test_assert_mat4_eq(view1, view2).status == 1)
ASSERTIFY(test_assert_mat4_eq(view1, view2))

TEST_SUCCESS
}
Expand All @@ -41,15 +41,15 @@ TEST_IMPL(camera_decomp) {

glm_persp_sizes(proj, fovy, sizes);

glm_frustum(-sizes[0] * 0.5,
sizes[0] * 0.5,
-sizes[1] * 0.5,
sizes[1] * 0.5,
glm_frustum(-sizes[0] * 0.5f,
sizes[0] * 0.5f,
-sizes[1] * 0.5f,
sizes[1] * 0.5f,
nearVal,
farVal,
proj2);

ASSERT(test_assert_mat4_eq(proj, proj2).status == 1)
ASSERTIFY(test_assert_mat4_eq(proj, proj2))

TEST_SUCCESS
}
4 changes: 2 additions & 2 deletions lib/cglm/test/src/test_clamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "test_common.h"

TEST_IMPL(clamp) {
vec3 v3 = {15.07, 0.4, 17.3};
vec4 v4 = {5.07, 2.3, 1.3, 1.4};
vec3 v3 = {15.07f, 0.4f, 17.3f};
vec4 v4 = {5.07f, 2.3f, 1.3f, 1.4f};

ASSERT(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f)
ASSERT(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f)
Expand Down
44 changes: 44 additions & 0 deletions lib/cglm/test/src/test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,50 @@ test_assert_mat3_eq(mat3 m1, mat3 m2) {
TEST_SUCCESS
}

test_status_t
test_assert_mat3_eqt(mat3 m1, mat3 m2) {
int i, j, k;

for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
for (k = 0; k < 3; k++)
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009);
}
}

TEST_SUCCESS
}

test_status_t
test_assert_mat4_eq_identity(mat4 m4) {
int i, j;

for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
if (i == j) {
ASSERT(glm_eq(m4[i][j], 1.0f))
} else {
ASSERT(glm_eq(m4[i][j], 0.0f))
}
}
}

TEST_SUCCESS
}

test_status_t
test_assert_mat4_eq_zero(mat4 m4) {
int i, j;

for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
ASSERT(glm_eq(m4[i][j], 0.0f))
}
}

TEST_SUCCESS
}

test_status_t
test_assert_eqf(float a, float b) {
ASSERT(fabsf(a - b) <= 0.000009); /* rounding errors */
Expand Down
Loading

0 comments on commit 916ea3c

Please sign in to comment.