From 5b9fa736409111b949ce7893bee4bcd42d9adfe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deal=28=E4=B8=80=E7=BA=BF=E7=81=B5=29?= Date: Thu, 9 Feb 2023 21:40:38 +0800 Subject: [PATCH] Fix #990 --- core/renderer/backend/ProgramState.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/core/renderer/backend/ProgramState.cpp b/core/renderer/backend/ProgramState.cpp index 979a7bd139..1ee482ff40 100644 --- a/core/renderer/backend/ProgramState.cpp +++ b/core/renderer/backend/ProgramState.cpp @@ -1,6 +1,6 @@ /**************************************************************************** Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd. - Copyright (c) 2021-2022 Bytedance Inc. + Copyright (c) 2021-2023 Bytedance Inc. https://axmolengine.github.io/ @@ -305,8 +305,7 @@ void ProgramState::convertAndCopyUniformData(const backend::UniformInfo& uniform void* buffer) { auto basicType = static_cast(uniformInfo.type); - char* convertedData = new char[uniformInfo.size]; - memset(convertedData, 0, uniformInfo.size); + int offset = 0; switch (basicType) { @@ -314,23 +313,27 @@ void ProgramState::convertAndCopyUniformData(const backend::UniformInfo& uniform { if (uniformInfo.isMatrix) { + float m4x3[12]; for (int i = 0; i < uniformInfo.count; i++) { if (offset >= srcSize) break; - convertMat3ToMat4x3((float*)srcData + offset, (float*)convertedData + i * MAT4X3_SIZE); + convertMat3ToMat4x3((float*)((uint8_t*)srcData + offset), m4x3); + memcpy((uint8_t*)buffer + uniformInfo.location + i * sizeof(m4x3), m4x3, sizeof(m4x3)); offset += MAT3_SIZE; } } else { + float f4[4]; for (int i = 0; i < uniformInfo.count; i++) { if (offset >= srcSize) break; - convertVec3ToVec4((float*)srcData + offset, (float*)convertedData + i * VEC4_SIZE); + convertVec3ToVec4((float*)((uint8_t*)srcData + offset), f4); + memcpy((uint8_t*)buffer + uniformInfo.location + i * sizeof(f4), f4, sizeof(f4)); offset += VEC3_SIZE; } } @@ -338,24 +341,28 @@ void ProgramState::convertAndCopyUniformData(const backend::UniformInfo& uniform } case kGlslTypeBool: { + bool b4[4]; for (int i = 0; i < uniformInfo.count; i++) { if (offset >= srcSize) break; - convertbVec3TobVec4((bool*)srcData + offset, (bool*)convertedData + i * BVEC4_SIZE); + convertbVec3TobVec4((bool*)((uint8_t*)srcData + offset), b4); + memcpy((uint8_t*)buffer + uniformInfo.location + i * sizeof(b4), b4, sizeof(b4)); offset += BVEC3_SIZE; } break; } case kGlslTypeInt: { + int i4[4]; for (int i = 0; i < uniformInfo.count; i++) { if (offset >= srcSize) break; - convertiVec3ToiVec4((int*)srcData + offset, (int*)convertedData + i * IVEC4_SIZE); + convertiVec3ToiVec4((int*)((uint8_t*)srcData + offset), i4); + memcpy((uint8_t*)buffer + uniformInfo.location + i * sizeof(i4), i4, sizeof(i4)); offset += IVEC3_SIZE; } break; @@ -364,9 +371,6 @@ void ProgramState::convertAndCopyUniformData(const backend::UniformInfo& uniform AX_ASSERT(false); break; } - - memcpy((char*)buffer + uniformInfo.location, convertedData, uniformInfo.size); - AX_SAFE_DELETE_ARRAY(convertedData); } #endif