Kaynağa Gözat

* implemented some more unit tests

master
Bergmann89 11 yıl önce
ebeveyn
işleme
6235280062
26 değiştirilmiş dosya ile 304 ekleme ve 40 silme
  1. +0
    -17
      tests/ShaderFileTests.lpi
  2. +0
    -0
      tests/testfiles/code_IfElseElifEnd.shdr
  3. +15
    -0
      tests/testfiles/code_InlineFuncMultiReturn.shdr
  4. +12
    -0
      tests/testfiles/code_InlineFuncSingleReturn.shdr
  5. +0
    -0
      tests/testfiles/code_InlineIf.shdr
  6. +15
    -0
      tests/testfiles/code_InlineProc.shdr
  7. +14
    -0
      tests/testfiles/code_SimpleFunc.shdr
  8. +8
    -0
      tests/testfiles/code_SimpleInclude.shdr
  9. +15
    -0
      tests/testfiles/code_SimpleInclude_include.shdr
  10. +10
    -0
      tests/testfiles/code_SimpleMain.shdr
  11. +0
    -0
      tests/testfiles/result_IfElseElifEnd_0.shdr
  12. +0
    -0
      tests/testfiles/result_IfElseElifEnd_1.shdr
  13. +0
    -0
      tests/testfiles/result_IfElseElifEnd_2.shdr
  14. +15
    -0
      tests/testfiles/result_InlineFuncMultiReturn.shdr
  15. +10
    -0
      tests/testfiles/result_InlineFuncSingleReturn.shdr
  16. +0
    -0
      tests/testfiles/result_InlineIf_0.shdr
  17. +0
    -0
      tests/testfiles/result_InlineIf_1.shdr
  18. +13
    -0
      tests/testfiles/result_InlineProc.shdr
  19. +15
    -0
      tests/testfiles/result_SimpleFunc_0.shdr
  20. +6
    -0
      tests/testfiles/result_SimpleFunc_1.shdr
  21. +16
    -0
      tests/testfiles/result_SimpleInclude.shdr
  22. +11
    -0
      tests/testfiles/result_SimpleMain.shdr
  23. +97
    -9
      tests/uShaderFileTestCase.pas
  24. +26
    -10
      uengShaderGeneratorArgs.pas
  25. +3
    -1
      uengShaderPartIf.pas
  26. +3
    -3
      uengShaderPartParameter.pas

+ 0
- 17
tests/ShaderFileTests.lpi Dosyayı Görüntüle

