From f74c7b19edd03b8d8d5cfa5fb7f5b79850d96e7e Mon Sep 17 00:00:00 2001 From: fincs Date: Thu, 24 Dec 2015 12:42:45 +0100 Subject: [PATCH] Examples have been moved to https://github.com/devkitPro/3ds-examples --- examples/Makefile | 20 -- examples/fragment_light/Makefile | 196 -------------- examples/fragment_light/source/main.c | 242 ------------------ examples/fragment_light/source/vshader.v.pica | 73 ------ examples/geoshader/Makefile | 196 -------------- examples/geoshader/source/main.c | 130 ---------- examples/geoshader/source/program.g.pica | 93 ------- examples/geoshader/source/program.v.pica | 25 -- examples/gputest/Makefile | 175 ------------- examples/gputest/data/grass.bin | 1 - examples/gputest/source/main.c | 212 --------------- examples/gputest/source/test_gsh.shader | 93 ------- examples/gputest/source/test_vsh.shader | 52 ---- examples/immediate/Makefile | 196 -------------- examples/immediate/source/main.c | 113 -------- examples/immediate/source/vshader.v.pica | 38 --- examples/simple_tri/Makefile | 196 -------------- examples/simple_tri/source/main.c | 131 ---------- examples/simple_tri/source/vshader.v.pica | 38 --- examples/textured_cube/Makefile | 196 -------------- examples/textured_cube/data/kitten.bin | Bin 16384 -> 0 bytes examples/textured_cube/source/main.c | 229 ----------------- examples/textured_cube/source/vshader.v.pica | 87 ------- 23 files changed, 2732 deletions(-) delete mode 100644 examples/Makefile delete mode 100644 examples/fragment_light/Makefile delete mode 100644 examples/fragment_light/source/main.c delete mode 100644 examples/fragment_light/source/vshader.v.pica delete mode 100644 examples/geoshader/Makefile delete mode 100644 examples/geoshader/source/main.c delete mode 100644 examples/geoshader/source/program.g.pica delete mode 100644 examples/geoshader/source/program.v.pica delete mode 100644 examples/gputest/Makefile delete mode 100644 examples/gputest/data/grass.bin delete mode 100644 examples/gputest/source/main.c delete mode 100644 examples/gputest/source/test_gsh.shader delete mode 100644 examples/gputest/source/test_vsh.shader delete mode 100644 examples/immediate/Makefile delete mode 100644 examples/immediate/source/main.c delete mode 100644 examples/immediate/source/vshader.v.pica delete mode 100644 examples/simple_tri/Makefile delete mode 100644 examples/simple_tri/source/main.c delete mode 100644 examples/simple_tri/source/vshader.v.pica delete mode 100644 examples/textured_cube/Makefile delete mode 100644 examples/textured_cube/data/kitten.bin delete mode 100644 examples/textured_cube/source/main.c delete mode 100644 examples/textured_cube/source/vshader.v.pica diff --git a/examples/Makefile b/examples/Makefile deleted file mode 100644 index 7d46ae8..0000000 --- a/examples/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -SUBDIRS:= $(shell ls | egrep -v '^(CVS)$$') - -DATESTRING := $(shell date +%Y)$(shell date +%m)$(shell date +%d) - -#--------------------------------------------------------------------------------- -all: examples -#--------------------------------------------------------------------------------- - @rm -fr bin - @mkdir -p bin - @find . -name "*.3dsx" ! -path "./bin/*" -exec cp -fv {} bin \; - -examples: - @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; - -#--------------------------------------------------------------------------------- -clean: -#--------------------------------------------------------------------------------- - @rm -fr bin - @rm -f *.bz2 - @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; diff --git a/examples/fragment_light/Makefile b/examples/fragment_light/Makefile deleted file mode 100644 index a6103f0..0000000 --- a/examples/fragment_light/Makefile +++ /dev/null @@ -1,196 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -TOPDIR ?= $(CURDIR) -include $(DEVKITARM)/3ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# -# NO_SMDH: if set to anything, no SMDH file is generated. -# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) -# APP_TITLE is the name of the app stored in the SMDH file (Optional) -# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) -# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) -# ICON is the filename of the icon (.png), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .png -# - icon.png -# - /default_icon.png -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include -#ROMFS := romfs - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft - -CFLAGS := -g -Wall -O2 -mword-relocations \ - -fomit-frame-pointer -ffunction-sections \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM11 -D_3DS - -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lcitro3d -lctru -lm - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) -SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.png) - ifneq (,$(findstring $(TARGET).png,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).png - else - ifneq (,$(findstring icon.png,$(icons))) - export APP_ICON := $(TOPDIR)/icon.png - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_SMDH)),) - export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh -endif - -ifneq ($(ROMFS),) - export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) -endif - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -ifeq ($(strip $(NO_SMDH)),) -$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh -else -$(OUTPUT).3dsx : $(OUTPUT).elf -endif - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - -#--------------------------------------------------------------------------------- -# rules for assembling GPU shaders -#--------------------------------------------------------------------------------- -define shader-as - $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@))) - picasso -o $(CURBIN) $1 - bin2s $(CURBIN) | $(AS) -o $@ - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h - echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h -endef - -%.shbin.o : %.v.pica %.g.pica - @echo $(notdir $^) - @$(call shader-as,$^) - -%.shbin.o : %.v.pica - @echo $(notdir $<) - @$(call shader-as,$<) - -%.shbin.o : %.shlist - @echo $(notdir $<) - @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file))) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/examples/fragment_light/source/main.c b/examples/fragment_light/source/main.c deleted file mode 100644 index 853aee4..0000000 --- a/examples/fragment_light/source/main.c +++ /dev/null @@ -1,242 +0,0 @@ -#include <3ds.h> -#include -#include -#include "vshader_shbin.h" - -#define CLEAR_COLOR 0x68B0D8FF - -#define DISPLAY_TRANSFER_FLAGS \ - (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ - GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ - GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) - -typedef struct { float position[3]; float texcoord[2]; float normal[3]; } vertex; - -static const vertex vertex_list[] = -{ - // First face (PZ) - // First triangle - { {-0.5f, -0.5f, +0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, +1.0f} }, - { {+0.5f, -0.5f, +0.5f}, {1.0f, 0.0f}, {0.0f, 0.0f, +1.0f} }, - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, +1.0f} }, - // Second triangle - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, +1.0f} }, - { {-0.5f, +0.5f, +0.5f}, {0.0f, 1.0f}, {0.0f, 0.0f, +1.0f} }, - { {-0.5f, -0.5f, +0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, +1.0f} }, - - // Second face (MZ) - // First triangle - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, - { {-0.5f, +0.5f, -0.5f}, {1.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, - { {+0.5f, +0.5f, -0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, -1.0f} }, - // Second triangle - { {+0.5f, +0.5f, -0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, -1.0f} }, - { {+0.5f, -0.5f, -0.5f}, {0.0f, 1.0f}, {0.0f, 0.0f, -1.0f} }, - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, - - // Third face (PX) - // First triangle - { {+0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, +0.5f, -0.5f}, {1.0f, 0.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {+1.0f, 0.0f, 0.0f} }, - // Second triangle - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, -0.5f, +0.5f}, {0.0f, 1.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {+1.0f, 0.0f, 0.0f} }, - - // Fourth face (MX) - // First triangle - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, -0.5f, +0.5f}, {1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} }, - // Second triangle - { {-0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, +0.5f, -0.5f}, {0.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} }, - - // Fifth face (PY) - // First triangle - { {-0.5f, +0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, +1.0f, 0.0f} }, - { {-0.5f, +0.5f, +0.5f}, {1.0f, 0.0f}, {0.0f, +1.0f, 0.0f} }, - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, +1.0f, 0.0f} }, - // Second triangle - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, +1.0f, 0.0f} }, - { {+0.5f, +0.5f, -0.5f}, {0.0f, 1.0f}, {0.0f, +1.0f, 0.0f} }, - { {-0.5f, +0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, +1.0f, 0.0f} }, - - // Sixth face (MY) - // First triangle - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, -1.0f, 0.0f} }, - { {+0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, {0.0f, -1.0f, 0.0f} }, - { {+0.5f, -0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, -1.0f, 0.0f} }, - // Second triangle - { {+0.5f, -0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, -1.0f, 0.0f} }, - { {-0.5f, -0.5f, +0.5f}, {0.0f, 1.0f}, {0.0f, -1.0f, 0.0f} }, - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, -1.0f, 0.0f} }, -}; - -#define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) - -static DVLB_s* vshader_dvlb; -static shaderProgram_s program; -static int uLoc_projection, uLoc_modelView; -static C3D_Mtx projection; - -static C3D_LightEnv lightEnv; -static C3D_Light light; -static C3D_LightLut lut_Phong; - -static void* vbo_data; -static float angleX = 0.0, angleY = 0.0; - -static void sceneInit(void) -{ - // Load the vertex shader, create a shader program and bind it - vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); - shaderProgramInit(&program); - shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); - C3D_BindProgram(&program); - - // Get the location of the uniforms - uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); - uLoc_modelView = shaderInstanceGetUniformLocation(program.vertexShader, "modelView"); - - // Configure attributes for use with the vertex shader - C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); - AttrInfo_Init(attrInfo); - AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position - AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2); // v1=texcoord - AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 3); // v2=normal - - // Create the VBO (vertex buffer object) - vbo_data = linearAlloc(sizeof(vertex_list)); - memcpy(vbo_data, vertex_list, sizeof(vertex_list)); - - // Configure buffers - C3D_BufInfo* bufInfo = C3D_GetBufInfo(); - BufInfo_Init(bufInfo); - BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 3, 0x210); - - // Configure the first fragment shading substage to blend the fragment primary color - // with the fragment secondary color. - // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight - C3D_TexEnv* env = C3D_GetTexEnv(0); - C3D_TexEnvSrc(env, C3D_Both, GPU_FRAGMENT_PRIMARY_COLOR, GPU_FRAGMENT_SECONDARY_COLOR, 0); - C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); - C3D_TexEnvFunc(env, C3D_Both, GPU_ADD); - - static const C3D_Material material = - { - { 0.2f, 0.2f, 0.2f }, //ambient - { 0.4f, 0.4f, 0.4f }, //diffuse - { 0.8f, 0.8f, 0.8f }, //specular0 - { 0.0f, 0.0f, 0.0f }, //specular1 - { 0.0f, 0.0f, 0.0f }, //emission - }; - - C3D_LightEnvInit(&lightEnv); - C3D_LightEnvBind(&lightEnv); - C3D_LightEnvMaterial(&lightEnv, &material); - - LightLut_Phong(&lut_Phong, 30); - C3D_LightEnvLut(&lightEnv, GPU_LUT_D0, GPU_LUTINPUT_LN, false, &lut_Phong); - - C3D_FVec lightVec = { { 1.0, -0.5, 0.0, 0.0 } }; - - C3D_LightInit(&light, &lightEnv); - C3D_LightColor(&light, 1.0, 1.0, 1.0); - C3D_LightPosition(&light, &lightVec); -} - -static void sceneRender(float iod) -{ - // Compute the projection matrix - Mtx_PerspStereoTilt(&projection, 40.0f*M_PI/180.0f, 400.0f/240.0f, 0.01f, 1000.0f, iod, 2.0f); - - // Calculate the modelView matrix - C3D_Mtx modelView; - Mtx_Identity(&modelView); - Mtx_Translate(&modelView, 0.0, 0.0, -4.0 + sinf(angleX)); - Mtx_RotateX(&modelView, angleX, true); - Mtx_RotateY(&modelView, angleY, true); - - // Rotate the cube each frame - if (iod >= 0.0f) - { - angleX += M_PI / 180; - angleY += M_PI / 360; - } - - // Update the uniforms - C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); - C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_modelView, &modelView); - - // Draw the VBO - C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); -} - -static void sceneExit(void) -{ - // Free the VBO - linearFree(vbo_data); - - // Free the shader program - shaderProgramFree(&program); - DVLB_Free(vshader_dvlb); -} - -int main() -{ - // Initialize graphics - gfxInitDefault(); - gfxSet3D(true); - - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - - // Initialize the renderbuffer - static C3D_RenderBuf rb; - C3D_RenderBufInit(&rb, 240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - rb.clearColor = CLEAR_COLOR; - C3D_RenderBufClear(&rb); - C3D_RenderBufBind(&rb); - - // Initialize the scene - sceneInit(); - - // Main loop - while (aptMainLoop()) - { - C3D_VideoSync(); - hidScanInput(); - - // Respond to user input - u32 kDown = hidKeysDown(); - if (kDown & KEY_START) - break; // break in order to return to hbmenu - - float slider = osGet3DSliderState(); - float iod = slider/3; - - // Render the scene - sceneRender(-iod); - C3D_Flush(); - C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); - C3D_RenderBufClear(&rb); - - if (iod > 0.0f) - { - sceneRender(iod); - C3D_Flush(); - C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); - C3D_RenderBufClear(&rb); - } - } - - // Deinitialize the scene - sceneExit(); - - // Deinitialize graphics - C3D_Fini(); - gfxExit(); - return 0; -} diff --git a/examples/fragment_light/source/vshader.v.pica b/examples/fragment_light/source/vshader.v.pica deleted file mode 100644 index e994949..0000000 --- a/examples/fragment_light/source/vshader.v.pica +++ /dev/null @@ -1,73 +0,0 @@ -; Example PICA200 vertex shader - -; Uniforms -.fvec projection[4], modelView[4] - -; Constants -.constf myconst(0.0, 1.0, -1.0, 0.5) -.alias zeros myconst.xxxx ; Vector full of zeros -.alias ones myconst.yyyy ; Vector full of ones -.alias half myconst.wwww - -; Outputs -.out outpos position -.out outtc0 texcoord0 -.out outclr color -.out outview view -.out outnq normalquat - -; Inputs (defined as aliases for convenience) -.alias inpos v0 -.alias intex v1 -.alias innrm v2 - -.proc main - ; Force the w component of inpos to be 1.0 - mov r0.xyz, inpos - mov r0.w, ones - - ; r1 = modelView * inpos - dp4 r1.x, modelView[0], r0 - dp4 r1.y, modelView[1], r0 - dp4 r1.z, modelView[2], r0 - dp4 r1.w, modelView[3], r0 - - ; outview = -r1 - mov outview, -r1 - - ; outpos = projection * r1 - dp4 outpos.x, projection[0], r1 - dp4 outpos.y, projection[1], r1 - dp4 outpos.z, projection[2], r1 - dp4 outpos.w, projection[3], r1 - - ; outtex = intex - mov outtc0, intex - - ; Transform the normal vector with the modelView matrix - ; TODO: use a separate normal matrix that is the transpose of the inverse of modelView - dp3 r14.x, modelView[0], innrm - dp3 r14.y, modelView[1], innrm - dp3 r14.z, modelView[2], innrm - dp3 r6.x, r14, r14 - rsq r6.x, r6.x - mul r14.xyz, r14.xyz, r6.x - - mov r0, myconst.yxxx - add r4, ones, r14.z - mul r4, half, r4 - cmp zeros, ge, ge, r4.x - rsq r4, r4.x - mul r5, half, r14 - jmpc cmp.x, degenerate - - rcp r0.z, r4.x - mul r0.xy, r5, r4 - -degenerate: - mov outnq, r0 - mov outclr, ones - - ; We're finished - end -.end diff --git a/examples/geoshader/Makefile b/examples/geoshader/Makefile deleted file mode 100644 index a6103f0..0000000 --- a/examples/geoshader/Makefile +++ /dev/null @@ -1,196 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -TOPDIR ?= $(CURDIR) -include $(DEVKITARM)/3ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# -# NO_SMDH: if set to anything, no SMDH file is generated. -# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) -# APP_TITLE is the name of the app stored in the SMDH file (Optional) -# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) -# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) -# ICON is the filename of the icon (.png), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .png -# - icon.png -# - /default_icon.png -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include -#ROMFS := romfs - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft - -CFLAGS := -g -Wall -O2 -mword-relocations \ - -fomit-frame-pointer -ffunction-sections \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM11 -D_3DS - -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lcitro3d -lctru -lm - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) -SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.png) - ifneq (,$(findstring $(TARGET).png,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).png - else - ifneq (,$(findstring icon.png,$(icons))) - export APP_ICON := $(TOPDIR)/icon.png - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_SMDH)),) - export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh -endif - -ifneq ($(ROMFS),) - export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) -endif - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -ifeq ($(strip $(NO_SMDH)),) -$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh -else -$(OUTPUT).3dsx : $(OUTPUT).elf -endif - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - -#--------------------------------------------------------------------------------- -# rules for assembling GPU shaders -#--------------------------------------------------------------------------------- -define shader-as - $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@))) - picasso -o $(CURBIN) $1 - bin2s $(CURBIN) | $(AS) -o $@ - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h - echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h -endef - -%.shbin.o : %.v.pica %.g.pica - @echo $(notdir $^) - @$(call shader-as,$^) - -%.shbin.o : %.v.pica - @echo $(notdir $<) - @$(call shader-as,$<) - -%.shbin.o : %.shlist - @echo $(notdir $<) - @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file))) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/examples/geoshader/source/main.c b/examples/geoshader/source/main.c deleted file mode 100644 index 65f1014..0000000 --- a/examples/geoshader/source/main.c +++ /dev/null @@ -1,130 +0,0 @@ -#include <3ds.h> -#include -#include -#include "program_shbin.h" - -#define CLEAR_COLOR 0x68B0D8FF - -#define DISPLAY_TRANSFER_FLAGS \ - (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ - GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ - GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) - -typedef struct { float position[3]; float color[4]; } vertex; - -static const vertex vertex_list[] = -{ - { {200.0f, 200.0f, 0.5f}, {1.0f, 0.0f, 0.0f, 1.0f} }, - { {100.0f, 40.0f, 0.5f}, {0.0f, 1.0f, 0.0f, 1.0f} }, - { {300.0f, 40.0f, 0.5f}, {0.0f, 0.0f, 1.0f, 1.0f} }, -}; - -#define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) - -static DVLB_s* program_dvlb; -static shaderProgram_s program; -static int uLoc_projection; -static C3D_Mtx projection; - -static void* vbo_data; - -static void sceneInit(void) -{ - // Load the shaders and create a shader program - // The geoshader stride is set to 6 so that it processes a triangle at a time - program_dvlb = DVLB_ParseFile((u32*)program_shbin, program_shbin_size); - shaderProgramInit(&program); - shaderProgramSetVsh(&program, &program_dvlb->DVLE[0]); - shaderProgramSetGsh(&program, &program_dvlb->DVLE[1], 6); - C3D_BindProgram(&program); - - // Get the location of the projection matrix uniform - uLoc_projection = shaderInstanceGetUniformLocation(program.geometryShader, "projection"); - - // Configure attributes for use with the vertex shader - C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); - AttrInfo_Init(attrInfo); - AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position - AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 4); // v1=color - - // Compute the projection matrix - Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0); - - // Create the VBO (vertex buffer object) - vbo_data = linearAlloc(sizeof(vertex_list)); - memcpy(vbo_data, vertex_list, sizeof(vertex_list)); - - // Configure buffers - C3D_BufInfo* bufInfo = C3D_GetBufInfo(); - BufInfo_Init(bufInfo); - BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 2, 0x10); - - // Configure the first fragment shading substage to just pass through the vertex color - // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight - C3D_TexEnv* env = C3D_GetTexEnv(0); - C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); - C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); - C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); -} - -static void sceneRender(void) -{ - // Update the uniforms - C3D_FVUnifMtx4x4(GPU_GEOMETRY_SHADER, uLoc_projection, &projection); - - // Draw the VBO - GPU_GEOMETRY_PRIM allows the geoshader to control primitive emission - C3D_DrawArrays(GPU_GEOMETRY_PRIM, 0, vertex_list_count); -} - -static void sceneExit(void) -{ - // Free the VBO - linearFree(vbo_data); - - // Free the shader program - shaderProgramFree(&program); - DVLB_Free(program_dvlb); -} - -int main() -{ - // Initialize graphics - gfxInitDefault(); - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - - // Initialize the renderbuffer - static C3D_RenderBuf rb; - C3D_RenderBufInit(&rb, 240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - rb.clearColor = CLEAR_COLOR; - C3D_RenderBufClear(&rb); - C3D_RenderBufBind(&rb); - - // Initialize the scene - sceneInit(); - - // Main loop - while (aptMainLoop()) - { - C3D_VideoSync(); - hidScanInput(); - - // Respond to user input - u32 kDown = hidKeysDown(); - if (kDown & KEY_START) - break; // break in order to return to hbmenu - - // Render the scene - sceneRender(); - C3D_Flush(); - C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); - C3D_RenderBufClear(&rb); - } - - // Deinitialize the scene - sceneExit(); - - // Deinitialize graphics - C3D_Fini(); - gfxExit(); - return 0; -} diff --git a/examples/geoshader/source/program.g.pica b/examples/geoshader/source/program.g.pica deleted file mode 100644 index 961ab9a..0000000 --- a/examples/geoshader/source/program.g.pica +++ /dev/null @@ -1,93 +0,0 @@ -; Example PICA200 geometry shader - -; Uniforms -.fvec projection[4] - -; Constants -.constf myconst(0.0, 1.0, -1.0, 0.5) -.alias zeros myconst.xxxx ; Vector full of zeros -.alias ones myconst.yyyy ; Vector full of ones -.alias half myconst.wwww - -; Outputs - this time the type *is* used -.out outpos position -.out outclr color - -; Inputs: we will receive the following inputs: -; v0-v1: position/color of the first vertex -; v2-v3: position/color of the second vertex -; v4-v5: position/color of the third vertex - -.gsh -.entry gmain -.proc gmain - ; Calculate the midpoints of the vertices - mov r4, v0 - add r4, v2, r4 - mul r4, half, r4 - mov r5, v2 - add r5, v4, r5 - mul r5, half, r5 - mov r6, v4 - add r6, v0, r6 - mul r6, half, r6 - - ; Emit the first triangle - mov r0, v0 - mov r1, r4 - mov r2, r6 - call emit_triangle - - ; Emit the second triangle - mov r0, r4 - mov r1, v2 - mov r2, r5 - call emit_triangle - - ; Emit the third triangle - mov r0, r6 - mov r1, r5 - mov r2, v4 - call emit_triangle - - ; We're finished - end -.end - -.proc emit_triangle - ; Emit the first vertex - setemit 0 - mov r8, r0 - mov r9, v1 - call process_vertex - emit - - ; Emit the second vertex - setemit 1 - mov r8, r1 - mov r9, v3 - call process_vertex - emit - - ; Emit the third vertex and finish the primitive - setemit 2, prim - mov r8, r2 - mov r9, v5 - call process_vertex - emit -.end - -; Subroutine -; Inputs: -; r8: vertex position -; r9: vertex color -.proc process_vertex - ; outpos = projectionMatrix * r8 - dp4 outpos.x, projection[0], r8 - dp4 outpos.y, projection[1], r8 - dp4 outpos.z, projection[2], r8 - dp4 outpos.w, projection[3], r8 - - ; outclr = r9 - mov outclr, r9 -.end diff --git a/examples/geoshader/source/program.v.pica b/examples/geoshader/source/program.v.pica deleted file mode 100644 index 80d67fb..0000000 --- a/examples/geoshader/source/program.v.pica +++ /dev/null @@ -1,25 +0,0 @@ -; Example PICA200 vertex shader - -; Constants -.constf myconst(0.0, 1.0, -1.0, -0.5) -.alias zeros myconst.xxxx ; Vector full of zeros -.alias ones myconst.yyyy ; Vector full of ones - -; Outputs - since we are also using a geoshader the output type isn't really used -.out outpos position -.out outclr color - -; Inputs (defined as aliases for convenience) -.alias inpos v0 -.alias inclr v1 - -.entry vmain -.proc vmain - ; Pass through both inputs to the geoshader - mov outpos.xyz, inpos - mov outpos.w, ones - mov outclr, inclr - - ; We're finished - end -.end diff --git a/examples/gputest/Makefile b/examples/gputest/Makefile deleted file mode 100644 index 70bae14..0000000 --- a/examples/gputest/Makefile +++ /dev/null @@ -1,175 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -TOPDIR ?= $(CURDIR) -include $(DEVKITARM)/3ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# -# NO_SMDH: if set to anything, no SMDH file is generated. -# APP_TITLE is the name of the app stored in the SMDH file (Optional) -# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) -# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) -# ICON is the filename of the icon (.png), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .png -# - icon.png -# - /default_icon.png -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft - -CFLAGS := -g -Wall -O2 -mword-relocations \ - -fomit-frame-pointer -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM11 -D_3DS - -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lcitro3d -lctru -lm - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SHADERFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shader))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) $(SHADERFILES:.shader=.shbin.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.png) - ifneq (,$(findstring $(TARGET).png,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).png - else - ifneq (,$(findstring icon.png,$(icons))) - export APP_ICON := $(TOPDIR)/icon.png - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_SMDH)),) - export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh -endif - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -ifeq ($(strip $(NO_SMDH)),) -$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh -else -$(OUTPUT).3dsx : $(OUTPUT).elf -endif - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - -#--------------------------------------------------------------------------------- -%.shbin.o: %.shader - @echo $(notdir $<) - $(eval CURBIN := $(patsubst %.shader,%.shbin,$(notdir $<))) - $(eval CURH := $(patsubst %.shader,%.shader.h,$(notdir $<))) - @picasso -o $(CURBIN) $< -h $(CURH) - @bin2s $(CURBIN) | $(AS) -o $@ - @echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h - @echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h - @echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/examples/gputest/data/grass.bin b/examples/gputest/data/grass.bin deleted file mode 100644 index 0bbf96e..0000000 --- a/examples/gputest/data/grass.bin +++ /dev/null @@ -1 +0,0 @@ -۞ިؔ۞ި{qؔqߟިߟި{ߟިިߟ۞۞ՆݖqՆхߟؔԍި۞ԍި۞{ިqߟ۞ߟԍؔߟ{ިхߟؔߟؔ۞ڕؔؔԍިؔхؔ{ؔ۞ݖ{qߟх۞qԍ{؍۞؍ؔхڕؔԍߟߟ۞хؔݖؔިި۞ިݖߟިߟڕި۞۞۞q{х{ߟqߟ{ԍڕԍߟ۞Ն۞Նߟ{Նqؔߟхڕ{qqqхՆ؍qڕߟՆڕؔԍڕԍ{хqqݖхݖ{ݖՆڕ؍Ն{؍Նؔߟԍؔݖ۞ڕ؍{Ն{ՆߟՆؔ{Ն{ݖ؍ԍ؍ԍԍԍߟؔؔхԍхߟՆߟхԍߟؔԍ؍ߟՆх؍Նڕߟхߟڕ{ݖ{ڕؔؔߟؔިԍިؔߟڕ۞ڕ۞ؔؔڕՆؔݖԍؔ۞ߟݖڕ؍ݖ۞ߟؔߟؔ؍хՆ؍؍ՆՆ{{Ն{{{ߟх؍؍ՆՆ؍ؔՆ؍Ն{{؍{Նq{؍ؔڕؔؔ۞ڕ۞ڕߟߟхߟхިؔ۞ڕؔިڕިݖ؍ՆԍߟިڕؔؔߟԍԍߟՆՆڕхߟ{хߟԍ{ڕqߟԍхх{{х{{ԍؔ{ݖؔݖިߟߟߟߟި۞ިԍؔ۞ԍ۞ߟߟ۞ڕ۞хڕߟߟԍڕԍ۞ڕؔިؔؔԍххߟިިިިި۞۞۞ިި۞ިިՆިިި۞۞ި۞ߟ{Նԍхڕхߟхؔԍڕؔߟԍ۞ؔި{ߟхߟԍߟؔ۞ؔؔؔ۞۞ؔ؍ԍՆх۞۞ߟ۞{ԍqؔߟхިхؔؔхԍԍ۞х۞{хՆڕڕؔхڕߟ۞ؔ{ߟх۞ԍؔؔߟި۞{۞qՆߟqڕ؍q{qqՆqqߟڕԍިؔ۞ڕިхڕԍߟݖߟؔq{{ߟݖqؔqؔިхq{qхq۞qݖ{Ն؍qߟ{{ߟ{qq{q؍{{{{q{q{qqqԍݖхߟ{ߟި{۞{ؔхԍqߟ{qq{{ؔߟؔڕ{ڕڕؔՆؔՆԍڕ؍{Ն{ڕх{{qqԍߟڕߟхڕߟ۞ݖؔڕ۞ߟߟؔߟڕڕ{qՆqх۞{ڕ؍Նڕ؍ڕݖ۞ؔݖؔ؍ԍݖԍިިڕхߟؔݖߟڕؔߟ۞ؔхߟԍ{ߟՆߟх{хߟڕߟԍؔߟؔߟ؍ڕި{ؔՆߟх{{۞хؔхؔިؔި۞ިިߟхިԍڕ۞؍۞ؔؔؔؔؔߟߟؔި۞ި۞ؔ۞ڕؔԍԍх۞۞хڕިԍިԍؔߟؔߟՆ؍{Նߟؔߟؔ{ݖ؍ԍڕԍԍڕؔިߟؔݖڕݖިߟ۞ؔ۞ԍިԍؔؔ۞ؔ۞ڕؔؔ۞ڕڕՆڕ{х؍х{q{{{qхqߟ{؍хххх{qqхؔ{qqqq۞ڕ۞{ؔ{؍ިՆ۞ؔՆ؍ߟިݖ۞ߟߟߟݖ۞؍ؔߟߟڕڕхؔхՆؔ۞{ߟ{ߟххххڕؔхՆԍՆߟхԍՆߟՆqݖԍݖ۞хި؍ڕՆ{ؔ{ххߟ۞۞{ؔݖިިިх؍ߟՆڕ؍ԍݖՆԍՆххՆՆ{{{Ն{ި۞۞ؔ۞хؔ{۞۞Նؔх۞۞ި۞хؔхՆި۞۞qq{qިڕ۞х{Նхߟ؍{х{ިިߟ۞{ՆхՆхߟ{ڕ۞хؔ{؍ؔݖхԍ{ՆՆՆ{{{ԍڕхڕԍ۞ؔߟ؍؍ххؔڕԍ؍۞۞ؔ۞ԍ؍ԍՆԍ۞{ؔؔڕߟх{{{{ߟхߟՆ{{qՆхՆхԍՆڕ؍х؍ݖݖڕхх{؍{؍Ն؍۞х۞х؍ڕԍؔؔх؍Նݖؔݖؔ۞۞ؔؔ؍ؔԍߟؔхڕՆؔؔݖхՆ{{{ݖх؍{{{qՆх۞ՆؔڕՆߟх؍х؍{ххߟؔߟߟ{۞ԍ۞ڕؔՆؔڕ۞ߟؔ۞۞۞ؔިި۞۞ؔڕؔݖؔؔԍؔՆх{х۞ؔߟԍ{х{؍ߟхߟ{ؔԍ۞ؔؔ۞ߟ۞ؔؔؔؔхԍߟި۞۞۞ؔߟؔߟؔڕؔݖؔՆؔߟؔ۞۞ߟхߟ{ؔؔؔԍߟ{ߟ{Ն؍{؍Ն؍х{Ն؍؍{х{ԍ{хх{хݖхՆؔq{qՆ{ڕqՆՆqݖх۞ݖؔՆߟ{۞ߟ۞؍qި{ߟ{ՆхؔՆߟڕ۞۞ߟߟؔ{ؔ{ڕߟԍڕԍՆߟхڕхԍՆؔڕߟ؍ԍхԍݖؔՆؔх؍ԍՆݖхԍؔхߟ{ݖިؔхؔ؍ݖߟؔڕިߟ۞ߟՆ؍ؔݖх؍ԍՆؔؔؔԍߟхԍх؍Նх۞ߟ۞ߟՆ؍Ն؍ݖݖՆՆՆՆՆ؍ՆԍхՆՆ؍ՆхݖؔՆؔؔިؔިؔݖх؍Նߟ۞ߟؔ۞ԍߟ۞ߟؔ۞ި۞ԍ{Նq{{ݖ{q{{Նх{х{Նх؍{{ՆхՆՆ{{Ն{ՆՆՆq{q{ݖ{ݖqqqqqՆՆՆՆ{؍{Ն{{q{хݖߟߟՆq{qqqqqՆqqqqqq{ݖ{؍q{؍q؍{qq{{Ն{{ڕххՆ{Ն{q{ՆՆ{qqq{qՆqq{{؍{qqqqڕ؍ؔڕ؍{؍{{Ն{ՆՆх؍х؍хߟ{{ՆՆ؍{ڕхڕՆ؍ՆՆ؍ؔՆԍԍ{؍Նؔߟؔ؍Նߟхԍ۞хߟՆՆՆԍххххݖԍߟڕ؍х؍ڕߟхߟԍхߟߟ۞ߟ۞ި۞ިх؍ڕڕݖqՆ{ؔԍԍх{Ն{ؔڕݖڕхՆх{{ڕ{ԍ{q{{Ն{{{q{ݖ{{х؍ߟؔߟԍ{؍хߟ{Ն{qݖ۞ߟؔqqqՆՆ{qqݖ{ݖڕqqqqхՆqՆqԍ{{ؔqqؔ{ڕިqqՆqݖ{{ިqߟؔؔ{ߟqՆ{{{ݖ{ڕqؔqڕؔߟххՆڕ؍х{ؔ{۞{qqх۞Նڕ{хؔԍ۞ި{{ڕ{ި{ԍ۞ިؔߟިߟԍ۞۞۞ڕߟڕڕިި۞ؔިؔިިؔ۞ԍߟԍߟԍؔި۞ԍ؍хڕ۞ؔިՆڕхڕިڕި؍хߟ۞ߟ۞؍۞ڕԍڕԍڕؔިؔԍؔԍߟ۞ި۞۞ި۞۞ؔؔߟڕߟިؔިߟݖؔ؍ڕڕؔՆԍިިՆՆ{Ն۞Նqq{ݖ{Ն{ххݖхިؔՆՆݖՆؔިؔ۞ڕݖ۞ݖԍؔ؍ؔ؍ݖڕߟިߟި۞ڕ۞ڕ۞ؔ{ؔؔ{۞qިިхq{qqqqq{؍ݖԍqх{ߟߟ{ڕ{ިߟ۞ߟ{q{Ն۞ݖڕڕ؍؍ڕ؍ݖߟߟ۞хՆх؍ڕؔڕхՆݖ؍ڕqqq{ިؔިؔqх{хߟ؍ߟԍݖԍԍؔڕхڕڕԍؔԍڕݖх؍{{х{ԍ۞ԍߟݖхؔؔڕڕڕڕڕݖ؍ԍڕՆqݖ{ؔߟ۞ߟڕхؔߟݖڕԍؔڕڕ؍ڕхх{؍؍ڕхՆؔؔԍՆؔՆߟՆڕ{؍хؔ{ԍ{؍Նݖ{ՆхՆݖԍߟхڕхڕڕ{хՆхՆхݖԍڕڕؔݖؔڕؔڕؔڕڕԍߟؔݖؔڕؔ؍ڕߟؔؔ؍ڕݖԍՆq؍q؍х{Ն{{Նq{؍ݖڕڕх؍хՆؔڕؔڕڕՆڕڕ{{Ն{qqqq؍{ՆՆ{{ՆՆqڕq{؍{؍{qqqq{qq{؍qqqݖߟڕؔqqqq؍{Նqqq{qq{q{{Նхݖ{{Ն{qqՆqqqq{؍qݖqq؍qߟ؍х{ՆߟݖؔՆqՆ{Նх؍{Նؔ۞ԍڕݖ{Ն{х{{qqՆqՆ{{{qq{qq{qqqqqqqqqqq{х؍ԍqqqq{ߟqݖԍߟڕ۞ؔ۞ؔؔؔؔڕڕԍ۞ԍؔؔхՆߟ؍ߟ{хݖ۞ݖߟՆߟ{ڕхՆԍՆ{ԍؔхݖ{ݖхؔߟؔՆݖՆ؍ڕؔڕؔххݖх۞ݖՆߟхԍхՆхߟԍߟԍхߟؔߟ۞ިؔ۞Ն۞хިхߟؔߟхިߟިؔ{ڕ{ڕިڕ۞ިިؔި۞ߟڕڕި۞۞ؔݖؔڕ۞ؔԍ۞ؔؔؔхх؍ՆڕՆ؍۞Ն۞ݖՆߟхԍڕިؔި۞۞ؔؔߟߟߟڕߟԍߟ۞ߟߟ۞ߟߟ۞ߟ۞ڕߟߟڕ؍؍Նިߟ۞ߟՆхх؍ߟڕڕԍхߟڕݖڕԍ؍х؍؍ՆՆؔڕؔؔԍݖݖՆؔؔڕߟڕ{ڕqՆ{{{Ն{{{qqqqqqqqߟх؍Ն؍ݖՆՆՆՆՆՆՆՆՆ{ؔ؍ڕՆؔ؍ՆݖՆՆՆ؍хԍ{ԍ{{{{{{{qqq{qqqq{Ն؍؍؍ххݖххߟ{ߟхؔхߟ؍ՆڕՆߟؔߟхݖхߟхߟхߟхԍ؍ՆՆՆՆՆՆՆՆՆՆ{ՆՆ{ߟхߟؔߟхх۞۞۞ިԍߟݖхڕхՆхՆڕԍߟڕߟхߟхڕԍؔԍؔ؍{ݖхԍхݖ{ݖхՆݖݖqݖх{ߟݖՆڕՆххߟ{ݖ{ݖqڕqх؍ߟ{ߟqڕ{ߟڕݖߟݖԍڕ؍{хх{хިߟххqqqՆqq{qq؍{ڕݖqхqՆqؔqхՆqqڕ{ՆߟхߟިՆ{ݖq۞ԍ؍ݖхххՆqߟq۞ؔԍ۞ߟߟިх۞ݖхх۞ިхߟڕؔՆݖؔߟԍؔؔ۞ߟߟؔڕߟԍިߟԍߟ۞ިߟ۞ި۞۞ߟԍߟߟ۞ި۞ިߟ۞ڕ؍Նхݖ؍ՆՆՆ{{{{{q{ڕԍՆхڕ؍؍{{{qqՆqqq{{Ն{qqqqݖ{ߟ{Ն{ݖ{qqqqqqqqqqq{qqqqхх{Նڕڕ؍ڕ{{q{Ն؍؍Նڕڕ؍؍ؔؔԍԍՆՆՆ{Նх{{qqqq؍Ն؍{q{{{؍{؍{{{{q{{{qqq{{q{{Նؔڕԍ؍؍qՆqхՆՆՆՆ{Ն{qqqqՆq{qqq{qqqqq{{q{{{{qq{{{{qՆqՆ{ՆՆq{q{хՆԍ؍q{qq{{{х{ՆՆՆqх{{؍{ݖՆqՆqՆԍՆڕՆqՆ{Նڕ؍ݖх{{؍q{ߟq؍ߟ{ڕݖq{qqԍх{؍х؍хڕߟިՆݖԍݖؔߟхݖؔߟڕԍ{Ն{{ԍхؔڕԍߟхݖхՆՆ؍ՆՆՆ{{Նqqq{q؍ххq{ڕՆԍՆՆq{qqqqq{q{ՆqqqqՆхՆ؍ڕ۞ڕ۞ՆхqՆڕؔх؍ؔ۞ڕڕ۞۞ؔ۞؍؍ՆՆڕؔՆԍq{qq{Նq{{q{{qqqq{{{q؍хՆхqqqq{ݖqڕؔߟڕڕڕ۞ڕؔԍؔхݖؔؔԍԍ۞۞ߟؔި۞۞۞ߟ؍ߟՆڕؔՆՆ{хqqߟхݖԍqq{qՆݖ{ݖݖՆхՆ{Նq{{؍хՆq{qՆߟ۞۞ߟ۞ߟؔؔؔԍߟߟڕؔ؍ߟڕؔ؍ؔݖؔݖхх{Ն؍ՆݖՆݖߟݖؔؔхؔ؍ݖߟݖؔ؍ؔ؍{{q{ݖ{ݖՆ{ՆՆԍڕхڕؔؔԍԍߟݖqՆ{۞ߟߟх؍ԍߟ{{Նqqqq{Նq{q{{{{ިިߟڕхިިхՆ{q{Նq{{qqՆq{۞q{{Ն{ՆՆ{ՆՆ{Ն{{ՆՆ{Ն{{Ն؍ՆՆڕхՆڕхߟ۞ؔ۞ߟՆqՆ{q{qqՆڕؔߟq{q؍ԍߟߟߟ۞ިߟިިՆ{؍х؍Նڕؔݖڕߟߟԍߟؔߟԍݖх؍{{{ՆхՆх{{Ն{{ިިިިߟߟߟߟިިިިިߟՆ{؍{qqqqՆՆхՆqq{qхݖ{ՆՆq؍{q{qqՆ{{{ߟ۞ڕؔؔݖؔڕՆԍ{{ԍՆՆՆqqqqqqqq{qՆqqqqqq{qq{{Ն{qqqqՆ{ՆՆՆߟ؍ڕхՆх؍Ն؍{Ն{؍Ն{Ն{Նq{{Ն{ՆqՆ{ՆՆ{Ն{{ՆՆՆqՆqՆڕхڕڕ{ߟՆ{{{؍q{{{{ݖ{ڕхՆߟՆq{qq{{Ն{qq{{{{{qqqq{qՆ{qqՆ{Ն{qqqՆ؍{ߟ{q{qՆߟՆ۞؍{ߟՆ{Ն؍Նq{qՆߟԍԍqݖqߟՆՆՆݖ{Նq{х؍ݖ{q{qqڕ{؍{qՆ{Ն{{q{qݖqՆݖq؍qՆqՆqхՆхݖԍqݖqՆqх{{хq{ԍ؍ؔߟqqؔߟԍߟؔڕ۞ߟх۞ڕިި۞ިިڕؔ۞ߟިިߟި؍ިިՆ{ިިިިިިިި \ No newline at end of file diff --git a/examples/gputest/source/main.c b/examples/gputest/source/main.c deleted file mode 100644 index 3c92a59..0000000 --- a/examples/gputest/source/main.c +++ /dev/null @@ -1,212 +0,0 @@ -#include -#include <3ds.h> -#include -#ifdef DEBUG -#include -#endif -#include "test_vsh_shbin.h" -#include "test_vsh.shader.h" -#include "test_gsh_shbin.h" -#include "test_gsh.shader.h" -#include "grass_bin.h" - -#define EXTENDED_TOPSCR_RESOLUTION - -#ifndef EXTENDED_TOPSCR_RESOLUTION -#define TOPSCR_WIDTH 240 -#define TOPSCR_COPYFLAG 0x00001000 -#else -#define TOPSCR_WIDTH (240*2) -#define TOPSCR_COPYFLAG 0x01001000 -#endif - -#define CLEAR_COLOR 0x80FF80FF - -C3D_RenderBuf rbTop, rbBot; - -static DVLB_s *pVsh, *pGsh; -static shaderProgram_s shader; - -C3D_MtxStack projMtx, mdlvMtx; - -typedef struct -{ - float position[3]; - float texCoord[2]; - float color[3]; -} vertex_t; - -static const vertex_t vertex_list[] = -{ - // First triangle - {{-0.5f, +0.5f, -4.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, - {{-0.5f, -0.5f, -4.0f}, {0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}}, - {{+0.5f, -0.5f, -4.0f}, {1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, - - // Second triangle - {{+0.5f, -0.5f, -4.0f}, {1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}, - {{+0.5f, +0.5f, -4.0f}, {1.0f, 1.0f}, {1.0f, 1.0f, 0.0f}}, - {{-0.5f, +0.5f, -4.0f}, {0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}}, -}; - -#define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) - -#define FOVY (2.0f/15) - -static void* myVbo; -static C3D_Tex myTex; - -static void drawScene(float trX, float trY) -{ - C3D_RenderBufBind(&rbTop); - - C3D_TexBind(0, &myTex); - - C3D_TexEnv* env = C3D_GetTexEnv(0); - C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_TEXTURE0, 0); - C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); - C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); - - Mtx_PerspTilt(MtxStack_Cur(&projMtx), C3D_Angle(FOVY), C3D_AspectRatioTop, 0.01f, 1000.0f); - Mtx_Identity(MtxStack_Cur(&mdlvMtx)); - Mtx_Translate(MtxStack_Cur(&mdlvMtx), trX, trY, 0.0f); - - MtxStack_Update(&projMtx); - MtxStack_Update(&mdlvMtx); - - C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); - - C3D_Flush(); -} - -static void drawSceneBottom(float trX, float trY) -{ - C3D_RenderBufBind(&rbBot); - - C3D_TexBind(0, NULL); - - C3D_TexEnv* env = C3D_GetTexEnv(0); - C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR, 0); - C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); - C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); - - Mtx_PerspTilt(MtxStack_Cur(&projMtx), C3D_Angle(FOVY), C3D_AspectRatioBot, 0.01f, 1000.0f); - Mtx_Identity(MtxStack_Cur(&mdlvMtx)); - Mtx_Translate(MtxStack_Cur(&mdlvMtx), trX, trY, 0.0f); - - MtxStack_Update(&projMtx); - MtxStack_Update(&mdlvMtx); - - C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); - - C3D_Flush(); -} - -int main() -{ - gfxInitDefault(); - gfxSet3D(true); // uncomment if using stereoscopic 3D - -#ifdef DEBUG - consoleInit(GFX_BOTTOM, NULL); - printf("Testing...\n"); -#endif - - C3D_RenderBufInit(&rbTop, TOPSCR_WIDTH, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - C3D_RenderBufInit(&rbBot, 240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - rbTop.clearColor = CLEAR_COLOR; - rbBot.clearColor = CLEAR_COLOR; - - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - - MtxStack_Init(&projMtx); - MtxStack_Bind(&projMtx, GPU_VERTEX_SHADER, VSH_FVEC_projMtx, VSH_ULEN_projMtx); - MtxStack_Init(&mdlvMtx); - MtxStack_Bind(&mdlvMtx, GPU_VERTEX_SHADER, VSH_FVEC_mdlvMtx, VSH_ULEN_mdlvMtx); - - C3D_TexInit(&myTex, 64, 64, GPU_RGBA8); - C3D_TexUpload(&myTex, grass_bin); - //C3D_TexFlush(&myTex) - // ^ Not needed! FlushAndRun() already does it - - // Load shaders - pVsh = DVLB_ParseFile((u32*)test_vsh_shbin, test_vsh_shbin_size); - pGsh = DVLB_ParseFile((u32*)test_gsh_shbin, test_gsh_shbin_size); - shaderProgramInit(&shader); - shaderProgramSetVsh(&shader, &pVsh->DVLE[0]); - shaderProgramSetGsh(&shader, &pGsh->DVLE[0], 3*5); // Comment this out to disable the geoshader - C3D_BindProgram(&shader); - - // Configure attributes - C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); - AttrInfo_Init(attrInfo); - AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // position - AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2); // texcoord - AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 3); // vertex color - - // Configure VBO - myVbo = linearAlloc(sizeof(vertex_list)); - memcpy(myVbo, vertex_list, sizeof(vertex_list)); - - // Configure buffers - C3D_BufInfo* bufInfo = C3D_GetBufInfo(); - BufInfo_Init(bufInfo); - BufInfo_Add(bufInfo, myVbo, sizeof(vertex_t), 3, 0x210); - - // Clear renderbuffers - C3D_RenderBufClear(&rbTop); - C3D_RenderBufClear(&rbBot); - - float trX = 0, trY = 0; - float zDist = 0.1f; - - // Main loop - while (aptMainLoop()) - { - C3D_VideoSync(); - hidScanInput(); - - u32 kDown = hidKeysDown(); - u32 kHeld = hidKeysHeld(); - if (kDown & KEY_START) - break; // break in order to return to hbmenu - - if (kHeld & KEY_UP) - trY += 0.05f; - if (kHeld & KEY_DOWN) - trY -= 0.05f; - if (kHeld & KEY_LEFT) - trX -= 0.05f; - if (kHeld & KEY_RIGHT) - trX += 0.05f; - if (kHeld & KEY_L) - zDist -= 0.005f; - if (kHeld & KEY_R) - zDist += 0.005f; - - float slider = osGet3DSliderState(); - float czDist = zDist*slider/2; - - drawScene(trX-czDist, trY); - C3D_RenderBufTransfer(&rbTop, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), TOPSCR_COPYFLAG); - - if (slider > 0.0f) - { - C3D_RenderBufClear(&rbTop); - drawScene(trX+czDist, trY); - C3D_RenderBufTransfer(&rbTop, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), TOPSCR_COPYFLAG); - } - - C3D_RenderBufClear(&rbTop); // In theory this could be async but meh... - -#ifndef DEBUG - drawSceneBottom(trX, trY); - C3D_RenderBufTransfer(&rbBot, (u32*)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), 0x1000); - C3D_RenderBufClear(&rbBot); // Same here -#endif - } - - C3D_Fini(); - gfxExit(); - return 0; -} diff --git a/examples/gputest/source/test_gsh.shader b/examples/gputest/source/test_gsh.shader deleted file mode 100644 index 7971bf0..0000000 --- a/examples/gputest/source/test_gsh.shader +++ /dev/null @@ -1,93 +0,0 @@ -; This is a geometry Shader - -; Constants -.constf myconst(0.0, 1.0, 2.0, 3.0) -.alias zeros myconst.xxxx -.alias ones myconst.yyyy - -; Outputs -.out outpos position -.out outtc0 texcoord0 -.out outtc1 texcoord1 -.out outtc2 texcoord2 -.out outclr color - -.proc main - ; === EMIT THE FIRST TRIANGLE - passed through as-is === - - ; Emit the first vertex of the triangle - setemit 0 - mov outpos, v0 - mov outtc0, v1 - mov outtc1, v2 - mov outtc2, v3 - mov outclr, v4 - emit - - ; Emit the second vertex of the triangle - setemit 1 - mov outpos, v5 - mov outtc0, v6 - mov outtc1, v7 - mov outtc2, v8 - mov outclr, v9 - emit - - ; Emit the third and final vertex of the triangle - setemit 2, prim - mov outpos, v10 - mov outtc0, v11 - mov outtc1, v12 - mov outtc2, v13 - mov outclr, v14 - emit - - ; === EMIT THE SECOND TRIANGLE - translated and its color inverted === - - ; Adjust the coordinates of the first vertex & invert its color - add r0, -myconst.xzxx, v0 - mul r0, myconst.zzyy, r0 - add r4.xyz, ones, -v4 - mov r4.w, v4 - - ; Adjust the coordinates of the second vertex & invert its color - add r5, -myconst.xzxx, v5 - mul r5, myconst.zzyy, r5 - add r9.xyz, ones, -v9 - mov r9.w, v9 - - ; Adjust the coordinates of the third vertex & invert its color - add r10, -myconst.xzxx, v10 - mul r10, myconst.zzyy, r10 - add r14.xyz, ones, -v14 - mov r14.w, v14 - - ; Emit the first vertex of the triangle - setemit 0 - mov outpos, r0 - mov outtc0, v1 - mov outtc1, v2 - mov outtc2, v3 - mov outclr, r4 - emit - - ; Emit the second vertex of the triangle - setemit 1 - mov outpos, r5 - mov outtc0, v6 - mov outtc1, v7 - mov outtc2, v8 - mov outclr, r9 - emit - - ; Emit the third and final vertex of the triangle - setemit 2, prim - mov outpos, r10 - mov outtc0, v11 - mov outtc1, v12 - mov outtc2, v13 - mov outclr, r14 - emit - - end -.end diff --git a/examples/gputest/source/test_vsh.shader b/examples/gputest/source/test_vsh.shader deleted file mode 100644 index 3ea4445..0000000 --- a/examples/gputest/source/test_vsh.shader +++ /dev/null @@ -1,52 +0,0 @@ -; This is a vertex shader - -; Uniforms -.fvec projMtx[4], mdlvMtx[4] - -; Constants -.constf myconst(0.0, 1.0, -1.0, 0.0) -.alias zeros myconst.xxxx -.alias ones myconst.yyyy -.alias negones myconst.zzzz -.alias dummytcoord myconst.xxxy ; (0,0,0,1) - -; Outputs -.out outpos position -.out outtc0 texcoord0 -.out outtc1 texcoord1 -.out outtc2 texcoord2 -.out outclr color - -; Inputs -.alias inpos v0 -.alias intex v1 -.alias inarg v2 - -.proc main - ; r0 = (inpos.x, inpos.y, inpos.z, 1.0) - mov r0.xyz, inpos - mov r0.w, ones - - ; r1 = mdlvMtx * r0 - dp4 r1.x, mdlvMtx[0], r0 - dp4 r1.y, mdlvMtx[1], r0 - dp4 r1.z, mdlvMtx[2], r0 - dp4 r1.w, mdlvMtx[3], r0 - - ; outpos = projMtx * r1 - dp4 outpos.x, projMtx[0], r1 - dp4 outpos.y, projMtx[1], r1 - dp4 outpos.z, projMtx[2], r1 - dp4 outpos.w, projMtx[3], r1 - - ; Set texcoords - mov outtc0, intex - mov outtc1, ones - mov outtc2, ones - - ; Set vertex color - mov outclr.xyz, inarg - mov outclr.w, ones - - end -.end diff --git a/examples/immediate/Makefile b/examples/immediate/Makefile deleted file mode 100644 index a6103f0..0000000 --- a/examples/immediate/Makefile +++ /dev/null @@ -1,196 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -TOPDIR ?= $(CURDIR) -include $(DEVKITARM)/3ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# -# NO_SMDH: if set to anything, no SMDH file is generated. -# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) -# APP_TITLE is the name of the app stored in the SMDH file (Optional) -# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) -# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) -# ICON is the filename of the icon (.png), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .png -# - icon.png -# - /default_icon.png -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include -#ROMFS := romfs - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft - -CFLAGS := -g -Wall -O2 -mword-relocations \ - -fomit-frame-pointer -ffunction-sections \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM11 -D_3DS - -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lcitro3d -lctru -lm - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) -SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.png) - ifneq (,$(findstring $(TARGET).png,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).png - else - ifneq (,$(findstring icon.png,$(icons))) - export APP_ICON := $(TOPDIR)/icon.png - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_SMDH)),) - export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh -endif - -ifneq ($(ROMFS),) - export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) -endif - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -ifeq ($(strip $(NO_SMDH)),) -$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh -else -$(OUTPUT).3dsx : $(OUTPUT).elf -endif - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - -#--------------------------------------------------------------------------------- -# rules for assembling GPU shaders -#--------------------------------------------------------------------------------- -define shader-as - $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@))) - picasso -o $(CURBIN) $1 - bin2s $(CURBIN) | $(AS) -o $@ - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h - echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h -endef - -%.shbin.o : %.v.pica %.g.pica - @echo $(notdir $^) - @$(call shader-as,$^) - -%.shbin.o : %.v.pica - @echo $(notdir $<) - @$(call shader-as,$<) - -%.shbin.o : %.shlist - @echo $(notdir $<) - @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file))) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/examples/immediate/source/main.c b/examples/immediate/source/main.c deleted file mode 100644 index 42f74e9..0000000 --- a/examples/immediate/source/main.c +++ /dev/null @@ -1,113 +0,0 @@ -#include <3ds.h> -#include -#include -#include "vshader_shbin.h" - -#define CLEAR_COLOR 0x68B0D8FF - -#define DISPLAY_TRANSFER_FLAGS \ - (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ - GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ - GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) - -static DVLB_s* vshader_dvlb; -static shaderProgram_s program; -static int uLoc_projection; -static C3D_Mtx projection; - -static void sceneInit(void) -{ - // Load the vertex shader, create a shader program and bind it - vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); - shaderProgramInit(&program); - shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); - C3D_BindProgram(&program); - - // Get the location of the uniforms - uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); - - // Configure attributes for use with the vertex shader - // Attribute format and element count are ignored in immediate mode - C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); - AttrInfo_Init(attrInfo); - AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position - AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 3); // v1=color - - // Compute the projection matrix - Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0); - - // Configure the first fragment shading substage to just pass through the vertex color - // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight - C3D_TexEnv* env = C3D_GetTexEnv(0); - C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); - C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); - C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); -} - -static void sceneRender(void) -{ - // Update the uniforms - C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); - - // Draw the triangle directly - C3D_ImmDrawBegin(GPU_TRIANGLES); - C3D_ImmSendAttrib(200.0f, 200.0f, 0.5f, 0.0f); // v0=position - C3D_ImmSendAttrib(1.0f, 0.0f, 0.0f, 1.0f); // v1=color - - C3D_ImmSendAttrib(100.0f, 40.0f, 0.5f, 0.0f); - C3D_ImmSendAttrib(0.0f, 1.0f, 0.0f, 1.0f); - - C3D_ImmSendAttrib(300.0f, 40.0f, 0.5f, 0.0f); - C3D_ImmSendAttrib(0.0f, 0.0f, 1.0f, 1.0f); - C3D_ImmDrawEnd(); -} - -static void sceneExit(void) -{ - // Free the shader program - shaderProgramFree(&program); - DVLB_Free(vshader_dvlb); -} - -int main() -{ - // Initialize graphics - gfxInitDefault(); - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - - // Initialize the renderbuffer - static C3D_RenderBuf rb; - C3D_RenderBufInit(&rb, 240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - rb.clearColor = CLEAR_COLOR; - C3D_RenderBufClear(&rb); - C3D_RenderBufBind(&rb); - - // Initialize the scene - sceneInit(); - - // Main loop - while (aptMainLoop()) - { - C3D_VideoSync(); - hidScanInput(); - - // Respond to user input - u32 kDown = hidKeysDown(); - if (kDown & KEY_START) - break; // break in order to return to hbmenu - - // Render the scene - sceneRender(); - C3D_Flush(); - C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); - C3D_RenderBufClear(&rb); - } - - // Deinitialize the scene - sceneExit(); - - // Deinitialize graphics - C3D_Fini(); - gfxExit(); - return 0; -} diff --git a/examples/immediate/source/vshader.v.pica b/examples/immediate/source/vshader.v.pica deleted file mode 100644 index ca9498c..0000000 --- a/examples/immediate/source/vshader.v.pica +++ /dev/null @@ -1,38 +0,0 @@ -; Example PICA200 vertex shader - -; Uniforms -.fvec projection[4] - -; Constants -.constf myconst(0.0, 1.0, -1.0, 0.1) -.constf myconst2(0.3, 0.0, 0.0, 0.0) -.alias zeros myconst.xxxx ; Vector full of zeros -.alias ones myconst.yyyy ; Vector full of ones - -; Outputs -.out outpos position -.out outclr color - -; Inputs (defined as aliases for convenience) -.alias inpos v0 -.alias inclr v1 - -.bool test - -.proc main - ; Force the w component of inpos to be 1.0 - mov r0.xyz, inpos - mov r0.w, ones - - ; outpos = projectionMatrix * inpos - dp4 outpos.x, projection[0], r0 - dp4 outpos.y, projection[1], r0 - dp4 outpos.z, projection[2], r0 - dp4 outpos.w, projection[3], r0 - - ; outclr = inclr - mov outclr, inclr - - ; We're finished - end -.end diff --git a/examples/simple_tri/Makefile b/examples/simple_tri/Makefile deleted file mode 100644 index a6103f0..0000000 --- a/examples/simple_tri/Makefile +++ /dev/null @@ -1,196 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -TOPDIR ?= $(CURDIR) -include $(DEVKITARM)/3ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# -# NO_SMDH: if set to anything, no SMDH file is generated. -# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) -# APP_TITLE is the name of the app stored in the SMDH file (Optional) -# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) -# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) -# ICON is the filename of the icon (.png), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .png -# - icon.png -# - /default_icon.png -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include -#ROMFS := romfs - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft - -CFLAGS := -g -Wall -O2 -mword-relocations \ - -fomit-frame-pointer -ffunction-sections \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM11 -D_3DS - -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lcitro3d -lctru -lm - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) -SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.png) - ifneq (,$(findstring $(TARGET).png,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).png - else - ifneq (,$(findstring icon.png,$(icons))) - export APP_ICON := $(TOPDIR)/icon.png - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_SMDH)),) - export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh -endif - -ifneq ($(ROMFS),) - export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) -endif - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -ifeq ($(strip $(NO_SMDH)),) -$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh -else -$(OUTPUT).3dsx : $(OUTPUT).elf -endif - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - -#--------------------------------------------------------------------------------- -# rules for assembling GPU shaders -#--------------------------------------------------------------------------------- -define shader-as - $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@))) - picasso -o $(CURBIN) $1 - bin2s $(CURBIN) | $(AS) -o $@ - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h - echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h -endef - -%.shbin.o : %.v.pica %.g.pica - @echo $(notdir $^) - @$(call shader-as,$^) - -%.shbin.o : %.v.pica - @echo $(notdir $<) - @$(call shader-as,$<) - -%.shbin.o : %.shlist - @echo $(notdir $<) - @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file))) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/examples/simple_tri/source/main.c b/examples/simple_tri/source/main.c deleted file mode 100644 index 72e9153..0000000 --- a/examples/simple_tri/source/main.c +++ /dev/null @@ -1,131 +0,0 @@ -#include <3ds.h> -#include -#include -#include "vshader_shbin.h" - -#define CLEAR_COLOR 0x68B0D8FF - -#define DISPLAY_TRANSFER_FLAGS \ - (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ - GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ - GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) - -typedef struct { float x, y, z; } vertex; - -static const vertex vertex_list[] = -{ - { 200.0f, 200.0f, 0.5f }, - { 100.0f, 40.0f, 0.5f }, - { 300.0f, 40.0f, 0.5f }, -}; - -#define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) - -static DVLB_s* vshader_dvlb; -static shaderProgram_s program; -static int uLoc_projection; -static C3D_Mtx projection; - -static void* vbo_data; - -static void sceneInit(void) -{ - // Load the vertex shader, create a shader program and bind it - vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); - shaderProgramInit(&program); - shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); - C3D_BindProgram(&program); - - // Get the location of the uniforms - uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); - - // Configure attributes for use with the vertex shader - C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); - AttrInfo_Init(attrInfo); - AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position - AttrInfo_AddFixed(attrInfo, 1); // v1=color - - // Set the fixed attribute (color) to solid white - C3D_FixedAttribSet(1, 1.0, 1.0, 1.0, 1.0); - - // Compute the projection matrix - Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0); - - // Create the VBO (vertex buffer object) - vbo_data = linearAlloc(sizeof(vertex_list)); - memcpy(vbo_data, vertex_list, sizeof(vertex_list)); - - // Configure buffers - C3D_BufInfo* bufInfo = C3D_GetBufInfo(); - BufInfo_Init(bufInfo); - BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 1, 0x0); - - // Configure the first fragment shading substage to just pass through the vertex color - // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight - C3D_TexEnv* env = C3D_GetTexEnv(0); - C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); - C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); - C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); -} - -static void sceneRender(void) -{ - // Update the uniforms - C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); - - // Draw the VBO - C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); -} - -static void sceneExit(void) -{ - // Free the VBO - linearFree(vbo_data); - - // Free the shader program - shaderProgramFree(&program); - DVLB_Free(vshader_dvlb); -} - -int main() -{ - // Initialize graphics - gfxInitDefault(); - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - - // Initialize the renderbuffer - static C3D_RenderBuf rb; - C3D_RenderBufInit(&rb, 240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - rb.clearColor = CLEAR_COLOR; - C3D_RenderBufClear(&rb); - C3D_RenderBufBind(&rb); - - // Initialize the scene - sceneInit(); - - // Main loop - while (aptMainLoop()) - { - C3D_VideoSync(); - hidScanInput(); - - // Respond to user input - u32 kDown = hidKeysDown(); - if (kDown & KEY_START) - break; // break in order to return to hbmenu - - // Render the scene - sceneRender(); - C3D_Flush(); - C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); - C3D_RenderBufClear(&rb); - } - - // Deinitialize the scene - sceneExit(); - - // Deinitialize graphics - C3D_Fini(); - gfxExit(); - return 0; -} diff --git a/examples/simple_tri/source/vshader.v.pica b/examples/simple_tri/source/vshader.v.pica deleted file mode 100644 index ca9498c..0000000 --- a/examples/simple_tri/source/vshader.v.pica +++ /dev/null @@ -1,38 +0,0 @@ -; Example PICA200 vertex shader - -; Uniforms -.fvec projection[4] - -; Constants -.constf myconst(0.0, 1.0, -1.0, 0.1) -.constf myconst2(0.3, 0.0, 0.0, 0.0) -.alias zeros myconst.xxxx ; Vector full of zeros -.alias ones myconst.yyyy ; Vector full of ones - -; Outputs -.out outpos position -.out outclr color - -; Inputs (defined as aliases for convenience) -.alias inpos v0 -.alias inclr v1 - -.bool test - -.proc main - ; Force the w component of inpos to be 1.0 - mov r0.xyz, inpos - mov r0.w, ones - - ; outpos = projectionMatrix * inpos - dp4 outpos.x, projection[0], r0 - dp4 outpos.y, projection[1], r0 - dp4 outpos.z, projection[2], r0 - dp4 outpos.w, projection[3], r0 - - ; outclr = inclr - mov outclr, inclr - - ; We're finished - end -.end diff --git a/examples/textured_cube/Makefile b/examples/textured_cube/Makefile deleted file mode 100644 index a6103f0..0000000 --- a/examples/textured_cube/Makefile +++ /dev/null @@ -1,196 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -TOPDIR ?= $(CURDIR) -include $(DEVKITARM)/3ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -# -# NO_SMDH: if set to anything, no SMDH file is generated. -# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) -# APP_TITLE is the name of the app stored in the SMDH file (Optional) -# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) -# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) -# ICON is the filename of the icon (.png), relative to the project folder. -# If not set, it attempts to use one of the following (in this order): -# - .png -# - icon.png -# - /default_icon.png -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := include -#ROMFS := romfs - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft - -CFLAGS := -g -Wall -O2 -mword-relocations \ - -fomit-frame-pointer -ffunction-sections \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM11 -D_3DS - -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 - -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -LIBS := -lcitro3d -lctru -lm - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(CTRULIB) - - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) -export TOPDIR := $(CURDIR) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) -SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) - -ifeq ($(strip $(ICON)),) - icons := $(wildcard *.png) - ifneq (,$(findstring $(TARGET).png,$(icons))) - export APP_ICON := $(TOPDIR)/$(TARGET).png - else - ifneq (,$(findstring icon.png,$(icons))) - export APP_ICON := $(TOPDIR)/icon.png - endif - endif -else - export APP_ICON := $(TOPDIR)/$(ICON) -endif - -ifeq ($(strip $(NO_SMDH)),) - export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh -endif - -ifneq ($(ROMFS),) - export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) -endif - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -ifeq ($(strip $(NO_SMDH)),) -$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh -else -$(OUTPUT).3dsx : $(OUTPUT).elf -endif - -$(OUTPUT).elf : $(OFILES) - -#--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - -#--------------------------------------------------------------------------------- -# rules for assembling GPU shaders -#--------------------------------------------------------------------------------- -define shader-as - $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@))) - picasso -o $(CURBIN) $1 - bin2s $(CURBIN) | $(AS) -o $@ - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h - echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h - echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h -endef - -%.shbin.o : %.v.pica %.g.pica - @echo $(notdir $^) - @$(call shader-as,$^) - -%.shbin.o : %.v.pica - @echo $(notdir $<) - @$(call shader-as,$<) - -%.shbin.o : %.shlist - @echo $(notdir $<) - @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file))) - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/examples/textured_cube/data/kitten.bin b/examples/textured_cube/data/kitten.bin deleted file mode 100644 index a87ac4a8f17788e646796732120bda82629e0c97..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmYLwb$ngNm4BQ#w#CfM%(9r7nHit-#LO%UY>{P2woEce=9uCbVu<57GsU?%$vHRF|IfQkI_gQiq_=`Kn6K z?N$RRw)v?`+XUZ7MS9*>Q&0u}Ie&F*eBQ68q)KDS|G&>!P?Rb!J5+cP)%$P z(So4c0yG6*(OwMI#fzcZ*b%Oco#DFJ6{#z2^V1eGrELK^&tzg-Am<9u5L9|TL>JEm zs!K0~>EXE$>Jr4cDNppbh3epWA)D7;WZNELfE^KfP>RyS&PaVIN9$v|xE5)M7sBF@{Qv3DjauCF&yW;yu)b_vuSY5r&d#j3HE_jiDZAj9n3wBkrRN!BdSf zg?f@1ubDw3#X?exH<45mETEal-^tdJT8g!#m0=IfbUWx|J3&3g0vhaVrddHd%MqH{ zj?gV|hi<+r3`)Ex(*UZmCTxaKji*kOrOvTxiI%+28tU=J(BOO;38v7ZEUh$aXlB_% zJA;(6G&60Xo#z6rYrS>%+*8hFe=QoEl@`-kt)Xi)D2n%&PohT^kHL zHi!BUIMjv0Q64OGgbig_$#_lN&*mf#QBapg{^l5`2J#w0;M&YNo8sWnkqWogM0j?l zkrxj47S7ocK^g1?TR?8<~=ce-TLo+w$h#=*8d2{!HA2g-Qg6HQa_9D9YlbU5^hF`01S z7%|q7)V3=gLarUDT~`7edeg|~bLdOuxFp4O`|d==HBzCgWKBJVt~Q;Cl66;-WXth( zy{Wv1@+ixeauoOUB*MNw1r7sg3hFe(^>VybC*^TGn`GIM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Vmx?f zYa)~xH&&vLzmwk&D>2@nM890Qjb{qKy%g8f=>w`!o?;xoA694VShYJ1$}LGyZ-`~x zc{1zd=&Q@)CA)@1#wX(WEi~-}%GRzY?l&i}mYi{m`Z&o>76;SnXvvy3fjWJDU4CDq z)5{nU&o<+sBIxz!z<#^}W&?RJ>1W;8RE^{~RxWu@%UD;&?_v7$CBZZ5$|knN@H-3E z)l;@wt}p%H2+6FRdHkXf$*737OGP-8v%Msx(hzAE@mo7TK+?|(lvFaj{;rkb`~Lxn CZh=bx diff --git a/examples/textured_cube/source/main.c b/examples/textured_cube/source/main.c deleted file mode 100644 index 54c4945..0000000 --- a/examples/textured_cube/source/main.c +++ /dev/null @@ -1,229 +0,0 @@ -#include <3ds.h> -#include -#include -#include "vshader_shbin.h" -#include "kitten_bin.h" - -#define CLEAR_COLOR 0x68B0D8FF - -#define DISPLAY_TRANSFER_FLAGS \ - (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ - GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ - GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) - -typedef struct { float position[3]; float texcoord[2]; float normal[3]; } vertex; - -static const vertex vertex_list[] = -{ - // First face (PZ) - // First triangle - { {-0.5f, -0.5f, +0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, +1.0f} }, - { {+0.5f, -0.5f, +0.5f}, {1.0f, 0.0f}, {0.0f, 0.0f, +1.0f} }, - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, +1.0f} }, - // Second triangle - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, +1.0f} }, - { {-0.5f, +0.5f, +0.5f}, {0.0f, 1.0f}, {0.0f, 0.0f, +1.0f} }, - { {-0.5f, -0.5f, +0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, +1.0f} }, - - // Second face (MZ) - // First triangle - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, - { {-0.5f, +0.5f, -0.5f}, {1.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, - { {+0.5f, +0.5f, -0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, -1.0f} }, - // Second triangle - { {+0.5f, +0.5f, -0.5f}, {1.0f, 1.0f}, {0.0f, 0.0f, -1.0f} }, - { {+0.5f, -0.5f, -0.5f}, {0.0f, 1.0f}, {0.0f, 0.0f, -1.0f} }, - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, 0.0f, -1.0f} }, - - // Third face (PX) - // First triangle - { {+0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, +0.5f, -0.5f}, {1.0f, 0.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {+1.0f, 0.0f, 0.0f} }, - // Second triangle - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, -0.5f, +0.5f}, {0.0f, 1.0f}, {+1.0f, 0.0f, 0.0f} }, - { {+0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {+1.0f, 0.0f, 0.0f} }, - - // Fourth face (MX) - // First triangle - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, -0.5f, +0.5f}, {1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} }, - // Second triangle - { {-0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, +0.5f, -0.5f}, {0.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} }, - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} }, - - // Fifth face (PY) - // First triangle - { {-0.5f, +0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, +1.0f, 0.0f} }, - { {-0.5f, +0.5f, +0.5f}, {1.0f, 0.0f}, {0.0f, +1.0f, 0.0f} }, - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, +1.0f, 0.0f} }, - // Second triangle - { {+0.5f, +0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, +1.0f, 0.0f} }, - { {+0.5f, +0.5f, -0.5f}, {0.0f, 1.0f}, {0.0f, +1.0f, 0.0f} }, - { {-0.5f, +0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, +1.0f, 0.0f} }, - - // Sixth face (MY) - // First triangle - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, -1.0f, 0.0f} }, - { {+0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, {0.0f, -1.0f, 0.0f} }, - { {+0.5f, -0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, -1.0f, 0.0f} }, - // Second triangle - { {+0.5f, -0.5f, +0.5f}, {1.0f, 1.0f}, {0.0f, -1.0f, 0.0f} }, - { {-0.5f, -0.5f, +0.5f}, {0.0f, 1.0f}, {0.0f, -1.0f, 0.0f} }, - { {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, {0.0f, -1.0f, 0.0f} }, -}; - -#define vertex_list_count (sizeof(vertex_list)/sizeof(vertex_list[0])) - -static DVLB_s* vshader_dvlb; -static shaderProgram_s program; -static int uLoc_projection, uLoc_modelView; -static int uLoc_lightVec, uLoc_lightHalfVec, uLoc_lightClr, uLoc_material; -static C3D_Mtx projection; -static C3D_Mtx material = -{ - { - { { 0.0f, 0.2f, 0.2f, 0.2f } }, // Ambient - { { 0.0f, 0.4f, 0.4f, 0.4f } }, // Diffuse - { { 0.0f, 0.8f, 0.8f, 0.8f } }, // Specular - { { 1.0f, 0.0f, 0.0f, 0.0f } }, // Emission - } -}; - -static void* vbo_data; -static C3D_Tex kitten_tex; -static float angleX = 0.0, angleY = 0.0; - -static void sceneInit(void) -{ - // Load the vertex shader, create a shader program and bind it - vshader_dvlb = DVLB_ParseFile((u32*)vshader_shbin, vshader_shbin_size); - shaderProgramInit(&program); - shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); - C3D_BindProgram(&program); - - // Get the location of the uniforms - uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); - uLoc_modelView = shaderInstanceGetUniformLocation(program.vertexShader, "modelView"); - uLoc_lightVec = shaderInstanceGetUniformLocation(program.vertexShader, "lightVec"); - uLoc_lightHalfVec = shaderInstanceGetUniformLocation(program.vertexShader, "lightHalfVec"); - uLoc_lightClr = shaderInstanceGetUniformLocation(program.vertexShader, "lightClr"); - uLoc_material = shaderInstanceGetUniformLocation(program.vertexShader, "material"); - - // Configure attributes for use with the vertex shader - C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); - AttrInfo_Init(attrInfo); - AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position - AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2); // v1=texcoord - AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 3); // v2=normal - - // Compute the projection matrix - Mtx_PerspTilt(&projection, 80.0f*M_PI/180.0f, 400.0f/240.0f, 0.01f, 1000.0f); - - // Create the VBO (vertex buffer object) - vbo_data = linearAlloc(sizeof(vertex_list)); - memcpy(vbo_data, vertex_list, sizeof(vertex_list)); - - // Configure buffers - C3D_BufInfo* bufInfo = C3D_GetBufInfo(); - BufInfo_Init(bufInfo); - BufInfo_Add(bufInfo, vbo_data, sizeof(vertex), 3, 0x210); - - // Load the texture and bind it to the first texture unit - C3D_TexInit(&kitten_tex, 64, 64, GPU_RGBA8); - C3D_TexUpload(&kitten_tex, kitten_bin); - C3D_TexSetFilter(&kitten_tex, GPU_LINEAR, GPU_NEAREST); - C3D_TexBind(0, &kitten_tex); - - // Configure the first fragment shading substage to blend the texture color with - // the vertex color (calculated by the vertex shader using a lighting algorithm) - // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight - C3D_TexEnv* env = C3D_GetTexEnv(0); - C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0, GPU_PRIMARY_COLOR, 0); - C3D_TexEnvOp(env, C3D_Both, 0, 0, 0); - C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE); -} - -static void sceneRender(void) -{ - // Calculate the modelView matrix - C3D_Mtx modelView; - Mtx_Identity(&modelView); - Mtx_Translate(&modelView, 0.0, 0.0, -2.0 + 0.5*sinf(angleX)); - Mtx_RotateX(&modelView, angleX, true); - Mtx_RotateY(&modelView, angleY, true); - - // Rotate the cube each frame - angleX += M_PI / 180; - angleY += M_PI / 360; - - // Update the uniforms - C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_projection, &projection); - C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_modelView, &modelView); - C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, uLoc_material, &material); - C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightVec, 0.0f, 0.0f, -1.0f, 0.0f); - C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightHalfVec, 0.0f, 0.0f, -1.0f, 0.0f); - C3D_FVUnifSet(GPU_VERTEX_SHADER, uLoc_lightClr, 1.0f, 1.0f, 1.0f, 1.0f); - - // Draw the VBO - C3D_DrawArrays(GPU_TRIANGLES, 0, vertex_list_count); -} - -static void sceneExit(void) -{ - // Free the texture - C3D_TexDelete(&kitten_tex); - - // Free the VBO - linearFree(vbo_data); - - // Free the shader program - shaderProgramFree(&program); - DVLB_Free(vshader_dvlb); -} - -int main() -{ - // Initialize graphics - gfxInitDefault(); - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - - // Initialize the renderbuffer - static C3D_RenderBuf rb; - C3D_RenderBufInit(&rb, 240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - rb.clearColor = CLEAR_COLOR; - C3D_RenderBufClear(&rb); - C3D_RenderBufBind(&rb); - - // Initialize the scene - sceneInit(); - - // Main loop - while (aptMainLoop()) - { - C3D_VideoSync(); - hidScanInput(); - - // Respond to user input - u32 kDown = hidKeysDown(); - if (kDown & KEY_START) - break; // break in order to return to hbmenu - - // Render the scene - sceneRender(); - C3D_Flush(); - C3D_RenderBufTransfer(&rb, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), DISPLAY_TRANSFER_FLAGS); - C3D_RenderBufClear(&rb); - } - - // Deinitialize the scene - sceneExit(); - - // Deinitialize graphics - C3D_Fini(); - gfxExit(); - return 0; -} diff --git a/examples/textured_cube/source/vshader.v.pica b/examples/textured_cube/source/vshader.v.pica deleted file mode 100644 index 03272ad..0000000 --- a/examples/textured_cube/source/vshader.v.pica +++ /dev/null @@ -1,87 +0,0 @@ -; Example PICA200 vertex shader - -; Uniforms -.fvec projection[4], modelView[4] -.fvec lightVec, lightHalfVec, lightClr, material[4] -.alias mat_amb material[0] -.alias mat_dif material[1] -.alias mat_spe material[2] -.alias mat_emi material[3] - -; Constants -.constf myconst(0.0, 1.0, -1.0, -0.5) -.alias zeros myconst.xxxx ; Vector full of zeros -.alias ones myconst.yyyy ; Vector full of ones - -; Outputs -.out outpos position -.out outtc0 texcoord0 -.out outclr color - -; Inputs (defined as aliases for convenience) -.alias inpos v0 -.alias intex v1 -.alias innrm v2 - -.proc main - ; Force the w component of inpos to be 1.0 - mov r0.xyz, inpos - mov r0.w, ones - - ; r1 = modelView * inpos - dp4 r1.x, modelView[0], r0 - dp4 r1.y, modelView[1], r0 - dp4 r1.z, modelView[2], r0 - dp4 r1.w, modelView[3], r0 - - ; outpos = projection * r1 - dp4 outpos.x, projection[0], r1 - dp4 outpos.y, projection[1], r1 - dp4 outpos.z, projection[2], r1 - dp4 outpos.w, projection[3], r1 - - ; outtex = intex - mov outtc0, intex - - ; Transform the normal vector with the modelView matrix - ; r1 = normalize(modelView * innrm) - mov r0.xyz, innrm - mov r0.w, zeros - dp4 r1.x, modelView[0], r0 - dp4 r1.y, modelView[1], r0 - dp4 r1.z, modelView[2], r0 - mov r1.w, zeros - dp3 r2, r1, r1 ; r2 = x^2+y^2+z^2 for each component - rsq r2, r2 ; r2 = 1/sqrt(r2) '' - mul r1, r2, r1 ; r1 = r1*r2 - - ; Calculate the diffuse level (r0.x) and the shininess level (r0.y) - ; r0.x = max(0, -(lightVec * r1)) - ; r0.y = max(0, (-lightHalfVec[i]) * r1) ^ 2 - dp3 r0.x, lightVec, r1 - add r0.x, zeros, -r0 - dp3 r0.y, -lightHalfVec, r1 - max r0, zeros, r0 - mul r0.y, r0, r0 - - ; Accumulate the vertex color in r1, initializing it to the emission color - mov r1, mat_emi - - ; r1 += specularColor * lightClr * shininessLevel - mul r2, lightClr, r0.yyyy - mad r1, r2, mat_spe, r1 - - ; r1 += diffuseColor * lightClr * diffuseLevel - mul r2, lightClr, r0.xxxx - mad r1, r2, mat_dif, r1 - - ; r1 += ambientColor * lightClr - mov r2, lightClr - mad r1, r2, mat_amb, r1 - - ; outclr = clamp r1 to [0,1] - min outclr, ones, r1 - - ; We're finished - end -.end