diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2010-05-30 01:22:24 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2010-05-30 01:22:24 +0400 |
commit | 9d3157eed000e7c543d04f5ad3efc5990675903b (patch) | |
tree | 54d3fcbc7a128ef0881385f49c57392c38bbd7e0 /source/gameengine | |
parent | e335321e884f270e2ad28a7b6c75eea7e11bf4b7 (diff) |
Reversing the last merge because I botched it.
Diffstat (limited to 'source/gameengine')
16 files changed, 265 insertions, 84 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 2f0f70ed9fe..efd93eb3102 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1570,6 +1570,13 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, objprop.m_boundobject.c.m_height = 2.f*bb.m_extends[2]; break; } + case OB_BOUND_CAPSULE: + { + objprop.m_boundclass = KX_BOUNDCAPSULE; + objprop.m_boundobject.c.m_radius = MT_max(bb.m_extends[0], bb.m_extends[1]); + objprop.m_boundobject.c.m_height = bb.m_extends[2]; + break; + } } } @@ -2691,4 +2698,4 @@ void BL_ConvertBlenderObjects(struct Main* maggie, MT_Scalar distance = (activecam)? activecam->GetCameraFar() - activecam->GetCameraNear(): 100.0f; RAS_BucketManager *bucketmanager = kxscene->GetBucketManager(); bucketmanager->OptimizeBuckets(distance); -} +}
\ No newline at end of file diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 3a5bb92b4fa..4792ead8be2 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -932,7 +932,7 @@ Main* KX_BlenderSceneConverter::GetMainDynamicPath(const char *path) return NULL; } -bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_Scene *scene_merge, char **err_str) +bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, char *filter, KX_Scene *scene_merge, char **err_str) { bContext *C; Main *main_newlib; /* stored as a dynamic 'main' until we free it */ @@ -941,6 +941,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_S BlendHandle *bpy_openlib = NULL; /* ptr to the open .blend file */ int idcode= BLO_idcode_from_name(group); short flag= 0; /* dont need any special options */ + bool found = false; /* used for error reporting when using item */ ReportList reports; static char err_local[255]; @@ -949,50 +950,48 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_S snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group); return false; } - - if(GetMainDynamicPath(path)) { - snprintf(err_local, sizeof(err_local), "blend file already open \"%s\"\n", path); - *err_str= err_local; - return false; - } - bpy_openlib = BLO_blendhandle_from_file( (char *)path ); - if(bpy_openlib==NULL) { - snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path); - *err_str= err_local; - return false; - } - - main_newlib= (Main *)MEM_callocN( sizeof(Main), "BgeMain"); - C= CTX_create(); - CTX_data_main_set(C, main_newlib); - BKE_reports_init(&reports, RPT_STORE); + main_newlib = GetMainDynamicPath(path); - /* here appending/linking starts */ - main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path); - - names = BLO_blendhandle_get_datablock_names( bpy_openlib, idcode); - - int i=0; - LinkNode *n= names; - while(n) { - BLO_library_append_named_part(C, main_tmp, &bpy_openlib, (char *)n->link, idcode, 0); - n= (LinkNode *)n->next; - i++; + if (main_newlib == NULL) + { + bpy_openlib = BLO_blendhandle_from_file( (char *)path ); + if(bpy_openlib==NULL) { + snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path); + *err_str= err_local; + return false; + } + + main_newlib= (Main *)MEM_callocN( sizeof(Main), "BgeMain"); + C= CTX_create(); + CTX_data_main_set(C, main_newlib); + BKE_reports_init(&reports, RPT_STORE); + + /* here appending/linking starts */ + main_tmp = BLO_library_append_begin(C, &bpy_openlib, (char *)path); + + names = BLO_blendhandle_get_datablock_names( bpy_openlib, idcode); + + int i=0; + LinkNode *n= names; + while(n) { + BLO_library_append_named_part(C, main_tmp, &bpy_openlib, (char *)n->link, idcode, 0); + n= (LinkNode *)n->next; + i++; + } + BLI_linklist_free(names, free); /* free linklist *and* each node's data */ + + BLO_library_append_end(C, main_tmp, &bpy_openlib, idcode, flag); + BLO_blendhandle_close(bpy_openlib); + + CTX_free(C); + BKE_reports_clear(&reports); + /* done linking */ + + /* needed for lookups*/ + GetMainDynamic().push_back(main_newlib); + strncpy(main_newlib->name, path, sizeof(main_newlib->name)); } - BLI_linklist_free(names, free); /* free linklist *and* each node's data */ - - BLO_library_append_end(C, main_tmp, &bpy_openlib, idcode, flag); - BLO_blendhandle_close(bpy_openlib); - - CTX_free(C); - BKE_reports_clear(&reports); - /* done linking */ - - /* needed for lookups*/ - GetMainDynamic().push_back(main_newlib); - strncpy(main_newlib->name, path, sizeof(main_newlib->name)); - if(idcode==ID_ME) { /* Convert all new meshes into BGE meshes */ @@ -1000,24 +999,39 @@ bool KX_BlenderSceneConverter::LinkBlendFile(const char *path, char *group, KX_S KX_Scene *kx_scene= m_currentScene; for(mesh= (ID *)main_newlib->mesh.first; mesh; mesh= (ID *)mesh->next ) { - RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this); - kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj); + /* If item is defined, use it to filter meshes */ + if (!strcmp(filter, "") || !strcmp(filter, mesh->name+2)) + { + found = true; + RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this); + kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj); + } } } else if(idcode==ID_SCE) { /* Merge all new linked in scene into the existing one */ ID *scene; for(scene= (ID *)main_newlib->scene.first; scene; scene= (ID *)scene->next ) { - printf("SceneName: %s\n", scene->name); - - /* merge into the base scene */ - KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene); - scene_merge->MergeScene(other); - - // RemoveScene(other); // Dont run this, it frees the entire scene converter data, just delete the scene - delete other; + /* If item is defined, use it to filter scenes */ + if (!strcmp(filter, "") || !strcmp(filter, scene->name+2)) + { + found = true; + printf("Loading scene: %s\n", scene->name+2); + /* merge into the base scene */ + KX_Scene* other= m_ketsjiEngine->CreateScene((Scene *)scene); + scene_merge->MergeScene(other); + + // RemoveScene(other); // Dont run this, it frees the entire scene converter data, just delete the scene + delete other; + } } } + + if (found == false) + { + printf("Item not found: %s\n", filter); + return false; + } return true; } diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index 3dd3afb5662..341e4546430 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -142,7 +142,7 @@ public: struct Main* GetMainDynamicPath(const char *path); vector<struct Main*> &GetMainDynamic(); - bool LinkBlendFile(const char *path, char *group, KX_Scene *scene_merge, char **err_str); + bool LinkBlendFile(const char *path, char *group, char *filter, KX_Scene *scene_merge, char **err_str); bool MergeScene(KX_Scene *to, KX_Scene *from); RAS_MeshObject *ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name); bool FreeBlendFile(struct Main *maggie); diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 71507642226..bde4bf3892b 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -228,7 +228,8 @@ static HWND findGhostWindowHWND(GHOST_IWindow* window) bool GPG_Application::startScreenSaverPreview( HWND parentWindow, const bool stereoVisual, - const int stereoMode) + const int stereoMode, + const GHOST_TUns16 samples) { bool success = false; @@ -240,7 +241,7 @@ bool GPG_Application::startScreenSaverPreview( STR_String title = ""; m_mainWindow = fSystem->createWindow(title, 0, 0, windowWidth, windowHeight, GHOST_kWindowStateMinimized, - GHOST_kDrawingContextTypeOpenGL, stereoVisual); + GHOST_kDrawingContextTypeOpenGL, stereoVisual, samples); if (!m_mainWindow) { printf("error: could not create main window\n"); exit(-1); @@ -282,9 +283,10 @@ bool GPG_Application::startScreenSaverFullScreen( int height, int bpp,int frequency, const bool stereoVisual, - const int stereoMode) + const int stereoMode, + const GHOST_TUns16 samples) { - bool ret = startFullScreen(width, height, bpp, frequency, stereoVisual, stereoMode); + bool ret = startFullScreen(width, height, bpp, frequency, stereoVisual, stereoMode, samples); if (ret) { HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow); @@ -306,13 +308,14 @@ bool GPG_Application::startWindow(STR_String& title, int windowWidth, int windowHeight, const bool stereoVisual, - const int stereoMode) + const int stereoMode, + const GHOST_TUns16 samples) { bool success; // Create the main window //STR_String title ("Blender Player - GHOST"); m_mainWindow = fSystem->createWindow(title, windowLeft, windowTop, windowWidth, windowHeight, GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL, stereoVisual); + GHOST_kDrawingContextTypeOpenGL, stereoVisual, samples); if (!m_mainWindow) { printf("error: could not create main window\n"); exit(-1); @@ -334,10 +337,11 @@ bool GPG_Application::startWindow(STR_String& title, bool GPG_Application::startEmbeddedWindow(STR_String& title, const GHOST_TEmbedderWindowID parentWindow, const bool stereoVisual, - const int stereoMode) { + const int stereoMode, + const GHOST_TUns16 samples) { m_mainWindow = fSystem->createWindow(title, 0, 0, 0, 0, GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL, stereoVisual, parentWindow); + GHOST_kDrawingContextTypeOpenGL, stereoVisual,samples, parentWindow); if (!m_mainWindow) { printf("error: could not create main window\n"); @@ -358,7 +362,8 @@ bool GPG_Application::startFullScreen( int height, int bpp,int frequency, const bool stereoVisual, - const int stereoMode) + const int stereoMode, + const GHOST_TUns16 samples) { bool success; // Create the main window diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h index 48a6c8e78ec..e6a47628923 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.h +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h @@ -59,12 +59,12 @@ public: bool SetGameEngineData(struct Main* maggie, struct Scene* scene, int argc, char** argv); bool startWindow(STR_String& title, int windowLeft, int windowTop, int windowWidth, int windowHeight, - const bool stereoVisual, const int stereoMode); - bool startFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode); - bool startEmbeddedWindow(STR_String& title, const GHOST_TEmbedderWindowID parent_window, const bool stereoVisual, const int stereoMode); + const bool stereoVisual, const int stereoMode, const GHOST_TUns16 numOfAASamples = 0); + bool startFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0); + bool startEmbeddedWindow(STR_String& title, const GHOST_TEmbedderWindowID parent_window, const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0); #ifdef WIN32 - bool startScreenSaverFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode); - bool startScreenSaverPreview(HWND parentWindow, const bool stereoVisual, const int stereoMode); + bool startScreenSaverFullScreen(int width, int height, int bpp, int frequency, const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0); + bool startScreenSaverPreview(HWND parentWindow, const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0); #endif virtual bool processEvent(GHOST_IEvent* event); diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index b7ed8666325..69df00949a8 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -214,6 +214,7 @@ void usage(const char* program) printf(" -c: keep console window open\n\n"); #endif printf(" -d: turn debugging on\n\n"); + printf(" -m: sets the number of samples to request for multisampling"); printf(" -g: game engine options:\n\n"); printf(" Name Default Description\n"); printf(" ------------------------------------------------------------------------\n"); @@ -229,6 +230,7 @@ void usage(const char* program) printf("\n"); printf("example: %s -w 320 200 10 10 -g noaudio c:\\loadtest.blend\n", program); printf("example: %s -g show_framerate = 0 c:\\loadtest.blend\n", program); + printf("example: %s -m 4 game.blend", program); } static void get_filename(int argc, char **argv, char *filename) @@ -334,6 +336,7 @@ int main(int argc, char** argv) int windowHeight = 480; GHOST_TUns32 fullScreenWidth = 0; GHOST_TUns32 fullScreenHeight= 0; + GHOST_TUns16 aaSamples = 4; int fullScreenBpp = 32; int fullScreenFrequency = 60; GHOST_TEmbedderWindowID parentWindow = 0; @@ -508,6 +511,12 @@ int main(int argc, char** argv) } } break; + case 'm': + i++; + + if ((i+1) < argc) + aaSamples = atoi(argv[i++]); + break; case 'h': usage(argv[0]); @@ -810,13 +819,13 @@ int main(int argc, char** argv) if (scr_saver_mode == SCREEN_SAVER_MODE_SAVER) { app.startScreenSaverFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency, - stereoWindow, stereomode); + stereoWindow, stereomode, aaSamples); } else #endif { app.startFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency, - stereoWindow, stereomode); + stereoWindow, stereomode, aaSamples); } } else @@ -856,16 +865,16 @@ int main(int argc, char** argv) #ifdef WIN32 if (scr_saver_mode == SCREEN_SAVER_MODE_PREVIEW) { - app.startScreenSaverPreview(scr_saver_hwnd, stereoWindow, stereomode); + app.startScreenSaverPreview(scr_saver_hwnd, stereoWindow, stereomode, aaSamples); } else #endif { if (parentWindow != 0) - app.startEmbeddedWindow(title, parentWindow, stereoWindow, stereomode); + app.startEmbeddedWindow(title, parentWindow, stereoWindow, stereomode, aaSamples); else app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight, - stereoWindow, stereomode); + stereoWindow, stereomode, aaSamples); } } } diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index c4af701f87b..1d41a7bcddb 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -69,6 +69,10 @@ ELSE(WITH_SDL) ADD_DEFINITIONS(-DDISABLE_SDL) ENDIF(WITH_SDL) +if(WITH_DDS) + ADD_DEFINITIONS(-DWITH_DDS) +ENDIF(WITH_DDS) + IF(WITH_PYTHON) SET(INC ${INC} ${PYTHON_INC}) ELSE(WITH_PYTHON) diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index 879bcd472c6..850bf4b4ad4 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -53,7 +53,8 @@ typedef enum { KX_BOUNDCONE, KX_BOUNDMESH, KX_BOUNDPOLYTOPE, - KX_BOUND_DYN_MESH + KX_BOUND_DYN_MESH, + KX_BOUNDCAPSULE } KX_BoundBoxClass; struct KX_BoxBounds diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 44ae032179b..e793f9d5966 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -184,6 +184,14 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, bm = shapeInfo->CreateBulletShape(ci.m_margin); break; } + case KX_BOUNDCAPSULE: + { + shapeInfo->m_radius = objprop->m_boundobject.c.m_radius; + shapeInfo->m_height = objprop->m_boundobject.c.m_height; + shapeInfo->m_shapeType = PHY_SHAPE_CAPSULE; + bm = shapeInfo->CreateBulletShape(ci.m_margin); + break; + } case KX_BOUNDMESH: { // mesh shapes can be shared, check first if we already have a shape on that mesh diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 0198555753e..7b0283a2efd 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -628,12 +628,13 @@ static PyObject *gLibLoad(PyObject*, PyObject* args) KX_Scene *kx_scene= gp_KetsjiScene; char *path; char *group; + char *filter= ""; char *err_str= NULL; - if (!PyArg_ParseTuple(args,"ss:LibLoad",&path, &group)) + if (!PyArg_ParseTuple(args,"ss|s:LibLoad",&path, &group, &filter)) return NULL; - if(kx_scene->GetSceneConverter()->LinkBlendFile(path, group, kx_scene, &err_str)) { + if(kx_scene->GetSceneConverter()->LinkBlendFile(path, group, filter, kx_scene, &err_str)) { Py_RETURN_TRUE; } diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 58dc8a314bf..505d3fa10a0 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -23,6 +23,9 @@ incs += ' #source/blender/misc #source/blender/blenloader #extern/glew/include # incs += ' ' + env['BF_BULLET_INC'] incs += ' ' + env['BF_OPENGL_INC'] +if env['WITH_BF_DDS']: + defs.append('WITH_DDS') + if env['WITH_BF_SDL']: incs += ' ' + env['BF_SDL_INC'] else: diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index fe429200dd4..ac0f61857f5 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -2027,6 +2027,11 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape(btScalar margin, b collisionShape->setMargin(margin); break; + case PHY_SHAPE_CAPSULE: + collisionShape = new btCapsuleShapeZ(m_radius, m_height); + collisionShape->setMargin(margin); + break; + case PHY_SHAPE_MESH: // Let's use the latest btScaledBvhTriangleMeshShape: it allows true sharing of // triangle mesh information between duplicates => drastic performance increase when diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index 08d94a2850a..4b5cdd41b9a 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -138,6 +138,7 @@ typedef enum PHY_ShapeType { PHY_SHAPE_SPHERE, PHY_SHAPE_CYLINDER, PHY_SHAPE_CONE, + PHY_SHAPE_CAPSULE, PHY_SHAPE_MESH, PHY_SHAPE_POLYTOPE, PHY_SHAPE_COMPOUND, diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 4527850a8e9..c0e08dba992 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -194,6 +194,15 @@ void RAS_2DFilterManager::AnalyseShader(int passindex, vector<STR_String>& propN { texflag[passindex] |= 0x2; } + if(glGetUniformLocationARB(m_filters[passindex], "bgl_QuarteredRenderTexture") != -1) + { + texflag[passindex] |= 0x4; + } + if(glGetUniformLocationARB(m_filters[passindex], "bgl_QuartedDepthTexture") != -1) + { + if(GLEW_ARB_depth_texture) + texflag[passindex] |= 0x8; + } if(m_gameObjects[passindex]) { @@ -241,6 +250,29 @@ void RAS_2DFilterManager::StartShaderProgram(int passindex) glUniform1iARB(uniformLoc, 2); } } + + /* Send the quartered render texture to glsl program if it needs */ + if(texflag[passindex] & 0x4){ + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_QuarteredRenderTexture"); + glActiveTextureARB(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, texname[3]); + + if (uniformLoc != -1) + { + glUniform1iARB(uniformLoc, 3); + } + } + + if(texflag[passindex] & 0x5){ + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_QuarteredDepthTexture"); + glActiveTextureARB(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, texname[4]); + + if (uniformLoc != -1) + { + glUniform1iARB(uniformLoc, 4); + } + } uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_TextureCoordinateOffset"); if (uniformLoc != -1) @@ -277,15 +309,24 @@ void RAS_2DFilterManager::EndShaderProgram() void RAS_2DFilterManager::FreeTextures() { - if(texname[0]!=(unsigned int)-1) + // Update this when adding new textures! + for (int i=0; i<5; i++) + { + if(texname[i]!=(unsigned int)-1) + glDeleteTextures(1, (GLuint*)&texname[i]); + } + + if(fbo != (unsigned int)-1) + glDeleteFramebuffersEXT(1, &fbo); + /*if(texname[0]!=(unsigned int)-1) glDeleteTextures(1, (GLuint*)&texname[0]); if(texname[1]!=(unsigned int)-1) glDeleteTextures(1, (GLuint*)&texname[1]); if(texname[2]!=(unsigned int)-1) - glDeleteTextures(1, (GLuint*)&texname[2]); + glDeleteTextures(1, (GLuint*)&texname[2]);*/ } -void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance) +void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance, bool qrender, bool qdepth) { FreeTextures(); @@ -321,6 +362,25 @@ void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); } + + if(qrender){ + glGenTextures(1, (GLuint*)&texname[3]); + glBindTexture(GL_TEXTURE_2D, texname[3]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, texturewidth/2, textureheight/2, 0, GL_RGBA8, + GL_UNSIGNED_BYTE, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glGenFramebuffersEXT(1, &fbo); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texname[3], 0); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + } + } void RAS_2DFilterManager::UpdateOffsetMatrix(RAS_ICanvas* canvas) @@ -377,6 +437,8 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) { bool need_depth=false; bool need_luminance=false; + bool need_qrender=false; + bool need_qdepth=false; int num_filters = 0; int passindex; @@ -392,7 +454,11 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) need_depth = true; if(texflag[passindex] & 0x2) need_luminance = true; - if(need_depth && need_luminance) + if(texflag[passindex] & 0x4) + need_qrender = true; + if(texflag[passindex] & 0x8) + need_qdepth = true; + if(need_depth && need_luminance && need_qrender && need_qdepth) break; } } @@ -412,7 +478,7 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) if(need_tex_update) { - SetupTextures(need_depth, need_luminance); + SetupTextures(need_depth, need_luminance, need_qrender, need_qdepth); need_tex_update = false; } @@ -428,6 +494,12 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, 0, 0, texturewidth,textureheight, 0); } + if(need_qdepth){ + glActiveTextureARB(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, texname[4]); + glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT, 0, 0, texturewidth, textureheight, 0); + } + glViewport(0,0, texturewidth, textureheight); glDisable(GL_DEPTH_TEST); @@ -448,6 +520,53 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texname[0]); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, texturewidth, textureheight, 0); + //glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, im_buff); + + if(need_qrender){ + //glActiveTextureARB(GL_TEXTURE3); + //glBindTexture(GL_TEXTURE_2D, texname[3]); + //glReadPixels(0, 0, texturewidth, textureheight, GL_RGB, GL_UNSIGNED_BYTE, im_buff); + //gluScaleImage(GL_RGB, texturewidth, textureheight, GL_UNSIGNED_BYTE, im_buff, + // texturewidth/2, textureheight/2, GL_UNSIGNED_BYTE, scaled_buff); + //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texturewidth, textureheight, GL_RGBA, GL_UNSIGNED_BYTE, im_buff); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == GL_FRAMEBUFFER_COMPLETE_EXT) { + glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT); + glViewport(0, 0, texturewidth/2, textureheight/2); + + /* glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0, texturewidth/2, 0, textureheight/2); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity();*/ + glClearColor(0, 0, 0, 1); + + glClear(GL_COLOR_BUFFER_BIT); + /*glBindTexture(GL_TEXTURE_2D, texname[0]); + glBegin(GL_QUADS); + glColor4f(0.f, 1.f, 1.f, 1.f); + glTexCoord2f(1.f, 1.f); glVertex2f(1,1); + glTexCoord2f(0.f, 1.f); glVertex2f(-1,1); + glTexCoord2f(0.f, 0.f); glVertex2f(-1,-1); + glTexCoord2f(1.f, 0.f); glVertex2f(1,-1); + glEnd();*/ + + glFlush(); + //glPopMatrix(); + //glMatrixMode(GL_PROJECTION); + //glPopMatrix(); + + glPopAttrib(); + } else { + printf("Could not use the framebuffer\n"); + } + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + } + + glClearColor(1, 0, 1, 1); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_QUADS); diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.h b/source/gameengine/Rasterizer/RAS_2DFilterManager.h index 7ff7cde7882..2519473520a 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.h +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.h @@ -45,7 +45,7 @@ private: void EndShaderProgram(); void PrintShaderErrors(unsigned int shader, const char *task, const char *code); - void SetupTextures(bool depth, bool luminance); + void SetupTextures(bool depth, bool luminance, bool qrender, bool qdepth); void FreeTextures(); void UpdateOffsetMatrix(RAS_ICanvas* canvas); @@ -54,13 +54,15 @@ private: float canvascoord[4]; float textureoffsets[18]; float view[4]; - /* texname[0] contains render to texture, texname[1] contains depth texture, texname[2] contains luminance texture*/ - unsigned int texname[3]; + /* texname[0] contains render to texture, texname[1] contains depth texture, texname[2] contains luminance texture + * texname[3] contains quartered render to texture, texname[4] contains quartered depth texture*/ + unsigned int texname[5]; int texturewidth; int textureheight; int canvaswidth; int canvasheight; int numberoffilters; + unsigned int fbo; /* bit 0: enable/disable depth texture * bit 1: enable/disable luminance texture*/ short texflag[MAX_RENDER_PASS]; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 122a738e4f3..ec5f4c4ac6d 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -297,6 +297,7 @@ bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time) m_last_frontface = true; glShadeModel(GL_SMOOTH); + glEnable(GL_MULTISAMPLE_ARB); m_2DCanvas->BeginFrame(); @@ -382,6 +383,7 @@ void RAS_OpenGLRasterizer::EndFrame() FlushDebugLines(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDisable(GL_MULTISAMPLE_ARB); m_2DCanvas->EndFrame(); } |