//---------------------------------------------------------------------
    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();
    }
//int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
int main(int argc,char *argv[])
{
	// Init socket under win32
	WSADATA wsaData;
	WORD wVersionRequested=MAKEWORD(1,1);
	if (WSAStartup(wVersionRequested,&wsaData)) return(-1);
	if ((LOBYTE(wsaData.wVersion)!=1) || (HIBYTE(wsaData.wVersion)!=1))
	{
		WSACleanup();
		return(-1);
	}
	// End init socket

	ReadConfFile(params);
	printf("%s\n%s\n%s\n%s\n%s\n",
		params.Login.c_str(),
		params.Password.c_str(),
		params.ServerName.c_str(),
		params.SchemeName.c_str(),
		params.BaseFiles.c_str());

	
	if ((argc==2) && (!strcmp(argv[1],"i")))
		IndexData();
	return(StartServer(8090));
}
void LodOutputProviderBuffer::inject()
{
    unsigned short submeshCount = ushort(mBuffer.submesh.size());
    OgreAssert(mMesh->getNumSubMeshes() == submeshCount, "");
    mMesh->removeLodLevels();
    for (unsigned short i = 0; i < submeshCount; i++) {
        SubMesh::LODFaceList& lods = mMesh->getSubMesh(i)->mLodFaceList;
        typedef vector<LodIndexBuffer>::type GenBuffers;
        GenBuffers& buffers = mBuffer.submesh[i].genIndexBuffers;

        size_t buffCount = buffers.size();
        for (size_t n=0; n<buffCount;n++) {
            LodIndexBuffer& buff = buffers[n];
            size_t indexCount = (buff.indexBufferSize ? buff.indexBufferSize : buff.indexCount);
            OgreAssert((int)buff.indexCount >= 0, "");
            lods.push_back(OGRE_NEW IndexData());
            lods.back()->indexStart = buff.indexStart;
            lods.back()->indexCount = buff.indexCount;
            if(indexCount != 0) {
                if(n > 0 && buffers[n-1].indexBuffer == buff.indexBuffer){
                    lods.back()->indexBuffer = (*(++lods.rbegin()))->indexBuffer;
                } else {
                    lods.back()->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
                        buff.indexSize == 2 ?
                        HardwareIndexBuffer::IT_16BIT : HardwareIndexBuffer::IT_32BIT,
                        indexCount, mMesh->getIndexBufferUsage(), mMesh->isIndexBufferShadowed());
                    size_t sizeInBytes = lods.back()->indexBuffer->getSizeInBytes();
                    void* pOutBuff = lods.back()->indexBuffer->lock(0, sizeInBytes, HardwareBuffer::HBL_DISCARD);
                    memcpy(pOutBuff, buff.indexBuffer.get(), sizeInBytes);
                    lods.back()->indexBuffer->unlock();
                }
            }
        }
    }
}
	//-----------------------------------------------------------------------
	BillboardChain::BillboardChain(const String& name, size_t maxElements,
		size_t numberOfChains, bool useTextureCoords, bool useColours, bool dynamic)
		:MovableObject(name),
		mMaxElementsPerChain(maxElements),
		mChainCount(numberOfChains),
		mUseTexCoords(useTextureCoords),
		mUseVertexColour(useColours),
		mDynamic(dynamic),
		mVertexDeclDirty(true),
		mBuffersNeedRecreating(true),
		mBoundsDirty(true),
		mIndexContentDirty(true),
		mRadius(0.0f),
		mTexCoordDir(TCD_U),
		mFaceCamera(true),
		mNormalBase(Vector3::UNIT_X)
	{
		mVertexData = OGRE_NEW VertexData();
		mIndexData = OGRE_NEW IndexData();

		mOtherTexCoordRange[0] = 0.0f;
		mOtherTexCoordRange[1] = 1.0f;

		setupChainContainers();

		mVertexData->vertexStart = 0;
		// index data set up later
		// set basic white material
		//this->setMaterialName("BaseWhiteNoLighting");

	}
    //-----------------------------------------------------------------------
    void BspSceneManager::setWorldGeometry(const String& filename)
    {
        mLevel.setNull();
        // Check extension is .bsp
        char extension[6];
        size_t pos = filename.find_last_of(".");
		if( pos == String::npos )
            OGRE_EXCEPT(
				Exception::ERR_INVALIDPARAMS,
                "Unable to load world geometry. Invalid extension (must be .bsp).",
                "BspSceneManager::setWorldGeometry");

        strncpy(extension, filename.substr(pos + 1, filename.length() - pos).c_str(), 5);
		extension[5] = 0;

        if (stricmp(extension, "bsp"))
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
			"Unable to load world geometry. Invalid extension (must be .bsp).",
            "BspSceneManager::setWorldGeometry");

        // Load using resource manager
        mLevel = BspResourceManager::getSingleton().load(filename, 
            ResourceGroupManager::getSingleton().getWorldResourceGroupName());

		if (mLevel->isSkyEnabled())
		{
			// Quake3 is always aligned with Z upwards
			Quaternion q;
			q.FromAngleAxis(Radian(Math::HALF_PI), Vector3::UNIT_X);
			// Also draw last, and make close to camera (far clip plane is shorter)
			setSkyDome(true, mLevel->getSkyMaterialName(),
				mLevel->getSkyCurvature(), 12, 2000, false, q);
		}
		else
		{
			setSkyDome(false, StringUtil::BLANK);
		}

        // Init static render operation
        mRenderOp.vertexData = mLevel->mVertexData;
        // index data is per-frame
        mRenderOp.indexData = OGRE_NEW IndexData();
        mRenderOp.indexData->indexStart = 0;
        mRenderOp.indexData->indexCount = 0;
        // Create enough index space to render whole level
        mRenderOp.indexData->indexBuffer = HardwareBufferManager::getSingleton()
            .createIndexBuffer(
                HardwareIndexBuffer::IT_32BIT, // always 32-bit
                mLevel->mNumIndexes, 
                HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, false);

        mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
        mRenderOp.useIndexes = true;


    }
