Merge "Move utility functions into glUtils"

This commit is contained in:
David Turner
2011-05-02 09:15:28 -07:00
committed by Android Code Review
3 changed files with 37 additions and 35 deletions

View File

@@ -54,4 +54,35 @@ extern "C" {
};
#endif
namespace GLUtils {
template <class T> void minmax(T *indices, int count, int *min, int *max) {
*min = -1;
*max = -1;
T *ptr = indices;
for (int i = 0; i < count; i++) {
if (*min == -1 || *ptr < *min) *min = *ptr;
if (*max == -1 || *ptr > *max) *max = *ptr;
ptr++;
}
}
template <class T> void shiftIndices(T *indices, int count, int offset) {
T *ptr = indices;
for (int i = 0; i < count; i++) {
*ptr += offset;
ptr++;
}
}
template <class T> void shiftIndices(T *src, T *dst, int count, int offset)
{
for (int i = 0; i < count; i++) {
*dst = *src + offset;
dst++;
src++;
}
}
}; // namespace GLUtils
#endif

View File

@@ -401,20 +401,20 @@ void GLEncoder::s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum
switch(type) {
case GL_BYTE:
case GL_UNSIGNED_BYTE:
ctx->minmax<unsigned char>((unsigned char *)indices, count, &minIndex, &maxIndex);
GLUtils::minmax<unsigned char>((unsigned char *)indices, count, &minIndex, &maxIndex);
if (minIndex != 0) {
adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count);
ctx->shiftIndices<unsigned char>((unsigned char *)indices,
GLUtils::shiftIndices<unsigned char>((unsigned char *)indices,
(unsigned char *)adjustedIndices,
count, -minIndex);
}
break;
case GL_SHORT:
case GL_UNSIGNED_SHORT:
ctx->minmax<unsigned short>((unsigned short *)indices, count, &minIndex, &maxIndex);
GLUtils::minmax<unsigned short>((unsigned short *)indices, count, &minIndex, &maxIndex);
if (minIndex != 0) {
adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count);
ctx->shiftIndices<unsigned short>((unsigned short *)indices,
GLUtils::shiftIndices<unsigned short>((unsigned short *)indices,
(unsigned short *)adjustedIndices,
count, -minIndex);
}

View File

@@ -88,34 +88,5 @@ private:
static void s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, void *indices);
static void s_glPixelStorei(void *self, GLenum param, GLint value);
void sendVertexData(unsigned first, unsigned count);
template <class T> void minmax(T *indices, int count, int *min, int *max) {
*min = -1;
*max = -1;
T *ptr = indices;
for (int i = 0; i < count; i++) {
if (*min == -1 || *ptr < *min) *min = *ptr;
if (*max == -1 || *ptr > *max) *max = *ptr;
ptr++;
}
}
template <class T> void shiftIndices(T *indices, int count, int offset) {
T *ptr = indices;
for (int i = 0; i < count; i++) {
*ptr += offset;
ptr++;
}
}
template <class T> void shiftIndices(T *src, T *dst, int count, int offset)
{
for (int i = 0; i < count; i++) {
*dst = *src + offset;
dst++;
src++;
}
}
};
#endif