applied patch from snailrose, related to multi-platform OpenGL extensions.
authorErwin Coumans <blender@erwincoumans.com>
Tue, 10 Jan 2006 06:34:42 +0000 (06:34 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Tue, 10 Jan 2006 06:34:42 +0000 (06:34 +0000)
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Ketsji/BL_Material.cpp
source/gameengine/Ketsji/BL_Material.h
source/gameengine/Ketsji/BL_Shader.cpp
source/gameengine/Ketsji/BL_Shader.h
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
source/gameengine/Ketsji/KX_BlenderMaterial.h
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/ARB_multitexture.h
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_GLExtensionManager.h
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp

index 368fe6f9a3161591de8c1917f1e4539175b9fa06..a2801db7069cb67ddfd48840d26f62e04a037793 100644 (file)
@@ -479,6 +479,7 @@ BL_Material* ConvertMaterial(  Mesh* mesh, Material *mat, TFace* tface,  MFace*
                material->ref                   = mat->ref;
                material->amb                   = mat->amb;
                material->ras_mode |= ((mat->mode & MA_ZTRA) != 0)?ZSORT:0;
+               material->ras_mode |= ((mat->mode & MA_WIRE) != 0)?WIRE:0;
        }
        else {
                int valid = 0;
index b77750c16443fd868532644f8ae5f12fc570aa81..29012904ea1b62bf51c06affbf1f7d4be90789c4 100644 (file)
@@ -1,21 +1,5 @@
 // ------------------------------------
-#ifdef WIN32
-#include <windows.h>
-#endif // WIN32
-#ifdef __APPLE__
-#include <OpenGL/gl.h>
-#include <OpenGL/glu.h>
-#else
-#include <GL/gl.h>
-#include <GL/glu.h>
-#endif
-
-
-#include <iostream>
-
 #include "BL_Material.h"
-#include "MT_assert.h"
-
 #include "DNA_material_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_image_types.h"
index a55756addb808c338dcbff1659269e7ed52e751e..0b8856690d48217b87c8bf46f725d6048a263e1e 100644 (file)
@@ -123,7 +123,8 @@ enum BL_ras_mode
        ZSORT=4,
        TRANSP=8,
        TRIANGLE=16,
-       USE_LIGHT=32
+       USE_LIGHT=32,
+       WIRE=64
 };
 
 // -------------------------------------
index ec804228f6171fb4855ddfec266b85fb35123c62..7e0b6df3a3aac3566168c3bb3165e3e8d62788c7 100644 (file)
 #include "MT_Matrix4x4.h"
 #include "MT_Matrix3x3.h"
 #include "KX_PyMath.h"
+#include "MEM_guardedalloc.h"
 
 #include "RAS_GLExtensionManager.h"
 
 //using namespace bgl;
 #define spit(x) std::cout << x << std::endl;
 
-
 const bool BL_Shader::Ok()const
 {
-        return (mShader !=0 && mOk && mUse);
+       return (mShader !=0 && mOk && mUse);
 }
 
 BL_Shader::BL_Shader(int n, PyTypeObject *T)
@@ -37,10 +37,10 @@ BL_Shader::BL_Shader(int n, PyTypeObject *T)
        mVert(0),
        mFrag(0),
        mPass(1),
-       vertProg(""),
-       fragProg(""),
        mOk(0),
-       mUse(0)
+       mUse(0),
+       vertProg(""),
+       fragProg("")
 {
        // if !RAS_EXT_support._ARB_shader_objects this class will not be used
 
@@ -91,45 +91,74 @@ BL_Shader::~BL_Shader()
 bool BL_Shader::LinkProgram()
 {
 #ifdef GL_ARB_shader_objects
-       if(!vertProg || !fragProg ) return false;
+       int numchars=0;
+       char* log=0;
+       int vertlen = 0, fraglen=0, proglen=0;
 
-       int vertstat,fragstat,progstat;
-       
-       // vertex prog
-       unsigned int vert = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
-       glShaderSourceARB(vert, 1, (const char**) &vertProg, 0);
-       glCompileShaderARB(vert);
-       glGetObjectParameterivARB(vert, GL_OBJECT_INFO_LOG_LENGTH_ARB, &vertstat);
-       // errors if any
-       printInfo(vert);
-       
-       // fragment prog
-       unsigned int frag = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
-       glShaderSourceARB(frag, 1,(const char**) &fragProg, 0);
-       glCompileShaderARB(frag);
-       glGetObjectParameterivARB(frag, GL_OBJECT_INFO_LOG_LENGTH_ARB, &fragstat);
-       // errors if any
-       printInfo(frag);
+       if(!vertProg || !fragProg){
+               spit("Invalid GLSL sources");
+               return false;
+       }
        
-       if(!vertstat || !fragstat) return false;
-
-       // main prog
-       unsigned int prog = glCreateProgramObjectARB();
-       glAttachObjectARB(prog,vert);
-       glAttachObjectARB(prog,frag);
+       // create our objects
+       unsigned int tmpVert = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
+       unsigned int tmpFrag = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
+       unsigned int tmpProg = glCreateProgramObjectARB();
+
+       if(!tmpVert || !tmpFrag || !tmpProg){
+               glDeleteObjectARB(tmpVert);
+               glDeleteObjectARB(tmpFrag);
+               glDeleteObjectARB(tmpProg);
+               return false;
+       }
+       // set/compile vertex shader
+       glShaderSourceARB(tmpVert, 1, (const char**)&vertProg, 0);
+       glCompileShaderARB(tmpVert);
+       glGetObjectParameterivARB(tmpVert, GL_OBJECT_INFO_LOG_LENGTH_ARB, &vertlen);
+
+       if( vertlen > 0 && !PrintInfo(vertlen,tmpVert, "Vertex Shader") ){
+               spit("Vertex shader failed");
+               glDeleteObjectARB(tmpVert);
+               glDeleteObjectARB(tmpFrag);
+               glDeleteObjectARB(tmpProg);
+               mOk     = 0;
+               return false;
+       }
+       // set/compile fragment shader
+       glShaderSourceARB(tmpFrag, 1,(const char**)&fragProg, 0);
+       glCompileShaderARB(tmpFrag);
+       glGetObjectParameterivARB(tmpFrag, GL_OBJECT_INFO_LOG_LENGTH_ARB, &fraglen);
+       if(fraglen >0 && !PrintInfo(fraglen,tmpFrag, "Fragment Shader") ){
+               spit("Fragment shader failed");
+               glDeleteObjectARB(tmpVert);
+               glDeleteObjectARB(tmpFrag);
+               glDeleteObjectARB(tmpProg);
+               mOk     = 0;
+               return false;
+       }
 
-       glLinkProgramARB(prog);
-       glGetObjectParameterivARB(prog, GL_OBJECT_INFO_LOG_LENGTH_ARB, &progstat);
-       // info on how it compiled &| linked
-       printInfo(prog);
+       // set compiled vert/frag shader & link
+       glAttachObjectARB(tmpProg, tmpVert);
+       glAttachObjectARB(tmpProg, tmpFrag);
+       glLinkProgramARB(tmpProg);
 
-       if(!progstat)
+       glGetObjectParameterivARB(tmpProg, GL_OBJECT_INFO_LOG_LENGTH_ARB, &proglen);
+       if(proglen > 0){
+               PrintInfo(proglen,tmpProg, "GLSL Shader");
+       }
+       else{
+               spit("Program failed");
+               glDeleteObjectARB(tmpVert);
+               glDeleteObjectARB(tmpFrag);
+               glDeleteObjectARB(tmpProg);
+               mOk     = 0;
                return false;
+       }
 
-       // assign
-       mShader = prog;
-       mVert   = vert;
-       mFrag   = frag;
+       // set
+       mShader = tmpProg;
+       mVert   = tmpVert;
+       mFrag   = tmpFrag;
        mOk             = 1;
        return true;
 #else
@@ -137,30 +166,33 @@ bool BL_Shader::LinkProgram()
 #endif//GL_ARB_shader_objects
 }
 
-void BL_Shader::printInfo(unsigned int pr)
+bool BL_Shader::PrintInfo(int len, unsigned int handle, const char *type)
 {
 #ifdef GL_ARB_shader_objects
-#ifndef GLcharARB
-typedef char GLcharARB;
-#endif 
-int length=0;
-       glGetObjectParameterivARB(pr, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
-
-       if(length > 1)
-       {
-               GLcharARB*logger = (GLcharARB*)malloc(sizeof(GLcharARB)*length);
-               int chars=0;
-               
-               glGetInfoLogARB(pr, length, &chars, logger);
-               if(chars>0)
-                       std::cout << (logger) << std::endl;
-
-               if(logger)
-                       free(logger);
+       int numchars=0;
+       char *log = (char*)MEM_mallocN(sizeof(char)*len, "print_log");
+       if(!log) {
+               spit("BL_Shader::PrintInfo() MEM_mallocN failed");
+               return false;
+       }
+       glGetInfoLogARB(handle, len, &numchars, log);
+       
+       if(numchars >0){
+               spit(type);
+               spit(log);
+               MEM_freeN(log);
+               log=0;
+               return false;
        }
+       MEM_freeN(log);
+       log=0;
+       return true;
+#else
+       return false
 #endif//GL_ARB_shader_objects
 }
 
+
 char *BL_Shader::GetVertPtr()
 {
        return vertProg?vertProg:0;
@@ -299,19 +331,16 @@ KX_PYMETHODDEF_DOC( BL_Shader, setSource," setSource(vertexProgram, fragmentProg
        {
                vertProg = v;
                fragProg = f;
-               if( LinkProgram() )
-               {
+               if( LinkProgram() ) {
                        glUseProgramObjectARB( mShader );
                        mUse = apply!=0;
                        Py_Return;
                }
-               else
-               {
-                       vertProg = 0;
-                       fragProg = 0;
-                       mUse = 0;
-                       glUseProgramObjectARB( 0 );
-               }
+               vertProg = 0;
+               fragProg = 0;
+               mUse = 0;
+               glUseProgramObjectARB( 0 );
+               PyErr_Format(PyExc_ValueError, "GLSL Error");
        }
        return NULL;
 #else
@@ -368,7 +397,6 @@ KX_PYMETHODDEF_DOC( BL_Shader, validate, "validate()")
        int stat = 0;
        glValidateProgramARB(mShader);
        glGetObjectParameterivARB(mShader, GL_OBJECT_VALIDATE_STATUS_ARB, &stat);
-       printInfo(mShader);
 
        return PyInt_FromLong((stat!=0));
 #else
index 19e0cb8e9b30f818abea19fd306a4f520df0e717..2e08eeb0d70d00551908636dd8a53b9474a25b49 100644 (file)
@@ -45,7 +45,7 @@ private:
        char*                   vertProg;
        char*                   fragProg;
        bool                    LinkProgram();
-       void                    printInfo(unsigned int pr);
+       bool                    PrintInfo(int len, unsigned int handle, const char *type);
 
 public:
        BL_Shader(int n, PyTypeObject *T=&Type);
index ab2b9c63b211c303cf0209d7f4ac17a1b733584c..ebf040d3c5d3c8e46820982dbb13aa0bd02e851e 100644 (file)
@@ -48,7 +48,7 @@ extern "C" {
 using namespace bgl;
 #define spit(x) std::cout << x << std::endl;
 
-static PyObject *gTextureDict = 0;
+//static PyObject *gTextureDict = 0;
 
 KX_BlenderMaterial::KX_BlenderMaterial(
     KX_Scene *scene,
@@ -73,9 +73,8 @@ KX_BlenderMaterial::KX_BlenderMaterial(
                clientobject
        ),
        mMaterial(data),
-       mScene(scene),
        mShader(0),
-       mUseShader(0),
+       mScene(scene),
        mPass(0)
 {
        ///RAS_EXT_support._ARB_multitexture == true if were here
@@ -129,9 +128,10 @@ void KX_BlenderMaterial::OnConstruction()
 {
        // for each unique material...
        #ifdef GL_ARB_multitexture
+/*     will be used to switch textures
        if(!gTextureDict)
                gTextureDict = PyDict_New();
-
+*/
        #ifdef GL_ARB_shader_objects
        if( RAS_EXT_support._ARB_shader_objects )
                mShader = new BL_Shader( mMaterial->num_enabled );
@@ -167,7 +167,7 @@ void KX_BlenderMaterial::OnConstruction()
                #ifdef GL_ARB_texture_cube_map
                }
                #endif//GL_ARB_texture_cube_map
-               PyDict_SetItemString(gTextureDict, mTextures[i].GetName().Ptr(), PyInt_FromLong(mTextures[i]));
+               /*PyDict_SetItemString(gTextureDict, mTextures[i].GetName().Ptr(), PyInt_FromLong(mTextures[i]));*/
        }
        #endif//GL_ARB_multitexture
 }
@@ -207,11 +207,11 @@ void KX_BlenderMaterial::OnExit()
                glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
        }
        
-       if (gTextureDict) {
+       /*if (gTextureDict) {
                PyDict_Clear(gTextureDict);
                Py_DECREF(gTextureDict);
                gTextureDict = 0;
-       }
+       }*/
 
        glActiveTextureARB(GL_TEXTURE0_ARB);
 
@@ -357,9 +357,6 @@ void KX_BlenderMaterial::setTexData( bool enable )
                #ifdef GL_ARB_texture_cube_map
                // use environment maps
                if( mMaterial->mapping[i].mapping &USEENV && RAS_EXT_support._ARB_texture_cube_map ) {
-                       // should not happen
-                       // if(mTextures[i].GetTextureType() & BL_TEX2D) continue;
-
                        glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, mTextures[i] ); 
                        glEnable(GL_TEXTURE_CUBE_MAP_ARB);
                        setTextureEnvironment( i );
@@ -374,12 +371,6 @@ void KX_BlenderMaterial::setTexData( bool enable )
                // 2d textures
                else { 
                #endif//GL_ARB_texture_cube_map
-                       
-                       // should not happen
-                       //if(mTextures[i].GetTextureType() & BL_TEXCUBE) continue;
-                       //
-                       MT_assert(!(mTextures[i].GetTextureType() & BL_TEXCUBE));
-
                        glBindTexture( GL_TEXTURE_2D, mTextures[i] );   
                        glEnable( GL_TEXTURE_2D );
                        setTextureEnvironment( i );
@@ -436,7 +427,7 @@ KX_BlenderMaterial::ActivatShaders(
                else
                        rasty->SetCullFace(true);
 
-               if (mMaterial->mode & RAS_IRasterizer::KX_LINES)
+               if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES)
                        rasty->SetLines(true);
                else
                        rasty->SetLines(false);
@@ -504,7 +495,7 @@ KX_BlenderMaterial::ActivateMat(
                else
                        rasty->SetCullFace(true);
 
-               if (mMaterial->mode & RAS_IRasterizer::KX_LINES)
+               if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES)
                        rasty->SetLines(true);
                else
                        rasty->SetLines(false);
@@ -881,10 +872,9 @@ void KX_BlenderMaterial::UpdateIPO(
 PyMethodDef KX_BlenderMaterial::Methods[] = 
 {
        KX_PYMETHODTABLE( KX_BlenderMaterial, getShader ),
-       KX_PYMETHODTABLE( KX_BlenderMaterial, useShader ),
        KX_PYMETHODTABLE( KX_BlenderMaterial, getMaterialIndex ),
-       KX_PYMETHODTABLE( KX_BlenderMaterial, getTexture ),
-       KX_PYMETHODTABLE( KX_BlenderMaterial, setTexture ),
+//     KX_PYMETHODTABLE( KX_BlenderMaterial, getTexture ),
+//     KX_PYMETHODTABLE( KX_BlenderMaterial, setTexture ),
 
        {NULL,NULL} //Sentinel
 };
@@ -940,24 +930,6 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()")
        #endif//GL_ARB_shader_objects
 }
 
-KX_PYMETHODDEF_DOC( KX_BlenderMaterial, useShader, "useShader(1:0)" )
-{
-       #ifdef GL_ARB_shader_objects
-       if(!RAS_EXT_support._ARB_shader_objects) {
-               PyErr_Format(PyExc_SystemError, "GLSL not supported");
-               return NULL;
-       }
-       int use =0;
-       if(PyArg_ParseTuple(args, "i", &use)) {
-               mUseShader = (use!= 0);
-               Py_Return;
-       }
-       return NULL;
-       #else
-       Py_Return;
-       #endif//GL_ARB_shader_objects
-}
-
 KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()")
 {
        return PyInt_FromLong( mMaterial->material_index );
@@ -965,11 +937,13 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()")
 
 KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getTexture, "getTexture( index )" )
 {
+       // TODO: enable python switching
        return NULL;
 }
 
 KX_PYMETHODDEF_DOC( KX_BlenderMaterial, setTexture , "setTexture( index, tex)")
 {
+       // TODO: enable python switching
        return NULL;
 }
 
index 012bbef279502b5554d219a3b40cc3fd95d98c5a..573481448908a495a6af5cc14d8eccf8736980f7 100644 (file)
@@ -68,7 +68,6 @@ public:
        virtual int       _setattr(const STR_String& attr, PyObject *pyvalue);
 
        KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
-       KX_PYMETHOD_DOC( KX_BlenderMaterial, useShader );
        KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );
        KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
        KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
@@ -80,7 +79,6 @@ public:
 private:
        BL_Material*    mMaterial;
        BL_Shader*              mShader;
-       bool                    mUseShader;
        KX_Scene*               mScene;
        BL_Texture              mTextures[MAXTEX];              // texture array
        
index a3031512049fc827c543ea04cf98dc092db03b51..2a760b09f5e738dcea4c7f57ccbf92c643e3a97c 100644 (file)
@@ -2,24 +2,6 @@
 #define __ARB_MULTITEXTURE_H__
 
 /* 
-       make sure glext is included before this, when setting up extensions
-
-should we try for this?
-...
-#include ("glext.h" or "SDL_opengl.h"(will need SDL-1.2.9))
-...
-#define BGL_MultiTexture
-#ifdef GL_VERSION_1_3 // in core 
-       #define BGL_TEXTURE0 // GL_TEXTURE0
-       #define bglActiveTexture(unit) bgl::glActiveTexture(unit)
-       // ...
-#elif GL_ARB_multitexture //  GL < 1_3 use extension
-       #define BGL_TEXTURE0 // GL_TEXTURE0_ARB
-       #define bglActiveTexture(unit) bgl::glActiveTextureARB(unit)
-       // ...
-#else // cant do it, skip
-       #undef BGL_MultiTexture
-#endif
 */
 
 /* ----------------------------------------------------------------------------
index f91b50e39bf42f11d6d7d8451a3813cdacced83a..2d862ea3853d6dd90564826fd900ca5f8bc19b63 100644 (file)
 #define __RAS_GLEXTENSIONMANAGER_H__
 
 
+#ifdef WIN32
+#  include <windows.h>
+#  include <GL/gl.h>
 
-#ifdef __APPLE__
-#include <OpenGL/gl.h>
-#else
-#include <GL/gl.h>
+#elif defined(__APPLE__)
+#  define __glext_h_
+#  include <OpenGL/gl.h>
+#  include <OpenGL/glu.h>
+#  undef __glext_h_
+
+#else /* UNIX */
+#  define __glext_h_
+#  include <GL/gl.h>
+#  include <GL/glx.h>
+#  undef GL_ARB_multitexture // (ubuntu)
+#  undef __glext_h_
 #endif
 
 #include "glext.h"
index fa507b85b1b32db82d2535d95827b9fea5d66f01..7a140fd0f7e1855dc181150b6eb196d95878e447 100644 (file)
@@ -432,7 +432,7 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void)
 void RAS_OpenGLRasterizer::EndFrame()
 {
        glDisable(GL_LIGHTING);
-       glDisable(GL_TEXTURE);
+       glDisable(GL_TEXTURE_2D);
 
        //DrawDebugLines
        glBegin(GL_LINES);