Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOX-76] add GLBuffer unit tests #166

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/nox/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nox/format.h>

#include <cstdint>
#include <vector>

namespace nox {

Expand Down
2 changes: 0 additions & 2 deletions include/nox/format.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <vector>

namespace nox {

enum class ImageFormat {
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ endif()
# --------------------------------------------------
set(NOX_UNIT_TESTS_OPENGL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_context_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_program_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gl_shader_tests.cpp
Expand Down
40 changes: 40 additions & 0 deletions tests/unit_tests/opengl/gl_buffer_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "src/opengl/gl_buffer.h"
#include "src/opengl/gl_vertex_array.h"

#include "tests/base/opengl/gl_test_environment.h"

#include <glad/gl.h>
#include <gtest/gtest.h>

using namespace nox;

struct GLBufferFixture : public tests::GLTestFixture {
struct Vertex {
float position[2];
float textureCoordinates[2];
};
static constexpr Vertex vertices[]{
{{0.5f, 0.5f}, {1.0f, 1.0f}}, // top right
{{0.5f, -0.5f}, {1.0f, 0.0f}}, // bottom right
{{-0.5f, -0.5f}, {0.0f, 0.0f}}, // bottom left
{{-0.5f, 0.5f}, {0.0f, 1.0f}}, // top left
};

static constexpr uint32_t indices[]{0, 1, 3,
1, 2, 3};
};

TEST_F(GLBufferFixture, GivenValidVertexBufferDescriptorWhenCallingCreateVertexBufferThenVertexBufferIsSuccessfullyCreated) {
auto vertexArrayRegistry = GLVertexArrayRegistry::create();

VertexBufferDescriptor vertexBufferDescriptor{};
vertexBufferDescriptor.usage = BufferUsage::STATIC;
vertexBufferDescriptor.size = sizeof(vertices);
vertexBufferDescriptor.data = vertices;
vertexBufferDescriptor.vertexAttributes = {
VertexAttributeFormat::RG32F,
VertexAttributeFormat::RG32F,
};
auto vertexBuffer = GLVertexBuffer::create(vertexBufferDescriptor, vertexArrayRegistry);
ASSERT_NE(nullptr, vertexBuffer);
}