diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2012-06-30 08:34:34 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2012-06-30 08:34:34 +0400 |
commit | 436f02ab9cdf58d8b68f124be0d974a5de0d9308 (patch) | |
tree | 55394116b8e2a7c84899e389acda1e725c61a744 /source/gameengine/Ketsji | |
parent | 2d7efed014539e5b7193f9a73ccfa61ea3ed0838 (diff) |
Finally committing support for compressed textures on the GPU (DDS+DXT). This patch started out as a patch by me, then cleaned up by Kupoman during his work on Cucumber.
One important thing to keep in mind when using this feature is that you'll need to flip your textures vertically (both the GIMP and Photoshop DDS tools I've seen have support for this on export). This is a quirk in using a texture format originally made for DirectX/DirectDraw, and flipping the compressed data is a real headache. Another quick fix for this issue is to change the Y value for the Size in the Mapping panel in the Texture properties to -1 (default is 1).
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/BL_Texture.cpp | 28 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Texture.h | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/CMakeLists.txt | 4 |
3 files changed, 33 insertions, 0 deletions
diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index 576da0d3f40..19247664dfa 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -144,7 +144,15 @@ bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap) mNeedsDeleted = 1; glGenTextures(1, (GLuint*)&mTexture); + +#ifdef WITH_DDS + if (ibuf->ftype & DDS) + InitGLCompressedTex(ibuf, mipmap); + else + InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap); +#else InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap); +#endif // track created units BL_TextureObject obj; @@ -183,6 +191,26 @@ void BL_Texture::InitGLTex(unsigned int *pix,int x,int y,bool mipmap) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } +void BL_Texture::InitGLCompressedTex(ImBuf* ibuf, bool mipmap) +{ +#ifndef WITH_DDS + // Fall back to uncompressed if DDS isn't enabled + InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap); + return; +#else + glBindTexture(GL_TEXTURE_2D, mTexture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + + if (GPU_upload_dxt_texture(ibuf) == 0) { + InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap); + return; + } +#endif +} void BL_Texture::InitNonPow2Tex(unsigned int *pix,int x,int y,bool mipmap) { diff --git a/source/gameengine/Ketsji/BL_Texture.h b/source/gameengine/Ketsji/BL_Texture.h index 2673be2bc42..a6bd354d260 100644 --- a/source/gameengine/Ketsji/BL_Texture.h +++ b/source/gameengine/Ketsji/BL_Texture.h @@ -35,6 +35,7 @@ private: void InitNonPow2Tex(unsigned int *p,int x,int y,bool mipmap ); void InitGLTex(unsigned int *p,int x,int y,bool mipmap ); + void InitGLCompressedTex(struct ImBuf *p, bool mipmap); public: BL_Texture(); ~BL_Texture( ); diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index c7f54838c10..4b3426e0784 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -221,6 +221,10 @@ set(SRC add_definitions(-DGLEW_STATIC) +if(WITH_IMAGE_DDS) + add_definitions(-DWITH_DDS) +endif() + if(WITH_SDL) list(APPEND INC_SYS ${SDL_INCLUDE_DIR} |