fDynTextureC.cpp 4.2 KB

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