diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2016-05-08 20:41:21 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2016-05-10 03:25:25 -0700 |
commit | 6cd3660c689ecf1fb7b41a5d167d3c54a67eec04 (patch) | |
tree | 35a86358993e855e34cb38a5bb62c2634828e34f | |
parent | dd5b4b38a7d2bc3cf729d4f14d1a987869685077 (diff) |
gltrace: Move vertex array count helpers to a different module.
-rw-r--r-- | helpers/glsize.hpp | 174 | ||||
-rw-r--r-- | wrappers/CMakeLists.txt | 1 | ||||
-rw-r--r-- | wrappers/gltrace.py | 1 | ||||
-rw-r--r-- | wrappers/gltrace_arrays.cpp | 171 | ||||
-rw-r--r-- | wrappers/gltrace_arrays.hpp | 90 |
5 files changed, 263 insertions, 174 deletions
diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp index 88fe0f1b..98b05a73 100644 --- a/helpers/glsize.hpp +++ b/helpers/glsize.hpp @@ -393,180 +393,6 @@ _glGetVertexAttribi(GLuint index, GLenum pname) { } -static inline GLuint -_glDrawArrays_count(GLint first, GLsizei count) -{ - if (!count) { - return 0; - } - return first + count; -} - -#define _glDrawArraysEXT_count _glDrawArrays_count - -static inline GLuint -_glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex) -{ - GLvoid *temp = 0; - - if (!count) { - return 0; - } - - GLint element_array_buffer = _element_array_buffer_binding(); - if (element_array_buffer) { - // Read indices from index buffer object - GLintptr offset = (GLintptr)indices; - GLsizeiptr size = count*_gl_type_size(type); - temp = malloc(size); - if (!temp) { - return 0; - } - memset(temp, 0, size); - _glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp); - indices = temp; - } else { - if (!indices) { - return 0; - } - } - - GLuint maxindex = 0; - - GLboolean restart_enabled = _glIsEnabled(GL_PRIMITIVE_RESTART); - while ((_glGetError() == GL_INVALID_ENUM)) - ; - - GLuint restart_index = 0; - if (restart_enabled) { - restart_index = (GLuint)_glGetInteger(GL_PRIMITIVE_RESTART_INDEX); - } - - GLsizei i; - if (type == GL_UNSIGNED_BYTE) { - const GLubyte *p = (const GLubyte *)indices; - for (i = 0; i < count; ++i) { - GLuint index = p[i]; - if (restart_enabled && index == restart_index) { - continue; - } - if (index > maxindex) { - maxindex = index; - } - } - } else if (type == GL_UNSIGNED_SHORT) { - const GLushort *p = (const GLushort *)indices; - for (i = 0; i < count; ++i) { - GLuint index = p[i]; - if (restart_enabled && index == restart_index) { - continue; - } - if (index > maxindex) { - maxindex = index; - } - } - } else if (type == GL_UNSIGNED_INT) { - const GLuint *p = (const GLuint *)indices; - for (i = 0; i < count; ++i) { - GLuint index = p[i]; - if (restart_enabled && index == restart_index) { - continue; - } - if (index > maxindex) { - maxindex = index; - } - } - } else { - os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type); - } - - if (element_array_buffer) { - free(temp); - } - - maxindex += basevertex; - - return maxindex + 1; -} - -static inline GLuint -_glDrawRangeElementsBaseVertex_count(GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex) -{ - if (end < start || - count < 0) { - return 0; - } - - return end + basevertex + 1; -} - -#define _glDrawElements_count(count, type, indices) _glDrawElementsBaseVertex_count(count, type, indices, 0) -#define _glDrawRangeElements_count(start, end, count, type, indices) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, 0) -#define _glDrawRangeElementsEXT_count _glDrawRangeElements_count - -/* FIXME take in consideration instancing */ -#define _glDrawArraysInstanced_count(first, count, primcount) _glDrawArrays_count(first, count) -#define _glDrawElementsInstanced_count(count, type, indices, primcount) _glDrawElements_count(count, type, indices) -#define _glDrawElementsInstancedBaseVertex_count(count, type, indices, primcount, basevertex) _glDrawElementsBaseVertex_count(count, type, indices, basevertex) -#define _glDrawRangeElementsInstanced_count(start, end, count, type, indices, primcount) _glDrawRangeElements_count(start, end, count, type, indices) -#define _glDrawRangeElementsInstancedBaseVertex_count(start, end, count, type, indices, primcount, basevertex) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, basevertex) - -#define _glDrawArraysInstancedBaseInstance_count(first, count, primcount, baseinstance) _glDrawArrays_count(first, count) -#define _glDrawElementsInstancedBaseInstance_count(count, type, indices, primcount, baseinstance) _glDrawElements_count(count, type, indices) -#define _glDrawElementsInstancedBaseVertexBaseInstance_count(count, type, indices, primcount, basevertex, baseinstance) _glDrawElementsBaseVertex_count(count, type, indices, basevertex) - -#define _glDrawArraysInstancedARB_count _glDrawArraysInstanced_count -#define _glDrawArraysInstancedEXT_count _glDrawArraysInstanced_count -#define _glDrawArraysInstancedANGLE_count _glDrawArraysInstanced_count -#define _glDrawArraysInstancedBaseInstanceEXT_count _glDrawArraysInstancedBaseInstance_count -#define _glDrawElementsBaseVertexEXT_count _glDrawElementsBaseVertex_count -#define _glDrawElementsInstancedARB_count _glDrawElementsInstanced_count -#define _glDrawElementsInstancedEXT_count _glDrawElementsInstanced_count -#define _glDrawElementsInstancedANGLE_count _glDrawElementsInstanced_count -#define _glDrawElementsInstancedBaseInstanceEXT_count _glDrawElementsInstancedBaseInstance_count -#define _glDrawElementsInstancedBaseVertexEXT_count _glDrawElementsInstancedBaseVertex_count -#define _glDrawElementsInstancedBaseVertexBaseInstanceEXT_count _glDrawElementsInstancedBaseVertexBaseInstance_count -#define _glDrawRangeElementsBaseVertexEXT_count _glDrawRangeElementsBaseVertex_count - - -static inline GLuint -_glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawcount) { - GLuint _count = 0; - for (GLsizei draw = 0; draw < drawcount; ++draw) { - GLuint _count_draw = _glDrawArrays_count(first[draw], count[draw]); - _count = std::max(_count, _count_draw); - } - return _count; -} - -static inline GLuint -_glMultiDrawElements_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount) { - GLuint _count = 0; - for (GLsizei draw = 0; draw < drawcount; ++draw) { - GLuint _count_draw = _glDrawElements_count(count[draw], type, indices[draw]); - _count = std::max(_count, _count_draw); - } - return _count; -} - -static inline GLuint -_glMultiDrawElementsBaseVertex_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint * basevertex) { - GLuint _count = 0; - for (GLsizei draw = 0; draw < drawcount; ++draw) { - GLuint _count_draw = _glDrawElementsBaseVertex_count(count[draw], type, indices[draw], basevertex[draw]); - _count = std::max(_count, _count_draw); - } - return _count; -} - -#define _glMultiDrawArraysEXT_count _glMultiDrawArrays_count -#define _glMultiDrawElementsEXT_count _glMultiDrawElements_count -#define _glMultiDrawElementsBaseVertexEXT_count _glMultiDrawElementsBaseVertex_count - -#define _glMultiModeDrawArraysIBM_count(first, count, drawcount, modestride) _glMultiDrawArrays_count(first, count, drawcount) -#define _glMultiModeDrawElementsIBM_count(count, type, indices, drawcount, modestride) _glMultiDrawElements_count(count, type, (const GLvoid **)indices, drawcount) - - static inline size_t _glCallLists_size(GLsizei n, GLenum type) { diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt index 622897e4..5e29b1ac 100644 --- a/wrappers/CMakeLists.txt +++ b/wrappers/CMakeLists.txt @@ -91,6 +91,7 @@ target_link_libraries (trace add_convenience_library (gltrace_common glcaps.cpp config.cpp + gltrace_arrays.cpp gltrace_state.cpp ) add_dependencies (gltrace_common glproc) diff --git a/wrappers/gltrace.py b/wrappers/gltrace.py index 2786ed48..ae8d725f 100644 --- a/wrappers/gltrace.py +++ b/wrappers/gltrace.py @@ -117,6 +117,7 @@ class GlTracer(Tracer): print '#include <algorithm>' print print '#include "gltrace.hpp"' + print '#include "gltrace_arrays.hpp"' print # Which glVertexAttrib* variant to use diff --git a/wrappers/gltrace_arrays.cpp b/wrappers/gltrace_arrays.cpp new file mode 100644 index 00000000..b2b1eb38 --- /dev/null +++ b/wrappers/gltrace_arrays.cpp @@ -0,0 +1,171 @@ +/************************************************************************** + * + * Copyright 2010-2016 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + + +#include "gltrace_arrays.hpp" + + +GLuint +_glDrawArrays_count(GLint first, GLsizei count) +{ + if (!count) { + return 0; + } + return first + count; +} + + +GLuint +_glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex) +{ + GLvoid *temp = 0; + + if (!count) { + return 0; + } + + GLint element_array_buffer = _element_array_buffer_binding(); + if (element_array_buffer) { + // Read indices from index buffer object + GLintptr offset = (GLintptr)indices; + GLsizeiptr size = count*_gl_type_size(type); + temp = malloc(size); + if (!temp) { + return 0; + } + memset(temp, 0, size); + _glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp); + indices = temp; + } else { + if (!indices) { + return 0; + } + } + + GLuint maxindex = 0; + + GLboolean restart_enabled = _glIsEnabled(GL_PRIMITIVE_RESTART); + while ((_glGetError() == GL_INVALID_ENUM)) + ; + + GLuint restart_index = 0; + if (restart_enabled) { + restart_index = (GLuint)_glGetInteger(GL_PRIMITIVE_RESTART_INDEX); + } + + GLsizei i; + if (type == GL_UNSIGNED_BYTE) { + const GLubyte *p = (const GLubyte *)indices; + for (i = 0; i < count; ++i) { + GLuint index = p[i]; + if (restart_enabled && index == restart_index) { + continue; + } + if (index > maxindex) { + maxindex = index; + } + } + } else if (type == GL_UNSIGNED_SHORT) { + const GLushort *p = (const GLushort *)indices; + for (i = 0; i < count; ++i) { + GLuint index = p[i]; + if (restart_enabled && index == restart_index) { + continue; + } + if (index > maxindex) { + maxindex = index; + } + } + } else if (type == GL_UNSIGNED_INT) { + const GLuint *p = (const GLuint *)indices; + for (i = 0; i < count; ++i) { + GLuint index = p[i]; + if (restart_enabled && index == restart_index) { + continue; + } + if (index > maxindex) { + maxindex = index; + } + } + } else { + os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type); + } + + if (element_array_buffer) { + free(temp); + } + + maxindex += basevertex; + + return maxindex + 1; +} + + +GLuint +_glDrawRangeElementsBaseVertex_count(GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex) +{ + if (end < start || + count < 0) { + return 0; + } + + return end + basevertex + 1; +} + + +GLuint +_glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawcount) +{ + GLuint _count = 0; + for (GLsizei draw = 0; draw < drawcount; ++draw) { + GLuint _count_draw = _glDrawArrays_count(first[draw], count[draw]); + _count = std::max(_count, _count_draw); + } + return _count; +} + + +GLuint +_glMultiDrawElements_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount) +{ + GLuint _count = 0; + for (GLsizei draw = 0; draw < drawcount; ++draw) { + GLuint _count_draw = _glDrawElements_count(count[draw], type, indices[draw]); + _count = std::max(_count, _count_draw); + } + return _count; +} + + +GLuint +_glMultiDrawElementsBaseVertex_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint * basevertex) +{ + GLuint _count = 0; + for (GLsizei draw = 0; draw < drawcount; ++draw) { + GLuint _count_draw = _glDrawElementsBaseVertex_count(count[draw], type, indices[draw], basevertex[draw]); + _count = std::max(_count, _count_draw); + } + return _count; +} diff --git a/wrappers/gltrace_arrays.hpp b/wrappers/gltrace_arrays.hpp new file mode 100644 index 00000000..d3b2662a --- /dev/null +++ b/wrappers/gltrace_arrays.hpp @@ -0,0 +1,90 @@ +/************************************************************************** + * + * Copyright 2010-2016 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + +#pragma once + + +#include "glproc.hpp" +#include "glsize.hpp" + + +GLuint +_glDrawArrays_count(GLint first, GLsizei count); + +#define _glDrawArraysEXT_count _glDrawArrays_count + +GLuint +_glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); + +GLuint +_glDrawRangeElementsBaseVertex_count(GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex); + + +#define _glDrawElements_count(count, type, indices) _glDrawElementsBaseVertex_count(count, type, indices, 0) +#define _glDrawRangeElements_count(start, end, count, type, indices) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, 0) +#define _glDrawRangeElementsEXT_count _glDrawRangeElements_count + +/* FIXME take in consideration instancing */ +#define _glDrawArraysInstanced_count(first, count, primcount) _glDrawArrays_count(first, count) +#define _glDrawElementsInstanced_count(count, type, indices, primcount) _glDrawElements_count(count, type, indices) +#define _glDrawElementsInstancedBaseVertex_count(count, type, indices, primcount, basevertex) _glDrawElementsBaseVertex_count(count, type, indices, basevertex) +#define _glDrawRangeElementsInstanced_count(start, end, count, type, indices, primcount) _glDrawRangeElements_count(start, end, count, type, indices) +#define _glDrawRangeElementsInstancedBaseVertex_count(start, end, count, type, indices, primcount, basevertex) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, basevertex) + +#define _glDrawArraysInstancedBaseInstance_count(first, count, primcount, baseinstance) _glDrawArrays_count(first, count) +#define _glDrawElementsInstancedBaseInstance_count(count, type, indices, primcount, baseinstance) _glDrawElements_count(count, type, indices) +#define _glDrawElementsInstancedBaseVertexBaseInstance_count(count, type, indices, primcount, basevertex, baseinstance) _glDrawElementsBaseVertex_count(count, type, indices, basevertex) + +#define _glDrawArraysInstancedARB_count _glDrawArraysInstanced_count +#define _glDrawArraysInstancedEXT_count _glDrawArraysInstanced_count +#define _glDrawArraysInstancedANGLE_count _glDrawArraysInstanced_count +#define _glDrawArraysInstancedBaseInstanceEXT_count _glDrawArraysInstancedBaseInstance_count +#define _glDrawElementsBaseVertexEXT_count _glDrawElementsBaseVertex_count +#define _glDrawElementsInstancedARB_count _glDrawElementsInstanced_count +#define _glDrawElementsInstancedEXT_count _glDrawElementsInstanced_count +#define _glDrawElementsInstancedANGLE_count _glDrawElementsInstanced_count +#define _glDrawElementsInstancedBaseInstanceEXT_count _glDrawElementsInstancedBaseInstance_count +#define _glDrawElementsInstancedBaseVertexEXT_count _glDrawElementsInstancedBaseVertex_count +#define _glDrawElementsInstancedBaseVertexBaseInstanceEXT_count _glDrawElementsInstancedBaseVertexBaseInstance_count +#define _glDrawRangeElementsBaseVertexEXT_count _glDrawRangeElementsBaseVertex_count + + +GLuint +_glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawcount); + +GLuint +_glMultiDrawElements_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); + +GLuint +_glMultiDrawElementsBaseVertex_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint * basevertex); + +#define _glMultiDrawArraysEXT_count _glMultiDrawArrays_count +#define _glMultiDrawElementsEXT_count _glMultiDrawElements_count +#define _glMultiDrawElementsBaseVertexEXT_count _glMultiDrawElementsBaseVertex_count + +#define _glMultiModeDrawArraysIBM_count(first, count, drawcount, modestride) _glMultiDrawArrays_count(first, count, drawcount) +#define _glMultiModeDrawElementsIBM_count(count, type, indices, drawcount, modestride) _glMultiDrawElements_count(count, type, (const GLvoid **)indices, drawcount) + + |