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); } }
// // 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; }
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(); } }
//----------------------------------------------------------------------- size_t MeshReadHelper::prepareVerticesGetOffset(size_t _vertexIndex) { mCurSubMeshInfoV = nullptr; size_t ofs = _vertexIndex - mCurSubMeshInfoT->vertexStartInJoinedList; if(ofs < mCurSubMeshInfoT->vertexCount) { mCurSubMeshInfoV = mCurSubMeshInfoT; } else { ofs = _vertexIndex - mCurSubMeshInfoF->vertexStartInJoinedList; if(ofs < mCurSubMeshInfoF->vertexCount) { mCurSubMeshInfoV = mCurSubMeshInfoF; } else { for(size_t j = 0; j != mSubMeshInfos.size(); ++j) { SubMeshInfo* curSubMeshInfo = &mSubMeshInfos[j]; ofs = _vertexIndex - curSubMeshInfo->vertexStartInJoinedList; if(ofs < curSubMeshInfo->vertexCount) { mCurSubMeshInfoV = curSubMeshInfo; break; } } } } if(!mCurSubMeshInfoV) GOTHOGRE_EXCEPT("Invalid index of vertex: " << _vertexIndex); lockVertexBuffer(); return ofs; }