summaryrefslogtreecommitdiff
path: root/indra/newview/gltf/asset.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/gltf/asset.cpp')
-rw-r--r--indra/newview/gltf/asset.cpp145
1 files changed, 75 insertions, 70 deletions
diff --git a/indra/newview/gltf/asset.cpp b/indra/newview/gltf/asset.cpp
index 4e66bf2cbf..55b275ecb4 100644
--- a/indra/newview/gltf/asset.cpp
+++ b/indra/newview/gltf/asset.cpp
@@ -516,7 +516,7 @@ bool Asset::prep()
for (auto& image : mImages)
{
- if (!image.prep(*this))
+ if (!image.prep(*this, mLoadIntoVRAM))
{
return false;
}
@@ -545,101 +545,103 @@ bool Asset::prep()
return false;
}
}
+ if (mLoadIntoVRAM)
+ {
+ // prepare vertex buffers
- // prepare vertex buffers
-
- // material count is number of materials + 1 for default material
- U32 mat_count = (U32) mMaterials.size() + 1;
-
- if (LLGLSLShader::sCurBoundShaderPtr == nullptr)
- { // make sure a shader is bound to satisfy mVertexBuffer->setBuffer
- gDebugProgram.bind();
- }
+ // material count is number of materials + 1 for default material
+ U32 mat_count = (U32) mMaterials.size() + 1;
- for (S32 double_sided = 0; double_sided < 2; ++double_sided)
- {
- RenderData& rd = mRenderData[double_sided];
- for (U32 i = 0; i < LLGLSLShader::NUM_GLTF_VARIANTS; ++i)
- {
- rd.mBatches[i].resize(mat_count);
+ if (LLGLSLShader::sCurBoundShaderPtr == nullptr)
+ { // make sure a shader is bound to satisfy mVertexBuffer->setBuffer
+ gDebugProgram.bind();
}
- // for each material
- for (S32 mat_id = -1; mat_id < (S32)mMaterials.size(); ++mat_id)
+ for (S32 double_sided = 0; double_sided < 2; ++double_sided)
{
- // for each shader variant
- U32 vertex_count[LLGLSLShader::NUM_GLTF_VARIANTS] = { 0 };
- U32 index_count[LLGLSLShader::NUM_GLTF_VARIANTS] = { 0 };
-
- S32 ds_mat = mat_id == -1 ? 0 : mMaterials[mat_id].mDoubleSided;
- if (ds_mat != double_sided)
+ RenderData& rd = mRenderData[double_sided];
+ for (U32 i = 0; i < LLGLSLShader::NUM_GLTF_VARIANTS; ++i)
{
- continue;
+ rd.mBatches[i].resize(mat_count);
}
- for (U32 variant = 0; variant < LLGLSLShader::NUM_GLTF_VARIANTS; ++variant)
+ // for each material
+ for (S32 mat_id = -1; mat_id < (S32)mMaterials.size(); ++mat_id)
{
- U32 attribute_mask = 0;
- // for each mesh
- for (auto& mesh : mMeshes)
+ // for each shader variant
+ U32 vertex_count[LLGLSLShader::NUM_GLTF_VARIANTS] = { 0 };
+ U32 index_count[LLGLSLShader::NUM_GLTF_VARIANTS] = { 0 };
+
+ S32 ds_mat = mat_id == -1 ? 0 : mMaterials[mat_id].mDoubleSided;
+ if (ds_mat != double_sided)
{
- // for each primitive
- for (auto& primitive : mesh.mPrimitives)
+ continue;
+ }
+
+ for (U32 variant = 0; variant < LLGLSLShader::NUM_GLTF_VARIANTS; ++variant)
+ {
+ U32 attribute_mask = 0;
+ // for each mesh
+ for (auto& mesh : mMeshes)
{
- if (primitive.mMaterial == mat_id && primitive.mShaderVariant == variant)
+ // for each primitive
+ for (auto& primitive : mesh.mPrimitives)
{
- // accumulate vertex and index counts
- primitive.mVertexOffset = vertex_count[variant];
- primitive.mIndexOffset = index_count[variant];
+ if (primitive.mMaterial == mat_id && primitive.mShaderVariant == variant)
+ {
+ // accumulate vertex and index counts
+ primitive.mVertexOffset = vertex_count[variant];
+ primitive.mIndexOffset = index_count[variant];
- vertex_count[variant] += primitive.getVertexCount();
- index_count[variant] += primitive.getIndexCount();
+ vertex_count[variant] += primitive.getVertexCount();
+ index_count[variant] += primitive.getIndexCount();
- // all primitives of a given variant and material should all have the same attribute mask
- llassert(attribute_mask == 0 || primitive.mAttributeMask == attribute_mask);
- attribute_mask |= primitive.mAttributeMask;
+ // all primitives of a given variant and material should all have the same attribute mask
+ llassert(attribute_mask == 0 || primitive.mAttributeMask == attribute_mask);
+ attribute_mask |= primitive.mAttributeMask;
+ }
}
}
- }
- // allocate vertex buffer and pack it
- if (vertex_count[variant] > 0)
- {
- U32 mat_idx = mat_id + 1;
- #if 0
- LLVertexBuffer* vb = new LLVertexBuffer(attribute_mask);
+ // allocate vertex buffer and pack it
+ if (vertex_count[variant] > 0)
+ {
+ U32 mat_idx = mat_id + 1;
+ #if 0
+ LLVertexBuffer* vb = new LLVertexBuffer(attribute_mask);
- rd.mBatches[variant][mat_idx].mVertexBuffer = vb;
- vb->allocateBuffer(vertex_count[variant],
- index_count[variant] * 2); // hack double index count... TODO: find a better way to indicate 32-bit indices will be used
- vb->setBuffer();
+ rd.mBatches[variant][mat_idx].mVertexBuffer = vb;
+ vb->allocateBuffer(vertex_count[variant],
+ index_count[variant] * 2); // hack double index count... TODO: find a better way to indicate 32-bit indices will be used
+ vb->setBuffer();
- for (auto& mesh : mMeshes)
- {
- for (auto& primitive : mesh.mPrimitives)
+ for (auto& mesh : mMeshes)
{
- if (primitive.mMaterial == mat_id && primitive.mShaderVariant == variant)
+ for (auto& primitive : mesh.mPrimitives)
{
- primitive.upload(vb);
+ if (primitive.mMaterial == mat_id && primitive.mShaderVariant == variant)
+ {
+ primitive.upload(vb);
+ }
}
}
- }
- vb->unmapBuffer();
+ vb->unmapBuffer();
- vb->unbind();
- #endif
+ vb->unbind();
+ #endif
+ }
}
}
}
- }
- // sanity check that all primitives have a vertex buffer
- for (auto& mesh : mMeshes)
- {
- for (auto& primitive : mesh.mPrimitives)
+ // sanity check that all primitives have a vertex buffer
+ for (auto& mesh : mMeshes)
{
- //llassert(primitive.mVertexBuffer.notNull());
+ for (auto& primitive : mesh.mPrimitives)
+ {
+ //llassert(primitive.mVertexBuffer.notNull());
+ }
}
}
#if 0
@@ -678,9 +680,10 @@ Asset::Asset(const Value& src)
*this = src;
}
-bool Asset::load(std::string_view filename)
+bool Asset::load(std::string_view filename, bool loadIntoVRAM)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_GLTF;
+ mLoadIntoVRAM = loadIntoVRAM;
mFilename = filename;
std::string ext = gDirUtilp->getExtension(mFilename);
@@ -698,7 +701,7 @@ bool Asset::load(std::string_view filename)
}
else if (ext == "glb")
{
- return loadBinary(str);
+ return loadBinary(str, mLoadIntoVRAM);
}
else
{
@@ -715,8 +718,9 @@ bool Asset::load(std::string_view filename)
return false;
}
-bool Asset::loadBinary(const std::string& data)
+bool Asset::loadBinary(const std::string& data, bool loadIntoVRAM)
{
+ mLoadIntoVRAM = loadIntoVRAM;
// load from binary gltf
const U8* ptr = (const U8*)data.data();
const U8* end = ptr + data.size();
@@ -941,8 +945,9 @@ void Asset::eraseBufferView(S32 bufferView)
LLViewerFetchedTexture* fetch_texture(const LLUUID& id);
-bool Image::prep(Asset& asset)
+bool Image::prep(Asset& asset, bool loadIntoVRAM)
{
+ mLoadIntoTexturePipe = loadIntoVRAM;
LLUUID id;
if (mUri.size() == UUID_STR_SIZE && LLUUID::parseUUID(mUri, &id) && id.notNull())
{ // loaded from an asset, fetch the texture from the asset system