/* * 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-vbo.c * Simple test of the API for GL_APPLE_object_purgeable with GL_ARB_vertex_buffer_object. */ #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 #ifndef GL_ARB_vertex_buffer_object #define GL_ARB_vertex_buffer_object 1 #define GL_ARRAY_BUFFER_ARB 0x8892 #define GL_STATIC_DRAW_ARB 0x88E0 typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const void *data, GLenum usage); #endif // GL_APPLE_object_purgeable static PFNGLOBJECTPURGEABLEAPPLEPROC pglObjectPurgeableAPPLE = NULL; static PFNGLOBJECTUNPURGEABLEAPPLEPROC pglObjectUnpurgeableAPPLE = NULL; static PFNGLGETOBJECTPARAMETERIVAPPLEPROC pglGetObjectParameterivAPPLE = NULL; // GL_ARB_vertex_buffer_object GL_ARB_pixel_buffer_object static PFNGLBINDBUFFERARBPROC pglBindBufferARB = NULL; static PFNGLDELETEBUFFERSARBPROC pglDeleteBuffersARB = NULL; static PFNGLGENBUFFERSARBPROC pglGenBuffersARB = NULL; static PFNGLBUFFERDATAARBPROC pglBufferDataARB = NULL; static GLboolean Automatic = GL_FALSE; static void init(void) { piglit_require_extension("GL_APPLE_object_purgeable"); piglit_require_extension("GL_ARB_vertex_buffer_object"); pglObjectPurgeableAPPLE = (PFNGLOBJECTPURGEABLEAPPLEPROC) piglit_get_proc_address("glObjectPurgeableAPPLE"); pglObjectUnpurgeableAPPLE = (PFNGLOBJECTUNPURGEABLEAPPLEPROC) piglit_get_proc_address("glObjectUnpurgeableAPPLE"); pglGetObjectParameterivAPPLE = (PFNGLGETOBJECTPARAMETERIVAPPLEPROC) piglit_get_proc_address("glGetObjectParameterivAPPLE"); pglGenBuffersARB = (PFNGLGENBUFFERSARBPROC) piglit_get_proc_address("glGenBuffersARB"); pglBindBufferARB = (PFNGLBINDBUFFERARBPROC) piglit_get_proc_address("glBindBufferARB"); pglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) piglit_get_proc_address("glDeleteBuffersARB"); pglBufferDataARB = (PFNGLBUFFERDATAARBPROC) piglit_get_proc_address("glBufferDataARB"); 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); } GLboolean test_ObjectpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option) { GLboolean pass = GL_TRUE; GLenum ret; ret = (*pglObjectPurgeableAPPLE)(objectType, name, option); FAIL_ON_ERROR("pglObjectpurgeableAPPLE"); switch (option) { case GL_VOLATILE_APPLE: if (ret != GL_VOLATILE_APPLE) { fprintf(stderr, "GL_VOLATILE_APPLE should be returned when call purgeable with GL_VOLATILE_APPLE\n"); pass = GL_FALSE; } break; case GL_RELEASED_APPLE: if (ret != GL_VOLATILE_APPLE && ret != GL_RELEASED_APPLE) { fprintf(stderr, "GL_VOLATILE_APPLE or GL_RELEASED_APPLE should be returned when call purgeable with GL_RELEASED_APPLE\n"); pass = GL_FALSE; } break; } return pass; } GLboolean test_ObjectunpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option) { GLboolean pass = GL_TRUE; GLenum ret; ret = (*pglObjectUnpurgeableAPPLE)(objectType, name, option); FAIL_ON_ERROR("pglObjectunpurgeableAPPLE"); switch (option) { case GL_RETAINED_APPLE: if (ret != GL_RETAINED_APPLE && ret != GL_UNDEFINED_APPLE) { fprintf(stderr, "GL_RETAINED_APPLE or GL_UNDEFINED_APPLE should be returned when call purgeable with GL_RETAINED_APPLE\n"); pass = GL_FALSE; } break; case GL_UNDEFINED_APPLE: if (ret != GL_UNDEFINED_APPLE) { fprintf(stderr, "GL_UNDEFINED_APPLE should be returned when call purgeable with GL_UNDEFINED_APPLE\n"); pass = GL_FALSE; } break; } return pass; } GLboolean test_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum expect) { GLboolean pass = GL_TRUE; GLint param; (*pglGetObjectParameterivAPPLE)(objectType, name, GL_PURGEABLE_APPLE, ¶m); FAIL_ON_ERROR("glGetObjectParameterivAPPLE"); if (param != expect) { fprintf(stderr, "GL_PURGEABLE_APPLE state is not set to GL_TRUE for texture object\n"); pass = GL_FALSE; } return pass; } static void display(void) { GLuint vbo; GLboolean pass = GL_TRUE; glClear(GL_COLOR_BUFFER_BIT); glGetError(); (*pglGenBuffersARB)(1, &vbo); (*pglBindBufferARB)(GL_ARRAY_BUFFER_ARB, vbo); (*pglBufferDataARB)(GL_ARRAY_BUFFER_ARB, 100*100, NULL, GL_STATIC_DRAW_ARB); (*pglBindBufferARB)(GL_ARRAY_BUFFER_ARB, 0); if (test_GetObjectParameterivAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_FALSE) != GL_TRUE) { fprintf(stderr, "Default GL_PURGEABLE_APPLE state should GL_FALSE for texture object\n"); pass = GL_FALSE; } if (test_ObjectpurgeableAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_VOLATILE_APPLE) != GL_TRUE) { fprintf(stderr, "Error when mark object %x to purgeable(GL_VOLATILE_APPLE)\n", vbo); pass = GL_FALSE; } if (test_GetObjectParameterivAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_TRUE) != GL_TRUE) { fprintf(stderr, "Object %x is not set to purgeable\n", vbo); pass = GL_FALSE; } if (test_ObjectunpurgeableAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_RETAINED_APPLE) != GL_TRUE) { fprintf(stderr, "Error when mark object %x to unpurgeable(GL_RETAINED_APPLE)\n", vbo); pass = GL_FALSE; } if (test_GetObjectParameterivAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_FALSE) != GL_TRUE) { fprintf(stderr, "Object %x is not set to unpurgeable\n", vbo); pass = GL_FALSE; } if (test_ObjectpurgeableAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_RELEASED_APPLE) != GL_TRUE) { fprintf(stderr, "Error when mark object %x to purgeable(GL_RELEASED_APPLE)\n", vbo); pass = GL_FALSE; } if (test_GetObjectParameterivAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_TRUE) != GL_TRUE) { fprintf(stderr, "Object %x is not set to purgeable\n", vbo); pass = GL_FALSE; } if (test_ObjectunpurgeableAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_UNDEFINED_APPLE) != GL_TRUE) { fprintf(stderr, "Error when mark object %x to unpurgeable(GL_UNDEFINED_APPLE)\n", vbo); pass = GL_FALSE; } if (test_GetObjectParameterivAPPLE(GL_BUFFER_OBJECT_APPLE, vbo, GL_FALSE) != GL_TRUE) { fprintf(stderr, "Object %x is not set to unpurgeable\n", vbo); pass = GL_FALSE; } (*pglDeleteBuffersARB)(1, &vbo); 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 GL_ARB_vertex_buffer_object"); glutReshapeFunc(reshape); glutKeyboardFunc(piglit_escape_exit_key); glutDisplayFunc(display); init(); glutMainLoop(); return 0; }