2
0

FMxShaderMemo.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // The graphics engine GXScene https://github.com/glscene
  3. //
  4. unit FMxShaderMemo;
  5. (* Shader code editor *)
  6. // TODO: decide how to load templates from external file,
  7. // update it without package recompilation
  8. interface
  9. uses
  10. System.Win.Registry,
  11. System.SysUtils,
  12. System.Types,
  13. System.UITypes,
  14. System.Classes,
  15. System.Variants,
  16. FMX.Types,
  17. FMX.Controls,
  18. FMX.Forms,
  19. FMX.Graphics,
  20. FMX.Dialogs,
  21. FMX.StdCtrls,
  22. FMX.Objects,
  23. FMX.Layouts,
  24. FMX.Menus,
  25. FMX.Memo,
  26. FMX.ScrollBox,
  27. FMX.Controls.Presentation,
  28. FMX.Memo.Types;
  29. type
  30. TShaderMemoForm = class(TForm)
  31. ToolBar1: TToolBar;
  32. Panel1: TPanel;
  33. ButtonOK: TButton;
  34. ImageOK: TImage;
  35. ButtonCancel: TButton;
  36. ImageCancel: TImage;
  37. CheckButton: TSpeedButton;
  38. CompilatorLog: TMemo;
  39. SBOpen: TSpeedButton;
  40. Image1: TImage;
  41. SBSave: TSpeedButton;
  42. Image2: TImage;
  43. SBHelp: TSpeedButton;
  44. Image3: TImage;
  45. GLSLMemo: TMemo;
  46. procedure FormCreate(Sender: TObject);
  47. end;
  48. function ShaderEditorForm: TShaderMemoForm;
  49. procedure ReleaseShaderEditor;
  50. //=====================================================================
  51. implementation
  52. //=====================================================================
  53. {$R *.fmx}
  54. const
  55. cRegistryKey = 'Software\GXScene\GLXceneShaderEdit';
  56. var
  57. vShaderEditor: TShaderMemoForm;
  58. function ShaderEditorForm: TShaderMemoForm;
  59. begin
  60. if not Assigned(vShaderEditor) then
  61. vShaderEditor := TShaderMemoForm.Create(nil);
  62. Result := vShaderEditor;
  63. end;
  64. procedure ReleaseShaderEditor;
  65. begin
  66. if Assigned(vShaderEditor) then
  67. begin
  68. vShaderEditor.Free;
  69. vShaderEditor := nil;
  70. end;
  71. end;
  72. function ReadRegistryInteger(reg: TRegistry; const name: string;
  73. defaultValue: Integer): Integer;
  74. begin
  75. if reg.ValueExists(name) then
  76. Result := reg.ReadInteger(name)
  77. else
  78. Result := defaultValue;
  79. end;
  80. procedure TShaderMemoForm.FormCreate(Sender: TObject);
  81. var
  82. reg: TRegistry;
  83. No: Integer;
  84. item: TMenuItem;
  85. begin
  86. reg := TRegistry.Create;
  87. try
  88. if reg.OpenKey(cRegistryKey, True) then
  89. begin
  90. Left := ReadRegistryInteger(reg, 'Left', Left);
  91. Top := ReadRegistryInteger(reg, 'Top', Top);
  92. Width := ReadRegistryInteger(reg, 'Width', 500);
  93. Height := ReadRegistryInteger(reg, 'Height', 640);
  94. end;
  95. finally
  96. reg.Free;
  97. end;
  98. { TODO : Replace with FMX.Memo routines }
  99. (*
  100. No := GLSLMemo.Styles.Add(TColors.Red, TColors.White, []);
  101. GLSLMemo.AddWord(No, GLSLDirectives);
  102. No := GLSLMemo.Styles.Add(TColors.Purple, TColors.White, [TFontStyle.fsBold]);
  103. GLSLMemo.AddWord(No, GLSLQualifiers);
  104. No := GLSLMemo.Styles.Add(TColors.Blue, TColors.White, [TFontStyle.fsBold]);
  105. GLSLMemo.AddWord(No, GLSLTypes);
  106. No := GLSLMemo.Styles.Add(TColors.Gray, TColors.White, [TFontStyle.fsBold]);
  107. GLSLMemo.AddWord(No, GLSLBuildIn);
  108. No := GLSLMemo.Styles.Add(TColors.Green, TColors.White, [TFontStyle.fsItalic]);
  109. GLSLMemo.AddWord(No, GLSLFunctions);
  110. No := GLSLMemo.Styles.Add(TColors.Yellow, TColors.Silver, [TFontStyle.fsItalic]);
  111. GLSLMemo.AddWord(No, GLSLFunctions);
  112. FLightLineStyle := GLSLMemo.Styles.Add(TColors.Black, TColors.LtGray, []);
  113. GLSLMemo.MultiCommentLeft := '/*';
  114. GLSLMemo.MultiCommentRight := '*/';
  115. GLSLMemo.LineComment := '//';
  116. GLSLMemo.CaseSensitive := True;
  117. GLSLMemo.DelErase := True;
  118. item := NewItem('Attribute block', 0, False, True, OnTemplateClick, 0, '');
  119. item.Tag := 5;
  120. GLSL120.Add(item);
  121. item := NewItem('Basic vertex program', 0, False, True, OnTemplateClick, 0, '');
  122. item.Tag := 0;
  123. GLSL120.Add(item);
  124. item := NewItem('Basic vertex program with TBN pass', 0, False, True, OnTemplateClick, 0, '');
  125. item.Tag := 1;
  126. GLSL120.Add(item);
  127. item := NewItem('Basic fragment program, Phong lighting', 0, False, True, OnTemplateClick, 0, '');
  128. item.Tag := 2;
  129. GLSL120.Add(item);
  130. item := NewItem('Fragment program, normal mapping', 0, False, True, OnTemplateClick, 0, '');
  131. item.Tag := 3;
  132. GLSL120.Add(item);
  133. item := NewItem('Attribute block', 0, False, True, OnTemplateClick, 0, '');
  134. item.Tag := 6;
  135. GLSL330.Add(item);
  136. item := NewItem('Geometry program, edge detection', 0, False, True, OnTemplateClick, 0, '');
  137. item.Tag := 4;
  138. GLSL330.Add(item);
  139. *)
  140. end;
  141. end.