NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/ds3d/glprocess/gl_helper.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_HELPER_H
19 #define DS3D_GLPROCESS_GL_HELPER_H
20 
21 #include "ds3d/common/common.h"
22 #include "ds3d/common/hpp/obj.hpp"
23 
24 #include "ds3d/glprocess/gl_common.h"
25 #include <glm/glm.hpp>
26 #include <glm/gtc/matrix_transform.hpp>
27 #include <glm/gtc/type_ptr.hpp>
28 
29 namespace ds3d { namespace gl {
30 
31 inline mat4f
33 {
34  mat4f ret;
35  ret.resize(4, {{0.0f, 0.0f, 0.0f, 0.0f}});
36  ret[0].data[0] = 1.0f;
37  ret[1].data[1] = 1.0f;
38  ret[2].data[2] = 1.0f;
39  ret[3].data[3] = 1.0f;
40  DS_ASSERT(ret.size() == 4);
41  return ret;
42 }
43 
44 inline mat4f
45 glmMat4ToDS(const glm::mat4& m)
46 {
47  mat4f ret(4);
48  memcpy(&ret[0], glm::value_ptr(m), sizeof(float) * 16);
49  DS_ASSERT(ret.size() == 4);
50  return ret;
51 }
52 
53 inline glm::mat4
54 dsMat4ToGlm(const mat4f& m)
55 {
56  DS_ASSERT(m.size() == 4);
57  glm::mat4 ret(1.0f);
58  memcpy(glm::value_ptr(ret), &m[0], sizeof(float) * 16);
59  return ret;
60 }
61 
62 inline glm::vec3
63 vec3ToGlm(const vec3f& m)
64 {
65  glm::vec3 ret(0.0f);
66  memcpy(glm::value_ptr(ret), &m, sizeof(vec3f));
67  return ret;
68 }
69 
70 inline mat4f
71 mvpMat(const mat4f& model, const mat4f& view, const mat4f& project)
72 {
73  glm::mat4 m = glm::make_mat4<float>((const float*)&model[0]);
74  glm::mat4 v = glm::make_mat4<float>((const float*)&view[0]);
75  glm::mat4 p = glm::make_mat4<float>((const float*)&project[0]);
76  return glmMat4ToDS(p * v * m);
77 }
78 
79 inline mat4f
80 mat4Mul(const mat4f& a, const mat4f& b)
81 {
82  DS_ASSERT(a.size() >= 4 && b.size() >= 4);
83  glm::mat4 gA = glm::make_mat4<float>((const float*)&a[0]);
84  glm::mat4 gB = glm::make_mat4<float>((const float*)&b[0]);
85  return glmMat4ToDS(gA * gB);
86 }
87 
88 }} // namespace ds3d::gl
89 
90 #endif // DS3D_GLPROCESS_GL_HELPER_H
ds3d::gl::dsMat4ToGlm
glm::mat4 dsMat4ToGlm(const mat4f &m)
Definition: sources/libs/ds3d/glprocess/gl_helper.h:54
ds3d::__xyz
Definition: includes/ds3d/common/idatatype.h:39
ds3d::vec3
__xyz< T > vec3
Definition: includes/ds3d/common/idatatype.h:65
ds3d::gl::mat4f
std::vector< vec4f > mat4f
Definition: sources/libs/ds3d/glprocess/gl_common.h:60
ds3d::gl::mat4Mul
mat4f mat4Mul(const mat4f &a, const mat4f &b)
Definition: sources/libs/ds3d/glprocess/gl_helper.h:80
ds3d::gl::mvpMat
mat4f mvpMat(const mat4f &model, const mat4f &view, const mat4f &project)
Definition: sources/libs/ds3d/glprocess/gl_helper.h:71
ds3d::gl::vec3ToGlm
glm::vec3 vec3ToGlm(const vec3f &m)
Definition: sources/libs/ds3d/glprocess/gl_helper.h:63
ds3d::gl::glmMat4ToDS
mat4f glmMat4ToDS(const glm::mat4 &m)
Definition: sources/libs/ds3d/glprocess/gl_helper.h:45
ds3d::gl::eye4x4
mat4f eye4x4()
Definition: sources/libs/ds3d/glprocess/gl_helper.h:32
ds3d
Definition: includes/ds3d/common/abi_dataprocess.h:25
DS_ASSERT
#define DS_ASSERT(...)
Definition: includes/ds3d/common/defines.h:36