| 180 | } |
| 181 | |
| 182 | void TerrainBlock::_updateBaseTexture(bool writeToCache) |
| 183 | { |
| 184 | if ( !mBaseShader && !_initBaseShader() ) |
| 185 | return; |
| 186 | |
| 187 | // This can sometimes occur outside a begin/end scene. |
| 188 | const bool sceneBegun = GFX->canCurrentlyRender(); |
| 189 | if ( !sceneBegun ) |
| 190 | GFX->beginScene(); |
| 191 | |
| 192 | GFXDEBUGEVENT_SCOPE( TerrainBlock_UpdateBaseTexture, ColorI::GREEN ); |
| 193 | |
| 194 | PROFILE_SCOPE( TerrainBlock_UpdateBaseTexture ); |
| 195 | |
| 196 | GFXTransformSaver saver; |
| 197 | |
| 198 | const U32 maxTextureSize = GFX->getCardProfiler()->queryProfile( "maxTextureSize", 1024 ); |
| 199 | |
| 200 | U32 baseTexSize = getNextPow2( mBaseTexSize ); |
| 201 | baseTexSize = getMin( maxTextureSize, baseTexSize ); |
| 202 | Point2I destSize( baseTexSize, baseTexSize ); |
| 203 | |
| 204 | // Setup geometry |
| 205 | GFXVertexBufferHandle<GFXVertexPT> vb; |
| 206 | { |
| 207 | F32 copyOffsetX = 2.0f * GFX->getFillConventionOffset() / (F32)destSize.x; |
| 208 | F32 copyOffsetY = 2.0f * GFX->getFillConventionOffset() / (F32)destSize.y; |
| 209 | |
| 210 | GFXVertexPT points[4]; |
| 211 | points[0].point = Point3F(1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0); |
| 212 | points[0].texCoord = Point2F(1.0, 1.0f); |
| 213 | points[1].point = Point3F(1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0); |
| 214 | points[1].texCoord = Point2F(1.0, 0.0f); |
| 215 | points[2].point = Point3F(-1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0); |
| 216 | points[2].texCoord = Point2F(0.0, 1.0f); |
| 217 | points[3].point = Point3F(-1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0); |
| 218 | points[3].texCoord = Point2F(0.0, 0.0f); |
| 219 | |
| 220 | vb.set( GFX, 4, GFXBufferTypeVolatile ); |
| 221 | GFXVertexPT *ptr = vb.lock(); |
| 222 | if(ptr) |
| 223 | { |
| 224 | dMemcpy( ptr, points, sizeof(GFXVertexPT) * 4 ); |
| 225 | vb.unlock(); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | GFXTexHandle blendTex; |
| 230 | |
| 231 | // If the base texture is already a valid render target then |
| 232 | // use it to render to else we create one. |
| 233 | if ( mBaseTex.isValid() && |
| 234 | mBaseTex->isRenderTarget() && |
| 235 | mBaseTex->getFormat() == GFXFormatR8G8B8A8 && |
| 236 | mBaseTex->getWidth() == destSize.x && |
| 237 | mBaseTex->getHeight() == destSize.y ) |
| 238 | blendTex = mBaseTex; |
| 239 | else |
no test coverage detected