Skip to content

Commit

Permalink
Merge pull request #9 from SungJJinKang/d3d11_work
Browse files Browse the repository at this point in the history
D3d11 work
  • Loading branch information
SungJJinKang committed Feb 5, 2022
2 parents 60da0d9 + 53431a0 commit b3e9095
Show file tree
Hide file tree
Showing 40 changed files with 1,779 additions and 539 deletions.
78 changes: 69 additions & 9 deletions DX11GraphicsAPI/DX11GraphicsAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ namespace dooms


static HRESULT InitWindow(HINSTANCE hInstance, int nCmdShow, int width, int height);
static HRESULT InitDevice();
static HRESULT InitDevice(const unsigned multisampleNum);
static void CleanupDevice();
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

Expand Down Expand Up @@ -420,7 +420,7 @@ namespace dooms
return S_OK;
}

static HRESULT InitDevice()
static HRESULT InitDevice(const unsigned multisampleNum)
{
HRESULT hr = S_OK;

Expand Down Expand Up @@ -563,12 +563,21 @@ namespace dooms
desc.CullMode = D3D11_CULL_BACK;
desc.FrontCounterClockwise = true;
desc.DepthBias = 0;
desc.DepthBias = 0;
desc.SlopeScaledDepthBias = 0.0f;
desc.DepthBiasClamp = 0.0f;
desc.DepthClipEnable = true;
desc.ScissorEnable = false;
desc.MultisampleEnable = false;
if(multisampleNum > 0)
{
desc.MultisampleEnable = true;
desc.AntialiasedLineEnable = true;
}
else
{
desc.MultisampleEnable = false;
desc.AntialiasedLineEnable = false;
}

desc.AntialiasedLineEnable = false;

HRESULT hr = dx11::g_pd3dDevice->CreateRasterizerState(&desc, &state);
Expand Down Expand Up @@ -806,7 +815,7 @@ namespace dooms
return 0;
}

