using Resource = union {Image, CubeTexture, VolumeTexture } // обычный Variant из 3х типовusing ImageDocument: QVector<QVector<Resource>>;// reading:auto doc = readFromFile();for (int i = 0; i < doc.imageCount(); ++i) { auto res = doc.resource(i, /*level*/ 0); switch (res.type) { .... }}// writing:auto imageCount = 10;Document doc(imageCount, Resource::Type::Image);for (int i = 0; i < imageCount; ++i) { doc.setResource(i, 0, Resource(QImage(...))); // тту выдаем ошибку если пытаемся засунунть ресурс не того типа.}
using ImageDocument: QVector<QVector<{Image, CubeTexture, VolumeTexture}>>;// reading:auto doc = readFromFile();if (doc.type() == Type::CubeTexture) { for (int i = 0; i < doc.imageCount(); ++i) { auto res = doc.resource(i, /*level*/ 0); auto texture = doc.cubeTexture(i, 0); } }}// запись то же самое, doc.setCubeTexture(i, 0);
template<class T>using Mipmaps = QVector<T>; // тут, на самом деле, целый класс-обертка со своими методами (int mipmapCount(), T mimpap(int index), QSize size(int index))using ImageMipmaps = Mimpaps<Image>;using CubeTextureMipmap = Mimpaps<CubeTexture>;using VolumeTextureMipmap = Mimpaps<VolumeTexture>;using ImageDocument = union { QImage, QVector<QImage>, ImageMipmaps, QVector<ImageMipmaps>, CubeTexture, QVector<CubeTexture>, ... } // Variant для 3*2*2 = 12 типов// readingauto doc = readFromFile();if (doc.type() & Type::VolumeTexture) { if (doc.type() & Type::Mipmaps) { auto texture = doc.toVolumeTextureMipmaps().mipmap(0); } else { auto texture = doc.toVolumeTexture(); }}
C++ (Qt)QImage i1 = ...;QImage i2 = ...; Image img;img.addFrame( i1 );img.addFrame( i2 ); ImageDocument doc;doc.addImage( img ); // --------------------- ImageDocument doc = readFromFile();for( auto img : doc ){ qDebug() << img.frames(); QImage i = img[ 0 ];}
QImage i1 = ...;CubeTexture i2 = ...; Image img;img.addFrame( i1 );img.addFrame( i2 );...
class VolumeTexture{public: VolumeTexture(); VolumeTexture(int width, int heigth, int depth = 1); QImage slice(int index); // returns QImage(width, height) void setSlice(int index, const QImage &image);};
class CubeTexture{public: CubeTexture(); CubeTexture(int size); enum Side { PositiveX = 0x1, NegativeX = 0x2, PositiveY = 0x3, NegativeY = 0x4, PositiveZ = 0x5, NegativeZ = 0x6, }; QImage side(Side side); // returns QImage(size, size) void setSide(Side side, const QImage &image);};
For Each Mipmap (Smallest to Largest) For Each Frame (First to Last) QImage OR CubeTexture OR VolumeTexture
C++ (Qt)struct CImageDoc { int GetNumFrames( void ) const; // { return impl->GetNumFrames(); } int GetNumMips( void ) const; CImageDoc * GetParent( void ); // может и это ... ...// data CImpl * impl;};