diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-01-10 09:34:42 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-01-10 09:34:42 +0300 |
commit | b7be6620d6ecfbec1d82128f402b585041910ca9 (patch) | |
tree | c43c034f4f9b79a46d68b6fe191f2b0644aad494 /source/gameengine/Ketsji | |
parent | 95355efec9406b6681c3f1b7852712349ad82dd9 (diff) |
applied patch from snailrose, related to multi-platform OpenGL extensions.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/BL_Material.cpp | 16 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Material.h | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Shader.cpp | 160 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Shader.h | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 52 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_BlenderMaterial.h | 2 |
6 files changed, 110 insertions, 125 deletions
diff --git a/source/gameengine/Ketsji/BL_Material.cpp b/source/gameengine/Ketsji/BL_Material.cpp index b77750c1644..29012904ea1 100644 --- a/source/gameengine/Ketsji/BL_Material.cpp +++ b/source/gameengine/Ketsji/BL_Material.cpp @@ -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" diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h index a55756addb8..0b8856690d4 100644 --- a/source/gameengine/Ketsji/BL_Material.h +++ b/source/gameengine/Ketsji/BL_Material.h @@ -123,7 +123,8 @@ enum BL_ras_mode ZSORT=4, TRANSP=8, TRIANGLE=16, - USE_LIGHT=32 + USE_LIGHT=32, + WIRE=64 }; // ------------------------------------- diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index ec804228f61..7e0b6df3a3a 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -19,16 +19,16 @@ #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 diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h index 19e0cb8e9b3..2e08eeb0d70 100644 --- a/source/gameengine/Ketsji/BL_Shader.h +++ b/source/gameengine/Ketsji/BL_Shader.h @@ -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); diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index ab2b9c63b21..ebf040d3c5d 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -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; } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 012bbef2795..57348144890 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -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 |