BGE modifier: last minute commit to fix a nasty bug with modifers messing the alpha blend mode of the GE. Note the alpha sorting on modified mesh is not implemented so derived mesh should not have alpha faces (clip will work though). Incidently fixed a performance problem in GLSL where the derived mesh was possibly rendered multiple times. Modifier support is still a bit experimental and should not be used in production game.
This commit is contained in:
@@ -460,17 +460,16 @@ void KX_GameObject::AddMeshUser()
|
||||
{
|
||||
for (size_t i=0;i<m_meshes.size();i++)
|
||||
{
|
||||
m_meshes[i]->AddMeshUser(this, &m_meshSlots);
|
||||
m_meshes[i]->AddMeshUser(this, &m_meshSlots, GetDeformer());
|
||||
}
|
||||
// set the part of the mesh slot that never change
|
||||
double* fl = GetOpenGLMatrixPtr()->getPointer();
|
||||
RAS_Deformer *deformer = GetDeformer();
|
||||
|
||||
SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
|
||||
RAS_MeshSlot* ms;
|
||||
for(mit.begin(); !mit.end(); ++mit)
|
||||
{
|
||||
(*mit)->m_OpenGLMatrix = fl;
|
||||
(*mit)->SetDeformer(deformer);
|
||||
}
|
||||
UpdateBuckets(false);
|
||||
}
|
||||
|
||||
@@ -382,15 +382,39 @@ RAS_TexVert* RAS_MeshObject::GetVertex(unsigned int matid,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void RAS_MeshObject::AddMeshUser(void *clientobj, SG_QList *head)
|
||||
void RAS_MeshObject::AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer)
|
||||
{
|
||||
list<RAS_MeshMaterial>::iterator it;
|
||||
list<RAS_MeshMaterial>::iterator mit;
|
||||
|
||||
for(it = m_materials.begin();it!=m_materials.end();++it) {
|
||||
/* always copy from the base slot, which is never removed
|
||||
* since new objects can be created with the same mesh data */
|
||||
if (deformer && !deformer->UseVertexArray())
|
||||
{
|
||||
// HACK!
|
||||
// this deformer doesn't use vertex array => derive mesh
|
||||
// we must keep only the mesh slots that have unique material id
|
||||
// this is to match the derived mesh drawing function
|
||||
// Need a better solution in the future: scan the derive mesh and create vertex array
|
||||
RAS_IPolyMaterial* curmat = it->m_bucket->GetPolyMaterial();
|
||||
if (curmat->GetFlag() & RAS_BLENDERGLSL)
|
||||
{
|
||||
for(mit = m_materials.begin(); mit != it; ++mit)
|
||||
{
|
||||
RAS_IPolyMaterial* mat = mit->m_bucket->GetPolyMaterial();
|
||||
if ((mat->GetFlag() & RAS_BLENDERGLSL) &&
|
||||
mat->GetMaterialIndex() == curmat->GetMaterialIndex())
|
||||
// no need to convert current mesh slot
|
||||
break;
|
||||
}
|
||||
if (mit != it)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
RAS_MeshSlot *ms = it->m_bucket->CopyMesh(it->m_baseslot);
|
||||
ms->m_clientObj = clientobj;
|
||||
ms->SetDeformer(deformer);
|
||||
it->m_slots.insert(clientobj, ms);
|
||||
head->QAddBack(ms);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "GEN_HashedPtr.h"
|
||||
|
||||
struct Mesh;
|
||||
class RAS_Deformer;
|
||||
|
||||
/* RAS_MeshObject is a mesh used for rendering. It stores polygons,
|
||||
* but the actual vertices and index arrays are stored in material
|
||||
@@ -130,7 +131,7 @@ public:
|
||||
RAS_Polygon* GetPolygon(int num) const;
|
||||
|
||||
/* buckets */
|
||||
virtual void AddMeshUser(void *clientobj, SG_QList *head);
|
||||
virtual void AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer);
|
||||
virtual void UpdateBuckets(
|
||||
void* clientobj,
|
||||
double* oglmatrix,
|
||||
|
||||
@@ -81,7 +81,7 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
|
||||
m_motionblurvalue(-1.0),
|
||||
m_texco_num(0),
|
||||
m_attrib_num(0),
|
||||
m_last_blendmode(GPU_BLEND_SOLID),
|
||||
//m_last_blendmode(GPU_BLEND_SOLID),
|
||||
m_last_frontface(true),
|
||||
m_materialCachingInfo(0)
|
||||
{
|
||||
@@ -118,7 +118,8 @@ bool RAS_OpenGLRasterizer::Init()
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
m_last_blendmode = GPU_BLEND_SOLID;
|
||||
//m_last_blendmode = GPU_BLEND_SOLID;
|
||||
GPU_set_material_blend_mode(GPU_BLEND_SOLID);
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
m_last_frontface = true;
|
||||
@@ -288,7 +289,8 @@ bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time)
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
m_last_blendmode = GPU_BLEND_SOLID;
|
||||
//m_last_blendmode = GPU_BLEND_SOLID;
|
||||
GPU_set_material_blend_mode(GPU_BLEND_SOLID);
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
m_last_frontface = true;
|
||||
@@ -787,7 +789,10 @@ void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi)
|
||||
GPU_material_vertex_attributes(GPU_material_from_blender(blscene, blmat), ¤t_gpu_attribs);
|
||||
else
|
||||
memset(¤t_gpu_attribs, 0, sizeof(current_gpu_attribs));
|
||||
// DM draw can mess up blending mode, restore at the end
|
||||
int current_blend_mode = GPU_get_material_blend_mode();
|
||||
ms.m_pDerivedMesh->drawFacesGLSL(ms.m_pDerivedMesh, CheckMaterialDM);
|
||||
GPU_set_material_blend_mode(current_blend_mode);
|
||||
} else {
|
||||
ms.m_pDerivedMesh->drawMappedFacesTex(ms.m_pDerivedMesh, CheckTexfaceDM, mcol);
|
||||
}
|
||||
@@ -1096,6 +1101,8 @@ void RAS_OpenGLRasterizer::DisableMotionBlur()
|
||||
|
||||
void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode)
|
||||
{
|
||||
GPU_set_material_blend_mode(blendmode);
|
||||
/*
|
||||
if(blendmode == m_last_blendmode)
|
||||
return;
|
||||
|
||||
@@ -1122,6 +1129,7 @@ void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode)
|
||||
}
|
||||
|
||||
m_last_blendmode = blendmode;
|
||||
*/
|
||||
}
|
||||
|
||||
void RAS_OpenGLRasterizer::SetFrontFace(bool ccw)
|
||||
|
||||
@@ -100,7 +100,7 @@ protected:
|
||||
TexCoGen m_attrib[RAS_MAX_ATTRIB];
|
||||
int m_texco_num;
|
||||
int m_attrib_num;
|
||||
int m_last_blendmode;
|
||||
//int m_last_blendmode;
|
||||
bool m_last_frontface;
|
||||
|
||||
/** Stores the caching information for the last material activated. */
|
||||
|
||||
Reference in New Issue
Block a user