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