示例#1
0
void DebugLines::draw()
{
   if(_drawn) return;
   else _drawn = true;

   // Initialization stuff
   mRenderOp.indexData = 0;
   mRenderOp.vertexData->vertexCount = _points.size();
   mRenderOp.vertexData->vertexStart = 0;
   mRenderOp.operationType = RenderOperation::OT_LINE_LIST;
   mRenderOp.useIndexes = false;

   Ogre::VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
   Ogre::VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding;

   decl->addElement(0, 0, VET_FLOAT3, VES_POSITION);

   HardwareVertexBufferSharedPtr vbuf =
	   HardwareBufferManager::getSingleton().createVertexBuffer(
         decl->getVertexSize(0),
         mRenderOp.vertexData->vertexCount,
		 HardwareBuffer::HBU_STATIC_WRITE_ONLY);

   bind->setBinding(0, vbuf);

   // Drawing stuff
   size_t size = _points.size();
   Vector3 vaabMin = _points[0];
   Vector3 vaabMax = _points[0];

   Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));

   for(size_t i = 0; i < size; i++)
   {
      *prPos++ = _points[i].x;
      *prPos++ = _points[i].y;
      *prPos++ = _points[i].z;

      if(_points[i].x < vaabMin.x)
         vaabMin.x = _points[i].x;
      if(_points[i].y < vaabMin.y)
         vaabMin.y = _points[i].y;
      if(_points[i].z < vaabMin.z)
         vaabMin.z = _points[i].z;

      if(_points[i].x > vaabMax.x)
         vaabMax.x = _points[i].x;
      if(_points[i].y > vaabMax.y)
         vaabMax.y = _points[i].y;
      if(_points[i].z > vaabMax.z)
         vaabMax.z = _points[i].z;
   }

   vbuf->unlock();

   mBox.setExtents(vaabMin, vaabMax);
}
示例#2
0
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();
}
 //-----------------------------------------------------------------------
 HardwareVertexBufferSharedPtr 
 HardwareBufferManagerBase::makeBufferCopy(
     const HardwareVertexBufferSharedPtr& source,
     HardwareBuffer::Usage usage, bool useShadowBuffer)
 {
     return this->createVertexBuffer(
         source->getVertexSize(), 
         source->getNumVertices(),
         usage, useShadowBuffer);
 }
	//---------------------------------------------------------------------
    void RenderSystem::setGlobalInstanceVertexBuffer( const HardwareVertexBufferSharedPtr val )
    {
        if ( !val.isNull() && !val->getIsInstanceData() )
        {
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
                        "A none instance data vertex buffer was set to be the global instance vertex buffer.",
                        "RenderSystem::setGlobalInstanceVertexBuffer");
        }
        mGlobalInstanceVertexBuffer = val;
    }
