Skip to content

Commit

Permalink
[OpenGL][Program] check macro to throw no_ogl
Browse files Browse the repository at this point in the history
  • Loading branch information
mqcmd196 committed Aug 30, 2024
1 parent ff9a0ec commit a702432
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/core/src/opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,11 +1407,20 @@ void cv::ogl::Arrays::bind() const

cv::ogl::Program::Program()
{
#ifndef HAVE_OPENGL
throw_no_ogl();
#else
program_ = gl::CreateProgram();
#endif
}

void cv::ogl::Program::attachShaders(const std::string& fragment_shader_source, const std::string& vertex_shader_source)
{
#ifndef HAVE_OPENGL
CV_UNUSED(fragment_shader_source);
CV_UNUSED(vertex_shader_source);
throw_no_ogl();
#else
GLuint fragment_shader = gl::CreateShader(gl::FRAGMENT_SHADER);
GLuint vertex_shader = gl::CreateShader(gl::VERTEX_SHADER);
const char* fragment_source = fragment_shader_source.c_str();
Expand All @@ -1424,10 +1433,14 @@ void cv::ogl::Program::attachShaders(const std::string& fragment_shader_source,
gl::AttachShader(program_, vertex_shader);
gl::LinkProgram(program_);
gl::UseProgram(program_);
#endif
};

std::string cv::ogl::Program::getDefaultFragmentShader()
{
#ifndef HAVE_OPENGL
throw_no_ogl();
#else
return
"#version 330 core\n"
"in vec2 TexCoord;\n"
Expand All @@ -1436,10 +1449,14 @@ std::string cv::ogl::Program::getDefaultFragmentShader()
"void main() {\n"
" color = texture(ourTexture, TexCoord);\n"
"}\n";
#endif
}

std::string cv::ogl::Program::getDefaultVertexShader()
{
#ifndef HAVE_OPENGL
throw_no_ogl()
#else
return
"#version 330 core\n"
"layout (location = 0) in vec3 position;\n"
Expand All @@ -1450,11 +1467,16 @@ std::string cv::ogl::Program::getDefaultVertexShader()
" gl_Position = transform * vec4(position, 1.0);\n"
" TexCoord = texCoord;\n"
"}\n";
#endif
}

unsigned int cv::ogl::Program::getProgramId()
{
#ifndef HAVE_OPENGL
throw_no_ogl()
#else
return program_;
#endif
}

////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit a702432

Please sign in to comment.