mirror of https://github.com/mosra/magnum.git
Browse Source
It seems like a bad idea, but it will: * Improve portability, as `Int` will be always 32bit. * Improve readability, as `std::int32_t` is just plain ugly and too complicated to write. * Improve consistency and reduce confusion, as it's not good to mix `int`, `std::int32_t`, `GLint`, `khronos_int_t` and whatnot in one codebase. * Possibly reduce compilation time, because including all ~35k lines worth of GL headers just for one GLfloat typedef is even worse than now forbidden #include <iostream> in headers.pull/278/head
6 changed files with 302 additions and 99 deletions
@ -0,0 +1,72 @@ |
|||||||
|
namespace Magnum { |
||||||
|
/** @page types Type system |
||||||
|
|
||||||
|
@brief Type aliases, naming and compatibility with OpenGL and GLSL types |
||||||
|
|
||||||
|
@section types-builtin Builtin types |
||||||
|
|
||||||
|
%Magnum provides typedefs for builtin integral and floating-point arithmetic |
||||||
|
types to ensure portability (e.g. Int is *always* 32bit), maintain consistency |
||||||
|
and reduce confusion (e.g. `std::int32_t`, `int` and `GLint` all refer to the |
||||||
|
same type). |
||||||
|
|
||||||
|
| %Magnum type | Size | Equivalent GLSL type | |
||||||
|
| ------------------ | -------------- | -------------------- | |
||||||
|
| @ref UnsignedByte | 8bit unsigned | | |
||||||
|
| @ref Byte | 8bit signed | | |
||||||
|
| @ref UnsignedShort | 16bit unsigned | | |
||||||
|
| @ref Short | 16bit signed | | |
||||||
|
| @ref UnsignedInt | 32bit unsigned | `uint` | |
||||||
|
| @ref Int | 32bit signed | `int` | |
||||||
|
| @ref UnsignedLong | 64bit unsigned | | |
||||||
|
| @ref Long | 64bit signed | | |
||||||
|
| @ref Float | 32bit | `float` | |
||||||
|
| @ref Double | 64bit | `double` | |
||||||
|
|
||||||
|
Types not meant to be used in arithmetic (such as `bool` or `std::size_t`) or |
||||||
|
types which cannot be directly passed to GLSL shaders (such as `long double`) |
||||||
|
have no typedefs. |
||||||
|
|
||||||
|
Types from the above table are then used to define other types. All following |
||||||
|
types are aliases of corresponding types in Math namespace. No suffix after type |
||||||
|
name means @ref Float underlying type, `ui` means @ref UnsignedInt underlying |
||||||
|
type, `i` is @ref Int underlying type and `d` is for @ref Double underlying type. |
||||||
|
|
||||||
|
@section types-matrix Matrix/vector types |
||||||
|
|
||||||
|
| %Magnum vector type | Equivalent GLSL type | |
||||||
|
| ---------------------------------------------- | ------------------------- | |
||||||
|
| @ref Vector2, @ref Vector3, @ref Vector4 | `vec2`, `vec3`, `vec4` | |
||||||
|
| @ref Vector2ui, @ref Vector3ui, @ref Vector4ui | `uvec2`, `uvec3`, `uvec4` | |
||||||
|
| @ref Vector2i, @ref Vector3i, @ref Vector4i | `ivec2`, `ivec3`, `ivec4` | |
||||||
|
| @ref Vector2d, @ref Vector3d, @ref Vector4d | `dvec2`, `dvec3`, `dvec4` | |
||||||
|
|
||||||
|
| %Magnum matrix type | Equivalent GLSL type | |
||||||
|
| --------------------------------- | ------------------------------------ | |
||||||
|
| @ref Matrix2 or @ref Matrix2d | `mat2`/`mat2x2` or `dmat2`/`dmat2x2` | |
||||||
|
| @ref Matrix3 or @ref Matrix3d | `mat3`/`mat3x3` or `dmat3`/`dmat3x3` | |
||||||
|
| @ref Matrix4 or @ref Matrix4d | `mat4`/`mat4x4` or `dmat3`/`dmat4x4` | |
||||||
|
| @ref Matrix2x3 or @ref Matrix2x3d | `mat2x3` or `dmat2x3` | |
||||||
|
| @ref Matrix3x2 or @ref Matrix3x2d | `mat3x2` or `dmat3x2` | |
||||||
|
| @ref Matrix2x4 or @ref Matrix2x4d | `mat2x4` or `dmat2x4` | |
||||||
|
| @ref Matrix4x2 or @ref Matrix4x2d | `mat4x2` or `dmat4x2` | |
||||||
|
| @ref Matrix3x4 or @ref Matrix3x4d | `mat3x4` or `dmat3x4` | |
||||||
|
| @ref Matrix4x3 or @ref Matrix4x3d | `mat4x3` or `dmat4x3` | |
||||||
|
|
||||||
|
Any super- or sub-class of the same size and underlying type can be used |
||||||
|
equivalently (e.g. Math::Vector or Color3 instead of @ref Vector3). |
||||||
|
|
||||||
|
@section types-other Other types |
||||||
|
|
||||||
|
Other types, which don't have their GLSL equivalent, are: |
||||||
|
|
||||||
|
- @ref Rectangle or @ref Rectanglei |
||||||
|
- @ref Complex or @ref Complexd, @ref DualComplex or @ref DualComplexd |
||||||
|
- @ref Quaternion or @ref Quaterniond, @ref DualQuaternion or @ref DualQuaterniond |
||||||
|
|
||||||
|
These types can be used in GLSL either by extracting values from their |
||||||
|
underlying structure or converting them to types supported by GLSL (e.g. |
||||||
|
quaternion to matrix). |
||||||
|
|
||||||
|
*/ |
||||||
|
} |
||||||
@ -0,0 +1,45 @@ |
|||||||
|
#ifndef Magnum_Types_h |
||||||
|
#define Magnum_Types_h |
||||||
|
/*
|
||||||
|
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Magnum is free software: you can redistribute it and/or modify |
||||||
|
it under the terms of the GNU Lesser General Public License version 3 |
||||||
|
only, as published by the Free Software Foundation. |
||||||
|
|
||||||
|
Magnum is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU Lesser General Public License version 3 for more details. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Declarations of built-in types |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <cstdint> |
||||||
|
|
||||||
|
#include "magnumConfigure.h" |
||||||
|
|
||||||
|
namespace Magnum { |
||||||
|
|
||||||
|
/* Documented in Magnum.h */ |
||||||
|
typedef std::uint8_t UnsignedByte; |
||||||
|
typedef std::int8_t Byte; |
||||||
|
typedef std::uint16_t UnsignedShort; |
||||||
|
typedef std::int16_t Short; |
||||||
|
typedef std::uint32_t UnsignedInt; |
||||||
|
typedef std::int32_t Int; |
||||||
|
typedef std::uint64_t UnsignedLong; |
||||||
|
typedef std::int64_t Long; |
||||||
|
typedef float Float; |
||||||
|
|
||||||
|
#ifndef MAGNUM_TARGET_GLES |
||||||
|
typedef double Double; |
||||||
|
#endif |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
#endif |
||||||
Loading…
Reference in new issue