A modern C++23 DirectX 11 rendering engine built with a focus on clean architecture, performance, and extensibility. DXEngine provides a robust foundation for 3D graphics applications on Windows, featuring a modular bindable system, comprehensive error handling, and an immediate mode GUI.
- Modern C++23: Leverages the latest C++ features for clean, efficient code
- DirectX 11 Rendering: Hardware-accelerated 3D graphics with full D3D11 pipeline support
- ImGui Integration: Immediate mode GUI for debugging and tool development
- Modular Architecture: Component-based system with clear separation of concerns
- Exception Safety: Comprehensive error handling with custom exception hierarchy
- Bindable Architecture: Flexible, type-safe resource binding system
- Drawable Objects: Base classes for renderable geometry with transform support
- HLSL Shader Support: Vertex and pixel shader compilation and management
- Buffer Management: Vertex, index, and constant buffer abstractions
- Device State Management: Automatic handling of device loss and recovery
- DXGI Debug Integration: Detailed DirectX debug information and error reporting
- Step Timer: High-resolution timing for frame rate control and animation
- Resource Management: RAII-compliant resource handling with smart pointers
- Cross-Compiler Support: Works with MSVC, GCC, and Clang
DXEngine is built around several key architectural patterns:
The core of the rendering system is the bindable architecture, where render states, shaders, and resources implement a common bindable
interface. This allows for:
- Type-safe resource binding
- Easy state management
- Flexible render pipeline configuration
- Minimal API calls through intelligent state caching
3D objects inherit from the drawable
base class, providing:
- Automatic resource binding during rendering
- Transform matrix management
- Update lifecycle for animations
- Static resource sharing for efficiency
Custom exception classes provide detailed error information:
engine_exception
: Base exception with file/line informationhr_exception
: Windows HRESULT error handlingrenderer::exception
: DirectX-specific errorsdevice_removed_exception
: Graphics device recovery
- Operating System: Windows 10/11 (64-bit)
- Graphics: DirectX 11 compatible graphics card
- Compiler:
- MSVC 2022 (recommended)
- GCC 9.0+ with MinGW
- Clang 10.0+
- CMake: 3.30 or higher
- vcpkg: Package manager for C++ libraries
- Visual Studio 2022: Recommended IDE (Community edition sufficient)
git clone https://github.com/yourusername/DXEngine.git
cd DXEngine
Ensure vcpkg is installed and the VCPKG_ROOT
environment variable is set:
# Example Windows setup
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
./vcpkg integrate install
Set the environment variable:
set VCPKG_ROOT=C:\path\to\vcpkg
Dependencies are automatically managed through vcpkg configuration:
# Dependencies will be installed automatically during CMake configuration
# Current dependencies:
# - imgui with dx11-binding and win32-binding features
mkdir build
cd build
cmake ..
cmake --build . --config Release
# From the build directory
./bin/dx_engine.exe
DXEngine/
├── include/ # Header files
│ ├── renderer/ # Rendering system headers
│ │ ├── bindable/ # Bindable resource abstractions
│ │ └── drawable/ # Drawable object system
│ ├── app.h # Main application class
│ ├── engine_exception.h # Exception hierarchy
│ └── stdafx.h # Precompiled header
├── src/ # Source files
│ ├── renderer/ # Rendering system implementation
│ ├── app.cpp # Application implementation
│ └── main.cpp # Entry point
├── shaders/ # HLSL shader files
│ ├── vertex_shader.vs.hlsl
│ └── pixel_shader.ps.hlsl
├── CMakeLists.txt # CMake configuration
├── vcpkg.json # Dependency configuration
└── README.md # This file
Main application class handling:
- Window creation and management
- Win32 message pump
- Initialization and shutdown
- Frame timing and main loop
Core rendering system providing:
- D3D11 device and context management
- Swap chain handling
- Render target management
- Drawing operations
Abstract base for all bindable resources:
- Vertex/Index buffers
- Shaders (vertex, pixel)
- Constant buffers
- Input layouts
- Render states
Base class for renderable objects:
- Transform matrix management
- Automatic resource binding
- Update lifecycle
- Static resource optimization
- Create a new class inheriting from
drawable_base<YourClass>
- Implement required virtual methods:
transform()
: Return current transform matrixupdate()
: Update object state per frame
- Initialize bindable resources in constructor
- Register with renderer for drawing
- Inherit from
bindable
base class - Implement
bind(renderer& rndr)
method - Use protected helper methods to access renderer internals
- Follow RAII principles for resource management
- Add HLSL files to the
shaders/
directory - Update
shaders/CMakeLists.txt
to include new shaders - Create corresponding bindable wrappers
- Implement shader compilation and management
The build system supports various configuration options:
# Debug build with full debugging information
cmake -DCMAKE_BUILD_TYPE=Debug ..
# Release build with optimizations
cmake -DCMAKE_BUILD_TYPE=Release ..
# Specify custom vcpkg toolchain
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake ..
- MSVC:
/W4 /MP /std:c++latest /utf-8
- GCC/Clang:
-Wall -Wextra -pedantic -std=c++1z
- Static bindables are cached and shared between objects
- Minimal state changes through intelligent binding
- Batch rendering for similar objects
- Efficient memory management with smart pointers
- RAII throughout the codebase
- Smart pointers for automatic cleanup
- COM pointer management with WRL
- Minimal dynamic allocations in hot paths
- DXGI debug layer integration for detailed D3D error reporting
- Custom exception hierarchy with file/line information
- ImGui integration for runtime debugging
- Comprehensive error handling and recovery
- Device Lost: Handled automatically with device recovery
- Shader Compilation: Check HLSL syntax and target profile
- Resource Binding: Verify bindable order and compatibility
- Performance: Use PIX or similar tools for GPU profiling
- Follow existing naming conventions (snake_case for variables/functions)
- Use modern C++ idioms and RAII
- Comprehensive documentation for public APIs
- Exception safety guarantees
- Fork the repository
- Create a feature branch
- Implement changes with tests
- Submit pull request with detailed description
This project is licensed under the MIT License - see the LICENSE file for details.
Tessa Power - [email protected]
- Microsoft DirectX team for excellent documentation
- ImGui developers for the immediate mode GUI framework
- vcpkg team for dependency management
- The C++ community for modern language features
Built with ❤️ and modern C++