void DiFoliageLayerBatch::GenerateGrassSprite( const float *grassPositions, unsigned int grassCount ) { ReleaseVertexDeclaration(); ReleaseSourceData(); ReleaseIndexBuffer(); // TODO }
DiInstanceBatch::~DiInstanceBatch() { DeleteAllInstancedModels(); DiCullNode *sceneNode = GetParentCullNode(); if( sceneNode ) { sceneNode->DetachAllObjects(); sceneNode->GetParent()->RemoveChild( sceneNode->GetName() ); } if( mRemoveOwnVertexData ) ReleaseSourceData(); if( mRemoveOwnIndexData ) ReleaseIndexBuffer(); ReleaseVertexDeclaration(); }
DiLineList::~DiLineList(void) { ReleaseSourceData(); ReleaseVertexDeclaration(); }
DiSprite::~DiSprite() { ReleaseSourceData(); ReleaseVertexDeclaration(); }
//-------------------------------------------------------------------------------------------------------------- D3D9VertexDeclaration::~D3D9VertexDeclaration() { ReleaseVertexDeclaration(); }
void DiFoliageLayerBatch::GenerateGrassQuad( const float *grassPositions, unsigned int grassCount ) { ReleaseVertexDeclaration(); ReleaseSourceData(); ReleaseIndexBuffer(); unsigned int quadCount; quadCount = grassCount; unsigned int maxUInt16 = std::numeric_limits<uint16>::max(); if(grassCount > maxUInt16) { return; } if(quadCount > maxUInt16) { return; } if (quadCount <= 0) { mVerticesNum = 0; mPrimitiveCount = 0; return; } mVerticesNum = 4 * quadCount; mPrimitiveCount = 2 * quadCount; mVertexDecl = Driver->CreateVertexDeclaration(); mVertexDecl->AddElement(0,VERT_TYPE_FLOAT3, VERT_USAGE_POSITION); mVertexDecl->AddElement(0,VERT_TYPE_FLOAT2, VERT_USAGE_TEXCOORD); mVertexDecl->Create(); uint32 vertSize = mVertexDecl->GetElements().GetStreamElementsSize(0); uint32 size = vertSize * mVerticesNum; DiVertexBuffer* vb = Driver->CreateVertexBuffer(); vb->Create(size); vb->SetStride(vertSize); mSourceData.push_back(vb); DiVec2 chunkPos = mParent->mParent->GetTerrainMap()->GetChunkCenterPos(mParent->mChunkID.x,mParent->mChunkID.y); float* pReal = static_cast<float*>(vb->Lock(0,size)); float rndWidth = mLayer->mDesc->mMaxWidth - mLayer->mDesc->mMinWidth; float rndHeight = mLayer->mDesc->mMaxHeight - mLayer->mDesc->mMinHeight; float minY = DiMath::POS_INFINITY, maxY = DiMath::NEG_INFINITY; const float *posPtr = grassPositions; for (uint16 i = 0; i < grassCount; ++i) { float x = *posPtr++; float z = *posPtr++; float rnd = *posPtr++; float halfScaleX = (mLayer->mDesc->mMinWidth + rndWidth * rnd) * 0.5f; float scaleY = (mLayer->mDesc->mMinHeight + rndHeight * rnd); float angle = *posPtr++; float xTrans = DiMath::Cos(angle) * halfScaleX; float zTrans = DiMath::Sin(angle) * halfScaleX; float x1 = x - xTrans, z1 = z - zTrans; float x2 = x + xTrans, z2 = z + zTrans; float height = 0; mParent->mParent->GetTerrainMap()->GetHeight(chunkPos.x+x,chunkPos.y+z,height); float y1 = height; float y2 = height; *pReal++ = float(x1); *pReal++ = float(y1 + scaleY); *pReal++ = float(z1); //pos *pReal++ = 0.f; *pReal++ = 0.f; //uv *pReal++ = float(x2); *pReal++ = float(y2 + scaleY); *pReal++ = float(z2); //pos *pReal++ = 1.f; *pReal++ = 0.f; //uv *pReal++ = float(x1); *pReal++ = float(y1); *pReal++ = float(z1); //pos *pReal++ = 0.f; *pReal++ = 1.f; //uv *pReal++ = float(x2); *pReal++ = float(y2); *pReal++ = float(z2); //pos *pReal++ = 1.f; *pReal++ = 1.f; //uv if (y1 < minY) { minY = y1; } if (y2 < minY) { minY = y2; } if (y1 + scaleY > maxY) { maxY = y1 + scaleY; } if (y2 + scaleY > maxY) { maxY = y2 + scaleY; } } vb->Unlock(); uint32 ibsize = 6 * quadCount * sizeof(uint16); mIndexBuffer = Driver->CreateIndexBuffer(); mIndexBuffer->Create(ibsize); uint16* pI = static_cast<uint16*>(mIndexBuffer->Lock(0,ibsize)); for (uint16 i = 0; i < quadCount; ++i) { uint16 offset = i * 4; *pI++ = 0 + offset; *pI++ = 2 + offset; *pI++ = 1 + offset; *pI++ = 1 + offset; *pI++ = 2 + offset; *pI++ = 3 + offset; } mIndexBuffer->Unlock(); }
DiFoliageLayerBatch::~DiFoliageLayerBatch() { ReleaseVertexDeclaration(); ReleaseSourceData(); ReleaseIndexBuffer(); }