Compare commits

...

55 Commits

Author SHA1 Message Date
Martin Felis
e8ef7924d2 Fixed Blend2Node::UpdateFlags(). 2023-04-03 19:31:09 +02:00
Martin Felis
0a45497de9 Added LockTranslationNode. 2023-04-02 21:40:49 +02:00
Martin Felis
7c8b44247b Fixed SpeedScale node not properly propagating time. 2023-04-02 21:24:12 +02:00
Martin Felis
abf44a875a Added support for const node inputs. 2023-04-02 16:26:24 +02:00
Martin Felis
42303d5f47 Store the input values of nodes if they are non-zero. 2023-04-01 22:53:53 +02:00
Martin Felis
3d55b748e6 Refactored anim graph data usage and evaluation.
- Refactored NodeSocketAccessor to NodeDescriptor.
- Connections are wired up during AnimGraph instantiation.
  - Output and input sockets point to the same memory location.
  - No re-wiring needed during evaluation.
  - AnimGraph are pre-allocated (refactoring for less memory usage postponed).
- Evaluation of AnimGraph now possible from the editor.
2023-04-01 14:16:20 +02:00
Martin Felis
91607baa9d Initial step for connectivity refactor.
Instead of wiring up pointers with prepareNodeEval() and finishNodeEval() use for each connection a single memory block where outputs and inputs point to.
2023-03-30 23:50:07 +02:00
Martin Felis
411aa5ef20 Better split between runtime library and editor. 2023-03-30 18:11:54 +02:00
Martin Felis
9168dec9f9 Added NodeDescriptor::UpdateFlags() to set Blend2 weight input flags. 2023-03-30 16:53:09 +02:00
Martin Felis
9dd10e8f27 Initial version of NodeDescriptor which aims to replace NodeSocketAccessor. 2023-03-29 22:25:09 +02:00
Martin Felis
08283d9bcf Evaluation of very simple graphs works. 2023-03-28 22:00:58 +02:00
Martin Felis
e38c0b4934 Started working on graph initialization in ATP Editor. 2023-03-26 23:39:11 +02:00
Martin Felis
a1931185d8 Simple AnimationPlayer now working. 2023-03-26 18:53:32 +02:00
Martin Felis
80ea25483b Started working on the animation player widget. 2023-03-26 15:01:44 +02:00
Martin Felis
7152fa74e1 Added SkinnedMeshResource 2023-03-26 13:28:12 +02:00
Martin Felis
15871f349c Updated ozz-animation to version 0.14.1 @35b2efd4 2023-03-26 13:28:12 +02:00
Martin Felis
bf3189ff49 Some more improvements of editor persistence. 2023-03-26 13:28:12 +02:00
Martin Felis
3d387a5dad Better serialization of application state. 2023-03-25 23:50:03 +01:00
Martin Felis
8a91c7700a Minor UI improvements. 2023-03-16 23:51:49 +01:00
Martin Felis
aa9ab1def1 Added missing test data 2022-10-18 22:34:01 +02:00
Martin Felis
2a8a5a5e40 Use std::list for animation data eval buffer.. 2022-04-18 23:14:34 +02:00
Martin Felis
68331467f0 Refactored graph evaluations. 2022-04-18 20:02:16 +02:00
Martin Felis
5e7a48b2eb WIP: graph evaluations. Fixed various memory issues, better tests. 2022-04-14 18:03:36 +02:00
Martin Felis
2da07ef961 Working on graph evaluations. WIP. 2022-04-13 15:48:39 +02:00
Martin Felis
b518220576 Added test which creates skeleton and animation during runtime. 2022-04-13 11:14:29 +02:00
Martin Felis
eeef635c64 Initial works for actial animation sampling and graph evaluation. 2022-04-11 16:46:09 +02:00
Martin Felis
bf0c7a7daa Added Tests for MathAdd Node 2022-04-11 11:40:53 +02:00
Martin Felis
e7314e3477 imnodes: pin coloring and connectivity logic 2022-04-08 12:48:04 +02:00
Martin Felis
5d8c1e289b Initial graph evaluations, added Float to Vec3 Node, minor editor tweaks. 2022-04-03 21:05:11 +02:00
Martin Felis
08ae84fcb4 New evaluation scheme.
- Animation Data are always referenced via a pointer in nodes.
- Animation Data storage pointers are injected from graph when node is evaluated.
- Node value outputs always stored in node.
- Node value inputs always referenced via pointer. References are created when instantiating the graph.
2022-04-01 13:19:54 +02:00
Martin Felis
abddbea62b Refactoring. 2022-03-25 12:05:56 +01:00
Martin Felis
6c0c0599f8 Removed old animation graph code. 2022-03-25 11:51:37 +01:00
Martin Felis
72a67195e6 Use socket pointers instead of indices for connections. 2022-03-25 11:23:03 +01:00
Martin Felis
84a9ef6f14 Use node pointer to check whether we use graph input/output nodes instead of indices. 2022-03-25 11:03:53 +01:00
Martin Felis
2f646bc5ec Simpler conversion SocketType <-> Strings. 2022-03-25 10:59:12 +01:00
Martin Felis
73e7a60875 Minor cleanup. 2022-02-24 23:47:31 +01:00
Martin Felis
976875c218 Added index member to node, preparing synctrack and node evaluation. 2022-02-24 22:55:40 +01:00
Martin Felis
d6453911e2 Removed node input splitting. 2022-02-24 22:06:47 +01:00
Martin Felis
306a2cb4d8 Minor fix to node input splitting. Not sure it is a good idea anymore, though... 2022-02-22 22:49:12 +01:00
Martin Felis
ef74f39cf4 Splitted animation and data node inputs. 2022-02-22 22:34:13 +01:00
Martin Felis
af5d27db85 Simple time propagation works. 2022-02-22 22:03:26 +01:00
Martin Felis
87eb2ab7df Mark all nodes that connect to the graph output nodes by default as active. 2022-02-20 16:00:45 +01:00
Martin Felis
b01acc2a88 Added marking of nodes active/inactive. 2022-02-20 15:57:19 +01:00
Martin Felis
618f6b613e Minor test cleanup. 2022-02-19 12:18:54 +01:00
Martin Felis
da916a7346 Added node ordering code and tests. 2022-02-19 12:16:57 +01:00
Martin Felis
bd304bde4e Give access to node inputs in runtime graph, initial works for marking of active nodes. 2022-02-19 00:25:51 +01:00
Martin Felis
9069a8192b Added serialization and deserialization of properties. 2022-02-18 23:33:30 +01:00
Martin Felis
ee6a8eb29a Basic node properties editor. 2022-02-18 22:24:19 +01:00
Martin Felis
0d0b181ebb Unified handling of nodes in editor. 2022-02-15 21:06:12 +01:00
Martin Felis
9b743fd081 Links can be removed in graph editor. 2022-02-15 20:57:59 +01:00
Martin Felis
3e02f28b18 Graph Input/Output wiring added. 2022-02-14 22:37:19 +01:00
Martin Felis
bbab4d8608 Graph editor allows instantiation of different node types. 2022-02-12 12:06:25 +01:00
Martin Felis
2b7cbe9d4c Simple graph output connection working. 2022-02-12 11:46:50 +01:00
Martin Felis
c2ae0a11d2 WIP AnimGraph instantiation. 2022-02-12 10:14:26 +01:00
Martin Felis
c5b0d1f976 Initial graph editor and graph instantiation from file. 2022-02-11 16:51:18 +01:00
279 changed files with 94019 additions and 3316 deletions

39
3rdparty/imnodes/.clang-format vendored Normal file
View File

@ -0,0 +1,39 @@
---
AccessModifierOffset: -4
AlignAfterOpenBracket: 'AlwaysBreak'
AlignConsecutiveDeclarations: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortFunctionsOnASingleLine: 'true'
AlwaysBreakBeforeMultilineStrings: 'true'
AlwaysBreakTemplateDeclarations: 'true'
BinPackArguments: 'false'
BinPackParameters: 'false'
BraceWrapping: {
AfterCaseLabel: 'true'
AfterClass: 'true'
AfterControlStatement: 'true'
AfterEnum: 'true'
AfterFunction: 'true'
AfterNamespace: 'true'
AfterStruct: 'true'
AfterUnion: 'true'
BeforeCatch: 'true'
BeforeElse: 'true'
IndentBraces: 'false'
}
BreakBeforeBraces: Custom
ColumnLimit: 100
Cpp11BracedListStyle: 'true'
DerivePointerAlignment: 'false'
IndentCaseLabels: 'false'
IndentWidth: 4
PenaltyExcessCharacter: 100000000
PenaltyReturnTypeOnItsOwnLine: 100000000
PointerAlignment: Left
PointerBindsToType: 'true'
SortIncludes: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeParens: ControlStatements
TabWidth: 8
UseTab: Never
...

33
3rdparty/imnodes/.clang-tidy vendored Normal file
View File

@ -0,0 +1,33 @@
# Apply this style by doing
#
# clang-tidy -fix-errors -config= <source-files>
#
# Running the command without -fix-errors will generate warnings about each
# style violation but won't change them.
Checks: '-*,readability-identifier-naming'
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: CamelCase
- key: readability-identifier-naming.MemberCase
value: CamelCase
- key: readability-identifier-naming.MethodCase
value: CamelCase
- key: readability-identifier-naming.NamespaceCase
value: CamelCase
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.PrivateMemberCase
value: CamelCase
- key: readability-identifier-naming.PrivateMemberPrefix
value: '_'
- key: readability-identifier-naming.StaticConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.StructCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: lower_case

View File

@ -0,0 +1,19 @@
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
container:
image: docker://nelarius/imnodes-docker-builder:latest
steps:
# This step uses checkout action: https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@v2
id: checkout
- name: premake5
run: premake5 gmake --sdl-include-path=/usr/include/SDL2
- name: make-debug
run: make all config=debug -j
- name: make-release
run: make all config=release -j

502
3rdparty/imnodes/.gitignore vendored Normal file
View File

