Example #1
0
/**
 * @brief handle post-processing bloom
 */
void R_DrawBloom (void)
{
	int i;
	bool renderBufferState;

	if (!r_config.frameBufferObject || !r_postprocess->integer || !r_programs->integer)
		return;

	/* save state, then set up for blit-style rendering to quads */
	renderBufferState = R_RenderbufferEnabled();
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_TEXTURE);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
#ifndef GL_VERSION_ES_CM_1_0
	glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
#endif
	glOrtho(0, viddef.context.width, viddef.context.height, 0, 9999.0f, SKYBOX_DEPTH);

	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);

	/* downsample into image pyramid */
	R_ResolveMSAA(fbo_render);
	R_BindTexture(fbo_render->textures[1]);
	qglGenerateMipmapEXT(GL_TEXTURE_2D);

	R_Blur(fbo_render, fbo_bloom0, 1, 0);
	R_Blur(fbo_bloom0, fbo_bloom1, 0, 1);

	R_UseFramebuffer(r_state.buffers0[0]);
	R_BindTexture(fbo_bloom1->textures[0]);
	qglGenerateMipmapEXT(GL_TEXTURE_2D);
	R_UseViewport(r_state.buffers0[0]);
	R_DrawQuad();

	for (i = 1; i < DOWNSAMPLE_PASSES; i++) {
		R_Blur(r_state.buffers0[i - 1], r_state.buffers1[i - 1], 0, 0);
		R_Blur(r_state.buffers1[i - 1], r_state.buffers2[i - 1], 0, 1);
		R_UseFramebuffer(r_state.buffers0[i]);
		R_BindTexture(r_state.buffers2[i - 1]->textures[0]);
		R_UseViewport(r_state.buffers0[i]);
		R_DrawQuad();
	}

	/* blur and combine downsampled images */
	R_BlurStack(DOWNSAMPLE_PASSES, r_state.buffers0, r_state.buffers1);

	/* re-combine the blurred version with the original "glow" image */
	R_UseProgram(r_state.combine2_program);
	R_UseFramebuffer(fbo_bloom0);
	R_BindTextureForTexUnit(fbo_render->textures[1], &texunit_0);
	R_BindTextureForTexUnit(r_state.buffers1[0]->textures[0], &texunit_1);

	R_UseViewport(fbo_screen);
	R_DrawQuad();

	/* draw final result to the screenbuffer */
	R_UseFramebuffer(fbo_screen);
	R_UseProgram(r_state.combine2_program);
	R_BindTextureForTexUnit(fbo_render->textures[0], &texunit_0);
	R_BindTextureForTexUnit(fbo_bloom0->textures[0], &texunit_1);

	R_DrawQuad();

	/* cleanup before returning */
	R_UseProgram(default_program);

	R_CheckError();

#ifndef GL_VERSION_ES_CM_1_0
	glPopAttrib();
#endif
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_TEXTURE);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	R_CheckError();

	/* reset renderbuffer state to what it was before */
	R_EnableRenderbuffer(renderBufferState);
}
void uiGeoscapeNode::draw (uiNode_t* node)
{
    vec2_t screenPos;

    geoscapeNode = node;
    UI_MAPEXTRADATA(node).flatgeoscape = cl_3dmap->integer == 0;
    UI_MAPEXTRADATA(node).radarOverlay = Cvar_GetValue("geo_overlay_radar");
    UI_MAPEXTRADATA(node).nationOverlay = Cvar_GetValue("geo_overlay_nation");
    UI_MAPEXTRADATA(node).xviOverlay = Cvar_GetValue("geo_overlay_xvi");
    UI_MAPEXTRADATA(node).ambientLightFactor = cl_3dmapAmbient->value;
    UI_MAPEXTRADATA(node).mapzoommin = cl_mapzoommin->value;
    UI_MAPEXTRADATA(node).mapzoommax = cl_mapzoommax->value;

    UI_GetNodeAbsPos(node, UI_MAPEXTRADATA(node).mapPos);
    Vector2Copy(node->box.size, UI_MAPEXTRADATA(node).mapSize);
    if (!UI_MAPEXTRADATACONST(node).flatgeoscape) {
        /* remove the left padding */
        UI_MAPEXTRADATA(node).mapSize[0] -= UI_MAPEXTRADATACONST(node).paddingRight;
    }

    /* Draw geoscape */
    UI_GetNodeScreenPos(node, screenPos);
    UI_PushClipRect(screenPos[0], screenPos[1], node->box.size[0], node->box.size[1]);

    if (UI_MAPEXTRADATACONST(node).smoothRotation) {
        if (UI_MAPEXTRADATACONST(node).flatgeoscape)
            smoothTranslate(node);
        else
            smoothRotate(node);
    }

    geoscapeData_t& data = *UI_MAPEXTRADATA(node).geoscapeData;
    data.geoscapeNode = node;
    GAME_DrawMap(&data);
    if (!data.active)
        return;

    const char* map = data.map;
    date_t& date = data.date;

    /* Draw the map and markers */
    if (UI_MAPEXTRADATACONST(node).flatgeoscape) {
        /* the last q value for the 2d geoscape night overlay */
        static float lastQ = 0.0f;

        /* the sun is not always in the plane of the equator on earth - calculate the angle the sun is at */
        const float q = (date.day % DAYS_PER_YEAR + (float)(date.sec / (SECONDS_PER_HOUR * 6)) / 4) * 2 * M_PI / DAYS_PER_YEAR - M_PI;
        if (lastQ != q) {
            calcAndUploadDayAndNightTexture(node, q);
            lastQ = q;
        }
        R_DrawFlatGeoscape(UI_MAPEXTRADATACONST(node).mapPos, UI_MAPEXTRADATACONST(node).mapSize, (float) date.sec / SECONDS_PER_DAY,
                           UI_MAPEXTRADATACONST(node).center[0], UI_MAPEXTRADATACONST(node).center[1], 0.5 / UI_MAPEXTRADATACONST(node).zoom, map,
                           data.nationOverlay, data.xviOverlay, data.radarOverlay, r_dayandnightTexture, r_xviTexture, r_radarTexture);

        GAME_DrawMapMarkers(node);
    } else {
        bool disableSolarRender = false;
        if (UI_MAPEXTRADATACONST(node).zoom > 3.3)
            disableSolarRender = true;

        R_EnableRenderbuffer(true);

        R_Draw3DGlobe(UI_MAPEXTRADATACONST(node).mapPos, UI_MAPEXTRADATACONST(node).mapSize, date.day, date.sec,
                      UI_MAPEXTRADATACONST(node).angles, UI_MAPEXTRADATACONST(node).zoom, map, disableSolarRender,
                      UI_MAPEXTRADATACONST(node).ambientLightFactor, UI_MAPEXTRADATA(node).nationOverlay,
                      UI_MAPEXTRADATA(node).xviOverlay, UI_MAPEXTRADATA(node).radarOverlay, r_xviTexture, r_radarTexture,
                      true);

        GAME_DrawMapMarkers(node);

        R_DrawBloom();
        R_EnableRenderbuffer(false);
    }

    UI_PopClipRect();
}