void NxLine::fillHardwareBuffers()
{
	int size = mPoints.size();
	prepareHardwareBuffers(size,0, mUseVertexColour);
 
	if (!size) 
	{ 
		mBox.setExtents(Vector3::ZERO,Vector3::ZERO);
		mDirty=false;
		return;
	}

	Nx::Vector3 vaabMin = mPoints[0];
	Nx::Vector3 vaabMax = mPoints[0];

	HardwareVertexBufferSharedPtr vbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer(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();


	if( mUseVertexColour ) {
		HardwareVertexBufferSharedPtr cbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer(1);
		cbuf->writeData(0, size * sizeof(unsigned int), &mPointsColor[0], true );
	}


	mBox.setExtents( NxVec3ToOgre( vaabMin ), NxVec3ToOgre(  vaabMax ) );
	mDirty = false;

}
	//---------------------------------------------------------------------
	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 NxTriangles::SetTextureCoordinates( const float * Coordinates )
{
 
	HardwareVertexBufferSharedPtr cbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer(2);

	 
	cbuf->writeData(0, cbuf->getNumVertices() * sizeof(float) * (mUVW ? 3 : 2), Coordinates, true );

 

}
示例#8
0
文件: sky.cpp 项目: SlavaHill/openmw
void SkyManager::ModVertexAlpha(Entity* ent, unsigned int meshType)
{
    // Get the vertex colour buffer of this mesh
    const Ogre::VertexElement* ves_diffuse = ent->getMesh()->getSubMesh(0)->vertexData->vertexDeclaration->findElementBySemantic( Ogre::VES_DIFFUSE );
    HardwareVertexBufferSharedPtr colourBuffer = ent->getMesh()->getSubMesh(0)->vertexData->vertexBufferBinding->getBuffer(ves_diffuse->getSource());

    // Lock
    void* pData = colourBuffer->lock(HardwareBuffer::HBL_NORMAL);

    // Iterate over all vertices
    int vertex_size = colourBuffer->getVertexSize();
    float * currentVertex = NULL;
    for (unsigned int i=0; i<colourBuffer->getNumVertices(); ++i)
    {
        // Get a pointer to the vertex colour
        ves_diffuse->baseVertexPointerToElement( pData, &currentVertex );

        unsigned char alpha=0;
        if (meshType == 0) alpha = i%2 ? 0 : 255; // this is a cylinder, so every second vertex belongs to the bottom-most row
        else if (meshType == 1)
        {
            if (i>= 49 && i <= 64) alpha = 0; // bottom-most row
            else if (i>= 33 && i <= 48) alpha = 64; // second bottom-most row
            else alpha = 255;
        }

        uint8 tmpR = static_cast<uint8>(255);
        uint8 tmpG = static_cast<uint8>(255);
        uint8 tmpB = static_cast<uint8>(255);
        uint8 tmpA = static_cast<uint8>(alpha);

        // This does not matter since R and B are always 1.
        /*VertexElementType format = Root::getSingleton().getRenderSystem()->getColourVertexElementType();
        switch (format)
        {
        case VET_COLOUR_ARGB:
            std::swap(tmpR, tmpB);
            break;
        case VET_COLOUR_ABGR:
            break;
        default:
            break;
        }*/

        // Modify
        *((uint32*)currentVertex) = tmpR | (tmpG << 8) | (tmpB << 16) | (tmpA << 24);

        // Move to the next vertex
        pData = static_cast<unsigned char *> (pData) + vertex_size;
    }

    // Unlock
    ent->getMesh()->getSubMesh(0)->vertexData->vertexBufferBinding->getBuffer(ves_diffuse->getSource())->unlock();
}
示例#9
0
 //------------------------------------------------------------------------
 void TerrainBatch::destroyGpuVertexBackupData()
 {
     if (mGpuVertexData)
     {
         HardwareVertexBufferSharedPtr destPosbuf = mGpuVertexData->vertexBufferBinding->getBuffer(TerrainTileRender::POSITION_BUFFER);
         
         if ( destPosbuf.isNull() == false )
         {
             destPosbuf->freeSystemMemoryBuffer();
         }
     }  
 }
示例#10
0
void MovableText::_updateColors(void){
    assert(mpFont);
    assert(!mpMaterial.isNull());

    // Convert to system-specific
    RGBA color;
    Root::getSingleton().convertColourValue(mColor, &color);
    HardwareVertexBufferSharedPtr vbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer(COLOUR_BINDING);
    RGBA *pDest = static_cast<RGBA*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
    for (int i = 0; i < (int)mRenderOp.vertexData->vertexCount; ++i)
        *pDest++ = color;
    vbuf->unlock();
    mUpdateColors = false;
}
void EdgeBuilderTests::testSingleIndexBufSingleVertexBuf()
{
    /* This tests the edge builders ability to find shared edges in the simple case
    of a single index buffer referencing a single vertex buffer
    */
    VertexData vd;
    IndexData id;
    // Test pyramid
    vd.vertexCount = 4;
    vd.vertexStart = 0;
    vd.vertexDeclaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
    vd.vertexDeclaration->addElement(0, 0, VET_FLOAT3, VES_POSITION);
    HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(sizeof(float)*3, 4, HardwareBuffer::HBU_STATIC,true);
    vd.vertexBufferBinding->setBinding(0, vbuf);
    float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = 0  ;
    *pFloat++ = 50 ; *pFloat++ = 0  ; *pFloat++ = 0  ;
    *pFloat++ = 0  ; *pFloat++ = 100; *pFloat++ = 0  ;
    *pFloat++ = 0  ; *pFloat++ = 0  ; *pFloat++ = -50;
    vbuf->unlock();

    id.indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
        HardwareIndexBuffer::IT_16BIT, 12, HardwareBuffer::HBU_STATIC, true);
    id.indexCount = 12;
    id.indexStart = 0;
    unsigned short* pIdx = static_cast<unsigned short*>(id.indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
    *pIdx++ = 0; *pIdx++ = 1; *pIdx++ = 2;
    *pIdx++ = 0; *pIdx++ = 2; *pIdx++ = 3;
    *pIdx++ = 1; *pIdx++ = 3; *pIdx++ = 2;
    *pIdx++ = 0; *pIdx++ = 3; *pIdx++ = 1;
    id.indexBuffer->unlock();

    EdgeListBuilder edgeBuilder;
    edgeBuilder.addVertexData(&vd);
    edgeBuilder.addIndexData(&id);
    EdgeData* edgeData = edgeBuilder.build();

    // Should be only one group, since only one vertex buffer
    CPPUNIT_ASSERT(edgeData->edgeGroups.size() == 1);
    // 4 tris
    CPPUNIT_ASSERT(edgeData->triangles.size() == 4);
    EdgeData::EdgeGroup& eg = edgeData->edgeGroups[0];
    // 6 edges
    CPPUNIT_ASSERT(eg.edges.size() == 6);

    delete edgeData;


}
    //---------------------------------------------------------------------
    void PanelOverlayElement::updatePositionGeometry(void)
    {
		/*
			0-----2
			|    /|
			|  /  |
			|/    |
			1-----3
		*/
		Real left, right, top, bottom;

		/* Convert positions into -1, 1 coordinate space (homogenous clip space).
			- Left / right is simple range conversion
			- Top / bottom also need inverting since y is upside down - this means
			that top will end up greater than bottom and when computing texture
			coordinates, we have to flip the v-axis (ie. subtract the value from
			1.0 to get the actual correct value).
		*/
		left = _getDerivedLeft() * 2 - 1;
		right = left + (mWidth * 2);
		top = -((_getDerivedTop() * 2) - 1);
		bottom =  top -  (mHeight * 2);

		HardwareVertexBufferSharedPtr vbuf =
			mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);
		float* pPos = static_cast<float*>(
			vbuf->lock(HardwareBuffer::HBL_DISCARD) );

		// Use the furthest away depth value, since materials should have depth-check off
		// This initialised the depth buffer for any 3D objects in front
		Real zValue = Root::getSingleton().getRenderSystem()->getMaximumDepthInputValue();
		*pPos++ = left;
		*pPos++ = top;
		*pPos++ = zValue;

		*pPos++ = left;
		*pPos++ = bottom;
		*pPos++ = zValue;

		*pPos++ = right;
		*pPos++ = top;
		*pPos++ = zValue;

		*pPos++ = right;
		*pPos++ = bottom;
		*pPos++ = zValue;

		vbuf->unlock();
    }
