From 5161b500c97878179cc4f8c9a0df717a25c5cb14 Mon Sep 17 00:00:00 2001
From: Kyle Ambroff <ambroff@lindenlab.com>
Date: Thu, 27 Jan 2011 15:14:18 -0800
Subject: Prevent crashiness from DisableRendering setting.

When DisableRendering is set, bypass all of the new rendering code that would
have crashed otherwise, since the GL manager isn't initialized.

Many of these blocks will be removed once I get LLWindowHeadless working with
the viewer.

--HG--
branch : headless
---
 indra/llrender/llgl.cpp           |  42 ++++++++++---
 indra/llrender/llimagegl.cpp      |  18 ++++++
 indra/newview/llviewermessage.cpp |  11 +++-
 indra/newview/llviewerwindow.cpp  |   8 +--
 indra/newview/llwearable.cpp      |   7 +++
 indra/newview/pipeline.cpp        | 126 +++++++++++++++++++++++++++++++++++++-
 6 files changed, 199 insertions(+), 13 deletions(-)

diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp
index 6ea63809f8..4d9ed0f0e2 100644
--- a/indra/llrender/llgl.cpp
+++ b/indra/llrender/llgl.cpp
@@ -538,9 +538,24 @@ void LLGLManager::setToDebugGPU()
 
 void LLGLManager::getGLInfo(LLSD& info)
 {
-	info["GLInfo"]["GLVendor"] = std::string((const char *)glGetString(GL_VENDOR));
-	info["GLInfo"]["GLRenderer"] = std::string((const char *)glGetString(GL_RENDERER));
-	info["GLInfo"]["GLVersion"] = std::string((const char *)glGetString(GL_VERSION));
+	// KWA FIXME: Disabling this for now if we are headless. Will revert
+	// this after MESA implementation of llwindow is working for the
+	// headless viewer.
+	if (gNoRender)
+	{
+		info["GLInfo"]["GLVendor"] = "";
+		info["GLInfo"]["GLRenderer"] = "";
+		info["GLInfo"]["GLVersion"] = "";
+	}
+	else
+	{
+		info["GLInfo"]["GLVendor"] =
+			std::string((const char *)glGetString(GL_VENDOR));
+		info["GLInfo"]["GLRenderer"] =
+			std::string((const char *)glGetString(GL_RENDERER));
+		info["GLInfo"]["GLVersion"] =
+			std::string((const char *)glGetString(GL_VERSION));
+	}
 
 #if !LL_MESA_HEADLESS
 	std::string all_exts = ll_safe_string((const char *)gGLHExts.mSysExts);
@@ -573,12 +588,25 @@ std::string LLGLManager::getGLInfoString()
 
 void LLGLManager::printGLInfoString()
 {
+	// KWA FIXME remove this when mesa implementation of llwindow is
+	// working.
+	if (gNoRender)
+	{
+		return;
+	}
+
 	std::string info_str;
 	std::string all_exts, line;
-	
-	LL_INFOS("RenderInit") << "GL_VENDOR:     " << ((const char *)glGetString(GL_VENDOR)) << LL_ENDL;
-	LL_INFOS("RenderInit") << "GL_RENDERER:   " << ((const char *)glGetString(GL_RENDERER)) << LL_ENDL;
-	LL_INFOS("RenderInit") << "GL_VERSION:    " << ((const char *)glGetString(GL_VERSION)) << LL_ENDL;
+
+	LL_INFOS("RenderInit") << "GL_VENDOR:     "
+			       << ((const char *)glGetString(GL_VENDOR))
+			       << LL_ENDL;
+	LL_INFOS("RenderInit") << "GL_RENDERER:   "
+			       << ((const char *)glGetString(GL_RENDERER))
+			       << LL_ENDL;
+	LL_INFOS("RenderInit") << "GL_VERSION:    "
+			       << ((const char *)glGetString(GL_VERSION))
+			       << LL_ENDL;
 
 #if !LL_MESA_HEADLESS
 	all_exts = std::string(gGLHExts.mSysExts);
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index e8e98211f1..4dfae948a8 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -1100,6 +1100,12 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt
 //the texture is assiciate with some image by calling glTexImage outside LLImageGL
 BOOL LLImageGL::createGLTexture()
 {
+	// KWA FIXME remove this when MESA llwindow works in the viewer.
+	if (gNoRender)
+	{
+		return FALSE;
+	}
+
 	if (gGLManager.mIsDisabled)
 	{
 		llwarns << "Trying to create a texture while GL is disabled!" << llendl;
@@ -1128,6 +1134,12 @@ BOOL LLImageGL::createGLTexture()
 
 BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename/*=0*/, BOOL to_create, S32 category)
 {
+	// KWA FIXME remove this when MESA llwindow works in the viewer.
+	if (gNoRender)
+	{
+		return FALSE;
+	}
+
 	if (gGLManager.mIsDisabled)
 	{
 		llwarns << "Trying to create a texture while GL is disabled!" << llendl;
@@ -1202,6 +1214,12 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S
 
 BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_hasmips, S32 usename)
 {
+	// KWA FIXME remove this when MESA llwindow works in the viewer.
+	if (gNoRender)
+	{
+		return FALSE;
+	}
+
 	llassert(data_in);
 
 	if (discard_level < 0)
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index 6fc85a3944..b921c79973 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -3936,7 +3936,16 @@ void send_agent_update(BOOL force_send, BOOL send_reliable)
 	// LBUTTON and ML_LBUTTON so that using the camera (alt-key) doesn't
 	// trigger a control event.
 	U32 control_flags = gAgent.getControlFlags();
-	MASK	key_mask = gKeyboard->currentMask(TRUE);
+
+	// KWA FIXME: We should wire this up to the event system so we can
+	// send keyboard events via lleventhost. For now if we are headless,
+	// just don't ask for input.
+	MASK key_mask = MASK_NONE;
+	if (!gNoRender)
+	{
+		key_mask = gKeyboard->currentMask(TRUE);
+	}
+
 	if (key_mask & MASK_ALT || key_mask & MASK_CONTROL)
 	{
 		control_flags &= ~(	AGENT_CONTROL_LBUTTON_DOWN |
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 166b110412..7b41ac9287 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -2573,15 +2573,15 @@ void LLViewerWindow::updateUI()
 
 	LLView::sMouseHandlerMessage.clear();
 
-	S32 x = mCurrentMousePoint.mX;
-	S32 y = mCurrentMousePoint.mY;
-	MASK mask = gKeyboard->currentMask(TRUE);
-
 	if (gNoRender)
 	{
 		return;
 	}
 
+	S32 x = mCurrentMousePoint.mX;
+	S32 y = mCurrentMousePoint.mY;
+	MASK mask = gKeyboard->currentMask(TRUE);
+
 	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST))
 	{
 		gDebugRaycastFaceHit = -1;
diff --git a/indra/newview/llwearable.cpp b/indra/newview/llwearable.cpp
index d1c0990f90..ddb6b4697f 100644
--- a/indra/newview/llwearable.cpp
+++ b/indra/newview/llwearable.cpp
@@ -981,6 +981,13 @@ BOOL LLWearable::isOnTop() const
 
 void LLWearable::createLayers(S32 te)
 {
+	// KWA FIXME: this is wrong. We should still be setting up these layers.
+	// why the hell isn't it working?
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLTexLayerSet *layer_set = gAgentAvatarp->getLayerSet((ETextureIndex)te);
 	if (layer_set)
 	{
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 59b526059b..15f3156622 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -419,6 +419,12 @@ LLPipeline::~LLPipeline()
 
 void LLPipeline::cleanup()
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	assertInitialized();
 
 	mGroupQ1.clear() ;
@@ -515,6 +521,12 @@ static LLFastTimer::DeclareTimer FTM_RESIZE_SCREEN_TEXTURE("Resize Screen Textur
 
 void LLPipeline::resizeScreenTexture()
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLFastTimer ft(FTM_RESIZE_SCREEN_TEXTURE);
 	if (gPipeline.canUseVertexShaders() && assertInitialized())
 	{
@@ -640,6 +652,12 @@ void LLPipeline::updateRenderDeferred()
 
 void LLPipeline::releaseGLBuffers()
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	assertInitialized();
 	
 	if (mNoiseMap)
@@ -694,6 +712,12 @@ void LLPipeline::releaseGLBuffers()
 
 void LLPipeline::createGLBuffers()
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt_cb(LLMemType::MTYPE_PIPELINE_CREATE_BUFFERS);
 	assertInitialized();
 
@@ -816,6 +840,12 @@ void LLPipeline::createGLBuffers()
 
 void LLPipeline::restoreGL() 
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt_cb(LLMemType::MTYPE_PIPELINE_RESTORE_GL);
 	assertInitialized();
 
@@ -842,6 +872,12 @@ void LLPipeline::restoreGL()
 
 BOOL LLPipeline::canUseVertexShaders()
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return FALSE;
+	}
+
 	if (sDisableShaders ||
 		!gGLManager.mHasVertexShader ||
 		!gGLManager.mHasFragmentShader ||
@@ -908,6 +944,12 @@ S32 LLPipeline::getMaxLightingDetail() const
 
 S32 LLPipeline::setLightingDetail(S32 level)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return 0;
+	}
+
 	LLMemType mt_ld(LLMemType::MTYPE_PIPELINE_LIGHTING_DETAIL);
 	assertInitialized();
 
@@ -973,6 +1015,12 @@ public:
 // Called when a texture changes # of channels (causes faces to move to alpha pool)
 void LLPipeline::dirtyPoolObjectTextures(const std::set<LLViewerFetchedTexture*>& textures)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	assertInitialized();
 
 	// *TODO: This is inefficient and causes frame spikes; need a better way to do this
@@ -1005,6 +1053,12 @@ void LLPipeline::dirtyPoolObjectTextures(const std::set<LLViewerFetchedTexture*>
 
 LLDrawPool *LLPipeline::findPool(const U32 type, LLViewerTexture *tex0)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return NULL;
+	}
+
 	assertInitialized();
 
 	LLDrawPool *poolp = NULL;
@@ -1132,6 +1186,11 @@ U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* ima
 
 void LLPipeline::addPool(LLDrawPool *new_poolp)
 {
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt_a(LLMemType::MTYPE_PIPELINE_ADD_POOL);
 	assertInitialized();
 	mPools.insert(new_poolp);
@@ -1159,6 +1218,12 @@ void LLPipeline::allocDrawable(LLViewerObject *vobj)
 
 void LLPipeline::unlinkDrawable(LLDrawable *drawable)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLFastTimer t(FTM_PIPELINE);
 
 	assertInitialized();
@@ -1308,6 +1373,12 @@ void LLPipeline::createObject(LLViewerObject* vobj)
 
 void LLPipeline::resetFrameStats()
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	assertInitialized();
 
 	LLViewerStats::getInstance()->mTrianglesDrawnStat.addValue(mTrianglesDrawn/1000.f);
@@ -2175,6 +2246,12 @@ void LLPipeline::markRebuild(LLSpatialGroup* group, BOOL priority)
 
 void LLPipeline::markRebuild(LLDrawable *drawablep, LLDrawable::EDrawableFlags flag, BOOL priority)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt(LLMemType::MTYPE_PIPELINE_MARK_REBUILD);
 
 	if (drawablep && !drawablep->isDead() && assertInitialized())
@@ -3807,6 +3884,12 @@ void LLPipeline::renderDebug()
 
 void LLPipeline::rebuildPools()
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt(LLMemType::MTYPE_PIPELINE_REBUILD_POOLS);
 
 	assertInitialized();
@@ -3847,6 +3930,12 @@ void LLPipeline::rebuildPools()
 
 void LLPipeline::addToQuickLookup( LLDrawPool* new_poolp )
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt(LLMemType::MTYPE_PIPELINE_QUICK_LOOKUP);
 
 	assertInitialized();
@@ -4341,6 +4430,11 @@ void LLPipeline::calcNearbyLights(LLCamera& camera)
 
 void LLPipeline::setupHWLights(LLDrawPool* pool)
 {
+	if (gNoRender)
+	{
+		return;
+	}
+
 	assertInitialized();
 
 	// Ambient
@@ -4521,6 +4615,12 @@ void LLPipeline::setupHWLights(LLDrawPool* pool)
 
 void LLPipeline::enableLights(U32 mask)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	assertInitialized();
 
 	if (mLightingDetail == 0)
@@ -4621,6 +4721,12 @@ void LLPipeline::enableLightsAvatarEdit(const LLColor4& color)
 
 void LLPipeline::enableLightsFullbright(const LLColor4& color)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	assertInitialized();
 	U32 mask = 0x1000; // Non-0 mask, set ambient
 	enableLights(mask);
@@ -5381,6 +5487,12 @@ static LLFastTimer::DeclareTimer FTM_RENDER_BLOOM("Bloom");
 
 void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt_ru(LLMemType::MTYPE_PIPELINE_RENDER_BLOOM);
 	if (!(gPipeline.canUseVertexShaders() &&
 		sRenderGlow))
@@ -7036,7 +7148,13 @@ inline float sgn(float a)
 }
 
 void LLPipeline::generateWaterReflection(LLCamera& camera_in)
-{	
+{
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	if (LLPipeline::sWaterReflections && assertInitialized() && LLDrawPoolWater::sNeedsReflectionUpdate)
 	{
 		BOOL skip_avatar_update = FALSE;
@@ -8617,6 +8735,12 @@ void LLPipeline::renderGroups(LLRenderPass* pass, U32 type, U32 mask, BOOL textu
 
 void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 {
+	// KWA FIXME reevaluate once MESA llwindow is working when headless
+	if (gNoRender)
+	{
+		return;
+	}
+
 	LLMemType mt_gi(LLMemType::MTYPE_PIPELINE_GENERATE_IMPOSTOR);
 	LLGLState::checkStates();
 	LLGLState::checkTextureChannels();
-- 
cgit v1.2.3

-- 
cgit v1.2.3