[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/games/astrododge/src
From:       Rivo Laks <rivolaks () hot ! ee>
Date:       2009-07-19 11:43:14
Message-ID: 1248003794.213366.10484.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 999176 by rivol:

Add RenderInfo class which collects some simple statistics on the number of \
batches/faces/etc rendered. The info can be seen by pressing Ctrl+I.

 M  +1 -0      CMakeLists.txt  
 M  +2 -0      astrododgeui.rc  
 M  +19 -0     gameguiview.cpp  
 M  +5 -0      gameguiview.h  
 M  +8 -3      gameview.cpp  
 M  +11 -1     mainwindow.cpp  
 M  +3 -20     mainwindow.h  
 M  +2 -1      model.cpp  
 M  +1 -1      model.h  
 A             renderinfo.cpp   [License: GPL (v3+)]
 A             renderinfo.h   [License: GPL (v3+)]


--- trunk/playground/games/astrododge/src/CMakeLists.txt #999175:999176
@@ -15,6 +15,7 @@
         mainwindow.cpp
         model.cpp
         planet.cpp
+        renderinfo.cpp
         shadermanager.cpp
         ship.cpp
         )
--- trunk/playground/games/astrododge/src/astrododgeui.rc #999175:999176
@@ -11,6 +11,8 @@
             <Text>View</Text>
             <Action name="hdr_enable" />
             <Action name="hdr_config" />
+            <Separator />
+            <Action name="show_renderinfo" />
         </Menu>
     </MenuBar>
 </gui>
--- trunk/playground/games/astrododge/src/gameguiview.cpp #999175:999176
@@ -19,6 +19,7 @@
 
 #include "gameworld.h"
 #include "ship.h"
+#include "renderinfo.h"
 
 #include <kgllib/glwidget.h>
 #include <kgllib/textrenderer.h>
@@ -179,10 +180,16 @@
     mWorld = world;
     mThrustoMeter = 0;
     mSpeedoMeter = 0;
+    mShowRenderInfo = false;
 
     setViewType(View_GUI);
 }
 
+void GameGUIView::setShowRenderInfo(bool show)
+{
+    mShowRenderInfo = show;
+}
+
 void GameGUIView::init()
 {
     kDebug();
@@ -260,6 +267,18 @@
     textRenderer()->draw(dodgerect, QString("Dodges: \
%1").arg(mWorld->ship()->dodgesAvailable, 0, 'f', 1),  Qt::AlignRight | \
Qt::AlignBottom, timefont);  
+    if (mShowRenderInfo) {
+        QString statistics;
+        statistics += QString("Lights: %1  batches: %2  faces: %3\n")
+                .arg(renderInfo->lights()).arg(renderInfo->batches()).arg(renderInfo->faces());
 +        statistics += QString("State changes:\n");
+        statistics += QString("buf: %1  mat: %2  tex: %3\n")
+                .arg(renderInfo->bufferChanges()).arg(renderInfo->materialChanges()).arg(renderInfo->textureChanges());
 +        glColor3f(0.8, 0.8, 0.8);
+        QRect statsRect(10, 30, 300, 100);
+        textRenderer()->draw(statsRect, statistics, Qt::AlignTop | Qt::AlignLeft, \
QFont("Arial", 10)); +    }
+
     textRenderer()->end();
 }
 
--- trunk/playground/games/astrododge/src/gameguiview.h #999175:999176
@@ -34,11 +34,16 @@
         virtual void resize(int w, int h);
         virtual void render();
 
+    public slots:
+        void setShowRenderInfo(bool show);
+
     private:
         GameWorld* mWorld;
 
         GLMeter* mThrustoMeter;
         GLMeter* mSpeedoMeter;
+
+        bool mShowRenderInfo;
 };
 
 #endif // GAMEGUIVIEW_H
--- trunk/playground/games/astrododge/src/gameview.cpp #999175:999176
@@ -24,6 +24,7 @@
 #include "bullet.h"
 #include "datastore.h"
 #include "shadermanager.h"
+#include "renderinfo.h"
 
 #include <kgllib/camera.h>
 #include <kgllib/widgetproxy.h>
@@ -91,8 +92,7 @@
     float elapsed = qMin(0.1f, fpsCounter()->timeElapsed());
     mWorld->advance(elapsed);
 
-    // Clear buffers
-    glClear(GL_DEPTH_BUFFER_BIT);
+    renderInfo->startNextFrame();
 
     // Set up matrices
     glMatrixMode(GL_PROJECTION);
@@ -183,6 +183,7 @@
 
 void GameView::renderObjects(const QList<GameObject*>* objects)
 {
+    renderInfo->addLight();
     Vector3f cameraPos = mWorld->ship()->position();
 
     GeometryBuffer* buffer = 0;
@@ -207,12 +208,14 @@
             }
             model->buffer()->bind();
             buffer = model->buffer();
