From b56cc6b31440bb5c5f98ea44e0dd241d36bc1b08 Mon Sep 17 00:00:00 2001 From: Bergmann89 Date: Mon, 5 Oct 2015 19:10:01 +0200 Subject: [PATCH] * removed library (will be maintenanced in extra project) --- library/build_release.sh | 206 ------- library/header/examples/c++/Makefile | 11 - library/header/examples/c++/example.cpp | 54 -- library/header/examples/c/Makefile | 11 - library/header/examples/c/example.c | 99 --- library/header/examples/color.shdr | 34 - library/header/examples/delphi/example.cfg | 42 -- library/header/examples/delphi/example.dof | 141 ----- library/header/examples/delphi/example.dpr | 48 -- library/header/examples/fpc/example.lpi | 66 -- library/header/examples/fpc/example.lpr | 60 -- library/header/examples/phonglight.shdr | 38 -- library/header/examples/simple.shdr | 9 - library/header/libShaderFile.h | 262 -------- library/header/libShaderFile.hpp | 574 ----------------- library/header/ulibShaderFile.pas | 450 -------------- library/libShaderFile.lpi | 380 ------------ library/libShaderFile.lpr | 681 --------------------- 18 files changed, 3166 deletions(-) delete mode 100755 library/build_release.sh delete mode 100644 library/header/examples/c++/Makefile delete mode 100644 library/header/examples/c++/example.cpp delete mode 100644 library/header/examples/c/Makefile delete mode 100644 library/header/examples/c/example.c delete mode 100644 library/header/examples/color.shdr delete mode 100644 library/header/examples/delphi/example.cfg delete mode 100644 library/header/examples/delphi/example.dof delete mode 100644 library/header/examples/delphi/example.dpr delete mode 100644 library/header/examples/fpc/example.lpi delete mode 100644 library/header/examples/fpc/example.lpr delete mode 100644 library/header/examples/phonglight.shdr delete mode 100644 library/header/examples/simple.shdr delete mode 100644 library/header/libShaderFile.h delete mode 100644 library/header/libShaderFile.hpp delete mode 100644 library/header/ulibShaderFile.pas delete mode 100644 library/libShaderFile.lpi delete mode 100644 library/libShaderFile.lpr diff --git a/library/build_release.sh b/library/build_release.sh deleted file mode 100755 index dae4ad7..0000000 --- a/library/build_release.sh +++ /dev/null @@ -1,206 +0,0 @@ -#!/bin/bash - -# set -x #enable debug - -SCRIPTPATH=$(readlink -f $0) -SCRIPTNAME=$(basename $SCRIPTPATH) -SCRIPTDIR=$(dirname $SCRIPTPATH) -git="git" -HAS_GIT=true -HEADER_DIR="$SCRIPTDIR/header" -DOCU_DIR="$SCRIPTDIR/../doc" -INC_MAJOR=false -INC_MINOR=false -INC_BUGFIX=false - -function log() -{ - echo "$@" >&2 -} - -function cleaupAndExit() -{ - if $HAS_GIT && [[ -n "$TAGNAME" ]] && [[ $1 -ne 0 ]]; then - log "remove git tag $TAGNAME" - $git tag -d $TAGNAME - fi - exit $1 -} - -function printHelp() -{ - printf "script to build libShaderFile release -Usage: - $SCRIPTNAME [parameter] - [] optional parameters - () required parameters - -Parameter: - --major | -m - increment major version and reset the minor version before creating git tag - - --minor | -n - increment major version and reset the bugfix version before creating git tag - - --bufgix | -b - increment bugfix version before creating git tag - - --help | -h | -? - print this help - " -} - -function getLastVersion() -{ - POS="HEAD" - TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null) - RET=$? - while [[ $RET -eq 0 ]]; do - if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo $(echo $TAG | egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+") - return 0 - fi - POS=$TAG"^" - TAG=$($git describe --tags --abbrev=0 $POS 2>/dev/null) - RET=$? - done - return 1 -} - -function incVersion() -{ - read -r -a PARTS <<< $(echo "$1" | tr "." " ") - if $INC_MAJOR; then - ((PARTS[0]++)) - PARTS[1]=0 - fi - if $INC_MINOR; then - ((PARTS[1]++)) - PARTS[2]=0 - fi - if $INC_BUGFIX; then - ((PARTS[2]++)) - fi - ((PARTS[3]++)) - local tmp="${PARTS[@]}" - echo "${tmp// /.}" -} - -function addGitTag() -{ - local INC_VERSION=true - log "create git version tag" - CURRENT=$(getLastVersion) - if [ $? -ne 0 ]; then - CURRENT="0.0.0.0" - INC_VERSION=false - fi - local tmp="v$CURRENT" - LINES=$($git log --pretty=oneline $tmp..HEAD) - if [ $? -eq 0 ]; then - DIFF=$(echo $LINES | wc -l) - if [ $DIFF -eq 0 ] || [ -z "$LINES" ]; then - log "current commit already has a version tag: $tmp" - TAGNAME=$tmp - return 0 - fi - fi - if $INC_VERSION; then - NEWVERSION=$(incVersion $CURRENT) - else - NEWVERSION="$CURRENT" - fi - log "current version: $CURRENT" - log "new version: $NEWVERSION" - local tmp="v$NEWVERSION" - $git tag $tmp - if [[ $? -ne 0 ]]; then - log "unable to create version tag: exit" - cleaupAndExit 100 - fi - TAGNAME=$tmp - return 0 -} - -function BuildConfig() -{ - CONFIG=$1 - POSTFIX=$2 - FILEEXT=$3 - - printf "\n== build project $CONFIG ==\n" - lazbuild --build-mode=$CONFIG --build-all --verbose $SCRIPTDIR/libShaderFile.lpi - if [ $? -ne 0 ]; then - echo "build failed! exit." - cleaupAndExit 1 - fi - - ZIPDIR="bin/$POSTFIX" - BINDIR="$ZIPDIR" - ZIPPATH="$SCRIPTDIR/libShaderFile-$POSTFIX.zip" - if [ -n "$TAGNAME" ]; then - mkdir -p "$SCRIPTDIR/$TAGNAME/" - ZIPPATH="$SCRIPTDIR/$TAGNAME/libShaderFile-$POSTFIX.zip" - fi - BINNAME="libShaderFile-$POSTFIX$FILEEXT" - if [ ! -f $BINNAME ]; then - echo "file not found: $EXENAME" - cleaupAndExit 2 - fi - - mkdir -p $BINDIR - mv "$BINNAME" "$BINDIR/" || { log "unable to copy linked binary"; cleaupAndExit 3; } - # use this to copy data folder instead of data archive: cp -R --preserve=links data $BINDIR || { log "unable to copy data folder"; cleaupAndExit 4; } - cp -r "$HEADER_DIR" "$BINDIR" || { log "unable to copy header files"; cleaupAndExit 4; } - cp -r "$DOCU_DIR" "$BINDIR/docu" || { log "unable to copy documentation files"; cleaupAndExit 5; } - - pushd $ZIPDIR - rm -rf $ZIPPATH - zip -r $ZIPPATH ./* || { log "unable to create zip archive"; cleaupAndExit 6; } - popd -} - -while [[ $# -gt 0 ]]; do - case $1 in - "--major" | "-m") - INC_MAJOR=true - ;; - - "--minor" | "-n") - INC_MINOR=true - ;; - - "--bufgix" | "-b") - INC_BUGFIX=true - ;; - - "--help" | "-h" | "-?") - printHelp - cleaupAndExit 0 - ;; - - *) - echo "invalid parameter: $1" - echo "use --help to get further information" - ;; - - esac - shift -done - -if $HAS_GIT; then - GIT_CHANGED=$($git status --untracked-files=all --verbose --porcelain) - if [[ -n "$GIT_CHANGED" ]]; then - log "git has uncommited changes. please commit before building a release" - cleaupAndExit 101 - fi - addGitTag -fi - -BuildConfig "Win32Release" "i386-win32" ".dll" -BuildConfig "Win64Release" "x86_64-win64" ".dll" -BuildConfig "Linux32Release" "i386-linux" ".so" -BuildConfig "Linux64Release" "x86_64-linux" ".so" - -cleaupAndExit 0 - diff --git a/library/header/examples/c++/Makefile b/library/header/examples/c++/Makefile deleted file mode 100644 index 3b6533a..0000000 --- a/library/header/examples/c++/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -ifeq ($(OS),Windows_NT) - LDFLAGS= -else - LDFLAGS=-ldl -endif - -all: example.cpp ../../libShaderFile.h - g++ -o example example.cpp $(LDFLAGS) - -clean: - rm -rf *.exe diff --git a/library/header/examples/c++/example.cpp b/library/header/examples/c++/example.cpp deleted file mode 100644 index a48c456..0000000 --- a/library/header/examples/c++/example.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include "../../libShaderFile.hpp" - -#if _WIN64 -static const char* LibName = "..\..\..\libShaderFile-x86_64-win64.dll"; -#elif _WIN32 -static const char* LibName = "..\..\..\libShaderFile-i386-win32.dll"; -#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) -static const char* LibName = "../../../libShaderFile-x86_64-linux.so"; -#elif __linux__ && (__i386 || _X86_) -static const char* LibName = "../../../libShaderFile-i386-linux.so"; -#else -# error 'unknown operation system' -#endif - -int main(int argc, char **argv) -{ - try - { - if (argc < 3) - { - std::cout << "error: expected input file and generator/class name as parameter" << std::endl; - return 1; - } - - // initialize library - lsf::Library lib(LibName); - - // create and load shader file - lsf::ShaderFile shaderFile(lib); - shaderFile.loadFromFile(argv[1]); - - const lsf::Library& l = shaderFile.getLibrary(); - - // get generator - lsf::Generator generator(shaderFile, argv[2]); - - int i = 3; - while (i < argc-1) - { - generator.setProperty(argv[i], argv[i+1]); - i += 2; - } - - std::cout << generator.generateCode() << std::endl; - - return 0; - } - catch(const std::exception& ex) - { - std::cout << "error: " << ex.what() << std::endl; - return 2; - } -} diff --git a/library/header/examples/c/Makefile b/library/header/examples/c/Makefile deleted file mode 100644 index 2e75d32..0000000 --- a/library/header/examples/c/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -ifeq ($(OS),Windows_NT) - LDFLAGS= -else - LDFLAGS=-ldl -endif - -all: example.c ../../libShaderFile.h - gcc -g -o example example.c $(LDFLAGS) - -clean: - rm -rf *.exe diff --git a/library/header/examples/c/example.c b/library/header/examples/c/example.c deleted file mode 100644 index 16ea244..0000000 --- a/library/header/examples/c/example.c +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include "../../libShaderFile.h" - -#if _WIN64 -# define LIB_NAME "..\..\..\libShaderFile-x86_64-win64.dll" -#elif _WIN32 -# define LIB_NAME "..\..\..\libShaderFile-i386-win32.dll" -#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) -# define LIB_NAME "../../../libShaderFile-x86_64-linux.so" -#elif __linux__ && (__i386 || _X86_) -# define LIB_NAME "../../../libShaderFile-i386-linux.so" -#else -# error 'unknown operation system' -#endif - -int main(int argc, char **argv) -{ - lsf_shader_file_handle_t sfHandle = 0; - lsf_shader_generator_handle_t sgHandle = 0; - lsf_error_code_t err = LSF_ERR_NONE; - int ret = 0, i = 3; - const char* code = NULL; - - if (argc < 3) - { - printf("error: expected input file and generator/class name as parameter\n"); - return 1; - } - - lsf_init(LIB_NAME); - - // create shader file - sfHandle = lsf_shader_file_create(); - if (!sfHandle) - { - printf("unable to create shader file: %s\n", lsf_get_last_error_msg()); - ret = 2; - goto cleanup_lib; - } - - // load shader file - err = lsf_shader_file_load_from_file(sfHandle, argv[1]); - if (err != LSF_ERR_NONE) - { - printf("unable to load shader file: %s\n", lsf_get_last_error_msg()); - ret = 3; - goto cleanup_shader_file; - } - - // create generator - sgHandle = lsf_generator_create(sfHandle, argv[2]); - if (!sgHandle) - { - printf("unable to create generator: %s\n", lsf_get_last_error_msg()); - ret = 4; - goto cleanup_shader_file; - } - - // apply properties - while (i < argc-1) - { - err = lsf_generator_set_property_by_name(sgHandle, argv[i], argv[i+1]); - if (err != LSF_ERR_NONE) - { - printf("unable to set property (%s=%s) (err=0x%08x)", argv[i], argv[i+1], err); - ret = 5; - goto cleanup_shader_generator; - } - i += 2; - } - - // generate code - code = lsf_generator_generate_code(sgHandle); - if (!code) - { - printf("unable to generate code: %s\n", lsf_get_last_error_msg()); - ret = 4; - goto cleanup_shader_generator; - } - - printf("%s", code); - -cleanup_shader_generator: - err = lsf_generator_destroy(sgHandle); - if (err != LSF_ERR_NONE) - printf("warning: could not destroy generator handle: %d\n", err); - -cleanup_shader_file: - err = lsf_shader_file_destroy(sfHandle); - if (err != LSF_ERR_NONE) - printf("warning: could not destroy shader file handle: %d\n", err); - -cleanup_lib: - err = lsf_finish(); - if (err != LSF_ERR_NONE) - printf("warning: could finish library: %d\n", err); - - return ret; -} diff --git a/library/header/examples/color.shdr b/library/header/examples/color.shdr deleted file mode 100644 index 31d7805..0000000 --- a/library/header/examples/color.shdr +++ /dev/null @@ -1,34 +0,0 @@ -{$CLASS Color} - {$PROPERTY UseColorMap 'false'} -{$END} - -{$CLASS ColorFrag $EXTENDS Color} - - /* you can also define code here. It will be added when the code for the class is generated */ - - {$FUNC 'vec4' GetColor $INLINE} - {$IF UseColorMap} - {$VAR 'vec2' '_texCoord' 'gl_TexCoord[0].st'} - {$UNIFORM 'sampler2D' 'uColorMap'} - return texture2D(uColorMap, _texCoord); - {$ELSE} - return gl_Color; - {$END} - {$END} - - {$MAIN} - gl_FragColor = {$CALL GetColor}; - {$END} -{$END} - -{$CLASS ColorVert $EXTENDS Color} - {$MAIN} - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - {$IF UseColorMap} - gl_TexCoord[0] = gl_MultiTexCoord0; - {$ELSE} - gl_FrontColor = gl_Color; - gl_BackColor = gl_Color; - {$END} - {$END} -{$END} \ No newline at end of file diff --git a/library/header/examples/delphi/example.cfg b/library/header/examples/delphi/example.cfg deleted file mode 100644 index ce48ecf..0000000 --- a/library/header/examples/delphi/example.cfg +++ /dev/null @@ -1,42 +0,0 @@ --$A8 --$B- --$C+ --$D+ --$E- --$F- --$G+ --$H+ --$I+ --$J- --$K- --$L+ --$M- --$N+ --$O+ --$P+ --$Q- --$R- --$S- --$T- --$U- --$V+ --$W- --$X+ --$YD --$Z1 --cg --AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; --H+ --W+ --M --$M16384,1048576 --K$00400000 --LE"c:\zusatzprogramme\delphi 7\Projects\Bpl" --LN"c:\zusatzprogramme\delphi 7\Projects\Bpl" --U"..\..\" --O"..\..\" --I"..\..\" --R"..\..\" --w-UNSAFE_TYPE --w-UNSAFE_CODE --w-UNSAFE_CAST diff --git a/library/header/examples/delphi/example.dof b/library/header/examples/delphi/example.dof deleted file mode 100644 index 112a24d..0000000 --- a/library/header/examples/delphi/example.dof +++ /dev/null @@ -1,141 +0,0 @@ -[FileVersion] -Version=7.0 -[Compiler] -A=8 -B=0 -C=1 -D=1 -E=0 -F=0 -G=1 -H=1 -I=1 -J=0 -K=0 -L=1 -M=0 -N=1 -O=1 -P=1 -Q=0 -R=0 -S=0 -T=0 -U=0 -V=1 -W=0 -X=1 -Y=1 -Z=1 -ShowHints=1 -ShowWarnings=1 -UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; -NamespacePrefix= -SymbolDeprecated=1 -SymbolLibrary=1 -SymbolPlatform=1 -UnitLibrary=1 -UnitPlatform=1 -UnitDeprecated=1 -HResultCompat=1 -HidingMember=1 -HiddenVirtual=1 -Garbage=1 -BoundsError=1 -ZeroNilCompat=1 -StringConstTruncated=1 -ForLoopVarVarPar=1 -TypedConstVarPar=1 -AsgToTypedConst=1 -CaseLabelRange=1 -ForVariable=1 -ConstructingAbstract=1 -ComparisonFalse=1 -ComparisonTrue=1 -ComparingSignedUnsigned=1 -CombiningSignedUnsigned=1 -UnsupportedConstruct=1 -FileOpen=1 -FileOpenUnitSrc=1 -BadGlobalSymbol=1 -DuplicateConstructorDestructor=1 -InvalidDirective=1 -PackageNoLink=1 -PackageThreadVar=1 -ImplicitImport=1 -HPPEMITIgnored=1 -NoRetVal=1 -UseBeforeDef=1 -ForLoopVarUndef=1 -UnitNameMismatch=1 -NoCFGFileFound=1 -MessageDirective=1 -ImplicitVariants=1 -UnicodeToLocale=1 -LocaleToUnicode=1 -ImagebaseMultiple=1 -SuspiciousTypecast=1 -PrivatePropAccessor=1 -UnsafeType=0 -UnsafeCode=0 -UnsafeCast=0 -[Linker] -MapFile=0 -OutputObjs=0 -ConsoleApp=1 -DebugInfo=0 -RemoteSymbols=0 -MinStackSize=16384 -MaxStackSize=1048576 -ImageBase=4194304 -ExeDescription= -[Directories] -OutputDir= -UnitOutputDir= -PackageDLLOutputDir= -PackageDCPOutputDir= -SearchPath=..\..\ -Packages=rtl;vcl;vclie;xmlrtl;inet;inetdbbde;inetdbxpress;vclx;dbrtl;soaprtl;dsnap;VclSmp;dbexpress;vcldb;dbxcds;adortl;ibxpress;vclactnband;bdertl;vclshlctrls;dclOfficeXP -Conditionals= -DebugSourceDirs= -UsePackages=0 -[Parameters] -RunParams= -HostApplication= -Launcher= -UseLauncher=0 -DebugCWD= -[Version Info] -IncludeVerInfo=0 -AutoIncBuild=0 -MajorVer=1 -MinorVer=0 -Release=0 -Build=0 -Debug=0 -PreRelease=0 -Special=0 -Private=0 -DLL=0 -Locale=1031 -CodePage=1252 -[Version Info Keys] -CompanyName= -FileDescription= -FileVersion=1.0.0.0 -InternalName= -LegalCopyright= -LegalTrademarks= -OriginalFilename= -ProductName= -ProductVersion=1.0.0.0 -Comments= -[HistoryLists\hlUnitAliases] -Count=1 -Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; -[HistoryLists\hlSearchPath] -Count=1 -Item0=..\..\ -[HistoryLists\hlUnitOutputDirectory] -Count=1 -Item0=../.. diff --git a/library/header/examples/delphi/example.dpr b/library/header/examples/delphi/example.dpr deleted file mode 100644 index 944ce58..0000000 --- a/library/header/examples/delphi/example.dpr +++ /dev/null @@ -1,48 +0,0 @@ -program example; - -{$APPTYPE CONSOLE} - -uses - SysUtils, - ulibShaderFile; - -var - i: Integer; - s: String; - ShaderFile: TlsfShaderFile; - Generator: TlsfGenerator; - -begin - lsf_init(ExtractFilePath(ParamStr(0)) + '..\..\..\libShaderFile-i386-win32.dll'); - try - if (ParamCount < 2) then begin - WriteLn('error: expected input file and generator/class name as parameter'); - ExitCode := 1; - exit; - end; - ShaderFile := TlsfShaderFile.Create; - try - ShaderFile.LoadFromFile(ParamStr(1)); - Generator := TlsfGenerator.Create(ShaderFile, ParamStr(2)); - try - i := 3; - while (i < ParamCount) do begin - s := ParamStr(i+1); - Generator.SetProperty(ParamStr(i), s); - inc(i, 2); - end; - WriteLn(Generator.GenerateCode); - finally - FreeAndNil(Generator); - end; - finally - FreeAndNil(ShaderFile); - end; - except - on e: Exception do begin - WriteLn('error: ' + e.Message); - ExitCode := 2; - end; - end; - lsf_finish; -end. diff --git a/library/header/examples/fpc/example.lpi b/library/header/examples/fpc/example.lpi deleted file mode 100644 index 37749ea..0000000 --- a/library/header/examples/fpc/example.lpi +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - <UseAppBundle Value="False"/> - <ResourceType Value="res"/> - </General> - <i18n> - <EnableI18N LFM="False"/> - </i18n> - <VersionInfo> - <StringTable ProductVersion=""/> - </VersionInfo> - <BuildModes Count="1"> - <Item1 Name="Default" Default="True"/> - </BuildModes> - <PublishOptions> - <Version Value="2"/> - </PublishOptions> - <RunParams> - <local> - <FormatVersion Value="1"/> - </local> - </RunParams> - <Units Count="1"> - <Unit0> - <Filename Value="example.lpr"/> - <IsPartOfProject Value="True"/> - </Unit0> - </Units> - </ProjectOptions> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="example"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir)"/> - <OtherUnitFiles Value="..\.."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - </CompilerOptions> - <Debugging> - <Exceptions Count="3"> - <Item1> - <Name Value="EAbort"/> - </Item1> - <Item2> - <Name Value="ECodetoolError"/> - </Item2> - <Item3> - <Name Value="EFOpenError"/> - </Item3> - </Exceptions> - </Debugging> -</CONFIG> diff --git a/library/header/examples/fpc/example.lpr b/library/header/examples/fpc/example.lpr deleted file mode 100644 index 6df54e4..0000000 --- a/library/header/examples/fpc/example.lpr +++ /dev/null @@ -1,60 +0,0 @@ -program example; - -uses - sysutils, variants, - ulibShaderFile; - -const - {$IF DEFINED(WIN32)} - LibName = '..\..\..\libShaderFile-i386-win32.dll'; - {$ELSEIF DEFINED(WIN64)} - LibName = '..\..\..\libShaderFile-x86_64-win64.dll'; - {$ELSEIF DEFINED(LINUX) AND DEFINED(CPU32)} - LibName = '../../../libShaderFile-i386-linux.so'; - {$ELSEIF DEFINED(LINUX) AND DEFINED(CPU64)} - LibName = '../../../libShaderFile-x86_64-linux.so'; - {$ELSE} - {$ERROR 'unknown operation system'} - {$IFEND} - -var - i: Integer; - s: String; - ShaderFile: TlsfShaderFile; - Generator: TlsfGenerator; - -begin - lsf_init(ExtractFilePath(ParamStr(0)) + LibName); - try - if (ParamCount < 2) then begin - WriteLn('error: expected input file and generator/class name as parameter'); - ExitCode := 1; - exit; - end; - ShaderFile := TlsfShaderFile.Create; - try - ShaderFile.LoadFromFile(ParamStr(1)); - Generator := TlsfGenerator.Create(ShaderFile, ParamStr(2)); - try - i := 3; - while (i < ParamCount) do begin - s := ParamStr(i+1); - Generator.SetProperty(ParamStr(i), s); - inc(i, 2); - end; - WriteLn(Generator.GenerateCode); - finally - FreeAndNil(Generator); - end; - finally - FreeAndNil(ShaderFile); - end; - except - on e: Exception do begin - WriteLn('error: ' + e.Message); - ExitCode := 2; - end; - end; - lsf_finish; -end. - diff --git a/library/header/examples/phonglight.shdr b/library/header/examples/phonglight.shdr deleted file mode 100644 index 3000692..0000000 --- a/library/header/examples/phonglight.shdr +++ /dev/null @@ -1,38 +0,0 @@ -{$INCLUDE 'color.shdr'} - -{$CLASS PhongLight} - {$PROPERTY UsePhongLight 'false'} - {$IF UsePhongLight} - {$VARYING 'vec3' 'vNormal'} - {$VARYING 'vec3' 'vVertex'} - {$END} -{$END} - -{$CLASS PhongLightFrag $EXTENDS PhongLight ColorFrag} - {$MAIN} - vec4 color = {$CALL GetColor}; - {$IF UsePhongLight} - vec3 eye = normalize(-vVertex); - vec3 lightVec = gl_LightSource[0].position.xyz - vVertex; - vec3 reflected = normalize(reflect(lightVec, vNormal)); - - vec4 ambient = gl_LightSource[0].ambient * gl_FrontMaterial.ambient; - vec4 diffuse = gl_LightSource[0].diffuse * max(dot(vNormal, lightVec), 0.0) * gl_FrontMaterial.diffuse; - vec4 specular = gl_LightSource[0].specular * pow(max(dot(reflected, eye), 0.0), gl_FrontMaterial.shininess) * gl_FrontMaterial.specular; - - gl_FragColor = vec4((ambient + diffuse) * color) + specular; - {$ELSE} - gl_FragColor = color; - {$END} - {$END} -{$END} - -{$CLASS PhongLightVert $EXTENDS PhongLight ColorVert} - {$MAIN} - {$INHERITED ColorVert $INLINE}; - {$IF UsePhongLight} - vNormal = normalize(gl_NormalMatrix * gl_Normal); - vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); - {$END} - {$END} -{$END} \ No newline at end of file diff --git a/library/header/examples/simple.shdr b/library/header/examples/simple.shdr deleted file mode 100644 index a00c188..0000000 --- a/library/header/examples/simple.shdr +++ /dev/null @@ -1,9 +0,0 @@ -{$MAIN} - {$PROPERTY EnableTexture 'false'} - {$IF EnableTexture} - {$UNIFORM 'sampler2D' 'uTexture0'} - gl_FragColor = texture2D(uTexture0, gl_TexCoord[0].st); - {$ELSE} - gl_FragColor = gl_Color; - {$END} -{$END} \ No newline at end of file diff --git a/library/header/libShaderFile.h b/library/header/libShaderFile.h deleted file mode 100644 index 865850e..0000000 --- a/library/header/libShaderFile.h +++ /dev/null @@ -1,262 +0,0 @@ -#ifndef LIB_SHADER_FILE_H -#define LIB_SHADER_FILE_H - -#include <stdint.h> - -/**********************************************************************************************************************************/ -/* public interface */ -/**********************************************************************************************************************************/ -#define LSF_LOGLEVEL_DEBUG 0 -#define LSF_LOGLEVEL_INFO 1 -#define LSF_LOGLEVEL_WARNING 2 -#define LSF_LOGLEVEL_ERROR 3 - -#define LSF_ERR_NONE 0x00000000 -#define LSF_ERR_NOT_INIT 0x00000001 -#define LSF_ERR_INVALID_HANDLE_SHADER_FILE 0x00000010 -#define LSF_ERR_INVALID_HANDLE_SHADER_GENERATOR 0x00000011 -#define LSF_ERR_INVALID_GENERATOR_NAME 0x00000020 -#define LSF_ERR_INVALID_PROPERTY_INDEX 0x00000021 -#define LSF_ERR_INVALID_PROPERTY_NAME 0x00000022 -#define LSF_ERR_GENERATOR_NOT_ASSIGNED_TO_FILE 0x00000023 -#define LSF_ERR_UNKNOWN_IDENTFIFIER 0x00001000 -#define LSF_ERR_DUPLICATE_IDENTIFIER 0x00001001 -#define LSF_ERR_OUT_OF_RANGE 0x00001002 -#define LSF_ERR_INVALID_IDENTIFIER 0x00001003 -#define LSF_ERR_INVALID_PARAMTER_COUNT 0x00001004 -#define LSF_ERR_INVALID_PARAMTER 0x00001005 -#define LSF_ERR_UNEXPECTED_TOKEN 0x00001006 -#define LSF_ERR_INVALID_TOKEN 0x00001007 -#define LSF_ERR_EXPRESSION_INTERNAL 0x00001008 -#define LSF_ERR_EXPRESSION 0x00001009 -#define LSF_ERR_SHADER_PART_INTERNAL 0x0000100A -#define LSF_ERR_SHADER_PART 0x0000100B -#define LSF_ERR_INVALID_LIBRARY_NAME 0x00002000 -#define LSF_ERR_INVALID_LIBRARY_HANDLE 0x00002001 -#define LSF_ERR_INVALID_METHOD_NAME 0x00002002 -#define LSF_ERR_UNKNOWN 0xFFFFFFFF - -#if __MINGW32__ -# define WINAPI __stdcall -#else -# define WINAPI -#endif - -typedef uint32_t lsf_error_code_t; -typedef uint32_t lsf_log_level_t; -typedef void* lsf_shader_file_handle_t; -typedef void* lsf_shader_generator_handle_t; - -typedef void (*lsf_shader_file_log_callback_t)(const lsf_log_level_t loglevel, const char* msg, const void* userargs); - -/** create a new shader file handle - * @returns shader file handle or NULL (check lsf_get_last_error_* for more details) */ -lsf_shader_file_handle_t (WINAPI *lsf_shader_file_create) (); - -/** set the callback for log messages of a specific shader file handle - * @param handle shader file handle to set callback for - * @param callback pointer to callback function - * @param userargs user defined arguments - * @returns error code (see LSF_ERR_*) */ -lsf_error_code_t (WINAPI *lsf_shader_file_set_log_callback) (const lsf_shader_file_handle_t handle, const lsf_shader_file_log_callback_t callback, const void* userargs); - -/** load shader file code from a given file - * @param handle handle of shader file to load from file - * @param filename file to load shader code from - * @returns error code (see LSF_ERR_*) */ -lsf_error_code_t (WINAPI *lsf_shader_file_load_from_file) (const lsf_shader_file_handle_t handle, const char* filename); - -/** save shader file code to a given file - * @param handle handle of shader file to save to file - * @param filename file to save shader code to - * @returns error code (see LSF_ERR_*) */ -lsf_error_code_t (WINAPI *lsf_shader_file_save_to_file) (const lsf_shader_file_handle_t handle, const char* filename); - -/** generate a list of all code generators in a shader file - * @param handle shader file handle to generate list for - * @returns list of code generators (seperated by linebreak) or NULL (check lsf_get_last_error_* for more details) */ -const char* (WINAPI *lsf_shader_file_get_generator_names) (const lsf_shader_file_handle_t handle); - -/** destroy a shader file handle - * @param handle shader file handle to destroy - * @returns error code (see LSF_ERR_*) */ -lsf_error_code_t (WINAPI *lsf_shader_file_destroy) (const lsf_shader_file_handle_t handle); - - -/** create a new code generator from a given shader file. the generator is owned by the shader file handle. - * if you destroy a shader file handle, all associated generator handles will be destroyed to. - * @param handle shader file handle to create generator from - * @param name name of the generator (see lsf_shader_file_get_generator_names to get a list of all valid names) - * @return generator handle of NULL (check lsf_get_last_error_* for more details) */ -lsf_shader_generator_handle_t (WINAPI *lsf_generator_create) (const lsf_shader_file_handle_t handle, const char* name); - -/** generate a list of all known properties within a given generator handle - * @handle generator handle to get properties from - * @return list of all known properties (seperated by linebreak) or NULL (check lsf_get_last_error_* for more details) */ -const char* (WINAPI *lsf_generator_get_property_names) (const lsf_shader_generator_handle_t handle); - -/** get a property value by its index - * @param handle generator handle - * @param index index of the property (see lsf_generator_get_property_names to calculate property index) - * @return property value or NULL (check lsf_get_last_error_* for more details) */ -const char* (WINAPI *lsf_generator_get_property) (const lsf_shader_generator_handle_t handle, const int index); - -/** get a property value by its name - * @param handle generator handle - * @param name name of the property - * @return property value or NULL (check lsf_get_last_error_* for more details) */ -const char* (WINAPI *lsf_generator_get_property_by_name) (const lsf_shader_generator_handle_t handle, const char* name); - -/** set a property value by its index - * @param handle generator handle - * @param index index of the property (see lsf_generator_get_property_names to calculate property index) - * @param value new value of the property - * @return property value or NULL (check lsf_get_last_error_* for more details) */ -lsf_error_code_t (WINAPI *lsf_generator_set_property) (const lsf_shader_generator_handle_t handle, const int index, const char* value); - -/** set a property value by its name - * @param handle generator handle - * @param name name of the property - * @param value new value of the property - * @return property value or NULL (check lsf_get_last_error_* for more details) */ -lsf_error_code_t (WINAPI *lsf_generator_set_property_by_name) (const lsf_shader_generator_handle_t handle, const char* name, const char* value); - -/** generate shader code - * @param handle generator handle - * @return generated shader code or NULL (check lsf_get_last_error_* for more details) */ -const char* (WINAPI *lsf_generator_generate_code) (const lsf_shader_generator_handle_t handle); - -/** destroy a generator handle - * @param handle generator handle to destroy - * @returns error code (see LSF_ERR_*) */ -lsf_error_code_t (WINAPI *lsf_generator_destroy) (const lsf_shader_generator_handle_t handle); - - -/** get last error code - * @return error code of last failed operation */ -lsf_error_code_t (WINAPI *lsf_get_last_error_code) (); - -/** get last error message - * @return error message of last failed operation */ -const char* (WINAPI *lsf_get_last_error_msg) (); - -/** get last error trace - * @return error message and a trace of last failed operation */ -const char* (WINAPI *lsf_get_last_error_trace) (); - -/** initialize the library - * @param libname name of the shared library to load data from - * @return 0 on success, LSF_ERR_* otherwise */ -int lsf_init(const char* libname); - -/** finalize the library - * @return 0 on success, LSF_ERR_* otherwise */ -int lsf_finish(void); - - -/**********************************************************************************************************************************/ -/* internal initialization code */ -/**********************************************************************************************************************************/ -//#define LSF_DEBUG -#ifdef LSF_DEBUG -# include <stdio.h> -#endif - -#if WIN32 || WIN64 || _WIN32 || _WIN64 -# include <windows.h> - -typedef HMODULE lib_handle_t; - -lib_handle_t open_lib(const char* name) - { return LoadLibrary(name); }; - -void* get_addr(lib_handle_t handle, const char* name) - { return GetProcAddress(handle, name); }; - -int close_lib(lib_handle_t handle) - { return FreeLibrary(handle); }; - -#elif LINUX || __linux__ -# include <dlfcn.h> - -typedef void* lib_handle_t; - -lib_handle_t open_lib(const char* name) - { return dlopen(name, RTLD_LAZY); }; - -void* get_addr(lib_handle_t handle, const char* name) - { return dlsym(handle, name); }; - -int close_lib(lib_handle_t handle) - { return !dlclose(handle); }; - -#else -# error "unknown operation system" -#endif - -#ifndef LSF_DEBUG -# define LoadProc(proc, name) \ - proc = get_addr(handle, name); \ - if (!proc) \ - return LSF_ERR_INVALID_METHOD_NAME -#else -# define LoadProc(proc, name) \ - proc = get_addr(handle, name); \ - printf("load method '%s' (addr=0x%016x)\n", name, proc); \ - if (!proc) \ - return LSF_ERR_INVALID_METHOD_NAME -#endif - -lsf_error_code_t (WINAPI *lsf_init_intern)(); -lsf_error_code_t (WINAPI *lsf_finish_intern)(); - -lib_handle_t handle = NULL; - -int lsf_init(const char* libname) -{ -#ifdef LSF_DEBUG - printf("loading library '%s'\n", libname); -#endif - - handle = open_lib(libname); - if (!handle) - return LSF_ERR_INVALID_LIBRARY_NAME; - -#ifdef LSF_DEBUG - printf(" done (handle=0x%016x)\n", handle); -#endif - - LoadProc(lsf_shader_file_create, "lsf_ShaderFile_create"); - LoadProc(lsf_shader_file_set_log_callback, "lsf_ShaderFile_setLogCallback"); - LoadProc(lsf_shader_file_load_from_file, "lsf_ShaderFile_loadFromFile"); - LoadProc(lsf_shader_file_save_to_file, "lsf_ShaderFile_saveToFile"); - LoadProc(lsf_shader_file_get_generator_names, "lsf_ShaderFile_getGeneratorNames"); - LoadProc(lsf_shader_file_destroy, "lsf_ShaderFile_destroy"); - - LoadProc(lsf_generator_create, "lsf_Generator_create"); - LoadProc(lsf_generator_get_property_names, "lsf_Generator_getPropertyNames"); - LoadProc(lsf_generator_get_property, "lsf_Generator_getProperty"); - LoadProc(lsf_generator_get_property_by_name, "lsf_Generator_getPropertyByName"); - LoadProc(lsf_generator_set_property, "lsf_Generator_setProperty"); - LoadProc(lsf_generator_set_property_by_name, "lsf_Generator_setPropertyByName"); - LoadProc(lsf_generator_generate_code, "lsf_Generator_generateCode"); - LoadProc(lsf_generator_destroy, "lsf_Generator_destroy"); - - LoadProc(lsf_init_intern, "lsf_init"); - LoadProc(lsf_get_last_error_code, "lsf_getLastErrorCode"); - LoadProc(lsf_get_last_error_msg, "lsf_getLastErrorMsg"); - LoadProc(lsf_get_last_error_trace, "lsf_getLastErrorTrace"); - LoadProc(lsf_finish_intern, "lsf_finish"); - - return lsf_init_intern(); -} - -int lsf_finish(void) -{ - lsf_error_code_t err = lsf_finish_intern(); - if (!close_lib(handle)) - return LSF_ERR_INVALID_LIBRARY_HANDLE; - return err; -} - -#endif /* LIB_SHADER_FILE_H */ diff --git a/library/header/libShaderFile.hpp b/library/header/libShaderFile.hpp deleted file mode 100644 index 6d3bf06..0000000 --- a/library/header/libShaderFile.hpp +++ /dev/null @@ -1,574 +0,0 @@ -#ifndef LIB_SHADER_FILE_HPP -#define LIB_SHADER_FILE_HPP - -#include <string> -#include <sstream> -#include <vector> -#include <stdint.h> - -#if WIN32 || WIN64 || _WIN32 || _WIN64 -# include <windows.h> -#elif LINUX || __linux__ -# include <dlfcn.h> -#else -# error "unknown operation system" -#endif - -#if __MINGW32__ -# define WINAPI __stdcall -#else -# define WINAPI -#endif - -/**********************************************************************************************************************************/ -/* public interface */ -/**********************************************************************************************************************************/ -namespace lsf -{ - enum LogLevel - { - llDebug = 0, - llInfo = 1, - llWarning = 2, - llError = 3, - }; - - enum ErrorCode - { - errNone = 0x00000000, - errNotInit = 0x00000001, - errInvalidHandleShaderFile = 0x00000010, - errInvalidHandleShaderGenerator = 0x00000011, - errInvalidGeneratorName = 0x00000020, - errInvalidPropertyIndex = 0x00000021, - errInvalidPropertyName = 0x00000022, - errGeneratorNotAssignedToFile = 0x00000023, - errUnknownIdentfifier = 0x00001000, - errDuplicateIdentifier = 0x00001001, - errOutOfRange = 0x00001002, - errInvalidIdentifier = 0x00001003, - errInvalidParamterCount = 0x00001004, - errInvalidParamter = 0x00001005, - errUnexpectedToken = 0x00001006, - errInvalidToken = 0x00001007, - errExpressionInternal = 0x00001008, - errExpression = 0x00001009, - errShaderPartInternal = 0x0000100a, - errShaderPart = 0x0000100b, - errInvalidLibraryName = 0x00002000, - errInvalidLibraryHandle = 0x00002001, - errInvalidMethodName = 0x00002002, - errUnknown = 0xffffffff, - }; - - /** class to load and manage shared library */ - class Library - { - friend class ShaderFile; - friend class Generator; - - public: - #if WIN32 || WIN64 || _WIN32 || _WIN64 - typedef HMODULE Handle; //!< shader file handle - #elif LINUX || __linux__ - typedef void* Handle; //!< shader file handle - #else - #error "unknown operation system" - #endif - - private: - struct Impl; //!< struct that implements the libraries methods - Impl* _impl; //!< struct that implements the libraries methods - Handle _handle; //!< handle of shared library - - public: - /** get last error code - * @return error code of last failed operation */ - ErrorCode getLastErrorCode() const; - - /** get last error message - * @return error message of last failed operation */ - std::string getLastErrorMsg() const; - - /** get last error trace - * @return error trace of last failed operation */ - std::string getLastErrorTrace() const; - - /** constructor - * @param libName name of shared library file */ - Library(std::string libName); - - /** destructor */ - virtual ~Library(); - - private: - /** deleted copy constructor */ - Library(const Library& that) { }; - }; - - /** class to manage a shader file */ - class ShaderFile - { - public: - typedef void* Handle; //!< shader file handle - - private: - const Library::Impl& _impl; //!< struct that implements the libraries methods - Handle _handle; //!< handle of this shader file - - protected: - /** method to log messages from shader file and code generation - * @param logLevel level of the log message - * @param msg message to write log log */ - virtual void logMsg(LogLevel logLevel, const std::string& msg); - - public: - /** get shader file handle - * @return handle of this shader file */ - Handle getHandle() const; - - /** get library - * @return library object this shader file is attached to */ - const Library& getLibrary() const; - - /** load shader file from a given file - * @param filename file to load shader code from */ - void loadFromFile(std::string filename); - - /** save shader file to a given file - * @param filename file to save shader code to */ - void saveToFile(std::string filename) const; - - /** constructor - * @param library library this shader file is attached to */ - ShaderFile(const Library& library); - - /** destructor */ - virtual ~ShaderFile(); - - private: - /** deleted copy constructor */ - ShaderFile(const ShaderFile& that); - - public: - /** callback method for log messages - * @param logLevel log level of the log message - * @param msg log message - * @param userargs user defined arguments */ - static void WINAPI logCallback(const LogLevel loglevel, const char* msg, void* userargs); - }; - - /** class to manage a shader code generator */ - class Generator - { - public: - typedef void* Handle; //!< shader generator handle - typedef std::vector<std::string> StringVec; //!< vector of strings - - private: - const Library::Impl& _impl; //!< struct that implements the libraries methods - const ShaderFile& _shaderFile; //!< shader file the generator is attached to - std::string _name; //!< name of this generator - Handle _handle; //!< handle of this generator - StringVec _propertyNames; //!< vector with all known properties - - public: - /** get generator name - * @return name of this generator */ - std::string getName() const; - - /** get generator handle - * @return handle of this generator */ - Handle getHandle() const; - - /** get shader file this generator is attached to - * @return shader file this genrator is attached to */ - const ShaderFile& getShaderFile() const; - - /** get a vector of all known properties - * @return vecotr with all known properties */ - const StringVec& getPropertyNames() const; - - /** get the value of a single property by its name - * @param name name of the property - * @return value of the property */ - std::string getProperty(const std::string& name) const; - - /** get the value of a single property by its index - * @param index index of the property (see getPropertyNames() to get the index of a property) - * @return value of the property */ - std::string getProperty(int index) const; - - /** set the value of a single property by its name - * @param name name of the property - * @param value value of the property */ - void setProperty(const std::string& name, const std::string& value); - - /** set the value of a single property by its index - * @param index index of the property (see getPropertyNames() to get the index of a property) - * @param value value of the property */ - void setProperty(int index, const std::string& value); - - /** generate the shader code with the current property setup - * @return generated shader code */ - std::string generateCode() const; - - /** constructor - * @param shaderFile shader file this generator is attached to - * @param name name of a valid generator inside the shaderFile */ - Generator(const ShaderFile& shaderFile, std::string name); - - /** destructor */ - virtual ~Generator(); - - private: - /** deleted copy constructor */ - Generator(const Generator& that); - }; - - /** object to handle error inside this library */ - class Exception : public std::exception - { - private: - std::string _message; //!< error message - ErrorCode _errorCode; //!< suitable error code to the error message - - public: - /** get error code - * @return error code of this exception */ - ErrorCode getErrorCode() const; - - /** get error message - * @return error message of this exception */ - std::string getMessage() const; - - /** @return error message of this exception */ - virtual const char* what() const throw(); - - /** constructor */ - Exception(std::string message, ErrorCode errorCode = errUnknown); - - /** destructor */ - ~Exception() throw(); - }; -} - - - - -/**********************************************************************************************************************************/ -/* private implementation */ -/**********************************************************************************************************************************/ -#if WIN32 || WIN64 || _WIN32 || _WIN64 -lsf::Library::Handle libOpen(const char* name) - { return LoadLibrary(name); }; - -template <typename T> -T getAddr(lsf::Library::Handle handle, const char* name) - { return reinterpret_cast<T>(GetProcAddress(handle, name)); }; - -int libClose(lsf::Library::Handle handle) - { return FreeLibrary(handle); }; - -#elif LINUX || __linux__ -lsf::Library::Handle libOpen(const char* name) - { return dlopen(name, RTLD_LAZY); }; - -template <typename T> -T getAddr(lsf::Library::Handle handle, const char* name) - { return reinterpret_cast<T>(dlsym(handle, name)); }; - -int libClose(lsf::Library::Handle handle) - { return !dlclose(handle); }; - -#else -# error "unknown operation system" -#endif - -/* Library::Impl ******************************************************************************************************************/ -struct lsf::Library::Impl -{ - typedef ShaderFile::Handle (WINAPI *lsf_shader_file_create_t) (); - typedef void (WINAPI *lsf_shader_file_log_callback_t) (const LogLevel loglevel, const char* msg, void* userargs); - typedef ErrorCode (WINAPI *lsf_shader_file_set_log_callback_t) (const ShaderFile::Handle handle, const lsf_shader_file_log_callback_t callback, void* userargs); - typedef ErrorCode (WINAPI *lsf_shader_file_load_from_file_t) (const ShaderFile::Handle handle, const char* filename); - typedef ErrorCode (WINAPI *lsf_shader_file_save_to_file_t) (const ShaderFile::Handle handle, const char* filename); - typedef const char* (WINAPI *lsf_shader_file_get_generator_names_t) (const ShaderFile::Handle handle); - typedef ErrorCode (WINAPI *lsf_shader_file_destroy_t) (const ShaderFile::Handle handle); - - typedef Generator::Handle (WINAPI *lsf_generator_create_t) (const ShaderFile::Handle handle, const char* name); - typedef const char* (WINAPI *lsf_generator_get_property_names_t) (const Generator::Handle handle); - typedef const char* (WINAPI *lsf_generator_get_property_t) (const Generator::Handle handle, const int index); - typedef const char* (WINAPI *lsf_generator_get_property_by_name_t) (const Generator::Handle handle, const char* name); - typedef ErrorCode (WINAPI *lsf_generator_set_property_t) (const Generator::Handle handle, const int index, const char* value); - typedef ErrorCode (WINAPI *lsf_generator_set_property_by_name_t) (const Generator::Handle handle, const char* name, const char* value); - typedef const char* (WINAPI *lsf_generator_generate_code_t) (const Generator::Handle handle); - typedef ErrorCode (WINAPI *lsf_generator_destroy_t) (const Generator::Handle handle); - - typedef ErrorCode (WINAPI *lsf_init_t) (); - typedef ErrorCode (WINAPI *lsf_get_last_error_code_t) (); - typedef const char* (WINAPI *lsf_get_last_error_msg_t) (); - typedef const char* (WINAPI *lsf_get_last_error_trace_t) (); - typedef ErrorCode (WINAPI *lsf_finish_t) (); - - const Library& library; - - lsf_shader_file_create_t lsf_shader_file_create; - lsf_shader_file_set_log_callback_t lsf_shader_file_set_log_callback; - lsf_shader_file_load_from_file_t lsf_shader_file_load_from_file; - lsf_shader_file_save_to_file_t lsf_shader_file_save_to_file; - lsf_shader_file_get_generator_names_t lsf_shader_file_get_generator_names; - lsf_shader_file_destroy_t lsf_shader_file_destroy; - - lsf_generator_create_t lsf_generator_create; - lsf_generator_get_property_names_t lsf_generator_get_property_names; - lsf_generator_get_property_t lsf_generator_get_property; - lsf_generator_get_property_by_name_t lsf_generator_get_property_by_name; - lsf_generator_set_property_t lsf_generator_set_property; - lsf_generator_set_property_by_name_t lsf_generator_set_property_by_name; - lsf_generator_generate_code_t lsf_generator_generate_code; - lsf_generator_destroy_t lsf_generator_destroy; - - lsf_init_t lsf_init; - lsf_get_last_error_code_t lsf_get_last_error_code; - lsf_get_last_error_msg_t lsf_get_last_error_msg; - lsf_get_last_error_trace_t lsf_get_last_error_trace; - lsf_finish_t lsf_finish; - - Impl(const Library& library) : - library (library), - - lsf_shader_file_create (NULL), - lsf_shader_file_set_log_callback (NULL), - lsf_shader_file_load_from_file (NULL), - lsf_shader_file_save_to_file (NULL), - lsf_shader_file_get_generator_names (NULL), - lsf_shader_file_destroy (NULL), - - lsf_generator_create (NULL), - lsf_generator_get_property_names (NULL), - lsf_generator_get_property (NULL), - lsf_generator_get_property_by_name (NULL), - lsf_generator_set_property (NULL), - lsf_generator_set_property_by_name (NULL), - lsf_generator_generate_code (NULL), - lsf_generator_destroy (NULL), - - lsf_init (NULL), - lsf_get_last_error_code (NULL), - lsf_get_last_error_msg (NULL), - lsf_get_last_error_trace (NULL), - lsf_finish (NULL) - { }; -}; - -/* Library ************************************************************************************************************************/ -template <typename T> -inline void loadProc(lsf::Library::Handle handle, T& proc, const char* name) -{ - proc = getAddr<T>(handle, name); - if (!proc) - throw lsf::Exception(std::string("unable to load method from library: ") + name, lsf::errInvalidMethodName); -} - -lsf::ErrorCode lsf::Library::getLastErrorCode() const - { return _impl->lsf_get_last_error_code(); } - -std::string lsf::Library::getLastErrorMsg() const - { return std::string(_impl->lsf_get_last_error_msg()); } - -std::string lsf::Library::getLastErrorTrace() const - { return std::string(_impl->lsf_get_last_error_trace()); } - -lsf::Library::Library(std::string libName) : - _impl(new Impl(*this)) -{ - _handle = libOpen(libName.c_str()); - if (!_handle) - throw Exception("unable to open shared library: " + libName, lsf::errInvalidLibraryName); - - loadProc(_handle, _impl->lsf_shader_file_create, "lsf_ShaderFile_create"); - loadProc(_handle, _impl->lsf_shader_file_set_log_callback, "lsf_ShaderFile_setLogCallback"); - loadProc(_handle, _impl->lsf_shader_file_load_from_file, "lsf_ShaderFile_loadFromFile"); - loadProc(_handle, _impl->lsf_shader_file_save_to_file, "lsf_ShaderFile_saveToFile"); - loadProc(_handle, _impl->lsf_shader_file_get_generator_names, "lsf_ShaderFile_getGeneratorNames"); - loadProc(_handle, _impl->lsf_shader_file_destroy, "lsf_ShaderFile_destroy"); - - loadProc(_handle, _impl->lsf_generator_create, "lsf_Generator_create"); - loadProc(_handle, _impl->lsf_generator_get_property_names, "lsf_Generator_getPropertyNames"); - loadProc(_handle, _impl->lsf_generator_get_property, "lsf_Generator_getProperty"); - loadProc(_handle, _impl->lsf_generator_get_property_by_name, "lsf_Generator_getPropertyByName"); - loadProc(_handle, _impl->lsf_generator_set_property, "lsf_Generator_setProperty"); - loadProc(_handle, _impl->lsf_generator_set_property_by_name, "lsf_Generator_setPropertyByName"); - loadProc(_handle, _impl->lsf_generator_generate_code, "lsf_Generator_generateCode"); - loadProc(_handle, _impl->lsf_generator_destroy, "lsf_Generator_destroy"); - - loadProc(_handle, _impl->lsf_init, "lsf_init"); - loadProc(_handle, _impl->lsf_get_last_error_code, "lsf_getLastErrorCode"); - loadProc(_handle, _impl->lsf_get_last_error_msg, "lsf_getLastErrorMsg"); - loadProc(_handle, _impl->lsf_get_last_error_trace, "lsf_getLastErrorTrace"); - loadProc(_handle, _impl->lsf_finish, "lsf_finish"); - - ErrorCode err = _impl->lsf_init(); - if (err != lsf::errNone) - throw Exception("unable to initialize library", err); -} - -lsf::Library::~Library() -{ - if (_impl) - { - _impl->lsf_finish(); - delete _impl; - _impl = NULL; - } - if (_handle) - { - libClose(_handle); - _handle = NULL; - } -} - -/* ShaderFile *********************************************************************************************************************/ -void lsf::ShaderFile::logMsg(LogLevel logLevel, const std::string& msg) - { /* DUMMY */ } - -inline lsf::ShaderFile::Handle lsf::ShaderFile::getHandle() const - { return _handle; } - -inline const lsf::Library& lsf::ShaderFile::getLibrary() const - { return _impl.library; } - -void lsf::ShaderFile::loadFromFile(std::string filename) -{ - ErrorCode err = _impl.lsf_shader_file_load_from_file(_handle, filename.c_str()); - if (err != errNone) - throw Exception("unable to load file", err); -} - -void lsf::ShaderFile::saveToFile(std::string filename) const -{ - ErrorCode err = _impl.lsf_shader_file_load_from_file(_handle, filename.c_str()); - if (err != errNone) - throw Exception("unable to load file", err); -} - -lsf::ShaderFile::ShaderFile(const Library& library) : - _impl(*library._impl) -{ - _handle = _impl.lsf_shader_file_create(); - if (!_handle) - throw Exception(_impl.lsf_get_last_error_msg(), _impl.lsf_get_last_error_code()); - ErrorCode err = _impl.lsf_shader_file_set_log_callback(_handle, &ShaderFile::logCallback, this); - if (err != errNone) - logMsg(llWarning, "unable to register log callback"); -} - -lsf::ShaderFile::~ShaderFile() -{ - _impl.lsf_shader_file_destroy(_handle); - _handle = NULL; -} - -void lsf::ShaderFile::logCallback(const lsf::LogLevel loglevel, const char* msg, void* userargs) -{ - static_cast<ShaderFile*>(userargs)->logMsg(loglevel, std::string(msg)); -} - -/* Generator **********************************************************************************************************************/ -inline std::string lsf::Generator::getName() const - { return _name; }; - -inline lsf::Generator::Handle lsf::Generator::getHandle() const - { return _handle; }; - -inline const lsf::ShaderFile& lsf::Generator::getShaderFile() const - { return _shaderFile; }; - -inline const lsf::Generator::StringVec& lsf::Generator::getPropertyNames() const - { return _propertyNames; }; - -std::string lsf::Generator::getProperty(const std::string& name) const -{ - const char* ret = _impl.lsf_generator_get_property_by_name(_handle, name.c_str()); - if (!ret) - throw Exception(_impl.lsf_get_last_error_msg(), _impl.lsf_get_last_error_code()); - return std::string(ret); -} - -std::string lsf::Generator::getProperty(int index) const -{ - const char* ret = _impl.lsf_generator_get_property(_handle, index); - if (!ret) - throw Exception(_impl.lsf_get_last_error_msg(), _impl.lsf_get_last_error_code()); - return std::string(ret); -} - -void lsf::Generator::setProperty(const std::string& name, const std::string& value) -{ - ErrorCode err = _impl.lsf_generator_set_property_by_name(_handle, name.c_str(), value.c_str()); - if (err != errNone) - throw Exception(_impl.lsf_get_last_error_msg(), err); -} - -void lsf::Generator::setProperty(int index, const std::string& value) -{ - ErrorCode err = _impl.lsf_generator_set_property(_handle, index, value.c_str()); - if (err != errNone) - throw Exception(_impl.lsf_get_last_error_msg(), err); -} - -std::string lsf::Generator::generateCode() const -{ - const char* ret = _impl.lsf_generator_generate_code(_handle); - if (!ret) - throw Exception(_impl.lsf_get_last_error_msg(), _impl.lsf_get_last_error_code()); - return std::string(ret); -} - -lsf::Generator::Generator(const ShaderFile& shaderFile, std::string name) : - _shaderFile (shaderFile), - _impl (*shaderFile.getLibrary()._impl), - _name (name) -{ - _handle = _impl.lsf_generator_create(_shaderFile.getHandle(), _name.c_str()); - if (!_handle) - throw Exception(_impl.lsf_get_last_error_msg(), _impl.lsf_get_last_error_code()); - const char* propertyNames = _impl.lsf_generator_get_property_names(_handle); - if (propertyNames) - { - std::stringstream ss(propertyNames); - std::string item; - while (std::getline(ss, item, '\x10')) - _propertyNames.push_back(item); - } -} - -lsf::Generator::~Generator() -{ - _impl.lsf_generator_destroy(_handle); - _handle = NULL; -} - -/* Exception **********************************************************************************************************************/ -inline lsf::ErrorCode lsf::Exception::getErrorCode() const - { return _errorCode; } - -inline std::string lsf::Exception::getMessage() const - { return _message; } - -const char* lsf::Exception::what() const throw() - { return _message.c_str(); }; - -lsf::Exception::Exception(std::string message, ErrorCode errorCode) : - _message (message), - _errorCode (errorCode) - { } - -lsf::Exception::~Exception() throw() - { } - -#endif /* LIB_SHADER_FILE_HPP */ - - - diff --git a/library/header/ulibShaderFile.pas b/library/header/ulibShaderFile.pas deleted file mode 100644 index 8693f5f..0000000 --- a/library/header/ulibShaderFile.pas +++ /dev/null @@ -1,450 +0,0 @@ -unit ulibShaderFile; - -{$IFDEF fpc} - {$mode objfpc}{$H+} -{$ENDIF} - -interface - -uses - Classes, SysUtils, Variants; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -type - {$Z4} - TlsfLogLevel = ( - llDebug = 0, - llInfo = 1, - llWarning = 2, - llError = 3 - ); - - {$Z4} - TlsfErrorCode = ( - errUnknown = -1, - errNone = $00000000, - errNotInit = $00000001, - errInvalidHandleShaderFile = $00000010, - errInvalidHandleShaderGenerator = $00000011, - errInvalidGeneratorName = $00000020, - errInvalidPropertyIndex = $00000021, - errInvalidPropertyName = $00000022, - errGeneratorNotAssignedToFile = $00000023, - errUnknownIdentfifier = $00001000, - errDuplicateIdentifier = $00001001, - errOutOfRange = $00001002, - errInvalidIdentifier = $00001003, - errInvalidParamterCount = $00001004, - errInvalidParamter = $00001005, - errUnexpectedToken = $00001006, - errInvalidToken = $00001007, - errExpressionInternal = $00001008, - errExpression = $00001009, - errShaderPartInternal = $0000100a, - errShaderPart = $0000100b, - errInvalidLibraryName = $00002000, - errInvalidLibraryHandle = $00002001, - errInvalidMethodName = $00002002 - ); - - TlsfShaderFileHandle = Pointer; - TlsfGeneratorHandle = Pointer; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TlsfShaderFileLogEvent = procedure(const aLogLevel: TlsfLogLevel; const aMsg: PAnsiChar; const aUserArgs: Pointer); stdcall; - - Tlsf_ShaderFile_create = function: TlsfShaderFileHandle; stdcall; - Tlsf_ShaderFile_setLogCallback = function(const aHandle: TlsfShaderFileHandle; const aCallback: TlsfShaderFileLogEvent; const aUserArgs: Pointer): TlsfErrorCode; stdcall; - Tlsf_ShaderFile_loadFromFile = function(const aHandle: TlsfShaderFileHandle; const aFilename: PAnsiChar): TlsfErrorCode; stdcall; - Tlsf_ShaderFile_saveToFile = function(const aHandle: TlsfShaderFileHandle; const aFilename: PAnsiChar): TlsfErrorCode; stdcall; - Tlsf_ShaderFile_getGeneratorNames = function(const aHandle: TlsfShaderFileHandle): PAnsiChar; stdcall; - Tlsf_ShaderFile_destroy = function(const aHandle: TlsfShaderFileHandle): TlsfErrorCode; stdcall; - - Tlsf_Generator_create = function(const aHandle: TlsfShaderFileHandle; const aName: PAnsiChar): TlsfGeneratorHandle; stdcall; - Tlsf_Generator_getPropertyNames = function(const aHandle: TlsfGeneratorHandle): PAnsiChar; stdcall; - Tlsf_Generator_getProperty = function(const aHandle: TlsfGeneratorHandle; const aIndex: Integer): PAnsiChar; stdcall; - Tlsf_Generator_getPropertyByName = function(const aHandle: TlsfGeneratorHandle; const aName: PAnsiChar): PAnsiChar; stdcall; - Tlsf_Generator_setProperty = function(const aHandle: TlsfGeneratorHandle; const aIndex: Integer; const aValue: PAnsiChar): TlsfErrorCode; stdcall; - Tlsf_Generator_setPropertyByName = function(const aHandle: TlsfGeneratorHandle; const aName: PAnsiChar; const aValue: PAnsiChar): TlsfErrorCode; stdcall; - Tlsf_Generator_generateCode = function(const aHandle: TlsfGeneratorHandle): PAnsiChar; stdcall; - Tlsf_Generator_destroy = function(const aHandle: TlsfGeneratorHandle): TlsfErrorCode; stdcall; - - Tlsf_init = function: TlsfErrorCode; stdcall; - Tlsf_getLastErrorCode = function: TlsfErrorCode; stdcall; - Tlsf_getLastErrorMsg = function: PAnsiChar; stdcall; - Tlsf_getLastErrorTrace = function: PAnsiChar; stdcall; - Tlsf_finish = function: TlsfErrorCode; stdcall; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TlsfShaderFile = class(TObject) - private - fHandle: TlsfShaderFileHandle; - protected - procedure LogMsg(const aLogLevel: TlsfLogLevel; const aMsg: String); virtual; - public - property Handle: TlsfShaderFileHandle read fHandle; - - procedure LoadFromFile(const aFilename: String); - procedure SaveToFile(const aFilename: String); - - constructor Create; - destructor Destroy; override; - end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TlsfGenerator = class(TObject) - private - fName: String; - fHandle: TlsfGeneratorHandle; - fShaderFile: TlsfShaderFile; - fProperties: TStringList; - - function GetProperties: TStrings; - public - property Name: String read fName; - property ShaderFile: TlsfShaderFile read fShaderFile; - property Properties: TStrings read GetProperties; - - function GetProperty(const aName: String): Variant; overload; - function GetProperty(const aIndex: Integer): Variant; overload; - procedure SetProperty(const aName: String; const aValue: Variant); overload; - procedure SetProperty(const aIndex: Integer; const aValue: Variant); overload; - - function GenerateCode: String; - - constructor Create(const aShaderFile: TlsfShaderFile; const aName: String); - destructor Destroy; override; - end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TlsfException = class(Exception) - private - fErrorCode: TlsfErrorCode; - public - property ErrorCode: TlsfErrorCode read fErrorCode; - constructor Create(const aMsg: string; const aError: TlsfErrorCode = errNone); - end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -var - lsf_ShaderFile_create: Tlsf_ShaderFile_create; - lsf_ShaderFile_setLogCallback: Tlsf_ShaderFile_setLogCallback; - lsf_ShaderFile_loadFromFile: Tlsf_ShaderFile_loadFromFile; - lsf_ShaderFile_saveToFile: Tlsf_ShaderFile_saveToFile; - lsf_ShaderFile_getGeneratorNames: Tlsf_ShaderFile_getGeneratorNames; - lsf_ShaderFile_destroy: Tlsf_ShaderFile_destroy; - - lsf_Generator_create: Tlsf_Generator_create; - lsf_Generator_getPropertyNames: Tlsf_Generator_getPropertyNames; - lsf_Generator_getProperty: Tlsf_Generator_getProperty; - lsf_Generator_getPropertyByName: Tlsf_Generator_getPropertyByName; - lsf_Generator_setProperty: Tlsf_Generator_setProperty; - lsf_Generator_setPropertyByName: Tlsf_Generator_setPropertyByName; - lsf_Generator_generateCode: Tlsf_Generator_generateCode; - lsf_Generator_destroy: Tlsf_Generator_destroy; - - lsf_getLastErrorCode: Tlsf_getLastErrorCode; - lsf_getLastErrorMsg: Tlsf_getLastErrorMsg; - lsf_getLastErrorTrace: Tlsf_getLastErrorTrace; - -procedure lsf_init(const aLibName: String); -procedure lsf_finish; - -implementation - -{$IF DEFINED(WIN32) OR DEFINED(WIN64)} -uses - windows; - -type - TLibHandle = HMODULE; - -const - InvalidLibHandle: TLibHandle = 0; - -function LibOpen(const aLibName: String; out aError: String): TLibHandle; -begin - result := LoadLibraryA(PAnsiChar(AnsiString(aLibName))); - if (result = 0) - then aError := SysErrorMessage(GetLastError()) - else aError := ''; -end; - -function GetAddr(const aLibHandle: TLibHandle; const aName: String): Pointer; -begin - result := GetProcAddress(aLibHandle, PAnsiChar(AnsiString(aName))); -end; - -procedure LibClose(const aLibHandle: TLibHandle); -begin - FreeLibrary(aLibHandle); -end; - -{$ELSEIF DEFINED(LINUX)} -uses - dl; - -type - TLibHandle = Pointer; - -const - InvalidLibHandle: TLibHandle = nil; - -function LibOpen(const aLibName: String; out aError: String): TLibHandle; -begin - dlerror(); - result := dlopen(PChar(aLibName), RTLD_LAZY); - if (result = InvalidLibHandle) - then aError := dlerror() - else aError := ''; -end; - -function GetAddr(const aLibHandle: TLibHandle; const aName: String): Pointer; -begin - result := dlsym(aLibHandle, PChar(aName)); -end; - -procedure LibClose(const aLibHandle: TLibHandle); -begin - dlclose(aLibHandle); -end; - -{$ELSE} - {$ERROR 'unknown operation system'} -{$IFEND} - -var - libHandle: TLibHandle; - lsf_init_intern: Tlsf_init; - lsf_finish_intern: Tlsf_finish; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure lsf_init(const aLibName: String); - - function LoadProc(const aName: String): Pointer; - begin - result := GetAddr(libHandle, aName); - if not Assigned(result) then - raise Exception.CreateFmt('unable to load ''%s'' from ''%s''', [aName, aLibName]); - end; - -var - eMsg: String; - err: TlsfErrorCode; -begin - libHandle := LibOpen(aLibName, eMsg); - if (libHandle = InvalidLibHandle) then - raise Exception.Create('unable to load library: ' + eMsg); - - lsf_ShaderFile_create := Tlsf_ShaderFile_create( LoadProc('lsf_ShaderFile_create')); - lsf_ShaderFile_setLogCallback := Tlsf_ShaderFile_setLogCallback( LoadProc('lsf_ShaderFile_setLogCallback')); - lsf_ShaderFile_loadFromFile := Tlsf_ShaderFile_loadFromFile( LoadProc('lsf_ShaderFile_loadFromFile')); - lsf_ShaderFile_saveToFile := Tlsf_ShaderFile_saveToFile( LoadProc('lsf_ShaderFile_saveToFile')); - lsf_ShaderFile_getGeneratorNames := Tlsf_ShaderFile_getGeneratorNames( LoadProc('lsf_ShaderFile_getGeneratorNames')); - lsf_ShaderFile_destroy := Tlsf_ShaderFile_destroy( LoadProc('lsf_ShaderFile_destroy')); - - lsf_Generator_create := Tlsf_Generator_create( LoadProc('lsf_Generator_create')); - lsf_Generator_getPropertyNames := Tlsf_Generator_getPropertyNames( LoadProc('lsf_Generator_getPropertyNames')); - lsf_Generator_getProperty := Tlsf_Generator_getProperty( LoadProc('lsf_Generator_getProperty')); - lsf_Generator_getPropertyByName := Tlsf_Generator_getPropertyByName( LoadProc('lsf_Generator_getPropertyByName')); - lsf_Generator_setProperty := Tlsf_Generator_setProperty( LoadProc('lsf_Generator_setProperty')); - lsf_Generator_setPropertyByName := Tlsf_Generator_setPropertyByName( LoadProc('lsf_Generator_setPropertyByName')); - lsf_Generator_generateCode := Tlsf_Generator_generateCode( LoadProc('lsf_Generator_generateCode')); - lsf_Generator_destroy := Tlsf_Generator_destroy( LoadProc('lsf_Generator_destroy')); - - lsf_init_intern := Tlsf_init( LoadProc('lsf_init')); - lsf_getLastErrorCode := Tlsf_getLastErrorCode( LoadProc('lsf_getLastErrorCode')); - lsf_getLastErrorMsg := Tlsf_getLastErrorMsg( LoadProc('lsf_getLastErrorMsg')); - lsf_getLastErrorTrace := Tlsf_getLastErrorTrace( LoadProc('lsf_getLastErrorTrace')); - lsf_finish_intern := Tlsf_finish( LoadProc('lsf_finish')); - - err := lsf_init_intern(); - if (err <> errNone) then - raise TlsfException.Create('error while initializing library: ' + lsf_getLastErrorMsg(), err); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure lsf_finish; -begin - lsf_finish_intern(); - lsf_ShaderFile_create := nil; - lsf_ShaderFile_setLogCallback := nil; - lsf_ShaderFile_loadFromFile := nil; - lsf_ShaderFile_saveToFile := nil; - lsf_ShaderFile_getGeneratorNames := nil; - lsf_ShaderFile_destroy := nil; - lsf_getLastErrorCode := nil; - lsf_getLastErrorMsg := nil; - lsf_getLastErrorTrace := nil; - if (libHandle <> InvalidLibHandle) then begin - LibClose(libHandle); - libHandle := InvalidLibHandle; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure LogCallback(const aLogLevel: TlsfLogLevel; const aMsg: PAnsiChar; const aUserArgs: Pointer); stdcall; -begin - TlsfShaderFile(aUserArgs).LogMsg(aLogLevel, String(aMsg)); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//TlsfShaderFile//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TlsfShaderFile.LogMsg(const aLogLevel: TlsfLogLevel; const aMsg: String); -begin - // DUMMY -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TlsfShaderFile.LoadFromFile(const aFilename: String); -var - err: TlsfErrorCode; -begin - err := lsf_ShaderFile_loadFromFile(fHandle, PAnsiChar(AnsiString(aFilename))); - if (err <> errNone) then - raise TlsfException.Create('error while loading from file: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TlsfShaderFile.SaveToFile(const aFilename: String); -var - err: TlsfErrorCode; -begin - err := lsf_ShaderFile_saveToFile(fHandle, PAnsiChar(AnsiString(aFilename))); - if (err <> errNone) then - raise TlsfException.Create('error while saving to file: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TlsfShaderFile.Create; -var - err: TlsfErrorCode; -begin - inherited Create; - - fHandle := lsf_ShaderFile_create(); - if not Assigned(fHandle) then - raise TlsfException.Create('error while creating shader file: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); - - err := lsf_ShaderFile_setLogCallback(fHandle, @LogCallback, self); - if (err <> errNone) then - raise TlsfException.Create('error while settings log callback: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -destructor TlsfShaderFile.Destroy; -begin - if Assigned(fHandle) then begin - lsf_ShaderFile_destroy(fHandle); - fHandle := nil; - end; - inherited Destroy; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//TlsfGenerator///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TlsfGenerator.GetProperties: TStrings; -begin - result := fProperties; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TlsfGenerator.GetProperty(const aName: String): Variant; -var - s: PAnsiChar; -begin - s := lsf_Generator_getPropertyByName(fHandle, PAnsiChar(AnsiString(aName))); - if not Assigned(s) then - raise TlsfException.Create('error while getting property by name: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); - result := String(s); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TlsfGenerator.GetProperty(const aIndex: Integer): Variant; -var - s: PAnsiChar; -begin - s := lsf_Generator_getProperty(fHandle, aIndex); - if not Assigned(s) then - raise TlsfException.Create('error while getting property by index: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); - result := String(s); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TlsfGenerator.SetProperty(const aName: String; const aValue: Variant); -var - err: TlsfErrorCode; - s: AnsiString; -begin - s := AnsiString(aValue); - err := lsf_Generator_setPropertyByName(fHandle, PAnsiChar(AnsiString(aName)), PAnsiChar(s)); - if (err <> errNone) then - raise TlsfException.Create('error while settings property by name: ' + lsf_getLastErrorMsg(), err); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TlsfGenerator.SetProperty(const aIndex: Integer; const aValue: Variant); -var - err: TlsfErrorCode; - s: AnsiString; -begin - s := AnsiString(aValue); - err := lsf_Generator_setProperty(fHandle, aIndex, PAnsiChar(s)); - if (err <> errNone) then - raise TlsfException.Create('error while settings property by name: ' + lsf_getLastErrorMsg(), err); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TlsfGenerator.GenerateCode: String; -var - s: PAnsiChar; -begin - s := lsf_Generator_generateCode(fHandle); - if not Assigned(s) then - raise TlsfException.Create('error while generating code: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); - result := String(s); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TlsfGenerator.Create(const aShaderFile: TlsfShaderFile; const aName: String); -var - s: PAnsiChar; -begin - inherited Create; - fProperties := TStringList.Create; - fShaderFile := aShaderFile; - fName := aName; - fHandle := lsf_Generator_create(fShaderFile.Handle, PAnsiChar(AnsiString(aName))); - if not Assigned(fHandle) then - raise TlsfException.Create('error while opening generator: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); - - s := lsf_Generator_getPropertyNames(fHandle); - if not Assigned(s) then - raise TlsfException.Create('error while generating code: ' + lsf_getLastErrorMsg(), lsf_getLastErrorCode()); - fProperties.Text := string(s); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -destructor TlsfGenerator.Destroy; -begin - if Assigned(fHandle) then begin - lsf_Generator_destroy(fHandle); - fHandle := nil; - end; - FreeAndNil(fProperties); - inherited Destroy; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//TlsfException///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TlsfException.Create(const aMsg: string; const aError: TlsfErrorCode); -begin - inherited Create(aMsg); - fErrorCode := aError; -end; - -end. - diff --git a/library/libShaderFile.lpi b/library/libShaderFile.lpi deleted file mode 100644 index 12001f3..0000000 --- a/library/libShaderFile.lpi +++ /dev/null @@ -1,380 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<CONFIG> - <ProjectOptions> - <Version Value="9"/> - <PathDelim Value="\"/> - <General> - <Flags> - <MainUnitHasCreateFormStatements Value="False"/> - <MainUnitHasTitleStatement Value="False"/> - </Flags> - <SessionStorage Value="InProjectDir"/> - <MainUnit Value="0"/> - <Title Value="libShaderFile"/> - <UseAppBundle Value="False"/> - <ResourceType Value="res"/> - </General> - <i18n> - <EnableI18N LFM="False"/> - </i18n> - <VersionInfo> - <StringTable ProductVersion=""/> - </VersionInfo> - <BuildModes Count="8"> - <Item1 Name="Win32Debug" Default="True"/> - <Item2 Name="Win32Release"> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <CodeGeneration> - <SmartLinkUnit Value="True"/> - <RelocatableUnit Value="True"/> - <TargetCPU Value="i386"/> - <TargetOS Value="win32"/> - <Optimizations> - <OptimizationLevel Value="3"/> - </Optimizations> - </CodeGeneration> - <Linking> - <Debugging> - <GenerateDebugInfo Value="False"/> - </Debugging> - <LinkSmart Value="True"/> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - </Item2> - <Item3 Name="Win64Debug"> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <Parsing> - <SyntaxOptions> - <IncludeAssertionCode Value="True"/> - </SyntaxOptions> - </Parsing> - <CodeGeneration> - <RelocatableUnit Value="True"/> - <Checks> - <IOChecks Value="True"/> - <RangeChecks Value="True"/> - <OverflowChecks Value="True"/> - <StackChecks Value="True"/> - </Checks> - <TargetCPU Value="x86_64"/> - <TargetOS Value="win64"/> - </CodeGeneration> - <Linking> - <Debugging> - <DebugInfoType Value="dsDwarf2Set"/> - <UseHeaptrc Value="True"/> - <UseExternalDbgSyms Value="True"/> - </Debugging> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - </Item3> - <Item4 Name="Win64Release"> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <CodeGeneration> - <SmartLinkUnit Value="True"/> - <RelocatableUnit Value="True"/> - <TargetCPU Value="x86_64"/> - <TargetOS Value="win64"/> - <Optimizations> - <OptimizationLevel Value="3"/> - </Optimizations> - </CodeGeneration> - <Linking> - <Debugging> - <GenerateDebugInfo Value="False"/> - </Debugging> - <LinkSmart Value="True"/> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - </Item4> - <Item5 Name="Linux32Debug"> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <Parsing> - <SyntaxOptions> - <IncludeAssertionCode Value="True"/> - </SyntaxOptions> - </Parsing> - <CodeGeneration> - <RelocatableUnit Value="True"/> - <Checks> - <IOChecks Value="True"/> - <RangeChecks Value="True"/> - <OverflowChecks Value="True"/> - <StackChecks Value="True"/> - </Checks> - <TargetCPU Value="i386"/> - <TargetOS Value="linux"/> - </CodeGeneration> - <Linking> - <Debugging> - <DebugInfoType Value="dsDwarf2Set"/> - <UseHeaptrc Value="True"/> - <UseExternalDbgSyms Value="True"/> - </Debugging> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - </Item5> - <Item6 Name="Linux32Release"> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <CodeGeneration> - <SmartLinkUnit Value="True"/> - <RelocatableUnit Value="True"/> - <TargetCPU Value="i386"/> - <TargetOS Value="linux"/> - <Optimizations> - <OptimizationLevel Value="3"/> - </Optimizations> - </CodeGeneration> - <Linking> - <Debugging> - <GenerateDebugInfo Value="False"/> - </Debugging> - <LinkSmart Value="True"/> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - </Item6> - <Item7 Name="Linux64Debug"> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <Parsing> - <SyntaxOptions> - <IncludeAssertionCode Value="True"/> - </SyntaxOptions> - </Parsing> - <CodeGeneration> - <RelocatableUnit Value="True"/> - <Checks> - <IOChecks Value="True"/> - <RangeChecks Value="True"/> - <OverflowChecks Value="True"/> - <StackChecks Value="True"/> - </Checks> - <TargetCPU Value="x86_64"/> - <TargetOS Value="linux"/> - </CodeGeneration> - <Linking> - <Debugging> - <DebugInfoType Value="dsDwarf2Set"/> - <UseHeaptrc Value="True"/> - <UseExternalDbgSyms Value="True"/> - </Debugging> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - </Item7> - <Item8 Name="Linux64Release"> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <CodeGeneration> - <SmartLinkUnit Value="True"/> - <RelocatableUnit Value="True"/> - <TargetCPU Value="x86_64"/> - <TargetOS Value="linux"/> - <Optimizations> - <OptimizationLevel Value="3"/> - </Optimizations> - </CodeGeneration> - <Linking> - <Debugging> - <GenerateDebugInfo Value="False"/> - </Debugging> - <LinkSmart Value="True"/> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - </Item8> - </BuildModes> - <PublishOptions> - <Version Value="2"/> - </PublishOptions> - <RunParams> - <local> - <FormatVersion Value="1"/> - </local> - </RunParams> - <Units Count="1"> - <Unit0> - <Filename Value="libShaderFile.lpr"/> - <IsPartOfProject Value="True"/> - </Unit0> - </Units> - </ProjectOptions> - <CompilerOptions> - <Version Value="11"/> - <PathDelim Value="\"/> - <Target> - <Filename Value="libShaderFile-$(TargetCPU)-$(TargetOS)"/> - </Target> - <SearchPaths> - <IncludeFiles Value="$(ProjOutDir);..\inc"/> - <OtherUnitFiles Value=".."/> - <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> - </SearchPaths> - <Parsing> - <SyntaxOptions> - <IncludeAssertionCode Value="True"/> - </SyntaxOptions> - </Parsing> - <CodeGeneration> - <RelocatableUnit Value="True"/> - <Checks> - <IOChecks Value="True"/> - <RangeChecks Value="True"/> - <OverflowChecks Value="True"/> - <StackChecks Value="True"/> - </Checks> - <TargetCPU Value="i386"/> - <TargetOS Value="win32"/> - </CodeGeneration> - <Linking> - <Debugging> - <DebugInfoType Value="dsDwarf2Set"/> - <UseHeaptrc Value="True"/> - <UseExternalDbgSyms Value="True"/> - </Debugging> - <Options> - <ExecutableType Value="Library"/> - </Options> - </Linking> - <Other> - <CompilerMessages> - <IgnoredMessages idx5024="True"/> - </CompilerMessages> - </Other> - </CompilerOptions> - <Debugging> - <Exceptions Count="3"> - <Item1> - <Name Value="EAbort"/> - </Item1> - <Item2> - <Name Value="ECodetoolError"/> - </Item2> - <Item3> - <Name Value="EFOpenError"/> - </Item3> - </Exceptions> - </Debugging> -</CONFIG> diff --git a/library/libShaderFile.lpr b/library/libShaderFile.lpr deleted file mode 100644 index 98c3f52..0000000 --- a/library/libShaderFile.lpr +++ /dev/null @@ -1,681 +0,0 @@ -library libShaderFile; - -{$mode objfpc}{$H+} - -uses - SysUtils, variants, - uengShaderFile, uengShaderGenerator, uengShaderPart, - uengShaderFileGenerics, uengShaderFileTypes; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//external types and contstants///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -const - {%H-}LSF_LOGLEVEL_DEBUG = llDebug; - {%H-}LSF_LOGLEVEL_INFO = llInfo; - {%H-}LSF_LOGLEVEL_WARNING = llWarning; - {%H-}LSF_LOGLEVEL_ERROR = llError; - - LSF_ERR_NONE = $00000000; - LSF_ERR_NOT_INIT = $00000001; - LSF_ERR_INVALID_HANDLE_SHADER_FILE = $00000010; - LSF_ERR_INVALID_HANDLE_SHADER_GENERATOR = $00000011; - LSF_ERR_INVALID_GENERATOR_NAME = $00000020; - LSF_ERR_INVALID_PROPERTY_INDEX = $00000021; - LSF_ERR_INVALID_PROPERTY_NAME = $00000022; - LSF_ERR_GENERATOR_NOT_ASSIGNED_TO_FILE = $00000023; - LSF_ERR_UNKNOWN_IDENTFIFIER = $00001000; - LSF_ERR_DUPLICATE_IDENTIFIER = $00001001; - LSF_ERR_OUT_OF_RANGE = $00001002; - LSF_ERR_INVALID_IDENTIFIER = $00001003; - LSF_ERR_INVALID_PARAMTER_COUNT = $00001004; - LSF_ERR_INVALID_PARAMTER = $00001005; - LSF_ERR_UNEXPECTED_TOKEN = $00001006; - LSF_ERR_INVALID_TOKEN = $00001007; - LSF_ERR_EXPRESSION_INTERNAL = $00001008; - LSF_ERR_EXPRESSION = $00001009; - LSF_ERR_SHADER_PART_INTERNAL = $0000100A; - LSF_ERR_SHADER_PART = $0000100B; - LSF_ERR_UNKNOWN = $FFFFFFFF; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -type - TlsfErrorCode = Cardinal; - TlsfLogLevel = Cardinal; - TlsfShaderFileHandle = Pointer; - TlsfShaderGeneratorHandle = Pointer; - TlsfShaderFileLogEvent = procedure(const aLogLevel: TlsfLogLevel; const aMsg: PAnsiChar; const aUserArgs: Pointer); stdcall; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//internal types and contstants///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -type - TShaderFile = class; - TShaderGenerator = class; - - TPropertyMap = specialize TutlMap<string, variant>; - TShaderGeneratorHandleHashSet = specialize TutlHashSet<TlsfShaderGeneratorHandle>; - TShaderGeneratorHashSet = specialize TutlHashSet<TShaderGenerator>; - - TShaderGenerator = class(TObject) - private - fOwner: TShaderFile; - fGenerator: TengShaderGenerator; - fProperties: TPropertyMap; - fPropertyNames: String; - fPropertyValue: String; - fGeneratedCode: String; - public - property Owner: TShaderFile read fOwner; - property PropertyNames: String read fPropertyNames; - property Properties: TPropertyMap read fProperties; - - function GetProperty(const aIndex: Integer): PAnsiChar; - function GetProperty(const aName: String): PAnsiChar; - function SetProperty(const aIndex: Integer; const aValue: PAnsiChar): TlsfErrorCode; - function SetProperty(const aName: String; const aValue: PAnsiChar): TlsfErrorCode; - function GenerateCode: PAnsiChar; - - constructor Create(const aOwner: TShaderFile; const aGenerator: TengShaderGenerator); - destructor Destroy; override; - end; - - TShaderFile = class(TengShaderFile) - private - fLogUserArgs: Pointer; - fLogCallback: TlsfShaderFileLogEvent; - fGenerators: TShaderGeneratorHashSet; - fGeneratorNames: String; - protected - procedure LogMsgIntern(const aSender: TengShaderPart; const aLogLevel: TengShaderPartLogLevel; const aMsg: String); override; - public - property LogCallback: TlsfShaderFileLogEvent read fLogCallback write fLogCallback; - property LogUserArgs: Pointer read fLogUserArgs write fLogUserArgs; - property GeneratorNames: String read fGeneratorNames; - - procedure LoadFromFile(const aFilename: String); reintroduce; - - function CreateGenerator(const aName: String): TShaderGenerator; - function DestroyGenerator(const aGenerator: TShaderGenerator): TlsfErrorCode; - - constructor Create; overload; - destructor Destroy; override; - end; - TShaderFileHashSet = specialize TutlHashSet<TShaderFile>; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -var - ShaderFiles: TShaderFileHashSet = nil; - ShaderGenerators: TShaderGeneratorHandleHashSet = nil; - LastErrorCode: TlsfErrorCode = LSF_ERR_NONE; - LastErrorMsg: String = ''; - LastErrorTrace: String = ''; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//Misc (not exportet)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure SetLastError(const aErrorCode: TlsfErrorCode; const aMsg: String); -begin - LastErrorCode := aErrorCode; - LastErrorMsg := aMsg; - LastErrorTrace := ''; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure SetLastError(const aException: Exception); -begin - if (aException is EengUnknownIdentifier) then - LastErrorCode := LSF_ERR_UNKNOWN_IDENTFIFIER - else if (aException is EengDuplicateIdentifier) then - LastErrorCode := LSF_ERR_DUPLICATE_IDENTIFIER - else if (aException is EengOutOfRange) then - LastErrorCode := LSF_ERR_OUT_OF_RANGE - else if (aException is EengInvalidIdentifier) then - LastErrorCode := LSF_ERR_INVALID_IDENTIFIER - else if (aException is EengInvalidParamterCount) then - LastErrorCode := LSF_ERR_INVALID_PARAMTER_COUNT - else if (aException is EengInvalidParamter) then - LastErrorCode := LSF_ERR_INVALID_PARAMTER - else if (aException is EengUnexpectedToken) then - LastErrorCode := LSF_ERR_UNEXPECTED_TOKEN - else if (aException is EengInvalidToken) then - LastErrorCode := LSF_ERR_INVALID_TOKEN - else if (aException is EengExpressionInternal) then - LastErrorCode := LSF_ERR_EXPRESSION_INTERNAL - else if (aException is EengExpression) then - LastErrorCode := LSF_ERR_EXPRESSION - else if (aException is EengShaderPartInternal) then - LastErrorCode := LSF_ERR_SHADER_PART_INTERNAL - else if (aException is EengShaderPart ) then - LastErrorCode := LSF_ERR_SHADER_PART - else - LastErrorCode := LSF_ERR_UNKNOWN; - if (aException is EengShaderPart) - then LastErrorTrace := (aException as EengShaderPart).PrintTrace - else LastErrorTrace := ''; - LastErrorMsg := aException.Message; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function CheckIfInitialized: Boolean; -begin - try - result := Assigned(ShaderFiles); - if not result then - SetLastError(LSf_ERR_NOT_INIT, 'libShaderFile has not been initialized. call lsf_init before using any other methods.'); - except - on e: Exception do begin - SetLastError(e); - result := false; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function CheckShaderFileHandle(const aHandle: TlsfShaderFileHandle): Boolean; -begin - try - result := CheckIfInitialized; - if result then begin - result := ShaderFiles.Contains(TShaderFile(aHandle)); - if not result then - SetLastError(LSF_ERR_INVALID_HANDLE_SHADER_FILE, Format('0x%x is not a valid shader file handle', [{%H-}PtrUInt(aHandle)])); - end; - except - on e: Exception do begin - SetLastError(e); - result := false; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function CheckShaderGeneratorHandle(const aHandle: TlsfShaderGeneratorHandle): Boolean; -begin - try - result := CheckIfInitialized; - if result then begin - result := ShaderGenerators.Contains(TShaderGenerator(aHandle)); - if not result then - SetLastError(LSF_ERR_INVALID_HANDLE_SHADER_GENERATOR, Format('0x%x is not a valid shader generator handle', [{%H-}PtrUInt(aHandle)])); - end; - except - on e: Exception do begin - SetLastError(e); - result := false; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//ShaderFile//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_ShaderFile_create: TlsfShaderFileHandle; stdcall; -var - sf: TShaderFile; -begin - try - result := nil; - if not CheckIfInitialized then - exit; - sf := TShaderFile.Create; - ShaderFiles.Add(sf); - result := sf; - except - on e: Exception do begin - SetLastError(e); - result := nil; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_ShaderFile_setLogCallback(const aHandle: TlsfShaderFileHandle; const aCallback: TlsfShaderFileLogEvent; const aUserArgs: Pointer): TlsfErrorCode; stdcall; -begin - try - result := LSF_ERR_NONE; - if CheckShaderFileHandle(aHandle) then with TShaderFile(aHandle) do begin - LogCallback := aCallback; - LogUserArgs := aUserArgs; - end else - result := LastErrorCode; - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_ShaderFile_loadFromFile(const aHandle: TlsfShaderFileHandle; const aFilename: PAnsiChar): TlsfErrorCode; stdcall; -begin - try - result := LSF_ERR_NONE; - if not CheckShaderFileHandle(aHandle) - then result := LastErrorCode - else TShaderFile(aHandle).LoadFromFile(aFilename); - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_ShaderFile_saveToFile(const aHandle: TlsfShaderFileHandle; const aFilename: PAnsiChar): TlsfErrorCode; stdcall; -begin - try - result := LSF_ERR_NONE; - if not CheckShaderFileHandle(aHandle) - then result := LastErrorCode - else TShaderFile(aHandle).SaveToFile(aFilename); - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_ShaderFile_getGeneratorNames(const aHandle: TlsfShaderFileHandle): PAnsiChar; stdcall; -begin - try - if not CheckShaderFileHandle(aHandle) - then result := nil - else result := PAnsiChar(TShaderFile(aHandle).GeneratorNames); - except - on e: Exception do begin - SetLastError(e); - result := nil; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_ShaderFile_destroy(const aHandle: TlsfShaderFileHandle): TlsfErrorCode; stdcall; -begin - try - result := LSF_ERR_NONE; - if not CheckShaderFileHandle(aHandle) - then result := LastErrorCode - else ShaderFiles.Remove(TShaderFile(aHandle)); - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//Generator///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_create(const aHandle: TlsfShaderFileHandle; const aName: PAnsiChar): TlsfShaderGeneratorHandle; stdcall; -begin - try - if not CheckShaderFileHandle(aHandle) - then result := nil - else result := TShaderFile(aHandle).CreateGenerator(string(aName)); - except - on e: Exception do begin - SetLastError(e); - result := nil; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_getPropertyNames(const aHandle: TlsfShaderGeneratorHandle): PAnsiChar; stdcall; -begin - try - if not CheckShaderGeneratorHandle(aHandle) - then result := nil - else result := PAnsiChar(TShaderGenerator(aHandle).PropertyNames); - except - on e: Exception do begin - SetLastError(e); - result := nil; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_getProperty(const aHandle: TlsfShaderGeneratorHandle; const aIndex: Integer): PAnsiChar; stdcall; -begin - try - if not CheckShaderGeneratorHandle(aHandle) - then result := nil - else result := TShaderGenerator(aHandle).GetProperty(aIndex); - except - on e: Exception do begin - SetLastError(e); - result := nil; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_getPropertyByName(const aHandle: TlsfShaderGeneratorHandle; const aName: PAnsiChar): PAnsiChar; stdcall; -begin - try - if not CheckShaderGeneratorHandle(aHandle) - then result := nil - else result := TShaderGenerator(aHandle).GetProperty(aName); - except - on e: Exception do begin - SetLastError(e); - result := nil; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_setProperty(const aHandle: TlsfShaderGeneratorHandle; const aIndex: Integer; const aValue: PAnsiChar): TlsfErrorCode; stdcall; -begin - try - if not CheckShaderGeneratorHandle(aHandle) - then result := LastErrorCode - else result := TShaderGenerator(aHandle).SetProperty(aIndex, aValue); - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_setPropertyByName(const aHandle: TlsfShaderGeneratorHandle; const aName, aValue: PAnsiChar): TlsfErrorCode; stdcall; -begin - try - if not CheckShaderGeneratorHandle(aHandle) - then result := LastErrorCode - else result := TShaderGenerator(aHandle).SetProperty(aName, aValue); - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_generateCode(const aHandle: TlsfShaderGeneratorHandle): PAnsiChar; stdcall; -begin - try - if not CheckShaderGeneratorHandle(aHandle) - then result := nil - else result := TShaderGenerator(aHandle).GenerateCode; - except - on e: Exception do begin - SetLastError(e); - result := nil; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_Generator_destroy(const aHandle: TlsfShaderGeneratorHandle): TlsfErrorCode; stdcall; -var - sg: TShaderGenerator; - sf: TShaderFile; -begin - try - result := LSF_ERR_NONE; - if CheckShaderGeneratorHandle(aHandle) then begin - sg := TShaderGenerator(aHandle); - sf := sg.Owner; - sf.DestroyGenerator(sg); - end else - result := LastErrorCode; - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//Global//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_init: TlsfErrorCode; stdcall; -begin - try - result := LSF_ERR_NONE; - ShaderFiles := TShaderFileHashSet.Create(true); - ShaderGenerators := TShaderGeneratorHandleHashSet.Create(true); - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_getLastErrorCode: TlsfErrorCode; stdcall; -begin - result := LastErrorCode; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_getLastErrorMsg: PAnsiChar; stdcall; -begin - result := PAnsiChar(LastErrorMsg); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_getLastErrorTrace: PAnsiChar; stdcall; -begin - result := PAnsiChar(LastErrorTrace); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function lsf_finish: TlsfErrorCode; stdcall; -begin - try - result := LSF_ERR_NONE; - FreeAndNil(ShaderGenerators); - FreeAndNil(ShaderFiles); - except - on e: Exception do begin - SetLastError(e); - result := LastErrorCode; - end; - end; -end; - -exports - lsf_ShaderFile_create, - lsf_ShaderFile_setLogCallback, - lsf_ShaderFile_loadFromFile, - lsf_ShaderFile_saveToFile, - lsf_ShaderFile_getGeneratorNames, - lsf_ShaderFile_destroy, - - lsf_Generator_create, - lsf_Generator_getPropertyNames, - lsf_Generator_getProperty, - lsf_Generator_getPropertyByName, - lsf_Generator_setProperty, - lsf_Generator_setPropertyByName, - lsf_Generator_generateCode, - lsf_Generator_destroy, - - lsf_init, - lsf_getLastErrorCode, - lsf_getLastErrorMsg, - lsf_getLastErrorTrace, - lsf_finish; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//TShaderGenerator////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TShaderGenerator.GetProperty(const aIndex: Integer): PAnsiChar; -begin - result := nil; - if (aIndex < 0) or (aIndex >= fProperties.Count) then begin - SetLastError(LSF_ERR_INVALID_PROPERTY_INDEX, Format('index (%d) out of range (%d:%d)', [aIndex, 0, fProperties.Count-1])); - exit; - end; - fPropertyValue := fProperties.ValueAt[aIndex]; - result := PAnsiChar(fPropertyValue); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TShaderGenerator.GetProperty(const aName: String): PAnsiChar; -var - i: Integer; -begin - result := nil; - i := fProperties.IndexOf(aName); - if (i >= 0) - then result := GetProperty(i) - else SetLastError(LSF_ERR_INVALID_PROPERTY_NAME, Format('%s is not a valid/known property name', [aName])); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TShaderGenerator.SetProperty(const aIndex: Integer; const aValue: PAnsiChar): TlsfErrorCode; -begin - result := LSF_ERR_NONE; - if (aIndex < 0) or (aIndex >= fProperties.Count) then begin - SetLastError(LSF_ERR_INVALID_PROPERTY_INDEX, Format('index (%d) out of range (%d:%d)', [aIndex, 0, fProperties.Count-1])); - result := LastErrorCode; - end; - fProperties.ValueAt[aIndex] := string(aValue); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TShaderGenerator.SetProperty(const aName: String; const aValue: PAnsiChar): TlsfErrorCode; -var - i: Integer; -begin - i := fProperties.IndexOf(aName); - if (i < 0) then begin - SetLastError(LSF_ERR_INVALID_PROPERTY_NAME, Format('%s is not a valid/known property name', [aName])); - result := LastErrorCode; - end else - result := SetProperty(i, aValue) -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TShaderGenerator.GenerateCode: PAnsiChar; -var - kvp: TPropertyMap.TKeyValuePair; - c: TengShaderCode; -begin - for kvp in fProperties.KeyValuePairs do - fGenerator.PropertyByName[kvp.Key] := kvp.Value; - c := TengShaderCode.Create; - try - fGenerator.GenerateCode(c); - fGeneratedCode := c.Text; - result := PAnsiChar(fGeneratedCode); - finally - FreeAndNil(c); - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TShaderGenerator.Create(const aOwner: TShaderFile; const aGenerator: TengShaderGenerator); -var - i: Integer; -begin - inherited Create; - fOwner := aOwner; - fGenerator := aGenerator; - fProperties := TPropertyMap.Create(true); - fPropertyNames := ''; - for i := 0 to fGenerator.PropertyCount-1 do begin - fProperties.Add(fGenerator.PropertyNames[i], fGenerator.PropertyByIndex[i]); - fPropertyNames := fPropertyNames + fGenerator.PropertyNames[i] + sLineBreak; - end; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -destructor TShaderGenerator.Destroy; -begin - FreeAndNil(fProperties); - inherited Destroy; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//TShaderFile/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TShaderFile.LogMsgIntern(const aSender: TengShaderPart; const aLogLevel: TengShaderPartLogLevel; const aMsg: String); -var - tmp: TlsfShaderFileLogEvent; -begin - inherited LogMsgIntern(aSender, aLogLevel, aMsg); - tmp := fLogCallback; - if Assigned(tmp) then - tmp(Cardinal(aLogLevel), PAnsiChar(aMsg), fLogUserArgs); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TShaderFile.LoadFromFile(const aFilename: String); -var - i: Integer; -begin - inherited LoadFromFile(aFilename, nil); - fGeneratorNames := ''; - for i := 0 to GeneratorCount-1 do - fGeneratorNames := fGeneratorNames + inherited GeneratorNames[i] + sLineBreak; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TShaderFile.CreateGenerator(const aName: String): TShaderGenerator; - - function CheckName: Boolean; - var - i: Integer; - begin - result := true; - for i := 0 to GeneratorCount-1 do - if (inherited GeneratorNames[i] = aName) then - exit; - result := false; - end; - -begin - result := nil; - if not CheckName then begin - SetLastError(LSF_ERR_INVALID_GENERATOR_NAME, 'a generator with the name ''' + aName + ''' does not exist'); - exit; - end; - result := TShaderGenerator.Create(self, Generator[aName]); - fGenerators.Add(result); - ShaderGenerators.Add(result); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TShaderFile.DestroyGenerator(const aGenerator: TShaderGenerator): TlsfErrorCode; -begin - if Assigned(ShaderGenerators) then - ShaderGenerators.Remove(aGenerator); - if not fGenerators.Remove(aGenerator) then begin - SetLastError(LSF_ERR_GENERATOR_NOT_ASSIGNED_TO_FILE, 'the passed generator handle is not owned by any file'); - result := LastErrorCode; - end else - result := LSF_ERR_NONE; -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TShaderFile.Create; -begin - inherited Create; - fGenerators := TShaderGeneratorHashSet.Create(true); -end; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -destructor TShaderFile.Destroy; -begin - FreeAndNil(fGenerators); - inherited Destroy; -end; - -end.