X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=helpers%2Fglsize.hpp;h=2da217f123a24ba3ce3058548f7886c9eb23640c;hb=ae423964d8b9e4cae2a180e20879205aeeeca27f;hp=9d39a3b717f6f812aee787d58a3be5a73623ad6d;hpb=1f94577d8c4b1c1a2a1a8f3dceb0daac02dd72b7;p=apitrace diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp index 9d39a3b..2da217f 100644 --- a/helpers/glsize.hpp +++ b/helpers/glsize.hpp @@ -329,6 +329,21 @@ _glArrayPointer_size(GLint size, GLenum type, GLsizei stride, GLsizei count) #define _glVertexAttribPointerARB_size(size, type, normalized, stride, count) _glArrayPointer_size(size, type, stride, count) #define _glVertexAttribPointerNV_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count) +/** + * Same as glGetIntegerv, but passing the result in the return value. + */ +static inline GLint +_glGetInteger(GLenum pname) { + GLint param = 0; + _glGetIntegerv(pname, ¶m); + return param; +} + +static inline GLint +_element_array_buffer_binding(void) { + return _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING); +} + static inline GLuint _glDrawArrays_count(GLint first, GLsizei count) { @@ -349,13 +364,12 @@ static inline GLuint _glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex) { GLvoid *temp = 0; - GLint element_array_buffer = 0; if (!count) { return 0; } - _glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &element_array_buffer); + GLint element_array_buffer = _element_array_buffer_binding(); if (element_array_buffer) { // Read indices from index buffer object GLintptr offset = (GLintptr)indices; @@ -617,12 +631,12 @@ _align(X x, Y y) { return (x + (y - 1)) & ~(y - 1); } -static inline size_t -_gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) { +static inline void +_gl_format_size(GLenum format, GLenum type, + unsigned & bits_per_element, unsigned & bits_per_pixel) +{ unsigned num_channels = _gl_format_channels(format); - unsigned bits_per_element; - unsigned bits_per_pixel; switch (type) { case GL_BITMAP: bits_per_pixel = bits_per_element = 1; @@ -677,6 +691,22 @@ _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsize bits_per_pixel = bits_per_element = 0; break; } +} + +static inline size_t +_glClearBufferData_size(GLenum format, GLenum type) { + unsigned bits_per_element; + unsigned bits_per_pixel; + _gl_format_size(format, type, bits_per_element, bits_per_pixel); + return (bits_per_pixel + 7)/8; +} + +static inline size_t +_gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) { + + unsigned bits_per_element; + unsigned bits_per_pixel; + _gl_format_size(format, type, bits_per_element, bits_per_pixel); GLint alignment = 4; GLint row_length = 0; @@ -785,6 +815,22 @@ _glClearBuffer_size(GLenum buffer) } } + +/** + * Helper function for determining the string lengths for glShaderSource and + * glShaderSourceARB, which is a tad too complex to inline in the specs. + */ +template +static inline size_t +_glShaderSource_length(const T * const * string, const GLint *length, GLsizei index) +{ + if (length != NULL && length[index] >= 0) { + return (size_t)length[index]; + } else { + return strlen(string[index]); + } +} + /* * attribute list, terminated by the given terminator. */