+            renderInfo->addBufferChange();
         }
         // Check material
         if (model->material() != material) {
             material = model->material();
             mShaderManager->setMaterial(material);
             mShaderManager->activateShader();
+            renderInfo->addMaterialChange();
         }
         // Check textures
         int newActiveTextures = qMin(maxTextures, model->textureCount());
@@ -235,6 +238,7 @@
             }
 
             texture[i] = newTex;
+            renderInfo->addTextureChange();
         }
         activeTextures = newActiveTextures;
 
@@ -246,7 +250,8 @@
         }
 
         // Render
-        model->render(obj->radius, obj->position(), cameraPos, mDetailLevel);
+        int faces = model->render(obj->radius, obj->position(), cameraPos, \
mDetailLevel); +        renderInfo->addBatch(faces);
 
         // Un-transform
         glPopMatrix();
--- trunk/playground/games/astrododge/src/mainwindow.cpp #999175:999176
@@ -118,6 +118,11 @@
     KAction* showHDRConfigAction = new KAction("Show HDR config", this);
     actionCollection()->addAction("hdr_config", showHDRConfigAction);
     connect(showHDRConfigAction, SIGNAL(triggered(bool)), mDisplay, \
SLOT(showHdrConfig())); +
+    mShowRenderInfoAction = new KToggleAction("Show renderinfo", this);
+    mShowRenderInfoAction->setChecked(false);
+    mShowRenderInfoAction->setShortcut(Qt::CTRL + Qt::Key_I);
+    actionCollection()->addAction("show_renderinfo", mShowRenderInfoAction);
 }
 
 void MainWindow::startNewGame()
@@ -145,7 +150,12 @@
 
     mView = new GameView(mDisplay, mWorld);
     mDisplay->appendView(mView);
-    mDisplay->appendView(new GameGUIView(mDisplay, mWorld));
+
+    GameGUIView* guiView = new GameGUIView(mDisplay, mWorld);
+    connect(mShowRenderInfoAction, SIGNAL(triggered(bool)), guiView, \
SLOT(setShowRenderInfo(bool))); +    \
guiView->setShowRenderInfo(mShowRenderInfoAction->isChecked()); +    \
mDisplay->appendView(guiView); +
     mDisplay->removeView(mLoadingView);
 
 //     delete mLoadingView;
--- trunk/playground/games/astrododge/src/mainwindow.h #999175:999176
@@ -18,8 +18,6 @@
 #ifndef MAINWINDOW_H
 #define MAINWINDOW_H
 
-
-
 #include <KXmlGuiWindow>
 
 class GameWorld;
@@ -28,26 +26,9 @@
 class LoadingView;
 class DataStore;
 
-struct RenderInfo
-{
-    RenderInfo()
-    {
-        totalTriangles = totalAsteroids = totalObjects = 0;
-        for (int i = 0; i < lodCount; i++) {
-            asteroidsPerLod[i] = 0;
-            trianglesPerLod[i] = 0;
-        }
-    }
+class KToggleAction;
 
-    static const int lodCount = 8;
-    unsigned int totalTriangles;
-    unsigned int totalObjects;
-    unsigned int totalAsteroids;
-    unsigned int asteroidsPerLod[lodCount];
-    unsigned int trianglesPerLod[lodCount];
-};
 
-
 /**
  * @author Rivo Laks <rivolaks@hot.ee>
  */
@@ -88,6 +69,8 @@
 
         // TODO: belongs to GameWorld
         bool mGameRunning;
+
+        KToggleAction* mShowRenderInfoAction;
 };
 
 #endif
--- trunk/playground/games/astrododge/src/model.cpp #999175:999176
@@ -176,9 +176,10 @@
     return mLODs[lod];
 }
 
-void Model::render(float radius, const Vector3f& position, const Vector3f& \
camerapos, float detail) const +int Model::render(float radius, const Vector3f& \
position, const Vector3f& camerapos, float detail) const  {
     int lod = getLod(radius, position, camerapos, detail);
     mLODs[lod]->renderOnce();
+    return mLODs[lod]->indicesCount()/3;
 }
 
--- trunk/playground/games/astrododge/src/model.h #999175:999176
@@ -82,7 +82,7 @@
     Batch* lod(int i) const  { return mLODs[i]; }
     Batch* collisionMesh() const;
 
-    void render(float radius, const Vector3f& position, const Vector3f& camerapos, \
float detail) const; +    int render(float radius, const Vector3f& position, const \
Vector3f& camerapos, float detail) const;  
     inline float getDetailLevel(float radius, const Vector3f& position, const \
Vector3f& camerapos, float detail) const  {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic