Unit1.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLBaseClasses"
  8. #pragma link "GLCadencer"
  9. #pragma link "GLCoordinates"
  10. #pragma link "GLCrossPlatform"
  11. #pragma link "GLMaterial"
  12. #pragma link "GLObjects"
  13. #pragma link "GLScene"
  14. #pragma link "GLWin32Viewer"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::FormCreate(TObject *Sender)
  24. {
  25. GLSceneViewer1->Align = alClient;
  26. frame =0;
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
  30. {
  31. TGLTexture *tex;
  32. TGLDynamicTextureImage *img;
  33. tex = GLMaterialLibrary1->TextureByName("Anim");
  34. if (!(dynamic_cast<TGLDynamicTextureImage *>(tex->Image)))
  35. exit;
  36. img = (TGLDynamicTextureImage *) tex->Image;
  37. switch (Key)
  38. {
  39. case VK_F2:
  40. {
  41. img->UsePBO = false;
  42. GLSceneViewer1->ResetPerformanceMonitor();
  43. frame = 0;
  44. break;
  45. }
  46. case VK_F3:
  47. {
  48. img->UsePBO = true;
  49. GLSceneViewer1->ResetPerformanceMonitor();
  50. frame = 0;
  51. break;
  52. }
  53. case VK_F4: partial = !partial; break;
  54. default:
  55. ;
  56. }
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::FormResize(TObject *Sender)
  60. {
  61. GLCamera1->SceneScale = GLSceneViewer1->ClientWidth / 400;
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  65. const double newTime)
  66. {
  67. GLSceneViewer1->Invalidate();
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::GLDirectOpenGL1Render(TObject *Sender, TGLRenderContextInfo &rci)
  71. {
  72. TGLTexture *tex;
  73. TGLDynamicTextureImage *img;
  74. // void* p;
  75. TRGBQuad* p;
  76. int X, Y;
  77. tex = GLMaterialLibrary1->TextureByName("Anim");
  78. if (tex->Disabled)
  79. {
  80. tex->ImageClassName = __classid(TGLDynamicTextureImage)->ClassName();
  81. img = (TGLDynamicTextureImage *) tex->Image;
  82. img->Width = 256;
  83. img->Height = 256;
  84. tex->TextureFormat = tfRGBA;
  85. tex->TextureMode = tmReplace;
  86. tex->Disabled = false;
  87. }
  88. img = (TGLDynamicTextureImage *)tex->Image;
  89. img->BeginUpdate();
  90. // draw some silly stuff
  91. //
  92. p = new TRGBQuad();
  93. p = (TRGBQuad*)img->Data;
  94. frame++;
  95. // first frame must always be drawn completely
  96. if (partial && (frame > 1))
  97. {
  98. // do partial update, set the dirty rectangle
  99. // note that we do NOT offset the p pointer,
  100. // since it is relative to the dirty rectangle,
  101. // not the complete texture
  102. // also note that the right/bottom edge is not included
  103. // in the upload
  104. img->DirtyRectangle = Rect(
  105. img->Width / 4,
  106. img->Height / 4,
  107. img->Width * 3 / 4,
  108. img->Height * 3 / 4);
  109. }
  110. for (Y = img->DirtyRectangle.Top; Y < img->DirtyRectangle.Bottom - 1; Y++)
  111. {
  112. for (X = img->DirtyRectangle.Left; X < img->DirtyRectangle.Right - 1; X++)
  113. {
  114. p->rgbRed = ((X ^ Y) + frame) && 255;
  115. p->rgbGreen = ((X + frame) ^ Y) && 255;
  116. p->rgbBlue = ((X - frame) ^ (Y + frame)) && 255;
  117. p++;
  118. }
  119. }
  120. img->EndUpdate();
  121. }
  122. //---------------------------------------------------------------------------
  123. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  124. {
  125. const
  126. // PBOText: array[Boolean] of string = ("PBO disabled", "PBO enabled");
  127. /// String PBOText[]: array[Boolean] of string = ("PBO disabled", "PBO enabled");
  128. TGLTexture *tex;
  129. TGLDynamicTextureImage *img;
  130. String s;
  131. tex = GLMaterialLibrary1->TextureByName("Anim");
  132. if ((dynamic_cast<TGLDynamicTextureImage *>(tex->Image)))
  133. {
  134. img = (TGLDynamicTextureImage *) tex->Image;
  135. s = "PBO";///PBOText[img->UsePBO];
  136. s = "Dynamic Text";
  137. }
  138. Caption = Format("%s - %s", ARRAYOFCONST ((GLSceneViewer1->FramesPerSecondText(), s)));
  139. GLSceneViewer1->ResetPerformanceMonitor();
  140. }
  141. //---------------------------------------------------------------------------