FInfo.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. //
  2. // This unit is part of the GLScene Engine, http://glscene.org
  3. //
  4. unit FInfo;
  5. (* Informations on OpenGL driver and contributions *)
  6. interface
  7. {$I GLScene.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. OpenGLTokens,
  23. OpenGLAdapter,
  24. GLScene,
  25. GLSceneViewer,
  26. GLContext,
  27. GLCrossPlatform;
  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. WebsiteLbl: TLabel;
  106. procedure CloseButtonClick(Sender: TObject);
  107. procedure FormCreate(Sender: TObject);
  108. procedure FormKeyPress(Sender: TObject; var Key: Char);
  109. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  110. procedure ListBoxExtensionsDblClick(Sender: TObject);
  111. procedure ListBoxExtensionsClick(Sender: TObject);
  112. procedure ListBoxExtensionsKeyPress(Sender: TObject; var Key: Char);
  113. procedure FormShow(Sender: TObject);
  114. procedure MIDelphi3DClick(Sender: TObject);
  115. procedure WebsiteLblClick(Sender: TObject);
  116. protected
  117. procedure LoadContributors;
  118. function GetSceneVersion: string;
  119. public
  120. procedure GetInfoFrom(aSceneBuffer: TGLSceneBuffer);
  121. end;
  122. //======================================================================
  123. implementation
  124. //======================================================================
  125. {$R *.dfm}
  126. procedure ShowInfoForm(aSceneBuffer: TGLSceneBuffer; Modal: boolean);
  127. var
  128. GLInfoForm: TGLInfoForm;
  129. begin
  130. GLInfoForm := TGLInfoForm.Create(nil);
  131. try
  132. GLInfoForm.GetInfoFrom(aSceneBuffer);
  133. with GLInfoForm do
  134. if Modal then
  135. ShowModal
  136. else
  137. Show;
  138. except
  139. GLInfoForm.Free;
  140. raise;
  141. end;
  142. end;
  143. // -------------------------------------------------------------------
  144. procedure TGLInfoForm.FormCreate(Sender: TObject);
  145. begin
  146. PageControl.ActivePageIndex := 0;
  147. end;
  148. procedure TGLInfoForm.FormShow(Sender: TObject);
  149. begin
  150. PageControl.ActivePageIndex := 0;
  151. end;
  152. // -------------------------------------------------------------------
  153. procedure TGLInfoForm.GetInfoFrom(aSceneBuffer: TGLSceneBuffer);
  154. const
  155. DRIVER_MASK = PFD_GENERIC_FORMAT or PFD_GENERIC_ACCELERATED;
  156. var
  157. pfd: TPixelformatDescriptor;
  158. pixelFormat: Integer;
  159. dc: HDC;
  160. i: Integer;
  161. ExtStr: String;
  162. procedure IntLimitToLabel(const aLabel: TLabel; const aLimit: TGLLimitType);
  163. begin
  164. aLabel.Caption := IntToStr(aSceneBuffer.LimitOf[aLimit]);
  165. end;
  166. begin
  167. Caption := Caption + ' (current context in ' +
  168. (aSceneBuffer.Owner as TComponent).Name + ')';
  169. aSceneBuffer.RenderingContext.Activate;
  170. try
  171. with aSceneBuffer do
  172. begin
  173. // common properties
  174. VendorLabel.Caption := String(gl.GetString(GL_VENDOR));
  175. RendererLabel.Caption := String(gl.GetString(GL_RENDERER));
  176. dc := wglGetCurrentDC();
  177. pixelFormat := GetPixelFormat(dc);
  178. DescribePixelFormat(dc, pixelFormat, SizeOf(pfd), pfd);
  179. // figure out the driver type
  180. if (DRIVER_MASK and pfd.dwFlags) = 0 then
  181. AccLabel.Caption := 'Installable Client Driver'
  182. else if (DRIVER_MASK and pfd.dwFlags) = DRIVER_MASK then
  183. AccLabel.Caption := 'Mini-Client Driver'
  184. else if (DRIVER_MASK and pfd.dwFlags) = PFD_GENERIC_FORMAT then
  185. AccLabel.Caption := 'Generic Software Driver';
  186. VersionLabel.Caption := String(gl.GetString(GL_VERSION));
  187. ExtStr := String(gl.GetString(GL_EXTENSIONS));
  188. ListBoxExtensions.Clear;
  189. while Length(ExtStr) > 0 do
  190. begin
  191. i := Pos(' ', ExtStr);
  192. if i = 0 then
  193. i := 255;
  194. ListBoxExtensions.Items.Add(Copy(ExtStr, 1, i - 1));
  195. Delete(ExtStr, 1, i);
  196. end;
  197. if LimitOf[limDoubleBuffer] = GL_TRUE then
  198. DoubleLabel.Caption := 'yes'
  199. else
  200. DoubleLabel.Caption := 'no';
  201. if LimitOf[limStereo] = GL_TRUE then
  202. StereoLabel.Caption := 'yes'
  203. else
  204. StereoLabel.Caption := 'no';
  205. // Include WGL extensions
  206. if GL.W_ARB_extensions_string then
  207. begin
  208. ExtStr := String(gl.WGetExtensionsStringARB(dc));
  209. while Length(ExtStr) > 0 do
  210. begin
  211. i := Pos(' ', ExtStr);
  212. if i = 0 then
  213. i := 255;
  214. ListBoxExtensions.Items.Add(Copy(ExtStr, 1, i - 1));
  215. Delete(ExtStr, 1, i);
  216. end;
  217. end;
  218. // Some extra info about the double buffer mode
  219. if (pfd.dwFlags and PFD_DOUBLEBUFFER) = PFD_DOUBLEBUFFER then
  220. begin
  221. CopyLabel.Caption := '';
  222. if (pfd.dwFlags and PFD_SWAP_EXCHANGE) > 0 then
  223. CopyLabel.Caption := 'exchange';
  224. if (pfd.dwFlags and PFD_SWAP_COPY) > 0 then
  225. begin
  226. if Length(CopyLabel.Caption) > 0 then
  227. CopyLabel.Caption := CopyLabel.Caption + ', ';
  228. CopyLabel.Caption := CopyLabel.Caption + 'copy';
  229. end;
  230. if Length(CopyLabel.Caption) = 0 then
  231. CopyLabel.Caption := 'no info available';
  232. end
  233. else
  234. begin
  235. CopyLabel.Caption := 'n/a';
  236. end;
  237. // buffer and pixel depths
  238. ColorLabel.Caption :=
  239. Format('red: %d, green: %d, blue: %d, alpha: %d bits',
  240. [LimitOf[limRedBits], LimitOf[limGreenBits], LimitOf[limBlueBits],
  241. LimitOf[limAlphaBits]]);
  242. DepthLabel.Caption := Format('%d bits', [LimitOf[limDepthBits]]);
  243. StencilLabel.Caption := Format('%d bits', [LimitOf[limStencilBits]]);
  244. AccumLabel.Caption :=
  245. Format('red: %d, green: %d, blue: %d, alpha: %d bits',
  246. [LimitOf[limAccumRedBits], LimitOf[limAccumGreenBits],
  247. LimitOf[limAccumBlueBits], LimitOf[limAccumAlphaBits]]);
  248. IntLimitToLabel(AuxLabel, limAuxBuffers);
  249. IntLimitToLabel(SubLabel, limSubpixelBits);
  250. OverlayLabel.Caption := IntToStr(pfd.bReserved and 7);
  251. UnderlayLabel.Caption := IntToStr(pfd.bReserved shr 3);
  252. // Maximum values
  253. IntLimitToLabel(ClipLabel, limClipPlanes);
  254. IntLimitToLabel(EvalLabel, limEvalOrder);
  255. IntLimitToLabel(LightLabel, limLights);
  256. IntLimitToLabel(ListLabel, limListNesting);
  257. IntLimitToLabel(ModelLabel, limModelViewStack);
  258. IntLimitToLabel(ViewLabel, limViewportDims);
  259. IntLimitToLabel(NameLabel, limNameStack);
  260. IntLimitToLabel(PixelLabel, limPixelMapTable);
  261. IntLimitToLabel(ProjLabel, limProjectionStack);
  262. IntLimitToLabel(TexSizeLabel, limTextureSize);
  263. IntLimitToLabel(TexStackLabel, limTextureStack);
  264. IntLimitToLabel(TexUnitsLabel, limNbTextureUnits);
  265. end;
  266. VersionLbl.Caption := GetSceneVersion;
  267. finally
  268. aSceneBuffer.RenderingContext.Deactivate;
  269. end;
  270. end;
  271. // -------------------------------------------------------------------
  272. procedure TGLInfoForm.CloseButtonClick(Sender: TObject);
  273. begin
  274. Close;
  275. end;
  276. // -------------------------------------------------------------------
  277. procedure TGLInfoForm.FormKeyPress(Sender: TObject; var Key: Char);
  278. begin
  279. if Key = #27 then
  280. Close;
  281. end;
  282. // -------------------------------------------------------------------
  283. procedure TGLInfoForm.FormClose(Sender: TObject; var Action: TCloseAction);
  284. begin
  285. Release;
  286. end;
  287. // -------------------------------------------------------------------
  288. procedure TGLInfoForm.ListBoxExtensionsDblClick(Sender: TObject);
  289. var
  290. p: Integer;
  291. url, buf: String;
  292. begin
  293. with ListBoxExtensions do
  294. begin
  295. if ItemIndex < 0 then
  296. Exit;
  297. url := Items[ItemIndex];
  298. end;
  299. p := Pos('_', url);
  300. buf := Copy(url, 1, p - 1);
  301. url := Copy(url, p + 1, 255);
  302. if (buf <> 'GL') and (buf <> 'WGL') and (buf <> 'GLX') then
  303. Exit;
  304. p := Pos('_', url);
  305. buf := Copy(url, 1, p - 1);
  306. url := 'http://www.opengl.org/registry/specs/' + buf + '/' +
  307. Copy(url, p + 1, 255) + '.txt';
  308. ShowHTMLUrl(url);
  309. end;
  310. // -------------------------------------------------------------------
  311. procedure TGLInfoForm.MIDelphi3DClick(Sender: TObject);
  312. var
  313. url: String;
  314. begin
  315. with ListBoxExtensions do
  316. begin
  317. if ItemIndex < 0 then
  318. Exit;
  319. url := 'http://www.delphi3d.net/hardware/extsupport.php?extension=' +
  320. Items[ItemIndex];
  321. end;
  322. ShowHTMLUrl(url);
  323. end;
  324. // -------------------------------------------------------------------
  325. procedure TGLInfoForm.ListBoxExtensionsClick(Sender: TObject);
  326. var
  327. extName: String;
  328. begin
  329. if ListBoxExtensions.ItemIndex < 0 then
  330. ListBoxExtensions.PopupMenu := nil
  331. else
  332. begin
  333. ListBoxExtensions.PopupMenu := PMWebLink;
  334. extName := ListBoxExtensions.Items[ListBoxExtensions.ItemIndex];
  335. MIRegistryLink.Caption := 'View OpenGL Extension Registry for ' + extName;
  336. MIDelphi3D.Caption := 'View Delphi3D Hardware Registry for ' + extName;
  337. end;
  338. end;
  339. procedure TGLInfoForm.ListBoxExtensionsKeyPress(Sender: TObject; var Key: Char);
  340. begin
  341. ListBoxExtensionsClick(Sender);
  342. end;
  343. // -------------------------------------------------------------------
  344. procedure TGLInfoForm.LoadContributors;
  345. var
  346. ContributorsFileName: string;
  347. ContrPath: TFileName;
  348. begin
  349. (*
  350. ContrPath := ExtractFilePath(ParamStr(0));
  351. ContributorsFileName := ContrPath + '\Contributors.txt';
  352. if FileExists(ContributorsFileName)
  353. then
  354. MemoContributors.Lines.LoadFromFile(ContributorsFileName)
  355. else
  356. MemoContributors.Lines.Text := 'Cannot find contributors list.';
  357. MemoContributors.Lines.Add(ContributorsFileName);
  358. *)
  359. end;
  360. // -------------------------------------------------------------------
  361. function TGLInfoForm.GetSceneVersion: string;
  362. var
  363. FExePath, FGLSceneRevision: string;
  364. begin
  365. FGLSceneRevision := Copy(GLSCENE_REVISION, 12, 4);
  366. FExePath := ExtractFilePath(ParamStr(0));
  367. if FileExists(FExePath + 'GLSceneRevision') then
  368. try
  369. with TStringList.Create do
  370. try
  371. LoadFromFile(FExePath + 'GLSceneRevision');
  372. if (Count >= 1) and (trim(Strings[0]) <> '') then
  373. FGLSceneRevision:= trim(Strings[0]);
  374. finally
  375. Free;
  376. end;
  377. except
  378. end;
  379. Result := Format(GLSCENE_VERSION, [FGLSceneRevision]);
  380. end;
  381. // ------------------------------------------------------------------------------
  382. procedure TGLInfoForm.WebsiteLblClick(Sender: TObject);
  383. begin
  384. ShowHTMLUrl(WebsiteLbl.Caption);
  385. end;
  386. // ------------------------------------------------------------------------------
  387. initialization
  388. // ------------------------------------------------------------------------------
  389. RegisterInfoForm(ShowInfoForm);
  390. end.