Commit for 2021.02.14.7z
This commit is contained in:
parent
3398714e8a
commit
3985d59cac
108
Makefile
108
Makefile
@ -1,9 +1,13 @@
|
||||
ARCH = win64
|
||||
PREFIX = gcc
|
||||
include makefiles/win64.$(PREFIX).make
|
||||
TARGET_NAME = program
|
||||
TARGET_EXTENSION = exe
|
||||
TARGET_LIB_EXTENSION = dll
|
||||
|
||||
include makefiles/$(ARCH).$(PREFIX).make
|
||||
|
||||
.PHONY: $(ARCH)-$(PREFIX)
|
||||
|
||||
TARGET_NAME += program
|
||||
BIN_DIR += ./bin
|
||||
|
||||
ENGINE_SRC_DIR += ./engine/src
|
||||
@ -25,11 +29,16 @@ GLSL_VALIDATOR += $(VULKAN_SDK_PATH)/Bin32/glslangValidator
|
||||
# Base Engine's DLL
|
||||
INC_DIR += $(ENGINE_INC_DIR)/$(ARCH)/$(PREFIX)
|
||||
DEPS +=
|
||||
REQ_DEPS += win32 opengl json:nlohmann png openal ogg freetype ncurses curl openvr luajit ultralight-ux bullet meshoptimizer # discord
|
||||
|
||||
ifneq (,$(findstring win32,$(REQ_DEPS)))
|
||||
ifneq (,$(findstring win64,$(ARCH)))
|
||||
REQ_DEPS += vulkan json:nlohmann png openal ogg freetype ncurses curl openvr luajit ultralight-ux bullet meshoptimizer # discord
|
||||
FLAGS +=
|
||||
DEPS += -lgdi32
|
||||
else ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
REQ_DEPS += opengl json:nlohmann #freetype ogg openal meshoptimizer # luajit ultralight-ux ncurses curl openvr discord
|
||||
FLAGS += $(KOS_CPPFLAGS) -frtti -DUF_NO_EXCEPTIONS
|
||||
INCS += $(KOS_INC_PATHS) -I/opt/dreamcast/sh-elf/sh-elf/include
|
||||
LIBS += $(KOS_LIB_PATHS) -L/opt/dreamcast/sh-elf/sh-elf/lib
|
||||
endif
|
||||
ifneq (,$(findstring vulkan,$(REQ_DEPS)))
|
||||
FLAGS += -DVK_USE_PLATFORM_WIN32_KHR -DUF_USE_VULKAN
|
||||
@ -37,14 +46,18 @@ ifneq (,$(findstring vulkan,$(REQ_DEPS)))
|
||||
endif
|
||||
ifneq (,$(findstring opengl,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_OPENGL -DUF_USE_GLEW
|
||||
DEPS += -lglew32 -lopengl32 -lglu32
|
||||
ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
DEPS += -lGLdc
|
||||
else
|
||||
DEPS += -lglew32 -lopengl32 -lglu32
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(findstring json,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_JSON
|
||||
DEPS +=
|
||||
ifneq (,$(findstring nlohmann,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_JSON_USE_NLOHMANN
|
||||
endif
|
||||
ifneq (,$(findstring nlohmann,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_JSON_USE_NLOHMANN
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(findstring png,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_PNG
|
||||
@ -52,7 +65,12 @@ ifneq (,$(findstring png,$(REQ_DEPS)))
|
||||
endif
|
||||
ifneq (,$(findstring openal,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_OPENAL
|
||||
DEPS += -lopenal -lalut
|
||||
ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
DEPS += -lAL
|
||||
else
|
||||
FLAGS += -DUF_USE_ALUT
|
||||
DEPS += -lopenal -lalut
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(findstring ogg,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_VORBIS
|
||||
@ -78,9 +96,15 @@ ifneq (,$(findstring openvr,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_OPENVR -DUSE_OPENVR_MINGW
|
||||
DEPS += -lopenvr_api
|
||||
endif
|
||||
ifneq (,$(findstring luajit,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_LUA -DUF_USE_LUAJIT
|
||||
DEPS += -lluajit-5.1
|
||||
ifneq (,$(findstring lua,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_LUA
|
||||
ifneq (,$(findstring luajit,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_LUAJIT
|
||||
DEPS += -lluajit-5.1
|
||||
INCS += -I/mingw64/include/luajit-2.1
|
||||
else
|
||||
DEPS += -llua-5.1
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(findstring ultralight-ux,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_ULTRALIGHT_UX
|
||||
@ -88,8 +112,12 @@ ifneq (,$(findstring ultralight-ux,$(REQ_DEPS)))
|
||||
endif
|
||||
ifneq (,$(findstring bullet,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_BULLET
|
||||
DEPS += -lBulletDynamics -lBulletCollision -lLinearMath
|
||||
# -lBullet3Collision -lLinearMath -lBullet3Common -lBullet3Dynamics -lGIMPACTUtils
|
||||
ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
DEPS += -lbulletdynamics -lbulletcollision -lbulletmath
|
||||
else
|
||||
DEPS += -lBulletDynamics -lBulletCollision -lLinearMath
|
||||
INCS += -I$(ENGINE_INC_DIR)/bullet/
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(findstring simd,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_SIMD #-march=native
|
||||
@ -105,14 +133,14 @@ LINKS += $(UF_LIBS) $(EXT_LIBS) $(DEPS)
|
||||
#-Wl,-subsystem,windows
|
||||
|
||||
LIB_DIR += $(ENGINE_LIB_DIR)/$(ARCH)
|
||||
INCS += -I$(ENGINE_INC_DIR) -I$(INC_DIR) -I$(VULKAN_SDK_PATH)/include -I/mingw64/include -I/mingw64/include/luajit-2.1 -I$(ENGINE_INC_DIR)/bullet/
|
||||
INCS += -I$(ENGINE_INC_DIR) -I$(INC_DIR) -I$(VULKAN_SDK_PATH)/include -I/mingw64/include
|
||||
LIBS += -L$(ENGINE_LIB_DIR) -L$(LIB_DIR) -L$(LIB_DIR)/$(PREFIX) -L$(VULKAN_SDK_PATH)/Lib
|
||||
|
||||
SRCS_DLL += $(wildcard $(ENGINE_SRC_DIR)/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*/*/*.cpp) $(wildcard $(ENGINE_SRC_DIR)/*/*/*/*/*.cpp)
|
||||
OBJS_DLL += $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_DLL))
|
||||
BASE_DLL += lib$(LIB_NAME)
|
||||
IM_DLL += $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_DLL).dll.a
|
||||
EX_DLL += $(BIN_DIR)/exe/lib/$(ARCH)/$(PREFIX)/$(BASE_DLL).dll
|
||||
IM_DLL += $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_DLL).$(TARGET_LIB_EXTENSION).a
|
||||
EX_DLL += $(BIN_DIR)/exe/lib/$(ARCH)/$(PREFIX)/$(BASE_DLL).$(TARGET_LIB_EXTENSION)
|
||||
# External Engine's DLL
|
||||
EXT_INC_DIR += $(INC_DIR)
|
||||
EXT_LB_FLAGS += $(LIB_DIR)
|
||||
@ -127,16 +155,51 @@ EXT_LIBS += -L$(ENGINE_LIB_DIR) -L$(EXT_LIB_DIR) -L$(EXT_LIB_DIR)/$(PREFIX)
|
||||
SRCS_EXT_DLL += $(wildcard $(EXT_SRC_DIR)/*.cpp) $(wildcard $(EXT_SRC_DIR)/*/*.cpp) $(wildcard $(EXT_SRC_DIR)/*/*/*.cpp) $(wildcard $(EXT_SRC_DIR)/*/*/*/*.cpp) $(wildcard $(EXT_SRC_DIR)/*/*/*/*/*.cpp)
|
||||
OBJS_EXT_DLL += $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_EXT_DLL))
|
||||
BASE_EXT_DLL += lib$(EXT_LIB_NAME)
|
||||
EXT_IM_DLL += $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).dll.a
|
||||
EXT_EX_DLL += $(BIN_DIR)/exe/lib/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).dll
|
||||
EXT_IM_DLL += $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).$(TARGET_LIB_EXTENSION).a
|
||||
EXT_EX_DLL += $(BIN_DIR)/exe/lib/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).$(TARGET_LIB_EXTENSION)
|
||||
# Client EXE
|
||||
SRCS += $(wildcard $(CLIENT_SRC_DIR)/*.cpp) $(wildcard $(CLIENT_SRC_DIR)/*/*.cpp)
|
||||
OBJS += $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS))
|
||||
TARGET += $(BIN_DIR)/exe/$(TARGET_NAME).$(PREFIX).exe
|
||||
TARGET += $(BIN_DIR)/exe/$(TARGET_NAME).$(PREFIX).$(TARGET_EXTENSION)
|
||||
# Shaders
|
||||
SRCS_SHADERS += $(wildcard bin/data/shaders/*.glsl)
|
||||
TARGET_SHADERS += $(patsubst %.glsl,%.spv,$(SRCS_SHADERS))
|
||||
|
||||
ifneq (,$(findstring dreamcast,$(ARCH)))
|
||||
#$(ARCH): $(EX_DLL) $(EXT_EX_DLL) $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
|
||||
$(ARCH): $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
|
||||
#OBJS = $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_EXT_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS))
|
||||
OBJS = $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS))
|
||||
DEPS += -lkallisti -lc -lm -lgcc -lstdc++ -lGLdc -lAL # -l$(LIB_NAME) -l$(EXT_LIB_NAME)
|
||||
|
||||
%.$(ARCH).$(PREFIX).o: %.cpp
|
||||
$(CC) $(FLAGS) $(INCS) -c $< -o $@
|
||||
|
||||
$(EX_DLL): FLAGS += -DUF_EXPORTS -DJSON_DLL_BUILD
|
||||
$(EX_DLL): $(OBJS_DLL)
|
||||
$(KOS_AR) cru $@ $^
|
||||
$(KOS_RANLIB) $@
|
||||
cp $@ $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_DLL).a
|
||||
|
||||
$(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS -DJSON_DLL_BUILD
|
||||
$(EXT_EX_DLL): $(OBJS_EXT_DLL)
|
||||
$(KOS_AR) cru $@ $^
|
||||
$(KOS_RANLIB) $@
|
||||
cp $@ $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).a
|
||||
|
||||
./bin/dreamcast/romdisk.img:
|
||||
$(KOS_GENROMFS) -f ./bin/dreamcast/romdisk.img -d ./bin/dreamcast/romdisk/ -v
|
||||
|
||||
./bin/dreamcast/romdisk.o: ./bin/dreamcast/romdisk.img
|
||||
$(KOS_BASE)/utils/bin2o/bin2o ./bin/dreamcast/romdisk.img romdisk ./bin/dreamcast/romdisk.o
|
||||
|
||||
$(TARGET): $(OBJS) ./bin/dreamcast/romdisk.o
|
||||
$(CC) -O2 -fomit-frame-pointer -ml -m4-single-only -ffunction-sections -fdata-sections $(KOS_INC_PATHS) $(INCS) -D_arch_dreamcast -D_arch_sub_pristine -Wall -g -fno-builtin -ml -m4-single-only -Wl,-Ttext=0x8c010000 -Wl,--gc-sections -T/opt/dreamcast/kos/utils/ldscripts/shlelf.xc -nodefaultlibs $(KOS_LIB_PATHS) $(LIBS) -o $(TARGET) $(OBJS) ./bin/dreamcast/romdisk.o -Wl,--start-group $(DEPS) -Wl,--end-group
|
||||
|
||||
./bin/dreamcast/$(TARGET_NAME).cdi: $(TARGET)
|
||||
cd ./bin/dreamcast/; ./elf2cdi.sh $(TARGET_NAME)
|
||||
|
||||
else
|
||||
$(ARCH): $(EX_DLL) $(EXT_EX_DLL) $(TARGET) $(TARGET_SHADERS)
|
||||
|
||||
%.$(ARCH).$(PREFIX).o: %.cpp
|
||||
@ -145,15 +208,16 @@ $(ARCH): $(EX_DLL) $(EXT_EX_DLL) $(TARGET) $(TARGET_SHADERS)
|
||||
$(EX_DLL): FLAGS += -DUF_EXPORTS -DJSON_DLL_BUILD
|
||||
$(EX_DLL): $(OBJS_DLL)
|
||||
$(CC) -shared -o $(EX_DLL) -g -Wl,--out-implib=$(IM_DLL) $(OBJS_DLL) $(LIBS) $(INCS) $(LINKS)
|
||||
cp $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_DLL).dll.a $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_DLL).a
|
||||
cp $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_DLL).$(TARGET_LIB_EXTENSION).a $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_DLL).a
|
||||
|
||||
$(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS -DJSON_DLL_BUILD
|
||||
$(EXT_EX_DLL): $(OBJS_EXT_DLL)
|
||||
$(CC) -shared -o $(EXT_EX_DLL) -g -Wl,--out-implib=$(EXT_IM_DLL) $(OBJS_EXT_DLL) $(EXT_LIBS) $(EXT_INCS) $(EXT_LINKS)
|
||||
cp $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).dll.a $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).a
|
||||
cp $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).$(TARGET_LIB_EXTENSION).a $(ENGINE_LIB_DIR)/$(ARCH)/$(PREFIX)/$(BASE_EXT_DLL).a
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(FLAGS) $(OBJS) $(LIBS) $(INCS) $(LINKS) -l$(LIB_NAME) -l$(EXT_LIB_NAME) -o $(TARGET)
|
||||
endif
|
||||
|
||||
%.spv: %.glsl
|
||||
$(GLSL_VALIDATOR) -V $< -o $@
|
||||
|
||||
@ -1,294 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in vec3 inPositionEye;
|
||||
layout (location = 2) in vec3 inNormalEye;
|
||||
layout (location = 3) in vec4 inColor;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void fog( inout vec3 i ) {
|
||||
vec3 color = vec3( 0, 0, 0 );
|
||||
float inner = 8, outer = 64;
|
||||
float distance = length(-inPositionEye);
|
||||
float factor = (distance - inner) / (outer - inner);
|
||||
factor = clamp( factor, 0.0, 1.0 );
|
||||
|
||||
i = mix(i.rgb, color, factor);
|
||||
}
|
||||
|
||||
void phong( inout vec3 i ) {
|
||||
vec3 Ls = vec3(1.0, 1.0, 1.0); // light specular
|
||||
vec3 Ld = vec3(0.4, 0.4, 1.0); // light color
|
||||
vec3 La = vec3(0.1, 0.1, 0.1);
|
||||
|
||||
vec3 Ks = vec3(0.6, 0.6, 0.9); // material specular
|
||||
vec3 Kd = i; // material diffuse
|
||||
vec3 Ka = vec3(0.7, 0.7, 0.7);
|
||||
|
||||
float Kexp = 1000.0;
|
||||
|
||||
vec3 dist_light_eye = vec3(0, 0, 0) - inPositionEye;
|
||||
vec3 dir_light_eye = normalize(dist_light_eye);
|
||||
float d_dot = max(dot( dir_light_eye, inNormalEye ), 0.0);
|
||||
|
||||
vec3 reflection_eye = reflect( -dir_light_eye, inNormalEye );
|
||||
vec3 surface_eye = normalize(-inPositionEye);
|
||||
float s_dot = max(dot( reflection_eye, surface_eye ), 0.0);
|
||||
float s_factor = pow( s_dot, Kexp );
|
||||
|
||||
vec3 Ia = La * Ka;
|
||||
vec3 Id = Ld * Kd * d_dot;
|
||||
vec3 Is = Ls * Ks * s_factor;
|
||||
i = Is + Id + Ia;
|
||||
}
|
||||
|
||||
const int indexMatrix16x16[256] = int[](0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255,
|
||||
128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127,
|
||||
32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223,
|
||||
160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95,
|
||||
8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247,
|
||||
136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119,
|
||||
40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215,
|
||||
168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87,
|
||||
2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253,
|
||||
130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125,
|
||||
34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221,
|
||||
162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93,
|
||||
10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245,
|
||||
138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117,
|
||||
42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213,
|
||||
170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85);
|
||||
|
||||
float indexValue16x16() {
|
||||
int x = int(mod(gl_FragCoord.x, 16));
|
||||
int y = int(mod(gl_FragCoord.y, 16));
|
||||
return indexMatrix16x16[(x + y * 16)] / 256.0;
|
||||
}
|
||||
/*
|
||||
const int paletteSize = 16;
|
||||
const vec3 palette[paletteSize] = vec3[](
|
||||
vec3( 0x00/255.0, 0x00/255.0, 0x18/255.0),
|
||||
vec3( 0x60/255.0, 0x60/255.0, 0x78/255.0),
|
||||
vec3( 0x00/255.0, 0x18/255.0, 0x30/255.0),
|
||||
vec3( 0x18/255.0, 0x18/255.0, 0x30/255.0),
|
||||
vec3( 0x30/255.0, 0x30/255.0, 0x48/255.0),
|
||||
vec3( 0x30/255.0, 0x30/255.0, 0x30/255.0),
|
||||
vec3( 0x18/255.0, 0x18/255.0, 0x48/255.0),
|
||||
vec3( 0x00/255.0, 0x00/255.0, 0x00/255.0),
|
||||
vec3( 0x18/255.0, 0x00/255.0, 0x00/255.0),
|
||||
vec3( 0x48/255.0, 0x48/255.0, 0x60/255.0),
|
||||
vec3( 0x30/255.0, 0x00/255.0, 0x18/255.0),
|
||||
vec3( 0x00/255.0, 0x18/255.0, 0x48/255.0),
|
||||
vec3( 0x90/255.0, 0x90/255.0, 0xa8/255.0),
|
||||
vec3( 0x48/255.0, 0x18/255.0, 0x30/255.0),
|
||||
vec3( 0x18/255.0, 0x30/255.0, 0x48/255.0),
|
||||
vec3( 0x18/255.0, 0x00/255.0, 0x18/255.0)
|
||||
);
|
||||
*/
|
||||
|
||||
const int paletteSize = 40;
|
||||
const vec3 palette[paletteSize] = vec3[](
|
||||
vec3( 0, 0, 0),
|
||||
vec3( 0, 0, 0.502),
|
||||
vec3( 0, 0, 0.753),
|
||||
vec3( 0, 0, 1),
|
||||
vec3( 0, 1, 0.251),
|
||||
vec3( 0, 1, 0.50),
|
||||
vec3( 24.0/360.0, 1, 0.251),
|
||||
vec3( 24.0/360.0, 1, 0.5),
|
||||
vec3( 24.0/360.0, 1, 0.625),
|
||||
vec3( 24.0/360.0, 1, 0.751),
|
||||
vec3( 30.0/360.0, 1, 0.251),
|
||||
vec3( 60.0/360.0, 0.333, 0.376),
|
||||
vec3( 60.0/360.0, 1, 0.251),
|
||||
vec3( 60.0/360.0, 1, 0.5),
|
||||
vec3( 60.0/360.0, 1, 0.751),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.751),
|
||||
vec3(150.0/360.0, 1, 0.251),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(150.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.751),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.251),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(270.0/360.0, 1, 0.751),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.751),
|
||||
vec3(330.0/360.0, 1, 0.251),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.751)
|
||||
);
|
||||
|
||||
/*
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
*/
|
||||
|
||||
float hueToRgb(float f1, float f2, float hue) {
|
||||
if (hue < 0.0)
|
||||
hue += 1.0;
|
||||
else if (hue > 1.0)
|
||||
hue -= 1.0;
|
||||
float res;
|
||||
if ((6.0 * hue) < 1.0)
|
||||
res = f1 + (f2 - f1) * 6.0 * hue;
|
||||
else if ((2.0 * hue) < 1.0)
|
||||
res = f2;
|
||||
else if ((3.0 * hue) < 2.0)
|
||||
res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
|
||||
else
|
||||
res = f1;
|
||||
return res;
|
||||
}
|
||||
|
||||
vec3 hslToRgb(vec3 hsl) {
|
||||
vec3 rgb;
|
||||
|
||||
if (hsl.y == 0.0) {
|
||||
rgb = vec3(hsl.z); // Luminance
|
||||
} else {
|
||||
float f2;
|
||||
|
||||
if (hsl.z < 0.5)
|
||||
f2 = hsl.z * (1.0 + hsl.y);
|
||||
else
|
||||
f2 = hsl.z + hsl.y - hsl.y * hsl.z;
|
||||
|
||||
float f1 = 2.0 * hsl.z - f2;
|
||||
|
||||
rgb.r = hueToRgb(f1, f2, hsl.x + (1.0/3.0));
|
||||
rgb.g = hueToRgb(f1, f2, hsl.x);
|
||||
rgb.b = hueToRgb(f1, f2, hsl.x - (1.0/3.0));
|
||||
}
|
||||
return rgb;
|
||||
}
|
||||
|
||||
vec3 rgbToHcv(vec3 rgb) {
|
||||
float epsilon = 1e-10;
|
||||
// Based on work by Sam Hocevar and Emil Persson
|
||||
vec4 p = (rgb.g < rgb.b) ? vec4(rgb.bg, -1.0, 2.0 / 3.0) : vec4(rgb.gb, 0.0, -1.0 / 3.0);
|
||||
vec4 q = (rgb.r < p.x) ? vec4(p.xyw, rgb.r) : vec4(rgb.r, p.yzx);
|
||||
float c = q.x - min(q.w, q.y);
|
||||
float h = abs((q.w - q.y) / (6.0 * c + epsilon) + q.z);
|
||||
return vec3(h, c, q.x);
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 rgb) {
|
||||
float epsilon = 1e-10;
|
||||
vec3 hcv = rgbToHcv(rgb);
|
||||
float l = hcv.z - hcv.y * 0.5;
|
||||
float s = hcv.y / (1.0 - abs(l * 2.0 - 1.0) + epsilon);
|
||||
return vec3(hcv.x, s, l);
|
||||
}
|
||||
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = rgbToHsl(palette[i]);
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 8.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue16x16();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue16x16();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
outFragColor = texture(samplerColor, inUv);
|
||||
phong(outFragColor.rgb);
|
||||
fog(outFragColor.rgb);
|
||||
outFragColor.rgb = mix( outFragColor.rgb, inColor.rgb, inColor.a );
|
||||
if ( outFragColor.a < 0.001 ) discard;
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,189 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in vec3 inPositionEye;
|
||||
layout (location = 2) in vec3 inNormalEye;
|
||||
layout (location = 3) in vec4 inColor;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void fog( inout vec3 i ) {
|
||||
vec3 color = vec3( 0, 0, 0 );
|
||||
float inner = 8, outer = 64;
|
||||
float distance = length(-inPositionEye);
|
||||
float factor = (distance - inner) / (outer - inner);
|
||||
factor = clamp( factor, 0.0, 1.0 );
|
||||
|
||||
i = mix(i.rgb, color, factor);
|
||||
}
|
||||
|
||||
void phong( inout vec3 i ) {
|
||||
vec3 Ls = vec3(1.0, 1.0, 1.0); // light specular
|
||||
vec3 Ld = vec3(0.4, 0.4, 1.0); // light color
|
||||
vec3 La = vec3(0.1, 0.1, 0.1);
|
||||
|
||||
vec3 Ks = vec3(0.6, 0.6, 0.9); // material specular
|
||||
vec3 Kd = i; // material diffuse
|
||||
vec3 Ka = vec3(0.7, 0.7, 0.7);
|
||||
|
||||
float Kexp = 1000.0;
|
||||
|
||||
vec3 dist_light_eye = vec3(0, 0, 0) - inPositionEye;
|
||||
vec3 dir_light_eye = normalize(dist_light_eye);
|
||||
float d_dot = max(dot( dir_light_eye, inNormalEye ), 0.0);
|
||||
|
||||
vec3 reflection_eye = reflect( -dir_light_eye, inNormalEye );
|
||||
vec3 surface_eye = normalize(-inPositionEye);
|
||||
float s_dot = max(dot( reflection_eye, surface_eye ), 0.0);
|
||||
float s_factor = pow( s_dot, Kexp );
|
||||
|
||||
vec3 Ia = La * Ka;
|
||||
vec3 Id = Ld * Kd * d_dot;
|
||||
vec3 Is = Ls * Ks * s_factor;
|
||||
i = Is + Id + Ia;
|
||||
}
|
||||
|
||||
const int indexMatrix4x4[16] = int[](0, 8, 2, 10,
|
||||
12, 4, 14, 6,
|
||||
3, 11, 1, 9,
|
||||
15, 7, 13, 5);
|
||||
|
||||
float indexValue4x4() {
|
||||
int x = int(mod(gl_FragCoord.x, 4));
|
||||
int y = int(mod(gl_FragCoord.y, 4));
|
||||
return indexMatrix4x4[(x + y * 4)] / 16.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue4x4();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue4x4();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
outFragColor = texture(samplerColor, inUv);
|
||||
phong(outFragColor.rgb);
|
||||
fog(outFragColor.rgb);
|
||||
outFragColor.rgb = mix( outFragColor.rgb, inColor.rgb, inColor.a );
|
||||
if ( outFragColor.a < 0.001 ) discard;
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,194 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in vec3 inPositionEye;
|
||||
layout (location = 2) in vec3 inNormalEye;
|
||||
layout (location = 3) in vec4 inColor;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void fog( inout vec3 i ) {
|
||||
vec3 color = vec3( 0, 0, 0 );
|
||||
float inner = 8, outer = 64;
|
||||
float distance = length(-inPositionEye);
|
||||
float factor = (distance - inner) / (outer - inner);
|
||||
factor = clamp( factor, 0.0, 1.0 );
|
||||
|
||||
i = mix(i.rgb, color, factor);
|
||||
}
|
||||
|
||||
void phong( inout vec3 i ) {
|
||||
vec3 Ls = vec3(1.0, 1.0, 1.0); // light specular
|
||||
vec3 Ld = vec3(0.4, 0.4, 1.0); // light color
|
||||
vec3 La = vec3(0.1, 0.1, 0.1);
|
||||
|
||||
vec3 Ks = vec3(0.6, 0.6, 0.9); // material specular
|
||||
vec3 Kd = i; // material diffuse
|
||||
vec3 Ka = vec3(0.7, 0.7, 0.7);
|
||||
|
||||
float Kexp = 1000.0;
|
||||
|
||||
vec3 dist_light_eye = vec3(0, 0, 0) - inPositionEye;
|
||||
vec3 dir_light_eye = normalize(dist_light_eye);
|
||||
float d_dot = max(dot( dir_light_eye, inNormalEye ), 0.0);
|
||||
|
||||
vec3 reflection_eye = reflect( -dir_light_eye, inNormalEye );
|
||||
vec3 surface_eye = normalize(-inPositionEye);
|
||||
float s_dot = max(dot( reflection_eye, surface_eye ), 0.0);
|
||||
float s_factor = pow( s_dot, Kexp );
|
||||
|
||||
vec3 Ia = La * Ka;
|
||||
vec3 Id = Ld * Kd * d_dot;
|
||||
vec3 Is = Ls * Ks * s_factor;
|
||||
i = Is + Id + Ia;
|
||||
}
|
||||
|
||||
const int indexMatrix8x8[64] = int[](0, 32, 8, 40, 2, 34, 10, 42,
|
||||
48, 16, 56, 24, 50, 18, 58, 26,
|
||||
12, 44, 4, 36, 14, 46, 6, 38,
|
||||
60, 28, 52, 20, 62, 30, 54, 22,
|
||||
3, 35, 11, 43, 1, 33, 9, 41,
|
||||
51, 19, 59, 27, 49, 17, 57, 25,
|
||||
15, 47, 7, 39, 13, 45, 5, 37,
|
||||
63, 31, 55, 23, 61, 29, 53, 21);
|
||||
|
||||
float indexValue8x8() {
|
||||
int x = int(mod(gl_FragCoord.x, 8));
|
||||
int y = int(mod(gl_FragCoord.y, 8));
|
||||
return indexMatrix8x8[(x + y * 8)] / 64.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue8x8();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue8x8();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
outFragColor = texture(samplerColor, inUv);
|
||||
phong(outFragColor.rgb);
|
||||
fog(outFragColor.rgb);
|
||||
outFragColor.rgb = mix( outFragColor.rgb, inColor.rgb, inColor.a );
|
||||
if ( outFragColor.a < 0.001 ) discard;
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,178 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
const int indexMatrix16x16[256] = int[](0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255,
|
||||
128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127,
|
||||
32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223,
|
||||
160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95,
|
||||
8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247,
|
||||
136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119,
|
||||
40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215,
|
||||
168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87,
|
||||
2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253,
|
||||
130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125,
|
||||
34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221,
|
||||
162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93,
|
||||
10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245,
|
||||
138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117,
|
||||
42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213,
|
||||
170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85);
|
||||
|
||||
float indexValue16x16() {
|
||||
int x = int(mod(gl_FragCoord.x, 16));
|
||||
int y = int(mod(gl_FragCoord.y, 16));
|
||||
return indexMatrix16x16[(x + y * 16)] / 256.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue16x16();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue16x16();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
outFragColor = texture(samplerColor, inUv);// vec4(inUv.s, inUv.t, 1.0, 1.0);
|
||||
if ( outFragColor.a < 0.001 ) discard;
|
||||
if ( inGui.mode == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
} else {
|
||||
outFragColor *= inGui.color;
|
||||
}
|
||||
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,166 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
const int indexMatrix4x4[16] = int[](0, 8, 2, 10,
|
||||
12, 4, 14, 6,
|
||||
3, 11, 1, 9,
|
||||
15, 7, 13, 5);
|
||||
|
||||
float indexValue4x4() {
|
||||
int x = int(mod(gl_FragCoord.x, 4));
|
||||
int y = int(mod(gl_FragCoord.y, 4));
|
||||
return indexMatrix4x4[(x + y * 4)] / 16.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue4x4();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue4x4();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
outFragColor = texture(samplerColor, inUv);// vec4(inUv.s, inUv.t, 1.0, 1.0);
|
||||
if ( outFragColor.a < 0.001 ) discard;
|
||||
if ( inGui.mode == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
} else {
|
||||
outFragColor *= inGui.color;
|
||||
}
|
||||
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,170 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
const int indexMatrix8x8[64] = int[](0, 32, 8, 40, 2, 34, 10, 42,
|
||||
48, 16, 56, 24, 50, 18, 58, 26,
|
||||
12, 44, 4, 36, 14, 46, 6, 38,
|
||||
60, 28, 52, 20, 62, 30, 54, 22,
|
||||
3, 35, 11, 43, 1, 33, 9, 41,
|
||||
51, 19, 59, 27, 49, 17, 57, 25,
|
||||
15, 47, 7, 39, 13, 45, 5, 37,
|
||||
63, 31, 55, 23, 61, 29, 53, 21);
|
||||
|
||||
float indexValue8x8() {
|
||||
int x = int(mod(gl_FragCoord.x, 8));
|
||||
int y = int(mod(gl_FragCoord.y, 8));
|
||||
return indexMatrix8x8[(x + y * 8)] / 64.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue8x8();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue8x8();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
outFragColor = texture(samplerColor, inUv);// vec4(inUv.s, inUv.t, 1.0, 1.0);
|
||||
if ( outFragColor.a < 0.001 ) discard;
|
||||
if ( inGui.mode == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
} else {
|
||||
outFragColor *= inGui.color;
|
||||
}
|
||||
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,196 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
int sdf;
|
||||
int shadowbox;
|
||||
vec4 stroke;
|
||||
float weight;
|
||||
int spread;
|
||||
float scale;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
const int indexMatrix16x16[256] = int[](0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255,
|
||||
128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127,
|
||||
32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223,
|
||||
160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95,
|
||||
8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247,
|
||||
136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119,
|
||||
40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215,
|
||||
168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87,
|
||||
2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253,
|
||||
130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125,
|
||||
34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221,
|
||||
162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93,
|
||||
10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245,
|
||||
138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117,
|
||||
42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213,
|
||||
170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85);
|
||||
|
||||
float indexValue16x16() {
|
||||
int x = int(mod(gl_FragCoord.x, 16));
|
||||
int y = int(mod(gl_FragCoord.y, 16));
|
||||
return indexMatrix16x16[(x + y * 16)] / 256.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue16x16();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue16x16();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
if ( inGui.shadowbox == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
return;
|
||||
}
|
||||
float dist = texture(samplerColor, inUv).r;
|
||||
if ( inGui.sdf == 1 ) {
|
||||
float smoothing = ( inGui.spread > 0 && inGui.scale > 0 ) ? 0.25 / (inGui.spread * inGui.scale) : 0.25 / (4 * 1.5);
|
||||
float outlining = smoothstep(0.5 - smoothing, 0.5 + smoothing, dist);
|
||||
float alpha = smoothstep(inGui.weight - smoothing, inGui.weight + smoothing, dist);
|
||||
vec4 c = inGui.color;
|
||||
outFragColor = mix(inGui.stroke, c, outlining);
|
||||
outFragColor.a = inGui.color.a * alpha;
|
||||
if ( alpha < 0.001 ) discard;
|
||||
if ( alpha > 1 ) discard;
|
||||
} else {
|
||||
outFragColor = vec4(inGui.color) * dist;
|
||||
if ( dist < 0.001 ) discard;
|
||||
if ( dist > 1 ) discard;
|
||||
}
|
||||
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,185 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
int sdf;
|
||||
int shadowbox;
|
||||
vec4 stroke;
|
||||
float weight;
|
||||
int spread;
|
||||
float scale;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
|
||||
const int indexMatrix4x4[16] = int[](0, 8, 2, 10,
|
||||
12, 4, 14, 6,
|
||||
3, 11, 1, 9,
|
||||
15, 7, 13, 5);
|
||||
|
||||
float indexValue4x4() {
|
||||
int x = int(mod(gl_FragCoord.x, 4));
|
||||
int y = int(mod(gl_FragCoord.y, 4));
|
||||
return indexMatrix4x4[(x + y * 4)] / 16.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue4x4();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue4x4();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
if ( inGui.shadowbox == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
return;
|
||||
}
|
||||
float dist = texture(samplerColor, inUv).r;
|
||||
if ( inGui.sdf == 1 ) {
|
||||
float smoothing = ( inGui.spread > 0 && inGui.scale > 0 ) ? 0.25 / (inGui.spread * inGui.scale) : 0.25 / (4 * 1.5);
|
||||
float outlining = smoothstep(0.5 - smoothing, 0.5 + smoothing, dist);
|
||||
float alpha = smoothstep(inGui.weight - smoothing, inGui.weight + smoothing, dist);
|
||||
vec4 c = inGui.color;
|
||||
outFragColor = mix(inGui.stroke, c, outlining);
|
||||
outFragColor.a = inGui.color.a * alpha;
|
||||
if ( alpha < 0.001 ) discard;
|
||||
if ( alpha > 1 ) discard;
|
||||
} else {
|
||||
outFragColor = vec4(inGui.color) * dist;
|
||||
if ( dist < 0.001 ) discard;
|
||||
if ( dist > 1 ) discard;
|
||||
}
|
||||
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,187 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
int sdf;
|
||||
int shadowbox;
|
||||
vec4 stroke;
|
||||
float weight;
|
||||
int spread;
|
||||
float scale;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
const int indexMatrix8x8[64] = int[](0, 32, 8, 40, 2, 34, 10, 42,
|
||||
48, 16, 56, 24, 50, 18, 58, 26,
|
||||
12, 44, 4, 36, 14, 46, 6, 38,
|
||||
60, 28, 52, 20, 62, 30, 54, 22,
|
||||
3, 35, 11, 43, 1, 33, 9, 41,
|
||||
51, 19, 59, 27, 49, 17, 57, 25,
|
||||
15, 47, 7, 39, 13, 45, 5, 37,
|
||||
63, 31, 55, 23, 61, 29, 53, 21);
|
||||
|
||||
float indexValue8x8() {
|
||||
int x = int(mod(gl_FragCoord.x, 8));
|
||||
int y = int(mod(gl_FragCoord.y, 8));
|
||||
return indexMatrix8x8[(x + y * 8)] / 64.0;
|
||||
}
|
||||
|
||||
const int paletteSize = 28;
|
||||
const vec3 palette[28] = vec3[](
|
||||
vec3(0, 0, 0),
|
||||
vec3(0, 0, 1),
|
||||
vec3(0, 0, 0.502),
|
||||
vec3(0, 0, 0.753),
|
||||
vec3(0, 1, 0.251),
|
||||
vec3(0, 1, 0.50),
|
||||
vec3(60.0/360.0, 1, 0.251),
|
||||
vec3(60.0/360.0, 1, 0.5),
|
||||
vec3(120.0/360.0, 1, 0.251),
|
||||
vec3(120.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.251),
|
||||
vec3(180.0/360.0, 1, 0.5),
|
||||
vec3(240.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.5),
|
||||
vec3(300.0/360.0, 1, 0.251),
|
||||
vec3(300.0/360.0, 1, 0.5),
|
||||
vec3(60.0/360.0, 0.333, 0.376),
|
||||
vec3(60.0/360.0, 1, 0.751),
|
||||
vec3(180.0/360.0, 1, 0.125),
|
||||
vec3(150.0/360.0, 1, 0.5),
|
||||
vec3(210.0/360.0, 1, 0.5),
|
||||
vec3(180.0/360.0, 1, 0.751),
|
||||
vec3(210.0/360.0, 1, 0.251),
|
||||
vec3(240.0/360.0, 1, 0.751),
|
||||
vec3(270.0/360.0, 1, 0.5),
|
||||
vec3(330.0/360.0, 1, 0.5),
|
||||
vec3(30.0/360.0, 1, 0.251),
|
||||
vec3(24.0/360.0, 1, 0.625)
|
||||
);
|
||||
|
||||
vec3 hslToRgb(vec3 HSL) {
|
||||
vec3 RGB; {
|
||||
float H = HSL.x;
|
||||
float R = abs(H * 6 - 3) - 1;
|
||||
float G = 2 - abs(H * 6 - 2);
|
||||
float B = 2 - abs(H * 6 - 4);
|
||||
RGB = clamp(vec3(R,G,B), 0, 1);
|
||||
}
|
||||
float C = (1 - abs(2 * HSL.z - 1)) * HSL.y;
|
||||
return (RGB - 0.5) * C + HSL.z;
|
||||
}
|
||||
|
||||
vec3 rgbToHsl(vec3 RGB) {
|
||||
float Epsilon = 1e-10;
|
||||
vec3 HCV; {
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4(RGB.bg, -1.0, 2.0/3.0) : vec4(RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4(P.xyw, RGB.r) : vec4(RGB.r, P.yzx);
|
||||
float C = Q.x - min(Q.w, Q.y);
|
||||
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
|
||||
HCV = vec3(H, C, Q.x);
|
||||
}
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1 - abs(L * 2 - 1) + Epsilon);
|
||||
return vec3(HCV.x, S, L);
|
||||
}
|
||||
|
||||
float hueDistance(float h1, float h2) {
|
||||
float diff = abs((h1 - h2));
|
||||
return min(abs((1.0 - diff)), diff);
|
||||
}
|
||||
|
||||
vec3[2] closestColors(float hue) {
|
||||
vec3 ret[2];
|
||||
vec3 closest = vec3(-2, 0, 0);
|
||||
vec3 secondClosest = vec3(-2, 0, 0);
|
||||
vec3 temp;
|
||||
for (int i = 0; i < paletteSize; ++i) {
|
||||
temp = palette[i];
|
||||
float tempDistance = hueDistance(temp.x, hue);
|
||||
if (tempDistance < hueDistance(closest.x, hue)) {
|
||||
secondClosest = closest;
|
||||
closest = temp;
|
||||
} else {
|
||||
if (tempDistance < hueDistance(secondClosest.x, hue)) {
|
||||
secondClosest = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret[0] = closest;
|
||||
ret[1] = secondClosest;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float lightnessSteps = 4.0;
|
||||
float lightnessStep(float l) {
|
||||
/* Quantize the lightness to one of `lightnessSteps` values */
|
||||
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
|
||||
}
|
||||
|
||||
vec3 dither1(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
|
||||
vec3 cs[2] = closestColors(hsl.x);
|
||||
vec3 c1 = cs[0];
|
||||
vec3 c2 = cs[1];
|
||||
float d = indexValue8x8();
|
||||
float hueDiff = hueDistance(hsl.x, c1.x) / hueDistance(c2.x, c1.x);
|
||||
|
||||
float l1 = lightnessStep(max((hsl.z - 0.125), 0.0));
|
||||
float l2 = lightnessStep(min((hsl.z + 0.124), 1.0));
|
||||
float lightnessDiff = (hsl.z - l1) / (l2 - l1);
|
||||
|
||||
vec3 resultColor = (hueDiff < d) ? c1 : c2;
|
||||
//resultColor.z = (lightnessDiff < d) ? l1 : l2;
|
||||
return hslToRgb(resultColor);
|
||||
}
|
||||
|
||||
float dither(float color) {
|
||||
float closestColor = (color < 0.5) ? 0 : 1;
|
||||
float secondClosestColor = 1 - closestColor;
|
||||
float d = indexValue8x8();
|
||||
float distance = abs(closestColor - color);
|
||||
return (distance < d) ? closestColor : secondClosestColor;
|
||||
}
|
||||
|
||||
vec3 dither(vec3 color) {
|
||||
vec3 hsl = rgbToHsl(color);
|
||||
hsl.y = dither(hsl.y);
|
||||
return hslToRgb(hsl);
|
||||
}
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
if ( inGui.shadowbox == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
return;
|
||||
}
|
||||
float dist = texture(samplerColor, inUv).r;
|
||||
if ( inGui.sdf == 1 ) {
|
||||
float smoothing = ( inGui.spread > 0 && inGui.scale > 0 ) ? 0.25 / (inGui.spread * inGui.scale) : 0.25 / (4 * 1.5);
|
||||
float outlining = smoothstep(0.5 - smoothing, 0.5 + smoothing, dist);
|
||||
float alpha = smoothstep(inGui.weight - smoothing, inGui.weight + smoothing, dist);
|
||||
vec4 c = inGui.color;
|
||||
outFragColor = mix(inGui.stroke, c, outlining);
|
||||
outFragColor.a = inGui.color.a * alpha;
|
||||
if ( alpha < 0.001 ) discard;
|
||||
if ( alpha > 1 ) discard;
|
||||
} else {
|
||||
outFragColor = vec4(inGui.color) * dist;
|
||||
if ( dist < 0.001 ) discard;
|
||||
if ( dist > 1 ) discard;
|
||||
}
|
||||
|
||||
outFragColor.rgb = dither(outFragColor.rgb);
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
outFragColor = texture(samplerColor, inUv);// vec4(inUv.s, inUv.t, 1.0, 1.0);
|
||||
if ( outFragColor.a < 0.001 ) discard;
|
||||
if ( inGui.mode == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
} else {
|
||||
outFragColor *= inGui.color;
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
int sdf;
|
||||
int shadowbox;
|
||||
vec4 stroke;
|
||||
float weight;
|
||||
int spread;
|
||||
float scale;
|
||||
};
|
||||
|
||||
layout (location = 0) in vec2 inUv;
|
||||
layout (location = 1) in flat Gui inGui;
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main() {
|
||||
if ( inUv.x < inGui.offset.x ) discard;
|
||||
if ( inUv.y < inGui.offset.y ) discard;
|
||||
if ( inUv.x > inGui.offset.z ) discard;
|
||||
if ( inUv.y > inGui.offset.w ) discard;
|
||||
|
||||
if ( inGui.shadowbox == 1 ) {
|
||||
outFragColor = inGui.color;
|
||||
return;
|
||||
}
|
||||
float dist = texture(samplerColor, inUv).r;
|
||||
if ( inGui.sdf == 1 ) {
|
||||
float smoothing = ( inGui.spread > 0 && inGui.scale > 0 ) ? 0.25 / (inGui.spread * inGui.scale) : 0.25 / (4 * 1.5);
|
||||
float outlining = smoothstep(0.5 - smoothing, 0.5 + smoothing, dist);
|
||||
float alpha = smoothstep(inGui.weight - smoothing, inGui.weight + smoothing, dist);
|
||||
vec4 c = inGui.color;
|
||||
outFragColor = mix(inGui.stroke, c, outlining);
|
||||
outFragColor.a = inGui.color.a * alpha;
|
||||
if ( alpha < 0.001 ) discard;
|
||||
if ( alpha > 1 ) discard;
|
||||
} else {
|
||||
outFragColor = vec4(inGui.color) * dist;
|
||||
if ( dist < 0.001 ) discard;
|
||||
if ( dist > 1 ) discard;
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (location = 0) in vec2 inPos;
|
||||
layout (location = 1) in vec2 inUv;
|
||||
|
||||
struct Matrices {
|
||||
mat4 model;
|
||||
};
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
int sdf;
|
||||
int shadowbox;
|
||||
vec4 stroke;
|
||||
float weight;
|
||||
int spread;
|
||||
float scale;
|
||||
};
|
||||
|
||||
layout (binding = 0) uniform UBO {
|
||||
Matrices matrices;
|
||||
Gui gui;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec2 outUv;
|
||||
layout (location = 1) out flat Gui outGui;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
|
||||
void main() {
|
||||
outUv = inUv;
|
||||
outGui = ubo.gui;
|
||||
|
||||
gl_Position = ubo.matrices.model * vec4(inPos.xy, ubo.gui.depth, 1.0);
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
#version 450
|
||||
|
||||
layout (location = 0) in vec2 inPos;
|
||||
layout (location = 1) in vec2 inUv;
|
||||
|
||||
struct Matrices {
|
||||
mat4 model;
|
||||
};
|
||||
struct Gui {
|
||||
vec4 offset;
|
||||
vec4 color;
|
||||
int mode;
|
||||
float depth;
|
||||
};
|
||||
|
||||
layout (binding = 0) uniform UBO {
|
||||
Matrices matrices;
|
||||
Gui gui;
|
||||
} ubo;
|
||||
|
||||
layout (location = 0) out vec2 outUv;
|
||||
layout (location = 1) out flat Gui outGui;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
|
||||
void main() {
|
||||
outUv = inUv;
|
||||
outGui = ubo.gui;
|
||||
|
||||
gl_Position = ubo.matrices.model * vec4(inPos.xy, ubo.gui.depth, 1.0);
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
#include "../main.h"
|
||||
#if !UF_ENV_DREAMCAST
|
||||
|
||||
#include <uf/utils/window/window.h>
|
||||
#include <uf/utils/io/iostream.h>
|
||||
@ -91,6 +92,7 @@ void client::initialize() {
|
||||
*/
|
||||
}
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
/* Initialize OpenAL */ {
|
||||
if ( !ext::oal.initialize() ) {
|
||||
std::cerr << "[ERROR] AL failed to initialize!" << std::endl;
|
||||
@ -98,6 +100,7 @@ void client::initialize() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize hooks */ {
|
||||
// if ( client::config["engine"]["hook"]["mode"] == "Both" || client::config["engine"]["hook"]["mode"] == "Readable" ) {
|
||||
@ -250,9 +253,12 @@ void client::terminate() {
|
||||
|
||||
client::window.terminate();
|
||||
|
||||
#if UF_USE_BULLET
|
||||
if ( !ext::oal.terminate() ) {
|
||||
std::cerr << "[ERROR] AL failed to terminate!" << std::endl;
|
||||
std::exit(EXIT_SUCCESS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
109
client/dc.cpp
Normal file
109
client/dc.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
#include <uf/ext/ext.h>
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
|
||||
#include <uf/ext/opengl/opengl.h>
|
||||
#include <uf/ext/opengl/commands.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
ext::opengl::settings::width = 640;
|
||||
ext::opengl::settings::height = 480;
|
||||
|
||||
ext::opengl::initialize();
|
||||
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClearDepth(1.0);
|
||||
glDepthFunc(GL_LESS);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(90.0f, (GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
#if 0
|
||||
while ( true ) {
|
||||
ext::opengl::tick();
|
||||
ext::opengl::render();
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
ext::opengl::CommandBuffer commands;
|
||||
|
||||
commands.record([]{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(90.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(-1.5f,0.0f,-6.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
glVertex3f( 0.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.0f,1.0f,0.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.0f,0.0f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
glTranslatef(3.0f,0.0f,0.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
});
|
||||
while ( true ) {
|
||||
commands.submit();
|
||||
glKosSwapBuffers();
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
while ( true ) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(90.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(-1.5f,0.0f,-6.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
glVertex3f( 0.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.0f,1.0f,0.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.0f,0.0f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
glTranslatef(3.0f,0.0f,0.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
glKosSwapBuffers();
|
||||
}
|
||||
#endif
|
||||
|
||||
ext::opengl::destroy();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +1,16 @@
|
||||
#include "main.h"
|
||||
|
||||
#if !UF_ENV_DREAMCAST
|
||||
#include <uf/utils/io/iostream.h>
|
||||
#include <uf/utils/time/time.h>
|
||||
|
||||
#include <uf/utils/mempool/mempool.h>
|
||||
|
||||
#define HANDLE_EXCEPTIONS 0
|
||||
#if UF_NO_EXCEPTIONS
|
||||
#define HANDLE_EXCEPTIONS 0
|
||||
#else
|
||||
#define HANDLE_EXCEPTIONS 1
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv){
|
||||
for ( size_t i = 0; i < argc; ++i ) {
|
||||
@ -72,4 +77,5 @@ int main(int argc, char** argv){
|
||||
ext::terminate();
|
||||
client::terminate();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/ext/ext.h>
|
||||
#if !UF_ENV_DREAMCAST
|
||||
#include <uf/utils/window/window.h>
|
||||
#include <uf/utils/serialize/serializer.h>
|
||||
#include <uf/utils/thread/thread.h>
|
||||
@ -15,4 +15,5 @@ namespace client {
|
||||
void tick();
|
||||
void render();
|
||||
void terminate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
37
engine/inc/dreamcast.h
Normal file
37
engine/inc/dreamcast.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <math.h>
|
||||
|
||||
namespace std {
|
||||
template<typename T>
|
||||
std::string to_string( const T& val ) {
|
||||
std::stringstream ss;
|
||||
ss << val;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline float strtof(const char* str, char** endptr) { return ::strtof(str, endptr); }
|
||||
inline double strtold(const char* str, char** endptr) { return ::strtold(str, endptr); }
|
||||
inline long long int strtoll(const char* str, char** endptr, int base) { return ::strtoll(str, endptr, base); }
|
||||
inline unsigned long long int strtoull(const char* str, char** endptr, int base) { return ::strtoull(str, endptr, base); }
|
||||
|
||||
template<typename... Args>
|
||||
inline int snprintf( char* s, size_t n, const char* format, Args... args ) {
|
||||
return ::snprintf(s, n, format, args...);
|
||||
}
|
||||
|
||||
inline unsigned long long stoull( const std::string& s, std::size_t* pos = 0, int base = 10 ) {
|
||||
std::wstring ws(s.begin(), s.end());
|
||||
return std::__cxx11::stoull( ws, pos, base );
|
||||
}
|
||||
inline int stoi( const std::string& s, std::size_t* pos = 0, int base = 10 ) {
|
||||
std::wstring ws(s.begin(), s.end());
|
||||
return std::__cxx11::stoi( ws, pos, base );
|
||||
}
|
||||
inline double cbrt( double x ) {
|
||||
return ::cbrt( x );
|
||||
}
|
||||
}
|
||||
@ -1579,7 +1579,7 @@ class TinyGLTF {
|
||||
|
||||
#endif
|
||||
|
||||
#elif !defined(__ANDROID__)
|
||||
#elif !defined(__ANDROID__) && !defined(__sh__)
|
||||
#include <wordexp.h>
|
||||
#endif
|
||||
|
||||
@ -2566,7 +2566,7 @@ std::string ExpandFilePath(const std::string &filepath, void *) {
|
||||
#else
|
||||
|
||||
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || \
|
||||
defined(__ANDROID__) || defined(__EMSCRIPTEN__)
|
||||
defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__sh__)
|
||||
// no expansion
|
||||
std::string s = filepath;
|
||||
#else
|
||||
|
||||
@ -46,7 +46,7 @@ struct meshopt_Stream
|
||||
* destination must contain enough space for the resulting remap table (vertex_count elements)
|
||||
* indices can be NULL if the input is unindexed
|
||||
*/
|
||||
MESHOPTIMIZER_API size_t meshopt_generateVertexRemap(unsigned int* destination, const unsigned int* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size);
|
||||
MESHOPTIMIZER_API size_t meshopt_generateVertexRemap(uint32_t* destination, const uint32_t* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size);
|
||||
|
||||
/**
|
||||
* Generates a vertex remap table from multiple vertex streams and an optional index buffer and returns number of unique vertices
|
||||
@ -57,7 +57,7 @@ MESHOPTIMIZER_API size_t meshopt_generateVertexRemap(unsigned int* destination,
|
||||
* destination must contain enough space for the resulting remap table (vertex_count elements)
|
||||
* indices can be NULL if the input is unindexed
|
||||
*/
|
||||
MESHOPTIMIZER_API size_t meshopt_generateVertexRemapMulti(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count, const struct meshopt_Stream* streams, size_t stream_count);
|
||||
MESHOPTIMIZER_API size_t meshopt_generateVertexRemapMulti(uint32_t* destination, const uint32_t* indices, size_t index_count, size_t vertex_count, const struct meshopt_Stream* streams, size_t stream_count);
|
||||
|
||||
/**
|
||||
* Generates vertex buffer from the source vertex buffer and remap table generated by meshopt_generateVertexRemap
|
||||
@ -65,7 +65,7 @@ MESHOPTIMIZER_API size_t meshopt_generateVertexRemapMulti(unsigned int* destinat
|
||||
* destination must contain enough space for the resulting vertex buffer (unique_vertex_count elements, returned by meshopt_generateVertexRemap)
|
||||
* vertex_count should be the initial vertex count and not the value returned by meshopt_generateVertexRemap
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_remapVertexBuffer(void* destination, const void* vertices, size_t vertex_count, size_t vertex_size, const unsigned int* remap);
|
||||
MESHOPTIMIZER_API void meshopt_remapVertexBuffer(void* destination, const void* vertices, size_t vertex_count, size_t vertex_size, const uint32_t* remap);
|
||||
|
||||
/**
|
||||
* Generate index buffer from the source index buffer and remap table generated by meshopt_generateVertexRemap
|
||||
@ -73,7 +73,7 @@ MESHOPTIMIZER_API void meshopt_remapVertexBuffer(void* destination, const void*
|
||||
* destination must contain enough space for the resulting index buffer (index_count elements)
|
||||
* indices can be NULL if the input is unindexed
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_remapIndexBuffer(unsigned int* destination, const unsigned int* indices, size_t index_count, const unsigned int* remap);
|
||||
MESHOPTIMIZER_API void meshopt_remapIndexBuffer(uint32_t* destination, const uint32_t* indices, size_t index_count, const uint32_t* remap);
|
||||
|
||||
/**
|
||||
* Generate index buffer that can be used for more efficient rendering when only a subset of the vertex attributes is necessary
|
||||
@ -82,7 +82,7 @@ MESHOPTIMIZER_API void meshopt_remapIndexBuffer(unsigned int* destination, const
|
||||
*
|
||||
* destination must contain enough space for the resulting index buffer (index_count elements)
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_generateShadowIndexBuffer(unsigned int* destination, const unsigned int* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size, size_t vertex_stride);
|
||||
MESHOPTIMIZER_API void meshopt_generateShadowIndexBuffer(uint32_t* destination, const uint32_t* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size, size_t vertex_stride);
|
||||
|
||||
/**
|
||||
* Generate index buffer that can be used for more efficient rendering when only a subset of the vertex attributes is necessary
|
||||
@ -91,7 +91,7 @@ MESHOPTIMIZER_API void meshopt_generateShadowIndexBuffer(unsigned int* destinati
|
||||
*
|
||||
* destination must contain enough space for the resulting index buffer (index_count elements)
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_generateShadowIndexBufferMulti(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count, const struct meshopt_Stream* streams, size_t stream_count);
|
||||
MESHOPTIMIZER_API void meshopt_generateShadowIndexBufferMulti(uint32_t* destination, const uint32_t* indices, size_t index_count, size_t vertex_count, const struct meshopt_Stream* streams, size_t stream_count);
|
||||
|
||||
/**
|
||||
* Vertex transform cache optimizer
|
||||
@ -100,7 +100,7 @@ MESHOPTIMIZER_API void meshopt_generateShadowIndexBufferMulti(unsigned int* dest
|
||||
*
|
||||
* destination must contain enough space for the resulting index buffer (index_count elements)
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_optimizeVertexCache(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count);
|
||||
MESHOPTIMIZER_API void meshopt_optimizeVertexCache(uint32_t* destination, const uint32_t* indices, size_t index_count, size_t vertex_count);
|
||||
|
||||
/**
|
||||
* Vertex transform cache optimizer for strip-like caches
|
||||
@ -109,7 +109,7 @@ MESHOPTIMIZER_API void meshopt_optimizeVertexCache(unsigned int* destination, co
|
||||
*
|
||||
* destination must contain enough space for the resulting index buffer (index_count elements)
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_optimizeVertexCacheStrip(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count);
|
||||
MESHOPTIMIZER_API void meshopt_optimizeVertexCacheStrip(uint32_t* destination, const uint32_t* indices, size_t index_count, size_t vertex_count);
|
||||
|
||||
/**
|
||||
* Vertex transform cache optimizer for FIFO caches
|
||||
@ -120,7 +120,7 @@ MESHOPTIMIZER_API void meshopt_optimizeVertexCacheStrip(unsigned int* destinatio
|
||||
* destination must contain enough space for the resulting index buffer (index_count elements)
|
||||
* cache_size should be less than the actual GPU cache size to avoid cache thrashing
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_optimizeVertexCacheFifo(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count, unsigned int cache_size);
|
||||
MESHOPTIMIZER_API void meshopt_optimizeVertexCacheFifo(uint32_t* destination, const uint32_t* indices, size_t index_count, size_t vertex_count, uint32_t cache_size);
|
||||
|
||||
/**
|
||||
* Overdraw optimizer
|
||||
@ -132,7 +132,7 @@ MESHOPTIMIZER_API void meshopt_optimizeVertexCacheFifo(unsigned int* destination
|
||||
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
|
||||
* threshold indicates how much the overdraw optimizer can degrade vertex cache efficiency (1.05 = up to 5%) to reduce overdraw more efficiently
|
||||
*/
|
||||
MESHOPTIMIZER_API void meshopt_optimizeOverdraw(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, float threshold);
|
||||
MESHOPTIMIZER_API void meshopt_optimizeOverdraw(uint32_t* destination, const uint32_t* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, float threshold);
|
||||
|
||||
/**
|
||||
* Vertex fetch cache optimizer
|
||||
@ -143,7 +143,7 @@ MESHOPTIMIZER_API void meshopt_optimizeOverdraw(unsigned int* destination, const
|
||||
* destination must contain enough space for the resulting vertex buffer (vertex_count elements)
|
||||
* indices is used both as an input and as an output index buffer
|
||||
*/
|
||||
MESHOPTIMIZER_API size_t meshopt_optimizeVertexFetch(void* destination, unsigned int* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size);
|
||||
MESHOPTIMIZER_API size_t meshopt_optimizeVertexFetch(void* destination, uint32_t* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size);
|
||||
|
||||
/**
|
||||
* Vertex fetch cache optimizer
|
||||
@ -153,7 +153,7 @@ MESHOPTIMIZER_API size_t meshopt_optimizeVertexFetch(void* destination, unsigned
|
||||
*
|
||||
* destination must contain enough space for the resulting remap table (vertex_count elements)
|
||||
*/
|
||||
MESHOPTIMIZER_API size_t meshopt_optimizeVertexFetchRemap(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count);
|
||||
MESHOPTIMIZER_API size_t meshopt_optimizeVertexFetchRemap(uint32_t* destination, const uint32_t* indices, size_t index_count, size_t vertex_count);
|
||||
|
||||
/**
|
||||
* Index buffer encoder
|
||||
@ -164,7 +164,7 @@ MESHOPTIMIZER_API size_t meshopt_optimizeVertexFetchRemap(unsigned int* destinat
|
||||
*
|
||||
* buffer must contain enough space for the encoded index buffer (use meshopt_encodeIndexBufferBound to compute worst case size)
|
||||
*/
|
||||
MESHOPTIMIZER_API size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, const unsigned int* indices, size_t index_count);
|
||||
MESHOPTIMIZER_API size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, const uint32_t* indices, size_t index_count);
|
||||
MESHOPTIMIZER_API size_t meshopt_encodeIndexBufferBound(size_t index_count, size_t vertex_count);
|
||||
|
||||
/**
|
||||
@ -191,7 +191,7 @@ MESHOPTIMIZER_API int meshopt_decodeIndexBuffer(void* destination, size_t index_
|
||||
*
|
||||
* buffer must contain enough space for the encoded index sequence (use meshopt_encodeIndexSequenceBound to compute worst case size)
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_encodeIndexSequence(unsigned char* buffer, size_t buffer_size, const unsigned int* indices, size_t index_count);
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_encodeIndexSequence(unsigned char* buffer, size_t buffer_size, const uint32_t* indices, size_t index_count);
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_encodeIndexSequenceBound(size_t index_count, size_t vertex_count);
|
||||
|
||||
/**
|
||||
@ -261,7 +261,7 @@ MESHOPTIMIZER_EXPERIMENTAL void meshopt_decodeFilterExp(void* buffer, size_t ver
|
||||
* destination must contain enough space for the *source* index buffer (since optimization is iterative, this means index_count elements - *not* target_index_count!)
|
||||
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error);
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplify(uint32_t* destination, const uint32_t* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error);
|
||||
|
||||
/**
|
||||
* Experimental: Mesh simplifier (sloppy)
|
||||
@ -274,7 +274,7 @@ MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplify(unsigned int* destination, co
|
||||
* destination must contain enough space for the target index buffer
|
||||
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifySloppy(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count);
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifySloppy(uint32_t* destination, const uint32_t* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count);
|
||||
|
||||
/**
|
||||
* Experimental: Point cloud simplifier
|
||||
@ -286,7 +286,7 @@ MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifySloppy(unsigned int* destinati
|
||||
* destination must contain enough space for the target index buffer
|
||||
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifyPoints(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_vertex_count);
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifyPoints(uint32_t* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_vertex_count);
|
||||
|
||||
/**
|
||||
* Mesh stripifier
|
||||
@ -298,7 +298,7 @@ MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_simplifyPoints(unsigned int* destinati
|
||||
* destination must contain enough space for the target index buffer, worst case can be computed with meshopt_stripifyBound
|
||||
* restart_index should be 0xffff or 0xffffffff depending on index size, or 0 to use degenerate triangles
|
||||
*/
|
||||
MESHOPTIMIZER_API size_t meshopt_stripify(unsigned int* destination, const unsigned int* indices, size_t index_count, size_t vertex_count, unsigned int restart_index);
|
||||
MESHOPTIMIZER_API size_t meshopt_stripify(uint32_t* destination, const uint32_t* indices, size_t index_count, size_t vertex_count, uint32_t restart_index);
|
||||
MESHOPTIMIZER_API size_t meshopt_stripifyBound(size_t index_count);
|
||||
|
||||
/**
|
||||
@ -308,13 +308,13 @@ MESHOPTIMIZER_API size_t meshopt_stripifyBound(size_t index_count);
|
||||
*
|
||||
* destination must contain enough space for the target index buffer, worst case can be computed with meshopt_unstripifyBound
|
||||
*/
|
||||
MESHOPTIMIZER_API size_t meshopt_unstripify(unsigned int* destination, const unsigned int* indices, size_t index_count, unsigned int restart_index);
|
||||
MESHOPTIMIZER_API size_t meshopt_unstripify(uint32_t* destination, const uint32_t* indices, size_t index_count, uint32_t restart_index);
|
||||
MESHOPTIMIZER_API size_t meshopt_unstripifyBound(size_t index_count);
|
||||
|
||||
struct meshopt_VertexCacheStatistics
|
||||
{
|
||||
unsigned int vertices_transformed;
|
||||
unsigned int warps_executed;
|
||||
uint32_t vertices_transformed;
|
||||
uint32_t warps_executed;
|
||||
float acmr; /* transformed vertices / triangle count; best case 0.5, worst case 3.0, optimum depends on topology */
|
||||
float atvr; /* transformed vertices / vertex count; best case 1.0, worst case 6.0, optimum is 1.0 (each vertex is transformed once) */
|
||||
};
|
||||
@ -324,12 +324,12 @@ struct meshopt_VertexCacheStatistics
|
||||
* Returns cache hit statistics using a simplified FIFO model
|
||||
* Results may not match actual GPU performance
|
||||
*/
|
||||
MESHOPTIMIZER_API struct meshopt_VertexCacheStatistics meshopt_analyzeVertexCache(const unsigned int* indices, size_t index_count, size_t vertex_count, unsigned int cache_size, unsigned int warp_size, unsigned int primgroup_size);
|
||||
MESHOPTIMIZER_API struct meshopt_VertexCacheStatistics meshopt_analyzeVertexCache(const uint32_t* indices, size_t index_count, size_t vertex_count, uint32_t cache_size, uint32_t warp_size, uint32_t primgroup_size);
|
||||
|
||||
struct meshopt_OverdrawStatistics
|
||||
{
|
||||
unsigned int pixels_covered;
|
||||
unsigned int pixels_shaded;
|
||||
uint32_t pixels_covered;
|
||||
uint32_t pixels_shaded;
|
||||
float overdraw; /* shaded pixels / covered pixels; best case 1.0 */
|
||||
};
|
||||
|
||||
@ -340,11 +340,11 @@ struct meshopt_OverdrawStatistics
|
||||
*
|
||||
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
|
||||
*/
|
||||
MESHOPTIMIZER_API struct meshopt_OverdrawStatistics meshopt_analyzeOverdraw(const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
MESHOPTIMIZER_API struct meshopt_OverdrawStatistics meshopt_analyzeOverdraw(const uint32_t* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
|
||||
struct meshopt_VertexFetchStatistics
|
||||
{
|
||||
unsigned int bytes_fetched;
|
||||
uint32_t bytes_fetched;
|
||||
float overfetch; /* fetched bytes / vertex buffer size; best case 1.0 (each byte is fetched once) */
|
||||
};
|
||||
|
||||
@ -353,11 +353,11 @@ struct meshopt_VertexFetchStatistics
|
||||
* Returns cache hit statistics using a simplified direct mapped model
|
||||
* Results may not match actual GPU performance
|
||||
*/
|
||||
MESHOPTIMIZER_API struct meshopt_VertexFetchStatistics meshopt_analyzeVertexFetch(const unsigned int* indices, size_t index_count, size_t vertex_count, size_t vertex_size);
|
||||
MESHOPTIMIZER_API struct meshopt_VertexFetchStatistics meshopt_analyzeVertexFetch(const uint32_t* indices, size_t index_count, size_t vertex_count, size_t vertex_size);
|
||||
|
||||
struct meshopt_Meshlet
|
||||
{
|
||||
unsigned int vertices[64];
|
||||
uint32_t vertices[64];
|
||||
unsigned char indices[126][3];
|
||||
unsigned char triangle_count;
|
||||
unsigned char vertex_count;
|
||||
@ -372,7 +372,7 @@ struct meshopt_Meshlet
|
||||
* destination must contain enough space for all meshlets, worst case size can be computed with meshopt_buildMeshletsBound
|
||||
* max_vertices and max_triangles can't exceed limits statically declared in meshopt_Meshlet (max_vertices <= 64, max_triangles <= 126)
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_buildMeshlets(struct meshopt_Meshlet* destination, const unsigned int* indices, size_t index_count, size_t vertex_count, size_t max_vertices, size_t max_triangles);
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_buildMeshlets(struct meshopt_Meshlet* destination, const uint32_t* indices, size_t index_count, size_t vertex_count, size_t max_vertices, size_t max_triangles);
|
||||
MESHOPTIMIZER_EXPERIMENTAL size_t meshopt_buildMeshletsBound(size_t index_count, size_t max_vertices, size_t max_triangles);
|
||||
|
||||
struct meshopt_Bounds
|
||||
@ -412,7 +412,7 @@ struct meshopt_Bounds
|
||||
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
|
||||
* index_count should be less than or equal to 256*3 (the function assumes clusters of limited size)
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL struct meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
MESHOPTIMIZER_EXPERIMENTAL struct meshopt_Bounds meshopt_computeClusterBounds(const uint32_t* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
MESHOPTIMIZER_EXPERIMENTAL struct meshopt_Bounds meshopt_computeMeshletBounds(const struct meshopt_Meshlet* meshlet, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
|
||||
/**
|
||||
@ -422,7 +422,7 @@ MESHOPTIMIZER_EXPERIMENTAL struct meshopt_Bounds meshopt_computeMeshletBounds(co
|
||||
*
|
||||
* destination must contain enough space for the resulting remap table (vertex_count elements)
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortRemap(unsigned int* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortRemap(uint32_t* destination, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
|
||||
/**
|
||||
* Experimental: Spatial sorter
|
||||
@ -431,7 +431,7 @@ MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortRemap(unsigned int* destinati
|
||||
* destination must contain enough space for the resulting index buffer (index_count elements)
|
||||
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
|
||||
*/
|
||||
MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortTriangles(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortTriangles(uint32_t* destination, const uint32_t* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
|
||||
/**
|
||||
* Set allocation callbacks
|
||||
@ -482,16 +482,16 @@ inline float meshopt_quantizeFloat(float v, int N);
|
||||
*
|
||||
* These functions mirror the C interface the library provides, providing template-based overloads so that
|
||||
* the caller can use an arbitrary type for the index data, both for input and output.
|
||||
* When the supplied type is the same size as that of unsigned int, the wrappers are zero-cost; when it's not,
|
||||
* When the supplied type is the same size as that of uint32_t, the wrappers are zero-cost; when it's not,
|
||||
* the wrappers end up allocating memory and copying index data to convert from one type to another.
|
||||
*/
|
||||
#if defined(__cplusplus) && !defined(MESHOPTIMIZER_NO_WRAPPERS)
|
||||
template <typename T>
|
||||
inline size_t meshopt_generateVertexRemap(unsigned int* destination, const T* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size);
|
||||
inline size_t meshopt_generateVertexRemap(uint32_t* destination, const T* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size);
|
||||
template <typename T>
|
||||
inline size_t meshopt_generateVertexRemapMulti(unsigned int* destination, const T* indices, size_t index_count, size_t vertex_count, const meshopt_Stream* streams, size_t stream_count);
|
||||
inline size_t meshopt_generateVertexRemapMulti(uint32_t* destination, const T* indices, size_t index_count, size_t vertex_count, const meshopt_Stream* streams, size_t stream_count);
|
||||
template <typename T>
|
||||
inline void meshopt_remapIndexBuffer(T* destination, const T* indices, size_t index_count, const unsigned int* remap);
|
||||
inline void meshopt_remapIndexBuffer(T* destination, const T* indices, size_t index_count, const uint32_t* remap);
|
||||
template <typename T>
|
||||
inline void meshopt_generateShadowIndexBuffer(T* destination, const T* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size, size_t vertex_stride);
|
||||
template <typename T>
|
||||
@ -501,11 +501,11 @@ inline void meshopt_optimizeVertexCache(T* destination, const T* indices, size_t
|
||||
template <typename T>
|
||||
inline void meshopt_optimizeVertexCacheStrip(T* destination, const T* indices, size_t index_count, size_t vertex_count);
|
||||
template <typename T>
|
||||
inline void meshopt_optimizeVertexCacheFifo(T* destination, const T* indices, size_t index_count, size_t vertex_count, unsigned int cache_size);
|
||||
inline void meshopt_optimizeVertexCacheFifo(T* destination, const T* indices, size_t index_count, size_t vertex_count, uint32_t cache_size);
|
||||
template <typename T>
|
||||
inline void meshopt_optimizeOverdraw(T* destination, const T* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride, float threshold);
|
||||
template <typename T>
|
||||
inline size_t meshopt_optimizeVertexFetchRemap(unsigned int* destination, const T* indices, size_t index_count, size_t vertex_count);
|
||||
inline size_t meshopt_optimizeVertexFetchRemap(uint32_t* destination, const T* indices, size_t index_count, size_t vertex_count);
|
||||
template <typename T>
|
||||
inline size_t meshopt_optimizeVertexFetch(void* destination, T* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size);
|
||||
template <typename T>
|
||||
@ -525,7 +525,7 @@ inline size_t meshopt_stripify(T* destination, const T* indices, size_t index_co
|
||||
template <typename T>
|
||||
inline size_t meshopt_unstripify(T* destination, const T* indices, size_t index_count, T restart_index);
|
||||
template <typename T>
|
||||
inline meshopt_VertexCacheStatistics meshopt_analyzeVertexCache(const T* indices, size_t index_count, size_t vertex_count, unsigned int cache_size, unsigned int warp_size, unsigned int buffer_size);
|
||||
inline meshopt_VertexCacheStatistics meshopt_analyzeVertexCache(const T* indices, size_t index_count, size_t vertex_count, uint32_t cache_size, uint32_t warp_size, uint32_t buffer_size);
|
||||
template <typename T>
|
||||
inline meshopt_OverdrawStatistics meshopt_analyzeOverdraw(const T* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
|
||||
template <typename T>
|
||||
@ -564,8 +564,8 @@ inline int meshopt_quantizeSnorm(float v, int N)
|
||||
|
||||
inline unsigned short meshopt_quantizeHalf(float v)
|
||||
{
|
||||
union { float f; unsigned int ui; } u = {v};
|
||||
unsigned int ui = u.ui;
|
||||
union { float f; uint32_t ui; } u = {v};
|
||||
uint32_t ui = u.ui;
|
||||
|
||||
int s = (ui >> 16) & 0x8000;
|
||||
int em = ui & 0x7fffffff;
|
||||
@ -587,14 +587,14 @@ inline unsigned short meshopt_quantizeHalf(float v)
|
||||
|
||||
inline float meshopt_quantizeFloat(float v, int N)
|
||||
{
|
||||
union { float f; unsigned int ui; } u = {v};
|
||||
unsigned int ui = u.ui;
|
||||
union { float f; uint32_t ui; } u = {v};
|
||||
uint32_t ui = u.ui;
|
||||
|
||||
const int mask = (1 << (23 - N)) - 1;
|
||||
const int round = (1 << (23 - N)) >> 1;
|
||||
|
||||
int e = ui & 0x7f800000;
|
||||
unsigned int rui = (ui + round) & ~mask;
|
||||
uint32_t rui = (ui + round) & ~mask;
|
||||
|
||||
/* round all numbers except inf/nan; this is important to make sure nan doesn't overflow into -0 */
|
||||
ui = e == 0x7f800000 ? ui : rui;
|
||||
@ -653,14 +653,14 @@ template <typename T> void (*meshopt_Allocator::StorageT<T>::deallocate)(void*)
|
||||
|
||||
/* Inline implementation for C++ templated wrappers */
|
||||
#if defined(__cplusplus) && !defined(MESHOPTIMIZER_NO_WRAPPERS)
|
||||
template <typename T, bool ZeroCopy = sizeof(T) == sizeof(unsigned int)>
|
||||
template <typename T, bool ZeroCopy = sizeof(T) == sizeof(uint32_t)>
|
||||
struct meshopt_IndexAdapter;
|
||||
|
||||
template <typename T>
|
||||
struct meshopt_IndexAdapter<T, false>
|
||||
{
|
||||
T* result;
|
||||
unsigned int* data;
|
||||
uint32_t* data;
|
||||
size_t count;
|
||||
|
||||
meshopt_IndexAdapter(T* result_, const T* input, size_t count_)
|
||||
@ -668,9 +668,9 @@ struct meshopt_IndexAdapter<T, false>
|
||||
, data(0)
|
||||
, count(count_)
|
||||
{
|
||||
size_t size = count > size_t(-1) / sizeof(unsigned int) ? size_t(-1) : count * sizeof(unsigned int);
|
||||
size_t size = count > size_t(-1) / sizeof(uint32_t) ? size_t(-1) : count * sizeof(uint32_t);
|
||||
|
||||
data = static_cast<unsigned int*>(meshopt_Allocator::Storage::allocate(size));
|
||||
data = static_cast<uint32_t*>(meshopt_Allocator::Storage::allocate(size));
|
||||
|
||||
if (input)
|
||||
{
|
||||
@ -694,16 +694,16 @@ struct meshopt_IndexAdapter<T, false>
|
||||
template <typename T>
|
||||
struct meshopt_IndexAdapter<T, true>
|
||||
{
|
||||
unsigned int* data;
|
||||
uint32_t* data;
|
||||
|
||||
meshopt_IndexAdapter(T* result, const T* input, size_t)
|
||||
: data(reinterpret_cast<unsigned int*>(result ? result : const_cast<T*>(input)))
|
||||
: data(reinterpret_cast<uint32_t*>(result ? result : const_cast<T*>(input)))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline size_t meshopt_generateVertexRemap(unsigned int* destination, const T* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size)
|
||||
inline size_t meshopt_generateVertexRemap(uint32_t* destination, const T* indices, size_t index_count, const void* vertices, size_t vertex_count, size_t vertex_size)
|
||||
{
|
||||
meshopt_IndexAdapter<T> in(0, indices, indices ? index_count : 0);
|
||||
|
||||
@ -711,7 +711,7 @@ inline size_t meshopt_generateVertexRemap(unsigned int* destination, const T* in
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline size_t meshopt_generateVertexRemapMulti(unsigned int* destination, const T* indices, size_t index_count, size_t vertex_count, const meshopt_Stream* streams, size_t stream_count)
|
||||
inline size_t meshopt_generateVertexRemapMulti(uint32_t* destination, const T* indices, size_t index_count, size_t vertex_count, const meshopt_Stream* streams, size_t stream_count)
|
||||
{
|
||||
meshopt_IndexAdapter<T> in(0, indices, indices ? index_count : 0);
|
||||
|
||||
@ -719,7 +719,7 @@ inline size_t meshopt_generateVertexRemapMulti(unsigned int* destination, const
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void meshopt_remapIndexBuffer(T* destination, const T* indices, size_t index_count, const unsigned int* remap)
|
||||
inline void meshopt_remapIndexBuffer(T* destination, const T* indices, size_t index_count, const uint32_t* remap)
|
||||
{
|
||||
meshopt_IndexAdapter<T> in(0, indices, indices ? index_count : 0);
|
||||
meshopt_IndexAdapter<T> out(destination, 0, index_count);
|
||||
@ -764,7 +764,7 @@ inline void meshopt_optimizeVertexCacheStrip(T* destination, const T* indices, s
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void meshopt_optimizeVertexCacheFifo(T* destination, const T* indices, size_t index_count, size_t vertex_count, unsigned int cache_size)
|
||||
inline void meshopt_optimizeVertexCacheFifo(T* destination, const T* indices, size_t index_count, size_t vertex_count, uint32_t cache_size)
|
||||
{
|
||||
meshopt_IndexAdapter<T> in(0, indices, index_count);
|
||||
meshopt_IndexAdapter<T> out(destination, 0, index_count);
|
||||
@ -782,7 +782,7 @@ inline void meshopt_optimizeOverdraw(T* destination, const T* indices, size_t in
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline size_t meshopt_optimizeVertexFetchRemap(unsigned int* destination, const T* indices, size_t index_count, size_t vertex_count)
|
||||
inline size_t meshopt_optimizeVertexFetchRemap(uint32_t* destination, const T* indices, size_t index_count, size_t vertex_count)
|
||||
{
|
||||
meshopt_IndexAdapter<T> in(0, indices, index_count);
|
||||
|
||||
@ -868,7 +868,7 @@ inline size_t meshopt_unstripify(T* destination, const T* indices, size_t index_
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline meshopt_VertexCacheStatistics meshopt_analyzeVertexCache(const T* indices, size_t index_count, size_t vertex_count, unsigned int cache_size, unsigned int warp_size, unsigned int buffer_size)
|
||||
inline meshopt_VertexCacheStatistics meshopt_analyzeVertexCache(const T* indices, size_t index_count, size_t vertex_count, uint32_t cache_size, uint32_t warp_size, uint32_t buffer_size)
|
||||
{
|
||||
meshopt_IndexAdapter<T> in(0, indices, index_count);
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#undef UF_ENV_LINUX
|
||||
#undef UF_ENV_MACOS
|
||||
#undef UF_ENV_FREEBSD
|
||||
#undef UF_ENV_DREAMCAST
|
||||
#undef UF_ENV_UNKNOWN
|
||||
#endif
|
||||
|
||||
@ -21,22 +22,39 @@
|
||||
#endif
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#define WINVER 0x0600
|
||||
// #warning Using "Windows"
|
||||
|
||||
#define UF_IO_ROOT "./data/"
|
||||
#elif defined(linux) || defined(__linux)
|
||||
// Linux
|
||||
#define UF_ENV "Linux"
|
||||
#define UF_ENV_LINUX 1
|
||||
#define UF_ENV_HEADER "linux.h"
|
||||
|
||||
#define UF_IO_ROOT "./data/"
|
||||
#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh)
|
||||
// MacOS
|
||||
#define UF_ENV "OSX"
|
||||
#define UF_ENV_OSX 1
|
||||
#define UF_ENV_HEADER "osx.h"
|
||||
|
||||
#define UF_IO_ROOT "./data/"
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
// FreeBSD
|
||||
#define UF_ENV "FreeBSD"
|
||||
#define UF_ENV_FREEBSD 1
|
||||
#define UF_ENV_HEADER "freebsd.h"
|
||||
|
||||
#define UF_IO_ROOT "./data/"
|
||||
#elif defined(__sh__)
|
||||
// Dreamcast
|
||||
#define UF_ENV "Dreamcast"
|
||||
#define UF_ENV_DREAMCAST 1
|
||||
#define UF_ENV_HEADER "dreamcast.h"
|
||||
#include UF_ENV_HEADER
|
||||
|
||||
#define _arch_dreamcast
|
||||
|
||||
#define UF_IO_ROOT "/rc/data/"
|
||||
#else
|
||||
// Unsupported system
|
||||
#define UF_ENV "Unknown"
|
||||
@ -81,45 +99,11 @@
|
||||
|
||||
// Legacy support
|
||||
#define UF_API_VAR UF_API
|
||||
#define UF_API_CALL __cdecl
|
||||
#define UF_API_CALL //__cdecl
|
||||
|
||||
#ifdef UF_DISABLE_ALIGNAS
|
||||
#define alignas(X)
|
||||
#endif
|
||||
|
||||
#include "macros.h"
|
||||
#include "simd.h"
|
||||
|
||||
//#define UF_USE_NLOHMANN 1 // wrapper works, please use this
|
||||
//#define UF_USE_JSONCPP 0 // originally implemented JSON with JSONCPP, internal wrapper broke things
|
||||
//#define UF_USE_RAPIDJSON 0 // wrapper for rapidjson is incomplete
|
||||
//#define UF_USE_LUA 0 // wrapper for SOL2 Lua tables is incomplete
|
||||
|
||||
/*
|
||||
// External libraries
|
||||
#ifndef UF_USE_GLEW
|
||||
#define UF_USE_GLEW 1
|
||||
#endif
|
||||
#ifndef UF_USE_JSON
|
||||
#define UF_USE_JSON 1
|
||||
#endif
|
||||
#ifndef UF_USE_LUA
|
||||
#define UF_USE_LUA 0
|
||||
#endif
|
||||
#ifndef UF_USE_NCURSES
|
||||
#define UF_USE_NCURSES 1
|
||||
#endif
|
||||
#ifndef UF_USE_OPENGL
|
||||
#define UF_USE_OPENGL 0
|
||||
#endif
|
||||
#ifndef UF_USE_SFML
|
||||
#define UF_USE_SFML 0
|
||||
#endif
|
||||
// Planned
|
||||
#ifndef UF_USE_VULKAN
|
||||
#define UF_USE_VULKAN 0
|
||||
#endif
|
||||
#ifndef UF_USE_DIRECTX
|
||||
#define UF_USE_DIRECTX 0
|
||||
#endif
|
||||
*/
|
||||
#include "simd.h"
|
||||
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
|
||||
#include <uf/engine/object/object.h>
|
||||
#include <uf/utils/math/transform.h>
|
||||
#include <uf/utils/graphic/mesh.h>
|
||||
#include <uf/utils/math/collision.h>
|
||||
|
||||
#if UF_USE_BULLET
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#endif
|
||||
namespace pod {
|
||||
struct UF_API Bullet {
|
||||
size_t uid = 0;
|
||||
@ -17,11 +17,16 @@ namespace pod {
|
||||
pod::Transform<>* transform = NULL;
|
||||
|
||||
bool shared = false; // share control of the transform both in-engine and bullet, set to true if you're directly modifying the transform
|
||||
#if UF_USE_BULLET
|
||||
btRigidBody* body = NULL;
|
||||
btCollisionShape* shape = NULL;
|
||||
#else
|
||||
void* body = NULL;
|
||||
void* shape = NULL;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#if UF_USE_BULLET
|
||||
namespace ext {
|
||||
namespace bullet {
|
||||
extern UF_API bool debugDrawEnabled;
|
||||
@ -74,4 +79,5 @@ namespace ext {
|
||||
}
|
||||
}
|
||||
|
||||
#include "bullet.inl"
|
||||
#include "bullet.inl"
|
||||
#endif
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if defined(UF_USE_FREETYPE)
|
||||
#if UF_USE_FREETYPE
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
@ -14,7 +14,9 @@
|
||||
#error "JSON implementation not defined"
|
||||
#endif
|
||||
|
||||
#include <uf/ext/lua/lua.h>
|
||||
#if UF_USE_LUA
|
||||
#include <uf/ext/lua/lua.h>
|
||||
#endif
|
||||
|
||||
namespace ext {
|
||||
namespace json {
|
||||
@ -36,10 +38,10 @@ namespace ext {
|
||||
void UF_API forEach( const ext::json::Value& json, const std::function<void(size_t, const ext::json::Value&, bool&)>& function );
|
||||
void UF_API forEach( const ext::json::Value& json, const std::function<void(const std::string&, const ext::json::Value&, bool&)>& function );
|
||||
|
||||
std::string UF_API encode( const sol::table& table );
|
||||
std::string UF_API encode( const ext::json::Value& json, bool pretty = true );
|
||||
void UF_API decode( ext::json::Value& json, const std::string& str );
|
||||
#if UF_USE_LUA
|
||||
std::string UF_API encode( const sol::table& table );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#include "json.inl"
|
||||
}
|
||||
@ -89,6 +89,10 @@ template<> inline bool ext::json::Value::is<float>(bool strict) const { return s
|
||||
template<> inline bool ext::json::Value::is<double>(bool strict) const { return strict ? is_number_float() : is_number(); }
|
||||
template<> inline bool ext::json::Value::is<std::string>(bool strict) const { return is_string(); }
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
template<> inline bool ext::json::Value::is<int>(bool strict) const { return strict ? is_number_integer() : is_number(); }
|
||||
template<> inline bool ext::json::Value::is<unsigned int>(bool strict) const { return strict ? is_number_unsigned() : is_number(); }
|
||||
#endif
|
||||
template<typename T> inline T ext::json::Value::as() const {
|
||||
if ( !is<T>() ) return T();
|
||||
return get<T>();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#define SOL_LUAJIT 1
|
||||
#define SOL_USING_CXX_LUA_JIT 1
|
||||
#define SOL_NO_EXCEPTIONS 1
|
||||
@ -42,4 +42,5 @@ namespace ext {
|
||||
}
|
||||
}
|
||||
|
||||
#include "lua.inl"
|
||||
#include "lua.inl"
|
||||
#endif
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if defined(UF_USE_OPENAL)
|
||||
#if UF_USE_OPENAL
|
||||
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
|
||||
@ -10,38 +10,49 @@ namespace ext {
|
||||
struct Device;
|
||||
|
||||
struct UF_API Buffer {
|
||||
GLhandle(VkDevice) device;
|
||||
GLhandle(VkBuffer) buffer = GL_NULL_HANDLE;
|
||||
GLhandle(VkDeviceMemory) memory = GL_NULL_HANDLE;
|
||||
GLhandle(VkDescriptorBufferInfo) descriptor; // = {GL_NULL_HANDLE,0,0};
|
||||
Device* device;
|
||||
void* buffer = GL_NULL_HANDLE;
|
||||
|
||||
struct {
|
||||
void* buffer = NULL;
|
||||
GLsizeiptr offset = 0;
|
||||
GLsizeiptr range = GL_WHOLE_SIZE;
|
||||
} descriptor = {GL_NULL_HANDLE,0,0};
|
||||
|
||||
struct CreateInfo {
|
||||
GLenum flags = 0;
|
||||
GLsizeiptr size = 0;
|
||||
GLenum usage = 0;
|
||||
};
|
||||
|
||||
GLsizeiptr size = 0;
|
||||
GLsizeiptr alignment = 0;
|
||||
void* mapped = nullptr;
|
||||
|
||||
GLhandle(VkBufferUsageFlags) usageFlags;
|
||||
GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags;
|
||||
|
||||
GLhandle(VkMemoryAllocateInfo) memAlloc;
|
||||
GLhandle(VkMemoryRequirements) memReqs;
|
||||
GLenum usageFlags = 0;
|
||||
|
||||
GLhandle(VmaAllocation) allocation;
|
||||
GLhandle(VmaAllocationInfo) allocationInfo;
|
||||
|
||||
GLhandle(VkResult) map( GLsizeiptr size = GL_WHOLE_SIZE, GLsizeiptr offset = 0 );
|
||||
struct AllocationInfo {
|
||||
uint32_t memoryType = 0;
|
||||
GLhandle(VkDeviceMemory) deviceMemory = GL_NULL_HANDLE;
|
||||
GLsizeiptr offset = 0;
|
||||
GLsizeiptr size = 0;
|
||||
void* pMappedData = NULL;
|
||||
void* pUserData = NULL;
|
||||
} allocationInfo;
|
||||
|
||||
bool map( GLsizeiptr size = GL_WHOLE_SIZE, GLsizeiptr offset = 0 );
|
||||
void unmap();
|
||||
|
||||
GLhandle(VkResult) bind( GLsizeiptr offset = 0 );
|
||||
bool bind( GLsizeiptr offset = 0 );
|
||||
|
||||
void setupDescriptor( GLsizeiptr size = GL_WHOLE_SIZE, GLsizeiptr offset = 0 );
|
||||
void copyTo( void* data, GLsizeiptr size );
|
||||
GLhandle(VkResult) flush( GLsizeiptr size = GL_WHOLE_SIZE, GLsizeiptr offset = 0 );
|
||||
GLhandle(VkResult) invalidate( GLsizeiptr size = GL_WHOLE_SIZE, GLsizeiptr offset = 0 );
|
||||
void allocate( GLhandle(VkBufferCreateInfo) );
|
||||
bool flush( GLsizeiptr size = GL_WHOLE_SIZE, GLsizeiptr offset = 0 );
|
||||
bool invalidate( GLsizeiptr size = GL_WHOLE_SIZE, GLsizeiptr offset = 0 );
|
||||
void allocate( const CreateInfo& );
|
||||
|
||||
// RAII
|
||||
~Buffer();
|
||||
void initialize( GLhandle(VkDevice) device );
|
||||
void initialize( Device& device );
|
||||
void destroy();
|
||||
};
|
||||
struct UF_API Buffers {
|
||||
@ -53,9 +64,13 @@ namespace ext {
|
||||
void initialize( Device& device );
|
||||
void destroy();
|
||||
//
|
||||
size_t initializeBuffer( void* data, GLsizeiptr length, GLhandle(VkBufferUsageFlags) usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags = GLenumerator(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), bool stage = GL_DEFAULT_STAGE_BUFFERS );
|
||||
template<typename T> inline size_t initializeBuffer( T data, GLsizeiptr length, GLhandle(VkBufferUsageFlags) usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags = GLenumerator(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), bool stage = GL_DEFAULT_STAGE_BUFFERS ) { return initializeBuffer( (void*) &data, length, usageFlags, memoryPropertyFlags, stage ); }
|
||||
template<typename T> inline size_t initializeBuffer( T data, GLhandle(VkBufferUsageFlags) usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags = GLenumerator(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), bool stage = GL_DEFAULT_STAGE_BUFFERS ) { return initializeBuffer( (void*) &data, static_cast<GLsizeiptr>(sizeof(T)), usageFlags, memoryPropertyFlags, stage ); }
|
||||
size_t initializeBuffer( void* data, GLsizeiptr length, GLenum usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags = GLenumerator(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), bool stage = GL_DEFAULT_STAGE_BUFFERS );
|
||||
template<typename T> inline size_t initializeBuffer( T data, GLsizeiptr length, GLenum usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags = GLenumerator(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), bool stage = GL_DEFAULT_STAGE_BUFFERS ) {
|
||||
return initializeBuffer( (void*) &data, length, usageFlags, memoryPropertyFlags, stage );
|
||||
}
|
||||
template<typename T> inline size_t initializeBuffer( T data, GLenum usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags = GLenumerator(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), bool stage = GL_DEFAULT_STAGE_BUFFERS ) {
|
||||
return initializeBuffer( (void*) &data, static_cast<GLsizeiptr>(sizeof(T)), usageFlags, memoryPropertyFlags, stage );
|
||||
}
|
||||
|
||||
void updateBuffer( void* data, GLsizeiptr length, size_t index = 0, bool stage = GL_DEFAULT_STAGE_BUFFERS );
|
||||
void updateBuffer( void* data, GLsizeiptr length, Buffer& buffer, bool stage = GL_DEFAULT_STAGE_BUFFERS );
|
||||
|
||||
20
engine/inc/uf/ext/opengl/commands.h
Normal file
20
engine/inc/uf/ext/opengl/commands.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/ext/opengl/ogl.h>
|
||||
#include <uf/utils/thread/thread.h>
|
||||
#include <uf/utils/thread/perthread.h>
|
||||
|
||||
namespace ext {
|
||||
namespace opengl {
|
||||
struct UF_API CommandBuffer {
|
||||
typedef std::function<void()> function_t;
|
||||
|
||||
std::vector<CommandBuffer::function_t> commands;
|
||||
|
||||
void record( const CommandBuffer::function_t& );
|
||||
void submit();
|
||||
void flush();
|
||||
size_t size() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -2,15 +2,21 @@
|
||||
|
||||
#include <uf/ext/opengl/ogl.h>
|
||||
#include <uf/ext/opengl/buffer.h>
|
||||
#include <uf/spec/context/context.h>
|
||||
#include <uf/utils/window/window.h>
|
||||
#include <uf/utils/thread/thread.h>
|
||||
#include <uf/utils/thread/perthread.h>
|
||||
|
||||
namespace ext {
|
||||
namespace opengl {
|
||||
class UF_API Device {
|
||||
struct UF_API Device {
|
||||
public:
|
||||
uf::Window* window;
|
||||
spec::Context* context;
|
||||
spec::Context::Settings contextSettings;
|
||||
|
||||
void initialize();
|
||||
void destroy();
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -7,26 +7,26 @@ namespace ext {
|
||||
namespace enums {
|
||||
namespace Compare {
|
||||
typedef GLenum type_t;
|
||||
static const GLenum NEVER = GLenumerator(VK_COMPARE_OP_NEVER);
|
||||
static const GLenum LESS = GLenumerator(VK_COMPARE_OP_LESS);
|
||||
static const GLenum EQUAL = GLenumerator(VK_COMPARE_OP_EQUAL);
|
||||
static const GLenum LESS_OR_EQUAL = GLenumerator(VK_COMPARE_OP_LESS_OR_EQUAL);
|
||||
static const GLenum GREATER = GLenumerator(VK_COMPARE_OP_GREATER);
|
||||
static const GLenum NOT_EQUAL = GLenumerator(VK_COMPARE_OP_NOT_EQUAL);
|
||||
static const GLenum GREATER_OR_EQUAL = GLenumerator(VK_COMPARE_OP_GREATER_OR_EQUAL);
|
||||
static const GLenum ALWAYS = GLenumerator(VK_COMPARE_OP_ALWAYS);
|
||||
static const GLenum NEVER = GL_NEVER;
|
||||
static const GLenum LESS = GL_LESS;
|
||||
static const GLenum EQUAL = GL_EQUAL;
|
||||
static const GLenum LESS_OR_EQUAL = GL_LEQUAL;
|
||||
static const GLenum GREATER = GL_GREATER;
|
||||
static const GLenum NOT_EQUAL = GL_NOTEQUAL;
|
||||
static const GLenum GREATER_OR_EQUAL = GL_GEQUAL;
|
||||
static const GLenum ALWAYS = GL_ALWAYS;
|
||||
}
|
||||
namespace Format {
|
||||
typedef GLenum type_t;
|
||||
static const GLenum D32_SFLOAT = GLenumerator(VK_FORMAT_D32_SFLOAT);
|
||||
static const GLenum R16G16B16A16_SFLOAT = GLenumerator(VK_FORMAT_R16G16B16A16_SFLOAT);
|
||||
static const GLenum R8_UNORM = GLenumerator(VK_FORMAT_R8_UNORM);
|
||||
static const GLenum R32_UINT = GLenumerator(VK_FORMAT_R32_UINT);
|
||||
static const GLenum R32G32_SINT = GLenumerator(VK_FORMAT_R32G32_SINT);
|
||||
static const GLenum R32G32_SFLOAT = GLenumerator(VK_FORMAT_R32G32_SFLOAT);
|
||||
static const GLenum R32G32B32_SFLOAT = GLenumerator(VK_FORMAT_R32G32B32_SFLOAT);
|
||||
static const GLenum R32G32B32A32_SFLOAT = GLenumerator(VK_FORMAT_R32G32B32A32_SFLOAT);
|
||||
static const GLenum R8G8B8A8_UNORM = GLenumerator(VK_FORMAT_R8G8B8A8_UNORM);
|
||||
static const GLenum D32_SFLOAT = 0x00000001; //GLenumerator(VK_FORMAT_D32_SFLOAT);
|
||||
static const GLenum R16G16B16A16_SFLOAT = 0x00000002; //GLenumerator(VK_FORMAT_R16G16B16A16_SFLOAT);
|
||||
static const GLenum R8_UNORM = 0x00000004; //GLenumerator(VK_FORMAT_R8_UNORM);
|
||||
static const GLenum R32_UINT = 0x00000008; //GLenumerator(VK_FORMAT_R32_UINT);
|
||||
static const GLenum R32G32_SINT = 0x00000010; //GLenumerator(VK_FORMAT_R32G32_SINT);
|
||||
static const GLenum R32G32_SFLOAT = 0x00000020; //GLenumerator(VK_FORMAT_R32G32_SFLOAT);
|
||||
static const GLenum R32G32B32_SFLOAT = 0x00000040; //GLenumerator(VK_FORMAT_R32G32B32_SFLOAT);
|
||||
static const GLenum R32G32B32A32_SFLOAT = 0x00000080; //GLenumerator(VK_FORMAT_R32G32B32A32_SFLOAT);
|
||||
static const GLenum R8G8B8A8_UNORM = 0x00000100; //GLenumerator(VK_FORMAT_R8G8B8A8_UNORM);
|
||||
}
|
||||
namespace Face {
|
||||
typedef GLenum type_t;
|
||||
@ -35,21 +35,32 @@ namespace ext {
|
||||
}
|
||||
namespace CullMode {
|
||||
typedef GLenum type_t;
|
||||
static const GLenum NONE = GL_NONE;
|
||||
static const GLenum NONE = 0;
|
||||
static const GLenum FRONT = GL_FRONT;
|
||||
static const GLenum BACK = GL_BACK;
|
||||
static const GLenum BOTH = GL_FRONT_AND_BACK;
|
||||
}
|
||||
namespace Shader {
|
||||
typedef GLenum type_t;
|
||||
static const GLenum VERTEX = GLenumerator(VK_SHADER_STAGE_VERTEX_BIT);
|
||||
static const GLenum TESSELLATION_CONTROL = GLenumerator(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
|
||||
static const GLenum TESSELLATION_EVALUATION = GLenumerator(VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
|
||||
static const GLenum GEOMETRY = GLenumerator(VK_SHADER_STAGE_GEOMETRY_BIT);
|
||||
static const GLenum FRAGMENT = GLenumerator(VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
static const GLenum COMPUTE = GLenumerator(VK_SHADER_STAGE_COMPUTE_BIT);
|
||||
#if UF_ENV_DREAMCAST
|
||||
static const GLenum VERTEX = 0x00000001;
|
||||
static const GLenum TESSELLATION_CONTROL = 0x00000002;
|
||||
static const GLenum TESSELLATION_EVALUATION = 0x00000003;
|
||||
static const GLenum GEOMETRY = 0x00000004;
|
||||
static const GLenum FRAGMENT = 0x00000005;
|
||||
static const GLenum COMPUTE = 0x00000006;
|
||||
static const GLenum ALL_GRAPHICS = 0x00000007;
|
||||
static const GLenum ALL = 0x00000008;
|
||||
#else
|
||||
static const GLenum VERTEX = GL_VERTEX_SHADER;
|
||||
static const GLenum TESSELLATION_CONTROL = GL_TESS_CONTROL_SHADER;
|
||||
static const GLenum TESSELLATION_EVALUATION = GL_TESS_EVALUATION_SHADER;
|
||||
static const GLenum GEOMETRY = GL_GEOMETRY_SHADER;
|
||||
static const GLenum FRAGMENT = GL_FRAGMENT_SHADER;
|
||||
static const GLenum COMPUTE = GL_COMPUTE_SHADER;
|
||||
static const GLenum ALL_GRAPHICS = GLenumerator(VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
static const GLenum ALL = GLenumerator(VK_SHADER_STAGE_ALL);
|
||||
#endif
|
||||
}
|
||||
namespace PrimitiveTopology {
|
||||
typedef GLenum type_t;
|
||||
@ -85,15 +96,15 @@ namespace ext {
|
||||
}
|
||||
namespace Buffer {
|
||||
typedef GLenum type_t;
|
||||
static const GLenum TRANSFER_SRC = GLenumerator(VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||
static const GLenum TRANSFER_DST = GLenumerator(VK_BUFFER_USAGE_TRANSFER_DST_BIT);
|
||||
static const GLenum UNIFORM_TEXEL = GLenumerator(VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT);
|
||||
static const GLenum STORAGE_TEXEL = GLenumerator(VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT);
|
||||
static const GLenum UNIFORM = GLenumerator(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
|
||||
static const GLenum STORAGE = GLenumerator(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
|
||||
static const GLenum INDEX = GLenumerator(VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
|
||||
static const GLenum VERTEX = GLenumerator(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
|
||||
static const GLenum INDIRECT = GLenumerator(VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT);
|
||||
static const GLenum TRANSFER_SRC = 0x00000001;
|
||||
static const GLenum TRANSFER_DST = 0x00000002;
|
||||
static const GLenum UNIFORM_TEXEL = 0x00000004;
|
||||
static const GLenum STORAGE_TEXEL = 0x00000008;
|
||||
static const GLenum UNIFORM = 0x00000010;
|
||||
static const GLenum STORAGE = 0x00000020;
|
||||
static const GLenum INDEX = 0x00000040;
|
||||
static const GLenum VERTEX = 0x00000080;
|
||||
static const GLenum INDIRECT = 0x00000100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <uf/ext/opengl/swapchain.h>
|
||||
#include <uf/ext/opengl/initializers.h>
|
||||
#include <uf/ext/opengl/texture.h>
|
||||
#include <uf/ext/opengl/commands.h>
|
||||
#include <uf/utils/graphic/mesh.h>
|
||||
#include <uf/utils/graphic/descriptor.h>
|
||||
|
||||
@ -82,7 +83,7 @@ namespace ext {
|
||||
void initialize( Graphic& graphic, GraphicDescriptor& descriptor );
|
||||
void update( Graphic& graphic );
|
||||
void update( Graphic& graphic, GraphicDescriptor& descriptor );
|
||||
void record( Graphic& graphic, GLhandle(VkCommandBuffer), size_t = 0, size_t = 0 );
|
||||
void record( Graphic& graphic, CommandBuffer&, size_t = 0, size_t = 0 );
|
||||
void destroy();
|
||||
};
|
||||
struct UF_API Material {
|
||||
@ -127,8 +128,8 @@ namespace ext {
|
||||
Pipeline& getPipeline( GraphicDescriptor& descriptor );
|
||||
void updatePipelines();
|
||||
|
||||
void record( GLhandle(VkCommandBuffer) commandBuffer, size_t pass = 0, size_t draw = 0 );
|
||||
void record( GLhandle(VkCommandBuffer) commandBuffer, GraphicDescriptor& descriptor, size_t pass = 0, size_t draw = 0 );
|
||||
void record( CommandBuffer& commandBuffer, size_t pass = 0, size_t draw = 0 );
|
||||
void record( CommandBuffer& commandBuffer, GraphicDescriptor& descriptor, size_t pass = 0, size_t draw = 0 );
|
||||
|
||||
bool hasStorage( const std::string& name );
|
||||
Buffer* getStorageBuffer( const std::string& name );
|
||||
|
||||
@ -12,8 +12,8 @@ void ext::opengl::Graphic::initializeGeometry( uf::BaseMesh<T, U>& mesh, size_t
|
||||
int32_t vertexBuffer = -1;
|
||||
int32_t indexBuffer = -1;
|
||||
for ( size_t i = 0; i < buffers.size(); ++i ) {
|
||||
if ( buffers[i].usageFlags & 1 ) vertexBuffer = i;
|
||||
if ( buffers[i].usageFlags & 2 ) indexBuffer = i;
|
||||
if ( buffers[i].usageFlags & uf::renderer::enums::Buffer::VERTEX ) vertexBuffer = i;
|
||||
if ( buffers[i].usageFlags & uf::renderer::enums::Buffer::INDEX ) indexBuffer = i;
|
||||
}
|
||||
|
||||
if ( vertexBuffer > 0 && indexBuffer > 0 ) {
|
||||
@ -31,10 +31,12 @@ void ext::opengl::Graphic::initializeGeometry( uf::BaseMesh<T, U>& mesh, size_t
|
||||
}
|
||||
}
|
||||
// can't reuse buffers, re-create buffers
|
||||
/*
|
||||
{
|
||||
for ( auto& buffer : buffers ) buffer.destroy();
|
||||
buffers.clear();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
descriptor.geometry = mesh;
|
||||
@ -43,11 +45,11 @@ void ext::opengl::Graphic::initializeGeometry( uf::BaseMesh<T, U>& mesh, size_t
|
||||
initializeBuffer(
|
||||
(void*) mesh.vertices.data(),
|
||||
mesh.vertices.size() * mesh.sizes.vertex,
|
||||
/*VK_BUFFER_USAGE_VERTEX_BUFFER_BIT*/ 1
|
||||
uf::renderer::enums::Buffer::VERTEX
|
||||
);
|
||||
initializeBuffer(
|
||||
(void*) mesh.indices.data(),
|
||||
mesh.indices.size() * mesh.sizes.indices,
|
||||
/*VK_BUFFER_USAGE_INDEX_BUFFER_BIT*/ 2
|
||||
uf::renderer::enums::Buffer::INDEX
|
||||
);
|
||||
}
|
||||
@ -1,25 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#include <GL/glew.h>
|
||||
#if defined(UF_ENV_WINDOWS)
|
||||
// The Visual C++ version of gl.h uses WINGDIAPI and APIENTRY but doesn't define them
|
||||
#ifdef _MSC_VER
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/wglext.h>
|
||||
#include <GL/glext.h>
|
||||
#elif defined(UF_ENV_LINUX) || defined(UF_ENV_FREEBSD)
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#elif defined(UF_ENV_MACOS)
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glu.h>
|
||||
#elif defined(UF_ENV_DREAMCAST)
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glkos.h>
|
||||
|
||||
#define GL_NONE 0
|
||||
#define GLsizeiptr GLsizei
|
||||
#endif
|
||||
#include <GL/glext.h>
|
||||
|
||||
#define GL_NULL_HANDLE NULL
|
||||
#define GL_WHOLE_SIZE -1
|
||||
#define GLhandle(x) size_t
|
||||
#define GLenumerator(x) 0
|
||||
#define GLenumerator(x) 0
|
||||
|
||||
#define GL_DEBUG_MESSAGE(...)\
|
||||
uf::iostream << "[" << __FUNCTION__ << "@" << __FILE__ ":" << __LINE__ << "] " << __VA_ARGS__ << "\n"
|
||||
|
||||
#define GL_VALIDATION_MESSAGE(...)\
|
||||
if ( ext::opengl::settings::validation ) GL_DEBUG_MESSAGE(__VA_ARGS__);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/ext/opengl/device.h>
|
||||
#include <uf/ext/opengl/commands.h>
|
||||
#include <uf/utils/graphic/descriptor.h>
|
||||
|
||||
namespace ext {
|
||||
@ -20,7 +21,7 @@ namespace ext {
|
||||
GLhandle(VkSemaphore) renderCompleteSemaphore;
|
||||
std::vector<GLhandle(VkFence)> fences;
|
||||
|
||||
typedef std::vector<GLhandle(VkCommandBuffer)> commands_container_t;
|
||||
typedef CommandBuffer commands_container_t;
|
||||
std::thread::id mostRecentCommandPoolId;
|
||||
uf::ThreadUnique<commands_container_t> commands;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
namespace ext {
|
||||
namespace opengl {
|
||||
struct UF_API BaseRenderMode : RenderMode {
|
||||
struct UF_API BaseRenderMode : public RenderMode {
|
||||
// virtual ~RenderMode();
|
||||
// RAII
|
||||
virtual const std::string getType() const;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
namespace ext {
|
||||
namespace opengl {
|
||||
struct UF_API ComputeRenderMode : RenderMode {
|
||||
struct UF_API ComputeRenderMode : public RenderMode {
|
||||
ext::opengl::Graphic blitter, compute;
|
||||
pod::Vector2ui dispatchSize = { 32, 32 };
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
namespace ext {
|
||||
namespace opengl {
|
||||
struct UF_API DeferredRenderMode : RenderMode {
|
||||
struct UF_API DeferredRenderMode : public RenderMode {
|
||||
ext::opengl::Graphic blitter;
|
||||
|
||||
// RAII
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
namespace ext {
|
||||
namespace opengl {
|
||||
struct UF_API RenderTargetRenderMode : RenderMode {
|
||||
struct UF_API RenderTargetRenderMode : public RenderMode {
|
||||
ext::opengl::Graphic blitter;
|
||||
//
|
||||
const std::string getTarget() const;
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
|
||||
#if UF_USE_OPENVR
|
||||
#include <uf/utils/math/matrix.h>
|
||||
#include <uf/utils/math/quaternion.h>
|
||||
#include <uf/utils/graphic/graphic.h>
|
||||
#include <uf/utils/serialize/serializer.h>
|
||||
|
||||
#ifdef USE_OPENVR_MINGW
|
||||
#include <openvr/openvr_mingw.hpp>
|
||||
#else
|
||||
@ -77,4 +80,5 @@ namespace ext {
|
||||
pod::Matrix4t<> UF_API eyeMatrix( vr::Hmd_Eye );
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_USE_ULTRALIGHT
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <uf/utils/math/vector.h>
|
||||
#include <uf/utils/image/image.h>
|
||||
#include <uf/utils/string/io.h>
|
||||
|
||||
#include <Ultralight/CAPI.h>
|
||||
|
||||
@ -41,4 +43,5 @@ namespace ext {
|
||||
void UF_API input( pod::HTML&, const std::string& );
|
||||
uf::Image UF_API capture( pod::HTML& );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if defined(UF_USE_VORBIS)
|
||||
#if UF_USE_VORBIS
|
||||
|
||||
#include <vorbis/vorbisfile.h>
|
||||
|
||||
|
||||
@ -12,8 +12,8 @@ void ext::vulkan::Graphic::initializeGeometry( uf::BaseMesh<T, U>& mesh, size_t
|
||||
int32_t vertexBuffer = -1;
|
||||
int32_t indexBuffer = -1;
|
||||
for ( size_t i = 0; i < buffers.size(); ++i ) {
|
||||
if ( buffers[i].usageFlags & VK_BUFFER_USAGE_VERTEX_BUFFER_BIT ) vertexBuffer = i;
|
||||
if ( buffers[i].usageFlags & VK_BUFFER_USAGE_INDEX_BUFFER_BIT ) indexBuffer = i;
|
||||
if ( buffers[i].usageFlags & uf::renderer::enums::Buffer::VERTEX ) vertexBuffer = i;
|
||||
if ( buffers[i].usageFlags & uf::renderer::enums::Buffer::INDEX ) indexBuffer = i;
|
||||
}
|
||||
|
||||
if ( vertexBuffer > 0 && indexBuffer > 0 ) {
|
||||
@ -31,10 +31,12 @@ void ext::vulkan::Graphic::initializeGeometry( uf::BaseMesh<T, U>& mesh, size_t
|
||||
}
|
||||
}
|
||||
// can't reuse buffers, re-create buffers
|
||||
/*
|
||||
{
|
||||
for ( auto& buffer : buffers ) buffer.destroy();
|
||||
buffers.clear();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
descriptor.geometry = mesh;
|
||||
@ -43,11 +45,11 @@ void ext::vulkan::Graphic::initializeGeometry( uf::BaseMesh<T, U>& mesh, size_t
|
||||
initializeBuffer(
|
||||
(void*) mesh.vertices.data(),
|
||||
mesh.vertices.size() * mesh.sizes.vertex,
|
||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
|
||||
uf::renderer::enums::Buffer::VERTEX
|
||||
);
|
||||
initializeBuffer(
|
||||
(void*) mesh.indices.data(),
|
||||
mesh.indices.size() * mesh.sizes.indices,
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT
|
||||
uf::renderer::enums::Buffer::INDEX
|
||||
);
|
||||
}
|
||||
@ -16,4 +16,5 @@
|
||||
if ( __VA_ARGS__ (time = TOKEN_PASTE(TIMER, __LINE__)(x)) >= x )
|
||||
|
||||
#define UF_DEBUG 1
|
||||
#define UF_DEBUG_PRINT() if ( UF_DEBUG ) uf::iostream << __FILE__ << ":" << __FUNCTION__ << "@" << __LINE__ << "\n";
|
||||
//#define UF_DEBUG_PRINT() if ( UF_DEBUG ) uf::iostream << __FILE__ << ":" << __FUNCTION__ << "@" << __LINE__ << "\n";
|
||||
#define UF_DEBUG_PRINT() if ( UF_DEBUG ) std::cout << __FILE__ << ":" << __FUNCTION__ << "@" << __LINE__ << std::endl;
|
||||
@ -6,8 +6,4 @@
|
||||
// include universal
|
||||
#include "universal.h"
|
||||
// defines which implementation to use
|
||||
#include UF_ENV_HEADER
|
||||
|
||||
#if UF_USE_SFML
|
||||
#include "unknown.h"
|
||||
#endif
|
||||
#include UF_ENV_HEADER
|
||||
8
engine/inc/uf/spec/context/dreamcast.h
Normal file
8
engine/inc/uf/spec/context/dreamcast.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "universal.h"
|
||||
#include "unknown.h"
|
||||
|
||||
namespace spec {
|
||||
typedef spec::unknown::Context Context;
|
||||
}
|
||||
@ -22,23 +22,12 @@ namespace spec {
|
||||
typedef spec::Window window_t;
|
||||
#endif
|
||||
struct Settings {
|
||||
unsigned int depthBits;
|
||||
unsigned int stencilBits;
|
||||
unsigned int bitsPerPixel;
|
||||
unsigned int antialiasingLevel;
|
||||
unsigned int majorVersion;
|
||||
unsigned int minorVersion;
|
||||
|
||||
explicit Settings(unsigned int depth = 24, unsigned int stencil = 4, unsigned int antialiasing = 0, unsigned int bitsPerPixel = 8, unsigned int major = 2, unsigned int minor = 0) :
|
||||
depthBits (depth),
|
||||
stencilBits (stencil),
|
||||
bitsPerPixel (bitsPerPixel),
|
||||
antialiasingLevel (antialiasing),
|
||||
majorVersion (major),
|
||||
minorVersion (minor)
|
||||
{
|
||||
|
||||
}
|
||||
uint32_t depthBits = 24;
|
||||
uint32_t stencilBits = 4;
|
||||
uint32_t bitsPerPixel = 8;
|
||||
uint32_t antialiasingLevel = 0;
|
||||
uint32_t majorVersion = 2;
|
||||
uint32_t minorVersion = 0;
|
||||
};
|
||||
protected:
|
||||
Context::window_t::handle_t m_window;
|
||||
|
||||
11
engine/inc/uf/spec/dreamcast.h
Normal file
11
engine/inc/uf/spec/dreamcast.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
// In the event some fool includes this file directly
|
||||
#include "universal.h"
|
||||
// Windows-specific stuffs
|
||||
#ifdef UF_ENV_DREAMCAST
|
||||
|
||||
// Headers
|
||||
|
||||
#endif
|
||||
19
engine/inc/uf/spec/time/dreamcast.h
Normal file
19
engine/inc/uf/spec/time/dreamcast.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#include "universal.h"
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
|
||||
namespace spec {
|
||||
namespace dreamcast {
|
||||
class UF_API Time : public spec::uni::Time {
|
||||
public:
|
||||
static Time::exp_t unit;
|
||||
};
|
||||
}
|
||||
typedef dreamcast::Time Time;
|
||||
extern UF_API Time time;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -28,7 +28,6 @@
|
||||
#endif
|
||||
|
||||
*/
|
||||
|
||||
#include UF_ENV_HEADER
|
||||
|
||||
// define some universal shit
|
||||
|
||||
72
engine/inc/uf/spec/window/dreamcast.h
Normal file
72
engine/inc/uf/spec/window/dreamcast.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#include "universal.h"
|
||||
#include <kos.h>
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
namespace spec {
|
||||
namespace dreamcast {
|
||||
class UF_API Window : public spec::uni::Window {
|
||||
public:
|
||||
typedef size_t handle_t;
|
||||
protected:
|
||||
spec::dreamcast::Window::handle_t m_handle;
|
||||
// size_t m_cursor;
|
||||
// size_t m_icon;
|
||||
|
||||
spec::dreamcast::Window::vector_t m_lastSize;
|
||||
bool m_keyRepeatEnabled;
|
||||
bool m_resizing;
|
||||
bool m_mouseInside;
|
||||
bool m_mouseGrabbed;
|
||||
uint16_t m_surrogate;
|
||||
bool m_syncParse;
|
||||
bool m_asyncParse;
|
||||
public:
|
||||
// C-tors
|
||||
UF_API Window();
|
||||
UF_API Window( spec::dreamcast::Window::handle_t );
|
||||
UF_API Window( const spec::dreamcast::Window::vector_t& size, const spec::dreamcast::Window::title_t& title = L"Window" );
|
||||
/*virtual*/ void UF_API create( const spec::dreamcast::Window::vector_t& size, const spec::dreamcast::Window::title_t& title = L"Window" );
|
||||
// D-tors
|
||||
/*virtual*/ ~Window();
|
||||
void UF_API terminate();
|
||||
// Gets
|
||||
spec::dreamcast::Window::handle_t UF_API getHandle() const;
|
||||
/*virtual*/ spec::dreamcast::Window::vector_t UF_API getPosition() const;
|
||||
/*virtual*/ spec::dreamcast::Window::vector_t UF_API getSize() const;
|
||||
/*virtual*/ size_t UF_API getRefreshRate() const;
|
||||
// Attribute modifiers
|
||||
/*virtual*/ void UF_API setPosition( const spec::dreamcast::Window::vector_t& position );
|
||||
/*virtual*/ void UF_API centerWindow();
|
||||
/*virtual*/ void UF_API setMousePosition( const spec::dreamcast::Window::vector_t& position );
|
||||
/*virtual*/ spec::dreamcast::Window::vector_t UF_API getMousePosition();
|
||||
/*virtual*/ void UF_API setSize( const spec::dreamcast::Window::vector_t& size );
|
||||
/*virtual*/ void UF_API setTitle( const spec::dreamcast::Window::title_t& title );
|
||||
/*virtual*/ void UF_API setIcon( const spec::dreamcast::Window::vector_t& size, uint8_t* pixels );
|
||||
/*virtual*/ void UF_API setVisible( bool visibility );
|
||||
/*virtual*/ void UF_API setCursorVisible( bool visibility );
|
||||
/*virtual*/ void UF_API setKeyRepeatEnabled( bool state );
|
||||
/*virtual*/ void UF_API setMouseGrabbed(bool state);
|
||||
|
||||
/*virtual*/ void UF_API requestFocus();
|
||||
/*virtual*/ bool UF_API hasFocus() const;
|
||||
// Update
|
||||
/*virtual*/ void UF_API processEvents();
|
||||
static /*virtual*/ bool UF_API isKeyPressed(const std::string&);
|
||||
bool UF_API pollEvents( bool block = false );
|
||||
// Win32 specific functions
|
||||
void UF_API registerWindowClass();
|
||||
void UF_API processEvent(/*UINT message, WPARAM wParam, LPARAM lParam*/);
|
||||
void UF_API grabMouse(bool state);
|
||||
|
||||
void UF_API setTracking(bool state);
|
||||
static pod::Vector2ui UF_API getResolution();
|
||||
void UF_API switchToFullscreen( bool borderless = false );
|
||||
static std::string UF_API getKey(/*WPARAM key, LPARAM flags*/);
|
||||
};
|
||||
}
|
||||
typedef spec::dreamcast::Window Window;
|
||||
}
|
||||
#endif
|
||||
@ -2,9 +2,17 @@
|
||||
|
||||
#include <uf/config.h>
|
||||
|
||||
#if defined(UF_USE_OPENAL)
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
#include <uf/ext/oal/oal.h>
|
||||
#else
|
||||
namespace ext {
|
||||
namespace al {
|
||||
typedef size_t Source;
|
||||
typedef size_t Buffer;
|
||||
}
|
||||
}
|
||||
typedef float ALfloat;
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
@ -99,6 +107,4 @@ namespace uf {
|
||||
|
||||
void cleanup( bool = false );
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -13,6 +13,7 @@ namespace ext {
|
||||
struct /*UF_API*/ VertexDescriptor {
|
||||
ext::RENDERER::enums::Format::type_t format; // VK_FORMAT_R32G32B32_SFLOAT
|
||||
size_t offset; // offsetof(Vertex, position)
|
||||
std::string name;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -68,4 +69,13 @@ namespace ext {
|
||||
}
|
||||
}
|
||||
|
||||
#undef UF_RENDERER
|
||||
#undef UF_RENDERER
|
||||
#define UF_VERTEX_DESCRIPTION( TYPE, FORMAT, ATTRIBUTE ) {\
|
||||
uf::renderer::enums::Format::FORMAT,\
|
||||
offsetof(TYPE, ATTRIBUTE),\
|
||||
#ATTRIBUTE\
|
||||
},
|
||||
|
||||
#define UF_VERTEX_DESCRIPTOR( TYPE, ... )\
|
||||
std::vector<uf::renderer::VertexDescriptor> TYPE::descriptor = { __VA_ARGS__ };
|
||||
|
||||
@ -6,7 +6,10 @@
|
||||
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
||||
#if UF_USE_MESHOPTIMIZER
|
||||
#include <meshoptimizer.h>
|
||||
#endif
|
||||
|
||||
#if UF_USE_VULKAN
|
||||
namespace uf {
|
||||
|
||||
@ -78,6 +78,7 @@ uf::BaseMesh<T,U> uf::BaseMesh<T,U>::simplify( float threshold ) {
|
||||
}
|
||||
template<typename T, typename U>
|
||||
void uf::BaseMesh<T,U>::optimize( size_t o ) {
|
||||
#if UF_USE_MESHOPTIMIZER
|
||||
// generate indices
|
||||
auto vertices = std::move( this->vertices );
|
||||
U indices = vertices.size();
|
||||
@ -102,6 +103,11 @@ void uf::BaseMesh<T,U>::optimize( size_t o ) {
|
||||
if ( o >= 3 ) {
|
||||
meshopt_optimizeVertexFetch(&this->vertices[0], &this->indices[0], this->indices.size(), &this->vertices[0], this->vertices.size(), sizeof(T));
|
||||
}
|
||||
#else
|
||||
this->indices.clear();
|
||||
this->indices.reserve(vertices.size());
|
||||
for ( size_t i = 0; i < vertices.size(); ++i )
|
||||
this->indices.emplace_back(i);
|
||||
/*
|
||||
old nasty way
|
||||
|
||||
@ -119,4 +125,5 @@ void uf::BaseMesh<T,U>::optimize( size_t o ) {
|
||||
mesh.indices.push_back( unique[vertex] );
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
@ -18,7 +18,9 @@ namespace uf {
|
||||
Serializer( const std::string& str = "{}" );
|
||||
Serializer( const ext::json::base_value& );
|
||||
Serializer( const ext::json::Value& );
|
||||
#if UF_USE_LUA
|
||||
Serializer( const sol::table& );
|
||||
#endif
|
||||
|
||||
Serializer::output_t serialize( bool pretty = false ) const;
|
||||
void deserialize( const std::string& );
|
||||
@ -69,7 +71,9 @@ namespace uf {
|
||||
uf::Serializer& operator=( const std::string& str );
|
||||
uf::Serializer& operator=( const ext::json::base_value& json );
|
||||
uf::Serializer& operator=( const ext::json::Value& json );
|
||||
#if UF_USE_LUA
|
||||
uf::Serializer& operator=( const sol::table& json );
|
||||
#endif
|
||||
uf::Serializer& operator<<( const std::string& str );
|
||||
uf::Serializer& operator>>( std::string& str );
|
||||
const uf::Serializer& operator>>( std::string& str ) const;
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
|
||||
namespace uf {
|
||||
namespace io {
|
||||
extern UF_API const std::string root;
|
||||
|
||||
std::string UF_API absolute( const std::string& );
|
||||
std::string UF_API filename( const std::string& );
|
||||
std::string UF_API extension( const std::string& );
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
|
||||
#if UF_USE_FREETYPE
|
||||
#include <vector>
|
||||
|
||||
#include <uf/utils/math/vector.h>
|
||||
@ -47,4 +47,5 @@ namespace uf {
|
||||
void useSdf( bool = true );
|
||||
void setSpread( int );
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -39,7 +39,11 @@ pod::Userdata* uf::userdata::create( uf::MemoryPool& requestedMemoryPool, const
|
||||
#include <stdexcept>
|
||||
template<typename T>
|
||||
T& uf::userdata::get( pod::Userdata* userdata, bool validate ) {
|
||||
if ( validate && !uf::userdata::is<T>( userdata ) ) throw std::logic_error("Userdata size|type mismatch");
|
||||
#if !UF_NO_EXCEPTIONS
|
||||
if ( validate && !uf::userdata::is<T>( userdata ) ) {
|
||||
throw std::logic_error("Userdata size|type mismatch");
|
||||
}
|
||||
#endif
|
||||
union {
|
||||
uint8_t* original;
|
||||
T* casted;
|
||||
@ -49,7 +53,11 @@ T& uf::userdata::get( pod::Userdata* userdata, bool validate ) {
|
||||
}
|
||||
template<typename T>
|
||||
const T& uf::userdata::get( const pod::Userdata* userdata, bool validate ) {
|
||||
if ( validate && !uf::userdata::is<T>( userdata ) ) throw std::logic_error("Userdata size|type mismatch");
|
||||
#if !UF_NO_EXCEPTIONS
|
||||
if ( validate && !uf::userdata::is<T>( userdata ) ) {
|
||||
throw std::logic_error("Userdata size|type mismatch");
|
||||
}
|
||||
#endif
|
||||
union {
|
||||
const uint8_t* original;
|
||||
const T* casted;
|
||||
|
||||
@ -53,6 +53,8 @@ namespace uf {
|
||||
/*virtual*/ bool UF_API_CALL pollEvents(bool block = false);
|
||||
/*virtual*/ bool UF_API_CALL setActive( bool active = true );
|
||||
/*virtual*/ void UF_API_CALL display();
|
||||
/*virtual*/ Window::window_t* UF_API_CALL getHandle();
|
||||
/*virtual*/ const Window::window_t* UF_API_CALL getHandle() const;
|
||||
};
|
||||
}
|
||||
#elif UF_USE_SFML
|
||||
|
||||
@ -99,7 +99,7 @@ std::string uf::Asset::cache( const std::string& uri, const std::string& hash )
|
||||
std::string extension = uf::io::extension( uri );
|
||||
if ( uri.substr(0,5) == "https" ) {
|
||||
std::string hash = hashed( uri );
|
||||
std::string cached = "./data/cache/" + hash + "." + extension;
|
||||
std::string cached = uf::io::root + "/cache/" + hash + "." + extension;
|
||||
if ( !uf::io::exists( cached ) && !retrieve( uri, cached, hash ) ) {
|
||||
uf::iostream << "Failed to preload `" + uri + "` (`" + cached + "`): HTTP error" << "\n";
|
||||
return "";
|
||||
@ -122,7 +122,7 @@ std::string uf::Asset::load( const std::string& uri, const std::string& hash ) {
|
||||
std::string extension = uf::io::extension( uri );
|
||||
if ( uri.substr(0,5) == "https" ) {
|
||||
std::string hash = hashed( uri );
|
||||
std::string cached = "./data/cache/" + hash + "." + extension;
|
||||
std::string cached = uf::io::root + "/cache/" + hash + "." + extension;
|
||||
if ( !uf::io::exists( cached ) && !retrieve( uri, cached, hash ) ) {
|
||||
uf::iostream << "Failed to load `" + uri + "` (`" + cached + "`): HTTP error" << "\n";
|
||||
return "";
|
||||
@ -158,9 +158,11 @@ std::string uf::Asset::load( const std::string& uri, const std::string& hash ) {
|
||||
} else if ( extension == "json" ) {
|
||||
UF_ASSET_REGISTER(uf::Serializer)
|
||||
asset.readFromFile(filename);
|
||||
#if UF_USE_LUA
|
||||
} else if ( extension == "lua" ) {
|
||||
UF_ASSET_REGISTER(pod::LuaScript)
|
||||
asset = ext::lua::script( filename );
|
||||
#endif
|
||||
} else if ( extension == "gltf" || extension == "glb" ) {
|
||||
UF_ASSET_REGISTER(pod::Graph)
|
||||
auto& metadata = this->getComponent<uf::Serializer>();
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#include <iostream>
|
||||
|
||||
//std::string uf::MasterData::root = "https://el..xyz/mastertable/get/%TABLE%/%KEY%?.json";
|
||||
std::string uf::MasterData::root = "./data/master/%TABLE%.json";
|
||||
std::string uf::MasterData::root = uf::io::root + "/master/%TABLE%.json";
|
||||
uf::Asset uf::MasterData::assetLoader;
|
||||
|
||||
uf::Serializer uf::MasterData::load( const std::string& table, size_t key ) {
|
||||
|
||||
@ -33,6 +33,7 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) {
|
||||
}
|
||||
}
|
||||
|
||||
#if UF_USE_BULLET
|
||||
if ( ext::json::isObject(metadata["system"]["physics"]) ) {
|
||||
float mass = metadata["system"]["physics"]["mass"].as<float>();
|
||||
if ( metadata["system"]["physics"]["type"].as<std::string>() == "BoundingBox" ) {
|
||||
@ -58,6 +59,7 @@ void uf::ObjectBehavior::initialize( uf::Object& self ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
this->addHook( "object:TransformReferenceController.%UID%", [&](ext::json::Value& json){
|
||||
auto& transform = this->getComponent<pod::Transform<>>();
|
||||
|
||||
@ -42,7 +42,11 @@ void uf::GltfBehavior::initialize( uf::Object& self ) {
|
||||
|
||||
{
|
||||
pod::Graph* graphPointer = NULL;
|
||||
#if UF_NO_EXCEPTIONS
|
||||
graphPointer = &assetLoader.get<pod::Graph>(filename);
|
||||
#else
|
||||
try { graphPointer = &assetLoader.get<pod::Graph>(filename); } catch ( ... ) {}
|
||||
#endif
|
||||
if ( !graphPointer ) return;
|
||||
auto& graph = this->getComponent<pod::Graph>();
|
||||
graph = std::move( *graphPointer );
|
||||
@ -98,15 +102,19 @@ void uf::GltfBehavior::initialize( uf::Object& self ) {
|
||||
auto& scene = uf::scene::getCurrentScene();
|
||||
auto& assetLoader = scene.getComponent<uf::Asset>();
|
||||
const uf::Image* imagePointer = NULL;
|
||||
#if UF_NO_EXCEPTIONS
|
||||
imagePointer = &assetLoader.get<uf::Image>(filename);
|
||||
#else
|
||||
try { imagePointer = &assetLoader.get<uf::Image>(filename); } catch ( ... ) {}
|
||||
#endif
|
||||
if ( !imagePointer ) continue;
|
||||
uf::Image image = *imagePointer;
|
||||
auto& texture = graphic.material.textures.emplace_back();
|
||||
texture.loadFromImage( image );
|
||||
}
|
||||
#if UF_USE_VULKAN
|
||||
graphic.process = true;
|
||||
|
||||
#if UF_USE_VULKAN
|
||||
{
|
||||
auto& shader = graphic.material.getShader("vertex");
|
||||
struct SpecializationConstant {
|
||||
|
||||
@ -12,10 +12,10 @@
|
||||
#include <uf/engine/asset/asset.h>
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
|
||||
UF_BEHAVIOR_REGISTER_CPP(uf::LuaBehavior)
|
||||
#define this (&self)
|
||||
void uf::LuaBehavior::initialize( uf::Object& self ) {
|
||||
#if UF_USE_LUA
|
||||
this->addHook( "asset:Load.%UID%", [&](ext::json::Value& json){
|
||||
std::string filename = json["filename"].as<std::string>();
|
||||
|
||||
@ -32,6 +32,7 @@ void uf::LuaBehavior::initialize( uf::Object& self ) {
|
||||
|
||||
return;
|
||||
});
|
||||
#endif
|
||||
}
|
||||
void uf::LuaBehavior::destroy( uf::Object& self ) {
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include <uf/ext/bullet/bullet.h>
|
||||
#if UF_USE_BULLET
|
||||
|
||||
#include <uf/utils/math/physics.h>
|
||||
#include <uf/utils/renderer/renderer.h>
|
||||
@ -72,78 +73,8 @@ namespace ext {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
static bool fixMeshNormal( btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, int partId0, int index0 ) {
|
||||
const btTriangleShape* tri_shape = static_cast<const btTriangleShape*>(colObj0Wrap->getCollisionShape());
|
||||
btVector3 tri_normal;
|
||||
tri_shape->calcNormal(cp.m_normalWorldOnB);
|
||||
cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis() * cp.m_normalWorldOnB;
|
||||
|
||||
// Reproject collision point along normal.
|
||||
cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
|
||||
cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
|
||||
return true;
|
||||
}
|
||||
|
||||
btScalar SegmentSqrDistance(const btVector3& from, const btVector3& to,const btVector3 &p) {
|
||||
btVector3 diff = p - from;
|
||||
btVector3 v = to - from;
|
||||
btScalar t = v.dot(diff);
|
||||
if (t > 0) {
|
||||
btScalar dotVV = v.dot(v);
|
||||
if (t < dotVV) diff -= (t / dotVV) * v;
|
||||
else diff -= v;
|
||||
}
|
||||
return diff.dot(diff);
|
||||
}
|
||||
|
||||
bool ProcessHeightfieldCollision(btManifoldPoint& cp, btVector3& cppos, btHeightfieldTerrainShape* heightfield_shape, btTriangleShape* triangle_shape, int part_id, int index) {
|
||||
// This can be classified as an edge collision if the contact normal differs from the triangle normal
|
||||
btVector3 triangle_normal;
|
||||
triangle_shape->calcNormal(triangle_normal);
|
||||
if (cp.m_normalWorldOnB.dot(triangle_normal) < 1 - SIMD_EPSILON) {
|
||||
// Need to find the edge that matches this contact normal
|
||||
int ev0 = -1, ev1 = -1;
|
||||
btVector3* vertices = &triangle_shape->getVertexPtr(0);
|
||||
for (int v0 = 2, v1 = 0; v1 < 3; v0 = v1, v1++) {
|
||||
float d = SegmentSqrDistance(vertices[v0], vertices[v1], cppos);
|
||||
if (d < SIMD_EPSILON) {
|
||||
ev0 = v0;
|
||||
ev1 = v1;
|
||||
}
|
||||
}
|
||||
|
||||
// Leave contact point alone if the edge can't be found
|
||||
if (ev0 == -1) return true;
|
||||
|
||||
// Get the triangle that shares this edge. If this is a boundary edge, the contact normal is
|
||||
// perfectly valid
|
||||
btVector3 neighbour_vertices[3];
|
||||
if (!heightfield_shape->getNeighbourTriangle(part_id, index, ev0, neighbour_vertices)) return true;
|
||||
|
||||
// If the two faces have similar normals, use the face normal and ignore the edge normal
|
||||
btVector3 other_normal = (neighbour_vertices[1]-neighbour_vertices[0]).cross(neighbour_vertices[2]-neighbour_vertices[0]);
|
||||
other_normal.normalize();
|
||||
if (triangle_normal.dot(other_normal) > 1 - SIMD_EPSILON) cp.m_normalWorldOnB = triangle_normal;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
#if !UF_ENV_DREAMCAST
|
||||
static bool contactCallback(btManifoldPoint &ManifoldPoint, const btCollisionObjectWrapper *Object0, int PartID0, int Index0, const btCollisionObjectWrapper *Object1, int PartID1, int Index1) {
|
||||
/*
|
||||
if ( colObj0Wrap->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE ) {
|
||||
fixMeshNormal( cp, colObj0Wrap, partId0, index0 );
|
||||
}
|
||||
if ( colObj1Wrap->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE ) {
|
||||
fixMeshNormal( cp, colObj1Wrap, partId1, index1 );
|
||||
}
|
||||
btAdjustInternalEdgeContacts(cp, colObj1Wrap, colObj0Wrap, partId1,index1);
|
||||
//btAdjustInternalEdgeContacts(cp,colObj1Wrap,colObj0Wrap, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
|
||||
//btAdjustInternalEdgeContacts(cp,colObj1Wrap,colObj0Wrap, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
|
||||
*/
|
||||
|
||||
if( Object1->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE ) return false;
|
||||
|
||||
pod::Vector3f Before = {
|
||||
@ -153,37 +84,16 @@ static bool contactCallback(btManifoldPoint &ManifoldPoint, const btCollisionObj
|
||||
};
|
||||
btAdjustInternalEdgeContacts(ManifoldPoint, Object1, Object0, PartID1, Index1);
|
||||
btAdjustInternalEdgeContacts(ManifoldPoint, Object0, Object1, PartID0, Index0);
|
||||
/*
|
||||
if ( Object0->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE ) {
|
||||
fixMeshNormal( ManifoldPoint, Object0, PartID0, Index0 );
|
||||
}
|
||||
if ( Object1->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE ) {
|
||||
fixMeshNormal( ManifoldPoint, Object1, PartID1, Index1 );
|
||||
}
|
||||
*/
|
||||
|
||||
pod::Vector3f After = {
|
||||
ManifoldPoint.m_normalWorldOnB.getX(),
|
||||
ManifoldPoint.m_normalWorldOnB.getY(),
|
||||
ManifoldPoint.m_normalWorldOnB.getZ(),
|
||||
};
|
||||
|
||||
// if ( Before != After ) std::cout << "Before: " << uf::string::toString(Before) << "\tafter: " << uf::string::toString(After) << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
void FixMeshNormal(btManifoldPoint& cp, const btCollisionObject* colObj0, int , int ) {
|
||||
const btTriangleMeshShape* tri_shape = static_cast<const btTriangleMeshShape*>(colObj0->getCollisionShape());
|
||||
btVector3 tri_normal;
|
||||
tri_shape->calcNormal(cp.m_normalWorldOnB);
|
||||
cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis() * cp.m_normalWorldOnB;
|
||||
|
||||
// Reproject collision point along normal.
|
||||
cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
|
||||
cp.m_localPointB = colObj0->getWorldTransform().invXform(cp.m_positionWorldOnB);
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
void ext::bullet::initialize() {
|
||||
ext::bullet::collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
@ -193,7 +103,9 @@ void ext::bullet::initialize() {
|
||||
ext::bullet::dynamicsWorld = new btDiscreteDynamicsWorld(ext::bullet::dispatcher, ext::bullet::overlappingPairCache, ext::bullet::solver, ext::bullet::collisionConfiguration);
|
||||
ext::bullet::dynamicsWorld->setGravity(btVector3(0, -9.81, 0));
|
||||
|
||||
#if !UF_ENV_DREAMCAST
|
||||
gContactAddedCallback = contactCallback;
|
||||
#endif
|
||||
|
||||
ext::bullet::debugDrawer.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
|
||||
ext::bullet::dynamicsWorld->setDebugDrawer(&ext::bullet::debugDrawer);
|
||||
@ -485,8 +397,8 @@ void UF_API ext::bullet::debugDraw( uf::Object& object ) {
|
||||
graphic.material.device = &uf::renderer::device;
|
||||
graphic.descriptor.cullMode = uf::renderer::enums::CullMode::NONE;
|
||||
|
||||
graphic.material.attachShader("./data/shaders/base.colored.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
graphic.material.attachShader("./data/shaders/base.frag.spv", uf::renderer::enums::Shader::FRAGMENT);
|
||||
graphic.material.attachShader(uf::io::root + "/shaders/base.colored.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
graphic.material.attachShader(uf::io::root + "/shaders/base.frag.spv", uf::renderer::enums::Shader::FRAGMENT);
|
||||
|
||||
graphic.initialize();
|
||||
graphic.initializeGeometry( mesh, 0 );
|
||||
@ -499,4 +411,5 @@ void UF_API ext::bullet::debugDraw( uf::Object& object ) {
|
||||
graphic.initializeGeometry( mesh, 0 );
|
||||
graphic.getPipeline().update( graphic );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,5 +1,6 @@
|
||||
#include <uf/ext/freetype/freetype.h>
|
||||
#include <iostream>
|
||||
#if UF_USE_FREETYPE
|
||||
#include <uf/ext/freetype/freetype.h>
|
||||
|
||||
ext::freetype::Library ext::freetype::library;
|
||||
|
||||
@ -103,4 +104,5 @@ UF_API std::string ext::freetype::getError( int error ) {
|
||||
}
|
||||
|
||||
return ft_errors[0].err_msg;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -295,7 +295,7 @@ pod::Graph ext::gltf::load( const std::string& filename, ext::gltf::load_mode_t
|
||||
image.loadFromBuffer( &i.image[0], {i.width, i.height}, 8, i.component, true );
|
||||
|
||||
if ( graph.metadata["dump images"].as<bool>() ) {
|
||||
std::string target = "./data/dump/" + uf::string::sha256(filename) + "." + std::to_string(_i++) + ".png";
|
||||
std::string target = uf::io::root + "/dump/" + uf::string::sha256(filename) + "." + std::to_string(_i++) + ".png";
|
||||
image.save( target );
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,18 +58,18 @@ namespace {
|
||||
if ( graph.mode & ext::gltf::LoadMode::LOAD ) {
|
||||
if ( graph.mode & ext::gltf::LoadMode::SEPARATE ) {
|
||||
if ( graph.mode & ext::gltf::LoadMode::SKINNED ) {
|
||||
graphic.material.attachShader("./data/shaders/gltf.skinned.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
graphic.material.attachShader(uf::io::root + "/shaders/gltf.skinned.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
} else {
|
||||
graphic.material.attachShader("./data/shaders/gltf.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
graphic.material.attachShader(uf::io::root + "/shaders/gltf.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
}
|
||||
} else {
|
||||
if ( graph.mode & ext::gltf::LoadMode::SKINNED ) {
|
||||
graphic.material.attachShader("./data/shaders/gltf.skinned.instanced.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
graphic.material.attachShader(uf::io::root + "/shaders/gltf.skinned.instanced.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
} else {
|
||||
graphic.material.attachShader("./data/shaders/gltf.instanced.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
graphic.material.attachShader(uf::io::root + "/shaders/gltf.instanced.vert.spv", uf::renderer::enums::Shader::VERTEX);
|
||||
}
|
||||
}
|
||||
graphic.material.attachShader("./data/shaders/gltf.frag.spv", uf::renderer::enums::Shader::FRAGMENT);
|
||||
graphic.material.attachShader(uf::io::root + "/shaders/gltf.frag.spv", uf::renderer::enums::Shader::FRAGMENT);
|
||||
{
|
||||
auto& shader = graphic.material.getShader("vertex");
|
||||
struct SpecializationConstant {
|
||||
@ -278,6 +278,7 @@ void uf::graph::process( pod::Graph& graph ) {
|
||||
auto& info = graph.metadata["tags"][nodeName];
|
||||
if ( info["collision"].is<std::string>() ) {
|
||||
std::string type = info["collision"].as<std::string>();
|
||||
#if UF_USE_BULLET
|
||||
if ( type == "static mesh" ) {
|
||||
bool applyTransform = false; //!(graph.mode & ext::gltf::LoadMode::TRANSFORM);
|
||||
auto& collider = ext::bullet::create( entity->as<uf::Object>(), mesh, applyTransform, 1 );
|
||||
@ -294,6 +295,7 @@ void uf::graph::process( pod::Graph& graph ) {
|
||||
} else if ( type == "bounding box" ) {
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,55 +1,19 @@
|
||||
#include <uf/ext/gltf/mesh.h>
|
||||
#include <uf/utils/graphic/descriptor.h>
|
||||
|
||||
std::vector<uf::renderer::VertexDescriptor> ext::gltf::mesh::ID::descriptor = {
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::ID, position)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::ID, uv)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::ID, normal)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32A32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::ID, tangent)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32_SINT,
|
||||
offsetof(ext::gltf::mesh::ID, id)
|
||||
}
|
||||
};
|
||||
std::vector<uf::renderer::VertexDescriptor> ext::gltf::mesh::Skinned::descriptor = {
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::Skinned, position)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::Skinned, uv)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::Skinned, normal)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32A32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::Skinned, tangent)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32_SINT,
|
||||
offsetof(ext::gltf::mesh::Skinned, id)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32A32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::Skinned, joints)
|
||||
},
|
||||
{
|
||||
uf::renderer::enums::Format::R32G32B32A32_SFLOAT,
|
||||
offsetof(ext::gltf::mesh::Skinned, weights)
|
||||
},
|
||||
};
|
||||
UF_VERTEX_DESCRIPTOR(ext::gltf::mesh::ID,
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::ID, R32G32B32_SFLOAT, position)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::ID, R32G32_SFLOAT, uv)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::ID, R32G32B32_SFLOAT, normal)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::ID, R32G32B32A32_SFLOAT, tangent)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::ID, R32G32_SINT, id)
|
||||
);
|
||||
UF_VERTEX_DESCRIPTOR(ext::gltf::mesh::Skinned,
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::Skinned, R32G32B32_SFLOAT, position)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::Skinned, R32G32_SFLOAT, uv)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::Skinned, R32G32B32_SFLOAT, normal)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::Skinned, R32G32B32A32_SFLOAT, tangent)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::Skinned, R32G32_SINT, id)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::Skinned, R32G32B32A32_SFLOAT, joints)
|
||||
UF_VERTEX_DESCRIPTION(ext::gltf::mesh::Skinned, R32G32B32A32_SFLOAT, weights)
|
||||
);
|
||||
@ -124,17 +124,22 @@ std::string ext::json::encode( const ext::json::Value& json, bool pretty ) {
|
||||
return ext::lua::state["json"]["encode"]( table );
|
||||
#endif
|
||||
}
|
||||
#if UF_USE_LUA
|
||||
std::string ext::json::encode( const sol::table& table ) {
|
||||
return ext::lua::state["json"]["encode"]( table );
|
||||
}
|
||||
|
||||
#endif
|
||||
void ext::json::decode( ext::json::Value& json, const std::string& str ) {
|
||||
#if defined(UF_JSON_USE_NLOHMANN) && UF_JSON_USE_NLOHMANN
|
||||
#if UF_NO_EXCEPTIONS
|
||||
json = nlohmann::json::parse(str, nullptr, true, true);
|
||||
#else
|
||||
try {
|
||||
json = nlohmann::json::parse(str, nullptr, true, true);
|
||||
} catch ( nlohmann::json::parse_error& e ) {
|
||||
uf::iostream << "[JSON] " << e.what() << "\n";
|
||||
}
|
||||
#endif
|
||||
#elif defined(UF_JSON_USE_JSONCPP) && UF_JSON_USE_JSONCPP
|
||||
Json::Reader reader;
|
||||
if ( !reader.parse(str, json) ) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
sol::state ext::lua::state;
|
||||
std::string ext::lua::main = "./data/scripts/main.lua";
|
||||
std::string ext::lua::main = uf::io::root + "/scripts/main.lua";
|
||||
std::unordered_map<std::string, std::string> ext::lua::modules;
|
||||
|
||||
#include <uf/utils/math/transform.h>
|
||||
@ -262,4 +262,5 @@ void ext::lua::terminate() {
|
||||
delete ext::lua::onInitializationFunctions;
|
||||
ext::lua::onInitializationFunctions = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/engine/asset/asset.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(uf::Asset,
|
||||
@ -26,4 +26,5 @@ UF_LUA_REGISTER_USERTYPE(uf::Asset,
|
||||
asset.cache( uri, callback, hash );
|
||||
}),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Asset::getOriginal )
|
||||
)
|
||||
)
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/audio/audio.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(uf::Audio,
|
||||
@ -30,4 +30,5 @@ UF_LUA_REGISTER_USERTYPE(uf::Audio,
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Audio::setMaxDistance ),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Audio::getVolume ),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Audio::getFilename )
|
||||
)
|
||||
)
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/camera/camera.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(uf::Camera,
|
||||
@ -40,3 +40,4 @@ UF_LUA_REGISTER_USERTYPE(uf::Camera,
|
||||
}),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Camera::update )
|
||||
)
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/math/matrix.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(pod::Matrix4f,
|
||||
@ -33,3 +33,4 @@ UF_LUA_REGISTER_USERTYPE(pod::Matrix4f,
|
||||
return uf::matrix::identity();
|
||||
})
|
||||
)
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/math/transform.h>
|
||||
#include <uf/utils/audio/audio.h>
|
||||
#include <uf/utils/camera/camera.h>
|
||||
@ -161,4 +161,5 @@ namespace {
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/math/quaternion.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(pod::Quaternion<>,
|
||||
@ -72,4 +72,5 @@ UF_LUA_REGISTER_USERTYPE(pod::Quaternion<>,
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, []( const pod::Quaternion<>& self ) {
|
||||
return uf::string::toString( self );
|
||||
})
|
||||
)
|
||||
)
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/math/physics.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(uf::Timer<>,
|
||||
@ -11,4 +11,5 @@ UF_LUA_REGISTER_USERTYPE(uf::Timer<>,
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Timer<>::reset ),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Timer<>::update ),
|
||||
UF_LUA_REGISTER_USERTYPE_MEMBER( uf::Timer<>::running )
|
||||
)
|
||||
)
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/math/transform.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(pod::Transform<>,
|
||||
@ -48,4 +48,5 @@ UF_LUA_REGISTER_USERTYPE(pod::Transform<>,
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE(getModel, []( const pod::Transform<>& t ) {
|
||||
return uf::transform::model( t );
|
||||
})
|
||||
)
|
||||
)
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include <uf/ext/lua/lua.h>
|
||||
|
||||
#if UF_USE_LUA
|
||||
#include <uf/utils/math/vector.h>
|
||||
|
||||
UF_LUA_REGISTER_USERTYPE(pod::Vector3f,
|
||||
@ -115,4 +115,5 @@ UF_LUA_REGISTER_USERTYPE(pod::Vector4f,
|
||||
UF_LUA_REGISTER_USERTYPE_DEFINE( __tostring, []( pod::Vector4f& self ) {
|
||||
return uf::string::toString( self );
|
||||
})
|
||||
)
|
||||
)
|
||||
#endif
|
||||
@ -6,46 +6,57 @@
|
||||
#include <uf/ext/opengl/opengl.h>
|
||||
#include <uf/ext/opengl/device.h>
|
||||
|
||||
GLhandle(VkResult) ext::opengl::Buffer::map( GLsizeiptr size, GLsizeiptr offset ) {
|
||||
bool ext::opengl::Buffer::map( GLsizeiptr size, GLsizeiptr offset ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ext::opengl::Buffer::unmap() {
|
||||
}
|
||||
|
||||
GLhandle(VkResult) ext::opengl::Buffer::bind( GLsizeiptr offset ) {
|
||||
bool ext::opengl::Buffer::bind( GLsizeiptr offset ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ext::opengl::Buffer::setupDescriptor( GLsizeiptr size, GLsizeiptr offset ) {
|
||||
descriptor.buffer = buffer;
|
||||
descriptor.offset = offset;
|
||||
descriptor.range = size;
|
||||
}
|
||||
|
||||
void ext::opengl::Buffer::copyTo( void* data, GLsizeiptr size ) {
|
||||
|
||||
void ext::opengl::Buffer::copyTo( void* data, GLsizeiptr len ) {
|
||||
if ( !buffer || !data ) return;
|
||||
if ( len >= size ) len = size;
|
||||
memcpy( buffer, data, len );
|
||||
}
|
||||
|
||||
GLhandle(VkResult) ext::opengl::Buffer::flush( GLsizeiptr size, GLsizeiptr offset ) {
|
||||
bool ext::opengl::Buffer::flush( GLsizeiptr size, GLsizeiptr offset ) {
|
||||
return 0;
|
||||
}
|
||||
bool ext::opengl::Buffer::invalidate( GLsizeiptr size, GLsizeiptr offset ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ext::opengl::Buffer::allocate( const CreateInfo& bufferCreateInfo ) {
|
||||
this->destroy();
|
||||
|
||||
this->buffer = malloc( bufferCreateInfo.size );
|
||||
this->usageFlags = bufferCreateInfo.usage;
|
||||
|
||||
GLhandle(VkResult) ext::opengl::Buffer::invalidate( GLsizeiptr size, GLsizeiptr offset ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ext::opengl::Buffer::allocate( GLhandle(VkBufferCreateInfo) bufferCreateInfo ) {
|
||||
|
||||
this->size = bufferCreateInfo.size;
|
||||
this->allocationInfo.size = bufferCreateInfo.size;
|
||||
this->allocationInfo.offset = 0;
|
||||
}
|
||||
|
||||
// RAII
|
||||
ext::opengl::Buffer::~Buffer() {
|
||||
// this->destroy();
|
||||
}
|
||||
void ext::opengl::Buffer::initialize( GLhandle(VkDevice) device ) {
|
||||
this->device = device;
|
||||
void ext::opengl::Buffer::initialize( Device& device ) {
|
||||
this->device = &device;
|
||||
}
|
||||
void ext::opengl::Buffer::destroy() {
|
||||
|
||||
if ( device && buffer ) free(buffer);
|
||||
device = NULL;
|
||||
buffer = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
@ -59,14 +70,25 @@ void ext::opengl::Buffers::destroy() {
|
||||
buffers.clear();
|
||||
}
|
||||
|
||||
size_t ext::opengl::Buffers::initializeBuffer( void* data, GLsizeiptr length, GLhandle(VkBufferUsageFlags) usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags, bool stage ) {
|
||||
size_t ext::opengl::Buffers::initializeBuffer( void* data, GLsizeiptr length, GLenum usageFlags, GLhandle(VkMemoryPropertyFlags) memoryPropertyFlags, bool stage ) {
|
||||
size_t index = buffers.size();
|
||||
auto& buffer = buffers.emplace_back();
|
||||
|
||||
buffer.allocate( Buffer::CreateInfo{
|
||||
.flags = 0,
|
||||
.size = length,
|
||||
.usage = usageFlags,
|
||||
} );
|
||||
buffer.copyTo( data, length );
|
||||
|
||||
return index;
|
||||
}
|
||||
void ext::opengl::Buffers::updateBuffer( void* data, GLsizeiptr length, size_t index, bool stage ) {
|
||||
Buffer& buffer = buffers.at(index);
|
||||
return updateBuffer( data, length, buffer, stage );
|
||||
}
|
||||
void ext::opengl::Buffers::updateBuffer( void* data, GLsizeiptr length, Buffer& buffer, bool stage ) {
|
||||
buffer.copyTo( data, length );
|
||||
}
|
||||
|
||||
#endif
|
||||
21
engine/src/ext/opengl/commands.cpp
Normal file
21
engine/src/ext/opengl/commands.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#if UF_USE_OPENGL
|
||||
|
||||
#include <uf/ext/opengl/opengl.h>
|
||||
#include <uf/ext/opengl/commands.h>
|
||||
|
||||
void ext::opengl::CommandBuffer::record( const CommandBuffer::function_t& command ) {
|
||||
commands.emplace_back( command );
|
||||
}
|
||||
void ext::opengl::CommandBuffer::submit() {
|
||||
for ( auto& command : commands ) {
|
||||
command();
|
||||
}
|
||||
}
|
||||
void ext::opengl::CommandBuffer::flush() {
|
||||
commands.empty();
|
||||
}
|
||||
size_t ext::opengl::CommandBuffer::size() const {
|
||||
return commands.size();
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -12,4 +12,32 @@
|
||||
|
||||
#include <uf/utils/serialize/serializer.h>
|
||||
|
||||
void ext::opengl::Device::initialize() {
|
||||
spec::Context::globalInit();
|
||||
this->context = (spec::Context*) spec::uni::Context::create( contextSettings, *this->window->getHandle() );
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
//glKosInit();
|
||||
GLdcConfig config;
|
||||
glKosInitConfig(&config);
|
||||
config.fsaa_enabled = GL_FALSE;
|
||||
glKosInitEx(&config);
|
||||
#else
|
||||
glewExperimental = GL_TRUE;
|
||||
if ( glewInit() != GLEW_OK ) {
|
||||
std::cout << "ERROR: " << errorString() << std::endl;
|
||||
std::exit(EXIT_FAILURE);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void ext::opengl::Device::destroy() {
|
||||
if ( this->context ) {
|
||||
this->context->terminate();
|
||||
delete this->context;
|
||||
this->context = NULL;
|
||||
}
|
||||
spec::Context::globalCleanup();
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -55,51 +55,15 @@ std::vector<ext::opengl::RenderMode*> ext::opengl::renderModes = {
|
||||
new ext::opengl::BaseRenderMode,
|
||||
};
|
||||
|
||||
void UF_API ext::opengl::initialize() {
|
||||
glewExperimental = GL_TRUE;
|
||||
if ( glewInit() != GLEW_OK ) {
|
||||
return;
|
||||
}
|
||||
/*
|
||||
device.initialize();
|
||||
swapchain.initialize( device );
|
||||
*/
|
||||
for ( auto& renderMode : renderModes ) {
|
||||
if ( !renderMode ) continue;
|
||||
renderMode->initialize(device);
|
||||
}
|
||||
std::vector<std::function<int()>> jobs;
|
||||
for ( auto& renderMode : renderModes ) {
|
||||
if ( !renderMode ) continue;
|
||||
if ( settings::experimental::individualPipelines ) renderMode->bindPipelines();
|
||||
if ( settings::experimental::multithreadedCommandRecording ) {
|
||||
jobs.emplace_back([&]{
|
||||
renderMode->createCommandBuffers();
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
renderMode->createCommandBuffers();
|
||||
}
|
||||
}
|
||||
if ( !jobs.empty() ) {
|
||||
uf::thread::batchWorkers( jobs );
|
||||
}
|
||||
{
|
||||
std::vector<uint8_t> pixels = {
|
||||
255, 0, 255, 255, 0, 0, 0, 255,
|
||||
0, 0, 0, 255, 255, 0, 255, 255,
|
||||
};
|
||||
Texture2D::empty.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST;
|
||||
Texture2D::empty.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST;
|
||||
Texture2D::empty.fromBuffers( (void*) &pixels[0], pixels.size(), uf::renderer::enums::Format::R8G8B8A8_UNORM, 2, 2 );
|
||||
}
|
||||
}
|
||||
std::string UF_API ext::opengl::errorString() {
|
||||
#if UF_ENV_DREAMCAST
|
||||
#else
|
||||
GLenum error;
|
||||
const GLubyte* bytes = NULL;
|
||||
if ((error = glGetError()) != GL_NO_ERROR) bytes = gluErrorString(error);
|
||||
std::string str = (const char*) bytes;
|
||||
return str;
|
||||
#endif
|
||||
}
|
||||
|
||||
/////
|
||||
@ -161,6 +125,40 @@ void UF_API ext::opengl::removeRenderMode( ext::opengl::RenderMode* mode, bool f
|
||||
if ( free ) delete mode;
|
||||
ext::opengl::states::rebuild = true;
|
||||
}
|
||||
void UF_API ext::opengl::initialize() {
|
||||
device.initialize();
|
||||
// swapchain.initialize( device );
|
||||
for ( auto& renderMode : renderModes ) {
|
||||
if ( !renderMode ) continue;
|
||||
renderMode->initialize(device);
|
||||
}
|
||||
|
||||
std::vector<std::function<int()>> jobs;
|
||||
for ( auto& renderMode : renderModes ) {
|
||||
if ( !renderMode ) continue;
|
||||
if ( settings::experimental::individualPipelines ) renderMode->bindPipelines();
|
||||
if ( settings::experimental::multithreadedCommandRecording ) {
|
||||
jobs.emplace_back([&]{
|
||||
renderMode->createCommandBuffers();
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
renderMode->createCommandBuffers();
|
||||
}
|
||||
}
|
||||
if ( !jobs.empty() ) {
|
||||
uf::thread::batchWorkers( jobs );
|
||||
}
|
||||
{
|
||||
std::vector<uint8_t> pixels = {
|
||||
255, 0, 255, 255, 0, 0, 0, 255,
|
||||
0, 0, 0, 255, 255, 0, 255, 255,
|
||||
};
|
||||
Texture2D::empty.sampler.descriptor.filter.min = uf::renderer::enums::Filter::NEAREST;
|
||||
Texture2D::empty.sampler.descriptor.filter.mag = uf::renderer::enums::Filter::NEAREST;
|
||||
Texture2D::empty.fromBuffers( (void*) &pixels[0], pixels.size(), uf::renderer::enums::Format::R8G8B8A8_UNORM, 2, 2 );
|
||||
}
|
||||
}
|
||||
void UF_API ext::opengl::tick(){
|
||||
ext::opengl::mutex.lock();
|
||||
if ( ext::opengl::states::resized || ext::opengl::settings::experimental::rebuildOnTickBegin ) {
|
||||
@ -235,11 +233,13 @@ void UF_API ext::opengl::render(){
|
||||
if ( ext::opengl::settings::experimental::waitOnRenderEnd ) {
|
||||
synchronize();
|
||||
}
|
||||
#if UF_USE_OPENVR
|
||||
/*
|
||||
if ( ext::openvr::context ) {
|
||||
ext::openvr::postSubmit();
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
ext::opengl::mutex.unlock();
|
||||
}
|
||||
void UF_API ext::opengl::destroy() {
|
||||
@ -263,11 +263,9 @@ void UF_API ext::opengl::destroy() {
|
||||
renderMode->destroy();
|
||||
renderMode = NULL;
|
||||
}
|
||||
/*
|
||||
swapchain.destroy();
|
||||
// swapchain.destroy();
|
||||
device.destroy();
|
||||
*/
|
||||
ext::opengl::mutex.unlock();
|
||||
ext::opengl::mutex.unlock();
|
||||
}
|
||||
void UF_API ext::opengl::synchronize( uint8_t flag ) {
|
||||
if ( flag & 0b01 ) {
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
#include <uf/utils/graphic/graphic.h>
|
||||
#include <uf/utils/serialize/serializer.h>
|
||||
#include <uf/engine/scene/scene.h>
|
||||
#include <uf/utils/math/transform.h>
|
||||
#include <uf/utils/camera/camera.h>
|
||||
|
||||
#include <uf/ext/openvr/openvr.h>
|
||||
|
||||
@ -51,23 +53,144 @@ void ext::opengl::RenderMode::bindGraphicPushConstants( ext::opengl::Graphic* po
|
||||
}
|
||||
|
||||
void ext::opengl::RenderMode::createCommandBuffers() {
|
||||
if ( this->getName() != "" ) return;
|
||||
this->execute = true;
|
||||
|
||||
std::vector<ext::opengl::Graphic*> graphics;
|
||||
this->synchronize();
|
||||
|
||||
float width = this->width > 0 ? this->width : ext::opengl::settings::width;
|
||||
float height = this->height > 0 ? this->height : ext::opengl::settings::height;
|
||||
|
||||
#if 0
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(90.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(-1.5f,0.0f,-6.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
glVertex3f( 0.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.0f,1.0f,0.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.0f,0.0f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
glTranslatef(3.0f,0.0f,0.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
#endif
|
||||
#if 1
|
||||
auto& commands = getCommands();
|
||||
commands.flush();
|
||||
commands.record([]{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
});
|
||||
commands.record([]{
|
||||
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(90.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
});
|
||||
commands.record([]{
|
||||
glTranslatef(-1.5f,0.0f,-6.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
glVertex3f( 0.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.0f,1.0f,0.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.0f,0.0f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
});
|
||||
commands.record([]{
|
||||
glTranslatef(3.0f,0.0f,0.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
});
|
||||
#endif
|
||||
#if 0
|
||||
auto& commands = getCommands();
|
||||
commands.flush();
|
||||
std::vector<uf::Entity*> entities;
|
||||
std::function<void(uf::Entity*)> filter = [&]( uf::Entity* entity ) {
|
||||
if ( !entity->hasComponent<uf::Graphic>() ) return;
|
||||
ext::opengl::Graphic& graphic = entity->getComponent<uf::Graphic>();
|
||||
if ( !graphic.initialized || !graphic.process ) return;
|
||||
graphics.push_back(&graphic);
|
||||
if ( !graphic.initialized || !graphic.process || graphic.descriptor.renderMode != this->getName() ) return;
|
||||
entities.emplace_back(entity);
|
||||
};
|
||||
size_t currentDraw = 0;
|
||||
size_t currentPass = 0;
|
||||
size_t currentSubpass = 0;
|
||||
for ( uf::Scene* scene : uf::scene::scenes ) {
|
||||
if ( !scene ) continue;
|
||||
scene->process(filter);
|
||||
}
|
||||
|
||||
auto& controller = scene->getController();
|
||||
auto& camera = controller.getComponent<uf::Camera>();
|
||||
auto& sceneMetadata = scene->getComponent<uf::Serializer>();
|
||||
if ( !ext::json::isNull( sceneMetadata["system"]["renderer"]["clear values"][0] ) ) {
|
||||
auto& v = sceneMetadata["system"]["renderer"]["clear values"][0];
|
||||
commands.record([=](){
|
||||
glClearColor(v[0].as<float>(), v[1].as<float>(), v[2].as<float>(), v[3].as<float>());
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
});
|
||||
}
|
||||
|
||||
this->synchronize();
|
||||
auto& view = camera.getView();
|
||||
auto& projection = camera.getProjection();
|
||||
|
||||
commands.record([=](){
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glLoadMatrixf( &projection[0] );
|
||||
});
|
||||
|
||||
for ( auto* pointer : entities ) {
|
||||
uf::Object& entity = pointer->as<uf::Object>();
|
||||
auto& graphic = entity.getComponent<uf::Graphic>();
|
||||
|
||||
auto& transform = entity.getComponent<pod::Transform<>>();
|
||||
auto model = view * uf::transform::model( transform );
|
||||
commands.record([=](){
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glLoadMatrixf( &model[0] );
|
||||
});
|
||||
|
||||
auto descriptor = bindGraphicDescriptor(graphic.descriptor, currentSubpass);
|
||||
graphic.record( commands, descriptor, currentPass, currentDraw++ );
|
||||
}
|
||||
entities.clear();
|
||||
}
|
||||
#endif
|
||||
// std::cout << "Recording | " << this->getName() << ": " << this->getType() << " | Commands: " << commands.size() << std::endl;
|
||||
// bindPipelines( graphics );
|
||||
createCommandBuffers( graphics );
|
||||
// createCommandBuffers( graphics );
|
||||
this->mostRecentCommandPoolId = std::this_thread::get_id();
|
||||
this->rebuild = false;
|
||||
}
|
||||
@ -117,6 +240,15 @@ void ext::opengl::RenderMode::bindPipelines( const std::vector<ext::opengl::Grap
|
||||
}
|
||||
|
||||
void ext::opengl::RenderMode::render() {
|
||||
#if UF_ENV_DREAMCAST
|
||||
glKosSwapBuffers();
|
||||
#else
|
||||
auto& commands = getCommands( this->mostRecentCommandPoolId );
|
||||
commands.submit();
|
||||
if (device && device->context && device->context->setActive(true)) {
|
||||
device->context->display();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::opengl::RenderMode::initialize( Device& device ) {
|
||||
@ -136,7 +268,9 @@ void ext::opengl::RenderMode::tick() {
|
||||
|
||||
void ext::opengl::RenderMode::destroy() {
|
||||
this->synchronize();
|
||||
|
||||
for ( auto& pair : this->commands.container() ) {
|
||||
pair.second.flush();
|
||||
}
|
||||
renderTarget.destroy();
|
||||
}
|
||||
void ext::opengl::RenderMode::synchronize( uint64_t timeout ) {
|
||||
|
||||
@ -14,16 +14,76 @@ const std::string ext::opengl::BaseRenderMode::getType() const {
|
||||
void ext::opengl::BaseRenderMode::createCommandBuffers( const std::vector<ext::opengl::Graphic*>& graphics ) {
|
||||
}
|
||||
|
||||
void ext::opengl::BaseRenderMode::initialize( Device& device ) {
|
||||
this->metadata["name"] = "Swapchain";
|
||||
auto windowSize = device.window->getSize();
|
||||
this->width = windowSize.x;
|
||||
this->height = windowSize.y;
|
||||
|
||||
ext::opengl::RenderMode::initialize( device );
|
||||
|
||||
#if 1
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClearDepth(1.0);
|
||||
glDepthFunc(GL_LESS);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(90.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::opengl::BaseRenderMode::tick() {
|
||||
ext::opengl::RenderMode::tick();
|
||||
#if 0
|
||||
if ( ext::opengl::states::resized ) {
|
||||
if ( ext::opengl::settings::height <= 0 ) ext::opengl::settings::height = 1;
|
||||
|
||||
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void ext::opengl::BaseRenderMode::render() {
|
||||
#if 0
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glLoadIdentity();
|
||||
|
||||
}
|
||||
glTranslatef(-1.5f,0.0f,-6.0f);
|
||||
|
||||
void ext::opengl::BaseRenderMode::initialize( Device& device ) {
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1.0f,0.0f,0.0f);
|
||||
glVertex3f( 0.0f, 1.0f, 0.0f);
|
||||
glColor3f(0.0f,1.0f,0.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glColor3f(0.0f,0.0f,1.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
|
||||
glTranslatef(3.0f,0.0f,0.0f);
|
||||
|
||||
glColor3f(0.5f,0.5f,1.0f);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(-1.0f, 1.0f, 0.0f);
|
||||
glVertex3f( 1.0f, 1.0f, 0.0f);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f);
|
||||
glEnd();
|
||||
#endif
|
||||
if ( ext::opengl::renderModes.size() > 1 ) return;
|
||||
ext::opengl::RenderMode::render();
|
||||
}
|
||||
|
||||
void ext::opengl::BaseRenderMode::destroy() {
|
||||
ext::opengl::RenderMode::destroy();
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -28,6 +28,11 @@ std::vector<ext::opengl::Graphic*> ext::opengl::DeferredRenderMode::getBlitters(
|
||||
}
|
||||
|
||||
void ext::opengl::DeferredRenderMode::initialize( Device& device ) {
|
||||
auto windowSize = device.window->getSize();
|
||||
this->width = windowSize.x;
|
||||
this->height = windowSize.y;
|
||||
|
||||
ext::opengl::RenderMode::initialize( device );
|
||||
}
|
||||
void ext::opengl::DeferredRenderMode::tick() {
|
||||
ext::opengl::RenderMode::tick();
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
#include <uf/ext/openvr/openvr.h>
|
||||
|
||||
#if UF_USE_OPENVR
|
||||
#include <uf/utils/io/iostream.h>
|
||||
#include <uf/utils/string/ext.h>
|
||||
#include <uf/utils/string/io.h>
|
||||
@ -723,4 +725,5 @@ uf::Graphic& ext::openvr::controllerRenderModel( vr::Controller_Hand hand ) {
|
||||
if ( hand == vr::Controller_Hand::Hand_Left ) return renderModels["{indexcontroller}valve_controller_knu_1_0_left"]; //return ::devices.controllers.left.mesh;
|
||||
else if ( hand == vr::Controller_Hand::Hand_Right ) return renderModels["{indexcontroller}valve_controller_knu_1_0_right"]; //return ::devices.controllers.right.mesh;
|
||||
throw false; //std::exception("error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,10 +1,10 @@
|
||||
#include <uf/ext/ultralight/ultralight.h>
|
||||
|
||||
#if UF_USE_ULTRALIGHT
|
||||
#include <AppCore/CAPI.h>
|
||||
|
||||
#include <uf/utils/io/iostream.h>
|
||||
#include <uf/utils/hook/hook.h>
|
||||
// std::string ext::ultralight::resourcesDir = "./data/resources/";
|
||||
// std::string ext::ultralight::resourcesDir = uf::io::root + "/resources/";
|
||||
|
||||
namespace {
|
||||
size_t uids = 0;
|
||||
@ -181,11 +181,11 @@ void ext::ultralight::initialize() {
|
||||
ulConfigSetDeviceScale(config, ext::ultralight::scale);
|
||||
|
||||
ulConfigSetFontFamilyStandard(config, UL::String("Arial"));
|
||||
ulConfigSetResourcePath(config, UL::String("./data/html/resources/"));
|
||||
ulConfigSetResourcePath(config, UL::String(uf::io::root + "/html/resources/"));
|
||||
ulConfigSetUseGPURenderer(config, false);
|
||||
ulEnablePlatformFontLoader();
|
||||
ulEnablePlatformFileSystem(UL::String("./data/html/assets/"));
|
||||
ulEnableDefaultLogger(UL::String("./data/logs/ultralight.log"));
|
||||
ulEnablePlatformFileSystem(UL::String(uf::io::root + "/html/assets/"));
|
||||
ulEnableDefaultLogger(UL::String(uf::io::root + "/logs/ultralight.log"));
|
||||
|
||||
|
||||
::renderer = ulCreateRenderer(config);
|
||||
@ -266,4 +266,5 @@ uf::Image ext::ultralight::capture( pod::HTML& container ) {
|
||||
ulBitmapUnlockPixels(bitmap);
|
||||
ulBitmapSwapRedBlueChannels(bitmap);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,7 +1,10 @@
|
||||
#include <uf/config.h>
|
||||
#if defined(UF_USE_VORBIS)
|
||||
#if UF_USE_VORBIS
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
#include <uf/ext/oal/oal.h>
|
||||
#endif
|
||||
|
||||
#include <uf/ext/vorbis/vorbis.h>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
@ -28,7 +31,9 @@ void UF_API_CALL ext::Vorbis::load( const std::string& filename ) {
|
||||
}
|
||||
|
||||
vorbis_info* info = ov_info(&file, -1);
|
||||
this->m_format = info->channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
|
||||
#if UF_USE_OPENAL
|
||||
this->m_format = info->channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
|
||||
#endif
|
||||
this->m_frequency = info->rate;
|
||||
|
||||
do {
|
||||
|
||||
@ -42,7 +42,7 @@ void ext::vulkan::ComputeRenderMode::initialize( Device& device ) {
|
||||
compute.material.device = &device;
|
||||
compute.descriptor.renderMode = this->getName();
|
||||
compute.material.initializeShaders({
|
||||
{"./data/shaders/raytracing.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT},
|
||||
{uf::io::root+"/shaders/raytracing.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT},
|
||||
});
|
||||
|
||||
for ( size_t i = 0; i < (ext::openvr::context ? 2 : 1); ++i ) {
|
||||
@ -96,8 +96,8 @@ void ext::vulkan::ComputeRenderMode::initialize( Device& device ) {
|
||||
|
||||
blitter.initializeGeometry( mesh );
|
||||
blitter.material.initializeShaders({
|
||||
{"./data/shaders/display.blit.vert.spv", VK_SHADER_STAGE_VERTEX_BIT},
|
||||
{"./data/shaders/display.blit.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT}
|
||||
{uf::io::root+"/shaders/display.blit.vert.spv", VK_SHADER_STAGE_VERTEX_BIT},
|
||||
{uf::io::root+"/shaders/display.blit.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT}
|
||||
});
|
||||
for ( auto& computeTexture : compute.material.textures ) {
|
||||
Texture2D& texture = blitter.material.textures.emplace_back();
|
||||
|
||||
@ -191,8 +191,8 @@ void ext::vulkan::DeferredRenderMode::initialize( Device& device ) {
|
||||
blitter.initializeGeometry( mesh );
|
||||
|
||||
blitter.material.initializeShaders({
|
||||
{"./data/shaders/display.subpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT},
|
||||
{"./data/shaders/display.subpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT}
|
||||
{uf::io::root+"/shaders/display.subpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT},
|
||||
{uf::io::root+"/shaders/display.subpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT}
|
||||
});
|
||||
{
|
||||
auto& scene = uf::scene::getCurrentScene();
|
||||
|
||||
@ -251,8 +251,8 @@ void ext::vulkan::RenderTargetRenderMode::initialize( Device& device ) {
|
||||
blitter.material.device = &device;
|
||||
blitter.initializeGeometry( mesh );
|
||||
blitter.material.initializeShaders({
|
||||
{"./data/shaders/display.renderTarget.vert.spv", VK_SHADER_STAGE_VERTEX_BIT},
|
||||
{"./data/shaders/display.renderTarget.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT}
|
||||
{uf::io::root+"/shaders/display.renderTarget.vert.spv", VK_SHADER_STAGE_VERTEX_BIT},
|
||||
{uf::io::root+"/shaders/display.renderTarget.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT}
|
||||
});
|
||||
|
||||
for ( auto& attachment : renderTarget.attachments ) {
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
|
||||
#if defined(UF_USE_OPENGL) && UF_USE_OPENGL == 1
|
||||
namespace {
|
||||
// This per-thread variable holds the current context for each thread
|
||||
// sf::ThreadLocalPtr<spec::Context> currentContext(NULL);
|
||||
@ -138,6 +137,4 @@ int UF_API_CALL spec::uni::Context::evaluateFormat( const spec::uni::Context::Se
|
||||
std::abs(int(settings.depthBits - depthBits)) +
|
||||
std::abs(int(settings.stencilBits - stencilBits)) +
|
||||
std::abs(int(settings.antialiasingLevel - antialiasing));
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include <uf/utils/io/iostream.h>
|
||||
|
||||
#if defined(UF_ENV_WINDOWS) && (!defined(UF_USE_SFML) || (defined(UF_USE_SFML) && UF_USE_SFML == 0)) && (defined(UF_USE_OPENGL) && UF_USE_OPENGL == 1)
|
||||
#if UF_ENV_WINDOWS && !UF_USE_SFML
|
||||
UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::Settings& settings ) :
|
||||
uni::Context( NULL, true, settings ),
|
||||
m_deviceContext (NULL),
|
||||
@ -11,19 +11,21 @@ UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::
|
||||
// Creating a dummy window is mandatory: we could create a memory DC but then
|
||||
// its pixel format wouldn't match the regular contexts' format, and thus
|
||||
// wglShareLists would always fail. Too bad...
|
||||
|
||||
#if UF_USE_OPENGL
|
||||
// Create a dummy window (disabled and hidden)
|
||||
this->m_window = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, 1, 1, NULL, NULL, GetModuleHandle(NULL), NULL);
|
||||
ShowWindow(this->m_window, SW_HIDE);
|
||||
this->m_deviceContext = GetDC(this->m_window);
|
||||
|
||||
if ( this->m_deviceContext ) this->create(shared);
|
||||
#endif
|
||||
}
|
||||
UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::Settings& settings, const Context::window_t& window ) :
|
||||
uni::Context( NULL, false, settings ),
|
||||
m_deviceContext (NULL),
|
||||
m_context (NULL)
|
||||
{
|
||||
#if UF_USE_OPENGL
|
||||
// Get the owner window and its device context
|
||||
this->m_window = window.getHandle();
|
||||
this->m_deviceContext = GetDC(this->m_window);
|
||||
@ -31,6 +33,7 @@ UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::
|
||||
// Create the context
|
||||
if ( this->m_deviceContext )
|
||||
this->create(shared);
|
||||
#endif
|
||||
}
|
||||
UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::Settings& settings, unsigned int width, unsigned int height ) : Context( shared, settings ) {
|
||||
|
||||
@ -40,128 +43,9 @@ spec::win32::Context::~Context() {
|
||||
}
|
||||
|
||||
void UF_API_CALL spec::win32::Context::create( uni::Context* shared ) {
|
||||
#if UF_USE_OPENGL
|
||||
// this->m_settings = settings;
|
||||
Context::Settings l_settings(24, 4, 0, 3, 3);
|
||||
|
||||
int bestFormat = 0;
|
||||
|
||||
// Find a pixel format with no antialiasing, if not needed or not supported
|
||||
if (bestFormat == 0) {
|
||||
// Setup a pixel format descriptor from the rendering settings
|
||||
PIXELFORMATDESCRIPTOR descriptor;
|
||||
ZeroMemory(&descriptor, sizeof(descriptor));
|
||||
descriptor.nSize = sizeof(descriptor);
|
||||
descriptor.nVersion = 1;
|
||||
descriptor.iLayerType = PFD_MAIN_PLANE;
|
||||
descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
descriptor.iPixelType = PFD_TYPE_RGBA;
|
||||
descriptor.cColorBits = (BYTE) l_settings.bitsPerPixel;
|
||||
descriptor.cDepthBits = (BYTE) l_settings.depthBits;
|
||||
descriptor.cStencilBits = (BYTE) l_settings.stencilBits;
|
||||
descriptor.cAlphaBits = l_settings.bitsPerPixel == 32 ? 8 : 0;
|
||||
|
||||
// Get the pixel format that best matches our requirements
|
||||
bestFormat = ChoosePixelFormat(this->m_deviceContext, &descriptor);
|
||||
if (bestFormat == 0) {
|
||||
uf::iostream << "[" << uf::IoStream::Color()("Red") << "ERROR" << "]" << "Failed to find a suitable pixel format for device context -- cannot create OpenGL context" << "\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Extract the depth and stencil bits from the chosen format
|
||||
PIXELFORMATDESCRIPTOR actualFormat;
|
||||
actualFormat.nSize = sizeof(actualFormat);
|
||||
actualFormat.nVersion = 1;
|
||||
DescribePixelFormat(this->m_deviceContext, bestFormat, sizeof(actualFormat), &actualFormat);
|
||||
l_settings.depthBits = actualFormat.cDepthBits;
|
||||
l_settings.stencilBits = actualFormat.cStencilBits;
|
||||
|
||||
// Set the chosen pixel format
|
||||
if (!SetPixelFormat(this->m_deviceContext, bestFormat, &actualFormat)) {
|
||||
uf::iostream << "[" << uf::IoStream::Color()("Red") << "ERROR" << "]" << "Failed to set pixel format for device context -- cannot create OpenGL context" << "\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the context to share display lists with
|
||||
HGLRC sharedContext = shared ? ((win32::Context*) shared)->m_context : NULL;
|
||||
|
||||
// If the OpenGL >= 3.0 context failed or if we don't want one, create a regular OpenGL 1.x/2.x context
|
||||
if (!this->m_context) {
|
||||
// set the context version to 2.0 (arbitrary)
|
||||
l_settings.majorVersion = 2;
|
||||
l_settings.minorVersion = 0;
|
||||
|
||||
// Share this context with others
|
||||
if (sharedContext) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
void UF_API_CALL spec::win32::Context::terminate() {
|
||||
// Destroy the OpenGL context
|
||||
if ( this->m_context ) {
|
||||
|
||||
}
|
||||
|
||||
// Destroy the device context
|
||||
if ( this->m_deviceContext ) ReleaseDC(this->m_window, this->m_deviceContext);
|
||||
|
||||
// Destroy the window if we own it
|
||||
if ( this->m_window && this->m_ownsWindow ) DestroyWindow(this->m_window);
|
||||
}
|
||||
|
||||
bool spec::win32::Context::makeCurrent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void spec::win32::Context::display() {
|
||||
if (this->m_deviceContext && this->m_context)
|
||||
SwapBuffers(this->m_deviceContext);
|
||||
}
|
||||
|
||||
void spec::win32::Context::setVerticalSyncEnabled(bool enabled) {
|
||||
|
||||
}
|
||||
# elif defined(UF_USE_OPENGL) && UF_USE_OPENGL == 0
|
||||
UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::Settings& settings ) :
|
||||
uni::Context( NULL, true, settings ),
|
||||
m_deviceContext (NULL),
|
||||
m_context (NULL)
|
||||
{
|
||||
// Creating a dummy window is mandatory: we could create a memory DC but then
|
||||
// its pixel format wouldn't match the regular contexts' format, and thus
|
||||
// wglShareLists would always fail. Too bad...
|
||||
|
||||
// Create a dummy window (disabled and hidden)
|
||||
this->m_window = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, 1, 1, NULL, NULL, GetModuleHandle(NULL), NULL);
|
||||
ShowWindow(this->m_window, SW_HIDE);
|
||||
this->m_deviceContext = GetDC(this->m_window);
|
||||
|
||||
if ( this->m_deviceContext ) this->create(shared);
|
||||
}
|
||||
UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::Settings& settings, const Context::window_t& window ) :
|
||||
uni::Context( NULL, false, settings ),
|
||||
m_deviceContext (NULL),
|
||||
m_context (NULL)
|
||||
{
|
||||
// Get the owner window and its device context
|
||||
this->m_window = window.getHandle();
|
||||
this->m_deviceContext = GetDC(this->m_window);
|
||||
|
||||
// Create the context
|
||||
if ( this->m_deviceContext )
|
||||
this->create(shared);
|
||||
}
|
||||
UF_API_CALL spec::win32::Context::Context( uni::Context* shared, const Context::Settings& settings, unsigned int width, unsigned int height ) : Context( shared, settings ) {
|
||||
|
||||
}
|
||||
spec::win32::Context::~Context() {
|
||||
this->terminate();
|
||||
}
|
||||
|
||||
void UF_API_CALL spec::win32::Context::create( uni::Context* shared ) {
|
||||
// this->m_settings = settings;
|
||||
Context::Settings l_settings(24, 4, 0, 3, 3);
|
||||
Context::Settings l_settings{24, 4, 8, 0, 3, 3};
|
||||
|
||||
int bestFormat = 0;
|
||||
if ( l_settings.antialiasingLevel > 0 ) {
|
||||
@ -322,8 +206,10 @@ void UF_API_CALL spec::win32::Context::create( uni::Context* shared ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
void UF_API_CALL spec::win32::Context::terminate() {
|
||||
#if UF_USE_OPENGL
|
||||
// Destroy the OpenGL context
|
||||
if ( this->m_context ) {
|
||||
if ( wglGetCurrentContext() == this->m_context) wglMakeCurrent(NULL, NULL);
|
||||
@ -335,19 +221,28 @@ void UF_API_CALL spec::win32::Context::terminate() {
|
||||
|
||||
// Destroy the window if we own it
|
||||
if ( this->m_window && this->m_ownsWindow ) DestroyWindow(this->m_window);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool spec::win32::Context::makeCurrent() {
|
||||
#if UF_USE_OPENGL
|
||||
return this->m_deviceContext && this->m_context && wglMakeCurrent(this->m_deviceContext, this->m_context);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void spec::win32::Context::display() {
|
||||
#if UF_USE_OPENGL
|
||||
if (this->m_deviceContext && this->m_context)
|
||||
SwapBuffers(this->m_deviceContext);
|
||||
#endif
|
||||
}
|
||||
|
||||
void spec::win32::Context::setVerticalSyncEnabled(bool enabled) {
|
||||
#if UF_USE_OPENGL
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
|
||||
if (wglSwapIntervalEXT) wglSwapIntervalEXT(enabled ? 1 : 0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user