Unit1.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLBaseClasses"
  9. #pragma link "GLBitmapFont"
  10. #pragma link "GLCoordinates"
  11. #pragma link "GLCrossPlatform"
  12. #pragma link "GLScene"
  13. #pragma link "GLWin32Viewer"
  14. #pragma link "GLWindowsFont"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. enum
  18. TWhat {wLines=0, wEllipses=1, wRects, wPoints, wTextOut, wArcs};
  19. TWhat vWhat;
  20. int vPenWidth;
  21. const int
  22. cNbLines = 20000;
  23. const int
  24. cNbEllipses = 20000;
  25. const int
  26. cNbRects = 5000;
  27. const int
  28. cNbPoints = 200000;
  29. const int
  30. cNbTextOuts = 20000;
  31. const int
  32. cNbArcs = 20000;
  33. //---------------------------------------------------------------------------
  34. __fastcall TForm1::TForm1(TComponent* Owner)
  35. : TForm(Owner)
  36. {
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TForm1::BULinesClick(TObject *Sender)
  40. {
  41. vWhat = wLines;
  42. Bench();
  43. }
  44. void __fastcall TForm1::BUEllipsesClick(TObject *Sender)
  45. {
  46. vWhat = wEllipses;
  47. Bench();
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::BUArcClick(TObject *Sender)
  51. {
  52. vWhat = wArcs;
  53. Bench();
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TForm1::BURectsClick(TObject *Sender)
  57. {
  58. vWhat = wRects;
  59. Bench();
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TForm1::BUPointsClick(TObject *Sender)
  63. {
  64. vWhat = wPoints;
  65. Bench();
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TForm1::BUTextOutClick(TObject *Sender)
  69. {
  70. vWhat = wTextOut;
  71. Bench();
  72. }
  73. //---------------------------------------------------------------------------
  74. void TForm1::Bench()
  75. {
  76. __int64 t;
  77. if (RBPenWidth1->Checked)
  78. vPenWidth =1;
  79. else vPenWidth =2;
  80. Application->ProcessMessages();
  81. RandSeed = 0;
  82. t = StartPrecisionTimer();
  83. GLSceneViewer->Refresh();
  84. LAGLCanvas->Caption = Format("GLCanvas: %.2f msec",
  85. ARRAYOFCONST((StopPrecisionTimer(t)*1000)));
  86. Application->ProcessMessages();
  87. RandSeed = 0;
  88. t = StartPrecisionTimer();
  89. PaintTheBox();
  90. LAGDI->Caption = Format("GDI: %.1f msec",
  91. ARRAYOFCONST((StopPrecisionTimer(t)*1000)));
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TForm1::GLDirectOpenGL1Render(TObject *Sender, TGLRenderContextInfo &rci)
  95. {
  96. int i, x, y;
  97. TGLCanvas *glc;
  98. TRect r;
  99. TColor Color;
  100. glc = new TGLCanvas(256, 256);
  101. glc->PenWidth = vPenWidth;
  102. switch (vWhat) {
  103. case wLines :
  104. for (i=1; i< cNbLines; i++) {
  105. glc->PenColor = Random(256*256*256);
  106. glc->MoveTo(Random(256), Random(256));
  107. glc->LineTo(Random(256), Random(256));
  108. }
  109. case wEllipses :
  110. for (i =1; i<cNbEllipses; i++){
  111. glc->PenColor = Random(256*256*256);
  112. glc->EllipseBB(Random(256), Random(256),
  113. Random(256), Random(256));
  114. }
  115. case wRects :{
  116. for (i =1; i< cNbRects; i++) {
  117. glc->PenColor = Random(256*256*256);
  118. r = Rect(Random(256), Random(256),
  119. Random(256), Random(256));
  120. glc->FillRect((int)r.left, (int)r.top, (int)r.right, (int)r.bottom);
  121. }
  122. }
  123. case wPoints : for (i=1; i<cNbPoints; i++) {
  124. glc->PenColor = Random(256*256*256);
  125. glc->PlotPixel(Random(256), Random(256));
  126. }
  127. case wTextOut : {
  128. for (i=1; i<cNbTextOuts; i++) {
  129. Color = Random(256*256*256);
  130. x = Random(256);
  131. y = Random(256);
  132. /// ? WindowsBitmapFont->TextOutW(rci, x, y, "Hello", Color);
  133. }
  134. }
  135. case wArcs :
  136. for (i = 1; i< cNbEllipses; i++) {
  137. glc->PenColor = Random(256*256*256);
  138. glc->Arc(
  139. Random(256), Random(256),
  140. Random(256), Random(256),
  141. Random(256), Random(256),
  142. Random(256), Random(256));
  143. }
  144. }
  145. delete glc;
  146. }
  147. //---------------------------------------------------------------------------
  148. void TForm1::PaintTheBox()
  149. {
  150. int i, x, y;
  151. TRect r;
  152. Graphics::TBitmap *b;
  153. //to be fair, use offscreen painting...
  154. b = new TBitmap;
  155. b->Width = 256;
  156. b->Height = 256;
  157. b->Canvas->Brush->Style = bsClear;
  158. b->Canvas->Pen->Width = vPenWidth;
  159. switch (vWhat) {
  160. case wLines : for (i=1; i< cNbLines; i++) {
  161. b->Canvas->Pen->Color = Random(256*256*256);
  162. b->Canvas->MoveTo(Random(256), Random(256));
  163. b->Canvas->LineTo(Random(256), Random(256));
  164. }
  165. case wEllipses :
  166. for (i =1; i<cNbEllipses; i++){
  167. b->Canvas->Pen->Color = Random(256*256*256);
  168. b->Canvas->Ellipse(Random(256), Random(256),
  169. Random(256), Random(256));
  170. }
  171. case wRects : {
  172. b->Canvas->Brush->Style = bsSolid;
  173. for (i =1; i< cNbRects; i++) {
  174. b->Canvas->Brush->Color = Random(256*256*256);
  175. r = Rect(Random(256), Random(256),
  176. Random(256), Random(256));
  177. b->Canvas->FillRect(r);
  178. }
  179. }
  180. case wPoints : for (i=1; i<cNbPoints; i++)
  181. b->Canvas->Pixels[Random(256)][Random(256)] =
  182. Random(256*256*256);
  183. case wTextOut : {
  184. Font = WindowsBitmapFont->Font;
  185. for (i=1; i<cNbTextOuts; i++) {
  186. Font->Color = Random(256*256*256);
  187. x = Random(256);
  188. y = Random(256);
  189. b->Canvas->TextOutW(x, y, "Hello");
  190. }
  191. }
  192. case wArcs :
  193. for (i = 1; i< cNbEllipses; i++) {
  194. b->Canvas->Pen->Color = Random(256*256*256);
  195. b->Canvas->Arc(
  196. Random(256), Random(256),
  197. Random(256), Random(256),
  198. Random(256), Random(256),
  199. Random(256), Random(256));
  200. }
  201. default: ;
  202. }
  203. b->Canvas->Draw(0, 0, b);
  204. delete b;
  205. }
  206. //---------------------------------------------------------------------------