case GL_BYTE:
case GL_UNSIGNED_BYTE:
return 1;
- break;
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_2_BYTES:
case GL_HALF_FLOAT:
return 2;
- break;
case GL_3_BYTES:
return 3;
- break;
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FLOAT:
case GL_4_BYTES:
return 4;
- break;
case GL_DOUBLE:
return 8;
- break;
default:
OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
return 0;
static inline size_t
__glArrayPointer_size(GLint size, GLenum type, GLsizei stride, GLsizei maxIndex)
{
- GLsizei elementSize = size*__gl_type_size(type);
+ size_t elementSize = size*__gl_type_size(type);
if (!stride) {
- stride = elementSize;
+ stride = (GLsizei)elementSize;
}
return stride*maxIndex + elementSize;
}
#define __glEdgeFlagPointer_size(stride, maxIndex) __glArrayPointer_size(1, GL_BOOL, stride, maxIndex)
#define __glFogCoordPointer_size(type, stride, maxIndex) __glArrayPointer_size(1, type, stride, maxIndex)
#define __glSecondaryColorPointer_size(size, type, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex)
+#define __glVertexAttribPointer_size(size, type, normalized, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex)
-static inline size_t
+static inline GLuint
__glDrawArrays_maxindex(GLint first, GLsizei count)
{
return first + count - 1;
}
-static inline size_t
-__glDrawElements_maxindex(GLsizei count, GLenum type, const GLvoid *_indices)
+static inline GLuint
+__glDrawElements_maxindex(GLsizei count, GLenum type, const GLvoid *indices)
{
- size_t maxindex = 0;
- unsigned i;
+ GLvoid *temp = 0;
+ GLint __element_array_buffer = 0;
+ __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);
+ if (__element_array_buffer) {
+ // Read indices from index buffer object
+ GLintptr offset = (GLintptr)indices;
+ GLsizeiptr size = count*__gl_type_size(type);
+ GLvoid *temp = malloc(size);
+ if (!temp) {
+ return 0;
+ }
+ memset(temp, 0, size);
+ __glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp);
+ indices = temp;
+ } else {
+ if (!indices) {
+ return 0;
+ }
+ }
+ GLuint maxindex = 0;
+ GLsizei i;
if (type == GL_UNSIGNED_BYTE) {
- const GLubyte *indices = (const GLubyte *)_indices;
+ const GLubyte *p = (const GLubyte *)indices;
for (i = 0; i < count; ++i) {
- if (indices[i] > maxindex) {
- maxindex = indices[i];
+ if (p[i] > maxindex) {
+ maxindex = p[i];
}
}
} else if (type == GL_UNSIGNED_SHORT) {
- const GLushort *indices = (const GLushort *)_indices;
+ const GLushort *p = (const GLushort *)indices;
for (i = 0; i < count; ++i) {
- if (indices[i] > maxindex) {
- maxindex = indices[i];
+ if (p[i] > maxindex) {
+ maxindex = p[i];
}
}
} else if (type == GL_UNSIGNED_INT) {
- const GLuint *indices = (const GLuint *)_indices;
+ const GLuint *p = (const GLuint *)indices;
for (i = 0; i < count; ++i) {
- if (indices[i] > maxindex) {
- maxindex = indices[i];
+ if (p[i] > maxindex) {
+ maxindex = p[i];
}
}
} else {
OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
}
+ if (__element_array_buffer) {
+ free(temp);
+ }
+
return maxindex;
}
-static inline size_t
+static inline GLuint
__glDrawRangeElements_maxindex(GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices)
{
+ (void)start;
+ (void)end;
return __glDrawElements_maxindex(count, type, indices);
}
#define __glGetIntegerv_size __glGetBooleanv_size
+#define __glGetInteger64v_size __glGetBooleanv_size
+
#define __glGetLightfv_size __glLightfv_size
#define __glGetLightiv_size __glLightfv_size
#define __glGetFramebufferAttachmentParameteriv_size __glGetFramebufferAttachmentParameterivEXT_size
static inline size_t
-__glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint border) {
- size_t num_channels;
+__gl_format_channels(GLenum format) {
switch (format) {
case GL_COLOR_INDEX:
case GL_RED:
case GL_BLUE:
case GL_ALPHA:
case GL_INTENSITY:
+ case GL_LUMINANCE:
case GL_DEPTH_COMPONENT:
case GL_STENCIL_INDEX:
- num_channels = 1;
+ return 1;
break;
case GL_LUMINANCE_ALPHA:
- num_channels = 2;
+ return 2;
break;
case GL_RGB:
case GL_BGR:
- num_channels = 3;
+ return 3;
break;
case GL_RGBA:
case GL_BGRA:
- num_channels = 4;
+ return 4;
break;
default:
- OS::DebugMessage("warning: %s: unexpected GLenum 0x%04X\n", __FUNCTION__, format);
- num_channels = 0;
+ OS::DebugMessage("warning: %s: unexpected format GLenum 0x%04X\n", __FUNCTION__, format);
+ return 0;
break;
}
+}
+
+static inline size_t
+__glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint border) {
+ size_t num_channels = __gl_format_channels(format);
size_t bits_per_pixel;
switch (type) {
bits_per_pixel = 32;
break;
default:
- OS::DebugMessage("warning: %s: unexpected GLenum 0x%04X\n", __FUNCTION__, type);
+ OS::DebugMessage("warning: %s: unexpected type GLenum 0x%04X\n", __FUNCTION__, type);
bits_per_pixel = 0;
break;
}
#define __glBitmap_size(width, height) __glTexImage2D_size(GL_COLOR_INDEX, GL_BITMAP, width, height, 0)
#define __glPolygonStipple_size() __glBitmap_size(32, 32)
+
+/*
+ * 0 terminated integer/float attribute list.
+ */
+template<class T>
+static inline size_t
+__AttribList_size(const T *pAttribList)
+{
+ size_t size = 0;
+
+ if (pAttribList) {
+ do {
+ ++size;
+ } while (*pAttribList++);
+ }
+
+ return size;
+}
+
+
#endif /* _GL_HELPERS_HPP_ */