mirror of https://github.com/mosra/magnum.git
Browse Source
Builds and passes tests at least with GCC 4.6 and 4.7. Conflicts: src/CMakeLists.txt src/Math/Matrix4.h src/Math/Test/CMakeLists.txt src/Mesh.cpp src/MeshTools/CompressIndices.h src/MeshTools/Tipsify.cpp src/Physics/Test/ShapeGroupTest.cpp src/Primitives/Icosphere.h src/SceneGraph/Camera.cpp src/Test/SwizzleTest.cpp src/Trade/MeshData3D.cpp src/magnumCompatibility.h
267 changed files with 18320 additions and 3501 deletions
@ -0,0 +1,49 @@
|
||||
Bug reports, feature requests or code contributions are always very welcome. |
||||
To make things easier, here are a few tips: |
||||
|
||||
Reporting bugs, requesting features |
||||
----------------------------------- |
||||
|
||||
- Best way to report bugs and request new features is to use GitHub |
||||
[issues](https://github.com/mosra/magnum/issues), but you can contact me |
||||
also any other way. |
||||
|
||||
Code contribution |
||||
----------------- |
||||
|
||||
- Building and installing Magnum is described in the |
||||
[documentation](http://mosra.cz/blog/magnum-doc/building.html). |
||||
- Follow the project coding guidelines. In short - try to match style of |
||||
surrounding code and avoid any trailing whitespace. When in doubt, consult |
||||
coding guidelines, which are available also |
||||
[online](http://mosra.cz/blog/magnum-doc/coding-style.html). |
||||
- Document your code. When updating or adding new API, make sure that Doxygen |
||||
documentation is up to date. Run |
||||
|
||||
doxygen |
||||
|
||||
in project root to generate the documentation and check that your |
||||
modifications didn't add any warnings. |
||||
- Build unit tests (`-DBUILD_TESTS=ON` parameter to CMake) and run them |
||||
using |
||||
|
||||
ctest --output-on-failure |
||||
|
||||
in build directory. All tests should always pass. Add new tests or modify |
||||
the existing to make sure new code is properly covered (if possible). Here |
||||
is a [short tutorial](http://mosra.cz/blog/corrade-doc/unit-testing.html) to |
||||
help you with creating unit tests. |
||||
- Best way to contribute is by using GitHub |
||||
[pull requests](https://github.com/mosra/magnum/pulls) - fork the repository |
||||
and make pull request from feature branch. You can also send patches via |
||||
e-mail or contact me any other way. |
||||
- All your code will be released under license of the project, so make sure |
||||
you (or your employers) have no problems with it. |
||||
|
||||
Contact |
||||
------- |
||||
|
||||
- Website - http://mosra.cz/blog/ |
||||
- GitHub - https://github.com/mosra/magnum |
||||
- E-mail - mosra@centrum.cz |
||||
- Jabber - mosra@jabbim.cz |
||||
@ -0,0 +1,8 @@
|
||||
namespace Magnum { |
||||
/** @page features Feature overview |
||||
@brief Fundamental principles and design goals |
||||
|
||||
- @subpage matrix-vector - @copybrief matrix-vector |
||||
- @subpage collision-detection - @copybrief collision-detection |
||||
*/ |
||||
} |
||||
@ -0,0 +1,181 @@
|
||||
namespace Magnum { namespace Math { |
||||
/** @page matrix-vector Operations with matrices and vectors |
||||
|
||||
@brief Introduction to essential classes of the graphics pipeline. |
||||
|
||||
@tableofcontents |
||||
|
||||
Matrices and vectors are the most important part of graphics programming and |
||||
one of goals of %Magnum is to make their usage as intuitive as possible. This |
||||
page will overview their usage and introduce some tricks to make your life |
||||
easier. |
||||
|
||||
@section matrix-vector-hierarchy Matrix and vector classes |
||||
|
||||
%Magnum has three main matrix and vector classes: RectangularMatrix, (square) |
||||
Matrix and Vector. To achieve greatest code reuse, %Matrix is internally |
||||
square %RectangularMatrix and %Vector is internally one-column |
||||
%RectangularMatrix. Both vectors and matrices can have arbitrary size (known |
||||
at compile time) and can store any meaningful type. |
||||
|
||||
Each subclass brings some specialization to its superclass and for most common |
||||
vector and matrix sizes there are specialized classes Matrix3 and Matrix4, |
||||
implementing various transformation in 2D and 3D, Vector2, Vector3 and Vector4, |
||||
implementing direct access to named components. Functions of each class try to |
||||
return the most specialized type known to make subsequent operations more |
||||
convenient - columns of %RectangularMatrix are returned as %Vector, but when |
||||
accessing columns of e.g. %Matrix3, they are returned as %Vector3. |
||||
|
||||
There are also even more specialized subclasses - Point2D, Point3D for |
||||
creating points with homogeneous coordinates and Color3, Color4 for color |
||||
handling and conversion. |
||||
|
||||
@section matrix-vector-construction Constructing matrices and vectors |
||||
|
||||
Default constructors of RectangularMatrix and Vector (and Vector2, Vector3, |
||||
Vector4, Color3) create zero-filled objects. Matrix (and Matrix3, Matrix4) is |
||||
by default constructed as identity matrix. Point2D and Point3D have |
||||
homogeneous component set to one, Color4 has alpha value set to opaque. |
||||
@code |
||||
RectangularMatrix<2, 3, int> a; // zero-filled |
||||
Vector<3, int> b; // zero-filled |
||||
|
||||
Matrix<3, int> identity; // diagonal set to 1 |
||||
Matrix<3, int> zero(Matrix<3, int>::Zero); // zero-filled |
||||
|
||||
Point2D<int> c; // {0, 0, 1} |
||||
Point3D<int> d; // {0, 0, 0, 1} |
||||
|
||||
Color4<float> black1; // {0.0f, 0.0f, 0.0f, 1.0f} |
||||
Color4<unsigned char> black2; // {0, 0, 0, 255} |
||||
@endcode |
||||
|
||||
Most common and most efficient way to create matrix or vector is to pass |
||||
values of all components to the constructor. |
||||
@code |
||||
Matrix3<int> mat(0, 1, 2, |
||||
3, 4, 5, |
||||
6, 7, 8); // column-major (see explanation why below) |
||||
|
||||
Vector3<int> vec(0, 1, 2); |
||||
@endcode |
||||
All constructors check number of passed arguments and the errors are catched |
||||
at compile time. |
||||
|
||||
You can specify all components of vector or whole diagonal of square matrix at |
||||
once: |
||||
@code |
||||
Matrix3<int> diag(Matrix3<int>::Identity, 2); // diagonal set to 2, zeros elsewhere |
||||
Vector3<int> fill(10); // {10, 10, 10} |
||||
@endcode |
||||
|
||||
Vectors are commonly used to specify various axes and scaling coefficients in |
||||
transformations, you can use convenience functions instead of typing out all |
||||
other elements: |
||||
@code |
||||
Matrix4::rotation(deg(5.0f), Vector3::xAxis()); // {1.0f, 0.0f, 0.0f} |
||||
Matrix3::translation(Vector2::yAxis(2.0f)); // {0.0f, 2.0f} |
||||
Matrix4::scaling(Vector3::zScale(-10.0f)); // {1.0f, 1.0f, -10.0f} |
||||
@endcode |
||||
|
||||
It is possible to create matrices from other matrices and vectors with the |
||||
same row count; vectors from vector and scalar: |
||||
@code |
||||
RectangularMatrix<2, 3, int> a; |
||||
Vector3<int> b, c; |
||||
Matrix3<int> mat = Matrix3<int>::from(b, a, c); |
||||
Vector<8, int> vec = Vector<8, int>::from(1, b, 2, c); |
||||
@endcode |
||||
|
||||
It is also possible to create them from an C-style array. The function does |
||||
simple type cast without any copying, so it's possible to conveniently operate |
||||
on the array itself: |
||||
@code |
||||
int[] mat = { 2, 4, 6, |
||||
1, 3, 5 }; |
||||
RectangularMatrix<2, 3, int>::from(mat) *= 2; // mat == { 4, 8, 12, 2, 6, 10 } |
||||
@endcode |
||||
Note that unlike constructors, this function has no way to check whether the |
||||
array is long enough to contain all elements, so use with caution. |
||||
|
||||
You can also convert between data types: |
||||
@code |
||||
Vector4<float> floating(1.3f, 2.7f, -15.0f, 7.0f); |
||||
Vector4<int> integral(Vector4<int>::from(floating)); // {1, 2, -15, 7} |
||||
@endcode |
||||
|
||||
@section matrix-vector-component-access Accessing matrix and vector components |
||||
|
||||
Column vectors of matrices and vector components can be accessed using square |
||||
brackets, there is also round bracket operator for accessing matrix components |
||||
directly: |
||||
@code |
||||
RectangularMatrix<3, 2, int> a; |
||||
a[2] /= 2; // third column (column major indexing, see explanation below) |
||||
a[0][1] = 5; // first column, second element |
||||
a(0, 1) += 3; // first column, second element (preferred) |
||||
|
||||
Vector<3, int> b; |
||||
b[1] = 1; // second element |
||||
@endcode |
||||
For accessing matrix element prefer round bracket operator, as it is possibly |
||||
faster than the double square brackets (but never slower) and isn't prone to |
||||
compiler mis-optimizations. |
||||
|
||||
Fixed-size vector subclasses have functions for accessing named components |
||||
and subparts: |
||||
@code |
||||
Vector4<int> a; |
||||
int x = a.x(); |
||||
a.y() += 5; |
||||
|
||||
Vector3<int> xyz = a.xyz(); |
||||
xyz.xy() *= 5; |
||||
@endcode |
||||
Color3 and Color4 name their components `rgba` instead of `xyzw`. |
||||
|
||||
For more involved operations with components there are two swizzle() functions, |
||||
they have the same features, but one is guaranteed to do most of the work at |
||||
compile-time, while the second has more convenient syntax: |
||||
@code |
||||
Vector4<int> original(-1, 2, 3, 4); |
||||
Vector4<int> bgra = swizzle<'b', 'g', 'r', 'a'>(original); // { 3, 2, -1, 4 } |
||||
Vector<6, int> a10rgb = swizzle(original, "a10rgb"); // { 4, 1, 0, -1, 2, 3 } |
||||
@endcode |
||||
|
||||
@section matrix-vector-column-major Matrices are column-major and vectors are columns |
||||
|
||||
OpenGL matrices are column-major, thus it is reasonable to have matrices in |
||||
%Magnum also column major (and vectors as columns). This has naturally some |
||||
implications and it may differ from what is common in mathematics: |
||||
|
||||
- Order of template arguments in specification of RectangularMatrix is also |
||||
column-major: |
||||
@code |
||||
RectangularMatrix<2, 3, int> mat; // two columns, three rows |
||||
@endcode |
||||
- Order of components in matrix constructors is also column-major, so the |
||||
elements passed in constructor doesn't need to be reordered internally |
||||
before putting them into data array: |
||||
@code |
||||
Matrix3<int> mat(0, 1, 2, |
||||
3, 4, 5, |
||||
6, 7, 8); // first column is {0, 1, 2} |
||||
@endcode |
||||
- Element accessing order is also column-major. It costs virtually no time to |
||||
return reference to portion of data array as column vector, thus the bracket |
||||
operator is accessing columns. Returned vector has also its own bracket |
||||
operator, which is indexing rows. To avoid confusion, first parameter of |
||||
round bracket operator is thus also column index. |
||||
@code |
||||
mat[0] *= 2; // first column |
||||
mat[2][0] = 5; // first element of first column vector |
||||
mat(2, 0) += 3; // first element of first column |
||||
@endcode |
||||
- Various algorithms which commonly operate on matrix rows (such as |
||||
@ref Algorithms::GaussJordan "Gauss-Jordan elimination") have faster |
||||
alternatives which operate on columns. It's then up to user decision to |
||||
operate with transposed matrices or use the slower non-transposed |
||||
alternative of the algorithm. |
||||
*/ |
||||
}} |
||||
@ -1,7 +0,0 @@
|
||||
namespace Magnum { namespace Physics { |
||||
/** @page physics Physics library |
||||
@brief Collision detection and rigid body dynamics. |
||||
|
||||
@subpage collision-detection |
||||
*/ |
||||
}} |
||||
@ -0,0 +1,22 @@
|
||||
/** @page unsupported Unsupported OpenGL features |
||||
|
||||
Some functionality, which is either soon-to-be deprecated or isn't proven to |
||||
add any performance gains, is not supported in %Magnum. |
||||
|
||||
@section unsupported-features Unsupported features |
||||
|
||||
- Luminance texture formats (OpenGL ES) are not supported, as they are |
||||
deprecated in OpenGL ES 3.0 and not present in core desktop OpenGL. |
||||
- Fixed precision data types (OpenGL ES) are not supported, as they occupy the |
||||
same memory as floats and they aren't faster than floats on current hardware |
||||
anymore. |
||||
|
||||
@section unsupported-extensions Unsupported extensions |
||||
|
||||
- @extension{INTEL,map_texture} negatively affects texture access performance. |
||||
Combination of buffer mapping and pixel buffers might be of the same or |
||||
better performance, without affecting texture access speed. |
||||
- @extension{NV,draw_texture} can be done with framebuffer blitting and |
||||
doesn't make any full-screen postprocessing easier, as shaders are excluded. |
||||
|
||||
*/ |
||||
@ -0,0 +1,6 @@
|
||||
if(NOT TARGET_GLES) |
||||
add_subdirectory(GL) |
||||
else() |
||||
add_subdirectory(GLES3) |
||||
add_subdirectory(KHR) |
||||
endif() |
||||
@ -0,0 +1 @@
|
||||
install(FILES glcorearb.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GL) |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
install(FILES gl3.h gl3platform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GLES3) |
||||
@ -0,0 +1,30 @@
|
||||
#ifndef __gl3platform_h_ |
||||
#define __gl3platform_h_ |
||||
|
||||
/* $Revision: 18437 $ on $Date:: 2012-07-08 23:31:39 -0700 #$ */ |
||||
|
||||
/*
|
||||
* This document is licensed under the SGI Free Software B License Version |
||||
* 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
|
||||
*/ |
||||
|
||||
/* Platform-specific types and definitions for OpenGL ES 3.X gl3.h
|
||||
* |
||||
* Adopters may modify khrplatform.h and this file to suit their platform. |
||||
* You are encouraged to submit all modifications to the Khronos group so that |
||||
* they can be included in future versions of this file. Please submit changes |
||||
* by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
|
||||
* by filing a bug against product "OpenGL-ES" component "Registry". |
||||
*/ |
||||
|
||||
#include <KHR/khrplatform.h> |
||||
|
||||
#ifndef GL_APICALL |
||||
#define GL_APICALL KHRONOS_APICALL |
||||
#endif |
||||
|
||||
#ifndef GL_APIENTRY |
||||
#define GL_APIENTRY KHRONOS_APIENTRY |
||||
#endif |
||||
|
||||
#endif /* __gl3platform_h_ */ |
||||
@ -0,0 +1 @@
|
||||
install(FILES khrplatform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/KHR) |
||||
@ -0,0 +1,269 @@
|
||||
#ifndef __khrplatform_h_ |
||||
#define __khrplatform_h_ |
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2009 The Khronos Group Inc. |
||||
** |
||||
** Permission is hereby granted, free of charge, to any person obtaining a |
||||
** copy of this software and/or associated documentation files (the |
||||
** "Materials"), to deal in the Materials without restriction, including |
||||
** without limitation the rights to use, copy, modify, merge, publish, |
||||
** distribute, sublicense, and/or sell copies of the Materials, and to |
||||
** permit persons to whom the Materials are 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 Materials. |
||||
** |
||||
** THE MATERIALS ARE 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 |
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
*/ |
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
* |
||||
* $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $ |
||||
* |
||||
* Adopters may modify this file to suit their platform. Adopters are |
||||
* encouraged to submit platform specific modifications to the Khronos |
||||
* group so that they can be included in future versions of this file. |
||||
* Please submit changes by sending them to the public Khronos Bugzilla |
||||
* (http://khronos.org/bugzilla) by filing a bug against product
|
||||
* "Khronos (general)" component "Registry". |
||||
* |
||||
* A predefined template which fills in some of the bug fields can be |
||||
* reached using http://tinyurl.com/khrplatform-h-bugreport, but you
|
||||
* must create a Bugzilla login first. |
||||
* |
||||
* |
||||
* See the Implementer's Guidelines for information about where this file |
||||
* should be located on your system and for more details of its use: |
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
* |
||||
* This file should be included as |
||||
* #include <KHR/khrplatform.h> |
||||
* by Khronos client API header files that use its types and defines. |
||||
* |
||||
* The types in khrplatform.h should only be used to define API-specific types. |
||||
* |
||||
* Types defined in khrplatform.h: |
||||
* khronos_int8_t signed 8 bit |
||||
* khronos_uint8_t unsigned 8 bit |
||||
* khronos_int16_t signed 16 bit |
||||
* khronos_uint16_t unsigned 16 bit |
||||
* khronos_int32_t signed 32 bit |
||||
* khronos_uint32_t unsigned 32 bit |
||||
* khronos_int64_t signed 64 bit |
||||
* khronos_uint64_t unsigned 64 bit |
||||
* khronos_intptr_t signed same number of bits as a pointer |
||||
* khronos_uintptr_t unsigned same number of bits as a pointer |
||||
* khronos_ssize_t signed size |
||||
* khronos_usize_t unsigned size |
||||
* khronos_float_t signed 32 bit floating point |
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds |
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in |
||||
* nanoseconds |
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds |
||||
* khronos_boolean_enum_t enumerated boolean type. This should |
||||
* only be used as a base type when a client API's boolean type is |
||||
* an enum. Client APIs which use an integer or other type for |
||||
* booleans cannot use this as the base type for their boolean. |
||||
* |
||||
* Tokens defined in khrplatform.h: |
||||
* |
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values. |
||||
* |
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0. |
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0. |
||||
* |
||||
* Calling convention macros defined in this file: |
||||
* KHRONOS_APICALL |
||||
* KHRONOS_APIENTRY |
||||
* KHRONOS_APIATTRIBUTES |
||||
* |
||||
* These may be used in function prototypes as: |
||||
* |
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname( |
||||
* int arg1, |
||||
* int arg2) KHRONOS_APIATTRIBUTES; |
||||
*/ |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL |
||||
*------------------------------------------------------------------------- |
||||
* This precedes the return type of the function in the function prototype. |
||||
*/ |
||||
#if defined(_WIN32) && !defined(__SCITECH_SNAP__) |
||||
# define KHRONOS_APICALL __declspec(dllimport) |
||||
#elif defined (__SYMBIAN32__) |
||||
# define KHRONOS_APICALL IMPORT_C |
||||
#else |
||||
# define KHRONOS_APICALL |
||||
#endif |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY |
||||
*------------------------------------------------------------------------- |
||||
* This follows the return type of the function and precedes the function |
||||
* name in the function prototype. |
||||
*/ |
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) |
||||
/* Win32 but not WinCE */ |
||||
# define KHRONOS_APIENTRY __stdcall |
||||
#else |
||||
# define KHRONOS_APIENTRY |
||||
#endif |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES |
||||
*------------------------------------------------------------------------- |
||||
* This follows the closing parenthesis of the function prototype arguments. |
||||
*/ |
||||
#if defined (__ARMCC_2__) |
||||
#define KHRONOS_APIATTRIBUTES __softfp |
||||
#else |
||||
#define KHRONOS_APIATTRIBUTES |
||||
#endif |
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions |
||||
*-----------------------------------------------------------------------*/ |
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__) |
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h> |
||||
*/ |
||||
#include <stdint.h> |
||||
typedef int32_t khronos_int32_t; |
||||
typedef uint32_t khronos_uint32_t; |
||||
typedef int64_t khronos_int64_t; |
||||
typedef uint64_t khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#elif defined(__VMS ) || defined(__sgi) |
||||
|
||||
/*
|
||||
* Using <inttypes.h> |
||||
*/ |
||||
#include <inttypes.h> |
||||
typedef int32_t khronos_int32_t; |
||||
typedef uint32_t khronos_uint32_t; |
||||
typedef int64_t khronos_int64_t; |
||||
typedef uint64_t khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__) |
||||
|
||||
/*
|
||||
* Win32 |
||||
*/ |
||||
typedef __int32 khronos_int32_t; |
||||
typedef unsigned __int32 khronos_uint32_t; |
||||
typedef __int64 khronos_int64_t; |
||||
typedef unsigned __int64 khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#elif defined(__sun__) || defined(__digital__) |
||||
|
||||
/*
|
||||
* Sun or Digital |
||||
*/ |
||||
typedef int khronos_int32_t; |
||||
typedef unsigned int khronos_uint32_t; |
||||
#if defined(__arch64__) || defined(_LP64) |
||||
typedef long int khronos_int64_t; |
||||
typedef unsigned long int khronos_uint64_t; |
||||
#else |
||||
typedef long long int khronos_int64_t; |
||||
typedef unsigned long long int khronos_uint64_t; |
||||
#endif /* __arch64__ */ |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#elif 0 |
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support |
||||
*/ |
||||
typedef int khronos_int32_t; |
||||
typedef unsigned int khronos_uint32_t; |
||||
#define KHRONOS_SUPPORT_INT64 0 |
||||
#define KHRONOS_SUPPORT_FLOAT 0 |
||||
|
||||
#else |
||||
|
||||
/*
|
||||
* Generic fallback |
||||
*/ |
||||
#include <stdint.h> |
||||
typedef int32_t khronos_int32_t; |
||||
typedef uint32_t khronos_uint32_t; |
||||
typedef int64_t khronos_int64_t; |
||||
typedef uint64_t khronos_uint64_t; |
||||
#define KHRONOS_SUPPORT_INT64 1 |
||||
#define KHRONOS_SUPPORT_FLOAT 1 |
||||
|
||||
#endif |
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms |
||||
*/ |
||||
typedef signed char khronos_int8_t; |
||||
typedef unsigned char khronos_uint8_t; |
||||
typedef signed short int khronos_int16_t; |
||||
typedef unsigned short int khronos_uint16_t; |
||||
typedef signed long int khronos_intptr_t; |
||||
typedef unsigned long int khronos_uintptr_t; |
||||
typedef signed long int khronos_ssize_t; |
||||
typedef unsigned long int khronos_usize_t; |
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT |
||||
/*
|
||||
* Float type |
||||
*/ |
||||
typedef float khronos_float_t; |
||||
#endif |
||||
|
||||
#if KHRONOS_SUPPORT_INT64 |
||||
/* Time types
|
||||
* |
||||
* These types can be used to represent a time interval in nanoseconds or |
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number |
||||
* of nanoseconds since some arbitrary system event (e.g. since the last |
||||
* time the system booted). The Unadjusted System Time is an unsigned |
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals |
||||
* may be either signed or unsigned. |
||||
*/ |
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t; |
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t; |
||||
#endif |
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits. |
||||
*/ |
||||
#ifndef KHRONOS_MAX_ENUM |
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF |
||||
#endif |
||||
|
||||
/*
|
||||
* Enumerated boolean type |
||||
* |
||||
* Values other than zero should be considered to be true. Therefore |
||||
* comparisons should not be made against KHRONOS_TRUE. |
||||
*/ |
||||
typedef enum { |
||||
KHRONOS_FALSE = 0, |
||||
KHRONOS_TRUE = 1, |
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM |
||||
} khronos_boolean_enum_t; |
||||
|
||||
#endif /* __khrplatform_h_ */ |
||||
@ -0,0 +1,117 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "Buffer.h" |
||||
|
||||
#include <Utility/Debug.h> |
||||
|
||||
#include "Context.h" |
||||
#include "Extensions.h" |
||||
#include "Implementation/State.h" |
||||
#include "Implementation/BufferState.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
Buffer::CopyImplementation Buffer::copyImplementation = &Buffer::copyImplementationDefault; |
||||
#endif |
||||
Buffer::SetDataImplementation Buffer::setDataImplementation = &Buffer::setDataImplementationDefault; |
||||
Buffer::SetSubDataImplementation Buffer::setSubDataImplementation = &Buffer::setSubDataImplementationDefault; |
||||
|
||||
void Buffer::initializeContextBasedFunctionality(Context* context) { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
if(context->isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) { |
||||
Debug() << "Buffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; |
||||
|
||||
copyImplementation = &Buffer::copyImplementationDSA; |
||||
setDataImplementation = &Buffer::setDataImplementationDSA; |
||||
setSubDataImplementation = &Buffer::setSubDataImplementationDSA; |
||||
} |
||||
#else |
||||
static_cast<void>(context); |
||||
#endif |
||||
} |
||||
|
||||
Buffer::~Buffer() { |
||||
GLuint* bindings = Context::current()->state()->buffer->bindings; |
||||
|
||||
/* Remove all current bindings from the state */ |
||||
for(std::size_t i = 1; i != Implementation::BufferState::TargetCount; ++i) |
||||
if(bindings[i] == _id) bindings[i] = 0; |
||||
|
||||
glDeleteBuffers(1, &_id); |
||||
} |
||||
|
||||
void Buffer::bind(Target target, GLuint id) { |
||||
GLuint& bound = Context::current()->state()->buffer->bindings[Implementation::BufferState::indexForTarget(target)]; |
||||
|
||||
/* Already bound, nothing to do */ |
||||
if(bound == id) return; |
||||
|
||||
/* Bind the buffer otherwise */ |
||||
bound = id; |
||||
glBindBuffer(static_cast<GLenum>(target), id); |
||||
} |
||||
|
||||
Buffer::Target Buffer::bindInternal(Target hint) { |
||||
GLuint* bindings = Context::current()->state()->buffer->bindings; |
||||
GLuint& hintBinding = bindings[Implementation::BufferState::indexForTarget(hint)]; |
||||
|
||||
/* Shortcut - if already bound to hint, return */ |
||||
if(hintBinding == _id) return hint; |
||||
|
||||
/* Return first target in which the buffer is bound */ |
||||
for(std::size_t i = 1; i != Implementation::BufferState::TargetCount; ++i) |
||||
if(bindings[i] == _id) return Implementation::BufferState::targetForIndex[i]; |
||||
|
||||
/* Bind the buffer to hint target otherwise */ |
||||
hintBinding = _id; |
||||
glBindBuffer(static_cast<GLenum>(hint), _id); |
||||
return hint; |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
void Buffer::copyImplementationDefault(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { |
||||
glCopyBufferSubData(static_cast<GLenum>(read->bindInternal(Target::CopyRead)), static_cast<GLenum>(write->bindInternal(Target::CopyWrite)), readOffset, writeOffset, size); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void Buffer::copyImplementationDSA(Buffer* read, Buffer* write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) { |
||||
glNamedCopyBufferSubDataEXT(read->_id, write->_id, readOffset, writeOffset, size); |
||||
} |
||||
#endif |
||||
#endif |
||||
|
||||
void Buffer::setDataImplementationDefault(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { |
||||
glBufferData(static_cast<GLenum>(bindInternal(_targetHint)), size, data, static_cast<GLenum>(usage)); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void Buffer::setDataImplementationDSA(GLsizeiptr size, const GLvoid* data, Buffer::Usage usage) { |
||||
glNamedBufferDataEXT(_id, size, data, static_cast<GLenum>(usage)); |
||||
} |
||||
#endif |
||||
|
||||
void Buffer::setSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data) { |
||||
glBufferSubData(static_cast<GLenum>(bindInternal(_targetHint)), offset, size, data); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void Buffer::setSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data) { |
||||
glNamedBufferSubDataEXT(_id, offset, size, data); |
||||
} |
||||
#endif |
||||
|
||||
} |
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "BufferedImage.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
template<std::uint8_t dimensions> void BufferedImage<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { |
||||
_components = components; |
||||
_type = type; |
||||
_size = size; |
||||
_buffer.setData(pixelSize(_components, _type)*size.product(), data, usage); |
||||
} |
||||
|
||||
template class BufferedImage<1>; |
||||
template class BufferedImage<2>; |
||||
template class BufferedImage<3>; |
||||
|
||||
} |
||||
@ -0,0 +1,265 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "Context.h" |
||||
|
||||
#include <string> |
||||
#include <unordered_map> |
||||
#include <Utility/Debug.h> |
||||
|
||||
#include "AbstractShaderProgram.h" |
||||
#include "AbstractTexture.h" |
||||
#include "Buffer.h" |
||||
#include "BufferedTexture.h" |
||||
#include "Extensions.h" |
||||
#include "IndexedMesh.h" |
||||
#include "Mesh.h" |
||||
#include "Implementation/State.h" |
||||
|
||||
using namespace std; |
||||
|
||||
namespace Magnum { |
||||
|
||||
const std::vector<Extension>& Extension::extensions(Version version) { |
||||
#define _extension(prefix, vendor, extension) \ |
||||
{Extensions::prefix::vendor::extension::Index, Extensions::prefix::vendor::extension::requiredVersion(), Extensions::prefix::vendor::extension::coreVersion(), Extensions::prefix::vendor::extension::string()} |
||||
static const std::vector<Extension> empty; |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
static const std::vector<Extension> extensions{ |
||||
_extension(GL,EXT,texture_filter_anisotropic)}; |
||||
static const std::vector<Extension> extensions300{ |
||||
_extension(GL,APPLE,flush_buffer_range), |
||||
_extension(GL,APPLE,vertex_array_object), |
||||
_extension(GL,ARB,color_buffer_float), |
||||
_extension(GL,ARB,half_float_pixel), |
||||
_extension(GL,ARB,texture_float), |
||||
_extension(GL,ARB,depth_buffer_float), |
||||
_extension(GL,ARB,texture_rg), |
||||
_extension(GL,EXT,framebuffer_object), |
||||
_extension(GL,EXT,packed_depth_stencil), |
||||
_extension(GL,EXT,framebuffer_blit), |
||||
_extension(GL,EXT,framebuffer_multisample), |
||||
_extension(GL,EXT,gpu_shader4), |
||||
_extension(GL,EXT,packed_float), |
||||
_extension(GL,EXT,texture_array), |
||||
_extension(GL,EXT,texture_compression_rgtc), |
||||
_extension(GL,EXT,texture_shared_exponent), |
||||
_extension(GL,EXT,framebuffer_sRGB), |
||||
_extension(GL,EXT,draw_buffers2), |
||||
_extension(GL,EXT,texture_integer), |
||||
_extension(GL,EXT,transform_feedback), |
||||
_extension(GL,NV,half_float), |
||||
_extension(GL,NV,depth_buffer_float), |
||||
_extension(GL,NV,conditional_render)}; |
||||
static const std::vector<Extension> extensions310{ |
||||
_extension(GL,ARB,texture_rectangle), |
||||
_extension(GL,ARB,draw_instanced), |
||||
_extension(GL,ARB,texture_buffer_object), |
||||
_extension(GL,ARB,uniform_buffer_object), |
||||
_extension(GL,ARB,copy_buffer), |
||||
_extension(GL,EXT,texture_snorm), |
||||
_extension(GL,NV,primitive_restart)}; |
||||
static const std::vector<Extension> extensions320{ |
||||
_extension(GL,ARB,geometry_shader4), |
||||
_extension(GL,ARB,depth_clamp), |
||||
_extension(GL,ARB,draw_elements_base_vertex), |
||||
_extension(GL,ARB,fragment_coord_conventions), |
||||
_extension(GL,ARB,provoking_vertex), |
||||
_extension(GL,ARB,seamless_cube_map), |
||||
_extension(GL,ARB,sync), |
||||
_extension(GL,ARB,texture_multisample), |
||||
_extension(GL,ARB,vertex_array_bgra)}; |
||||
static const std::vector<Extension> extensions330{ |
||||
_extension(GL,ARB,instanced_arrays), |
||||
_extension(GL,ARB,blend_func_extended), |
||||
_extension(GL,ARB,explicit_attrib_location), |
||||
_extension(GL,ARB,occlusion_query2), |
||||
_extension(GL,ARB,sampler_objects), |
||||
_extension(GL,ARB,shader_bit_encoding), |
||||
_extension(GL,ARB,texture_rgb10_a2ui), |
||||
_extension(GL,ARB,texture_swizzle), |
||||
_extension(GL,ARB,timer_query), |
||||
_extension(GL,ARB,vertex_type_2_10_10_10_rev)}; |
||||
static const std::vector<Extension> extensions400{ |
||||
_extension(GL,ARB,draw_buffers_blend), |
||||
_extension(GL,ARB,sample_shading), |
||||
_extension(GL,ARB,texture_cube_map_array), |
||||
_extension(GL,ARB,texture_gather), |
||||
_extension(GL,ARB,texture_query_lod), |
||||
_extension(GL,ARB,draw_indirect), |
||||
_extension(GL,ARB,gpu_shader5), |
||||
_extension(GL,ARB,gpu_shader_fp64), |
||||
_extension(GL,ARB,shader_subroutine), |
||||
_extension(GL,ARB,tessellation_shader), |
||||
_extension(GL,ARB,texture_buffer_object_rgb32), |
||||
_extension(GL,ARB,transform_feedback2), |
||||
_extension(GL,ARB,transform_feedback3)}; |
||||
static const std::vector<Extension> extensions410{ |
||||
_extension(GL,ARB,ES2_compatibility), |
||||
_extension(GL,ARB,get_program_binary), |
||||
_extension(GL,ARB,separate_shader_objects), |
||||
_extension(GL,ARB,shader_precision), |
||||
_extension(GL,ARB,vertex_attrib_64bit), |
||||
_extension(GL,ARB,viewport_array)}; |
||||
static const std::vector<Extension> extensions420{ |
||||
_extension(GL,ARB,texture_compression_bptc), |
||||
_extension(GL,ARB,base_instance), |
||||
_extension(GL,ARB,shading_language_420pack), |
||||
_extension(GL,ARB,transform_feedback_instanced), |
||||
_extension(GL,ARB,compressed_texture_pixel_storage), |
||||
_extension(GL,ARB,conservative_depth), |
||||
_extension(GL,ARB,internalformat_query), |
||||
_extension(GL,ARB,map_buffer_alignment), |
||||
_extension(GL,ARB,shader_atomic_counters), |
||||
_extension(GL,ARB,shader_image_load_store), |
||||
_extension(GL,ARB,texture_storage)}; |
||||
static const std::vector<Extension> extensions430; |
||||
#undef _extension |
||||
#else |
||||
static const std::vector<Extension> extensions; |
||||
static const std::vector<Extension> extensionsES200; |
||||
static const std::vector<Extension> extensionsES300; |
||||
#endif |
||||
|
||||
switch(version) { |
||||
case Version::None: return extensions; |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case Version::GL210: return empty; |
||||
case Version::GL300: return extensions300; |
||||
case Version::GL310: return extensions310; |
||||
case Version::GL320: return extensions320; |
||||
case Version::GL330: return extensions330; |
||||
case Version::GL400: return extensions400; |
||||
/* case Version::GLES200: */ |
||||
case Version::GL410: return extensions410; |
||||
case Version::GL420: return extensions420; |
||||
/* case Version::GLES300: */ |
||||
case Version::GL430: return extensions430; |
||||
#else |
||||
case Version::GLES200: return extensionsES200; |
||||
case Version::GLES300: return extensionsES300; |
||||
#endif |
||||
} |
||||
|
||||
return empty; |
||||
} |
||||
|
||||
Context* Context::_current = nullptr; |
||||
|
||||
Context::Context() { |
||||
/* Version */ |
||||
glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion); |
||||
glGetIntegerv(GL_MINOR_VERSION, &_minorVersion); |
||||
_version = static_cast<Version>(_majorVersion*100+_minorVersion*10); |
||||
|
||||
/* Get first future (not supported) version */ |
||||
vector<Version> versions{ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
Version::GL300, |
||||
Version::GL310, |
||||
Version::GL320, |
||||
Version::GL330, |
||||
Version::GL400, |
||||
Version::GL410, |
||||
Version::GL420, |
||||
Version::GL430, |
||||
#else |
||||
Version::GLES200, |
||||
Version::GLES300, |
||||
#endif |
||||
Version::None |
||||
}; |
||||
size_t future = 0; |
||||
while(versions[future] != Version::None && versions[future] < _version) |
||||
++future; |
||||
|
||||
/* List of extensions from future versions (extensions from current and
|
||||
previous versions should be supported automatically, so we don't need |
||||
to check for them) */ |
||||
unordered_map<string, Extension> futureExtensions; |
||||
for(size_t i = future; i != versions.size(); ++i) |
||||
for(const Extension& extension: Extension::extensions(versions[i])) |
||||
futureExtensions.insert(make_pair(extension._string, extension)); |
||||
|
||||
/* Check for presence of extensions in future versions */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
if(isVersionSupported(Version::GL300)) { |
||||
#else |
||||
if(isVersionSupported(Version::GLES300)) { |
||||
#endif |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
GLuint index = 0; |
||||
const char* extension; |
||||
while((extension = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, index++)))) { |
||||
auto found = futureExtensions.find(extension); |
||||
if(found != futureExtensions.end()) { |
||||
_supportedExtensions.push_back(found->second); |
||||
extensionStatus.set(found->second._index); |
||||
} |
||||
} |
||||
#endif |
||||
|
||||
/* OpenGL 2.1 / OpenGL ES 2.0 doesn't have glGetStringi() */ |
||||
} else { |
||||
/* Don't crash when glGetString() returns nullptr */ |
||||
const char* e = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
||||
if(e) { |
||||
vector<string> extensions = Corrade::Utility::split(e, ' '); |
||||
for(const string& extension: extensions) { |
||||
auto found = futureExtensions.find(extension); |
||||
if(found != futureExtensions.end()) { |
||||
_supportedExtensions.push_back(found->second); |
||||
extensionStatus.set(found->second._index); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* Set this context as current */ |
||||
CORRADE_ASSERT(!_current, "Context: Another context currently active", ); |
||||
_current = this; |
||||
|
||||
/* Initialize state tracker */ |
||||
_state = new Implementation::State; |
||||
|
||||
/* Initialize functionality based on current OpenGL version and extensions */ |
||||
AbstractShaderProgram::initializeContextBasedFunctionality(this); |
||||
AbstractTexture::initializeContextBasedFunctionality(this); |
||||
Buffer::initializeContextBasedFunctionality(this); |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
BufferedTexture::initializeContextBasedFunctionality(this); |
||||
#endif |
||||
IndexedMesh::initializeContextBasedFunctionality(this); |
||||
Mesh::initializeContextBasedFunctionality(this); |
||||
} |
||||
|
||||
Context::~Context() { |
||||
CORRADE_ASSERT(_current == this, "Context: Cannot destroy context which is not currently active", ); |
||||
delete _state; |
||||
_current = nullptr; |
||||
} |
||||
|
||||
Version Context::supportedVersion(initializer_list<Version> versions) const { |
||||
for(auto version: versions) |
||||
if(isVersionSupported(version)) return version; |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
return Version::GL210; |
||||
#else |
||||
return Version::GLES200; |
||||
#endif |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,273 @@
|
||||
#ifndef Magnum_Context_h |
||||
#define Magnum_Context_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 Enum Version, class Magnum::Context, Magnum::Extension |
||||
*/ |
||||
|
||||
#include <bitset> |
||||
#include <vector> |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
#include "magnumVisibility.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
namespace Implementation { |
||||
class State; |
||||
} |
||||
#endif |
||||
|
||||
/** @brief OpenGL version */ |
||||
enum class Version: GLint { |
||||
None = 0, /**< @brief Unspecified */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
GL210 = 210, /**< @brief OpenGL 2.1 / GLSL 1.20 */ |
||||
GL300 = 300, /**< @brief OpenGL 3.0 / GLSL 1.30 */ |
||||
GL310 = 310, /**< @brief OpenGL 3.1 / GLSL 1.40 */ |
||||
GL320 = 320, /**< @brief OpenGL 3.2 / GLSL 1.50 */ |
||||
GL330 = 330, /**< @brief OpenGL 3.3, GLSL 3.30 */ |
||||
GL400 = 400, /**< @brief OpenGL 4.0, GLSL 4.00 */ |
||||
GL410 = 410, /**< @brief OpenGL 4.1, GLSL 4.10 */ |
||||
GL420 = 420, /**< @brief OpenGL 4.2, GLSL 4.20 */ |
||||
GL430 = 430, /**< @brief OpenGL 4.3, GLSL 4.30 */ |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief OpenGL ES 2.0, GLSL ES 1.00 |
||||
* |
||||
* All the functionality is present in OpenGL 4.2 (extension |
||||
* @extension{ARB,ES2_compatibility}), so on desktop OpenGL this is |
||||
* equivalent to @ref Version "Version::GL410". |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
GLES200 = 410, |
||||
#else |
||||
GLES200 = 200, |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief OpenGL ES 3.0, GLSL ES 3.00 |
||||
* |
||||
* All the functionality is present in OpenGL 4.3 (extension |
||||
* @extension{ARB,ES3_compatibility}), so on desktop OpenGL this is the |
||||
* equivalent to @ref Version "Version::GL430". |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
GLES300 = 430 |
||||
#else |
||||
GLES300 = 300 |
||||
#endif |
||||
}; |
||||
|
||||
/**
|
||||
@brief Run-time information about OpenGL extension |
||||
|
||||
Encapsulates runtime information about OpenGL extension, such as name string, |
||||
minimal required OpenGL version and version in which the extension was adopted |
||||
to core. |
||||
|
||||
See also Extensions namespace, which contain compile-time information about |
||||
OpenGL extensions. |
||||
*/ |
||||
class MAGNUM_EXPORT Extension { |
||||
friend class Context; |
||||
|
||||
public: |
||||
/** @brief All extensions for given OpenGL version */ |
||||
static const std::vector<Extension>& extensions(Version version); |
||||
|
||||
/** @brief Minimal version required by this extension */ |
||||
inline constexpr Version requiredVersion() const { return _requiredVersion; } |
||||
|
||||
/** @brief Version in which this extension was adopted to core */ |
||||
inline constexpr Version coreVersion() const { return _coreVersion; } |
||||
|
||||
/** @brief %Extension string */ |
||||
inline constexpr const char* string() const { return _string; } |
||||
|
||||
private: |
||||
/* GCC 4.6 doesn't like const members, as std::vector doesn't have
|
||||
proper move semantic yet */ |
||||
std::size_t _index; |
||||
Version _requiredVersion; |
||||
Version _coreVersion; |
||||
const char* _string; |
||||
|
||||
inline constexpr Extension(std::size_t index, Version requiredVersion, Version coreVersion, const char* string): _index(index), _requiredVersion(requiredVersion), _coreVersion(coreVersion), _string(string) {} |
||||
}; |
||||
|
||||
/**
|
||||
@brief OpenGL context |
||||
|
||||
Provides access to version and extension information. |
||||
*/ |
||||
class MAGNUM_EXPORT Context { |
||||
Context(const Context&) = delete; |
||||
Context(Context&&) = delete; |
||||
Context& operator=(const Context&) = delete; |
||||
Context& operator=(Context&&) = delete; |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Constructor |
||||
* |
||||
* @see @fn_gl{Get} with @def_gl{MAJOR_VERSION}, @def_gl{MINOR_VERSION}, |
||||
* @fn_gl{GetString} with @def_gl{EXTENSIONS} |
||||
*/ |
||||
Context(); |
||||
~Context(); |
||||
|
||||
/** @brief Current context */ |
||||
inline static Context* current() { return _current; } |
||||
|
||||
/** @brief OpenGL version */ |
||||
inline Version version() const { return _version; } |
||||
|
||||
/** @brief Major OpenGL version (e.g. `4`) */ |
||||
inline GLint majorVersion() const { return _majorVersion; } |
||||
|
||||
/** @brief Minor OpenGL version (e.g. `3`) */ |
||||
inline GLint minorVersion() const { return _minorVersion; } |
||||
|
||||
/**
|
||||
* @brief Vendor string |
||||
* |
||||
* @see @fn_gl{GetString} with @def_gl{VENDOR} |
||||
*/ |
||||
inline std::string vendorString() const { |
||||
return reinterpret_cast<const char*>(glGetString(GL_VENDOR)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Renderer string |
||||
* |
||||
* @see @fn_gl{GetString} with @def_gl{RENDERER} |
||||
*/ |
||||
inline std::string rendererString() const { |
||||
return reinterpret_cast<const char*>(glGetString(GL_RENDERER)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Version string |
||||
* |
||||
* @see @fn_gl{GetString} with @def_gl{VERSION} |
||||
*/ |
||||
inline std::string versionString() const { |
||||
return reinterpret_cast<const char*>(glGetString(GL_VERSION)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Shading language version string |
||||
* |
||||
* @see @fn_gl{GetString} with @def_gl{SHADING_LANGUAGE_VERSION} |
||||
*/ |
||||
inline std::string shadingLanguageVersionString() const { |
||||
return reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION)); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Supported extensions |
||||
* |
||||
* The list contains only extensions from OpenGL versions newer than |
||||
* the current. |
||||
* |
||||
* @see isExtensionSupported(), Extension::extensions() |
||||
*/ |
||||
inline const std::vector<Extension>& supportedExtensions() const { |
||||
return _supportedExtensions; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Whether given OpenGL version is supported |
||||
* |
||||
* @see supportedVersion() |
||||
*/ |
||||
inline bool isVersionSupported(Version version) const { |
||||
return _version >= version; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Get supported OpenGL version |
||||
* |
||||
* Returns first supported OpenGL version from passed list. Convenient |
||||
* equivalent to subsequent isVersionSupported() calls, e.g.: |
||||
* @code |
||||
* Version v = isVersionSupported(Version::GL330) ? Version::GL330 : Version::GL210; |
||||
* Version v = supportedVersion({Version::GL330, Version::GL210}); |
||||
* @endcode |
||||
* |
||||
* If no version from the list is supported, returns lowest available |
||||
* OpenGL version (@ref Version "Version::GL210" for desktop OpenGL, |
||||
* @ref Version "Version::GLES200" for OpenGL ES). |
||||
*/ |
||||
Version supportedVersion(std::initializer_list<Version> versions) const; |
||||
|
||||
/**
|
||||
* @brief Whether given extension is supported |
||||
* |
||||
* %Extensions usable with this function are listed in Extensions |
||||
* namespace in header Extensions.h. Example usage: |
||||
* @code |
||||
* if(Context::current()->isExtensionSupported<Extensions::GL::ARB::tessellation_shader>()) { |
||||
* // draw fancy detailed model
|
||||
* } else { |
||||
* // texture fallback
|
||||
* } |
||||
* @endcode |
||||
* |
||||
* @see isExtensionSupported(const Extension&) const |
||||
*/ |
||||
template<class T> inline bool isExtensionSupported() const { |
||||
return _version >= T::coreVersion() || (_version >= T::requiredVersion() && extensionStatus[T::Index]); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Whether given extension is supported |
||||
* |
||||
* Can be used e.g. for listing extensions available on current |
||||
* hardware, but for general usage prefer isExtensionSupported() const, |
||||
* as it does most operations in compile time. |
||||
* |
||||
* @see supportedExtensions(), Extension::extensions() |
||||
*/ |
||||
inline bool isExtensionSupported(const Extension& extension) const { |
||||
return _version >= extension._coreVersion || (_version >= extension._requiredVersion && extensionStatus[extension._index]); |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
inline Implementation::State* state() { return _state; } |
||||
#endif |
||||
|
||||
private: |
||||
static Context* _current; |
||||
|
||||
Version _version; |
||||
GLint _majorVersion; |
||||
GLint _minorVersion; |
||||
|
||||
std::bitset<128> extensionStatus; |
||||
std::vector<Extension> _supportedExtensions; |
||||
|
||||
Implementation::State* _state; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,125 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "EglContextHandler.h" |
||||
|
||||
#include <Utility/Debug.h> |
||||
|
||||
#include "Context.h" |
||||
|
||||
namespace Magnum { namespace Contexts { |
||||
|
||||
EglContextHandler::~EglContextHandler() { |
||||
eglDestroyContext(display, context); |
||||
eglDestroySurface(display, surface); |
||||
eglTerminate(display); |
||||
} |
||||
|
||||
VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) { |
||||
/* Initialize */ |
||||
display = eglGetDisplay(nativeDisplay); |
||||
if(!eglInitialize(display, nullptr, nullptr)) { |
||||
Error() << "Cannot initialize EGL:" << errorString(eglGetError()); |
||||
exit(1); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
EGLenum api = EGL_OPENGL_API; |
||||
#else |
||||
EGLenum api = EGL_OPENGL_ES_API; |
||||
#endif |
||||
if(!eglBindAPI(api)) { |
||||
Error() << "Cannot bind EGL API:" << errorString(eglGetError()); |
||||
exit(1); |
||||
} |
||||
|
||||
/* Choose EGL config */ |
||||
static const EGLint attribs[] = { |
||||
EGL_RED_SIZE, 1, |
||||
EGL_GREEN_SIZE, 1, |
||||
EGL_BLUE_SIZE, 1, |
||||
EGL_DEPTH_SIZE, 1, |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, |
||||
#else |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
||||
#endif |
||||
EGL_NONE |
||||
}; |
||||
EGLint configCount; |
||||
if(!eglChooseConfig(display, attribs, &config, 1, &configCount)) { |
||||
Error() << "Cannot get EGL visual config:" << errorString(eglGetError()); |
||||
exit(1); |
||||
} |
||||
|
||||
if(!configCount) { |
||||
Error() << "No matching EGL visual config available"; |
||||
exit(1); |
||||
} |
||||
|
||||
/* Get visual ID */ |
||||
EGLint visualId; |
||||
if(!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visualId)) { |
||||
Error() << "Cannot get native visual ID:" << errorString(eglGetError()); |
||||
exit(1); |
||||
} |
||||
|
||||
return visualId; |
||||
} |
||||
|
||||
void EglContextHandler::createContext(EGLNativeWindowType window) { |
||||
static const EGLint contextAttributes[] = { |
||||
#ifdef MAGNUM_TARGET_GLES |
||||
EGL_CONTEXT_CLIENT_VERSION, 2, |
||||
#endif |
||||
EGL_NONE |
||||
}; |
||||
if(!eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes)) { |
||||
Error() << "Cannot create EGL context:" << errorString(eglGetError()); |
||||
exit(1); |
||||
} |
||||
if(!(surface = eglCreateWindowSurface(display, config, window, NULL))) { |
||||
Error() << "Cannot create window surface:" << errorString(eglGetError()); |
||||
exit(1); |
||||
} |
||||
|
||||
/** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ |
||||
} |
||||
|
||||
const char* EglContextHandler::errorString(EGLint error) { |
||||
switch(error) { |
||||
#define _error(name) case name: return #name; |
||||
_error(EGL_SUCCESS) |
||||
_error(EGL_NOT_INITIALIZED) |
||||
_error(EGL_BAD_ACCESS) |
||||
_error(EGL_BAD_ALLOC) |
||||
_error(EGL_BAD_ATTRIBUTE) |
||||
_error(EGL_BAD_CONTEXT) |
||||
_error(EGL_BAD_CONFIG) |
||||
_error(EGL_BAD_CURRENT_SURFACE) |
||||
_error(EGL_BAD_DISPLAY) |
||||
_error(EGL_BAD_SURFACE) |
||||
_error(EGL_BAD_MATCH) |
||||
_error(EGL_BAD_PARAMETER) |
||||
_error(EGL_BAD_NATIVE_PIXMAP) |
||||
_error(EGL_BAD_NATIVE_WINDOW) |
||||
_error(EGL_CONTEXT_LOST) |
||||
#undef _error |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
}} |
||||
@ -1,86 +0,0 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "EglInterface.h" |
||||
|
||||
namespace Magnum { namespace Contexts { |
||||
|
||||
EglInterface::~EglInterface() { |
||||
eglDestroyContext(display, context); |
||||
eglDestroySurface(display, surface); |
||||
eglTerminate(display); |
||||
} |
||||
|
||||
VisualId EglInterface::getVisualId(EGLNativeDisplayType nativeDisplay) { |
||||
/* Initialize */ |
||||
display = eglGetDisplay(nativeDisplay); |
||||
eglInitialize(display, 0, 0); |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
eglBindAPI(EGL_OPENGL_API); |
||||
#else |
||||
eglBindAPI(EGL_OPENGL_ES_API); |
||||
#endif |
||||
|
||||
/* Choose EGL config */ |
||||
static const EGLint attribs[] = { |
||||
EGL_RED_SIZE, 1, |
||||
EGL_GREEN_SIZE, 1, |
||||
EGL_BLUE_SIZE, 1, |
||||
EGL_DEPTH_SIZE, 1, |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, |
||||
#else |
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
||||
#endif |
||||
EGL_NONE |
||||
}; |
||||
EGLint configCount; |
||||
if(!eglChooseConfig(display, attribs, &config, 1, &configCount)) { |
||||
Error() << "Cannot get EGL visual config"; |
||||
exit(1); |
||||
} |
||||
|
||||
/* Get visual ID */ |
||||
EGLint visualId; |
||||
if(!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &visualId)) { |
||||
Error() << "Cannot get native visual ID"; |
||||
exit(1); |
||||
} |
||||
|
||||
return visualId; |
||||
} |
||||
|
||||
void EglInterface::createContext(EGLNativeWindowType window) { |
||||
static const EGLint contextAttributes[] = { |
||||
#ifdef MAGNUM_TARGET_GLES |
||||
EGL_CONTEXT_CLIENT_VERSION, 2, |
||||
#endif |
||||
EGL_NONE |
||||
}; |
||||
context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes); |
||||
if(!context) { |
||||
Error() << "Cannot create EGL context"; |
||||
exit(1); |
||||
} |
||||
surface = eglCreateWindowSurface(display, config, window, NULL); |
||||
if(!surface) { |
||||
Error() << "Cannot create window surface"; |
||||
exit(1); |
||||
} |
||||
|
||||
/** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,109 @@
|
||||
#ifndef Magnum_DimensionTraits_h |
||||
#define Magnum_DimensionTraits_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. |
||||
*/ |
||||
|
||||
#include <cstdint> |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::DimensionTraits |
||||
*/ |
||||
|
||||
namespace Magnum { |
||||
|
||||
namespace Math { |
||||
template<std::size_t, class> class Vector; |
||||
template<class> class Vector2; |
||||
template<class> class Vector3; |
||||
|
||||
template<class> class Point2D; |
||||
template<class> class Point3D; |
||||
|
||||
template<class> class Matrix3; |
||||
template<class> class Matrix4; |
||||
} |
||||
|
||||
/** @brief Matrix, point and vector specializations for given dimension count */ |
||||
template<std::uint8_t dimensions, class T> struct DimensionTraits { |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
/**
|
||||
* @brief Vector type |
||||
* |
||||
* Math::Vector, Math::Vector2 or Math::Vector3 based on dimension count. |
||||
*/ |
||||
typedef U VectorType; |
||||
|
||||
/**
|
||||
* @brief Point type |
||||
* |
||||
* Floating-point Math::Point2D or Math::Point3D for 2D or 3D. No point |
||||
* type defined for one dimension and integral types. |
||||
*/ |
||||
typedef U PointType; |
||||
|
||||
/**
|
||||
* @brief Matrix type |
||||
* |
||||
* Floating-point Math::Matrix3 or Math::Matrix4 for 2D or 3D. No matrix |
||||
* type defined for one dimension and integral types. |
||||
*/ |
||||
typedef U MatrixType; |
||||
#endif |
||||
}; |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
/* One dimension */ |
||||
template<class T> struct DimensionTraits<1, T> { |
||||
typedef Math::Vector<1, T> VectorType; |
||||
}; |
||||
|
||||
/* Two dimensions - integral */ |
||||
template<class T> struct DimensionTraits<2, T> { |
||||
typedef Math::Vector2<T> VectorType; |
||||
}; |
||||
|
||||
/* Two dimensions - floating-point */ |
||||
template<> struct DimensionTraits<2, float> { |
||||
typedef Math::Vector2<float> VectorType; |
||||
typedef Math::Point2D<float> PointType; |
||||
typedef Math::Matrix3<float> MatrixType; |
||||
}; |
||||
template<> struct DimensionTraits<2, double> { |
||||
typedef Math::Vector2<double> VectorType; |
||||
typedef Math::Point2D<double> PointType; |
||||
typedef Math::Matrix3<double> MatrixType; |
||||
}; |
||||
|
||||
/* Three dimensions - integral */ |
||||
template<class T> struct DimensionTraits<3, T> { |
||||
typedef Math::Vector3<T> VectorType; |
||||
}; |
||||
|
||||
/* Three dimensions - floating-point */ |
||||
template<> struct DimensionTraits<3, float> { |
||||
typedef Math::Vector3<float> VectorType; |
||||
typedef Math::Point3D<float> PointType; |
||||
typedef Math::Matrix4<float> MatrixType; |
||||
}; |
||||
template<> struct DimensionTraits<3, double> { |
||||
typedef Math::Vector3<double> VectorType; |
||||
typedef Math::Point3D<double> PointType; |
||||
typedef Math::Matrix4<double> MatrixType; |
||||
}; |
||||
#endif |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,153 @@
|
||||
#ifndef Magnum_Extensions_h |
||||
#define Magnum_Extensions_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 Namespace Magnum::Extensions |
||||
*/ |
||||
|
||||
#include "Context.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief Compile-time information about OpenGL extensions |
||||
|
||||
Each extension is `struct` named hierarchically by prefix, vendor and |
||||
extension name, for example `GL::APPLE::vertex_array_object`. Each struct has |
||||
the same public methods as Extension class (requiredVersion(), coreVersion() |
||||
and string(), but these structs are better suited for compile-time decisions |
||||
rather than Extension instances. See Context::isExtensionSupported() for |
||||
example usage. |
||||
|
||||
@todo Manual indices for extensions, this has gaps |
||||
@todo Unhide ES2_compatibility, ES3_compatibility on ES |
||||
@todo Add ES and GL 4.3 extensions |
||||
*/ |
||||
namespace Extensions { |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
#define _extension(prefix, vendor, extension, _requiredVersion, _coreVersion) \ |
||||
struct extension { \
|
||||
enum: std::size_t { Index = __LINE__-1 }; \
|
||||
constexpr static Version requiredVersion() { return Version::_requiredVersion; } \
|
||||
constexpr static Version coreVersion() { return Version::_coreVersion; } \
|
||||
constexpr static const char* string() { return #prefix "_" #vendor "_" #extension; } \
|
||||
}; |
||||
namespace GL { |
||||
#line 1 |
||||
namespace AMD { |
||||
_extension(GL,AMD,shader_trinary_minmax, GL210, None) // #428
|
||||
} namespace APPLE { |
||||
_extension(GL,APPLE,flush_buffer_range, GL210, GL300) // #321
|
||||
_extension(GL,APPLE,vertex_array_object, GL210, GL300) // #273
|
||||
} namespace ARB { |
||||
_extension(GL,ARB,texture_rectangle, GL210, GL310) // #38
|
||||
_extension(GL,ARB,color_buffer_float, GL210, GL300) // #39
|
||||
_extension(GL,ARB,half_float_pixel, GL210, GL300) // #40
|
||||
_extension(GL,ARB,texture_float, GL210, GL300) // #41
|
||||
_extension(GL,ARB,depth_buffer_float, GL210, GL300) // #43
|
||||
_extension(GL,ARB,draw_instanced, GL210, GL310) // #44
|
||||
_extension(GL,ARB,geometry_shader4, GL210, GL320) // #47
|
||||
_extension(GL,ARB,instanced_arrays, GL210, GL330) // #49
|
||||
_extension(GL,ARB,texture_buffer_object, GL210, GL310) // #51
|
||||
_extension(GL,ARB,texture_rg, GL210, GL300) // #53
|
||||
_extension(GL,ARB,uniform_buffer_object, GL210, GL310) // #57
|
||||
_extension(GL,ARB,copy_buffer, /*?*/ GL210, GL310) // #59
|
||||
_extension(GL,ARB,depth_clamp, /*?*/ GL210, GL320) // #61
|
||||
_extension(GL,ARB,draw_elements_base_vertex, /*?*/ GL210, GL320) // #62
|
||||
_extension(GL,ARB,fragment_coord_conventions, /*?*/ GL210, GL320) // #63
|
||||
_extension(GL,ARB,provoking_vertex, /*?*/ GL210, GL320) // #64
|
||||
_extension(GL,ARB,seamless_cube_map, GL210, GL320) // #65
|
||||
_extension(GL,ARB,sync, GL310, GL320) // #66
|
||||
_extension(GL,ARB,texture_multisample, /*?*/ GL210, GL320) // #67
|
||||
_extension(GL,ARB,vertex_array_bgra, GL210, GL320) // #68
|
||||
_extension(GL,ARB,draw_buffers_blend, GL210, GL400) // #69
|
||||
_extension(GL,ARB,sample_shading, GL210, GL400) // #70
|
||||
_extension(GL,ARB,texture_cube_map_array, /*?*/ GL210, GL400) // #71
|
||||
_extension(GL,ARB,texture_gather, GL210, GL400) // #72
|
||||
_extension(GL,ARB,texture_query_lod, GL210, GL400) // #73
|
||||
_extension(GL,ARB,texture_compression_bptc, GL310, GL420) // #77
|
||||
_extension(GL,ARB,blend_func_extended, GL210, GL330) // #78
|
||||
_extension(GL,ARB,explicit_attrib_location, GL210, GL330) // #79
|
||||
_extension(GL,ARB,occlusion_query2, GL210, GL330) // #80
|
||||
_extension(GL,ARB,sampler_objects, GL210, GL330) // #81
|
||||
_extension(GL,ARB,shader_bit_encoding, /*?*/ GL210, GL330) // #82
|
||||
_extension(GL,ARB,texture_rgb10_a2ui, GL210, GL330) // #83
|
||||
_extension(GL,ARB,texture_swizzle, /*?*/ GL210, GL330) // #84
|
||||
_extension(GL,ARB,timer_query, /*?*/ GL210, GL330) // #85
|
||||
_extension(GL,ARB,vertex_type_2_10_10_10_rev, GL210, GL330) // #86
|
||||
_extension(GL,ARB,draw_indirect, GL310, GL400) // #87
|
||||
_extension(GL,ARB,gpu_shader5, GL320, GL400) // #88
|
||||
_extension(GL,ARB,gpu_shader_fp64, GL320, GL400) // #89
|
||||
_extension(GL,ARB,shader_subroutine, GL320, GL400) // #90
|
||||
_extension(GL,ARB,tessellation_shader, GL320, GL400) // #91
|
||||
_extension(GL,ARB,texture_buffer_object_rgb32, /*?*/ GL210, GL400) // #92
|
||||
_extension(GL,ARB,transform_feedback2, GL210, GL400) // #93
|
||||
_extension(GL,ARB,transform_feedback3, GL210, GL400) // #94
|
||||
_extension(GL,ARB,ES2_compatibility, /*?*/ GL210, GL410) // #95
|
||||
_extension(GL,ARB,get_program_binary, GL300, GL410) // #96
|
||||
_extension(GL,ARB,separate_shader_objects, GL210, GL410) // #97
|
||||
_extension(GL,ARB,shader_precision, GL400, GL410) // #98
|
||||
_extension(GL,ARB,vertex_attrib_64bit, GL300, GL410) // #99
|
||||
_extension(GL,ARB,viewport_array, GL210, GL410) // #100
|
||||
_extension(GL,ARB,base_instance, GL210, GL420) // #107
|
||||
_extension(GL,ARB,shading_language_420pack, GL300, GL420) // #108
|
||||
_extension(GL,ARB,transform_feedback_instanced, GL210, GL420) // #109
|
||||
_extension(GL,ARB,compressed_texture_pixel_storage, GL210, GL420) // #110
|
||||
_extension(GL,ARB,conservative_depth, GL300, GL420) // #111
|
||||
_extension(GL,ARB,internalformat_query, GL210, GL420) // #112
|
||||
_extension(GL,ARB,map_buffer_alignment, GL210, GL420) // #113
|
||||
_extension(GL,ARB,shader_atomic_counters, GL300, GL420) // #114
|
||||
_extension(GL,ARB,shader_image_load_store, GL300, GL420) // #115
|
||||
_extension(GL,ARB,texture_storage, GL210, GL420) // #117
|
||||
} namespace EXT { |
||||
_extension(GL,EXT,texture_filter_anisotropic, GL210, None) // #187
|
||||
_extension(GL,EXT,framebuffer_object, GL210, GL300) // #310
|
||||
_extension(GL,EXT,packed_depth_stencil, GL210, GL300) // #312
|
||||
_extension(GL,EXT,framebuffer_blit, GL210, GL300) // #316
|
||||
_extension(GL,EXT,framebuffer_multisample, GL210, GL300) // #317
|
||||
_extension(GL,EXT,gpu_shader4, GL210, GL300) // #326
|
||||
_extension(GL,EXT,packed_float, GL210, GL300) // #328
|
||||
_extension(GL,EXT,texture_array, GL210, GL300) // #329
|
||||
_extension(GL,EXT,texture_compression_rgtc, GL210, GL300) // #332
|
||||
_extension(GL,EXT,texture_shared_exponent, GL210, GL300) // #333
|
||||
_extension(GL,EXT,framebuffer_sRGB, GL210, GL300) // #337
|
||||
_extension(GL,EXT,draw_buffers2, GL210, GL300) // #340
|
||||
_extension(GL,EXT,texture_integer, GL210, GL300) // #343
|
||||
_extension(GL,EXT,transform_feedback, GL210, GL300) // #352
|
||||
_extension(GL,EXT,direct_state_access, GL210, None) // #353
|
||||
_extension(GL,EXT,texture_snorm, GL300, GL310) // #365
|
||||
} namespace INTEL { |
||||
/* INTEL_map_texture not supported */ // #429
|
||||
} namespace NV { |
||||
_extension(GL,NV,half_float, GL210, GL300) // #283
|
||||
_extension(GL,NV,primitive_restart, GL210, GL310) // #285
|
||||
_extension(GL,NV,depth_buffer_float, GL210, GL300) // #334
|
||||
_extension(GL,NV,conditional_render, GL210, GL300) // #346
|
||||
/* NV_draw_texture not supported */ // #430
|
||||
} |
||||
} |
||||
#undef _extension |
||||
#endif |
||||
#endif |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "Image.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
template<std::uint8_t dimensions> void Image<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data) { |
||||
delete[] _data; |
||||
_components = components; |
||||
_type = type; |
||||
_size = size; |
||||
_data = reinterpret_cast<char*>(data); |
||||
} |
||||
|
||||
template class Image<1>; |
||||
template class Image<2>; |
||||
template class Image<3>; |
||||
|
||||
} |
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "BufferState.h" |
||||
|
||||
#include <Utility/Debug.h> |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
const Buffer::Target BufferState::targetForIndex[] = { |
||||
Buffer::Target::Array, |
||||
Buffer::Target::CopyRead, |
||||
Buffer::Target::CopyWrite, |
||||
Buffer::Target::ElementArray, |
||||
Buffer::Target::PixelPack, |
||||
Buffer::Target::PixelUnpack, |
||||
Buffer::Target::TransformFeedback, |
||||
Buffer::Target::Uniform, |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
Buffer::Target::AtomicCounter, |
||||
Buffer::Target::DispatchIndirect, |
||||
Buffer::Target::DrawIndirect, |
||||
Buffer::Target::ShaderStorage, |
||||
Buffer::Target::Texture |
||||
#endif |
||||
}; |
||||
|
||||
std::size_t BufferState::indexForTarget(Buffer::Target target) { |
||||
switch(target) { |
||||
case Buffer::Target::Array: return 1; |
||||
case Buffer::Target::CopyRead: return 2; |
||||
case Buffer::Target::CopyWrite: return 3; |
||||
case Buffer::Target::ElementArray: return 4; |
||||
case Buffer::Target::PixelPack: return 5; |
||||
case Buffer::Target::PixelUnpack: return 6; |
||||
case Buffer::Target::TransformFeedback: return 7; |
||||
case Buffer::Target::Uniform: return 8; |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case Buffer::Target::AtomicCounter: return 9; |
||||
case Buffer::Target::DispatchIndirect: return 10; |
||||
case Buffer::Target::DrawIndirect: return 11; |
||||
case Buffer::Target::ShaderStorage: return 12; |
||||
case Buffer::Target::Texture: return 13; |
||||
#endif |
||||
} |
||||
|
||||
CORRADE_ASSERT(false, "Unknown Buffer target", 0); |
||||
return 0; |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,43 @@
|
||||
#ifndef Magnum_Implementation_BufferState_h |
||||
#define Magnum_Implementation_BufferState_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. |
||||
*/ |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
#include "Buffer.h" |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
struct BufferState { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
static const std::size_t TargetCount = 13+1; |
||||
#else |
||||
static const std::size_t TargetCount = 8+1; |
||||
#endif |
||||
|
||||
/* Target <-> index mapping */ |
||||
static std::size_t indexForTarget(Buffer::Target target); |
||||
static const Buffer::Target targetForIndex[TargetCount-1]; |
||||
|
||||
inline constexpr BufferState(): bindings() {} |
||||
|
||||
/* Currently bound buffer for all targets */ |
||||
GLuint bindings[TargetCount]; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,30 @@
|
||||
#ifndef Magnum_Implementation_MeshState_h |
||||
#define Magnum_Implementation_MeshState_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. |
||||
*/ |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
struct MeshState { |
||||
inline MeshState(): currentVAO(0) {} |
||||
|
||||
GLuint currentVAO; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,31 @@
|
||||
#ifndef Magnum_Implementation_ShaderProgramState_h |
||||
#define Magnum_Implementation_ShaderProgramState_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. |
||||
*/ |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
struct ShaderProgramState { |
||||
inline constexpr ShaderProgramState(): current(0) {} |
||||
|
||||
/* Currently used program */ |
||||
GLuint current; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "State.h" |
||||
|
||||
#include "BufferState.h" |
||||
#include "MeshState.h" |
||||
#include "ShaderProgramState.h" |
||||
#include "TextureState.h" |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
State::State(): buffer(new BufferState), mesh(new MeshState), shaderProgram(new ShaderProgramState), texture(new TextureState) {} |
||||
|
||||
State::~State() { |
||||
delete texture; |
||||
delete shaderProgram; |
||||
delete mesh; |
||||
delete buffer; |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,39 @@
|
||||
#ifndef Magnum_Implementation_State_h |
||||
#define Magnum_Implementation_State_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. |
||||
*/ |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
struct BufferState; |
||||
struct MeshState; |
||||
struct ShaderProgramState; |
||||
struct TextureState; |
||||
|
||||
struct State { |
||||
State(); |
||||
~State(); |
||||
|
||||
BufferState* const buffer; |
||||
MeshState* const mesh; |
||||
ShaderProgramState* const shaderProgram; |
||||
TextureState* const texture; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,34 @@
|
||||
#ifndef Magnum_Implementation_TextureState_h |
||||
#define Magnum_Implementation_TextureState_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. |
||||
*/ |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
namespace Magnum { namespace Implementation { |
||||
|
||||
struct TextureState { |
||||
inline TextureState(): maxSupportedLayerCount(0), maxSupportedAnisotropy(0.0f), currentLayer(0) {} |
||||
|
||||
GLint maxSupportedLayerCount; |
||||
GLfloat maxSupportedAnisotropy; |
||||
GLint currentLayer; |
||||
|
||||
std::vector<GLuint> bindings; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,79 @@
|
||||
#ifndef Magnum_Math_Constants_h |
||||
#define Magnum_Math_Constants_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 Class Magnum::Math::Constants, functions Magnum::Math::deg(), Magnum::Math::rad() |
||||
*/ |
||||
|
||||
namespace Magnum { namespace Math { |
||||
|
||||
/**
|
||||
@brief Numeric constants |
||||
|
||||
@internal See MathTypeTraits class for implementation notes. |
||||
*/ |
||||
template<class T> struct Constants { |
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
/**
|
||||
* @brief Pi |
||||
* |
||||
* @see deg(), rad() |
||||
*/ |
||||
static inline constexpr T pi(); |
||||
|
||||
static inline constexpr T sqrt2(); /**< @brief Square root of 2 */ |
||||
static inline constexpr T sqrt3(); /**< @brief Square root of 3 */ |
||||
#endif |
||||
}; |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
template<> struct Constants<double> { |
||||
static inline constexpr double pi() { return 3.141592653589793; } |
||||
static inline constexpr double sqrt2() { return 1.414213562373095; } |
||||
static inline constexpr double sqrt3() { return 1.732050807568877; } |
||||
}; |
||||
template<> struct Constants<float> { |
||||
static inline constexpr float pi() { return 3.141592654f; } |
||||
static inline constexpr float sqrt2() { return 1.414213562f; } |
||||
static inline constexpr float sqrt3() { return 1.732050808f; } |
||||
}; |
||||
#endif |
||||
|
||||
/**
|
||||
@brief Angle in degrees |
||||
|
||||
Function to make angle entering less error-prone. Converts the value to |
||||
radians at compile time. For example `deg(180.0f)` is converted to `3.14f`. |
||||
|
||||
Usable for entering e.g. rotation: |
||||
@code |
||||
Matrix4::rotation(deg(30.0f), Vector3::yAxis()); |
||||
@endcode |
||||
@see Constants, rad() |
||||
*/ |
||||
template<class T> inline constexpr T deg(T value) { return value*Constants<T>::pi()/180; } |
||||
|
||||
/**
|
||||
* @brief Angle in radians |
||||
* |
||||
* See deg() for more information. |
||||
*/ |
||||
template<class T> inline constexpr T rad(T value) { return value; } |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,89 @@
|
||||
#ifndef Magnum_Math_Point2D_h |
||||
#define Magnum_Math_Point2D_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 Class Magnum::Math::Point2D |
||||
*/ |
||||
|
||||
#include "Vector3.h" |
||||
|
||||
namespace Magnum { namespace Math { |
||||
|
||||
/**
|
||||
@brief Two-dimensional homogeneous coordinates |
||||
@tparam T Data type |
||||
|
||||
Same as Vector3, except that constructors have default value for Z component |
||||
set to one. See also @ref matrix-vector for brief introduction. |
||||
@see Point3D |
||||
@configurationvalueref{Magnum::Math::Point2D} |
||||
*/ |
||||
template<class T> class Point2D: public Vector3<T> { |
||||
public: |
||||
/**
|
||||
* @brief Default constructor |
||||
* |
||||
* X and Y components are set to zero, Z is set to one. |
||||
*/ |
||||
inline constexpr Point2D(): Vector3<T>(T(0), T(0), T(1)) {} |
||||
|
||||
/** @brief Copy constructor */ |
||||
inline constexpr Point2D(const RectangularMatrix<1, 3, T>& other): Vector3<T>(other) {} |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param x X component |
||||
* @param y Y component |
||||
* @param z Z component |
||||
*/ |
||||
inline constexpr Point2D(T x, T y, T z = T(1)): Vector3<T>(x, y, z) {} |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param xy Two-component vector |
||||
* @param z Z component |
||||
*/ |
||||
inline constexpr Point2D(const Vector2<T>& xy, T z = T(1)): Vector3<T>(xy, z) {} |
||||
|
||||
/**
|
||||
* @brief Vector part of the point |
||||
* |
||||
* Equivalent to calling xy(). Useful for seamless 2D/3D integration. |
||||
* @see Point3D::vector() |
||||
*/ |
||||
inline Vector2<T>& vector() { return Vector3<T>::xy(); } |
||||
inline constexpr Vector2<T> vector() const { return Vector3<T>::xy(); } /**< @overload */ |
||||
|
||||
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point2D, 3) |
||||
MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Point2D<T>) |
||||
}; |
||||
|
||||
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point2D, 3) |
||||
|
||||
/** @debugoperator{Magnum::Math::Point2D} */ |
||||
template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point2D<T>& value) { |
||||
return debug << static_cast<const Vector<3, T>&>(value); |
||||
} |
||||
|
||||
}} |
||||
|
||||
namespace Corrade { namespace Utility { |
||||
/** @configurationvalue{Magnum::Math::Point2D} */ |
||||
template<class T> struct ConfigurationValue<Magnum::Math::Point2D<T>>: public ConfigurationValue<Magnum::Math::Vector<3, T>> {}; |
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,90 @@
|
||||
#ifndef Magnum_Math_Point3D_h |
||||
#define Magnum_Math_Point3D_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 Class Magnum::Math::Point3D |
||||
*/ |
||||
|
||||
#include "Vector4.h" |
||||
|
||||
namespace Magnum { namespace Math { |
||||
|
||||
/**
|
||||
@brief Three-dimensional homogeneous coordinates |
||||
@tparam T Data type |
||||
|
||||
Same as Vector4, except that constructors have default value for W component |
||||
set to one. See also @ref matrix-vector for brief introduction. |
||||
@see Point2D |
||||
@configurationvalueref{Magnum::Math::Point3D} |
||||
*/ |
||||
template<class T> class Point3D: public Vector4<T> { |
||||
public: |
||||
/**
|
||||
* @brief Default constructor |
||||
* |
||||
* X, Y and Z components are set to zero, W is set to one. |
||||
*/ |
||||
inline constexpr Point3D(): Vector4<T>(T(0), T(0), T(0), T(1)) {} |
||||
|
||||
/** @brief Copy constructor */ |
||||
inline constexpr Point3D(const RectangularMatrix<1, 4, T>& other): Vector4<T>(other) {} |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param x X component |
||||
* @param y Y component |
||||
* @param z Z component |
||||
* @param w W component |
||||
*/ |
||||
inline constexpr Point3D(T x, T y, T z, T w = T(1)): Vector4<T>(x, y, z, w) {} |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param xyz Three-component vector |
||||
* @param w W component |
||||
*/ |
||||
inline constexpr Point3D(const Vector3<T>& xyz, T w = T(1)): Vector4<T>(xyz, w) {} |
||||
|
||||
/**
|
||||
* @brief Vector part of the point |
||||
* |
||||
* Equivalent to calling xyz(). Useful for seamless 2D/3D integration. |
||||
* @see Point2D::vector() |
||||
*/ |
||||
inline Vector3<T>& vector() { return Vector4<T>::xyz(); } |
||||
inline constexpr Vector3<T> vector() const { return Vector4<T>::xyz(); } /**< @overload */ |
||||
|
||||
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Point3D, 4) |
||||
MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Point3D<T>) |
||||
}; |
||||
|
||||
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Point3D, 4) |
||||
|
||||
/** @debugoperator{Magnum::Math::Point3D} */ |
||||
template<class T> inline Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Point3D<T>& value) { |
||||
return debug << static_cast<const Vector<4, T>&>(value); |
||||
} |
||||
|
||||
}} |
||||
|
||||
namespace Corrade { namespace Utility { |
||||
/** @configurationvalue{Magnum::Math::Point3D} */ |
||||
template<class T> struct ConfigurationValue<Magnum::Math::Point3D<T>>: public ConfigurationValue<Magnum::Math::Vector<4, T>> {}; |
||||
}} |
||||
|
||||
#endif |
||||
@ -1,20 +1,24 @@
|
||||
corrade_add_test2(MathConstantsTest ConstantsTest.cpp) |
||||
if(NOT CMAKE_NO_OBJECT_TARGET) |
||||
set(MathTest_SRCS MathTest.cpp $<TARGET_OBJECTS:MagnumMathObjects>) |
||||
else() |
||||
set(MathTest_SRCS MathTest.cpp ${MagnumMath_SRCS}) |
||||
endif() |
||||
corrade_add_test2(MathTest ${MathTest_SRCS}) |
||||
corrade_add_test2(MathMathTypeTraitsTest MathTypeTraitsTest.cpp) |
||||
|
||||
corrade_add_test2(MathRectangularMatrixTest RectangularMatrixTest.cpp) |
||||
|
||||
corrade_add_test2(MathVectorTest VectorTest.cpp) |
||||
set_target_properties(MathVectorTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) |
||||
corrade_add_test2(MathVector2Test Vector2Test.cpp) |
||||
corrade_add_test2(MathVector3Test Vector3Test.cpp) |
||||
corrade_add_test2(MathVector4Test Vector4Test.cpp) |
||||
|
||||
corrade_add_test2(MathPoint2DTest Point2DTest.cpp) |
||||
corrade_add_test2(MathPoint3DTest Point3DTest.cpp) |
||||
|
||||
corrade_add_test2(MathMatrixTest MatrixTest.cpp) |
||||
corrade_add_test2(MathMatrix3Test Matrix3Test.cpp) |
||||
corrade_add_test2(MathMatrix4Test Matrix4Test.cpp) |
||||
|
||||
if(NOT CMAKE_NO_OBJECT_TARGET) |
||||
set(MathTest_SRCS MathTest.cpp $<TARGET_OBJECTS:MagnumMathObjects>) |
||||
else() |
||||
set(MathTest_SRCS MathTest.cpp ${MagnumMath_SRCS}) |
||||
endif() |
||||
corrade_add_test2(MathTest ${MathTest_SRCS}) |
||||
set_target_properties(MathVectorTest MathMatrix4Test PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) |
||||
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
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. |
||||
*/ |
||||
|
||||
#include "ConstantsTest.h" |
||||
|
||||
#include "Constants.h" |
||||
#include "Math.h" |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest) |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { |
||||
|
||||
ConstantsTest::ConstantsTest() { |
||||
addTests(&ConstantsTest::constants, |
||||
&ConstantsTest::degrad); |
||||
} |
||||
|
||||
void ConstantsTest::constants() { |
||||
CORRADE_COMPARE(Math::pow<2>(Constants<float>::sqrt2()), 2.0f); |
||||
CORRADE_COMPARE(Math::pow<2>(Constants<float>::sqrt3()), 3.0f); |
||||
|
||||
CORRADE_COMPARE(Math::pow<2>(Constants<double>::sqrt2()), 2.0); |
||||
CORRADE_COMPARE(Math::pow<2>(Constants<double>::sqrt3()), 3.0); |
||||
} |
||||
|
||||
void ConstantsTest::degrad() { |
||||
CORRADE_COMPARE(deg(90.0), Constants<double>::pi()/2); |
||||
CORRADE_COMPARE(deg(90.0f), Constants<float>::pi()/2); |
||||
CORRADE_COMPARE(rad(Constants<double>::pi()/2), Constants<double>::pi()/2); |
||||
} |
||||
|
||||
}}} |
||||
@ -0,0 +1,32 @@
|
||||
#ifndef Magnum_Math_Test_ConstantsTest_h |
||||
#define Magnum_Math_Test_ConstantsTest_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. |
||||
*/ |
||||
|
||||
#include <TestSuite/Tester.h> |
||||
|
||||
namespace Magnum { namespace Math { namespace Test { |
||||
|
||||
class ConstantsTest: public Corrade::TestSuite::Tester<ConstantsTest> { |
||||
public: |
||||
ConstantsTest(); |
||||
|
||||
void constants(); |
||||
void degrad(); |
||||
}; |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue