48 Commits

Author SHA1 Message Date
2e33adf4a9 Minor - Améliore la gestion des entités ImGui - V14.9.0
Optimizes entity management in ImGui by deferring updates to the entity list until necessary.

Changes include:
- Sets the entity list as dirty upon adding or deleting entities to ensure the list is only updated when needed
- Changes the type of entity ID stored in CachedEntity
- Adjusts ImGui window size
2025-10-24 17:47:54 +02:00
c67a805bd7 Minor - Améliore la gestion des entités ImGui - V14.8.0
Optimizes entity list updates in the ImGui interface by caching entity names and IDs.

This reduces unnecessary string operations during rendering and improves performance, especially when dealing with a large number of entities.

The initial ImGui window size has also been reduced for performance reasons.
2025-10-24 12:00:26 +02:00
cb234f64f0 Patch - Config file change - V14.7.1
Config file change
2025-10-16 18:49:09 +02:00
5ab98c9a0a Minor - Ajoute le culling par la lumière du soleil - V14.7.0
Implémente un système de culling basé sur la position de la lumière du soleil pour améliorer les performances du rendu des ombres.

Crée un thread dédié au culling des objets non visibles par la lumière du soleil.
Ajoute une structure de frustum spécifique au culling par la lumière du soleil.
Modifie le RenderComponent pour suivre si un objet est visible par la lumière du soleil.
2025-10-14 18:45:57 +02:00
37bba7866c Patch - Fix White Shadow Map - V14.6.2
Exclut le skysphere du rendu de la shadowmap.
Supprime le code inutile de la caméra principale.
2025-10-14 15:18:21 +02:00
ebbbd181e3 Patch - Simplifie la gestion des erreurs - V14.6.1
Remplace les blocs if/else par une macro R_LOG_ERROR pour une gestion plus concise et uniforme des erreurs lors de l'initialisation des objets.

Améliore la lisibilité du code et réduit la duplication.
2025-10-14 14:12:34 +02:00
ba7d0ca27e Minor - Implémente le rendu des ombres - V14.6.0
Ajoute la possibilité de rendre une shadow map pour les objets de la scène.
Supprime la dépendance de la texture du depth shader et ajoute une option pour caster les ombres sur les RenderComponents.
Modifie la taille de la fenêtre dans l'imgui.ini
2025-10-14 13:33:30 +02:00
13fc189ee8 Patch - Adjusts UI and fixes a stats update call. - V14.5.36
Fixes an issue where the stats update function was not being called correctly, ensuring accurate and up-to-date information is displayed.
2025-10-13 11:26:36 +02:00
af5473f6e3 Patch - Uses degree conversion macro - V14.5.35
Replaces direct calculations of radians to degrees with a macro.

This change centralizes the conversion factor, enhancing code
readability and maintainability. It also removes a duplicate
definition of the same macro.
2025-10-10 18:13:49 +02:00
526b38eb4f Patch - Fixes object list item labeling issue - V14.5.34
Avoids duplicated ImGui labels in the object list by adding the entity ID to the item label.

Also, corrects ImGui layout issues, preventing window overlap.
2025-10-10 17:53:49 +02:00
295b7354d9 Patch - Improves camera controls and movement. - V14.5.33
Refactors camera input handling for smoother and more intuitive control.

This change introduces a dedicated CameraInput structure and updates the
camera class to use it for movement and rotation based on user input.
It removes the old position class camera related logic and integrates mouse
delta for precise rotation control and scroll wheel for speed adjustments.

Updates ImGui layout to reflect the new size for the docked space.
2025-10-10 17:16:10 +02:00
b31b242775 Patch - Adds camera input handling - V14.5.32
Adds a system for managing camera input using a dedicated
CameraInput struct and updates the camera class to process
these inputs. This allows for more flexible and controlled
camera movement.
2025-10-10 15:31:39 +02:00
7c6562719f Patch - Adds utility and improves error handling - V14.5.31
Adds a utility function to retrieve key states for a given container of keys, enhancing input processing capabilities.

Improves error handling by adding more logging for render failures, giving the development team better insights into potential issues and aiding debugging efforts.
2025-10-10 12:46:13 +02:00
00339aa6c2 Patch - Improves code and UI for better engine stability - V14.5.30
Addresses minor issues across the engine to improve stability and UI.

- Updates ImGui window size for better rendering
- Adds macro for boolean returns (R_TRUE and R_FALSE)
- Adds missing includes and removes unused code
- Updates shader code to use the new macros and improve readability
2025-10-10 00:32:19 +02:00
2b8e222d7c Patch - Refactors logging and adds macro header - V14.5.29
This commit refactors the logging system by replacing direct calls to the Logger class with macros. This improves code readability and maintainability by providing a consistent and concise way to log messages throughout the engine.

The 'macro.h' header file is added and included in multiple system classes to define these logging macros, centralizing logging functionality.

Additionally, error handling is improved in imguiManager::IncrementBuildVersionInConfig by logging specific errors during file operations.
2025-10-09 18:47:33 +02:00
7c5a6435bb Patch - Adds macro for simplified logging - V14.5.28
Introduces a macro to streamline logging, enhancing code readability and maintainability.

The new macro replaces direct Logger calls with more concise and expressive `LOG_INFO`, `LOG_ERROR` etc. calls, reducing boilerplate code and improving consistency in logging practices across the engine.
2025-10-09 16:58:48 +02:00
fe77100612 Patch - Updates build version patch number - V14.5.27
Increments the build version patch number to reflect the latest changes.

This ensures accurate version tracking for the engine.
2025-10-08 19:50:39 +02:00
985e4de77d Refactors CI notification to use JSON payload
Updates the CI notification process to send a JSON payload to the notification service, instead of constructing the JSON string directly in the Jenkinsfile. This improves readability, maintainability, and simplifies data handling for both success and failure scenarios. It also allows for easier extension of the data being sent in the future.
2025-10-08 19:43:58 +02:00
b1ba23f9c0 Updates CI notification in Jenkinsfile
Updates the Jenkinsfile to ensure proper JSON formatting for the
list of artifact URLs passed to the CI notification service.
This ensures that the recipient correctly interprets the download links.
2025-10-08 18:56:15 +02:00
884db4877e Updates parameter descriptions and JSON construction
Updates descriptions of Jenkins parameters for clarity.

Refactors the construction of the JSON string containing URLs to
improve readability.
2025-10-08 18:51:12 +02:00
38569b18a7 Jenkins Test #18 2025-10-08 18:45:26 +02:00
aa8e5c0782 Jenkins Test #17 2025-10-08 18:41:45 +02:00
6680e4689b Jenkins Test #16 2025-10-08 18:30:36 +02:00
a2dc31f49c Jenkins Test #15 2025-10-08 18:23:09 +02:00
fc9a4bdc47 Jenkins Test #14 2025-10-08 18:17:33 +02:00
4922305921 Jenkins Test #13 2025-10-08 18:12:35 +02:00
14c07f8750 Jenkins Test #12 2025-10-08 18:10:28 +02:00
2f5a970a4e Jenkins Test #11 2025-10-08 18:06:27 +02:00
6667a57585 Jenkins Test #10 2025-10-08 18:02:19 +02:00
9da4a5e852 Jenkins Test #9 2025-10-08 18:00:12 +02:00
871d7c8265 Jenkins Test #8 2025-10-08 17:53:48 +02:00
3352f2afa7 Jenkins Test #7 2025-10-08 17:28:14 +02:00
715955ef6a Jenkins Test #6 2025-10-08 17:16:35 +02:00
90a43254f3 Jenkins Test #5 2025-10-08 17:11:48 +02:00
f1db564fb3 Jenkins Test #4 2025-10-08 17:09:23 +02:00
97b5483cc9 Test Jenkins #3 2025-10-08 16:32:16 +02:00
ad056fa2a8 Test Jenkins #2 2025-10-08 16:29:03 +02:00
1bdcd5cd1b Jenkins Test 2025-10-08 16:26:27 +02:00
467b357620 Patch - Refactors build and package stages for parallelism - V14.5.5
Improves build and package processes by introducing parallel execution for debug and release configurations.

This change reduces overall execution time by building and packaging debug and release versions concurrently.
2025-10-08 16:17:15 +02:00
0368276fbf Patch - Updates build version to 14.5.4 - V14.5.4
Updates the major, minor, and patch version numbers.

This reflects the latest iteration of the software, keeping the version information current.
2025-10-08 15:38:57 +02:00
9515b18d1e Patch - Packages builds and updates archiving - V14.5.3
Packages debug and release builds into ZIP archives.

Updates artifact archiving to include only the ZIP packages,
rather than individual executables and DLLs. This simplifies
the artifact management process and reduces storage space.
2025-10-08 15:01:52 +02:00
d131c78a59 Actualiser Jenkinsfile 2025-10-08 12:51:05 +00:00
56389b5dee Ajouter Jenkinsfile 2025-10-08 12:46:49 +00:00
389cde97c2 Minor - Adds target FPS control to engine settings - V14.5.0
Adds functionality to control the target FPS of the engine via the ImGui settings panel.

This includes:
- Adding target FPS variables and accessors in the application class.
- Adding a set_target_fps function to the fps_limiter class.
- Updating the ImGui engine settings panel to include a target FPS setting.
- Modifying the main loop to make use of the fps limiter and the engine target FPS.
2025-10-01 16:58:37 +02:00
0e41fb0ec9 Patch - Start Implementing FPS Limiter - V14.4.1
Adds an FPS limiter to control the framerate, preventing excessive resource usage and providing a more consistent experience.

Removes the standalone FPS limiter from the imguiManager and integrates it into the system class.
2025-10-01 16:21:23 +02:00
e4836174b4 Minor - Adds dynamic screen depth and near controls - V14.4.0
Implements dynamic adjustment of screen depth and near clipping plane distances via the ImGui interface.

This allows users to modify the perspective projection in real-time, affecting the rendering of the scene.

The changes involve:
- Adding screen depth and near variables to the application class.
- Exposing these variables in the ImGui settings window.
- Adding functions to the application and d3d classes to update the projection matrix based on new screen depth and near values.
- Updates the sky sphere size to use world scale.
2025-10-01 16:03:11 +02:00
284e282679 Minor - Improves engine settings and sky sphere - V14.3.0
Refactors the Engine Settings window into a tabbed interface, enhancing usability.

Updates the sky sphere implementation to use a configurable distance.

Adjusts ImGui layout for better docking and window arrangement.
2025-10-01 14:07:09 +02:00
4b47346208 Minor - Rework skysphere from Object to Entity - V14.2.0
Introduces a skysphere entity to the scene.
Creates the skysphere during application initialization and manages its visibility via Z-buffer enabling/disabling in the render system.
The skysphere is now an ECS entity.
The culling thread skips the skybox entity to avoid unnecessary calculations since it's always visible.
The position of the skybox is updated with the active camera.
2025-09-29 19:08:43 +02:00
106 changed files with 8856 additions and 2365 deletions

136
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,136 @@
pipeline {
agent { label 'windows' }
parameters {
string(name: 'DISCORD_USER_ID', defaultValue: '378262266723696651', description: 'ID Discord pour recevoir le DM')
choice(name: 'BUILD_TYPE', choices: ['Both', 'Debug', 'Release'], description: 'Type de build à exécuter')
}
options {
timestamps()
disableConcurrentBuilds()
timeout(time: 30, unit: 'MINUTES')
}
triggers {
pollSCM('')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
parallel {
stage('Build Debug') {
when { expression { params.BUILD_TYPE in ['Both', 'Debug'] } }
steps {
echo 'Building Debug...'
bat """
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe" ^
"%WORKSPACE%\\KhaoticEngineReborn.sln" ^
/p:Configuration=Debug ^
/p:Platform=x64 ^
/m ^
/verbosity:minimal
"""
}
}
stage('Build Release') {
when { expression { params.BUILD_TYPE in ['Both', 'Release'] } }
steps {
echo 'Building Release...'
bat """
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe" ^
"%WORKSPACE%\\KhaoticEngineReborn.sln" ^
/p:Configuration=Release ^
/p:Platform=x64 ^
/m ^
/verbosity:minimal
"""
}
}
}
}
stage('Package') {
parallel {
stage('Package Debug') {
when { expression { params.BUILD_TYPE in ['Both', 'Debug'] } }
steps {
echo 'Packaging Debug into ZIP'
bat 'if not exist "%WORKSPACE%\\builds" mkdir "%WORKSPACE%\\builds"'
bat """
powershell -Command "Compress-Archive -Path '%WORKSPACE%\\**\\Debug\\*' -DestinationPath '%WORKSPACE%\\builds\\KhaoticEngineReborn_Debug.zip' -Force"
"""
}
}
stage('Package Release') {
when { expression { params.BUILD_TYPE in ['Both', 'Release'] } }
steps {
echo 'Packaging Release into ZIP'
bat 'if not exist "%WORKSPACE%\\builds" mkdir "%WORKSPACE%\\builds"'
bat """
powershell -Command "Compress-Archive -Path '%WORKSPACE%\\**\\Release\\*' -DestinationPath '%WORKSPACE%\\builds\\KhaoticEngineReborn_Release.zip' -Force"
"""
}
}
}
}
stage('Archive Artifacts') {
steps {
archiveArtifacts artifacts: 'builds/*.zip', fingerprint: true
}
}
}
post {
success {
script {
def urlsList = []
if (params.BUILD_TYPE in ['Both', 'Debug']) {
urlsList << "${env.BUILD_URL}artifact/builds/KhaoticEngineReborn_Debug.zip"
}
if (params.BUILD_TYPE in ['Both', 'Release']) {
urlsList << "${env.BUILD_URL}artifact/builds/KhaoticEngineReborn_Release.zip"
}
def data = [
userId: params.DISCORD_USER_ID,
status: 'success',
urls: urlsList
]
def jsonFile = "${env.WORKSPACE}\\payload.json"
writeFile file: jsonFile, text: groovy.json.JsonOutput.toJson(data)
bat """
curl -X POST http://192.168.1.131:2500/ci-notify ^
-H "Content-Type: application/json" ^
--data @${jsonFile}
"""
}
}
failure {
script {
def data = [
userId: params.DISCORD_USER_ID,
status: 'failure',
urls: []
]
def jsonFile = "${env.WORKSPACE}\\payload-fail.json"
writeFile file: jsonFile, text: groovy.json.JsonOutput.toJson(data)
bat """
curl -X POST http://192.168.1.131:2500/ci-notify ^
-H "Content-Type: application/json" ^
--data @${jsonFile}
"""
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -141,6 +141,7 @@
<ClInclude Include="src\inc\system\input_class.h" /> <ClInclude Include="src\inc\system\input_class.h" />
<ClInclude Include="src\inc\system\light_class.h" /> <ClInclude Include="src\inc\system\light_class.h" />
<ClInclude Include="src\inc\system\Logger.h" /> <ClInclude Include="src\inc\system\Logger.h" />
<ClInclude Include="src\inc\system\macro.h" />
<ClInclude Include="src\inc\system\model_class.h" /> <ClInclude Include="src\inc\system\model_class.h" />
<ClInclude Include="src\inc\system\Modellistclass.h" /> <ClInclude Include="src\inc\system\Modellistclass.h" />
<ClInclude Include="src\inc\system\object.h" /> <ClInclude Include="src\inc\system\object.h" />

View File

@@ -1,6 +1,6 @@
[Window][DockSpace] [Window][DockSpace]
Pos=0,0 Pos=0,0
Size=1584,861 Size=1536,793
Collapsed=0 Collapsed=0
[Window][Debug##Default] [Window][Debug##Default]
@@ -15,22 +15,22 @@ Collapsed=0
DockId=0x00000006,0 DockId=0x00000006,0
[Window][render Stats] [Window][render Stats]
Pos=0,630 Pos=0,562
Size=1584,231 Size=1217,231
Collapsed=0 Collapsed=0
DockId=0x00000009,0 DockId=0x00000009,0
[Window][Objects] [Window][Objects]
Pos=0,19 Pos=0,19
Size=234,842 Size=15,22
Collapsed=0 Collapsed=0
DockId=0x0000000B,0 DockId=0x0000000B,0
[Window][Terrain] [Window][Terrain]
Pos=0,19 Pos=0,19
Size=266,842 Size=15,22
Collapsed=0 Collapsed=0
DockId=0x00000007,0 DockId=0x0000000B,1
[Window][Log Window] [Window][Log Window]
Pos=0,630 Pos=0,630
@@ -45,23 +45,27 @@ Collapsed=0
DockId=0x0000000B,0 DockId=0x0000000B,0
[Window][Engine Settings] [Window][Engine Settings]
Pos=1267,462 Pos=1219,19
Size=317,166 Size=317,774
Collapsed=0
DockId=0x00000006,0
[Window][Inspector]
Pos=1352,19
Size=232,842
Collapsed=0 Collapsed=0
DockId=0x00000002,0 DockId=0x00000002,0
[Docking][Data] [Docking][Data]
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1584,842 Split=X DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1536,774 Split=X
DockNode ID=0x00000005 Parent=0xCCBD8CF7 SizeRef=1265,842 Split=Y DockNode ID=0x00000001 Parent=0xCCBD8CF7 SizeRef=1350,842 Split=X
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=1584,609 Split=X DockNode ID=0x00000005 Parent=0x00000001 SizeRef=1265,842 Split=Y
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=234,842 Selected=0x031DC75C DockNode ID=0x00000003 Parent=0x00000005 SizeRef=1584,609 Split=X
DockNode ID=0x0000000C Parent=0x00000003 SizeRef=1348,842 Split=X DockNode ID=0x0000000B Parent=0x00000003 SizeRef=251,842 Selected=0x031DC75C
DockNode ID=0x00000007 Parent=0x0000000C SizeRef=266,842 Selected=0x393905AB DockNode ID=0x0000000C Parent=0x00000003 SizeRef=964,842 CentralNode=1
DockNode ID=0x00000008 Parent=0x0000000C SizeRef=1316,842 Split=X DockNode ID=0x00000004 Parent=0x00000005 SizeRef=1584,231 Split=X Selected=0xF5D1BB37
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1265,842 CentralNode=1 DockNode ID=0x00000009 Parent=0x00000004 SizeRef=792,231 Selected=0xF5D1BB37
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=317,842 Selected=0x9F035453 DockNode ID=0x0000000A Parent=0x00000004 SizeRef=790,231 Selected=0xAB74BEE9
DockNode ID=0x00000004 Parent=0x00000005 SizeRef=1584,231 Split=X Selected=0xF5D1BB37 DockNode ID=0x00000006 Parent=0x00000001 SizeRef=317,842 Selected=0x0B098C4B
DockNode ID=0x00000009 Parent=0x00000004 SizeRef=792,231 Selected=0xF5D1BB37 DockNode ID=0x00000002 Parent=0xCCBD8CF7 SizeRef=232,842 Selected=0x36DC96AB
DockNode ID=0x0000000A Parent=0x00000004 SizeRef=790,231 Selected=0xAB74BEE9
DockNode ID=0x00000006 Parent=0xCCBD8CF7 SizeRef=317,842 Selected=0x9F035453

View File

@@ -1,8 +1,6 @@
///////////// /////////////
// GLOBALS // // GLOBALS //
///////////// /////////////
Texture2D shaderTexture : register(t0);
SamplerState SampleType : register(s0);
////////////// //////////////
// TYPEDEFS // // TYPEDEFS //
@@ -10,7 +8,6 @@ SamplerState SampleType : register(s0);
struct PixelInputType struct PixelInputType
{ {
float4 position : SV_POSITION; float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -14,13 +14,11 @@ cbuffer MatrixBuffer
struct VertexInputType struct VertexInputType
{ {
float4 position : POSITION; float4 position : POSITION;
float2 tex : TEXCOORD0;
}; };
struct PixelInputType struct PixelInputType
{ {
float4 position : SV_POSITION; float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
}; };
@@ -40,8 +38,5 @@ PixelInputType DepthVertexShader(VertexInputType input)
output.position = mul(output.position, viewMatrix); output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix); output.position = mul(output.position, projectionMatrix);
// Store the texture coordinates for the pixel shader.
output.tex = input.tex;
return output; return output;
} }

View File

@@ -10,6 +10,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -5,6 +5,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -13,6 +13,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -10,6 +10,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;
@@ -34,14 +35,14 @@ public:
bool initialize(ID3D11Device*, HWND); bool initialize(ID3D11Device*, HWND);
void shutdown(); void shutdown();
bool render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*); bool render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX);
private: private:
bool initialize_shader(ID3D11Device*, HWND, WCHAR*, WCHAR*); bool initialize_shader(ID3D11Device*, HWND, WCHAR*, WCHAR*);
void shutdown_shader(); void shutdown_shader();
void output_shader_error_message(ID3D10Blob*, HWND, WCHAR*); void output_shader_error_message(ID3D10Blob*, HWND, WCHAR*);
bool set_shader_parameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*); bool set_shader_parameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX);
void render_shader(ID3D11DeviceContext*, int); void render_shader(ID3D11DeviceContext*, int);
private: private:
@@ -49,7 +50,6 @@ private:
ID3D11PixelShader* pixel_shader_; ID3D11PixelShader* pixel_shader_;
ID3D11InputLayout* layout_; ID3D11InputLayout* layout_;
ID3D11Buffer* matrix_buffer_; ID3D11Buffer* matrix_buffer_;
ID3D11SamplerState* sample_state_;
}; };

View File

@@ -10,6 +10,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -11,6 +11,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -17,6 +17,7 @@ constexpr int num_lights = 4;
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -2,6 +2,7 @@
#include <d3d11.h> #include <d3d11.h>
#include <DirectXMath.h> #include <DirectXMath.h>
#include <string> #include <string>
#include "macro.h"
class master_shader class master_shader

View File

@@ -13,6 +13,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -10,6 +10,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -13,6 +13,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -9,6 +9,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -21,6 +21,7 @@
#include "skybox_shader_class.h" #include "skybox_shader_class.h"
#include "sunlight_shader_class.h" #include "sunlight_shader_class.h"
#include "depth_shader_class.h" #include "depth_shader_class.h"
#include "macro.h"
using namespace DirectX; using namespace DirectX;
@@ -53,8 +54,7 @@ public:
int indexCount, int indexCount,
XMMATRIX worldMatrix, XMMATRIX worldMatrix,
XMMATRIX viewMatrix, XMMATRIX viewMatrix,
XMMATRIX projectionMatrix, XMMATRIX projectionMatrix
ID3D11ShaderResourceView* texture
); );
private: private:

View File

@@ -5,6 +5,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -9,6 +9,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -5,6 +5,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -10,6 +10,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -10,6 +10,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -10,6 +10,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -9,6 +9,7 @@
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
using namespace std; using namespace std;

View File

@@ -9,6 +9,8 @@
#include "camera_class.h" #include "camera_class.h"
#include "light_class.h" #include "light_class.h"
#include "macro.h"
#include "Fmod/core/inc/fmod.hpp" #include "Fmod/core/inc/fmod.hpp"
#include "bitmap_class.h" #include "bitmap_class.h"
@@ -61,8 +63,6 @@
// GLOBALS // // GLOBALS //
///////////// /////////////
constexpr bool full_screen = false; constexpr bool full_screen = false;
constexpr float screen_depth = 1000.0f;
constexpr float screen_near = 0.3f;
static std::map<std::string, std::shared_ptr<model_class>> g_model_cache; static std::map<std::string, std::shared_ptr<model_class>> g_model_cache;
@@ -381,7 +381,7 @@ public:
* Construct the frustum for culling. * Construct the frustum for culling.
* This function will calculate the frustum based on the current camera view and projection matrices. * This function will calculate the frustum based on the current camera view and projection matrices.
*/ */
void construct_frustum(); void construct_frustum(frustum& frustum, float screen_depth, XMMATRIX projectionMatrix, XMMATRIX viewMatrix);
/** /**
* Get the number of objects rendered in the current frame. * Get the number of objects rendered in the current frame.
@@ -450,6 +450,50 @@ public:
* @return A reference to the global model cache as a map of strings to shared pointers of model_class. * @return A reference to the global model cache as a map of strings to shared pointers of model_class.
*/ */
std::map<std::string, std::shared_ptr<model_class>>& get_model_cache() { return g_model_cache; } std::map<std::string, std::shared_ptr<model_class>>& get_model_cache() { return g_model_cache; }
/**
* Get the sky entity ID.
* @return The sky entity ID as an integer.
*/
int get_sky_id() const { return sky_id_; }
/** Get the Sky entity as a shared pointer.
* @return A shared pointer to the sky entity.
*/
std::shared_ptr<ecs::Entity> get_sky_entity_shared_ptr() const { return sky_entity_; }
/**
* Update the screen depth.
*/
bool update_screen_depth(float new_screen_depth);
/**
* Update the screen near.
*/
bool update_screen_near(float new_screen_near);
/**
* Get the screen depth.
* @return The screen depth as a float.
*/
float get_screen_depth() const { return screen_depth; }
/**
* Get the screen near.
* @return The screen near as a float.
*/
float get_screen_near() const { return screen_near; }
/**
* Get the target fps for the application.
* @return The target fps as an integer.
*/
int get_target_fps() const { return target_fps_; };
/**
* Set the target fps for the application.
* @param target_fps The new target fps as an integer.
*/
void set_target_fps(int target_fps) { target_fps_ = target_fps; };
private: private:
/** /**
@@ -500,6 +544,13 @@ private:
* @return True if the refraction was rendered to the texture successfully, false otherwise. * @return True if the refraction was rendered to the texture successfully, false otherwise.
*/ */
bool render_refraction_to_texture(); bool render_refraction_to_texture();
/**
* Render the shadow map texture for the scene.
* @return True if the shadow map was rendered successfully, false otherwise.
*/
bool render_shadow_map();
/** /**
* Render the reflection of the scene to a texture. * Render the reflection of the scene to a texture.
* This function will render the reflection effects, such as water or mirrors, to a texture. * This function will render the reflection effects, such as water or mirrors, to a texture.
@@ -530,6 +581,16 @@ private:
* The thread function for culling objects in the scene. * The thread function for culling objects in the scene.
*/ */
void culling_thread_function(); void culling_thread_function();
/**
* A thread function to handle culling of objects no visible by sun light.
*/
void sun_culling_thread_function();
/**
* Create the skysphere entity.
*/
bool create_skysphere();
public : public :
std::vector<ID3D11ShaderResourceView*> textures; std::vector<ID3D11ShaderResourceView*> textures;
@@ -540,6 +601,11 @@ private :
std::thread culling_thread_; std::thread culling_thread_;
std::atomic<bool> culling_active_; std::atomic<bool> culling_active_;
std::mutex objects_mutex_; std::mutex objects_mutex_;
// Thread de culling pour les shadows
std::thread culling_sun_thread_;
std::atomic<bool> culling_sun_active_;
std::mutex objects_sun_mutex_;
std::mutex terrain_mutex_; std::mutex terrain_mutex_;
std::vector<std::tuple<float, float, float, std::string, int>> terrain_generation_data_; std::vector<std::tuple<float, float, float, std::string, int>> terrain_generation_data_;
@@ -559,12 +625,15 @@ private :
HWND hwnd_; HWND hwnd_;
bool windowed_; bool windowed_;
float screen_depth = 1000.0f;
float screen_near = 0.3f;
// ------------------------------------- // // ------------------------------------- //
// ------------- RENDERING ------------- // // ------------- RENDERING ------------- //
// ------------------------------------- // // ------------------------------------- //
XMMATRIX base_view_matrix_; XMMATRIX base_view_matrix_;
render_texture_class* render_texture_, * refraction_texture_, * reflection_texture_; render_texture_class* render_texture_, * refraction_texture_, * reflection_texture_,* shadow_texture_ ;
render_texture_class* scene_texture_; render_texture_class* scene_texture_;
display_plane_class* display_plane_; display_plane_class* display_plane_;
int screen_width_, screen_height_; int screen_width_, screen_height_;
@@ -587,7 +656,9 @@ private :
float speed_ = 0.1f; // speed for the demo spinning object float speed_ = 0.1f; // speed for the demo spinning object
std::vector<object*> imported_object_; std::vector<object*> imported_object_;
int object_id_ = 0; int object_id_ = 0;
std::vector<object*> skybox_;
int sky_id_ = -1;
std::shared_ptr<ecs::Entity> sky_entity_;
// ----------------------------------- // // ----------------------------------- //
// ------------- LIGHTS -------------- // // ------------- LIGHTS -------------- //
@@ -647,12 +718,14 @@ private :
ID3D11ShaderResourceView* back_buffer_srv_; ID3D11ShaderResourceView* back_buffer_srv_;
stats* stats_; stats* stats_;
int target_fps_ = 60;
// ------------------------------------------------- // // ------------------------------------------------- //
// ------------------- Culling --------------------- // // ------------------- Culling --------------------- //
// ------------------------------------------------- // // ------------------------------------------------- //
frustum frustum_culling_; frustum frustum_culling_;
frustum sun_culling_;
int render_count_; int render_count_;
float frustum_culling_tolerance_ = 5.f; float frustum_culling_tolerance_ = 5.f;
@@ -662,6 +735,7 @@ private :
input inputs_; input inputs_;
bool tab_was_pressed_; bool tab_was_pressed_;
std::shared_ptr<CameraInput> camera_input_;
// ------------------------------------------------- // // ------------------------------------------------- //
// ------------------- SOUND ----------------------- // // ------------------- SOUND ----------------------- //

View File

@@ -13,6 +13,7 @@ using namespace DirectX;
// MY CLASS INCLUDES // // MY CLASS INCLUDES //
/////////////////////// ///////////////////////
#include "texture_class.h" #include "texture_class.h"
#include "macro.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -9,6 +9,9 @@
// INCLUDES // // INCLUDES //
////////////// //////////////
#include <directxmath.h> #include <directxmath.h>
#include "input_class.h"
#include "macro.h"
using namespace DirectX; using namespace DirectX;
@@ -69,6 +72,10 @@ public:
*/ */
XMMATRIX get_view_matrix(XMMATRIX& view_matrix) const; XMMATRIX get_view_matrix(XMMATRIX& view_matrix) const;
/**
* Update the camera's view matrix without
*/
/** /**
* @brief Renders the reflection of the scene from the camera's perspective. * @brief Renders the reflection of the scene from the camera's perspective.
* *
@@ -120,7 +127,40 @@ public:
return upF; return upF;
} }
/**
* Move the camera
* @param std::vector<bool> inputs : forward, backward, left, right, up, down, scrollUp, scrollDown, rightClick
* @param float deltaTime : time since last frame
* @return void
*/
void move(float deltatime, float delta_x, float delta_y);
/**
* Rotate the camera
* @param float delta_x : mouse delta x
* @param float delta_y : mouse delta y
* @return void
*/
void rotate(float delta_x, float delta_y);
/**
* Update the camera input states based on the provided input_class instance.
* This method updates the internal state of the camera's input handling.
* @param imputs A pointer to an input_class instance containing the current input states.
*/
void update_camera_inputs_states(input_class* imputs);
/**
* Set the camera inputs structure.
* @param inputs A shared pointer to a CameraInput structure containing the input states.
*/
void set_camera_inputs(std::shared_ptr<CameraInput> inputs) { inputs_ = inputs; }
/**
* Get the camera inputs structure.
* @return A shared pointer to the CameraInput structure containing the input states.
*/
std::shared_ptr<CameraInput> get_camera_inputs() { return inputs_; }
private: private:
float position_x_, position_y_, position_z_; float position_x_, position_y_, position_z_;
@@ -128,6 +168,9 @@ private:
XMMATRIX view_matrix_; XMMATRIX view_matrix_;
XMMATRIX reflection_view_matrix_; XMMATRIX reflection_view_matrix_;
float camera_speed_;
std::shared_ptr<CameraInput> inputs_;
float camera_sensitivity_ = 0.1f;
}; };
#endif #endif

View File

@@ -21,6 +21,7 @@
#include "font_shader_class.h" #include "font_shader_class.h"
#include "font_class.h" #include "font_class.h"
#include "text_class.h" #include "text_class.h"
#include "macro.h"
using namespace DirectX; using namespace DirectX;
@@ -165,6 +166,16 @@ public:
*/ */
void disable_alpha_blending(); void disable_alpha_blending();
/**
* Set new projection parameters.
* @param width The new width for the projection matrix.
* @param height The new height for the projection matrix.
* @param screenDepth The new screen depth.
* @param screenNear The new near clipping plane distance.
* @return True if the projection parameters were set successfully, false otherwise.
*/
bool set_projection_params(int width,int height,float screenDepth, float screenNear);
private: private:
bool vsync_enabled_; bool vsync_enabled_;
int video_card_memory_; int video_card_memory_;