@ -0,0 +1,502 @@
### Project ###
TODO.md
### ImGui ###
**.ini
### Local build ###
bin/
build/
lib/
imnodes.sln
# Created by https://www.toptal.com/developers/gitignore/api/sublimetext
# Edit at https://www.toptal.com/developers/gitignore?templates=sublimetext
### SublimeText ###
# Cache files for Sublime Text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
# Workspace files are user-specific
*.sublime-workspace
# Project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using Sublime Text
*.sublime-project
# SFTP configuration file
sftp-config.json
sftp-config-alt*.json
# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
Package Control.merged-ca-bundle
Package Control.user-ca-bundle
oscrypto-ca-bundle.crt
bh_unicode_properties.cache
# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings
# End of https://www.toptal.com/developers/gitignore/api/sublimetext
# Created by https://www.gitignore.io/api/c,c++
### C ###
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
### C++ ###
# Prerequisites
# Compiled Object files
*.slo
# Precompiled Headers
# Compiled Dynamic libraries
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
# Executables
# End of https://www.gitignore.io/api/c,c++
# Created by https://www.gitignore.io/api/visualstudiocode
### VisualStudioCode ###
.vscode/*
# End of https://www.gitignore.io/api/visualstudiocode
# Created by https://www.gitignore.io/api/premake-gmake
### premake-gmake ###
Makefile
*.make
obj/
# End of https://www.gitignore.io/api/premake-gmake
# Created by https://www.gitignore.io/api/visualstudio
# Edit at https://www.gitignore.io/?templates=visualstudio
### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# End of https://www.gitignore.io/api/visualstudio

21
3rdparty/imnodes/LICENSE.md vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Johann Muszynski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

270
3rdparty/imnodes/README.md vendored Normal file
View File

@ -0,0 +1,270 @@
<h1 align="center">imnodes</h1>
<p align="center">A small, dependency-free node editor extension for <a href="https://github.com/ocornut/imgui">dear imgui</a>.</p>
<p align="center">
<img src="https://raw.githubusercontent.com/Nelarius/imnodes/master/img/imnodes.gif?token=ADH_jEpqbBrw0nH-BUmOip490dyO2CnRks5cVZllwA%3D%3D">
</p>
[![Build Status](https://github.com/nelarius/imnodes/workflows/Build/badge.svg)](https://github.com/nelarius/imnodes/actions?workflow=Build)
Features:
* Create nodes, links, and pins in an immediate-mode style
* Single header and source file, just copy-paste `imnodes.h`, `imnodes_internal.h`, and `imnodes.cpp` into your project. The only dependency is `dear imgui` itself!
* Written in the same style of C++ as `dear imgui` itself -- no modern C++ used
* Use regular `dear imgui` widgets inside the nodes
* Multiple node and link selection with a box selector
* Nodes, links, and pins are fully customizable, from color style to layout
* Default themes match `dear imgui`'s default themes
Scroll down for a brief tour, known issues, and further information!
## Build the examples
This repository includes a few example files, under `example/`. You can copy-paste them into your own imgui project, or you can build them here, in this repository. To build here:
* SDL2 needs to be installed
* premake5 is used to generate the build files
```bash
# Assuming you've installed SDL2 via vcpkg, for instance
$ premake5 gmake \
--sdl-include-path=/Users/nelarius/vcpkg/installed/x64-osx/include/SDL2 \
--sdl-link-path=/Users/nelarius/vcpkg/installed/x64-osx/lib
# Or alternatively, if you are on MacOS and have the SDL2 framework installed
$ premake5 gmake --use-sdl-framework
$ make all -j
```
## A brief tour
Here is a small overview of how the extension is used. For more information on example usage, scroll to the bottom of the README.
Before anything can be done, the library must be initialized. This can be done at the same time as `dear imgui` initialization.
```cpp
ImGui::CreateContext();
ImNodes::CreateContext();
// elsewhere in the code...
ImNodes::DestroyContext();
ImGui::DestroyContext();
```
The node editor is a workspace which contains nodes. The node editor must be instantiated within a window, like any other UI element.
```cpp
ImGui::Begin("node editor");
ImNodes::BeginNodeEditor();
ImNodes::EndNodeEditor();
ImGui::End();
```
Now you should have a workspace with a grid visible in the window. An empty node can now be instantiated:
```cpp
const int hardcoded_node_id = 1;
ImNodes::BeginNodeEditor();
ImNodes::BeginNode(hardcoded_node_id);
ImGui::Dummy(ImVec2(80.0f, 45.0f));
ImNodes::EndNode();
ImNodes::EndNodeEditor();
```
Nodes, like windows in `dear imgui` must be uniquely identified. But we can't use the node titles for identification, because it should be possible to have many nodes of the same name in the workspace. Instead, you just use integers for identification.
Attributes are the UI content of the node. An attribute will have a pin (the little circle) on either side of the node. There are two types of attributes: input, and output attributes. Input attribute pins are on the left side of the node, and output attribute pins are on the right. Like nodes, pins must be uniquely identified.
```cpp
ImNodes::BeginNode(hardcoded_node_id);
const int output_attr_id = 2;
ImNodes::BeginOutputAttribute(output_attr_id);
// in between Begin|EndAttribute calls, you can call ImGui
// UI functions
ImGui::Text("output pin");
ImNodes::EndOutputAttribute();
ImNodes::EndNode();
```
The extension doesn't really care what is in the attribute. It just renders the pin for the attribute, and allows the user to create links between pins.
A title bar can be added to the node using `BeginNodeTitleBar` and `EndNodeTitleBar`. Like attributes, you place your title bar's content between the function calls. Note that these functions have to be called before adding attributes or other `dear imgui` UI elements to the node, since the node's layout is built in order, top-to-bottom.
```cpp
ImNodes::BeginNode(hardcoded_node_id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("output node");
ImNodes::EndNodeTitleBar();
// pins and other node UI content omitted...
ImNodes::EndNode();
```
The user has to render their own links between nodes as well. A link is a curve which connects two attributes. A link is just a pair of attribute ids. And like nodes and attributes, links too have to be identified by unique integer values:
```cpp
std::vector<std::pair<int, int>> links;
// elsewhere in the code...
for (int i = 0; i < links.size(); ++i)
{
const std::pair<int, int> p = links[i];
// in this case, we just use the array index of the link
// as the unique identifier
ImNodes::Link(i, p.first, p.second);
}
```
After `EndNodeEditor` has been called, you can check if a link was created during the frame with the function call `IsLinkCreated`:
```cpp
int start_attr, end_attr;
if (ImNodes::IsLinkCreated(&start_attr, &end_attr))
{
links.push_back(std::make_pair(start_attr, end_attr));
}
```
In addition to checking for new links, you can also check whether UI elements are being hovered over by the mouse cursor:
```cpp
int node_id;
if (ImNodes::IsNodeHovered(&node_id))
{
node_hovered = node_id;
}
```
You can also check to see if any node has been selected. Nodes can be clicked on, or they can be selected by clicking and dragging the box selector over them.
```cpp
// Note that since many nodes can be selected at once, we first need to query the number of
// selected nodes before getting them.
const int num_selected_nodes = ImNodes::NumSelectedNodes();
if (num_selected_nodes > 0)
{
std::vector<int> selected_nodes;
selected_nodes.resize(num_selected_nodes);
ImNodes::GetSelectedNodes(selected_nodes.data());
}
```
See `imnodes.h` for more UI event-related functions.
Like `dear imgui`, the style of the UI can be changed. You can set the color style of individual nodes, pins, and links mid-frame by calling `ImNodes::PushColorStyle` and `ImNodes::PopColorStyle`.
```cpp
// set the titlebar color of an individual node
ImNodes::PushColorStyle(
ImNodesCol_TitleBar, IM_COL32(11, 109, 191, 255));
ImNodes::PushColorStyle(
ImNodesCol_TitleBarSelected, IM_COL32(81, 148, 204, 255));
ImNodes::BeginNode(hardcoded_node_id);
// node internals here...
ImNodes::EndNode();
ImNodes::PopColorStyle();
ImNodes::PopColorStyle();
```
If the style is not being set mid-frame, `ImNodes::GetStyle` can be called instead, and the values can be set into the style array directly.
```cpp
// set the titlebar color for all nodes
ImNodesStyle& style = ImNodes::GetStyle();
style.colors[ImNodesCol_TitleBar] = IM_COL32(232, 27, 86, 255);
style.colors[ImNodesCol_TitleBarSelected] = IM_COL32(241, 108, 146, 255);
```
To handle quicker navigation of large graphs you can use an interactive mini-map overlay. The mini-map can be zoomed and scrolled. Editor nodes will track the panning of the mini-map accordingly.
```cpp
ImGui::Begin("node editor");
ImNodes::BeginNodeEditor();
// add nodes...
// must be called right before EndNodeEditor
ImNodes::MiniMap();
ImNodes::EndNodeEditor();
ImGui::End();
```
The relative sizing and corner location of the mini-map in the editor space can be specified like so:
```cpp
// MiniMap is a square region with a side length that is 20% the largest editor canvas dimension
// See ImNodesMiniMapLocation_ for other corner locations
ImNodes::MiniMap(0.2f, ImNodesMiniMapLocation_TopRight);
```
The mini-map also supports limited node hovering customization through a user-defined callback.
```cpp
// User callback
void mini_map_node_hovering_callback(int node_id, void* user_data)
{
ImGui::SetTooltip("This is node %d", node_id);
}
// Later on...
ImNodes::MiniMap(0.2f, ImNodesMiniMapLocation_TopRight, mini_map_node_hovering_callback, custom_user_data);
// 'custom_user_data' can be used to supply extra information needed for drawing within the callback
```
## Customizing ImNodes
ImNodes can be customized by providing an `imnodes_config.h` header and specifying defining `IMNODES_USER_CONFIG=imnodes_config.h` when compiling.
It is currently possible to override the type of the minimap hovering callback function. This is useful when generating bindings for another language.
Here's an example imnodes_config.h, which generates a pybind wrapper for the callback.
```cpp
#pragma once
#include <pybind11/functional.h>
namespace pybind11 {
inline bool PyWrapper_Check(PyObject *o) { return true; }
class wrapper : public object {
public:
PYBIND11_OBJECT_DEFAULT(wrapper, object, PyWrapper_Check)
wrapper(void* x) { m_ptr = (PyObject*)x; }
explicit operator bool() const { return m_ptr != nullptr && m_ptr != Py_None; }
};
} //namespace pybind11
namespace py = pybind11;
#define ImNodesMiniMapNodeHoveringCallback py::wrapper
#define ImNodesMiniMapNodeHoveringCallbackUserData py::wrapper
```
## Known issues
* `ImGui::Separator()` spans the current window span. As a result, using a separator inside a node will result in the separator spilling out of the node into the node editor grid.
## Further information
See the `examples/` directory to see library usage in greater detail.
* simple.cpp is a simple hello-world style program which displays two nodes
* save_load.cpp is enables you to add and remove nodes and links, and serializes/deserializes them, so that the program state is retained between restarting the program
* color_node_editor.cpp is a more complete example, which shows how a simple node editor is implemented with a graph.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2021 Omar Cornut
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,123 @@
//-----------------------------------------------------------------------------
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
//-----------------------------------------------------------------------------
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------
#pragma once
//---- Define assertion handler. Defaults to calling assert().
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//---- Disable all of Dear ImGui or don't implement standard windows.
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger window: ShowMetricsWindow() will be empty.
//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
//---- Include imgui_user.h at the end of imgui.h as a convenience
//#define IMGUI_INCLUDE_IMGUI_USER_H
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
//#define IMGUI_USE_BGRA_PACKED_COLOR
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
//#define IMGUI_USE_WCHAR32
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
// #define IMGUI_USE_STB_SPRINTF
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
//#define IMGUI_ENABLE_FREETYPE
//---- Use stb_truetype to build and rasterize the font atlas (default)
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
//#define IMGUI_ENABLE_STB_TRUETYPE
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
//#define ImDrawIdx unsigned int
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
//struct ImDrawList;
//struct ImDrawCmd;
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
//#define ImDrawCallback MyImDrawCallback
//---- Debug Tools: Macro to break in Debugger
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
//#define IM_DEBUG_BREAK IM_ASSERT(0)
//#define IM_DEBUG_BREAK __debugbreak()
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
// This adds a small runtime cost which is why it is not enabled by default.
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
//---- Debug Tools: Enable slower asserts
//#define IMGUI_DEBUG_PARANOID
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
/*
namespace ImGui
{
void MyFunction(const char* name, const MyMatrix44& v);
}
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,778 @@
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
// - Desktop GL: 2.x 3.x 4.x
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices.
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
// 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader.
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
// 2021-06-25: OpenGL: Use OES_vertex_array extension on Emscripten + backup/restore current state.
// 2021-06-21: OpenGL: Destroy individual vertex/fragment shader objects right after they are linked into the main shader.
// 2021-05-24: OpenGL: Access GL_CLIP_ORIGIN when "GL_ARB_clip_control" extension is detected, inside of just OpenGL 4.5 version.
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
// 2021-04-06: OpenGL: Don't try to read GL_CLIP_ORIGIN unless we're OpenGL 4.5 or greater.
// 2021-02-18: OpenGL: Change blending equation to preserve alpha in output buffer.
// 2021-01-03: OpenGL: Backup, setup and restore GL_STENCIL_TEST state.
// 2020-10-23: OpenGL: Backup, setup and restore GL_PRIMITIVE_RESTART state.
// 2020-10-15: OpenGL: Use glGetString(GL_VERSION) instead of glGetIntegerv(GL_MAJOR_VERSION, ...) when the later returns zero (e.g. Desktop GL 2.x)
// 2020-09-17: OpenGL: Fix to avoid compiling/calling glBindSampler() on ES or pre 3.3 context which have the defines set by a loader.
// 2020-07-10: OpenGL: Added support for glad2 OpenGL loader.
// 2020-05-08: OpenGL: Made default GLSL version 150 (instead of 130) on OSX.
// 2020-04-21: OpenGL: Fixed handling of glClipControl(GL_UPPER_LEFT) by inverting projection matrix.
// 2020-04-12: OpenGL: Fixed context version check mistakenly testing for 4.0+ instead of 3.2+ to enable ImGuiBackendFlags_RendererHasVtxOffset.
// 2020-03-24: OpenGL: Added support for glbinding 2.x OpenGL loader.
// 2020-01-07: OpenGL: Added support for glbinding 3.x OpenGL loader.
// 2019-10-25: OpenGL: Using a combination of GL define and runtime GL version to decide whether to use glDrawElementsBaseVertex(). Fix building with pre-3.2 GL loaders.
// 2019-09-22: OpenGL: Detect default GL loader using __has_include compiler facility.
// 2019-09-16: OpenGL: Tweak initialization code to allow application calling ImGui_ImplOpenGL3_CreateFontsTexture() before the first NewFrame() call.
// 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
// 2019-03-29: OpenGL: Not calling glBindBuffer more than necessary in the render loop.
// 2019-03-15: OpenGL: Added a GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized GL function loaders early.
// 2019-03-03: OpenGL: Fix support for ES 2.0 (WebGL 1.0).
// 2019-02-20: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN even if defined by the headers/loader.
// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
// 2019-02-01: OpenGL: Using GLSL 410 shaders for any version over 410 (e.g. 430, 450).
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT) / GL_CLIP_ORIGIN.
// 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used.
// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES".
// 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation.
// 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link.
// 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples.
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state.
// 2018-05-14: OpenGL: Making the call to glBindSampler() optional so 3.2 context won't fail if the function is a NULL pointer.
// 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplOpenGL3_Init() so user can override the GLSL version e.g. "#version 150".
// 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context.
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplSdlGL3_RenderDrawData() in the .h file so you can call it yourself.
// 2018-01-07: OpenGL: Changed GLSL shader version from 330 to 150.
// 2017-09-01: OpenGL: Save and restore current bound sampler. Save and restore current polygon mode.
// 2017-05-01: OpenGL: Fixed save and restore of current blend func state.
// 2017-05-01: OpenGL: Fixed save and restore of current GL_ACTIVE_TEXTURE.
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
// 2016-07-29: OpenGL: Explicitly setting GL_UNPACK_ROW_LENGTH to reduce issues because SDL changes it. (#752)
//----------------------------------------
// OpenGL GLSL GLSL
// version version string
//----------------------------------------
// 2.0 110 "#version 110"
// 2.1 120 "#version 120"
// 3.0 130 "#version 130"
// 3.1 140 "#version 140"
// 3.2 150 "#version 150"
// 3.3 330 "#version 330 core"
// 4.0 400 "#version 400 core"
// 4.1 410 "#version 410 core"
// 4.2 420 "#version 410 core"
// 4.3 430 "#version 430 core"
// ES 2.0 100 "#version 100" = WebGL 1.0
// ES 3.0 300 "#version 300 es" = WebGL 2.0
//----------------------------------------
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "imgui.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
#include <stddef.h> // intptr_t
#else
#include <stdint.h> // intptr_t
#endif
// GL includes
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2.h>
#if defined(__EMSCRIPTEN__)
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#include <GLES2/gl2ext.h>
#endif
#elif defined(IMGUI_IMPL_OPENGL_ES3)
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
#else
#include <GLES3/gl3.h> // Use GL ES 3
#endif
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
// Helper libraries are often used for this purpose! Here we are using our own minimal custom loader based on gl3w.
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
#define IMGL3W_IMPL
#include "imgui_impl_opengl3_loader.h"
#endif
// Vertex arrays are not supported on ES2/WebGL1 unless Emscripten which uses an extension
#ifndef IMGUI_IMPL_OPENGL_ES2
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
#elif defined(__EMSCRIPTEN__)
#define IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
#define glBindVertexArray glBindVertexArrayOES
#define glGenVertexArrays glGenVertexArraysOES
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define GL_VERTEX_ARRAY_BINDING GL_VERTEX_ARRAY_BINDING_OES
#endif
// Desktop GL 2.0+ has glPolygonMode() which GL ES and WebGL don't have.
#ifdef GL_POLYGON_MODE
#define IMGUI_IMPL_HAS_POLYGON_MODE
#endif
// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_2)
#define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
#endif
// Desktop GL 3.3+ has glBindSampler()
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_3)
#define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
#endif
// Desktop GL 3.1+ has GL_PRIMITIVE_RESTART state
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_1)
#define IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
#endif
// Desktop GL use extension detection
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
#define IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
#endif
// OpenGL Data
struct ImGui_ImplOpenGL3_Data
{
GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2)
char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings.
GLuint FontTexture;
GLuint ShaderHandle;
GLint AttribLocationTex; // Uniforms location
GLint AttribLocationProjMtx;
GLuint AttribLocationVtxPos; // Vertex attributes location
GLuint AttribLocationVtxUV;
GLuint AttribLocationVtxColor;
unsigned int VboHandle, ElementsHandle;
bool HasClipOrigin;
ImGui_ImplOpenGL3_Data() { memset(this, 0, sizeof(*this)); }
};
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData()
{
return ImGui::GetCurrentContext() ? (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData : NULL;
}
// Functions
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
// Initialize our loader
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
if (imgl3wInit() != 0)
{
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
return false;
}
#endif
// Setup backend capabilities flags
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
io.BackendRendererUserData = (void*)bd;
io.BackendRendererName = "imgui_impl_opengl3";
// Query for GL version (e.g. 320 for GL 3.2)
#if !defined(IMGUI_IMPL_OPENGL_ES2)
GLint major = 0;
GLint minor = 0;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
if (major == 0 && minor == 0)
{
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
const char* gl_version = (const char*)glGetString(GL_VERSION);
sscanf(gl_version, "%d.%d", &major, &minor);
}
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
#else
bd->GlVersion = 200; // GLES 2
#endif
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
if (bd->GlVersion >= 320)
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
#endif
// Store GLSL version string so we can refer to it later in case we recreate shaders.
// Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure.
if (glsl_version == NULL)
{
#if defined(IMGUI_IMPL_OPENGL_ES2)
glsl_version = "#version 100";
#elif defined(IMGUI_IMPL_OPENGL_ES3)
glsl_version = "#version 300 es";
#elif defined(__APPLE__)
glsl_version = "#version 150";
#else
glsl_version = "#version 130";
#endif
}
IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(bd->GlslVersionString));
strcpy(bd->GlslVersionString, glsl_version);
strcat(bd->GlslVersionString, "\n");
// Make an arbitrary GL call (we don't actually need the result)
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
GLint current_texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
// Detect extensions we support
bd->HasClipOrigin = (bd->GlVersion >= 450);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_EXTENSIONS
GLint num_extensions = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
for (GLint i = 0; i < num_extensions; i++)
{
const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
if (extension != NULL && strcmp(extension, "GL_ARB_clip_control") == 0)
bd->HasClipOrigin = true;
}
#endif
return true;
}
void ImGui_ImplOpenGL3_Shutdown()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
ImGui_ImplOpenGL3_DestroyDeviceObjects();
io.BackendRendererName = NULL;
io.BackendRendererUserData = NULL;
IM_DELETE(bd);
}
void ImGui_ImplOpenGL3_NewFrame()
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
IM_ASSERT(bd != NULL && "Did you call ImGui_ImplOpenGL3_Init()?");
if (!bd->ShaderHandle)
ImGui_ImplOpenGL3_CreateDeviceObjects();
}
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glEnable(GL_SCISSOR_TEST);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
if (bd->GlVersion >= 310)
glDisable(GL_PRIMITIVE_RESTART);
#endif
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
#endif
// Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
#if defined(GL_CLIP_ORIGIN)
bool clip_origin_lower_left = true;
if (bd->HasClipOrigin)
{
GLenum current_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&current_clip_origin);
if (current_clip_origin == GL_UPPER_LEFT)
clip_origin_lower_left = false;
}
#endif
// Setup viewport, orthographic projection matrix
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
float L = draw_data->DisplayPos.x;
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
float T = draw_data->DisplayPos.y;
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
#if defined(GL_CLIP_ORIGIN)
if (!clip_origin_lower_left) { float tmp = T; T = B; B = tmp; } // Swap top and bottom if origin is upper left
#endif
const float ortho_projection[4][4] =
{
{ 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
{ 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
};
glUseProgram(bd->ShaderHandle);
glUniform1i(bd->AttribLocationTex, 0);
glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
if (bd->GlVersion >= 330)
glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
#endif
(void)vertex_array_object;
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glBindVertexArray(vertex_array_object);
#endif
// Bind vertex/index buffers and setup attributes for ImDrawVert
glBindBuffer(GL_ARRAY_BUFFER, bd->VboHandle);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bd->ElementsHandle);
glEnableVertexAttribArray(bd->AttribLocationVtxPos);
glEnableVertexAttribArray(bd->AttribLocationVtxUV);
glEnableVertexAttribArray(bd->AttribLocationVtxColor);
glVertexAttribPointer(bd->AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos));
glVertexAttribPointer(bd->AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv));
glVertexAttribPointer(bd->AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col));
}
// OpenGL3 Render function.
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly.
// This is in order to be able to run within an OpenGL engine that doesn't do so.
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
{
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
if (fb_width <= 0 || fb_height <= 0)
return;
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Backup GL state
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
glActiveTexture(GL_TEXTURE0);
GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program);
GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
GLuint last_sampler; if (bd->GlVersion >= 330) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; }
#endif
GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer);
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object);
#endif
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
#endif
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
GLenum last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb);
GLenum last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, (GLint*)&last_blend_dst_rgb);
GLenum last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, (GLint*)&last_blend_src_alpha);
GLenum last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, (GLint*)&last_blend_dst_alpha);
GLenum last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, (GLint*)&last_blend_equation_rgb);
GLenum last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, (GLint*)&last_blend_equation_alpha);
GLboolean last_enable_blend = glIsEnabled(GL_BLEND);
GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE);
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
GLboolean last_enable_stencil_test = glIsEnabled(GL_STENCIL_TEST);
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
GLboolean last_enable_primitive_restart = (bd->GlVersion >= 310) ? glIsEnabled(GL_PRIMITIVE_RESTART) : GL_FALSE;
#endif
// Setup desired GL state
// Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
// The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
GLuint vertex_array_object = 0;
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glGenVertexArrays(1, &vertex_array_object);
#endif
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
// Will project scissor/clipping rectangles into framebuffer space
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
// Render command lists
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
// Upload vertex/index buffers
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW);
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback != NULL)
{
// User callback, registered via ImDrawList::AddCallback()
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
else
pcmd->UserCallback(cmd_list, pcmd);
}
else
{
// Project scissor/clipping rectangles into framebuffer space
ImVec4 clip_rect;
clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
{
// Apply scissor/clipping rectangle
glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y));
// Bind texture, Draw
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID());
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
if (bd->GlVersion >= 320)
glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset);
else
#endif
glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)));
}
}
}
}
// Destroy the temporary VAO
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glDeleteVertexArrays(1, &vertex_array_object);
#endif
// Restore modified GL state
glUseProgram(last_program);
glBindTexture(GL_TEXTURE_2D, last_texture);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER
if (bd->GlVersion >= 330)
glBindSampler(0, last_sampler);
#endif
glActiveTexture(last_active_texture);
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glBindVertexArray(last_vertex_array_object);
#endif
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);
if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST);
if (last_enable_stencil_test) glEnable(GL_STENCIL_TEST); else glDisable(GL_STENCIL_TEST);
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
#ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_PRIMITIVE_RESTART
if (bd->GlVersion >= 310) { if (last_enable_primitive_restart) glEnable(GL_PRIMITIVE_RESTART); else glDisable(GL_PRIMITIVE_RESTART); }
#endif
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
#endif
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
(void)bd; // Not all compilation paths use this
}
bool ImGui_ImplOpenGL3_CreateFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Build texture atlas
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
// Upload texture to graphics system
GLint last_texture;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
glGenTextures(1, &bd->FontTexture);
glBindTexture(GL_TEXTURE_2D, bd->FontTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
#ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Store our identifier
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
// Restore state
glBindTexture(GL_TEXTURE_2D, last_texture);
return true;
}
void ImGui_ImplOpenGL3_DestroyFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
if (bd->FontTexture)
{
glDeleteTextures(1, &bd->FontTexture);
io.Fonts->SetTexID(0);
bd->FontTexture = 0;
}
}
// If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
static bool CheckShader(GLuint handle, const char* desc)
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
GLint status = 0, log_length = 0;
glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s! With GLSL: %s\n", desc, bd->GlslVersionString);
if (log_length > 1)
{
ImVector<char> buf;
buf.resize((int)(log_length + 1));
glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
fprintf(stderr, "%s\n", buf.begin());
}
return (GLboolean)status == GL_TRUE;
}
// If you get an error please report on GitHub. You may try different GL context version or GLSL version.
static bool CheckProgram(GLuint handle, const char* desc)
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
GLint status = 0, log_length = 0;
glGetProgramiv(handle, GL_LINK_STATUS, &status);
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! With GLSL %s\n", desc, bd->GlslVersionString);
if (log_length > 1)
{
ImVector<char> buf;
buf.resize((int)(log_length + 1));
glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
fprintf(stderr, "%s\n", buf.begin());
}
return (GLboolean)status == GL_TRUE;
}
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
// Backup GL state
GLint last_texture, last_array_buffer;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
GLint last_vertex_array;
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
#endif
// Parse GLSL version string
int glsl_version = 130;
sscanf(bd->GlslVersionString, "#version %d", &glsl_version);
const GLchar* vertex_shader_glsl_120 =
"uniform mat4 ProjMtx;\n"
"attribute vec2 Position;\n"
"attribute vec2 UV;\n"
"attribute vec4 Color;\n"
"varying vec2 Frag_UV;\n"
"varying vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* vertex_shader_glsl_130 =
"uniform mat4 ProjMtx;\n"
"in vec2 Position;\n"
"in vec2 UV;\n"
"in vec4 Color;\n"
"out vec2 Frag_UV;\n"
"out vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* vertex_shader_glsl_300_es =
"precision highp float;\n"
"layout (location = 0) in vec2 Position;\n"
"layout (location = 1) in vec2 UV;\n"
"layout (location = 2) in vec4 Color;\n"
"uniform mat4 ProjMtx;\n"
"out vec2 Frag_UV;\n"
"out vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* vertex_shader_glsl_410_core =
"layout (location = 0) in vec2 Position;\n"
"layout (location = 1) in vec2 UV;\n"
"layout (location = 2) in vec4 Color;\n"
"uniform mat4 ProjMtx;\n"
"out vec2 Frag_UV;\n"
"out vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" Frag_UV = UV;\n"
" Frag_Color = Color;\n"
" gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
"}\n";
const GLchar* fragment_shader_glsl_120 =
"#ifdef GL_ES\n"
" precision mediump float;\n"
"#endif\n"
"uniform sampler2D Texture;\n"
"varying vec2 Frag_UV;\n"
"varying vec4 Frag_Color;\n"
"void main()\n"
"{\n"
" gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
"}\n";
const GLchar* fragment_shader_glsl_130 =
"uniform sampler2D Texture;\n"
"in vec2 Frag_UV;\n"
"in vec4 Frag_Color;\n"
"out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";
const GLchar* fragment_shader_glsl_300_es =
"precision mediump float;\n"
"uniform sampler2D Texture;\n"
"in vec2 Frag_UV;\n"
"in vec4 Frag_Color;\n"
"layout (location = 0) out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";
const GLchar* fragment_shader_glsl_410_core =
"in vec2 Frag_UV;\n"
"in vec4 Frag_Color;\n"
"uniform sampler2D Texture;\n"
"layout (location = 0) out vec4 Out_Color;\n"
"void main()\n"
"{\n"
" Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
"}\n";
// Select shaders matching our GLSL versions
const GLchar* vertex_shader = NULL;
const GLchar* fragment_shader = NULL;
if (glsl_version < 130)
{
vertex_shader = vertex_shader_glsl_120;
fragment_shader = fragment_shader_glsl_120;
}
else if (glsl_version >= 410)
{
vertex_shader = vertex_shader_glsl_410_core;
fragment_shader = fragment_shader_glsl_410_core;
}
else if (glsl_version == 300)
{
vertex_shader = vertex_shader_glsl_300_es;
fragment_shader = fragment_shader_glsl_300_es;
}
else
{
vertex_shader = vertex_shader_glsl_130;
fragment_shader = fragment_shader_glsl_130;
}
// Create shaders
const GLchar* vertex_shader_with_version[2] = { bd->GlslVersionString, vertex_shader };
GLuint vert_handle = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vert_handle, 2, vertex_shader_with_version, NULL);
glCompileShader(vert_handle);
CheckShader(vert_handle, "vertex shader");
const GLchar* fragment_shader_with_version[2] = { bd->GlslVersionString, fragment_shader };
GLuint frag_handle = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(frag_handle, 2, fragment_shader_with_version, NULL);
glCompileShader(frag_handle);
CheckShader(frag_handle, "fragment shader");
// Link
bd->ShaderHandle = glCreateProgram();
glAttachShader(bd->ShaderHandle, vert_handle);
glAttachShader(bd->ShaderHandle, frag_handle);
glLinkProgram(bd->ShaderHandle);
CheckProgram(bd->ShaderHandle, "shader program");
glDetachShader(bd->ShaderHandle, vert_handle);
glDetachShader(bd->ShaderHandle, frag_handle);
glDeleteShader(vert_handle);
glDeleteShader(frag_handle);
bd->AttribLocationTex = glGetUniformLocation(bd->ShaderHandle, "Texture");
bd->AttribLocationProjMtx = glGetUniformLocation(bd->ShaderHandle, "ProjMtx");
bd->AttribLocationVtxPos = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Position");
bd->AttribLocationVtxUV = (GLuint)glGetAttribLocation(bd->ShaderHandle, "UV");
bd->AttribLocationVtxColor = (GLuint)glGetAttribLocation(bd->ShaderHandle, "Color");
// Create buffers
glGenBuffers(1, &bd->VboHandle);
glGenBuffers(1, &bd->ElementsHandle);
ImGui_ImplOpenGL3_CreateFontsTexture();
// Restore modified GL state
glBindTexture(GL_TEXTURE_2D, last_texture);
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
glBindVertexArray(last_vertex_array);
#endif
return true;
}
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
{
ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData();
if (bd->VboHandle) { glDeleteBuffers(1, &bd->VboHandle); bd->VboHandle = 0; }
if (bd->ElementsHandle) { glDeleteBuffers(1, &bd->ElementsHandle); bd->ElementsHandle = 0; }
if (bd->ShaderHandle) { glDeleteProgram(bd->ShaderHandle); bd->ShaderHandle = 0; }
ImGui_ImplOpenGL3_DestroyFontsTexture();
}

View File

@ -0,0 +1,55 @@
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
// - Desktop GL: 2.x 3.x 4.x
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices.
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// About GLSL version:
// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
#pragma once
#include "imgui.h" // IMGUI_IMPL_API
// Backend API
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
// (Optional) Called by Init/NewFrame/Shutdown
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
// Specific OpenGL ES versions
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
&& !defined(IMGUI_IMPL_OPENGL_ES3)
// Try to detect GLES on matching platforms
#if defined(__APPLE__)
#include "TargetConditionals.h"
#endif
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
#elif defined(__EMSCRIPTEN__)
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
#else
// Otherwise imgui_impl_opengl3_loader.h will be used.
#endif
#endif

View File

@ -0,0 +1,730 @@
/*
* This file was generated with gl3w_gen.py, part of imgl3w
* (hosted at https://github.com/dearimgui/gl3w_stripped)
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// We embed our own OpenGL loader to not require user to provide their own or to have to use ours, which proved to be endless problems for users.
// Our loader is custom-generated, based on gl3w but automatically filtered to only include enums/functions that we use in this source file.
// Regenerate with: python gl3w_gen.py --imgui-dir /path/to/imgui/
// see https://github.com/dearimgui/gl3w_stripped for more info.
#ifndef __gl3w_h_
#define __gl3w_h_
// Adapted from KHR/khrplatform.h to avoid including entire file.
typedef float khronos_float_t;
typedef signed char khronos_int8_t;
typedef unsigned char khronos_uint8_t;
typedef signed short int khronos_int16_t;
typedef unsigned short int khronos_uint16_t;
#ifdef _WIN64
typedef signed long long int khronos_intptr_t;
typedef signed long long int khronos_ssize_t;
#else
typedef signed long int khronos_intptr_t;
typedef signed long int khronos_ssize_t;
#endif
#if defined(_MSC_VER) && !defined(__clang__)
typedef signed __int64 khronos_int64_t;
typedef unsigned __int64 khronos_uint64_t;
#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
#include <stdint.h>
typedef int64_t khronos_int64_t;
typedef uint64_t khronos_uint64_t;
#else
typedef signed long long khronos_int64_t;
typedef unsigned long long khronos_uint64_t;
#endif
#ifndef __gl_glcorearb_h_
#define __gl_glcorearb_h_ 1
#ifdef __cplusplus
extern "C" {
#endif
/*
** Copyright 2013-2020 The Khronos Group Inc.
** SPDX-License-Identifier: MIT
**
** This header is generated from the Khronos OpenGL / OpenGL ES XML
** API Registry. The current version of the Registry, generator scripts
** used to make the header, and the header can be found at
** https://github.com/KhronosGroup/OpenGL-Registry
*/
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#endif
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef APIENTRYP
#define APIENTRYP APIENTRY *
#endif
#ifndef GLAPI
#define GLAPI extern
#endif
/* glcorearb.h is for use with OpenGL core profile implementations.
** It should should be placed in the same directory as gl.h and
** included as <GL/glcorearb.h>.
**
** glcorearb.h includes only APIs in the latest OpenGL core profile
** implementation together with APIs in newer ARB extensions which
** can be supported by the core profile. It does not, and never will
** include functionality removed from the core profile, such as
** fixed-function vertex and fragment processing.
**
** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
** <GL/glext.h> in the same source file.
*/
/* Generated C header for:
* API: gl
* Profile: core
* Versions considered: .*
* Versions emitted: .*
* Default extensions included: glcore
* Additional extensions included: _nomatch_^
* Extensions removed: _nomatch_^
*/
#ifndef GL_VERSION_1_0
typedef void GLvoid;
typedef unsigned int GLenum;
typedef khronos_float_t GLfloat;
typedef int GLint;
typedef int GLsizei;
typedef unsigned int GLbitfield;
typedef double GLdouble;
typedef unsigned int GLuint;
typedef unsigned char GLboolean;
typedef khronos_uint8_t GLubyte;
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_FALSE 0
#define GL_TRUE 1
#define GL_TRIANGLES 0x0004
#define GL_ONE 1
#define GL_SRC_ALPHA 0x0302
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
#define GL_FRONT_AND_BACK 0x0408
#define GL_POLYGON_MODE 0x0B40
#define GL_CULL_FACE 0x0B44
#define GL_DEPTH_TEST 0x0B71
#define GL_STENCIL_TEST 0x0B90
#define GL_VIEWPORT 0x0BA2
#define GL_BLEND 0x0BE2
#define GL_SCISSOR_BOX 0x0C10
#define GL_SCISSOR_TEST 0x0C11
#define GL_UNPACK_ROW_LENGTH 0x0CF2
#define GL_PACK_ALIGNMENT 0x0D05
#define GL_TEXTURE_2D 0x0DE1
#define GL_UNSIGNED_BYTE 0x1401
#define GL_UNSIGNED_SHORT 0x1403
#define GL_UNSIGNED_INT 0x1405
#define GL_FLOAT 0x1406
#define GL_RGBA 0x1908
#define GL_FILL 0x1B02
#define GL_VERSION 0x1F02
#define GL_EXTENSIONS 0x1F03
#define GL_LINEAR 0x2601
#define GL_TEXTURE_MAG_FILTER 0x2800
#define GL_TEXTURE_MIN_FILTER 0x2801
typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
GLAPI void APIENTRY glClear (GLbitfield mask);
GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
GLAPI void APIENTRY glDisable (GLenum cap);
GLAPI void APIENTRY glEnable (GLenum cap);
GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
#endif
#endif /* GL_VERSION_1_0 */
#ifndef GL_VERSION_1_1
typedef khronos_float_t GLclampf;
typedef double GLclampd;
#define GL_TEXTURE_BINDING_2D 0x8069
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
#endif
#endif /* GL_VERSION_1_1 */
#ifndef GL_VERSION_1_3
#define GL_TEXTURE0 0x84C0
#define GL_ACTIVE_TEXTURE 0x84E0
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glActiveTexture (GLenum texture);
#endif
#endif /* GL_VERSION_1_3 */
#ifndef GL_VERSION_1_4
#define GL_BLEND_DST_RGB 0x80C8
#define GL_BLEND_SRC_RGB 0x80C9
#define GL_BLEND_DST_ALPHA 0x80CA
#define GL_BLEND_SRC_ALPHA 0x80CB
#define GL_FUNC_ADD 0x8006
typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
GLAPI void APIENTRY glBlendEquation (GLenum mode);
#endif
#endif /* GL_VERSION_1_4 */
#ifndef GL_VERSION_1_5
typedef khronos_ssize_t GLsizeiptr;
typedef khronos_intptr_t GLintptr;
#define GL_ARRAY_BUFFER 0x8892
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#define GL_ARRAY_BUFFER_BINDING 0x8894
#define GL_STREAM_DRAW 0x88E0
typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
#endif
#endif /* GL_VERSION_1_5 */
#ifndef GL_VERSION_2_0
typedef char GLchar;
typedef khronos_int16_t GLshort;
typedef khronos_int8_t GLbyte;
typedef khronos_uint16_t GLushort;
#define GL_BLEND_EQUATION_RGB 0x8009
#define GL_BLEND_EQUATION_ALPHA 0x883D
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_VERTEX_SHADER 0x8B31
#define GL_COMPILE_STATUS 0x8B81
#define GL_LINK_STATUS 0x8B82
#define GL_INFO_LOG_LENGTH 0x8B84
#define GL_CURRENT_PROGRAM 0x8B8D
#define GL_UPPER_LEFT 0x8CA2
typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
GLAPI void APIENTRY glCompileShader (GLuint shader);
GLAPI GLuint APIENTRY glCreateProgram (void);
GLAPI GLuint APIENTRY glCreateShader (GLenum type);
GLAPI void APIENTRY glDeleteProgram (GLuint program);
GLAPI void APIENTRY glDeleteShader (GLuint shader);
GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
GLAPI void APIENTRY glLinkProgram (GLuint program);
GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
GLAPI void APIENTRY glUseProgram (GLuint program);
GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
#endif
#endif /* GL_VERSION_2_0 */
#ifndef GL_VERSION_3_0
typedef khronos_uint16_t GLhalf;
#define GL_MAJOR_VERSION 0x821B
#define GL_MINOR_VERSION 0x821C
#define GL_NUM_EXTENSIONS 0x821D
#define GL_FRAMEBUFFER_SRGB 0x8DB9
#define GL_VERTEX_ARRAY_BINDING 0x85B5
typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
GLAPI void APIENTRY glBindVertexArray (GLuint array);
GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
#endif
#endif /* GL_VERSION_3_0 */
#ifndef GL_VERSION_3_1
#define GL_VERSION_3_1 1
#define GL_PRIMITIVE_RESTART 0x8F9D
#endif /* GL_VERSION_3_1 */
#ifndef GL_VERSION_3_2
#define GL_VERSION_3_2 1
typedef struct __GLsync *GLsync;
typedef khronos_uint64_t GLuint64;
typedef khronos_int64_t GLint64;
typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
#endif
#endif /* GL_VERSION_3_2 */
#ifndef GL_VERSION_3_3
#define GL_VERSION_3_3 1
#define GL_SAMPLER_BINDING 0x8919
typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
#endif
#endif /* GL_VERSION_3_3 */
#ifndef GL_VERSION_4_1
typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
#endif /* GL_VERSION_4_1 */
#ifndef GL_VERSION_4_3
typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
#endif /* GL_VERSION_4_3 */
#ifndef GL_VERSION_4_5
#define GL_CLIP_ORIGIN 0x935C
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
#endif /* GL_VERSION_4_5 */
#ifndef GL_ARB_bindless_texture
typedef khronos_uint64_t GLuint64EXT;
#endif /* GL_ARB_bindless_texture */
#ifndef GL_ARB_cl_event
struct _cl_context;
struct _cl_event;
#endif /* GL_ARB_cl_event */
#ifndef GL_ARB_clip_control
#define GL_ARB_clip_control 1
#endif /* GL_ARB_clip_control */
#ifndef GL_ARB_debug_output
typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
#endif /* GL_ARB_debug_output */
#ifndef GL_EXT_EGL_image_storage
typedef void *GLeglImageOES;
#endif /* GL_EXT_EGL_image_storage */
#ifndef GL_EXT_direct_state_access
typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
#endif /* GL_EXT_direct_state_access */
#ifndef GL_NV_draw_vulkan_image
typedef void (APIENTRY *GLVULKANPROCNV)(void);
#endif /* GL_NV_draw_vulkan_image */
#ifndef GL_NV_gpu_shader5
typedef khronos_int64_t GLint64EXT;
#endif /* GL_NV_gpu_shader5 */
#ifndef GL_NV_vertex_buffer_unified_memory
typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
#endif /* GL_NV_vertex_buffer_unified_memory */
#ifdef __cplusplus
}
#endif
#endif
#ifndef GL3W_API
#define GL3W_API
#endif
#ifndef __gl_h_
#define __gl_h_
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define GL3W_OK 0
#define GL3W_ERROR_INIT -1
#define GL3W_ERROR_LIBRARY_OPEN -2
#define GL3W_ERROR_OPENGL_VERSION -3
typedef void (*GL3WglProc)(void);
typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
/* gl3w api */
GL3W_API int imgl3wInit(void);
GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
GL3W_API int imgl3wIsSupported(int major, int minor);
GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
/* gl3w internal state */
union GL3WProcs {
GL3WglProc ptr[52];
struct {
PFNGLACTIVETEXTUREPROC ActiveTexture;
PFNGLATTACHSHADERPROC AttachShader;
PFNGLBINDBUFFERPROC BindBuffer;
PFNGLBINDSAMPLERPROC BindSampler;
PFNGLBINDTEXTUREPROC BindTexture;
PFNGLBINDVERTEXARRAYPROC BindVertexArray;
PFNGLBLENDEQUATIONPROC BlendEquation;
PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
PFNGLBUFFERDATAPROC BufferData;
PFNGLCLEARPROC Clear;
PFNGLCLEARCOLORPROC ClearColor;
PFNGLCOMPILESHADERPROC CompileShader;
PFNGLCREATEPROGRAMPROC CreateProgram;
PFNGLCREATESHADERPROC CreateShader;
PFNGLDELETEBUFFERSPROC DeleteBuffers;
PFNGLDELETEPROGRAMPROC DeleteProgram;
PFNGLDELETESHADERPROC DeleteShader;
PFNGLDELETETEXTURESPROC DeleteTextures;
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
PFNGLDETACHSHADERPROC DetachShader;
PFNGLDISABLEPROC Disable;
PFNGLDRAWELEMENTSPROC DrawElements;
PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
PFNGLENABLEPROC Enable;
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
PFNGLGENBUFFERSPROC GenBuffers;
PFNGLGENTEXTURESPROC GenTextures;
PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
PFNGLGETINTEGERVPROC GetIntegerv;
PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
PFNGLGETPROGRAMIVPROC GetProgramiv;
PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
PFNGLGETSHADERIVPROC GetShaderiv;
PFNGLGETSTRINGPROC GetString;
PFNGLGETSTRINGIPROC GetStringi;
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
PFNGLISENABLEDPROC IsEnabled;
PFNGLLINKPROGRAMPROC LinkProgram;
PFNGLPIXELSTOREIPROC PixelStorei;
PFNGLPOLYGONMODEPROC PolygonMode;
PFNGLREADPIXELSPROC ReadPixels;
PFNGLSCISSORPROC Scissor;
PFNGLSHADERSOURCEPROC ShaderSource;
PFNGLTEXIMAGE2DPROC TexImage2D;
PFNGLTEXPARAMETERIPROC TexParameteri;
PFNGLUNIFORM1IPROC Uniform1i;
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
PFNGLUSEPROGRAMPROC UseProgram;
PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
PFNGLVIEWPORTPROC Viewport;
} gl;
};
GL3W_API extern union GL3WProcs gl3wProcs;
/* OpenGL functions */
#define glActiveTexture gl3wProcs.gl.ActiveTexture
#define glAttachShader gl3wProcs.gl.AttachShader
#define glBindBuffer gl3wProcs.gl.BindBuffer
#define glBindSampler gl3wProcs.gl.BindSampler
#define glBindTexture gl3wProcs.gl.BindTexture
#define glBindVertexArray gl3wProcs.gl.BindVertexArray
#define glBlendEquation gl3wProcs.gl.BlendEquation
#define glBlendEquationSeparate gl3wProcs.gl.BlendEquationSeparate
#define glBlendFuncSeparate gl3wProcs.gl.BlendFuncSeparate
#define glBufferData gl3wProcs.gl.BufferData
#define glClear gl3wProcs.gl.Clear
#define glClearColor gl3wProcs.gl.ClearColor
#define glCompileShader gl3wProcs.gl.CompileShader
#define glCreateProgram gl3wProcs.gl.CreateProgram
#define glCreateShader gl3wProcs.gl.CreateShader
#define glDeleteBuffers gl3wProcs.gl.DeleteBuffers
#define glDeleteProgram gl3wProcs.gl.DeleteProgram
#define glDeleteShader gl3wProcs.gl.DeleteShader
#define glDeleteTextures gl3wProcs.gl.DeleteTextures
#define glDeleteVertexArrays gl3wProcs.gl.DeleteVertexArrays
#define glDetachShader gl3wProcs.gl.DetachShader
#define glDisable gl3wProcs.gl.Disable
#define glDrawElements gl3wProcs.gl.DrawElements
#define glDrawElementsBaseVertex gl3wProcs.gl.DrawElementsBaseVertex
#define glEnable gl3wProcs.gl.Enable
#define glEnableVertexAttribArray gl3wProcs.gl.EnableVertexAttribArray
#define glGenBuffers gl3wProcs.gl.GenBuffers
#define glGenTextures gl3wProcs.gl.GenTextures
#define glGenVertexArrays gl3wProcs.gl.GenVertexArrays
#define glGetAttribLocation gl3wProcs.gl.GetAttribLocation
#define glGetIntegerv gl3wProcs.gl.GetIntegerv
#define glGetProgramInfoLog gl3wProcs.gl.GetProgramInfoLog
#define glGetProgramiv gl3wProcs.gl.GetProgramiv
#define glGetShaderInfoLog gl3wProcs.gl.GetShaderInfoLog
#define glGetShaderiv gl3wProcs.gl.GetShaderiv
#define glGetString gl3wProcs.gl.GetString
#define glGetStringi gl3wProcs.gl.GetStringi
#define glGetUniformLocation gl3wProcs.gl.GetUniformLocation
#define glIsEnabled gl3wProcs.gl.IsEnabled
#define glLinkProgram gl3wProcs.gl.LinkProgram
#define glPixelStorei gl3wProcs.gl.PixelStorei
#define glPolygonMode gl3wProcs.gl.PolygonMode
#define glReadPixels gl3wProcs.gl.ReadPixels
#define glScissor gl3wProcs.gl.Scissor
#define glShaderSource gl3wProcs.gl.ShaderSource
#define glTexImage2D gl3wProcs.gl.TexImage2D
#define glTexParameteri gl3wProcs.gl.TexParameteri
#define glUniform1i gl3wProcs.gl.Uniform1i
#define glUniformMatrix4fv gl3wProcs.gl.UniformMatrix4fv
#define glUseProgram gl3wProcs.gl.UseProgram
#define glVertexAttribPointer gl3wProcs.gl.VertexAttribPointer
#define glViewport gl3wProcs.gl.Viewport
#ifdef __cplusplus
}
#endif
#endif
#ifdef IMGL3W_IMPL
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
static HMODULE libgl;
typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
static GL3WglGetProcAddr wgl_get_proc_address;
static int open_libgl(void)
{
libgl = LoadLibraryA("opengl32.dll");
if (!libgl)
return GL3W_ERROR_LIBRARY_OPEN;
wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
return GL3W_OK;
}
static void close_libgl(void) { FreeLibrary(libgl); }
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
res = (GL3WglProc)wgl_get_proc_address(proc);
if (!res)
res = (GL3WglProc)GetProcAddress(libgl, proc);
return res;
}
#elif defined(__APPLE__)
#include <dlfcn.h>
static void *libgl;
static int open_libgl(void)
{
libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
if (!libgl)
return GL3W_ERROR_LIBRARY_OPEN;
return GL3W_OK;
}
static void close_libgl(void) { dlclose(libgl); }
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
*(void **)(&res) = dlsym(libgl, proc);
return res;
}
#else
#include <dlfcn.h>
static void *libgl;
static GL3WglProc (*glx_get_proc_address)(const GLubyte *);
static int open_libgl(void)
{
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
if (!libgl)
return GL3W_ERROR_LIBRARY_OPEN;
*(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
return GL3W_OK;
}
static void close_libgl(void) { dlclose(libgl); }
static GL3WglProc get_proc(const char *proc)
{
GL3WglProc res;
res = glx_get_proc_address((const GLubyte *)proc);
if (!res)
*(void **)(&res) = dlsym(libgl, proc);
return res;
}
#endif
static struct { int major, minor; } version;
static int parse_version(void)
{
if (!glGetIntegerv)
return GL3W_ERROR_INIT;
glGetIntegerv(GL_MAJOR_VERSION, &version.major);
glGetIntegerv(GL_MINOR_VERSION, &version.minor);
if (version.major < 3)
return GL3W_ERROR_OPENGL_VERSION;
return GL3W_OK;
}
static void load_procs(GL3WGetProcAddressProc proc);
int imgl3wInit(void)
{
int res = open_libgl();
if (res)
return res;
atexit(close_libgl);
return imgl3wInit2(get_proc);
}
int imgl3wInit2(GL3WGetProcAddressProc proc)
{
load_procs(proc);
return parse_version();
}
int imgl3wIsSupported(int major, int minor)
{
if (major < 3)
return 0;
if (version.major == major)
return version.minor >= minor;
return version.major >= major;
}
GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
static const char *proc_names[] = {
"glActiveTexture",
"glAttachShader",
"glBindBuffer",
"glBindSampler",
"glBindTexture",
"glBindVertexArray",
"glBlendEquation",
"glBlendEquationSeparate",
"glBlendFuncSeparate",
"glBufferData",
"glClear",
"glClearColor",
"glCompileShader",
"glCreateProgram",
"glCreateShader",
"glDeleteBuffers",
"glDeleteProgram",
"glDeleteShader",
"glDeleteTextures",
"glDeleteVertexArrays",
"glDetachShader",
"glDisable",
"glDrawElements",
"glDrawElementsBaseVertex",
"glEnable",
"glEnableVertexAttribArray",
"glGenBuffers",
"glGenTextures",
"glGenVertexArrays",
"glGetAttribLocation",
"glGetIntegerv",
"glGetProgramInfoLog",
"glGetProgramiv",
"glGetShaderInfoLog",
"glGetShaderiv",
"glGetString",
"glGetStringi",
"glGetUniformLocation",
"glIsEnabled",
"glLinkProgram",
"glPixelStorei",
"glPolygonMode",
"glReadPixels",
"glScissor",
"glShaderSource",
"glTexImage2D",
"glTexParameteri",
"glUniform1i",
"glUniformMatrix4fv",
"glUseProgram",
"glVertexAttribPointer",
"glViewport",
};
GL3W_API union GL3WProcs gl3wProcs;
static void load_procs(GL3WGetProcAddressProc proc)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(proc_names); i++)
gl3wProcs.ptr[i] = proc(proc_names[i]);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,443 @@
// dear imgui: Platform Backend for SDL2
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
// (Prefer SDL 2.0.5+ for full feature support.)
// Implemented features:
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Clipboard support.
// [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE).
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// Missing features:
// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2021-08-17: Calling io.AddFocusEvent() on SDL_WINDOWEVENT_FOCUS_GAINED/SDL_WINDOWEVENT_FOCUS_LOST.
// 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using SDL_GetMouseFocus() + SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, requires SDL 2.0.5+)
// 2021-06-29: *BREAKING CHANGE* Removed 'SDL_Window* window' parameter to ImGui_ImplSDL2_NewFrame() which was unnecessary.
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
// 2021-03-22: Rework global mouse pos availability check listing supported platforms explicitly, effectively fixing mouse access on Raspberry Pi. (#2837, #3950)
// 2020-05-25: Misc: Report a zero display-size when window is minimized, to be consistent with other backends.
// 2020-02-20: Inputs: Fixed mapping for ImGuiKey_KeyPadEnter (using SDL_SCANCODE_KP_ENTER instead of SDL_SCANCODE_RETURN2).
// 2019-12-17: Inputs: On Wayland, use SDL_GetMouseState (because there is no global mouse state).
// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor.
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
// 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
// 2018-12-21: Inputs: Workaround for Android/iOS which don't seem to handle focus related calls.
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
// 2018-11-14: Changed the signature of ImGui_ImplSDL2_ProcessEvent() to take a 'const SDL_Event*'.
// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
// 2018-06-08: Misc: Extracted imgui_impl_sdl.cpp/.h away from the old combined SDL2+OpenGL/Vulkan examples.
// 2018-06-08: Misc: ImGui_ImplSDL2_InitForOpenGL() now takes a SDL_GLContext parameter.
// 2018-05-09: Misc: Fixed clipboard paste memory leak (we didn't call SDL_FreeMemory on the data returned by SDL_GetClipboardText).
// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
// 2018-02-16: Inputs: Added support for mouse cursors, honoring ImGui::GetMouseCursor() value.
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
// 2018-02-05: Misc: Using SDL_GetPerformanceCounter() instead of SDL_GetTicks() to be able to handle very high framerate (1000+ FPS).
// 2018-02-05: Inputs: Keyboard mapping is using scancodes everywhere instead of a confusing mixture of keycodes and scancodes.
// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
// 2018-01-19: Inputs: When available (SDL 2.0.4+) using SDL_CaptureMouse() to retrieve coordinates outside of client area when dragging. Otherwise (SDL 2.0.3 and before) testing for SDL_WINDOW_INPUT_FOCUS instead of SDL_WINDOW_MOUSE_FOCUS.
// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
#include "imgui.h"
#include "imgui_impl_sdl.h"
// SDL
#include <SDL.h>
#include <SDL_syswm.h>
#if defined(__APPLE__)
#include "TargetConditionals.h"
#endif
#if SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
#else
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
#endif
#define SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH SDL_VERSION_ATLEAST(2,0,5)
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
// SDL Data
struct ImGui_ImplSDL2_Data
{
SDL_Window* Window;
Uint64 Time;
bool MousePressed[3];
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
char* ClipboardTextData;
bool MouseCanUseGlobalState;
ImGui_ImplSDL2_Data() { memset(this, 0, sizeof(*this)); }
};
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData()
{
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData : NULL;
}
// Functions
static const char* ImGui_ImplSDL2_GetClipboardText(void*)
{
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
if (bd->ClipboardTextData)
SDL_free(bd->ClipboardTextData);
bd->ClipboardTextData = SDL_GetClipboardText();
return bd->ClipboardTextData;
}
static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text)
{
SDL_SetClipboardText(text);
}
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
switch (event->type)
{
case SDL_MOUSEWHEEL:
{
if (event->wheel.x > 0) io.MouseWheelH += 1;
if (event->wheel.x < 0) io.MouseWheelH -= 1;
if (event->wheel.y > 0) io.MouseWheel += 1;
if (event->wheel.y < 0) io.MouseWheel -= 1;
return true;
}
case SDL_MOUSEBUTTONDOWN:
{
if (event->button.button == SDL_BUTTON_LEFT) { bd->MousePressed[0] = true; }
if (event->button.button == SDL_BUTTON_RIGHT) { bd->MousePressed[1] = true; }
if (event->button.button == SDL_BUTTON_MIDDLE) { bd->MousePressed[2] = true; }
return true;
}
case SDL_TEXTINPUT:
{
io.AddInputCharactersUTF8(event->text.text);
return true;
}
case SDL_KEYDOWN:
case SDL_KEYUP:
{
int key = event->key.keysym.scancode;
IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown));
io.KeysDown[key] = (event->type == SDL_KEYDOWN);
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
#ifdef _WIN32
io.KeySuper = false;
#else
io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
#endif
return true;
}
case SDL_WINDOWEVENT:
{
if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
io.AddFocusEvent(true);
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
io.AddFocusEvent(false);
return true;
}
}
return false;
}
static bool ImGui_ImplSDL2_Init(SDL_Window* window)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!");
// Check and store if we are on a SDL backend that supports global mouse position
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
bool mouse_can_use_global_state = false;
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
const char* sdl_backend = SDL_GetCurrentVideoDriver();
const char* global_mouse_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
for (int n = 0; n < IM_ARRAYSIZE(global_mouse_whitelist); n++)
if (strncmp(sdl_backend, global_mouse_whitelist[n], strlen(global_mouse_whitelist[n])) == 0)
mouse_can_use_global_state = true;
#endif
// Setup backend capabilities flags
ImGui_ImplSDL2_Data* bd = IM_NEW(ImGui_ImplSDL2_Data)();
io.BackendPlatformUserData = (void*)bd;
io.BackendPlatformName = "imgui_impl_sdl";
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
bd->Window = window;
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
// Keyboard mapping. Dear ImGui will use those indices to peek into the io.KeysDown[] array.
io.KeyMap[ImGuiKey_Tab] = SDL_SCANCODE_TAB;
io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
io.KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN;
io.KeyMap[ImGuiKey_PageUp] = SDL_SCANCODE_PAGEUP;
io.KeyMap[ImGuiKey_PageDown] = SDL_SCANCODE_PAGEDOWN;
io.KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME;
io.KeyMap[ImGuiKey_End] = SDL_SCANCODE_END;
io.KeyMap[ImGuiKey_Insert] = SDL_SCANCODE_INSERT;
io.KeyMap[ImGuiKey_Delete] = SDL_SCANCODE_DELETE;
io.KeyMap[ImGuiKey_Backspace] = SDL_SCANCODE_BACKSPACE;
io.KeyMap[ImGuiKey_Space] = SDL_SCANCODE_SPACE;
io.KeyMap[ImGuiKey_Enter] = SDL_SCANCODE_RETURN;
io.KeyMap[ImGuiKey_Escape] = SDL_SCANCODE_ESCAPE;
io.KeyMap[ImGuiKey_KeyPadEnter] = SDL_SCANCODE_KP_ENTER;
io.KeyMap[ImGuiKey_A] = SDL_SCANCODE_A;
io.KeyMap[ImGuiKey_C] = SDL_SCANCODE_C;
io.KeyMap[ImGuiKey_V] = SDL_SCANCODE_V;
io.KeyMap[ImGuiKey_X] = SDL_SCANCODE_X;
io.KeyMap[ImGuiKey_Y] = SDL_SCANCODE_Y;
io.KeyMap[ImGuiKey_Z] = SDL_SCANCODE_Z;
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
io.ClipboardUserData = NULL;
// Load mouse cursors
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
#ifdef _WIN32
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(window, &info))
io.ImeWindowHandle = info.info.win.window;
#else
(void)window;
#endif
// Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
// (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
// It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
// you can ignore SDL_MOUSEBUTTONDOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED)
#if SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
#endif
return true;
}
bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
{
IM_UNUSED(sdl_gl_context); // Viewport branch will need this.
return ImGui_ImplSDL2_Init(window);
}
bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
{
#if !SDL_HAS_VULKAN
IM_ASSERT(0 && "Unsupported");
#endif
return ImGui_ImplSDL2_Init(window);
}
bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
{
#if !defined(_WIN32)
IM_ASSERT(0 && "Unsupported");
#endif
return ImGui_ImplSDL2_Init(window);
}
bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window)
{
return ImGui_ImplSDL2_Init(window);
}
void ImGui_ImplSDL2_Shutdown()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
if (bd->ClipboardTextData)
SDL_free(bd->ClipboardTextData);
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
SDL_FreeCursor(bd->MouseCursors[cursor_n]);
io.BackendPlatformName = NULL;
io.BackendPlatformUserData = NULL;
IM_DELETE(bd);
}
static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
{
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
ImGuiIO& io = ImGui::GetIO();
ImVec2 mouse_pos_prev = io.MousePos;
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
// Update mouse buttons
int mouse_x_local, mouse_y_local;
Uint32 mouse_buttons = SDL_GetMouseState(&mouse_x_local, &mouse_y_local);
io.MouseDown[0] = bd->MousePressed[0] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[1] = bd->MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
io.MouseDown[2] = bd->MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
bd->MousePressed[0] = bd->MousePressed[1] = bd->MousePressed[2] = false;
// Obtain focused and hovered window. We forward mouse input when focused or when hovered (and no other window is capturing)
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
SDL_Window* focused_window = SDL_GetKeyboardFocus();
SDL_Window* hovered_window = SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH ? SDL_GetMouseFocus() : NULL; // This is better but is only reliably useful with SDL 2.0.5+ and SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH.
SDL_Window* mouse_window = NULL;
if (hovered_window && bd->Window == hovered_window)
mouse_window = hovered_window;
else if (focused_window && bd->Window == focused_window)
mouse_window = focused_window;
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside
SDL_CaptureMouse(ImGui::IsAnyMouseDown() ? SDL_TRUE : SDL_FALSE);
#else
// SDL 2.0.3 and non-windowed systems: single-viewport only
SDL_Window* mouse_window = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) ? bd->Window : NULL;
#endif
if (mouse_window == NULL)
return;
// Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
if (io.WantSetMousePos)
SDL_WarpMouseInWindow(bd->Window, (int)mouse_pos_prev.x, (int)mouse_pos_prev.y);
// Set Dear ImGui mouse position from OS position + get buttons. (this is the common behavior)
if (bd->MouseCanUseGlobalState)
{
// Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
// Unlike local position obtained earlier this will be valid when straying out of bounds.
int mouse_x_global, mouse_y_global;
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
int window_x, window_y;
SDL_GetWindowPosition(mouse_window, &window_x, &window_y);
io.MousePos = ImVec2((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y));
}
else
{
io.MousePos = ImVec2((float)mouse_x_local, (float)mouse_y_local);
}
}
static void ImGui_ImplSDL2_UpdateMouseCursor()
{
ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
return;
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
{
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
SDL_ShowCursor(SDL_FALSE);
}
else
{
// Show OS mouse cursor
SDL_SetCursor(bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
SDL_ShowCursor(SDL_TRUE);
}
}
static void ImGui_ImplSDL2_UpdateGamepads()
{
ImGuiIO& io = ImGui::GetIO();
memset(io.NavInputs, 0, sizeof(io.NavInputs));
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
return;
// Get gamepad
SDL_GameController* game_controller = SDL_GameControllerOpen(0);
if (!game_controller)
{
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
return;
}
// Update gamepad inputs
#define MAP_BUTTON(NAV_NO, BUTTON_NO) { io.NavInputs[NAV_NO] = (SDL_GameControllerGetButton(game_controller, BUTTON_NO) != 0) ? 1.0f : 0.0f; }
#define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GameControllerGetAxis(game_controller, AXIS_NO) - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; }
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
MAP_BUTTON(ImGuiNavInput_Activate, SDL_CONTROLLER_BUTTON_A); // Cross / A
MAP_BUTTON(ImGuiNavInput_Cancel, SDL_CONTROLLER_BUTTON_B); // Circle / B
MAP_BUTTON(ImGuiNavInput_Menu, SDL_CONTROLLER_BUTTON_X); // Square / X
MAP_BUTTON(ImGuiNavInput_Input, SDL_CONTROLLER_BUTTON_Y); // Triangle / Y
MAP_BUTTON(ImGuiNavInput_DpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT); // D-Pad Left
MAP_BUTTON(ImGuiNavInput_DpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); // D-Pad Right
MAP_BUTTON(ImGuiNavInput_DpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP); // D-Pad Up
MAP_BUTTON(ImGuiNavInput_DpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN); // D-Pad Down
MAP_BUTTON(ImGuiNavInput_FocusPrev, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
MAP_BUTTON(ImGuiNavInput_FocusNext, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
MAP_BUTTON(ImGuiNavInput_TweakSlow, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
MAP_BUTTON(ImGuiNavInput_TweakFast, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
MAP_ANALOG(ImGuiNavInput_LStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
MAP_ANALOG(ImGuiNavInput_LStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
MAP_ANALOG(ImGuiNavInput_LStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32767);
MAP_ANALOG(ImGuiNavInput_LStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
#undef MAP_BUTTON
#undef MAP_ANALOG
}
void ImGui_ImplSDL2_NewFrame()
{
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDL2_Init()?");
ImGuiIO& io = ImGui::GetIO();
// Setup display size (every frame to accommodate for window resizing)
int w, h;
int display_w, display_h;
SDL_GetWindowSize(bd->Window, &w, &h);
if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_MINIMIZED)
w = h = 0;
SDL_GL_GetDrawableSize(bd->Window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)w, (float)h);
if (w > 0 && h > 0)
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
static Uint64 frequency = SDL_GetPerformanceFrequency();
Uint64 current_time = SDL_GetPerformanceCounter();
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
bd->Time = current_time;
ImGui_ImplSDL2_UpdateMousePosAndButtons();
ImGui_ImplSDL2_UpdateMouseCursor();
// Update game controllers (if enabled and available)
ImGui_ImplSDL2_UpdateGamepads();
}

View File

@ -0,0 +1,34 @@
// dear imgui: Platform Backend for SDL2
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
// Implemented features:
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Clipboard support.
// [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE).
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// Missing features:
// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
#pragma once
#include "imgui.h" // IMGUI_IMPL_API
struct SDL_Window;
typedef union SDL_Event SDL_Event;
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
static inline void ImGui_ImplSDL2_NewFrame(SDL_Window*) { ImGui_ImplSDL2_NewFrame(); } // 1.84: removed unnecessary parameter
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,639 @@
// [DEAR IMGUI]
// This is a slightly modified version of stb_rect_pack.h 1.00.
// Those changes would need to be pushed into nothings/stb:
// - Added STBRP__CDECL
// Grep for [DEAR IMGUI] to find the changes.
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
// Sean Barrett 2014
//
// Useful for e.g. packing rectangular textures into an atlas.
// Does not do rotation.
//
// Not necessarily the awesomest packing method, but better than
// the totally naive one in stb_truetype (which is primarily what
// this is meant to replace).
//
// Has only had a few tests run, may have issues.
//
// More docs to come.
//
// No memory allocations; uses qsort() and assert() from stdlib.
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
//
// This library currently uses the Skyline Bottom-Left algorithm.
//
// Please note: better rectangle packers are welcome! Please
// implement them to the same API, but with a different init
// function.
//
// Credits
//
// Library
// Sean Barrett
// Minor features
// Martins Mozeiko
// github:IntellectualKitty
//
// Bugfixes / warning fixes
// Jeremy Jaussaud
// Fabian Giesen
//
// Version history:
//
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
// 0.99 (2019-02-07) warning fixes
// 0.11 (2017-03-03) return packing success/fail result
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
// 0.09 (2016-08-27) fix compiler warnings
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
// 0.05: added STBRP_ASSERT to allow replacing assert
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
// 0.01: initial release
//
// LICENSE
//
// See end of file for license information.
//////////////////////////////////////////////////////////////////////////////
//
// INCLUDE SECTION
//
#ifndef STB_INCLUDE_STB_RECT_PACK_H
#define STB_INCLUDE_STB_RECT_PACK_H
#define STB_RECT_PACK_VERSION 1
#ifdef STBRP_STATIC
#define STBRP_DEF static
#else
#define STBRP_DEF extern
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct stbrp_context stbrp_context;
typedef struct stbrp_node stbrp_node;
typedef struct stbrp_rect stbrp_rect;
#ifdef STBRP_LARGE_RECTS
typedef int stbrp_coord;
#else
typedef unsigned short stbrp_coord;
#endif
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
// Assign packed locations to rectangles. The rectangles are of type
// 'stbrp_rect' defined below, stored in the array 'rects', and there
// are 'num_rects' many of them.
//
// Rectangles which are successfully packed have the 'was_packed' flag
// set to a non-zero value and 'x' and 'y' store the minimum location
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
// if you imagine y increasing downwards). Rectangles which do not fit
// have the 'was_packed' flag set to 0.
//
// You should not try to access the 'rects' array from another thread
// while this function is running, as the function temporarily reorders
// the array while it executes.
//
// To pack into another rectangle, you need to call stbrp_init_target
// again. To continue packing into the same rectangle, you can call
// this function again. Calling this multiple times with multiple rect
// arrays will probably produce worse packing results than calling it
// a single time with the full rectangle array, but the option is
// available.
//
// The function returns 1 if all of the rectangles were successfully
// packed and 0 otherwise.
struct stbrp_rect
{
// reserved for your use:
int id;
// input:
stbrp_coord w, h;
// output:
stbrp_coord x, y;
int was_packed; // non-zero if valid packing
}; // 16 bytes, nominally
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
// Initialize a rectangle packer to:
// pack a rectangle that is 'width' by 'height' in dimensions
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
//
// You must call this function every time you start packing into a new target.
//
// There is no "shutdown" function. The 'nodes' memory must stay valid for
// the following stbrp_pack_rects() call (or calls), but can be freed after
// the call (or calls) finish.
//
// Note: to guarantee best results, either:
// 1. make sure 'num_nodes' >= 'width'
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
//
// If you don't do either of the above things, widths will be quantized to multiples
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
//
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
// may run out of temporary storage and be unable to pack some rectangles.
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
// Optionally call this function after init but before doing any packing to
// change the handling of the out-of-temp-memory scenario, described above.
// If you call init again, this will be reset to the default (false).
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
// Optionally select which packing heuristic the library should use. Different
// heuristics will produce better/worse results for different data sets.
// If you call init again, this will be reset to the default.
enum
{
STBRP_HEURISTIC_Skyline_default=0,
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
STBRP_HEURISTIC_Skyline_BF_sortHeight
};
//////////////////////////////////////////////////////////////////////////////
//
// the details of the following structures don't matter to you, but they must
// be visible so you can handle the memory allocations for them
struct stbrp_node
{
stbrp_coord x,y;
stbrp_node *next;
};
struct stbrp_context
{
int width;
int height;
int align;
int init_mode;
int heuristic;
int num_nodes;
stbrp_node *active_head;
stbrp_node *free_head;
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
};
#ifdef __cplusplus
}
#endif
#endif
//////////////////////////////////////////////////////////////////////////////
//
// IMPLEMENTATION SECTION
//
#ifdef STB_RECT_PACK_IMPLEMENTATION
#ifndef STBRP_SORT
#include <stdlib.h>
#define STBRP_SORT qsort
#endif
#ifndef STBRP_ASSERT
#include <assert.h>
#define STBRP_ASSERT assert
#endif
// [DEAR IMGUI] Added STBRP__CDECL
#ifdef _MSC_VER
#define STBRP__NOTUSED(v) (void)(v)
#define STBRP__CDECL __cdecl
#else
#define STBRP__NOTUSED(v) (void)sizeof(v)
#define STBRP__CDECL
#endif
enum
{
STBRP__INIT_skyline = 1
};
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
{
switch (context->init_mode) {
case STBRP__INIT_skyline:
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
context->heuristic = heuristic;
break;
default:
STBRP_ASSERT(0);
}
}
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
{
if (allow_out_of_mem)
// if it's ok to run out of memory, then don't bother aligning them;
// this gives better packing, but may fail due to OOM (even though
// the rectangles easily fit). @TODO a smarter approach would be to only
// quantize once we've hit OOM, then we could get rid of this parameter.
context->align = 1;
else {
// if it's not ok to run out of memory, then quantize the widths
// so that num_nodes is always enough nodes.
//
// I.e. num_nodes * align >= width
// align >= width / num_nodes
// align = ceil(width/num_nodes)
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
}
}
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
{
int i;
#ifndef STBRP_LARGE_RECTS
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
#endif
for (i=0; i < num_nodes-1; ++i)
nodes[i].next = &nodes[i+1];
nodes[i].next = NULL;
context->init_mode = STBRP__INIT_skyline;
context->heuristic = STBRP_HEURISTIC_Skyline_default;
context->free_head = &nodes[0];
context->active_head = &context->extra[0];
context->width = width;
context->height = height;
context->num_nodes = num_nodes;
stbrp_setup_allow_out_of_mem(context, 0);
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
context->extra[0].x = 0;
context->extra[0].y = 0;
context->extra[0].next = &context->extra[1];
context->extra[1].x = (stbrp_coord) width;
#ifdef STBRP_LARGE_RECTS
context->extra[1].y = (1<<30);
#else
context->extra[1].y = 65535;
#endif
context->extra[1].next = NULL;
}
// find minimum y position if it starts at x1
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
{
stbrp_node *node = first;
int x1 = x0 + width;
int min_y, visited_width, waste_area;
STBRP__NOTUSED(c);
STBRP_ASSERT(first->x <= x0);
#if 0
// skip in case we're past the node
while (node->next->x <= x0)
++node;
#else
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
#endif
STBRP_ASSERT(node->x <= x0);
min_y = 0;
waste_area = 0;
visited_width = 0;
while (node->x < x1) {
if (node->y > min_y) {
// raise min_y higher.
// we've accounted for all waste up to min_y,
// but we'll now add more waste for everything we've visted
waste_area += visited_width * (node->y - min_y);
min_y = node->y;
// the first time through, visited_width might be reduced
if (node->x < x0)
visited_width += node->next->x - x0;
else
visited_width += node->next->x - node->x;
} else {
// add waste area
int under_width = node->next->x - node->x;
if (under_width + visited_width > width)
under_width = width - visited_width;
waste_area += under_width * (min_y - node->y);
visited_width += under_width;
}
node = node->next;
}
*pwaste = waste_area;
return min_y;
}
typedef struct
{
int x,y;
stbrp_node **prev_link;
} stbrp__findresult;
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
{
int best_waste = (1<<30), best_x, best_y = (1 << 30);
stbrp__findresult fr;
stbrp_node **prev, *node, *tail, **best = NULL;
// align to multiple of c->align
width = (width + c->align - 1);
width -= width % c->align;
STBRP_ASSERT(width % c->align == 0);
// if it can't possibly fit, bail immediately
if (width > c->width || height > c->height) {
fr.prev_link = NULL;
fr.x = fr.y = 0;
return fr;
}
node = c->active_head;
prev = &c->active_head;
while (node->x + width <= c->width) {
int y,waste;
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
// bottom left
if (y < best_y) {
best_y = y;
best = prev;
}
} else {
// best-fit
if (y + height <= c->height) {
// can only use it if it first vertically
if (y < best_y || (y == best_y && waste < best_waste)) {
best_y = y;
best_waste = waste;
best = prev;
}
}
}
prev = &node->next;
node = node->next;
}
best_x = (best == NULL) ? 0 : (*best)->x;
// if doing best-fit (BF), we also have to try aligning right edge to each node position
//
// e.g, if fitting
//
// ____________________
// |____________________|
//
// into
//
// | |
// | ____________|
// |____________|
//
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
//
// This makes BF take about 2x the time
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
tail = c->active_head;
node = c->active_head;
prev = &c->active_head;
// find first node that's admissible
while (tail->x < width)
tail = tail->next;
while (tail) {
int xpos = tail->x - width;
int y,waste;
STBRP_ASSERT(xpos >= 0);
// find the left position that matches this
while (node->next->x <= xpos) {
prev = &node->next;
node = node->next;
}
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (y + height <= c->height) {
if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos;
STBRP_ASSERT(y <= best_y);
best_y = y;
best_waste = waste;
best = prev;
}
}
}
tail = tail->next;
}
}
fr.prev_link = best;
fr.x = best_x;
fr.y = best_y;
return fr;
}
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
{
// find best position according to heuristic
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
stbrp_node *node, *cur;
// bail if:
// 1. it failed
// 2. the best node doesn't fit (we don't always check this)
// 3. we're out of memory
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
res.prev_link = NULL;
return res;
}
// on success, create new node
node = context->free_head;
node->x = (stbrp_coord) res.x;
node->y = (stbrp_coord) (res.y + height);
context->free_head = node->next;
// insert the new node into the right starting point, and
// let 'cur' point to the remaining nodes needing to be
// stiched back in
cur = *res.prev_link;
if (cur->x < res.x) {
// preserve the existing one, so start testing with the next one
stbrp_node *next = cur->next;
cur->next = node;
cur = next;
} else {
*res.prev_link = node;
}
// from here, traverse cur and free the nodes, until we get to one
// that shouldn't be freed
while (cur->next && cur->next->x <= res.x + width) {
stbrp_node *next = cur->next;
// move the current node to the free list
cur->next = context->free_head;
context->free_head = cur;
cur = next;
}
// stitch the list back in
node->next = cur;
if (cur->x < res.x + width)
cur->x = (stbrp_coord) (res.x + width);
#ifdef _DEBUG
cur = context->active_head;
while (cur->x < context->width) {
STBRP_ASSERT(cur->x < cur->next->x);
cur = cur->next;
}
STBRP_ASSERT(cur->next == NULL);
{
int count=0;
cur = context->active_head;
while (cur) {
cur = cur->next;
++count;
}
cur = context->free_head;
while (cur) {
cur = cur->next;
++count;
}
STBRP_ASSERT(count == context->num_nodes+2);
}
#endif
return res;
}
// [DEAR IMGUI] Added STBRP__CDECL
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
const stbrp_rect *q = (const stbrp_rect *) b;
if (p->h > q->h)
return -1;
if (p->h < q->h)
return 1;
return (p->w > q->w) ? -1 : (p->w < q->w);
}
// [DEAR IMGUI] Added STBRP__CDECL
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
const stbrp_rect *q = (const stbrp_rect *) b;
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
}
#ifdef STBRP_LARGE_RECTS
#define STBRP__MAXVAL 0xffffffff
#else
#define STBRP__MAXVAL 0xffff
#endif
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
{
int i, all_rects_packed = 1;
// we use the 'was_packed' field internally to allow sorting/unsorting
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = i;
}
// sort according to heuristic
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
for (i=0; i < num_rects; ++i) {
if (rects[i].w == 0 || rects[i].h == 0) {
rects[i].x = rects[i].y = 0; // empty rect needs no space
} else {
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
if (fr.prev_link) {
rects[i].x = (stbrp_coord) fr.x;
rects[i].y = (stbrp_coord) fr.y;
} else {
rects[i].x = rects[i].y = STBRP__MAXVAL;
}
}
}
// unsort
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
// set was_packed flags and all_rects_packed status
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
if (!rects[i].was_packed)
all_rects_packed = 0;
}
// return the all_rects_packed status
return all_rects_packed;
}
#endif
/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,710 @@
#include "node_editor.h"
#include "graph.h"
#include <imnodes.h>
#include <imgui.h>
#include <SDL_keycode.h>
#include <SDL_timer.h>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <vector>
namespace example
{
namespace
{
enum class NodeType
{
add,
multiply,
output,
sine,
time,
value
};
struct Node
{
NodeType type;
float value;
explicit Node(const NodeType t) : type(t), value(0.f) {}
Node(const NodeType t, const float v) : type(t), value(v) {}
};
template<class T>
T clamp(T x, T a, T b)
{
return std::min(b, std::max(x, a));
}
static float current_time_seconds = 0.f;
static bool emulate_three_button_mouse = false;
ImU32 evaluate(const Graph<Node>& graph, const int root_node)
{
std::stack<int> postorder;
dfs_traverse(
graph, root_node, [&postorder](const int node_id) -> void { postorder.push(node_id); });
std::stack<float> value_stack;
while (!postorder.empty())
{
const int id = postorder.top();
postorder.pop();
const Node node = graph.node(id);
switch (node.type)
{
case NodeType::add:
{
const float rhs = value_stack.top();
value_stack.pop();
const float lhs = value_stack.top();
value_stack.pop();
value_stack.push(lhs + rhs);
}
break;
case NodeType::multiply:
{
const float rhs = value_stack.top();
value_stack.pop();
const float lhs = value_stack.top();
value_stack.pop();
value_stack.push(rhs * lhs);
}
break;
case NodeType::sine:
{
const float x = value_stack.top();
value_stack.pop();
const float res = std::abs(std::sin(x));
value_stack.push(res);
}
break;
case NodeType::time:
{
value_stack.push(current_time_seconds);
}
break;
case NodeType::value:
{
// If the edge does not have an edge connecting to another node, then just use the value
// at this node. It means the node's input pin has not been connected to anything and
// the value comes from the node's UI.
if (graph.num_edges_from_node(id) == 0ull)
{
value_stack.push(node.value);
}
}
break;
default:
break;
}
}
// The final output node isn't evaluated in the loop -- instead we just pop
// the three values which should be in the stack.
assert(value_stack.size() == 3ull);
const int b = static_cast<int>(255.f * clamp(value_stack.top(), 0.f, 1.f) + 0.5f);
value_stack.pop();
const int g = static_cast<int>(255.f * clamp(value_stack.top(), 0.f, 1.f) + 0.5f);
value_stack.pop();
const int r = static_cast<int>(255.f * clamp(value_stack.top(), 0.f, 1.f) + 0.5f);
value_stack.pop();
return IM_COL32(r, g, b, 255);
}
class ColorNodeEditor
{
public:
ColorNodeEditor() : graph_(), nodes_(), root_node_id_(-1),
minimap_location_(ImNodesMiniMapLocation_BottomRight) {}
void show()
{
// Update timer context
current_time_seconds = 0.001f * SDL_GetTicks();
auto flags = ImGuiWindowFlags_MenuBar;
// The node editor window
ImGui::Begin("color node editor", NULL, flags);
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Mini-map"))
{
const char* names[] = {
"Top Left",
"Top Right",
"Bottom Left",
"Bottom Right",
};
int locations[] = {
ImNodesMiniMapLocation_TopLeft,
ImNodesMiniMapLocation_TopRight,
ImNodesMiniMapLocation_BottomLeft,
ImNodesMiniMapLocation_BottomRight,
};
for (int i = 0; i < 4; i++)
{
bool selected = minimap_location_ == locations[i];
if (ImGui::MenuItem(names[i], NULL, &selected))
minimap_location_ = locations[i];
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Style"))
{
if (ImGui::MenuItem("Classic"))
{
ImGui::StyleColorsClassic();
ImNodes::StyleColorsClassic();
}
if (ImGui::MenuItem("Dark"))
{
ImGui::StyleColorsDark();
ImNodes::StyleColorsDark();
}
if (ImGui::MenuItem("Light"))
{
ImGui::StyleColorsLight();
ImNodes::StyleColorsLight();
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
ImGui::TextUnformatted("Edit the color of the output color window using nodes.");
ImGui::Columns(2);
ImGui::TextUnformatted("A -- add node");
ImGui::TextUnformatted("X -- delete selected node or link");
ImGui::NextColumn();
if (ImGui::Checkbox("emulate_three_button_mouse", &emulate_three_button_mouse))
{
ImNodes::GetIO().EmulateThreeButtonMouse.Modifier =
emulate_three_button_mouse ? &ImGui::GetIO().KeyAlt : NULL;
}
ImGui::Columns(1);
ImNodes::BeginNodeEditor();
// Handle new nodes
// These are driven by the user, so we place this code before rendering the nodes
{
const bool open_popup = ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
ImNodes::IsEditorHovered() &&
ImGui::IsKeyReleased(SDL_SCANCODE_A);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.f, 8.f));
if (!ImGui::IsAnyItemHovered() && open_popup)
{
ImGui::OpenPopup("add node");
}
if (ImGui::BeginPopup("add node"))
{
const ImVec2 click_pos = ImGui::GetMousePosOnOpeningCurrentPopup();
if (ImGui::MenuItem("add"))
{
const Node value(NodeType::value, 0.f);
const Node op(NodeType::add);
UiNode ui_node;
ui_node.type = UiNodeType::add;
ui_node.add.lhs = graph_.insert_node(value);
ui_node.add.rhs = graph_.insert_node(value);
ui_node.id = graph_.insert_node(op);
graph_.insert_edge(ui_node.id, ui_node.add.lhs);
graph_.insert_edge(ui_node.id, ui_node.add.rhs);
nodes_.push_back(ui_node);
ImNodes::SetNodeScreenSpacePos(ui_node.id, click_pos);
}
if (ImGui::MenuItem("multiply"))
{
const Node value(NodeType::value, 0.f);
const Node op(NodeType::multiply);
UiNode ui_node;
ui_node.type = UiNodeType::multiply;
ui_node.multiply.lhs = graph_.insert_node(value);
ui_node.multiply.rhs = graph_.insert_node(value);
ui_node.id = graph_.insert_node(op);
graph_.insert_edge(ui_node.id, ui_node.multiply.lhs);
graph_.insert_edge(ui_node.id, ui_node.multiply.rhs);
nodes_.push_back(ui_node);
ImNodes::SetNodeScreenSpacePos(ui_node.id, click_pos);
}
if (ImGui::MenuItem("output") && root_node_id_ == -1)
{
const Node value(NodeType::value, 0.f);
const Node out(NodeType::output);
UiNode ui_node;
ui_node.type = UiNodeType::output;
ui_node.output.r = graph_.insert_node(value);
ui_node.output.g = graph_.insert_node(value);
ui_node.output.b = graph_.insert_node(value);
ui_node.id = graph_.insert_node(out);
graph_.insert_edge(ui_node.id, ui_node.output.r);
graph_.insert_edge(ui_node.id, ui_node.output.g);
graph_.insert_edge(ui_node.id, ui_node.output.b);
nodes_.push_back(ui_node);
ImNodes::SetNodeScreenSpacePos(ui_node.id, click_pos);
root_node_id_ = ui_node.id;
}
if (ImGui::MenuItem("sine"))
{
const Node value(NodeType::value, 0.f);
const Node op(NodeType::sine);
UiNode ui_node;
ui_node.type = UiNodeType::sine;
ui_node.sine.input = graph_.insert_node(value);
ui_node.id = graph_.insert_node(op);
graph_.insert_edge(ui_node.id, ui_node.sine.input);
nodes_.push_back(ui_node);
ImNodes::SetNodeScreenSpacePos(ui_node.id, click_pos);
}
if (ImGui::MenuItem("time"))
{
UiNode ui_node;
ui_node.type = UiNodeType::time;
ui_node.id = graph_.insert_node(Node(NodeType::time));
nodes_.push_back(ui_node);
ImNodes::SetNodeScreenSpacePos(ui_node.id, click_pos);
}
ImGui::EndPopup();
}
ImGui::PopStyleVar();
}
for (const UiNode& node : nodes_)
{
switch (node.type)
{
case UiNodeType::add:
{
const float node_width = 100.f;
ImNodes::BeginNode(node.id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("add");
ImNodes::EndNodeTitleBar();
{
ImNodes::BeginInputAttribute(node.add.lhs);
const float label_width = ImGui::CalcTextSize("left").x;
ImGui::TextUnformatted("left");
if (graph_.num_edges_from_node(node.add.lhs) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat("##hidelabel", &graph_.node(node.add.lhs).value, 0.01f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
{
ImNodes::BeginInputAttribute(node.add.rhs);
const float label_width = ImGui::CalcTextSize("right").x;
ImGui::TextUnformatted("right");
if (graph_.num_edges_from_node(node.add.rhs) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat("##hidelabel", &graph_.node(node.add.rhs).value, 0.01f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
ImGui::Spacing();
{
ImNodes::BeginOutputAttribute(node.id);
const float label_width = ImGui::CalcTextSize("result").x;
ImGui::Indent(node_width - label_width);
ImGui::TextUnformatted("result");
ImNodes::EndOutputAttribute();
}
ImNodes::EndNode();
}
break;
case UiNodeType::multiply:
{
const float node_width = 100.0f;
ImNodes::BeginNode(node.id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("multiply");
ImNodes::EndNodeTitleBar();
{
ImNodes::BeginInputAttribute(node.multiply.lhs);
const float label_width = ImGui::CalcTextSize("left").x;
ImGui::TextUnformatted("left");
if (graph_.num_edges_from_node(node.multiply.lhs) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat(
"##hidelabel", &graph_.node(node.multiply.lhs).value, 0.01f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
{
ImNodes::BeginInputAttribute(node.multiply.rhs);
const float label_width = ImGui::CalcTextSize("right").x;
ImGui::TextUnformatted("right");
if (graph_.num_edges_from_node(node.multiply.rhs) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat(
"##hidelabel", &graph_.node(node.multiply.rhs).value, 0.01f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
ImGui::Spacing();
{
ImNodes::BeginOutputAttribute(node.id);
const float label_width = ImGui::CalcTextSize("result").x;
ImGui::Indent(node_width - label_width);
ImGui::TextUnformatted("result");
ImNodes::EndOutputAttribute();
}
ImNodes::EndNode();
}
break;
case UiNodeType::output:
{
const float node_width = 100.0f;
ImNodes::PushColorStyle(ImNodesCol_TitleBar, IM_COL32(11, 109, 191, 255));
ImNodes::PushColorStyle(ImNodesCol_TitleBarHovered, IM_COL32(45, 126, 194, 255));
ImNodes::PushColorStyle(ImNodesCol_TitleBarSelected, IM_COL32(81, 148, 204, 255));
ImNodes::BeginNode(node.id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("output");
ImNodes::EndNodeTitleBar();
ImGui::Dummy(ImVec2(node_width, 0.f));
{
ImNodes::BeginInputAttribute(node.output.r);
const float label_width = ImGui::CalcTextSize("r").x;
ImGui::TextUnformatted("r");
if (graph_.num_edges_from_node(node.output.r) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat(
"##hidelabel", &graph_.node(node.output.r).value, 0.01f, 0.f, 1.0f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
ImGui::Spacing();
{
ImNodes::BeginInputAttribute(node.output.g);
const float label_width = ImGui::CalcTextSize("g").x;
ImGui::TextUnformatted("g");
if (graph_.num_edges_from_node(node.output.g) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat(
"##hidelabel", &graph_.node(node.output.g).value, 0.01f, 0.f, 1.f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
ImGui::Spacing();
{
ImNodes::BeginInputAttribute(node.output.b);
const float label_width = ImGui::CalcTextSize("b").x;
ImGui::TextUnformatted("b");
if (graph_.num_edges_from_node(node.output.b) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat(
"##hidelabel", &graph_.node(node.output.b).value, 0.01f, 0.f, 1.0f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
ImNodes::EndNode();
ImNodes::PopColorStyle();
ImNodes::PopColorStyle();
ImNodes::PopColorStyle();
}
break;
case UiNodeType::sine:
{
const float node_width = 100.0f;
ImNodes::BeginNode(node.id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("sine");
ImNodes::EndNodeTitleBar();
{
ImNodes::BeginInputAttribute(node.sine.input);
const float label_width = ImGui::CalcTextSize("number").x;
ImGui::TextUnformatted("number");
if (graph_.num_edges_from_node(node.sine.input) == 0ull)
{
ImGui::SameLine();
ImGui::PushItemWidth(node_width - label_width);
ImGui::DragFloat(
"##hidelabel", &graph_.node(node.sine.input).value, 0.01f, 0.f, 1.0f);
ImGui::PopItemWidth();
}
ImNodes::EndInputAttribute();
}
ImGui::Spacing();
{
ImNodes::BeginOutputAttribute(node.id);
const float label_width = ImGui::CalcTextSize("output").x;
ImGui::Indent(node_width - label_width);
ImGui::TextUnformatted("output");
ImNodes::EndInputAttribute();
}
ImNodes::EndNode();
}
break;
case UiNodeType::time:
{
ImNodes::BeginNode(node.id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("time");
ImNodes::EndNodeTitleBar();
ImNodes::BeginOutputAttribute(node.id);
ImGui::Text("output");
ImNodes::EndOutputAttribute();
ImNodes::EndNode();
}
break;
}
}
for (const auto& edge : graph_.edges())
{
// If edge doesn't start at value, then it's an internal edge, i.e.
// an edge which links a node's operation to its input. We don't
// want to render node internals with visible links.
if (graph_.node(edge.from).type != NodeType::value)
continue;
ImNodes::Link(edge.id, edge.from, edge.to);
}
ImNodes::MiniMap(0.2f, minimap_location_);
ImNodes::EndNodeEditor();
// Handle new links
// These are driven by Imnodes, so we place the code after EndNodeEditor().
{
int start_attr, end_attr;
if (ImNodes::IsLinkCreated(&start_attr, &end_attr))
{
const NodeType start_type = graph_.node(start_attr).type;
const NodeType end_type = graph_.node(end_attr).type;
const bool valid_link = start_type != end_type;
if (valid_link)
{
// Ensure the edge is always directed from the value to
// whatever produces the value
if (start_type != NodeType::value)
{
std::swap(start_attr, end_attr);
}
graph_.insert_edge(start_attr, end_attr);
}
}
}
// Handle deleted links
{
int link_id;
if (ImNodes::IsLinkDestroyed(&link_id))
{
graph_.erase_edge(link_id);
}
}
{
const int num_selected = ImNodes::NumSelectedLinks();
if (num_selected > 0 && ImGui::IsKeyReleased(SDL_SCANCODE_X))
{
static std::vector<int> selected_links;
selected_links.resize(static_cast<size_t>(num_selected));
ImNodes::GetSelectedLinks(selected_links.data());
for (const int edge_id : selected_links)
{
graph_.erase_edge(edge_id);
}
}
}
{
const int num_selected = ImNodes::NumSelectedNodes();
if (num_selected > 0 && ImGui::IsKeyReleased(SDL_SCANCODE_X))
{
static std::vector<int> selected_nodes;
selected_nodes.resize(static_cast<size_t>(num_selected));
ImNodes::GetSelectedNodes(selected_nodes.data());
for (const int node_id : selected_nodes)
{
graph_.erase_node(node_id);
auto iter = std::find_if(
nodes_.begin(), nodes_.end(), [node_id](const UiNode& node) -> bool {
return node.id == node_id;
});
// Erase any additional internal nodes
switch (iter->type)
{
case UiNodeType::add:
graph_.erase_node(iter->add.lhs);
graph_.erase_node(iter->add.rhs);
break;
case UiNodeType::multiply:
graph_.erase_node(iter->multiply.lhs);
graph_.erase_node(iter->multiply.rhs);
break;
case UiNodeType::output:
graph_.erase_node(iter->output.r);
graph_.erase_node(iter->output.g);
graph_.erase_node(iter->output.b);
root_node_id_ = -1;
break;
case UiNodeType::sine:
graph_.erase_node(iter->sine.input);
break;
default:
break;
}
nodes_.erase(iter);
}
}
}
ImGui::End();
// The color output window
const ImU32 color =
root_node_id_ != -1 ? evaluate(graph_, root_node_id_) : IM_COL32(255, 20, 147, 255);
ImGui::PushStyleColor(ImGuiCol_WindowBg, color);
ImGui::Begin("output color");
ImGui::End();
ImGui::PopStyleColor();
}
private:
enum class UiNodeType
{
add,
multiply,
output,
sine,
time,
};
struct UiNode
{
UiNodeType type;
// The identifying id of the ui node. For add, multiply, sine, and time
// this is the "operation" node id. The additional input nodes are
// stored in the structs.
int id;
union
{
struct
{
int lhs, rhs;
} add;
struct
{
int lhs, rhs;
} multiply;
struct
{
int r, g, b;
} output;
struct
{
int input;
} sine;
};
};
Graph<Node> graph_;
std::vector<UiNode> nodes_;
int root_node_id_;
ImNodesMiniMapLocation minimap_location_;
};
static ColorNodeEditor color_editor;
} // namespace
void NodeEditorInitialize()
{
ImNodesIO& io = ImNodes::GetIO();
io.LinkDetachWithModifierClick.Modifier = &ImGui::GetIO().KeyCtrl;
}
void NodeEditorShow() { color_editor.show(); }
void NodeEditorShutdown() {}
} // namespace example

357
3rdparty/imnodes/example/graph.h vendored Normal file
View File

@ -0,0 +1,357 @@
#pragma once
#include <algorithm>
#include <cassert>
#include <iterator>
#include <stack>
#include <stddef.h>
#include <utility>
#include <vector>
namespace example
{
template<typename ElementType>
struct Span
{
using iterator = ElementType*;
template<typename Container>
Span(Container& c) : begin_(c.data()), end_(begin_ + c.size())
{
}
iterator begin() const { return begin_; }
iterator end() const { return end_; }
private:
iterator begin_;
iterator end_;
};
template<typename ElementType>
class IdMap
{
public:
using iterator = typename std::vector<ElementType>::iterator;
using const_iterator = typename std::vector<ElementType>::const_iterator;
// Iterators
const_iterator begin() const { return elements_.begin(); }
const_iterator end() const { return elements_.end(); }
// Element access
Span<const ElementType> elements() const { return elements_; }
// Capacity
bool empty() const { return sorted_ids_.empty(); }
size_t size() const { return sorted_ids_.size(); }
// Modifiers
std::pair<iterator, bool> insert(int id, const ElementType& element);
std::pair<iterator, bool> insert(int id, ElementType&& element);
size_t erase(int id);
void clear();
// Lookup
iterator find(int id);
const_iterator find(int id) const;
bool contains(int id) const;
private:
std::vector<ElementType> elements_;
std::vector<int> sorted_ids_;
};
template<typename ElementType>
std::pair<typename IdMap<ElementType>::iterator, bool> IdMap<ElementType>::insert(
const int id,
const ElementType& element)
{
auto lower_bound = std::lower_bound(sorted_ids_.begin(), sorted_ids_.end(), id);
if (lower_bound != sorted_ids_.end() && id == *lower_bound)
{
return std::make_pair(
std::next(elements_.begin(), std::distance(sorted_ids_.begin(), lower_bound)), false);
}
auto insert_element_at =
std::next(elements_.begin(), std::distance(sorted_ids_.begin(), lower_bound));
sorted_ids_.insert(lower_bound, id);
return std::make_pair(elements_.insert(insert_element_at, element), true);
}
template<typename ElementType>
std::pair<typename IdMap<ElementType>::iterator, bool> IdMap<ElementType>::insert(
const int id,
ElementType&& element)
{
auto lower_bound = std::lower_bound(sorted_ids_.begin(), sorted_ids_.end(), id);
if (lower_bound != sorted_ids_.end() && id == *lower_bound)
{
return std::make_pair(
std::next(elements_.begin(), std::distance(sorted_ids_.begin(), lower_bound)), false);
}
auto insert_element_at =
std::next(elements_.begin(), std::distance(sorted_ids_.begin(), lower_bound));
sorted_ids_.insert(lower_bound, id);
return std::make_pair(elements_.insert(insert_element_at, std::move(element)), true);
}
template<typename ElementType>
size_t IdMap<ElementType>::erase(const int id)
{
auto lower_bound = std::lower_bound(sorted_ids_.begin(), sorted_ids_.end(), id);
if (lower_bound == sorted_ids_.end() || id != *lower_bound)
{
return 0ull;
}
auto erase_element_at =
std::next(elements_.begin(), std::distance(sorted_ids_.begin(), lower_bound));
sorted_ids_.erase(lower_bound);
elements_.erase(erase_element_at);
return 1ull;
}
template<typename ElementType>
void IdMap<ElementType>::clear()
{
elements_.clear();
sorted_ids_.clear();
}
template<typename ElementType>
typename IdMap<ElementType>::iterator IdMap<ElementType>::find(const int id)
{
const auto lower_bound = std::lower_bound(sorted_ids_.cbegin(), sorted_ids_.cend(), id);
return (lower_bound == sorted_ids_.cend() || *lower_bound != id)
? elements_.end()
: std::next(elements_.begin(), std::distance(sorted_ids_.cbegin(), lower_bound));
}
template<typename ElementType>
typename IdMap<ElementType>::const_iterator IdMap<ElementType>::find(const int id) const
{
const auto lower_bound = std::lower_bound(sorted_ids_.cbegin(), sorted_ids_.cend(), id);
return (lower_bound == sorted_ids_.cend() || *lower_bound != id)
? elements_.cend()
: std::next(elements_.cbegin(), std::distance(sorted_ids_.cbegin(), lower_bound));
}
template<typename ElementType>
bool IdMap<ElementType>::contains(const int id) const
{
const auto lower_bound = std::lower_bound(sorted_ids_.cbegin(), sorted_ids_.cend(), id);
if (lower_bound == sorted_ids_.cend())
{
return false;
}
return *lower_bound == id;
}
// a very simple directional graph
template<typename NodeType>
class Graph
{
public:
Graph() : current_id_(0), nodes_(), edges_from_node_(), node_neighbors_(), edges_() {}
struct Edge
{
int id;
int from, to;
Edge() = default;
Edge(const int id, const int f, const int t) : id(id), from(f), to(t) {}
inline int opposite(const int n) const { return n == from ? to : from; }
inline bool contains(const int n) const { return n == from || n == to; }
};
// Element access
NodeType& node(int node_id);
const NodeType& node(int node_id) const;
Span<const int> neighbors(int node_id) const;
Span<const Edge> edges() const;
// Capacity
size_t num_edges_from_node(int node_id) const;
// Modifiers
int insert_node(const NodeType& node);
void erase_node(int node_id);
int insert_edge(int from, int to);
void erase_edge(int edge_id);
private:
int current_id_;
// These contains map to the node id
IdMap<NodeType> nodes_;
IdMap<int> edges_from_node_;
IdMap<std::vector<int>> node_neighbors_;
// This container maps to the edge id
IdMap<Edge> edges_;
};
template<typename NodeType>
NodeType& Graph<NodeType>::node(const int id)
{
return const_cast<NodeType&>(static_cast<const Graph*>(this)->node(id));
}
template<typename NodeType>
const NodeType& Graph<NodeType>::node(const int id) const
{
const auto iter = nodes_.find(id);
assert(iter != nodes_.end());
return *iter;
}
template<typename NodeType>
Span<const int> Graph<NodeType>::neighbors(int node_id) const
{
const auto iter = node_neighbors_.find(node_id);
assert(iter != node_neighbors_.end());
return *iter;
}
template<typename NodeType>
Span<const typename Graph<NodeType>::Edge> Graph<NodeType>::edges() const
{
return edges_.elements();
}
template<typename NodeType>
size_t Graph<NodeType>::num_edges_from_node(const int id) const
{
auto iter = edges_from_node_.find(id);
assert(iter != edges_from_node_.end());
return *iter;
}
template<typename NodeType>
int Graph<NodeType>::insert_node(const NodeType& node)
{
const int id = current_id_++;
assert(!nodes_.contains(id));
nodes_.insert(id, node);
edges_from_node_.insert(id, 0);
node_neighbors_.insert(id, std::vector<int>());
return id;
}
template<typename NodeType>
void Graph<NodeType>::erase_node(const int id)
{
// first, remove any potential dangling edges
{
static std::vector<int> edges_to_erase;
for (const Edge& edge : edges_.elements())
{
if (edge.contains(id))
{
edges_to_erase.push_back(edge.id);
}
}
for (const int edge_id : edges_to_erase)
{
erase_edge(edge_id);
}
edges_to_erase.clear();
}
nodes_.erase(id);
edges_from_node_.erase(id);
node_neighbors_.erase(id);
}
template<typename NodeType>
int Graph<NodeType>::insert_edge(const int from, const int to)
{
const int id = current_id_++;
assert(!edges_.contains(id));
assert(nodes_.contains(from));
assert(nodes_.contains(to));
edges_.insert(id, Edge(id, from, to));
// update neighbor count
assert(edges_from_node_.contains(from));
*edges_from_node_.find(from) += 1;
// update neighbor list
assert(node_neighbors_.contains(from));
node_neighbors_.find(from)->push_back(to);
return id;
}
template<typename NodeType>
void Graph<NodeType>::erase_edge(const int edge_id)
{
// This is a bit lazy, we find the pointer here, but we refind it when we erase the edge based
// on id key.
assert(edges_.contains(edge_id));
const Edge& edge = *edges_.find(edge_id);
// update neighbor count
assert(edges_from_node_.contains(edge.from));
int& edge_count = *edges_from_node_.find(edge.from);
assert(edge_count > 0);
edge_count -= 1;
// update neighbor list
{
assert(node_neighbors_.contains(edge.from));
auto neighbors = node_neighbors_.find(edge.from);
auto iter = std::find(neighbors->begin(), neighbors->end(), edge.to);
assert(iter != neighbors->end());
neighbors->erase(iter);
}
edges_.erase(edge_id);
}
template<typename NodeType, typename Visitor>
void dfs_traverse(const Graph<NodeType>& graph, const int start_node, Visitor visitor)
{
std::stack<int> stack;
stack.push(start_node);
while (!stack.empty())
{
const int current_node = stack.top();
stack.pop();
visitor(current_node);
for (const int neighbor : graph.neighbors(current_node))
{
stack.push(neighbor);
}
}
}
} // namespace example

48
3rdparty/imnodes/example/hello.cpp vendored Normal file
View File

@ -0,0 +1,48 @@
#include "node_editor.h"
#include <imnodes.h>
#include <imgui.h>
namespace example
{
namespace
{
class HelloWorldNodeEditor
{
public:
void show()
{
ImGui::Begin("simple node editor");
ImNodes::BeginNodeEditor();
ImNodes::BeginNode(1);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("simple node :)");
ImNodes::EndNodeTitleBar();
ImNodes::BeginInputAttribute(2);
ImGui::Text("input");
ImNodes::EndInputAttribute();
ImNodes::BeginOutputAttribute(3);
ImGui::Indent(40);
ImGui::Text("output");
ImNodes::EndOutputAttribute();
ImNodes::EndNode();
ImNodes::EndNodeEditor();
ImGui::End();
}
};
static HelloWorldNodeEditor editor;
} // namespace
void NodeEditorInitialize() { ImNodes::SetNodeGridSpacePos(1, ImVec2(200.0f, 200.0f)); }
void NodeEditorShow() { editor.show(); }
void NodeEditorShutdown() {}
} // namespace example

128
3rdparty/imnodes/example/main.cpp vendored Normal file
View File

@ -0,0 +1,128 @@
#include "node_editor.h"
#include <imgui.h>
#include <imgui_impl_sdl.h>
#include <imgui_impl_opengl3.h>
#include <imnodes.h>
#include <stdio.h>
#include <SDL.h>
#include <GL/gl3w.h>
int main(int, char**)
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
{
printf("Error: %s\n", SDL_GetError());
return -1;
}
#if __APPLE__
// GL 3.2 Core + GLSL 150
const char* glsl_version = "#version 150";
SDL_GL_SetAttribute(
SDL_GL_CONTEXT_FLAGS,
SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#else
// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_DisplayMode current;
SDL_GetCurrentDisplayMode(0, &current);
SDL_Window* window = SDL_CreateWindow(
"imgui-node-editor example",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
1280,
720,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
if (gl3wInit())
{
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
return 1;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
ImGui_ImplOpenGL3_Init(glsl_version);
ImNodes::CreateContext();
// Setup style
ImGui::StyleColorsDark();
ImNodes::StyleColorsDark();
bool done = false;
bool initialized = false;
{
const ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
}
while (!done)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT)
done = true;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE &&
event.window.windowID == SDL_GetWindowID(window))
done = true;
}
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
if (!initialized)
{
initialized = true;
example::NodeEditorInitialize();
}
example::NodeEditorShow();
// Rendering
ImGui::Render();
int fb_width, fb_height;
SDL_GL_GetDrawableSize(window, &fb_width, &fb_height);
glViewport(0, 0, fb_width, fb_height);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window);
}
example::NodeEditorShutdown();
ImNodes::DestroyContext();
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_GL_DeleteContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}

View File

@ -0,0 +1,137 @@
#include "node_editor.h"
#include <imnodes.h>
#include <imgui.h>
#include <SDL_scancode.h>
#include <algorithm>
#include <vector>
namespace example
{
namespace
{
struct Node
{
int id;
float value;
Node(const int i, const float v) : id(i), value(v) {}
};
struct Link
{
int id;
int start_attr, end_attr;
};
struct Editor
{
ImNodesEditorContext* context = nullptr;
std::vector<Node> nodes;
std::vector<Link> links;
int current_id = 0;
};
void show_editor(const char* editor_name, Editor& editor)
{
ImNodes::EditorContextSet(editor.context);
ImGui::Begin(editor_name);
ImGui::TextUnformatted("A -- add node");
ImNodes::BeginNodeEditor();
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
ImNodes::IsEditorHovered() && ImGui::IsKeyReleased(SDL_SCANCODE_A))
{
const int node_id = ++editor.current_id;
ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos());
editor.nodes.push_back(Node(node_id, 0.f));
}
for (Node& node : editor.nodes)
{
ImNodes::BeginNode(node.id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("node");
ImNodes::EndNodeTitleBar();
ImNodes::BeginInputAttribute(node.id << 8);
ImGui::TextUnformatted("input");
ImNodes::EndInputAttribute();
ImNodes::BeginStaticAttribute(node.id << 16);
ImGui::PushItemWidth(120.0f);
ImGui::DragFloat("value", &node.value, 0.01f);
ImGui::PopItemWidth();
ImNodes::EndStaticAttribute();
ImNodes::BeginOutputAttribute(node.id << 24);
const float text_width = ImGui::CalcTextSize("output").x;
ImGui::Indent(120.f + ImGui::CalcTextSize("value").x - text_width);
ImGui::TextUnformatted("output");
ImNodes::EndOutputAttribute();
ImNodes::EndNode();
}
for (const Link& link : editor.links)
{
ImNodes::Link(link.id, link.start_attr, link.end_attr);
}
ImNodes::EndNodeEditor();
{
Link link;
if (ImNodes::IsLinkCreated(&link.start_attr, &link.end_attr))
{
link.id = ++editor.current_id;
editor.links.push_back(link);
}
}
{
int link_id;
if (ImNodes::IsLinkDestroyed(&link_id))
{
auto iter = std::find_if(
editor.links.begin(), editor.links.end(), [link_id](const Link& link) -> bool {
return link.id == link_id;
});
assert(iter != editor.links.end());
editor.links.erase(iter);
}
}
ImGui::End();
}
Editor editor1;
Editor editor2;
} // namespace
void NodeEditorInitialize()
{
editor1.context = ImNodes::EditorContextCreate();
editor2.context = ImNodes::EditorContextCreate();
ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick);
ImNodesIO& io = ImNodes::GetIO();
io.LinkDetachWithModifierClick.Modifier = &ImGui::GetIO().KeyCtrl;
}
void NodeEditorShow()
{
show_editor("editor1", editor1);
show_editor("editor2", editor2);
}
void NodeEditorShutdown()
{
ImNodes::PopAttributeFlag();
ImNodes::EditorContextFree(editor1.context);
ImNodes::EditorContextFree(editor2.context);
}
} // namespace example

View File

@ -0,0 +1,8 @@
#pragma once
namespace example
{
void NodeEditorInitialize();
void NodeEditorShow();
void NodeEditorShutdown();
} // namespace example

206
3rdparty/imnodes/example/save_load.cpp vendored Normal file
View File

@ -0,0 +1,206 @@
#include "node_editor.h"
#include <imnodes.h>
#include <imgui.h>
#include <SDL_keycode.h>
#include <algorithm>
#include <cassert>
#include <fstream>
#include <ios> // for std::streamsize
#include <stddef.h>
#include <vector>
namespace example
{
namespace
{
struct Node
{
int id;
float value;
Node() = default;
Node(const int i, const float v) : id(i), value(v) {}
};
struct Link
{
int id;
int start_attr, end_attr;
};
class SaveLoadEditor
{
public:
SaveLoadEditor() : nodes_(), links_(), current_id_(0) {}
void show()
{
ImGui::Begin("Save & load example");
ImGui::TextUnformatted("A -- add node");
ImGui::TextUnformatted(
"Close the executable and rerun it -- your nodes should be exactly "
"where you left them!");
ImNodes::BeginNodeEditor();
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
ImNodes::IsEditorHovered() && ImGui::IsKeyReleased(SDL_SCANCODE_A))
{
const int node_id = ++current_id_;
ImNodes::SetNodeScreenSpacePos(node_id, ImGui::GetMousePos());
nodes_.push_back(Node(node_id, 0.f));
}
for (Node& node : nodes_)
{
ImNodes::BeginNode(node.id);
ImNodes::BeginNodeTitleBar();
ImGui::TextUnformatted("node");
ImNodes::EndNodeTitleBar();
ImNodes::BeginInputAttribute(node.id << 8);
ImGui::TextUnformatted("input");
ImNodes::EndInputAttribute();
ImNodes::BeginStaticAttribute(node.id << 16);
ImGui::PushItemWidth(120.f);
ImGui::DragFloat("value", &node.value, 0.01f);
ImGui::PopItemWidth();
ImNodes::EndStaticAttribute();
ImNodes::BeginOutputAttribute(node.id << 24);
const float text_width = ImGui::CalcTextSize("output").x;
ImGui::Indent(120.f + ImGui::CalcTextSize("value").x - text_width);
ImGui::TextUnformatted("output");
ImNodes::EndOutputAttribute();
ImNodes::EndNode();
}
for (const Link& link : links_)
{
ImNodes::Link(link.id, link.start_attr, link.end_attr);
}
ImNodes::EndNodeEditor();
{
Link link;
if (ImNodes::IsLinkCreated(&link.start_attr, &link.end_attr))
{
link.id = ++current_id_;
links_.push_back(link);
}
}
{
int link_id;
if (ImNodes::IsLinkDestroyed(&link_id))
{
auto iter =
std::find_if(links_.begin(), links_.end(), [link_id](const Link& link) -> bool {
return link.id == link_id;
});
assert(iter != links_.end());
links_.erase(iter);
}
}
ImGui::End();
}
void save()
{
// Save the internal imnodes state
ImNodes::SaveCurrentEditorStateToIniFile("save_load.ini");
// Dump our editor state as bytes into a file
std::fstream fout(
"save_load.bytes", std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
// copy the node vector to file
const size_t num_nodes = nodes_.size();
fout.write(
reinterpret_cast<const char*>(&num_nodes),
static_cast<std::streamsize>(sizeof(size_t)));
fout.write(
reinterpret_cast<const char*>(nodes_.data()),
static_cast<std::streamsize>(sizeof(Node) * num_nodes));
// copy the link vector to file
const size_t num_links = links_.size();
fout.write(
reinterpret_cast<const char*>(&num_links),
static_cast<std::streamsize>(sizeof(size_t)));
fout.write(
reinterpret_cast<const char*>(links_.data()),
static_cast<std::streamsize>(sizeof(Link) * num_links));
// copy the current_id to file
fout.write(
reinterpret_cast<const char*>(&current_id_), static_cast<std::streamsize>(sizeof(int)));
}
void load()
{
// Load the internal imnodes state
ImNodes::LoadCurrentEditorStateFromIniFile("save_load.ini");
// Load our editor state into memory
std::fstream fin("save_load.bytes", std::ios_base::in | std::ios_base::binary);
if (!fin.is_open())
{
return;
}
// copy nodes into memory
size_t num_nodes;
fin.read(reinterpret_cast<char*>(&num_nodes), static_cast<std::streamsize>(sizeof(size_t)));
nodes_.resize(num_nodes);
fin.read(
reinterpret_cast<char*>(nodes_.data()),
static_cast<std::streamsize>(sizeof(Node) * num_nodes));
// copy links into memory
size_t num_links;
fin.read(reinterpret_cast<char*>(&num_links), static_cast<std::streamsize>(sizeof(size_t)));
links_.resize(num_links);
fin.read(
reinterpret_cast<char*>(links_.data()),
static_cast<std::streamsize>(sizeof(Link) * num_links));
// copy current_id into memory
fin.read(reinterpret_cast<char*>(&current_id_), static_cast<std::streamsize>(sizeof(int)));
}
private:
std::vector<Node> nodes_;
std::vector<Link> links_;
int current_id_;
};
static SaveLoadEditor editor;
} // namespace
void NodeEditorInitialize()
{
ImNodes::GetIO().LinkDetachWithModifierClick.Modifier = &ImGui::GetIO().KeyCtrl;
ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick);
editor.load();
}
void NodeEditorShow() { editor.show(); }
void NodeEditorShutdown()
{
ImNodes::PopAttributeFlag();
editor.save();
}
} // namespace example

BIN
3rdparty/imnodes/img/imnodes.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

3182
3rdparty/imnodes/imnodes.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

416
3rdparty/imnodes/imnodes.h vendored Normal file
View File

@ -0,0 +1,416 @@
#pragma once
#include <stddef.h>
#include <imgui.h>
#ifdef IMNODES_USER_CONFIG
#include IMNODES_USER_CONFIG
#endif
#ifndef IMNODES_NAMESPACE
#define IMNODES_NAMESPACE ImNodes
#endif
typedef int ImNodesCol; // -> enum ImNodesCol_
typedef int ImNodesStyleVar; // -> enum ImNodesStyleVar_
typedef int ImNodesStyleFlags; // -> enum ImNodesStyleFlags_
typedef int ImNodesPinShape; // -> enum ImNodesPinShape_
typedef int ImNodesAttributeFlags; // -> enum ImNodesAttributeFlags_
typedef int ImNodesMiniMapLocation; // -> enum ImNodesMiniMapLocation_
enum ImNodesCol_
{
ImNodesCol_NodeBackground = 0,
ImNodesCol_NodeBackgroundHovered,
ImNodesCol_NodeBackgroundSelected,
ImNodesCol_NodeOutline,
ImNodesCol_TitleBar,
ImNodesCol_TitleBarHovered,
ImNodesCol_TitleBarSelected,
ImNodesCol_Link,
ImNodesCol_LinkHovered,
ImNodesCol_LinkSelected,
ImNodesCol_Pin,
ImNodesCol_PinHovered,
ImNodesCol_BoxSelector,
ImNodesCol_BoxSelectorOutline,
ImNodesCol_GridBackground,
ImNodesCol_GridLine,
ImNodesCol_MiniMapBackground,
ImNodesCol_MiniMapBackgroundHovered,
ImNodesCol_MiniMapOutline,
ImNodesCol_MiniMapOutlineHovered,
ImNodesCol_MiniMapNodeBackground,
ImNodesCol_MiniMapNodeBackgroundHovered,
ImNodesCol_MiniMapNodeBackgroundSelected,
ImNodesCol_MiniMapNodeOutline,
ImNodesCol_MiniMapLink,
ImNodesCol_MiniMapLinkSelected,
ImNodesCol_MiniMapCanvas,
ImNodesCol_MiniMapCanvasOutline,
ImNodesCol_COUNT
};
enum ImNodesStyleVar_
{
ImNodesStyleVar_GridSpacing = 0,
ImNodesStyleVar_NodeCornerRounding,
ImNodesStyleVar_NodePadding,
ImNodesStyleVar_NodeBorderThickness,
ImNodesStyleVar_LinkThickness,
ImNodesStyleVar_LinkLineSegmentsPerLength,
ImNodesStyleVar_LinkHoverDistance,
ImNodesStyleVar_PinCircleRadius,
ImNodesStyleVar_PinQuadSideLength,
ImNodesStyleVar_PinTriangleSideLength,
ImNodesStyleVar_PinLineThickness,
ImNodesStyleVar_PinHoverRadius,
ImNodesStyleVar_PinOffset,
ImNodesStyleVar_MiniMapPadding,
ImNodesStyleVar_MiniMapOffset,
ImNodesStyleVar_COUNT
};
enum ImNodesStyleFlags_
{
ImNodesStyleFlags_None = 0,
ImNodesStyleFlags_NodeOutline = 1 << 0,
ImNodesStyleFlags_GridLines = 1 << 2
};
enum ImNodesPinShape_
{
ImNodesPinShape_Circle,
ImNodesPinShape_CircleFilled,
ImNodesPinShape_Triangle,
ImNodesPinShape_TriangleFilled,
ImNodesPinShape_Quad,
ImNodesPinShape_QuadFilled
};
// This enum controls the way the attribute pins behave.
enum ImNodesAttributeFlags_
{
ImNodesAttributeFlags_None = 0,
// Allow detaching a link by left-clicking and dragging the link at a pin it is connected to.
// NOTE: the user has to actually delete the link for this to work. A deleted link can be
// detected by calling IsLinkDestroyed() after EndNodeEditor().
ImNodesAttributeFlags_EnableLinkDetachWithDragClick = 1 << 0,
// Visual snapping of an in progress link will trigger IsLink Created/Destroyed events. Allows
// for previewing the creation of a link while dragging it across attributes. See here for demo:
// https://github.com/Nelarius/imnodes/issues/41#issuecomment-647132113 NOTE: the user has to
// actually delete the link for this to work. A deleted link can be detected by calling
// IsLinkDestroyed() after EndNodeEditor().
ImNodesAttributeFlags_EnableLinkCreationOnSnap = 1 << 1
};
struct ImNodesIO
{
struct EmulateThreeButtonMouse
{
EmulateThreeButtonMouse();
// The keyboard modifier to use in combination with mouse left click to pan the editor view.
// Set to NULL by default. To enable this feature, set the modifier to point to a boolean
// indicating the state of a modifier. For example,
//
// ImNodes::GetIO().EmulateThreeButtonMouse.Modifier = &ImGui::GetIO().KeyAlt;
const bool* Modifier;
} EmulateThreeButtonMouse;
struct LinkDetachWithModifierClick
{
LinkDetachWithModifierClick();
// Pointer to a boolean value indicating when the desired modifier is pressed. Set to NULL
// by default. To enable the feature, set the modifier to point to a boolean indicating the
// state of a modifier. For example,
//
// ImNodes::GetIO().LinkDetachWithModifierClick.Modifier = &ImGui::GetIO().KeyCtrl;
//
// Left-clicking a link with this modifier pressed will detach that link. NOTE: the user has
// to actually delete the link for this to work. A deleted link can be detected by calling
// IsLinkDestroyed() after EndNodeEditor().
const bool* Modifier;
} LinkDetachWithModifierClick;
// Holding alt mouse button pans the node area, by default middle mouse button will be used
// Set based on ImGuiMouseButton values
int AltMouseButton;
// Panning speed when dragging an element and mouse is outside the main editor view.
float AutoPanningSpeed;
ImNodesIO();
};
struct ImNodesStyle
{
float GridSpacing;
float NodeCornerRounding;
ImVec2 NodePadding;
float NodeBorderThickness;
float LinkThickness;
float LinkLineSegmentsPerLength;
float LinkHoverDistance;
// The following variables control the look and behavior of the pins. The default size of each
// pin shape is balanced to occupy approximately the same surface area on the screen.
// The circle radius used when the pin shape is either ImNodesPinShape_Circle or
// ImNodesPinShape_CircleFilled.
float PinCircleRadius;
// The quad side length used when the shape is either ImNodesPinShape_Quad or
// ImNodesPinShape_QuadFilled.
float PinQuadSideLength;
// The equilateral triangle side length used when the pin shape is either
// ImNodesPinShape_Triangle or ImNodesPinShape_TriangleFilled.
float PinTriangleSideLength;
// The thickness of the line used when the pin shape is not filled.
float PinLineThickness;
// The radius from the pin's center position inside of which it is detected as being hovered
// over.
float PinHoverRadius;
// Offsets the pins' positions from the edge of the node to the outside of the node.
float PinOffset;
// Mini-map padding size between mini-map edge and mini-map content.
ImVec2 MiniMapPadding;
// Mini-map offset from the screen side.
ImVec2 MiniMapOffset;
// By default, ImNodesStyleFlags_NodeOutline and ImNodesStyleFlags_Gridlines are enabled.
ImNodesStyleFlags Flags;
// Set these mid-frame using Push/PopColorStyle. You can index this color array with with a
// ImNodesCol value.
unsigned int Colors[ImNodesCol_COUNT];
ImNodesStyle();
};
enum ImNodesMiniMapLocation_
{
ImNodesMiniMapLocation_BottomLeft,
ImNodesMiniMapLocation_BottomRight,
ImNodesMiniMapLocation_TopLeft,
ImNodesMiniMapLocation_TopRight,
};
struct ImGuiContext;
struct ImVec2;
struct ImNodesContext;
// An editor context corresponds to a set of nodes in a single workspace (created with a single
// Begin/EndNodeEditor pair)
//
// By default, the library creates an editor context behind the scenes, so using any of the imnodes
// functions doesn't require you to explicitly create a context.
struct ImNodesEditorContext;
// Callback type used to specify special behavior when hovering a node in the minimap
#ifndef ImNodesMiniMapNodeHoveringCallback
typedef void (*ImNodesMiniMapNodeHoveringCallback)(int, void*);
#endif
#ifndef ImNodesMiniMapNodeHoveringCallbackUserData
typedef void* ImNodesMiniMapNodeHoveringCallbackUserData;
#endif
namespace IMNODES_NAMESPACE
{
// Call this function if you are compiling imnodes in to a dll, separate from ImGui. Calling this
// function sets the GImGui global variable, which is not shared across dll boundaries.
void SetImGuiContext(ImGuiContext* ctx);
ImNodesContext* CreateContext();
void DestroyContext(ImNodesContext* ctx = NULL); // NULL = destroy current context
ImNodesContext* GetCurrentContext();
void SetCurrentContext(ImNodesContext* ctx);
ImNodesEditorContext* EditorContextCreate();
void EditorContextFree(ImNodesEditorContext*);
void EditorContextSet(ImNodesEditorContext*);
ImVec2 EditorContextGetPanning();
void EditorContextResetPanning(const ImVec2& pos);
void EditorContextMoveToNode(const int node_id);
ImNodesIO& GetIO();
// Returns the global style struct. See the struct declaration for default values.
ImNodesStyle& GetStyle();
// Style presets matching the dear imgui styles of the same name.
void StyleColorsDark(); // on by default
void StyleColorsClassic();
void StyleColorsLight();
// The top-level function call. Call this before calling BeginNode/EndNode. Calling this function
// will result the node editor grid workspace being rendered.
void BeginNodeEditor();
void EndNodeEditor();
// Add a navigable minimap to the editor; call before EndNodeEditor after all
// nodes and links have been specified
void MiniMap(
const float minimap_size_fraction = 0.2f,
const ImNodesMiniMapLocation location = ImNodesMiniMapLocation_TopLeft,
const ImNodesMiniMapNodeHoveringCallback node_hovering_callback = NULL,
const ImNodesMiniMapNodeHoveringCallbackUserData node_hovering_callback_data = NULL);
// Use PushColorStyle and PopColorStyle to modify ImNodesStyle::Colors mid-frame.
void PushColorStyle(ImNodesCol item, unsigned int color);
void PopColorStyle();
void PushStyleVar(ImNodesStyleVar style_item, float value);
void PushStyleVar(ImNodesStyleVar style_item, const ImVec2& value);
void PopStyleVar(int count = 1);
// id can be any positive or negative integer, but INT_MIN is currently reserved for internal use.
void BeginNode(int id);
void EndNode();
ImVec2 GetNodeDimensions(int id);
// Place your node title bar content (such as the node title, using ImGui::Text) between the
// following function calls. These functions have to be called before adding any attributes, or the
// layout of the node will be incorrect.
void BeginNodeTitleBar();
void EndNodeTitleBar();
// Attributes are ImGui UI elements embedded within the node. Attributes can have pin shapes
// rendered next to them. Links are created between pins.
//
// The activity status of an attribute can be checked via the IsAttributeActive() and
// IsAnyAttributeActive() function calls. This is one easy way of checking for any changes made to
// an attribute's drag float UI, for instance.
//
// Each attribute id must be unique.
// Create an input attribute block. The pin is rendered on left side.
void BeginInputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled, ImU32 color_background = IM_COL32(53, 150, 250, 180), ImU32 color_hovered = IM_COL32(53, 150, 250, 255));
void EndInputAttribute();
// Create an output attribute block. The pin is rendered on the right side.
void BeginOutputAttribute(int id, ImNodesPinShape shape = ImNodesPinShape_CircleFilled, ImU32 color_background = IM_COL32(53, 150, 250, 180), ImU32 color_hovered = IM_COL32(53, 150, 250, 255));
void EndOutputAttribute();
// Create a static attribute block. A static attribute has no pin, and therefore can't be linked to
// anything. However, you can still use IsAttributeActive() and IsAnyAttributeActive() to check for
// attribute activity.
void BeginStaticAttribute(int id);
void EndStaticAttribute();
// Push a single AttributeFlags value. By default, only AttributeFlags_None is set.
void PushAttributeFlag(ImNodesAttributeFlags flag);
void PopAttributeFlag();
// Render a link between attributes.
// The attributes ids used here must match the ids used in Begin(Input|Output)Attribute function
// calls. The order of start_attr and end_attr doesn't make a difference for rendering the link.
void Link(int id, int start_attribute_id, int end_attribute_id);
// Enable or disable the ability to click and drag a specific node.
void SetNodeDraggable(int node_id, const bool draggable);
// The node's position can be expressed in three coordinate systems:
// * screen space coordinates, -- the origin is the upper left corner of the window.
// * editor space coordinates -- the origin is the upper left corner of the node editor window
// * grid space coordinates, -- the origin is the upper left corner of the node editor window,
// translated by the current editor panning vector (see EditorContextGetPanning() and
// EditorContextResetPanning())
// Use the following functions to get and set the node's coordinates in these coordinate systems.
void SetNodeScreenSpacePos(int node_id, const ImVec2& screen_space_pos);
void SetNodeEditorSpacePos(int node_id, const ImVec2& editor_space_pos);
void SetNodeGridSpacePos(int node_id, const ImVec2& grid_pos);
ImVec2 GetNodeScreenSpacePos(const int node_id);
ImVec2 GetNodeEditorSpacePos(const int node_id);
ImVec2 GetNodeGridSpacePos(const int node_id);
// Returns true if the current node editor canvas is being hovered over by the mouse, and is not
// blocked by any other windows.
bool IsEditorHovered();
// The following functions return true if a UI element is being hovered over by the mouse cursor.
// Assigns the id of the UI element being hovered over to the function argument. Use these functions
// after EndNodeEditor() has been called.
bool IsNodeHovered(int* node_id);
bool IsLinkHovered(int* link_id);
bool IsPinHovered(int* attribute_id);
// Use The following two functions to query the number of selected nodes or links in the current
// editor. Use after calling EndNodeEditor().
int NumSelectedNodes();
int NumSelectedLinks();
// Get the selected node/link ids. The pointer argument should point to an integer array with at
// least as many elements as the respective NumSelectedNodes/NumSelectedLinks function call
// returned.
void GetSelectedNodes(int* node_ids);
void GetSelectedLinks(int* link_ids);
// Clears the list of selected nodes/links. Useful if you want to delete a selected node or link.
void ClearNodeSelection();
void ClearLinkSelection();
// Use the following functions to add or remove individual nodes or links from the current editors
// selection. Note that all functions require the id to be an existing valid id for this editor.
// Select-functions has the precondition that the object is currently considered unselected.
// Clear-functions has the precondition that the object is currently considered selected.
// Preconditions listed above can be checked via IsNodeSelected/IsLinkSelected if not already
// known.
void SelectNode(int node_id);
void ClearNodeSelection(int node_id);
bool IsNodeSelected(int node_id);
void SelectLink(int link_id);
void ClearLinkSelection(int link_id);
bool IsLinkSelected(int link_id);
// Was the previous attribute active? This will continuously return true while the left mouse button
// is being pressed over the UI content of the attribute.
bool IsAttributeActive();
// Was any attribute active? If so, sets the active attribute id to the output function argument.
bool IsAnyAttributeActive(int* attribute_id = NULL);
// Use the following functions to query a change of state for an existing link, or new link. Call
// these after EndNodeEditor().
// Did the user start dragging a new link from a pin?
bool IsLinkStarted(int* started_at_attribute_id);
// Did the user drop the dragged link before attaching it to a pin?
// There are two different kinds of situations to consider when handling this event:
// 1) a link which is created at a pin and then dropped
// 2) an existing link which is detached from a pin and then dropped
// Use the including_detached_links flag to control whether this function triggers when the user
// detaches a link and drops it.
bool IsLinkDropped(int* started_at_attribute_id = NULL, bool including_detached_links = true);
// Did the user finish creating a new link?
bool IsLinkCreated(
int* started_at_attribute_id,
int* ended_at_attribute_id,
bool* created_from_snap = NULL);
bool IsLinkCreated(
int* started_at_node_id,
int* started_at_attribute_id,
int* ended_at_node_id,
int* ended_at_attribute_id,
bool* created_from_snap = NULL);
// Was an existing link detached from a pin by the user? The detached link's id is assigned to the
// output argument link_id.
bool IsLinkDestroyed(int* link_id);
// Use the following functions to write the editor context's state to a string, or directly to a
// file. The editor context is serialized in the INI file format.
const char* SaveCurrentEditorStateToIniString(size_t* data_size = NULL);
const char* SaveEditorStateToIniString(
const ImNodesEditorContext* editor,
size_t* data_size = NULL);
void LoadCurrentEditorStateFromIniString(const char* data, size_t data_size);
void LoadEditorStateFromIniString(ImNodesEditorContext* editor, const char* data, size_t data_size);
void SaveCurrentEditorStateToIniFile(const char* file_name);
void SaveEditorStateToIniFile(const ImNodesEditorContext* editor, const char* file_name);
void LoadCurrentEditorStateFromIniFile(const char* file_name);
void LoadEditorStateFromIniFile(ImNodesEditorContext* editor, const char* file_name);
} // namespace IMNODES_NAMESPACE

495
3rdparty/imnodes/imnodes_internal.h vendored Normal file
View File

@ -0,0 +1,495 @@
#pragma once
#include "imnodes.h"
#include <imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>
#include <assert.h>
#include <limits.h>
// the structure of this file:
//
// [SECTION] internal enums
// [SECTION] internal data structures
// [SECTION] global and editor context structs
// [SECTION] object pool implementation
struct ImNodesContext;
extern ImNodesContext* GImNodes;
// [SECTION] internal enums
typedef int ImNodesScope;
typedef int ImNodesAttributeType;
typedef int ImNodesUIState;
typedef int ImNodesClickInteractionType;
typedef int ImNodesLinkCreationType;
enum ImNodesScope_
{
ImNodesScope_None = 1,
ImNodesScope_Editor = 1 << 1,
ImNodesScope_Node = 1 << 2,
ImNodesScope_Attribute = 1 << 3
};
enum ImNodesAttributeType_
{
ImNodesAttributeType_None,
ImNodesAttributeType_Input,
ImNodesAttributeType_Output
};
enum ImNodesUIState_
{
ImNodesUIState_None = 0,
ImNodesUIState_LinkStarted = 1 << 0,
ImNodesUIState_LinkDropped = 1 << 1,
ImNodesUIState_LinkCreated = 1 << 2
};
enum ImNodesClickInteractionType_
{
ImNodesClickInteractionType_Node,
ImNodesClickInteractionType_Link,
ImNodesClickInteractionType_LinkCreation,
ImNodesClickInteractionType_Panning,
ImNodesClickInteractionType_BoxSelection,
ImNodesClickInteractionType_ImGuiItem,
ImNodesClickInteractionType_None
};
enum ImNodesLinkCreationType_
{
ImNodesLinkCreationType_Standard,
ImNodesLinkCreationType_FromDetach
};
// [SECTION] internal data structures
// The object T must have the following interface:
//
// struct T
// {
// T();
//
// int id;
// };
template<typename T>
struct ImObjectPool
{
ImVector<T> Pool;
ImVector<bool> InUse;
ImVector<int> FreeList;
ImGuiStorage IdMap;
ImObjectPool() : Pool(), InUse(), FreeList(), IdMap() {}
};
// Emulates std::optional<int> using the sentinel value `INVALID_INDEX`.
struct ImOptionalIndex
{
ImOptionalIndex() : _Index(INVALID_INDEX) {}
ImOptionalIndex(const int value) : _Index(value) {}
// Observers
inline bool HasValue() const { return _Index != INVALID_INDEX; }
inline int Value() const
{
assert(HasValue());
return _Index;
}
// Modifiers
inline ImOptionalIndex& operator=(const int value)
{
_Index = value;
return *this;
}
inline void Reset() { _Index = INVALID_INDEX; }
inline bool operator==(const ImOptionalIndex& rhs) const { return _Index == rhs._Index; }
inline bool operator==(const int rhs) const { return _Index == rhs; }
inline bool operator!=(const ImOptionalIndex& rhs) const { return _Index != rhs._Index; }
inline bool operator!=(const int rhs) const { return _Index != rhs; }
static const int INVALID_INDEX = -1;
private:
int _Index;
};
struct ImNodeData
{
int Id;
ImVec2 Origin; // The node origin is in editor space
ImRect TitleBarContentRect;
ImRect Rect;
struct
{
ImU32 Background, BackgroundHovered, BackgroundSelected, Outline, Titlebar, TitlebarHovered,
TitlebarSelected;
} ColorStyle;
struct
{
float CornerRounding;
ImVec2 Padding;
float BorderThickness;
} LayoutStyle;
ImVector<int> PinIndices;
bool Draggable;
ImNodeData(const int node_id)
: Id(node_id), Origin(100.0f, 100.0f), TitleBarContentRect(),
Rect(ImVec2(0.0f, 0.0f), ImVec2(0.0f, 0.0f)), ColorStyle(), LayoutStyle(), PinIndices(),
Draggable(true)
{
}
~ImNodeData() { Id = INT_MIN; }
};
struct ImPinData
{
int Id;
int ParentNodeIdx;
ImRect AttributeRect;
ImNodesAttributeType Type;
ImNodesPinShape Shape;
ImVec2 Pos; // screen-space coordinates
int Flags;
struct
{
ImU32 Background, Hovered;
} ColorStyle;
ImPinData(const int pin_id)
: Id(pin_id), ParentNodeIdx(), AttributeRect(), Type(ImNodesAttributeType_None),
Shape(ImNodesPinShape_CircleFilled), Pos(), Flags(ImNodesAttributeFlags_None),
ColorStyle()
{
}
};
struct ImLinkData
{
int Id;
int StartPinIdx, EndPinIdx;
struct
{
ImU32 Base, Hovered, Selected;
} ColorStyle;
ImLinkData(const int link_id) : Id(link_id), StartPinIdx(), EndPinIdx(), ColorStyle() {}
};
struct ImClickInteractionState
{
ImNodesClickInteractionType Type;
struct
{
int StartPinIdx;
ImOptionalIndex EndPinIdx;
ImNodesLinkCreationType Type;
} LinkCreation;
struct
{
ImRect Rect; // Coordinates in grid space
} BoxSelector;
ImClickInteractionState() : Type(ImNodesClickInteractionType_None) {}
};
struct ImNodesColElement
{
ImU32 Color;
ImNodesCol Item;
ImNodesColElement(const ImU32 c, const ImNodesCol s) : Color(c), Item(s) {}
};
struct ImNodesStyleVarElement
{
ImNodesStyleVar Item;
float FloatValue[2];
ImNodesStyleVarElement(const ImNodesStyleVar variable, const float value) : Item(variable)
{
FloatValue[0] = value;
}
ImNodesStyleVarElement(const ImNodesStyleVar variable, const ImVec2 value) : Item(variable)
{
FloatValue[0] = value.x;
FloatValue[1] = value.y;
}
};
// [SECTION] global and editor context structs
struct ImNodesEditorContext
{
ImObjectPool<ImNodeData> Nodes;
ImObjectPool<ImPinData> Pins;
ImObjectPool<ImLinkData> Links;
ImVector<int> NodeDepthOrder;
// ui related fields
ImVec2 Panning;
ImVec2 AutoPanningDelta;
// Minimum and maximum extents of all content in grid space. Valid after final
// ImNodes::EndNode() call.
ImRect GridContentBounds;
ImVector<int> SelectedNodeIndices;
ImVector<int> SelectedLinkIndices;
ImClickInteractionState ClickInteraction;
// Mini-map state set by MiniMap()
bool MiniMapEnabled;
ImNodesMiniMapLocation MiniMapLocation;
float MiniMapSizeFraction;
ImNodesMiniMapNodeHoveringCallback MiniMapNodeHoveringCallback;
ImNodesMiniMapNodeHoveringCallbackUserData MiniMapNodeHoveringCallbackUserData;
// Mini-map state set during EndNodeEditor() call
ImRect MiniMapRectScreenSpace;
ImRect MiniMapContentScreenSpace;
float MiniMapScaling;
ImNodesEditorContext()
: Nodes(), Pins(), Links(), Panning(0.f, 0.f), SelectedNodeIndices(), SelectedLinkIndices(),
ClickInteraction(), MiniMapEnabled(false), MiniMapSizeFraction(0.0f),
MiniMapNodeHoveringCallback(NULL), MiniMapNodeHoveringCallbackUserData(NULL),
MiniMapScaling(0.0f)
{
}
};
struct ImNodesContext
{
ImNodesEditorContext* DefaultEditorCtx;
ImNodesEditorContext* EditorCtx;
// Canvas draw list and helper state
ImDrawList* CanvasDrawList;
ImGuiStorage NodeIdxToSubmissionIdx;
ImVector<int> NodeIdxSubmissionOrder;
ImVector<int> NodeIndicesOverlappingWithMouse;
ImVector<int> OccludedPinIndices;
// Canvas extents
ImVec2 CanvasOriginScreenSpace;
ImRect CanvasRectScreenSpace;
// Debug helpers
ImNodesScope CurrentScope;
// Configuration state
ImNodesIO Io;
ImNodesStyle Style;
ImVector<ImNodesColElement> ColorModifierStack;
ImVector<ImNodesStyleVarElement> StyleModifierStack;
ImGuiTextBuffer TextBuffer;
int CurrentAttributeFlags;
ImVector<int> AttributeFlagStack;
// UI element state
int CurrentNodeIdx;
int CurrentPinIdx;
int CurrentAttributeId;
ImOptionalIndex HoveredNodeIdx;
ImOptionalIndex HoveredLinkIdx;
ImOptionalIndex HoveredPinIdx;
ImOptionalIndex DeletedLinkIdx;
ImOptionalIndex SnapLinkIdx;
// Event helper state
// TODO: this should be a part of a state machine, and not a member of the global struct.
// Unclear what parts of the code this relates to.
int ImNodesUIState;
int ActiveAttributeId;
bool ActiveAttribute;
// ImGui::IO cache
ImVec2 MousePos;
bool LeftMouseClicked;
bool LeftMouseReleased;
bool AltMouseClicked;
bool LeftMouseDragging;
bool AltMouseDragging;
float AltMouseScrollDelta;
};
namespace IMNODES_NAMESPACE
{
static inline ImNodesEditorContext& EditorContextGet()
{
// No editor context was set! Did you forget to call ImNodes::CreateContext()?
assert(GImNodes->EditorCtx != NULL);
return *GImNodes->EditorCtx;
}
// [SECTION] ObjectPool implementation
template<typename T>
static inline int ObjectPoolFind(const ImObjectPool<T>& objects, const int id)
{
const int index = objects.IdMap.GetInt(static_cast<ImGuiID>(id), -1);
return index;
}
template<typename T>
static inline void ObjectPoolUpdate(ImObjectPool<T>& objects)
{
for (int i = 0; i < objects.InUse.size(); ++i)
{
const int id = objects.Pool[i].Id;
if (!objects.InUse[i] && objects.IdMap.GetInt(id, -1) == i)
{
objects.IdMap.SetInt(id, -1);
objects.FreeList.push_back(i);
(objects.Pool.Data + i)->~T();
}
}
}
template<>
inline void ObjectPoolUpdate(ImObjectPool<ImNodeData>& nodes)
{
for (int i = 0; i < nodes.InUse.size(); ++i)
{
if (nodes.InUse[i])
{
nodes.Pool[i].PinIndices.clear();
}
else
{
const int id = nodes.Pool[i].Id;
if (nodes.IdMap.GetInt(id, -1) == i)
{
// Remove node idx form depth stack the first time we detect that this idx slot is
// unused
ImVector<int>& depth_stack = EditorContextGet().NodeDepthOrder;
const int* const elem = depth_stack.find(i);
assert(elem != depth_stack.end());
depth_stack.erase(elem);
nodes.IdMap.SetInt(id, -1);
nodes.FreeList.push_back(i);
(nodes.Pool.Data + i)->~ImNodeData();
}
}
}
}
template<typename T>
static inline void ObjectPoolReset(ImObjectPool<T>& objects)
{
if (!objects.InUse.empty())
{
memset(objects.InUse.Data, 0, objects.InUse.size_in_bytes());
}
}
template<typename T>
static inline int ObjectPoolFindOrCreateIndex(ImObjectPool<T>& objects, const int id)
{
int index = objects.IdMap.GetInt(static_cast<ImGuiID>(id), -1);
// Construct new object
if (index == -1)
{
if (objects.FreeList.empty())
{
index = objects.Pool.size();
IM_ASSERT(objects.Pool.size() == objects.InUse.size());
const int new_size = objects.Pool.size() + 1;
objects.Pool.resize(new_size);
objects.InUse.resize(new_size);
}
else
{
index = objects.FreeList.back();
objects.FreeList.pop_back();
}
IM_PLACEMENT_NEW(objects.Pool.Data + index) T(id);
objects.IdMap.SetInt(static_cast<ImGuiID>(id), index);
}
// Flag it as used
objects.InUse[index] = true;
return index;
}
template<>
inline int ObjectPoolFindOrCreateIndex(ImObjectPool<ImNodeData>& nodes, const int node_id)
{
int node_idx = nodes.IdMap.GetInt(static_cast<ImGuiID>(node_id), -1);
// Construct new node
if (node_idx == -1)
{
if (nodes.FreeList.empty())
{
node_idx = nodes.Pool.size();
IM_ASSERT(nodes.Pool.size() == nodes.InUse.size());
const int new_size = nodes.Pool.size() + 1;
nodes.Pool.resize(new_size);
nodes.InUse.resize(new_size);
}
else
{
node_idx = nodes.FreeList.back();
nodes.FreeList.pop_back();
}
IM_PLACEMENT_NEW(nodes.Pool.Data + node_idx) ImNodeData(node_id);
nodes.IdMap.SetInt(static_cast<ImGuiID>(node_id), node_idx);
ImNodesEditorContext& editor = EditorContextGet();
editor.NodeDepthOrder.push_back(node_idx);
}
// Flag node as used
nodes.InUse[node_idx] = true;
return node_idx;
}
template<typename T>
static inline T& ObjectPoolFindOrCreateObject(ImObjectPool<T>& objects, const int id)
{
const int index = ObjectPoolFindOrCreateIndex(objects, id);
return objects.Pool[index];
}
} // namespace IMNODES_NAMESPACE

154
3rdparty/imnodes/premake5.lua vendored Normal file
View File

@ -0,0 +1,154 @@
newoption {
trigger = "sdl-include-path",
value = "path",
description = "The location of your SDL2 header files"
}
newoption {
trigger = "sdl-link-path",
value = "path",
description = "The location of your SDL2 link libraries"
}
newoption {
trigger = "use-sdl-framework",
description = "Use the installed SDL2 framework (on MacOS)"
}
local projectlocation = os.getcwd()
local gl3wlocation = path.join(os.getcwd(), "dependencies/gl3w")
local imguilocation = path.join(os.getcwd(), "dependencies/imgui-1.84.2")
if _ACTION then
projectlocation = path.join(projectlocation, "build", _ACTION)
end
function imnodes_example_project(name, example_file)
project(name)
location(projectlocation)
kind "ConsoleApp"
language "C++"
cppdialect "C++11"
targetdir "bin/%{cfg.buildcfg}"
debugdir "bin/%{cfg.buildcfg}"
files {"example/main.cpp", path.join("example", example_file) }
includedirs {
os.getcwd(),
imguilocation,
path.join(gl3wlocation, "include"),
}
links { "gl3w", "imgui", "imnodes" }
defines { "IMGUI_IMPL_OPENGL_LOADER_GL3W" }
if _OPTIONS["sdl-include-path"] then
includedirs { _OPTIONS["sdl-include-path"] }
end
if _OPTIONS["sdl-link-path"] then
libdirs { _OPTIONS["sdl-link-path"] }
filter "system:macosx"
links {
"iconv",
"AudioToolbox.framework",
"Carbon.framework",
"Cocoa.framework",
"CoreAudio.framework",
"CoreVideo.framework",
"ForceFeedback.framework",
"IOKit.framework"
}
filter "*"
end
if _OPTIONS["use-sdl-framework"] then
includedirs { "/Library/Frameworks/SDL2.framework/Headers" }
linkoptions { "-F/Library/Frameworks -framework SDL2 -framework CoreFoundation" }
else
links { "SDL2" }
end
filter "system:windows"
defines { "SDL_MAIN_HANDLED" }
links { "opengl32" }
if _OPTIONS["sdl-link-path"] then
postbuildcommands {
"{COPY} " ..
path.join(os.getcwd(), _OPTIONS["sdl-link-path"].."/../bin/", "SDL2.dll") ..
" %{cfg.targetdir}" }
end
filter "system:linux"
links { "dl" }
end
workspace "imnodes"
configurations { "Debug", "Release" }
architecture "x86_64"
defines { "IMGUI_DISABLE_OBSOLETE_FUNCTIONS" }
filter "configurations:Debug"
symbols "On"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
filter "action:vs*"
defines { "_CRT_SECURE_NO_WARNINGS" }
warnings "Extra"
startproject "colornode"
group "dependencies"
project "gl3w"
location(projectlocation)
kind "StaticLib"
language "C"
targetdir "lib/%{cfg.buildcfg}"
files { path.join(gl3wlocation, "src/gl3w.c") }
includedirs { path.join(gl3wlocation, "include") }
project "imgui"
location(projectlocation)
kind "StaticLib"
language "C++"
cppdialect "C++98"
targetdir "lib/%{cfg.buildcfg}"
files { path.join(imguilocation, "**.cpp") }
includedirs {
imguilocation,
path.join(gl3wlocation, "include") }
if _OPTIONS["sdl-include-path"] then
includedirs { _OPTIONS["sdl-include-path"] }
end
if _OPTIONS["use-sdl-framework"] then
includedirs { "/Library/Frameworks/SDL2.framework/Headers" }
end
group "imnodes"
project "imnodes"
location(projectlocation)
kind "StaticLib"
language "C++"
cppdialect "C++98"
enablewarnings { "all" }
targetdir "lib/%{cfg.buildcfg}"
files { "imnodes.h", "imnodes_internal.h", "imnodes.cpp" }
includedirs { path.join(imguilocation) }
group "examples"
imnodes_example_project("hello", "hello.cpp")
imnodes_example_project("saveload", "save_load.cpp")
imnodes_example_project("colornode", "color_node_editor.cpp")
imnodes_example_project("multieditor", "multi_editor.cpp")

21
3rdparty/json/LICENSE.MIT vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2013-2022 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

22109
3rdparty/json/json.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,3 +10,7 @@ The following authors have all licensed their contributions to ozz-animation und
- Andreas Streichardt <andreas.streichardt@gmail.com>
- Chen Junjie <kitchen.gz.020@gmail.com>
- James W. Walker <jw@jwwalker.com>
- James W. Fleming <jaemz@alum.mit.edu>
- Kota Iguchi <developer@infosia.co.jp>
- Mikołaj Siedlarek <mikolaj@siedlarek.net>
- Paul Gruenbacher <pgruenbacher@gmail.com>

View File

@ -1,3 +1,24 @@
Release version 0.14.0
----------------------
* Samples
- [sample_fbx2mesh] Supports vertices part of a skinned mesh but with a weight of 0.
- [sample_fbx2mesh] Assigns non-influenced vertices to root joint.
* Library
- [offline] #124 Fixes incorrect root joint detection bug in glTF importer.
- [offline] #129 #130 Copy animation name to output in ozz::animation::offline::AdditiveAnimationBuilder.
- [animation] #103 Allows move constructor and assignment for ozz::animation::Skeleton, ozz::animation::Animation and ozz::animation::Track.
- [animation] Renames SamplingCache to SamplingJob::Context.
- [animation] #110 Renames skeleton bind pose to rest pose, to avoid confusion with skinning bind pose.
- [base] Fixes Float4x4::FromEuler which was swapping pitch and roll.
* Build pipeline
- Moves CI to github actions.
- #59 Adds support for shared libraries on Windows (dll), Linux and MacOS platforms.
- #111 Removes _GLIBCXX_DEBUG from default build settings as it can create incompatibilities when using prebuilt packages.
- #122 #137 Adds support for gcc 11 compiler.
Release version 0.13.0
----------------------
@ -52,7 +73,7 @@ Release version 0.11.0
* Library
- [animation] Adds two-bone and aim inverse kinematic solvers. They can be used at runtime to procedurally affect joint local-space transforms.
- [animation] Allows resizing SamplingCache, meaning the can be allocated without knowing the number of joints the cache needs to support.
- [animation] Allows resizing SamplingJob::Context, meaning the can be allocated without knowing the number of joints the cache needs to support.
- [animation] Allow ozz::animation::LocalToModelJob to partially update a hierarchy, aka all children of a joint. This is useful when changes to a local-space pose has been limited to part of the joint hierarchy, like when applying IK or modifying model-space matrices independently from local-space transform.
- [animation] Changes ozz::animation::Skeleton joints from breadth-first to depth-first. This change breaks compatibility of previous ozz::animation::offline::RawAnimation, ozz::animation::Animation and ozz::animation::Skeleton archives.
- [animation] Renames track_triggering_job_stl.h to track_triggering_job_trait.h.

View File

@ -5,11 +5,12 @@ project(ozz)
# Current version
set(OZZ_VERSION_MAJOR 0)
set(OZZ_VERSION_MINOR 13)
set(OZZ_VERSION_MINOR 14)
set(OZZ_VERSION_PATCH 0)
set(OZZ_VERSION ${OZZ_VERSION_MAJOR}.${OZZ_VERSION_MINOR}.${OZZ_VERSION_PATCH})
# Add project build options
option(BUILD_SHARED_LIBS "Build ozz as shared libraries" OFF)
option(ozz_build_tools "Build tools" ON)
option(ozz_build_fbx "Build Fbx pipeline (Requires Fbx SDK)" ON)
option(ozz_build_gltf "Build glTF importer (Requires c++11)" ON)
@ -18,8 +19,14 @@ option(ozz_build_samples "Build samples" ON)
option(ozz_build_howtos "Build howtos" ON)
option(ozz_build_tests "Build unit tests" ON)
option(ozz_build_simd_ref "Force SIMD math reference implementation" OFF)
option(ozz_build_msvc_rt_dll "Select msvc DLL runtime library" ON)
option(ozz_build_postfix "Use per config postfix name" ON)
option(ozz_build_msvc_rt_dll "Select msvc DLL runtime library" OFF)
# Checks DLL flags
if(WIN32 AND BUILD_SHARED_LIBS AND NOT ozz_build_msvc_rt_dll)
message("Forcing ozz_build_msvc_rt_dll to ON as ozz is being built as dll (BUILD_SHARED_LIBS is ON).")
set(ozz_build_msvc_rt_dll ON)
endif()
# Include ozz cmake parameters and scripts
include(CheckCXXCompilerFlag)
@ -27,6 +34,7 @@ include(${PROJECT_SOURCE_DIR}/build-utils/cmake/compiler_settings.cmake)
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/package_settings.cmake)
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/fuse_target.cmake)
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/clang_format.cmake)
include(${PROJECT_SOURCE_DIR}/build-utils/cmake/shared_library.cmake)
# Add project execution options
option(ozz_run_tests_headless "Run samples without rendering (used for unit tests)" ON)
@ -39,6 +47,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/build-utils/cm
if(ozz_build_tools AND ozz_build_fbx)
# Select a msvc runtime compatible with ozz_build_msvc_rt_dll
set(FBX_SHARED ${BUILD_SHARED_LIBS})
set(FBX_MSVC_RT_DLL ${ozz_build_msvc_rt_dll})
# Search for FBX sdk package
@ -49,6 +58,7 @@ if(ozz_build_tools AND ozz_build_fbx)
message("Fbx SDK not found, FBX tools libraries and samples will be skipped.")
set(ozz_build_fbx OFF)
endif()
else()
# Disables fbx if tools are disabled
set(ozz_build_fbx OFF)
@ -75,6 +85,7 @@ file(MAKE_DIRECTORY ${ozz_temp_directory})
# Outputs selected options (can be modified by the command line)
message("-- ---------------------------------------------------------")
message("-- Selected options:")
message("-- - BUILD_SHARED_LIBS: " ${BUILD_SHARED_LIBS})
message("-- - ozz_build_tools: " ${ozz_build_tools})
message("-- - ozz_build_fbx: " ${ozz_build_fbx})
message("-- - ozz_build_gltf: " ${ozz_build_gltf})

View File

@ -25,10 +25,10 @@ Samples, tools and tests depend on external libraries (glfw, tinygltf, Fbx SDK,
Build status
------------
| | Linux | Mac OS | Windows |
| | Linux | macOS | Windows |
| ------- | ------ | ------ | ------- |
| master | [![Travis-CI](https://travis-ci.org/guillaumeblanc/ozz-animation.svg?branch=master)](http://travis-ci.org/guillaumeblanc/ozz-animation) | [![Travis-CI](https://travis-ci.org/guillaumeblanc/ozz-animation.svg?branch=master)](http://travis-ci.org/guillaumeblanc/ozz-animation) | [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/guillaumeblanc/ozz-animation?branch=master&svg=true)](http://ci.appveyor.com/project/guillaumeblanc/ozz-animation) |
| develop | [![Travis-CI](https://travis-ci.org/guillaumeblanc/ozz-animation.svg?branch=develop)](http://travis-ci.org/guillaumeblanc/ozz-animation) | [![Travis-CI](https://travis-ci.org/guillaumeblanc/ozz-animation.svg?branch=develop)](http://travis-ci.org/guillaumeblanc/ozz-animation) | [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/guillaumeblanc/ozz-animation?branch=develop&svg=true)](http://ci.appveyor.com/project/guillaumeblanc/ozz-animation) |
| master | [![Linux](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/linux.yml/badge.svg?branch=master)](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/linux.yml) | [![macOS](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/macos.yml/badge.svg?branch=master)](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/macos.yml) | [![Windows](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/windows.yml/badge.svg?branch=master)](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/windows.yml) |
| develop | [![Linux](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/linux.yml/badge.svg?branch=develop)](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/linux.yml) | [![macOS](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/macos.yml/badge.svg?branch=develop)](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/macos.yml) | [![Windows](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/windows.yml/badge.svg?branch=develop)](https://github.com/guillaumeblanc/ozz-animation/actions/workflows/windows.yml) |
The dashboard for all branches is available [here](http://guillaumeblanc.github.io/ozz-animation/documentation/dashboard/).

View File

@ -30,33 +30,34 @@ set(cxx_all_flags
# Cross compiler compilation flags
# Requires C++11
set(CMAKE_CXX_STANDARD 11)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Simd math force ref
if(ozz_build_simd_ref)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS OZZ_BUILD_SIMD_REF)
add_compile_definitions(OZZ_BUILD_SIMD_REF)
endif()
# Disables crt secure warnings
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
#--------------------------------------
# Modify default MSVC compilation flags
if(MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
#---------------------------
# For the common build flags
# Disables crt secure warnings
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _CRT_SECURE_NO_WARNINGS)
# Adds support for multiple processes builds
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "/MP")
add_compile_options(/MP)
# Set the warning level to W4
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "/W4")
add_compile_options(/W4)
# Set warning as error
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "/WX")
add_compile_options(/WX)
# Select whether to use the DLL version or the static library version of the Visual C++ runtime library.
foreach(flag ${cxx_all_flags})
@ -68,40 +69,35 @@ if(MSVC)
endforeach()
#--------------------------------------
# else consider the compiler as GCC compatible
# Modify default GCC compilation flags
# else consider the compiler as GCC compatible (inc clang)
else()
# Set the warning level to Wall
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Wall")
add_compile_options(-Wall)
# Enable extra level of warning
#set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Wextra")
#add_compile_options(-Wextra)
# Set warning as error
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Werror")
add_compile_options(-Werror)
# Disables warning: ignored-attributes reports issue when using _m128 as template argument
# ignored-attributes reports issue when using _m128 as template argument
check_cxx_compiler_flag("-Wignored-attributes" W_IGNORED_ATTRIBUTES)
if(W_IGNORED_ATTRIBUTES)
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Wno-ignored-attributes")
add_compile_options(-Wno-ignored-attributes)
endif()
# Enables warning: sign comparison warnings
check_cxx_compiler_flag("-Wsign-compare" W_SIGN_COMPARE)
if(W_SIGN_COMPARE)
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Wsign-compare")
# Disables c98 retrocompatibility warnings
check_cxx_compiler_flag("-Wc++98-compat-pedantic" W_98_COMPAT_PEDANTIC)
if(W_98_COMPAT_PEDANTIC)
add_compile_options(-Wno-c++98-compat-pedantic)
endif()
# Check some more options availability for the targeted compiler
# Check some options availibity for the targetted compiler
check_cxx_compiler_flag("-Wnull-dereference" W_NULL_DEREFERENCE)
check_cxx_compiler_flag("-Wpragma-pack" W_PRAGMA_PACK)
# Enables debug glibcxx if NDebug isn't defined, not supported by APPLE
if(NOT APPLE)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "$<$<CONFIG:Debug>:_GLIBCXX_DEBUG>")
endif()
#----------------------
# Sets emscripten output
if(EMSCRIPTEN)

View File

@ -9,11 +9,18 @@ function(fuse_target _target_name)
# Get all target sources.
get_property(target_source_files TARGET ${_target_name} PROPERTY SOURCES)
foreach(src_file ${target_source_files})
if(IS_ABSOLUTE ${src_file})
file(RELATIVE_PATH src_file ${CMAKE_CURRENT_LIST_DIR} ${src_file})
endif()
list(APPEND relative_target_source_files ${src_file})
endforeach()
add_custom_command(
OUTPUT ${output_file}
DEPENDS ${target_source_files}
${PROJECT_SOURCE_DIR}/build-utils/cmake/fuse_target_script.cmake
COMMAND ${CMAKE_COMMAND} -Dozz_fuse_output_file="${output_file}" -Dozz_target_source_files="${target_source_files}" -Dozz_fuse_target_dir="${CMAKE_CURRENT_LIST_DIR}" -Dozz_fuse_src_dir="${PROJECT_SOURCE_DIR}" -P "${PROJECT_SOURCE_DIR}/build-utils/cmake/fuse_target_script.cmake")
COMMAND ${CMAKE_COMMAND} -Dozz_fuse_output_file="${output_file}" -Dozz_target_source_files="${relative_target_source_files}" -Dozz_fuse_target_dir="${CMAKE_CURRENT_LIST_DIR}" -Dozz_fuse_src_dir="${PROJECT_SOURCE_DIR}" -P "${PROJECT_SOURCE_DIR}/build-utils/cmake/fuse_target_script.cmake")
add_custom_target(BUILD_FUSE_${_target_name} ALL DEPENDS ${output_file})
set_target_properties(BUILD_FUSE_${_target_name} PROPERTIES FOLDER "ozz/fuse")

View File

@ -2,18 +2,25 @@
#----------------------------------------------------------
# Start with new content
string(CONCAT output_content "" "// This file is autogenerated. Do not modify it.\n\n")
string(CONCAT output_content "" "// This file is autogenerated. Any modification might be lost.\n\n")
# Patches arguments so that cmake interprate it as a list.
string (REPLACE " " ";" ozz_target_source_files "${ozz_target_source_files}")
# Patches arguments so that cmake take them as a list.
separate_arguments(ozz_target_source_files)
string(REPLACE "\\ " " " ozz_fuse_target_dir "${ozz_fuse_target_dir}")
string(REPLACE "\\ " " " ozz_fuse_src_dir "${ozz_fuse_src_dir}")
string(REPLACE "\\ " " " ozz_fuse_output_file "${ozz_fuse_output_file}")
# Concat all sources to the output.
foreach(src_file ${ozz_target_source_files})
get_filename_component(src_file_ext ${src_file} EXT)
get_filename_component(absolute_src_file ${src_file} ABSOLUTE BASE_DIR ${ozz_fuse_target_dir})
get_filename_component(src_file_ext ${absolute_src_file} EXT)
# Handle source files.
if(src_file_ext STREQUAL ".cc")
file(READ "${ozz_fuse_target_dir}/${src_file}" src_file_content)
file(READ "${absolute_src_file}" src_file_content)
string(CONCAT output_content "${output_content}" "// Including ${src_file} file.\n\n")
string(CONCAT output_content "${output_content}" "${src_file_content}\n")
@ -28,10 +35,12 @@ foreach(internal_include_line ${internal_include_lines})
STRING(REGEX REPLACE "#include \"([^\"]+)\"" "\\1" internal_include_file "${internal_include_line}" )
file(READ "${ozz_fuse_src_dir}/src/${internal_include_file}" internal_src_file_content)
get_filename_component(internal_src_file src/${internal_include_file} ABSOLUTE BASE_DIR ${ozz_fuse_src_dir})
file(READ "${internal_src_file}" internal_src_file_content)
string(REPLACE "${internal_include_line}" "\n// Includes internal include file ${internal_include_file}\n\n${internal_src_file_content}" output_content "${output_content}")
endforeach()
# Output new file
file(WRITE "${ozz_fuse_output_file}" "${output_content}")

View File

@ -9,9 +9,15 @@
# FBX_INCLUDE_DIRS - The Fbx SDK include directories
# FBX_LIBRARIES - The libraries needed to use Fbx SDK
# FBX_LIBRARIES_DEBUG - The libraries needed to use debug Fbx SDK
# FBX_SHARED_LIBRARIES - The shared library file (dll, so) to use Fbx
# FBX_SHARED_LIBRARIES_DEBUG - The shared library file (dll, so) to use debug
# Fbx SDK
#
# A cmake target named fbx::sdk is also created. Adding this target to your
# project via target_link_libraries will setup everything automatically.
#
# It accepts the following variables as input:
#
# FBX_SHARED - Optional. Select whether to use the shared version fbx sdk.
# FBX_MSVC_RT_DLL - Optional. Select whether to use the DLL version or the
# static library version of the Visual C++ runtime library.
# Default is ON (aka, DLL version: /MD).
@ -52,7 +58,7 @@
###############################################################################
# Generic library search function definition
###############################################################################
function(FindFbxLibrariesGeneric _FBX_ROOT_DIR _OUT_FBX_LIBRARIES _OUT_FBX_LIBRARIES_DEBUG)
function(FindFbxLibrariesGeneric _FBX_ROOT_DIR _OUT_FBX_LIBRARIES _OUT_FBX_LIBRARIES_DEBUG _OUT_FBX_SHARED_LIBRARIES _OUT_FBX_SHARED_LIBRARIES_DEBUG)
# Directory structure depends on the platform:
# - Windows: \lib\<compiler_version>\<processor_type>\<build_mode>
# - Mac OSX: \lib\<compiler_version>\ub\<processor_type>\<build_mode>
@ -61,7 +67,9 @@ function(FindFbxLibrariesGeneric _FBX_ROOT_DIR _OUT_FBX_LIBRARIES _OUT_FBX_LIBRA
# Figures out matching compiler/os directory.
if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.20)
set(FBX_CP_PATH "vs2019")
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10)
set(FBX_CP_PATH "vs2017")
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
set(FBX_CP_PATH "vs2015")
@ -90,19 +98,25 @@ function(FindFbxLibrariesGeneric _FBX_ROOT_DIR _OUT_FBX_LIBRARIES _OUT_FBX_LIBRA
endif()
endif()
# Set libraries names to search, sorted by preference.
set(FBX_SEARCH_LIB_NAMES fbxsdk-static.a libfbxsdk.a fbxsdk.a)
# Select whether to use the DLL version or the static library version of the Visual C++ runtime library.
# Default is "md", aka use the multithread DLL version of the run-time library.
if (NOT DEFINED FBX_MSVC_RT_DLL OR FBX_MSVC_RT_DLL)
set(FBX_SEARCH_LIB_NAMES ${FBX_SEARCH_LIB_NAMES} libfbxsdk-md.lib)
# Select whether to use the DLL version or the static library version of fbx sdk.
if (FBX_SHARED)
# Dynamic libraries
set(FBX_SEARCH_LIB_NAMES ${FBX_SEARCH_LIB_NAMES} libfbxsdk.lib libfbxsdk.dylib libfbxsdk.so)
else()
set(FBX_SEARCH_LIB_NAMES ${FBX_SEARCH_LIB_NAMES} libfbxsdk-mt.lib)
# static library names
set(FBX_SEARCH_LIB_NAMES ${FBX_SEARCH_LIB_NAMES} libfbxsdk.a libfbxsdk-static.a)
# Select whether to use the DLL version or the static library version of the Visual C++ runtime library.
# Default is "md", aka use the multithread DLL version of the run-time library.
if (NOT DEFINED FBX_MSVC_RT_DLL OR FBX_MSVC_RT_DLL)
set(FBX_SEARCH_LIB_NAMES ${FBX_SEARCH_LIB_NAMES} libfbxsdk-md.lib)
else()
set(FBX_SEARCH_LIB_NAMES ${FBX_SEARCH_LIB_NAMES} libfbxsdk-mt.lib)
endif()
endif()
# Set search path.
set(FBX_SEARCH_LIB_PATH "${_FBX_ROOT_DIR}/lib/${FBX_CP_PATH}/${FBX_PROCESSOR_PATH}")
set(FBX_SEARCH_LIB_PATH "${_FBX_ROOT_DIR}lib/${FBX_CP_PATH}/${FBX_PROCESSOR_PATH}")
find_library(FBX_LIB
${FBX_SEARCH_LIB_NAMES}
@ -114,21 +128,42 @@ function(FindFbxLibrariesGeneric _FBX_ROOT_DIR _OUT_FBX_LIBRARIES _OUT_FBX_LIBRA
${FBX_SEARCH_LIB_NAMES}
HINTS "${FBX_SEARCH_LIB_PATH}/debug/")
if(UNIX)
if(APPLE) # APPLE requires to link with Carbon framework
find_library(CARBON_FRAMEWORK Carbon)
list(APPEND FBX_LIB ${CARBON_FRAMEWORK})
list(APPEND FBX_LIB_DEBUG ${CARBON_FRAMEWORK})
else()
find_package(Threads)
list(APPEND FBX_LIB ${CMAKE_THREAD_LIBS_INIT} dl)
list(APPEND FBX_LIB_DEBUG ${CMAKE_THREAD_LIBS_INIT} dl)
endif()
# Looks for shared libraries
if (FBX_SHARED)
set(FBX_SEARCH_SHARED_LIB_NAMES libfbxsdk.dll libfbxsdk.so libfbxsdk.dylib)
find_file(FBX_SHARED_LIB
${FBX_SEARCH_SHARED_LIB_NAMES}
HINTS "${FBX_SEARCH_LIB_PATH}/release/")
find_file(FBX_SHARED_LIB_DEBUG
${FBX_SEARCH_SHARED_LIB_NAMES}
HINTS "${FBX_SEARCH_LIB_PATH}/debug/")
set(${_OUT_FBX_SHARED_LIBRARIES} ${FBX_SHARED_LIB} PARENT_SCOPE)
set(${_OUT_FBX_SHARED_LIBRARIES_DEBUG} ${FBX_SHARED_LIB_DEBUG} PARENT_SCOPE)
endif()
# Create a target for a convenient use of the sdk with cmake
if(FBX_SHARED)
add_library(fbx::sdk SHARED IMPORTED GLOBAL)
set_property(TARGET fbx::sdk PROPERTY IMPORTED_LOCATION ${FBX_SHARED_LIB})
set_property(TARGET fbx::sdk PROPERTY IMPORTED_LOCATION_DEBUG ${FBX_SHARED_LIB_DEBUG})
set_property(TARGET fbx::sdk PROPERTY IMPORTED_IMPLIB ${FBX_LIB})
set_property(TARGET fbx::sdk PROPERTY IMPORTED_IMPLIB_DEBUG ${FBX_LIB_DEBUG})
target_compile_definitions(fbx::sdk INTERFACE FBXSDK_SHARED)
else()
add_library(fbx::sdk STATIC IMPORTED GLOBAL)
set_property(TARGET fbx::sdk PROPERTY IMPORTED_LOCATION ${FBX_LIB})
set_property(TARGET fbx::sdk PROPERTY IMPORTED_LOCATION_DEBUG ${FBX_LIB_DEBUG})
endif()
target_include_directories(fbx::sdk INTERFACE "${_FBX_ROOT_DIR}include/")
target_compile_options(fbx::sdk
INTERFACE $<$<BOOL:${W_NULL_DEREFERENCE}>:-Wno-null-dereference>
INTERFACE $<$<BOOL:${W_PRAGMA_PACK}>:-Wno-pragma-pack>)
FindFbxVersion(${FBX_ROOT_DIR} PATH_VERSION)
# 2019 SDK needs to link against bundled libxml and zlib
# 2019+ non-DLL SDK needs to link against bundled libxml and zlib
if(PATH_VERSION GREATER_EQUAL "2019.1")
if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
set(ADDITIONAL_LIB_SEARCH_PATH_RELEASE "${FBX_SEARCH_LIB_PATH}/release/")
@ -150,48 +185,71 @@ function(FindFbxLibrariesGeneric _FBX_ROOT_DIR _OUT_FBX_LIBRARIES _OUT_FBX_LIBRA
find_library(XML_LIB
${XML_SEARCH_LIB_NAMES}
HINTS ${ADDITIONAL_LIB_SEARCH_PATH_RELEASE})
find_library(Z_LIB
${Z_SEARCH_LIB_NAMES}
HINTS ${ADDITIONAL_LIB_SEARCH_PATH_RELEASE})
# Searches debug version also
find_library(XML_LIB_DEBUG
${XML_SEARCH_LIB_NAMES}
HINTS ${ADDITIONAL_LIB_SEARCH_PATH_DEBUG})
if(XML_LIB AND XML_LIB_DEBUG)
target_link_libraries(fbx::sdk INTERFACE optimized ${XML_LIB})
target_link_libraries(fbx::sdk INTERFACE debug ${XML_LIB_DEBUG})
else()
message(WARNING "FBX found but required libxml2 was not found!")
endif()
find_library(Z_LIB
${Z_SEARCH_LIB_NAMES}
HINTS ${ADDITIONAL_LIB_SEARCH_PATH_RELEASE})
find_library(Z_LIB_DEBUG
${Z_SEARCH_LIB_NAMES}
HINTS ${ADDITIONAL_LIB_SEARCH_PATH_DEBUG})
# for whatever reason on apple it will need iconv as well?!
if(APPLE)
find_library(ICONV_LIB
iconv)
# no special debug search here as mac only anyway
if(NOT ICONV_LIB)
message(WARNING "FBX found but required iconv was not found!")
endif()
list(APPEND FBX_LIB ${ICONV_LIB})
list(APPEND FBX_LIB_DEBUG ${ICONV_LIB})
endif()
if(NOT XML_LIB)
message(WARNING "FBX found but required libxml2 was not found!")
endif()
if(NOT Z_LIB)
if(Z_LIB AND Z_LIB_DEBUG)
target_link_libraries(fbx::sdk INTERFACE optimized ${Z_LIB})
target_link_libraries(fbx::sdk INTERFACE debug ${Z_LIB_DEBUG})
else()
message(WARNING "FBX found but required zlib was not found!")
endif()
list(APPEND FBX_LIB ${XML_LIB} ${Z_LIB})
list(APPEND FBX_LIB_DEBUG ${XML_LIB_DEBUG} ${Z_LIB_DEBUG})
endif()
# Other dependencies.
if(APPLE)
find_library(ICONV_LIB iconv)
if(ICONV_LIB)
target_link_libraries(fbx::sdk INTERFACE ${ICONV_LIB})
list(APPEND FBX_LIB ${ICONV_LIB})
list(APPEND FBX_LIB_DEBUG ${ICONV_LIB})
else()
message(WARNING "FBX found but required iconv was not found!")
endif()
find_library(CARBON_FRAMEWORK Carbon)
if(CARBON_FRAMEWORK)
target_link_libraries(fbx::sdk INTERFACE ${CARBON_FRAMEWORK})
list(APPEND FBX_LIB ${CARBON_FRAMEWORK})
list(APPEND FBX_LIB_DEBUG ${CARBON_FRAMEWORK})
else()
message(WARNING "FBX found but required Carbon was not found!")
endif()
endif()
if(UNIX)
find_package(Threads)
target_link_libraries(fbx::sdk INTERFACE ${CMAKE_THREAD_LIBS_INIT} dl)
list(APPEND FBX_LIB ${CMAKE_THREAD_LIBS_INIT} dl)
list(APPEND FBX_LIB_DEBUG ${CMAKE_THREAD_LIBS_INIT} dl)
endif()
set(${_OUT_FBX_LIBRARIES} ${FBX_LIB} PARENT_SCOPE)
set(${_OUT_FBX_LIBRARIES_DEBUG} ${FBX_LIB_DEBUG} PARENT_SCOPE)
else()
message ("A Fbx SDK was found, but doesn't match your compiler settings.")
message("A Fbx installation was found, but couldn't be matched with current compiler settings.")
endif()
# Deduce fbx sdk version
endfunction()
###############################################################################
@ -257,7 +315,7 @@ if(FBX_INCLUDE_DIR)
set(FBX_INCLUDE_DIRS "${FBX_INCLUDE_DIR}/include")
# Searches libraries according to the current compiler
FindFbxLibrariesGeneric(${FBX_ROOT_DIR} FBX_LIBRARIES FBX_LIBRARIES_DEBUG)
FindFbxLibrariesGeneric(${FBX_ROOT_DIR} FBX_LIBRARIES FBX_LIBRARIES_DEBUG FBX_SHARED_LIBRARIES FBX_SHARED_LIBRARIES_DEBUG)
endif()
# Handles find_package arguments and set FBX_FOUND to TRUE if all listed variables and version are valid.

View File

@ -0,0 +1,48 @@
# Finds target dependencies on shared libraries so they can
# be copied next to the exe.
#----------------------------------------------------------
# Finds all target dependencies
function(get_link_libraries OUTPUT_LIST _TARGET)
get_target_property(LIBS ${_TARGET} LINK_LIBRARIES)
list(APPEND VISITED_TARGETS ${TARGET})
set(LIB_FILES "")
foreach(LIB ${LIBS})
if (TARGET ${LIB})
list(FIND VISITED_TARGETS ${LIB} VISITED)
if (${VISITED} EQUAL -1)
get_link_libraries(LINK_LIBS ${LIB})
list(APPEND LIB_FILES ${LIB} ${LINK_LIBS})
endif()
endif()
endforeach()
set(VISITED_TARGETS ${VISITED_TARGETS} PARENT_SCOPE)
set(${OUTPUT_LIST} ${LIB_FILES} PARENT_SCOPE)
endfunction()
# Copy dependent shared libraries next to executable target
function(target_copy_shared_libraries _TARGET)
get_link_libraries(LINKED_TARGETS ${_TARGET})
foreach(LINKED_TARGET ${LINKED_TARGETS})
get_target_property(TARGET_TYPE ${LINKED_TARGET} TYPE)
if(TARGET_TYPE STREQUAL "SHARED_LIBRARY")
list(APPEND DLL_TARGETS "$<TARGET_FILE:${LINKED_TARGET}>")
endif()
endforeach()
if(DLL_TARGETS)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET}_dll_copy"
DEPENDS ${DLL_TARGETS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DLL_TARGETS} "./"
COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET}_dll_copy"
VERBATIM)
# This allows to create a dependency with the command above, so command is executed again when target is built AND a DLL changed
target_sources(${_TARGET} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET}_dll_copy")
endif()
endfunction()

View File

@ -1,4 +1,4 @@
add_library(gtest
add_library(gtest STATIC
fused-src/gtest/gtest_main.cc
fused-src/gtest/gtest-all.cc
fused-src/gtest/gtest.h)
@ -12,4 +12,3 @@ target_link_libraries(gtest
target_include_directories(gtest PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/extern/gtest/fused-src>)

View File

@ -7832,14 +7832,14 @@ static int ExecDeathTestChildMain(void* child_arg) {
// correct answer.
void StackLowerThanAddress(const void* ptr, bool* result) GTEST_NO_INLINE_;
void StackLowerThanAddress(const void* ptr, bool* result) {
int dummy;
int dummy = 0;
*result = (&dummy < ptr);
}
// Make sure AddressSanitizer does not tamper with the stack here.
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
bool StackGrowsDown() {
int dummy;
int dummy = 0;
bool result;
StackLowerThanAddress(&dummy, &result);
return result;

View File

@ -6,8 +6,18 @@ add_library(json
set_target_properties(json
PROPERTIES FOLDER "extern")
target_compile_definitions(json
PUBLIC $<$<BOOL:${BUILD_SHARED_LIBS}>:JSON_DLL>
PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:JSON_DLL_BUILD>)
set_target_properties(json
PROPERTIES COMPILE_OPTIONS $<$<CXX_COMPILER_ID:MSVC>:/wd4702>)
set_target_properties(json
PROPERTIES COMPILE_OPTIONS $<$<CXX_COMPILER_ID:MSVC>:/wd4275>)
target_compile_options(json
PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/wd4702>
PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/wd4275>)
target_include_directories(json PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/extern/jsoncpp/dist>)

View File

@ -416,7 +416,7 @@ public:
virtual ~Exception() throw();
virtual char const* what() const throw();
protected:
void operator = (const Exception&);
void operator = (const Exception&) = delete;
std::string const msg_;
};

View File

@ -4,6 +4,7 @@ add_executable(load_from_file
load_from_file.cc)
target_link_libraries(load_from_file
ozz_animation)
target_copy_shared_libraries(load_from_file)
set_target_properties(load_from_file
PROPERTIES FOLDER "howtos")
add_test(NAME load_from_file COMMAND load_from_file "${ozz_media_directory}/bin/pab_skeleton.ozz")
@ -18,6 +19,7 @@ add_executable(custom_skeleton_importer
custom_skeleton_importer.cc)
target_link_libraries(custom_skeleton_importer
ozz_animation_offline)
target_copy_shared_libraries(custom_skeleton_importer)
set_target_properties(custom_skeleton_importer
PROPERTIES FOLDER "howtos")
add_test(NAME custom_skeleton_importer COMMAND custom_skeleton_importer)
@ -28,6 +30,7 @@ add_executable(custom_animation_importer
custom_animation_importer.cc)
target_link_libraries(custom_animation_importer
ozz_animation_offline)
target_copy_shared_libraries(custom_animation_importer)
set_target_properties(custom_animation_importer
PROPERTIES FOLDER "howtos")
add_test(NAME custom_animation_importer COMMAND custom_animation_importer)

View File

@ -25,13 +25,12 @@
// //
//----------------------------------------------------------------------------//
#include <cstdlib>
#include "ozz/animation/offline/raw_skeleton.h"
#include "ozz/animation/offline/skeleton_builder.h"
#include "ozz/animation/runtime/skeleton.h"
#include <cstdlib>
// Code for ozz-animation HowTo: "How to write a custon skeleton importer?"
int main(int argc, char const* argv[]) {
@ -52,7 +51,7 @@ int main(int argc, char const* argv[]) {
// Setup root joints name.
root.name = "root";
// Setup root joints bind-pose/rest transformation, in joint local-space.
// Setup root joints rest pose transformation, in joint local-space.
// This is the default skeleton posture (most of the time a T-pose). It's
// used as a fallback when there's no animation for a joint.
root.transform.translation = ozz::math::Float3(0.f, 1.f, 0.f);

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_ADDITIVE_ANIMATION_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_ADDITIVE_ANIMATION_BUILDER_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
@ -46,7 +47,7 @@ struct RawAnimation;
// Defines the class responsible for building a delta animation from an offline
// raw animation. This is used to create animations compatible with additive
// blending.
class AdditiveAnimationBuilder {
class OZZ_ANIMOFFLINE_DLL AdditiveAnimationBuilder {
public:
// Initializes the builder.
AdditiveAnimationBuilder();

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_BUILDER_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/memory/unique_ptr.h"
namespace ozz {
@ -44,7 +45,7 @@ struct RawAnimation;
// Defines the class responsible of building runtime animation instances from
// offline raw animations.
// No optimization at all is performed on the raw animation.
class AnimationBuilder {
class OZZ_ANIMOFFLINE_DLL AnimationBuilder {
public:
// Creates an Animation based on _raw_animation and *this builder parameters.
// Returns a valid Animation on success.

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_OPTIMIZER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_ANIMATION_OPTIMIZER_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/containers/map.h"
namespace ozz {
@ -54,7 +55,7 @@ struct RawAnimation;
// that leads to the hand if user wants it to be precise. Default optimization
// tolerances are set in order to favor quality over runtime performances and
// memory footprint.
class AnimationOptimizer {
class OZZ_ANIMOFFLINE_DLL AnimationOptimizer {
public:
// Initializes the optimizer with default tolerances (favoring quality).
AnimationOptimizer();
@ -89,7 +90,7 @@ class AnimationOptimizer {
float distance;
};
// Golbal optimization settings. These settings apply to all joints of the
// Global optimization settings. These settings apply to all joints of the
// hierarchy, unless overriden by joint specific settings.
Setting setting;

View File

@ -0,0 +1,44 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_EXPORT_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_EXPORT_H_
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#ifdef OZZ_BUILD_ANIMOFFLINE_LIB
// Import/Export for dynamic linking while building ozz
#define OZZ_ANIMOFFLINE_DLL __declspec(dllexport)
#else
#define OZZ_ANIMOFFLINE_DLL __declspec(dllimport)
#endif
#else // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
// Static or non msvc linking
#define OZZ_ANIMOFFLINE_DLL
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#endif // OZZ_OZZ_ANIMATION_OFFLINE_EXPORT_H_

View File

@ -0,0 +1,44 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_FBX_EXPORT_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_FBX_EXPORT_H_
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#ifdef OZZ_BUILD_ANIMATIONFBX_LIB
// Import/Export for dynamic linking while building ozz
#define OZZ_ANIMFBX_DLL __declspec(dllexport)
#else
#define OZZ_ANIMFBX_DLL __declspec(dllimport)
#endif
#else // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
// Static or non msvc linking
#define OZZ_ANIMFBX_DLL
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#endif // OZZ_OZZ_ANIMATION_OFFLINE_FBX_EXPORT_H_

View File

@ -30,6 +30,7 @@
#include <fbxsdk.h>
#include "ozz/animation/offline/fbx/export.h"
#include "ozz/base/maths/simd_math.h"
#include "ozz/base/maths/transform.h"
@ -42,7 +43,7 @@ namespace offline {
namespace fbx {
// Manages FbxManager instance.
class FbxManagerInstance {
class OZZ_ANIMFBX_DLL FbxManagerInstance {
public:
// Instantiates FbxManager.
FbxManagerInstance();
@ -58,7 +59,7 @@ class FbxManagerInstance {
};
// Default io settings used to import a scene.
class FbxDefaultIOSettings {
class OZZ_ANIMFBX_DLL FbxDefaultIOSettings {
public:
// Instantiates default settings.
explicit FbxDefaultIOSettings(const FbxManagerInstance& _manager);
@ -77,13 +78,13 @@ class FbxDefaultIOSettings {
};
// Io settings used to import an animation from a scene.
class FbxAnimationIOSettings : public FbxDefaultIOSettings {
class OZZ_ANIMFBX_DLL FbxAnimationIOSettings : public FbxDefaultIOSettings {
public:
FbxAnimationIOSettings(const FbxManagerInstance& _manager);
};
// Io settings used to import a skeleton from a scene.
class FbxSkeletonIOSettings : public FbxDefaultIOSettings {
class OZZ_ANIMFBX_DLL FbxSkeletonIOSettings : public FbxDefaultIOSettings {
public:
FbxSkeletonIOSettings(const FbxManagerInstance& _manager);
};
@ -94,7 +95,7 @@ class FbxSkeletonIOSettings : public FbxDefaultIOSettings {
// While Fbx sdk FbxAxisSystem::ConvertScene and FbxSystem::ConvertScene only
// affect scene root, this class functions can be used to bake nodes, vertices,
// animations transformations...
class FbxSystemConverter {
class OZZ_ANIMFBX_DLL FbxSystemConverter {
public:
// Initialize converter with fbx scene systems.
FbxSystemConverter(const FbxAxisSystem& _from_axis,
@ -133,7 +134,7 @@ class FbxSystemConverter {
};
// Loads a scene from a Fbx file.
class FbxSceneLoader {
class OZZ_ANIMFBX_DLL FbxSceneLoader {
public:
// Loads the scene that can then be obtained with scene() function.
FbxSceneLoader(const char* _filename, const char* _password,

View File

@ -28,6 +28,8 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_ANIMATION_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_ANIMATION_H_
#include "ozz/animation/offline/fbx/export.h"
#include "ozz/animation/offline/fbx/fbx.h"
#include "ozz/animation/offline/tools/import2ozz.h"
@ -51,34 +53,40 @@ struct RawquaternionTrack;
namespace fbx {
OzzImporter::AnimationNames GetAnimationNames(FbxSceneLoader& _scene_loader);
OZZ_ANIMFBX_DLL OzzImporter::AnimationNames GetAnimationNames(
FbxSceneLoader& _scene_loader);
bool ExtractAnimation(const char* _animation_name,
OZZ_ANIMFBX_DLL bool ExtractAnimation(const char* _animation_name,
FbxSceneLoader& _scene_loader, const Skeleton& _skeleton,
float _sampling_rate, RawAnimation* _animation);
OzzImporter::NodeProperties GetNodeProperties(FbxSceneLoader& _scene_loader,
OZZ_ANIMFBX_DLL OzzImporter::NodeProperties GetNodeProperties(
FbxSceneLoader& _scene_loader,
const char* _node_name);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
OZZ_ANIMFBX_DLL bool ExtractTrack(const char* _animation_name,
const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,
RawFloatTrack* _track);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
OZZ_ANIMFBX_DLL bool ExtractTrack(const char* _animation_name,
const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,
RawFloat2Track* _track);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
OZZ_ANIMFBX_DLL bool ExtractTrack(const char* _animation_name,
const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,
RawFloat3Track* _track);
bool ExtractTrack(const char* _animation_name, const char* _node_name,
OZZ_ANIMFBX_DLL bool ExtractTrack(const char* _animation_name,
const char* _node_name,
const char* _track_name,
OzzImporter::NodeProperty::Type _type,
FbxSceneLoader& _scene_loader, float _sampling_rate,

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_SKELETON_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_FBX_FBX_SKELETON_H_
#include "ozz/animation/offline/fbx/export.h"
#include "ozz/animation/offline/fbx/fbx.h"
#include "ozz/animation/offline/tools/import2ozz.h"
@ -39,7 +40,7 @@ struct RawSkeleton;
namespace fbx {
bool ExtractSkeleton(FbxSceneLoader& _loader,
OZZ_ANIMFBX_DLL bool ExtractSkeleton(FbxSceneLoader& _loader,
const OzzImporter::NodeType& _types,
RawSkeleton* _skeleton);

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
#include "ozz/base/io/archive_traits.h"
@ -55,7 +56,7 @@ namespace offline {
// 3. Keyframes' time are all within [0,animation duration] range.
// Animations that would fail this validation will fail to be converted by the
// AnimationBuilder.
struct RawAnimation {
struct OZZ_ANIMOFFLINE_DLL RawAnimation {
// Constructs a valid RawAnimation with a 1s default duration.
RawAnimation();
@ -146,7 +147,7 @@ OZZ_IO_TYPE_TAG("ozz-raw_animation", animation::offline::RawAnimation)
// Should not be called directly but through io::Archive << and >> operators.
template <>
struct Extern<animation::offline::RawAnimation> {
struct OZZ_ANIMOFFLINE_DLL Extern<animation::offline::RawAnimation> {
static void Save(OArchive& _archive,
const animation::offline::RawAnimation* _animations,
size_t _count);

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
#include "ozz/animation/offline/export.h"
#include "ozz/animation/offline/raw_animation.h"
#include "ozz/base/maths/transform.h"
@ -38,22 +39,25 @@ namespace animation {
namespace offline {
// Translation interpolation method.
math::Float3 LerpTranslation(const math::Float3& _a, const math::Float3& _b,
OZZ_ANIMOFFLINE_DLL math::Float3 LerpTranslation(const math::Float3& _a,
const math::Float3& _b,
float _alpha);
// Rotation interpolation method.
math::Quaternion LerpRotation(const math::Quaternion& _a,
OZZ_ANIMOFFLINE_DLL math::Quaternion LerpRotation(const math::Quaternion& _a,
const math::Quaternion& _b, float _alpha);
// Scale interpolation method.
math::Float3 LerpScale(const math::Float3& _a, const math::Float3& _b,
OZZ_ANIMOFFLINE_DLL math::Float3 LerpScale(const math::Float3& _a,
const math::Float3& _b,
float _alpha);
// Samples a RawAnimation track. This function shall be used for offline
// purpose. Use ozz::animation::Animation and ozz::animation::SamplingJob for
// runtime purpose.
// Returns false if track is invalid.
bool SampleTrack(const RawAnimation::JointTrack& _track, float _time,
OZZ_ANIMOFFLINE_DLL bool SampleTrack(const RawAnimation::JointTrack& _track,
float _time,
ozz::math::Transform* _transform);
// Samples a RawAnimation. This function shall be used for offline
@ -61,7 +65,8 @@ bool SampleTrack(const RawAnimation::JointTrack& _track, float _time,
// runtime purpose.
// _animation must be valid.
// Returns false output range is too small or animation is invalid.
bool SampleAnimation(const RawAnimation& _animation, float _time,
OZZ_ANIMOFFLINE_DLL bool SampleAnimation(
const RawAnimation& _animation, float _time,
const span<ozz::math::Transform>& _transforms);
// Implement fixed rate keyframe time iteration. This utility purpose is to
@ -69,7 +74,7 @@ bool SampleAnimation(const RawAnimation& _animation, float _time,
// between consecutive time samples have a fixed period.
// This sounds trivial, but floating point error could occur if keyframe time
// was accumulated for a long duration.
class FixedRateSamplingTime {
class OZZ_ANIMOFFLINE_DLL FixedRateSamplingTime {
public:
FixedRateSamplingTime(float _duration, float _frequency);

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_SKELETON_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_SKELETON_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
#include "ozz/base/io/archive_traits.h"
@ -41,13 +42,13 @@ namespace offline {
// This skeleton type is not intended to be used in run time. It is used to
// define the offline skeleton object that can be converted to the runtime
// skeleton using the SkeletonBuilder. This skeleton structure exposes joints'
// hierarchy. A joint is defined with a name, a transformation (its bind pose),
// and its children. Children are exposed as a public std::vector of joints.
// This same type is used for skeleton roots, also exposed from the public API.
// The public API exposed through std:vector's of joints can be used freely with
// the only restriction that the total number of joints does not exceed
// Skeleton::kMaxJoints.
struct RawSkeleton {
// hierarchy. A joint is defined with a name, a transformation (its rest_pose
// pose), and its children. Children are exposed as a public std::vector of
// joints. This same type is used for skeleton roots, also exposed from the
// public API. The public API exposed through std:vector's of joints can be used
// freely with the only restriction that the total number of joints does not
// exceed Skeleton::kMaxJoints.
struct OZZ_ANIMOFFLINE_DLL RawSkeleton {
// Construct an empty skeleton.
RawSkeleton();
@ -65,7 +66,7 @@ struct RawSkeleton {
// The name of the joint.
ozz::string name;
// Joint bind pose transformation in local space.
// Joint rest pose transformation in local space.
math::Transform transform;
};
@ -139,7 +140,7 @@ OZZ_IO_TYPE_TAG("ozz-raw_skeleton", animation::offline::RawSkeleton)
// Should not be called directly but through io::Archive << and >> operators.
template <>
struct Extern<animation::offline::RawSkeleton> {
struct OZZ_ANIMOFFLINE_DLL Extern<animation::offline::RawSkeleton> {
static void Save(OArchive& _archive,
const animation::offline::RawSkeleton* _skeletons,
size_t _count);

View File

@ -28,11 +28,10 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_TRACK_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/maths/quaternion.h"
#include "ozz/base/maths/vec_float.h"
@ -85,7 +84,7 @@ namespace internal {
// RawTrack that would fail this validation will fail to be converted by
// the RawTrackBuilder.
template <typename _ValueType>
struct RawTrack {
struct OZZ_ANIMOFFLINE_DLL RawTrack {
typedef _ValueType ValueType;
typedef RawTrackKeyframe<ValueType> Keyframe;
@ -109,11 +108,15 @@ struct RawTrack {
} // namespace internal
// Offline user-channel animation track type instantiation.
struct RawFloatTrack : public internal::RawTrack<float> {};
struct RawFloat2Track : public internal::RawTrack<math::Float2> {};
struct RawFloat3Track : public internal::RawTrack<math::Float3> {};
struct RawFloat4Track : public internal::RawTrack<math::Float4> {};
struct RawQuaternionTrack : public internal::RawTrack<math::Quaternion> {};
struct OZZ_ANIMOFFLINE_DLL RawFloatTrack : public internal::RawTrack<float> {};
struct OZZ_ANIMOFFLINE_DLL RawFloat2Track
: public internal::RawTrack<math::Float2> {};
struct OZZ_ANIMOFFLINE_DLL RawFloat3Track
: public internal::RawTrack<math::Float3> {};
struct OZZ_ANIMOFFLINE_DLL RawFloat4Track
: public internal::RawTrack<math::Float4> {};
struct OZZ_ANIMOFFLINE_DLL RawQuaternionTrack
: public internal::RawTrack<math::Quaternion> {};
} // namespace offline
} // namespace animation

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_SKELETON_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_SKELETON_BUILDER_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/maths/transform.h"
#include "ozz/base/memory/unique_ptr.h"
@ -43,7 +44,7 @@ namespace offline {
struct RawSkeleton;
// Defines the class responsible of building Skeleton instances.
class SkeletonBuilder {
class OZZ_ANIMOFFLINE_DLL SkeletonBuilder {
public:
// Creates a Skeleton based on _raw_skeleton and *this builder parameters.
// Returns a Skeleton instance on success, an empty unique_ptr on failure. See

View File

@ -0,0 +1,44 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_EXPORT_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_EXPORT_H_
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#ifdef OZZ_BUILD_ANIMATIONTOOLS_LIB
// Import/Export for dynamic linking while building ozz
#define OZZ_ANIMTOOLS_DLL __declspec(dllexport)
#else
#define OZZ_ANIMTOOLS_DLL __declspec(dllimport)
#endif
#else // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
// Static or non msvc linking
#define OZZ_ANIMTOOLS_DLL
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#endif // OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_EXPORT_H_

View File

@ -28,6 +28,8 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_IMPORT2OZZ_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_TOOLS_IMPORT2OZZ_H_
#include "ozz/animation/offline/tools/export.h"
#include "ozz/base/containers/string.h"
#include "ozz/base/containers/vector.h"
@ -35,6 +37,8 @@
#include "ozz/animation/offline/raw_skeleton.h"
#include "ozz/animation/offline/raw_track.h"
#include "ozz/base/platform.h"
namespace ozz {
namespace animation {
@ -51,7 +55,7 @@ namespace offline {
// To import a new source data format, one will implement the pure virtual
// functions of this interface. All the conversions end error processing are
// done by the tool.
class OzzImporter {
class OZZ_ANIMTOOLS_DLL OzzImporter {
public:
virtual ~OzzImporter() {}
@ -72,6 +76,7 @@ class OzzImporter {
bool camera : 1; // Uses camera nodes as skeleton joints.
bool geometry : 1; // Uses geometry nodes as skeleton joints.
bool light : 1; // Uses light nodes as skeleton joints.
bool null : 1; // Uses null nodes as skeleton joints.
bool any : 1; // Uses any node type as skeleton joints, including those
// listed above and any other.
};

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_TRACK_BUILDER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_TRACK_BUILDER_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/memory/unique_ptr.h"
namespace ozz {
@ -53,7 +54,7 @@ struct RawQuaternionTrack;
// offline tracks.The input raw track is first validated. Runtime conversion of
// a validated raw track cannot fail. Note that no optimization is performed on
// the data at all.
class TrackBuilder {
class OZZ_ANIMOFFLINE_DLL TrackBuilder {
public:
// Creates a Track based on _raw_track and *this builder parameters.
// Returns a track instance on success, an empty unique_ptr on failure. See

View File

@ -28,6 +28,9 @@
#ifndef OZZ_OZZ_ANIMATION_OFFLINE_TRACK_OPTIMIZER_H_
#define OZZ_OZZ_ANIMATION_OFFLINE_TRACK_OPTIMIZER_H_
#include "ozz/animation/offline/export.h"
#include "ozz/base/platform.h"
namespace ozz {
namespace animation {
namespace offline {
@ -44,7 +47,7 @@ struct RawQuaternionTrack;
// keyframes (within a tolerance value) are removed from the track. Default
// optimization tolerances are set in order to favor quality over runtime
// performances and memory footprint.
class TrackOptimizer {
class OZZ_ANIMOFFLINE_DLL TrackOptimizer {
public:
// Initializes the optimizer with default tolerances (favoring quality).
TrackOptimizer();

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
@ -58,11 +59,19 @@ struct QuaternionKey;
// joints order of the runtime skeleton structure. In order to optimize cache
// coherency when sampling the animation, Keyframes in this array are sorted by
// time, then by track number.
class Animation {
class OZZ_ANIMATION_DLL Animation {
public:
// Builds a default animation.
Animation();
// Allow moves.
Animation(Animation&&);
Animation& operator=(Animation&&);
// Delete copies.
Animation(Animation const&) = delete;
Animation& operator=(Animation const&) = delete;
// Declares the public non-virtual destructor.
~Animation();
@ -80,9 +89,7 @@ class Animation {
const char* name() const { return name_ ? name_ : ""; }
// Gets the buffer of translations keys.
span<const Float3Key> translations() const {
return translations_;
}
span<const Float3Key> translations() const { return translations_; }
// Gets the buffer of rotation keys.
span<const QuaternionKey> rotations() const { return rotations_; }
@ -98,12 +105,7 @@ class Animation {
void Save(ozz::io::OArchive& _archive) const;
void Load(ozz::io::IArchive& _archive, uint32_t _version);
protected:
private:
// Disables copy and assignation.
Animation(Animation const&);
void operator=(Animation const&);
// AnimationBuilder class is allowed to instantiate an Animation.
friend class offline::AnimationBuilder;

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_UTILS_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_UTILS_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/animation/runtime/animation.h"
namespace ozz {
@ -35,9 +36,12 @@ namespace animation {
// Count translation, rotation or scale keyframes for a given track number. Use
// a negative _track value to count all tracks.
int CountTranslationKeyframes(const Animation& _animation, int _track = -1);
int CountRotationKeyframes(const Animation& _animation, int _track = -1);
int CountScaleKeyframes(const Animation& _animation, int _track = -1);
OZZ_ANIMATION_DLL int CountTranslationKeyframes(const Animation& _animation,
int _track = -1);
OZZ_ANIMATION_DLL int CountRotationKeyframes(const Animation& _animation,
int _track = -1);
OZZ_ANIMATION_DLL int CountScaleKeyframes(const Animation& _animation,
int _track = -1);
} // namespace animation
} // namespace ozz
#endif // OZZ_OZZ_ANIMATION_RUNTIME_ANIMATION_UTILS_H_

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_BLENDING_JOB_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_BLENDING_JOB_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/maths/simd_math.h"
#include "ozz/base/span.h"
@ -44,15 +45,15 @@ namespace animation {
// (the result of a sampled animation) according to their respective weight,
// into one output pose.
// The number of transforms/joints blended by the job is defined by the number
// of transforms of the bind pose (note that this is a SoA format). This means
// that all buffers must be at least as big as the bind pose buffer.
// of transforms of the rest pose (note that this is a SoA format). This means
// that all buffers must be at least as big as the rest pose buffer.
// Partial animation blending is supported through optional joint weights that
// can be specified with layers joint_weights buffer. Unspecified joint weights
// are considered as a unit weight of 1.f, allowing to mix full and partial
// blend operations in a single pass.
// The job does not owned any buffers (input/output) and will thus not delete
// them during job's destruction.
struct BlendingJob {
struct OZZ_ANIMATION_DLL BlendingJob {
// Default constructor, initializes default values.
BlendingJob();
@ -63,7 +64,7 @@ struct BlendingJob {
// -if any layer is not valid.
// -if output range is not valid.
// -if any buffer (including layers' content : transform, joint weights...) is
// smaller than the bind pose buffer.
// smaller than the rest pose buffer.
// -if the threshold value is less than or equal to 0.f.
bool Validate() const;
@ -75,7 +76,7 @@ struct BlendingJob {
// Defines a layer of blending input data (local space transforms) and
// parameters (weights).
struct Layer {
struct OZZ_ANIMATION_DLL Layer {
// Default constructor, initializes default values.
Layer();
@ -86,8 +87,8 @@ struct BlendingJob {
// The range [begin,end[ of input layer posture. This buffer expect to store
// local space transforms, that are usually outputted from a sampling job.
// This range must be at least as big as the bind pose buffer, even though
// only the number of transforms defined by the bind pose buffer will be
// This range must be at least as big as the rest pose buffer, even though
// only the number of transforms defined by the rest pose buffer will be
// processed.
span<const math::SoaTransform> transform;
@ -95,8 +96,8 @@ struct BlendingJob {
// layer.
// If both pointers are nullptr (default case) then per joint weight
// blending is disabled. A valid range is defined as being at least as big
// as the bind pose buffer, even though only the number of transforms
// defined by the bind pose buffer will be processed. When a layer doesn't
// as the rest pose buffer, even though only the number of transforms
// defined by the rest pose buffer will be processed. When a layer doesn't
// specifies per joint weights, then it is implicitly considered as
// being 1.f. This default value is a reference value for the normalization
// process, which implies that the range of values for joint weights should
@ -106,7 +107,7 @@ struct BlendingJob {
span<const math::SimdFloat4> joint_weights;
};
// The job blends the bind pose to the output when the accumulated weight of
// The job blends the rest pose to the output when the accumulated weight of
// all layers is less than this threshold value.
// Must be greater than 0.f.
float threshold;
@ -119,18 +120,18 @@ struct BlendingJob {
// The range of layers that must be added to the output.
span<const Layer> additive_layers;
// The skeleton bind pose. The size of this buffer defines the number of
// The skeleton rest pose. The size of this buffer defines the number of
// transforms to blend. This is the reference because this buffer is defined
// by the skeleton that all the animations belongs to.
// It is used when the accumulated weight for a bone on all layers is
// less than the threshold value, in order to fall back on valid transforms.
span<const ozz::math::SoaTransform> bind_pose;
span<const ozz::math::SoaTransform> rest_pose;
// Job output.
// The range of output transforms to be filled with blended layer
// transforms during job execution.
// Must be at least as big as the bind pose buffer, but only the number of
// transforms defined by the bind pose buffer size will be processed.
// Must be at least as big as the rest pose buffer, but only the number of
// transforms defined by the rest pose buffer size will be processed.
span<ozz::math::SoaTransform> output;
};
} // namespace animation

View File

@ -0,0 +1,44 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_EXPORT_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_EXPORT_H_
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#ifdef OZZ_BUILD_ANIMATION_LIB
// Import/Export for dynamic linking while building ozz
#define OZZ_ANIMATION_DLL __declspec(dllexport)
#else
#define OZZ_ANIMATION_DLL __declspec(dllimport)
#endif
#else // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
// Static or non msvc linking
#define OZZ_ANIMATION_DLL
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#endif // OZZ_OZZ_ANIMATION_RUNTIME_EXPORT_H_

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_IK_AIM_JOB_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_IK_AIM_JOB_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/platform.h"
#include "ozz/base/maths/simd_math.h"
@ -50,7 +51,7 @@ namespace animation {
// vector should aim the target.
// Result is unstable if joint-to-target direction is parallel to pole vector,
// or if target is too close to joint position.
struct IKAimJob {
struct OZZ_ANIMATION_DLL IKAimJob {
// Default constructor, initializes default values.
IKAimJob();

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_IK_TWO_BONE_JOB_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_IK_TWO_BONE_JOB_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/platform.h"
#include "ozz/base/maths/simd_math.h"
@ -51,7 +52,7 @@ namespace animation {
// ancestors (joints in-between will simply remain fixed).
// Implementation is inspired by Autodesk Maya 2 bone IK, improved stability
// wise and extended with Soften IK.
struct IKTwoBoneJob {
struct OZZ_ANIMATION_DLL IKTwoBoneJob {
// Constructor, initializes default values.
IKTwoBoneJob();

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_LOCAL_TO_MODEL_JOB_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_LOCAL_TO_MODEL_JOB_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
@ -55,7 +56,7 @@ class Skeleton;
// ordered like skeleton's joints. Output are matrices, because the combination
// of affine transformations can contain shearing or complex transformation
// that cannot be represented as Transform object.
struct LocalToModelJob {
struct OZZ_ANIMATION_DLL LocalToModelJob {
// Default constructor, initializes default values.
LocalToModelJob();

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_SAMPLING_JOB_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_SAMPLING_JOB_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
@ -43,19 +44,16 @@ namespace animation {
// Forward declares the animation type to sample.
class Animation;
// Forward declares the cache object used by the SamplingJob.
class SamplingCache;
// Samples an animation at a given time ratio in the unit interval [0,1] (where
// 0 is the beginning of the animation, 1 is the end), to output the
// corresponding posture in local-space.
// SamplingJob uses a cache (aka SamplingCache) to store intermediate values
// (decompressed animation keyframes...) while sampling. This cache also stores
// pre-computed values that allows drastic optimization while playing/sampling
// the animation forward. Backward sampling works, but isn't optimized through
// the cache. The job does not owned the buffers (in/output) and will thus not
// delete them during job's destruction.
struct SamplingJob {
// SamplingJob uses a context (aka SamplingJob::Context) to store intermediate
// values (decompressed animation keyframes...) while sampling. This context
// also stores pre-computed values that allows drastic optimization while
// playing/sampling the animation forward. Backward sampling works, but isn't
// optimized through the context. The job does not owned the buffers (in/output)
// and will thus not delete them during job's destruction.
struct OZZ_ANIMATION_DLL SamplingJob {
// Default constructor, initializes default values.
SamplingJob();
@ -80,8 +78,11 @@ struct SamplingJob {
// The animation to sample.
const Animation* animation;
// A cache object that must be big enough to sample *this animation.
SamplingCache* cache;
// Forward declares the context object used by the SamplingJob.
class Context;
// A context object that must be big enough to sample *this animation.
Context* context;
// Job output.
// The output range to be filled with sampled joints during job execution.
@ -98,61 +99,62 @@ struct InterpSoaFloat3;
struct InterpSoaQuaternion;
} // namespace internal
// Declares the cache object used by the workload to take advantage of the
// Declares the context object used by the workload to take advantage of the
// frame coherency of animation sampling.
class SamplingCache {
class OZZ_ANIMATION_DLL SamplingJob::Context {
public:
// Constructs an empty cache. The cache needs to be resized with the
// Constructs an empty context. The context needs to be resized with the
// appropriate number of tracks before it can be used with a SamplingJob.
SamplingCache();
Context();
// Constructs a cache that can be used to sample any animation with at most
// Constructs a context that can be used to sample any animation with at most
// _max_tracks tracks. _num_tracks is internally aligned to a multiple of
// soa size, which means max_tracks() can return a different (but bigger)
// value than _max_tracks.
explicit SamplingCache(int _max_tracks);
explicit Context(int _max_tracks);
// Deallocates cache.
~SamplingCache();
// Disables copy and assignation.
Context(Context const&) = delete;
Context& operator=(Context const&) = delete;
// Resize the number of joints that the cache can support.
// This also implicitly invalidate the cache.
// Deallocates context.
~Context();
// Resize the number of joints that the context can support.
// This also implicitly invalidate the context.
void Resize(int _max_tracks);
// Invalidate the cache.
// The SamplingJob automatically invalidates a cache when required
// Invalidate the context.
// The SamplingJob automatically invalidates a context when required
// during sampling. This automatic mechanism is based on the animation
// address and sampling time ratio. The weak point is that it can result in a
// crash if ever the address of an animation is used again with another
// animation (could be the result of successive call to delete / new).
// Therefore it is recommended to manually invalidate a cache when it is
// known that this cache will not be used for with an animation again.
// Therefore it is recommended to manually invalidate a context when it is
// known that this context will not be used for with an animation again.
void Invalidate();
// The maximum number of tracks that the cache can handle.
// The maximum number of tracks that the context can handle.
int max_tracks() const { return max_soa_tracks_ * 4; }
int max_soa_tracks() const { return max_soa_tracks_; }
private:
// Disables copy and assignation.
SamplingCache(SamplingCache const&);
void operator=(SamplingCache const&);
friend struct SamplingJob;
// Steps the cache in order to use it for a potentially new animation and
// Steps the context in order to use it for a potentially new animation and
// ratio. If the _animation is different from the animation currently cached,
// or if the _ratio shows that the animation is played backward, then the
// cache is invalidated and reseted for the new _animation and _ratio.
// context is invalidated and reset for the new _animation and _ratio.
void Step(const Animation& _animation, float _ratio);
// The animation this cache refers to. nullptr means that the cache is invalid.
// The animation this context refers to. nullptr means that the context is
// invalid.
const Animation* animation_;
// The current time ratio in the animation.
float ratio_;
// The number of soa tracks that can store this cache.
// The number of soa tracks that can store this context.
int max_soa_tracks_;
// Soa hot data to interpolate.
@ -166,7 +168,7 @@ class SamplingCache {
int* rotation_keys_;
int* scale_keys_;
// Current cursors in the animation. 0 means that the cache is invalid.
// Current cursors in the animation. 0 means that the context is invalid.
int translation_cursor_;
int rotation_cursor_;
int scale_cursor_;

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_SKELETON_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_SKELETON_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
@ -48,16 +49,16 @@ class SkeletonBuilder;
}
// This runtime skeleton data structure provides a const-only access to joint
// hierarchy, joint names and bind-pose. This structure is filled by the
// hierarchy, joint names and rest-pose. This structure is filled by the
// SkeletonBuilder and can be serialize/deserialized.
// Joint names, bind-poses and hierarchy information are all stored in separate
// Joint names, rest-poses and hierarchy information are all stored in separate
// arrays of data (as opposed to joint structures for the RawSkeleton), in order
// to closely match with the way runtime algorithms use them. Joint hierarchy is
// packed as an array of parent jont indices (16 bits), stored in depth-first
// order. This is enough to traverse the whole joint hierarchy. See
// IterateJointsDF() from skeleton_utils.h that implements a depth-first
// traversal utility.
class Skeleton {
class OZZ_ANIMATION_DLL Skeleton {
public:
// Defines Skeleton constant values.
enum Constants {
@ -81,6 +82,14 @@ class Skeleton {
// Builds a default skeleton.
Skeleton();
// Allow move.
Skeleton(Skeleton&&);
Skeleton& operator=(Skeleton&&);
// Disables copy and assignation.
Skeleton(Skeleton const&) = delete;
Skeleton& operator=(Skeleton const&) = delete;
// Declares the public non-virtual destructor.
~Skeleton();
@ -91,9 +100,9 @@ class Skeleton {
// skeleton. This value is useful to allocate SoA runtime data structures.
int num_soa_joints() const { return (num_joints() + 3) / 4; }
// Returns joint's bind poses. Bind poses are stored in soa format.
span<const math::SoaTransform> joint_bind_poses() const {
return joint_bind_poses_;
// Returns joint's rest poses. Rest poses are stored in soa format.
span<const math::SoaTransform> joint_rest_poses() const {
return joint_rest_poses_;
}
// Returns joint's parent indices range.
@ -110,10 +119,6 @@ class Skeleton {
void Load(ozz::io::IArchive& _archive, uint32_t _version);
private:
// Disables copy and assignation.
Skeleton(Skeleton const&);
void operator=(Skeleton const&);
// Internal allocation/deallocation function.
// Allocate returns the beginning of the contiguous buffer of names.
char* Allocate(size_t _char_count, size_t _num_joints);
@ -125,8 +130,8 @@ class Skeleton {
// Buffers below store joint informations in joing depth first order. Their
// size is equal to the number of joints of the skeleton.
// Bind pose of every joint in local space.
span<math::SoaTransform> joint_bind_poses_;
// Rest pose of every joint in local space.
span<math::SoaTransform> joint_rest_poses_;
// Array of joint parent indexes.
span<int16_t> joint_parents_;

View File

@ -28,17 +28,18 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_SKELETON_UTILS_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_SKELETON_UTILS_H_
#include <cassert>
#include "ozz/animation/runtime/export.h"
#include "ozz/animation/runtime/skeleton.h"
#include "ozz/base/maths/transform.h"
#include <cassert>
namespace ozz {
namespace animation {
// Get bind-pose of a skeleton joint.
ozz::math::Transform GetJointLocalBindPose(const Skeleton& _skeleton,
int _joint);
// Get rest-pose of a skeleton joint.
OZZ_ANIMATION_DLL ozz::math::Transform GetJointLocalRestPose(
const Skeleton& _skeleton, int _joint);
// Test if a joint is a leaf. _joint number must be in range [0, num joints].
// "_joint" is a leaf if it's the last joint, or next joint's parent isn't
@ -51,12 +52,15 @@ inline bool IsLeaf(const Skeleton& _skeleton, int _joint) {
return next == num_joints || parents[next] != _joint;
}
// Finds joint index by name. Uses a case sensitive comparison.
OZZ_ANIMATION_DLL int FindJoint(const Skeleton& _skeleton, const char* _name);
// Applies a specified functor to each joint in a depth-first order.
// _Fct is of type void(int _current, int _parent) where the first argument is
// the child of the second argument. _parent is kNoParent if the
// _current joint is a root. _from indicates the joint from which the joint
// hierarchy traversal begins. Use Skeleton::kNoParent to traverse the
// whole hierarchy, in case there are multiple roots.
// _Fct is of type void(int _current, int _parent) where the first argument
// is the child of the second argument. _parent is kNoParent if the _current
// joint is a root. _from indicates the joint from which the joint hierarchy
// traversal begins. Use Skeleton::kNoParent to traverse the whole
// hierarchy, in case there are multiple roots.
template <typename _Fct>
inline _Fct IterateJointsDF(const Skeleton& _skeleton, _Fct _fct,
int _from = Skeleton::kNoParent) {

View File

@ -28,12 +28,12 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_TRACK_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_TRACK_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
#include "ozz/base/maths/quaternion.h"
#include "ozz/base/maths/vec_float.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
namespace ozz {
namespace animation {
@ -54,11 +54,20 @@ namespace internal {
// coherently. Ratios are usually accessed/read alone from the jobs that all
// start by looking up the keyframes to interpolate indeed.
template <typename _ValueType>
class Track {
class OZZ_ANIMATION_DLL Track {
public:
typedef _ValueType ValueType;
Track();
// Allow move.
Track(Track&& _other);
Track& operator=(Track&& _other);
// Disables copy and assignation.
Track(Track const&) = delete;
void operator=(Track const&) = delete;
~Track();
// Keyframe accessors.
@ -78,10 +87,6 @@ class Track {
void Load(ozz::io::IArchive& _archive, uint32_t _version);
private:
// Disables copy and assignation.
Track(Track const&);
void operator=(Track const&);
// TrackBuilder class is allowed to allocate a Track.
friend class offline::TrackBuilder;
@ -99,7 +104,7 @@ class Track {
span<uint8_t> steps_;
// Track name.
char* name_;
char* name_ = nullptr;
};
// Definition of operations policies per track value type.
@ -146,11 +151,12 @@ inline math::Quaternion TrackPolicy<math::Quaternion>::identity() {
} // namespace internal
// Runtime track data structure instantiation.
class FloatTrack : public internal::Track<float> {};
class Float2Track : public internal::Track<math::Float2> {};
class Float3Track : public internal::Track<math::Float3> {};
class Float4Track : public internal::Track<math::Float4> {};
class QuaternionTrack : public internal::Track<math::Quaternion> {};
class OZZ_ANIMATION_DLL FloatTrack : public internal::Track<float> {};
class OZZ_ANIMATION_DLL Float2Track : public internal::Track<math::Float2> {};
class OZZ_ANIMATION_DLL Float3Track : public internal::Track<math::Float3> {};
class OZZ_ANIMATION_DLL Float4Track : public internal::Track<math::Float4> {};
class OZZ_ANIMATION_DLL QuaternionTrack
: public internal::Track<math::Quaternion> {};
} // namespace animation
namespace io {

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_TRACK_SAMPLING_JOB_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_TRACK_SAMPLING_JOB_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/animation/runtime/track.h"
namespace ozz {
@ -65,14 +66,15 @@ struct TrackSamplingJob {
// Track sampling job implementation. Track sampling allows to query a track
// value for a specified ratio. This is a ratio rather than a time because
// tracks have no duration.
struct FloatTrackSamplingJob : public internal::TrackSamplingJob<FloatTrack> {};
struct Float2TrackSamplingJob : public internal::TrackSamplingJob<Float2Track> {
};
struct Float3TrackSamplingJob : public internal::TrackSamplingJob<Float3Track> {
};
struct Float4TrackSamplingJob : public internal::TrackSamplingJob<Float4Track> {
};
struct QuaternionTrackSamplingJob
struct OZZ_ANIMATION_DLL FloatTrackSamplingJob
: public internal::TrackSamplingJob<FloatTrack> {};
struct OZZ_ANIMATION_DLL Float2TrackSamplingJob
: public internal::TrackSamplingJob<Float2Track> {};
struct OZZ_ANIMATION_DLL Float3TrackSamplingJob
: public internal::TrackSamplingJob<Float3Track> {};
struct OZZ_ANIMATION_DLL Float4TrackSamplingJob
: public internal::TrackSamplingJob<Float4Track> {};
struct OZZ_ANIMATION_DLL QuaternionTrackSamplingJob
: public internal::TrackSamplingJob<QuaternionTrack> {};
} // namespace animation

View File

@ -28,6 +28,7 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_TRACK_TRIGGERING_JOB_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_TRACK_TRIGGERING_JOB_H_
#include "ozz/animation/runtime/export.h"
#include "ozz/base/platform.h"
namespace ozz {
@ -46,7 +47,7 @@ class FloatTrack;
// track types isn't possible.
// The job execution actually performs a lazy evaluation of edges. It builds an
// iterator that will process the next edge on each call to ++ operator.
struct TrackTriggeringJob {
struct OZZ_ANIMATION_DLL TrackTriggeringJob {
TrackTriggeringJob();
// Validates job parameters.
@ -95,7 +96,7 @@ struct TrackTriggeringJob {
// Iterator implementation. Calls to ++ operator will compute the next edge. It
// should be compared (using operator !=) to job's end iterator to test if the
// last edge has been reached.
class TrackTriggeringJob::Iterator {
class OZZ_ANIMATION_DLL TrackTriggeringJob::Iterator {
public:
Iterator() : job_(nullptr), outer_(0.f), inner_(0) {}

View File

@ -28,6 +28,8 @@
#ifndef OZZ_OZZ_ANIMATION_RUNTIME_TRACK_TRIGGERING_JOB_TRAIT_H_
#define OZZ_OZZ_ANIMATION_RUNTIME_TRACK_TRIGGERING_JOB_TRAIT_H_
#include "ozz/animation/runtime/export.h"
// Defines iterator traits required to use TrackTriggeringJob::Iterator
// with stl algorithms.
// This is a separate file from "track_triggering_job.h" to prevent everyone

View File

@ -0,0 +1,73 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_BASE_CONTAINERS_ARRAY_H_
#define OZZ_OZZ_BASE_CONTAINERS_ARRAY_H_
#include <array>
#include "ozz/base/platform.h"
namespace ozz {
// Redirects std::array to ozz::array .
template <class _Ty, size_t _N>
using array = std::array<_Ty, _N>;
// Extends std::array with two functions that gives access to the begin and the
// end of its array of elements.
// Returns the mutable begin of the array of elements, or nullptr if
// array's empty.
template <class _Ty, size_t _N>
inline _Ty* array_begin(std::array<_Ty, _N>& _array) {
return _array.data();
}
// Returns the non-mutable begin of the array of elements, or nullptr if
// array's empty.
template <class _Ty, size_t _N>
inline const _Ty* array_begin(const std::array<_Ty, _N>& _array) {
return _array.data();
}
// Returns the mutable end of the array of elements, or nullptr if
// array's empty. Array end is one element past the last element of the
// array, it cannot be dereferenced.
template <class _Ty, size_t _N>
inline _Ty* array_end(std::array<_Ty, _N>& _array) {
return _array.data() + _N;
}
// Returns the non-mutable end of the array of elements, or nullptr if
// array's empty. Array end is one element past the last element of the
// array, it cannot be dereferenced.
template <class _Ty, size_t _N>
inline const _Ty* array_end(const std::array<_Ty, _N>& _array) {
return _array.data() + _N;
}
} // namespace ozz
#endif // OZZ_OZZ_BASE_CONTAINERS_ARRAY_H_

View File

@ -0,0 +1,63 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_BASE_CONTAINERS_ARRAY_ARCHIVE_H_
#define OZZ_OZZ_BASE_CONTAINERS_ARRAY_ARCHIVE_H_
#include "ozz/base/containers/array.h"
#include "ozz/base/io/archive.h"
namespace ozz {
namespace io {
OZZ_IO_TYPE_NOT_VERSIONABLE_T2(class _Ty, size_t _N, std::array<_Ty, _N>)
template <class _Ty, size_t _N>
struct Extern<std::array<_Ty, _N>> {
inline static void Save(OArchive& _archive,
const std::array<_Ty, _N>* _values, size_t _count) {
if (void(0), _N != 0) {
for (size_t i = 0; i < _count; i++) {
const std::array<_Ty, _N>& array = _values[i];
_archive << ozz::io::MakeArray(array.data(), _N);
}
}
}
inline static void Load(IArchive& _archive, std::array<_Ty, _N>* _values,
size_t _count, uint32_t _version) {
(void)_version;
if (void(0), _N != 0) {
for (size_t i = 0; i < _count; i++) {
std::array<_Ty, _N>& array = _values[i];
_archive >> ozz::io::MakeArray(array.data(), _N);
}
}
}
};
} // namespace io
} // namespace ozz
#endif // OZZ_OZZ_BASE_CONTAINERS_ARRAY_ARCHIVE_H_

View File

@ -49,7 +49,7 @@ class StdAllocator {
StdAllocator(const StdAllocator&) noexcept {}
template <class _Other>
StdAllocator<value_type>(const StdAllocator<_Other>&) noexcept {}
StdAllocator(const StdAllocator<_Other>&) noexcept {}
template <class _Other>
struct rebind {

View File

@ -38,7 +38,7 @@ namespace io {
OZZ_IO_TYPE_NOT_VERSIONABLE(ozz::string)
template <>
struct Extern<ozz::string> {
struct OZZ_BASE_DLL Extern<ozz::string> {
static void Save(OArchive& _archive, const ozz::string* _values,
size_t _count);
static void Load(IArchive& _archive, ozz::string* _values, size_t _count,

View File

@ -48,7 +48,7 @@ struct Extern<std::vector<_Ty, _Allocator>> {
const uint32_t size = static_cast<uint32_t>(vector.size());
_archive << size;
if (size > 0) {
_archive << ozz::io::MakeArray(&vector[0], size);
_archive << ozz::io::MakeArray(vector.data(), size);
}
}
}
@ -62,7 +62,7 @@ struct Extern<std::vector<_Ty, _Allocator>> {
_archive >> size;
vector.resize(size);
if (size > 0) {
_archive >> ozz::io::MakeArray(&vector[0], size);
_archive >> ozz::io::MakeArray(vector.data(), size);
}
}
}

View File

@ -66,20 +66,17 @@ template <typename _Ty, size_t _size = sizeof(_Ty)>
struct EndianSwapper;
// Internal macro used to swap two bytes.
#define OZZ_BYTE_SWAP(_a, _b) \
do { \
const char temp = _a; \
_a = _b; \
_b = temp; \
#define OZZ_BYTE_SWAP(_a, _b) \
do { \
const ozz::byte temp = (_a); \
(_a) = (_b); \
(_b) = temp; \
} while (0)
// EndianSwapper specialization for 1 byte types.
template <typename _Ty>
struct EndianSwapper<_Ty, 1> {
OZZ_INLINE static void Swap(_Ty* _ty, size_t _count) {
(void)_ty;
(void)_count;
}
OZZ_INLINE static void Swap(_Ty*, size_t) {}
OZZ_INLINE static _Ty Swap(_Ty _ty) { return _ty; }
};
@ -87,13 +84,13 @@ struct EndianSwapper<_Ty, 1> {
template <typename _Ty>
struct EndianSwapper<_Ty, 2> {
OZZ_INLINE static void Swap(_Ty* _ty, size_t _count) {
char* alias = reinterpret_cast<char*>(_ty);
byte* alias = reinterpret_cast<byte*>(_ty);
for (size_t i = 0; i < _count * 2; i += 2) {
OZZ_BYTE_SWAP(alias[i + 0], alias[i + 1]);
}
}
OZZ_INLINE static _Ty Swap(_Ty _ty) { // Pass by copy to swap _ty in-place.
char* alias = reinterpret_cast<char*>(&_ty);
byte* alias = reinterpret_cast<byte*>(&_ty);
OZZ_BYTE_SWAP(alias[0], alias[1]);
return _ty;
}
@ -103,14 +100,14 @@ struct EndianSwapper<_Ty, 2> {
template <typename _Ty>
struct EndianSwapper<_Ty, 4> {
OZZ_INLINE static void Swap(_Ty* _ty, size_t _count) {
char* alias = reinterpret_cast<char*>(_ty);
byte* alias = reinterpret_cast<byte*>(_ty);
for (size_t i = 0; i < _count * 4; i += 4) {
OZZ_BYTE_SWAP(alias[i + 0], alias[i + 3]);
OZZ_BYTE_SWAP(alias[i + 1], alias[i + 2]);
}
}
OZZ_INLINE static _Ty Swap(_Ty _ty) { // Pass by copy to swap _ty in-place.
char* alias = reinterpret_cast<char*>(&_ty);
byte* alias = reinterpret_cast<byte*>(&_ty);
OZZ_BYTE_SWAP(alias[0], alias[3]);
OZZ_BYTE_SWAP(alias[1], alias[2]);
return _ty;
@ -121,7 +118,7 @@ struct EndianSwapper<_Ty, 4> {
template <typename _Ty>
struct EndianSwapper<_Ty, 8> {
OZZ_INLINE static void Swap(_Ty* _ty, size_t _count) {
char* alias = reinterpret_cast<char*>(_ty);
byte* alias = reinterpret_cast<byte*>(_ty);
for (size_t i = 0; i < _count * 8; i += 8) {
OZZ_BYTE_SWAP(alias[i + 0], alias[i + 7]);
OZZ_BYTE_SWAP(alias[i + 1], alias[i + 6]);
@ -130,7 +127,7 @@ struct EndianSwapper<_Ty, 8> {
}
}
OZZ_INLINE static _Ty Swap(_Ty _ty) { // Pass by copy to swap _ty in-place.
char* alias = reinterpret_cast<char*>(&_ty);
byte* alias = reinterpret_cast<byte*>(&_ty);
OZZ_BYTE_SWAP(alias[0], alias[7]);
OZZ_BYTE_SWAP(alias[1], alias[6]);
OZZ_BYTE_SWAP(alias[2], alias[5]);

View File

@ -0,0 +1,44 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#ifndef OZZ_OZZ_BASE_EXPORT_H_
#define OZZ_OZZ_BASE_EXPORT_H_
#if defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#ifdef OZZ_BUILD_BASE_LIB
// Import/Export for dynamic linking while building ozz
#define OZZ_BASE_DLL __declspec(dllexport)
#else
#define OZZ_BASE_DLL __declspec(dllimport)
#endif
#else // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
// Static or non msvc linking
#define OZZ_BASE_DLL
#endif // defined(_MSC_VER) && defined(OZZ_USE_DYNAMIC_LINKING)
#endif // OZZ_OZZ_BASE_EXPORT_H_

View File

@ -77,16 +77,16 @@
// integrity, like data corruption or file truncation, must also be validated on
// the user side.
#include <stdint.h>
#include <cassert>
#include "ozz/base/endianness.h"
#include "ozz/base/io/archive_traits.h"
#include "ozz/base/io/stream.h"
#include "ozz/base/platform.h"
#include "ozz/base/span.h"
#include <stdint.h>
#include <cassert>
#include "ozz/base/io/archive_traits.h"
namespace ozz {
namespace io {
namespace internal {
@ -102,7 +102,7 @@ struct Tagger;
// The output endianness mode is set at construction time. It is written to the
// stream to allow the IArchive to perform the required conversion to the native
// endianness mode while reading.
class OArchive {
class OZZ_BASE_DLL OArchive {
public:
// Constructs an output archive from the Stream _stream that must be valid
// and opened for writing.
@ -126,7 +126,7 @@ class OArchive {
}
// Primitive type saving.
#define OZZ_IO_PRIMITIVE_TYPE(_type) \
#define OZZ_IO_PRIMITIVE_TYPE(_type) \
void operator<<(_type _v) { \
_type v = endian_swap_ ? EndianSwapper<_type>::Swap(_v) : _v; \
OZZ_IF_DEBUG(size_t size =) stream_->Write(&v, sizeof(v)); \
@ -171,7 +171,7 @@ class OArchive {
// Implements input archive concept used to load/de-serialize data to a Stream.
// Endianness conversions are automatically performed according to the Archive
// and the native formats.
class IArchive {
class OZZ_BASE_DLL IArchive {
public:
// Constructs an input archive from the Stream _stream that must be opened for
// reading, at the same tell (position in the stream) as when it was passed to
@ -199,7 +199,7 @@ class IArchive {
}
// Primitive type loading.
#define OZZ_IO_PRIMITIVE_TYPE(_type) \
#define OZZ_IO_PRIMITIVE_TYPE(_type) \
void operator>>(_type& _v) { \
_type v; \
OZZ_IF_DEBUG(size_t size =) stream_->Read(&v, sizeof(v)); \
@ -314,7 +314,7 @@ struct Version<const Array<_Ty>> {
};
// Specializes Array Save/Load for primitive types.
#define OZZ_IO_PRIMITIVE_TYPE(_type) \
#define OZZ_IO_PRIMITIVE_TYPE(_type) \
template <> \
inline void Array<const _type>::Save(OArchive& _archive) const { \
if (_archive.endian_swap()) { \

View File

@ -31,16 +31,16 @@
// Provides Stream interface used to read/write a memory buffer or a file with
// Crt fread/fwrite/fseek/ftell like functions.
#include "ozz/base/platform.h"
#include <cstddef>
#include "ozz/base/platform.h"
namespace ozz {
namespace io {
// Declares a stream access interface that conforms with CRT FILE API.
// This interface should be used to remap io operations.
class Stream {
class OZZ_BASE_DLL Stream {
public:
// Tests whether a file is opened.
virtual bool opened() const = 0;
@ -86,7 +86,7 @@ class Stream {
};
// Implements Stream of type File.
class File : public Stream {
class OZZ_BASE_DLL File : public Stream {
public:
// Test if a file at path _filename exists.
// Note that this function is costly. If you aim to open the file right after,
@ -133,7 +133,7 @@ class File : public Stream {
// Implements an in-memory Stream. Allows to use a memory buffer as a Stream.
// The opening mode is equivalent to fopen w+b (binary read/write).
class MemoryStream : public Stream {
class OZZ_BASE_DLL MemoryStream : public Stream {
public:
// Construct an empty memory stream opened in w+b mode.
MemoryStream();
@ -172,7 +172,7 @@ class MemoryStream : public Stream {
static const size_t kMaxSize;
// Buffer of data.
char* buffer_;
byte* buffer_;
// The size of the buffer, which is greater or equal to the size of the data
// it contains (end_).

View File

@ -34,6 +34,8 @@
// So it is included here to ensure a portable behavior.
#include <cstring>
#include "platform.h"
// Proposes a logging interface that redirects logs to std::cout, clog and cerr
// output streams. This interface adds a logging level functionality (kSilent,
// kStandard, kVerbose) to the std API, which can be set using
@ -50,17 +52,17 @@ enum Level {
};
// Sets the global logging level.
Level SetLevel(Level _level);
OZZ_BASE_DLL Level SetLevel(Level _level);
// Gets the global logging level.
Level GetLevel();
OZZ_BASE_DLL Level GetLevel();
// Implements logging base class.
// This class is not intended to be used publicly, it is derived by user
// classes LogV, Log, Out, Err...
// Forwards ostream::operator << to a standard ostream or a silent
// ostringstream according to the logging level at construction time.
class Logger {
class OZZ_BASE_DLL Logger {
public:
// Forwards ostream::operator << for any type.
template <typename _T>
@ -101,28 +103,28 @@ class Logger {
// Logs verbose output to the standard error stream (std::clog).
// Enabled if logging level is Verbose.
class LogV : public Logger {
class OZZ_BASE_DLL LogV : public Logger {
public:
LogV();
};
// Logs output to the standard error stream (std::clog).
// Enabled if logging level is not Silent.
class Log : public Logger {
class OZZ_BASE_DLL Log : public Logger {
public:
Log();
};
// Logs output to the standard output (std::cout).
// Enabled if logging level is not Silent.
class Out : public Logger {
class OZZ_BASE_DLL Out : public Logger {
public:
Out();
};
// Logs error to the standard error stream (std::cerr).
// Enabled if logging level is not Silent.
class Err : public Logger {
class OZZ_BASE_DLL Err : public Logger {
public:
Err();
};
@ -131,7 +133,7 @@ class Err : public Logger {
// settings when exiting scope.
// User is reponsible for making sure stream still exist upon RAII destruction.
// See std::setprecision() for more details.
class FloatPrecision {
class OZZ_BASE_DLL FloatPrecision {
public:
FloatPrecision(const Logger& _logger, int _precision);
~FloatPrecision();

View File

@ -39,7 +39,7 @@ namespace math {
struct Float4x4;
// Defines an axis aligned box.
struct Box {
struct OZZ_BASE_DLL Box {
// Constructs an invalid box.
Box();
@ -78,7 +78,7 @@ OZZ_INLINE Box Merge(const Box& _a, const Box& _b) {
}
// Compute box transformation by a matrix.
Box TransformBox(const Float4x4& _matrix, const Box& _box);
OZZ_BASE_DLL Box TransformBox(const Float4x4& _matrix, const Box& _box);
} // namespace math
} // namespace ozz
#endif // OZZ_OZZ_BASE_MATHS_BOX_H_

View File

@ -152,7 +152,8 @@ typedef const SimdInt4& _SimdInt4;
} // namespace ozz
#endif // OZZ_SIMD_x
// Native SIMD operator already exist on some compilers, so they have to be disable from ozz implementation
// Native SIMD operator already exist on some compilers, so they have to be
// disable from ozz implementation
#if !defined(OZZ_SIMD_REF) && (defined(__GNUC__) || defined(__llvm__))
#define OZZ_DISABLE_SSE_NATIVE_OPERATORS
#endif

View File

@ -31,6 +31,7 @@
// SIMD refence implementation, based on scalar floats.
#include <stdint.h>
#include <cassert>
#include <cmath>
#include <cstddef>
@ -1820,22 +1821,9 @@ OZZ_INLINE bool ToAffine(const Float4x4& _m, SimdFloat4* _translation,
}
OZZ_INLINE Float4x4 Float4x4::FromEuler(_SimdFloat4 _v) {
const float ch = std::cos(_v.x);
const float sh = std::sin(_v.x);
const float ca = std::cos(_v.y);
const float sa = std::sin(_v.y);
const float cb = std::cos(_v.z);
const float sb = std::sin(_v.z);
const float sa_cb = sa * cb;
const float sa_sb = sa * sb;
const Float4x4 ret = {
{{ch * ca, sh * sb - ch * sa_cb, ch * sa_sb + sh * cb, 0.f},
{sa, ca * cb, -ca * sb, 0.f},
{-sh * ca, sh * sa_cb + ch * sb, -sh * sa_sb + ch * cb, 0.f},
{0.f, 0.f, 0.f, 1.f}}};
return ret;
return Float4x4::FromAxisAngle(simd_float4::y_axis(), SplatX(_v)) *
Float4x4::FromAxisAngle(simd_float4::x_axis(), SplatY(_v)) *
Float4x4::FromAxisAngle(simd_float4::z_axis(), SplatZ(_v));
}
OZZ_INLINE Float4x4 Float4x4::FromAxisAngle(_SimdFloat4 _axis,

View File

@ -31,6 +31,7 @@
// SIMD SSE2+ implementation, based on scalar floats.
#include <stdint.h>
#include <cassert>
// Temporarly needed while trigonometric functions aren't implemented.
@ -1294,7 +1295,7 @@ OZZ_INLINE SimdInt4 Sign(_SimdInt4 _v) {
OZZ_INLINE SimdInt4 Min(_SimdInt4 _a, _SimdInt4 _b) {
#ifdef OZZ_SIMD_SSE4_1
return _mm_min_epi32(_a, _b);
#else // OZZ_SIMD_SSE4_1
#else // OZZ_SIMD_SSE4_1
return OZZ_SSE_SELECT_I(_mm_cmplt_epi32(_a, _b), _a, _b);
#endif // OZZ_SIMD_SSE4_1
}
@ -1302,7 +1303,7 @@ OZZ_INLINE SimdInt4 Min(_SimdInt4 _a, _SimdInt4 _b) {
OZZ_INLINE SimdInt4 Max(_SimdInt4 _a, _SimdInt4 _b) {
#ifdef OZZ_SIMD_SSE4_1
return _mm_max_epi32(_a, _b);
#else // OZZ_SIMD_SSE4_1
#else // OZZ_SIMD_SSE4_1
return OZZ_SSE_SELECT_I(_mm_cmpgt_epi32(_a, _b), _a, _b);
#endif // OZZ_SIMD_SSE4_1
}
@ -1775,26 +1776,9 @@ inline bool ToAffine(const Float4x4& _m, SimdFloat4* _translation,
}
inline Float4x4 Float4x4::FromEuler(_SimdFloat4 _v) {
const __m128 cos = Cos(_v);
const __m128 sin = Sin(_v);
const float cx = GetX(cos);
const float sx = GetX(sin);
const float cy = GetY(cos);
const float sy = GetY(sin);
const float cz = GetZ(cos);
const float sz = GetZ(sin);
const float sycz = sy * cz;
const float sysz = sy * sz;
const Float4x4 ret = {{simd_float4::Load(cx * cy, sx * sz - cx * sycz,
cx * sysz + sx * cz, 0.f),
simd_float4::Load(sy, cy * cz, -cy * sz, 0.f),
simd_float4::Load(-sx * cy, sx * sycz + cx * sz,
-sx * sysz + cx * cz, 0.f),
simd_float4::w_axis()}};
return ret;
return Float4x4::FromAxisAngle(simd_float4::y_axis(), SplatX(_v)) *
Float4x4::FromAxisAngle(simd_float4::x_axis(), SplatY(_v)) *
Float4x4::FromAxisAngle(simd_float4::z_axis(), SplatZ(_v));
}
inline Float4x4 Float4x4::FromAxisAngle(_SimdFloat4 _axis, _SimdFloat4 _angle) {

Some files were not shown because too many files have changed in this diff Show More