//-----------------------------------------------------------------------
	void MeshReadHelper::lockVertexBuffer()
	{
		VertexData* vertexData = mCurSubMeshInfoV->vertexData;
		if(vertexData == mVertexData)
			return; // 

		if(!vertexData)
		{
			unlockVertexBuffer();
			return; // error, exiting with mIndexPtr == nullptr
		}

		mVertexData = vertexData;

		const VertexElement* positionElem = mVertexData->vertexDeclaration->findElementBySemantic(VES_POSITION);
		if(!positionElem)
		{
			unlockVertexBuffer();
			return; // error, exiting with mIndexPtr == nullptr
		}

		mVertexOffset = positionElem->getOffset();
		mVertexType   = positionElem->getType();

		HardwareVertexBufferSharedPtr vertexBuffer = mVertexData->vertexBufferBinding->getBuffer(positionElem->getSource());
		if(vertexBuffer == mVertexBuffer)
			return; // continue using the same buffer

		unlockVertexBuffer();

		mVertexData = vertexData;
		mVertexBuffer = vertexBuffer;

		if(mVertexBuffer.isNull())
			return; // error, exiting with mIndexPtr == nullptr

		mVertexSize = mVertexBuffer->getVertexSize();

		assert(mVertexPtr == nullptr);
		if(mVertexBuffer == mTexCoordBuffer)
		{
			mVertexPtr = mTexCoordPtr;
		}
		else
		{
			mVertexPtr = mVertexBuffer->lock( HardwareBuffer::HBL_READ_ONLY );
		}
	}
	//-----------------------------------------------------------------------
	void MeshReadHelper::unlockAllBuffers()
	{
		unlockIndexBuffer();
		unlockVertexBuffer();
		unlockTexCoordBuffer();
		resetCurPointers();
	}
예제 #3
0
VOID JCDisplayObject::render()
{
	if(m_lpTexture != NULL)
	{
		lockVertexBuffer();
		updateVertexBufferAlpha();
		updateVertexBufferXYWH();
		unlockVertexBuffer();

		m_lpd3dd->SetTexture(0, m_lpTexture);
		if(m_alphaEnabled)
		{
			m_lpd3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
			m_lpd3dd->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
			m_lpd3dd->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
			m_lpd3dd->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
			m_lpd3dd->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
			m_lpd3dd->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
		}
		else
		{
			m_lpd3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		}
		m_lpd3dd->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		m_lpd3dd->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
		m_lpd3dd->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD);
		m_lpd3dd->SetStreamSource(0, m_lpVB, 0, sizeof(Vertex));
		m_lpd3dd->SetFVF(Vertex::FVF);
		m_lpd3dd->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
	}
}
예제 #4
0
																																						//
// Creates a copy of the mesh which has no image or material specifications
DirectX::Mesh* DirectX::Mesh::cloneOutline( Mesh* out )
{
	if( !out ) out = new Mesh( ); out->release( );

	unsigned int nVertices = m_mesh->GetNumVertices( );
	unsigned int nFaces = m_mesh->GetNumFaces( );
	unsigned long options = m_mesh->GetOptions( );
	unsigned int fvf = m_mesh->GetFVF( );

	void* vertices = lockVertexBuffer( D3DLOCK_READONLY );
	void* indices = lockIndexBuffer( D3DLOCK_READONLY );
	out->create( vertices, indices, fvf, nVertices, nFaces, options );
	unlockVertexBuffer( ); unlockIndexBuffer( );

	out->update( ); return out;
}
예제 #5
0
VOID JCDisplayObject::initVertexBuffer()
{
	if(m_lpVB == NULL)
	{
		jccommon_hResultVerifyM(m_lpd3dd->CreateVertexBuffer(VB_SIZE, D3DUSAGE_WRITEONLY, Vertex::FVF, D3DPOOL_MANAGED, &m_lpVB, NULL));
		lockVertexBuffer();
		Vertex vbData[] = {
			Vertex(0.0f, 0.0f, 0xFF000000, 0.0f, 1.0f), 
			Vertex(0.0f, 0.0f, 0xFF000000, 0.0f, 0.0f), 
			Vertex(0.0f, 0.0f, 0xFF000000, 1.0f, 1.0f), 
			Vertex(0.0f, 0.0f, 0xFF000000, 1.0f, 0.0f)
		};
		jccommon_memcpyM(m_lpVBData, &vbData, VB_SIZE);
		updateVertexBufferXYWH();
		updateVertexBufferAlpha();
		unlockVertexBuffer();
	}
}