示例#13
0
void DynamicLines::fillHardwareBuffers()
{
    int size = (int)mPoints.size();

    prepareHardwareBuffers(size, 0);

    if (!size)
    {
        mBox.setExtents(Vector3::ZERO, Vector3::ZERO);
        mDirty = false;
        return;
    }

    Vector3 vaabMin = mPoints[0];
    Vector3 vaabMax = mPoints[0];

    HardwareVertexBufferSharedPtr vbuf =
        mRenderOp.vertexData->vertexBufferBinding->getBuffer(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);

    mDirty = false;
}
  void DebugRectangle2D::setCorners(Real left, Real top, Real right, Real bottom)
  {
    VertexDeclaration * const decl = mRenderOp.vertexData->vertexDeclaration;
    const VertexElement* poselem = decl->findElementBySemantic(VES_POSITION);
    const VertexElement* colorelem = decl->findElementBySemantic(VES_DIFFUSE);

    HardwareVertexBufferSharedPtr vbuf =
    mRenderOp.vertexData->vertexBufferBinding->getBuffer(POSITION_BINDING);

    const size_t vertexSize = vbuf->getVertexSize ();
    float *pPos;
    RGBA *pColor;
    Root * const root = Root::getSingletonPtr();

    uchar* pMain = static_cast<uchar *>(
        vbuf->lock(HardwareBuffer::HBL_DISCARD));

//    #define V3(AX, AY, AZ, ACOLOR) poselem->baseVertexPointerToElement(pMain, &pPos); \
//            *pPos++ = AX; *pPos++ =  AY; *pPos++ =  AZ; \
//            pMain += vertexSize;

#define V3(A_X, A_Y, A_Z, ACOLOR) poselem->baseVertexPointerToElement(pMain, &pPos); \
			*pPos++ = static_cast <float> (A_X); \
			*pPos++ = static_cast <float> (A_Y); \
			*pPos++ = static_cast <float> (A_Z); \
            colorelem->baseVertexPointerToElement(pMain, &pColor); \
            root->convertColourValue (ACOLOR, pColor); \
            pMain += vertexSize;

    V3(left, top, -1.0f, ColourValue::White)
    V3(left, bottom, -1.0f, ColourValue::White)
    V3(right, bottom, -1.0f, ColourValue::White)
    V3(right, top, -1.0f, ColourValue::White)

    vbuf->unlock();

    HardwareIndexBufferSharedPtr iBuf = mRenderOp.indexData->indexBuffer;
    ushort* pIdx = static_cast<ushort*>(
        iBuf->lock(0, iBuf->getSizeInBytes(),HardwareBuffer::HBL_DISCARD));

    *pIdx++ = static_cast<ushort> (0); *pIdx++ = static_cast<ushort> (1); // line 1
    *pIdx++ = static_cast<ushort> (1); *pIdx++ = static_cast<ushort> (2);// line 2
    *pIdx++ = static_cast<ushort> (2); *pIdx++ = static_cast<ushort> (3);// line 3
    *pIdx++ = static_cast<ushort> (3); *pIdx++ = static_cast<ushort> (0);// line 4

    iBuf->unlock();
  }
