fCanvasC.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. TFormCanvas *FormCanvas;
  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 TFormCanvas::TFormCanvas(TComponent* Owner)
  33. : TForm(Owner)
  34. {
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TFormCanvas::BULinesClick(TObject *Sender)
  38. {
  39. vWhat = wLines;
  40. Bench();
  41. }
  42. void __fastcall TFormCanvas::BUEllipsesClick(TObject *Sender)
  43. {
  44. vWhat = wEllipses;
  45. Bench();
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall TFormCanvas::BUArcClick(TObject *Sender)
  49. {
  50. vWhat = wArcs;
  51. Bench();
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TFormCanvas::BURectsClick(TObject *Sender)
  55. {
  56. vWhat = wRects;
  57. Bench();
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TFormCanvas::BUPointsClick(TObject *Sender)
  61. {
  62. vWhat = wPoints;
  63. Bench();
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TFormCanvas::BUTextOutClick(TObject *Sender)
  67. {
  68. vWhat = wTextOut;
  69. Bench();
  70. }
  71. //---------------------------------------------------------------------------
  72. void TFormCanvas::Bench()
  73. {
  74. __int64 t; // TVarRec 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", ARRAYOFCONST((StopPrecisionTimer(t)*1000)));
  83. Application->ProcessMessages();
  84. RandSeed = 0;
  85. t = StartPrecisionTimer();
  86. PaintTheBox();
  87. /// LAGDI->Caption = Format("GDI: %.1f msec", ARRAYOFCONST((StopPrecisionTimer(t)*1000)));
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TFormCanvas::GLDirectOpenGL1Render(TObject *Sender, TGLRenderContextInfo &rci)
  91. {
  92. int i, x, y;
  93. TGLCanvas *glc;
  94. TRect r;
  95. TColor Color;
  96. glc = new TGLCanvas(256, 256);
  97. glc->PenWidth = vPenWidth;
  98. switch (vWhat) {
  99. case wLines :
  100. for (i=1; i< cNbLines; i++) {
  101. glc->PenColor = clRed; // Random(256*256*256);
  102. glc->MoveTo(random(256), random(256));
  103. glc->LineTo(Random(256), Random(256));
  104. }
  105. case wEllipses :
  106. for (i =1; i<cNbEllipses; i++){
  107. glc->PenColor = clGreen; // Random(256*256*256);
  108. glc->EllipseBB(Random(256), Random(256),
  109. Random(256), Random(256));
  110. }
  111. case wRects :{
  112. for (i =1; i< cNbRects; i++) {
  113. glc->PenColor = clBlue; // Random(256*256*256);
  114. r = Rect(Random(256), Random(256),
  115. Random(256), Random(256));
  116. glc->FillRect((int)r.left, (int)r.top, (int)r.right, (int)r.bottom);
  117. }
  118. }
  119. case wPoints : for (i=1; i<cNbPoints; i++) {
  120. glc->PenColor = clGray; // Random(256*256*256);
  121. glc->PlotPixel(Random(256), Random(256));
  122. }
  123. case wTextOut : {
  124. for (i=1; i<cNbTextOuts; i++) {
  125. Color = clMaroon; // Random(256*256*256);
  126. x = Random(256);
  127. y = Random(256);
  128. // WindowsBitmapFont->TextOut(rci, x, y, "Hello", Color);
  129. }
  130. }
  131. case wArcs :
  132. for (i = 1; i< cNbEllipses; i++) {
  133. glc->PenColor = clCream; // Random(256*256*256);
  134. glc->Arc(
  135. Random(256), Random(256),
  136. Random(256), Random(256),
  137. Random(256), Random(256),
  138. Random(256), Random(256));
  139. }
  140. }
  141. delete glc;
  142. }
  143. //---------------------------------------------------------------------------
  144. void TFormCanvas::PaintTheBox()
  145. {
  146. int i, x, y;
  147. TRect r;
  148. Vcl::Graphics::TBitmap *b;
  149. //to be fair, use offscreen painting...
  150. b = new TBitmap;
  151. b->Width = 256;
  152. b->Height = 256;
  153. b->Canvas->Brush->Style = bsClear;
  154. b->Canvas->Pen->Width = vPenWidth;
  155. switch (vWhat) {
  156. case wLines : for (i=1; i< cNbLines; i++) {
  157. b->Canvas->Pen->Color = clRed; // Random(256*256*256);
  158. b->Canvas->MoveTo(Random(256), Random(256));
  159. b->Canvas->LineTo(Random(256), Random(256));
  160. }
  161. case wEllipses :
  162. for (i =1; i<cNbEllipses; i++){
  163. b->Canvas->Pen->Color = clGreen; // Random(256*256*256);
  164. b->Canvas->Ellipse(Random(256), Random(256),
  165. Random(256), Random(256));
  166. }
  167. case wRects : {
  168. b->Canvas->Brush->Style = bsSolid;
  169. for (i =1; i< cNbRects; i++) {
  170. b->Canvas->Brush->Color = clBlue; // Random(256*256*256);
  171. r = Rect(Random(256), Random(256),
  172. Random(256), Random(256));
  173. b->Canvas->FillRect(r);
  174. }
  175. }
  176. case wPoints : for (i=1; i<cNbPoints; i++)
  177. b->Canvas->Pixels[Random(256)][Random(256)] = clGray; // Random(256*256*256);
  178. case wTextOut : {
  179. Font = WindowsBitmapFont->Font;
  180. for (i=1; i<cNbTextOuts; i++) {
  181. Font->Color = clMaroon; // Random(256*256*256);
  182. x = Random(256);
  183. y = Random(256);
  184. b->Canvas->TextOutW(x, y, "Hello");
  185. }
  186. }
  187. case wArcs :
  188. for (i = 1; i< cNbEllipses; i++) {
  189. b->Canvas->Pen->Color = clCream; // Random(256*256*256);
  190. b->Canvas->Arc(
  191. Random(256), Random(256),
  192. Random(256), Random(256),
  193. Random(256), Random(256),
  194. Random(256), Random(256));
  195. }
  196. default: ;
  197. }
  198. b->Canvas->Draw(0, 0, b);
  199. delete b;
  200. }
  201. //---------------------------------------------------------------------------