summaryrefslogtreecommitdiff
path: root/indra/llprimitive
diff options
context:
space:
mode:
authorGilbert Gonzales <gilbert@lindenlab.com>2013-06-20 16:40:43 -0700
committerGilbert Gonzales <gilbert@lindenlab.com>2013-06-20 16:40:43 -0700
commit988eae369882f57eeb4bca893dcc2c46eb773ec7 (patch)
tree8518e405fceeff8a0593329c1a0d335a30b79031 /indra/llprimitive
parent50bb863be1c0e3528fd850aac812fc6196a7c4fc (diff)
parent7da4c651911743707c0cc7cd4bebdcefb52eb379 (diff)
merge
Diffstat (limited to 'indra/llprimitive')
-rwxr-xr-xindra/llprimitive/CMakeLists.txt4
-rw-r--r--indra/llprimitive/llmaterial.cpp227
-rw-r--r--indra/llprimitive/llmaterial.h155
-rw-r--r--indra/llprimitive/llmaterialid.cpp183
-rw-r--r--indra/llprimitive/llmaterialid.h76
-rwxr-xr-xindra/llprimitive/llprimitive.cpp89
-rwxr-xr-xindra/llprimitive/llprimitive.h8
-rwxr-xr-xindra/llprimitive/llprimtexturelist.cpp19
-rwxr-xr-xindra/llprimitive/llprimtexturelist.h4
-rwxr-xr-xindra/llprimitive/lltextureentry.cpp42
-rwxr-xr-xindra/llprimitive/lltextureentry.h22
11 files changed, 820 insertions, 9 deletions
diff --git a/indra/llprimitive/CMakeLists.txt b/indra/llprimitive/CMakeLists.txt
index 1768a06a27..0dd13916bf 100755
--- a/indra/llprimitive/CMakeLists.txt
+++ b/indra/llprimitive/CMakeLists.txt
@@ -24,6 +24,8 @@ include_directories(SYSTEM
)
set(llprimitive_SOURCE_FILES
+ llmaterialid.cpp
+ llmaterial.cpp
llmaterialtable.cpp
llmediaentry.cpp
llmodel.cpp
@@ -41,6 +43,8 @@ set(llprimitive_HEADER_FILES
CMakeLists.txt
legacy_object_types.h
+ llmaterial.h
+ llmaterialid.h
llmaterialtable.h
llmediaentry.h
llmodel.h
diff --git a/indra/llprimitive/llmaterial.cpp b/indra/llprimitive/llmaterial.cpp
new file mode 100644
index 0000000000..cf4c645cfd
--- /dev/null
+++ b/indra/llprimitive/llmaterial.cpp
@@ -0,0 +1,227 @@
+/**
+ * @file llmaterial.cpp
+ * @brief Material definition
+ *
+ * $LicenseInfo:firstyear=2006&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, 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 "llmaterial.h"
+
+/**
+ * Materials cap parameters
+ */
+#define MATERIALS_CAP_NORMAL_MAP_FIELD "NormMap"
+#define MATERIALS_CAP_NORMAL_MAP_OFFSET_X_FIELD "NormOffsetX"
+#define MATERIALS_CAP_NORMAL_MAP_OFFSET_Y_FIELD "NormOffsetY"
+#define MATERIALS_CAP_NORMAL_MAP_REPEAT_X_FIELD "NormRepeatX"
+#define MATERIALS_CAP_NORMAL_MAP_REPEAT_Y_FIELD "NormRepeatY"
+#define MATERIALS_CAP_NORMAL_MAP_ROTATION_FIELD "NormRotation"
+
+#define MATERIALS_CAP_SPECULAR_MAP_FIELD "SpecMap"
+#define MATERIALS_CAP_SPECULAR_MAP_OFFSET_X_FIELD "SpecOffsetX"
+#define MATERIALS_CAP_SPECULAR_MAP_OFFSET_Y_FIELD "SpecOffsetY"
+#define MATERIALS_CAP_SPECULAR_MAP_REPEAT_X_FIELD "SpecRepeatX"
+#define MATERIALS_CAP_SPECULAR_MAP_REPEAT_Y_FIELD "SpecRepeatY"
+#define MATERIALS_CAP_SPECULAR_MAP_ROTATION_FIELD "SpecRotation"
+
+#define MATERIALS_CAP_SPECULAR_COLOR_FIELD "SpecColor"
+#define MATERIALS_CAP_SPECULAR_EXP_FIELD "SpecExp"
+#define MATERIALS_CAP_ENV_INTENSITY_FIELD "EnvIntensity"
+#define MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD "AlphaMaskCutoff"
+#define MATERIALS_CAP_DIFFUSE_ALPHA_MODE_FIELD "DiffuseAlphaMode"
+
+const LLColor4U LLMaterial::DEFAULT_SPECULAR_LIGHT_COLOR(255,255,255,255);
+
+/**
+ * Materials constants
+ */
+
+const F32 MATERIALS_MULTIPLIER = 10000.f;
+
+/**
+ * Helper functions
+ */
+
+template<typename T> T getMaterialField(const LLSD& data, const std::string& field, const LLSD::Type field_type)
+{
+ if ( (data.has(field)) && (field_type == data[field].type()) )
+ {
+ return (T)data[field];
+ }
+ llerrs << "Missing or mistyped field '" << field << "' in material definition" << llendl;
+ return (T)LLSD();
+}
+
+// GCC didn't like the generic form above for some reason
+template<> LLUUID getMaterialField(const LLSD& data, const std::string& field, const LLSD::Type field_type)
+{
+ if ( (data.has(field)) && (field_type == data[field].type()) )
+ {
+ return data[field].asUUID();
+ }
+ llerrs << "Missing or mistyped field '" << field << "' in material definition" << llendl;
+ return LLUUID::null;
+}
+
+/**
+ * LLMaterial class
+ */
+
+const LLMaterial LLMaterial::null;
+
+LLMaterial::LLMaterial()
+ : mNormalOffsetX(0.0f)
+ , mNormalOffsetY(0.0f)
+ , mNormalRepeatX(1.0f)
+ , mNormalRepeatY(1.0f)
+ , mNormalRotation(0.0f)
+ , mSpecularOffsetX(0.0f)
+ , mSpecularOffsetY(0.0f)
+ , mSpecularRepeatX(1.0f)
+ , mSpecularRepeatY(1.0f)
+ , mSpecularRotation(0.0f)
+ , mSpecularLightColor(LLMaterial::DEFAULT_SPECULAR_LIGHT_COLOR)
+ , mSpecularLightExponent(LLMaterial::DEFAULT_SPECULAR_LIGHT_EXPONENT)
+ , mEnvironmentIntensity(LLMaterial::DEFAULT_ENV_INTENSITY)
+ , mDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_BLEND)
+ , mAlphaMaskCutoff(0)
+{
+}
+
+LLMaterial::LLMaterial(const LLSD& material_data)
+{
+ fromLLSD(material_data);
+}
+
+LLSD LLMaterial::asLLSD() const
+{
+ LLSD material_data;
+
+ material_data[MATERIALS_CAP_NORMAL_MAP_FIELD] = mNormalID;
+ material_data[MATERIALS_CAP_NORMAL_MAP_OFFSET_X_FIELD] = llround(mNormalOffsetX * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_NORMAL_MAP_OFFSET_Y_FIELD] = llround(mNormalOffsetY * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_NORMAL_MAP_REPEAT_X_FIELD] = llround(mNormalRepeatX * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_NORMAL_MAP_REPEAT_Y_FIELD] = llround(mNormalRepeatY * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_NORMAL_MAP_ROTATION_FIELD] = llround(mNormalRotation * MATERIALS_MULTIPLIER);
+
+ material_data[MATERIALS_CAP_SPECULAR_MAP_FIELD] = mSpecularID;
+ material_data[MATERIALS_CAP_SPECULAR_MAP_OFFSET_X_FIELD] = llround(mSpecularOffsetX * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_SPECULAR_MAP_OFFSET_Y_FIELD] = llround(mSpecularOffsetY * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_SPECULAR_MAP_REPEAT_X_FIELD] = llround(mSpecularRepeatX * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_SPECULAR_MAP_REPEAT_Y_FIELD] = llround(mSpecularRepeatY * MATERIALS_MULTIPLIER);
+ material_data[MATERIALS_CAP_SPECULAR_MAP_ROTATION_FIELD] = llround(mSpecularRotation * MATERIALS_MULTIPLIER);
+
+ material_data[MATERIALS_CAP_SPECULAR_COLOR_FIELD] = mSpecularLightColor.getValue();
+ material_data[MATERIALS_CAP_SPECULAR_EXP_FIELD] = mSpecularLightExponent;
+ material_data[MATERIALS_CAP_ENV_INTENSITY_FIELD] = mEnvironmentIntensity;
+ material_data[MATERIALS_CAP_DIFFUSE_ALPHA_MODE_FIELD] = mDiffuseAlphaMode;
+ material_data[MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD] = mAlphaMaskCutoff;
+
+ return material_data;
+}
+
+void LLMaterial::fromLLSD(const LLSD& material_data)
+{
+ mNormalID = getMaterialField<LLSD::UUID>(material_data, MATERIALS_CAP_NORMAL_MAP_FIELD, LLSD::TypeUUID);
+ mNormalOffsetX = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_NORMAL_MAP_OFFSET_X_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mNormalOffsetY = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_NORMAL_MAP_OFFSET_Y_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mNormalRepeatX = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_NORMAL_MAP_REPEAT_X_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mNormalRepeatY = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_NORMAL_MAP_REPEAT_Y_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mNormalRotation = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_NORMAL_MAP_ROTATION_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+
+ mSpecularID = getMaterialField<LLSD::UUID>(material_data, MATERIALS_CAP_SPECULAR_MAP_FIELD, LLSD::TypeUUID);
+ mSpecularOffsetX = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_MAP_OFFSET_X_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mSpecularOffsetY = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_MAP_OFFSET_Y_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mSpecularRepeatX = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_MAP_REPEAT_X_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mSpecularRepeatY = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_MAP_REPEAT_Y_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+ mSpecularRotation = (F32)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_MAP_ROTATION_FIELD, LLSD::TypeInteger) / MATERIALS_MULTIPLIER;
+
+ mSpecularLightColor.setValue(getMaterialField<LLSD>(material_data, MATERIALS_CAP_SPECULAR_COLOR_FIELD, LLSD::TypeArray));
+ mSpecularLightExponent = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_SPECULAR_EXP_FIELD, LLSD::TypeInteger);
+ mEnvironmentIntensity = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_ENV_INTENSITY_FIELD, LLSD::TypeInteger);
+ mDiffuseAlphaMode = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_DIFFUSE_ALPHA_MODE_FIELD, LLSD::TypeInteger);
+ mAlphaMaskCutoff = (U8)getMaterialField<LLSD::Integer>(material_data, MATERIALS_CAP_ALPHA_MASK_CUTOFF_FIELD, LLSD::TypeInteger);
+}
+
+bool LLMaterial::isNull() const
+{
+ return (*this == null);
+}
+
+bool LLMaterial::operator == (const LLMaterial& rhs) const
+{
+ return
+ (mNormalID == rhs.mNormalID) && (mNormalOffsetX == rhs.mNormalOffsetX) && (mNormalOffsetY == rhs.mNormalOffsetY) &&
+ (mNormalRepeatX == rhs.mNormalRepeatX) && (mNormalRepeatY == rhs.mNormalRepeatY) && (mNormalRotation == rhs.mNormalRotation) &&
+ (mSpecularID == rhs.mSpecularID) && (mSpecularOffsetX == rhs.mSpecularOffsetX) && (mSpecularOffsetY == rhs.mSpecularOffsetY) &&
+ (mSpecularRepeatX == rhs.mSpecularRepeatX) && (mSpecularRepeatY == rhs.mSpecularRepeatY) && (mSpecularRotation == rhs.mSpecularRotation) &&
+ (mSpecularLightColor == rhs.mSpecularLightColor) && (mSpecularLightExponent == rhs.mSpecularLightExponent) &&
+ (mEnvironmentIntensity == rhs.mEnvironmentIntensity) && (mDiffuseAlphaMode == rhs.mDiffuseAlphaMode) && (mAlphaMaskCutoff == rhs.mAlphaMaskCutoff);
+}
+
+bool LLMaterial::operator != (const LLMaterial& rhs) const
+{
+ return !(*this == rhs);
+}
+
+
+U32 LLMaterial::getShaderMask(U32 alpha_mode)
+{ //NEVER incorporate this value into the message system -- this function will vary depending on viewer implementation
+ U32 ret = 0;
+
+ //two least significant bits are "diffuse alpha mode"
+ if (alpha_mode != DIFFUSE_ALPHA_MODE_DEFAULT)
+ {
+ ret = alpha_mode;
+ }
+ else
+ {
+ ret = getDiffuseAlphaMode();
+ }
+
+ llassert(ret < SHADER_COUNT);
+
+ //next bit is whether or not specular map is present
+ const U32 SPEC_BIT = 0x4;
+
+ if (getSpecularID().notNull())
+ {
+ ret |= SPEC_BIT;
+ }
+
+ llassert(ret < SHADER_COUNT);
+
+ //next bit is whether or not normal map is present
+ const U32 NORM_BIT = 0x8;
+ if (getNormalID().notNull())
+ {
+ ret |= NORM_BIT;
+ }
+
+ llassert(ret < SHADER_COUNT);
+
+ return ret;
+}
+
+
diff --git a/indra/llprimitive/llmaterial.h b/indra/llprimitive/llmaterial.h
new file mode 100644
index 0000000000..9f52a3f6c1
--- /dev/null
+++ b/indra/llprimitive/llmaterial.h
@@ -0,0 +1,155 @@
+/**
+ * @file llmaterial.h
+ * @brief Material definition
+ *
+ * $LicenseInfo:firstyear=2006&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, 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_LLMATERIAL_H
+#define LL_LLMATERIAL_H
+
+#include <boost/shared_ptr.hpp>
+
+#include "llmaterialid.h"
+#include "llsd.h"
+#include "v4coloru.h"
+#include "llpointer.h"
+#include "llrefcount.h"
+
+class LLMaterial : public LLRefCount
+{
+public:
+
+ typedef enum
+ {
+ DIFFUSE_ALPHA_MODE_NONE = 0,
+ DIFFUSE_ALPHA_MODE_BLEND = 1,
+ DIFFUSE_ALPHA_MODE_MASK = 2,
+ DIFFUSE_ALPHA_MODE_EMISSIVE = 3,
+ DIFFUSE_ALPHA_MODE_DEFAULT = 4,
+ } eDiffuseAlphaMode;
+
+ typedef enum
+ {
+ SHADER_COUNT = 16,
+ ALPHA_SHADER_COUNT = 4
+ } eShaderCount;
+
+
+
+ static const U8 DEFAULT_SPECULAR_LIGHT_EXPONENT = ((U8)(0.2f * 255));
+ static const LLColor4U DEFAULT_SPECULAR_LIGHT_COLOR;
+ static const U8 DEFAULT_ENV_INTENSITY = 0;
+
+ LLMaterial();
+ LLMaterial(const LLSD& material_data);
+
+ LLSD asLLSD() const;
+ void fromLLSD(const LLSD& material_data);
+
+ const LLUUID& getNormalID() const { return mNormalID; }
+ void setNormalID(const LLUUID& normal_id) { mNormalID = normal_id; }
+ void getNormalOffset(F32& offset_x, F32& offset_y) const { offset_x = mNormalOffsetX; offset_y = mNormalOffsetY; }
+ F32 getNormalOffsetX() const { return mNormalOffsetX; }
+ F32 getNormalOffsetY() const { return mNormalOffsetY; }
+
+ void setNormalOffset(F32 offset_x, F32 offset_y) { mNormalOffsetX = offset_x; mNormalOffsetY = offset_y; }
+ void setNormalOffsetX(F32 offset_x) { mNormalOffsetX = offset_x; }
+ void setNormalOffsetY(F32 offset_y) { mNormalOffsetY = offset_y; }
+
+ void getNormalRepeat(F32& repeat_x, F32& repeat_y) const { repeat_x = mNormalRepeatX; repeat_y = mNormalRepeatY; }
+ F32 getNormalRepeatX() const { return mNormalRepeatX; }
+ F32 getNormalRepeatY() const { return mNormalRepeatY; }
+
+ void setNormalRepeat(F32 repeat_x, F32 repeat_y) { mNormalRepeatX = repeat_x; mNormalRepeatY = repeat_y; }
+ void setNormalRepeatX(F32 repeat_x) { mNormalRepeatX = repeat_x; }
+ void setNormalRepeatY(F32 repeat_y) { mNormalRepeatY = repeat_y; }
+
+ F32 getNormalRotation() const { return mNormalRotation; }
+ void setNormalRotation(F32 rot) { mNormalRotation = rot; }
+
+ const LLUUID& getSpecularID() const { return mSpecularID; }
+ void setSpecularID(const LLUUID& specular_id) { mSpecularID = specular_id; }
+ void getSpecularOffset(F32& offset_x, F32& offset_y) const { offset_x = mSpecularOffsetX; offset_y = mSpecularOffsetY; }
+ F32 getSpecularOffsetX() const { return mSpecularOffsetX; }
+ F32 getSpecularOffsetY() const { return mSpecularOffsetY; }
+
+ void setSpecularOffset(F32 offset_x, F32 offset_y) { mSpecularOffsetX = offset_x; mSpecularOffsetY = offset_y; }
+ void setSpecularOffsetX(F32 offset_x) { mSpecularOffsetX = offset_x; }
+ void setSpecularOffsetY(F32 offset_y) { mSpecularOffsetY = offset_y; }
+
+ void getSpecularRepeat(F32& repeat_x, F32& repeat_y) const { repeat_x = mSpecularRepeatX; repeat_y = mSpecularRepeatY; }
+ F32 getSpecularRepeatX() const { return mSpecularRepeatX; }
+ F32 getSpecularRepeatY() const { return mSpecularRepeatY; }
+
+ void setSpecularRepeat(F32 repeat_x, F32 repeat_y) { mSpecularRepeatX = repeat_x; mSpecularRepeatY = repeat_y; }
+ void setSpecularRepeatX(F32 repeat_x) { mSpecularRepeatX = repeat_x; }
+ void setSpecularRepeatY(F32 repeat_y) { mSpecularRepeatY = repeat_y; }
+
+ F32 getSpecularRotation() const { return mSpecularRotation; }
+ void setSpecularRotation(F32 rot) { mSpecularRotation = rot; }
+
+ const LLColor4U getSpecularLightColor() const { return mSpecularLightColor; }
+ void setSpecularLightColor(const LLColor4U& color) { mSpecularLightColor = color; }
+ U8 getSpecularLightExponent() const { return mSpecularLightExponent; }
+ void setSpecularLightExponent(U8 exponent) { mSpecularLightExponent = exponent; }
+ U8 getEnvironmentIntensity() const { return mEnvironmentIntensity; }
+ void setEnvironmentIntensity(U8 intensity) { mEnvironmentIntensity = intensity; }
+ U8 getDiffuseAlphaMode() const { return mDiffuseAlphaMode; }
+ void setDiffuseAlphaMode(U8 alpha_mode) { mDiffuseAlphaMode = alpha_mode; }
+ U8 getAlphaMaskCutoff() const { return mAlphaMaskCutoff; }
+ void setAlphaMaskCutoff(U8 cutoff) { mAlphaMaskCutoff = cutoff; }
+
+ bool isNull() const;
+ static const LLMaterial null;
+
+ bool operator == (const LLMaterial& rhs) const;
+ bool operator != (const LLMaterial& rhs) const;
+
+ U32 getShaderMask(U32 alpha_mode = DIFFUSE_ALPHA_MODE_DEFAULT);
+
+protected:
+ LLUUID mNormalID;
+ F32 mNormalOffsetX;
+ F32 mNormalOffsetY;
+ F32 mNormalRepeatX;
+ F32 mNormalRepeatY;
+ F32 mNormalRotation;
+
+ LLUUID mSpecularID;
+ F32 mSpecularOffsetX;
+ F32 mSpecularOffsetY;
+ F32 mSpecularRepeatX;
+ F32 mSpecularRepeatY;
+ F32 mSpecularRotation;
+
+ LLColor4U mSpecularLightColor;
+ U8 mSpecularLightExponent;
+ U8 mEnvironmentIntensity;
+ U8 mDiffuseAlphaMode;
+ U8 mAlphaMaskCutoff;
+};
+
+typedef LLPointer<LLMaterial> LLMaterialPtr;
+
+#endif // LL_LLMATERIAL_H
+
diff --git a/indra/llprimitive/llmaterialid.cpp b/indra/llprimitive/llmaterialid.cpp
new file mode 100644
index 0000000000..820f62c43c
--- /dev/null
+++ b/indra/llprimitive/llmaterialid.cpp
@@ -0,0 +1,183 @@
+/**
+* @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"
+
+#include <string>
+
+#include "llformat.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 void* pMemory)
+{
+ set(pMemory);
+}
+
+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);
+}
+
+bool LLMaterialID::operator < (const LLMaterialID& pOtherMaterialID) const
+{
+ return (compareToOtherMaterialID(pOtherMaterialID) < 0);
+}
+
+bool LLMaterialID::operator <= (const LLMaterialID& pOtherMaterialID) const
+{
+ return (compareToOtherMaterialID(pOtherMaterialID) <= 0);
+}
+
+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));
+}
+
+LLSD LLMaterialID::asLLSD() const
+{
+ LLSD::Binary materialIDBinary;
+
+ materialIDBinary.resize(MATERIAL_ID_SIZE * sizeof(U8));
+ memcpy(materialIDBinary.data(), mID, MATERIAL_ID_SIZE * sizeof(U8));
+
+ LLSD materialID = materialIDBinary;
+ return materialID;
+}
+
+std::string LLMaterialID::asString() const
+{
+ std::string materialIDString;
+ for (unsigned int i = 0U; i < static_cast<unsigned int>(MATERIAL_ID_SIZE / sizeof(U32)); ++i)
+ {
+ if (i != 0U)
+ {
+ materialIDString += "-";
+ }
+ const U32 *value = reinterpret_cast<const U32*>(&get()[i * sizeof(U32)]);
+ materialIDString += llformat("%08x", *value);
+ }
+ return materialIDString;
+}
+
+std::ostream& operator<<(std::ostream& s, const LLMaterialID &material_id)
+{
+ s << material_id.asString();
+ return s;
+}
+
+
+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.get(), MATERIAL_ID_SIZE * sizeof(U8));
+}
+
+int LLMaterialID::compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const
+{
+ int retVal = 0;
+
+ for (unsigned int i = 0U; (retVal == 0) && (i < static_cast<unsigned int>(MATERIAL_ID_SIZE / sizeof(U32))); ++i)
+ {
+ const U32 *thisValue = reinterpret_cast<const U32*>(&get()[i * sizeof(U32)]);
+ const U32 *otherValue = reinterpret_cast<const U32*>(&pOtherMaterialID.get()[i * sizeof(U32)]);
+ retVal = ((*thisValue < *otherValue) ? -1 : ((*thisValue > *otherValue) ? 1 : 0));
+ }
+
+ return retVal;
+}
diff --git a/indra/llprimitive/llmaterialid.h b/indra/llprimitive/llmaterialid.h
new file mode 100644
index 0000000000..0a95204085
--- /dev/null
+++ b/indra/llprimitive/llmaterialid.h
@@ -0,0 +1,76 @@
+/**
+* @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
+
+#include <string>
+
+class LLMaterialID
+{
+public:
+ LLMaterialID();
+ LLMaterialID(const LLSD& pMaterialID);
+ LLMaterialID(const LLSD::Binary& pMaterialID);
+ LLMaterialID(const void* pMemory);
+ LLMaterialID(const LLMaterialID& pOtherMaterialID);
+ ~LLMaterialID();
+
+ bool operator == (const LLMaterialID& pOtherMaterialID) const;
+ bool operator != (const LLMaterialID& pOtherMaterialID) const;
+
+ bool operator < (const LLMaterialID& pOtherMaterialID) const;
+ bool operator <= (const LLMaterialID& pOtherMaterialID) const;
+ 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();
+
+ LLSD asLLSD() const;
+ std::string asString() const;
+
+ friend std::ostream& operator<<(std::ostream& s, const LLMaterialID &material_id);
+
+ 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 c340fc2d35..2fa77177f5 100755
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -39,6 +39,7 @@
#include "llsdutil_math.h"
#include "llprimtexturelist.h"
#include "imageids.h"
+#include "llmaterialid.h"
/**
* exported constants
@@ -314,6 +315,15 @@ S32 LLPrimitive::setTERotation(const U8 index, const F32 r)
return mTextureList.setRotation(index, r);
}
+S32 LLPrimitive::setTEMaterialID(const U8 index, const LLMaterialID& pMaterialID)
+{
+ return mTextureList.setMaterialID(index, pMaterialID);
+}
+
+S32 LLPrimitive::setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams)
+{
+ return mTextureList.setMaterialParams(index, pMaterialParams);
+}
//===============================================================
S32 LLPrimitive::setTEBumpShinyFullbright(const U8 index, const U8 bump)
@@ -364,6 +374,23 @@ S32 LLPrimitive::setTEGlow(const U8 index, const F32 glow)
return mTextureList.setGlow(index, glow);
}
+void LLPrimitive::setAllTESelected(bool sel)
+{
+ for (int i = 0, cnt = getNumTEs(); i < cnt; i++)
+ {
+ setTESelected(i, sel);
+ }
+}
+
+void LLPrimitive::setTESelected(const U8 te, bool sel)
+{
+ LLTextureEntry* tep = getTE(te);
+ if ( (tep) && (tep->setSelected(sel)) && (!sel) && (tep->hasPendingMaterialUpdate()) )
+ {
+ LLMaterialID material_id = tep->getMaterialID();
+ setTEMaterialID(te, material_id);
+ }
+}
LLPCode LLPrimitive::legacyToPCode(const U8 legacy)
{
@@ -1044,7 +1071,7 @@ S32 LLPrimitive::unpackTEField(U8 *cur_ptr, U8 *buffer_end, U8 *data_ptr, U8 dat
while ((cur_ptr < buffer_end) && (*cur_ptr != 0))
{
-// llinfos << "TE exception" << llendl;
+ LL_DEBUGS("TEFieldDecode") << "TE exception" << LL_ENDL;
i = 0;
while (*cur_ptr & 0x80)
{
@@ -1059,14 +1086,16 @@ S32 LLPrimitive::unpackTEField(U8 *cur_ptr, U8 *buffer_end, U8 *data_ptr, U8 dat
if (i & 0x01)
{
htonmemcpy(data_ptr+(j*data_size),cur_ptr,type,data_size);
-// char foo[64];
-// sprintf(foo,"%x %x",*(data_ptr+(j*data_size)), *(data_ptr+(j*data_size)+1));
-// llinfos << "Assigning " << foo << " to face " << j << llendl;
+ LL_DEBUGS("TEFieldDecode") << "Assigning " ;
+ char foo[64];
+ sprintf(foo,"%x %x",*(data_ptr+(j*data_size)), *(data_ptr+(j*data_size)+1));
+ LL_CONT << foo << " to face " << j << LL_ENDL;
}
i = i >> 1;
}
cur_ptr += data_size;
}
+ llassert(cur_ptr <= buffer_end); // buffer underrun
return (S32)(cur_ptr - start_loc);
}
@@ -1088,6 +1117,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];
@@ -1125,6 +1155,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);
@@ -1146,6 +1179,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));
@@ -1167,6 +1202,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];
@@ -1204,6 +1240,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);
@@ -1225,6 +1264,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");
@@ -1234,6 +1275,9 @@ BOOL LLPrimitive::packTEMessage(LLDataPacker &dp) const
S32 LLPrimitive::parseTEMessage(LLMessageSystem* mesgsys, char const* block_name, const S32 block_num, LLTEContents& tec)
{
S32 retval = 0;
+ // temp buffer for material ID processing
+ // data will end up in tec.material_id[]
+ U8 material_data[LLTEContents::MAX_TES*16];
if (block_num < 0)
{
@@ -1282,14 +1326,29 @@ S32 LLPrimitive::parseTEMessage(LLMessageSystem* mesgsys, char const* block_name
cur_ptr++;
cur_ptr += unpackTEField(cur_ptr, tec.packed_buffer+tec.size, (U8 *)tec.glow, 1, tec.face_count, MVT_U8);
+ if (cur_ptr < tec.packed_buffer + tec.size)
+ {
+ cur_ptr++;
+ cur_ptr += unpackTEField(cur_ptr, tec.packed_buffer+tec.size, (U8 *)material_data, 16, tec.face_count, MVT_LLUUID);
+ }
+ else
+ {
+ memset(material_data, 0, sizeof(material_data));
+ }
+
+ for (U32 i = 0; i < tec.face_count; i++)
+ {
+ tec.material_ids[i].set(&material_data[i * 16]);
+ }
+
retval = 1;
return retval;
-}
-
+ }
+
S32 LLPrimitive::applyParsedTEMessage(LLTEContents& tec)
{
S32 retval = 0;
-
+
LLColor4 color;
LLColor4U coloru;
for (U32 i = 0; i < tec.face_count; i++)
@@ -1302,6 +1361,9 @@ S32 LLPrimitive::applyParsedTEMessage(LLTEContents& tec)
retval |= setTEBumpShinyFullbright(i, tec.bump[i]);
retval |= setTEMediaTexGen(i, tec.media_flags[i]);
retval |= setTEGlow(i, (F32)tec.glow[i] / (F32)0xFF);
+
+ retval |= setTEMaterialID(i, tec.material_ids[i]);
+
coloru = LLColor4U(tec.colors + 4*i);
// Note: This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
@@ -1336,6 +1398,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];
@@ -1347,6 +1410,7 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp)
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];
@@ -1389,10 +1453,20 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp)
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);
+ if (cur_ptr < packed_buffer + size)
+ {
+ cur_ptr++;
+ cur_ptr += unpackTEField(cur_ptr, packed_buffer+size, (U8 *)material_data, 16, face_count, MVT_LLUUID);
+ }
+ else
+ {
+ memset(material_data, 0, sizeof(material_data));
+ }
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;
@@ -1406,6 +1480,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 6a8b59c81c..47a21beaaf 100755
--- 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;
@@ -309,7 +310,8 @@ struct LLTEContents
U8 bump[MAX_TES];
U8 media_flags[MAX_TES];
U8 glow[MAX_TES];
-
+ LLMaterialID material_ids[MAX_TES];
+
static const U32 MAX_TE_BUFFER = 4096;
U8 packed_buffer[MAX_TE_BUFFER];
@@ -359,6 +361,7 @@ public:
LLTextureEntry* getTE(const U8 te_num) const;
virtual void setNumTEs(const U8 num_tes);
+ virtual void setAllTESelected(bool sel);
virtual void setAllTETextures(const LLUUID &tex_id);
virtual void setTE(const U8 index, const LLTextureEntry& te);
virtual S32 setTEColor(const U8 te, const LLColor4 &color);
@@ -381,7 +384,10 @@ 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 S32 setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams);
virtual BOOL setMaterial(const U8 material); // returns TRUE if material changed
+ virtual void setTESelected(const U8 te, bool sel);
void copyTEs(const LLPrimitive *primitive);
S32 packTEField(U8 *cur_ptr, U8 *data_ptr, U8 data_size, U8 last_face_index, EMsgVariableType type) const;
diff --git a/indra/llprimitive/llprimtexturelist.cpp b/indra/llprimitive/llprimtexturelist.cpp
index 7ef87ed382..537e7a6695 100755
--- 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"
// static
@@ -358,6 +359,24 @@ 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::setMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams)
+{
+ if (index < mEntryList.size())
+ {
+ return mEntryList[index]->setMaterialParams(pMaterialParams);
+ }
+ 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..d7fabbbb79 100755
--- a/indra/llprimitive/llprimtexturelist.h
+++ b/indra/llprimitive/llprimtexturelist.h
@@ -31,9 +31,11 @@
#include "lluuid.h"
#include "v3color.h"
#include "v4color.h"
+#include "llmaterial.h"
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 +104,8 @@ 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 setMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams);
S32 size() const;
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp
index 34eff17519..597f078490 100755
--- 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"
@@ -60,18 +61,24 @@ LLTextureEntry* LLTextureEntry::newTextureEntry()
//===============================================================
LLTextureEntry::LLTextureEntry()
: mMediaEntry(NULL)
+ , mSelected(false)
+ , mMaterialUpdatePending(false)
{
init(LLUUID::null,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
}
LLTextureEntry::LLTextureEntry(const LLUUID& tex_id)
: mMediaEntry(NULL)
+ , mSelected(false)
+ , mMaterialUpdatePending(false)
{
init(tex_id,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
}
LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
: mMediaEntry(NULL)
+ , mSelected(false)
+ , mMaterialUpdatePending(false)
{
mID = rhs.mID;
mScaleS = rhs.mScaleS;
@@ -83,6 +90,8 @@ LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
mBump = rhs.mBump;
mMediaFlags = rhs.mMediaFlags;
mGlow = rhs.mGlow;
+ mMaterialID = rhs.mMaterialID;
+ mMaterial = rhs.mMaterial;
if (rhs.mMediaEntry != NULL) {
// Make a copy
mMediaEntry = new LLMediaEntry(*rhs.mMediaEntry);
@@ -103,6 +112,8 @@ LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
mBump = rhs.mBump;
mMediaFlags = rhs.mMediaFlags;
mGlow = rhs.mGlow;
+ mMaterialID = rhs.mMaterialID;
+ mMaterial = rhs.mMaterial;
if (mMediaEntry != NULL) {
delete mMediaEntry;
}
@@ -130,6 +141,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 +171,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 +187,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 +537,34 @@ S32 LLTextureEntry::setGlow(F32 glow)
return TEM_CHANGE_NONE;
}
+S32 LLTextureEntry::setMaterialID(const LLMaterialID& pMaterialID)
+{
+ if ( (mMaterialID != pMaterialID) || (mMaterialUpdatePending && !mSelected) )
+ {
+ if (mSelected)
+ {
+ mMaterialUpdatePending = true;
+ mMaterialID = pMaterialID;
+ return TEM_CHANGE_NONE;
+ }
+
+ mMaterialUpdatePending = false;
+ mMaterialID = pMaterialID;
+ return TEM_CHANGE_TEXTURE;
+ }
+ return TEM_CHANGE_NONE;
+}
+
+S32 LLTextureEntry::setMaterialParams(const LLMaterialPtr pMaterialParams)
+{
+ if (mSelected)
+ {
+ mMaterialUpdatePending = true;
+ }
+ mMaterial = pMaterialParams;
+ return TEM_CHANGE_TEXTURE;
+}
+
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..19edcaa27d 100755
--- a/indra/llprimitive/lltextureentry.h
+++ b/indra/llprimitive/lltextureentry.h
@@ -30,6 +30,8 @@
#include "lluuid.h"
#include "v4color.h"
#include "llsd.h"
+#include "llmaterialid.h"
+#include "llmaterial.h"
// These bits are used while unpacking TEM messages to tell which aspects of
// the texture entry changed.
@@ -98,6 +100,10 @@ public:
void init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 offset_s, F32 offset_t, F32 rotation, U8 bump);
+ bool hasPendingMaterialUpdate() const { return mMaterialUpdatePending; }
+ bool isSelected() const { return mSelected; }
+ bool setSelected(bool sel) { bool prev_sel = mSelected; mSelected = sel; return prev_sel; }
+
// These return a TEM_ flag from above to indicate if something changed.
S32 setID (const LLUUID &tex_id);
S32 setColor(const LLColor4 &color);
@@ -121,11 +127,19 @@ public:
S32 setTexGen(U8 texGen);
S32 setMediaTexGen(U8 media);
S32 setGlow(F32 glow);
+ S32 setMaterialID(const LLMaterialID& pMaterialID);
+ S32 setMaterialParams(const LLMaterialPtr pMaterialParams);
virtual const LLUUID &getID() const { return mID; }
const LLColor4 &getColor() const { return mColor; }
void getScale(F32 *s, F32 *t) const { *s = mScaleS; *t = mScaleT; }
+ F32 getScaleS() const { return mScaleS; }
+ F32 getScaleT() const { return mScaleT; }
+
void getOffset(F32 *s, F32 *t) const { *s = mOffsetS; *t = mOffsetT; }
+ F32 getOffsetS() const { return mOffsetS; }
+ F32 getOffsetT() const { return mOffsetT; }
+
F32 getRotation() const { return mRotation; }
void getRotation(F32 *theta) const { *theta = mRotation; }
@@ -136,9 +150,11 @@ public:
U8 getBumpShinyFullbright() const { return mBump; }
U8 getMediaFlags() const { return mMediaFlags & TEM_MEDIA_MASK; }
- U8 getTexGen() const { return mMediaFlags & TEM_TEX_GEN_MASK; }
+ LLTextureEntry::e_texgen getTexGen() const { return LLTextureEntry::e_texgen(mMediaFlags & TEM_TEX_GEN_MASK); }
U8 getMediaTexGen() const { return mMediaFlags; }
F32 getGlow() const { return mGlow; }
+ const LLMaterialID& getMaterialID() const { return mMaterialID; };
+ const LLMaterialPtr getMaterialParams() const { return mMaterial; };
// *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()
@@ -188,11 +204,15 @@ public:
static const char* TEXTURE_MEDIA_DATA_KEY;
protected:
+ bool mSelected;
LLUUID mID; // Texture GUID
LLColor4 mColor;
U8 mBump; // Bump map, shiny, and fullbright
U8 mMediaFlags; // replace with web page, movie, etc.
F32 mGlow;
+ bool mMaterialUpdatePending;
+ LLMaterialID mMaterialID;
+ LLMaterialPtr mMaterial;
// 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