From 0a324d9323ba7bbae89d108ee79d7e92ea8930d3 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 1 Feb 2015 21:39:47 +0100 Subject: [PATCH] Added some comments (as requested) Former-commit-id: 4a6c7a025625ab49e59aaffa818cb50374e778d7 --- src/Nazara/Graphics/TextSprite.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Nazara/Graphics/TextSprite.cpp b/src/Nazara/Graphics/TextSprite.cpp index 9361aabc4..465be492c 100644 --- a/src/Nazara/Graphics/TextSprite.cpp +++ b/src/Nazara/Graphics/TextSprite.cpp @@ -183,7 +183,7 @@ void NzTextSprite::Update(const NzAbstractTextDrawer& drawer) indices.first = index; index += indices.count; - indices.count = 0; // On réinitialise count à zéro (on va s'en servir pour compteur dans la boucle suivante) + indices.count = 0; // On réinitialise count à zéro (on va s'en servir comme compteur dans la boucle suivante) } NzSparsePtr texCoordPtr(&m_vertices[0].uv, sizeof(NzVertexStruct_XYZ_Color_UV)); @@ -240,7 +240,7 @@ void NzTextSprite::Update(const NzAbstractTextDrawer& drawer) *texCoord++ = uvRect.GetCorner(nzRectCorner_RightTop); } - // Et on passe au prochain + // Et on passe au prochain sommet indices->count++; } @@ -327,6 +327,9 @@ bool NzTextSprite::OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractIm } #endif + // La texture d'un atlas vient d'être recréée (changement de taille) + // nous devons ajuster les coordonnées de textures et la texture du rendu + NzTexture* oldTexture = static_cast(oldLayer); NzTexture* newTexture = static_cast(newLayer); @@ -338,8 +341,9 @@ bool NzTextSprite::OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractIm NzVector2ui oldSize(oldTexture->GetSize()); NzVector2ui newSize(newTexture->GetSize()); - NzVector2f scale = NzVector2f(oldSize)/NzVector2f(newSize); + NzVector2f scale = NzVector2f(oldSize)/NzVector2f(newSize); // ratio ancienne et nouvelle taille + // On va maintenant parcourir toutes les coordonnées de texture pour les multiplier par ce ratio NzSparsePtr texCoordPtr(&m_vertices[indices.first].uv, sizeof(NzVertexStruct_XYZ_Color_UV)); for (unsigned int i = 0; i < indices.count; ++i) { @@ -367,6 +371,7 @@ void NzTextSprite::OnAtlasReleased(const NzAbstractAtlas* atlas, void* userdata) } #endif + // L'atlas a été libéré alors que le TextSprite l'utilisait encore, notre seule option (pour éviter un crash) est de nous réinitialiser NazaraWarning("TextSprite " + NzString::Pointer(this) + " has been cleared because atlas " + NzString::Pointer(atlas) + " that was under use has been released"); Clear(); } @@ -386,12 +391,15 @@ void NzTextSprite::UpdateVertices() const if (!m_transformMatrixUpdated) UpdateTransformMatrix(); + // On récupère le repère de la scène NzVector3f down = (m_scene) ? m_scene->GetDown() : NzVector3f::Down(); NzVector3f right = (m_scene) ? m_scene->GetRight() : NzVector3f::Right(); NzSparsePtr colorPtr(&m_vertices[0].color, sizeof(NzVertexStruct_XYZ_Color_UV)); NzSparsePtr posPtr(&m_vertices[0].position, sizeof(NzVertexStruct_XYZ_Color_UV)); + // Nous allons maintenant initialiser les sommets finaux (ceux envoyés à la RenderQueue) + // à l'aide du repère, de la matrice et de notre attribut de couleur for (auto& pair : m_renderInfos) { RenderIndices& indices = pair.second;