mirror of
https://github.com/opencv/opencv.git
synced 2026-09-11 21:01:33 -05:00
Core, Highgui: OpenGL wrappers & window free-callback API #29485 This PR is a continuation of the work started in [20371](https://github.com/opencv/opencv/pull/20371) ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
// Copyright (C) 2026, BigVision LLC, all rights reserved.
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
#include "test_precomp.hpp"
|
|
#include <opencv2/core/opengl.hpp>
|
|
|
|
namespace opencv_test { namespace {
|
|
|
|
using namespace cv;
|
|
|
|
// ogl wrappers need a current GL context; skip when none is available (headless CI).
|
|
static void ensureGlContext(const String& w)
|
|
{
|
|
try
|
|
{
|
|
namedWindow(w, WINDOW_OPENGL);
|
|
if (getWindowProperty(w, WND_PROP_OPENGL) <= 0)
|
|
throw cvtest::SkipTestException("window created without an OpenGL context");
|
|
setOpenGlContext(w);
|
|
}
|
|
catch (const cv::Exception&)
|
|
{
|
|
throw cvtest::SkipTestException("OpenGL/display not available");
|
|
}
|
|
}
|
|
|
|
// A grown sole-owner buffer must keep the same GL id (in-place resize).
|
|
TEST(OpenGL_Buffer, resize_keeps_id)
|
|
{
|
|
const String w = "ogl_buf_test";
|
|
ensureGlContext(w);
|
|
|
|
ogl::Buffer buf;
|
|
buf.create(4, 3, CV_32F, ogl::Buffer::ARRAY_BUFFER, false);
|
|
unsigned int id1 = buf.bufId();
|
|
EXPECT_NE(id1, 0u);
|
|
|
|
buf.create(16, 3, CV_32F, ogl::Buffer::ARRAY_BUFFER, false); // grow -> resize in place
|
|
EXPECT_EQ(buf.bufId(), id1);
|
|
|
|
destroyWindow(w);
|
|
}
|
|
|
|
// Shader compile + type().
|
|
TEST(OpenGL_Shader, compile_and_type)
|
|
{
|
|
const String w = "ogl_shader_test";
|
|
ensureGlContext(w);
|
|
|
|
const char* vs = "#version 330 core\nvoid main(){ gl_Position = vec4(0.0); }";
|
|
ogl::Shader sh(vs, ogl::Shader::VERTEX, false);
|
|
EXPECT_NE(sh.shaderId(), 0u);
|
|
EXPECT_EQ(sh.type(), ogl::Shader::VERTEX);
|
|
|
|
destroyWindow(w);
|
|
}
|
|
|
|
}} // namespace
|