Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 329 vs 330 for /trunk/Source Code/Environment/Vegetation/Vegetation.cpp

Diff revisions: vs.
  @@ -114,6 +114,7 @@
114 114 vegMaterial->setShaderProgram(_grassShaderName, FINAL_STAGE, true);
115 115 vegMaterial->setShaderProgram(_grassShaderName + ".Shadow", SHADOW_STAGE, true);
116 116 vegMaterial->setShaderProgram(_grassShaderName + ".PrePass", Z_PRE_PASS_STAGE, true);
117 + vegMaterial->addCustomTexture(_grassBillboards, ShaderProgram::TEXTURE_UNIT0);
117 118 vegMaterial->setShaderLoadThreaded(false);
118 119 vegMaterial->dumpToFile(false);
119 120 setMaterialTpl(vegMaterial);
  @@ -253,7 +254,7 @@
253 254 _windX = sceneState.getWindDirX();
254 255 _windZ = sceneState.getWindDirZ();
255 256 _windS = sceneState.getWindSpeed();
256 - Material* mat = sgn->getMaterialInstance();
257 + Material* mat = sgn->getComponent<RenderingComponent>()->getMaterialInstance();
257 258 for (U8 i = 0; i < 3; ++i){
258 259 RenderStage stage = (i == 0 ? FINAL_STAGE : (i == 1 ? SHADOW_STAGE : Z_PRE_PASS_STAGE));
259 260 mat->getShaderInfo(stage).getProgram()->Uniform("grassScale",/* _grassSize*/1.0f);
  @@ -314,38 +315,49 @@
314 315 _cullDrawCommand.queryID(queryId);
315 316 _cullDrawCommand.drawToBuffer(true);
316 317 _cullDrawCommand.shaderProgram(_cullShader);
317 - GFX_DEVICE.submitRenderCommand(buffer, _cullDrawCommand);
318 + _cullDrawCommand.sourceBuffer(buffer);
319 +
320 + GFX_DEVICE.submitRenderCommand(_cullDrawCommand);
321 +
318 322 //_cullDrawCommand.setInstanceCount(_instanceCountTrees);
319 - //GFX_DEVICE.submitRenderCommand(_treeGPUBuffer, _cullDrawCommand);
323 + //_cullDrawCommand.sourceBuffer(_treeGPUBuffer);
324 + //GFX_DEVICE.submitRenderCommand(_cullDrawCommand);
320 325 GFX_DEVICE.toggleRasterization(true);
321 326 }
322 327 }
323 328
324 - bool Vegetation::onDraw(SceneGraphNode* const sgn, const RenderStage& renderStage){
325 - _staticDataUpdated = false;
326 - return !(!_render || !_success || !_threadedLoadComplete || _terrainChunk->getLoD() > 0 || (LightManager::getInstance().currentShadowPass() > 0 && GFX_DEVICE.isCurrentRenderStage(SHADOW_STAGE)));
327 - }
328 -
329 - void Vegetation::render(SceneGraphNode* const sgn, const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage){
329 + void Vegetation::getDrawCommands(SceneGraphNode* const sgn, const RenderStage& renderStage, SceneRenderState& sceneRenderState, vectorImpl<GenericDrawCommand>& drawCommandsOut) {
330 + GenericVertexData* buffer = _grassGPUBuffer[_readBuffer];
330 331 U32 queryId = getQueryID();
331 332 //gpuCull();
332 - GenericVertexData* buffer = _grassGPUBuffer[_readBuffer];
333 +
333 334 I32 instanceCount = buffer->GetFeedbackPrimitiveCount(queryId);
334 - if (instanceCount == 0)
335 + if (instanceCount == 0) {
335 336 return;
337 + }
338 + buffer->getDrawAttribDescriptor(posLocation).offset(_instanceCountGrass * queryId);
339 + buffer->getDrawAttribDescriptor(scaleLocation).offset(_instanceCountGrass * queryId);
340 + buffer->getDrawAttribDescriptor(instLocation).offset(_instanceCountGrass * queryId);
341 +
342 + RenderingComponent* const renderable = sgn->getComponent<RenderingComponent>();
343 + assert(renderable != nullptr);
336 344
337 - _grassBillboards->Bind(0);
338 - _renderDrawCommand.renderWireframe(sgn->renderWireframe());
345 + _renderDrawCommand.renderWireframe(renderable->renderWireframe());
339 346 _renderDrawCommand.stateHash(_grassStateBlockHash);
340 347 _renderDrawCommand.instanceCount(instanceCount);
341 348 _renderDrawCommand.LoD(1);
342 - _renderDrawCommand.drawID(GFX_DEVICE.getDrawID(sgn->getGUID()));
343 - _renderDrawCommand.shaderProgram(sgn->getDrawShader(currentRenderStage));
344 - buffer->getDrawAttribDescriptor(posLocation).offset(_instanceCountGrass * queryId);
345 - buffer->getDrawAttribDescriptor(scaleLocation).offset(_instanceCountGrass * queryId);
346 - buffer->getDrawAttribDescriptor(instLocation).offset(_instanceCountGrass * queryId);
347 -
348 - GFX_DEVICE.submitRenderCommand(buffer, _renderDrawCommand);
349 + _renderDrawCommand.shaderProgram(renderable->getDrawShader(renderStage));
350 + _renderDrawCommand.sourceBuffer(buffer);
351 + drawCommandsOut.push_back(_renderDrawCommand);
352 + }
353 +
354 + bool Vegetation::onDraw(SceneGraphNode* const sgn, const RenderStage& renderStage){
355 + _staticDataUpdated = false;
356 + return !(!_render || !_success || !_threadedLoadComplete || _terrainChunk->getLoD() > 0 || (LightManager::getInstance().currentShadowPass() > 0 && GFX_DEVICE.isCurrentRenderStage(SHADOW_STAGE)));
357 + }
358 +
359 + void Vegetation::render(SceneGraphNode* const sgn, const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage){
360 + GFX_DEVICE.submitRenderCommand(_renderDrawCommand);
349 361 }
350 362
351 363 void Vegetation::generateTrees(){