-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPBGE: Render text objects as mesh objects.
Previously all text objects was rendered at the frame render end. It caused that as text objects use transparency, they were all on top of all other transparent regular meshes which are not writing to the depth buffer. To solve this issue the text objects should be rendered like the other regular meshes and enjoy the ordering made for transparency objects. But this would assume that text objects are meshes which is not really the case as they don't use any materials. To first considerate the text objects as meshes they need a material. This material is particular as it doesn't bind any shader. It exists only to say that meshes using it are texts. This material must be global to the game engine to make sure that we use as much as possible a common RAS_DisplayArrayBucket and RAS_MaterialBucket. The material is then a subclass of RAS_IPolyMaterial named KX_TextMaterial which contains mostly empty functions, only it's constructor enable material text flags. An instance of this material is stored statically in KX_TextMaterial.cpp and get its pointer with GetTextMaterial from KX_TextMaterial.h. RAS_IPolyMaterial contains a new function IsText which returns true for KX_TextMaterial depending of a text flag. This function is used when creating the material bucket to add the material bucket in a specific list accessed with m_buckets[TEXT_BUCKET]. The function is used again when rendering to call IndexPrimitivesText with the mesh user. As texts objects doesn't have any RAS_MeshObject and RAS_DisplayArray, then the RAS_DisplayArrayBucket must check if the m_mesh is non NULL before for example get if it is modified. Also m_mesh is used to differ a modifier display array bucket than a text display array bucket in FindDisplayArrayBucket as the both have a NULL display array. As KX_FontObject inherit of KX_GameObject, we just have to make virtual functions managing mesh user and mesh slots (AddMeshUser, UpdateBuckets). The override of AddMeshUser just find or create the material bucket with the global KX_TextMaterial. UpdateBuckets updates all data needed to render the texts in the RAS_TextUser. The RAS_TextUser is a subclass of RAS_MeshUser containing extra data used to render the texts: - dpi - size - aspect - resolution - fontid - offset - spacing - texts[] In IndexPrimitivesText we loop on all text contained in RAS_TextUser::m_texts, translate text matrix and call RenderText3D with all other values contained in RAS_TextUser. Two bugs are fixed with this patch coresponding to issues #119 and #114. #119 is about unordered transparency and #114 is for text rendered even if they are inactive because the scene render all object in the list of texts which is wrong as some of them can be inactive. This is fixed by the fact that only active objects update theirs mesh user and add theirs mesh slot to be rendered. This patch allow for the moment to draw text objects as meshes with an empty material, but later if a way is found to render texts with original material, the rest will be already done.
- Loading branch information
1 parent
366017f
commit 7038db2
Showing
26 changed files
with
521 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* ***** BEGIN GPL LICENSE BLOCK ***** | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Contributor(s): Tristan Porteries. | ||
* | ||
* ***** END GPL LICENSE BLOCK ***** | ||
*/ | ||
|
||
/** \file gameengine/Ketsji/KX_TextMaterial.cpp | ||
* \ingroup ketsji | ||
*/ | ||
|
||
#include "KX_TextMaterial.h" | ||
|
||
#include "DNA_material_types.h" | ||
|
||
static KX_TextMaterial textMaterial = KX_TextMaterial(); | ||
|
||
KX_TextMaterial *GetTextMaterial() | ||
{ | ||
return &textMaterial; | ||
} | ||
|
||
KX_TextMaterial::KX_TextMaterial() | ||
:RAS_IPolyMaterial("__TextMaterial__", NULL) | ||
{ | ||
m_rasMode |= (RAS_ALPHA | RAS_TEXT); | ||
m_flag |= RAS_BLENDERGLSL; | ||
m_alphablend = GEMAT_ALPHA; | ||
} | ||
|
||
KX_TextMaterial::~KX_TextMaterial() | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::Activate(RAS_IRasterizer *rasty) | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::Desactivate(RAS_IRasterizer *rasty) | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::ActivateInstancing(RAS_IRasterizer *rasty, void *matrixoffset, void *positionoffset, void *coloroffset, unsigned int stride) | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::DesactivateInstancing() | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::ActivateMeshSlot(RAS_MeshSlot *ms, RAS_IRasterizer *rasty) | ||
{ | ||
} | ||
|
||
const STR_String& KX_TextMaterial::GetTextureName() const | ||
{ | ||
static STR_String empty = ""; | ||
return empty; | ||
} | ||
|
||
Material *KX_TextMaterial::GetBlenderMaterial() const | ||
{ | ||
return NULL; | ||
} | ||
|
||
Image *KX_TextMaterial::GetBlenderImage() const | ||
{ | ||
return NULL; | ||
} | ||
|
||
MTexPoly *KX_TextMaterial::GetMTexPoly() const | ||
{ | ||
return NULL; | ||
} | ||
|
||
Scene *KX_TextMaterial::GetBlenderScene() const | ||
{ | ||
return NULL; | ||
} | ||
|
||
bool KX_TextMaterial::UseInstancing() const | ||
{ | ||
return false; | ||
} | ||
|
||
void KX_TextMaterial::ReleaseMaterial() | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::UpdateIPO(MT_Vector4 rgba, MT_Vector3 specrgb, MT_Scalar hard, MT_Scalar spec, MT_Scalar ref, | ||
MT_Scalar emit, MT_Scalar ambient, MT_Scalar alpha, MT_Scalar specalpha) | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::Replace_IScene(SCA_IScene *val) | ||
{ | ||
} | ||
|
||
void KX_TextMaterial::OnConstruction() | ||
{ | ||
} |
Oops, something went wrong.