# Khaotic Engine Reborn: ecs::RenderSystem Class Reference

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.

: 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

  entityManager | The EntityManager containing the entities to render.
  viewMatrix | The view matrix for rendering.
  projectionMatrix | The projection matrix for rendering.
  diffuseColors | Array of diffuse colors for lighting.
  lightPositions | Array of light positions for lighting.
  ambientColors | Array of ambient colors for lighting.
  cameraPos | The position of the camera in world space.
  sunlightDiffuse | The diffuse color of sunlight.
  sunlightAmbient | The ambient color of sunlight.
  sunlightDirection | The direction of sunlight in world space.
  sunlightIntensity | The intensity of sunlight.

Returns
  The number of entities rendered successfully.

Definition at line 214 of file render_system.h.

{
int renderCount = 0;
// Récupérer toutes les entités qui ont les composants RenderComponent et TransformComponent
auto entities = entityManager->GetEntitiesWithComponent<RenderComponent>();
for (auto& entity : entities) {
auto render = entity->GetComponent<RenderComponent>();
// Vérifier si l'entité a un TransformComponent
auto transform = entity->GetComponent<TransformComponent>();
if (!transform) continue;
// Vérifier si le modèle est visible
if (!render->IsVisible()) continue;
// Effectuer le rendu
if (RenderEntity(entity, viewMatrix, projectionMatrix,
diffuseColors, lightPositions, ambientColors,cameraPos,
sunlightDiffuse, sunlightAmbient, sunlightDirection,
sunlightIntensity)) {
renderCount++;
}
}
return renderCount;
}
ecs::RenderSystem::RenderEntity
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)
Definition render_system.h:38

## 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

  entity | The entity to render.
  viewMatrix | The view matrix for rendering.
  projectionMatrix | The projection matrix for rendering.
  diffuseColors | Array of diffuse colors for lighting.
  lightPositions | Array of light positions for lighting.
  ambientColors | Array of ambient colors for lighting.
  cameraPosition | The position of the camera in world space.
  sunlightDiffuse | The diffuse color of sunlight.
  sunlightAmbient | The ambient color of sunlight.
  sunlightDirection | The direction of sunlight in world space.
  sunlightIntensity | The intensity of sunlight.

Returns
  True if rendering was successful, false otherwise.

Definition at line 38 of file render_system.h.

{
// Vérifier si l'entité a tous les composants nécessaires
auto transform = entity->GetComponent<TransformComponent>();
auto render = entity->GetComponent<RenderComponent>();
auto shader = entity->GetComponent<ShaderComponent>();
if (!transform || !render || !shader || !render->GetModel())
return false;
// Calculer la matrice monde
XMMATRIX scaleMatrix = transform->GetScaleMatrix();
XMMATRIX rotateMatrix = transform->GetRotateMatrix();
XMMATRIX translateMatrix = transform->GetTranslateMatrix();
XMMATRIX worldMatrix = XMMatrixMultiply(
XMMatrixMultiply(scaleMatrix, rotateMatrix),
translateMatrix
);
// Rendre le modèle
render->Render(m_deviceContext);
// Sélectionner le shader approprié
switch (shader->GetActiveShader()) {
case ShaderType::ALPHA_MAPPING:
return m_shaderManager->render_alpha_map_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0),
render->GetTexture(TextureType::Diffuse, 1),
render->GetTexture(TextureType::Alpha, 0)
);
case ShaderType::CEL_SHADING:
return m_shaderManager->render_cel_shading_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0),
sunlightDiffuse,
sunlightAmbient,
sunlightDirection,
sunlightIntensity
);
case ShaderType::NORMAL_MAPPING:
return m_shaderManager->render_normal_map_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0),
render->GetTexture(TextureType::Normal, 0),
sunlightDirection,
sunlightDiffuse
);
case ShaderType::SPECULAR_MAPPING:
return m_shaderManager->render_spec_map_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0),
render->GetTexture(TextureType::Normal, 0),
render->GetTexture(TextureType::Specular, 0),
sunlightDirection,
sunlightDiffuse,
cameraPosition,
sunlightDiffuse, // Couleur speculaire (à ajuster)
16.0f // Puissance speculaire (à ajuster)
);
case ShaderType::LIGHTING:
{
// Créer des copies locales non constantes des tableaux
DirectX::XMFLOAT4 localDiffuseColors[4];
DirectX::XMFLOAT4 localLightPositions[4];
DirectX::XMFLOAT4 localAmbientColors[4];
// Copier les données
for (int i = 0; i < 4; i++) {
localDiffuseColors[i] = diffuseColors[i];
localLightPositions[i] = lightPositions[i];
localAmbientColors[i] = ambientColors[i];
}
return m_shaderManager->renderlight_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0),
localDiffuseColors,
localLightPositions,
localAmbientColors
);
}
case ShaderType::SUNLIGHT:
return m_shaderManager->render_sunlight_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0),
sunlightDiffuse,
sunlightAmbient,
sunlightDirection,
sunlightIntensity
);
case ShaderType::SKYBOX:
return m_shaderManager->render_skybox_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0),
sunlightDiffuse,
sunlightAmbient,
sunlightDirection,
sunlightIntensity
);
case ShaderType::TEXTURE:
default:
return m_shaderManager->render_texture_shader(
m_deviceContext,
render->GetIndexCount(),
worldMatrix,
viewMatrix,
projectionMatrix,
render->GetTexture(TextureType::Diffuse, 0)
);
}
}

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

- enginecustom/src/inc/system/ecs/systems/render_system.h