View File

@@ -6,7 +6,7 @@
// MY CLASS INCLUDES // // MY CLASS INCLUDES //
/////////////////////// ///////////////////////
#include "d_3d_class.h" #include "d_3d_class.h"
#include "macro.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Class name: display_plane_class // Class name: display_plane_class

View File

@@ -5,7 +5,7 @@
#include <imgui.h> #include <imgui.h>
#include "entity.h" #include "entity.h"
#include "Logger.h" #include "macro.h"
/** /**
* namespace for the Entity-Component-System (ECS) * namespace for the Entity-Component-System (ECS)
@@ -55,7 +55,7 @@ public:
* @param data The string data to deserialize from. * @param data The string data to deserialize from.
* @return True if deserialization was successful, otherwise false. * @return True if deserialization was successful, otherwise false.
*/ */
virtual bool Deserialize(const std::string& data) { return false;} virtual bool Deserialize(const std::string& data) { R_FALSE}
/** /**
* Virtual function to render ImGui controls for the component. * Virtual function to render ImGui controls for the component.

View File

@@ -77,17 +77,17 @@ public:
bool Load(const std::string& path) { bool Load(const std::string& path) {
if (!m_system) { if (!m_system) {
Initialize(); Initialize();
if (!m_system) return false; if (!m_system) R_FALSE
} }
Logger::Get().Log("Loading audio file: " + path, __FILE__, __LINE__, Logger::LogLevel::Info); LOG_INFO("Loading audio file: " + path);
m_soundPath = path; m_soundPath = path;
if (!std::filesystem::exists(path)) { if (!std::filesystem::exists(path)) {
m_lastError = "Fichier non trouv<75>: " + path; m_lastError = "Fichier non trouv<75>: " + path;
Logger::Get().Log(m_lastError, __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR(m_lastError);
return false; R_FALSE
} }
if (m_sound) { if (m_sound) {
@@ -109,10 +109,11 @@ public:
if (result != FMOD_OK) { if (result != FMOD_OK) {
m_lastError = "<EFBFBD>chec du chargement du son: " + std::to_string(result) + m_lastError = "<EFBFBD>chec du chargement du son: " + std::to_string(result) +
" (chemin: " + absolutePath.string() + ")"; " (chemin: " + absolutePath.string() + ")";
return false; LOG_ERROR(m_lastError);
R_FALSE
} }
return true; R_TRUE
} }
/** /**
@@ -297,6 +298,7 @@ public:
if (!m_lastError.empty()) { if (!m_lastError.empty()) {
ImGui::TextColored(ImVec4(1, 0, 0, 1), "Error: %s", m_lastError.c_str()); ImGui::TextColored(ImVec4(1, 0, 0, 1), "Error: %s", m_lastError.c_str());
LOG_ERROR(m_lastError);
} }
} else { } else {
ImGui::Text("Loaded: %s", m_soundPath.c_str()); ImGui::Text("Loaded: %s", m_soundPath.c_str());
@@ -493,7 +495,7 @@ public:
std::stringstream ss(data); std::stringstream ss(data);
std::string type; std::string type;
std::getline(ss, type, ':'); std::getline(ss, type, ':');
if (type != "AudioComponent") return false; if (type != "AudioComponent") R_FALSE
std::string s_volume, s_pan, s_pitch, s_looping, s_muted, s_paused, s_priority, s_spatialized, s_use_velocity; std::string s_volume, s_pan, s_pitch, s_looping, s_muted, s_paused, s_priority, s_spatialized, s_use_velocity;
@@ -507,8 +509,6 @@ public:
std::getline(ss, s_priority, ':'); std::getline(ss, s_priority, ':');
std::getline(ss, s_spatialized, ':'); std::getline(ss, s_spatialized, ':');
std::getline(ss, s_use_velocity, ':'); std::getline(ss, s_use_velocity, ':');
Logger::Get().Log("Deserializing AudioComponent: path=" + m_soundPath, __FILE__, __LINE__, Logger::LogLevel::Warning);
m_volume = std::stof(s_volume); m_volume = std::stof(s_volume);
m_pan = std::stof(s_pan); m_pan = std::stof(s_pan);
@@ -525,7 +525,7 @@ public:
Load(m_soundPath); Load(m_soundPath);
} }
return true; R_TRUE
} }
private: private:

View File

@@ -119,7 +119,7 @@ public:
std::string type; std::string type;
std::getline(ss, type, ':'); std::getline(ss, type, ':');
if (type != "IdentityComponent") return false; if (type != "IdentityComponent") R_FALSE
std::string token, name, objectTypeStr; std::string token, name, objectTypeStr;
int id; int id;
@@ -131,7 +131,7 @@ public:
SetId(id); SetId(id);
SetName(name); SetName(name);
SetType(StringToObjectType(objectTypeStr)); SetType(StringToObjectType(objectTypeStr));
return true; R_TRUE
} }
void OnImGuiRender() override { void OnImGuiRender() override {

View File

@@ -65,7 +65,7 @@ private:
bool CreateScriptFile() { bool CreateScriptFile() {
if (strlen(scriptNameBuffer) == 0) if (strlen(scriptNameBuffer) == 0)
return false; R_FALSE
scriptName = scriptNameBuffer; scriptName = scriptNameBuffer;
if (scriptName.length() < 4 || scriptName.substr(scriptName.length() - 4) != ".lua") { if (scriptName.length() < 4 || scriptName.substr(scriptName.length() - 4) != ".lua") {
@@ -81,19 +81,19 @@ private:
std::filesystem::create_directories(scriptFolder, ec); std::filesystem::create_directories(scriptFolder, ec);
if (ec) { if (ec) {
// Log erreur // Log erreur
return false; R_FALSE
} }
std::string fullPath = scriptFolder + scriptName; std::string fullPath = scriptFolder + scriptName;
// Cr<43>er un fichier script vide ou template simple // Cr<43>er un fichier script vide ou template simple
std::ofstream ofs(fullPath); std::ofstream ofs(fullPath);
if (!ofs) return false; if (!ofs) R_FALSE
ofs << "-- Script Lua vide pour ECS\n\nfunction on_update(dt)\n -- Code ici\nend\n"; ofs << "-- Script Lua vide pour ECS\n\nfunction on_update(dt)\n -- Code ici\nend\n";
ofs.close(); ofs.close();
return true; R_TRUE
} }
}; };

View File

@@ -46,13 +46,13 @@ public:
std::string type; std::string type;
std::getline(ss, type, ':'); std::getline(ss, type, ':');
if (type != "ModelPathComponent") return false; if (type != "ModelPathComponent") R_FALSE
std::string modelPath; std::string modelPath;
std::getline(ss, modelPath); std::getline(ss, modelPath);
SetPath(std::wstring(modelPath.begin(), modelPath.end())); SetPath(std::wstring(modelPath.begin(), modelPath.end()));
return true; R_TRUE
} }
void OnImGuiRender() override { void OnImGuiRender() override {

View File

@@ -213,7 +213,7 @@ public:
std::string type; std::string type;
std::getline(ss, type, ':'); std::getline(ss, type, ':');
if (type != "PhysicsComponent") return false; if (type != "PhysicsComponent") R_FALSE
std::string token; std::string token;
float mass, boundingRadius; float mass, boundingRadius;
@@ -230,7 +230,7 @@ public:
SetPhysicsEnabled(physicsEnabled); SetPhysicsEnabled(physicsEnabled);
SetGravityEnabled(gravityEnabled); SetGravityEnabled(gravityEnabled);
SetGrounded(isGrounded); SetGrounded(isGrounded);
return true; R_TRUE
} }
void OnImGuiRender() override { void OnImGuiRender() override {

View File

@@ -48,9 +48,9 @@ public:
* @return True if initialization was successful, false otherwise. * @return True if initialization was successful, false otherwise.
*/ */
bool InitializeWithModel(std::shared_ptr<model_class> model) { bool InitializeWithModel(std::shared_ptr<model_class> model) {
if (!model) return false; if (!model) R_FALSE
m_model = model; m_model = model;
return true; R_TRUE
} }
/** /**
@@ -73,14 +73,14 @@ public:
// Cr<43>er un nouveau mod<6F>le // Cr<43>er un nouveau mod<6F>le
auto new_model = std::make_shared<model_class>(); auto new_model = std::make_shared<model_class>();
if (!new_model->Initialize(device, deviceContext, const_cast<char*>(modelFilename), textureContainer)) { if (!new_model->Initialize(device, deviceContext, const_cast<char*>(modelFilename), textureContainer)) {
return false; R_FALSE
} }
g_model_cache[filename] = new_model; g_model_cache[filename] = new_model;
m_model = new_model; m_model = new_model;
} }
m_modelFilePath = modelFilename; m_modelFilePath = modelFilename;
return true; R_TRUE
} }
/** /**
@@ -101,13 +101,13 @@ public:
ID3D11ShaderResourceView* texture = nullptr; ID3D11ShaderResourceView* texture = nullptr;
result = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture); result = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(result)) { if (FAILED(result)) {
return false; R_FALSE
} }
texturesContainer.AssignTexture(texturesContainer, texture, texturePath, i); texturesContainer.AssignTexture(texturesContainer, texture, texturePath, i);
i++; i++;
} }
return true; R_TRUE
} }
/** /**
@@ -190,6 +190,15 @@ public:
} }
} }
void RenderOnlyGeometryFromSun(ID3D11DeviceContext* ctx)
{
if (m_model && m_is_in_sun_pov) m_model->Render(ctx);
}
void set_is_sun_visible(bool v) { m_is_in_sun_pov = v; }
bool is_in_sun_pov() const { return m_is_in_sun_pov; }
/** /**
* Serialize the RenderComponent's state to a string. * Serialize the RenderComponent's state to a string.
* This method is useful for saving the component's state or debugging. * This method is useful for saving the component's state or debugging.
@@ -224,6 +233,7 @@ public:
std::stringstream ss; std::stringstream ss;
ss << "RenderComponent:HasModel:" ss << "RenderComponent:HasModel:"
<< is_shadow_caster_ << ":"
<< diffuse_count << ":" << diffuse_paths_ << ":" << diffuse_count << ":" << diffuse_paths_ << ":"
<< normal_count << ":" << normal_paths_ << ":" << normal_count << ":" << normal_paths_ << ":"
<< specular_count << ":" << specular_paths_ << ":" << specular_count << ":" << specular_paths_ << ":"
@@ -245,12 +255,15 @@ public:
std::string type; std::string type;
if (!std::getline(ss, type, ':') || type != "RenderComponent") if (!std::getline(ss, type, ':') || type != "RenderComponent")
return false; R_FALSE
std::string token; std::string token;
if (!std::getline(ss, token, ':') || token != "HasModel") if (!std::getline(ss, token, ':') || token != "HasModel")
return false; R_FALSE
std::getline(ss,token, ':');
is_shadow_caster_ = std::stoi(token);
int diffuse_count = 0, normal_count = 0, specular_count = 0, alpha_count = 0; int diffuse_count = 0, normal_count = 0, specular_count = 0, alpha_count = 0;
@@ -258,14 +271,14 @@ public:
auto read_count = [&](int& count) -> bool { auto read_count = [&](int& count) -> bool {
if (!std::getline(ss, token, ':')) if (!std::getline(ss, token, ':'))
return false; R_FALSE
try { try {
count = std::stoi(token); count = std::stoi(token);
} }
catch (...) { catch (...) {
return false; R_FALSE
} }
return true; R_TRUE
}; };
auto clean_token = [](std::string& str) { auto clean_token = [](std::string& str) {
@@ -278,29 +291,29 @@ public:
auto read_paths = [&](int count, std::vector<std::wstring>& paths) -> bool { auto read_paths = [&](int count, std::vector<std::wstring>& paths) -> bool {
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
if (!std::getline(ss, token, ':')) if (!std::getline(ss, token, ':'))
return false; R_FALSE
clean_token(token); clean_token(token);
if (!token.empty()) { if (!token.empty()) {
paths.emplace_back(token.begin(), token.end()); paths.emplace_back(token.begin(), token.end());
Logger::Get().Log("Loaded path: " + std::string(token.begin(), token.end()), __FILE__, __LINE__, Logger::LogLevel::Info); LOG_INFO("Loaded path: " + std::string(token.begin(), token.end()));
} }
} }
return true; R_TRUE
}; };
if (!read_count(diffuse_count)) return false; if (!read_count(diffuse_count)) R_FALSE
if (!read_paths(diffuse_count, paths_diffuse)) return false; if (!read_paths(diffuse_count, paths_diffuse)) R_FALSE
if (!read_count(normal_count)) return false; if (!read_count(normal_count)) R_FALSE
if (!read_paths(normal_count, paths_normal)) return false; if (!read_paths(normal_count, paths_normal)) R_FALSE
if (!read_count(specular_count)) return false; if (!read_count(specular_count)) R_FALSE
if (!read_paths(specular_count, paths_specular)) return false; if (!read_paths(specular_count, paths_specular)) R_FALSE
if (!read_count(alpha_count)) return false; if (!read_count(alpha_count)) R_FALSE
if (!read_paths(alpha_count, paths_alpha)) return false; if (!read_paths(alpha_count, paths_alpha)) R_FALSE
// Lib<69>rer textures existantes // Lib<69>rer textures existantes
for (auto& tex : texture_container_buffer.diffuse) if (tex) { tex->Release(); tex = nullptr; } for (auto& tex : texture_container_buffer.diffuse) if (tex) { tex->Release(); tex = nullptr; }
@@ -318,7 +331,7 @@ public:
texture_container_buffer.specularPaths = std::move(paths_specular); texture_container_buffer.specularPaths = std::move(paths_specular);
texture_container_buffer.alphaPaths = std::move(paths_alpha); texture_container_buffer.alphaPaths = std::move(paths_alpha);
return true; R_TRUE
} }
/** /**
@@ -328,6 +341,7 @@ public:
*/ */
void OnImGuiRender() override { void OnImGuiRender() override {
ImGui::Checkbox("Visible", &m_isVisible); ImGui::Checkbox("Visible", &m_isVisible);
C_BOX("Is shadow caster" , &is_shadow_caster_);
ImGui::Text("Model File Path: %s", m_modelFilePath.c_str()); ImGui::Text("Model File Path: %s", m_modelFilePath.c_str());
if (m_model) { if (m_model) {
ImGui::Text("Index Count: %d", m_model->GetIndexCount()); ImGui::Text("Index Count: %d", m_model->GetIndexCount());
@@ -453,6 +467,17 @@ public:
void SetTextureContainer(const TextureContainer& texContainer) { texture_container_buffer = texContainer; } void SetTextureContainer(const TextureContainer& texContainer) { texture_container_buffer = texContainer; }
const TextureContainer& GetTextureContainerBuffer() const { return texture_container_buffer; } const TextureContainer& GetTextureContainerBuffer() const { return texture_container_buffer; }
/**
* Get whether the model casts shadows.
* @return True if the model casts shadows, false otherwise.
*/
bool IsShadowCaster() const { return is_shadow_caster_; }
/**
* Set whether the model casts shadows.
* @param isCaster True to make the model cast shadows, false otherwise.
*/
void SetShadowCaster(bool isCaster) { is_shadow_caster_ = isCaster; }
private: private:
std::shared_ptr<model_class> m_model; std::shared_ptr<model_class> m_model;
std::string m_modelFilePath; std::string m_modelFilePath;
@@ -460,6 +485,8 @@ private:
ID3D11Device* device; ID3D11Device* device;
ID3D11DeviceContext* context; ID3D11DeviceContext* context;
TextureContainer texture_container_buffer; TextureContainer texture_container_buffer;
bool is_shadow_caster_ = true;
bool m_is_in_sun_pov;
}; };
} // namespace ecs } // namespace ecs

View File

@@ -53,17 +53,17 @@ public:
* @return The ShaderType enum corresponding to the provided string. * @return The ShaderType enum corresponding to the provided string.
*/ */
static ShaderType StringToShaderType(const std::string& str) { static ShaderType StringToShaderType(const std::string& str) {
if (str == "ALPHA_MAPPING") return ShaderType::ALPHA_MAPPING; if (str == "ALPHA_MAPPING") return SHD_ALPHA;
if (str == "CEL_SHADING") return ShaderType::CEL_SHADING; if (str == "CEL_SHADING") return SHD_CEL;
if (str == "NORMAL_MAPPING") return ShaderType::NORMAL_MAPPING; if (str == "NORMAL_MAPPING") return SHD_NORM;
if (str == "SPECULAR_MAPPING") return ShaderType::SPECULAR_MAPPING; if (str == "SPECULAR_MAPPING") return SHD_SPEC;
if (str == "TEXTURE") return ShaderType::TEXTURE; if (str == "TEXTURE") return SHD_TEX;
if (str == "LIGHTING") return ShaderType::LIGHTING; if (str == "LIGHTING") return SHD_LIGHT;
if (str == "SUNLIGHT") return ShaderType::SUNLIGHT; if (str == "SUNLIGHT") return SHD_SUN;
if (str == "SKYBOX") return ShaderType::SKYBOX; if (str == "SKYBOX") return SHD_SKYBOX;
if (str == "REFLECTION") return ShaderType::REFLECTION; if (str == "REFLECTION") return SHD_REFL;
if (str == "REFRACTION") return ShaderType::REFRACTION; if (str == "REFRACTION") return SHD_REFR;
return ShaderType::TEXTURE; return SHD_TEX;
} }
/** /**
@@ -74,17 +74,17 @@ public:
*/ */
static std::string ShaderTypeToString(ShaderType type) { static std::string ShaderTypeToString(ShaderType type) {
switch (type) { switch (type) {
case ShaderType::ALPHA_MAPPING: return "ALPHA_MAPPING"; case SHD_ALPHA: return "ALPHA_MAPPING";
case ShaderType::CEL_SHADING: return "CEL_SHADING"; case SHD_CEL: return "CEL_SHADING";
case ShaderType::NORMAL_MAPPING: return "NORMAL_MAPPING"; case SHD_NORM: return "NORMAL_MAPPING";
case ShaderType::SPECULAR_MAPPING: return "SPECULAR_MAPPING"; case SHD_SPEC: return "SPECULAR_MAPPING";
case ShaderType::TEXTURE: return "TEXTURE"; case SHD_TEX: return "TEXTURE";
case ShaderType::LIGHTING: return "LIGHTING"; case SHD_LIGHT: return "LIGHTING";
case ShaderType::SUNLIGHT: return "SUNLIGHT"; case SHD_SUN: return "SUNLIGHT";
case ShaderType::SKYBOX: return "SKYBOX"; case SHD_SKYBOX: return "SKYBOX";
case ShaderType::REFLECTION: return "REFLECTION"; case SHD_REFL: return "REFLECTION";
case ShaderType::REFRACTION: return "REFRACTION"; case SHD_REFR: return "REFRACTION";
default: return "TEXTURE"; default: return "TEXTURE";
} }
} }
@@ -101,13 +101,13 @@ public:
std::string type; std::string type;
std::getline(ss, type, ':'); std::getline(ss, type, ':');
if (type != "ShaderComponent") return false; if (type != "ShaderComponent") R_FALSE
std::string shaderTypeStr; std::string shaderTypeStr;
std::getline(ss, shaderTypeStr); std::getline(ss, shaderTypeStr);
SetActiveShader(StringToShaderType(shaderTypeStr)); SetActiveShader(StringToShaderType(shaderTypeStr));
return true; R_TRUE
} }
void OnImGuiRender() override { void OnImGuiRender() override {

View File

@@ -186,7 +186,7 @@ public:
std::string type; std::string type;
std::getline(ss, type, ':'); std::getline(ss, type, ':');
if (type != "TransformComponent") return false; if (type != "TransformComponent") R_FALSE
std::string token; std::string token;
XMFLOAT3 position, rotation, scale; XMFLOAT3 position, rotation, scale;
@@ -206,7 +206,7 @@ public:
SetPosition(XMLoadFloat3(&position)); SetPosition(XMLoadFloat3(&position));
SetRotation(XMLoadFloat3(&rotation)); SetRotation(XMLoadFloat3(&rotation));
SetScale(XMLoadFloat3(&scale)); SetScale(XMLoadFloat3(&scale));
return true; R_TRUE
} }
/** /**

View File

@@ -178,6 +178,9 @@ public:
ID3D11Device* GetDevice() const { return device; } ID3D11Device* GetDevice() const { return device; }
ID3D11DeviceContext* GetContext() const { return context; } ID3D11DeviceContext* GetContext() const { return context; }
int GetSkyID() const { return sky_id_; }
void SetSkyID(int id) { sky_id_ = id; }
private: private:
EntityID m_NextEntityID; EntityID m_NextEntityID;
std::unordered_map<EntityID, std::shared_ptr<Entity>> m_Entities; std::unordered_map<EntityID, std::shared_ptr<Entity>> m_Entities;
@@ -186,6 +189,7 @@ private:
FMOD::System* sound_system_ = nullptr; FMOD::System* sound_system_ = nullptr;
ID3D11Device* device; ID3D11Device* device;
ID3D11DeviceContext* context; ID3D11DeviceContext* context;
int sky_id_ = -1;
}; };
} // namespace ecs } // namespace ecs

View File

@@ -53,7 +53,7 @@ public:
auto shader = entity->GetComponent<ShaderComponent>(); auto shader = entity->GetComponent<ShaderComponent>();
if (!transform || !render || !shader || !render->GetModel()) if (!transform || !render || !shader || !render->GetModel())
return false; R_FALSE
// Calculer la matrice monde // Calculer la matrice monde
XMMATRIX scaleMatrix = transform->GetScaleMatrix(); XMMATRIX scaleMatrix = transform->GetScaleMatrix();
@@ -238,6 +238,16 @@ public:
// V<>rifier si le mod<6F>le est visible // V<>rifier si le mod<6F>le est visible
if (!render->IsVisible()) continue; if (!render->IsVisible()) continue;
// check if the id the sky id to disabled the z buffer
if (entity->GetID() == entityManager->GetSkyID())
{
// D<>sactiver le Z-buffer pour le skysphere
m_deviceContext->OMSetDepthStencilState(nullptr, 0);
} else {
// Activer le Z-buffer pour les autres entit<69>s
m_deviceContext->OMSetDepthStencilState(nullptr, 1);
}
// Effectuer le rendu // Effectuer le rendu
if (RenderEntity(entity, viewMatrix, projectionMatrix, if (RenderEntity(entity, viewMatrix, projectionMatrix,
diffuseColors, lightPositions, ambientColors,cameraPos, diffuseColors, lightPositions, ambientColors,cameraPos,

View File

@@ -7,6 +7,7 @@
////////////// //////////////
#include <directxmath.h> #include <directxmath.h>
#include <fstream> #include <fstream>
#include "macro.h"
using namespace DirectX; using namespace DirectX;

View File

@@ -3,11 +3,9 @@
class fps_limiter { class fps_limiter {
public: public:
/** /**
* Builder for fps_limiter class * Constructor for fps_limiter class
* This class is used to limit the execution rate of a loop based on a target frames per second (FPS). * @param target_fps Target frames per second for the limiter. Default is 60.0f FPS.
* @param target_fps Target frames per second for the limiter. The default is 60.0f FPS.
*/ */
explicit fps_limiter(const float target_fps = 60.0f) explicit fps_limiter(const float target_fps = 60.0f)
: min_delta_(1.0f / target_fps), last_time_(std::chrono::high_resolution_clock::now()) {} : min_delta_(1.0f / target_fps), last_time_(std::chrono::high_resolution_clock::now()) {}
@@ -25,7 +23,17 @@ public:
return false; return false;
} }
/**
* Dynamically set the target FPS limit.
* @param target_fps New target frames per second.
*/
void set_target_fps(float target_fps) {
if (target_fps > 0.0f) {
min_delta_ = 1.0f / target_fps;
}
}
private: private:
float min_delta_; float min_delta_; // Minimum time in seconds between frames
std::chrono::high_resolution_clock::time_point last_time_; std::chrono::high_resolution_clock::time_point last_time_; // Time point of last allowed execution
}; };

View File

@@ -1,4 +1,5 @@
#include <DirectXMath.h> #include <DirectXMath.h>
#include "macro.h"
using namespace DirectX; using namespace DirectX;
class frustum class frustum
@@ -13,12 +14,14 @@ public:
void ConstructFrustum(float screenDepth, XMMATRIX projectionMatrix, XMMATRIX viewMatrix); void ConstructFrustum(float screenDepth, XMMATRIX projectionMatrix, XMMATRIX viewMatrix);
/** /**
* Check if a point is inside the frustum. * Check if a point is inside the frustum.
* @param x X coordinate of the point. * @param x_center X coordinate of the point.
* @param y Y coordinate of the point. * @param y_center Y coordinate of the point.
* @param z Z coordinate of the point. * @param z_center Z coordinate of the point.
* @param radius Radius of the point (for bounding sphere).
* @param tolerance Tolerance value for the check.
* @return True if the point is inside the frustum, otherwise false. * @return True if the point is inside the frustum, otherwise false.
*/ */
bool CheckCube(float xCenter, float yCenter, float zCenter, float radius, float tolerance); bool CheckCube(float x_center, float y_center, float z_center, float radius, float tolerance);
private: private:
XMVECTOR m_planes[6]; XMVECTOR m_planes[6];

View File

@@ -6,6 +6,7 @@
// INCLUDES // // INCLUDES //
////////////// //////////////
#include <directxmath.h> #include <directxmath.h>
#include "macro.h"
using namespace DirectX; using namespace DirectX;

View File

@@ -5,6 +5,7 @@
#include "Logger.h" #include "Logger.h"
#include "sceneManager.h" #include "sceneManager.h"
#include "fps_limiter.h" #include "fps_limiter.h"
#include "macro.h"
#include <imgui.h> #include <imgui.h>
#include <imgui_impl_dx11.h> #include <imgui_impl_dx11.h>
@@ -38,6 +39,12 @@ struct ComponentEntry {
std::function<void()> addFunc; std::function<void()> addFunc;
}; };
struct CachedEntity
{
std::string name;
int id;
};
class imguiManager class imguiManager
{ {
public: public:
@@ -174,6 +181,10 @@ private:
// --------------------------------------------- // // --------------------------------------------- //
// ----------------- Functions ----------------- // // ----------------- Functions ----------------- //
// --------------------------------------------- // // --------------------------------------------- //
/**
* Update the cached entity list if there is a new, delete or rename entity
*/
void UpdateCachedEntitiesIfNeeded();
// --------------------------------------------- // // --------------------------------------------- //
// ----------------- Variables ----------------- // // ----------------- Variables ----------------- //
@@ -185,6 +196,8 @@ private:
scene_manager* scene_manager_; scene_manager* scene_manager_;
stats* stats_; stats* stats_;
ecs::EntityManager* entity_manager_; ecs::EntityManager* entity_manager_;
std::shared_ptr<ecs::Entity> sky_entity_shared_ptr_;
bool showObjectWindow; bool showObjectWindow;
bool showTerrainWindow; bool showTerrainWindow;
@@ -229,6 +242,8 @@ private:
std::string version_driver_; std::string version_driver_;
ecs::EntityID m_selected_entity_id = 0; // ID of the currently selected entity ecs::EntityID m_selected_entity_id = 0; // ID of the currently selected entity
std::vector<CachedEntity> cachedEntities_;
bool entityListDirty = true;
int BUILD_VERSION_VER = -1; int BUILD_VERSION_VER = -1;
}; };

View File