示例#15
0
    //------------------------------------------------------------------------
    void TerrainBatch::checkAndUpdateGpuVertexBackupData()
    {
        if ( mGpuVertexData )
        {
            HardwareVertexBufferSharedPtr destPosbuf = mGpuVertexData->vertexBufferBinding->getBuffer(TerrainTileRender::POSITION_BUFFER);
            if ( destPosbuf.isNull() == false )
            {
                destPosbuf->createSystemMemoryBuffer();

                {
                    updateVertexData( mVertexRectInTile );
                }

                destPosbuf->freeSystemMemoryBuffer();
            }
        }
    }
示例#16
0
	//-----------------------------------------------------------------------
	void LightInstanceBatchHW::buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation )
	{
		InstanceBatch::buildFrom( baseSubMesh, renderOperation );

		//We need to clone the VertexData (but just reference all buffers, except the last one)
		//because last buffer contains data specific to this batch, we need a different binding
		mRenderOperation.vertexData	= mRenderOperation.vertexData->clone( false );
		VertexData *thisVertexData		= mRenderOperation.vertexData;
		const unsigned short lastSource	= thisVertexData->vertexDeclaration->getMaxSource();
		HardwareVertexBufferSharedPtr vertexBuffer =
										HardwareBufferManager::getSingleton().createVertexBuffer(
										thisVertexData->vertexDeclaration->getVertexSize(lastSource),
										mInstancesPerBatch,
										HardwareBuffer::HBU_STATIC_WRITE_ONLY );
		thisVertexData->vertexBufferBinding->setBinding( lastSource, vertexBuffer );
		vertexBuffer->setIsInstanceData( true );
		vertexBuffer->setInstanceDataStepRate( 1 );
	}
	//-----------------------------------------------------------------------
    void HardwareBufferManagerBase::registerVertexBufferSourceAndCopy(
			const HardwareVertexBufferSharedPtr& sourceBuffer,
			const HardwareVertexBufferSharedPtr& copy)
	{
		OGRE_LOCK_MUTEX(mTempBuffersMutex)
		// Add copy to free temporary vertex buffers
        mFreeTempVertexBufferMap.insert(
            FreeTemporaryVertexBufferMap::value_type(sourceBuffer.get(), copy));
	}
