More informative error messages
| | |
| | | #define _GNU_SOURCE |
| | | |
| | | #include <errno.h> |
| | | #include <stdbool.h> |
| | | #include <stdint.h> |
| | |
| | | // use apitrace, vogl or similar tool to see what it does |
| | | |
| | | |
| | | static void pumpGLErrors() { |
| | | static void pumpGLErrors(const char *format, ...) { |
| | | va_list args; |
| | | |
| | | va_start(args, format); |
| | | |
| | | char *tempStr = NULL; |
| | | vasprintf(&tempStr, format, args); |
| | | |
| | | va_end(args); |
| | | |
| | | GLenum err; |
| | | while ((err = glGetError()) != GL_NO_ERROR) { |
| | | switch (err) { |
| | | case GL_INVALID_ENUM: |
| | | printf("GL error GL_INVALID_ENUM\n"); |
| | | printf("GL error GL_INVALID_ENUM in \"%s\"\n", tempStr); |
| | | break; |
| | | |
| | | case GL_INVALID_VALUE: |
| | | printf("GL error GL_INVALID_VALUE\n"); |
| | | printf("GL error GL_INVALID_VALUE in \"%s\"\n", tempStr); |
| | | break; |
| | | |
| | | default: |
| | | printf("Unknown GL error %04x\n", err); |
| | | printf("Unknown GL error %04x in \"%s\"\n", err, tempStr); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | free(tempStr); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | if (isCompressed) { |
| | | glCompressedTexImage2D(GL_TEXTURE_2D, miplevel, glfmt, mipW, mipH, 0, miptexlen, miptex); |
| | | pumpGLErrors("glCompressedTexImage2D %u 0x%04x %ux%u %u", miplevel, glfmt, mipW, mipH, miptexlen); |
| | | } else { |
| | | glTexImage2D(GL_TEXTURE_2D, miplevel, internalFormat, mipW, mipH, 0, glfmt, GL_UNSIGNED_BYTE, miptex); |
| | | pumpGLErrors("glTexImage2D %u 0x%04x %ux%u 0x%04x", miplevel, internalFormat, mipW, mipH, glfmt); |
| | | } |
| | | pumpGLErrors(); |
| | | } |
| | | |
| | | // and now the same with ARB_texture_storage if it's available |
| | |
| | | glGenTextures(1, &texId); |
| | | glBindTexture(GL_TEXTURE_2D, texId); |
| | | glTexStorage2D(GL_TEXTURE_2D, miplevels, internalFormat, w, h); |
| | | pumpGLErrors(); |
| | | pumpGLErrors("glTexStorage2D %u 0x%04x %ux%u", miplevels, internalFormat, w, h); |
| | | |
| | | for (unsigned int miplevel = 0; miplevel < miplevels; miplevel++) { |
| | | const void *miptex = NULL; |
| | |
| | | |
| | | if (isCompressed) { |
| | | glCompressedTexSubImage2D(GL_TEXTURE_2D, miplevel, 0, 0, mipW, mipH, glfmt, miptexlen, miptex); |
| | | pumpGLErrors("glCompressedTexSubImage2D %u %ux%u 0x%04x %u", miplevel, mipW, mipH, glfmt, miptexlen); |
| | | } else { |
| | | glTexSubImage2D(GL_TEXTURE_2D, miplevel, 0, 0, mipW, mipH, glfmt, GL_UNSIGNED_BYTE, miptex); |
| | | pumpGLErrors("glTexSubImage2D %u %ux%u 0x%04x", miplevel, mipW, mipH, glfmt); |
| | | } |
| | | pumpGLErrors(); |
| | | } |
| | | } |
| | | |