@@ -17,6 +17,7 @@
////////////// //////////////
#include "Logger.h" #include "Logger.h"
#include <dinput.h> #include <dinput.h>
#include "macro.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Class name: input_class // Class name: input_class
@@ -24,6 +25,17 @@
class input_class class input_class
{ {
public: public:
template<typename Container>
std::vector<bool> get_key_states(const Container& key) const
{
std::vector<bool> key_states;
key_states.reserve(key.size());
for (auto k : key)
key_states.push_back(this->is_key_pressed(k));
return key_states;
}
input_class(); input_class();
input_class(const input_class&); input_class(const input_class&);
~input_class(); ~input_class();
@@ -44,15 +56,11 @@ public:
bool IsScrollDown() const; bool IsScrollDown() const;
bool IsUpArrowPressed() const; bool IsUpArrowPressed() const;
bool IsDownArrowPressed() const; bool IsDownArrowPressed() const;
bool IsAPressed() const;
bool IsDPressed() const;
bool IsWPressed() const;
bool IsSPressed() const;
bool IsQPressed() const;
bool IsEPressed()const;
bool IsKeyDown(unsigned int) const; bool IsKeyDown(unsigned int) const;
bool is_key_pressed(const unsigned int); bool is_key_pressed(const unsigned int);
private: private:
bool m_keys[256]; bool m_keys[256];

View File

@@ -10,6 +10,7 @@
// INCLUDES // // INCLUDES //
////////////// //////////////
#include <directxmath.h> #include <directxmath.h>
#include "macro.h"
using namespace DirectX; using namespace DirectX;

View File

@@ -0,0 +1,185 @@
#pragma once
#include "imgui.h"
#include "Logger.h"
#include <limits>
#include <DirectXMath.h>
// --------------------- //
// --- Global Macros --- //
// --------------------- //
#define R_FALSE return false;
#define R_TRUE return true;
#define TO_RAD 0.0174532925f
#define TO_DEG (180.0f/3.141593f)
#ifdef max
#pragma push_macro("max")
#undef max
#define PUSHED_MAX_DEFINED
#endif
// convert unsigned long long int to int safely
inline int ulli_to_int(unsigned long long x)
{
return (x > static_cast<unsigned long long>(std::numeric_limits<int>::max())) ? std::numeric_limits<int>::max() : static_cast<int>(x);
}
// convert int to float safely
inline float int_to_float(int x)
{
return (x > static_cast<int>(std::numeric_limits<float>::max())) ? std::numeric_limits<float>::max() : static_cast<float>(x);
}
// convert size_t to int safely
inline int size_t_to_int(size_t x)
{
return (x > static_cast<size_t>(std::numeric_limits<int>::max())) ? std::numeric_limits<int>::max() : static_cast<int>(x);
}
#ifdef PUSHED_MAX_DEFINED
#pragma pop_macro("max")
#undef PUSHED_MAX_DEFINED
#endif
// --------------------------------------------------------- //
// --- Macros for logging with different severity levels --- //
// --------------------------------------------------------- //
#define LOG(msg, level) Logger::Get().Log(msg, __FILE__, __LINE__, level)
#define LOG_INFO(msg) Logger::Get().Log(msg, __FILE__, __LINE__, Logger::LogLevel::Info)
#define LOG_WARNING(msg) Logger::Get().Log(msg, __FILE__, __LINE__, Logger::LogLevel::Warning)
#define LOG_ERROR(msg) Logger::Get().Log(msg, __FILE__, __LINE__, Logger::LogLevel::Error)
#define LOG_DEBUG(msg) Logger::Get().Log(msg, __FILE__, __LINE__, Logger::LogLevel::Debug)
#define LOG_SHUTDOWN(msg) Logger::Get().Log(msg, __FILE__, __LINE__, Logger::LogLevel::Shutdown)
#define LOG_INIT(msg) Logger::Get().Log(msg, __FILE__, __LINE__, Logger::LogLevel::Initialize)
#define R_LOG_ERROR(result,msg) \
if(!(result)) { \
LOG_ERROR(msg); \
return false; \
}
// ---------------------------------------------------- //
// --- Macros for the Entity Component System (ECS) --- //
// ---------------------------------------------------- //
#define CREATE_ENTITY entity_manager_->CreateEntity();
#define SHD_ALPHA ecs::ShaderType::ALPHA_MAPPING
#define SHD_CEL ecs::ShaderType::CEL_SHADING
#define SHD_LIGHT ecs::ShaderType::LIGHTING
#define SHD_NORM ecs::ShaderType::NORMAL_MAPPING
#define SHD_REFL ecs::ShaderType::REFLECTION
#define SHD_REFR ecs::ShaderType::REFRACTION
#define SHD_SKYBOX ecs::ShaderType::SKYBOX
#define SHD_SPEC ecs::ShaderType::SPECULAR_MAPPING
#define SHD_SUN ecs::ShaderType::SUNLIGHT
#define SHD_TEX ecs::ShaderType::TEXTURE
// ---------------------------------------- //
// --- Macros for the application class --- //
// ---------------------------------------- //
#define CHECK_2_CONDITION_INDEPENDENT_RETURN(cond1, cond2) \
if(!(cond1)) { \
LOG_ERROR("Condition 1 failed: " #cond1); \
return false; \
} \
if (!(cond2)) { \
LOG_ERROR("Condition 2 failed: " #cond2); \
return false; \
}
#define CHECK_CONDITION_RETURN(cond) \
if(!(cond)) { \
LOG_ERROR("Condition failed: " #cond); \
return false; \
}
// ------------------------------------------------ //
// --- Macros and constexpr for the ImGUI class --- //
// ------------------------------------------------ //
constexpr ImVec4 BG_DK_GRAY = ImVec4(0.1f, 0.1f, 0.1f, 1.0f);
constexpr ImVec4 BG_GRAY = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
constexpr ImVec4 BG_LT_GRAY = ImVec4(0.3f, 0.3f, 0.3f, 1.0f);
constexpr ImVec4 ACCENT_COLOR = ImVec4(0.14f, 0.5f, 0.8f, 0.5f);
constexpr ImVec4 ACCENT_LT_COLOR= ImVec4(0.14f, 0.5f, 0.8f, 1.0f);
constexpr ImVec4 TEXT_COLOR = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
constexpr ImVec4 TEXT_DIM_COLOR = ImVec4(0.6f, 0.6f, 0.6f, 1.0f);
constexpr ImVec4 BORDER_COLOR = ImVec4(0.25f, 0.25f, 0.27f, 1.00f);
constexpr ImVec4 BLK = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
#define BASIC_DOCK_STYLE_1 \
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); \
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); \
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); \
ImGui::PushStyleVar(ImGuiStyleVar_DockingSeparatorSize, 1.0f);
#define BEGIN(name, p_open) ImGui::Begin(name, p_open);
#define S_LINE ImGui::SameLine();
#define E_MENU ImGui::EndMenu();
#define END ImGui::End();
#define TEXT_V(label,var) ImGui::Text(label, var);
#define SEP ImGui::Separator();
#define PSV ImGui::PopStyleVar();
#define O_POPUP(str) ImGui::OpenPopup(str);
#define E_POPUP ImGui::EndPopup();
#define TEX(label) ImGui::Text(label);
#define BUTTON(label) ImGui::Button(label)
#define B_MENU(label) ImGui::BeginMenu(label)
#define M_ITEM_LP(label, p_open) ImGui::MenuItem(label, NULL, p_open)
#define M_ITEM_L(label) ImGui::MenuItem(label)
#define F_SLIDER(label, value, min, max) ImGui::SliderFloat(label, value, min, max)
#define I_SLIDER(label, value, min, max) ImGui::SliderInt(label, value, min, max)
#define C_HEADER(label) ImGui::CollapsingHeader(label)
#define SEL(label, isSelected) ImGui::Selectable(label, isSelected)
#define I_TEX(label, buf, buf_size) ImGui::InputText(label, buf, buf_size)
#define C_BOX(label, v) ImGui::Checkbox(label, v)
#define B_POPUP(str) ImGui::BeginPopup(str)
// ------------------------------------ //
// --- Macros for the frustum class --- //
// ------------------------------------ //
inline bool TestPlaneCorner(
const DirectX::XMVECTOR& plane,
float xPos, float yPos, float zPos,
float tolerance)
{
float val =
DirectX::XMVectorGetX(plane) * xPos +
DirectX::XMVectorGetY(plane) * yPos +
DirectX::XMVectorGetZ(plane) * zPos +
DirectX::XMVectorGetW(plane);
return val > -tolerance;
}
#define CHECK_FRUSTRUM_CUBE_CORNERS(plane, xCenter, yCenter, zCenter, radius, tolerance) \
do { \
const float offsets[2] = { -radius, radius }; \
bool inside = false; \
for (int xi = 0; xi < 2 && !inside; ++xi) { \
for (int yi = 0; yi < 2 && !inside; ++yi) { \
for (int zi = 0; zi < 2 && !inside; ++zi) { \
if (TestPlaneCorner(plane, xCenter + offsets[xi], yCenter + offsets[yi], zCenter + offsets[zi], tolerance)) { \
inside = true; \
} \
} \
} \
} \
if (!inside) { \
R_FALSE; \
} \
} while (0);
// ---------------------------------------------- //
// --- Macros for the camera input processing --- //
// ---------------------------------------------- //
struct CameraInput {
bool move_forward = false;
bool move_backward = false;
bool move_left = false;
bool move_right = false;
bool move_up = false;
bool move_down = false;
bool scroll_up = false;
bool scroll_down = false;
bool right_click = false;
};

View File

@@ -6,6 +6,7 @@
// INCLUDES // // INCLUDES //
////////////// //////////////
#include "Logger.h" #include "Logger.h"
#include "macro.h"
#include <d3d11.h> #include <d3d11.h>
#include <directxmath.h> #include <directxmath.h>

View File

@@ -22,16 +22,10 @@ public:
void GetRotation(float&, float&) const; void GetRotation(float&, float&) const;
void GetPosition(float&, float&, float&) const; void GetPosition(float&, float&, float&) const;
void TurnLeft(bool);
void TurnRight(bool);
void TurnMouse(float, float, float, bool);
void MoveCamera(bool, bool, bool, bool, bool, bool, bool, bool, bool);
private: private:
float m_frameTime; float m_frameTime;
float m_rotationY, m_rotationX; float m_rotationY, m_rotationX;
float m_positionX, m_positionY, m_positionZ; float m_positionX, m_positionY, m_positionZ;
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed, m_cameraSpeed, m_speed;
}; };
#endif #endif

View File

@@ -11,6 +11,7 @@
#include "Logger.h" #include "Logger.h"
#include <d3d11.h> #include <d3d11.h>
#include <directxmath.h> #include <directxmath.h>
#include "macro.h"
using namespace DirectX; using namespace DirectX;

View File

@@ -2,6 +2,7 @@
#include <filesystem> #include <filesystem>
#include <string> #include <string>
#include <vector> #include <vector>
#include "macro.h"
#include "ecs/entity.h" #include "ecs/entity.h"
#include "ecs/ComponentFactory.h" #include "ecs/ComponentFactory.h"

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <d3d11.h> #include <d3d11.h>
#include <directxmath.h> #include <directxmath.h>
#include "macro.h"
class shadow_map { class shadow_map {
public: public:

View File

@@ -64,6 +64,8 @@ private:
bool is_debug_key_pressed_ = false; bool is_debug_key_pressed_ = false;
std::mutex render_mutex_; std::mutex render_mutex_;
std::unique_ptr<fps_limiter> fps_limiter_ = std::make_unique<fps_limiter>(60);
}; };

View File

@@ -8,6 +8,7 @@
#include "Logger.h" #include "Logger.h"
#include <d3d11.h> #include <d3d11.h>
#include <stdio.h> #include <stdio.h>
#include "macro.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -7,6 +7,7 @@
////////////// //////////////
#include "Logger.h" #include "Logger.h"
#include <windows.h> #include <windows.h>
#include "macro.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,8 +1,18 @@
#pragma once #pragma once
#include "imgui.h" #include "imgui.h"
/**
* Definitions for build versioning.
* The build version is composed of:
* - Major version (BUILD_VERSION_MAJOR)
* - Minor version (BUILD_VERSION_MINOR)
* - Patch version (BUILD_VERSION_PATCH)
* - Build number (BUILD_VERSION_VER) which is incremented at each build.
* - Build type (BUILD_VERSION_TYPE) which can be "Debug" or "Release"
* - Build state (BUILD_VERSION_STATE) which can be "Dev" or "Stable"
*/
#define BUILD_VERSION_MAJOR 14 #define BUILD_VERSION_MAJOR 14
#define BUILD_VERSION_MINOR 1 #define BUILD_VERSION_MINOR 5
#define BUILD_VERSION_PATCH 1 #define BUILD_VERSION_PATCH 27
// BUILD_VERSION_VER est un int persist<73> dans un fichier, <20> charger au lancement et incr<63>menter <20> chaque build (voir point 3) // BUILD_VERSION_VER est un int persist<73> dans un fichier, <20> charger au lancement et incr<63>menter <20> chaque build (voir point 3)
extern int BUILD_VERSION_VER; extern int BUILD_VERSION_VER;

View File

@@ -23,7 +23,7 @@ alpha_map_shader_class::~alpha_map_shader_class()
bool alpha_map_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool alpha_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing alpha_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing alpha_map_shader_class");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -34,27 +34,27 @@ bool alpha_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/alphamap.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/alphamap.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string ", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string ");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/alphamap.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/alphamap.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing shader");
return false; R_FALSE
} }
return true; R_TRUE
} }
@@ -77,20 +77,20 @@ bool alpha_map_shader_class::render(ID3D11DeviceContext* deviceContext, int inde
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3);
if (!result) if (!result)
{ {
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error setting shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool alpha_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool alpha_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -120,10 +120,10 @@ bool alpha_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -139,26 +139,26 @@ bool alpha_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -194,8 +194,8 @@ bool alpha_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -217,8 +217,8 @@ bool alpha_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -240,67 +240,67 @@ bool alpha_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating sampler state");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void alpha_map_shader_class::shutdown_shader() void alpha_map_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down shader");
// Release the sampler state. // Release the sampler state.
if (sample_state_) if (sample_state_)
{ {
Logger::Get().Log("Releasing sampler state", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing sampler state");
sample_state_->Release(); sample_state_->Release();
sample_state_ = 0; sample_state_ = 0;
Logger::Get().Log("Sampler state released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Sampler state released");
} }
// Release the matrix constant buffer. // Release the matrix constant buffer.
if (matrix_buffer_) if (matrix_buffer_)
{ {
Logger::Get().Log("Releasing constant buffer", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing constant buffer");
matrix_buffer_->Release(); matrix_buffer_->Release();
matrix_buffer_ = 0; matrix_buffer_ = 0;
Logger::Get().Log("Constant buffer released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Constant buffer released");
} }
// Release the layout. // Release the layout.
if (layout_) if (layout_)
{ {
Logger::Get().Log("Releasing layout", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing layout");
layout_->Release(); layout_->Release();
layout_ = 0; layout_ = 0;
Logger::Get().Log("Layout released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Layout released");
} }
// Release the pixel shader. // Release the pixel shader.
if (pixel_shader_) if (pixel_shader_)
{ {
Logger::Get().Log("Releasing pixel shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing pixel shader");
pixel_shader_->Release(); pixel_shader_->Release();
pixel_shader_ = 0; pixel_shader_ = 0;
Logger::Get().Log("Pixel shader released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Pixel shader released");
} }
// Release the vertex shader. // Release the vertex shader.
if (vertex_shader_) if (vertex_shader_)
{ {
Logger::Get().Log("Releasing vertex shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing vertex shader");
vertex_shader_->Release(); vertex_shader_->Release();
vertex_shader_ = 0; vertex_shader_ = 0;
Logger::Get().Log("Vertex shader released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Vertex shader released");
} }
Logger::Get().Log("Shader shutdown complete", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shader shutdown complete");
return; return;
} }
@@ -360,8 +360,8 @@ bool alpha_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCo
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -386,7 +386,7 @@ bool alpha_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCo
deviceContext->PSSetShaderResources(1, 1, &texture2); deviceContext->PSSetShaderResources(1, 1, &texture2);
deviceContext->PSSetShaderResources(2, 1, &texture3); deviceContext->PSSetShaderResources(2, 1, &texture3);
return true; R_TRUE
} }

View File

@@ -30,7 +30,7 @@ celshade_class::~celshade_class()
bool celshade_class::initialize(ID3D11Device* device, HWND hwnd) bool celshade_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing LightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing LightShaderClass");
wchar_t vsFilename[128]; wchar_t vsFilename[128];
wchar_t psFilename[128]; wchar_t psFilename[128];
@@ -41,28 +41,28 @@ bool celshade_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/celshading.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/celshading.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/celshading.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/celshading.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize shader");
return false; R_FALSE
} }
Logger::Get().Log("SunLightShaderClass initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("SunLightShaderClass initialized");
return true; R_TRUE
} }
@@ -84,20 +84,20 @@ bool celshade_class::render(ID3D11DeviceContext* deviceContext, int index_count,
result = set_shader_parameters(deviceContext, world_matrix, view_matrix, projection_matrix, texture, diffuse_color, ambient_color, sun_direction, sunIntensity); result = set_shader_parameters(deviceContext, world_matrix, view_matrix, projection_matrix, texture, diffuse_color, ambient_color, sun_direction, sunIntensity);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, index_count); render_shader(deviceContext, index_count);
return true; R_TRUE
} }
bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -124,9 +124,9 @@ bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* v
} }
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -139,25 +139,25 @@ bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* v
} }
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -192,8 +192,8 @@ bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* v
result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout_); result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -222,8 +222,8 @@ bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* v
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sampler state");
return false; R_FALSE
} }
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader. // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
@@ -238,8 +238,8 @@ bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* v
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create matrix buffer");
return false; R_FALSE
} }
// Setup the description of the dynamic sunlight constant buffer that is in the pixel shader. // Setup the description of the dynamic sunlight constant buffer that is in the pixel shader.
@@ -254,13 +254,13 @@ bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* v
result = device->CreateBuffer(&sunlightBufferDesc, NULL, &sunlight_buffer_); result = device->CreateBuffer(&sunlightBufferDesc, NULL, &sunlight_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sunlight buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sunlight buffer");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
@@ -268,7 +268,7 @@ bool celshade_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* v
void celshade_class::shutdown_shader() void celshade_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down SunLightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down SunLightShaderClass");
// Release the light constant buffers. // Release the light constant buffers.
if (sunlight_color_buffer_) if (sunlight_color_buffer_)
@@ -332,7 +332,7 @@ void celshade_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("SunLightShaderClass shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("SunLightShaderClass shut down");
return; return;
} }
@@ -389,7 +389,6 @@ bool celshade_class::set_shader_parameters(
HRESULT result; HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
matrix_buffer_type* dataPtr; matrix_buffer_type* dataPtr;
camera_buffer_type* dataPtr2;
sun_light_buffer_type* dataPtr3; sun_light_buffer_type* dataPtr3;
unsigned int bufferNumber; unsigned int bufferNumber;
@@ -402,7 +401,7 @@ bool celshade_class::set_shader_parameters(
result = device_context->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = device_context->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -426,7 +425,7 @@ bool celshade_class::set_shader_parameters(
result = device_context->Map(sunlight_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = device_context->Map(sunlight_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -450,7 +449,7 @@ bool celshade_class::set_shader_parameters(
// Set shader texture resource in the pixel shader. // Set shader texture resource in the pixel shader.
device_context->PSSetShaderResources(0, 1, &texture); device_context->PSSetShaderResources(0, 1, &texture);
return true; R_TRUE
} }
void celshade_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void celshade_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -23,7 +23,7 @@ color_shader_class::~color_shader_class()
bool color_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool color_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing color_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing color_shader_class");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -35,29 +35,29 @@ bool color_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/Color.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/Color.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/Color.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/Color.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing shader");
return false; R_FALSE
} }
Logger::Get().Log("color_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("color_shader_class initialized");
return true; R_TRUE
} }
void color_shader_class::shutdown() void color_shader_class::shutdown()
@@ -78,19 +78,19 @@ bool color_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCou
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix);
if (!result) if (!result)
{ {
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error setting shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool color_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool color_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -119,10 +119,10 @@ bool color_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -138,26 +138,26 @@ bool color_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -186,8 +186,8 @@ bool color_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -209,56 +209,56 @@ bool color_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void color_shader_class::shutdown_shader() void color_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down shader");
// Release the matrix constant buffer. // Release the matrix constant buffer.
if (matrix_buffer_) if (matrix_buffer_)
{ {
Logger::Get().Log("Releasing matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing matrix buffer");
matrix_buffer_->Release(); matrix_buffer_->Release();
matrix_buffer_ = 0; matrix_buffer_ = 0;
Logger::Get().Log("Matrix buffer released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Matrix buffer released");
} }
// Release the layout. // Release the layout.
if (layout_) if (layout_)
{ {
Logger::Get().Log("Releasing layout", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing layout");
layout_->Release(); layout_->Release();
layout_ = 0; layout_ = 0;
Logger::Get().Log("Layout released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Layout released");
} }
// Release the pixel shader. // Release the pixel shader.
if (pixel_shader_) if (pixel_shader_)
{ {
Logger::Get().Log("Releasing pixel shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing pixel shader");
pixel_shader_->Release(); pixel_shader_->Release();
pixel_shader_ = 0; pixel_shader_ = 0;
Logger::Get().Log("Pixel shader released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Pixel shader released");
} }
// Release the vertex shader. // Release the vertex shader.
if (vertex_shader_) if (vertex_shader_)
{ {
Logger::Get().Log("Releasing vertex shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing vertex shader");
vertex_shader_->Release(); vertex_shader_->Release();
vertex_shader_ = 0; vertex_shader_ = 0;
Logger::Get().Log("Vertex shader released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Vertex shader released");
} }
Logger::Get().Log("Shader shut down", __FILE__, __LINE__); LOG_SHUTDOWN("Shader shut down");
return; return;
} }
@@ -301,7 +301,7 @@ void color_shader_class::output_shader_error_message(ID3D10Blob* errorMessage, H
bool color_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, bool color_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
XMMATRIX projectionMatrix) XMMATRIX projectionMatrix)
{ {
Logger::Get().Log("Setting shader parameters", __FILE__, __LINE__); LOG_DEBUG("Setting shader parameters");
HRESULT result; HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
@@ -317,8 +317,8 @@ bool color_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -338,7 +338,7 @@ bool color_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
// Finanly set the constant buffer in the vertex shader with the updated values. // Finanly set the constant buffer in the vertex shader with the updated values.
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &matrix_buffer_); deviceContext->VSSetConstantBuffers(bufferNumber, 1, &matrix_buffer_);
return true; R_TRUE
} }
void color_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void color_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -7,7 +7,6 @@ depth_shader_class::depth_shader_class()
pixel_shader_ = 0; pixel_shader_ = 0;
layout_ = 0; layout_ = 0;
matrix_buffer_ = 0; matrix_buffer_ = 0;
sample_state_ = 0;
} }
@@ -23,7 +22,7 @@ depth_shader_class::~depth_shader_class()
bool depth_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool depth_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing texture shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing texture shader");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -33,29 +32,29 @@ bool depth_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/depth.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/depth.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying stirng", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying stirng");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/depth.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/depth.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying stirng", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying stirng");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing shader");
return false; R_FALSE
} }
Logger::Get().Log("Texture shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Texture shader initialized");
return true; R_TRUE
} }
void depth_shader_class::shutdown() void depth_shader_class::shutdown()
@@ -67,28 +66,27 @@ void depth_shader_class::shutdown()
} }
bool depth_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, bool depth_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture) XMMATRIX projectionMatrix)
{ {
bool result; bool result;
// Set the shader parameters that it will use for rendering. // Set the shader parameters that it will use for rendering.
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix);
if (!result) if (!result)
{ {
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error setting shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -97,7 +95,6 @@ bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
D3D11_INPUT_ELEMENT_DESC polygonLayout[2]; D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
unsigned int numElements; unsigned int numElements;
D3D11_BUFFER_DESC matrixBufferDesc; D3D11_BUFFER_DESC matrixBufferDesc;
D3D11_SAMPLER_DESC samplerDesc;
// initialize the pointers this function will use to null. // initialize the pointers this function will use to null.
@@ -117,10 +114,10 @@ bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -136,26 +133,26 @@ bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
// This setup needs to match the VertexType stucture in the ModelClass and in the shader. // This setup needs to match the VertexType stucture in the ModelClass and in the shader.
@@ -183,8 +180,8 @@ bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -206,47 +203,18 @@ bool depth_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
}
// Create a texture sampler state description.
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 1;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 0;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 0;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
// Create the texture sampler state.
result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result))
{
Logger::Get().Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void depth_shader_class::shutdown_shader() void depth_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down shader");
// Release the sampler state.
if (sample_state_)
{
sample_state_->Release();
sample_state_ = 0;
}
// Release the matrix constant buffer. // Release the matrix constant buffer.
if (matrix_buffer_) if (matrix_buffer_)
@@ -276,7 +244,7 @@ void depth_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shader shut down");
return; return;
} }
@@ -317,7 +285,7 @@ void depth_shader_class::output_shader_error_message(ID3D10Blob* errorMessage, H
} }
bool depth_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, bool depth_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture) XMMATRIX projectionMatrix)
{ {
HRESULT result; HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
@@ -334,8 +302,8 @@ bool depth_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -354,10 +322,8 @@ bool depth_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
// Finanly set the constant buffer in the vertex shader with the updated values. // Finanly set the constant buffer in the vertex shader with the updated values.
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &matrix_buffer_); deviceContext->VSSetConstantBuffers(bufferNumber, 1, &matrix_buffer_);
// Set shader texture resource in the pixel shader.
deviceContext->PSSetShaderResources(0, 1, &texture);
return true; R_TRUE
} }
void depth_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void depth_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)
@@ -368,8 +334,6 @@ void depth_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int i
// Set the vertex and pixel shaders that will be used to render this triangle. // Set the vertex and pixel shaders that will be used to render this triangle.
deviceContext->VSSetShader(vertex_shader_, NULL, 0); deviceContext->VSSetShader(vertex_shader_, NULL, 0);
deviceContext->PSSetShader(pixel_shader_, NULL, 0); deviceContext->PSSetShader(pixel_shader_, NULL, 0);
// Set the sampler state in the pixel shader.
deviceContext->PSSetSamplers(0, 1, &sample_state_);
// render the triangle. // render the triangle.
deviceContext->DrawIndexed(indexCount, 0, 0); deviceContext->DrawIndexed(indexCount, 0, 0);

View File

@@ -24,7 +24,7 @@ font_shader_class::~font_shader_class()
bool font_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool font_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing font_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing font_shader_class");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -35,29 +35,29 @@ bool font_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/font.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/font.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/font.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/font.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing shader");
return false; R_FALSE
} }
Logger::Get().Log("font_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true; LOG_INIT("font_shader_class initialized");
R_TRUE
} }
void font_shader_class::shutdown() void font_shader_class::shutdown()
@@ -78,19 +78,19 @@ bool font_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCoun
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, pixelColor); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, pixelColor);
if (!result) if (!result)
{ {
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error setting shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -121,10 +121,10 @@ bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -140,26 +140,26 @@ bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -188,8 +188,8 @@ bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -211,8 +211,8 @@ bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -234,8 +234,8 @@ bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating sampler state");
return false; R_FALSE
} }
// Setup the description of the dynamic pixel constant buffer that is in the pixel shader. // Setup the description of the dynamic pixel constant buffer that is in the pixel shader.
@@ -250,18 +250,18 @@ bool font_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR
result = device->CreateBuffer(&pixelBufferDesc, NULL, &pixel_buffer_); result = device->CreateBuffer(&pixelBufferDesc, NULL, &pixel_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void font_shader_class::shutdown_shader() void font_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down shader");
// Release the pixel constant buffer. // Release the pixel constant buffer.
if (pixel_buffer_) if (pixel_buffer_)
@@ -305,7 +305,7 @@ void font_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shader shut down");
return; return;
} }
@@ -365,8 +365,8 @@ bool font_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -393,8 +393,8 @@ bool font_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext
result = deviceContext->Map(pixel_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(pixel_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the pixel constant buffer. // Get a pointer to the data in the pixel constant buffer.
@@ -412,7 +412,7 @@ bool font_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContext
// Now set the pixel constant buffer in the pixel shader with the updated value. // Now set the pixel constant buffer in the pixel shader with the updated value.
deviceContext->PSSetConstantBuffers(bufferNumber, 1, &pixel_buffer_); deviceContext->PSSetConstantBuffers(bufferNumber, 1, &pixel_buffer_);
return true; R_TRUE
} }
void font_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void font_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -23,7 +23,7 @@ light_map_shader_class::~light_map_shader_class()
bool light_map_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool light_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing light_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing light_map_shader_class");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -34,29 +34,29 @@ bool light_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/lightmap.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/lightmap.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/lightmap.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/lightmap.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing shader");
return false; R_FALSE
} }
Logger::Get().Log("light_map_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("light_map_shader_class initialized");
return true; R_TRUE
} }
@@ -74,25 +74,24 @@ bool light_map_shader_class::render(ID3D11DeviceContext* deviceContext, int inde
{ {
bool result; bool result;
// Set the shader parameters that it will use for rendering. // Set the shader parameters that it will use for rendering.
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
if (!result) if (!result)
{ {
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error setting shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool light_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool light_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
ID3D10Blob* vertexShaderBuffer; ID3D10Blob* vertexShaderBuffer;
@@ -121,10 +120,10 @@ bool light_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -140,26 +139,26 @@ bool light_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -195,8 +194,8 @@ bool light_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -218,8 +217,8 @@ bool light_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -241,19 +240,19 @@ bool light_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating sampler state");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void light_map_shader_class::shutdown_shader() void light_map_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down light_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down light_map_shader_class");
// Release the sampler state. // Release the sampler state.
if (sample_state_) if (sample_state_)
@@ -290,7 +289,7 @@ void light_map_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("light_map_shader_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("light_map_shader_class shut down");
return; return;
} }
@@ -350,8 +349,8 @@ bool light_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCo
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -375,7 +374,7 @@ bool light_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCo
deviceContext->PSSetShaderResources(0, 1, &texture1); deviceContext->PSSetShaderResources(0, 1, &texture1);
deviceContext->PSSetShaderResources(1, 1, &texture2); deviceContext->PSSetShaderResources(1, 1, &texture2);
return true; R_TRUE
} }

View File

@@ -30,7 +30,7 @@ light_shader_class::~light_shader_class()
bool light_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool light_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing light_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing light_shader_class");
wchar_t vsFilename[128]; wchar_t vsFilename[128];
wchar_t psFilename[128]; wchar_t psFilename[128];
@@ -41,28 +41,28 @@ bool light_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/light.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/light.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/light.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/light.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize shader");
return false; R_FALSE
} }
Logger::Get().Log("light_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("light_shader_class initialized");
return true; R_TRUE
} }
@@ -84,20 +84,20 @@ bool light_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCou
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientClor); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientClor);
if(!result) if(!result)
{ {
Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -129,10 +129,10 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -147,26 +147,26 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -203,8 +203,8 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
&layout_); &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -233,8 +233,8 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sampler state");
return false; R_FALSE
} }
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader. // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
@@ -249,8 +249,8 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create matrix buffer");
return false; R_FALSE
} }
@@ -267,8 +267,8 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&cameraBufferDesc, NULL, &camera_buffer_); result = device->CreateBuffer(&cameraBufferDesc, NULL, &camera_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create camera buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create camera buffer");
return false; R_FALSE
} }
// Setup the description of the dynamic constant buffer that is in the pixel shader. // Setup the description of the dynamic constant buffer that is in the pixel shader.
@@ -283,8 +283,8 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&lightColorBufferDesc, NULL, &light_color_buffer_); result = device->CreateBuffer(&lightColorBufferDesc, NULL, &light_color_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create light color buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create light color buffer");
return false; R_FALSE
} }
// Setup the description of the dynamic constant buffer that is in the vertex shader. // Setup the description of the dynamic constant buffer that is in the vertex shader.
@@ -299,19 +299,19 @@ bool light_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&lightPositionBufferDesc, NULL, &light_position_buffer_); result = device->CreateBuffer(&lightPositionBufferDesc, NULL, &light_position_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create light position buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create light position buffer");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void light_shader_class::shutdown_shader() void light_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down light_shader_class", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down light_shader_class");
// Release the light constant buffers. // Release the light constant buffers.
if (light_color_buffer_) if (light_color_buffer_)
@@ -375,7 +375,7 @@ void light_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("light_shader_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("light_shader_class shut down");
return; return;
} }
@@ -436,8 +436,8 @@ bool light_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map matrix buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -461,16 +461,16 @@ bool light_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(camera_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(camera_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map camera buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map camera buffer");
return false; R_FALSE
} }
// Lock the light position constant buffer so it can be written to. // Lock the light position constant buffer so it can be written to.
result = deviceContext->Map(light_position_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(light_position_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map light position buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map light position buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -498,8 +498,8 @@ bool light_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(light_color_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(light_color_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map light color buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map light color buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -521,7 +521,7 @@ bool light_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
deviceContext->PSSetConstantBuffers(bufferNumber, 1, &light_color_buffer_); deviceContext->PSSetConstantBuffers(bufferNumber, 1, &light_color_buffer_);
return true; R_TRUE
} }

View File

@@ -1,5 +1,4 @@
#include "master_shader.h" #include "master_shader.h"
#include "Logger.h"
master_shader::master_shader() master_shader::master_shader()
{ {
@@ -16,9 +15,9 @@ master_shader::~master_shader()
bool master_shader::initialize(ID3D11Device* device, HWND hwnd) bool master_shader::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing master_shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing master_shader");
bool success = false; bool success = false;
return true; R_TRUE
} }

View File

@@ -26,7 +26,7 @@ multi_texture_shader_class::~multi_texture_shader_class()
bool multi_texture_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool multi_texture_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing multi_texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing multi_texture_shader_class");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -37,29 +37,29 @@ bool multi_texture_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/multitexture.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/multitexture.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to set the filename of the vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set the filename of the vertex shader");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/multitexture.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/multitexture.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to set the filename of the pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set the filename of the pixel shader");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize the vertex and pixel shaders", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize the vertex and pixel shaders");
return false; R_FALSE
} }
Logger::Get().Log("multi_texture_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("multi_texture_shader_class initialized");
return true; R_TRUE
} }
void multi_texture_shader_class::shutdown() void multi_texture_shader_class::shutdown()
@@ -80,19 +80,19 @@ bool multi_texture_shader_class::render(ID3D11DeviceContext* deviceContext, int
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to set the shader parameters that it will use for rendering", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set the shader parameters that it will use for rendering");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool multi_texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool multi_texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing the shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing the shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -122,10 +122,10 @@ bool multi_texture_shader_class::initialize_shader(ID3D11Device* device, HWND hw
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Failed to compile the vertex shader code", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile the vertex shader code");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -141,26 +141,26 @@ bool multi_texture_shader_class::initialize_shader(ID3D11Device* device, HWND hw
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Failed to compile the pixel shader code", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile the pixel shader code");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the vertex shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the vertex shader from the buffer");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the pixel shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the pixel shader from the buffer");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -196,8 +196,8 @@ bool multi_texture_shader_class::initialize_shader(ID3D11Device* device, HWND hw
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the vertex input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the vertex input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -219,8 +219,8 @@ bool multi_texture_shader_class::initialize_shader(ID3D11Device* device, HWND hw
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the constant buffer pointer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the constant buffer pointer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -242,18 +242,18 @@ bool multi_texture_shader_class::initialize_shader(ID3D11Device* device, HWND hw
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the texture sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the texture sampler state");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void multi_texture_shader_class::shutdown_shader() void multi_texture_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down the shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down the shader");
// Release the sampler state. // Release the sampler state.
if (sample_state_) if (sample_state_)
@@ -290,7 +290,7 @@ void multi_texture_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shader shut down");
return; return;
} }
@@ -348,8 +348,8 @@ bool multi_texture_shader_class::set_shader_parameters(ID3D11DeviceContext* devi
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to lock the constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to lock the constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -373,7 +373,7 @@ bool multi_texture_shader_class::set_shader_parameters(ID3D11DeviceContext* devi
deviceContext->PSSetShaderResources(0, 1, &texture1); deviceContext->PSSetShaderResources(0, 1, &texture1);
deviceContext->PSSetShaderResources(1, 1, &texture2); deviceContext->PSSetShaderResources(1, 1, &texture2);
return true; R_TRUE
} }
void multi_texture_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void multi_texture_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -24,7 +24,7 @@ normal_map_shader_class::~normal_map_shader_class()
bool normal_map_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool normal_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing normal map shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing normal map shader");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -35,29 +35,29 @@ bool normal_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/normalmap.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/normalmap.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to set the filename of the vertex shader", __FILE__, __LINE__); LOG_ERROR("Failed to set the filename of the vertex shader");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/normalmap.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/normalmap.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to set the filename of the pixel shader", __FILE__, __LINE__); LOG_ERROR("Failed to set the filename of the pixel shader");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize the vertex and pixel shaders", __FILE__, __LINE__); LOG_ERROR("Failed to initialize the vertex and pixel shaders");
return false; R_FALSE
} }
Logger::Get().Log("Successfully initialized normal map shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Successfully initialized normal map shader");
return true; R_TRUE
} }
@@ -79,20 +79,20 @@ bool normal_map_shader_class::render(ID3D11DeviceContext* deviceContext, int ind
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, lightDirection, diffuseColor); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, lightDirection, diffuseColor);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to set the shader parameters that will be used for rendering", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set the shader parameters that will be used for rendering");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing normal map shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing normal map shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -123,10 +123,10 @@ bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Failed to compile the vertex shader code", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile the vertex shader code");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -142,26 +142,26 @@ bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Failed to compile the pixel shader code", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile the pixel shader code");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the vertex shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the vertex shader from the buffer");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the pixel shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the pixel shader from the buffer");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -213,8 +213,8 @@ bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the vertex input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the vertex input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -236,8 +236,8 @@ bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the constant buffer pointer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the constant buffer pointer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -259,8 +259,8 @@ bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the texture sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the texture sampler state");
return false; R_FALSE
} }
// Setup the description of the light dynamic constant buffer that is in the pixel shader. // Setup the description of the light dynamic constant buffer that is in the pixel shader.
@@ -275,19 +275,19 @@ bool normal_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&lightBufferDesc, NULL, &light_buffer_); result = device->CreateBuffer(&lightBufferDesc, NULL, &light_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create the light constant buffer pointer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create the light constant buffer pointer");
return false; R_FALSE
} }
Logger::Get().Log("Successfully initialized normal map shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Successfully initialized normal map shader");
return true; R_TRUE
} }
void normal_map_shader_class::shutdown_shader() void normal_map_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down normal map shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down normal map shader");
// Release the light constant buffer. // Release the light constant buffer.
if (light_buffer_) if (light_buffer_)
@@ -331,7 +331,7 @@ void normal_map_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Successfully shut down normal map shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Successfully shut down normal map shader");
return; return;
} }
@@ -392,8 +392,8 @@ bool normal_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to lock the constant buffer so it can be written to", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to lock the constant buffer so it can be written to");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -421,8 +421,8 @@ bool normal_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
result = deviceContext->Map(light_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(light_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to lock the light constant buffer so it can be written to", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to lock the light constant buffer so it can be written to");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -446,7 +446,7 @@ bool normal_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
deviceContext->PSSetShaderResources(0, 1, &texture1); deviceContext->PSSetShaderResources(0, 1, &texture1);
deviceContext->PSSetShaderResources(1, 1, &texture2); deviceContext->PSSetShaderResources(1, 1, &texture2);
return true; R_TRUE
} }

View File

@@ -21,7 +21,7 @@ reflection_shader_class::~reflection_shader_class()
bool reflection_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool reflection_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing reflection shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing reflection shader");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -32,29 +32,29 @@ bool reflection_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/reflection.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/reflection.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/reflection.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/reflection.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing shader");
return false; R_FALSE
} }
Logger::Get().Log("Reflection shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Reflection shader initialized");
return true; R_TRUE
} }
void reflection_shader_class::shutdown() void reflection_shader_class::shutdown()
@@ -70,24 +70,23 @@ bool reflection_shader_class::render(ID3D11DeviceContext* deviceContext, int ind
{ {
bool result; bool result;
// Set the shader parameters that it will use for rendering. // Set the shader parameters that it will use for rendering.
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, reflectionTexture, reflectionMatrix); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, reflectionTexture, reflectionMatrix);
if (!result) if (!result)
{ {
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error setting shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing reflection shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing reflection shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -118,10 +117,10 @@ bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
result = D3DCompileFromFile(psFilename, NULL, NULL, "ReflectionPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, result = D3DCompileFromFile(psFilename, NULL, NULL, "ReflectionPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0,
@@ -136,26 +135,26 @@ bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -183,8 +182,8 @@ bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -206,8 +205,8 @@ bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
@@ -228,8 +227,8 @@ bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating sampler state");
return false; R_FALSE
} }
// Setup the description of the reflection dynamic constant buffer that is in the vertex shader. // Setup the description of the reflection dynamic constant buffer that is in the vertex shader.
reflectionBufferDesc.Usage = D3D11_USAGE_DYNAMIC; reflectionBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
@@ -243,18 +242,18 @@ bool reflection_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&reflectionBufferDesc, NULL, &reflection_buffer_); result = device->CreateBuffer(&reflectionBufferDesc, NULL, &reflection_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
Logger::Get().Log("Reflection shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Reflection shader initialized");
return true; R_TRUE
} }
void reflection_shader_class::shutdown_shader() void reflection_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down reflection shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down reflection shader");
// Release the reflection constant buffer. // Release the reflection constant buffer.
if (reflection_buffer_) if (reflection_buffer_)
@@ -298,7 +297,7 @@ void reflection_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Reflection shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Reflection shader shut down");
return; return;
} }
@@ -361,8 +360,8 @@ bool reflection_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -386,8 +385,8 @@ bool reflection_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
result = deviceContext->Map(reflection_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(reflection_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the matrix constant buffer. // Get a pointer to the data in the matrix constant buffer.
@@ -411,7 +410,7 @@ bool reflection_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
// Set the reflection texture resource in the pixel shader. // Set the reflection texture resource in the pixel shader.
deviceContext->PSSetShaderResources(1, 1, &reflectionTexture); deviceContext->PSSetShaderResources(1, 1, &reflectionTexture);
return true; R_TRUE
} }

View File

@@ -25,6 +25,8 @@ refraction_shader_class::~refraction_shader_class()
bool refraction_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool refraction_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
LOG_INIT("Initializing refraction shader");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
wchar_t psFilename[128]; wchar_t psFilename[128];
@@ -34,24 +36,29 @@ bool refraction_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/refraction.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/refraction.vs");
if (error != 0) if (error != 0)
{ {
return false; LOG_ERROR("Error copying vertex shader filename");
R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/refraction.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/refraction.ps");
if (error != 0) if (error != 0)
{ {
return false; LOG_ERROR("Error copying pixel shader filename");
R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error initializing shader");
R_FALSE
} }
return true; LOG_INIT("Refraction shader initialized");
R_TRUE
} }
@@ -68,23 +75,25 @@ bool refraction_shader_class::render(ID3D11DeviceContext* deviceContext, int ind
{ {
bool result; bool result;
// Set the shader parameters that it will use for rendering. // Set the shader parameters that it will use for rendering.
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error setting shader parameters");
R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
LOG_INIT("Initializing refraction shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
ID3D10Blob* vertexShaderBuffer; ID3D10Blob* vertexShaderBuffer;
@@ -118,7 +127,7 @@ bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK); MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -134,24 +143,27 @@ bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
LOG_ERROR("Missing pixel shader file");
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK); MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating vertex shader");
R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating pixel shader");
R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -187,7 +199,8 @@ bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating input layout");
R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -209,7 +222,8 @@ bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating matrix buffer");
R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -231,7 +245,8 @@ bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating sampler state");
R_FALSE
} }
// Setup the description of the light dynamic constant buffer that is in the pixel shader. // Setup the description of the light dynamic constant buffer that is in the pixel shader.
@@ -247,7 +262,8 @@ bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&lightBufferDesc, NULL, &light_buffer_); result = device->CreateBuffer(&lightBufferDesc, NULL, &light_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating light buffer");
R_FALSE
} }
// Setup the description of the clip plane dynamic constant buffer that is in the vertex shader. // Setup the description of the clip plane dynamic constant buffer that is in the vertex shader.
@@ -262,15 +278,20 @@ bool refraction_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd,
result = device->CreateBuffer(&clipPlaneBufferDesc, NULL, &clip_plane_buffer_); result = device->CreateBuffer(&clipPlaneBufferDesc, NULL, &clip_plane_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating clip plane buffer");
R_FALSE
} }
return true; LOG_INIT("Refraction shader initialized");
R_TRUE
} }
void refraction_shader_class::shutdown_shader() void refraction_shader_class::shutdown_shader()
{ {
LOG_SHUTDOWN("Shutting down refraction shader");
// Release the clip plane constant buffer. // Release the clip plane constant buffer.
if (clip_plane_buffer_) if (clip_plane_buffer_)
{ {
@@ -320,6 +341,8 @@ void refraction_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
LOG_SHUTDOWN("Refraction shader shut down");
return; return;
} }
@@ -380,7 +403,8 @@ bool refraction_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error mapping matrix buffer");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -404,7 +428,8 @@ bool refraction_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
result = deviceContext->Map(clip_plane_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(clip_plane_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result)) if(FAILED(result))
{ {
return false; LOG_ERROR("Error mapping clip plane buffer");
R_FALSE
} }
// Get a pointer to the data in the clip plane constant buffer. // Get a pointer to the data in the clip plane constant buffer.
@@ -429,7 +454,8 @@ bool refraction_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
result = deviceContext->Map(light_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(light_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result)) if(FAILED(result))
{ {
return false; LOG_ERROR("Error mapping light buffer");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -450,7 +476,7 @@ bool refraction_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceC
// Finally set the light constant buffer in the pixel shader with the updated values. // Finally set the light constant buffer in the pixel shader with the updated values.
deviceContext->PSSetConstantBuffers(bufferNumber, 1, &light_buffer_); deviceContext->PSSetConstantBuffers(bufferNumber, 1, &light_buffer_);
return true; R_TRUE
} }

View File

@@ -30,7 +30,7 @@ shader_manager_class::~shader_manager_class()
bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd) bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing shader_manager_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader_manager_class");
bool result; bool result;
@@ -39,8 +39,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = texture_shader_->initialize(device, hwnd); result = texture_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing texture_shader_class");
return false; R_FALSE
} }
// Create and initialize the normal map shader object. // Create and initialize the normal map shader object.
@@ -48,8 +48,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = normal_map_shader_->initialize(device, hwnd); result = normal_map_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing normal_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing normal_map_shader_class");
return false; R_FALSE
} }
// Create and initialize the multitexture shader object. // Create and initialize the multitexture shader object.
@@ -57,8 +57,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = multitexture_shader_->initialize(device, hwnd); result = multitexture_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing multi_texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing multi_texture_shader_class");
return false; R_FALSE
} }
// Create and initialize the translate shader object. // Create and initialize the translate shader object.
@@ -66,8 +66,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = translate_shader_->initialize(device, hwnd); result = translate_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing translate_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing translate_shader_class");
return false; R_FALSE
} }
// Create and initialize the alpha map shader object. // Create and initialize the alpha map shader object.
@@ -75,8 +75,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = alpha_map_shader_->initialize(device, hwnd); result = alpha_map_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing alpha_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing alpha_map_shader_class");
return false; R_FALSE
} }
// Create and initialize the specular map shader object. // Create and initialize the specular map shader object.
@@ -84,8 +84,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = spec_map_shader_->initialize(device, hwnd); result = spec_map_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing spec_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing spec_map_shader_class");
return false; R_FALSE
} }
// Create and initialize the transparent shader object. // Create and initialize the transparent shader object.
@@ -93,8 +93,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = transparent_shader_->initialize(device, hwnd); result = transparent_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing transparent_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing transparent_shader_class");
return false; R_FALSE
} }
// Create and initialize the light shader object. // Create and initialize the light shader object.
@@ -102,8 +102,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = light_shader_->initialize(device, hwnd); result = light_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing light_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing light_shader_class");
return false; R_FALSE
} }
// Create and initialize the light map shader object. // Create and initialize the light map shader object.
@@ -111,8 +111,8 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = light_map_shader_->initialize(device, hwnd); result = light_map_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing light_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing light_map_shader_class");
return false; R_FALSE
} }
// Create and initialize the refraction shader object. // Create and initialize the refraction shader object.
@@ -120,7 +120,7 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = refraction_shader_->initialize(device, hwnd); result = refraction_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
// Create and initialize the water shader object. // Create and initialize the water shader object.
@@ -128,47 +128,47 @@ bool shader_manager_class::initialize(ID3D11Device* device, HWND hwnd)
result = water_shader_->initialize(device, hwnd); result = water_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
cel_shading_shader_ = new celshade_class; cel_shading_shader_ = new celshade_class;
result = cel_shading_shader_->initialize(device, hwnd); result = cel_shading_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
sunlight_shader_ = new sunlight_shader_class; sunlight_shader_ = new sunlight_shader_class;
result = sunlight_shader_->initialize(device, hwnd); result = sunlight_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
skybox_shader_ = new skybox_shader_class; skybox_shader_ = new skybox_shader_class;
result = skybox_shader_->Initialize(device, hwnd); result = skybox_shader_->Initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing skybox_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing skybox_shader_class");
return false; R_FALSE
} }
depth_shader_ = new depth_shader_class; depth_shader_ = new depth_shader_class;
result = depth_shader_->initialize(device, hwnd); result = depth_shader_->initialize(device, hwnd);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing depth_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing depth_shader_class");
return false; R_FALSE
} }
Logger::Get().Log("shader_manager_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("shader_manager_class initialized");
return true; R_TRUE
} }
void shader_manager_class::shutdown() void shader_manager_class::shutdown()
{ {
Logger::Get().Log("Shutting down shader_manager_class", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down shader_manager_class");
// Release the normal map shader object. // Release the normal map shader object.
if (normal_map_shader_) if (normal_map_shader_)
@@ -287,7 +287,9 @@ void shader_manager_class::shutdown()
depth_shader_ = 0; depth_shader_ = 0;
} }
Logger::Get().Log("shader_manager_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("shader_manager_class shut down");
return;
} }
bool shader_manager_class::render_texture_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_texture_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -298,11 +300,11 @@ bool shader_manager_class::render_texture_shader(ID3D11DeviceContext* deviceCont
result = texture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture); result = texture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture);
if (!result) if (!result)
{ {
Logger::Get().Log("Error rendering texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error rendering texture_shader_class");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_normal_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_normal_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -313,11 +315,11 @@ bool shader_manager_class::render_normal_map_shader(ID3D11DeviceContext* deviceC
result = normal_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, colorTexture, normalTexture, lightDirection, diffuseColor); result = normal_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, colorTexture, normalTexture, lightDirection, diffuseColor);
if (!result) if (!result)
{ {
Logger::Get().Log("Error rendering normal_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error rendering normal_map_shader_class");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_multitexture_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_multitexture_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -328,11 +330,11 @@ bool shader_manager_class::render_multitexture_shader(ID3D11DeviceContext* devic
result = multitexture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2); result = multitexture_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
if (!result) if (!result)
{ {
Logger::Get().Log("Error rendering multi_texture_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error rendering multi_texture_shader_class");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_translate_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_translate_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -343,11 +345,11 @@ bool shader_manager_class::render_translate_shader(ID3D11DeviceContext* deviceCo
result = translate_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, valeur); result = translate_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, valeur);
if (!result) if (!result)
{ {
Logger::Get().Log("Error rendering translate_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error rendering translate_shader_class");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_alpha_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_alpha_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -358,11 +360,11 @@ bool shader_manager_class::render_alpha_map_shader(ID3D11DeviceContext* deviceCo
result = alpha_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3); result = alpha_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3);
if (!result) if (!result)
{ {
Logger::Get().Log("Error rendering alpha_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error rendering alpha_map_shader_class");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_spec_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_spec_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -375,11 +377,11 @@ bool shader_manager_class::render_spec_map_shader(ID3D11DeviceContext* deviceCon
diffuseColor, cameraPosition, specularColor, specularPower); diffuseColor, cameraPosition, specularColor, specularPower);
if (!result) if (!result)
{ {
Logger::Get().Log("Error rendering spec_map_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error rendering spec_map_shader_class");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_transparent_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_transparent_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -390,11 +392,11 @@ bool shader_manager_class::render_transparent_shader(ID3D11DeviceContext* device
result = transparent_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, blendAmount); result = transparent_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, blendAmount);
if (!result) if (!result)
{ {
Logger::Get().Log("Error rendering transparent_shader_class", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error rendering transparent_shader_class");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::renderlight_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::renderlight_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -405,10 +407,11 @@ bool shader_manager_class::renderlight_shader(ID3D11DeviceContext* deviceContext
result = light_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientColor); result = light_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition, ambientColor);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering light_shader_class");
R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::renderlight_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, bool shader_manager_class::renderlight_map_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
@@ -419,10 +422,11 @@ bool shader_manager_class::renderlight_map_shader(ID3D11DeviceContext* deviceCon
result = light_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2); result = light_map_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering light_map_shader_class");
R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_refraction_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_refraction_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -433,10 +437,11 @@ bool shader_manager_class::render_refraction_shader(ID3D11DeviceContext* deviceC
result = refraction_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane); result = refraction_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambientColor, diffuseColor, lightPosition, clipPlane);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering refraction_shader_class");
R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_water_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_water_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -449,10 +454,11 @@ bool shader_manager_class::render_water_shader(ID3D11DeviceContext* deviceContex
refractionTexture, normalTexture, waterTranslation, reflectRefractScale); refractionTexture, normalTexture, waterTranslation, reflectRefractScale);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering water_shader_class");
R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_cel_shading_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_cel_shading_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -463,10 +469,11 @@ bool shader_manager_class::render_cel_shading_shader(ID3D11DeviceContext* device
result = cel_shading_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); result = cel_shading_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering celshade_class");
R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_sunlight_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_sunlight_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -477,10 +484,11 @@ bool shader_manager_class::render_sunlight_shader(ID3D11DeviceContext* deviceCon
result = sunlight_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); result = sunlight_shader_->render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering sunlight_shader_class");
R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_skybox_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, bool shader_manager_class::render_skybox_shader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix,
@@ -491,10 +499,11 @@ bool shader_manager_class::render_skybox_shader(ID3D11DeviceContext* deviceConte
result = skybox_shader_->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); result = skybox_shader_->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering skybox_shader_class");
R_FALSE
} }
return true; R_TRUE
} }
bool shader_manager_class::render_depth_shader( bool shader_manager_class::render_depth_shader(
@@ -502,17 +511,17 @@ bool shader_manager_class::render_depth_shader(
int indexCount, int indexCount,
XMMATRIX worldMatrix, XMMATRIX worldMatrix,
XMMATRIX viewMatrix, XMMATRIX viewMatrix,
XMMATRIX projectionMatrix, XMMATRIX projectionMatrix
ID3D11ShaderResourceView* texture
) )
{ {
bool result; bool result;
result = depth_shader_->render(context, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture); result = depth_shader_->render(context, indexCount, worldMatrix, viewMatrix, projectionMatrix);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Error rendering depth_shader_class");
R_FALSE
} }
return true; R_TRUE
} }

View File

@@ -30,7 +30,7 @@ skybox_shader_class::~skybox_shader_class()
bool skybox_shader_class::Initialize(ID3D11Device* device, HWND hwnd) bool skybox_shader_class::Initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing LightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing LightShaderClass");
wchar_t vsFilename[128]; wchar_t vsFilename[128];
wchar_t psFilename[128]; wchar_t psFilename[128];
@@ -41,28 +41,28 @@ bool skybox_shader_class::Initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/skybox.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/skybox.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/skybox.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/skybox.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// Initialize the vertex and pixel shaders. // Initialize the vertex and pixel shaders.
result = InitializeShader(device, hwnd, vsFilename, psFilename); result = InitializeShader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize shader");
return false; R_FALSE
} }
Logger::Get().Log("skybox_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("skybox_shader_class initialized");
return true; R_TRUE
} }
@@ -84,20 +84,20 @@ bool skybox_shader_class::Render(ID3D11DeviceContext* deviceContext, int indexCo
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
RenderShader(deviceContext, indexCount); RenderShader(deviceContext, indexCount);
return true; R_TRUE
} }
bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -124,9 +124,9 @@ bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
} }
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -139,25 +139,25 @@ bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
} }
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -192,8 +192,8 @@ bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &m_layout); result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &m_layout);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -222,8 +222,8 @@ bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateSamplerState(&samplerDesc, &m_sampleState); result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sampler state");
return false; R_FALSE
} }
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader. // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
@@ -238,8 +238,8 @@ bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer); result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create matrix buffer");
return false; R_FALSE
} }
// Setup the description of the dynamic sunlight constant buffer that is in the pixel shader. // Setup the description of the dynamic sunlight constant buffer that is in the pixel shader.
@@ -254,13 +254,13 @@ bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&sunlightBufferDesc, NULL, &m_sunlightBuffer); result = device->CreateBuffer(&sunlightBufferDesc, NULL, &m_sunlightBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sunlight buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sunlight buffer");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
@@ -268,7 +268,7 @@ bool skybox_shader_class::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
void skybox_shader_class::ShutdownShader() void skybox_shader_class::ShutdownShader()
{ {
Logger::Get().Log("Shutting down SunLightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down SunLightShaderClass");
// Release the light constant buffers. // Release the light constant buffers.
if (m_sunlightColorBuffer) if (m_sunlightColorBuffer)
@@ -332,7 +332,7 @@ void skybox_shader_class::ShutdownShader()
m_vertexShader = 0; m_vertexShader = 0;
} }
Logger::Get().Log("SunLightShaderClass shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("SunLightShaderClass shut down");
return; return;
} }
@@ -379,7 +379,6 @@ bool skybox_shader_class::SetShaderParameters(ID3D11DeviceContext* deviceContext
HRESULT result; HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
MatrixBufferType* dataPtr; MatrixBufferType* dataPtr;
CameraBufferType* dataPtr2;
SkyboxBufferType* dataPtr3; SkyboxBufferType* dataPtr3;
unsigned int bufferNumber; unsigned int bufferNumber;
@@ -392,7 +391,7 @@ bool skybox_shader_class::SetShaderParameters(ID3D11DeviceContext* deviceContext
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -416,7 +415,7 @@ bool skybox_shader_class::SetShaderParameters(ID3D11DeviceContext* deviceContext
result = deviceContext->Map(m_sunlightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(m_sunlightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -440,7 +439,7 @@ bool skybox_shader_class::SetShaderParameters(ID3D11DeviceContext* deviceContext
// Set shader texture resource in the pixel shader. // Set shader texture resource in the pixel shader.
deviceContext->PSSetShaderResources(0, 1, &texture); deviceContext->PSSetShaderResources(0, 1, &texture);
return true; R_TRUE
} }
void skybox_shader_class::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount) void skybox_shader_class::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -25,6 +25,9 @@ spec_map_shader_class::~spec_map_shader_class()
bool spec_map_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool spec_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
LOG_INIT("Initializing SpecMapShaderClass");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
wchar_t psFilename[128]; wchar_t psFilename[128];
@@ -34,24 +37,24 @@ bool spec_map_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/specmap.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/specmap.vs");
if (error != 0) if (error != 0)
{ {
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/specmap.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/specmap.ps");
if (error != 0) if (error != 0)
{ {
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
return true; R_TRUE
} }
@@ -75,13 +78,14 @@ bool spec_map_shader_class::render(ID3D11DeviceContext* deviceContext, int index
cameraPosition, specularColor, specularPower); cameraPosition, specularColor, specularPower);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Failed to set shader parameters in SpecMapShaderClass");
R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
@@ -120,7 +124,7 @@ bool spec_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK); MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -139,21 +143,23 @@ bool spec_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK); MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to create vertex shader in SpecMapShaderClass");
R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to create pixel shader in SpecMapShaderClass");
R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -205,7 +211,8 @@ bool spec_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to create input layout in SpecMapShaderClass");
R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -227,7 +234,8 @@ bool spec_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to create uniform buffer in SpecMapShaderClass");
R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -249,7 +257,8 @@ bool spec_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to create sample state in SpecMapShaderClass");
R_FALSE
} }
// Setup the description of the light dynamic constant buffer that is in the pixel shader. // Setup the description of the light dynamic constant buffer that is in the pixel shader.
@@ -264,7 +273,8 @@ bool spec_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateBuffer(&lightBufferDesc, NULL, &light_buffer_); result = device->CreateBuffer(&lightBufferDesc, NULL, &light_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to create light buffer in SpecMapShaderClass");
R_FALSE
} }
// Setup the description of the camera dynamic constant buffer that is in the vertex shader. // Setup the description of the camera dynamic constant buffer that is in the vertex shader.
@@ -279,15 +289,18 @@ bool spec_map_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateBuffer(&cameraBufferDesc, NULL, &camera_buffer_); result = device->CreateBuffer(&cameraBufferDesc, NULL, &camera_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to create camera buffer in SpecMapShaderClass");
R_FALSE
} }
return true; R_TRUE
} }
void spec_map_shader_class::shutdown_shader() void spec_map_shader_class::shutdown_shader()
{ {
LOG_SHUTDOWN("Shutting down SpecMapShaderClass");
// Release the camera constant buffer. // Release the camera constant buffer.
if (camera_buffer_) if (camera_buffer_)
{ {
@@ -397,7 +410,8 @@ bool spec_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to map mapped buffer in SpecMapShaderClass");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -426,7 +440,8 @@ bool spec_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
result = deviceContext->Map(light_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(light_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to map lighting buffer in SpecMapShaderClass");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -451,7 +466,8 @@ bool spec_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
result = deviceContext->Map(camera_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(camera_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Failed to map camera buffer in SpecMapShaderClass");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -469,7 +485,7 @@ bool spec_map_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
// Now set the camera constant buffer in the vertex shader with the updated values. // Now set the camera constant buffer in the vertex shader with the updated values.
deviceContext->VSSetConstantBuffers(bufferNumber, 1, &camera_buffer_); deviceContext->VSSetConstantBuffers(bufferNumber, 1, &camera_buffer_);
return true; R_TRUE
} }

View File

@@ -30,7 +30,7 @@ sunlight_shader_class::~sunlight_shader_class()
bool sunlight_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool sunlight_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing LightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing LightShaderClass");
wchar_t vsFilename[128]; wchar_t vsFilename[128];
wchar_t psFilename[128]; wchar_t psFilename[128];
@@ -41,28 +41,28 @@ bool sunlight_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/sunlight.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/sunlight.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/sunlight.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/sunlight.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy string");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize shader");
return false; R_FALSE
} }
Logger::Get().Log("SunLightShaderClass initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("SunLightShaderClass initialized");
return true; R_TRUE
} }
@@ -84,20 +84,20 @@ bool sunlight_shader_class::render(ID3D11DeviceContext* deviceContext, int index
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -124,9 +124,9 @@ bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
} }
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -139,25 +139,25 @@ bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
} }
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -192,8 +192,8 @@ bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout_); result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -222,8 +222,8 @@ bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sampler state");
return false; R_FALSE
} }
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader. // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
@@ -238,8 +238,8 @@ bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create matrix buffer");
return false; R_FALSE
} }
// Setup the description of the dynamic sunlight constant buffer that is in the pixel shader. // Setup the description of the dynamic sunlight constant buffer that is in the pixel shader.
@@ -254,13 +254,13 @@ bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
result = device->CreateBuffer(&sunlightBufferDesc, NULL, &sunlight_buffer_); result = device->CreateBuffer(&sunlightBufferDesc, NULL, &sunlight_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sunlight buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sunlight buffer");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
@@ -268,7 +268,7 @@ bool sunlight_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, W
void sunlight_shader_class::shutdown_shader() void sunlight_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down SunLightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down SunLightShaderClass");
// Release the light constant buffers. // Release the light constant buffers.
if (sunlight_color_buffer_) if (sunlight_color_buffer_)
@@ -332,7 +332,7 @@ void sunlight_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("SunLightShaderClass shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("SunLightShaderClass shut down");
return; return;
} }
@@ -379,7 +379,6 @@ bool sunlight_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
HRESULT result; HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
matrix_buffer_type* dataPtr; matrix_buffer_type* dataPtr;
camera_buffer_type* dataPtr2;
sun_light_buffer_type* dataPtr3; sun_light_buffer_type* dataPtr3;
unsigned int bufferNumber; unsigned int bufferNumber;
@@ -392,7 +391,7 @@ bool sunlight_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -416,7 +415,7 @@ bool sunlight_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
result = deviceContext->Map(sunlight_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(sunlight_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -440,7 +439,7 @@ bool sunlight_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCon
// Set shader texture resource in the pixel shader. // Set shader texture resource in the pixel shader.
deviceContext->PSSetShaderResources(0, 1, &texture); deviceContext->PSSetShaderResources(0, 1, &texture);
return true; R_TRUE
} }
void sunlight_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void sunlight_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -23,7 +23,7 @@ texture_shader_class::~texture_shader_class()
bool texture_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool texture_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing texture shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing texture shader");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -33,29 +33,29 @@ bool texture_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/texture.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/texture.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying stirng", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying stirng");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/texture.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/texture.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Error copying stirng", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error copying stirng");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error initializing shader");
return false; R_FALSE
} }
Logger::Get().Log("Texture shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Texture shader initialized");
return true; R_TRUE
} }
void texture_shader_class::shutdown() void texture_shader_class::shutdown()
@@ -76,19 +76,19 @@ bool texture_shader_class::render(ID3D11DeviceContext* deviceContext, int indexC
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture);
if (!result) if (!result)
{ {
Logger::Get().Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error setting shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -117,10 +117,10 @@ bool texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WC
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -136,26 +136,26 @@ bool texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WC
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error compiling shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
// This setup needs to match the VertexType stucture in the ModelClass and in the shader. // This setup needs to match the VertexType stucture in the ModelClass and in the shader.
@@ -183,8 +183,8 @@ bool texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WC
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -206,8 +206,8 @@ bool texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WC
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating constant buffer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
@@ -228,18 +228,18 @@ bool texture_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WC
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error creating sampler state");
return false; R_FALSE
} }
Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Shader initialized");
return true; R_TRUE
} }
void texture_shader_class::shutdown_shader() void texture_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down shader");
// Release the sampler state. // Release the sampler state.
if (sample_state_) if (sample_state_)
@@ -276,7 +276,7 @@ void texture_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shader shut down");
return; return;
} }
@@ -334,8 +334,8 @@ bool texture_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCont
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Error mapping constant buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -357,7 +357,7 @@ bool texture_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceCont
// Set shader texture resource in the pixel shader. // Set shader texture resource in the pixel shader.
deviceContext->PSSetShaderResources(0, 1, &texture); deviceContext->PSSetShaderResources(0, 1, &texture);
return true; R_TRUE
} }
void texture_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void texture_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -24,7 +24,7 @@ translate_shader_class::~translate_shader_class()
bool translate_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool translate_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initilaizing translate_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initilaizing translate_shader_class");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -35,29 +35,29 @@ bool translate_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/translate.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/translate.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy vsFilename", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy vsFilename");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/translate.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/translate.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy psFilename", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy psFilename");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize shader");
return false; R_FALSE
} }
Logger::Get().Log("translate_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("translate_shader_class initialized");
return true; R_TRUE
} }
@@ -79,20 +79,20 @@ bool translate_shader_class::render(ID3D11DeviceContext * deviceContext, int ind
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, translation); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, translation);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd, WCHAR * vsFilename, WCHAR * psFilename) bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd, WCHAR * vsFilename, WCHAR * psFilename)
{ {
Logger::Get().Log("Initializing translate shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing translate shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -123,10 +123,10 @@ bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -142,26 +142,26 @@ bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd,
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -189,8 +189,8 @@ bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd,
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -212,8 +212,8 @@ bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd,
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create matrix buffer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -235,8 +235,8 @@ bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd,
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sampler state");
return false; R_FALSE
} }
// Setup the description of the texture translation dynamic constant buffer that is in the pixel shader. // Setup the description of the texture translation dynamic constant buffer that is in the pixel shader.
@@ -251,19 +251,19 @@ bool translate_shader_class::initialize_shader(ID3D11Device * device, HWND hwnd,
result = device->CreateBuffer(&translateBufferDesc, NULL, &translate_buffer_); result = device->CreateBuffer(&translateBufferDesc, NULL, &translate_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create translate buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create translate buffer");
return false; R_FALSE
} }
Logger::Get().Log("Translate shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Translate shader initialized");
return true; R_TRUE
} }
void translate_shader_class::shutdown_shader() void translate_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down translate shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down translate shader");
// Release the texture translation constant buffer. // Release the texture translation constant buffer.
if (translate_buffer_) if (translate_buffer_)
@@ -307,7 +307,7 @@ void translate_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Translate shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Translate shader shut down");
return; return;
} }
@@ -368,8 +368,8 @@ bool translate_shader_class::set_shader_parameters(ID3D11DeviceContext * deviceC
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map matrix buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -396,8 +396,8 @@ bool translate_shader_class::set_shader_parameters(ID3D11DeviceContext * deviceC
result = deviceContext->Map(translate_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(translate_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map translate buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map translate buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the texture translation constant buffer. // Get a pointer to the data in the texture translation constant buffer.
@@ -415,7 +415,7 @@ bool translate_shader_class::set_shader_parameters(ID3D11DeviceContext * deviceC
// Now set the texture translation constant buffer in the pixel shader with the updated values. // Now set the texture translation constant buffer in the pixel shader with the updated values.
deviceContext->PSSetConstantBuffers(bufferNumber, 1, &translate_buffer_); deviceContext->PSSetConstantBuffers(bufferNumber, 1, &translate_buffer_);
return true; R_TRUE
} }

View File

@@ -24,7 +24,7 @@ transparent_shader_class::~transparent_shader_class()
bool transparent_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool transparent_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
Logger::Get().Log("Initializing transparent_shader_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing transparent_shader_class");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
@@ -35,29 +35,29 @@ bool transparent_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/transparent.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/transparent.vs");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy vertex shader filename", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy vertex shader filename");
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/transparent.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/transparent.ps");
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to copy pixel shader filename", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to copy pixel shader filename");
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // Initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize shader");
return false; R_FALSE
} }
Logger::Get().Log("transparent_shader_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("transparent_shader_class initialized");
return true; R_TRUE
} }
@@ -79,20 +79,20 @@ bool transparent_shader_class::render(ID3D11DeviceContext* deviceContext, int in
result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, blend); result = set_shader_parameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, blend);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set shader parameters");
return false; R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{ {
Logger::Get().Log("Initializing transparent shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing transparent shader");
HRESULT result; HRESULT result;
ID3D10Blob* errorMessage; ID3D10Blob* errorMessage;
@@ -123,10 +123,10 @@ bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd
// If there was nothing in the error message then it simply could not find the shader file itself. // If there was nothing in the error message then it simply could not find the shader file itself.
else else
{ {
Logger::Get().Log("Failed to compile vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile vertex shader");
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -142,26 +142,26 @@ bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd
// If there was nothing in the error message then it simply could not find the file itself. // If there was nothing in the error message then it simply could not find the file itself.
else else
{ {
Logger::Get().Log("Failed to compile pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to compile pixel shader");
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex shader");
return false; R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create pixel shader");
return false; R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -189,8 +189,8 @@ bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create input layout");
return false; R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -212,8 +212,8 @@ bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create matrix buffer");
return false; R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -235,8 +235,8 @@ bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create sampler state");
return false; R_FALSE
} }
// Setup the description of the transparent dynamic constant buffer that is in the pixel shader. // Setup the description of the transparent dynamic constant buffer that is in the pixel shader.
@@ -251,19 +251,19 @@ bool transparent_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd
result = device->CreateBuffer(&transparentBufferDesc, NULL, &transparent_buffer_); result = device->CreateBuffer(&transparentBufferDesc, NULL, &transparent_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create transparent buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create transparent buffer");
return false; R_FALSE
} }
Logger::Get().Log("Transparent shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Transparent shader initialized");
return true; R_TRUE
} }
void transparent_shader_class::shutdown_shader() void transparent_shader_class::shutdown_shader()
{ {
Logger::Get().Log("Shutting down transparent shader", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down transparent shader");
// Release the transparent constant buffer. // Release the transparent constant buffer.
if (transparent_buffer_) if (transparent_buffer_)
@@ -307,7 +307,7 @@ void transparent_shader_class::shutdown_shader()
vertex_shader_ = 0; vertex_shader_ = 0;
} }
Logger::Get().Log("Transparent shader shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Transparent shader shut down");
return; return;
} }
@@ -367,8 +367,8 @@ bool transparent_shader_class::set_shader_parameters(ID3D11DeviceContext* device
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map matrix buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -395,8 +395,8 @@ bool transparent_shader_class::set_shader_parameters(ID3D11DeviceContext* device
result = deviceContext->Map(transparent_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(transparent_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map transparent buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map transparent buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the transparent constant buffer. // Get a pointer to the data in the transparent constant buffer.
@@ -414,7 +414,7 @@ bool transparent_shader_class::set_shader_parameters(ID3D11DeviceContext* device
// Now set the transparent constant buffer in the pixel shader with the updated values. // Now set the transparent constant buffer in the pixel shader with the updated values.
deviceContext->PSSetConstantBuffers(bufferNumber, 1, &transparent_buffer_); deviceContext->PSSetConstantBuffers(bufferNumber, 1, &transparent_buffer_);
return true; R_TRUE
} }

View File

@@ -25,6 +25,9 @@ water_shader_class::~water_shader_class()
bool water_shader_class::initialize(ID3D11Device* device, HWND hwnd) bool water_shader_class::initialize(ID3D11Device* device, HWND hwnd)
{ {
LOG_INIT("Initializing Water Shader");
bool result; bool result;
wchar_t vsFilename[128]; wchar_t vsFilename[128];
wchar_t psFilename[128]; wchar_t psFilename[128];
@@ -34,24 +37,24 @@ bool water_shader_class::initialize(ID3D11Device* device, HWND hwnd)
error = wcscpy_s(vsFilename, 128, L"src/hlsl/water.vs"); error = wcscpy_s(vsFilename, 128, L"src/hlsl/water.vs");
if (error != 0) if (error != 0)
{ {
return false; R_FALSE
} }
// Set the filename of the pixel shader. // Set the filename of the pixel shader.
error = wcscpy_s(psFilename, 128, L"src/hlsl/water.ps"); error = wcscpy_s(psFilename, 128, L"src/hlsl/water.ps");
if (error != 0) if (error != 0)
{ {
return false; R_FALSE
} }
// initialize the vertex and pixel shaders. // initialize the vertex and pixel shaders.
result = initialize_shader(device, hwnd, vsFilename, psFilename); result = initialize_shader(device, hwnd, vsFilename, psFilename);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
return true; R_TRUE
} }
@@ -75,13 +78,14 @@ bool water_shader_class::render(ID3D11DeviceContext* deviceContext, int indexCou
refractionTexture, normalTexture, waterTranslation, reflectRefractScale); refractionTexture, normalTexture, waterTranslation, reflectRefractScale);
if (!result) if (!result)
{ {
return false; LOG_ERROR("Failed to set shader parameters in water shader");
R_FALSE
} }
// Now render the prepared buffers with the shader. // Now render the prepared buffers with the shader.
render_shader(deviceContext, indexCount); render_shader(deviceContext, indexCount);
return true; R_TRUE
} }
@@ -120,7 +124,7 @@ bool water_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK); MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
} }
return false; R_FALSE
} }
// Compile the pixel shader code. // Compile the pixel shader code.
@@ -139,21 +143,23 @@ bool water_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK); MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
} }
return false; R_FALSE
} }
// Create the vertex shader from the buffer. // Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_); result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertex_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating vertex shader in water shader");
R_FALSE
} }
// Create the pixel shader from the buffer. // Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_); result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &pixel_shader_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating pixel shader in water shader");
R_FALSE
} }
// Create the vertex input layout description. // Create the vertex input layout description.
@@ -181,7 +187,8 @@ bool water_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
vertexShaderBuffer->GetBufferSize(), &layout_); vertexShaderBuffer->GetBufferSize(), &layout_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating input layout in water shader");
R_FALSE
} }
// Release the vertex shader buffer and pixel shader buffer since they are no longer needed. // Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
@@ -203,7 +210,8 @@ bool water_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_); result = device->CreateBuffer(&matrixBufferDesc, NULL, &matrix_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating matrix buffer in water shader");
R_FALSE
} }
// Create a texture sampler state description. // Create a texture sampler state description.
@@ -225,7 +233,8 @@ bool water_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateSamplerState(&samplerDesc, &sample_state_); result = device->CreateSamplerState(&samplerDesc, &sample_state_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating sampler state in water shader");
R_FALSE
} }
// Setup the description of the reflection dynamic constant buffer that is in the vertex shader. // Setup the description of the reflection dynamic constant buffer that is in the vertex shader.
@@ -240,7 +249,8 @@ bool water_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&reflectionBufferDesc, NULL, &reflection_buffer_); result = device->CreateBuffer(&reflectionBufferDesc, NULL, &reflection_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating reflection buffer in water shader");
R_FALSE
} }
// Setup the description of the water dynamic constant buffer that is in the pixel shader. // Setup the description of the water dynamic constant buffer that is in the pixel shader.
@@ -255,15 +265,19 @@ bool water_shader_class::initialize_shader(ID3D11Device* device, HWND hwnd, WCHA
result = device->CreateBuffer(&waterBufferDesc, NULL, &water_buffer_); result = device->CreateBuffer(&waterBufferDesc, NULL, &water_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error creating water buffer in water shader");
R_FALSE
} }
return true; R_TRUE
} }
void water_shader_class::shutdown_shader() void water_shader_class::shutdown_shader()
{ {
LOG_SHUTDOWN("Shutting down Water Shader");
// Release the water constant buffer. // Release the water constant buffer.
if (water_buffer_) if (water_buffer_)
{ {
@@ -373,7 +387,8 @@ bool water_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(matrix_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error mapping matrix buffer in water shader");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -397,7 +412,8 @@ bool water_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(reflection_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(reflection_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error mapping reflection buffer in water shader");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -428,7 +444,8 @@ bool water_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
result = deviceContext->Map(water_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContext->Map(water_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; LOG_ERROR("Error mapping water buffer in water shader");
R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -448,7 +465,7 @@ bool water_shader_class::set_shader_parameters(ID3D11DeviceContext* deviceContex
// Finally set the water constant buffer in the pixel shader with the updated values. // Finally set the water constant buffer in the pixel shader with the updated values.
deviceContext->PSSetConstantBuffers(bufferNumber, 1, &water_buffer_); deviceContext->PSSetConstantBuffers(bufferNumber, 1, &water_buffer_);
return true; R_TRUE
} }
void water_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount) void water_shader_class::render_shader(ID3D11DeviceContext* deviceContext, int indexCount)

View File

@@ -1,5 +1,5 @@
#include "system_class.h" #include "system_class.h"
#include "macro.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow)
{ {
@@ -23,7 +23,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline,
result = System->initialize(); result = System->initialize();
if (result) if (result)
{ {
Logger::Get().Log("System initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("System initialized");
System->send_path(path,WFolder); System->send_path(path,WFolder);
System->run(); System->run();
} }

View File

@@ -25,7 +25,7 @@ void Skybox::Initialize(d_3d_class* d3dClassRef)
object* Skybox::ConstructSkybox(application_class* app) object* Skybox::ConstructSkybox(application_class* app)
{ {
Logger::Get().Log("Construct skybox", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INFO("Construct skybox");
char modelFilename[128]; char modelFilename[128];
strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj"); strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj");
@@ -43,7 +43,7 @@ object* Skybox::ConstructSkybox(application_class* app)
HRESULT result = DirectX::CreateWICTextureFromFile(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), textureFilename.c_str(), nullptr, &texture); HRESULT result = DirectX::CreateWICTextureFromFile(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), textureFilename.c_str(), nullptr, &texture);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()));
return nullptr; return nullptr;
} }
SkyboxTextures.diffuse.push_back(texture); SkyboxTextures.diffuse.push_back(texture);
@@ -55,7 +55,7 @@ object* Skybox::ConstructSkybox(application_class* app)
HRESULT result = m_Skybox->Initialize(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), modelFilename, SkyboxTextures); HRESULT result = m_Skybox->Initialize(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), modelFilename, SkyboxTextures);
if (!result) if (!result)
{ {
Logger::Get().Log("Could not initialize the skybox model object", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Could not initialize the skybox model object");
delete m_Skybox; delete m_Skybox;
return nullptr; return nullptr;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -20,7 +20,7 @@ bitmap_class::~bitmap_class()
bool bitmap_class::initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, int screenWidth, int screenHeight, char* textureFilename, int renderX, int renderY) bool bitmap_class::initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, int screenWidth, int screenHeight, char* textureFilename, int renderX, int renderY)
{ {
Logger::Get().Log("Initializing bitmap class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing bitmap class");
bool result; bool result;
@@ -36,21 +36,21 @@ bool bitmap_class::initialize(ID3D11Device* device, ID3D11DeviceContext* deviceC
result = initialize_buffers(device); result = initialize_buffers(device);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize buffers");
return false; R_FALSE
} }
// Load the texture for this bitmap. // Load the texture for this bitmap.
result = load_texture(device, deviceContext, textureFilename); result = load_texture(device, deviceContext, textureFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to load texture", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to load texture");
return false; R_FALSE
} }
Logger::Get().Log("Bitmap class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Bitmap class initialized");
return true; R_TRUE
} }
void bitmap_class::shutdown() void bitmap_class::shutdown()
@@ -68,19 +68,18 @@ bool bitmap_class::render(ID3D11DeviceContext* deviceContext)
{ {
bool result; bool result;
// Update the buffers if the position of the bitmap has changed from its original position. // Update the buffers if the position of the bitmap has changed from its original position.
result = update_buffers(deviceContext); result = update_buffers(deviceContext);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to update buffers", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to update buffers");
return false; R_FALSE
} }
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing. // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
render_buffers(deviceContext); render_buffers(deviceContext);
return true; R_TRUE
} }
int bitmap_class::get_index_count() int bitmap_class::get_index_count()
@@ -95,7 +94,7 @@ ID3D11ShaderResourceView* bitmap_class::get_texture()
bool bitmap_class::initialize_buffers(ID3D11Device* device) bool bitmap_class::initialize_buffers(ID3D11Device* device)
{ {
Logger::Get().Log("Initializing buffers", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing buffers");
vertex_type* vertices; vertex_type* vertices;
unsigned long* indices; unsigned long* indices;
@@ -146,8 +145,8 @@ bool bitmap_class::initialize_buffers(ID3D11Device* device)
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &vertex_buffer_); result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &vertex_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex buffer");
return false; R_FALSE
} }
// Set up the description of the index buffer. // Set up the description of the index buffer.
@@ -167,8 +166,8 @@ bool bitmap_class::initialize_buffers(ID3D11Device* device)
result = device->CreateBuffer(&indexBufferDesc, &indexData, &index_buffer_); result = device->CreateBuffer(&indexBufferDesc, &indexData, &index_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create index buffer");
return false; R_FALSE
} }
// Release the arrays now that the vertex and index buffers have been created and loaded. // Release the arrays now that the vertex and index buffers have been created and loaded.
@@ -178,34 +177,34 @@ bool bitmap_class::initialize_buffers(ID3D11Device* device)
delete[] indices; delete[] indices;
indices = 0; indices = 0;
Logger::Get().Log("Buffers initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Buffers initialized");
return true; R_TRUE
} }
void bitmap_class::shutdown_buffers() void bitmap_class::shutdown_buffers()
{ {
Logger::Get().Log("Shutting down buffers", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down buffers");
// Release the index buffer. // Release the index buffer.
if (index_buffer_) if (index_buffer_)
{ {
Logger::Get().Log("Releasing index buffer", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing index buffer");
index_buffer_->Release(); index_buffer_->Release();
index_buffer_ = 0; index_buffer_ = 0;
Logger::Get().Log("Index buffer released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Index buffer released");
} }
// Release the vertex buffer. // Release the vertex buffer.
if (vertex_buffer_) if (vertex_buffer_)
{ {
Logger::Get().Log("Releasing vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing vertex buffer");
vertex_buffer_->Release(); vertex_buffer_->Release();
vertex_buffer_ = 0; vertex_buffer_ = 0;
Logger::Get().Log("Vertex buffer released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Vertex buffer released");
} }
Logger::Get().Log("Buffers shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Buffers shut down");
return; return;
} }
@@ -221,7 +220,7 @@ bool bitmap_class::update_buffers(ID3D11DeviceContext* deviceContent)
// If the position we are rendering this bitmap to hasn't changed then don't update the vertex buffer. // If the position we are rendering this bitmap to hasn't changed then don't update the vertex buffer.
if ((prev_pos_x_ == render_x_) && (prev_pos_y_ == render_y_)) if ((prev_pos_x_ == render_x_) && (prev_pos_y_ == render_y_))
{ {
return true; R_TRUE
} }
// If the rendering location has changed then store the new position and update the vertex buffer. // If the rendering location has changed then store the new position and update the vertex buffer.
@@ -268,8 +267,8 @@ bool bitmap_class::update_buffers(ID3D11DeviceContext* deviceContent)
result = deviceContent->Map(vertex_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContent->Map(vertex_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to map vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to map vertex buffer");
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -288,7 +287,7 @@ bool bitmap_class::update_buffers(ID3D11DeviceContext* deviceContent)
delete[] vertices; delete[] vertices;
vertices = 0; vertices = 0;
return true; R_TRUE
} }
void bitmap_class::render_buffers(ID3D11DeviceContext* deviceContext) void bitmap_class::render_buffers(ID3D11DeviceContext* deviceContext)
@@ -324,31 +323,31 @@ bool bitmap_class::load_texture(ID3D11Device* device, ID3D11DeviceContext* devic
result = texture_->Initialize(device, deviceContext, filename); result = texture_->Initialize(device, deviceContext, filename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize texture object", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize texture object");
return false; R_FALSE
} }
// Store the size in pixels that this bitmap should be rendered at. // Store the size in pixels that this bitmap should be rendered at.
bitmap_width_ = texture_->GetWidth(); bitmap_width_ = texture_->GetWidth();
bitmap_height_ = texture_->GetHeight(); bitmap_height_ = texture_->GetHeight();
return true; R_TRUE
} }
void bitmap_class::release_texture() void bitmap_class::release_texture()
{ {
Logger::Get().Log("Releasing texture", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing texture");
// Release the texture object. // Release the texture object.
if (texture_) if (texture_)
{ {
Logger::Get().Log("Releasing texture object", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Releasing texture object");
texture_->Shutdown(); texture_->Shutdown();
delete texture_; delete texture_;
texture_ = 0; texture_ = 0;
Logger::Get().Log("Texture object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Texture object released");
} }
Logger::Get().Log("Texture released", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Texture released");
return; return;
} }

View File

@@ -5,6 +5,7 @@
camera_class::camera_class() camera_class::camera_class()
{ {
LOG_INIT("Initializing camera class");
position_x_ = 0.0f; position_x_ = 0.0f;
position_y_ = 0.0f; position_y_ = 0.0f;
position_z_ = 0.0f; position_z_ = 0.0f;
@@ -12,6 +13,13 @@ camera_class::camera_class()
rotation_x_ = 0.0f; rotation_x_ = 0.0f;
rotation_y_ = 0.0f; rotation_y_ = 0.0f;
rotation_z_ = 0.0f; rotation_z_ = 0.0f;
camera_speed_ = 4.0f;
view_matrix_ = XMMatrixIdentity();
reflection_view_matrix_ = XMMatrixIdentity();
LOG_INIT("Camera class initialized");
} }
@@ -22,6 +30,7 @@ camera_class::camera_class(const camera_class& other)
camera_class::~camera_class() camera_class::~camera_class()
{ {
LOG_SHUTDOWN("Camera class destructor called");
} }
void camera_class::set_position(float x, float y, float z) void camera_class::set_position(float x, float y, float z)
@@ -105,6 +114,8 @@ void camera_class::render()
return; return;
} }
XMMATRIX camera_class::get_view_matrix(XMMATRIX& view_matrix) const XMMATRIX camera_class::get_view_matrix(XMMATRIX& view_matrix) const
{ {
view_matrix = view_matrix_; view_matrix = view_matrix_;
@@ -168,4 +179,130 @@ void camera_class::get_reflection_view_matrix(XMMATRIX& reflectionViewMatrix) co
{ {
reflectionViewMatrix = reflection_view_matrix_; reflectionViewMatrix = reflection_view_matrix_;
return; return;
}
void camera_class::move(float deltatime, float delta_x, float delta_y)
{
if (!inputs_) return;
float speed;
float radiansY = rotation_y_ * TO_RAD;
float radiansX = rotation_x_ * TO_RAD;
rotate(delta_x, delta_y);
if (inputs_->scroll_up && inputs_->right_click)
{
camera_speed_ *= 1.1f;
}
if (inputs_->scroll_down && inputs_->right_click)
{
camera_speed_ *= 0.9f;
if (camera_speed_ < 0.25f) // Minimum speed.
{
camera_speed_ = 0.25f;
}
}
if (inputs_->scroll_up && !inputs_->right_click)
{
speed = camera_speed_ * 20 * deltatime;
position_x_ += sinf(radiansY) * cosf(radiansX) * speed;
position_z_ += cosf(radiansY) * cosf(radiansX) * speed;
position_y_ -= sinf(radiansX) * speed;
}
if (inputs_->scroll_up && !inputs_->right_click)
{
speed = camera_speed_ * 20 * deltatime;
position_x_ -= sinf(radiansY) * cosf(radiansX) * speed;
position_z_ -= cosf(radiansY) * cosf(radiansX) * speed;
position_y_ += sinf(radiansX) * speed;
}
speed = camera_speed_ * deltatime;
if (inputs_->move_forward)
{
position_x_ += sinf(radiansY) * cosf(radiansX) * speed;
position_z_ += cosf(radiansY) * cosf(radiansX) * speed;
position_y_ -= sinf(radiansX) * speed;
}
if (inputs_->move_backward)
{
position_x_ -= sinf(radiansY) * cosf(radiansX) * speed;
position_z_ -= cosf(radiansY) * cosf(radiansX) * speed;
position_y_ += sinf(radiansX) * speed;
}
if (inputs_->move_left)
{
position_x_ -= cosf(radiansY) * speed;
position_z_ += sinf(radiansY) * speed;
}
if (inputs_->move_right)
{
position_x_ += cosf(radiansY) * speed;
position_z_ -= sinf(radiansY) * speed;
}
if (inputs_->move_up)
{
position_y_ += speed;
}
if (inputs_->move_down)
{
position_y_ -= speed;
}
return;
}
void camera_class::rotate(float delta_x, float delta_y)
{
if (inputs_ == nullptr) return;
float delta_yaw = delta_x * camera_sensitivity_;
float delta_pitch = delta_y * camera_sensitivity_;
if (inputs_->right_click)
{
rotation_y_ += delta_yaw;
if (rotation_y_ < 0.0f)
{
rotation_y_ += 360.0f;
}
else if (rotation_y_ > 360.0f)
{
rotation_y_ -= 360.0f;
}
rotation_x_ += delta_pitch;
if (rotation_x_ < -90.0f)
{
rotation_x_ = -90.0f;
}
else if (rotation_x_ > 90.0f)
{
rotation_x_ = 90.0f;
}
}
return;
}
void camera_class::update_camera_inputs_states(input_class* inputs)
{
inputs_->move_forward = inputs->is_key_pressed(DIK_W);
inputs_->move_backward = inputs->is_key_pressed(DIK_S);
inputs_->move_left = inputs->is_key_pressed(DIK_A);
inputs_->move_right = inputs->is_key_pressed(DIK_D);
inputs_->move_up = inputs->is_key_pressed(DIK_E);
inputs_->move_down = inputs->is_key_pressed(DIK_Q);
inputs_->scroll_up = inputs->IsScrollUp();
inputs_->scroll_down = inputs->IsScrollDown();
inputs_->right_click = inputs->IsRightMousePressed();
} }

View File

@@ -6,6 +6,7 @@
d_3d_class::d_3d_class() d_3d_class::d_3d_class()
{ {
LOG_INIT("Initializing D3D class constructor");
swap_chain = 0; swap_chain = 0;
device_ = 0; device_ = 0;
device_context_ = 0; device_context_ = 0;
@@ -17,6 +18,7 @@ d_3d_class::d_3d_class()
depth_disabled_stencil_state_ = 0; depth_disabled_stencil_state_ = 0;
alpha_enable_blending_state_ = 0; alpha_enable_blending_state_ = 0;
alpha_disable_blending_state_ = 0; alpha_disable_blending_state_ = 0;
LOG_INIT("D3D class constructor initialized");
} }
@@ -27,12 +29,13 @@ d_3d_class::d_3d_class(const d_3d_class& other)
d_3d_class::~d_3d_class() d_3d_class::~d_3d_class()
{ {
LOG_SHUTDOWN("D3D class destructor called");
} }
bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear) bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear)
{ {
Logger::Get().Log("Initializing D3Dclass", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing D3Dclass");
HRESULT result; HRESULT result;
IDXGIFactory* factory; IDXGIFactory* factory;
@@ -61,48 +64,48 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create DXGIFactory", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create DXGIFactory");
return false; R_FALSE
} }
// Use the factory to create an adapter for the primary graphics interface (video card). // Use the factory to create an adapter for the primary graphics interface (video card).
result = factory->EnumAdapters(0, &adapter); result = factory->EnumAdapters(0, &adapter);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create adapter", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create adapter");
return false; R_FALSE
} }
// Enumerate the primary adapter output (monitor). // Enumerate the primary adapter output (monitor).
result = adapter->EnumOutputs(0, &adapterOutput); result = adapter->EnumOutputs(0, &adapterOutput);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create adapter output", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create adapter output");
return false; R_FALSE
} }
// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor). // Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL); result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to get display mode list", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to get display mode list");
return false; R_FALSE
} }
// Create a list to hold all the possible display modes for this monitor/video card combination. // Create a list to hold all the possible display modes for this monitor/video card combination.
displayModeList = new DXGI_MODE_DESC[numModes]; displayModeList = new DXGI_MODE_DESC[numModes];
if (!displayModeList) if (!displayModeList)
{ {
Logger::Get().Log("Failed to create display mode list", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create display mode list");
return false; R_FALSE
} }
// Now fill the display mode list structures. // Now fill the display mode list structures.
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList); result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to fill display mode list", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to fill display mode list");
return false; R_FALSE
} }
// Now go through all the display modes and find the one that matches the screen width and height. // Now go through all the display modes and find the one that matches the screen width and height.
@@ -123,8 +126,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = adapter->GetDesc(&adapterDesc); result = adapter->GetDesc(&adapterDesc);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to get adapter description", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to get adapter description");
return false; R_FALSE
} }
// Store the dedicated video card memory in megabytes. // Store the dedicated video card memory in megabytes.
@@ -134,8 +137,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
error = wcstombs_s(&stringLength, video_card_description_, 128, adapterDesc.Description, 128); error = wcstombs_s(&stringLength, video_card_description_, 128, adapterDesc.Description, 128);
if (error != 0) if (error != 0)
{ {
Logger::Get().Log("Failed to convert video card name to character array", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to convert video card name to character array");
return false; R_FALSE
} }
// Release the display mode list. // Release the display mode list.
@@ -217,24 +220,24 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
D3D11_SDK_VERSION, &swapChainDesc, &swap_chain, &device_, NULL, &device_context_); D3D11_SDK_VERSION, &swapChainDesc, &swap_chain, &device_, NULL, &device_context_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create swap chain, device and device context", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create swap chain, device and device context");
return false; R_FALSE
} }
// Get the pointer to the back buffer. // Get the pointer to the back buffer.
result = swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr); result = swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to get pointer to back buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to get pointer to back buffer");
return false; R_FALSE
} }
// Create the render target view with the back buffer pointer. // Create the render target view with the back buffer pointer.
result = device_->CreateRenderTargetView(backBufferPtr, NULL, &render_target_view_); result = device_->CreateRenderTargetView(backBufferPtr, NULL, &render_target_view_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create render target view", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create render target view");
return false; R_FALSE
} }
// Release pointer to the back buffer as we no longer need it. // Release pointer to the back buffer as we no longer need it.
@@ -261,8 +264,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = device_->CreateTexture2D(&depthBufferDesc, NULL, &depth_stencil_buffer_); result = device_->CreateTexture2D(&depthBufferDesc, NULL, &depth_stencil_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create texture for depth buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create texture for depth buffer");
return false; R_FALSE
} }
// initialize the description of the stencil state. // initialize the description of the stencil state.
@@ -293,8 +296,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = device_->CreateDepthStencilState(&depthStencilDesc, &depth_stencil_state_); result = device_->CreateDepthStencilState(&depthStencilDesc, &depth_stencil_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create depth stencil state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create depth stencil state");
return false; R_FALSE
} }
// Set the depth stencil state. // Set the depth stencil state.
@@ -312,8 +315,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = device_->CreateDepthStencilView(depth_stencil_buffer_, &depthStencilViewDesc, &depth_stencil_view_); result = device_->CreateDepthStencilView(depth_stencil_buffer_, &depthStencilViewDesc, &depth_stencil_view_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create depth stencil view", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create depth stencil view");
return false; R_FALSE
} }
// Bind the render target view and depth stencil buffer to the output render pipeline. // Bind the render target view and depth stencil buffer to the output render pipeline.
@@ -335,8 +338,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = device_->CreateRasterizerState(&rasterDesc, &raster_state_); result = device_->CreateRasterizerState(&rasterDesc, &raster_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create rasterizer state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create rasterizer state");
return false; R_FALSE
} }
// Now set the rasterizer state. // Now set the rasterizer state.
@@ -390,8 +393,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = device_->CreateDepthStencilState(&depthDisabledStencilDesc, &depth_disabled_stencil_state_); result = device_->CreateDepthStencilState(&depthDisabledStencilDesc, &depth_disabled_stencil_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create depth disabled stencil state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create depth disabled stencil state");
return false; R_FALSE
} }
// Clear the blend state description. // Clear the blend state description.
@@ -411,8 +414,8 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = device_->CreateBlendState(&blendStateDescription, &alpha_enable_blending_state_); result = device_->CreateBlendState(&blendStateDescription, &alpha_enable_blending_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create alpha enabled blend state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create alpha enabled blend state");
return false; R_FALSE
} }
// Modify the description to create an alpha disabled blend state description. // Modify the description to create an alpha disabled blend state description.
@@ -422,18 +425,17 @@ bool d_3d_class::initialize(int screenWidth, int screenHeight, bool vsync, HWND
result = device_->CreateBlendState(&blendStateDescription, &alpha_disable_blending_state_); result = device_->CreateBlendState(&blendStateDescription, &alpha_disable_blending_state_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create alpha disabled blend state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create alpha disabled blend state");
return false; R_FALSE
} }
return true; R_TRUE
} }
void d_3d_class::shutdown() void d_3d_class::shutdown()
{ {
LOG_SHUTDOWN("Shutting down D3Dclass");
Logger::Get().Log("Shutting down D3Dclass", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
// Before shutting down set to windowed mode or when you release the swap chain it will throw an exception. // Before shutting down set to windowed mode or when you release the swap chain it will throw an exception.
if (swap_chain) if (swap_chain)
@@ -507,7 +509,7 @@ void d_3d_class::shutdown()
swap_chain = 0; swap_chain = 0;
} }
Logger::Get().Log("D3Dclass shutdown", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("D3Dclass shutdown");
return; return;
} }
@@ -592,7 +594,7 @@ void d_3d_class::reset_viewport()
void d_3d_class::release_resources() void d_3d_class::release_resources()
{ {
Logger::Get().Log("Releasing D3D resources", __FILE__, __LINE__); LOG_SHUTDOWN("Releasing D3D resources");
// libere la vue // libere la vue
if (render_target_view_) if (render_target_view_)
@@ -615,13 +617,13 @@ void d_3d_class::release_resources()
depth_stencil_view_ = 0; depth_stencil_view_ = 0;
} }
Logger::Get().Log("D3D resources released", __FILE__, __LINE__); LOG_SHUTDOWN("D3D resources released");
} }
// Reset the resources for the swap chain // Reset the resources for the swap chain
void d_3d_class::reset_resources(int newWidth, int newHeight) void d_3d_class::reset_resources(int newWidth, int newHeight)
{ {
Logger::Get().Log("Resetting D3D resources", __FILE__, __LINE__); LOG_INIT("Resetting D3D resources");
HRESULT result; HRESULT result;
@@ -629,21 +631,21 @@ void d_3d_class::reset_resources(int newWidth, int newHeight)
result = swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer); result = swap_chain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to get back buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to get back buffer");
return; return;
} }
result = device_->CreateRenderTargetView(backBuffer, NULL, &render_target_view_); result = device_->CreateRenderTargetView(backBuffer, NULL, &render_target_view_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create render target view", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create render target view");
return; return;
} }
result = backBuffer->Release(); result = backBuffer->Release();
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to release back buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to release back buffer");
return; return;
} }
@@ -672,14 +674,14 @@ void d_3d_class::reset_resources(int newWidth, int newHeight)
result = device_->CreateTexture2D(&depthBufferDesc, NULL, &depth_stencil_buffer_); result = device_->CreateTexture2D(&depthBufferDesc, NULL, &depth_stencil_buffer_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create depth stencil buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create depth stencil buffer");
return; return;
} }
result = device_->CreateDepthStencilView(depth_stencil_buffer_, &depthStencilViewDesc, &depth_stencil_view_); result = device_->CreateDepthStencilView(depth_stencil_buffer_, &depthStencilViewDesc, &depth_stencil_view_);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create depth stencil view", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create depth stencil view");
return; return;
} }
@@ -694,9 +696,7 @@ IDXGISwapChain* d_3d_class::get_swap_chain()
void d_3d_class::resize_swap_chain(int newWidth, int newHeight) 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));
// log the new width and height
Logger::Get().Log("Resizing swap chain to " + std::to_string(newWidth) + "x" + std::to_string(newHeight), __FILE__, __LINE__);
HRESULT result; HRESULT result;
@@ -708,7 +708,7 @@ void d_3d_class::resize_swap_chain(int newWidth, int newHeight)
result = swap_chain->ResizeBuffers(0, newWidth, newHeight, DXGI_FORMAT_UNKNOWN, 0); result = swap_chain->ResizeBuffers(0, newWidth, newHeight, DXGI_FORMAT_UNKNOWN, 0);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to resize swap chain", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to resize swap chain");
return; return;
} }
@@ -771,4 +771,21 @@ void d_3d_class::disable_alpha_blending()
void d_3d_class::set_vsync(bool vsync) void d_3d_class::set_vsync(bool vsync)
{ {
vsync_enabled_ = vsync; vsync_enabled_ = vsync;
}
bool d_3d_class::set_projection_params(int width, int height, float screenDepth, float screenNear)
{
float fieldOfView, screenAspect;
// Setup the projection matrix.
fieldOfView = 3.141592654f / 4.0f;
screenAspect = (float)width / (float)height;
// Create the projection matrix for 3D rendering.
projection_matrix_ = XMMatrixPerspectiveFovLH(fieldOfView, screenAspect, screenNear, screenDepth);
// Create an orthographic projection matrix for 2D rendering.
ortho_matrix_ = XMMatrixOrthographicLH((float)width, (float)height, screenNear, screenDepth);
R_TRUE
} }

View File

@@ -3,8 +3,10 @@
display_plane_class::display_plane_class() display_plane_class::display_plane_class()
{ {
LOG_INIT("Initializing display_plane_class constructor");
m_vertexBuffer = 0; m_vertexBuffer = 0;
m_indexBuffer = 0; m_indexBuffer = 0;
LOG_INIT("Display_plane_class constructor initialized");
} }
@@ -15,11 +17,12 @@ display_plane_class::display_plane_class(const display_plane_class& other)
display_plane_class::~display_plane_class() display_plane_class::~display_plane_class()
{ {
LOG_SHUTDOWN("Display_plane_class destructor called");
} }
bool display_plane_class::Initialize(ID3D11Device* device, float width, float height) bool display_plane_class::Initialize(ID3D11Device* device, float width, float height)
{ {
Logger::Get().Log("Initializing display_plane_class, width: " + std::to_string(width) + ", height: " + std::to_string(height), __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing display_plane_class, width: " + std::to_string(width) + ", height: " + std::to_string(height));
bool result; bool result;
@@ -27,18 +30,21 @@ bool display_plane_class::Initialize(ID3D11Device* device, float width, float he
result = InitializeBuffers(device, width, height); result = InitializeBuffers(device, width, height);
if (!result) if (!result)
{ {
Logger::Get().Log("Could not initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Could not initialize buffers");
return false; R_FALSE
} }
return true; LOG_INIT("Display_plane_class initialized");
R_TRUE
} }
void display_plane_class::Shutdown() void display_plane_class::Shutdown()
{ {
LOG_SHUTDOWN("Shutting down display_plane_class");
// Release the vertex and index buffers. // Release the vertex and index buffers.
ShutdownBuffers(); ShutdownBuffers();
LOG_SHUTDOWN("Display_plane_class shut down");
return; return;
} }
@@ -60,7 +66,7 @@ int display_plane_class::GetIndexCount()
bool display_plane_class::InitializeBuffers(ID3D11Device* device, float width, float height) bool display_plane_class::InitializeBuffers(ID3D11Device* device, float width, float height)
{ {
Logger::Get().Log("Initializing buffers", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing buffers");
VertexType* vertices; VertexType* vertices;
unsigned long* indices; unsigned long* indices;
@@ -126,8 +132,8 @@ bool display_plane_class::InitializeBuffers(ID3D11Device* device, float width, f
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Could not create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Could not create vertex buffer");
return false; R_FALSE
} }
// Set up the description of the index buffer. // Set up the description of the index buffer.
@@ -147,8 +153,8 @@ bool display_plane_class::InitializeBuffers(ID3D11Device* device, float width, f
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Could not create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Could not create index buffer");
return false; R_FALSE
} }
// Release the arrays now that the vertex and index buffers have been created and loaded. // Release the arrays now that the vertex and index buffers have been created and loaded.
@@ -158,31 +164,35 @@ bool display_plane_class::InitializeBuffers(ID3D11Device* device, float width, f
delete[] indices; delete[] indices;
indices = 0; indices = 0;
Logger::Get().Log("Buffers initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Buffers initialized");
return true; R_TRUE
} }
void display_plane_class::ShutdownBuffers() void display_plane_class::ShutdownBuffers()
{ {
Logger::Get().Log("Shutting down Plane buffers", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down Plane buffers");
// Release the index buffer. // Release the index buffer.
if (m_indexBuffer) if (m_indexBuffer)
{ {
LOG_SHUTDOWN("Releasing index buffer");
m_indexBuffer->Release(); m_indexBuffer->Release();
m_indexBuffer = 0; m_indexBuffer = 0;
LOG_SHUTDOWN("Index buffer released");
} }
// Release the vertex buffer. // Release the vertex buffer.
if (m_vertexBuffer) if (m_vertexBuffer)
{ {
LOG_SHUTDOWN("Releasing vertex buffer");
m_vertexBuffer->Release(); m_vertexBuffer->Release();
m_vertexBuffer = 0; m_vertexBuffer = 0;
LOG_SHUTDOWN("Vertex buffer released");
} }
Logger::Get().Log("Plane buffers shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Plane buffers shut down");
return; return;
} }

View File

@@ -2,8 +2,10 @@
font_class::font_class() font_class::font_class()
{ {
LOG_INIT("Initializing font class constructor");
m_Font = 0; m_Font = 0;
m_Texture = 0; m_Texture = 0;
LOG_INIT("Font class constructor initialized");
} }
@@ -14,11 +16,12 @@ font_class::font_class(const font_class& other)
font_class::~font_class() font_class::~font_class()
{ {
LOG_SHUTDOWN("Font class destructor called");
} }
bool font_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, int fontChoice) bool font_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, int fontChoice)
{ {
Logger::Get().Log("Initializing font class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing font class");
char fontFilename[128]; char fontFilename[128];
char fontTextureFilename[128]; char fontTextureFilename[128];
@@ -49,37 +52,39 @@ bool font_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
result = LoadFontData(fontFilename); result = LoadFontData(fontFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to load font data", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to load font data");
return false; R_FALSE
} }
// Load the texture that has the font characters on it. // Load the texture that has the font characters on it.
result = LoadTexture(device, deviceContext, fontTextureFilename); result = LoadTexture(device, deviceContext, fontTextureFilename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to load font texture", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to load font texture");
return false; R_FALSE
} }
Logger::Get().Log("Font class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Font class initialized");
return true; R_TRUE
} }
void font_class::Shutdown() void font_class::Shutdown()
{ {
LOG_SHUTDOWN("Shutting down font class");
// Release the font texture. // Release the font texture.
ReleaseTexture(); ReleaseTexture();
// Release the font data. // Release the font data.
ReleaseFontData(); ReleaseFontData();
LOG_SHUTDOWN("Font class shut down");
return; return;
} }
bool font_class::LoadFontData(char* filename) bool font_class::LoadFontData(char* filename)
{ {
Logger::Get().Log(("Loading font data from %s", filename), __FILE__, __LINE__); LOG_INFO("Loading font data from " + std::string(filename));
std::ifstream fin; std::ifstream fin;
int i; int i;
@@ -92,8 +97,8 @@ bool font_class::LoadFontData(char* filename)
fin.open(filename); fin.open(filename);
if (fin.fail()) if (fin.fail())
{ {
Logger::Get().Log("Failed to open font file", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to open font file");
return false; R_FALSE
} }
// Read in the 95 used ascii characters for text. // Read in the 95 used ascii characters for text.
@@ -118,26 +123,31 @@ bool font_class::LoadFontData(char* filename)
// Close the file. // Close the file.
fin.close(); fin.close();
Logger::Get().Log("Font data loaded", __FILE__, __LINE__); LOG_INFO("Font data loaded");
return true; R_TRUE
} }
void font_class::ReleaseFontData() void font_class::ReleaseFontData()
{ {
LOG_SHUTDOWN("Releasing font data");
// Release the font data array. // Release the font data array.
if (m_Font) if (m_Font)
{ {
LOG_SHUTDOWN("Releasing font array");
delete[] m_Font; delete[] m_Font;
m_Font = 0; m_Font = 0;
LOG_SHUTDOWN("Font array released");
} }
LOG_SHUTDOWN("Font data released");
return; return;
} }
bool font_class::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename) bool font_class::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename)
{ {
Logger::Get().Log(("Loading font texture from %s", filename), __FILE__, __LINE__); LOG_INFO("Loading font texture from " + std::string(filename));
bool result; bool result;
@@ -148,25 +158,30 @@ bool font_class::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCo
result = m_Texture->Initialize(device, deviceContext, filename); result = m_Texture->Initialize(device, deviceContext, filename);
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to initialize font texture", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize font texture");
return false; R_FALSE
} }
Logger::Get().Log("Font texture loaded", __FILE__, __LINE__); LOG_INFO("Font texture loaded");
return true; R_TRUE
} }
void font_class::ReleaseTexture() void font_class::ReleaseTexture()
{ {
LOG_SHUTDOWN("Releasing font texture");
// Release the texture object. // Release the texture object.
if (m_Texture) if (m_Texture)
{ {
LOG_SHUTDOWN("Releasing texture object");
m_Texture->Shutdown(); m_Texture->Shutdown();
delete m_Texture; delete m_Texture;
m_Texture = 0; m_Texture = 0;
LOG_SHUTDOWN("Texture object released");
} }
LOG_SHUTDOWN("Font texture released");
return; return;
} }

View File

@@ -56,33 +56,14 @@ void frustum::ConstructFrustum(float screenDepth, XMMATRIX projectionMatrix, XMM
} }
} }
bool frustum::CheckCube(float xCenter, float yCenter, float zCenter, float radius, float tolerance) bool frustum::CheckCube(const float x_center,const float y_center,const float z_center,const float radius,const float tolerance)
{ {
// V<>rifiez chaque plan du frustum pour voir si le cube est <20> l'int<6E>rieur // V<>rifiez chaque plan du frustum pour voir si le cube est <20> l'int<6E>rieur
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
XMVECTOR plane = m_planes[i]; XMVECTOR plane = m_planes[i];
if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance) CHECK_FRUSTRUM_CUBE_CORNERS(plane, x_center, y_center, z_center, radius, tolerance)
continue;
if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance)
continue;
if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance)
continue;
if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter - radius) + XMVectorGetW(plane) > -tolerance)
continue;
if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)
continue;
if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter - radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)
continue;
if (XMVectorGetX(plane) * (xCenter - radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)
continue;
if (XMVectorGetX(plane) * (xCenter + radius) + XMVectorGetY(plane) * (yCenter + radius) + XMVectorGetZ(plane) * (zCenter + radius) + XMVectorGetW(plane) > -tolerance)
continue;
// Si le cube est en dehors de l'un des plans, il n'est pas dans le frustum
return false;
} }
// Si le cube est <20> l'int<6E>rieur de tous les plans, il est dans le frustum // Si le cube est <20> l'int<6E>rieur de tous les plans, il est dans le frustum
return true; R_TRUE
} }

View File

@@ -130,11 +130,11 @@ bool FrustumClass::CheckPoint(float x, float y, float z)
{ {
if (((m_planes[i].x * x) + (m_planes[i].y * y) + (m_planes[i].z * z) + m_planes[i].w) < 0.0f) if (((m_planes[i].x * x) + (m_planes[i].y * y) + (m_planes[i].z * z) + m_planes[i].w) < 0.0f)
{ {
return false; R_FALSE
} }
} }
return true; R_TRUE
} }
bool FrustumClass::CheckCube(float xCenter, float yCenter, float zCenter, float radius) bool FrustumClass::CheckCube(float xCenter, float yCenter, float zCenter, float radius)
@@ -201,10 +201,10 @@ bool FrustumClass::CheckCube(float xCenter, float yCenter, float zCenter, float
continue; continue;
} }
return false; R_FALSE
} }
return true; R_TRUE
} }
bool FrustumClass::CheckSphere(float xCenter, float yCenter, float zCenter, float radius) bool FrustumClass::CheckSphere(float xCenter, float yCenter, float zCenter, float radius)
@@ -217,11 +217,11 @@ bool FrustumClass::CheckSphere(float xCenter, float yCenter, float zCenter, floa
{ {
if (((m_planes[i].x * xCenter) + (m_planes[i].y * yCenter) + (m_planes[i].z * zCenter) + m_planes[i].w) < -radius) if (((m_planes[i].x * xCenter) + (m_planes[i].y * yCenter) + (m_planes[i].z * zCenter) + m_planes[i].w) < -radius)
{ {
return false; R_FALSE
} }
} }
return true; R_TRUE
} }
bool FrustumClass::CheckRectangle(float xCenter, float yCenter, float zCenter, float xSize, float ySize, float zSize) bool FrustumClass::CheckRectangle(float xCenter, float yCenter, float zCenter, float xSize, float ySize, float zSize)
@@ -288,9 +288,9 @@ bool FrustumClass::CheckRectangle(float xCenter, float yCenter, float zCenter, f
continue; continue;
} }
return false; R_FALSE
} }
return true; R_TRUE
} }

View File

