From 14f6bbadef2c39e58a3b54c0c6212949acf50e45 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 8 Aug 2011 15:29:23 -0500 Subject: SH-2242 Work in progress migrating to glVertexAttrib everywhere --- indra/newview/lldrawpoolbump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index d801f6df18..a0990ca645 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -762,7 +762,7 @@ void LLDrawPoolBump::renderBump(U32 pass) LLGLDisable fog(GL_FOG); LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_LEQUAL); LLGLEnable blend(GL_BLEND); - glColor4f(1,1,1,1); + gGL.diffuseColor4f(1,1,1,1); /// Get rid of z-fighting with non-bump pass. LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL); glPolygonOffset(-1.0f, -1.0f); -- cgit v1.2.3 From 7c95af74f195c9ec4ebc0fc0264d98cd4a85be49 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 14 Sep 2011 16:30:45 -0500 Subject: SH-2243 work in progress -- application side matrix stack management --- indra/newview/lldrawpoolbump.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index 0c3e93cd8a..501bd88970 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -1369,18 +1369,18 @@ void LLDrawPoolBump::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture, BOOL if (mShiny) { gGL.getTexUnit(0)->activate(); - glMatrixMode(GL_TEXTURE); + gGL.matrixMode(LLRender::MM_TEXTURE); } else { gGL.getTexUnit(1)->activate(); - glMatrixMode(GL_TEXTURE); - glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); gPipeline.mTextureMatrixOps++; gGL.getTexUnit(0)->activate(); } - glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix); + gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); gPipeline.mTextureMatrixOps++; tex_setup = true; @@ -1416,11 +1416,11 @@ void LLDrawPoolBump::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture, BOOL else { gGL.getTexUnit(1)->activate(); - glLoadIdentity(); + gGL.loadIdentity(); gGL.getTexUnit(0)->activate(); } - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); } } @@ -1465,6 +1465,7 @@ void LLDrawPoolInvisible::endDeferredPass( S32 pass ) void LLDrawPoolInvisible::renderDeferred( S32 pass ) { //render invisiprims; this doesn't work becaue it also blocks all the post-deferred stuff +#if 0 LLFastTimer t(FTM_RENDER_INVISIBLE); U32 invisi_mask = LLVertexBuffer::MAP_VERTEX; @@ -1482,4 +1483,5 @@ void LLDrawPoolInvisible::renderDeferred( S32 pass ) renderShiny(true); endShiny(true); } +#endif } -- cgit v1.2.3 From 967479f9039dc358b9419be7f117162f7d90609c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 5 Oct 2011 15:12:02 -0500 Subject: SH-2031 Fix for stall in image update -- don't use the CPU to convert a height map into a normal map -- use the GPU instead via a shader. Also, WTF glFinish? --- indra/newview/lldrawpoolbump.cpp | 176 ++++++++++++++++++++++++++++----------- 1 file changed, 128 insertions(+), 48 deletions(-) (limited to 'indra/newview/lldrawpoolbump.cpp') diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index 501bd88970..be12eb800f 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -1088,6 +1088,8 @@ LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedText } +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_STANDARD_LOADED("Bump Standard Callback"); + // static void LLBumpImageList::onSourceBrightnessLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata ) { @@ -1110,14 +1112,24 @@ void LLBumpImageList::onSourceDarknessLoaded( BOOL success, LLViewerFetchedTextu } } +static LLFastTimer::DeclareTimer FTM_BUMP_GEN_NORMAL("Generate Normal Map"); +static LLFastTimer::DeclareTimer FTM_BUMP_CREATE_TEXTURE("Create GL Normal Map"); + void LLBumpImageList::onSourceStandardLoaded( BOOL success, LLViewerFetchedTexture* src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata) { if (success && LLPipeline::sRenderDeferred) { + LLFastTimer t(FTM_BUMP_SOURCE_STANDARD_LOADED); LLPointer nrm_image = new LLImageRaw(src->getWidth(), src->getHeight(), 4); - generateNormalMapFromAlpha(src, nrm_image); + { + LLFastTimer t(FTM_BUMP_GEN_NORMAL); + generateNormalMapFromAlpha(src, nrm_image); + } src_vi->setExplicitFormat(GL_RGBA, GL_RGBA); - src_vi->createGLTexture(src_vi->getDiscardLevel(), nrm_image); + { + LLFastTimer t(FTM_BUMP_CREATE_TEXTURE); + src_vi->createGLTexture(src_vi->getDiscardLevel(), nrm_image); + } } } @@ -1176,24 +1188,39 @@ void LLBumpImageList::generateNormalMapFromAlpha(LLImageRaw* src, LLImageRaw* nr } } + +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_LOADED("Bump Source Loaded"); +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_ENTRIES_UPDATE("Entries Update"); +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_MIN_MAX("Min/Max"); +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_RGB2LUM("RGB to Luminance"); +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_RESCALE("Rescale"); +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_GEN_NORMAL("Generate Normal"); +static LLFastTimer::DeclareTimer FTM_BUMP_SOURCE_CREATE("Create"); + // static void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLImageRaw* src, LLUUID& source_asset_id, EBumpEffect bump_code ) { if( success ) { + LLFastTimer t(FTM_BUMP_SOURCE_LOADED); + + bump_image_map_t& entries_list(bump_code == BE_BRIGHTNESS ? gBumpImageList.mBrightnessEntries : gBumpImageList.mDarknessEntries ); bump_image_map_t::iterator iter = entries_list.find(source_asset_id); - if (iter == entries_list.end() || - iter->second.isNull() || - iter->second->getWidth() != src->getWidth() || - iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution - { //make sure an entry exists for this image - LLPointer raw = new LLImageRaw(1,1,1); - raw->clear(0x77, 0x77, 0xFF, 0xFF); - - entries_list[src_vi->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE); - iter = entries_list.find(src_vi->getID()); + { + LLFastTimer t(FTM_BUMP_SOURCE_ENTRIES_UPDATE); + if (iter == entries_list.end() || + iter->second.isNull() || + iter->second->getWidth() != src->getWidth() || + iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution + { //make sure an entry exists for this image + LLPointer raw = new LLImageRaw(1,1,1); + raw->clear(0x77, 0x77, 0xFF, 0xFF); + + entries_list[src_vi->getID()] = LLViewerTextureManager::getLocalTexture( raw.get(), TRUE); + iter = entries_list.find(src_vi->getID()); + } } //if (iter->second->getWidth() != src->getWidth() || @@ -1224,50 +1251,56 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI { case 1: case 2: - if( src_data_size == dst_data_size * src_components ) { - for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components ) + LLFastTimer t(FTM_BUMP_SOURCE_MIN_MAX); + if( src_data_size == dst_data_size * src_components ) { - dst_data[i] = src_data[j]; - if( dst_data[i] < minimum ) + for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components ) { - minimum = dst_data[i]; - } - if( dst_data[i] > maximum ) - { - maximum = dst_data[i]; + dst_data[i] = src_data[j]; + if( dst_data[i] < minimum ) + { + minimum = dst_data[i]; + } + if( dst_data[i] > maximum ) + { + maximum = dst_data[i]; + } } } - } - else - { - llassert(0); - dst_image->clear(); + else + { + llassert(0); + dst_image->clear(); + } } break; case 3: case 4: - if( src_data_size == dst_data_size * src_components ) { - for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components ) + LLFastTimer t(FTM_BUMP_SOURCE_RGB2LUM); + if( src_data_size == dst_data_size * src_components ) { - // RGB to luminance - dst_data[i] = (R_WEIGHT * src_data[j] + G_WEIGHT * src_data[j+1] + B_WEIGHT * src_data[j+2]) >> FIXED_PT; - //llassert( dst_data[i] <= 255 );true because it's 8bit - if( dst_data[i] < minimum ) - { - minimum = dst_data[i]; - } - if( dst_data[i] > maximum ) + for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components ) { - maximum = dst_data[i]; + // RGB to luminance + dst_data[i] = (R_WEIGHT * src_data[j] + G_WEIGHT * src_data[j+1] + B_WEIGHT * src_data[j+2]) >> FIXED_PT; + //llassert( dst_data[i] <= 255 );true because it's 8bit + if( dst_data[i] < minimum ) + { + minimum = dst_data[i]; + } + if( dst_data[i] > maximum ) + { + maximum = dst_data[i]; + } } } - } - else - { - llassert(0); - dst_image->clear(); + else + { + llassert(0); + dst_image->clear(); + } } break; default: @@ -1278,6 +1311,7 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI if( maximum > minimum ) { + LLFastTimer t(FTM_BUMP_SOURCE_RESCALE); U8 bias_and_scale_lut[256]; F32 twice_one_over_range = 2.f / (maximum - minimum); S32 i; @@ -1311,17 +1345,63 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI // accidentally releases it. LLPointer bump = LLViewerTextureManager::getLocalTexture( TRUE ); + if (!LLPipeline::sRenderDeferred) { + LLFastTimer t(FTM_BUMP_SOURCE_CREATE); bump->setExplicitFormat(GL_ALPHA8, GL_ALPHA); bump->createGLTexture(0, dst_image); } - else - { - LLPointer nrm_image = new LLImageRaw(dst_image->getWidth(), dst_image->getHeight(), 4); - generateNormalMapFromAlpha(dst_image, nrm_image); - bump->setExplicitFormat(GL_RGBA, GL_RGBA); - bump->createGLTexture(0, nrm_image); + else + { //convert to normal map + { + LLFastTimer t(FTM_BUMP_SOURCE_CREATE); + bump->setExplicitFormat(GL_RGBA8, GL_ALPHA); + bump->createGLTexture(0, dst_image); + } + + { + LLFastTimer t(FTM_BUMP_SOURCE_GEN_NORMAL); + gPipeline.mScreen.bindTarget(); + LLGLDepthTest depth(GL_FALSE); + LLGLDisable cull(GL_CULL_FACE); + LLGLDisable blend(GL_BLEND); + gGL.setColorMask(TRUE, TRUE); + gNormalMapGenProgram.bind(); + gNormalMapGenProgram.uniform1f("norm_scale", gSavedSettings.getF32("RenderNormalMapScale")); + gNormalMapGenProgram.uniform1f("stepX", 1.f/bump->getWidth()); + gNormalMapGenProgram.uniform1f("stepY", 1.f/bump->getHeight()); + + LLVector2 v((F32) bump->getWidth()/gPipeline.mScreen.getWidth(), + (F32) bump->getHeight()/gPipeline.mScreen.getHeight()); + + gGL.getTexUnit(0)->bind(bump); + + gGL.begin(LLRender::TRIANGLE_STRIP); + + gGL.texCoord2f(0, 0); + gGL.vertex2f(0, 0); + gGL.texCoord2f(0, 1); + gGL.vertex2f(0, v.mV[1]); + gGL.texCoord2f(1, 0); + gGL.vertex2f(v.mV[0], 0); + gGL.texCoord2f(1, 1); + gGL.vertex2f(v.mV[0], v.mV[1]); + + gGL.end(); + + gGL.flush(); + + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bump->getWidth(), bump->getHeight()); + + glGenerateMipmap(GL_TEXTURE_2D); + + gPipeline.mScreen.flush(); + + gNormalMapGenProgram.unbind(); + + //generateNormalMapFromAlpha(dst_image, nrm_image); + } } iter->second = bump; // derefs (and deletes) old image -- cgit v1.2.3