Compare commits
52 Commits
07b0a63202
...
c8d16631f8
Author | SHA1 | Date | |
---|---|---|---|
c8d16631f8 | |||
ac8b6b2eb8 | |||
cbc0ac7dbc | |||
41952bf140 | |||
961cf3e007 | |||
9fc1003fbb | |||
9f5104bedc | |||
ce3e28295c | |||
3be9f44264 | |||
0f14d7341a | |||
851398b31f | |||
5df959666e | |||
dd88360740 | |||
56b4ebf9ef | |||
83eecacc0b | |||
0071818a2d | |||
190376859f | |||
3f92bff9a0 | |||
6e2eea031a | |||
fa325e7d3d | |||
ab2e72df38 | |||
d91a26e294 | |||
35a43e70b8 | |||
c814aea10c | |||
4266dd1bfe | |||
5e65339d82 | |||
46f30152c6 | |||
00951b6456 | |||
23929b68a7 | |||
c8a47c2860 | |||
714dcf4128 | |||
ae21bbff96 | |||
11e7e0f540 | |||
3b649afbb7 | |||
65d8bab566 | |||
65a35a8ead | |||
b1033f884e | |||
0442aeba36 | |||
c504a3fe0d | |||
ae66951f6a | |||
e1d2501a57 | |||
2d76844e7d | |||
ca25dd50ad | |||
5ab6c7681a | |||
080f51add7 | |||
d623be0f91 | |||
b9c6a7e653 | |||
fe260e377e | |||
681a46ea70 | |||
7eef66f2b9 | |||
544d9e2e02 | |||
82e6842c4a |
509
LICENSE
509
LICENSE
@ -1,202 +1,373 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1. Definitions.
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
2.1. Grants
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
2.2. Effective Date
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
@ -77,15 +77,15 @@ Compile software:
|
||||
lutin gale-sample-basic
|
||||
|
||||
|
||||
License (APACHE v2.0)
|
||||
License (MPL v2.0)
|
||||
=====================
|
||||
Copyright gale Edouard DUPIN
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
Licensed under the Mozilla Public License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
https://www.mozilla.org/MPL/2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ -95,4 +95,4 @@ limitations under the License.
|
||||
|
||||
|
||||
# gale
|
||||
(APACHE-2) Graphic Abstraction Layer for Ewol: abstract the OpenGL/... interface and mouse/touch/keyboard for multiple system (Linux, Android, MacOs, Windows, Ios)
|
||||
(MPL v2.0) Graphic Abstraction Layer for Ewol: abstract the OpenGL/... interface and mouse/touch/keyboard for multiple system (Linux, Android, MacOs, Windows, Ios)
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.gale;
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.gale;
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.gale;
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.gale;
|
||||
@ -12,6 +12,7 @@ import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Process;
|
||||
|
||||
// import the gale package :
|
||||
/* no need in same package... */
|
||||
@ -31,14 +32,17 @@ public class GaleRendererGL implements GLSurfaceView.Renderer
|
||||
m_galeNative = _galeInstance;
|
||||
}
|
||||
public void onSurfaceCreated(GL10 _gl, EGLConfig _config) {
|
||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
|
||||
m_galeNative.renderInit();
|
||||
}
|
||||
|
||||
public void onSurfaceChanged(GL10 _gl, int _w, int _h) {
|
||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
|
||||
m_galeNative.renderResize(_w, _h);
|
||||
}
|
||||
|
||||
public void onDrawFrame(GL10 _gl) {
|
||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
|
||||
m_galeNative.renderDraw();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.gale;
|
||||
@ -35,6 +35,12 @@ public class GaleSurfaceViewGL extends GLSurfaceView implements GaleConstants {
|
||||
m_galeNative = _galeInstance;
|
||||
/*
|
||||
List of the Android API :
|
||||
Android 9.0 28 Pie
|
||||
Android 8.0 - 8.1 26 Oreo
|
||||
Android 7.0 - 7.1.2 24 Nougat
|
||||
Android 6.0 - 6.0.1 23 Marshmallow
|
||||
Android 5.0 - 5.1.1 21 LOLIPOP
|
||||
Android 4.4 - 4.4.4 19 KIT-KAT
|
||||
Android 4.1, 4.1.1 16 JELLY_BEAN Platform Highlights
|
||||
Android 4.0.3, 4.0.4 15 ICE_CREAM_SANDWICH_MR1 Platform Highlights
|
||||
Android 4.0, 4.0.1, 4.0.2 14 ICE_CREAM_SANDWICH
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.gale;
|
||||
|
@ -41,16 +41,16 @@ Are there any licensing restrictions? {#gale_mainpage_restriction}
|
||||
GALE is **FREE software** and _all sub-library are FREE and staticly linkable !!!_
|
||||
|
||||
|
||||
License (APACHE-2.0) {#gale_mainpage_license}
|
||||
====================
|
||||
License (MPL v2.0) {#gale_mainpage_license}
|
||||
==================
|
||||
|
||||
Copyright gale Edouard DUPIN
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
Licensed under the Mozilla Public License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
<http://www.apache.org/licenses/LICENSE-2.0>
|
||||
<https://www.mozilla.org/MPL/2.0>
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -1,15 +1,17 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <gale/Application.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::Application);
|
||||
|
||||
gale::Application::Application() :
|
||||
m_canDraw(false),
|
||||
m_needRedraw(true),
|
||||
m_title("gale"),
|
||||
m_iconName(""),
|
||||
@ -119,23 +121,23 @@ vec2 gale::Application::getPosition() const {
|
||||
return vec2(0,0);
|
||||
}
|
||||
|
||||
void gale::Application::setTitle(const std::string& _title) {
|
||||
void gale::Application::setTitle(const etk::String& _title) {
|
||||
m_title = _title;
|
||||
gale::Context& context = gale::getContext();
|
||||
context.setTitle(m_title);
|
||||
}
|
||||
|
||||
std::string gale::Application::getTitle() {
|
||||
etk::String gale::Application::getTitle() {
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void gale::Application::setIcon(const std::string& _iconFile) {
|
||||
void gale::Application::setIcon(const etk::Uri& _iconFile) {
|
||||
m_iconName = _iconFile;
|
||||
gale::Context& context = gale::getContext();
|
||||
context.setIcon(m_iconName);
|
||||
}
|
||||
|
||||
std::string gale::Application::getIcon() {
|
||||
const etk::Uri& gale::Application::getIcon() {
|
||||
return m_iconName;
|
||||
}
|
||||
|
||||
@ -149,7 +151,7 @@ enum gale::context::cursor gale::Application::getCursor() {
|
||||
return m_cursor;
|
||||
}
|
||||
|
||||
void gale::Application::openURL(const std::string& _url) {
|
||||
void gale::Application::openURL(const etk::String& _url) {
|
||||
gale::Context& context = gale::getContext();
|
||||
context.openURL(_url);
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <ememory/memory.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/math/Vector2D.hpp>
|
||||
#include <gale/orientation.hpp>
|
||||
#include <gale/key/status.hpp>
|
||||
@ -23,6 +24,7 @@ namespace gale {
|
||||
Application();
|
||||
virtual ~Application();
|
||||
public:
|
||||
bool m_canDraw;
|
||||
/**
|
||||
* @brief The application is created.
|
||||
* @param[in] _context Current gale context.
|
||||
@ -144,31 +146,31 @@ namespace gale {
|
||||
*/
|
||||
virtual vec2 getPosition() const;
|
||||
private:
|
||||
std::string m_title;
|
||||
etk::String m_title;
|
||||
public:
|
||||
/**
|
||||
* @brief Set the title of the application
|
||||
* @param[in] _title New title to set at the application (if possible: Android and Ios does not support it)
|
||||
*/
|
||||
virtual void setTitle(const std::string& _title);
|
||||
virtual void setTitle(const etk::String& _title);
|
||||
/**
|
||||
* @brief Get the current title of the application
|
||||
* @return Current title
|
||||
*/
|
||||
virtual std::string getTitle();
|
||||
virtual etk::String getTitle();
|
||||
private:
|
||||
std::string m_iconName;
|
||||
etk::Uri m_iconName;
|
||||
public:
|
||||
/**
|
||||
* @brief set the Icon of the application.
|
||||
* @param[in] _iconFile File name icon (.bmp/.png).
|
||||
*/
|
||||
virtual void setIcon(const std::string& _iconFile);
|
||||
virtual void setIcon(const etk::Uri& _iconFile);
|
||||
/**
|
||||
* @brief Get the current filename of the application.
|
||||
* @return Filename of the icon.
|
||||
*/
|
||||
virtual std::string getIcon();
|
||||
virtual const etk::Uri& getIcon();
|
||||
private:
|
||||
enum gale::context::cursor m_cursor;
|
||||
public:
|
||||
@ -187,7 +189,7 @@ namespace gale {
|
||||
* @brief Open an URL on an internal brother.
|
||||
* @param[in] _url URL to open.
|
||||
*/
|
||||
virtual void openURL(const std::string& _url);
|
||||
virtual void openURL(const etk::String& _url);
|
||||
private:
|
||||
enum gale::orientation m_orientation;
|
||||
public:
|
||||
|
@ -1,12 +1,14 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::distance);
|
||||
ETK_DECLARE_TYPE(gale::Dimension);
|
||||
// TODO : set this in a super class acced in a statin fuction...
|
||||
// ratio in milimeter :
|
||||
static bool isInit = false;
|
||||
@ -80,7 +82,7 @@ gale::Dimension::Dimension(const vec2& _size, enum gale::distance _type) :
|
||||
set(_size, _type);
|
||||
}
|
||||
|
||||
void gale::Dimension::set(std::string _config) {
|
||||
void gale::Dimension::set(etk::String _config) {
|
||||
m_data.setValue(0,0);
|
||||
m_type = gale::distance::pixel;
|
||||
enum distance type = gale::distance::pixel;
|
||||
@ -121,8 +123,8 @@ gale::Dimension::~Dimension() {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
gale::Dimension::operator std::string() const {
|
||||
std::string str;
|
||||
gale::Dimension::operator etk::String() const {
|
||||
etk::String str;
|
||||
str = get(getType());
|
||||
|
||||
switch(getType()) {
|
||||
@ -178,12 +180,12 @@ vec2 gale::Dimension::get(enum gale::distance _type) const {
|
||||
|
||||
void gale::Dimension::set(const vec2& _size, enum gale::distance _type) {
|
||||
// set min max on input to limit error :
|
||||
vec2 size(std::avg(0.0f,_size.x(),9999999.0f),
|
||||
std::avg(0.0f,_size.y(),9999999.0f));
|
||||
vec2 size(etk::avg(0.0f,_size.x(),9999999.0f),
|
||||
etk::avg(0.0f,_size.y(),9999999.0f));
|
||||
switch(_type) {
|
||||
case gale::distance::pourcent: {
|
||||
vec2 size2(std::avg(0.0f,_size.x(),100.0f),
|
||||
std::avg(0.0f,_size.y(),100.0f));
|
||||
vec2 size2(etk::avg(0.0f,_size.x(),100.0f),
|
||||
etk::avg(0.0f,_size.y(),100.0f));
|
||||
m_data = vec2(size2.x()*0.01f, size2.y()*0.01f);
|
||||
//GALE_VERBOSE("Set % : " << size2 << " == > " << m_data);
|
||||
break;
|
||||
@ -259,7 +261,7 @@ vec2 gale::Dimension::getFoot() const {
|
||||
return gale::Dimension::getMillimeter()*millimeterToFoot;
|
||||
}
|
||||
|
||||
std::ostream& gale::operator <<(std::ostream& _os, enum gale::distance _obj) {
|
||||
etk::Stream& gale::operator <<(etk::Stream& _os, enum gale::distance _obj) {
|
||||
switch(_obj) {
|
||||
case gale::distance::pourcent:
|
||||
_os << "%";
|
||||
@ -289,24 +291,24 @@ std::ostream& gale::operator <<(std::ostream& _os, enum gale::distance _obj) {
|
||||
return _os;
|
||||
}
|
||||
|
||||
std::ostream& gale::operator <<(std::ostream& _os, const gale::Dimension& _obj) {
|
||||
etk::Stream& gale::operator <<(etk::Stream& _os, const gale::Dimension& _obj) {
|
||||
_os << _obj.get(_obj.getType()) << _obj.getType();
|
||||
return _os;
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<gale::Dimension>(const gale::Dimension& _obj) {
|
||||
template<> etk::String toString<gale::Dimension>(const gale::Dimension& _obj) {
|
||||
return _obj;
|
||||
}
|
||||
template<> std::u32string to_u32string<gale::Dimension>(const gale::Dimension& _obj) {
|
||||
return etk::to_u32string(etk::to_string(_obj));
|
||||
template<> etk::UString toUString<gale::Dimension>(const gale::Dimension& _obj) {
|
||||
return etk::toUString(etk::toString(_obj));
|
||||
}
|
||||
template<> bool from_string<gale::Dimension>(gale::Dimension& _variableRet, const std::string& _value) {
|
||||
template<> bool from_string<gale::Dimension>(gale::Dimension& _variableRet, const etk::String& _value) {
|
||||
_variableRet = gale::Dimension(_value);
|
||||
return true;
|
||||
}
|
||||
template<> bool from_string<gale::Dimension>(gale::Dimension& _variableRet, const std::u32string& _value) {
|
||||
return from_string(_variableRet, etk::to_string(_value));
|
||||
template<> bool from_string<gale::Dimension>(gale::Dimension& _variableRet, const etk::UString& _value) {
|
||||
return from_string(_variableRet, etk::toString(_value));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -43,7 +43,7 @@ namespace gale {
|
||||
* @brief Constructor
|
||||
* @param[in] _config dimension configuration.
|
||||
*/
|
||||
Dimension(const std::string& _config) :
|
||||
Dimension(const etk::String& _config) :
|
||||
m_data(0,0),
|
||||
m_type(gale::distance::pixel) {
|
||||
set(_config);
|
||||
@ -65,7 +65,7 @@ namespace gale {
|
||||
/**
|
||||
* @brief string cast :
|
||||
*/
|
||||
operator std::string() const;
|
||||
operator etk::String() const;
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in requested type
|
||||
@ -85,7 +85,7 @@ namespace gale {
|
||||
* @brief set the current dimention in requested type
|
||||
* @param[in] _config dimension configuration.
|
||||
*/
|
||||
void set(std::string _config);
|
||||
void set(etk::String _config);
|
||||
public:
|
||||
/**
|
||||
* @brief get the current dimention in pixel
|
||||
@ -199,7 +199,7 @@ namespace gale {
|
||||
static float getWindowsDiag(enum gale::distance _type);
|
||||
|
||||
};
|
||||
std::ostream& operator <<(std::ostream& _os, enum gale::distance _obj);
|
||||
std::ostream& operator <<(std::ostream& _os, const gale::Dimension& _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, enum gale::distance _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, const gale::Dimension& _obj);
|
||||
}
|
||||
|
||||
|
@ -1,30 +1,18 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#include <gale/Thread.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
|
||||
#include <gale/context/Context.hpp>
|
||||
|
||||
#if defined(__TARGET_OS__Android)
|
||||
void* gale::Thread::threadCallback(void* _userData) {
|
||||
gale::Thread* threadHandle = static_cast<gale::Thread*>(_userData);
|
||||
if (threadHandle != nullptr) {
|
||||
threadHandle->threadCall();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::Thread);
|
||||
|
||||
gale::Thread::Thread() :
|
||||
m_state(state::stop),
|
||||
#if !defined(__TARGET_OS__Android)
|
||||
m_thread(nullptr),
|
||||
#endif
|
||||
m_context(nullptr) {
|
||||
m_context(0) {
|
||||
GALE_INFO("Create new Thread");
|
||||
}
|
||||
|
||||
@ -36,29 +24,24 @@ gale::Thread::~Thread() {
|
||||
|
||||
void gale::Thread::start() {
|
||||
if (m_state == state::stop) {
|
||||
GALE_DEBUG("Allocate std::thread [START]");
|
||||
GALE_DEBUG("Allocate ethread::Thread [START]");
|
||||
m_state = state::starting;
|
||||
m_context = &gale::getContext();
|
||||
#if defined(__TARGET_OS__Android)
|
||||
pthread_create(&m_thread, nullptr, &gale::Thread::threadCallback, this);
|
||||
#else
|
||||
m_thread = ememory::makeShared<std::thread>(&gale::Thread::threadCall, this);
|
||||
if (m_thread == nullptr) {
|
||||
GALE_ERROR("Can not create thread ...");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
//m_thread->detach();
|
||||
GALE_DEBUG("Allocate std::thread [Set priority]");
|
||||
m_thread = ememory::makeShared<ethread::Thread>([=](){this->threadCall();}, "galeThread");
|
||||
if (m_thread == null) {
|
||||
GALE_ERROR("Can not create thread ...");
|
||||
return;
|
||||
}
|
||||
GALE_DEBUG("Allocate ethread::Thread [Set priority]");
|
||||
// set priority
|
||||
|
||||
GALE_DEBUG("Allocate std::thread [Register context]");
|
||||
GALE_DEBUG("Allocate ethread::Thread [Register context]");
|
||||
// set association with the gale context ...
|
||||
//gale::contextRegisterThread(m_thread);
|
||||
|
||||
GALE_DEBUG("Allocate std::thread [set State]");
|
||||
GALE_DEBUG("Allocate ethread::Thread [set State]");
|
||||
m_state = state::running;
|
||||
GALE_DEBUG("Allocate std::thread [STOP]");
|
||||
GALE_DEBUG("Allocate ethread::Thread [STOP]");
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,46 +49,62 @@ void gale::Thread::stop() {
|
||||
if (m_state == state::stop) {
|
||||
return;
|
||||
}
|
||||
// Request thread stop ==> other wise, we waint indefinitly ...
|
||||
m_state = state::stopping;
|
||||
while ( m_state == state::running
|
||||
|| m_state == state::starting) {
|
||||
// requesting a stop ...
|
||||
GALE_INFO("wait Thread stopping");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
ethread::sleepMilliSeconds((100));
|
||||
}
|
||||
GALE_DEBUG("stop std::thread [START]");
|
||||
#if defined(__TARGET_OS__Android)
|
||||
void* ret = nullptr;
|
||||
int val = pthread_join(m_thread, &ret);
|
||||
#else
|
||||
m_thread->join();
|
||||
#endif
|
||||
GALE_DEBUG("stop ethread::Thread [START]");
|
||||
m_thread->join();
|
||||
//gale::contextUnRegisterThread(m_thread);
|
||||
GALE_DEBUG("stop std::thread [delete]");
|
||||
#if defined(__TARGET_OS__Android)
|
||||
|
||||
#else
|
||||
m_thread.reset();
|
||||
#endif
|
||||
GALE_DEBUG("stop std::thread [set state]");
|
||||
GALE_DEBUG("stop ethread::Thread [delete]");
|
||||
m_thread.reset();
|
||||
GALE_DEBUG("stop ethread::Thread [set state]");
|
||||
m_state = state::stop;
|
||||
GALE_DEBUG("stop std::thread [STOP]");
|
||||
GALE_INFO("stop ethread::Thread [STOP]");
|
||||
}
|
||||
|
||||
void gale::Thread::threadCall() {
|
||||
GALE_DEBUG("THREAD MAIN [START]");
|
||||
if (m_name != "") {
|
||||
ethread::setName(m_name);
|
||||
m_lastUpdatateName = echrono::Steady::now();
|
||||
}
|
||||
gale::setContext(m_context);
|
||||
while (m_state != state::stopping) {
|
||||
if (m_state == state::starting) {
|
||||
GALE_DEBUG("run std::thread [NOTHING to do]");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
GALE_DEBUG("run ethread::Thread [NOTHING to do]");
|
||||
ethread::sleepMilliSeconds((1));
|
||||
continue;
|
||||
}
|
||||
if (m_name != "") {
|
||||
if ((echrono::Steady::now()-m_lastUpdatateName) > echrono::seconds(10)) {
|
||||
m_lastUpdatateName = echrono::Steady::now();
|
||||
ethread::setName(m_name);
|
||||
}
|
||||
}
|
||||
if (onThreadCall() == true) {
|
||||
GALE_DEBUG("run std::thread [AUTO STOP]");
|
||||
GALE_DEBUG("run ethread::Thread [AUTO STOP]");
|
||||
m_state = state::stopping;
|
||||
return;
|
||||
}
|
||||
}
|
||||
GALE_DEBUG("THREAD MAIN [STOP]");
|
||||
gale::setContext(null);
|
||||
m_state = state::stopping;
|
||||
}
|
||||
|
||||
bool gale::Thread::onThreadCall() {
|
||||
return true;
|
||||
};
|
||||
|
||||
enum gale::Thread::state gale::Thread::getState() {
|
||||
return m_state;
|
||||
}
|
||||
|
||||
void gale::Thread::setName(etk::String _name) {
|
||||
m_name = _name;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -9,50 +9,72 @@
|
||||
#include <ethread/tools.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
|
||||
#if defined(__TARGET_OS__Android)
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <thread>
|
||||
#endif
|
||||
#include <ethread/Thread.hpp>
|
||||
|
||||
namespace gale {
|
||||
/**
|
||||
* @brief in the dimention class we store the data as the more usefull unit (pixel)
|
||||
* but one case need to be dynamic the %, then when requested in % the register the % value
|
||||
* @brief We have our own thread in gale to manage gale context folowing and manage android rong management of ethread::Thread when calling java.
|
||||
*/
|
||||
class Thread {
|
||||
private:
|
||||
enum class state {
|
||||
stop,
|
||||
starting,
|
||||
running,
|
||||
stopping
|
||||
};
|
||||
enum state m_state;
|
||||
#if defined(__TARGET_OS__Android)
|
||||
pthread_t m_thread;
|
||||
#else
|
||||
ememory::SharedPtr<std::thread> m_thread;
|
||||
#endif
|
||||
gale::Context* m_context;
|
||||
class Thread : public ememory::EnableSharedFromThis<Thread> {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor (default :0,0 mode pixel)
|
||||
* @brief Internal state capabilities of the thread.
|
||||
*/
|
||||
enum class state {
|
||||
stop, //!< The thread is not active
|
||||
starting, //!< The thread is in creation state
|
||||
running, //!< The current thread is activate
|
||||
stopping //!< The thread is stoping
|
||||
};
|
||||
private:
|
||||
enum state m_state; //!< Current state of the thread.
|
||||
public:
|
||||
/**
|
||||
* @brief Get the current state of the thread
|
||||
* @return The state of the thread
|
||||
*/
|
||||
enum gale::Thread::state getState();
|
||||
private:
|
||||
ememory::SharedPtr<ethread::Thread> m_thread; //!< Current handle on the thread
|
||||
gale::Context* m_context; //!< Copy of the gale context (permit to get current gale interface)
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Thread();
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
virtual ~Thread();
|
||||
void start();
|
||||
void stop();
|
||||
/**
|
||||
* @brief Start the Thread (create thread here)
|
||||
*/
|
||||
virtual void start();
|
||||
/**
|
||||
* @brief Stop the Thread (destroy thread here)
|
||||
*/
|
||||
virtual void stop();
|
||||
private:
|
||||
#if defined(__TARGET_OS__Android)
|
||||
static void* threadCallback(void* _userData);
|
||||
#endif
|
||||
etk::String m_name; //!< thread Name
|
||||
echrono::Steady m_lastUpdatateName;
|
||||
public:
|
||||
/**
|
||||
* @brief change name of the thread
|
||||
* @param[in] _name Name of the thread
|
||||
*/
|
||||
void setName(etk::String m_name);
|
||||
private:
|
||||
/**
|
||||
* @brief Internal periodic call of the thead
|
||||
*/
|
||||
void threadCall();
|
||||
protected:
|
||||
virtual bool onThreadCall() { return true; };
|
||||
/**
|
||||
* @brief Periodic call of the thread process
|
||||
* @return true The thread has ended process and need to be destroyed
|
||||
* @return false Need an other cycle if user does not request stop
|
||||
*/
|
||||
virtual bool onThreadCall();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,17 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN, Kevin BILLONNEAU
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <cstdint>
|
||||
extern "C" {
|
||||
#include <stdint.h>
|
||||
}
|
||||
#include <pthread.h>
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
@ -19,7 +21,7 @@
|
||||
|
||||
// jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include
|
||||
|
||||
std::mutex g_interfaceMutex;
|
||||
ethread::Mutex g_interfaceMutex;
|
||||
|
||||
|
||||
class AndroidContext : public gale::Context {
|
||||
@ -51,10 +53,10 @@ class AndroidContext : public gale::Context {
|
||||
private:
|
||||
bool safeInitMethodID(jmethodID& _mid, jclass& _cls, const char* _name, const char* _sign) {
|
||||
_mid = m_JavaVirtualMachinePointer->GetMethodID(_cls, _name, _sign);
|
||||
if(_mid == nullptr) {
|
||||
if(_mid == null) {
|
||||
GALE_ERROR("C->java : Can't find the method " << _name);
|
||||
/* remove access on the virtual machine : */
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
m_JavaVirtualMachinePointer = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -63,7 +65,7 @@ class AndroidContext : public gale::Context {
|
||||
AndroidContext(gale::Application* _application, JNIEnv* _env, jclass _classBase, jobject _objCallback, enum application _typeAPPL) :
|
||||
gale::Context(_application),
|
||||
m_javaApplicationType(_typeAPPL),
|
||||
m_JavaVirtualMachinePointer(nullptr),
|
||||
m_JavaVirtualMachinePointer(null),
|
||||
m_javaClassGale(0),
|
||||
m_javaClassGaleCallback(0),
|
||||
m_javaObjectGaleCallback(0),
|
||||
@ -87,21 +89,21 @@ class AndroidContext : public gale::Context {
|
||||
GALE_DEBUG("*******************************************");
|
||||
m_JavaVirtualMachinePointer = _env;
|
||||
// get default needed all time elements :
|
||||
if (nullptr != m_JavaVirtualMachinePointer) {
|
||||
if (null != m_JavaVirtualMachinePointer) {
|
||||
GALE_DEBUG("C->java : try load org/gale/Gale class");
|
||||
m_javaClassGale = m_JavaVirtualMachinePointer->FindClass("org/gale/Gale" );
|
||||
if (m_javaClassGale == 0) {
|
||||
GALE_ERROR("C->java : Can't find org/gale/Gale class");
|
||||
// remove access on the virtual machine :
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
m_JavaVirtualMachinePointer = null;
|
||||
return;
|
||||
}
|
||||
/* The object field extends Activity and implement GaleCallback */
|
||||
m_javaClassGaleCallback = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback);
|
||||
if(m_javaClassGaleCallback == nullptr) {
|
||||
if(m_javaClassGaleCallback == null) {
|
||||
GALE_ERROR("C->java : Can't find org/gale/GaleCallback class");
|
||||
// remove access on the virtual machine :
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
m_JavaVirtualMachinePointer = null;
|
||||
return;
|
||||
}
|
||||
bool functionCallbackIsMissing = false;
|
||||
@ -187,7 +189,7 @@ class AndroidContext : public gale::Context {
|
||||
|
||||
m_javaObjectGaleCallback = _env->NewGlobalRef(_objCallback);
|
||||
//javaObjectGaleCallbackAndActivity = objCallback;
|
||||
if (m_javaObjectGaleCallback == nullptr) {
|
||||
if (m_javaObjectGaleCallback == null) {
|
||||
functionCallbackIsMissing = true;
|
||||
}
|
||||
|
||||
@ -195,7 +197,7 @@ class AndroidContext : public gale::Context {
|
||||
if (m_javaDefaultClassString == 0) {
|
||||
GALE_ERROR("C->java : Can't find java/lang/String" );
|
||||
// remove access on the virtual machine :
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
m_JavaVirtualMachinePointer = null;
|
||||
functionCallbackIsMissing = true;
|
||||
}
|
||||
if (functionCallbackIsMissing == true) {
|
||||
@ -210,7 +212,7 @@ class AndroidContext : public gale::Context {
|
||||
|
||||
void unInit(JNIEnv* _env) {
|
||||
_env->DeleteGlobalRef(m_javaObjectGaleCallback);
|
||||
m_javaObjectGaleCallback = nullptr;
|
||||
m_javaObjectGaleCallback = null;
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
@ -289,9 +291,9 @@ class AndroidContext : public gale::Context {
|
||||
private:
|
||||
bool java_attach_current_thread(int *_rstatus) {
|
||||
GALE_DEBUG("C->java : call java");
|
||||
if (jvm_basics::getJavaVM() == nullptr) {
|
||||
if (jvm_basics::getJavaVM() == null) {
|
||||
GALE_ERROR("C->java : JVM not initialised");
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
m_JavaVirtualMachinePointer = null;
|
||||
return false;
|
||||
}
|
||||
*_rstatus = jvm_basics::getJavaVM()->GetEnv((void **) &m_JavaVirtualMachinePointer, JNI_VERSION_1_6);
|
||||
@ -299,12 +301,12 @@ class AndroidContext : public gale::Context {
|
||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
||||
lJavaVMAttachArgs.name = "GaleNativeThread";
|
||||
lJavaVMAttachArgs.group = nullptr;
|
||||
lJavaVMAttachArgs.group = null;
|
||||
int status = jvm_basics::getJavaVM()->AttachCurrentThread(&m_JavaVirtualMachinePointer, &lJavaVMAttachArgs);
|
||||
jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer);
|
||||
if (status != JNI_OK) {
|
||||
GALE_ERROR("C->java : AttachCurrentThread failed : " << status);
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
m_JavaVirtualMachinePointer = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -314,7 +316,7 @@ class AndroidContext : public gale::Context {
|
||||
void java_detach_current_thread(int _status) {
|
||||
if(_status == JNI_EDETACHED) {
|
||||
jvm_basics::getJavaVM()->DetachCurrentThread();
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
m_JavaVirtualMachinePointer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +357,7 @@ class AndroidContext : public gale::Context {
|
||||
java_detach_current_thread(status);
|
||||
}
|
||||
|
||||
void setTitle(const std::string& _title) {
|
||||
void setTitle(const etk::String& _title) {
|
||||
GALE_DEBUG("C->java : send message to the java : \"" << _title << "\"");
|
||||
if (m_javaApplicationType == appl_application) {
|
||||
int status;
|
||||
@ -374,7 +376,7 @@ class AndroidContext : public gale::Context {
|
||||
}
|
||||
}
|
||||
|
||||
void openURL(const std::string& _url) {
|
||||
void openURL(const etk::String& _url) {
|
||||
GALE_DEBUG("C->java : send message to the java : open URL'" << _url << "'");
|
||||
int status;
|
||||
if(!java_attach_current_thread(&status)) {
|
||||
@ -396,7 +398,7 @@ class AndroidContext : public gale::Context {
|
||||
return;
|
||||
}
|
||||
GALE_DEBUG("C->java : 222");
|
||||
if (nullptr == _dataString) {
|
||||
if (null == _dataString) {
|
||||
GALE_ERROR("C->java : No data to send ...");
|
||||
return;
|
||||
}
|
||||
@ -464,14 +466,34 @@ class AndroidContext : public gale::Context {
|
||||
}
|
||||
|
||||
void OS_Resize(const vec2& _size) {
|
||||
GALE_VERBOSE("OS_Resize [BEGIN]");
|
||||
GALE_INFO("OS_Resize [BEGIN]");
|
||||
m_currentHeight = _size.y();
|
||||
gale::Context::OS_Resize(_size);
|
||||
GALE_VERBOSE("OS_Resize [END]");
|
||||
GALE_INFO("OS_Resize [END]");
|
||||
}
|
||||
void ANDROID_start() {
|
||||
GALE_INFO("ANDROID_start [BEGIN]");
|
||||
|
||||
GALE_INFO("ANDROID_start [END]");
|
||||
}
|
||||
void ANDROID_reStart() {
|
||||
GALE_INFO("ANDROID_reStart [BEGIN]");
|
||||
|
||||
GALE_INFO("ANDROID_reStart [END]");
|
||||
}
|
||||
void ANDROID_create() {
|
||||
GALE_INFO("ANDROID_create [BEGIN]");
|
||||
start2ndThreadProcessing();
|
||||
GALE_INFO("ANDROID_create [END]");
|
||||
}
|
||||
void ANDROID_destroy() {
|
||||
GALE_INFO("ANDROID_destroy [BEGIN]");
|
||||
|
||||
GALE_INFO("ANDROID_destroy [END]");
|
||||
}
|
||||
};
|
||||
|
||||
static std::vector<AndroidContext*> s_listInstance;
|
||||
static etk::Vector<AndroidContext*> s_listInstance;
|
||||
gale::Application* s_applicationInit = NULL;
|
||||
|
||||
extern "C" {
|
||||
@ -482,10 +504,10 @@ extern "C" {
|
||||
jint _mode,
|
||||
jstring _myString,
|
||||
jstring _applicationName) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -500,12 +522,12 @@ extern "C" {
|
||||
if (isCopy == JNI_TRUE) {
|
||||
// from here str is reset ...
|
||||
_env->ReleaseStringUTFChars(_myString, str);
|
||||
str = nullptr;
|
||||
str = null;
|
||||
}
|
||||
if (isCopy2 == JNI_TRUE) {
|
||||
// from here str is reset ...
|
||||
_env->ReleaseStringUTFChars(_applicationName, str2);
|
||||
str2 = nullptr;
|
||||
str2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -515,59 +537,59 @@ extern "C" {
|
||||
jclass _classBase,
|
||||
jobject _objCallback,
|
||||
int _typeApplication) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Creating GALE context **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
AndroidContext* tmpContext = nullptr;
|
||||
AndroidContext* tmpContext = null;
|
||||
s_applicationInit = NULL;
|
||||
gale::Application* localApplication = NULL;
|
||||
// call the basic init of all application (that call us ...)
|
||||
main(0,NULL);
|
||||
main(0, NULL);
|
||||
localApplication = s_applicationInit;
|
||||
s_applicationInit = NULL;
|
||||
if (org_gale_GaleConstants_GALE_APPL_TYPE_ACTIVITY == _typeApplication) {
|
||||
tmpContext = new AndroidContext(localApplication, _env, _classBase, _objCallback, AndroidContext::appl_application);
|
||||
tmpContext = ETK_NEW(AndroidContext, localApplication, _env, _classBase, _objCallback, AndroidContext::appl_application);
|
||||
} else if (org_gale_GaleConstants_GALE_APPL_TYPE_WALLPAPER == _typeApplication) {
|
||||
tmpContext = new AndroidContext(localApplication, _env, _classBase, _objCallback, AndroidContext::appl_wallpaper);
|
||||
tmpContext = ETK_NEW(AndroidContext, localApplication, _env, _classBase, _objCallback, AndroidContext::appl_wallpaper);
|
||||
} else {
|
||||
GALE_CRITICAL(" try to create an instance with no apply type: " << _typeApplication);
|
||||
return -1;
|
||||
}
|
||||
if (nullptr == tmpContext) {
|
||||
if (tmpContext == null) {
|
||||
GALE_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.size()-1));
|
||||
return -1;
|
||||
}
|
||||
// for future case : all time this ...
|
||||
s_listInstance.push_back(tmpContext);
|
||||
s_listInstance.pushBack(tmpContext);
|
||||
int32_t newID = s_listInstance.size()-1;
|
||||
return newID;
|
||||
}
|
||||
|
||||
void Java_org_gale_Gale_EWsetJavaVirtualMachineStop(JNIEnv* _env, jclass _cls, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** remove JVM Pointer **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0) {
|
||||
|| _id < 0) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
return;
|
||||
}
|
||||
if (nullptr == s_listInstance[_id]) {
|
||||
if (s_listInstance[_id] == null) {
|
||||
GALE_ERROR("the requested instance _id=" << (int32_t)_id << " is already removed ...");
|
||||
return;
|
||||
}
|
||||
s_listInstance[_id]->unInit(_env);
|
||||
delete(s_listInstance[_id]);
|
||||
s_listInstance[_id]=nullptr;
|
||||
ETK_DELETE(AndroidContext, s_listInstance[_id]);
|
||||
s_listInstance[_id]=null;
|
||||
}
|
||||
void Java_org_gale_Gale_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG(" == > Touch Event");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -576,55 +598,58 @@ extern "C" {
|
||||
}
|
||||
|
||||
void Java_org_gale_Gale_EWonCreate(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Activity on Create **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
}
|
||||
s_listInstance[_id]->ANDROID_create();
|
||||
//s_listInstance[_id]->init();
|
||||
}
|
||||
|
||||
void Java_org_gale_Gale_EWonStart(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Activity on Start **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id]== null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
}
|
||||
s_listInstance[_id]->ANDROID_start();
|
||||
//SendSystemMessage(" testmessages ... ");
|
||||
}
|
||||
void Java_org_gale_Gale_EWonReStart(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Activity on Re-Start **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
}
|
||||
s_listInstance[_id]->ANDROID_reStart();
|
||||
}
|
||||
void Java_org_gale_Gale_EWonResume(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Activity on resume **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -632,13 +657,13 @@ extern "C" {
|
||||
s_listInstance[_id]->OS_Resume();
|
||||
}
|
||||
void Java_org_gale_Gale_EWonPause(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Activity on pause **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -648,13 +673,13 @@ extern "C" {
|
||||
s_listInstance[_id]->OS_Suspend();
|
||||
}
|
||||
void Java_org_gale_Gale_EWonStop(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Activity on Stop **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -662,17 +687,18 @@ extern "C" {
|
||||
s_listInstance[_id]->OS_Stop();
|
||||
}
|
||||
void Java_org_gale_Gale_EWonDestroy(JNIEnv* _env, jobject _thiz, jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_DEBUG("*******************************************");
|
||||
GALE_DEBUG("** Activity on Destroy **");
|
||||
GALE_DEBUG("*******************************************");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
}
|
||||
s_listInstance[_id]->ANDROID_destroy();
|
||||
//s_listInstance[_id]->UnInit();
|
||||
}
|
||||
|
||||
@ -687,10 +713,10 @@ extern "C" {
|
||||
jint _pointerID,
|
||||
jfloat _x,
|
||||
jfloat _y) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == null) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -708,10 +734,10 @@ extern "C" {
|
||||
jboolean _isDown,
|
||||
jfloat _x,
|
||||
jfloat _y) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id < 0
|
||||
|| s_listInstance[_id] == nullptr ) {
|
||||
|| s_listInstance[_id] == null ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -728,10 +754,10 @@ extern "C" {
|
||||
jint _pointerID,
|
||||
jfloat _x,
|
||||
jfloat _y) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -749,10 +775,10 @@ extern "C" {
|
||||
jboolean _isDown,
|
||||
jfloat _x,
|
||||
jfloat _y) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -767,10 +793,10 @@ extern "C" {
|
||||
jobject _thiz,
|
||||
jint _id,
|
||||
jint _pointerID) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -783,10 +809,10 @@ extern "C" {
|
||||
jint _id,
|
||||
jint _type,
|
||||
jboolean _isdown) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -800,10 +826,10 @@ extern "C" {
|
||||
jint _id,
|
||||
jint _uniChar,
|
||||
jboolean _isdown) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -817,10 +843,10 @@ extern "C" {
|
||||
jint _id,
|
||||
jfloat _ratioX,
|
||||
jfloat _ratioY) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -835,10 +861,10 @@ extern "C" {
|
||||
jint _id,
|
||||
jint _keyVal,
|
||||
jboolean _isdown) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return false;
|
||||
@ -879,11 +905,11 @@ extern "C" {
|
||||
void Java_org_gale_Gale_EWrenderInit(JNIEnv* _env,
|
||||
jobject _thiz,
|
||||
jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_VERBOSE("Java_org_gale_Gale_EWrenderInit [BEGIN]");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -896,11 +922,11 @@ extern "C" {
|
||||
jint _id,
|
||||
jint _w,
|
||||
jint _h) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_VERBOSE("Java_org_gale_Gale_EWrenderResize [BEGIN]");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
@ -913,11 +939,11 @@ extern "C" {
|
||||
void Java_org_gale_Gale_EWrenderDraw(JNIEnv* _env,
|
||||
jobject _thiz,
|
||||
jint _id) {
|
||||
std::unique_lock<std::mutex> lock(g_interfaceMutex);
|
||||
ethread::UniqueLock lock(g_interfaceMutex);
|
||||
GALE_VERBOSE("Java_org_gale_Gale_EWrenderDraw [BEGIN]");
|
||||
if( _id >= (int32_t)s_listInstance.size()
|
||||
|| _id<0
|
||||
|| nullptr == s_listInstance[_id] ) {
|
||||
|| null == s_listInstance[_id] ) {
|
||||
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||
// TODO : generate error in java to stop the current instance
|
||||
return;
|
||||
|
29
gale/context/Android/Context.hpp
Normal file
29
gale/context/Android/Context.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if 0
|
||||
namespace gale {
|
||||
namespace context {
|
||||
namespace Android {
|
||||
/**
|
||||
* @brief Check if the backend can be instanciate
|
||||
* @return true if the backend is availlable (false otherwise)
|
||||
*/
|
||||
bool isBackendPresent();
|
||||
/**
|
||||
* @brief Create the context main intance
|
||||
* @param[in] _application pointer on the application
|
||||
* @param[in] _argc number of parameter
|
||||
* @param[in] _argv araay of pointer of each parameters
|
||||
* @return instance on the generic created context
|
||||
*/
|
||||
ememory::SharedPtr<gale::Context> createInstance(gale::Application* _application, int _argc, const char *_argv[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,12 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/os/Fifo.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
@ -14,20 +14,25 @@
|
||||
#include <gale/Application.hpp>
|
||||
#include <gale/context/clipBoard.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
// TODO : #include <gale/context/InputManager.hpp>
|
||||
#include <gale/context/Fps.hpp>
|
||||
#include <gale/Thread.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
#include <gale/orientation.hpp>
|
||||
#include <gale/context/clipBoard.hpp>
|
||||
#include <ethread/tools.hpp>
|
||||
#include <ethread/MutexRecursive.hpp>
|
||||
#include <echrono/Steady.hpp>
|
||||
|
||||
#define MAX_MANAGE_INPUT (15)
|
||||
|
||||
namespace gale {
|
||||
class Thread;
|
||||
class PeriodicThread;
|
||||
class Context {
|
||||
friend class gale::PeriodicThread;
|
||||
protected:
|
||||
std::recursive_mutex m_mutex;
|
||||
ethread::MutexRecursive m_mutex;
|
||||
ememory::SharedPtr<gale::Thread> m_periodicThread;
|
||||
private:
|
||||
ememory::SharedPtr<gale::Application> m_application; //!< Application handle
|
||||
public:
|
||||
@ -47,8 +52,13 @@ namespace gale {
|
||||
return m_resourceManager;
|
||||
};
|
||||
public:
|
||||
Context(gale::Application* _application, int32_t _argc=0, const char* _argv[]=nullptr);
|
||||
Context(gale::Application* _application, int32_t _argc=0, const char* _argv[]=null);
|
||||
virtual ~Context();
|
||||
/**
|
||||
* @brief StartProcessing (2nd thread).
|
||||
* @note to call when all the Context is started
|
||||
*/
|
||||
void start2ndThreadProcessing();
|
||||
protected:
|
||||
/**
|
||||
* @brief set the curent interface.
|
||||
@ -56,18 +66,18 @@ namespace gale {
|
||||
*/
|
||||
void lockContext();
|
||||
/**
|
||||
* @brief set the curent interface at nullptr.
|
||||
* @brief set the curent interface at null.
|
||||
* @note this un-lock the main mutex
|
||||
*/
|
||||
void unLockContext();
|
||||
private:
|
||||
protected:
|
||||
// simulation area:
|
||||
bool m_imulationActive;
|
||||
etk::FSNode m_simulationFile;
|
||||
bool m_simulationActive;
|
||||
etk::Uri m_simulationUri;
|
||||
ememory::SharedPtr<etk::io::Interface> m_simulationFile;
|
||||
private:
|
||||
echrono::Steady m_previousDisplayTime; // this is to limit framerate ... in case...
|
||||
// TODO : gale::context::InputManager m_input;
|
||||
etk::Fifo<std::function<void(gale::Context& _context)> > m_msgSystem;
|
||||
etk::Fifo<etk::Function<void(gale::Context& _context)> > m_msgSystem;
|
||||
bool m_displayFps;
|
||||
gale::context::Fps m_FpsSystemEvent;
|
||||
gale::context::Fps m_FpsSystemContext;
|
||||
@ -78,10 +88,10 @@ namespace gale {
|
||||
*/
|
||||
void processEvents();
|
||||
public:
|
||||
void postAction(std::function<void(gale::Context& _context)> _action);
|
||||
void postAction(etk::Function<void(gale::Context& _context)> _action);
|
||||
public:
|
||||
|
||||
virtual void setArchiveDir(int _mode, const char* _str, const char* _applName=nullptr);
|
||||
virtual void setArchiveDir(int _mode, const char* _str, const char* _applName=null);
|
||||
|
||||
virtual void OS_SetInput(enum gale::key::type _type,
|
||||
enum gale::key::status _status,
|
||||
@ -222,12 +232,12 @@ namespace gale {
|
||||
* @brief set the new title of the windows
|
||||
* @param[in] title New desired title
|
||||
*/
|
||||
virtual void setTitle(const std::string& _title);
|
||||
virtual void setTitle(const etk::String& _title);
|
||||
/**
|
||||
* @brief Open an URL on an eternal brother.
|
||||
* @param[in] _url URL to open.
|
||||
*/
|
||||
virtual void openURL(const std::string& _url) { };
|
||||
virtual void openURL(const etk::String& _url) { };
|
||||
/**
|
||||
* @brief force the screen orientation (availlable on portable elements ...
|
||||
* @param[in] _orientation Selected orientation.
|
||||
@ -253,19 +263,12 @@ namespace gale {
|
||||
* @brief set the Icon of the program
|
||||
* @param[in] _inputFile new filename icon of the curent program.
|
||||
*/
|
||||
virtual void setIcon(const std::string& _inputFile) { };
|
||||
virtual void setIcon(const etk::Uri& _inputFile) { };
|
||||
/**
|
||||
* @brief Enable or Disable the decoration on the Windows (availlable only on Desktop)
|
||||
* @param[in] _status "true" to enable decoration / false otherwise
|
||||
*/
|
||||
virtual void setWindowsDecoration(bool _status) {};
|
||||
/**
|
||||
* @brief get the curent time in micro-second
|
||||
* @note : must be implemented in all system OS implementation
|
||||
* @return The curent time of the process
|
||||
*/
|
||||
// TODO : REMOVE this ... deprecated since c++11
|
||||
static int64_t getTime();
|
||||
private:
|
||||
// TODO : set user argument here ....
|
||||
|
||||
@ -285,10 +288,11 @@ namespace gale {
|
||||
static int main(int _argc, const char *_argv[]);
|
||||
public:
|
||||
/**
|
||||
* @brief Special for init (main) set the start image when loading data
|
||||
* @param[in] _fileName Name of the image to load
|
||||
* @brief Internal API to run the processing of the event loop ...
|
||||
* @return The Exit value of the program
|
||||
* @note INTERNAL API
|
||||
*/
|
||||
void setInitImage(const std::string& _fileName);
|
||||
virtual int32_t run() = 0;
|
||||
};
|
||||
/**
|
||||
* @brief From everyware in the program, we can get the context inteface.
|
||||
@ -304,11 +308,11 @@ namespace gale {
|
||||
* @brief When a new thread is created, it is needed to register it in the gale context interface to permit to get the context associated on it ...
|
||||
* @param[in] _thread generic C++11 thread handle
|
||||
*/
|
||||
void contextRegisterThread(std::thread* _thread);
|
||||
void contextRegisterThread(ethread::Thread* _thread);
|
||||
/**
|
||||
* @brief Remove an associated thread
|
||||
* @param[in] _thread generic C++11 thread handle
|
||||
*/
|
||||
void contextUnRegisterThread(std::thread* _thread);
|
||||
void contextUnRegisterThread(ethread::Thread* _thread);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
#include <echrono/Steady.hpp>
|
||||
@ -25,6 +25,7 @@ namespace gale {
|
||||
echrono::Duration m_avg_idle;
|
||||
echrono::Duration m_max_idle;
|
||||
echrono::Steady m_ticTime;
|
||||
echrono::Steady m_lastDrawTime;
|
||||
bool m_display;
|
||||
bool m_drawingDone;
|
||||
const char * m_displayName;
|
||||
@ -46,7 +47,7 @@ namespace gale {
|
||||
m_drawingDone(false),
|
||||
m_displayName(_displayName),
|
||||
m_displayFPS(_displayFPS) {
|
||||
|
||||
m_lastDrawTime = echrono::Steady::now();
|
||||
}
|
||||
/**
|
||||
* @brief Destructor
|
||||
@ -80,13 +81,13 @@ namespace gale {
|
||||
GALE_PRINT(m_displayName << ": processTime: " << processTimeLocal);
|
||||
}
|
||||
if (m_drawingDone == true) {
|
||||
m_min = std::min(m_min, processTimeLocal);
|
||||
m_max = std::max(m_max, processTimeLocal);
|
||||
m_min = etk::min(m_min, processTimeLocal);
|
||||
m_max = etk::max(m_max, processTimeLocal);
|
||||
m_avg += processTimeLocal;
|
||||
m_drawingDone = false;
|
||||
} else {
|
||||
m_min_idle = std::min(m_min_idle, processTimeLocal);
|
||||
m_max_idle = std::max(m_max_idle, processTimeLocal);
|
||||
m_min_idle = etk::min(m_min_idle, processTimeLocal);
|
||||
m_max_idle = etk::max(m_max_idle, processTimeLocal);
|
||||
m_avg_idle += processTimeLocal;
|
||||
}
|
||||
}
|
||||
@ -104,18 +105,20 @@ namespace gale {
|
||||
if (m_display == true) {
|
||||
if (m_nbDisplayTime > 0) {
|
||||
GALE_PRINT(m_displayName << " : Active : "
|
||||
<< m_min << " "
|
||||
<< m_avg / m_nbDisplayTime << "ms "
|
||||
<< m_min << " | "
|
||||
<< m_avg / m_nbDisplayTime << " | "
|
||||
<< m_max << " ");
|
||||
}
|
||||
if (m_nbCallTime-m_nbDisplayTime>0) {
|
||||
GALE_PRINT(m_displayName << " : idle : "
|
||||
<< m_min_idle << " "
|
||||
<< m_avg_idle / (m_nbCallTime-m_nbDisplayTime) << "ms "
|
||||
<< m_min_idle << " | "
|
||||
<< m_avg_idle / (m_nbCallTime-m_nbDisplayTime) << " | "
|
||||
<< m_max_idle << " ");
|
||||
}
|
||||
if (m_displayFPS == true) {
|
||||
GALE_PRINT("FPS : " << m_nbDisplayTime << "/" << m_nbCallTime << "fps");
|
||||
float nbSeconds = (echrono::Steady::now() - m_lastDrawTime).toSeconds();
|
||||
m_lastDrawTime = echrono::Steady::now();
|
||||
GALE_PRINT("FPS : " << m_nbDisplayTime << "/" << m_nbCallTime << " frames ==> " << (float(m_nbDisplayTime)/nbSeconds) << "fps");
|
||||
}
|
||||
m_max = echrono::Duration(0);
|
||||
m_min = echrono::Duration(99999999,0);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include <gale/key/key.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
@ -18,10 +18,11 @@
|
||||
#include <gale/context/IOs/Interface.h>
|
||||
#include <gale/context/IOs/Context.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
}
|
||||
|
||||
#include <sys/times.h>
|
||||
#include <mach/clock.h>
|
||||
@ -35,6 +36,7 @@ public:
|
||||
MacOSInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv) {
|
||||
// nothing to do ...
|
||||
start2ndThreadProcessing();
|
||||
}
|
||||
|
||||
int32_t Run() {
|
||||
@ -122,25 +124,25 @@ public:
|
||||
_move,
|
||||
(_isDown==true?gale::key::status::down:gale::key::status::up));
|
||||
}
|
||||
void openURL(const std::string& _url) {
|
||||
void openURL(const etk::String& _url) {
|
||||
mm_openURL(_url.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
MacOSInterface* interface = nullptr;
|
||||
MacOSInterface* interface = null;
|
||||
|
||||
|
||||
|
||||
bool IOs::draw(bool _displayEveryTime) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return false;
|
||||
}
|
||||
return interface->MAC_Draw(_displayEveryTime);
|
||||
}
|
||||
|
||||
void IOs::resize(float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_Resize(_x, _y);
|
||||
@ -148,82 +150,82 @@ void IOs::resize(float _x, float _y) {
|
||||
|
||||
|
||||
void IOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetMouseState(_id, _isDown, _x, _y);
|
||||
}
|
||||
|
||||
void IOs::setMouseMotion(int32_t _id, float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetMouseMotion(_id, _x, _y);
|
||||
}
|
||||
|
||||
void IOs::setInputState(int32_t _id, bool _isDown, float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetInputState(_id, _isDown, _x, _y);
|
||||
}
|
||||
|
||||
void IOs::setInputMotion(int32_t _id, float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetInputMotion(_id, _x, _y);
|
||||
}
|
||||
|
||||
void IOs::setKeyboard(gale::key::Special _special, int32_t _unichar, bool _isDown, bool _isARepeateKey) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetKeyboard(_special, _unichar, _isDown, _isARepeateKey);
|
||||
}
|
||||
|
||||
void IOs::setKeyboardMove(gale::key::Special& _special, enum gale::key::keyboard _move, bool _isDown) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetKeyboardMove(_special, _move, _isDown);
|
||||
}
|
||||
|
||||
void IOs::start() {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
//interface->OS_Start();
|
||||
}
|
||||
|
||||
void IOs::resume() {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->OS_Resume();
|
||||
}
|
||||
|
||||
void IOs::suspend() {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->OS_Suspend();
|
||||
}
|
||||
|
||||
void IOs::stop() {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->OS_Stop();
|
||||
}
|
||||
void IOs::background() {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->OS_Background();
|
||||
}
|
||||
void IOs::foreground() {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->OS_Foreground();
|
||||
@ -231,7 +233,7 @@ void IOs::foreground() {
|
||||
|
||||
|
||||
static int l_argc = 0;
|
||||
static const char **l_argv = nullptr;
|
||||
static const char **l_argv = null;
|
||||
static gale::Application* l_application;
|
||||
/**
|
||||
* @brief Main of the program
|
||||
@ -249,20 +251,20 @@ int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
void IOs::createInterface() {
|
||||
etk::init(l_argc, l_argv);
|
||||
GALE_INFO("Create new interface");
|
||||
interface = new MacOSInterface(l_application, l_argc, l_argv);
|
||||
l_application = nullptr;
|
||||
if (nullptr == interface) {
|
||||
interface = ETK_NEW(MacOSInterface, l_application, l_argc, l_argv);
|
||||
l_application = null;
|
||||
if (interface == null) {
|
||||
GALE_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void IOs::releaseInterface() {
|
||||
if (interface != nullptr) {
|
||||
if (interface != null) {
|
||||
GALE_INFO("Remove interface");
|
||||
}
|
||||
delete(interface);
|
||||
interface = nullptr;
|
||||
ETK_DELETE(MacOSInterface, interface);
|
||||
interface = null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -32,3 +32,25 @@ namespace IOs {
|
||||
void suspend();
|
||||
}
|
||||
|
||||
#if 0
|
||||
namespace gale {
|
||||
namespace context {
|
||||
namespace ios {
|
||||
/**
|
||||
* @brief Check if the backend can be instanciate
|
||||
* @return true if the backend is availlable (false otherwise)
|
||||
*/
|
||||
bool isBackendPresent();
|
||||
/**
|
||||
* @brief Create the context main intance
|
||||
* @param[in] _application pointer on the application
|
||||
* @param[in] _argc number of parameter
|
||||
* @param[in] _argv araay of pointer of each parameters
|
||||
* @return instance on the generic created context
|
||||
*/
|
||||
ememory::SharedPtr<gale::Context> createInstance(gale::Application* _application, int _argc, const char *_argv[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
@ -11,7 +11,10 @@
|
||||
#include <gale/context/InputManager.hpp>
|
||||
#include <gale/Application.hpp>
|
||||
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::context::InputManager);
|
||||
ETK_DECLARE_TYPE(gale::context::InputPoperty);
|
||||
ETK_DECLARE_TYPE(gale::context::InputLimit);
|
||||
|
||||
#define EVENT_DEBUG GALE_VERBOSE
|
||||
//#define EVENT_DEBUG GALE_DEBUG
|
||||
@ -34,7 +37,7 @@ bool gale::context::InputManager::localEventInput(enum gale::key::type _type,
|
||||
int32_t _IdInput,
|
||||
enum gale::key::status _status,
|
||||
vec2 _pos) {
|
||||
if (nullptr != _destApplication) {
|
||||
if (null != _destApplication) {
|
||||
if (_type == gale::key::typeMouse || _type == gale::key::typeFinger) {
|
||||
// create the system Event :
|
||||
gale::event::InputSystem tmpEventSystem(_type, _status, _IdInput, _pos, _destApplication, 0, m_specialKey); // TODO : set the real ID ...
|
||||
@ -50,7 +53,7 @@ bool gale::context::InputManager::localEventInput(enum gale::key::type _type,
|
||||
void gale::context::InputManager::abortElement(InputPoperty *_eventTable,
|
||||
int32_t _idInput,
|
||||
enum gale::key::type _type) {
|
||||
if (nullptr == _eventTable) {
|
||||
if (null == _eventTable) {
|
||||
return;
|
||||
}
|
||||
if (_eventTable[_idInput].isUsed == true) {
|
||||
@ -64,7 +67,7 @@ void gale::context::InputManager::abortElement(InputPoperty *_eventTable,
|
||||
|
||||
void gale::context::InputManager::cleanElement(InputPoperty *_eventTable,
|
||||
int32_t _idInput) {
|
||||
if (nullptr == _eventTable) {
|
||||
if (null == _eventTable) {
|
||||
return;
|
||||
}
|
||||
//GALE_INFO("CleanElement[" << idInput << "] = @" << (int64_t)eventTable);
|
||||
@ -109,7 +112,7 @@ int32_t gale::context::InputManager::localGetDestinationId(enum gale::key::type
|
||||
ememory::SharedPtr<gale::Application> tmpApplication = m_eventInputSaved[iii].curentApplicationEvent.lock();
|
||||
if (tmpApplication == _destApplication) {
|
||||
if (iii != _realInputId) {
|
||||
lastMinimum = std::max(lastMinimum, m_eventInputSaved[iii].destinationInputId);
|
||||
lastMinimum = etk::max(lastMinimum, m_eventInputSaved[iii].destinationInputId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,7 +131,7 @@ void gale::context::InputManager::motion(enum gale::key::type _type,
|
||||
// reject pointer == > out of IDs...
|
||||
return;
|
||||
}
|
||||
InputPoperty *eventTable = nullptr;
|
||||
InputPoperty *eventTable = null;
|
||||
if (_type == gale::key::typeMouse) {
|
||||
eventTable = m_eventMouseSaved;
|
||||
} else if (_type == gale::key::typeFinger) {
|
||||
@ -148,11 +151,11 @@ void gale::context::InputManager::motion(enum gale::key::type _type,
|
||||
// this event is all time on the good Application ... and manage the enter and leave ...
|
||||
// NOTE : the "layer Application" force us to get the Application at the specific position all the time :
|
||||
ememory::SharedPtr<gale::Application> tmpApplication;
|
||||
if (m_grabApplication.lock() != nullptr) {
|
||||
if (m_grabApplication.lock() != null) {
|
||||
// grab all events ...
|
||||
tmpApplication = m_grabApplication.lock();
|
||||
} else {
|
||||
if (nullptr != tmpWindows) {
|
||||
if (null != tmpWindows) {
|
||||
tmpApplication = tmpWindows->getApplicationAtPos(_pos);
|
||||
}
|
||||
}
|
||||
@ -176,7 +179,7 @@ void gale::context::InputManager::motion(enum gale::key::type _type,
|
||||
eventTable[_pointerID].isInside = true;
|
||||
// get destination Application :
|
||||
eventTable[_pointerID].curentApplicationEvent = tmpApplication;
|
||||
if (tmpApplication == nullptr) {
|
||||
if (tmpApplication == null) {
|
||||
eventTable[_pointerID].isInside = false;
|
||||
} else {
|
||||
eventTable[_pointerID].origin = tmpApplication->getOrigin();
|
||||
@ -259,7 +262,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
|
||||
}
|
||||
EVENT_DEBUG("event pointerId=" << _pointerID);
|
||||
// convert position in open-GL coordonates ...
|
||||
InputPoperty *eventTable = nullptr;
|
||||
InputPoperty *eventTable = null;
|
||||
InputLimit localLimit;
|
||||
if (_type == gale::key::typeMouse) {
|
||||
eventTable = m_eventMouseSaved;
|
||||
@ -317,8 +320,8 @@ void gale::context::InputManager::state(enum gale::key::type _type,
|
||||
eventTable[_pointerID].isInside = true;
|
||||
ememory::SharedPtr<gale::Application> tmpApplication = m_grabApplication.lock();
|
||||
// get destination Application :
|
||||
if(nullptr != tmpWindows) {
|
||||
if ( tmpApplication != nullptr
|
||||
if(null != tmpWindows) {
|
||||
if ( tmpApplication != null
|
||||
&& _type == gale::key::typeMouse) {
|
||||
eventTable[_pointerID].curentApplicationEvent = tmpApplication;
|
||||
} else {
|
||||
@ -328,7 +331,7 @@ void gale::context::InputManager::state(enum gale::key::type _type,
|
||||
eventTable[_pointerID].curentApplicationEvent.reset();
|
||||
}
|
||||
tmpApplication = eventTable[_pointerID].curentApplicationEvent.lock();
|
||||
if (tmpApplication != nullptr) {
|
||||
if (tmpApplication != null) {
|
||||
eventTable[_pointerID].origin = tmpApplication->getOrigin();
|
||||
eventTable[_pointerID].size = tmpApplication->getSize();
|
||||
eventTable[_pointerID].destinationInputId = localGetDestinationId(_type, tmpApplication, _pointerID);
|
||||
@ -378,14 +381,14 @@ void gale::context::InputManager::state(enum gale::key::type _type,
|
||||
// save start time
|
||||
eventTable[_pointerID].lastTimeEvent = currentTime;
|
||||
int32_t nbClickMax = 0;
|
||||
if(tmpApplication != nullptr) {
|
||||
if(tmpApplication != null) {
|
||||
nbClickMax = tmpApplication->getMouseLimit();
|
||||
if (nbClickMax>5) {
|
||||
nbClickMax = 5;
|
||||
}
|
||||
}
|
||||
// in grab mode the single to quinte event are not generated ....
|
||||
if( ( m_grabApplication.lock() == nullptr
|
||||
if( ( m_grabApplication.lock() == null
|
||||
|| _type != gale::key::typeMouse )
|
||||
&& eventTable[_pointerID].nbClickEvent < nbClickMax) {
|
||||
// generate event SINGLE :
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <gale/key/key.hpp>
|
||||
#include <ememory/SharedPtr.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
|
||||
namespace MacOs {
|
||||
// return true if a flush is needed
|
||||
@ -21,7 +23,27 @@ namespace MacOs {
|
||||
void setKeyboardMove(gale::key::Special& _keyboardMode, enum gale::key::keyboard _move, bool _isDown, bool _isAReapeateKey);
|
||||
void stopRequested();
|
||||
/*
|
||||
void setRedrawCallback(const std::function<void()>& _func);
|
||||
void setRedrawCallback(const etk::Function<void()>& _func);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
namespace gale {
|
||||
namespace context {
|
||||
namespace macos {
|
||||
/**
|
||||
* @brief Check if the backend can be instanciate
|
||||
* @return true if the backend is availlable (false otherwise)
|
||||
*/
|
||||
bool isBackendPresent();
|
||||
/**
|
||||
* @brief Create the context main intance
|
||||
* @param[in] _application pointer on the application
|
||||
* @param[in] _argc number of parameter
|
||||
* @param[in] _argv araay of pointer of each parameters
|
||||
* @return instance on the generic created context
|
||||
*/
|
||||
ememory::SharedPtr<gale::Context> createInstance(gale::Application* _application, int _argc, const char *_argv[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <gale/context/clipBoard.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
@ -38,9 +38,10 @@ class MacOSInterface : public gale::Context {
|
||||
MacOSInterface(gale::Application* _application, int _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv) {
|
||||
mm_main(_argc, _argv);
|
||||
start2ndThreadProcessing();
|
||||
}
|
||||
|
||||
int32_t Run() {
|
||||
int32_t run() {
|
||||
return mm_run();
|
||||
}
|
||||
public:
|
||||
@ -90,9 +91,9 @@ class MacOSInterface : public gale::Context {
|
||||
move = gale::key::keyboard::right;
|
||||
break;
|
||||
}
|
||||
OS_setKeyboard(_special, move, (_isDown==false?gale::key::status::down:gale::key::status::up), _isAReapeateKey);
|
||||
OS_setKeyboard(_special, move, (_isDown==true?gale::key::status::down:gale::key::status::up), _isAReapeateKey);
|
||||
} else {
|
||||
OS_setKeyboard(_special, gale::key::keyboard::character, (_isDown==false?gale::key::status::down:gale::key::status::up), _isAReapeateKey, _unichar);
|
||||
OS_setKeyboard(_special, gale::key::keyboard::character, (_isDown==true?gale::key::status::down:gale::key::status::up), _isAReapeateKey, _unichar);
|
||||
}
|
||||
}
|
||||
void MAC_SetKeyboardMove(gale::key::Special& _special,
|
||||
@ -101,8 +102,8 @@ class MacOSInterface : public gale::Context {
|
||||
bool _isAReapeateKey) {
|
||||
OS_setKeyboard(_special, _move, (_isDown==true?gale::key::status::down:gale::key::status::up), _isAReapeateKey);
|
||||
}
|
||||
void openURL(const std::string& _url) {
|
||||
std::string req = "open " + _url;
|
||||
void openURL(const etk::String& _url) {
|
||||
etk::String req = "open " + _url;
|
||||
system(req.c_str());
|
||||
}
|
||||
void MAC_Stop() {
|
||||
@ -115,7 +116,7 @@ class MacOSInterface : public gale::Context {
|
||||
if (_clipboardID == gale::context::clipBoard::clipboardStd) {
|
||||
NSPasteboard* myPasteboard = [NSPasteboard generalPasteboard];
|
||||
NSString* myString = [myPasteboard stringForType:NSPasteboardTypeString];
|
||||
std::string val([myString UTF8String]);
|
||||
etk::String val([myString UTF8String]);
|
||||
gale::context::clipBoard::setSystem(_clipboardID, val);
|
||||
if (val.size() != 0) {
|
||||
OS_ClipBoardArrive(_clipboardID);
|
||||
@ -142,19 +143,20 @@ class MacOSInterface : public gale::Context {
|
||||
};
|
||||
|
||||
|
||||
MacOSInterface* interface = nullptr;
|
||||
MacOSInterface* interface = null;
|
||||
|
||||
|
||||
|
||||
bool MacOs::draw(bool _displayEveryTime) {
|
||||
if (interface == nullptr) {
|
||||
GALE_VERBOSE("draw request " << uint64_t(interface) << " " << _displayEveryTime);
|
||||
if (interface == null) {
|
||||
return false;
|
||||
}
|
||||
return interface->MAC_Draw(_displayEveryTime);
|
||||
}
|
||||
|
||||
void MacOs::resize(float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_Resize(_x, _y);
|
||||
@ -162,70 +164,56 @@ void MacOs::resize(float _x, float _y) {
|
||||
|
||||
|
||||
void MacOs::setMouseState(int32_t _id, bool _isDown, float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetMouseState(_id, _isDown, _x, _y);
|
||||
}
|
||||
|
||||
void MacOs::setMouseMotion(int32_t _id, float _x, float _y) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetMouseMotion(_id, _x, _y);
|
||||
}
|
||||
|
||||
void MacOs::setKeyboard(gale::key::Special _keyboardMode, int32_t _unichar, bool _isDown, bool _isAReapeateKey) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetKeyboard(_keyboardMode, _unichar, _isDown, _isAReapeateKey);
|
||||
}
|
||||
|
||||
void MacOs::setKeyboardMove(gale::key::Special& _keyboardMode, enum gale::key::keyboard _move, bool _isDown, bool _isAReapeateKey) {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_SetKeyboardMove(_keyboardMode, _move, _isDown, _isAReapeateKey);
|
||||
}
|
||||
|
||||
void MacOs::stopRequested() {
|
||||
if (interface == nullptr) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->MAC_Stop();
|
||||
}
|
||||
/*
|
||||
void MacOs::setRedrawCallback(const std::function<void()>& _func) {
|
||||
if (interface == nullptr) {
|
||||
void MacOs::setRedrawCallback(const etk::Function<void()>& _func) {
|
||||
if (interface == null) {
|
||||
return;
|
||||
}
|
||||
interface->getWidgetManager().setCallbackonRedrawNeeded(_func);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* @brief Main of the program
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int gale::run(gale::Application* _application, int _argc, const char* _argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
interface = new MacOSInterface(_application, _argc, _argv);
|
||||
if (nullptr == interface) {
|
||||
GALE_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
|
||||
return -2;
|
||||
}
|
||||
|
||||
int32_t retValue = interface->Run();
|
||||
GALE_INFO("Stop running");
|
||||
delete(interface);
|
||||
interface = nullptr;
|
||||
return retValue;
|
||||
|
||||
|
||||
bool gale::context::macos::isBackendPresent() {
|
||||
// TODO : Do it better...
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ememory::SharedPtr<gale::Context> gale::context::macos::createInstance(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
ememory::SharedPtr<MacOSInterface> tmp = ememory::makeShared<MacOSInterface>(_application, _argc, _argv);
|
||||
interface = tmp.get();
|
||||
return tmp;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#include "Context.hpp"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@ -96,7 +96,7 @@ int mm_main(int _argc, const char* _argv[]) {
|
||||
}
|
||||
|
||||
int mm_run(void) {
|
||||
//MacOs::setRedrawCallback(std::bind(callbackSomeThingToDo));
|
||||
GALE_ERROR("Start to run");
|
||||
[NSApp run];
|
||||
GALE_DEBUG("END of application");
|
||||
// return no error
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
@ -1,13 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#import <gale/context/MacOs/OpenglView.hpp>
|
||||
#include <OpenGL/gl.h>
|
||||
#include <gale/context/MacOS/Context.hpp>
|
||||
#include <gale/context/MacOs/Context.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <gale/context/MacOs/OpenglView.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
|
||||
@interface GaleMainWindows : NSWindow {
|
||||
OpenGLView* _view;
|
||||
@ -32,6 +33,15 @@
|
||||
- (void)flagsChanged:(NSEvent *)theEvent;
|
||||
- (void)closeRequestGale;
|
||||
- (void)UpdateScreenRequested;
|
||||
/**
|
||||
* @brief Check if we have the need to change the internal flag of shift, ctrl ...
|
||||
* @param[in] bitField MacOs bit field
|
||||
* @param[in] flags Patern to check
|
||||
* @param[in] key Gale key
|
||||
*/
|
||||
- (void)flagsUpdate:(uint32_t) bitField
|
||||
:(uint32_t) flags
|
||||
:(enum gale::key::keyboard) key;
|
||||
@end
|
||||
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#import <gale/context/MacOs/Windows.hpp>
|
||||
#include <gale/context/MacOS/Context.hpp>
|
||||
#include <gale/context/MacOs/Context.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
@ -28,38 +28,27 @@
|
||||
GALE_DEBUG("INIT ...");
|
||||
// set the windows at a specific position :
|
||||
[windowsID cascadeTopLeftFromPoint:NSMakePoint(50,50)];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
// set the windows resizable
|
||||
#ifdef __MAC_10_12
|
||||
[windowsID setStyleMask:[windowsID styleMask] | NSWindowStyleMaskResizable];
|
||||
#else
|
||||
[windowsID setStyleMask:[windowsID styleMask] | NSResizableWindowMask];
|
||||
#endif
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
// oposite : [window setStyleMask:[window styleMask] & ~NSResizableWindowMask];
|
||||
// set the title
|
||||
id appName = [[NSProcessInfo processInfo] processName];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
[windowsID setTitle:appName];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
|
||||
[windowsID setAcceptsMouseMovedEvents:YES];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
// ???
|
||||
[windowsID makeKeyAndOrderFront:nil];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
|
||||
NSRect window_frame = [windowsID frame];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
|
||||
_view=[[OpenGLView alloc]initWithFrame:window_frame]; //NSMakeRect(0, 0, 800, 600)];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
[windowsID setContentView:_view];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
[_view setAutoresizesSubviews:YES];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
|
||||
// Override point for customization after application launch.
|
||||
//[window addSubview:view];
|
||||
@ -67,7 +56,6 @@
|
||||
//[window makeKeyAndVisible];
|
||||
|
||||
//[windowsID setDelegate:view];
|
||||
GALE_DEBUG("ALLOCATE ...");
|
||||
return windowsID;
|
||||
}
|
||||
|
||||
@ -84,32 +72,44 @@
|
||||
|
||||
static gale::key::Special guiKeyBoardMode;
|
||||
|
||||
static etk::Vector<etk::Pair<uint16_t,unichar>> g_listlasteventDown;
|
||||
|
||||
-(void)localKeyEvent:(NSEvent*)theEvent isDown:(bool)_isDown {
|
||||
bool thisIsAReapeateKey = false;
|
||||
if ([theEvent isARepeat]) {
|
||||
thisIsAReapeateKey = true;
|
||||
}
|
||||
//[self flagsChanged:theEvent];
|
||||
NSString *str = [theEvent charactersIgnoringModifiers];
|
||||
// TODO : set if for every char in the string !!!
|
||||
unichar c = [str characterAtIndex:0];
|
||||
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown);
|
||||
uint16_t keycode = [theEvent keyCode];
|
||||
// special case for \t + shift:
|
||||
if ( guiKeyBoardMode.getShift() == true
|
||||
&& c == 25) {
|
||||
// We remap it to the correct tabulation.
|
||||
c = 9;
|
||||
}
|
||||
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown << " keycode=" << keycode);
|
||||
bool find = true;
|
||||
enum gale::key::keyboard keyInput;
|
||||
switch (c) {
|
||||
case 63232: keyInput = gale::key::keyboard::up; break;
|
||||
case 63233: keyInput = gale::key::keyboard::down; break;
|
||||
case 63234: keyInput = gale::key::keyboard::left; break;
|
||||
case 63235: keyInput = gale::key::keyboard::right; break;
|
||||
case 63276: keyInput = gale::key::keyboard::pageUp; break;
|
||||
case 63277: keyInput = gale::key::keyboard::pageDown; break;
|
||||
case 63273: keyInput = gale::key::keyboard::start; break;
|
||||
case 63275: keyInput = gale::key::keyboard::end; break;
|
||||
/*
|
||||
case 78: keyInput = gale::key::keyboard::stopDefil; break;
|
||||
case 127: keyInput = gale::key::keyboard::wait; break;
|
||||
*/
|
||||
case NSUpArrowFunctionKey: keyInput = gale::key::keyboard::up; break;
|
||||
case NSDownArrowFunctionKey: keyInput = gale::key::keyboard::down; break;
|
||||
case NSLeftArrowFunctionKey: keyInput = gale::key::keyboard::left; break;
|
||||
case NSRightArrowFunctionKey: keyInput = gale::key::keyboard::right; break;
|
||||
case NSPageUpFunctionKey: keyInput = gale::key::keyboard::pageUp; break;
|
||||
case NSPageDownFunctionKey: keyInput = gale::key::keyboard::pageDown; break;
|
||||
case NSBeginFunctionKey:
|
||||
case NSHomeFunctionKey: keyInput = gale::key::keyboard::start; break;
|
||||
case NSEndFunctionKey: keyInput = gale::key::keyboard::end; break;
|
||||
case NSScrollLockFunctionKey: keyInput = gale::key::keyboard::stopDefil; break;
|
||||
case NSPauseFunctionKey: keyInput = gale::key::keyboard::wait; break;
|
||||
case NSPrintScreenFunctionKey: keyInput = gale::key::keyboard::print; break;
|
||||
case 16: keyInput = gale::key::keyboard::contextMenu; break;
|
||||
|
||||
case 63302:
|
||||
case NSInsertFunctionKey:
|
||||
find = false;
|
||||
keyInput = gale::key::keyboard::insert;
|
||||
if(_isDown == false) {
|
||||
@ -125,19 +125,44 @@ static gale::key::Special guiKeyBoardMode;
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, keyInput, false, thisIsAReapeateKey);
|
||||
break;
|
||||
//case 84: keyInput = gale::key::keyboardCenter; break; // Keypad
|
||||
case 63236: keyInput = gale::key::keyboard::f1; break;
|
||||
case 63237: keyInput = gale::key::keyboard::f2; break;
|
||||
case 63238: keyInput = gale::key::keyboard::f3; break;
|
||||
case 63239: keyInput = gale::key::keyboard::f4; break;
|
||||
case 63240: keyInput = gale::key::keyboard::f5; break;
|
||||
case 63241: keyInput = gale::key::keyboard::f6; break;
|
||||
case 63242: keyInput = gale::key::keyboard::f7; break;
|
||||
case 63243: keyInput = gale::key::keyboard::f8; break;
|
||||
case 63244: keyInput = gale::key::keyboard::f9; break;
|
||||
case 63245: keyInput = gale::key::keyboard::f10; break;
|
||||
case 63246: keyInput = gale::key::keyboard::f11; break;
|
||||
case 63247: keyInput = gale::key::keyboard::f12; break;
|
||||
case 63272: // Suppress
|
||||
case NSF1FunctionKey: keyInput = gale::key::keyboard::f1; break;
|
||||
case NSF2FunctionKey: keyInput = gale::key::keyboard::f2; break;
|
||||
case NSF3FunctionKey: keyInput = gale::key::keyboard::f3; break;
|
||||
case NSF4FunctionKey: keyInput = gale::key::keyboard::f4; break;
|
||||
case NSF5FunctionKey: keyInput = gale::key::keyboard::f5; break;
|
||||
case NSF6FunctionKey: keyInput = gale::key::keyboard::f6; break;
|
||||
case NSF7FunctionKey: keyInput = gale::key::keyboard::f7; break;
|
||||
case NSF8FunctionKey: keyInput = gale::key::keyboard::f8; break;
|
||||
case NSF9FunctionKey: keyInput = gale::key::keyboard::f9; break;
|
||||
case NSF10FunctionKey: keyInput = gale::key::keyboard::f10; break;
|
||||
case NSF11FunctionKey: keyInput = gale::key::keyboard::f11; break;
|
||||
case NSF12FunctionKey: keyInput = gale::key::keyboard::f12; break;
|
||||
case NSF13FunctionKey:
|
||||
case NSF14FunctionKey:
|
||||
case NSF15FunctionKey:
|
||||
case NSF16FunctionKey:
|
||||
case NSF17FunctionKey:
|
||||
case NSF18FunctionKey:
|
||||
case NSF19FunctionKey:
|
||||
case NSF20FunctionKey:
|
||||
case NSF21FunctionKey:
|
||||
case NSF22FunctionKey:
|
||||
case NSF23FunctionKey:
|
||||
case NSF24FunctionKey:
|
||||
case NSF25FunctionKey:
|
||||
case NSF26FunctionKey:
|
||||
case NSF27FunctionKey:
|
||||
case NSF28FunctionKey:
|
||||
case NSF29FunctionKey:
|
||||
case NSF30FunctionKey:
|
||||
case NSF31FunctionKey:
|
||||
case NSF32FunctionKey:
|
||||
case NSF33FunctionKey:
|
||||
case NSF34FunctionKey:
|
||||
case NSF35FunctionKey:
|
||||
find = false;
|
||||
break;
|
||||
case NSDeleteFunctionKey: // Suppress
|
||||
find = false;
|
||||
MacOs::setKeyboard(guiKeyBoardMode, u32char::Delete, _isDown, thisIsAReapeateKey);
|
||||
if (true == thisIsAReapeateKey) {
|
||||
@ -151,10 +176,36 @@ static gale::key::Special guiKeyBoardMode;
|
||||
// special keyboard transcription ...
|
||||
str = [theEvent characters];
|
||||
c = [str characterAtIndex:0];
|
||||
GALE_VERBOSE("Key Event ALT " << c << " = '" << char(c) << "' isDown=" << _isDown << " nb in list=" << g_listlasteventDown.size());
|
||||
} else {
|
||||
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown);
|
||||
}
|
||||
// MacOs have a problem of synchronizing the correct key with the modifier...
|
||||
if (_isDown == false) {
|
||||
for (auto it = g_listlasteventDown.begin();
|
||||
it != g_listlasteventDown.end();
|
||||
++it) {
|
||||
if (it->first == keycode) {
|
||||
c = it->second;
|
||||
g_listlasteventDown.erase(it);
|
||||
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown << " (override)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// remove a previous occurence of this element (case where Macos does not send the UP)...
|
||||
for (auto it = g_listlasteventDown.begin();
|
||||
it != g_listlasteventDown.end();
|
||||
++it) {
|
||||
if (it->first == keycode) {
|
||||
g_listlasteventDown.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_listlasteventDown.push_back(etk::makePair(keycode, c));
|
||||
}
|
||||
GALE_VERBOSE("Key Event " << c << " = '" << char(c) << "' isDown=" << _isDown);
|
||||
MacOs::setKeyboard(guiKeyBoardMode, c, _isDown, thisIsAReapeateKey);
|
||||
if (true==thisIsAReapeateKey) {
|
||||
if (thisIsAReapeateKey == true) {
|
||||
MacOs::setKeyboard(guiKeyBoardMode, c, !_isDown, thisIsAReapeateKey);
|
||||
}
|
||||
}
|
||||
@ -178,127 +229,76 @@ static gale::key::Special guiKeyBoardMode;
|
||||
[self localKeyEvent:theEvent isDown:false];
|
||||
}
|
||||
|
||||
- (void)flagsUpdate:(uint32_t) bitField
|
||||
:(uint32_t) flags
|
||||
:(enum gale::key::keyboard) key {
|
||||
if ((bitField & flags) != 0) {
|
||||
GALE_VERBOSE("Flag change: " << key);
|
||||
if (guiKeyBoardMode.get(key) == false) {
|
||||
GALE_VERBOSE(" " << key << " DOWN");
|
||||
guiKeyBoardMode.update(key, true);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, key, true, false);
|
||||
}
|
||||
} else {
|
||||
if (guiKeyBoardMode.get(key) == true) {
|
||||
GALE_VERBOSE(" " << key << " UP");
|
||||
guiKeyBoardMode.update(key, false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, key, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)theEvent {
|
||||
uint32_t bitField = [theEvent modifierFlags];
|
||||
GALE_VERBOSE("flagsChanged : " << etk::toBin([theEvent modifierFlags], 32));
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagCapsLock) != 0) {
|
||||
[self flagsUpdate:bitField: NSEventModifierFlagCapsLock: gale::key::keyboard::capLock];
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSAlphaShiftKeyMask) != 0) {
|
||||
[self flagsUpdate:bitField: NSAlphaShiftKeyMask: gale::key::keyboard::capLock];
|
||||
#endif
|
||||
GALE_VERBOSE("NSEventModifierFlagCapsLock");
|
||||
if (guiKeyBoardMode.getCapsLock() == false) {
|
||||
guiKeyBoardMode.setCapsLock(true);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::capLock, true, false);
|
||||
}
|
||||
} else {
|
||||
if (guiKeyBoardMode.getCapsLock() == true) {
|
||||
guiKeyBoardMode.setCapsLock(false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::capLock, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagShift) != 0) {
|
||||
//[self flagsUpdate:bitField: NSEventModifierFlagShift: gale::key::keyboard::shiftLeft];
|
||||
[self flagsUpdate:bitField: 0x02: gale::key::keyboard::shiftLeft];
|
||||
[self flagsUpdate:bitField: 0x04: gale::key::keyboard::shiftRight];
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSShiftKeyMask) != 0) {
|
||||
[self flagsUpdate:bitField: NSShiftKeyMask: gale::key::keyboard::shiftLeft];
|
||||
#endif
|
||||
GALE_VERBOSE("NSEventModifierFlagShift");
|
||||
if (guiKeyBoardMode.getShift() == false) {
|
||||
guiKeyBoardMode.setShift(true);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::shiftLeft, true, false);
|
||||
}
|
||||
} else {
|
||||
if (guiKeyBoardMode.getShift() == true) {
|
||||
guiKeyBoardMode.setShift(false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::shiftLeft, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagControl) != 0) {
|
||||
//[self flagsUpdate:bitField: NSEventModifierFlagControl: gale::key::keyboard::ctrlLeft];
|
||||
[self flagsUpdate:bitField: 0x0001: gale::key::keyboard::ctrlLeft];
|
||||
[self flagsUpdate:bitField: 0x2000: gale::key::keyboard::ctrlRight];
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSControlKeyMask) != 0) {
|
||||
[self flagsUpdate:bitField: NSControlKeyMask: gale::key::keyboard::ctrlLeft];
|
||||
#endif
|
||||
//GALE_VERBOSE("NSEventModifierFlagControl");
|
||||
if (guiKeyBoardMode.getCtrl() == false) {
|
||||
GALE_VERBOSE("NSEventModifierFlagControl DOWN");
|
||||
guiKeyBoardMode.setCtrl(true);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::ctrlLeft, true, false);
|
||||
}
|
||||
} else {
|
||||
if (guiKeyBoardMode.getCtrl() == true) {
|
||||
GALE_VERBOSE("NSEventModifierFlagControl UP");
|
||||
guiKeyBoardMode.setCtrl(false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::ctrlLeft, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagOption) != 0) {
|
||||
//[self flagsUpdate:bitField: NSEventModifierFlagOption: gale::key::keyboard::altLeft];
|
||||
[self flagsUpdate:bitField: 0x0020: gale::key::keyboard::altLeft];
|
||||
[self flagsUpdate:bitField: 0x0040: gale::key::keyboard::altRight];
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSAlternateKeyMask) != 0) {
|
||||
[self flagsUpdate:bitField: NSAlternateKeyMask: gale::key::keyboard::altLeft];
|
||||
#endif
|
||||
GALE_VERBOSE("NSEventModifierFlagOption");
|
||||
if (guiKeyBoardMode.getAlt() == false) {
|
||||
guiKeyBoardMode.setAlt(true);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::alt, true, false);
|
||||
}
|
||||
} else {
|
||||
if (guiKeyBoardMode.getAlt() == true) {
|
||||
guiKeyBoardMode.setAlt(false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::alt, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagCommand) != 0) {
|
||||
//[self flagsUpdate:bitField: NSEventModifierFlagCommand: gale::key::keyboard::metaLeft];
|
||||
[self flagsUpdate:bitField: 0x0008: gale::key::keyboard::metaLeft];
|
||||
[self flagsUpdate:bitField: 0x0010: gale::key::keyboard::metaRight];
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSCommandKeyMask) != 0) {
|
||||
[self flagsUpdate:bitField: NSCommandKeyMask: gale::key::keyboard::metaLeft];
|
||||
#endif
|
||||
GALE_VERBOSE("NSEventModifierFlagCommand");
|
||||
if (guiKeyBoardMode.getMeta() == false) {
|
||||
guiKeyBoardMode.setMeta(true);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::metaLeft, true, false);
|
||||
}
|
||||
} else {
|
||||
if (guiKeyBoardMode.getMeta() == true) {
|
||||
guiKeyBoardMode.setMeta(false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::metaLeft, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagNumericPad) != 0) {
|
||||
[self flagsUpdate:bitField: NSEventModifierFlagNumericPad: gale::key::keyboard::numLock];
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSNumericPadKeyMask) != 0) {
|
||||
[self flagsUpdate:bitField: NSNumericPadKeyMask: gale::key::keyboard::numLock];
|
||||
#endif
|
||||
GALE_VERBOSE("NSEventModifierFlagNumericPad");
|
||||
if (guiKeyBoardMode.getNumLock() == false) {
|
||||
guiKeyBoardMode.setNumLock(true);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::numLock, true, false);
|
||||
}
|
||||
} else {
|
||||
if (guiKeyBoardMode.getNumLock() == true) {
|
||||
guiKeyBoardMode.setNumLock(false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::numLock, false, false);
|
||||
}
|
||||
}
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagHelp) != 0) {
|
||||
if ((bitField & NSEventModifierFlagFunction) != 0) {
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSHelpKeyMask) != 0) {
|
||||
#endif
|
||||
GALE_VERBOSE("NSEventModifierFlagHelp");
|
||||
}
|
||||
#ifdef __MAC_10_12
|
||||
if (([theEvent modifierFlags] & NSEventModifierFlagFunction) != 0) {
|
||||
#else
|
||||
if (([theEvent modifierFlags] & NSFunctionKeyMask) != 0) {
|
||||
if ((bitField & NSFunctionKeyMask) != 0) {
|
||||
#endif
|
||||
GALE_VERBOSE("NSEventModifierFlagFunction");
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::contextMenu, true, false);
|
||||
MacOs::setKeyboardMove(guiKeyBoardMode, gale::key::keyboard::contextMenu, false, false);
|
||||
}
|
||||
GALE_VERBOSE("EVENT : " << int32_t([theEvent modifierFlags]));
|
||||
GALE_VERBOSE(" ==> new state special: " << etk::to_string(guiKeyBoardMode));
|
||||
}
|
||||
|
||||
// this generate all the event entry availlable ==> like a big keep focus ...
|
||||
@ -311,46 +311,46 @@ static gale::key::Special guiKeyBoardMode;
|
||||
|
||||
-(void)mouseMoved:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_VERBOSE("mouseMoved : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("mouseMoved : " << float(point.x) << " " << (float)point.y);
|
||||
MacOs::setMouseMotion(0, point.x, point.y);
|
||||
}
|
||||
-(void)mouseEntered:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_INFO("mouseEntered : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("mouseEntered : " << float(point.x) << " " << (float)point.y);
|
||||
}
|
||||
-(void)mouseExited:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_INFO("mouseExited : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("mouseExited : " << float(point.x) << " " << float(point.y));
|
||||
}
|
||||
|
||||
-(void)mouseDown:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_VERBOSE("mouseDown : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("mouseDown : " << float(point.x) << " " << float(point.y));
|
||||
MacOs::setMouseState(1, true, point.x, point.y);
|
||||
}
|
||||
-(void)mouseDragged:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_VERBOSE("mouseDragged : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("mouseDragged : " << float(point.x) << " " << float(point.y));
|
||||
MacOs::setMouseMotion(1, point.x, point.y);
|
||||
}
|
||||
-(void)mouseUp:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_VERBOSE("mouseUp : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("mouseUp : " << float(point.x) << " " << float(point.y));
|
||||
MacOs::setMouseState(1, false, point.x, point.y);
|
||||
}
|
||||
-(void)rightMouseDown:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_VERBOSE("rightMouseDown : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("rightMouseDown : " << float(point.x) << " " << float(point.y));
|
||||
MacOs::setMouseState(3, true, point.x, point.y);
|
||||
}
|
||||
-(void)rightMouseDragged:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_VERBOSE("rightMouseDragged : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("rightMouseDragged : " << float(point.x) << " " << float(point.y));
|
||||
MacOs::setMouseMotion(3, point.x, point.y);
|
||||
}
|
||||
-(void)rightMouseUp:(NSEvent *)event {
|
||||
NSPoint point = [event locationInWindow];
|
||||
GALE_VERBOSE("rightMouseUp : " << (float)point.x << " " << (float)point.y);
|
||||
GALE_VERBOSE("rightMouseUp : " << float(point.x) << " " << float(point.y));
|
||||
MacOs::setMouseState(3, false, point.x, point.y);
|
||||
}
|
||||
-(void)otherMouseDown:(NSEvent *)event {
|
||||
|
335
gale/context/SDL/Context.cpp
Normal file
335
gale/context/SDL/Context.cpp
Normal file
@ -0,0 +1,335 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
}
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
#include <emscripten.h>
|
||||
|
||||
bool hasDisplay = false;
|
||||
#define DEBUG_GLUT_EVENT
|
||||
#ifdef DEBUG_GLUT_EVENT
|
||||
#define GLUT_DEBUG GALE_DEBUG
|
||||
#define GLUT_VERBOSE GALE_VERBOSE
|
||||
#define GLUT_INFO GALE_INFO
|
||||
#define GLUT_CRITICAL GALE_CRITICAL
|
||||
#else
|
||||
#define GLUT_DEBUG GALE_VERBOSE
|
||||
#define GLUT_VERBOSE GALE_VERBOSE
|
||||
#define GLUT_INFO GALE_VERBOSE
|
||||
#define GLUT_CRITICAL GALE_VERBOSE
|
||||
#endif
|
||||
|
||||
#ifdef GALE_BUILD_EGAMI
|
||||
#include <egami/egami.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
class GLUTInterface : public gale::Context {
|
||||
private:
|
||||
gale::key::Special m_guiKeyBoardMode;
|
||||
int32_t m_originX;
|
||||
int32_t m_originY;
|
||||
vec2 m_cursorEventPos;
|
||||
vec2 m_currentSize;
|
||||
bool m_doubleBuffered;
|
||||
bool m_run;
|
||||
//forcing the position
|
||||
bool m_grabAllEvent; //!< grab mode enable...
|
||||
vec2 m_forcePos; //!< position to reset the cursor
|
||||
bool m_positionChangeRequested; //!< the position modifiquation has been requested
|
||||
vec2 m_curentGrabDelta; //!< the position in GLUT will arrive by pool
|
||||
bool m_inputIsPressed[MAX_MANAGE_INPUT];
|
||||
etk::String m_uniqueWindowsName;
|
||||
enum gale::context::cursor m_currentCursor; //!< select the current cursor to display :
|
||||
char32_t m_lastKeyPressed; //!< The last element key presed...
|
||||
public:
|
||||
GLUTInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv),
|
||||
m_originX(0),
|
||||
m_originY(0),
|
||||
m_cursorEventPos(0,0),
|
||||
m_currentSize(640,480),
|
||||
m_doubleBuffered(0),
|
||||
m_run(false),
|
||||
m_grabAllEvent(false),
|
||||
m_forcePos(0,0),
|
||||
m_positionChangeRequested(false),
|
||||
m_curentGrabDelta(0,0),
|
||||
m_currentCursor(gale::context::cursor::arrow),
|
||||
m_lastKeyPressed(0) {
|
||||
GLUT_INFO("GLUT:INIT");
|
||||
for (int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
|
||||
m_inputIsPressed[iii] = false;
|
||||
}
|
||||
if (m_doubleBuffered) {
|
||||
//XSync(m_display,0);
|
||||
}
|
||||
OS_Resize(m_currentSize);
|
||||
|
||||
// Configure the DPI of the screen:
|
||||
{
|
||||
vec2 dpi(0,0);
|
||||
dpi.setX(75);
|
||||
dpi.setY(75);
|
||||
gale::Dimension::setPixelRatio(dpi, gale::distance::inch);
|
||||
GALE_INFO("monitor property : dpi=" << dpi << " px/inch");
|
||||
}
|
||||
m_run = true;
|
||||
start2ndThreadProcessing();
|
||||
}
|
||||
|
||||
~GLUTInterface() {
|
||||
//GLUT_Quit();
|
||||
}
|
||||
|
||||
int32_t draw() {
|
||||
GLUT_INFO("RUN");
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
GLUT_INFO("RUN 2");
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GLUT_INFO("RUN 3");
|
||||
//glLoadIdentity();
|
||||
GLUT_INFO("Draw [START]");
|
||||
OS_Draw(true);
|
||||
GLUT_INFO("Draw [STOP]");
|
||||
glutSwapBuffers();
|
||||
//ethread::sleepMilliSeconds((1000));
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void stop() {
|
||||
GLUT_INFO("GLUT-API: Stop");
|
||||
m_run = false;
|
||||
}
|
||||
void reshape(int _width, int _height) {
|
||||
glViewport(0, 0, (GLint) _width, (GLint) _height);
|
||||
m_currentSize = vec2(_width, _height);
|
||||
OS_Resize(vec2(_width, _height));
|
||||
}
|
||||
void special(int _special) {
|
||||
GALE_INFO("Value=" << _special);
|
||||
bool find = true;
|
||||
enum gale::key::keyboard keyInput = gale::key::keyboard::unknow;
|
||||
switch (_special) {
|
||||
//case 80: // keypad
|
||||
case GLUT_KEY_UP: keyInput = gale::key::keyboard::up; break;
|
||||
//case 83: // keypad
|
||||
case GLUT_KEY_LEFT: keyInput = gale::key::keyboard::left; break;
|
||||
//case 85: // keypad
|
||||
case GLUT_KEY_RIGHT: keyInput = gale::key::keyboard::right; break;
|
||||
//case 88: // keypad
|
||||
case GLUT_KEY_DOWN: keyInput = gale::key::keyboard::down; break;
|
||||
//case 81: // keypad
|
||||
case GLUT_KEY_PAGE_UP: keyInput = gale::key::keyboard::pageUp; break;
|
||||
//case 89: // keypad
|
||||
case GLUT_KEY_PAGE_DOWN: keyInput = gale::key::keyboard::pageDown; break;
|
||||
//case 79: // keypad
|
||||
case GLUT_KEY_HOME: keyInput = gale::key::keyboard::start; break;
|
||||
//case 87: // keypad
|
||||
case GLUT_KEY_END: keyInput = gale::key::keyboard::end; break;
|
||||
// TODO: case 78: keyInput = gale::key::keyboard::stopDefil; break;
|
||||
// TODO: case 127: keyInput = gale::key::keyboard::wait; break;
|
||||
//case 90: // keypad
|
||||
case GLUT_KEY_INSERT: keyInput = gale::key::keyboard::insert; break;
|
||||
//case 84: keyInput = gale::key::keyboardCenter; break; // Keypad
|
||||
case GLUT_KEY_F1: keyInput = gale::key::keyboard::f1; break;
|
||||
case GLUT_KEY_F2: keyInput = gale::key::keyboard::f2; break;
|
||||
case GLUT_KEY_F3: keyInput = gale::key::keyboard::f3; break;
|
||||
case GLUT_KEY_F4: keyInput = gale::key::keyboard::f4; break;
|
||||
case GLUT_KEY_F5: keyInput = gale::key::keyboard::f5; break;
|
||||
case GLUT_KEY_F6: keyInput = gale::key::keyboard::f6; break;
|
||||
case GLUT_KEY_F7: keyInput = gale::key::keyboard::f7; break;
|
||||
case GLUT_KEY_F8: keyInput = gale::key::keyboard::f8; break;
|
||||
case GLUT_KEY_F9: keyInput = gale::key::keyboard::f9; break;
|
||||
case GLUT_KEY_F10: keyInput = gale::key::keyboard::f10; break;
|
||||
case GLUT_KEY_F11: keyInput = gale::key::keyboard::f11; break;
|
||||
case GLUT_KEY_F12: keyInput = gale::key::keyboard::f12; break;
|
||||
case 112: keyInput = gale::key::keyboard::shiftLeft; break;
|
||||
case 114: keyInput = gale::key::keyboard::ctrlLeft; break;
|
||||
case 116: keyInput = gale::key::keyboard::alt; break;
|
||||
case 111: // Suppr
|
||||
find = false;
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
gale::key::keyboard::character,
|
||||
gale::key::status::down,
|
||||
false,
|
||||
0x7F);
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
gale::key::keyboard::character,
|
||||
gale::key::status::up,
|
||||
false,
|
||||
0x7F);
|
||||
break;
|
||||
case 120: // delete
|
||||
find = false;
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
gale::key::keyboard::character,
|
||||
gale::key::status::down,
|
||||
false,
|
||||
0x08);
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
gale::key::keyboard::character,
|
||||
gale::key::status::up,
|
||||
false,
|
||||
0x08);
|
||||
break;
|
||||
default:
|
||||
find = false;
|
||||
GALE_ERROR("Not find special:" << _special);
|
||||
}
|
||||
if (find == true) {
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
keyInput,
|
||||
gale::key::status::down,
|
||||
false);
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
keyInput,
|
||||
gale::key::status::up,
|
||||
false);
|
||||
}
|
||||
/* case GLUT_KEY_F11:
|
||||
glutFullScreen();
|
||||
break;
|
||||
*/
|
||||
GALE_ERROR("eventKey Move type : " << keyInput );
|
||||
}
|
||||
|
||||
void keyboard(unsigned char _key) {
|
||||
GALE_ERROR("keyboard: " << int(_key));
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
gale::key::keyboard::character,
|
||||
gale::key::status::down,
|
||||
false,
|
||||
_key);
|
||||
OS_setKeyboard(m_guiKeyBoardMode,
|
||||
gale::key::keyboard::character,
|
||||
gale::key::status::up,
|
||||
false,
|
||||
_key);
|
||||
}
|
||||
|
||||
void mouse(int _button, bool _up, const vec2& _pos) {
|
||||
GALE_ERROR("mouse: " << _button << " " << (_up==true?"up":"down") << " " << _pos);
|
||||
m_cursorEventPos = vec2(_pos.x(), m_currentSize.y() - _pos.y());
|
||||
OS_SetInput(gale::key::type::mouse,
|
||||
(_up==true?gale::key::status::up:gale::key::status::down),
|
||||
_button+1,
|
||||
m_cursorEventPos);
|
||||
m_inputIsPressed[_button+1] = !_up;
|
||||
}
|
||||
|
||||
void mousePasive(const vec2& _pos) {
|
||||
GALE_ERROR("mouse: " << _pos);
|
||||
m_cursorEventPos = vec2(_pos.x(), m_currentSize.y() - _pos.y());
|
||||
|
||||
// For compatibility of the Android system :
|
||||
bool findOne = false;
|
||||
for (int32_t iii=0; iii<MAX_MANAGE_INPUT ; iii++) {
|
||||
if (m_inputIsPressed[iii] == true) {
|
||||
OS_SetInput(gale::key::type::mouse,
|
||||
gale::key::status::move,
|
||||
iii,
|
||||
m_cursorEventPos);
|
||||
findOne = true;
|
||||
}
|
||||
}
|
||||
if (findOne == false) {
|
||||
OS_SetInput(gale::key::type::mouse,
|
||||
gale::key::status::move,
|
||||
0,
|
||||
m_cursorEventPos);
|
||||
}
|
||||
}
|
||||
int32_t run() {
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
GLUTInterface* g_interface = null;
|
||||
|
||||
static void gale_glut_idle() {
|
||||
glutPostRedisplay();
|
||||
//g_interface->idle();
|
||||
}
|
||||
static void gale_glut_reshape(int _width, int _height) {
|
||||
g_interface->reshape(_width, _height);
|
||||
}
|
||||
static void gale_glut_draw() {
|
||||
g_interface->draw();
|
||||
}
|
||||
static void gale_glut_special(int _special, int _x, int _y) {
|
||||
g_interface->special(_special);
|
||||
}
|
||||
static void gale_glut_keyboard(unsigned char _key, int _x, int _y) {
|
||||
g_interface->keyboard(_key);
|
||||
}
|
||||
static void gale_glut_mouse(int _button, int _state, int _x, int _y) {
|
||||
g_interface->mouse( _button, bool(_state), vec2(_x, _y));
|
||||
}
|
||||
static void gale_glut_mouse_pasive(int _x, int _y) {
|
||||
g_interface->mousePasive(vec2(_x, _y));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include <gale/context/SDL/Context.hpp>
|
||||
|
||||
bool gale::context::sdl::isBackendPresent() {
|
||||
// TODO : Do it better...
|
||||
return true;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<gale::Context> gale::context::sdl::createInstance(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
#ifndef __EMSCRIPTEN__
|
||||
// include GL stuff, to check that we can compile hybrid 2d/GL apps
|
||||
extern void glBegin(int mode);
|
||||
extern void glBindBuffer(int target, int buffer);
|
||||
if (_argc == 9876) {
|
||||
glBegin(0);
|
||||
glBindBuffer(0, 0);
|
||||
}
|
||||
#endif
|
||||
ememory::SharedPtr<gale::Context> out; ememory::makeShared<X11Interface>(_application, _argc, _argv);
|
||||
|
||||
/* Initialize the window */
|
||||
glutInit(&_argc, (char**)_argv);
|
||||
glutInitWindowSize(600, 450);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
||||
glutCreateWindow("coucou, name to change ...");
|
||||
/* Set up glut callback functions */
|
||||
glutIdleFunc(gale_glut_idle);
|
||||
glutReshapeFunc(gale_glut_reshape);
|
||||
glutDisplayFunc(gale_glut_draw);
|
||||
glutSpecialFunc(gale_glut_special);
|
||||
//glutEntryFunc(gale_glut_entry);
|
||||
glutKeyboardFunc(gale_glut_keyboard);
|
||||
glutMouseFunc(gale_glut_mouse);
|
||||
glutMotionFunc(gale_glut_mouse_pasive);
|
||||
GALE_DEBUG("7987984654654\n");
|
||||
|
||||
return out;
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
#include <etk/math/Vector2D.hpp>
|
||||
#include <etk/math/Vector3D.hpp>
|
||||
@ -23,16 +23,16 @@
|
||||
#include <windowsx.h>
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
static std::string GetLastErrorAsString() {
|
||||
static etk::String GetLastErrorAsString() {
|
||||
//Get the error message, if any.
|
||||
DWORD errorMessageID = ::GetLastError();
|
||||
if(errorMessageID == 0) {
|
||||
return std::string(); //No error message has been recorded
|
||||
return etk::String(); //No error message has been recorded
|
||||
}
|
||||
LPSTR messageBuffer = nullptr;
|
||||
LPSTR messageBuffer = null;
|
||||
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
|
||||
std::string message(messageBuffer, size);
|
||||
etk::String message(messageBuffer, size);
|
||||
//Free the buffer.
|
||||
LocalFree(messageBuffer);
|
||||
return message;
|
||||
@ -40,7 +40,7 @@ static std::string GetLastErrorAsString() {
|
||||
|
||||
class WindowsContext;
|
||||
// This is a bad hook to get the wurrent windows pointer (it is unique ...):
|
||||
static WindowsContext * galeWindowsContext = nullptr;
|
||||
static WindowsContext * galeWindowsContext = null;
|
||||
|
||||
// Window Procedure
|
||||
static LRESULT CALLBACK WndProc(HWND _hWnd, UINT _message, WPARAM _wParam, LPARAM _lParam);
|
||||
@ -62,7 +62,7 @@ class WindowsContext : public gale::Context {
|
||||
gale::Context(_application, _argc, _argv),
|
||||
m_run(true),
|
||||
m_clipBoardOwnerStd(false),
|
||||
m_hInstance(GetModuleHandle(nullptr)),
|
||||
m_hInstance(GetModuleHandle(null)),
|
||||
m_hWnd(0),
|
||||
m_hDC(0),
|
||||
m_hRC(0) {
|
||||
@ -71,10 +71,11 @@ class WindowsContext : public gale::Context {
|
||||
m_inputIsPressed[iii] = false;
|
||||
}
|
||||
configure();
|
||||
start2ndThreadProcessing();
|
||||
}
|
||||
|
||||
~WindowsContext() {
|
||||
galeWindowsContext = nullptr;
|
||||
galeWindowsContext = null;
|
||||
release();
|
||||
}
|
||||
|
||||
@ -117,12 +118,12 @@ class WindowsContext : public gale::Context {
|
||||
, // The style of the window being created.
|
||||
10, 10, // start position
|
||||
800, 600, // start size
|
||||
nullptr, // A handle to the parent or owner window of the window being created
|
||||
nullptr, // A handle to a menu, or specifies a child-window identifier, depending on the window style
|
||||
null, // A handle to the parent or owner window of the window being created
|
||||
null, // A handle to a menu, or specifies a child-window identifier, depending on the window style
|
||||
m_hInstance, // A handle to the instance of the module to be associated with the window.
|
||||
nullptr //A pointer to a value to be passed to the window through the CREATESTRUCT structure
|
||||
null //A pointer to a value to be passed to the window through the CREATESTRUCT structure
|
||||
);
|
||||
if(m_hWnd == nullptr) {
|
||||
if(m_hWnd == null) {
|
||||
GALE_ERROR("Can not create windows '" << GetLastErrorAsString() << "'" );
|
||||
MessageBox(m_hWnd, "Error creating window\n(gale internal error #45211)", "Error", MB_ICONEXCLAMATION);
|
||||
PostQuitMessage(0);
|
||||
@ -176,7 +177,7 @@ class WindowsContext : public gale::Context {
|
||||
// program main loop
|
||||
while(m_run == true) {
|
||||
// check for messages
|
||||
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||
if (PeekMessage(&msg, null, 0, 0, PM_REMOVE)) {
|
||||
// handle or dispatch messages
|
||||
if (msg.message == WM_QUIT) {
|
||||
m_run = false;
|
||||
@ -232,10 +233,10 @@ class WindowsContext : public gale::Context {
|
||||
case gale::context::clipBoard::clipboardStd:
|
||||
// TODO : never done reset at false ...
|
||||
if (m_clipBoardOwnerStd == false) {
|
||||
char* buffer = nullptr;
|
||||
char* buffer = null;
|
||||
if(OpenClipboard(m_hWnd)) {
|
||||
buffer = (char*)GetClipboardData(CF_TEXT);
|
||||
std::string tmpppp((char*)buffer);
|
||||
etk::String tmpppp((char*)buffer);
|
||||
// TODO : Check if we need to free buffer ...
|
||||
gale::context::clipBoard::setSystem(gale::context::clipBoard::clipboardSelection, tmpppp);
|
||||
// just transmit an event , we have the data in the system
|
||||
@ -261,7 +262,7 @@ class WindowsContext : public gale::Context {
|
||||
case gale::context::clipBoard::clipboardStd:
|
||||
// Request the clipBoard :
|
||||
if (m_clipBoardOwnerStd == false) {
|
||||
std::string tmpData = gale::context::clipBoard::get(_clipboardID);
|
||||
etk::String tmpData = gale::context::clipBoard::get(_clipboardID);
|
||||
//put your text in source
|
||||
if(OpenClipboard(m_hWnd)) {
|
||||
HGLOBAL clipbuffer;
|
||||
@ -303,7 +304,7 @@ class WindowsContext : public gale::Context {
|
||||
// create and enable the render context(RC)
|
||||
*_hRC = wglCreateContext(*_hDC);
|
||||
wglMakeCurrent(*_hDC, *_hRC);
|
||||
if (wglGetCurrentContext() == nullptr) {
|
||||
if (wglGetCurrentContext() == null) {
|
||||
GALE_ERROR("can not create OPEN gL context...");
|
||||
MessageBox(_hWnd, "Error initilizing open GL\n openGL context creation error...\n(gale internal error #3526)", "Error", MB_ICONEXCLAMATION);
|
||||
PostQuitMessage(0);
|
||||
@ -313,7 +314,7 @@ class WindowsContext : public gale::Context {
|
||||
|
||||
// disable openGL (fisnish application ...
|
||||
void disableOpenGL(HWND _hWnd, HDC _hDC, HGLRC _hRC) {
|
||||
wglMakeCurrent(nullptr, nullptr);
|
||||
wglMakeCurrent(null, null);
|
||||
wglDeleteContext(_hRC);
|
||||
ReleaseDC(_hWnd, _hDC);
|
||||
}
|
||||
@ -358,7 +359,7 @@ class WindowsContext : public gale::Context {
|
||||
*/
|
||||
case WM_WINDOWPOSCHANGING: {
|
||||
WINDOWPOS* tmpVal = (WINDOWPOS*)_lParam;
|
||||
if (tmpVal == nullptr) {
|
||||
if (tmpVal == null) {
|
||||
break;
|
||||
}
|
||||
GALE_VERBOSE("WM_WINDOWPOSCHANGING : : (" << tmpVal->x << "," << tmpVal->y << ") ( " << tmpVal->cx << "," << tmpVal->cy << ")");
|
||||
@ -610,7 +611,7 @@ class WindowsContext : public gale::Context {
|
||||
return DefWindowProc(_hWnd, _message, _wParam, _lParam);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setTitle(const std::string& _title) {
|
||||
void setTitle(const etk::String& _title) {
|
||||
GALE_VERBOSE("Windows: set Title (START)");
|
||||
SetWindowText(m_hWnd, _title.c_str());
|
||||
GALE_VERBOSE("Windows: set Title (END)");
|
||||
@ -619,29 +620,19 @@ class WindowsContext : public gale::Context {
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND _hWnd, UINT _message, WPARAM _wParam, LPARAM _lParam) {
|
||||
// TODO : set this function really work...
|
||||
if (galeWindowsContext == nullptr) {
|
||||
if (galeWindowsContext == null) {
|
||||
return 0;
|
||||
}
|
||||
return galeWindowsContext->WndProcReal(_hWnd, _message, _wParam, _lParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main of the program
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
WindowsContext* localInterface = new WindowsContext(_application, _argc, _argv);
|
||||
if (localInterface == nullptr) {
|
||||
GALE_CRITICAL("Can not create the 'Windows' interface ... MEMORY allocation error");
|
||||
return -2;
|
||||
}
|
||||
|
||||
int32_t retValue = localInterface->run();
|
||||
delete(localInterface);
|
||||
localInterface = nullptr;
|
||||
GALE_INFO("END APPLICATION");
|
||||
return retValue;
|
||||
#include <gale/context/Windows/Context.hpp>
|
||||
|
||||
bool gale::context::windows::isBackendPresent() {
|
||||
// TODO : Do it better...
|
||||
return true;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<gale::Context> gale::context::windows::createInstance(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
return ememory::makeShared<WindowsContext>(_application, _argc, _argv);
|
||||
}
|
||||
|
26
gale/context/Windows/Context.hpp
Normal file
26
gale/context/Windows/Context.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace gale {
|
||||
namespace context {
|
||||
namespace windows {
|
||||
/**
|
||||
* @brief Check if the backend can be instanciate
|
||||
* @return true if the backend is availlable (false otherwise)
|
||||
*/
|
||||
bool isBackendPresent();
|
||||
/**
|
||||
* @brief Create the context main intance
|
||||
* @param[in] _application pointer on the application
|
||||
* @param[in] _argc number of parameter
|
||||
* @param[in] _argv araay of pointer of each parameters
|
||||
* @return instance on the generic created context
|
||||
*/
|
||||
ememory::SharedPtr<gale::Context> createInstance(gale::Application* _application, int _argc, const char *_argv[]);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
}
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
@ -24,52 +25,97 @@
|
||||
|
||||
|
||||
#if defined(__TARGET_OS__Linux)
|
||||
#include <GL/glx.h>
|
||||
#if defined(__TARGET_OS__Web)
|
||||
extern "C" {
|
||||
#include <X11/Xlibint.h>
|
||||
#include <X11/Xutil.h>
|
||||
}
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
extern "C" {
|
||||
#include <GL/glext.h>
|
||||
#include <GL/glfw.h>
|
||||
}
|
||||
#else
|
||||
extern "C" {
|
||||
#include <GL/glx.h>
|
||||
}
|
||||
#endif
|
||||
#elif defined(__TARGET_OS__MacOs)
|
||||
#include <OpenGL/glx.h>
|
||||
extern "C" {
|
||||
#include <OpenGL/glx.h>
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
extern "C" {
|
||||
#include <X11/Xatom.h>
|
||||
#include <sys/times.h>
|
||||
}
|
||||
/*
|
||||
#define GUI_LOCK() XLockDisplay(m_display)
|
||||
#define GUI_UNLOCK() XUnlockDisplay(m_display)
|
||||
*/
|
||||
bool hasDisplay = false;
|
||||
static bool hasDisplay = false;
|
||||
//#define DEBUG_X11_EVENT
|
||||
#ifdef DEBUG_X11_EVENT
|
||||
#define X11_DEBUG GALE_DEBUG
|
||||
#define X11_VERBOSE GALE_VERBOSE
|
||||
#define X11_INFO GALE_INFO
|
||||
#define X11_CRITICAL GALE_CRITICAL
|
||||
static int32_t callLevel = 0;
|
||||
etk::String getOffset(int32_t _size) {
|
||||
etk::String out;
|
||||
for (int32_t iii=0; iii<_size; ++iii) {
|
||||
out += "....";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
class GaleTmpFuncCall {
|
||||
private:
|
||||
etk::String m_value;
|
||||
int32_t m_level;
|
||||
public:
|
||||
GaleTmpFuncCall(const etk::String& _value) :
|
||||
m_value(_value),
|
||||
m_level(callLevel++) {
|
||||
GALE_INFO(getOffset(m_level) << " ==> " << m_value);
|
||||
}
|
||||
~GaleTmpFuncCall() {
|
||||
GALE_INFO(getOffset(m_level) << "<== " << m_value);
|
||||
callLevel--;
|
||||
}
|
||||
};
|
||||
#define X11_FUNC() GaleTmpFuncCall tmpValueCallqsdfqsdfqsdfqsdfqsdfqsdfqsdfqsdfqsdf(__PRETTY_FUNCTION__)
|
||||
#else
|
||||
#define X11_DEBUG GALE_VERBOSE
|
||||
#define X11_VERBOSE GALE_VERBOSE
|
||||
#define X11_INFO GALE_VERBOSE
|
||||
#define X11_CRITICAL GALE_VERBOSE
|
||||
#define X11_FUNC() do {} while(false)
|
||||
#endif
|
||||
|
||||
// attributes for a single buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListSgl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
|
||||
// attributes for a double buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListDbl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_DOUBLEBUFFER,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
// attributes for a single buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListSgl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
|
||||
// attributes for a double buffered visual in RGBA format with at least 4 bits per color and a 16 bit depth buffer
|
||||
static int attrListDbl[] = {
|
||||
GLX_RGBA,
|
||||
GLX_DOUBLEBUFFER,
|
||||
GLX_RED_SIZE, 4,
|
||||
GLX_GREEN_SIZE, 4,
|
||||
GLX_BLUE_SIZE, 4,
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
None
|
||||
};
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
typedef struct Hints {
|
||||
@ -102,7 +148,9 @@ class X11Interface : public gale::Context {
|
||||
int32_t m_cursorEventY;
|
||||
int32_t m_currentHeight;
|
||||
int32_t m_currentWidth;
|
||||
XVisualInfo* m_visual;
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
XVisualInfo* m_visual;
|
||||
#endif
|
||||
bool m_doubleBuffered;
|
||||
bool m_run;
|
||||
//forcing the position
|
||||
@ -123,20 +171,22 @@ class X11Interface : public gale::Context {
|
||||
Atom XAtomTargetTarget;
|
||||
Atom XAtomGALE;
|
||||
Atom XAtomDeleteWindows;
|
||||
std::string m_uniqueWindowsName;
|
||||
etk::String m_uniqueWindowsName;
|
||||
enum gale::context::cursor m_currentCursor; //!< select the current cursor to display :
|
||||
char32_t m_lastKeyPressed; //!< The last element key presed...
|
||||
public:
|
||||
X11Interface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv),
|
||||
m_display(nullptr),
|
||||
m_display(NULL),
|
||||
m_originX(0),
|
||||
m_originY(0),
|
||||
m_cursorEventX(0),
|
||||
m_cursorEventY(0),
|
||||
m_currentHeight(0),
|
||||
m_currentWidth(0),
|
||||
m_visual(nullptr),
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
m_visual(NULL),
|
||||
#endif
|
||||
m_doubleBuffered(0),
|
||||
m_run(false),
|
||||
m_grabAllEvent(false),
|
||||
@ -155,33 +205,41 @@ class X11Interface : public gale::Context {
|
||||
XAtomDeleteWindows(0),
|
||||
m_currentCursor(gale::context::cursor::arrow),
|
||||
m_lastKeyPressed(0) {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11:INIT");
|
||||
for (int32_t iii=0; iii<MAX_MANAGE_INPUT; iii++) {
|
||||
m_inputIsPressed[iii] = false;
|
||||
}
|
||||
if (m_doubleBuffered) {
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#if defined(__TARGET_OS__Web)
|
||||
glfwSwapBuffers();
|
||||
#else
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#endif
|
||||
XSync(m_display,0);
|
||||
}
|
||||
createX11Context();
|
||||
createOGlContext();
|
||||
// reset the Atom properties ...
|
||||
// Reset the Atom properties.
|
||||
XAtomSelection = XInternAtom(m_display, "PRIMARY", 0);
|
||||
XAtomClipBoard = XInternAtom(m_display, "CLIPBOARD", 0);
|
||||
XAtomTargetString = XInternAtom(m_display, "STRING", 0);
|
||||
XAtomTargetStringUTF8 = XInternAtom(m_display, "UTF8_STRING", 0);
|
||||
XAtomTargetTarget = XInternAtom(m_display, "TARGETS", 0);
|
||||
m_uniqueWindowsName = "GALE_" + etk::to_string(etk::tool::irand(0, 1999999999));
|
||||
m_uniqueWindowsName = "GALE_" + etk::toString(etk::tool::irand(0, 1999999999));
|
||||
XAtomGALE = XInternAtom(m_display, m_uniqueWindowsName.c_str(), 0);
|
||||
XAtomDeleteWindows = XInternAtom(m_display, "WM_DELETE_WINDOW", 0);
|
||||
m_run = true;
|
||||
start2ndThreadProcessing();
|
||||
}
|
||||
|
||||
~X11Interface() {
|
||||
// TODO : ...
|
||||
X11_FUNC();
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
X11_FUNC();
|
||||
bool specialEventThatNeedARedraw = false;
|
||||
// main cycle
|
||||
while(m_run == true) {
|
||||
@ -212,21 +270,21 @@ class X11Interface : public gale::Context {
|
||||
{
|
||||
XSelectionRequestEvent *req=&(event.xselectionrequest);
|
||||
if (req->property == 0) {
|
||||
GALE_ERROR("Get nullptr ATOM ... property");
|
||||
GALE_ERROR("Get null ATOM ... property");
|
||||
break;
|
||||
}
|
||||
if (req->target == 0) {
|
||||
GALE_ERROR("Get nullptr ATOM ... target");
|
||||
GALE_ERROR("Get null ATOM ... target");
|
||||
break;
|
||||
}
|
||||
char * atomNameProperty = XGetAtomName(m_display, req->property);
|
||||
char * atomNameTarget = XGetAtomName(m_display, req->target);
|
||||
GALE_INFO("X11 property: \"" << atomNameProperty << "\"");
|
||||
GALE_INFO("X11 target: \"" << atomNameTarget << "\"");
|
||||
if (atomNameProperty != nullptr) {
|
||||
if (atomNameProperty != NULL) {
|
||||
XFree(atomNameProperty);
|
||||
}
|
||||
if (atomNameTarget != nullptr) {
|
||||
if (atomNameTarget != NULL) {
|
||||
XFree(atomNameTarget);
|
||||
}
|
||||
}
|
||||
@ -263,12 +321,12 @@ class X11Interface : public gale::Context {
|
||||
&buf// **prop_return);
|
||||
);
|
||||
if (m_clipBoardRequestPrimary == true) {
|
||||
std::string tmpppp((char*)buf);
|
||||
etk::String tmpppp((char*)buf);
|
||||
gale::context::clipBoard::setSystem(gale::context::clipBoard::clipboardSelection, tmpppp);
|
||||
// just transmit an event , we have the data in the system
|
||||
OS_ClipBoardArrive(gale::context::clipBoard::clipboardSelection);
|
||||
} else {
|
||||
std::string tmpppp((char*)buf);
|
||||
etk::String tmpppp((char*)buf);
|
||||
gale::context::clipBoard::setSystem(gale::context::clipBoard::clipboardStd, tmpppp);
|
||||
// just transmit an event , we have the data in the system
|
||||
OS_ClipBoardArrive(gale::context::clipBoard::clipboardStd);
|
||||
@ -280,29 +338,35 @@ class X11Interface : public gale::Context {
|
||||
XSelectionRequestEvent *req=&(event.xselectionrequest);
|
||||
#ifdef DEBUG_X11_EVENT
|
||||
{
|
||||
if (req->property == 0) {
|
||||
GALE_ERROR("Get nullptr ATOM ... property");
|
||||
if (req->property == NULL) {
|
||||
GALE_ERROR("Get null ATOM ... property");
|
||||
break;
|
||||
}
|
||||
if (req->selection == 0) {
|
||||
GALE_ERROR("Get nullptr ATOM ... selection");
|
||||
if (req->selection == NULL) {
|
||||
GALE_ERROR("Get null ATOM ... selection");
|
||||
break;
|
||||
}
|
||||
if (req->target == 0) {
|
||||
GALE_ERROR("Get nullptr ATOM ... target");
|
||||
if (req->target == NULL) {
|
||||
GALE_ERROR("Get null ATOM ... target");
|
||||
break;
|
||||
}
|
||||
char * atomNameProperty = XGetAtomName(m_display, req->property);
|
||||
char * atomNameSelection = XGetAtomName(m_display, req->selection);
|
||||
char * atomNameTarget = XGetAtomName(m_display, req->target);
|
||||
GALE_INFO(" from: " << atomNameProperty << " request=" << atomNameSelection << " in " << atomNameTarget);
|
||||
if (nullptr != atomNameProperty) { XFree(atomNameProperty); }
|
||||
if (nullptr != atomNameSelection) { XFree(atomNameSelection); }
|
||||
if (nullptr != atomNameTarget) { XFree(atomNameTarget); }
|
||||
if (atomNameProperty != NULL) {
|
||||
XFree(atomNameProperty);
|
||||
}
|
||||
if (atomNameSelection != NULL) {
|
||||
XFree(atomNameSelection);
|
||||
}
|
||||
if (atomNameTarget != NULL) {
|
||||
XFree(atomNameTarget);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string tmpData = "";
|
||||
etk::String tmpData = "";
|
||||
if (req->selection == XAtomSelection) {
|
||||
tmpData = gale::context::clipBoard::get(gale::context::clipBoard::clipboardSelection);
|
||||
} else if (req->selection == XAtomClipBoard) {
|
||||
@ -538,6 +602,7 @@ class X11Interface : public gale::Context {
|
||||
X11_INFO("X11 event : " << event.type << " = 'KeyPress/KeyRelease' ");
|
||||
{
|
||||
X11_DEBUG("eventKey : " << event.xkey.keycode << " state : " << event.xkey.state);
|
||||
/*
|
||||
if (event.xkey.state & (1<<0) ) {
|
||||
//GALE_DEBUG(" Special Key : SHIFT");
|
||||
m_guiKeyBoardMode.setShift(true);
|
||||
@ -583,6 +648,7 @@ class X11Interface : public gale::Context {
|
||||
} else {
|
||||
m_guiKeyBoardMode.setAltGr(false);
|
||||
}
|
||||
*/
|
||||
bool find = true;
|
||||
enum gale::key::keyboard keyInput;
|
||||
switch (event.xkey.keycode) {
|
||||
@ -628,17 +694,17 @@ class X11Interface : public gale::Context {
|
||||
case 76: keyInput = gale::key::keyboard::f10; break;
|
||||
case 95: keyInput = gale::key::keyboard::f11; break;
|
||||
case 96: keyInput = gale::key::keyboard::f12; break;
|
||||
case 66: keyInput = gale::key::keyboard::capLock; m_guiKeyBoardMode.setCapsLock( (event.type == KeyPress) ? true : false); break;
|
||||
case 50: keyInput = gale::key::keyboard::shiftLeft; m_guiKeyBoardMode.setShift ( (event.type == KeyPress) ? true : false); break;
|
||||
case 62: keyInput = gale::key::keyboard::shiftRight; m_guiKeyBoardMode.setShift ( (event.type == KeyPress) ? true : false); break;
|
||||
case 37: keyInput = gale::key::keyboard::ctrlLeft; m_guiKeyBoardMode.setCtrl ( (event.type == KeyPress) ? true : false); break;
|
||||
case 105: keyInput = gale::key::keyboard::ctrlRight; m_guiKeyBoardMode.setCtrl ( (event.type == KeyPress) ? true : false); break;
|
||||
case 133: keyInput = gale::key::keyboard::metaLeft; m_guiKeyBoardMode.setMeta ( (event.type == KeyPress) ? true : false); break;
|
||||
case 134: keyInput = gale::key::keyboard::metaRight; m_guiKeyBoardMode.setMeta ( (event.type == KeyPress) ? true : false); break;
|
||||
case 64: keyInput = gale::key::keyboard::alt; m_guiKeyBoardMode.setAlt ( (event.type == KeyPress) ? true : false); break;
|
||||
case 108: keyInput = gale::key::keyboard::altGr; m_guiKeyBoardMode.setAltGr ( (event.type == KeyPress) ? true : false); break;
|
||||
case 66: keyInput = gale::key::keyboard::capLock; m_guiKeyBoardMode.setCapsLock (event.type == KeyPress); break;
|
||||
case 50: keyInput = gale::key::keyboard::shiftLeft; m_guiKeyBoardMode.setShiftLeft (event.type == KeyPress); break;
|
||||
case 62: keyInput = gale::key::keyboard::shiftRight; m_guiKeyBoardMode.setShiftRight(event.type == KeyPress); break;
|
||||
case 37: keyInput = gale::key::keyboard::ctrlLeft; m_guiKeyBoardMode.setCtrlLeft (event.type == KeyPress); break;
|
||||
case 105: keyInput = gale::key::keyboard::ctrlRight; m_guiKeyBoardMode.setCtrlRight (event.type == KeyPress); break;
|
||||
case 133: keyInput = gale::key::keyboard::metaLeft; m_guiKeyBoardMode.setMetaLeft (event.type == KeyPress); break;
|
||||
case 134: keyInput = gale::key::keyboard::metaRight; m_guiKeyBoardMode.setMetaRight (event.type == KeyPress); break;
|
||||
case 64: keyInput = gale::key::keyboard::alt; m_guiKeyBoardMode.setAltLeft (event.type == KeyPress); break;
|
||||
case 108: keyInput = gale::key::keyboard::altGr; m_guiKeyBoardMode.setAltRight (event.type == KeyPress); break;
|
||||
case 135: keyInput = gale::key::keyboard::contextMenu; break;
|
||||
case 77: keyInput = gale::key::keyboard::numLock; m_guiKeyBoardMode.setNumLock ( (event.type == KeyPress) ? true : false); break;
|
||||
case 77: keyInput = gale::key::keyboard::numLock; m_guiKeyBoardMode.setNumLock (event.type == KeyPress); break;
|
||||
case 91: // Suppr on keypad
|
||||
find = false;
|
||||
if(m_guiKeyBoardMode.getNumLock() == true){
|
||||
@ -751,12 +817,12 @@ class X11Interface : public gale::Context {
|
||||
// break;
|
||||
case MapNotify:
|
||||
X11_INFO("X11 event : MapNotify");
|
||||
specialEventThatNeedARedraw=true;
|
||||
specialEventThatNeedARedraw = true;
|
||||
OS_Show();
|
||||
break;
|
||||
case UnmapNotify:
|
||||
X11_INFO("X11 event : UnmapNotify");
|
||||
specialEventThatNeedARedraw=true;
|
||||
specialEventThatNeedARedraw = true;
|
||||
OS_Hide();
|
||||
break;
|
||||
default:
|
||||
@ -766,24 +832,36 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
if(m_run == true) {
|
||||
if (m_doubleBuffered && hasDisplay) {
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#if defined(__TARGET_OS__Web)
|
||||
glfwSwapBuffers();
|
||||
#else
|
||||
glXSwapBuffers(m_display, m_WindowHandle);
|
||||
#endif
|
||||
XSync(m_display,0);
|
||||
}
|
||||
//specialEventThatNeedARedraw = true;
|
||||
// draw after switch the previous windows ...
|
||||
//GALE_DEBUG("specialEventThatNeedARedraw"<<specialEventThatNeedARedraw);
|
||||
if (specialEventThatNeedARedraw == true) {
|
||||
X11_INFO("specialEventThatNeedARedraw = " << specialEventThatNeedARedraw);
|
||||
}
|
||||
hasDisplay = OS_Draw(specialEventThatNeedARedraw);
|
||||
specialEventThatNeedARedraw=false;
|
||||
if (hasDisplay == true) {
|
||||
// need to request it every time needed to have a redrawing (this can take some time if the application filter the drfaw periodicity)
|
||||
specialEventThatNeedARedraw = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void stop() {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11-API: Stop");
|
||||
m_run = false;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void setSize(const vec2& _size) {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11-API: changeSize=" << _size);
|
||||
m_currentHeight = _size.y();
|
||||
m_currentWidth = _size.x();
|
||||
@ -791,6 +869,7 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setFullScreen(bool _status) {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11-API: changeFullscreen=" << _status);
|
||||
XEvent event;
|
||||
event.xclient.type = ClientMessage;
|
||||
@ -825,6 +904,7 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void grabKeyboardEvents(bool _status) {
|
||||
X11_FUNC();
|
||||
if (_status == true) {
|
||||
X11_INFO("X11-API: Grab Keyboard Events");
|
||||
XGrabKeyboard(m_display, m_WindowHandle,
|
||||
@ -839,6 +919,7 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void setWindowsDecoration(bool _status) {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11-API: setWindows Decoration :" << _status);
|
||||
// Remove/set decoration
|
||||
Hints hints;
|
||||
@ -856,6 +937,7 @@ class X11Interface : public gale::Context {
|
||||
};
|
||||
/****************************************************************************************/
|
||||
virtual void setPos(const vec2& _pos) {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11-API: changePos=" << _pos);
|
||||
m_windowsPos = _pos;
|
||||
XMoveWindow(m_display, m_WindowHandle, _pos.x(), _pos.y());
|
||||
@ -865,6 +947,7 @@ class X11Interface : public gale::Context {
|
||||
/****************************************************************************************/
|
||||
/*
|
||||
virtual void getAbsPos(ivec2& pos) {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11-API: getAbsPos");
|
||||
int tmp;
|
||||
unsigned int tmp2;
|
||||
@ -874,6 +957,7 @@ class X11Interface : public gale::Context {
|
||||
*/
|
||||
/****************************************************************************************/
|
||||
virtual void setCursor(enum gale::context::cursor _newCursor) {
|
||||
X11_FUNC();
|
||||
if (_newCursor != m_currentCursor) {
|
||||
X11_DEBUG("X11-API: set New Cursor : " << _newCursor);
|
||||
// undefine previous cursors ...
|
||||
@ -964,6 +1048,7 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void grabPointerEvents(bool _status, const vec2& _forcedPosition) {
|
||||
X11_FUNC();
|
||||
if (_status == true) {
|
||||
X11_DEBUG("X11-API: Grab Events");
|
||||
int32_t test = XGrabPointer(m_display,RootWindow(m_display, DefaultScreen(m_display)), True,
|
||||
@ -1011,6 +1096,7 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
bool createX11Context() {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11: CreateX11Context");
|
||||
int x,y, attr_mask;
|
||||
XSizeHints hints;
|
||||
@ -1021,8 +1107,8 @@ class X11Interface : public gale::Context {
|
||||
static char *title = (char*)"Gale";
|
||||
|
||||
// Connect to the X server
|
||||
m_display = XOpenDisplay(nullptr);
|
||||
if(m_display == nullptr) {
|
||||
m_display = XOpenDisplay(NULL);
|
||||
if(m_display == NULL) {
|
||||
GALE_CRITICAL("Could not open display X.");
|
||||
exit(-1);
|
||||
} else {
|
||||
@ -1033,24 +1119,39 @@ class X11Interface : public gale::Context {
|
||||
gale::Dimension::setPixelRatio(vec2((float)DisplayWidth(m_display, Xscreen)/(float)DisplayWidthMM(m_display, Xscreen),
|
||||
(float)DisplayHeight(m_display, Xscreen)/(float)DisplayHeightMM(m_display, Xscreen)),
|
||||
gale::distance::millimeter);
|
||||
// get an appropriate visual
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl);
|
||||
if (m_visual == nullptr) {
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl);
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
// get an appropriate visual
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListDbl);
|
||||
if (m_visual == NULL) {
|
||||
m_visual = glXChooseVisual(m_display, Xscreen, attrListSgl);
|
||||
m_doubleBuffered = false;
|
||||
GALE_ERROR("GL-X singlebuffered rendering will be used, no doublebuffering available");
|
||||
} else {
|
||||
m_doubleBuffered = true;
|
||||
GALE_INFO("GL-X doublebuffered rendering available");
|
||||
}
|
||||
#else
|
||||
m_doubleBuffered = false;
|
||||
GALE_INFO("GL-X singlebuffered rendering will be used, no doublebuffering available");
|
||||
} else {
|
||||
m_doubleBuffered = true;
|
||||
GALE_INFO("GL-X doublebuffered rendering available");
|
||||
}
|
||||
#endif
|
||||
{
|
||||
int32_t glxMajor, glxMinor;
|
||||
glXQueryVersion(m_display, &glxMajor, &glxMinor);
|
||||
#if defined(__TARGET_OS__Web)
|
||||
int32_t glxRev;
|
||||
glfwGetVersion(&glxMajor, &glxMinor, &glxRev);
|
||||
#else
|
||||
glXQueryVersion(m_display, &glxMajor, &glxMinor);
|
||||
#endif
|
||||
GALE_INFO("GLX-Version " << glxMajor << "." << glxMinor);
|
||||
}
|
||||
// Create a colormap - only needed on some X clients, eg. IRIX
|
||||
Window Xroot = RootWindow(m_display, Xscreen);
|
||||
attr.colormap = XCreateColormap(m_display, Xroot, m_visual->visual, AllocNone);
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
if ( m_display != NULL
|
||||
&& m_visual != NULL) {
|
||||
attr.colormap = XCreateColormap(m_display, Xroot, m_visual->visual, AllocNone);
|
||||
}
|
||||
#endif
|
||||
|
||||
attr.border_pixel = 0;
|
||||
attr.event_mask = StructureNotifyMask
|
||||
@ -1086,9 +1187,17 @@ class X11Interface : public gale::Context {
|
||||
Xroot,
|
||||
x, y, tmp_width, tmp_height,
|
||||
1,
|
||||
m_visual->depth,
|
||||
#if defined(__TARGET_OS__Web)
|
||||
0,
|
||||
#else
|
||||
m_visual->depth,
|
||||
#endif
|
||||
InputOutput,
|
||||
m_visual->visual,
|
||||
#if defined(__TARGET_OS__Web)
|
||||
0,
|
||||
#else
|
||||
m_visual->visual,
|
||||
#endif
|
||||
attr_mask, &attr);
|
||||
|
||||
if(!m_WindowHandle) {
|
||||
@ -1113,10 +1222,10 @@ class X11Interface : public gale::Context {
|
||||
StartupState->flags = StateHint;
|
||||
|
||||
XSetWMProperties(m_display, m_WindowHandle,&textprop, &textprop,/* Window title/icon title*/
|
||||
nullptr, 0,/* Argv[], argc for program*/
|
||||
NULL, 0,/* Argv[], argc for program*/
|
||||
&hints, /* Start position/size*/
|
||||
StartupState,/* Iconised/not flag */
|
||||
nullptr);
|
||||
NULL);
|
||||
|
||||
XFree(StartupState);
|
||||
|
||||
@ -1125,15 +1234,15 @@ class X11Interface : public gale::Context {
|
||||
//XIfEvent(m_display, &event, WaitForMapNotify, (char*)&m_WindowHandle);
|
||||
|
||||
|
||||
m_xim = XOpenIM(m_display, nullptr, NULL, NULL);
|
||||
if (m_xim == nullptr) {
|
||||
m_xim = XOpenIM(m_display, NULL, NULL, NULL);
|
||||
if (m_xim == NULL) {
|
||||
GALE_ERROR("Could not open input method");
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
XIMStyles *styles=nullptr;
|
||||
char* failed_arg = XGetIMValues(m_xim, XNQueryInputStyle, &styles, nullptr);
|
||||
if (failed_arg != nullptr) {
|
||||
XIMStyles *styles=NULL;
|
||||
char* failed_arg = XGetIMValues(m_xim, XNQueryInputStyle, &styles, NULL);
|
||||
if (failed_arg != NULL) {
|
||||
GALE_ERROR("XIM Can't get styles");
|
||||
return false;
|
||||
}
|
||||
@ -1141,8 +1250,8 @@ class X11Interface : public gale::Context {
|
||||
GALE_INFO("style " << styles->supported_styles[iii]);
|
||||
}
|
||||
*/
|
||||
m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_WindowHandle, nullptr);
|
||||
if (m_xic == nullptr) {
|
||||
m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_WindowHandle, NULL);
|
||||
if (m_xic == NULL) {
|
||||
GALE_ERROR("Could not open IC");
|
||||
return false;
|
||||
}
|
||||
@ -1160,8 +1269,10 @@ class X11Interface : public gale::Context {
|
||||
return true;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setIcon(const std::string& _inputFile) {
|
||||
#ifdef GALE_BUILD_EGAMI
|
||||
void setIcon(const etk::Uri& _inputFile) {
|
||||
X11_FUNC();
|
||||
#if defined(GALE_BUILD_EGAMI) \
|
||||
&& !defined(__TARGET_OS__Web)
|
||||
egami::Image dataImage = egami::load(_inputFile);
|
||||
// load data
|
||||
if (dataImage.exist() == false) {
|
||||
@ -1184,12 +1295,13 @@ class X11Interface : public gale::Context {
|
||||
GALE_CRITICAL("Unknow thys type of bitDepth : " << depth);
|
||||
return;
|
||||
}
|
||||
char* tmpVal = new char[4*dataImage.getWidth()*dataImage.getHeight()];
|
||||
if (nullptr == tmpVal) {
|
||||
etk::Vector<char> tmpVal;
|
||||
tmpVal.resize(4*dataImage.getWidth()*dataImage.getHeight(), 0);
|
||||
if (tmpVal == NULL) {
|
||||
GALE_CRITICAL("Allocation error ...");
|
||||
return;
|
||||
}
|
||||
char* tmpPointer = tmpVal;
|
||||
char* tmpPointer = &tmpVal[0];
|
||||
switch(depth) {
|
||||
case 16:
|
||||
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
|
||||
@ -1228,13 +1340,17 @@ class X11Interface : public gale::Context {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_display == NULL
|
||||
|| m_visual == NULL) {
|
||||
GALE_ERROR("X11 Can not create Image Icon ==> null on m_display or m_visual");
|
||||
return;
|
||||
}
|
||||
XImage* myImage = XCreateImage(m_display,
|
||||
m_visual->visual,
|
||||
depth,
|
||||
ZPixmap,
|
||||
0,
|
||||
(char*)tmpVal,
|
||||
(char*)&tmpVal[0],
|
||||
dataImage.getWidth(),
|
||||
dataImage.getHeight(),
|
||||
32,
|
||||
@ -1286,7 +1402,7 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
// allocate a WM hints structure.
|
||||
XWMHints* win_hints = XAllocWMHints();
|
||||
if (win_hints == nullptr) {
|
||||
if (win_hints == NULL) {
|
||||
GALE_ERROR("XAllocWMHints - out of memory");
|
||||
return;
|
||||
}
|
||||
@ -1303,13 +1419,13 @@ class X11Interface : public gale::Context {
|
||||
// Note when we free the pixmap ... the icon is removed ... == > this is a real memory leek ...
|
||||
//XFreePixmap(m_display, tmpPixmap);
|
||||
|
||||
myImage->data = nullptr;
|
||||
myImage->data = null;
|
||||
XDestroyImage(myImage);
|
||||
delete[] tmpVal;
|
||||
#endif
|
||||
}
|
||||
/****************************************************************************************/
|
||||
static void setVSync(bool _sync) {
|
||||
X11_FUNC();
|
||||
// Function pointer for the wgl extention function we need to enable/disable
|
||||
typedef int32_t (APIENTRY *PFNWGLSWAPINTERVALPROC)( int );
|
||||
PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0;
|
||||
@ -1318,7 +1434,11 @@ class X11Interface : public gale::Context {
|
||||
GALE_ERROR("Can not set the vertical synchronisation status" << _sync << " (1)");
|
||||
return;
|
||||
} else {
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glXGetProcAddress( (const GLubyte *)"wglSwapIntervalEXT" );
|
||||
#if !defined(__TARGET_OS__Web)
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glXGetProcAddress( (const GLubyte *)"wglSwapIntervalEXT" );
|
||||
#else
|
||||
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glfwGetProcAddress( (const char *)"wglSwapIntervalEXT" );
|
||||
#endif
|
||||
if(wglSwapIntervalEXT) {
|
||||
wglSwapIntervalEXT(_sync);
|
||||
} else {
|
||||
@ -1328,22 +1448,36 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
bool createOGlContext() {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11:CreateOGlContext");
|
||||
/* create a GLX context */
|
||||
GLXContext RenderContext = glXCreateContext(m_display, m_visual, 0, GL_TRUE);
|
||||
/* connect the glx-context to the window */
|
||||
glXMakeCurrent(m_display, m_WindowHandle, RenderContext);
|
||||
if (glXIsDirect(m_display, RenderContext)) {
|
||||
GALE_INFO("XF86 DRI enabled\n");
|
||||
} else {
|
||||
GALE_INFO("XF86 DRI NOT available\n");
|
||||
}
|
||||
#if defined(__TARGET_OS__Web)
|
||||
/* create a GLX context */
|
||||
GContext RenderContext = wglCreateContext(m_display, 0, GL_TRUE);
|
||||
/* connect the glx-context to the window */
|
||||
wglMakeCurrent(m_display, m_WindowHandle, RenderContext);
|
||||
if (glwIsDirect(m_display, RenderContext)) {
|
||||
GALE_INFO("XF86 DRI enabled\n");
|
||||
} else {
|
||||
GALE_INFO("XF86 DRI NOT available\n");
|
||||
}
|
||||
#else
|
||||
/* create a GLX context */
|
||||
GLXContext RenderContext = glXCreateContext(m_display, m_visual, 0, GL_TRUE);
|
||||
/* connect the glx-context to the window */
|
||||
glXMakeCurrent(m_display, m_WindowHandle, RenderContext);
|
||||
if (glXIsDirect(m_display, RenderContext)) {
|
||||
GALE_INFO("XF86 DRI enabled\n");
|
||||
} else {
|
||||
GALE_INFO("XF86 DRI NOT available\n");
|
||||
}
|
||||
#endif
|
||||
// enable vertical synchronisation : (some computer has synchronisation disable)
|
||||
setVSync(true);
|
||||
return true;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setTitle(const std::string& _title) {
|
||||
void setTitle(const etk::String& _title) {
|
||||
X11_FUNC();
|
||||
X11_INFO("X11: set Title (START)");
|
||||
XTextProperty tp;
|
||||
tp.value = (unsigned char *)_title.c_str();
|
||||
@ -1356,14 +1490,16 @@ class X11Interface : public gale::Context {
|
||||
XSetWMIconName(m_display, m_WindowHandle, &tp);
|
||||
X11_INFO("X11: set Title (END)");
|
||||
}
|
||||
void openURL(const std::string& _url) {
|
||||
std::string req = "xdg-open ";
|
||||
void openURL(const etk::String& _url) {
|
||||
X11_FUNC();
|
||||
etk::String req = "xdg-open ";
|
||||
req += _url;
|
||||
system(req.c_str());
|
||||
return;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) {
|
||||
X11_FUNC();
|
||||
switch (_clipboardID) {
|
||||
case gale::context::clipBoard::clipboardSelection:
|
||||
if (m_clipBoardOwnerPrimary == false) {
|
||||
@ -1402,6 +1538,7 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void clipBoardSet(enum gale::context::clipBoard::clipboardListe _clipboardID) {
|
||||
X11_FUNC();
|
||||
switch (_clipboardID) {
|
||||
case gale::context::clipBoard::clipboardSelection:
|
||||
// Request the selection :
|
||||
@ -1424,21 +1561,13 @@ class X11Interface : public gale::Context {
|
||||
}
|
||||
};
|
||||
|
||||
#include <gale/context/X11/Context.hpp>
|
||||
|
||||
/**
|
||||
* @brief Main of the program
|
||||
* @param std IO
|
||||
* @return std IO
|
||||
*/
|
||||
int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
etk::init(_argc, _argv);
|
||||
X11Interface* interface = new X11Interface(_application, _argc, _argv);
|
||||
if (interface == nullptr) {
|
||||
GALE_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
|
||||
return -2;
|
||||
}
|
||||
int32_t retValue = interface->run();
|
||||
delete(interface);
|
||||
interface = nullptr;
|
||||
return retValue;
|
||||
bool gale::context::x11::isBackendPresent() {
|
||||
// TODO : Do it better...
|
||||
return true;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<gale::Context> gale::context::x11::createInstance(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
return ememory::makeShared<X11Interface>(_application, _argc, _argv);
|
||||
}
|
||||
|
26
gale/context/X11/Context.hpp
Normal file
26
gale/context/X11/Context.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace gale {
|
||||
namespace context {
|
||||
namespace x11 {
|
||||
/**
|
||||
* @brief Check if the backend can be instanciate
|
||||
* @return true if the backend is availlable (false otherwise)
|
||||
*/
|
||||
bool isBackendPresent();
|
||||
/**
|
||||
* @brief Create the context main intance
|
||||
* @param[in] _application pointer on the application
|
||||
* @param[in] _argc number of parameter
|
||||
* @param[in] _argv araay of pointer of each parameters
|
||||
* @return instance on the generic created context
|
||||
*/
|
||||
ememory::SharedPtr<gale::Context> createInstance(gale::Application* _application, int _argc, const char *_argv[]);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
@ -9,6 +9,8 @@
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/context/clipBoard.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::context::clipBoard::clipboardListe);
|
||||
|
||||
/*
|
||||
note: copy id data :
|
||||
@ -17,7 +19,7 @@ note: copy id data :
|
||||
10 : middle button
|
||||
*/
|
||||
//!< Local copy of the clipboards
|
||||
static std::string myCopy[gale::context::clipBoard::clipboardCount];
|
||||
static etk::String myCopy[gale::context::clipBoard::clipboardCount];
|
||||
|
||||
static const char* clipboardDescriptionString[gale::context::clipBoard::clipboardCount+1] = {
|
||||
"clipboard0",
|
||||
@ -35,7 +37,7 @@ static const char* clipboardDescriptionString[gale::context::clipBoard::clipboar
|
||||
"clipboardCount"
|
||||
};
|
||||
|
||||
std::ostream& gale::operator <<(std::ostream& _os, enum gale::context::clipBoard::clipboardListe _obj) {
|
||||
etk::Stream& gale::operator <<(etk::Stream& _os, enum gale::context::clipBoard::clipboardListe _obj) {
|
||||
if (_obj >= 0 && _obj <gale::context::clipBoard::clipboardCount) {
|
||||
_os << clipboardDescriptionString[int32_t(_obj)];
|
||||
} else {
|
||||
@ -45,9 +47,19 @@ std::ostream& gale::operator <<(std::ostream& _os, enum gale::context::clipBoard
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<enum gale::context::clipBoard::clipboardListe>(const enum gale::context::clipBoard::clipboardListe& _obj) {
|
||||
template<> etk::String toString<enum gale::context::clipBoard::clipboardListe>(const enum gale::context::clipBoard::clipboardListe& _obj) {
|
||||
return clipboardDescriptionString[int32_t(_obj)];
|
||||
}
|
||||
|
||||
template <> bool from_string<enum gale::context::clipBoard::clipboardListe>(enum gale::context::clipBoard::clipboardListe& _variableRet, const etk::String& _value) {
|
||||
for (size_t iii=0; iii< sizeof(clipboardDescriptionString); ++iii) {
|
||||
if (_value == clipboardDescriptionString[iii]) {
|
||||
_variableRet = (enum gale::context::clipBoard::clipboardListe)iii;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void gale::context::clipBoard::init() {
|
||||
@ -66,7 +78,7 @@ void gale::context::clipBoard::unInit() {
|
||||
}
|
||||
|
||||
|
||||
void gale::context::clipBoard::set(enum gale::context::clipBoard::clipboardListe _clipboardID, const std::string& _data) {
|
||||
void gale::context::clipBoard::set(enum gale::context::clipBoard::clipboardListe _clipboardID, const etk::String& _data) {
|
||||
// check if ID is correct
|
||||
if(0 == _data.size()) {
|
||||
GALE_INFO("request a copy of nothing");
|
||||
@ -103,7 +115,7 @@ void gale::context::clipBoard::request(enum gale::context::clipBoard::clipboardL
|
||||
}
|
||||
|
||||
|
||||
void gale::context::clipBoard::setSystem(enum gale::context::clipBoard::clipboardListe _clipboardID, const std::string& _data) {
|
||||
void gale::context::clipBoard::setSystem(enum gale::context::clipBoard::clipboardListe _clipboardID, const etk::String& _data) {
|
||||
if(_clipboardID >= gale::context::clipBoard::clipboardCount) {
|
||||
GALE_WARNING("request ClickBoard id error");
|
||||
return;
|
||||
@ -113,8 +125,8 @@ void gale::context::clipBoard::setSystem(enum gale::context::clipBoard::clipboar
|
||||
}
|
||||
|
||||
|
||||
const std::string& gale::context::clipBoard::get(enum gale::context::clipBoard::clipboardListe _clipboardID) {
|
||||
static const std::string emptyString("");
|
||||
const etk::String& gale::context::clipBoard::get(enum gale::context::clipBoard::clipboardListe _clipboardID) {
|
||||
static const etk::String emptyString("");
|
||||
if(_clipboardID >= gale::context::clipBoard::clipboardCount) {
|
||||
GALE_WARNING("request ClickBoard id error");
|
||||
return emptyString;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -32,7 +32,7 @@ namespace gale {
|
||||
* @param[in] _clipboardID Select the specific ID of the clipboard
|
||||
* @param[in] _data The string that might be send to the clipboard
|
||||
*/
|
||||
void set(enum gale::context::clipBoard::clipboardListe _clipboardID, const std::string& _data);
|
||||
void set(enum gale::context::clipBoard::clipboardListe _clipboardID, const etk::String& _data);
|
||||
/**
|
||||
* @brief Call system to request the current clipboard.
|
||||
* @note Due to some system that manage the clipboard request asynchronous (like X11) and gale managing the system with only one thread,
|
||||
@ -47,7 +47,7 @@ namespace gale {
|
||||
* @param[in] _clipboardID selected clipboard ID
|
||||
* @param[in] _data new buffer data
|
||||
*/
|
||||
void setSystem(enum gale::context::clipBoard::clipboardListe _clipboardID,const std::string& _data);
|
||||
void setSystem(enum gale::context::clipBoard::clipboardListe _clipboardID,const etk::String& _data);
|
||||
/**
|
||||
* @brief get the gale internal buffer of the curent clipboard. The end user can use it when he receive the event in
|
||||
* the widget : @ref onEventClipboard == > we can nothe this function is the only one which permit it.
|
||||
@ -55,7 +55,7 @@ namespace gale {
|
||||
* @param[in] _clipboardID selected clipboard ID
|
||||
* @return the requested buffer
|
||||
*/
|
||||
const std::string& get(enum gale::context::clipBoard::clipboardListe _clipboardID);
|
||||
const etk::String& get(enum gale::context::clipBoard::clipboardListe _clipboardID);
|
||||
|
||||
// internal section
|
||||
|
||||
@ -72,5 +72,5 @@ namespace gale {
|
||||
/**
|
||||
* @brief Debug operator To display the curent element in a Human redeable information
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, const enum gale::context::clipBoard::clipboardListe _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, const enum gale::context::clipBoard::clipboardListe _obj);
|
||||
}
|
||||
|
@ -1,17 +1,20 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <vector>
|
||||
#include <etk/Vector.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::context::CommandLine);
|
||||
|
||||
void gale::context::CommandLine::parse(int32_t _argc, const char* _argv[]) {
|
||||
for (int32_t i=1 ; i<_argc; i++) {
|
||||
GALE_INFO("commandLine : \"" << _argv[i] << "\"" );
|
||||
m_listArgs.push_back(_argv[i]);
|
||||
m_listArgs.pushBack(_argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,8 +22,8 @@ int32_t gale::context::CommandLine::size() {
|
||||
return m_listArgs.size();
|
||||
}
|
||||
|
||||
const std::string& gale::context::CommandLine::get(int32_t _id) {
|
||||
static const std::string errorArg("");
|
||||
const etk::String& gale::context::CommandLine::get(int32_t _id) {
|
||||
static const etk::String errorArg("");
|
||||
if ( _id < 0
|
||||
&& _id >= (int64_t)m_listArgs.size()) {
|
||||
return errorArg;
|
||||
@ -28,8 +31,8 @@ const std::string& gale::context::CommandLine::get(int32_t _id) {
|
||||
return m_listArgs[_id];
|
||||
}
|
||||
|
||||
void gale::context::CommandLine::add(const std::string& _newElement) {
|
||||
m_listArgs.push_back(_newElement);
|
||||
void gale::context::CommandLine::add(const etk::String& _newElement) {
|
||||
m_listArgs.pushBack(_newElement);
|
||||
}
|
||||
|
||||
void gale::context::CommandLine::remove(int32_t _id) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -11,7 +11,7 @@ namespace gale {
|
||||
namespace context {
|
||||
class CommandLine {
|
||||
private:
|
||||
std::vector<std::string> m_listArgs; //!< list of all argument parsed
|
||||
etk::Vector<etk::String> m_listArgs; //!< list of all argument parsed
|
||||
public:
|
||||
/**
|
||||
* @brief Parse the command line parameters
|
||||
@ -26,12 +26,12 @@ namespace gale {
|
||||
* @brief get an element with a specific ID
|
||||
* @return _id The cmdLine Id element
|
||||
*/
|
||||
const std::string& get(int32_t _id);
|
||||
const etk::String& get(int32_t _id);
|
||||
/**
|
||||
* @brief add one element at the Command line
|
||||
* @param[in] _newElement String in the input that might be added.
|
||||
*/
|
||||
void add(const std::string& _newElement);
|
||||
void add(const etk::String& _newElement);
|
||||
/**
|
||||
* @brief remove an element
|
||||
* @param[in] _id Id of the element
|
||||
|
@ -1,10 +1,12 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/context/cursor.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::context::cursor);
|
||||
|
||||
static const char* cursorDescriptionString[] = {
|
||||
"cursor::arrow",
|
||||
@ -30,7 +32,7 @@ static const char* cursorDescriptionString[] = {
|
||||
"cursor::none"
|
||||
};
|
||||
|
||||
std::ostream& gale::context::operator <<(std::ostream& _os, enum gale::context::cursor _obj) {
|
||||
etk::Stream& gale::context::operator <<(etk::Stream& _os, enum gale::context::cursor _obj) {
|
||||
_os << cursorDescriptionString[int32_t(_obj)];
|
||||
return _os;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -35,7 +35,7 @@ namespace gale {
|
||||
/**
|
||||
* @brief Debug operator To display the curent element in a Human readable information
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, enum gale::context::cursor _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, enum gale::context::cursor _obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -36,11 +36,11 @@
|
||||
#include <gale/renderer/eSystem.hpp>
|
||||
#include <gale/openGL/openGL.hpp>
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
}
|
||||
#include <directfb.h>
|
||||
#include <directfbgl.h>
|
||||
|
||||
@ -50,7 +50,7 @@ int64_t guiInterface::getTime() {
|
||||
int ret = clock_gettime(CLOCK_REALTIME, &now);
|
||||
if (ret != 0) {
|
||||
// Error to get the time ...
|
||||
now.tv_sec = time(nullptr);
|
||||
now.tv_sec = time(null);
|
||||
now.tv_nsec = 0;
|
||||
}
|
||||
//GALE_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us");
|
||||
@ -66,16 +66,16 @@ bool m_grabAllEvent = false;
|
||||
|
||||
|
||||
// the super interface
|
||||
IDirectFB *dfb = nullptr;
|
||||
IDirectFB *dfb = null;
|
||||
|
||||
// the primary surface (surface of primary layer)
|
||||
IDirectFBSurface *primary = nullptr;
|
||||
IDirectFBSurface *primary = null;
|
||||
|
||||
// the GL context
|
||||
IDirectFBGL *primary_gl = nullptr;
|
||||
IDirectFBGL *primary_gl = null;
|
||||
|
||||
// event buffer
|
||||
IDirectFBEventBuffer *events = nullptr;
|
||||
IDirectFBEventBuffer *events = null;
|
||||
|
||||
static int screen_width =800;
|
||||
static int screen_height = 600;
|
||||
@ -86,12 +86,12 @@ static int screen_height = 600;
|
||||
* @param title New desired title
|
||||
* @return ---
|
||||
*/
|
||||
void guiInterface::setTitle(std::string& title) {
|
||||
void guiInterface::setTitle(etk::String& title) {
|
||||
// TODO : ...
|
||||
}
|
||||
|
||||
|
||||
void guiInterface::setIcon(std::string inputFile) {
|
||||
void guiInterface::setIcon(etk::String inputFile) {
|
||||
// TODO : ...
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ void DirectFB_Init(int argc, const char *argv[]) {
|
||||
primary->setDstBlendFunction(primary, DSBF_SRCALPHA);
|
||||
primary->setDrawingFlags(primary, DSDRAW_BLEND);
|
||||
|
||||
primary->Blit(primary, primary, nullptr, 0, 0);
|
||||
primary->Blit(primary, primary, null, 0, 0);
|
||||
|
||||
|
||||
GALE_INFO("call getSize");
|
||||
@ -170,7 +170,7 @@ void DirectFB_Init(int argc, const char *argv[]) {
|
||||
}
|
||||
|
||||
GALE_INFO("call Flip");
|
||||
primary->Flip(primary, nullptr, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
|
||||
primary->Flip(primary, null, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
|
||||
|
||||
// NOTE : we need to force it on X11 display ...
|
||||
GALE_INFO("call getGL");
|
||||
@ -207,7 +207,7 @@ void DirectFB_Run() {
|
||||
primary->FillRectangle(primary, 0, 0, screen_width, screen_height);
|
||||
primary->setColor (primary, 0xFF, (uint8_t)position, 0x00, 0xFF);
|
||||
primary->FillRectangle(primary, position, position, 300, 300);
|
||||
primary->Flip(primary, nullptr, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
|
||||
primary->Flip(primary, null, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
|
||||
position++;
|
||||
if (position>600) {
|
||||
position = 0;
|
||||
@ -229,7 +229,7 @@ void DirectFB_Run() {
|
||||
GALE_ERROR("primary_gl->Unlock");
|
||||
DirectFBErrorFatal("primary_gl->Unlock", err);
|
||||
}
|
||||
primary->Flip(primary, nullptr, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
|
||||
primary->Flip(primary, null, (DFBSurfaceFlipFlags)0);//DSFLIP_ONSYNC);
|
||||
}
|
||||
|
||||
while (events->getEvent(events, DFB_EVENT(&evt)) == DFB_OK) {
|
||||
|
230
gale/context/simulation/Context.cpp
Normal file
230
gale/context/simulation/Context.cpp
Normal file
@ -0,0 +1,230 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
}
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <etk/tool.hpp>
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/key/key.hpp>
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <etk/etk.hpp>
|
||||
|
||||
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
|
||||
|
||||
static etk::Vector<etk::String> localSplit(const etk::String& _input) {
|
||||
etk::Vector<etk::String> out;
|
||||
char lastValue = '\0';
|
||||
etk::String tmpInput;
|
||||
for(auto &it : _input) {
|
||||
if ( lastValue == ':'
|
||||
&& it == ':') {
|
||||
tmpInput += "::";
|
||||
lastValue = '\0';
|
||||
continue;
|
||||
} else if (lastValue == ':') {
|
||||
out.pushBack(tmpInput);
|
||||
tmpInput = "";
|
||||
tmpInput += it;
|
||||
} else if (it == ':') {
|
||||
// nothing to do ...
|
||||
} else {
|
||||
tmpInput += it;
|
||||
}
|
||||
lastValue = it;
|
||||
|
||||
}
|
||||
if (tmpInput!="") {
|
||||
out.pushBack(tmpInput);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class SimulationInterface : public gale::Context {
|
||||
private:
|
||||
gale::key::Special m_guiKeyBoardMode;
|
||||
bool m_run;
|
||||
public:
|
||||
SimulationInterface(gale::Application* _application, int32_t _argc, const char* _argv[]) :
|
||||
gale::Context(_application, _argc, _argv) {
|
||||
GALE_INFO("SIMU:INIT");
|
||||
m_run = true;
|
||||
start2ndThreadProcessing();
|
||||
}
|
||||
|
||||
~SimulationInterface() {
|
||||
// TODO : ...
|
||||
}
|
||||
|
||||
int32_t run() {
|
||||
m_simulationFile = etk::uri::get(m_simulationUri);
|
||||
// Try to open the file of simulation:
|
||||
if ( m_simulationFile == null
|
||||
|| m_simulationFile->open(etk::io::OpenMode::Read) == false) {
|
||||
GALE_ERROR("can not open the simulation file");
|
||||
return -1;
|
||||
}
|
||||
etk::String action;
|
||||
// main cycle
|
||||
while(m_run == true) {
|
||||
bool lineIsOk = m_simulationFile->gets(action);
|
||||
if (lineIsOk == false) {
|
||||
// reach end of simulation file;
|
||||
return 0;
|
||||
}
|
||||
if (action.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
GALE_VERBOSE("SIM-EVENT : '" << action << "'");
|
||||
etk::Vector<etk::String> pads = localSplit(action);
|
||||
GALE_DEBUG(" " << pads);
|
||||
// The first is the time ...
|
||||
if (pads.size() < 2) {
|
||||
GALE_ERROR("Simu: Can not parse: '" << action << "'");
|
||||
continue;
|
||||
}
|
||||
uint64_t time = etk::string_to_uint64_t(pads[0]);
|
||||
etk::String localAction = pads[1];
|
||||
if (localAction == "INIT") {
|
||||
// nothing to do ...
|
||||
} else if (localAction == "RECALCULATE_SIZE") {
|
||||
//requestUpdateSize();
|
||||
} else if (localAction == "RESIZE") {
|
||||
// vec2
|
||||
OS_Resize(vec2(pads[2]));
|
||||
} else if (localAction == "INPUT") {
|
||||
// string type
|
||||
// string status
|
||||
// int32_t pointerID
|
||||
// vec2 pos
|
||||
enum gale::key::type type;
|
||||
etk::from_string(type, pads[2]);
|
||||
enum gale::key::status status;
|
||||
etk::from_string(status, pads[3]);
|
||||
int32_t pointerID = etk::string_to_int32_t(pads[4]);
|
||||
vec2 pos(pads[5]);
|
||||
OS_SetInput(type, status, pointerID, pos);
|
||||
|
||||
} else if (localAction == "KEYBOARD") {
|
||||
// string special
|
||||
// string type
|
||||
// int32_t state
|
||||
// vec2 value
|
||||
|
||||
gale::key::Special special;
|
||||
etk::from_string(special, pads[2]);
|
||||
enum gale::key::keyboard type;
|
||||
etk::from_string(type, pads[3]);
|
||||
enum gale::key::status status;
|
||||
etk::from_string(status, pads[4]);
|
||||
char32_t valChar = etk::string_to_uint64_t(pads[5]);
|
||||
|
||||
OS_setKeyboard(special, type, status, false, valChar);
|
||||
|
||||
} else if (localAction == "VIEW") {
|
||||
// bool ==> hide, show ...
|
||||
if (etk::string_to_bool(pads[2]) == true) {
|
||||
OS_Show();
|
||||
} else {
|
||||
OS_Hide();
|
||||
}
|
||||
} else if (localAction == "CLIPBOARD_ARRIVE") {
|
||||
// int32_t clipboard ID
|
||||
enum gale::context::clipBoard::clipboardListe clipboardId;
|
||||
etk::from_string(clipboardId, pads[2]);
|
||||
OS_ClipBoardArrive(clipboardId);
|
||||
} else if (localAction == "DRAW") {
|
||||
// bool ==> display every time ...
|
||||
OS_Draw(etk::string_to_bool(pads[2]));
|
||||
} else {
|
||||
GALE_ERROR("unknow event : '" << localAction << "'");
|
||||
}
|
||||
}
|
||||
m_simulationFile->close();
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void stop() {
|
||||
GALE_INFO("SIMU-API: Stop");
|
||||
m_run = false;
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void setSize(const vec2& _size) {
|
||||
GALE_INFO("SIMU-API: changeSize=" << _size);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setFullScreen(bool _status) {
|
||||
GALE_INFO("SIMU-API: changeFullscreen=" << _status);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void grabKeyboardEvents(bool _status) {
|
||||
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void setWindowsDecoration(bool _status) {
|
||||
GALE_INFO("SIMU-API: setWindows Decoration :" << _status);
|
||||
};
|
||||
/****************************************************************************************/
|
||||
virtual void setPos(const vec2& _pos) {
|
||||
GALE_INFO("SIMU-API: changePos=" << _pos);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
virtual void setCursor(enum gale::context::cursor _newCursor) {
|
||||
GALE_INFO("SIMU-API: setCursor=" << _newCursor);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void grabPointerEvents(bool _status, const vec2& _forcedPosition) {
|
||||
GALE_DEBUG("SIMU-API: Grab Events");
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setIcon(const etk::String& _inputFile) {
|
||||
GALE_DEBUG("SIMU set icon " << _inputFile);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void setTitle(const etk::String& _title) {
|
||||
GALE_INFO("SIMU: set Title " << _title);
|
||||
}
|
||||
void openURL(const etk::String& _url) {
|
||||
GALE_INFO("SIMU: open URL " << _url);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) {
|
||||
GALE_INFO("SIMU: clipBoardGet " << _clipboardID);
|
||||
}
|
||||
/****************************************************************************************/
|
||||
void clipBoardSet(enum gale::context::clipBoard::clipboardListe _clipboardID) {
|
||||
GALE_INFO("SIMU: clipBoardSet " << _clipboardID);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#include <gale/context/simulation/Context.hpp>
|
||||
|
||||
bool gale::context::simulation::isBackendPresent() {
|
||||
// TODO : Do it better...
|
||||
return true;
|
||||
}
|
||||
|
||||
ememory::SharedPtr<gale::Context> gale::context::simulation::createInstance(gale::Application* _application, int _argc, const char *_argv[]) {
|
||||
// Disable openGL:
|
||||
gale::openGL::startSimulationMode();
|
||||
return ememory::makeShared<SimulationInterface>(_application, _argc, _argv);
|
||||
}
|
26
gale/context/simulation/Context.hpp
Normal file
26
gale/context/simulation/Context.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace gale {
|
||||
namespace context {
|
||||
namespace simulation {
|
||||
/**
|
||||
* @brief Check if the backend can be instanciate
|
||||
* @return true if the backend is availlable (false otherwise)
|
||||
*/
|
||||
bool isBackendPresent();
|
||||
/**
|
||||
* @brief Create the context main intance
|
||||
* @param[in] _application pointer on the application
|
||||
* @param[in] _argc number of parameter
|
||||
* @param[in] _argv araay of pointer of each parameters
|
||||
* @return instance on the generic created context
|
||||
*/
|
||||
ememory::SharedPtr<gale::Context> createInstance(gale::Application* _application, int _argc, const char *_argv[]);
|
||||
}
|
||||
}
|
||||
}
|
2049
gale/context/wayland/Context.cpp
Normal file
2049
gale/context/wayland/Context.cpp
Normal file
File diff suppressed because it is too large
Load Diff
26
gale/context/wayland/Context.hpp
Normal file
26
gale/context/wayland/Context.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace gale {
|
||||
namespace context {
|
||||
namespace wayland {
|
||||
/**
|
||||
* @brief Check if the backend can be instanciate
|
||||
* @return true if the backend is availlable (false otherwise)
|
||||
*/
|
||||
bool isBackendPresent();
|
||||
/**
|
||||
* @brief Create the context main intance
|
||||
* @param[in] _application pointer on the application
|
||||
* @param[in] _argc number of parameter
|
||||
* @param[in] _argv araay of pointer of each parameters
|
||||
* @return instance on the generic created context
|
||||
*/
|
||||
ememory::SharedPtr<gale::Context> createInstance(gale::Application* _application, int _argc, const char *_argv[]);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/debug.hpp>
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
@ -1,22 +1,21 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
|
||||
#include <gale/context/commandLine.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/Dimension.hpp>
|
||||
#include <chrono>
|
||||
|
||||
#ifndef GALE_VERSION
|
||||
#define GALE_VERSION "0.0.0"
|
||||
#endif
|
||||
|
||||
std::string gale::getCompilationMode() {
|
||||
etk::String gale::getCompilationMode() {
|
||||
#ifdef MODE_RELEASE
|
||||
return "Release";
|
||||
#else
|
||||
@ -24,7 +23,7 @@ std::string gale::getCompilationMode() {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string gale::getBoardType() {
|
||||
etk::String gale::getBoardType() {
|
||||
#ifdef __TARGET_OS__Linux
|
||||
return "Linux";
|
||||
#elif defined(__TARGET_OS__Android)
|
||||
@ -40,7 +39,7 @@ std::string gale::getBoardType() {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string gale::getVersion() {
|
||||
etk::String gale::getVersion() {
|
||||
return GALE_VERSION;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -21,21 +21,21 @@ namespace gale {
|
||||
* @param[in] _argv Standard argv
|
||||
* @return normal error int for the application error management
|
||||
*/
|
||||
int32_t run(gale::Application* _application, int32_t _argc = 0, const char* _argv[] = nullptr);
|
||||
int32_t run(gale::Application* _application, int32_t _argc = 0, const char* _argv[] = null);
|
||||
/**
|
||||
* @brief get GALE version
|
||||
* @return The string that describe gale version
|
||||
*/
|
||||
std::string getVersion();
|
||||
etk::String getVersion();
|
||||
/**
|
||||
* @brief get compilation mode (release/debug)
|
||||
* @return the string of the mode of commpilation
|
||||
*/
|
||||
std::string getCompilationMode();
|
||||
etk::String getCompilationMode();
|
||||
/**
|
||||
* @brief get the board type (Android/Linux/MacOs/...)
|
||||
* @return the string of the mode of commpilation
|
||||
*/
|
||||
std::string getBoardType();
|
||||
etk::String getBoardType();
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,29 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/key/Special.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::key::Special);
|
||||
|
||||
#define GALE_FLAG_KEY_CAPS_LOCK 0x00000001
|
||||
#define GALE_FLAG_KEY_SHIFT 0x00000002
|
||||
#define GALE_FLAG_KEY_CTRL 0x00000004
|
||||
#define GALE_FLAG_KEY_META 0x00000008
|
||||
#define GALE_FLAG_KEY_ALT 0x00000010
|
||||
#define GALE_FLAG_KEY_ALTGR 0x00000020
|
||||
#define GALE_FLAG_KEY_NUM_LOCK 0x00000040
|
||||
#define GALE_FLAG_KEY_INSERT 0x00000080
|
||||
#define GALE_FLAG_KEY_CAPS_LOCK 0x00000001
|
||||
#define GALE_FLAG_KEY_SHIFT 0x00000030
|
||||
#define GALE_FLAG_KEY_SHIFT_LEFT 0x00000010
|
||||
#define GALE_FLAG_KEY_SHIFT_RIGHT 0x00000020
|
||||
#define GALE_FLAG_KEY_CTRL 0x00000300
|
||||
#define GALE_FLAG_KEY_CTRL_LEFT 0x00000100
|
||||
#define GALE_FLAG_KEY_CTRL_RIGHT 0x00000200
|
||||
#define GALE_FLAG_KEY_META 0x00003000
|
||||
#define GALE_FLAG_KEY_META_LEFT 0x00001000
|
||||
#define GALE_FLAG_KEY_META_RIGHT 0x00002000
|
||||
#define GALE_FLAG_KEY_ALT 0x00030000
|
||||
#define GALE_FLAG_KEY_ALT_LEFT 0x00010000
|
||||
#define GALE_FLAG_KEY_ALT_RIGHT 0x00020000
|
||||
#define GALE_FLAG_KEY_NUM_LOCK 0x00000002
|
||||
#define GALE_FLAG_KEY_INSERT 0x00000003
|
||||
|
||||
// TODO : Update to support the Left and right of some key ...
|
||||
|
||||
@ -31,22 +40,28 @@ void gale::key::Special::update(enum gale::key::keyboard _move, bool _isDown) {
|
||||
setCapsLock(_isDown);
|
||||
break;
|
||||
case keyboard::shiftLeft:
|
||||
setShiftLeft(_isDown);
|
||||
break;
|
||||
case keyboard::shiftRight:
|
||||
setShift(_isDown);
|
||||
setShiftRight(_isDown);
|
||||
break;
|
||||
case keyboard::ctrlLeft:
|
||||
setCtrlLeft(_isDown);
|
||||
break;
|
||||
case keyboard::ctrlRight:
|
||||
setCtrl(_isDown);
|
||||
setCtrlRight(_isDown);
|
||||
break;
|
||||
case keyboard::metaLeft:
|
||||
setMetaLeft(_isDown);
|
||||
break;
|
||||
case keyboard::metaRight:
|
||||
setMeta(_isDown);
|
||||
setMetaRight(_isDown);
|
||||
break;
|
||||
case keyboard::alt:
|
||||
setAlt(_isDown);
|
||||
case keyboard::altLeft:
|
||||
setAltLeft(_isDown);
|
||||
break;
|
||||
case keyboard::altGr:
|
||||
setAltGr(_isDown);
|
||||
case keyboard::altRight:
|
||||
setAltRight(_isDown);
|
||||
break;
|
||||
case keyboard::numLock:
|
||||
setNumLock(_isDown);
|
||||
@ -56,165 +71,154 @@ void gale::key::Special::update(enum gale::key::keyboard _move, bool _isDown) {
|
||||
}
|
||||
}
|
||||
|
||||
bool gale::key::Special::getCapsLock() const {
|
||||
if ((m_value & GALE_FLAG_KEY_CAPS_LOCK) != 0) {
|
||||
return true;
|
||||
bool gale::key::Special::get(enum gale::key::keyboard _move) {
|
||||
switch (_move) {
|
||||
case keyboard::insert:
|
||||
return getInsert();
|
||||
case keyboard::capLock:
|
||||
return getCapsLock();
|
||||
case keyboard::shiftLeft:
|
||||
return getShiftLeft();
|
||||
case keyboard::shiftRight:
|
||||
return getShiftRight();
|
||||
case keyboard::ctrlLeft:
|
||||
return getCtrlLeft();
|
||||
case keyboard::ctrlRight:
|
||||
return getCtrlRight();
|
||||
case keyboard::metaLeft:
|
||||
return getMetaLeft();
|
||||
case keyboard::metaRight:
|
||||
return getMetaRight();
|
||||
case keyboard::altLeft:
|
||||
return getAltLeft();
|
||||
case keyboard::altRight:
|
||||
return getAltRight();
|
||||
case keyboard::numLock:
|
||||
return getNumLock();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void gale::key::Special::setCapsLock(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_CAPS_LOCK) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_CAPS_LOCK;
|
||||
|
||||
|
||||
void gale::key::Special::setFlag(uint32_t _flag, bool _isDown) {
|
||||
if ((m_value & _flag) != 0) {
|
||||
if (_isDown == false) {
|
||||
m_value -= _flag;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_CAPS_LOCK;
|
||||
if (_isDown == true) {
|
||||
m_value += _flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool gale::key::Special::getFlag(uint32_t _flag) const {
|
||||
if ((m_value & _flag) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
bool gale::key::Special::getCapsLock() const {
|
||||
return getFlag(GALE_FLAG_KEY_CAPS_LOCK);
|
||||
}
|
||||
void gale::key::Special::setCapsLock(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_CAPS_LOCK, _value);
|
||||
}
|
||||
|
||||
bool gale::key::Special::getShift() const {
|
||||
if ((m_value & GALE_FLAG_KEY_SHIFT) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getFlag(GALE_FLAG_KEY_SHIFT);
|
||||
}
|
||||
void gale::key::Special::setShift(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_SHIFT) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_SHIFT;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_SHIFT;
|
||||
}
|
||||
}
|
||||
bool gale::key::Special::getShiftLeft() const {
|
||||
return getFlag(GALE_FLAG_KEY_SHIFT_LEFT);
|
||||
}
|
||||
bool gale::key::Special::getShiftRight() const {
|
||||
return getFlag(GALE_FLAG_KEY_SHIFT_RIGHT);
|
||||
}
|
||||
void gale::key::Special::setShiftLeft(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_SHIFT_LEFT, _value);
|
||||
}
|
||||
void gale::key::Special::setShiftRight(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_SHIFT_RIGHT, _value);
|
||||
}
|
||||
|
||||
bool gale::key::Special::getCtrl() const {
|
||||
if ((m_value & GALE_FLAG_KEY_CTRL) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getFlag(GALE_FLAG_KEY_CTRL);
|
||||
}
|
||||
void gale::key::Special::setCtrl(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_CTRL) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_CTRL;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_CTRL;
|
||||
}
|
||||
}
|
||||
bool gale::key::Special::getCtrlLeft() const {
|
||||
return getFlag(GALE_FLAG_KEY_CTRL_LEFT);
|
||||
}
|
||||
bool gale::key::Special::getCtrlRight() const {
|
||||
return getFlag(GALE_FLAG_KEY_CTRL_RIGHT);
|
||||
}
|
||||
void gale::key::Special::setCtrlLeft(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_CTRL_LEFT, _value);
|
||||
}
|
||||
void gale::key::Special::setCtrlRight(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_CTRL_RIGHT, _value);
|
||||
}
|
||||
|
||||
bool gale::key::Special::getMeta() const {
|
||||
if ((m_value & GALE_FLAG_KEY_META) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getFlag(GALE_FLAG_KEY_META);
|
||||
}
|
||||
void gale::key::Special::setMeta(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_META) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_META;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_META;
|
||||
}
|
||||
}
|
||||
bool gale::key::Special::getMetaLeft() const {
|
||||
return getFlag(GALE_FLAG_KEY_META_LEFT);
|
||||
}
|
||||
bool gale::key::Special::getMetaRight() const {
|
||||
return getFlag(GALE_FLAG_KEY_META_RIGHT);
|
||||
}
|
||||
void gale::key::Special::setMetaLeft(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_META_LEFT, _value);
|
||||
}
|
||||
void gale::key::Special::setMetaRight(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_META_RIGHT, _value);
|
||||
}
|
||||
|
||||
bool gale::key::Special::getAlt() const {
|
||||
if ((m_value & GALE_FLAG_KEY_ALT) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getFlag(GALE_FLAG_KEY_ALT);
|
||||
}
|
||||
void gale::key::Special::setAlt(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_ALT) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_ALT;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_ALT;
|
||||
}
|
||||
}
|
||||
bool gale::key::Special::getAltLeft() const {
|
||||
return getFlag(GALE_FLAG_KEY_ALT_LEFT);
|
||||
}
|
||||
|
||||
bool gale::key::Special::getAltGr() const {
|
||||
if ((m_value & GALE_FLAG_KEY_ALTGR) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
bool gale::key::Special::getAltRight() const {
|
||||
return getFlag(GALE_FLAG_KEY_ALT_RIGHT);
|
||||
}
|
||||
void gale::key::Special::setAltGr(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_ALTGR) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_ALTGR;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_ALTGR;
|
||||
}
|
||||
}
|
||||
void gale::key::Special::setAltLeft(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_ALT_LEFT, _value);
|
||||
}
|
||||
void gale::key::Special::setAltRight(bool _value) {
|
||||
setFlag(GALE_FLAG_KEY_ALT_RIGHT, _value);
|
||||
}
|
||||
|
||||
bool gale::key::Special::getNumLock() const {
|
||||
if ((m_value & GALE_FLAG_KEY_NUM_LOCK) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getFlag(GALE_FLAG_KEY_NUM_LOCK);
|
||||
}
|
||||
void gale::key::Special::setNumLock(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_NUM_LOCK) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_NUM_LOCK;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_NUM_LOCK;
|
||||
}
|
||||
}
|
||||
setFlag(GALE_FLAG_KEY_NUM_LOCK, _value);
|
||||
}
|
||||
|
||||
bool gale::key::Special::getInsert() const {
|
||||
if ((m_value & GALE_FLAG_KEY_INSERT) != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getFlag(GALE_FLAG_KEY_INSERT);
|
||||
}
|
||||
void gale::key::Special::setInsert(bool _value) {
|
||||
if ((m_value & GALE_FLAG_KEY_INSERT) != 0) {
|
||||
if (_value == false) {
|
||||
m_value -= GALE_FLAG_KEY_INSERT;
|
||||
}
|
||||
} else {
|
||||
if (_value == true) {
|
||||
m_value += GALE_FLAG_KEY_INSERT;
|
||||
}
|
||||
}
|
||||
setFlag(GALE_FLAG_KEY_INSERT, _value);
|
||||
}
|
||||
|
||||
std::ostream& gale::key::operator <<(std::ostream& _os, const gale::key::Special& _obj) {
|
||||
etk::Stream& gale::key::operator <<(etk::Stream& _os, const gale::key::Special& _obj) {
|
||||
_os << " capLock=" << _obj.getCapsLock();
|
||||
_os << " shift=" << _obj.getShift();
|
||||
_os << " ctrl=" << _obj.getCtrl();
|
||||
_os << " meta=" << _obj.getMeta();
|
||||
_os << " alt=" << _obj.getAlt();
|
||||
_os << " altGr=" << _obj.getAltGr();
|
||||
_os << " verNum=" << _obj.getNumLock();
|
||||
_os << " insert=" << _obj.getInsert();
|
||||
return _os;
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<gale::key::Special>(const gale::key::Special& _obj) {
|
||||
std::string out;
|
||||
template<> etk::String toString<gale::key::Special>(const gale::key::Special& _obj) {
|
||||
etk::String out;
|
||||
if (_obj.getCapsLock() == true) {
|
||||
out += "CAPS";
|
||||
}
|
||||
@ -223,30 +227,44 @@ namespace etk {
|
||||
out += "|";
|
||||
}
|
||||
out += "SHIFT";
|
||||
if (_obj.getShiftLeft() == false) {
|
||||
out += "-RIGHT";
|
||||
} else if (_obj.getShiftRight() == false) {
|
||||
out += "-LEFT";
|
||||
}
|
||||
}
|
||||
if (_obj.getCtrl() == true) {
|
||||
if (out.size() > 0) {
|
||||
out += "|";
|
||||
}
|
||||
out += "CTRL";
|
||||
if (_obj.getCtrlLeft() == false) {
|
||||
out += "-RIGHT";
|
||||
} else if (_obj.getCtrlRight() == false) {
|
||||
out += "-LEFT";
|
||||
}
|
||||
}
|
||||
if (_obj.getMeta() == true) {
|
||||
if (out.size() > 0) {
|
||||
out += "|";
|
||||
}
|
||||
out += "META";
|
||||
if (_obj.getMetaLeft() == false) {
|
||||
out += "-RIGHT";
|
||||
} else if (_obj.getMetaRight() == false) {
|
||||
out += "-LEFT";
|
||||
}
|
||||
}
|
||||
if (_obj.getAlt() == true) {
|
||||
if (out.size() > 0) {
|
||||
out += "|";
|
||||
}
|
||||
out += "ALT";
|
||||
}
|
||||
if (_obj.getAltGr() == true) {
|
||||
if (out.size() > 0) {
|
||||
out += "|";
|
||||
if (_obj.getAltLeft() == false) {
|
||||
out += "-RIGHT";
|
||||
} else if (_obj.getAltRight() == false) {
|
||||
out += "-LEFT";
|
||||
}
|
||||
out += "ALTGR";
|
||||
}
|
||||
if (_obj.getNumLock() == true) {
|
||||
if (out.size() > 0) {
|
||||
@ -262,4 +280,50 @@ namespace etk {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
template <> bool from_string<gale::key::Special>(gale::key::Special& _variableRet, const etk::String& _value) {
|
||||
gale::key::Special out;
|
||||
etk::Vector<etk::String> listElem = _value.split('|');
|
||||
for (auto &it : listElem) {
|
||||
if (it == "CAPS") {
|
||||
out.setCapsLock(true);
|
||||
} else if (it == "SHIFT") {
|
||||
out.setShiftLeft(true);
|
||||
out.setShiftRight(true);
|
||||
} else if (it == "SHIFT-LEFT") {
|
||||
out.setShiftLeft(true);
|
||||
} else if (it == "SHIFT-RIGHT") {
|
||||
out.setShiftRight(true);
|
||||
} else if (it == "CTRL") {
|
||||
out.setCtrlLeft(true);
|
||||
out.setCtrlRight(true);
|
||||
} else if (it == "CTRL-LEFT") {
|
||||
out.setCtrlLeft(true);
|
||||
} else if (it == "CTRL-RIGHT") {
|
||||
out.setCtrlRight(true);
|
||||
} else if (it == "META") {
|
||||
out.setMetaLeft(true);
|
||||
out.setMetaRight(true);
|
||||
} else if (it == "META-LEFT") {
|
||||
out.setMetaLeft(true);
|
||||
} else if (it == "META-RIGHT") {
|
||||
out.setMetaRight(true);
|
||||
} else if (it == "ALT") {
|
||||
out.setAltLeft(true);
|
||||
out.setAltRight(true);
|
||||
} else if (it == "ALT-LEFT") {
|
||||
out.setAltLeft(true);
|
||||
} else if (it == "ALT-RIGHT") {
|
||||
out.setAltRight(true);
|
||||
} else if (it == "NUM_LOCK") {
|
||||
out.setNumLock(true);
|
||||
} else if (it == "INSERT") {
|
||||
out.setInsert(true);
|
||||
} else {
|
||||
GALE_ERROR("unknow element '" << it << "'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_variableRet = out;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -37,50 +37,114 @@ namespace gale {
|
||||
*/
|
||||
bool getShift() const;
|
||||
/**
|
||||
* @brief Set the current Shift key status
|
||||
* @brief Get the current Shift left key status
|
||||
* @return The Shift value
|
||||
*/
|
||||
bool getShiftLeft() const;
|
||||
/**
|
||||
* @brief Get the current Shift right key status
|
||||
* @return The Shift value
|
||||
*/
|
||||
bool getShiftRight() const;
|
||||
/**
|
||||
* @brief Set the current Shift left key status
|
||||
* @param[in] _value The new Shift value
|
||||
*/
|
||||
void setShift(bool _value);
|
||||
void setShiftLeft(bool _value);
|
||||
/**
|
||||
* @brief Set the current Shift right key status
|
||||
* @param[in] _value The new Shift value
|
||||
*/
|
||||
void setShiftRight(bool _value);
|
||||
/**
|
||||
* @brief Get the Current Control key status
|
||||
* @return The Control value
|
||||
*/
|
||||
bool getCtrl() const;
|
||||
/**
|
||||
* @brief Set the Current Control key status
|
||||
* @brief Get the Current Control left key status
|
||||
* @return The Control value
|
||||
*/
|
||||
bool getCtrlLeft() const;
|
||||
/**
|
||||
* @brief Get the Current Control right key status
|
||||
* @return The Control value
|
||||
*/
|
||||
bool getCtrlRight() const;
|
||||
/**
|
||||
* @brief Set the Current Control left key status
|
||||
* @param[in] _value The new Control value
|
||||
*/
|
||||
void setCtrl(bool _value);
|
||||
void setCtrlLeft(bool _value);
|
||||
/**
|
||||
* @brief Set the Current Control right key status
|
||||
* @param[in] _value The new Control value
|
||||
*/
|
||||
void setCtrlRight(bool _value);
|
||||
/**
|
||||
* @brief Get the current Meta key status (also named windows or apple key)
|
||||
* @return The Meta value (name Windows key, apple key, command key ...)
|
||||
*/
|
||||
bool getMeta() const;
|
||||
/**
|
||||
* @brief Set the current Meta key status (also named windows or apple key)
|
||||
* @brief Get the current Meta left key status (also named windows or apple key)
|
||||
* @return The Meta value (name Windows key, apple key, command key ...)
|
||||
*/
|
||||
bool getMetaLeft() const;
|
||||
/**
|
||||
* @brief Get the current Meta right key status (also named windows or apple key)
|
||||
* @return The Meta value (name Windows key, apple key, command key ...)
|
||||
*/
|
||||
bool getMetaRight() const;
|
||||
/**
|
||||
* @brief Set the current Meta left key status (also named windows or apple key)
|
||||
* @param[in] _value The new Meta value (name Windows key, apple key, command key ...)
|
||||
*/
|
||||
void setMeta(bool _value);
|
||||
void setMetaLeft(bool _value);
|
||||
/**
|
||||
* @brief Set the current Meta right key status (also named windows or apple key)
|
||||
* @param[in] _value The new Meta value (name Windows key, apple key, command key ...)
|
||||
*/
|
||||
void setMetaRight(bool _value);
|
||||
/**
|
||||
* @brief Get the current Alt key status
|
||||
* @return The Alt value
|
||||
*/
|
||||
bool getAlt() const;
|
||||
/**
|
||||
* @brief Set the current Alt key status
|
||||
* @brief Get the current Alt left key status
|
||||
* @return The Alt value
|
||||
*/
|
||||
bool getAltLeft() const;
|
||||
/**
|
||||
* @brief Get the current Alt right key status (alt-gr)
|
||||
* @return The Alt value
|
||||
*/
|
||||
bool getAltRight() const;
|
||||
/**
|
||||
* @brief Set the current Alt left key status
|
||||
* @param[in] _value The new Alt value
|
||||
*/
|
||||
void setAlt(bool _value);
|
||||
void setAltLeft(bool _value);
|
||||
/**
|
||||
* @brief Set the current Alt right key status (alt-gr)
|
||||
* @param[in] _value The new Alt value
|
||||
*/
|
||||
void setAltRight(bool _value);
|
||||
/**
|
||||
* @brief Get the current Alt-Gr key status
|
||||
* @return The Alt-gr value (does not exist on MacOs)
|
||||
*/
|
||||
bool getAltGr() const;
|
||||
bool getAltGr() const {
|
||||
return getAltRight();
|
||||
}
|
||||
/**
|
||||
* @brief Set the current Alt-Gr key status
|
||||
* @param[in] _value The new Alt-gr value (does not exist on MacOs)
|
||||
*/
|
||||
void setAltGr(bool _value);
|
||||
void setAltGr(bool _value) {
|
||||
setAltRight(_value);
|
||||
}
|
||||
/**
|
||||
* @brief Get the current Ver-num key status
|
||||
* @return The Numerical Lock value
|
||||
@ -104,11 +168,32 @@ namespace gale {
|
||||
/**
|
||||
* @brief Update the internal value with the input moving key.
|
||||
* @param[in] _move Moving key.
|
||||
* @param[in] _isFown The Key is pressed or not.
|
||||
* @param[in] _isDown The key is pressed or not.
|
||||
*/
|
||||
void update(enum gale::key::keyboard _move, bool _isDown);
|
||||
/**
|
||||
* @brief Get the value with the input moving key.
|
||||
* @param[in] _move Moving key.
|
||||
* @return true The key is pressed.
|
||||
* @return false The key is released.
|
||||
*/
|
||||
bool get(enum gale::key::keyboard _move);
|
||||
protected:
|
||||
/**
|
||||
* @brief Set the internal value with the input moving FLAG.
|
||||
* @param[in] _flag Moving Flag.
|
||||
* @param[in] _isDown The key is pressed or not.
|
||||
*/
|
||||
void setFlag(uint32_t _flag, bool _isDown);
|
||||
/**
|
||||
* @brief Get the value with the input moving FLAG.
|
||||
* @param[in] _flag Moving internal FLAG.
|
||||
* @return true The key is pressed.
|
||||
* @return false The key is released.
|
||||
*/
|
||||
bool getFlag(uint32_t _flag) const;
|
||||
};
|
||||
std::ostream& operator <<(std::ostream& _os, const gale::key::Special& _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, const gale::key::Special& _obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/key/keyboard.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(enum gale::key::keyboard);
|
||||
|
||||
static const char* keyboardDescriptionString[] = {
|
||||
"keyboard::unknow",
|
||||
@ -41,8 +43,8 @@ static const char* keyboardDescriptionString[] = {
|
||||
"keyboard::ctrlRight",
|
||||
"keyboard::metaLeft",
|
||||
"keyboard::metaRight",
|
||||
"keyboard::alt",
|
||||
"keyboard::altGr",
|
||||
"keyboard::altLeft",
|
||||
"keyboard::altRight",
|
||||
"keyboard::contextMenu",
|
||||
"keyboard::numLock",
|
||||
// harware section:
|
||||
@ -55,14 +57,24 @@ static const char* keyboardDescriptionString[] = {
|
||||
"keyboard::back",
|
||||
};
|
||||
|
||||
std::ostream& gale::key::operator <<(std::ostream& _os, const enum gale::key::keyboard _obj) {
|
||||
etk::Stream& gale::key::operator <<(etk::Stream& _os, const enum gale::key::keyboard _obj) {
|
||||
_os << keyboardDescriptionString[int32_t(_obj)];
|
||||
return _os;
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<enum gale::key::keyboard>(const enum gale::key::keyboard& _obj) {
|
||||
template<> etk::String toString<enum gale::key::keyboard>(const enum gale::key::keyboard& _obj) {
|
||||
return keyboardDescriptionString[int32_t(_obj)];
|
||||
}
|
||||
|
||||
template <> bool from_string<enum gale::key::keyboard>(enum gale::key::keyboard& _variableRet, const etk::String& _value) {
|
||||
for (size_t iii=0; iii< sizeof(keyboardDescriptionString); ++iii) {
|
||||
if (keyboardDescriptionString[iii] == _value) {
|
||||
_variableRet = (enum gale::key::keyboard)iii;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -14,56 +14,58 @@ namespace gale {
|
||||
* @warning If you modify Id of these element check the java interface file of constant : GaleConstant.java
|
||||
*/
|
||||
enum class keyboard {
|
||||
unknow = 0, //!< Unknown keyboard key
|
||||
character, //!< Char input is arrived ...
|
||||
left, //!< Left key <--
|
||||
right, //!< Right key -->
|
||||
up, //!< Up key ^
|
||||
down, //!< Down key \/
|
||||
pageUp, //!< Page Up key
|
||||
pageDown, //!< page down key
|
||||
start, //!< Start key
|
||||
end, //!< End key
|
||||
print, //!< print screen key.
|
||||
stopDefil, //!< Stop display key.
|
||||
wait, //!< Wait key.
|
||||
insert, //!< insert key.
|
||||
f1, //!< F1 key.
|
||||
f2, //!< F2 key.
|
||||
f3, //!< F3 key.
|
||||
f4, //!< F4 key.
|
||||
f5, //!< F5 key.
|
||||
f6, //!< F6 key.
|
||||
f7, //!< F7 key.
|
||||
f8, //!< F8 key.
|
||||
f9, //!< F9 key.
|
||||
f10, //!< F10 key.
|
||||
f11, //!< F11 key.
|
||||
f12, //!< F12 key.
|
||||
capLock, //!< Capital Letter Lock key.
|
||||
shiftLeft, //!< Shift left key.
|
||||
shiftRight, //!< Shift right key.
|
||||
ctrlLeft, //!< Control left key.
|
||||
ctrlRight, //!< Control right key.
|
||||
metaLeft, //!< Meta left key (apple key or windows key).
|
||||
metaRight, //!< Meta right key (apple key or windows key).
|
||||
alt, //!< Alt key.
|
||||
altGr, //!< Alt ground key.
|
||||
contextMenu, //!< Contextual menu key.
|
||||
numLock, //!< Numerical Lock key
|
||||
unknow = 0, //!< Unknown keyboard key
|
||||
character, //!< Char input is arrived ...
|
||||
left, //!< Left key <--
|
||||
right, //!< Right key -->
|
||||
up, //!< Up key ^
|
||||
down, //!< Down key \/
|
||||
pageUp, //!< Page Up key
|
||||
pageDown, //!< page down key
|
||||
start, //!< Start key
|
||||
end, //!< End key
|
||||
print, //!< print screen key.
|
||||
stopDefil, //!< Stop display key.
|
||||
wait, //!< Wait key.
|
||||
insert, //!< insert key.
|
||||
f1, //!< F1 key.
|
||||
f2, //!< F2 key.
|
||||
f3, //!< F3 key.
|
||||
f4, //!< F4 key.
|
||||
f5, //!< F5 key.
|
||||
f6, //!< F6 key.
|
||||
f7, //!< F7 key.
|
||||
f8, //!< F8 key.
|
||||
f9, //!< F9 key.
|
||||
f10, //!< F10 key.
|
||||
f11, //!< F11 key.
|
||||
f12, //!< F12 key.
|
||||
capLock, //!< Capital Letter Lock key.
|
||||
shiftLeft, //!< Shift left key.
|
||||
shiftRight, //!< Shift right key.
|
||||
ctrlLeft, //!< Control left key.
|
||||
ctrlRight, //!< Control right key.
|
||||
metaLeft, //!< Meta left key (apple key or windows key).
|
||||
metaRight, //!< Meta right key (apple key or windows key).
|
||||
altLeft, //!< Alt left key.
|
||||
alt = altLeft, //!< Alt key. Same as altLeft.
|
||||
altRight, //!< Alt right key.
|
||||
altGr = altRight, //!< Alt ground key. Same as AltRight
|
||||
contextMenu, //!< Contextual menu key.
|
||||
numLock, //!< Numerical Lock key
|
||||
// harware section:
|
||||
volumeUp, //!< Hardware volume UP key
|
||||
volumeDown, //!< Hardware volume DOWN key
|
||||
menu, //!< Hardware Menu key
|
||||
camera, //!< Hardware Camera key
|
||||
home, //!< Hardware Home key
|
||||
power, //!< Hardware Power key
|
||||
back //!< Hardware Back key
|
||||
volumeUp, //!< Hardware volume UP key
|
||||
volumeDown, //!< Hardware volume DOWN key
|
||||
menu, //!< Hardware Menu key
|
||||
camera, //!< Hardware Camera key
|
||||
home, //!< Hardware Home key
|
||||
power, //!< Hardware Power key
|
||||
back //!< Hardware Back key
|
||||
};
|
||||
/**
|
||||
* @brief Debug operator To display the curent element in a Human redeable information
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, const enum gale::key::keyboard _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, const enum gale::key::keyboard _obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/key/status.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(enum gale::key::status);
|
||||
|
||||
static const char* statusDescriptionString[] = {
|
||||
"status::unknow",
|
||||
@ -26,14 +28,23 @@ static const char* statusDescriptionString[] = {
|
||||
"status::transfert"
|
||||
};
|
||||
|
||||
std::ostream& gale::key::operator <<(std::ostream& _os, const enum gale::key::status _obj) {
|
||||
etk::Stream& gale::key::operator <<(etk::Stream& _os, const enum gale::key::status _obj) {
|
||||
_os << statusDescriptionString[int32_t(_obj)];
|
||||
return _os;
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<enum gale::key::status>(const enum gale::key::status& _obj) {
|
||||
template<> etk::String toString<enum gale::key::status>(const enum gale::key::status& _obj) {
|
||||
return statusDescriptionString[int32_t(_obj)];
|
||||
}
|
||||
|
||||
template <> bool from_string<enum gale::key::status>(enum gale::key::status& _variableRet, const etk::String& _value) {
|
||||
for (size_t iii=0; iii< sizeof(statusDescriptionString); ++iii) {
|
||||
if (statusDescriptionString[iii] == _value) {
|
||||
_variableRet = (enum gale::key::status)iii;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -33,7 +33,7 @@ namespace gale {
|
||||
/**
|
||||
* @brief Debug operator To display the curent element in a Human redeable information
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, const enum gale::key::status _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, const enum gale::key::status _obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <gale/key/type.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(enum gale::key::type);
|
||||
|
||||
static const char* typeDescriptionString[] = {
|
||||
"type::unknow",
|
||||
@ -15,13 +16,23 @@ static const char* typeDescriptionString[] = {
|
||||
"type::stylet"
|
||||
};
|
||||
|
||||
std::ostream& gale::key::operator <<(std::ostream& _os, const enum gale::key::type _obj) {
|
||||
etk::Stream& gale::key::operator <<(etk::Stream& _os, const enum gale::key::type _obj) {
|
||||
_os << typeDescriptionString[int32_t(_obj)];
|
||||
return _os;
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<enum gale::key::type>(const enum gale::key::type& _obj) {
|
||||
template<> etk::String toString<enum gale::key::type>(const enum gale::key::type& _obj) {
|
||||
return typeDescriptionString[int32_t(_obj)];
|
||||
}
|
||||
|
||||
template <> bool from_string<enum gale::key::type>(enum gale::key::type& _variableRet, const etk::String& _value) {
|
||||
for (size_t iii=0; iii< sizeof(typeDescriptionString); ++iii) {
|
||||
if (typeDescriptionString[iii] == _value) {
|
||||
_variableRet = (enum gale::key::type)iii;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -21,7 +21,7 @@ namespace gale {
|
||||
/**
|
||||
* @brief Debug operator To display the curent element in a Human redeable information
|
||||
*/
|
||||
std::ostream& operator <<(std::ostream& _os, enum gale::key::type _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, enum gale::key::type _obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <gale/orientation.hpp>
|
||||
#include <etk/String.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(enum gale::orientation);
|
||||
|
||||
static const char* listValues[] = {
|
||||
"orientation::screenAuto",
|
||||
@ -13,7 +16,7 @@ static const char* listValues[] = {
|
||||
"orientation::screenPortrait"
|
||||
};
|
||||
|
||||
std::ostream& gale::operator <<(std::ostream& _os, const enum gale::orientation _obj) {
|
||||
etk::Stream& gale::operator <<(etk::Stream& _os, const enum gale::orientation _obj) {
|
||||
_os << listValues[int32_t(_obj)];
|
||||
return _os;
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/Stream.hpp>
|
||||
|
||||
namespace gale {
|
||||
enum class orientation {
|
||||
screenAuto = 0,
|
||||
screenLandscape,
|
||||
screenPortrait
|
||||
};
|
||||
std::ostream& operator <<(std::ostream& _os, enum gale::orientation _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, enum gale::orientation _obj);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -22,7 +22,7 @@ extern "C" {
|
||||
#undef glTranslatef
|
||||
#elif defined(__TARGET_OS__Android)
|
||||
// Include openGL ES 2
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#elif defined(__TARGET_OS__Windows)
|
||||
// TO ENABLE THE SHADER api ...
|
||||
|
@ -1,14 +1,15 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <etk/Pair.hpp>
|
||||
//#define DIRECT_MODE
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
#include <ethread/tools.hpp>
|
||||
@ -27,6 +28,8 @@ static void checkGlError(const char* _op, int32_t _localLine) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
//#define CHECK_GL_ERROR(cmd,line) do { } while (false)
|
||||
#define CHECK_GL_ERROR(cmd,line) checkGlError(cmd,line)
|
||||
|
||||
#define OPENGL_ERROR(data) do { } while (false)
|
||||
//#define OPENGL_ERROR(data) GALE_ERROR(data)
|
||||
@ -37,7 +40,7 @@ static void checkGlError(const char* _op, int32_t _localLine) {
|
||||
|
||||
|
||||
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
bool s_simulationMode = false;
|
||||
/**
|
||||
* @brief Start the simulation mode of Open GL (can be usebull when no HW is availlable for testing System like buildfarm (eg: travis-ci)
|
||||
@ -53,12 +56,12 @@ static void checkGlError(const char* _op, int32_t _localLine) {
|
||||
* @note due ti the fact that the system can be called for multiple instance, for naw we just limit the acces to one process at a time.
|
||||
* @return the main inteface Mutex
|
||||
*/
|
||||
static std::mutex& mutexOpenGl() {
|
||||
static std::mutex s_drawMutex;
|
||||
static ethread::Mutex& mutexOpenGl() {
|
||||
static ethread::Mutex s_drawMutex;
|
||||
return s_drawMutex;
|
||||
}
|
||||
|
||||
std::vector<mat4> l_matrixList;
|
||||
etk::Vector<mat4> l_matrixList;
|
||||
mat4 l_matrixCamera;
|
||||
static uint32_t l_flagsCurrent = 0;
|
||||
static uint32_t l_flagsMustBeSet = 0;
|
||||
@ -70,7 +73,7 @@ void gale::openGL::lock() {
|
||||
mutexOpenGl().lock();
|
||||
l_matrixList.clear();
|
||||
mat4 tmpMat;
|
||||
l_matrixList.push_back(tmpMat);
|
||||
l_matrixList.pushBack(tmpMat);
|
||||
l_matrixCamera.identity();
|
||||
l_flagsCurrent = 0;
|
||||
l_flagsMustBeSet = 0;
|
||||
@ -79,46 +82,45 @@ void gale::openGL::lock() {
|
||||
}
|
||||
|
||||
void gale::openGL::unLock() {
|
||||
mutexOpenGl().unlock();
|
||||
mutexOpenGl().unLock();
|
||||
}
|
||||
|
||||
static std::vector<std::thread::id>& getContextList() {
|
||||
static std::vector<std::thread::id> g_val;
|
||||
static etk::Vector<uint64_t>& getContextList() {
|
||||
static etk::Vector<uint64_t> g_val;
|
||||
return g_val;
|
||||
}
|
||||
|
||||
bool gale::openGL::hasContext() {
|
||||
bool ret = false;
|
||||
mutexOpenGl().lock();
|
||||
auto it = std::find(getContextList().begin(), getContextList().end(), std::this_thread::get_id());
|
||||
auto it = etk::find(getContextList().begin(), getContextList().end(), ethread::getId());
|
||||
if (it != getContextList().end()) {
|
||||
ret = true;
|
||||
}
|
||||
mutexOpenGl().unlock();
|
||||
mutexOpenGl().unLock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void gale::openGL::threadHasContext() {
|
||||
mutexOpenGl().lock();
|
||||
auto it = std::find(getContextList().begin(), getContextList().end(), std::this_thread::get_id());
|
||||
auto it = etk::find(getContextList().begin(), getContextList().end(), ethread::getId());
|
||||
if (it != getContextList().end()) {
|
||||
GALE_ERROR("set openGL context associate with threadID a second time ... ");
|
||||
} else {
|
||||
getContextList().push_back(std::this_thread::get_id());
|
||||
getContextList().pushBack(ethread::getId());
|
||||
}
|
||||
mutexOpenGl().unlock();
|
||||
mutexOpenGl().unLock();
|
||||
}
|
||||
|
||||
void gale::openGL::threadHasNoMoreContext() {
|
||||
mutexOpenGl().lock();
|
||||
auto it = std::find(getContextList().begin(), getContextList().end(), std::this_thread::get_id());
|
||||
auto it = etk::find(getContextList().begin(), getContextList().end(), ethread::getId());
|
||||
if (it != getContextList().end()) {
|
||||
getContextList().erase(it);
|
||||
} else {
|
||||
GALE_ERROR("rm openGL context associate with threadID that is not registered.");
|
||||
}
|
||||
|
||||
mutexOpenGl().unlock();
|
||||
mutexOpenGl().unLock();
|
||||
}
|
||||
|
||||
void gale::openGL::setBasicMatrix(const mat4& _newOne) {
|
||||
@ -126,13 +128,13 @@ void gale::openGL::setBasicMatrix(const mat4& _newOne) {
|
||||
GALE_ERROR("matrix is not corect size in the stack : " << l_matrixList.size());
|
||||
}
|
||||
l_matrixList.clear();
|
||||
l_matrixList.push_back(_newOne);
|
||||
l_matrixList.pushBack(_newOne);
|
||||
}
|
||||
|
||||
void gale::openGL::setMatrix(const mat4& _newOne) {
|
||||
if (l_matrixList.size() == 0) {
|
||||
GALE_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
l_matrixList.push_back(_newOne);
|
||||
l_matrixList.pushBack(_newOne);
|
||||
return;
|
||||
}
|
||||
l_matrixList[l_matrixList.size()-1] = _newOne;
|
||||
@ -142,11 +144,11 @@ void gale::openGL::push() {
|
||||
if (l_matrixList.size() == 0) {
|
||||
GALE_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
mat4 tmp;
|
||||
l_matrixList.push_back(tmp);
|
||||
l_matrixList.pushBack(tmp);
|
||||
return;
|
||||
}
|
||||
mat4 tmp = l_matrixList[l_matrixList.size()-1];
|
||||
l_matrixList.push_back(tmp);
|
||||
l_matrixList.pushBack(tmp);
|
||||
}
|
||||
|
||||
void gale::openGL::pop() {
|
||||
@ -154,11 +156,11 @@ void gale::openGL::pop() {
|
||||
GALE_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
l_matrixList.clear();
|
||||
mat4 tmp;
|
||||
l_matrixList.push_back(tmp);
|
||||
l_matrixList.pushBack(tmp);
|
||||
l_matrixCamera.identity();
|
||||
return;
|
||||
}
|
||||
l_matrixList.pop_back();
|
||||
l_matrixList.popBack();
|
||||
l_matrixCamera.identity();
|
||||
}
|
||||
|
||||
@ -166,7 +168,7 @@ const mat4& gale::openGL::getMatrix() {
|
||||
if (l_matrixList.size() == 0) {
|
||||
GALE_ERROR("set matrix list is not corect size in the stack : " << l_matrixList.size());
|
||||
mat4 tmp;
|
||||
l_matrixList.push_back(tmp);
|
||||
l_matrixList.pushBack(tmp);
|
||||
}
|
||||
return l_matrixList[l_matrixList.size()-1];
|
||||
}
|
||||
@ -187,11 +189,12 @@ void gale::openGL::finish() {
|
||||
void gale::openGL::flush() {
|
||||
l_programId = -1;
|
||||
l_textureflags = 0;
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glFlush();
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
checkGlError("glFlush", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
OPENGL_INFO("========================" );
|
||||
@ -204,21 +207,25 @@ void gale::openGL::swap() {
|
||||
}
|
||||
|
||||
void gale::openGL::setViewPort(const ivec2& _start, const ivec2& _stop) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
OPENGL_INFO("setViewport " << _start << " " << _stop);
|
||||
glViewport(_start.x(), _start.y(), _stop.x(), _stop.y());
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glViewport", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void gale::openGL::setViewPort(const vec2& _start, const vec2& _stop) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
OPENGL_INFO("setViewport " << _start << " " << _stop);
|
||||
glViewport(_start.x(), _start.y(), _stop.x(), _stop.y());
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glViewport", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -237,35 +244,39 @@ static int32_t basicFlagClearCount = sizeof(basicFlagClear) / sizeof(struct corr
|
||||
|
||||
|
||||
void gale::openGL::clearColor(const etk::Color<float>& _color) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glClearColor(_color.r(), _color.g(), _color.b(), _color.a());
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glClearColor", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void gale::openGL::clearDepth(float _value) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
#if !((defined(__TARGET_OS__Android) || defined(__TARGET_OS__IOs)))
|
||||
glClearDepth(_value);
|
||||
CHECK_GL_ERROR("glClearDepth", __LINE__);
|
||||
#endif
|
||||
#if defined(__TARGET_OS__IOs)
|
||||
glClearDepthf(_value);
|
||||
CHECK_GL_ERROR("glClearDepthf", __LINE__);
|
||||
#endif
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void gale::openGL::clearStencil(int32_t _value) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glClearStencil(_value);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glClearStencil", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -277,47 +288,49 @@ void gale::openGL::clear(uint32_t _flags) {
|
||||
field |= basicFlagClear[iii].OGlFlag;
|
||||
}
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glClear(field);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glClear", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::ostream& gale::openGL::operator <<(std::ostream& _os, enum gale::openGL::flag _obj) {
|
||||
static std::vector<std::pair<enum openGL::flag, const char*>> list = {
|
||||
std::make_pair(openGL::flag_blend, "FLAG_BLEND"),
|
||||
std::make_pair(openGL::flag_clipDistanceI, "FLAG_CLIP_DISTANCE_I"),
|
||||
std::make_pair(openGL::flag_colorLogigOP, "FLAG_COLOR_LOGIC_OP"),
|
||||
std::make_pair(openGL::flag_cullFace, "FLAG_CULL_FACE"),
|
||||
std::make_pair(openGL::flag_debugOutput, "FLAG_DEBUG_OUTPUT"),
|
||||
std::make_pair(openGL::flag_debugOutputSynchronous, "flag_debugOutput_SYNCHRONOUS"),
|
||||
std::make_pair(openGL::flag_depthClamp, "FLAG_DEPTH_CLAMP"),
|
||||
std::make_pair(openGL::flag_depthTest, "FLAG_DEPTH_TEST"),
|
||||
std::make_pair(openGL::flag_dither, "FLAG_DITHER"),
|
||||
std::make_pair(openGL::flag_framebufferSRGB, "FLAG_FRAMEBUFFER_SRGB"),
|
||||
std::make_pair(openGL::flag_lineSmooth, "FLAG_LINE_SMOOTH"),
|
||||
std::make_pair(openGL::flag_multisample, "FLAG_MULTISAMPLE"),
|
||||
std::make_pair(openGL::flag_polygonOffsetFill, "FLAG_POLYGON_OFFSET_FILL"),
|
||||
std::make_pair(openGL::flag_polygonOffsetLine, "FLAG_POLYGON_OFFSET_LINE"),
|
||||
std::make_pair(openGL::flag_polygonOffsetPoint, "FLAG_POLYGON_OFFSET_POINT"),
|
||||
std::make_pair(openGL::flag_polygonSmooth, "FLAG_POLYGON_SMOOTH"),
|
||||
std::make_pair(openGL::flag_primitiveRestart, "FLAG_PRIMITIVE_RESTART"),
|
||||
std::make_pair(openGL::flag_primitiveRestartFixedIndex, "flag_primitiveRestart_FIXED_INDEX"),
|
||||
std::make_pair(openGL::flag_sampleAlphaToCoverage, "FLAG_SAMPLE_ALPHA_TO_COVERAGE"),
|
||||
std::make_pair(openGL::flag_sampleAlphaToOne, "FLAG_SAMPLE_ALPHA_TO_ONE"),
|
||||
std::make_pair(openGL::flag_sampleCoverage, "FLAG_SAMPLE_COVERAGE"),
|
||||
std::make_pair(openGL::flag_sampleShading, "FLAG_SAMPLE_SHADING"),
|
||||
std::make_pair(openGL::flag_sampleMask, "FLAG_SAMPLE_MASK"),
|
||||
std::make_pair(openGL::flag_scissorTest, "FLAG_SCISSOR_TEST"),
|
||||
std::make_pair(openGL::flag_stencilTest, "FLAG_STENCIL_TEST"),
|
||||
std::make_pair(openGL::flag_programPointSize, "FLAG_PROGRAM_POINT_SIZE"),
|
||||
std::make_pair(openGL::flag_texture2D, "FLAG_TEXTURE_2D"),
|
||||
std::make_pair(openGL::flag_alphaTest, "FLAG_ALPHA_TEST"),
|
||||
std::make_pair(openGL::flag_fog, "FLAG_FOG")
|
||||
etk::Stream& gale::openGL::operator <<(etk::Stream& _os, enum gale::openGL::flag _obj) {
|
||||
static etk::Vector<etk::Pair<enum openGL::flag, const char*>> list = {
|
||||
etk::makePair(openGL::flag_blend, "FLAG_BLEND"),
|
||||
etk::makePair(openGL::flag_clipDistanceI, "FLAG_CLIP_DISTANCE_I"),
|
||||
etk::makePair(openGL::flag_colorLogigOP, "FLAG_COLOR_LOGIC_OP"),
|
||||
etk::makePair(openGL::flag_cullFace, "FLAG_CULL_FACE"),
|
||||
etk::makePair(openGL::flag_debugOutput, "FLAG_DEBUG_OUTPUT"),
|
||||
etk::makePair(openGL::flag_debugOutputSynchronous, "flag_debugOutput_SYNCHRONOUS"),
|
||||
etk::makePair(openGL::flag_depthClamp, "FLAG_DEPTH_CLAMP"),
|
||||
etk::makePair(openGL::flag_depthTest, "FLAG_DEPTH_TEST"),
|
||||
etk::makePair(openGL::flag_dither, "FLAG_DITHER"),
|
||||
etk::makePair(openGL::flag_framebufferSRGB, "FLAG_FRAMEBUFFER_SRGB"),
|
||||
etk::makePair(openGL::flag_lineSmooth, "FLAG_LINE_SMOOTH"),
|
||||
etk::makePair(openGL::flag_multisample, "FLAG_MULTISAMPLE"),
|
||||
etk::makePair(openGL::flag_polygonOffsetFill, "FLAG_POLYGON_OFFSET_FILL"),
|
||||
etk::makePair(openGL::flag_polygonOffsetLine, "FLAG_POLYGON_OFFSET_LINE"),
|
||||
etk::makePair(openGL::flag_polygonOffsetPoint, "FLAG_POLYGON_OFFSET_POINT"),
|
||||
etk::makePair(openGL::flag_polygonSmooth, "FLAG_POLYGON_SMOOTH"),
|
||||
etk::makePair(openGL::flag_primitiveRestart, "FLAG_PRIMITIVE_RESTART"),
|
||||
etk::makePair(openGL::flag_primitiveRestartFixedIndex, "flag_primitiveRestart_FIXED_INDEX"),
|
||||
etk::makePair(openGL::flag_sampleAlphaToCoverage, "FLAG_SAMPLE_ALPHA_TO_COVERAGE"),
|
||||
etk::makePair(openGL::flag_sampleAlphaToOne, "FLAG_SAMPLE_ALPHA_TO_ONE"),
|
||||
etk::makePair(openGL::flag_sampleCoverage, "FLAG_SAMPLE_COVERAGE"),
|
||||
etk::makePair(openGL::flag_sampleShading, "FLAG_SAMPLE_SHADING"),
|
||||
etk::makePair(openGL::flag_sampleMask, "FLAG_SAMPLE_MASK"),
|
||||
etk::makePair(openGL::flag_scissorTest, "FLAG_SCISSOR_TEST"),
|
||||
etk::makePair(openGL::flag_stencilTest, "FLAG_STENCIL_TEST"),
|
||||
etk::makePair(openGL::flag_programPointSize, "FLAG_PROGRAM_POINT_SIZE"),
|
||||
etk::makePair(openGL::flag_texture2D, "FLAG_TEXTURE_2D"),
|
||||
etk::makePair(openGL::flag_alphaTest, "FLAG_ALPHA_TEST"),
|
||||
etk::makePair(openGL::flag_fog, "FLAG_FOG")
|
||||
};
|
||||
|
||||
_os << "{";
|
||||
bool hasOne = false;
|
||||
for (auto &it : list) {
|
||||
@ -334,25 +347,25 @@ std::ostream& gale::openGL::operator <<(std::ostream& _os, enum gale::openGL::fl
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::pair<enum gale::openGL::renderMode, std::string>>& getListRenderMode() {
|
||||
static std::vector<std::pair<enum gale::openGL::renderMode, std::string>> list = {
|
||||
std::make_pair(gale::openGL::renderMode::point, "POINTS"),
|
||||
std::make_pair(gale::openGL::renderMode::line, "LINES"),
|
||||
std::make_pair(gale::openGL::renderMode::lineStrip, "LINES_STRIP"),
|
||||
std::make_pair(gale::openGL::renderMode::lineLoop, "LINE_LOOP"),
|
||||
std::make_pair(gale::openGL::renderMode::triangle, "TRIANGLE"),
|
||||
std::make_pair(gale::openGL::renderMode::triangleStrip, "TRIANGLE_STRIP"),
|
||||
std::make_pair(gale::openGL::renderMode::triangleFan, "TRIANGLE_FAN"),
|
||||
std::make_pair(gale::openGL::renderMode::quad, "QUAD"),
|
||||
std::make_pair(gale::openGL::renderMode::quadStrip, "QUAD_STRIP"),
|
||||
std::make_pair(gale::openGL::renderMode::polygon, "POLYGON"),
|
||||
etk::Vector<etk::Pair<enum gale::openGL::renderMode, etk::String>>& getListRenderMode() {
|
||||
static etk::Vector<etk::Pair<enum gale::openGL::renderMode, etk::String>> list = {
|
||||
etk::makePair(gale::openGL::renderMode::point, "POINTS"),
|
||||
etk::makePair(gale::openGL::renderMode::line, "LINES"),
|
||||
etk::makePair(gale::openGL::renderMode::lineStrip, "LINES_STRIP"),
|
||||
etk::makePair(gale::openGL::renderMode::lineLoop, "LINE_LOOP"),
|
||||
etk::makePair(gale::openGL::renderMode::triangle, "TRIANGLE"),
|
||||
etk::makePair(gale::openGL::renderMode::triangleStrip, "TRIANGLE_STRIP"),
|
||||
etk::makePair(gale::openGL::renderMode::triangleFan, "TRIANGLE_FAN"),
|
||||
etk::makePair(gale::openGL::renderMode::quad, "QUAD"),
|
||||
etk::makePair(gale::openGL::renderMode::quadStrip, "QUAD_STRIP"),
|
||||
etk::makePair(gale::openGL::renderMode::polygon, "POLYGON"),
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<gale::openGL::renderMode>(const gale::openGL::renderMode& _obj) {
|
||||
template<> etk::String toString<gale::openGL::renderMode>(const gale::openGL::renderMode& _obj) {
|
||||
for (auto &it : getListRenderMode()) {
|
||||
if (it.first == _obj) {
|
||||
return it.second;
|
||||
@ -361,10 +374,10 @@ namespace etk {
|
||||
GALE_ERROR("Can not convert : " << static_cast<int32_t>(_obj) << " return UNKNOW");
|
||||
return "UNKNOW";
|
||||
}
|
||||
template<> std::u32string to_u32string<gale::openGL::renderMode>(const gale::openGL::renderMode& _obj) {
|
||||
return etk::to_u32string(etk::to_string(_obj));
|
||||
template<> etk::UString toUString<gale::openGL::renderMode>(const gale::openGL::renderMode& _obj) {
|
||||
return etk::toUString(etk::toString(_obj));
|
||||
}
|
||||
template<> bool from_string<gale::openGL::renderMode>(gale::openGL::renderMode& _variableRet, const std::string& _value) {
|
||||
template<> bool from_string<gale::openGL::renderMode>(gale::openGL::renderMode& _variableRet, const etk::String& _value) {
|
||||
for (auto &it : getListRenderMode()) {
|
||||
if (it.second == _value) {
|
||||
_variableRet = it.first;
|
||||
@ -375,13 +388,13 @@ namespace etk {
|
||||
_variableRet = gale::openGL::renderMode::triangle;
|
||||
return false;
|
||||
}
|
||||
template<> bool from_string<gale::openGL::renderMode>(gale::openGL::renderMode& _variableRet, const std::u32string& _value) {
|
||||
return from_string(_variableRet, etk::to_string(_value));
|
||||
template<> bool from_string<gale::openGL::renderMode>(gale::openGL::renderMode& _variableRet, const etk::UString& _value) {
|
||||
return from_string(_variableRet, etk::toString(_value));
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& gale::openGL::operator <<(std::ostream& _os, enum gale::openGL::renderMode _obj) {
|
||||
_os << etk::to_string(_obj);
|
||||
etk::Stream& gale::openGL::operator <<(etk::Stream& _os, enum gale::openGL::renderMode _obj) {
|
||||
_os << etk::toString(_obj);
|
||||
return _os;
|
||||
}
|
||||
|
||||
@ -461,17 +474,18 @@ void gale::openGL::reset() {
|
||||
}
|
||||
|
||||
void gale::openGL::enable(enum gale::openGL::flag _flagID) {
|
||||
//GALE_INFO("Enable : " <GALE_ERROR< _flagID);
|
||||
OPENGL_INFO("Enable : " << _flagID);
|
||||
#ifdef DIRECT_MODE
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
|
||||
if ( basicFlag[iii].curentFlag == (uint32_t)_flagID ) {
|
||||
if (basicFlag[iii].curentFlag == (uint32_t)_flagID) {
|
||||
glEnable(basicFlag[iii].OGlFlag);
|
||||
CHECK_GL_ERROR("glEnable", __LINE__);
|
||||
}
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
# else
|
||||
@ -482,15 +496,16 @@ void gale::openGL::enable(enum gale::openGL::flag _flagID) {
|
||||
}
|
||||
|
||||
void gale::openGL::disable(enum gale::openGL::flag _flagID) {
|
||||
//GALE_INFO("Disable : " << _flagID);
|
||||
OPENGL_INFO("Disable : " << _flagID);
|
||||
#ifdef DIRECT_MODE
|
||||
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
|
||||
if ( basicFlag[iii].curentFlag == (uint32_t)_flagID ) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
if (basicFlag[iii].curentFlag == (uint32_t)_flagID) {
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glDisable(basicFlag[iii].OGlFlag);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDisable", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -516,20 +531,22 @@ void gale::openGL::updateAllFlags() {
|
||||
uint32_t CurrentFlag = basicFlag[iii].curentFlag;
|
||||
if ( (l_flagsMustBeSet&CurrentFlag)!=(l_flagsCurrent&CurrentFlag) ) {
|
||||
if ( (l_flagsMustBeSet&CurrentFlag) != 0) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glEnable(basicFlag[iii].OGlFlag);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glEnable", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
OPENGL_INFO(" enable : " << (enum openGL::flag)basicFlag[iii].curentFlag);
|
||||
} else {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glDisable(basicFlag[iii].OGlFlag);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDisable", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
OPENGL_INFO(" disable : " << (enum openGL::flag)basicFlag[iii].curentFlag);
|
||||
@ -542,11 +559,12 @@ void gale::openGL::updateAllFlags() {
|
||||
|
||||
void gale::openGL::activeTexture(uint32_t _flagID) {
|
||||
if (l_programId >= 0) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glActiveTexture(_flagID);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glActiveTexture", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
@ -584,102 +602,106 @@ const uint32_t convertRenderMode[] = {
|
||||
void gale::openGL::drawArrays(enum gale::openGL::renderMode _mode, int32_t _first, int32_t _count) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glDrawArrays(convertRenderMode[uint32_t(_mode)], _first, _count);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDrawArrays", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void gale::openGL::drawElements(enum renderMode _mode, const std::vector<uint32_t>& _indices) {
|
||||
void gale::openGL::drawElements(enum renderMode _mode, const etk::Vector<uint32_t>& _indices) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
//GALE_DEBUG("Request draw of " << indices.size() << "elements");
|
||||
glDrawElements(convertRenderMode[uint32_t(_mode)], _indices.size(), GL_UNSIGNED_INT, &_indices[0]);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDrawElements", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void gale::openGL::drawElements16(enum renderMode _mode, const std::vector<uint16_t>& _indices) {
|
||||
void gale::openGL::drawElements16(enum renderMode _mode, const etk::Vector<uint16_t>& _indices) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glDrawElements(convertRenderMode[uint32_t(_mode)], _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDrawElements", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void gale::openGL::drawElements8(enum renderMode _mode, const std::vector<uint8_t>& _indices) {
|
||||
void gale::openGL::drawElements8(enum renderMode _mode, const etk::Vector<uint8_t>& _indices) {
|
||||
if (l_programId >= 0) {
|
||||
updateAllFlags();
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glDrawElements(convertRenderMode[uint32_t(_mode)], _indices.size(), GL_UNSIGNED_BYTE, &_indices[0]);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDrawElements", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void gale::openGL::useProgram(int32_t _id) {
|
||||
//GALE_DEBUG("USE prog : " << _id);
|
||||
GALE_VERBOSE("USE prog : " << _id);
|
||||
#if 1
|
||||
// note : In normal openGL case, the system might call with the program ID and at the end with 0,
|
||||
// here, we wrap this use to prevent over call of glUseProgram == > then we set -1 when the
|
||||
// user no more use this program, and just stop grnerating. (chen 0 == > this is an errored program ...
|
||||
if (-1 == _id) {
|
||||
if (_id == -1) {
|
||||
// not used == > because it is unneded
|
||||
return;
|
||||
}
|
||||
if (l_programId != _id) {
|
||||
l_programId = _id;
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glUseProgram(l_programId);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
if (-1 == _id) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
if (_id == -1) {
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glUseProgram(0);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
l_programId = _id;
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glUseProgram(_id);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#if 1
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
checkGlError("glUseProgram", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glUseProgram", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@ -688,18 +710,23 @@ void gale::openGL::useProgram(int32_t _id) {
|
||||
|
||||
|
||||
|
||||
bool gale::openGL::genBuffers(std::vector<uint32_t>& _buffers) {
|
||||
bool gale::openGL::genBuffers(etk::Vector<uint32_t>& _buffers) {
|
||||
if (_buffers.size() == 0) {
|
||||
GALE_WARNING("try to generate vector buffer with size 0");
|
||||
return true;
|
||||
}
|
||||
OPENGL_INFO("Create N=" << _buffers.size() << " Buffer");
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glGenBuffers(_buffers.size(), &_buffers[0]);
|
||||
checkGlError("glGenBuffers", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glGenBuffers", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
} else {
|
||||
static int32_t count = 1;
|
||||
for (auto &it : _buffers) {
|
||||
it = count++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
bool hasError = false;
|
||||
@ -712,17 +739,18 @@ bool gale::openGL::genBuffers(std::vector<uint32_t>& _buffers) {
|
||||
return hasError;
|
||||
}
|
||||
|
||||
bool gale::openGL::deleteBuffers(std::vector<uint32_t>& _buffers) {
|
||||
bool gale::openGL::deleteBuffers(etk::Vector<uint32_t>& _buffers) {
|
||||
if (_buffers.size() == 0) {
|
||||
GALE_WARNING("try to delete vector buffer with size 0");
|
||||
return true;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
// TODO: Check if we are in the correct thread
|
||||
glDeleteBuffers(_buffers.size(), &_buffers[0]);
|
||||
checkGlError("glDeleteBuffers", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDeleteBuffers", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
for (auto &it : _buffers) {
|
||||
@ -732,12 +760,12 @@ bool gale::openGL::deleteBuffers(std::vector<uint32_t>& _buffers) {
|
||||
}
|
||||
|
||||
bool gale::openGL::bindBuffer(uint32_t _bufferId) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _bufferId);
|
||||
checkGlError("glBindBuffer", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glBindBuffer", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
@ -750,24 +778,24 @@ static GLenum convertUsage[] = {
|
||||
};
|
||||
|
||||
bool gale::openGL::bufferData(size_t _size, const void* _data, enum gale::openGL::usage _usage) {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glBufferData(GL_ARRAY_BUFFER, _size, _data, convertUsage[uint32_t(_usage)]);
|
||||
checkGlError("glBufferData", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glBufferData", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gale::openGL::unbindBuffer() {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
checkGlError("glBindBuffer(0)", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glBindBuffer(0)", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
@ -785,25 +813,25 @@ int64_t gale::openGL::shader::create(enum gale::openGL::shader::type _type) {
|
||||
GLuint shader = 0;
|
||||
if (_type == gale::openGL::shader::type::vertex) {
|
||||
GALE_VERBOSE("create shader: VERTEX");
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
} else {
|
||||
static int32_t count = 0;
|
||||
static int32_t count = 1;
|
||||
shader = count++;
|
||||
}
|
||||
#endif
|
||||
} else if (_type == gale::openGL::shader::type::fragment) {
|
||||
GALE_VERBOSE("create shader: FRAGMENT");
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
} else {
|
||||
static int32_t count = 0;
|
||||
static int32_t count = 1;
|
||||
shader = count++;
|
||||
}
|
||||
#endif
|
||||
@ -814,11 +842,11 @@ int64_t gale::openGL::shader::create(enum gale::openGL::shader::type _type) {
|
||||
GALE_VERBOSE("create shader: ... (done)");
|
||||
if (shader == 0) {
|
||||
GALE_ERROR("glCreateShader return error ...");
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
checkGlError("glCreateShader");
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
@ -830,37 +858,42 @@ void gale::openGL::shader::remove(int64_t& _shader) {
|
||||
if (_shader < 0) {
|
||||
return;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
// TODO: Check if we are in the correct thread
|
||||
glDeleteShader(GLuint(_shader));
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDeleteShader", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
_shader = -1;
|
||||
}
|
||||
|
||||
bool gale::openGL::shader::compile(int64_t _shader, const std::string& _data) {
|
||||
bool gale::openGL::shader::compile(int64_t _shader, const etk::String& _data) {
|
||||
const char* data = &_data[0];
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glShaderSource(GLuint(_shader), 1, (const char**)&data, nullptr);
|
||||
glShaderSource(GLuint(_shader), 1, (const char**)&data, NULL);
|
||||
CHECK_GL_ERROR("glShaderSource", __LINE__);
|
||||
glCompileShader(GLuint(_shader));
|
||||
CHECK_GL_ERROR("glCompileShader", __LINE__);
|
||||
GLint compiled = 0;
|
||||
glGetShaderiv(GLuint(_shader), GL_COMPILE_STATUS, &compiled);
|
||||
CHECK_GL_ERROR("glGetShaderiv", __LINE__);
|
||||
if (!compiled) {
|
||||
GLint infoLen = 0;
|
||||
l_bufferDisplayError[0] = '\0';
|
||||
glGetShaderInfoLog(GLuint(_shader), LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
|
||||
GALE_ERROR("Error " << l_bufferDisplayError);
|
||||
std::vector<std::string> lines = etk::split(_data, '\n');
|
||||
etk::Vector<etk::String> lines = etk::split(_data, '\n');
|
||||
for (size_t iii=0; iii<lines.size(); iii++) {
|
||||
GALE_ERROR("file " << (iii+1) << "|" << lines[iii]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
@ -869,16 +902,16 @@ bool gale::openGL::shader::compile(int64_t _shader, const std::string& _data) {
|
||||
|
||||
int64_t gale::openGL::program::create() {
|
||||
GLuint program = 0;
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
program = glCreateProgram();
|
||||
if (program == 0) {
|
||||
GALE_ERROR("program creation return error ...");
|
||||
checkGlError("glCreateProgram", __LINE__);
|
||||
CHECK_GL_ERROR("glCreateProgram", __LINE__);
|
||||
return -1;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
} else {
|
||||
static uint32_t iii=0;
|
||||
program = iii++;
|
||||
@ -892,12 +925,13 @@ void gale::openGL::program::remove(int64_t& _prog) {
|
||||
if (_prog < 0) {
|
||||
return;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
// TODO: Check if we are in the correct thread
|
||||
glDeleteProgram(GLuint(_prog));
|
||||
checkGlError("glDeleteProgram", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glDeleteProgram", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
_prog = -1;
|
||||
@ -912,12 +946,12 @@ bool gale::openGL::program::attach(int64_t _prog, int64_t _shader) {
|
||||
GALE_ERROR("wrong shader ID");
|
||||
return false;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glAttachShader(GLuint(_prog), GLuint(_shader));
|
||||
checkGlError("glAttachShader", __LINE__);
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
CHECK_GL_ERROR("glAttachShader", __LINE__);
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
@ -927,14 +961,14 @@ bool gale::openGL::program::compile(int64_t _prog) {
|
||||
GALE_ERROR("wrong program ID");
|
||||
return false;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
glLinkProgram(GLuint(_prog));
|
||||
checkGlError("glLinkProgram", __LINE__);
|
||||
CHECK_GL_ERROR("glLinkProgram", __LINE__);
|
||||
GLint linkStatus = GL_FALSE;
|
||||
glGetProgramiv(GLuint(_prog), GL_LINK_STATUS, &linkStatus);
|
||||
checkGlError("glGetProgramiv", __LINE__);
|
||||
CHECK_GL_ERROR("glGetProgramiv", __LINE__);
|
||||
if (linkStatus != GL_TRUE) {
|
||||
GLint bufLength = 0;
|
||||
l_bufferDisplayError[0] = '\0';
|
||||
@ -963,13 +997,13 @@ bool gale::openGL::program::compile(int64_t _prog) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t gale::openGL::program::getAttributeLocation(int64_t _prog, const std::string& _name) {
|
||||
int32_t gale::openGL::program::getAttributeLocation(int64_t _prog, const etk::String& _name) {
|
||||
if (_prog < 0) {
|
||||
GALE_ERROR("wrong program ID");
|
||||
return -1;
|
||||
@ -979,21 +1013,21 @@ int32_t gale::openGL::program::getAttributeLocation(int64_t _prog, const std::st
|
||||
return -1;
|
||||
}
|
||||
GLint val = 0;
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
val = glGetAttribLocation(GLuint(_prog), _name.c_str());
|
||||
if (val < 0) {
|
||||
checkGlError("glGetAttribLocation", __LINE__);
|
||||
CHECK_GL_ERROR("glGetAttribLocation", __LINE__);
|
||||
GALE_WARNING("glGetAttribLocation(\"" << _name << "\") = " << val);
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return val;
|
||||
}
|
||||
|
||||
int32_t gale::openGL::program::getUniformLocation(int64_t _prog, const std::string& _name) {
|
||||
int32_t gale::openGL::program::getUniformLocation(int64_t _prog, const etk::String& _name) {
|
||||
if (_prog < 0) {
|
||||
GALE_ERROR("wrong program ID");
|
||||
return -1;
|
||||
@ -1003,15 +1037,21 @@ int32_t gale::openGL::program::getUniformLocation(int64_t _prog, const std::stri
|
||||
return -1;
|
||||
}
|
||||
GLint val = 0;
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
if (s_simulationMode == false) {
|
||||
#endif
|
||||
val = glGetUniformLocation(GLuint(_prog), _name.c_str());
|
||||
if (val < 0) {
|
||||
checkGlError("glGetUniformLocation", __LINE__);
|
||||
if (val == GL_INVALID_VALUE) {
|
||||
CHECK_GL_ERROR("glGetUniformLocation", __LINE__);
|
||||
GALE_WARNING("glGetUniformLocation(\"" << _name << "\") = GL_INVALID_VALUE");
|
||||
} else if (val == GL_INVALID_OPERATION) {
|
||||
CHECK_GL_ERROR("glGetUniformLocation", __LINE__);
|
||||
GALE_WARNING("glGetUniformLocation(\"" << _name << "\") = GL_INVALID_OPERATION");
|
||||
} else if (val < 0) {
|
||||
CHECK_GL_ERROR("glGetUniformLocation", __LINE__);
|
||||
GALE_WARNING("glGetUniformLocation(\"" << _name << "\") = " << val);
|
||||
}
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
}
|
||||
#endif
|
||||
return val;
|
||||
|
@ -1,19 +1,19 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <vector>
|
||||
#include <etk/math/Matrix4.hpp>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <etk/math/Matrix4x4.hpp>
|
||||
#include <etk/math/Vector2D.hpp>
|
||||
#include <etk/Color.hpp>
|
||||
|
||||
namespace gale {
|
||||
namespace openGL {
|
||||
#ifdef GALE_SIMULATION_OPENGL_AVAILLABLE
|
||||
#ifdef GALE_BUILD_SIMULATION
|
||||
/**
|
||||
* @brief Start the simulation mode of Open GL (can be usebull when no HW is availlable for testing System like buildfarm (eg: travis-ci)
|
||||
* This generate a non access on the openGL IO, and all function work corectly.
|
||||
@ -193,9 +193,9 @@ namespace gale {
|
||||
* @brief draw a specific array == > this enable mode difference ...
|
||||
*/
|
||||
void drawArrays(enum renderMode _mode, int32_t _first, int32_t _count);
|
||||
void drawElements (enum renderMode _mode, const std::vector<uint32_t>& _indices);
|
||||
void drawElements16(enum renderMode _mode, const std::vector<uint16_t>& _indices);
|
||||
void drawElements8 (enum renderMode _mode, const std::vector<uint8_t>& _indices);
|
||||
void drawElements (enum renderMode _mode, const etk::Vector<uint32_t>& _indices);
|
||||
void drawElements16(enum renderMode _mode, const etk::Vector<uint16_t>& _indices);
|
||||
void drawElements8 (enum renderMode _mode, const etk::Vector<uint8_t>& _indices);
|
||||
/**
|
||||
* @brief Use openGL program
|
||||
* @param[in] id Id of the program that might be used
|
||||
@ -204,8 +204,8 @@ namespace gale {
|
||||
void reset();
|
||||
|
||||
|
||||
bool genBuffers(std::vector<uint32_t>& _buffers);
|
||||
bool deleteBuffers(std::vector<uint32_t>& _buffers);
|
||||
bool genBuffers(etk::Vector<uint32_t>& _buffers);
|
||||
bool deleteBuffers(etk::Vector<uint32_t>& _buffers);
|
||||
bool bindBuffer(uint32_t _bufferId);
|
||||
enum class usage {
|
||||
streamDraw,
|
||||
@ -222,18 +222,18 @@ namespace gale {
|
||||
};
|
||||
int64_t create(enum gale::openGL::shader::type _type);
|
||||
void remove(int64_t& _shader);
|
||||
bool compile(int64_t _shader, const std::string& _data);
|
||||
bool compile(int64_t _shader, const etk::String& _data);
|
||||
};
|
||||
namespace program {
|
||||
int64_t create();
|
||||
void remove(int64_t& _prog);
|
||||
bool attach(int64_t _prog, int64_t _shader);
|
||||
bool compile(int64_t _prog);
|
||||
int32_t getAttributeLocation(int64_t _prog, const std::string& _name);
|
||||
int32_t getUniformLocation(int64_t _prog, const std::string& _name);
|
||||
int32_t getAttributeLocation(int64_t _prog, const etk::String& _name);
|
||||
int32_t getUniformLocation(int64_t _prog, const etk::String& _name);
|
||||
};
|
||||
std::ostream& operator <<(std::ostream& _os, enum openGL::flag _obj);
|
||||
std::ostream& operator <<(std::ostream& _os, enum openGL::renderMode _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, enum openGL::flag _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, enum openGL::renderMode _obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
@ -11,7 +11,8 @@
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::resource::Manager);
|
||||
|
||||
gale::resource::Manager::Manager() :
|
||||
m_contextHasBeenRemoved(true),
|
||||
@ -20,7 +21,7 @@ gale::resource::Manager::Manager() :
|
||||
}
|
||||
|
||||
gale::resource::Manager::~Manager() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
bool hasError = false;
|
||||
if (m_resourceListToUpdate.size()!=0) {
|
||||
GALE_ERROR("Must not have anymore resources to update !!!");
|
||||
@ -37,14 +38,14 @@ gale::resource::Manager::~Manager() {
|
||||
}
|
||||
|
||||
void gale::resource::Manager::unInit() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
display();
|
||||
m_resourceListToUpdate.clear();
|
||||
// remove all resources ...
|
||||
auto it(m_resourceList.begin());
|
||||
while(it != m_resourceList.end()) {
|
||||
ememory::SharedPtr<gale::Resource> tmpRessource = (*it).lock();
|
||||
if (tmpRessource != nullptr) {
|
||||
if (tmpRessource != null) {
|
||||
GALE_WARNING("Find a resource that is not removed : [" << tmpRessource->getId() << "]"
|
||||
<< "=\"" << tmpRessource->getName() << "\" "
|
||||
<< tmpRessource.useCount() << " elements");
|
||||
@ -58,10 +59,10 @@ void gale::resource::Manager::unInit() {
|
||||
void gale::resource::Manager::display() {
|
||||
GALE_INFO("Resources loaded : ");
|
||||
// remove all resources ...
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
for (auto &it : m_resourceList) {
|
||||
ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
|
||||
if (tmpRessource != nullptr) {
|
||||
if (tmpRessource != null) {
|
||||
GALE_INFO(" [" << tmpRessource->getId() << "]"
|
||||
<< tmpRessource->getType()
|
||||
<< "=\"" << tmpRessource->getName() << "\" "
|
||||
@ -74,13 +75,13 @@ void gale::resource::Manager::display() {
|
||||
void gale::resource::Manager::reLoadResources() {
|
||||
GALE_INFO("------------- Resources re-loaded -------------");
|
||||
// remove all resources ...
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_resourceList.size() != 0) {
|
||||
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
|
||||
GALE_INFO(" Reload level : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
|
||||
for (auto &it : m_resourceList) {
|
||||
ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
|
||||
if(tmpRessource != nullptr) {
|
||||
if(tmpRessource != null) {
|
||||
if (jjj == tmpRessource->getResourceLevel()) {
|
||||
tmpRessource->reload();
|
||||
GALE_INFO(" [" << tmpRessource->getId() << "]="<< tmpRessource->getType());
|
||||
@ -96,16 +97,16 @@ void gale::resource::Manager::reLoadResources() {
|
||||
|
||||
void gale::resource::Manager::update(const ememory::SharedPtr<gale::Resource>& _object) {
|
||||
// chek if not added before
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
for (auto &it : m_resourceListToUpdate) {
|
||||
if ( it != nullptr
|
||||
if ( it != null
|
||||
&& it == _object) {
|
||||
// just prevent some double add ...
|
||||
return;
|
||||
}
|
||||
}
|
||||
// add it ...
|
||||
m_resourceListToUpdate.push_back(_object);
|
||||
m_resourceListToUpdate.pushBack(_object);
|
||||
}
|
||||
|
||||
// Specific to load or update the data in the openGl context == > system use only
|
||||
@ -118,48 +119,48 @@ void gale::resource::Manager::updateContext() {
|
||||
if (m_contextHasBeenRemoved == true) {
|
||||
// need to update all ...
|
||||
m_contextHasBeenRemoved = false;
|
||||
std::list<ememory::WeakPtr<gale::Resource>> resourceList;
|
||||
etk::Vector<ememory::WeakPtr<gale::Resource>> resourceList;
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
// Clean the update list
|
||||
m_resourceListToUpdate.clear();
|
||||
resourceList = m_resourceList;
|
||||
}
|
||||
if (resourceList.size() != 0) {
|
||||
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
|
||||
GALE_INFO(" updateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
|
||||
GALE_VERBOSE(" updateContext level (D) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
|
||||
for (auto &it : resourceList) {
|
||||
ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
|
||||
if( tmpRessource != nullptr
|
||||
if( tmpRessource != null
|
||||
&& jjj == tmpRessource->getResourceLevel()) {
|
||||
//GALE_DEBUG("Update context named : " << l_resourceList[iii]->getName());
|
||||
if (tmpRessource->updateContext() == false) {
|
||||
// Lock error ==> postponned
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
m_resourceListToUpdate.push_back(tmpRessource);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_resourceListToUpdate.pushBack(tmpRessource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::vector<ememory::SharedPtr<gale::Resource>> resourceListToUpdate;
|
||||
etk::Vector<ememory::SharedPtr<gale::Resource>> resourceListToUpdate;
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
resourceListToUpdate = m_resourceListToUpdate;
|
||||
// Clean the update list
|
||||
m_resourceListToUpdate.clear();
|
||||
}
|
||||
if (resourceListToUpdate.size() != 0) {
|
||||
for (size_t jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
|
||||
GALE_INFO(" updateContext level (U) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
|
||||
GALE_VERBOSE(" updateContext level (U) : " << jjj << "/" << (MAX_RESOURCE_LEVEL-1));
|
||||
for (auto &it : resourceListToUpdate) {
|
||||
if ( it != nullptr
|
||||
if ( it != null
|
||||
&& jjj == it->getResourceLevel()) {
|
||||
if (it->updateContext() == false) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
// Lock error ==> postponned
|
||||
m_resourceListToUpdate.push_back(it);
|
||||
m_resourceListToUpdate.pushBack(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,10 +171,10 @@ void gale::resource::Manager::updateContext() {
|
||||
|
||||
// in this case, it is really too late ...
|
||||
void gale::resource::Manager::contextHasBeenDestroyed() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
for (auto &it : m_resourceList) {
|
||||
ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
|
||||
if (tmpRessource != nullptr) {
|
||||
if (tmpRessource != null) {
|
||||
tmpRessource->removeContextToLate();
|
||||
}
|
||||
}
|
||||
@ -187,38 +188,38 @@ void gale::resource::Manager::applicationExiting() {
|
||||
}
|
||||
|
||||
// internal generic keeper ...
|
||||
ememory::SharedPtr<gale::Resource> gale::resource::Manager::localKeep(const std::string& _filename) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ememory::SharedPtr<gale::Resource> gale::resource::Manager::localKeep(const etk::String& _filename) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
GALE_VERBOSE("KEEP (DEFAULT) : file : '" << _filename << "' in " << m_resourceList.size() << " resources");
|
||||
for (auto &it : m_resourceList) {
|
||||
ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
|
||||
if (tmpRessource != nullptr) {
|
||||
if (tmpRessource != null) {
|
||||
if (tmpRessource->getName() == _filename) {
|
||||
return tmpRessource;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return null;
|
||||
}
|
||||
|
||||
// internal generic keeper ...
|
||||
void gale::resource::Manager::localAdd(const ememory::SharedPtr<gale::Resource>& _object) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
//Add ... find empty slot
|
||||
for (auto &it : m_resourceList) {
|
||||
ememory::SharedPtr<gale::Resource> tmpRessource = it.lock();
|
||||
if (tmpRessource == nullptr) {
|
||||
if (tmpRessource == null) {
|
||||
it = _object;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// add at the end if no slot is free
|
||||
m_resourceList.push_back(_object);
|
||||
m_resourceList.pushBack(_object);
|
||||
}
|
||||
|
||||
// in case of error ...
|
||||
void gale::resource::Manager::cleanInternalRemoved() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
//GALE_INFO("remove object in Manager");
|
||||
updateContext();
|
||||
for (auto it(m_resourceList.begin()); it!=m_resourceList.end(); ++it) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <ethread/MutexRecursive.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/resource/Resource.hpp>
|
||||
|
||||
@ -15,11 +15,11 @@ namespace gale {
|
||||
namespace resource {
|
||||
class Manager{
|
||||
private:
|
||||
std::list<ememory::WeakPtr<gale::Resource>> m_resourceList;
|
||||
std::vector<ememory::SharedPtr<gale::Resource>> m_resourceListToUpdate;
|
||||
etk::Vector<ememory::WeakPtr<gale::Resource>> m_resourceList;
|
||||
etk::Vector<ememory::SharedPtr<gale::Resource>> m_resourceListToUpdate;
|
||||
bool m_contextHasBeenRemoved;
|
||||
bool m_exiting;
|
||||
std::recursive_mutex m_mutex;
|
||||
ethread::MutexRecursive m_mutex;
|
||||
public:
|
||||
/**
|
||||
* @brief initialize the internal variable
|
||||
@ -40,7 +40,7 @@ namespace gale {
|
||||
void display();
|
||||
/**
|
||||
* @brief Reload all resources from files, and send there in openGL card if needed.
|
||||
* @note If file is reference at THEME:XXX:filename if the Theme change the file will reload the newOne
|
||||
* @note If file is reference at THEME_XXX:///filename if the Theme change the file will reload the newOne
|
||||
*/
|
||||
void reLoadResources();
|
||||
/**
|
||||
@ -62,7 +62,7 @@ namespace gale {
|
||||
void applicationExiting();
|
||||
public:
|
||||
// internal API to extent eResources in extern Soft
|
||||
ememory::SharedPtr<gale::Resource> localKeep(const std::string& _filename);
|
||||
ememory::SharedPtr<gale::Resource> localKeep(const etk::String& _filename);
|
||||
void localAdd(const ememory::SharedPtr<gale::Resource>& _object);
|
||||
virtual void cleanInternalRemoved();
|
||||
};
|
||||
|
@ -1,16 +1,18 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/resource/Program.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::resource::Program);
|
||||
|
||||
//#define LOCAL_DEBUG GALE_VERBOSE
|
||||
#define LOCAL_DEBUG GALE_DEBUG
|
||||
@ -25,50 +27,51 @@ gale::resource::Program::Program() :
|
||||
m_resourceLevel = 1;
|
||||
}
|
||||
|
||||
void gale::resource::Program::init(const std::string& _filename) {
|
||||
gale::Resource::init(_filename);
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
GALE_DEBUG("OGL : load PROGRAM '" << m_name << "'");
|
||||
void gale::resource::Program::init(const etk::Uri& _uri) {
|
||||
gale::Resource::init(_uri.get());
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
GALE_DEBUG("OGL : load PROGRAM '" << _uri << "'");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
etk::FSNode file(m_name);
|
||||
if (file.exist() == false) {
|
||||
GALE_DEBUG("File does not Exist : \"" << file << "\" == > automatic load of framment and shader with same names... ");
|
||||
std::string tmpFilename = m_name;
|
||||
// remove extention ...
|
||||
tmpFilename.erase(tmpFilename.size()-4, 4);
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename+"vert");
|
||||
if (tmpShader == nullptr) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
if (etk::uri::exist(_uri) == false) {
|
||||
GALE_DEBUG("File does not Exist : \"" << _uri << "\" == > automatic load of framment and shader with same names... ");
|
||||
etk::Uri tmpUri = _uri;
|
||||
tmpUri.setPath(_uri.getPath().getExtentionRemoved() + ".vert");
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpUri.get());
|
||||
if (tmpShader == null) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpUri);
|
||||
return;
|
||||
} else {
|
||||
GALE_DEBUG("Add shader on program : "<< tmpFilename << "vert");
|
||||
m_shaderList.push_back(tmpShader);
|
||||
GALE_DEBUG("Add shader on program : "<< tmpUri << "vert");
|
||||
m_shaderList.pushBack(tmpShader);
|
||||
}
|
||||
tmpShader = gale::resource::Shader::create(tmpFilename+"frag");
|
||||
if (tmpShader == nullptr) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
tmpUri.setPath(_uri.getPath().getExtentionRemoved() + ".frag");
|
||||
tmpShader = gale::resource::Shader::create(tmpUri.get());
|
||||
if (tmpShader == null) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpUri);
|
||||
return;
|
||||
} else {
|
||||
GALE_DEBUG("Add shader on program : "<< tmpFilename << "frag");
|
||||
m_shaderList.push_back(tmpShader);
|
||||
GALE_DEBUG("Add shader on program : "<< tmpUri << "frag");
|
||||
m_shaderList.pushBack(tmpShader);
|
||||
}
|
||||
} else {
|
||||
std::string fileExtention = file.fileGetExtention();
|
||||
if (fileExtention != "prog") {
|
||||
GALE_ERROR("File does not have extention \".prog\" for program but : \"" << fileExtention << "\"");
|
||||
if (_uri.getPath().getExtention() != "prog") {
|
||||
GALE_ERROR("File does not have extention \".prog\" for program but : \"" << _uri.getPath() << "\"");
|
||||
return;
|
||||
}
|
||||
if (file.fileOpenRead() == false) {
|
||||
GALE_ERROR("Can not open the file : \"" << file << "\"");
|
||||
auto fileIO = etk::uri::get(_uri);
|
||||
if ( fileIO == null
|
||||
|| fileIO->open(etk::io::OpenMode::Read) == false) {
|
||||
GALE_ERROR("Can not open the file : \"" << _uri << "\"");
|
||||
return;
|
||||
}
|
||||
#define MAX_LINE_SIZE (2048)
|
||||
char tmpData[MAX_LINE_SIZE];
|
||||
while (file.fileGets(tmpData, MAX_LINE_SIZE) != nullptr) {
|
||||
int32_t len = strlen(tmpData);
|
||||
etk::String tmpData;
|
||||
GALE_DEBUG("===========================================================");
|
||||
while (fileIO->gets(tmpData) != false) {
|
||||
GALE_DEBUG("data: " << tmpData);
|
||||
int32_t len = tmpData.size();
|
||||
if( tmpData[len-1] == '\n'
|
||||
|| tmpData[len-1] == '\r') {
|
||||
|| tmpData[len-1] == '\r') {
|
||||
tmpData[len-1] = '\0';
|
||||
len--;
|
||||
}
|
||||
@ -79,19 +82,25 @@ void gale::resource::Program::init(const std::string& _filename) {
|
||||
if (tmpData[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
// get it with relative position :
|
||||
std::string tmpFilename = file.getRelativeFolder() + tmpData;
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpFilename);
|
||||
if (tmpShader == nullptr) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpFilename);
|
||||
// get it with relative position:
|
||||
etk::Uri tmpUri = _uri;
|
||||
tmpUri.setPath(_uri.getPath().getParent() / tmpData);
|
||||
GALE_VERBOSE("base path: " << _uri);
|
||||
GALE_VERBOSE("base path: " << _uri.getPath());
|
||||
GALE_VERBOSE("base path: " << _uri.getPath().getParent());
|
||||
GALE_VERBOSE("new path: " << _uri.getPath().getParent() / tmpData);
|
||||
GALE_VERBOSE("create shader: " << tmpUri);
|
||||
ememory::SharedPtr<gale::resource::Shader> tmpShader = gale::resource::Shader::create(tmpUri.get());
|
||||
if (tmpShader == null) {
|
||||
GALE_ERROR("Error while getting a specific shader filename : " << tmpUri);
|
||||
} else {
|
||||
GALE_DEBUG("Add shader on program : "<< tmpFilename);
|
||||
m_shaderList.push_back(tmpShader);
|
||||
GALE_DEBUG("Add shader on program : "<< tmpUri);
|
||||
m_shaderList.pushBack(tmpShader);
|
||||
}
|
||||
|
||||
}
|
||||
GALE_DEBUG("===========================================================");
|
||||
// close the file:
|
||||
file.fileClose();
|
||||
fileIO->close();
|
||||
}
|
||||
if (gale::openGL::hasContext() == true) {
|
||||
updateContext();
|
||||
@ -108,7 +117,7 @@ gale::resource::Program::~Program() {
|
||||
m_hasTexture1 = false;
|
||||
}
|
||||
|
||||
std::ostream& gale::resource::operator <<(std::ostream& _os, const gale::resource::progAttributeElement& _obj) {
|
||||
etk::Stream& gale::resource::operator <<(etk::Stream& _os, const gale::resource::progAttributeElement& _obj) {
|
||||
_os << "{";
|
||||
_os << "[" << _obj.m_name << "] ";
|
||||
_os << _obj.m_elementId << " ";
|
||||
@ -117,7 +126,7 @@ std::ostream& gale::resource::operator <<(std::ostream& _os, const gale::resourc
|
||||
return _os;
|
||||
}
|
||||
|
||||
std::ostream& gale::resource::operator <<(std::ostream& _os, const std::vector<gale::resource::progAttributeElement>& _obj){
|
||||
etk::Stream& gale::resource::operator <<(etk::Stream& _os, const etk::Vector<gale::resource::progAttributeElement>& _obj){
|
||||
_os << "{";
|
||||
for (auto &it : _obj) {
|
||||
_os << it;
|
||||
@ -162,7 +171,7 @@ static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
|
||||
|
||||
|
||||
bool gale::resource::Program::checkIdValidity(int32_t _idElem) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if ( _idElem < 0
|
||||
|| (size_t)_idElem > m_elementList.size()) {
|
||||
return false;
|
||||
@ -170,8 +179,8 @@ bool gale::resource::Program::checkIdValidity(int32_t _idElem) {
|
||||
return m_elementList[_idElem].m_isLinked;
|
||||
}
|
||||
|
||||
int32_t gale::resource::Program::getAttribute(std::string _elementName) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
int32_t gale::resource::Program::getAttribute(etk::String _elementName) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
// check if it exist previously :
|
||||
for(size_t iii=0; iii<m_elementList.size(); iii++) {
|
||||
if (m_elementList[iii].m_name == _elementName) {
|
||||
@ -199,12 +208,12 @@ int32_t gale::resource::Program::getAttribute(std::string _elementName) {
|
||||
tmp.m_elementId = -1;
|
||||
tmp.m_isLinked = false;
|
||||
}
|
||||
m_elementList.push_back(tmp);
|
||||
m_elementList.pushBack(tmp);
|
||||
return m_elementList.size()-1;
|
||||
}
|
||||
|
||||
int32_t gale::resource::Program::getUniform(std::string _elementName) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
int32_t gale::resource::Program::getUniform(const etk::String& _elementName) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
// check if it exist previously :
|
||||
for(size_t iii=0; iii<m_elementList.size(); iii++) {
|
||||
if (m_elementList[iii].m_name == _elementName) {
|
||||
@ -232,13 +241,13 @@ int32_t gale::resource::Program::getUniform(std::string _elementName) {
|
||||
tmp.m_elementId = -1;
|
||||
tmp.m_isLinked = false;
|
||||
}
|
||||
m_elementList.push_back(tmp);
|
||||
m_elementList.pushBack(tmp);
|
||||
return m_elementList.size()-1;
|
||||
}
|
||||
|
||||
bool gale::resource::Program::updateContext() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex, std::defer_lock);
|
||||
if (lock.try_lock() == false) {
|
||||
ethread::RecursiveLock lock(m_mutex, true);
|
||||
if (lock.tryLock() == false) {
|
||||
//Lock error ==> try later ...
|
||||
return false;
|
||||
}
|
||||
@ -253,14 +262,14 @@ bool gale::resource::Program::updateContext() {
|
||||
}
|
||||
// first attach vertex shader, and after fragment shader
|
||||
for (size_t iii=0; iii<m_shaderList.size(); iii++) {
|
||||
if (m_shaderList[iii] != nullptr) {
|
||||
if (m_shaderList[iii] != null) {
|
||||
if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type::vertex) {
|
||||
gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t iii=0; iii<m_shaderList.size(); iii++) {
|
||||
if (m_shaderList[iii] != nullptr) {
|
||||
if (m_shaderList[iii] != null) {
|
||||
if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type::fragment) {
|
||||
gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID());
|
||||
}
|
||||
@ -302,7 +311,7 @@ bool gale::resource::Program::updateContext() {
|
||||
}
|
||||
|
||||
void gale::resource::Program::removeContext() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == true) {
|
||||
gale::openGL::program::remove(m_program);
|
||||
m_program = 0;
|
||||
@ -315,7 +324,7 @@ void gale::resource::Program::removeContext() {
|
||||
}
|
||||
|
||||
void gale::resource::Program::removeContextToLate() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_exist = false;
|
||||
m_program = 0;
|
||||
}
|
||||
@ -338,13 +347,13 @@ void gale::resource::Program::reload() {
|
||||
return;
|
||||
}
|
||||
// remove previous data ...
|
||||
if (m_fileData != nullptr) {
|
||||
delete[] m_fileData;
|
||||
if (m_fileData != null) {
|
||||
del ete[] m_fileData;
|
||||
m_fileData = 0;
|
||||
}
|
||||
// allocate data
|
||||
m_fileData = new char[fileSize+5];
|
||||
if (m_fileData == nullptr) {
|
||||
m_fileData = ne w char[fileSize+5];
|
||||
if (m_fileData == null) {
|
||||
GALE_ERROR("Error Memory allocation size=" << fileSize);
|
||||
return;
|
||||
}
|
||||
@ -365,7 +374,7 @@ void gale::resource::Program::sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -394,15 +403,16 @@ void gale::resource::Program::sendAttributePointer(int32_t _idElem,
|
||||
int32_t _index,
|
||||
int32_t _jumpBetweenSample,
|
||||
int32_t _offset) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
if ( _idElem < 0
|
||||
|| (size_t)_idElem > m_elementList.size()) {
|
||||
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
if (false == m_elementList[_idElem].m_isLinked) {
|
||||
if (m_elementList[_idElem].m_isLinked == false) {
|
||||
return;
|
||||
}
|
||||
// check error of the VBO goog enought ...
|
||||
@ -426,17 +436,19 @@ void gale::resource::Program::sendAttributePointer(int32_t _idElem,
|
||||
(GLvoid *)_offset); // Pointer on the buffer
|
||||
checkGlError("glVertexAttribPointer", __LINE__, _idElem);
|
||||
glEnableVertexAttribArray(m_elementList[_idElem].m_elementId);
|
||||
m_listOfVBOUsed.pushBack(m_elementList[_idElem].m_elementId);
|
||||
checkGlError("glEnableVertexAttribArray", __LINE__, _idElem);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void gale::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix, bool _transpose) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
if (_idElem<0 || (size_t)_idElem>m_elementList.size()) {
|
||||
if ( _idElem < 0
|
||||
|| (size_t)_idElem > m_elementList.size()) {
|
||||
GALE_ERROR("idElem = " << _idElem << " not in [0.." << (m_elementList.size()-1) << "]");
|
||||
return;
|
||||
}
|
||||
@ -445,7 +457,7 @@ void gale::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix
|
||||
}
|
||||
//GALE_ERROR("[" << m_elementList[_idElem].m_name << "] send 1 matrix");
|
||||
// note : Android des not supported the transposition of the matrix, then we will done it oursef:
|
||||
if (true == _transpose) {
|
||||
if (_transpose == true) {
|
||||
mat4 tmp = _matrix;
|
||||
tmp.transpose();
|
||||
glUniformMatrix4fv(m_elementList[_idElem].m_elementId, 1, GL_FALSE, tmp.m_mat);
|
||||
@ -458,7 +470,7 @@ void gale::resource::Program::uniformMatrix(int32_t _idElem, const mat4& _matrix
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void gale::resource::Program::uniform1f(int32_t _idElem, float _value1) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -473,7 +485,7 @@ void gale::resource::Program::uniform1f(int32_t _idElem, float _value1) {
|
||||
checkGlError("glUniform1f", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform2f(int32_t _idElem, float _value1, float _value2) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -488,7 +500,7 @@ void gale::resource::Program::uniform2f(int32_t _idElem, float _value1, float _
|
||||
checkGlError("glUniform2f", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform3f(int32_t _idElem, float _value1, float _value2, float _value3) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -503,7 +515,7 @@ void gale::resource::Program::uniform3f(int32_t _idElem, float _value1, float _v
|
||||
checkGlError("glUniform3f", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform4f(int32_t _idElem, float _value1, float _value2, float _value3, float _value4) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -521,7 +533,7 @@ void gale::resource::Program::uniform4f(int32_t _idElem, float _value1, float _v
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void gale::resource::Program::uniform1i(int32_t _idElem, int32_t _value1) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -536,7 +548,7 @@ void gale::resource::Program::uniform1i(int32_t _idElem, int32_t _value1) {
|
||||
checkGlError("glUniform1i", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform2i(int32_t _idElem, int32_t _value1, int32_t _value2) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -551,7 +563,7 @@ void gale::resource::Program::uniform2i(int32_t _idElem, int32_t _value1, int32_
|
||||
checkGlError("glUniform2i", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform3i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -566,7 +578,7 @@ void gale::resource::Program::uniform3i(int32_t _idElem, int32_t _value1, int32_
|
||||
checkGlError("glUniform3i", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform4i(int32_t _idElem, int32_t _value1, int32_t _value2, int32_t _value3, int32_t _value4) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -585,7 +597,7 @@ void gale::resource::Program::uniform4i(int32_t _idElem, int32_t _value1, int32_
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void gale::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -601,15 +613,15 @@ void gale::resource::Program::uniform1fv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform1fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform1fv", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -625,15 +637,15 @@ void gale::resource::Program::uniform2fv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform2fv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform2fv", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -649,8 +661,8 @@ void gale::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
GALE_VERBOSE("[" << m_elementList[_idElem].m_name << "] send " << _nbElement << " vec3");
|
||||
@ -658,7 +670,7 @@ void gale::resource::Program::uniform3fv(int32_t _idElem, int32_t _nbElement, co
|
||||
checkGlError("glUniform3fv", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, const float *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -674,8 +686,8 @@ void gale::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
GALE_VERBOSE("[" << m_elementList[_idElem].m_name << "] send " << _nbElement << " vec4");
|
||||
@ -686,7 +698,7 @@ void gale::resource::Program::uniform4fv(int32_t _idElem, int32_t _nbElement, co
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void gale::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -702,15 +714,15 @@ void gale::resource::Program::uniform1iv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform1iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform1iv", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -726,15 +738,15 @@ void gale::resource::Program::uniform2iv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform2iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform2iv", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -750,15 +762,15 @@ void gale::resource::Program::uniform3iv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform3iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
checkGlError("glUniform3iv", __LINE__, _idElem);
|
||||
}
|
||||
void gale::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, const int32_t *_value) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -774,8 +786,8 @@ void gale::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, co
|
||||
GALE_ERROR("No element to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
if (_value == nullptr) {
|
||||
GALE_ERROR("nullptr Input pointer to send at open GL ...");
|
||||
if (_value == null) {
|
||||
GALE_ERROR("null Input pointer to send at open GL ...");
|
||||
return;
|
||||
}
|
||||
glUniform4iv(m_elementList[_idElem].m_elementId, _nbElement, _value);
|
||||
@ -791,6 +803,7 @@ void gale::resource::Program::uniform4iv(int32_t _idElem, int32_t _nbElement, co
|
||||
|
||||
|
||||
void gale::resource::Program::use() {
|
||||
GALE_VERBOSE("Will use program : " << m_program);
|
||||
#ifdef PROGRAM_DISPLAY_SPEED
|
||||
g_startTime = gale::getTime();
|
||||
#endif
|
||||
@ -801,7 +814,7 @@ void gale::resource::Program::use() {
|
||||
|
||||
|
||||
void gale::resource::Program::setTexture0(int32_t _idElem, int64_t _textureOpenGlID) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -828,7 +841,7 @@ void gale::resource::Program::setTexture0(int32_t _idElem, int64_t _textureOpenG
|
||||
}
|
||||
|
||||
void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenGlID) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
@ -856,11 +869,15 @@ void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenG
|
||||
|
||||
|
||||
void gale::resource::Program::unUse() {
|
||||
//GALE_WARNING("Will use program : " << m_program);
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
GALE_VERBOSE("Will UN-use program : " << m_program);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == false) {
|
||||
return;
|
||||
}
|
||||
for (auto &it : m_listOfVBOUsed) {
|
||||
glDisableVertexAttribArray(it);
|
||||
}
|
||||
m_listOfVBOUsed.clear();
|
||||
#if 0
|
||||
if (m_hasTexture == true) {
|
||||
gale::openGL::disable(GL_TEXTURE_2D);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <gale/resource/Shader.hpp>
|
||||
#include <gale/resource/VirtualBufferObject.hpp>
|
||||
#include <etk/Color.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
namespace gale {
|
||||
namespace resource {
|
||||
@ -23,15 +24,15 @@ namespace gale {
|
||||
*/
|
||||
class progAttributeElement {
|
||||
public :
|
||||
std::string m_name; //!< Name of the element
|
||||
etk::String m_name; //!< Name of the element
|
||||
int32_t m_elementId; //!< openGl Id if this element == > can not exist ==> @ref m_isLinked
|
||||
bool m_isAttribute; //!< true if it was an attribute element, otherwite it was an uniform
|
||||
bool m_isLinked; //!< if this element does not exist this is false
|
||||
};
|
||||
//! @not_in_doc
|
||||
std::ostream& operator <<(std::ostream& _os, const gale::resource::progAttributeElement& _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, const gale::resource::progAttributeElement& _obj);
|
||||
//! @not_in_doc
|
||||
std::ostream& operator <<(std::ostream& _os, const std::vector<gale::resource::progAttributeElement>& _obj);
|
||||
etk::Stream& operator <<(etk::Stream& _os, const etk::Vector<gale::resource::progAttributeElement>& _obj);
|
||||
/**
|
||||
* @brief Program is a compilation of some fragment Shader and vertex Shader. This construct automaticly this assiciation
|
||||
* The input file must have the form : "myFile.prog"
|
||||
@ -49,19 +50,20 @@ namespace gale {
|
||||
private :
|
||||
bool m_exist; //!< the file existed
|
||||
int64_t m_program; //!< openGL id of the current program
|
||||
std::vector<ememory::SharedPtr<gale::resource::Shader>> m_shaderList; //!< List of all the shader loaded
|
||||
std::vector<gale::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user
|
||||
etk::Vector<ememory::SharedPtr<gale::resource::Shader>> m_shaderList; //!< List of all the shader loaded
|
||||
etk::Vector<gale::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user
|
||||
etk::Vector<int32_t> m_listOfVBOUsed; //!< retain the list of VBO used to disable it when unuse program ...
|
||||
bool m_hasTexture; //!< A texture has been set to the current shader
|
||||
bool m_hasTexture1; //!< A texture has been set to the current shader
|
||||
protected:
|
||||
/**
|
||||
* @brief Contructor of an opengl Program.
|
||||
* @param[in] filename Standard file name format. see @ref etk::FSNode
|
||||
* @param[in] _uri Uri of the file
|
||||
*/
|
||||
Program();
|
||||
void init(const std::string& _filename);
|
||||
void init(const etk::Uri& _uri);
|
||||
public:
|
||||
DECLARE_RESOURCE_NAMED_FACTORY(Program);
|
||||
DECLARE_RESOURCE_URI_FACTORY(Program);
|
||||
/**
|
||||
* @brief Destructor, remove the current Program.
|
||||
*/
|
||||
@ -79,42 +81,52 @@ namespace gale {
|
||||
* @param[in] _elementName Name of the requested attribute.
|
||||
* @return An abstract ID of the current attribute (this value is all time availlable, even if the program will be reloaded)
|
||||
*/
|
||||
int32_t getAttribute(std::string _elementName);
|
||||
int32_t getAttribute(etk::String _elementName);
|
||||
/**
|
||||
* @brief Send attribute table to the spefified ID attribure (not send if does not really exist in the openGL program).
|
||||
* @param[in] _idElem Id of the Attribute that might be sended.
|
||||
* @param[in] _nbElement Specifies the number of elements that are to be modified.
|
||||
* @param[in] _pointer Pointer on the data that might be sended.
|
||||
* @param[in] _vbo Reference on the buffer to send.
|
||||
* @param[in] _index Reference on the buffer to send.
|
||||
* @param[in] _jumpBetweenSample Number of byte to jump between 2 vertex (this permit to enterlace informations)
|
||||
* @param[in] _offset offset of start the elements send.
|
||||
*/
|
||||
void sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample=0);
|
||||
void sendAttributePointer(int32_t _idElem,
|
||||
const ememory::SharedPtr<gale::resource::VirtualBufferObject>& _vbo,
|
||||
int32_t _index,
|
||||
int32_t _jumpBetweenSample=0,
|
||||
int32_t _offset=0);
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec2>& _data) {
|
||||
sendAttribute(_idElem, 2/*u,v / x,y*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<vec3>& _data) {
|
||||
sendAttribute(_idElem, 3/*x,y,z,unused*/, &_data[0], 4*sizeof(btScalar));
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<etk::Color<float>>& _data) {
|
||||
sendAttribute(_idElem, 4/*r,g,b,a*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const std::vector<float>& _data) {
|
||||
sendAttribute(_idElem, 1, &_data[0]);
|
||||
}
|
||||
#ifndef THIS_IS_DEPRECATED_TO_REMOVE
|
||||
/**
|
||||
* @brief Send attribute table to the spefified ID attribure (not send if does not really exist in the openGL program).
|
||||
* @param[in] _idElem Id of the Attribute that might be sended.
|
||||
* @param[in] _nbElement Specifies the number of elements that are to be modified.
|
||||
* @param[in] _pointer Pointer on the data that might be sended.
|
||||
* @param[in] _jumpBetweenSample Number of byte to jump between 2 vertex (this permit to enterlace informations)
|
||||
*/
|
||||
void sendAttribute(int32_t _idElem,
|
||||
int32_t _nbElement,
|
||||
const void* _pointer,
|
||||
int32_t _jumpBetweenSample=0);
|
||||
inline void sendAttribute(int32_t _idElem, const etk::Vector<vec2>& _data) {
|
||||
sendAttribute(_idElem, 2/*u,v / x,y*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const etk::Vector<vec3>& _data) {
|
||||
sendAttribute(_idElem, 3/*x,y,z,unused*/, &_data[0], 4*sizeof(btScalar));
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const etk::Vector<etk::Color<float>>& _data) {
|
||||
sendAttribute(_idElem, 4/*r,g,b,a*/, &_data[0]);
|
||||
}
|
||||
inline void sendAttribute(int32_t _idElem, const etk::Vector<float>& _data) {
|
||||
sendAttribute(_idElem, 1, &_data[0]);
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @brief User request an Uniform on this program.
|
||||
* @note uniform value is availlable for all the fragment shader in the program (only one value for all)
|
||||
* @param[in] _elementName Name of the requested uniform.
|
||||
* @return An abstract ID of the current uniform (this value is all time availlable, even if the program will be reloaded)
|
||||
*/
|
||||
int32_t getUniform(std::string _elementName);
|
||||
int32_t getUniform(const etk::String& _elementName);
|
||||
/**
|
||||
* @brief Send a uniform element to the spefified ID (not send if does not really exist in the openGL program)
|
||||
* @param[in] _idElem Id of the uniform that might be sended.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
@ -10,7 +10,9 @@
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/gale.hpp>
|
||||
#include <gale/context/Context.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
|
||||
ETK_DECLARE_TYPE(gale::Resource);
|
||||
|
||||
gale::Resource::Resource() :
|
||||
m_id(0),
|
||||
@ -25,11 +27,16 @@ void gale::Resource::init() {
|
||||
m_resourceHasBeenInit=true;
|
||||
}
|
||||
|
||||
void gale::Resource::init(const std::string& _name) {
|
||||
void gale::Resource::init(const etk::String& _name) {
|
||||
m_resourceHasBeenInit=true;
|
||||
m_name = _name;
|
||||
}
|
||||
|
||||
void gale::Resource::init(const etk::Uri& _uri) {
|
||||
m_resourceHasBeenInit=true;
|
||||
m_name = _uri.get();
|
||||
}
|
||||
|
||||
const char * const gale::Resource::getType() {
|
||||
if (m_listType.size() == 0) {
|
||||
return "gale::Resource";
|
||||
@ -38,14 +45,14 @@ const char * const gale::Resource::getType() {
|
||||
}
|
||||
|
||||
void gale::Resource::addResourceType(const char* _type) {
|
||||
if (_type == nullptr) {
|
||||
if (_type == null) {
|
||||
GALE_ERROR(" try to add a type with no value...");
|
||||
return;
|
||||
}
|
||||
m_listType.push_back(_type);
|
||||
m_listType.pushBack(_type);
|
||||
}
|
||||
std::string gale::Resource::getTypeDescription() {
|
||||
std::string ret("gale::Resource");
|
||||
etk::String gale::Resource::getTypeDescription() {
|
||||
etk::String ret("gale::Resource");
|
||||
for(auto element : m_listType) {
|
||||
ret += "|";
|
||||
ret += element;
|
||||
@ -53,7 +60,7 @@ std::string gale::Resource::getTypeDescription() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool gale::Resource::isTypeCompatible(const std::string& _type) {
|
||||
bool gale::Resource::isTypeCompatible(const etk::String& _type) {
|
||||
if (_type == "gale::Resource") {
|
||||
return true;
|
||||
}
|
||||
|
@ -1,25 +1,27 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <ethread/Mutex.hpp>
|
||||
#include <ethread/MutexRecursive.hpp>
|
||||
#include <ememory/memory.hpp>
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
|
||||
#define MAX_RESOURCE_LEVEL (5)
|
||||
|
||||
#define DECLARE_RESOURCE_FACTORY(className) \
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create( GALE_TYPE&& ... _all ) { \
|
||||
ememory::SharedPtr<className> resource(new className()); \
|
||||
if (resource == nullptr) { \
|
||||
ememory::SharedPtr<className> resource(ETK_NEW(className)); \
|
||||
if (resource == null) { \
|
||||
GALE_ERROR("Factory resource error"); \
|
||||
return nullptr; \
|
||||
return null; \
|
||||
} \
|
||||
resource->init(std::forward<GALE_TYPE>(_all)... ); \
|
||||
resource->init(etk::forward<GALE_TYPE>(_all)... ); \
|
||||
if (resource->resourceHasBeenCorectlyInit() == false) { \
|
||||
GALE_CRITICAL("resource Is not correctly init : " << #className ); \
|
||||
} \
|
||||
@ -28,26 +30,55 @@
|
||||
}
|
||||
|
||||
#define DECLARE_RESOURCE_NAMED_FACTORY(className) \
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create(const std::string& _name, GALE_TYPE&& ... _all ) { \
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create(const etk::String& _name, GALE_TYPE&& ... _all ) { \
|
||||
ememory::SharedPtr<className> resource; \
|
||||
ememory::SharedPtr<gale::Resource> resource2; \
|
||||
if (_name != "" && _name != "---") { \
|
||||
if (_name.isEmpty() == false && _name != "---") { \
|
||||
resource2 = getManager().localKeep(_name); \
|
||||
} \
|
||||
if (resource2 != nullptr) { \
|
||||
if (resource2 != null) { \
|
||||
resource = ememory::dynamicPointerCast<className>(resource2); \
|
||||
if (resource == nullptr) { \
|
||||
if (resource == null) { \
|
||||
GALE_CRITICAL("Request resource file : '" << _name << "' With the wrong type (dynamic cast error)"); \
|
||||
return nullptr; \
|
||||
return null; \
|
||||
} \
|
||||
return resource; \
|
||||
} \
|
||||
resource = ememory::SharedPtr<className>(new className()); \
|
||||
if (resource == nullptr) { \
|
||||
resource = ememory::SharedPtr<className>(ETK_NEW(className)); \
|
||||
if (resource == null) { \
|
||||
GALE_ERROR("allocation error of a resource : " << _name); \
|
||||
return nullptr; \
|
||||
return null; \
|
||||
} \
|
||||
resource->init(_name, std::forward<GALE_TYPE>(_all)... ); \
|
||||
resource->init(_name, etk::forward<GALE_TYPE>(_all)... ); \
|
||||
if (resource->resourceHasBeenCorectlyInit() == false) { \
|
||||
GALE_CRITICAL("resource Is not correctly init : " << #className ); \
|
||||
} \
|
||||
getManager().localAdd(resource); \
|
||||
return resource; \
|
||||
}
|
||||
|
||||
#define DECLARE_RESOURCE_URI_FACTORY(className) \
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create(const etk::Uri& _uri, GALE_TYPE&& ... _all ) { \
|
||||
ememory::SharedPtr<className> resource; \
|
||||
ememory::SharedPtr<gale::Resource> resource2; \
|
||||
etk::String name = _uri.get(); \
|
||||
if (name.isEmpty() == false && name != "---") { \
|
||||
resource2 = getManager().localKeep(name); \
|
||||
} \
|
||||
if (resource2 != null) { \
|
||||
resource = ememory::dynamicPointerCast<className>(resource2); \
|
||||
if (resource == null) { \
|
||||
GALE_CRITICAL("Request resource file : '" << name << "' With the wrong type (dynamic cast error)"); \
|
||||
return null; \
|
||||
} \
|
||||
return resource; \
|
||||
} \
|
||||
resource = ememory::SharedPtr<className>(ETK_NEW(className)); \
|
||||
if (resource == null) { \
|
||||
GALE_ERROR("allocation error of a resource : " << name); \
|
||||
return null; \
|
||||
} \
|
||||
resource->init(_uri, etk::forward<GALE_TYPE>(_all)... ); \
|
||||
if (resource->resourceHasBeenCorectlyInit() == false) { \
|
||||
GALE_CRITICAL("resource Is not correctly init : " << #className ); \
|
||||
} \
|
||||
@ -59,22 +90,22 @@
|
||||
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create(GALE_TYPE&& ... _all ) { \
|
||||
ememory::SharedPtr<className> resource; \
|
||||
ememory::SharedPtr<gale::Resource> resource2 = getManager().localKeep(uniqueName); \
|
||||
if (resource2 != nullptr) { \
|
||||
if (resource2 != null) { \
|
||||
resource = ememory::dynamicPointerCast<className>(resource2); \
|
||||
if (resource == nullptr) { \
|
||||
if (resource == null) { \
|
||||
GALE_CRITICAL("Request resource file : '" << uniqueName << "' With the wrong type (dynamic cast error)"); \
|
||||
return nullptr; \
|
||||
return null; \
|
||||
} \
|
||||
} \
|
||||
if (resource != nullptr) { \
|
||||
if (resource != null) { \
|
||||
return resource; \
|
||||
} \
|
||||
resource = ememory::SharedPtr<className>(new className()); \
|
||||
if (resource == nullptr) { \
|
||||
resource = ememory::SharedPtr<className>(ETK_NEW(className)); \
|
||||
if (resource == null) { \
|
||||
GALE_ERROR("allocation error of a resource : " << uniqueName); \
|
||||
return nullptr; \
|
||||
return null; \
|
||||
} \
|
||||
resource->init(uniqueName, std::forward<GALE_TYPE>(_all)... ); \
|
||||
resource->init(uniqueName, etk::forward<GALE_TYPE>(_all)... ); \
|
||||
if (resource->resourceHasBeenCorectlyInit() == false) { \
|
||||
GALE_CRITICAL("resource Is not correctly init : " << #className ); \
|
||||
} \
|
||||
@ -97,7 +128,7 @@ namespace gale {
|
||||
*/
|
||||
class Resource : public ememory::EnableSharedFromThis<gale::Resource> {
|
||||
protected:
|
||||
mutable std::recursive_mutex m_mutex;
|
||||
mutable ethread::MutexRecursive m_mutex;
|
||||
protected:
|
||||
/**
|
||||
* @brief generic protected contructor (use factory to create this class)
|
||||
@ -106,10 +137,13 @@ namespace gale {
|
||||
/**
|
||||
* @brief Initialisation of the class and previous classes.
|
||||
* @param[in] _name Name of the resource.
|
||||
* @param[in] _uri Uri of the resource.
|
||||
*/
|
||||
void init();
|
||||
//! @previous
|
||||
void init(const std::string& _name);
|
||||
void init(const etk::String& _name);
|
||||
//! @previous
|
||||
void init(const etk::Uri& _uri);
|
||||
public:
|
||||
//! geenric destructor
|
||||
virtual ~Resource() {
|
||||
@ -128,7 +162,7 @@ namespace gale {
|
||||
return m_resourceHasBeenInit;
|
||||
}
|
||||
private:
|
||||
std::vector<const char*> m_listType;
|
||||
etk::Vector<const char*> m_listType;
|
||||
public:
|
||||
/**
|
||||
* @brief get the current type of the Resource
|
||||
@ -139,34 +173,34 @@ namespace gale {
|
||||
* @brief Get the herarchic of the Resource type.
|
||||
* @return descriptive string.
|
||||
*/
|
||||
std::string getTypeDescription();
|
||||
etk::String getTypeDescription();
|
||||
/**
|
||||
* @brief check if the element herited from a specific type
|
||||
* @param[in] _type Type to check.
|
||||
* @return true if the element is compatible.
|
||||
*/
|
||||
bool isTypeCompatible(const std::string& _type);
|
||||
bool isTypeCompatible(const etk::String& _type);
|
||||
protected:
|
||||
/**
|
||||
* @brief Add a type of the list of Object.
|
||||
* @param[in] _type new type to add.
|
||||
* @param[in] _type Type to add.
|
||||
*/
|
||||
void addResourceType(const char* _type);
|
||||
protected:
|
||||
std::string m_name; //!< name of the resource ...
|
||||
etk::String m_name; //!< name of the resource ...
|
||||
public:
|
||||
/**
|
||||
* @brief get the resource name
|
||||
* @return The requested name
|
||||
*/
|
||||
const std::string& getName() const {
|
||||
const etk::String& getName() const {
|
||||
return m_name;
|
||||
};
|
||||
/**
|
||||
* @brief get the resource name
|
||||
* @param[in] _name The new name
|
||||
* @param[in] _name The name to set.
|
||||
*/
|
||||
void setName(const std::string& _name) {
|
||||
void setName(const etk::String& _name) {
|
||||
m_name = _name;
|
||||
};
|
||||
protected:
|
||||
|
@ -1,17 +1,20 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/os/FSNode.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/resource/Shader.hpp>
|
||||
#include <gale/resource/Manager.hpp>
|
||||
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::resource::Shader);
|
||||
|
||||
gale::resource::Shader::Shader() :
|
||||
gale::Resource(),
|
||||
m_exist(false),
|
||||
@ -22,33 +25,33 @@ gale::resource::Shader::Shader() :
|
||||
m_resourceLevel = 0;
|
||||
}
|
||||
|
||||
void gale::resource::Shader::init(const std::string& _filename) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
gale::Resource::init(_filename);
|
||||
GALE_DEBUG("OGL : load SHADER '" << _filename << "'");
|
||||
void gale::resource::Shader::init(const etk::Uri& _uri) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
gale::Resource::init(_uri.get());
|
||||
GALE_DEBUG("OGL : load SHADER '" << _uri << "'");
|
||||
// load data from file "all the time ..."
|
||||
|
||||
if (etk::end_with(m_name, ".frag") == true) {
|
||||
if (_uri.getPath().getExtention() == "frag") {
|
||||
m_type = gale::openGL::shader::type::fragment;
|
||||
} else if (etk::end_with(m_name, ".vert") == true) {
|
||||
} else if (_uri.getPath().getExtention() == "vert") {
|
||||
m_type = gale::openGL::shader::type::vertex;
|
||||
} else {
|
||||
GALE_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << m_name << "\"");
|
||||
GALE_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << _uri << "\"");
|
||||
return;
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
gale::resource::Shader::~Shader() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_fileData.clear();
|
||||
gale::openGL::shader::remove(m_shader);
|
||||
m_exist = false;
|
||||
}
|
||||
|
||||
bool gale::resource::Shader::updateContext() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex, std::defer_lock);
|
||||
if (lock.try_lock() == false) {
|
||||
ethread::RecursiveLock lock(m_mutex, true);
|
||||
if (lock.tryLock() == false) {
|
||||
//Lock error ==> try later ...
|
||||
return false;
|
||||
}
|
||||
@ -83,7 +86,7 @@ bool gale::resource::Shader::updateContext() {
|
||||
}
|
||||
|
||||
void gale::resource::Shader::removeContext() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (true == m_exist) {
|
||||
gale::openGL::shader::remove(m_shader);
|
||||
m_exist = false;
|
||||
@ -91,34 +94,21 @@ void gale::resource::Shader::removeContext() {
|
||||
}
|
||||
|
||||
void gale::resource::Shader::removeContextToLate() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_exist = false;
|
||||
m_shader = 0;
|
||||
}
|
||||
|
||||
void gale::resource::Shader::reload() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
etk::FSNode file(m_name);
|
||||
if (false == file.exist()) {
|
||||
GALE_CRITICAL("File does not Exist : '" << file << "' : '" << file.getFileSystemName() << "'");
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
etk::Uri uri = m_name;
|
||||
if (etk::uri::exist(uri) == false) {
|
||||
GALE_CRITICAL("File does not Exist : '" << uri << "' : path='" << uri.getPath() << "'");
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t fileSize = file.fileSize();
|
||||
if (0 == fileSize) {
|
||||
GALE_CRITICAL("This file is empty : " << file);
|
||||
return;
|
||||
}
|
||||
if (false == file.fileOpenRead()) {
|
||||
GALE_CRITICAL("Can not open the file : " << file);
|
||||
return;
|
||||
}
|
||||
m_fileData = file.fileReadAllString();
|
||||
// close the file:
|
||||
file.fileClose();
|
||||
|
||||
etk::uri::readAll(uri, m_fileData);
|
||||
GALE_VERBOSE("load shader:\n-----------------------------------------------------------------\n" << m_fileData << "\n-----------------------------------------------------------------");
|
||||
// now change the OGL context ...
|
||||
|
||||
if (gale::openGL::hasContext() == true) {
|
||||
GALE_DEBUG("OGL : load SHADER '" << m_name << "' ==> call update context (direct)");
|
||||
removeContext();
|
||||
@ -126,8 +116,8 @@ void gale::resource::Shader::reload() {
|
||||
} else {
|
||||
GALE_DEBUG("OGL : load SHADER '" << m_name << "' ==> tagged has update context needed");
|
||||
// TODO : Check this, this is a leek ==> in the GPU ... really bad ...
|
||||
m_exist = false;
|
||||
m_shader = 0;
|
||||
m_exist = false;
|
||||
m_shader = 0;
|
||||
getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <gale/debug.hpp>
|
||||
#include <gale/renderer/openGL/openGL.hpp>
|
||||
#include <gale/resource/Resource.hpp>
|
||||
#include <etk/uri/uri.hpp>
|
||||
|
||||
namespace gale {
|
||||
namespace resource {
|
||||
@ -18,7 +19,7 @@ namespace gale {
|
||||
class Shader : public gale::Resource {
|
||||
private :
|
||||
bool m_exist; //!< The shader file existed and has been loaded
|
||||
std::string m_fileData; //!< A copy of the data loaded from the file (usefull only when opengl context is removed)
|
||||
etk::String m_fileData; //!< A copy of the data loaded from the file (usefull only when opengl context is removed)
|
||||
int64_t m_shader; //!< opengl id of this element
|
||||
gale::openGL::shader::type m_type; //!< Type of the current shader(vertex/fragment)
|
||||
protected:
|
||||
@ -28,8 +29,8 @@ namespace gale {
|
||||
*/
|
||||
Shader();
|
||||
public:
|
||||
void init(const std::string& _filename);
|
||||
DECLARE_RESOURCE_NAMED_FACTORY(Shader);
|
||||
void init(const etk::Uri& _uri);
|
||||
DECLARE_RESOURCE_URI_FACTORY(Shader);
|
||||
/**
|
||||
* @brief Destructor, remove the current Shader
|
||||
*/
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
@ -10,6 +10,8 @@
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/resource/Texture.hpp>
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::resource::Texture);
|
||||
|
||||
/**
|
||||
* @brief get the next power 2 if the input
|
||||
@ -29,7 +31,7 @@ static int32_t nextP2(int32_t _value) {
|
||||
}
|
||||
|
||||
|
||||
void gale::resource::Texture::init(const std::string& _filename) {
|
||||
void gale::resource::Texture::init(const etk::String& _filename) {
|
||||
gale::Resource::init(_filename);
|
||||
}
|
||||
void gale::resource::Texture::init() {
|
||||
@ -43,7 +45,7 @@ gale::resource::Texture::Texture() :
|
||||
m_size(0,0),
|
||||
m_dataType(gale::resource::Texture::dataType::int16),
|
||||
m_dataColorSpace(gale::resource::Texture::color::mono) {
|
||||
addResourceType("gale::compositing::Texture");
|
||||
addResourceType("gale::resource::Texture");
|
||||
}
|
||||
|
||||
gale::resource::Texture::~Texture() {
|
||||
@ -51,12 +53,12 @@ gale::resource::Texture::~Texture() {
|
||||
}
|
||||
|
||||
bool gale::resource::Texture::updateContext() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex, std::defer_lock);
|
||||
if (lock.try_lock() == false) {
|
||||
ethread::RecursiveLock lock(m_mutex, true);
|
||||
if (lock.tryLock() == false) {
|
||||
//Lock error ==> try later ...
|
||||
return false;
|
||||
}
|
||||
if (false == m_loaded) {
|
||||
if (m_loaded == false) {
|
||||
// Request a new texture at openGl :
|
||||
glGenTextures(1, &m_texId);
|
||||
}
|
||||
@ -88,32 +90,33 @@ bool gale::resource::Texture::updateContext() {
|
||||
}
|
||||
|
||||
void gale::resource::Texture::removeContext() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (true == m_loaded) {
|
||||
// Request remove texture ...
|
||||
GALE_INFO("TEXTURE: Rm [" << getId() << "] texId=" << m_texId);
|
||||
// TODO: Check if we are in the correct thread
|
||||
glDeleteTextures(1, &m_texId);
|
||||
m_loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
void gale::resource::Texture::removeContextToLate() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_loaded = false;
|
||||
m_texId=0;
|
||||
}
|
||||
|
||||
void gale::resource::Texture::flush() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
// request to the manager to be call at the next update ...
|
||||
getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
|
||||
}
|
||||
|
||||
void gale::resource::Texture::setTexture(const ememory::SharedPtr<std::vector<char>>& _data,
|
||||
void gale::resource::Texture::setTexture(const ememory::SharedPtr<etk::Vector<char>>& _data,
|
||||
const ivec2& _size,
|
||||
enum gale::resource::Texture::dataType _dataType,
|
||||
enum gale::resource::Texture::color _dataColorSpace) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_data = _data;
|
||||
m_size = _size;
|
||||
m_endPointSize = _size;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -45,7 +45,7 @@ namespace gale {
|
||||
};
|
||||
// Public API:
|
||||
protected:
|
||||
void init(const std::string& _filename);
|
||||
void init(const etk::String& _filename);
|
||||
void init();
|
||||
Texture();
|
||||
public:
|
||||
@ -57,12 +57,12 @@ namespace gale {
|
||||
|
||||
private:
|
||||
// Image propoerties:
|
||||
ememory::SharedPtr<std::vector<char>> m_data; //!< pointer on the image data.
|
||||
ememory::SharedPtr<etk::Vector<char>> m_data; //!< pointer on the image data.
|
||||
ivec2 m_size; //!< size of the image data.
|
||||
enum dataType m_dataType; //!< Type of the image.
|
||||
enum color m_dataColorSpace; //!< Color space of the image.
|
||||
public:
|
||||
void setTexture(const ememory::SharedPtr<std::vector<char>>& _data,
|
||||
void setTexture(const ememory::SharedPtr<etk::Vector<char>>& _data,
|
||||
const ivec2& _size,
|
||||
enum gale::resource::Texture::dataType _dataType,
|
||||
enum gale::resource::Texture::color _dataColorSpace);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
@ -9,6 +9,8 @@
|
||||
#include <gale/resource/Manager.hpp>
|
||||
#include <gale/resource/VirtualBufferObject.hpp>
|
||||
#include <gale/renderer/openGL/openGL-include.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(gale::resource::VirtualBufferObject);
|
||||
|
||||
void gale::resource::VirtualBufferObject::init(int32_t _number) {
|
||||
gale::Resource::init();
|
||||
@ -19,6 +21,20 @@ void gale::resource::VirtualBufferObject::init(int32_t _number) {
|
||||
GALE_DEBUG("OGL : load VBO count=\"" << _number << "\"");
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::clear() {
|
||||
GALE_VERBOSE(" Clear: [" << getId() << "] '" << getName() << "' (size=" << m_buffer[0].size() << ")");
|
||||
// DO not clear the m_vbo indexed in the graphic cards ...
|
||||
for (size_t iii=0; iii<m_vboUsed.size(); ++iii) {
|
||||
m_vboUsed[iii] = false;
|
||||
}
|
||||
for (auto &it : m_buffer) {
|
||||
it.clear();
|
||||
}
|
||||
for (auto &it : m_vboSizeDataOffset) {
|
||||
it = -1;
|
||||
}
|
||||
}
|
||||
|
||||
gale::resource::VirtualBufferObject::VirtualBufferObject() :
|
||||
m_exist(false) {
|
||||
addResourceType("gale::VirtualBufferObject");
|
||||
@ -34,35 +50,38 @@ void gale::resource::VirtualBufferObject::retreiveData() {
|
||||
}
|
||||
|
||||
bool gale::resource::VirtualBufferObject::updateContext() {
|
||||
GALE_ERROR(" Start");
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex, std::defer_lock);
|
||||
if (lock.try_lock() == false) {
|
||||
GALE_VERBOSE(" Start: [" << getId() << "] '" << getName() << "' (size=" << m_buffer[0].size() << ")");
|
||||
ethread::RecursiveLock lock(m_mutex, true);
|
||||
if (lock.tryLock() == false) {
|
||||
//Lock error ==> try later ...
|
||||
GALE_WARNING(" ==> Lock error on VBO");
|
||||
return false;
|
||||
}
|
||||
if (false == m_exist) {
|
||||
if (m_exist == false) {
|
||||
GALE_DEBUG(" ==> ALLOCATE new handle");
|
||||
// Allocate and assign a Vertex Array Object to our handle
|
||||
gale::openGL::genBuffers(m_vbo);
|
||||
}
|
||||
m_exist = true;
|
||||
for (size_t iii=0; iii<m_vbo.size(); iii++) {
|
||||
GALE_INFO("VBO : add [" << getId() << "]=" << m_buffer[iii].size() << "*sizeof(float) OGl_Id=" << m_vbo[iii]);
|
||||
if (true == m_vboUsed[iii]) {
|
||||
GALE_VERBOSE("VBO : add [" << getId() << "]=" << m_buffer[iii].size() << "*sizeof(float) OGl_Id=" << m_vbo[iii]);
|
||||
if (m_vboUsed[iii] == true) {
|
||||
// select the buffer to set data inside it ...
|
||||
if (m_buffer[iii].size()>0) {
|
||||
if (m_buffer[iii].size() > 0) {
|
||||
gale::openGL::bindBuffer(m_vbo[iii]);
|
||||
gale::openGL::bufferData(sizeof(float)*m_buffer[iii].size(), &((m_buffer[iii])[0]), gale::openGL::usage::staticDraw);
|
||||
float* bufferPonter =&(m_buffer[iii][0]);
|
||||
gale::openGL::bufferData(sizeof(float)*m_buffer[iii].size(), bufferPonter, gale::openGL::usage::streamDraw);
|
||||
}
|
||||
}
|
||||
}
|
||||
// un-bind it to permet to have no error in the next display ...
|
||||
gale::openGL::unbindBuffer();
|
||||
GALE_ERROR(" Stop");
|
||||
GALE_VERBOSE(" Stop: [" << getId() << "] '" << getName() << "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::removeContext() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_exist == true) {
|
||||
gale::openGL::deleteBuffers(m_vbo);
|
||||
m_exist = false;
|
||||
@ -70,7 +89,7 @@ void gale::resource::VirtualBufferObject::removeContext() {
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::removeContextToLate() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
m_exist = false;
|
||||
for (size_t iii=0; iii<m_vbo.size(); iii++) {
|
||||
m_vbo[iii] = 0;
|
||||
@ -78,19 +97,20 @@ void gale::resource::VirtualBufferObject::removeContextToLate() {
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::reload() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
removeContext();
|
||||
updateContext();
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::flush() {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
// request to the manager to be call at the next update ...
|
||||
getManager().update(ememory::dynamicPointerCast<gale::Resource>(sharedFromThis()));
|
||||
GALE_VERBOSE("Request flush of VBO: [" << getId() << "] '" << getName() << "'");
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec3& _data) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 3;
|
||||
} else if (m_vboSizeDataOffset[_id] != 3) {
|
||||
@ -98,13 +118,13 @@ void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec3&
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.x());
|
||||
m_buffer[_id].push_back(_data.y());
|
||||
m_buffer[_id].push_back(_data.z());
|
||||
m_buffer[_id].pushBack(_data.x());
|
||||
m_buffer[_id].pushBack(_data.y());
|
||||
m_buffer[_id].pushBack(_data.z());
|
||||
}
|
||||
|
||||
vec3 gale::resource::VirtualBufferObject::getOnBufferVec3(int32_t _id, int32_t _elementID) const {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if ((size_t)_elementID*3 > m_buffer[_id].size()) {
|
||||
return vec3(0,0,0);
|
||||
}
|
||||
@ -114,16 +134,16 @@ vec3 gale::resource::VirtualBufferObject::getOnBufferVec3(int32_t _id, int32_t _
|
||||
}
|
||||
|
||||
int32_t gale::resource::VirtualBufferObject::bufferSize(int32_t _id) const {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
return m_buffer[_id].size()/m_vboSizeDataOffset[_id];
|
||||
}
|
||||
int32_t gale::resource::VirtualBufferObject::getElementSize(int32_t _id) const {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
return m_vboSizeDataOffset[_id];
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec2& _data) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 2;
|
||||
} else if (m_vboSizeDataOffset[_id] != 2) {
|
||||
@ -131,12 +151,12 @@ void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const vec2&
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.x());
|
||||
m_buffer[_id].push_back(_data.y());
|
||||
m_buffer[_id].pushBack(_data.x());
|
||||
m_buffer[_id].pushBack(_data.y());
|
||||
}
|
||||
|
||||
vec2 gale::resource::VirtualBufferObject::getOnBufferVec2(int32_t _id, int32_t _elementID) const {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if ((size_t)_elementID*2 > m_buffer[_id].size()) {
|
||||
return vec2(0,0);
|
||||
}
|
||||
@ -144,51 +164,8 @@ vec2 gale::resource::VirtualBufferObject::getOnBufferVec2(int32_t _id, int32_t _
|
||||
m_buffer[_id][2*_elementID+1]);
|
||||
}
|
||||
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,4>& _data) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 4;
|
||||
} else if (m_vboSizeDataOffset[_id] != 4) {
|
||||
GALE_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
m_buffer[_id].push_back(_data.g());
|
||||
m_buffer[_id].push_back(_data.b());
|
||||
m_buffer[_id].push_back(_data.a());
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,3>& _data) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 3;
|
||||
} else if (m_vboSizeDataOffset[_id] != 3) {
|
||||
GALE_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
m_buffer[_id].push_back(_data.g());
|
||||
m_buffer[_id].push_back(_data.b());
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,2>& _data) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 2;
|
||||
} else if (m_vboSizeDataOffset[_id] != 2) {
|
||||
GALE_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
m_buffer[_id].push_back(_data.g());
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,1>& _data) {
|
||||
std::unique_lock<std::recursive_mutex> lock(m_mutex);
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const float& _data) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 1;
|
||||
} else if (m_vboSizeDataOffset[_id] != 1) {
|
||||
@ -196,6 +173,60 @@ void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::C
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].push_back(_data.r());
|
||||
m_buffer[_id].pushBack(_data);
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,4>& _data) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 4;
|
||||
} else if (m_vboSizeDataOffset[_id] != 4) {
|
||||
GALE_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].pushBack(_data.r());
|
||||
m_buffer[_id].pushBack(_data.g());
|
||||
m_buffer[_id].pushBack(_data.b());
|
||||
m_buffer[_id].pushBack(_data.a());
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,3>& _data) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 3;
|
||||
} else if (m_vboSizeDataOffset[_id] != 3) {
|
||||
GALE_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].pushBack(_data.r());
|
||||
m_buffer[_id].pushBack(_data.g());
|
||||
m_buffer[_id].pushBack(_data.b());
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,2>& _data) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 2;
|
||||
} else if (m_vboSizeDataOffset[_id] != 2) {
|
||||
GALE_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].pushBack(_data.r());
|
||||
m_buffer[_id].pushBack(_data.g());
|
||||
}
|
||||
|
||||
void gale::resource::VirtualBufferObject::pushOnBuffer(int32_t _id, const etk::Color<float,1>& _data) {
|
||||
ethread::RecursiveLock lock(m_mutex);
|
||||
if (m_vboSizeDataOffset[_id] == -1) {
|
||||
m_vboSizeDataOffset[_id] = 1;
|
||||
} else if (m_vboSizeDataOffset[_id] != 1) {
|
||||
GALE_WARNING("set multiType in VBO (Not supported ==> TODO : Maybe update it");
|
||||
return;
|
||||
}
|
||||
m_vboUsed[_id] = true;
|
||||
m_buffer[_id].pushBack(_data.r());
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license APACHE v2.0 (see license file)
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@ -20,10 +20,10 @@ namespace gale {
|
||||
class VirtualBufferObject : public gale::Resource {
|
||||
private :
|
||||
bool m_exist; //!< This data is availlable in the Graphic card
|
||||
std::vector<uint32_t> m_vbo; //!< openGl ID of this VBO
|
||||
std::vector<bool> m_vboUsed; //!< true if the VBO is allocated or used ...
|
||||
std::vector<std::vector<float>> m_buffer; //!< data that is availlable in the VBO system ...
|
||||
std::vector<int8_t> m_vboSizeDataOffset; //!< Internal size of the VBO (dynamicly set)
|
||||
etk::Vector<uint32_t> m_vbo; //!< openGl ID of this VBO
|
||||
etk::Vector<bool> m_vboUsed; //!< true if the VBO is allocated or used ...
|
||||
etk::Vector<etk::Vector<float>> m_buffer; //!< data that is availlable in the VBO system ...
|
||||
etk::Vector<int8_t> m_vboSizeDataOffset; //!< Internal size of the VBO (dynamicly set)
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor of this VBO.
|
||||
@ -38,6 +38,10 @@ namespace gale {
|
||||
*/
|
||||
virtual ~VirtualBufferObject();
|
||||
public:
|
||||
/**
|
||||
* @brief clear buffers
|
||||
*/
|
||||
void clear();
|
||||
/**
|
||||
* @brief get the real openGL ID.
|
||||
* @return the Ogl id reference of this VBO.
|
||||
@ -50,7 +54,7 @@ namespace gale {
|
||||
* @param[in] id Id of the buffer requested
|
||||
* @return A reference on the data.
|
||||
*/
|
||||
std::vector<float>& getRefBuffer(int32_t _id) {
|
||||
etk::Vector<float>& getRefBuffer(int32_t _id) {
|
||||
m_vboUsed[_id] = true;
|
||||
return m_buffer[_id];
|
||||
};
|
||||
@ -92,6 +96,8 @@ namespace gale {
|
||||
void pushOnBuffer(int32_t _id, const etk::Color<float,2>& _data);
|
||||
//! @previous
|
||||
void pushOnBuffer(int32_t _id, const etk::Color<float,1>& _data);
|
||||
//! @previous
|
||||
void pushOnBuffer(int32_t _id, const float& _data);
|
||||
/**
|
||||
* @brief get the data from the graphic card.
|
||||
*/
|
||||
|
13
license.txt
13
license.txt
@ -1,13 +0,0 @@
|
||||
Copyright gale Edouard DUPIN
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ def get_desc():
|
||||
return "Simple windows with gale"
|
||||
|
||||
def get_licence():
|
||||
return "APACHE-2"
|
||||
return "MPL-2"
|
||||
|
||||
def get_compagny_type():
|
||||
return "com"
|
||||
|
107
lutin_gale.py
107
lutin_gale.py
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.tools as tools
|
||||
import lutin.debug as debug
|
||||
import realog.debug as debug
|
||||
import lutin.image as image
|
||||
import os
|
||||
import lutin.multiprocess as lutinMultiprocess
|
||||
@ -14,7 +14,7 @@ def get_desc():
|
||||
return "gale is a main library to use widget in the openGl environement and manage all the wraping os"
|
||||
|
||||
def get_licence():
|
||||
return "APACHE-2"
|
||||
return "MPL-2"
|
||||
|
||||
def get_compagny_type():
|
||||
return "com"
|
||||
@ -61,8 +61,24 @@ def configure(target, my_module):
|
||||
'gale/context/cursor.hpp',
|
||||
'gale/context/Fps.hpp'
|
||||
])
|
||||
if "Linux" in target.get_type():
|
||||
my_module.add_src_file('gale/context/X11/Context.cpp')
|
||||
if "Web" in target.get_type():
|
||||
my_module.add_src_file('gale/context/SDL/Context.cpp')
|
||||
elif "Linux" in target.get_type():
|
||||
|
||||
my_module.add_optionnal_depend(
|
||||
'X11',
|
||||
["c++", "-DGALE_BUILD_X11"],
|
||||
src_file=[
|
||||
'gale/context/X11/Context.cpp',
|
||||
]
|
||||
)
|
||||
my_module.add_optionnal_depend(
|
||||
'wayland',
|
||||
["c++", "-DGALE_BUILD_WAYLAND"],
|
||||
src_file=[
|
||||
'gale/context/wayland/Context.cpp',
|
||||
]
|
||||
)
|
||||
# check if egami is present in the worktree: this is for the icon parsing ...
|
||||
my_module.add_optionnal_depend('egami', ["c++", "-DGALE_BUILD_EGAMI"])
|
||||
elif "Windows" in target.get_type():
|
||||
@ -98,6 +114,15 @@ def configure(target, my_module):
|
||||
])
|
||||
else:
|
||||
debug.error("unknow mode...")
|
||||
|
||||
if "Linux" in target.get_type() \
|
||||
or "Windows" in target.get_type() \
|
||||
or "MacOs" in target.get_type():
|
||||
# only in debug we add simulation:
|
||||
if target.get_mode() == "debug":
|
||||
my_module.add_flag('c++', "-DGALE_BUILD_SIMULATION")
|
||||
my_module.add_src_file('gale/context/simulation/Context.cpp')
|
||||
|
||||
# Key properties:
|
||||
my_module.add_src_file([
|
||||
'gale/key/keyboard.cpp',
|
||||
@ -150,8 +175,18 @@ def configure(target, my_module):
|
||||
"-DGALE_VERSION=\"\\\"" + tools.version_to_string(my_module.get_pkg("VERSION")) + "\\\"\""
|
||||
])
|
||||
|
||||
if "Linux" in target.get_type():
|
||||
pass
|
||||
if "Web" in target.get_type():
|
||||
my_module.add_depend([
|
||||
"SDL"
|
||||
])
|
||||
elif "Linux" in target.get_type():
|
||||
# TODO : This is specific at wayland ==> check How we can add it better
|
||||
my_module.add_depend([
|
||||
'egl',
|
||||
'gles2',
|
||||
'xkbcommon'
|
||||
])
|
||||
my_module.add_action(tool_generate_wayland_protocol, data={})
|
||||
elif "Android" in target.get_type():
|
||||
my_module.add_depend(["SDK", "jvm-basics"])
|
||||
# add tre creator of the basic java class ...
|
||||
@ -178,6 +213,54 @@ def configure(target, my_module):
|
||||
|
||||
|
||||
|
||||
##################################################################
|
||||
##
|
||||
## Wayland specific section
|
||||
##
|
||||
##################################################################
|
||||
def tool_generate_wayland_protocol(target, module, package_name):
|
||||
file_list = []
|
||||
debug.warning("------------------------------------------------------------------------")
|
||||
debug.warning("Generate wayland back elements... '" + str(module) + "'" )
|
||||
debug.warning("------------------------------------------------------------------------")
|
||||
cmd = ["pkg-config", "wayland-protocols", "--variable=pkgdatadir"]
|
||||
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
|
||||
if ret == False:
|
||||
debug.error("Can not execute protocol extraction...")
|
||||
WAYLAND_PROTOCOLS_DIR = ret
|
||||
debug.warning("WAYLAND_PROTOCOLS_DIR = " + str(WAYLAND_PROTOCOLS_DIR))
|
||||
cmd = ["pkg-config", "--variable=wayland_scanner", "wayland-scanner"]
|
||||
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
|
||||
if ret == False:
|
||||
debug.error("Can not execute protocol extraction...")
|
||||
WAYLAND_SCANNER = ret
|
||||
debug.warning("WAYLAND_SCANNER = " + str(WAYLAND_SCANNER))
|
||||
XDG_SHELL_PROTOCOL = os.path.join(WAYLAND_PROTOCOLS_DIR, "stable", "xdg-shell", "xdg-shell.xml")
|
||||
debug.warning("XDG_SHELL_PROTOCOL = " + str(XDG_SHELL_PROTOCOL))
|
||||
client_protocol_header = "xdg-shell-client-protocol.h"
|
||||
client_protocol = "xdg-shell-protocol.c"
|
||||
# create files
|
||||
|
||||
debug.warning("Generate file = " + client_protocol_header)
|
||||
tmp_file = "/tmp/gale_wayland.tmp"
|
||||
cmd = [WAYLAND_SCANNER, "client-header", XDG_SHELL_PROTOCOL, tmp_file]
|
||||
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
|
||||
if ret == False:
|
||||
debug.error("error in generate wayland header code")
|
||||
tmp_file_data = tools.file_read_data(tmp_file)
|
||||
module.add_generated_header_file(tmp_file_data, client_protocol_header)
|
||||
|
||||
|
||||
debug.warning("Generate file = " + client_protocol)
|
||||
cmd = [WAYLAND_SCANNER, "private-code", XDG_SHELL_PROTOCOL, tmp_file]
|
||||
ret = lutinMultiprocess.run_command_direct(tools.list_to_str(cmd))
|
||||
if ret == False:
|
||||
debug.error("Error in wayland generation code of private header protocole")
|
||||
|
||||
tmp_file_data = tools.file_read_data(tmp_file)
|
||||
module.add_generated_src_file(tmp_file_data, client_protocol)
|
||||
|
||||
|
||||
##################################################################
|
||||
##
|
||||
## Android specific section
|
||||
@ -212,7 +295,7 @@ def tool_generate_main_java_class(target, module, package_name):
|
||||
tmpFile.write( "/**\n")
|
||||
tmpFile.write( " * @author Edouard DUPIN, Kevin BILLONNEAU\n")
|
||||
tmpFile.write( " * @copyright 2011, Edouard DUPIN, all right reserved\n")
|
||||
tmpFile.write( " * @license APACHE v2.0 (see license file)\n")
|
||||
tmpFile.write( " * @license MPL-2 (see license file)\n")
|
||||
tmpFile.write( " * @note This file is autogenerate ==> see documantation to generate your own\n")
|
||||
tmpFile.write( " */\n")
|
||||
tmpFile.write( "package "+ android_package_name + ";\n")
|
||||
@ -249,8 +332,8 @@ def tool_generate_main_java_class(target, module, package_name):
|
||||
tmpFile.write( " \n")
|
||||
if module.get_pkg("ANDROID_APPL_TYPE")!="APPL":
|
||||
tmpFile.write( " public Engine onCreateEngine() {\n")
|
||||
tmpFile.write( " Engine tmpEngine = super.onCreateEngine();\n")
|
||||
tmpFile.write( " initApkPath(\"" + module.get_pkg("COMPAGNY_TYPE")+"\", \""+module.get_pkg("COMPAGNY_NAME2")+"\", \"" + application_name + "\", \"" + package_name + "\");\n")
|
||||
tmpFile.write( " Engine tmpEngine = super.onCreateEngine();\n")
|
||||
tmpFile.write( " return tmpEngine;\n")
|
||||
tmpFile.write( " }\n")
|
||||
|
||||
@ -263,12 +346,12 @@ def tool_generate_main_java_class(target, module, package_name):
|
||||
|
||||
if module.get_pkg("ANDROID_APPL_TYPE")!="APPL":
|
||||
tmpFile.write( " public void onCreate() {\n")
|
||||
tmpFile.write( " super.onCreate();\n")
|
||||
tmpFile.write( " initApkPath(\"" + module.get_pkg("COMPAGNY_TYPE")+"\", \""+module.get_pkg("COMPAGNY_NAME2")+"\", \"" + application_name + "\", \"" + package_name + "\");\n")
|
||||
tmpFile.write( " super.onCreate();\n")
|
||||
else:
|
||||
tmpFile.write( " public void onCreate(android.os.Bundle savedInstanceState) {\n")
|
||||
tmpFile.write( " super.onCreate(savedInstanceState);\n")
|
||||
tmpFile.write( " initApkPath(\"" + module.get_pkg("COMPAGNY_TYPE")+"\", \""+module.get_pkg("COMPAGNY_NAME2")+"\", \"" + application_name + "\", \"" + package_name + "\");\n")
|
||||
tmpFile.write( " super.onCreate(savedInstanceState);\n")
|
||||
|
||||
if module.get_pkg("GENERATE_SECTION__ON_CREATE") != None:
|
||||
for elem in module.get_pkg("GENERATE_SECTION__ON_CREATE"):
|
||||
@ -368,7 +451,7 @@ def tool_generate_main_java_class(target, module, package_name):
|
||||
module.set_pkg("VERSION_CODE", "0")
|
||||
tmpFile.write( ' android:versionCode="' + str(module.get_pkg("VERSION_CODE")) + '" \n')
|
||||
tmpFile.write( ' android:versionName="'+tools.version_to_string(module.get_pkg("VERSION"))+'"> \n')
|
||||
tmpFile.write( ' <uses-feature android:glEsVersion="0x00020000" android:required="true" />\n')
|
||||
tmpFile.write( ' <uses-feature android:glEsVersion="0x00030000" android:required="true" />\n')
|
||||
tmpFile.write( ' <uses-sdk android:minSdkVersion="' + str(target.board_id) + '" \n')
|
||||
tmpFile.write( ' android:targetSdkVersion="' + str(target.board_id) + '" /> \n')
|
||||
if module.get_pkg("ANDROID_APPL_TYPE")=="APPL":
|
||||
|
207
sample/basic.cpp
207
sample/basic.cpp
@ -16,91 +16,130 @@
|
||||
#include <gale/resource/Program.hpp>
|
||||
|
||||
|
||||
class MainApplication : public gale::Application {
|
||||
private:
|
||||
ememory::SharedPtr<gale::resource::Program> m_GLprogram;
|
||||
int32_t m_GLPosition;
|
||||
int32_t m_GLMatrix;
|
||||
int32_t m_GLColor;
|
||||
public:
|
||||
void onCreate(gale::Context& _context) override {
|
||||
setSize(vec2(800, 600));
|
||||
m_GLprogram = gale::resource::Program::create("DATA:basic.prog");
|
||||
if (m_GLprogram != nullptr) {
|
||||
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
|
||||
m_GLColor = m_GLprogram->getAttribute("EW_color");
|
||||
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
|
||||
#define GALE_SAMPLE_VBO_VERTICES (0)
|
||||
#define GALE_SAMPLE_VBO_COLOR (1)
|
||||
namespace appl {
|
||||
class MainApplication : public gale::Application {
|
||||
private:
|
||||
ememory::SharedPtr<gale::resource::Program> m_GLprogram;
|
||||
int32_t m_GLPosition;
|
||||
int32_t m_GLMatrix;
|
||||
int32_t m_GLColor;
|
||||
float m_angle;
|
||||
ememory::SharedPtr<gale::resource::VirtualBufferObject> m_verticesVBO;
|
||||
public:
|
||||
void onCreate(gale::Context& _context) override {
|
||||
setSize(vec2(800, 600));
|
||||
m_angle = 0.0f;
|
||||
m_GLprogram = gale::resource::Program::create("DATA:///basic.prog");
|
||||
if (m_GLprogram != null) {
|
||||
m_GLPosition = m_GLprogram->getAttribute("EW_coord3d");
|
||||
m_GLColor = m_GLprogram->getAttribute("EW_color");
|
||||
m_GLMatrix = m_GLprogram->getUniform("EW_MatrixTransformation");
|
||||
}
|
||||
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer
|
||||
m_verticesVBO = gale::resource::VirtualBufferObject::create(5);
|
||||
if (m_verticesVBO == null) {
|
||||
TEST_ERROR("can not instanciate VBO ...");
|
||||
return;
|
||||
}
|
||||
// TO facilitate some debugs we add a name of the VBO:
|
||||
m_verticesVBO->setName("[VBO] of basic SAMPLE");
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_VERTICES, vec3(-0.5,-0.5,0));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_VERTICES, vec3(0,0.5,0));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_VERTICES, vec3(0.5,-0.5,0));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_COLOR, etk::Color<float>(etk::color::red));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_COLOR, etk::Color<float>(etk::color::green));
|
||||
m_verticesVBO->pushOnBuffer(GALE_SAMPLE_VBO_COLOR, etk::Color<float>(etk::color::blue));
|
||||
// update all the VBO elements ...
|
||||
m_verticesVBO->flush();
|
||||
TEST_INFO("==> Init APPL (END)");
|
||||
}
|
||||
TEST_INFO("==> Init APPL (END)");
|
||||
}
|
||||
void onDraw(gale::Context& _context) override {
|
||||
ivec2 size = getSize();
|
||||
// set the basic openGL view port: (position drawed in the windows)
|
||||
gale::openGL::setViewPort(ivec2(0,0),size);
|
||||
// Clear all the stacked matrix ...
|
||||
gale::openGL::setBasicMatrix(mat4());
|
||||
// clear background
|
||||
gale::openGL::clearColor(etk::color::yellow);
|
||||
// real clear request:
|
||||
gale::openGL::clear(gale::openGL::clearFlag_colorBuffer);
|
||||
// create a local matrix environnement.
|
||||
gale::openGL::push();
|
||||
|
||||
mat4 tmpProjection = etk::matOrtho(-1, 1,
|
||||
-1, 1,
|
||||
-2, 2);
|
||||
// set internal matrix system:
|
||||
gale::openGL::setMatrix(tmpProjection);
|
||||
|
||||
vec3 vertices[3]={ vec3(-0.5,-0.5,0),
|
||||
vec3(0,0.5,0),
|
||||
vec3(0.5,-0.5,0)
|
||||
};
|
||||
etk::Color<float> color[3] = { etk::color::red,
|
||||
etk::color::green,
|
||||
etk::color::blue
|
||||
};
|
||||
if (m_GLprogram == nullptr) {
|
||||
TEST_INFO("No shader ...");
|
||||
return;
|
||||
void onDraw(gale::Context& _context) override {
|
||||
m_angle += 0.01;
|
||||
TEST_INFO("==> appl Draw ...");
|
||||
ivec2 size = getSize();
|
||||
// set the basic openGL view port: (position drawed in the windows)
|
||||
gale::openGL::setViewPort(ivec2(0,0),size);
|
||||
// Clear all the stacked matrix ...
|
||||
gale::openGL::setBasicMatrix(mat4());
|
||||
// clear background
|
||||
etk::Color<float,4> bgColor = etk::color::yellow;
|
||||
bgColor.setA(0.75);
|
||||
gale::openGL::clearColor(bgColor);
|
||||
// real clear request:
|
||||
gale::openGL::clear(gale::openGL::clearFlag_colorBuffer);
|
||||
// create a local matrix environnement.
|
||||
gale::openGL::push();
|
||||
|
||||
mat4 tmpProjection = etk::matOrtho(-1, 1,
|
||||
-1, 1,
|
||||
-2, 2);
|
||||
// set internal matrix system:
|
||||
gale::openGL::setMatrix(tmpProjection);
|
||||
#if 0
|
||||
vec3 vertices[3]={ vec3(-0.5,-0.5,0),
|
||||
vec3(0,0.5,0),
|
||||
vec3(0.5,-0.5,0)
|
||||
};
|
||||
etk::Color<float> color[3] = { etk::color::red,
|
||||
etk::color::green,
|
||||
etk::color::blue
|
||||
};
|
||||
#endif
|
||||
if (m_GLprogram == null) {
|
||||
TEST_INFO("No shader ...");
|
||||
return;
|
||||
}
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = gale::openGL::getMatrix() * etk::matRotate(vec3(0,0,1),m_angle);
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix;
|
||||
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
#if 1
|
||||
// position:
|
||||
m_GLprogram->sendAttributePointer(m_GLPosition, m_verticesVBO, GALE_SAMPLE_VBO_VERTICES);
|
||||
// color:
|
||||
m_GLprogram->sendAttributePointer(m_GLColor, m_verticesVBO, GALE_SAMPLE_VBO_COLOR);
|
||||
#else
|
||||
// position:
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z,unused*/, vertices, 4*sizeof(float));
|
||||
// color:
|
||||
m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, color, 4*sizeof(float));
|
||||
#endif
|
||||
|
||||
// Request the draw od the elements:
|
||||
gale::openGL::drawArrays(gale::openGL::renderMode::triangle, 0, 3 /*number of points*/);
|
||||
m_GLprogram->unUse();
|
||||
// Restore context of matrix
|
||||
gale::openGL::pop();
|
||||
}
|
||||
//EWOL_DEBUG(" display " << m_coord.size() << " elements" );
|
||||
m_GLprogram->use();
|
||||
// set Matrix : translation/positionMatrix
|
||||
mat4 projMatrix = gale::openGL::getMatrix();
|
||||
mat4 camMatrix = gale::openGL::getCameraMatrix();
|
||||
mat4 tmpMatrix = projMatrix * camMatrix;
|
||||
m_GLprogram->uniformMatrix(m_GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
m_GLprogram->sendAttribute(m_GLPosition, 3/*x,y,z,unused*/, vertices, 4*sizeof(float));
|
||||
// color :
|
||||
m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, color, 4*sizeof(float));
|
||||
// Request the draw od the elements :
|
||||
gale::openGL::drawArrays(gale::openGL::renderMode::triangle, 0, 3 /*number of points*/);
|
||||
m_GLprogram->unUse();
|
||||
// Restore context of matrix
|
||||
gale::openGL::pop();
|
||||
}
|
||||
void onPointer(enum gale::key::type _type,
|
||||
int32_t _pointerID,
|
||||
const vec2& _pos,
|
||||
gale::key::status _state) override {
|
||||
TEST_INFO("input event: type=" << _type);
|
||||
TEST_INFO(" id=" << _pointerID);
|
||||
TEST_INFO(" pos=" << _pos);
|
||||
TEST_INFO(" state=" << _state);
|
||||
}
|
||||
void onKeyboard(const gale::key::Special& _special,
|
||||
enum gale::key::keyboard _type,
|
||||
char32_t _value,
|
||||
gale::key::status _state) override {
|
||||
TEST_INFO("Keyboard event: special=" << _special);
|
||||
TEST_INFO(" type=" << _type);
|
||||
TEST_INFO(" value=" << uint32_t(_value));
|
||||
TEST_INFO(" state=" << _state);
|
||||
}
|
||||
};
|
||||
|
||||
void onPointer(enum gale::key::type _type,
|
||||
int32_t _pointerID,
|
||||
const vec2& _pos,
|
||||
gale::key::status _state) override {
|
||||
/*
|
||||
TEST_INFO("input event: type=" << _type);
|
||||
TEST_INFO(" id=" << _pointerID);
|
||||
TEST_INFO(" pos=" << _pos);
|
||||
TEST_INFO(" state=" << _state);
|
||||
*/
|
||||
}
|
||||
void onKeyboard(const gale::key::Special& _special,
|
||||
enum gale::key::keyboard _type,
|
||||
char32_t _value,
|
||||
gale::key::status _state) override {
|
||||
TEST_INFO("Keyboard event: special=" << _special);
|
||||
TEST_INFO(" type=" << _type);
|
||||
TEST_INFO(" value=" << uint32_t(_value));
|
||||
TEST_INFO(" state=" << _state);
|
||||
}
|
||||
};
|
||||
}
|
||||
//! [gale_declare_main]
|
||||
/**
|
||||
* @brief Main of the program (This can be set in every case, but it is not used in Andoid...).
|
||||
@ -108,7 +147,7 @@ class MainApplication : public gale::Application {
|
||||
* @return std IO
|
||||
*/
|
||||
int main(int _argc, const char *_argv[]) {
|
||||
return gale::run(new MainApplication(), _argc, _argv);
|
||||
return gale::run(ETK_NEW(appl::MainApplication), _argc, _argv);
|
||||
}
|
||||
//! [gale_declare_main]
|
||||
|
||||
|
@ -3,7 +3,7 @@ precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// output :
|
||||
// output:
|
||||
varying vec4 f_color;
|
||||
|
||||
void main(void) {
|
||||
|
@ -3,12 +3,12 @@ precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// Input :
|
||||
// Input:
|
||||
attribute vec3 EW_coord3d;
|
||||
attribute vec4 EW_color;
|
||||
uniform mat4 EW_MatrixTransformation;
|
||||
|
||||
// output :
|
||||
// output:
|
||||
varying vec4 f_color;
|
||||
|
||||
void main(void) {
|
||||
|
@ -1 +1 @@
|
||||
0.7.0
|
||||
1.0.0
|
Loading…
x
Reference in New Issue
Block a user