void StereoManager::updateAllDependentRenderTargets(bool isLeftEye) { Ogre::uint32 mask; if(isLeftEye) { mask = left_mask_; } else { mask = right_mask_; } RenderTargetList::iterator itarg, itargend; itargend = rendertarget_list_.end(); for( itarg = rendertarget_list_.begin(); itarg != itargend; ++itarg ) { Ogre::RenderTarget *rt = itarg->first; int n = rt->getNumViewports(); std::vector<int> maskVector(n); // VS2005 gives a warning if I declare the vector as uint32 but not with int for(int i = 0; i<n ; ++i) { maskVector[i] = rt->getViewport(i)->getVisibilityMask(); rt->getViewport(i)->setVisibilityMask(maskVector[i] & mask); } rt->update(); for(int i = 0; i<n ; ++i) { rt->getViewport(i)->setVisibilityMask(maskVector[i]); } } }
QByteArray U2BitCompression::compress(const char* text, int len, int alphabetSize, const int* alphabetCharNums, U2OpStatus& os) { // algorithm: // 1. compute chars freq -> derive number of bits per char // 2. assign bit masks per char. Do not assign any bit masks for non used alphabet chars // 3. compress chars // 4. create header with used char mask // Result bits [len type][len][used alpha bits][compressed text] // where [len type] is a type of length field: 00 -> empty, 01 -> 8 byte, 10 -> 16 bytes, 11 -> 32 bytes // [len] - length of the result sequence // [used alpha bits] bit is set if alpha char is used in the text. // [compressed text] the data in compressed form assert(alphabetSize <= 32); //avoid this check in runtime -> use this method correctly // find all used chars in text QVector<bool> visitVector(alphabetSize, false); bool* visited = visitVector.data(); for (int i = 0; i < len; i++) { uchar c = text[i]; int n = alphabetCharNums[c]; if (n == -1) { os.setError(tr("Bit compression: illegal character in text '%1'").arg(char(c))); return QByteArray(); } if (!visited[n]) { visited[n] = true; } } // assign sequential bit-mask for all used chars QVector<uchar> maskVector(alphabetSize, 0); uchar* mask = maskVector.data(); uchar m = 0; for (int i = 0; i < alphabetSize; i++) { if (visited[i]) { mask[i] = m; m++; } } // store header and data to bit set int bitsPerChar = U2Bits::getNumberOfBitsPerChar(m); int compressedBitSize = len * bitsPerChar; int lenBits = getLenBitsSize(len); int headerSizeBits = 2 + lenBits + alphabetSize; int resultSizeBits = headerSizeBits + compressedBitSize; static QByteArray res; QByteArray bitSet = U2Bits::allocateBits(resultSizeBits); uchar* bits = (uchar*)bitSet.data(); writeLength(bits, len, lenBits); int pos = 2 + lenBits; for (; pos < alphabetSize; pos++) { if (visited[pos]) { U2Bits::setBit(bits, pos); } } for (int i = 0; i < len; i++, pos+=bitsPerChar) { uchar c = text[i]; int n = alphabetCharNums[c]; uchar m = mask[n]; U2Bits::setBits(bits, pos, &m, bitsPerChar); } return bitSet; }