-
Notifications
You must be signed in to change notification settings - Fork 0
Dev/nissekaka directx #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6ef53fc
Added base for DX11 and DX12. Intention is to make an API that can ho…
nissekaka 1cc002a
Merge branch 'develop' of https://github.com/OlleKReutercrona/RuneFor…
nissekaka d5024c4
Added IRenderer to abstract Graphics engines.
nissekaka ccbaa84
Removed Init functions to make sure these objects are never in a non-…
nissekaka e64d2a3
Naming convention + HRESULT
nissekaka 9429e74
Naming convention + HRESULT
nissekaka d939312
Merge branch 'dev/nissekaka-directx' of https://github.com/OlleKReute…
nissekaka d01a584
Removed HRESULT hr where it didn't make sense
nissekaka 93b4ac9
DX11 create params
nissekaka 94ffaf3
Merge branch 'develop' into dev/nissekaka-directx
nissekaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #include "stdafx.h" | ||
| #include "DX11.h" | ||
| #include <stdexcept> | ||
|
|
||
| using namespace Microsoft::WRL; | ||
|
|
||
| RF::DX11::DX11(const DX11CreationParams& params) : | ||
| mWidth(params.width), | ||
| mHeight(params.height) { | ||
| //mClearColour(params.clearColour) { | ||
| if (FAILED(CreateDeviceAndSwapChain(params.hwnd, params.width, params.height))) | ||
| throw std::runtime_error("Failed to create Direct3D 11 device and swap chain."); | ||
|
|
||
| if (FAILED(CreateRenderTargetView())) | ||
| throw std::runtime_error("Failed to create Direct3D 11 render target view."); | ||
|
|
||
| SetViewport(mWidth, mHeight); | ||
| } | ||
|
|
||
| RF::DX11::~DX11() { | ||
| } | ||
|
|
||
| HRESULT RF::DX11::CreateDeviceAndSwapChain(const HWND hwnd, const uint32_t width, const uint32_t height) { | ||
| DXGI_SWAP_CHAIN_DESC scd = {}; | ||
| scd.BufferDesc.Width = width; | ||
| scd.BufferDesc.Height = height; | ||
| scd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; | ||
| scd.BufferDesc.RefreshRate.Numerator = 0u; | ||
| scd.BufferDesc.RefreshRate.Denominator = 0u; | ||
| scd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; | ||
| scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; | ||
| scd.SampleDesc.Count = 1u; // Anti-aliasing | ||
| scd.SampleDesc.Quality = 0u; // Anti-aliasing | ||
| scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; | ||
| scd.BufferCount = 1u; // 1 back buffer and 1 front buffer | ||
| scd.OutputWindow = hwnd; | ||
| scd.Windowed = true; | ||
| scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; | ||
| scd.Flags = 0u; | ||
|
OlleKReutercrona marked this conversation as resolved.
|
||
|
|
||
| UINT swapCreateFlags = 0u; | ||
| #ifndef NDEBUG | ||
| swapCreateFlags |= D3D11_CREATE_DEVICE_DEBUG; | ||
| #endif | ||
|
|
||
| return D3D11CreateDeviceAndSwapChain( | ||
| nullptr, | ||
| D3D_DRIVER_TYPE_HARDWARE, | ||
| nullptr, | ||
| swapCreateFlags, | ||
| nullptr, | ||
| 0, | ||
| D3D11_SDK_VERSION, | ||
| &scd, | ||
| &mSwap, | ||
| &mDevice, | ||
| nullptr, | ||
| &mContext | ||
| ); | ||
| } | ||
|
|
||
| HRESULT RF::DX11::CreateRenderTargetView() { | ||
| HRESULT hr = S_OK; | ||
|
|
||
| Microsoft::WRL::ComPtr<ID3D11Resource> backBuffer; | ||
| hr = mSwap->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer); | ||
| if (FAILED(hr)) | ||
| return hr; | ||
|
|
||
| hr = mDevice->CreateRenderTargetView(backBuffer.Get(), nullptr, &mDefaultTarget); | ||
| return hr; | ||
| } | ||
|
|
||
| void RF::DX11::SetViewport(const uint32_t width, const uint32_t height) { | ||
| D3D11_VIEWPORT vp = {}; | ||
| vp.Width = static_cast<FLOAT>(width); | ||
| vp.Height = static_cast<FLOAT>(height); | ||
| vp.MinDepth = 0.0f; | ||
| vp.MaxDepth = 1.0f; | ||
| vp.TopLeftX = 0.0f; | ||
| vp.TopLeftY = 0.0f; | ||
| mContext->RSSetViewports(1u, &vp); | ||
| } | ||
|
|
||
| void RF::DX11::Render(const FrameData&) { | ||
| const FLOAT clearColor[] = { 0.2f, 0.4f, 0.6f, 1.0f }; | ||
|
OlleKReutercrona marked this conversation as resolved.
|
||
| mContext->ClearRenderTargetView(mDefaultTarget.Get(), clearColor); | ||
| mSwap->Present(1u, 0u); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #pragma once | ||
| #include "IRenderer.h" | ||
|
|
||
| #include <wrl.h> | ||
| #include <d3d11.h> | ||
|
|
||
| namespace RF { | ||
| struct DX11CreationParams { | ||
| HWND hwnd; | ||
| uint32_t width; | ||
| uint32_t height; | ||
| //Colour clearColour = { 0.2f, 0.4f, 0.6f, 1.0f }; | ||
| bool startInFullScreen = false; | ||
| }; | ||
|
|
||
| class DX11 : public IRenderer { | ||
| public: | ||
| DX11(const DX11CreationParams& params); | ||
| ~DX11(); | ||
|
|
||
| DX11() = delete; | ||
| DX11(const DX11&) = delete; | ||
| void operator=(const DX11&) = delete; | ||
|
|
||
| virtual void Render(const FrameData& frameData); | ||
| private: | ||
| HRESULT CreateDeviceAndSwapChain(const HWND hwnd, const uint32_t width, const uint32_t height); | ||
| HRESULT CreateRenderTargetView(); | ||
| void SetViewport(const uint32_t width, const uint32_t height); | ||
|
|
||
| uint32_t mWidth; | ||
| uint32_t mHeight; | ||
| //Colour mClearColour; | ||
|
|
||
| Microsoft::WRL::ComPtr<ID3D11Device> mDevice; | ||
| Microsoft::WRL::ComPtr<IDXGISwapChain> mSwap; | ||
| Microsoft::WRL::ComPtr<ID3D11DeviceContext> mContext; | ||
| Microsoft::WRL::ComPtr<ID3D11RenderTargetView> mDefaultTarget; | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det här borde vara en preprocessor check i och med att vi aldrig kommer byta api i runtime