add index to attributes class

This commit is contained in:
frank 2021-10-14 00:31:35 -04:00
parent 1690bb5f19
commit 64f6b765a7
4 changed files with 42 additions and 16 deletions

View File

@ -10,6 +10,29 @@
#include "Attributes.hpp"
/* Set the generic vertex attribute index for the attributes. It must be the same index that is
* returned when glGetAttribLocation is given the shader program and variable name the attributes
* will be associated with. This index may be specified in the shader source code using the location
* layout qualifier in GLSL 3.3 and above. It can also be set automatically by OpenGL when a shader
* program is linked. In both cases, the return value of glGetAttribLocation should be passed to
* this function. Otherwise, this index can be an arbitrary choice that is not greater than
* GL_MAX_VERTEX_ATTRIBS, in which case it would be explicitly passed to glBindAttribLocation. It
* can then be passed to glVertexAttribPointer to set the properties of the attributes on the
* GPU. */
void sb::Attributes::index(std::uint32_t index)
{
attribute_index = index;
}
/* Returns the generic vertex attribute index for the attributes. This index can be passed to
* glBindAttribLocation to assign the index to a shader input variable if the index isn't already
* assigned by a layout qualifier in the GLSL source code. The index should be passed to
* glVertexAttribPointer to specify the location to use when rendering. */
std::uint32_t sb::Attributes::index() const
{
return attribute_index;
}
/* Returns the count of attributes */
std::size_t sb::Attributes::count() const
{

View File

@ -116,15 +116,19 @@ namespace sb
private:
/* Every type of vertex in the glm vertex types (bool, unsigned int, int, float) from 1D to 4D is included in this variant.
* Each variant alternative is a vector of vertex type, so only homogenous vectors can be used. Index 0 is the std::monospace
* alternative, which is used to default initialize Attributes to an empty state where no variant alternative is selected.
* 1D vertices are specified by vectors of scalars, rather than the 1D glm vertex types. The std::vector<bool> alternative is
* not included because its specialization doesn't include a data member function */
using Vertices = std::variant<std::monostate, std::vector<std::uint32_t>, std::vector<std::int32_t>, std::vector<float>,
std::vector<glm::bvec2>, std::vector<glm::uvec2>, std::vector<glm::ivec2>, std::vector<glm::vec2>,
std::vector<glm::bvec3>, std::vector<glm::uvec3>, std::vector<glm::ivec3>, std::vector<glm::vec3>,
std::vector<glm::bvec4>, std::vector<glm::uvec4>, std::vector<glm::ivec4>, std::vector<glm::vec4>>;
* Each variant alternative is a vector of vertex type, so only homogenous vectors can be used. Index 0 is the std::monostate
* alternative, which is used here for default initialization to indicate Attributes are in an empty state where no variant
* alternative is selected. 1D vertices are specified by vectors of scalars, rather than the 1D glm vertex types. 1D vertices
* also include an unsigned byte type. The std::vector<bool> alternative is not included because its specialization doesn't
* include a data member function. */
using Vertices = std::variant<
std::monostate, std::vector<std::uint8_t>, std::vector<std::uint32_t>, std::vector<std::int32_t>, std::vector<float>,
std::vector<glm::bvec2>, std::vector<glm::uvec2>, std::vector<glm::ivec2>, std::vector<glm::vec2>,
std::vector<glm::bvec3>, std::vector<glm::uvec3>, std::vector<glm::ivec3>, std::vector<glm::vec3>,
std::vector<glm::bvec4>, std::vector<glm::uvec4>, std::vector<glm::ivec4>, std::vector<glm::vec4>
>;
Vertices vertices;
std::uint32_t attribute_index = 0;
public:
@ -207,8 +211,8 @@ namespace sb
}
void extend(const Attributes&, std::size_t = 1);
void index(int);
int index() const;
void index(std::uint32_t);
std::uint32_t index() const;
void enable() const;
std::size_t size() const;
std::size_t count() const;

View File

@ -263,7 +263,6 @@ GLuint Game::load_shader(const fs::path& path, GLenum type) const
std::ostringstream message;
std::string contents = sb::file_to_string(path);
glShaderSource(shader, 1, reinterpret_cast<const GLchar**>(&contents), 0);
// glShaderSource(shader, 1, const_cast<const GLchar**>(&buf), 0);
glCompileShader(shader);
GLint is_compiled;
glGetShaderiv(shader, GL_COMPILE_STATUS, &is_compiled);

View File

@ -26,7 +26,7 @@ void sb::Log::log(const std::ostringstream& message, const Level level, const in
}
/* Log all GL errors accumulated since the last time this function was called */
bool sb::Log::gl_errors(const std::string& suffix)
bool sb::Log::gl_errors(const std::string& heading)
{
GLenum error;
bool error_logged = false;
@ -34,6 +34,10 @@ bool sb::Log::gl_errors(const std::string& suffix)
{
error_logged = true;
std::ostringstream message;
if (!heading.empty())
{
message << heading << ": ";
}
if (error == GL_INVALID_ENUM)
{
message << "GL_INVALID_ENUM, an unacceptable value is specified for an enumerated argument";
@ -64,10 +68,6 @@ bool sb::Log::gl_errors(const std::string& suffix)
message << "GL_STACK_OVERFLOW, an attempt has been made to perform an operation that would " <<
"cause an internal stack to overflow";
}
if (!suffix.empty())
{
message << " " << suffix;
}
log(message);
}
return error_logged;