feat:: vsync stuff
This commit is contained in:
@@ -28,6 +28,9 @@ SOFTWARE.
|
||||
|
||||
C4JRender RenderManager;
|
||||
|
||||
//str1k3r - set VSync to true by default
|
||||
bool C4JRender::m_VSyncState = true;
|
||||
|
||||
void C4JRender::Tick()
|
||||
{
|
||||
InternalRenderManager.CBuffTick();
|
||||
@@ -38,6 +41,16 @@ void C4JRender::UpdateGamma(unsigned short usGamma)
|
||||
InternalRenderManager.UpdateGamma(usGamma);
|
||||
}
|
||||
|
||||
void C4JRender::SetVSync(bool vs)
|
||||
{
|
||||
m_VSyncState = vs;
|
||||
}
|
||||
|
||||
int C4JRender::GetVSync()
|
||||
{
|
||||
return m_VSyncState ? 1 : 0;
|
||||
}
|
||||
|
||||
void C4JRender::MatrixMode(int type)
|
||||
{
|
||||
InternalRenderManager.MatrixMode(type);
|
||||
@@ -118,9 +131,9 @@ void C4JRender::DoScreenGrabOnNextPresent()
|
||||
InternalRenderManager.DoScreenGrabOnNextPresent();
|
||||
}
|
||||
|
||||
void C4JRender::Present()
|
||||
void C4JRender::Present(int ScreenWidth, int ScreenHeight)
|
||||
{
|
||||
InternalRenderManager.Present();
|
||||
InternalRenderManager.Present(ScreenWidth, ScreenHeight);
|
||||
}
|
||||
|
||||
void C4JRender::Clear(int flags, D3D11_RECT* pRect)
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
ID3D11DeviceContext *InitialiseContext(bool fromPresent);
|
||||
void StartFrame();
|
||||
void DoScreenGrabOnNextPresent();
|
||||
void Present();
|
||||
void Present(int ScreenWidth, int ScreenHeight);
|
||||
void Clear(int flags, D3D11_RECT *pRect);
|
||||
void SetClearColour(const float colourRGBA[4]);
|
||||
bool IsWidescreen();
|
||||
|
||||
@@ -55,8 +55,6 @@ D3D11_PRIMITIVE_TOPOLOGY Renderer::g_topologies[C4JRender::PRIMITIVE_TYPE_COUNT]
|
||||
};
|
||||
|
||||
static const unsigned int kVertexBufferSize = 0x100000;
|
||||
static const unsigned int kScreenGrabWidth = 1920;
|
||||
static const unsigned int kScreenGrabHeight = 1080;
|
||||
static const unsigned int kThumbnailSize = 64;
|
||||
|
||||
static const unsigned int g_vertexStrides[C4JRender::VERTEX_TYPE_COUNT] = { 32, 16, 32, 32 };
|
||||
@@ -864,7 +862,7 @@ bool Renderer::IsWidescreen()
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::Present()
|
||||
void Renderer::Present(int ScreenWidth, int ScreenHeight)
|
||||
{
|
||||
PROFILER_SCOPE("Renderer::Present", "Present", MP_MAGENTA);
|
||||
|
||||
@@ -872,7 +870,7 @@ void Renderer::Present()
|
||||
{
|
||||
PROFILER_SCOPE("Renderer::Present", "ScreenGrab", MP_MAGENTA);
|
||||
|
||||
unsigned char *linearData = new unsigned char[kScreenGrabWidth * kScreenGrabHeight * 4];
|
||||
unsigned char *linearData = new unsigned char[ScreenWidth * ScreenHeight * 4];
|
||||
|
||||
ID3D11Resource *backBufferResource = NULL;
|
||||
ID3D11Texture2D *backBuffer = NULL;
|
||||
@@ -898,13 +896,13 @@ void Renderer::Present()
|
||||
m_pDeviceContext->Map(stagingTexture, 0, D3D11_MAP_READ_WRITE, 0, &mapped);
|
||||
const unsigned char* src = reinterpret_cast<const unsigned char*>(mapped.pData);
|
||||
|
||||
for (UINT y = 0; y < kScreenGrabHeight; ++y)
|
||||
for (UINT y = 0; y < ScreenHeight; ++y)
|
||||
{
|
||||
unsigned char *dstRow = linearData + y * kScreenGrabWidth * 4;
|
||||
unsigned char *dstRow = linearData + y * ScreenWidth * 4;
|
||||
const unsigned char *srcRow = src + y * mapped.RowPitch;
|
||||
std::memcpy(dstRow, srcRow, kScreenGrabWidth * 4);
|
||||
std::memcpy(dstRow, srcRow, ScreenWidth * 4);
|
||||
|
||||
for (UINT x = 0; x < kScreenGrabWidth; ++x)
|
||||
for (UINT x = 0; x < ScreenWidth; ++x)
|
||||
dstRow[x * 4 + 3] = 0xFF;
|
||||
}
|
||||
|
||||
@@ -926,8 +924,8 @@ void Renderer::Present()
|
||||
UTCSysTime.wSecond);
|
||||
|
||||
D3DXIMAGE_INFO info;
|
||||
info.Width = kScreenGrabWidth;
|
||||
info.Height = kScreenGrabHeight;
|
||||
info.Width = ScreenWidth;
|
||||
info.Height = ScreenHeight;
|
||||
SaveTextureData(fileName, &info, reinterpret_cast<int*>(linearData));
|
||||
|
||||
delete[] linearData;
|
||||
@@ -935,7 +933,7 @@ void Renderer::Present()
|
||||
m_bShouldScreenGrabNextFrame = false;
|
||||
}
|
||||
|
||||
m_pSwapChain->Present(1, 0);
|
||||
m_pSwapChain->Present(C4JRender::GetVSync(), 0);
|
||||
++presentCount;
|
||||
}
|
||||
|
||||
@@ -1046,4 +1044,3 @@ Renderer::Context &Renderer::getContext()
|
||||
{
|
||||
return *reinterpret_cast<Renderer::Context*>(TlsGetValue(Renderer::tlsIdx));
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,11 @@ public:
|
||||
void Tick();
|
||||
void UpdateGamma(unsigned short usGamma);
|
||||
|
||||
// VSync
|
||||
static bool m_VSyncState;
|
||||
static void SetVSync(bool vs);
|
||||
static int GetVSync();
|
||||
|
||||
// Matrix stack
|
||||
void MatrixMode(int type);
|
||||
void MatrixSetIdentity();
|
||||
@@ -76,7 +81,7 @@ public:
|
||||
void InitialiseContext();
|
||||
void StartFrame();
|
||||
void DoScreenGrabOnNextPresent();
|
||||
void Present();
|
||||
void Present(int ScreenWidth, int ScreenHeight);
|
||||
void Clear(int flags, D3D11_RECT *pRect = NULL);
|
||||
void SetClearColour(const float colourRGBA[4]);
|
||||
bool IsWidescreen();
|
||||
|
||||
Reference in New Issue
Block a user