-
Notifications
You must be signed in to change notification settings - Fork 11
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
Draft
AR-DEV-1
wants to merge
19
commits into
Redot-Engine:master
Choose a base branch
from
AR-DEV-1:rendering-hardware-abstraction
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6458806
Start workin' on RHI
AR-DEV-1 b58cba3
Idk how I missed these, they coulda been major security vulnerabilities
AR-DEV-1 7b92c6b
Do what CodeRabbit said & add Wayland support (still doesn't work)
AR-DEV-1 64c0d2f
Fix includes
AR-DEV-1 c955c7d
Add uniform management
AR-DEV-1 eebea86
Add texture loadin' support
AR-DEV-1 b433315
Add framebuffer handles, render targets & dynamic/transient buffers s…
AR-DEV-1 436c405
Add depth & stencil testing, Alpha blending modes, dedicated sampler …
AR-DEV-1 d1694ef
Draco is 3D!
AR-DEV-1 64615cd
Add camera controller & remove all std imports (replaced by the tradi…
AR-DEV-1 27f83bc
Apply suggestions
AR-DEV-1 80af026
Fix issues
AR-DEV-1 43141d2
Minor improvements & fixes
AR-DEV-1 b448c46
Add mesh abstraction + compilation of shaders when building
AR-DEV-1 97d97ee
Add transform system
AR-DEV-1 c2c80b5
Upgrade render pipeline architecture (material + RenderGraph refactor)
AR-DEV-1 2f2f08c
Start working on Quad/Sprite renderer
AR-DEV-1 e43bcea
Merge branch 'master' of https://github.com/Redot-Engine/DraconicEngi…
AR-DEV-1 b117660
Work on QuadRenderer
AR-DEV-1 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> | ||
|
|
||
| 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.
|
||
| } | ||
|
|
||
| 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.
Outdated
|
||
|
|
||
| #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; | ||
| } | ||
|
AR-DEV-1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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); | ||
|
AR-DEV-1 marked this conversation as resolved.
Outdated
|
||
|
|
||
| draco::rhi::end_frame(); | ||
| } | ||
|
|
||
| draco::rhi::shutdown(); | ||
|
|
||
| SDL_DestroyWindow(window); | ||
| SDL_Quit(); | ||
| return 0; | ||
| } | ||
|
|
||
| // Fun fact: AR literally went mad & tis is the result | ||
|
AR-DEV-1 marked this conversation as resolved.
Outdated
|
||
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) | ||
|
AR-DEV-1 marked this conversation as resolved.
Outdated
|
||
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.