示例#18
0
	void HardwareBufferManagerBase::touchVertexBufferCopy(const HardwareVertexBufferSharedPtr& bufferCopy)
	{
		TemporayVertexBufferLicenseMap::iterator i = mTempVertexBufferLicenses.find(bufferCopy.get());
		if (i != mTempVertexBufferLicenses.end())
		{
			VertexBufferLicense& vbl = i->second;
			assert(vbl.licenseType == BLT_AUTOMATIC_RELEASE);
			vbl.expiredDelay = EXPIRED_DELAY_FRAME_THRESHOLD;
		}
	}
示例#19
0
void MovableText::_updateColors(void)
{
	assert(mpFont);
	assert(!mpMaterial.isNull());

	// Convert to system-specific
	RGBA color;
	Root::getSingleton().convertColourValue(mColor, &color);
	HardwareVertexBufferSharedPtr vbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer(COLOUR_BINDING);
	//RGBA *pDest = static_cast<RGBA*>(vbuf->lock(HardwareBuffer::HBL_NORMAL));
	RGBA* pDest=(RGBA*)malloc(vbuf->getSizeInBytes());
	RGBA* oDest=pDest;
	for (uint i = 0; i < mRenderOp.vertexData->vertexCount; ++i)
		*pDest++ = color;
	//vbuf->unlock();
	vbuf->writeData(0, vbuf->getSizeInBytes(), oDest, true);
	free(oDest);
	mUpdateColors = false;
}
示例#20
0
文件: sky.cpp 项目: Dgdiniz/openmw
void SkyManager::ModVertexAlpha(Entity* ent, unsigned int meshType)
{
    // Get the vertex colour buffer of this mesh
    const Ogre::VertexElement* ves_diffuse = ent->getMesh()->getSubMesh(0)->vertexData->vertexDeclaration->findElementBySemantic( Ogre::VES_DIFFUSE );
    HardwareVertexBufferSharedPtr colourBuffer = ent->getMesh()->getSubMesh(0)->vertexData->vertexBufferBinding->getBuffer(ves_diffuse->getSource());

    // Lock
    void* pData = colourBuffer->lock(HardwareBuffer::HBL_NORMAL);

    // Iterate over all vertices
    int vertex_size = colourBuffer->getVertexSize();
    float * currentVertex = NULL;
    for (unsigned int i=0; i<colourBuffer->getNumVertices(); ++i)
    {
        // Get a pointer to the vertex colour
        ves_diffuse->baseVertexPointerToElement( pData, &currentVertex );

        unsigned char alpha=0;
        if (meshType == 0) alpha = i%2 ? 0 : 255; // this is a cylinder, so every second vertex belongs to the bottom-most row
        else if (meshType == 1)
        {
            if (i>= 49 && i <= 64) alpha = 0; // bottom-most row
            else if (i>= 33 && i <= 48) alpha = 64; // second bottom-most row
            else alpha = 255;
        }
        // NB we would have to swap R and B depending on rendersystem specific VertexElementType, but doesn't matter since they are both 1
        uint8 tmpR = static_cast<uint8>(255);
        uint8 tmpG = static_cast<uint8>(255);
        uint8 tmpB = static_cast<uint8>(255);
        uint8 tmpA = static_cast<uint8>(alpha);

        // Modify
        *((uint32*)currentVertex) = tmpR | (tmpG << 8) | (tmpB << 16) | (tmpA << 24);

        // Move to the next vertex
        pData = static_cast<unsigned char *> (pData) + vertex_size;
    }

    // Unlock
    ent->getMesh()->getSubMesh(0)->vertexData->vertexBufferBinding->getBuffer(ves_diffuse->getSource())->unlock();
}
示例#21
0
	void HardwareBufferManagerBase::releaseVertexBufferCopy(const HardwareVertexBufferSharedPtr& bufferCopy)
	{
		TemporayVertexBufferLicenseMap::iterator i = mTempVertexBufferLicenses.find(bufferCopy.get());
		if (i != mTempVertexBufferLicenses.end())
		{
			const VertexBufferLicense& vbl = i->second;
			vbl.licensee->licenseExpired(vbl.buffer.get());
			mFreeTempVertexBufferMap.insert(
				FreeTemporaryVertexBufferMap::value_type(vbl.originalBufferPtr, vbl.buffer));
			mTempVertexBufferLicenses.erase(i);

		}
	}
