c++ - Unpack 4 bytes out of int in GLSL -
i have following vertex shader:
#version 330 core struct bone { int parent; float scale; mat4 matrix; }; uniform mat4 mvp; uniform bone[67] bones; layout(location = 0) in vec3 position; layout(location = 1) in int boneindex; layout(location = 2) in vec4 weight; layout(location = 3) in vec3 normal; layout(location = 4) in vec2 uvcords; out vec2 uv; void main() { gl_position = mvp * vec4(position, 1.0f); uv = uvcords; }
which fill (c++):
glvertexattribpointer(0, 3, gl_float, gl_false, sizeof(vertex), (void*)0); //float position[3] glvertexattribpointer(1, 1, gl_int, gl_false, sizeof(vertex), (void*)12); //char boneindex[4] glvertexattribpointer(2, 4, gl_float, gl_false, sizeof(vertex), (void*)16); //float weights[4] glvertexattribpointer(3, 3, gl_float, gl_false, sizeof(vertex), (void*)32); //float normals[3] glvertexattribpointer(4, 2, gl_float, gl_false, sizeof(vertex), (void*)44); //float texturecords[2]
the buffer object contains actual data array of those:
struct vertex { float position[3]; char boneindex[4]; float weights[4]; float normals[3]; float texturecords[2]; };
now, question is, how can extract 4 bytes int boneindex
in glsl side? because know glsl not support byte sized types, guess ill have extract 4 different int variables, dont know how.
there 2 issues here. first of all, not correctly setting integer attribute pointer. have use glvertexattribipointer
make data available integer in pipeline.
to acces single bytes, can use standard integer bit shift operations in glsl, in c. recommend using unsigned integers (and unsigned chars), though. example accessing second-highest byte in value can done (boneindex >> 16) & 0xff
.
Comments
Post a Comment