keunyoung | b85b275 | 2013-03-08 12:28:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #ifndef __GL_UTILS_H__ |
| 17 | #define __GL_UTILS_H__ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | |
| 22 | #ifdef GL_API |
| 23 | #undef GL_API |
| 24 | #endif |
| 25 | #define GL_API |
| 26 | |
| 27 | #ifdef GL_APIENTRY |
| 28 | #undef GL_APIENTRY |
| 29 | #endif |
| 30 | |
| 31 | #ifdef GL_APIENTRYP |
| 32 | #undef GL_APIENTRYP |
| 33 | #endif |
| 34 | #define GL_APIENTRYP |
| 35 | |
| 36 | #ifndef ANDROID |
| 37 | #define GL_APIENTRY |
| 38 | #endif |
| 39 | |
| 40 | #include <GLES/gl.h> |
| 41 | #include <GLES/glext.h> |
| 42 | #include <GLES2/gl2.h> |
| 43 | #include <GLES2/gl2ext.h> |
| 44 | |
| 45 | #ifdef __cplusplus |
| 46 | extern "C" { |
| 47 | #endif |
| 48 | |
| 49 | size_t glSizeof(GLenum type); |
| 50 | size_t glUtilsParamSize(GLenum param); |
| 51 | void glUtilsPackPointerData(unsigned char *dst, unsigned char *str, |
| 52 | int size, GLenum type, unsigned int stride, |
| 53 | unsigned int datalen); |
| 54 | void glUtilsWritePackPointerData(void* stream, unsigned char *src, |
| 55 | int size, GLenum type, unsigned int stride, |
| 56 | unsigned int datalen); |
| 57 | int glUtilsPixelBitSize(GLenum format, GLenum type); |
| 58 | void glUtilsPackStrings(char *ptr, char **strings, GLint *length, GLsizei count); |
| 59 | int glUtilsCalcShaderSourceLen(char **strings, GLint *length, GLsizei count); |
| 60 | #ifdef __cplusplus |
| 61 | }; |
| 62 | #endif |
| 63 | |
| 64 | namespace GLUtils { |
| 65 | |
| 66 | template <class T> void minmax(T *indices, int count, int *min, int *max) { |
| 67 | *min = -1; |
| 68 | *max = -1; |
| 69 | T *ptr = indices; |
| 70 | for (int i = 0; i < count; i++) { |
| 71 | if (*min == -1 || *ptr < *min) *min = *ptr; |
| 72 | if (*max == -1 || *ptr > *max) *max = *ptr; |
| 73 | ptr++; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | template <class T> void shiftIndices(T *indices, int count, int offset) { |
| 78 | T *ptr = indices; |
| 79 | for (int i = 0; i < count; i++) { |
| 80 | *ptr += offset; |
| 81 | ptr++; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
| 86 | template <class T> void shiftIndices(T *src, T *dst, int count, int offset) |
| 87 | { |
| 88 | for (int i = 0; i < count; i++) { |
| 89 | *dst = *src + offset; |
| 90 | dst++; |
| 91 | src++; |
| 92 | } |
| 93 | } |
| 94 | }; // namespace GLUtils |
| 95 | #endif |