mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 04:08:32 +09:00
[Feat]: (MG_Test/Program): add test to check optfine shader behavior
This commit is contained in:
@@ -835,4 +835,104 @@ TEST_F(ProgramTest, MinecraftTexColor1_21_6) {
|
||||
spvcSession.Compile(&result);
|
||||
printf("%s\n\n", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* optifine_vs1 = R"(#version 460 core
|
||||
|
||||
in vec3 Position;
|
||||
in vec2 UV0;
|
||||
|
||||
uniform mat4 ModelViewMat;
|
||||
uniform mat4 ProjMat;
|
||||
|
||||
out vec2 texCoord0;
|
||||
|
||||
void main() {
|
||||
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);
|
||||
|
||||
texCoord0 = UV0;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* optifine_fs1 = R"(#version 460 core
|
||||
|
||||
uniform sampler2D Sampler0;
|
||||
|
||||
uniform vec4 ColorModulator;
|
||||
|
||||
in vec2 texCoord0;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
vec4 color = texture(Sampler0, texCoord0);
|
||||
if (color.a == 0.0) {
|
||||
discard;
|
||||
}
|
||||
fragColor = color * ColorModulator;
|
||||
})";
|
||||
|
||||
TEST_F(ProgramTest, CompileAndLinkOptfineSample1) {
|
||||
char infoLog[1024] = "";
|
||||
|
||||
GLuint fs = CreateShader(GL_FRAGMENT_SHADER);
|
||||
ShaderSource(fs, 1, &optifine_fs1, NULL);
|
||||
CompileShader(fs);
|
||||
GLint fsStatus = GL_FALSE;
|
||||
GetShaderiv(fs, GL_COMPILE_STATUS, &fsStatus);
|
||||
GetShaderInfoLog(fs, 1024, nullptr, infoLog);
|
||||
ASSERT_EQ(fsStatus, GL_TRUE) << infoLog;
|
||||
|
||||
GLuint vs = CreateShader(GL_VERTEX_SHADER);
|
||||
ShaderSource(vs, 1, &optifine_vs1, NULL);
|
||||
CompileShader(vs);
|
||||
GLint vsStatus = GL_FALSE;
|
||||
GetShaderiv(vs, GL_COMPILE_STATUS, &vsStatus);
|
||||
GetShaderInfoLog(vs, 1024, nullptr, infoLog);
|
||||
ASSERT_EQ(vsStatus, GL_TRUE) << infoLog;
|
||||
|
||||
GLuint program = CreateProgram();
|
||||
AttachShader(program, fs);
|
||||
AttachShader(program, vs);
|
||||
|
||||
BindAttribLocation(program, 0, "Position");
|
||||
BindAttribLocation(program, 2, "UV0");
|
||||
BindAttribLocation(program, 1, "Color");
|
||||
|
||||
LinkProgram(program);
|
||||
GLint linkStatus = GL_FALSE;
|
||||
GetProgramiv(program, GL_LINK_STATUS, &linkStatus);
|
||||
ASSERT_EQ(linkStatus, GL_TRUE);
|
||||
printf("Program linked.\n");
|
||||
|
||||
UseProgram(program);
|
||||
GLint posLoc = GetAttribLocation(program, "Position");
|
||||
ASSERT_EQ(posLoc, 0);
|
||||
GLint uv0Loc = GetAttribLocation(program, "UV0");
|
||||
ASSERT_EQ(uv0Loc, 2);
|
||||
|
||||
auto programObject = MG_State::pGLContext->GetCurrentProgram();
|
||||
auto& spirvs = programObject->GetGeneratedSpirv();
|
||||
char* found_correct_uv0 = nullptr;
|
||||
const char* needle = "layout(location = 2) in vec2 UV0;";
|
||||
for (auto spirv: spirvs) {
|
||||
MG_Util::ShaderTranspiler::SpvcSession spvcSession(spirv);
|
||||
spvc_compiler_options options;
|
||||
spvcSession.CreateOptions(&options);
|
||||
|
||||
spvc_compiler_options_set_uint(options, SPVC_COMPILER_OPTION_GLSL_VERSION, 460);
|
||||
spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_FALSE);
|
||||
// spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_VULKAN_SEMANTICS, SPVC_FALSE);
|
||||
|
||||
spvcSession.SetOptions(options);
|
||||
|
||||
const char* result = nullptr;
|
||||
spvcSession.Compile(&result);
|
||||
printf("%s\n\n", result);
|
||||
const char* ret = strstr(result, needle);
|
||||
if (ret)
|
||||
found_correct_uv0 = (char*)ret;
|
||||
}
|
||||
ASSERT_TRUE(found_correct_uv0 != nullptr) << "Not found correct attribute in generated shader.\n(Searching for \"" << needle << "\")";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user