Skip to content

glm::faceforward<vecType> specialization missing. #289

@bcrist

Description

@bcrist

In 0.9.6.1, when faceforward is used with a vector type, it results in the following error under Visual Studio 2015:

error C2677: binary '<': no global operator found which takes type 'glm::tvec2<float,0>' (or there is no acceptable conversion)

This seems to be because dot returns a scalar, which is then compared to a vector. For example, the instantiation of faceforward<vec2> is equivalent to:

vec2 faceforward(vec2 const & N, vec2 const & I, vec2 const & Nref) {
    return dot(Nref, I) < static_cast<vec2>(0) ? N : -N;
}

Adding a faceforward specialization for vector types in func_geometric.inl fixes this error. The key difference being, we need to cast 0 to T instead of genType:

template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> faceforward(vecType<T, P> const & N, vecType<T, P> const & I, vecType<T, P> const & Nref)
{
    return dot(Nref, I) < static_cast<T>(0) ? N : -N;
}

Perhaps there may be a more succinct solution if there is something like the following already implemented (I don't know GLM internals well enough to know)

template <typename genType>
struct GetValueType {
    typedef genType value_type;
};
template <typename T, precision P, template <typename, precision> class vecType>
struct GetValueType<vecType<T, P>> {
    typedef T value_type;
};

In which case the existing faceforward implementation can simply be changed to use static_cast<typename GetValueType<genType>::value_type>(0).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions