| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| #include "GLES2/gl2.h" |
| #include "SDL/SDL.h" |
|
|
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <emscripten.h> |
| #include <unistd.h> |
|
|
| typedef enum { |
| TEST_STATUS_SUCCESS = 0, |
| TEST_STATUS_FAILURE = 1 |
| } TestStatus; |
|
|
| |
| |
| static void exit_with_status(TestStatus code) { |
| #ifdef REPORT_RESULT |
| int result = (code == TEST_STATUS_SUCCESS) ? 1 : 0; |
| REPORT_RESULT(result); |
| #endif |
|
|
| exit(code); |
| } |
|
|
| |
| static void clear_gl_errors() { |
| GLenum err; |
| do { |
| err = glGetError(); |
| } while (err != GL_NO_ERROR); |
| } |
|
|
| int main(int argc, char *argv[]) { |
| TestStatus passed = TEST_STATUS_SUCCESS; |
| SDL_Surface *screen; |
|
|
| if (SDL_Init(SDL_INIT_VIDEO) != 0) { |
| printf("SDL_Init failed with %s\n", SDL_GetError()); |
| exit_with_status(TEST_STATUS_FAILURE); |
| } |
|
|
| SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
| screen = SDL_SetVideoMode(640, 480, 16, SDL_OPENGL); |
| if (!screen) { |
| printf("SDL_SetVideoMode failed with %s\n", SDL_GetError()); |
| exit_with_status(TEST_STATUS_FAILURE); |
| } |
|
|
| GLuint texture; |
| glGenTextures(1, &texture); |
|
|
| glBindTexture(GL_TEXTURE_2D, texture); |
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
| |
| |
| |
| |
| void* pixels = malloc(4 * 32 * 32); |
| if (pixels == NULL) { |
| printf("Unable to allocate pixel data\n"); |
| exit_with_status(TEST_STATUS_FAILURE); |
| } |
|
|
| |
| glTexImage2D(GL_TEXTURE_2D, 0, 0xffff, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| GLenum err = glGetError(); |
| if (err == GL_NO_ERROR) { |
| printf("internal format == 0xffff succeeded, but should have failed\n"); |
| passed = TEST_STATUS_FAILURE; |
| } |
| clear_gl_errors(); |
|
|
| |
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, 0xffff, GL_UNSIGNED_BYTE, pixels); |
| err = glGetError(); |
| if (err == GL_NO_ERROR) { |
| printf("format == 0xffff succeeded, but should have failed\n"); |
| passed = TEST_STATUS_FAILURE; |
| } |
| clear_gl_errors(); |
|
|
| |
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, 0xffff, pixels); |
| err = glGetError(); |
| if (err == GL_NO_ERROR) { |
| printf("type == 0xffff succeeded, but should have failed\n"); |
| passed = TEST_STATUS_FAILURE; |
| } |
| clear_gl_errors(); |
|
|
| |
| glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| err = glGetError(); |
| if (err != GL_NO_ERROR) { |
| printf("GL_RGBA/GL_UNSIGNED_BYTE failed with %x, but should have succeeded\n", err); |
| passed = TEST_STATUS_FAILURE; |
| } |
| clear_gl_errors(); |
|
|
| |
| glBindTexture(GL_TEXTURE_2D, 0); |
| glDeleteTextures(1, &texture); |
| free(pixels); |
|
|
| |
| SDL_Quit(); |
|
|
| exit_with_status(passed); |
| } |
|
|