@@ -2,8 +2,6 @@
#include "application_class.h" #include "application_class.h"
#include "stats.h" #include "stats.h"
static fps_limiter fpsLimiter(60.0f);
imguiManager::imguiManager() imguiManager::imguiManager()
{ {
io = nullptr; io = nullptr;
@@ -51,7 +49,7 @@ imguiManager::~imguiManager()
bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) { bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) {
std::ifstream file_in(filepath); std::ifstream file_in(filepath);
if (!file_in) return false; // fichier introuvable if (!file_in) R_FALSE // fichier introuvable
std::vector<std::string> lines; std::vector<std::string> lines;
std::string line; std::string line;
@@ -69,7 +67,8 @@ bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) {
line = "VER=" + std::to_string(BUILD_VERSION_VER); line = "VER=" + std::to_string(BUILD_VERSION_VER);
} }
} catch (...) { } catch (...) {
return false; // erreur conversion LOG_ERROR("Error converting VER to integer");
R_FALSE // erreur conversion
} }
} }
lines.push_back(line); lines.push_back(line);
@@ -84,18 +83,22 @@ bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) {
// Réécrire tout le fichier // Réécrire tout le fichier
std::ofstream file_out(filepath, std::ios::trunc); std::ofstream file_out(filepath, std::ios::trunc);
if (!file_out) return false; if (!file_out)
{
LOG_ERROR("Error writing to file");
R_FALSE
}
for (const auto& l : lines) { for (const auto& l : lines) {
file_out << l << "\n"; file_out << l << "\n";
} }
file_out.close(); file_out.close();
return true; R_TRUE
} }
bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext) bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext)
{ {
Logger::Get().Log("Initializing imgui", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing imgui");
m_device = device; m_device = device;
m_deviceContext = deviceContext; m_deviceContext = deviceContext;
@@ -117,13 +120,13 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
// Palette de couleurs sobres inspir<69>e des <20>diteurs modernes // Palette de couleurs sobres inspir<69>e des <20>diteurs modernes
ImVec4 background_dark = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); // Fond fonc<6E> // ImVec4 background_dark = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); // Fond fonc<6E>
ImVec4 background = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); // Fond principal // ImVec4 background = ImVec4(0.15f, 0.15f, 0.15f, 1.00f); // Fond principal
ImVec4 background_light = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); // Fond clair // ImVec4 background_light = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); // Fond clair
ImVec4 accent = ImVec4(0.14f, 0.44f, 0.80f, 0.50f); // Accent bleu // ImVec4 accent = ImVec4(0.14f, 0.44f, 0.80f, 0.50f); // Accent bleu
ImVec4 accent_light = ImVec4(0.14f, 0.44f, 0.80f, 1.00f); // Accent bleu vif // ImVec4 accent_light = ImVec4(0.14f, 0.44f, 0.80f, 1.00f); // Accent bleu vif
ImVec4 text = ImVec4(1.0f, 1.0f, 1.0f, 1.00f); // Texte plus blanc // ImVec4 text = ImVec4(1.0f, 1.0f, 1.0f, 1.00f); // Texte plus blanc
ImVec4 text_dim = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); // ImVec4 text_dim = ImVec4(0.70f, 0.70f, 0.70f, 1.00f);
// Ajustements de style g<>n<EFBFBD>raux // Ajustements de style g<>n<EFBFBD>raux
style.WindowPadding = ImVec2(4.0f, 4.0f); // Moins de padding dans les fen<65>tres style.WindowPadding = ImVec2(4.0f, 4.0f); // Moins de padding dans les fen<65>tres
@@ -147,57 +150,57 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
style.TabRounding = 4.0f; style.TabRounding = 4.0f;
// Couleurs principales // Couleurs principales
style.Colors[ImGuiCol_Text] = text; style.Colors[ImGuiCol_Text] = TEXT_COLOR;
style.Colors[ImGuiCol_TextDisabled] = text_dim; style.Colors[ImGuiCol_TextDisabled] = TEXT_DIM_COLOR;
style.Colors[ImGuiCol_WindowBg] = background; style.Colors[ImGuiCol_WindowBg] = BG_GRAY;
style.Colors[ImGuiCol_ChildBg] = background_dark; style.Colors[ImGuiCol_ChildBg] = BG_DK_GRAY;
style.Colors[ImGuiCol_PopupBg] = background_dark; style.Colors[ImGuiCol_PopupBg] = BG_DK_GRAY;
style.Colors[ImGuiCol_Border] = ImVec4(0.25f, 0.25f, 0.27f, 1.00f); style.Colors[ImGuiCol_Border] = BORDER_COLOR;
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); style.Colors[ImGuiCol_BorderShadow] = BLK;
// Encadrements // Encadrements
style.Colors[ImGuiCol_FrameBg] = background_light; style.Colors[ImGuiCol_FrameBg] = BG_LT_GRAY;
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f); style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f);
// Titres // Titres
style.Colors[ImGuiCol_TitleBg] = background_dark; style.Colors[ImGuiCol_TitleBg] = BG_DK_GRAY;
style.Colors[ImGuiCol_TitleBgActive] = accent; style.Colors[ImGuiCol_TitleBgActive] = ACCENT_COLOR;
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.12f, 0.12f, 0.12f, 0.90f); style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.12f, 0.12f, 0.12f, 0.90f);
// <20>l<EFBFBD>ments de menu // <20>l<EFBFBD>ments de menu
style.Colors[ImGuiCol_MenuBarBg] = background_dark; style.Colors[ImGuiCol_MenuBarBg] = BG_DK_GRAY;
style.Colors[ImGuiCol_ScrollbarBg] = background_dark; style.Colors[ImGuiCol_ScrollbarBg] = BG_DK_GRAY;
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
// Boutons et interactions // Boutons et interactions
style.Colors[ImGuiCol_CheckMark] = accent_light; style.Colors[ImGuiCol_CheckMark] = ACCENT_LT_COLOR;
style.Colors[ImGuiCol_SliderGrab] = accent; style.Colors[ImGuiCol_SliderGrab] = ACCENT_COLOR;
style.Colors[ImGuiCol_SliderGrabActive] = accent_light; style.Colors[ImGuiCol_SliderGrabActive] = ACCENT_LT_COLOR;
style.Colors[ImGuiCol_Button] = background_light; style.Colors[ImGuiCol_Button] = BG_LT_GRAY;
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f); style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.30f, 0.30f, 1.00f);
style.Colors[ImGuiCol_ButtonActive] = accent; style.Colors[ImGuiCol_ButtonActive] = ACCENT_COLOR;
// En-t<>tes et onglets // En-t<>tes et onglets
style.Colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); style.Colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f); style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
style.Colors[ImGuiCol_HeaderActive] = accent; style.Colors[ImGuiCol_HeaderActive] = ACCENT_COLOR;
style.Colors[ImGuiCol_Separator] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f); style.Colors[ImGuiCol_Separator] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f);
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f); style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.45f, 0.45f, 0.45f, 1.00f);
style.Colors[ImGuiCol_SeparatorActive] = accent; style.Colors[ImGuiCol_SeparatorActive] = ACCENT_COLOR;
style.Colors[ImGuiCol_Tab] = background_dark; style.Colors[ImGuiCol_Tab] = BG_DK_GRAY;
style.Colors[ImGuiCol_TabHovered] = accent; style.Colors[ImGuiCol_TabHovered] = ACCENT_COLOR;
style.Colors[ImGuiCol_TabActive] = accent; style.Colors[ImGuiCol_TabActive] = ACCENT_COLOR;
style.Colors[ImGuiCol_TabUnfocused] = background_dark; style.Colors[ImGuiCol_TabUnfocused] = BG_DK_GRAY;
style.Colors[ImGuiCol_TabUnfocusedActive] = background; style.Colors[ImGuiCol_TabUnfocusedActive] = BG_GRAY;
// Autres <20>l<EFBFBD>ments // Autres <20>l<EFBFBD>ments
style.Colors[ImGuiCol_DockingPreview] = accent; style.Colors[ImGuiCol_DockingPreview] = ACCENT_COLOR;
style.Colors[ImGuiCol_DockingEmptyBg] = background_light; style.Colors[ImGuiCol_DockingEmptyBg] = BG_LT_GRAY;
// Charger une police avec une meilleure nettet<65> // Charger une police avec une meilleure nettet<65>
ImFontConfig fontConfig; ImFontConfig fontConfig;
@@ -220,8 +223,8 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
// initialize the scene manager // initialize the scene manager
scene_manager_ = new scene_manager; scene_manager_ = new scene_manager;
if (!scene_manager_->initialize(app_.get())) { if (!scene_manager_->initialize(app_.get())) {
Logger::Get().Log("Failed to initialize scene manager", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize scene manager");
return false; R_FALSE
} }
stats_ = app_->get_stats(); stats_ = app_->get_stats();
@@ -254,29 +257,35 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
std::string configPath = "config.txt"; // ou chemin complet std::string configPath = "config.txt"; // ou chemin complet
configPath = exeDir + BUILD_VERSION_TYPE + "\\" + configPath; configPath = exeDir + BUILD_VERSION_TYPE + "\\" + configPath;
if (!IncrementBuildVersionInConfig(configPath)) { if (!IncrementBuildVersionInConfig(configPath)) {
Logger::Get().Log("Failed to increment build version in config.txt", __FILE__, __LINE__, Logger::LogLevel::Warning); LOG_WARNING("Failed to increment build version in config.txt");
} }
// update the build version text in the inverse build type folder // update the build version text in the inverse build type folder
configPath = "config.txt"; configPath = "config.txt";
configPath = exeDir + BUILD_VERSION_INVERSE + "\\" + configPath; configPath = exeDir + BUILD_VERSION_INVERSE + "\\" + configPath;
Logger::Get().Log("Inverse build type config path: " + configPath, __FILE__, __LINE__, Logger::LogLevel::Info); LOG_INFO("Inverse build type config path: " + configPath);
if (!IncrementBuildVersionInConfig(configPath)) { if (!IncrementBuildVersionInConfig(configPath)) {
Logger::Get().Log("Failed to increment build version in config.txt of inverse build type", __FILE__, __LINE__, Logger::LogLevel::Warning); LOG_WARNING("Failed to increment build version in config.txt of inverse build type");
}
// get the sky entity shared ptr from the application
sky_entity_shared_ptr_ = app_->get_sky_entity_shared_ptr();
if (!sky_entity_shared_ptr_) {
LOG_WARNING("Sky entity shared ptr is null");
} }
Logger::Get().Log("imgui initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("imgui initialized");
return true; R_TRUE
} }
void imguiManager::Shutdown() void imguiManager::Shutdown()
{ {
Logger::Get().Log("Shutting down imgui", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down imgui");
ImGui_ImplDX11_Shutdown(); ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown(); ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
Logger::Get().Log("imgui shutdown", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("imgui shutdown");
} }
void imguiManager::Render() void imguiManager::Render()
@@ -300,14 +309,7 @@ void imguiManager::NewFrame()
} }
void imguiManager::SetupDockspace() { void imguiManager::SetupDockspace() {
// Configuration du style pour supprimer l'espace autour des fen<65>tres dock<63>es BASIC_DOCK_STYLE_1
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
// Configuration du style pour les n<>uds de dock
ImGui::PushStyleVar(ImGuiStyleVar_DockingSeparatorSize, 1.0f); // R<>duit l'<27>paisseur des s<>parateurs
// Configuration de la fen<65>tre principale // Configuration de la fen<65>tre principale
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking; ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGuiViewport* viewport = ImGui::GetMainViewport();
@@ -331,27 +333,27 @@ void imguiManager::SetupDockspace() {
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("Windows")) { if (B_MENU("Windows")) {
ImGui::MenuItem("Object Window", NULL, &showObjectWindow); M_ITEM_LP("Object Window", &showObjectWindow);
ImGui::MenuItem("Terrain Window", NULL, &showTerrainWindow); M_ITEM_LP("Terrain Window", &showTerrainWindow);
ImGui::MenuItem("Light Window", NULL, &showLightWindow); M_ITEM_LP("Light Window", &showLightWindow);
ImGui::MenuItem("Engine Settings Window", NULL, &showEngineSettingsWindow); M_ITEM_LP("Engine Settings Window", &showEngineSettingsWindow);
ImGui::MenuItem("Log Window", NULL, &showLogWindow); M_ITEM_LP("Log Window", &showLogWindow);
ImGui::MenuItem("render Stats", NULL, &showStatsWindow); M_ITEM_LP("render Stats", &showStatsWindow);
ImGui::EndMenu(); E_MENU
} }
if (ImGui::BeginMenu("Scene")) { if (B_MENU("Scene")) {
if (ImGui::MenuItem("Save Scene")) { if (M_ITEM_L("Save Scene")) {
scene_manager_->save_scene(); scene_manager_->save_scene();
} }
if (ImGui::MenuItem("Save Scene As...")) { if (M_ITEM_L("Save Scene As...")) {
scene_manager_->save_scene_as(); scene_manager_->save_scene_as();
} }
if (ImGui::MenuItem("Load Scene")) { if (M_ITEM_L("Load Scene")) {
scene_manager_->load_scene(); scene_manager_->load_scene();
} }
ImGui::EndMenu(); E_MENU
} }
const float PAD_X = 14.0f; const float PAD_X = 14.0f;
@@ -395,34 +397,34 @@ void imguiManager::SetupDockspace() {
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
ImGui::End(); END
} }
void imguiManager::WidgetSpeedSlider(float* speed) void imguiManager::WidgetSpeedSlider(float* speed)
{ {
ImGui::SliderFloat("Speed", speed, 0.0f, 100.0f); F_SLIDER("Speed", speed, 0.0f, 100.0f);
} }
void imguiManager::WidgetButton() void imguiManager::WidgetButton()
{ {
static int counter = 0; static int counter = 0;
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) if (BUTTON("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++; counter++;
ImGui::SameLine(); S_LINE
ImGui::Text("counter = %d", counter); TEXT_V("counter = %d", counter)
} }
void imguiManager::WidgetAddObject() void imguiManager::WidgetAddObject()
{ {
if (ImGui::CollapsingHeader("Objects")) if (C_HEADER("Objects"))
{ {
if (ImGui::Button("Add Cube")) if (BUTTON("Add Cube"))
{ {
app_->add_cube(); app_->add_cube();
} }
ImGui::SameLine(); S_LINE
if (ImGui::Button("Import Object")) if (BUTTON("Import Object"))
{ {
// Open file dialog // Open file dialog
OPENFILENAME ofn; OPENFILENAME ofn;
@@ -500,23 +502,25 @@ void imguiManager::WidgetAddObject()
// Remplacer les antislashs par des slashs // Remplacer les antislashs par des slashs
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/'); std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
app_->add_kobject(relativePath); app_->add_kobject(relativePath);
// set entities list as dirty
entityListDirty = true;
} }
} }
} }
ImGui::SameLine(); S_LINE
ImGui::Text("Number of cubes: %d", entity_manager_->GetEntityCount()); TEXT_V("Number of cubes: %d", entity_manager_->GetEntityCount());
} }
} }
void imguiManager::WidgetObjectWindow() void imguiManager::WidgetObjectWindow()
{ {
ImGui::Begin("Objects", &showObjectWindow); BEGIN("Objects", &showObjectWindow)
if (ImGui::Button("Add Cube")) { app_->add_cube(); } if (BUTTON("Add Cube")) { app_->add_cube(); }
ImGui::SameLine(); S_LINE
if (ImGui::Button("Import Object")) if (BUTTON("Import Object"))
{ {
// Open file dialog // Open file dialog
OPENFILENAME ofn; OPENFILENAME ofn;
@@ -594,44 +598,36 @@ void imguiManager::WidgetObjectWindow()
// Remplacer les antislashs par des slashs // Remplacer les antislashs par des slashs
std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/'); std::replace(relativePath.begin(), relativePath.end(), L'\\', L'/');
app_->add_kobject(relativePath); app_->add_kobject(relativePath);
// set list as dirty since new entity has been added to the scene
entityListDirty = true;
} }
} }
} }
ImGui::SameLine(); S_LINE
ImGui::Text("Number of objects: %d", entity_manager_->GetEntityCount()); TEXT_V("Number of cubes: %d", entity_manager_->GetEntityCount())
SEP
ImGui::Separator();
UpdateCachedEntitiesIfNeeded();
auto entities = entity_manager_->GetAllEntities();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(4,2)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(4,2));
for (auto& entity : entities) for (auto& cachedEntitie : cachedEntities_)
{ {
auto identity = entity->GetComponent<ecs::IdentityComponent>(); bool isSelected = (cachedEntitie.id == m_selected_entity_id);
if (identity) if (SEL(cachedEntitie.name.c_str(), isSelected))
{ {
std::string name = identity->GetName(); m_selected_entity_id = cachedEntitie.id;
if (name.empty()) name = "Entity #" + std::to_string(identity->GetId()); show_inspector_window_ = true;
bool isSelected = (entity->GetID() == m_selected_entity_id);
if (ImGui::Selectable(name.c_str(), isSelected))
{
m_selected_entity_id = entity->GetID();
show_inspector_window_ = true;
}
} }
} }
ImGui::PopStyleVar(); PSV
ImGui::End(); END
} }
void imguiManager::WidgetInspectorWindow() void imguiManager::WidgetInspectorWindow()
{ {
ImGui::Begin("Inspector", &show_inspector_window_); BEGIN("Inspector", &show_inspector_window_)
auto entity = entity_manager_->GetEntityByID(m_selected_entity_id); auto entity = entity_manager_->GetEntityByID(m_selected_entity_id);
if (entity) if (entity)
@@ -641,14 +637,14 @@ void imguiManager::WidgetInspectorWindow()
{ {
char name[256]; char name[256];
strcpy_s(name, identity->GetName().c_str()); strcpy_s(name, identity->GetName().c_str());
if (ImGui::InputText("Name", name, sizeof(name))) if (I_TEX("Name",name,sizeof(name)))
{ {
identity->SetName(std::string(name)); identity->SetName(std::string(name));
} }
ImGui::Text("ID: %d", identity->GetId()); TEXT_V("ID: %d", identity->GetId())
} }
ImGui::Separator(); SEP
// Lister et afficher les composants // Lister et afficher les composants
auto components = entity->GetAllComponents(); auto components = entity->GetAllComponents();
@@ -657,27 +653,28 @@ void imguiManager::WidgetInspectorWindow()
auto& comp = pair.second; auto& comp = pair.second;
// Utiliser le nom du type comme en-tete // Utiliser le nom du type comme en-tete
std::string compName = typeid(*comp).name(); std::string compName = typeid(*comp).name();
if (ImGui::CollapsingHeader(compName.c_str())) if (C_HEADER(compName.c_str()))
{ {
comp->OnImGuiRender(); comp->OnImGuiRender();
} }
} }
if (ImGui::Button("Delete Entity")) if (BUTTON("Delete Entity"))
{ {
entity_manager_->DestroyEntity(m_selected_entity_id); entity_manager_->DestroyEntity(m_selected_entity_id);
m_selected_entity_id = -1; m_selected_entity_id = -1;
show_inspector_window_ = false; show_inspector_window_ = false;
entityListDirty = true;
} }
ImGui::SameLine(); S_LINE
if (ImGui::Button("Add Component")) { if (BUTTON("Add Component")) {
ImGui::OpenPopup("AddComponentPopup"); O_POPUP("AddComponentPopup");
} }
if (ImGui::BeginPopup("AddComponentPopup")) { if (B_POPUP("AddComponentPopup")) {
ImGui::Text("Select Component to Add:"); TEX("Select Component to Add:")
ImGui::Separator(); SEP;
ComponentEntry componentsEntry[] = { ComponentEntry componentsEntry[] = {
{"Transform Component", [&]() { if (!entity->HasComponent<ecs::TransformComponent>()) entity->AddComponent<ecs::TransformComponent>(); }}, {"Transform Component", [&]() { if (!entity->HasComponent<ecs::TransformComponent>()) entity->AddComponent<ecs::TransformComponent>(); }},
@@ -692,65 +689,63 @@ void imguiManager::WidgetInspectorWindow()
}; };
for (auto& comp : componentsEntry) { for (auto& comp : componentsEntry) {
if (ImGui::MenuItem(comp.name)) { if (M_ITEM_L(comp.name)) {
comp.addFunc(); comp.addFunc();
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
} }
ImGui::EndPopup(); E_POPUP
} }
} }
else else
{ {
ImGui::Text("No entity selected."); TEX("No entity selected.")
} }
ImGui::End(); END
} }
void imguiManager::WidgetTerrainWindow() void imguiManager::WidgetTerrainWindow()
{ {
ImGui::Begin("Terrain", &showTerrainWindow); BEGIN("Terrain", &showTerrainWindow)
ImGui::Text("Number of terrain cubes: %d", app_->get_terrain_entity_count()); TEXT_V("Number of terrain cubes: %d", app_->get_terrain_entity_count())
SEP
ImGui::Separator(); if (BUTTON("Generate Flat Terrain"))
if (ImGui::Button("Generate Flat Terrain"))
{ {
app_->generate_terrain(); app_->generate_terrain();
} }
ImGui::Separator(); SEP
// Input for the number of cubes on each side // Input for the number of cubes on each side
ImGui::Text("Number of cubes on each side: "); TEX("Number of cubes on each side: ")
ImGui::SameLine(); S_LINE
ImGui::InputInt("##SideCount", &m_SideCount); ImGui::InputInt("##SideCount", &m_SideCount);
if (m_SideCount < 1) if (m_SideCount < 1)
{ {
m_SideCount = 1; m_SideCount = 1;
} }
ImGui::Separator(); SEP
if (ImGui::Button("Generate BigCube Terrain")) if (ImGui::Button("Generate BigCube Terrain"))
{ {
app_->create_big_cube(m_SideCount); app_->create_big_cube(m_SideCount);
} }
ImGui::Separator(); SEP
if (ImGui::Button("Delete All Terrain Cubes")) if (ImGui::Button("Delete All Terrain Cubes"))
{ {
app_->delete_terrain(); app_->delete_terrain();
} }
ImGui::End();
END
} }
bool imguiManager::ImGuiWidgetRenderer() bool imguiManager::ImGuiWidgetRenderer()
@@ -762,16 +757,6 @@ bool imguiManager::ImGuiWidgetRenderer()
SetupDockspace(); SetupDockspace();
//ImGui Widget //ImGui Widget
ImGui::Begin("Khaotic Engine", NULL);
float speed = app_->get_speed();
WidgetSpeedSlider(&speed);
app_->set_speed(speed);
WidgetButton();
WidgetAddObject();
ImGui::End();
// Read the widget list and call the function if the show variable is true // Read the widget list and call the function if the show variable is true
for (const auto& entry : widgets_) for (const auto& entry : widgets_)
@@ -782,12 +767,12 @@ bool imguiManager::ImGuiWidgetRenderer()
//render imgui //render imgui
Render(); Render();
return true; R_TRUE
} }
void imguiManager::WidgetLightWindow() void imguiManager::WidgetLightWindow()
{ {
ImGui::Begin("Light", &showLightWindow); BEGIN("Light", &showLightWindow)
// Sun light settings // Sun light settings
@@ -814,7 +799,7 @@ void imguiManager::WidgetLightWindow()
} }
ImGui::Separator(); SEP
int index = 0; int index = 0;
@@ -823,7 +808,7 @@ void imguiManager::WidgetLightWindow()
for(auto& light : app_->get_lights()) for(auto& light : app_->get_lights())
{ {
std::string headerName = "Light " + std::to_string(index); std::string headerName = "Light " + std::to_string(index);
if (ImGui::CollapsingHeader(headerName.c_str())) if (C_HEADER(headerName.c_str()))
{ {
XMVECTOR position = app_->get_light_position(index); XMVECTOR position = app_->get_light_position(index);
XMVECTOR color = app_->get_light_color(index); XMVECTOR color = app_->get_light_color(index);
@@ -847,68 +832,160 @@ void imguiManager::WidgetLightWindow()
index++; index++;
}; };
ImGui::End(); END
} }
void imguiManager::WidgetEngineSettingsWindow() void imguiManager::WidgetEngineSettingsWindow()
{ {
ImGui::Begin("Engine Settings", &showEngineSettingsWindow); BEGIN("Engine Settings", &showEngineSettingsWindow)
// Begining Of General Setting // Variables temporaires pour les settings
ImGui::Text("General"); static bool temp_v_sync = app_->get_vsync();
static int temp_target_fps = app_->get_target_fps();
static float temp_screen_depth = app_->get_screen_depth();
static float temp_screen_near = app_->get_screen_near();
static float temp_frustum_tolerance = app_->get_frustum_tolerance();
static int temp_physics_tick_rate = app_->get_physics_tick_rate();
static float temp_gravity_values[3] = {
XMVectorGetX(app_->get_physics()->GetGravity()),
XMVectorGetY(app_->get_physics()->GetGravity()),
XMVectorGetZ(app_->get_physics()->GetGravity())
};
// Checkbox for toggling vsync globally in the application class by calling the set_vsync function in the application class when the checkbox state changes if (ImGui::BeginTabBar("Engine Settings"))
bool vsync = app_->get_vsync();
if (ImGui::Checkbox("Vsync", &vsync))
{ {
app_->set_vsync(vsync); if (ImGui::BeginTabItem("General"))
{
ImGui::Checkbox("Vsync", &temp_v_sync);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Enable or disable Vsync");
ImGui::InputInt("Target FPS", &temp_target_fps);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Set the target FPS for the engine");
// Drag float input for screen depth and near with min and max values and update the app values on change
ImGui::DragFloat("Screen Depth", &temp_screen_depth, 1.f, 0.1f, 10000.0f);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Set the screen depth");
ImGui::DragFloat("Screen Near", &temp_screen_near, 1.f, 0.1f, 10000.0f);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Set the screen near");
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Culling Settings"))
{
ImGui::DragFloat("Frustum Tolerance", &temp_frustum_tolerance, 0.1f, 0.0f, 100.0f);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Set the frustum tolerance for culling");
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Physics Settings"))
{
ImGui::InputInt("Physics Tick Rate", &temp_physics_tick_rate);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Set the physics tick rate (Fixed Update Interval)");
ImGui::DragFloat3("Gravity", temp_gravity_values);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Set the gravity vector for the physics engine");
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Skysphere Settings"))
{
if (sky_entity_shared_ptr_)
{
// get the transform component
auto transform = sky_entity_shared_ptr_->GetComponent<ecs::TransformComponent>();
auto render = sky_entity_shared_ptr_->GetComponent<ecs::RenderComponent>();
auto shader = sky_entity_shared_ptr_->GetComponent<ecs::ShaderComponent>();
if (transform)
{
// get the scale and display it as a drag float3 input (need to convert from XMVECTOR to float[3])
XMVECTOR scale = transform->GetScale();
float scale_values[3] = { XMVectorGetX(scale), XMVectorGetY(scale), XMVectorGetZ(scale) };
if (ImGui::DragFloat3("Skysphere Scale", scale_values, 0.1f, 1.0f, 1000.0f))
{
transform->SetScale(XMVectorSet(scale_values[0], scale_values[1], scale_values[2], 0.0f));
}
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip("Set the scale of the skysphere");
}
}
if (render)
{
// display the render component default imguirender
render->OnImGuiRender();
}
if (shader)
{
// display the render component default imguirender
shader->OnImGuiRender();
}
}
else
{
TEX("Sky entity not found.")
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
} }
// End Of General Setting if (ImGui::Button("Apply Settings"))
ImGui::Separator();
// culling section
ImGui::Text("Culling");
// float input for frustum tolerance
float frustumTolerance = app_->get_frustum_tolerance();
if (ImGui::DragFloat("Frustum Tolerance", &frustumTolerance, 0.1f, 0.0f, 100.0f))
{ {
app_->set_frustum_tolerance(frustumTolerance); app_->set_vsync(temp_v_sync);
app_->set_target_fps(temp_target_fps);
app_->update_screen_depth(temp_screen_depth);
app_->update_screen_near(temp_screen_near);
app_->set_frustum_tolerance(temp_frustum_tolerance);
app_->set_physics_tick_rate(temp_physics_tick_rate);
app_->get_physics()->SetGravity(XMVectorSet(temp_gravity_values[0], temp_gravity_values[1], temp_gravity_values[2], 0.0f));
}
S_LINE
if (ImGui::Button("Reset Settings"))
{
temp_v_sync = app_->get_vsync();
temp_target_fps = app_->get_target_fps();
temp_screen_depth = app_->get_screen_depth();
temp_screen_near = app_->get_screen_near();
temp_frustum_tolerance = app_->get_frustum_tolerance();
temp_physics_tick_rate = app_->get_physics_tick_rate();
temp_gravity_values[0] = XMVectorGetX(app_->get_physics()->GetGravity());
temp_gravity_values[1] = XMVectorGetY(app_->get_physics()->GetGravity());
temp_gravity_values[2] = XMVectorGetZ(app_->get_physics()->GetGravity());
} }
// End Of Culling Setting END
ImGui::Separator();
// physics section
ImGui::Text("physics");
// Input To set the Fixed Update Interval
int physicsInterval = app_->get_physics_tick_rate();
if (ImGui::InputInt("physics Tick Rate", &physicsInterval))
{
app_->set_physics_tick_rate(physicsInterval);
}
// Input to change the gravity on same line
XMVECTOR gravity = app_->get_physics()->GetGravity();
float gravityValues[3] = { XMVectorGetX(gravity), XMVectorGetY(gravity), XMVectorGetZ(gravity) };
if (ImGui::DragFloat3("Gravity", gravityValues))
{
app_->get_physics()->SetGravity(XMVectorSet(gravityValues[0], gravityValues[1], gravityValues[2], 0.0f));
}
ImGui::End();
} }
void imguiManager::WidgetLogWindow() void imguiManager::WidgetLogWindow()
{ {
ImGui::Begin("Log Window" , &showLogWindow); BEGIN("Log Window" , &showLogWindow)
// Filtre de recherche // Filtre de recherche
static ImGuiTextFilter filter; static ImGuiTextFilter filter;
filter.Draw("Filter ", 180); filter.Draw("Filter ", 180);
ImGui::SameLine(); S_LINE
// Bouton pour ouvrir le fichier de log // Bouton pour ouvrir le fichier de log
if (ImGui::Button("Open Log File")) if (ImGui::Button("Open Log File"))
@@ -917,25 +994,25 @@ void imguiManager::WidgetLogWindow()
} }
// Place the menu on the same line as the filter // Place the menu on the same line as the filter
ImGui::SameLine(); S_LINE
// Menu d<>roulant pour les niveaux de log // Menu d<>roulant pour les niveaux de log
if (ImGui::BeginMenu("Log Levels")) if (B_MENU("Log Levels"))
{ {
for (size_t i = 0; i < Logger::LogLevelCount; ++i) for (size_t i = 0; i < Logger::LogLevelCount; ++i)
{ {
bool isVisible = !Logger::Get().m_disabledLogLevels[i]; bool isVisible = !Logger::Get().m_disabledLogLevels[i];
if (ImGui::Checkbox(Logger::Get().GetLogLevelInfo(static_cast<Logger::LogLevel>(i)).name, &isVisible)) if (C_BOX(Logger::Get().GetLogLevelInfo(static_cast<Logger::LogLevel>(i)).name, &isVisible))
{ {
Logger::Get().m_disabledLogLevels[i] = !isVisible; Logger::Get().m_disabledLogLevels[i] = !isVisible;
} }
} }
ImGui::EndMenu(); E_MENU
} }
const auto& logBuffer = Logger::Get().GetLogBuffer(); const auto& logBuffer = Logger::Get().GetLogBuffer();
std::vector<Logger::LogEntry> logfiltered; std::vector<Logger::LogEntry> logfiltered;
int logCount = logBuffer.size(); int logCount = ulli_to_int(logBuffer.size());
// Affichage des logs filtr<74>s // Affichage des logs filtr<74>s
ImGui::BeginChild("Log"); ImGui::BeginChild("Log");
@@ -950,7 +1027,7 @@ void imguiManager::WidgetLogWindow()
if (logfiltered.size() == 0) if (logfiltered.size() == 0)
{ {
ImGui::Text("No logs to display."); TEX("No logs to display.")
} }
else else
{ {
@@ -978,7 +1055,7 @@ void imguiManager::WidgetLogWindow()
ImGui::EndChild(); ImGui::EndChild();
ImGui::End(); END
} }
void imguiManager::WidgetRenderWindow(ImVec2 availableSize) void imguiManager::WidgetRenderWindow(ImVec2 availableSize)
@@ -1021,10 +1098,10 @@ void imguiManager::WidgetRenderWindow(ImVec2 availableSize)
} }
else else
{ {
ImGui::Text("render texture is not available."); TEX("render texture is not available.")
} }
ImGui::End(); END
} }
void imguiManager::WidgetRenderStats() void imguiManager::WidgetRenderStats()
@@ -1046,13 +1123,13 @@ void imguiManager::WidgetRenderStats()
m_frameTimeHistory[m_frameTimeHistoryIndex] = current_frame_time_; m_frameTimeHistory[m_frameTimeHistoryIndex] = current_frame_time_;
m_frameTimeHistoryIndex = (m_frameTimeHistoryIndex + 1) % FRAME_HISTORY_COUNT; m_frameTimeHistoryIndex = (m_frameTimeHistoryIndex + 1) % FRAME_HISTORY_COUNT;
ImGui::Text("FPS: %d", current_fps_); TEXT_V("FPS: %d", current_fps_)
ImGui::SameLine(); S_LINE
ImGui::Text("Min Fps: %d", min_fps_); TEXT_V("Min Fps: %d", min_fps_)
ImGui::SameLine(); S_LINE
ImGui::Text("Max Fps: %d", max_fps_); TEXT_V("Max Fps: %d", max_fps_)
ImGui::Separator(); SEP
// Trouver les valeurs min/max pour l'<27>chelle du graphique // Trouver les valeurs min/max pour l'<27>chelle du graphique
float frameTimeMin = FLT_MAX; float frameTimeMin = FLT_MAX;
@@ -1073,7 +1150,7 @@ void imguiManager::WidgetRenderStats()
frameTimeMax += margin; frameTimeMax += margin;
// Afficher le graphique // Afficher le graphique
ImGui::Text("Frame Time: %.3f ms", current_frame_time_ * 1000.0f); TEXT_V("Frame Time: %.3f ms", current_frame_time_ * 1000.0f)
ImGui::PlotLines("FrameTimeGraph", // Au lieu de cha<68>ne vide "" ImGui::PlotLines("FrameTimeGraph", // Au lieu de cha<68>ne vide ""
m_frameTimeHistory, m_frameTimeHistory,
FRAME_HISTORY_COUNT, FRAME_HISTORY_COUNT,
@@ -1083,16 +1160,16 @@ void imguiManager::WidgetRenderStats()
frameTimeMax, frameTimeMax,
ImVec2(0, 80)); ImVec2(0, 80));
ImGui::Text("Draw Calls: %d", draw_calls_); TEXT_V("Draw Calls: %d", draw_calls_)
ImGui::Separator(); SEP
ImGui::Text("Statistiques de rendu:"); TEX("Statistiques de rendu:")
ImGui::Text("Vertices total: %d", *total_vertex_count_); TEXT_V("Vertices total: %d", *total_vertex_count_)
ImGui::Text("Triangles total: %d", *total_triangle_count_); TEXT_V("Triangles total: %d", *total_triangle_count_)
ImGui::SameLine(); S_LINE
ImGui::Text("Triangles visibles: %d", visible_triangle_count_); TEXT_V("Triangles visibles: %d", visible_triangle_count_)
app_->get_direct_3d()->get_video_card_info(card_name_, video_memory_); app_->get_direct_3d()->get_video_card_info(card_name_, video_memory_);
cpu_name_ = stats_->get_cpu_name(); cpu_name_ = stats_->get_cpu_name();
@@ -1103,43 +1180,59 @@ void imguiManager::WidgetRenderStats()
ImGui::SetColumnWidth(1, ImGui::GetWindowWidth() * 0.33f); ImGui::SetColumnWidth(1, ImGui::GetWindowWidth() * 0.33f);
// Premier collapsing header pour les informations GPU // Premier collapsing header pour les informations GPU
if (ImGui::CollapsingHeader("Informations GPU")) if (C_HEADER("Informations GPU"))
{ {
ImGui::Text("Carte graphique: %s", card_name_); TEXT_V("Carte graphique: %s", card_name_)
ImGui::Text("Memoire video: %d Mo", video_memory_); TEXT_V("Memoire video: %d Mo", video_memory_)
ImGui::Text("Pilote: %s", version_driver_.c_str()); TEXT_V("Pilote: %s", version_driver_.c_str())
} }
ImGui::NextColumn(); ImGui::NextColumn();
// Second collapsing header pour les informations CPU // Second collapsing header pour les informations CPU
if (ImGui::CollapsingHeader("Informations CPU")) if (C_HEADER("Informations CPU"))
{ {
SYSTEM_INFO sysInfo; SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo); GetSystemInfo(&sysInfo);
ImGui::Text("Processeur: %s", cpu_name_.c_str()); TEXT_V("Processeur: %s", cpu_name_.c_str())
ImGui::Text("Nombre de coeurs: %u", sysInfo.dwNumberOfProcessors); TEXT_V("Nombre de coeurs: %u", sysInfo.dwNumberOfProcessors)
ImGui::Text("Architecture: %s", (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) ? "x64" : "x86"); TEXT_V("Architecture: %s", (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) ? "x64" : "x86")
ImGui::Text("Taille de la page: %u octets", sysInfo.dwPageSize); TEXT_V("Taille de la page: %u octets", sysInfo.dwPageSize)
ImGui::Text("Taille du cache: %u octets", sysInfo.dwAllocationGranularity); TEXT_V("Taille du cache: %u octets", sysInfo.dwAllocationGranularity)
ImGui::Text("Type de processeur: %u", sysInfo.wProcessorLevel); TEXT_V("Type de processeur: %u", sysInfo.wProcessorLevel)
ImGui::Text("Version du processeur: %u", sysInfo.wProcessorRevision); TEXT_V("Version du processeur: %u", sysInfo.wProcessorRevision)
} }
ImGui::NextColumn(); ImGui::NextColumn();
if (ImGui::CollapsingHeader("Informations RAM")) if (C_HEADER("Informations RAM"))
{ {
MEMORYSTATUSEX mem_info; MEMORYSTATUSEX mem_info;
mem_info.dwLength = sizeof(MEMORYSTATUSEX); mem_info.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&mem_info); GlobalMemoryStatusEx(&mem_info);
ImGui::Text("Memoire totale: %llu Mo", mem_info.ullTotalPhys / (1024 * 1024)); TEXT_V("Memoire totale: %llu Mo", mem_info.ullTotalPhys / (1024 * 1024))
ImGui::Text("Memoire disponible: %llu Mo", mem_info.ullAvailPhys / (1024 * 1024)); TEXT_V("Memoire disponible: %llu Mo", mem_info.ullAvailPhys / (1024 * 1024))
ImGui::Text("Memoire utilisee: %llu Mo", (mem_info.ullTotalPhys - mem_info.ullAvailPhys) / (1024 * 1024)); TEXT_V("Memoire utilisee: %llu Mo", (mem_info.ullTotalPhys - mem_info.ullAvailPhys) / (1024 * 1024))
} }
ImGui::Columns(1); ImGui::Columns(1);
ImGui::End(); END
} }
void imguiManager::UpdateCachedEntitiesIfNeeded() {
if (!entityListDirty) return;
cachedEntities_.clear();
auto entities = entity_manager_->GetAllEntities();
for (auto& entity : entities) {
auto identity = entity->GetComponent<ecs::IdentityComponent>();
if (identity) {
std::string name = identity->GetName();
auto id = identity->GetId();
if (name.empty())
name = "Entity " + std::to_string(identity->GetId());
cachedEntities_.push_back({name,id});
}
}
entityListDirty = false;
}

View File

@@ -21,7 +21,7 @@ input_class::~input_class()
bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight) bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
{ {
Logger::Get().Log("Initializing input class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing input class");
HRESULT result; HRESULT result;
int i; int i;
@@ -44,84 +44,84 @@ bool input_class::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, in
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL); result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create direct input interface", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create direct input interface");
return false; R_FALSE
} }
// Initialize the direct input interface for the keyboard. // Initialize the direct input interface for the keyboard.
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL); result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create direct input interface for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create direct input interface for the keyboard");
return false; R_FALSE
} }
// Set the data format. In this case since it is a keyboard we can use the predefined data format. // Set the data format. In this case since it is a keyboard we can use the predefined data format.
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard); result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to set data format for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set data format for the keyboard");
return false; R_FALSE
} }
// Set the cooperative level of the keyboard to share with other programs. // Set the cooperative level of the keyboard to share with other programs.
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to set cooperative level of the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set cooperative level of the keyboard");
return false; R_FALSE
} }
// Now acquire the keyboard. // Now acquire the keyboard.
result = m_keyboard->Acquire(); result = m_keyboard->Acquire();
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to acquire the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to acquire the keyboard");
return false; R_FALSE
} }
// Initialize the direct input interface for the mouse. // Initialize the direct input interface for the mouse.
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL); result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create direct input interface for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create direct input interface for the mouse");
return false; R_FALSE
} }
// Set the data format for the mouse using the pre-defined mouse data format. // Set the data format for the mouse using the pre-defined mouse data format.
result = m_mouse->SetDataFormat(&c_dfDIMouse); result = m_mouse->SetDataFormat(&c_dfDIMouse);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to set data format for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set data format for the mouse");
return false; R_FALSE
} }
// Set the cooperative level of the mouse to share with other programs. // Set the cooperative level of the mouse to share with other programs.
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to set cooperative level of the mouse", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to set cooperative level of the mouse");
return false; R_FALSE
} }
// Acquire the mouse. // Acquire the mouse.
result = m_mouse->Acquire(); result = m_mouse->Acquire();
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to acquire the mouse", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to acquire the mouse");
return false; R_FALSE
} }
Logger::Get().Log("Input class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Input class initialized");
return true; R_TRUE
} }
void input_class::KeyDown(unsigned int input) void input_class::KeyDown(unsigned int input)
{ {
// If a key is pressed then save that state in the key array. // If a key is pressed then save that state in the key array.
Logger::Get().Log("Key down: " + std::to_string(input), __FILE__, __LINE__, Logger::LogLevel::Input); LOG("Key down: " + std::to_string(input), Logger::LogLevel::Input);
m_keys[input] = true; m_keys[input] = true;
return; return;
} }
@@ -143,7 +143,7 @@ bool input_class::IsKeyDown(unsigned int key) const
void input_class::Shutdown() void input_class::Shutdown()
{ {
Logger::Get().Log("Shutting down input class", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down input class");
// Release the mouse. // Release the mouse.
if (m_mouse) if (m_mouse)
@@ -168,7 +168,7 @@ void input_class::Shutdown()
m_directInput = 0; m_directInput = 0;
} }
Logger::Get().Log("Input class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Input class shut down");
return; return;
} }
@@ -177,27 +177,26 @@ bool input_class::Frame()
{ {
bool result; bool result;
// Read the current state of the keyboard. // Read the current state of the keyboard.
result = ReadKeyboard(); result = ReadKeyboard();
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to read keyboard state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to read keyboard state");
return false; R_FALSE
} }
// Read the current state of the mouse. // Read the current state of the mouse.
result = ReadMouse(); result = ReadMouse();
if (!result) if (!result)
{ {
Logger::Get().Log("Failed to read mouse state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to read mouse state");
return false; R_FALSE
} }
// Process the changes in the mouse and keyboard. // Process the changes in the mouse and keyboard.
ProcessInput(); ProcessInput();
return true; R_TRUE
} }
bool input_class::ReadKeyboard() bool input_class::ReadKeyboard()
@@ -216,12 +215,12 @@ bool input_class::ReadKeyboard()
} }
else else
{ {
Logger::Get().Log("Failed to get keyboard device state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to get keyboard device state");
return false; R_FALSE
} }
} }
return true; R_TRUE
} }
bool input_class::ReadMouse() bool input_class::ReadMouse()
@@ -240,12 +239,12 @@ bool input_class::ReadMouse()
} }
else else
{ {
Logger::Get().Log("Failed to get mouse device state", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to get mouse device state");
return false; R_FALSE
} }
} }
return true; R_TRUE
} }
void input_class::ProcessInput() void input_class::ProcessInput()
@@ -269,20 +268,20 @@ bool input_class::IsEscapePressed() const
// Do a bitwise and on the keyboard state to check if the escape key is currently being pressed. // Do a bitwise and on the keyboard state to check if the escape key is currently being pressed.
if (m_keyboardState[DIK_ESCAPE] & 0x80) if (m_keyboardState[DIK_ESCAPE] & 0x80)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
bool input_class::IsLeftArrowPressed() const bool input_class::IsLeftArrowPressed() const
{ {
if (m_keyboardState[DIK_LEFT] & 0x80) if (m_keyboardState[DIK_LEFT] & 0x80)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
@@ -290,20 +289,20 @@ bool input_class::IsRightArrowPressed() const
{ {
if (m_keyboardState[DIK_RIGHT] & 0x80) if (m_keyboardState[DIK_RIGHT] & 0x80)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
bool input_class::IsUpArrowPressed() const bool input_class::IsUpArrowPressed() const
{ {
if (m_keyboardState[DIK_UP] & 0x80) if (m_keyboardState[DIK_UP] & 0x80)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
@@ -311,79 +310,16 @@ bool input_class::IsDownArrowPressed() const
{ {
if (m_keyboardState[DIK_DOWN] & 0x80) if (m_keyboardState[DIK_DOWN] & 0x80)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// Les touches correspondent aux claviers QWERTY // // Les touches correspondent aux claviers QWERTY //
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
bool input_class::IsAPressed() const
{
// Touche A sur QWERTY, Q sur AZERTY
if (m_keyboardState[DIK_A] & 0x80)
{
return true;
}
return false;
}
bool input_class::IsDPressed() const
{
if (m_keyboardState[DIK_D] & 0x80)
{
return true;
}
return false;
}
bool input_class::IsWPressed() const
{
// Touche W sur QWERTY, Z sur AZERTY
if (m_keyboardState[DIK_W] & 0x80)
{
return true;
}
return false;
}
bool input_class::IsSPressed() const
{
if (m_keyboardState[DIK_S] & 0x80)
{
return true;
}
return false;
}
bool input_class::IsQPressed() const
{
// Touche Q sur QWERTY, A sur AZERTY
if (m_keyboardState[DIK_Q] & 0x80)
{
return true;
}
return false;
}
bool input_class::IsEPressed() const
{
if (m_keyboardState[DIK_E] & 0x80)
{
return true;
}
return false;
}
void input_class::GetMouseLocation(int& mouseX, int& mouseY) const void input_class::GetMouseLocation(int& mouseX, int& mouseY) const
{ {
mouseX = m_mouseX; mouseX = m_mouseX;
@@ -396,10 +332,10 @@ bool input_class::IsLeftMousePressed() const
// Check the left mouse button state. // Check the left mouse button state.
if (m_mouseState.rgbButtons[0] & 0x80) if (m_mouseState.rgbButtons[0] & 0x80)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
bool input_class::IsRightMousePressed() const bool input_class::IsRightMousePressed() const
@@ -407,38 +343,33 @@ bool input_class::IsRightMousePressed() const
// Check the left mouse button state. // Check the left mouse button state.
if (m_mouseState.rgbButtons[1] & 0x80) if (m_mouseState.rgbButtons[1] & 0x80)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
bool input_class::IsScrollUp() const bool input_class::IsScrollUp() const
{ {
if (m_mouseState.lZ > 0) if (m_mouseState.lZ > 0)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
bool input_class::IsScrollDown() const bool input_class::IsScrollDown() const
{ {
if (m_mouseState.lZ < 0) if (m_mouseState.lZ < 0)
{ {
return true; R_TRUE
} }
return false; R_FALSE
} }
bool input_class::is_key_pressed(const unsigned int key_code) bool input_class::is_key_pressed(const unsigned int key_code)
{ {
if (m_keyboardState[key_code] & 0x80) return m_keyboardState[key_code] & 0x80;
{
return true;
}
return false;
} }

View File

@@ -29,12 +29,12 @@ bool model_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCo
bool result = Initialize(device, deviceContext, modelFilename); bool result = Initialize(device, deviceContext, modelFilename);
if (!result) { if (!result) {
return false; R_FALSE
} }
m_Textures = textures; // Copie de la structure de textures m_Textures = textures; // Copie de la structure de textures
return true; R_TRUE
} }
bool model_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename) { bool model_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename) {
@@ -44,8 +44,8 @@ bool model_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCo
// Load in the model data. // Load in the model data.
result = LoadModel(modelFilename); result = LoadModel(modelFilename);
if (!result) { if (!result) {
Logger::Get().Log("Failed to load model data", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to load model data");
return false; R_FALSE
} }
// Calculate the tangent and binormal vectors for the model. // Calculate the tangent and binormal vectors for the model.
@@ -54,11 +54,11 @@ bool model_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCo
// Initialize the vertex and index buffers. // Initialize the vertex and index buffers.
result = InitializeBuffers(device); result = InitializeBuffers(device);
if (!result) { if (!result) {
Logger::Get().Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to initialize buffers");
return false; R_FALSE
} }
return true; R_TRUE
} }
void model_class::Shutdown() void model_class::Shutdown()
@@ -139,8 +139,8 @@ bool model_class::InitializeBuffers(ID3D11Device* device)
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create vertex buffer");
return false; R_FALSE
} }
// Set up the description of the static index buffer. // Set up the description of the static index buffer.
@@ -160,8 +160,8 @@ bool model_class::InitializeBuffers(ID3D11Device* device)
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create index buffer");
return false; R_FALSE
} }
// Release the arrays now that the vertex and index buffers have been created and loaded. // Release the arrays now that the vertex and index buffers have been created and loaded.
@@ -170,7 +170,7 @@ bool model_class::InitializeBuffers(ID3D11Device* device)
delete[] indices; delete[] indices;
indices = 0; indices = 0;
return true; R_TRUE
} }
@@ -227,8 +227,8 @@ bool model_class::LoadModel(char* filename)
} }
else else
{ {
Logger::Get().Log("Unsupported file format", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Unsupported file format");
return false; R_FALSE
} }
} }
@@ -238,8 +238,8 @@ bool model_class::LoadObjModel(char* filename)
std::ifstream fin(filename, std::ios::in | std::ios::binary); std::ifstream fin(filename, std::ios::in | std::ios::binary);
if (!fin) if (!fin)
{ {
Logger::Get().Log("<EFBFBD>chec d'ouverture du fichier mod<6F>le", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec d'ouverture du fichier mod<6F>le");
return false; R_FALSE
} }
// Lecture du fichier entier d'un coup (<28>vite la lecture ligne par ligne) // Lecture du fichier entier d'un coup (<28>vite la lecture ligne par ligne)
@@ -309,9 +309,9 @@ bool model_class::LoadObjModel(char* filename)
while (*linePtr && *linePtr != ' ') linePtr++; while (*linePtr && *linePtr != ' ') linePtr++;
while (*linePtr == ' ') linePtr++; while (*linePtr == ' ') linePtr++;
if (posIndex[i] < 0) posIndex[i] += temp_positions.size() + 1; if (posIndex[i] < 0) posIndex[i] += size_t_to_int(temp_positions.size()) + 1;
if (texIndex[i] < 0) texIndex[i] += temp_texcoords.size() + 1; if (texIndex[i] < 0) texIndex[i] += size_t_to_int(temp_texcoords.size()) + 1;
if (normIndex[i] < 0) normIndex[i] += temp_normals.size() + 1; if (normIndex[i] < 0) normIndex[i] += size_t_to_int(temp_normals.size()) + 1;
} }
for (int i = 2; i >= 0; --i) for (int i = 2; i >= 0; --i)
@@ -331,12 +331,12 @@ bool model_class::LoadObjModel(char* filename)
} }
// Allocation et copie efficace du mod<6F>le final // Allocation et copie efficace du mod<6F>le final
m_vertexCount = temp_model.size(); m_vertexCount = size_t_to_int(temp_model.size());
m_indexCount = temp_model.size(); m_indexCount = size_t_to_int(temp_model.size());
m_model = new ModelType[m_vertexCount]; m_model = new ModelType[m_vertexCount];
std::memcpy(m_model, temp_model.data(), m_vertexCount * sizeof(ModelType)); std::memcpy(m_model, temp_model.data(), m_vertexCount * sizeof(ModelType));
return true; R_TRUE
} }
bool model_class::LoadTxtModel(char* filename) bool model_class::LoadTxtModel(char* filename)
@@ -352,8 +352,8 @@ bool model_class::LoadTxtModel(char* filename)
// If it could not open the file then exit. // If it could not open the file then exit.
if (fin.fail()) if (fin.fail())
{ {
Logger::Get().Log("Failed to open model file", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to open model file");
return false; R_FALSE
} }
// Read up to the value of vertex count. // Read up to the value of vertex count.
@@ -392,7 +392,7 @@ bool model_class::LoadTxtModel(char* filename)
// Close the model file. // Close the model file.
fin.close(); fin.close();
return true; R_TRUE
} }
void model_class::CalculateModelVectors() void model_class::CalculateModelVectors()
@@ -535,8 +535,8 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture); hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult)) if (FAILED(hResult))
{ {
Logger::Get().Log("<EFBFBD>chec du chargement de la texture diffuse: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec du chargement de la texture diffuse: " + std::string(texturePath.begin(), texturePath.end()));
return false; R_FALSE
} }
textureContainer.diffuse.push_back(texture); textureContainer.diffuse.push_back(texture);
} }
@@ -548,8 +548,8 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture); hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult)) if (FAILED(hResult))
{ {
Logger::Get().Log("<EFBFBD>chec du chargement de la texture normale: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec du chargement de la texture normale: " + std::string(texturePath.begin(), texturePath.end()));
return false; R_FALSE
} }
textureContainer.normal.push_back(texture); textureContainer.normal.push_back(texture);
} }
@@ -561,8 +561,8 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture); hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult)) if (FAILED(hResult))
{ {
Logger::Get().Log("<EFBFBD>chec du chargement de la texture sp<73>culaire: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec du chargement de la texture sp<73>culaire: " + std::string(texturePath.begin(), texturePath.end()));
return false; R_FALSE
} }
textureContainer.specular.push_back(texture); textureContainer.specular.push_back(texture);
} }
@@ -574,17 +574,17 @@ bool model_class::PreloadTextures(ID3D11Device* device, ID3D11DeviceContext* dev
hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture); hResult = DirectX::CreateWICTextureFromFile(device, deviceContext, texturePath.c_str(), nullptr, &texture);
if (FAILED(hResult)) if (FAILED(hResult))
{ {
Logger::Get().Log("<EFBFBD>chec du chargement de la texture alpha: " + std::string(texturePath.begin(), texturePath.end()), __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec du chargement de la texture alpha: " + std::string(texturePath.begin(), texturePath.end()));
return false; R_FALSE
} }
textureContainer.alpha.push_back(texture); textureContainer.alpha.push_back(texture);
} }
return true; R_TRUE
} }
bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type, int index) { bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type, int index) {
Logger::Get().Log("Changing texture", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Changing texture");
HRESULT result; HRESULT result;
ID3D11ShaderResourceView* newTexture = nullptr; ID3D11ShaderResourceView* newTexture = nullptr;
@@ -592,8 +592,8 @@ bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* devic
// Charger la nouvelle texture // Charger la nouvelle texture
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture); result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
if (FAILED(result)) { if (FAILED(result)) {
Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to load texture: " + std::string(filename.begin(), filename.end()));
return false; R_FALSE
} }
// R<>cup<75>rer le vecteur correspondant au type de texture // R<>cup<75>rer le vecteur correspondant au type de texture
@@ -640,12 +640,12 @@ bool model_class::ChangeTexture(ID3D11Device* device, ID3D11DeviceContext* devic
break; break;
} }
Logger::Get().Log("Texture changed successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Texture changed successfully");
return true; R_TRUE
} }
bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type) { bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, std::wstring filename, TextureType type) {
Logger::Get().Log("Adding texture", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Adding texture");
HRESULT result; HRESULT result;
ID3D11ShaderResourceView* newTexture = nullptr; ID3D11ShaderResourceView* newTexture = nullptr;
@@ -653,8 +653,8 @@ bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCo
// Charger la nouvelle texture // Charger la nouvelle texture
result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture); result = DirectX::CreateWICTextureFromFile(device, deviceContext, filename.c_str(), nullptr, &newTexture);
if (FAILED(result)) { if (FAILED(result)) {
Logger::Get().Log("Failed to load texture: " + std::string(filename.begin(), filename.end()), __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to load texture: " + std::string(filename.begin(), filename.end()));
return false; R_FALSE
} }
// Ajouter la texture au vecteur appropri<72> selon le type // Ajouter la texture au vecteur appropri<72> selon le type
@@ -677,14 +677,14 @@ bool model_class::AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCo
break; break;
} }
Logger::Get().Log("Texture added successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Texture added successfully");
return true; R_TRUE
} }
bool model_class::AddTexture(ID3D11ShaderResourceView* texture, TextureType type) { bool model_class::AddTexture(ID3D11ShaderResourceView* texture, TextureType type) {
if (!texture) { if (!texture) {
Logger::Get().Log("Cannot add null texture", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Cannot add null texture");
return false; R_FALSE
} }
// Ajouter la texture au vecteur appropri<72> // Ajouter la texture au vecteur appropri<72>
@@ -706,6 +706,6 @@ bool model_class::AddTexture(ID3D11ShaderResourceView* texture, TextureType type
m_Textures.alphaPaths.push_back(L"[texture pr<70>charg<72>e]"); m_Textures.alphaPaths.push_back(L"[texture pr<70>charg<72>e]");
break; break;
} }
return true; R_TRUE
} }

