+void R_BeginCoronaQuery(rtlight_t *rtlight, float scale, qboolean usequery)
+{
+ // if it's too close, skip it
+ if (VectorLength(rtlight->color) < (1.0f / 256.0f))
+ return;
+ if (VectorDistance2(rtlight->shadoworigin, r_refdef.view.origin) < 32.0f * 32.0f)
+ return;
+ if (usequery && r_numqueries + 2 <= r_maxqueries)
+ {
+ rtlight->corona_queryindex_allpixels = r_queries[r_numqueries++];
+ rtlight->corona_queryindex_visiblepixels = r_queries[r_numqueries++];
+ CHECKGLERROR
+ qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_allpixels);
+ R_DrawSprite(GL_ONE, GL_ZERO, r_shadow_lightcorona, NULL, true, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, 1, 1, 1, 1);
+ qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
+ qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_visiblepixels);
+ R_DrawSprite(GL_ONE, GL_ZERO, r_shadow_lightcorona, NULL, false, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, 1, 1, 1, 1);
+ qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
+ CHECKGLERROR
+ }
+ rtlight->corona_visibility = 1;
+}
+
+void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale)
+{
+ vec3_t color;
+ GLint allpixels = 0, visiblepixels = 0;
+ // now we have to check the query result
+ if (rtlight->corona_queryindex_visiblepixels)
+ {
+ CHECKGLERROR
+ qglGetQueryObjectivARB(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT_ARB, &visiblepixels);
+ qglGetQueryObjectivARB(rtlight->corona_queryindex_allpixels, GL_QUERY_RESULT_ARB, &allpixels);
+ CHECKGLERROR
+ //Con_Printf("%i of %i pixels\n", (int)visiblepixels, (int)allpixels);
+ if (visiblepixels < 1 || allpixels < 1)
+ return;
+ rtlight->corona_visibility *= (float)visiblepixels / (float)allpixels;
+ cscale *= rtlight->corona_visibility;
+ }
+ else
+ {
+ // FIXME: these traces should scan all render entities instead of cl.world
+ if (CL_Move(r_refdef.view.origin, vec3_origin, vec3_origin, rtlight->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction < 1)
+ return;
+ }
+ VectorScale(rtlight->color, cscale, color);
+ if (VectorLength(color) > (1.0f / 256.0f))
+ R_DrawSprite(GL_ONE, GL_ONE, r_shadow_lightcorona, NULL, true, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, color[0], color[1], color[2], 1);
+}
+