diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-06-17 14:27:34 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-06-17 14:27:34 +0400 |
commit | 272a91f754fd215f2ad9b48ba80fe56ee0564d7a (patch) | |
tree | f34afc9fd09b6a2bbcacd0709190969d09dc748f /source/gameengine/Ketsji/BL_Texture.cpp | |
parent | c9d1924ea5575ae2a4ce2cc7fd16e63e6ef14d84 (diff) |
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
Diffstat (limited to 'source/gameengine/Ketsji/BL_Texture.cpp')
-rw-r--r-- | source/gameengine/Ketsji/BL_Texture.cpp | 161 |
1 files changed, 49 insertions, 112 deletions
diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index 687b1af957d..f24ef4322f0 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -1,19 +1,6 @@ // ------------------------------------ -#ifdef WIN32 -#include <windows.h> -#endif // WIN32 -#ifdef __APPLE__ -#define GL_GLEXT_LEGACY 1 -#include <OpenGL/gl.h> -#include <OpenGL/glu.h> -#else -#include <GL/gl.h> -/* #if defined(__sun__) && !defined(__sparc__) -#include <mesa/glu.h> -#else */ -#include <GL/glu.h> -/* #endif */ -#endif + +#include "GL/glew.h" #include <iostream> #include <map> @@ -30,15 +17,11 @@ #include "BLI_blenlib.h" #include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h" -#include "RAS_OpenGLRasterizer/ARB_multitexture.h" #include "RAS_ICanvas.h" #include "RAS_Rect.h" #include "KX_GameObject.h" - -using namespace bgl; - #define spit(x) std::cout << x << std::endl; #include "MEM_guardedalloc.h" @@ -220,9 +203,7 @@ void BL_Texture::InitNonPow2Tex(unsigned int *pix,int x,int y,bool mipmap) bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap) { -#ifdef GL_ARB_texture_cube_map - - if (!RAS_EXT_support._ARB_texture_cube_map) + if (!GLEW_ARB_texture_cube_map) { spit("cubemaps not supported"); mOk = false; @@ -312,9 +293,8 @@ bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap) glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); - #ifdef GL_VERSION_1_2 - glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE ); - #endif + if(GLEW_VERSION_1_2) + glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE ); if (needs_split) my_free_envmapdata(cubemap); @@ -326,13 +306,6 @@ bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap) mOk = IsValid(); return mOk; - -#else - - mOk = false; - return mOk; - -#endif//GL_ARB_texture_cube_map } bool BL_Texture::IsValid() @@ -362,58 +335,40 @@ int BL_Texture::GetMaxUnits() { GLint unit=0; -#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT) - if (!getenv("WITHOUT_GLEXT")) { - if(RAS_EXT_support._ARB_multitexture) { - glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &unit); - return (MAXTEX>=unit?unit:MAXTEX); - } + if(GLEW_ARB_multitexture) { + glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &unit); + return (MAXTEX>=unit?unit:MAXTEX); } -#endif + return 0; } void BL_Texture::ActivateFirst() { -#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT) - if (!getenv("WITHOUT_GLEXT")) { - if(RAS_EXT_support._ARB_multitexture) - bgl::blActiveTextureARB(GL_TEXTURE0_ARB); - } -#endif + if(GLEW_ARB_multitexture) + glActiveTextureARB(GL_TEXTURE0_ARB); } void BL_Texture::ActivateUnit(int unit) { -#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT) - if (!getenv("WITHOUT_GLEXT")) { - if(RAS_EXT_support._ARB_multitexture) - if(unit <= MAXTEX) - bgl::blActiveTextureARB(GL_TEXTURE0_ARB+unit); - } -#endif + if(GLEW_ARB_multitexture) + if(unit <= MAXTEX) + glActiveTextureARB(GL_TEXTURE0_ARB+unit); } void BL_Texture::DisableUnit() { -#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT) - if (!getenv("WITHOUT_GLEXT")) { - if(RAS_EXT_support._ARB_multitexture) - bgl::blActiveTextureARB(GL_TEXTURE0_ARB+mUnit); - } -#endif - + if(GLEW_ARB_multitexture) + glActiveTextureARB(GL_TEXTURE0_ARB+mUnit); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); - #ifdef GL_ARB_texture_cube_map - if(RAS_EXT_support._ARB_texture_cube_map && glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB)) + if(GLEW_ARB_texture_cube_map && glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB)) glDisable(GL_TEXTURE_CUBE_MAP_ARB); else - #endif { if (glIsEnabled(GL_TEXTURE_2D)) glDisable(GL_TEXTURE_2D); @@ -429,56 +384,45 @@ void BL_Texture::DisableUnit() void BL_Texture::DisableAllTextures() { -#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT) - if (!getenv("WITHOUT_GLEXT")) { - glDisable(GL_BLEND); - for(int i=0; i<MAXTEX; i++) { - if(RAS_EXT_support._ARB_multitexture) - bgl::blActiveTextureARB(GL_TEXTURE0_ARB+i); - - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glDisable(GL_TEXTURE_2D); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_R); - glDisable(GL_TEXTURE_GEN_Q); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - } - if(RAS_EXT_support._ARB_multitexture) - bgl::blActiveTextureARB(GL_TEXTURE0_ARB); + glDisable(GL_BLEND); + + for(int i=0; i<MAXTEX; i++) { + if(GLEW_ARB_multitexture) + glActiveTextureARB(GL_TEXTURE0_ARB+i); + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_GEN_R); + glDisable(GL_TEXTURE_GEN_Q); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); } -#endif + + if(GLEW_ARB_multitexture) + glActiveTextureARB(GL_TEXTURE0_ARB); } void BL_Texture::ActivateTexture() { -#if defined(GL_ARB_multitexture) && defined(WITH_GLEXT) - if (!getenv("WITHOUT_GLEXT")) { - if(RAS_EXT_support._ARB_multitexture) - bgl::blActiveTextureARB(GL_TEXTURE0_ARB+mUnit); + if(GLEW_ARB_multitexture) + glActiveTextureARB(GL_TEXTURE0_ARB+mUnit); -#ifdef GL_ARB_texture_cube_map - if (mType == GL_TEXTURE_CUBE_MAP_ARB && RAS_EXT_support._ARB_texture_cube_map) - { - glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, mTexture ); - glEnable(GL_TEXTURE_CUBE_MAP_ARB); - } else -#endif - { - - #ifdef GL_ARB_texture_cube_map - if(RAS_EXT_support._ARB_texture_cube_map ) - glDisable(GL_TEXTURE_CUBE_MAP_ARB); - #endif + if (mType == GL_TEXTURE_CUBE_MAP_ARB && GLEW_ARB_texture_cube_map) + { + glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, mTexture ); + glEnable(GL_TEXTURE_CUBE_MAP_ARB); + } + else { + if(GLEW_ARB_texture_cube_map ) + glDisable(GL_TEXTURE_CUBE_MAP_ARB); - glBindTexture( GL_TEXTURE_2D, mTexture ); - glEnable(GL_TEXTURE_2D); - } + glBindTexture( GL_TEXTURE_2D, mTexture ); + glEnable(GL_TEXTURE_2D); } -#endif } void BL_Texture::SetMapping(int mode) @@ -492,9 +436,8 @@ void BL_Texture::SetMapping(int mode) return; } -#ifdef GL_ARB_texture_cube_map if( mType == GL_TEXTURE_CUBE_MAP_ARB && - RAS_EXT_support._ARB_texture_cube_map && + GLEW_ARB_texture_cube_map && mode &USEREFL) { glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB ); @@ -508,7 +451,6 @@ void BL_Texture::SetMapping(int mode) return; } else -#endif { glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP ); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP ); @@ -523,11 +465,7 @@ void BL_Texture::SetMapping(int mode) void BL_Texture::setTexEnv(BL_Material *mat, bool modulate) { -#ifndef GL_ARB_texture_env_combine - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - return; -#else - if(modulate || !RAS_EXT_support._ARB_texture_env_combine){ + if(modulate || !GLEW_ARB_texture_env_combine){ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); return; } @@ -661,7 +599,6 @@ void BL_Texture::setTexEnv(BL_Material *mat, bool modulate) glTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.0); glEndList(); -#endif //!GL_ARB_texture_env_combine } int BL_Texture::GetPow2(int n) |