private int findFirstFreeHandle(int lod) { for (int i = 0; i < mHandles.Count; i++) { if (!mHandles[i].inUse && mHandles[i].LOD == lod) { return(i); } } BTerrainVisualDataHandle vdh = new BTerrainVisualDataHandle(); vdh.mHandle = new BTerrainVisualData(); vdh.inUse = false; mHandles.Add(vdh); return(mHandles.Count - 1); }
public bool render() { if (mSetVBs.Count == 0) { createRenderVBs(); if (mSetVBs.Count == 0) { return(false); } } BRenderDevice.getDevice().VertexDeclaration = VertexTypes.Pos.vertDecl; //my shader is started in the parent FoliageManager class.. BTerrainQuadNode qn = TerrainGlobals.getTerrain().getQuadNodeLeafArray()[mOwnerQNIndex]; //find our visual handle index //CLM the skirts f**k this up.. just find the highest LOD that's valid... BTerrainVisualDataHandle vdh = null; for (int i = 0; i < (int)Terrain.BTerrainVisual.eLODLevel.cLODCount; i++) { if (qn.mVisualDataIndxPerLOD[i] != -1) { vdh = TerrainGlobals.getVisual().getVisualHandle(qn.mVisualDataIndxPerLOD[i]); break; } } if (vdh == null) { return(false); } //bind my QN positions texture FoliageManager.mFoliageGPUShader.mShader.SetValue(FoliageManager.mTerrainQNPosTexture, vdh.mHandle.mPositionsTexture); Vector4 QnData = new Vector4((BTerrainQuadNode.getMaxNodeWidth() >> vdh.LOD), TerrainGlobals.getTerrain().getTileScale(), mOwnerNodeDesc.mMinXVert, mOwnerNodeDesc.mMinZVert); FoliageManager.mFoliageGPUShader.mShader.SetValue(FoliageManager.mTerrainQNData, QnData); for (int setI = 0; setI < mSetsUsed.Count; setI++) { FoliageSet set = FoliageManager.giveSet(mSetsUsed[setI]); float rcpBladeImgWidth = 1.0f / (float)set.mNumBlades; FoliageManager.mFoliageGPUShader.mShader.SetValue(FoliageManager.mSetRCPBladeTexWidth, rcpBladeImgWidth); FoliageManager.mFoliageGPUShader.mShader.SetValue(FoliageManager.mSetAlbedoTexture, set.mD3DAlbedoTexture == null? BRenderDevice.getTextureManager().getDefaultTexture(TextureManager.eDefaultTextures.cDefTex_Red): set.mD3DAlbedoTexture.mTexture); FoliageManager.mFoliageGPUShader.mShader.SetValue(FoliageManager.mSetOpacityTexture, set.mD3DOpacityTexture == null ? BRenderDevice.getTextureManager().getDefaultTexture(TextureManager.eDefaultTextures.cDefTex_White) : set.mD3DOpacityTexture.mTexture); FoliageManager.mFoliageGPUShader.mShader.SetValue(FoliageManager.mSetPositionsTexture, set.mD3DPositionsTexture); FoliageManager.mFoliageGPUShader.mShader.SetValue(FoliageManager.mSetUVsTexture, set.mD3DUVsTexture); //DRAW US FOOL! BRenderDevice.getDevice().SetStreamSource(0, mSetVBs[setI], 0); BRenderDevice.getDevice().Indices = mSetIBs[setI]; FoliageManager.mFoliageGPUShader.mShader.CommitChanges(); BRenderDevice.getDevice().DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, mSetVertCount[setI], 0, mSetPolyCount[setI]); } return(true); }