Skip to content

Commit

Permalink
More explicit type declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBanana committed Jul 20, 2023
1 parent 0c55008 commit 64a7be4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
32 changes: 16 additions & 16 deletions sources/Core/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,17 @@ void Image::ReadPixels(const Offset3D& offset, const Extent3D& extent, const Dst
ValidateImageDataSize(extent, imageDesc);

/* Get source image parameters */
const auto bpp = GetBytesPerPixel();
const auto srcRowStride = bpp * GetExtent().width;
const auto srcDepthStride = srcRowStride * GetExtent().height;
auto src = data_.get() + GetDataPtrOffset(offset);
const std::uint32_t bpp = GetBytesPerPixel();
const std::uint32_t srcRowStride = bpp * GetExtent().width;
const std::uint32_t srcDepthStride = srcRowStride * GetExtent().height;
const char* src = data_.get() + GetDataPtrOffset(offset);

if (GetFormat() == imageDesc.format && GetDataType() == imageDesc.dataType)
{
/* Get destination image parameters */
const auto dstRowStride = bpp * extent.width;
const auto dstDepthStride = dstRowStride * extent.height;
auto dst = reinterpret_cast<char*>(imageDesc.data);
const std::uint32_t dstRowStride = bpp * extent.width;
const std::uint32_t dstDepthStride = dstRowStride * extent.height;
char* dst = reinterpret_cast<char*>(imageDesc.data);

/* Blit region into destination image */
BitBlit(
Expand All @@ -337,7 +337,7 @@ void Image::ReadPixels(const Offset3D& offset, const Extent3D& extent, const Dst
else
{
/* Copy region into temporary sub-image */
Image subImage { extent, GetFormat(), GetDataType() };
Image subImage{ extent, GetFormat(), GetDataType() };

BitBlit(
extent, bpp,
Expand All @@ -362,17 +362,17 @@ void Image::WritePixels(const Offset3D& offset, const Extent3D& extent, const Sr
ValidateImageDataSize(extent, imageDesc);

/* Get destination image parameters */
const auto bpp = GetBytesPerPixel();
const auto dstRowStride = bpp * GetExtent().width;
const auto dstDepthStride = dstRowStride * GetExtent().height;
auto dst = data_.get() + GetDataPtrOffset(offset);
const std::uint32_t bpp = GetBytesPerPixel();
const std::uint32_t dstRowStride = bpp * GetExtent().width;
const std::uint32_t dstDepthStride = dstRowStride * GetExtent().height;
char* dst = data_.get() + GetDataPtrOffset(offset);

if (GetFormat() == imageDesc.format && GetDataType() == imageDesc.dataType)
{
/* Get source image parameters */
const auto srcRowStride = bpp * extent.width;
const auto srcDepthStride = srcRowStride * extent.height;
auto src = reinterpret_cast<const char*>(imageDesc.data);
const std::uint32_t srcRowStride = bpp * extent.width;
const std::uint32_t srcDepthStride = srcRowStride * extent.height;
const char* src = reinterpret_cast<const char*>(imageDesc.data);

/* Blit source image into region */
BitBlit(
Expand All @@ -384,7 +384,7 @@ void Image::WritePixels(const Offset3D& offset, const Extent3D& extent, const Sr
else
{
/* Copy input data into sub-image into */
Image subImage { extent, imageDesc.format, imageDesc.dataType };
Image subImage{ extent, imageDesc.format, imageDesc.dataType };
::memcpy(subImage.GetData(), imageDesc.data, imageDesc.dataSize);

/* Convert sub-image */
Expand Down
49 changes: 25 additions & 24 deletions sources/Platform/Win32/Win32WindowCallback.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Win32WindowCallback.cpp
*
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/
Expand All @@ -14,6 +14,7 @@
#ifndef HID_USAGE_PAGE_GENERIC
# define HID_USAGE_PAGE_GENERIC ((USHORT)0x01)
#endif

#ifndef HID_USAGE_GENERIC_MOUSE
# define HID_USAGE_GENERIC_MOUSE ((USHORT)0x02)
#endif
Expand Down Expand Up @@ -45,15 +46,15 @@ static void PostKeyEvent(Window& window, Key keyCode, bool isDown)
static void PostKeyEvent(HWND wnd, WPARAM wParam, LPARAM lParam, bool isDown, bool isSysKey)
{
/* Get window object from window handle */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
/* Extract key code */
auto keyCodeSys = static_cast<std::uint32_t>(wParam);
auto keyCodeOEM = static_cast<std::uint32_t>(lParam & (0xff << 16)) >> 16;
bool isExtendedKey = ((lParam & (1 << 24)) != 0);
const DWORD keyCodeSys = static_cast<DWORD>(wParam);
const DWORD keyCodeOEM = static_cast<DWORD>(lParam & (0xff << 16)) >> 16;
const bool isExtendedKey = ((lParam & (1 << 24)) != 0);

/* Get key code mapping first */
auto keyCode = MapKey(static_cast<std::uint8_t>(keyCodeSys));
const Key keyCode = MapKey(static_cast<BYTE>(keyCodeSys));

/* Check for extended keys */
switch (keyCode)
Expand Down Expand Up @@ -96,15 +97,15 @@ static void ReleaseMouseCapture()
}
}

static void CaptureMouseButton(HWND wnd, Key keyCode, bool doubleClick = false)
static void CaptureMouseButton(HWND wnd, Key keyCode, bool isDoubleClick = false)
{
/* Get window object from window handle */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
/* Post key events and capture mouse */
window->PostKeyDown(keyCode);

if (doubleClick)
if (isDoubleClick)
window->PostDoubleClick(keyCode);

if (++g_mouseCaptureCounter == 1)
Expand All @@ -115,7 +116,7 @@ static void CaptureMouseButton(HWND wnd, Key keyCode, bool doubleClick = false)
static void ReleaseMouseButton(HWND wnd, Key keyCode)
{
/* Get window object from window handle */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
/* Post key event and release mouse capture */
window->PostKeyUp(keyCode);
Expand All @@ -134,7 +135,7 @@ static void ReleaseMouseButton(HWND wnd, Key keyCode)
static void PostLocalMouseMotion(HWND wnd, LPARAM lParam)
{
/* Get window object from window handle */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
/* Extract mouse position from event parameter */
int x = GET_X_LPARAM(lParam);
Expand All @@ -148,7 +149,7 @@ static void PostLocalMouseMotion(HWND wnd, LPARAM lParam)
static void PostGlobalMouseMotion(HWND wnd, LPARAM lParam)
{
/* Get window object from window handle */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
RAWINPUT raw;
UINT rawSize = sizeof(raw);
Expand All @@ -160,7 +161,7 @@ static void PostGlobalMouseMotion(HWND wnd, LPARAM lParam)

if (raw.header.dwType == RIM_TYPEMOUSE)
{
const auto& mouse = raw.data.mouse;
const RAWMOUSE& mouse = raw.data.mouse;

if (mouse.usFlags == MOUSE_MOVE_RELATIVE)
{
Expand Down Expand Up @@ -200,34 +201,34 @@ LRESULT CALLBACK Win32WindowCallback(HWND wnd, UINT msg, WPARAM wParam, LPARAM l
case WM_SIZE:
{
/* Post resize event to window */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
WORD width = LOWORD(lParam);
WORD height = HIWORD(lParam);
window->PostResize({ static_cast<std::uint32_t>(width), static_cast<std::uint32_t>(height) });
window->PostResize(Extent2D{ width, height });
}
}
break;

case WM_CLOSE:
{
/* Post close event to window */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
window->PostQuit();
}
break;

case WM_SETFOCUS:
{
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
window->PostGetFocus();
}
break;

case WM_KILLFOCUS:
{
ReleaseMouseCapture();
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
window->PostLostFocus();
}
break;
Expand Down Expand Up @@ -260,7 +261,7 @@ LRESULT CALLBACK Win32WindowCallback(HWND wnd, UINT msg, WPARAM wParam, LPARAM l

case WM_CHAR:
{
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
window->PostChar(static_cast<wchar_t>(wParam));
}
return 0;
Expand Down Expand Up @@ -329,7 +330,7 @@ LRESULT CALLBACK Win32WindowCallback(HWND wnd, UINT msg, WPARAM wParam, LPARAM l

case WM_MOUSEWHEEL:
{
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
window->PostWheelMotion(GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA);
}
return 0;
Expand All @@ -351,7 +352,7 @@ LRESULT CALLBACK Win32WindowCallback(HWND wnd, UINT msg, WPARAM wParam, LPARAM l
case WM_ERASEBKGND:
{
/* Do not erase background to avoid flickering when user resizes the window */
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
if (window->GetBehavior().disableClearOnResize)
return 0;
Expand All @@ -361,7 +362,7 @@ LRESULT CALLBACK Win32WindowCallback(HWND wnd, UINT msg, WPARAM wParam, LPARAM l

case WM_ENTERSIZEMOVE:
{
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
auto timerID = window->GetBehavior().moveAndResizeTimerID;
if (timerID != Constants::invalidTimerID)
Expand All @@ -375,7 +376,7 @@ LRESULT CALLBACK Win32WindowCallback(HWND wnd, UINT msg, WPARAM wParam, LPARAM l

case WM_EXITSIZEMOVE:
{
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
auto timerID = window->GetBehavior().moveAndResizeTimerID;
if (timerID != Constants::invalidTimerID)
Expand All @@ -389,7 +390,7 @@ LRESULT CALLBACK Win32WindowCallback(HWND wnd, UINT msg, WPARAM wParam, LPARAM l

case WM_TIMER:
{
if (auto window = GetWindowFromUserData(wnd))
if (Win32Window* window = GetWindowFromUserData(wnd))
{
auto timerID = static_cast<std::uint32_t>(wParam);
window->PostTimer(timerID);
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/Direct3D11/Direct3D11.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Direct3D11.h
*
*
* Copyright (c) 2015 Lukas Hermanns. All rights reserved.
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt).
*/
Expand Down
16 changes: 9 additions & 7 deletions sources/Renderer/Direct3D12/D3D12SwapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void D3D12SwapChain::SetName(const char* name)
void D3D12SwapChain::Present()
{
/* Present swap-chain with vsync interval */
auto hr = swapChainDXGI_->Present(syncInterval_, 0);
HRESULT hr = swapChainDXGI_->Present(syncInterval_, 0);
DXThrowIfFailed(hr, "failed to present DXGI swap chain");

/* Advance frame counter */
Expand Down Expand Up @@ -357,7 +357,7 @@ void D3D12SwapChain::CreateDescriptorHeaps(const D3D12Device& device, std::uint3
}
}

void D3D12SwapChain::CreateResolutionDependentResources(const Extent2D& resolution)
HRESULT D3D12SwapChain::CreateResolutionDependentResources(const Extent2D& resolution)
{
ID3D12Device* device = renderSystem_.GetDXDevice();

Expand All @@ -378,7 +378,7 @@ void D3D12SwapChain::CreateResolutionDependentResources(const Extent2D& resoluti
if (swapChainDXGI_)
{
/* Resize swap chain */
auto hr = swapChainDXGI_->ResizeBuffers(
HRESULT hr = swapChainDXGI_->ResizeBuffers(
numColorBuffers_,
resolution.width,
resolution.height,
Expand All @@ -389,7 +389,7 @@ void D3D12SwapChain::CreateResolutionDependentResources(const Extent2D& resoluti
if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
{
/* Do not continue execution of this method, device resources will be destroyed and re-created */
return;
return hr;
}
else
DXThrowIfFailed(hr, "failed to resize DXGI swap chain buffers");
Expand Down Expand Up @@ -429,6 +429,8 @@ void D3D12SwapChain::CreateResolutionDependentResources(const Extent2D& resoluti
/* Create depth-stencil buffer (is used) */
if (HasDepthBuffer())
CreateDepthStencil(device, resolution);

return S_OK;
}

void D3D12SwapChain::CreateColorBufferRTVs(ID3D12Device* device, const Extent2D& resolution)
Expand All @@ -437,7 +439,7 @@ void D3D12SwapChain::CreateColorBufferRTVs(ID3D12Device* device, const Extent2D&
for_range(i, numColorBuffers_)
{
/* Get render target resource from swap-chain buffer */
auto hr = swapChainDXGI_->GetBuffer(i, IID_PPV_ARGS(colorBuffers_[i].native.ReleaseAndGetAddressOf()));
HRESULT hr = swapChainDXGI_->GetBuffer(i, IID_PPV_ARGS(colorBuffers_[i].native.ReleaseAndGetAddressOf()));
DXThrowIfCreateFailed(hr, "ID3D12Resource", "for swap-chain color buffer");

colorBuffers_[i].SetInitialState(D3D12_RESOURCE_STATE_PRESENT);
Expand All @@ -460,7 +462,7 @@ void D3D12SwapChain::CreateColorBufferRTVs(ID3D12Device* device, const Extent2D&
for_range(i, numColorBuffers_)
{
/* Create render target resource */
auto hr = device->CreateCommittedResource(
HRESULT hr = device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&tex2DMSDesc,
Expand Down Expand Up @@ -499,7 +501,7 @@ void D3D12SwapChain::CreateDepthStencil(ID3D12Device* device, const Extent2D& re
(D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE)
);

auto hr = device->CreateCommittedResource(
HRESULT hr = device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
D3D12_HEAP_FLAG_NONE,
&tex2DDesc,
Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/Direct3D12/D3D12SwapChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class D3D12SwapChain final : public SwapChain

void CreateDescriptorHeaps(const D3D12Device& device, std::uint32_t samples);

void CreateResolutionDependentResources(const Extent2D& resolution);
HRESULT CreateResolutionDependentResources(const Extent2D& resolution);
void CreateColorBufferRTVs(ID3D12Device* device, const Extent2D& resolution);
void CreateDepthStencil(ID3D12Device* device, const Extent2D& resolution);

Expand Down

0 comments on commit 64a7be4

Please sign in to comment.