Frame timer does not show time

I am currently using DirectX11 and MFC. The top of the window should tell me how long it takes to render the cube (in seconds). At the moment the cube is rendered but when I try to work out how many seconds it took to render the cube I keep getting 0 on the top of the window. This cannot be right. Help please?

This is my Ondraw function:

void CLearningVisualCView::OnDraw(CDC* pDC)
// I want the OnDraw function to create the cube..
{

CString TimerReports;

// TODO: add draw code for native data here

CLearningVisualCDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;

Timer.GetStartTime();
Render(); // This renders the cube

Timer.GetEndTime(); // The counts stopwatch ends.
Timer.DeltaCountDifference(Timer.StartTime, Timer.EndTime);
Timer.GetSecondsPerCount();
Timer.FrameTime(Timer.DeltaCounts, Timer.SecondsPerCount);

TimerReports.Format(_T("%.100I64d"), Timer.Time);

//TimerReports.Format(_T("%.5I64d"), Timer.FrameTime(Timer.DeltaCounts, Timer.SecondsPerCount)); // This converts the DeltaCountDifference into a CString. It has 5 d.p.
AfxGetMainWnd()->SetWindowText(TimerReports); // This displays my count difference to the top of the window.

}


This is my Timer class:

#include "stdafx.h"
#include "GameTimer.h"

GameTimer::GameTimer()
{

//  QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
//  SecondsPerCount = 1.0 / (double)countsPerSec;

}

GameTimer::~GameTimer()
{

}

_int64 GameTimer::GetStartTime()
{

QueryPerformanceCounter((LARGE_INTEGER*)&StartTime);

return StartTime;

}

_int64 GameTimer::GetEndTime()
{

QueryPerformanceCounter((LARGE_INTEGER*)&EndTime);

return EndTime;

}

// The _int64& are references. We will link them to the StartTime and the EndTime in the CLearningVisualCView - OnDraw(). This is done by adding them as arguments.

_int64 GameTimer::DeltaCountDifference(_int64& TimeA, _int64& TimeB)
{

_int64 DeltaCounts = TimeB - TimeA;

return DeltaCounts;
}

float GameTimer::GetSecondsPerCount()
{

QueryPerformanceFrequency((LARGE_INTEGER*)&CountsPerSecond);

SecondsPerCount = 1 / CountsPerSecond;

return SecondsPerCount;
}

_int64 GameTimer::FrameTime(_int64& TheDeltaCounts, float& SecsPerCount)
{

Time = TheDeltaCounts * SecsPerCount;

return Time;
}


SecondsPerCount = 1 / CountsPerSecond;

That will always be 0. CountsPerSecond is an integer value, as is the constant 1. Integer operations result in integers.

You will need to coerce the arguments into a floating point format before performing the division. The best way to do this without potential warnings would be:

SecondsPerCount = 1.0 / static_cast<double>(CountsPerSecond);

Which is the code you have commented out in your sample.

You also didn't show the header for that type, so there could be a bunch of errors there as well that we can't possibly know about.

Lastly, keep in mind that you may not be measuring what you think you're measuring, as calling graphics API draw commands will not actually draw the image. You need to flush the command queue or present the window backbuffer to ensure all the draw commands are actually processed. You are (probably) accurately measuring how long it takes your application to ask the GPU to do some work, which may or may not be what you want.

• Thank you so much for your reply @Sean Middleditch I have in my render function the line HR = mSwapChain->Present(0, 0); Is this what you mean by presenting the back buffer? I do have the header files but I am not sure where to place them on this discussion. – Vic M Nov 18 '15 at 14:22
• Thank you so much for your reply. I have in my render function the line HR = mSwapChain->Present(0, 0); Is this what you mean by presenting the back buffer? I do have the header files but I am not sure where to place them on this discussion. – Vic M – Vic M Nov 19 '15 at 12:15