Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 167 vs 168 for /trunk/Source Code/Environment/Terrain/TerrainLoader.cpp

Diff revisions: vs.
  @@ -33,14 +33,9 @@
33 33
34 34 /// Visual resources must be loaded in the rendering thread to gain acces to the current graphic context
35 35 void Terrain::loadVisualResources(){
36 - _terrainTextures[TERRAIN_TEXTURE_DIFFUSE]->setTextureWrap(TEXTURE_REPEAT,
37 - TEXTURE_REPEAT,
38 - TEXTURE_REPEAT);
39 -
40 - if(_terrainTextures[TERRAIN_TEXTURE_ALPHA] != NULL){
41 - _alphaTexturePresent = true;
42 - }
43 36
37 + _alphaTexturePresent = (_terrainTextures[TERRAIN_TEXTURE_ALPHA] != NULL);
38 +
44 39 //Generate a render state
45 40 RenderStateBlockDescriptor terrainDesc;
46 41 terrainDesc.setCullMode(CULL_MODE_CW);
  @@ -76,12 +71,13 @@
76 71 const vectorImpl<vec3<F32> >& normalData = _groundVBO->getNormal();
77 72 const vectorImpl<vec3<F32> >& tangentData = _groundVBO->getTangent();
78 73
79 - U8 d; U32 t, id;
80 - bool alpha = false;
81 - U8* data = ImageTools::OpenImage(terrain->getVariable("heightmap"),
82 - _terrainWidth,
83 - _terrainHeight,
84 - d, t, id,alpha);
74 + ImageTools::ImageData img;
75 + img.create(terrain->getVariable("heightmap"));
76 + ///data will be destroyed when img gets out of scope
77 + const U8* data = img.data();
78 +
79 + _terrainWidth = img.dimensions().width;
80 + _terrainHeight = img.dimensions().height;
85 81
86 82 D_PRINT_FN(Locale::get("TERRAIN_INFO"),_terrainWidth, _terrainHeight);
87 83 assert(data);
  @@ -114,13 +110,12 @@
114 110
115 111 U32 idxIMG = COORD( i<heightmapWidth? i : i-1, j<heightmapHeight? j : j-1, heightmapWidth);
116 112
117 - F32 h = (F32)(data[idxIMG*d + 0] + data[idxIMG*d + 1] + data[idxIMG*d + 2])/3.0f;
113 + F32 h = (F32)(data[idxIMG*img.bpp() + 0] + data[idxIMG*img.bpp() + 1] + data[idxIMG*img.bpp() + 2])/3.0f;
118 114
119 115 vertexData.y = (bMin.y + ((F32)h) * (bMax.y - bMin.y)/(255)) * _terrainHeightScaleFactor;
120 116 _groundVBO->modifyPositionValue(idxHM,vertexData);
121 117 }
122 118 }
123 - SAFE_DELETE_ARRAY(data);
124 119
125 120 U32 offset = 2;
126 121 vec3<F32> vU, vV, vUV;
  @@ -168,18 +163,19 @@
168 163 _groundVBO->modifyTangentValue(idx0,normalData[idx1]);
169 164 }
170 165 }
171 - ///Use primitive restart for each strip
166 + //Terrain dimensions
167 + vec2<U32> terrainDim(_terrainWidth, _terrainHeight);
168 + //Use primitive restart for each strip
172 169 _groundVBO->setIndicesDelimiter(TERRAIN_STRIP_RESTART_INDEX);
173 170 _terrainQuadtree->setParentShaderProgram(getMaterial()->getShaderProgram());
174 171 _terrainQuadtree->setParentVBO(_groundVBO);
175 - _terrainQuadtree->Build(_boundingBox, vec2<U32>(_terrainWidth, _terrainHeight), terrain->getChunkSize(), _groundVBO);
172 + _terrainQuadtree->Build(_boundingBox, terrainDim, terrain->getChunkSize(), _groundVBO);
176 173
177 174 ResourceDescriptor infinitePlane("infinitePlane");
178 175 infinitePlane.setFlag(true); //No default material
179 176 _plane = CreateResource<Quad3D>(infinitePlane);
180 -
181 - F32 depth = GET_ACTIVE_SCENE()->state()->getWaterDepth();
182 - F32 height = GET_ACTIVE_SCENE()->state()->getWaterLevel()- depth;
177 + F32 depth = GET_ACTIVE_SCENE()->state().getWaterDepth();
178 + F32 height = GET_ACTIVE_SCENE()->state().getWaterLevel()- depth;
183 179 _farPlane = 2.0f * ParamHandler::getInstance().getParam<F32>("runtime.zFar");
184 180 _plane->setCorner(Quad3D::TOP_LEFT, vec3<F32>( -_farPlane, height, -_farPlane));
185 181 _plane->setCorner(Quad3D::TOP_RIGHT, vec3<F32>( _farPlane, height, -_farPlane));
  @@ -208,12 +204,11 @@
208 204 computeBoundingBox(_node);
209 205 ShaderProgram* s = getMaterial()->getShaderProgram();
210 206
211 - s->Uniform("alphaTexture", _alphaTexturePresent);
212 - s->Uniform("detail_scale", _normalMapUVScale);
207 + s->Uniform("detail_scale", _normalMapUVScale);
213 208 s->Uniform("diffuse_scale", _diffuseUVScale);
214 209 s->Uniform("bbox_min", _boundingBox.getMin());
215 - s->Uniform("bbox_max", _boundingBox.getMax());
216 - s->Uniform("water_height", GET_ACTIVE_SCENE()->state()->getWaterLevel());
210 + s->Uniform("bbox_diff", _boundingBox.getMax() - _boundingBox.getMin());
211 + s->Uniform("_waterHeight", GET_ACTIVE_SCENE()->state().getWaterLevel());
217 212 s->Uniform("dvd_lightCount", 1);
218 213 s->UniformTexture("texDiffuseMap", 0);
219 214 s->UniformTexture("texNormalHeightMap", 1);