Skip to content

Commit aa07cf3

Browse files
committed
Add GPU example (toon shading with Utah teapot)
1 parent e8b27b0 commit aa07cf3

File tree

5 files changed

+4242
-0
lines changed

5 files changed

+4242
-0
lines changed

graphics/gpu/toon_shading/Makefile

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
5+
ifeq ($(strip $(DEVKITARM)),)
6+
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
7+
endif
8+
9+
TOPDIR ?= $(CURDIR)
10+
include $(DEVKITARM)/3ds_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+
#
19+
# NO_SMDH: if set to anything, no SMDH file is generated.
20+
# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
21+
# APP_TITLE is the name of the app stored in the SMDH file (Optional)
22+
# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
23+
# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
24+
# ICON is the filename of the icon (.png), relative to the project folder.
25+
# If not set, it attempts to use one of the following (in this order):
26+
# - <Project name>.png
27+
# - icon.png
28+
# - <libctru folder>/default_icon.png
29+
#---------------------------------------------------------------------------------
30+
TARGET := $(notdir $(CURDIR))
31+
BUILD := build
32+
SOURCES := source
33+
DATA := data
34+
INCLUDES := include
35+
#ROMFS := romfs
36+
37+
#---------------------------------------------------------------------------------
38+
# options for code generation
39+
#---------------------------------------------------------------------------------
40+
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
41+
42+
CFLAGS := -g -Wall -O2 -mword-relocations \
43+
-fomit-frame-pointer -ffunction-sections \
44+
$(ARCH)
45+
46+
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
47+
48+
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
49+
50+
ASFLAGS := -g $(ARCH)
51+
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
52+
53+
LIBS := -lcitro3d -lctru -lm
54+
55+
#---------------------------------------------------------------------------------
56+
# list of directories containing libraries, this must be the top level containing
57+
# include and lib
58+
#---------------------------------------------------------------------------------
59+
LIBDIRS := $(CTRULIB)
60+
61+
62+
#---------------------------------------------------------------------------------
63+
# no real need to edit anything past this point unless you need to add additional
64+
# rules for different file extensions
65+
#---------------------------------------------------------------------------------
66+
ifneq ($(BUILD),$(notdir $(CURDIR)))
67+
#---------------------------------------------------------------------------------
68+
69+
export OUTPUT := $(CURDIR)/$(TARGET)
70+
export TOPDIR := $(CURDIR)
71+
72+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
73+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
74+
75+
export DEPSDIR := $(CURDIR)/$(BUILD)
76+
77+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
78+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
79+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
80+
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
81+
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
82+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
83+
84+
#---------------------------------------------------------------------------------
85+
# use CXX for linking C++ projects, CC for standard C
86+
#---------------------------------------------------------------------------------
87+
ifeq ($(strip $(CPPFILES)),)
88+
#---------------------------------------------------------------------------------
89+
export LD := $(CC)
90+
#---------------------------------------------------------------------------------
91+
else
92+
#---------------------------------------------------------------------------------
93+
export LD := $(CXX)
94+
#---------------------------------------------------------------------------------
95+
endif
96+
#---------------------------------------------------------------------------------
97+
98+
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
99+
100+
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \
101+
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o)
102+
103+
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
104+
105+
export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))
106+
107+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
108+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
109+
-I$(CURDIR)/$(BUILD)
110+
111+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
112+
113+
ifeq ($(strip $(ICON)),)
114+
icons := $(wildcard *.png)
115+
ifneq (,$(findstring $(TARGET).png,$(icons)))
116+
export APP_ICON := $(TOPDIR)/$(TARGET).png
117+
else
118+
ifneq (,$(findstring icon.png,$(icons)))
119+
export APP_ICON := $(TOPDIR)/icon.png
120+
endif
121+
endif
122+
else
123+
export APP_ICON := $(TOPDIR)/$(ICON)
124+
endif
125+
126+
ifeq ($(strip $(NO_SMDH)),)
127+
export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
128+
endif
129+
130+
ifneq ($(ROMFS),)
131+
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
132+
endif
133+
134+
.PHONY: $(BUILD) clean all
135+
136+
#---------------------------------------------------------------------------------
137+
all: $(BUILD)
138+
139+
$(BUILD):
140+
@[ -d $@ ] || mkdir -p $@
141+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
142+
143+
#---------------------------------------------------------------------------------
144+
clean:
145+
@echo clean ...
146+
@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf
147+
148+
149+
#---------------------------------------------------------------------------------
150+
else
151+
152+
DEPENDS := $(OFILES:.o=.d)
153+
154+
#---------------------------------------------------------------------------------
155+
# main targets
156+
#---------------------------------------------------------------------------------
157+
ifeq ($(strip $(NO_SMDH)),)
158+
$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
159+
else
160+
$(OUTPUT).3dsx : $(OUTPUT).elf
161+
endif
162+
163+
$(OFILES_SOURCES) : $(HFILES)
164+
165+
$(OUTPUT).elf : $(OFILES)
166+
167+
#---------------------------------------------------------------------------------
168+
# you need a rule like this for each extension you use as binary data
169+
#---------------------------------------------------------------------------------
170+
%.bin.o %_bin.h : %.bin
171+
#---------------------------------------------------------------------------------
172+
@echo $(notdir $<)
173+
@$(bin2o)
174+
175+
#---------------------------------------------------------------------------------
176+
# rules for assembling GPU shaders
177+
#---------------------------------------------------------------------------------
178+
define shader-as
179+
$(eval CURBIN := $*.shbin)
180+
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
181+
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
182+
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
183+
picasso -o $(CURBIN) $1
184+
bin2s $(CURBIN) | $(AS) -o $*.shbin.o
185+
endef
186+
187+
%.shbin.o %_shbin.h : %.v.pica
188+
@echo $(notdir $<)
189+
@$(call shader-as,$<)
190+
191+
-include $(DEPENDS)
192+
193+
#---------------------------------------------------------------------------------------
194+
endif
195+
#---------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)