Khaotic Engine Reborn
Loading...
Searching...
No Matches
ecs::RenderSystem Class Reference

Public Member Functions

 RenderSystem (ID3D11DeviceContext *deviceContext, shader_manager_class *shaderManager)
 
bool RenderEntity (std::shared_ptr< Entity > entity, const DirectX::XMMATRIX &viewMatrix, const DirectX::XMMATRIX &projectionMatrix, const DirectX::XMFLOAT4 *diffuseColors, const DirectX::XMFLOAT4 *lightPositions, const DirectX::XMFLOAT4 *ambientColors, const DirectX::XMFLOAT3 &cameraPosition, const DirectX::XMFLOAT4 &sunlightDiffuse, const DirectX::XMFLOAT4 &sunlightAmbient, const DirectX::XMFLOAT3 &sunlightDirection, float sunlightIntensity)
 
int RenderAllEntities (EntityManager *entityManager, const DirectX::XMMATRIX &viewMatrix, const DirectX::XMMATRIX &projectionMatrix, const DirectX::XMFLOAT4 *diffuseColors, const DirectX::XMFLOAT4 *lightPositions, const DirectX::XMFLOAT4 *ambientColors, const DirectX::XMFLOAT3 &cameraPos, const DirectX::XMFLOAT4 &sunlightDiffuse, const DirectX::XMFLOAT4 &sunlightAmbient, const DirectX::XMFLOAT3 &sunlightDirection, float sunlightIntensity)
 

Detailed Description

Definition at line 11 of file render_system.h.

Constructor & Destructor Documentation

◆ RenderSystem()

ecs::RenderSystem::RenderSystem ( ID3D11DeviceContext * deviceContext,
shader_manager_class * shaderManager )
inline

Builder for the RenderSystem class. This class is responsible for rendering entities with the necessary components.

Parameters
deviceContext
shaderManager

Definition at line 19 of file render_system.h.

20 : m_deviceContext(deviceContext), m_shaderManager(shaderManager) {}

Member Function Documentation

◆ RenderAllEntities()

int ecs::RenderSystem::RenderAllEntities ( EntityManager * entityManager,
const DirectX::XMMATRIX & viewMatrix,
const DirectX::XMMATRIX & projectionMatrix,
const DirectX::XMFLOAT4 * diffuseColors,
const DirectX::XMFLOAT4 * lightPositions,
const DirectX::XMFLOAT4 * ambientColors,
const DirectX::XMFLOAT3 & cameraPos,
const DirectX::XMFLOAT4 & sunlightDiffuse,
const DirectX::XMFLOAT4 & sunlightAmbient,
const DirectX::XMFLOAT3 & sunlightDirection,
float sunlightIntensity )
inline

Render all entities in the EntityManager that have the necessary components. This method iterates through all entities and renders them if they have the required components.

Parameters
entityManagerThe EntityManager containing the entities to render.
viewMatrixThe view matrix for rendering.
projectionMatrixThe projection matrix for rendering.
diffuseColorsArray of diffuse colors for lighting.
lightPositionsArray of light positions for lighting.
ambientColorsArray of ambient colors for lighting.
cameraPosThe position of the camera in world space.
sunlightDiffuseThe diffuse color of sunlight.
sunlightAmbientThe ambient color of sunlight.
sunlightDirectionThe direction of sunlight in world space.
sunlightIntensityThe intensity of sunlight.
Returns
The number of entities rendered successfully.

Definition at line 214 of file render_system.h.