示例#6
0
    //------------------------------------------------------------------------
    void TerrainBatch::createGpuIndexData()
    {
        destroyGpuIndexData();

        if ( !mGpuIndexData )
        {
            // clone, using default buffer manager ie hardware
            mGpuIndexData = MG_NEW IndexData();
            populateIndexData();
        }
    }
示例#7
0
    //-----------------------------------------------------------------------
    SubMesh::SubMesh()
        : useSharedVertices(true)
        , operationType(RenderOperation::OT_TRIANGLE_LIST)
        , vertexData(0)
        , mMatInitialised(false)
        , mBoneAssignmentsOutOfDate(false)
		, mVertexAnimationType(VAT_NONE)
		, mBuildEdgesEnabled(true)
    {
		indexData = OGRE_NEW IndexData();
    }
	//-----------------------------------------------------------------------
	void InstanceBatchShader::setupIndices( const SubMesh* baseSubMesh )
	{
		mRenderOperation.indexData = OGRE_NEW IndexData();
		mRemoveOwnIndexData = true;	//Raise flag to remove our own index data in the end (not always needed)

		IndexData *thisIndexData = mRenderOperation.indexData;
		IndexData *baseIndexData = baseSubMesh->indexData;

		thisIndexData->indexStart = 0;
		thisIndexData->indexCount = baseIndexData->indexCount * mInstancesPerBatch;

		//TODO: Check numVertices is below max supported by GPU
		HardwareIndexBuffer::IndexType indexType = HardwareIndexBuffer::IT_16BIT;
		if( mRenderOperation.vertexData->vertexCount > 65535 )
			indexType = HardwareIndexBuffer::IT_32BIT;
		thisIndexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
													indexType, thisIndexData->indexCount,
													HardwareBuffer::HBU_STATIC_WRITE_ONLY );

		void *buf			= thisIndexData->indexBuffer->lock( HardwareBuffer::HBL_DISCARD );
		void const *baseBuf	= baseIndexData->indexBuffer->lock( HardwareBuffer::HBL_READ_ONLY );

		uint16 *thisBuf16 = static_cast<uint16*>(buf);
		uint32 *thisBuf32 = static_cast<uint32*>(buf);

		for( size_t i=0; i<mInstancesPerBatch; ++i )
		{
			const size_t vertexOffset = i * mRenderOperation.vertexData->vertexCount / mInstancesPerBatch;

			uint16 const *initBuf16 = static_cast<uint16 const *>(baseBuf);
			uint32 const *initBuf32 = static_cast<uint32 const *>(baseBuf);

			for( size_t j=0; j<baseIndexData->indexCount; ++j )
			{
				uint32 originalVal;
				if( baseSubMesh->indexData->indexBuffer->getType() == HardwareIndexBuffer::IT_16BIT )
					originalVal = *initBuf16++;
				else
					originalVal = *initBuf32++;

				if( indexType == HardwareIndexBuffer::IT_16BIT )
					*thisBuf16++ = static_cast<uint16>(originalVal) + vertexOffset;
				else
					*thisBuf32++ = static_cast<uint32>(originalVal + vertexOffset);
			}
		}

		baseIndexData->indexBuffer->unlock();
		thisIndexData->indexBuffer->unlock();
	}
示例#9
0
	//-----------------------------------------------------------------------------
	//--------------------------------------------------------------------------
	ManualObject::ManualObjectSectionShadowRenderable::ManualObjectSectionShadowRenderable(
		ManualObject* parent, HardwareIndexBufferSharedPtr* indexBuffer,
		const VertexData* vertexData, bool createSeparateLightCap,
		bool isLightCap)
		: mParent(parent)
	{
		// Initialise render op
		mRenderOp.indexData = OGRE_NEW IndexData();
		mRenderOp.indexData->indexBuffer = *indexBuffer;
		mRenderOp.indexData->indexStart = 0;
		// index start and count are sorted out later

		// Create vertex data which just references position component (and 2 component)
		mRenderOp.vertexData = OGRE_NEW VertexData();
		// Map in position data
		mRenderOp.vertexData->vertexDeclaration->addElement(0,0,VET_FLOAT3, VES_POSITION);
		ushort origPosBind =
			vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION)->getSource();
		mPositionBuffer = vertexData->vertexBufferBinding->getBuffer(origPosBind);
		mRenderOp.vertexData->vertexBufferBinding->setBinding(0, mPositionBuffer);
		// Map in w-coord buffer (if present)
		if(!vertexData->hardwareShadowVolWBuffer.isNull())
		{
			mRenderOp.vertexData->vertexDeclaration->addElement(1,0,VET_FLOAT1, VES_TEXTURE_COORDINATES, 0);
			mWBuffer = vertexData->hardwareShadowVolWBuffer;
			mRenderOp.vertexData->vertexBufferBinding->setBinding(1, mWBuffer);
		}
		// Use same vertex start as input
		mRenderOp.vertexData->vertexStart = vertexData->vertexStart;

		if (isLightCap)
		{
			// Use original vertex count, no extrusion
			mRenderOp.vertexData->vertexCount = vertexData->vertexCount;
		}
		else
		{
			// Vertex count must take into account the doubling of the buffer,
			// because second half of the buffer is the extruded copy
			mRenderOp.vertexData->vertexCount =
				vertexData->vertexCount * 2;
			if (createSeparateLightCap)
			{
				// Create child light cap
				mLightCap = OGRE_NEW ManualObjectSectionShadowRenderable(parent,
					indexBuffer, vertexData, false, true);
			}
		}
	}
示例#10
0
	IndexData* IndexData::clone(BOOL copyData /* = TRUE */, HardwareBufferManagerBase* mgr /* = 0 */) const 
	{
		HardwareBufferManagerBase* pManager = mgr ? mgr : HardwareBufferManager::getSingletonPtr();
		IndexData* dest = WIND_NEW IndexData();
		if (indexBuffer.get())
		{
			if (copyData)
			{
				dest->indexBuffer = pManager->createIndexBuffer(indexBuffer->getType(), indexBuffer->getNumIndexes(), indexBuffer->getUsage(), indexBuffer->hasShadowBuffer());
				dest->indexBuffer->copyData(*indexBuffer, 0, 0, indexBuffer->getSizeInBytes(), TRUE);
			}
			else
			{
				dest->indexBuffer = indexBuffer;
			}
		}
		dest->indexCount = indexCount;
		dest->indexStart = indexStart;
		return dest;
	}
    //-----------------------------------------------------------------------
    void BspSceneManager::setWorldGeometry(DataStreamPtr& stream, 
		const String& typeName)
    {
        mLevel.setNull();

        // Load using resource manager
        mLevel = BspResourceManager::getSingleton().load(stream, 
			ResourceGroupManager::getSingleton().getWorldResourceGroupName());

		if (mLevel->isSkyEnabled())
		{
			// Quake3 is always aligned with Z upwards
			Quaternion q;
			q.FromAngleAxis(Radian(Math::HALF_PI), Vector3::UNIT_X);
			// Also draw last, and make close to camera (far clip plane is shorter)
			setSkyDome(true, mLevel->getSkyMaterialName(),
				mLevel->getSkyCurvature(), 12, 2000, false, q);
		}
		else
		{
			setSkyDome(false, StringUtil::BLANK);
		}

        // Init static render operation
        mRenderOp.vertexData = mLevel->mVertexData;
        // index data is per-frame
        mRenderOp.indexData = OGRE_NEW IndexData();
        mRenderOp.indexData->indexStart = 0;
        mRenderOp.indexData->indexCount = 0;
        // Create enough index space to render whole level
        mRenderOp.indexData->indexBuffer = HardwareBufferManager::getSingleton()
            .createIndexBuffer(
                HardwareIndexBuffer::IT_32BIT, // always 32-bit
                mLevel->mNumIndexes, 
                HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, false);

        mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
        mRenderOp.useIndexes = true;


    }
示例#12
0
	//------------------------------------------------------------------------------//
	void GeoTerrainSection::_createConnectorRend()
	{
		for(int i = 0;i < GeoTerrain::TotalSides; ++i)
		{
			mConnectorRends[i].setCreator(this);
			mConnectorRends[i].setSectionPos(mSectionPos);
			RenderData* rend = mConnectorRends[i].getRenderData();
			rend->vertexData = TITAN_NEW VertexData(mCreator->getVertexDecl(),mVertexBufferBinding);
			rend->vertexData->vertexCount = mCreator->getHorzVertexData()->getNumVertices();

			rend->useIndex = true;
			rend->indexData = TITAN_NEW IndexData();
			rend->indexData->indexStart = 0;

			Vector4 uvScaleOffset = Vector4((float)1.0f/(mCreator->getSectorCountX()+1),
				(float)1.0f/(mCreator->getSectorCountZ()+1),
				(float)mSectorX,
				(float)mSectorZ);
			mConnectorRends[i].setCustomShaderParam(0, uvScaleOffset);
		}
	}
示例#13
0
	//-----------------------------------------------------------------------------
	void ManualObject::index(uint32 idx)
	{
		if (!mCurrentSection)
		{
			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
				"You must call begin() before this method",
				"ManualObject::index");
		}
		mAnyIndexed = true;
		if (idx >= 65536)
			mCurrentSection->set32BitIndices(true);

		// make sure we have index data
		RenderOperation* rop = mCurrentSection->getRenderOperation();
		if (!rop->indexData)
		{
			rop->indexData = OGRE_NEW IndexData();
			rop->indexData->indexCount = 0;
		}
		rop->useIndexes = true;
		resizeTempIndexBufferIfNeeded(++rop->indexData->indexCount);

		mTempIndexBuffer[rop->indexData->indexCount - 1] = idx;
	}
    void LodOutputProviderCompressedMesh::bakeSecondPass(LodData* data, int lodIndex) {
        unsigned short submeshCount = mMesh->getNumSubMeshes();
        assert(mTriangleCacheList.size() == data->mTriangleList.size());
        assert(lodIndex > mLastIndexBufferID); // Implementation limitation
        // Create buffers.
        for (unsigned short i = 0; i < submeshCount; i++) {
            SubMesh::LODFaceList& lods = mMesh->getSubMesh(i)->mLodFaceList;
            lods.reserve(lods.size() + 2);
            size_t indexCount = data->mIndexBufferInfoList[i].indexCount + data->mIndexBufferInfoList[i].prevOnlyIndexCount;
            assert(data->mIndexBufferInfoList[i].prevIndexCount >= data->mIndexBufferInfoList[i].indexCount);
            assert(data->mIndexBufferInfoList[i].prevIndexCount >= data->mIndexBufferInfoList[i].prevOnlyIndexCount);
            
            IndexData* prevLod = *lods.insert(lods.begin() + mLastIndexBufferID, OGRE_NEW IndexData());
            prevLod->indexStart = 0;

            //If the index is empty we need to create a "dummy" triangle, just to keep the index buffer from being empty.
            //The main reason for this is that the OpenGL render system will crash with a segfault unless the index has some values.
            //This should hopefully be removed with future versions of Ogre. The most preferred solution would be to add the
            //ability for a submesh to be excluded from rendering for a given LOD (which isn't possible currently 2012-12-09).
            indexCount = std::max<size_t>(indexCount, 3);
            prevLod->indexCount = std::max<size_t>(data->mIndexBufferInfoList[i].prevIndexCount, 3u);

            prevLod->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(
                data->mIndexBufferInfoList[i].indexSize == 2 ?
                HardwareIndexBuffer::IT_16BIT : HardwareIndexBuffer::IT_32BIT,
                indexCount, mMesh->getIndexBufferUsage(), mMesh->isIndexBufferShadowed());

            data->mIndexBufferInfoList[i].buf.pshort =
                static_cast<unsigned short*>(prevLod->indexBuffer->lock(0, prevLod->indexBuffer->getSizeInBytes(),
                HardwareBuffer::HBL_DISCARD));

            //Check if we should fill it with a "dummy" triangle.
            if (indexCount == 3) {
                memset(data->mIndexBufferInfoList[i].buf.pshort, 0, 3 * data->mIndexBufferInfoList[i].indexSize);
            }

            // Set up the other Lod
            IndexData* curLod = *lods.insert(lods.begin() + lodIndex, OGRE_NEW IndexData());
            curLod->indexStart = indexCount - data->mIndexBufferInfoList[i].indexCount;
            curLod->indexCount = data->mIndexBufferInfoList[i].indexCount;
            if(curLod->indexCount == 0){
                curLod->indexStart-=3;
                curLod->indexCount=3;
            }
        }

        // Fill buffers.
        // Filling will be done in 3 parts.
        // 1. prevLod only indices.
        size_t triangleCount = mTriangleCacheList.size();
        for (size_t i = 0; i < triangleCount; i++) {
            if (mTriangleCacheList[i].vertexChanged) {
                assert(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].prevIndexCount != 0);
                assert(mTriangleCacheList[i].vertexID[0] != mTriangleCacheList[i].vertexID[1]);
                assert(mTriangleCacheList[i].vertexID[1] != mTriangleCacheList[i].vertexID[2]);
                assert(mTriangleCacheList[i].vertexID[2] != mTriangleCacheList[i].vertexID[0]);
                if (data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].indexSize == 2) {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pshort++) =
                            static_cast<unsigned short>(mTriangleCacheList[i].vertexID[m]);
                    }
                } else {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pint++) =
                            static_cast<unsigned int>(mTriangleCacheList[i].vertexID[m]);
                    }
                }
            }
        }


        // 2. shared indices.
        for (size_t i = 0; i < triangleCount; i++) {
            if (!data->mTriangleList[i].isRemoved && !mTriangleCacheList[i].vertexChanged) {
                assert(mTriangleCacheList[i].vertexID[0] == data->mTriangleList[i].vertexID[0]);
                assert(mTriangleCacheList[i].vertexID[1] == data->mTriangleList[i].vertexID[1]);
                assert(mTriangleCacheList[i].vertexID[2] == data->mTriangleList[i].vertexID[2]);

                assert(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].indexCount != 0);
                assert(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].prevIndexCount != 0);
                if (data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].indexSize == 2) {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pshort++) =
                            static_cast<unsigned short>(data->mTriangleList[i].vertexID[m]);
                    }
                } else {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pint++) =
                            static_cast<unsigned int>(data->mTriangleList[i].vertexID[m]);
                    }
                }
            }
        }

        // 3. curLod indices only.
        for (size_t i = 0; i < triangleCount; i++) {
            if (!data->mTriangleList[i].isRemoved && mTriangleCacheList[i].vertexChanged) {
                assert(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].indexCount != 0);
                if (data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].indexSize == 2) {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pshort++) =
                            static_cast<unsigned short>(data->mTriangleList[i].vertexID[m]);
                    }
                } else {
                    for (int m = 0; m < 3; m++) {
                        *(data->mIndexBufferInfoList[data->mTriangleList[i].submeshID].buf.pint++) =
                            static_cast<unsigned int>(data->mTriangleList[i].vertexID[m]);
                    }
                }
            }
        }

        // Close buffers.
        for (unsigned short i = 0; i < submeshCount; i++) {
            SubMesh::LODFaceList& lods = mMesh->getSubMesh(i)->mLodFaceList;
            IndexData* prevLod = lods[mLastIndexBufferID];
            IndexData* curLod = lods[lodIndex];
            prevLod->indexBuffer->unlock();
            curLod->indexBuffer = prevLod->indexBuffer;
        }
    }
    //---------------------------------------------------------------------
    void ProgressiveMesh::build(ushort numLevels, LODFaceList* outList, 
			VertexReductionQuota quota, Real reductionValue)
    {
        IndexData* newLod;

        computeAllCosts();

#if OGRE_DEBUG_MODE
		dumpContents("pm_before.log");
#endif

        // Init
        mCurrNumIndexes = mpIndexData->indexCount;
        size_t numVerts, numCollapses;
        // Use COMMON vert count, not original vert count
        // Since collapsing 1 common vert position is equivalent to collapsing them all
        numVerts = mNumCommonVertices;
		
#if OGRE_DEBUG_MODE 
		ofdebug.open("progressivemesh.log");
#endif
		numCollapses = 0;
		bool abandon = false;
		while (numLevels--)
        {
            // NB idf 'abandon' is set, we stop reducing 
            // However, we still bake the number of LODs requested, even if it 
            // means they are the same
            if (!abandon)
            {
			    if (quota == VRQ_PROPORTIONAL)
			    {
				    numCollapses = static_cast<size_t>(numVerts * reductionValue);
			    }
			    else 
			    {
				    numCollapses = static_cast<size_t>(reductionValue);
			    }
                // Minimum 3 verts!
                if ( (numVerts - numCollapses) < 3) 
                    numCollapses = numVerts - 3;
			    // Store new number of verts
			    numVerts = numVerts - numCollapses;

			    while(numCollapses-- && !abandon)
                {
                    size_t nextIndex = getNextCollapser();
                    // Collapse on every buffer
                    WorkingDataList::iterator idata, idataend;
                    idataend = mWorkingData.end();
                    for (idata = mWorkingData.begin(); idata != idataend; ++idata)
                    {
                        PMVertex* collapser = &( idata->mVertList.at( nextIndex ) );
                        // This will reduce mCurrNumIndexes and recalc costs as required
					    if (collapser->collapseTo == NULL)
					    {
						    // Must have run out of valid collapsables
						    abandon = true;
						    break;
					    }
#if OGRE_DEBUG_MODE 
					    ofdebug << "Collapsing index " << (unsigned int)collapser->index << "(border: "<< collapser->isBorder() <<
						    ") to " << (unsigned int)collapser->collapseTo->index << "(border: "<< collapser->collapseTo->isBorder() <<
						    ")" << std::endl;
#endif
					    assert(collapser->collapseTo->removed == false);

                        collapse(collapser);
                    }

                }
            }
#if OGRE_DEBUG_MODE
			StringUtil::StrStreamType logname;
			logname << "pm_level" << numLevels << ".log";
			dumpContents(logname.str());
#endif

            // Bake a new LOD and add it to the list
            newLod = OGRE_NEW IndexData();
            bakeNewLOD(newLod);
            outList->push_back(newLod);
			
        }



    }
示例#16
0
		void Bitmap::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
		{
			HRESULT hr;

			m_VertexCount = 6;
			m_IndexCount = 6;

			std::vector<Vertex> VertexData(6);
			std::vector<UINT> IndexData(6);

			for (int i = 0; i != m_IndexCount; ++i)
			{
				IndexData[i] = i;
			}
			// Calculate the screen coordinates of the left side of the bitmap.
			float left = (float)((m_sw / 2) * -1) + (float)m_posX;

			// Calculate the screen coordinates of the right side of the bitmap.
			float  right = left + (float)m_width;

			// Calculate the screen coordinates of the top of the bitmap.
			float  top = (float)(m_sh / 2) - (float)m_posY;

			// Calculate the screen coordinates of the bottom of the bitmap.
			float  bottom = top - (float)m_height;

			// First triangle.
			VertexData[0].Pos = XMFLOAT3(left, top, 0.0f);  // Top left.
			VertexData[0].Tex = XMFLOAT2(0.0f, 0.0f);

			VertexData[1].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
			VertexData[1].Tex = XMFLOAT2(1.0f, 1.0f);

			VertexData[2].Pos = XMFLOAT3(left, bottom, 0.0f);  // Bottom left.
			VertexData[2].Tex = XMFLOAT2(0.0f, 1.0f);

			// Second triangle.
			VertexData[3].Pos = XMFLOAT3(left, top, 0.0f);  // Bottom left.
			VertexData[3].Tex = XMFLOAT2(0.0f, 0.0f);

			VertexData[4].Pos = XMFLOAT3(right, top, 0.0f); // Top right.
			VertexData[4].Tex = XMFLOAT2(1.0f, 0.0f);

			VertexData[5].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
			VertexData[5].Tex = XMFLOAT2(1.0f, 1.0f);

			///////////////////////////Index Buffer ////////////////////////////////

			// Set up the description of the static vertex buffer.
			D3D11_BUFFER_DESC VertexBufferDesc;
			VertexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
			VertexBufferDesc.ByteWidth           = sizeof(Vertex) * m_VertexCount;
			VertexBufferDesc.BindFlags           = D3D11_BIND_VERTEX_BUFFER;
			VertexBufferDesc.CPUAccessFlags      = 0;
			VertexBufferDesc.MiscFlags           = 0;
			VertexBufferDesc.StructureByteStride = 0;

			// Give the subresource structure a pointer to the vertex data.
			D3D11_SUBRESOURCE_DATA VBO;
			VBO.pSysMem          = &VertexData[0];
			VBO.SysMemPitch      = 0;
			VBO.SysMemSlicePitch = 0;

			// Now create the vertex buffer.
			hr = pD3D11Device->CreateBuffer(&VertexBufferDesc, &VBO, &m_pVertexBuffer);
			DebugHR(hr);

			/////////////////////////////////Index Buffer ///////////////////////////////////////

			// Set up the description of the static index buffer.
			D3D11_BUFFER_DESC IndexBufferDesc;
			IndexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
			IndexBufferDesc.ByteWidth           = sizeof(UINT) * m_IndexCount;
			IndexBufferDesc.BindFlags           = D3D11_BIND_INDEX_BUFFER;
			IndexBufferDesc.CPUAccessFlags      = 0;
			IndexBufferDesc.MiscFlags           = 0;
			IndexBufferDesc.StructureByteStride = 0;

			// Give the subresource structure a pointer to the index data.
			D3D11_SUBRESOURCE_DATA IBO;
			IBO.pSysMem          = &IndexData[0];
			IBO.SysMemPitch      = 0;
			IBO.SysMemSlicePitch = 0;

			hr = pD3D11Device->CreateBuffer(&IndexBufferDesc, &IBO, &m_pIndexBuffer);
			DebugHR(hr);

			////////////////////////////////MVP Buffer//////////////////////////////////////

			D3D11_BUFFER_DESC mvpBufferDesc;
			ZeroMemory(&mvpBufferDesc, sizeof(D3D11_BUFFER_DESC));
			mvpBufferDesc.Usage          = D3D11_USAGE_DEFAULT;
			mvpBufferDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
			mvpBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
			mvpBufferDesc.CPUAccessFlags = 0;
			mvpBufferDesc.MiscFlags      = 0;
			hr = pD3D11Device->CreateBuffer(&mvpBufferDesc, NULL, &m_pMVPBuffer);
			DebugHR(hr);

			// Create a texture sampler state description.
			D3D11_SAMPLER_DESC samplerDesc;
			samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
			samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
			samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
			samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
			samplerDesc.MipLODBias = 0.0f;
			samplerDesc.MaxAnisotropy = 1;
			samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
			samplerDesc.BorderColor[0] = 0;
			samplerDesc.BorderColor[1] = 0;
			samplerDesc.BorderColor[2] = 0;
			samplerDesc.BorderColor[3] = 0;
			samplerDesc.MinLOD = 0;
			samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

			// Create the texture sampler state.
			hr = pD3D11Device->CreateSamplerState(&samplerDesc, &m_pTexSamplerState);
			DebugHR(hr);
		}
    //---------------------------------------------------------------------
    void BorderPanelOverlayElement::initialise(void)
    {
		bool init = !mInitialised;

        PanelOverlayElement::initialise();

        // superclass will handle the interior panel area 

        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);

			// Vertex buffer #1, position
			HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton()
				.createVertexBuffer(
					decl->getVertexSize(POSITION_BINDING), 
					mRenderOp2.vertexData->vertexCount,
					HardwareBuffer::HBU_STATIC_WRITE_ONLY);
			// bind position
			VertexBufferBinding* binding = mRenderOp2.vertexData->vertexBufferBinding;
			binding->setBinding(POSITION_BINDING, vbuf);

			// Vertex buffer #2, texcoords
			vbuf = HardwareBufferManager::getSingleton()
				.createVertexBuffer(
					decl->getVertexSize(TEXCOORD_BINDING), 
					mRenderOp2.vertexData->vertexCount,
					HardwareBuffer::HBU_STATIC_WRITE_ONLY, true);
			// bind texcoord
			binding->setBinding(TEXCOORD_BINDING, vbuf);

			mRenderOp2.operationType = RenderOperation::OT_TRIANGLE_LIST;
			mRenderOp2.useIndexes = true;
			// Index data
			mRenderOp2.indexData = OGRE_NEW IndexData();
			mRenderOp2.indexData->indexCount = 8 * 6;
			mRenderOp2.indexData->indexStart = 0;
            mRenderOp2.useGlobalInstancingVertexBufferIsAvailable = false;

			/* Each cell is
				0-----2
				|    /|
				|  /  |
				|/    |
				1-----3
			*/
			mRenderOp2.indexData->indexBuffer = HardwareBufferManager::getSingleton().
				createIndexBuffer(
					HardwareIndexBuffer::IT_16BIT, 
					mRenderOp2.indexData->indexCount, 
					HardwareBuffer::HBU_STATIC_WRITE_ONLY);

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

			for (ushort cell = 0; cell < 8; ++cell)
			{
				ushort base = cell * 4;
				*pIdx++ = base;
				*pIdx++ = base + 1;
				*pIdx++ = base + 2;

				*pIdx++ = base + 2;
				*pIdx++ = base + 1;
				*pIdx++ = base + 3;
			}

			mRenderOp2.indexData->indexBuffer->unlock();

			// Create sub-object for rendering border
			mBorderRenderable = OGRE_NEW BorderRenderable(this);

			mInitialised = true;
		}
    }
    size_t MeshBuilder::generateBuffers(RenderOperation &operation)
    {
        // Early out if nothing to do.
        if (mIndices.size() == 0)
        {
            return 0;
        }

        // Prepare vertex buffer
        operation.operationType = RenderOperation::OT_TRIANGLE_LIST;

        operation.vertexData = OGRE_NEW VertexData();
        operation.vertexData->vertexCount = mVertices.size();
        operation.vertexData->vertexStart = 0;
    
        VertexDeclaration *decl = operation.vertexData->vertexDeclaration;
        VertexBufferBinding *bind = operation.vertexData->vertexBufferBinding;
    
        size_t offset = 0;

        // Add vertex-positions to the buffer
        decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
        offset += VertexElement::getTypeSize(VET_FLOAT3);
    
        // Add vertex-normals to the buffer
        decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
    
        HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
            decl->getVertexSize(MAIN_BINDING),
            operation.vertexData->vertexCount,
            HardwareBuffer::HBU_STATIC_WRITE_ONLY);
    
        bind->setBinding(0, vbuf);

        float* vertices = static_cast<float*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
    
        VecVertex::const_iterator endVertices = mVertices.end();
        for (VecVertex::const_iterator iter = mVertices.begin(); iter != endVertices; ++iter)
        {
            *vertices++ = (float)iter->x;
            *vertices++ = (float)iter->y;
            *vertices++ = (float)iter->z;
            *vertices++ = (float)iter->nX;
            *vertices++ = (float)iter->nY;
            *vertices++ = (float)iter->nZ;
        }

        vbuf->unlock();
    
        // Get Indexarray
        operation.indexData = OGRE_NEW IndexData();
        operation.indexData->indexCount = mIndices.size();
        operation.indexData->indexStart = 0;
    
        VecIndices::const_iterator endIndices = mIndices.end();
        if (operation.indexData->indexCount > USHRT_MAX)
        {
            operation.indexData->indexBuffer =
                HardwareBufferManager::getSingleton().createIndexBuffer(
                HardwareIndexBuffer::IT_32BIT,
                operation.indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);

            unsigned int* indices = static_cast<unsigned int*>(
                operation.indexData->indexBuffer->lock(0,
                    operation.indexData->indexBuffer->getSizeInBytes(),
                    HardwareBuffer::HBL_DISCARD));
    
            for (VecIndices::const_iterator iter = mIndices.begin(); iter != endIndices; ++iter)
            {
                *indices++ = *iter;
            }
        }
        else
        {
            operation.indexData->indexBuffer =
                HardwareBufferManager::getSingleton().createIndexBuffer(
                HardwareIndexBuffer::IT_16BIT,
                operation.indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);

            unsigned short* indices = static_cast<unsigned short*>(
                operation.indexData->indexBuffer->lock(0,
                    operation.indexData->indexBuffer->getSizeInBytes(),
                    HardwareBuffer::HBL_DISCARD));
    
            for (VecIndices::const_iterator iter = mIndices.begin(); iter != endIndices; ++iter)
            {
                *indices++ = (unsigned short)*iter;
            }
        }

        operation.indexData->indexBuffer->unlock();
        return mIndices.size() / 3;
    }
示例#19
0
void TextSprite::createGeometry()
{
	Model::GroupMap &groups = getGroups();
	GeometryPtr &g = groups[bRenderer::DEFAULT_GROUP_NAME()];
	if (!g)
		g = GeometryPtr(new Geometry);

	GeometryDataPtr gData = GeometryDataPtr(new GeometryData);

	GLuint verNum = 6;
	GLuint fontPixelSize = _font->getPixelSize();
	// Initialize position of the first sprite
	GLfloat pos_x = 0.f;
	GLfloat pos_y = 0.f;
	GLfloat z = 0.f;
	bool beginningofLine = true;

	// Create a sprite per character
	for (GLuint i = 0; i < _text.length(); i++){
		if (_text.at(i) == '\n')
		{
			beginningofLine = true;
			pos_x = 0.f;
			pos_y -= 1.0f;
			// The line break has to be erased instead of just increasing i
			// otherwise the indices wouldn't be correct anymore
			_text.erase(_text.begin() + i);
			// If the line break was at the end of the string we have to leave the loop
			if (i >= _text.length())
				break;
		}

		// load character
		ftgl::texture_glyph_t* glyph = _font->getCharacter(_text.at(i));

		if (glyph != NULL)
		{

			GLfloat u0 = glyph->s0;
			GLfloat v0 = glyph->t0;
			GLfloat u1 = glyph->s1;
			GLfloat v1 = glyph->t1;

			GLfloat x0 = pos_x + (beginningofLine ? 0.f : (static_cast<GLfloat>(glyph->offset_x) / fontPixelSize));
			GLfloat y0 = pos_y + (static_cast<GLfloat>(glyph->offset_y) / fontPixelSize);
			GLfloat x1 = x0 + (static_cast<GLfloat>(glyph->width) / fontPixelSize);
			GLfloat y1 = y0 - (static_cast<GLfloat>(glyph->height) / fontPixelSize);

			pos_x += static_cast<GLfloat>(glyph->advance_x) / fontPixelSize;
			pos_y += static_cast<GLfloat>(glyph->advance_y) / fontPixelSize;

			beginningofLine = false;

			// Add vertices
			gData->vboVertices.push_back(Vertex(
				x0, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v0						// texCoord
			));
			gData->vboVertices.push_back(Vertex(
				x1, y1, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v1						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x1, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v0						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x0, y0, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v0						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x0, y1, z, 					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u0, v1						// texCoord
				));
			gData->vboVertices.push_back(Vertex(
				x1, y1, z,					// position
				0.0f, 0.0f, -1.0f,			// normal
				-1.0f, 0.0f, 0.0f,			// tangent
				0.0f, 1.0f, 0.0f,			// bitangent
				u1, v1						// texCoord	
				));

			// Add indices
			for (GLushort j = (0 + i*verNum); j < (6 + i*verNum); j++)
				gData->vboIndices.push_back(j);

			// Add index data
			gData->indices.push_back(IndexData(3 + i*verNum, 2 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(2 + i*verNum, 1 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(0 + i*verNum, 0 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(1 + i*verNum, 5 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(3 + i*verNum, 4 + i*verNum, 0 + i*verNum));
			gData->indices.push_back(IndexData(0 + i*verNum, 3 + i*verNum, 0 + i*verNum));
		}
	}

	g->initialize(gData);

	setBoundingBoxObjectSpace(g->getBoundingBoxObjectSpace());
}
示例#20
0
	void D3DBitmap::init_buffer(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext)
	{
		HRESULT hr;
	
		m_VertexCount = 6;
		m_IndexCount = 6;
	
		std::vector<Vertex> VertexData(6);
		std::vector<UINT> IndexData(6);
	
		for (int i = 0; i != m_IndexCount; ++i)
		{
			IndexData[i] = i;
		}
		// Calculate the screen coordinates of the left side of the D3DBitmap.
		float left = (float)((m_sw / 2) * -1) + (float)m_posX;
	
		// Calculate the screen coordinates of the right side of the D3DBitmap.
		float  right = left + (float)m_width;
	
		// Calculate the screen coordinates of the top of the D3DBitmap.
		float  top = (float)(m_sh / 2) - (float)m_posY;
	
		// Calculate the screen coordinates of the bottom of the D3DBitmap.
		float  bottom = top - (float)m_height;
	
		// First triangle.
		VertexData[0].Pos = XMFLOAT3(left, top, 0.0f);  // Top left.
		VertexData[0].Tex = XMFLOAT2(0.0f, 0.0f);
	
		VertexData[1].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
		VertexData[1].Tex = XMFLOAT2(1.0f, 1.0f);
	
		VertexData[2].Pos = XMFLOAT3(left, bottom, 0.0f);  // Bottom left.
		VertexData[2].Tex = XMFLOAT2(0.0f, 1.0f);
	
		// Second triangle.
		VertexData[3].Pos = XMFLOAT3(left, top, 0.0f);  // Bottom left.
		VertexData[3].Tex = XMFLOAT2(0.0f, 0.0f);
	
		VertexData[4].Pos = XMFLOAT3(right, top, 0.0f); // Top right.
		VertexData[4].Tex = XMFLOAT2(0.0f, 1.0f);
	
		VertexData[5].Pos = XMFLOAT3(right, bottom, 0.0f);  // Bottom right.
		VertexData[5].Tex = XMFLOAT2(1.0f, 1.0f);
	
		///////////////////////////Index Buffer ////////////////////////////////
	
		// Set up the description of the static vertex buffer.
		D3D11_BUFFER_DESC VertexBufferDesc;
		VertexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
		VertexBufferDesc.ByteWidth           = sizeof(Vertex) * m_VertexCount;
		VertexBufferDesc.BindFlags           = D3D11_BIND_VERTEX_BUFFER;
		VertexBufferDesc.CPUAccessFlags      = 0;
		VertexBufferDesc.MiscFlags           = 0;
		VertexBufferDesc.StructureByteStride = 0;
	
		// Give the subresource structure a pointer to the vertex data.
		D3D11_SUBRESOURCE_DATA VBO;
		VBO.pSysMem          = &VertexData[0];
		VBO.SysMemPitch      = 0;
		VBO.SysMemSlicePitch = 0;
	
		// Now create the vertex buffer.
		hr = pD3D11Device->CreateBuffer(&VertexBufferDesc, &VBO, &m_pVertexBuffer);
		DebugHR(hr);
	
		/////////////////////////////////Index Buffer ///////////////////////////////////////
	
		// Set up the description of the static index buffer.
		D3D11_BUFFER_DESC IndexBufferDesc;
		IndexBufferDesc.Usage               = D3D11_USAGE_DEFAULT;
		IndexBufferDesc.ByteWidth           = sizeof(UINT) * m_IndexCount;
		IndexBufferDesc.BindFlags           = D3D11_BIND_INDEX_BUFFER;
		IndexBufferDesc.CPUAccessFlags      = 0;
		IndexBufferDesc.MiscFlags           = 0;
		IndexBufferDesc.StructureByteStride = 0;
	
		// Give the subresource structure a pointer to the index data.
		D3D11_SUBRESOURCE_DATA IBO;
		IBO.pSysMem          = &IndexData[0];
		IBO.SysMemPitch      = 0;
		IBO.SysMemSlicePitch = 0;
	
		hr = pD3D11Device->CreateBuffer(&IndexBufferDesc, &IBO, &m_pIndexBuffer);
		DebugHR(hr);
	
		////////////////////////////////MVP Buffer//////////////////////////////////////
	
		D3D11_BUFFER_DESC mvpBufferDesc;
		ZeroMemory(&mvpBufferDesc, sizeof(D3D11_BUFFER_DESC));
		mvpBufferDesc.Usage          = D3D11_USAGE_DEFAULT;
		mvpBufferDesc.ByteWidth      = sizeof(d3d::MatrixBuffer);
		mvpBufferDesc.BindFlags      = D3D11_BIND_CONSTANT_BUFFER;
		mvpBufferDesc.CPUAccessFlags = 0;
		mvpBufferDesc.MiscFlags      = 0;
		hr = pD3D11Device->CreateBuffer(&mvpBufferDesc, NULL, &m_pMVPBuffer);
		DebugHR(hr);
	
	}
示例#21
0
	//-------------------------------------------------------------------------------//
	void ChunkTerrainSection::_recursiveTessellate(float distA, float distB, float distC, float distD, int level, int levelX, int levelZ, float vScale, float vLimit)
	{
		bool split = false;
		// can we attempt to split?
		if (level+1 < mTotalLevels)
		{
			int index = (levelZ*LEVEL_SIDE_LENGTH(level))+levelX;
			float errorMetric = mErrorMerticTree[level][index];

			// find the shortest distance
			float dist = minimum(distA, distB);
			dist = minimum(dist, distC);
			dist = minimum(dist, distD);

			// find the ratio of errorMetric over distance
			float vRatio = (errorMetric*vScale)/(dist+0.0001f);

			// if we exceed the ratio limit, split
			if (vRatio > vLimit)
			{
				int nextLevel = level+1;
				int startX = levelX<<1;
				int startZ = levelZ<<1;

				// compute midpoint distances
				float midAB = (distA + distB)*0.5f;
				float midBC = (distB + distC)*0.5f;
				float midCD = (distC + distD)*0.5f;
				float midDA = (distD + distA)*0.5f;
				float midQuad = (distA + distC)*0.5f;

				// recurse through the four children
				_recursiveTessellate(
					distA, midAB, midQuad, midDA,
					nextLevel, startX, startZ,
					vScale, vLimit);

				_recursiveTessellate(
					midAB, distB, midBC, midQuad,
					nextLevel, startX, startZ+1,
					vScale, vLimit);

				_recursiveTessellate(
					midBC, distC, midCD, midQuad,
					nextLevel, startX+1, startZ+1,
					vScale, vLimit);

				_recursiveTessellate(
					midAB, midQuad, midCD, distD,
					nextLevel, startX+1, startZ,
					vScale, vLimit);

				// remember that we split
				split = true;

			}
		}

		// did we split?
		if (!split)
		{
			// add ourselves to the renderable list
			uint8 lodShift = 5 - level;
			uint8 offsetX = levelX << lodShift;
			uint8 offsetZ = levelZ << lodShift;
			uint16 vertexStride = (1 << mCreator->getSectorShift()) + 1;
			uint16 rendBaseVertex = (offsetZ * vertexStride) + offsetX;
#if 1
			ChunkTerrain* cTerrain = static_cast<ChunkTerrain*>(mCreator);
			TerrainSectionRend* chunkRend = TITAN_NEW TerrainSectionRend(this);
			chunkRend->setSectionPos(getSectionPos());
			int vertexCount = mCreator->getSectorVertex() * mCreator->getSectorVertex();
			RenderData* rend;
			rend = chunkRend->getRenderData();
			rend->operationType = OT_TRIANGLE_STRIP;
			rend->vertexData = TITAN_NEW VertexData(mCreator->getVertexDecl(),mVertexBufferBinding);
			rend->vertexData->vertexStart = rendBaseVertex;
			rend->vertexData->vertexCount = vertexCount;
			rend->useIndex = true;
			rend->indexData = TITAN_NEW IndexData();
			rend->indexData->indexBuffer = cTerrain->getLodIndexBuffer(0, level);
			rend->indexData->indexStart = 0;
			rend->indexData->indexCount = rend->indexData->indexBuffer->getNumIndexes();
			mTerrainSectionRendVec.push_back(chunkRend);


			RenderData* rend2;
			TerrainSectionRend* skirtRend = TITAN_NEW TerrainSectionRend(this);
			skirtRend->setSectionPos(getSectionPos());
			rend2 = skirtRend->getRenderData();
			rend2->operationType = OT_TRIANGLE_STRIP;
			rend2->vertexData = TITAN_NEW VertexData(mCreator->getVertexDecl(),mVertexBufferBinding);
			rend2->vertexData->vertexStart = rendBaseVertex;
			rend2->vertexData->vertexCount = vertexCount;
			rend2->useIndex = true;
			rend2->indexData = TITAN_NEW IndexData();
			rend2->indexData->indexBuffer = cTerrain->getLodIndexBuffer(1, level);
			rend2->indexData->indexStart = 0;
			rend2->indexData->indexCount = rend2->indexData->indexBuffer->getNumIndexes();
			mTerrainSectionRendVec.push_back(skirtRend);
#endif
		}

	}