|
@@ -12,6 +12,99 @@
|
|
|
|
|
|
namespace GL {
|
|
|
|
|
|
+// General helper function to read arbitrary vertex attribute data into a float array
|
|
|
+static void read_from_vertex_attribute_pointer(VertexAttribPointer const& attrib, int index, float* elements)
|
|
|
+{
|
|
|
+ auto const* byte_ptr = reinterpret_cast<char const*>(attrib.pointer);
|
|
|
+ auto normalize = attrib.normalize;
|
|
|
+ size_t stride = attrib.stride;
|
|
|
+
|
|
|
+ switch (attrib.type) {
|
|
|
+ case GL_BYTE: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLbyte) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++) {
|
|
|
+ elements[i] = *(reinterpret_cast<GLbyte const*>(byte_ptr + stride * index) + i);
|
|
|
+ if (normalize)
|
|
|
+ elements[i] /= 0x80;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GL_UNSIGNED_BYTE: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLubyte) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++) {
|
|
|
+ elements[i] = *(reinterpret_cast<GLubyte const*>(byte_ptr + stride * index) + i);
|
|
|
+ if (normalize)
|
|
|
+ elements[i] /= 0xff;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GL_SHORT: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLshort) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++) {
|
|
|
+ elements[i] = *(reinterpret_cast<GLshort const*>(byte_ptr + stride * index) + i);
|
|
|
+ if (normalize)
|
|
|
+ elements[i] /= 0x8000;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GL_UNSIGNED_SHORT: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLushort) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++) {
|
|
|
+ elements[i] = *(reinterpret_cast<GLushort const*>(byte_ptr + stride * index) + i);
|
|
|
+ if (normalize)
|
|
|
+ elements[i] /= 0xffff;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GL_INT: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLint) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++) {
|
|
|
+ elements[i] = *(reinterpret_cast<GLint const*>(byte_ptr + stride * index) + i);
|
|
|
+ if (normalize)
|
|
|
+ elements[i] /= 0x80000000;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GL_UNSIGNED_INT: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLuint) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++) {
|
|
|
+ elements[i] = *(reinterpret_cast<GLuint const*>(byte_ptr + stride * index) + i);
|
|
|
+ if (normalize)
|
|
|
+ elements[i] /= 0xffffffff;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GL_FLOAT: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLfloat) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++)
|
|
|
+ elements[i] = *(reinterpret_cast<GLfloat const*>(byte_ptr + stride * index) + i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case GL_DOUBLE: {
|
|
|
+ if (stride == 0)
|
|
|
+ stride = sizeof(GLdouble) * attrib.size;
|
|
|
+
|
|
|
+ for (int i = 0; i < attrib.size; i++)
|
|
|
+ elements[i] = static_cast<float>(*(reinterpret_cast<GLdouble const*>(byte_ptr + stride * index) + i));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void GLContext::gl_array_element(GLint i)
|
|
|
{
|
|
|
// NOTE: This always dereferences data; display list support is deferred to the
|
|
@@ -236,97 +329,4 @@ void GLContext::gl_vertex_pointer(GLint size, GLenum type, GLsizei stride, void
|
|
|
m_client_vertex_pointer = { .size = size, .type = type, .stride = stride, .pointer = pointer };
|
|
|
}
|
|
|
|
|
|
-// General helper function to read arbitrary vertex attribute data into a float array
|
|
|
-void GLContext::read_from_vertex_attribute_pointer(VertexAttribPointer const& attrib, int index, float* elements)
|
|
|
-{
|
|
|
- auto byte_ptr = reinterpret_cast<char const*>(attrib.pointer);
|
|
|
- auto normalize = attrib.normalize;
|
|
|
- size_t stride = attrib.stride;
|
|
|
-
|
|
|
- switch (attrib.type) {
|
|
|
- case GL_BYTE: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLbyte) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++) {
|
|
|
- elements[i] = *(reinterpret_cast<GLbyte const*>(byte_ptr + stride * index) + i);
|
|
|
- if (normalize)
|
|
|
- elements[i] /= 0x80;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case GL_UNSIGNED_BYTE: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLubyte) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++) {
|
|
|
- elements[i] = *(reinterpret_cast<GLubyte const*>(byte_ptr + stride * index) + i);
|
|
|
- if (normalize)
|
|
|
- elements[i] /= 0xff;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case GL_SHORT: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLshort) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++) {
|
|
|
- elements[i] = *(reinterpret_cast<GLshort const*>(byte_ptr + stride * index) + i);
|
|
|
- if (normalize)
|
|
|
- elements[i] /= 0x8000;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case GL_UNSIGNED_SHORT: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLushort) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++) {
|
|
|
- elements[i] = *(reinterpret_cast<GLushort const*>(byte_ptr + stride * index) + i);
|
|
|
- if (normalize)
|
|
|
- elements[i] /= 0xffff;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case GL_INT: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLint) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++) {
|
|
|
- elements[i] = *(reinterpret_cast<GLint const*>(byte_ptr + stride * index) + i);
|
|
|
- if (normalize)
|
|
|
- elements[i] /= 0x80000000;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case GL_UNSIGNED_INT: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLuint) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++) {
|
|
|
- elements[i] = *(reinterpret_cast<GLuint const*>(byte_ptr + stride * index) + i);
|
|
|
- if (normalize)
|
|
|
- elements[i] /= 0xffffffff;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- case GL_FLOAT: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLfloat) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++)
|
|
|
- elements[i] = *(reinterpret_cast<GLfloat const*>(byte_ptr + stride * index) + i);
|
|
|
- break;
|
|
|
- }
|
|
|
- case GL_DOUBLE: {
|
|
|
- if (stride == 0)
|
|
|
- stride = sizeof(GLdouble) * attrib.size;
|
|
|
-
|
|
|
- for (int i = 0; i < attrib.size; i++)
|
|
|
- elements[i] = static_cast<float>(*(reinterpret_cast<GLdouble const*>(byte_ptr + stride * index) + i));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
}
|