Repository navigation
Add rendering stuff, cross-platform support, camera controller & SDL input logic #16
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 1 commit
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
6458806
Start workin' on RHI
DaveTheEggman b58cba3
Idk how I missed these, they coulda been major security vulnerabilities
DaveTheEggman 7b92c6b
Do what CodeRabbit said & add Wayland support (still doesn't work)
DaveTheEggman 64c0d2f
Fix includes
DaveTheEggman c955c7d
Add uniform management
DaveTheEggman eebea86
Add texture loadin' support
DaveTheEggman b433315
Add framebuffer handles, render targets & dynamic/transient buffers s…
DaveTheEggman 436c405
Add depth & stencil testing, Alpha blending modes, dedicated sampler …
DaveTheEggman d1694ef
Draco is 3D!
DaveTheEggman 64615cd
Add camera controller & remove all std imports (replaced by the tradi…
DaveTheEggman 27f83bc
Apply suggestions
DaveTheEggman 80af026
Fix issues
DaveTheEggman 43141d2
Minor improvements & fixes
DaveTheEggman b448c46
Add mesh abstraction + compilation of shaders when building
DaveTheEggman 97d97ee
Add transform system
DaveTheEggman c2c80b5
Upgrade render pipeline architecture (material + RenderGraph refactor)
DaveTheEggman 2f2f08c
Start working on Quad/Sprite renderer
DaveTheEggman e43bcea
Merge branch 'master' of https://github.com/Redot-Engine/DraconicEngi…
DaveTheEggman b117660
Work on QuadRenderer
DaveTheEggman 463ab5e
QuadRenderer finally works!
DaveTheEggman e148291
Merge branch 'Redot-Engine:master' into rendering-hardware-abstraction
DaveTheEggman 6dcdc0f
Small stuff
DaveTheEggman 1046f1d
Apply some suggestions
DaveTheEggman 833d9a8
Forgot these
DaveTheEggman d28e09f
Minor fixes
DaveTheEggman 62db8b7
Minor fixes
DaveTheEggman 7183e07
Fix incorrect declaration
DaveTheEggman 1065b03
Fix Wayland
DaveTheEggman 570b52a
Wayland works!
DaveTheEggman 05c8310
Compile shaderc
DaveTheEggman cb36c8f
Remove sync window SDL loop so Draco may run on Windows [skip ci]
DaveTheEggman 4540c3a
PR cleanup
DaveTheEggman c40f59c
Update CMake version
DaveTheEggman abad3ef
Add missing include
DaveTheEggman e94b9de
Add caching to CI
DaveTheEggman dd90c75
Merge branch 'master' into rendering-hardware-abstraction
DaveTheEggman ff5480f
Fix compiler error
DaveTheEggman f8c737c
Apply suggestions
DaveTheEggman 5862d99
Merge branch 'master' into rendering-hardware-abstraction
DaveTheEggman 9b61dd6
Use our own types & constants
DaveTheEggman 3b6f166
Merge branch 'master' into rendering-hardware-abstraction
DaveTheEggman c6007b8
Cleanup + improvements
DaveTheEggman 5373a78
Merge branch 'Redot-Engine:master' into rendering-hardware-abstraction
DaveTheEggman e79fa0b
Fix errors
DaveTheEggman de86d2c
Apply some suggestions
DaveTheEggman e720027
Code cleanup
DaveTheEggman b0e9cd2
Address some of Jon's concerns
DaveTheEggman 4abe47d
Merge branch 'master' into rendering-hardware-abstraction
DaveTheEggman 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| add_modules_library(definitions) | ||
| add_modules_library(math) | ||
| target_link_libraries(math PUBLIC definitions) | ||
| add_modules_library(filesystem) | ||
| target_link_libraries(math PUBLIC definitions) | ||
| target_link_libraries(filesystem PUBLIC definitions) |
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,36 @@ | ||
| module; | ||
|
|
||
| import std; | ||
|
|
||
| module core.filesystem; | ||
|
|
||
| namespace draco::filesystem | ||
| { | ||
| std::vector<std::uint8_t> load_binary(const std::string& path) | ||
| { | ||
| // Open at the end (ate) to get size and in binary mode | ||
| std::ifstream file(path, std::ios::binary | std::ios::ate); | ||
|
|
||
| if (!file.is_open()) { | ||
| std::println("Error: Could not open file at: {}", path); | ||
| // Return an empty vector | ||
| return {}; | ||
| } | ||
|
|
||
| std::streamsize size = file.tellg(); | ||
| if (size <= 0) { | ||
| std::println("Error: File is empty or unreadable: {}", path); | ||
| return {}; | ||
| } | ||
|
|
||
| file.seekg(0, std::ios::beg); | ||
|
|
||
| std::vector<std::uint8_t> buffer(static_cast<std::size_t>(size)); | ||
| if (file.read(reinterpret_cast<char*>(buffer.data()), size)) { | ||
| return buffer; | ||
| } | ||
|
|
||
| std::println("Error: Failed to read file contents: {}", path); | ||
| return {}; | ||
| } | ||
| } |
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,9 @@ | ||
| export module core.filesystem; | ||
|
|
||
| import std; | ||
|
|
||
| export namespace draco::filesystem | ||
| { | ||
| // Returns a buffer of the file data | ||
| std::vector<std::uint8_t> load_binary(const std::string& path); | ||
| } |
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,133 @@ | ||
| import std; | ||
|
|
||
| #include <SDL3/SDL.h> | ||
| #include <bgfx/bgfx.h> | ||
| #include <bx/math.h> | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| import core.filesystem; | ||
|
|
||
| import rendering.rhi; | ||
| import rendering.rhi.vertex; | ||
|
|
||
| int main(int argc, char* argv[]) | ||
| { | ||
| if (!SDL_Init(SDL_INIT_VIDEO)) { | ||
| std::println("SDL init failed: {}", SDL_GetError()); | ||
| return -1; | ||
| } | ||
|
|
||
| SDL_Window* window = SDL_CreateWindow( | ||
| "Draconic Engine", | ||
| 1280, 720, | ||
| SDL_WINDOW_RESIZABLE | ||
| ); | ||
|
|
||
| if (!window) { | ||
| std::println("Failed to create window: {}", SDL_GetError()); | ||
| return -1; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| const char* driver = SDL_GetCurrentVideoDriver(); | ||
| std::println("Driver: {}", driver ? driver : "Unknown"); | ||
|
|
||
| void* nwh = nullptr; // Native window handle | ||
| void* ndt = nullptr; // Native display type | ||
|
|
||
| #if defined(__linux__) | ||
|
|
||
| SDL_PropertiesID props = SDL_GetWindowProperties(window); | ||
|
|
||
| if (driver && std::string_view(driver) == "x11") | ||
| { | ||
| ndt = SDL_GetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, nullptr); // Get the X11 display pointer | ||
| nwh = (void*)(uintptr_t)SDL_GetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0); // Get the X11 window number and cast it to a pointer | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| #endif | ||
|
|
||
| if (!nwh) { | ||
| std::println("Failed to get native window handle"); | ||
| return -1; | ||
| } | ||
|
|
||
| if(!ndt) { | ||
| std::println("Failed to get native display type"); | ||
| return -1; | ||
| } | ||
|
|
||
| // Init the RHI with the native window handle and initial size | ||
| if (!draco::rhi::init(ndt, nwh, 1280, 720)) { | ||
| std::println("Failed to initialize RHI"); | ||
| SDL_DestroyWindow(window); | ||
| SDL_Quit(); | ||
| return -1; | ||
| } | ||
|
|
||
| // Geometry data for a triangle to test rendering | ||
| // It includes both positions & colors | ||
| draco::rhi::PosColorVertex triangle[] = { | ||
| { 0.0f, 0.5f, 0.0f, 0xff0000ff }, | ||
| { 0.5f, -0.5f, 0.0f, 0xff00ff00 }, | ||
| { -0.5f, -0.5f, 0.0f, 0xffff0000} | ||
| }; | ||
|
|
||
| auto vbh = draco::rhi::create_vertex_buffer(triangle, sizeof(triangle)); | ||
|
|
||
| // Load the vertex & fragment shaders | ||
| auto vs_data = draco::filesystem::load_binary("vs_triangle.bin"); | ||
| auto fs_data = draco::filesystem::load_binary("fs_triangle.bin"); | ||
|
|
||
| // If the path is empty, return an error | ||
| if (vs_data.empty() || fs_data.empty()) { | ||
| std::println("Failed to load shaders"); | ||
| std::println("Workin' dir: {}", std::filesystem::current_path().string()); | ||
| return -1; | ||
| } | ||
|
This conversation was marked as resolved.
Resolved
|
||
|
|
||
| auto vsh = draco::rhi::create_shader(vs_data.data(), (uint32_t)vs_data.size()); | ||
| auto fsh = draco::rhi::create_shader(fs_data.data(), (uint32_t)fs_data.size()); | ||
|
|
||
|
|
||
| // TODO: Expose our own macros for the state flags instead of using bgfx's directly, tis is just for testin' | ||
| auto pipeline = draco::rhi::create_pipeline({vsh, fsh, (0 | ||
| | BGFX_STATE_WRITE_RGB | ||
| | BGFX_STATE_WRITE_A | ||
| | BGFX_STATE_MSAA | ||
| | BGFX_STATE_PT_TRISTRIP)}); | ||
|
|
||
| bool running = true; | ||
|
|
||
| while (running) | ||
| { | ||
| SDL_Event event; | ||
| while (SDL_PollEvent(&event)) | ||
| { | ||
| if (event.type == SDL_EVENT_QUIT) | ||
| running = false; | ||
| } | ||
|
|
||
| int w, h; | ||
| SDL_GetWindowSize(window, &w, &h); | ||
|
|
||
| draco::rhi::resize(uint16_t(w), uint16_t(h)); | ||
|
|
||
| draco::rhi::begin_frame(); | ||
|
|
||
| draco::rhi::RenderPacket packet{}; | ||
| packet.vertex_buffer = vbh; | ||
| packet.pipeline = pipeline; | ||
| bx::mtxIdentity(packet.model); | ||
|
|
||
| draco::rhi::submit(packet, 0); | ||
|
This conversation was marked as resolved.
Resolved
|
||
|
|
||
| draco::rhi::end_frame(); | ||
| } | ||
|
|
||
| draco::rhi::shutdown(); | ||
|
|
||
| SDL_DestroyWindow(window); | ||
| SDL_Quit(); | ||
| return 0; | ||
| } | ||
|
|
||
| // Fun fact: AR literally went mad & tis is the result | ||
|
This conversation was marked as resolved.
Resolved
|
||
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,3 @@ | ||
| add_modules_library(rhi SHARED) | ||
| target_sources(rhi PRIVATE rhi/rhi_bgfx.cpp rhi/vertex.cppm) | ||
| target_link_libraries(rhi PUBLIC core bgfx bx) | ||
|
This conversation was marked as resolved.
Resolved
|
||
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,46 @@ | ||
| export module rendering.rhi; | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| export namespace draco::rhi | ||
| { | ||
| using BufferHandle = uint16_t; | ||
| using PipelineHandle = uint16_t; | ||
| using ShaderHandle = uint16_t; | ||
| using ViewID = uint16_t; | ||
|
|
||
| struct RenderPacket | ||
| { | ||
| uint64_t sort_key; | ||
|
|
||
| BufferHandle vertex_buffer; | ||
| BufferHandle index_buffer; | ||
| PipelineHandle pipeline; | ||
|
|
||
| float model[16]; | ||
| uint32_t draw_tags; | ||
| }; | ||
|
|
||
| struct PipelineDesc | ||
| { | ||
| ShaderHandle vs; | ||
| ShaderHandle fs; | ||
| uint64_t state; | ||
| }; | ||
|
|
||
| bool init(void* display_type, void* window_handle, uint16_t width, uint16_t height); | ||
| void shutdown(); | ||
|
|
||
| void resize(uint16_t width, uint16_t height); | ||
|
|
||
| ShaderHandle create_shader(const void* data, uint32_t size); | ||
| PipelineHandle create_pipeline(const PipelineDesc&); | ||
|
|
||
| BufferHandle create_vertex_buffer(const void* data, uint32_t size); | ||
| BufferHandle create_index_buffer(const void* data, uint32_t size); | ||
|
|
||
| void submit(const RenderPacket&, ViewID); | ||
|
|
||
| void begin_frame(); | ||
| void end_frame(); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.