1 /**************************************************************************
3 * Copyright 2011 Jose Fonseca
4 * Copyright 2010 VMware, Inc.
5 * Copyright 2004 IBM Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sub license,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
23 * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 **************************************************************************/
31 * Auxiliary functions to compute the size of array/blob arguments, depending.
44 #include "glimports.hpp"
48 _gl_type_size(GLenum type)
53 case GL_UNSIGNED_BYTE:
56 case GL_UNSIGNED_SHORT:
71 os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
77 _gl_uniform_size(GLenum type, GLenum &elemType, GLint &numCols, GLint &numRows) {
101 elemType = GL_DOUBLE;
105 elemType = GL_DOUBLE;
109 elemType = GL_DOUBLE;
127 case GL_UNSIGNED_INT:
128 elemType = GL_UNSIGNED_INT;
130 case GL_UNSIGNED_INT_VEC2:
131 elemType = GL_UNSIGNED_INT;
134 case GL_UNSIGNED_INT_VEC3:
135 elemType = GL_UNSIGNED_INT;
138 case GL_UNSIGNED_INT_VEC4:
139 elemType = GL_UNSIGNED_INT;
172 case GL_FLOAT_MAT2x3:
177 case GL_FLOAT_MAT2x4:
182 case GL_FLOAT_MAT3x2:
187 case GL_FLOAT_MAT3x4:
192 case GL_FLOAT_MAT4x2:
197 case GL_FLOAT_MAT4x3:
203 elemType = GL_DOUBLE;
208 elemType = GL_DOUBLE;
213 elemType = GL_DOUBLE;
217 case GL_DOUBLE_MAT2x3:
218 elemType = GL_DOUBLE;
222 case GL_DOUBLE_MAT2x4:
223 elemType = GL_DOUBLE;
227 case GL_DOUBLE_MAT3x2:
228 elemType = GL_DOUBLE;
232 case GL_DOUBLE_MAT3x4:
233 elemType = GL_DOUBLE;
237 case GL_DOUBLE_MAT4x2:
238 elemType = GL_DOUBLE;
242 case GL_DOUBLE_MAT4x3:
243 elemType = GL_DOUBLE;
250 case GL_SAMPLER_CUBE:
251 case GL_SAMPLER_1D_SHADOW:
252 case GL_SAMPLER_2D_SHADOW:
253 case GL_SAMPLER_1D_ARRAY:
254 case GL_SAMPLER_2D_ARRAY:
255 case GL_SAMPLER_CUBE_MAP_ARRAY:
256 case GL_SAMPLER_1D_ARRAY_SHADOW:
257 case GL_SAMPLER_2D_ARRAY_SHADOW:
258 case GL_SAMPLER_2D_MULTISAMPLE:
259 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY:
260 case GL_SAMPLER_CUBE_SHADOW:
261 case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW:
262 case GL_SAMPLER_BUFFER:
263 case GL_SAMPLER_2D_RECT:
264 case GL_SAMPLER_2D_RECT_SHADOW:
265 case GL_INT_SAMPLER_1D:
266 case GL_INT_SAMPLER_2D:
267 case GL_INT_SAMPLER_3D:
268 case GL_INT_SAMPLER_CUBE:
269 case GL_INT_SAMPLER_1D_ARRAY:
270 case GL_INT_SAMPLER_2D_ARRAY:
271 case GL_INT_SAMPLER_CUBE_MAP_ARRAY:
272 case GL_INT_SAMPLER_2D_MULTISAMPLE:
273 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
274 case GL_INT_SAMPLER_BUFFER:
275 case GL_INT_SAMPLER_2D_RECT:
276 case GL_UNSIGNED_INT_SAMPLER_1D:
277 case GL_UNSIGNED_INT_SAMPLER_2D:
278 case GL_UNSIGNED_INT_SAMPLER_3D:
279 case GL_UNSIGNED_INT_SAMPLER_CUBE:
280 case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY:
281 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
282 case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY:
283 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE:
284 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY:
285 case GL_UNSIGNED_INT_SAMPLER_BUFFER:
286 case GL_UNSIGNED_INT_SAMPLER_2D_RECT:
290 os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
299 _glArrayPointer_size(GLint size, GLenum type, GLsizei stride, GLsizei count)
305 if (size == GL_BGRA) {
310 os::log("apitrace: warning: %s: unexpected size 0x%04X\n", __FUNCTION__, size);
313 size_t elementSize = size*_gl_type_size(type);
315 stride = (GLsizei)elementSize;
318 return stride*(count - 1) + elementSize;
321 #define _glVertexPointer_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count)
322 #define _glNormalPointer_size(type, stride, count) _glArrayPointer_size(3, type, stride, count)
323 #define _glColorPointer_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count)
324 #define _glIndexPointer_size(type, stride, count) _glArrayPointer_size(1, type, stride, count)
325 #define _glTexCoordPointer_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count)
326 #define _glEdgeFlagPointer_size(stride, count) _glArrayPointer_size(1, GL_BOOL, stride, count)
327 #define _glFogCoordPointer_size(type, stride, count) _glArrayPointer_size(1, type, stride, count)
328 #define _glSecondaryColorPointer_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count)
329 #define _glVertexAttribPointer_size(size, type, normalized, stride, count) _glArrayPointer_size(size, type, stride, count)
330 #define _glVertexAttribPointerARB_size(size, type, normalized, stride, count) _glArrayPointer_size(size, type, stride, count)
331 #define _glVertexAttribPointerNV_size(size, type, stride, count) _glArrayPointer_size(size, type, stride, count)
334 * Same as glGetIntegerv, but passing the result in the return value.
337 _glGetInteger(GLenum pname) {
339 _glGetIntegerv(pname, ¶m);
344 _element_array_buffer_binding(void) {
345 return _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING);
349 _glDrawArrays_count(GLint first, GLsizei count)
354 return first + count;
357 #define _glDrawArraysEXT_count _glDrawArrays_count
359 /* Forward declaration for definition in gltrace.py */
361 _shadow_glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size,
365 _glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex)
373 GLint element_array_buffer = _element_array_buffer_binding();
374 if (element_array_buffer) {
375 // Read indices from index buffer object
376 GLintptr offset = (GLintptr)indices;
377 GLsizeiptr size = count*_gl_type_size(type);
378 GLvoid *temp = malloc(size);
382 memset(temp, 0, size);
383 _shadow_glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp);
393 if (type == GL_UNSIGNED_BYTE) {
394 const GLubyte *p = (const GLubyte *)indices;
395 for (i = 0; i < count; ++i) {
396 if (p[i] > maxindex) {
400 } else if (type == GL_UNSIGNED_SHORT) {
401 const GLushort *p = (const GLushort *)indices;
402 for (i = 0; i < count; ++i) {
403 if (p[i] > maxindex) {
407 } else if (type == GL_UNSIGNED_INT) {
408 const GLuint *p = (const GLuint *)indices;
409 for (i = 0; i < count; ++i) {
410 if (p[i] > maxindex) {
415 os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
418 if (element_array_buffer) {
422 maxindex += basevertex;
427 #define _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, basevertex) _glDrawElementsBaseVertex_count(count, type, indices, basevertex)
429 #define _glDrawElements_count(count, type, indices) _glDrawElementsBaseVertex_count(count, type, indices, 0);
430 #define _glDrawRangeElements_count(start, end, count, type, indices) _glDrawElements_count(count, type, indices)
431 #define _glDrawRangeElementsEXT_count _glDrawRangeElements_count
433 /* FIXME take in consideration instancing */
434 #define _glDrawArraysInstanced_count(first, count, primcount) _glDrawArrays_count(first, count)
435 #define _glDrawElementsInstanced_count(count, type, indices, primcount) _glDrawElements_count(count, type, indices)
436 #define _glDrawElementsInstancedBaseVertex_count(count, type, indices, primcount, basevertex) _glDrawElementsBaseVertex_count(count, type, indices, basevertex)
437 #define _glDrawRangeElementsInstanced_count(start, end, count, type, indices, primcount) _glDrawRangeElements_count(start, end, count, type, indices)
438 #define _glDrawRangeElementsInstancedBaseVertex_count(start, end, count, type, indices, primcount, basevertex) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, basevertex)
440 #define _glDrawArraysInstancedBaseInstance_count(first, count, primcount, baseinstance) _glDrawArrays_count(first, count)
441 #define _glDrawElementsInstancedBaseInstance_count(count, type, indices, primcount, baseinstance) _glDrawElements_count(count, type, indices)
442 #define _glDrawElementsInstancedBaseVertexBaseInstance_count(count, type, indices, primcount, basevertex, baseinstance) _glDrawElementsBaseVertex_count(count, type, indices, basevertex)
444 #define _glDrawArraysInstancedARB_count _glDrawArraysInstanced_count
445 #define _glDrawElementsInstancedARB_count _glDrawElementsInstanced_count
446 #define _glDrawArraysInstancedEXT_count _glDrawArraysInstanced_count
447 #define _glDrawElementsInstancedEXT_count _glDrawElementsInstanced_count
454 } DrawArraysIndirectCommand;
457 _glMultiDrawArraysIndirect_count(const GLvoid *indirect, GLsizei drawcount, GLsizei stride) {
458 const DrawArraysIndirectCommand *cmd;
461 if (drawcount <= 0) {
466 stride = sizeof *cmd;
469 GLint draw_indirect_buffer = _glGetInteger(GL_DRAW_INDIRECT_BUFFER_BINDING);
470 if (draw_indirect_buffer) {
471 // Read commands from indirect buffer object
472 GLintptr offset = (GLintptr)indirect;
473 GLsizeiptr size = sizeof *cmd + (drawcount - 1) * stride;
474 GLvoid *temp = malloc(size);
478 memset(temp, 0, size);
479 _glGetBufferSubData(GL_DRAW_INDIRECT_BUFFER, offset, size, temp);
488 for (GLsizei i = 0; i < drawcount; ++i) {
489 cmd = (const DrawArraysIndirectCommand *)((const GLbyte *)indirect + i * stride);
491 GLuint count_i = _glDrawArraysInstancedBaseInstance_count(
498 count = std::max(count, count_i);
501 if (draw_indirect_buffer) {
509 _glDrawArraysIndirect_count(const GLvoid *indirect) {
510 return _glMultiDrawArraysIndirect_count(indirect, 1, 0);
519 } DrawElementsIndirectCommand;
522 _glMultiDrawElementsIndirect_count(GLenum type, const GLvoid *indirect, GLsizei drawcount, GLsizei stride) {
523 const DrawElementsIndirectCommand *cmd;
526 if (drawcount <= 0) {
531 stride = sizeof *cmd;
534 GLint draw_indirect_buffer = _glGetInteger(GL_DRAW_INDIRECT_BUFFER_BINDING);
535 if (draw_indirect_buffer) {
536 // Read commands from indirect buffer object
537 GLintptr offset = (GLintptr)indirect;
538 GLsizeiptr size = sizeof *cmd + (drawcount - 1) * stride;
539 GLvoid *temp = malloc(size);
543 memset(temp, 0, size);
544 _glGetBufferSubData(GL_DRAW_INDIRECT_BUFFER, offset, size, temp);
552 cmd = (const DrawElementsIndirectCommand *)indirect;
555 for (GLsizei i = 0; i < drawcount; ++i) {
556 cmd = (const DrawElementsIndirectCommand *)((const GLbyte *)indirect + i * stride);
558 GLuint count_i = _glDrawElementsInstancedBaseVertexBaseInstance_count(
561 (GLvoid *)(uintptr_t)(cmd->firstIndex * _gl_type_size(type)),
567 count = std::max(count, count_i);
570 if (draw_indirect_buffer) {
578 _glDrawElementsIndirect_count(GLenum type, const GLvoid *indirect) {
579 return _glMultiDrawElementsIndirect_count(type, indirect, 1, 0);
582 #define _glMultiDrawArraysIndirectAMD_count _glMultiDrawArraysIndirect_count
583 #define _glMultiDrawElementsIndirectAMD_count _glMultiDrawElementsIndirect_count
586 _glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawcount) {
588 for (GLsizei draw = 0; draw < drawcount; ++draw) {
589 GLuint _count_draw = _glDrawArrays_count(first[draw], count[draw]);
590 _count = std::max(_count, _count_draw);
596 _glMultiDrawElements_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount) {
598 for (GLsizei draw = 0; draw < drawcount; ++draw) {
599 GLuint _count_draw = _glDrawElements_count(count[draw], type, indices[draw]);
600 _count = std::max(_count, _count_draw);
606 _glMultiDrawElementsBaseVertex_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint * basevertex) {
608 for (GLsizei draw = 0; draw < drawcount; ++draw) {
609 GLuint _count_draw = _glDrawElementsBaseVertex_count(count[draw], type, indices[draw], basevertex[draw]);
610 _count = std::max(_count, _count_draw);
615 #define _glMultiDrawArraysEXT_count _glMultiDrawArrays_count
616 #define _glMultiDrawElementsEXT_count _glMultiDrawElements_count
618 #define _glMultiModeDrawArraysIBM_count(first, count, drawcount, modestride) _glMultiDrawArrays_count(first, count, drawcount)
619 #define _glMultiModeDrawElementsIBM_count(count, type, indices, drawcount, modestride) _glMultiDrawElements_count(count, type, (const GLvoid **)indices, drawcount)
623 _glCallLists_size(GLsizei n, GLenum type)
625 return n*_gl_type_size(type);
629 _glMap1d_size(GLenum target, GLint stride, GLint order)
638 case GL_MAP1_TEXTURE_COORD_1:
641 case GL_MAP1_TEXTURE_COORD_2:
645 case GL_MAP1_TEXTURE_COORD_3:
646 case GL_MAP1_VERTEX_3:
649 case GL_MAP1_COLOR_4:
650 case GL_MAP1_TEXTURE_COORD_4:
651 case GL_MAP1_VERTEX_4:
655 os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, target);
659 if (stride < channels) {
663 return channels + stride * (order - 1);
666 #define _glMap1f_size _glMap1d_size
669 _glMap2d_size(GLenum target, GLint ustride, GLint uorder, GLint vstride, GLint vorder)
671 if (uorder < 1 || vorder < 1) {
678 case GL_MAP2_TEXTURE_COORD_1:
681 case GL_MAP2_TEXTURE_COORD_2:
685 case GL_MAP2_TEXTURE_COORD_3:
686 case GL_MAP2_VERTEX_3:
689 case GL_MAP2_COLOR_4:
690 case GL_MAP2_TEXTURE_COORD_4:
691 case GL_MAP2_VERTEX_4:
695 os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, target);
699 if (ustride < channels || vstride < channels) {
704 ustride * (uorder - 1) +
705 vstride * (vorder - 1);
708 #define _glMap2f_size _glMap2d_size
711 * Number of channels in this format.
713 * That is, the number of elements per pixel when this format is passed with a
714 * to DrawPixels, ReadPixels, TexImage*, TexSubImage*, GetTexImage, etc.
716 static inline unsigned
717 _gl_format_channels(GLenum format) {
723 case GL_GREEN_INTEGER:
725 case GL_BLUE_INTEGER:
727 case GL_ALPHA_INTEGER:
730 case GL_LUMINANCE_INTEGER_EXT:
731 case GL_DEPTH_COMPONENT:
732 case GL_STENCIL_INDEX:
734 case GL_DEPTH_STENCIL:
735 case GL_LUMINANCE_ALPHA:
736 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
739 case GL_422_EXT: // (luminance, chrominance)
740 case GL_422_REV_EXT: // (luminance, chrominance)
741 case GL_422_AVERAGE_EXT: // (luminance, chrominance)
742 case GL_422_REV_AVERAGE_EXT: // (luminance, chrominance)
743 case GL_HILO_NV: // (hi, lo)
744 case GL_DSDT_NV: // (ds, dt)
745 case GL_YCBCR_422_APPLE: // (luminance, chroma)
746 case GL_RGB_422_APPLE: // (G, B) on even pixels, (G, R) on odd pixels
747 case GL_YCRCB_422_SGIX: // (Y, [Cb,Cr])
753 case GL_DSDT_MAG_NV: // (ds, dt, magnitude)
754 case GL_YCRCB_444_SGIX: // (Cb, Y, Cr)
757 case GL_RGBA_INTEGER:
759 case GL_BGRA_INTEGER:
762 case GL_DSDT_MAG_VIB_NV: // (ds, dt, magnitude, vibrance)
766 case GL_FORMAT_SUBSAMPLE_24_24_OML:
767 case GL_FORMAT_SUBSAMPLE_244_244_OML:
768 // requires UNSIGNED_INT_10_10_10_2, so this value will be ignored
771 os::log("apitrace: warning: %s: unexpected format GLenum 0x%04X\n", __FUNCTION__, format);
779 return (x & (x - 1)) == 0;
782 template<class X, class Y>
785 return (x + (y - 1)) & ~(y - 1);
789 _gl_format_size(GLenum format, GLenum type,
790 unsigned & bits_per_element, unsigned & bits_per_pixel)
792 unsigned num_channels = _gl_format_channels(format);
796 bits_per_pixel = bits_per_element = 1;
799 case GL_UNSIGNED_BYTE:
800 bits_per_element = 8;
801 bits_per_pixel = bits_per_element * num_channels;
804 case GL_UNSIGNED_SHORT:
806 bits_per_element = 16;
807 bits_per_pixel = bits_per_element * num_channels;
810 case GL_UNSIGNED_INT:
812 bits_per_element = 32;
813 bits_per_pixel = bits_per_element * num_channels;
815 case GL_UNSIGNED_BYTE_3_3_2:
816 case GL_UNSIGNED_BYTE_2_3_3_REV:
817 bits_per_pixel = bits_per_element = 8;
819 case GL_UNSIGNED_SHORT_4_4_4_4:
820 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
821 case GL_UNSIGNED_SHORT_5_5_5_1:
822 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
823 case GL_UNSIGNED_SHORT_5_6_5:
824 case GL_UNSIGNED_SHORT_5_6_5_REV:
825 case GL_UNSIGNED_SHORT_8_8_MESA:
826 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
827 bits_per_pixel = bits_per_element = 16;
829 case GL_UNSIGNED_INT_8_8_8_8:
830 case GL_UNSIGNED_INT_8_8_8_8_REV:
831 case GL_UNSIGNED_INT_10_10_10_2:
832 case GL_UNSIGNED_INT_2_10_10_10_REV:
833 case GL_UNSIGNED_INT_24_8:
834 case GL_UNSIGNED_INT_10F_11F_11F_REV:
835 case GL_UNSIGNED_INT_5_9_9_9_REV:
836 case GL_UNSIGNED_INT_S8_S8_8_8_NV:
837 case GL_UNSIGNED_INT_8_8_S8_S8_REV_NV:
838 bits_per_pixel = bits_per_element = 32;
840 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
841 bits_per_pixel = bits_per_element = 64;
844 os::log("apitrace: warning: %s: unexpected type GLenum 0x%04X\n", __FUNCTION__, type);
845 bits_per_pixel = bits_per_element = 0;
851 _glClearBufferData_size(GLenum format, GLenum type) {
852 unsigned bits_per_element;
853 unsigned bits_per_pixel;
854 _gl_format_size(format, type, bits_per_element, bits_per_pixel);
855 return (bits_per_pixel + 7)/8;
859 _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) {
861 unsigned bits_per_element;
862 unsigned bits_per_pixel;
863 _gl_format_size(format, type, bits_per_element, bits_per_pixel);
866 GLint row_length = 0;
867 GLint image_height = 0;
869 GLint skip_pixels = 0;
870 GLint skip_images = 0;
872 _glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
873 if (has_unpack_subimage) {
874 _glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
875 _glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &image_height);
876 _glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
877 _glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
878 _glGetIntegerv(GL_UNPACK_SKIP_IMAGES, &skip_images);
881 if (row_length <= 0) {
885 size_t row_stride = (row_length*bits_per_pixel + 7)/8;
887 if ((bits_per_element == 1*8 ||
888 bits_per_element == 2*8 ||
889 bits_per_element == 4*8 ||
890 bits_per_element == 8*8) &&
891 (GLint)bits_per_element < alignment*8) {
892 row_stride = _align(row_stride, alignment);
895 if (image_height <= 0) {
896 image_height = height;
899 /* XXX: GL_UNPACK_IMAGE_HEIGHT and GL_UNPACK_SKIP_IMAGES should probably
900 * not be considered for pixel rectangles. */
902 size_t image_stride = image_height*row_stride;
904 size_t size = depth*image_stride;
906 size += (skip_pixels*bits_per_pixel + 7)/8;
907 size += skip_rows*row_stride;
908 size += skip_images*image_stride;
913 // note that can_unpack_subimage() is generated by gltrace.py
914 #define _glTexImage3D_size(format, type, width, height, depth) _gl_image_size(format, type, width, height, depth, can_unpack_subimage())
915 #define _glTexImage2D_size(format, type, width, height) _gl_image_size(format, type, width, height, 1, can_unpack_subimage())
916 #define _glTexImage1D_size(format, type, width) _gl_image_size(format, type, width, 1, 1, can_unpack_subimage())
918 #define _glTexSubImage3D_size(format, type, width, height, depth) _glTexImage3D_size(format, type, width, height, depth)
919 #define _glTexSubImage2D_size(format, type, width, height) _glTexImage2D_size(format, type, width, height)
920 #define _glTexSubImage1D_size(format, type, width) _glTexImage1D_size(format, type, width)
922 #define _glTexImage3DEXT_size _glTexImage3D_size
923 #define _glTexImage2DEXT_size _glTexImage2D_size
924 #define _glTexImage1DEXT_size _glTexImage1D_size
925 #define _glTexSubImage3DEXT_size _glTexSubImage3D_size
926 #define _glTexSubImage2DEXT_size _glTexSubImage2D_size
927 #define _glTexSubImage1DEXT_size _glTexSubImage1D_size
929 #define _glTextureImage3DEXT_size _glTexImage3D_size
930 #define _glTextureImage2DEXT_size _glTexImage2D_size
931 #define _glTextureImage1DEXT_size _glTexImage1D_size
932 #define _glTextureSubImage3DEXT_size _glTexSubImage3D_size
933 #define _glTextureSubImage2DEXT_size _glTexSubImage2D_size
934 #define _glTextureSubImage1DEXT_size _glTexSubImage1D_size
936 #define _glMultiTexImage3DEXT_size _glTexImage3D_size
937 #define _glMultiTexImage2DEXT_size _glTexImage2D_size
938 #define _glMultiTexImage1DEXT_size _glTexImage1D_size
939 #define _glMultiTexSubImage3DEXT_size _glTexSubImage3D_size
940 #define _glMultiTexSubImage2DEXT_size _glTexSubImage2D_size
941 #define _glMultiTexSubImage1DEXT_size _glTexSubImage1D_size
943 #define _glDrawPixels_size(format, type, width, height) _glTexImage2D_size(format, type, width, height)
944 #define _glConvolutionFilter1D_size(format, type, width) _glTexImage1D_size(format, type, width)
945 #define _glConvolutionFilter2D_size(format, type, width, height) _glTexImage2D_size(format, type, width, height)
946 #define _glColorTable_size(format, type, width) _glTexImage1D_size(format, type, width)
947 #define _glColorSubTable_size(format, type, count) _glColorTable_size(format, type, count)
949 #define _glBitmap_size(width, height) _glTexImage2D_size(GL_COLOR_INDEX, GL_BITMAP, width, height)
950 #define _glPolygonStipple_size() _glBitmap_size(32, 32)
953 _glClearBuffer_size(GLenum buffer)
961 case GL_FRONT_AND_BACK:
967 os::log("apitrace: warning: %s: unexpected buffer GLenum 0x%04X\n", __FUNCTION__, buffer);
973 _glPath_coords_size(GLsizei numCoords, GLenum coordType)
977 return numCoords * sizeof(GLbyte);
978 case GL_UNSIGNED_BYTE:
979 return numCoords * sizeof(GLubyte);
981 return numCoords * sizeof(GLshort);
982 case GL_UNSIGNED_SHORT:
983 return numCoords * sizeof(GLushort);
985 return numCoords * sizeof(GLfloat);
992 _glPath_fontName_size(GLenum fontTarget, const void *fontName)
994 switch (fontTarget) {
995 case GL_STANDARD_FONT_NAME_NV:
996 case GL_SYSTEM_FONT_NAME_NV:
997 case GL_FILE_NAME_NV:
999 // Include +1 to copy nul terminator.
1000 GLsizei size = GLsizei(strlen(reinterpret_cast<const char*>(fontName))+1);
1008 static inline size_t
1009 _glPath_chardcodes_size(GLsizei numGlyphs, GLenum type)
1011 GLsizei bytes_per_glyph;
1015 bytes_per_glyph = 4;
1018 bytes_per_glyph = 1;
1021 bytes_per_glyph = 2;
1026 return bytes_per_glyph*numGlyphs;
1029 static GLsizei floatPerTransformList(GLenum transformType)
1031 switch (transformType) {
1034 case GL_TRANSLATE_X_NV:
1035 case GL_TRANSLATE_Y_NV:
1037 case GL_TRANSLATE_2D_NV:
1039 case GL_TRANSLATE_3D_NV:
1041 case GL_AFFINE_2D_NV:
1042 case GL_TRANSPOSE_AFFINE_2D_NV:
1044 case GL_PROJECTIVE_2D_NV:
1045 case GL_TRANSPOSE_PROJECTIVE_2D_NV:
1047 case GL_AFFINE_3D_NV:
1048 case GL_TRANSPOSE_AFFINE_3D_NV:
1050 case GL_PROJECTIVE_3D_NV:
1051 case GL_TRANSPOSE_PROJECTIVE_3D_NV:
1058 static inline size_t
1059 _gl_transformType_size(GLenum transformType)
1061 return floatPerTransformList(transformType)*sizeof(GLfloat);
1064 static inline size_t
1065 _gl_transformType_size(GLsizei numPaths, GLenum transformType)
1067 return numPaths*floatPerTransformList(transformType)*sizeof(GLfloat);
1070 static size_t valuesPerPathParameter(GLenum pname)
1073 case GL_PATH_FILL_MODE_NV:
1074 case GL_PATH_FILL_MASK_NV:
1075 case GL_PATH_FILL_COVER_MODE_NV:
1076 case GL_PATH_STROKE_WIDTH_NV:
1077 case GL_PATH_INITIAL_END_CAP_NV:
1078 case GL_PATH_TERMINAL_END_CAP_NV:
1079 case GL_PATH_JOIN_STYLE_NV:
1080 case GL_PATH_MITER_LIMIT_NV:
1081 case GL_PATH_INITIAL_DASH_CAP_NV:
1082 case GL_PATH_TERMINAL_DASH_CAP_NV:
1083 case GL_PATH_DASH_OFFSET_NV:
1084 case GL_PATH_DASH_OFFSET_RESET_NV:
1085 case GL_PATH_CLIENT_LENGTH_NV:
1086 case GL_PATH_STROKE_COVER_MODE_NV:
1087 case GL_PATH_STROKE_MASK_NV:
1088 case GL_PATH_STROKE_OVERSAMPLE_COUNT_NV:
1089 case GL_PATH_SAMPLE_QUALITY_NV:
1090 case GL_PATH_END_CAPS_NV: // not valid for glGetPathParameter
1091 case GL_PATH_DASH_CAPS_NV: // not valid for glGetPathParameter
1098 static inline size_t
1099 _gl_PathParameter_size(GLenum pname)
1101 return valuesPerPathParameter(pname);
1104 // See RFC-3629 "UTF-8, a transformation format of ISO 10646"
1105 // http://www.rfc-editor.org/rfc/rfc3629.txt
1106 // http://rfc-ref.org/RFC-TEXTS/3629/index.html
1108 __glPathGetCodePointUTF8(const void *&utf_string,
1111 const GLubyte *p = reinterpret_cast<const GLubyte*>(utf_string);
1113 if ((c0 & 0x80) == 0x00) {
1114 // Zero continuation (0 to 127)
1116 assert(code_point <= 127);
1120 if ((c1 & 0xC0) != 0x80) {
1121 // Stop processing the UTF byte sequence early.
1124 if ((c0 & 0xE0) == 0xC0) {
1125 // One contination (128 to 2047)
1126 code_point = ((c0 & 0x1F) << 6) | (c1 & 0x3F);
1127 if (code_point < 128) {
1130 assert(code_point >= 128 && code_point <= 2047);
1134 if ((c2 & 0xC0) != 0x80) {
1135 // Stop processing the UTF byte sequence early.
1138 if ((c0 & 0xF0) == 0xE0) {
1139 // Two continuation (2048 to 55295 and 57344 to 65535)
1140 code_point = ((c0 & 0x0F) << 12) |
1141 ((c1 & 0x3F) << 6) |
1143 // "The definition of UTF-8 prohibits encoding character numbers between
1144 // U+D800 and U+DFFF, which are reserved for use with the UTF-16
1145 // encoding form (as surrogate pairs) and do not directly represent
1149 if ((code_point >= 55296) && (code_point <= 57343)) {
1150 // Stop processing the UTF byte sequence early.
1153 if (code_point < 2048) {
1156 assert(code_point >= 2048 && code_point <= 65535);
1157 assert(code_point < 55296 || code_point > 57343);
1161 if ((c3 & 0xC0) != 0x80) {
1162 // Stop processing the UTF byte sequence early.
1165 if ((c0 & 0xF8) == 0xF0) {
1166 // Three continuation (65536 to 1114111)
1167 code_point = ((c0 & 0x07) << 18) |
1168 ((c1 & 0x3F) << 12) |
1169 ((c2 & 0x3F) << 6) |
1171 if (code_point < 65536 && code_point > 1114111) {
1174 assert(code_point >= 65536 && code_point <= 1114111);
1177 // Skip invalid or restricted encodings.
1178 // Stop processing the UTF byte sequence early.
1188 // See RFC-2781 "UTF-16, a transformation format of ISO 10646"
1189 // http://rfc-ref.org/RFC-TEXTS/2781/index.html
1190 // http://www.rfc-editor.org/rfc/rfc2781.txt
1192 __glPathGetCodePointUTF16(const void *&utf_string,
1195 // Section 2.2 (Decoding UTF-16) of http://www.rfc-editor.org/rfc/rfc2781.txt
1196 // "Decoding of a single character from UTF-16 to an ISO 10646 character
1197 // value proceeds as follows."
1198 const GLushort *p = reinterpret_cast<const GLushort*>(utf_string);
1200 // "Let W1 be the next 16-bit integer in the
1201 // sequence of integers representing the text."
1203 // "1) If W1 < 0xD800 or W1 > 0xDFFF, the character value U is the value
1204 // of W1. Terminate."
1205 if ((W1 < 0xDB00) || (W1 > 0xDFFF)) {
1209 // "2) Determine if W1 is between 0xD800 and 0xDBFF."
1210 bool between1 = (W1 >= 0xDB00) && (W1 <= 0xDBFF);
1212 // "If not, the sequence
1213 // is in error and no valid character can be obtained using W1.
1217 // "Let W2 be the (eventual) next integer following W1."
1219 // DOES NOT APPLY because API provides character (not byte) count.
1220 // "3) If there is no W2 (that is, the sequence ends with W1), [Terminate]"
1222 // "... or if W2 is not between 0xDC00 and 0xDFFF, the sequence
1223 // is in error. Terminate."
1224 bool between2 = (W2 >= 0xDC00) && (W2 <= 0xDFFF);
1228 // "4) Construct a 20-bit unsigned integer U', taking the 10 low-order
1229 // bits of W1 as its 10 high-order bits and the 10 low-order bits of
1230 // W2 as its 10 low-order bits."
1231 code_point = ((W1 & 0x3FF) << 10) |
1233 // "5) Add 0x10000 to U' to obtain the character value U. Terminate."
1234 code_point += 0x10000;
1241 static size_t bytesOfSequence(GLsizei count, GLenum type, const GLvoid *sequence)
1243 GLsizei bytes_per_element;
1246 bytes_per_element = sizeof(GLbyte);
1248 case GL_UNSIGNED_BYTE:
1249 bytes_per_element = sizeof(GLubyte);
1252 bytes_per_element = sizeof(GLshort);
1254 case GL_UNSIGNED_SHORT:
1255 bytes_per_element = sizeof(GLushort);
1258 bytes_per_element = sizeof(GLint);
1260 case GL_UNSIGNED_INT:
1261 bytes_per_element = sizeof(GLuint);
1264 bytes_per_element = sizeof(GLfloat);
1267 bytes_per_element = 2*sizeof(GLubyte);
1270 bytes_per_element = 3*sizeof(GLubyte);
1273 bytes_per_element = 4*sizeof(GLubyte);
1277 const void *utf_string = sequence;
1278 for (GLsizei i=0; i<count; i++) {
1279 GLuint code_point; // ignored
1280 bool ok = __glPathGetCodePointUTF8(utf_string, code_point);
1285 const char *start = reinterpret_cast<const char*>(sequence);
1286 const char *end = reinterpret_cast<const char*>(utf_string);
1291 const void *utf_string = sequence;
1292 for (GLsizei i=0; i<count; i++) {
1293 GLuint code_point; // ignored
1294 bool ok = __glPathGetCodePointUTF16(utf_string, code_point);
1299 const char *start = reinterpret_cast<const char*>(sequence);
1300 const char *end = reinterpret_cast<const char*>(utf_string);
1303 default: // generate INVALID_ENUM
1307 return count * bytes_per_element;
1313 static inline size_t
1314 _gl_Paths_size(GLsizei numPaths, GLenum pathNameType, const GLvoid *paths)
1316 return bytesOfSequence(numPaths, pathNameType, paths);
1319 static inline size_t
1320 _gl_PathColorGen_size(GLenum genMode, GLenum colorFormat)
1322 GLsizei coeffsPerComponent;
1325 coeffsPerComponent = 0;
1327 case GL_OBJECT_LINEAR:
1328 case GL_PATH_OBJECT_BOUNDING_BOX_NV:
1329 coeffsPerComponent = 3;
1332 coeffsPerComponent = 4;
1339 switch (colorFormat) {
1345 case GL_LUMINANCE_ALPHA:
1358 GLsizei numCoeffs = components * coeffsPerComponent;
1359 return numCoeffs*sizeof(GLfloat);
1362 static inline size_t
1363 _gl_PathTexGen_size(GLenum genMode, GLsizei components)
1365 GLsizei coeffsPerComponent;
1369 case GL_OBJECT_LINEAR:
1370 case GL_PATH_OBJECT_BOUNDING_BOX_NV:
1371 coeffsPerComponent = 3;
1374 coeffsPerComponent = 4;
1380 if (components < 1 || components > 4) {
1384 GLsizei numCoeffs = components * coeffsPerComponent;
1385 return numCoeffs*sizeof(GLfloat);
1388 static size_t valuesPerGetPathParameter(GLenum pname)
1391 case GL_PATH_FILL_MODE_NV:
1392 case GL_PATH_FILL_MASK_NV:
1393 case GL_PATH_FILL_COVER_MODE_NV:
1394 case GL_PATH_STROKE_WIDTH_NV:
1395 case GL_PATH_INITIAL_END_CAP_NV:
1396 case GL_PATH_TERMINAL_END_CAP_NV:
1397 case GL_PATH_JOIN_STYLE_NV:
1398 case GL_PATH_MITER_LIMIT_NV:
1399 case GL_PATH_INITIAL_DASH_CAP_NV:
1400 case GL_PATH_TERMINAL_DASH_CAP_NV:
1401 case GL_PATH_DASH_OFFSET_NV:
1402 case GL_PATH_DASH_OFFSET_RESET_NV:
1403 case GL_PATH_CLIENT_LENGTH_NV:
1404 case GL_PATH_STROKE_COVER_MODE_NV:
1405 case GL_PATH_STROKE_MASK_NV:
1406 case GL_PATH_STROKE_OVERSAMPLE_COUNT_NV:
1407 case GL_PATH_SAMPLE_QUALITY_NV:
1414 static inline size_t
1415 _gl_GetPathParameter_size(GLenum pname)
1417 return valuesPerGetPathParameter(pname);
1420 static inline size_t
1421 _gl_GetPathSpacing(GLsizei numPaths, GLenum transformType)
1423 switch (transformType) {
1424 case GL_TRANSLATE_X_NV:
1425 return (numPaths-1)*1;
1426 case GL_TRANSLATE_2D_NV:
1427 return (numPaths-1)*2;
1434 * Helper function for determining the string lengths for glShaderSource and
1435 * glShaderSourceARB, which is a tad too complex to inline in the specs.
1437 template<class Char>
1438 static inline size_t
1439 _glShaderSource_length(const Char * const * string, const GLint *length, GLsizei index)
1441 if (length != NULL && length[index] >= 0) {
1442 return (size_t)length[index];
1444 return strlen(string[index]);
1449 * Helper function for determining the string lengths for glGetDebugMessageLog*.
1451 template<class Char>
1452 static inline size_t
1453 _glGetDebugMessageLog_length(const Char * string, const GLsizei *lengths, GLuint count)
1458 for (index = 0; index < count; ++index) {
1459 size += lengths[index];
1462 for (index = 0; index < count; ++index) {
1463 size += strlen(&string[size]) + 1;
1467 // Remove the last null terminator
1473 #endif /* _GL_SIZE_HPP_ */