Subversion Repository Public Repository

Divide-Framework

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
#include "Headers/Terrain.h"
#include "Headers/TerrainLoader.h"
#include "Headers/TerrainDescriptor.h"

#include "Platform/Video/Headers/GFXDevice.h"
#include "Geometry/Material/Headers/Material.h"
#include "Managers/Headers/SceneManager.h"
#include "Geometry/Shapes/Headers/Predefined/Quad3D.h"

namespace Divide {

bool TerrainLoader::loadTerrain(Terrain* terrain,
                                TerrainDescriptor* terrainDescriptor) {
    const stringImpl& name = terrainDescriptor->getVariable("terrainName");

    TerrainLoaderAttorney::setUnderwaterDiffuseScale(
        *terrain, terrainDescriptor->getVariablef("underwaterDiffuseScale"));

    SamplerDescriptor blendMapSampler;
    blendMapSampler.setWrapMode(TextureWrap::TEXTURE_CLAMP);
    blendMapSampler.setAnisotropy(0);
    blendMapSampler.toggleMipMaps(false);

    TerrainTextureLayer* textureLayer = nullptr;
    stringImpl layerOffsetStr;
    stringImpl currentTexture;
    stringImpl arrayLocation;
    U32 textureCount = 0;
    U32 textureCountAlbedo = 0;
    U32 textureCountDetail = 0;

    for (U32 i = 0; i < terrainDescriptor->getTextureLayerCount(); ++i) {
        textureCountAlbedo = 0;
        textureCountDetail = 0;

        layerOffsetStr = std::to_string(i);
        textureLayer = MemoryManager_NEW TerrainTextureLayer();

        ResourceDescriptor textureBlendMap("Terrain Blend Map_" + name +
                                           "_layer_" + layerOffsetStr);
        textureBlendMap.setResourceLocation(
            terrainDescriptor->getVariable("blendMap" + layerOffsetStr));
        textureBlendMap.setPropertyDescriptor(blendMapSampler);
        textureLayer->setBlendMap(CreateResource<Texture>(textureBlendMap));

        arrayLocation.clear();
        currentTexture =
            terrainDescriptor->getVariable("redAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation = currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TEXTURE_RED_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleR" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("greenAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TEXTURE_GREEN_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleG" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("blueAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TEXTURE_BLUE_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleB" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("alphaAlbedo" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCount++;
            textureCountAlbedo++;
            textureLayer->setDiffuseScale(
                TerrainTextureLayer::TEXTURE_ALPHA_CHANNEL,
                terrainDescriptor->getVariablef("diffuseScaleA" +
                                                layerOffsetStr));
        }

        ResourceDescriptor textureTileMaps("Terrain Tile Maps_" + name +
                                           "_layer_" + layerOffsetStr);
        textureTileMaps.setEnumValue(enum_to_uint(TextureType::TEXTURE_2D_ARRAY));
        textureTileMaps.setID(textureCountAlbedo);
        textureTileMaps.setResourceLocation(arrayLocation);
        textureTileMaps.setPropertyDescriptor(
            TerrainLoaderAttorney::getAlbedoSampler(*terrain));
        textureLayer->setTileMaps(CreateResource<Texture>(textureTileMaps));

        arrayLocation.clear();
        currentTexture =
            terrainDescriptor->getVariable("redDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TEXTURE_RED_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleR" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("greenDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TEXTURE_GREEN_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleG" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("blueDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TEXTURE_BLUE_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleB" +
                                                layerOffsetStr));
        }
        currentTexture =
            terrainDescriptor->getVariable("alphaDetail" + layerOffsetStr);
        if (!currentTexture.empty()) {
            arrayLocation += "," + currentTexture;
            textureCountDetail++;
            textureLayer->setDetailScale(
                TerrainTextureLayer::TEXTURE_ALPHA_CHANNEL,
                terrainDescriptor->getVariablef("detailScaleA" +
                                                layerOffsetStr));
        }

        ResourceDescriptor textureNormalMaps("Terrain Normal Maps_" + name +
                                             "_layer_" + layerOffsetStr);
        textureNormalMaps.setEnumValue(enum_to_uint(TextureType::TEXTURE_2D_ARRAY));
        textureNormalMaps.setID(textureCountDetail);
        textureNormalMaps.setResourceLocation(arrayLocation);
        textureNormalMaps.setPropertyDescriptor(
            TerrainLoaderAttorney::getNormalSampler(*terrain));
        textureLayer->setNormalMaps(CreateResource<Texture>(textureTileMaps));

        TerrainLoaderAttorney::addTextureLayer(*terrain, textureLayer);
    }

    ResourceDescriptor terrainMaterialDescriptor("terrainMaterial_" + name);
    Material* terrainMaterial =
        CreateResource<Material>(terrainMaterialDescriptor);

    terrainMaterial->setDiffuse(
        vec4<F32>(DefaultColors::WHITE().rgb() / 2, 1.0f));
    terrainMaterial->setAmbient(
        vec4<F32>(DefaultColors::WHITE().rgb() / 3, 1.0f));
    terrainMaterial->setSpecular(vec4<F32>(0.1f, 0.1f, 0.1f, 1.0f));
    terrainMaterial->setShininess(20.0f);
    terrainMaterial->setShadingMode(Material::ShadingMode::SHADING_BLINN_PHONG);
    terrainMaterial->addShaderDefines("COMPUTE_TBN");
    terrainMaterial->addShaderDefines("SKIP_TEXTURES");
    terrainMaterial->addShaderDefines(
        "MAX_TEXTURE_LAYERS " +
        std::to_string(TerrainLoaderAttorney::textureLayerCount(*terrain)));
    terrainMaterial->addShaderDefines("CURRENT_TEXTURE_COUNT " +
                                      std::to_string(textureCount));
    terrainMaterial->setShaderProgram("terrain", RenderStage::FINAL_STAGE, true);
    terrainMaterial->setShaderProgram("depthPass.Shadow.Terrain", RenderStage::SHADOW_STAGE,
                                      true);
    terrainMaterial->setShaderProgram("depthPass.PrePass.Terrain",
                                      RenderStage::Z_PRE_PASS_STAGE, true);

    ResourceDescriptor textureWaterCaustics("Terrain Water Caustics_" + name);
    textureWaterCaustics.setResourceLocation(
        terrainDescriptor->getVariable("waterCaustics"));
    textureWaterCaustics.setPropertyDescriptor(
        TerrainLoaderAttorney::getAlbedoSampler(*terrain));
    terrainMaterial->setTexture(ShaderProgram::TEXTURE_UNIT0,
                                CreateResource<Texture>(textureWaterCaustics));

    ResourceDescriptor underwaterAlbedoTexture("Terrain Underwater Albedo_" +
                                               name);
    underwaterAlbedoTexture.setResourceLocation(
        terrainDescriptor->getVariable("underwaterAlbedoTexture"));
    underwaterAlbedoTexture.setPropertyDescriptor(
        TerrainLoaderAttorney::getAlbedoSampler(*terrain));
    terrainMaterial->setTexture(
        ShaderProgram::TEXTURE_UNIT1,
        CreateResource<Texture>(underwaterAlbedoTexture));

    ResourceDescriptor underwaterDetailTexture("Terrain Underwater Detail_" +
                                               name);
    underwaterDetailTexture.setResourceLocation(
        terrainDescriptor->getVariable("underwaterDetailTexture"));
    underwaterDetailTexture.setPropertyDescriptor(
        TerrainLoaderAttorney::getNormalSampler(*terrain));
    terrainMaterial->setTexture(
        ShaderProgram::TEXTURE_NORMALMAP,
        CreateResource<Texture>(underwaterDetailTexture));

    terrainMaterial->setShaderLoadThreaded(false);
    terrainMaterial->dumpToFile(false);
    terrain->setMaterialTpl(terrainMaterial);

    // Generate a render state
    RenderStateBlockDescriptor terrainDesc;
    terrainDesc.setCullMode(CullMode::CULL_MODE_CW);
    RenderStateBlockDescriptor terrainDescRef;
    terrainDescRef.setCullMode(CullMode::CULL_MODE_CCW);
    // Generate a shadow render state
    RenderStateBlockDescriptor terrainDescDepth;
    terrainDescDepth.setCullMode(CullMode::CULL_MODE_CCW);
    // terrainDescDepth.setZBias(1.0f, 2.0f);
    terrainDescDepth.setColorWrites(true, true, false, false);

    TerrainLoaderAttorney::setRenderStateHashes(
        *terrain, GFX_DEVICE.getOrCreateStateBlock(terrainDesc),
        GFX_DEVICE.getOrCreateStateBlock(terrainDescRef),
        GFX_DEVICE.getOrCreateStateBlock(terrainDescDepth));

    return loadThreadedResources(terrain, terrainDescriptor);
}

bool TerrainLoader::loadThreadedResources(
    Terrain* terrain, TerrainDescriptor* terrainDescriptor) {
    ResourceDescriptor infinitePlane("infinitePlane");
    infinitePlane.setFlag(true);  // No default material
    Quad3D* planePtr = TerrainLoaderAttorney::plane(*terrain);
    F32& farPlane = TerrainLoaderAttorney::farPlane(*terrain);
    planePtr = CreateResource<Quad3D>(infinitePlane);
    Quad3D& plane = *planePtr;
    // our bottom plane is placed at the bottom of our water entity
    F32 height = GET_ACTIVE_SCENE()->state().getWaterLevel() -
                 GET_ACTIVE_SCENE()->state().getWaterDepth();
    farPlane = 2.0f *
               GET_ACTIVE_SCENE()
                   ->state()
                   .getRenderState()
                   .getCameraConst()
                   .getZPlanes()
                   .y;
    plane.setCorner(Quad3D::TOP_LEFT,
                    vec3<F32>(-farPlane * 1.5f, height, -farPlane * 1.5f));
    plane.setCorner(Quad3D::TOP_RIGHT,
                    vec3<F32>(farPlane * 1.5f, height, -farPlane * 1.5f));
    plane.setCorner(Quad3D::BOTTOM_LEFT,
                    vec3<F32>(-farPlane * 1.5f, height, farPlane * 1.5f));
    plane.setCorner(Quad3D::BOTTOM_RIGHT,
                    vec3<F32>(farPlane * 1.5f, height, farPlane * 1.5f));

    VertexBuffer* groundVB = terrain->getGeometryVB();
    vec2<F32>& terrainScaleFactor =
        TerrainLoaderAttorney::scaleFactor(*terrain);
    ;

    TerrainLoaderAttorney::chunkSize(*terrain) =
        terrainDescriptor->getChunkSize();
    terrainScaleFactor.set(terrainDescriptor->getScale());

    const vec2<U16>& terrainDimensions = terrainDescriptor->getDimensions();
    const vectorImpl<vec3<F32> >& normalData = groundVB->getNormal();
    const vectorImpl<vec3<F32> >& tangentData = groundVB->getTangent();

    U16 heightmapWidth = terrainDimensions.width;
    U16 heightmapHeight = terrainDimensions.height;
    vectorImpl<U16> heightValues;
    if (terrainDescriptor->is16Bit()) {
        assert(heightmapWidth != 0 && heightmapHeight != 0);
        stringImpl terrainRawFile(terrainDescriptor->getVariable("heightmap"));
        // only raw files for 16 bit support
        assert(terrainRawFile.substr(terrainRawFile.length() - 4,
                                     terrainRawFile.length()).compare(".raw") ==
               0);
        // Read File Data
        FILE* terrainFile = nullptr;
        fopen_s(&terrainFile, terrainRawFile.c_str(), "rb");
        assert(terrainFile);
        U32 lCurPos = ftell(terrainFile);
        fseek(terrainFile, 0, SEEK_END);
        U32 positionCount = ftell(terrainFile);
        fseek(terrainFile, lCurPos, SEEK_SET);
        heightValues.reserve(positionCount / 2);
        U8* dataTemp = MemoryManager_NEW U8[positionCount];
        rewind(terrainFile);
        assert(dataTemp);
        fread(dataTemp, 1, positionCount, terrainFile);
        fclose(terrainFile);
        for (U32 i = 0; i < positionCount + 1; i += 2) {
            heightValues.push_back(((U8)dataTemp[i + 1] << 8) |
                                   (U8)dataTemp[i]);
        }
        MemoryManager::DELETE_ARRAY(dataTemp);
    } else {
        ImageTools::ImageData img;
        img.create(terrainDescriptor->getVariable("heightmap"));
        assert(terrainDimensions == img.dimensions());
        // data will be destroyed when img gets out of scope
        const U8* data = img.data();
        assert(data);
        heightValues.reserve(heightmapWidth * heightmapWidth);
        for (size_t i = 0; i < img.imageSize(); ++i) {
            heightValues.push_back(data[i]);
        }
    }
    vec2<U16>& dimensions = TerrainLoaderAttorney::dimensions(*terrain);
    TerrainLoaderAttorney::dimensions(*terrain)
        .set(heightmapWidth, heightmapHeight);
    if (dimensions.x % 2 == 0) {
        dimensions.x++;
    }
    if (dimensions.y % 2 == 0) {
        dimensions.y++;
    }
    Console::d_printfn(Locale::get("TERRAIN_INFO"), dimensions.x, dimensions.y);

    I32 terrainWidth = (I32)dimensions.x;
    I32 terrainHeight = (I32)dimensions.y;
    F32 minAltitude = terrainDescriptor->getAltitudeRange().x;
    F32 maxAltitude = terrainDescriptor->getAltitudeRange().y;
    F32 altitudeRange = maxAltitude - minAltitude;

    groundVB->resizePositionCount(terrainWidth * terrainHeight);
    groundVB->resizeNormalCount(terrainWidth * terrainHeight);
    groundVB->resizeTangentCount(terrainWidth * terrainHeight);

    BoundingBox& terrainBB = TerrainLoaderAttorney::boundingBox(*terrain);

    terrainBB.set(
        vec3<F32>(-terrainWidth * 0.5f, minAltitude, -terrainHeight * 0.5f),
        vec3<F32>(terrainWidth * 0.5f, maxAltitude, terrainHeight * 0.5f));

    terrainBB.Translate(terrainDescriptor->getPosition());
    terrainBB.Multiply(vec3<F32>(terrainScaleFactor.x, terrainScaleFactor.y,
                                 terrainScaleFactor.x));
    F32 yOffset = terrainDescriptor->getPosition().y;
    const vec3<F32>& bMin = terrainBB.getMin();
    const vec3<F32>& bMax = terrainBB.getMax();
    F32 yScaleFactor = terrainScaleFactor.y;
    // scale and translate all height by half to convert from 0-255 (0-65335) to
    // -127 - 128 (-32767 - 32768)
    if (terrainDescriptor->is16Bit()) {
#pragma omp parallel for
        for (I32 j = 0; j < terrainHeight; j++) {
            for (I32 i = 0; i < terrainWidth; i++) {
                U32 idxHM = TER_COORD(i, j, terrainWidth);

                vec3<F32> vertexData;
                vertexData.x =
                    bMin.x + ((F32)i) * (bMax.x - bMin.x) / (terrainWidth - 1);
                vertexData.z =
                    bMin.z + ((F32)j) * (bMax.z - bMin.z) / (terrainHeight - 1);

                U32 idxIMG = TER_COORD<U32>(
                    i < (I32)heightmapWidth ? i : i - 1,
                    j < (I32)heightmapHeight ? j : j - 1, heightmapWidth);

                vertexData.y =
                    minAltitude +
                    altitudeRange * (F32)heightValues[idxIMG] / 65536.0f;
                vertexData.y *= yScaleFactor;
                vertexData.y += yOffset;
#pragma omp critical
                { groundVB->modifyPositionValue(idxHM, vertexData); }
            }
        }
    } else {
#pragma omp parallel for
        for (I32 j = 0; j < terrainHeight; j++) {
            for (I32 i = 0; i < terrainWidth; i++) {
                U32 idxHM = TER_COORD(i, j, terrainWidth);
                vec3<F32> vertexData;

                vertexData.x =
                    bMin.x + ((F32)i) * (bMax.x - bMin.x) / (terrainWidth - 1);
                vertexData.z =
                    bMin.z + ((F32)j) * (bMax.z - bMin.z) / (terrainHeight - 1);

                U32 idxIMG = TER_COORD<U32>(
                    i < (I32)heightmapWidth ? i : i - 1,
                    j < (I32)heightmapHeight ? j : j - 1, heightmapWidth);

                F32 h = static_cast<F32>(heightValues[idxIMG * 3 + 0] +
                                         heightValues[idxIMG * 3 + 1] +
                                         heightValues[idxIMG * 3 + 2]) /
                        3.0f;

                vertexData.y = minAltitude + altitudeRange * h / 255.0f;
                vertexData.y *= yScaleFactor;
                vertexData.y += yOffset;
#pragma omp critical
                { groundVB->modifyPositionValue(idxHM, vertexData); }
            }
        }
    }

    heightValues.clear();

    const vectorImpl<vec3<F32> >& groundPos = groundVB->getPosition();

    I32 offset = 2;
    vec3<F32> vU, vV, vUV;
    U32 idx = 0, idx0 = 0, idx1 = 0;
    for (I32 j = offset; j < terrainHeight - offset; j++) {
        for (I32 i = offset; i < terrainWidth - offset; i++) {
            idx = TER_COORD(i, j, terrainWidth);

            vU.set(groundPos[TER_COORD(i + offset, j + 0, terrainWidth)] -
                   groundPos[TER_COORD(i - offset, j + 0, terrainWidth)]);
            vV.set(groundPos[TER_COORD(i + 0, j + offset, terrainWidth)] -
                   groundPos[TER_COORD(i + 0, j - offset, terrainWidth)]);
            vUV.cross(vV, vU);
            vUV.normalize();
            groundVB->modifyNormalValue(idx, vUV);
            vU = -vU;
            vU.normalize();
            groundVB->modifyTangentValue(idx, vU);
        }
    }

    for (I32 j = 0; j < offset; j++) {
        for (I32 i = 0; i < terrainWidth; i++) {
            idx0 = TER_COORD(i, j, terrainWidth);
            idx1 = TER_COORD(i, offset, terrainWidth);

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0, tangentData[idx1]);

            idx0 = TER_COORD(i, terrainHeight - 1 - j, terrainWidth);
            idx1 = TER_COORD(i, terrainHeight - 1 - offset, terrainWidth);

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0, tangentData[idx1]);
        }
    }

    for (I32 i = 0; i < offset; i++) {
        for (I32 j = 0; j < terrainHeight; j++) {
            idx0 = TER_COORD(i, j, terrainWidth);
            idx1 = TER_COORD(offset, j, terrainWidth);

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0, normalData[idx1]);

            idx0 = TER_COORD(terrainWidth - 1 - i, j, terrainWidth);
            idx1 = TER_COORD(terrainWidth - 1 - offset, j, terrainWidth);

            groundVB->modifyNormalValue(idx0, normalData[idx1]);
            groundVB->modifyTangentValue(idx0, normalData[idx1]);
        }
    }
    groundVB->Create();
    TerrainLoaderAttorney::buildQuadtree(*terrain);
    initializeVegetation(terrain, terrainDescriptor);
    Console::printfn(Locale::get("TERRAIN_LOAD_END"),
                     terrain->getName().c_str());
    return true;
}

void TerrainLoader::initializeVegetation(Terrain* terrain,
                                         TerrainDescriptor* terrainDescriptor) {
    U8 textureCount = 0;
    stringImpl textureLocation;

    stringImpl currentImage = terrainDescriptor->getVariable("grassBillboard1");
    if (!currentImage.empty()) {
        textureLocation += currentImage;
        textureCount++;
    }

    currentImage = terrainDescriptor->getVariable("grassBillboard2");
    if (!currentImage.empty()) {
        textureLocation += " " + currentImage;
        textureCount++;
    }

    currentImage = terrainDescriptor->getVariable("grassBillboard3");
    if (!currentImage.empty()) {
        textureLocation += " " + currentImage;
        textureCount++;
    }

    currentImage = terrainDescriptor->getVariable("grassBillboard4");
    if (!currentImage.empty()) {
        textureLocation += " " + currentImage;
        textureCount++;
    }

    if (textureCount == 0) return;

    SamplerDescriptor grassSampler;
    grassSampler.setAnisotropy(0);
    grassSampler.setWrapMode(TextureWrap::TEXTURE_CLAMP);
    ResourceDescriptor textureDetailMaps("Vegetation Billboards");
    textureDetailMaps.setEnumValue(enum_to_uint(TextureType::TEXTURE_2D_ARRAY));
    textureDetailMaps.setID(textureCount);
    textureDetailMaps.setResourceLocation(textureLocation);
    textureDetailMaps.setPropertyDescriptor(grassSampler);
    Texture* grassBillboardArray = CreateResource<Texture>(textureDetailMaps);

    VegetationDetails& vegDetails =
        TerrainLoaderAttorney::vegetationDetails(*terrain);
    vegDetails.billboardCount = textureCount;
    vegDetails.name = terrainDescriptor->getName() + "_grass";
    vegDetails.grassDensity = terrainDescriptor->getGrassDensity();
    vegDetails.grassScale = terrainDescriptor->getGrassScale();
    vegDetails.treeDensity = terrainDescriptor->getTreeDensity();
    vegDetails.treeScale = terrainDescriptor->getTreeScale();
    vegDetails.map = terrainDescriptor->getVariable("grassMap");
    vegDetails.grassBillboards = grassBillboardArray;
    vegDetails.grassShaderName = "grass";
    vegDetails.parentTerrain = terrain;
}

bool TerrainLoader::Save(const char* fileName) { return true; }

bool TerrainLoader::Load(const char* filename) { return true; }
};

Commits for Divide-Framework/trunk/Source Code/Environment/Terrain/TerrainLoader.cpp

Diff revisions: vs.
Revision Author Commited Message
365 Diff Diff IonutCava picture IonutCava Sun 08 Mar, 2015 21:26:10 +0000

[Ionut]
- More enum-related type safety changes

364 Diff Diff IonutCava picture IonutCava Fri 06 Mar, 2015 16:55:21 +0000

[Ionut]
- Part 1 of type safe enum replacement (does not compile)

358 Diff Diff IonutCava picture IonutCava Sun 01 Mar, 2015 22:44:38 +0000

[Ionut]
- Fixed some OpenGL initialization issues and function calls (no proper support for DSA yet)
- Cleanup up the Sound and Physics Wrappers
- Some readability improvements here and there

351 Diff Diff IonutCava picture IonutCava Wed 11 Feb, 2015 16:39:15 +0000

[Ionut]
- Large amount of decoupling between classes by using Attorney-style classes where friendship was required.

350 Diff Diff IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)

343 Diff Diff IonutCava picture IonutCava Thu 15 Jan, 2015 17:30:12 +0000

[Ionut]
- Refactored 2 singletons into static classes (Console and TerrainLoader)
- Changed some C-casts to static_casts
- Updated copyright notices

337 Diff Diff IonutCava picture IonutCava Wed 17 Dec, 2014 17:25:16 +0000

[Ionut]
- Replaced all tabs with 4 spaces (some spacing may be off now. no way to check all the files.)
- Moved implementation details for ParamHandler, BoundingBox, BoundingSphere and ProfileTimer to proper .inl and .cpp files. (more to follow)
- Update all forward declared enums with the required storage type (as requested by the C++11 standard)

334 Diff Diff IonutCava picture IonutCava Wed 10 Dec, 2014 17:21:22 +0000

[Ionut]
- Reorganized the Hardware project and renamed to "Platform"
- Reorganized the Server project

333 Diff Diff IonutCava picture IonutCava Tue 09 Dec, 2014 16:15:44 +0000

[Ionut]
- Removed “core.h” and moved everything to their appropriate header files
- Renamed MathClasses to MathMatrices (finally)
- Renamed “-Inl.h” files to ".inl"
- Some String wrapper refactoring
- Update “InstallLibraries.bat” so that it still offers valid options

331 IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)