Fix: MaterialStyle::decoded错误

main
wuyize 2023-03-24 00:02:35 +08:00
parent b2e49dae17
commit dc4de8823e
1 changed files with 6 additions and 4 deletions

View File

@ -64,7 +64,9 @@ std::unique_ptr<MaterialStyle> Renderer::MaterialStyle::decoded(const std::vecto
else /// MaterialStyleStroke else /// MaterialStyleStroke
{ {
std::unique_ptr<MaterialStroke> materialStroke; std::unique_ptr<MaterialStroke> materialStroke;
uint headUint = floatBitsToUint(encoded[1]); uint widthMapSize = floatBitsToUint(encoded[1]);
uint headIndex = widthMapSize + 2;
uint headUint = floatBitsToUint(encoded[headIndex]);
vec4 head = unpackUnorm4x8(headUint); vec4 head = unpackUnorm4x8(headUint);
StrokeType strokeType = (StrokeType)floor(head.b * 10); StrokeType strokeType = (StrokeType)floor(head.b * 10);
StrokeEndType endType = (StrokeEndType)(int(round(head.b * 100)) % 10); StrokeEndType endType = (StrokeEndType)(int(round(head.b * 100)) % 10);
@ -72,7 +74,7 @@ std::unique_ptr<MaterialStyle> Renderer::MaterialStyle::decoded(const std::vecto
{ {
/// Plain /// Plain
case 0: { case 0: {
materialStroke = std::make_unique<StrokePlain>(Material(glm::unpackUnorm4x8(glm::floatBitsToUint(encoded[2])), glm::vec2(head.r, head.g))); materialStroke = std::make_unique<StrokePlain>(Material(glm::unpackUnorm4x8(glm::floatBitsToUint(encoded[headIndex+1])), glm::vec2(head.r, head.g)));
break; break;
} }
/// RadialGradient /// RadialGradient
@ -82,9 +84,9 @@ std::unique_ptr<MaterialStyle> Renderer::MaterialStyle::decoded(const std::vecto
std::map<float, Material> materialMap; std::map<float, Material> materialMap;
for (uint i = 0; i < size; i++) for (uint i = 0; i < size; i++)
{ {
auto data = floatBitsToUint(encoded[2 + i * 2]); auto data = floatBitsToUint(encoded[headIndex + 1 + i * 2]);
auto level = unpackUnorm2x16(data).y; auto level = unpackUnorm2x16(data).y;
auto color = unpackUnorm4x8(floatBitsToUint(encoded[3 + i * 2])); auto color = unpackUnorm4x8(floatBitsToUint(encoded[headIndex + 2 + i * 2]));
auto metallicRoughness = unpackUnorm4x8(data); auto metallicRoughness = unpackUnorm4x8(data);
materialMap.emplace(level, Material(color, glm::vec2(metallicRoughness.r, metallicRoughness.g))); materialMap.emplace(level, Material(color, glm::vec2(metallicRoughness.r, metallicRoughness.g)));
} }