if (FAILED(dx11::InitDevice()))
if (FAILED(dx11::InitDevice(multiSamplingNum)))
{
dx11::CleanupDevice();
assert(0);
Expand Down Expand Up @@ -1873,13 +1882,14 @@ namespace dooms
(
const GraphicsAPI::eBufferTarget bufferTarget,
const unsigned long long bufferSize,
const void* const initialData
const void* const initialData,
const bool dynamicWrite /* if you don't use map/unmap or use only UpdateSubResource, you don't need set to true.*/
)
{
D3D11_BUFFER_DESC bd = {};
bd.Usage = D3D11_USAGE_DEFAULT;
bd.Usage = (dynamicWrite == false) ? D3D11_USAGE_DEFAULT : D3D11_USAGE_DYNAMIC;
bd.ByteWidth = bufferSize;
bd.CPUAccessFlags = 0;
bd.CPUAccessFlags = (dynamicWrite == false) ? 0 : D3D11_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;
bd.StructureByteStride = 0;

Expand Down Expand Up @@ -1949,7 +1959,8 @@ namespace dooms
{
assert(bufferObject != 0);
ID3D11Resource* const bufferResource = reinterpret_cast<ID3D11Resource*>(bufferObject);


// You can't update buffer partially with UpdateSubresource.
dx11::g_pImmediateContext->UpdateSubresource(bufferResource, NULL, nullptr, data, 0, 0);
}

Expand Down Expand Up @@ -2187,5 +2198,54 @@ namespace dooms
return nullptr;
}

DOOMS_ENGINE_GRAPHICS_API void* MapBufferObjectToClientAddress
(
const unsigned long long bufferID,
const GraphicsAPI::eBufferTarget bindBufferTarget,
const GraphicsAPI::eMapBufferAccessOption mapBufferAccessOption
)
{
ID3D11Resource* const d3d11Resource = reinterpret_cast<ID3D11Resource*>(bufferID);

D3D11_MAP mapType;
switch (mapBufferAccessOption)
{
case GraphicsAPI::READ_ONLY:
mapType = D3D11_MAP::D3D11_MAP_READ;
break;
case GraphicsAPI::WRITE_ONLY:
mapType = D3D11_MAP::D3D11_MAP_WRITE;
break;
case GraphicsAPI::READ_WRITE:
mapType = D3D11_MAP::D3D11_MAP_READ_WRITE;
break;
case GraphicsAPI::WRITE_DISCARD:
mapType = D3D11_MAP::D3D11_MAP_WRITE_DISCARD;
break;
case GraphicsAPI::WRITE_NO_OVERWRITE:
mapType = D3D11_MAP::D3D11_MAP_WRITE_NO_OVERWRITE;
break;
default:
NEVER_HAPPEN;
}

D3D11_MAPPED_SUBRESOURCE mappedResource{};

dx11::g_pImmediateContext->Map(d3d11Resource, 0, mapType, NULL, &mappedResource);

return mappedResource.pData;
}

DOOMS_ENGINE_GRAPHICS_API void UnMapBufferObjectMappedToClientAddress
(
const unsigned long long bufferID,
const GraphicsAPI::eBufferTarget bindBufferTarget
)
{
ID3D11Resource* const d3d11Resource = reinterpret_cast<ID3D11Resource*>(bufferID);

dx11::g_pImmediateContext->Unmap(d3d11Resource, 0);
}

}
}
4 changes: 4 additions & 0 deletions Doom3/Doom3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ xcopy /y /d /E /H /C /I "$(ProjectDir)Assets" "$(TargetDir)Assets"</Command>
<ClCompile Include="Source\GameLogic\CustomComponent\ExportTextureTester.cpp" />
<ClCompile Include="Source\GameLogic\CustomComponent\FireBulletComponent.cpp" />
<ClCompile Include="Source\GameLogic\CustomComponent\Move_WASD.cpp" />
<ClCompile Include="Source\GameLogic\CustomComponent\PathFollower.cpp" />
<ClCompile Include="Source\GameLogic\CustomComponent\Portfolio\DeferredRenderingDebuggerController.cpp" />
<ClCompile Include="Source\GameLogic\CustomComponent\Portfolio\OverDrawVisualizationDebugger.cpp" />
<ClCompile Include="Source\GameLogic\CustomComponent\Portfolio\PhysicsDebuggerController.cpp" />
Expand Down Expand Up @@ -946,6 +947,8 @@ xcopy /y /d /E /H /C /I "$(ProjectDir)Assets" "$(TargetDir)Assets"</Command>
<ClInclude Include="Source\GameLogic\CustomComponent\ExportTextureTester.h" />
<ClInclude Include="Source\GameLogic\CustomComponent\FireBulletComponent.h" />
<ClInclude Include="Source\GameLogic\CustomComponent\Move_WASD.h" />
<ClInclude Include="Source\GameLogic\CustomComponent\PathFollower.h" />
<ClInclude Include="Source\GameLogic\CustomComponent\PathFollower.reflection.h" />
<ClInclude Include="Source\GameLogic\CustomComponent\PerformanceTestController.h" />
<ClInclude Include="Source\GameLogic\CustomComponent\Portfolio\DeferredRenderingDebuggerController.h" />
<ClInclude Include="Source\GameLogic\CustomComponent\Portfolio\OverDrawVisualizationDebugger.h" />
Expand Down Expand Up @@ -1162,6 +1165,7 @@ xcopy /y /d /E /H /C /I "$(ProjectDir)Assets" "$(TargetDir)Assets"</Command>
</MASM>
<None Include="Source\Core\ResourceManagement\JobSystem_cpp\MultithreadingJobSystemStrategy.md" />
<None Include="Source\Core\ResourceManagement\JobSystem_cpp\README.md" />
<None Include="Source\GameLogic\Benchmark.inl" />
<None Include="Source\GameLogic\CustomComponent\ButtonRotate.reflectionh" />
<None Include="Source\GameLogic\OverDrawVisualizationTest.inl" />
<None Include="Source\GameLogic\Portfolio.inl" />
Expand Down
12 changes: 12 additions & 0 deletions Doom3/Doom3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@
<ClCompile Include="Source\Core\Graphics\GraphicsAPI\graphicsAPIHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\GameLogic\CustomComponent\PathFollower.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="dependency\glad\include\glad\glad.h">
Expand Down Expand Up @@ -1970,6 +1973,12 @@
<ClInclude Include="Source\Core\Graphics\GraphicsAPI\graphicsAPIHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\GameLogic\CustomComponent\PathFollower.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Source\GameLogic\CustomComponent\PathFollower.reflection.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="dependency\glfw-3.3.2.bin.WIN64\docs\html\search\all_0.html" />
Expand Down Expand Up @@ -2153,6 +2162,9 @@
</None>
<None Include="x64\Debug\Assets\config.ini" />
<None Include="Source\GameLogic\CustomComponent\ButtonRotate.reflectionh" />
<None Include="Source\GameLogic\Benchmark.inl">
<Filter>Header Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Text Include="Source\Core\Graphics\ReadThis!!!!.txt" />
Expand Down
4 changes: 2 additions & 2 deletions Doom3/Source/Component/Rendering/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ dooms::Camera* dooms::Camera::GetMainCamera()
/// </summary>
/// <returns></returns>

math::Matrix4x4 dooms::Camera::GetProjectionMatrix()
math::Matrix4x4 dooms::Camera::GetProjectionMatrix(const bool forceNDCNegativeOneToOne)
{
math::Matrix4x4 result{ nullptr };
if (mProjectionMode == eProjectionType::Perspective)
Expand All @@ -263,7 +263,7 @@ math::Matrix4x4 dooms::Camera::GetProjectionMatrix()
NEVER_HAPPEN;
}

