ZIntPoint ZDvidInfo::getBlockIndex(double x, double y, double z) const { ZIntPoint blockIndex(-1, -1, -1); if (x < m_startCoordinates[0] || x >= m_startCoordinates[0] + m_stackSize[0]) { return blockIndex; } if (y < m_startCoordinates[1] || y >= m_startCoordinates[1] + m_stackSize[1]) { return blockIndex; } if (z < m_startCoordinates[2] || z >= m_startCoordinates[2] + m_stackSize[2]) { return blockIndex; } int pt[3]; pt[0] = iround(x); pt[1] = iround(y); pt[2] = iround(z); for (int i = 0; i < 3; ++i) { blockIndex[i] = (pt[i] - m_startCoordinates[i]) / m_blockSize[i] + m_startBlockIndex[i]; } return blockIndex; }
void UniformBlock::updateBinding() const { m_program->checkDirty(); glUniformBlockBinding(m_program->id(), blockIndex(), m_bindingIndex); }
ZIntPoint ZDvidInfo::getBlockIndex(int x, int y, int z) const { ZIntPoint blockIndex(-1, -1, -1); if (x < m_startCoordinates[0] || x >= m_startCoordinates[0] + m_stackSize[0]) { return blockIndex; } if (y < m_startCoordinates[1] || y >= m_startCoordinates[1] + m_stackSize[1]) { return blockIndex; } if (z < m_startCoordinates[2] || z >= m_startCoordinates[2] + m_stackSize[2]) { return blockIndex; } blockIndex.set( (x - m_startCoordinates[0]) / m_blockSize[0] + m_startBlockIndex[0], (y - m_startCoordinates[1]) / m_blockSize[1] + m_startBlockIndex[1], (z - m_startCoordinates[2]) / m_blockSize[2] + m_startBlockIndex[2]); #if 0 for (int i = 0; i < 3; ++i) { blockIndex[i] = (pt[i] - m_startCoordinates[i]) / m_blockSize[i] + m_startBlockIndex[i]; } #endif return blockIndex; }
TEST memory_blockIndex(){ int i = 4; int *p1 = &i; int *p2 = p1 + 5; int *p3 = blockIndex(p1, 5, sizeof(int)); ASSERT_EQ(p2, p3); PASS(); }
void Descriptor::commitVersion(uint64_t version) { auto index = blockIndex(version); auto mask = (0x1u << ((version - 1) % BITS_PER_BLOCK)); mDescriptor[index] |= mask; if (version == mBaseVersion + 1) { updateBaseVersion(); } }
void Descriptor::updateBaseVersion() { auto index = blockIndex(mBaseVersion + 1); // Process version blocks where all versions are marked as committed // Release the block and increase base version so that it is aligned to the next block for (; mDescriptor[index] == std::numeric_limits<BlockType>::max(); index = ((index + 1) % CAPACITY)) { mBaseVersion += ((mBaseVersion % BITS_PER_BLOCK != 0) ? (BITS_PER_BLOCK - (mBaseVersion % BITS_PER_BLOCK)) : BITS_PER_BLOCK); mDescriptor[index] = 0x0u; } // Process the version block where the versions are only partially marked as committed // Check the block bit by bit and increase base version until the first uncommitted version is encountered for (; (mDescriptor[index] & (0x1u << (mBaseVersion % BITS_PER_BLOCK))) != 0x0u; ++mBaseVersion) { } LOG_ASSERT(blockIndex(mBaseVersion + 1) == index, "Base version and block index do not match"); }
bool Descriptor::isCommitted(uint64_t version) const { if (version <= mBaseVersion) { return true; } if (version > mLastVersion) { return false; } auto index = blockIndex(version); auto mask = (0x1u << ((version - 1) % BITS_PER_BLOCK)); return (mDescriptor[index] & mask) != 0x0u; }
std::string UniformBlock::getName() const { if (m_identity.isName()) return m_identity.name(); GLint length = getActive(GL_UNIFORM_BLOCK_NAME_LENGTH); std::vector<char> name(length); glGetActiveUniformBlockName(m_program->id(), blockIndex(), length, nullptr, name.data()); return std::string(name.data(), length); }
void Descriptor::serialize(crossbow::buffer_writer& writer) const { if (mBaseVersion >= mLastVersion) { return; } auto startIndex = blockIndex(mBaseVersion + 1); auto endIndex = blockIndex(mLastVersion); auto descLen = ((endIndex < startIndex ? CAPACITY - startIndex + endIndex : endIndex - startIndex) + 1) * sizeof(BlockType); LOG_ASSERT(descLen == serializedLength(), "Sizes do not match"); if (!writer.canWrite(descLen)) { throw std::length_error("Output buffer too small for descriptor"); } if (endIndex < startIndex) { writer.write(&mDescriptor[startIndex], (CAPACITY - startIndex) * sizeof(BlockType)); startIndex = 0; } writer.write(&mDescriptor[startIndex], (endIndex - startIndex) * sizeof(BlockType)); auto mask = (0x1u << ((mLastVersion - 1) % BITS_PER_BLOCK)); auto endBlock = mDescriptor[endIndex] | mask; writer.write<BlockType>(endBlock); }
QModelIndex TextDocumentStructureModel::index(int row, int column, const QModelIndex &parentIndex) const { kDebug(32500) << "-------------------------- row:" << row << "column:"<<column << "index:"<<parentIndex<<m_textDocument; if (! m_textDocument) { return QModelIndex(); } if (! parentIndex.isValid()) { return createIndex(row, column, static_cast<quintptr>(0)); } Q_ASSERT(parentIndex.internalId() < uint(m_nodeDataTable.count())); const NodeData &nodeData = m_nodeDataTable.at(parentIndex.internalId()); // can be only frame for now Q_ASSERT(nodeData.type == NodeData::Frame); QTextFrame* parentFrame = nodeData.frame; int index = -1; int count = 0; for (QTextFrame::iterator iterator = parentFrame->begin(); !iterator.atEnd(); ++iterator) { if (count == row) { QTextFrame *frame = iterator.currentFrame(); if (frame) { index = frameIndex(frame); break; } else { QTextBlock block = iterator.currentBlock(); if (block.isValid()) { index = blockIndex(block); break; } } } ++count; } Q_ASSERT(index != -1); return createIndex(row, column, index); }
void addSplat(int textureIndex, const TextureSplat &splat) { if(blendings.empty()) return; BlendStorage &storage = blendings[textureIndex]; if(storage.weights.empty()) storage.weights.resize(size.x * size.y); int limitY = splat.size.y; int limitX = splat.size.x; if(limitX + splat.position.x >= size.x - 2) limitX = size.x - 2 - splat.position.x; if(limitY + splat.position.y >= size.y - 2) limitY = size.y - 2 - splat.position.y; for(int j = 0; j < limitY; ++j) for(int i = 0; i < limitX; ++i) { int positionX = splat.position.x + i; int positionY = j + splat.position.y; int position = positionY * size.x + positionX; if(positionX < 0 || positionX >= size.x) continue; if(positionY < 0 || positionX >= size.x) continue; int oldWeight = storage.weights[position]; int newWeight = splat.weights[j * splat.size.x + i]; if(newWeight < oldWeight) continue; VC2I blockIndex(positionX / (BLOCK_SIZE - 1), positionY / (BLOCK_SIZE - 1)); VC2I blockPosition(positionX - blockIndex.x * (BLOCK_SIZE - 1), positionY - blockIndex.y * (BLOCK_SIZE - 1)); //if(blockPosition.x < 0 || blockPosition.y < 0) // continue; //if(blockPosition.x >= blockAmount.x || blockPosition.y >= blockAmount.y) // continue; // Normalize old weights { int sum = 255 - newWeight; for(unsigned int k = 0; k < blendings.size(); ++k) { int original = blendings[k].weights[position]; blendings[k].weights[position] = sum * blendings[k].weights[position] / 255; if(original) setPixel(blockIndex, blockPosition, k, blendings[k].weights[position]); } int newSum = 0; for(unsigned int k = 0; k < blendings.size(); ++k) { if(int(k) != textureIndex) newSum += blendings[k].weights[position]; } int diff = sum - newSum; newWeight += diff; } storage.weights[position] = newWeight; setPixel(blockIndex, blockPosition, textureIndex, newWeight); } }
QString KCharSelectData::section(CharSelectData* charselect, uint16_t unicode) { return sectionName(sectionIndex(blockIndex(c))); }
QString KCharSelectData::block(CharSelectData* charselect, uint16_t unicode) { return blockName(blockIndex(c)); }
void UniformBlock::getActive(const GLenum pname, GLint * params) const { m_program->checkDirty(); glGetActiveUniformBlockiv(m_program->id(), blockIndex(), pname, params); }