91 lines
2.2 KiB
C++
91 lines
2.2 KiB
C++
#include "fixtures/OpenGLTestFixture.h"
|
|
#include "XCEngine/RHI/OpenGL/OpenGLShader.h"
|
|
#include "XCEngine/RHI/OpenGL/OpenGLCommandList.h"
|
|
|
|
#include <string>
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
TEST_F(OpenGLTestFixture, Shader_Compile_VertexFragment) {
|
|
const char* vertexSource = R"(
|
|
#version 330 core
|
|
in vec3 aPosition;
|
|
void main() {
|
|
gl_Position = vec4(aPosition, 1.0);
|
|
}
|
|
)";
|
|
|
|
const char* fragmentSource = R"(
|
|
#version 330 core
|
|
out vec4 FragColor;
|
|
void main() {
|
|
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
|
}
|
|
)";
|
|
|
|
OpenGLShader shader;
|
|
bool result = shader.Compile(vertexSource, fragmentSource);
|
|
|
|
ASSERT_TRUE(result);
|
|
EXPECT_TRUE(shader.IsValid());
|
|
EXPECT_NE(shader.GetID(), 0u);
|
|
|
|
shader.Shutdown();
|
|
}
|
|
|
|
TEST_F(OpenGLTestFixture, Shader_Compile_WithGeometry) {
|
|
const char* vertexSource = R"(
|
|
#version 330 core
|
|
void main() {
|
|
gl_Position = vec4(0.0);
|
|
}
|
|
)";
|
|
|
|
const char* fragmentSource = R"(
|
|
#version 330 core
|
|
void main() {
|
|
}
|
|
)";
|
|
|
|
const char* geometrySource = R"(
|
|
#version 330 core
|
|
layout(triangles) in;
|
|
layout(triangle_strip, max_vertices = 3) out;
|
|
void main() {
|
|
for(int i = 0; i < 3; i++) {
|
|
gl_Position = gl_in[i].gl_Position;
|
|
EmitVertex();
|
|
}
|
|
EndPrimitive();
|
|
}
|
|
)";
|
|
|
|
OpenGLShader shader;
|
|
bool result = shader.Compile(vertexSource, fragmentSource, geometrySource);
|
|
|
|
ASSERT_TRUE(result);
|
|
EXPECT_TRUE(shader.IsValid());
|
|
|
|
shader.Shutdown();
|
|
}
|
|
|
|
TEST_F(OpenGLTestFixture, Shader_Compile_InvalidSource) {
|
|
const char* invalidSource = R"(
|
|
#version 330 core
|
|
void main() {
|
|
undefined_symbol;
|
|
}
|
|
)";
|
|
|
|
OpenGLShader shader;
|
|
testing::internal::CaptureStdout();
|
|
bool result = shader.Compile(invalidSource, "void main() { }");
|
|
const std::string output = testing::internal::GetCapturedStdout();
|
|
|
|
EXPECT_FALSE(result);
|
|
EXPECT_FALSE(shader.IsValid());
|
|
EXPECT_NE(output.find("ERROR::SHADER_COMPILATION_ERROR"), std::string::npos);
|
|
|
|
shader.Shutdown();
|
|
}
|