1
/***************************************************************************
2
OgrePagingLandScapeTextureCoordinatesManager.cpp - description
4
begin : Mon Jun 16 2003
5
copyright : (C) 2003-2006 by Jose A Milan && Tuan Kuranes
6
email : spoke2@supercable.es && tuan.kuranes@free.fr
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU Lesser General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
18
#include "OgrePagingLandScapePrecompiledHeaders.h"
20
#include "OgrePagingLandScapeSceneManager.h"
21
#include "OgrePagingLandScapeOptions.h"
22
#include "OgrePagingLandScapeTextureCoordinatesManager.h"
26
//-----------------------------------------------------------------------
27
PagingLandScapeTextureCoordinatesManager::PagingLandScapeTextureCoordinatesManager(PagingLandScapeSceneManager * scnMgr) :
30
mOptions (scnMgr->getOptions())
33
//-----------------------------------------------------------------------
34
PagingLandScapeTextureCoordinatesManager::~PagingLandScapeTextureCoordinatesManager()
38
//-----------------------------------------------------------------------
39
void PagingLandScapeTextureCoordinatesManager::clear()
42
if (!mTexBuffs.empty())
44
HardwareTextureBuffersCol::iterator iend = mTexBuffs.end();
45
for (HardwareTextureBuffersCol::iterator i = mTexBuffs.begin();
49
// std::for_each(i->begin (),
58
//-----------------------------------------------------------------------
59
void PagingLandScapeTextureCoordinatesManager::load()
61
const unsigned int pSize = mOptions->PageSize;
62
const unsigned int tSize = mOptions->TileSize;
63
if (mPageSize != pSize ||
70
const unsigned int NumTiles = mOptions->NumTiles;
72
mTexBuffs.reserve (NumTiles);
73
mTexBuffs.resize (NumTiles);
74
for (unsigned int i = 0; i < NumTiles; ++i)
76
mTexBuffs[i].reserve (NumTiles);
77
mTexBuffs[i].resize (NumTiles);
81
//-----------------------------------------------------------------------
82
HardwareVertexBufferSharedPtr PagingLandScapeTextureCoordinatesManager::getBuffer(
83
const unsigned int tilex,
84
const unsigned int tilez)
86
assert (tilex < mOptions->NumTiles &&
87
tilez < mOptions->NumTiles);
89
if (mTexBuffs [tilex][tilez].isNull ())
91
const unsigned int tileSize = mOptions->TileSize;
93
const VertexElementType t = VET_FLOAT2;
94
//const VertexElementType t = VET_SHORT2;
95
const size_t vertexSize = VertexElement::getTypeSize (t);
96
HardwareVertexBufferSharedPtr vbuf =
97
HardwareBufferManager::getSingleton ().createVertexBuffer(
100
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
102
float* pTex = static_cast<float*> (vbuf->lock(HardwareBuffer::HBL_DISCARD));
103
//ushort* pSecond = static_cast<ushort*> (vbuf->lock(HardwareBuffer::HBL_DISCARD));
105
// Calculate the offset in the texture position
106
const unsigned int offSetX = tilex * (tileSize - 1);
107
const unsigned int offSetZ = tilez * (tileSize - 1);
108
const unsigned int endx = offSetX + tileSize;
109
const unsigned int endz = offSetZ + tileSize;
111
const Real Aux1 = 1.0 / (mOptions->PageSize - 1);
112
Real K_Tex2DataPos = offSetZ * Aux1;
113
for (unsigned int k = offSetZ; k < endz; k ++)
115
Real K_Tex1DataPos = offSetX * Aux1;
116
for (unsigned int i = offSetX; i < endx; i ++)
119
//assert (K_Tex1DataPos >= 0.0f && K_Tex1DataPos <= 1.0f);
120
//assert (K_Tex2DataPos >= 0.0f && K_Tex2DataPos <= 1.0f);
121
if (K_Tex1DataPos > 1.0f) K_Tex1DataPos = 1.0f;
122
if (K_Tex2DataPos > 1.0f) K_Tex2DataPos = 1.0f;
123
*pTex++ = K_Tex1DataPos;
124
*pTex++ = K_Tex2DataPos;
126
// *pTex++ = static_cast<ushort> (K_Tex1DataPos * 65535);
127
// *pTex++ = static_cast<ushort> (K_Tex2DataPos * 65535);
129
K_Tex1DataPos += Aux1;
131
K_Tex2DataPos += Aux1;
134
mTexBuffs [tilex][tilez] = vbuf;
136
return mTexBuffs [tilex][tilez];