我试图创建一个函数,该函数能够将精度调制器关键字放在浮点变量前面,而没有这样的关键字,因此它将 const float x; 转换为 lowp const fl......
我试图创建一个能够
因此它转换
const float x;
到
lowp const float x;
但是我想忽略以下情况:
lowp const float x;
precision lowp float;
根据我之前的问题 链接 ,这是我的正则表达式:
(\bhighp((?:\s+\w+)*)(float|(?:i|b)?vec[2-4]|mat[2-4](?:x[2-4])?)(*SKIP)(?!)|\bfloat\b)
因此,我只是想忽略浮动之前存在 highp|lowp|mediump 的情况。
我有这个正则表达式命令:
#include <iostream>
#include <string>
#include <boost/regex/v5/regex.hpp>
using namespace boost;
std::string precisionModulation(std::string& shaderSource) {
const regex highpFloatRegex2(R"(highp|lowp|mediump((?:\s+\w+)*)(float)(*SKIP)(?!)|(?=\s+(float)))");
shaderSource = regex_replace(shaderSource, highpFloatRegex2, "lowp");
return shaderSource;
}
int main() {
std::string shaderSource = R"(
float foo1;
highp const float foo1;
precision highp float foo2;
)";
std::cout << "Original Shader Source:\n" << shaderSource << std::endl;
std::string modifiedSource = precisionModulation(shaderSource);
std::cout << "\nModified Shader Source:\n" << modifiedSource << std::endl;
return 0;
}
不幸的是我得到了奇怪的结果:
Original Shader Source:
float foo1;
highp const float foo1;
const highp float foo1;
precision highp float foo2;
Modified Shader Source:
lowp float foo1;
highp const lowp float foo1;
const highp lowp float foo1;
precision highp lowp float foo2;
我也尝试过:
\w*(?<!highp)((?:\s+\w+)*)\s+float