2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "RAS_MaterialBucket.h"
|
|
|
|
|
2002-11-25 15:29:57 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#pragma warning (disable:4786)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif // WIN32
|
|
|
|
|
|
|
|
#include "RAS_Polygon.h"
|
|
|
|
#include "RAS_TexVert.h"
|
|
|
|
#include "RAS_IRasterizer.h"
|
|
|
|
#include "RAS_IRenderTools.h"
|
|
|
|
#include "RAS_MeshObject.h"
|
|
|
|
#include "RAS_Deformer.h" // __NLA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KX_VertexIndex::KX_VertexIndex(int size)
|
|
|
|
{
|
|
|
|
m_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-17 05:23:17 +00:00
|
|
|
void KX_VertexIndex::SetIndex(short loc,unsigned int index)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
m_indexarray[loc]=index;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KX_MeshSlot::Less(const KX_MeshSlot& lhs) const
|
|
|
|
{
|
|
|
|
bool result = ((m_mesh < lhs.m_mesh ) ||
|
|
|
|
((m_mesh == lhs.m_mesh)&&(m_OpenGLMatrix < lhs.m_OpenGLMatrix)));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-03-09 22:02:32 +00:00
|
|
|
KX_MeshSlot::~KX_MeshSlot()
|
|
|
|
{
|
|
|
|
if (m_DisplayList)
|
|
|
|
m_DisplayList->Release();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
RAS_MaterialBucket::RAS_MaterialBucket(RAS_IPolyMaterial* mat)
|
|
|
|
:m_bModified(true)
|
|
|
|
{
|
|
|
|
m_bScheduled=true;
|
|
|
|
m_material = mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::SchedulePolygons(int drawingmode)
|
|
|
|
{
|
|
|
|
m_bScheduled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::ClearScheduledPolygons()
|
|
|
|
{
|
|
|
|
m_bScheduled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-05-04 09:34:02 +00:00
|
|
|
RAS_IPolyMaterial* RAS_MaterialBucket::GetPolyMaterial() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
return m_material;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::SetMeshSlot(KX_MeshSlot& ms)
|
|
|
|
{
|
|
|
|
m_meshSlots.insert(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::RemoveMeshSlot(KX_MeshSlot& ms)
|
|
|
|
{
|
|
|
|
T_MeshSlotList::iterator it = m_meshSlots.find(ms);
|
|
|
|
|
|
|
|
if (!(it == m_meshSlots.end()))
|
|
|
|
m_meshSlots.erase(it);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::MarkVisibleMeshSlot(KX_MeshSlot& ms,
|
|
|
|
bool visible,
|
|
|
|
bool color,
|
|
|
|
const MT_Vector4& rgbavec)
|
|
|
|
{
|
|
|
|
T_MeshSlotList::iterator it = m_meshSlots.find(ms);
|
|
|
|
|
|
|
|
assert (!(it == m_meshSlots.end()));
|
|
|
|
(*it).m_bVisible = visible;
|
|
|
|
(*it).m_bObjectColor = color;
|
|
|
|
(*it).m_RGBAcolor= rgbavec;
|
|
|
|
}
|
|
|
|
|
2004-05-04 09:34:02 +00:00
|
|
|
bool RAS_MaterialBucket::IsTransparant() const
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
return (m_material->IsTransparant());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::StartFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::EndFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-05-21 08:55:12 +00:00
|
|
|
unsigned int RAS_MaterialBucket::NumMeshSlots()
|
|
|
|
{
|
|
|
|
return m_meshSlots.size();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-05-21 08:55:12 +00:00
|
|
|
RAS_MaterialBucket::T_MeshSlotList::iterator RAS_MaterialBucket::msBegin()
|
|
|
|
{
|
|
|
|
return m_meshSlots.begin();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-05-21 08:55:12 +00:00
|
|
|
RAS_MaterialBucket::T_MeshSlotList::iterator RAS_MaterialBucket::msEnd()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-05-21 08:55:12 +00:00
|
|
|
return m_meshSlots.end();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-01-16 06:02:06 +00:00
|
|
|
bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
|
|
|
|
RAS_IRenderTools *rendertools, int &drawmode)
|
2004-05-21 08:55:12 +00:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
rendertools->SetViewMat(cameratrans);
|
|
|
|
|
2005-01-16 06:02:06 +00:00
|
|
|
if (!rasty->SetMaterial(*m_material))
|
|
|
|
return false;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-01-06 03:46:54 +00:00
|
|
|
bool dolights = false;
|
|
|
|
const unsigned int flag = m_material->GetFlag();
|
|
|
|
|
2006-02-13 05:45:32 +00:00
|
|
|
|
2006-01-06 03:46:54 +00:00
|
|
|
if( flag & RAS_BLENDERMAT)
|
2006-02-13 05:45:32 +00:00
|
|
|
dolights = (flag &RAS_MULTILIGHT)!=0;
|
2006-01-06 03:46:54 +00:00
|
|
|
else
|
2006-02-13 05:45:32 +00:00
|
|
|
dolights = (m_material->GetDrawingMode()&16)!=0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2007-05-20 15:55:49 +00:00
|
|
|
if ((rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID) || !dolights)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2005-04-23 11:54:21 +00:00
|
|
|
rendertools->ProcessLighting(-1);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-30 19:58:44 +00:00
|
|
|
rendertools->ProcessLighting(RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER/*m_material->GetLightLayer()*/);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2005-01-16 06:02:06 +00:00
|
|
|
drawmode = (rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID ?
|
2002-10-12 11:37:38 +00:00
|
|
|
1: (m_material->UsesTriangles() ? 0 : 2));
|
2005-01-16 06:02:06 +00:00
|
|
|
|
|
|
|
return true;
|
2004-05-21 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty,
|
|
|
|
RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, int drawmode)
|
|
|
|
{
|
|
|
|
if (!ms.m_bVisible)
|
|
|
|
return;
|
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
m_material->ActivateMeshSlot(ms, rasty);
|
2004-05-21 08:55:12 +00:00
|
|
|
|
|
|
|
/* __NLA Do the deformation */
|
|
|
|
if (ms.m_pDeformer)
|
2004-11-22 11:49:35 +00:00
|
|
|
{
|
2004-05-21 08:55:12 +00:00
|
|
|
ms.m_pDeformer->Apply(m_material);
|
2004-11-22 11:49:35 +00:00
|
|
|
// KX_ReInstanceShapeFromMesh(ms.m_mesh); // Recompute the physics mesh. (Can't call KX_* from RAS_)
|
|
|
|
}
|
2004-05-21 08:55:12 +00:00
|
|
|
/* End __NLA */
|
2004-11-22 11:49:35 +00:00
|
|
|
|
|
|
|
if (rasty->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID)
|
|
|
|
ms.m_mesh->SortPolygons(cameratrans*MT_Transform(ms.m_OpenGLMatrix));
|
2004-05-21 08:55:12 +00:00
|
|
|
|
|
|
|
rendertools->PushMatrix();
|
|
|
|
rendertools->applyTransform(rasty,ms.m_OpenGLMatrix,m_material->GetDrawingMode());
|
|
|
|
|
2006-04-02 21:04:20 +00:00
|
|
|
if(rasty->QueryLists())
|
|
|
|
{
|
|
|
|
if(ms.m_DisplayList)
|
|
|
|
ms.m_DisplayList->SetModified(ms.m_mesh->MeshModified());
|
|
|
|
}
|
|
|
|
|
2004-05-21 08:55:12 +00:00
|
|
|
// Use the text-specific IndexPrimitives for text faces
|
|
|
|
if (m_material->GetDrawingMode() & RAS_IRasterizer::RAS_RENDER_3DPOLYGON_TEXT)
|
|
|
|
{
|
|
|
|
rasty->IndexPrimitives_3DText(
|
|
|
|
ms.m_mesh->GetVertexCache(m_material),
|
|
|
|
ms.m_mesh->GetIndexCache(m_material),
|
|
|
|
drawmode,
|
|
|
|
m_material,
|
|
|
|
rendertools, // needed for textprinting on polys
|
|
|
|
ms.m_bObjectColor,
|
|
|
|
ms.m_RGBAcolor);
|
|
|
|
|
|
|
|
}
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
// for using glMultiTexCoord
|
|
|
|
else if(m_material->GetFlag() & RAS_MULTITEX )
|
|
|
|
{
|
|
|
|
rasty->IndexPrimitivesMulti(
|
|
|
|
ms.m_mesh->GetVertexCache(m_material),
|
|
|
|
ms.m_mesh->GetIndexCache(m_material),
|
|
|
|
drawmode,
|
|
|
|
m_material,
|
|
|
|
rendertools,
|
|
|
|
ms.m_bObjectColor,
|
2006-04-02 21:04:20 +00:00
|
|
|
ms.m_RGBAcolor,
|
|
|
|
&ms.m_DisplayList
|
2006-01-06 03:46:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// for using glMultiTexCoord on deformer
|
|
|
|
else if(m_material->GetFlag() & RAS_DEFMULTI )
|
|
|
|
{
|
2006-04-02 21:04:20 +00:00
|
|
|
rasty->IndexPrimitivesMulti_Ex(
|
2006-01-06 03:46:54 +00:00
|
|
|
ms.m_mesh->GetVertexCache(m_material),
|
|
|
|
ms.m_mesh->GetIndexCache(m_material),
|
|
|
|
drawmode,
|
|
|
|
m_material,
|
|
|
|
rendertools,
|
|
|
|
ms.m_bObjectColor,
|
|
|
|
ms.m_RGBAcolor
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-05-21 08:55:12 +00:00
|
|
|
// Use the (slower) IndexPrimitives_Ex which can recalc face normals & such
|
|
|
|
// for deformed objects - eventually should be extended to recalc ALL normals
|
|
|
|
else if (ms.m_pDeformer){
|
|
|
|
rasty->IndexPrimitives_Ex(
|
|
|
|
ms.m_mesh->GetVertexCache(m_material),
|
|
|
|
ms.m_mesh->GetIndexCache(m_material),
|
|
|
|
drawmode,
|
|
|
|
m_material,
|
|
|
|
rendertools, // needed for textprinting on polys
|
|
|
|
ms.m_bObjectColor,
|
|
|
|
ms.m_RGBAcolor
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Use the normal IndexPrimitives
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rasty->IndexPrimitives(
|
|
|
|
ms.m_mesh->GetVertexCache(m_material),
|
|
|
|
ms.m_mesh->GetIndexCache(m_material),
|
|
|
|
drawmode,
|
|
|
|
m_material,
|
|
|
|
rendertools, // needed for textprinting on polys
|
|
|
|
ms.m_bObjectColor,
|
2006-04-02 21:04:20 +00:00
|
|
|
ms.m_RGBAcolor,
|
|
|
|
&ms.m_DisplayList
|
2004-05-21 08:55:12 +00:00
|
|
|
);
|
|
|
|
}
|
2006-04-02 21:04:20 +00:00
|
|
|
|
|
|
|
if(rasty->QueryLists()) {
|
|
|
|
if(ms.m_DisplayList)
|
|
|
|
ms.m_mesh->SetMeshModified(false);
|
|
|
|
}
|
|
|
|
|
2004-05-21 08:55:12 +00:00
|
|
|
rendertools->PopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RAS_MaterialBucket::Render(const MT_Transform& cameratrans,
|
|
|
|
RAS_IRasterizer* rasty,
|
|
|
|
RAS_IRenderTools* rendertools)
|
|
|
|
{
|
|
|
|
if (m_meshSlots.begin()== m_meshSlots.end())
|
|
|
|
return;
|
|
|
|
|
2004-06-04 03:00:13 +00:00
|
|
|
//rendertools->SetViewMat(cameratrans);
|
2004-05-21 08:55:12 +00:00
|
|
|
|
2004-06-04 03:00:13 +00:00
|
|
|
//rasty->SetMaterial(*m_material);
|
2004-05-21 08:55:12 +00:00
|
|
|
|
|
|
|
|
2005-01-16 06:02:06 +00:00
|
|
|
int drawmode;
|
2002-10-12 11:37:38 +00:00
|
|
|
for (T_MeshSlotList::const_iterator it = m_meshSlots.begin();
|
2004-05-21 08:55:12 +00:00
|
|
|
! (it == m_meshSlots.end()); ++it)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-04-30 19:58:44 +00:00
|
|
|
rendertools->SetClientObject((*it).m_clientObj);
|
2005-01-16 06:02:06 +00:00
|
|
|
while (ActivateMaterial(cameratrans, rasty, rendertools, drawmode))
|
|
|
|
RenderMeshSlot(cameratrans, rasty, rendertools, *it, drawmode);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-05-25 14:37:39 +00:00
|
|
|
// to reset the eventual GL_CW mode
|
|
|
|
rendertools->SetClientObject(NULL);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|