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 #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 #endif

View File

@@ -41,7 +41,7 @@ GLint * GLEncoder::getCompressedTextureFormats()
} }
void GLEncoder::s_glGetIntegerv(void *self, GLenum param, GLint *ptr) void GLEncoder::s_glGetIntegerv(void *self, GLenum param, GLint *ptr)
{ {
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
if (param == GL_COMPRESSED_TEXTURE_FORMATS) { if (param == GL_COMPRESSED_TEXTURE_FORMATS) {
@@ -49,7 +49,7 @@ void GLEncoder::s_glGetIntegerv(void *self, GLenum param, GLint *ptr)
if (ctx->m_num_compressedTextureFormats > 0 && compressedTextureFormats != NULL) { if (ctx->m_num_compressedTextureFormats > 0 && compressedTextureFormats != NULL) {
memcpy(ptr, compressedTextureFormats, ctx->m_num_compressedTextureFormats * sizeof(GLint)); memcpy(ptr, compressedTextureFormats, ctx->m_num_compressedTextureFormats * sizeof(GLint));
} }
} }
else if (!ctx->m_state->getClientStateParameter<GLint>(param,ptr)) { else if (!ctx->m_state->getClientStateParameter<GLint>(param,ptr)) {
ctx->m_glGetIntegerv_enc(self, param, ptr); ctx->m_glGetIntegerv_enc(self, param, ptr);
} }
@@ -401,20 +401,20 @@ void GLEncoder::s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum
switch(type) { switch(type) {
case GL_BYTE: case GL_BYTE:
case GL_UNSIGNED_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) { if (minIndex != 0) {
adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count); 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, (unsigned char *)adjustedIndices,
count, -minIndex); count, -minIndex);
} }
break; break;
case GL_SHORT: case GL_SHORT:
case GL_UNSIGNED_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) { if (minIndex != 0) {
adjustedIndices = ctx->m_fixedBuffer.alloc(glSizeof(type) * count); 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, (unsigned short *)adjustedIndices,
count, -minIndex); 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_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, void *indices);
static void s_glPixelStorei(void *self, GLenum param, GLint value); static void s_glPixelStorei(void *self, GLenum param, GLint value);
void sendVertexData(unsigned first, unsigned count); 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 #endif