Merge "Move utility functions into glUtils"
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user