NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/sources/libs/ds3d/glprocess/gl_program.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef DS3D_GLPROCESS_GL_PROGRAM_H
19 #define DS3D_GLPROCESS_GL_PROGRAM_H
20 
21 #include "ds3d/common/common.h"
22 #include "ds3d/glprocess/gl_common.h"
23 
24 namespace ds3d { namespace gl {
25 
26 struct Shader {
27  GLuint v = 0;
28 
29  Shader() = default;
30  ~Shader() { reset(); }
31  ErrCode compile(const std::string& shaderStr, GLenum type);
32 
33  void reset(GLuint newVal = 0)
34  {
35  if (v) {
36  glDeleteShader(v);
37  }
38  v = newVal;
39  }
41  {
42  reset(o.v);
43  o.v = 0;
44  }
45 
47 };
48 
49 class Program {
50  GLuint _val = 0;
51  DS3D_DISABLE_CLASS_COPY(Program);
52 
53 public:
54  Program() = default;
55  ~Program() { reset(); }
57  {
58  reset();
59  _val = o._val;
60  o._val = 0;
61  }
62  ErrCode create();
63  ErrCode link(const std::vector<Shader>& shaders);
64  bool isValid() const;
65 
66  int uniformLocation(const std::string& name)
67  {
68  DS_ASSERT(get());
69  return glGetUniformLocation(get(), name.c_str());
70  }
71  int attribLocation(const std::string& name)
72  {
73  DS_ASSERT(get());
74  return glGetAttribLocation(get(), name.c_str());
75  }
77  {
78  DS_ASSERT(get());
79  glUseProgram(get());
80  DS3D_RETURN_GL_ERROR("glUseProgram");
81  return ErrCode::kGood;
82  }
83 
85  {
86  glUseProgram(0);
87  DS3D_RETURN_GL_ERROR("gl closeProgram");
88  return ErrCode::kGood;
89  }
90 
91  GLuint get() const { return _val; }
92  void reset(GLuint newVal = 0)
93  {
94  if (_val) {
95  glDeleteProgram(_val);
96  }
97  _val = newVal;
98  }
99 };
100 
101 Program* BuildProgramFromSource(
102  const std::vector<std::string>& sources, const std::vector<GLenum>& types);
103 
104 }} // namespace ds3d::gl
105 
106 #endif // DS3D_GLPROCESS_GL_PROGRAM_H
ds3d::gl::Shader::v
GLuint v
Definition: sources/libs/ds3d/glprocess/gl_program.h:27
ds3d::gl::Program::Program
Program()=default
ds3d::gl::Program
Definition: sources/libs/ds3d/glprocess/gl_program.h:49
ds3d::gl::Program::useProgram
ErrCode useProgram()
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:76
ds3d::gl::Program::~Program
~Program()
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:55
ds3d::gl::Program::attribLocation
int attribLocation(const std::string &name)
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:71
ds3d::gl::Program::isValid
bool isValid() const
ds3d::ErrCode::kGood
@ kGood
ds3d::gl::Program::Program
Program(Program &&o)
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:56
ds3d::gl::Program::create
ErrCode create()
ds3d::gl::Shader::DS3D_DISABLE_CLASS_COPY
DS3D_DISABLE_CLASS_COPY(Shader)
ds3d::ErrCode
ErrCode
Definition: includes/ds3d/common/common.h:47
ds3d::gl::Shader::compile
ErrCode compile(const std::string &shaderStr, GLenum type)
ds3d::gl::Shader
Definition: sources/libs/ds3d/glprocess/gl_program.h:26
ds3d::gl::Shader::Shader
Shader()=default
ds3d::gl::Program::uniformLocation
int uniformLocation(const std::string &name)
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:66
ds3d::gl::Shader::~Shader
~Shader()
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:30
ds3d::gl::Shader::Shader
Shader(Shader &&o)
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:40
ds3d::gl::BuildProgramFromSource
Program * BuildProgramFromSource(const std::vector< std::string > &sources, const std::vector< GLenum > &types)
ds3d::gl::Shader::reset
void reset(GLuint newVal=0)
Definition: sources/libs/ds3d/glprocess/gl_program.h:33
DS3D_RETURN_GL_ERROR
#define DS3D_RETURN_GL_ERROR(fmt,...)
Definition: sources/libs/ds3d/glprocess/gl_common.h:56
ds3d
Definition: includes/ds3d/common/abi_dataprocess.h:25
ds3d::gl::Program::link
ErrCode link(const std::vector< Shader > &shaders)
ds3d::gl::Program::get
GLuint get() const
Definition: sources/libs/ds3d/glprocess/gl_program.h:91
DS_ASSERT
#define DS_ASSERT(...)
Definition: includes/ds3d/common/defines.h:36
ds3d::gl::Program::closeProgram
ErrCode closeProgram()
Definition: 9.2/sources/libs/ds3d/glprocess/gl_program.h:84
ds3d::gl::Program::reset
void reset(GLuint newVal=0)
Definition: sources/libs/ds3d/glprocess/gl_program.h:92