Main
This commit is contained in:
parent
f88c571faa
commit
a9bfb2d27a
22
.vscode/c_cpp_properties.json
vendored
Normal file
22
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Win32",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"C:/msys64/mingw64/include/**"
|
||||||
|
],
|
||||||
|
"defines": [
|
||||||
|
"_DEBUG",
|
||||||
|
"UNICODE",
|
||||||
|
"_UNICODE"
|
||||||
|
],
|
||||||
|
"windowsSdkVersion": "10.0.22621.0",
|
||||||
|
"compilerPath": "C:/msys64/mingw64/bin/g++.exe",
|
||||||
|
"cStandard": "c23",
|
||||||
|
"cppStandard": "c++23",
|
||||||
|
"intelliSenseMode": "windows-gcc-x64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
25
.vscode/launch.json
vendored
Normal file
25
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug Game Engine",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/build/game_engine.exe", // Path to your executable
|
||||||
|
"args": [], // Add arguments to pass to your program if necessary
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe", // Path to your GDB executable
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
77
.vscode/settings.json
vendored
Normal file
77
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"*.pyx": "python",
|
||||||
|
"*.js": "javascript",
|
||||||
|
"*.c": "c",
|
||||||
|
"array": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"charconv": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"compare": "cpp",
|
||||||
|
"concepts": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
|
"map": "cpp",
|
||||||
|
"set": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"algorithm": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"memory_resource": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"format": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"iostream": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"numbers": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"ranges": "cpp",
|
||||||
|
"span": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"text_encoding": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"variant": "cpp",
|
||||||
|
"valarray": "cpp",
|
||||||
|
"filesystem": "cpp",
|
||||||
|
"codecvt": "cpp",
|
||||||
|
"ratio": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"condition_variable": "cpp",
|
||||||
|
"mutex": "cpp",
|
||||||
|
"semaphore": "cpp",
|
||||||
|
"stop_token": "cpp",
|
||||||
|
"thread": "cpp"
|
||||||
|
}
|
||||||
|
}
|
28
.vscode/tasks.json
vendored
Normal file
28
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "Build with Makefile",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "mingw32-make",
|
||||||
|
"args": ["all"], // Use the "all" target from your Makefile
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"problemMatcher": ["$gcc"],
|
||||||
|
"detail": "Task to build the project using the provided Makefile."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Clean with Makefile",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "mingw32-make",
|
||||||
|
"args": ["clean"], // Use the "clean" target from your Makefile
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": false
|
||||||
|
},
|
||||||
|
"detail": "Task to clean the project using the provided Makefile."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
55
Makefile
Normal file
55
Makefile
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# Compiler
|
||||||
|
CC = g++
|
||||||
|
|
||||||
|
# Compiler flags
|
||||||
|
CFLAGS = -Wall -g
|
||||||
|
|
||||||
|
# Paths to include directories (Adjust these paths to your installation)
|
||||||
|
IMG_INCLUDE_DIR = include
|
||||||
|
IMGUI_INCLUDE_DIR = imgui
|
||||||
|
SDL2_LIB_DIR = C:/msys64/mingw64/bin
|
||||||
|
LIB_DIR = lib
|
||||||
|
|
||||||
|
# Include directories
|
||||||
|
INCLUDE_DIRS = -I$(IMG_INCLUDE_DIR) -I$(IMGUI_INCLUDE_DIR)
|
||||||
|
|
||||||
|
# Library directories
|
||||||
|
LIB_DIRS = -L$(SDL2_LIB_DIR) -L$(LIB_DIR)
|
||||||
|
|
||||||
|
# Libraries to link
|
||||||
|
LIBS = -lmingw32 -lglfw3 -lopengl32 -lglew32 -lyaml-cpp -lcomdlg32
|
||||||
|
|
||||||
|
# Source directories
|
||||||
|
SRC_DIR = src
|
||||||
|
IMGUI_DIR = imgui
|
||||||
|
|
||||||
|
# Object directory
|
||||||
|
OBJ_DIR = build
|
||||||
|
|
||||||
|
# Source files
|
||||||
|
SOURCES = $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(IMGUI_DIR)/*.cpp)
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
OBJECTS = $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SOURCES))
|
||||||
|
OBJECTS := $(patsubst $(IMGUI_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(OBJECTS))
|
||||||
|
|
||||||
|
# Executable name
|
||||||
|
EXECUTABLE = $(OBJ_DIR)/game_engine.exe
|
||||||
|
|
||||||
|
# Build target
|
||||||
|
all: $(OBJ_DIR) $(EXECUTABLE)
|
||||||
|
|
||||||
|
$(OBJ_DIR):
|
||||||
|
mkdir $(OBJ_DIR)
|
||||||
|
|
||||||
|
$(EXECUTABLE): $(OBJECTS)
|
||||||
|
$(CC) $(OBJECTS) -o $@ $(LIB_DIRS) $(LIBS)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||||
|
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $< -o $@
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(IMGUI_DIR)/%.cpp
|
||||||
|
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $< -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
del /Q $(OBJ_DIR)\*.o
|
1274
assets/cottage_obj.obj
Normal file
1274
assets/cottage_obj.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
assets/creative-technology-showreel-241274.mp3
Normal file
BIN
assets/creative-technology-showreel-241274.mp3
Normal file
Binary file not shown.
0
assets/scenes/Empty.polys
Normal file
0
assets/scenes/Empty.polys
Normal file
28
assets/scenes/Scene.polys
Normal file
28
assets/scenes/Scene.polys
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Entities:
|
||||||
|
- ID: 0
|
||||||
|
Name: Light
|
||||||
|
Components:
|
||||||
|
Light:
|
||||||
|
Type: 2
|
||||||
|
Intensity: 9.30000019
|
||||||
|
Color: [1, 1, 1]
|
||||||
|
Constant: 1
|
||||||
|
Linear: 0.0900000036
|
||||||
|
Quadratic: 0.0320000015
|
||||||
|
cutOff: 0
|
||||||
|
outerCutOff: 39.7900009
|
||||||
|
Direction: [-0.200000003, -1, -0.300000012]
|
||||||
|
Transform:
|
||||||
|
Position: [-1.70000005, -0.200000003, -0.100000001]
|
||||||
|
Rotation: [1.5, 2.70000005, -17.5]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
|
- ID: 1
|
||||||
|
Name: Cube
|
||||||
|
Components:
|
||||||
|
Render:
|
||||||
|
MeshName: WhiteCube
|
||||||
|
Color: [1, 1, 1]
|
||||||
|
Transform:
|
||||||
|
Position: [-1.21370173, 1.20000005, 0]
|
||||||
|
Rotation: [1.34287302e-05, -41.9440002, 1.62548586e-05]
|
||||||
|
Scale: [1, 1, 1]
|
18
assets/scenes/light.polys
Normal file
18
assets/scenes/light.polys
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Entities:
|
||||||
|
- ID: 0
|
||||||
|
Name: Entity 0
|
||||||
|
Components:
|
||||||
|
Light:
|
||||||
|
Type: 0
|
||||||
|
Intensity: 1
|
||||||
|
Color: [1, 1, 1]
|
||||||
|
Constant: 1
|
||||||
|
Linear: 0.0900000036
|
||||||
|
Quadratic: 0.0320000015
|
||||||
|
cutOff: 12.5
|
||||||
|
outerCutOff: 17.5
|
||||||
|
Direction: [-0.200000003, -1, -0.300000012]
|
||||||
|
Transform:
|
||||||
|
Position: [0, 0, 0]
|
||||||
|
Rotation: [0, 0, 0]
|
||||||
|
Scale: [1, 1, 1]
|
8
assets/scenes/scene1.polys
Normal file
8
assets/scenes/scene1.polys
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Entities:
|
||||||
|
- ID: 0
|
||||||
|
Name: Entity 0
|
||||||
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [0, 0, 0]
|
||||||
|
Rotation: [0, 0, 0]
|
||||||
|
Scale: [1, 1, 1]
|
BIN
assets/texture.png
Normal file
BIN
assets/texture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 MiB |
BIN
assets/textures/texture.jpg
Normal file
BIN
assets/textures/texture.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 MiB |
BIN
build/CollisionShape3DComponent.o
Normal file
BIN
build/CollisionShape3DComponent.o
Normal file
Binary file not shown.
BIN
build/EditorCamera.o
Normal file
BIN
build/EditorCamera.o
Normal file
Binary file not shown.
BIN
build/Entity.o
Normal file
BIN
build/Entity.o
Normal file
Binary file not shown.
BIN
build/GraphEditor.o
Normal file
BIN
build/GraphEditor.o
Normal file
Binary file not shown.
BIN
build/ImCurveEdit.o
Normal file
BIN
build/ImCurveEdit.o
Normal file
Binary file not shown.
BIN
build/ImGradient.o
Normal file
BIN
build/ImGradient.o
Normal file
Binary file not shown.
BIN
build/ImGuiStyle.o
Normal file
BIN
build/ImGuiStyle.o
Normal file
Binary file not shown.
BIN
build/ImGuizmo.o
Normal file
BIN
build/ImGuizmo.o
Normal file
Binary file not shown.
BIN
build/ImSequencer.o
Normal file
BIN
build/ImSequencer.o
Normal file
Binary file not shown.
BIN
build/LightComponent.o
Normal file
BIN
build/LightComponent.o
Normal file
Binary file not shown.
BIN
build/LogSystem.o
Normal file
BIN
build/LogSystem.o
Normal file
Binary file not shown.
BIN
build/RenderComponent.o
Normal file
BIN
build/RenderComponent.o
Normal file
Binary file not shown.
BIN
build/RigidBody3DComponent.o
Normal file
BIN
build/RigidBody3DComponent.o
Normal file
Binary file not shown.
BIN
build/Shader.o
Normal file
BIN
build/Shader.o
Normal file
Binary file not shown.
BIN
build/TransformComponent.o
Normal file
BIN
build/TransformComponent.o
Normal file
Binary file not shown.
BIN
build/game_engine.exe
Normal file
BIN
build/game_engine.exe
Normal file
Binary file not shown.
BIN
build/imgui.o
Normal file
BIN
build/imgui.o
Normal file
Binary file not shown.
BIN
build/imgui_demo.o
Normal file
BIN
build/imgui_demo.o
Normal file
Binary file not shown.
BIN
build/imgui_draw.o
Normal file
BIN
build/imgui_draw.o
Normal file
Binary file not shown.
BIN
build/imgui_impl_glfw.o
Normal file
BIN
build/imgui_impl_glfw.o
Normal file
Binary file not shown.
BIN
build/imgui_impl_opengl3.o
Normal file
BIN
build/imgui_impl_opengl3.o
Normal file
Binary file not shown.
BIN
build/imgui_tables.o
Normal file
BIN
build/imgui_tables.o
Normal file
Binary file not shown.
BIN
build/imgui_widgets.o
Normal file
BIN
build/imgui_widgets.o
Normal file
Binary file not shown.
BIN
build/main.o
Normal file
BIN
build/main.o
Normal file
Binary file not shown.
BIN
build/modelImported.o
Normal file
BIN
build/modelImported.o
Normal file
Binary file not shown.
1274
cottage_obj.obj
Normal file
1274
cottage_obj.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
fonts/font.ttf
Normal file
BIN
fonts/font.ttf
Normal file
Binary file not shown.
BIN
fonts/primary.ttf
Normal file
BIN
fonts/primary.ttf
Normal file
Binary file not shown.
BIN
fonts/upheavtt.ttf
Normal file
BIN
fonts/upheavtt.ttf
Normal file
Binary file not shown.
59
imgui.ini
Normal file
59
imgui.ini
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
[Window][DockSpace Window]
|
||||||
|
Pos=0,20
|
||||||
|
Size=1280,720
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=60,60
|
||||||
|
Size=400,400
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Entity Component Tree]
|
||||||
|
Pos=318,28
|
||||||
|
Size=197,1161
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000005,0
|
||||||
|
|
||||||
|
[Window][Game View]
|
||||||
|
Pos=312,28
|
||||||
|
Size=626,322
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000009,0
|
||||||
|
|
||||||
|
[Window][Asset Panel]
|
||||||
|
Pos=8,379
|
||||||
|
Size=302,353
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000008,0
|
||||||
|
|
||||||
|
[Window][Inspector]
|
||||||
|
Pos=940,28
|
||||||
|
Size=332,704
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000004,0
|
||||||
|
|
||||||
|
[Window][Scene]
|
||||||
|
Pos=8,28
|
||||||
|
Size=302,349
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000007,0
|
||||||
|
|
||||||
|
[Window][Info]
|
||||||
|
Pos=312,352
|
||||||
|
Size=626,380
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x0000000A,0
|
||||||
|
|
||||||
|
[Docking][Data]
|
||||||
|
DockSpace ID=0xC746EC7D Window=0x9DF47A72 Pos=8,28 Size=1264,704 Split=X Selected=0x642CEEBB
|
||||||
|
DockNode ID=0x00000003 Parent=0xC746EC7D SizeRef=1570,1161 Split=X
|
||||||
|
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=302,1161 Split=Y Selected=0x9D571615
|
||||||
|
DockNode ID=0x00000007 Parent=0x00000001 SizeRef=580,577 Selected=0xE192E354
|
||||||
|
DockNode ID=0x00000008 Parent=0x00000001 SizeRef=580,582 Selected=0x9D571615
|
||||||
|
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1600,1161 Split=X
|
||||||
|
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=197,1161 Selected=0x4E0EE8E4
|
||||||
|
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=1035,1161 Split=Y Selected=0x642CEEBB
|
||||||
|
DockNode ID=0x00000009 Parent=0x00000006 SizeRef=1266,779 CentralNode=1 Selected=0x642CEEBB
|
||||||
|
DockNode ID=0x0000000A Parent=0x00000006 SizeRef=1266,380 Selected=0xE534E588
|
||||||
|
DockNode ID=0x00000004 Parent=0xC746EC7D SizeRef=332,1161 Selected=0xE7039252
|
||||||
|
|
1111
imgui/GraphEditor.cpp
Normal file
1111
imgui/GraphEditor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
457
imgui/ImCurveEdit.cpp
Normal file
457
imgui/ImCurveEdit.cpp
Normal file
@ -0,0 +1,457 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files(the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions :
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
#include "ImCurveEdit.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
#if !defined(_MSC_VER) && !defined(__MINGW64_VERSION_MAJOR)
|
||||||
|
#define _malloca(x) alloca(x)
|
||||||
|
#define _freea(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ImCurveEdit
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
static ImVec2 operator+(const ImVec2& a, const ImVec2& b) {
|
||||||
|
return ImVec2(a.x + b.x, a.y + b.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImVec2 operator-(const ImVec2& a, const ImVec2& b) {
|
||||||
|
return ImVec2(a.x - b.x, a.y - b.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImVec2 operator*(const ImVec2& a, const ImVec2& b) {
|
||||||
|
return ImVec2(a.x * b.x, a.y * b.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImVec2 operator/(const ImVec2& a, const ImVec2& b) {
|
||||||
|
return ImVec2(a.x / b.x, a.y / b.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ImVec2 operator*(const ImVec2& a, const float b) {
|
||||||
|
return ImVec2(a.x * b, a.y * b);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static float smoothstep(float edge0, float edge1, float x)
|
||||||
|
{
|
||||||
|
x = ImClamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
|
||||||
|
return x * x * (3 - 2 * x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float distance(float x, float y, float x1, float y1, float x2, float y2)
|
||||||
|
{
|
||||||
|
float A = x - x1;
|
||||||
|
float B = y - y1;
|
||||||
|
float C = x2 - x1;
|
||||||
|
float D = y2 - y1;
|
||||||
|
|
||||||
|
float dot = A * C + B * D;
|
||||||
|
float len_sq = C * C + D * D;
|
||||||
|
float param = -1.f;
|
||||||
|
if (len_sq > FLT_EPSILON)
|
||||||
|
param = dot / len_sq;
|
||||||
|
|
||||||
|
float xx, yy;
|
||||||
|
|
||||||
|
if (param < 0.f) {
|
||||||
|
xx = x1;
|
||||||
|
yy = y1;
|
||||||
|
}
|
||||||
|
else if (param > 1.f) {
|
||||||
|
xx = x2;
|
||||||
|
yy = y2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
xx = x1 + param * C;
|
||||||
|
yy = y1 + param * D;
|
||||||
|
}
|
||||||
|
|
||||||
|
float dx = x - xx;
|
||||||
|
float dy = y - yy;
|
||||||
|
return sqrtf(dx * dx + dy * dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int DrawPoint(ImDrawList* draw_list, ImVec2 pos, const ImVec2 size, const ImVec2 offset, bool edited)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
static const ImVec2 localOffsets[4] = { ImVec2(1,0), ImVec2(0,1), ImVec2(-1,0), ImVec2(0,-1) };
|
||||||
|
ImVec2 offsets[4];
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
offsets[i] = pos * size + localOffsets[i] * 4.5f + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ImVec2 center = pos * size + offset;
|
||||||
|
const ImRect anchor(center - ImVec2(5, 5), center + ImVec2(5, 5));
|
||||||
|
draw_list->AddConvexPolyFilled(offsets, 4, 0xFF000000);
|
||||||
|
if (anchor.Contains(io.MousePos))
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
if (io.MouseDown[0])
|
||||||
|
ret = 2;
|
||||||
|
}
|
||||||
|
if (edited)
|
||||||
|
draw_list->AddPolyline(offsets, 4, 0xFFFFFFFF, true, 3.0f);
|
||||||
|
else if (ret)
|
||||||
|
draw_list->AddPolyline(offsets, 4, 0xFF80B0FF, true, 2.0f);
|
||||||
|
else
|
||||||
|
draw_list->AddPolyline(offsets, 4, 0xFF0080FF, true, 2.0f);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Edit(Delegate& delegate, const ImVec2& size, unsigned int id, const ImRect* clippingRect, ImVector<EditPoint>* selectedPoints)
|
||||||
|
{
|
||||||
|
static bool selectingQuad = false;
|
||||||
|
static ImVec2 quadSelection;
|
||||||
|
static int overCurve = -1;
|
||||||
|
static int movingCurve = -1;
|
||||||
|
static bool scrollingV = false;
|
||||||
|
static std::set<EditPoint> selection;
|
||||||
|
static bool overSelectedPoint = false;
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Border, 0);
|
||||||
|
ImGui::BeginChild(id, size, ImGuiChildFlags_FrameStyle);
|
||||||
|
delegate.focused = ImGui::IsWindowFocused();
|
||||||
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
if (clippingRect)
|
||||||
|
draw_list->PushClipRect(clippingRect->Min, clippingRect->Max, true);
|
||||||
|
|
||||||
|
const ImVec2 offset = ImGui::GetCursorScreenPos() + ImVec2(0.f, size.y);
|
||||||
|
const ImVec2 ssize(size.x, -size.y);
|
||||||
|
const ImRect container(offset + ImVec2(0.f, ssize.y), offset + ImVec2(ssize.x, 0.f));
|
||||||
|
ImVec2& min = delegate.GetMin();
|
||||||
|
ImVec2& max = delegate.GetMax();
|
||||||
|
|
||||||
|
// handle zoom and VScroll
|
||||||
|
if (container.Contains(io.MousePos))
|
||||||
|
{
|
||||||
|
if (fabsf(io.MouseWheel) > FLT_EPSILON)
|
||||||
|
{
|
||||||
|
const float r = (io.MousePos.y - offset.y) / ssize.y;
|
||||||
|
float ratioY = ImLerp(min.y, max.y, r);
|
||||||
|
auto scaleValue = [&](float v) {
|
||||||
|
v -= ratioY;
|
||||||
|
v *= (1.f - io.MouseWheel * 0.05f);
|
||||||
|
v += ratioY;
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
min.y = scaleValue(min.y);
|
||||||
|
max.y = scaleValue(max.y);
|
||||||
|
}
|
||||||
|
if (!scrollingV && ImGui::IsMouseDown(2))
|
||||||
|
{
|
||||||
|
scrollingV = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImVec2 range = max - min + ImVec2(1.f, 0.f); // +1 because of inclusive last frame
|
||||||
|
|
||||||
|
const ImVec2 viewSize(size.x, -size.y);
|
||||||
|
const ImVec2 sizeOfPixel = ImVec2(1.f, 1.f) / viewSize;
|
||||||
|
const size_t curveCount = delegate.GetCurveCount();
|
||||||
|
|
||||||
|
if (scrollingV)
|
||||||
|
{
|
||||||
|
float deltaH = io.MouseDelta.y * range.y * sizeOfPixel.y;
|
||||||
|
min.y -= deltaH;
|
||||||
|
max.y -= deltaH;
|
||||||
|
if (!ImGui::IsMouseDown(2))
|
||||||
|
scrollingV = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_list->AddRectFilled(offset, offset + ssize, delegate.GetBackgroundColor());
|
||||||
|
|
||||||
|
auto pointToRange = [&](ImVec2 pt) { return (pt - min) / range; };
|
||||||
|
auto rangeToPoint = [&](ImVec2 pt) { return (pt * range) + min; };
|
||||||
|
|
||||||
|
draw_list->AddLine(ImVec2(-1.f, -min.y / range.y) * viewSize + offset, ImVec2(1.f, -min.y / range.y) * viewSize + offset, 0xFF000000, 1.5f);
|
||||||
|
bool overCurveOrPoint = false;
|
||||||
|
|
||||||
|
int localOverCurve = -1;
|
||||||
|
// make sure highlighted curve is rendered last
|
||||||
|
int* curvesIndex = (int*)_malloca(sizeof(int) * curveCount);
|
||||||
|
for (size_t c = 0; c < curveCount; c++)
|
||||||
|
curvesIndex[c] = int(c);
|
||||||
|
int highLightedCurveIndex = -1;
|
||||||
|
if (overCurve != -1 && curveCount)
|
||||||
|
{
|
||||||
|
ImSwap(curvesIndex[overCurve], curvesIndex[curveCount - 1]);
|
||||||
|
highLightedCurveIndex = overCurve;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t cur = 0; cur < curveCount; cur++)
|
||||||
|
{
|
||||||
|
int c = curvesIndex[cur];
|
||||||
|
if (!delegate.IsVisible(c))
|
||||||
|
continue;
|
||||||
|
const size_t ptCount = delegate.GetPointCount(c);
|
||||||
|
if (ptCount < 1)
|
||||||
|
continue;
|
||||||
|
CurveType curveType = delegate.GetCurveType(c);
|
||||||
|
if (curveType == CurveNone)
|
||||||
|
continue;
|
||||||
|
const ImVec2* pts = delegate.GetPoints(c);
|
||||||
|
uint32_t curveColor = delegate.GetCurveColor(c);
|
||||||
|
if ((c == highLightedCurveIndex && selection.empty() && !selectingQuad) || movingCurve == c)
|
||||||
|
curveColor = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
for (size_t p = 0; p < ptCount - 1; p++)
|
||||||
|
{
|
||||||
|
const ImVec2 p1 = pointToRange(pts[p]);
|
||||||
|
const ImVec2 p2 = pointToRange(pts[p + 1]);
|
||||||
|
|
||||||
|
if (curveType == CurveSmooth || curveType == CurveLinear)
|
||||||
|
{
|
||||||
|
size_t subStepCount = (curveType == CurveSmooth) ? 20 : 2;
|
||||||
|
float step = 1.f / float(subStepCount - 1);
|
||||||
|
for (size_t substep = 0; substep < subStepCount - 1; substep++)
|
||||||
|
{
|
||||||
|
float t = float(substep) * step;
|
||||||
|
|
||||||
|
const ImVec2 sp1 = ImLerp(p1, p2, t);
|
||||||
|
const ImVec2 sp2 = ImLerp(p1, p2, t + step);
|
||||||
|
|
||||||
|
const float rt1 = smoothstep(p1.x, p2.x, sp1.x);
|
||||||
|
const float rt2 = smoothstep(p1.x, p2.x, sp2.x);
|
||||||
|
|
||||||
|
const ImVec2 pos1 = ImVec2(sp1.x, ImLerp(p1.y, p2.y, rt1)) * viewSize + offset;
|
||||||
|
const ImVec2 pos2 = ImVec2(sp2.x, ImLerp(p1.y, p2.y, rt2)) * viewSize + offset;
|
||||||
|
|
||||||
|
if (distance(io.MousePos.x, io.MousePos.y, pos1.x, pos1.y, pos2.x, pos2.y) < 8.f && !scrollingV)
|
||||||
|
{
|
||||||
|
localOverCurve = int(c);
|
||||||
|
overCurve = int(c);
|
||||||
|
overCurveOrPoint = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_list->AddLine(pos1, pos2, curveColor, 1.3f);
|
||||||
|
} // substep
|
||||||
|
}
|
||||||
|
else if (curveType == CurveDiscrete)
|
||||||
|
{
|
||||||
|
ImVec2 dp1 = p1 * viewSize + offset;
|
||||||
|
ImVec2 dp2 = ImVec2(p2.x, p1.y) * viewSize + offset;
|
||||||
|
ImVec2 dp3 = p2 * viewSize + offset;
|
||||||
|
draw_list->AddLine(dp1, dp2, curveColor, 1.3f);
|
||||||
|
draw_list->AddLine(dp2, dp3, curveColor, 1.3f);
|
||||||
|
|
||||||
|
if ((distance(io.MousePos.x, io.MousePos.y, dp1.x, dp1.y, dp3.x, dp1.y) < 8.f ||
|
||||||
|
distance(io.MousePos.x, io.MousePos.y, dp3.x, dp1.y, dp3.x, dp3.y) < 8.f)
|
||||||
|
/*&& localOverCurve == -1*/)
|
||||||
|
{
|
||||||
|
localOverCurve = int(c);
|
||||||
|
overCurve = int(c);
|
||||||
|
overCurveOrPoint = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // point loop
|
||||||
|
|
||||||
|
for (size_t p = 0; p < ptCount; p++)
|
||||||
|
{
|
||||||
|
const int drawState = DrawPoint(draw_list, pointToRange(pts[p]), viewSize, offset, (selection.find({ int(c), int(p) }) != selection.end() && movingCurve == -1 && !scrollingV));
|
||||||
|
if (drawState && movingCurve == -1 && !selectingQuad)
|
||||||
|
{
|
||||||
|
overCurveOrPoint = true;
|
||||||
|
overSelectedPoint = true;
|
||||||
|
overCurve = -1;
|
||||||
|
if (drawState == 2)
|
||||||
|
{
|
||||||
|
if (!io.KeyShift && selection.find({ int(c), int(p) }) == selection.end())
|
||||||
|
selection.clear();
|
||||||
|
selection.insert({ int(c), int(p) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // curves loop
|
||||||
|
|
||||||
|
if (localOverCurve == -1)
|
||||||
|
overCurve = -1;
|
||||||
|
|
||||||
|
// move selection
|
||||||
|
static bool pointsMoved = false;
|
||||||
|
static ImVec2 mousePosOrigin;
|
||||||
|
static std::vector<ImVec2> originalPoints;
|
||||||
|
if (overSelectedPoint && io.MouseDown[0])
|
||||||
|
{
|
||||||
|
if ((fabsf(io.MouseDelta.x) > 0.f || fabsf(io.MouseDelta.y) > 0.f) && !selection.empty())
|
||||||
|
{
|
||||||
|
if (!pointsMoved)
|
||||||
|
{
|
||||||
|
delegate.BeginEdit(0);
|
||||||
|
mousePosOrigin = io.MousePos;
|
||||||
|
originalPoints.resize(selection.size());
|
||||||
|
int index = 0;
|
||||||
|
for (auto& sel : selection)
|
||||||
|
{
|
||||||
|
const ImVec2* pts = delegate.GetPoints(sel.curveIndex);
|
||||||
|
originalPoints[index++] = pts[sel.pointIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pointsMoved = true;
|
||||||
|
ret = 1;
|
||||||
|
auto prevSelection = selection;
|
||||||
|
int originalIndex = 0;
|
||||||
|
for (auto& sel : prevSelection)
|
||||||
|
{
|
||||||
|
const ImVec2 p = rangeToPoint(pointToRange(originalPoints[originalIndex]) + (io.MousePos - mousePosOrigin) * sizeOfPixel);
|
||||||
|
const int newIndex = delegate.EditPoint(sel.curveIndex, sel.pointIndex, p);
|
||||||
|
if (newIndex != sel.pointIndex)
|
||||||
|
{
|
||||||
|
selection.erase(sel);
|
||||||
|
selection.insert({ sel.curveIndex, newIndex });
|
||||||
|
}
|
||||||
|
originalIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overSelectedPoint && !io.MouseDown[0])
|
||||||
|
{
|
||||||
|
overSelectedPoint = false;
|
||||||
|
if (pointsMoved)
|
||||||
|
{
|
||||||
|
pointsMoved = false;
|
||||||
|
delegate.EndEdit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add point
|
||||||
|
if (overCurve != -1 && io.MouseDoubleClicked[0])
|
||||||
|
{
|
||||||
|
const ImVec2 np = rangeToPoint((io.MousePos - offset) / viewSize);
|
||||||
|
delegate.BeginEdit(overCurve);
|
||||||
|
delegate.AddPoint(overCurve, np);
|
||||||
|
delegate.EndEdit();
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// move curve
|
||||||
|
|
||||||
|
if (movingCurve != -1)
|
||||||
|
{
|
||||||
|
const size_t ptCount = delegate.GetPointCount(movingCurve);
|
||||||
|
const ImVec2* pts = delegate.GetPoints(movingCurve);
|
||||||
|
if (!pointsMoved)
|
||||||
|
{
|
||||||
|
mousePosOrigin = io.MousePos;
|
||||||
|
pointsMoved = true;
|
||||||
|
originalPoints.resize(ptCount);
|
||||||
|
for (size_t index = 0; index < ptCount; index++)
|
||||||
|
{
|
||||||
|
originalPoints[index] = pts[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ptCount >= 1)
|
||||||
|
{
|
||||||
|
for (size_t p = 0; p < ptCount; p++)
|
||||||
|
{
|
||||||
|
delegate.EditPoint(movingCurve, int(p), rangeToPoint(pointToRange(originalPoints[p]) + (io.MousePos - mousePosOrigin) * sizeOfPixel));
|
||||||
|
}
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
{
|
||||||
|
movingCurve = -1;
|
||||||
|
pointsMoved = false;
|
||||||
|
delegate.EndEdit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (movingCurve == -1 && overCurve != -1 && ImGui::IsMouseClicked(0) && selection.empty() && !selectingQuad)
|
||||||
|
{
|
||||||
|
movingCurve = overCurve;
|
||||||
|
delegate.BeginEdit(overCurve);
|
||||||
|
}
|
||||||
|
|
||||||
|
// quad selection
|
||||||
|
if (selectingQuad)
|
||||||
|
{
|
||||||
|
const ImVec2 bmin = ImMin(quadSelection, io.MousePos);
|
||||||
|
const ImVec2 bmax = ImMax(quadSelection, io.MousePos);
|
||||||
|
draw_list->AddRectFilled(bmin, bmax, 0x40FF0000, 1.f);
|
||||||
|
draw_list->AddRect(bmin, bmax, 0xFFFF0000, 1.f);
|
||||||
|
const ImRect selectionQuad(bmin, bmax);
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
{
|
||||||
|
if (!io.KeyShift)
|
||||||
|
selection.clear();
|
||||||
|
// select everythnig is quad
|
||||||
|
for (size_t c = 0; c < curveCount; c++)
|
||||||
|
{
|
||||||
|
if (!delegate.IsVisible(c))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const size_t ptCount = delegate.GetPointCount(c);
|
||||||
|
if (ptCount < 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const ImVec2* pts = delegate.GetPoints(c);
|
||||||
|
for (size_t p = 0; p < ptCount; p++)
|
||||||
|
{
|
||||||
|
const ImVec2 center = pointToRange(pts[p]) * viewSize + offset;
|
||||||
|
if (selectionQuad.Contains(center))
|
||||||
|
selection.insert({ int(c), int(p) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// done
|
||||||
|
selectingQuad = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!overCurveOrPoint && ImGui::IsMouseClicked(0) && !selectingQuad && movingCurve == -1 && !overSelectedPoint && container.Contains(io.MousePos))
|
||||||
|
{
|
||||||
|
selectingQuad = true;
|
||||||
|
quadSelection = io.MousePos;
|
||||||
|
}
|
||||||
|
if (clippingRect)
|
||||||
|
draw_list->PopClipRect();
|
||||||
|
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
ImGui::PopStyleColor(1);
|
||||||
|
|
||||||
|
if (selectedPoints)
|
||||||
|
{
|
||||||
|
selectedPoints->resize(int(selection.size()));
|
||||||
|
int index = 0;
|
||||||
|
for (auto& point : selection)
|
||||||
|
(*selectedPoints)[index++] = point;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
116
imgui/ImGradient.cpp
Normal file
116
imgui/ImGradient.cpp
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files(the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions :
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
#include "ImGradient.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
|
namespace ImGradient
|
||||||
|
{
|
||||||
|
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x * rhs, lhs.y * rhs); }
|
||||||
|
static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x / rhs, lhs.y / rhs); }
|
||||||
|
static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); }
|
||||||
|
static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); }
|
||||||
|
static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); }
|
||||||
|
static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x / rhs.x, lhs.y / rhs.y); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int DrawPoint(ImDrawList* draw_list, ImVec4 color, const ImVec2 size, bool editing, ImVec2 pos)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
ImVec2 p1 = ImLerp(pos, ImVec2(pos + ImVec2(size.x - size.y, 0.f)), color.w) + ImVec2(3, 3);
|
||||||
|
ImVec2 p2 = ImLerp(pos + ImVec2(size.y, size.y), ImVec2(pos + size), color.w) - ImVec2(3, 3);
|
||||||
|
ImRect rc(p1, p2);
|
||||||
|
|
||||||
|
color.w = 1.f;
|
||||||
|
draw_list->AddRectFilled(p1, p2, ImColor(color));
|
||||||
|
if (editing)
|
||||||
|
draw_list->AddRect(p1, p2, 0xFFFFFFFF, 2.f, 15, 2.5f);
|
||||||
|
else
|
||||||
|
draw_list->AddRect(p1, p2, 0x80FFFFFF, 2.f, 15, 1.25f);
|
||||||
|
|
||||||
|
if (rc.Contains(io.MousePos))
|
||||||
|
{
|
||||||
|
if (io.MouseClicked[0])
|
||||||
|
return 2;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Edit(Delegate& delegate, const ImVec2& size, int& selection)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
||||||
|
ImGui::BeginChild(137, size, ImGuiChildFlags_FrameStyle);
|
||||||
|
|
||||||
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
const ImVec2 offset = ImGui::GetCursorScreenPos();
|
||||||
|
|
||||||
|
const ImVec4* pts = delegate.GetPoints();
|
||||||
|
static int currentSelection = -1;
|
||||||
|
static int movingPt = -1;
|
||||||
|
if (currentSelection >= int(delegate.GetPointCount()))
|
||||||
|
currentSelection = -1;
|
||||||
|
if (movingPt != -1)
|
||||||
|
{
|
||||||
|
ImVec4 current = pts[movingPt];
|
||||||
|
current.w += io.MouseDelta.x / size.x;
|
||||||
|
current.w = ImClamp(current.w, 0.f, 1.f);
|
||||||
|
delegate.EditPoint(movingPt, current);
|
||||||
|
ret = true;
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
movingPt = -1;
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < delegate.GetPointCount(); i++)
|
||||||
|
{
|
||||||
|
int ptSel = DrawPoint(draw_list, pts[i], size, i == currentSelection, offset);
|
||||||
|
if (ptSel == 2)
|
||||||
|
{
|
||||||
|
currentSelection = int(i);
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
if (ptSel == 1 && io.MouseDown[0] && movingPt == -1)
|
||||||
|
{
|
||||||
|
movingPt = int(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImRect rc(offset, offset + size);
|
||||||
|
if (rc.Contains(io.MousePos) && io.MouseDoubleClicked[0])
|
||||||
|
{
|
||||||
|
float t = (io.MousePos.x - offset.x) / size.x;
|
||||||
|
delegate.AddPoint(delegate.GetPoint(t));
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
selection = currentSelection;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
3144
imgui/ImGuizmo.cpp
Normal file
3144
imgui/ImGuizmo.cpp
Normal file
File diff suppressed because it is too large
Load Diff
695
imgui/ImSequencer.cpp
Normal file
695
imgui/ImSequencer.cpp
Normal file
@ -0,0 +1,695 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files(the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions :
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
#include "ImSequencer.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace ImSequencer
|
||||||
|
{
|
||||||
|
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
static ImVec2 operator+(const ImVec2& a, const ImVec2& b) {
|
||||||
|
return ImVec2(a.x + b.x, a.y + b.y);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
static bool SequencerAddDelButton(ImDrawList* draw_list, ImVec2 pos, bool add = true)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImRect btnRect(pos, ImVec2(pos.x + 16, pos.y + 16));
|
||||||
|
bool overBtn = btnRect.Contains(io.MousePos);
|
||||||
|
bool containedClick = overBtn && btnRect.Contains(io.MouseClickedPos[0]);
|
||||||
|
bool clickedBtn = containedClick && io.MouseReleased[0];
|
||||||
|
int btnColor = overBtn ? 0xAAEAFFAA : 0x77A3B2AA;
|
||||||
|
if (containedClick && io.MouseDownDuration[0] > 0)
|
||||||
|
btnRect.Expand(2.0f);
|
||||||
|
|
||||||
|
float midy = pos.y + 16 / 2 - 0.5f;
|
||||||
|
float midx = pos.x + 16 / 2 - 0.5f;
|
||||||
|
draw_list->AddRect(btnRect.Min, btnRect.Max, btnColor, 4);
|
||||||
|
draw_list->AddLine(ImVec2(btnRect.Min.x + 3, midy), ImVec2(btnRect.Max.x - 3, midy), btnColor, 2);
|
||||||
|
if (add)
|
||||||
|
draw_list->AddLine(ImVec2(midx, btnRect.Min.y + 3), ImVec2(midx, btnRect.Max.y - 3), btnColor, 2);
|
||||||
|
return clickedBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Sequencer(SequenceInterface* sequence, int* currentFrame, bool* expanded, int* selectedEntry, int* firstFrame, int sequenceOptions)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
int cx = (int)(io.MousePos.x);
|
||||||
|
int cy = (int)(io.MousePos.y);
|
||||||
|
static float framePixelWidth = 10.f;
|
||||||
|
static float framePixelWidthTarget = 10.f;
|
||||||
|
int legendWidth = 200;
|
||||||
|
|
||||||
|
static int movingEntry = -1;
|
||||||
|
static int movingPos = -1;
|
||||||
|
static int movingPart = -1;
|
||||||
|
int delEntry = -1;
|
||||||
|
int dupEntry = -1;
|
||||||
|
int ItemHeight = 20;
|
||||||
|
|
||||||
|
bool popupOpened = false;
|
||||||
|
int sequenceCount = sequence->GetItemCount();
|
||||||
|
if (!sequenceCount)
|
||||||
|
return false;
|
||||||
|
ImGui::BeginGroup();
|
||||||
|
|
||||||
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
|
||||||
|
ImVec2 canvas_size = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
|
||||||
|
int firstFrameUsed = firstFrame ? *firstFrame : 0;
|
||||||
|
|
||||||
|
|
||||||
|
int controlHeight = sequenceCount * ItemHeight;
|
||||||
|
for (int i = 0; i < sequenceCount; i++)
|
||||||
|
controlHeight += int(sequence->GetCustomHeight(i));
|
||||||
|
int frameCount = ImMax(sequence->GetFrameMax() - sequence->GetFrameMin(), 1);
|
||||||
|
|
||||||
|
static bool MovingScrollBar = false;
|
||||||
|
static bool MovingCurrentFrame = false;
|
||||||
|
struct CustomDraw
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
ImRect customRect;
|
||||||
|
ImRect legendRect;
|
||||||
|
ImRect clippingRect;
|
||||||
|
ImRect legendClippingRect;
|
||||||
|
};
|
||||||
|
ImVector<CustomDraw> customDraws;
|
||||||
|
ImVector<CustomDraw> compactCustomDraws;
|
||||||
|
// zoom in/out
|
||||||
|
const int visibleFrameCount = (int)floorf((canvas_size.x - legendWidth) / framePixelWidth);
|
||||||
|
const float barWidthRatio = ImMin(visibleFrameCount / (float)frameCount, 1.f);
|
||||||
|
const float barWidthInPixels = barWidthRatio * (canvas_size.x - legendWidth);
|
||||||
|
|
||||||
|
ImRect regionRect(canvas_pos, canvas_pos + canvas_size);
|
||||||
|
|
||||||
|
static bool panningView = false;
|
||||||
|
static ImVec2 panningViewSource;
|
||||||
|
static int panningViewFrame;
|
||||||
|
if (ImGui::IsWindowFocused() && io.KeyAlt && io.MouseDown[2])
|
||||||
|
{
|
||||||
|
if (!panningView)
|
||||||
|
{
|
||||||
|
panningViewSource = io.MousePos;
|
||||||
|
panningView = true;
|
||||||
|
panningViewFrame = *firstFrame;
|
||||||
|
}
|
||||||
|
*firstFrame = panningViewFrame - int((io.MousePos.x - panningViewSource.x) / framePixelWidth);
|
||||||
|
*firstFrame = ImClamp(*firstFrame, sequence->GetFrameMin(), sequence->GetFrameMax() - visibleFrameCount);
|
||||||
|
}
|
||||||
|
if (panningView && !io.MouseDown[2])
|
||||||
|
{
|
||||||
|
panningView = false;
|
||||||
|
}
|
||||||
|
framePixelWidthTarget = ImClamp(framePixelWidthTarget, 0.1f, 50.f);
|
||||||
|
|
||||||
|
framePixelWidth = ImLerp(framePixelWidth, framePixelWidthTarget, 0.33f);
|
||||||
|
|
||||||
|
frameCount = sequence->GetFrameMax() - sequence->GetFrameMin();
|
||||||
|
if (visibleFrameCount >= frameCount && firstFrame)
|
||||||
|
*firstFrame = sequence->GetFrameMin();
|
||||||
|
|
||||||
|
|
||||||
|
// --
|
||||||
|
if (expanded && !*expanded)
|
||||||
|
{
|
||||||
|
ImGui::InvisibleButton("canvas", ImVec2(canvas_size.x - canvas_pos.x, (float)ItemHeight));
|
||||||
|
draw_list->AddRectFilled(canvas_pos, ImVec2(canvas_size.x + canvas_pos.x, canvas_pos.y + ItemHeight), 0xFF3D3837, 0);
|
||||||
|
char tmps[512];
|
||||||
|
ImFormatString(tmps, IM_ARRAYSIZE(tmps), sequence->GetCollapseFmt(), frameCount, sequenceCount);
|
||||||
|
draw_list->AddText(ImVec2(canvas_pos.x + 26, canvas_pos.y + 2), 0xFFFFFFFF, tmps);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool hasScrollBar(true);
|
||||||
|
/*
|
||||||
|
int framesPixelWidth = int(frameCount * framePixelWidth);
|
||||||
|
if ((framesPixelWidth + legendWidth) >= canvas_size.x)
|
||||||
|
{
|
||||||
|
hasScrollBar = true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// test scroll area
|
||||||
|
ImVec2 headerSize(canvas_size.x, (float)ItemHeight);
|
||||||
|
ImVec2 scrollBarSize(canvas_size.x, 14.f);
|
||||||
|
ImGui::InvisibleButton("topBar", headerSize);
|
||||||
|
draw_list->AddRectFilled(canvas_pos, canvas_pos + headerSize, 0xFFFF0000, 0);
|
||||||
|
ImVec2 childFramePos = ImGui::GetCursorScreenPos();
|
||||||
|
ImVec2 childFrameSize(canvas_size.x, canvas_size.y - 8.f - headerSize.y - (hasScrollBar ? scrollBarSize.y : 0));
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, 0);
|
||||||
|
ImGui::BeginChild(889, childFrameSize, ImGuiChildFlags_FrameStyle);
|
||||||
|
sequence->focused = ImGui::IsWindowFocused();
|
||||||
|
ImGui::InvisibleButton("contentBar", ImVec2(canvas_size.x, float(controlHeight)));
|
||||||
|
const ImVec2 contentMin = ImGui::GetItemRectMin();
|
||||||
|
const ImVec2 contentMax = ImGui::GetItemRectMax();
|
||||||
|
const ImRect contentRect(contentMin, contentMax);
|
||||||
|
const float contentHeight = contentMax.y - contentMin.y;
|
||||||
|
|
||||||
|
// full background
|
||||||
|
draw_list->AddRectFilled(canvas_pos, canvas_pos + canvas_size, 0xFF242424, 0);
|
||||||
|
|
||||||
|
// current frame top
|
||||||
|
ImRect topRect(ImVec2(canvas_pos.x + legendWidth, canvas_pos.y), ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + ItemHeight));
|
||||||
|
|
||||||
|
if (!MovingCurrentFrame && !MovingScrollBar && movingEntry == -1 && sequenceOptions & SEQUENCER_CHANGE_FRAME && currentFrame && *currentFrame >= 0 && topRect.Contains(io.MousePos) && io.MouseDown[0])
|
||||||
|
{
|
||||||
|
MovingCurrentFrame = true;
|
||||||
|
}
|
||||||
|
if (MovingCurrentFrame)
|
||||||
|
{
|
||||||
|
if (frameCount)
|
||||||
|
{
|
||||||
|
*currentFrame = (int)((io.MousePos.x - topRect.Min.x) / framePixelWidth) + firstFrameUsed;
|
||||||
|
if (*currentFrame < sequence->GetFrameMin())
|
||||||
|
*currentFrame = sequence->GetFrameMin();
|
||||||
|
if (*currentFrame >= sequence->GetFrameMax())
|
||||||
|
*currentFrame = sequence->GetFrameMax();
|
||||||
|
}
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
MovingCurrentFrame = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//header
|
||||||
|
draw_list->AddRectFilled(canvas_pos, ImVec2(canvas_size.x + canvas_pos.x, canvas_pos.y + ItemHeight), 0xFF3D3837, 0);
|
||||||
|
if (sequenceOptions & SEQUENCER_ADD)
|
||||||
|
{
|
||||||
|
if (SequencerAddDelButton(draw_list, ImVec2(canvas_pos.x + legendWidth - ItemHeight, canvas_pos.y + 2), true))
|
||||||
|
ImGui::OpenPopup("addEntry");
|
||||||
|
|
||||||
|
if (ImGui::BeginPopup("addEntry"))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < sequence->GetItemTypeCount(); i++)
|
||||||
|
if (ImGui::Selectable(sequence->GetItemTypeName(i)))
|
||||||
|
{
|
||||||
|
sequence->Add(i);
|
||||||
|
*selectedEntry = sequence->GetItemCount() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndPopup();
|
||||||
|
popupOpened = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//header frame number and lines
|
||||||
|
int modFrameCount = 10;
|
||||||
|
int frameStep = 1;
|
||||||
|
while ((modFrameCount * framePixelWidth) < 150)
|
||||||
|
{
|
||||||
|
modFrameCount *= 2;
|
||||||
|
frameStep *= 2;
|
||||||
|
};
|
||||||
|
int halfModFrameCount = modFrameCount / 2;
|
||||||
|
|
||||||
|
auto drawLine = [&](int i, int regionHeight) {
|
||||||
|
bool baseIndex = ((i % modFrameCount) == 0) || (i == sequence->GetFrameMax() || i == sequence->GetFrameMin());
|
||||||
|
bool halfIndex = (i % halfModFrameCount) == 0;
|
||||||
|
int px = (int)canvas_pos.x + int(i * framePixelWidth) + legendWidth - int(firstFrameUsed * framePixelWidth);
|
||||||
|
int tiretStart = baseIndex ? 4 : (halfIndex ? 10 : 14);
|
||||||
|
int tiretEnd = baseIndex ? regionHeight : ItemHeight;
|
||||||
|
|
||||||
|
if (px <= (canvas_size.x + canvas_pos.x) && px >= (canvas_pos.x + legendWidth))
|
||||||
|
{
|
||||||
|
draw_list->AddLine(ImVec2((float)px, canvas_pos.y + (float)tiretStart), ImVec2((float)px, canvas_pos.y + (float)tiretEnd - 1), 0xFF606060, 1);
|
||||||
|
|
||||||
|
draw_list->AddLine(ImVec2((float)px, canvas_pos.y + (float)ItemHeight), ImVec2((float)px, canvas_pos.y + (float)regionHeight - 1), 0x30606060, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseIndex && px > (canvas_pos.x + legendWidth))
|
||||||
|
{
|
||||||
|
char tmps[512];
|
||||||
|
ImFormatString(tmps, IM_ARRAYSIZE(tmps), "%d", i);
|
||||||
|
draw_list->AddText(ImVec2((float)px + 3.f, canvas_pos.y), 0xFFBBBBBB, tmps);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
auto drawLineContent = [&](int i, int /*regionHeight*/) {
|
||||||
|
int px = (int)canvas_pos.x + int(i * framePixelWidth) + legendWidth - int(firstFrameUsed * framePixelWidth);
|
||||||
|
int tiretStart = int(contentMin.y);
|
||||||
|
int tiretEnd = int(contentMax.y);
|
||||||
|
|
||||||
|
if (px <= (canvas_size.x + canvas_pos.x) && px >= (canvas_pos.x + legendWidth))
|
||||||
|
{
|
||||||
|
//draw_list->AddLine(ImVec2((float)px, canvas_pos.y + (float)tiretStart), ImVec2((float)px, canvas_pos.y + (float)tiretEnd - 1), 0xFF606060, 1);
|
||||||
|
|
||||||
|
draw_list->AddLine(ImVec2(float(px), float(tiretStart)), ImVec2(float(px), float(tiretEnd)), 0x30606060, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (int i = sequence->GetFrameMin(); i <= sequence->GetFrameMax(); i += frameStep)
|
||||||
|
{
|
||||||
|
drawLine(i, ItemHeight);
|
||||||
|
}
|
||||||
|
drawLine(sequence->GetFrameMin(), ItemHeight);
|
||||||
|
drawLine(sequence->GetFrameMax(), ItemHeight);
|
||||||
|
/*
|
||||||
|
draw_list->AddLine(canvas_pos, ImVec2(canvas_pos.x, canvas_pos.y + controlHeight), 0xFF000000, 1);
|
||||||
|
draw_list->AddLine(ImVec2(canvas_pos.x, canvas_pos.y + ItemHeight), ImVec2(canvas_size.x, canvas_pos.y + ItemHeight), 0xFF000000, 1);
|
||||||
|
*/
|
||||||
|
// clip content
|
||||||
|
|
||||||
|
draw_list->PushClipRect(childFramePos, childFramePos + childFrameSize, true);
|
||||||
|
|
||||||
|
// draw item names in the legend rect on the left
|
||||||
|
size_t customHeight = 0;
|
||||||
|
for (int i = 0; i < sequenceCount; i++)
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
sequence->Get(i, NULL, NULL, &type, NULL);
|
||||||
|
ImVec2 tpos(contentMin.x + 3, contentMin.y + i * ItemHeight + 2 + customHeight);
|
||||||
|
draw_list->AddText(tpos, 0xFFFFFFFF, sequence->GetItemLabel(i));
|
||||||
|
|
||||||
|
if (sequenceOptions & SEQUENCER_DEL)
|
||||||
|
{
|
||||||
|
if (SequencerAddDelButton(draw_list, ImVec2(contentMin.x + legendWidth - ItemHeight + 2 - 10, tpos.y + 2), false))
|
||||||
|
delEntry = i;
|
||||||
|
|
||||||
|
if (SequencerAddDelButton(draw_list, ImVec2(contentMin.x + legendWidth - ItemHeight - ItemHeight + 2 - 10, tpos.y + 2), true))
|
||||||
|
dupEntry = i;
|
||||||
|
}
|
||||||
|
customHeight += sequence->GetCustomHeight(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// slots background
|
||||||
|
customHeight = 0;
|
||||||
|
for (int i = 0; i < sequenceCount; i++)
|
||||||
|
{
|
||||||
|
unsigned int col = (i & 1) ? 0xFF3A3636 : 0xFF413D3D;
|
||||||
|
|
||||||
|
size_t localCustomHeight = sequence->GetCustomHeight(i);
|
||||||
|
ImVec2 pos = ImVec2(contentMin.x + legendWidth, contentMin.y + ItemHeight * i + 1 + customHeight);
|
||||||
|
ImVec2 sz = ImVec2(canvas_size.x + canvas_pos.x, pos.y + ItemHeight - 1 + localCustomHeight);
|
||||||
|
if (!popupOpened && cy >= pos.y && cy < pos.y + (ItemHeight + localCustomHeight) && movingEntry == -1 && cx>contentMin.x && cx < contentMin.x + canvas_size.x)
|
||||||
|
{
|
||||||
|
col += 0x80201008;
|
||||||
|
pos.x -= legendWidth;
|
||||||
|
}
|
||||||
|
draw_list->AddRectFilled(pos, sz, col, 0);
|
||||||
|
customHeight += localCustomHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_list->PushClipRect(childFramePos + ImVec2(float(legendWidth), 0.f), childFramePos + childFrameSize, true);
|
||||||
|
|
||||||
|
// vertical frame lines in content area
|
||||||
|
for (int i = sequence->GetFrameMin(); i <= sequence->GetFrameMax(); i += frameStep)
|
||||||
|
{
|
||||||
|
drawLineContent(i, int(contentHeight));
|
||||||
|
}
|
||||||
|
drawLineContent(sequence->GetFrameMin(), int(contentHeight));
|
||||||
|
drawLineContent(sequence->GetFrameMax(), int(contentHeight));
|
||||||
|
|
||||||
|
// selection
|
||||||
|
bool selected = selectedEntry && (*selectedEntry >= 0);
|
||||||
|
if (selected)
|
||||||
|
{
|
||||||
|
customHeight = 0;
|
||||||
|
for (int i = 0; i < *selectedEntry; i++)
|
||||||
|
customHeight += sequence->GetCustomHeight(i);
|
||||||
|
draw_list->AddRectFilled(ImVec2(contentMin.x, contentMin.y + ItemHeight * *selectedEntry + customHeight), ImVec2(contentMin.x + canvas_size.x, contentMin.y + ItemHeight * (*selectedEntry + 1) + customHeight), 0x801080FF, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// slots
|
||||||
|
customHeight = 0;
|
||||||
|
for (int i = 0; i < sequenceCount; i++)
|
||||||
|
{
|
||||||
|
int* start, * end;
|
||||||
|
unsigned int color;
|
||||||
|
sequence->Get(i, &start, &end, NULL, &color);
|
||||||
|
size_t localCustomHeight = sequence->GetCustomHeight(i);
|
||||||
|
|
||||||
|
ImVec2 pos = ImVec2(contentMin.x + legendWidth - firstFrameUsed * framePixelWidth, contentMin.y + ItemHeight * i + 1 + customHeight);
|
||||||
|
ImVec2 slotP1(pos.x + *start * framePixelWidth, pos.y + 2);
|
||||||
|
ImVec2 slotP2(pos.x + *end * framePixelWidth + framePixelWidth, pos.y + ItemHeight - 2);
|
||||||
|
ImVec2 slotP3(pos.x + *end * framePixelWidth + framePixelWidth, pos.y + ItemHeight - 2 + localCustomHeight);
|
||||||
|
unsigned int slotColor = color | 0xFF000000;
|
||||||
|
unsigned int slotColorHalf = (color & 0xFFFFFF) | 0x40000000;
|
||||||
|
|
||||||
|
if (slotP1.x <= (canvas_size.x + contentMin.x) && slotP2.x >= (contentMin.x + legendWidth))
|
||||||
|
{
|
||||||
|
draw_list->AddRectFilled(slotP1, slotP3, slotColorHalf, 2);
|
||||||
|
draw_list->AddRectFilled(slotP1, slotP2, slotColor, 2);
|
||||||
|
}
|
||||||
|
if (ImRect(slotP1, slotP2).Contains(io.MousePos) && io.MouseDoubleClicked[0])
|
||||||
|
{
|
||||||
|
sequence->DoubleClick(i);
|
||||||
|
}
|
||||||
|
// Ensure grabbable handles
|
||||||
|
const float max_handle_width = slotP2.x - slotP1.x / 3.0f;
|
||||||
|
const float min_handle_width = ImMin(10.0f, max_handle_width);
|
||||||
|
const float handle_width = ImClamp(framePixelWidth / 2.0f, min_handle_width, max_handle_width);
|
||||||
|
ImRect rects[3] = { ImRect(slotP1, ImVec2(slotP1.x + handle_width, slotP2.y))
|
||||||
|
, ImRect(ImVec2(slotP2.x - handle_width, slotP1.y), slotP2)
|
||||||
|
, ImRect(slotP1, slotP2) };
|
||||||
|
|
||||||
|
const unsigned int quadColor[] = { 0xFFFFFFFF, 0xFFFFFFFF, slotColor + (selected ? 0 : 0x202020) };
|
||||||
|
if (movingEntry == -1 && (sequenceOptions & SEQUENCER_EDIT_STARTEND))// TODOFOCUS && backgroundRect.Contains(io.MousePos))
|
||||||
|
{
|
||||||
|
for (int j = 2; j >= 0; j--)
|
||||||
|
{
|
||||||
|
ImRect& rc = rects[j];
|
||||||
|
if (!rc.Contains(io.MousePos))
|
||||||
|
continue;
|
||||||
|
draw_list->AddRectFilled(rc.Min, rc.Max, quadColor[j], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
ImRect& rc = rects[j];
|
||||||
|
if (!rc.Contains(io.MousePos))
|
||||||
|
continue;
|
||||||
|
if (!ImRect(childFramePos, childFramePos + childFrameSize).Contains(io.MousePos))
|
||||||
|
continue;
|
||||||
|
if (ImGui::IsMouseClicked(0) && !MovingScrollBar && !MovingCurrentFrame)
|
||||||
|
{
|
||||||
|
movingEntry = i;
|
||||||
|
movingPos = cx;
|
||||||
|
movingPart = j + 1;
|
||||||
|
sequence->BeginEdit(movingEntry);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// custom draw
|
||||||
|
if (localCustomHeight > 0)
|
||||||
|
{
|
||||||
|
ImVec2 rp(canvas_pos.x, contentMin.y + ItemHeight * i + 1 + customHeight);
|
||||||
|
ImRect customRect(rp + ImVec2(legendWidth - (firstFrameUsed - sequence->GetFrameMin() - 0.5f) * framePixelWidth, float(ItemHeight)),
|
||||||
|
rp + ImVec2(legendWidth + (sequence->GetFrameMax() - firstFrameUsed - 0.5f + 2.f) * framePixelWidth, float(localCustomHeight + ItemHeight)));
|
||||||
|
ImRect clippingRect(rp + ImVec2(float(legendWidth), float(ItemHeight)), rp + ImVec2(canvas_size.x, float(localCustomHeight + ItemHeight)));
|
||||||
|
|
||||||
|
ImRect legendRect(rp + ImVec2(0.f, float(ItemHeight)), rp + ImVec2(float(legendWidth), float(localCustomHeight)));
|
||||||
|
ImRect legendClippingRect(canvas_pos + ImVec2(0.f, float(ItemHeight)), canvas_pos + ImVec2(float(legendWidth), float(localCustomHeight + ItemHeight)));
|
||||||
|
customDraws.push_back({ i, customRect, legendRect, clippingRect, legendClippingRect });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImVec2 rp(canvas_pos.x, contentMin.y + ItemHeight * i + customHeight);
|
||||||
|
ImRect customRect(rp + ImVec2(legendWidth - (firstFrameUsed - sequence->GetFrameMin() - 0.5f) * framePixelWidth, float(0.f)),
|
||||||
|
rp + ImVec2(legendWidth + (sequence->GetFrameMax() - firstFrameUsed - 0.5f + 2.f) * framePixelWidth, float(ItemHeight)));
|
||||||
|
ImRect clippingRect(rp + ImVec2(float(legendWidth), float(0.f)), rp + ImVec2(canvas_size.x, float(ItemHeight)));
|
||||||
|
|
||||||
|
compactCustomDraws.push_back({ i, customRect, ImRect(), clippingRect, ImRect() });
|
||||||
|
}
|
||||||
|
customHeight += localCustomHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// moving
|
||||||
|
if (/*backgroundRect.Contains(io.MousePos) && */movingEntry >= 0)
|
||||||
|
{
|
||||||
|
#if IMGUI_VERSION_NUM >= 18723
|
||||||
|
ImGui::SetNextFrameWantCaptureMouse(true);
|
||||||
|
#else
|
||||||
|
ImGui::CaptureMouseFromApp();
|
||||||
|
#endif
|
||||||
|
int diffFrame = int((cx - movingPos) / framePixelWidth);
|
||||||
|
if (std::abs(diffFrame) > 0)
|
||||||
|
{
|
||||||
|
int* start, * end;
|
||||||
|
sequence->Get(movingEntry, &start, &end, NULL, NULL);
|
||||||
|
if (selectedEntry)
|
||||||
|
*selectedEntry = movingEntry;
|
||||||
|
int& l = *start;
|
||||||
|
int& r = *end;
|
||||||
|
if (movingPart & 1)
|
||||||
|
l += diffFrame;
|
||||||
|
if (movingPart & 2)
|
||||||
|
r += diffFrame;
|
||||||
|
if (l < 0)
|
||||||
|
{
|
||||||
|
if (movingPart & 2)
|
||||||
|
r -= l;
|
||||||
|
l = 0;
|
||||||
|
}
|
||||||
|
if (movingPart & 1 && l > r)
|
||||||
|
l = r;
|
||||||
|
if (movingPart & 2 && r < l)
|
||||||
|
r = l;
|
||||||
|
movingPos += int(diffFrame * framePixelWidth);
|
||||||
|
}
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
{
|
||||||
|
// single select
|
||||||
|
if (!diffFrame && movingPart && selectedEntry)
|
||||||
|
{
|
||||||
|
*selectedEntry = movingEntry;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
movingEntry = -1;
|
||||||
|
sequence->EndEdit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cursor
|
||||||
|
if (currentFrame && firstFrame && *currentFrame >= *firstFrame && *currentFrame <= sequence->GetFrameMax())
|
||||||
|
{
|
||||||
|
static const float cursorWidth = 8.f;
|
||||||
|
float cursorOffset = contentMin.x + legendWidth + (*currentFrame - firstFrameUsed) * framePixelWidth + framePixelWidth / 2 - cursorWidth * 0.5f;
|
||||||
|
draw_list->AddLine(ImVec2(cursorOffset, canvas_pos.y), ImVec2(cursorOffset, contentMax.y), 0xA02A2AFF, cursorWidth);
|
||||||
|
char tmps[512];
|
||||||
|
ImFormatString(tmps, IM_ARRAYSIZE(tmps), "%d", *currentFrame);
|
||||||
|
draw_list->AddText(ImVec2(cursorOffset + 10, canvas_pos.y + 2), 0xFF2A2AFF, tmps);
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_list->PopClipRect();
|
||||||
|
draw_list->PopClipRect();
|
||||||
|
|
||||||
|
for (auto& customDraw : customDraws)
|
||||||
|
sequence->CustomDraw(customDraw.index, draw_list, customDraw.customRect, customDraw.legendRect, customDraw.clippingRect, customDraw.legendClippingRect);
|
||||||
|
for (auto& customDraw : compactCustomDraws)
|
||||||
|
sequence->CustomDrawCompact(customDraw.index, draw_list, customDraw.customRect, customDraw.clippingRect);
|
||||||
|
|
||||||
|
// copy paste
|
||||||
|
if (sequenceOptions & SEQUENCER_COPYPASTE)
|
||||||
|
{
|
||||||
|
ImRect rectCopy(ImVec2(contentMin.x + 100, canvas_pos.y + 2)
|
||||||
|
, ImVec2(contentMin.x + 100 + 30, canvas_pos.y + ItemHeight - 2));
|
||||||
|
bool inRectCopy = rectCopy.Contains(io.MousePos);
|
||||||
|
unsigned int copyColor = inRectCopy ? 0xFF1080FF : 0xFF000000;
|
||||||
|
draw_list->AddText(rectCopy.Min, copyColor, "Copy");
|
||||||
|
|
||||||
|
ImRect rectPaste(ImVec2(contentMin.x + 140, canvas_pos.y + 2)
|
||||||
|
, ImVec2(contentMin.x + 140 + 30, canvas_pos.y + ItemHeight - 2));
|
||||||
|
bool inRectPaste = rectPaste.Contains(io.MousePos);
|
||||||
|
unsigned int pasteColor = inRectPaste ? 0xFF1080FF : 0xFF000000;
|
||||||
|
draw_list->AddText(rectPaste.Min, pasteColor, "Paste");
|
||||||
|
|
||||||
|
if (inRectCopy && io.MouseReleased[0])
|
||||||
|
{
|
||||||
|
sequence->Copy();
|
||||||
|
}
|
||||||
|
if (inRectPaste && io.MouseReleased[0])
|
||||||
|
{
|
||||||
|
sequence->Paste();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
if (hasScrollBar)
|
||||||
|
{
|
||||||
|
ImGui::InvisibleButton("scrollBar", scrollBarSize);
|
||||||
|
ImVec2 scrollBarMin = ImGui::GetItemRectMin();
|
||||||
|
ImVec2 scrollBarMax = ImGui::GetItemRectMax();
|
||||||
|
|
||||||
|
// ratio = number of frames visible in control / number to total frames
|
||||||
|
|
||||||
|
float startFrameOffset = ((float)(firstFrameUsed - sequence->GetFrameMin()) / (float)frameCount) * (canvas_size.x - legendWidth);
|
||||||
|
ImVec2 scrollBarA(scrollBarMin.x + legendWidth, scrollBarMin.y - 2);
|
||||||
|
ImVec2 scrollBarB(scrollBarMin.x + canvas_size.x, scrollBarMax.y - 1);
|
||||||
|
draw_list->AddRectFilled(scrollBarA, scrollBarB, 0xFF222222, 0);
|
||||||
|
|
||||||
|
ImRect scrollBarRect(scrollBarA, scrollBarB);
|
||||||
|
bool inScrollBar = scrollBarRect.Contains(io.MousePos);
|
||||||
|
|
||||||
|
draw_list->AddRectFilled(scrollBarA, scrollBarB, 0xFF101010, 8);
|
||||||
|
|
||||||
|
|
||||||
|
ImVec2 scrollBarC(scrollBarMin.x + legendWidth + startFrameOffset, scrollBarMin.y);
|
||||||
|
ImVec2 scrollBarD(scrollBarMin.x + legendWidth + barWidthInPixels + startFrameOffset, scrollBarMax.y - 2);
|
||||||
|
draw_list->AddRectFilled(scrollBarC, scrollBarD, (inScrollBar || MovingScrollBar) ? 0xFF606060 : 0xFF505050, 6);
|
||||||
|
|
||||||
|
ImRect barHandleLeft(scrollBarC, ImVec2(scrollBarC.x + 14, scrollBarD.y));
|
||||||
|
ImRect barHandleRight(ImVec2(scrollBarD.x - 14, scrollBarC.y), scrollBarD);
|
||||||
|
|
||||||
|
bool onLeft = barHandleLeft.Contains(io.MousePos);
|
||||||
|
bool onRight = barHandleRight.Contains(io.MousePos);
|
||||||
|
|
||||||
|
static bool sizingRBar = false;
|
||||||
|
static bool sizingLBar = false;
|
||||||
|
|
||||||
|
draw_list->AddRectFilled(barHandleLeft.Min, barHandleLeft.Max, (onLeft || sizingLBar) ? 0xFFAAAAAA : 0xFF666666, 6);
|
||||||
|
draw_list->AddRectFilled(barHandleRight.Min, barHandleRight.Max, (onRight || sizingRBar) ? 0xFFAAAAAA : 0xFF666666, 6);
|
||||||
|
|
||||||
|
ImRect scrollBarThumb(scrollBarC, scrollBarD);
|
||||||
|
static const float MinBarWidth = 44.f;
|
||||||
|
if (sizingRBar)
|
||||||
|
{
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
{
|
||||||
|
sizingRBar = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float barNewWidth = ImMax(barWidthInPixels + io.MouseDelta.x, MinBarWidth);
|
||||||
|
float barRatio = barNewWidth / barWidthInPixels;
|
||||||
|
framePixelWidthTarget = framePixelWidth = framePixelWidth / barRatio;
|
||||||
|
int newVisibleFrameCount = int((canvas_size.x - legendWidth) / framePixelWidthTarget);
|
||||||
|
int lastFrame = *firstFrame + newVisibleFrameCount;
|
||||||
|
if (lastFrame > sequence->GetFrameMax())
|
||||||
|
{
|
||||||
|
framePixelWidthTarget = framePixelWidth = (canvas_size.x - legendWidth) / float(sequence->GetFrameMax() - *firstFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sizingLBar)
|
||||||
|
{
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
{
|
||||||
|
sizingLBar = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (fabsf(io.MouseDelta.x) > FLT_EPSILON)
|
||||||
|
{
|
||||||
|
float barNewWidth = ImMax(barWidthInPixels - io.MouseDelta.x, MinBarWidth);
|
||||||
|
float barRatio = barNewWidth / barWidthInPixels;
|
||||||
|
float previousFramePixelWidthTarget = framePixelWidthTarget;
|
||||||
|
framePixelWidthTarget = framePixelWidth = framePixelWidth / barRatio;
|
||||||
|
int newVisibleFrameCount = int(visibleFrameCount / barRatio);
|
||||||
|
int newFirstFrame = *firstFrame + newVisibleFrameCount - visibleFrameCount;
|
||||||
|
newFirstFrame = ImClamp(newFirstFrame, sequence->GetFrameMin(), ImMax(sequence->GetFrameMax() - visibleFrameCount, sequence->GetFrameMin()));
|
||||||
|
if (newFirstFrame == *firstFrame)
|
||||||
|
{
|
||||||
|
framePixelWidth = framePixelWidthTarget = previousFramePixelWidthTarget;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*firstFrame = newFirstFrame;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (MovingScrollBar)
|
||||||
|
{
|
||||||
|
if (!io.MouseDown[0])
|
||||||
|
{
|
||||||
|
MovingScrollBar = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float framesPerPixelInBar = barWidthInPixels / (float)visibleFrameCount;
|
||||||
|
*firstFrame = int((io.MousePos.x - panningViewSource.x) / framesPerPixelInBar) - panningViewFrame;
|
||||||
|
*firstFrame = ImClamp(*firstFrame, sequence->GetFrameMin(), ImMax(sequence->GetFrameMax() - visibleFrameCount, sequence->GetFrameMin()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (scrollBarThumb.Contains(io.MousePos) && ImGui::IsMouseClicked(0) && firstFrame && !MovingCurrentFrame && movingEntry == -1)
|
||||||
|
{
|
||||||
|
MovingScrollBar = true;
|
||||||
|
panningViewSource = io.MousePos;
|
||||||
|
panningViewFrame = -*firstFrame;
|
||||||
|
}
|
||||||
|
if (!sizingRBar && onRight && ImGui::IsMouseClicked(0))
|
||||||
|
sizingRBar = true;
|
||||||
|
if (!sizingLBar && onLeft && ImGui::IsMouseClicked(0))
|
||||||
|
sizingLBar = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
|
if (regionRect.Contains(io.MousePos))
|
||||||
|
{
|
||||||
|
bool overCustomDraw = false;
|
||||||
|
for (auto& custom : customDraws)
|
||||||
|
{
|
||||||
|
if (custom.customRect.Contains(io.MousePos))
|
||||||
|
{
|
||||||
|
overCustomDraw = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (overCustomDraw)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
frameOverCursor = *firstFrame + (int)(visibleFrameCount * ((io.MousePos.x - (float)legendWidth - canvas_pos.x) / (canvas_size.x - legendWidth)));
|
||||||
|
//frameOverCursor = max(min(*firstFrame - visibleFrameCount / 2, frameCount - visibleFrameCount), 0);
|
||||||
|
|
||||||
|
/**firstFrame -= frameOverCursor;
|
||||||
|
*firstFrame *= framePixelWidthTarget / framePixelWidth;
|
||||||
|
*firstFrame += frameOverCursor;*/
|
||||||
|
if (io.MouseWheel < -FLT_EPSILON)
|
||||||
|
{
|
||||||
|
*firstFrame -= frameOverCursor;
|
||||||
|
*firstFrame = int(*firstFrame * 1.1f);
|
||||||
|
framePixelWidthTarget *= 0.9f;
|
||||||
|
*firstFrame += frameOverCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (io.MouseWheel > FLT_EPSILON)
|
||||||
|
{
|
||||||
|
*firstFrame -= frameOverCursor;
|
||||||
|
*firstFrame = int(*firstFrame * 0.9f);
|
||||||
|
framePixelWidthTarget *= 1.1f;
|
||||||
|
*firstFrame += frameOverCursor;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expanded)
|
||||||
|
{
|
||||||
|
if (SequencerAddDelButton(draw_list, ImVec2(canvas_pos.x + 2, canvas_pos.y + 2), !*expanded))
|
||||||
|
*expanded = !*expanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delEntry != -1)
|
||||||
|
{
|
||||||
|
sequence->Del(delEntry);
|
||||||
|
if (selectedEntry && (*selectedEntry == delEntry || *selectedEntry >= sequence->GetItemCount()))
|
||||||
|
*selectedEntry = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dupEntry != -1)
|
||||||
|
{
|
||||||
|
sequence->Duplicate(dupEntry);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
3169
imgui/glad.c
Normal file
3169
imgui/glad.c
Normal file
File diff suppressed because it is too large
Load Diff
22679
imgui/imgui.cpp
Normal file
22679
imgui/imgui.cpp
Normal file
File diff suppressed because it is too large
Load Diff
10691
imgui/imgui_demo.cpp
Normal file
10691
imgui/imgui_demo.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4809
imgui/imgui_draw.cpp
Normal file
4809
imgui/imgui_draw.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1453
imgui/imgui_impl_glfw.cpp
Normal file
1453
imgui/imgui_impl_glfw.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1005
imgui/imgui_impl_opengl3.cpp
Normal file
1005
imgui/imgui_impl_opengl3.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4467
imgui/imgui_tables.cpp
Normal file
4467
imgui/imgui_tables.cpp
Normal file
File diff suppressed because it is too large
Load Diff
10434
imgui/imgui_widgets.cpp
Normal file
10434
imgui/imgui_widgets.cpp
Normal file
File diff suppressed because it is too large
Load Diff
151
include/GraphEditor.h
Normal file
151
include/GraphEditor.h
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
|
namespace GraphEditor {
|
||||||
|
|
||||||
|
typedef size_t NodeIndex;
|
||||||
|
typedef size_t SlotIndex;
|
||||||
|
typedef size_t LinkIndex;
|
||||||
|
typedef size_t TemplateIndex;
|
||||||
|
|
||||||
|
// Force the view to be respositionned and zoom to fit nodes with Show function.
|
||||||
|
// Parameter value will be changed to Fit_None by the function.
|
||||||
|
enum FitOnScreen
|
||||||
|
{
|
||||||
|
Fit_None,
|
||||||
|
Fit_AllNodes,
|
||||||
|
Fit_SelectedNodes
|
||||||
|
};
|
||||||
|
|
||||||
|
// Display options and colors
|
||||||
|
struct Options
|
||||||
|
{
|
||||||
|
ImRect mMinimap{{0.75f, 0.8f, 0.99f, 0.99f}}; // rectangle coordinates of minimap
|
||||||
|
ImU32 mBackgroundColor{ IM_COL32(40, 40, 40, 255) }; // full background color
|
||||||
|
ImU32 mGridColor{ IM_COL32(0, 0, 0, 60) }; // grid lines color
|
||||||
|
ImU32 mGridColor2{ IM_COL32(0, 0, 0, 160) }; // grid lines color every 10th
|
||||||
|
ImU32 mSelectedNodeBorderColor{ IM_COL32(255, 130, 30, 255) }; // node border color when it's selected
|
||||||
|
ImU32 mNodeBorderColor{ IM_COL32(100, 100, 100, 0) }; // node border color when it's not selected
|
||||||
|
ImU32 mQuadSelection{ IM_COL32(255, 32, 32, 64) }; // quad selection inside color
|
||||||
|
ImU32 mQuadSelectionBorder{ IM_COL32(255, 32, 32, 255) }; // quad selection border color
|
||||||
|
ImU32 mDefaultSlotColor{ IM_COL32(128, 128, 128, 255) }; // when no color is provided in node template, use this value
|
||||||
|
ImU32 mFrameFocus{ IM_COL32(64, 128, 255, 255) }; // rectangle border when graph editor has focus
|
||||||
|
float mLineThickness{ 5 }; // links width in pixels when zoom value is 1
|
||||||
|
float mGridSize{ 64.f }; // background grid size in pixels when zoom value is 1
|
||||||
|
float mRounding{ 3.f }; // rounding at node corners
|
||||||
|
float mZoomRatio{ 0.1f }; // factor per mouse wheel delta
|
||||||
|
float mZoomLerpFactor{ 0.25f }; // the smaller, the smoother
|
||||||
|
float mBorderSelectionThickness{ 6.f }; // thickness of selection border around nodes
|
||||||
|
float mBorderThickness{ 6.f }; // thickness of selection border around nodes
|
||||||
|
float mNodeSlotRadius{ 8.f }; // circle radius for inputs and outputs
|
||||||
|
float mNodeSlotHoverFactor{ 1.2f }; // increase size when hovering
|
||||||
|
float mMinZoom{ 0.2f }, mMaxZoom { 1.1f };
|
||||||
|
float mSnap{ 5.f };
|
||||||
|
bool mDisplayLinksAsCurves{ true }; // false is straight and 45deg lines
|
||||||
|
bool mAllowQuadSelection{ true }; // multiple selection using drag and drop
|
||||||
|
bool mRenderGrid{ true }; // grid or nothing
|
||||||
|
bool mDrawIONameOnHover{ true }; // only draw node input/output when hovering
|
||||||
|
};
|
||||||
|
|
||||||
|
// View state: scroll position and zoom factor
|
||||||
|
struct ViewState
|
||||||
|
{
|
||||||
|
ImVec2 mPosition{0.0f, 0.0f}; // scroll position
|
||||||
|
float mFactor{ 1.0f }; // current zoom factor
|
||||||
|
float mFactorTarget{ 1.0f }; // targeted zoom factor interpolated using Options.mZoomLerpFactor
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Template
|
||||||
|
{
|
||||||
|
ImU32 mHeaderColor;
|
||||||
|
ImU32 mBackgroundColor;
|
||||||
|
ImU32 mBackgroundColorOver;
|
||||||
|
ImU8 mInputCount;
|
||||||
|
const char** mInputNames; // can be nullptr. No text displayed.
|
||||||
|
ImU32* mInputColors; // can be nullptr, default slot color will be used.
|
||||||
|
ImU8 mOutputCount;
|
||||||
|
const char** mOutputNames; // can be nullptr. No text displayed.
|
||||||
|
ImU32* mOutputColors; // can be nullptr, default slot color will be used.
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Node
|
||||||
|
{
|
||||||
|
const char* mName;
|
||||||
|
TemplateIndex mTemplateIndex;
|
||||||
|
ImRect mRect;
|
||||||
|
bool mSelected{ false };
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Link
|
||||||
|
{
|
||||||
|
NodeIndex mInputNodeIndex;
|
||||||
|
SlotIndex mInputSlotIndex;
|
||||||
|
NodeIndex mOutputNodeIndex;
|
||||||
|
SlotIndex mOutputSlotIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Delegate
|
||||||
|
{
|
||||||
|
virtual bool AllowedLink(NodeIndex from, NodeIndex to) = 0;
|
||||||
|
|
||||||
|
virtual void SelectNode(NodeIndex nodeIndex, bool selected) = 0;
|
||||||
|
virtual void MoveSelectedNodes(const ImVec2 delta) = 0;
|
||||||
|
|
||||||
|
virtual void AddLink(NodeIndex inputNodeIndex, SlotIndex inputSlotIndex, NodeIndex outputNodeIndex, SlotIndex outputSlotIndex) = 0;
|
||||||
|
virtual void DelLink(LinkIndex linkIndex) = 0;
|
||||||
|
|
||||||
|
// user is responsible for clipping
|
||||||
|
virtual void CustomDraw(ImDrawList* drawList, ImRect rectangle, NodeIndex nodeIndex) = 0;
|
||||||
|
|
||||||
|
// use mouse position to open context menu
|
||||||
|
// if nodeIndex != -1, right click happens on the specified node
|
||||||
|
virtual void RightClick(NodeIndex nodeIndex, SlotIndex slotIndexInput, SlotIndex slotIndexOutput) = 0;
|
||||||
|
|
||||||
|
virtual const size_t GetTemplateCount() = 0;
|
||||||
|
virtual const Template GetTemplate(TemplateIndex index) = 0;
|
||||||
|
|
||||||
|
virtual const size_t GetNodeCount() = 0;
|
||||||
|
virtual const Node GetNode(NodeIndex index) = 0;
|
||||||
|
|
||||||
|
virtual const size_t GetLinkCount() = 0;
|
||||||
|
virtual const Link GetLink(LinkIndex index) = 0;
|
||||||
|
|
||||||
|
virtual ~Delegate() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
void Show(Delegate& delegate, const Options& options, ViewState& viewState, bool enabled, FitOnScreen* fit = nullptr);
|
||||||
|
void GraphEditorClear();
|
||||||
|
|
||||||
|
bool EditOptions(Options& options);
|
||||||
|
|
||||||
|
} // namespace
|
82
include/ImCurveEdit.h
Normal file
82
include/ImCurveEdit.h
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
struct ImRect;
|
||||||
|
|
||||||
|
namespace ImCurveEdit
|
||||||
|
{
|
||||||
|
enum CurveType
|
||||||
|
{
|
||||||
|
CurveNone,
|
||||||
|
CurveDiscrete,
|
||||||
|
CurveLinear,
|
||||||
|
CurveSmooth,
|
||||||
|
CurveBezier,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EditPoint
|
||||||
|
{
|
||||||
|
int curveIndex;
|
||||||
|
int pointIndex;
|
||||||
|
bool operator <(const EditPoint& other) const
|
||||||
|
{
|
||||||
|
if (curveIndex < other.curveIndex)
|
||||||
|
return true;
|
||||||
|
if (curveIndex > other.curveIndex)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (pointIndex < other.pointIndex)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Delegate
|
||||||
|
{
|
||||||
|
bool focused = false;
|
||||||
|
virtual size_t GetCurveCount() = 0;
|
||||||
|
virtual bool IsVisible(size_t /*curveIndex*/) { return true; }
|
||||||
|
virtual CurveType GetCurveType(size_t /*curveIndex*/) const { return CurveLinear; }
|
||||||
|
virtual ImVec2& GetMin() = 0;
|
||||||
|
virtual ImVec2& GetMax() = 0;
|
||||||
|
virtual size_t GetPointCount(size_t curveIndex) = 0;
|
||||||
|
virtual uint32_t GetCurveColor(size_t curveIndex) = 0;
|
||||||
|
virtual ImVec2* GetPoints(size_t curveIndex) = 0;
|
||||||
|
virtual int EditPoint(size_t curveIndex, int pointIndex, ImVec2 value) = 0;
|
||||||
|
virtual void AddPoint(size_t curveIndex, ImVec2 value) = 0;
|
||||||
|
virtual unsigned int GetBackgroundColor() { return 0xFF202020; }
|
||||||
|
// handle undo/redo thru this functions
|
||||||
|
virtual void BeginEdit(int /*index*/) {}
|
||||||
|
virtual void EndEdit() {}
|
||||||
|
|
||||||
|
virtual ~Delegate() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Edit(Delegate& delegate, const ImVec2& size, unsigned int id, const ImRect* clippingRect = NULL, ImVector<EditPoint>* selectedPoints = NULL);
|
||||||
|
}
|
45
include/ImGradient.h
Normal file
45
include/ImGradient.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
struct ImVec4;
|
||||||
|
struct ImVec2;
|
||||||
|
|
||||||
|
namespace ImGradient
|
||||||
|
{
|
||||||
|
struct Delegate
|
||||||
|
{
|
||||||
|
virtual size_t GetPointCount() = 0;
|
||||||
|
virtual ImVec4* GetPoints() = 0;
|
||||||
|
virtual int EditPoint(int pointIndex, ImVec4 value) = 0;
|
||||||
|
virtual ImVec4 GetPoint(float t) = 0;
|
||||||
|
virtual void AddPoint(ImVec4 value) = 0;
|
||||||
|
virtual ~Delegate() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool Edit(Delegate& delegate, const ImVec2& size, int& selection);
|
||||||
|
}
|
306
include/ImGuizmo.h
Normal file
306
include/ImGuizmo.h
Normal file
@ -0,0 +1,306 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// History :
|
||||||
|
// 2019/11/03 View gizmo
|
||||||
|
// 2016/09/11 Behind camera culling. Scaling Delta matrix not multiplied by source matrix scales. local/world rotation and translation fixed. Display message is incorrect (X: ... Y:...) in local mode.
|
||||||
|
// 2016/09/09 Hatched negative axis. Snapping. Documentation update.
|
||||||
|
// 2016/09/04 Axis switch and translation plan autohiding. Scale transform stability improved
|
||||||
|
// 2016/09/01 Mogwai changed to Manipulate. Draw debug cube. Fixed inverted scale. Mixing scale and translation/rotation gives bad results.
|
||||||
|
// 2016/08/31 First version
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// Future (no order):
|
||||||
|
//
|
||||||
|
// - Multi view
|
||||||
|
// - display rotation/translation/scale infos in local/world space and not only local
|
||||||
|
// - finish local/world matrix application
|
||||||
|
// - OPERATION as bitmask
|
||||||
|
//
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// Example
|
||||||
|
#if 0
|
||||||
|
void EditTransform(const Camera& camera, matrix_t& matrix)
|
||||||
|
{
|
||||||
|
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
||||||
|
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
||||||
|
if (ImGui::IsKeyPressed(90))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
if (ImGui::IsKeyPressed(69))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
if (ImGui::IsKeyPressed(82)) // r Key
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||||
|
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||||
|
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
|
||||||
|
|
||||||
|
if (mCurrentGizmoOperation != ImGuizmo::SCALE)
|
||||||
|
{
|
||||||
|
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::LOCAL;
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
|
||||||
|
mCurrentGizmoMode = ImGuizmo::WORLD;
|
||||||
|
}
|
||||||
|
static bool useSnap(false);
|
||||||
|
if (ImGui::IsKeyPressed(83))
|
||||||
|
useSnap = !useSnap;
|
||||||
|
ImGui::Checkbox("", &useSnap);
|
||||||
|
ImGui::SameLine();
|
||||||
|
vec_t snap;
|
||||||
|
switch (mCurrentGizmoOperation)
|
||||||
|
{
|
||||||
|
case ImGuizmo::TRANSLATE:
|
||||||
|
snap = config.mSnapTranslation;
|
||||||
|
ImGui::InputFloat3("Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::ROTATE:
|
||||||
|
snap = config.mSnapRotation;
|
||||||
|
ImGui::InputFloat("Angle Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
case ImGuizmo::SCALE:
|
||||||
|
snap = config.mSnapScale;
|
||||||
|
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||||
|
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef USE_IMGUI_API
|
||||||
|
#include "imconfig.h"
|
||||||
|
#endif
|
||||||
|
#ifndef IMGUI_API
|
||||||
|
#define IMGUI_API
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IMGUIZMO_NAMESPACE
|
||||||
|
#define IMGUIZMO_NAMESPACE ImGuizmo
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct ImGuiWindow;
|
||||||
|
|
||||||
|
namespace IMGUIZMO_NAMESPACE
|
||||||
|
{
|
||||||
|
// call inside your own window and before Manipulate() in order to draw gizmo to that window.
|
||||||
|
// Or pass a specific ImDrawList to draw to (e.g. ImGui::GetForegroundDrawList()).
|
||||||
|
IMGUI_API void SetDrawlist(ImDrawList* drawlist = nullptr);
|
||||||
|
|
||||||
|
// call BeginFrame right after ImGui_XXXX_NewFrame();
|
||||||
|
IMGUI_API void BeginFrame();
|
||||||
|
|
||||||
|
// this is necessary because when imguizmo is compiled into a dll, and imgui into another
|
||||||
|
// globals are not shared between them.
|
||||||
|
// More details at https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam
|
||||||
|
// expose method to set imgui context
|
||||||
|
IMGUI_API void SetImGuiContext(ImGuiContext* ctx);
|
||||||
|
|
||||||
|
// return true if mouse cursor is over any gizmo control (axis, plan or screen component)
|
||||||
|
IMGUI_API bool IsOver();
|
||||||
|
|
||||||
|
// return true if mouse IsOver or if the gizmo is in moving state
|
||||||
|
IMGUI_API bool IsUsing();
|
||||||
|
|
||||||
|
// return true if the view gizmo is in moving state
|
||||||
|
IMGUI_API bool IsUsingViewManipulate();
|
||||||
|
// only check if your mouse is over the view manipulator - no matter whether it's active or not
|
||||||
|
IMGUI_API bool IsViewManipulateHovered();
|
||||||
|
|
||||||
|
// return true if any gizmo is in moving state
|
||||||
|
IMGUI_API bool IsUsingAny();
|
||||||
|
|
||||||
|
// enable/disable the gizmo. Stay in the state until next call to Enable.
|
||||||
|
// gizmo is rendered with gray half transparent color when disabled
|
||||||
|
IMGUI_API void Enable(bool enable);
|
||||||
|
|
||||||
|
// helper functions for manualy editing translation/rotation/scale with an input float
|
||||||
|
// translation, rotation and scale float points to 3 floats each
|
||||||
|
// Angles are in degrees (more suitable for human editing)
|
||||||
|
// example:
|
||||||
|
// float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||||
|
// ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||||
|
// ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||||
|
// ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||||
|
// ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||||
|
// ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16);
|
||||||
|
//
|
||||||
|
// These functions have some numerical stability issues for now. Use with caution.
|
||||||
|
IMGUI_API void DecomposeMatrixToComponents(const float* matrix, float* translation, float* rotation, float* scale);
|
||||||
|
IMGUI_API void RecomposeMatrixFromComponents(const float* translation, const float* rotation, const float* scale, float* matrix);
|
||||||
|
|
||||||
|
IMGUI_API void SetRect(float x, float y, float width, float height);
|
||||||
|
// default is false
|
||||||
|
IMGUI_API void SetOrthographic(bool isOrthographic);
|
||||||
|
|
||||||
|
// Render a cube with face color corresponding to face normal. Usefull for debug/tests
|
||||||
|
IMGUI_API void DrawCubes(const float* view, const float* projection, const float* matrices, int matrixCount);
|
||||||
|
IMGUI_API void DrawGrid(const float* view, const float* projection, const float* matrix, const float gridSize);
|
||||||
|
|
||||||
|
// call it when you want a gizmo
|
||||||
|
// Needs view and projection matrices.
|
||||||
|
// matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional
|
||||||
|
// translation is applied in world space
|
||||||
|
enum OPERATION
|
||||||
|
{
|
||||||
|
TRANSLATE_X = (1u << 0),
|
||||||
|
TRANSLATE_Y = (1u << 1),
|
||||||
|
TRANSLATE_Z = (1u << 2),
|
||||||
|
ROTATE_X = (1u << 3),
|
||||||
|
ROTATE_Y = (1u << 4),
|
||||||
|
ROTATE_Z = (1u << 5),
|
||||||
|
ROTATE_SCREEN = (1u << 6),
|
||||||
|
SCALE_X = (1u << 7),
|
||||||
|
SCALE_Y = (1u << 8),
|
||||||
|
SCALE_Z = (1u << 9),
|
||||||
|
BOUNDS = (1u << 10),
|
||||||
|
SCALE_XU = (1u << 11),
|
||||||
|
SCALE_YU = (1u << 12),
|
||||||
|
SCALE_ZU = (1u << 13),
|
||||||
|
|
||||||
|
TRANSLATE = TRANSLATE_X | TRANSLATE_Y | TRANSLATE_Z,
|
||||||
|
ROTATE = ROTATE_X | ROTATE_Y | ROTATE_Z | ROTATE_SCREEN,
|
||||||
|
SCALE = SCALE_X | SCALE_Y | SCALE_Z,
|
||||||
|
SCALEU = SCALE_XU | SCALE_YU | SCALE_ZU, // universal
|
||||||
|
UNIVERSAL = TRANSLATE | ROTATE | SCALEU
|
||||||
|
};
|
||||||
|
|
||||||
|
inline OPERATION operator|(OPERATION lhs, OPERATION rhs)
|
||||||
|
{
|
||||||
|
return static_cast<OPERATION>(static_cast<int>(lhs) | static_cast<int>(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
enum MODE
|
||||||
|
{
|
||||||
|
LOCAL,
|
||||||
|
WORLD
|
||||||
|
};
|
||||||
|
|
||||||
|
IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL);
|
||||||
|
//
|
||||||
|
// Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en
|
||||||
|
// It seems to be a defensive patent in the US. I don't think it will bring troubles using it as
|
||||||
|
// other software are using the same mechanics. But just in case, you are now warned!
|
||||||
|
//
|
||||||
|
IMGUI_API void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
|
||||||
|
|
||||||
|
// use this version if you did not call Manipulate before and you are just using ViewManipulate
|
||||||
|
IMGUI_API void ViewManipulate(float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor);
|
||||||
|
|
||||||
|
IMGUI_API void SetAlternativeWindow(ImGuiWindow* window);
|
||||||
|
|
||||||
|
[[deprecated("Use PushID/PopID instead.")]]
|
||||||
|
IMGUI_API void SetID(int id);
|
||||||
|
|
||||||
|
// ID stack/scopes
|
||||||
|
// Read the FAQ (docs/FAQ.md or http://dearimgui.org/faq) for more details about how ID are handled in dear imgui.
|
||||||
|
// - Those questions are answered and impacted by understanding of the ID stack system:
|
||||||
|
// - "Q: Why is my widget not reacting when I click on it?"
|
||||||
|
// - "Q: How can I have widgets with an empty label?"
|
||||||
|
// - "Q: How can I have multiple widgets with the same label?"
|
||||||
|
// - Short version: ID are hashes of the entire ID stack. If you are creating widgets in a loop you most likely
|
||||||
|
// want to push a unique identifier (e.g. object pointer, loop index) to uniquely differentiate them.
|
||||||
|
// - You can also use the "Label##foobar" syntax within widget label to distinguish them from each others.
|
||||||
|
// - In this header file we use the "label"/"name" terminology to denote a string that will be displayed + used as an ID,
|
||||||
|
// whereas "str_id" denote a string that is only used as an ID and not normally displayed.
|
||||||
|
IMGUI_API void PushID(const char* str_id); // push string into the ID stack (will hash string).
|
||||||
|
IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end); // push string into the ID stack (will hash string).
|
||||||
|
IMGUI_API void PushID(const void* ptr_id); // push pointer into the ID stack (will hash pointer).
|
||||||
|
IMGUI_API void PushID(int int_id); // push integer into the ID stack (will hash integer).
|
||||||
|
IMGUI_API void PopID(); // pop from the ID stack.
|
||||||
|
IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). e.g. if you want to query into ImGuiStorage yourself
|
||||||
|
IMGUI_API ImGuiID GetID(const char* str_id_begin, const char* str_id_end);
|
||||||
|
IMGUI_API ImGuiID GetID(const void* ptr_id);
|
||||||
|
|
||||||
|
// return true if the cursor is over the operation's gizmo
|
||||||
|
IMGUI_API bool IsOver(OPERATION op);
|
||||||
|
IMGUI_API void SetGizmoSizeClipSpace(float value);
|
||||||
|
|
||||||
|
// Allow axis to flip
|
||||||
|
// When true (default), the guizmo axis flip for better visibility
|
||||||
|
// When false, they always stay along the positive world/local axis
|
||||||
|
IMGUI_API void AllowAxisFlip(bool value);
|
||||||
|
|
||||||
|
// Configure the limit where axis are hidden
|
||||||
|
IMGUI_API void SetAxisLimit(float value);
|
||||||
|
// Set an axis mask to permanently hide a given axis (true -> hidden, false -> shown)
|
||||||
|
IMGUI_API void SetAxisMask(bool x, bool y, bool z);
|
||||||
|
// Configure the limit where planes are hiden
|
||||||
|
IMGUI_API void SetPlaneLimit(float value);
|
||||||
|
// from a x,y,z point in space and using Manipulation view/projection matrix, check if mouse is in pixel radius distance of that projected point
|
||||||
|
IMGUI_API bool IsOver(float* position, float pixelRadius);
|
||||||
|
|
||||||
|
enum COLOR
|
||||||
|
{
|
||||||
|
DIRECTION_X, // directionColor[0]
|
||||||
|
DIRECTION_Y, // directionColor[1]
|
||||||
|
DIRECTION_Z, // directionColor[2]
|
||||||
|
PLANE_X, // planeColor[0]
|
||||||
|
PLANE_Y, // planeColor[1]
|
||||||
|
PLANE_Z, // planeColor[2]
|
||||||
|
SELECTION, // selectionColor
|
||||||
|
INACTIVE, // inactiveColor
|
||||||
|
TRANSLATION_LINE, // translationLineColor
|
||||||
|
SCALE_LINE,
|
||||||
|
ROTATION_USING_BORDER,
|
||||||
|
ROTATION_USING_FILL,
|
||||||
|
HATCHED_AXIS_LINES,
|
||||||
|
TEXT,
|
||||||
|
TEXT_SHADOW,
|
||||||
|
COUNT
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Style
|
||||||
|
{
|
||||||
|
IMGUI_API Style();
|
||||||
|
|
||||||
|
float TranslationLineThickness; // Thickness of lines for translation gizmo
|
||||||
|
float TranslationLineArrowSize; // Size of arrow at the end of lines for translation gizmo
|
||||||
|
float RotationLineThickness; // Thickness of lines for rotation gizmo
|
||||||
|
float RotationOuterLineThickness; // Thickness of line surrounding the rotation gizmo
|
||||||
|
float ScaleLineThickness; // Thickness of lines for scale gizmo
|
||||||
|
float ScaleLineCircleSize; // Size of circle at the end of lines for scale gizmo
|
||||||
|
float HatchedAxisLineThickness; // Thickness of hatched axis lines
|
||||||
|
float CenterCircleSize; // Size of circle at the center of the translate/scale gizmo
|
||||||
|
|
||||||
|
ImVec4 Colors[COLOR::COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
IMGUI_API Style& GetStyle();
|
||||||
|
}
|
79
include/ImSequencer.h
Normal file
79
include/ImSequencer.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// https://github.com/CedricGuillemet/ImGuizmo
|
||||||
|
// v1.91.3 WIP
|
||||||
|
//
|
||||||
|
// The MIT License(MIT)
|
||||||
|
//
|
||||||
|
// Copyright(c) 2021 Cedric Guillemet
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
struct ImDrawList;
|
||||||
|
struct ImRect;
|
||||||
|
namespace ImSequencer
|
||||||
|
{
|
||||||
|
enum SEQUENCER_OPTIONS
|
||||||
|
{
|
||||||
|
SEQUENCER_EDIT_NONE = 0,
|
||||||
|
SEQUENCER_EDIT_STARTEND = 1 << 1,
|
||||||
|
SEQUENCER_CHANGE_FRAME = 1 << 3,
|
||||||
|
SEQUENCER_ADD = 1 << 4,
|
||||||
|
SEQUENCER_DEL = 1 << 5,
|
||||||
|
SEQUENCER_COPYPASTE = 1 << 6,
|
||||||
|
SEQUENCER_EDIT_ALL = SEQUENCER_EDIT_STARTEND | SEQUENCER_CHANGE_FRAME
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SequenceInterface
|
||||||
|
{
|
||||||
|
bool focused = false;
|
||||||
|
virtual int GetFrameMin() const = 0;
|
||||||
|
virtual int GetFrameMax() const = 0;
|
||||||
|
virtual int GetItemCount() const = 0;
|
||||||
|
|
||||||
|
virtual void BeginEdit(int /*index*/) {}
|
||||||
|
virtual void EndEdit() {}
|
||||||
|
virtual int GetItemTypeCount() const { return 0; }
|
||||||
|
virtual const char* GetItemTypeName(int /*typeIndex*/) const { return ""; }
|
||||||
|
virtual const char* GetItemLabel(int /*index*/) const { return ""; }
|
||||||
|
virtual const char* GetCollapseFmt() const { return "%d Frames / %d entries"; }
|
||||||
|
|
||||||
|
virtual void Get(int index, int** start, int** end, int* type, unsigned int* color) = 0;
|
||||||
|
virtual void Add(int /*type*/) {}
|
||||||
|
virtual void Del(int /*index*/) {}
|
||||||
|
virtual void Duplicate(int /*index*/) {}
|
||||||
|
|
||||||
|
virtual void Copy() {}
|
||||||
|
virtual void Paste() {}
|
||||||
|
|
||||||
|
virtual size_t GetCustomHeight(int /*index*/) { return 0; }
|
||||||
|
virtual void DoubleClick(int /*index*/) {}
|
||||||
|
virtual void CustomDraw(int /*index*/, ImDrawList* /*draw_list*/, const ImRect& /*rc*/, const ImRect& /*legendRect*/, const ImRect& /*clippingRect*/, const ImRect& /*legendClippingRect*/) {}
|
||||||
|
virtual void CustomDrawCompact(int /*index*/, ImDrawList* /*draw_list*/, const ImRect& /*rc*/, const ImRect& /*clippingRect*/) {}
|
||||||
|
|
||||||
|
virtual ~SequenceInterface() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// return true if selection is made
|
||||||
|
bool Sequencer(SequenceInterface* sequence, int* currentFrame, bool* expanded, int* selectedEntry, int* firstFrame, int sequenceOptions);
|
||||||
|
|
||||||
|
}
|
311
include/KHR/khrplatform.h
Normal file
311
include/KHR/khrplatform.h
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
#ifndef __khrplatform_h_
|
||||||
|
#define __khrplatform_h_
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||||
|
**
|
||||||
|
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
** copy of this software and/or associated documentation files (the
|
||||||
|
** "Materials"), to deal in the Materials without restriction, including
|
||||||
|
** without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
** permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
** the following conditions:
|
||||||
|
**
|
||||||
|
** The above copyright notice and this permission notice shall be included
|
||||||
|
** in all copies or substantial portions of the Materials.
|
||||||
|
**
|
||||||
|
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Khronos platform-specific types and definitions.
|
||||||
|
*
|
||||||
|
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||||
|
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||||
|
* The last semantic modification to khrplatform.h was at commit ID:
|
||||||
|
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||||
|
*
|
||||||
|
* Adopters may modify this file to suit their platform. Adopters are
|
||||||
|
* encouraged to submit platform specific modifications to the Khronos
|
||||||
|
* group so that they can be included in future versions of this file.
|
||||||
|
* Please submit changes by filing pull requests or issues on
|
||||||
|
* the EGL Registry repository linked above.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* See the Implementer's Guidelines for information about where this file
|
||||||
|
* should be located on your system and for more details of its use:
|
||||||
|
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||||
|
*
|
||||||
|
* This file should be included as
|
||||||
|
* #include <KHR/khrplatform.h>
|
||||||
|
* by Khronos client API header files that use its types and defines.
|
||||||
|
*
|
||||||
|
* The types in khrplatform.h should only be used to define API-specific types.
|
||||||
|
*
|
||||||
|
* Types defined in khrplatform.h:
|
||||||
|
* khronos_int8_t signed 8 bit
|
||||||
|
* khronos_uint8_t unsigned 8 bit
|
||||||
|
* khronos_int16_t signed 16 bit
|
||||||
|
* khronos_uint16_t unsigned 16 bit
|
||||||
|
* khronos_int32_t signed 32 bit
|
||||||
|
* khronos_uint32_t unsigned 32 bit
|
||||||
|
* khronos_int64_t signed 64 bit
|
||||||
|
* khronos_uint64_t unsigned 64 bit
|
||||||
|
* khronos_intptr_t signed same number of bits as a pointer
|
||||||
|
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||||
|
* khronos_ssize_t signed size
|
||||||
|
* khronos_usize_t unsigned size
|
||||||
|
* khronos_float_t signed 32 bit floating point
|
||||||
|
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||||
|
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||||
|
* nanoseconds
|
||||||
|
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||||
|
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||||
|
* only be used as a base type when a client API's boolean type is
|
||||||
|
* an enum. Client APIs which use an integer or other type for
|
||||||
|
* booleans cannot use this as the base type for their boolean.
|
||||||
|
*
|
||||||
|
* Tokens defined in khrplatform.h:
|
||||||
|
*
|
||||||
|
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||||
|
*
|
||||||
|
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||||
|
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||||
|
*
|
||||||
|
* Calling convention macros defined in this file:
|
||||||
|
* KHRONOS_APICALL
|
||||||
|
* KHRONOS_APIENTRY
|
||||||
|
* KHRONOS_APIATTRIBUTES
|
||||||
|
*
|
||||||
|
* These may be used in function prototypes as:
|
||||||
|
*
|
||||||
|
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||||
|
* int arg1,
|
||||||
|
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||||
|
# define KHRONOS_STATIC 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APICALL
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This precedes the return type of the function in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(KHRONOS_STATIC)
|
||||||
|
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||||
|
* header compatible with static linking. */
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
# define KHRONOS_APICALL __declspec(dllimport)
|
||||||
|
#elif defined (__SYMBIAN32__)
|
||||||
|
# define KHRONOS_APICALL IMPORT_C
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APICALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIENTRY
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the return type of the function and precedes the function
|
||||||
|
* name in the function prototype.
|
||||||
|
*/
|
||||||
|
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||||
|
/* Win32 but not WinCE */
|
||||||
|
# define KHRONOS_APIENTRY __stdcall
|
||||||
|
#else
|
||||||
|
# define KHRONOS_APIENTRY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* Definition of KHRONOS_APIATTRIBUTES
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
* This follows the closing parenthesis of the function prototype arguments.
|
||||||
|
*/
|
||||||
|
#if defined (__ARMCC_2__)
|
||||||
|
#define KHRONOS_APIATTRIBUTES __softfp
|
||||||
|
#else
|
||||||
|
#define KHRONOS_APIATTRIBUTES
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
* basic type definitions
|
||||||
|
*-----------------------------------------------------------------------*/
|
||||||
|
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <stdint.h>
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
/*
|
||||||
|
* To support platform where unsigned long cannot be used interchangeably with
|
||||||
|
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||||
|
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||||
|
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||||
|
* unsigned long long or similar (this results in different C++ name mangling).
|
||||||
|
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||||
|
* platforms where the size of a pointer is larger than the size of long.
|
||||||
|
*/
|
||||||
|
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||||
|
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||||
|
#define KHRONOS_USE_INTPTR_T
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(__VMS ) || defined(__sgi)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using <inttypes.h>
|
||||||
|
*/
|
||||||
|
#include <inttypes.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Win32
|
||||||
|
*/
|
||||||
|
typedef __int32 khronos_int32_t;
|
||||||
|
typedef unsigned __int32 khronos_uint32_t;
|
||||||
|
typedef __int64 khronos_int64_t;
|
||||||
|
typedef unsigned __int64 khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif defined(__sun__) || defined(__digital__)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sun or Digital
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#if defined(__arch64__) || defined(_LP64)
|
||||||
|
typedef long int khronos_int64_t;
|
||||||
|
typedef unsigned long int khronos_uint64_t;
|
||||||
|
#else
|
||||||
|
typedef long long int khronos_int64_t;
|
||||||
|
typedef unsigned long long int khronos_uint64_t;
|
||||||
|
#endif /* __arch64__ */
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#elif 0
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hypothetical platform with no float or int64 support
|
||||||
|
*/
|
||||||
|
typedef int khronos_int32_t;
|
||||||
|
typedef unsigned int khronos_uint32_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 0
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 0
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic fallback
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
typedef int32_t khronos_int32_t;
|
||||||
|
typedef uint32_t khronos_uint32_t;
|
||||||
|
typedef int64_t khronos_int64_t;
|
||||||
|
typedef uint64_t khronos_uint64_t;
|
||||||
|
#define KHRONOS_SUPPORT_INT64 1
|
||||||
|
#define KHRONOS_SUPPORT_FLOAT 1
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that are (so far) the same on all platforms
|
||||||
|
*/
|
||||||
|
typedef signed char khronos_int8_t;
|
||||||
|
typedef unsigned char khronos_uint8_t;
|
||||||
|
typedef signed short int khronos_int16_t;
|
||||||
|
typedef unsigned short int khronos_uint16_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||||
|
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||||
|
* to be the only LLP64 architecture in current use.
|
||||||
|
*/
|
||||||
|
#ifdef KHRONOS_USE_INTPTR_T
|
||||||
|
typedef intptr_t khronos_intptr_t;
|
||||||
|
typedef uintptr_t khronos_uintptr_t;
|
||||||
|
#elif defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_intptr_t;
|
||||||
|
typedef unsigned long long int khronos_uintptr_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_intptr_t;
|
||||||
|
typedef unsigned long int khronos_uintptr_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN64)
|
||||||
|
typedef signed long long int khronos_ssize_t;
|
||||||
|
typedef unsigned long long int khronos_usize_t;
|
||||||
|
#else
|
||||||
|
typedef signed long int khronos_ssize_t;
|
||||||
|
typedef unsigned long int khronos_usize_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_FLOAT
|
||||||
|
/*
|
||||||
|
* Float type
|
||||||
|
*/
|
||||||
|
typedef float khronos_float_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if KHRONOS_SUPPORT_INT64
|
||||||
|
/* Time types
|
||||||
|
*
|
||||||
|
* These types can be used to represent a time interval in nanoseconds or
|
||||||
|
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||||
|
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||||
|
* time the system booted). The Unadjusted System Time is an unsigned
|
||||||
|
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||||
|
* may be either signed or unsigned.
|
||||||
|
*/
|
||||||
|
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||||
|
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dummy value used to pad enum types to 32 bits.
|
||||||
|
*/
|
||||||
|
#ifndef KHRONOS_MAX_ENUM
|
||||||
|
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enumerated boolean type
|
||||||
|
*
|
||||||
|
* Values other than zero should be considered to be true. Therefore
|
||||||
|
* comparisons should not be made against KHRONOS_TRUE.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
KHRONOS_FALSE = 0,
|
||||||
|
KHRONOS_TRUE = 1,
|
||||||
|
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||||
|
} khronos_boolean_enum_t;
|
||||||
|
|
||||||
|
#endif /* __khrplatform_h_ */
|
5331
include/glad.h
Normal file
5331
include/glad.h
Normal file
File diff suppressed because it is too large
Load Diff
5331
include/glad/glad.h
Normal file
5331
include/glad/glad.h
Normal file
File diff suppressed because it is too large
Load Diff
139
include/imconfig.h
Normal file
139
include/imconfig.h
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// DEAR IMGUI COMPILE-TIME OPTIONS
|
||||||
|
// 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 file 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.
|
||||||
|
// - Windows 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) // MSVC Windows: DLL export
|
||||||
|
//#define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import
|
||||||
|
//#define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden
|
||||||
|
|
||||||
|
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
|
||||||
|
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
|
|
||||||
|
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||||||
|
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. 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.
|
||||||
|
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() 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_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
|
||||||
|
//#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_DEFAULT_FONT // Disable default embedded font (ProggyClean.ttf), remove ~9.5 KB from output binary. AddFontDefault() will assert.
|
||||||
|
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||||
|
|
||||||
|
//---- Enable Test Engine / Automation features.
|
||||||
|
//#define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by include "imgui_te_config.h", see Test Engine for details.
|
||||||
|
|
||||||
|
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||||
|
// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included.
|
||||||
|
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||||
|
//#define IMGUI_USER_H_FILENAME "my_folder/my_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_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined.
|
||||||
|
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.
|
||||||
|
|
||||||
|
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||||
|
// 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.h.
|
||||||
|
//#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 FreeType + plutosvg or lunasvg to render OpenType SVG fonts (SVGinOT)
|
||||||
|
// Only works in combination with IMGUI_ENABLE_FREETYPE.
|
||||||
|
// - lunasvg is currently easier to acquire/install, as e.g. it is part of vcpkg.
|
||||||
|
// - plutosvg will support more fonts and may load them faster. It currently requires to be built manually but it is fairly easy. See misc/freetype/README for instructions.
|
||||||
|
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
|
||||||
|
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||||||
|
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||||
|
|
||||||
|
//---- 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 \
|
||||||
|
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
|
||||||
|
operator MyVec2() const { return MyVec2(x,y); }
|
||||||
|
|
||||||
|
#define IM_VEC4_CLASS_EXTRA \
|
||||||
|
constexpr 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); }
|
||||||
|
*/
|
||||||
|
//---- ...Or use Dear ImGui's own very basic math operators.
|
||||||
|
//#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
|
//---- 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 (we provide a default implementation of this in the codebase)
|
||||||
|
// (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: Enable slower asserts
|
||||||
|
//#define IMGUI_DEBUG_PARANOID
|
||||||
|
|
||||||
|
//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files)
|
||||||
|
/*
|
||||||
|
namespace ImGui
|
||||||
|
{
|
||||||
|
void MyFunction(const char* name, MyMatrix44* mtx);
|
||||||
|
}
|
||||||
|
*/
|
3975
include/imgui.h
Normal file
3975
include/imgui.h
Normal file
File diff suppressed because it is too large
Load Diff
67
include/imgui_impl_glfw.h
Normal file
67
include/imgui_impl_glfw.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// dear imgui: Platform Backend for GLFW
|
||||||
|
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
|
||||||
|
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||||
|
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.)
|
||||||
|
|
||||||
|
// Implemented features:
|
||||||
|
// [X] Platform: Clipboard support.
|
||||||
|
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
|
||||||
|
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||||
|
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||||
|
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
|
||||||
|
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
|
// Issues:
|
||||||
|
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "imgui.h" // IMGUI_IMPL_API
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
struct GLFWwindow;
|
||||||
|
struct GLFWmonitor;
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
|
||||||
|
|
||||||
|
// Emscripten related initialization phase methods (call after ImGui_ImplGlfw_InitForOpenGL)
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* window, const char* canvas_selector);
|
||||||
|
//static inline void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector) { ImGui_ImplGlfw_InstallEmscriptenCallbacks(nullptr, canvas_selector); } } // Renamed in 1.91.0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// GLFW callbacks install
|
||||||
|
// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
|
||||||
|
// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks.
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
|
||||||
|
|
||||||
|
// GFLW callbacks options:
|
||||||
|
// - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user)
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows);
|
||||||
|
|
||||||
|
// GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks)
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event);
|
||||||
|
|
||||||
|
// GLFW helpers
|
||||||
|
IMGUI_IMPL_API void ImGui_ImplGlfw_Sleep(int milliseconds);
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
67
include/imgui_impl_opengl3.h
Normal file
67
include/imgui_impl_opengl3.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// 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: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
|
||||||
|
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
|
|
||||||
|
// About WebGL/ES:
|
||||||
|
// - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
|
||||||
|
// - This is done automatically on iOS, Android and Emscripten targets.
|
||||||
|
// - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
// About GLSL version:
|
||||||
|
// The 'glsl_version' initialization parameter should be nullptr (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
|
||||||
|
#ifndef IMGUI_DISABLE
|
||||||
|
|
||||||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||||
|
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
|
||||||
|
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();
|
||||||
|
|
||||||
|
// Configuration flags to add in your imconfig file:
|
||||||
|
//#define IMGUI_IMPL_OPENGL_ES2 // Enable ES 2 (Auto-detected on Emscripten)
|
||||||
|
//#define IMGUI_IMPL_OPENGL_ES3 // Enable ES 3 (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__) || defined(__amigaos4__)
|
||||||
|
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
|
||||||
|
#else
|
||||||
|
// Otherwise imgui_impl_opengl3_loader.h will be used.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifndef IMGUI_DISABLE
|
916
include/imgui_impl_opengl3_loader.h
Normal file
916
include/imgui_impl_opengl3_loader.h
Normal file
@ -0,0 +1,916 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// About imgui_impl_opengl3_loader.h:
|
||||||
|
//
|
||||||
|
// 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 our imgui_impl_opengl3.cpp source file in order to be small.
|
||||||
|
//
|
||||||
|
// YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY.
|
||||||
|
// THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE.
|
||||||
|
//
|
||||||
|
// IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions):
|
||||||
|
// IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCLUDING 'imgui_impl_opengl3_loader.h'
|
||||||
|
// IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER.
|
||||||
|
// (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS)
|
||||||
|
// YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT.
|
||||||
|
// BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp
|
||||||
|
// WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT.
|
||||||
|
//
|
||||||
|
// Regenerate with:
|
||||||
|
// python3 gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
|
||||||
|
//
|
||||||
|
// More info:
|
||||||
|
// https://github.com/dearimgui/gl3w_stripped
|
||||||
|
// https://github.com/ocornut/imgui/issues/4445
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __gl3w_h_
|
||||||
|
#define __gl3w_h_
|
||||||
|
|
||||||
|
// Adapted from KHR/khrplatform.h to avoid including entire file.
|
||||||
|
#ifndef __khrplatform_h_
|
||||||
|
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
|
||||||
|
#endif // __khrplatform_h_
|
||||||
|
|
||||||
|
#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 0x0404
|
||||||
|
#define GL_BACK 0x0405
|
||||||
|
#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_VENDOR 0x1F00
|
||||||
|
#define GL_RENDERER 0x1F01
|
||||||
|
#define GL_VERSION 0x1F02
|
||||||
|
#define GL_EXTENSIONS 0x1F03
|
||||||
|
#define GL_LINEAR 0x2601
|
||||||
|
#define GL_TEXTURE_MAG_FILTER 0x2800
|
||||||
|
#define GL_TEXTURE_MIN_FILTER 0x2801
|
||||||
|
#define GL_TEXTURE_WRAP_S 0x2802
|
||||||
|
#define GL_TEXTURE_WRAP_T 0x2803
|
||||||
|
#define GL_REPEAT 0x2901
|
||||||
|
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 PFNGLFLUSHPROC) (void);
|
||||||
|
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 GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
|
||||||
|
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 glFlush (void);
|
||||||
|
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 GLenum APIENTRY glGetError (void);
|
||||||
|
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_2
|
||||||
|
#define GL_CLAMP_TO_EDGE 0x812F
|
||||||
|
#endif /* GL_VERSION_1_2 */
|
||||||
|
#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_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
|
||||||
|
#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);
|
||||||
|
typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||||
|
#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);
|
||||||
|
GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
|
||||||
|
#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_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
|
||||||
|
#define GL_BLEND_EQUATION_ALPHA 0x883D
|
||||||
|
#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
|
||||||
|
#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 PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
|
||||||
|
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 PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
|
||||||
|
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
|
||||||
|
typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
|
||||||
|
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 glDisableVertexAttribArray (GLuint index);
|
||||||
|
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 glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
|
||||||
|
GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
|
||||||
|
GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
|
||||||
|
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_2_1
|
||||||
|
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
||||||
|
#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
|
||||||
|
#endif /* GL_VERSION_2_1 */
|
||||||
|
#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;
|
||||||
|
#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
|
||||||
|
#define GL_CONTEXT_PROFILE_MASK 0x9126
|
||||||
|
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 ImGL3WProcs {
|
||||||
|
GL3WglProc ptr[59];
|
||||||
|
struct {
|
||||||
|
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||||
|
PFNGLATTACHSHADERPROC AttachShader;
|
||||||
|
PFNGLBINDBUFFERPROC BindBuffer;
|
||||||
|
PFNGLBINDSAMPLERPROC BindSampler;
|
||||||
|
PFNGLBINDTEXTUREPROC BindTexture;
|
||||||
|
PFNGLBINDVERTEXARRAYPROC BindVertexArray;
|
||||||
|
PFNGLBLENDEQUATIONPROC BlendEquation;
|
||||||
|
PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
|
||||||
|
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
|
||||||
|
PFNGLBUFFERDATAPROC BufferData;
|
||||||
|
PFNGLBUFFERSUBDATAPROC BufferSubData;
|
||||||
|
PFNGLCLEARPROC Clear;
|
||||||
|
PFNGLCLEARCOLORPROC ClearColor;
|
||||||
|
PFNGLCOMPILESHADERPROC CompileShader;
|
||||||
|
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||||
|
PFNGLCREATESHADERPROC CreateShader;
|
||||||
|
PFNGLDELETEBUFFERSPROC DeleteBuffers;
|
||||||
|
PFNGLDELETEPROGRAMPROC DeleteProgram;
|
||||||
|
PFNGLDELETESHADERPROC DeleteShader;
|
||||||
|
PFNGLDELETETEXTURESPROC DeleteTextures;
|
||||||
|
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
|
||||||
|
PFNGLDETACHSHADERPROC DetachShader;
|
||||||
|
PFNGLDISABLEPROC Disable;
|
||||||
|
PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
|
||||||
|
PFNGLDRAWELEMENTSPROC DrawElements;
|
||||||
|
PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
|
||||||
|
PFNGLENABLEPROC Enable;
|
||||||
|
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
|
||||||
|
PFNGLFLUSHPROC Flush;
|
||||||
|
PFNGLGENBUFFERSPROC GenBuffers;
|
||||||
|
PFNGLGENTEXTURESPROC GenTextures;
|
||||||
|
PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
|
||||||
|
PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
|
||||||
|
PFNGLGETERRORPROC GetError;
|
||||||
|
PFNGLGETINTEGERVPROC GetIntegerv;
|
||||||
|
PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
|
||||||
|
PFNGLGETPROGRAMIVPROC GetProgramiv;
|
||||||
|
PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
|
||||||
|
PFNGLGETSHADERIVPROC GetShaderiv;
|
||||||
|
PFNGLGETSTRINGPROC GetString;
|
||||||
|
PFNGLGETSTRINGIPROC GetStringi;
|
||||||
|
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
|
||||||
|
PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
|
||||||
|
PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
|
||||||
|
PFNGLISENABLEDPROC IsEnabled;
|
||||||
|
PFNGLISPROGRAMPROC IsProgram;
|
||||||
|
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 ImGL3WProcs imgl3wProcs;
|
||||||
|
|
||||||
|
/* OpenGL functions */
|
||||||
|
#define glActiveTexture imgl3wProcs.gl.ActiveTexture
|
||||||
|
#define glAttachShader imgl3wProcs.gl.AttachShader
|
||||||
|
#define glBindBuffer imgl3wProcs.gl.BindBuffer
|
||||||
|
#define glBindSampler imgl3wProcs.gl.BindSampler
|
||||||
|
#define glBindTexture imgl3wProcs.gl.BindTexture
|
||||||
|
#define glBindVertexArray imgl3wProcs.gl.BindVertexArray
|
||||||
|
#define glBlendEquation imgl3wProcs.gl.BlendEquation
|
||||||
|
#define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate
|
||||||
|
#define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate
|
||||||
|
#define glBufferData imgl3wProcs.gl.BufferData
|
||||||
|
#define glBufferSubData imgl3wProcs.gl.BufferSubData
|
||||||
|
#define glClear imgl3wProcs.gl.Clear
|
||||||
|
#define glClearColor imgl3wProcs.gl.ClearColor
|
||||||
|
#define glCompileShader imgl3wProcs.gl.CompileShader
|
||||||
|
#define glCreateProgram imgl3wProcs.gl.CreateProgram
|
||||||
|
#define glCreateShader imgl3wProcs.gl.CreateShader
|
||||||
|
#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
|
||||||
|
#define glDeleteProgram imgl3wProcs.gl.DeleteProgram
|
||||||
|
#define glDeleteShader imgl3wProcs.gl.DeleteShader
|
||||||
|
#define glDeleteTextures imgl3wProcs.gl.DeleteTextures
|
||||||
|
#define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays
|
||||||
|
#define glDetachShader imgl3wProcs.gl.DetachShader
|
||||||
|
#define glDisable imgl3wProcs.gl.Disable
|
||||||
|
#define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray
|
||||||
|
#define glDrawElements imgl3wProcs.gl.DrawElements
|
||||||
|
#define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex
|
||||||
|
#define glEnable imgl3wProcs.gl.Enable
|
||||||
|
#define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray
|
||||||
|
#define glFlush imgl3wProcs.gl.Flush
|
||||||
|
#define glGenBuffers imgl3wProcs.gl.GenBuffers
|
||||||
|
#define glGenTextures imgl3wProcs.gl.GenTextures
|
||||||
|
#define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays
|
||||||
|
#define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation
|
||||||
|
#define glGetError imgl3wProcs.gl.GetError
|
||||||
|
#define glGetIntegerv imgl3wProcs.gl.GetIntegerv
|
||||||
|
#define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog
|
||||||
|
#define glGetProgramiv imgl3wProcs.gl.GetProgramiv
|
||||||
|
#define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog
|
||||||
|
#define glGetShaderiv imgl3wProcs.gl.GetShaderiv
|
||||||
|
#define glGetString imgl3wProcs.gl.GetString
|
||||||
|
#define glGetStringi imgl3wProcs.gl.GetStringi
|
||||||
|
#define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation
|
||||||
|
#define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv
|
||||||
|
#define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv
|
||||||
|
#define glIsEnabled imgl3wProcs.gl.IsEnabled
|
||||||
|
#define glIsProgram imgl3wProcs.gl.IsProgram
|
||||||
|
#define glLinkProgram imgl3wProcs.gl.LinkProgram
|
||||||
|
#define glPixelStorei imgl3wProcs.gl.PixelStorei
|
||||||
|
#define glPolygonMode imgl3wProcs.gl.PolygonMode
|
||||||
|
#define glReadPixels imgl3wProcs.gl.ReadPixels
|
||||||
|
#define glScissor imgl3wProcs.gl.Scissor
|
||||||
|
#define glShaderSource imgl3wProcs.gl.ShaderSource
|
||||||
|
#define glTexImage2D imgl3wProcs.gl.TexImage2D
|
||||||
|
#define glTexParameteri imgl3wProcs.gl.TexParameteri
|
||||||
|
#define glUniform1i imgl3wProcs.gl.Uniform1i
|
||||||
|
#define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv
|
||||||
|
#define glUseProgram imgl3wProcs.gl.UseProgram
|
||||||
|
#define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer
|
||||||
|
#define glViewport imgl3wProcs.gl.Viewport
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IMGL3W_IMPL
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define GL3W_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; // OpenGL library
|
||||||
|
static void* libglx; // GLX library
|
||||||
|
static void* libegl; // EGL library
|
||||||
|
static GL3WGetProcAddressProc gl_get_proc_address;
|
||||||
|
|
||||||
|
static void close_libgl(void)
|
||||||
|
{
|
||||||
|
if (libgl) {
|
||||||
|
dlclose(libgl);
|
||||||
|
libgl = NULL;
|
||||||
|
}
|
||||||
|
if (libegl) {
|
||||||
|
dlclose(libegl);
|
||||||
|
libegl = NULL;
|
||||||
|
}
|
||||||
|
if (libglx) {
|
||||||
|
dlclose(libglx);
|
||||||
|
libglx = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_library_loaded(const char* name, void** lib)
|
||||||
|
{
|
||||||
|
*lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
|
||||||
|
return *lib != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int open_libs(void)
|
||||||
|
{
|
||||||
|
// On Linux we have two APIs to get process addresses: EGL and GLX.
|
||||||
|
// EGL is supported under both X11 and Wayland, whereas GLX is X11-specific.
|
||||||
|
|
||||||
|
libgl = NULL;
|
||||||
|
libegl = NULL;
|
||||||
|
libglx = NULL;
|
||||||
|
|
||||||
|
// First check what's already loaded, the windowing library might have
|
||||||
|
// already loaded either EGL or GLX and we want to use the same one.
|
||||||
|
|
||||||
|
if (is_library_loaded("libEGL.so.1", &libegl) ||
|
||||||
|
is_library_loaded("libGLX.so.0", &libglx)) {
|
||||||
|
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (libgl)
|
||||||
|
return GL3W_OK;
|
||||||
|
else
|
||||||
|
close_libgl();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_library_loaded("libGL.so", &libgl))
|
||||||
|
return GL3W_OK;
|
||||||
|
if (is_library_loaded("libGL.so.1", &libgl))
|
||||||
|
return GL3W_OK;
|
||||||
|
if (is_library_loaded("libGL.so.3", &libgl))
|
||||||
|
return GL3W_OK;
|
||||||
|
|
||||||
|
// Neither is already loaded, so we have to load one. Try EGL first
|
||||||
|
// because it is supported under both X11 and Wayland.
|
||||||
|
|
||||||
|
// Load OpenGL + EGL
|
||||||
|
libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
libegl = dlopen("libEGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (libgl && libegl)
|
||||||
|
return GL3W_OK;
|
||||||
|
else
|
||||||
|
close_libgl();
|
||||||
|
|
||||||
|
// Fall back to legacy libGL, which includes GLX
|
||||||
|
// While most systems use libGL.so.1, NetBSD seems to use that libGL.so.3. See https://github.com/ocornut/imgui/issues/6983
|
||||||
|
libgl = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!libgl)
|
||||||
|
libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!libgl)
|
||||||
|
libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
|
||||||
|
if (libgl)
|
||||||
|
return GL3W_OK;
|
||||||
|
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int open_libgl(void)
|
||||||
|
{
|
||||||
|
int res = open_libs();
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
if (libegl)
|
||||||
|
*(void**)(&gl_get_proc_address) = dlsym(libegl, "eglGetProcAddress");
|
||||||
|
else if (libglx)
|
||||||
|
*(void**)(&gl_get_proc_address) = dlsym(libglx, "glXGetProcAddressARB");
|
||||||
|
else
|
||||||
|
*(void**)(&gl_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
|
||||||
|
|
||||||
|
if (!gl_get_proc_address) {
|
||||||
|
close_libgl();
|
||||||
|
return GL3W_ERROR_LIBRARY_OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GL3W_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GL3WglProc get_proc(const char* proc)
|
||||||
|
{
|
||||||
|
GL3WglProc res = NULL;
|
||||||
|
|
||||||
|
// Before EGL version 1.5, eglGetProcAddress doesn't support querying core
|
||||||
|
// functions and may return a dummy function if we try, so try to load the
|
||||||
|
// function from the GL library directly first.
|
||||||
|
if (libegl)
|
||||||
|
*(void**)(&res) = dlsym(libgl, proc);
|
||||||
|
|
||||||
|
if (!res)
|
||||||
|
res = gl_get_proc_address(proc);
|
||||||
|
|
||||||
|
if (!libegl && !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 == 0 && version.minor == 0)
|
||||||
|
{
|
||||||
|
// Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
|
||||||
|
if (const char* gl_version = (const char*)glGetString(GL_VERSION))
|
||||||
|
sscanf(gl_version, "%d.%d", &version.major, &version.minor);
|
||||||
|
}
|
||||||
|
if (version.major < 2)
|
||||||
|
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 < 2)
|
||||||
|
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",
|
||||||
|
"glBufferSubData",
|
||||||
|
"glClear",
|
||||||
|
"glClearColor",
|
||||||
|
"glCompileShader",
|
||||||
|
"glCreateProgram",
|
||||||
|
"glCreateShader",
|
||||||
|
"glDeleteBuffers",
|
||||||
|
"glDeleteProgram",
|
||||||
|
"glDeleteShader",
|
||||||
|
"glDeleteTextures",
|
||||||
|
"glDeleteVertexArrays",
|
||||||
|
"glDetachShader",
|
||||||
|
"glDisable",
|
||||||
|
"glDisableVertexAttribArray",
|
||||||
|
"glDrawElements",
|
||||||
|
"glDrawElementsBaseVertex",
|
||||||
|
"glEnable",
|
||||||
|
"glEnableVertexAttribArray",
|
||||||
|
"glFlush",
|
||||||
|
"glGenBuffers",
|
||||||
|
"glGenTextures",
|
||||||
|
"glGenVertexArrays",
|
||||||
|
"glGetAttribLocation",
|
||||||
|
"glGetError",
|
||||||
|
"glGetIntegerv",
|
||||||
|
"glGetProgramInfoLog",
|
||||||
|
"glGetProgramiv",
|
||||||
|
"glGetShaderInfoLog",
|
||||||
|
"glGetShaderiv",
|
||||||
|
"glGetString",
|
||||||
|
"glGetStringi",
|
||||||
|
"glGetUniformLocation",
|
||||||
|
"glGetVertexAttribPointerv",
|
||||||
|
"glGetVertexAttribiv",
|
||||||
|
"glIsEnabled",
|
||||||
|
"glIsProgram",
|
||||||
|
"glLinkProgram",
|
||||||
|
"glPixelStorei",
|
||||||
|
"glPolygonMode",
|
||||||
|
"glReadPixels",
|
||||||
|
"glScissor",
|
||||||
|
"glShaderSource",
|
||||||
|
"glTexImage2D",
|
||||||
|
"glTexParameteri",
|
||||||
|
"glUniform1i",
|
||||||
|
"glUniformMatrix4fv",
|
||||||
|
"glUseProgram",
|
||||||
|
"glVertexAttribPointer",
|
||||||
|
"glViewport",
|
||||||
|
};
|
||||||
|
|
||||||
|
GL3W_API union ImGL3WProcs imgl3wProcs;
|
||||||
|
|
||||||
|
static void load_procs(GL3WGetProcAddressProc proc)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
|
||||||
|
imgl3wProcs.ptr[i] = proc(proc_names[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
3881
include/imgui_internal.h
Normal file
3881
include/imgui_internal.h
Normal file
File diff suppressed because it is too large
Load Diff
627
include/imstb_rectpack.h
Normal file
627
include/imstb_rectpack.h
Normal file
@ -0,0 +1,627 @@
|
|||||||
|
// [DEAR IMGUI]
|
||||||
|
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||||
|
// Grep for [DEAR IMGUI] to find the changes.
|
||||||
|
//
|
||||||
|
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||||
|
// Sean Barrett 2014
|
||||||
|
//
|
||||||
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
|
// Does not do rotation.
|
||||||
|
//
|
||||||
|
// Before #including,
|
||||||
|
//
|
||||||
|
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
//
|
||||||
|
// in the file that you want to have the implementation.
|
||||||
|
//
|
||||||
|
// 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.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
typedef int stbrp_coord;
|
||||||
|
|
||||||
|
#define STBRP__MAXVAL 0x7fffffff
|
||||||
|
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
context->extra[1].y = (1<<30);
|
||||||
|
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); [DEAR IMGUI]
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
1469
include/imstb_textedit.h
Normal file
1469
include/imstb_textedit.h
Normal file
File diff suppressed because it is too large
Load Diff
5085
include/imstb_truetype.h
Normal file
5085
include/imstb_truetype.h
Normal file
File diff suppressed because it is too large
Load Diff
7988
include/stb_image.h
Normal file
7988
include/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
41
main.py
Normal file
41
main.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import trimesh
|
||||||
|
|
||||||
|
def generate_vertex_array_from_model(file_path):
|
||||||
|
# Load the model using trimesh
|
||||||
|
mesh = trimesh.load(file_path)
|
||||||
|
|
||||||
|
# Ensure the mesh has valid geometry
|
||||||
|
if not mesh.is_volume:
|
||||||
|
print("Warning: The loaded mesh is not a closed volume.")
|
||||||
|
|
||||||
|
# Prepare vertex array data
|
||||||
|
vertices = []
|
||||||
|
for face in mesh.faces:
|
||||||
|
for vertex_index in face:
|
||||||
|
# Get the vertex position
|
||||||
|
position = mesh.vertices[vertex_index]
|
||||||
|
# Get the vertex normal
|
||||||
|
normal = mesh.vertex_normals[vertex_index]
|
||||||
|
# Add position and normal to the vertex array
|
||||||
|
vertices.extend([*position, *normal])
|
||||||
|
|
||||||
|
return vertices
|
||||||
|
|
||||||
|
# Save the vertex array to a formatted string
|
||||||
|
def save_vertex_array_to_file(vertices, output_file):
|
||||||
|
with open(output_file, 'w') as f:
|
||||||
|
f.write("GLfloat vertices[] = {\n")
|
||||||
|
for i, value in enumerate(vertices):
|
||||||
|
f.write(f" {value:.4f}f,")
|
||||||
|
if (i + 1) % 6 == 0: # Add a newline after every vertex (6 values: 3 position + 3 normal)
|
||||||
|
f.write("\n")
|
||||||
|
f.write("};\n")
|
||||||
|
|
||||||
|
# Example usage
|
||||||
|
model_path = "./model.obj" # Replace with the path to your model
|
||||||
|
output_path = "output_vertex_array.txt"
|
||||||
|
|
||||||
|
vertices = generate_vertex_array_from_model(model_path)
|
||||||
|
save_vertex_array_to_file(vertices, output_path)
|
||||||
|
|
||||||
|
print(f"Vertex array saved to {output_path}")
|
7
shaders/cam_frag.glsl
Normal file
7
shaders/cam_frag.glsl
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#version 330 core
|
||||||
|
in vec3 fragColor;
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = vec4(fragColor, 1.0);
|
||||||
|
}
|
16
shaders/cam_vertex.glsl
Normal file
16
shaders/cam_vertex.glsl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout(location = 0) in vec3 position;
|
||||||
|
|
||||||
|
uniform vec3 lineStart;
|
||||||
|
uniform vec3 lineEnd;
|
||||||
|
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
out vec3 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec3 worldPos = mix(lineStart, lineEnd, float(gl_VertexID));
|
||||||
|
gl_Position = projection * view * vec4(worldPos, 1.0);
|
||||||
|
fragColor = vec3(0.0, 1.0, 1.0); // Set line color
|
||||||
|
}
|
163
shaders/fragment_shader.glsl
Normal file
163
shaders/fragment_shader.glsl
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
// Point Lights
|
||||||
|
struct PointLight {
|
||||||
|
vec3 position;
|
||||||
|
vec3 color;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_POINT_LIGHTS 256
|
||||||
|
uniform int numPointLights;
|
||||||
|
uniform PointLight pointLights[MAX_POINT_LIGHTS];
|
||||||
|
|
||||||
|
// Directional Lights
|
||||||
|
struct DirLight {
|
||||||
|
vec3 direction;
|
||||||
|
vec3 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_DIR_LIGHTS 10
|
||||||
|
uniform int numDirLights;
|
||||||
|
uniform DirLight dirLights[MAX_DIR_LIGHTS];
|
||||||
|
|
||||||
|
// Spotlights
|
||||||
|
struct SpotLight {
|
||||||
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
vec3 color;
|
||||||
|
|
||||||
|
float cutOff; // Cosine of the inner cutoff angle
|
||||||
|
float outerCutOff; // Cosine of the outer cutoff angle
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_SPOT_LIGHTS 64
|
||||||
|
uniform int numSpotLights;
|
||||||
|
uniform SpotLight spotLights[MAX_SPOT_LIGHTS];
|
||||||
|
|
||||||
|
uniform vec3 objectColor; // Fallback color
|
||||||
|
uniform sampler2D texture1; // Texture sampler
|
||||||
|
uniform bool useTexture; // Flag to determine if a texture is used
|
||||||
|
|
||||||
|
in vec2 TexCoords;
|
||||||
|
|
||||||
|
// Function to calculate lighting for a Point Light
|
||||||
|
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 viewDir, vec3 fragPos)
|
||||||
|
{
|
||||||
|
// Ambient
|
||||||
|
float ambientStrength = 0.1;
|
||||||
|
vec3 ambient = ambientStrength * light.color;
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
vec3 lightDir = normalize(light.position - fragPos);
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
vec3 diffuse = diff * light.color;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
float specularStrength = 0.5;
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
|
vec3 specular = specularStrength * spec * light.color;
|
||||||
|
|
||||||
|
// Attenuation
|
||||||
|
float distance = length(light.position - fragPos);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance +
|
||||||
|
light.quadratic * (distance * distance));
|
||||||
|
|
||||||
|
return (ambient + diffuse + specular) * attenuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to calculate lighting for a Directional Light
|
||||||
|
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
|
||||||
|
{
|
||||||
|
// Ambient
|
||||||
|
float ambientStrength = 0.1;
|
||||||
|
vec3 ambient = ambientStrength * light.color;
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
vec3 lightDir = normalize(-light.direction); // Directional light direction
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
vec3 diffuse = diff * light.color;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
float specularStrength = 0.5;
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
|
vec3 specular = specularStrength * spec * light.color;
|
||||||
|
|
||||||
|
return (ambient + diffuse + specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to calculate lighting for a Spotlight
|
||||||
|
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 viewDir, vec3 fragPos)
|
||||||
|
{
|
||||||
|
// Ambient
|
||||||
|
float ambientStrength = 0.1;
|
||||||
|
vec3 ambient = ambientStrength * light.color;
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
vec3 lightDir = normalize(light.position - fragPos);
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
vec3 diffuse = diff * light.color;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
float specularStrength = 0.5;
|
||||||
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
|
vec3 specular = specularStrength * spec * light.color;
|
||||||
|
|
||||||
|
// Attenuation
|
||||||
|
float distance = length(light.position - fragPos);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance +
|
||||||
|
light.quadratic * (distance * distance));
|
||||||
|
|
||||||
|
// Spotlight intensity
|
||||||
|
vec3 spotDir = normalize(light.direction);
|
||||||
|
float theta = dot(lightDir, spotDir);
|
||||||
|
float epsilon = light.cutOff - light.outerCutOff;
|
||||||
|
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);
|
||||||
|
|
||||||
|
return (ambient + diffuse + specular) * attenuation * intensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 norm = normalize(Normal);
|
||||||
|
vec3 viewDir = normalize(viewPos - FragPos);
|
||||||
|
vec3 result = vec3(0.0);
|
||||||
|
|
||||||
|
// Calculate Point Lights
|
||||||
|
for (int i = 0; i < numPointLights; ++i)
|
||||||
|
{
|
||||||
|
result += CalcPointLight(pointLights[i], norm, viewDir, FragPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate Directional Lights
|
||||||
|
for (int i = 0; i < numDirLights; ++i)
|
||||||
|
{
|
||||||
|
result += CalcDirLight(dirLights[i], norm, viewDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate Spotlights
|
||||||
|
for (int i = 0; i < numSpotLights; ++i)
|
||||||
|
{
|
||||||
|
result += CalcSpotLight(spotLights[i], norm, viewDir, FragPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine lighting with object color or texture
|
||||||
|
vec3 baseColor = useTexture ? texture(texture1, TexCoords).rgb : objectColor;
|
||||||
|
color = vec4(result * baseColor, 1.0);
|
||||||
|
}
|
9
shaders/gizmo_fragment_shader.glsl
Normal file
9
shaders/gizmo_fragment_shader.glsl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
uniform vec3 gizmoColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
color = vec4(gizmoColor, 1.0);
|
||||||
|
}
|
11
shaders/gizmo_vertex_shader.glsl
Normal file
11
shaders/gizmo_vertex_shader.glsl
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout(location = 0) in vec3 position;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = projection * view * model * vec4(position, 1.0);
|
||||||
|
}
|
20
shaders/vertex_shader.glsl
Normal file
20
shaders/vertex_shader.glsl
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout(location = 0) in vec3 position;
|
||||||
|
layout(location = 1) in vec3 normal;
|
||||||
|
layout(location = 2) in vec2 texCoords;
|
||||||
|
|
||||||
|
out vec3 FragPos;
|
||||||
|
out vec3 Normal;
|
||||||
|
out vec2 TexCoords;
|
||||||
|
|
||||||
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
TexCoords = texCoords; // Pass texture coordinates to fragment shader
|
||||||
|
FragPos = vec3(model * vec4(position, 1.0));
|
||||||
|
Normal = mat3(transpose(inverse(model))) * normal;
|
||||||
|
gl_Position = projection * view * vec4(FragPos, 1.0);
|
||||||
|
}
|
109
src/CameraComponent.h
Normal file
109
src/CameraComponent.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
// CameraComponent.h
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include "Component.h"
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
// Enumeration for Projection Types (Optional)
|
||||||
|
enum class ProjectionType {
|
||||||
|
Perspective = 0,
|
||||||
|
Orthographic = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CameraComponent : public Component {
|
||||||
|
// Camera Attributes
|
||||||
|
float zoom; // Applicable for Orthographic Projection
|
||||||
|
float fov; // Field of View in degrees for Perspective Projection
|
||||||
|
bool orthographic; // Toggle between Orthographic and Perspective
|
||||||
|
float nearPlane;
|
||||||
|
float farPlane;
|
||||||
|
|
||||||
|
// Constructor with default values
|
||||||
|
CameraComponent()
|
||||||
|
: zoom(10.0f),
|
||||||
|
fov(45.0f),
|
||||||
|
orthographic(false),
|
||||||
|
nearPlane(0.1f),
|
||||||
|
farPlane(1000.0f)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// Override to provide the component's name
|
||||||
|
virtual const std::string& GetName() const override {
|
||||||
|
static std::string name = "Camera";
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static method to retrieve the component's name
|
||||||
|
static std::string GetStaticName() {
|
||||||
|
return "Camera";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Computes the view matrix based on position and rotation from TransformComponent
|
||||||
|
glm::mat4 GetViewMatrix(const glm::vec3& position, float rotation) const {
|
||||||
|
glm::mat4 view = glm::mat4(1.0f);
|
||||||
|
// Apply translation and rotation inversely to simulate camera movement
|
||||||
|
view = glm::translate(view, -position);
|
||||||
|
view = glm::rotate(view, glm::radians(-rotation), glm::vec3(0, 0, 1));
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Computes the projection matrix based on the current projection type and aspect ratio
|
||||||
|
glm::mat4 GetProjectionMatrix(float aspectRatio) const {
|
||||||
|
if (orthographic) {
|
||||||
|
float halfWidth = zoom / 2.0f;
|
||||||
|
float halfHeight = halfWidth / aspectRatio;
|
||||||
|
return glm::ortho(-halfWidth, halfWidth, -halfHeight, halfHeight, nearPlane, farPlane);
|
||||||
|
} else {
|
||||||
|
return glm::perspective(glm::radians(fov), aspectRatio, nearPlane, farPlane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialization Method
|
||||||
|
virtual YAML::Node Serialize() override {
|
||||||
|
YAML::Node node;
|
||||||
|
|
||||||
|
// Zoom
|
||||||
|
node["Zoom"] = zoom;
|
||||||
|
|
||||||
|
// Field of View
|
||||||
|
node["FOV"] = fov;
|
||||||
|
|
||||||
|
// Orthographic Projection Toggle
|
||||||
|
node["Orthographic"] = orthographic;
|
||||||
|
|
||||||
|
// Near Plane
|
||||||
|
node["NearPlane"] = nearPlane;
|
||||||
|
|
||||||
|
// Far Plane
|
||||||
|
node["FarPlane"] = farPlane;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialization Method
|
||||||
|
virtual void Deserialize(const YAML::Node& node) override {
|
||||||
|
if (node["Zoom"]) {
|
||||||
|
zoom = node["Zoom"].as<float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node["FOV"]) {
|
||||||
|
fov = node["FOV"].as<float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node["Orthographic"]) {
|
||||||
|
orthographic = node["Orthographic"].as<bool>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node["NearPlane"]) {
|
||||||
|
nearPlane = node["NearPlane"].as<float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node["FarPlane"]) {
|
||||||
|
farPlane = node["FarPlane"].as<float>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
223
src/CollisionShape3DComponent.cpp
Normal file
223
src/CollisionShape3DComponent.cpp
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
// CollisionShape3DComponent.cpp
|
||||||
|
#include "CollisionShape3DComponent.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// Define the static name
|
||||||
|
const std::string CollisionShape3DComponent::name = "CollisionShape";
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Constructors
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// Default Constructor
|
||||||
|
CollisionShape3DComponent::CollisionShape3DComponent()
|
||||||
|
: shapeType(CollisionShapeType::Box),
|
||||||
|
size(1.0f, 1.0f, 1.0f),
|
||||||
|
radius(1.0f),
|
||||||
|
direction(0.0f, 1.0f, 0.0f),
|
||||||
|
height(2.0f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parameterized Constructor
|
||||||
|
CollisionShape3DComponent::CollisionShape3DComponent(CollisionShapeType type, const glm::vec3& sz, float rad, const glm::vec3& dir, float ht)
|
||||||
|
: shapeType(type),
|
||||||
|
size(sz),
|
||||||
|
radius(rad),
|
||||||
|
direction(dir),
|
||||||
|
height(ht)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// GetName Methods
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// Returns the name of the component
|
||||||
|
const std::string& CollisionShape3DComponent::GetName() const
|
||||||
|
{
|
||||||
|
return GetStaticName();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the static name of the component
|
||||||
|
const std::string& CollisionShape3DComponent::GetStaticName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Serialization Methods
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// Serialize the component to YAML
|
||||||
|
YAML::Node CollisionShape3DComponent::Serialize()
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
node["ShapeType"] = static_cast<int>(shapeType);
|
||||||
|
|
||||||
|
switch (shapeType)
|
||||||
|
{
|
||||||
|
case CollisionShapeType::Box:
|
||||||
|
{
|
||||||
|
YAML::Node SizeNode;
|
||||||
|
SizeNode.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
SizeNode.push_back(size.x);
|
||||||
|
SizeNode.push_back(size.y);
|
||||||
|
SizeNode.push_back(size.z);
|
||||||
|
node["Size"] = SizeNode;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CollisionShapeType::Sphere:
|
||||||
|
node["Radius"] = radius;
|
||||||
|
break;
|
||||||
|
case CollisionShapeType::Capsule:
|
||||||
|
{
|
||||||
|
YAML::Node DirNode;
|
||||||
|
DirNode.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
DirNode.push_back(direction.x);
|
||||||
|
DirNode.push_back(direction.y);
|
||||||
|
DirNode.push_back(direction.z);
|
||||||
|
node["Direction"] = DirNode;
|
||||||
|
node["Height"] = height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
std::cerr << "Warning: Unknown CollisionShapeType during serialization.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialize the component from YAML
|
||||||
|
void CollisionShape3DComponent::Deserialize(const YAML::Node& node)
|
||||||
|
{
|
||||||
|
// Deserialize ShapeType
|
||||||
|
if (node["ShapeType"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int typeInt = node["ShapeType"].as<int>();
|
||||||
|
if (typeInt >= 0 && typeInt <= 2) // Assuming enum values 0,1,2
|
||||||
|
{
|
||||||
|
shapeType = static_cast<CollisionShapeType>(typeInt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'ShapeType' has an invalid value (" << typeInt << "). Using default (Box).\n";
|
||||||
|
shapeType = CollisionShapeType::Box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'ShapeType': " << e.what() << "\nUsing default (Box).\n";
|
||||||
|
shapeType = CollisionShapeType::Box;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'ShapeType' node not found. Using default (Box).\n";
|
||||||
|
shapeType = CollisionShapeType::Box;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialize based on ShapeType
|
||||||
|
switch (shapeType)
|
||||||
|
{
|
||||||
|
case CollisionShapeType::Box:
|
||||||
|
{
|
||||||
|
if (node["Size"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto sz = node["Size"].as<std::vector<float>>();
|
||||||
|
if (sz.size() == 3)
|
||||||
|
size = glm::vec3(sz[0], sz[1], sz[2]);
|
||||||
|
else
|
||||||
|
std::cerr << "Warning: 'Size' does not have exactly 3 elements. Using default size.\n";
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Size': " << e.what() << "\nUsing default size.\n";
|
||||||
|
size = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Size' node not found for Box. Using default size.\n";
|
||||||
|
size = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CollisionShapeType::Sphere:
|
||||||
|
if (node["Radius"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
radius = node["Radius"].as<float>();
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Radius': " << e.what() << "\nUsing default radius.\n";
|
||||||
|
radius = 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Radius' node not found for Sphere. Using default radius.\n";
|
||||||
|
radius = 1.0f;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CollisionShapeType::Capsule:
|
||||||
|
{
|
||||||
|
if (node["Direction"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto dir = node["Direction"].as<std::vector<float>>();
|
||||||
|
if (dir.size() == 3)
|
||||||
|
direction = glm::vec3(dir[0], dir[1], dir[2]);
|
||||||
|
else
|
||||||
|
std::cerr << "Warning: 'Direction' does not have exactly 3 elements. Using default direction.\n";
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Direction': " << e.what() << "\nUsing default direction.\n";
|
||||||
|
direction = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Direction' node not found for Capsule. Using default direction.\n";
|
||||||
|
direction = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node["Height"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
height = node["Height"].as<float>();
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Height': " << e.what() << "\nUsing default height.\n";
|
||||||
|
height = 2.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Height' node not found for Capsule. Using default height.\n";
|
||||||
|
height = 2.0f;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add deserialization for additional shapes here
|
||||||
|
|
||||||
|
default:
|
||||||
|
std::cerr << "Warning: Unknown CollisionShapeType during deserialization.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
44
src/CollisionShape3DComponent.h
Normal file
44
src/CollisionShape3DComponent.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// CollisionShape3DComponent.h
|
||||||
|
#ifndef COLLISIONSHAPE3DCOMPONENT_H
|
||||||
|
#define COLLISIONSHAPE3DCOMPONENT_H
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Enum for different collision shapes
|
||||||
|
enum class CollisionShapeType {
|
||||||
|
Box,
|
||||||
|
Sphere,
|
||||||
|
Capsule,
|
||||||
|
// Add more shapes as needed
|
||||||
|
};
|
||||||
|
|
||||||
|
class CollisionShape3DComponent : public Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Collision Shape Properties
|
||||||
|
CollisionShapeType shapeType;
|
||||||
|
glm::vec3 size; // For Box: width, height, depth
|
||||||
|
float radius; // For Sphere: radius
|
||||||
|
glm::vec3 direction; // For Capsule: direction vector
|
||||||
|
float height; // For Capsule: height
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
CollisionShape3DComponent();
|
||||||
|
CollisionShape3DComponent(CollisionShapeType type, const glm::vec3& sz = glm::vec3(1.0f), float rad = 1.0f, const glm::vec3& dir = glm::vec3(0.0f, 1.0f, 0.0f), float ht = 2.0f);
|
||||||
|
|
||||||
|
// Override Component methods
|
||||||
|
virtual const std::string& GetName() const override;
|
||||||
|
static const std::string& GetStaticName();
|
||||||
|
|
||||||
|
// Serialization methods
|
||||||
|
virtual YAML::Node Serialize() override;
|
||||||
|
virtual void Deserialize(const YAML::Node& node) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COLLISIONSHAPE3DCOMPONENT_H
|
19
src/Component.h
Normal file
19
src/Component.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Component.h
|
||||||
|
#ifndef COMPONENT_H
|
||||||
|
#define COMPONENT_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
class Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~Component() {}
|
||||||
|
virtual const std::string& GetName() const = 0;
|
||||||
|
|
||||||
|
// Serialization methods
|
||||||
|
virtual YAML::Node Serialize() = 0;
|
||||||
|
virtual void Deserialize(const YAML::Node& node) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COMPONENT_H
|
107
src/EditorCamera.cpp
Normal file
107
src/EditorCamera.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
// EditorCamera.cpp
|
||||||
|
|
||||||
|
#include "EditorCamera.h"
|
||||||
|
#include <glm/gtx/rotate_vector.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
EditorCamera::EditorCamera(glm::vec3 target, float distance, float yaw, float pitch)
|
||||||
|
: target(target), distance(distance), yaw(yaw), pitch(pitch), positionDirty(true)
|
||||||
|
{
|
||||||
|
// Initialize the camera position based on the initial yaw, pitch, and distance
|
||||||
|
UpdateCameraPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorCamera::ProcessMouseMovement(float deltaX, float deltaY)
|
||||||
|
{
|
||||||
|
float sensitivity = 0.1f; // Adjust sensitivity as needed
|
||||||
|
yaw += deltaX * sensitivity;
|
||||||
|
pitch += deltaY * sensitivity;
|
||||||
|
|
||||||
|
// Clamp the pitch to prevent flipping
|
||||||
|
if (pitch > maxPitch)
|
||||||
|
pitch = maxPitch;
|
||||||
|
if (pitch < minPitch)
|
||||||
|
pitch = minPitch;
|
||||||
|
|
||||||
|
positionDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorCamera::ProcessMouseScroll(float deltaScroll)
|
||||||
|
{
|
||||||
|
float zoomSensitivity = 1.0f; // Adjust zoom sensitivity as needed
|
||||||
|
distance -= deltaScroll * zoomSensitivity;
|
||||||
|
|
||||||
|
// Clamp the distance to prevent the camera from getting too close or too far
|
||||||
|
if (distance < minDistance)
|
||||||
|
distance = minDistance;
|
||||||
|
if (distance > maxDistance)
|
||||||
|
distance = maxDistance;
|
||||||
|
|
||||||
|
positionDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 EditorCamera::GetViewMatrix() const
|
||||||
|
{
|
||||||
|
if (positionDirty)
|
||||||
|
const_cast<EditorCamera *>(this)->UpdateCameraPosition();
|
||||||
|
|
||||||
|
return glm::lookAt(position, target, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 EditorCamera::GetProjectionMatrix(float aspectRatio) const
|
||||||
|
{
|
||||||
|
return glm::perspective(glm::radians(45.0f), aspectRatio, 0.1f, 100.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 EditorCamera::GetPosition() const
|
||||||
|
{
|
||||||
|
if (positionDirty)
|
||||||
|
const_cast<EditorCamera *>(this)->UpdateCameraPosition();
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorCamera::SetTarget(const glm::vec3 &newTarget)
|
||||||
|
{
|
||||||
|
target = newTarget;
|
||||||
|
positionDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 EditorCamera::GetTarget() const
|
||||||
|
{
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorCamera::UpdateCameraPosition()
|
||||||
|
{
|
||||||
|
// Convert angles from degrees to radians
|
||||||
|
float yawRad = glm::radians(yaw);
|
||||||
|
float pitchRad = glm::radians(pitch);
|
||||||
|
|
||||||
|
// Calculate the camera's position in spherical coordinates
|
||||||
|
float x = distance * cos(pitchRad) * sin(yawRad);
|
||||||
|
float y = distance * sin(pitchRad);
|
||||||
|
float z = distance * cos(pitchRad) * cos(yawRad);
|
||||||
|
|
||||||
|
// Update the camera's position relative to the target
|
||||||
|
position = target + glm::vec3(x, y, z);
|
||||||
|
positionDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorCamera::SetYaw(float newYaw)
|
||||||
|
{
|
||||||
|
yaw = newYaw;
|
||||||
|
positionDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorCamera::SetPitch(float newPitch)
|
||||||
|
{
|
||||||
|
// Clamp the pitch to prevent flipping
|
||||||
|
if (newPitch > maxPitch)
|
||||||
|
pitch = maxPitch;
|
||||||
|
else if (newPitch < minPitch)
|
||||||
|
pitch = minPitch;
|
||||||
|
else
|
||||||
|
pitch = newPitch;
|
||||||
|
|
||||||
|
positionDirty = true;
|
||||||
|
}
|
62
src/EditorCamera.h
Normal file
62
src/EditorCamera.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// EditorCamera.h
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
class EditorCamera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EditorCamera(
|
||||||
|
glm::vec3 target = glm::vec3(0.0f),
|
||||||
|
float distance = 10.0f,
|
||||||
|
float yaw = 45.0f, // Horizontal angle in degrees
|
||||||
|
float pitch = 30.0f // Vertical angle in degrees
|
||||||
|
);
|
||||||
|
|
||||||
|
// Processes input received from a mouse input system. Expects the offset value in both the x and y direction.
|
||||||
|
void ProcessMouseMovement(float deltaX, float deltaY);
|
||||||
|
|
||||||
|
// Processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
|
||||||
|
void ProcessMouseScroll(float deltaScroll);
|
||||||
|
|
||||||
|
// Returns the view matrix calculated using Euler Angles and the LookAt Matrix
|
||||||
|
glm::mat4 GetViewMatrix() const;
|
||||||
|
|
||||||
|
// Returns the projection matrix
|
||||||
|
glm::mat4 GetProjectionMatrix(float aspectRatio) const;
|
||||||
|
|
||||||
|
// Returns the current position of the camera
|
||||||
|
glm::vec3 GetPosition() const;
|
||||||
|
|
||||||
|
// Sets a new target for the camera to orbit around
|
||||||
|
void SetTarget(const glm::vec3& newTarget);
|
||||||
|
|
||||||
|
// Gets the current target
|
||||||
|
glm::vec3 GetTarget() const;
|
||||||
|
|
||||||
|
void SetYaw(float newYaw);
|
||||||
|
void SetPitch(float newPitch);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Updates the camera's position based on spherical coordinates
|
||||||
|
void UpdateCameraPosition();
|
||||||
|
|
||||||
|
// Camera Attributes
|
||||||
|
glm::vec3 target; // The point the camera is looking at
|
||||||
|
float distance; // Distance from the target
|
||||||
|
float yaw; // Horizontal angle in degrees
|
||||||
|
float pitch; // Vertical angle in degrees
|
||||||
|
|
||||||
|
// Constraints
|
||||||
|
const float minPitch = -89.0f;
|
||||||
|
const float maxPitch = 89.0f;
|
||||||
|
const float minDistance = 1.0f;
|
||||||
|
const float maxDistance = 100.0f;
|
||||||
|
|
||||||
|
// Cached camera position and flag to check if it needs updating
|
||||||
|
mutable glm::vec3 position;
|
||||||
|
mutable bool positionDirty;
|
||||||
|
};
|
100
src/Entity.cpp
Normal file
100
src/Entity.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
// Entity.cpp
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "TransformComponent.h"
|
||||||
|
#include "RenderComponent.h"
|
||||||
|
#include "LightComponent.h"
|
||||||
|
#include "RigidBody3DComponent.h"
|
||||||
|
#include "CollisionShape3DComponent.h"
|
||||||
|
#include "CameraComponent.h"
|
||||||
|
|
||||||
|
Entity::Entity(int id, const std::string& name)
|
||||||
|
: id(id), name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Entity::AddComponent(const std::shared_ptr<Component>& component)
|
||||||
|
{
|
||||||
|
components[component->GetName()] = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
YAML::Node Entity::Serialize()
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
node["ID"] = id;
|
||||||
|
node["Name"] = name;
|
||||||
|
|
||||||
|
YAML::Node componentsNode;
|
||||||
|
for (const auto& compPair : components)
|
||||||
|
{
|
||||||
|
const std::string& compName = compPair.first;
|
||||||
|
std::shared_ptr<Component> component = compPair.second;
|
||||||
|
componentsNode[compName] = component->Serialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
node["Components"] = componentsNode;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entity::Deserialize(const YAML::Node& node)
|
||||||
|
{
|
||||||
|
if (node["ID"])
|
||||||
|
{
|
||||||
|
id = node["ID"].as<int>();
|
||||||
|
}
|
||||||
|
if (node["Name"])
|
||||||
|
{
|
||||||
|
name = node["Name"].as<std::string>();
|
||||||
|
}
|
||||||
|
if (node["Components"])
|
||||||
|
{
|
||||||
|
YAML::Node componentsNode = node["Components"];
|
||||||
|
for (auto it = componentsNode.begin(); it != componentsNode.end(); ++it)
|
||||||
|
{
|
||||||
|
std::string compName = it->first.as<std::string>();
|
||||||
|
YAML::Node compNode = it->second;
|
||||||
|
|
||||||
|
if (compName == TransformComponent::GetStaticName())
|
||||||
|
{
|
||||||
|
auto transform = std::make_shared<TransformComponent>();
|
||||||
|
transform->Deserialize(compNode);
|
||||||
|
AddComponent(transform);
|
||||||
|
}
|
||||||
|
else if (compName == RenderComponent::GetStaticName())
|
||||||
|
{
|
||||||
|
auto render = std::make_shared<RenderComponent>();
|
||||||
|
render->Deserialize(compNode);
|
||||||
|
AddComponent(render);
|
||||||
|
}
|
||||||
|
else if (compName == LightComponent::GetStaticName())
|
||||||
|
{
|
||||||
|
auto lightComponent = std::make_shared<LightComponent>();
|
||||||
|
lightComponent->Deserialize(compNode);
|
||||||
|
AddComponent(lightComponent);
|
||||||
|
}
|
||||||
|
else if (compName == RigidBody3DComponent::GetStaticName())
|
||||||
|
{
|
||||||
|
auto ridgid = std::make_shared<RigidBody3DComponent>();
|
||||||
|
ridgid->Deserialize(compNode);
|
||||||
|
AddComponent(ridgid);
|
||||||
|
}
|
||||||
|
else if (compName == CollisionShape3DComponent::GetStaticName())
|
||||||
|
{
|
||||||
|
auto collis = std::make_shared<CollisionShape3DComponent>();
|
||||||
|
collis->Deserialize(compNode);
|
||||||
|
AddComponent(collis);
|
||||||
|
}
|
||||||
|
else if (compName == CameraComponent::GetStaticName())
|
||||||
|
{
|
||||||
|
auto cammera = std::make_shared<CameraComponent>();
|
||||||
|
cammera->Deserialize(compNode);
|
||||||
|
AddComponent(cammera);
|
||||||
|
} else {
|
||||||
|
std::cout << "[Poly] [De/Serialize] [ERROR] Invalid Component Type '"<< compName <<"' Skipping" << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
// Add deserialization for other components as needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
src/Entity.h
Normal file
39
src/Entity.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Entity.h
|
||||||
|
#ifndef ENTITY_H
|
||||||
|
#define ENTITY_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <memory>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
class Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int id;
|
||||||
|
std::string name;
|
||||||
|
std::unordered_map<std::string, std::shared_ptr<Component>> components;
|
||||||
|
|
||||||
|
Entity(int id, const std::string& name);
|
||||||
|
|
||||||
|
void AddComponent(const std::shared_ptr<Component>& component);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::shared_ptr<T> GetComponent()
|
||||||
|
{
|
||||||
|
auto it = components.find(T::GetStaticName());
|
||||||
|
if (it != components.end())
|
||||||
|
{
|
||||||
|
return std::dynamic_pointer_cast<T>(it->second);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialization methods
|
||||||
|
YAML::Node Serialize();
|
||||||
|
void Deserialize(const YAML::Node& node);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ENTITY_H
|
93
src/ImGuiStyle.cpp
Normal file
93
src/ImGuiStyle.cpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#include "ImGuiStyle.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
void SetupImGuiStyle()
|
||||||
|
{
|
||||||
|
// Windark style by DestroyerDarkNess from ImThemes
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
|
||||||
|
style.Alpha = 1.0f;
|
||||||
|
style.DisabledAlpha = 0.6000000238418579f;
|
||||||
|
style.WindowPadding = ImVec2(8.0f, 8.0f);
|
||||||
|
style.WindowRounding = 8.399999618530273f;
|
||||||
|
style.WindowBorderSize = 1.0f;
|
||||||
|
style.WindowMinSize = ImVec2(32.0f, 32.0f);
|
||||||
|
style.WindowTitleAlign = ImVec2(0.0f, 0.5f);
|
||||||
|
style.WindowMenuButtonPosition = ImGuiDir_Right;
|
||||||
|
style.ChildRounding = 3.0f;
|
||||||
|
style.ChildBorderSize = 1.0f;
|
||||||
|
style.PopupRounding = 3.0f;
|
||||||
|
style.PopupBorderSize = 1.0f;
|
||||||
|
style.FramePadding = ImVec2(4.0f, 3.0f);
|
||||||
|
style.FrameRounding = 3.0f;
|
||||||
|
style.FrameBorderSize = 1.0f;
|
||||||
|
style.ItemSpacing = ImVec2(8.0f, 4.0f);
|
||||||
|
style.ItemInnerSpacing = ImVec2(4.0f, 4.0f);
|
||||||
|
style.CellPadding = ImVec2(4.0f, 2.0f);
|
||||||
|
style.IndentSpacing = 21.0f;
|
||||||
|
style.ColumnsMinSpacing = 6.0f;
|
||||||
|
style.ScrollbarSize = 5.599999904632568f;
|
||||||
|
style.ScrollbarRounding = 18.0f;
|
||||||
|
style.GrabMinSize = 10.0f;
|
||||||
|
style.GrabRounding = 3.0f;
|
||||||
|
style.TabRounding = 3.0f;
|
||||||
|
style.TabBorderSize = 0.0f;
|
||||||
|
style.TabMinWidthForCloseButton = 0.0f;
|
||||||
|
style.ColorButtonPosition = ImGuiDir_Right;
|
||||||
|
style.ButtonTextAlign = ImVec2(0.5f, 0.5f);
|
||||||
|
style.SelectableTextAlign = ImVec2(0.0f, 0.0f);
|
||||||
|
|
||||||
|
style.Colors[ImGuiCol_Text] = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.6000000238418579f, 0.6000000238418579f, 0.6000000238418579f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.125490203499794f, 0.125490203499794f, 0.125490203499794f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ChildBg] = ImVec4(0.125490203499794f, 0.125490203499794f, 0.125490203499794f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.168627455830574f, 0.168627455830574f, 0.168627455830574f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_Border] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.168627455830574f, 0.168627455830574f, 0.168627455830574f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.2156862765550613f, 0.2156862765550613f, 0.2156862765550613f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.125490203499794f, 0.125490203499794f, 0.125490203499794f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.168627455830574f, 0.168627455830574f, 0.168627455830574f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.125490203499794f, 0.125490203499794f, 0.125490203499794f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.168627455830574f, 0.168627455830574f, 0.168627455830574f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.125490203499794f, 0.125490203499794f, 0.125490203499794f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.3019607961177826f, 0.3019607961177826f, 0.3019607961177826f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.3490196168422699f, 0.3490196168422699f, 0.3490196168422699f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.0f, 0.4705882370471954f, 0.843137264251709f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.0f, 0.4705882370471954f, 0.843137264251709f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.0f, 0.3294117748737335f, 0.6000000238418579f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_Button] = ImVec4(0.168627455830574f, 0.168627455830574f, 0.168627455830574f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.2156862765550613f, 0.2156862765550613f, 0.2156862765550613f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_Header] = ImVec4(0.2156862765550613f, 0.2156862765550613f, 0.2156862765550613f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.3019607961177826f, 0.3019607961177826f, 0.3019607961177826f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_Separator] = ImVec4(0.2156862765550613f, 0.2156862765550613f, 0.2156862765550613f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.3019607961177826f, 0.3019607961177826f, 0.3019607961177826f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.2156862765550613f, 0.2156862765550613f, 0.2156862765550613f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.3019607961177826f, 0.3019607961177826f, 0.3019607961177826f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_Tab] = ImVec4(0.168627455830574f, 0.168627455830574f, 0.168627455830574f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TabHovered] = ImVec4(0.2156862765550613f, 0.2156862765550613f, 0.2156862765550613f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TabActive] = ImVec4(0.250980406999588f, 0.250980406999588f, 0.250980406999588f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.168627455830574f, 0.168627455830574f, 0.168627455830574f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.2156862765550613f, 0.2156862765550613f, 0.2156862765550613f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_PlotLines] = ImVec4(0.0f, 0.4705882370471954f, 0.843137264251709f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.0f, 0.3294117748737335f, 0.6000000238418579f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.0f, 0.4705882370471954f, 0.843137264251709f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.0f, 0.3294117748737335f, 0.6000000238418579f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.1882352977991104f, 0.1882352977991104f, 0.2000000029802322f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.3098039329051971f, 0.3098039329051971f, 0.3490196168422699f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.2274509817361832f, 0.2274509817361832f, 0.2470588237047195f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0f, 1.0f, 1.0f, 0.05999999865889549f);
|
||||||
|
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.0f, 0.4705882370471954f, 0.843137264251709f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.0f, 1.0f, 0.0f, 0.8999999761581421f);
|
||||||
|
style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.2588235437870026f, 0.5882353186607361f, 0.9764705896377563f, 1.0f);
|
||||||
|
style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0f, 1.0f, 1.0f, 0.699999988079071f);
|
||||||
|
style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.800000011920929f, 0.800000011920929f, 0.800000011920929f, 0.2000000029802322f);
|
||||||
|
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.800000011920929f, 0.800000011920929f, 0.800000011920929f, 0.3499999940395355f);
|
||||||
|
}
|
9
src/ImGuiStyle.h
Normal file
9
src/ImGuiStyle.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// ImGuiStyle.h
|
||||||
|
|
||||||
|
#ifndef IMGUISTYLE_H
|
||||||
|
#define IMGUISTYLE_H
|
||||||
|
|
||||||
|
void SetupImGuiStyle();
|
||||||
|
|
||||||
|
|
||||||
|
#endif // IMGUISTYLE_H
|
106
src/LightComponent.cpp
Normal file
106
src/LightComponent.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// LightComponent.cpp
|
||||||
|
#include "LightComponent.h"
|
||||||
|
|
||||||
|
const std::string LightComponent::name = "Light";
|
||||||
|
|
||||||
|
LightComponent::LightComponent()
|
||||||
|
: type(LightType::Point),
|
||||||
|
color(1.0f, 1.0f, 1.0f), // Default color
|
||||||
|
direction(-0.2f, -1.0f, -0.3f), // Default direction
|
||||||
|
intensity(1.0f),
|
||||||
|
constant(1.0f),
|
||||||
|
linear(0.09f),
|
||||||
|
quadratic(0.032f),
|
||||||
|
cutOff(12.5f), // Reasonable default for spotlight
|
||||||
|
outerCutOff(17.5f) // Slightly larger than cutOff for smooth transition
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &LightComponent::GetName() const
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &LightComponent::GetStaticName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
YAML::Node LightComponent::Serialize()
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
node["Type"] = static_cast<int>(type);
|
||||||
|
node["Intensity"] = intensity;
|
||||||
|
|
||||||
|
// Serialize Color
|
||||||
|
YAML::Node colorNode;
|
||||||
|
colorNode.push_back(color.r);
|
||||||
|
colorNode.push_back(color.g);
|
||||||
|
colorNode.push_back(color.b);
|
||||||
|
colorNode.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
node["Color"] = colorNode;
|
||||||
|
|
||||||
|
// Serialize Attenuation
|
||||||
|
node["Constant"] = constant;
|
||||||
|
node["Linear"] = linear;
|
||||||
|
node["Quadratic"] = quadratic;
|
||||||
|
|
||||||
|
// Serialize Cutoff Angles
|
||||||
|
node["cutOff"] = cutOff;
|
||||||
|
node["outerCutOff"] = outerCutOff;
|
||||||
|
|
||||||
|
// Serialize Direction
|
||||||
|
YAML::Node directionNode;
|
||||||
|
directionNode.push_back(direction.x);
|
||||||
|
directionNode.push_back(direction.y);
|
||||||
|
directionNode.push_back(direction.z);
|
||||||
|
directionNode.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
node["Direction"] = directionNode;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LightComponent::Deserialize(const YAML::Node &node)
|
||||||
|
{
|
||||||
|
if (node["Type"])
|
||||||
|
{
|
||||||
|
type = static_cast<LightType>(node["Type"].as<int>());
|
||||||
|
}
|
||||||
|
if (node["Intensity"])
|
||||||
|
{
|
||||||
|
intensity = node["Intensity"].as<float>();
|
||||||
|
}
|
||||||
|
if (node["Color"])
|
||||||
|
{
|
||||||
|
auto clr = node["Color"].as<std::vector<float>>();
|
||||||
|
if (clr.size() == 3)
|
||||||
|
color = glm::vec3(clr[0], clr[1], clr[2]);
|
||||||
|
}
|
||||||
|
if (node["Constant"])
|
||||||
|
{
|
||||||
|
constant = node["Constant"].as<float>();
|
||||||
|
}
|
||||||
|
if (node["cutOff"])
|
||||||
|
{
|
||||||
|
cutOff = node["cutOff"].as<float>();
|
||||||
|
}
|
||||||
|
if (node["outerCutOff"])
|
||||||
|
{
|
||||||
|
outerCutOff = node["outerCutOff"].as<float>();
|
||||||
|
}
|
||||||
|
if (node["Linear"])
|
||||||
|
{
|
||||||
|
linear = node["Linear"].as<float>();
|
||||||
|
}
|
||||||
|
if (node["Quadratic"])
|
||||||
|
{
|
||||||
|
quadratic = node["Quadratic"].as<float>();
|
||||||
|
}
|
||||||
|
if (node["Direction"])
|
||||||
|
{
|
||||||
|
auto dir = node["Direction"].as<std::vector<float>>();
|
||||||
|
if (dir.size() == 3)
|
||||||
|
direction = glm::vec3(dir[0], dir[1], dir[2]);
|
||||||
|
}
|
||||||
|
}
|
48
src/LightComponent.h
Normal file
48
src/LightComponent.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// LightComponent.h
|
||||||
|
#ifndef LIGHT_COMPONENT_H
|
||||||
|
#define LIGHT_COMPONENT_H
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
enum class LightType
|
||||||
|
{
|
||||||
|
Point,
|
||||||
|
Directional,
|
||||||
|
Spot
|
||||||
|
};
|
||||||
|
|
||||||
|
class LightComponent : public Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LightType type;
|
||||||
|
glm::vec3 color;
|
||||||
|
float intensity;
|
||||||
|
|
||||||
|
// Point light properties
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
|
||||||
|
|
||||||
|
// Directional light properties
|
||||||
|
glm::vec3 direction;
|
||||||
|
// Cutoff angles (for Spot Lights, in radians)
|
||||||
|
float cutOff;
|
||||||
|
float outerCutOff;
|
||||||
|
|
||||||
|
LightComponent();
|
||||||
|
virtual const std::string& GetName() const override;
|
||||||
|
static const std::string& GetStaticName();
|
||||||
|
|
||||||
|
// Serialization methods
|
||||||
|
virtual YAML::Node Serialize() override;
|
||||||
|
virtual void Deserialize(const YAML::Node& node) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LIGHT_COMPONENT_H
|
81
src/LogSystem.cpp
Normal file
81
src/LogSystem.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// LogSystem.cpp
|
||||||
|
#include "LogSystem.h"
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
// Initialize global log buffer and mutex
|
||||||
|
std::vector<std::string> g_LogBuffer;
|
||||||
|
std::mutex g_LogMutex;
|
||||||
|
|
||||||
|
// Helper function to get current timestamp as string
|
||||||
|
std::string GetCurrentTimestamp() {
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto now_time_t = std::chrono::system_clock::to_time_t(now);
|
||||||
|
auto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
now.time_since_epoch()) %
|
||||||
|
1000;
|
||||||
|
|
||||||
|
std::tm tm_time;
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
localtime_s(&tm_time, &now_time_t);
|
||||||
|
#else
|
||||||
|
localtime_r(&now_time_t, &tm_time);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << std::put_time(&tm_time, "%H:%M:%S") << "."
|
||||||
|
<< std::setfill('0') << std::setw(3) << now_ms.count();
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to add a new log message with timestamp
|
||||||
|
void AddLogMessage(const std::string& message) {
|
||||||
|
std::lock_guard<std::mutex> lock(g_LogMutex);
|
||||||
|
|
||||||
|
// Create the log entry with timestamp
|
||||||
|
std::string logEntry = "[Poly] [" +GetCurrentTimestamp() + "] " + message;
|
||||||
|
g_LogBuffer.emplace_back(logEntry);
|
||||||
|
|
||||||
|
// Ensure the log buffer doesn't exceed the maximum size
|
||||||
|
if (g_LogBuffer.size() > MAX_LOG_MESSAGES) {
|
||||||
|
g_LogBuffer.erase(g_LogBuffer.begin(),
|
||||||
|
g_LogBuffer.begin() + (g_LogBuffer.size() - MAX_LOG_MESSAGES));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to draw the log terminal
|
||||||
|
void DrawLogTerminal(const char* title, bool* p_open) {
|
||||||
|
ImGui::Begin(title, p_open);
|
||||||
|
|
||||||
|
// Top Bar: Clear Button and Auto-Scroll Checkbox
|
||||||
|
if (ImGui::Button("Clear")) {
|
||||||
|
std::lock_guard<std::mutex> lock(g_LogMutex);
|
||||||
|
g_LogBuffer.clear();
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
static bool autoScroll = true;
|
||||||
|
ImGui::Checkbox("Auto-scroll", &autoScroll);
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Child region for scrolling
|
||||||
|
ImGui::BeginChild("ScrollingRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||||
|
|
||||||
|
// Lock the mutex to safely access the log buffer
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(g_LogMutex);
|
||||||
|
for (const auto& log : g_LogBuffer) {
|
||||||
|
ImGui::TextUnformatted(log.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-scroll to the bottom if enabled
|
||||||
|
if (autoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
|
||||||
|
ImGui::SetScrollHereY(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::End();
|
||||||
|
}
|
22
src/LogSystem.h
Normal file
22
src/LogSystem.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// LogSystem.h
|
||||||
|
#ifndef LOGSYSTEM_H
|
||||||
|
#define LOGSYSTEM_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
// Global log buffer and its mutex
|
||||||
|
extern std::vector<std::string> g_LogBuffer;
|
||||||
|
extern std::mutex g_LogMutex;
|
||||||
|
|
||||||
|
// Maximum number of log messages to retain
|
||||||
|
constexpr size_t MAX_LOG_MESSAGES = 1000;
|
||||||
|
|
||||||
|
// Function to add a new log message
|
||||||
|
void AddLogMessage(const std::string& message);
|
||||||
|
|
||||||
|
// Function to draw the log terminal
|
||||||
|
void DrawLogTerminal(const char* title = "Terminal", bool* p_open = nullptr);
|
||||||
|
|
||||||
|
#endif // LOGSYSTEM_H
|
51
src/RenderComponent.cpp
Normal file
51
src/RenderComponent.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// RenderComponent.cpp
|
||||||
|
#include "RenderComponent.h"
|
||||||
|
|
||||||
|
const std::string RenderComponent::name = "Render";
|
||||||
|
|
||||||
|
RenderComponent::RenderComponent()
|
||||||
|
: meshName("WhiteCube"), color(1.0f, 1.0f, 1.0f)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& RenderComponent::GetName() const
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& RenderComponent::GetStaticName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
YAML::Node RenderComponent::Serialize()
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
node["MeshName"] = meshName;
|
||||||
|
|
||||||
|
// Color
|
||||||
|
{
|
||||||
|
YAML::Node colorNode;
|
||||||
|
colorNode.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
colorNode.push_back(color.r);
|
||||||
|
colorNode.push_back(color.g);
|
||||||
|
colorNode.push_back(color.b);
|
||||||
|
node["Color"] = colorNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderComponent::Deserialize(const YAML::Node& node)
|
||||||
|
{
|
||||||
|
if (node["MeshName"])
|
||||||
|
{
|
||||||
|
meshName = node["MeshName"].as<std::string>();
|
||||||
|
}
|
||||||
|
if (node["Color"])
|
||||||
|
{
|
||||||
|
auto clr = node["Color"].as<std::vector<float>>();
|
||||||
|
if (clr.size() == 3)
|
||||||
|
color = glm::vec3(clr[0], clr[1], clr[2]);
|
||||||
|
}
|
||||||
|
}
|
30
src/RenderComponent.h
Normal file
30
src/RenderComponent.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// RenderComponent.h
|
||||||
|
#ifndef RENDER_COMPONENT_H
|
||||||
|
#define RENDER_COMPONENT_H
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
class RenderComponent : public Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::string meshName;
|
||||||
|
glm::vec3 color;
|
||||||
|
|
||||||
|
RenderComponent();
|
||||||
|
virtual const std::string& GetName() const override;
|
||||||
|
static const std::string& GetStaticName();
|
||||||
|
|
||||||
|
// Serialization methods
|
||||||
|
virtual YAML::Node Serialize() override;
|
||||||
|
virtual void Deserialize(const YAML::Node& node) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RENDER_COMPONENT_H
|
174
src/RigidBody3DComponent.cpp
Normal file
174
src/RigidBody3DComponent.cpp
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
// RigidBody3DComponent.cpp
|
||||||
|
#include "RigidBody3DComponent.h"
|
||||||
|
|
||||||
|
// Other necessary includes
|
||||||
|
#include <glm/gtc/type_ptr.hpp> // For glm::value_ptr if used in ImGui
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Define the static name
|
||||||
|
const std::string RigidBody3DComponent::name = "RigidBody";
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Constructors
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// Default Constructor
|
||||||
|
RigidBody3DComponent::RigidBody3DComponent()
|
||||||
|
: velocity(0.0f, 0.0f, 0.0f),
|
||||||
|
acceleration(0.0f, 0.0f, 0.0f),
|
||||||
|
mass(1.0f),
|
||||||
|
type(RigidBodyType::Dynamic)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parameterized Constructor
|
||||||
|
RigidBody3DComponent::RigidBody3DComponent(const glm::vec3 &vel, const glm::vec3 &acc, float m, RigidBodyType rbType)
|
||||||
|
: velocity(vel),
|
||||||
|
acceleration(acc),
|
||||||
|
mass(m),
|
||||||
|
type(rbType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// GetName Methods
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// Returns the name of the component
|
||||||
|
const std::string &RigidBody3DComponent::GetName() const
|
||||||
|
{
|
||||||
|
return GetStaticName();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the static name of the component
|
||||||
|
const std::string &RigidBody3DComponent::GetStaticName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Serialization Methods
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
// Serialize the component to YAML
|
||||||
|
YAML::Node RigidBody3DComponent::Serialize()
|
||||||
|
{
|
||||||
|
YAML::Node node;
|
||||||
|
// Position
|
||||||
|
{
|
||||||
|
YAML::Node VelNode;
|
||||||
|
VelNode.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
VelNode.push_back(velocity.x);
|
||||||
|
VelNode.push_back(velocity.y);
|
||||||
|
VelNode.push_back(velocity.z);
|
||||||
|
node["Velocity"] = VelNode;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
YAML::Node accNode;
|
||||||
|
accNode.SetStyle(YAML::EmitterStyle::Flow);
|
||||||
|
accNode.push_back(acceleration.x);
|
||||||
|
accNode.push_back(acceleration.y);
|
||||||
|
accNode.push_back(acceleration.z);
|
||||||
|
node["Acceleration"] = accNode;
|
||||||
|
}
|
||||||
|
node["Mass"] = mass;
|
||||||
|
node["Type"] = static_cast<int>(type); // Serialize enum as int
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialize the component from YAML
|
||||||
|
void RigidBody3DComponent::Deserialize(const YAML::Node& node)
|
||||||
|
{
|
||||||
|
// Deserialize Velocity
|
||||||
|
if (node["Velocity"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto vel = node["Velocity"].as<std::vector<float>>();
|
||||||
|
if (vel.size() == 3)
|
||||||
|
velocity = glm::vec3(vel[0], vel[1], vel[2]);
|
||||||
|
else
|
||||||
|
std::cerr << "Warning: 'Velocity' does not have exactly 3 elements. Using default value.\n";
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Velocity': " << e.what() << "\nUsing default velocity.\n";
|
||||||
|
velocity = glm::vec3(0.0f, 0.0f, 0.0f); // Default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Velocity' node not found. Using default value.\n";
|
||||||
|
velocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialize Acceleration
|
||||||
|
if (node["Acceleration"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto acc = node["Acceleration"].as<std::vector<float>>();
|
||||||
|
if (acc.size() == 3)
|
||||||
|
acceleration = glm::vec3(acc[0], acc[1], acc[2]);
|
||||||
|
else
|
||||||
|
std::cerr << "Warning: 'Acceleration' does not have exactly 3 elements. Using default value.\n";
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Acceleration': " << e.what() << "\nUsing default acceleration.\n";
|
||||||
|
acceleration = glm::vec3(0.0f, 0.0f, 0.0f); // Default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Acceleration' node not found. Using default value.\n";
|
||||||
|
acceleration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialize Mass
|
||||||
|
if (node["Mass"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mass = node["Mass"].as<float>();
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Mass': " << e.what() << "\nUsing default mass.\n";
|
||||||
|
mass = 1.0f; // Default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Mass' node not found. Using default mass.\n";
|
||||||
|
mass = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserialize Type
|
||||||
|
if (node["Type"])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int typeInt = node["Type"].as<int>();
|
||||||
|
if (typeInt >= 0 && typeInt <= 2) // Assuming enum values 0,1,2
|
||||||
|
{
|
||||||
|
type = static_cast<RigidBodyType>(typeInt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Type' has an invalid value (" << typeInt << "). Using default (Dynamic).\n";
|
||||||
|
type = RigidBodyType::Dynamic;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const YAML::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Error deserializing 'Type': " << e.what() << "\nUsing default type (Dynamic).\n";
|
||||||
|
type = RigidBodyType::Dynamic; // Default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: 'Type' node not found. Using default type (Dynamic).\n";
|
||||||
|
type = RigidBodyType::Dynamic;
|
||||||
|
}
|
||||||
|
}
|
43
src/RigidBody3DComponent.h
Normal file
43
src/RigidBody3DComponent.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// RigidBody3DComponent.h
|
||||||
|
#ifndef RIGIDBODY3DCOMPONENT_H
|
||||||
|
#define RIGIDBODY3DCOMPONENT_H
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
// Enum for Rigid Body Types (optional, based on your needs)
|
||||||
|
enum class RigidBodyType {
|
||||||
|
Static,
|
||||||
|
Dynamic,
|
||||||
|
Kinematic
|
||||||
|
};
|
||||||
|
|
||||||
|
class RigidBody3DComponent : public Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Physical Properties
|
||||||
|
glm::vec3 velocity;
|
||||||
|
glm::vec3 acceleration;
|
||||||
|
float mass;
|
||||||
|
RigidBodyType type;
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
RigidBody3DComponent();
|
||||||
|
RigidBody3DComponent(const glm::vec3& vel, const glm::vec3& acc, float m, RigidBodyType rbType);
|
||||||
|
|
||||||
|
// Override Component methods
|
||||||
|
virtual const std::string& GetName() const override;
|
||||||
|
static const std::string& GetStaticName();
|
||||||
|
|
||||||
|
// Serialization methods
|
||||||
|
virtual YAML::Node Serialize() override;
|
||||||
|
virtual void Deserialize(const YAML::Node& node) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RIGIDBODY3DCOMPONENT_H
|
98
src/Shader.cpp
Normal file
98
src/Shader.cpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include "Shader.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Shader constructor
|
||||||
|
Shader::Shader(const GLchar* vertexPath, const GLchar* fragmentPath)
|
||||||
|
{
|
||||||
|
// 1. Retrieve the vertex/fragment source code from filePath
|
||||||
|
std::string vertexCode;
|
||||||
|
std::string fragmentCode;
|
||||||
|
std::ifstream vShaderFile;
|
||||||
|
std::ifstream fShaderFile;
|
||||||
|
|
||||||
|
// Ensure ifstream objects can throw exceptions
|
||||||
|
vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Open files
|
||||||
|
vShaderFile.open(vertexPath);
|
||||||
|
fShaderFile.open(fragmentPath);
|
||||||
|
std::stringstream vShaderStream, fShaderStream;
|
||||||
|
// Read file's buffer contents into streams
|
||||||
|
vShaderStream << vShaderFile.rdbuf();
|
||||||
|
fShaderStream << fShaderFile.rdbuf();
|
||||||
|
// Close file handlers
|
||||||
|
vShaderFile.close();
|
||||||
|
fShaderFile.close();
|
||||||
|
// Convert stream into string
|
||||||
|
vertexCode = vShaderStream.str();
|
||||||
|
fragmentCode = fShaderStream.str();
|
||||||
|
}
|
||||||
|
catch (std::ifstream::failure& e)
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR::SHADER::FILE_NOT_SUCCESSFULLY_READ\n";
|
||||||
|
}
|
||||||
|
const GLchar* vShaderCode = vertexCode.c_str();
|
||||||
|
const GLchar* fShaderCode = fragmentCode.c_str();
|
||||||
|
|
||||||
|
// 2. Compile shaders
|
||||||
|
GLuint vertex, fragment;
|
||||||
|
GLint success;
|
||||||
|
GLchar infoLog[512];
|
||||||
|
|
||||||
|
// Vertex Shader
|
||||||
|
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||||
|
glCompileShader(vertex);
|
||||||
|
// Check compile errors
|
||||||
|
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
||||||
|
std::cerr << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fragment Shader
|
||||||
|
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||||
|
glCompileShader(fragment);
|
||||||
|
// Check compile errors
|
||||||
|
glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
glGetShaderInfoLog(fragment, 512, NULL, infoLog);
|
||||||
|
std::cerr << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shader Program
|
||||||
|
Program = glCreateProgram();
|
||||||
|
glAttachShader(Program, vertex);
|
||||||
|
glAttachShader(Program, fragment);
|
||||||
|
glLinkProgram(Program);
|
||||||
|
// Check linking errors
|
||||||
|
glGetProgramiv(Program, GL_LINK_STATUS, &success);
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
glGetProgramInfoLog(Program, 512, NULL, infoLog);
|
||||||
|
std::cerr << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the shaders
|
||||||
|
glDeleteShader(vertex);
|
||||||
|
glDeleteShader(fragment);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activate the shader
|
||||||
|
void Shader::Use()
|
||||||
|
{
|
||||||
|
glUseProgram(Program);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set integer uniform
|
||||||
|
void Shader::setInt(const std::string& name, int value) const
|
||||||
|
{
|
||||||
|
glUniform1i(glGetUniformLocation(Program, name.c_str()), value);
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user