2
0

GLSLExpert.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // GLSLExpert
  2. {: Egg<p>
  3. GLSLExpert expert registration and bindings<p>
  4. <b>Historique : </b><font size=-1><ul>
  5. <li>14/02/05 - Egg - Creation
  6. </ul></font>
  7. }
  8. unit GLSLExpert;
  9. interface
  10. uses Windows, Classes, ToolsAPI, Menus, SysUtils;
  11. type
  12. // TGLSLWizard
  13. //
  14. TGLSLWizard = class(TNotifierObject, IOTAMenuWizard, IOTAWizard)
  15. public
  16. // IOTAWizard
  17. function GetIDString : String;
  18. function GetName : String;
  19. function GetState : TWizardState;
  20. procedure Execute;
  21. // IOTAMenuWizard
  22. function GetMenuText : String;
  23. end;
  24. // TGLSLKeyBinding
  25. //
  26. TGLSLKeyBinding = class (TNotifierObject, IOTAKeyboardBinding)
  27. procedure KeyProcValidate(const Context: IOTAKeyContext; KeyCode: TShortcut; var BindingResult: TKeyBindingResult);
  28. procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
  29. function GetBindingType : TBindingType;
  30. function GetDisplayName : String;
  31. function GetName : String;
  32. end;
  33. procedure Register;
  34. // ------------------------------------------------------------------
  35. // ------------------------------------------------------------------
  36. // ------------------------------------------------------------------
  37. implementation
  38. // ------------------------------------------------------------------
  39. // ------------------------------------------------------------------
  40. // ------------------------------------------------------------------
  41. uses Dialogs;
  42. var
  43. vKeyBindingIndex : Integer;
  44. vValidateShortCut : TShortCut = 24662; // Ctrl+Shift+V
  45. procedure Register;
  46. begin
  47. RegisterPackageWizard(TGLSLWizard.Create);
  48. vKeyBindingIndex:=(BorlandIDEServices as IOTAKeyboardServices).AddKeyboardBinding(TGLSLKeyBinding.Create);
  49. end;
  50. procedure TGLSLWizard.Execute;
  51. begin
  52. ShowMessage( 'GLSL Expert'#13#10#13#10
  53. +'Copyright 2005 - Eric Grange / GLScene.org');
  54. end;
  55. function TGLSLWizard.GetIDString: string;
  56. begin
  57. Result := 'GLScene.GLSLExpert';
  58. end;
  59. function TGLSLWizard.GetMenuText: string;
  60. begin
  61. Result := 'GLSL Expert';
  62. end;
  63. function TGLSLWizard.GetName : string;
  64. begin
  65. Result := 'GLSLExpert';
  66. end;
  67. function TGLSLWizard.GetState : TWizardState;
  68. begin
  69. Result:=[wsEnabled];
  70. end;
  71. procedure TGLSLKeyBinding.BindKeyboard(const BindingServices : IOTAKeyBindingServices);
  72. begin
  73. BindingServices.AddKeyBinding([vValidateShortCut], KeyProcValidate, nil);
  74. end;
  75. function TGLSLKeyBinding.GetBindingType : TBindingType;
  76. begin
  77. Result:=btPartial;
  78. end;
  79. function TGLSLKeyBinding.GetDisplayName : String;
  80. begin
  81. Result:='GLSLExpert KeyBinding';
  82. end;
  83. function TGLSLKeyBinding.GetName : String;
  84. begin
  85. Result:=GetDisplayName;
  86. end;
  87. // KeyProcValidate
  88. //
  89. procedure TGLSLKeyBinding.KeyProcValidate(const Context: IOTAKeyContext; KeyCode: TShortcut;
  90. var BindingResult: TKeyBindingResult);
  91. var
  92. editorServices : IOTAEditorServices;
  93. msgServices : IOTAMessageServices;
  94. msgGroup : IOTAMessageGroup;
  95. editBuffer : IOTAEditBuffer;
  96. editPosition : IOTAEditPosition;
  97. i, p, colNb, lineNb : Integer;
  98. currentDirBackup : String;
  99. fileName, cmdLine, logFileName : String;
  100. errPrefix, errLine : String;
  101. lineRef : Pointer;
  102. log : TStringList;
  103. begin
  104. BindingResult:=krHandled;
  105. editorServices:=(BorlandIDEServices as IOTAEditorServices);
  106. msgServices:=(BorlandIDEServices as IOTAMessageServices);
  107. editBuffer:=editorServices.TopBuffer;
  108. if Assigned(editBuffer) and (not editBuffer.IsReadOnly) then begin
  109. editPosition:=editBuffer.EditPosition;
  110. fileName:=editBuffer.FileName;
  111. cmdLine:='"C:\Program Files\3Dlabs\GLSL Validate\glslvalidate.exe" ';
  112. if CompareText(ExtractFileExt(fileName), '.glsl')<>0 then
  113. Exit // not a GLSL file
  114. else if Pos('_fp.glsl', LowerCase(fileName))>0 then begin
  115. cmdLine:=cmdLine+'/f ';
  116. logFileName:='fragment.log';
  117. end else if Pos('_vp.glsl', LowerCase(fileName))>0 then begin
  118. cmdLine:=cmdLine+'/v ';
  119. logFileName:='vertex.log';
  120. end else begin
  121. ShowMessage( 'Couldn''t determine if this was a vertex or fragment program.'#13#10
  122. +'Please terminate your filename with "_fp.glsl" or "_vp.glsl",'#13#10
  123. +'or contribute better detection logic code ;)');
  124. Exit;
  125. end;
  126. if editBuffer.IsModified then
  127. (BorlandIDEServices as IOTAActionServices).SaveFile(fileName);
  128. cmdLine:=cmdLine+'"'+fileName+'"';
  129. currentDirBackup:=GetCurrentDir;
  130. SetCurrentDir(ExtractFilePath(fileName));
  131. WinExec(PAnsiChar(AnsiString(cmdLine)), SW_HIDE);
  132. SetCurrentDir(currentDirBackup);
  133. logFileName:=ExtractFilePath(fileName)+logFileName;
  134. if FileExists(logFileName) then begin
  135. log:=TStringList.Create;
  136. try
  137. msgGroup:=msgServices.GetGroup('GLSL');
  138. if msgGroup=nil then
  139. msgGroup:=msgServices.AddMessageGroup('GLSL')
  140. else msgServices.ClearToolMessages(msgGroup);
  141. log.LoadFromFile(logFileName);
  142. if log.Count=0 then
  143. msgServices.AddToolMessage(fileName, 'Validation failed for some undetermined reason...',
  144. 'GLSL', 0, 0, nil, lineRef, msgGroup)
  145. else if CompareText(log[0], 'Success.')=0 then
  146. msgServices.AddToolMessage(fileName, 'Validation passed successfully!',
  147. 'GLSL', 0, 0, nil, lineRef, msgGroup)
  148. else begin
  149. // we got error dude
  150. for i:=1 to log.Count-1 do begin
  151. p:=Pos(':', log[i]);
  152. if p>0 then begin
  153. errPrefix:=Copy(log[i], 1, p-1);
  154. errLine:=Copy(log[i], p+1, MaxInt);
  155. p:=Pos(':', errLine);
  156. colNb:=StrToIntDef(Copy(errLine, 1, p-1), 0);
  157. errLine:=Copy(errLine, p+1, MaxInt);
  158. p:=Pos(':', errLine);
  159. lineNb:=StrToIntDef(Copy(errLine, 1, p-1), 0);
  160. errLine:=Copy(errLine, p+1, MaxInt);
  161. msgServices.AddToolMessage(fileName, errLine, errPrefix, lineNb, colNb,
  162. nil, lineRef, msgGroup);
  163. end;
  164. end;
  165. end;
  166. msgServices.ShowMessageView(msgGroup);
  167. finally
  168. log.Free;
  169. end;
  170. DeleteFile(logFileName);
  171. end else ShowMessage('Couldn''t find validation log file!');
  172. end;
  173. end;
  174. end.