-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rafal Maziejuk <[email protected]>
- Loading branch information
1 parent
0700a1e
commit 4ff9cb0
Showing
4 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "src/opengl/gl_context.h" | ||
#include "src/opengl/gl_program.h" | ||
#include "src/opengl/gl_shader.h" | ||
|
||
#include "tests/fixtures/window_fixture.h" | ||
|
||
#include <glad/gl.h> | ||
#include <gtest/gtest.h> | ||
|
||
using namespace nox; | ||
|
||
struct GLProgramFixture : public tests::WindowFixture, | ||
public ::testing::Test { | ||
void SetUp() override { | ||
tests::WindowFixture::setUp(); | ||
|
||
SurfaceDescriptor surfaceDescriptor{}; | ||
surfaceDescriptor.surfaceBackendDescriptor = surfaceBackendDescriptor; | ||
surfaceDescriptor.surfaceAttributesDescriptor = OpenGLSurfaceAttributesDescriptor{}; | ||
|
||
context = GLContext::create(surfaceDescriptor); | ||
ASSERT_NE(nullptr, context); | ||
} | ||
|
||
void TearDown() override { | ||
tests::WindowFixture::tearDown(); | ||
} | ||
|
||
std::unique_ptr<GLContext> context{nullptr}; | ||
}; | ||
|
||
TEST_F(GLProgramFixture, WhenCreatingProgramThenProgramIsSuccessfullyCreated) { | ||
GLProgram program{}; | ||
|
||
EXPECT_NE(0u, program.getHandle()); | ||
} | ||
|
||
TEST_F(GLProgramFixture, GivenCorrectShadersWhenLinkingProgramThenTrueIsReturned) { | ||
constexpr auto vertexShaderSource = R"( | ||
#version 460 core | ||
out gl_PerVertex { | ||
vec4 gl_Position; | ||
}; | ||
void main() { | ||
gl_Position = vec4(1.0); | ||
} | ||
)"; | ||
constexpr auto fragmentShaderSource = R"( | ||
#version 460 core | ||
out vec4 fragmentColor; | ||
void main() { | ||
fragmentColor = vec4(1.0); | ||
} | ||
)"; | ||
|
||
GLProgram program{}; | ||
const GLShader vertexShader{{ShaderType::VERTEX}}; | ||
const GLShader fragmentShader{{ShaderType::FRAGMENT}}; | ||
|
||
vertexShader.compile(vertexShaderSource); | ||
fragmentShader.compile(fragmentShaderSource); | ||
program.attachShader(vertexShader.getHandle()); | ||
program.attachShader(fragmentShader.getHandle()); | ||
|
||
EXPECT_TRUE(program.link()); | ||
} | ||
|
||
TEST_F(GLProgramFixture, GivenIncorrectShadersWhenLinkingProgramThenFalseIsReturned) { | ||
constexpr auto vertexShaderSource = R"( | ||
#version 460 core | ||
out gl_PerVertex { | ||
vec4 gl_Position; | ||
}; | ||
void main() { | ||
gl_Position = vec4(1.0); | ||
} | ||
)"; | ||
constexpr auto fragmentShaderSource = R"( | ||
#version 460 core | ||
in vec2 textureCoordinates; | ||
out vec4 fragmentColor; | ||
void main() { | ||
fragmentColor = texture(fullscreenTexture, textureCoordinates); | ||
} | ||
)"; | ||
|
||
GLProgram program{}; | ||
const GLShader vertexShader{{ShaderType::VERTEX}}; | ||
const GLShader fragmentShader{{ShaderType::FRAGMENT}}; | ||
|
||
vertexShader.compile(vertexShaderSource); | ||
fragmentShader.compile(fragmentShaderSource); | ||
program.attachShader(vertexShader.getHandle()); | ||
program.attachShader(fragmentShader.getHandle()); | ||
|
||
EXPECT_FALSE(program.link()); | ||
} |