Added clock time
This commit is contained in:
@@ -209,6 +209,7 @@
|
||||
<ClCompile Include="DeckLinkAPI_i.c" />
|
||||
<ClCompile Include="control\RuntimeServices.cpp" />
|
||||
<ClCompile Include="decklink\DeckLinkSession.cpp" />
|
||||
<ClCompile Include="runtime\RuntimeClock.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="gl\GLExtensions.h" />
|
||||
@@ -224,6 +225,7 @@
|
||||
<ClInclude Include="gl\VideoFrameTransfer.h" />
|
||||
<ClInclude Include="control\RuntimeServices.h" />
|
||||
<ClInclude Include="decklink\DeckLinkSession.h" />
|
||||
<ClInclude Include="runtime\RuntimeClock.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="LoopThroughWithOpenGLCompositing.ico" />
|
||||
|
||||
@@ -54,6 +54,9 @@
|
||||
<ClCompile Include="decklink\DeckLinkSession.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="runtime\RuntimeClock.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="gl\GLExtensions.h">
|
||||
@@ -95,6 +98,9 @@
|
||||
<ClInclude Include="decklink\DeckLinkSession.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="runtime\RuntimeClock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="LoopThroughWithOpenGLCompositing.ico">
|
||||
|
||||
@@ -18,6 +18,8 @@ bool GlobalParamsBuffer::Update(const RuntimeRenderState& state, unsigned availa
|
||||
AppendStd140Float(buffer, static_cast<float>(state.timeSeconds));
|
||||
AppendStd140Vec2(buffer, static_cast<float>(state.inputWidth), static_cast<float>(state.inputHeight));
|
||||
AppendStd140Vec2(buffer, static_cast<float>(state.outputWidth), static_cast<float>(state.outputHeight));
|
||||
AppendStd140Float(buffer, static_cast<float>(state.utcTimeSeconds));
|
||||
AppendStd140Float(buffer, static_cast<float>(state.utcOffsetSeconds));
|
||||
AppendStd140Float(buffer, static_cast<float>(state.frameCount));
|
||||
AppendStd140Float(buffer, static_cast<float>(state.mixAmount));
|
||||
AppendStd140Float(buffer, static_cast<float>(state.bypass));
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "RuntimeClock.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool ToUtcTime(std::time_t time, std::tm& utcTime)
|
||||
{
|
||||
return gmtime_s(&utcTime, &time) == 0;
|
||||
}
|
||||
|
||||
bool ToLocalTime(std::time_t time, std::tm& localTime)
|
||||
{
|
||||
return localtime_s(&localTime, &time) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeClockSnapshot GetRuntimeClockSnapshot()
|
||||
{
|
||||
return MakeRuntimeClockSnapshot(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
|
||||
}
|
||||
|
||||
RuntimeClockSnapshot MakeRuntimeClockSnapshot(std::time_t now)
|
||||
{
|
||||
RuntimeClockSnapshot snapshot;
|
||||
|
||||
std::tm utcTime = {};
|
||||
if (!ToUtcTime(now, utcTime))
|
||||
return snapshot;
|
||||
|
||||
snapshot.utcTimeSeconds =
|
||||
static_cast<double>(utcTime.tm_hour * 3600 + utcTime.tm_min * 60 + utcTime.tm_sec);
|
||||
|
||||
std::tm localTime = {};
|
||||
if (!ToLocalTime(now, localTime))
|
||||
return snapshot;
|
||||
|
||||
utcTime.tm_isdst = localTime.tm_isdst;
|
||||
const std::time_t localAsTime = std::mktime(&localTime);
|
||||
const std::time_t utcAsLocalTime = std::mktime(&utcTime);
|
||||
if (localAsTime != static_cast<std::time_t>(-1) && utcAsLocalTime != static_cast<std::time_t>(-1))
|
||||
snapshot.utcOffsetSeconds = std::difftime(localAsTime, utcAsLocalTime);
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
12
apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeClock.h
Normal file
12
apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeClock.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
|
||||
struct RuntimeClockSnapshot
|
||||
{
|
||||
double utcTimeSeconds = 0.0;
|
||||
double utcOffsetSeconds = 0.0;
|
||||
};
|
||||
|
||||
RuntimeClockSnapshot GetRuntimeClockSnapshot();
|
||||
RuntimeClockSnapshot MakeRuntimeClockSnapshot(std::time_t now);
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "RuntimeHost.h"
|
||||
|
||||
#include "RuntimeClock.h"
|
||||
#include "RuntimeParameterUtils.h"
|
||||
#include "ShaderCompiler.h"
|
||||
#include "ShaderPackageRegistry.h"
|
||||
@@ -1321,6 +1323,7 @@ bool RuntimeHost::TryGetLayerRenderStates(unsigned outputWidth, unsigned outputH
|
||||
|
||||
void RuntimeHost::BuildLayerRenderStatesLocked(unsigned outputWidth, unsigned outputHeight, std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
const RuntimeClockSnapshot clock = GetRuntimeClockSnapshot();
|
||||
for (const LayerPersistentState& layer : mPersistentState.layers)
|
||||
{
|
||||
auto shaderIt = mPackagesById.find(layer.shaderId);
|
||||
@@ -1331,6 +1334,8 @@ void RuntimeHost::BuildLayerRenderStatesLocked(unsigned outputWidth, unsigned ou
|
||||
state.layerId = layer.id;
|
||||
state.shaderId = layer.shaderId;
|
||||
state.timeSeconds = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - mStartTime).count();
|
||||
state.utcTimeSeconds = clock.utcTimeSeconds;
|
||||
state.utcOffsetSeconds = clock.utcOffsetSeconds;
|
||||
state.frameCount = static_cast<double>(mFrameCounter);
|
||||
state.mixAmount = 1.0;
|
||||
state.bypass = layer.bypass ? 1.0 : 0.0;
|
||||
|
||||
@@ -102,6 +102,8 @@ struct RuntimeRenderState
|
||||
std::vector<ShaderTextureAsset> textureAssets;
|
||||
std::vector<ShaderFontAsset> fontAssets;
|
||||
double timeSeconds = 0.0;
|
||||
double utcTimeSeconds = 0.0;
|
||||
double utcOffsetSeconds = 0.0;
|
||||
double frameCount = 0.0;
|
||||
double mixAmount = 1.0;
|
||||
double bypass = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user