diff options
Diffstat (limited to 'indra/newview/llface.cpp')
-rw-r--r-- | indra/newview/llface.cpp | 792 |
1 files changed, 223 insertions, 569 deletions
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index 85abec6cc8..9a3fb1e4c9 100644 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -47,7 +47,6 @@ #include "llviewercamera.h" #include "llviewertexturelist.h" #include "llvopartgroup.h" -#include "llvosky.h" #include "llvovolume.h" #include "pipeline.h" #include "llviewerregion.h" @@ -192,7 +191,6 @@ void LLFace::destroy() if (isState(LLFace::PARTICLE)) { - LLVOPartGroup::freeVBSlot(getGeomIndex()/4); clearState(LLFace::PARTICLE); } @@ -213,7 +211,7 @@ void LLFace::destroy() if (group) { group->dirtyGeom(); - gPipeline.markRebuild(group, TRUE); + gPipeline.markRebuild(group); } } } @@ -252,7 +250,7 @@ void LLFace::setPool(LLFacePool* new_pool, LLViewerTexture *texturep) if (mDrawablep) { - gPipeline.markRebuild(mDrawablep, LLDrawable::REBUILD_ALL, TRUE); + gPipeline.markRebuild(mDrawablep, LLDrawable::REBUILD_ALL); } } mGeomIndex = 0; @@ -334,7 +332,7 @@ void LLFace::dirtyTexture() vobj->updateVisualComplexity(); } - gPipeline.markRebuild(drawablep, LLDrawable::REBUILD_VOLUME, FALSE); + gPipeline.markRebuild(drawablep, LLDrawable::REBUILD_VOLUME); } } } @@ -342,34 +340,6 @@ void LLFace::dirtyTexture() gPipeline.markTextured(drawablep); } -void LLFace::notifyAboutCreatingTexture(LLViewerTexture *texture) -{ - LLDrawable* drawablep = getDrawable(); - if(mVObjp.notNull() && mVObjp->getVolume()) - { - LLVOVolume *vobj = drawablep->getVOVolume(); - if(vobj && vobj->notifyAboutCreatingTexture(texture)) - { - gPipeline.markTextured(drawablep); - gPipeline.markRebuild(drawablep, LLDrawable::REBUILD_VOLUME); - } - } -} - -void LLFace::notifyAboutMissingAsset(LLViewerTexture *texture) -{ - LLDrawable* drawablep = getDrawable(); - if(mVObjp.notNull() && mVObjp->getVolume()) - { - LLVOVolume *vobj = drawablep->getVOVolume(); - if(vobj && vobj->notifyAboutMissingAsset(texture)) - { - gPipeline.markTextured(drawablep); - gPipeline.markRebuild(drawablep, LLDrawable::REBUILD_VOLUME); - } - } -} - void LLFace::switchTexture(U32 ch, LLViewerTexture* new_texture) { llassert(ch < LLRender::NUM_TEXTURE_CHANNELS); @@ -387,11 +357,9 @@ void LLFace::switchTexture(U32 ch, LLViewerTexture* new_texture) llassert(mTexture[ch].notNull()); - new_texture->addTextureStats(mTexture[ch]->getMaxVirtualSize()) ; - if (ch == LLRender::DIFFUSE_MAP) { - getViewerObject()->changeTEImage(mTEOffset, new_texture) ; + getViewerObject()->changeTEImage(mTEOffset, new_texture) ; } setTexture(ch, new_texture) ; @@ -567,6 +535,7 @@ void LLFace::renderSelected(LLViewerTexture *imagep, const LLColor4& color) if (mDrawablep->isState(LLDrawable::RIGGED)) { +#if 0 // TODO -- there is no way this won't destroy our GL machine as implemented, rewrite it to not rely on software skinning LLVOVolume* volume = mDrawablep->getVOVolume(); if (volume) { @@ -590,19 +559,19 @@ void LLFace::renderSelected(LLViewerTexture *imagep, const LLColor4& color) #endif } gGL.syncMatrices(); - LL_PROFILER_GPU_ZONEC( "gl.DrawElements", 0x00FF00 ); glDrawElements(GL_TRIANGLES, vol_face.mNumIndices, GL_UNSIGNED_SHORT, vol_face.mIndices); #if GL_VERSION_1_1 glDisableClientState(GL_TEXTURE_COORD_ARRAY); #endif } } +#endif } else { // cheaters sometimes prosper... // - mVertexBuffer->setBuffer(mVertexBuffer->getTypeMask()); + mVertexBuffer->setBuffer(); mVertexBuffer->draw(LLRender::TRIANGLES, mIndicesCount, mIndicesIndex); } @@ -650,18 +619,6 @@ void LLFace::renderOneWireframe(const LLColor4 &color, F32 fogCfx, bool wirefram } else { -#if GL_VERSION_1_1 - LLGLEnable fog(GL_FOG); - glFogi(GL_FOG_MODE, GL_LINEAR); -#endif - float d = (LLViewerCamera::getInstance()->getPointOfInterest() - LLViewerCamera::getInstance()->getOrigin()).magVec(); - LLColor4 fogCol = color * fogCfx; -#if GL_VERSION_1_1 - glFogf(GL_FOG_START, d); - glFogf(GL_FOG_END, d*(1 + (LLViewerCamera::getInstance()->getView() / LLViewerCamera::getInstance()->getDefaultFOV()))); - glFogfv(GL_FOG_COLOR, fogCol.mV); -#endif - gGL.flush(); { gGL.diffuseColor4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], 0.4f); @@ -677,7 +634,7 @@ void LLFace::renderOneWireframe(const LLColor4 &color, F32 fogCfx, bool wirefram { LLGLDisable depth(wireframe_selection ? 0 : GL_BLEND); - LLGLEnable stencil(wireframe_selection ? 0 : GL_STENCIL_TEST); + //LLGLEnable stencil(wireframe_selection ? 0 : GL_STENCIL_TEST); if (!wireframe_selection) { //modify wireframe into outline selection mode @@ -697,54 +654,8 @@ void LLFace::renderOneWireframe(const LLColor4 &color, F32 fogCfx, bool wirefram } } -/* removed in lieu of raycast uv detection -void LLFace::renderSelectedUV() -{ - LLViewerTexture* red_blue_imagep = LLViewerTextureManager::getFetchedTextureFromFile("uv_test1.j2c", TRUE, LLGLTexture::BOOST_UI); - LLViewerTexture* green_imagep = LLViewerTextureManager::getFetchedTextureFromFile("uv_test2.tga", TRUE, LLGLTexture::BOOST_UI); - - LLGLSUVSelect object_select; - - // use red/blue gradient to get coarse UV coordinates - renderSelected(red_blue_imagep, LLColor4::white); - - static F32 bias = 0.f; - static F32 factor = -10.f; - glPolygonOffset(factor, bias); - - // add green dither pattern on top of red/blue gradient - gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_ONE); - gGL.matrixMode(LLRender::MM_TEXTURE); - gGL.pushMatrix(); - // make green pattern repeat once per texel in red/blue texture - gGL.scalef(256.f, 256.f, 1.f); - gGL.matrixMode(LLRender::MM_MODELVIEW); - - renderSelected(green_imagep, LLColor4::white); - - gGL.matrixMode(LLRender::MM_TEXTURE); - gGL.popMatrix(); - gGL.matrixMode(LLRender::MM_MODELVIEW); - gGL.blendFunc(LLRender::BF_SOURCE_ALPHA, LLRender::BF_ONE_MINUS_SOURCE_ALPHA); -} -*/ - void LLFace::setDrawInfo(LLDrawInfo* draw_info) { - if (draw_info) - { - if (draw_info->mFace) - { - draw_info->mFace->setDrawInfo(NULL); - } - draw_info->mFace = this; - } - - if (mDrawInfo) - { - mDrawInfo->mFace = NULL; - } - mDrawInfo = draw_info; } @@ -1180,21 +1091,27 @@ void LLFace::updateRebuildFlags() bool LLFace::canRenderAsMask() { - if (LLPipeline::sNoAlpha) + const LLTextureEntry* te = getTextureEntry(); + if( !te || !getViewerObject() || !getTexture() ) { - return true; + return false; } + if (te->getGLTFRenderMaterial()) + { + return false; + } + + if (LLPipeline::sNoAlpha) + { + return true; + } + if (isState(LLFace::RIGGED)) { // never auto alpha-mask rigged faces return false; } - const LLTextureEntry* te = getTextureEntry(); - if( !te || !getViewerObject() || !getTexture() ) - { - return false; - } LLMaterial* mat = te->getMaterialParams(); if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) @@ -1206,75 +1123,19 @@ bool LLFace::canRenderAsMask() (te->getGlow() == 0.f) && // glowing masks are hard to implement - don't mask getTexture()->getIsAlphaMask()) // texture actually qualifies for masking (lazily recalculated but expensive) { - if (LLPipeline::sRenderDeferred) - { - if (getViewerObject()->isHUDAttachment() || te->getFullbright()) - { //hud attachments and fullbright objects are NOT subject to the deferred rendering pipe - return LLPipeline::sAutoMaskAlphaNonDeferred; - } - else - { - return LLPipeline::sAutoMaskAlphaDeferred; - } + if (getViewerObject()->isHUDAttachment() || te->getFullbright()) + { //hud attachments and fullbright objects are NOT subject to the deferred rendering pipe + return LLPipeline::sAutoMaskAlphaNonDeferred; } else { - return LLPipeline::sAutoMaskAlphaNonDeferred; + return LLPipeline::sAutoMaskAlphaDeferred; } } return false; } - -//static -void LLFace::cacheFaceInVRAM(const LLVolumeFace& vf) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE; - U32 mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | - LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_NORMAL; - - if (vf.mWeights) - { - mask |= LLVertexBuffer::MAP_WEIGHT4; - } - - LLVertexBuffer* buff = new LLVertexBuffer(mask, GL_STATIC_DRAW); - vf.mVertexBuffer = buff; - - buff->allocateBuffer(vf.mNumVertices, 0, true); - - LLStrider<LLVector4a> f_vert; - LLStrider<LLVector4a> f_tangent; - LLStrider<LLVector3> f_norm; - LLStrider<LLVector2> f_tc; - - buff->getTangentStrider(f_tangent); - buff->getVertexStrider(f_vert); - buff->getNormalStrider(f_norm); - buff->getTexCoord0Strider(f_tc); - - for (U32 i = 0; i < vf.mNumVertices; ++i) - { - *f_vert++ = vf.mPositions[i]; - *f_tangent++ = vf.mTangents[i]; - *f_tc++ = vf.mTexCoords[i]; - (*f_norm++).set(vf.mNormals[i].getF32ptr()); - } - - if (vf.mWeights) - { - LLStrider<LLVector4> f_wght; - buff->getWeight4Strider(f_wght); - for (U32 i = 0; i < vf.mNumVertices; ++i) - { - (*f_wght++).set(vf.mWeights[i].getF32ptr()); - } - } - - buff->flush(); -} - //helper function for pushing primitives for transform shaders and cleaning up //uninitialized data on the tail, plus tracking number of expected primitives void push_for_transform(LLVertexBuffer* buff, U32 source_count, U32 dest_count) @@ -1293,22 +1154,32 @@ void push_for_transform(LLVertexBuffer* buff, U32 source_count, U32 dest_count) } BOOL LLFace::getGeometryVolume(const LLVolume& volume, - const S32 &f, - const LLMatrix4& mat_vert_in, const LLMatrix3& mat_norm_in, - const U16 &index_offset, - bool force_rebuild) + S32 face_index, + const LLMatrix4& mat_vert_in, + const LLMatrix3& mat_norm_in, + U16 index_offset, + bool force_rebuild, + bool no_debug_assert) { LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE; llassert(verify()); - if (volume.getNumVolumeFaces() <= f) { - LL_WARNS() << "Attempt get volume face out of range! Total Faces: " << volume.getNumVolumeFaces() << " Attempt get access to: " << f << LL_ENDL; - return FALSE; - } + if (face_index < 0 || face_index >= volume.getNumVolumeFaces()) + { + if (gDebugGL) + { + LL_WARNS() << "Face index is out of bounds!" << LL_ENDL; + LL_WARNS() << "Attempt get volume face out of range!" + " Total Faces: " << volume.getNumVolumeFaces() << + " Attempt get access to: " << face_index << LL_ENDL; + llassert(no_debug_assert); + } + return FALSE; + } bool rigged = isState(RIGGED); - const LLVolumeFace &vf = volume.getVolumeFace(f); + const LLVolumeFace &vf = volume.getVolumeFace(face_index); S32 num_vertices = (S32)vf.mNumVertices; S32 num_indices = (S32) vf.mNumIndices; @@ -1317,23 +1188,20 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, updateRebuildFlags(); } - - //don't use map range (generates many redundant unmap calls) - bool map_range = false; //gGLManager.mHasMapBufferRange || gGLManager.mHasFlushBufferRange; - if (mVertexBuffer.notNull()) { if (num_indices + (S32) mIndicesIndex > mVertexBuffer->getNumIndices()) { if (gDebugGL) { - LL_WARNS() << "Index buffer overflow!" << LL_ENDL; + LL_WARNS() << "Index buffer overflow!" << LL_ENDL; LL_WARNS() << "Indices Count: " << mIndicesCount << " VF Num Indices: " << num_indices << " Indices Index: " << mIndicesIndex << " VB Num Indices: " << mVertexBuffer->getNumIndices() << LL_ENDL; - LL_WARNS() << " Face Index: " << f + LL_WARNS() << " Face Index: " << face_index << " Pool Type: " << mPoolType << LL_ENDL; + llassert(no_debug_assert); } return FALSE; } @@ -1343,6 +1211,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, if (gDebugGL) { LL_WARNS() << "Vertex buffer overflow!" << LL_ENDL; + llassert(no_debug_assert); } return FALSE; } @@ -1379,7 +1248,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, bool rebuild_tangent = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TANGENT); bool rebuild_weights = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_WEIGHT4); - const LLTextureEntry *tep = mVObjp->getTE(f); + const LLTextureEntry *tep = mVObjp->getTE(face_index); const U8 bump_code = tep ? tep->getBumpmap() : 0; BOOL is_static = mDrawablep->isStatic(); @@ -1398,28 +1267,24 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, LLColor4U color = tep->getColor(); + if (tep->getGLTFRenderMaterial()) + { + color = tep->getGLTFRenderMaterial()->mBaseColor; + } + if (rebuild_color) { //decide if shiny goes in alpha channel of color if (tep && - getPoolType() != LLDrawPool::POOL_ALPHA) // <--- alpha channel MUST contain transparency, not shiny + !isInAlphaPool()) // <--- alpha channel MUST contain transparency, not shiny { LLMaterial* mat = tep->getMaterialParams().get(); bool shiny_in_alpha = false; - if (LLPipeline::sRenderDeferred) - { //store shiny in alpha if we don't have a specular map - if (!mat || mat->getSpecularID().isNull()) - { - shiny_in_alpha = true; - } - } - else + //store shiny in alpha if we don't have a specular map + if (!mat || mat->getSpecularID().isNull()) { - if (!mat || mat->getDiffuseAlphaMode() != LLMaterial::DIFFUSE_ALPHA_MODE_MASK) - { - shiny_in_alpha = true; - } + shiny_in_alpha = true; } if (shiny_in_alpha) @@ -1442,7 +1307,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, if (full_rebuild) { LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - indices"); - mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount, map_range); + mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount); volatile __m128i* dst = (__m128i*) indicesp.get(); __m128i* src = (__m128i*) vf.mIndices; @@ -1465,46 +1330,77 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, *idx++ = vf.mIndices[i]+index_offset; } } - - if (map_range) - { - mVertexBuffer->flush(); - } } + + LLMaterial* mat = tep->getMaterialParams().get(); + LLGLTFMaterial* gltf_mat = tep->getGLTFRenderMaterial(); + F32 r = 0, os = 0, ot = 0, ms = 0, mt = 0, cos_ang = 0, sin_ang = 0; - bool do_xform = false; - if (rebuild_tcoord) - { - if (tep) - { - r = tep->getRotation(); - os = tep->mOffsetS; - ot = tep->mOffsetT; - ms = tep->mScaleS; - mt = tep->mScaleT; - cos_ang = cos(r); - sin_ang = sin(r); - - if (cos_ang != 1.f || - sin_ang != 0.f || - os != 0.f || - ot != 0.f || - ms != 1.f || - mt != 1.f) - { - do_xform = true; - } - else - { - do_xform = false; - } - } - else - { - do_xform = false; - } - } + + constexpr S32 XFORM_NONE = 0; + constexpr S32 XFORM_BLINNPHONG_COLOR = 1; + constexpr S32 XFORM_BLINNPHONG_NORMAL = 1 << 1; + constexpr S32 XFORM_BLINNPHONG_SPECULAR = 1 << 2; + + S32 xforms = XFORM_NONE; + // For GLTF, transforms will be applied later + if (rebuild_tcoord && tep && !gltf_mat) + { + r = tep->getRotation(); + os = tep->mOffsetS; + ot = tep->mOffsetT; + ms = tep->mScaleS; + mt = tep->mScaleT; + cos_ang = cos(r); + sin_ang = sin(r); + + if (cos_ang != 1.f || + sin_ang != 0.f || + os != 0.f || + ot != 0.f || + ms != 1.f || + mt != 1.f) + { + xforms |= XFORM_BLINNPHONG_COLOR; + } + if (mat) + { + F32 r_norm = 0, os_norm = 0, ot_norm = 0, ms_norm = 0, mt_norm = 0, cos_ang_norm = 0, sin_ang_norm = 0; + mat->getNormalOffset(os_norm, ot_norm); + mat->getNormalRepeat(ms_norm, mt_norm); + r_norm = mat->getNormalRotation(); + cos_ang_norm = cos(r_norm); + sin_ang_norm = sin(r_norm); + if (cos_ang_norm != 1.f || + sin_ang_norm != 0.f || + os_norm != 0.f || + ot_norm != 0.f || + ms_norm != 1.f || + mt_norm != 1.f) + { + xforms |= XFORM_BLINNPHONG_NORMAL; + } + } + if (mat) + { + F32 r_spec = 0, os_spec = 0, ot_spec = 0, ms_spec = 0, mt_spec = 0, cos_ang_spec = 0, sin_ang_spec = 0; + mat->getSpecularOffset(os_spec, ot_spec); + mat->getSpecularRepeat(ms_spec, mt_spec); + r_spec = mat->getSpecularRotation(); + cos_ang_spec = cos(r_spec); + sin_ang_spec = sin(r_spec); + if (cos_ang_spec != 1.f || + sin_ang_spec != 0.f || + os_spec != 0.f || + ot_spec != 0.f || + ms_spec != 1.f || + mt_spec != 1.f) + { + xforms |= XFORM_BLINNPHONG_SPECULAR; + } + } + } const LLMeshSkinInfo* skin = nullptr; LLMatrix4a mat_vert; @@ -1545,155 +1441,6 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, } } - static LLCachedControl<bool> use_transform_feedback(gSavedSettings, "RenderUseTransformFeedback", false); - -#ifdef GL_TRANSFORM_FEEDBACK_BUFFER - if (use_transform_feedback && - mVertexBuffer->getUsage() == GL_DYNAMIC_COPY && - gTransformPositionProgram.mProgramObject && //transform shaders are loaded - mVertexBuffer->useVBOs() && //target buffer is in VRAM - !rebuild_weights && //TODO: add support for weights - !volume.isUnique()) //source volume is NOT flexi - { //use transform feedback to pack vertex buffer - - LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - transform feedback"); - LLGLEnable discard(GL_RASTERIZER_DISCARD); - LLVertexBuffer* buff = (LLVertexBuffer*) vf.mVertexBuffer.get(); - - if (vf.mVertexBuffer.isNull() || buff->getNumVerts() != vf.mNumVertices) - { - mVObjp->getVolume()->genTangents(f); - LLFace::cacheFaceInVRAM(vf); - buff = (LLVertexBuffer*) vf.mVertexBuffer.get(); - } - - LLGLSLShader* cur_shader = LLGLSLShader::sCurBoundShaderPtr; - - gGL.pushMatrix(); - gGL.loadMatrix((GLfloat*) mat_vert_in.mMatrix); - - if (rebuild_pos) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tf position"); - gTransformPositionProgram.bind(); - - mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_VERTEX, mGeomIndex, mGeomCount); - - U8 index = mTextureIndex < FACE_DO_NOT_BATCH_TEXTURES ? mTextureIndex : 0; - - S32 val = 0; - U8* vp = (U8*) &val; - vp[0] = index; - vp[1] = 0; - vp[2] = 0; - vp[3] = 0; - - gTransformPositionProgram.uniform1i(sTextureIndexIn, val); - glBeginTransformFeedback(GL_POINTS); - buff->setBuffer(LLVertexBuffer::MAP_VERTEX); - - push_for_transform(buff, vf.mNumVertices, mGeomCount); - - glEndTransformFeedback(); - } - - if (rebuild_color) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tf color"); - gTransformColorProgram.bind(); - - mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_COLOR, mGeomIndex, mGeomCount); - - S32 val = *((S32*) color.mV); - - gTransformColorProgram.uniform1i(sColorIn, val); - glBeginTransformFeedback(GL_POINTS); - buff->setBuffer(LLVertexBuffer::MAP_VERTEX); - push_for_transform(buff, vf.mNumVertices, mGeomCount); - glEndTransformFeedback(); - } - - if (rebuild_emissive) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tf emissive"); - gTransformColorProgram.bind(); - - mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_EMISSIVE, mGeomIndex, mGeomCount); - - U8 glow = (U8) llclamp((S32) (getTextureEntry()->getGlow()*255), 0, 255); - - S32 glow32 = glow | - (glow << 8) | - (glow << 16) | - (glow << 24); - - gTransformColorProgram.uniform1i(sColorIn, glow32); - glBeginTransformFeedback(GL_POINTS); - buff->setBuffer(LLVertexBuffer::MAP_VERTEX); - push_for_transform(buff, vf.mNumVertices, mGeomCount); - glEndTransformFeedback(); - } - - if (rebuild_normal) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tf normal"); - gTransformNormalProgram.bind(); - - mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_NORMAL, mGeomIndex, mGeomCount); - - glBeginTransformFeedback(GL_POINTS); - buff->setBuffer(LLVertexBuffer::MAP_NORMAL); - push_for_transform(buff, vf.mNumVertices, mGeomCount); - glEndTransformFeedback(); - } - - if (rebuild_tangent) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tf tangent"); - gTransformTangentProgram.bind(); - - mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_TANGENT, mGeomIndex, mGeomCount); - - glBeginTransformFeedback(GL_POINTS); - buff->setBuffer(LLVertexBuffer::MAP_TANGENT); - push_for_transform(buff, vf.mNumVertices, mGeomCount); - glEndTransformFeedback(); - } - - if (rebuild_tcoord) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tf tcoord"); - gTransformTexCoordProgram.bind(); - - mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_TEXCOORD0, mGeomIndex, mGeomCount); - - glBeginTransformFeedback(GL_POINTS); - buff->setBuffer(LLVertexBuffer::MAP_TEXCOORD0); - push_for_transform(buff, vf.mNumVertices, mGeomCount); - glEndTransformFeedback(); - - bool do_bump = bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1); - - if (do_bump) - { - mVertexBuffer->bindForFeedback(0, LLVertexBuffer::TYPE_TEXCOORD1, mGeomIndex, mGeomCount); - glBeginTransformFeedback(GL_POINTS); - buff->setBuffer(LLVertexBuffer::MAP_TEXCOORD0); - push_for_transform(buff, vf.mNumVertices, mGeomCount); - glEndTransformFeedback(); - } - } - - glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0); - gGL.popMatrix(); - - if (cur_shader) - { - cur_shader->bind(); - } - } - else -#endif { //if it's not fullbright and has no normals, bake sunlight based on face normal //bool bake_sunlight = !getTextureEntry()->getFullbright() && @@ -1716,7 +1463,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, if (bump_code) { - mVObjp->getVolume()->genTangents(f); + mVObjp->getVolume()->genTangents(face_index); F32 offset_multiple; switch( bump_code ) { @@ -1765,7 +1512,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, U8 texgen = getTextureEntry()->getTexGen(); if (rebuild_tcoord && texgen != LLTextureEntry::TEX_GEN_DEFAULT) { //planar texgen needs binormals - mVObjp->getVolume()->genTangents(f); + mVObjp->getVolume()->genTangents(face_index); } U8 tex_mode = 0; @@ -1794,7 +1541,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, sin_ang = 0.f; ms = mt = 1.f; - do_xform = false; + xforms = XFORM_NONE; } if (getVirtualSize() >= MIN_TEX_ANIM_SIZE) // || isState(LLFace::RIGGED)) @@ -1806,17 +1553,16 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, LLVector4a scalea; scalea.load3(scale.mV); - LLMaterial* mat = tep->getMaterialParams().get(); - bool do_bump = bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1); - if (mat && !do_bump) + if ((mat || gltf_mat) && !do_bump) { do_bump = mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1) || mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2); } - bool do_tex_mat = tex_mode && mTextureMatrix; + // For GLTF materials: Transforms will be applied later + bool do_tex_mat = tex_mode && mTextureMatrix && !gltf_mat; if (!do_bump) { //not bump mapped, might be able to do a cheap update @@ -1827,7 +1573,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - texgen"); if (!do_tex_mat) { - if (!do_xform) + if (xforms == XFORM_NONE) { LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("ggv - texgen 1"); S32 tc_size = (num_vertices*2*sizeof(F32)+0xF) & ~0xF; @@ -1906,7 +1652,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, *tex_coords0++ = tc; } } - else + else if (xforms != XFORM_NONE) { for (S32 i = 0; i < num_vertices; i++) { @@ -1922,11 +1668,20 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, *tex_coords0++ = tc; } } - } + else + { + for (S32 i = 0; i < num_vertices; i++) + { + LLVector2 tc(vf.mTexCoords[i]); + LLVector4a& norm = vf.mNormals[i]; + LLVector4a& center = *(vf.mCenter); + LLVector4a vec = vf.mPositions[i]; + vec.mul(scalea); + planarProjection(tc, norm, center, vec); - if (map_range) - { - mVertexBuffer->flush(); + *tex_coords0++ = tc; + } + } } } else @@ -1944,15 +1699,18 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, for (U32 ch = 0; ch < 3; ++ch) { + S32 xform_channel = XFORM_NONE; switch (ch) { case 0: - mVertexBuffer->getTexCoord0Strider(dst, mGeomIndex, mGeomCount, map_range); + xform_channel = XFORM_BLINNPHONG_COLOR; + mVertexBuffer->getTexCoord0Strider(dst, mGeomIndex, mGeomCount); break; case 1: + xform_channel = XFORM_BLINNPHONG_NORMAL; if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1)) { - mVertexBuffer->getTexCoord1Strider(dst, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getTexCoord1Strider(dst, mGeomIndex, mGeomCount); if (mat && !tex_anim) { r = mat->getNormalRotation(); @@ -1970,9 +1728,10 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, } break; case 2: + xform_channel = XFORM_BLINNPHONG_SPECULAR; if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2)) { - mVertexBuffer->getTexCoord2Strider(dst, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getTexCoord2Strider(dst, mGeomIndex, mGeomCount); if (mat && !tex_anim) { r = mat->getSpecularRotation(); @@ -1989,57 +1748,55 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, } break; } + const bool do_xform = (xforms & xform_channel) != XFORM_NONE; - for (S32 i = 0; i < num_vertices; i++) - { - LLVector2 tc(vf.mTexCoords[i]); - - LLVector4a& norm = vf.mNormals[i]; - - LLVector4a& center = *(vf.mCenter); - - if (texgen != LLTextureEntry::TEX_GEN_DEFAULT) - { - LLVector4a vec = vf.mPositions[i]; - - vec.mul(scalea); - - if (texgen == LLTextureEntry::TEX_GEN_PLANAR) - { - planarProjection(tc, norm, center, vec); - } - } - - if (tex_mode && mTextureMatrix) - { - LLVector3 tmp(tc.mV[0], tc.mV[1], 0.f); - tmp = tmp * *mTextureMatrix; - tc.mV[0] = tmp.mV[0]; - tc.mV[1] = tmp.mV[1]; - } - else - { - xform(tc, cos_ang, sin_ang, os, ot, ms, mt); - } - - *dst++ = tc; - if (do_bump) - { - bump_tc.push_back(tc); - } - } + for (S32 i = 0; i < num_vertices; i++) + { + LLVector2 tc(vf.mTexCoords[i]); + + LLVector4a& norm = vf.mNormals[i]; + + LLVector4a& center = *(vf.mCenter); + + if (texgen != LLTextureEntry::TEX_GEN_DEFAULT) + { + LLVector4a vec = vf.mPositions[i]; + + vec.mul(scalea); + + if (texgen == LLTextureEntry::TEX_GEN_PLANAR) + { + planarProjection(tc, norm, center, vec); + } + } + + if (tex_mode && mTextureMatrix) + { + LLVector3 tmp(tc.mV[0], tc.mV[1], 0.f); + tmp = tmp * *mTextureMatrix; + tc.mV[0] = tmp.mV[0]; + tc.mV[1] = tmp.mV[1]; + } + else if (do_xform) + { + xform(tc, cos_ang, sin_ang, os, ot, ms, mt); + } + + *dst++ = tc; + if (do_bump) + { + bump_tc.push_back(tc); + } + } } - if (map_range) + if ((!mat && !gltf_mat) && do_bump) { - mVertexBuffer->flush(); - } - - if (!mat && do_bump) - { - mVertexBuffer->getTexCoord1Strider(tex_coords1, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getTexCoord1Strider(tex_coords1, mGeomIndex, mGeomCount); + mVObjp->getVolume()->genTangents(face_index); + for (S32 i = 0; i < num_vertices; i++) { LLVector4a tangent = vf.mTangents[i]; @@ -2071,11 +1828,6 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, *tex_coords1++ = tc; } - - if (map_range) - { - mVertexBuffer->flush(); - } } } } @@ -2091,7 +1843,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, llassert(num_vertices > 0); - mVertexBuffer->getVertexStrider(vert, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getVertexStrider(vert, mGeomIndex, mGeomCount); F32* dst = (F32*) vert.get(); @@ -2137,18 +1889,13 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, res0.store4a((F32*) dst); dst += 4; } - - if (map_range) - { - mVertexBuffer->flush(); - } } if (rebuild_normal) { LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - normal"); - mVertexBuffer->getNormalStrider(norm, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getNormalStrider(norm, mGeomIndex, mGeomCount); F32* normals = (F32*) norm.get(); LLVector4a* src = vf.mNormals; LLVector4a* end = src+num_vertices; @@ -2160,62 +1907,47 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, normal.store4a(normals); normals += 4; } - - if (map_range) - { - mVertexBuffer->flush(); - } } if (rebuild_tangent) { LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tangent"); - mVertexBuffer->getTangentStrider(tangent, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getTangentStrider(tangent, mGeomIndex, mGeomCount); F32* tangents = (F32*) tangent.get(); - mVObjp->getVolume()->genTangents(f); + mVObjp->getVolume()->genTangents(face_index); LLVector4Logical mask; mask.clear(); mask.setElement<3>(); LLVector4a* src = vf.mTangents; - LLVector4a* end = vf.mTangents+num_vertices; + LLVector4a* end = vf.mTangents +num_vertices; while (src < end) { LLVector4a tangent_out; mat_normal.rotate(*src, tangent_out); - tangent_out.normalize3fast(); tangent_out.setSelectWithMask(mask, *src, tangent_out); tangent_out.store4a(tangents); src++; tangents += 4; } - - if (map_range) - { - mVertexBuffer->flush(); - } } if (rebuild_weights && vf.mWeights) { LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - weight"); - mVertexBuffer->getWeight4Strider(wght, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getWeight4Strider(wght, mGeomIndex, mGeomCount); F32* weights = (F32*) wght.get(); LLVector4a::memcpyNonAliased16(weights, (F32*) vf.mWeights, num_vertices*4*sizeof(F32)); - if (map_range) - { - mVertexBuffer->flush(); - } } if (rebuild_color && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_COLOR) ) { LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - color"); - mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount); LLVector4a src; @@ -2236,18 +1968,13 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, src.store4a(dst); dst += 4; } - - if (map_range) - { - mVertexBuffer->flush(); - } } if (rebuild_emissive) { LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - emissive"); LLStrider<LLColor4U> emissive; - mVertexBuffer->getEmissiveStrider(emissive, mGeomIndex, mGeomCount, map_range); + mVertexBuffer->getEmissiveStrider(emissive, mGeomIndex, mGeomCount); U8 glow = (U8) llclamp((S32) (getTextureEntry()->getGlow()*255), 0, 255); @@ -2275,11 +2002,6 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, src.store4a(dst); dst += 4; } - - if (map_range) - { - mVertexBuffer->flush(); - } } } @@ -2302,6 +2024,15 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, return TRUE; } +void LLFace::renderIndexed() +{ + if (mVertexBuffer.notNull()) + { + mVertexBuffer->setBuffer(); + mVertexBuffer->drawRange(LLRender::TRIANGLES, getGeomIndex(), getGeomIndex() + getGeomCount()-1, getIndicesCount(), getIndicesStart()); + } +} + //check if the face has a media BOOL LLFace::hasMedia() const { @@ -2328,6 +2059,7 @@ void LLFace::resetVirtualSize() F32 LLFace::getTextureVirtualSize() { + LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; F32 radius; F32 cos_angle_to_view_dir; BOOL in_frustum = calcPixelArea(cos_angle_to_view_dir, radius); @@ -2632,97 +2364,12 @@ void LLFace::setViewerObject(LLViewerObject* objp) mVObjp = objp; } -const LLColor4& LLFace::getRenderColor() const -{ - if (isState(USE_FACE_COLOR)) - { - return mFaceColor; // Face Color - } - else - { - const LLTextureEntry* tep = getTextureEntry(); - return (tep ? tep->getColor() : LLColor4::white); - } -} - -void LLFace::renderSetColor() const -{ - if (!LLFacePool::LLOverrideFaceColor::sOverrideFaceColor) - { - const LLColor4* color = &(getRenderColor()); - - gGL.diffuseColor4fv(color->mV); - } -} - -S32 LLFace::pushVertices(const U16* index_array) const -{ - if (mIndicesCount) - { - U32 render_type = LLRender::TRIANGLES; - if (mDrawInfo) - { - render_type = mDrawInfo->mDrawMode; - } - mVertexBuffer->drawRange(render_type, mGeomIndex, mGeomIndex+mGeomCount-1, mIndicesCount, mIndicesIndex); - gPipeline.addTrianglesDrawn(mIndicesCount, render_type); - } - - return mIndicesCount; -} const LLMatrix4& LLFace::getRenderMatrix() const { return mDrawablep->getRenderMatrix(); } -S32 LLFace::renderElements(const U16 *index_array) const -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE - - S32 ret = 0; - - if (isState(GLOBAL)) - { - ret = pushVertices(index_array); - } - else - { - gGL.pushMatrix(); - gGL.multMatrix((float*)getRenderMatrix().mMatrix); - ret = pushVertices(index_array); - gGL.popMatrix(); - } - - return ret; -} - -S32 LLFace::renderIndexed() -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE - - if(mDrawablep == NULL || mDrawPoolp == NULL) - { - return 0; - } - - return renderIndexed(mDrawPoolp->getVertexDataMask()); -} - -S32 LLFace::renderIndexed(U32 mask) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE - - if (mVertexBuffer.isNull()) - { - return 0; - } - - mVertexBuffer->setBuffer(mask); - U16* index_array = (U16*) mVertexBuffer->getIndicesPointer(); - return renderElements(index_array); -} - //============================================================================ // From llface.inl @@ -2806,3 +2453,10 @@ U64 LLFace::getSkinHash() { return mSkinInfo ? mSkinInfo->mHash : 0; } + +bool LLFace::isInAlphaPool() const +{ + return getPoolType() == LLDrawPool::POOL_ALPHA || + getPoolType() == LLDrawPool::POOL_ALPHA_PRE_WATER || + getPoolType() == LLDrawPool::POOL_ALPHA_POST_WATER; +} |