Hash :
5317b778
Author :
Date :
2022-08-23T08:58:04
Enable desktop GLSL for desktop GL frontend Bug: angleproject:7533 Change-Id: I91bd0c217880b05683b86449a9211b9844575ebc Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3850471 Commit-Queue: Eddie Hatfield <eddiehatfield@google.com> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/shader_utils.h"
namespace angle
{
class DesktopGLSLTest : public ANGLETest<>
{
protected:
DesktopGLSLTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
};
// Simple test case of compiling a desktop OpenGL shader to verify that the shader compiler
// initializes.
TEST_P(DesktopGLSLTest, BasicCompilation)
{
constexpr char kVS[] = R"(#version 150
in vec4 position;
void main()
{
gl_Position = position;
})";
constexpr char kFS[] = R"(#version 150
out vec4 fragColor;
void main()
{
fragColor = vec4(1.0, 0.5, 0.2, 1.0);
})";
ANGLE_GL_PROGRAM(testProgram, kVS, kFS);
}
// Test calling sh::Compile with fragment shader source string
TEST_P(DesktopGLSLTest, DesktopGLString)
{
constexpr char kFS[] =
R"(#version 330
void main()
{
})";
ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
}
// Test calling sh::Compile with core version
TEST_P(DesktopGLSLTest, FragmentShaderCoreVersion)
{
constexpr char kFS[] =
R"(#version 330 core
void main()
{
})";
ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
}
// Implicit conversions in basic operations
TEST_P(DesktopGLSLTest, ImplicitConversionBasicOperation)
{
constexpr char kFS[] =
R"(#version 330 core
void main()
{
//float a = 1 + 1.5;
//float b = 1 - 1.5;
//float c = 1 * 1.5;
//float d = 1 / 1.5;
//float e = 1.5 + 1;
//float f = 1.5 - 1;
float g = 1.5 * 1;
//float h = 1.5 / 1;
})";
ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
}
// Implicit conversions when assigning
TEST_P(DesktopGLSLTest, ImplicitConversionAssign)
{
constexpr char kFS[] =
R"(#version 330 core
void main()
{
float a = 1;
uint b = 2u;
a = b;
a += b;
a -= b;
a *= b;
a /= b;
})";
ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
}
// Implicit conversions for vectors
TEST_P(DesktopGLSLTest, ImplicitConversionVector)
{
constexpr char kFS[] =
R"(#version 330 core
void main()
{
vec3 a;
ivec3 b = ivec3(1, 1, 1);
a = b;
})";
ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
}
// Implicit conversions should not convert between ints and uints
TEST_P(DesktopGLSLTest, ImplicitConversionAssignFailed)
{
constexpr char kFS[] =
R"(#version 330 core
void main()
{
int a = 1;
uint b = 2;
a = b;
})";
ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
}
// GL shaders use implicit conversions between types
// Testing internal implicit conversions
TEST_P(DesktopGLSLTest, ImplicitConversionFunction)
{
constexpr char kFS[] =
R"(#version 330 core
void main()
{
float cosTheta = clamp(0.5,0,1);
float exp = pow(0.5,2);
})";
ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DesktopGLSLTest);
ANGLE_INSTANTIATE_TEST_GL32_CORE(DesktopGLSLTest);
} // namespace angle