1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Change how draw calls are counted

This commit is contained in:
Daniel Evans 2015-03-28 13:54:28 +00:00 committed by Daniel Evans
parent 6851c5e011
commit 49a8b9b2f4
6 changed files with 33 additions and 11 deletions

View File

@ -89,12 +89,8 @@ public:
GameRenderer(GameWorld*);
~GameRenderer();
/** Number of issued draw calls */
size_t rendered;
/** Number of culling events */
size_t culled;
size_t frames;
size_t geoms;
/** @todo Clean up all these shader program and location variables */
Renderer::ShaderProgram* worldProg;

View File

@ -97,9 +97,21 @@ public:
virtual void invalidate() = 0;
/**
* Resets all per-frame counters.
*/
void swap();
/**
* Returns the number of draw calls issued for the current frame.
*/
int getDrawCount();
private:
glm::ivec2 viewport;
glm::mat4 projection2D;
protected:
int drawCounter;
};
class OpenGLRenderer : public Renderer

View File

@ -282,7 +282,7 @@ void GameRenderer::renderWorld(const ViewCamera &camera, float alpha)
_camera.frustum.update(proj * view);
rendered = culled = geoms = frames = 0;
culled = 0;
renderer->useProgram(worldProg);
@ -816,8 +816,6 @@ void GameRenderer::renderItem(InventoryItem *item, const glm::mat4 &modelMatrix)
void GameRenderer::renderGeometry(Model* model, size_t g, const glm::mat4& modelMatrix, float opacity, GameObject* object)
{
geoms++;
for(size_t sg = 0; sg < model->geometries[g]->subgeom.size(); ++sg)
{
Model::SubGeometry& subgeom = model->geometries[g]->subgeom[sg];
@ -880,8 +878,6 @@ void GameRenderer::renderGeometry(Model* model, size_t g, const glm::mat4& model
dp.ambient = mat.ambientIntensity;
}
rendered++;
if( abortTransparent ) {
transparentDrawQueue.push_back(
{model, g, sg, modelMatrix, dp, object}
@ -995,7 +991,6 @@ void GameRenderer::drawOnScreenText()
bool GameRenderer::renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GameObject* object, float opacity, bool queueTransparent)
{
frames++;
auto localmatrix = matrix;
bool vis = true;

View File

@ -87,6 +87,16 @@ void Renderer::setViewport(const glm::ivec2& vp)
projection2D = glm::ortho(0.f, (float)viewport.x, (float)viewport.y, 0.f, -1.f, 1.f);
}
void Renderer::swap()
{
drawCounter = 0;
}
int Renderer::getDrawCount()
{
return drawCounter;
}
void OpenGLRenderer::useDrawBuffer(DrawBuffer* dbuff)
{
if( dbuff != currentDbuff )
@ -122,6 +132,8 @@ OpenGLRenderer::OpenGLRenderer()
glBindBufferBase(GL_UNIFORM_BUFFER, 1, UBOScene);
glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOObject);
swap();
}
std::string OpenGLRenderer::getIDString() const
@ -221,6 +233,7 @@ void OpenGLRenderer::draw(const glm::mat4& model, DrawBuffer* draw, const Render
};
uploadUBO(UBOObject, oudata);
drawCounter++;
glDrawElements(draw->getFaceType(), p.count, GL_UNSIGNED_INT,
(void*) (sizeof(RenderIndex) * p.start));
}
@ -239,6 +252,7 @@ void OpenGLRenderer::drawArrays(const glm::mat4& model, DrawBuffer* draw, const
};
uploadUBO(UBOObject, oudata);
drawCounter++;
glDrawArrays(draw->getFaceType(), p.start, p.count);
}

View File

@ -265,6 +265,10 @@ void RWGame::tick(float dt)
void RWGame::render(float alpha, float time)
{
lastDraws = getRenderer()->getRenderer()->getDrawCount();
getRenderer()->getRenderer()->swap();
auto size = getWindow().getSize();
renderer->setViewport(size.x, size.y);
@ -362,7 +366,7 @@ void RWGame::renderDebugStats(float time)
{
std::stringstream ss;
ss << "Frametime: " << time << " (FPS " << (1.f/time) << ")\n";
ss << "Draws: " << renderer->rendered << " (" << renderer->culled << " Culled)\n";
ss << "Draws: " << lastDraws << " (" << renderer->culled << " Culls)\n";
// Count the number of interesting objects.
int peds = 0, cars = 0;

View File

@ -16,6 +16,7 @@ class RWGame
bool inFocus;
ViewCamera lastCam, nextCam;
bool showDebugStats;
int lastDraws; /// Number of draws issued for the last frame.
float accum;
float timescale;