fCanvasC.cpp 5.6 KB

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