Move utility functions into glUtils
Move utility functions into glUtils so they can be shared
between GLESv1 and GLESv2 codecs.
Change-Id: I673b316395604e4288412e7ace328076812d4cc1
diff --git a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h
index 3596406..1c1259a 100644
--- a/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h
+++ b/tools/emulator/opengl/shared/OpenglCodecCommon/glUtils.h
@@ -54,4 +54,35 @@
};
#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
diff --git a/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.cpp b/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.cpp
index fe9aa04..edc75bc 100644
--- a/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.cpp
+++ b/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.cpp
@@ -41,7 +41,7 @@
}
void GLEncoder::s_glGetIntegerv(void *self, GLenum param, GLint *ptr)
-{
+{
GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL);
if (param == GL_COMPRESSED_TEXTURE_FORMATS) {
@@ -49,7 +49,7 @@
if (ctx->m_num_compressedTextureFormats > 0 && compressedTextureFormats != NULL) {
memcpy(ptr, compressedTextureFormats, ctx->m_num_compressedTextureFormats * sizeof(GLint));
}
- }
+ }
else if (!ctx->m_state->getClientStateParameter<GLint>(param,ptr)) {
ctx->m_glGetIntegerv_enc(self, param, ptr);
}
@@ -401,20 +401,20 @@
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);
}
diff --git a/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.h b/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.h
index 7c50f61..3223ae9 100644
--- a/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.h
+++ b/tools/emulator/opengl/system/GLESv1_enc/GLEncoder.h
@@ -88,34 +88,5 @@
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