AxisAlignedBox getVertexDataAabb( VertexData* vd, const Ogre::Matrix4& transform)
{
	AxisAlignedBox aabb;

	const VertexElement* ve = vd->vertexDeclaration->findElementBySemantic(VES_POSITION);
	HardwareVertexBufferSharedPtr vb = vd->vertexBufferBinding->getBuffer(ve->getSource());

	unsigned char* data = static_cast<unsigned char*>(
	vb->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));

	for (size_t i = 0; i < vd->vertexCount; ++i)
	{
		float* v;
		ve->baseVertexPointerToElement(data, &v);
		aabb.merge(transform * Ogre::Vector3(v[0], v[1], v[2]));

		data += vb->getVertexSize();
	}
	vb->unlock();

	return aabb;
}
示例#23
0
	//-----------------------------------------------------------------------
	void LightInstanceBatchHW::setupVertices( const SubMesh* baseSubMesh )
	{
		mRenderOperation.vertexData = baseSubMesh->vertexData->clone();
		mRemoveOwnVertexData = true; //Raise flag to remove our own vertex data in the end (not always needed)
		
		VertexData *thisVertexData = mRenderOperation.vertexData;

		//No skeletal animation support in this technique, sorry
		removeBlendData();

		//Modify the declaration so it contains an extra source, where we can put the per instance data
		size_t offset				= 0;
		unsigned short nextTexCoord	= thisVertexData->vertexDeclaration->getNextFreeTextureCoordinate();
		const unsigned short newSource = thisVertexData->vertexDeclaration->getMaxSource() + 1;
		for( int i=0; i<3; ++i )
		{
			thisVertexData->vertexDeclaration->addElement( newSource, offset, VET_FLOAT4,
															VES_TEXTURE_COORDINATES, nextTexCoord++ );
			offset = thisVertexData->vertexDeclaration->getVertexSize( newSource );
		}

		// µã¹âµÄLightColor + LightFalloffÖµ [6/7/2013 mavaL]
		for( int i=0; i<2; ++i )
		{
			thisVertexData->vertexDeclaration->addElement( newSource, offset, VET_FLOAT4,
				VES_TEXTURE_COORDINATES, nextTexCoord++ );
			offset = thisVertexData->vertexDeclaration->getVertexSize( newSource );
		}

		//Create the vertex buffer containing per instance data
		HardwareVertexBufferSharedPtr vertexBuffer =
										HardwareBufferManager::getSingleton().createVertexBuffer(
										thisVertexData->vertexDeclaration->getVertexSize(newSource),
										mInstancesPerBatch,
										HardwareBuffer::HBU_STATIC_WRITE_ONLY );
		thisVertexData->vertexBufferBinding->setBinding( newSource, vertexBuffer );
		vertexBuffer->setIsInstanceData( true );
		vertexBuffer->setInstanceDataStepRate( 1 );
	}
void ColoredTextAreaOverlayElement::updateColours(void)
{
	if(!mRenderOp.vertexData) return;
	// Convert to system-specific
	RGBA topColour, bottomColour;
	// Set default to white
	Root::getSingleton().convertColourValue(ColourValue::White, &topColour);
	Root::getSingleton().convertColourValue(ColourValue::White, &bottomColour);

	HardwareVertexBufferSharedPtr vbuf = 
		mRenderOp.vertexData->vertexBufferBinding->getBuffer(COLOUR_BINDING);

	//RGBA* pDest = static_cast<RGBA*>(
	//	vbuf->lock(HardwareBuffer::HBL_NORMAL) );
	RGBA* pDest=(RGBA*)malloc(vbuf->getSizeInBytes());
	RGBA* oDest=pDest;

	for (size_t i = 0; i < mAllocSize; ++i)
	{
		if (i < m_Colors.size())
		{
			Root::getSingleton().convertColourValue(GetColor(m_Colors[i], m_ValueTop), &topColour);
			Root::getSingleton().convertColourValue(GetColor(m_Colors[i], m_ValueBottom), &bottomColour);
		}

		// First tri (top, bottom, top)
		*pDest++ = topColour;
		*pDest++ = bottomColour;
		*pDest++ = topColour;
		// Second tri (top, bottom, bottom)
		*pDest++ = topColour;
		*pDest++ = bottomColour;
		*pDest++ = bottomColour;
	}
	vbuf->writeData(0, vbuf->getSizeInBytes(), oDest, true);
	free(oDest);
	//vbuf->unlock();
}
示例#25
0
    //-----------------------------------------------------------------------------------
    void Rectangle2D::setNormals( const Ogre::Vector3 &topLeft, const Ogre::Vector3 &bottomLeft,
                                    const Ogre::Vector3 &topRight, const Ogre::Vector3 &bottomRight)
    {
        HardwareVertexBufferSharedPtr vbuf = mRenderOp.vertexData->vertexBufferBinding->getBuffer( 1 );
        float* pFloat = static_cast<float*>( vbuf->lock(HardwareBuffer::HBL_DISCARD) );

        *pFloat++ = topLeft.x;
        *pFloat++ = topLeft.y;
        *pFloat++ = topLeft.z;

        if( mQuad )
        {
            *pFloat++ = bottomLeft.x;
            *pFloat++ = bottomLeft.y;
            *pFloat++ = bottomLeft.z;

            *pFloat++ = topRight.x;
            *pFloat++ = topRight.y;
            *pFloat++ = topRight.z;

            *pFloat++ = bottomRight.x;
            *pFloat++ = bottomRight.y;
            *pFloat++ = bottomRight.z;
        }
        else
        {
            *pFloat++ = bottomLeft.x;
            *pFloat++ = Math::lerp( topLeft.y, bottomLeft.y, 2.0f );
            *pFloat++ = bottomLeft.z;

            *pFloat++ = Math::lerp( topLeft.x, topRight.x, 2.0f );
            *pFloat++ = topRight.y;
            *pFloat++ = topRight.z;
        }

        vbuf->unlock();
    }
示例#26
0
	void Rectangle2D::setUVs( const Ogre::Vector2 &topLeft, const Ogre::Vector2 &bottomLeft,
								const Ogre::Vector2 &topRight, const Ogre::Vector2 &bottomRight)
	{
		if( mRenderOp.vertexData->vertexDeclaration->getElementCount() <= TEXCOORD_BINDING )
			return; //Vertex data wasn't built with UV buffer

		HardwareVertexBufferSharedPtr vbuf = 
            mRenderOp.vertexData->vertexBufferBinding->getBuffer(TEXCOORD_BINDING);
        float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));

        *pFloat++ = topLeft.x;
        *pFloat++ = topLeft.y;

        *pFloat++ = bottomLeft.x;
        *pFloat++ = bottomLeft.y;

        *pFloat++ = topRight.x;
        *pFloat++ = topRight.y;

        *pFloat++ = bottomRight.x;
        *pFloat++ = bottomRight.y;

        vbuf->unlock();
	}
