Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/test_utils/ShaderExtensionTest.h
1693 views
1
//
2
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// ShaderExtensionTest.cpp:
7
// Utilities for testing that GLSL extension pragma and changing the extension flag in compiler
8
// resources has the correct effect.
9
//
10
11
#include "GLSLANG/ShaderLang.h"
12
#include "angle_gl.h"
13
#include "gtest/gtest.h"
14
15
using testing::Combine;
16
using testing::make_tuple;
17
using testing::Values;
18
19
namespace sh
20
{
21
22
const char ESSLVersion100[] = "#version 100\n";
23
const char ESSLVersion300[] = "#version 300 es\n";
24
const char ESSLVersion310[] = "#version 310 es\n";
25
26
class ShaderExtensionTest
27
: public testing::TestWithParam<testing::tuple<ShShaderSpec, const char *, const char *>>
28
{
29
protected:
30
void SetUp() override
31
{
32
sh::InitBuiltInResources(&mResources);
33
mCompiler = nullptr;
34
}
35
36
void TearDown() override { DestroyCompiler(); }
37
void DestroyCompiler()
38
{
39
if (mCompiler)
40
{
41
sh::Destruct(mCompiler);
42
mCompiler = nullptr;
43
}
44
}
45
46
void InitializeCompiler()
47
{
48
DestroyCompiler();
49
mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()),
50
SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);
51
ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";
52
}
53
54
testing::AssertionResult TestShaderCompile(const char *pragma)
55
{
56
return TestShaderCompile(testing::get<1>(GetParam()), // Version.
57
pragma,
58
testing::get<2>(GetParam()) // Shader.
59
);
60
}
61
62
testing::AssertionResult TestShaderCompile(const char *version,
63
const char *pragma,
64
const char *shader)
65
{
66
const char *shaderStrings[] = {version, pragma, shader};
67
bool success = sh::Compile(mCompiler, shaderStrings, 3, 0);
68
if (success)
69
{
70
return ::testing::AssertionSuccess() << "Compilation success";
71
}
72
return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);
73
}
74
75
protected:
76
ShBuiltInResources mResources;
77
ShHandle mCompiler;
78
};
79
80
} // namespace sh
81
82