@@ -43,7 +43,6 @@
<Unit0> <Unit0>
<Filename Value="ShaderFileTests.lpr"/> <Filename Value="ShaderFileTests.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="ShaderFileTests"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="uShaderFileTestCase.pas"/> <Filename Value="uShaderFileTestCase.pas"/>
@@ -53,22 +52,18 @@
<Unit2> <Unit2>
<Filename Value="..\uengShaderPart.pas"/> <Filename Value="..\uengShaderPart.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPart"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
<Filename Value="..\uengShaderFileTypes.pas"/> <Filename Value="..\uengShaderFileTypes.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderFileTypes"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="..\uengShaderFile.pas"/> <Filename Value="..\uengShaderFile.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderFile"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
<Filename Value="..\uengShaderGenerator.pas"/> <Filename Value="..\uengShaderGenerator.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderGenerator"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="..\uengShaderFileConstants.pas"/> <Filename Value="..\uengShaderFileConstants.pas"/>
@@ -88,7 +83,6 @@
<Unit9> <Unit9>
<Filename Value="..\uengShaderFileParser.pas"/> <Filename Value="..\uengShaderFileParser.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderFileParser"/>
</Unit9> </Unit9>
<Unit10> <Unit10>
<Filename Value="..\uengShaderFileScope.pas"/> <Filename Value="..\uengShaderFileScope.pas"/>
@@ -103,27 +97,22 @@
<Unit12> <Unit12>
<Filename Value="..\uengShaderPartCall.pas"/> <Filename Value="..\uengShaderPartCall.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartCall"/>
</Unit12> </Unit12>
<Unit13> <Unit13>
<Filename Value="..\uengShaderPartClass.pas"/> <Filename Value="..\uengShaderPartClass.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartClass"/>
</Unit13> </Unit13>
<Unit14> <Unit14>
<Filename Value="..\uengShaderPartCntr.pas"/> <Filename Value="..\uengShaderPartCntr.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartCntr"/>
</Unit14> </Unit14>
<Unit15> <Unit15>
<Filename Value="..\uengShaderPartComment.pas"/> <Filename Value="..\uengShaderPartComment.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartComment"/>
</Unit15> </Unit15>
<Unit16> <Unit16>
<Filename Value="..\uengShaderPartEcho.pas"/> <Filename Value="..\uengShaderPartEcho.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartEcho"/>
</Unit16> </Unit16>
<Unit17> <Unit17>
<Filename Value="..\uengShaderPartIf.pas"/> <Filename Value="..\uengShaderPartIf.pas"/>
@@ -133,22 +122,18 @@
<Unit18> <Unit18>
<Filename Value="..\uengShaderPartInclude.pas"/> <Filename Value="..\uengShaderPartInclude.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartInclude"/>
</Unit18> </Unit18>
<Unit19> <Unit19>
<Filename Value="..\uengShaderPartKeyValuePair.pas"/> <Filename Value="..\uengShaderPartKeyValuePair.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartKeyValuePair"/>
</Unit19> </Unit19>
<Unit20> <Unit20>
<Filename Value="..\uengShaderPartMessage.pas"/> <Filename Value="..\uengShaderPartMessage.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartMessage"/>
</Unit20> </Unit20>
<Unit21> <Unit21>
<Filename Value="..\uengShaderPartMeta.pas"/> <Filename Value="..\uengShaderPartMeta.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartMeta"/>
</Unit21> </Unit21>
<Unit22> <Unit22>
<Filename Value="..\uengShaderPartParameter.pas"/> <Filename Value="..\uengShaderPartParameter.pas"/>
@@ -163,12 +148,10 @@
<Unit24> <Unit24>
<Filename Value="..\uengShaderPartScope.pas"/> <Filename Value="..\uengShaderPartScope.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartScope"/>
</Unit24> </Unit24>
<Unit25> <Unit25>
<Filename Value="..\uengShaderPartText.pas"/> <Filename Value="..\uengShaderPartText.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="uengShaderPartText"/>
</Unit25> </Unit25>
<Unit26> <Unit26>
<Filename Value="..\uengShaderCodePart.pas"/> <Filename Value="..\uengShaderCodePart.pas"/>


tests/code_IfElseElifEnd.shdr → tests/testfiles/code_IfElseElifEnd.shdr Dosyayı Görüntüle


+ 15
- 0
tests/testfiles/code_InlineFuncMultiReturn.shdr Dosyayı Görüntüle

@@ -0,0 +1,15 @@
{$FUNC 'vec4' 'CalcColor' 'vec4' 'seed' $INLINE}
{$UNIFORM 'sampler2D' 'uTexture0'}
{$UNIFORM 'sampler2D' 'uTexture1'}
vec4 tex0 = texture2D(uTexture0, texCoord);
vec4 tex1 = texture2D(uTexture1, texCoord);
if (seed.r == 0.0)
return tex0 * tex1 * uColor;
else
return tex0 * tex1 * (-1.0 * uColor);
{$END}

{$MAIN}
{$UNIFORM 'vec4' 'uColor'}
gl_FragColor = {$CALL CalcColor 'uColor'};
{$END}

+ 12
- 0
tests/testfiles/code_InlineFuncSingleReturn.shdr Dosyayı Görüntüle

