diff options
Diffstat (limited to 'indra/llprimitive')
-rw-r--r-- | indra/llprimitive/CMakeLists.txt | 2 | ||||
-rw-r--r-- | indra/llprimitive/llmaterialid.cpp | 112 | ||||
-rw-r--r-- | indra/llprimitive/llmaterialid.h | 62 | ||||
-rwxr-xr-x | indra/llprimitive/llprimitive.cpp | 54 | ||||
-rw-r--r-- | indra/llprimitive/llprimitive.h | 2 | ||||
-rw-r--r-- | indra/llprimitive/llprimtexturelist.cpp | 10 | ||||
-rw-r--r-- | indra/llprimitive/llprimtexturelist.h | 2 | ||||
-rw-r--r-- | indra/llprimitive/lltextureentry.cpp | 17 | ||||
-rw-r--r-- | indra/llprimitive/lltextureentry.h | 4 |
9 files changed, 244 insertions, 21 deletions
diff --git a/indra/llprimitive/CMakeLists.txt b/indra/llprimitive/CMakeLists.txt index e4d9de7eb6..82d0f892f2 100644 --- a/indra/llprimitive/CMakeLists.txt +++ b/indra/llprimitive/CMakeLists.txt @@ -20,6 +20,7 @@ include_directories( ) set(llprimitive_SOURCE_FILES + llmaterialid.cpp llmaterialtable.cpp llmediaentry.cpp llmodel.cpp @@ -37,6 +38,7 @@ set(llprimitive_HEADER_FILES CMakeLists.txt legacy_object_types.h + llmaterialid.h llmaterialtable.h llmediaentry.h llmodel.h diff --git a/indra/llprimitive/llmaterialid.cpp b/indra/llprimitive/llmaterialid.cpp new file mode 100644 index 0000000000..4355a8ea3f --- /dev/null +++ b/indra/llprimitive/llmaterialid.cpp @@ -0,0 +1,112 @@ +/** +* @file llmaterialid.cpp +* @brief Implementation of llmaterialid +* @author Stinson@lindenlab.com +* +* $LicenseInfo:firstyear=2012&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2012, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ + +#include "linden_common.h" + +#include "llmaterialid.h" + +const LLMaterialID LLMaterialID::null; + +LLMaterialID::LLMaterialID() +{ + clear(); +} + +LLMaterialID::LLMaterialID(const LLSD& pMaterialID) +{ + llassert(pMaterialID.isBinary()); + parseFromBinary(pMaterialID.asBinary()); +} + +LLMaterialID::LLMaterialID(const LLSD::Binary& pMaterialID) +{ + parseFromBinary(pMaterialID); +} + +LLMaterialID::LLMaterialID(const LLMaterialID& pOtherMaterialID) +{ + copyFromOtherMaterialID(pOtherMaterialID); +} + +LLMaterialID::~LLMaterialID() +{ +} + +bool LLMaterialID::operator == (const LLMaterialID& pOtherMaterialID) const +{ + return (compareToOtherMaterialID(pOtherMaterialID) == 0); +} + +bool LLMaterialID::operator != (const LLMaterialID& pOtherMaterialID) const +{ + return (compareToOtherMaterialID(pOtherMaterialID) != 0); +} + +LLMaterialID& LLMaterialID::operator = (const LLMaterialID& pOtherMaterialID) +{ + copyFromOtherMaterialID(pOtherMaterialID); + return (*this); +} + +bool LLMaterialID::isNull() const +{ + return (compareToOtherMaterialID(LLMaterialID::null) == 0); +} + +const U8* LLMaterialID::get() const +{ + return mID; +} + +void LLMaterialID::set(const void* pMemory) +{ + llassert(pMemory != NULL); + + // assumes that the required size of memory is available + memcpy(mID, pMemory, MATERIAL_ID_SIZE * sizeof(U8)); +} + +void LLMaterialID::clear() +{ + memset(mID, 0, MATERIAL_ID_SIZE * sizeof(U8)); +} + +void LLMaterialID::parseFromBinary (const LLSD::Binary& pMaterialID) +{ + llassert(pMaterialID.size() == (MATERIAL_ID_SIZE * sizeof(U8))); + memcpy(mID, &pMaterialID[0], MATERIAL_ID_SIZE * sizeof(U8)); +} + +void LLMaterialID::copyFromOtherMaterialID(const LLMaterialID& pOtherMaterialID) +{ + memcpy(mID, pOtherMaterialID.mID, MATERIAL_ID_SIZE * sizeof(U8)); +} + +int LLMaterialID::compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const +{ + return memcmp(mID, pOtherMaterialID.mID, MATERIAL_ID_SIZE * sizeof(U8)); +} diff --git a/indra/llprimitive/llmaterialid.h b/indra/llprimitive/llmaterialid.h new file mode 100644 index 0000000000..4551550db5 --- /dev/null +++ b/indra/llprimitive/llmaterialid.h @@ -0,0 +1,62 @@ +/** +* @file llmaterialid.h +* @brief Header file for llmaterialid +* @author Stinson@lindenlab.com +* +* $LicenseInfo:firstyear=2012&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2012, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ +#ifndef LL_LLMATERIALID_H +#define LL_LLMATERIALID_H + +#define MATERIAL_ID_SIZE 16 + +class LLMaterialID +{ +public: + LLMaterialID(); + LLMaterialID(const LLSD& pMaterialID); + LLMaterialID(const LLSD::Binary& pMaterialID); + LLMaterialID(const LLMaterialID& pOtherMaterialID); + ~LLMaterialID(); + + bool operator == (const LLMaterialID& pOtherMaterialID) const; + bool operator != (const LLMaterialID& pOtherMaterialID) const; + LLMaterialID& operator = (const LLMaterialID& pOtherMaterialID); + + bool isNull() const; + + const U8* get() const; + void set(const void* pMemory); + void clear(); + + static const LLMaterialID null; + +private: + void parseFromBinary(const LLSD::Binary& pMaterialID); + void copyFromOtherMaterialID(const LLMaterialID& pOtherMaterialID); + int compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const; + + U8 mID[MATERIAL_ID_SIZE]; +} ; + +#endif // LL_LLMATERIALID_H + diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp index c6e229ae8e..86aa371368 100755 --- a/indra/llprimitive/llprimitive.cpp +++ b/indra/llprimitive/llprimitive.cpp @@ -39,6 +39,7 @@ #include "lldatapacker.h" #include "llsdutil_math.h" #include "llprimtexturelist.h" +#include "llmaterialid.h" /** * exported constants @@ -366,6 +367,11 @@ S32 LLPrimitive::setTEGlow(const U8 index, const F32 glow) return mTextureList.setGlow(index, glow); } +S32 LLPrimitive::setTEMaterialID(const U8 index, const LLMaterialID& pMaterialID) +{ + return mTextureList.setMaterialID(index, pMaterialID); +} + LLPCode LLPrimitive::legacyToPCode(const U8 legacy) { @@ -1091,6 +1097,7 @@ BOOL LLPrimitive::packTEMessage(LLMessageSystem *mesgsys) const U8 bump[MAX_TES]; U8 media_flags[MAX_TES]; U8 glow[MAX_TES]; + U8 material_data[MAX_TES*16]; const U32 MAX_TE_BUFFER = 4096; U8 packed_buffer[MAX_TE_BUFFER]; @@ -1128,6 +1135,9 @@ BOOL LLPrimitive::packTEMessage(LLMessageSystem *mesgsys) const bump[face_index] = te->getBumpShinyFullbright(); media_flags[face_index] = te->getMediaTexGen(); glow[face_index] = (U8) llround((llclamp(te->getGlow(), 0.0f, 1.0f) * (F32)0xFF)); + + // Directly sending material_ids is not safe! + memcpy(&material_data[face_index*16],getTE(face_index)->getMaterialID().get(),16); /* Flawfinder: ignore */ } cur_ptr += packTEField(cur_ptr, (U8 *)image_ids, sizeof(LLUUID),last_face_index, MVT_LLUUID); @@ -1149,6 +1159,8 @@ BOOL LLPrimitive::packTEMessage(LLMessageSystem *mesgsys) const cur_ptr += packTEField(cur_ptr, (U8 *)media_flags, 1 ,last_face_index, MVT_U8); *cur_ptr++ = 0; cur_ptr += packTEField(cur_ptr, (U8 *)glow, 1 ,last_face_index, MVT_U8); + *cur_ptr++ = 0; + cur_ptr += packTEField(cur_ptr, (U8 *)material_data, 16, last_face_index, MVT_LLUUID); } mesgsys->addBinaryDataFast(_PREHASH_TextureEntry, packed_buffer, (S32)(cur_ptr - packed_buffer)); @@ -1170,6 +1182,7 @@ BOOL LLPrimitive::packTEMessage(LLDataPacker &dp) const U8 bump[MAX_TES]; U8 media_flags[MAX_TES]; U8 glow[MAX_TES]; + U8 material_data[MAX_TES*16]; const U32 MAX_TE_BUFFER = 4096; U8 packed_buffer[MAX_TE_BUFFER]; @@ -1207,6 +1220,9 @@ BOOL LLPrimitive::packTEMessage(LLDataPacker &dp) const bump[face_index] = te->getBumpShinyFullbright(); media_flags[face_index] = te->getMediaTexGen(); glow[face_index] = (U8) llround((llclamp(te->getGlow(), 0.0f, 1.0f) * (F32)0xFF)); + + // Directly sending material_ids is not safe! + memcpy(&material_data[face_index*16],getTE(face_index)->getMaterialID().get(),16); /* Flawfinder: ignore */ } cur_ptr += packTEField(cur_ptr, (U8 *)image_ids, sizeof(LLUUID),last_face_index, MVT_LLUUID); @@ -1228,6 +1244,8 @@ BOOL LLPrimitive::packTEMessage(LLDataPacker &dp) const cur_ptr += packTEField(cur_ptr, (U8 *)media_flags, 1 ,last_face_index, MVT_U8); *cur_ptr++ = 0; cur_ptr += packTEField(cur_ptr, (U8 *)glow, 1 ,last_face_index, MVT_U8); + *cur_ptr++ = 0; + cur_ptr += packTEField(cur_ptr, (U8 *)material_data, 16, last_face_index, MVT_LLUUID); } dp.packBinaryData(packed_buffer, (S32)(cur_ptr - packed_buffer), "TextureEntry"); @@ -1246,6 +1264,7 @@ S32 LLPrimitive::unpackTEMessage(LLMessageSystem* mesgsys, char const* block_nam const U32 MAX_TES = 32; // Avoid construction of 32 UUIDs per call. JC + static LLMaterialID material_ids[MAX_TES]; U8 image_data[MAX_TES*16]; U8 colors[MAX_TES*4]; @@ -1257,6 +1276,7 @@ S32 LLPrimitive::unpackTEMessage(LLMessageSystem* mesgsys, char const* block_nam U8 bump[MAX_TES]; U8 media_flags[MAX_TES]; U8 glow[MAX_TES]; + U8 material_data[MAX_TES*16]; const U32 MAX_TE_BUFFER = 4096; U8 packed_buffer[MAX_TE_BUFFER]; @@ -1309,6 +1329,13 @@ S32 LLPrimitive::unpackTEMessage(LLMessageSystem* mesgsys, char const* block_nam cur_ptr += unpackTEField(cur_ptr, packed_buffer+size, (U8 *)media_flags, 1, face_count, MVT_U8); cur_ptr++; cur_ptr += unpackTEField(cur_ptr, packed_buffer+size, (U8 *)glow, 1, face_count, MVT_U8); + cur_ptr++; + cur_ptr += unpackTEField(cur_ptr, packed_buffer+size, (U8 *)material_data, 16, face_count, MVT_LLUUID); + + for (U32 i = 0; i < face_count; i++) + { + material_ids[i].set(&material_data[i * 16]); + } LLColor4 color; LLColor4U coloru; @@ -1321,6 +1348,7 @@ S32 LLPrimitive::unpackTEMessage(LLMessageSystem* mesgsys, char const* block_nam retval |= setTEBumpShinyFullbright(i, bump[i]); retval |= setTEMediaTexGen(i, media_flags[i]); retval |= setTEGlow(i, (F32)glow[i] / (F32)0xFF); + retval |= setTEMaterialID(i, material_ids[i]); coloru = LLColor4U(colors + 4*i); // Note: This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f) @@ -1346,6 +1374,7 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp) // Avoid construction of 32 UUIDs per call static LLUUID image_ids[MAX_TES]; + static LLMaterialID material_ids[MAX_TES]; U8 image_data[MAX_TES*16]; U8 colors[MAX_TES*4]; @@ -1357,7 +1386,7 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp) U8 bump[MAX_TES]; U8 media_flags[MAX_TES]; U8 glow[MAX_TES]; - unsigned char material_id[MAX_TES*16]; + U8 material_data[MAX_TES*16]; const U32 MAX_TE_BUFFER = 4096; U8 packed_buffer[MAX_TE_BUFFER]; @@ -1401,30 +1430,12 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp) cur_ptr++; cur_ptr += unpackTEField(cur_ptr, packed_buffer+size, (U8 *)glow, 1, face_count, MVT_U8); cur_ptr++; - cur_ptr += unpackTEField(cur_ptr, packed_buffer+size, (U8 *)material_id, 16, face_count, MVT_LLUUID); - -#if 0 - for (U32 curFace = 0U; curFace < face_count; ++curFace) - { - std::string materialID(reinterpret_cast<char *>(&material_id[curFace * 16]), 16); - std::string materialIDString; - for (unsigned int i = 0U; i < 4U; ++i) - { - if (i != 0U) - { - materialIDString += "-"; - } - const U32 *value = reinterpret_cast<const U32*>(&materialID.c_str()[i * 4]); - materialIDString += llformat("%08x", *value); - } - - llinfos << "STINSON DEBUG: found material ID for face #" << curFace << " => " << materialIDString << llendl; - } -#endif + cur_ptr += unpackTEField(cur_ptr, packed_buffer+size, (U8 *)material_data, 16, face_count, MVT_LLUUID); for (i = 0; i < face_count; i++) { memcpy(image_ids[i].mData,&image_data[i*16],16); /* Flawfinder: ignore */ + material_ids[i].set(&material_data[i * 16]); } LLColor4 color; @@ -1438,6 +1449,7 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp) retval |= setTEBumpShinyFullbright(i, bump[i]); retval |= setTEMediaTexGen(i, media_flags[i]); retval |= setTEGlow(i, (F32)glow[i] / (F32)0xFF); + retval |= setTEMaterialID(i, material_ids[i]); coloru = LLColor4U(colors + 4*i); // Note: This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f) diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h index 8dcaa8c740..e1635740ef 100644 --- a/indra/llprimitive/llprimitive.h +++ b/indra/llprimitive/llprimitive.h @@ -42,6 +42,7 @@ class LLMessageSystem; class LLVolumeParams; class LLColor4; class LLColor3; +class LLMaterialID; class LLTextureEntry; class LLDataPacker; class LLVolumeMgr; @@ -353,6 +354,7 @@ public: virtual S32 setTEFullbright(const U8 te, const U8 fullbright); virtual S32 setTEMediaFlags(const U8 te, const U8 flags); virtual S32 setTEGlow(const U8 te, const F32 glow); + virtual S32 setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID); virtual BOOL setMaterial(const U8 material); // returns TRUE if material changed void copyTEs(const LLPrimitive *primitive); diff --git a/indra/llprimitive/llprimtexturelist.cpp b/indra/llprimitive/llprimtexturelist.cpp index 36e04df7b7..20438578b3 100644 --- a/indra/llprimitive/llprimtexturelist.cpp +++ b/indra/llprimitive/llprimtexturelist.cpp @@ -27,6 +27,7 @@ #include "linden_common.h" #include "llprimtexturelist.h" +#include "llmaterialid.h" #include "lltextureentry.h" #include "llmemtype.h" @@ -359,6 +360,15 @@ S32 LLPrimTextureList::setGlow(const U8 index, const F32 glow) return TEM_CHANGE_NONE; } +S32 LLPrimTextureList::setMaterialID(const U8 index, const LLMaterialID& pMaterialID) +{ + if (index < mEntryList.size()) + { + return mEntryList[index]->setMaterialID(pMaterialID); + } + return TEM_CHANGE_NONE; +} + S32 LLPrimTextureList::size() const { return mEntryList.size(); diff --git a/indra/llprimitive/llprimtexturelist.h b/indra/llprimitive/llprimtexturelist.h index 3cfa52f1d5..691df44c18 100644 --- a/indra/llprimitive/llprimtexturelist.h +++ b/indra/llprimitive/llprimtexturelist.h @@ -34,6 +34,7 @@ class LLTextureEntry; +class LLMaterialID; // this is a list of LLTextureEntry*'s because in practice the list's elements // are of some derived class: LLFooTextureEntry @@ -102,6 +103,7 @@ public: S32 setFullbright(const U8 index, const U8 t); S32 setMediaFlags(const U8 index, const U8 media_flags); S32 setGlow(const U8 index, const F32 glow); + S32 setMaterialID(const U8 index, const LLMaterialID& pMaterialID); S32 size() const; diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp index 34eff17519..b04fa809d2 100644 --- a/indra/llprimitive/lltextureentry.cpp +++ b/indra/llprimitive/lltextureentry.cpp @@ -29,6 +29,7 @@ #include "lluuid.h" #include "llmediaentry.h" #include "lltextureentry.h" +#include "llmaterialid.h" #include "llsdutil_math.h" #include "v4color.h" @@ -83,6 +84,8 @@ LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs) mBump = rhs.mBump; mMediaFlags = rhs.mMediaFlags; mGlow = rhs.mGlow; + mMaterialID = rhs.mMaterialID; + if (rhs.mMediaEntry != NULL) { // Make a copy mMediaEntry = new LLMediaEntry(*rhs.mMediaEntry); @@ -103,6 +106,7 @@ LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs) mBump = rhs.mBump; mMediaFlags = rhs.mMediaFlags; mGlow = rhs.mGlow; + mMaterialID = rhs.mMaterialID; if (mMediaEntry != NULL) { delete mMediaEntry; } @@ -130,6 +134,7 @@ void LLTextureEntry::init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 of mBump = bump; mMediaFlags = 0x0; mGlow = 0; + mMaterialID.clear(); setColor(LLColor4(1.f, 1.f, 1.f, 1.f)); if (mMediaEntry != NULL) { @@ -159,6 +164,7 @@ bool LLTextureEntry::operator!=(const LLTextureEntry &rhs) const if (mBump != rhs.mBump) return (true); if (mMediaFlags != rhs.mMediaFlags) return (true); if (mGlow != rhs.mGlow) return (true); + if (mMaterialID != rhs.mMaterialID) return (true); return(false); } @@ -174,6 +180,7 @@ bool LLTextureEntry::operator==(const LLTextureEntry &rhs) const if (mBump != rhs.mBump) return (false); if (mMediaFlags != rhs.mMediaFlags) return false; if (mGlow != rhs.mGlow) return false; + if (mMaterialID != rhs.mMaterialID) return (false); return(true); } @@ -523,6 +530,16 @@ S32 LLTextureEntry::setGlow(F32 glow) return TEM_CHANGE_NONE; } +S32 LLTextureEntry::setMaterialID(const LLMaterialID& pMaterialID) +{ + if (mMaterialID != pMaterialID) + { + mMaterialID = pMaterialID; + return TEM_CHANGE_TEXTURE; + } + return TEM_CHANGE_NONE; +} + void LLTextureEntry::setMediaData(const LLMediaEntry &media_entry) { mMediaFlags |= MF_HAS_MEDIA; diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h index 437b85e03f..b681ce8ca7 100644 --- a/indra/llprimitive/lltextureentry.h +++ b/indra/llprimitive/lltextureentry.h @@ -30,6 +30,7 @@ #include "lluuid.h" #include "v4color.h" #include "llsd.h" +#include "llmaterialid.h" // These bits are used while unpacking TEM messages to tell which aspects of // the texture entry changed. @@ -121,6 +122,7 @@ public: S32 setTexGen(U8 texGen); S32 setMediaTexGen(U8 media); S32 setGlow(F32 glow); + S32 setMaterialID(const LLMaterialID& pMaterialID); virtual const LLUUID &getID() const { return mID; } const LLColor4 &getColor() const { return mColor; } @@ -139,6 +141,7 @@ public: U8 getTexGen() const { return mMediaFlags & TEM_TEX_GEN_MASK; } U8 getMediaTexGen() const { return mMediaFlags; } F32 getGlow() const { return mGlow; } + const LLMaterialID& getMaterialID() const { return mMaterialID; }; // *NOTE: it is possible for hasMedia() to return true, but getMediaData() to return NULL. // CONVERSELY, it is also possible for hasMedia() to return false, but getMediaData() @@ -193,6 +196,7 @@ protected: U8 mBump; // Bump map, shiny, and fullbright U8 mMediaFlags; // replace with web page, movie, etc. F32 mGlow; + LLMaterialID mMaterialID; // Note the media data is not sent via the same message structure as the rest of the TE LLMediaEntry* mMediaEntry; // The media data for the face |