#ifndef CHUNK_HPP #define CHUNK_HPP #include "chunk.h" template Chunk::Chunk(const uint& uniqueKey, Scene::ObjectType objectType, const Eigen::Vector3d &offset) : IChunk(uniqueKey, objectType, offset) { m_currentContext = nullptr; m_contextAccessor = nullptr; } template Chunk::~Chunk() { typename IContextAccessor::ContextCollectionIterator itC(getContextAccessor()->getContexts()); while(itC.hasNext()) itC.next().value()->destroyAll(this); } template void Chunk::setContextAccessor(const IContextAccessor* accessor) { m_contextAccessor = (IContextAccessor*)accessor; } template IContextAccessor* Chunk::getContextAccessor() const { return m_contextAccessor; } template void Chunk::setCurrentContext(const RendererContextT* context) { if(m_currentContext == context) return; m_currentContext = (RendererContextT*)context; } template RendererContextT* Chunk::getCurrentContext() const { return m_currentContext; } template IGraphicsDocument* Chunk::getCurrentDocument() const { if(m_currentContext == nullptr) return nullptr; return m_currentContext->getDocument(); } template void Chunk::destroyGLForCurrentContext() { lock(); destroyGL(m_currentContext); unlock(); } template void Chunk::destroyGL(const QOpenGLContext* context) { lock(); RendererContextT* rc = getContextAccessor()->getContexts().value(const_cast(context), nullptr); destroyGL(rc); unlock(); } template void Chunk::destroyGL(RendererContextT* context) { lock(); IChunk::setUpdated(false); if(context == nullptr) return; setContextUpdated(context, false); context->destroyAll(this); unlock(); } template void Chunk::getSelectionColor(float sColor[]) { QColor sCol = Qt::red; if(getCurrentDocument() != nullptr) sCol = getCurrentDocument()->getSelectionColor(); sColor[0] = sCol.redF(); sColor[1] = sCol.greenF(); sColor[2] = sCol.blueF(); sColor[3] = sCol.alphaF(); } template void Chunk::setUpdated(bool status) { if(mustChangeUpdateStatus(status)) { IChunk::setUpdated(status); this->lock(); if(m_currentContext != nullptr) setContextUpdated(m_currentContext, status); if(status == false) { typename IContextAccessor::ContextCollectionIterator it(getContextAccessor()->getContexts()); while(it.hasNext()) setContextUpdated(it.next().value(), status); } this->unlock(); } } template void Chunk::setContextUpdated(RendererContextT* context, bool status) { Q_UNUSED(status) ChunkCustomUpdateValues* cuv = context->createOrGetChunkCustomUpdateValues(this); cuv->setUserValue("DrawModeToUse", (int)getDrawModeToUse()); } template bool Chunk::isUpdated() const { if(!IChunk::isUpdated()) return false; RendererContextT* context = getCurrentContext(); if(context != nullptr) { ChunkCustomUpdateValues* cuv = context->createOrGetChunkCustomUpdateValues(this); if(cuv->getUserValue("DrawModeToUse", (int)getDrawModeToUse()).toInt() != ((int)getDrawModeToUse())) return false; } return true; } #endif // CHUNK_HPP