示例#27
0
	void Rectangle2D::setNormals(const Ogre::Vector3 &topLeft, const Ogre::Vector3 &bottomLeft, const Ogre::Vector3 &topRight, const Ogre::Vector3 &bottomRight)
	{
		HardwareVertexBufferSharedPtr vbuf = 
            mRenderOp.vertexData->vertexBufferBinding->getBuffer(NORMAL_BINDING);
        float* pFloat = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));

        *pFloat++ = topLeft.x;
        *pFloat++ = topLeft.y;
        *pFloat++ = topLeft.z;

        *pFloat++ = bottomLeft.x;
        *pFloat++ = bottomLeft.y;
        *pFloat++ = bottomLeft.z;

        *pFloat++ = topRight.x;
        *pFloat++ = topRight.y;
        *pFloat++ = topRight.z;

        *pFloat++ = bottomRight.x;
        *pFloat++ = bottomRight.y;
        *pFloat++ = bottomRight.z;

        vbuf->unlock();
	}
	//-----------------------------------------------------------------------
    HardwareVertexBufferSharedPtr 
    HardwareBufferManagerBase::allocateVertexBufferCopy(
        const HardwareVertexBufferSharedPtr& sourceBuffer, 
        BufferLicenseType licenseType, HardwareBufferLicensee* licensee,
        bool copyData)
    {
		// pre-lock the mVertexBuffers mutex, which would usually get locked in
		//  makeBufferCopy / createVertexBuffer
		// this prevents a deadlock in _notifyVertexBufferDestroyed
		// which locks the same mutexes (via other methods) but in reverse order
        OGRE_LOCK_MUTEX(mVertexBuffersMutex);
		{
                    OGRE_LOCK_MUTEX(mTempBuffersMutex);
			HardwareVertexBufferSharedPtr vbuf;

			// Locate existing buffer copy in temporary vertex buffers
			FreeTemporaryVertexBufferMap::iterator i = 
				mFreeTempVertexBufferMap.find(sourceBuffer.get());
			if (i == mFreeTempVertexBufferMap.end())
			{
				// copy buffer, use shadow buffer and make dynamic
				vbuf = makeBufferCopy(
					sourceBuffer, 
					HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, 
					true);
			}
			else
			{
				// Allocate existing copy
				vbuf = i->second;
				mFreeTempVertexBufferMap.erase(i);
			}

			// Copy data?
			if (copyData)
			{
				vbuf->copyData(*(sourceBuffer.get()), 0, 0, sourceBuffer->getSizeInBytes(), true);
			}

			// Insert copy into licensee list
			mTempVertexBufferLicenses.insert(
				TemporaryVertexBufferLicenseMap::value_type(
					vbuf.get(),
					VertexBufferLicense(sourceBuffer.get(), licenseType, EXPIRED_DELAY_FRAME_THRESHOLD, vbuf, licensee)));
			return vbuf;
		}

    }
示例#29
0
    // ------------------------------------------------------------------------
    void ShadowCaster::extrudeVertices(
        const HardwareVertexBufferSharedPtr& vertexBuffer, 
        size_t originalVertexCount, const Vector4& light, Real extrudeDist)
    {
        assert (vertexBuffer->getVertexSize() == sizeof(float) * 3
            && "Position buffer should contain only positions!");

        // Extrude the first area of the buffer into the second area
        // Lock the entire buffer for writing, even though we'll only be
        // updating the latter because you can't have 2 locks on the same
        // buffer
        HardwareBufferLockGuard vertexLock(vertexBuffer, HardwareBuffer::HBL_NORMAL);
        float* pSrc = static_cast<float*>(vertexLock.pData);

        // TODO: We should add extra (ununsed) vertices ensure source and
        // destination buffer have same alignment for slight performance gain.
        float* pDest = pSrc + originalVertexCount * 3;

        OptimisedUtil::getImplementation()->extrudeVertices(
            light, extrudeDist,
            pSrc, pDest, originalVertexCount);
    }
示例#30
0
	HardwareVertexBufferSharedPtr HardwareBufferManagerBase::allocateVertexBufferCopy(const HardwareVertexBufferSharedPtr& sourceBuffer, BufferLicenseType licenseType, HardwareBufferLicensee* licensee, BOOL copyData /* = FALSE */)
	{
		HardwareVertexBufferSharedPtr vbuf;
		FreeTemporaryVertexBufferMap::iterator i = mFreeTempVertexBufferMap.find(sourceBuffer.get());
		if (i == mFreeTempVertexBufferMap.end())
		{
			vbuf = makeBufferCopy(sourceBuffer, HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
				TRUE);
		}
		else
		{
			vbuf = i->second;
			mFreeTempVertexBufferMap.erase(i);
		}
		if (copyData)
		{
			vbuf->copyData(*(sourceBuffer.get()), 0, 0, sourceBuffer->getSizeInBytes(), TRUE);
		}
		mTempVertexBufferLicenses.insert(
			TemporayVertexBufferLicenseMap::value_type(
			vbuf.get(),
			VertexBufferLicense(sourceBuffer.get(), licenseType, EXPIRED_DELAY_FRAME_THRESHOLD, vbuf, licensee)));
		return vbuf;
	}