~thumper/nux/next-changes

« back to all changes in this revision

Viewing changes to NuxGraphics/GLTimer.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 21:15:42 UTC
  • Revision ID: neil.patel@canonical.com-20100901211542-cw2ce3ak28unouwb
Add NuxGraphics with licensing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it 
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but 
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of 
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public 
 
12
 * License for more details.
 
13
 * 
 
14
 * You should have received a copy of both the GNU Lesser General Public 
 
15
 * License version 3 along with this program.  If not, see 
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "NuxCore/NKernel.h"
 
24
#include "GLResource.h"
 
25
#include "GLTimer.h"
 
26
 
 
27
NAMESPACE_BEGIN_OGL
 
28
GLTimer::GLTimer()
 
29
{
 
30
#if defined(INL_OS_WINDOWS)
 
31
    LARGE_INTEGER freq;
 
32
    QueryPerformanceFrequency(&freq);
 
33
    QueryPerformanceCounter(&now);
 
34
    res = (float) (1.0f / (double) freq.QuadPart);
 
35
#elif defined(INL_OS_LINUX)
 
36
    gettimeofday(&m_last_time, NULL);
 
37
#endif
 
38
}
 
39
 
 
40
GLTimer::~GLTimer()
 
41
{
 
42
}
 
43
 
 
44
void GLTimer::Reset(void)
 
45
{
 
46
#if defined(INL_OS_WINDOWS)
 
47
    QueryPerformanceCounter(&now);
 
48
#elif defined(INL_OS_LINUX)
 
49
    gettimeofday(&m_last_time, NULL);
 
50
#endif
 
51
}
 
52
 
 
53
float GLTimer::PassedMilliseconds(void)
 
54
{
 
55
#if defined(INL_OS_WINDOWS)
 
56
    LARGE_INTEGER temp;
 
57
    QueryPerformanceCounter(&temp);
 
58
    double elapsedTime = (temp.QuadPart - now.QuadPart) * res * 1000.0f;
 
59
    //now.QuadPart = temp.QuadPart;
 
60
    return elapsedTime;
 
61
 
 
62
#elif defined(INL_OS_LINUX)
 
63
    timeval current_time;
 
64
    float elapsedTime;
 
65
    
 
66
    gettimeofday(&current_time, NULL);
 
67
 
 
68
    elapsedTime = (current_time.tv_sec - m_last_time.tv_sec) * 1000.0f;      // seconds to millisecond
 
69
    elapsedTime += (current_time.tv_usec - m_last_time.tv_usec) / 1000.0f;   // micro seconds to millisecond
 
70
    return elapsedTime;
 
71
#endif
 
72
}
 
73
 
 
74
// float GLTimer::PassedFrac(void)
 
75
// {
 
76
//     LARGE_INTEGER temp;
 
77
//     QueryPerformanceCounter(&temp);
 
78
//     return (temp.QuadPart - now.QuadPart) * res;
 
79
// }
 
80
NAMESPACE_END_OGL