Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Functions
compressedtex.cpp File Reference

compressed texture (mostly dds) loading. More...

#include <SDL_opengl.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include "inexor/engine/rendergl.hpp"
#include "inexor/io/Logging.hpp"
#include "inexor/io/legacy/stream.hpp"
#include "inexor/network/SharedVar.hpp"
#include "inexor/shared/command.hpp"
#include "inexor/shared/cube_endian.hpp"
#include "inexor/shared/cube_loops.hpp"
#include "inexor/shared/geom.hpp"
#include "inexor/shared/tools.hpp"
#include "inexor/texture/compressedtex.hpp"
#include "inexor/texture/image.hpp"

Macros

#define DECODEDDS(name, dbpp, initblock, writeval, nextval)
 

Functions

 VAR (dbgdds, 0, 0, 1)
 
 DECODEDDS (decodedxt1, s.compressed==GL_COMPRESSED_RGBA_S3TC_DXT1_EXT?4:3, ushort color0=lilswap(*(const ushort *) src);ushort color1=lilswap(*(const ushort *)&src[2]);uint bits=lilswap(*(const uint *)&src[4]);bvec4 rgba[4];rgba[0]=bvec4(bvec::from565(color0), 0xFF);rgba[1]=bvec4(bvec::from565(color1), 0xFF);if(color0 > color1){rgba[2].lerp(rgba[0], rgba[1], 2, 1, 3);rgba[3].lerp(rgba[0], rgba[1], 1, 2, 3);}else{rgba[2].lerp(rgba[0], rgba[1], 1, 1, 2);rgba[3]=bvec4(0, 0, 0, 0);}, memcpy(dst, rgba[bits &3].v, d.bpp);, bits >>=2;)
 
 DECODEDDS (decodedxt3, 4, ullong alpha=lilswap(*(const ullong *) src);ushort color0=lilswap(*(const ushort *)&src[8]);ushort color1=lilswap(*(const ushort *)&src[10]);uint bits=lilswap(*(const uint *)&src[12]);bvec rgb[4];rgb[0]=bvec::from565(color0);rgb[1]=bvec::from565(color1);rgb[2].lerp(rgb[0], rgb[1], 2, 1, 3);rgb[3].lerp(rgb[0], rgb[1], 1, 2, 3);, memcpy(dst, rgb[bits &3].v, 3);dst[3]=((alpha &0xF)*1088+32) >> 6;, bits >>=2;alpha >>=4;)
 
static void decodealpha (uchar alpha0, uchar alpha1, uchar alpha[8])
 
 DECODEDDS (decodedxt5, 4, uchar alpha[8];decodealpha(src[0], src[1], alpha);ullong alphabits=lilswap(*(const ushort *)&src[2])+((ullong) lilswap(*(const uint *)&src[4])<< 16);ushort color0=lilswap(*(const ushort *)&src[8]);ushort color1=lilswap(*(const ushort *)&src[10]);uint bits=lilswap(*(const uint *)&src[12]);bvec rgb[4];rgb[0]=bvec::from565(color0);rgb[1]=bvec::from565(color1);rgb[2].lerp(rgb[0], rgb[1], 2, 1, 3);rgb[3].lerp(rgb[0], rgb[1], 1, 2, 3);, memcpy(dst, rgb[bits &3].v, 3);dst[3]=alpha[alphabits &7];, bits >>=2;alphabits >>=3;)
 
bool loaddds (const char *filename, ImageData &image, int force)
 

Detailed Description

compressed texture (mostly dds) loading.

Macro Definition Documentation

#define DECODEDDS (   name,
  dbpp,
  initblock,
  writeval,
  nextval 
)
Value:
static void name(ImageData &s) \
{ \
ImageData d(s.w, s.h, dbpp); \
uchar *dst = d.data; \
const uchar *src = s.data; \
for(int by = 0; by < s.h; by += s.align) \
{ \
for(int bx = 0; bx < s.w; bx += s.align, src += s.bpp) \
{ \
int maxy = min(d.h - by, s.align), maxx = min(d.w - bx, s.align); \
initblock; \
loop(y, maxy) \
{ \
int x; \
for(x = 0; x < maxx; ++x) \
{ \
writeval; \
nextval; \
dst += d.bpp; \
} \
for(; x < s.align; ++x) { nextval; } \
dst += d.pitch - maxx*d.bpp; \
} \
dst += maxx*d.bpp - maxy*d.pitch; \
} \
dst += (s.align-1)*d.pitch; \
} \
s.replace(d); \
}
#define loop(v, m)
Legacy file defining loops.
Definition: cube_loops.hpp:7
Structure holding the Raw Pixel Data and minimum image info.
Definition: image.hpp:20
const T & min(const inexor::rpc::SharedVar< T > &a, const T &b)
Definition: SharedVar.hpp:210
int d
Definition: octaedit.cpp:1749
unsigned char uchar
Basic type definitions.
Definition: cube_types.hpp:7

Function Documentation

static void decodealpha ( uchar  alpha0,
uchar  alpha1,
uchar  alpha[8] 
)
inlinestatic
DECODEDDS ( decodedxt1  ,
s.  compressed = =GL_COMPRESSED_RGBA_S3TC_DXT1_EXT?4:3,
ushort  color0 = lilswap(*(const ushort *) src);ushort color1=lilswap(*(const ushort *)&src[2]);uint bits=lilswap(*(const uint *)&src[4]);bvec4 rgba[4];rgba[0]=bvec4(bvec::from565(color0), 0xFF);rgba[1]=bvec4(bvec::from565(color1), 0xFF);if(color0 > color1){rgba[2].lerp(rgba[0], rgba[1], 2, 1, 3);rgba[3].lerp(rgba[0], rgba[1], 1, 2, 3);}else{rgba[2].lerp(rgba[0], rgba[1], 1, 1, 2);rgba[3]=bvec4(0, 0, 0, 0);},
memcpy(dst, rgba[bits &3].v, d.bpp);  ,
bits >>  = 2; 
)
DECODEDDS ( decodedxt3  ,
,
ullong  alpha = lilswap(*(const ullong *) src);ushort color0=lilswap(*(const ushort *)&src[8]);ushort color1=lilswap(*(const ushort *)&src[10]);uint bits=lilswap(*(const uint *)&src[12]);bvec rgb[4];rgb[0]=bvec::from565(color0);rgb[1]=bvec::from565(color1);rgb[2].lerp(rgb[0], rgb[1], 2, 1, 3);rgb[3].lerp(rgb[0], rgb[1], 1, 2, 3);,
memcpy(dst, rgb[bits &3].v, 3);  dst[3] = ((alpha &0xF)*1088+32) >> 6;,
bits >>  = 2;alpha >>=4; 
)
DECODEDDS ( decodedxt5  ,
,
uchar alpha;decodealpha(src[0], src[1], alpha);ullong  alphabits[8] = lilswap(*(const ushort *)&src[2])+((ullonglilswap(*(const uint *)&src[4])<< 16);ushort color0=lilswap(*(const ushort *)&src[8]);ushort color1=lilswap(*(const ushort *)&src[10]);uint bits=lilswap(*(const uint *)&src[12]);bvec rgb[4];rgb[0]=bvec::from565(color0);rgb[1]=bvec::from565(color1);rgb[2].lerp(rgb[0], rgb[1], 2, 1, 3);rgb[3].lerp(rgb[0], rgb[1], 1, 2, 3);,
memcpy(dst, rgb[bits &3].v, 3);  dst[3] = alpha[alphabits &7];,
bits >>  = 2;alphabits >>=3; 
)
bool loaddds ( const char *  filename,
ImageData image,
int  force 
)
VAR ( dbgdds  ,
,
,
 
)