@@ -0,0 +1,12 @@
{$FUNC 'vec4' 'CalcColor' 'vec4' 'seed' $INLINE}
{$UNIFORM 'sampler2D' 'uTexture0'}
{$UNIFORM 'sampler2D' 'uTexture1'}
vec4 tex0 = texture2D(uTexture0, texCoord);
vec4 tex1 = texture2D(uTexture1, texCoord);
return tex0 * tex1 * uColor;
{$END}

{$MAIN}
{$UNIFORM 'vec4' 'uColor'}
gl_FragColor = {$CALL CalcColor 'uColor'};
{$END}

tests/code_InlineIf.shdr → tests/testfiles/code_InlineIf.shdr Dosyayı Görüntüle


+ 15
- 0
tests/testfiles/code_InlineProc.shdr Dosyayı Görüntüle

@@ -0,0 +1,15 @@
{$PROC 'CalcColor' 'vec4' 'seed' 'out vec4' 'color' $INLINE}
{$UNIFORM 'sampler2D' 'uTexture0'}
{$UNIFORM 'sampler2D' 'uTexture1'}
color =
texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
uColor;
{$END}

{$MAIN}
{$UNIFORM 'vec4' 'uColor'}
vec4 color;
{$CALL CalcColor 'uColor' 'color'}
gl_FragColor = color;
{$END}

+ 14
- 0
tests/testfiles/code_SimpleFunc.shdr Dosyayı Görüntüle

@@ -0,0 +1,14 @@
{$PROPERTY TestProperty '0'}

{$FUNC 'vec4' 'CalcColor' 'vec4' 'seed'}
{$UNIFORM 'sampler2D' 'uTexture0'}
{$UNIFORM 'sampler2D' 'uTexture1'}
return texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
seed;
{$END}

{$MAIN}
{$UNIFORM 'vec4' 'uColor'}
gl_FragColor = {$IF TestProperty}uColor{$ELSE}{$CALL CalcColor 'uColor'}{$END};
{$END}

+ 8
- 0
tests/testfiles/code_SimpleInclude.shdr Dosyayı Görüntüle

@@ -0,0 +1,8 @@
{$INCLUDE './code_SimpleInclude_include.shdr'}

uniform vec4 uColor;

void main(void)
{
gl_FragColor = CalcColor(uColor);
}

+ 15
- 0
tests/testfiles/code_SimpleInclude_include.shdr Dosyayı Görüntüle

@@ -0,0 +1,15 @@


uniform sampler2D uTexture0;
uniform sampler2D uTexture1;



vec4 CalcColor(vec4 seed)
{
return texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
seed;
}



+ 10
- 0
tests/testfiles/code_SimpleMain.shdr Dosyayı Görüntüle

@@ -0,0 +1,10 @@
{$MAIN}
{$UNIFORM 'sampler2D' 'uTexture0'}
{$UNIFORM 'sampler2D' 'uTexture1'}
{$UNIFORM 'vec4' 'uColor'}

gl_FragColor =
texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
uColor;
{$END}

tests/result_IfElseElifEnd_0.shdr → tests/testfiles/result_IfElseElifEnd_0.shdr Dosyayı Görüntüle


tests/result_IfElseElifEnd_1.shdr → tests/testfiles/result_IfElseElifEnd_1.shdr Dosyayı Görüntüle


tests/result_IfElseElifEnd_2.shdr → tests/testfiles/result_IfElseElifEnd_2.shdr Dosyayı Görüntüle


+ 15
- 0
tests/testfiles/result_InlineFuncMultiReturn.shdr Dosyayı Görüntüle

@@ -0,0 +1,15 @@
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform vec4 uColor;

void main(void)
{
vec4 CalcColor_ret0000;
vec4 tex0 = texture2D(uTexture0, texCoord);
vec4 tex1 = texture2D(uTexture1, texCoord);
if (uColor.r == 0.0)
CalcColor_ret0000 = tex0 * tex1 * uColor;
else
CalcColor_ret0000 = tex0 * tex1 * (-1.0 * uColor);
gl_FragColor = CalcColor_ret0000;
}

