MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DrawTerrainTrianglesHardware

Function DrawTerrainTrianglesHardware

Descent3/terrainrender.cpp:2899–3150  ·  view source on GitHub ↗

Draws the 2 triangles of the Terrainlist[index] (hardware)

Source from the content-addressed store, hash-verified

2897}
2898// Draws the 2 triangles of the Terrainlist[index] (hardware)
2899int DrawTerrainTrianglesHardware(int index, int bm_handle, int upper_left, int lower_right) {
2900 int i;
2901 int cur_seg;
2902 int n = Terrain_list[index].segment;
2903 int lod = Terrain_list[index].lod;
2904 int bottom_start, left_start, right_start;
2905 int point_count = 0;
2906 int points_this_triangle = 0;
2907
2908 terrain_segment *tseg = &Terrain_seg[n];
2909 terrain_tex_segment *texseg = &Terrain_tex_seg[tseg->texseg_index];
2910 int rotator = texseg->rotation & 0x0F;
2911 int tile = texseg->rotation >> 4;
2912 int simplemul = 1 << ((MAX_TERRAIN_LOD - 1) - lod);
2913 int cx, cz, smul_x, smul_z;
2914 cx = n % TERRAIN_WIDTH;
2915 cz = n / TERRAIN_WIDTH;
2916
2917 // Get lightmap coordinates
2918 float lightmap_u = (cx % 128) / 128.0;
2919 float lightmap_v = (128 - ((cz % 128) + simplemul)) / 128.0;
2920 float uvadjust;
2921 int draw_big_square = 0;
2922 int subx = cx % MAX_LOD_SIZE;
2923 int subz = (MAX_LOD_SIZE - 1) - ((cz + (simplemul - 1)) % MAX_LOD_SIZE);
2924 bool solid_square = 1;
2925 int testt = 0, testr = 0, testb = 0, testl = 0;
2926 // Check to make sure we don't access memory that is off the map
2927 if (cx + simplemul == TERRAIN_WIDTH) {
2928 smul_x = simplemul - 1;
2929 solid_square = 0;
2930 } else
2931 smul_x = simplemul;
2932 if (cz + simplemul == TERRAIN_DEPTH) {
2933 solid_square = 0;
2934 smul_z = simplemul - 1;
2935 } else
2936 smul_z = simplemul;
2937 // Build a list of points for our polygon. We must do it this way to
2938 // prevent tjoint cracking
2939 // Do simpler operation if at highest level of detail
2940 if (lod == (MAX_TERRAIN_LOD - 1)) {
2941 uvadjust = (simplemul / 128.0);
2942 cur_seg = n + (TERRAIN_WIDTH * smul_z);
2943 base[0] = World_point_buffer[cur_seg];
2944
2945 cur_seg = n + (TERRAIN_WIDTH * smul_z) + smul_x;
2946 base[1] = World_point_buffer[cur_seg];
2947
2948 cur_seg = n + smul_x;
2949 base[2] = World_point_buffer[cur_seg];
2950
2951 base[3] = World_point_buffer[n];
2952
2953 base[0].p3_u = tile * TerrainUSpeedup[rotator][subz * LOD_ROW_SIZE + subx];
2954 base[0].p3_v = tile * TerrainVSpeedup[rotator][subz * LOD_ROW_SIZE + subx];
2955 base[1].p3_u = tile * TerrainUSpeedup[rotator][subz * LOD_ROW_SIZE + subx + 1];
2956 base[1].p3_v = tile * TerrainVSpeedup[rotator][subz * LOD_ROW_SIZE + subx + 1];

Callers 1

DisplayTerrainListFunction · 0.85

Calls 4

g3_DrawPolyFunction · 0.85
DrawTerrainOutlineFunction · 0.85
rend_SetOverlayTypeFunction · 0.50
rend_SetOverlayMapFunction · 0.50

Tested by

no test coverage detected