gameglwidget.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "gameglwidget.h"
  2. #ifdef Q_OS_SYMBIAN
  3. // memory profile helper
  4. #include "memprofile.h"
  5. #include <EGL/egl.h>
  6. #endif
  7. #ifdef USE_GOOM_MONITOR
  8. // engine requests 10 MB of graphics memory from goom
  9. const int KRequestGraphicsMemoryAmount = 10*1024*1024;
  10. #endif
  11. static void Profiling()
  12. {
  13. #if defined(Q_OS_SYMBIAN) && !defined(NDEBUG)
  14. static int iFrameCount = 0;
  15. iFrameCount++;
  16. static int lastUsedPrivate = 0;
  17. EGLDisplay aDisp = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  18. int aTotalGRAM = 0;
  19. int aUsedGRAM = 0;
  20. int aUsedPrivate = 0;
  21. int aUsedShared = 0;
  22. int free = 0;
  23. GetProfilingExtensionData(aDisp, aTotalGRAM, aUsedGRAM, aUsedPrivate,
  24. aUsedShared);
  25. free = aTotalGRAM - aUsedGRAM;
  26. if (lastUsedPrivate != aUsedPrivate)
  27. {
  28. qDebug("Frame %d", iFrameCount);
  29. qDebug(
  30. "MEMORY_STATS_TOTAL: %d USED: %d USEDPRIVATE: %d USEDSHARED: %d FREE: %d DELTA:%d\n",
  31. aTotalGRAM, aUsedGRAM, aUsedPrivate, aUsedShared, free,
  32. lastUsedPrivate - aUsedPrivate);
  33. }
  34. lastUsedPrivate = aUsedPrivate;
  35. #endif
  36. }
  37. GameGLWidget::GameGLWidget(GF::GameApp *game0, QWidget *parent) :
  38. QGLWidget(QGLFormat(QGL::NoDepthBuffer), parent), game(game0),
  39. gamePrepared(false)
  40. {
  41. qDebug("GameGLWidget game=%x", game0);
  42. Profiling();
  43. }
  44. GameGLWidget::~GameGLWidget()
  45. {
  46. qDebug("~GameGLWidget");
  47. uninitializeGL();
  48. Profiling();
  49. }
  50. void GameGLWidget::uninitializeGL()
  51. {
  52. qDebug("uninitializeGL");
  53. if(gamePrepared && game)
  54. {
  55. game->release();
  56. gamePrepared=false;
  57. }
  58. #ifdef USE_GOOM_MONITOR
  59. iGoom.Close();
  60. #endif
  61. doneCurrent();
  62. }
  63. void GameGLWidget::initializeGL()
  64. {
  65. qDebug("initializeGL");
  66. Profiling();
  67. #ifdef USE_GOOM_MONITOR
  68. int err=iGoom.Connect();
  69. qDebug("GOOM ret = %d", err);
  70. if(err==KErrNone)
  71. {
  72. for(int i=0;i<10;i++)
  73. {
  74. int err = iGoom.RequestFreeMemory(KRequestGraphicsMemoryAmount);
  75. qDebug("GOOM RequestFreeMemory ret = %d", err);
  76. if(err==KErrNone)
  77. break;
  78. else
  79. User::After(200000);
  80. }
  81. }
  82. #endif
  83. Profiling();
  84. if(game)
  85. {
  86. game->prepare();
  87. gamePrepared=true;
  88. }
  89. #ifdef USE_GOOM_MONITOR
  90. // iGoom.MemoryAllocationsComplete();
  91. #endif
  92. qDebug("initializeGL done");
  93. Profiling();
  94. }
  95. void GameGLWidget::resizeGL(int w, int h)
  96. {
  97. qDebug("ResizeGL: %dx%d", w, h) ;
  98. glViewport(0,0, w,h );
  99. if(game) game->resize(w, h);
  100. qDebug("ResizeGL done") ;
  101. Profiling();
  102. }
  103. void GameGLWidget::paintGL()
  104. {
  105. // qDebug("paintGL") ;
  106. Profiling();
  107. glClearColor(0,0,0,0);
  108. glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  109. if(game) game->render();
  110. }