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

[OpenGL] Add OpenGL Program helper classes and functions for OpenGL >= 3.2 #26090

Open
wants to merge 12 commits into
base: 4.x
Choose a base branch
from

Conversation

mqcmd196
Copy link
Contributor

@mqcmd196 mqcmd196 commented Aug 30, 2024

This PR adds an OpenGL Program wrapper for supporting fragment and vertex shader required from OpenGL >= 3.2. I also edited the sample code and confirmed it worked in my environment.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

modules/core/include/opencv2/core/opengl.hpp Outdated Show resolved Hide resolved
modules/core/include/opencv2/core/opengl.hpp Outdated Show resolved Hide resolved
modules/core/include/opencv2/core/opengl.hpp Outdated Show resolved Hide resolved
@asmorkalov
Copy link
Contributor

@mqcmd196 Could you adapt existing opengl.cpp sample to GTK3 or we need more changes?

@asmorkalov
Copy link
Contributor

Implementation should be guarded as follows:

#ifndef HAVE_OPENGL
    throw_no_ogl();
#else
// impl itself
#endif

Otherwise it leads to complication issues.

@mqcmd196
Copy link
Contributor Author

Implementation should be guarded as follows:

#ifndef HAVE_OPENGL
throw_no_ogl();
#else
// impl itself
#endif
Otherwise it leads to complication issues.

Fixed in a702432

@mqcmd196
Copy link
Contributor Author

mqcmd196 commented Aug 30, 2024

Could you adapt existing opengl.cpp sample to GTK3 or we need more changes?

The existing samples/opengl/opengl.cpp is written in OpenGL v2.x. I think GTK3 and GTK4 dropped their support and only worked with OpenGL >= 3.2. (I'm sorry, but someone reported the issue somewhere, but I lost.)

@mqcmd196 mqcmd196 changed the title [OpenGL] Add OpenGL Program class for implementing shader used in OpenGL >= 3.2 [OpenGL] Add OpenGL Program helper classes and functions for OpenGL >= 3.2 Aug 30, 2024
@mqcmd196 mqcmd196 marked this pull request as draft August 30, 2024 08:42
@asmorkalov asmorkalov added the GSoC label Sep 4, 2024

const Ptr<cv::ogl::VertexArray::Impl> cv::ogl::VertexArray::Impl::empty()
{
static Ptr<Impl> p(new Impl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make_ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide more info?

modules/core/src/opengl.cpp Outdated Show resolved Hide resolved
@asmorkalov
Copy link
Contributor

FAILED: modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o 
/usr/bin/ccache /usr/bin/c++  -DCVAPI_EXPORTS -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int -DOPENCV_WITH_ITT=1 -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/ci/opencv/modules/core/include -Imodules/core -I/home/ci/opencv/3rdparty/include/opencl/1.2 -I/home/ci/opencv/3rdparty/ittnotify/include -isystem . -isystem /usr/include/eigen3 -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG -fPIC   -std=c++11 -MD -MT modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o -MF modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o.d -o modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o -c /home/ci/opencv/modules/core/src/opengl.cpp
/home/ci/opencv/modules/core/src/opengl.cpp:826:16: error: redefinition of 'class cv::ogl::VertexArray'
  826 | class cv::ogl::VertexArray
      |                ^~~~~~~~~~~
In file included from /home/ci/opencv/modules/core/src/precomp.hpp:56,
                 from /home/ci/opencv/modules/core/src/opengl.cpp:43:
/home/ci/opencv/modules/core/include/opencv2/core/opengl.hpp:281:18: note: previous definition of 'class cv::ogl::VertexArray'
  281 | class CV_EXPORTS VertexArray

@mqcmd196 mqcmd196 marked this pull request as ready for review September 21, 2024 01:56
@asmorkalov asmorkalov self-assigned this Sep 23, 2024
@asmorkalov asmorkalov added this to the 4.11.0 milestone Sep 23, 2024

void setAutoRelease(bool flag);

void vertexAttribPointer(InputArray arr, unsigned int index, int size, int stride, int offset) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stride should be in bytes. It's implemented for the case if structure is heterogeneous or larger than just shader input data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like void vertexAttribPointer(InputArray arr, unsigned int index, int size, unsigned char stride, int offset) const; ??

Comment on lines +571 to +574
/////////////////// Export to Graphic device ///////////////////

CV_EXPORTS void uniformMatrix4fv(int location, int count, float* value);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to make it a method of Program class. Also it makes sense to add methods with integer as location and a string as location name.


/** @brief Wrapper for OpenGL 3.2 Program object
*/
class CV_EXPORTS Program{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to refactor it to Pimpl and hide program_ from public interface.

@mqcmd196 mqcmd196 force-pushed the PR/opengl_shader_wrapper branch from bdf8169 to 1c25ef8 Compare September 24, 2024 02:00
@mqcmd196
Copy link
Contributor Author

FAILED: modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o
/usr/bin/ccache /usr/bin/c++ -DCVAPI_EXPORTS -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int -DOPENCV_WITH_ITT=1 -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/ci/opencv/modules/core/include -Imodules/core -I/home/ci/opencv/3rdparty/include/opencl/1.2 -I/home/ci/opencv/3rdparty/ittnotify/include -isystem . -isystem /usr/include/eigen3 -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -fPIC -std=c++11 -MD -MT modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o -MF modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o.d -o modules/core/CMakeFiles/opencv_core.dir/src/opengl.cpp.o -c /home/ci/opencv/modules/core/src/opengl.cpp
/home/ci/opencv/modules/core/src/opengl.cpp:826:16: error: redefinition of 'class cv::ogl::VertexArray'
826 | class cv::ogl::VertexArray
| ^~~~~~~~~~~
In file included from /home/ci/opencv/modules/core/src/precomp.hpp:56,
from /home/ci/opencv/modules/core/src/opengl.cpp:43:
/home/ci/opencv/modules/core/include/opencv2/core/opengl.hpp:281:18: note: previous definition of 'class cv::ogl::VertexArray'
281 | class CV_EXPORTS VertexArray

1c25ef8

@asmorkalov asmorkalov modified the milestones: 4.11.0, 4.12.0 Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants