Ticket #2456: Tex_Part2_V2.patch

File Tex_Part2_V2.patch, 29.4 KB (added by IronNerd, 10 years ago)
  • source/graphics/tests/test_TextureConverter.h

     
    3838        m_VFS = CreateVfs(20*MiB);
    3939        TS_ASSERT_OK(m_VFS->Mount(L"", DataDir()/"mods"/"_test.tex", VFS_MOUNT_MUST_EXIST));
    4040        TS_ASSERT_OK(m_VFS->Mount(L"cache/", DataDir()/"_testcache"));
    41 
    42         tex_codec_register_all();
    4341    }
    4442
    4543    void tearDown()
    4644    {
    47         tex_codec_unregister_all();
    48 
    4945        m_VFS.reset();
    5046        DeleteDirectory(DataDir()/"_testcache");
    5147    }
  • source/graphics/tests/test_TextureManager.h

     
    4141        TS_ASSERT_OK(m_VFS->Mount(L"cache/", DataDir()/"_testcache"));
    4242
    4343        h_mgr_init();
    44         tex_codec_register_all();
    4544
    4645        CXeromyces::Startup();
    4746    }
     
    5049    {
    5150        CXeromyces::Terminate();
    5251
    53         tex_codec_unregister_all();
    5452        h_mgr_shutdown();
    5553
    5654        m_VFS.reset();
  • source/lib/res/graphics/tests/test_tex.h

     
    6464    }
    6565
    6666public:
    67 
    68     // this also covers BGR and orientation transforms.
    69     void DISABLED_test_encode_decode()  // disabled because it's completely broken
    70     {
    71         tex_codec_register_all();
    72 
    73         // for each codec
    74         const TexCodecVTbl* c = 0;
    75         for(;;)
    76         {
    77             c = tex_codec_next(c);
    78             if(!c)
    79                 break;
    80 
    81             // get an extension that this codec will support
    82             // (so that tex_encode uses this codec)
    83             wchar_t extension[30] = {'.'};
    84             wcscpy_s(extension+1, 29, c->name);
    85             // .. make sure the c->name hack worked
    86             const TexCodecVTbl* correct_c = 0;
    87             TS_ASSERT_OK(tex_codec_for_filename(extension, &correct_c));
    88             TS_ASSERT_EQUALS(c, correct_c);
    89 
    90             // for each test width/height combination
    91             const size_t widths [] = { 4, 5, 4, 256, 384 };
    92             const size_t heights[] = { 4, 4, 5, 256, 256 };
    93             for(size_t i = 0; i < ARRAY_SIZE(widths); i++)
    94             {
    95                 // for each bit depth
    96                 for(size_t bpp = 8; bpp <= 32; bpp += 8)
    97                 {
    98                     size_t flags = 0;
    99                     if(!wcscmp(extension, L".dds"))
    100                         flags |= (TEX_DXT&3);   // DXT3
    101                     if(bpp == 8)
    102                         flags |= TEX_GREY;
    103                     else if(bpp == 16)
    104                         continue; // not supported
    105                     else if(bpp == 32)
    106                         flags |= TEX_ALPHA;
    107 
    108                     // normal
    109                     generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);
    110                     // top-down
    111                     flags &= ~TEX_ORIENTATION; flags |= TEX_TOP_DOWN;
    112                     generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);
    113                     // bottom up
    114                     flags &= ~TEX_ORIENTATION; flags |= TEX_BOTTOM_UP;
    115                     generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);
    116 
    117                     flags &= ~TEX_ORIENTATION;
    118                     flags |= TEX_BGR;
    119 
    120                     // bgr, normal
    121                     generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);
    122                     // bgr, top-down
    123                     flags &= ~TEX_ORIENTATION; flags |= TEX_TOP_DOWN;
    124                     generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);
    125                     // bgr, bottom up
    126                     flags &= ~TEX_ORIENTATION; flags |= TEX_BOTTOM_UP;
    127                     generate_encode_decode_compare(widths[i], heights[i], flags, bpp, extension);
    128                 }   // for bpp
    129             }   // for width/height
    130         }    // foreach codec
    131 
    132         tex_codec_unregister_all();
    133     }
    134 
    13567    // have mipmaps be created for a test image; check resulting size and pixels
    13668    void test_mipmap_create()
    13769    {
     
    16496
    16597    void test_s3tc_decode()
    16698    {
    167         tex_codec_register_all();
    168 
    16999        const size_t w = 4, h = 4, bpp = 4;
    170100        const size_t size = w*h/2;
    171101        shared_ptr<u8> img(new u8[size], ArrayDeleter());
     
    187117
    188118        // compare img
    189119        TS_ASSERT_SAME_DATA(t.get_data(), expected, 48);
    190 
    191         // cleanup
    192         tex_codec_unregister_all();
    193120    }
    194121};
  • source/lib/tex/tex.cpp

     
    569569// but this is open to misuse.
    570570bool tex_is_known_extension(const VfsPath& pathname)
    571571{
    572     const TexCodecVTbl* dummy;
     572    const ITexCodec* dummy;
    573573    // found codec for it => known extension
    574574    const OsPath extension = pathname.Extension();
    575575    if(tex_codec_for_filename(extension, &dummy) == INFO::OK)
     
    704704// directly into the output buffer and makes for zero-copy IO.
    705705size_t tex_hdr_size(const VfsPath& filename)
    706706{
    707     const TexCodecVTbl* c;
     707    const ITexCodec* c;
    708708   
    709709    const OsPath extension = filename.Extension();
    710710    WARN_RETURN_STATUS_IF_ERR(tex_codec_for_filename(extension, &c));
     
    718718
    719719Status Tex::decode(const shared_ptr<u8>& Data, size_t DataSize)
    720720{
    721     const TexCodecVTbl* c;
     721    const ITexCodec* c;
    722722    RETURN_STATUS_IF_ERR(tex_codec_for_header(Data.get(), DataSize, &c));
    723723
    724724    // make sure the entire header is available
     
    762762    const size_t max_out_size = img_size()*4 + 256*KiB;
    763763    RETURN_STATUS_IF_ERR(da_alloc(da, max_out_size));
    764764
    765     const TexCodecVTbl* c;
     765    const ITexCodec* c;
    766766    WARN_RETURN_STATUS_IF_ERR(tex_codec_for_filename(extension, &c));
    767767
    768768    // encode into <da>
  • source/lib/tex/tex.h

     
    368368
    369369
    370370/**
    371  * Manually register codecs. must be called before first use of a
    372  * codec (e.g. loading a texture).
    373  *
    374  * This would normally be taken care of by TEX_CODEC_REGISTER, but
    375  * no longer works when building as a static library.
    376  * Workaround: hard-code a list of codecs in tex_codec.cpp and
    377  * call their registration functions.
    378  **/
    379 extern void tex_codec_register_all();
    380 
    381 /**
    382  * remove all codecs that have been registered.
    383  **/
    384 extern void tex_codec_unregister_all();
    385 
    386 /**
    387371 * special value for levels_to_skip: the callback will only be called
    388372 * for the base mipmap level (i.e. 100%)
    389373 **/
  • source/lib/tex/tex_bmp.cpp

     
    6060#define BI_RGB 0        // biCompression
    6161
    6262
    63 static Status bmp_transform(Tex* UNUSED(t), size_t UNUSED(transforms))
     63Status TexCodecBmp::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const
    6464{
    6565    return INFO::TEX_CODEC_CANNOT_HANDLE;
    6666}
    6767
    6868
    69 static bool bmp_is_hdr(const u8* file)
     69bool TexCodecBmp::is_hdr(const u8* file) const
    7070{
    7171    // check header signature (bfType == "BM"?).
    7272    // we compare single bytes to be endian-safe.
     
    7474}
    7575
    7676
    77 static bool bmp_is_ext(const OsPath& extension)
     77bool TexCodecBmp::is_ext(const OsPath& extension) const
    7878{
    7979    return extension == L".bmp";
    8080}
    8181
    8282
    83 static size_t bmp_hdr_size(const u8* file)
     83size_t TexCodecBmp::hdr_size(const u8* file) const
    8484{
    8585    const size_t hdr_size = sizeof(BmpHeader);
    8686    if(file)
     
    9595
    9696
    9797// requirements: uncompressed, direct colour, bottom up
    98 static Status bmp_decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t)
     98Status TexCodecBmp::decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) const
    9999{
    100100    const BmpHeader* hdr = (const BmpHeader*)data;
    101101    const long w       = (long)read_le32(&hdr->biWidth);
     
    124124}
    125125
    126126
    127 static Status bmp_encode(Tex* RESTRICT t, DynArray* RESTRICT da)
     127Status TexCodecBmp::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const
    128128{
    129129    const size_t hdr_size = sizeof(BmpHeader);  // needed for BITMAPFILEHEADER
    130130    const size_t img_size = t->img_size();
     
    155155    };
    156156    return tex_codec_write(t, transforms, &hdr, hdr_size, da);
    157157}
    158 
    159 TEX_CODEC_REGISTER(bmp);
  • source/lib/tex/tex_codec.cpp

     
    3333#include "lib/allocators/shared_ptr.h" // ArrayDeleter
    3434#include "tex.h"
    3535
    36 static const TexCodecVTbl* codecs;
     36// Statically allocate all of the codecs...
     37TexCodecDds DdsCodec;
     38TexCodecPng PngCodec;
     39TexCodecJpg JpgCodec;
     40TexCodecTga TgaCodec;
     41TexCodecPng BmpCodec;
     42// Codecs will be searched in this order
     43static const ITexCodec *codecs[] = {(ITexCodec *)&DdsCodec, (ITexCodec *)&PngCodec,
     44    (ITexCodec *)&JpgCodec, (ITexCodec *)&TgaCodec, (ITexCodec *)&BmpCodec};
     45static const int codecs_len = sizeof(codecs) / sizeof(ITexCodec*);
    3746
    38 // add this vtbl to the codec list. called at NLSO init time by the
    39 // TEX_CODEC_REGISTER in each codec file. note that call order and therefore
    40 // order in the list is undefined, but since each codec only steps up if it
    41 // can handle the given format, this is not a problem.
    42 //
    43 // returns int to alloc calling from a macro at file scope.
    44 int tex_codec_register(TexCodecVTbl* c)
    45 {
    46     ENSURE(c);
    47 
    48     // insert at front of list.
    49     c->next = codecs;
    50     codecs = c;
    51 
    52     return 0;   // (assigned to dummy variable)
    53 }
    54 
    55 // remove all codecs that have been registered.
    56 void tex_codec_unregister_all()
    57 {
    58     codecs = NULL;
    59 }
    60 
    6147// find codec that recognizes the desired output file extension,
    6248// or return ERR::TEX_UNKNOWN_FORMAT if unknown.
    6349// note: does not raise a warning because it is used by
    6450// tex_is_known_extension.
    65 Status tex_codec_for_filename(const OsPath& extension, const TexCodecVTbl** c)
     51Status tex_codec_for_filename(const OsPath& extension, const ITexCodec** c)
    6652{
    67     for(*c = codecs; *c; *c = (*c)->next)
     53    for(int i = 0; i < codecs_len; ++i)
    6854    {
    6955        // we found it
    70         if((*c)->is_ext(extension))
     56        if(codecs[i]->is_ext(extension)) {
     57            *c = codecs[i];
    7158            return INFO::OK;
     59        }
    7260    }
    7361
    7462    return ERR::TEX_UNKNOWN_FORMAT; // NOWARN
     
    7664
    7765
    7866// find codec that recognizes the header's magic field
    79 Status tex_codec_for_header(const u8* file, size_t file_size, const TexCodecVTbl** c)
     67Status tex_codec_for_header(const u8* file, size_t file_size, const ITexCodec** c)
    8068{
    8169    // we guarantee at least 4 bytes for is_hdr to look at
    8270    if(file_size < 4)
    8371        WARN_RETURN(ERR::TEX_INCOMPLETE_HEADER);
    84 
    85     for(*c = codecs; *c; *c = (*c)->next)
     72   
     73    for(int i = 0; i < codecs_len; ++i)
    8674    {
    8775        // we found it
    88         if((*c)->is_hdr(file))
     76        if(codecs[i]->is_hdr(file)) {
     77            *c = codecs[i];
    8978            return INFO::OK;
     79        }
    9080    }
    9181
    9282    WARN_RETURN(ERR::TEX_UNKNOWN_FORMAT);
    9383}
    9484
    95 
    96 const TexCodecVTbl* tex_codec_next(const TexCodecVTbl* prev_codec)
    97 {
    98     // first time
    99     if(!prev_codec)
    100         return codecs;
    101     // middle of list: return next (can be 0 to indicate end of list)
    102     else
    103         return prev_codec->next;
    104 }
    105 
    106 
    10785Status tex_codec_transform(Tex* t, size_t transforms)
    10886{
    10987    Status ret = INFO::TEX_CODEC_CANNOT_HANDLE;
    11088
    11189    // find codec that understands the data, and transform
    112     for(const TexCodecVTbl* c = codecs; c; c = c->next)
     90    for(int i = 0; i < codecs_len; ++i)
    11391    {
    114         Status err = c->transform(t, transforms);
     92        Status err = codecs[i]->transform(t, transforms);
    11593        // success
    11694        if(err == INFO::OK)
    11795            return INFO::OK;
     
    131109// helper functions used by codecs
    132110//-----------------------------------------------------------------------------
    133111
    134 void tex_codec_register_all()
    135 {
    136 #define REGISTER_CODEC(name) extern void name##_register(); name##_register()
    137     REGISTER_CODEC(bmp);
    138     REGISTER_CODEC(dds);
    139     REGISTER_CODEC(jpg);
    140     REGISTER_CODEC(png);
    141     REGISTER_CODEC(tga);
    142 #undef REGISTER_CODEC
    143 }
    144 
    145112// allocate an array of row pointers that point into the given texture data.
    146113// <file_orientation> indicates whether the file format is top-down or
    147114// bottom-up; the row array is inverted if necessary to match global
  • source/lib/tex/tex_codec.h

     
    3636 * 'template method'-style interface to increase code reuse and
    3737 * simplify writing new codecs.
    3838 **/
    39 struct TexCodecVTbl
     39class ITexCodec
    4040{
     41public:
    4142    /**
    4243     * decode the file into a Tex structure.
    4344     *
     
    4950     * @param t output texture object
    5051     * @return Status
    5152     **/
    52     Status (*decode)(u8* data, size_t size, Tex* RESTRICT t);
     53    virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const = 0;
    5354
    5455    /**
    5556     * encode the texture data into the codec's file format (in memory).
     
    6263     * by the caller.
    6364     * @return Status
    6465     **/
    65     Status (*encode)(Tex* RESTRICT t, DynArray* RESTRICT da);
     66    virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const = 0;
    6667
    6768    /**
    6869     * transform the texture's pixel format.
     
    7374     * to its format; generic pixel format transforms are handled by
    7475     * the caller.
    7576     **/
    76     Status (*transform)(Tex* t, size_t transforms);
     77    virtual Status transform(Tex* t, size_t transforms) const = 0;
    7778
    7879    /**
    7980     * indicate if the data appears to be an instance of this codec's header,
     
    8384     * (this should be enough to examine the header's 'magic' field)
    8485     * @return bool
    8586     **/
    86     bool (*is_hdr)(const u8* file);
     87    virtual bool is_hdr(const u8* file) const = 0;
    8788
    8889    /**
    8990     * is the extension that of a file format supported by this codec?
     
    9596     * @param extension (including '.')
    9697     * @return bool
    9798     **/
    98     bool (*is_ext)(const OsPath& extension);
     99    virtual bool is_ext(const OsPath& extension) const = 0;
    99100
    100101    /**
    101102     * return size of the file header supported by this codec.
     
    106107     * variable-length fields.
    107108     * @return size [bytes]
    108109     **/
    109     size_t (*hdr_size)(const u8* file);
     110    virtual size_t hdr_size(const u8* file) const = 0;
    110111
    111112    /**
    112113     * name of codec for debug purposes. typically set via TEX_CODEC_REGISTER.
    113114     **/
    114     const wchar_t* name;
     115    virtual const wchar_t* get_name() const = 0;
     116};
    115117
    116     /**
    117      * intrusive linked-list of codecs: more convenient than fixed-size
    118      * static storage.
    119      * set by caller; should be initialized to NULL.
    120      **/
    121     const TexCodecVTbl* next;
     118class TexCodecPng:ITexCodec {
     119public:
     120    virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const;
     121    virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const;
     122    virtual Status transform(Tex* t, size_t transforms) const;
     123    virtual bool is_hdr(const u8* file) const;
     124    virtual bool is_ext(const OsPath& extension) const;
     125    virtual size_t hdr_size(const u8* file) const;
     126    virtual const wchar_t* get_name() const {
     127        static const wchar_t *name = L"png";
     128        return name;
     129    };
    122130};
    123131
     132class TexCodecJpg:ITexCodec {
     133public:
     134    virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const;
     135    virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const;
     136    virtual Status transform(Tex* t, size_t transforms) const;
     137    virtual bool is_hdr(const u8* file) const;
     138    virtual bool is_ext(const OsPath& extension) const;
     139    virtual size_t hdr_size(const u8* file) const;
     140    virtual const wchar_t* get_name() const {
     141        static const wchar_t *name = L"jpg";
     142        return name;
     143    };
     144};
    124145
    125 /**
    126  * build codec vtbl and register it. the codec will be queried for future
    127  * texture load requests. call order is undefined, but since each codec
    128  * only steps up if it can handle the given format, this is not a problem.
    129  *
    130  * @param name identifier of codec (not string!). used to bind 'member'
    131  * functions prefixed with it to the vtbl, and as the TexCodecVTbl name.
    132  * it should also mirror the default file extension (e.g. dds) -
    133  * this is relied upon (but verified) in the self-test.
    134  *
    135  * usage: at file scope within the source file containing the codec's methods.
    136  **/
    137 #define TEX_CODEC_REGISTER(name)\
    138     static TexCodecVTbl UID__ = \
    139     {\
    140         name##_decode, name##_encode, name##_transform,\
    141         name##_is_hdr, name##_is_ext, name##_hdr_size,\
    142         WIDEN(#name)\
    143     };\
    144     /*static int dummy = tex_codec_register(&vtbl);*/\
    145     /* note: when building as a static library, pre-main initializers */\
    146     /* will not run! as a workaround, we build an externally visible */\
    147     /* registration function that must be called via */\
    148     /* tex_codec_register_all - see comments there. */\
    149     void name##_register() { tex_codec_register(&UID__); }
     146class TexCodecDds:ITexCodec {
     147public:
     148    virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const;
     149    virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const;
     150    virtual Status transform(Tex* t, size_t transforms) const;
     151    virtual bool is_hdr(const u8* file) const;
     152    virtual bool is_ext(const OsPath& extension) const;
     153    virtual size_t hdr_size(const u8* file) const;
     154    virtual const wchar_t* get_name() const {
     155        static const wchar_t *name = L"dds";
     156        return name;
     157    };
     158};
    150159
     160class TexCodecTga:ITexCodec {
     161public:
     162    virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const;
     163    virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const;
     164    virtual Status transform(Tex* t, size_t transforms) const;
     165    virtual bool is_hdr(const u8* file) const;
     166    virtual bool is_ext(const OsPath& extension) const;
     167    virtual size_t hdr_size(const u8* file) const;
     168    virtual const wchar_t* get_name() const {
     169        static const wchar_t *name = L"tga";
     170        return name;
     171    };
     172};
    151173
    152 /**
    153  * add this vtbl to the codec list. called at NLSO init time by the
    154  * TEX_CODEC_REGISTER in each codec file.
    155  * order in list is unspecified; see TEX_CODEC_REGISTER.
    156  *
    157  * @param c pointer to vtbl.
    158  * @return int (allows calling from a macro at file scope; value is not used)
    159  **/
    160 extern int tex_codec_register(TexCodecVTbl* c);
     174class TexCodecBmp:ITexCodec {
     175public:
     176    virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const;
     177    virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const;
     178    virtual Status transform(Tex* t, size_t transforms) const;
     179    virtual bool is_hdr(const u8* file) const;
     180    virtual bool is_ext(const OsPath& extension) const;
     181    virtual size_t hdr_size(const u8* file) const;
     182    virtual const wchar_t* get_name() const {
     183        static const wchar_t *name = L"bmp";
     184        return name;
     185    };
     186};
    161187
    162 
    163188/**
    164189 * Find codec that recognizes the desired output file extension.
    165190 *
     
    169194 * called by tex_is_known_extension) if no codec indicates they can
    170195 * handle the given extension.
    171196 **/
    172 extern Status tex_codec_for_filename(const OsPath& extension, const TexCodecVTbl** c);
     197extern Status tex_codec_for_filename(const OsPath& extension, const ITexCodec** c);
    173198
    174199/**
    175200 * find codec that recognizes the header's magic field.
     
    181206 * @return Status; ERR::RES_UNKNOWN_FORMAT if no codec indicates they can
    182207 * handle the given format (header).
    183208 **/
    184 extern Status tex_codec_for_header(const u8* data, size_t data_size, const TexCodecVTbl** c);
     209extern Status tex_codec_for_header(const u8* data, size_t data_size, const ITexCodec** c);
    185210
    186211/**
    187  * enumerate all registered codecs.
    188  *
    189  * used by self-test to test each one of them in turn.
    190  *
    191  * @param prev_codec the last codec returned by this function.
    192  * pass 0 the first time.
    193  * note: this routine is stateless and therefore reentrant.
    194  * @return the next codec, or 0 if all have been returned.
    195  **/
    196 extern const TexCodecVTbl* tex_codec_next(const TexCodecVTbl* prev_codec);
    197 
    198 /**
    199212 * transform the texture's pixel format.
    200213 * tries each codec's transform method once, or until one indicates success.
    201214 *
  • source/lib/tex/tex_dds.cpp

     
    586586
    587587//-----------------------------------------------------------------------------
    588588
    589 static bool dds_is_hdr(const u8* file)
     589bool TexCodecDds::is_hdr(const u8* file) const
    590590{
    591591    return *(u32*)file == FOURCC('D','D','S',' ');
    592592}
    593593
    594594
    595 static bool dds_is_ext(const OsPath& extension)
     595bool TexCodecDds::is_ext(const OsPath& extension) const
    596596{
    597597    return extension == L".dds";
    598598}
    599599
    600600
    601 static size_t dds_hdr_size(const u8* UNUSED(file))
     601size_t TexCodecDds::hdr_size(const u8* UNUSED(file)) const
    602602{
    603603    return 4+sizeof(DDS_HEADER);
    604604}
    605605
    606606
    607 static Status dds_decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t)
     607Status TexCodecDds::decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) const
    608608{
    609609    const DDS_HEADER* sd = (const DDS_HEADER*)(data+4);
    610610    RETURN_STATUS_IF_ERR(decode_sd(sd, t->m_Width, t->m_Height, t->m_Bpp, t->m_Flags));
     
    612612}
    613613
    614614
    615 static Status dds_encode(Tex* RESTRICT UNUSED(t), DynArray* RESTRICT UNUSED(da))
     615Status TexCodecDds::encode(Tex* RESTRICT UNUSED(t), DynArray* RESTRICT UNUSED(da)) const
    616616{
    617617    // note: do not return ERR::NOT_SUPPORTED et al. because that would
    618618    // break tex_write (which assumes either this, 0 or errors are returned).
     
    622622
    623623TIMER_ADD_CLIENT(tc_dds_transform);
    624624
    625 static Status dds_transform(Tex* t, size_t transforms)
     625Status TexCodecDds::transform(Tex* t, size_t transforms) const
    626626{
    627627    TIMER_ACCRUE(tc_dds_transform);
    628628
     
    651651    // both not DXT (nothing we can do) - bail.
    652652    return INFO::TEX_CODEC_CANNOT_HANDLE;
    653653}
    654 
    655 
    656 TEX_CODEC_REGISTER(dds);
  • source/lib/tex/tex_jpg.cpp

     
    423423//-----------------------------------------------------------------------------
    424424
    425425
    426 static Status jpg_transform(Tex* UNUSED(t), size_t UNUSED(transforms))
     426Status TexCodecJpg::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const
    427427{
    428428    return INFO::TEX_CODEC_CANNOT_HANDLE;
    429429}
     
    557557
    558558
    559559
    560 static bool jpg_is_hdr(const u8* file)
     560bool TexCodecJpg::is_hdr(const u8* file) const
    561561{
    562562    // JFIF requires SOI marker at start of stream.
    563563    // we compare single bytes to be endian-safe.
     
    565565}
    566566
    567567
    568 static bool jpg_is_ext(const OsPath& extension)
     568bool TexCodecJpg::is_ext(const OsPath& extension) const
    569569{
    570570    return extension == L".jpg" || extension == L".jpeg";
    571571}
    572572
    573573
    574 static size_t jpg_hdr_size(const u8* UNUSED(file))
     574size_t TexCodecJpg::hdr_size(const u8* UNUSED(file)) const
    575575{
    576576    return 0;   // libjpg returns decoded image data; no header
    577577}
    578578
    579579
    580 static Status jpg_decode(rpU8 data, size_t size, Tex* RESTRICT t)
     580Status TexCodecJpg::decode(rpU8 data, size_t size, Tex* RESTRICT t) const
    581581{
    582582    // contains the JPEG decompression parameters and pointers to
    583583    //  working space (allocated as needed by the JPEG library).
     
    598598
    599599
    600600// limitation: palette images aren't supported
    601 static Status jpg_encode(Tex* RESTRICT t, DynArray* RESTRICT da)
     601Status TexCodecJpg::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const
    602602{
    603603    // contains the JPEG compression parameters and pointers to
    604604    // working space (allocated as needed by the JPEG library).
     
    616616
    617617    return ret;
    618618}
    619 
    620 TEX_CODEC_REGISTER(jpg);
  • source/lib/tex/tex_png.cpp

     
    107107
    108108//-----------------------------------------------------------------------------
    109109
    110 static Status png_transform(Tex* UNUSED(t), size_t UNUSED(transforms))
     110Status TexCodecPng::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const
    111111{
    112112    return INFO::TEX_CODEC_CANNOT_HANDLE;
    113113}
     
    200200
    201201
    202202
    203 static bool png_is_hdr(const u8* file)
     203bool TexCodecPng::is_hdr(const u8* file) const
    204204{
    205205    // don't use png_sig_cmp, so we don't pull in libpng for
    206206    // this check alone (it might not actually be used).
     
    208208}
    209209
    210210
    211 static bool png_is_ext(const OsPath& extension)
     211bool TexCodecPng::is_ext(const OsPath& extension) const
    212212{
    213213    return extension == L".png";
    214214}
    215215
    216216
    217 static size_t png_hdr_size(const u8* UNUSED(file))
     217size_t TexCodecPng::hdr_size(const u8* UNUSED(file)) const
    218218{
    219219    return 0;   // libpng returns decoded image data; no header
    220220}
     
    223223TIMER_ADD_CLIENT(tc_png_decode);
    224224
    225225// limitation: palette images aren't supported
    226 static Status png_decode(rpU8 data, size_t size, Tex* RESTRICT t)
     226Status TexCodecPng::decode(rpU8 data, size_t size, Tex* RESTRICT t) const
    227227{
    228228TIMER_ACCRUE(tc_png_decode);
    229229
     
    257257
    258258
    259259// limitation: palette images aren't supported
    260 static Status png_encode(Tex* RESTRICT t, DynArray* RESTRICT da)
     260Status TexCodecPng::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const
    261261{
    262262    Status ret = ERR::FAIL;
    263263    png_infop info_ptr = 0;
     
    284284    png_destroy_write_struct(&png_ptr, &info_ptr);
    285285    return ret;
    286286}
    287 
    288 TEX_CODEC_REGISTER(png);
  • source/lib/tex/tex_tga.cpp

     
    6767#pragma pack(pop)
    6868
    6969
    70 static Status tga_transform(Tex* UNUSED(t), size_t UNUSED(transforms))
     70Status TexCodecTga::transform(Tex* UNUSED(t), size_t UNUSED(transforms)) const
    7171{
    7272    return INFO::TEX_CODEC_CANNOT_HANDLE;
    7373}
    7474
    7575
    76 static bool tga_is_hdr(const u8* file)
     76bool TexCodecTga::is_hdr(const u8* file) const
    7777{
    7878    TgaHeader* hdr = (TgaHeader*)file;
    7979
     
    9393}
    9494
    9595
    96 static bool tga_is_ext(const OsPath& extension)
     96bool TexCodecTga::is_ext(const OsPath& extension) const
    9797{
    9898    return extension == L".tga";
    9999}
    100100
    101101
    102 static size_t tga_hdr_size(const u8* file)
     102size_t TexCodecTga::hdr_size(const u8* file) const
    103103{
    104104    size_t hdr_size = sizeof(TgaHeader);
    105105    if(file)
     
    112112
    113113
    114114// requirements: uncompressed, direct color, bottom up
    115 static Status tga_decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t)
     115Status TexCodecTga::decode(rpU8 data, size_t UNUSED(size), Tex* RESTRICT t) const
    116116{
    117117    const TgaHeader* hdr = (const TgaHeader*)data;
    118118    const u8 type  = hdr->img_type;
     
    144144}
    145145
    146146
    147 static Status tga_encode(Tex* RESTRICT t, DynArray* RESTRICT da)
     147Status TexCodecTga::encode(Tex* RESTRICT t, DynArray* RESTRICT da) const
    148148{
    149149    u8 img_desc = 0;
    150150    if(t->m_Flags & TEX_TOP_DOWN)
     
    173173    return tex_codec_write(t, transforms, &hdr, hdr_size, da);
    174174}
    175175
    176 TEX_CODEC_REGISTER(tga);
  • source/network/tests/test_Net.h

     
    4444
    4545        // Need some stuff for terrain movement costs:
    4646        // (TODO: this ought to be independent of any graphics code)
    47         tex_codec_register_all();
    4847        new CTerrainTextureManager;
    4948        g_TexMan.LoadTerrainTextures();
    5049
     
    5655        enet_deinitialize();
    5756
    5857        delete &g_TexMan;
    59         tex_codec_unregister_all();
    6058
    6159        CXeromyces::Terminate();
    6260        g_VFS.reset();
  • source/ps/ArchiveBuilder.cpp

     
    3636CArchiveBuilder::CArchiveBuilder(const OsPath& mod, const OsPath& tempdir) :
    3737    m_TempDir(tempdir)
    3838{
    39     tex_codec_register_all();
    40 
    4139    m_VFS = CreateVfs(20*MiB);
    4240
    4341    DeleteDirectory(m_TempDir/"_archivecache"); // clean up in case the last run failed
     
    5553    m_VFS.reset();
    5654
    5755    DeleteDirectory(m_TempDir/"_archivecache");
    58 
    59     tex_codec_unregister_all();
    6056}
    6157
    6258void CArchiveBuilder::AddBaseMod(const OsPath& mod)
  • source/ps/GameSetup/GameSetup.cpp

     
    682682    g_VBMan.Shutdown();
    683683    TIMER_END(L"shutdown Renderer");
    684684
    685     tex_codec_unregister_all();
    686 
    687685    g_Profiler2.ShutdownGPU();
    688686
    689687    // Free cursors before shutting down SDL, as they may depend on SDL.
     
    936934
    937935    RunHardwareDetection();
    938936
    939     tex_codec_register_all();
    940 
    941937    const int quality = SANE_TEX_QUALITY_DEFAULT;   // TODO: set value from config file
    942938    SetTextureQuality(quality);
    943939
  • source/ps/Replay.cpp

     
    134134
    135135    // Need some stuff for terrain movement costs:
    136136    // (TODO: this ought to be independent of any graphics code)
    137     tex_codec_register_all();
    138137    new CTerrainTextureManager;
    139138    g_TexMan.LoadTerrainTextures();
    140139
     
    246245
    247246    // Clean up
    248247    delete &g_TexMan;
    249     tex_codec_unregister_all();
    250248
    251249    delete &g_Profiler;
    252250    delete &g_ProfileViewer;
  • source/simulation2/components/tests/test_Pathfinder.h

     
    4141
    4242        // Need some stuff for terrain movement costs:
    4343        // (TODO: this ought to be independent of any graphics code)
    44         tex_codec_register_all();
    4544        new CTerrainTextureManager;
    4645        g_TexMan.LoadTerrainTextures();
    4746    }
     
    4948    void tearDown()
    5049    {
    5150        delete &g_TexMan;
    52         tex_codec_unregister_all();
    5351
    5452        g_VFS.reset();
    5553
  • source/simulation2/tests/test_Serializer.h

     
    638638
    639639        // Need some stuff for terrain movement costs:
    640640        // (TODO: this ought to be independent of any graphics code)
    641         tex_codec_register_all();
    642641        new CTerrainTextureManager;
    643642        g_TexMan.LoadTerrainTextures();
    644643
     
    685684
    686685        // Shut down the world
    687686        delete &g_TexMan;
    688         tex_codec_unregister_all();
    689687        g_VFS.reset();
    690688        CXeromyces::Terminate();
    691689    }