| 211 | } |
| 212 | |
| 213 | void Flares::OcclusionQuery(int which) { |
| 214 | Graphics* graphics = Graphics::Instance(); |
| 215 | Textures* textures = Textures::Instance(); |
| 216 | Shaders* shaders = Shaders::Instance(); |
| 217 | Camera* cam = ActiveCameras::Get(); |
| 218 | Flare* flare = flares[which]; |
| 219 | CHECK_GL_ERROR(); |
| 220 | int active_cam_id = ActiveCameras::Instance()->GetID(); |
| 221 | if ((int)flare->query.size() <= active_cam_id) { |
| 222 | flare->query.resize(active_cam_id + 1); |
| 223 | } |
| 224 | OccQuery& query = flare->query[active_cam_id]; |
| 225 | if (g_perform_occlusion_query) { |
| 226 | if (!query.created) { |
| 227 | glGenQueries(1, &query.id); |
| 228 | query.created = true; |
| 229 | } |
| 230 | CHECK_GL_ERROR(); |
| 231 | GLuint count = 0; |
| 232 | if (query.started) { |
| 233 | PROFILER_ZONE(g_profiler_ctx, "glGetQueryObjectuiv a"); |
| 234 | glGetQueryObjectuiv(query.id, GL_QUERY_RESULT_AVAILABLE, &count); |
| 235 | } else { |
| 236 | count = 1; |
| 237 | } |
| 238 | CHECK_GL_ERROR(); |
| 239 | if (count) { |
| 240 | if (query.started) { |
| 241 | PROFILER_ZONE(g_profiler_ctx, "glGetQueryObjectuiv b"); |
| 242 | glGetQueryObjectuiv(query.id, GL_QUERY_RESULT, &count); |
| 243 | unsigned total = _occlusion_size * _occlusion_size * |
| 244 | max(1, graphics->config_.FSAA_samples()); |
| 245 | flare->visible = min(1.0f, max(0.0f, ((float)count) / ((float)total))); |
| 246 | flare->visible *= flare->visible_mult; |
| 247 | } else { |
| 248 | query.started = true; |
| 249 | flare->visible = 0.0f; |
| 250 | } |
| 251 | { |
| 252 | PROFILER_ZONE(g_profiler_ctx, "glBeginQuery"); |
| 253 | // LOGI << "flare_begin_query " << query.id << std::endl; |
| 254 | glBeginQuery(GL_SAMPLES_PASSED, query.id); |
| 255 | } |
| 256 | if (flare->visible_mult > 0.0f) { |
| 257 | vec3 cam_to_flare; |
| 258 | vec3 cam_pos = cam->GetPos(); |
| 259 | |
| 260 | if (flare->distant) { |
| 261 | cam_to_flare = flare->position; |
| 262 | } else { |
| 263 | cam_to_flare = flare->position - cam_pos; |
| 264 | } |
| 265 | cam_to_flare = normalize(cam_to_flare); |
| 266 | float dot_prod = dot(cam_to_flare, cam->GetFacing()); |
| 267 | if (dot_prod > 0.0f) { |
| 268 | CHECK_GL_ERROR(); |
| 269 | vec3 flare_pos; |
| 270 | if (flare->distant) { |
nothing calls this directly
no test coverage detected