author Erwin Coumans Tue, 11 Apr 2006 05:57:30 +0000 (05:57 +0000) committer Erwin Coumans Tue, 11 Apr 2006 05:57:30 +0000 (05:57 +0000)
14 files changed:

index 23b92c637923fbb7af4ec7ecfde11087bc26a534..15ff6c788fe6fa38cfaa1ef81e5c27a8c2166e23 100644 (file)
@@ -97,25 +97,27 @@ bool MinkowskiPenetrationDepthSolver::CalcPenDepth(SimplexSolverInterface& simpl
)
{

-
//just take fixed number of orientation, and sample the penetration depth in that direction
float minProj = 1e30f;
SimdVector3 minNorm;
SimdVector3 minVertex;
SimdVector3 minA,minB;
+       SimdVector3 seperatingAxisInA,seperatingAxisInB;
+       SimdVector3 pInA,qInB,pWorld,qWorld,w;
+
for (int i=0;i<NUM_UNITSPHERE_POINTS;i++)
{
const SimdVector3& norm = sPenetrationDirections[i];

-               SimdVector3 seperatingAxisInA = (-norm)* transA.getBasis();
-               SimdVector3 seperatingAxisInB = norm* transB.getBasis();
+               seperatingAxisInA = (-norm)* transA.getBasis();
+               seperatingAxisInB = norm* transB.getBasis();

-               SimdVector3 pInA = convexA->LocalGetSupportingVertex(seperatingAxisInA);
-               SimdVector3 qInB = convexB->LocalGetSupportingVertex(seperatingAxisInB);
-               SimdPoint3  pWorld = transA(pInA);
-               SimdPoint3  qWorld = transB(qInB);
+               pInA = convexA->LocalGetSupportingVertexWithoutMargin(seperatingAxisInA);
+               qInB = convexB->LocalGetSupportingVertexWithoutMargin(seperatingAxisInB);
+               pWorld = transA(pInA);
+               qWorld = transB(qInB);

-               SimdVector3 w   = qWorld - pWorld;
+               w       = qWorld - pWorld;
float delta = norm.dot(w);
//find smallest delta

@@ -128,6 +130,16 @@ bool MinkowskiPenetrationDepthSolver::CalcPenDepth(SimplexSolverInterface& simpl

}
}
+
+
+       minA += minNorm*convexA->GetMargin();
+       minB -= minNorm*convexB->GetMargin();
+       minProj += (convexA->GetMargin() + convexB->GetMargin());
+
+
+
+
//#define DEBUG_DRAW 1
#ifdef DEBUG_DRAW
if (debugDraw)
index 283120fe2f367068934f57d9d0a2fa3330ebac7a..408b909a62502c6fcdb40c4397210e21824a057d 100644 (file)
@@ -494,7 +494,17 @@ BL_Material* ConvertMaterial(  Mesh* mesh, Material *mat, TFace* tface,  MFace*
material->spec_f                = mat->spec;
material->ref                   = mat->ref;
material->amb                   = mat->amb;
-               material->ras_mode |= ((mat->mode & MA_ZTRA) != 0)?ZSORT:0;
+
+               // set alpha testing without z-sorting
+               if( ((mesh->tface && tface ) && (!tface->transp)) && mat->mode & MA_ZTRA) {
+                       // sets the RAS_IPolyMaterial::m_flag |RAS_FORCEALPHA
+                       // this is so we don't have the overhead of the z-sorting code
+                       material->ras_mode|=ALPHA_TEST;
+               }
+               else{
+                       // use regular z-sorting
+                       material->ras_mode |= ((mat->mode & MA_ZTRA) != 0)?ZSORT:0;
+               }
material->ras_mode |= ((mat->mode & MA_WIRE) != 0)?WIRE:0;
}
else {
index 27d59257cbdb6595b1c01a5f33fbf6be3e7d037c..dbf482e2db39b69a61386e80e07ef5b0a2b9ba12 100644 (file)
@@ -120,7 +120,8 @@ enum BL_flag
TEXALPHA=8,             // use alpha combiner functions
TEXNEG=16,              // negate blending
HASIPO=32,
-       USENEGALPHA=64
+       USENEGALPHA=64,
+       ALPHA_TEST=128
};

// BL_Material::ras_mode
//using namespace bgl;
#define spit(x) std::cout << x << std::endl;

-/* ----
-       testing for a faster solution!
-       ...  just compile out
-       The idea is to install a shader in other
-       areas if code, find the shader via the scene and,
-       install it with ...
-
-       ...
-*/
#define SORT_UNIFORMS 1
-
#define UNIFORM_MAX_LEN sizeof(float)*16

BL_Uniform::BL_Uniform(int data_size)
mPass(1),
mOk(0),
mUse(0),
+       mAttr(0),
vertProg(""),
fragProg(""),
mError(0),
mDirty(true)
{
// if !RAS_EXT_support._ARB_shader_objects this class will not be used
-       for (int i=0; i<MAXTEX; i++) {
-               mSampler[i] = BL_Sampler();
-       }
+       //for (int i=0; i<MAXTEX; i++) {
+       //      mSampler[i] = BL_Sampler();
+       //}
}

using namespace bgl;
@@ -159,12 +148,12 @@ using namespace bgl;
{
-       for (int i=0; i<MAXTEX; i++){
-               if(mSampler[i].mOwn) {
-                       if(mSampler[i].mTexture)
-                               mSampler[i].mTexture->DeleteTex();
-               }
-       }
+       //for (int i=0; i<MAXTEX; i++){
+       //      if(mSampler[i].mOwn) {
+       //              if(mSampler[i].mTexture)
+       //                      mSampler[i].mTexture->DeleteTex();
+       //      }
+       //}
ClearUniforms();

@@ -214,15 +203,6 @@ BL_Uniform  *BL_Shader::FindUniform(const int location)
void BL_Shader::SetUniformfv(int location, int type, float *param,int size, bool transpose)
{
#ifdef SORT_UNIFORMS
-#ifdef WIN32
-#ifndef NDEBUG
-       MT_assert(type > BL_Uniform::UNI_NONE && type < BL_Uniform::UNI_MAX);
-       MT_assert(location);
-       MT_assert(param);
-       //MT_assert(size > 0 && size <= UNIFORM_MAX_LEN);
-#endif
-#endif //WIN32
-
BL_Uniform *uni= FindUniform(location);
if(uni) {
memcpy(uni->getData(), param, size);
@@ -242,16 +222,6 @@ void BL_Shader::SetUniformfv(int location, int type, float *param,int size, bool
void BL_Shader::SetUniformiv(int location, int type, int *param,int size, bool transpose)
{
#ifdef SORT_UNIFORMS
-#ifdef WIN32
-#ifndef NDEBUG
-       //MT_assert(type > BL_Uniform::UNI_NONE && type < BL_Uniform::UNI_MAX);
-       MT_assert(location);
-       MT_assert(param);
-       //MT_assert(size > 0 && size <= UNIFORM_MAX_LEN);
-#endif
-#endif //WIN32
-
-
BL_Uniform *uni= FindUniform(location);
if(uni) {
memcpy(uni->getData(), param, size);
@@ -438,12 +408,12 @@ unsigned int BL_Shader::GetProg()
{
}
-
-{
-       MT_assert(i<=MAXTEX);
-       return &mSampler[i];
-}
+//
+//{
+//     MT_assert(i<=MAXTEX);
+//     return &mSampler[i];
+//}

{
@@ -457,14 +427,14 @@ void BL_Shader::SetSampler(int loc, int unit)
}
#endif
}
-
-{
-       MT_assert(unit<=MAXTEX);
-       mSampler[unit].mTexture = texture;
-       mSampler[unit].mLoc =-1;
-       mSampler[unit].mOwn = 0;
-}
+//
+//{
+//     MT_assert(unit<=MAXTEX);
+//     mSampler[unit].mTexture = texture;
+//     mSampler[unit].mLoc =-1;
+//     mSampler[unit].mOwn = 0;
+//}

{
@@ -504,7 +474,7 @@ void BL_Shader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty )
for(it = mPreDef.begin(); it!= mPreDef.end(); it++)
{
BL_DefUniform *uni = (*it);
-                       if(!uni->mLoc) continue;
+                       if(uni->mLoc == -1) continue;

switch (uni->mType)
{
@@ -826,8 +796,7 @@ PyMethodDef BL_Shader::Methods[] =
-// TODO: GL_ARB_vertex/fragment_program support

@@ -967,10 +936,18 @@ KX_PYMETHODDEF_DOC( BL_Shader, setSampler, "setSampler(name, index)" )
{
int loc = GetUniformLocation(uniform);
if(loc != -1) {
-                       if(index <= MAXTEX)
-                               mSampler[index].mLoc = loc;
-                       else
+                       if(index >= MAXTEX &&  index < 0)
spit("Invalid texture sample index: " << index);
+
+#ifdef SORT_UNIFORMS
+                       SetUniformiv(loc, BL_Uniform::UNI_INT, &index, (sizeof(int)) );
+#else
+                       SetUniform(loc, index);
+#endif
+                       //if(index <= MAXTEX)
+                       //      mSampler[index].mLoc = loc;
+                       //else
+                       //      spit("Invalid texture sample index: " << index);
}
Py_Return;
}
@@ -1418,7 +1395,24 @@ KX_PYMETHODDEF_DOC( BL_Shader, setUniformMatrix3,

{
-       Py_Return;
+       if(mError) {
+               Py_INCREF(Py_None);
+               return Py_None;
+       }
+       int attr=0;
+       if(PyArg_ParseTuple(args, "i", &attr )) {
+                       return NULL;
+               }
+               mAttr=SHD_TANGENT;
+               Py_Return;
+       }
+       return NULL;
+#endif
}

@@ -21,14 +21,10 @@ class BL_Sampler
{
public:
BL_Sampler():
-               mLoc(-1),
-               mTexture(0),
-               mOwn(0)
+               mLoc(-1)
{
}
int                             mLoc;           // Sampler location
-       BL_Texture*             mTexture;       // Texture data
-       bool                    mOwn;           // True if we own it
};

/**
@@ -104,7 +100,8 @@ private:
int                             mPass;                          // 1.. unused
bool                    mOk;                            // Valid and ok
bool                    mUse;                           // ...
-       BL_Sampler              mSampler[MAXTEX];       // Number of samplers
+//BL_Sampler           mSampler[MAXTEX];       // Number of samplers
+       int                             mAttr;                          // Tangent attribute
char*                   vertProg;                       // Vertex program string
char*                   fragProg;                       // Fragment program string
bool                    mError;                         // ...
@@ -166,12 +163,13 @@ public:
int getNumPass()        {return mPass;}
bool GetError()         {return mError;}
// ---
-       const BL_Sampler*       GetSampler(int i);
+       //const BL_Sampler*     GetSampler(int i);
void                            SetSampler(int loc, int unit);

const bool                      Ok()const;
unsigned int            GetProg();
void                            SetProg(bool enable);
+       int                                     GetAttribute(){return mAttr;};

// --
// Apply methods : sets colected uniforms
@@ -181,8 +179,8 @@ public:
// Update predefined uniforms each render call
void Update(const class KX_MeshSlot & ms, class RAS_IRasterizer* rasty);

-       // Set sampler units (copied)
-       void InitializeSampler(int unit, BL_Texture* texture );
+       //// Set sampler units (copied)
+       //void InitializeSampler(int unit, BL_Texture* texture );

void SetUniformfv(int location,int type, float *param, int size,bool transpose=false);
@@ -206,15 +204,16 @@ public:
// Python interface
virtual PyObject* _getattr(const STR_String& attr);

+       // -----------------------------------
-
-       // -----------------------------------
+
+       // -----------------------------------
@@ -223,19 +222,12 @@ public:
-
-
-
-
-
-       // These come from within the material buttons
-       // sampler2d/samplerCube work
};

index f61cab5839208d24b8fea2c9eddacf8f6c4d6813..af1a8ddb568c1e2b046c5fc3d49741fee2f464af 100644 (file)
@@ -82,14 +82,13 @@ KX_BlenderMaterial::KX_BlenderMaterial(
mPass(0)

{
-       ///RAS_EXT_support._ARB_multitexture == true if were here
-
// --------------------------------
// RAS_IPolyMaterial variables...
m_flag |=RAS_BLENDERMAT;
m_flag |=(mMaterial->IdMode>=ONETEX)?RAS_MULTITEX:0;
m_flag |=(mMaterial->ras_mode & USE_LIGHT)!=0?RAS_MULTILIGHT:0;
-
+       m_flag |=(mMaterial->ras_mode &ALPHA_TEST)!=0?RAS_FORCEALPHA:0;
+
// figure max
int enabled = mMaterial->num_enabled;
int max = BL_Texture::GetMaxUnits();
@@ -197,17 +196,15 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras)

// for each enabled unit
for(i=0; i<mMaterial->num_enabled; i++) {
-               const BL_Sampler *samp = mShader->GetSampler(i);
-               BL_Texture *tex = samp->mTexture;
-               if( samp->mLoc == -1 || !tex || !tex->Ok() )
-                       continue;
-               tex->ActivateTexture();
+               if(!mTextures[i].Ok()) continue;
+               mTextures[i].ActivateTexture();
+               mTextures[0].SetMapping(mMaterial->mapping[i].mapping);
}
+
if(!mUserDefBlend) {
setDefaultBlending();
-       }else
-       {
+       }
+       else {
// tested to be valid enums
glEnable(GL_BLEND);
glBlendFunc(mBlendFunc[0], mBlendFunc[1]);
@@ -418,18 +415,19 @@ void KX_BlenderMaterial::ActivatGLMaterials( RAS_IRasterizer* rasty )const
mMaterial->matcolor[0]*mMaterial->emit,
mMaterial->matcolor[1]*mMaterial->emit,
mMaterial->matcolor[2]*mMaterial->emit,
-               1.0
-               );
+               1.0 );
+
rasty->SetAmbient(mMaterial->amb);
if (mMaterial->material)
rasty->SetPolygonOffset(-mMaterial->material->zoffs, 0.0);
}

+
void KX_BlenderMaterial::ActivateTexGen(RAS_IRasterizer *ras) const
{
-       //              ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT);
+                       ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT);

for(int i=0; i<mMaterial->num_enabled; i++) {
int mode = mMaterial->mapping[i].mapping;

-                       for(int i= 0; i<mMaterial->num_enabled; i++) {
-                               if(mMaterial->mapping[i].mapping & USEENV )
-                               else
-                       }
mModified = true;
}

index 091e78c7b28bf04a461e62cbf949ef8d3c999536..999a79546a1e81ca1023b0d23657200446e47759 100644 (file)
@@ -142,7 +142,8 @@ void RAS_BucketManager::Renderbuckets(

for (bucket = m_MaterialBuckets.begin(); bucket != m_MaterialBuckets.end(); ++bucket)
{
-               if((*bucket)->GetPolyMaterial()->IsZSort())
+               RAS_IPolyMaterial *tmp = (*bucket)->GetPolyMaterial();
+               if(tmp->IsZSort() || tmp->GetFlag() &RAS_FORCEALPHA )
rasty->SetAlphaTest(true);
else
rasty->SetAlphaTest(false);
index 6eef16471677dd2de2e35459f929e197dca3da4c..c02ff7c35667c398cb767c56055721ea95b1fa0f 100644 (file)
@@ -54,7 +54,8 @@ enum MaterialProps
RAS_AUTOGEN             =128,
RAS_NORMAL              =256,
-       RAS_DEFMULTI    =512
+       RAS_DEFMULTI    =512,
+       RAS_FORCEALPHA  =1024
};

/**
index 66e0fe0678db2cb1cc8c9109ef908511f81c895d..98a4c15b740a6e1eaf2a27588464dd639cb258e9 100644 (file)
@@ -392,6 +392,7 @@ public:
virtual void    DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0;

virtual void    SetTexCoords(TexCoGen coords, int unit) = 0;
+       virtual void    SetAttrib(int type) = 0;
virtual void    GetViewMatrix(MT_Matrix4x4 &mat) const = 0;

virtual bool    QueryLists(){return false;}
index 9e06fcda299912229875642a25b441fe4c5d8487..aba20e1a37b5c5603d24a6beae5c39d599ea3e6d 100644 (file)
@@ -406,7 +406,6 @@ PFNGLGETACTIVEATTRIBARBPROC blGetActiveAttribARB;
PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB;
#endif

-#if 0 // TODO: GL_ARB_vertex/fragment_program support
#ifdef GL_ARB_vertex_program
PFNGLVERTEXATTRIB1FARBPROC blVertexAttrib1fARB;
PFNGLVERTEXATTRIB1FVARBPROC blVertexAttrib1fvARB;
@@ -421,7 +420,6 @@ PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB;
PFNGLGETVERTEXATTRIBFVARBPROC blGetVertexAttribfvARB;
PFNGLGETVERTEXATTRIBIVARBPROC blGetVertexAttribivARB;
#endif
-#endif

#ifdef GL_EXT_compiled_vertex_array
PFNGLLOCKARRAYSEXTPROC blLockArraysEXT;
@@ -612,7 +610,6 @@ static void LinkExtensions()
}
#endif

-#if 0 // TODO: GL_ARB_vertex/fragment_program support
#if defined(GL_ARB_vertex_program)
if (QueryExtension("GL_ARB_vertex_program"))
{
@@ -637,7 +634,6 @@ static void LinkExtensions()
}
}
#endif
-#endif

#ifdef GL_ARB_depth_texture
index 9e6df30708a04bceb9d72e843063fc5b7f995196..ff1be63f17465be5052e1c0ca712b800689d7b64 100644 (file)
@@ -510,7 +510,6 @@ extern PFNGLGETACTIVEATTRIBARBPROC blGetActiveAttribARB;
extern PFNGLGETATTRIBLOCATIONARBPROC blGetAttribLocationARB;
#endif

-#if 0 // TODO: GL_ARB_vertex/fragment_program support
#ifdef GL_ARB_vertex_program
extern PFNGLVERTEXATTRIB1FARBPROC blVertexAttrib1fARB;
extern PFNGLVERTEXATTRIB1FVARBPROC blVertexAttrib1fvARB;
@@ -525,7 +524,6 @@ extern PFNGLGETVERTEXATTRIBDVARBPROC blGetVertexAttribdvARB;
extern PFNGLGETVERTEXATTRIBFVARBPROC blGetVertexAttribfvARB;
extern PFNGLGETVERTEXATTRIBIVARBPROC blGetVertexAttribivARB;
#endif
-#endif

#ifdef GL_EXT_compiled_vertex_array
extern PFNGLLOCKARRAYSEXTPROC blLockArraysEXT;
index 8f7876f66a164a48d6be663aa28fdbc9b8aeffa7..5006506688a6eab84fb0eacdf04b7123cb232f7b 100644 (file)
@@ -81,6 +81,7 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
m_focallength(0.0),
m_setfocallength(false),
m_noOfScanlines(32),
+       m_useTang(false),
m_materialCachingInfo(0)
{
m_viewmatrix.Identity();
@@ -1208,6 +1209,10 @@ void RAS_OpenGLRasterizer::SetTexCoords(TexCoGen coords,int unit)
m_texco[unit] = coords;
}

+void RAS_OpenGLRasterizer::SetAttrib(int type)
+{
+       if(type == RAS_TEXTANGENT) m_useTang=true;
+}

void RAS_OpenGLRasterizer::TexCoord(const RAS_TexVert &tv, int enabled)
{
@@ -1242,6 +1247,12 @@ void RAS_OpenGLRasterizer::TexCoord(const RAS_TexVert &tv, int enabled)
}
}
#endif
+
+#ifdef GL_ARB_vertex_program
+       if(m_useTang && bgl::RAS_EXT_support._ARB_vertex_program)
+               bgl::blVertexAttrib4fvARB(1/*tangent*/, tv.getTangent());
+#endif
+
}
void RAS_OpenGLRasterizer::Tangent(    const RAS_TexVert& v1,
const RAS_TexVert& v2,
@@ -94,6 +94,7 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer
protected:
int                             m_drawingmode;
TexCoGen                m_texco[RAS_MAX];
+       bool                    m_useTang;

/** Stores the caching information for the last material activated. */
RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo;
@@ -284,6 +285,7 @@ public:
std::vector <OglDebugLine>      m_debugLines;

virtual void    SetTexCoords(TexCoGen coords,int enabled);
+       virtual void    SetAttrib(int type);
void                    TexCoord(const RAS_TexVert &tv, int unit);
virtual void    GetViewMatrix(MT_Matrix4x4 &mat) const;