/* * Copyright © 2010 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * Authors: * Shuang He */ /** * \file object_purgeable-api-error.c * Simple test of the API for GL_APPLE_object_purgeable with error handling. */ #include "piglit-util.h" #define FAIL_ON_ERROR(string) \ do { \ const GLenum err = glGetError(); \ if (err != GL_NO_ERROR) { \ fprintf(stderr, "%s generated error 0x%04x\n", \ string, err); \ pass = GL_FALSE; \ } \ } while (0) #ifndef APIENTRY #define APIENTRY #endif #ifndef APIENTRYP #define APIENTRYP APIENTRY * #endif #ifndef GL_APPLE_object_purgeable #define GL_APPLE_object_purgeable 1 #define GL_RELEASED_APPLE 0x8A19 #define GL_VOLATILE_APPLE 0x8A1A #define GL_RETAINED_APPLE 0x8A1B #define GL_UNDEFINED_APPLE 0x8A1C #define GL_PURGEABLE_APPLE 0x8A1D #define GL_BUFFER_OBJECT_APPLE 0x85B3 typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option); typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint* params); #endif static PFNGLOBJECTPURGEABLEAPPLEPROC pglObjectPurgeableAPPLE = NULL; static PFNGLOBJECTUNPURGEABLEAPPLEPROC pglObjectUnpurgeableAPPLE = NULL; static PFNGLGETOBJECTPARAMETERIVAPPLEPROC pglGetObjectParameterivAPPLE = NULL; static GLboolean Automatic = GL_FALSE; static void init(void) { piglit_require_extension("GL_APPLE_object_purgeable"); pglObjectPurgeableAPPLE = (PFNGLOBJECTPURGEABLEAPPLEPROC) piglit_get_proc_address("glObjectPurgeableAPPLE"); pglObjectUnpurgeableAPPLE = (PFNGLOBJECTUNPURGEABLEAPPLEPROC) piglit_get_proc_address("glObjectUnpurgeableAPPLE"); pglGetObjectParameterivAPPLE = (PFNGLGETOBJECTPARAMETERIVAPPLEPROC) piglit_get_proc_address("glGetObjectParameterivAPPLE"); glClearColor(0.1, 0.1, 0.3, 0.0); } static void reshape(int width, int height) { glViewport(0, 0, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); glMatrixMode(GL_MODELVIEW); } static void display(void) { int i; GLint param; GLuint textures[12]; GLboolean pass = GL_TRUE; glClear(GL_COLOR_BUFFER_BIT); glGenTextures(12, textures); for (i=0; i<12; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 100, 100, 0, GL_RGB, GL_INT, NULL); } glBindTexture(GL_TEXTURE_2D, 0); glGetError(); // Subcase 1 (*pglObjectPurgeableAPPLE)(-1, textures[0], GL_VOLATILE_APPLE); if (glGetError() != GL_INVALID_ENUM) { fprintf(stderr, "ObjectPurgeable should generate GL_INVALID_ENUM for invalid object type\n"); pass = GL_FALSE; } // Subcase 2 (*pglObjectPurgeableAPPLE)(GL_TEXTURE, textures[1], GL_VOLATILE_APPLE); (*pglObjectUnpurgeableAPPLE)(-1, textures[1], GL_RETAINED_APPLE); if (glGetError() != GL_INVALID_ENUM) { fprintf(stderr, "ObjectUnpurgeable should generate GL_INVALID_ENUM for invalid object type\n"); pass = GL_FALSE; } // Subcase 3 (*pglObjectPurgeableAPPLE)(GL_TEXTURE, textures[2], -1); if (glGetError() != GL_INVALID_ENUM) { fprintf(stderr, "ObjectPurgeable should generate GL_INVALID_ENUM for invalid option\n"); pass = GL_FALSE; } // Subcase 4 (*pglObjectPurgeableAPPLE)(GL_TEXTURE, textures[3], GL_VOLATILE_APPLE); (*pglObjectUnpurgeableAPPLE)(GL_TEXTURE, textures[3], -1); if (glGetError() != GL_INVALID_ENUM) { fprintf(stderr, "ObjectUnpurgeable should generate GL_INVALID_ENUM for invalid option\n"); pass = GL_FALSE; } // Subcase 5 glBegin(GL_POINTS); (*pglObjectPurgeableAPPLE)(GL_TEXTURE, textures[4], GL_VOLATILE_APPLE); glEnd(); if (glGetError() != GL_INVALID_OPERATION) { fprintf(stderr, "GL_INVALID_OPERNATION should be generated when ObjectPurgeable is called bwtween glBegin() and glEnd()\n"); pass = GL_FALSE; } // Subcase 6 (*pglObjectPurgeableAPPLE)(GL_TEXTURE, textures[5], GL_VOLATILE_APPLE); glBegin(GL_POINTS); (*pglObjectUnpurgeableAPPLE)(GL_TEXTURE, textures[5], GL_UNDEFINED_APPLE); glEnd(); if (glGetError() != GL_INVALID_OPERATION) { fprintf(stderr, "GL_INVALID_OPERNATION should be generated when ObjectUnpurgeable is called bwtween glBegin() and glEnd()\n"); pass = GL_FALSE; } // Subcase 7 (*pglObjectPurgeableAPPLE)(GL_TEXTURE, textures[6], GL_VOLATILE_APPLE); (*pglObjectPurgeableAPPLE)(GL_TEXTURE, textures[6], GL_VOLATILE_APPLE); if (glGetError() != GL_INVALID_OPERATION) { fprintf(stderr, "GL_INVALID_OPERNATION should be generated when ObjectPurgeable is called when PURGEABLE is already TRUE\n"); pass = GL_FALSE; } // Subcase 8 (*pglObjectUnpurgeableAPPLE)(GL_TEXTURE, textures[7], GL_UNDEFINED_APPLE); if (glGetError() != GL_INVALID_OPERATION) { fprintf(stderr, "GL_INVALID_OPERNATION should be generated when ObjectUnpurgeable is called when PURGEABLE is already FALSE\n"); pass = GL_FALSE; } // Subcase 9 (*pglGetObjectParameterivAPPLE)(-1, textures[8], GL_PURGEABLE_APPLE, ¶m); if (glGetError() != GL_INVALID_ENUM) { fprintf(stderr, "GL_INVALID_ENUM should be generated when GetObjectParameterivAPPLE is called with invalid object type\n"); pass = GL_FALSE; } // Subcase 10 (*pglGetObjectParameterivAPPLE)(GL_TEXTURE, -1, GL_PURGEABLE_APPLE, ¶m); if (glGetError() != GL_INVALID_VALUE) { fprintf(stderr, "GL_INVALID_ENUM should be generated when GetObjectParameterivAPPLE is called with invalid object name\n"); pass = GL_FALSE; } // Subcase 11 (*pglGetObjectParameterivAPPLE)(GL_TEXTURE, 0, GL_PURGEABLE_APPLE, ¶m); if (glGetError() != GL_INVALID_VALUE) { fprintf(stderr, "GL_INVALID_ENUM should be generated when GetObjectParameterivAPPLE is called with invalid object name 0\n"); pass = GL_FALSE; } // Subcase 12 (*pglGetObjectParameterivAPPLE)(GL_TEXTURE, textures[11], -1, ¶m); if (glGetError() != GL_INVALID_ENUM) { fprintf(stderr, "GL_INVALID_ENUM should be generated when GetObjectParameterivAPPLE is called with invalid pname\n"); pass = GL_FALSE; } glDeleteTextures(12, textures); if (Automatic) piglit_report_result(pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE); } int main(int argc, char **argv) { glutInit(&argc, argv); if (argc == 2 && !strcmp(argv[1], "-auto")) Automatic = GL_TRUE; glutInitWindowSize(400, 300); glutInitDisplayMode(GLUT_RGB); glutCreateWindow("GL_APPLE_object_purgeable API test with error handling"); glutReshapeFunc(reshape); glutKeyboardFunc(piglit_escape_exit_key); glutDisplayFunc(display); init(); glutMainLoop(); return 0; }