Tests: Add a simple LibGL render-test
At the moment we just check if we *can* render a simple triangle, we do not yet actually test if the image is indeed the triangle we wanted. This test also outputs the rendered image when GL_DEBUG is enabled to a file called "picture.bmp" for manual verification. Co-authored-by: sunverwerth <s.unverwerth@serenityos.org>
This commit is contained in:
parent
3a4dd5ff87
commit
7a27ecc135
Notes:
sideshowbarker
2024-07-17 23:23:22 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/7a27ecc1352 Pull-request: https://github.com/SerenityOS/serenity/pull/11118 Reviewed-by: https://github.com/alimpfard ✅ Reviewed-by: https://github.com/sunverwerth ✅
4 changed files with 74 additions and 0 deletions
|
@ -520,6 +520,12 @@ if (BUILD_LAGOM)
|
|||
lagom_test(${source} LIBS LagomCompress)
|
||||
endforeach()
|
||||
|
||||
# GL
|
||||
file(GLOB LIBGL_TESTS CONFIGURE_DEPENDS "../../Tests/LibGL/*.cpp")
|
||||
foreach(source ${LIBGL_TESTS})
|
||||
lagom_test(${source} LIBS LagomGL)
|
||||
endforeach()
|
||||
|
||||
# Regex
|
||||
file(GLOB LIBREGEX_TESTS CONFIGURE_DEPENDS "../../Tests/LibRegex/*.cpp")
|
||||
# RegexLibC test POSIX <regex.h> and contains many Serenity extensions
|
||||
|
|
|
@ -6,6 +6,7 @@ add_subdirectory(LibCore)
|
|||
add_subdirectory(LibCpp)
|
||||
add_subdirectory(LibELF)
|
||||
add_subdirectory(LibGfx)
|
||||
add_subdirectory(LibGL)
|
||||
add_subdirectory(LibIMAP)
|
||||
add_subdirectory(LibJS)
|
||||
add_subdirectory(LibM)
|
||||
|
|
7
Tests/LibGL/CMakeLists.txt
Normal file
7
Tests/LibGL/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
set(TEST_SOURCES
|
||||
TestRender.cpp
|
||||
)
|
||||
|
||||
foreach(source IN LISTS TEST_SOURCES)
|
||||
serenity_test("${source}" LibGL LIBS LibGL)
|
||||
endforeach()
|
60
Tests/LibGL/TestRender.cpp
Normal file
60
Tests/LibGL/TestRender.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/Format.h>
|
||||
#include <LibGL/GL/gl.h>
|
||||
#include <LibGL/GLContext.h>
|
||||
#include <LibGfx/BMPWriter.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define RENDER_WIDTH 16
|
||||
#define RENDER_HEIGHT 16
|
||||
|
||||
TEST_CASE(simple_triangle)
|
||||
{
|
||||
auto bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, { RENDER_WIDTH, RENDER_HEIGHT }));
|
||||
auto context = GL::create_context(*bitmap);
|
||||
|
||||
GL::make_context_current(context);
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearDepth(1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glVertex2f(0, 1);
|
||||
glVertex2f(-1, -1);
|
||||
glVertex2f(1, -1);
|
||||
glEnd();
|
||||
|
||||
context->present();
|
||||
|
||||
EXPECT_EQ(glGetError(), 0u);
|
||||
// FIXME: Verify that the image is indeed correct
|
||||
|
||||
if constexpr (GL_DEBUG) {
|
||||
// output the image to manually verify that the output is correct
|
||||
Gfx::BMPWriter writer {};
|
||||
auto buffer = writer.dump(bitmap);
|
||||
int fd = open("./picture.bmp", O_CREAT | O_WRONLY, 0755);
|
||||
EXPECT(fd > 0);
|
||||
ssize_t nwritten = write(fd, buffer.data(), buffer.size());
|
||||
EXPECT_EQ((size_t)nwritten, buffer.size());
|
||||
close(fd);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue