add dimensions and type functions to attributes class
This commit is contained in:
parent
64f6b765a7
commit
3baaa7624e
|
@ -19,7 +19,7 @@
|
|||
* 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)
|
||||
void sb::Attributes::index(GLuint index)
|
||||
{
|
||||
attribute_index = index;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ void sb::Attributes::index(std::uint32_t index)
|
|||
* 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
|
||||
GLuint sb::Attributes::index() const
|
||||
{
|
||||
return attribute_index;
|
||||
}
|
||||
|
@ -66,6 +66,74 @@ std::size_t sb::Attributes::size() const
|
|||
}, vertices);
|
||||
}
|
||||
|
||||
/* Return the GLenum that corresponds to the type of scalar being held in the vertices. This
|
||||
* will return either GL_FLOAT, GL_INT, GL_UNSIGNED_INT, GL_UNSIGNED_BYTE, GL_BOOL, or
|
||||
* GL_INVALID_ENUM. A return value of GL_INVALID_ENUM indicates an error meaning there are no
|
||||
* attributes and no type exists yet. */
|
||||
GLenum sb::Attributes::type() const
|
||||
{
|
||||
return std::visit([] (const auto& vector) -> GLenum {
|
||||
using VectorType = std::decay_t<decltype(vector)>;
|
||||
/* omit size check for the monostate (uninitialized attributes) variant */
|
||||
if constexpr (!std::is_same_v<VectorType, std::monostate>)
|
||||
{
|
||||
using VertexType = typename VectorType::value_type;
|
||||
/* For 1D vertices, the vertex type will be scalar */
|
||||
if constexpr (std::is_scalar_v<VertexType>)
|
||||
{
|
||||
using ScalarType = VertexType;
|
||||
if constexpr (std::is_floating_point_v<ScalarType>) return GL_FLOAT;
|
||||
else if constexpr (std::is_unsigned_v<ScalarType>)
|
||||
{
|
||||
if constexpr (sizeof(ScalarType) > 8) return GL_UNSIGNED_INT;
|
||||
else return GL_UNSIGNED_BYTE;
|
||||
}
|
||||
else return GL_INT;
|
||||
}
|
||||
/* For dimensions greater than 1, the scalar type will be the value_type of the vertex type */
|
||||
else
|
||||
{
|
||||
using ScalarType = typename VertexType::value_type;
|
||||
if constexpr (std::is_floating_point_v<ScalarType>) return GL_FLOAT;
|
||||
else if constexpr (std::is_unsigned_v<ScalarType>)
|
||||
{
|
||||
if constexpr (sizeof(ScalarType) > 1) return GL_UNSIGNED_INT;
|
||||
else return GL_BOOL;
|
||||
}
|
||||
else return GL_INT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GL_INVALID_ENUM;
|
||||
}
|
||||
}, vertices);
|
||||
}
|
||||
|
||||
/* Return the number of dimensions in the vertices. If there are no vertices, return 0. */
|
||||
std::size_t sb::Attributes::dimensions() const
|
||||
{
|
||||
return std::visit([] (const auto& vector) -> std::size_t {
|
||||
using VectorType = std::decay_t<decltype(vector)>;
|
||||
if constexpr (!std::is_same_v<VectorType, std::monostate>)
|
||||
{
|
||||
using VertexType = typename VectorType::value_type;
|
||||
if constexpr (std::is_scalar_v<VertexType>)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VertexType::length();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}, vertices);
|
||||
}
|
||||
|
||||
/* Returns a pointer to the first vertex in the object's underlying vector of vertices. This can be used
|
||||
* along with the size function to pass the raw bytes of the vertices to the GPU. */
|
||||
sb::Attributes::operator const void*() const
|
||||
|
|
|
@ -87,15 +87,19 @@
|
|||
#ifndef SB_ATTRIBUTES_H_
|
||||
#define SB_ATTRIBUTES_H_
|
||||
|
||||
#include <any>
|
||||
/* include Open GL */
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#include <GL/glew.h>
|
||||
#else
|
||||
#include "glew/glew.h"
|
||||
#endif
|
||||
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
#include <initializer_list>
|
||||
#include <variant>
|
||||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include "glm/glm.hpp"
|
||||
#include "Log.hpp"
|
||||
#include "extension.hpp"
|
||||
|
@ -128,7 +132,7 @@ namespace sb
|
|||
std::vector<glm::bvec4>, std::vector<glm::uvec4>, std::vector<glm::ivec4>, std::vector<glm::vec4>
|
||||
>;
|
||||
Vertices vertices;
|
||||
std::uint32_t attribute_index = 0;
|
||||
GLuint attribute_index = 0;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -212,10 +216,12 @@ namespace sb
|
|||
|
||||
void extend(const Attributes&, std::size_t = 1);
|
||||
void index(std::uint32_t);
|
||||
std::uint32_t index() const;
|
||||
GLuint index() const;
|
||||
void enable() const;
|
||||
std::size_t size() const;
|
||||
std::size_t count() const;
|
||||
GLenum type() const;
|
||||
std::size_t dimensions() const;
|
||||
friend std::ostream& operator<<(std::ostream&, const Attributes&);
|
||||
operator const void*() const;
|
||||
|
||||
|
|
|
@ -10,17 +10,14 @@
|
|||
|
||||
[Log.hpp]
|
||||
|
||||
Log messages of specified priority to the SDL logging method, which is overridden in
|
||||
Log messages of specified priority through the SDL logging method, which is overridden in
|
||||
the Game class to write to stdout, file, or both, depending on the user's configuration
|
||||
settings.
|
||||
|
||||
The logging methods can be used statically, or the log object defined here can be used
|
||||
like a stream to stream messages to.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef Log_h_
|
||||
#define Log_h_
|
||||
#ifndef SB_LOG_H_
|
||||
#define SB_LOG_H_
|
||||
|
||||
/* include Open GL */
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
|
|
Loading…
Reference in New Issue