void SpriteD3D::createVertexBuffer() { const int numVertices(6); const int bufferSize(numVertices * sizeof(SPRITE_VERTEX)); assert(Platform::getInstancePtr()); WindowsPlatform* pWin(static_cast<WindowsPlatform*>(Platform::getInstancePtr())); assert(pWin); assert(!FAILED(pWin->getDevice()->CreateVertexBuffer(bufferSize, 0, FVF_SPRITE_VERTEX, D3DPOOL_DEFAULT, &pVertexBuffer_, nullptr))); SPRITE_VERTEX *pVertices( nullptr); assert(!FAILED(pVertexBuffer_->Lock(0, 0, (void**)&pVertices, 0))); pVertices[0] = vertices_[3]; pVertices[1] = vertices_[0]; pVertices[2] = vertices_[1]; pVertices[3] = vertices_[3]; pVertices[4] = vertices_[1]; pVertices[5] = vertices_[2]; pVertexBuffer_->Unlock(); }
// renders the isosurface to given D3D device - just geometry, all texture states // etc. should be done outside of this void CIsoSurface::Render() { std::vector<sLight> pVertices(m_iVxCount); for ( int n = 0; n < m_iVxCount; n++ ) { pVertices[n].vertex.x = m_pVxs[n].x - 0.5f; pVertices[n].vertex.y = m_pVxs[n].y - 0.5f; pVertices[n].vertex.z = m_pVxs[n].z - 0.5f; pVertices[n].normal.x = m_pNorms[n].x; pVertices[n].normal.y = m_pNorms[n].y; pVertices[n].normal.z = m_pNorms[n].z; pVertices[n].normal = glm::normalize(pVertices[n].normal); // these UV coordinated are possibly not the most useful pVertices[n].coord = m_pVxs[n]; pVertices[n].color = glm::vec4(1.0f); } m_base->EnableShader(); glBufferData(GL_ARRAY_BUFFER, sizeof(sLight)*m_iVxCount, &pVertices[0], GL_DYNAMIC_DRAW); glDrawArrays(GL_TRIANGLES, 0, m_iVxCount); m_base->DisableShader(); }
bool CMesh::Init(CGeometry *pOrgGeom, CStrAny sMatSemantic, uint8_t btMatSemanticIndex) { ASSERT(pOrgGeom && pOrgGeom->m_ePrimitiveType == CGeometry::PT_TRIANGLELIST); UINT uiVertices, uiIndices, i; m_pOrgGeom = pOrgGeom; uiVertices = pOrgGeom->GetVBVertexCount(); uiIndices = pOrgGeom->GetIBIndexCount(); ASSERT(uiVertices && uiIndices); CAutoDeleteArrayPtr<TVertex *> pVertices(new TVertex *[uiVertices]); static CStrAny sPOSITION(ST_CONST, "POSITION"); int iPosIndex, iPosOffset, iVertSize; int iMatIndex, iMatOffset; CInputDesc::TInputElement *pPosElem, *pMatElem; pPosElem = pOrgGeom->m_pInputDesc->GetElementInfo(sPOSITION, 0, &iPosIndex); ASSERT(pPosElem && pPosElem->m_Type == CInputDesc::T_FLOAT && pPosElem->m_btElements == 3); iPosOffset = pOrgGeom->m_pInputDesc->GetElementOffset(iPosIndex); iVertSize = pOrgGeom->m_pInputDesc->GetSize(); if (sMatSemantic.Length()) { pMatElem = pOrgGeom->m_pInputDesc->GetElementInfo(sMatSemantic, btMatSemanticIndex, &iMatIndex); ASSERT(pMatElem && pMatElem->m_Type == CInputDesc::T_FLOAT); iMatOffset = pOrgGeom->m_pInputDesc->GetElementOffset(iMatIndex); } else iMatOffset = -1; UINT uiVertMapFlags = (pOrgGeom->m_pVB->m_uiFlags & CResource::RF_KEEPSYSTEMCOPY) ? CResource::RMF_SYSTEM_ONLY : 0; uint8_t *pVertex = pOrgGeom->m_pVB->Map(0, uiVertMapFlags); ASSERT(pVertex); int iMatID = 0; for (i = 0; i < uiVertices; i++) { CVector<3> *pPos = (CVector<3> *) (pVertex + iPosOffset); if (iMatOffset >= 0) iMatID = (int) *(float *) (pVertex + iMatOffset); pVertices[i] = AddVertex(*pPos, iMatID); pVertex += iVertSize; } pOrgGeom->m_pVB->Unmap(); UINT uiIndMapFlags = (pOrgGeom->m_pIB->m_uiFlags & CResource::RF_KEEPSYSTEMCOPY) ? CResource::RMF_SYSTEM_ONLY : 0; uint16_t *pIndex = (uint16_t *) pOrgGeom->m_pIB->Map(0, uiIndMapFlags); ASSERT(pIndex); for (i = 0; i < uiIndices; i += 3) { ASSERT(pIndex[0] < uiVertices && pIndex[1] < uiVertices && pIndex[2] < uiVertices); AddTriangle(pVertices[pIndex[0]], pVertices[pIndex[1]], pVertices[pIndex[2]]); pIndex += 3; } pOrgGeom->m_pIB->Unmap(); return true; }
bool Model_TexturedNM::Initialize( const PrimitiveFactory & PrimMaker, const Graphics & Gfx ) { // Set the stride for this model type m_Stride = sizeof( VertexBufferTypeAllInOneNMap ); // Create the vertex array. auto vertPosition = PrimMaker.GetVertices(); // Set the number of verticex indices in the vertex array. m_vertexCount = vertPosition.size(); m_indexCount = vertPosition.size(); // Get the color auto color = PrimMaker.GetColor(); // Get the texture coordinates auto uvs = PrimMaker.GetUVs(); // Get normals auto normals = PrimMaker.GetNormals(); // Get precalculated Tangent, biTangent and CoNormal auto tangent = PrimMaker.GetTangent(); auto binormal = PrimMaker.GetBiTangent(); // TODO: later add functionality to deal w files w NO normals // Load the vertex buffer array with data. std::vector<VertexBufferTypeAllInOneNMap> pVertices( m_vertexCount ); for( UINT idx = 0; idx < m_vertexCount; ++idx ) { pVertices[ idx ].color = color; pVertices[ idx ].position = vertPosition[ idx ]; pVertices[ idx ].uv = uvs[ idx ]; pVertices[ idx ].tangent = tangent[ idx ]; pVertices[ idx ].binormal = binormal[ idx ]; pVertices[ idx ].normal = normals[ idx ]; } // Load the index array with data. auto indices = PrimMaker.GetIndices(); // Set the number of indices in the index array. m_indexCount = indices.size(); // use vertex and index arrays to create the vertex and index buffers. bool result = initializeBuffers( pVertices.data(), indices.data(), Gfx ); RETURN_MESSAGE_IF_FALSE( result, L"Could not initialize the model's buffers." ); return true; }
void CAreaProxy::ReadPolygonsForAreaSolid( CCryFile& file, int numberOfPolygons, bool bObstruction ) { static const int numberOfStaticVertices(200); Vec3 pStaticVertices[numberOfStaticVertices]; for( int i = 0; i < numberOfPolygons; ++i ) { int numberOfVertices(0); file.ReadType(&numberOfVertices); Vec3* pVertices(NULL); if( numberOfVertices > numberOfStaticVertices ) pVertices = new Vec3[numberOfVertices]; else pVertices = pStaticVertices; for( int k = 0; k < numberOfVertices; ++k ) file.ReadType(&pVertices[k]); m_pArea->AddConvexHullToSolid(pVertices, bObstruction, numberOfVertices); if( pVertices != pStaticVertices ) delete [] pVertices; } }