Subversion Repository Public Repository

Divide-Framework

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

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

Diff revisions: vs.
  @@ -76,11 +76,11 @@
76 76 _grassPositions.clear();
77 77 RemoveResource(_cullShader);
78 78
79 - MemoryManager::SAFE_DELETE( _grassGPUBuffer[0] );
80 - MemoryManager::SAFE_DELETE( _grassGPUBuffer[1] );
81 - MemoryManager::SAFE_DELETE( _treeGPUBuffer[0] );
82 - MemoryManager::SAFE_DELETE( _treeGPUBuffer[1] );
83 - MemoryManager::SAFE_DELETE( _grassMatrices );
79 + MemoryManager::DELETE( _grassGPUBuffer[0] );
80 + MemoryManager::DELETE( _grassGPUBuffer[1] );
81 + MemoryManager::DELETE( _treeGPUBuffer[0] );
82 + MemoryManager::DELETE( _treeGPUBuffer[1] );
83 + MemoryManager::DELETE( _grassMatrices );
84 84 PRINT_FN(Locale::get("UNLOAD_VEGETATION_END"));
85 85 }
86 86
  @@ -120,7 +120,10 @@
120 120 setMaterialTpl(vegMaterial);
121 121
122 122 Kernel* kernel = Application::getInstance().getKernel();
123 - _generateVegetation.reset(kernel->AddTask(0, 1, DELEGATE_BIND(&Vegetation::generateGrass, this), DELEGATE_BIND(&Vegetation::uploadGrassData, this)));
123 + _generateVegetation.reset(kernel->AddTask(0,
124 + 1,
125 + DELEGATE_BIND(&Vegetation::generateGrass, this),
126 + DELEGATE_BIND(&Vegetation::uploadGrassData, this)));
124 127 _generateVegetation->startTask();
125 128 setState(RES_LOADED);
126 129 }
  @@ -152,14 +155,28 @@
152 155 static const vec2<F32> pos240(cosf(RADIANS(240.0f)), sinf(RADIANS(240.0f)));
153 156
154 157 static const vec3<F32> vertices[] = {
155 - vec3<F32>(-pos000.x, 0.0f, -pos000.y), vec3<F32>(-pos000.x, 1.0f, -pos000.y), vec3<F32>(pos000.x, 1.0f, pos000.y), vec3<F32>(pos000.x, 0.0f, pos000.y),
156 - vec3<F32>(-pos120.x, 0.0f, -pos120.y), vec3<F32>(-pos120.x, 1.0f, -pos120.y), vec3<F32>(pos120.x, 1.0f, pos120.y), vec3<F32>(pos120.x, 0.0f, pos120.y),
157 - vec3<F32>(-pos240.x, 0.0f, -pos240.y), vec3<F32>(-pos240.x, 1.0f, -pos240.y), vec3<F32>(pos240.x, 1.0f, pos240.y), vec3<F32>(pos240.x, 0.0f, pos240.y)
158 + vec3<F32>(-pos000.x, 0.0f, -pos000.y),
159 + vec3<F32>(-pos000.x, 1.0f, -pos000.y),
160 + vec3<F32>( pos000.x, 1.0f, pos000.y),
161 + vec3<F32>( pos000.x, 0.0f, pos000.y),
162 +
163 + vec3<F32>(-pos120.x, 0.0f, -pos120.y),
164 + vec3<F32>(-pos120.x, 1.0f, -pos120.y),
165 + vec3<F32>( pos120.x, 1.0f, pos120.y),
166 + vec3<F32>( pos120.x, 0.0f, pos120.y),
167 +
168 + vec3<F32>(-pos240.x, 0.0f, -pos240.y),
169 + vec3<F32>(-pos240.x, 1.0f, -pos240.y),
170 + vec3<F32>( pos240.x, 1.0f, pos240.y),
171 + vec3<F32>( pos240.x, 0.0f, pos240.y)
158 172 };
159 173
160 174 static const U32 indices[] = { 2, 1, 0, 2, 0, 1, 2, 0, 3, 2, 3, 0 };
161 175
162 - static const vec2<F32> texcoords[] = { vec2<F32>(0.0f, 0.99f), vec2<F32>(0.0f, 0.01f), vec2<F32>(1.0f, 0.01f), vec2<F32>(1.0f, 0.99f) };
176 + static const vec2<F32> texcoords[] = { vec2<F32>(0.0f, 0.99f),
177 + vec2<F32>(0.0f, 0.01f),
178 + vec2<F32>(1.0f, 0.01f),
179 + vec2<F32>(1.0f, 0.99f) };
163 180
164 181 vectorImpl<vec3<F32> > grassBlades;
165 182 vectorImpl<vec2<F32> > texCoord;
  @@ -195,7 +212,10 @@