if(dooms::graphics::GraphicsAPIManager::GetCurrentAPIType() == graphics::GraphicsAPI::eGraphicsAPIType::DX11_10)
if(forceNDCNegativeOneToOne == false && dooms::graphics::GraphicsAPIManager::GetCurrentAPIType() == graphics::GraphicsAPI::eGraphicsAPIType::DX11_10)
{
static const math::Matrix4x4 zOffsetForD3D = math::scale(math::Vector3{ 1.0f, 1.0f, 0.5f }) * math::translate(math::Vector3{ 0, 0, 1.0f });
result = zOffsetForD3D * result;
Expand Down
8 changes: 4 additions & 4 deletions Doom3/Source/Component/Rendering/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace dooms
Camera& operator=(Camera&&) noexcept = delete;

D_PROPERTY()
graphics::DefferedRenderingFrameBuffer mDefferedRenderingFrameBuffer;
graphics::DefferedRenderingFrameBuffer mDeferredRenderingFrameBuffer{};

D_PROPERTY()
UINT32 CameraIndexInCullingSystem;
Expand Down Expand Up @@ -166,7 +166,7 @@ namespace dooms
/// this function will be called at every frame
/// </summary>
/// <returns></returns>
math::Matrix4x4 GetProjectionMatrix();
math::Matrix4x4 GetProjectionMatrix(const bool forceNDCNegativeOneToOne = false);
/// <summary>
/// this function will be called at every frame
/// </summary>
Expand All @@ -179,9 +179,9 @@ namespace dooms
const math::Vector3 up = transform->up();
return math::lookAt(pos, pos + forward, up);
}
FORCE_INLINE math::Matrix4x4 GetViewProjectionMatrix()
FORCE_INLINE math::Matrix4x4 GetViewProjectionMatrix(const bool forceNDCNegativeOneToOne = false)
{
return GetProjectionMatrix() * GetViewMatrix();
return GetProjectionMatrix(forceNDCNegativeOneToOne) * GetViewMatrix();
}

NO_DISCARD math::Vector3 NDCToScreenPoint(const math::Vector3& ndcPoint);
Expand Down
2 changes: 1 addition & 1 deletion Doom3/Source/Component/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ namespace dooms
SetPosition(worldPos);


SetRotation(math::Quaternion(angle * math::DEGREE_TO_RADIAN, axis));
SetRotation(math::Quaternion(angle * static_cast<FLOAT32>(math::DEGREE_TO_RADIAN), axis));
}

FORCE_INLINE math::Vector3 TransformDirection(math::Vector3& direction) const noexcept
Expand Down
8 changes: 0 additions & 8 deletions Doom3/Source/Core/DObject/DObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ void dooms::DObjectManager::DestroyAllDObjects(const bool force)
dooms::DObject* const targetDObject = *iterBegin;
targetDObject->SetIsPendingKill();
iterBegin++;

if (force || targetDObject->GetIsNewAllocated())
{
targetDObject->DestroySelfInstantly();

iterBegin = mDObjectsContainer.mDObjectList.begin();
iterEnd = mDObjectsContainer.mDObjectList.end(); // TODO : OPTIMIZATION
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ namespace dooms
if (isFieldOwnerObjectDerivedFromDObject && IsValid(reinterpret_cast<dooms::DObject*>(object)))
{// check if object is struct or class not inheriting DObject
reinterpret_cast<dooms::DObject*>(object)->OnChangedByGUI(dField);
CallFieldDirtyCallback(fieldDAttributeList.GetDirtyCallbackFunctionName(), &dClass, object);
// TODO : FIX THIS. Only Release mode cause bug.
//CallFieldDirtyCallback(fieldDAttributeList.GetDirtyCallbackFunctionName(), &dClass, object);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,8 @@ void dooms::gc::garbageCollectorSolver::StartSweepStage(const eGCMethod gcMethod

for (dooms::DObject* deletedDbject : deletedDObjectList)
{
D_ASSERT(deletedDbject != nullptr);
D_ASSERT(deletedDbject != nullptr); D_DEBUG_LOG(eLogType::D_LOG, "GC Collect Object ( Type Name : %s, DObject Name : %s )", deletedDbject->GetTypeFullName(), deletedDbject->GetDObjectName().c_str());
deletedDbject->DestroySelfInstantly();
D_DEBUG_LOG(eLogType::D_LOG, "GC Collect Object ( Type Name : %s, DObject Name : %s )", deletedDbject->GetTypeFullName(), deletedDbject->GetDObjectName().c_str());
}
}

Expand Down
Loading

0 comments on commit b3e9095

Please sign in to comment.