mirror of https://github.com/mosra/magnum.git
Browse Source
Conflicts: src/CMakeLists.txt src/Context.cpp src/DebugTools/Profiler.h src/DimensionTraits.h src/Magnum.h src/Math/Math.h src/Math/MathTypeTraits.h src/Math/Matrix4.h src/Mesh.cpp src/Mesh.h src/MeshTools/CMakeLists.txt src/MeshTools/CompressIndices.cpp src/MeshTools/FlipNormals.cpp src/MeshTools/Test/TipsifyTest.h src/MeshTools/Tipsify.cpp src/MeshTools/Transform.h src/Physics/Implementation/DebugRenderer.h src/Profiler.cpp src/SceneGraph/FeatureGroup.h src/SceneGraph/Object.hpp src/SceneGraph/SceneGraph.h src/SizeTraits.h src/Test/SwizzleTest.cpp
519 changed files with 37566 additions and 15158 deletions
@ -1,674 +1,19 @@
|
||||
GNU GENERAL PUBLIC LICENSE |
||||
Version 3, 29 June 2007 |
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
||||
Everyone is permitted to copy and distribute verbatim copies |
||||
of this license document, but changing it is not allowed. |
||||
|
||||
Preamble |
||||
|
||||
The GNU General Public License is a free, copyleft license for |
||||
software and other kinds of works. |
||||
|
||||
The licenses for most software and other practical works are designed |
||||
to take away your freedom to share and change the works. By contrast, |
||||
the GNU General Public License is intended to guarantee your freedom to |
||||
share and change all versions of a program--to make sure it remains free |
||||
software for all its users. We, the Free Software Foundation, use the |
||||
GNU General Public License for most of our software; it applies also to |
||||
any other work released this way by its authors. You can apply it to |
||||
your programs, too. |
||||
|
||||
When we speak of free software, we are referring to freedom, not |
||||
price. Our General Public Licenses are designed to make sure that you |
||||
have the freedom to distribute copies of free software (and charge for |
||||
them if you wish), that you receive source code or can get it if you |
||||
want it, that you can change the software or use pieces of it in new |
||||
free programs, and that you know you can do these things. |
||||
|
||||
To protect your rights, we need to prevent others from denying you |
||||
these rights or asking you to surrender the rights. Therefore, you have |
||||
certain responsibilities if you distribute copies of the software, or if |
||||
you modify it: responsibilities to respect the freedom of others. |
||||
|
||||
For example, if you distribute copies of such a program, whether |
||||
gratis or for a fee, you must pass on to the recipients the same |
||||
freedoms that you received. You must make sure that they, too, receive |
||||
or can get the source code. And you must show them these terms so they |
||||
know their rights. |
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: |
||||
(1) assert copyright on the software, and (2) offer you this License |
||||
giving you legal permission to copy, distribute and/or modify it. |
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains |
||||
that there is no warranty for this free software. For both users' and |
||||
authors' sake, the GPL requires that modified versions be marked as |
||||
changed, so that their problems will not be attributed erroneously to |
||||
authors of previous versions. |
||||
|
||||
Some devices are designed to deny users access to install or run |
||||
modified versions of the software inside them, although the manufacturer |
||||
can do so. This is fundamentally incompatible with the aim of |
||||
protecting users' freedom to change the software. The systematic |
||||
pattern of such abuse occurs in the area of products for individuals to |
||||
use, which is precisely where it is most unacceptable. Therefore, we |
||||
have designed this version of the GPL to prohibit the practice for those |
||||
products. If such problems arise substantially in other domains, we |
||||
stand ready to extend this provision to those domains in future versions |
||||
of the GPL, as needed to protect the freedom of users. |
||||
|
||||
Finally, every program is threatened constantly by software patents. |
||||
States should not allow patents to restrict development and use of |
||||
software on general-purpose computers, but in those that do, we wish to |
||||
avoid the special danger that patents applied to a free program could |
||||
make it effectively proprietary. To prevent this, the GPL assures that |
||||
patents cannot be used to render the program non-free. |
||||
|
||||
The precise terms and conditions for copying, distribution and |
||||
modification follow. |
||||
|
||||
TERMS AND CONDITIONS |
||||
|
||||
0. Definitions. |
||||
|
||||
"This License" refers to version 3 of the GNU General Public License. |
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of |
||||
works, such as semiconductor masks. |
||||
|
||||
"The Program" refers to any copyrightable work licensed under this |
||||
License. Each licensee is addressed as "you". "Licensees" and |
||||
"recipients" may be individuals or organizations. |
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work |
||||
in a fashion requiring copyright permission, other than the making of an |
||||
exact copy. The resulting work is called a "modified version" of the |
||||
earlier work or a work "based on" the earlier work. |
||||
|
||||
A "covered work" means either the unmodified Program or a work based |
||||
on the Program. |
||||
|
||||
To "propagate" a work means to do anything with it that, without |
||||
permission, would make you directly or secondarily liable for |
||||
infringement under applicable copyright law, except executing it on a |
||||
computer or modifying a private copy. Propagation includes copying, |
||||
distribution (with or without modification), making available to the |
||||
public, and in some countries other activities as well. |
||||
|
||||
To "convey" a work means any kind of propagation that enables other |
||||
parties to make or receive copies. Mere interaction with a user through |
||||
a computer network, with no transfer of a copy, is not conveying. |
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" |
||||
to the extent that it includes a convenient and prominently visible |
||||
feature that (1) displays an appropriate copyright notice, and (2) |
||||
tells the user that there is no warranty for the work (except to the |
||||
extent that warranties are provided), that licensees may convey the |
||||
work under this License, and how to view a copy of this License. If |
||||
the interface presents a list of user commands or options, such as a |
||||
menu, a prominent item in the list meets this criterion. |
||||
|
||||
1. Source Code. |
||||
|
||||
The "source code" for a work means the preferred form of the work |
||||
for making modifications to it. "Object code" means any non-source |
||||
form of a work. |
||||
|
||||
A "Standard Interface" means an interface that either is an official |
||||
standard defined by a recognized standards body, or, in the case of |
||||
interfaces specified for a particular programming language, one that |
||||
is widely used among developers working in that language. |
||||
|
||||
The "System Libraries" of an executable work include anything, other |
||||
than the work as a whole, that (a) is included in the normal form of |
||||
packaging a Major Component, but which is not part of that Major |
||||
Component, and (b) serves only to enable use of the work with that |
||||
Major Component, or to implement a Standard Interface for which an |
||||
implementation is available to the public in source code form. A |
||||
"Major Component", in this context, means a major essential component |
||||
(kernel, window system, and so on) of the specific operating system |
||||
(if any) on which the executable work runs, or a compiler used to |
||||
produce the work, or an object code interpreter used to run it. |
||||
|
||||
The "Corresponding Source" for a work in object code form means all |
||||
the source code needed to generate, install, and (for an executable |
||||
work) run the object code and to modify the work, including scripts to |
||||
control those activities. However, it does not include the work's |
||||
System Libraries, or general-purpose tools or generally available free |
||||
programs which are used unmodified in performing those activities but |
||||
which are not part of the work. For example, Corresponding Source |
||||
includes interface definition files associated with source files for |
||||
the work, and the source code for shared libraries and dynamically |
||||
linked subprograms that the work is specifically designed to require, |
||||
such as by intimate data communication or control flow between those |
||||
subprograms and other parts of the work. |
||||
|
||||
The Corresponding Source need not include anything that users |
||||
can regenerate automatically from other parts of the Corresponding |
||||
Source. |
||||
|
||||
The Corresponding Source for a work in source code form is that |
||||
same work. |
||||
|
||||
2. Basic Permissions. |
||||
|
||||
All rights granted under this License are granted for the term of |
||||
copyright on the Program, and are irrevocable provided the stated |
||||
conditions are met. This License explicitly affirms your unlimited |
||||
permission to run the unmodified Program. The output from running a |
||||
covered work is covered by this License only if the output, given its |
||||
content, constitutes a covered work. This License acknowledges your |
||||
rights of fair use or other equivalent, as provided by copyright law. |
||||
|
||||
You may make, run and propagate covered works that you do not |
||||
convey, without conditions so long as your license otherwise remains |
||||
in force. You may convey covered works to others for the sole purpose |
||||
of having them make modifications exclusively for you, or provide you |
||||
with facilities for running those works, provided that you comply with |
||||
the terms of this License in conveying all material for which you do |
||||
not control copyright. Those thus making or running the covered works |
||||
for you must do so exclusively on your behalf, under your direction |
||||
and control, on terms that prohibit them from making any copies of |
||||
your copyrighted material outside their relationship with you. |
||||
|
||||
Conveying under any other circumstances is permitted solely under |
||||
the conditions stated below. Sublicensing is not allowed; section 10 |
||||
makes it unnecessary. |
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law. |
||||
|
||||
No covered work shall be deemed part of an effective technological |
||||
measure under any applicable law fulfilling obligations under article |
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or |
||||
similar laws prohibiting or restricting circumvention of such |
||||
measures. |
||||
|
||||
When you convey a covered work, you waive any legal power to forbid |
||||
circumvention of technological measures to the extent such circumvention |
||||
is effected by exercising rights under this License with respect to |
||||
the covered work, and you disclaim any intention to limit operation or |
||||
modification of the work as a means of enforcing, against the work's |
||||
users, your or third parties' legal rights to forbid circumvention of |
||||
technological measures. |
||||
|
||||
4. Conveying Verbatim Copies. |
||||
|
||||
You may convey verbatim copies of the Program's source code as you |
||||
receive it, in any medium, provided that you conspicuously and |
||||
appropriately publish on each copy an appropriate copyright notice; |
||||
keep intact all notices stating that this License and any |
||||
non-permissive terms added in accord with section 7 apply to the code; |
||||
keep intact all notices of the absence of any warranty; and give all |
||||
recipients a copy of this License along with the Program. |
||||
|
||||
You may charge any price or no price for each copy that you convey, |
||||
and you may offer support or warranty protection for a fee. |
||||
|
||||
5. Conveying Modified Source Versions. |
||||
|
||||
You may convey a work based on the Program, or the modifications to |
||||
produce it from the Program, in the form of source code under the |
||||
terms of section 4, provided that you also meet all of these conditions: |
||||
|
||||
a) The work must carry prominent notices stating that you modified |
||||
it, and giving a relevant date. |
||||
|
||||
b) The work must carry prominent notices stating that it is |
||||
released under this License and any conditions added under section |
||||
7. This requirement modifies the requirement in section 4 to |
||||
"keep intact all notices". |
||||
|
||||
c) You must license the entire work, as a whole, under this |
||||
License to anyone who comes into possession of a copy. This |
||||
License will therefore apply, along with any applicable section 7 |
||||
additional terms, to the whole of the work, and all its parts, |
||||
regardless of how they are packaged. This License gives no |
||||
permission to license the work in any other way, but it does not |
||||
invalidate such permission if you have separately received it. |
||||
|
||||
d) If the work has interactive user interfaces, each must display |
||||
Appropriate Legal Notices; however, if the Program has interactive |
||||
interfaces that do not display Appropriate Legal Notices, your |
||||
work need not make them do so. |
||||
|
||||
A compilation of a covered work with other separate and independent |
||||
works, which are not by their nature extensions of the covered work, |
||||
and which are not combined with it such as to form a larger program, |
||||
in or on a volume of a storage or distribution medium, is called an |
||||
"aggregate" if the compilation and its resulting copyright are not |
||||
used to limit the access or legal rights of the compilation's users |
||||
beyond what the individual works permit. Inclusion of a covered work |
||||
in an aggregate does not cause this License to apply to the other |
||||
parts of the aggregate. |
||||
|
||||
6. Conveying Non-Source Forms. |
||||
|
||||
You may convey a covered work in object code form under the terms |
||||
of sections 4 and 5, provided that you also convey the |
||||
machine-readable Corresponding Source under the terms of this License, |
||||
in one of these ways: |
||||
|
||||
a) Convey the object code in, or embodied in, a physical product |
||||
(including a physical distribution medium), accompanied by the |
||||
Corresponding Source fixed on a durable physical medium |
||||
customarily used for software interchange. |
||||
|
||||
b) Convey the object code in, or embodied in, a physical product |
||||
(including a physical distribution medium), accompanied by a |
||||
written offer, valid for at least three years and valid for as |
||||
long as you offer spare parts or customer support for that product |
||||
model, to give anyone who possesses the object code either (1) a |
||||
copy of the Corresponding Source for all the software in the |
||||
product that is covered by this License, on a durable physical |
||||
medium customarily used for software interchange, for a price no |
||||
more than your reasonable cost of physically performing this |
||||
conveying of source, or (2) access to copy the |
||||
Corresponding Source from a network server at no charge. |
||||
|
||||
c) Convey individual copies of the object code with a copy of the |
||||
written offer to provide the Corresponding Source. This |
||||
alternative is allowed only occasionally and noncommercially, and |
||||
only if you received the object code with such an offer, in accord |
||||
with subsection 6b. |
||||
|
||||
d) Convey the object code by offering access from a designated |
||||
place (gratis or for a charge), and offer equivalent access to the |
||||
Corresponding Source in the same way through the same place at no |
||||
further charge. You need not require recipients to copy the |
||||
Corresponding Source along with the object code. If the place to |
||||
copy the object code is a network server, the Corresponding Source |
||||
may be on a different server (operated by you or a third party) |
||||
that supports equivalent copying facilities, provided you maintain |
||||
clear directions next to the object code saying where to find the |
||||
Corresponding Source. Regardless of what server hosts the |
||||
Corresponding Source, you remain obligated to ensure that it is |
||||
available for as long as needed to satisfy these requirements. |
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided |
||||
you inform other peers where the object code and Corresponding |
||||
Source of the work are being offered to the general public at no |
||||
charge under subsection 6d. |
||||
|
||||
A separable portion of the object code, whose source code is excluded |
||||
from the Corresponding Source as a System Library, need not be |
||||
included in conveying the object code work. |
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any |
||||
tangible personal property which is normally used for personal, family, |
||||
or household purposes, or (2) anything designed or sold for incorporation |
||||
into a dwelling. In determining whether a product is a consumer product, |
||||
doubtful cases shall be resolved in favor of coverage. For a particular |
||||
product received by a particular user, "normally used" refers to a |
||||
typical or common use of that class of product, regardless of the status |
||||
of the particular user or of the way in which the particular user |
||||
actually uses, or expects or is expected to use, the product. A product |
||||
is a consumer product regardless of whether the product has substantial |
||||
commercial, industrial or non-consumer uses, unless such uses represent |
||||
the only significant mode of use of the product. |
||||
|
||||
"Installation Information" for a User Product means any methods, |
||||
procedures, authorization keys, or other information required to install |
||||
and execute modified versions of a covered work in that User Product from |
||||
a modified version of its Corresponding Source. The information must |
||||
suffice to ensure that the continued functioning of the modified object |
||||
code is in no case prevented or interfered with solely because |
||||
modification has been made. |
||||
|
||||
If you convey an object code work under this section in, or with, or |
||||
specifically for use in, a User Product, and the conveying occurs as |
||||
part of a transaction in which the right of possession and use of the |
||||
User Product is transferred to the recipient in perpetuity or for a |
||||
fixed term (regardless of how the transaction is characterized), the |
||||
Corresponding Source conveyed under this section must be accompanied |
||||
by the Installation Information. But this requirement does not apply |
||||
if neither you nor any third party retains the ability to install |
||||
modified object code on the User Product (for example, the work has |
||||
been installed in ROM). |
||||
|
||||
The requirement to provide Installation Information does not include a |
||||
requirement to continue to provide support service, warranty, or updates |
||||
for a work that has been modified or installed by the recipient, or for |
||||
the User Product in which it has been modified or installed. Access to a |
||||
network may be denied when the modification itself materially and |
||||
adversely affects the operation of the network or violates the rules and |
||||
protocols for communication across the network. |
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, |
||||
in accord with this section must be in a format that is publicly |
||||
documented (and with an implementation available to the public in |
||||
source code form), and must require no special password or key for |
||||
unpacking, reading or copying. |
||||
|
||||
7. Additional Terms. |
||||
|
||||
"Additional permissions" are terms that supplement the terms of this |
||||
License by making exceptions from one or more of its conditions. |
||||
Additional permissions that are applicable to the entire Program shall |
||||
be treated as though they were included in this License, to the extent |
||||
that they are valid under applicable law. If additional permissions |
||||
apply only to part of the Program, that part may be used separately |
||||
under those permissions, but the entire Program remains governed by |
||||
this License without regard to the additional permissions. |
||||
|
||||
When you convey a copy of a covered work, you may at your option |
||||
remove any additional permissions from that copy, or from any part of |
||||
it. (Additional permissions may be written to require their own |
||||
removal in certain cases when you modify the work.) You may place |
||||
additional permissions on material, added by you to a covered work, |
||||
for which you have or can give appropriate copyright permission. |
||||
|
||||
Notwithstanding any other provision of this License, for material you |
||||
add to a covered work, you may (if authorized by the copyright holders of |
||||
that material) supplement the terms of this License with terms: |
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the |
||||
terms of sections 15 and 16 of this License; or |
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or |
||||
author attributions in that material or in the Appropriate Legal |
||||
Notices displayed by works containing it; or |
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or |
||||
requiring that modified versions of such material be marked in |
||||
reasonable ways as different from the original version; or |
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or |
||||
authors of the material; or |
||||
|
||||
e) Declining to grant rights under trademark law for use of some |
||||
trade names, trademarks, or service marks; or |
||||
|
||||
f) Requiring indemnification of licensors and authors of that |
||||
material by anyone who conveys the material (or modified versions of |
||||
it) with contractual assumptions of liability to the recipient, for |
||||
any liability that these contractual assumptions directly impose on |
||||
those licensors and authors. |
||||
|
||||
All other non-permissive additional terms are considered "further |
||||
restrictions" within the meaning of section 10. If the Program as you |
||||
received it, or any part of it, contains a notice stating that it is |
||||
governed by this License along with a term that is a further |
||||
restriction, you may remove that term. If a license document contains |
||||
a further restriction but permits relicensing or conveying under this |
||||
License, you may add to a covered work material governed by the terms |
||||
of that license document, provided that the further restriction does |
||||
not survive such relicensing or conveying. |
||||
|
||||
If you add terms to a covered work in accord with this section, you |
||||
must place, in the relevant source files, a statement of the |
||||
additional terms that apply to those files, or a notice indicating |
||||
where to find the applicable terms. |
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the |
||||
form of a separately written license, or stated as exceptions; |
||||
the above requirements apply either way. |
||||
|
||||
8. Termination. |
||||
|
||||
You may not propagate or modify a covered work except as expressly |
||||
provided under this License. Any attempt otherwise to propagate or |
||||
modify it is void, and will automatically terminate your rights under |
||||
this License (including any patent licenses granted under the third |
||||
paragraph of section 11). |
||||
|
||||
However, if you cease all violation of this License, then your |
||||
license from a particular copyright holder is reinstated (a) |
||||
provisionally, unless and until the copyright holder explicitly and |
||||
finally terminates your license, and (b) permanently, if the copyright |
||||
holder fails to notify you of the violation by some reasonable means |
||||
prior to 60 days after the cessation. |
||||
|
||||
Moreover, your license from a particular copyright holder is |
||||
reinstated permanently if the copyright holder notifies you of the |
||||
violation by some reasonable means, this is the first time you have |
||||
received notice of violation of this License (for any work) from that |
||||
copyright holder, and you cure the violation prior to 30 days after |
||||
your receipt of the notice. |
||||
|
||||
Termination of your rights under this section does not terminate the |
||||
licenses of parties who have received copies or rights from you under |
||||
this License. If your rights have been terminated and not permanently |
||||
reinstated, you do not qualify to receive new licenses for the same |
||||
material under section 10. |
||||
|
||||
9. Acceptance Not Required for Having Copies. |
||||
|
||||
You are not required to accept this License in order to receive or |
||||
run a copy of the Program. Ancillary propagation of a covered work |
||||
occurring solely as a consequence of using peer-to-peer transmission |
||||
to receive a copy likewise does not require acceptance. However, |
||||
nothing other than this License grants you permission to propagate or |
||||
modify any covered work. These actions infringe copyright if you do |
||||
not accept this License. Therefore, by modifying or propagating a |
||||
covered work, you indicate your acceptance of this License to do so. |
||||
|
||||
10. Automatic Licensing of Downstream Recipients. |
||||
|
||||
Each time you convey a covered work, the recipient automatically |
||||
receives a license from the original licensors, to run, modify and |
||||
propagate that work, subject to this License. You are not responsible |
||||
for enforcing compliance by third parties with this License. |
||||
|
||||
An "entity transaction" is a transaction transferring control of an |
||||
organization, or substantially all assets of one, or subdividing an |
||||
organization, or merging organizations. If propagation of a covered |
||||
work results from an entity transaction, each party to that |
||||
transaction who receives a copy of the work also receives whatever |
||||
licenses to the work the party's predecessor in interest had or could |
||||
give under the previous paragraph, plus a right to possession of the |
||||
Corresponding Source of the work from the predecessor in interest, if |
||||
the predecessor has it or can get it with reasonable efforts. |
||||
|
||||
You may not impose any further restrictions on the exercise of the |
||||
rights granted or affirmed under this License. For example, you may |
||||
not impose a license fee, royalty, or other charge for exercise of |
||||
rights granted under this License, and you may not initiate litigation |
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that |
||||
any patent claim is infringed by making, using, selling, offering for |
||||
sale, or importing the Program or any portion of it. |
||||
|
||||
11. Patents. |
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this |
||||
License of the Program or a work on which the Program is based. The |
||||
work thus licensed is called the contributor's "contributor version". |
||||
|
||||
A contributor's "essential patent claims" are all patent claims |
||||
owned or controlled by the contributor, whether already acquired or |
||||
hereafter acquired, that would be infringed by some manner, permitted |
||||
by this License, of making, using, or selling its contributor version, |
||||
but do not include claims that would be infringed only as a |
||||
consequence of further modification of the contributor version. For |
||||
purposes of this definition, "control" includes the right to grant |
||||
patent sublicenses in a manner consistent with the requirements of |
||||
this License. |
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free |
||||
patent license under the contributor's essential patent claims, to |
||||
make, use, sell, offer for sale, import and otherwise run, modify and |
||||
propagate the contents of its contributor version. |
||||
|
||||
In the following three paragraphs, a "patent license" is any express |
||||
agreement or commitment, however denominated, not to enforce a patent |
||||
(such as an express permission to practice a patent or covenant not to |
||||
sue for patent infringement). To "grant" such a patent license to a |
||||
party means to make such an agreement or commitment not to enforce a |
||||
patent against the party. |
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, |
||||
and the Corresponding Source of the work is not available for anyone |
||||
to copy, free of charge and under the terms of this License, through a |
||||
publicly available network server or other readily accessible means, |
||||
then you must either (1) cause the Corresponding Source to be so |
||||
available, or (2) arrange to deprive yourself of the benefit of the |
||||
patent license for this particular work, or (3) arrange, in a manner |
||||
consistent with the requirements of this License, to extend the patent |
||||
license to downstream recipients. "Knowingly relying" means you have |
||||
actual knowledge that, but for the patent license, your conveying the |
||||
covered work in a country, or your recipient's use of the covered work |
||||
in a country, would infringe one or more identifiable patents in that |
||||
country that you have reason to believe are valid. |
||||
|
||||
If, pursuant to or in connection with a single transaction or |
||||
arrangement, you convey, or propagate by procuring conveyance of, a |
||||
covered work, and grant a patent license to some of the parties |
||||
receiving the covered work authorizing them to use, propagate, modify |
||||
or convey a specific copy of the covered work, then the patent license |
||||
you grant is automatically extended to all recipients of the covered |
||||
work and works based on it. |
||||
|
||||
A patent license is "discriminatory" if it does not include within |
||||
the scope of its coverage, prohibits the exercise of, or is |
||||
conditioned on the non-exercise of one or more of the rights that are |
||||
specifically granted under this License. You may not convey a covered |
||||
work if you are a party to an arrangement with a third party that is |
||||
in the business of distributing software, under which you make payment |
||||
to the third party based on the extent of your activity of conveying |
||||
the work, and under which the third party grants, to any of the |
||||
parties who would receive the covered work from you, a discriminatory |
||||
patent license (a) in connection with copies of the covered work |
||||
conveyed by you (or copies made from those copies), or (b) primarily |
||||
for and in connection with specific products or compilations that |
||||
contain the covered work, unless you entered into that arrangement, |
||||
or that patent license was granted, prior to 28 March 2007. |
||||
|
||||
Nothing in this License shall be construed as excluding or limiting |
||||
any implied license or other defenses to infringement that may |
||||
otherwise be available to you under applicable patent law. |
||||
|
||||
12. No Surrender of Others' Freedom. |
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or |
||||
otherwise) that contradict the conditions of this License, they do not |
||||
excuse you from the conditions of this License. If you cannot convey a |
||||
covered work so as to satisfy simultaneously your obligations under this |
||||
License and any other pertinent obligations, then as a consequence you may |
||||
not convey it at all. For example, if you agree to terms that obligate you |
||||
to collect a royalty for further conveying from those to whom you convey |
||||
the Program, the only way you could satisfy both those terms and this |
||||
License would be to refrain entirely from conveying the Program. |
||||
|
||||
13. Use with the GNU Affero General Public License. |
||||
|
||||
Notwithstanding any other provision of this License, you have |
||||
permission to link or combine any covered work with a work licensed |
||||
under version 3 of the GNU Affero General Public License into a single |
||||
combined work, and to convey the resulting work. The terms of this |
||||
License will continue to apply to the part which is the covered work, |
||||
but the special requirements of the GNU Affero General Public License, |
||||
section 13, concerning interaction through a network will apply to the |
||||
combination as such. |
||||
|
||||
14. Revised Versions of this License. |
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of |
||||
the GNU General Public License from time to time. Such new versions will |
||||
be similar in spirit to the present version, but may differ in detail to |
||||
address new problems or concerns. |
||||
|
||||
Each version is given a distinguishing version number. If the |
||||
Program specifies that a certain numbered version of the GNU General |
||||
Public License "or any later version" applies to it, you have the |
||||
option of following the terms and conditions either of that numbered |
||||
version or of any later version published by the Free Software |
||||
Foundation. If the Program does not specify a version number of the |
||||
GNU General Public License, you may choose any version ever published |
||||
by the Free Software Foundation. |
||||
|
||||
If the Program specifies that a proxy can decide which future |
||||
versions of the GNU General Public License can be used, that proxy's |
||||
public statement of acceptance of a version permanently authorizes you |
||||
to choose that version for the Program. |
||||
|
||||
Later license versions may give you additional or different |
||||
permissions. However, no additional obligations are imposed on any |
||||
author or copyright holder as a result of your choosing to follow a |
||||
later version. |
||||
|
||||
15. Disclaimer of Warranty. |
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY |
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT |
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY |
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, |
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM |
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF |
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
||||
|
||||
16. Limitation of Liability. |
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS |
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY |
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE |
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF |
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD |
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), |
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
||||
SUCH DAMAGES. |
||||
|
||||
17. Interpretation of Sections 15 and 16. |
||||
|
||||
If the disclaimer of warranty and limitation of liability provided |
||||
above cannot be given local legal effect according to their terms, |
||||
reviewing courts shall apply local law that most closely approximates |
||||
an absolute waiver of all civil liability in connection with the |
||||
Program, unless a warranty or assumption of liability accompanies a |
||||
copy of the Program in return for a fee. |
||||
|
||||
END OF TERMS AND CONDITIONS |
||||
|
||||
How to Apply These Terms to Your New Programs |
||||
|
||||
If you develop a new program, and you want it to be of the greatest |
||||
possible use to the public, the best way to achieve this is to make it |
||||
free software which everyone can redistribute and change under these terms. |
||||
|
||||
To do so, attach the following notices to the program. It is safest |
||||
to attach them to the start of each source file to most effectively |
||||
state the exclusion of warranty; and each file should have at least |
||||
the "copyright" line and a pointer to where the full notice is found. |
||||
|
||||
<one line to give the program's name and a brief idea of what it does.> |
||||
Copyright (C) <year> <name of author> |
||||
|
||||
This program is free software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
This program 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 General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
||||
Also add information on how to contact you by electronic and paper mail. |
||||
|
||||
If the program does terminal interaction, make it output a short |
||||
notice like this when it starts in an interactive mode: |
||||
|
||||
<program> Copyright (C) <year> <name of author> |
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
||||
This is free software, and you are welcome to redistribute it |
||||
under certain conditions; type `show c' for details. |
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate |
||||
parts of the General Public License. Of course, your program's commands |
||||
might be different; for a GUI interface, you would use an "about box". |
||||
|
||||
You should also get your employer (if you work as a programmer) or school, |
||||
if any, to sign a "copyright disclaimer" for the program, if necessary. |
||||
For more information on this, and how to apply and follow the GNU GPL, see |
||||
<http://www.gnu.org/licenses/>. |
||||
|
||||
The GNU General Public License does not permit incorporating your program |
||||
into proprietary programs. If your program is a subroutine library, you |
||||
may consider it more useful to permit linking proprietary applications with |
||||
the library. If this is what you want to do, use the GNU Lesser General |
||||
Public License instead of this License. But first, please read |
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>. |
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
|
||||
@ -1,165 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE |
||||
Version 3, 29 June 2007 |
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
||||
Everyone is permitted to copy and distribute verbatim copies |
||||
of this license document, but changing it is not allowed. |
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates |
||||
the terms and conditions of version 3 of the GNU General Public |
||||
License, supplemented by the additional permissions listed below. |
||||
|
||||
0. Additional Definitions. |
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser |
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU |
||||
General Public License. |
||||
|
||||
"The Library" refers to a covered work governed by this License, |
||||
other than an Application or a Combined Work as defined below. |
||||
|
||||
An "Application" is any work that makes use of an interface provided |
||||
by the Library, but which is not otherwise based on the Library. |
||||
Defining a subclass of a class defined by the Library is deemed a mode |
||||
of using an interface provided by the Library. |
||||
|
||||
A "Combined Work" is a work produced by combining or linking an |
||||
Application with the Library. The particular version of the Library |
||||
with which the Combined Work was made is also called the "Linked |
||||
Version". |
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the |
||||
Corresponding Source for the Combined Work, excluding any source code |
||||
for portions of the Combined Work that, considered in isolation, are |
||||
based on the Application, and not on the Linked Version. |
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the |
||||
object code and/or source code for the Application, including any data |
||||
and utility programs needed for reproducing the Combined Work from the |
||||
Application, but excluding the System Libraries of the Combined Work. |
||||
|
||||
1. Exception to Section 3 of the GNU GPL. |
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License |
||||
without being bound by section 3 of the GNU GPL. |
||||
|
||||
2. Conveying Modified Versions. |
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a |
||||
facility refers to a function or data to be supplied by an Application |
||||
that uses the facility (other than as an argument passed when the |
||||
facility is invoked), then you may convey a copy of the modified |
||||
version: |
||||
|
||||
a) under this License, provided that you make a good faith effort to |
||||
ensure that, in the event an Application does not supply the |
||||
function or data, the facility still operates, and performs |
||||
whatever part of its purpose remains meaningful, or |
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of |
||||
this License applicable to that copy. |
||||
|
||||
3. Object Code Incorporating Material from Library Header Files. |
||||
|
||||
The object code form of an Application may incorporate material from |
||||
a header file that is part of the Library. You may convey such object |
||||
code under terms of your choice, provided that, if the incorporated |
||||
material is not limited to numerical parameters, data structure |
||||
layouts and accessors, or small macros, inline functions and templates |
||||
(ten or fewer lines in length), you do both of the following: |
||||
|
||||
a) Give prominent notice with each copy of the object code that the |
||||
Library is used in it and that the Library and its use are |
||||
covered by this License. |
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license |
||||
document. |
||||
|
||||
4. Combined Works. |
||||
|
||||
You may convey a Combined Work under terms of your choice that, |
||||
taken together, effectively do not restrict modification of the |
||||
portions of the Library contained in the Combined Work and reverse |
||||
engineering for debugging such modifications, if you also do each of |
||||
the following: |
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that |
||||
the Library is used in it and that the Library and its use are |
||||
covered by this License. |
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license |
||||
document. |
||||
|
||||
c) For a Combined Work that displays copyright notices during |
||||
execution, include the copyright notice for the Library among |
||||
these notices, as well as a reference directing the user to the |
||||
copies of the GNU GPL and this license document. |
||||
|
||||
d) Do one of the following: |
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this |
||||
License, and the Corresponding Application Code in a form |
||||
suitable for, and under terms that permit, the user to |
||||
recombine or relink the Application with a modified version of |
||||
the Linked Version to produce a modified Combined Work, in the |
||||
manner specified by section 6 of the GNU GPL for conveying |
||||
Corresponding Source. |
||||
|
||||
1) Use a suitable shared library mechanism for linking with the |
||||
Library. A suitable mechanism is one that (a) uses at run time |
||||
a copy of the Library already present on the user's computer |
||||
system, and (b) will operate properly with a modified version |
||||
of the Library that is interface-compatible with the Linked |
||||
Version. |
||||
|
||||
e) Provide Installation Information, but only if you would otherwise |
||||
be required to provide such information under section 6 of the |
||||
GNU GPL, and only to the extent that such information is |
||||
necessary to install and execute a modified version of the |
||||
Combined Work produced by recombining or relinking the |
||||
Application with a modified version of the Linked Version. (If |
||||
you use option 4d0, the Installation Information must accompany |
||||
the Minimal Corresponding Source and Corresponding Application |
||||
Code. If you use option 4d1, you must provide the Installation |
||||
Information in the manner specified by section 6 of the GNU GPL |
||||
for conveying Corresponding Source.) |
||||
|
||||
5. Combined Libraries. |
||||
|
||||
You may place library facilities that are a work based on the |
||||
Library side by side in a single library together with other library |
||||
facilities that are not Applications and are not covered by this |
||||
License, and convey such a combined library under terms of your |
||||
choice, if you do both of the following: |
||||
|
||||
a) Accompany the combined library with a copy of the same work based |
||||
on the Library, uncombined with any other library facilities, |
||||
conveyed under the terms of this License. |
||||
|
||||
b) Give prominent notice with the combined library that part of it |
||||
is a work based on the Library, and explaining where to find the |
||||
accompanying uncombined form of the same work. |
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License. |
||||
|
||||
The Free Software Foundation may publish revised and/or new versions |
||||
of the GNU Lesser General Public License from time to time. Such new |
||||
versions will be similar in spirit to the present version, but may |
||||
differ in detail to address new problems or concerns. |
||||
|
||||
Each version is given a distinguishing version number. If the |
||||
Library as you received it specifies that a certain numbered version |
||||
of the GNU Lesser General Public License "or any later version" |
||||
applies to it, you have the option of following the terms and |
||||
conditions either of that published version or of any later version |
||||
published by the Free Software Foundation. If the Library as you |
||||
received it does not specify a version number of the GNU Lesser |
||||
General Public License, you may choose any version of the GNU Lesser |
||||
General Public License ever published by the Free Software Foundation. |
||||
|
||||
If the Library as you received it specifies that a proxy can decide |
||||
whether future versions of the GNU Lesser General Public License shall |
||||
apply, that proxy's public statement of acceptance of any version is |
||||
permanent authorization for you to choose that version for the |
||||
Library. |
||||
@ -0,0 +1,79 @@
|
||||
/* |
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
namespace Magnum { |
||||
/** @page debug-tools Debugging helpers |
||||
|
||||
@brief Convenience classes to help you during development. |
||||
|
||||
@tableofcontents |
||||
|
||||
DebugTools library provides various helper classes to help you with |
||||
prototyping and debugging applications without the need to write too much |
||||
common code. They probably have no usage in production code, but can be useful |
||||
in development. |
||||
|
||||
@section debug-tools-renderers Debug renderers |
||||
|
||||
%Debug renderers provide a way to visualize objects and object features in |
||||
@ref scenegraph "scene graph" without the need to mess around with meshes and |
||||
shaders. They are implemented as object features, so you can attach any number |
||||
of them to any object. |
||||
|
||||
Basic usage involves instancing DebugTools::ResourceManager and keeping it for |
||||
for the whole lifetime of debug renderers. Next you need some SceneGraph::DrawableGroup |
||||
instance. You can use the same group as for the rest of your scene, but |
||||
preferrably use dedicated one for debug renderers, so you can easily enable or |
||||
disable debug rendering. |
||||
|
||||
Next step is to create configuration for your debug renderers and create |
||||
particular debug renderer. The configuration is managed using the resource |
||||
manager - you create configuration instance, add it to the manager and then |
||||
reference it using particular resource key. This way you can easily share the |
||||
same options with more renderers. If no options are specified or resource with |
||||
given key doesn't exist, default fallback is used. |
||||
|
||||
Example usage: visualizing object position, rotation and scaling using |
||||
DebugTools::ObjectRenderer: |
||||
@code |
||||
// Global instance of debug resource manager, drawable group for the renderers |
||||
DebugTools::ResourceManager manager; |
||||
SceneGraph::DrawableGroup3D debugDrawables; |
||||
|
||||
// Create renderer options which will be referenced later by "my" resource key |
||||
DebugTools::ResourceManager::instance()->set("my", |
||||
(new DebugTools::ObjectRendererOptions())->setSize(0.3f)); |
||||
|
||||
// Create debug renderer for given object, use "my" options for it. The |
||||
// renderer is automatically added to the object features and also to |
||||
// specified drawable group. |
||||
Object3D* object; |
||||
new DebugTools::ObjectRenderer2D(object, "my", debugDrawables); |
||||
@endcode |
||||
|
||||
See DebugTools::ObjectRenderer and DebugTools::ShapeRenderer for more |
||||
information. |
||||
|
||||
*/ |
||||
} |
||||
@ -1,9 +1,36 @@
|
||||
/* |
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
namespace Magnum { |
||||
/** @page features Feature overview |
||||
@brief Fundamental principles and design goals |
||||
|
||||
- @subpage matrix-vector - @copybrief matrix-vector |
||||
- @subpage scenegraph - @copybrief scenegraph |
||||
- @subpage collision-detection - @copybrief collision-detection |
||||
- @subpage types -- @copybrief types |
||||
- @subpage matrix-vector -- @copybrief matrix-vector |
||||
- @subpage transformations -- @copybrief transformations |
||||
- @subpage scenegraph -- @copybrief scenegraph |
||||
- @subpage collision-detection -- @copybrief collision-detection |
||||
- @subpage debug-tools -- @copybrief debug-tools |
||||
*/ |
||||
} |
||||
|
||||
@ -0,0 +1,90 @@
|
||||
/* |
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
namespace Magnum { |
||||
/** @page method-chaining Method chaining |
||||
|
||||
@brief Little feature helping to reduce typing and encourage best practices. |
||||
|
||||
Method chaining ([Wikipedia](http://en.wikipedia.org/wiki/Method_chaining)) is a |
||||
feature which allows you to chain method calls one after another without |
||||
repeatedly specifying variable the method is called on. Its primary goal is to |
||||
reduce unnecessary repeated names, improving code readability. |
||||
|
||||
%Magnum uses this feature for configuring OpenGL objects (such as various mesh |
||||
and framebuffer options, shader uniforms etc.). Because OpenGL was designed with |
||||
"bind-to-modify" approach, most configuration calls need to bind the object |
||||
first and only after that change the parameters (unless @extension{EXT,direct_state_access} |
||||
extension is available to avoid this). To reduce unneeded bind calls, %Magnum |
||||
binds the object only if it is not already bound somewhere. Method chaining |
||||
encourages you to configure whole object in one run, effectively reducing the |
||||
number of needed bindings. Consider the following example: |
||||
@code |
||||
Texture2D *carDiffuseTexture, *carSpecularTexture, *carBumpTexture; |
||||
|
||||
carDiffuseTexture->setStorage(5, Texture2D::InternalFormat::SRGB8); |
||||
carSpecularTexture->setStorage(3, Texture2D::InternalFormat::R8); |
||||
carBumpTexture->setStorage(5, Texture2D::InternalFormat::RGB8); |
||||
carDiffuseTexture->setSubImage(0, {}, diffuse); |
||||
carSpecularTexture->setSubImage(0, {}, specular; |
||||
carBumpTexture->setSubImage(0, {}, bump); |
||||
carDiffuseTexture->generateMipmap(); |
||||
carSpecularTexture->generateMipmap(); |
||||
carBumpTexture->generateMipmap(); |
||||
@endcode |
||||
|
||||
This code is written that similar configuration steps are grouped together, |
||||
which might be good when somebody needs to change something for all three |
||||
textures at once, but on the other hand the code is cluttered with repeated |
||||
names and after each configuration step the texture must be rebound to another. |
||||
With method chaining used the code looks much lighter and each object is |
||||
configured in one run, reducing count of bind calls from 9 to 3. |
||||
@code |
||||
carDiffuseTexture->setStorage(5, Texture2D::InternalFormat::SRGB8) |
||||
->setSubImage(0, {}, diffuse) |
||||
->generateMipmap(); |
||||
carSpecularTexture->setStorage(3, Texture2D::InternalFormat::R8) |
||||
->setSubImage(0, {}, diffuse) |
||||
->generateMipmap(); |
||||
carBumpTexture->setStorage(5, Texture2D::InternalFormat::RGB8) |
||||
->setSubImage(0, {}, bump) |
||||
->generateMipmap(); |
||||
@endcode |
||||
|
||||
Method chaining is not used on non-configuring functions, such as Framebuffer::clear() |
||||
or Mesh::draw(), as these won't be commonly used in conjunction with other |
||||
functions anyway. |
||||
|
||||
Method chaining is also used in SceneGraph and other libraries and in some cases |
||||
it allows you to just "configure and forget" without even saving the created |
||||
object to some variable, for example when adding static object to an scene: |
||||
@code |
||||
Scene3D scene; |
||||
|
||||
(new MyObject(&scene)) |
||||
->rotateX(90.0_degf) |
||||
->translate({-1.5f, 0.5f, 7.0f}); |
||||
@endcode |
||||
*/ |
||||
} |
||||
@ -1,9 +1,34 @@
|
||||
/* |
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
namespace Magnum { |
||||
/** @page tips Tips and tricks |
||||
@brief Hints for better productivity and performance. |
||||
|
||||
- @subpage portability - @copybrief portability |
||||
- @subpage best-practices - @copybrief best-practices |
||||
- @subpage compilation-speedup - @copybrief compilation-speedup |
||||
- @subpage method-chaining -- @copybrief method-chaining |
||||
- @subpage portability -- @copybrief portability |
||||
- @subpage best-practices -- @copybrief best-practices |
||||
- @subpage compilation-speedup -- @copybrief compilation-speedup |
||||
*/ |
||||
} |
||||
|
||||
@ -0,0 +1,314 @@
|
||||
/* |
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
namespace Magnum { namespace Math { |
||||
/** @page transformations 2D and 3D transformations |
||||
|
||||
@brief Introduction to essential operations on vectors and points. |
||||
|
||||
@tableofcontents |
||||
|
||||
Transformations are essential operations involved in scene management -- object |
||||
relations, hierarchies, animations etc. %Magnum provides classes for |
||||
transformations in both 2D and 3D. Each class is suited for different purposes, |
||||
but their usage is nearly the same to make your life simpler. This page will |
||||
explain the basic operation and differences between various representations. |
||||
|
||||
@section transformations-representation Representing transformations |
||||
|
||||
The first and most straightforward way to represent transformations is to use |
||||
homogeneous transformation matrix, i.e. Matrix3 for 2D and Matrix4 for 3D. The |
||||
matrices are able to represent all possible types of transformations -- rotation, |
||||
translation, scaling, reflection etc. and also projective transformation, thus |
||||
they are used at the very core of graphics pipeline and are supported natively |
||||
in OpenGL. |
||||
|
||||
On the other hand, matrices need 9 or 16 floats to represent the transformation, |
||||
which has implications on both memory usage and performance (relatively slow |
||||
matrix multiplication). It is also relatively hard to extract transformation |
||||
properties (such as rotation angle/axis) from them, interpolate between them or |
||||
compute inverse transformation. They suffer badly from so-called floating-point |
||||
drift -- e.g. after a few combined rotations the transformation won't be pure |
||||
rotation anymore, but will involve also a bit of scaling, shearing and whatnot. |
||||
|
||||
However, you can trade some transformation features for improved performance and |
||||
better behavior -- for just a rotation you can use Complex in 2D and Quaternion |
||||
in 3D, or DualComplex and DualQuaternion if you want also translation. It is not |
||||
possible to represent scaling, reflection or other transformations with them, |
||||
but they occupy only 2 or 4 floats (4 or 8 floats in dual versions), can be |
||||
easily inverted and interpolated and have many other awesome properties. However, |
||||
they are not magic so they also suffer slightly from floating-point drift, but |
||||
not too much and the drift can be accounted for more easily than with matrices. |
||||
|
||||
@section transformations-types Transformation types |
||||
|
||||
Transformation matrices and (dual) complex numbers or quaternions have completely |
||||
different internals, but they share the same API to achieve the same things, |
||||
greatly simplifying their usage. In many cases it is even possible to hot-swap |
||||
the transformation class type without changing any function calls. |
||||
|
||||
@subsection transformations-default Default (identity) transformation |
||||
|
||||
Default-constructed Matrix3, Matrix4, Complex, Quaternion, DualComplex and |
||||
DualQuaternion represent identity transformation, so you don't need to worry |
||||
about them in initialization. |
||||
|
||||
@subsection transformations-rotation Rotation |
||||
|
||||
2D rotation is represented solely by its angle in counterclockwise direction and |
||||
rotation transformation can be created by calling Matrix3::rotation(), |
||||
Complex::rotation() or DualComplex::rotation(), for example: |
||||
@code |
||||
auto a = Matrix3::rotation(23.0_degf); |
||||
auto b = Complex::rotation(Rad(Constants::pi()/2)); |
||||
auto c = DualComplex::rotation(-1.57_radf); |
||||
@endcode |
||||
|
||||
3D rotation is represented by angle and (three-dimensional) axis. The rotation |
||||
can be created by calling Matrix4::rotation(), Quaternion::rotation() or |
||||
DualQuaternion::rotation(). The axis must be always of unit length to avoid |
||||
redundant normalization. Shortcuts Vector3::xAxis(), Vector3::yAxis() and |
||||
Vector3::zAxis() are provided for convenience. %Matrix representation has also |
||||
Matrix4::rotationX(), Matrix4::rotationY() and Matrix4::rotationZ() which are |
||||
faster than using the generic function for rotation around primary axes. |
||||
Examples: |
||||
@code |
||||
auto a = Quaternion::rotation(60.0_degf, Vector3::xAxis()); |
||||
auto b = DualQuaternion::rotation(-1.0_degf, Vector3(1.0f, 0.5f, 3.0f).normalized()); |
||||
auto c = Matrix4::rotationZ(angle); |
||||
@endcode |
||||
|
||||
Rotations are always around origin. Rotation about arbitrary point can be done |
||||
by applying translation to have the point at origin, performing the rotation and |
||||
then translating back. Read below for more information. |
||||
@todo DualQuaternion and rotation around arbitrary axis |
||||
|
||||
@subsection transformations-translation Translation |
||||
|
||||
2D translation is defined by two-dimensional vector and can be created with |
||||
Matrix3::translation() or DualComplex::translation(). You can use Vector2::xAxis() |
||||
or Vector2::yAxis() to translate only along given axis. Examples: |
||||
@code |
||||
auto a = Matrix3::translation(Vector2::xAxis(-5.0f)); |
||||
auto b = DualComplex::translation({-1.0f, 0.5f}); |
||||
@endcode |
||||
|
||||
3D translation is defined by three-dimensional vector and can be created with |
||||
Matrix4::translation() or DualQuaternion::translation(). You can use |
||||
Vector3::xAxis() and friends also here. Examples: |
||||
@code |
||||
auto a = Matrix4::translation(vector); |
||||
auto b = DualQuaternion::translation(Vector3::zAxis(1.3f)); |
||||
@endcode |
||||
|
||||
@subsection transformations-scaling Scaling and reflection |
||||
|
||||
Scaling is defined by two- or three-dimensional vector and is represented by |
||||
matrices. You can create it with Matrix3::scaling() or Matrix4::scaling(). You |
||||
can use Vector3::xScale(), Vector3::yScale(), Vector3::zScale() or their 2D |
||||
counterparts to scale along one axis and leave the rest unchanged or call |
||||
explicit one-parameter vector constructor to scale uniformly on all axes. |
||||
Examples: |
||||
@code |
||||
auto a = Matrix3::scaling(Vector2::xScale(2.0f)); |
||||
auto b = Matrix4::scaling({2.0f, -2.0f, 1.5f}); |
||||
auto c = Matrix4::scaling(Vector3(10.0f)); |
||||
@endcode |
||||
|
||||
Reflections are defined by normal along which to reflect (i.e., two- or |
||||
three-dimensional vector of unit length) and they are also represented by |
||||
matrices. Reflection is created with Matrix3::reflection() or Matrix4::reflection(). |
||||
You can use Vector3::xAxis() and friends also here. Examples: |
||||
@code |
||||
auto a = Matrix3::reflection(Vector2::yAxis()); |
||||
auto b = Matrix4::reflection(axis.normalized()); |
||||
@endcode |
||||
|
||||
Scaling and reflection is also done relative to origin, you can use method |
||||
mentioned above to scale or reflect around arbitrary point. |
||||
|
||||
Sscaling and reflection can be (to some extent) also represented by complex |
||||
numbers and quaternions, but it has some bad properties and would make some |
||||
operations more expensive, so it's not implemented. |
||||
|
||||
@subsection transformations-projective Projective transformations |
||||
|
||||
Projective transformations eploit the full potential of transformation matrices. |
||||
In 2D there is only one projection type, which can be created with Matrix3::projection() |
||||
and it is defined by area which will be projected into unit rectangle. In 3D |
||||
there is orthographic projection, created with Matrix4::orthographicProjection() |
||||
and defined by volume to project into unit cube, and perspective projection. |
||||
Perspective projection is created with Matrix4::perspectiveProjection() and is |
||||
defined either by field-of-view, aspect ratio and distance to near and far plane |
||||
of view frustum or by size of near plane, its distance and distance to far |
||||
plane. Some examples: |
||||
@code |
||||
auto a = Matrix3::projection({4.0f, 3.0f}); |
||||
auto b = Matrix4::orthographicProjection({4.0f, 3.0f, 100.0f}); |
||||
auto c = Matrix4::perspectiveProjection(35.0_degf, 1.333f, 0.001f, 100.0f); |
||||
@endcode |
||||
|
||||
@section transformations-composing Composing and inverting transformations |
||||
|
||||
Transformations (of the same representation) can be composed simply by |
||||
multiplying them, it works the same for matrices, complex numbers, quaternions |
||||
and their dual counterparts. Order of multiplication matters -- the |
||||
transformation on the right-hand side of multiplication is applied first, the |
||||
transformation on the left-hand side is applied second. For example, rotation |
||||
followed by translation is done like this: |
||||
@code |
||||
auto a = DualComplex::translation(Vector2::yAxis(2.0f))* |
||||
DualComplex::rotation(25.0_degf); |
||||
auto b = Matrix4::translation(Vector3::yAxis(5.0f))* |
||||
Matrix4::rotationY(25.0_degf); |
||||
@endcode |
||||
|
||||
Inverse transformation can be computed using Matrix3::inverted(), Matrix4::inverted(), |
||||
Complex::inverted(), Quaternion::inverted(), DualComplex::inverted() or |
||||
DualQuaternion::inverted(). %Matrix inversion is quite costly, so if your |
||||
transformation involves only translation and rotation, you can use faster |
||||
alternatives Matrix3::invertedRigid() and Matrix4::invertedRigid(). If you are |
||||
sure that the (dual) complex number or (dual) quaternion is of unit length, you |
||||
can use Complex::invertedNormalized(), Quaternion::invertedNormalized(), |
||||
DualComplex::invertedNormalized() or DualQuaternion::invertedNormalized() which |
||||
is a little bit faster, because it doesn't need to renormalize the result. |
||||
|
||||
@section transformations-transforming Transforming vectors and points |
||||
|
||||
Transformations can be used directly for transforming vectors and points. %Vector |
||||
transformation does not involve translation, in 2D can be done using |
||||
Matrix3::transformVector() and Complex::transformVector(), in 3D using |
||||
Matrix4::transformVector() and Quaternion::transformVector(). For transformation |
||||
with normalized quaternion you can use faster alternative Quaternion::transformVectorNormalized(). |
||||
Example: |
||||
@code |
||||
auto transformation = Matrix3::rotation(-30.0_degf)*Matrix3::scaling(Vector2(3.0f)); |
||||
Vector2 transformed = transformation.transformVector({1.5f, -7.9f}); |
||||
@endcode |
||||
|
||||
Point transformation involves also translation, in 2D is done with |
||||
Matrix3::transformPoint() and DualComplex::transformPoint(), in 3D with |
||||
Matrix4::transformPoint() and DualQuaternion::transformPoint(). Also here you |
||||
can use faster alternative Quaternion::transformPointNormalized(): |
||||
@code |
||||
auto transformation = DualQuaternion::rotation(-30.0_degf, Vector3::xAxis())* |
||||
DualQuaternion::translation(Vector3::yAxis(3.0f)); |
||||
Vector3 transformed = transformation.transformPointNormalized({1.5f, 3.0f, -7.9f}); |
||||
@endcode |
||||
|
||||
@section transformations-properties Transformation properties and conversion |
||||
|
||||
It is possible to extract some transformation properties from transformation |
||||
matrices, particularly translation vector, rotation/scaling part of the matrix |
||||
(or pure rotation if the matrix has uniform scaling) and also base vectors: |
||||
@code |
||||
Matrix4 a; |
||||
auto rotationScaling = transformation.rotationScaling(); |
||||
Vector3 up = transformation.up(); |
||||
Vector3 right = transformation.right(); |
||||
|
||||
Matrix3 b; |
||||
auto rotation = b.rotation(); |
||||
Float xTranslation = b.translation().x(); |
||||
@endcode |
||||
Extracting scaling and rotation from arbitrary transformation matrices is harder |
||||
and can be done using Algorithms::svd(). Extracting rotation angle (and axis in |
||||
3D) from rotation part is possible using by converting it to complex number or |
||||
quaternion, see below. |
||||
|
||||
You can also recreate transformation matrix from rotation and translation parts: |
||||
@code |
||||
Matrix3 c = Matrix3::from(rotation, {1.0f, 3.0f}); |
||||
@endcode |
||||
|
||||
%Complex numbers and quaternions are far better in this regard and they allow |
||||
you to extract rotation angle using Complex::angle() or Quaternion::angle() or |
||||
rotation axis in 3D using Quaternion::axis(). Their dual versions allow to |
||||
extract both rotation and translation part using DualComplex::rotation() const, |
||||
DualQuaternion::rotation() const, DualComplex::translation() const and |
||||
DualQuaternion::translation() const. |
||||
@code |
||||
DualComplex a; |
||||
Rad rotationAngle = a.rotation().angle(); |
||||
Vector2 translation = a.translation(); |
||||
|
||||
Quaternion b; |
||||
Vector3 rotationAxis = b.axis(); |
||||
@endcode |
||||
|
||||
You can convert Complex and Quaternion to rotation matrix using Complex::toMatrix() |
||||
and Quaternion::toMatrix() or their dual version to rotation and translation |
||||
matrix using DualComplex::toMatrix() and DualQuaternion::toMatrix(): |
||||
@code |
||||
Quaternion a; |
||||
auto rotation = Matrix4::from(a.toMatrix(), {}); |
||||
|
||||
DualComplex b; |
||||
Matrix3 transformation = b.toMatrix(); |
||||
@endcode |
||||
|
||||
Conversion the other way around is possible only from rotation matrices using |
||||
Complex::fromMatrix() or Quaternion::fromMatrix() and from rotation and |
||||
translation matrices using DualComplex::fromMatrix() and |
||||
DualQuaternion::fromMatrix(): |
||||
@code |
||||
Matrix3 rotation; |
||||
auto a = Complex::fromMatrix(rotation.rotationScaling()); |
||||
|
||||
Matrix4 transformation; |
||||
auto b = DualQuaternion::fromMatrix(transformation); |
||||
@endcode |
||||
|
||||
@section transformations-interpolation Transformation interpolation |
||||
|
||||
@todoc Write this when interpolation is done also for (dual) complex numbers and |
||||
dual quaternions |
||||
|
||||
@section transformations-normalization Normalizing transformations |
||||
|
||||
When doing multiplicative transformations, e.g. adding rotating to an |
||||
transformation many times during an animation, the resulting transformation will |
||||
accumulate rounding errors and behave strangely. For transformation matrices |
||||
this can't always be fixed, because they can represent any transformation (and |
||||
thus no algorithm can't tell if the transformation is in expected form or not). |
||||
If you restrict yourselves (e.g. only uniform scaling and no skew), the matrix |
||||
can be reorthogonalized using Algorithms::gramSchmidtOrthogonalize() (or |
||||
Algorithms::gramSchmidtOrthonormalize(), if you don't have any scaling). You can |
||||
also use Algorithms::svd() to more precisely (but way more slowly) account for |
||||
the drift. Example: |
||||
@code |
||||
Matrix4 transformation; |
||||
Math::Algorithms::gramSchmidtOrthonormalizeInPlace(transformation); |
||||
@endcode |
||||
|
||||
For quaternions and complex number this problem can be solved far more easily |
||||
using Complex::normalized(), Quaternion::normalized(), DualComplex::normalized() |
||||
and DualQuaternion::normalized(). Transformation quaternions and complex numbers |
||||
are always of unit length, thus normalizing them reduces the drift. |
||||
@code |
||||
DualQuaternion transformation; |
||||
transformation = transformation.normalized(); |
||||
@endcode |
||||
*/ |
||||
}} |
||||
@ -0,0 +1,99 @@
|
||||
/* |
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
namespace Magnum { |
||||
/** @page types Type system |
||||
|
||||
@brief Type aliases, naming and compatibility with OpenGL and GLSL types |
||||
|
||||
@section types-builtin Builtin types |
||||
|
||||
%Magnum provides typedefs for builtin integral and floating-point arithmetic |
||||
types to ensure portability (e.g. Int is *always* 32bit), maintain consistency |
||||
and reduce confusion (e.g. `std::int32_t`, `int` and `GLint` all refer to the |
||||
same type). |
||||
|
||||
| %Magnum type | Size | Equivalent GLSL type | |
||||
| ------------------ | -------------- | -------------------- | |
||||
| @ref UnsignedByte | 8bit unsigned | | |
||||
| @ref Byte | 8bit signed | | |
||||
| @ref UnsignedShort | 16bit unsigned | | |
||||
| @ref Short | 16bit signed | | |
||||
| @ref UnsignedInt | 32bit unsigned | `uint` | |
||||
| @ref Int | 32bit signed | `int` | |
||||
| @ref UnsignedLong | 64bit unsigned | | |
||||
| @ref Long | 64bit signed | | |
||||
| @ref Float | 32bit | `float` | |
||||
| @ref Double | 64bit | `double` | |
||||
|
||||
Types not meant to be used in arithmetic (such as `bool` or `std::size_t`) or |
||||
types which cannot be directly passed to GLSL shaders (such as `long double`) |
||||
have no typedefs. |
||||
|
||||
Types from the above table are then used to define other types. All following |
||||
types are aliases of corresponding types in Math namespace. No suffix after type |
||||
name means @ref Float underlying type, `ui` means @ref UnsignedInt underlying |
||||
type, `i` is @ref Int underlying type and `d` is for @ref Double underlying type. |
||||
|
||||
@section types-matrix Matrix/vector types |
||||
|
||||
| %Magnum vector type | Equivalent GLSL type | |
||||
| ---------------------------------------------- | ------------------------- | |
||||
| @ref Vector2, @ref Vector3, @ref Vector4 | `vec2`, `vec3`, `vec4` | |
||||
| @ref Vector2ui, @ref Vector3ui, @ref Vector4ui | `uvec2`, `uvec3`, `uvec4` | |
||||
| @ref Vector2i, @ref Vector3i, @ref Vector4i | `ivec2`, `ivec3`, `ivec4` | |
||||
| @ref Vector2d, @ref Vector3d, @ref Vector4d | `dvec2`, `dvec3`, `dvec4` | |
||||
|
||||
| %Magnum matrix type | Equivalent GLSL type | |
||||
| --------------------------------- | ------------------------------------ | |
||||
| @ref Matrix2 or @ref Matrix2d | `mat2`/`mat2x2` or `dmat2`/`dmat2x2` | |
||||
| @ref Matrix3 or @ref Matrix3d | `mat3`/`mat3x3` or `dmat3`/`dmat3x3` | |
||||
| @ref Matrix4 or @ref Matrix4d | `mat4`/`mat4x4` or `dmat3`/`dmat4x4` | |
||||
| @ref Matrix2x3 or @ref Matrix2x3d | `mat2x3` or `dmat2x3` | |
||||
| @ref Matrix3x2 or @ref Matrix3x2d | `mat3x2` or `dmat3x2` | |
||||
| @ref Matrix2x4 or @ref Matrix2x4d | `mat2x4` or `dmat2x4` | |
||||
| @ref Matrix4x2 or @ref Matrix4x2d | `mat4x2` or `dmat4x2` | |
||||
| @ref Matrix3x4 or @ref Matrix3x4d | `mat3x4` or `dmat3x4` | |
||||
| @ref Matrix4x3 or @ref Matrix4x3d | `mat4x3` or `dmat4x3` | |
||||
|
||||
Any super- or sub-class of the same size and underlying type can be used |
||||
equivalently (e.g. Math::Vector or Color3 instead of @ref Vector3). |
||||
|
||||
@section types-other Other types |
||||
|
||||
Other types, which don't have their GLSL equivalent, are: |
||||
|
||||
- @ref Rectangle, @ref Rectanglei or @ref Rectangled |
||||
- @ref Complex or @ref Complexd, @ref DualComplex or @ref DualComplexd |
||||
- @ref Quaternion or @ref Quaterniond, @ref DualQuaternion or @ref DualQuaterniond |
||||
|
||||
These types can be used in GLSL either by extracting values from their |
||||
underlying structure or converting them to types supported by GLSL (e.g. |
||||
quaternion to matrix). |
||||
|
||||
For your convenience, there is also alias for class with often used constants -- |
||||
@ref Constants or @ref Constantsd. |
||||
|
||||
*/ |
||||
} |
||||
@ -1 +1,25 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
install(FILES glcorearb.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GL) |
||||
|
||||
@ -1 +1,25 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
install(FILES gl3.h gl3platform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/GLES3) |
||||
|
||||
@ -1 +1,25 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
install(FILES khrplatform.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/external/KHR) |
||||
|
||||
@ -1,3 +1,27 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
if(NOT CMAKE_CROSSCOMPILING) |
||||
install(FILES FindMagnum.cmake DESTINATION ${MAGNUM_CMAKE_MODULE_INSTALL_DIR}) |
||||
endif() |
||||
|
||||
@ -0,0 +1,57 @@
|
||||
# - Find HarfBuzz |
||||
# |
||||
# This module tries to find HarfBuzz library and then defines: |
||||
# HARFBUZZ_FOUND - True if HarfBuzz library is found |
||||
# HARFBUZZ_INCLUDE_DIRS - Include dirs |
||||
# HARFBUZZ_LIBRARIES - HarfBuzz libraries |
||||
# |
||||
# Additionally these variables are defined for internal usage: |
||||
# HARFBUZZ_INCLUDE_DIR - Include dir (w/o dependencies) |
||||
# HARFBUZZ_LIBRARY - HarfBuzz library (w/o dependencies) |
||||
# |
||||
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
# Library |
||||
find_library(HARFBUZZ_LIBRARY NAMES harfbuzz) |
||||
|
||||
# Include dir |
||||
find_path(HARFBUZZ_INCLUDE_DIR |
||||
NAMES hb.h |
||||
PATH_SUFFIXES harfbuzz |
||||
) |
||||
|
||||
include(FindPackageHandleStandardArgs) |
||||
find_package_handle_standard_args("HarfBuzz" DEFAULT_MSG |
||||
HARFBUZZ_LIBRARY |
||||
HARFBUZZ_INCLUDE_DIR |
||||
) |
||||
|
||||
set(HARFBUZZ_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR}) |
||||
set(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARY}) |
||||
|
||||
mark_as_advanced(FORCE |
||||
HARFBUZZ_LIBRARY |
||||
HARFBUZZ_INCLUDE_DIR) |
||||
@ -0,0 +1,250 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractFramebuffer.h" |
||||
|
||||
#include "BufferImage.h" |
||||
#include "Context.h" |
||||
#include "Extensions.h" |
||||
#include "Image.h" |
||||
|
||||
#include "Implementation/FramebufferState.h" |
||||
#include "Implementation/State.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
AbstractFramebuffer::DrawBuffersImplementation AbstractFramebuffer::drawBuffersImplementation = &AbstractFramebuffer::drawBuffersImplementationDefault; |
||||
AbstractFramebuffer::DrawBufferImplementation AbstractFramebuffer::drawBufferImplementation = &AbstractFramebuffer::drawBufferImplementationDefault; |
||||
AbstractFramebuffer::ReadBufferImplementation AbstractFramebuffer::readBufferImplementation = &AbstractFramebuffer::readBufferImplementationDefault; |
||||
|
||||
AbstractFramebuffer::Target AbstractFramebuffer::readTarget = AbstractFramebuffer::Target::ReadDraw; |
||||
AbstractFramebuffer::Target AbstractFramebuffer::drawTarget = AbstractFramebuffer::Target::ReadDraw; |
||||
#endif |
||||
|
||||
void AbstractFramebuffer::bind(Target target) { |
||||
bindInternal(target); |
||||
setViewportInternal(); |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
void AbstractFramebuffer::bindInternal(Target target) { |
||||
Implementation::FramebufferState* state = Context::current()->state()->framebuffer; |
||||
|
||||
/* If already bound, done, otherwise update tracked state */ |
||||
if(target == Target::Read) { |
||||
if(state->readBinding == _id) return; |
||||
state->readBinding = _id; |
||||
} else if(target == Target::Draw) { |
||||
if(state->drawBinding == _id) return; |
||||
state->drawBinding = _id; |
||||
} else if(target == Target::ReadDraw) { |
||||
if(state->readBinding == _id && state->drawBinding == _id) return; |
||||
state->readBinding = state->drawBinding = _id; |
||||
} else CORRADE_INTERNAL_ASSERT(false); |
||||
|
||||
glBindFramebuffer(static_cast<GLenum>(target), _id); |
||||
} |
||||
|
||||
AbstractFramebuffer::Target AbstractFramebuffer::bindInternal() { |
||||
Implementation::FramebufferState* state = Context::current()->state()->framebuffer; |
||||
|
||||
/* Return target to which the framebuffer is already bound */ |
||||
if(state->readBinding == _id && state->drawBinding == _id) |
||||
return Target::ReadDraw; |
||||
if(state->readBinding == _id) |
||||
return Target::Read; |
||||
if(state->drawBinding == _id) |
||||
return Target::Draw; |
||||
|
||||
/* Or bind it, if not already */ |
||||
state->readBinding = _id; |
||||
if(readTarget == Target::ReadDraw) state->drawBinding = _id; |
||||
|
||||
glBindFramebuffer(GLenum(readTarget), _id); |
||||
return readTarget; |
||||
} |
||||
#endif |
||||
|
||||
void AbstractFramebuffer::blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& sourceRectangle, const Rectanglei& destinationRectangle, AbstractFramebuffer::BlitMask mask, AbstractFramebuffer::BlitFilter filter) { |
||||
source.bindInternal(AbstractFramebuffer::Target::Read); |
||||
destination.bindInternal(AbstractFramebuffer::Target::Draw); |
||||
/** @todo Get some extension wrangler instead to avoid undeclared glBlitFramebuffer() on ES2 */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
glBlitFramebuffer(sourceRectangle.left(), sourceRectangle.bottom(), sourceRectangle.right(), sourceRectangle.top(), destinationRectangle.left(), destinationRectangle.bottom(), destinationRectangle.right(), destinationRectangle.top(), static_cast<GLbitfield>(mask), static_cast<GLenum>(filter)); |
||||
#else |
||||
static_cast<void>(sourceRectangle); |
||||
static_cast<void>(destinationRectangle); |
||||
static_cast<void>(mask); |
||||
static_cast<void>(filter); |
||||
#endif |
||||
} |
||||
|
||||
AbstractFramebuffer* AbstractFramebuffer::setViewport(const Rectanglei& rectangle) { |
||||
_viewport = rectangle; |
||||
|
||||
/* Update the viewport if the framebuffer is currently bound */ |
||||
if(Context::current()->state()->framebuffer->drawBinding == _id) |
||||
setViewportInternal(); |
||||
|
||||
return this; |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
void AbstractFramebuffer::setViewportInternal() { |
||||
Implementation::FramebufferState* state = Context::current()->state()->framebuffer; |
||||
|
||||
CORRADE_INTERNAL_ASSERT(state->drawBinding == _id); |
||||
|
||||
/* Already up-to-date, nothing to do */ |
||||
if(state->viewport == _viewport) |
||||
return; |
||||
|
||||
/* Update the state and viewport */ |
||||
state->viewport = _viewport; |
||||
glViewport(_viewport.left(), _viewport.bottom(), _viewport.width(), _viewport.height()); |
||||
} |
||||
#endif |
||||
|
||||
void AbstractFramebuffer::clear(ClearMask mask) { |
||||
bindInternal(drawTarget); |
||||
glClear(static_cast<GLbitfield>(mask)); |
||||
} |
||||
|
||||
void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image) { |
||||
bindInternal(readTarget); |
||||
char* data = new char[AbstractImage::pixelSize(format, type)*size.product()]; |
||||
glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(format), static_cast<GLenum>(type), data); |
||||
image->setData(size, format, type, data); |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
void AbstractFramebuffer::read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage) { |
||||
bindInternal(readTarget); |
||||
/* If the buffer doesn't have sufficient size, resize it */ |
||||
/** @todo Explicitly reset also when buffer usage changes */ |
||||
if(image->size() != size || image->format() != format || image->type() != type) |
||||
image->setData(size, format, type, nullptr, usage); |
||||
|
||||
image->buffer()->bind(Buffer::Target::PixelPack); |
||||
glReadPixels(offset.x(), offset.y(), size.x(), size.y(), static_cast<GLenum>(format), static_cast<GLenum>(type), nullptr); |
||||
} |
||||
#endif |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attachments) { |
||||
/** @todo Re-enable when extension wrangler is available for ES2 */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
glInvalidateFramebuffer(GLenum(bindInternal()), count, attachments); |
||||
#else |
||||
//glDiscardFramebufferEXT(GLenum(bindInternal()), count, attachments);
|
||||
static_cast<void>(count); |
||||
static_cast<void>(attachments); |
||||
#endif |
||||
} |
||||
|
||||
void AbstractFramebuffer::invalidateImplementation(GLsizei count, GLenum* attachments, const Rectanglei& rectangle) { |
||||
/** @todo Re-enable when extension wrangler is available for ES2 */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
glInvalidateSubFramebuffer(GLenum(bindInternal()), count, attachments, rectangle.left(), rectangle.bottom(), rectangle.width(), rectangle.height()); |
||||
#else |
||||
//glDiscardSubFramebufferEXT(GLenum(bindInternal()), count, attachments, rectangle.left(), rectangle.bottom(), rectangle.width(), rectangle.height());
|
||||
static_cast<void>(count); |
||||
static_cast<void>(attachments); |
||||
static_cast<void>(rectangle); |
||||
#endif |
||||
} |
||||
#endif |
||||
|
||||
void AbstractFramebuffer::initializeContextBasedFunctionality(Context* context) { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
if(context->isExtensionSupported<Extensions::GL::EXT::framebuffer_blit>()) { |
||||
Debug() << "AbstractFramebuffer: using" << Extensions::GL::EXT::framebuffer_blit::string() << "features"; |
||||
|
||||
readTarget = Target::Read; |
||||
drawTarget = Target::Draw; |
||||
} |
||||
|
||||
if(context->isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) { |
||||
Debug() << "AbstractFramebuffer: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; |
||||
|
||||
drawBuffersImplementation = &AbstractFramebuffer::drawBuffersImplementationDSA; |
||||
drawBufferImplementation = &AbstractFramebuffer::drawBufferImplementationDSA; |
||||
readBufferImplementation = &AbstractFramebuffer::readBufferImplementationDSA; |
||||
} |
||||
#else |
||||
static_cast<void>(context); |
||||
#endif |
||||
} |
||||
|
||||
void AbstractFramebuffer::drawBuffersImplementationDefault(GLsizei count, const GLenum* buffers) { |
||||
/** @todo Re-enable when extension wrangler is available for ES2 */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
bindInternal(drawTarget); |
||||
glDrawBuffers(count, buffers); |
||||
#else |
||||
static_cast<void>(count); |
||||
static_cast<void>(buffers); |
||||
#endif |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void AbstractFramebuffer::drawBuffersImplementationDSA(GLsizei count, const GLenum* buffers) { |
||||
glFramebufferDrawBuffersEXT(_id, count, buffers); |
||||
} |
||||
#endif |
||||
|
||||
void AbstractFramebuffer::drawBufferImplementationDefault(GLenum buffer) { |
||||
/** @todo Re-enable when extension wrangler is available for ES2 */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
bindInternal(drawTarget); |
||||
glDrawBuffer(buffer); |
||||
#else |
||||
static_cast<void>(buffer); |
||||
#endif |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void AbstractFramebuffer::drawBufferImplementationDSA(GLenum buffer) { |
||||
glFramebufferDrawBufferEXT(_id, buffer); |
||||
} |
||||
#endif |
||||
|
||||
void AbstractFramebuffer::readBufferImplementationDefault(GLenum buffer) { |
||||
/** @todo Get some extension wrangler instead to avoid undeclared glReadBuffer() on ES2 */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
bindInternal(readTarget); |
||||
glReadBuffer(buffer); |
||||
#else |
||||
static_cast<void>(buffer); |
||||
#endif |
||||
} |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void AbstractFramebuffer::readBufferImplementationDSA(GLenum buffer) { |
||||
glFramebufferReadBufferEXT(_id, buffer); |
||||
} |
||||
#endif |
||||
|
||||
} |
||||
@ -0,0 +1,310 @@
|
||||
#ifndef Magnum_AbstractFramebuffer_h |
||||
#define Magnum_AbstractFramebuffer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::AbstractFramebuffer |
||||
*/ |
||||
|
||||
#include <Containers/EnumSet.h> |
||||
|
||||
#include "Math/Geometry/Rectangle.h" |
||||
#include "AbstractImage.h" |
||||
#include "Buffer.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief Base for default and named framebuffers |
||||
|
||||
See DefaultFramebuffer and Framebuffer for more information. |
||||
|
||||
@section AbstractFramebuffer-performance-optimization Performance optimizations |
||||
|
||||
The engine tracks currently bound framebuffer and current viewport to avoid |
||||
unnecessary calls to @fn_gl{BindFramebuffer} and @fn_gl{Viewport} when |
||||
switching framebuffers. |
||||
|
||||
@todo @extension{ARB,viewport_array} |
||||
*/ |
||||
class MAGNUM_EXPORT AbstractFramebuffer { |
||||
friend class Context; |
||||
|
||||
AbstractFramebuffer(const AbstractFramebuffer& other) = delete; |
||||
AbstractFramebuffer(AbstractFramebuffer&& other) = delete; |
||||
AbstractFramebuffer& operator=(const AbstractFramebuffer& other) = delete; |
||||
AbstractFramebuffer& operator=(AbstractFramebuffer&& other) = delete; |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Mask for clearing |
||||
* |
||||
* @see ClearMask |
||||
*/ |
||||
enum class Clear: GLbitfield { |
||||
Color = GL_COLOR_BUFFER_BIT, /**< Color */ |
||||
Depth = GL_DEPTH_BUFFER_BIT, /**< Depth value */ |
||||
Stencil = GL_STENCIL_BUFFER_BIT /**< Stencil value */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Mask for clearing |
||||
* |
||||
* @see clear() |
||||
*/ |
||||
typedef Corrade::Containers::EnumSet<Clear, GLbitfield, |
||||
GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT> ClearMask; |
||||
|
||||
/**
|
||||
* @brief Mask for blitting |
||||
* |
||||
* @see BlitMask |
||||
* @requires_gl30 %Extension @extension{EXT,framebuffer_object} |
||||
* @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} |
||||
*/ |
||||
enum class Blit: GLbitfield { |
||||
ColorBuffer = GL_COLOR_BUFFER_BIT, /**< Color buffer */ |
||||
DepthBuffer = GL_DEPTH_BUFFER_BIT, /**< Depth buffer */ |
||||
StencilBuffer = GL_STENCIL_BUFFER_BIT /**< Stencil buffer */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Mask for blitting |
||||
* |
||||
* @see blit() |
||||
* @requires_gl30 %Extension @extension{EXT,framebuffer_object} |
||||
* @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} |
||||
*/ |
||||
typedef Corrade::Containers::EnumSet<Blit, GLbitfield, |
||||
GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT> BlitMask; |
||||
|
||||
/**
|
||||
* @brief Blit filtering |
||||
* |
||||
* @see blit() |
||||
*/ |
||||
enum class BlitFilter: GLenum { |
||||
Nearest = GL_NEAREST, /**< Nearest neighbor filtering */ |
||||
Linear = GL_LINEAR /**< Linear interpolation filtering */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Target for binding framebuffer |
||||
* |
||||
* @see DefaultFramebuffer::bind(), Framebuffer::bind() |
||||
* @requires_gl30 %Extension @extension{EXT,framebuffer_object} |
||||
*/ |
||||
enum class Target: GLenum { |
||||
/**
|
||||
* For reading only. |
||||
* @requires_gl30 %Extension @extension{EXT,framebuffer_blit} |
||||
* @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} |
||||
* or @es_extension{ANGLE,framebuffer_blit} |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
Read = GL_READ_FRAMEBUFFER, |
||||
#else |
||||
Read = GL_READ_FRAMEBUFFER_APPLE, |
||||
#endif |
||||
|
||||
/**
|
||||
* For drawing only. |
||||
* @requires_gl30 %Extension @extension{EXT,framebuffer_blit} |
||||
* @requires_gles30 %Extension @es_extension{APPLE,framebuffer_multisample} |
||||
* or @es_extension{ANGLE,framebuffer_blit} |
||||
*/ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
Draw = GL_DRAW_FRAMEBUFFER, |
||||
#else |
||||
Draw = GL_DRAW_FRAMEBUFFER_APPLE, |
||||
#endif |
||||
|
||||
ReadDraw = GL_FRAMEBUFFER /**< For both reading and drawing. */ |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Copy block of pixels |
||||
* @param source Source framebuffer |
||||
* @param destination Destination framebuffer |
||||
* @param sourceRectangle Source rectangle |
||||
* @param destinationRectangle Destination rectangle |
||||
* @param mask Which buffers to perform blit operation on |
||||
* @param filter Interpolation filter |
||||
* |
||||
* Binds @p source framebuffer to @ref Target "Target::Read" and |
||||
* @p destination framebuffer to @ref Target "Target::Draw" and |
||||
* performs blitting operation. See DefaultFramebuffer::mapForRead(), |
||||
* Framebuffer::mapForRead(), DefaultFramebuffer::mapForDraw() and |
||||
* Framebuffer::mapForDraw() for specifying particular buffers for |
||||
* blitting operation. |
||||
* @see @fn_gl{BlitFramebuffer} |
||||
* @requires_gl30 %Extension @extension{EXT,framebuffer_blit} |
||||
* @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} |
||||
*/ |
||||
static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& sourceRectangle, const Rectanglei& destinationRectangle, BlitMask mask, BlitFilter filter); |
||||
|
||||
/**
|
||||
* @brief Copy block of pixels |
||||
* @param source Source framebuffer |
||||
* @param destination Destination framebuffer |
||||
* @param rectangle Source and destination rectangle |
||||
* @param mask Which buffers to perform blit operation on |
||||
* |
||||
* Convenience alternative to above function when source rectangle is |
||||
* the same as destination rectangle. As the image is copied |
||||
* pixel-by-pixel, no interpolation is needed and thus |
||||
* @ref BlitFilter "BlitFilter::Nearest" filtering is used by default. |
||||
* @see @fn_gl{BlitFramebuffer} |
||||
* @requires_gl30 %Extension @extension{EXT,framebuffer_blit} |
||||
* @requires_gles30 %Extension @es_extension{ANGLE,framebuffer_blit} |
||||
*/ |
||||
inline static void blit(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Rectanglei& rectangle, BlitMask mask) { |
||||
blit(source, destination, rectangle, rectangle, mask, BlitFilter::Nearest); |
||||
} |
||||
|
||||
explicit AbstractFramebuffer() = default; |
||||
virtual ~AbstractFramebuffer() = 0; |
||||
|
||||
/**
|
||||
* @brief Bind framebuffer for rendering |
||||
* |
||||
* Binds the framebuffer and updates viewport to saved dimensions. |
||||
* @see setViewport(), DefaultFramebuffer::mapForRead(), |
||||
* Framebuffer::mapForRead(), DefaultFramebuffer::mapForDraw(), |
||||
* Framebuffer::mapForDraw(), @fn_gl{BindFramebuffer}, |
||||
* @fn_gl{Viewport} |
||||
*/ |
||||
void bind(Target target); |
||||
|
||||
/** @brief Viewport rectangle */ |
||||
inline Rectanglei viewport() const { return _viewport; } |
||||
|
||||
/**
|
||||
* @brief Set viewport |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* Saves the viewport to be used at later time in bind(). If the |
||||
* framebuffer is currently bound, updates the viewport to given |
||||
* rectangle. |
||||
* @see @fn_gl{Viewport} |
||||
*/ |
||||
AbstractFramebuffer* setViewport(const Rectanglei& rectangle); |
||||
|
||||
/**
|
||||
* @brief Clear specified buffers in framebuffer |
||||
* @param mask Which buffers to clear |
||||
* |
||||
* To improve performance you can also use |
||||
* DefaultFramebuffer::invalidate() / Framebuffer::invalidate() instead |
||||
* of clearing given buffer if you will not use it anymore or fully |
||||
* overwrite it later. |
||||
* @see Renderer::setClearColor(), Renderer::setClearDepth(), |
||||
* Renderer::setClearStencil(), @fn_gl{BindFramebuffer}, |
||||
* @fn_gl{Clear} |
||||
*/ |
||||
void clear(ClearMask mask); |
||||
|
||||
/**
|
||||
* @brief Read block of pixels from framebuffer to image |
||||
* @param offset Offset in the framebuffer |
||||
* @param size %Image size |
||||
* @param format Format of pixel data |
||||
* @param type Data type of pixel data |
||||
* @param image %Image where to put the data |
||||
* |
||||
* @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} |
||||
* @todo Read size, format & type from image? |
||||
*/ |
||||
void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, Image2D* image); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* @brief Read block of pixels from framebuffer to buffer image |
||||
* @param offset Offset in the framebuffer |
||||
* @param size %Image size |
||||
* @param format Format of pixel data |
||||
* @param type Data type of pixel data |
||||
* @param image %Buffer image where to put the data |
||||
* @param usage %Buffer usage |
||||
* |
||||
* @see @fn_gl{BindFramebuffer}, @fn_gl{ReadPixels} |
||||
* @requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. |
||||
* @todo Read size, format & type from image? |
||||
*/ |
||||
void read(const Vector2i& offset, const Vector2i& size, AbstractImage::Format format, AbstractImage::Type type, BufferImage2D* image, Buffer::Usage usage); |
||||
#endif |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
protected: |
||||
void MAGNUM_LOCAL bindInternal(Target target); |
||||
Target MAGNUM_LOCAL bindInternal(); |
||||
void MAGNUM_LOCAL setViewportInternal(); |
||||
|
||||
static MAGNUM_LOCAL Target readTarget; |
||||
static MAGNUM_LOCAL Target drawTarget; |
||||
|
||||
typedef void(AbstractFramebuffer::*DrawBuffersImplementation)(GLsizei, const GLenum*); |
||||
static MAGNUM_LOCAL DrawBuffersImplementation drawBuffersImplementation; |
||||
|
||||
typedef void(AbstractFramebuffer::*DrawBufferImplementation)(GLenum); |
||||
static DrawBufferImplementation drawBufferImplementation; |
||||
|
||||
typedef void(AbstractFramebuffer::*ReadBufferImplementation)(GLenum); |
||||
static ReadBufferImplementation readBufferImplementation; |
||||
|
||||
void MAGNUM_LOCAL invalidateImplementation(GLsizei count, GLenum* attachments); |
||||
void MAGNUM_LOCAL invalidateImplementation(GLsizei count, GLenum* attachments, const Rectanglei& rectangle); |
||||
|
||||
GLuint _id; |
||||
Rectanglei _viewport; |
||||
#endif |
||||
|
||||
private: |
||||
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); |
||||
|
||||
void MAGNUM_LOCAL drawBuffersImplementationDefault(GLsizei count, const GLenum* buffers); |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void MAGNUM_LOCAL drawBuffersImplementationDSA(GLsizei count, const GLenum* buffers); |
||||
#endif |
||||
|
||||
void MAGNUM_LOCAL drawBufferImplementationDefault(GLenum buffer); |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void MAGNUM_LOCAL drawBufferImplementationDSA(GLenum buffer); |
||||
#endif |
||||
|
||||
void MAGNUM_LOCAL readBufferImplementationDefault(GLenum buffer); |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
void MAGNUM_LOCAL readBufferImplementationDSA(GLenum buffer); |
||||
#endif |
||||
}; |
||||
|
||||
inline AbstractFramebuffer::~AbstractFramebuffer() {} |
||||
|
||||
CORRADE_ENUMSET_OPERATORS(AbstractFramebuffer::ClearMask) |
||||
CORRADE_ENUMSET_OPERATORS(AbstractFramebuffer::BlitMask) |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -1,105 +1,216 @@
|
||||
/*
|
||||
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. |
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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. |
||||
*/ |
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
#include "AbstractImage.h" |
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
#include <Utility/Debug.h> |
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "TypeTraits.h" |
||||
#include "AbstractImage.h" |
||||
|
||||
using namespace std; |
||||
#include <Utility/Assert.h> |
||||
|
||||
namespace Magnum { |
||||
|
||||
size_t AbstractImage::pixelSize(Components format, ComponentType type) { |
||||
size_t size = 0; |
||||
std::size_t AbstractImage::pixelSize(Format format, Type type) { |
||||
std::size_t size = 0; |
||||
switch(type) { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case ComponentType::RGB332: |
||||
case ComponentType::BGR233: |
||||
return 1; |
||||
case Type::UnsignedByte: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Type::Byte: |
||||
#endif |
||||
case ComponentType::RGB565: |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case ComponentType::BGR565: |
||||
size = 1; break; |
||||
case Type::UnsignedShort: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Type::Short: |
||||
#endif |
||||
case Type::HalfFloat: |
||||
size = 2; break; |
||||
case Type::UnsignedInt: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Type::Int: |
||||
#endif |
||||
case ComponentType::RGBA4: |
||||
case Type::Float: |
||||
size = 4; break; |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case ComponentType::ABGR4: |
||||
case Type::UnsignedByte332: |
||||
case Type::UnsignedByte233Rev: |
||||
return 1; |
||||
#endif |
||||
case ComponentType::RGB5Alpha1: |
||||
case Type::UnsignedShort565: |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case ComponentType::Alpha1BGR5: |
||||
case Type::UnsignedShort565Rev: |
||||
#endif |
||||
case Type::UnsignedShort4444: |
||||
case Type::UnsignedShort4444Rev: |
||||
case Type::UnsignedShort5551: |
||||
case Type::UnsignedShort1555Rev: |
||||
return 2; |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case ComponentType::RGBA8: |
||||
case ComponentType::ABGR8: |
||||
case ComponentType::RGB10Alpha2: |
||||
case ComponentType::Alpha2RGB10: |
||||
case ComponentType::Depth24Stencil8: |
||||
case ComponentType::B10GR11Float: |
||||
case ComponentType::Exponent5RGB9: |
||||
case Type::UnsignedInt8888: |
||||
case Type::UnsignedInt8888Rev: |
||||
case Type::UnsignedInt1010102: |
||||
#endif |
||||
case Type::UnsignedInt2101010Rev: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Type::UnsignedInt10F11F11FRev: |
||||
case Type::UnsignedInt5999Rev: |
||||
#endif |
||||
case Type::UnsignedInt248: |
||||
return 4; |
||||
case ComponentType::Depth32FloatStencil8: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Type::Float32UnsignedInt248Rev: |
||||
return 8; |
||||
#endif |
||||
case ComponentType::UnsignedByte: |
||||
case ComponentType::Byte: |
||||
size = 1; break; |
||||
case ComponentType::UnsignedShort: |
||||
case ComponentType::Short: |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case ComponentType::HalfFloat: |
||||
size = 2; break; |
||||
#endif |
||||
case ComponentType::UnsignedInt: |
||||
case ComponentType::Int: |
||||
case ComponentType::Float: |
||||
size = 4; break; |
||||
} |
||||
|
||||
switch(format) { |
||||
case Format::Red: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Format::RedInteger: |
||||
#endif |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case Components::Red: |
||||
case Components::Green: |
||||
case Components::Blue: |
||||
case Format::Green: |
||||
case Format::Blue: |
||||
case Format::GreenInteger: |
||||
case Format::BlueInteger: |
||||
#endif |
||||
return 1*size; |
||||
case Components::RedGreen: |
||||
case Format::RG: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Format::RGInteger: |
||||
#endif |
||||
return 2*size; |
||||
case Format::RGB: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Format::RGBInteger: |
||||
#endif |
||||
case Components::RGB: |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case Components::BGR: |
||||
case Format::BGR: |
||||
case Format::BGRInteger: |
||||
#endif |
||||
return 3*size; |
||||
case Components::RGBA: |
||||
case Format::RGBA: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
case Format::RGBAInteger: |
||||
#endif |
||||
case Format::BGRA: |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case Components::BGRA: |
||||
case Format::BGRAInteger: |
||||
#endif |
||||
return 4*size; |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
case Components::Depth: |
||||
case Components::StencilIndex: |
||||
case Components::DepthStencil: |
||||
/* Handled above */ |
||||
case Format::DepthComponent: |
||||
case Format::StencilIndex: |
||||
case Format::DepthStencil: |
||||
CORRADE_INTERNAL_ASSERT(false); |
||||
#endif |
||||
} |
||||
|
||||
CORRADE_INTERNAL_ASSERT(false); |
||||
return 0; |
||||
} |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
Debug operator<<(Debug debug, AbstractImage::Format value) { |
||||
switch(value) { |
||||
#define _c(value) case AbstractImage::Format::value: return debug << "AbstractImage::Format::" #value; |
||||
_c(Red) |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
_c(Green) |
||||
_c(Blue) |
||||
#endif |
||||
_c(RG) |
||||
_c(RGB) |
||||
_c(RGBA) |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
_c(BGR) |
||||
#endif |
||||
_c(BGRA) |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
_c(RedInteger) |
||||
_c(GreenInteger) |
||||
_c(BlueInteger) |
||||
_c(RGInteger) |
||||
_c(RGBInteger) |
||||
_c(RGBAInteger) |
||||
_c(BGRInteger) |
||||
_c(BGRAInteger) |
||||
#endif |
||||
_c(DepthComponent) |
||||
_c(StencilIndex) |
||||
_c(DepthStencil) |
||||
#undef _c |
||||
} |
||||
|
||||
return debug << "AbstractImage::Format::(invalid)"; |
||||
} |
||||
|
||||
Debug operator<<(Debug debug, AbstractImage::Type value) { |
||||
switch(value) { |
||||
#define _c(value) case AbstractImage::Type::value: return debug << "AbstractImage::Type::" #value; |
||||
_c(UnsignedByte) |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
_c(Byte) |
||||
#endif |
||||
_c(UnsignedShort) |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
_c(Short) |
||||
#endif |
||||
_c(UnsignedInt) |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
_c(Int) |
||||
#endif |
||||
_c(HalfFloat) |
||||
_c(Float) |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
_c(UnsignedByte332) |
||||
_c(UnsignedByte233Rev) |
||||
#endif |
||||
_c(UnsignedShort565) |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
_c(UnsignedShort565Rev) |
||||
#endif |
||||
_c(UnsignedShort4444) |
||||
_c(UnsignedShort4444Rev) |
||||
_c(UnsignedShort5551) |
||||
_c(UnsignedShort1555Rev) |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
_c(UnsignedInt8888) |
||||
_c(UnsignedInt8888Rev) |
||||
_c(UnsignedInt1010102) |
||||
#endif |
||||
_c(UnsignedInt2101010Rev) |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
_c(UnsignedInt10F11F11FRev) |
||||
_c(UnsignedInt5999Rev) |
||||
#endif |
||||
_c(UnsignedInt248) |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
_c(Float32UnsignedInt248Rev) |
||||
#endif |
||||
#undef _c |
||||
} |
||||
|
||||
return debug << "AbstractImage::Type::(invalid)"; |
||||
} |
||||
#endif |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,221 @@
|
||||
#ifndef Magnum_Array_h |
||||
#define Magnum_Array_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Array, Magnum::Array1D, Magnum::Array2D, Magnum::Array3D |
||||
*/ |
||||
|
||||
#include <type_traits> |
||||
#include <Utility/Debug.h> |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief %Array |
||||
@tparam dimensions Dimension count |
||||
@tparam T Data type |
||||
|
||||
Similar to Math::Vector, but more suitable for storing enum values which don't |
||||
need any math operations and fuzzy comparison (e.g. enum values). Unlike |
||||
Math::Vector this class has non-explicit constructor from one value. |
||||
@see Array1D, Array2D, Array3D |
||||
*/ |
||||
template<UnsignedInt dimensions, class T> class Array { |
||||
public: |
||||
typedef T Type; /**< @brief Data type */ |
||||
const static UnsignedInt Dimensions = dimensions; /**< @brief Dimension count */ |
||||
|
||||
/**
|
||||
* @brief Default constructor |
||||
* |
||||
* Sets all components to their default-constructed values |
||||
*/ |
||||
inline constexpr /*implicit*/ Array(): _data() {} |
||||
|
||||
/**
|
||||
* @brief Initializer-list constructor |
||||
* @param first First value |
||||
* @param next Next values |
||||
*/ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
template<class ...U> inline constexpr /*implicit*/ Array(T first, T second, U... next): _data{first, second, next...} { |
||||
static_assert(sizeof...(next)+2 == dimensions, "Improper number of arguments passed to Array constructor"); |
||||
} |
||||
template<class U = T> inline constexpr /*implicit*/ Array(typename std::enable_if<std::is_same<T, U>::value && dimensions == 1, U>::type first): _data{first} {} |
||||
#else |
||||
template<class ...U> inline constexpr /*implicit*/ Array(T first, U... next); |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param value Value for all fields |
||||
*/ |
||||
template<class U, class = typename std::enable_if<std::is_same<T, U>::value && dimensions != 1, U>::type> inline /*implicit*/ Array(U value) { |
||||
for(UnsignedInt i = 0; i != dimensions; ++i) |
||||
_data[i] = value; |
||||
} |
||||
|
||||
/** @brief Equality */ |
||||
inline bool operator==(const Array<dimensions, T>& other) const { |
||||
for(UnsignedInt i = 0; i != dimensions; ++i) |
||||
if(_data[i] != other._data[i]) return false; |
||||
return true; |
||||
} |
||||
|
||||
/** @brief Non-equality */ |
||||
inline bool operator!=(const Array<dimensions, T>& other) const { |
||||
return !operator==(other); |
||||
} |
||||
|
||||
/** @brief Value at given position */ |
||||
inline T& operator[](UnsignedInt pos) { return _data[pos]; } |
||||
inline constexpr T operator[](UnsignedInt pos) const { return _data[pos]; } /**< @overload */ |
||||
|
||||
/**
|
||||
* @brief Raw data |
||||
* @return One-dimensional array of `dimensions` length |
||||
*/ |
||||
inline T* data() { return _data; } |
||||
inline constexpr const T* data() const { return _data; } /**< @overload */ |
||||
|
||||
private: |
||||
T _data[dimensions]; |
||||
}; |
||||
|
||||
/**
|
||||
@brief One-dimensional array |
||||
@tparam T Data type |
||||
*/ |
||||
template<class T> class Array1D: public Array<1, T> { |
||||
public: |
||||
/** @copydoc Array::Array() */ |
||||
inline constexpr /*implicit*/ Array1D() = default; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param x X component |
||||
*/ |
||||
inline constexpr /*implicit*/ Array1D(T x): Array<1, T>(x) {} |
||||
|
||||
/** @brief Copy constructor */ |
||||
inline constexpr Array1D(const Array<1, T>& other): Array<1, T>(other) {} |
||||
|
||||
inline T& x() { return (*this)[0]; } /**< @brief X component */ |
||||
inline constexpr T x() const { return (*this)[0]; } /**< @overload */ |
||||
}; |
||||
|
||||
/**
|
||||
@brief Two-dimensional array |
||||
@tparam T Data type |
||||
*/ |
||||
template<class T> class Array2D: public Array<2, T> { |
||||
public: |
||||
/** @copydoc Array::Array() */ |
||||
inline constexpr /*implicit*/ Array2D() = default; |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param x X component |
||||
* @param y Y component |
||||
*/ |
||||
inline constexpr /*implicit*/ Array2D(T x, T y): Array<2, T>(x, y) {} |
||||
|
||||
/** @copydoc Array::Array(U) */ |
||||
inline constexpr /*implicit*/ Array2D(T value): Array<2, T>(value, value) {} |
||||
|
||||
/** @brief Copy constructor */ |
||||
inline constexpr Array2D(const Array<2, T>& other): Array<2, T>(other) {} |
||||
|
||||
inline T& x() { return (*this)[0]; } /**< @brief X component */ |
||||
inline constexpr T x() const { return (*this)[0]; } /**< @overload */ |
||||
inline T& y() { return (*this)[1]; } /**< @brief Y component */ |
||||
inline constexpr T y() const { return (*this)[1]; } /**< @overload */ |
||||
}; |
||||
|
||||
/**
|
||||
@brief Three-dimensional array |
||||
@tparam T Data type |
||||
*/ |
||||
template<class T> class Array3D: public Array<3, T> { |
||||
public: |
||||
/** @copydoc Array::Array() */ |
||||
inline constexpr /*implicit*/ Array3D() {} |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param x X component |
||||
* @param y Y component |
||||
* @param z Z component |
||||
*/ |
||||
inline constexpr /*implicit*/ Array3D(T x, T y, T z): Array<3, T>(x, y, z) {} |
||||
|
||||
/** @copydoc Array::Array(U) */ |
||||
inline constexpr /*implicit*/ Array3D(T value): Array<3, T>(value, value, value) {} |
||||
|
||||
/** @brief Copy constructor */ |
||||
inline constexpr Array3D(const Array<3, T>& other): Array<3, T>(other) {} |
||||
|
||||
inline T& x() { return (*this)[0]; } /**< @brief X component */ |
||||
inline constexpr T x() const { return (*this)[0]; } /**< @overload */ |
||||
inline T& y() { return (*this)[1]; } /**< @brief Y component */ |
||||
inline constexpr T y() const { return (*this)[1]; } /**< @overload */ |
||||
inline T& z() { return (*this)[2]; } /**< @brief Z component */ |
||||
inline constexpr T z() const { return (*this)[2]; } /**< @overload */ |
||||
}; |
||||
|
||||
/** @debugoperator{Magnum::Array} */ |
||||
template<UnsignedInt dimensions, class T> Debug operator<<(Debug debug, const Array<dimensions, T>& value) { |
||||
debug << "Array("; |
||||
debug.setFlag(Debug::SpaceAfterEachValue, false); |
||||
for(UnsignedInt i = 0; i != dimensions; ++i) { |
||||
if(i != 0) debug << ", "; |
||||
debug << value[i]; |
||||
} |
||||
debug << ")"; |
||||
debug.setFlag(Debug::SpaceAfterEachValue, true); |
||||
return debug; |
||||
} |
||||
|
||||
/** @debugoperator{Magnum::Array1D} */ |
||||
template<class T> inline Debug operator<<(Debug debug, const Array1D<T>& value) { |
||||
return debug << static_cast<const Array<1, T>&>(value); |
||||
} |
||||
|
||||
/** @debugoperator{Magnum::Array2D} */ |
||||
template<class T> inline Debug operator<<(Debug debug, const Array2D<T>& value) { |
||||
return debug << static_cast<const Array<2, T>&>(value); |
||||
} |
||||
|
||||
/** @debugoperator{Magnum::Array3D} */ |
||||
template<class T> inline Debug operator<<(Debug debug, const Array3D<T>& value) { |
||||
return debug << static_cast<const Array<3, T>&>(value); |
||||
} |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,42 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "BufferImage.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
template<UnsignedInt dimensions> void BufferImage<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage) { |
||||
_format = format; |
||||
_type = type; |
||||
_size = size; |
||||
_buffer.setData(pixelSize(format, type)*size.product(), data, usage); |
||||
} |
||||
|
||||
template class BufferImage<1>; |
||||
template class BufferImage<2>; |
||||
template class BufferImage<3>; |
||||
#endif |
||||
|
||||
} |
||||
@ -0,0 +1,103 @@
|
||||
#ifndef Magnum_BufferImage_h |
||||
#define Magnum_BufferImage_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/** @file
|
||||
* @brief Class Magnum::BufferImage, typedef Magnum::BufferImage1D, Magnum::BufferImage2D, Magnum::BufferImage3D |
||||
*/ |
||||
#endif |
||||
|
||||
#include "Math/Vector3.h" |
||||
#include "AbstractImage.h" |
||||
#include "Buffer.h" |
||||
#include "DimensionTraits.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
@brief %Buffer image |
||||
|
||||
Stores image data in GPU memory. Interchangeable with Image, ImageWrapper or |
||||
Trade::ImageData. |
||||
@see BufferImage1D, BufferImage2D, BufferImage3D, Buffer |
||||
@requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. |
||||
*/ |
||||
template<UnsignedInt dimensions> class MAGNUM_EXPORT BufferImage: public AbstractImage { |
||||
public: |
||||
const static UnsignedInt Dimensions = dimensions; /**< @brief %Image dimension count */ |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param format Format of pixel data |
||||
* @param type Data type of pixel data |
||||
* |
||||
* Dimensions and buffer are empty, call setData() to fill the image |
||||
* with data. |
||||
*/ |
||||
inline explicit BufferImage(Format format, Type type): AbstractImage(format, type) { |
||||
_buffer.setTargetHint(Buffer::Target::PixelPack); |
||||
} |
||||
|
||||
/** @brief %Image size */ |
||||
inline typename DimensionTraits<Dimensions, Int>::VectorType size() const { return _size; } |
||||
|
||||
/** @brief %Image buffer */ |
||||
inline Buffer* buffer() { return &_buffer; } |
||||
|
||||
/**
|
||||
* @brief Set image data |
||||
* @param size %Image size |
||||
* @param format Format of pixel data |
||||
* @param type Data type of pixel data |
||||
* @param data %Image data |
||||
* @param usage %Image buffer usage |
||||
* |
||||
* Updates the image buffer with given data. The data are not deleted |
||||
* after filling the buffer. |
||||
* |
||||
* @see Buffer::setData() |
||||
*/ |
||||
void setData(const typename DimensionTraits<Dimensions, Int>::VectorType& size, Format format, Type type, const GLvoid* data, Buffer::Usage usage); |
||||
|
||||
private: |
||||
Math::Vector<Dimensions, Int> _size; |
||||
Buffer _buffer; |
||||
}; |
||||
|
||||
/** @brief One-dimensional buffer image */ |
||||
typedef BufferImage<1> BufferImage1D; |
||||
|
||||
/** @brief Two-dimensional buffer image */ |
||||
typedef BufferImage<2> BufferImage2D; |
||||
|
||||
/** @brief Three-dimensional buffer image */ |
||||
typedef BufferImage<3> BufferImage3D; |
||||
#endif |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -0,0 +1,66 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "BufferTexture.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
#include "Buffer.h" |
||||
#include "Context.h" |
||||
#include "Extensions.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
BufferTexture::SetBufferImplementation BufferTexture::setBufferImplementation = &BufferTexture::setBufferImplementationDefault; |
||||
BufferTexture::SetBufferRangeImplementation BufferTexture::setBufferRangeImplementation = &BufferTexture::setBufferRangeImplementationDefault; |
||||
|
||||
void BufferTexture::initializeContextBasedFunctionality(Context* context) { |
||||
if(context->isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) { |
||||
Debug() << "BufferTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; |
||||
|
||||
setBufferImplementation = &BufferTexture::setBufferImplementationDSA; |
||||
setBufferRangeImplementation = &BufferTexture::setBufferRangeImplementationDSA; |
||||
} |
||||
} |
||||
|
||||
void BufferTexture::setBufferImplementationDefault(InternalFormat internalFormat, Buffer* buffer) { |
||||
bindInternal(); |
||||
glTexBuffer(GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); |
||||
} |
||||
|
||||
void BufferTexture::setBufferImplementationDSA(InternalFormat internalFormat, Buffer* buffer) { |
||||
glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id()); |
||||
} |
||||
|
||||
void BufferTexture::setBufferRangeImplementationDefault(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size) { |
||||
bindInternal(); |
||||
glTexBufferRange(GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id(), offset, size); |
||||
} |
||||
|
||||
void BufferTexture::setBufferRangeImplementationDSA(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size) { |
||||
glTextureBufferRangeEXT(id(), GL_TEXTURE_BUFFER, GLenum(internalFormat), buffer->id(), offset, size); |
||||
} |
||||
|
||||
|
||||
} |
||||
#endif |
||||
@ -0,0 +1,261 @@
|
||||
#ifndef Magnum_BufferTexture_h |
||||
#define Magnum_BufferTexture_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @file
|
||||
* @brief Class Magnum::BufferTexture |
||||
*/ |
||||
#endif |
||||
|
||||
#include "AbstractTexture.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief %Buffer texture |
||||
|
||||
This texture is, unlike classic textures such as Texture or CubeMapTexture, |
||||
used as simple data source, without any unnecessary interpolation and |
||||
wrapping methods. |
||||
|
||||
@section BufferTexture-usage Usage |
||||
|
||||
%Texture data are stored in buffer and after binding the buffer to the texture |
||||
using setBuffer(), you can fill the buffer at any time using data setting |
||||
functions in Buffer itself. |
||||
|
||||
Note that the buffer is not managed (e.g. deleted on destruction) by the |
||||
texture, so you have to manage it on your own. On the other hand it allows you |
||||
to use one buffer for more textures or store more than one data in it. |
||||
|
||||
Example usage: |
||||
@code |
||||
Buffer* buffer; |
||||
BufferTexture texture; |
||||
texture.setBuffer(buffer); |
||||
|
||||
constexpr static Vector3 data[] = { |
||||
// ...
|
||||
}; |
||||
buffer.setData(data, Buffer::Usage::StaticDraw); |
||||
@endcode |
||||
|
||||
The texture is bound to layer specified by shader via bind(). In shader, the |
||||
texture is used via `samplerBuffer`. Unlike in classic textures, coordinates |
||||
for buffer textures are integer coordinates passed to `texelFetch()`. See also |
||||
AbstractShaderProgram documentation for more information. |
||||
|
||||
@section BufferTexture-performance-optimization Performance optimizations |
||||
If extension @extension{EXT,direct_state_access} is available, setBuffer() |
||||
functions use DSA to avoid unnecessary calls to @fn_gl{ActiveTexture} and |
||||
@fn_gl{BindTexture}. See @ref AbstractTexture-performance-optimization |
||||
"relevant section in AbstractTexture documentation" and respective function |
||||
documentation for more information. |
||||
|
||||
@requires_gl31 %Extension @extension{ARB,texture_buffer_object} |
||||
@requires_gl Texture buffers are not available in OpenGL ES. |
||||
*/ |
||||
class MAGNUM_EXPORT BufferTexture: private AbstractTexture { |
||||
friend class Context; |
||||
|
||||
BufferTexture(const BufferTexture& other) = delete; |
||||
BufferTexture(BufferTexture&& other) = delete; |
||||
BufferTexture& operator=(const BufferTexture& other) = delete; |
||||
BufferTexture& operator=(BufferTexture&& other) = delete; |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Internal format |
||||
* |
||||
* @see setBuffer() |
||||
*/ |
||||
enum class InternalFormat: GLenum { |
||||
/** Red component, normalized unsigned byte. */ |
||||
R8 = GL_R8, |
||||
|
||||
/** Red and green component, each normalized unsigned byte. */ |
||||
RG8 = GL_RG8, |
||||
|
||||
/** RGBA, each component normalized unsigned byte. */ |
||||
RGBA8 = GL_RGBA8, |
||||
|
||||
/** Red component, normalized unsigned short. */ |
||||
R16 = GL_R16, |
||||
|
||||
/** Red and green component, each normalized unsigned short. */ |
||||
RG16 = GL_RG16, |
||||
|
||||
/** RGBA, each component normalized unsigned short. */ |
||||
RGBA16 = GL_RGBA16, |
||||
|
||||
/** Red component, non-normalized unsigned byte. */ |
||||
R8UI = GL_R8UI, |
||||
|
||||
/** Red and green component, each non-normalized unsigned byte. */ |
||||
RG8UI = GL_RG8UI, |
||||
|
||||
/** RGBA, each component non-normalized unsigned byte. */ |
||||
RGBA8UI = GL_RGBA8UI, |
||||
|
||||
/** Red component, non-normalized signed byte. */ |
||||
R8I = GL_R8I, |
||||
|
||||
/** Red and green component, each non-normalized signed byte. */ |
||||
RG8I = GL_RG8I, |
||||
|
||||
/** RGBA, each component non-normalized signed byte. */ |
||||
RGBA8I = GL_RGBA8I, |
||||
|
||||
/** Red component, non-normalized unsigned short. */ |
||||
R16UI = GL_R16UI, |
||||
|
||||
/** Red and green component, each non-normalized unsigned short. */ |
||||
RG16UI = GL_RG16UI, |
||||
|
||||
/** RGBA, each component non-normalized unsigned short. */ |
||||
RGBA16UI = GL_RGBA16UI, |
||||
|
||||
/** Red component, non-normalized signed short. */ |
||||
R16I = GL_R16I, |
||||
|
||||
/** Red and green component, each non-normalized signed short. */ |
||||
RG16I = GL_RG16I, |
||||
|
||||
/** RGBA, each component non-normalized signed short. */ |
||||
RGBA16I = GL_RGBA16I, |
||||
|
||||
/** Red component, non-normalized unsigned int. */ |
||||
R32UI = GL_R32UI, |
||||
|
||||
/** Red and green component, each non-normalized unsigned int. */ |
||||
RG32UI = GL_RG32UI, |
||||
|
||||
/**
|
||||
* RGB, each component non-normalized unsigned int. |
||||
* @requires_gl40 %Extension @extension{ARB,texture_buffer_object_rgb32} |
||||
*/ |
||||
RGB32UI = GL_RGB32UI, |
||||
|
||||
/** RGBA, each component non-normalized unsigned int. */ |
||||
RGBA32UI = GL_RGBA32UI, |
||||
|
||||
/** Red component, non-normalized signed int. */ |
||||
R32I = GL_R32I, |
||||
|
||||
/** Red and green component, each non-normalized signed int. */ |
||||
RG32I = GL_RG32I, |
||||
|
||||
/**
|
||||
* RGB, each component non-normalized signed int. |
||||
* @requires_gl40 %Extension @extension{ARB,texture_buffer_object_rgb32} |
||||
*/ |
||||
RGB32I = GL_RGB32I, |
||||
|
||||
/** RGBA, each component non-normalized signed int. */ |
||||
RGBA32I = GL_RGBA32I, |
||||
|
||||
/** Red component, half float. */ |
||||
R16F = GL_R16F, |
||||
|
||||
/** Red and green component, each half float. */ |
||||
RG16F = GL_RG16F, |
||||
|
||||
/** RGBA, each component half float. */ |
||||
RGBA16F = GL_RGBA16F, |
||||
|
||||
/** Red component, float. */ |
||||
R32F = GL_R32F, |
||||
|
||||
/** Red and green component, each float. */ |
||||
RG32F = GL_RG32F, |
||||
|
||||
/**
|
||||
* RGB, each component float. |
||||
* @requires_gl40 %Extension @extension{ARB,texture_buffer_object_rgb32} |
||||
*/ |
||||
RGB32F = GL_RGB32F, |
||||
|
||||
/** RGBA, each component float. */ |
||||
RGBA32F = GL_RGBA32F |
||||
}; |
||||
|
||||
inline explicit BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} |
||||
|
||||
/** @copydoc AbstractTexture::bind() */ |
||||
inline void bind(Int layer) { AbstractTexture::bind(layer); } |
||||
|
||||
/**
|
||||
* @brief Set texture buffer |
||||
* @param internalFormat Internal format |
||||
* @param buffer %Buffer with data |
||||
* |
||||
* Binds given buffer to this texture. The buffer itself can be then |
||||
* filled with data of proper format at any time using Buffer own data |
||||
* setting functions. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexBuffer} |
||||
* or @fn_gl_extension{TextureBuffer,EXT,direct_state_access} |
||||
*/ |
||||
inline void setBuffer(InternalFormat internalFormat, Buffer* buffer) { |
||||
(this->*setBufferImplementation)(internalFormat, buffer); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Set texture buffer |
||||
* @param internalFormat Internal format |
||||
* @param buffer %Buffer |
||||
* @param offset Offset |
||||
* @param size Data size |
||||
* |
||||
* Binds range of given buffer to this texture. The buffer itself can |
||||
* be then filled with data of proper format at any time using Buffer |
||||
* own data setting functions. |
||||
* @requires_gl43 %Extension @extension{ARB,texture_buffer_range} |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexBuffer} |
||||
* or @fn_gl_extension{TextureBufferRange,EXT,direct_state_access} |
||||
*/ |
||||
inline void setBuffer(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size) { |
||||
(this->*setBufferRangeImplementation)(internalFormat, buffer, offset, size); |
||||
} |
||||
|
||||
private: |
||||
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); |
||||
|
||||
typedef void(BufferTexture::*SetBufferImplementation)(InternalFormat, Buffer*); |
||||
void MAGNUM_LOCAL setBufferImplementationDefault(InternalFormat internalFormat, Buffer* buffer); |
||||
void MAGNUM_LOCAL setBufferImplementationDSA(InternalFormat internalFormat, Buffer* buffer); |
||||
static SetBufferImplementation setBufferImplementation; |
||||
|
||||
typedef void(BufferTexture::*SetBufferRangeImplementation)(InternalFormat, Buffer*, GLintptr, GLsizeiptr); |
||||
void MAGNUM_LOCAL setBufferRangeImplementationDefault(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size); |
||||
void MAGNUM_LOCAL setBufferRangeImplementationDSA(InternalFormat internalFormat, Buffer* buffer, GLintptr offset, GLsizeiptr size); |
||||
static SetBufferRangeImplementation setBufferRangeImplementation; |
||||
}; |
||||
|
||||
} |
||||
#endif |
||||
|
||||
#endif |
||||
@ -1,33 +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 "BufferedImage.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
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>; |
||||
#endif |
||||
|
||||
} |
||||
@ -1,127 +0,0 @@
|
||||
#ifndef Magnum_BufferedImage_h |
||||
#define Magnum_BufferedImage_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. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/** @file
|
||||
* @brief Class Magnum::BufferedImage, typedef Magnum::BufferedImage1D, Magnum::BufferedImage2D, Magnum::BufferedImage3D |
||||
*/ |
||||
#endif |
||||
|
||||
#include "Math/Vector3.h" |
||||
#include "AbstractImage.h" |
||||
#include "Buffer.h" |
||||
#include "DimensionTraits.h" |
||||
#include "TypeTraits.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
@brief %Buffered image |
||||
|
||||
Class for storing image data in GPU memory. Can be replaced with Image, which |
||||
stores image data in client memory, ImageWrapper, or for example with |
||||
Trade::ImageData. |
||||
@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer |
||||
@requires_gles30 Pixel buffer objects are not available in OpenGL ES 2.0. |
||||
*/ |
||||
template<std::uint8_t dimensions> class MAGNUM_EXPORT BufferedImage: public AbstractImage { |
||||
public: |
||||
const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ |
||||
|
||||
/**
|
||||
* @brief Constructor |
||||
* @param components Color components |
||||
* @param type Data type |
||||
* |
||||
* Dimensions and buffer are empty, call setData() to fill the image |
||||
* with data. |
||||
*/ |
||||
inline BufferedImage(Components components, ComponentType type): AbstractImage(components, type) { |
||||
_buffer.setTargetHint(Buffer::Target::PixelPack); |
||||
} |
||||
|
||||
/** @brief %Image size */ |
||||
inline typename DimensionTraits<Dimensions, GLsizei>::VectorType size() const { return _size; } |
||||
|
||||
/**
|
||||
* @brief Data |
||||
* |
||||
* Binds the buffer to @ref Buffer::Target "pixel unpack |
||||
* target" and returns nullptr, so it can be used for texture updating |
||||
* functions the same way as Image::data(). |
||||
* |
||||
* @see Buffer::bind(Target) |
||||
*/ |
||||
inline void* data() { |
||||
_buffer.bind(Buffer::Target::PixelUnpack); |
||||
return nullptr; |
||||
} |
||||
|
||||
/** @brief %Image buffer */ |
||||
inline Buffer* buffer() { return &_buffer; } |
||||
|
||||
/**
|
||||
* @brief Set image data |
||||
* @param size %Image size |
||||
* @param components Color components. Data type is detected |
||||
* from passed data array. |
||||
* @param data %Image data |
||||
* @param usage %Image buffer usage |
||||
* |
||||
* Updates the image buffer with given data. The data are not deleted |
||||
* after filling the buffer. |
||||
* |
||||
* @see setData(const Math::Vector<Dimensions, GLsizei>&, Components, ComponentType, const GLvoid*, Buffer::Usage) |
||||
*/ |
||||
template<class T> inline void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, const T* data, Buffer::Usage usage) { |
||||
setData(size, components, TypeTraits<T>::imageType(), data, usage); |
||||
} |
||||
|
||||
/**
|
||||
* @brief Set image data |
||||
* @param size %Image size |
||||
* @param components Color components |
||||
* @param type Data type |
||||
* @param data %Image data |
||||
* @param usage %Image buffer usage |
||||
* |
||||
* Updates the image buffer with given data. The data are not deleted |
||||
* after filling the buffer. |
||||
* |
||||
* @see Buffer::setData() |
||||
*/ |
||||
void setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage); |
||||
|
||||
protected: |
||||
Math::Vector<Dimensions, GLsizei> _size; /**< @brief %Image size */ |
||||
Buffer _buffer; /**< @brief %Image buffer */ |
||||
}; |
||||
|
||||
/** @brief One-dimensional buffered image */ |
||||
typedef BufferedImage<1> BufferedImage1D; |
||||
|
||||
/** @brief Two-dimensional buffered image */ |
||||
typedef BufferedImage<2> BufferedImage2D; |
||||
|
||||
/** @brief Three-dimensional buffered image */ |
||||
typedef BufferedImage<3> BufferedImage3D; |
||||
#endif |
||||
|
||||
} |
||||
|
||||
#endif |
||||
@ -1,77 +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 "BufferedTexture.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
#include "Buffer.h" |
||||
#include "Context.h" |
||||
#include "Extensions.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
BufferedTexture::SetBufferImplementation BufferedTexture::setBufferImplementation = &BufferedTexture::setBufferImplementationDefault; |
||||
|
||||
void BufferedTexture::initializeContextBasedFunctionality(Context* context) { |
||||
if(context->isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) { |
||||
Debug() << "BufferedTexture: using" << Extensions::GL::EXT::direct_state_access::string() << "features"; |
||||
|
||||
setBufferImplementation = &BufferedTexture::setBufferImplementationDSA; |
||||
} |
||||
} |
||||
|
||||
void BufferedTexture::setBufferImplementationDefault(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { |
||||
bindInternal(); |
||||
glTexBuffer(GL_TEXTURE_BUFFER, internalFormat, buffer->id()); |
||||
} |
||||
|
||||
void BufferedTexture::setBufferImplementationDSA(BufferedTexture::InternalFormat internalFormat, Buffer* buffer) { |
||||
glTextureBufferEXT(id(), GL_TEXTURE_BUFFER, internalFormat, buffer->id()); |
||||
} |
||||
|
||||
BufferedTexture::InternalFormat::InternalFormat(Components components, ComponentType type) { |
||||
#define internalFormatSwitch(c) switch(type) { \ |
||||
case ComponentType::UnsignedByte: \
|
||||
internalFormat = GL_##c##8UI; break; \
|
||||
case ComponentType::Byte: \
|
||||
internalFormat = GL_##c##8I; break; \
|
||||
case ComponentType::UnsignedShort: \
|
||||
internalFormat = GL_##c##16UI; break; \
|
||||
case ComponentType::Short: \
|
||||
internalFormat = GL_##c##16I; break; \
|
||||
case ComponentType::UnsignedInt: \
|
||||
internalFormat = GL_##c##32UI; break; \
|
||||
case ComponentType::Int: \
|
||||
internalFormat = GL_##c##32I; break; \
|
||||
case ComponentType::Half: \
|
||||
internalFormat = GL_##c##16F; break; \
|
||||
case ComponentType::Float: \
|
||||
internalFormat = GL_##c##32F; break; \
|
||||
case ComponentType::NormalizedUnsignedByte: \
|
||||
internalFormat = GL_##c##8; break; \
|
||||
case ComponentType::NormalizedUnsignedShort: \
|
||||
internalFormat = GL_##c##16; break; \
|
||||
} |
||||
if(components == Components::Red) |
||||
internalFormatSwitch(R) |
||||
else if(components == Components::RedGreen) |
||||
internalFormatSwitch(RG) |
||||
else if(components == Components::RGBA) |
||||
internalFormatSwitch(RGBA) |
||||
#undef internalFormatSwitch |
||||
} |
||||
|
||||
} |
||||
#endif |
||||
@ -1,175 +0,0 @@
|
||||
#ifndef Magnum_BufferedTexture_h |
||||
#define Magnum_BufferedTexture_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. |
||||
*/ |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/** @file
|
||||
* @brief Class Magnum::BufferedTexture |
||||
*/ |
||||
#endif |
||||
|
||||
#include "AbstractTexture.h" |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief Buffered texture |
||||
|
||||
This texture is, unlike classic textures such as Texture or CubeMapTexture, |
||||
used as simple data source, without any unneccessary interpolation and |
||||
wrapping methods. Texture data are stored in buffer and after binding the |
||||
buffer to the texture using setBuffer(), you can fill the buffer at any time |
||||
using data setting functions in Buffer itself. |
||||
|
||||
When using buffered texture in the shader, use `samplerBuffer` and fetch the |
||||
data using integer coordinates in `texelFetch()`. |
||||
|
||||
@section BufferedTexture-performance-optimization Performance optimizations |
||||
If extension @extension{EXT,direct_state_access} is available, setBuffer() |
||||
uses DSA function to avoid unnecessary calls to @fn_gl{ActiveTexture} and |
||||
@fn_gl{BindTexture}. See @ref AbstractTexture-performance-optimization |
||||
"relevant section in AbstractTexture documentation" and respective function |
||||
documentation for more information. |
||||
|
||||
@requires_gl31 Extension @extension{ARB,texture_buffer_object} |
||||
@requires_gl Texture buffers are not available in OpenGL ES. |
||||
*/ |
||||
class MAGNUM_EXPORT BufferedTexture: private AbstractTexture { |
||||
friend class Context; |
||||
|
||||
BufferedTexture(const BufferedTexture& other) = delete; |
||||
BufferedTexture(BufferedTexture&& other) = delete; |
||||
BufferedTexture& operator=(const BufferedTexture& other) = delete; |
||||
BufferedTexture& operator=(BufferedTexture&& other) = delete; |
||||
|
||||
public: |
||||
/** @{ @name Internal buffered texture formats */ |
||||
|
||||
/**
|
||||
* @copybrief AbstractTexture::Components |
||||
* |
||||
* Like AbstractTexture::Components, without three-component RGB. |
||||
*/ |
||||
enum class Components { |
||||
Red, RedGreen, RGBA |
||||
}; |
||||
|
||||
/**
|
||||
* @copybrief AbstractTexture::ComponentType |
||||
* |
||||
* Like AbstractTexture::ComponentType, without normalized signed |
||||
* types. |
||||
*/ |
||||
enum class ComponentType { |
||||
UnsignedByte, Byte, UnsignedShort, Short, UnsignedInt, Int, Half, |
||||
Float, NormalizedUnsignedByte, NormalizedUnsignedShort |
||||
}; |
||||
|
||||
/** @copybrief AbstractTexture::Format */ |
||||
enum class Format: GLenum { |
||||
/**
|
||||
* Three-component RGB, float, each component 32bit, 96bit total. |
||||
* |
||||
* @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} |
||||
*/ |
||||
RGB32Float = GL_RGB32F, |
||||
|
||||
/**
|
||||
* Three-component RGB, unsigned non-normalized, each component |
||||
* 32bit, 96bit total. |
||||
* |
||||
* @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} |
||||
*/ |
||||
RGB32UnsignedInt = GL_RGB32UI, |
||||
|
||||
/**
|
||||
* Three-component RGB, signed non-normalized, each component |
||||
* 32bit, 96bit total. |
||||
* |
||||
* @requires_gl40 Extension @extension{ARB,texture_buffer_object_rgb32} |
||||
*/ |
||||
RGB32Int = GL_RGB32I |
||||
}; |
||||
|
||||
/** @copydoc AbstractTexture::InternalFormat */ |
||||
class MAGNUM_EXPORT InternalFormat { |
||||
public: |
||||
/** @copybrief AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components, AbstractTexture::ComponentType) */ |
||||
InternalFormat(Components components, ComponentType type); |
||||
|
||||
/** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Format) */ |
||||
inline constexpr InternalFormat(Format format): internalFormat(static_cast<GLenum>(format)) {} |
||||
|
||||
/**
|
||||
* @brief OpenGL internal format ID |
||||
* |
||||
* @todoc Remove workaround when Doxygen supports \@copydoc for conversion operators |
||||
*/ |
||||
inline constexpr operator GLint() const { return internalFormat; } |
||||
|
||||
private: |
||||
GLint internalFormat; |
||||
}; |
||||
|
||||
/*@}*/ |
||||
|
||||
inline BufferedTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {} |
||||
|
||||
/** @copydoc AbstractTexture::bind() */ |
||||
inline void bind(GLint layer) { AbstractTexture::bind(layer); } |
||||
|
||||
/**
|
||||
* @brief Set texture buffer |
||||
* @param internalFormat Internal format |
||||
* @param buffer %Buffer with data |
||||
* |
||||
* Binds given buffer to this texture. The buffer itself can be then |
||||
* filled with data of proper format at any time using Buffer own data |
||||
* setting functions. |
||||
* @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexBuffer} |
||||
* or @fn_gl_extension{TextureBuffer,EXT,direct_state_access} |
||||
*/ |
||||
inline void setBuffer(InternalFormat internalFormat, Buffer* buffer) { |
||||
(this->*setBufferImplementation)(internalFormat, buffer); |
||||
} |
||||
|
||||
private: |
||||
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); |
||||
|
||||
typedef void(BufferedTexture::*SetBufferImplementation)(InternalFormat, Buffer*); |
||||
void MAGNUM_LOCAL setBufferImplementationDefault(InternalFormat internalFormat, Buffer* buffer); |
||||
void MAGNUM_LOCAL setBufferImplementationDSA(InternalFormat internalFormat, Buffer* buffer); |
||||
static SetBufferImplementation setBufferImplementation; |
||||
}; |
||||
|
||||
/** @relates BufferedTexture
|
||||
@brief Convertor of component count and data type to InternalFormat |
||||
*/ |
||||
inline BufferedTexture::InternalFormat operator|(BufferedTexture::Components components, BufferedTexture::ComponentType type) { |
||||
return BufferedTexture::InternalFormat(components, type); |
||||
} |
||||
/** @relates BufferedTexture
|
||||
* @overload |
||||
*/ |
||||
inline BufferedTexture::InternalFormat operator|(BufferedTexture::ComponentType type, BufferedTexture::Components components) { |
||||
return BufferedTexture::InternalFormat(components, type); |
||||
} |
||||
|
||||
} |
||||
#endif |
||||
|
||||
#endif |
||||
@ -0,0 +1,62 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
set(MagnumDebugTools_SRCS |
||||
ForceRenderer.cpp |
||||
ObjectRenderer.cpp |
||||
Profiler.cpp |
||||
ResourceManager.cpp |
||||
ShapeRenderer.cpp |
||||
|
||||
Implementation/AbstractBoxRenderer.cpp |
||||
Implementation/AbstractShapeRenderer.cpp |
||||
Implementation/AxisAlignedBoxRenderer.cpp |
||||
Implementation/BoxRenderer.cpp |
||||
Implementation/PointRenderer.cpp) |
||||
|
||||
set(MagnumDebugTools_HEADERS |
||||
ForceRenderer.h |
||||
DebugTools.h |
||||
ObjectRenderer.h |
||||
Profiler.h |
||||
ResourceManager.h |
||||
ShapeRenderer.h |
||||
|
||||
magnumDebugToolsVisibility.h) |
||||
|
||||
add_library(MagnumDebugTools SHARED ${MagnumDebugTools_SRCS}) |
||||
target_link_libraries(MagnumDebugTools |
||||
Magnum |
||||
MagnumMeshTools |
||||
MagnumPhysics |
||||
MagnumPrimitives |
||||
MagnumSceneGraph |
||||
MagnumShaders) |
||||
|
||||
install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) |
||||
install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) |
||||
|
||||
if(BUILD_TESTS) |
||||
add_subdirectory(Test) |
||||
endif() |
||||
@ -0,0 +1,58 @@
|
||||
#ifndef Magnum_DebugTools_DebugTools_h |
||||
#define Magnum_DebugTools_DebugTools_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Forward declarations for Magnum::DebugTools namespace |
||||
*/ |
||||
|
||||
#include "Types.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
/** @todoc Remove `ifndef` when Doxygen is sane again */ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
template<UnsignedInt> class ForceRenderer; |
||||
typedef ForceRenderer<2> ForceRenderer2D; |
||||
typedef ForceRenderer<3> ForceRenderer3D; |
||||
class ForceRendererOptions; |
||||
|
||||
template<UnsignedInt> class ObjectRenderer; |
||||
typedef ObjectRenderer<2> ObjectRenderer2D; |
||||
typedef ObjectRenderer<3> ObjectRenderer3D; |
||||
class ObjectRendererOptions; |
||||
|
||||
class Profiler; |
||||
class ResourceManager; |
||||
|
||||
template<UnsignedInt> class ShapeRenderer; |
||||
typedef ShapeRenderer<2> ShapeRenderer2D; |
||||
typedef ShapeRenderer<3> ShapeRenderer3D; |
||||
class ShapeRendererOptions; |
||||
#endif |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "ForceRenderer.h" |
||||
|
||||
#include "Buffer.h" |
||||
#include "Mesh.h" |
||||
#include "DebugTools/ResourceManager.h" |
||||
#include "SceneGraph/AbstractCamera.h" |
||||
#include "Shaders/FlatShader.h" |
||||
|
||||
#include "DebugTools/Implementation/ForceRendererTransformation.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
namespace { |
||||
|
||||
template<UnsignedInt dimensions> ResourceKey shaderKey(); |
||||
template<> inline ResourceKey shaderKey<2>() { return ResourceKey("FlatShader2D"); } |
||||
template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D"); } |
||||
|
||||
constexpr std::array<Vector2, 4> positions{{ |
||||
{0.0f, 0.0f}, |
||||
{1.0f, 0.0f}, |
||||
{0.9f, 0.1f}, |
||||
{0.9f, -0.1f} |
||||
}}; |
||||
|
||||
constexpr std::array<UnsignedByte, 6> indices{{ |
||||
0, 1, |
||||
1, 2, |
||||
1, 3 |
||||
}}; |
||||
|
||||
} |
||||
|
||||
template<UnsignedInt dimensions> ForceRenderer<dimensions>::ForceRenderer(SceneGraph::AbstractObject<dimensions>* object, const typename DimensionTraits<dimensions, Float>::VectorType& forcePosition, const typename DimensionTraits<dimensions, Float>::VectorType* force, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(object, drawables), forcePosition(forcePosition), force(force), options(ResourceManager::instance()->get<ForceRendererOptions>(options)) { |
||||
/* Shader */ |
||||
shader = ResourceManager::instance()->get<AbstractShaderProgram, Shaders::FlatShader<dimensions>>(shaderKey<dimensions>()); |
||||
if(!shader) ResourceManager::instance()->set<AbstractShaderProgram>(shader.key(), new Shaders::FlatShader<dimensions>); |
||||
|
||||
/* Mesh and vertex buffer */ |
||||
mesh = ResourceManager::instance()->get<Mesh>("force"); |
||||
vertexBuffer = ResourceManager::instance()->get<Buffer>("force-vertices"); |
||||
indexBuffer = ResourceManager::instance()->get<Buffer>("force-indices"); |
||||
if(mesh) return; |
||||
|
||||
/* Create the mesh */ |
||||
Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); |
||||
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); |
||||
|
||||
vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); |
||||
ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
indexBuffer->setData(indices, Buffer::Usage::StaticDraw); |
||||
ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
Mesh* mesh = new Mesh; |
||||
mesh->setPrimitive(Mesh::Primitive::Lines) |
||||
->setIndexCount(indices.size()) |
||||
->addVertexBuffer(vertexBuffer, 0, |
||||
typename Shaders::FlatShader<dimensions>::Position(Shaders::FlatShader<dimensions>::Position::Components::Two)) |
||||
->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size()); |
||||
ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> void ForceRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions>* camera) { |
||||
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation<dimensions>(transformationMatrix.translation()+forcePosition, *force)*DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->scale()))) |
||||
->setColor(options->color()) |
||||
->use(); |
||||
mesh->draw(); |
||||
} |
||||
|
||||
template class ForceRenderer<2>; |
||||
template class ForceRenderer<3>; |
||||
|
||||
}} |
||||
@ -0,0 +1,145 @@
|
||||
#ifndef Magnum_DebugTools_ForceRenderer_h |
||||
#define Magnum_DebugTools_ForceRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::DebugTools::ForceRenderer, Magnum::DebugTools::ForceRendererOptions, typedef Magnum::DebugTools::ForceRenderer2D, Magnum::DebugTools::ForceRenderer3D |
||||
*/ |
||||
|
||||
#include "Color.h" |
||||
#include "Resource.h" |
||||
#include "SceneGraph/Drawable.h" |
||||
#include "Shaders/Shaders.h" |
||||
|
||||
#include "magnumDebugToolsVisibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
/**
|
||||
@brief Force renderer options |
||||
|
||||
See ForceRenderer documentation for more information. |
||||
*/ |
||||
class ForceRendererOptions { |
||||
public: |
||||
inline constexpr ForceRendererOptions(): _size(1.0f) {} |
||||
|
||||
/** @brief Color of rendered arrow */ |
||||
inline constexpr Color3<> color() const { return _color; } |
||||
|
||||
/**
|
||||
* @brief Set color of rendered arrow |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* Default is black. |
||||
*/ |
||||
inline ForceRendererOptions* setColor(const Color3<>& color) { |
||||
_color = color; |
||||
return this; |
||||
} |
||||
|
||||
/** @brief Scale of rendered arrow */ |
||||
inline constexpr Float scale() const { return _size; } |
||||
|
||||
/**
|
||||
* @brief Set scale of rendered arrow |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* Default is `1.0f`. |
||||
*/ |
||||
inline ForceRendererOptions* setSize(Float size) { |
||||
_size = size; |
||||
return this; |
||||
} |
||||
|
||||
private: |
||||
Color3<> _color; |
||||
Float _size; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Force renderer |
||||
|
||||
Visualizes force pushing on object by an arrow of the same direction and size. |
||||
See @ref debug-tools-renderers for more information. |
||||
|
||||
@section ForceRenderer-usage Basic usage |
||||
|
||||
Example code: |
||||
@code |
||||
// Create some options
|
||||
DebugTools::ResourceManager::instance()->set("my", (new DebugTools::ForceRendererOptions() |
||||
->setScale(5.0f) |
||||
->setColor(Color3<>::fromHSV(120.0_degf, 1.0f, 0.7f))); |
||||
|
||||
// Create debug renderer for given object, use "my" options for it
|
||||
Object3D* object; |
||||
Vector3 force; |
||||
new DebugTools::ForceRenderer2D(object, {0.3f, 1.5f, -0.7f}, &force, "my", debugDrawables); |
||||
@endcode |
||||
|
||||
@see ForceRenderer2D, ForceRenderer3D |
||||
*/ |
||||
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ForceRenderer: public SceneGraph::Drawable<dimensions> { |
||||
public: |
||||
/**
|
||||
* @brief Constructor |
||||
* @param object Object for which to create debug renderer |
||||
* @param forcePosition Where to render the force, relative to object |
||||
* @param force Force vector |
||||
* @param options Options resource key. See |
||||
* @ref ForceRenderer-usage "class documentation" for more |
||||
* information. |
||||
* @param drawables Drawable group |
||||
* |
||||
* The renderer is automatically added to object's features, @p force is |
||||
* saved as reference to original vector and thus it must be available |
||||
* for the whole lifetime of the renderer. |
||||
*/ |
||||
explicit ForceRenderer(SceneGraph::AbstractObject<dimensions>* object, const typename DimensionTraits<dimensions, Float>::VectorType& forcePosition, const typename DimensionTraits<dimensions, Float>::VectorType* force, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr); |
||||
|
||||
protected: |
||||
/** @todoc Remove Float when Doxygen properly treats this as override */ |
||||
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, Float>* camera) override; |
||||
|
||||
private: |
||||
const typename DimensionTraits<dimensions, Float>::VectorType forcePosition; |
||||
const typename DimensionTraits<dimensions, Float>::VectorType* const force; |
||||
|
||||
Resource<ForceRendererOptions> options; |
||||
Resource<AbstractShaderProgram, Shaders::FlatShader<dimensions>> shader; |
||||
Resource<Mesh> mesh; |
||||
Resource<Buffer> vertexBuffer, indexBuffer; |
||||
}; |
||||
|
||||
/** @brief Two-dimensional force renderer */ |
||||
typedef ForceRenderer<2> ForceRenderer2D; |
||||
|
||||
/** @brief Three-dimensional force renderer */ |
||||
typedef ForceRenderer<3> ForceRenderer3D; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractBoxRenderer.h" |
||||
|
||||
#include "Primitives/Cube.h" |
||||
#include "Primitives/Square.h" |
||||
#include "Trade/MeshData2D.h" |
||||
#include "Trade/MeshData3D.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
AbstractBoxRenderer<2>::AbstractBoxRenderer(): AbstractShapeRenderer<2>("box2d", "box2d-vertices", {}) { |
||||
if(!mesh) this->createResources(Primitives::Square::wireframe()); |
||||
} |
||||
|
||||
AbstractBoxRenderer<3>::AbstractBoxRenderer(): AbstractShapeRenderer<3>("box3d", "box3d-vertices", "box3d-indices") { |
||||
if(!mesh) this->createResources(Primitives::Cube::wireframe()); |
||||
} |
||||
|
||||
template class AbstractBoxRenderer<2>; |
||||
template class AbstractBoxRenderer<3>; |
||||
|
||||
}}} |
||||
@ -0,0 +1,50 @@
|
||||
#ifndef Magnum_DebugTools_Implementation_AbstractBoxRenderer_h |
||||
#define Magnum_DebugTools_Implementation_AbstractBoxRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractShapeRenderer.h" |
||||
|
||||
#include "Resource.h" |
||||
#include "Shaders/Shaders.h" |
||||
|
||||
#include "corradeCompatibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> class AbstractBoxRenderer; |
||||
|
||||
template<> class AbstractBoxRenderer<2>: public AbstractShapeRenderer<2> { |
||||
public: |
||||
AbstractBoxRenderer(); |
||||
}; |
||||
|
||||
template<> class AbstractBoxRenderer<3>: public AbstractShapeRenderer<3> { |
||||
public: |
||||
AbstractBoxRenderer(); |
||||
}; |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,111 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractShapeRenderer.h" |
||||
|
||||
#include "AbstractShaderProgram.h" |
||||
#include "Buffer.h" |
||||
#include "Mesh.h" |
||||
#include "DebugTools/ResourceManager.h" |
||||
#include "MeshTools/CompressIndices.h" |
||||
#include "Shaders/FlatShader.h" |
||||
#include "Trade/MeshData2D.h" |
||||
#include "Trade/MeshData3D.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
namespace { |
||||
|
||||
template<UnsignedInt dimensions> ResourceKey shaderKey(); |
||||
template<> inline ResourceKey shaderKey<2>() { return ResourceKey("FlatShader2D"); } |
||||
template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D"); } |
||||
|
||||
template<UnsignedInt dimensions> void create(typename MeshData<dimensions>::Type&, Resource<Mesh>&, Resource<Buffer>&, Resource<Buffer>&); |
||||
|
||||
template<> void create<2>(Trade::MeshData2D& data, Resource<Mesh>& meshResource, Resource<Buffer>& vertexBufferResource, Resource<Buffer>& indexBufferResource) { |
||||
/* Vertex buffer */ |
||||
Buffer* buffer = new Buffer(Buffer::Target::Array); |
||||
buffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); |
||||
ResourceManager::instance()->set(vertexBufferResource.key(), buffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
/* Mesh configuration */ |
||||
Mesh* mesh = new Mesh; |
||||
mesh->setPrimitive(data.primitive()) |
||||
->setVertexCount(data.positions(0)->size()) |
||||
->addVertexBuffer(buffer, 0, Shaders::FlatShader2D::Position()); |
||||
ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
/* Index buffer, if needed, if not, resource key doesn't have to be set */ |
||||
if(data.indices()) { |
||||
CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey()); |
||||
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); |
||||
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices()); |
||||
ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
} |
||||
} |
||||
|
||||
template<> void create<3>(Trade::MeshData3D& data, Resource<Mesh>& meshResource, Resource<Buffer>& vertexBufferResource, Resource<Buffer>& indexBufferResource) { |
||||
/* Vertex buffer */ |
||||
Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); |
||||
vertexBuffer->setData(*data.positions(0), Buffer::Usage::StaticDraw); |
||||
ResourceManager::instance()->set(vertexBufferResource.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
/* Mesh configuration */ |
||||
Mesh* mesh = new Mesh; |
||||
mesh->setPrimitive(data.primitive()) |
||||
->setVertexCount(data.positions(0)->size()) |
||||
->addVertexBuffer(vertexBuffer, 0, Shaders::FlatShader3D::Position()); |
||||
ResourceManager::instance()->set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
/* Index buffer, if needed, if not, resource key doesn't have to be set */ |
||||
if(data.indices()) { |
||||
CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey()); |
||||
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); |
||||
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *data.indices()); |
||||
ResourceManager::instance()->set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
template<UnsignedInt dimensions> AbstractShapeRenderer<dimensions>::AbstractShapeRenderer(ResourceKey meshKey, ResourceKey vertexBufferKey, ResourceKey indexBufferKey) { |
||||
shader = ResourceManager::instance()->get<AbstractShaderProgram, Shaders::FlatShader<dimensions>>(shaderKey<dimensions>()); |
||||
mesh = ResourceManager::instance()->get<Mesh>(meshKey); |
||||
vertexBuffer = ResourceManager::instance()->get<Buffer>(vertexBufferKey); |
||||
indexBuffer = ResourceManager::instance()->get<Buffer>(indexBufferKey); |
||||
|
||||
if(!shader) ResourceManager::instance()->set<AbstractShaderProgram>(shaderKey<dimensions>(), |
||||
new Shaders::FlatShader<dimensions>, ResourceDataState::Final, ResourcePolicy::Resident); |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> AbstractShapeRenderer<dimensions>::~AbstractShapeRenderer() {} |
||||
|
||||
template<UnsignedInt dimensions> void AbstractShapeRenderer<dimensions>::createResources(typename MeshData<dimensions>::Type data) { |
||||
create<dimensions>(data, this->mesh, this->vertexBuffer, this->indexBuffer); |
||||
} |
||||
|
||||
template class AbstractShapeRenderer<2>; |
||||
template class AbstractShapeRenderer<3>; |
||||
|
||||
}}} |
||||
@ -0,0 +1,61 @@
|
||||
#ifndef Magnum_DebugTools_Implementation_AbstractShapeRenderer_h |
||||
#define Magnum_DebugTools_Implementation_AbstractShapeRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "DimensionTraits.h" |
||||
#include "Resource.h" |
||||
#include "DebugTools/DebugTools.h" |
||||
#include "SceneGraph/SceneGraph.h" |
||||
#include "Shaders/Shaders.h" |
||||
#include "Trade/Trade.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> struct MeshData; |
||||
|
||||
template<> struct MeshData<2> { typedef Trade::MeshData2D Type; }; |
||||
template<> struct MeshData<3> { typedef Trade::MeshData3D Type; }; |
||||
|
||||
template<UnsignedInt dimensions> class AbstractShapeRenderer { |
||||
public: |
||||
AbstractShapeRenderer(ResourceKey mesh, ResourceKey vertexBuffer, ResourceKey indexBuffer); |
||||
virtual ~AbstractShapeRenderer(); |
||||
|
||||
virtual void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) = 0; |
||||
|
||||
protected: |
||||
/* Call only if the mesh resource isn't already present */ |
||||
void createResources(typename MeshData<dimensions>::Type data); |
||||
|
||||
Resource<AbstractShaderProgram, Shaders::FlatShader<dimensions>> shader; |
||||
Resource<Mesh> mesh; |
||||
|
||||
private: |
||||
Resource<Buffer> indexBuffer, vertexBuffer; |
||||
}; |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AxisAlignedBoxRenderer.h" |
||||
|
||||
#include "Mesh.h" |
||||
#include "DebugTools/ShapeRenderer.h" |
||||
#include "Physics/AxisAlignedBox.h" |
||||
#include "Shaders/FlatShader.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> AxisAlignedBoxRenderer<dimensions>::AxisAlignedBoxRenderer(Physics::AxisAlignedBox<dimensions>& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} |
||||
|
||||
template<UnsignedInt dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) { |
||||
/* Half scale, because the box is 2x2(x2) */ |
||||
typename DimensionTraits<dimensions>::MatrixType transformation = |
||||
DimensionTraits<dimensions>::MatrixType::translation((axisAlignedBox.transformedMin()+axisAlignedBox.transformedMax())/2)* |
||||
DimensionTraits<dimensions>::MatrixType::scaling((axisAlignedBox.transformedMax()-axisAlignedBox.transformedMin())/2); |
||||
this->shader->setTransformationProjectionMatrix(projectionMatrix*transformation) |
||||
->setColor(options->color()) |
||||
->use(); |
||||
this->mesh->draw(); |
||||
} |
||||
|
||||
template class AxisAlignedBoxRenderer<2>; |
||||
template class AxisAlignedBoxRenderer<3>; |
||||
|
||||
}}} |
||||
@ -0,0 +1,47 @@
|
||||
#ifndef Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h |
||||
#define Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractBoxRenderer.h" |
||||
|
||||
#include "Physics/Physics.h" |
||||
|
||||
#include "corradeCompatibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> class AxisAlignedBoxRenderer: public AbstractBoxRenderer<dimensions> { |
||||
public: |
||||
AxisAlignedBoxRenderer(Physics::AxisAlignedBox<dimensions>& axisAlignedBox); |
||||
|
||||
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; |
||||
|
||||
private: |
||||
Physics::AxisAlignedBox<dimensions>& axisAlignedBox; |
||||
}; |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,48 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "BoxRenderer.h" |
||||
|
||||
#include "Mesh.h" |
||||
#include "DebugTools/ShapeRenderer.h" |
||||
#include "Physics/Box.h" |
||||
#include "Shaders/FlatShader.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> BoxRenderer<dimensions>::BoxRenderer(Physics::Box<dimensions>& box): box(box) {} |
||||
|
||||
template<UnsignedInt dimensions> void BoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) { |
||||
/* Half scale, because the box is 2x2(x2) */ |
||||
this->shader->setTransformationProjectionMatrix(projectionMatrix*box.transformedTransformation()* |
||||
DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(0.5f))) |
||||
->setColor(options->color()) |
||||
->use(); |
||||
this->mesh->draw(); |
||||
} |
||||
|
||||
template class BoxRenderer<2>; |
||||
template class BoxRenderer<3>; |
||||
|
||||
}}} |
||||
@ -0,0 +1,47 @@
|
||||
#ifndef Magnum_DebugTools_Implementation_BoxRenderer_h |
||||
#define Magnum_DebugTools_Implementation_BoxRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractBoxRenderer.h" |
||||
|
||||
#include "Physics/Physics.h" |
||||
|
||||
#include "corradeCompatibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> class BoxRenderer: public AbstractBoxRenderer<dimensions> { |
||||
public: |
||||
BoxRenderer(Physics::Box<dimensions>& box); |
||||
|
||||
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; |
||||
|
||||
private: |
||||
Physics::Box<dimensions>& box; |
||||
}; |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,70 @@
|
||||
#ifndef Magnum_DebugTools_Implementation_ForceRendererTransformation_h |
||||
#define Magnum_DebugTools_Implementation_ForceRendererTransformation_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Math/Matrix3.h" |
||||
#include "Math/Matrix4.h" |
||||
#include "Magnum.h" |
||||
#include "DimensionTraits.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> typename DimensionTraits<dimensions>::MatrixType forceRendererTransformation(const typename DimensionTraits<dimensions>::VectorType& forcePosition, const typename DimensionTraits<dimensions>::VectorType& force); |
||||
|
||||
template<> inline Matrix3 forceRendererTransformation<2>(const Vector2& forcePosition, const Vector2& force) { |
||||
return Matrix3::from({force, Vector2(-force.y(), force.x())}, forcePosition); |
||||
} |
||||
|
||||
template<> inline Matrix4 forceRendererTransformation<3>(const Vector3& forcePosition, const Vector3& force) { |
||||
const Matrix4 translation = Matrix4::translation(forcePosition); |
||||
const Float forceLength = force.length(); |
||||
|
||||
/* Zero length, zero scaling */ |
||||
if(forceLength < Math::TypeTraits<Float>::epsilon()) |
||||
return translation*Matrix4::scaling(Vector3(0.0f)); |
||||
|
||||
const Float dot = Vector3::dot(force/forceLength, Vector3::xAxis()); |
||||
|
||||
/* Force is parallel to X axis, just scaling */ |
||||
if(dot > 1.0f - Math::TypeTraits<Float>::epsilon()) |
||||
return translation*Matrix4::scaling(Vector3(forceLength)); |
||||
|
||||
/* Force is antiparallel to X axis, scaling inverted on X */ |
||||
if(-dot > 1.0f - Math::TypeTraits<Float>::epsilon()) |
||||
return translation*Matrix4::scaling({-forceLength, forceLength, forceLength}); |
||||
|
||||
/* Normal of plane going through force vector and X axis vector */ |
||||
const Vector3 normal = Vector3::cross(Vector3::xAxis(), force).normalized(); |
||||
|
||||
/* Third base vector, orthogonal to force and normal */ |
||||
const Vector3 binormal = Vector3::cross(normal, force).normalized(); |
||||
|
||||
/* Transformation matrix from scaled base vectors and translation vector */ |
||||
return Matrix4::from({force, normal*forceLength, binormal*forceLength}, forcePosition); |
||||
} |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,68 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "PointRenderer.h" |
||||
|
||||
#include "Mesh.h" |
||||
#include "DebugTools/ShapeRenderer.h" |
||||
#include "Physics/Point.h" |
||||
#include "Primitives/Crosshair.h" |
||||
#include "Shaders/FlatShader.h" |
||||
#include "Trade/MeshData2D.h" |
||||
#include "Trade/MeshData3D.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
namespace { |
||||
template<UnsignedInt dimensions> ResourceKey meshKey(); |
||||
template<> inline ResourceKey meshKey<2>() { return ResourceKey("point2d"); } |
||||
template<> inline ResourceKey meshKey<3>() { return ResourceKey("point3d"); } |
||||
|
||||
template<UnsignedInt dimensions> ResourceKey vertexBufferKey(); |
||||
template<> inline ResourceKey vertexBufferKey<2>() { return ResourceKey("point2d-vertices"); } |
||||
template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("point3d-vertices"); } |
||||
|
||||
template<UnsignedInt dimensions> typename MeshData<dimensions>::Type meshData(); |
||||
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::Crosshair2D::wireframe(); } |
||||
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); } |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> PointRenderer<dimensions>::PointRenderer(Physics::Point<dimensions>& point): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), point(point) { |
||||
if(!this->mesh) this->createResources(meshData<dimensions>()); |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> void PointRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) { |
||||
/* Half scale, because the point is 2x2(x2) */ |
||||
this->shader->setTransformationProjectionMatrix(projectionMatrix* |
||||
DimensionTraits<dimensions>::MatrixType::translation(point.transformedPosition())* |
||||
DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->pointSize()/2))) |
||||
->setColor(options->color()) |
||||
->use(); |
||||
this->mesh->draw(); |
||||
} |
||||
|
||||
template class PointRenderer<2>; |
||||
template class PointRenderer<3>; |
||||
|
||||
}}} |
||||
@ -0,0 +1,47 @@
|
||||
#ifndef Magnum_DebugTools_Implementation_PointRenderer_h |
||||
#define Magnum_DebugTools_Implementation_PointRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "AbstractShapeRenderer.h" |
||||
|
||||
#include "Physics/Physics.h" |
||||
|
||||
#include "corradeCompatibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
||||
|
||||
template<UnsignedInt dimensions> class PointRenderer: public AbstractShapeRenderer<dimensions> { |
||||
public: |
||||
PointRenderer(Physics::Point<dimensions>& point); |
||||
|
||||
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; |
||||
|
||||
private: |
||||
Physics::Point<dimensions>& point; |
||||
}; |
||||
|
||||
}}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,186 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "ObjectRenderer.h" |
||||
|
||||
#include "Buffer.h" |
||||
#include "DebugTools/ResourceManager.h" |
||||
#include "MeshTools/Interleave.h" |
||||
#include "SceneGraph/AbstractCamera.h" |
||||
#include "Shaders/VertexColorShader.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
namespace { |
||||
|
||||
template<UnsignedInt> struct Renderer; |
||||
|
||||
template<> struct Renderer<2> { |
||||
inline static ResourceKey shader() { return {"VertexColorShader2D"}; } |
||||
inline static ResourceKey vertexBuffer() { return {"object2d-vertices"}; } |
||||
inline static ResourceKey indexBuffer() { return {"object2d-indices"}; } |
||||
inline static ResourceKey mesh() { return {"object2d"}; } |
||||
|
||||
static const std::array<Vector2, 8> positions; |
||||
static const std::array<Color3<>, 8> colors; |
||||
static const std::array<UnsignedByte, 12> indices; |
||||
}; |
||||
|
||||
const std::array<Vector2, 8> Renderer<2>::positions{{ |
||||
{ 0.0f, 0.0f}, |
||||
{ 1.0f, 0.0f}, /* X axis */ |
||||
{ 0.9f, 0.1f}, |
||||
{ 0.9f, -0.1f}, |
||||
|
||||
{ 0.0f, 0.0f}, |
||||
{ 0.0f, 1.0f}, /* Y axis */ |
||||
{ 0.1f, 0.9f}, |
||||
{-0.1f, 0.9f} |
||||
}}; |
||||
|
||||
const std::array<Color3<>, 8> Renderer<2>::colors{{ |
||||
{1.0f, 0.0f, 0.0f}, |
||||
{1.0f, 0.0f, 0.0f}, /* X axis */ |
||||
{1.0f, 0.0f, 0.0f}, |
||||
{1.0f, 0.0f, 0.0f}, |
||||
|
||||
{0.0f, 1.0f, 0.0f}, |
||||
{0.0f, 1.0f, 0.0f}, /* Y axis */ |
||||
{0.0f, 1.0f, 0.0f}, |
||||
{0.0f, 1.0f, 0.0f}, |
||||
}}; |
||||
|
||||
const std::array<UnsignedByte, 12> Renderer<2>::indices{{ |
||||
0, 1, |
||||
1, 2, /* X axis */ |
||||
1, 3, |
||||
|
||||
4, 5, |
||||
5, 6, /* Y axis */ |
||||
5, 7 |
||||
}}; |
||||
|
||||
template<> struct Renderer<3> { |
||||
inline static ResourceKey shader() { return {"VertexColorShader3D"}; } |
||||
inline static ResourceKey vertexBuffer() { return {"object3d-vertices"}; } |
||||
inline static ResourceKey indexBuffer() { return {"object3d-indices"}; } |
||||
inline static ResourceKey mesh() { return {"object3d"}; } |
||||
|
||||
static const std::array<Vector3, 12> positions; |
||||
static const std::array<Color3<>, 12> colors; |
||||
static const std::array<uint8_t, 18> indices; |
||||
}; |
||||
|
||||
const std::array<Vector3, 12> Renderer<3>::positions{{ |
||||
{ 0.0f, 0.0f, 0.0f}, |
||||
{ 1.0f, 0.0f, 0.0f}, /* X axis */ |
||||
{ 0.9f, 0.1f, 0.0f}, |
||||
{ 0.9f, -0.1f, 0.0f}, |
||||
|
||||
{ 0.0f, 0.0f, 0.0f}, |
||||
{ 0.0f, 1.0f, 0.0f}, /* Y axis */ |
||||
{ 0.1f, 0.9f, 0.0f}, |
||||
{-0.1f, 0.9f, 0.0f}, |
||||
|
||||
{ 0.0f, 0.0f, 0.0f}, |
||||
{ 0.0f, 0.0f, 1.0f}, /* Z axis */ |
||||
{ 0.1f, 0.0f, 0.9f}, |
||||
{-0.1f, 0.0f, 0.9f} |
||||
}}; |
||||
|
||||
const std::array<Color3<>, 12> Renderer<3>::colors{{ |
||||
{1.0f, 0.0f, 0.0f}, |
||||
{1.0f, 0.0f, 0.0f}, /* X axis */ |
||||
{1.0f, 0.0f, 0.0f}, |
||||
{1.0f, 0.0f, 0.0f}, |
||||
|
||||
{0.0f, 1.0f, 0.0f}, |
||||
{0.0f, 1.0f, 0.0f}, /* Y axis */ |
||||
{0.0f, 1.0f, 0.0f}, |
||||
{0.0f, 1.0f, 0.0f}, |
||||
|
||||
{0.0f, 0.0f, 1.0f}, |
||||
{0.0f, 0.0f, 1.0f}, /* Z axis */ |
||||
{0.0f, 0.0f, 1.0f}, |
||||
{0.0f, 0.0f, 1.0f} |
||||
}}; |
||||
|
||||
const std::array<UnsignedByte, 18> Renderer<3>::indices{{ |
||||
0, 1, |
||||
1, 2, /* X axis */ |
||||
1, 3, |
||||
|
||||
4, 5, |
||||
5, 6, /* Y axis */ |
||||
5, 7, |
||||
|
||||
8, 9, |
||||
9, 10, /* Z axis */ |
||||
9, 11 |
||||
}}; |
||||
|
||||
} |
||||
|
||||
template<UnsignedInt dimensions> ObjectRenderer<dimensions>::ObjectRenderer(SceneGraph::AbstractObject<dimensions>* object, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(object, drawables), options(ResourceManager::instance()->get<ObjectRendererOptions>(options)) { |
||||
/* Shader */ |
||||
shader = ResourceManager::instance()->get<AbstractShaderProgram, Shaders::VertexColorShader<dimensions>>(Renderer<dimensions>::shader()); |
||||
if(!shader) ResourceManager::instance()->set<AbstractShaderProgram>(shader.key(), new Shaders::VertexColorShader<dimensions>); |
||||
|
||||
/* Mesh and vertex buffer */ |
||||
mesh = ResourceManager::instance()->get<Mesh>(Renderer<dimensions>::mesh()); |
||||
vertexBuffer = ResourceManager::instance()->get<Buffer>(Renderer<dimensions>::vertexBuffer()); |
||||
indexBuffer = ResourceManager::instance()->get<Buffer>(Renderer<dimensions>::indexBuffer()); |
||||
if(mesh) return; |
||||
|
||||
/* Create the mesh */ |
||||
Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); |
||||
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); |
||||
Mesh* mesh = new Mesh; |
||||
|
||||
MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, Renderer<dimensions>::positions, Renderer<dimensions>::colors); |
||||
ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
indexBuffer->setData(Renderer<dimensions>::indices, Buffer::Usage::StaticDraw); |
||||
ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
|
||||
mesh->setPrimitive(Mesh::Primitive::Lines) |
||||
->setIndexCount(Renderer<dimensions>::indices.size()) |
||||
->addInterleavedVertexBuffer(vertexBuffer, 0, |
||||
typename Shaders::VertexColorShader<dimensions>::Position(), |
||||
typename Shaders::VertexColorShader<dimensions>::Color()) |
||||
->setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, Renderer<dimensions>::positions.size()); |
||||
ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> void ObjectRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions>* camera) { |
||||
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->size()))) |
||||
->use(); |
||||
|
||||
mesh->draw(); |
||||
} |
||||
|
||||
template class ObjectRenderer<2>; |
||||
template class ObjectRenderer<3>; |
||||
|
||||
}} |
||||
@ -0,0 +1,120 @@
|
||||
#ifndef Magnum_DebugTools_ObjectRenderer_h |
||||
#define Magnum_DebugTools_ObjectRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::DebugTools::ObjectRenderer, Magnum::DebugTools::ObjectRendererOptions, typedef Magnum::DebugTools::ObjectRenderer2D, Magnum::DebugTools::ObjectRenderer3D |
||||
*/ |
||||
|
||||
#include "Resource.h" |
||||
#include "SceneGraph/Drawable.h" |
||||
#include "Shaders/Shaders.h" |
||||
|
||||
#include "magnumDebugToolsVisibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
/**
|
||||
@brief Object renderer options |
||||
|
||||
See ObjectRenderer documentation for more information. |
||||
*/ |
||||
class ObjectRendererOptions { |
||||
public: |
||||
inline constexpr ObjectRendererOptions(): _size(1.0f) {} |
||||
|
||||
/** @brief Size of the rendered axes */ |
||||
inline constexpr Float size() const { return _size; } |
||||
|
||||
/**
|
||||
* @brief Set size of the rendered axes |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* Default is `1.0f`. |
||||
*/ |
||||
inline ObjectRendererOptions* setSize(Float size) { |
||||
_size = size; |
||||
return this; |
||||
} |
||||
|
||||
private: |
||||
Float _size; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Object renderer |
||||
|
||||
Visualizes object position, rotation and scale using colored axes. See |
||||
@ref debug-tools-renderers for more information. |
||||
|
||||
@section ObjectRenderer-usage Basic usage |
||||
|
||||
Example code: |
||||
@code |
||||
// Create some options
|
||||
DebugTools::ResourceManager::instance()->set("my", |
||||
(new DebugTools::ObjectRendererOptions())->setSize(0.3f)); |
||||
|
||||
// Create debug renderer for given object, use "my" options for it
|
||||
Object3D* object; |
||||
new DebugTools::ObjectRenderer2D(object, "my", debugDrawables); |
||||
@endcode |
||||
|
||||
@see ObjectRenderer2D, ObjectRenderer3D |
||||
*/ |
||||
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer: public SceneGraph::Drawable<dimensions> { |
||||
public: |
||||
/**
|
||||
* @brief Constructor |
||||
* @param object Object for which to create debug renderer |
||||
* @param options Options resource key. See |
||||
* @ref ObjectRenderer-usage "class documentation" for more |
||||
* information. |
||||
* @param drawables Drawable group |
||||
* |
||||
* The renderer is automatically added to object's features. |
||||
*/ |
||||
explicit ObjectRenderer(SceneGraph::AbstractObject<dimensions>* object, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr); |
||||
|
||||
protected: |
||||
/** @todoc Remove Float when Doxygen properly treats this as override */ |
||||
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, Float>* camera) override; |
||||
|
||||
private: |
||||
Resource<ObjectRendererOptions> options; |
||||
Resource<AbstractShaderProgram, Shaders::VertexColorShader<dimensions>> shader; |
||||
Resource<Mesh> mesh; |
||||
Resource<Buffer> vertexBuffer, indexBuffer; |
||||
}; |
||||
|
||||
/** @brief Two-dimensional object renderer */ |
||||
typedef ObjectRenderer<2> ObjectRenderer2D; |
||||
|
||||
/** @brief Three-dimensional object renderer */ |
||||
typedef ObjectRenderer<3> ObjectRenderer3D; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,131 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Profiler.h" |
||||
|
||||
#include <algorithm> |
||||
#include <numeric> |
||||
#include <Utility/Assert.h> |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
using namespace std::chrono; |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
Profiler::Section Profiler::addSection(const std::string& name) { |
||||
CORRADE_ASSERT(!enabled, "Profiler: cannot add section when profiling is enabled", 0); |
||||
sections.push_back(name); |
||||
return sections.size()-1; |
||||
} |
||||
|
||||
void Profiler::setMeasureDuration(std::size_t frames) { |
||||
CORRADE_ASSERT(!enabled, "Profiler: cannot set measure duration when profiling is enabled", ); |
||||
measureDuration = frames; |
||||
} |
||||
|
||||
void Profiler::enable() { |
||||
enabled = true; |
||||
frameData.assign(measureDuration*sections.size(), high_resolution_clock::duration::zero()); |
||||
totalData.assign(sections.size(), high_resolution_clock::duration::zero()); |
||||
frameCount = 0; |
||||
} |
||||
|
||||
void Profiler::disable() { |
||||
enabled = false; |
||||
} |
||||
|
||||
void Profiler::start(Section section) { |
||||
if(!enabled) return; |
||||
CORRADE_ASSERT(section < sections.size(), "Profiler: unknown section passed to start()", ); |
||||
|
||||
save(); |
||||
|
||||
currentSection = section; |
||||
} |
||||
|
||||
void Profiler::stop() { |
||||
if(!enabled) return; |
||||
|
||||
save(); |
||||
|
||||
previousTime = high_resolution_clock::time_point(); |
||||
} |
||||
|
||||
void Profiler::save() { |
||||
auto now = high_resolution_clock::now(); |
||||
|
||||
/* If the profiler is already running, add time to given section */ |
||||
if(previousTime != high_resolution_clock::time_point()) |
||||
frameData[currentFrame*sections.size()+currentSection] += now-previousTime; |
||||
|
||||
/* Set current time as previous for next section */ |
||||
previousTime = now; |
||||
} |
||||
|
||||
void Profiler::nextFrame() { |
||||
if(!enabled) return; |
||||
|
||||
/* Next frame index */ |
||||
std::size_t nextFrame = (currentFrame+1) % measureDuration; |
||||
|
||||
/* Add times of current frame to total */ |
||||
for(std::size_t i = 0; i != sections.size(); ++i) |
||||
totalData[i] += frameData[currentFrame*sections.size()+i]; |
||||
|
||||
/* Subtract times of next frame from total and erase them */ |
||||
for(std::size_t i = 0; i != sections.size(); ++i) { |
||||
totalData[i] -= frameData[nextFrame*sections.size()+i]; |
||||
frameData[nextFrame*sections.size()+i] = high_resolution_clock::duration::zero(); |
||||
} |
||||
|
||||
/* Advance to next frame */ |
||||
currentFrame = nextFrame; |
||||
|
||||
if(frameCount < measureDuration) ++frameCount; |
||||
} |
||||
|
||||
void Profiler::printStatistics() { |
||||
if(!enabled) return; |
||||
|
||||
std::vector<std::size_t> totalSorted(sections.size()); |
||||
std::iota(totalSorted.begin(), totalSorted.end(), 0); |
||||
|
||||
#ifndef CORRADE_GCC44_COMPATIBILITY |
||||
std::sort(totalSorted.begin(), totalSorted.end(), [this](std::size_t i, std::size_t j){return totalData[i] > totalData[j];}); |
||||
#else |
||||
std::sort(totalSorted.begin(), totalSorted.end(), Compare(this)); |
||||
#endif |
||||
|
||||
Debug() << "Statistics for last" << measureDuration << "frames:"; |
||||
for(std::size_t i = 0; i != sections.size(); ++i) |
||||
Debug() << " " << sections[totalSorted[i]] << duration_cast<microseconds>(totalData[totalSorted[i]]).count()/frameCount |
||||
#ifndef CORRADE_GCC44_COMPATIBILITY |
||||
<< u8"µs"; |
||||
#else |
||||
<< "µs"; |
||||
#endif |
||||
} |
||||
|
||||
}} |
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#define MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE |
||||
|
||||
#include "ResourceManager.h" |
||||
|
||||
#include "Buffer.h" |
||||
#include "Mesh.h" |
||||
#include "DebugTools/ForceRenderer.h" |
||||
#include "DebugTools/ObjectRenderer.h" |
||||
#include "DebugTools/ShapeRenderer.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
template class ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ForceRendererOptions, DebugTools::ObjectRendererOptions, DebugTools::ShapeRendererOptions>; |
||||
|
||||
namespace DebugTools { |
||||
|
||||
ResourceManager::ResourceManager() { |
||||
setFallback(new ForceRendererOptions); |
||||
setFallback(new ObjectRendererOptions); |
||||
setFallback(new ShapeRendererOptions); |
||||
} |
||||
|
||||
ResourceManager::~ResourceManager() {} |
||||
|
||||
}} |
||||
@ -0,0 +1,64 @@
|
||||
#ifndef Magnum_DebugTools_ResourceManager_h |
||||
#define Magnum_DebugTools_ResourceManager_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::DebugTools::ResourceManager |
||||
*/ |
||||
|
||||
#include "Magnum.h" |
||||
|
||||
#ifndef MAGNUM_RESOURCEMANAGER_DEFINE_INTERNALINSTANCE |
||||
#define MAGNUM_RESOURCEMANAGER_DONT_DEFINE_INTERNALINSTANCE |
||||
#endif |
||||
#include "../ResourceManager.h" |
||||
|
||||
#include "SceneGraph/SceneGraph.h" |
||||
#include "Physics/Physics.h" |
||||
#include "DebugTools.h" |
||||
|
||||
#include "magnumDebugToolsVisibility.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
extern template ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ForceRendererOptions, DebugTools::ObjectRendererOptions, DebugTools::ShapeRendererOptions> MAGNUM_DEBUGTOOLS_EXPORT *& ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ForceRendererOptions, DebugTools::ObjectRendererOptions, DebugTools::ShapeRendererOptions>::internalInstance(); |
||||
|
||||
namespace DebugTools { |
||||
|
||||
/**
|
||||
@brief %Resource manager for debug tools |
||||
|
||||
Stores various data used by debug renderers. See @ref debug-tools for more |
||||
information. |
||||
*/ |
||||
class MAGNUM_DEBUGTOOLS_EXPORT ResourceManager: public Magnum::ResourceManager<AbstractShaderProgram, Buffer, Mesh, DebugTools::ForceRendererOptions, DebugTools::ObjectRendererOptions, DebugTools::ShapeRendererOptions> { |
||||
public: |
||||
explicit ResourceManager(); |
||||
~ResourceManager(); |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,109 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "ShapeRenderer.h" |
||||
|
||||
#include "ResourceManager.h" |
||||
#include "Physics/AbstractShape.h" |
||||
#include "Physics/AxisAlignedBox.h" |
||||
#include "Physics/Box.h" |
||||
#include "Physics/ObjectShape.h" |
||||
#include "Physics/Point.h" |
||||
#include "Physics/ShapeGroup.h" |
||||
#include "SceneGraph/AbstractCamera.h" |
||||
|
||||
#include "Implementation/AxisAlignedBoxRenderer.h" |
||||
#include "Implementation/BoxRenderer.h" |
||||
#include "Implementation/PointRenderer.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
namespace Implementation { |
||||
|
||||
template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractShape<2>* shape) { |
||||
switch(shape->type()) { |
||||
case Physics::AbstractShape2D::Type::AxisAlignedBox: |
||||
renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast<Physics::AxisAlignedBox2D*>(shape))); |
||||
break; |
||||
case Physics::AbstractShape2D::Type::Box: |
||||
renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast<Physics::Box2D*>(shape))); |
||||
break; |
||||
case Physics::AbstractShape2D::Type::Point: |
||||
renderer->renderers.push_back(new Implementation::PointRenderer<2>(*static_cast<Physics::Point2D*>(shape))); |
||||
break; |
||||
case Physics::AbstractShape2D::Type::ShapeGroup: { |
||||
Physics::ShapeGroup2D* group = static_cast<Physics::ShapeGroup2D*>(shape); |
||||
if(group->first()) createDebugMesh(renderer, group->first()); |
||||
if(group->second()) createDebugMesh(renderer, group->second()); |
||||
} break; |
||||
default: |
||||
Warning() << "DebugTools::ShapeRenderer2D::createShapeRenderer(): type" << shape->type() << "not implemented"; |
||||
} |
||||
} |
||||
|
||||
template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractShape<3>* shape) { |
||||
switch(shape->type()) { |
||||
case Physics::AbstractShape3D::Type::AxisAlignedBox: |
||||
renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(*static_cast<Physics::AxisAlignedBox3D*>(shape))); |
||||
break; |
||||
case Physics::AbstractShape3D::Type::Box: |
||||
renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast<Physics::Box3D*>(shape))); |
||||
break; |
||||
case Physics::AbstractShape3D::Type::Point: |
||||
renderer->renderers.push_back(new Implementation::PointRenderer<3>(*static_cast<Physics::Point3D*>(shape))); |
||||
break; |
||||
case Physics::AbstractShape3D::Type::ShapeGroup: { |
||||
Physics::ShapeGroup3D* group = static_cast<Physics::ShapeGroup3D*>(shape); |
||||
if(group->first()) createDebugMesh(renderer, group->first()); |
||||
if(group->second()) createDebugMesh(renderer, group->second()); |
||||
} break; |
||||
default: |
||||
Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented"; |
||||
} |
||||
} |
||||
|
||||
} |
||||
#endif |
||||
|
||||
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::ShapeRenderer(Physics::ObjectShape<dimensions>* shape, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(shape->object(), drawables), options(ResourceManager::instance()->get<ShapeRendererOptions>(options)) { |
||||
CORRADE_ASSERT(shape->shape() != nullptr, "DebugTools::ShapeRenderer: cannot create renderer for empty shape", ); |
||||
Implementation::createDebugMesh(this, shape->shape()); |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::~ShapeRenderer() { |
||||
for(auto it = renderers.begin(); it != renderers.end(); ++it) |
||||
delete *it; |
||||
} |
||||
|
||||
template<UnsignedInt dimensions> void ShapeRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType&, SceneGraph::AbstractCamera<dimensions>* camera) { |
||||
typename DimensionTraits<dimensions>::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix(); |
||||
for(auto it = renderers.begin(); it != renderers.end(); ++it) |
||||
(*it)->draw(options, projectionMatrix); |
||||
} |
||||
|
||||
template class ShapeRenderer<2>; |
||||
template class ShapeRenderer<3>; |
||||
|
||||
}} |
||||
@ -0,0 +1,157 @@
|
||||
#ifndef Magnum_DebugTools_ShapeRenderer_h |
||||
#define Magnum_DebugTools_ShapeRenderer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::DebugTools::ShapeRenderer, Magnum::DebugTools::ShapeRendererOptions, typedef Magnum::DebugTools::ShapeRenderer2D, Magnum::DebugTools::ShapeRenderer3D |
||||
*/ |
||||
|
||||
#include "Color.h" |
||||
#include "Resource.h" |
||||
#include "SceneGraph/Drawable.h" |
||||
#include "Physics/Physics.h" |
||||
|
||||
#include "magnumDebugToolsVisibility.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { |
||||
|
||||
/** @todoc Remove `ifndef` when Doxygen is sane again */ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
template<UnsignedInt> class ShapeRenderer; |
||||
#endif |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
namespace Implementation { |
||||
template<UnsignedInt> class AbstractShapeRenderer; |
||||
|
||||
template<UnsignedInt dimensions> void createDebugMesh(ShapeRenderer<dimensions>* renderer, Physics::AbstractShape<dimensions>* shape); |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
@brief Shape renderer options |
||||
|
||||
See ShapeRenderer documentation for more information. |
||||
*/ |
||||
class ShapeRendererOptions { |
||||
public: |
||||
inline constexpr ShapeRendererOptions(): _pointSize(0.25f) {} |
||||
|
||||
/** @brief Color of rendered shape */ |
||||
inline constexpr Color3<> color() const { return _color; } |
||||
|
||||
/**
|
||||
* @brief Set color of rendered shape |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* Default is black. |
||||
*/ |
||||
inline ShapeRendererOptions* setColor(const Color3<>& color) { |
||||
_color = color; |
||||
return this; |
||||
} |
||||
|
||||
/** @brief Point size */ |
||||
inline constexpr Float pointSize() const { return _pointSize; } |
||||
|
||||
/**
|
||||
* @brief Set point size |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* Size of rendered crosshairs, representing Physics::Point shapes. |
||||
* Default is `0.25f`. |
||||
*/ |
||||
inline ShapeRendererOptions* setPointSize(Float size) { |
||||
_pointSize = size; |
||||
return this; |
||||
} |
||||
|
||||
private: |
||||
Color3<> _color; |
||||
Float _pointSize; |
||||
}; |
||||
|
||||
/**
|
||||
@brief Shape renderer |
||||
|
||||
Visualizes collision shapes using wireframe primitives. See |
||||
@ref debug-tools-renderers for more information. |
||||
|
||||
@section ShapeRenderer-usage Basic usage |
||||
|
||||
Example code: |
||||
@code |
||||
// Create some options
|
||||
DebugTools::ResourceManager::instance()->set("red", |
||||
(new DebugTools::ShapeRendererOptions())->setColor({1.0f, 0.0f, 0.0f})); |
||||
|
||||
// Create debug renderer for given shape, use "red" options for it
|
||||
Physics::ObjectShape2D* shape; |
||||
new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables); |
||||
@endcode |
||||
|
||||
@see ShapeRenderer2D, ShapeRenderer3D |
||||
*/ |
||||
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable<dimensions> { |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
friend void Implementation::createDebugMesh<>(ShapeRenderer<dimensions>*, Physics::AbstractShape<dimensions>*); |
||||
#endif |
||||
|
||||
public: |
||||
/**
|
||||
* @brief Constructor |
||||
* @param shape Object for which to create debug renderer |
||||
* @param options Options resource key. See |
||||
* @ref ShapeRenderer-usage "class documentation" for more |
||||
* information. |
||||
* @param drawables Drawable group |
||||
* |
||||
* The renderer is automatically added to shape's object features, |
||||
* @p shape must be available for the whole lifetime of the renderer. |
||||
* |
||||
* @attention Passed object must have assigned shape. |
||||
*/ |
||||
explicit ShapeRenderer(Physics::ObjectShape<dimensions>* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr); |
||||
|
||||
~ShapeRenderer(); |
||||
|
||||
protected: |
||||
/** @todoc Remove Float when Doxygen properly treats this as override */ |
||||
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, Float>* camera) override; |
||||
|
||||
private: |
||||
Resource<ShapeRendererOptions> options; |
||||
std::vector<Implementation::AbstractShapeRenderer<dimensions>*> renderers; |
||||
}; |
||||
|
||||
/** @brief Two-dimensional shape renderer */ |
||||
typedef ShapeRenderer<2> ShapeRenderer2D; |
||||
|
||||
/** @brief Three-dimensional shape renderer */ |
||||
typedef ShapeRenderer<3> ShapeRenderer3D; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -0,0 +1,25 @@
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# Permission is hereby granted, free of charge, to any person obtaining a |
||||
# copy of this software and associated documentation files (the "Software"), |
||||
# to deal in the Software without restriction, including without limitation |
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
# and/or sell copies of the Software, and to permit persons to whom the |
||||
# Software is furnished to do so, subject to the following conditions: |
||||
# |
||||
# The above copyright notice and this permission notice shall be included |
||||
# in all copies or substantial portions of the Software. |
||||
# |
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
# DEALINGS IN THE SOFTWARE. |
||||
# |
||||
|
||||
corrade_add_test(MagnumDebugToolsForceRendererTest ForceRendererTest.cpp LIBRARIES MagnumMathTestLib) |
||||
@ -0,0 +1,123 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <TestSuite/Tester.h> |
||||
|
||||
#include "DebugTools/Implementation/ForceRendererTransformation.h" |
||||
|
||||
namespace Magnum { namespace DebugTools { namespace Implementation { namespace Test { |
||||
|
||||
class ForceRendererTest: public Corrade::TestSuite::Tester { |
||||
public: |
||||
explicit ForceRendererTest(); |
||||
|
||||
void zero2D(); |
||||
void parallel2D(); |
||||
void antiParallel2D(); |
||||
void arbitrary2D(); |
||||
|
||||
void zero3D(); |
||||
void parallel3D(); |
||||
void antiParallel3D(); |
||||
void arbitrary3D(); |
||||
}; |
||||
|
||||
ForceRendererTest::ForceRendererTest() { |
||||
addTests({&ForceRendererTest::zero2D, |
||||
&ForceRendererTest::parallel2D, |
||||
&ForceRendererTest::antiParallel2D, |
||||
&ForceRendererTest::arbitrary2D, |
||||
|
||||
&ForceRendererTest::zero3D, |
||||
&ForceRendererTest::parallel3D, |
||||
&ForceRendererTest::antiParallel3D, |
||||
&ForceRendererTest::arbitrary3D}); |
||||
} |
||||
|
||||
void ForceRendererTest::zero2D() { |
||||
CORRADE_COMPARE(Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, Vector2()), |
||||
Matrix3::translation({0.5f, -3.0f})*Matrix3::scaling(Vector2(0.0f))); |
||||
} |
||||
|
||||
void ForceRendererTest::parallel2D() { |
||||
CORRADE_COMPARE(Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, Vector2::xAxis(2.5f)), |
||||
Matrix3::translation({0.5f, -3.0f})*Matrix3::scaling(Vector2(2.5f))); |
||||
} |
||||
|
||||
void ForceRendererTest::antiParallel2D() { |
||||
CORRADE_COMPARE(Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, Vector2::xAxis(-2.5f)), |
||||
Matrix3::translation({0.5f, -3.0f})*Matrix3::scaling(Vector2(-2.5f))); |
||||
} |
||||
|
||||
void ForceRendererTest::arbitrary2D() { |
||||
Vector2 force(2.7f, -11.5f); |
||||
Matrix3 m = Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, force); |
||||
|
||||
/* Translation, right-pointing base vector is the same as force */ |
||||
CORRADE_COMPARE(m.translation(), Vector2(0.5f, -3.0f)); |
||||
CORRADE_COMPARE(m.right(), force); |
||||
|
||||
/* All vectors have the same length */ |
||||
CORRADE_COMPARE(m.up().length(), force.length()); |
||||
|
||||
/* All vectors are parallel */ |
||||
CORRADE_COMPARE(Vector2::dot(m.right(), m.up()), 0.0f); |
||||
} |
||||
|
||||
void ForceRendererTest::zero3D() { |
||||
CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3()), |
||||
Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling(Vector3(0.0f))); |
||||
} |
||||
|
||||
void ForceRendererTest::parallel3D() { |
||||
CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3::xAxis(2.5f)), |
||||
Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling(Vector3(2.5f))); |
||||
} |
||||
|
||||
void ForceRendererTest::antiParallel3D() { |
||||
CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3::xAxis(-2.5f)), |
||||
Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling({-2.5f, 2.5f, 2.5f})); |
||||
} |
||||
|
||||
void ForceRendererTest::arbitrary3D() { |
||||
Vector3 force(3.7f, -5.7f, -11.5f); |
||||
Matrix4 m = Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, force); |
||||
|
||||
/* Translation, right-pointing base vector is the same as force */ |
||||
CORRADE_COMPARE(m.translation(), Vector3(0.5f, -3.0f, 1.0f)); |
||||
CORRADE_COMPARE(m.right(), force); |
||||
|
||||
/* All vectors have the same length */ |
||||
CORRADE_COMPARE(m.up().length(), force.length()); |
||||
CORRADE_COMPARE(m.backward().length(), force.length()); |
||||
|
||||
/* All vectors are parallel */ |
||||
CORRADE_COMPARE(Vector3::dot(m.right(), m.up()), 0.0f); |
||||
CORRADE_COMPARE(Vector3::dot(m.right(), m.backward()), 0.0f); |
||||
CORRADE_COMPARE(Vector3::dot(m.up(), m.backward()), 0.0f); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::DebugTools::Implementation::Test::ForceRendererTest) |
||||
@ -0,0 +1,37 @@
|
||||
#ifndef Magnum_DebugTools_magnumDebugToolsVisibility_h |
||||
#define Magnum_DebugTools_magnumDebugToolsVisibility_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#ifdef _WIN32 |
||||
#ifdef MagnumDebugTools_EXPORTS |
||||
#define MAGNUM_DEBUGTOOLS_EXPORT __declspec(dllexport) |
||||
#else |
||||
#define MAGNUM_DEBUGTOOLS_EXPORT __declspec(dllimport) |
||||
#endif |
||||
#else |
||||
#define MAGNUM_DEBUGTOOLS_EXPORT __attribute__ ((visibility ("default"))) |
||||
#endif |
||||
|
||||
#endif |
||||
@ -0,0 +1,93 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "DefaultFramebuffer.h" |
||||
|
||||
#include "Context.h" |
||||
|
||||
#include "Implementation/State.h" |
||||
#include "Implementation/FramebufferState.h" |
||||
#include "Extensions.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
DefaultFramebuffer defaultFramebuffer; |
||||
|
||||
DefaultFramebuffer::DefaultFramebuffer() { _id = 0; } |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
DefaultFramebuffer* DefaultFramebuffer::mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments) { |
||||
/* Max attachment location */ |
||||
std::size_t max = 0; |
||||
for(const auto& attachment: attachments) |
||||
if(attachment.first > max) max = attachment.first; |
||||
|
||||
/* Create linear array from associative */ |
||||
GLenum* _attachments = new GLenum[max+1]; |
||||
std::fill_n(_attachments, max, GL_NONE); |
||||
for(const auto& attachment: attachments) |
||||
_attachments[attachment.first] = static_cast<GLenum>(attachment.second); |
||||
|
||||
(this->*drawBuffersImplementation)(max+1, _attachments); |
||||
delete[] _attachments; |
||||
return this; |
||||
} |
||||
#endif |
||||
|
||||
void DefaultFramebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments) { |
||||
GLenum* _attachments = new GLenum[attachments.size()]; |
||||
for(std::size_t i = 0; i != attachments.size(); ++i) |
||||
_attachments[i] = GLenum(*(attachments.begin()+i)); |
||||
|
||||
invalidateImplementation(attachments.size(), _attachments); |
||||
|
||||
delete[] _attachments; |
||||
} |
||||
|
||||
void DefaultFramebuffer::invalidate(std::initializer_list<InvalidationAttachment> attachments, const Rectanglei& rectangle) { |
||||
GLenum* _attachments = new GLenum[attachments.size()]; |
||||
for(std::size_t i = 0; i != attachments.size(); ++i) |
||||
_attachments[i] = GLenum(*(attachments.begin()+i)); |
||||
|
||||
invalidateImplementation(attachments.size(), _attachments, rectangle); |
||||
|
||||
delete[] _attachments; |
||||
} |
||||
|
||||
void DefaultFramebuffer::initializeContextBasedFunctionality(Context* context) { |
||||
Implementation::FramebufferState* state = context->state()->framebuffer; |
||||
|
||||
/* Initial framebuffer size */ |
||||
GLint viewport[4]; |
||||
glGetIntegerv(GL_VIEWPORT, viewport); |
||||
defaultFramebuffer._viewport = state->viewport = Rectanglei::fromSize({viewport[0], viewport[1]}, {viewport[2], viewport[3]}); |
||||
|
||||
/* Fake initial glViewport() call for ApiTrace */ |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
if(context->isExtensionSupported<Extensions::GL::GREMEDY::string_marker>()) |
||||
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); |
||||
#endif |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,384 @@
|
||||
#ifndef Magnum_DefaultFramebuffer_h |
||||
#define Magnum_DefaultFramebuffer_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::DefaultFramebuffer |
||||
*/ |
||||
|
||||
#include "AbstractFramebuffer.h" |
||||
|
||||
namespace Magnum { |
||||
|
||||
/**
|
||||
@brief Default framebuffer |
||||
|
||||
Default framebuffer, i.e. the actual screen surface. It is automatically |
||||
created when Context is created and it is available through global variable |
||||
@ref defaultFramebuffer. It is by default mapped to whole screen surface. |
||||
|
||||
@section DefaultFramebuffer-usage Usage |
||||
|
||||
When you are using only the default framebuffer, the usage is simple. You |
||||
must ensure that it is properly resized when application surface is resized, |
||||
i.e. you must pass the new size in your @ref Platform::GlutApplication::viewportEvent() "viewportEvent()" |
||||
implementation, for example: |
||||
@code |
||||
void viewportEvent(const Vector2i& size) { |
||||
defaultFramebuffer.setViewport({}, size); |
||||
|
||||
// ...
|
||||
} |
||||
@endcode |
||||
|
||||
Next thing you probably want is to clear all used buffers before performing |
||||
any drawing in your @ref Platform::GlutApplication::drawEvent() "drawEvent()" |
||||
implementation, for example: |
||||
@code |
||||
void drawEvent() { |
||||
defaultFramebuffer.clear(AbstractFramebuffer::Clear::Color|AbstractFramebuffer::Clear::Depth); |
||||
|
||||
// ...
|
||||
} |
||||
@endcode |
||||
|
||||
See Framebuffer documentation for more involved usage, usage of non-default or |
||||
multiple framebuffers. |
||||
|
||||
@section DefaultFramebuffer-performance-optimization Performance optimizations |
||||
|
||||
See also @ref AbstractFramebuffer-performance-optimization "relevant section in AbstractFramebuffer". |
||||
|
||||
If extension @extension{EXT,direct_state_access} is available, functions |
||||
mapForDraw() and mapForRead() use DSA to avoid unnecessary calls to |
||||
@fn_gl{BindFramebuffer}. See their respective documentation for more |
||||
information. |
||||
*/ |
||||
class MAGNUM_EXPORT DefaultFramebuffer: public AbstractFramebuffer { |
||||
friend class Context; |
||||
|
||||
public: |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* @brief Draw attachment |
||||
* |
||||
* @see mapForDraw() |
||||
* @requires_gles30 Draw attachments for default framebuffer are |
||||
* available only in OpenGL ES 3.0. |
||||
*/ |
||||
enum class DrawAttachment: GLenum { |
||||
/** Don't use the output. */ |
||||
None = GL_NONE, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* Write output to front left buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
FrontLeft = GL_FRONT_LEFT, |
||||
|
||||
/**
|
||||
* Write output to front right buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
FrontRight = GL_FRONT_RIGHT, |
||||
|
||||
/**
|
||||
* Write output to back left buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
BackLeft = GL_BACK_LEFT, |
||||
|
||||
/**
|
||||
* Write output to back right buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
BackRight = GL_BACK_RIGHT, |
||||
#endif |
||||
|
||||
/**
|
||||
* Write output to back buffer. |
||||
* |
||||
* On desktop OpenGL, this is equal to @ref DrawAttachment "DrawAttachment::BackLeft". |
||||
*/ |
||||
#ifdef MAGNUM_TARGET_GLES |
||||
Back = GL_BACK, |
||||
#else |
||||
Back = GL_BACK_LEFT, |
||||
#endif |
||||
|
||||
/**
|
||||
* Write output to front buffer. |
||||
* |
||||
* On desktop OpenGL, this is equal to @ref DrawAttachment "DrawAttachment::FrontLeft". |
||||
*/ |
||||
#ifdef MAGNUM_TARGET_GLES |
||||
Front = GL_FRONT |
||||
#else |
||||
Front = GL_FRONT_LEFT |
||||
#endif |
||||
}; |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Read attachment |
||||
* |
||||
* @see mapForRead() |
||||
* @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} |
||||
*/ |
||||
enum class ReadAttachment: GLenum { |
||||
/** Don't read from any buffer */ |
||||
None = GL_NONE, |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* Read from front left buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
FrontLeft = GL_FRONT_LEFT, |
||||
|
||||
/**
|
||||
* Read from front right buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
FrontRight = GL_FRONT_RIGHT, |
||||
|
||||
/**
|
||||
* Read from back left buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
BackLeft = GL_BACK_LEFT, |
||||
|
||||
/**
|
||||
* Read from back right buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
BackRight = GL_BACK_RIGHT, |
||||
|
||||
/**
|
||||
* Read from left buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
Left = GL_LEFT, |
||||
|
||||
/**
|
||||
* Read from right buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
Right = GL_RIGHT, |
||||
#endif |
||||
|
||||
/** Read from back buffer. */ |
||||
Back = GL_BACK, |
||||
|
||||
/**
|
||||
* Read from front buffer. |
||||
* @requires_es_extension %Extension @es_extension2{NV,read_buffer_front,GL_NV_read_buffer} |
||||
*/ |
||||
Front = GL_FRONT |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES |
||||
, |
||||
|
||||
/**
|
||||
* Read from front and back buffer. |
||||
* @requires_gl In OpenGL ES you must specify either |
||||
* @ref Magnum::DefaultFramebuffer::ReadAttachment "ReadAttachment::Front" |
||||
* or @ref Magnum::DefaultFramebuffer::ReadAttachment "ReadAttachment::Back". |
||||
*/ |
||||
FrontAndBack = GL_FRONT_AND_BACK |
||||
#endif |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Invalidation attachment |
||||
* |
||||
* @see invalidate() |
||||
* @requires_gl43 %Extension @extension{ARB,invalidate_subdata} |
||||
* @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer} |
||||
*/ |
||||
enum class InvalidationAttachment: GLenum { |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
/**
|
||||
* Invalidate front left buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
FrontLeft = GL_FRONT_LEFT, |
||||
|
||||
/**
|
||||
* Invalidate front right buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
FrontRight = GL_FRONT_RIGHT, |
||||
|
||||
/**
|
||||
* Invalidate back left buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
BackLeft = GL_BACK_LEFT, |
||||
|
||||
/**
|
||||
* Invalidate back right buffer. |
||||
* @requires_gl Stereo rendering is not available in OpenGL ES. |
||||
*/ |
||||
BackRight = GL_BACK_RIGHT, |
||||
#endif |
||||
|
||||
/** Invalidate color buffer. */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
Color = GL_COLOR, |
||||
#else |
||||
Color = GL_COLOR_EXT, |
||||
#endif |
||||
|
||||
/** Invalidate depth bufer. */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
Depth = GL_DEPTH, |
||||
#else |
||||
Depth = GL_DEPTH_EXT, |
||||
#endif |
||||
|
||||
/** Invalidate stencil buffer. */ |
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
Stencil = GL_STENCIL |
||||
#else |
||||
Stencil = GL_STENCIL_EXT |
||||
#endif |
||||
}; |
||||
|
||||
explicit MAGNUM_LOCAL DefaultFramebuffer(); |
||||
|
||||
#ifndef MAGNUM_TARGET_GLES2 |
||||
/**
|
||||
* @brief Map shader outputs to buffer attachment |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* @p attachments is list of shader outputs mapped to buffer |
||||
* attachments. %Shader outputs which are not listed are not used, you |
||||
* can achieve the same by passing @ref DrawAttachment "DrawAttachment::None" |
||||
* as attachment. Example usage: |
||||
* @code |
||||
* framebuffer.mapForDraw({{MyShader::ColorOutput, DefaultFramebuffer::DrawAttachment::BackLeft}, |
||||
* {MyShader::NormalOutput, DefaultFramebuffer::DrawAttachment::None}}); |
||||
* @endcode |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available and the |
||||
* framebufferbuffer is not currently bound, it is bound before the |
||||
* operation. |
||||
* @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffers} or |
||||
* @fn_gl_extension{FramebufferDrawBuffers,EXT,direct_state_access} |
||||
* @requires_gles30 Draw attachments for default framebuffer are |
||||
* available only in OpenGL ES 3.0. |
||||
*/ |
||||
DefaultFramebuffer* mapForDraw(std::initializer_list<std::pair<UnsignedInt, DrawAttachment>> attachments); |
||||
|
||||
/**
|
||||
* @brief Map shader output to buffer attachment |
||||
* @param attachment %Buffer attachment |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* Similar to above function, can be used in cases when shader has |
||||
* only one (unnamed) output. |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available and the |
||||
* framebufferbuffer is not currently bound, it is bound before the |
||||
* operation. |
||||
* @see mapForRead(), @fn_gl{BindFramebuffer}, @fn_gl{DrawBuffer} or |
||||
* @fn_gl_extension{FramebufferDrawBuffer,EXT,direct_state_access} |
||||
* @requires_gles30 Draw attachments for default framebuffer are |
||||
* available only in OpenGL ES 3.0. |
||||
*/ |
||||
inline DefaultFramebuffer* mapForDraw(DrawAttachment attachment) { |
||||
(this->*drawBufferImplementation)(static_cast<GLenum>(attachment)); |
||||
return this; |
||||
} |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Map given attachment for reading |
||||
* @param attachment %Buffer attachment |
||||
* @return Pointer to self (for method chaining) |
||||
* |
||||
* If @extension{EXT,direct_state_access} is not available and the |
||||
* framebufferbuffer is not currently bound, it is bound before the |
||||
* operation. |
||||
* @see mapForDraw(), @fn_gl{BindFramebuffer}, @fn_gl{ReadBuffer} or |
||||
* @fn_gl_extension{FramebufferReadBuffer,EXT,direct_state_access} |
||||
* @requires_gles30 %Extension @es_extension2{NV,read_buffer,GL_NV_read_buffer} |
||||
*/ |
||||
inline DefaultFramebuffer* mapForRead(ReadAttachment attachment) { |
||||
(this->*readBufferImplementation)(static_cast<GLenum>(attachment)); |
||||
return this; |
||||
} |
||||
|
||||
/**
|
||||
* @brief Invalidate framebuffer |
||||
* @param attachments Attachments to invalidate |
||||
* |
||||
* The framebuffer is bound to some target before the operation, if |
||||
* not already. |
||||
* @see @fn_gl{InvalidateFramebuffer} or @fn_gles_extension{DiscardFramebuffer,EXT,discard_framebuffer} |
||||
* on OpenGL ES 2.0 |
||||
* @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use |
||||
* clear() instead where the extension is not supported. |
||||
* @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer}. |
||||
* Use clear() instead where the extension is not supported. |
||||
*/ |
||||
void invalidate(std::initializer_list<InvalidationAttachment> attachments); |
||||
|
||||
/**
|
||||
* @brief Invalidate framebuffer rectangle |
||||
* @param attachments Attachments to invalidate |
||||
* @param rectangle %Rectangle to invalidate |
||||
* |
||||
* The framebuffer is bound to some target before the operation, if |
||||
* not already. |
||||
* @see @fn_gl{InvalidateSubFramebuffer} or @fn_gles_extension{DiscardSubFramebuffer,EXT,discard_framebuffer} |
||||
* on OpenGL ES 2.0 |
||||
* @requires_gl43 %Extension @extension{ARB,invalidate_subdata}. Use |
||||
* clear() instead where the extension is not supported. |
||||
* @requires_gles30 %Extension @es_extension{EXT,discard_framebuffer}. |
||||
* Use clear() instead where the extension is not supported. |
||||
*/ |
||||
void invalidate(std::initializer_list<InvalidationAttachment> attachments, const Rectanglei& rectangle); |
||||
|
||||
/* Overloads to remove WTF-factor from method chaining order */ |
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
inline DefaultFramebuffer* setViewport(const Rectanglei& rectangle) { |
||||
AbstractFramebuffer::setViewport(rectangle); |
||||
return this; |
||||
} |
||||
#endif |
||||
|
||||
private: |
||||
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); |
||||
}; |
||||
|
||||
/** @brief Default framebuffer instance */ |
||||
extern DefaultFramebuffer MAGNUM_EXPORT defaultFramebuffer; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue