Skip to content

Commit bbd8727

Browse files
committed
Add deko3d GPU-rendered console example
1 parent 36dff0d commit bbd8727

File tree

6 files changed

+899
-0
lines changed

6 files changed

+899
-0
lines changed

graphics/deko3d/deko_console/Makefile

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
5+
ifeq ($(strip $(DEVKITPRO)),)
6+
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
7+
endif
8+
9+
TOPDIR ?= $(CURDIR)
10+
include $(DEVKITPRO)/libnx/switch_rules
11+
12+
#---------------------------------------------------------------------------------
13+
# TARGET is the name of the output
14+
# BUILD is the directory where object files & intermediate files will be placed
15+
# SOURCES is a list of directories containing source code
16+
# DATA is a list of directories containing data files
17+
# INCLUDES is a list of directories containing header files
18+
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
19+
#
20+
# NO_ICON: if set to anything, do not use icon.
21+
# NO_NACP: if set to anything, no .nacp file is generated.
22+
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
23+
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
24+
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
25+
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
26+
# ICON is the filename of the icon (.jpg), relative to the project folder.
27+
# If not set, it attempts to use one of the following (in this order):
28+
# - <Project name>.jpg
29+
# - icon.jpg
30+
# - <libnx folder>/default_icon.jpg
31+
#
32+
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
33+
# If not set, it attempts to use one of the following (in this order):
34+
# - <Project name>.json
35+
# - config.json
36+
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
37+
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
38+
# NACP building is skipped as well.
39+
#---------------------------------------------------------------------------------
40+
TARGET := $(notdir $(CURDIR))
41+
BUILD := build
42+
SOURCES := source
43+
DATA := data
44+
INCLUDES := include
45+
ROMFS := romfs
46+
47+
# Output folders for autogenerated files in romfs
48+
OUT_SHADERS := shaders
49+
50+
#---------------------------------------------------------------------------------
51+
# options for code generation
52+
#---------------------------------------------------------------------------------
53+
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
54+
55+
CFLAGS := -g -Wall -O2 -ffunction-sections \
56+
$(ARCH) $(DEFINES)
57+
58+
CFLAGS += $(INCLUDE) -D__SWITCH__
59+
60+
CXXFLAGS := $(CFLAGS) -std=gnu++17 -fno-exceptions -fno-rtti
61+
62+
ASFLAGS := -g $(ARCH)
63+
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
64+
65+
LIBS := -ldeko3d -lnx -lm
66+
67+
#---------------------------------------------------------------------------------
68+
# list of directories containing libraries, this must be the top level containing
69+
# include and lib
70+
#---------------------------------------------------------------------------------
71+
LIBDIRS := $(PORTLIBS) $(LIBNX)
72+
73+
74+
#---------------------------------------------------------------------------------
75+
# no real need to edit anything past this point unless you need to add additional
76+
# rules for different file extensions
77+
#---------------------------------------------------------------------------------
78+
ifneq ($(BUILD),$(notdir $(CURDIR)))
79+
#---------------------------------------------------------------------------------
80+
81+
export OUTPUT := $(CURDIR)/$(TARGET)
82+
export TOPDIR := $(CURDIR)
83+
84+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
85+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
86+
87+
export DEPSDIR := $(CURDIR)/$(BUILD)
88+
89+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
90+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
91+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
92+
GLSLFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.glsl)))
93+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
94+
95+
#---------------------------------------------------------------------------------
96+
# use CXX for linking C++ projects, CC for standard C
97+
#---------------------------------------------------------------------------------
98+
ifeq ($(strip $(CPPFILES)),)
99+
#---------------------------------------------------------------------------------
100+
export LD := $(CC)
101+
#---------------------------------------------------------------------------------
102+
else
103+
#---------------------------------------------------------------------------------
104+
export LD := $(CXX)
105+
#---------------------------------------------------------------------------------
106+
endif
107+
#---------------------------------------------------------------------------------
108+
109+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
110+
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
111+
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
112+
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
113+
114+
ifneq ($(strip $(ROMFS)),)
115+
ROMFS_TARGETS :=
116+
ROMFS_FOLDERS :=
117+
ifneq ($(strip $(OUT_SHADERS)),)
118+
ROMFS_SHADERS := $(ROMFS)/$(OUT_SHADERS)
119+
ROMFS_TARGETS += $(patsubst %.glsl, $(ROMFS_SHADERS)/%.dksh, $(GLSLFILES))
120+
ROMFS_FOLDERS += $(ROMFS_SHADERS)
121+
endif
122+
123+
export ROMFS_DEPS := $(foreach file,$(ROMFS_TARGETS),$(CURDIR)/$(file))
124+
endif
125+
126+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
127+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
128+
-I$(CURDIR)/$(BUILD)
129+
130+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
131+
132+
ifeq ($(strip $(CONFIG_JSON)),)
133+
jsons := $(wildcard *.json)
134+
ifneq (,$(findstring $(TARGET).json,$(jsons)))
135+
export APP_JSON := $(TOPDIR)/$(TARGET).json
136+
else
137+
ifneq (,$(findstring config.json,$(jsons)))
138+
export APP_JSON := $(TOPDIR)/config.json
139+
endif
140+
endif
141+
else
142+
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
143+
endif
144+
145+
ifeq ($(strip $(ICON)),)
146+
icons := $(wildcard *.jpg)
147+
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
148+
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
149+
else
150+
ifneq (,$(findstring icon.jpg,$(icons)))
151+
export APP_ICON := $(TOPDIR)/icon.jpg
152+
endif
153+
endif
154+
else
155+
export APP_ICON := $(TOPDIR)/$(ICON)
156+
endif
157+
158+
ifeq ($(strip $(NO_ICON)),)
159+
export NROFLAGS += --icon=$(APP_ICON)
160+
endif
161+
162+
ifeq ($(strip $(NO_NACP)),)
163+
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
164+
endif
165+
166+
ifneq ($(APP_TITLEID),)
167+
export NACPFLAGS += --titleid=$(APP_TITLEID)
168+
endif
169+
170+
ifneq ($(ROMFS),)
171+
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
172+
endif
173+
174+
.PHONY: all clean
175+
176+
#---------------------------------------------------------------------------------
177+
all: $(ROMFS_TARGETS) | $(BUILD)
178+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
179+
180+
$(BUILD):
181+
@mkdir -p $@
182+
183+
ifneq ($(strip $(ROMFS_TARGETS)),)
184+
185+
$(ROMFS_TARGETS): | $(ROMFS_FOLDERS)
186+
187+
$(ROMFS_FOLDERS):
188+
@mkdir -p $@
189+
190+
$(ROMFS_SHADERS)/%_vsh.dksh: %_vsh.glsl
191+
@echo {vert} $(notdir $<)
192+
@uam -s vert -o $@ $<
193+
194+
$(ROMFS_SHADERS)/%_tcsh.dksh: %_tcsh.glsl
195+
@echo {tess_ctrl} $(notdir $<)
196+
@uam -s tess_ctrl -o $@ $<
197+
198+
$(ROMFS_SHADERS)/%_tesh.dksh: %_tesh.glsl
199+
@echo {tess_eval} $(notdir $<)
200+
@uam -s tess_eval -o $@ $<
201+
202+
$(ROMFS_SHADERS)/%_gsh.dksh: %_gsh.glsl
203+
@echo {geom} $(notdir $<)
204+
@uam -s geom -o $@ $<
205+
206+
$(ROMFS_SHADERS)/%_fsh.dksh: %_fsh.glsl
207+
@echo {frag} $(notdir $<)
208+
@uam -s frag -o $@ $<
209+
210+
$(ROMFS_SHADERS)/%.dksh: %.glsl
211+
@echo {comp} $(notdir $<)
212+
@uam -s comp -o $@ $<
213+
214+
endif
215+
216+
#---------------------------------------------------------------------------------
217+
clean:
218+
@echo clean ...
219+
ifeq ($(strip $(APP_JSON)),)
220+
@rm -fr $(BUILD) $(ROMFS_FOLDERS) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
221+
else
222+
@rm -fr $(BUILD) $(ROMFS_FOLDERS) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
223+
endif
224+
225+
226+
#---------------------------------------------------------------------------------
227+
else
228+
.PHONY: all
229+
230+
DEPENDS := $(OFILES:.o=.d)
231+
232+
#---------------------------------------------------------------------------------
233+
# main targets
234+
#---------------------------------------------------------------------------------
235+
ifeq ($(strip $(APP_JSON)),)
236+
237+
all : $(OUTPUT).nro
238+
239+
ifeq ($(strip $(NO_NACP)),)
240+
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp $(ROMFS_DEPS)
241+
else
242+
$(OUTPUT).nro : $(OUTPUT).elf $(ROMFS_DEPS)
243+
endif
244+
245+
else
246+
247+
all : $(OUTPUT).nsp
248+
249+
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
250+
251+
$(OUTPUT).nso : $(OUTPUT).elf
252+
253+
endif
254+
255+
$(OUTPUT).elf : $(OFILES)
256+
257+
$(OFILES_SRC) : $(HFILES_BIN)
258+
259+
#---------------------------------------------------------------------------------
260+
# you need a rule like this for each extension you use as binary data
261+
#---------------------------------------------------------------------------------
262+
%.bin.o %_bin.h : %.bin
263+
#---------------------------------------------------------------------------------
264+
@echo $(notdir $<)
265+
@$(bin2o)
266+
267+
-include $(DEPENDS)
268+
269+
#---------------------------------------------------------------------------------------
270+
endif
271+
#---------------------------------------------------------------------------------------
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#version 460
2+
3+
layout (location = 0) noperspective in vec3 inTexCoord;
4+
layout (location = 1) flat in vec4 inFrontPal;
5+
layout (location = 2) flat in vec4 inBackPal;
6+
7+
layout (location = 0) out vec4 outColor;
8+
9+
layout (binding = 0) uniform sampler2DArray tileset;
10+
11+
void main()
12+
{
13+
float value = texture(tileset, inTexCoord).r;
14+
outColor = mix(inBackPal, inFrontPal, value);
15+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#version 460
2+
3+
layout (location = 0) in float inTileId;
4+
layout (location = 1) in uvec2 inColorId;
5+
6+
layout (location = 0) out vec3 outTexCoord;
7+
layout (location = 1) out vec4 outFrontPal;
8+
layout (location = 2) out vec4 outBackPal;
9+
10+
layout (std140, binding = 0) uniform Config
11+
{
12+
vec4 dimensions;
13+
vec4 vertices[3];
14+
vec4 palettes[24];
15+
} u;
16+
17+
void main()
18+
{
19+
float id = float(gl_InstanceID);
20+
float tileRow = floor(id / u.dimensions.z);
21+
float tileCol = id - tileRow * u.dimensions.z;
22+
23+
vec2 basePos;
24+
basePos.x = 2.0 * (tileCol + 0.5) / u.dimensions.z - 1.0;
25+
basePos.y = 2.0 * (1.0 - (tileRow + 0.5) / u.dimensions.w) - 1.0;
26+
27+
vec2 vtxData = u.vertices[gl_VertexID].xy;
28+
vec2 scale = vec2(1.0) / u.dimensions.zw;
29+
gl_Position.xy = vtxData * scale + basePos;
30+
gl_Position.zw = vec2(0.5, 1.0);
31+
32+
outTexCoord = vec3(u.vertices[gl_VertexID].zw, inTileId);
33+
outFrontPal = u.palettes[inColorId.x];
34+
outBackPal = u.palettes[inColorId.y];
35+
}

0 commit comments

Comments
 (0)