summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-10-16 16:40:35 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-19 22:22:58 +0200
commit2d59c9b6b627d041598f6363c3bcff03c1ba65c6 (patch)
treeb2772a6e3ae8e8da3751b6905c18086bc6b05804 /Userland/Libraries
parent01a4d58432a52f084dd9614188291a8766da8100 (diff)
downloadserenity-2d59c9b6b627d041598f6363c3bcff03c1ba65c6.zip
LibGL: Make `read_from_vertex_attribute_pointer` static
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGL/GLContext.h18
-rw-r--r--Userland/Libraries/LibGL/Vertex.cpp186
2 files changed, 101 insertions, 103 deletions
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index 02c3bc5237..5f3bc2b4d0 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -78,6 +78,14 @@ struct ContextParameter {
} value;
};
+struct VertexAttribPointer {
+ GLint size { 4 };
+ GLenum type { GL_FLOAT };
+ bool normalize { true };
+ GLsizei stride { 0 };
+ void const* pointer { 0 };
+};
+
enum Face {
Front = 0,
Back = 1,
@@ -497,16 +505,6 @@ private:
};
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_color_pointer;
Vector<VertexAttribPointer> m_client_tex_coord_pointer;
diff --git a/Userland/Libraries/LibGL/Vertex.cpp b/Userland/Libraries/LibGL/Vertex.cpp
index d8b890d2ef..fe31c5be1b 100644
--- a/Userland/Libraries/LibGL/Vertex.cpp
+++ b/Userland/Libraries/LibGL/Vertex.cpp
@@ -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;
- }
- }
-}
-
}