224 {
225
226 int renderCount = 0;
227
228 // Récupérer toutes les entités qui ont les composants RenderComponent et TransformComponent
229 auto entities = entityManager->GetEntitiesWithComponent<RenderComponent>();
230
231 for (auto& entity : entities) {
232 auto render = entity->GetComponent<RenderComponent>();
233
234 // Vérifier si l'entité a un TransformComponent
235 auto transform = entity->GetComponent<TransformComponent>();
236 if (!transform) continue;
237
238 // Vérifier si le modèle est visible
239 if (!render->IsVisible()) continue;
240
241 // Effectuer le rendu
242 if (RenderEntity(entity, viewMatrix, projectionMatrix,
243 diffuseColors, lightPositions, ambientColors,cameraPos,
244 sunlightDiffuse, sunlightAmbient, sunlightDirection,
245 sunlightIntensity)) {
246 renderCount++;
247 }
248 }
249
250 return renderCount;
251 }
bool RenderEntity(std::shared_ptr< Entity > entity, const DirectX::XMMATRIX &viewMatrix, const DirectX::XMMATRIX &projectionMatrix, const DirectX::XMFLOAT4 *diffuseColors, const DirectX::XMFLOAT4 *lightPositions, const DirectX::XMFLOAT4 *ambientColors, const DirectX::XMFLOAT3 &cameraPosition, const DirectX::XMFLOAT4 &sunlightDiffuse, const DirectX::XMFLOAT4 &sunlightAmbient, const DirectX::XMFLOAT3 &sunlightDirection, float sunlightIntensity)

◆ RenderEntity()

bool ecs::RenderSystem::RenderEntity ( std::shared_ptr< Entity > entity,
const DirectX::XMMATRIX & viewMatrix,
const DirectX::XMMATRIX & projectionMatrix,
const DirectX::XMFLOAT4 * diffuseColors,
const DirectX::XMFLOAT4 * lightPositions,
const DirectX::XMFLOAT4 * ambientColors,
const DirectX::XMFLOAT3 & cameraPosition,
const DirectX::XMFLOAT4 & sunlightDiffuse,
const DirectX::XMFLOAT4 & sunlightAmbient,
const DirectX::XMFLOAT3 & sunlightDirection,
float sunlightIntensity )
inline

Render an entity with the necessary components. This method checks if the entity has the required components and renders it using the appropriate shader.

Parameters
entityThe entity to render.
viewMatrixThe view matrix for rendering.
projectionMatrixThe projection matrix for rendering.
diffuseColorsArray of diffuse colors for lighting.
lightPositionsArray of light positions for lighting.
ambientColorsArray of ambient colors for lighting.
cameraPositionThe position of the camera in world space.
sunlightDiffuseThe diffuse color of sunlight.
sunlightAmbientThe ambient color of sunlight.
sunlightDirectionThe direction of sunlight in world space.
sunlightIntensityThe intensity of sunlight.
Returns
True if rendering was successful, false otherwise.

Definition at line 38 of file render_system.h.

48 {
49
50 // Vérifier si l'entité a tous les composants nécessaires
51 auto transform = entity->GetComponent<TransformComponent>();
52 auto render = entity->GetComponent<RenderComponent>();
53 auto shader = entity->GetComponent<ShaderComponent>();
54
55 if (!transform || !render || !shader || !render->GetModel())
56 return false;
57
58 // Calculer la matrice monde
59 XMMATRIX scaleMatrix = transform->GetScaleMatrix();
60 XMMATRIX rotateMatrix = transform->GetRotateMatrix();
61 XMMATRIX translateMatrix = transform->GetTranslateMatrix();
62
63 XMMATRIX worldMatrix = XMMatrixMultiply(
64 XMMatrixMultiply(scaleMatrix, rotateMatrix),
65 translateMatrix
66 );
67
68 // Rendre le modèle
69 render->Render(m_deviceContext);
70
71 // Sélectionner le shader approprié
72 switch (shader->GetActiveShader()) {
73 case ShaderType::ALPHA_MAPPING:
74 return m_shaderManager->render_alpha_map_shader(
75 m_deviceContext,
76 render->GetIndexCount(),
77 worldMatrix,
78 viewMatrix,
79 projectionMatrix,
80 render->GetTexture(TextureType::Diffuse, 0),
81 render->GetTexture(TextureType::Diffuse, 1),
82 render->GetTexture(TextureType::Alpha, 0)
83 );
84
85 case ShaderType::CEL_SHADING:
86 return m_shaderManager->render_cel_shading_shader(
87 m_deviceContext,
88 render->GetIndexCount(),
89 worldMatrix,
90 viewMatrix,
91 projectionMatrix,
92 render->GetTexture(TextureType::Diffuse, 0),
93 sunlightDiffuse,
94 sunlightAmbient,
95 sunlightDirection,
96 sunlightIntensity
97 );
98
99 case ShaderType::NORMAL_MAPPING:
100 return m_shaderManager->render_normal_map_shader(
101 m_deviceContext,
102 render->GetIndexCount(),
103 worldMatrix,
104 viewMatrix,
105 projectionMatrix,
106 render->GetTexture(TextureType::Diffuse, 0),
107 render->GetTexture(TextureType::Normal, 0),
108 sunlightDirection,
109 sunlightDiffuse
110 );
111
112 case ShaderType::SPECULAR_MAPPING:
113
114 return m_shaderManager->render_spec_map_shader(
115 m_deviceContext,
116 render->GetIndexCount(),
117 worldMatrix,
118 viewMatrix,
119 projectionMatrix,
120 render->GetTexture(TextureType::Diffuse, 0),
121 render->GetTexture(TextureType::Normal, 0),
122 render->GetTexture(TextureType::Specular, 0),
123 sunlightDirection,
124 sunlightDiffuse,
125 cameraPosition,
126 sunlightDiffuse, // Couleur speculaire (à ajuster)
127 16.0f // Puissance speculaire (à ajuster)
128 );
129
130 case ShaderType::LIGHTING:
131 {
132 // Créer des copies locales non constantes des tableaux
133 DirectX::XMFLOAT4 localDiffuseColors[4];
134 DirectX::XMFLOAT4 localLightPositions[4];
135 DirectX::XMFLOAT4 localAmbientColors[4];
136
137 // Copier les données
138 for (int i = 0; i < 4; i++) {
139 localDiffuseColors[i] = diffuseColors[i];
140 localLightPositions[i] = lightPositions[i];
141 localAmbientColors[i] = ambientColors[i];
142 }
143
144 return m_shaderManager->renderlight_shader(
145 m_deviceContext,
146 render->GetIndexCount(),
147 worldMatrix,
148 viewMatrix,
149 projectionMatrix,
150 render->GetTexture(TextureType::Diffuse, 0),
151 localDiffuseColors,
152 localLightPositions,
153 localAmbientColors
154 );
155 }
156
157 case ShaderType::SUNLIGHT:
158 return m_shaderManager->render_sunlight_shader(
159 m_deviceContext,
160 render->GetIndexCount(),
161 worldMatrix,
162 viewMatrix,
163 projectionMatrix,
164 render->GetTexture(TextureType::Diffuse, 0),
165 sunlightDiffuse,
166 sunlightAmbient,
167 sunlightDirection,
168 sunlightIntensity
169 );
170
171 case ShaderType::SKYBOX:
172 return m_shaderManager->render_skybox_shader(
173 m_deviceContext,
174 render->GetIndexCount(),
175 worldMatrix,
176 viewMatrix,
177 projectionMatrix,
178 render->GetTexture(TextureType::Diffuse, 0),
179 sunlightDiffuse,
180 sunlightAmbient,
181 sunlightDirection,
182 sunlightIntensity
183 );
184
185 case ShaderType::TEXTURE:
186 default:
187 return m_shaderManager->render_texture_shader(
188 m_deviceContext,
189 render->GetIndexCount(),
190 worldMatrix,
191 viewMatrix,
192 projectionMatrix,
193 render->GetTexture(TextureType::Diffuse, 0)
194 );
195 }
196 }

The documentation for this class was generated from the following file: