| 223 | } |
| 224 | |
| 225 | void TerrainObject::DrawDepthMap(const mat4& proj_view_matrix, const vec4* cull_planes, int num_cull_planes, Object::DrawType draw_type) { |
| 226 | if (g_debug_runtime_disable_terrain_object_draw_depth_map) { |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | if (terrain_info_.minimal || preview_mode) |
| 231 | return; |
| 232 | PROFILER_GPU_ZONE(g_profiler_ctx, "TerrainObject::DrawDepthMap"); |
| 233 | Graphics* graphics = Graphics::Instance(); |
| 234 | Shaders* shaders = Shaders::Instance(); |
| 235 | // Textures* textures = Textures::Instance(); |
| 236 | // Camera* cam = ActiveCameras::Get(); |
| 237 | graphics->setGLState(gl_state_); |
| 238 | mat4 t = GetTransform(); // this seems to always be identity |
| 239 | vec4 test(1.0, 1.0, 1.0, 1.0); |
| 240 | LOG_ASSERT(t * test == test); |
| 241 | |
| 242 | bool use_tesselation = false; // GLEW_ARB_tessellation_shader; |
| 243 | |
| 244 | const int kShaderStrSize = 1024; |
| 245 | char buf[2][kShaderStrSize]; |
| 246 | char* shader_str[2] = {buf[0], buf[1]}; |
| 247 | FormatString(shader_str[0], kShaderStrSize, "envobject #TERRAIN #DEPTH_ONLY"); |
| 248 | if (draw_type == kDrawAllShadowCascades) { |
| 249 | FormatString(shader_str[1], kShaderStrSize, "%s #SHADOW_CASCADE", shader_str[0]); |
| 250 | std::swap(shader_str[0], shader_str[1]); |
| 251 | } |
| 252 | if (use_tesselation) { |
| 253 | FormatString(shader_str[1], kShaderStrSize, "%s #FRACTAL_DISPLACE", shader_str[0]); |
| 254 | std::swap(shader_str[0], shader_str[1]); |
| 255 | } |
| 256 | int shader = shaders->returnProgram(shader_str[0], use_tesselation ? Shaders::kTesselation : Shaders::kNone); |
| 257 | |
| 258 | shaders->setProgram(shader); |
| 259 | shaders->SetUniformMat4("projection_view_mat", proj_view_matrix); |
| 260 | shaders->SetUniformFloat("time", game_timer.GetRenderTime()); |
| 261 | shaders->SetUniformVec3("cam_pos", ActiveCameras::Get()->GetPos()); |
| 262 | const vec3 translation = GetTranslation(); |
| 263 | |
| 264 | int vert_attrib_id = shaders->returnShaderAttrib("vertex_attrib", shader); |
| 265 | graphics->EnableVertexAttribArray(vert_attrib_id); |
| 266 | for (auto& patch : terrain_.terrain_patches) { |
| 267 | const vec3 adjusted_min = patch.min_coords + translation; |
| 268 | const vec3 adjusted_max = patch.max_coords + translation; |
| 269 | if (CheckBoxAgainstPlanes(adjusted_min, adjusted_max, cull_planes, num_cull_planes)) { |
| 270 | if (!patch.vbo_loaded) { |
| 271 | patch.createVBO(); |
| 272 | } |
| 273 | patch.VBO_faces.Bind(); |
| 274 | patch.VBO_vertices.Bind(); |
| 275 | glVertexAttribPointer(vert_attrib_id, 3, GL_FLOAT, false, 3 * sizeof(GLfloat), 0); |
| 276 | graphics->DrawElements(use_tesselation ? GL_PATCHES : GL_TRIANGLES, (unsigned int)patch.faces.size(), GL_UNSIGNED_INT, 0); |
| 277 | } |
| 278 | } |
| 279 | for (auto& patch : terrain_.edge_terrain_patches) { |
| 280 | const vec3 adjusted_min = patch.min_coords + translation; |
| 281 | const vec3 adjusted_max = patch.max_coords + translation; |
| 282 | if (CheckBoxAgainstPlanes(adjusted_min, adjusted_max, cull_planes, num_cull_planes)) { |
nothing calls this directly
no test coverage detected