Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Stokes <mogurijin@gmail.com>2012-06-30 08:34:34 +0400
committerMitchell Stokes <mogurijin@gmail.com>2012-06-30 08:34:34 +0400
commit436f02ab9cdf58d8b68f124be0d974a5de0d9308 (patch)
tree55394116b8e2a7c84899e389acda1e725c61a744 /source/blender/imbuf
parent2d7efed014539e5b7193f9a73ccfa61ea3ed0838 (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/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_imbuf_types.h32
-rw-r--r--source/blender/imbuf/intern/allocimbuf.c2
-rw-r--r--source/blender/imbuf/intern/dds/DirectDrawSurface.cpp27
-rw-r--r--source/blender/imbuf/intern/dds/DirectDrawSurface.h2
-rw-r--r--source/blender/imbuf/intern/dds/dds_api.cpp12
5 files changed, 74 insertions, 1 deletions
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 2cb1dfe149a..dcb5cdd7d32 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -50,6 +50,13 @@ struct ImMetaData;
#define IB_MIPMAP_LEVELS 20
#define IB_FILENAME_SIZE 1024
+typedef struct DDSData {
+ unsigned int fourcc; /* DDS fourcc info */
+ unsigned int nummipmaps; /* The number of mipmaps in the dds file */
+ unsigned char *data; /* The compressed image data */
+ unsigned int size; /* The size of the compressed data */
+} DDSData;
+
/**
* \ingroup imbuf
* This is the abstraction of an image. ImBuf is the basic type used for all
@@ -119,6 +126,9 @@ typedef struct ImBuf {
unsigned char *encodedbuffer; /* Compressed image only used with png currently */
unsigned int encodedsize; /* Size of data written to encodedbuffer */
unsigned int encodedbuffersize; /* Size of encodedbuffer */
+
+ /* information for compressed textures */
+ struct DDSData dds_data;
} ImBuf;
/* Moved from BKE_bmfont_types.h because it is a userflag bit mask. */
@@ -215,6 +225,28 @@ typedef struct ImBuf {
#define IB_PROFILE_SRGB 2
#define IB_PROFILE_CUSTOM 3
+/* dds */
+#ifdef WITH_DDS
+#ifndef MAKEFOURCC
+#define MAKEFOURCC(ch0, ch1, ch2, ch3)\
+ ((unsigned long)(unsigned char)(ch0) | \
+ ((unsigned long)(unsigned char)(ch1) << 8) | \
+ ((unsigned long)(unsigned char)(ch2) << 16) | \
+ ((unsigned long)(unsigned char)(ch3) << 24))
+#endif //MAKEFOURCC
+
+/*
+ * FOURCC codes for DX compressed-texture pixel formats
+ */
+
+#define FOURCC_DDS (MAKEFOURCC('D','D','S',' '))
+#define FOURCC_DXT1 (MAKEFOURCC('D','X','T','1'))
+#define FOURCC_DXT2 (MAKEFOURCC('D','X','T','2'))
+#define FOURCC_DXT3 (MAKEFOURCC('D','X','T','3'))
+#define FOURCC_DXT4 (MAKEFOURCC('D','X','T','4'))
+#define FOURCC_DXT5 (MAKEFOURCC('D','X','T','5'))
+
+#endif // DDS
extern const char *imb_ext_image[];
extern const char *imb_ext_image_qt[];
extern const char *imb_ext_movie[];
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index 5dff3e1aea0..68a094c26d0 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -162,6 +162,8 @@ void IMB_freeImBuf(ImBuf *ibuf)
IMB_freezbuffloatImBuf(ibuf);
freeencodedbufferImBuf(ibuf);
IMB_metadata_free(ibuf);
+ if (ibuf->dds_data.data != NULL)
+ free(ibuf->dds_data.data); /* dds_data.data is allocated by DirectDrawSurface::readData(), so don't use MEM_freeN! */
MEM_freeN(ibuf);
}
}
diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
index 438988fbe48..82f355e1bb2 100644
--- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
+++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp
@@ -1016,6 +1016,10 @@ uint DirectDrawSurface::mipmapCount() const
else return 1;
}
+uint DirectDrawSurface::fourCC() const
+{
+ return header.pf.fourcc;
+}
uint DirectDrawSurface::width() const
{
@@ -1131,6 +1135,29 @@ void DirectDrawSurface::mipmap(Image * img, uint face, uint mipmap)
}
}
+// It was easier to copy this function from upstream than to resync.
+// This should be removed if a resync ever occurs.
+void* DirectDrawSurface::readData(uint &rsize)
+{
+ uint header_size = 128; // sizeof(DDSHeader);
+ if (header.hasDX10Header())
+ {
+ header_size += 20; // sizeof(DDSHeader10);
+ }
+
+ uint size = stream.size - header_size;
+ rsize = size;
+
+ unsigned char *data = new unsigned char[size];
+
+ stream.seek(header_size);
+ mem_read(stream, data, size);
+
+ // Maybe check if size == rsize? assert() isn't in this scope...
+
+ return data;
+}
+
void DirectDrawSurface::readLinearImage(Image * img)
{
diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.h b/source/blender/imbuf/intern/dds/DirectDrawSurface.h
index ddae8826620..a851533b1f3 100644
--- a/source/blender/imbuf/intern/dds/DirectDrawSurface.h
+++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.h
@@ -158,6 +158,7 @@ public:
bool hasAlpha() const;
uint mipmapCount() const;
+ uint fourCC() const;
uint width() const;
uint height() const;
uint depth() const;
@@ -171,6 +172,7 @@ public:
void setUserVersion(int version);
void mipmap(Image * img, uint f, uint m);
+ void* readData(uint &size);
// void mipmap(FloatImage * img, uint f, uint m);
void printInfo() const;
diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp
index 071d94c2076..fba326f7865 100644
--- a/source/blender/imbuf/intern/dds/dds_api.cpp
+++ b/source/blender/imbuf/intern/dds/dds_api.cpp
@@ -123,6 +123,8 @@ struct ImBuf *imb_load_dds(unsigned char *mem, size_t size, int flags)
ibuf->ftype = DDS;
ibuf->profile = IB_PROFILE_SRGB;
+ ibuf->dds_data.fourcc = dds.fourCC();
+ ibuf->dds_data.nummipmaps = dds.mipmapCount();
if ((flags & IB_test) == 0) {
if (!imb_addrectImBuf(ibuf)) return(ibuf);
@@ -136,10 +138,18 @@ struct ImBuf *imb_load_dds(unsigned char *mem, size_t size, int flags)
cp[0] = pixel.r; /* set R component of col */
cp[1] = pixel.g; /* set G component of col */
cp[2] = pixel.b; /* set B component of col */
- if (bits_per_pixel == 32)
+ if (dds.hasAlpha())
cp[3] = pixel.a; /* set A component of col */
rect[i] = col;
}
+
+ if (ibuf->dds_data.fourcc != FOURCC_DDS)
+ ibuf->dds_data.data = (unsigned char*)dds.readData(ibuf->dds_data.size);
+ else {
+ ibuf->dds_data.data = NULL;
+ ibuf->dds_data.size = 0;
+ }
+
IMB_flipy(ibuf);
}