Minor - Optimise l'accès aux ressources D3D - V14.10.0

Refactorise l'accès aux interfaces Direct3D pour plus de clarté et d'efficacité, en utilisant des accesseurs `const` et en déplaçant certaines fonctions directement dans l'en-tête.

Cela simplifie l'utilisation des ressources D3D et améliore la lisibilité du code.
This commit is contained in:
2025-11-02 01:22:50 +01:00
parent 1a92ac64d7
commit 040d919b69
7 changed files with 31 additions and 79 deletions

View File

@@ -75,20 +75,20 @@ public:
*
* @return Pointer to the ID3D11Device interface.
*/
ID3D11Device* get_device();
ID3D11Device* get_device() const { return device_; };
/**
* @brief Gets the Direct3D device context.
*
* @return Pointer to the ID3D11DeviceContext interface.
*/
ID3D11DeviceContext* get_device_context();
ID3D11DeviceContext* get_device_context() const { return device_context_; };
//XMMATRIX get_projection_matrix(XMMATRIX& projectionMatrix);
IDXGISwapChain* swap_chain;
/**
* Get the swap chain associated with the Direct3D device.
* @return Pointer to the IDXGISwapChain interface.
*/
IDXGISwapChain* get_swap_chain();
IDXGISwapChain* get_swap_chain() const { return swap_chain; };
/**
* Resizes the swap chain to the specified width and height.
* @param width New width of the swap chain.
@@ -100,7 +100,7 @@ public:
*
* @param vsync True to enable vertical sync, false to disable.
*/
void set_vsync(bool vsync);
void set_vsync(bool vsync) { vsync_enabled_ = vsync; };
/**
* Get the projection matrix.
@@ -135,7 +135,10 @@ public:
/**
* Resets the viewport to the default settings.
*/
void reset_viewport();
void reset_viewport() const
{
device_context_->RSSetViewports(1, &viewport_);
}
/**
* Release all Direct3D resources.
@@ -151,11 +154,17 @@ public:
/**
* Turn on the Z-buffer to enable depth.
*/
void turn_z_buffer_on();
void turn_z_buffer_on()const
{
device_context_->OMSetDepthStencilState(depth_stencil_state_, 1);
}
/**
* Turn off the Z-buffer to disable depth.
*/
void turn_z_buffer_off();
void turn_z_buffer_off() const
{
device_context_->OMSetDepthStencilState(depth_disabled_stencil_state_, 1);
}
/**
* Turn on alpha blending for transparency effects.

View File

@@ -69,7 +69,7 @@ inline int size_t_to_int(size_t x)
#define LOG_SHUTDOWN(msg) ((void)0)
#define LOG_INIT(msg) ((void)0)
#define R_LOG_ERROR(result,msg) ((void)0)
#define R_LOG_ERROR(result,msg) ((void)0);
#endif

View File

@@ -3,8 +3,6 @@
#define WIN32_LEAN_AND_MEAN
static bool DEBUG_MODE = true;
#include "Logger.h"
#include "input_class.h"

View File

@@ -555,21 +555,9 @@ void d_3d_class::end_scene()
return;
}
ID3D11Device* d_3d_class::get_device()
void d_3d_class::get_video_card_info(char* description, int& memory)
{
return device_;
}
ID3D11DeviceContext* d_3d_class::get_device_context()
{
return device_context_;
}
void d_3d_class::get_video_card_info(char* cardName, int& memory)
{
strcpy_s(cardName, 128, video_card_description_);
strcpy_s(description, 128, video_card_description_);
memory = video_card_memory_;
return;
}
@@ -583,15 +571,6 @@ void d_3d_class::set_back_buffer_render_target()
return;
}
void d_3d_class::reset_viewport()
{
// Set the viewport.
device_context_->RSSetViewports(1, &viewport_);
return;
}
void d_3d_class::release_resources()
{
LOG_SHUTDOWN("Releasing D3D resources");
@@ -689,11 +668,6 @@ void d_3d_class::reset_resources(int newWidth, int newHeight)
device_context_->OMSetRenderTargets(1, &render_target_view_, depth_stencil_view_);
}
IDXGISwapChain* d_3d_class::get_swap_chain()
{
return swap_chain;
}
void d_3d_class::resize_swap_chain(int newWidth, int newHeight)
{
LOG_INFO("Resizing swap chain to " + std::to_string(newWidth) + "x" + std::to_string(newHeight));
@@ -721,19 +695,6 @@ void d_3d_class::resize_swap_chain(int newWidth, int newHeight)
device_context_->RSSetViewports(1, &viewport_);
}
void d_3d_class::turn_z_buffer_on()
{
device_context_->OMSetDepthStencilState(depth_stencil_state_, 1);
return;
}
void d_3d_class::turn_z_buffer_off()
{
device_context_->OMSetDepthStencilState(depth_disabled_stencil_state_, 1);
return;
}
void d_3d_class::enable_alpha_blending()
{
float blendFactor[4];
@@ -768,11 +729,6 @@ void d_3d_class::disable_alpha_blending()
return;
}
void d_3d_class::set_vsync(bool vsync)
{
vsync_enabled_ = vsync;
}
bool d_3d_class::set_projection_params(int width, int height, float screenDepth, float screenNear)
{
float fieldOfView, screenAspect;

View File

@@ -61,17 +61,16 @@ bool system_class::initialize()
application_->get_direct_3d()->resize_swap_chain(initial_window_width_, initial_window_height_);
}
#ifdef _DEBUG
// initialize imgui
if(DEBUG_MODE)
imgui_manager_ = std::make_shared<imguiManager>();
imgui_manager_->SetApp(application_);
result = imgui_manager_->Initialize(hwnd_, application_->get_direct_3d()->get_device(), application_->get_direct_3d()->get_device_context());
if (!result)
{
imgui_manager_ = std::make_shared<imguiManager>();
imgui_manager_->SetApp(application_);
result = imgui_manager_->Initialize(hwnd_, application_->get_direct_3d()->get_device(), application_->get_direct_3d()->get_device_context());
if (!result)
{
R_FALSE
}
R_FALSE
}
#endif
}
catch (const std::exception& e)
@@ -177,19 +176,8 @@ bool system_class::frame()
R_FALSE
}
if(!input_->IsKeyDown(222))
{
//log the key press
is_debug_key_pressed_ = false;
}
else if (input_->IsKeyDown(222) && !is_debug_key_pressed_)
{
// Log the key release state
is_debug_key_pressed_ = true;
DEBUG_MODE = !DEBUG_MODE;
}
if (DEBUG_MODE)
#ifdef _DEBUG
if (input_->IsKeyDown(DIK_F1))
{
// render ImGui
result = imgui_manager_->ImGuiWidgetRenderer();
@@ -199,6 +187,7 @@ bool system_class::frame()
R_FALSE
}
}
#endif
application_->get_direct_3d()->end_scene();

BIN
x64/Debug/config.txt (Stored with Git LFS)

Binary file not shown.

BIN
x64/Release/config.txt (Stored with Git LFS)

Binary file not shown.