Debian Codegraph @

Sources/nCine/Graphics/RHI/GL/GLAttribute.h

raw
1 #pragma once
2
3 #ifndef DOXYGEN_GENERATING_OUTPUT
4 #define NCINE_INCLUDE_OPENGL
5 #include "../../../CommonHeaders.h"
6 #endif
7
8 #include "../../../../Main.h"
9
10 namespace nCine::RHI::GL
11 {
12 /**
13 @brief Stores information about an active vertex shader attribute
14
15 Queried from a linked shader program with `glGetActiveAttrib()`, this holds the attribute's
16 location, size, GL type and name. Attributes with a reserved `gl_` prefix are skipped and keep
17 a location of -1.
18 */
19 class GLAttribute
20 {
21 public:
22 GLAttribute();
23 GLAttribute(GLuint program, GLuint index);
24 /** @brief Creates an attribute from offline reflection data, querying only the location */
25 GLAttribute(GLuint program, const char* name, GLenum type);
26
27 /** @brief Returns the attribute location, or -1 if it has no location */
28 inline GLint GetLocation() const {
29 return _location;
30 }
31 /** @brief Returns the number of components for array attributes (1 for non-array attributes) */
32 inline GLint GetSize() const {
33 return _size;
34 }
35 /** @brief Returns the GL type of the attribute (e.g., `GL_FLOAT_VEC4`) */
36 inline GLenum GetType() const {
37 return _type;
38 }
39 /** @brief Returns the attribute name */
40 inline const char* GetName() const {
41 return _name;
42 }
43 /**
44 * @brief Returns the basic GL type underlying the attribute type
45 *
46 * Maps a composite type to its scalar component type, e.g., `GL_FLOAT_VEC4` to `GL_FLOAT`.
47 */
48 GLenum GetBasicType() const;
49 /**
50 * @brief Returns the number of components in the attribute type
51 *
52 * For example, 4 for `GL_FLOAT_VEC4` and 1 for a scalar type.
53 */
54 std::int32_t GetComponentCount() const;
55
56 /** @brief Returns `true` if the attribute name starts with the reserved `gl_` prefix */
57 bool HasReservedPrefix() const;
58
59 private:
60 GLint _location;
61 GLint _size;
62 GLenum _type;
63 static constexpr std::int32_t MaxNameLength = 32;
64 char _name[MaxNameLength];
65 };
66
67 }