Skip to content

Commit

Permalink
[NOX-76] add GLBuffer unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rafal Maziejuk <[email protected]>
  • Loading branch information
rafalmaziejuk committed Jun 22, 2024
1 parent b24494a commit fe6fb48
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
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 include/nox/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class NOX_EXPORT Texture {

[[nodiscard]] virtual TextureType getType() const = 0;
[[nodiscard]] virtual ImageFormat getFormat() const = 0;
[[nodiscard]] virtual Vector3D<uint32_t> getSize() const = 0;

public:
Texture(const Texture &) = delete;
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);
}

0 comments on commit fe6fb48

Please sign in to comment.