-
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
041cfbc
commit c50f920
Showing
8 changed files
with
176 additions
and
37 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
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,89 @@ | ||
#include "src/opengl/gl_context.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 GLShaderFixture : 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(GLShaderFixture, GivenValidShaderDescriptorAndSourceWhenCallingCreateShaderThenShaderIsSuccessfullyCreated) { | ||
using TestParams = std::array<std::pair<ShaderType, GLenum>, static_cast<size_t>(ShaderType::MAX) - 1>; | ||
constexpr TestParams testParams{{ | ||
{ShaderType::VERTEX, GL_VERTEX_SHADER}, | ||
{ShaderType::FRAGMENT, GL_FRAGMENT_SHADER}, | ||
{ShaderType::TESS_CONTROL, GL_TESS_CONTROL_SHADER}, | ||
{ShaderType::TESS_EVALUATION, GL_TESS_EVALUATION_SHADER}, | ||
{ShaderType::GEOMETRY, GL_GEOMETRY_SHADER}, | ||
{ShaderType::COMPUTE, GL_COMPUTE_SHADER}, | ||
}}; | ||
constexpr auto shaderSource = R"( | ||
#version 460 core | ||
void main() {} | ||
)"; | ||
|
||
for (const auto &[shaderType, expectedShaderType] : testParams) { | ||
ShaderDescriptor shaderDescriptor{}; | ||
shaderDescriptor.type = shaderType; | ||
|
||
const auto shader = GLShader::create(shaderDescriptor, shaderSource); | ||
ASSERT_NE(nullptr, shader); | ||
|
||
GLint glShaderType = GL_NONE; | ||
glGetShaderiv(shader->getHandle(), GL_SHADER_TYPE, &glShaderType); | ||
|
||
EXPECT_NE(0u, shader->getHandle()); | ||
EXPECT_EQ(shaderType, shader->getType()); | ||
EXPECT_EQ(expectedShaderType, glShaderType); | ||
} | ||
} | ||
|
||
TEST_F(GLShaderFixture, GivenInvalidShaderDescriptorWhenCallingCreateShaderThenNullptrIsReturned) { | ||
constexpr auto shaderSource = R"( | ||
#version 460 core | ||
void main() {} | ||
)"; | ||
|
||
ShaderDescriptor shaderDescriptor{}; | ||
shaderDescriptor.type = ShaderType::NONE; | ||
|
||
const auto shader = GLShader::create(shaderDescriptor, shaderSource); | ||
EXPECT_EQ(nullptr, shader); | ||
} | ||
|
||
TEST_F(GLShaderFixture, GivenInvalidShaderSourceWhenCallingCreateShaderThenNullptrIsReturned) { | ||
constexpr auto shaderSource = R"( | ||
#version 460 core | ||
main() {} | ||
)"; | ||
|
||
ShaderDescriptor shaderDescriptor{}; | ||
shaderDescriptor.type = ShaderType::VERTEX; | ||
|
||
const auto shader = GLShader::create(shaderDescriptor, shaderSource); | ||
EXPECT_EQ(nullptr, shader); | ||
} |