+ 10
- 0
tests/testfiles/result_InlineFuncSingleReturn.shdr Dosyayı Görüntüle

@@ -0,0 +1,10 @@
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform vec4 uColor;

void main(void)
{
vec4 tex0 = texture2D(uTexture0, texCoord);
vec4 tex1 = texture2D(uTexture1, texCoord);
gl_FragColor = (tex0 * tex1 * uColor);
}

tests/result_InlineIf_0.shdr → tests/testfiles/result_InlineIf_0.shdr Dosyayı Görüntüle


tests/result_InlineIf_1.shdr → tests/testfiles/result_InlineIf_1.shdr Dosyayı Görüntüle


+ 13
- 0
tests/testfiles/result_InlineProc.shdr Dosyayı Görüntüle

@@ -0,0 +1,13 @@
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform vec4 uColor;

void main(void)
{
vec4 color;
color =
texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
uColor;
gl_FragColor = color;
}

+ 15
- 0
tests/testfiles/result_SimpleFunc_0.shdr Dosyayı Görüntüle

@@ -0,0 +1,15 @@
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform vec4 uColor;

vec4 CalcColor(vec4 seed)
{
return texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
seed;
}

void main(void)
{
gl_FragColor = CalcColor(uColor);
}

+ 6
- 0
tests/testfiles/result_SimpleFunc_1.shdr Dosyayı Görüntüle

@@ -0,0 +1,6 @@
uniform vec4 uColor;

void main(void)
{
gl_FragColor = uColor;
}

+ 16
- 0
tests/testfiles/result_SimpleInclude.shdr Dosyayı Görüntüle

@@ -0,0 +1,16 @@
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;

vec4 CalcColor(vec4 seed)
{
return texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
seed;
}

uniform vec4 uColor;

void main(void)
{
gl_FragColor = CalcColor(uColor);
}

+ 11
- 0
tests/testfiles/result_SimpleMain.shdr Dosyayı Görüntüle

@@ -0,0 +1,11 @@
uniform sampler2D uTexture0;
uniform sampler2D uTexture1;
uniform vec4 uColor;

void main(void)
{
gl_FragColor =
texture2D(uTexture0, texCoord) *
texture2D(uTexture1, texCoord) *
uColor;
}

+ 97
- 9
tests/uShaderFileTestCase.pas Dosyayı Görüntüle

@@ -10,11 +10,37 @@ uses


type type
TShaderFileTestCase = class(TTestCase) TShaderFileTestCase = class(TTestCase)
private
protected
procedure DoTest(const aCode: String; const aValue: Integer; const aResult: String); procedure DoTest(const aCode: String; const aValue: Integer; const aResult: String);
procedure DoTest(const aCode: String; const aResult: String);
end;

TTestCase_IfElseElifEnd = class(TShaderFileTestCase)
published published
procedure IfElseElifEnd;
procedure InlineIf;
procedure IfElifElseEnd0;
procedure IfElifElseEnd1;
procedure IfElifElseEnd2;

procedure InlineIf0;
procedure InlineIf1;
end;

TTestCase_FuncProcMain = class(TShaderFileTestCase)
published
procedure SimpleMain;

procedure SimpleFunc0;
procedure SimpleFunc1;

procedure InlineProc;

procedure InlineFuncSingleReturn;
procedure InlineFuncMultiReturn;
end;

TTestCase_Include = class(TShaderFileTestCase)
published
procedure SimpleInclude;
end; end;


