//-------------------------------------------------------------------------------// void OverlayPanelElement::initialise(const String& texName, float width, float height, float left, float top) { mTexture = TextureMgr::getSingletonPtr()->getByName(texName); setSize(width, height); setPosition(left, top); mIsVisible = true; if(!mIsInitialised) { mRenderData.vertexData = TITAN_NEW VertexData(); VertexDeclaration* decl = mRenderData.vertexData->vertexDecl; decl->addElement(0,0, VET_FLOAT3, VES_POSITION); mRenderData.vertexData->vertexStart = 0; mRenderData.vertexData->vertexCount = 4; VertexBufferPtr vbuf = HardwareBufferMgr::getSingletonPtr()->createVertexBuffer(decl->getVertexSize(0), mRenderData.vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); mRenderData.vertexData->vertexBufferBinding->setBinding(0, vbuf); mRenderData.useIndex = false; mRenderData.operationType = OT_TRIANGLE_STRIP; mIsInitialised = true; } notifyGeometryOld(); }
//----------------------------------------------------------------------- void BillboardChain::setupVertexDeclaration(void) { if (mVertexDeclDirty) { VertexDeclaration* decl = mVertexData->vertexDeclaration; decl->removeAllElements(); size_t offset = 0; // Add a description for the buffer of the positions of the vertices decl->addElement(0, offset, VET_FLOAT3, VES_POSITION); offset += VertexElement::getTypeSize(VET_FLOAT3); if (mUseVertexColour) { decl->addElement(0, offset, VET_COLOUR, VES_DIFFUSE); offset += VertexElement::getTypeSize(VET_COLOUR); } if (mUseTexCoords) { decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES); } if (!mUseTexCoords && !mUseVertexColour) { LogManager::getSingleton().logMessage( "Error - BillboardChain '" + mName + "' is using neither " "texture coordinates or vertex colours; it will not be " "visible on some rendering APIs so you should change this " "so you use one or the other."); } mVertexDeclDirty = false; } }
//--------------------------------------------------------------------- void BorderPanelOverlayElement::initialise(void) { bool init = !mInitialised; // init mRenderOp2 before calling superclass, as virtual _restoreManualHardwareResources would be called within if (init) { // Setup render op in advance mRenderOp2.vertexData = OGRE_NEW VertexData(); mRenderOp2.vertexData->vertexCount = 4 * 8; // 8 cells, can't necessarily share vertices cos // texcoords may differ mRenderOp2.vertexData->vertexStart = 0; // Vertex declaration VertexDeclaration* decl = mRenderOp2.vertexData->vertexDeclaration; // Position and texture coords each have their own buffers to allow // each to be edited separately with the discard flag decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); decl->addElement(TEXCOORD_BINDING, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0); // Index data mRenderOp2.operationType = RenderOperation::OT_TRIANGLE_LIST; mRenderOp2.useIndexes = true; mRenderOp2.indexData = OGRE_NEW IndexData(); mRenderOp2.indexData->indexCount = 8 * 6; mRenderOp2.indexData->indexStart = 0; mRenderOp2.useGlobalInstancingVertexBufferIsAvailable = false; // Create sub-object for rendering border mBorderRenderable = OGRE_NEW BorderRenderable(this); } // superclass will handle the interior panel area and call _restoreManualHardwareResources PanelOverlayElement::initialise(); }
void WireBoundingBox::_initWireBoundingBox() { mRenderOp.vertexData = OGRE_NEW VertexData(); mRenderOp.indexData = 0; mRenderOp.vertexData->vertexCount = 24; mRenderOp.vertexData->vertexStart = 0; mRenderOp.operationType = RenderOperation::OT_LINE_LIST; mRenderOp.useIndexes = false; mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false; VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(POSITION_BINDING), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY); // Bind buffer bind->setBinding(POSITION_BINDING, vbuf); // set basic white material this->setMaterial("BaseWhiteNoLighting"); }
void GeomUtils::createQuad(VertexData*& vertexData) { assert(vertexData); vertexData->vertexCount = 4; vertexData->vertexStart = 0; VertexDeclaration* vertexDecl = vertexData->vertexDeclaration; VertexBufferBinding* bind = vertexData->vertexBufferBinding; vertexDecl->addElement(0, 0, VET_FLOAT3, VES_POSITION); HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( vertexDecl->getVertexSize(0), vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY); // Bind buffer bind->setBinding(0, vbuf); // Upload data float data[]={ -1,1,-1, // corner 1 -1,-1,-1, // corner 2 1,1,-1, // corner 3 1,-1,-1}; // corner 4 vbuf->writeData(0, sizeof(data), data, true); }
VertexDeclaration* VertexBufferManager::CreateVertexDeclaration( const std::string &name, VertexPointer *pointers, size_t count ) { VertexDeclaration *pDecl = new VertexDeclaration(); pDecl->AddPointers( pointers, count ); mVertexDeclarations[ name ] = pDecl; return pDecl; }
//--------------------------------------------------------------------- void PanelOverlayElement::initialise(void) { bool init = !mInitialised; OverlayContainer::initialise(); if (init) { // Setup render op in advance mRenderOp.vertexData = OGRE_NEW VertexData(); // Vertex declaration: 1 position, add texcoords later depending on #layers // Create as separate buffers so we can lock & discard separately VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); // Basic vertex data mRenderOp.vertexData->vertexStart = 0; mRenderOp.vertexData->vertexCount = 4; // No indexes & issue as a strip mRenderOp.useIndexes = false; mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP; mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false; mInitialised = true; _restoreManualHardwareResources(); } }
void TextAreaOverlayElement::initialise(void) { if (!mInitialised) { // Set up the render op // Combine positions and texture coords since they tend to change together // since character sizes are different mRenderOp.vertexData = OGRE_NEW VertexData(); VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; size_t offset = 0; // Positions decl->addElement(POS_TEX_BINDING, offset, VET_FLOAT3, VES_POSITION); offset += VertexElement::getTypeSize(VET_FLOAT3); // Texcoords decl->addElement(POS_TEX_BINDING, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0); // Colours - store these in a separate buffer because they change less often decl->addElement(COLOUR_BINDING, 0, VET_COLOUR, VES_DIFFUSE); mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST; mRenderOp.useIndexes = false; mRenderOp.vertexData->vertexStart = 0; mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false; // Vertex buffer will be created in checkMemoryAllocation mRenderOp.srcRenderable = this; checkMemoryAllocation( DEFAULT_INITIAL_CHARS ); mInitialised = true; } }
bool areCompatible ( const VertexDeclaration &u, const VertexDeclaration &v ) { if( u.count() != v.count() ) return false; for(std::size_t i(0); i<u.count(); ++i) { bool have = false; for(std::size_t j(0); j<v.count(); ++j) { if(u[i].getSemantic() == v[j].getSemantic() && u[i].getType() == v[j].getType() ) have = true; if(have) break; } if(!have) return false; } return true; }
//--------------------------------------------------------------------- void TextAreaOverlayElement::_restoreManualHardwareResources() { if(!mInitialised) return; // 6 verts per char since we're doing tri lists without indexes // Allocate space for positions & texture coords // Note - mRenderOp.vertexData->vertexCount will be less than allocatedVertexCount size_t allocatedVertexCount = mAllocSize * 6; VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; // Create dynamic since text tends to change a lot // positions & texcoords HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton(). createVertexBuffer( decl->getVertexSize(POS_TEX_BINDING), allocatedVertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); bind->setBinding(POS_TEX_BINDING, vbuf); // colours vbuf = HardwareBufferManager::getSingleton(). createVertexBuffer( decl->getVertexSize(COLOUR_BINDING), allocatedVertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); bind->setBinding(COLOUR_BINDING, vbuf); // Buffers are restored, but with trash within mGeomPositionsOutOfDate = true; mGeomUVsOutOfDate = true; mColoursChanged = true; }
//--------------------------------------------------------------------- void PanelOverlayElement::initialise(void) { bool init = !mInitialised; OverlayContainer::initialise(); if (init) { // Setup render op in advance mRenderOp.vertexData = OGRE_NEW VertexData(); // Vertex declaration: 1 position, add texcoords later depending on #layers // Create as separate buffers so we can lock & discard separately VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); // Basic vertex data mRenderOp.vertexData->vertexStart = 0; mRenderOp.vertexData->vertexCount = 4; // Vertex buffer #1 HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(POSITION_BINDING), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY// mostly static except during resizing ); // Bind buffer mRenderOp.vertexData->vertexBufferBinding->setBinding(POSITION_BINDING, vbuf); // No indexes & issue as a strip mRenderOp.useIndexes = false; mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP; mInitialised = true; } }
void Line3D::drawLines(void) { if(mDrawn) return; else mDrawn = true; // Initialization stuff mRenderOp.indexData = 0; mRenderOp.vertexData->vertexCount = mPoints.size(); mRenderOp.vertexData->vertexStart = 0; mRenderOp.operationType = RenderOperation::OT_LINE_LIST; // OT_LINE_LIST, OT_LINE_STRIP mRenderOp.useIndexes = false; VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration; VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding; decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(POSITION_BINDING), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY); bind->setBinding(POSITION_BINDING, vbuf); // Drawing stuff int size = mPoints.size(); Vector3 vaabMin = mPoints[0]; Vector3 vaabMax = mPoints[0]; Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); for(int i = 0; i < size; i++) { *prPos++ = mPoints[i].x; *prPos++ = mPoints[i].y; *prPos++ = mPoints[i].z; if(mPoints[i].x < vaabMin.x) vaabMin.x = mPoints[i].x; if(mPoints[i].y < vaabMin.y) vaabMin.y = mPoints[i].y; if(mPoints[i].z < vaabMin.z) vaabMin.z = mPoints[i].z; if(mPoints[i].x > vaabMax.x) vaabMax.x = mPoints[i].x; if(mPoints[i].y > vaabMax.y) vaabMax.y = mPoints[i].y; if(mPoints[i].z > vaabMax.z) vaabMax.z = mPoints[i].z; } vbuf->unlock(); mBox.setExtents(vaabMin, vaabMax); }
void VertexBuffer::doadvance() { VertexDeclaration* vd = m_vertexdeclaration; if( vd ) { vd->advance(); } }
VertexDeclaration TerrainManager::GetTempMeshDecl() { VertexDeclaration decl; decl.Add( VertexTypes::VEC3 ); // pos decl.Add( VertexTypes::VEC3 ); // normal decl.Add( VertexTypes::VEC2 ); // uv return decl; }
void GeomUtils::createCone(Ogre::VertexData*& vertexData, Ogre::IndexData*& indexData, float radius , float height, int nVerticesInBase) { assert(vertexData && indexData); // define the vertex format VertexDeclaration* vertexDecl = vertexData->vertexDeclaration; // positions vertexDecl->addElement(0, 0, VET_FLOAT3, VES_POSITION); // allocate the vertex buffer vertexData->vertexCount = nVerticesInBase + 1; HardwareVertexBufferSharedPtr vBuf = HardwareBufferManager::getSingleton().createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); VertexBufferBinding* binding = vertexData->vertexBufferBinding; binding->setBinding(0, vBuf); float* pVertex = static_cast<float*>(vBuf->lock(HardwareBuffer::HBL_DISCARD)); // allocate index buffer - cone and base indexData->indexCount = (3 * nVerticesInBase) + (3 * (nVerticesInBase - 2)); indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(HardwareIndexBuffer::IT_16BIT, indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); HardwareIndexBufferSharedPtr iBuf = indexData->indexBuffer; unsigned short* pIndices = static_cast<unsigned short*>(iBuf->lock(HardwareBuffer::HBL_DISCARD)); //Positions : cone head and base for (int i=0; i<3; i++) *pVertex++ = 0.0f; //Base : float fDeltaBaseAngle = (2 * Math::PI) / nVerticesInBase; for (int i=0; i<nVerticesInBase; i++) { float angle = i * fDeltaBaseAngle; *pVertex++ = radius * cosf(angle); *pVertex++ = height; *pVertex++ = radius * sinf(angle); } //Indices : //Cone head to vertices for (int i=0; i<nVerticesInBase; i++) { *pIndices++ = 0; *pIndices++ = (i%nVerticesInBase) + 1; *pIndices++ = ((i+1)%nVerticesInBase) + 1; } //Cone base for (int i=0; i<nVerticesInBase-2; i++) { *pIndices++ = 1; *pIndices++ = i + 3; *pIndices++ = i + 2; } // Unlock vBuf->unlock(); iBuf->unlock(); }
//--------------------------------------------------------------------- void PrefabFactory::createPlane(Mesh* mesh) { SubMesh* sub = mesh->createSubMesh(); float vertices[32] = { -100, -100, 0, // pos 0,0,1, // normal 0,1, // texcoord 100, -100, 0, 0,0,1, 1,1, 100, 100, 0, 0,0,1, 1,0, -100, 100, 0 , 0,0,1, 0,0 }; mesh->sharedVertexData = OGRE_NEW VertexData(); mesh->sharedVertexData->vertexCount = 4; VertexDeclaration* decl = mesh->sharedVertexData->vertexDeclaration; VertexBufferBinding* bind = mesh->sharedVertexData->vertexBufferBinding; size_t offset = 0; decl->addElement(0, offset, VET_FLOAT3, VES_POSITION); offset += VertexElement::getTypeSize(VET_FLOAT3); decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL); offset += VertexElement::getTypeSize(VET_FLOAT3); decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0); offset += VertexElement::getTypeSize(VET_FLOAT2); HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( offset, 4, HardwareBuffer::HBU_STATIC_WRITE_ONLY); bind->setBinding(0, vbuf); vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true); sub->useSharedVertices = true; HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton(). createIndexBuffer( HardwareIndexBuffer::IT_16BIT, 6, HardwareBuffer::HBU_STATIC_WRITE_ONLY); unsigned short faces[6] = {0,1,2, 0,2,3 }; sub->indexData->indexBuffer = ibuf; sub->indexData->indexCount = 6; sub->indexData->indexStart =0; ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true); mesh->_setBounds(AxisAlignedBox(-100,-100,0,100,100,0), true); mesh->_setBoundingSphereRadius(Math::Sqrt(100*100+100*100)); }
void RenderState::setVertexAttributesBaseIndex(const VertexDeclaration& decl, size_t index, bool force) { #if !defined(ET_CONSOLE_APPLICATION) for (size_t i = 0; i < decl.numElements(); ++i) { const VertexElement& e = decl.element(i); size_t dataOffset = index * (decl.interleaved() ? decl.dataSize() : vertexAttributeTypeSize(e.type())); setVertexAttribPointer(e, dataOffset, force); } #endif }
//----------------------------------------------------------------------------- VertexDeclaration* VertexDeclaration::clone(void) { VertexDeclaration* ret = HardwareBufferManager::getSingleton().createVertexDeclaration(); VertexElementList::const_iterator i, iend; iend = mElementList.end(); for (i = mElementList.begin(); i != iend; ++i) { ret->addElement(i->getSource(), i->getOffset(), i->getType(), i->getSemantic(), i->getIndex()); } return ret; }
ProceduralManualObject* createProceduralParticleSystem() { particleSystem = static_cast<ProceduralManualObject*> (mSceneMgr->createMovableObject("ParticleGSEntity", ProceduralManualObjectFactory::FACTORY_TYPE_NAME)); particleSystem->setMaterial("Ogre/ParticleGS/Display"); //Generate the geometry that will seed the particle system ManualObject* particleSystemSeed = mSceneMgr->createManualObject("ParticleSeed"); //This needs to be the initial launcher particle particleSystemSeed->begin("Ogre/ParticleGS/Display", RenderOperation::OT_POINT_LIST); particleSystemSeed->position(0,0,0); //Position particleSystemSeed->textureCoord(1); //Timer particleSystemSeed->textureCoord(0); //Type particleSystemSeed->textureCoord(0,0,0); //Velocity particleSystemSeed->end(); //Generate the RenderToBufferObject RenderToVertexBufferSharedPtr r2vbObject = HardwareBufferManager::getSingleton().createRenderToVertexBuffer(); r2vbObject->setRenderToBufferMaterialName("Ogre/ParticleGS/Generate"); //Apply the random texture TexturePtr randomTexture = RandomTools::generateRandomVelocityTexture(); r2vbObject->getRenderToBufferMaterial()->getTechnique(0)->getPass(0)-> getTextureUnitState("RandomTexture")->setTextureName( randomTexture->getName(), randomTexture->getTextureType()); r2vbObject->setOperationType(RenderOperation::OT_POINT_LIST); r2vbObject->setMaxVertexCount(16000); r2vbObject->setResetsEveryUpdate(false); VertexDeclaration* vertexDecl = r2vbObject->getVertexDeclaration(); size_t offset = 0; offset += vertexDecl->addElement(0, offset, VET_FLOAT3, VES_POSITION).getSize(); //Position offset += vertexDecl->addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 0).getSize(); //Timer offset += vertexDecl->addElement(0, offset, VET_FLOAT1, VES_TEXTURE_COORDINATES, 1).getSize(); //Type offset += vertexDecl->addElement(0, offset, VET_FLOAT3, VES_TEXTURE_COORDINATES, 2).getSize(); //Velocity //Bind the two together particleSystem->setRenderToVertexBuffer(r2vbObject); particleSystem->setManualObject(particleSystemSeed); //Set bounds AxisAlignedBox aabb; aabb.setMinimum(-100,-100,-100); aabb.setMaximum(100,100,100); particleSystem->setBoundingBox(aabb); return particleSystem; }
//----------------------------------------------------------------------------- void GL3PlusRenderToVertexBuffer::bindVerticesOutput(Pass* pass) { VertexDeclaration* declaration = mVertexData->vertexDeclaration; size_t elemCount = declaration->getElementCount(); if (elemCount > 0) { GLuint linkProgramId = 0; // Have GLSL shaders, using varying attributes if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS)) { GLSLProgramPipeline* programPipeline = GLSLProgramPipelineManager::getSingleton().getActiveProgramPipeline(); linkProgramId = programPipeline->getGLProgramPipelineHandle(); } else { GLSLLinkProgram* linkProgram = GLSLLinkProgramManager::getSingleton().getActiveLinkProgram(); linkProgramId = linkProgram->getGLProgramHandle(); } // Note: 64 is the minimum number of interleaved attributes allowed by GL_EXT_transform_feedback // So we are using it. Otherwise we could query during rendersystem initialisation and use a dynamic sized array. // But that would require C99. // const GLchar *names[64]; const GLchar *names[1] = {"gl_Position"};//, "oUv0", "oUv1", "oUv2" }; // vector<const GLchar*>::type names; // for (unsigned short e = 0; e < elemCount; e++) // { // const VertexElement* element = declaration->getElement(e); // String varyingName = getSemanticVaryingName(element->getSemantic(), element->getIndex()); // names[e] = varyingName.c_str(); //// names.push_back(varyingName.c_str()); // } OGRE_CHECK_GL_ERROR(glTransformFeedbackVaryings(linkProgramId, elemCount, names, GL_INTERLEAVED_ATTRIBS)); OGRE_CHECK_GL_ERROR(glLinkProgram(linkProgramId)); GLint didLink = 0; OGRE_CHECK_GL_ERROR(glGetProgramiv( linkProgramId, GL_LINK_STATUS, &didLink )); logObjectInfo( String("RVB GLSL link result : "), linkProgramId ); if(glIsProgram(linkProgramId)) { glValidateProgram(linkProgramId); } logObjectInfo( String("RVB GLSL validation result : "), linkProgramId ); } }
bool operator== ( const VertexDeclaration &u, const VertexDeclaration &v ) { if( u.count() != v.count() ) return false; for(std::size_t i(0); i<u.count(); ++i) { if( u[i] != v[i] ) return false; } return true; }
void RenderState::setVertexAttributes(const VertexDeclaration& decl, bool force) { #if !defined(ET_CONSOLE_APPLICATION) for (uint32_t i = 0; i < VertexAttributeUsage_max; ++i) setVertexAttribEnabled(i, decl.has(static_cast<VertexAttributeUsage>(i)), force); setVertexAttributesBaseIndex(decl, 0); #endif }
//----------------------------------------------------------------------------- void TempBlendedBufferInfo::extractFrom(const VertexData* sourceData) { // Release old buffer copies first if (!destPositionBuffer.isNull()) { destPositionBuffer->getManager()->releaseVertexBufferCopy(destPositionBuffer); assert(destPositionBuffer.isNull()); } if (!destNormalBuffer.isNull()) { destNormalBuffer->getManager()->releaseVertexBufferCopy(destNormalBuffer); assert(destNormalBuffer.isNull()); } VertexDeclaration* decl = sourceData->vertexDeclaration; VertexBufferBinding* bind = sourceData->vertexBufferBinding; const VertexElement *posElem = decl->findElementBySemantic(VES_POSITION); const VertexElement *normElem = decl->findElementBySemantic(VES_NORMAL); assert(posElem && "Positions are required"); posBindIndex = posElem->getSource(); srcPositionBuffer = bind->getBuffer(posBindIndex); if (!normElem) { posNormalShareBuffer = false; srcNormalBuffer.setNull(); } else { normBindIndex = normElem->getSource(); if (normBindIndex == posBindIndex) { posNormalShareBuffer = true; srcNormalBuffer.setNull(); } else { posNormalShareBuffer = false; srcNormalBuffer = bind->getBuffer(normBindIndex); } } }
DebugRectangle2D::DebugRectangle2D() : SimpleRenderable () { #ifdef PLSM2_EIHORT mUseIdentityProjection = true; mUseIdentityView = true; #endif mRenderOp.indexData = new IndexData(); mRenderOp.vertexData = new VertexData(); mRenderOp.operationType = RenderOperation::OT_LINE_LIST; mRenderOp.indexData->indexCount = 8; mRenderOp.vertexData->vertexCount = 4; mRenderOp.vertexData->vertexStart = 0; mRenderOp.useIndexes = true; VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); const size_t offset = VertexElement::getTypeSize(VET_FLOAT3); decl->addElement (POSITION_BINDING, offset, VET_COLOUR, VES_DIFFUSE); mRenderOp.indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer( HardwareIndexBuffer::IT_16BIT, mRenderOp.indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY); HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(POSITION_BINDING), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY); // Bind buffer bind->setBinding(POSITION_BINDING, vbuf); SimpleRenderable::setBoundingBox(AxisAlignedBox(-1000 * Vector3::UNIT_SCALE, 1000 * Vector3::UNIT_SCALE)); SimpleRenderable::setRenderQueueGroup (RENDER_QUEUE_OVERLAY); // set basic white material SimpleRenderable::setMaterial("BaseWhiteNoLighting"); }
//-------------------------------------------------------------------------------// void OverlayPanelElement::updateTexData() { if(!mTexture.isNull() &&mIsInitialised) { VertexDeclaration* decl = mRenderData.vertexData->vertexDecl; if(mTexCoordNum == 0) { decl->addElement(1, 0,VET_FLOAT2, VES_TEXTURE_COORDINATES, 0); VertexBufferPtr vbuf = HardwareBufferMgr::getSingletonPtr()->createVertexBuffer(decl->getVertexSize(1), mRenderData.vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); mRenderData.vertexData->vertexBufferBinding->setBinding(1,vbuf); mTexCoordNum = 1; } if(mTexCoordNum) { VertexBufferPtr buf = mRenderData.vertexData->vertexBufferBinding->getBuffer(1); float* pVBStart = static_cast<float*>(buf->lock(HardwareBuffer::HBL_DISCARD)); size_t uvSize = VertexElement::getTypeSize(VET_FLOAT2) / sizeof(float); size_t vertexSize = decl->getVertexSize(1) / sizeof(float); float* pTex = pVBStart; pTex[0] = mU1; pTex[1] = mV1; pTex += vertexSize; pTex[0] = mU1; pTex[1] = mV2; pTex += vertexSize; pTex[0] = mU2; pTex[1] = mV1; pTex += vertexSize; pTex[0] = mU2; pTex[1] = mV2; buf->unlock(); } } }
//--------------------------------------------------------------------- void PanelOverlayElement::_restoreManualHardwareResources() { if(!mInitialised) return; VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; // Vertex buffer #1 HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(POSITION_BINDING), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY// mostly static except during resizing ); // Bind buffer mRenderOp.vertexData->vertexBufferBinding->setBinding(POSITION_BINDING, vbuf); // Buffers are restored, but with trash within mGeomPositionsOutOfDate = true; mGeomUVsOutOfDate = true; }
void EffectBillboardChain::_createBuffer(void) { if (mRenderOp.vertexData) { delete mRenderOp.vertexData; mRenderOp.vertexData = NULL; } mRenderOp.vertexData = new VertexData(); mRenderOp.indexData = NULL; mRenderOp.vertexData->vertexCount = mCurrentNbChainElements * 2; mRenderOp.vertexData->vertexStart = 0; mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP; mRenderOp.useIndexes = false; VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; // Add a description for the buffer of the positions of the vertices size_t offset = 0; decl->addElement(0, offset, VET_FLOAT3, VES_POSITION); offset += VertexElement::getTypeSize(VET_FLOAT3); decl->addElement(0, offset, VET_COLOUR, VES_DIFFUSE); offset += VertexElement::getTypeSize(VET_COLOUR); decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES); offset += VertexElement::getTypeSize(VET_FLOAT2); // Create the buffer HardwareVertexBufferSharedPtr pVertexBuffer = HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(0), mCurrentNbChainElements * 2, HardwareBuffer::HBU_STATIC_WRITE_ONLY); // Bind the buffer bind->setBinding(0, pVertexBuffer); }
//--------------------------------------------------------------------- void PanelOverlayElement::_releaseManualHardwareResources() { if(!mInitialised) return; VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; bind->unsetBinding(POSITION_BINDING); // Remove all texcoord element declarations if(mNumTexCoordsInBuffer > 0) { bind->unsetBinding(TEXCOORD_BINDING); VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; for(size_t i = mNumTexCoordsInBuffer; i > 0; --i) { decl->removeElement(VES_TEXTURE_COORDINATES, static_cast<unsigned short>(i - 1)); } mNumTexCoordsInBuffer = 0; } }
bool VertexBuffer::bind( size_t* vertexcount, VertexDeclaration** pvd ) { VertexDeclaration* vd = m_vertexdeclaration; if( !vd || !m_vertexbuffer ) { return false; } if( Context::CurrentVertexBuffer != this ) { glBindBuffer( GL_ARRAY_BUFFER, m_vertexbuffer ); checkerror(); Context::CurrentVertexBuffer = this; } size_t vertexsize; if( !vd->bind( &vertexsize ) ) { return false; } *vertexcount = m_buffersize / vertexsize; *pvd = vd; return true; }
void TextAreaOverlayElement::checkMemoryAllocation( size_t numChars ) { if( mAllocSize < numChars) { // Create and bind new buffers // Note that old buffers will be deleted automatically through reference counting // 6 verts per char since we're doing tri lists without indexes // Allocate space for positions & texture coords VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; mRenderOp.vertexData->vertexCount = numChars * 6; // Create dynamic since text tends to change a lot // positions & texcoords HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton(). createVertexBuffer( decl->getVertexSize(POS_TEX_BINDING), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); bind->setBinding(POS_TEX_BINDING, vbuf); // colours vbuf = HardwareBufferManager::getSingleton(). createVertexBuffer( decl->getVertexSize(COLOUR_BINDING), mRenderOp.vertexData->vertexCount, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); bind->setBinding(COLOUR_BINDING, vbuf); mAllocSize = numChars; mColoursChanged = true; // force colour buffer regeneration } }