1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the libgltf project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 */ 9 10 #ifndef FPSCOUNTER_H 11 #define FPSCOUNTER_H 12 13 #ifndef QA_TEST 14 #define QA_TEST 0 15 #endif 16 17 #ifndef AUTO_CLOSE_TIME 18 #define AUTO_CLOSE_TIME 10 19 #endif 20 21 #include "Font.h" 22 #include "Shaders.h" 23 #include "types.h" 24 25 #define WRITEFPS2FILE 0 26 #if WRITEFPS2FILE 27 #include <fstream> 28 #include <vector> 29 #endif 30 #define TIMETHRESHOLD 1 31 #define FPS_FILE "./FPSCounter.txt" 32 #define VERTSHADER "uniform mat4 projMatrix;\n"\ 33 "uniform mat4 modelViewMatrix;\n"\ 34 "attribute vec2 inPosition;\n"\ 35 "attribute vec2 inCoord;\n"\ 36 "varying vec2 texCoord;\n"\ 37 "void main()\n"\ 38 "{\n"\ 39 " gl_Position = projMatrix * modelViewMatrix *\n"\ 40 " vec4(inPosition, 0.0, 1.0);\n"\ 41 " texCoord = inCoord;\n"\ 42 "}" 43 44 #define FRAGSHADER "varying vec2 texCoord;\n"\ 45 "uniform sampler2D gSampler;\n"\ 46 "uniform vec4 vColor;\n"\ 47 "void main()\n"\ 48 "{\n"\ 49 " vec4 vTexColor = texture2D(gSampler, texCoord);\n"\ 50 " gl_FragColor = vec4(vTexColor.r, vTexColor.r, vTexColor.r,"\ 51 " vTexColor.r)*vColor;\n"\ 52 "}" 53 54 namespace libgltf 55 { 56 57 class FPSCounter 58 { 59 public: 60 void timeStamp(); 61 62 void printFPS(glTFViewport* pViewpoit); 63 bool loadFPSShader(ShaderProgram* pShaderProgram); 64 65 FPSCounter(ShaderProgram* pShaderProgram); 66 ~FPSCounter(); 67 68 private: 69 FPSCounter(const FPSCounter&); 70 FPSCounter& operator=(const FPSCounter&); 71 72 void init(ShaderProgram* pShaderProgram); 73 Font* pFont; 74 75 unsigned int uiFPSProgram; 76 77 double mLastTime; 78 79 int mFrames; 80 int mFPS; 81 82 #if WRITEFPS2FILE 83 std::vector<int> FPSRecoder; 84 std::ofstream FPSFile; 85 int timeCounter; 86 #endif 87 }; 88 89 } // namespace libgltf 90 91 #endif 92 93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 94