implementation implementation
@@ -23,7 +49,7 @@ uses
Forms; Forms;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TShaderFileTestCase///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TShaderFileTestCase///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TShaderFileTestCase.DoTest(const aCode: String; const aValue: Integer; const aResult: String); procedure TShaderFileTestCase.DoTest(const aCode: String; const aValue: Integer; const aResult: String);
var var
@@ -36,12 +62,12 @@ begin
code := TengShaderCode.Create; code := TengShaderCode.Create;
sl := TStringList.Create; sl := TStringList.Create;
try try
shdr.LoadFromFile(ExpandFileName(aCode));
shdr.LoadFromFile(ExpandFileName('testfiles\' + aCode));
gen := shdr.Generator['']; gen := shdr.Generator[''];
if (gen.PropertyCount > 0) then if (gen.PropertyCount > 0) then
gen.PropertyByIndex[0] := aValue; gen.PropertyByIndex[0] := aValue;
gen.GenerateCode(code); gen.GenerateCode(code);
sl.LoadFromFile(ExpandFileName(aResult));
sl.LoadFromFile(ExpandFileName('testfiles\' + aResult));
AssertEquals(sl.Text, code.Text); AssertEquals(sl.Text, code.Text);
finally finally
FreeAndNil(sl); FreeAndNil(sl);
@@ -50,23 +76,85 @@ begin
end; end;
end; end;


procedure TShaderFileTestCase.DoTest(const aCode: String; const aResult: String);
begin
DoTest(aCode, 0, aResult);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TTestCase_IfElseElifEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TShaderFileTestCase.IfElseElifEnd;
procedure TTestCase_IfElseElifEnd.IfElifElseEnd0;
begin begin
DoTest('code_IfElseElifEnd.shdr', 0, 'result_IfElseElifEnd_0.shdr'); DoTest('code_IfElseElifEnd.shdr', 0, 'result_IfElseElifEnd_0.shdr');
end;

procedure TTestCase_IfElseElifEnd.IfElifElseEnd1;
begin
DoTest('code_IfElseElifEnd.shdr', 1, 'result_IfElseElifEnd_1.shdr'); DoTest('code_IfElseElifEnd.shdr', 1, 'result_IfElseElifEnd_1.shdr');
end;

procedure TTestCase_IfElseElifEnd.IfElifElseEnd2;
begin
DoTest('code_IfElseElifEnd.shdr', 2, 'result_IfElseElifEnd_2.shdr'); DoTest('code_IfElseElifEnd.shdr', 2, 'result_IfElseElifEnd_2.shdr');
end; end;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TShaderFileTestCase.InlineIf;
procedure TTestCase_IfElseElifEnd.InlineIf0;
begin begin
DoTest('code_InlineIf.shdr', 0, 'result_InlineIf_0.shdr'); DoTest('code_InlineIf.shdr', 0, 'result_InlineIf_0.shdr');
end;

procedure TTestCase_IfElseElifEnd.InlineIf1;
begin
DoTest('code_InlineIf.shdr', 1, 'result_InlineIf_1.shdr'); DoTest('code_InlineIf.shdr', 1, 'result_InlineIf_1.shdr');
end; end;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TTestCase_MainSimple//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TTestCase_FuncProcMain.SimpleMain;
begin
DoTest('code_SimpleMain.shdr', 'result_SimpleMain.shdr');
end;

procedure TTestCase_FuncProcMain.SimpleFunc0;
begin
DoTest('code_SimpleFunc.shdr', 0, 'result_SimpleFunc_0.shdr');
end;

procedure TTestCase_FuncProcMain.SimpleFunc1;
begin
DoTest('code_SimpleFunc.shdr', 1, 'result_SimpleFunc_1.shdr');
end;

procedure TTestCase_FuncProcMain.InlineProc;
begin
DoTest('code_InlineProc.shdr', 'result_InlineProc.shdr');
end;

procedure TTestCase_FuncProcMain.InlineFuncSingleReturn;
begin
DoTest('code_InlineFuncSingleReturn.shdr', 'result_InlineFuncSingleReturn.shdr');
end;

procedure TTestCase_FuncProcMain.InlineFuncMultiReturn;
begin
DoTest('code_InlineFuncMultiReturn.shdr', 'result_InlineFuncMultiReturn.shdr');
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TTestCase_Include/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TTestCase_Include.SimpleInclude;
begin
DoTest('code_SimpleInclude.shdr', 0, 'result_SimpleInclude.shdr');
end;

initialization initialization
RegisterTest(TShaderFileTestCase);
RegisterTest(TTestCase_IfElseElifEnd);
RegisterTest(TTestCase_FuncProcMain);
RegisterTest(TTestCase_Include);


end. end.



+ 26
- 10
uengShaderGeneratorArgs.pas Dosyayı Görüntüle

@@ -37,12 +37,13 @@ type
TengShaderGeneratorArgs = class(TObject) TengShaderGeneratorArgs = class(TObject)
private type private type
TengGeneratorToken = ( TengGeneratorToken = (
gtNormal = 0, // normal text
gtLineBreak = 1, // line break
gtCommandEnd = 2, // command end (like ';')
gtBlockBegin = 3, // code block begin (to calculate indent)
gtBlockEnd = 4, // code block end (to calculate indent)
gtToken = 5 // code token (like '$INCLUDE' or '$IF')
gtNormal = 0, // normal text
gtLineBreak = 1, // line break
gtCommandEnd = 2, // command end (like ';')
gtBlockBegin = 3, // code block begin (to calculate indent)
gtBlockEnd = 4, // code block end (to calculate indent)
gtAppendToPrev = 5, // append current line to prev line
gtToken = 6 // code token (like '$INCLUDE' or '$IF')
); );


TCodePart = class(TObject) TCodePart = class(TObject)
@@ -121,7 +122,8 @@ type
function AddCommandEnd(const aToken: String): TengShaderGeneratorArgs; function AddCommandEnd(const aToken: String): TengShaderGeneratorArgs;
function AddLineBreak: TengShaderGeneratorArgs; function AddLineBreak: TengShaderGeneratorArgs;
function BeginBlock(const aIndent: Integer = 0): TengShaderGeneratorArgs; function BeginBlock(const aIndent: Integer = 0): TengShaderGeneratorArgs;
function EndBlock: TengShaderGeneratorArgs;
function EndBlock(const aCanAppend: Boolean = false): TengShaderGeneratorArgs;
function AppendToPrevLine: TengShaderGeneratorArgs;


procedure AddMeta(const aMeta: TengMetaData); procedure AddMeta(const aMeta: TengMetaData);
procedure AddParameter(const aParam: TengShaderPart); procedure AddParameter(const aParam: TengShaderPart);
@@ -172,6 +174,7 @@ begin
gtBlockBegin: result := format('[B%d]', [fIndent]); gtBlockBegin: result := format('[B%d]', [fIndent]);
gtBlockEnd: result := '[E]'; gtBlockEnd: result := '[E]';
gtToken: result := '[T' + fText + ']'; gtToken: result := '[T' + fText + ']';
gtAppendToPrev: result := '[A]';
else else
result := '[' + IntToStr(Integer(fToken)) + ']' + fText result := '[' + IntToStr(Integer(fToken)) + ']' + fText
end; end;
@@ -317,11 +320,13 @@ var


gtBlockEnd: begin gtBlockEnd: begin
IndentBlock(FirstLineIndex, aIndent); IndentBlock(FirstLineIndex, aIndent);
if (Trim(line) = '') and not (gfPrevIsEmpty in f) then
include(f, gfAddToPrev);
exit; exit;
end; end;


gtAppendToPrev: begin
if (Trim(line) = '') and not (gfPrevIsEmpty in f) then
include(f, gfAddToPrev);
end;
else else
s := cp.Code; s := cp.Code;
line := line + s; line := line + s;
@@ -329,6 +334,7 @@ var
end; end;
end; end;


{$IFDEF DEBUG}
procedure GenerateDebugCode; procedure GenerateDebugCode;
var var
cp: TCodePart; cp: TCodePart;
@@ -346,12 +352,15 @@ var
FreeAndNil(sl); FreeAndNil(sl);
end; end;
end; end;
{$ENDIF}


begin begin
i := 0; i := 0;
f := [gfPrevIsEmpty, gfCodeIsEmpty]; f := [gfPrevIsEmpty, gfCodeIsEmpty];
line := ''; line := '';
{$IFDEF DEBUG}
GenerateDebugCode; GenerateDebugCode;
{$ENDIF}
ProgressBlock(0); ProgressBlock(0);
end; end;


@@ -590,12 +599,19 @@ begin
end; end;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TengShaderGeneratorArgs.EndBlock: TengShaderGeneratorArgs;
function TengShaderGeneratorArgs.EndBlock(const aCanAppend: Boolean): TengShaderGeneratorArgs;
begin begin
fCode.Last.Items.Add(TCodePart.Create(gtBlockEnd, '')); fCode.Last.Items.Add(TCodePart.Create(gtBlockEnd, ''));
result := self; result := self;
end; end;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TengShaderGeneratorArgs.AppendToPrevLine: TengShaderGeneratorArgs;
begin
fCode.Last.Items.Add(TCodePart.Create(gtAppendToPrev, ''));
result := self;
end;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TengShaderGeneratorArgs.AddMeta(const aMeta: TengMetaData); procedure TengShaderGeneratorArgs.AddMeta(const aMeta: TengMetaData);
begin begin


+ 3
- 1
uengShaderPartIf.pas Dosyayı Görüntüle

@@ -166,8 +166,10 @@ begin
if b if b
then p := fIfPart then p := fIfPart
else p := fElsePart; else p := fElsePart;
if Assigned(p) then
if Assigned(p) then begin
p.GenerateCodeIntern(aArgs); p.GenerateCodeIntern(aArgs);
aArgs.AppendToPrevLine;
end;
end; end;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


+ 3
- 3
uengShaderPartParameter.pas Dosyayı Görüntüle

@@ -168,7 +168,7 @@ procedure TengShaderPartVar.GenerateCodeIntern(const aArgs: TengShaderGeneratorA
begin begin
inherited GenerateCodeIntern(aArgs); inherited GenerateCodeIntern(aArgs);
if (gfGenerateParameterCode in aArgs.Flags) then begin if (gfGenerateParameterCode in aArgs.Flags) then begin
aArgs.AddText(format('%*s %s', [aArgs.MaxParameterLength, fType, fName]));
aArgs.AddText(format('%-*s %s', [aArgs.MaxParameterLength, fType, fName]));
if (fDefaultValue <> '') then if (fDefaultValue <> '') then
aArgs.AddText(' = ' + fDefaultValue); aArgs.AddText(' = ' + fDefaultValue);
aArgs.AddCommandEnd(';'); aArgs.AddCommandEnd(';');
@@ -188,7 +188,7 @@ procedure TengShaderPartVarying.GenerateCodeIntern(const aArgs: TengShaderGenera
begin begin
inherited GenerateCodeIntern(aArgs); inherited GenerateCodeIntern(aArgs);
if (gfGenerateParameterCode in aArgs.Flags) then if (gfGenerateParameterCode in aArgs.Flags) then
aArgs.AddText(Format('varying %*s %s;', [aArgs.MaxParameterLength, fType, fName]));
aArgs.AddText(Format('varying %-*s %s;', [aArgs.MaxParameterLength, fType, fName]));
end; end;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -204,7 +204,7 @@ procedure TengShaderPartUniform.GenerateCodeIntern(const aArgs: TengShaderGenera
begin begin
inherited GenerateCodeIntern(aArgs); inherited GenerateCodeIntern(aArgs);
if (gfGenerateParameterCode in aArgs.Flags) then if (gfGenerateParameterCode in aArgs.Flags) then
aArgs.AddText(Format('uniform %*s %s;', [aArgs.MaxParameterLength, fType, fName]));
aArgs.AddText(Format('uniform %-*s %s;', [aArgs.MaxParameterLength, fType, fName]));
end; end;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Yükleniyor…
İptal
Kaydet