-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(WIIU) add a tool to convert slang shaders.
- Loading branch information
1 parent
d62ada4
commit 517a3f8
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
all: slang-convert | ||
|
||
slang-convert: main.c | ||
$(CC) $< -o $@ -g -O0 -Wall -Werror | ||
|
||
clean: | ||
rm slang-convert main.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/sh | ||
|
||
#### options #### | ||
|
||
slang_dir=slang-shaders | ||
gshcompiler=$(pwd)/compiler.exe | ||
vshflag=--vsh | ||
pshflag=--psh | ||
outputflag=--out | ||
alignflag=--align | ||
|
||
################# | ||
|
||
|
||
currentdir=$(pwd) | ||
|
||
die () | ||
{ | ||
echo error while converting $name | ||
#mv -f tmp.vsh $currentdir | ||
#mv -f tmp.psh $currentdir | ||
#cp $1 $currentdir 2> /dev/null | ||
#exit 1 | ||
} | ||
|
||
|
||
make | ||
|
||
cd $slang_dir | ||
slang_dir=$(pwd) | ||
slang_files=`find $slang_dir -name "*.slang"` | ||
|
||
for name in $slang_files ; do | ||
echo $name | ||
echo cd $(dirname $name) | ||
cd $(dirname $name) | ||
echo $currentdir/slang-convert --slang $name --vsh tmp.vsh --psh tmp.psh | ||
$currentdir/slang-convert --slang $(basename $name) --vsh tmp.vsh --psh tmp.psh | ||
echo $gshcompiler $alignflag $vshflag tmp.vsh $pshflag tmp.psh $outputflag `echo "$name" | sed "s/\.slang//"`.gsh | ||
$gshcompiler $alignflag $vshflag tmp.vsh $pshflag tmp.psh $outputflag `echo "$name" | sed "s/\.slang//"`.gsh || die $name | ||
rm -rf tmp.vsh tmp.psh | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <ctype.h> | ||
#include <string.h> | ||
|
||
int main(int argc, const char** argv) | ||
{ | ||
|
||
const char* slang = NULL; | ||
const char* vs_asm = NULL; | ||
const char* ps_asm = NULL; | ||
const char* vs_out = NULL; | ||
const char* ps_out = NULL; | ||
|
||
for(int i = 1; i < argc - 1; i+=2) | ||
{ | ||
if(!strcmp(argv[i], "--slang")) | ||
slang = argv[i + 1]; | ||
else if(!strcmp(argv[i], "--vsource")) | ||
vs_asm = argv[i + 1]; | ||
else if(!strcmp(argv[i], "--psource")) | ||
ps_asm = argv[i + 1]; | ||
else if(!strcmp(argv[i], "--vsh")) | ||
vs_out = argv[i + 1]; | ||
else if(!strcmp(argv[i], "--psh")) | ||
ps_out = argv[i + 1]; | ||
} | ||
|
||
|
||
if(!slang || !vs_out || !ps_out || (!vs_asm && ps_asm) || (vs_asm && !ps_asm)) | ||
{ | ||
printf("Usage :\n"); | ||
printf("%s --slang <slang input> --vsh <vsh output> --psh <psh output>\n", argv[0]); | ||
printf("%s --slang <slang input> --vsource <vsh asm input> --psource <psh asm input> --vsh <vsh output> --psh <psh output>\n", argv[0]); | ||
} | ||
|
||
char* slang_buffer; | ||
size_t slang_filesize; | ||
{ | ||
FILE* slang_file = fopen(slang, "rb"); | ||
fseek(slang_file, 0, SEEK_END); | ||
slang_filesize = ftell(slang_file); | ||
fseek(slang_file, 0, SEEK_SET); | ||
slang_buffer = malloc(slang_filesize + 1); | ||
fread(slang_buffer, 1, slang_filesize, slang_file); | ||
fclose(slang_file); | ||
} | ||
|
||
slang_buffer[slang_filesize] = '\0'; | ||
|
||
FILE* vs_out_fp = fopen(vs_out, "wb"); | ||
FILE* ps_out_fp = fopen(ps_out, "wb"); | ||
|
||
const char* line = "#version 150\n"; | ||
fwrite(line, 1, strlen(line),vs_out_fp); | ||
fwrite(line, 1, strlen(line),ps_out_fp); | ||
|
||
char* next = slang_buffer; | ||
|
||
bool vson = true; | ||
bool pson = true; | ||
|
||
while(*next) | ||
{ | ||
const char* line = next; | ||
|
||
while(*next && *next != '\n' && *next != '\r') | ||
next++; | ||
|
||
if (*next == '\r') | ||
*next++ = '\0'; | ||
|
||
*next++ = '\0'; | ||
|
||
// while((*next == '\n') || (*next == '\r')) | ||
// *next++ = '\0'; | ||
|
||
if(strstr(line, "#version")) | ||
continue; | ||
|
||
if(strstr(line, "#pragma")) | ||
{ | ||
if(strstr(line, "#pragma stage vertex")) | ||
{ | ||
vson = true; | ||
pson = false; | ||
} | ||
else if(strstr(line, "#pragma stage fragment")) | ||
{ | ||
vson = false; | ||
pson = true; | ||
} | ||
|
||
continue; | ||
} | ||
|
||
|
||
char* layout = strstr(line, "layout("); | ||
if(layout) | ||
{ | ||
while(*layout != ')') | ||
layout++; | ||
|
||
layout++; | ||
|
||
while(*layout && isspace(*layout)) | ||
layout++; | ||
|
||
if(!strncmp(layout, "uniform", 7)) | ||
line = layout; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
if(vson) | ||
{ | ||
fwrite(line, 1, strlen(line),vs_out_fp); | ||
fputc('\n', vs_out_fp); | ||
} | ||
|
||
if(pson) | ||
{ | ||
fwrite(line, 1, strlen(line),ps_out_fp); | ||
fputc('\n', ps_out_fp); | ||
} | ||
|
||
} | ||
|
||
fclose(vs_out_fp); | ||
fclose(ps_out_fp); | ||
|
||
return 0; | ||
} | ||
|
||
|