Rendering system rewrite, tons of refactoring, optimizations, and other cool stuff (#116)
This commit is contained in:
parent
67ee59f437
commit
59cf8f6300
457 changed files with 44999 additions and 6136 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,3 +5,6 @@ osxbuild/
|
|||
.*DS_Store
|
||||
__pycache__
|
||||
*.out
|
||||
*.kdev4
|
||||
.kdev4/
|
||||
*.kate-swp
|
||||
|
|
|
@ -21,7 +21,7 @@ Dependencies
|
|||
- libzip >= 1.0
|
||||
- libpng >= 1.5.0
|
||||
- libjpeg
|
||||
- OpenGL >= 2.1
|
||||
- OpenGL >= 3.3
|
||||
|
||||
Build-only dependencies
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
37
atlas/meson.build
Normal file
37
atlas/meson.build
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
atlases_dir = meson.current_source_dir()
|
||||
atlases_overrides_dir = join_paths(atlases_dir, 'overrides')
|
||||
|
||||
# TODO: find a nice way to scale this over multiple atlas directories, if needed.
|
||||
|
||||
run_target('gen-atlases',
|
||||
command: [
|
||||
gen_atlases_command,
|
||||
atlases_overrides_dir,
|
||||
join_paths(atlases_dir, 'common'),
|
||||
join_paths(resources_dir, 'gfx'),
|
||||
'--name', 'common',
|
||||
'--width', '4096',
|
||||
'--height', '4096',
|
||||
'--border', '1',
|
||||
'--single',
|
||||
'--crop',
|
||||
'--leanify',
|
||||
],
|
||||
)
|
||||
|
||||
run_target('gen-atlases-fast',
|
||||
command: [
|
||||
gen_atlases_command,
|
||||
atlases_overrides_dir,
|
||||
join_paths(atlases_dir, 'common'),
|
||||
join_paths(resources_dir, 'gfx'),
|
||||
'--name', 'common',
|
||||
'--width', '4096',
|
||||
'--height', '4096',
|
||||
'--border', '1',
|
||||
'--single',
|
||||
'--crop',
|
||||
'--no-leanify',
|
||||
],
|
||||
)
|
|
@ -85,7 +85,13 @@ Resources
|
|||
|
||||
If ``1``, the game will crash with an error message when it attempts to
|
||||
use a resource that hasn't been previously preloaded. Useful for
|
||||
developers to debug missing preloads. Doesn't affect optional resources.
|
||||
developers to debug missing preloads.
|
||||
|
||||
**TAISEI_PRELOAD_SHADERS**
|
||||
| Default: ``0``
|
||||
|
||||
If ``1``, Taisei will load all shader programs at startup. This is mainly
|
||||
useful for developers to quickly ensure that none of them fail to compile.
|
||||
|
||||
Video and OpenGL
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
@ -104,6 +110,17 @@ Video and OpenGL
|
|||
|
||||
Use ``SDL_VIDEODRIVER`` instead.
|
||||
|
||||
**TAISEI_RENDERER**
|
||||
| Default: ``gl33``
|
||||
|
||||
Selects the rendering backend to use. Currently available options are:
|
||||
|
||||
- ``gl33``: the OpenGL 3.3 Core renderer
|
||||
- ``null``: the no-op renderer (nothing is displayed)
|
||||
|
||||
Note that the actual subset of usable backends, as well as the default
|
||||
choice, can be controlled by build options.
|
||||
|
||||
**TAISEI_LIBGL**
|
||||
| Default: unset
|
||||
|
||||
|
@ -113,21 +130,34 @@ Video and OpenGL
|
|||
Taisei is linked to libgl (which is not recommended, because it's not
|
||||
portable).
|
||||
|
||||
**TAISEI_GL_DEBUG**
|
||||
| Default: ``0`` for release builds, ``1`` for debug builds
|
||||
|
||||
Enables OpenGL debugging. A debug context will be requested, all OpenGL
|
||||
messages will be logged, and errors are fatal. Requires the ``KHR_debug``
|
||||
or ``ARB_debug_output`` extension.
|
||||
|
||||
**TAISEI_GL_EXT_OVERRIDES**
|
||||
| Default: unset
|
||||
|
||||
Space-separated list of OpenGL extensions that are assumed to be
|
||||
supported, even if the driver says they aren't. Prefix an extension with
|
||||
``-`` to invert this behaviour. Might be used to work around bugs in
|
||||
some weird/ancient/broken drivers, but your chances are slim. Also note
|
||||
that Taisei assumes many extensions to be available on any sane OpenGL
|
||||
2.1+ implementation and doesn't test for them, so you can't disable code
|
||||
that uses those this way.
|
||||
some weird/ancient/broken drivers, but your chances are slim. Note that
|
||||
this only affects code paths that actually test for the given extensions,
|
||||
not the actual OpenGL functionality. Some OpenGL implementations (such as
|
||||
Mesa) provide their own mechanisms for controlling extensions. You most
|
||||
likely want to use that instead.
|
||||
|
||||
**TAISEI_FRAMERATE_GRAPHS**
|
||||
| Default: ``0`` for release builds, ``1`` for debug builds
|
||||
|
||||
if ``1``, framerate graphs will be drawn on the HUD.
|
||||
If ``1``, framerate graphs will be drawn on the HUD.
|
||||
|
||||
**TAISEI_OBJPOOL_STATS**
|
||||
| Default: ``0`` for release builds, ``1`` for debug builds
|
||||
|
||||
Displays some statistics about usage of in-game objects.
|
||||
|
||||
Timing
|
||||
~~~~~~
|
||||
|
|
62
external/cglm/.gitignore
vendored
Normal file
62
external/cglm/.gitignore
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
*.xcodeproj
|
||||
*.xcworkspace
|
||||
*.sln
|
||||
*.vcxproj
|
||||
*.vcxproj.*
|
||||
*.suo
|
||||
*.sdf
|
||||
*.opensdf
|
||||
ipch/
|
||||
Debug/
|
||||
Release/
|
||||
.DS_Store
|
||||
.vs
|
||||
*.nupkg
|
||||
*.opendb
|
||||
packages.config
|
||||
/aclocal.m4
|
||||
/ar-lib
|
||||
/autom4te.cache/
|
||||
/compile
|
||||
/config.guess
|
||||
/config.log
|
||||
/config.status
|
||||
/config.sub
|
||||
/configure
|
||||
/depcomp
|
||||
/install-sh
|
||||
/ltmain.sh
|
||||
/missing
|
||||
/libtool
|
||||
/.libs/
|
||||
.deps/
|
||||
*.[oa]
|
||||
*.l[oa]
|
||||
Makefile
|
||||
Makefile.in
|
||||
m4/*.m4
|
||||
.buildstamp
|
||||
.dirstamp
|
||||
packages/
|
||||
.anjuta/*
|
||||
*.anjuta*
|
||||
config.h.*
|
||||
/config.h
|
||||
stamp*
|
||||
COPYING
|
||||
.idea/*
|
||||
*.VC.db
|
||||
cscope.*
|
||||
*-git-ignored-file.*
|
||||
test/*.trs
|
||||
test/test_*
|
||||
*.log
|
||||
test-*
|
||||
test/.libs/*
|
||||
test/tests
|
||||
cglm_arm/*
|
||||
cglm_test_ios/*
|
||||
cglm_test_iosTests/*
|
||||
docs/build/*
|
||||
win/cglm_test_*
|
||||
* copy.*
|
3
external/cglm/.gitmodules
vendored
Normal file
3
external/cglm/.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "test/lib/cmocka"]
|
||||
path = test/lib/cmocka
|
||||
url = git://git.cryptomilk.org/projects/cmocka.git
|
11
external/cglm/.gitrepo
vendored
Normal file
11
external/cglm/.gitrepo
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
; DO NOT EDIT (unless you know what you are doing)
|
||||
;
|
||||
; This subdirectory is a git "subrepo", and this file is maintained by the
|
||||
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
|
||||
;
|
||||
[subrepo]
|
||||
remote = https://github.com/taisei-project/cglm
|
||||
branch = taisei
|
||||
commit = 5af24c6b834fd85bb41ae2520f7030c1b689152e
|
||||
parent = cc41f444380def4cb5338aeda1204698d14d49f2
|
||||
cmdver = 0.3.1
|
59
external/cglm/.travis.yml
vendored
Normal file
59
external/cglm/.travis.yml
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
language: c
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
exclude:
|
||||
# Skip GCC builds on macOS.
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
include:
|
||||
# Additional GCC builds for code coverage.
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: CODE_COVERAGE=ON
|
||||
|
||||
cache:
|
||||
apt: true
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
- lcov
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
script:
|
||||
- sh ./build-deps.sh
|
||||
- sh ./autogen.sh
|
||||
- if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then
|
||||
./configure CFLAGS="-ftest-coverage -fprofile-arcs";
|
||||
else
|
||||
./configure;
|
||||
fi
|
||||
- make
|
||||
- make check
|
||||
|
||||
after_success:
|
||||
- if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then
|
||||
pip install --user cpp-coveralls
|
||||
coveralls
|
||||
--build-root .
|
||||
--exclude lib
|
||||
--exclude test
|
||||
--gcov-options '\-lp'
|
||||
--verbose;
|
||||
fi
|
53
external/cglm/CONTRIBUTING.md
vendored
Normal file
53
external/cglm/CONTRIBUTING.md
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
# CONTRIBUTING
|
||||
|
||||
Any contributions (code, documentation, ...) are welcome. This project uses [cmocka](http://cmocka.org) for testing, you may need to check their documentation
|
||||
|
||||
# New Features
|
||||
- This library may not accept all new features, it is better to create an issue and get approval before coding
|
||||
- You must add test for every new feature
|
||||
- The feature must be compiled in both UNIX/POSIX systems (e.g. macos, linux...) and Windows
|
||||
|
||||
# Code Style
|
||||
This library is written with C99, don't try to add C++ files (yes it can compiled into lib),
|
||||
if you have enough reason to add C++ files than create an issue and get approval before coding,
|
||||
|
||||
- All functions must have `glm` prefix
|
||||
- Lines should be wrapped at 80 characters.
|
||||
- Don't invent new style for existing ones
|
||||
- Use C89 style comments (`/* comments */`) not C++ style comments (`// comments`)
|
||||
- Don't use TABs instead use 2 spaces for TABs
|
||||
- All indents must be 2 spaces, not 1 nor 4 space
|
||||
- All functions in `include` folder must be exported by `CGLM_EXPORT` and wrapped by `extern "C" {` for C++
|
||||
- Crate new line for return type, attribs:
|
||||
|
||||
```C
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mul(mat4 m1, mat4 m2, mat4 dest)
|
||||
```
|
||||
|
||||
not acceptable:
|
||||
|
||||
```C
|
||||
CGLM_INLINE void glm_mul(mat4 m1, mat4 m2, mat4 dest)
|
||||
```
|
||||
- Variables must be declared at the top of a scope before usage:
|
||||
```C
|
||||
int x;
|
||||
int y;
|
||||
|
||||
x = y = 0;
|
||||
```
|
||||
|
||||
not acceptable:
|
||||
|
||||
```C
|
||||
int x;
|
||||
|
||||
x = 0;
|
||||
int y = 0;
|
||||
```
|
||||
|
||||
- All files must retain same LICENSE statement
|
||||
- Code with warnings will not be accepted, please suppress them (not by disabling them)
|
||||
- Run code anaylysis before submitting pull requests, if you use Xcode you can enable Sanitizer in scheme, you can use valgrind in linux
|
69
external/cglm/LICENSE
vendored
Normal file
69
external/cglm/LICENSE
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Recep Aslantas <info@recp.me>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
-
|
||||
|
||||
This library [initially] used some [piece of] implementations
|
||||
(may include codes) from these open source projects/resources:
|
||||
|
||||
1. Affine Transforms
|
||||
The original glm repo (g-truc), url: https://github.com/g-truc/glm
|
||||
|
||||
LICENSE[S]:
|
||||
The Happy Bunny License (Modified MIT License)
|
||||
The MIT License
|
||||
Copyright (c) 2005 - 2016 G-Truc Creation
|
||||
|
||||
FULL LICENSE: https://github.com/g-truc/glm/blob/master/copying.txt
|
||||
|
||||
2. Quaternions
|
||||
Anton's OpenGL 4 Tutorials book source code:
|
||||
|
||||
LICENSE:
|
||||
OpenGL 4 Example Code.
|
||||
Accompanies written series "Anton's OpenGL 4 Tutorials"
|
||||
Email: anton at antongerdelan dot net
|
||||
First version 27 Jan 2014
|
||||
Copyright Dr Anton Gerdelan, Trinity College Dublin, Ireland.
|
||||
|
||||
3. Euler Angles
|
||||
David Eberly
|
||||
Geometric Tools, LLC http://www.geometrictools.com/
|
||||
Copyright (c) 1998-2016. All Rights Reserved.
|
||||
|
||||
Computing Euler angles from a rotation matrix (euler.pdf)
|
||||
Gregory G. Slabaugh
|
||||
|
||||
4. Extracting Planes
|
||||
Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix
|
||||
Authors:
|
||||
Gil Gribb (ggribb@ravensoft.com)
|
||||
Klaus Hartmann (k_hartmann@osnabrueck.netsurf.de)
|
||||
|
||||
5. Transform AABB
|
||||
Transform Axis Aligned Bounding Boxes:
|
||||
http://dev.theomader.com/transform-bounding-boxes/
|
||||
https://github.com/erich666/GraphicsGems/blob/master/gems/TransBox.c
|
||||
|
||||
6. Cull frustum
|
||||
http://www.txutxi.com/?p=584
|
||||
http://old.cescg.org/CESCG-2002/DSykoraJJelinek/
|
215
external/cglm/README.md
vendored
Normal file
215
external/cglm/README.md
vendored
Normal file
|
@ -0,0 +1,215 @@
|
|||
# 🎥 OpenGL Mathematics (glm) for `C`
|
||||
[](https://travis-ci.org/recp/cglm)
|
||||
[](https://ci.appveyor.com/project/recp/cglm/branch/master)
|
||||
[](https://coveralls.io/github/recp/cglm?branch=master)
|
||||
[](https://www.codacy.com/app/recp/cglm?utm_source=github.com&utm_medium=referral&utm_content=recp/cglm&utm_campaign=Badge_Grade)
|
||||
|
||||
The original glm library is for C++ only (templates, namespaces, classes...), this library targeted to C99 but currently you can use it for C89 safely by language extensions e.g `__restrict`
|
||||
|
||||
#### Documentation
|
||||
|
||||
Almost all functions (inline versions) and parameters are documented inside related headers. <br />
|
||||
Complete documentation is in progress: http://cglm.readthedocs.io
|
||||
|
||||
#### Note for previous versions:
|
||||
|
||||
- _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec_copy`
|
||||
- OpenGL related functions are dropped to make this lib platform/third-party independent
|
||||
- make sure you have latest version and feel free to report bugs, troubles
|
||||
|
||||
#### Note for C++ developers:
|
||||
If you don't aware about original GLM library yet, you may also want to look at:
|
||||
https://github.com/g-truc/glm
|
||||
|
||||
#### Note for new comers (Important):
|
||||
- `vec4` and `mat4` variables must be aligned. (There will be unaligned versions later)
|
||||
- **in** and **[in, out]** parameters must be initialized (please). But **[out]** parameters not, initializing out param is also redundant
|
||||
- All functions are inline if you don't want to use pre-compiled versions with glmc_ prefix, you can ignore build process. Just incliude headers.
|
||||
- if your debugger takes you to cglm headers then make sure you are not trying to copy vec4 to vec3 or alig issues...
|
||||
- Welcome!
|
||||
|
||||
#### Note for experienced developers:
|
||||
- Since I'm testing this library in my projects, sometimes bugs occurs; finding that bug[s] and making improvements would be more easy with multiple developer/contributor and their projects or knowledge. Consider to make some tests if you suspect something is wrong and any feedbacks, contributions and bug reports are always welcome.
|
||||
|
||||
#### Allocations?
|
||||
`cglm` doesn't alloc any memory on heap. So it doesn't provide any allocator. You should alloc memory for **out** parameters too if you pass pointer of memory location. Don't forget that **vec4** (also quat/**versor**) and **mat4** must be aligned (16-bytes), because *cglm* uses SIMD instructions to optimize most operations if available.
|
||||
|
||||
#### Returning vector or matrix... ?
|
||||
Since almost all types are arrays and **C** doesn't allow returning arrays, so **cglm** doesn't support this feature. In the future *cglm* may use **struct** for some types for this purpose.
|
||||
|
||||
#### Other APIs like Vulkan, Metal, Dx?
|
||||
Currently *cglm* uses default clip space configuration (-1, 1) for camera functions (perspective, extract corners...), in the future other clip space configurations will be supported
|
||||
|
||||
<hr/>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<div>Like some other graphics libraries (especially OpenGL) this library use Column-Major layout to keep matrices in the memory. </div>
|
||||
<div> </div>
|
||||
<div>In the future the library may support an option to use row-major layout, CURRENTLY if you need to row-major layout you will need to transpose it. </div>
|
||||
</td>
|
||||
<td>
|
||||
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Matrix_Columns.svg" width="300px" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Features
|
||||
- general purpose matrix operations (mat4, mat3)
|
||||
- chain matrix multiplication (square only)
|
||||
- general purpose vector operations (cross, dot, rotate, proj, angle...)
|
||||
- affine transforms
|
||||
- matrix decomposition (extract rotation, scaling factor)
|
||||
- optimized affine transform matrices (mul, rigid-body inverse)
|
||||
- camera (lookat)
|
||||
- projections (ortho, perspective)
|
||||
- quaternions
|
||||
- euler angles / yaw-pitch-roll to matrix
|
||||
- extract euler angles
|
||||
- inline or pre-compiled function call
|
||||
- frustum (extract view frustum planes, corners...)
|
||||
- bounding box (AABB in Frustum (culling), crop, merge...)
|
||||
|
||||
<hr />
|
||||
|
||||
You have two option to call a function/operation: inline or library call (link)
|
||||
Almost all functions are marked inline (always_inline) so compiler probably will inline.
|
||||
To call pre-compiled version, just use `glmc_` (c stands for 'call') instead of `glm_`.
|
||||
|
||||
```C
|
||||
#include <cglm/cglm.h> /* for inline */
|
||||
#include <cglm/call.h> /* for library call (this also includes cglm.h) */
|
||||
|
||||
mat4 rot, trans, rt;
|
||||
/* ... */
|
||||
glm_mul(trans, rot, rt); /* inline */
|
||||
glmc_mul(trans, rot, rt); /* call from library */
|
||||
```
|
||||
Most of math functions are optimized manualy with SSE2 if available, if not? Dont worry there are non-sse versions of all operations
|
||||
|
||||
You can pass matrices and vectors as array to functions rather than get address.
|
||||
|
||||
```C
|
||||
mat4 m = {
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
};
|
||||
|
||||
glm_translate(m, (vec3){1.0f, 0.0f, 0.0f});
|
||||
```
|
||||
|
||||
Library contains general purpose mat4 mul and inverse functions but also contains some special form (optimized) of these functions for affine transform matrices. If you want to multiply two affine transform matrices you can use glm_mul instead of glm_mat4_mul and glm_inv_tr (ROT + TR) instead glm_mat4_inv
|
||||
```C
|
||||
/* multiplication */
|
||||
mat4 modelMat;
|
||||
glm_mul(T, R, modelMat);
|
||||
|
||||
/* othonormal rot + tr matrix inverse (rigid-body) */
|
||||
glm_inv_tr(modelMat);
|
||||
```
|
||||
|
||||
## License
|
||||
MIT. check the LICENSE file
|
||||
|
||||
## Build
|
||||
|
||||
### Unix (Autotools)
|
||||
|
||||
```text
|
||||
$ sh ./build-deps.sh # run only once (dependencies)
|
||||
$
|
||||
$ sh autogen.sh
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make install
|
||||
$ [sudo] make install
|
||||
```
|
||||
|
||||
### Windows (MSBuild)
|
||||
Windows related build files, project files are located in `win` folder,
|
||||
make sure you are inside `cglm/win` folder.
|
||||
Code Analysis are enabled, it may take awhile to build
|
||||
|
||||
```Powershell
|
||||
$ cd win
|
||||
$ .\build.bat
|
||||
```
|
||||
if `msbuild` won't work (because of multi version VS) then try to build with `devenv`:
|
||||
```Powershell
|
||||
$ devenv cglm.sln /Build Release
|
||||
```
|
||||
|
||||
## How to use
|
||||
If you want to use inline versions of funcstions then; include main header
|
||||
```C
|
||||
#include <cglm/cglm.h>
|
||||
```
|
||||
the haeder will include all headers. Then call func you want e.g. rotate vector by axis:
|
||||
```C
|
||||
glm_vec_rotate(v1, glm_rad(45), (vec3){1.0f, 0.0f, 0.0f});
|
||||
```
|
||||
some functions are overloaded :) e.g you can normalize vector:
|
||||
```C
|
||||
glm_vec_normalize(vec);
|
||||
```
|
||||
this will normalize vec and store normalized vector into `vec` but if you will store normalized vector into another vector do this:
|
||||
```C
|
||||
glm_vec_normalize_to(vec, result);
|
||||
```
|
||||
like this function you may see `_to` postfix, this functions store results to another variables and save temp memory
|
||||
|
||||
|
||||
to call pre-compiled versions include header with `c` postfix, c means call. Pre-compiled versions are just wrappers.
|
||||
```C
|
||||
#include <cglm/call.h>
|
||||
```
|
||||
this header will include all heaers with c postfix. You need to call functions with c posfix:
|
||||
```C
|
||||
glmc_vec_normalize(vec);
|
||||
```
|
||||
|
||||
Function usage and parameters are documented inside related headers. You may see same parameter passed twice in some examples like this:
|
||||
```C
|
||||
glm_mat4_mul(m1, m2, m1);
|
||||
|
||||
/* or */
|
||||
glm_mat4_mul(m1, m1, m1);
|
||||
```
|
||||
the first two parameter are **[in]** and the last one is **[out]** parameter. After multiplied *m1* and *m2* the result is stored in *m1*. This is why we send *m1* twice. You may store result in different matrix, this just an example.
|
||||
|
||||
## How to send matrix to OpenGL
|
||||
|
||||
mat4 is array of vec4 and vec4 is array of floats. `glUniformMatrix4fv` functions accecpts `float*` as `value` (last param), so you can cast mat4 to float* or you can pass first column of matrix as beginning of memory of matrix:
|
||||
|
||||
Option 1: Send first column
|
||||
```C
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, matrix[0]);
|
||||
|
||||
/* array of matrices */
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, matrix[0][0]);
|
||||
```
|
||||
|
||||
Option 2: Cast matrix to pointer type (also valid for multiple dimensional arrays)
|
||||
```C
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, (float *)matrix);
|
||||
```
|
||||
|
||||
You can pass same way to another APIs e.g. Vulkan, DX...
|
||||
|
||||
## Notes
|
||||
|
||||
- This library uses float types only, does not support Integers, Double... yet
|
||||
- If headers are not working properly with your compiler, IDE please open an issue, because I'm using GCC and clang to test it maybe sometimes MSVC
|
||||
|
||||
**TODO:**
|
||||
- [ ] Unit tests (In Progress)
|
||||
- [ ] Unit tests for comparing cglm with glm results
|
||||
- [x] Add version info
|
||||
- [ ] Unaligned operations (e.g. `glm_umat4_mul`)
|
||||
- [ ] Extra documentation
|
||||
- [ ] ARM Neon Arch (In Progress)
|
1
external/cglm/_config.yml
vendored
Normal file
1
external/cglm/_config.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
theme: jekyll-theme-minimal
|
7
external/cglm/appveyor.yml
vendored
Normal file
7
external/cglm/appveyor.yml
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
image: Visual Studio 2017
|
||||
|
||||
build_script:
|
||||
- ps: >-
|
||||
cd win
|
||||
|
||||
.\build.bat
|
24
external/cglm/autogen.sh
vendored
Normal file
24
external/cglm/autogen.sh
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# Copyright (c), Recep Aslantas.
|
||||
#
|
||||
# MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
# Full license can be found in the LICENSE file
|
||||
#
|
||||
|
||||
cd $(dirname "$0")
|
||||
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
libtoolBin=$(which glibtoolize)
|
||||
libtoolBinDir=$(dirname "${libtoolBin}")
|
||||
|
||||
if [ ! -f "${libtoolBinDir}/libtoolize" ]; then
|
||||
ln -s $libtoolBin "${libtoolBinDir}/libtoolize"
|
||||
fi
|
||||
fi
|
||||
|
||||
autoheader
|
||||
libtoolize
|
||||
aclocal -I m4
|
||||
autoconf
|
||||
automake --add-missing --copy
|
30
external/cglm/build-deps.sh
vendored
Normal file
30
external/cglm/build-deps.sh
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
#! /bin/sh
|
||||
#
|
||||
# Copyright (c), Recep Aslantas.
|
||||
#
|
||||
# MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
# Full license can be found in the LICENSE file
|
||||
#
|
||||
|
||||
# check if deps are pulled
|
||||
git submodule update --init --recursive
|
||||
|
||||
# fix glibtoolize
|
||||
|
||||
cd $(dirname "$0")
|
||||
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
libtoolBin=$(which glibtoolize)
|
||||
libtoolBinDir=$(dirname "${libtoolBin}")
|
||||
ln -s $libtoolBin "${libtoolBinDir}/libtoolize"
|
||||
fi
|
||||
|
||||
# general deps: gcc make autoconf automake libtool cmake
|
||||
|
||||
# test - cmocka
|
||||
cd ./test/lib/cmocka
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
|
||||
make -j8
|
||||
cd ../../../../
|
57
external/cglm/configure.ac
vendored
Normal file
57
external/cglm/configure.ac
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
#*****************************************************************************
|
||||
# Copyright (c), Recep Aslantas. *
|
||||
# *
|
||||
# MIT License (MIT), http://opensource.org/licenses/MIT *
|
||||
# Full license can be found in the LICENSE file *
|
||||
# *
|
||||
#*****************************************************************************
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([cglm], [0.2.1], [info@recp.me])
|
||||
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
|
||||
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_CONFIG_SRCDIR([src/])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
|
||||
AC_PROG_INSTALL
|
||||
AM_PROG_AR
|
||||
|
||||
AC_ENABLE_SHARED
|
||||
AC_ENABLE_STATIC
|
||||
|
||||
LT_INIT
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB([m], [floor])
|
||||
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([limits.h \
|
||||
stddef.h \
|
||||
stdint.h \
|
||||
stdlib.h \
|
||||
string.h ])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_CHECK_HEADER_STDBOOL
|
||||
AC_C_INLINE
|
||||
AC_TYPE_INT32_T
|
||||
AC_TYPE_INT64_T
|
||||
AC_TYPE_SIZE_T
|
||||
AC_TYPE_UINT16_T
|
||||
AC_TYPE_UINT32_T
|
||||
AC_TYPE_UINT64_T
|
||||
AC_TYPE_UINT8_T
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_ERROR_AT_LINE
|
||||
|
||||
AC_CONFIG_FILES([makefile])
|
||||
|
||||
AC_OUTPUT
|
36
external/cglm/docs/make.bat
vendored
Normal file
36
external/cglm/docs/make.bat
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=python -msphinx
|
||||
)
|
||||
set SOURCEDIR=source
|
||||
set BUILDDIR=build
|
||||
set SPHINXPROJ=cglm
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The Sphinx module was not found. Make sure you have Sphinx installed,
|
||||
echo.then set the SPHINXBUILD environment variable to point to the full
|
||||
echo.path of the 'sphinx-build' executable. Alternatively you may add the
|
||||
echo.Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.http://sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
||||
|
||||
:end
|
||||
popd
|
52
external/cglm/docs/source/build.rst
vendored
Normal file
52
external/cglm/docs/source/build.rst
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
Building cglm
|
||||
================================
|
||||
|
||||
| **cglm** does not have external dependencies except for unit testing.
|
||||
| When you pulled cglm repo with submodules all dependencies will be pulled too.
|
||||
| `build-deps.sh` will pull all dependencies/submodules and build for you.
|
||||
|
||||
External dependencies:
|
||||
* cmocka - for unit testing
|
||||
|
||||
**NOTE:**
|
||||
If you only need to inline versions, you don't need to build **cglm**, you don't need to link it to your program.
|
||||
Just import cglm to your project as dependency / external lib by copy-paste then use it as usual
|
||||
|
||||
**Unix (Autotools):**
|
||||
|
||||
.. code-block:: bash
|
||||
:linenos:
|
||||
|
||||
$ sh ./build-deps.sh # run this only once (dependencies)
|
||||
|
||||
$ sh autogen.sh
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make check # run tests (optional)
|
||||
$ [sudo] make install # install to system (optional)
|
||||
|
||||
**make** will build cglm to **.libs** sub folder in project folder.
|
||||
If you don't want to install cglm to your system's folder you can get static and dynamic libs in this folder.
|
||||
|
||||
**Build dependencies (windows):**
|
||||
|
||||
Windows related build files, project files are located in win folder,
|
||||
make sure you are inside in cglm/win folder.
|
||||
|
||||
Code Analysis are enabled, it may take awhile to build.
|
||||
|
||||
.. code-block:: bash
|
||||
:linenos:
|
||||
|
||||
$ cd win
|
||||
$ .\build.bat
|
||||
|
||||
if *msbuild* is not worked (because of multi versions of Visual Studio)
|
||||
then try to build with *devenv*:
|
||||
|
||||
.. code-block:: bash
|
||||
:linenos:
|
||||
|
||||
$ devenv cglm.sln /Build Release
|
||||
|
||||
Currently tests are not available on Windows.
|
163
external/cglm/docs/source/conf.py
vendored
Normal file
163
external/cglm/docs/source/conf.py
vendored
Normal file
|
@ -0,0 +1,163 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# cglm documentation build configuration file, created by
|
||||
# sphinx-quickstart on Tue Jun 6 20:31:05 2017.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
# import os
|
||||
# import sys
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = []
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
#
|
||||
# source_suffix = ['.rst', '.md']
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'cglm'
|
||||
copyright = u'2017, Recep Aslantas'
|
||||
author = u'Recep Aslantas'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'0.2.1'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'0.2.1'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = None
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This patterns also effect to html_static_path and html_extra_path
|
||||
exclude_patterns = []
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = False
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = 'alabaster'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#
|
||||
# html_theme_options = {}
|
||||
|
||||
html_theme_options = {
|
||||
'github_banner': 'true',
|
||||
'github_button': 'true',
|
||||
'github_user': 'recp',
|
||||
'github_repo': 'cglm',
|
||||
'travis_button': 'true',
|
||||
'show_related': 'true',
|
||||
'fixed_sidebar': 'true'
|
||||
}
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
|
||||
# -- Options for HTMLHelp output ------------------------------------------
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'cglmdoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#
|
||||
# 'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#
|
||||
# 'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'cglm.tex', u'cglm Documentation',
|
||||
u'Recep Aslantas', 'manual'),
|
||||
]
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'cglm', u'cglm Documentation',
|
||||
[author], 1)
|
||||
]
|
||||
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'cglm', u'cglm Documentation',
|
||||
author, 'cglm', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
66
external/cglm/docs/source/getting_started.rst
vendored
Normal file
66
external/cglm/docs/source/getting_started.rst
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
Getting Started
|
||||
================================
|
||||
|
||||
**cglm** uses **glm** prefix for all functions e.g. glm_lookat. You can see supported types in common header file:
|
||||
|
||||
.. code-block:: c
|
||||
:linenos:
|
||||
|
||||
typedef float vec3[3];
|
||||
typedef int ivec3[3];
|
||||
typedef CGLM_ALIGN(16) float vec4[4];
|
||||
|
||||
typedef vec3 mat3[3];
|
||||
typedef vec4 mat4[4];
|
||||
|
||||
typedef vec4 versor;
|
||||
|
||||
As you can see types don't store extra informations in favor of space.
|
||||
You can send these values e.g. matrix to OpenGL directly without casting or calling a function like *value_ptr*
|
||||
|
||||
*vec4* and *mat4* requires 16 byte aligment because vec4 and mat4 operations are
|
||||
vectorized by SIMD instructions (SSE/AVX).
|
||||
|
||||
**NOTE:** Unaligned vec4 and unaligned mat4 operations will be supported in the future. Check todo list.
|
||||
Because you may want to multiply a CGLM matrix with external matrix.
|
||||
There is no guarantee that non-CGLM matrix is aligned. Unaligned types will have *u* prefix e.g. **umat4**
|
||||
|
||||
cglm provides a few way to call a function to do same operation.
|
||||
|
||||
* Inline - *glm_, glm_u*
|
||||
* aligned
|
||||
* unaligned (todo)
|
||||
* Pre-compiled - *glmc_, glmc_u*
|
||||
* aligned
|
||||
* unaligned (todo)
|
||||
|
||||
For instance **glm_mat4_mul** is inline (all *glm_* functions are inline), to make it non-inline (pre-compiled)
|
||||
call it as **glmc_mat4_mul** from library, to use unaligned version use **glm_umat4_mul** (todo).
|
||||
|
||||
Most functions have **dest** parameter for output. For instance mat4_mul func looks like this:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest)
|
||||
|
||||
The dest parameter is out parameter. Result will be stored in **dest**.
|
||||
Also in this case matrix multiplication order is dest = m1 * m2.
|
||||
|
||||
* Changing parameter order will change the multiplication order.
|
||||
* You can pass all parameter same (this is similar to m1 `*=` m1), you can pass **dest** as m1 or m2 (this is similar to m1 `*=` m2)
|
||||
|
||||
**v** postfix in function names
|
||||
-------------------------------
|
||||
|
||||
You may see **v** postfix in some function names, v stands for vector.
|
||||
For instance consider a function that accepts three parameters x, y, z.
|
||||
This function may be overloaded by **v** postfix to accept vector (vec3) instead of separate parameters.
|
||||
In some places the v means that it will be apply to a vector.
|
||||
|
||||
**_to** postfix in function names
|
||||
---------------------------------
|
||||
|
||||
*_to* version of function will store the result in specified parameter instead of in-out parameter.
|
||||
Some functions don't have _to prefix but they still behave like this e.g. glm_mat4_mul.
|
45
external/cglm/docs/source/index.rst
vendored
Normal file
45
external/cglm/docs/source/index.rst
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
.. cglm documentation master file, created by
|
||||
sphinx-quickstart on Tue Jun 6 20:31:05 2017.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to cglm's documentation!
|
||||
================================
|
||||
|
||||
**cglm** is optimized 3D math library written in C99 (compatible with C89).
|
||||
It is similar to original **glm** library except this is mainly for **C**
|
||||
|
||||
This library stores matrices as row-major order but in the future column-major
|
||||
is considered to be supported as optional.
|
||||
|
||||
Also currently only **float** type is supported for most operations.
|
||||
|
||||
**Features**
|
||||
|
||||
* general purpose matrix operations (mat4, mat3)
|
||||
* chain matrix multiplication (square only)
|
||||
* general purpose vector operations (cross, dot, rotate, proj, angle...)
|
||||
* affine transforms
|
||||
* matrix decomposition (extract rotation, scaling factor)
|
||||
* optimized affine transform matrices (mul, rigid-body inverse)
|
||||
* camera (lookat)
|
||||
* projections (ortho, perspective)
|
||||
* quaternions
|
||||
* euler angles / yaw-pitch-roll to matrix
|
||||
* extract euler angles
|
||||
* inline or pre-compiled function call
|
||||
* more features (todo)
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Table Of Contents:
|
||||
|
||||
build
|
||||
getting_started
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
15
external/cglm/gen-glmcall-header.py
vendored
Executable file
15
external/cglm/gen-glmcall-header.py
vendored
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
api_regex = re.compile(r'^CGLM_EXPORT\s*.*?\s*glmc_([a-zA-Z_0-9]*)', re.DOTALL | re.MULTILINE)
|
||||
inc_path = pathlib.Path(__file__).parent / 'include' / 'cglm'
|
||||
|
||||
with (inc_path / 'glm2call.h').open('w') as out:
|
||||
print('\n// Auto-generated, do not modify.', file=out)
|
||||
|
||||
for path in (inc_path / 'call').glob('**/*.h'):
|
||||
print('\n// {0}'.format(path.relative_to(inc_path)), file=out)
|
||||
for name in api_regex.findall(path.read_text()):
|
||||
print('#undef glm_{0}\n#define glm_{0} glmc_{0}'.format(name), file=out)
|
114
external/cglm/include/cglm/affine-mat.h
vendored
Normal file
114
external/cglm/include/cglm/affine-mat.h
vendored
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
/*
|
||||
Functions:
|
||||
CGLM_INLINE void glm_mul(mat4 m1, mat4 m2, mat4 dest);
|
||||
CGLM_INLINE void glm_inv_tr(mat4 mat);
|
||||
*/
|
||||
|
||||
#ifndef cglm_affine_mat_h
|
||||
#define cglm_affine_mat_h
|
||||
|
||||
#include "common.h"
|
||||
#include "mat4.h"
|
||||
|
||||
#ifdef CGLM_SSE_FP
|
||||
# include "simd/sse2/affine.h"
|
||||
#endif
|
||||
|
||||
#ifdef CGLM_AVX_FP
|
||||
# include "simd/avx/affine.h"
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief this is similar to glm_mat4_mul but specialized to affine transform
|
||||
*
|
||||
* Matrix format should be:
|
||||
* R R R X
|
||||
* R R R Y
|
||||
* R R R Z
|
||||
* 0 0 0 W
|
||||
*
|
||||
* this reduces some multiplications. It should be faster than mat4_mul.
|
||||
* if you are not sure about matrix format then DON'T use this! use mat4_mul
|
||||
*
|
||||
* @param[in] m1 affine matrix 1
|
||||
* @param[in] m2 affine matrix 2
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mul(mat4 m1, mat4 m2, mat4 dest) {
|
||||
#ifdef __AVX__
|
||||
glm_mul_avx(m1, m2, dest);
|
||||
#elif defined( __SSE__ ) || defined( __SSE2__ )
|
||||
glm_mul_sse2(m1, m2, dest);
|
||||
#else
|
||||
float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], a03 = m1[0][3],
|
||||
a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2], a13 = m1[1][3],
|
||||
a20 = m1[2][0], a21 = m1[2][1], a22 = m1[2][2], a23 = m1[2][3],
|
||||
a30 = m1[3][0], a31 = m1[3][1], a32 = m1[3][2], a33 = m1[3][3],
|
||||
|
||||
b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2],
|
||||
b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2],
|
||||
b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2],
|
||||
b30 = m2[3][0], b31 = m2[3][1], b32 = m2[3][2], b33 = m2[3][3];
|
||||
|
||||
dest[0][0] = a00 * b00 + a10 * b01 + a20 * b02;
|
||||
dest[0][1] = a01 * b00 + a11 * b01 + a21 * b02;
|
||||
dest[0][2] = a02 * b00 + a12 * b01 + a22 * b02;
|
||||
dest[0][3] = a03 * b00 + a13 * b01 + a23 * b02;
|
||||
|
||||
dest[1][0] = a00 * b10 + a10 * b11 + a20 * b12;
|
||||
dest[1][1] = a01 * b10 + a11 * b11 + a21 * b12;
|
||||
dest[1][2] = a02 * b10 + a12 * b11 + a22 * b12;
|
||||
dest[1][3] = a03 * b10 + a13 * b11 + a23 * b12;
|
||||
|
||||
dest[2][0] = a00 * b20 + a10 * b21 + a20 * b22;
|
||||
dest[2][1] = a01 * b20 + a11 * b21 + a21 * b22;
|
||||
dest[2][2] = a02 * b20 + a12 * b21 + a22 * b22;
|
||||
dest[2][3] = a03 * b20 + a13 * b21 + a23 * b22;
|
||||
|
||||
dest[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33;
|
||||
dest[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33;
|
||||
dest[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33;
|
||||
dest[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief inverse orthonormal rotation + translation matrix (ridig-body)
|
||||
*
|
||||
* @code
|
||||
* X = | R T | X' = | R' -R'T |
|
||||
* | 0 1 | | 0 1 |
|
||||
* @endcode
|
||||
*
|
||||
* @param[in,out] mat matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_inv_tr(mat4 mat) {
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
glm_inv_tr_sse2(mat);
|
||||
#else
|
||||
CGLM_ALIGN(16) mat3 r;
|
||||
CGLM_ALIGN(16) vec3 t;
|
||||
|
||||
/* rotate */
|
||||
glm_mat4_pick3t(mat, r);
|
||||
glm_mat4_ins3(r, mat);
|
||||
|
||||
/* translate */
|
||||
glm_mat3_mulv(r, mat[3], t);
|
||||
glm_vec_flipsign(t);
|
||||
glm_vec_copy(t, mat[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* cglm_affine_mat_h */
|
543
external/cglm/include/cglm/affine.h
vendored
Normal file
543
external/cglm/include/cglm/affine.h
vendored
Normal file
|
@ -0,0 +1,543 @@
|
|||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
/*
|
||||
Functions:
|
||||
CGLM_INLINE void glm_translate_to(mat4 m, vec3 v, mat4 dest);
|
||||
CGLM_INLINE void glm_translate(mat4 m, vec3 v);
|
||||
CGLM_INLINE void glm_translate_x(mat4 m, float to);
|
||||
CGLM_INLINE void glm_translate_y(mat4 m, float to);
|
||||
CGLM_INLINE void glm_translate_z(mat4 m, float to);
|
||||
CGLM_INLINE void glm_translate_make(mat4 m, vec3 v);
|
||||
CGLM_INLINE void glm_scale_to(mat4 m, vec3 v, mat4 dest);
|
||||
CGLM_INLINE void glm_scale_make(mat4 m, vec3 v);
|
||||
CGLM_INLINE void glm_scale(mat4 m, vec3 v);
|
||||
CGLM_INLINE void glm_scale1(mat4 m, float s);
|
||||
CGLM_INLINE void glm_scale_uni(mat4 m, float s);
|
||||
CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest);
|
||||
CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest);
|
||||
CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest);
|
||||
CGLM_INLINE void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc);
|
||||
CGLM_INLINE void glm_rotate_make(mat4 m, float angle, vec3 axis);
|
||||
CGLM_INLINE void glm_rotate_ndc(mat4 m, float angle, vec3 axis);
|
||||
CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis);
|
||||
CGLM_INLINE void glm_decompose_scalev(mat4 m, vec3 s);
|
||||
CGLM_INLINE bool glm_uniscaled(mat4 m);
|
||||
CGLM_INLINE void glm_decompose_rs(mat4 m, mat4 r, vec3 s);
|
||||
CGLM_INLINE void glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s);
|
||||
*/
|
||||
|
||||
#ifndef cglm_affine_h
|
||||
#define cglm_affine_h
|
||||
|
||||
#include "common.h"
|
||||
#include "vec4.h"
|
||||
#include "affine-mat.h"
|
||||
#include "util.h"
|
||||
|
||||
/*!
|
||||
* @brief translate existing transform matrix by v vector
|
||||
* and store result in dest
|
||||
*
|
||||
* @param[in] m affine transfrom
|
||||
* @param[in] v translate vector [x, y, z]
|
||||
* @param[out] dest translated matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate_to(mat4 m, vec3 v, mat4 dest) {
|
||||
mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
_mm_store_ps(dest[3],
|
||||
_mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_load_ps(t[0]),
|
||||
_mm_set1_ps(v[0])),
|
||||
_mm_mul_ps(_mm_load_ps(t[1]),
|
||||
_mm_set1_ps(v[1]))),
|
||||
_mm_add_ps(_mm_mul_ps(_mm_load_ps(t[2]),
|
||||
_mm_set1_ps(v[2])),
|
||||
_mm_load_ps(t[3]))))
|
||||
;
|
||||
|
||||
_mm_store_ps(dest[0], _mm_load_ps(m[0]));
|
||||
_mm_store_ps(dest[1], _mm_load_ps(m[1]));
|
||||
_mm_store_ps(dest[2], _mm_load_ps(m[2]));
|
||||
#else
|
||||
vec4 v1, v2, v3;
|
||||
|
||||
glm_vec4_scale(t[0], v[0], v1);
|
||||
glm_vec4_scale(t[1], v[1], v2);
|
||||
glm_vec4_scale(t[2], v[2], v3);
|
||||
|
||||
glm_vec4_add(v1, t[3], t[3]);
|
||||
glm_vec4_add(v2, t[3], t[3]);
|
||||
glm_vec4_add(v3, t[3], t[3]);
|
||||
|
||||
glm__memcpy(float, dest, t, sizeof(mat4));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief translate existing transform matrix by v vector
|
||||
* and stores result in same matrix
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] v translate vector [x, y, z]
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate(mat4 m, vec3 v) {
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
_mm_store_ps(m[3],
|
||||
_mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]),
|
||||
_mm_set1_ps(v[0])),
|
||||
_mm_mul_ps(_mm_load_ps(m[1]),
|
||||
_mm_set1_ps(v[1]))),
|
||||
_mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]),
|
||||
_mm_set1_ps(v[2])),
|
||||
_mm_load_ps(m[3]))))
|
||||
;
|
||||
#else
|
||||
vec4 v1, v2, v3;
|
||||
|
||||
glm_vec4_scale(m[0], v[0], v1);
|
||||
glm_vec4_scale(m[1], v[1], v2);
|
||||
glm_vec4_scale(m[2], v[2], v3);
|
||||
|
||||
glm_vec4_add(v1, m[3], m[3]);
|
||||
glm_vec4_add(v2, m[3], m[3]);
|
||||
glm_vec4_add(v3, m[3], m[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief translate existing transform matrix by x factor
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] x x factor
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate_x(mat4 m, float x) {
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
_mm_store_ps(m[3],
|
||||
_mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]),
|
||||
_mm_set1_ps(x)),
|
||||
_mm_load_ps(m[3])))
|
||||
;
|
||||
#else
|
||||
vec4 v1;
|
||||
glm_vec4_scale(m[0], x, v1);
|
||||
glm_vec4_add(v1, m[3], m[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief translate existing transform matrix by y factor
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] y y factor
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate_y(mat4 m, float y) {
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
_mm_store_ps(m[3],
|
||||
_mm_add_ps(_mm_mul_ps(_mm_load_ps(m[1]),
|
||||
_mm_set1_ps(y)),
|
||||
_mm_load_ps(m[3])))
|
||||
;
|
||||
#else
|
||||
vec4 v1;
|
||||
glm_vec4_scale(m[1], y, v1);
|
||||
glm_vec4_add(v1, m[3], m[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief translate existing transform matrix by z factor
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] z z factor
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate_z(mat4 m, float z) {
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
_mm_store_ps(m[3],
|
||||
_mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]),
|
||||
_mm_set1_ps(z)),
|
||||
_mm_load_ps(m[3])))
|
||||
;
|
||||
#else
|
||||
vec4 v1;
|
||||
glm_vec4_scale(m[2], z, v1);
|
||||
glm_vec4_add(v1, m[3], m[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW translate transform matrix by v vector
|
||||
*
|
||||
* @param[out] m affine transfrom
|
||||
* @param[in] v translate vector [x, y, z]
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate_make(mat4 m, vec3 v) {
|
||||
mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
glm_translate_to(t, v, m);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief scale existing transform matrix by v vector
|
||||
* and store result in dest
|
||||
*
|
||||
* @param[in] m affine transfrom
|
||||
* @param[in] v scale vector [x, y, z]
|
||||
* @param[out] dest scaled matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_scale_to(mat4 m, vec3 v, mat4 dest) {
|
||||
glm_vec4_scale(m[0], v[0], dest[0]);
|
||||
glm_vec4_scale(m[1], v[1], dest[1]);
|
||||
glm_vec4_scale(m[2], v[2], dest[2]);
|
||||
|
||||
glm_vec4_copy(m[3], dest[3]);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW scale matrix by v vector
|
||||
*
|
||||
* @param[out] m affine transfrom
|
||||
* @param[in] v scale vector [x, y, z]
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_scale_make(mat4 m, vec3 v) {
|
||||
mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
glm_scale_to(t, v, m);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief scales existing transform matrix by v vector
|
||||
* and stores result in same matrix
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] v scale vector [x, y, z]
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_scale(mat4 m, vec3 v) {
|
||||
glm_scale_to(m, v, m);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief DEPRECATED! Use glm_scale_uni
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_scale1(mat4 m, float s) {
|
||||
vec3 v = { s, s, s };
|
||||
glm_scale_to(m, v, m);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief applies uniform scale to existing transform matrix v = [s, s, s]
|
||||
* and stores result in same matrix
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] s scale factor
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_scale_uni(mat4 m, float s) {
|
||||
vec3 v = { s, s, s };
|
||||
glm_scale_to(m, v, m);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief rotate existing transform matrix around X axis by angle
|
||||
* and store result in dest
|
||||
*
|
||||
* @param[in] m affine transfrom
|
||||
* @param[in] angle angle (radians)
|
||||
* @param[out] dest rotated matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_rotate_x(mat4 m, float angle, mat4 dest) {
|
||||
float cosVal;
|
||||
float sinVal;
|
||||
mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
|
||||
cosVal = cosf(angle);
|
||||
sinVal = sinf(angle);
|
||||
|
||||
t[1][1] = cosVal;
|
||||
t[1][2] = sinVal;
|
||||
t[2][1] = -sinVal;
|
||||
t[2][2] = cosVal;
|
||||
|
||||
glm_mat4_mul(m, t, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief rotate existing transform matrix around Y axis by angle
|
||||
* and store result in dest
|
||||
*
|
||||
* @param[in] m affine transfrom
|
||||
* @param[in] angle angle (radians)
|