void setRenderSystem(Ogre::RenderSystem* _render) { // отписываемся if (mRenderSystem != nullptr) { mRenderSystem->removeListener(this); mRenderSystem = nullptr; } mRenderSystem = _render; // подписываемся на рендер евент if (mRenderSystem != nullptr) { mRenderSystem->addListener(this); // формат цвета в вершинах Ogre::VertexElementType vertex_type = mRenderSystem->getColourVertexElementType(); if (vertex_type == Ogre::VET_COLOUR_ARGB) mVertexFormat = VertexColourType::ColourARGB; else if (vertex_type == Ogre::VET_COLOUR_ABGR) mVertexFormat = VertexColourType::ColourABGR; updateRenderInfo(); } }
//------------------------------------------------------------------------------------------------ void DebugLines::draw() { if (_lines.empty()) { mRenderOp.vertexData->vertexCount = 0; return; } // Initialization stuff mRenderOp.vertexData->vertexCount = _lines.size() * 2; Ogre::VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration; Ogre::VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding; if (_vbuf.isNull()) { decl->addElement(0, 0, VET_FLOAT3, VES_POSITION); decl->addElement(0, 12, VET_COLOUR, VES_DIFFUSE); _vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(0), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); bind->setBinding(0, _vbuf); } else { if (_vbuf->getNumVertices() != mRenderOp.vertexData->vertexCount) { bind->unsetAllBindings(); _vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(0), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE); bind->setBinding(0, _vbuf); } } // Drawing stuff unsigned int size = (unsigned int)_lines.size(); Ogre::Vector3 vaabMin = _lines[0]._start; Ogre::Vector3 vaabMax = _lines[0]._start; float *prPos = static_cast<float*>(_vbuf->lock(HardwareBuffer::HBL_DISCARD)); Ogre::RenderSystem* rs = Root::getSingleton().getRenderSystem(); Ogre::VertexElementType vet = VET_COLOUR_ARGB; if (rs) vet = rs->getColourVertexElementType(); for(unsigned int i = 0; i < size; i++) { const DebugLine& line = _lines[i]; uint32 packedColor; if (vet == VET_COLOUR_ARGB) packedColor = line._color.getAsARGB(); else packedColor = line._color.getAsABGR(); *prPos++ = line._start.x; *prPos++ = line._start.y; *prPos++ = line._start.z; *((uint32*)prPos) = packedColor; prPos++; *prPos++ = line._end.x; *prPos++ = line._end.y; *prPos++ = line._end.z; *((uint32*)prPos) = packedColor; prPos++; if (line._start.x < vaabMin.x) vaabMin.x = line._start.x; else if (line._start.x > vaabMax.x) vaabMax.x = line._start.x; if (line._start.y < vaabMin.y) vaabMin.y = line._start.y; else if (line._start.y > vaabMax.y) vaabMax.y = line._start.y; if (line._start.z < vaabMin.z) vaabMin.z = line._start.z; else if (line._start.z > vaabMax.z) vaabMax.z = line._start.z; if (line._end.x < vaabMin.x) vaabMin.x = line._end.x; else if (line._end.x > vaabMax.x) vaabMax.x = line._end.x; if (line._end.y < vaabMin.y) vaabMin.y = line._end.y; else if (line._end.y > vaabMax.y) vaabMax.y = line._end.y; if (line._end.z < vaabMin.z) vaabMin.z = line._end.z; else if (line._end.z > vaabMax.z) vaabMax.z = line._end.z; } _vbuf->unlock(); mBox.setInfinite(); //mBox.Extents(vaabMin, vaabMax); clear(); }