FmInfo.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. //
  2. // The graphics GaLaXy Engine. The unit of GLScene
  3. //
  4. unit FmInfo;
  5. (* Informations on OpenGL driver and contributions *)
  6. interface
  7. {$I Stage.Defines.inc}
  8. uses
  9. Winapi.OpenGL,
  10. Winapi.Windows,
  11. System.SysUtils,
  12. System.Classes,
  13. Vcl.Forms,
  14. Vcl.Controls,
  15. Vcl.Buttons,
  16. Vcl.StdCtrls,
  17. Vcl.ComCtrls,
  18. Vcl.ExtCtrls,
  19. Vcl.Graphics,
  20. Vcl.Menus,
  21. Vcl.Imaging.jpeg,
  22. Stage.OpenGLTokens,
  23. GLS.OpenGLAdapter,
  24. GLS.Scene,
  25. GLS.SceneViewer,
  26. GLS.Context,
  27. Stage.Utils;
  28. type
  29. TGLInfoForm = class(TForm)
  30. AccLabel: TLabel;
  31. AccumLabel: TLabel;
  32. AuxLabel: TLabel;
  33. ClipLabel: TLabel;
  34. ColorLabel: TLabel;
  35. CopyLabel: TLabel;
  36. DepthLabel: TLabel;
  37. DoubleLabel: TLabel;
  38. EvalLabel: TLabel;
  39. Image: TImage;
  40. Label1: TLabel;
  41. Label10: TLabel;
  42. Label11: TLabel;
  43. Label12: TLabel;
  44. Label13: TLabel;
  45. Label14: TLabel;
  46. Label15: TLabel;
  47. Label16: TLabel;
  48. Label17: TLabel;
  49. Label18: TLabel;
  50. Label2: TLabel;
  51. Label20: TLabel;
  52. Label23: TLabel;
  53. Label25: TLabel;
  54. Label26: TLabel;
  55. Label27: TLabel;
  56. Label28: TLabel;
  57. Label29: TLabel;
  58. Label3: TLabel;
  59. Label30: TLabel;
  60. LabelCommon: TLabel;
  61. LabelDepths: TLabel;
  62. LabelMaxValues: TLabel;
  63. Label34: TLabel;
  64. Label35: TLabel;
  65. Label37: TLabel;
  66. Label4: TLabel;
  67. Label5: TLabel;
  68. Label6: TLabel;
  69. Label7: TLabel;
  70. Label8: TLabel;
  71. Label9: TLabel;
  72. LightLabel: TLabel;
  73. ListLabel: TLabel;
  74. MemoAbout: TMemo;
  75. MemoContributors: TMemo;
  76. ModelLabel: TLabel;
  77. NameLabel: TLabel;
  78. OverlayLabel: TLabel;
  79. PageControl: TPageControl;
  80. PixelLabel: TLabel;
  81. ProjLabel: TLabel;
  82. RendererLabel: TLabel;
  83. ScrollBoxInfo: TScrollBox;
  84. TabSheetInformation: TTabSheet;
  85. StencilLabel: TLabel;
  86. StereoLabel: TLabel;
  87. SubLabel: TLabel;
  88. TabSheetAbout: TTabSheet;
  89. TabSheetContributors: TTabSheet;
  90. TexSizeLabel: TLabel;
  91. TexStackLabel: TLabel;
  92. TexUnitsLabel: TLabel;
  93. UnderlayLabel: TLabel;
  94. VendorLabel: TLabel;
  95. VersionLabel: TLabel;
  96. TabSheetExtensions: TTabSheet;
  97. ListBoxExtensions: TListBox;
  98. PMWebLink: TPopupMenu;
  99. MIRegistryLink: TMenuItem;
  100. MIDelphi3D: TMenuItem;
  101. TabSheetGLScene: TTabSheet;
  102. CloseButton: TButton;
  103. VersionLbl: TLabel;
  104. ViewLabel: TLabel;
  105. lblSfGLScene: TLabel;
  106. lblGithubGLScene: TLabel;
  107. procedure CloseButtonClick(Sender: TObject);
  108. procedure FormCreate(Sender: TObject);
  109. procedure FormKeyPress(Sender: TObject; var Key: Char);
  110. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  111. procedure ListBoxExtensionsDblClick(Sender: TObject);
  112. procedure ListBoxExtensionsClick(Sender: TObject);
  113. procedure ListBoxExtensionsKeyPress(Sender: TObject; var Key: Char);
  114. procedure FormShow(Sender: TObject);
  115. procedure MIDelphi3DClick(Sender: TObject);
  116. procedure lblSfGLSceneClick(Sender: TObject);
  117. procedure lblGithubGLSceneClick(Sender: TObject);
  118. protected
  119. function GetSceneVersion: string;
  120. public
  121. procedure GetInfoFrom(aSceneBuffer: TGLSceneBuffer);
  122. end;
  123. //======================================================================
  124. implementation
  125. //======================================================================
  126. {$R *.dfm}
  127. procedure ShowInfoForm(aSceneBuffer: TGLSceneBuffer; Modal: boolean);
  128. var
  129. GLInfoForm: TGLInfoForm;
  130. begin
  131. GLInfoForm := TGLInfoForm.Create(nil);
  132. try
  133. GLInfoForm.GetInfoFrom(aSceneBuffer);
  134. with GLInfoForm do
  135. if Modal then
  136. ShowModal
  137. else
  138. Show;
  139. except
  140. GLInfoForm.Free;
  141. raise;
  142. end;
  143. end;
  144. // -------------------------------------------------------------------
  145. procedure TGLInfoForm.FormCreate(Sender: TObject);
  146. begin
  147. PageControl.ActivePageIndex := 0;
  148. end;
  149. procedure TGLInfoForm.FormShow(Sender: TObject);
  150. begin
  151. PageControl.ActivePageIndex := 0;
  152. end;
  153. // -------------------------------------------------------------------
  154. procedure TGLInfoForm.GetInfoFrom(aSceneBuffer: TGLSceneBuffer);
  155. const
  156. DRIVER_MASK = PFD_GENERIC_FORMAT or PFD_GENERIC_ACCELERATED;
  157. var
  158. pfd: TPixelformatDescriptor;
  159. pixelFormat: Integer;
  160. dc: HDC;
  161. i: Integer;
  162. ExtStr: String;
  163. procedure IntLimitToLabel(const aLabel: TLabel; const aLimit: TGLLimitType);
  164. begin
  165. aLabel.Caption := IntToStr(aSceneBuffer.LimitOf[aLimit]);
  166. end;
  167. begin
  168. Caption := Caption + ' (current context in ' +
  169. (aSceneBuffer.Owner as TComponent).Name + ')';
  170. aSceneBuffer.RenderingContext.Activate;
  171. try
  172. with aSceneBuffer do
  173. begin
  174. // common properties
  175. VendorLabel.Caption := String(gl.GetString(GL_VENDOR));
  176. RendererLabel.Caption := String(gl.GetString(GL_RENDERER));
  177. dc := wglGetCurrentDC();
  178. pixelFormat := GetPixelFormat(dc);
  179. DescribePixelFormat(dc, pixelFormat, SizeOf(pfd), pfd);
  180. // figure out the driver type
  181. if (DRIVER_MASK and pfd.dwFlags) = 0 then
  182. AccLabel.Caption := 'Installable Client Driver'
  183. else if (DRIVER_MASK and pfd.dwFlags) = DRIVER_MASK then
  184. AccLabel.Caption := 'Mini-Client Driver'
  185. else if (DRIVER_MASK and pfd.dwFlags) = PFD_GENERIC_FORMAT then
  186. AccLabel.Caption := 'Generic Software Driver';
  187. VersionLabel.Caption := String(gl.GetString(GL_VERSION));
  188. ExtStr := String(gl.GetString(GL_EXTENSIONS));
  189. ListBoxExtensions.Clear;
  190. while Length(ExtStr) > 0 do
  191. begin
  192. i := Pos(' ', ExtStr);
  193. if i = 0 then
  194. i := 255;
  195. ListBoxExtensions.Items.Add(Copy(ExtStr, 1, i - 1));
  196. Delete(ExtStr, 1, i);
  197. end;
  198. if LimitOf[limDoubleBuffer] = GL_TRUE then
  199. DoubleLabel.Caption := 'yes'
  200. else
  201. DoubleLabel.Caption := 'no';
  202. if LimitOf[limStereo] = GL_TRUE then
  203. StereoLabel.Caption := 'yes'
  204. else
  205. StereoLabel.Caption := 'no';
  206. // Include WGL extensions
  207. if GL.W_ARB_extensions_string then
  208. begin
  209. ExtStr := String(gl.WGetExtensionsStringARB(dc));
  210. while Length(ExtStr) > 0 do
  211. begin
  212. i := Pos(' ', ExtStr);
  213. if i = 0 then
  214. i := 255;
  215. ListBoxExtensions.Items.Add(Copy(ExtStr, 1, i - 1));
  216. Delete(ExtStr, 1, i);
  217. end;
  218. end;
  219. // Some extra info about the double buffer mode
  220. if (pfd.dwFlags and PFD_DOUBLEBUFFER) = PFD_DOUBLEBUFFER then
  221. begin
  222. CopyLabel.Caption := '';
  223. if (pfd.dwFlags and PFD_SWAP_EXCHANGE) > 0 then
  224. CopyLabel.Caption := 'exchange';
  225. if (pfd.dwFlags and PFD_SWAP_COPY) > 0 then
  226. begin
  227. if Length(CopyLabel.Caption) > 0 then
  228. CopyLabel.Caption := CopyLabel.Caption + ', ';
  229. CopyLabel.Caption := CopyLabel.Caption + 'copy';
  230. end;
  231. if Length(CopyLabel.Caption) = 0 then
  232. CopyLabel.Caption := 'no info available';
  233. end
  234. else
  235. begin
  236. CopyLabel.Caption := 'n/a';
  237. end;
  238. // buffer and pixel depths
  239. ColorLabel.Caption :=
  240. Format('red: %d, green: %d, blue: %d, alpha: %d bits',
  241. [LimitOf[limRedBits], LimitOf[limGreenBits], LimitOf[limBlueBits],
  242. LimitOf[limAlphaBits]]);
  243. DepthLabel.Caption := Format('%d bits', [LimitOf[limDepthBits]]);
  244. StencilLabel.Caption := Format('%d bits', [LimitOf[limStencilBits]]);
  245. AccumLabel.Caption :=
  246. Format('red: %d, green: %d, blue: %d, alpha: %d bits',
  247. [LimitOf[limAccumRedBits], LimitOf[limAccumGreenBits],
  248. LimitOf[limAccumBlueBits], LimitOf[limAccumAlphaBits]]);
  249. IntLimitToLabel(AuxLabel, limAuxBuffers);
  250. IntLimitToLabel(SubLabel, limSubpixelBits);
  251. OverlayLabel.Caption := IntToStr(pfd.bReserved and 7);
  252. UnderlayLabel.Caption := IntToStr(pfd.bReserved shr 3);
  253. // Maximum values
  254. IntLimitToLabel(ClipLabel, limClipPlanes);
  255. IntLimitToLabel(EvalLabel, limEvalOrder);
  256. IntLimitToLabel(LightLabel, limLights);
  257. IntLimitToLabel(ListLabel, limListNesting);
  258. IntLimitToLabel(ModelLabel, limModelViewStack);
  259. IntLimitToLabel(ViewLabel, limViewportDims);
  260. IntLimitToLabel(NameLabel, limNameStack);
  261. IntLimitToLabel(PixelLabel, limPixelMapTable);
  262. IntLimitToLabel(ProjLabel, limProjectionStack);
  263. IntLimitToLabel(TexSizeLabel, limTextureSize);
  264. IntLimitToLabel(TexStackLabel, limTextureStack);
  265. IntLimitToLabel(TexUnitsLabel, limNbTextureUnits);
  266. end;
  267. VersionLbl.Caption := GetSceneVersion;
  268. finally
  269. aSceneBuffer.RenderingContext.Deactivate;
  270. end;
  271. end;
  272. // -------------------------------------------------------------------
  273. procedure TGLInfoForm.CloseButtonClick(Sender: TObject);
  274. begin
  275. Close;
  276. end;
  277. // -------------------------------------------------------------------
  278. procedure TGLInfoForm.FormKeyPress(Sender: TObject; var Key: Char);
  279. begin
  280. if Key = #27 then
  281. Close;
  282. end;
  283. // -------------------------------------------------------------------
  284. procedure TGLInfoForm.FormClose(Sender: TObject; var Action: TCloseAction);
  285. begin
  286. Release;
  287. end;
  288. // -------------------------------------------------------------------
  289. procedure TGLInfoForm.ListBoxExtensionsDblClick(Sender: TObject);
  290. var
  291. p: Integer;
  292. url, buf: String;
  293. begin
  294. with ListBoxExtensions do
  295. begin
  296. if ItemIndex < 0 then
  297. Exit;
  298. url := Items[ItemIndex];
  299. end;
  300. p := Pos('_', url);
  301. buf := Copy(url, 1, p - 1);
  302. url := Copy(url, p + 1, 255);
  303. if (buf <> 'GL') and (buf <> 'WGL') and (buf <> 'GLX') then
  304. Exit;
  305. p := Pos('_', url);
  306. buf := Copy(url, 1, p - 1);
  307. url := 'http://www.opengl.org/registry/specs/' + buf + '/' +
  308. Copy(url, p + 1, 255) + '.txt';
  309. ShowHTMLUrl(url);
  310. end;
  311. // -------------------------------------------------------------------
  312. procedure TGLInfoForm.MIDelphi3DClick(Sender: TObject);
  313. var
  314. url: String;
  315. begin
  316. with ListBoxExtensions do
  317. begin
  318. if ItemIndex < 0 then
  319. Exit;
  320. url := 'http://www.delphi3d.net/hardware/extsupport.php?extension=' +
  321. Items[ItemIndex];
  322. end;
  323. ShowHTMLUrl(url);
  324. end;
  325. // -------------------------------------------------------------------
  326. procedure TGLInfoForm.ListBoxExtensionsClick(Sender: TObject);
  327. var
  328. extName: String;
  329. begin
  330. if ListBoxExtensions.ItemIndex < 0 then
  331. ListBoxExtensions.PopupMenu := nil
  332. else
  333. begin
  334. ListBoxExtensions.PopupMenu := PMWebLink;
  335. extName := ListBoxExtensions.Items[ListBoxExtensions.ItemIndex];
  336. MIRegistryLink.Caption := 'View OpenGL Extension Registry for ' + extName;
  337. MIDelphi3D.Caption := 'View Delphi3D Hardware Registry for ' + extName;
  338. end;
  339. end;
  340. procedure TGLInfoForm.ListBoxExtensionsKeyPress(Sender: TObject; var Key: Char);
  341. begin
  342. ListBoxExtensionsClick(Sender);
  343. end;
  344. // -------------------------------------------------------------------
  345. function TGLInfoForm.GetSceneVersion: string;
  346. var
  347. FExePath, FGLSceneRevision: string;
  348. begin
  349. FGLSceneRevision := Copy(GLSCENE_REVISION, 12, 4);
  350. FExePath := ExtractFilePath(ParamStr(0));
  351. if FileExists(FExePath + 'GLSceneRevision') then
  352. try
  353. with TStringList.Create do
  354. try
  355. LoadFromFile(FExePath + 'GLSceneRevision');
  356. if (Count >= 1) and (trim(Strings[0]) <> '') then
  357. FGLSceneRevision:= trim(Strings[0]);
  358. finally
  359. Free;
  360. end;
  361. except
  362. end;
  363. Result := Format(GLSCENE_VERSION, [FGLSceneRevision]);
  364. end;
  365. // ------------------------------------------------------------------------------
  366. procedure TGLInfoForm.lblSfGLSceneClick(Sender: TObject);
  367. begin
  368. ShowHTMLUrl(lblSfGLScene.Caption);
  369. end;
  370. procedure TGLInfoForm.lblGithubGLSceneClick(Sender: TObject);
  371. begin
  372. ShowHTMLUrl(lblGithubGLScene.Caption);
  373. end;
  374. // ------------------------------------------------------------------------------
  375. initialization
  376. // ------------------------------------------------------------------------------
  377. RegisterInfoForm(ShowInfoForm);
  378. end.