Hash :
33ea2f97
Author :
Date :
2014-08-29T15:15:01
Added BufferSubData benchmark. BUG=angle:705 Change-Id: I65d557f35e4c9f1d94853a775330a92b7d428847 Reviewed-on: https://chromium-review.googlesource.com/213810 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "SimpleBenchmark.h"
#include <iostream>
SimpleBenchmark::SimpleBenchmark(const std::string &name, size_t width, size_t height, EGLint glesMajorVersion, EGLint requestedRenderer)
: mNumFrames(0),
mName(name),
mRunning(false),
mDrawIterations(10),
mRunTimeSeconds(5.0)
{
mOSWindow.reset(CreateOSWindow());
mEGLWindow.reset(new EGLWindow(width, height, glesMajorVersion, requestedRenderer));
mTimer.reset(CreateTimer());
}
bool SimpleBenchmark::initialize()
{
std::cout << "========= " << mName << " =========" << std::endl;
return initializeBenchmark();
}
void SimpleBenchmark::destroy()
{
double totalTime = mTimer->getElapsedTime();
std::cout << " - total time: " << totalTime << " sec" << std::endl;
std::cout << " - frames: " << mNumFrames << std::endl;
std::cout << " - average frame time: " << 1000.0 * totalTime / mNumFrames << " msec" << std::endl;
std::cout << "=========" << std::endl << std::endl;
destroyBenchmark();
}
void SimpleBenchmark::step(float dt, double totalTime)
{
stepBenchmark(dt, totalTime);
}
void SimpleBenchmark::draw()
{
if (mTimer->getElapsedTime() > mRunTimeSeconds) {
mRunning = false;
return;
}
++mNumFrames;
beginDrawBenchmark();
for (unsigned int iteration = 0; iteration < mDrawIterations; ++iteration)
{
drawBenchmark();
}
endDrawBenchmark();
}
int SimpleBenchmark::run()
{
if (!mOSWindow->initialize(mName, mEGLWindow->getWidth(), mEGLWindow->getHeight()))
{
return -1;
}
if (!mEGLWindow->initializeGL(mOSWindow.get()))
{
return -1;
}
mRunning = true;
int result = 0;
if (!initialize())
{
mRunning = false;
result = -1;
}
mTimer->start();
double prevTime = 0.0;
while (mRunning)
{
double elapsedTime = mTimer->getElapsedTime();
double deltaTime = elapsedTime - prevTime;
step(static_cast<float>(deltaTime), elapsedTime);
// Clear events that the application did not process from this frame
Event event;
while (popEvent(&event))
{
// If the application did not catch a close event, close now
if (event.Type == Event::EVENT_CLOSED)
{
mRunning = false;
}
}
if (!mRunning)
{
break;
}
draw();
mEGLWindow->swap();
mOSWindow->messageLoop();
prevTime = elapsedTime;
}
destroy();
mEGLWindow->destroyGL();
mOSWindow->destroy();
return result;
}
bool SimpleBenchmark::popEvent(Event *event)
{
return mOSWindow->popEvent(event);
}
OSWindow *SimpleBenchmark::getWindow()
{
return mOSWindow.get();
}