void render_ui(F32 zoom_factor, int subfield)
{
	LLGLState::checkStates();
	
	glPushMatrix();
	glLoadMatrixd(gGLLastModelView);
	glh::matrix4f saved_view = glh_get_current_modelview();
	glh_set_current_modelview(glh_copy_matrix(gGLLastModelView));
	
	{
		BOOL to_texture = gPipeline.canUseVertexShaders() &&
							LLPipeline::sRenderGlow;

		if (to_texture)
		{
			gPipeline.renderBloom(gSnapshot, zoom_factor, subfield);
		}

		render_hud_elements();
		render_hud_attachments();
	}

	LLGLSDefault gls_default;
	LLGLSUIDefault gls_ui;
	{
		gPipeline.disableLights();
	}

	{
		
		gGL.color4f(1,1,1,1);
		if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
		{
			LLFastTimer t(LLFastTimer::FTM_RENDER_UI);

			if (!gDisconnected)
			{
				render_ui_3d();
				LLGLState::checkStates();
			}

			render_ui_2d();
			LLGLState::checkStates();
		}
		gGL.flush();

		{
			gViewerWindow->setup2DRender();
			gViewerWindow->updateDebugText();
			gViewerWindow->drawDebugText();
		}

		LLVertexBuffer::unbind();
	}

	glh_set_current_modelview(saved_view);
	glPopMatrix();

	if (gDisplaySwapBuffers)
	{
		LLFastTimer t(LLFastTimer::FTM_SWAP);
		gViewerWindow->mWindow->swapBuffers();
	}
	gDisplaySwapBuffers = TRUE;
}
void render_ui(F32 zoom_factor, int subfield, bool tiling)
{
	LLGLState::checkStates();
	
	glh::matrix4f saved_view = glh_get_current_modelview();

	if (!gSnapshot)
	{
		gGL.pushMatrix();
		gGL.loadMatrix(gGLLastModelView);
		glh_set_current_modelview(glh_copy_matrix(gGLLastModelView));
	}
	
	{
		BOOL to_texture = gPipeline.canUseVertexShaders() &&
							LLPipeline::sRenderGlow;

		if (to_texture)
		{
			gPipeline.renderBloom(gSnapshot, zoom_factor, subfield, tiling);
		}

		if(gPipeline.canUseVertexShaders())
		{
			LLPostProcess::getInstance()->renderEffects(gViewerWindow->getWindowDisplayWidth(), gViewerWindow->getWindowDisplayHeight());
		}
		
		render_hud_elements();
		render_hud_attachments();
	}

	LLGLSDefault gls_default;
	LLGLSUIDefault gls_ui;
	{
		gPipeline.disableLights();
	}

	{
		gGL.color4f(1,1,1,1);
		if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
		{
			LLFastTimer t(FTM_RENDER_UI);

			if (!gDisconnected)
			{
				render_ui_3d();
				LLGLState::checkStates();
			}
			else
			{
				render_disconnected_background();
			}

			render_ui_2d();
			LLGLState::checkStates();
		}
		gGL.flush();

		{
			gViewerWindow->setup2DRender();
			gViewerWindow->updateDebugText();
			gViewerWindow->drawDebugText();
		}

		LLVertexBuffer::unbind();
	}

	if (!gSnapshot)
	{
		glh_set_current_modelview(saved_view);
		gGL.popMatrix();
	}

	if (gDisplaySwapBuffers)
	{
		LLFastTimer t(FTM_SWAP);
		gViewerWindow->getWindow()->swapBuffers();
	}
	gDisplaySwapBuffers = TRUE;
}