View File

@@ -61,13 +61,13 @@ bool object::Initialize(
auto new_model = std::make_shared<model_class>(); auto new_model = std::make_shared<model_class>();
if (!new_model->Initialize(device, deviceContext, modelFilename, texturesContainer)) if (!new_model->Initialize(device, deviceContext, modelFilename, texturesContainer))
{ {
return false; R_FALSE
} }
g_model_cache[filename] = new_model; g_model_cache[filename] = new_model;
m_model_ = new_model; m_model_ = new_model;
} }
return true; R_TRUE
} }
void object::SetScaleMatrix(XMMATRIX scaleMatrix) void object::SetScaleMatrix(XMMATRIX scaleMatrix)
@@ -405,7 +405,6 @@ bool object::LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, Textu
HRESULT result; HRESULT result;
int i = 0; int i = 0;
TextureType type;
for (const auto& texturePath : texturePaths) for (const auto& texturePath : texturePaths)
{ {
ID3D11ShaderResourceView* texture = nullptr; ID3D11ShaderResourceView* texture = nullptr;
@@ -421,16 +420,15 @@ bool object::LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, Textu
std::wstring ws(errMsg); std::wstring ws(errMsg);
std::string str(ws.begin(), ws.end()); std::string str(ws.begin(), ws.end());
Logger::Get().Log("Failed to load texture: " + std::string(texturePath.begin(), texturePath.end()) + LOG_ERROR("Failed to load texture: " + std::string(texturePath.begin(), texturePath.end()) +
"\nError: " + std::to_string(result) + "\nError: " + std::to_string(result) +
"\nDescription: " + str, "\nDescription: " + str);
__FILE__, __LINE__, Logger::LogLevel::Error); R_FALSE // Assurez-vous de retourner false ou de g<>rer l'erreur de mani<6E>re appropri<72>e
return false; // Assurez-vous de retourner false ou de g<>rer l'erreur de mani<6E>re appropri<72>e
} }
texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i); texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i);
i++; i++;
} }
return true; R_TRUE
} }

View File

@@ -84,7 +84,7 @@ bool physics::IsColliding(object* object1, object* object2)
if (type1 == ObjectType::Unknown || type2 == ObjectType::Unknown) if (type1 == ObjectType::Unknown || type2 == ObjectType::Unknown)
{ {
return false; R_FALSE
} }
if (type1 == ObjectType::Sphere && type2 == ObjectType::Sphere) if (type1 == ObjectType::Sphere && type2 == ObjectType::Sphere)
@@ -108,7 +108,7 @@ bool physics::IsColliding(object* object1, object* object2)
return CubesOverlap(object1, object2); return CubesOverlap(object1, object2);
} }
return false; R_FALSE
} }

View File

@@ -8,12 +8,6 @@ position_class::position_class()
m_positionX = 0.0f; m_positionX = 0.0f;
m_positionY = 0.0f; m_positionY = 0.0f;
m_positionZ = 0.0f; m_positionZ = 0.0f;
m_leftTurnSpeed = 0.0f;
m_rightTurnSpeed = 0.0f;
m_horizontalTurnSpeed = 0.0f;
m_verticalTurnSpeed = 0.0f;
m_cameraSpeed = 4.0f;
m_speed = m_cameraSpeed;
} }
@@ -45,197 +39,4 @@ void position_class::GetPosition(float& x, float& y, float& z) const
y = m_positionY; y = m_positionY;
z = m_positionZ; z = m_positionZ;
return; return;
}
void position_class::TurnLeft(bool keydown)
{
// If the key is pressed increase the speed at which the camera turns left. If not slow down the turn speed.
if (keydown)
{
m_leftTurnSpeed += m_frameTime * 1.5f;
if (m_leftTurnSpeed > (m_frameTime * 200.0f))
{
m_leftTurnSpeed = m_frameTime * 200.0f;
}
}
else
{
m_leftTurnSpeed -= m_frameTime * 1.0f;
if (m_leftTurnSpeed < 0.0f)
{
m_leftTurnSpeed = 0.0f;
}
}
// Update the rotation using the turning speed.
m_rotationY -= m_leftTurnSpeed;
if (m_rotationY < 0.0f)
{
m_rotationY += 360.0f;
}
return;
}
void position_class::TurnRight(bool keydown)
{
// If the key is pressed increase the speed at which the camera turns right. If not slow down the turn speed.
if (keydown)
{
m_rightTurnSpeed += m_frameTime * 1.5f;
if (m_rightTurnSpeed > (m_frameTime * 200.0f))
{
m_rightTurnSpeed = m_frameTime * 200.0f;
}
}
else
{
m_rightTurnSpeed -= m_frameTime * 1.0f;
if (m_rightTurnSpeed < 0.0f)
{
m_rightTurnSpeed = 0.0f;
}
}
// Update the rotation using the turning speed.
m_rotationY += m_rightTurnSpeed;
if (m_rotationY > 360.0f)
{
m_rotationY -= 360.0f;
}
return;
}
void position_class::TurnMouse(float deltaX, float deltaY, float sensitivity, bool rightMouseDown)
{
// The turning speed is proportional to the horizontal mouse movement
m_horizontalTurnSpeed = deltaX * sensitivity;
if (rightMouseDown)
{
// Update the rotation using the turning speed
m_rotationY += m_horizontalTurnSpeed;
if (m_rotationY < 0.0f)
{
m_rotationY += 360.0f;
}
else if (m_rotationY > 360.0f)
{
m_rotationY -= 360.0f;
}
// The turning speed is proportional to the vertical mouse movement
m_verticalTurnSpeed = deltaY * sensitivity;
// Update the rotation using the turning speed
m_rotationX += m_verticalTurnSpeed;
if (m_rotationX < -90.0f)
{
m_rotationX = -90.0f;
}
else if (m_rotationX > 90.0f)
{
m_rotationX = 90.0f;
}
}
return;
}
void position_class::MoveCamera(bool forward, bool backward, bool left, bool right, bool up, bool down, bool scrollUp, bool scrollDown, bool rightClick)
{
float radiansY, radiansX, speed;
// Set the speed of the camera if the right click is down.
if (scrollUp && rightClick)
{
m_cameraSpeed *= 1.1f;
}
if (scrollDown && rightClick)
{
m_cameraSpeed *= 0.9f;
if (m_cameraSpeed < 0.25f) // Minimum speed.
{
m_cameraSpeed = 0.25f;
}
}
// Convert degrees to radians.
radiansY = m_rotationY * 0.0174532925f;
radiansX = m_rotationX * 0.0174532925f;
//////////////////////////
// Update the position. //
//////////////////////////
// Moves the camera forward on a greater scale than the arrows.
if (scrollUp && !rightClick)
{
speed = m_speed * 20 * m_frameTime;
m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
m_positionY -= sinf(radiansX) * speed;
}
// Moves the camera backward on a greater scale than the arrows.
if (scrollDown && !rightClick)
{
speed = m_speed * 20 * m_frameTime;
m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
m_positionY += sinf(radiansX) * speed;
}
// Set the speed of the camera.
speed = m_cameraSpeed * m_frameTime;
// If moving forward, the position moves in the direction of the camera and accordingly to its angle.
if (forward)
{
m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
m_positionY -= sinf(radiansX) * speed;
}
// If moving backward, the position moves in the opposite direction of the camera and accordingly to its angle.
if (backward)
{
m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
m_positionY += sinf(radiansX) * speed;
}
// If moving left, the position moves to the left of the camera and accordingly to its angle.
if (left)
{
m_positionX -= cosf(radiansY) * speed;
m_positionZ += sinf(radiansY) * speed;
}
// If moving right, the position moves to the right of the camera and accordingly to its angle.
if (right)
{
m_positionX += cosf(radiansY) * speed;
m_positionZ -= sinf(radiansY) * speed;
}
// If moving up, the position moves up.
if (up)
{
m_positionY += speed;
}
// If moving down, the position moves down.
if (down)
{
m_positionY -= speed;
}
return;
} }

View File

@@ -21,7 +21,7 @@ render_texture_class::~render_texture_class()
bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, int textureHeight, float screenDepth, float screenNear, int format) bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, int textureHeight, float screenDepth, float screenNear, int format)
{ {
Logger::Get().Log("Initializing render_texture_class", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Initializing render_texture_class");
D3D11_TEXTURE2D_DESC textureDesc; D3D11_TEXTURE2D_DESC textureDesc;
HRESULT result; HRESULT result;
@@ -70,8 +70,8 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
result = device->CreateTexture2D(&textureDesc, NULL, &m_renderTargetTexture); result = device->CreateTexture2D(&textureDesc, NULL, &m_renderTargetTexture);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create render target texture", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create render target texture");
return false; R_FALSE
} }
// Setup the description of the render target view. // Setup the description of the render target view.
@@ -83,8 +83,8 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
result = device->CreateRenderTargetView(m_renderTargetTexture, &renderTargetViewDesc, &m_renderTargetView); result = device->CreateRenderTargetView(m_renderTargetTexture, &renderTargetViewDesc, &m_renderTargetView);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create render target view", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create render target view");
return false; R_FALSE
} }
// Setup the description of the shader resource view. // Setup the description of the shader resource view.
@@ -97,8 +97,8 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
result = device->CreateShaderResourceView(m_renderTargetTexture, &shaderResourceViewDesc, &m_shaderResourceView); result = device->CreateShaderResourceView(m_renderTargetTexture, &shaderResourceViewDesc, &m_shaderResourceView);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create shader resource view", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create shader resource view");
return false; R_FALSE
} }
// Initialize the description of the depth buffer. // Initialize the description of the depth buffer.
@@ -121,8 +121,8 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
result = device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer); result = device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create depth buffer texture", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create depth buffer texture");
return false; R_FALSE
} }
// Initailze the depth stencil view description. // Initailze the depth stencil view description.
@@ -137,8 +137,8 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
result = device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView); result = device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
if (FAILED(result)) if (FAILED(result))
{ {
Logger::Get().Log("Failed to create depth stencil view", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Failed to create depth stencil view");
return false; R_FALSE
} }
// Setup the viewport for rendering. // Setup the viewport for rendering.
@@ -155,14 +155,14 @@ bool render_texture_class::Initialize(ID3D11Device * device, int textureWidth, i
// Create an orthographic projection matrix for 2D rendering. // Create an orthographic projection matrix for 2D rendering.
m_orthoMatrix = XMMatrixOrthographicLH((float)textureWidth, (float)textureHeight, screenNear, screenDepth); m_orthoMatrix = XMMatrixOrthographicLH((float)textureWidth, (float)textureHeight, screenNear, screenDepth);
Logger::Get().Log("render_texture_class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("render_texture_class initialized");
return true; R_TRUE
} }
void render_texture_class::Shutdown() void render_texture_class::Shutdown()
{ {
Logger::Get().Log("Shutting down render_texture_class", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("Shutting down render_texture_class");
if (m_depthStencilView) if (m_depthStencilView)
{ {
@@ -194,7 +194,7 @@ void render_texture_class::Shutdown()
m_renderTargetTexture = 0; m_renderTargetTexture = 0;
} }
Logger::Get().Log("render_texture_class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); LOG_SHUTDOWN("render_texture_class shut down");
return; return;
} }

View File

@@ -13,35 +13,34 @@ scene_manager::~scene_manager()
bool scene_manager::initialize(application_class* app) bool scene_manager::initialize(application_class* app)
{ {
if (!app) { if (!app) {
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Application pointer is null");
return false; R_FALSE
} }
app_ = app; app_ = app;
if (app_ == nullptr) { if (app_ == nullptr) {
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Application pointer is null");
return false; R_FALSE
} }
direct_3d_ = app_->get_direct_3d(); direct_3d_ = app_->get_direct_3d();
if (!direct_3d_) { if (!direct_3d_) {
Logger::Get().Log("Direct3D pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Direct3D pointer is null");
return false; R_FALSE
} }
return true; R_TRUE
} }
bool scene_manager::shutdown() bool scene_manager::shutdown()
{ {
app_ = nullptr; app_ = nullptr;
return true; R_TRUE
} }
bool scene_manager::save_scene_as() { bool scene_manager::save_scene_as() {
LOG_INFO("Saving scene as...");
Logger::Get().Log("Saving scene as...", __FILE__, __LINE__, Logger::LogLevel::Info);
OPENFILENAME ofn; OPENFILENAME ofn;
wchar_t szFile[260] = { 0 }; wchar_t szFile[260] = { 0 };
@@ -68,12 +67,11 @@ bool scene_manager::save_scene_as() {
// Sauvegarder la sc<73>ne avec le nouveau chemin // Sauvegarder la sc<73>ne avec le nouveau chemin
save_scene(); save_scene();
LOG_INFO("Scene saved as: " + scene_path_);
Logger::Get().Log("Scene saved as: " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Info); R_FALSE
return false;
} }
return true; R_TRUE
} }
bool scene_manager::load_scene() { bool scene_manager::load_scene() {
@@ -94,16 +92,16 @@ bool scene_manager::load_scene() {
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
ofn.lpstrDefExt = L"ker"; ofn.lpstrDefExt = L"ker";
if (GetOpenFileName(&ofn) != TRUE) { if (GetOpenFileName(&ofn) != TRUE) {
Logger::Get().Log("Load scene canceled or failed", __FILE__, __LINE__, Logger::LogLevel::Warning); LOG_WARNING("Load scene canceled or failed");
return false; // L'utilisateur a annul<75> la bo<62>te de dialogue R_FALSE // L'utilisateur a annul<75> la bo<62>te de dialogue
} }
std::filesystem::path filepath = ofn.lpstrFile; std::filesystem::path filepath = ofn.lpstrFile;
scene_path_ = convert_w_string_to_string(filepath.wstring()); scene_path_ = convert_w_string_to_string(filepath.wstring());
if (scene_path_.empty()) { if (scene_path_.empty()) {
Logger::Get().Log("Invalid scene path", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Invalid scene path");
return false; R_FALSE
} }
Logger::Get().Log("Loading scene from: " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Info); LOG_INFO("Loading scene from: " + scene_path_);
w_folder_ = app_->get_w_folder(); w_folder_ = app_->get_w_folder();
@@ -115,8 +113,8 @@ bool scene_manager::load_scene() {
std::ifstream inFile(scene_path_); std::ifstream inFile(scene_path_);
if (!inFile.is_open()) { if (!inFile.is_open()) {
Logger::Get().Log("<EFBFBD>chec de l'ouverture du fichier", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec de l'ouverture du fichier");
return false; R_FALSE
} }
auto entity_manager = app_->get_entity_manager(); auto entity_manager = app_->get_entity_manager();
@@ -155,18 +153,18 @@ bool scene_manager::load_scene() {
auto modelPathComponent = currentEntity->GetComponent<ecs::ModelPathComponent>(); auto modelPathComponent = currentEntity->GetComponent<ecs::ModelPathComponent>();
if (!modelPathComponent) { if (!modelPathComponent) {
Logger::Get().Log("ModelPathComponent missing for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning); LOG_WARNING("ModelPathComponent missing for entity ID: " + std::to_string(currentEntity->GetID()));
} }
if (!modelPathComponent || modelPathComponent->GetPath().empty()) { if (!modelPathComponent || modelPathComponent->GetPath().empty()) {
Logger::Get().Log("No model path specified for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning); LOG_WARNING("No model path specified for entity ID: " + std::to_string(currentEntity->GetID()));
} }
auto renderComponent = currentEntity->GetComponent<ecs::RenderComponent>(); auto renderComponent = currentEntity->GetComponent<ecs::RenderComponent>();
if (!renderComponent) if (!renderComponent)
{ {
Logger::Get().Log("RenderComponent missing for entity ID: " + std::to_string(currentEntity->GetID()), __FILE__, __LINE__, Logger::LogLevel::Warning); LOG_WARNING("RenderComponent missing for entity ID: " + std::to_string(currentEntity->GetID()));
} }
currentTextures = renderComponent->GetTextureContainerBuffer(); currentTextures = renderComponent->GetTextureContainerBuffer();
@@ -185,7 +183,7 @@ bool scene_manager::load_scene() {
// Pr<50>charger les textures // Pr<50>charger les textures
if (!model->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), currentTextures)) { if (!model->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), currentTextures)) {
Logger::Get().Log("<EFBFBD>chec du pr<70>chargement des textures", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec du pr<70>chargement des textures");
} }
char modelFilename[256]; char modelFilename[256];
@@ -193,7 +191,7 @@ bool scene_manager::load_scene() {
wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), modelPath.c_str(), _TRUNCATE); wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), modelPath.c_str(), _TRUNCATE);
if (!model->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, currentTextures)) { if (!model->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, currentTextures)) {
Logger::Get().Log("<EFBFBD>chec d'initialisation du mod<6F>le", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec d'initialisation du mod<6F>le");
} else { } else {
// Ajouter au cache // Ajouter au cache
modelCache[modelKey] = model; modelCache[modelKey] = model;
@@ -221,8 +219,8 @@ bool scene_manager::load_scene() {
} }
} }
Logger::Get().Log("Sc<EFBFBD>ne charg<72>e avec succ<63>s", __FILE__, __LINE__, Logger::LogLevel::Info); LOG_INFO("Sc<EFBFBD>ne charg<72>e avec succ<63>s");
return true; R_TRUE
} }
@@ -230,13 +228,12 @@ bool scene_manager::save_scene() {
entity_ = app_->get_entity_manager()->GetAllEntities(); entity_ = app_->get_entity_manager()->GetAllEntities();
if (scene_path_.empty() && !save_scene_as()) { if (scene_path_.empty() && !save_scene_as()) {
return false; R_FALSE
} }
std::ofstream outFile(scene_path_); std::ofstream outFile(scene_path_);
if (!outFile.is_open()) { if (!outFile.is_open()) {
Logger::Get().Log("<EFBFBD>chec de l'ouverture du fichier", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("<EFBFBD>chec de l'ouverture du fichier");
return false; R_FALSE
} }
for (const auto& entity : entity_) { for (const auto& entity : entity_) {
@@ -259,8 +256,8 @@ bool scene_manager::save_scene() {
} }
outFile.close(); outFile.close();
Logger::Get().Log("Sc<EFBFBD>ne sauvegard<72>e avec succ<63>s: " + scene_path_, __FILE__, __LINE__, Logger::LogLevel::Info); LOG_INFO("Sc<EFBFBD>ne sauvegard<72>e avec succ<63>s: " + scene_path_);
return true; R_TRUE
} }
std::wstring scene_manager::get_scene_path() std::wstring scene_manager::get_scene_path()
@@ -298,4 +295,3 @@ std::string scene_manager::convert_w_string_to_string(const std::wstring& wstr)
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, NULL, NULL); WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size_needed, NULL, NULL);
return str; return str;
} }

View File

@@ -22,7 +22,7 @@ bool shadow_map::initialize(ID3D11Device* device, int width, int height) {
texDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; texDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
if (FAILED(device->CreateTexture2D(&texDesc, nullptr, &depth_texture_))) if (FAILED(device->CreateTexture2D(&texDesc, nullptr, &depth_texture_)))
return false; R_FALSE
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {}; D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; dsvDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
@@ -30,7 +30,7 @@ bool shadow_map::initialize(ID3D11Device* device, int width, int height) {
dsvDesc.Texture2D.MipSlice = 0; dsvDesc.Texture2D.MipSlice = 0;
if (FAILED(device->CreateDepthStencilView(depth_texture_, &dsvDesc, &depth_stencil_view_))) if (FAILED(device->CreateDepthStencilView(depth_texture_, &dsvDesc, &depth_stencil_view_)))
return false; R_FALSE
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS; srvDesc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
@@ -38,9 +38,9 @@ bool shadow_map::initialize(ID3D11Device* device, int width, int height) {
srvDesc.Texture2D.MipLevels = 1; srvDesc.Texture2D.MipLevels = 1;
if (FAILED(device->CreateShaderResourceView(depth_texture_, &srvDesc, &shader_resource_view_))) if (FAILED(device->CreateShaderResourceView(depth_texture_, &srvDesc, &shader_resource_view_)))
return false; R_FALSE
return true; R_TRUE
} }
void shadow_map::shutdown() { void shadow_map::shutdown() {

View File

@@ -38,17 +38,17 @@ bool sprite_class::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceC
result = InitializeBuffers(device); result = InitializeBuffers(device);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
// Load the textures for this sprite. // Load the textures for this sprite.
result = LoadTextures(device, deviceContext, spriteFilename); result = LoadTextures(device, deviceContext, spriteFilename);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
return true; R_TRUE
} }
@@ -73,13 +73,13 @@ bool sprite_class::Render(ID3D11DeviceContext* deviceContext)
result = UpdateBuffers(deviceContext); result = UpdateBuffers(deviceContext);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
// Put the vertex and index buffers on the graphics pipeline to prepare them for drawing. // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
RenderBuffers(deviceContext); RenderBuffers(deviceContext);
return true; R_TRUE
} }
void sprite_class::Update(float frameTime) void sprite_class::Update(float frameTime)
@@ -169,7 +169,7 @@ bool sprite_class::InitializeBuffers(ID3D11Device* device)
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Set up the description of the index buffer. // Set up the description of the index buffer.
@@ -189,7 +189,7 @@ bool sprite_class::InitializeBuffers(ID3D11Device* device)
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Release the arrays now that the vertex and index buffers have been created and loaded. // Release the arrays now that the vertex and index buffers have been created and loaded.
@@ -199,7 +199,7 @@ bool sprite_class::InitializeBuffers(ID3D11Device* device)
delete[] indices; delete[] indices;
indices = 0; indices = 0;
return true; R_TRUE
} }
@@ -235,7 +235,7 @@ bool sprite_class::UpdateBuffers(ID3D11DeviceContext* deviceContent)
// If the position we are rendering this bitmap to hasn't changed then don't update the vertex buffer. // If the position we are rendering this bitmap to hasn't changed then don't update the vertex buffer.
if ((m_prevPosX == m_renderX) && (m_prevPosY == m_renderY)) if ((m_prevPosX == m_renderX) && (m_prevPosY == m_renderY))
{ {
return true; R_TRUE
} }
// If the rendering location has changed then store the new position and update the vertex buffer. // If the rendering location has changed then store the new position and update the vertex buffer.
@@ -282,7 +282,7 @@ bool sprite_class::UpdateBuffers(ID3D11DeviceContext* deviceContent)
result = deviceContent->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); result = deviceContent->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return false; R_FALSE
} }
// Get a pointer to the data in the constant buffer. // Get a pointer to the data in the constant buffer.
@@ -301,7 +301,7 @@ bool sprite_class::UpdateBuffers(ID3D11DeviceContext* deviceContent)
delete[] vertices; delete[] vertices;
vertices = 0; vertices = 0;
return true; R_TRUE
} }
@@ -340,7 +340,7 @@ bool sprite_class::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* devic
fin.open(filename); fin.open(filename);
if (fin.fail()) if (fin.fail())
{ {
return false; R_FALSE
} }
// Read in the number of textures. // Read in the number of textures.
@@ -369,7 +369,7 @@ bool sprite_class::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* devic
result = m_Textures[i].Initialize(device, deviceContext, textureFilename); result = m_Textures[i].Initialize(device, deviceContext, textureFilename);
if (!result) if (!result)
{ {
return false; R_FALSE
} }
} }
@@ -389,7 +389,7 @@ bool sprite_class::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* devic
// Set the starting texture in the cycle to be the first one in the list. // Set the starting texture in the cycle to be the first one in the list.
m_currentTexture = 0; m_currentTexture = 0;
return true; R_TRUE
} }
void sprite_class::ReleaseTextures() void sprite_class::ReleaseTextures()

View File

@@ -15,8 +15,8 @@ stats::~stats()
bool stats::initialize(application_class* app) bool stats::initialize(application_class* app)
{ {
if (!app) { if (!app) {
Logger::Get().Log("Application pointer is null", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("Application pointer is null");
return false; R_FALSE
} }
drawcalls_ = 0; drawcalls_ = 0;
@@ -25,13 +25,13 @@ bool stats::initialize(application_class* app)
fps_ = app_->get_fps(); fps_ = app_->get_fps();
if (!fps_) { if (!fps_) {
Logger::Get().Log("FPS object is null", __FILE__, __LINE__, Logger::LogLevel::Error); LOG_ERROR("FPS object is null");
return false; R_FALSE
} }
Logger::Get().Log("Stats initialized successfully", __FILE__, __LINE__, Logger::LogLevel::Initialize); LOG_INIT("Stats initialized successfully");
return true; R_TRUE
} }
void stats::update_geometric_stats() void stats::update_geometric_stats()
@@ -44,7 +44,7 @@ void stats::update_geometric_stats()
update_visible_count(); update_visible_count();
Logger::Get().Log("Statistics updated: " + std::to_string(*total_vertex_count_) + " vertices, " + std::to_string(*total_triangle_count_) + " triangles", __FILE__, __LINE__, Logger::LogLevel::Debug); LOG_DEBUG("Statistics updated: " + std::to_string(*total_vertex_count_) + " vertices, " + std::to_string(*total_triangle_count_) + " triangles");
} }
} }

Some files were not shown because too many files have changed in this diff Show More