-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bootstrap/dx11 debug shapes #4
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
95d4cd6
Draft of renderer interface
Condzi e636da3
DirectX devices init
Condzi a197097
Immediate mode pipeline
Condzi f9992bb
enable debug mode in DX11
Condzi e859bad
Cool shapes
Condzi 3477d5f
column_major for constants
Condzi 08e562a
No need to zero the vs_out
Condzi e7266f7
Use typedefs for ID3D types
Condzi 39cd1b2
Request D3D 11.1
Condzi b4e85fa
formatting
Condzi 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 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#define RT_LOG_FILE "log.txt" | ||
|
||
#define TEMP_MEM_SIZE RT_MEGABYTES(8) | ||
|
||
namespace rt { | ||
char const static *WIN_NAME = "Raytracing Engine"; | ||
char const static *WIN_CLASS = "rt_engine"; | ||
s64 constexpr static WIN_WIDTH = 1366; | ||
s64 constexpr static WIN_HEIGHT = 768; | ||
bool constexpr static VSYNC = true; | ||
|
||
s64 constexpr static TEMP_MEM_SIZE = RT_MEGABYTES(8); | ||
s64 constexpr static IM_TRIS_COUNT = 1024; | ||
} // namespace rt |
This file contains 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 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,91 @@ | ||
namespace rt { | ||
struct D3d { | ||
::ID3D11Device *device = NULL; | ||
::ID3D11DeviceContext *device_context = NULL; | ||
::IDXGISwapChain *swap_chain = NULL; | ||
::ID3D11RenderTargetView *render_target_view = NULL; | ||
|
||
struct XXC_Pipeline *xxc_pipeline = NULL; | ||
} static gD3d; | ||
|
||
void | ||
gfx_init_or_panic() { | ||
::DXGI_SWAP_CHAIN_DESC const swap_chain_descr = { | ||
.BufferDesc = { | ||
.RefreshRate = { | ||
.Numerator = 0, | ||
.Denominator = 1 | ||
}, | ||
.Format = DXGI_FORMAT_B8G8R8A8_UNORM, | ||
}, | ||
|
||
.SampleDesc = { | ||
.Count = 1, | ||
.Quality = 0 | ||
}, | ||
|
||
.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, | ||
.BufferCount = 1, | ||
.OutputWindow = gWin32_Window.hWnd, | ||
.Windowed = true, // @Note: for fullscreen, set to false & set width and height | ||
.SwapEffect = DXGI_SWAP_EFFECT_DISCARD | ||
}; | ||
|
||
::UINT flags = D3D11_CREATE_DEVICE_SINGLETHREADED; | ||
|
||
#if HANDMADE_INTERNAL | ||
flags |= D3D11_CREATE_DEVICE_DEBUG; | ||
#endif | ||
|
||
::D3D_FEATURE_LEVEL feature_level; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On all current hardware you can set to 11_1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
::HRESULT hr; | ||
hr = ::D3D11CreateDeviceAndSwapChain( | ||
NULL, | ||
D3D_DRIVER_TYPE_HARDWARE, | ||
NULL, | ||
flags, | ||
NULL, | ||
0, | ||
D3D11_SDK_VERSION, | ||
&swap_chain_descr, | ||
&gD3d.swap_chain, | ||
&gD3d.device, | ||
&feature_level, | ||
&gD3d.device_context | ||
); | ||
|
||
check_(gD3d.swap_chain); | ||
check_(gD3d.device); | ||
check_(gD3d.device_context); | ||
d3d_check_hresult_(hr); | ||
|
||
::ID3D11Texture2D *framebuffer; | ||
hr = gD3d.swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&framebuffer); | ||
d3d_check_hresult_(hr); | ||
|
||
hr = gD3d.device->CreateRenderTargetView(framebuffer, 0, &gD3d.render_target_view); | ||
d3d_check_hresult_(hr); | ||
|
||
d3d_safe_release_(framebuffer); | ||
|
||
gfx_im_init_or_panic(); | ||
} | ||
|
||
void | ||
gfx_render() { | ||
/* clear the back buffer to cornflower blue for the new frame */ | ||
float background_colour[4] = { 0x64 / 255.0f, 0x95 / 255.0f, 0xED / 255.0f, 1.0f }; | ||
gD3d.device_context->ClearRenderTargetView(gD3d.render_target_view, background_colour); | ||
|
||
|
||
// Tell the output merger to use our render target | ||
gD3d.device_context->OMSetRenderTargets(1, &gD3d.render_target_view, NULL); | ||
|
||
gfx_im_flush(); | ||
|
||
// Present | ||
gD3d.swap_chain->Present( VSYNC?1:0, 0 ); | ||
} | ||
} // namespace rt | ||
|
||
#include "im_pipeline.cxx" |
This file contains 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,46 @@ | ||
#include "im_pipeline.hxx" | ||
|
||
|
||
#define d3d_safe_release_(x) \ | ||
do { \ | ||
if (x) { \ | ||
x->Release(); \ | ||
x = NULL; \ | ||
} \ | ||
} while(false) | ||
|
||
#define d3d_check_hresult_(hr) \ | ||
do { \ | ||
if (FAILED(hr)) { \ | ||
String const error_str = os_error_to_string(hr); \ | ||
\ | ||
logf("[D3D] !!! %s:%d -- ", __FILE__, (s32)__LINE__); \ | ||
logf("%.*s\n", (s32)error_str.count, error_str.data); \ | ||
\ | ||
errf("Failed to initialize DirectX 11."); \ | ||
} \ | ||
} while(false) | ||
|
||
namespace rt { | ||
u32 constexpr COLOR_RED = 0xff0000ff; | ||
u32 constexpr COLOR_GREEN = 0x00ff00ff; | ||
u32 constexpr COLOR_BLUE = 0x0000ffff; | ||
|
||
// XX - x and y position | ||
// C - 32-bit color | ||
struct Vertex_XXC { | ||
Vec2 position; | ||
u32 color; | ||
}; | ||
|
||
struct alignas(16) Constants { | ||
Mat4x4 projection; | ||
Mat4x4 camera; | ||
}; | ||
|
||
void | ||
gfx_init_or_panic(); | ||
|
||
void | ||
gfx_render(); | ||
} // namespace rt; |
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.
Consider creating typedefs of ID3D types, ex.
typedef ID3D11Device IDevice
to avoid interface versioning. D3D have various updates with increasing numbers as sufixes (from previous example, newest device isID3D11Device5
from d3d11_4.h) to help in maintaining code. Also consider using COM smart pointers to avoid memory leaks and manual managment of interface counters (Microsoft way of handling lifetime of the interface).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.
Done