| 322 | } |
| 323 | |
| 324 | void TerrainBlock::_updateBaseTexture(bool writeToCache) |
| 325 | { |
| 326 | if ( !mBaseShader && !_initBaseShader() ) |
| 327 | return; |
| 328 | |
| 329 | // This can sometimes occur outside a begin/end scene. |
| 330 | const bool sceneBegun = GFX->canCurrentlyRender(); |
| 331 | if ( !sceneBegun ) |
| 332 | GFX->beginScene(); |
| 333 | |
| 334 | GFXDEBUGEVENT_SCOPE( TerrainBlock_UpdateBaseTexture, ColorI::GREEN ); |
| 335 | |
| 336 | PROFILE_SCOPE( TerrainBlock_UpdateBaseTexture ); |
| 337 | |
| 338 | GFXTransformSaver saver; |
| 339 | |
| 340 | const U32 maxTextureSize = GFX->getCardProfiler()->queryProfile( "maxTextureSize", 1024 ); |
| 341 | |
| 342 | U32 baseTexSize = getNextPow2( mBaseTexSize ); |
| 343 | baseTexSize = getMin( maxTextureSize, baseTexSize ); |
| 344 | Point2I destSize( baseTexSize, baseTexSize ); |
| 345 | |
| 346 | // Setup geometry |
| 347 | GFXVertexBufferHandle<GFXVertexPT> vb; |
| 348 | { |
| 349 | F32 copyOffsetX = 2.0f * GFX->getFillConventionOffset() / (F32)destSize.x; |
| 350 | F32 copyOffsetY = 2.0f * GFX->getFillConventionOffset() / (F32)destSize.y; |
| 351 | |
| 352 | GFXVertexPT points[4]; |
| 353 | points[0].point = Point3F(1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0); |
| 354 | points[0].texCoord = Point2F(1.0, 1.0f); |
| 355 | points[1].point = Point3F(1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0); |
| 356 | points[1].texCoord = Point2F(1.0, 0.0f); |
| 357 | points[2].point = Point3F(-1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0); |
| 358 | points[2].texCoord = Point2F(0.0, 1.0f); |
| 359 | points[3].point = Point3F(-1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0); |
| 360 | points[3].texCoord = Point2F(0.0, 0.0f); |
| 361 | |
| 362 | vb.set( GFX, 4, GFXBufferTypeVolatile ); |
| 363 | GFXVertexPT *ptr = vb.lock(); |
| 364 | if(ptr) |
| 365 | { |
| 366 | dMemcpy( ptr, points, sizeof(GFXVertexPT) * 4 ); |
| 367 | vb.unlock(); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | GFXTexHandle blendTex; |
| 372 | |
| 373 | // If the base texture is already a valid render target then |
| 374 | // use it to render to else we create one. |
| 375 | if ( mBaseTex.isValid() && |
| 376 | mBaseTex->isRenderTarget() && |
| 377 | mBaseTex->getFormat() == GFXFormatR8G8B8A8_SRGB && |
| 378 | mBaseTex->getWidth() == destSize.x && |
| 379 | mBaseTex->getHeight() == destSize.y ) |
| 380 | blendTex = mBaseTex; |
| 381 | else |
no test coverage detected