195 212
196 213 Material* mat = getMaterialTpl();
197 214 for (U8 i = 0; i < 3; ++i){
198 - ShaderProgram* const shaderProg = mat->getShaderInfo(i == 0 ? FINAL_STAGE : (i == 1 ? SHADOW_STAGE : Z_PRE_PASS_STAGE)).getProgram();
215 + ShaderProgram* const shaderProg = mat->getShaderInfo(i == 0 ? FINAL_STAGE :
216 + (i == 1 ? SHADOW_STAGE :
217 + Z_PRE_PASS_STAGE)).getProgram();
218 +
199 219 shaderProg->Uniform("positionOffsets", grassBlades);
200 220 shaderProg->Uniform("texCoordOffsets", texCoord);
201 221 shaderProg->Uniform("rotationMatrices", rotationMatrices);
  @@ -207,15 +227,17 @@
207 227 GenericVertexData* buffer = _grassGPUBuffer[i];
208 228
209 229 buffer->Create(BufferUsage_PLACEHOLDER, 3);
210 - buffer->SetFeedbackBuffer(CulledPositionBuffer, 0); // position culled will be generated using transform feedback using shader output 'posLocation' writing to buffer "CulledPositionBuffer"
230 + // position culled will be generated using transform feedback using shader output 'posLocation'
231 + // writing to buffer "CulledPositionBuffer"
232 + buffer->SetFeedbackBuffer(CulledPositionBuffer, 0);
211 233 buffer->SetFeedbackBuffer(CulledSizeBuffer, 1);
212 234 buffer->SetFeedbackBuffer(CulledInstanceBuffer, 2);
213 235
214 - buffer->SetBuffer(UnculledPositionBuffer, _instanceCountGrass, sizeof(vec4<F32>), 3, &_grassPositions[0], false, false);
215 - buffer->SetBuffer(UnculledSizeBuffer, _instanceCountGrass, sizeof(F32), 3, &_grassScales[0], false, false);
216 - buffer->SetBuffer(CulledPositionBuffer, _instanceCountGrass * 3, sizeof(vec4<F32>), 3, NULL, true, false); // "true, false" = DYNAMIC_COPY
217 - buffer->SetBuffer(CulledSizeBuffer, _instanceCountGrass * 3, sizeof(F32), 3, NULL, true, false);
218 - buffer->SetBuffer(CulledInstanceBuffer, _instanceCountGrass * 3, sizeof(I32), 3, NULL, true, false);
236 + buffer->SetBuffer(UnculledPositionBuffer, _instanceCountGrass, sizeof(vec4<F32>), 3, &_grassPositions[0], false, false);
237 + buffer->SetBuffer(UnculledSizeBuffer, _instanceCountGrass, sizeof(F32), 3, &_grassScales[0], false, false);
238 + buffer->SetBuffer(CulledPositionBuffer, _instanceCountGrass*3, sizeof(vec4<F32>), 3, NULL, true, false);
239 + buffer->SetBuffer(CulledSizeBuffer, _instanceCountGrass*3, sizeof(F32), 3, NULL, true, false);
240 + buffer->SetBuffer(CulledInstanceBuffer, _instanceCountGrass*3, sizeof(I32), 3, NULL, true, false);
219 241
220 242 buffer->getDrawAttribDescriptor(posLocation).set(CulledPositionBuffer, instanceDiv, 4, false, 0, 0, FLOAT_32);
221 243 buffer->getDrawAttribDescriptor(scaleLocation).set(CulledSizeBuffer, instanceDiv, 1, false, 0, 0, FLOAT_32);
  @@ -326,7 +348,10 @@
326 348 }
327 349 }
328 350
329 - void Vegetation::getDrawCommands(SceneGraphNode* const sgn, const RenderStage& renderStage, SceneRenderState& sceneRenderState, vectorImpl<GenericDrawCommand>& drawCommandsOut) {
351 + void Vegetation::getDrawCommands(SceneGraphNode* const sgn,
352 + const RenderStage& renderStage,
353 + SceneRenderState& sceneRenderState,
354 + vectorImpl<GenericDrawCommand>& drawCommandsOut) {
330 355 GenericVertexData* buffer = _grassGPUBuffer[_readBuffer];
331 356 U32 queryId = getQueryID();
332 357 //gpuCull();
  @@ -353,10 +378,17 @@
353 378
354 379 bool Vegetation::onDraw(SceneGraphNode* const sgn, const RenderStage& renderStage){
355 380 _staticDataUpdated = false;
356 - return !(!_render || !_success || !_threadedLoadComplete || _terrainChunk->getLoD() > 0 || (LightManager::getInstance().currentShadowPass() > 0 && GFX_DEVICE.isCurrentRenderStage(SHADOW_STAGE)));
381 + return !(!_render ||
382 + !_success ||
383 + !_threadedLoadComplete ||
384 + _terrainChunk->getLoD() > 0 ||
385 + (LightManager::getInstance().currentShadowPass() > 0 &&
386 + GFX_DEVICE.isCurrentRenderStage(SHADOW_STAGE)));
357 387 }
358 388
359 - void Vegetation::render(SceneGraphNode* const sgn, const SceneRenderState& sceneRenderState, const RenderStage& currentRenderStage){
389 + void Vegetation::render(SceneGraphNode* const sgn,
390 + const SceneRenderState& sceneRenderState,
391 + const RenderStage& currentRenderStage) {
360 392 GFX_DEVICE.submitRenderCommand(_renderDrawCommand);
361 393 }
362 394