Skip to content

Commit 084698d

Browse files
mardyWinterMute
authored andcommitted
arrays: make texture coordinate generation work with vertex buffers
Implement the read_{pos,norm}() functions for the DirectVboReader class too, because they are needed when generating texture coordinates.
1 parent f4b2329 commit 084698d

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/arrays.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,43 @@ struct DirectVboReader: public VertexReaderBase {
284284
void process_element(int index) {
285285
GX_Position1x16(index);
286286
}
287+
template<typename T> const T *elemAt(int index) {
288+
return reinterpret_cast<const T*>(data + stride * index);
289+
}
290+
291+
template<typename T>
292+
void read_floats(int index, float *out) {
293+
const T *ptr = elemAt<T>(index);
294+
out[0] = *ptr++;
295+
out[1] = *ptr++;
296+
if (format.num_components >= 3) {
297+
out[2] = *ptr++;
298+
} else {
299+
out[2] = 0.0f;
300+
}
301+
}
302+
303+
void read_float_components(int index, float *out) {
304+
switch (format.size) {
305+
case GX_F32: read_floats<float>(index, out); break;
306+
case GX_S16: read_floats<int16_t>(index, out); break;
307+
case GX_U16: read_floats<uint16_t>(index, out); break;
308+
case GX_S8: read_floats<int8_t>(index, out); break;
309+
case GX_U8: read_floats<uint8_t>(index, out); break;
310+
}
311+
}
312+
313+
void read_pos3f(int index, Pos3f pos) override {
314+
read_float_components(index, pos);
315+
}
316+
void read_norm3f(int index, Norm3f norm) override {
317+
read_float_components(index, norm);
318+
}
319+
287320
/* These should never be called on this class, since it doesn't make sense
288-
* to call glArrayElement() when a VBO is bound. */
321+
* to call glArrayElement() when a VBO is bound, and they are not used for
322+
* texture coordinate generation. */
289323
void read_color(int index, GXColor *color) override {}
290-
void read_pos3f(int index, Pos3f pos) override {}
291-
void read_norm3f(int index, Norm3f norm) override {}
292324
void read_tex2f(int index, Tex2f tex) override {}
293325
};
294326

0 commit comments

Comments
 (0)