void OgreImGui::ImGUIRenderable::updateVertexData(ImDrawData* draw_data,unsigned int cmdIndex)
{
    Ogre::VertexBufferBinding* bind   = mRenderOp.vertexData->vertexBufferBinding;

    const ImDrawList* cmd_list = draw_data->CmdLists[cmdIndex];

    if (bind->getBindings().empty() || mVertexBufferSize != cmd_list->VtxBuffer.size())
    {
        mVertexBufferSize = cmd_list->VtxBuffer.size();
        bind->setBinding(0,Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(ImDrawVert),mVertexBufferSize,Ogre::HardwareBuffer::HBU_WRITE_ONLY));
    }

    if (mRenderOp.indexData->indexBuffer.isNull() || mIndexBufferSize != cmd_list->IdxBuffer.size())
    {
        mIndexBufferSize = cmd_list->IdxBuffer.size();

        mRenderOp.indexData->indexBuffer=
        Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT,mIndexBufferSize,Ogre::HardwareBuffer::HBU_WRITE_ONLY);
    }

    // Copy all vertices
    ImDrawVert* vtx_dst = (ImDrawVert*)(bind->getBuffer(0)->lock(Ogre::HardwareBuffer::HBL_DISCARD));
    ImDrawIdx* idx_dst = (ImDrawIdx*)(mRenderOp.indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));

    memcpy(vtx_dst, &cmd_list->VtxBuffer[0], mVertexBufferSize * sizeof(ImDrawVert));
    memcpy(idx_dst, &cmd_list->IdxBuffer[0], mIndexBufferSize * sizeof(ImDrawIdx));

    mRenderOp.vertexData->vertexStart = 0;
    mRenderOp.vertexData->vertexCount =  cmd_list->VtxBuffer.size();
    mRenderOp.indexData->indexStart = 0;
    mRenderOp.indexData->indexCount =  cmd_list->IdxBuffer.size();

    bind->getBuffer(0)->unlock();
    mRenderOp.indexData->indexBuffer->unlock();
}
Beispiel #2
0
/// @author https://bitbucket.org/ChaosCreator/imgui-ogre2.1-binding/src/8f1a01db510f543a987c3c16859d0a33400d9097/ImguiRenderable.cpp?at=master&fileviewer=file-view-default
/// Commentary on OGRE forums: http://www.ogre3d.org/forums/viewtopic.php?f=5&t=89081#p531059
void OgreImGui::ImGUIRenderable::updateVertexData(const ImDrawVert* vtxBuf, const ImDrawIdx* idxBuf, unsigned int vtxCount, unsigned int idxCount)
{
    Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;

    if (bind->getBindings().empty() || mVertexBufferSize != vtxCount)
    {
        mVertexBufferSize = vtxCount;

        bind->setBinding(0, Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(ImDrawVert), mVertexBufferSize, Ogre::HardwareBuffer::HBU_WRITE_ONLY));
    }
    if (mRenderOp.indexData->indexBuffer.isNull() || mIndexBufferSize != idxCount)
    {
        mIndexBufferSize = idxCount;

        mRenderOp.indexData->indexBuffer =
            Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, mIndexBufferSize, Ogre::HardwareBuffer::HBU_WRITE_ONLY);
    }

    // Copy all vertices
    ImDrawVert* vtxDst = (ImDrawVert*)(bind->getBuffer(0)->lock(Ogre::HardwareBuffer::HBL_DISCARD));
    ImDrawIdx* idxDst = (ImDrawIdx*)(mRenderOp.indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));

    memcpy(vtxDst, vtxBuf, mVertexBufferSize * sizeof(ImDrawVert));
    memcpy(idxDst, idxBuf, mIndexBufferSize * sizeof(ImDrawIdx));

    mRenderOp.vertexData->vertexStart = 0;
    mRenderOp.vertexData->vertexCount = vtxCount;
    mRenderOp.indexData->indexStart = 0;
    mRenderOp.indexData->indexCount = idxCount;


    bind->getBuffer(0)->unlock();
    mRenderOp.indexData->indexBuffer->unlock();
}
Beispiel #3
0
GrassPatch::GrassPatch(int nb_blades, int nb_blade_segments, float width, float height, Ogre::SceneManager* ScnMgr)
{
	int		i, nb_particles;

	// Create the particle field
	nb_particles = nb_blades * (nb_blade_segments + 1);
	m_Particles = new GrassParticleField(nb_particles, 1);

	// Allocate the blade list
	m_Blades = new Blade *[nb_blades];
	m_NbBlades = nb_blades;
	Ogre::Radian *angle = new Ogre::Radian(Ogre::Math::PI * ((rand()%1000) / 1000.0f));

	// Create the blades of grass
	for (i = 0; i < nb_blades; i++)
	{
		m_Blades[i] = new Blade(m_Particles,
								i * (nb_blade_segments + 1),
								nb_blade_segments,
								4 + ((rand()%1000) / 1000.0f)*0.5f,
								0.3f + ((rand()%1000) / 1000.0f)*0.1f,
								width / 2 - ((rand()%1000) / 500.0f) * width,
								height / 2 - ((rand()%1000) / 500.0f) * height,
								*angle);
		m_Blades[i]->moving = true;
		m_Blades[i]->timeout = 0;
	}
	m_VertexCount = nb_blades * m_Blades[0]->GetStrippedVertexCount();
	m_TriangleCount = ((nb_blade_segments - 1) << 1) + 1;
 
    mvertexData = new Ogre::VertexData ();

    // Vertex declaration
	Ogre::VertexDeclaration* decl = mvertexData->vertexDeclaration;
	Ogre::VertexBufferBinding* binding = mvertexData->vertexBufferBinding;         
    
    size_t offset = 0;

    //position
	decl->addElement (POSITION_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION); 
	offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);

    // normal here
	decl->addElement(POSITION_BINDING, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
	offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
     
    // Diffuse Color
    decl->addElement(POSITION_BINDING, offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);  
	offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
    
    // texture here
	decl->addElement(POSITION_BINDING, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);  
	offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);

   //position updated each frame 
	Ogre::HardwareVertexBufferSharedPtr vbuf1 = 
           Ogre::HardwareBufferManager::getSingleton().createVertexBuffer (offset,        // size of one whole vertex
																		   m_VertexCount,                                // number of vertices
																		   Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, // usage
                                                                            false);                                      // no shadow buffer

	binding->setBinding(POSITION_BINDING, vbuf1);
 

	Ogre::HardwareVertexBufferSharedPtr vVertices = binding->getBuffer(POSITION_BINDING);
	Ogre::Real *pVertices = static_cast<Ogre::Real*>( vVertices->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );

    // Colour up the blades
	for (i = 0; i < m_NbBlades; i++)
        m_Blades[i]->Paint (i, pVertices); 
       
	vVertices->unlock();

    // Index buffer to handle triangle strip vertex buffer as triangle list
     
    // Create index buffer 
      int nIndexes = m_TriangleCount*3*m_NbBlades;
   
      Ogre::HardwareIndexBufferSharedPtr iBuf = 
            Ogre::HardwareBufferManager::getSingleton().createIndexBuffer (Ogre::HardwareIndexBuffer::IT_32BIT, 
                                                                nIndexes, 
                                                                Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY, 
                                                                false); 

      // Fill index buffer 
      unsigned int* pIdx = static_cast<unsigned int*> (iBuf->lock (Ogre::HardwareBuffer::HBL_DISCARD)); 
               
       unsigned int j = 0;
        for (i = 0; i < m_NbBlades; i++)
	        m_Blades[i]->UpdateIndexBuffer(&j, i, pIdx);

      iBuf->unlock ();
          

    mRenderOp.vertexData = mvertexData;
//	mRenderOp.vertexData->vertexCount = m_VertexCount;
    mRenderOp.vertexData->vertexCount= nIndexes;
	mRenderOp.vertexData->vertexStart = 0;  

    mRenderOp.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
    mRenderOp.indexData = new Ogre::IndexData();
    mRenderOp.indexData->indexBuffer = iBuf; 
    mRenderOp.indexData->indexCount = nIndexes; 
    mRenderOp.indexData->indexStart = 0;  

	mRenderOp.useIndexes = true; 
      
    mRenderOp.srcRenderable = this;

    setMaterial ("Examples/Grass");  
 
    // setup radius the bounding box of this SimpleRenderable to big values to be sure to achieve drawing.
    mRadius = 100;
	setBoundingBox(Ogre::AxisAlignedBox(-300, -300, -300, 600, 600, 600));

 }