mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
LibGL: Make read_from_vertex_attribute_pointer
static
This commit is contained in:
parent
01a4d58432
commit
2d59c9b6b6
2 changed files with 101 additions and 103 deletions
|
@ -78,6 +78,14 @@ struct ContextParameter {
|
||||||
} value;
|
} value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct VertexAttribPointer {
|
||||||
|
GLint size { 4 };
|
||||||
|
GLenum type { GL_FLOAT };
|
||||||
|
bool normalize { true };
|
||||||
|
GLsizei stride { 0 };
|
||||||
|
void const* pointer { 0 };
|
||||||
|
};
|
||||||
|
|
||||||
enum Face {
|
enum Face {
|
||||||
Front = 0,
|
Front = 0,
|
||||||
Back = 1,
|
Back = 1,
|
||||||
|
@ -497,16 +505,6 @@ private:
|
||||||
};
|
};
|
||||||
Optional<CurrentListing> m_current_listing_index;
|
Optional<CurrentListing> m_current_listing_index;
|
||||||
|
|
||||||
struct VertexAttribPointer {
|
|
||||||
GLint size { 4 };
|
|
||||||
GLenum type { GL_FLOAT };
|
|
||||||
bool normalize { true };
|
|
||||||
GLsizei stride { 0 };
|
|
||||||
void const* pointer { 0 };
|
|
||||||
};
|
|
||||||
|
|
||||||
static void read_from_vertex_attribute_pointer(VertexAttribPointer const&, int index, float* elements);
|
|
||||||
|
|
||||||
VertexAttribPointer m_client_vertex_pointer;
|
VertexAttribPointer m_client_vertex_pointer;
|
||||||
VertexAttribPointer m_client_color_pointer;
|
VertexAttribPointer m_client_color_pointer;
|
||||||
Vector<VertexAttribPointer> m_client_tex_coord_pointer;
|
Vector<VertexAttribPointer> m_client_tex_coord_pointer;
|
||||||
|
|
|
@ -12,6 +12,99 @@
|
||||||
|
|
||||||
namespace GL {
|
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)
|
void GLContext::gl_array_element(GLint i)
|
||||||
{
|
{
|
||||||
// NOTE: This always dereferences data; display list support is deferred to the
|
// 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 };
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue