fTexFormatD.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. unit fTexFormatD;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. Vcl.Graphics,
  8. Vcl.Controls,
  9. Vcl.Forms,
  10. Vcl.Dialogs,
  11. Vcl.StdCtrls,
  12. Vcl.ExtCtrls,
  13. Vcl.Imaging.Jpeg,
  14. GLS.Scene,
  15. GLScene.VectorTypes,
  16. GLS.Objects,
  17. GLS.Texture,
  18. GLS.HUDObjects,
  19. GLS.Cadencer,
  20. GLS.SceneViewer,
  21. GLS.Coordinates,
  22. GLS.BaseClasses;
  23. type
  24. TFormTexFormat = class(TForm)
  25. GLSceneViewer1: TGLSceneViewer;
  26. GLScene1: TGLScene;
  27. GLCamera1: TGLCamera;
  28. Panel1: TPanel;
  29. CBFormat: TComboBox;
  30. Label2: TLabel;
  31. Label3: TLabel;
  32. CBCompression: TComboBox;
  33. Label4: TLabel;
  34. CBImage: TComboBox;
  35. LAPicSize: TLabel;
  36. Label5: TLabel;
  37. RBDefault: TRadioButton;
  38. RBDouble: TRadioButton;
  39. HUDSprite1: TGLHUDSprite;
  40. LAUsedMemory: TLabel;
  41. RBQuad: TRadioButton;
  42. LARGB32: TLabel;
  43. LACompression: TLabel;
  44. procedure FormCreate(Sender: TObject);
  45. procedure CBImageChange(Sender: TObject);
  46. procedure FormResize(Sender: TObject);
  47. procedure GLSceneViewer1AfterRender(Sender: TObject);
  48. private
  49. PathToData: TFileName;
  50. public
  51. newSelection: Boolean;
  52. end;
  53. var
  54. FormTexFormat: TFormTexFormat;
  55. implementation
  56. {$R *.DFM}
  57. uses
  58. GLS.TextureFormat, GLScene.Utils;
  59. procedure TFormTexFormat.FormCreate(Sender: TObject);
  60. var
  61. sr: TSearchRec;
  62. i: Integer;
  63. begin
  64. PathToData := GetCurrentAssetPath();
  65. SetCurrentDir(PathToData + '\texture');
  66. // collect JPeg textures from the asset directory
  67. i := FindFirst('*.jpg', faAnyFile, sr);
  68. while i = 0 do
  69. begin
  70. CBImage.Items.Add(sr.Name);
  71. i := FindNext(sr);
  72. end;
  73. FindClose(sr);
  74. // default selection
  75. CBFormat.ItemIndex := 0;
  76. CBCompression.ItemIndex := 0;
  77. CBImage.ItemIndex := 0;
  78. CBImageChange(Self);
  79. end;
  80. procedure TFormTexFormat.CBImageChange(Sender: TObject);
  81. begin
  82. // adjust settings from selection and reload the texture map
  83. with HUDSprite1.Material.Texture do
  84. begin
  85. TextureFormat := TGLTextureFormat(Integer(tfRGB) + CBFormat.ItemIndex);
  86. Compression := TGLTextureCompression(Integer(tcNone) +
  87. CBCompression.ItemIndex);
  88. Image.LoadFromFile(CBImage.Text);
  89. LAPicSize.Caption := IntToStr(Image.Width) + ' x ' + IntToStr(Image.Height);
  90. if RBDefault.Checked then
  91. begin
  92. HUDSprite1.Width := Image.Width;
  93. HUDSprite1.Height := Image.Height;
  94. end
  95. else if RBDouble.Checked then
  96. begin
  97. HUDSprite1.Width := Image.Width * 2;
  98. HUDSprite1.Height := Image.Height * 2;
  99. end
  100. else
  101. begin
  102. HUDSprite1.Width := Image.Width * 4;
  103. HUDSprite1.Height := Image.Height * 4;
  104. end;
  105. end;
  106. FormResize(Self);
  107. newSelection := True;
  108. end;
  109. procedure TFormTexFormat.FormResize(Sender: TObject);
  110. begin
  111. // re-center the HUDSprite
  112. HUDSprite1.Position.X := GLSceneViewer1.Width / 2;
  113. HUDSprite1.Position.Y := GLSceneViewer1.Height / 2;
  114. GLSceneViewer1.Invalidate;
  115. end;
  116. procedure TFormTexFormat.GLSceneViewer1AfterRender(Sender: TObject);
  117. var
  118. rgb: Integer;
  119. begin
  120. // update compression stats, only the 1st time after a new selection
  121. if newSelection then
  122. with HUDSprite1.Material.Texture do
  123. begin
  124. rgb := Image.Width * Image.Height * 4;
  125. LARGB32.Caption := Format('RGBA 32bits would require %d kB',
  126. [rgb div 1024]);
  127. LAUsedMemory.Caption := Format('Required memory : %d kB',
  128. [TextureImageRequiredMemory div 1024]);
  129. LACompression.Caption := Format('Compression ratio : %d %%',
  130. [100 - 100 * TextureImageRequiredMemory div rgb]);
  131. newSelection := False;
  132. end;
  133. end;
  134. end.